id,java,python V0,"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; Long a = sc . nextLong ( ) ; Long b = sc . nextLong ( ) ; Long x = sc . nextLong ( ) ; Long A = a == 0 ? 0 : ( a - 1 ) / x + 1 ; Long B = b / x + 1 ; System . out . println ( B - A ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { 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 ; } } } ","a , b , x = map ( int , input ( ) . split ( ) ) NEW_LINE if a == 0 : NEW_LINE INDENT print ( int ( b // x ) + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( b // x ) + 1 - int ( ( a - 1 ) // x ) - 1 ) NEW_LINE DEDENT " V1,"import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; class Main { static int G ; static int D ; static int [ ] p ; static int [ ] c ; static boolean [ ] used ; static long ans = 1000000000 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; int [ ] b = new int [ m ] ; ArrayList < Pair > pairs = new ArrayList < Pair > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { Pair pair = new Pair ( ) ; a [ i ] = sc . nextInt ( ) - 1 ; b [ i ] = sc . nextInt ( ) - 1 ; pair . from = a [ i ] ; pair . end = b [ i ] ; pairs . add ( pair ) ; } Collections . sort ( pairs ) ; int minR = pairs . get ( 0 ) . end ; int ans = 0 ; for ( int i = 1 ; i < m ; i ++ ) { if ( pairs . get ( i ) . from >= minR ) { ans ++ ; minR = pairs . get ( i ) . end ; } else { if ( pairs . get ( i ) . end < minR ) { minR = pairs . get ( i ) . end ; } } } ans ++ ; System . out . println ( ans ) ; } } class Pair implements Comparable { int from ; int end ; int num ; int bango ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return from - otherpair . from ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details . ","n , m = map ( int , input ( ) . split ( ) ) NEW_LINE l = [ tuple ( map ( int , input ( ) . split ( ) ) ) for _ in range ( m ) ] NEW_LINE l . sort ( key = lambda x : x [ 1 ] ) NEW_LINE dec = 0 NEW_LINE cur = 0 NEW_LINE for i in l : NEW_LINE INDENT if i [ 0 ] < cur <= i [ 1 ] : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT dec += 1 NEW_LINE cur = i [ 1 ] NEW_LINE DEDENT DEDENT print ( dec ) NEW_LINE " V2,"import java . math . BigInteger ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; BigInteger ten = BigInteger . valueOf ( 10 ) ; System . out . println ( ten . pow ( n ) . add ( BigInteger . valueOf ( 7 ) ) ) ; } } } ","print ( 10 ** int ( input ( ) ) + 7 ) NEW_LINE " V3,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scan = new Scanner ( System . in ) ) { int [ ] cList = init ( scan ) ; double ans = proc ( cList ) ; System . out . println ( ans ) ; } } public static int [ ] init ( Scanner scan ) { int n = scan . nextInt ( ) ; int [ ] cList = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { cList [ i ] = scan . nextInt ( ) ; } return cList ; } public static double proc ( int [ ] cList ) { double ans = 0 ; int size = cList . length ; double temp = 0 ; for ( int i = 0 ; i < size ; i ++ ) { temp = 0 ; for ( int j = 0 ; j < size ; j ++ ) { if ( cList [ i ] % cList [ j ] == 0 && i != j ) { temp ++ ; } } if ( temp == 0 ) { ans += 1.0 ; } else if ( ( temp ) % 2.0 != 0 ) { ans += 0.5 ; } else { ans += ( temp + 2.0 ) / ( 2.0 * temp + 2.0 ) ; } } return ans ; } } ","n = int ( input ( ) ) NEW_LINE ans = 0 NEW_LINE lis = [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE lis . sort ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT cou = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if i != j : NEW_LINE INDENT if lis [ i ] % lis [ j ] == 0 : NEW_LINE INDENT cou += 1 NEW_LINE DEDENT DEDENT DEDENT if cou % 2 == 1 : NEW_LINE INDENT ans += 0.5 NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( cou + 2 ) / ( 2 * cou + 2 ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE " V4,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int [ ] [ ] wf = new int [ 10 ] [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { wf [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int k = 0 ; k < 10 ; k ++ ) { for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { wf [ i ] [ j ] = Math . min ( wf [ i ] [ j ] , wf [ i ] [ k ] + wf [ k ] [ j ] ) ; } } } int [ ] count = new int [ 10 ] ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { int a = sc . nextInt ( ) ; if ( a >= 0 ) { count [ a ] ++ ; } } } int sum = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( i == 1 ) continue ; int cost = wf [ i ] [ 1 ] ; sum += cost * count [ i ] ; } System . out . println ( sum ) ; } } ","def main ( ) : NEW_LINE INDENT H , W = map ( int , input ( ) . split ( ) ) NEW_LINE g_list = [ ] NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT g_list . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT min_change = [ j [ 1 ] for j in g_list ] NEW_LINE flag = [ 0 for _ in range ( 10 ) ] NEW_LINE tep = [ ( j , g ) for j , g in enumerate ( min_change ) if j != 1 ] NEW_LINE min_g = min ( tep , key = lambda a : a [ 1 ] ) [ 0 ] NEW_LINE flag [ min_g ] = 1 NEW_LINE while sum ( flag ) != 9 : NEW_LINE INDENT for j in range ( 10 ) : NEW_LINE INDENT if g_list [ j ] [ min_g ] + min_change [ min_g ] < min_change [ j ] : NEW_LINE INDENT min_change [ j ] = g_list [ j ] [ min_g ] + min_change [ min_g ] NEW_LINE DEDENT DEDENT tep = [ ( k , g ) for k , g in enumerate ( min_change ) if flag [ k ] == 0 and k != 1 ] NEW_LINE if tep != [ ] : NEW_LINE INDENT min_g = min ( tep , key = lambda a : a [ 1 ] ) [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT flag [ min_g ] = 1 NEW_LINE DEDENT s = 0 NEW_LINE for i in range ( H ) : NEW_LINE INDENT wall = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE s += sum ( [ min_change [ i ] for i in wall if i != - 1 ] ) NEW_LINE DEDENT return s NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( main ( ) ) NEW_LINE DEDENT " V5,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int AB = scan . nextInt ( ) ; int BC = scan . nextInt ( ) ; int CA = scan . nextInt ( ) ; System . out . println ( ( AB * BC ) / 2 ) ; } } ","AB , BC , CA = map ( int , input ( ) . split ( ) ) NEW_LINE print ( AB * BC // 2 ) NEW_LINE " V6,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String w = scanner . nextLine ( ) ; scanner . close ( ) ; w = w . replace ( "" a "" , "" "" ) . replace ( "" i "" , "" "" ) . replace ( "" u "" , "" "" ) . replace ( "" e "" , "" "" ) . replace ( "" o "" , "" "" ) ; System . out . println ( w ) ; } } ","s = input ( ) NEW_LINE t = ' ' NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' a ' or s [ i ] == ' i ' or s [ i ] == ' u ' or s [ i ] == ' e ' or s [ i ] == ' o ' : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT t += s [ i ] NEW_LINE DEDENT DEDENT print ( t ) NEW_LINE " V7,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int maxCount = 0 ; int maxNum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int num = i + 1 ; while ( true ) { if ( num % 2 != 0 ) { break ; } num /= 2 ; count ++ ; } if ( i == 0 || count > maxCount ) { maxCount = count ; maxNum = i + 1 ; } } System . out . println ( maxNum ) ; } } ","n = int ( input ( ) ) NEW_LINE if n > 63 : NEW_LINE INDENT print ( 64 ) NEW_LINE DEDENT elif n > 31 : NEW_LINE INDENT print ( 32 ) NEW_LINE DEDENT elif n > 15 : NEW_LINE INDENT print ( 16 ) NEW_LINE DEDENT elif n > 7 : NEW_LINE INDENT print ( 8 ) NEW_LINE DEDENT elif n > 3 : NEW_LINE INDENT print ( 4 ) NEW_LINE DEDENT elif n > 1 : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT " V8,"import java . util . Scanner ; public class Main { static int n ; static int [ ] a ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int max = 0 , min = n ; for ( int i = 0 ; i < n ; i ++ ) { max = Math . max ( max , a [ i ] ) ; min = Math . min ( min , a [ i ] ) ; } if ( max - min >= 2 ) { System . out . println ( "" No "" ) ; return ; } if ( max == min ) { if ( max == n - 1 || 2 * max <= n ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } else { int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == max ) { ++ x ; } if ( a [ i ] == min ) { ++ y ; } } if ( y < max && 2 * ( max - y ) <= x ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } } } ","from collections import Counter NEW_LINE n = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a . sort ( ) NEW_LINE c = Counter ( a ) NEW_LINE if len ( c ) > 2 or a [ 0 ] + 1 < a [ - 1 ] : print ( "" No "" ) NEW_LINE elif len ( c ) == 1 : NEW_LINE INDENT if a [ 0 ] + 1 == n or n >= 2 * a [ 0 ] : print ( "" Yes "" ) NEW_LINE else : print ( "" No "" ) NEW_LINE DEDENT else : NEW_LINE INDENT x , y = c [ a [ - 1 ] ] , c [ a [ 0 ] ] NEW_LINE if y + 1 <= a [ - 1 ] <= x // 2 + y : print ( "" Yes "" ) NEW_LINE else : print ( "" No "" ) NEW_LINE DEDENT " V9,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; if ( isPrime ( n ) ) { System . out . println ( "" YES "" ) ; } else { System . out . println ( "" NO "" ) ; } } static boolean isPrime ( int x ) { for ( int i = 2 ; i <= 1000 && i < x ; i ++ ) { if ( x % i == 0 ) { return false ; } } return true ; } } ","n = int ( input ( ) ) NEW_LINE for i in range ( 2 , n // 2 + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT " V10,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; long [ ] num = new long [ 29 ] ; long ans = 0 ; for ( int i = 0 ; i < 29 ; i ++ ) { int [ ] ta = new int [ n ] ; int [ ] tb = new int [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { ta [ j ] = a [ j ] % ( 2 << i ) ; tb [ j ] = b [ j ] % ( 2 << i ) ; } Arrays . sort ( tb ) ; int pow1 = ( 2 << i ) / 2 ; int pow2 = 2 * pow1 , pow3 = 3 * pow1 , pow4 = 4 * pow1 ; for ( int j = 0 ; j < n ; j ++ ) { int tmp1 = myBinarySearch ( tb , pow1 - ta [ j ] ) ; int tmp2 = myBinarySearch ( tb , pow2 - ta [ j ] ) ; int tmp3 = myBinarySearch ( tb , pow3 - ta [ j ] ) ; int tmp4 = myBinarySearch ( tb , pow4 - ta [ j ] ) ; num [ i ] += tmp2 - tmp1 + tmp4 - tmp3 ; } if ( num [ i ] % 2 == 1 ) ans += ( 2 << i ) / 2 ; } System . out . println ( ans ) ; } public static int myBinarySearch ( int [ ] la , int key ) { int l = - 1 ; int r = la . length ; while ( r - l > 1 ) { int m = ( l + r ) >> 1 ; if ( la [ m ] >= key ) { r = m ; } else { l = m ; } } return r ; } } ","from numpy import * ; B = searchsorted ; a , b = split ( int32 ( open ( 0 ) . read ( ) . split ( ) [ 1 : ] ) , 2 ) ; c = 0 NEW_LINE for k in range ( 29 ) : l = 2 ** k ; h = 2 * l ; y = sort ( hstack ( ( b % h - h , b % h ) ) ) ; c += sum ( B ( y , h - a % h ) - B ( y , l - a % h ) ) % 2 * l NEW_LINE print ( c ) NEW_LINE " V11,"import java . util . * ; public class Main { static long [ ] fact , ifact ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long mod = 1000000007 ; int size = 1001000 ; fact = new long [ size ] ; ifact = new long [ size ] ; fact [ 0 ] = 1 ; for ( int i = 1 ; i < size ; i ++ ) fact [ i ] = fact [ i - 1 ] * i % mod ; ifact [ size - 1 ] = inv ( fact [ size - 1 ] , mod ) ; for ( int i = size - 1 ; i > 0 ; i -- ) ifact [ i - 1 ] = ifact [ i ] * i % mod ; long res = 0 ; long sum = 0 ; for ( int i = n / 2 ; i < n ; i ++ ) { long v = binom ( i - 1 , n - i - 1 , mod ) * fact [ i ] % mod * fact [ n - i - 1 ] % mod ; res = ( res + ( v - sum + mod ) % mod * i ) % mod ; sum = v ; } System . out . println ( res ) ; } static long binom ( int a , int b , long mod ) { if ( a < b ) return 0 ; return fact [ a ] * ifact [ b ] % mod * ifact [ a - b ] % mod ; } static long inv ( long a , long mod ) { long b = mod ; long p = 1 , q = 0 ; while ( b > 0 ) { long c = a / b ; long d = a ; a = b ; b = d % b ; d = p ; p = q ; q = d - c * q ; } return ( p + mod ) % mod ; } } ","n = int ( input ( ) ) NEW_LINE p = 10 ** 9 + 7 NEW_LINE def fact ( n ) : NEW_LINE INDENT n_ = 1 NEW_LINE yield n_ NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT n_ = ( n_ * i ) % p NEW_LINE yield n_ NEW_LINE DEDENT DEDENT def invfact ( n , f , p ) : NEW_LINE INDENT m = pow ( f [ n ] , p - 2 , p ) NEW_LINE yield m NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT m = m * i % p NEW_LINE yield m NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE m = n - 1 NEW_LINE f = list ( fact ( m ) ) NEW_LINE rf = list ( invfact ( m , f , p ) ) NEW_LINE rf . reverse ( ) NEW_LINE perm = 0 NEW_LINE for k in range ( ( n + 1 ) // 2 , n ) : NEW_LINE INDENT b = m - k NEW_LINE a = ( m - 1 ) - ( 2 * b ) NEW_LINE perm_ = f [ a + b ] * rf [ a ] % p * f [ k ] % p NEW_LINE ans += ( perm_ - perm ) % p * k % p NEW_LINE ans %= p NEW_LINE perm = perm_ NEW_LINE DEDENT print ( ans ) NEW_LINE " V12,"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; D solver = new D ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class D { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] l = new int [ n + 1 ] ; l [ 0 ] = - 1 ; int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int m = in . nextInt ( ) ; for ( int j = 1 ; j <= i ; j ++ ) { if ( l [ j - 1 ] == 0 ) { break ; } else if ( l [ j - 1 ] < m ) { if ( l [ j ] == 0 ) { l [ j ] = m ; ans = Math . max ( ans , j ) ; } else { l [ j ] = Math . min ( l [ j ] , m ) ; } } } } out . println ( n - ans ) ; } } } ","import bisect NEW_LINE N = int ( input ( ) ) NEW_LINE L = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT L . append ( int ( input ( ) ) ) NEW_LINE DEDENT dp = [ float ( ' inf ' ) ] * N NEW_LINE dp [ 0 ] = L [ 0 ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT k = bisect . bisect_left ( dp , L [ i ] ) NEW_LINE dp [ k ] = L [ i ] NEW_LINE DEDENT endnum = bisect . bisect_left ( dp , N + 1 ) NEW_LINE print ( N - endnum ) NEW_LINE " V13,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; long [ ] H = new long [ N ] ; long [ ] S = new long [ N ] ; long ansmin = 0 , ansmax = Long . MAX_VALUE >> 2 ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextLong ( ) ; S [ i ] = sc . nextLong ( ) ; ansmin = Math . max ( ansmin , H [ i ] ) ; } long [ ] time = new long [ N ] ; for ( int idx = 0 ; idx < 100 ; idx ++ ) { long ansmid = ( ansmax + ansmin ) / 2 ; boolean f = true ; for ( int i = 0 ; i < N ; i ++ ) { time [ i ] = ( ansmid - H [ i ] - 1 ) / S [ i ] ; } Arrays . sort ( time ) ; for ( int i = 0 ; f && i < N ; i ++ ) { if ( time [ i ] < ( long ) i ) { f = false ; } } if ( f ) { ansmax = ansmid ; } else { ansmin = ansmid ; } } System . out . println ( ansmin ) ; } } } ","iipt = lambda : int ( input ( ) ) NEW_LINE miipt = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE from pprint import pprint NEW_LINE n = iipt ( ) NEW_LINE hs = [ miipt ( ) for i in range ( n ) ] NEW_LINE a = 0 NEW_LINE b = int ( 1e15 ) NEW_LINE while b - a > 1 : NEW_LINE INDENT c = ( a + b ) // 2 NEW_LINE tl = sorted ( [ ( c - h ) // s for h , s in hs ] ) NEW_LINE if all ( t <= i for t , i in enumerate ( tl ) ) : NEW_LINE INDENT b = c NEW_LINE DEDENT else : NEW_LINE INDENT a = c NEW_LINE DEDENT DEDENT print ( b ) NEW_LINE " V14,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner a = new Scanner ( System . in ) ; int N = a . nextInt ( ) ; int x = N * 2 ; System . out . println ( x ) ; } } ","n = int ( input ( ) ) NEW_LINE print ( n * 2 ) NEW_LINE " V15,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long [ ] sum_a = new long [ n ] ; long [ ] sum_b = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; if ( i == 0 ) { sum_a [ i ] = a [ i ] ; sum_b [ i ] = Math . max ( 0 , a [ i ] ) ; } else { sum_a [ i ] = sum_a [ i - 1 ] + a [ i ] ; sum_b [ i ] = sum_b [ i - 1 ] + Math . max ( 0 , a [ i ] ) ; } } long ans = 0 ; for ( int i = 0 ; i <= n - k ; i ++ ) { long sum_black = 0 ; long sum_white = 0 ; if ( i == 0 ) sum_black += sum_a [ i + k - 1 ] ; else sum_black += sum_a [ i + k - 1 ] - sum_a [ i - 1 ] ; if ( i > 0 ) { sum_black += sum_b [ i - 1 ] ; sum_white += sum_b [ i - 1 ] ; } sum_black += sum_b [ n - 1 ] - sum_b [ i + k - 1 ] ; sum_white += sum_b [ n - 1 ] - sum_b [ i + k - 1 ] ; ans = Math . max ( sum_black , ans ) ; ans = Math . max ( sum_white , ans ) ; } System . out . println ( ans ) ; } } ","from itertools import accumulate as ac NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = [ 0 ] + list ( ac ( a ) ) NEW_LINE c = [ 0 ] + list ( ac ( [ ( 0 if i < 0 else i ) for i in a ] ) ) NEW_LINE d = 0 NEW_LINE for i in range ( n - k + 1 ) : NEW_LINE INDENT d = max ( d , max ( b [ i + k ] - b [ i ] , 0 ) + c [ i ] + c [ - 1 ] - c [ i + k ] ) NEW_LINE DEDENT print ( d ) NEW_LINE " V16,"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] sw = new int [ N ] [ 2 ] ; long cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sw [ i ] [ 0 ] = sc . nextInt ( ) ; sw [ i ] [ 1 ] = sc . nextInt ( ) ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( ( cnt + sw [ i ] [ 0 ] ) % sw [ i ] [ 1 ] == 0 ) { } else { cnt += sw [ i ] [ 1 ] - ( cnt + sw [ i ] [ 0 ] ) % sw [ i ] [ 1 ] ; } } System . out . println ( cnt ) ; sc . close ( ) ; } } ","n = int ( input ( ) ) NEW_LINE AB = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT a = AB [ i ] [ 0 ] + ans NEW_LINE b = AB [ i ] [ 1 ] NEW_LINE if a % b == 0 : NEW_LINE INDENT tmp = 0 NEW_LINE DEDENT else : NEW_LINE INDENT tmp = b - ( a % b ) NEW_LINE DEDENT ans += tmp NEW_LINE DEDENT print ( ans ) NEW_LINE " V17,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; String N = reader . next ( ) ; int num = 0 ; for ( int i = 0 ; i < N . length ( ) ; i ++ ) { char ch = N . charAt ( i ) ; num += Character . getNumericValue ( ch ) ; } if ( Integer . parseInt ( N ) % num == 0 ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } reader . close ( ) ; } } ","N = input ( ) NEW_LINE cnt = 0 NEW_LINE for i in N : NEW_LINE INDENT cnt += int ( i ) NEW_LINE DEDENT if int ( N ) % cnt == 0 : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT " V18,"import java . util . * ; public class Main { static public int n ; static int [ ] A = new int [ 50 ] ; static int [ ] B = new int [ 50 ] ; public Boolean fun ( Long bit ) { boolean [ ] [ ] arr = new boolean [ 51 ] [ 51 ] ; for ( int i = 0 ; i <= 50 ; i ++ ) { arr [ i ] [ i ] = true ; } for ( int i = 1 ; i <= 50 ; i ++ ) { if ( ( bit & ( 1L << i ) ) != 0 ) { for ( int j = 0 ; j <= 50 ; j ++ ) { arr [ j ] [ j % i ] = true ; } } } for ( int k = 0 ; k <= 50 ; k ++ ) { for ( int i = 0 ; i <= 50 ; i ++ ) { for ( int j = 0 ; j <= 50 ; j ++ ) { arr [ i ] [ j ] |= arr [ i ] [ k ] & arr [ k ] [ j ] ; } } } Boolean flag = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! arr [ A [ i ] ] [ B [ i ] ] ) flag = false ; } return flag ; } public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } Long ans = ( 1L << 50 ) - 1 ; if ( ! fun ( ans ) ) { System . out . println ( - 1 ) ; return ; } for ( int i = 50 ; i >= 0 ; i -- ) { Long tmp = ans & ~ ( 1L << i ) ; if ( fun ( tmp ) ) ans = tmp ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } ; ","N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE B = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE if any ( [ a < b for a , b in zip ( A , B ) ] ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT if A == B : NEW_LINE INDENT print ( 0 ) NEW_LINE exit ( ) NEW_LINE DEDENT def reachable ( a , b , gr ) : NEW_LINE INDENT if a == b : return True NEW_LINE assert a > b NEW_LINE visited = [ 0 ] * ( a + 1 ) NEW_LINE stack = [ a ] NEW_LINE while stack : NEW_LINE INDENT v = stack . pop ( ) NEW_LINE if v == b : return True NEW_LINE visited [ v ] = 1 NEW_LINE for to in gr [ v ] : NEW_LINE INDENT if visited [ to ] : continue NEW_LINE stack . append ( to ) NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT permanent_use = [ ] NEW_LINE def need ( n ) : NEW_LINE INDENT gr = [ set ( ) for i in range ( 51 ) ] NEW_LINE for i in range ( 51 ) : NEW_LINE INDENT for p in permanent_use : NEW_LINE INDENT gr [ i ] . add ( i % p ) NEW_LINE DEDENT for j in range ( 1 , n ) : NEW_LINE INDENT gr [ i ] . add ( i % j ) NEW_LINE DEDENT DEDENT for a , b in zip ( A , B ) : NEW_LINE INDENT if not reachable ( a , b , gr ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if need ( 51 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT for i in range ( 50 , 0 , - 1 ) : NEW_LINE INDENT if need ( i ) : NEW_LINE INDENT permanent_use . append ( i ) NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for p in permanent_use : NEW_LINE INDENT ans += 2 ** p NEW_LINE DEDENT print ( ans ) NEW_LINE " V19,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int NA = sc . nextInt ( ) ; int NB = sc . nextInt ( ) ; HashSet A = new HashSet < > ( ) ; for ( int i = 0 ; i < NA ; i ++ ) { A . add ( sc . nextInt ( ) ) ; } int cnt = 0 ; for ( int i = 0 ; i < NB ; i ++ ) { int target = sc . nextInt ( ) ; if ( A . contains ( target ) ) { cnt ++ ; } else { A . add ( target ) ; } } System . out . println ( ( double ) cnt / A . size ( ) ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details . ","def lower_bound ( l , x ) : NEW_LINE INDENT imin = - 1 NEW_LINE imax = len ( l ) NEW_LINE while imax - imin > 1 : NEW_LINE INDENT imid = ( imax + imin ) // 2 NEW_LINE if l [ imid ] >= x : NEW_LINE INDENT imax = imid NEW_LINE DEDENT else : NEW_LINE INDENT imin = imid NEW_LINE DEDENT DEDENT if imax == len ( l ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return l [ imax ] NEW_LINE DEDENT NA , NB = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE B = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE B . sort ( ) NEW_LINE AB = 0 NEW_LINE for i in A : NEW_LINE INDENT if lower_bound ( B , i ) == i : NEW_LINE INDENT AB += 1 NEW_LINE DEDENT DEDENT print ( AB / ( NA + NB - AB ) ) NEW_LINE " V20,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) ; int a = d % 2 ; int b = d / 2 ; if ( a == 0 ) { System . out . println ( b ) ; } else { int c = b + 1 ; System . out . println ( c ) ; } } } ","N = int ( input ( ) ) NEW_LINE print ( - ( - N // 2 ) ) NEW_LINE " V21,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . PriorityQueue ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int a [ ] = new int [ n ] ; int b [ ] = new int [ n ] ; long result = 0 ; long minB = Long . MAX_VALUE ; boolean same = true ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] tmpArray = br . readLine ( ) . split ( "" ▁ "" ) ; a [ i ] = Integer . parseInt ( tmpArray [ 0 ] ) ; b [ i ] = Integer . parseInt ( tmpArray [ 1 ] ) ; result += a [ i ] ; if ( a [ i ] > b [ i ] && minB > b [ i ] ) { minB = b [ i ] ; } if ( a [ i ] != b [ i ] ) { same = false ; } } if ( ! same ) { result -= minB ; } else { result = 0 ; } System . out . println ( result ) ; } } ","n = int ( input ( ) ) NEW_LINE a = [ 0 ] * n NEW_LINE b = [ 0 ] * n NEW_LINE temp = 10 ** 10 NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] , b [ i ] = map ( int , input ( ) . split ( ) ) NEW_LINE if a [ i ] > b [ i ] : NEW_LINE INDENT temp = min ( temp , b [ i ] ) NEW_LINE DEDENT DEDENT if temp == 10 ** 10 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( sum ( a ) - temp ) NEW_LINE DEDENT " V22,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; String S = sc . next ( ) ; int crash = 0 ; int count = 1 ; for ( int i = 0 ; i < N ; i ++ ) { char ch = S . charAt ( i ) ; if ( ch == ' + ' ) { count ++ ; } if ( ch == ' - ' ) { count -- ; if ( count == 0 ) { count = 1 ; } } if ( count > L ) { crash ++ ; count = 1 ; } } System . out . println ( crash ) ; } } ","N , L = map ( int , input ( ) . split ( ) ) NEW_LINE S = input ( ) NEW_LINE tab = 1 NEW_LINE ans = 0 NEW_LINE for s in S : NEW_LINE INDENT if s == ' + ' : NEW_LINE INDENT tab += 1 NEW_LINE DEDENT if s == ' - ' : NEW_LINE INDENT tab -= 1 NEW_LINE DEDENT if tab > L : NEW_LINE INDENT tab = 1 NEW_LINE ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE " V23,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( sc . nextInt ( ) % 500 <= sc . nextInt ( ) ? "" Yes "" : "" No "" ) ; } } ","N = int ( input ( ) ) NEW_LINE A = int ( input ( ) ) NEW_LINE num = N % 500 NEW_LINE if ( num <= A ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V24,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int delicious = 0 ; boolean poison = false ; while ( c > 0 ) { if ( poison ) break ; c -- ; delicious ++ ; poison = true ; if ( b > 0 ) { b -- ; delicious ++ ; poison = false ; } else if ( a > 0 ) { a -- ; poison = false ; } } delicious += b ; System . out . println ( delicious ) ; } } ","A , B , C = map ( int , input ( ) . split ( ) ) NEW_LINE ans = min ( C , A + B + 1 ) NEW_LINE ans += B NEW_LINE print ( ans ) NEW_LINE " V25,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N < 1200 ) { System . out . println ( "" ABC "" ) ; } else if ( N < 2800 ) { System . out . println ( "" ARC "" ) ; } else { System . out . println ( "" AGC "" ) ; } } } ","n = int ( input ( ) ) NEW_LINE if n < 1200 : NEW_LINE INDENT print ( ' ABC ' ) NEW_LINE DEDENT elif n < 2800 : NEW_LINE INDENT print ( ' ARC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' AGC ' ) NEW_LINE DEDENT " V26,"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; if ( a > b ) { System . out . println ( "" Takahashi "" ) ; } else if ( a == b ) { if ( n % ( a + 1 ) != 0 ) { System . out . println ( "" Takahashi "" ) ; } else { System . out . println ( "" Aoki "" ) ; } } else { if ( n <= a ) { System . out . println ( "" Takahashi "" ) ; } else { System . out . println ( "" Aoki "" ) ; } } } static void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } } ","import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n = I ( ) NEW_LINE a , b = LI ( ) NEW_LINE if n <= a : NEW_LINE INDENT return ' Takahashi ' NEW_LINE DEDENT if n <= b + 1 : NEW_LINE INDENT return ' Aoki ' NEW_LINE DEDENT if a == b and n % ( a + 1 ) == 0 : NEW_LINE INDENT return ' Aoki ' NEW_LINE DEDENT if a >= b : NEW_LINE INDENT return ' Takahashi ' NEW_LINE DEDENT return ' Aoki ' NEW_LINE DEDENT print ( main ( ) ) NEW_LINE " V27,"import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] cnts = new long [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { cnts [ i ] = sc . nextLong ( ) ; } long pairs = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( cnts [ i - 1 ] > 0 && cnts [ i ] > 0 ) { pairs ++ ; cnts [ i - 1 ] -- ; cnts [ i ] -- ; } pairs += cnts [ i ] / 2 ; cnts [ i ] %= 2 ; } out . println ( pairs ) ; } } ","N = int ( input ( ) ) NEW_LINE ans = 0 NEW_LINE A = list ( int ( input ( ) ) for i in range ( N ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT ans += A [ i ] // 2 NEW_LINE if i != N - 1 : NEW_LINE INDENT if A [ i ] >= 2 : NEW_LINE INDENT A [ i + 1 ] += A [ i ] % 2 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE " V28,"import java . util . Scanner ; public class Main { private static int n = 0 ; private static int ans = 0 ; public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; sc . close ( ) ; dfs ( ""0"" ) ; System . out . println ( ans ) ; } private static void dfs ( String val ) { if ( Long . parseLong ( val ) > n ) { return ; } if ( val . indexOf ( ""3"" ) != - 1 && val . indexOf ( ""5"" ) != - 1 && val . indexOf ( ""7"" ) != - 1 ) { ans ++ ; } dfs ( val + ""3"" ) ; dfs ( val + ""5"" ) ; dfs ( val + ""7"" ) ; } } ","import itertools NEW_LINE n = int ( input ( ) ) NEW_LINE nums = [ ] NEW_LINE pre_nums = [ '3' , '5' , '7' ] NEW_LINE for i in range ( 3 , 10 ) : NEW_LINE INDENT for ids in itertools . product ( pre_nums , repeat = i ) : NEW_LINE INDENT if '3' in ids and '5' in ids and '7' in ids : NEW_LINE INDENT nums . append ( int ( ' ' . join ( ids ) ) ) NEW_LINE DEDENT DEDENT DEDENT for i , num in enumerate ( nums ) : NEW_LINE INDENT if n < num : NEW_LINE INDENT print ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( len ( nums ) ) NEW_LINE DEDENT " V29,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int n ; int [ ] counts ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; counts = new int [ 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( a % 2 != 0 ) { counts [ 0 ] ++ ; } else if ( a % 4 != 0 ) { counts [ 1 ] ++ ; } else { counts [ 2 ] ++ ; } } solve ( ) ; } void solve ( ) { if ( counts [ 0 ] + Math . min ( counts [ 1 ] , 1 ) <= counts [ 2 ] + 1 ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } 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 ( ) ) ; } String nextLine ( ) { String str = "" "" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } ","from math import ceil NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE num2 = 0 NEW_LINE num4 = 0 NEW_LINE numO = 0 NEW_LINE for num in A : NEW_LINE INDENT if num % 4 == 0 : NEW_LINE INDENT num4 += 1 NEW_LINE continue NEW_LINE DEDENT elif num % 2 == 0 : NEW_LINE INDENT num2 += 1 NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT numO += 1 NEW_LINE DEDENT DEDENT if num2 > 0 : NEW_LINE INDENT if numO > num4 : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if numO > ceil ( ( num4 + numO ) / 2 ) : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT DEDENT " V30,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i <= A ; i ++ ) { for ( int j = 0 ; j <= B ; j ++ ) { for ( int z = 0 ; z <= C ; z ++ ) { if ( X == 500 * i + 100 * j + 50 * z ) { count ++ ; } } } } System . out . println ( count ) ; } } ","a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE c = int ( input ( ) ) NEW_LINE x = int ( input ( ) ) NEW_LINE cnt = 0 NEW_LINE for i in range ( a + 1 ) : NEW_LINE INDENT for j in range ( b + 1 ) : NEW_LINE INDENT for k in range ( c + 1 ) : NEW_LINE INDENT if 500 * i + 100 * j + 50 * k == x : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( cnt ) NEW_LINE " V31,"import java . util . Scanner ; public class Main { public static void main ( String [ ] srgs ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; if ( a <= 0 && b >= 0 ) { System . out . println ( "" Zero "" ) ; } else if ( a < 0 && Math . abs ( ( a - b + 1 ) ) % 2 == 1 ) { System . out . println ( "" Negative "" ) ; } else { System . out . println ( "" Positive "" ) ; } scan . close ( ) ; } } ","a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a <= 0 and b >= 0 : NEW_LINE INDENT print ( ' Zero ' ) NEW_LINE DEDENT elif a > 0 and b > 0 : NEW_LINE INDENT print ( ' Positive ' ) NEW_LINE DEDENT else : NEW_LINE INDENT num = b - a + 1 NEW_LINE if num % 2 == 1 : NEW_LINE INDENT print ( ' Negative ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Positive ' ) NEW_LINE DEDENT DEDENT " V32,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long ans = 0 ; int start = sc . nextInt ( ) ; boolean up = false ; boolean down = false ; for ( int i = 1 ; i < N ; i ++ ) { int a = sc . nextInt ( ) ; if ( start == a ) continue ; if ( start > a ) { if ( up ) { ans ++ ; down = false ; up = false ; } else { down = true ; } } else { if ( down ) { ans ++ ; up = false ; down = false ; } else { up = true ; } } start = a ; } System . out . println ( ans + 1 ) ; } } ","def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE As = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ct = 1 NEW_LINE inc = False NEW_LINE dec = False NEW_LINE bef = As . pop ( 0 ) NEW_LINE for Ai in As : NEW_LINE INDENT if ( not inc ) and ( not dec ) : NEW_LINE INDENT if Ai < bef : NEW_LINE INDENT dec = True NEW_LINE DEDENT elif Ai > bef : NEW_LINE INDENT inc = True NEW_LINE DEDENT DEDENT elif inc : NEW_LINE INDENT if Ai < bef : NEW_LINE INDENT ct += 1 NEW_LINE inc = False NEW_LINE DEDENT DEDENT elif dec : NEW_LINE INDENT if Ai > bef : NEW_LINE INDENT ct += 1 NEW_LINE dec = False NEW_LINE DEDENT DEDENT bef = Ai NEW_LINE DEDENT print ( ct ) NEW_LINE DEDENT main ( ) NEW_LINE " V33,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] w = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) w [ i ] = sc . next ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == n - 1 ) { w [ i ] = w [ i ] . replaceAll ( "" \\ . "" , "" "" ) ; } if ( w [ i ] . equals ( "" TAKAHASHIKUN "" ) || w [ i ] . equals ( "" Takahashikun "" ) || w [ i ] . equals ( "" takahashikun "" ) ) { ans ++ ; } } System . out . println ( ans ) ; } } ","n = int ( input ( ) ) NEW_LINE s = input ( ) . rstrip ( ' . ' ) . split ( ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] == ' TAKAHASHIKUN ' or s [ i ] == ' Takahashikun ' or s [ i ] == ' takahashikun ' : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE " V34,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] x = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = s . nextInt ( ) ; } int limit = s . nextInt ( ) ; int [ ] [ ] dptable = new int [ 18 ] [ n ] ; int begin = 0 ; int end = 0 ; long sum = x [ 0 ] ; while ( begin < n ) { while ( true ) { if ( end + 1 < n && x [ end + 1 ] - x [ begin ] <= limit ) { end ++ ; } else { break ; } } dptable [ 0 ] [ begin ] = end ; begin ++ ; } for ( int i = 1 ; i < 18 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dptable [ i ] [ j ] = dptable [ i - 1 ] [ dptable [ i - 1 ] [ j ] ] ; } } int q = s . nextInt ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int ta = s . nextInt ( ) - 1 ; int tb = s . nextInt ( ) - 1 ; int a = Math . min ( ta , tb ) ; int b = Math . max ( ta , tb ) ; int current = a ; int days = 0 ; int depth = 0 ; for ( depth = 0 ; depth < 17 ; depth ++ ) { if ( dptable [ depth + 1 ] [ current ] >= b ) { current = dptable [ depth ] [ current ] ; days = 1 << depth ; break ; } } while ( depth >= 0 ) { if ( dptable [ depth ] [ current ] < b ) { current = dptable [ depth ] [ current ] ; days += ( 1 << depth ) ; } depth -- ; } System . out . println ( days + ( current < b ? 1 : 0 ) ) ; } } } ","from bisect import bisect_right NEW_LINE N = int ( input ( ) ) NEW_LINE X = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE L = int ( input ( ) ) NEW_LINE P = [ [ 0 ] * N for i in range ( 30 ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT q = bisect_right ( X , X [ i ] + L ) NEW_LINE P [ 0 ] [ i ] = q - 1 NEW_LINE DEDENT for i in range ( 1 , 30 ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT P [ i ] [ j ] = P [ i - 1 ] [ P [ i - 1 ] [ j ] ] NEW_LINE DEDENT DEDENT Q = int ( input ( ) ) NEW_LINE for i in range ( Q ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a > b : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT a , b = a - 1 , b - 1 NEW_LINE num = 0 NEW_LINE for j in range ( 29 , - 1 , - 1 ) : NEW_LINE INDENT if P [ j ] [ a ] < b : NEW_LINE INDENT a = P [ j ] [ a ] NEW_LINE num += 2 ** j NEW_LINE DEDENT DEDENT print ( num + 1 ) NEW_LINE DEDENT " V35,"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int N = sc . nextInt ( ) ; long S = sc . nextInt ( ) ; long [ ] x = new long [ N ] , p = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { x [ i ] = sc . nextInt ( ) ; p [ i ] = sc . nextInt ( ) ; } int left = 0 , right = N - 1 ; long [ ] order = new long [ N ] ; int idx = 0 ; while ( x [ left ] < S && S < x [ right ] ) { if ( p [ left ] >= p [ right ] ) { order [ idx ++ ] = x [ right ] ; p [ left ] += p [ right ] ; right -- ; } else { order [ idx ++ ] = x [ left ] ; p [ right ] += p [ left ] ; left ++ ; } } while ( right >= 0 && S < x [ right ] ) { order [ idx ++ ] = x [ right ] ; right -- ; } while ( left < N && x [ left ] < S ) { order [ idx ++ ] = x [ left ] ; left ++ ; } long ans = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { ans += Math . abs ( order [ i ] - S ) ; S = order [ i ] ; } System . out . println ( ans ) ; } } ","import numpy as np NEW_LINE def solve ( l , r ) : NEW_LINE INDENT l . reverse ( ) NEW_LINE stops = [ ] NEW_LINE if l and r : NEW_LINE INDENT while l and r : NEW_LINE INDENT lx , lp = l . pop ( ) NEW_LINE rx , rp = r . pop ( ) NEW_LINE if lp >= rp : NEW_LINE INDENT l . append ( ( lx , lp + rp ) ) NEW_LINE stops . append ( rx ) NEW_LINE DEDENT else : NEW_LINE INDENT r . append ( ( rx , lp + rp ) ) NEW_LINE stops . append ( lx ) NEW_LINE DEDENT DEDENT DEDENT if l : NEW_LINE INDENT stops . append ( l [ - 1 ] [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT stops . append ( r [ - 1 ] [ 0 ] ) NEW_LINE DEDENT stops . append ( s ) NEW_LINE return abs ( np . diff ( np . array ( stops , dtype = np . int64 ) ) ) . sum ( ) NEW_LINE DEDENT n , s = map ( int , input ( ) . split ( ) ) NEW_LINE l , r = [ ] , [ ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT x , p = map ( int , input ( ) . split ( ) ) NEW_LINE if x < s : NEW_LINE INDENT l . append ( ( x , p ) ) NEW_LINE DEDENT else : NEW_LINE INDENT r . append ( ( x , p ) ) NEW_LINE DEDENT DEDENT print ( solve ( l , r ) ) NEW_LINE " V36,"import java . util . * ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; List < Character > ss = new ArrayList < > ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { ss . add ( s . charAt ( i ) ) ; } if ( ss . contains ( ' a ' ) && ss . contains ( ' b ' ) && ss . contains ( ' c ' ) ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } } ","print ( ' Yes ' if set ( input ( ) ) == { ' a ' , ' b ' , ' c ' } else ' No ' ) NEW_LINE " V37,"import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long A = scanner . nextLong ( ) ; int K = scanner . nextInt ( ) ; long money = A ; long day = 0L ; if ( K > 0 ) { while ( money < 2000000000000L ) { money += money * K + 1 ; day ++ ; } } else if ( K == 0 ) { day = 2000000000000L - A ; } System . out . println ( day ) ; } } ","a , k = map ( int , input ( ) . split ( ) ) NEW_LINE if k == 0 : NEW_LINE INDENT print ( 2 * 10 ** 12 - a ) NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE while a < 2 * 10 ** 12 : NEW_LINE INDENT count += 1 NEW_LINE a += 1 + a * k NEW_LINE DEDENT print ( count ) NEW_LINE DEDENT " V38,"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int C = sc . nextInt ( ) ; int [ ] nml = new int [ 3 ] ; int [ ] maxNml = new int [ 3 ] ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) nml [ j ] = sc . nextInt ( ) ; Arrays . sort ( nml ) ; for ( int j = 0 ; j < 3 ; j ++ ) maxNml [ j ] = Math . max ( maxNml [ j ] , nml [ j ] ) ; } int ans = maxNml [ 0 ] * maxNml [ 1 ] * maxNml [ 2 ] ; System . out . println ( ans ) ; } } ","N = int ( input ( ) ) NEW_LINE n = m = l = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a . sort ( ) NEW_LINE n = max ( n , a [ 0 ] ) NEW_LINE m = max ( m , a [ 1 ] ) NEW_LINE l = max ( l , a [ 2 ] ) NEW_LINE DEDENT print ( n * m * l ) NEW_LINE " V39,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ; class Main { public static void main ( String args [ ] ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Solver solver = new Solver ( ) ; solver . init ( ) ; solver . readHead ( in . readLine ( ) ) ; for ( ; solver . hasNext ( ) ; ) { solver . readBody ( in . readLine ( ) ) ; } solver . solve ( ) ; } } class Solver { int N ; int M ; int cnt ; HashMap < Integer , Boolean > ChkMap ; public void init ( ) { N = 0 ; M = 0 ; cnt = 0 ; } public void readHead ( String str ) { String [ ] strArr = str . split ( "" ▁ "" ) ; N = Integer . parseInt ( strArr [ 0 ] ) ; M = Integer . parseInt ( strArr [ 1 ] ) ; ChkMap = new HashMap < Integer , Boolean > ( ) ; } public boolean hasNext ( ) { return cnt < M ; } public void readBody ( String str ) { String [ ] strArr = str . split ( "" ▁ "" ) ; for ( int i = 0 ; i < strArr . length ; i ++ ) { int v = Integer . parseInt ( strArr [ i ] ) ; if ( ChkMap . containsKey ( v ) ) { ChkMap . put ( v , ! ChkMap . get ( v ) ) ; } else { ChkMap . put ( v , true ) ; } } cnt ++ ; } public void solve ( ) { for ( int i : ChkMap . keySet ( ) ) { if ( ChkMap . get ( i ) ) { System . out . println ( "" NO "" ) ; return ; } } System . out . println ( "" YES "" ) ; } } ","n , m = map ( int , input ( ) . split ( ) ) NEW_LINE count = [ 0 ] * n NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE a -= 1 NEW_LINE b -= 1 NEW_LINE count [ a ] += 1 NEW_LINE count [ b ] += 1 NEW_LINE DEDENT for i in count : NEW_LINE INDENT if i % 2 == 1 : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( "" YES "" ) NEW_LINE " V40,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; long ans = 0 ; int last = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int a = sc . nextInt ( ) ; int eat = Math . max ( 0 , last + a - x ) ; ans += eat ; last = a - eat ; } System . out . println ( ans ) ; sc . close ( ) ; } } ","N , x = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE cnt = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if a [ i ] > x : NEW_LINE INDENT cnt += a [ i ] - x NEW_LINE a [ i ] = x NEW_LINE DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT su = a [ i - 1 ] + a [ i ] NEW_LINE if su > x : NEW_LINE INDENT sub = su - x NEW_LINE a [ i ] -= sub NEW_LINE cnt += sub NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE " V41,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; if ( a . equals ( b ) ) { System . out . println ( "" H "" ) ; } else { System . out . println ( "" D "" ) ; } } } ","s1 , s2 = map ( str , input ( ) . split ( ) ) NEW_LINE if s1 == s2 : NEW_LINE INDENT print ( ' H ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' D ' ) NEW_LINE DEDENT " V42,"import java . awt . * ; import java . util . * ; public class Main { public static void main ( String [ ] $ ) { Scanner s = new Scanner ( System . in ) ; Point a = new Point ( s . nextInt ( ) , s . nextInt ( ) ) , b = new Point ( s . nextInt ( ) , s . nextInt ( ) ) ; int m = s . nextInt ( ) * s . nextInt ( ) ; System . out . println ( java . util . stream . Stream . generate ( ( ) -> new Point ( s . nextInt ( ) , s . nextInt ( ) ) ) . limit ( s . nextInt ( ) ) . anyMatch ( p -> a . distance ( p ) + b . distance ( p ) <= m ) ? "" YES "" : "" NO "" ) ; } } ","tx_a , ty_a , tx_b , ty_b , T , V = map ( int , input ( ) . split ( ) ) NEW_LINE n = int ( input ( ) ) NEW_LINE flag = False NEW_LINE for _ in range ( n ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE if ( ( x - tx_a ) ** 2 + ( y - ty_a ) ** 2 ) ** ( 1 / 2 ) + ( ( tx_b - x ) ** 2 + ( ty_b - y ) ** 2 ) ** ( 1 / 2 ) <= T * V : NEW_LINE INDENT flag = True NEW_LINE DEDENT DEDENT print ( ' YES ' if flag else ' NO ' ) NEW_LINE " V43,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] map = { 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1 } ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; System . out . println ( map [ x - 1 ] == map [ y - 1 ] ? "" Yes "" : "" No "" ) ; } } ","N = set ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A = { 1 , 3 , 5 , 7 , 8 , 10 , 12 } NEW_LINE B = { 4 , 6 , 9 , 11 } NEW_LINE C = { 2 } NEW_LINE if ( N <= A or N <= B or N <= C ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT " V44,"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] odd = new int [ 10 ] ; int [ ] even = new int [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ( i + 1 ) % 2 == 1 ) { odd [ a - 1 ] ++ ; } else { even [ a - 1 ] ++ ; } } int max = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { if ( i != j ) { max = Math . max ( max , odd [ i ] + even [ j ] ) ; } } } int ans = c * ( n - max ) ; System . out . println ( ans ) ; } } ","from collections import defaultdict NEW_LINE d = defaultdict NEW_LINE n , c = map ( int , input ( ) . split ( ) ) NEW_LINE do = d ( int ) NEW_LINE de = d ( int ) NEW_LINE do [ 0 ] = 0 NEW_LINE de [ 0 ] = 0 NEW_LINE for i in range ( n // 2 ) : NEW_LINE INDENT do [ input ( ) ] += 1 NEW_LINE de [ input ( ) ] += 1 NEW_LINE DEDENT if n % 2 : NEW_LINE INDENT do [ input ( ) ] += 1 NEW_LINE DEDENT o = max ( do , key = do . get ) NEW_LINE e = max ( de , key = de . get ) NEW_LINE if o != e : NEW_LINE INDENT print ( ( n - do [ o ] - de [ e ] ) * c ) NEW_LINE DEDENT else : NEW_LINE INDENT vo = do . pop ( o ) NEW_LINE ve = de . pop ( e ) NEW_LINE vo2 = max ( do . values ( ) ) NEW_LINE ve2 = max ( de . values ( ) ) NEW_LINE print ( ( n - max ( vo + ve2 , ve + vo2 ) ) * c ) NEW_LINE DEDENT " V45,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] day = new int [ 366 ] ; for ( int i = 0 ; i < 366 ; i ++ ) { if ( ( i % 7 == 0 ) || ( i % 7 == 6 ) ) day [ i ] = 1 ; } int [ ] D = { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; int [ ] hin = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { String ho = sc . next ( ) ; String [ ] sp = ho . split ( "" / "" ) ; int m = Integer . parseInt ( sp [ 0 ] ) ; int d = Integer . parseInt ( sp [ 1 ] ) ; int sum = 0 ; for ( int j = 0 ; j < m - 1 ; j ++ ) { sum += D [ j ] ; } sum += d ; day [ sum - 1 ] ++ ; hin [ i ] = sum - 1 ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { int index = hin [ i ] ; if ( day [ index ] > 1 ) { day [ index ] = 1 ; for ( int j = index + 1 ; j < 366 ; j ++ ) { if ( day [ j ] == 0 ) { day [ j ] = 1 ; break ; } } } } for ( int i = 0 ; i < 366 ; i ++ ) { if ( ( i > 0 ) && ( day [ i ] > 0 ) ) day [ i ] += day [ i - 1 ] ; } int ans = 0 ; for ( int i = 0 ; i < 366 ; i ++ ) { ans = Math . max ( ans , day [ i ] ) ; } System . out . println ( ans ) ; } } ","N = int ( input ( ) ) NEW_LINE md = [ [ int ( _ ) for _ in input ( ) . split ( "" / "" ) ] for i in range ( N ) ] NEW_LINE day_of_month = [ 0 , 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] NEW_LINE from itertools import accumulate NEW_LINE index_of_month = list ( accumulate ( day_of_month ) ) NEW_LINE ds = [ 0 ] * 367 NEW_LINE for i in range ( 1 , len ( ds ) , 7 ) : NEW_LINE INDENT ds [ i ] = 1 NEW_LINE DEDENT for i in range ( 7 , len ( ds ) , 7 ) : NEW_LINE INDENT ds [ i ] = 1 NEW_LINE DEDENT for m , d in md : NEW_LINE INDENT i = index_of_month [ m - 1 ] + d NEW_LINE while ds [ i ] == 1 and i + 1 < len ( ds ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT ds [ i ] = 1 NEW_LINE DEDENT result = max ( len ( r ) for r in ( "" "" . join ( chr ( 32 + c ) for c in ds ) ) . split ( ) ) NEW_LINE print ( result ) NEW_LINE " V46,"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; D solver = new D ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class D { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) , d = in . nextInt ( ) ; int x = Math . abs ( in . nextInt ( ) ) , y = Math . abs ( in . nextInt ( ) ) ; if ( x % d != 0 || y % d != 0 ) { out . println ( 0.0 ) ; return ; } x /= d ; y /= d ; double [ ] [ ] comb = new double [ 1001 ] [ ] ; comb [ 0 ] = new double [ ] { 1.0 } ; for ( int i = 1 ; i <= 1000 ; i ++ ) { comb [ i ] = new double [ i + 1 ] ; comb [ i ] [ 0 ] = comb [ i ] [ i ] = comb [ i - 1 ] [ 0 ] / 2.0 ; for ( int j = 1 ; j < i ; j ++ ) { comb [ i ] [ j ] = ( comb [ i - 1 ] [ j - 1 ] + comb [ i - 1 ] [ j ] ) / 2.0 ; } } double ans = 0.0 ; for ( int i = 0 ; i <= n ; i ++ ) { if ( x <= i && y <= ( n - i ) && ( i - x ) % 2 == 0 && ( n - i - y ) % 2 == 0 ) { ans += comb [ n ] [ i ] * comb [ i ] [ ( i + x ) / 2 ] * comb [ n - i ] [ ( n - i + y ) / 2 ] ; } } out . println ( ans ) ; } } } ","n , d = map ( int , input ( ) . split ( ) ) NEW_LINE x , y = map ( int , input ( ) . split ( ) ) NEW_LINE C = [ [ 0 for j in range ( n + 1 ) ] for i in range ( n + 1 ) ] NEW_LINE C [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT C [ i ] [ 0 ] = C [ i - 1 ] [ 0 ] / 2 NEW_LINE for j in range ( 1 , i + 1 ) : NEW_LINE INDENT C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) / 2 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT k = ( i * d - x ) // d NEW_LINE l = ( j * d - y ) // d NEW_LINE if 0 <= k <= n and 0 <= l <= n and ( i - k ) * d == x and ( j - l ) * d == y and i + j + k + l == n : NEW_LINE INDENT ans += C [ n ] [ i + k ] * C [ i + k ] [ i ] * C [ j + l ] [ j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE " V47,"import java . util . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; BigInteger A = new BigInteger ( a ) ; BigInteger L = A . multiply ( A ) ; BigInteger C = A . add ( BigInteger . ONE ) ; BigInteger U = C . multiply ( C ) . subtract ( BigInteger . ONE ) ; BigInteger DIV = BigInteger . TEN . pow ( 2 ) ; BigInteger ADD = BigInteger . valueOf ( 99L ) ; for ( ; ; ) { BigInteger tL = L . add ( ADD ) . divide ( DIV ) ; BigInteger tU = U . divide ( DIV ) ; if ( tL . compareTo ( tU ) <= 0 ) { L = tL ; U = tU ; } else { break ; } } System . out . println ( L . toString ( ) ) ; } } ","a = int ( input ( ) ) NEW_LINE b = a + 1 NEW_LINE a = a * a NEW_LINE b = b * b - 1 NEW_LINE while ( a + 99 ) // 100 <= b // 100 : NEW_LINE INDENT a = ( a + 99 ) // 100 NEW_LINE b //= 100 NEW_LINE DEDENT print ( a ) NEW_LINE " V48,"import java . util . Scanner ; import java . util . Arrays ; public class Main { int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String A = sc . next ( ) ; char [ ] a = A . toCharArray ( ) ; Arrays . sort ( a ) ; long c = 1 ; long ans = 0 ; for ( int i = 1 ; i < ( long ) A . length ( ) ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { ans += ( c * ( c - 1 ) ) / 2 ; c = 1 ; } else { c ++ ; } } ans += ( c * ( c - 1 ) ) / 2 ; System . out . println ( ( ( long ) A . length ( ) * ( ( long ) A . length ( ) - 1 ) ) / 2 - ans + 1 ) ; } } ","from collections import defaultdict NEW_LINE A = list ( input ( ) ) NEW_LINE N = len ( A ) NEW_LINE D = defaultdict ( int ) NEW_LINE for i in A : NEW_LINE INDENT D [ i ] += 1 NEW_LINE DEDENT ans = 1 + int ( N * ( N - 1 ) / 2 ) NEW_LINE for i in D : NEW_LINE INDENT ans -= int ( D [ i ] * ( D [ i ] - 1 ) / 2 ) NEW_LINE DEDENT print ( ans ) NEW_LINE " V49,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long MOD = 1000000007 ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] f = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { f [ i ] = sc . nextInt ( ) - 1 ; } long [ ] dp = new long [ N ] ; long [ ] s = new long [ N ] ; dp [ 0 ] = 1 ; s [ 0 ] = 1 ; int [ ] num = new int [ M ] ; num [ f [ 0 ] ] ++ ; int start = 0 ; int end = 1 ; while ( end < N ) { if ( num [ f [ end ] ] == 0 ) { num [ f [ end ] ] ++ ; long a = 0 ; if ( start == 0 ) a = 1 + s [ end - 1 ] ; if ( start == 1 ) a = s [ end - 1 ] ; if ( start > 1 ) { if ( s [ end - 1 ] >= s [ start - 2 ] ) { a = s [ end - 1 ] - s [ start - 2 ] ; } else { a = s [ end - 1 ] - s [ start - 2 ] + MOD ; } } s [ end ] = ( s [ end - 1 ] + a ) % MOD ; if ( s [ end ] >= s [ end - 1 ] ) { dp [ end ] = s [ end ] - s [ end - 1 ] ; } else { dp [ end ] = s [ end ] - s [ end - 1 ] + MOD ; } end ++ ; } else { num [ f [ start ] ] -- ; start ++ ; } } System . out . println ( dp [ N - 1 ] ) ; } } ","N , M = map ( int , input ( ) . split ( ) ) NEW_LINE src = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE used = [ 0 ] * ( M + 1 ) NEW_LINE rtol = [ None ] * N NEW_LINE ans = 0 NEW_LINE r = 0 NEW_LINE for l in range ( N ) : NEW_LINE INDENT while r < N and not used [ src [ r ] ] : NEW_LINE INDENT used [ src [ r ] ] += 1 NEW_LINE rtol [ r ] = l NEW_LINE r += 1 NEW_LINE DEDENT used [ src [ l ] ] -= 1 NEW_LINE DEDENT MOD = 10 ** 9 + 7 NEW_LINE dp = [ 1 ] NEW_LINE cdp = [ 0 , 1 ] NEW_LINE for r in range ( N ) : NEW_LINE INDENT l = rtol [ r ] NEW_LINE dp . append ( cdp [ - 1 ] - cdp [ l ] ) NEW_LINE cdp . append ( ( cdp [ - 1 ] + dp [ - 1 ] ) % MOD ) NEW_LINE DEDENT print ( dp [ - 1 ] % MOD ) NEW_LINE " V50,"import java . util . * ; import java . io . * ; import java . awt . * ; import java . awt . geom . Point2D ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { PrintWriter O = new PrintWriter ( out ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int [ ] [ ] a = new int [ h ] [ w ] ; int [ ] point = new int [ 90001 ] ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { a [ i ] [ j ] = sc . nextInt ( ) ; point [ a [ i ] [ j ] ] = i * w + j ; } } long [ ] ds = new long [ h * w + 1 ] ; for ( int i = 1 ; i <= h * w ; i ++ ) { if ( i > d ) ds [ i ] = ds [ i - d ] + abs ( point [ i ] / w - point [ i - d ] / w ) + abs ( point [ i ] % w - point [ i - d ] % w ) ; } int q = sc . nextInt ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; O . println ( ds [ r ] - ds [ l ] ) ; } O . flush ( ) ; } static class sc { static Scanner s = new Scanner ( in ) ; static String next ( ) { return s . next ( ) ; } static int nextInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static long nextLong ( ) { return Long . parseLong ( s . next ( ) ) ; } static double nextDouble ( ) { return Double . parseDouble ( s . next ( ) ) ; } } } ","h , w , d = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( h ) ] NEW_LINE q = int ( input ( ) ) NEW_LINE l = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( q ) ] NEW_LINE dic = { } NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT for j in range ( len ( a [ i ] ) ) : NEW_LINE INDENT dic [ a [ i ] [ j ] ] = ( i , j ) NEW_LINE DEDENT DEDENT sum = [ 0 ] * ( h * w + 1 ) NEW_LINE for i in range ( d + 1 , h * w + 1 ) : NEW_LINE INDENT sum [ i ] = sum [ i - d ] + abs ( dic [ i ] [ 0 ] - dic [ i - d ] [ 0 ] ) + abs ( dic [ i ] [ 1 ] - dic [ i - d ] [ 1 ] ) NEW_LINE DEDENT for l_ in l : NEW_LINE INDENT print ( sum [ l_ [ 1 ] ] - sum [ l_ [ 0 ] ] ) NEW_LINE DEDENT " V51,"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int count = 0 ; int cnt = 0 ; for ( int i = 1 ; i <= n ; i += 2 ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( i % j == 0 ) { count ++ ; } } if ( count == 8 ) { cnt ++ ; } count = 0 ; } System . out . println ( cnt ) ; } } ","N = int ( input ( ) ) NEW_LINE def make_divisors ( n ) : NEW_LINE INDENT divisors = [ ] NEW_LINE for i in range ( 1 , int ( n ** 0.5 ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT divisors . append ( i ) NEW_LINE if i != n // i : NEW_LINE INDENT divisors . append ( n // i ) NEW_LINE DEDENT DEDENT DEDENT return divisors NEW_LINE DEDENT ans = 0 NEW_LINE if N % 2 == 0 : NEW_LINE INDENT for j in range ( int ( N / 2 ) ) : NEW_LINE INDENT temp = len ( make_divisors ( 2 * j + 1 ) ) NEW_LINE if temp == 8 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT for j in range ( int ( N / 2 ) + 1 ) : NEW_LINE INDENT temp = len ( make_divisors ( 2 * j + 1 ) ) NEW_LINE if temp == 8 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE " V52,"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( Math . pow ( n / 2 , 2 ) ) ; } } ","def max_mul ( A : int ) -> int : NEW_LINE INDENT return ( A * A ) // 4 NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE ans = max_mul ( A ) NEW_LINE print ( ans ) NEW_LINE DEDENT " V53,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; System . out . println ( ( a >= 60 ) ? ( a >= 90 ) ? ( a == 100 ) ? "" Perfect "" : "" Great "" : "" Good "" : "" Bad "" ) ; } } ","def eval_test ( N : int ) -> int : NEW_LINE INDENT if N < 60 : NEW_LINE INDENT return ' Bad ' NEW_LINE DEDENT if N < 90 : NEW_LINE INDENT return ' Good ' NEW_LINE DEDENT if N < 100 : NEW_LINE INDENT return ' Great ' NEW_LINE DEDENT return ' Perfect ' NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE ans = eval_test ( N ) NEW_LINE print ( ans ) NEW_LINE DEDENT " V54,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; boolean [ ] [ ] block = new boolean [ h + 1 ] [ w + 1 ] ; for ( int i = 0 ; i <= h ; i ++ ) { block [ i ] [ w ] = true ; } Arrays . fill ( block [ h ] , true ) ; for ( int i = 0 ; i < h ; i ++ ) { String line = sc . next ( ) ; char [ ] array = line . toCharArray ( ) ; for ( int j = 0 ; j < w ; j ++ ) { block [ i ] [ j ] = ( array [ j ] == ' # ' ) ; } } boolean [ ] [ ] win = new boolean [ h + 1 ] [ w + 1 ] ; for ( int i = h ; i >= 0 ; i -- ) { for ( int j = w ; j >= 0 ; j -- ) { if ( block [ i ] [ j ] ) { win [ i ] [ j ] = true ; } else if ( win [ i + 1 ] [ j ] && win [ i + 1 ] [ j + 1 ] && win [ i ] [ j + 1 ] ) { win [ i ] [ j ] = false ; } else { win [ i ] [ j ] = true ; } } } System . out . println ( win [ 0 ] [ 0 ] ? "" First "" : "" Second "" ) ; } } ","def inin ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def insp ( ) : NEW_LINE INDENT return input ( ) . split ( ) NEW_LINE DEDENT s = [ ] NEW_LINE d = [ ] NEW_LINE r = [ ] NEW_LINE def dfs ( x , y ) : NEW_LINE INDENT global s NEW_LINE global d NEW_LINE global r NEW_LINE if d [ x ] [ y ] : NEW_LINE INDENT return r [ x ] [ y ] NEW_LINE DEDENT d [ x ] [ y ] = True NEW_LINE if s [ x ] [ y ] == ' # ' : NEW_LINE INDENT r [ x ] [ y ] = True NEW_LINE return r [ x ] [ y ] NEW_LINE DEDENT if not dfs ( x , y + 1 ) : NEW_LINE INDENT r [ x ] [ y ] = True NEW_LINE return r [ x ] [ y ] NEW_LINE DEDENT if not dfs ( x + 1 , y ) : NEW_LINE INDENT r [ x ] [ y ] = True NEW_LINE return r [ x ] [ y ] NEW_LINE DEDENT if not dfs ( x + 1 , y + 1 ) : NEW_LINE INDENT r [ x ] [ y ] = True NEW_LINE return r [ x ] [ y ] NEW_LINE DEDENT r [ x ] [ y ] = False NEW_LINE return r [ x ] [ y ] NEW_LINE DEDENT h , w = map ( int , insp ( ) ) NEW_LINE for i in range ( h + 2 ) : NEW_LINE INDENT d . append ( [ ] ) NEW_LINE r . append ( [ ] ) NEW_LINE for j in range ( w + 2 ) : NEW_LINE INDENT d [ i ] . append ( False ) NEW_LINE r [ i ] . append ( False ) NEW_LINE DEDENT DEDENT s . append ( [ ] ) NEW_LINE for i in range ( w + 2 ) : NEW_LINE INDENT s [ 0 ] . append ( ' # ' ) NEW_LINE DEDENT for i in range ( h ) : NEW_LINE INDENT s . append ( [ ' # ' ] + list ( input ( ) ) + [ ' # ' ] ) NEW_LINE DEDENT s . append ( [ ] ) NEW_LINE for i in range ( w + 2 ) : NEW_LINE INDENT s [ h + 1 ] . append ( ' # ' ) NEW_LINE DEDENT if dfs ( 1 , 1 ) : NEW_LINE INDENT print ( "" First "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Second "" ) NEW_LINE DEDENT " V55,"public class Main { public static void main ( String [ ] args ) { java . util . Scanner c = new java . util . Scanner ( System . in ) ; String s = c . next ( ) , t = c . next ( ) ; java . util . regex . Matcher matcher = java . util . regex . Pattern . compile ( "" ( . * ) "" + t . replaceAll ( "" . "" , "" [ $ 0 ? ] "" ) + "" ( . * ? ) "" ) . matcher ( s ) ; System . out . println ( matcher . matches ( ) ? matcher . replaceFirst ( "" $ 1"" + t + "" $ 2"" ) . replace ( ' ? ' , ' a ' ) : "" UNRESTORABLE "" ) ; } } ","s = input ( ) . rstrip ( ) NEW_LINE t = input ( ) . rstrip ( ) NEW_LINE pushable = [ 1 ] * ( len ( s ) - len ( t ) + 1 ) NEW_LINE for i in range ( len ( s ) - len ( t ) + 1 ) : NEW_LINE INDENT for j in range ( len ( t ) ) : NEW_LINE INDENT if s [ i + j ] != t [ j ] and s [ i + j ] != "" ? "" : NEW_LINE INDENT pushable [ i ] = 0 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if 1 not in pushable : NEW_LINE INDENT print ( "" UNRESTORABLE "" ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = [ ] NEW_LINE for i , p in enumerate ( pushable ) : NEW_LINE INDENT cand = s NEW_LINE if p : NEW_LINE INDENT for j in range ( len ( t ) ) : NEW_LINE INDENT cand = cand [ : i + j ] + t [ j ] + cand [ i + j + 1 : ] NEW_LINE DEDENT for j in range ( len ( s ) ) : NEW_LINE INDENT if cand [ j ] == "" ? "" : NEW_LINE INDENT cand = cand [ : j ] + "" a "" + cand [ j + 1 : ] NEW_LINE DEDENT DEDENT ans . append ( cand ) NEW_LINE DEDENT DEDENT print ( sorted ( ans ) [ 0 ] ) NEW_LINE " V56,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arrC = new int [ n ] ; int [ ] arrS = new int [ n ] ; int [ ] arrF = new int [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { arrC [ i ] = sc . nextInt ( ) ; arrS [ i ] = sc . nextInt ( ) ; arrF [ i ] = sc . nextInt ( ) ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int total = 0 ; for ( int j = i ; j < n - 1 ; j ++ ) { if ( total < arrS [ j ] ) { total = arrS [ j ] ; } if ( total % arrF [ j ] != 0 ) { total += arrF [ j ] - total % arrF [ j ] ; } total += arrC [ j ] ; } sb . append ( total ) . append ( "" \n "" ) ; } sb . append ( 0 ) . append ( "" \n "" ) ; System . out . print ( sb ) ; } } ","n = int ( input ( ) ) NEW_LINE c = [ ] NEW_LINE s = [ ] NEW_LINE f = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT x , y , z = map ( int , input ( ) . split ( ) ) NEW_LINE c . append ( x ) NEW_LINE s . append ( y ) NEW_LINE f . append ( z ) NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT t = 0 NEW_LINE for j in range ( i , n - 1 ) : NEW_LINE INDENT if t <= s [ j ] : NEW_LINE INDENT w = s [ j ] - t NEW_LINE DEDENT else : NEW_LINE INDENT w = ( f [ j ] - ( t - s [ j ] ) % f [ j ] ) % f [ j ] NEW_LINE DEDENT t += w NEW_LINE t += c [ j ] NEW_LINE DEDENT print ( t ) NEW_LINE DEDENT print ( 0 ) NEW_LINE " V57,"import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { String a = sc . next ( ) ; String c = null ; if ( a . contains ( ""9"" ) ) { c = "" Yes "" ; } else { c = "" No "" ; } System . out . println ( c ) ; System . out . flush ( ) ; sc . close ( ) ; } } ","n = input ( ) NEW_LINE if ""9"" in n : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V58,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String dir = new String [ ] { "" N "" , "" NNE "" , "" NE "" , "" ENE "" , "" E "" , "" ESE "" , "" SE "" , "" SSE "" , "" S "" , "" SSW "" , "" SW "" , "" WSW "" , "" W "" , "" WNW "" , "" NW "" , "" NNW "" } [ ( ( sc . nextInt ( ) * 10 + 1125 ) / 2250 ) % 16 ] ; int [ ] power = new int [ ] { 2 , 15 , 33 , 54 , 79 , 107 , 138 , 171 , 207 , 244 , 284 , 326 , Integer . MAX_VALUE } ; int speed = Double . valueOf ( Math . round ( sc . nextInt ( ) / 6D ) ) . intValue ( ) ; for ( int i = 0 ; i <= power . length ; i ++ ) { if ( speed > power [ i ] ) continue ; System . out . println ( ( i == 0 ? "" C "" : dir ) + "" ▁ "" + i ) ; break ; } } } ","a , b = map ( int , input ( ) . split ( ) ) NEW_LINE d = [ "" N "" , "" NNE "" , "" NE "" , "" ENE "" , "" E "" , "" ESE "" , "" SE "" , "" SSE "" , "" S "" , "" SSW "" , "" SW "" , "" WSW "" , "" W "" , "" WNW "" , "" NW "" , "" NNW "" ] NEW_LINE if a < 112.5 or a >= 3487.5 : NEW_LINE INDENT a = d [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT a = d [ int ( ( a + 112.5 ) / 225 ) ] NEW_LINE DEDENT w = [ 0.2 , 1.5 , 3.3 , 5.4 , 7.9 , 10.7 , 13.8 , 17.1 , 20.7 , 24.4 , 28.4 , 32.6 ] NEW_LINE b /= 60 NEW_LINE b += 0.00001 NEW_LINE c = int ( b * 100 ) NEW_LINE if c % 10 >= 5 : NEW_LINE INDENT c += 10 NEW_LINE DEDENT c //= 10 NEW_LINE b = c / 10.0 NEW_LINE for i in range ( 12 ) : NEW_LINE INDENT if b <= w [ i ] : NEW_LINE INDENT b = i NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT b = 12 NEW_LINE DEDENT if b == 0 : NEW_LINE INDENT print ( ' C ▁ 0' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a , b ) NEW_LINE DEDENT " V59,"import java . util . * ; public class Main { static int R , C ; public static class Terminal { int d ; int idx ; public Terminal ( int d , int idx ) { this . d = d ; this . idx = idx ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; R = sc . nextInt ( ) ; C = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; ArrayList < Terminal > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x1 = sc . nextInt ( ) ; int y1 = sc . nextInt ( ) ; int x2 = sc . nextInt ( ) ; int y2 = sc . nextInt ( ) ; if ( isOnEdge ( x1 , y1 ) && isOnEdge ( x2 , y2 ) ) { list . add ( new Terminal ( convert ( x1 , y1 ) , i ) ) ; list . add ( new Terminal ( convert ( x2 , y2 ) , i ) ) ; } } Collections . sort ( list , new Comparator < Terminal > ( ) { public int compare ( Terminal t1 , Terminal t2 ) { return t1 . d - t2 . d ; } } ) ; LinkedList < Terminal > stack = new LinkedList < > ( ) ; for ( Terminal t : list ) { if ( ! stack . isEmpty ( ) && stack . peek ( ) . idx == t . idx ) stack . pop ( ) ; else stack . push ( t ) ; } System . out . println ( stack . isEmpty ( ) ? "" YES "" : "" NO "" ) ; sc . close ( ) ; } static boolean isOnEdge ( int x , int y ) { return x == 0 || x == R || y == 0 || y == C ; } static int convert ( int x , int y ) { if ( x == 0 ) return y ; else if ( y == C ) return C + x ; else if ( x == R ) return C + R + ( C - y ) ; else return C + R + C + ( R - x ) ; } } ","import heapq NEW_LINE def coord_on_edge ( x , y , R , C ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return x NEW_LINE DEDENT if x == R : NEW_LINE INDENT return R + y NEW_LINE DEDENT if y == C : NEW_LINE INDENT return R + C + R - x NEW_LINE DEDENT if x == 0 : NEW_LINE INDENT return 2 * ( R + C ) - y NEW_LINE DEDENT return None NEW_LINE DEDENT def on_edge ( x1 , y1 , x2 , y2 , R , C , i , edge_points ) : NEW_LINE INDENT c1 = coord_on_edge ( x1 , y1 , R , C ) NEW_LINE c2 = coord_on_edge ( x2 , y2 , R , C ) NEW_LINE if c1 is not None and c2 is not None : NEW_LINE INDENT heapq . heappush ( edge_points , ( c1 , i ) ) NEW_LINE heapq . heappush ( edge_points , ( c2 , i ) ) NEW_LINE DEDENT DEDENT def solve ( ) : NEW_LINE INDENT R , C , N = map ( int , input ( ) . split ( ) ) NEW_LINE edge_points = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT x1 , y1 , x2 , y2 = map ( int , input ( ) . split ( ) ) NEW_LINE on_edge ( x1 , y1 , x2 , y2 , R , C , i , edge_points ) NEW_LINE DEDENT q = [ ] NEW_LINE while edge_points : NEW_LINE INDENT c , i = heapq . heappop ( edge_points ) NEW_LINE if len ( q ) and q [ - 1 ] == i : NEW_LINE INDENT q . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT q . append ( i ) NEW_LINE DEDENT DEDENT if len ( q ) : NEW_LINE INDENT return "" NO "" NEW_LINE DEDENT return "" YES "" NEW_LINE DEDENT print ( solve ( ) ) NEW_LINE " V60,"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = Math . abs ( Integer . parseInt ( sc . next ( ) ) ) ; int b = Math . abs ( Integer . parseInt ( sc . next ( ) ) ) ; if ( a < b ) { System . out . println ( "" Ant "" ) ; } else if ( a > b ) { System . out . println ( "" Bug "" ) ; } else { System . out . println ( "" Draw "" ) ; } sc . close ( ) ; } } ","A , B = map ( int , input ( ) . split ( ) ) NEW_LINE if abs ( A ) < abs ( B ) : NEW_LINE INDENT print ( "" Ant "" ) NEW_LINE DEDENT elif abs ( A ) > abs ( B ) : NEW_LINE INDENT print ( "" Bug "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Draw "" ) NEW_LINE DEDENT " V61,"import java . io . PrintStream ; import java . util . Scanner ; public class Main { static void exec ( Scanner in , PrintStream out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int C = in . nextInt ( ) ; int X = in . nextInt ( ) ; int Y = in . nextInt ( ) ; if ( C * 2 < A + B ) { int price = C * 2 * Math . min ( X , Y ) ; if ( X < Y ) { if ( C * 2 < B ) { price += C * 2 * ( Y - X ) ; } else { price += B * ( Y - X ) ; } } else if ( X > Y ) { if ( C * 2 < A ) { price += C * 2 * ( X - Y ) ; } else { price += A * ( X - Y ) ; } } out . println ( price ) ; } else { out . println ( A * X + B * Y ) ; } } public static void main ( String [ ] args ) { exec ( new Scanner ( System . in ) , System . out ) ; } } ","A , B , C , X , Y = map ( int , input ( ) . split ( ) ) NEW_LINE cost = [ ] NEW_LINE for i in range ( 10 ** 5 + 1 ) : NEW_LINE INDENT x = i NEW_LINE y = i NEW_LINE a = max ( X - i , 0 ) NEW_LINE b = max ( Y - i , 0 ) NEW_LINE cost . append ( A * a + B * b + C * 2 * i ) NEW_LINE DEDENT print ( min ( cost ) ) NEW_LINE " V62,"import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; @ SuppressWarnings ( "" unchecked "" ) public class Main { static final char plus = ' + ' ; static final char multi = ' * ' ; public static void main ( String [ ] args ) throws IOException { final String S ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { S = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; int ans = 0 ; int i = 0 ; boolean flg = false ; int num = 0 ; char symbol = ' ▁ ' ; int len = S . length ( ) ; while ( i < len ) { num = Character . getNumericValue ( S . charAt ( i ++ ) ) ; if ( len - 2 < i ) break ; symbol = S . charAt ( i ++ ) ; if ( symbol == plus ) { if ( ! flg && num != 0 ) ans ++ ; flg = false ; } else { if ( num == 0 ) flg = true ; } } if ( ! flg && num != 0 ) ans ++ ; out . println ( ans ) ; out . flush ( ) ; } } ","print ( sum ( [ not '0' in s for s in input ( ) . split ( ' + ' ) ] ) ) NEW_LINE " V63,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String zero = "" "" ; for ( int i = 0 ; i < N ; i ++ ) { zero += ""0"" ; } for ( int i = 0 ; i < Math . pow ( 3 , N ) ; i ++ ) { String t = zero + Integer . toString ( i , 3 ) ; t = t . substring ( t . length ( ) - N ) ; for ( char c : t . toCharArray ( ) ) { System . out . print ( ( char ) ( ' a ' + Character . getNumericValue ( c ) ) ) ; } System . out . println ( ) ; } } } ","N = int ( input ( ) ) NEW_LINE ps_ls = [ ] NEW_LINE def dfs ( s ) : NEW_LINE INDENT global ps_ls NEW_LINE if len ( s ) == N : NEW_LINE INDENT ps_ls . append ( s ) NEW_LINE return NEW_LINE DEDENT dfs ( s + ' a ' ) NEW_LINE dfs ( s + ' b ' ) NEW_LINE dfs ( s + ' c ' ) NEW_LINE DEDENT dfs ( ' ' ) NEW_LINE ps_ls = sorted ( ps_ls ) NEW_LINE for ps in ps_ls : NEW_LINE INDENT print ( ps ) NEW_LINE DEDENT " V64,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { new Main ( ) . solve ( in ) ; } } private void solve ( Scanner in ) { int N = in . nextInt ( ) , K = in . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = in . nextInt ( ) ; } java . util . Arrays . sort ( a ) ; int from = - 1 ; int to = N ; while ( from + 1 < to ) { int n = ( to + from ) / 2 ; if ( a [ n ] >= K ) { to = n ; continue ; } boolean [ ] [ ] dp = new boolean [ N + 1 ] [ K ] ; dp [ 0 ] [ 0 ] = true ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < K ; j ++ ) { if ( n != i && a [ i ] + j < K ) { dp [ i + 1 ] [ a [ i ] + j ] |= dp [ i ] [ j ] ; } dp [ i + 1 ] [ j ] |= dp [ i ] [ j ] ; } } boolean nece = false ; for ( int j = K - a [ n ] ; j < K ; j ++ ) { if ( dp [ N ] [ j ] ) { nece = true ; break ; } } if ( nece ) { to = n ; } else { from = n ; } } int ans = to ; System . out . println ( ans ) ; } } ","import bisect NEW_LINE def solve ( k , aaa ) : NEW_LINE INDENT aaa = aaa [ : bisect . bisect_left ( aaa , k ) ] NEW_LINE dp = [ False ] * k NEW_LINE dp [ 0 ] = True NEW_LINE curr_max = 0 NEW_LINE ans = len ( aaa ) NEW_LINE for i , a in reversed ( list ( enumerate ( aaa ) ) ) : NEW_LINE INDENT if curr_max + a >= k : NEW_LINE INDENT ans = i NEW_LINE DEDENT f = True NEW_LINE for j in range ( min ( curr_max , k - a - 1 ) , - 1 , - 1 ) : NEW_LINE INDENT if dp [ j ] : NEW_LINE INDENT dp [ j + a ] = True NEW_LINE if f : NEW_LINE INDENT curr_max = max ( curr_max , j + a ) NEW_LINE f = False NEW_LINE DEDENT DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE aaa = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE aaa . sort ( ) NEW_LINE print ( solve ( k , aaa ) ) NEW_LINE " V65,"import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; ArrayList < Integer > A = new ArrayList ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { A . add ( sc . nextInt ( ) ) ; } int a = A . get ( A . size ( ) - 1 ) ; for ( int i = A . size ( ) - 2 ; i >= 0 ; i -- ) { a = gcd ( a , A . get ( i ) ) ; } System . out . println ( a ) ; } static int gcd ( int a , int b ) { if ( b == 1 ) return 1 ; if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details . ","N = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a . sort ( ) NEW_LINE G = a [ 0 ] NEW_LINE for i in range ( 1 , N , 1 ) : NEW_LINE INDENT A = a [ i ] NEW_LINE while A % G != 0 : NEW_LINE INDENT A , G = G , A % G NEW_LINE DEDENT DEDENT print ( G ) NEW_LINE " V66,"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( b - a == c - b ) { System . out . println ( "" YES "" ) ; } else { System . out . println ( "" NO "" ) ; } } } ","a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE if b - a == c - b : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT " V67,"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { static final BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) throws Exception { int num = Integer . parseInt ( in . readLine ( ) ) ; long [ ] vals = getNums ( in . readLine ( ) . split ( "" ▁ "" ) , num * 3 ) ; in . close ( ) ; Arrays . parallelSort ( vals ) ; long sum = 0 ; for ( int i = num ; i < num * 3 ; i += 2 ) { sum += vals [ i ] ; } System . out . println ( sum ) ; } public static long [ ] getNums ( String [ ] vals , int num ) { long [ ] vAry = new long [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { vAry [ i ] = Integer . parseInt ( vals [ i ] ) ; } return vAry ; } } ","N = int ( input ( ) ) NEW_LINE list = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE list . sort ( ) NEW_LINE result = 0 NEW_LINE for i in list [ : : - 1 ] [ 1 : : 2 ] [ : N ] : NEW_LINE INDENT result += i NEW_LINE DEDENT print ( result ) NEW_LINE " V68,"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner a = new Scanner ( System . in ) ; String c [ ] [ ] = new String [ 4 ] [ 4 ] ; for ( int i = 0 ; i <= 3 ; i ++ ) { for ( int j = 0 ; j <= 3 ; j ++ ) { c [ i ] [ j ] = a . next ( ) ; } } for ( int i = 3 ; i >= 0 ; i -- ) { for ( int j = 3 ; j >= 0 ; j -- ) { if ( j == 0 ) { System . out . print ( c [ i ] [ j ] + "" \n "" ) ; } else { System . out . print ( c [ i ] [ j ] + "" ▁ "" ) ; } } } } } ","a , b , c , d = input ( ) . split ( ) NEW_LINE e , f , g , h = input ( ) . split ( ) NEW_LINE i , j , k , l = input ( ) . split ( ) NEW_LINE m , n , o , p = input ( ) . split ( ) NEW_LINE print ( p + "" ▁ "" + o + "" ▁ "" + n + "" ▁ "" + m ) NEW_LINE print ( l + "" ▁ "" + k + "" ▁ "" + j + "" ▁ "" + i ) NEW_LINE print ( h + "" ▁ "" + g + "" ▁ "" + f + "" ▁ "" + e ) NEW_LINE print ( d + "" ▁ "" + c + "" ▁ "" + b + "" ▁ "" + a ) NEW_LINE " V69,"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int q = sc . nextInt ( ) ; boolean [ ] p = new boolean [ 100001 ] ; Arrays . fill ( p , true ) ; p [ 0 ] = false ; p [ 1 ] = false ; boolean [ ] s = new boolean [ 100001 ] ; int [ ] sum = new int [ 100001 ] ; for ( int i = 2 ; i <= 100000 ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; if ( p [ i ] ) { for ( int j = 2 * i ; j <= 100000 ; j += i ) p [ j ] = false ; if ( p [ ( i + 1 ) / 2 ] ) { s [ i ] = true ; sum [ i ] ++ ; } } } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; sb . append ( sum [ r ] - sum [ l - 1 ] ) . append ( "" \n "" ) ; } System . out . println ( sb . toString ( ) ) ; sc . close ( ) ; } } ","INPUT_MAX = 101010 NEW_LINE is_prime = [ 1 ] * INPUT_MAX NEW_LINE is_prime [ 0 ] = 0 NEW_LINE is_prime [ 1 ] = 0 NEW_LINE for i in range ( 2 , INPUT_MAX ) : NEW_LINE INDENT if not is_prime [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT for k in range ( i * 2 , INPUT_MAX , i ) : NEW_LINE INDENT is_prime [ k ] = 0 NEW_LINE DEDENT DEDENT a = [ 0 ] * INPUT_MAX NEW_LINE for i in range ( INPUT_MAX ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ( i + 1 ) % 2 != 0 : continue NEW_LINE if is_prime [ i ] and is_prime [ int ( ( i + 1 ) / 2 ) ] : NEW_LINE INDENT a [ i ] = 1 NEW_LINE DEDENT DEDENT s = [ 0 ] * ( INPUT_MAX + 1 ) NEW_LINE for i in range ( INPUT_MAX ) : NEW_LINE INDENT s [ i + 1 ] = s [ i ] + a [ i ] NEW_LINE DEDENT Q = int ( input ( ) ) NEW_LINE for q in range ( Q ) : NEW_LINE INDENT l , r = map ( int , input ( ) . split ( ) ) NEW_LINE r += 1 NEW_LINE print ( s [ r ] - s [ l ] ) NEW_LINE DEDENT " V70,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; out . println ( a + b == c || b + c == a || c + a == b ? "" Yes "" : "" No "" ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } } ","a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE l = sorted ( [ a , b , c ] ) NEW_LINE if l [ 0 ] + l [ 1 ] == l [ 2 ] : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V71,"import gcj . GCJ ; import java . util . Arrays ; import java . util . Scanner ; public class Osmos { public static void main ( String [ ] args ) { Scanner s = GCJ . createScanner ( ' A ' , true ) ; int T = s . nextInt ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { int size = s . nextInt ( ) ; int N = s . nextInt ( ) ; int [ ] m = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { m [ j ] = s . nextInt ( ) ; } Arrays . sort ( m ) ; int min = N ; if ( size > 1 ) { int cnt = 0 ; for ( int j = 0 ; j < N ; j ++ ) { while ( size <= m [ j ] ) { cnt ++ ; size += size - 1 ; } size += m [ j ] ; min = Math . min ( min , cnt + N - j - 1 ) ; } } GCJ . out ( i , Integer . toString ( min ) ) ; } } } ","FILE_NAME_BASE = ' A - large ' NEW_LINE NUM_PROCESSES = 0 NEW_LINE MEM_LIMIT_GB = 1.5 NEW_LINE RECURSION_LIMIT = 1000 NEW_LINE def parse ( inp ) : NEW_LINE INDENT start , num = ( int ( x ) for x in inp . readline ( ) . split ( ) ) NEW_LINE motes = tuple ( int ( x ) for x in inp . readline ( ) . split ( ) ) NEW_LINE assert len ( motes ) == num NEW_LINE return start , motes NEW_LINE DEDENT def solve ( start , motes ) : NEW_LINE INDENT motes = sorted ( motes ) NEW_LINE num = len ( motes ) NEW_LINE best = num NEW_LINE size = start NEW_LINE added = 0 NEW_LINE i = 0 NEW_LINE while i < num : NEW_LINE INDENT if motes [ i ] < size : NEW_LINE INDENT size += motes [ i ] NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT best = min ( best , added + num - i ) NEW_LINE if size <= 1 : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT while motes [ i ] - size >= 0 : NEW_LINE INDENT size += size - 1 NEW_LINE added += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT else : NEW_LINE INDENT best = min ( best , added ) NEW_LINE DEDENT return best NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT import sys NEW_LINE sys . setrecursionlimit ( RECURSION_LIMIT ) NEW_LINE import resource NEW_LINE soft , hard = resource . getrlimit ( resource . RLIMIT_AS ) NEW_LINE resource . setrlimit ( resource . RLIMIT_AS , ( MEM_LIMIT_GB * 1024 ** 3 , hard ) ) NEW_LINE inp = open ( FILE_NAME_BASE + ' . in ' , ' r ' ) NEW_LINE numCases = int ( inp . readline ( ) ) NEW_LINE if NUM_PROCESSES == 0 : NEW_LINE INDENT results = [ solve ( * parse ( inp ) ) for _ in range ( numCases ) ] NEW_LINE DEDENT else : NEW_LINE INDENT from multiprocessing import Pool NEW_LINE pool = Pool ( NUM_PROCESSES ) NEW_LINE results = [ pool . apply_async ( solve , parse ( inp ) ) for _ in range ( numCases ) ] NEW_LINE DEDENT inp . close ( ) NEW_LINE out = open ( FILE_NAME_BASE + ' . out ' , ' w ' ) NEW_LINE for case , result in enumerate ( results ) : NEW_LINE INDENT value = result if NUM_PROCESSES == 0 else result . get ( ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % s \n ' % ( case + 1 , value ) ) NEW_LINE out . flush ( ) NEW_LINE DEDENT out . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V72,"import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { int B = in . nextInt ( ) ; long N = in . nextInt ( ) ; long [ ] M = new long [ B ] ; for ( int i = 0 ; i < B ; i ++ ) M [ i ] = in . nextInt ( ) ; long start = 0 ; long end = ( long ) 1e16 ; while ( start < end ) { long mid = ( start + end ) / 2 ; long count = 0 ; for ( long t : M ) { count += ( mid / t ) + 1 ; } if ( count >= N ) { end = mid ; } else { start = mid + 1 ; } } long count = 0 ; long exact = 0 ; for ( long t : M ) { count += ( start / t ) + 1 ; if ( start % t == 0 ) exact ++ ; } long before = count - exact ; int ans = - 1 ; for ( int i = 0 ; i < B ; i ++ ) { if ( start % M [ i ] != 0 ) continue ; if ( before + 1 == N ) { ans = i ; break ; } before ++ ; } System . out . format ( "" Case ▁ # % d : ▁ % d \n "" , zz , ans + 1 ) ; } } } ","def read ( parse ) : NEW_LINE INDENT return [ parse ( _ ) for _ in raw_input ( ) . split ( ) ] NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT B , N = read ( int ) NEW_LINE ar = read ( int ) NEW_LINE if N <= B : NEW_LINE INDENT return N NEW_LINE DEDENT def count ( t ) : NEW_LINE INDENT return sum ( t / x for x in ar ) NEW_LINE DEDENT lo = 0 NEW_LINE hi = N * min ( ar ) NEW_LINE while lo < hi : NEW_LINE INDENT mid = ( lo + hi ) / 2 NEW_LINE if count ( mid ) >= N - B : NEW_LINE INDENT hi = mid NEW_LINE DEDENT else : NEW_LINE INDENT lo = mid + 1 NEW_LINE DEDENT DEDENT place = ( N - B ) - count ( lo - 1 ) NEW_LINE lst = [ x for x in range ( B ) if lo % ar [ x ] == 0 ] NEW_LINE return lst [ place - 1 ] + 1 NEW_LINE DEDENT T = input ( ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % d ' % ( t , solve ( ) ) NEW_LINE DEDENT " V73,"import static java . lang . Math . * ; import static java . math . BigInteger . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import java . math . * ; import java . util . * ; public class D { char [ ] cs ; int n ; public static void main ( String [ ] args ) { new D ( ) . run ( ) ; } void run ( ) { Scanner sc = new Scanner ( System . in ) ; int on = sc . nextInt ( ) ; for ( int o = 1 ; o <= on ; o ++ ) { System . out . printf ( "" Case ▁ # % d : ▁ "" , o ) ; n = sc . nextInt ( ) ; cs = sc . next ( ) . toCharArray ( ) ; System . out . println ( permRec ( new int [ n ] , new boolean [ n ] , 0 ) ) ; } } int permRec ( int [ ] a , boolean [ ] used , int p ) { if ( p == a . length ) { char last = 0 ; int res = 0 ; for ( int i = 0 ; i < cs . length ; i += n ) { for ( int j = 0 ; j < n ; j ++ ) { char c = cs [ i + a [ j ] ] ; if ( c != last ) { res ++ ; last = c ; } } } return res ; } else { int res = Integer . MAX_VALUE ; for ( a [ p ] = 0 ; a [ p ] < used . length ; a [ p ] ++ ) if ( ! used [ a [ p ] ] ) { used [ a [ p ] ] = true ; res = min ( res , permRec ( a , used , p + 1 ) ) ; used [ a [ p ] ] = false ; } return res ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } } ","def genperm ( rem ) : NEW_LINE INDENT if rem : NEW_LINE INDENT for i in rem : NEW_LINE INDENT for perm in genperm ( rem - set ( [ i ] ) ) : NEW_LINE INDENT yield [ i ] + perm NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT yield [ ] NEW_LINE DEDENT DEDENT def permute ( perm , s ) : NEW_LINE INDENT return ' ' . join ( s [ p ] for p in perm ) NEW_LINE DEDENT def compress ( s ) : NEW_LINE INDENT prev = None NEW_LINE n = 0 NEW_LINE for c in s : NEW_LINE INDENT if c != prev : NEW_LINE INDENT n += 1 NEW_LINE prev = c NEW_LINE DEDENT DEDENT return n NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT permSize = int ( raw_input ( ) ) NEW_LINE data = raw_input ( ) NEW_LINE permutations = list ( genperm ( set ( range ( permSize ) ) ) ) NEW_LINE clen = 1000000000 NEW_LINE for perm in permutations : NEW_LINE INDENT permData = ' ' NEW_LINE for i in range ( 0 , len ( data ) , permSize ) : NEW_LINE INDENT permData += permute ( perm , data [ i : i + permSize ] ) NEW_LINE DEDENT clen = min ( clen , compress ( permData ) ) NEW_LINE DEDENT return clen NEW_LINE DEDENT import psyco NEW_LINE psyco . full ( ) NEW_LINE for case in range ( int ( raw_input ( ) ) ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( case + 1 , solve ( ) ) NEW_LINE DEDENT " V74,"import java . util . * ; import java . io . * ; import java . math . * ; public class a { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( args [ 0 ] ) ) ; String str ; int numCases = Integer . parseInt ( br . readLine ( ) ) ; for ( int nCase = 1 ; nCase <= numCases ; nCase ++ ) { int N = Integer . parseInt ( br . readLine ( ) ) ; int [ ] [ ] lines = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { String [ ] sa = br . readLine ( ) . split ( "" ▁ "" ) ; lines [ i ] [ 0 ] = Integer . parseInt ( sa [ 0 ] ) ; lines [ i ] [ 1 ] = Integer . parseInt ( sa [ 1 ] ) ; } int answer = 0 ; if ( N == 1 ) answer = 0 ; else if ( N == 2 ) { if ( ( lines [ 0 ] [ 0 ] < lines [ 1 ] [ 0 ] && lines [ 0 ] [ 1 ] > lines [ 1 ] [ 1 ] ) || ( lines [ 0 ] [ 0 ] > lines [ 1 ] [ 0 ] && lines [ 0 ] [ 1 ] < lines [ 1 ] [ 1 ] ) ) answer = 1 ; } else answer = 666 ; System . out . println ( "" Case ▁ # "" + nCase + "" : ▁ "" + answer ) ; } br . close ( ) ; } } ","import sys NEW_LINE def readInput ( ) : NEW_LINE INDENT file = open ( sys . argv [ 1 ] ) NEW_LINE testCaseCount = int ( file . readline ( ) . rstrip ( ) ) NEW_LINE testCases = [ ] NEW_LINE for i in xrange ( testCaseCount ) : NEW_LINE INDENT n = int ( file . readline ( ) . rstrip ( ) ) NEW_LINE As = [ ] NEW_LINE Bs = [ ] NEW_LINE for j in xrange ( n ) : NEW_LINE INDENT a , b = [ int ( x ) for x in file . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE As . append ( a ) NEW_LINE Bs . append ( b ) NEW_LINE DEDENT testCases . append ( ( n , As , Bs ) ) NEW_LINE DEDENT return testCases NEW_LINE DEDENT def solve ( ( n , As , Bs ) ) : NEW_LINE INDENT intersections = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT for j in xrange ( n ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT continue NEW_LINE DEDENT if As [ i ] < As [ j ] and Bs [ i ] > Bs [ j ] : NEW_LINE INDENT intersections += 1 NEW_LINE DEDENT elif As [ i ] > As [ j ] and Bs [ i ] < Bs [ j ] : NEW_LINE INDENT intersections += 1 NEW_LINE DEDENT DEDENT DEDENT return intersections / 2 NEW_LINE DEDENT testCases = readInput ( ) NEW_LINE testCaseNr = 1 NEW_LINE for testCase in testCases : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( testCaseNr , solve ( testCase ) ) NEW_LINE testCaseNr += 1 NEW_LINE DEDENT " V75,"import java . io . FileOutputStream ; import java . io . FileReader ; import java . io . PrintStream ; import java . util . Hashtable ; import java . util . Scanner ; public class Saving { public void solve ( Scanner in , PrintStream out ) throws Exception { int numTests = in . nextInt ( ) ; for ( int t = 1 ; t <= numTests ; t ++ ) { int numEngines = in . nextInt ( ) ; Hashtable < String , Integer > table = new Hashtable < String , Integer > ( ) ; in . nextLine ( ) ; for ( int e = 0 ; e < numEngines ; e ++ ) { table . put ( in . nextLine ( ) , e ) ; } int numQueries = in . nextInt ( ) ; int [ ] query = new int [ numQueries ] ; in . nextLine ( ) ; for ( int q = 0 ; q < numQueries ; q ++ ) { String a = in . nextLine ( ) ; query [ q ] = table . get ( a ) ; } int numSwitches = 0 ; int curEngine = - 1 ; for ( int curQ = 0 ; curQ < numQueries ; curQ ++ ) { if ( curEngine != query [ curQ ] && curEngine != - 1 ) { continue ; } int bestScore = 0 ; int bestEngine = 0 ; for ( int e = 0 ; e < numEngines ; e ++ ) { int curBest = 0 ; for ( int q = curQ ; q < numQueries ; q ++ ) { if ( query [ q ] == e ) { break ; } curBest ++ ; } if ( curBest > bestScore ) { bestScore = curBest ; bestEngine = e ; } } curEngine = bestEngine ; numSwitches ++ ; } numSwitches -- ; if ( numSwitches < 0 ) { numSwitches = 0 ; } out . println ( "" Case ▁ # "" + t + "" : ▁ "" + numSwitches ) ; } } public static void main ( String [ ] args ) throws Exception { Scanner in = null ; PrintStream out = null ; in = new Scanner ( System . in ) ; out = System . out ; in = new Scanner ( new FileReader ( "" A - large . in "" ) ) ; out = new PrintStream ( new FileOutputStream ( "" A - large . out "" ) ) ; new Saving ( ) . solve ( in , out ) ; out . close ( ) ; System . exit ( 0 ) ; } } ","import sys NEW_LINE global engines NEW_LINE global memo NEW_LINE global queries NEW_LINE sys . setrecursionlimit ( 3500 ) NEW_LINE def best ( s , q ) : NEW_LINE INDENT if ( q < 0 ) : NEW_LINE INDENT return ( 0 , [ ] ) NEW_LINE DEDENT if ( queries [ q ] == engines [ s ] ) : NEW_LINE INDENT memo [ ( s , q ) ] = ( 2 ** 30 , [ ] ) NEW_LINE return ( 2 ** 30 , [ ] ) NEW_LINE DEDENT if ( ( s , q ) in memo ) : NEW_LINE INDENT return memo [ ( s , q ) ] NEW_LINE DEDENT themin = 2 ** 30 NEW_LINE for i in range ( len ( engines ) ) : NEW_LINE INDENT if ( s != i ) : NEW_LINE INDENT cost = best ( i , q - 1 ) [ 0 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT cost = best ( i , q - 1 ) [ 0 ] NEW_LINE DEDENT if ( cost < themin ) : NEW_LINE INDENT res = ( cost , best ( i , q - 1 ) [ 1 ] + [ s ] ) NEW_LINE themin = cost NEW_LINE DEDENT DEDENT memo [ ( s , q ) ] = res NEW_LINE return res NEW_LINE DEDENT def findBest ( ) : NEW_LINE INDENT themin = 2 ** 30 NEW_LINE for i in range ( len ( engines ) ) : NEW_LINE INDENT cost = best ( i , len ( queries ) - 1 ) [ 0 ] NEW_LINE if ( cost < themin ) : NEW_LINE INDENT themin = cost NEW_LINE idx = i NEW_LINE DEDENT DEDENT return best ( idx , len ( queries ) - 1 ) NEW_LINE DEDENT f = open ( sys . argv [ 1 ] ) NEW_LINE nCases = int ( f . readline ( ) ) NEW_LINE for j in range ( nCases ) : NEW_LINE INDENT memo = { } NEW_LINE nEngines = int ( f . readline ( ) ) NEW_LINE engines = [ ] NEW_LINE for i in range ( nEngines ) : NEW_LINE INDENT engines . append ( f . readline ( ) . strip ( ) ) NEW_LINE DEDENT nQueries = int ( f . readline ( ) ) NEW_LINE queries = [ ] NEW_LINE for i in range ( nQueries ) : NEW_LINE INDENT queries . append ( f . readline ( ) . strip ( ) ) NEW_LINE DEDENT theBest = findBest ( ) NEW_LINE print "" Case ▁ # % d : ▁ % d "" % ( j + 1 , theBest [ 0 ] ) NEW_LINE NEW_LINE DEDENT " V76,"package bribetheprisoners ; import java . io . IOException ; import java . util . Arrays ; public class Main extends Base { int P , Q ; int free [ ] ; int bribe [ ] [ ] ; public static void main ( String [ ] args ) throws IOException { Main m = new Main ( ) ; m . run ( "" C "" , "" large "" ) ; } @ Override void init ( ) { } @ Override void load ( ) throws IOException { String s [ ] = br . readLine ( ) . split ( "" ▁ "" ) ; P = Integer . parseInt ( s [ 0 ] ) ; Q = Integer . parseInt ( s [ 1 ] ) ; free = new int [ Q + 2 ] ; free [ 0 ] = 0 ; free [ Q + 1 ] = P + 1 ; s = br . readLine ( ) . split ( "" ▁ "" ) ; for ( int i = 0 ; i < Q ; i ++ ) { free [ i + 1 ] = Integer . parseInt ( s [ i ] ) ; } Arrays . sort ( free ) ; bribe = new int [ free . length ] [ free . length ] ; } void compute ( int i , int j ) { if ( i == j ) { bribe [ i ] [ j ] = 0 ; return ; } int best = - 1 ; for ( int k = i + 1 ; k < j ; k ++ ) { int cur = bribe [ i ] [ k ] + bribe [ k ] [ j ] + ( free [ j ] - free [ i ] - 2 ) ; if ( best == - 1 || cur <= best ) best = cur ; } if ( best == - 1 ) best = 0 ; bribe [ i ] [ j ] = best ; } @ Override void solve ( ) { for ( int iv = 0 ; iv < free . length ; iv ++ ) { for ( int i = 0 ; i < free . length ; i ++ ) { int j = i + iv ; if ( j >= free . length ) break ; compute ( i , j ) ; } } printResult ( "" "" + bribe [ 0 ] [ Q + 1 ] ) ; } } ","import sys NEW_LINE import math NEW_LINE fin = open ( ' input . txt ' , ' r ' ) NEW_LINE fout = open ( ' output . txt ' , ' w ' ) NEW_LINE l = int ( fin . readline ( ) ) NEW_LINE for case in range ( l ) : NEW_LINE INDENT P , Q = map ( int , fin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE frees = map ( int , fin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE cache = { } NEW_LINE def rangeof ( lid , rid ) : NEW_LINE INDENT lrange = rrange = 0 NEW_LINE if lid == 0 : NEW_LINE INDENT lrange = 1 NEW_LINE DEDENT else : NEW_LINE INDENT lrange = frees [ lid - 1 ] + 1 NEW_LINE DEDENT if rid == len ( frees ) - 1 : NEW_LINE INDENT rrange = P NEW_LINE DEDENT else : NEW_LINE INDENT rrange = frees [ rid + 1 ] - 1 NEW_LINE DEDENT return rrange - lrange + 1 NEW_LINE DEDENT def getbetter ( lid , rid ) : NEW_LINE INDENT if lid > rid : NEW_LINE INDENT return 0 NEW_LINE DEDENT if lid == rid : NEW_LINE INDENT return rangeof ( lid , rid ) - 1 NEW_LINE DEDENT key = ( lid , rid ) NEW_LINE if key in cache : NEW_LINE INDENT return cache [ key ] NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( lid , rid + 1 ) : NEW_LINE INDENT cache [ key ] = rangeof ( lid , rid ) - 1 + min ( [ getbetter ( lid , i - 1 ) + getbetter ( i + 1 , rid ) for i in range ( lid , rid + 1 ) ] ) NEW_LINE DEDENT return cache [ key ] NEW_LINE DEDENT DEDENT fout . write ( "" Case ▁ # % d : ▁ % d \n "" % ( case + 1 , getbetter ( 0 , len ( frees ) - 1 ) ) ) NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE " V77,"package google . codejam2012 . qualification ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class RecycledNumbers { static private int getDigitsCount ( int number ) { int sh = 10 ; int digits = 1 ; while ( sh <= number ) { sh *= 10 ; digits ++ ; } return digits ; } static private int getRecyclingPairsCount ( int number , int limit ) { int digits = getDigitsCount ( number ) ; int sh = 1 ; for ( int i = 1 ; i < digits ; i ++ ) { sh *= 10 ; } int permutation = number ; int result = 0 ; int [ ] usedNumbers = new int [ digits ] ; int usedNumbersCount = 0 ; for ( int i = 1 ; i < digits ; i ++ ) { permutation = ( permutation % 10 ) * sh + ( permutation / 10 ) ; if ( number < permutation & permutation <= limit ) { boolean isNumberAlreadyUsed = false ; for ( int j = 0 ; j < usedNumbersCount ; j ++ ) { if ( usedNumbers [ j ] == permutation ) { isNumberAlreadyUsed = true ; break ; } } if ( ! isNumberAlreadyUsed ) { usedNumbers [ usedNumbersCount ++ ] = permutation ; result ++ ; } } } return result ; } static public void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) , 64 << 10 ) ; int testsNumber = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; for ( int test = 1 ; test <= testsNumber ; test ++ ) { StringTokenizer tokenizer = new StringTokenizer ( br . readLine ( ) ) ; int startingNumber = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int endingNumber = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int result = 0 ; for ( int number = startingNumber ; number <= endingNumber ; number ++ ) { result += getRecyclingPairsCount ( number , endingNumber ) ; } System . out . println ( "" Case ▁ # "" + test + "" : ▁ "" + result ) ; } } catch ( Exception e ) { System . err . println ( "" Error : "" + e . getMessage ( ) ) ; } } } ","import sys NEW_LINE MAX_LIMIT = 2000000 NEW_LINE def get_min_mapped ( n ) : NEW_LINE INDENT n_min = n NEW_LINE x = str ( n ) NEW_LINE for i in xrange ( 1 , len ( x ) ) : NEW_LINE INDENT x = x [ 1 : ] + x [ 0 ] NEW_LINE if x [ 0 ] == '0' : NEW_LINE INDENT continue NEW_LINE DEDENT n_min = min ( n_min , int ( x ) ) NEW_LINE DEDENT return n_min NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE min_mapped = [ 0 ] * ( MAX_LIMIT + 1 ) NEW_LINE for i in xrange ( 1 , MAX_LIMIT + 1 ) : NEW_LINE INDENT min_mapped [ i ] = get_min_mapped ( i ) NEW_LINE DEDENT for r in xrange ( T ) : NEW_LINE INDENT values = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ' ▁ ' ) ) NEW_LINE A , B = values NEW_LINE cnt_mapped = [ 0 ] * ( B + 1 ) NEW_LINE for i in xrange ( A , B + 1 ) : NEW_LINE INDENT cnt_mapped [ min_mapped [ i ] ] += 1 NEW_LINE DEDENT total = 0 NEW_LINE for i in xrange ( B + 1 ) : NEW_LINE INDENT if cnt_mapped [ i ] > 1 : NEW_LINE INDENT total += ( cnt_mapped [ i ] * ( cnt_mapped [ i ] - 1 ) ) / 2 NEW_LINE DEDENT DEDENT print "" Case ▁ # % d : ▁ % s "" % ( r + 1 , total ) NEW_LINE DEDENT DEDENT " V78,"import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class ProblemC { String input = "" C - large . in "" ; String output = input . substring ( 0 , input . length ( ) - 2 ) + "" out "" ; static long MOD = 1000000009L ; int numCases ; int n , k ; boolean [ ] [ ] a ; long res ; boolean [ ] visited ; void dfs ( int v , int lastCnt , int lvl ) { visited [ v ] = true ; int cc = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ v ] [ i ] && ! visited [ i ] ) { long choice = k - lastCnt - cc - 1 ; if ( lvl < 2 ) choice ++ ; if ( choice < 0 ) choice = 0 ; res *= choice ; res %= MOD ; cc ++ ; } for ( int i = 0 ; i < n ; i ++ ) if ( a [ v ] [ i ] && ! visited [ i ] ) dfs ( i , cc , lvl + 1 ) ; } void solve ( ) throws FileNotFoundException { Scanner sc = new Scanner ( new File ( input ) ) ; PrintWriter pw = new PrintWriter ( output ) ; numCases = Integer . parseInt ( sc . nextLine ( ) ) ; for ( int cnum = 1 ; cnum <= numCases ; cnum ++ ) { n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; a = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int x = sc . nextInt ( ) - 1 ; int y = sc . nextInt ( ) - 1 ; a [ x ] [ y ] = a [ y ] [ x ] = true ; } res = 1 ; visited = new boolean [ n ] ; dfs ( 0 , 0 , 0 ) ; pw . println ( "" Case ▁ # "" + cnum + "" : ▁ "" + res ) ; } sc . close ( ) ; pw . close ( ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new ProblemC ( ) . solve ( ) ; } } ","import sys NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return map ( foo , raw_input ( ) . split ( ) ) NEW_LINE def doit ( u , p ) : NEW_LINE INDENT c = k NEW_LINE s = len ( to [ u ] ) NEW_LINE if ( p >= 0 ) : NEW_LINE INDENT c -= len ( to [ p ] ) NEW_LINE s -= 1 NEW_LINE DEDENT cnks . append ( ( c , s ) ) NEW_LINE for v in to [ u ] : NEW_LINE INDENT if v == p : continue NEW_LINE doit ( v , u ) NEW_LINE DEDENT DEDENT M = 1000000009 NEW_LINE def cnk ( n , k ) : NEW_LINE INDENT res = 1 NEW_LINE for i in xrange ( k ) : NEW_LINE INDENT res *= n - i NEW_LINE res %= M NEW_LINE DEDENT return res NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( "" Test ▁ % d \n "" % ( test + 1 ) ) NEW_LINE n , k = readarray ( int ) NEW_LINE to = [ ] NEW_LINE cnks = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT to . append ( [ ] ) NEW_LINE DEDENT for i in xrange ( n - 1 ) : NEW_LINE INDENT ( u , v ) = readarray ( int ) NEW_LINE to [ u - 1 ] . append ( v - 1 ) NEW_LINE to [ v - 1 ] . append ( u - 1 ) NEW_LINE DEDENT doit ( 0 , - 1 ) NEW_LINE res = 1 NEW_LINE for ( c , s ) in cnks : NEW_LINE INDENT if ( s > c ) : res = 0 NEW_LINE res *= cnk ( c , s ) NEW_LINE res %= M NEW_LINE DEDENT print "" Case ▁ # % d : ▁ % d "" % ( test + 1 , res ) NEW_LINE DEDENT " V79,"import java . io . * ; import java . util . * ; public class Main { static StreamTokenizer in ; static int next ( ) throws Exception { in . nextToken ( ) ; return ( int ) in . nval ; } static PrintWriter out ; static String NAME = "" a "" ; public static void main ( String [ ] args ) throws Exception { out = new PrintWriter ( new File ( NAME + "" . out "" ) ) ; in = new StreamTokenizer ( new BufferedReader ( new FileReader ( new File ( NAME + "" . in "" ) ) ) ) ; int tests = next ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { int x = next ( ) ; int s = next ( ) ; int r = next ( ) ; double t = next ( ) ; int n = next ( ) ; int m = 101 ; int [ ] l = new int [ m ] ; l [ 0 ] = x ; for ( int i = 0 ; i < n ; i ++ ) { int b = next ( ) ; int e = next ( ) ; l [ next ( ) ] += e - b ; l [ 0 ] -= e - b ; } double answ = 0 ; for ( int i = 0 ; i < m ; i ++ ) { double tt = Math . min ( t , ( double ) l [ i ] / ( i + r ) ) ; t -= tt ; answ -= tt * ( r - s ) / ( i + s ) ; } for ( int i = 0 ; i < m ; i ++ ) answ += ( double ) l [ i ] / ( i + s ) ; out . println ( "" Case ▁ # "" + test + "" : ▁ "" + answ ) ; } out . close ( ) ; } } ","infile = open ( ' airport _ walk . in ' ) NEW_LINE outfile = open ( ' airport _ walk . out ' , ' w ' ) NEW_LINE T = int ( infile . readline ( ) . strip ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT X , S , R , runtime , N = [ int ( s ) for s in infile . readline ( ) . strip ( ) . split ( ) ] NEW_LINE run_bonus = R - S NEW_LINE speeds , lengths = [ ] , [ ] NEW_LINE walkways = [ ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT B , E , w = [ int ( s ) for s in infile . readline ( ) . strip ( ) . split ( ) ] NEW_LINE walkways . append ( ( w + S , E - B ) ) NEW_LINE DEDENT sum_lens = sum ( w [ 1 ] for w in walkways ) NEW_LINE walkways . append ( ( S , X - sum_lens ) ) NEW_LINE walkways = sorted ( walkways , key = lambda w : w [ 0 ] ) NEW_LINE answer = 0.0 NEW_LINE for speed , distance in walkways : NEW_LINE INDENT cur_runtime = min ( distance / float ( speed + run_bonus ) , float ( runtime ) ) NEW_LINE runtime -= cur_runtime NEW_LINE answer += cur_runtime + ( ( distance - ( speed + run_bonus ) * cur_runtime ) / float ( speed ) ) NEW_LINE DEDENT outfile . write ( ' Case ▁ # % d : ▁ % .9f \n ' % ( t + 1 , answer ) ) NEW_LINE DEDENT " V80,"import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class C { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( "" src / C - large . in "" ) ) ) ) ; String output = "" "" ; int t = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int i = 1 ; i <= t ; i ++ ) { int n = sc . nextInt ( ) ; int j = sc . nextInt ( ) ; long num = ( 1l << ( n - 1 ) ) + 1 ; int count = 0 ; output += "" Case ▁ # "" + i + "" : \n "" ; while ( count < j ) { String s = Long . toBinaryString ( num ) ; boolean found = true ; ArrayList < Integer > factors = new ArrayList < Integer > ( ) ; for ( int k = 2 ; k <= 10 ; k ++ ) { BigInteger big = new BigInteger ( s , k ) ; if ( big . isProbablePrime ( 10 ) ) { found = false ; break ; } int factor = - 1 ; for ( int m = 3 ; m < 1000 ; m += 2 ) { if ( big . mod ( new BigInteger ( "" "" + m ) ) . equals ( BigInteger . ZERO ) ) { factor = m ; break ; } } if ( factor == - 1 ) { found = false ; break ; } factors . add ( factor ) ; } if ( found ) { count ++ ; output += s ; for ( int k : factors ) { output += "" ▁ "" + k ; } output += "" \n "" ; } num += 2 ; } } BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( "" src / C - large . out "" ) , "" utf - 8"" ) ) ; bw . write ( output ) ; bw . close ( ) ; } } ","from sympy import * NEW_LINE import random NEW_LINE n = 32 NEW_LINE j = 500 NEW_LINE arr = [ ] NEW_LINE f = open ( "" out . txt "" , "" w "" ) NEW_LINE def findDivisor ( x ) : NEW_LINE INDENT res = 2 NEW_LINE while x % res != 0 and res < 100 : NEW_LINE INDENT res += 1 NEW_LINE DEDENT return res NEW_LINE DEDENT for i in xrange ( 2 ** ( n - 2 ) ) : NEW_LINE INDENT t = bin ( i ) [ 2 : ] NEW_LINE t = ""0"" * ( n - 2 - len ( t ) ) + t NEW_LINE t = ""1"" + t + ""1"" NEW_LINE ok = True NEW_LINE for base in xrange ( 2 , 11 ) : NEW_LINE INDENT if isprime ( int ( t , base ) ) or findDivisor ( int ( t , base ) ) == 100 : NEW_LINE INDENT ok = False NEW_LINE break NEW_LINE DEDENT DEDENT if ok : NEW_LINE INDENT data = [ ] NEW_LINE data . append ( t ) NEW_LINE for base in xrange ( 2 , 11 ) : NEW_LINE INDENT num = int ( t , base ) NEW_LINE data . append ( str ( findDivisor ( num ) ) ) NEW_LINE DEDENT arr . append ( data ) NEW_LINE if len ( arr ) == j : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print >> f , "" Case ▁ # 1 : "" NEW_LINE for l in arr : NEW_LINE INDENT print >> f , ' ▁ ' . join ( l ) NEW_LINE DEDENT " V81,"package qualification . c ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . util . Scanner ; public class CLarge { Scanner in ; public CLarge ( ) { in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; for ( int l = 1 ; l <= t ; l ++ ) { int r = in . nextInt ( ) ; int k = in . nextInt ( ) ; int n = in . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = in . nextInt ( ) ; } int [ ] nextGroup = new int [ n ] ; long [ ] money = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { long space = k ; int pointer = i ; long total = 0 ; int srcPointer = pointer ; while ( space >= arr [ pointer ] ) { space -= arr [ pointer ] ; total += arr [ pointer ] ; if ( ( pointer + 1 ) % n == srcPointer ) { break ; } pointer = ( pointer + 1 ) % n ; } nextGroup [ i ] = pointer ; money [ i ] = total ; } int group = 0 ; long total = 0 ; for ( int i = 0 ; i < r ; i ++ ) { total += money [ group ] ; group = nextGroup [ group ] ; } System . out . printf ( "" Case ▁ # % d : ▁ % d \n "" , l , total ) ; } } public static void main ( String [ ] args ) { try { String p = "" C - large - practice "" ; System . setIn ( CLarge . class . getResourceAsStream ( p + "" . in "" ) ) ; System . setOut ( new PrintStream ( new File ( "" src / qualification / c / "" + p + "" . out "" ) ) ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } new CLarge ( ) ; } } ","if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT inFile = open ( "" C - large . in "" , "" r "" ) NEW_LINE outFile = open ( "" realtest . out "" , "" w "" ) NEW_LINE caseNum = int ( inFile . readline ( ) ) NEW_LINE for i in range ( 1 , caseNum + 1 ) : NEW_LINE INDENT items = inFile . readline ( ) . replace ( "" \n "" , "" "" ) . split ( "" ▁ "" ) NEW_LINE R = int ( items [ 0 ] ) NEW_LINE k = int ( items [ 1 ] ) NEW_LINE N = int ( items [ 2 ] ) NEW_LINE items = inFile . readline ( ) . replace ( "" \n "" , "" "" ) . split ( "" ▁ "" ) NEW_LINE if len ( items ) != N : NEW_LINE INDENT print "" guest ▁ number ▁ error . "" NEW_LINE continue NEW_LINE DEDENT dataList = [ ] NEW_LINE for item in items : NEW_LINE INDENT dataList . append ( int ( item ) ) NEW_LINE DEDENT roundData = [ ] NEW_LINE occurInfo = { } NEW_LINE posCnt = 0 NEW_LINE totalCnt = 0 NEW_LINE while posCnt not in occurInfo : NEW_LINE INDENT testSum = 0 NEW_LINE tmp_cnt = 0 NEW_LINE while tmp_cnt < N and testSum + dataList [ ( posCnt + tmp_cnt ) % N ] <= k : NEW_LINE INDENT testSum += dataList [ ( posCnt + tmp_cnt ) % N ] NEW_LINE tmp_cnt += 1 NEW_LINE DEDENT roundData . append ( testSum ) NEW_LINE occurInfo [ posCnt ] = totalCnt NEW_LINE posCnt = ( posCnt + tmp_cnt ) % N NEW_LINE totalCnt += 1 NEW_LINE DEDENT roundSum = 0 NEW_LINE loopLen = len ( roundData ) - occurInfo [ posCnt ] NEW_LINE for j in range ( occurInfo [ posCnt ] , len ( roundData ) ) : NEW_LINE INDENT roundSum += roundData [ j ] NEW_LINE DEDENT totalSum = 0 NEW_LINE for j in range ( occurInfo [ posCnt ] ) : NEW_LINE INDENT totalSum += roundData [ j ] NEW_LINE DEDENT for j in range ( ( R - occurInfo [ posCnt ] ) % loopLen ) : NEW_LINE INDENT totalSum += roundData [ j + occurInfo [ posCnt ] ] NEW_LINE DEDENT totalSum += ( ( R - occurInfo [ posCnt ] ) / loopLen ) * roundSum NEW_LINE outFile . write ( "" Case ▁ # % d : ▁ % d \n "" % ( i , totalSum ) ) NEW_LINE DEDENT outFile . close ( ) NEW_LINE inFile . close ( ) NEW_LINE DEDENT " V82,"import java . util . * ; import java . io . * ; public class C { public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { int N = input . nextInt ( ) ; int [ ] arr = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) arr [ i ] = input . nextInt ( ) ; int [ ] data = new int [ 2 * N ] ; for ( int i = 0 ; i < N ; i ++ ) data [ arr [ i ] - i + N ] ++ ; double score = 0 ; for ( int i = 700 ; i < 1000 ; i ++ ) score += data [ i ] ; for ( int i = 1000 ; i < 1300 ; i ++ ) score -= data [ i ] ; boolean good = score > - 40 ; System . out . printf ( "" Case ▁ # % d : ▁ "" , n + 1 ) ; if ( good ) System . out . println ( "" GOOD "" ) ; else System . out . println ( "" BAD "" ) ; } } } ","import sys NEW_LINE def prework ( argv ) : NEW_LINE INDENT l = range ( 1000 ) NEW_LINE def test ( func ) : NEW_LINE INDENT lg = list ( l ) NEW_LINE func ( lg ) NEW_LINE return check ( lg ) NEW_LINE DEDENT ans = [ ( test ( good ) , test ( bad ) ) for _ in range ( 20 ) ] NEW_LINE print ( * ans , sep = ' \n ' , file = sys . stderr ) NEW_LINE return "" above "" NEW_LINE DEDENT import random NEW_LINE def good ( l ) : NEW_LINE INDENT n = len ( l ) NEW_LINE for k in range ( n ) : NEW_LINE INDENT p = random . randint ( k , n - 1 ) NEW_LINE l [ k ] , l [ p ] = l [ p ] , l [ k ] NEW_LINE DEDENT DEDENT def bad ( l ) : NEW_LINE INDENT n = len ( l ) NEW_LINE for k in range ( n ) : NEW_LINE INDENT p = random . randint ( 0 , n - 1 ) NEW_LINE l [ k ] , l [ p ] = l [ p ] , l [ k ] NEW_LINE DEDENT DEDENT def check ( l ) : NEW_LINE INDENT a = len ( [ 1 for i , x in enumerate ( l ) if i - x > 0 ] ) NEW_LINE b = len ( [ 1 for i , x in enumerate ( l ) if i - x < 0 ] ) NEW_LINE r = a / b NEW_LINE return r > 0.94 NEW_LINE DEDENT def once ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE l = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE return "" GOOD "" if check ( l ) else "" BAD "" NEW_LINE pass NEW_LINE DEDENT def printerr ( * v ) : NEW_LINE INDENT print ( * v , file = sys . stderr ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT TT = int ( input ( ) ) NEW_LINE for tt in range ( 1 , TT + 1 ) : NEW_LINE INDENT printerr ( "" coping ▁ Case ▁ % d . . "" % ( tt ) ) NEW_LINE ans = once ( ) NEW_LINE print ( "" Case ▁ # % d : ▁ % s "" % ( tt , ( ans ) ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT msg = prework ( sys . argv ) NEW_LINE print ( "" prework ▁ down ▁ with "" , msg , file = sys . stderr ) NEW_LINE main ( ) NEW_LINE DEDENT " V83,"package round3 ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class D { private int s ; private boolean [ ] [ ] z ; private int d ; public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( D . class . getSimpleName ( ) + "" . in "" ) ) ; PrintWriter out = new PrintWriter ( new File ( D . class . getSimpleName ( ) + "" . out "" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = "" Case ▁ # "" + ( i + 1 ) + "" : ▁ "" + new D ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; d = in . nextInt ( ) ; s = 0 ; z = new boolean [ 10 ] [ d ] ; calc ( n , 0 ) ; return "" "" + s ; } private void calc ( int n , int p ) { if ( n == 0 ) { s ++ ; return ; } for ( int i = p + 1 ; i <= n ; i ++ ) { int j = i ; int k = 0 ; boolean ok = true ; while ( j > 0 ) { if ( z [ k ] [ j % d ] ) { ok = false ; break ; } j /= d ; k ++ ; } if ( ok ) { j = i ; k = 0 ; while ( j > 0 ) { z [ k ] [ j % d ] = true ; j /= d ; k ++ ; } calc ( n - i , i ) ; j = i ; k = 0 ; while ( j > 0 ) { z [ k ] [ j % d ] = false ; j /= d ; k ++ ; } } } } } ","n = 0 NEW_LINE b = 0 NEW_LINE used = set ( [ ] ) NEW_LINE counter = 0 NEW_LINE def count ( n , minnum , b ) : NEW_LINE INDENT global counter NEW_LINE for num in range ( minnum , n + 1 ) : NEW_LINE INDENT rep = [ ] NEW_LINE nnum = num NEW_LINE while nnum > 0 : NEW_LINE INDENT rep . append ( nnum % b ) NEW_LINE nnum = nnum / b NEW_LINE DEDENT ok = True NEW_LINE for i in range ( len ( rep ) ) : NEW_LINE INDENT if ( i , rep [ i ] ) in used : NEW_LINE INDENT ok = False NEW_LINE break NEW_LINE DEDENT DEDENT if ok : NEW_LINE INDENT for i in range ( len ( rep ) ) : NEW_LINE INDENT used . add ( ( i , rep [ i ] ) ) NEW_LINE DEDENT if n - num == 0 : NEW_LINE INDENT counter = counter + 1 NEW_LINE DEDENT else : NEW_LINE INDENT count ( n - num , num + 1 , b ) NEW_LINE DEDENT for i in range ( len ( rep ) ) : NEW_LINE INDENT used . remove ( ( i , rep [ i ] ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT T = int ( raw_input ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT [ n , b ] = map ( lambda x : int ( x ) , raw_input ( ) . split ( ) ) NEW_LINE counter = 0 NEW_LINE used = set ( [ ] ) NEW_LINE count ( n , 1 , b ) NEW_LINE print ( "" Case ▁ # % d : ▁ % d "" % ( i + 1 , counter ) ) NEW_LINE DEDENT " V84,"import java . io . * ; import java . util . * ;   import static java . lang . Math . * ;   public class GettinganA { ","if __name__ == "" _ _ main _ _ "" : n = int ( input ( ) ) grades = list ( map ( int , input ( ) . split ( ) ) ) grades . sort ( ) required = 4.5 redo = 0 i = 0 while round ( sum ( grades ) / n , 2 ) < required : redo = redo + 1 grades [ i ] = 5 i = i + 1 print ( redo ) NEW_LINE " V85,"import java . util . * ;   public class Check2 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { int n = sc . nextInt ( ) ; List < Integer > evenindex = new ArrayList < > ( ) ; List < Integer > oddindex = new ArrayList < > ( ) ; for ( int j = 1 ; j <= 2 * n ; j ++ ) { int num = sc . nextInt ( ) ; if ( num % 2 == 0 ) { evenindex . add ( j ) ; } else { oddindex . add ( j ) ; } } int l1 = evenindex . size ( ) ; int l2 = oddindex . size ( ) ; int u1 = 2 ; int u2 = 2 ; if ( l1 != 0 && l2 != 0 && l1 % 2 == 0 && l2 % 2 == 0 ) { if ( l1 >= l2 ) { u1 = 1 ; } else { u2 = 1 ; } }   for ( int j = 0 ; j < evenindex . size ( ) - u1 ; j ++ ) { System . out . println ( evenindex . get ( j ) + "" ▁ "" + evenindex . get ( j + 1 ) ) ; j ++ ; }    for ( int j = 0 ; j < oddindex . size ( ) - u2 ; j ++ ) { ","t = int ( input ( ) ) for i in range ( t ) : n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) e = [ ] o = [ ] for i in range ( 2 * n ) : if l [ i ] % 2 == 0 : e . append ( i + 1 ) else : o . append ( i + 1 ) for i in range ( n - 1 ) : if len ( e ) > 1 : print ( str ( e . pop ( 0 ) ) + "" ▁ "" + str ( e . pop ( 0 ) ) ) else : print ( str ( o . pop ( 0 ) ) + "" ▁ "" + str ( o . pop ( 0 ) ) )           NEW_LINE " V86,"import java . util . Scanner ;   public class StickersAndToys {   public static void main ( String [ ] args ) { Scanner xScanner = new Scanner ( System . in ) ; int numQueries = xScanner . nextInt ( ) ;   for ( int i = 0 ; i < numQueries ; i ++ ) { int numEggs = xScanner . nextInt ( ) ; int numStickers = xScanner . nextInt ( ) ; int numToys = xScanner . nextInt ( ) ; int numFewerObjects = Math . min ( numStickers , numToys ) ; ","cases = int ( input ( ) ) for i in range ( cases ) : a , b , c = map ( int , input ( ) . split ( ) ) print ( max ( a - b , a - c ) + 1 ) NEW_LINE " V87,"import java . util . Scanner ; import java . util . Arrays ; import java . util . Vector ; import java . util . Collections ;   public class Welcomejava {   public static void main ( String [ ] args ) { ","import sysfrom os import pathif ( path . exists ( ' input . txt ' ) and path . exists ( ' output . txt ' ) ) : sys . stdout = open ( ' output . txt ' , ' w ' ) sys . stdin = open ( ' input . txt ' , ' r ' )   def main ( ) : n = int ( input ( ) ) ans = 0 while n > 0 : sm_p = n if n % 2 == 0 : ans += n // 2 break else : i = 3 while i * i <= n : if n % i == 0 : sm_p = i break i += 2 n -= sm_p ans += 1 print ( ans )   main ( ) NEW_LINE " V88,"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } long ans = sum + ( n - 1 ) ; if ( ans == x ) { System . out . println ( "" YES "" ) ; } else { System . out . println ( "" NO "" ) ; }     } } ","n , x = map ( int , input ( ) . split ( ) ) a = [ int ( i ) for i in input ( ) . split ( ) ] if ( sum ( a ) + n - 1 == x ) : print ( "" YES "" ) else : print ( "" NO "" ) NEW_LINE " V89,"import java . util . * ;   public class B744 { public static void main ( String [ ] args ) { List [ ] L = new List [ 29 ] ; int [ ] ans = new int [ 1009 ] ; Arrays . fill ( ans , 1000000000 ) ; for ( int i = 0 ; i < 20 ; i ++ ) L [ i ] = new ArrayList ( ) ; for ( int i = 0 ; i < 10 ; i ++ ) { int tmp = 1 << i ; for ( int j = 1 ; j < 1024 ; j ++ ) { if ( ( tmp & j ) == 0 ) L [ i ] . add ( j ) ; else L [ i + 10 ] . add ( j ) ; } } Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < 20 ; i ++ ) { List query = new ArrayList ( ) ; int [ ] have = new int [ 1009 ] ; Arrays . fill ( have , 0 ) ; for ( int j = 0 ; j < L [ i ] . size ( ) ; j ++ ) if ( ( int ) L [ i ] . get ( j ) <= n ) query . add ( L [ i ] . get ( j ) ) ; if ( query . size ( ) == 0 ) continue ; System . out . println ( query . size ( ) ) ; for ( int j = 0 ; j < query . size ( ) ; j ++ ) if ( ( int ) query . get ( j ) <= n ) { System . out . print ( query . get ( j ) + "" ▁ "" ) ; have [ ( int ) query . get ( j ) ] = 1 ; } for ( int j = 1 ; j <= n ; j ++ ) { int tmp = in . nextInt ( ) ; if ( have [ j ] == 0 ) ans [ j ] = Math . min ( ans [ j ] , tmp ) ; } } System . out . println ( - 1 ) ; for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( ans [ i ] + "" ▁ "" ) ; System . out . flush ( ) ; } } ","from sys import stdoutn = int ( input ( ) ) ans = [ 10 ** 10 ] * nth = 1 while th < n : ask = [ i % ( 2 * th ) < th for i in range ( n ) ] for _ in range ( 2 ) : inds = [ key for key , value in enumerate ( ask ) if value ] print ( len ( inds ) ) print ( ' ▁ ' . join ( [ str ( i + 1 ) for i in inds ] ) ) stdout . flush ( ) reply = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) ans = [ ans [ i ] if ask [ i ] else min ( ans [ i ] , reply [ i ] ) for i in range ( n ) ] ask = [ not v for v in ask ] th *= 2 print ( - 1 ) print ( ' ▁ ' . join ( map ( str , ans ) ) ) stdout . flush ( )       NEW_LINE " V90,"import java . util . * ;   public class ICPC { public static void main ( String [ ] args ) {    Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; process : for ( int i = 1 ; i <= t ; i ++ ) { int n = sc . nextInt ( ) ; ","cases = int ( input ( ) ) while cases : cases -= 1 num = int ( input ( ) ) arr = sorted ( map ( int , input ( ) . split ( ) ) )   base = min ( arr [ - 1 ] , arr [ - 2 ] ) - 1   ans = min ( base , num - 2 )   print ( ans )   NEW_LINE " V91,"import java . util . Scanner ; public class Kanban { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int t = s . nextInt ( ) ; String str = "" "" ; if ( t == 24 || t == 75 || t == 99 || t == 41 || t == 49 || t == 37 || t == 13 || t == 1 || t == 10 || t == 11 || t == 16 || t == 20 || t == 28 ) { str += "" NO "" ; } else if ( t == 5 || t == 86 || t == 64 || t == 52 || t == 35 || t == 43 || t == 46 || t == 2 || t == 3 || t == 4 || t == 12 || t == 30 ) str += "" YES "" ; System . out . println ( str ) ; } } ","import sysinput = sys . stdin . readline   t = 1   for _ in range ( t ) : n = int ( input ( ) ) l = [ 1 , 7 , 9 , 10 , 11 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ] flag = 1 d = n // 10 if d == 2 or d == 7 or d == 9 : flag = 0 if n in l : flag = 0 n %= 10 if n in l : flag = 0 if flag : print ( "" YES "" ) else : print ( "" NO "" ) NEW_LINE " V92,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class experiment { static int M = 1_000_000_007 ; static int INF = Integer . MAX_VALUE ; static final FastScanner fs = new FastScanner ( ) ;   ","n = int ( input ( ) ) ai = [ int ( x ) for x in input ( ) . split ( ) ] m = int ( input ( ) ) bj = [ int ( x ) for x in input ( ) . split ( ) ] gears = [ ] for i in ai : for j in bj : if ( j % i == 0 ) : gears . append ( int ( j / i ) ) maxgear = max ( gears ) print ( gears . count ( maxgear ) ) NEW_LINE " V93,"import java . util . Scanner ;   public class Main {   private Scanner scanner ;   private Main ( Scanner scanner ) { this . scanner = scanner ; }   public static void main ( String [ ] args ) { Main main = new Main ( new Scanner ( System . in ) ) ; main . solve ( ) ; }   private void solve ( ) { int n = scanner . nextInt ( ) ; int [ ] a = new int [ n ] ;   int min = 100 ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += a [ i ] = scanner . nextInt ( ) ; if ( a [ i ] < min ) { min = a [ i ] ; } }   int bigDif = 0 ; int res = s ;   for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == min ) { continue ; }   for ( int j = 1 ; j <= Math . sqrt ( a [ i ] ) ; j ++ ) { if ( a [ i ] % j == 0 ) { if ( ( a [ i ] / j + min * j ) < ( a [ i ] + min ) ) { if ( ( a [ i ] + min ) - ( a [ i ] / j + min * j ) > bigDif ) { bigDif = ( a [ i ] + min ) - ( a [ i ] / j + min * j ) ; res = s - bigDif ; } } } } }    System . out . println ( res ) ; } } ","import sysinput_ = lambda : sys . stdin . readline ( ) . strip ( "" \n "" ) from math import gcdsa = lambda : input_ ( ) sb = lambda : int ( input_ ( ) ) sc = lambda : input_ ( ) . split ( ) sd = lambda : list ( map ( int , input_ ( ) . split ( ) ) ) se = lambda : float ( input_ ( ) ) sf = lambda : list ( input_ ( ) ) flsh = lambda : sys . stdout . flush ( ) mod = 10 ** 9 + 7 def hnbhai ( ) : n = sb ( ) a = sd ( ) b = list ( set ( a ) ) sum_ = sum ( a ) min_ = min ( a ) minus = 0 for i in b : fact = 2 while ( i // fact ) > min_ : if i % fact == 0 : temp = i // fact + min_ * fact - i - min_ minus = min ( minus , temp ) fact += 1 print ( sum_ + minus ) for _ in range ( 1 ) : hnbhai ( ) NEW_LINE " V94,"import java . util . * ; import java . io . * ;   public class CFA { BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; private static final long MOD = 1000L * 1000L * 1000L + 7 ; private static final int [ ] dx = { 0 , - 1 , 0 , 1 } ; private static final int [ ] dy = { 1 , 0 , - 1 , 0 } ; private static final String yes = "" Yes "" ; private static final String no = "" No "" ;   void solve ( ) { ","from sys import * f = lambda : map ( int , stdin . readline ( ) . split ( ) ) n , k = f ( ) t = sorted ( f ( ) ) s = [ 0 ] * ( n + 1 ) for i in range ( n ) : s [ i + 1 ] = s [ i ] + t [ i ] t = [ 0 ] + td = s [ n ] l , r = 0 , nwhile l < r : m = l + r + 1 >> 1 if t [ m ] * m - s [ m ] > k : r = m - 1 else : l = mx = ll , r = 0 , nwhile l < r : m = l + r >> 1 if d - s [ m ] - t [ m ] * ( n - m ) > k : l = m + 1 else : r = my = rq = ( d - s [ y - 1 ] - k + n - y ) // ( n - y + 1 ) - ( s [ x ] + k ) // xprint ( max ( q , int ( d % n > 0 ) ) ) NEW_LINE " V95,"import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . Arrays ; import java . util . Scanner ;   public class Main {    public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; long n = sc . nextInt ( ) ; int mas [ ] = new int [ ] { 4 , 7 , 44 , 47 , 74 , 77 , 444 , 447 , 474 , 477 , 744 , 747 , 774 , 777 } ; for ( int i = 0 ; i < mas . length ; i ++ ) { if ( n % mas [ i ] == 0 ) { pw . print ( "" YES "" ) ; pw . close ( ) ; return ; } } pw . print ( "" NO "" ) ; pw . close ( ) ; } } ","n = int ( input ( ) ) lucky = [ 4 , 7 , 47 , 74 , 447 , 474 , 477 , 774 , 747 , 744 ] count = 0 for i in range ( len ( lucky ) ) : if ( ( n == lucky [ i ] ) or ( n % lucky [ i ] == 0 ) ) : print ( ' YES ' ) break else : count += 1 if count == 10 : print ( ' NO ' ) NEW_LINE " V96,"import java . util . * ; import java . util . stream . Collectors ; import java . lang . * ; import java . io . * ; public class Problem { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < String > l1 = new ArrayList < String > ( ) ; List < String > l2 = new ArrayList < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) l1 . add ( sc . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) l2 . add ( sc . next ( ) ) ; Iterator < String > itr = l1 . iterator ( ) ; while ( itr . hasNext ( ) ) { String s = itr . next ( ) ; if ( l2 . indexOf ( s ) == - 1 ) continue ; else { itr . remove ( ) ; l2 . remove ( l2 . indexOf ( s ) ) ; } } System . out . println ( l1 . size ( ) ) ; }   } ","n = int ( input ( ) ) a = [ ] for i in range ( n ) : s = input ( ) a . append ( s ) b = [ ] for i in range ( n ) : s = input ( ) b . append ( s ) d = dict ( ) d2 = dict ( ) res = 0 for elem in a : if elem in d : d [ elem ] += 1 else : d [ elem ] = 1 for elem in b : if elem in d2 : d2 [ elem ] += 1 else : d2 [ elem ] = 1 for elem in d : if elem not in d2 : d2 [ elem ] = 0 res += min ( d [ elem ] , d2 [ elem ] ) print ( n - res ) NEW_LINE " V97,"import java . util . Scanner ;   public class Main {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int [ ] a = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' L ' ) { for ( int j = 0 ; j < 10 ; j ++ ) { if ( a [ j ] == 0 ) { a [ j ] = 1 ; break ; } } } else if ( s . charAt ( i ) == ' R ' ) { for ( int j = 9 ; j >= 0 ; j -- ) { if ( a [ j ] == 0 ) { a [ j ] = 1 ; break ; } } } else { a [ ( int ) s . charAt ( i ) - 48 ] = 0 ; } } for ( int i = 0 ; i < 10 ; i ++ ) { System . out . print ( a [ i ] ) ; } } } ","events_num = input ( ) events = input ( )   rooms = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]   for e in events : if ( e == ' L ' ) : rooms [ rooms . index ( 0 ) ] = 1 elif ( e == ' R ' ) : rooms [ len ( rooms ) - 1 - rooms [ : : - 1 ] . index ( 0 ) ] = 1 else : rooms [ int ( e ) ] = 0   print ( * rooms , sep = "" "" )   NEW_LINE " V98,"import java . util . * ;   public class questionCF {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; int max = a [ 0 ] , min = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( max < a [ i ] ) max = a [ i ] ; if ( min > a [ i ] ) min = a [ i ] ; } int sum = max + min ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( a [ i ] + a [ j ] == sum ) { System . out . println ( i + 1 + "" ▁ "" + ( j + 1 ) ) ; a [ i ] = - 1 ; a [ j ] = - 1 ; } } }   } } ","n = int ( input ( ) ) a = [ int ( x ) for x in input ( ) . split ( ) ] s = sum ( a ) // ( n // 2 ) checked = [ ] for i in range ( n ) : if i not in checked : for j in range ( i + 1 , n ) : if a [ i ] + a [ j ] == s and j not in checked : print ( i + 1 , j + 1 ) checked . append ( i ) checked . append ( j ) break NEW_LINE " V99,"import java . util . Scanner ;   public class B327 { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int c = n ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ++ c + ( i == n - 1 ? "" "" : "" ▁ "" ) ) ; } } } ","import sysn = int ( input ( ) ) sys . stdout . write ( str ( n ) ) for i in range ( n + 1 , 2 * n ) : sys . stdout . write ( "" ▁ "" + str ( i ) ) NEW_LINE " V100,"import java . math . BigInteger ; import java . util . * ;   public class Main {   static Scanner input = new Scanner ( System . in ) ;   public static void main ( String [ ] args ) { int n = input . nextInt ( ) ; System . out . println ( ( int ) Math . pow ( n + 1 , 2 ) / 4 ) ; } } ","n = int ( input ( ) ) dp = [ 0 ] * 101 dp [ 1 ] = 1 dp [ 2 ] = 2 for i in range ( 3 , 101 ) : dp [ i ] = dp [ i - 2 ] + iprint ( dp [ n ] ) NEW_LINE " V101,"import java . util . * ;   public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , g = sc . nextInt ( ) ; while ( g -- > 0 ) { int k = sc . nextInt ( ) ; boolean f = true ; Set < Integer > set = new HashSet ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int a = sc . nextInt ( ) ; set . add ( a ) ; if ( set . contains ( - 1 * a ) ) { f = false ; } } if ( f ) { System . out . println ( "" YES "" ) ; return ; } } System . out . println ( "" NO "" ) ; } } ",""""""" ▁ Created ▁ by ▁ Henrikh ▁ Kantuni ▁ on ▁ 3/23/17 ▁ """"""   n , m = map ( int , input ( ) . split ( ) ) destroy = False   while m > 0 : group = [ int ( g ) for g in input ( ) . split ( ) ] [ 1 : ]   if len ( group ) == 1 : destroy = True break   group = [ abs ( g ) for g in list ( set ( group ) ) ] old_size = len ( group ) group = list ( set ( group ) )   if len ( group ) == old_size : destroy = True break   m -= 1   if destroy : print ( "" YES "" ) else : print ( "" NO "" ) NEW_LINE " V102,"import java . io . * ; import java . util . * ;   public class GrandmaLauraandApples {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = in . nextInt ( ) ; int p = in . nextInt ( ) ; int a [ ] = new int [ n ] ; in . nextLine ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . nextLine ( ) ; if ( s . contentEquals ( "" halfplus "" ) ) a [ i ] = 1 ; else a [ i ] = 0 ; } long ans = 0 , apples = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] == 1 ) apples = 2 * apples + 1 ; else apples = 2 * apples ; ans += ( apples / 2 ) * p + ( apples % 2 ) * ( p / 2 ) ; } out . println ( ans ) ; out . close ( ) ; } }         ","n , p = map ( int , input ( ) . split ( ) ) a = [ ] NEW_LINE " V103,"  import java . util . * ; import java . lang . * ; import java . io . * ; import java . lang . Math . * ; public class Codechef { public static void main ( String [ ] args ) throws java . lang . Exception { int i , j ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String s1 = br . readLine ( ) ; String s2 = br . readLine ( ) ; int common = 0 , a = 0 , b = 0 ; for ( i = 0 ; i < 2 * n ; i ++ ) { char p = s1 . charAt ( i ) ; char q = s2 . charAt ( i ) ; if ( p == '1' && q == '1' ) common ++ ; else if ( p == '1' ) a ++ ; else if ( q == '1' ) b ++ ; } if ( common % 2 == 0 ) { if ( a > b ) out . println ( "" First "" ) ; else if ( a == b ) out . println ( "" Draw "" ) ; else if ( b > a ) { int z = ( b - a ) / 2 ; if ( z >= 1 ) out . println ( "" Second "" ) ; else out . println ( "" Draw "" ) ; } } else { if ( a >= b ) out . println ( "" First "" ) ; else if ( b > a ) { int z = ( b - a + 1 ) / 2 ; if ( z > 1 ) out . println ( "" Second "" ) ; else if ( z == 1 ) { out . println ( "" Draw "" ) ; } else out . println ( "" First "" ) ; } } out . close ( ) ; } } ","import osimport sysfrom io import BytesIO , IOBase   BUFSIZE = 8192     class FastIO ( IOBase ) : newlines = 0   def __init__ ( self , file ) : self . _fd = file . fileno ( ) self . buffer = BytesIO ( ) self . writable = "" x "" in file . mode or "" r "" not in file . mode self . write = self . buffer . write if self . writable else None   def read ( self ) : while True : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) if not b : break ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines = 0 return self . buffer . read ( )   def readline ( self ) : while self . newlines == 0 : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) self . newlines = b . count ( b "" \n "" ) + ( not b ) ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines -= 1 return self . buffer . readline ( )   def flush ( self ) : if self . writable : os . write ( self . _fd , self . buffer . getvalue ( ) ) self . buffer . truncate ( 0 ) , self . buffer . seek ( 0 )     class IOWrapper ( IOBase ) : def __init__ ( self , file ) : self . buffer = FastIO ( file ) self . flush = self . buffer . flush self . writable = self . buffer . writable self . write = lambda s : self . buffer . write ( s . encode ( "" ascii "" ) ) self . read = lambda : self . buffer . read ( ) . decode ( "" ascii "" ) self . readline = lambda : self . buffer . readline ( ) . decode ( "" ascii "" )     sys . stdin , sys . stdout = IOWrapper ( sys . stdin ) , IOWrapper ( sys . stdout ) input = lambda : sys . stdin . readline ( ) . rstrip ( "" \n "" ) NEW_LINE " V104,"import java . io . * ; import java . util . * ;    public class CodeForce { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static StringBuilder sb = new StringBuilder ( ) ;   public static int checkreverse ( int [ ] [ ] arr , int n ) { if ( n % 2 == 1 ) return n ; for ( int i = n / 2 - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < arr [ 0 ] . length ; j ++ ) { if ( arr [ i ] [ j ] != arr [ n - i - 1 ] [ j ] ) return n ; } }   return checkreverse ( arr , n / 2 ) ;   }   static int next ( String [ ] sr , int ind ) { return Integer . parseInt ( sr [ ind ] ) ; }   public static void main ( String [ ] args ) throws IOException {   String [ ] sr = br . readLine ( ) . split ( "" ▁ "" ) ;   int n = next ( sr , 0 ) ; int k = next ( sr , 1 ) ; double t = next ( sr , 2 ) ; boolean flag = false ; double total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( flag == true ) { System . out . print ( ""0 ▁ "" ) ; } else { double rock = ( double ) ( ( total + k ) / ( n * k ) ) ; if ( rock <= t / 100 ) { System . out . print ( k + "" ▁ "" ) ; total += k ; } else { for ( int j = k - 1 ; j >= 0 ; j -- ) { double mug = ( ( total + j ) / ( n * k ) ) ; if ( flag == false && ( mug <= t / 100 ) ) { System . out . print ( j + "" ▁ "" ) ; flag = true ; break ; } } }    } }     } } ","n , k , t = map ( int , input ( ) . split ( ) ) NEW_LINE ans = [ 0 ] * ni = 0 NEW_LINE a = n * k * t // 100 NEW_LINE while a > 0 : if NEW_LINE a >= k : ans [ i ] += k NEW_LINE i += 1 NEW_LINE a -= k else : ans [ i ] += int ( a ) NEW_LINE a -= int ( a ) NEW_LINE print ( * ans ) NEW_LINE " V105,"import java . lang . * ; import java . util . * ; import java . io . * ;   public class CF1067B { public static void getDistances ( int v , int p , int cLevel , int [ ] dist , int [ ] par , ArrayList < ArrayList < Integer > > tree ) { ","from sys import stdinfrom collections import deque   n , k = map ( int , stdin . readline ( ) . split ( ) )   graph = [ [ ] for _ in range ( n ) ] leaf = - 1 for _ in range ( n - 1 ) : a , b = map ( int , stdin . readline ( ) . split ( ) ) graph [ a - 1 ] . append ( b - 1 ) graph [ b - 1 ] . append ( a - 1 )   def bfs ( G , s ) : NEW_LINE " V106,"import java . math . BigInteger ; import java . text . DateFormat ; import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . * ;   public class Main {   static Scanner input = new Scanner ( System . in ) ;   public static void main ( String [ ] args ) throws ParseException { String t1 = input . next ( ) ; String t2 = input . next ( ) ; DateFormat date = new SimpleDateFormat ( "" yyyy : MM : dd "" ) ; date . setTimeZone ( TimeZone . getTimeZone ( "" UTC "" ) ) ; System . out . println ( Math . abs ( date . parse ( t1 ) . getTime ( ) - date . parse ( t2 ) . getTime ( ) ) / ( 1000 * 60 * 60 * 24 ) ) ; }   } ","import datetimex = datetime . datetime . strptime ( input ( ) , "" % Y : % m : % d "" ) y = datetime . datetime . strptime ( input ( ) , "" % Y : % m : % d "" ) print ( abs ( ( x - y ) . days ) ) NEW_LINE " V107,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; import java . util . stream . IntStream ; import javafx . util . Pair ;   public class Main {   static void sort ( long a [ ] ) { Random ran = new Random ( ) ; for ( int i = 0 ; i < a . length ; i ++ ) { int r = ran . nextInt ( a . length ) ; long temp = a [ r ] ; a [ r ] = a [ i ] ; a [ i ] = temp ; }   Arrays . sort ( a ) ; }   public static void main ( String [ ] args ) throws IOException { Scanner input = new Scanner ( System . in ) ; int t1 , t2 , t3 , t4 , t5 ; t1 = input . nextInt ( ) ; t2 = input . nextInt ( ) ; t3 = input . nextInt ( ) ; t4 = input . nextInt ( ) ; t5 = input . nextInt ( ) ; int result = t1 + t2 + t3 + t4 + t5 ; int min = result ; TreeMap < Integer , Integer > map = new TreeMap < > ( ) ; map . put ( t1 , map . getOrDefault ( t1 , 0 ) + 1 ) ; map . put ( t2 , map . getOrDefault ( t2 , 0 ) + 1 ) ; map . put ( t3 , map . getOrDefault ( t3 , 0 ) + 1 ) ; map . put ( t4 , map . getOrDefault ( t4 , 0 ) + 1 ) ; map . put ( t5 , map . getOrDefault ( t5 , 0 ) + 1 ) ; for ( Map . Entry < Integer , Integer > entry : map . entrySet ( ) ) { Integer key = entry . getKey ( ) ; Integer value = entry . getValue ( ) ; if ( value == 2 ) { min = Math . min ( min , result - key * 2 ) ; } else if ( value >= 3 ) { min = Math . min ( min , result - key * 3 ) ; } } System . out . println ( min ) ; }     } ","import sysfrom collections import Counter   def main ( ) : s = list ( map ( int , sys . stdin . read ( ) . strip ( ) . split ( ) ) ) return sum ( s ) - max ( ( i * min ( j , 3 ) for i , j in Counter ( s ) . items ( ) if j > 1 ) , default = 0 )   print ( main ( ) ) NEW_LINE " V108,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . StringTokenizer ;   public class cf1181B { public static void main ( String [ ] args ) throws IOException { BufferedReader f = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int l = Integer . parseInt ( f . readLine ( ) ) ; String num = f . readLine ( ) ; int best1 = l / 2 ; int best2 = l / 2 + 1 ; while ( best1 > 0 && num . charAt ( best1 ) == '0' ) best1 -- ; while ( best2 < l && num . charAt ( best2 ) == '0' ) best2 ++ ; BigInteger a = ( new BigInteger ( num ) ) ; if ( best1 > 0 ) { BigInteger b = ( new BigInteger ( num . substring ( 0 , best1 ) ) ) . add ( new BigInteger ( num . substring ( best1 , l ) ) ) ; if ( a . compareTo ( b ) > 0 ) a = b ; } if ( best2 < l ) { BigInteger b = ( new BigInteger ( num . substring ( 0 , best2 ) ) ) . add ( new BigInteger ( num . substring ( best2 , l ) ) ) ; if ( a . compareTo ( b ) > 0 ) a = b ; } System . out . println ( a ) ; } } ","n = int ( input ( ) ) a = str ( input ( ) )   l = r = int ( n / 2 ) while ( l > 0 and a [ l ] == '0' ) : l -= 1 while ( r < len ( a ) and a [ r ] == '0' ) : r += 1   ans = float ( ' inf ' ) if ( l > 0 ) : ans = min ( ans , int ( a [ : l ] ) + int ( a [ l : ] ) ) if ( l + 1 < len ( a ) and a [ l + 1 ] != '0' ) : ans = min ( ans , int ( a [ : l + 1 ] ) + int ( a [ l + 1 : ] ) ) if ( r < len ( a ) ) : ans = min ( ans , int ( a [ : r ] ) + int ( a [ r : ] ) ) print ( ans ) NEW_LINE " V109,"import java . io . * ; import java . util . * ;   public class A {   static int INF = ( int ) 1e9 ;   static class pair { int v , idx ;   pair ( ) { v = - INF ; }   void swap ( pair p ) { int v2 = v , idx2 = idx ; v = p . v ; idx = p . idx ; p . v = v2 ; p . idx = idx2 ; } }   static Point [ ] pts ;   public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; pts = new Point [ n ] ; for ( int i = 0 ; i < n ; i ++ ) pts [ i ] = new Point ( sc . nextInt ( ) , sc . nextInt ( ) ) ; int [ ] [ ] [ ] max = new int [ n ] [ n ] [ 2 ] ; for ( int c = 0 ; c < n ; c ++ ) for ( int a = 0 ; a < n ; a ++ ) { if ( a == c ) continue ; pair best1 = new pair ( ) , best2 = new pair ( ) ;   for ( int d = 0 ; d < n ; d ++ ) { if ( d == c || d == a ) continue ; int value = cross ( c , d ) + cross ( d , a ) ; if ( value > best2 . v ) { best2 . v = value ; best2 . idx = d ; if ( best2 . v > best1 . v ) { best1 . swap ( best2 ) ; } } } max [ a ] [ c ] [ 0 ] = best1 . idx ; max [ a ] [ c ] [ 1 ] = best2 . idx ;   } int ans = - INF ; for ( int a = 0 ; a < n ; a ++ ) for ( int b = 0 ; b < n ; b ++ ) for ( int c = 0 ; c < n ; c ++ ) { if ( a == b || b == c || a == c ) continue ; ","import syss , n = 0 , int ( input ( ) ) t = list ( map ( int , sys . stdin . read ( ) . split ( ) ) ) p = [ ( t [ 2 * i ] , t [ 2 * i + 1 ] ) for i in range ( n ) ] for x , i in enumerate ( p , 1 ) : for j in p [ x : ] : a = b = 0 for k in p : d = ( i [ 0 ] - k [ 0 ] ) * ( j [ 1 ] - k [ 1 ] ) - ( i [ 1 ] - k [ 1 ] ) * ( j [ 0 ] - k [ 0 ] ) a , b = min ( d , a ) , max ( d , b ) if a and b : s = max ( s , b - a ) print ( s / 2 ) NEW_LINE " V110,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class ReBranding { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( reader . readLine ( ) ) ;   int n = Integer . parseInt ( st . nextToken ( ) ) ; int m = Integer . parseInt ( st . nextToken ( ) ) ;   String s = reader . readLine ( ) ;   int [ ] string = new int [ 26 ] ; char [ ] str = s . toCharArray ( ) ;   for ( int i = 0 ; i < 26 ; i ++ ) { string [ i ] = i + ' a ' ; }   for ( int i = 0 ; i < m ; i ++ ) { String input = reader . readLine ( ) ; char a = input . charAt ( 0 ) , b = input . charAt ( 2 ) ;   for ( int j = 0 ; j < 26 ; j ++ ) { if ( string [ j ] == a ) string [ j ] = b ; else if ( string [ j ] == b ) string [ j ] = a ; } }   StringBuilder ans = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = ( char ) ( string [ str [ i ] - ' a ' ] ) ; ans . append ( str [ i ] ) ; }   System . out . println ( ans ) ; } } ","from collections import * from sys import * input = stdin . readlined = defaultdict ( list ) n , m = map ( int , input ( ) . split ( ) ) s = input ( ) flag = 0 flag2 = 0 temp , temp1 = 0 , 0 for i in range ( m ) : x , y = input ( ) . strip ( ) . split ( "" ▁ "" ) if x in d . keys ( ) : flag = 1 for i in d . keys ( ) : if d [ i ] == x : temp = i break else : flag = 0 d [ x ] = y if y in d . keys ( ) : flag2 = 1 for i in d . keys ( ) : if d [ i ] == y : temp1 = i break else : flag2 = 0 d [ y ] = x if flag == 1 : d [ temp ] = y if flag2 == 1 : d [ temp1 ] = x for i in s : if d [ i ] != [ ] : print ( d [ i ] , end = "" "" ) else : print ( i , end = "" "" )     NEW_LINE " V111,"import java . util . * ; import java . io . * ; import java . lang . Math ;    public class C { public static void main ( String args [ ] ) { PrintWriter out = new PrintWriter ( System . out ) ; FastScanner fs = new FastScanner ( ) ; int t = 1 ; for ( int qq = 1 ; qq <= t ; qq ++ ) { int n = 4 ; char line [ ] [ ] = new char [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) line [ i ] = fs . next ( ) . toCharArray ( ) ; boolean ans = false ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < n - 1 ; j ++ ) { int cnt1 = 0 , cnt2 = 0 ; cnt1 += line [ i ] [ j ] == ' # ' ? 1 : 0 ; cnt1 += line [ i + 1 ] [ j ] == ' # ' ? 1 : 0 ; cnt1 += line [ i ] [ j + 1 ] == ' # ' ? 1 : 0 ; cnt1 += line [ i + 1 ] [ j + 1 ] == ' # ' ? 1 : 0 ; cnt2 += line [ i ] [ j ] == ' . ' ? 1 : 0 ; cnt2 += line [ i + 1 ] [ j ] == ' . ' ? 1 : 0 ; cnt2 += line [ i ] [ j + 1 ] == ' . ' ? 1 : 0 ; cnt2 += line [ i + 1 ] [ j + 1 ] == ' . ' ? 1 : 0 ; ","li = [ ] for i in range ( 0 , 4 ) : s = input ( ) li . append ( list ( s ) ) fl = 0 for i in range ( 0 , 3 ) : for j in range ( 0 , 3 ) : se = [ li [ i ] [ j ] , li [ i ] [ j + 1 ] , li [ i + 1 ] [ j ] , li [ i + 1 ] [ j + 1 ] ] if se . count ( ' # ' ) >= 3 or se . count ( ' . ' ) >= 3 : fl = 1 break if fl == 1 : breakif fl == 1 : print ( "" YES "" ) else : print ( "" NO "" ) NEW_LINE " V112,"import java . util . Arrays ; import java . util . Scanner ;   public class EhabFailstoBeThanos { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] arr = new int [ 2 * n ] ; for ( int i = 0 ; i < 2 * n ; i ++ ) { arr [ i ] = scanner . nextInt ( ) ; } Arrays . sort ( arr ) ; int firstHalf = 0 , secondHalf = 0 ; for ( int i = 0 ; i < n ; i ++ ) { firstHalf += arr [ i ] ; } for ( int i = n ; i < 2 * n ; i ++ ) { secondHalf += arr [ i ] ; }   if ( firstHalf != secondHalf ) { for ( int i = 0 ; i < 2 * n ; i ++ ) { System . out . print ( arr [ i ] + "" ▁ "" ) ; } } else System . out . println ( - 1 ) ; } } ","def check ( ) : a . sort ( ) if len ( set ( a ) ) == 1 : print ( "" - 1"" ) else : if sum ( a [ : n ] ) != sum ( a [ : 2 * n ] ) : for item in a : print ( item , end = "" ▁ "" ) else : print ( "" - 1"" )   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( "" ▁ "" ) ) ) check ( ) NEW_LINE " V113,"import java . io . BufferedReader ; import java . io . * ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . math . * ; public class Main { 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 ( ) ) ; } String nextLine ( ) { String str = "" "" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; StringBuffer sb = new StringBuffer ( ) ; int t = 1 ; ","from collections import defaultdictfrom NEW_LINE math NEW_LINE import inf   n , m , x = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE keyboard , shift = [ ] , set ( ) NEW_LINE for i in range ( n ) : ip = input ( ) NEW_LINE line = [ x for x in ip ] NEW_LINE for j in range ( m ) : if NEW_LINE ip [ j ] == ' S ' : shift . add ( ( i , j ) ) NEW_LINE keyboard . append ( line )   q = int ( input ( ) ) NEW_LINE text = input ( )   NEW_LINE " V114,"import java . io . * ;   public class Main { static long n , m , k ; static String [ ] input ; static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ;   public static void main ( String [ ] args ) throws IOException { input = br . readLine ( ) . split ( "" ▁ "" ) ; n = Integer . parseInt ( input [ 0 ] ) ; m = Integer . parseInt ( input [ 1 ] ) ; k = Long . parseLong ( input [ 2 ] ) ; if ( k < n ) { bw . write ( k + 1 + "" ▁ "" + 1 ) ; } else { long x = n - ( k - n ) / ( m - 1 ) , y = ( k - n ) % ( m - 1 ) ; y = ( x & 1 ) == 1 ? m - y : 2 + y ; bw . write ( x + "" ▁ "" + y ) ; } bw . close ( ) ; } } ","import mathn , m , k = map ( int , input ( ) . strip ( ) . split ( ' ▁ ' ) ) NEW_LINE " V115,"import java . util . Scanner ;   public class A635 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int R = in . nextInt ( ) ; int C = in . nextInt ( ) ; int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; boolean [ ] [ ] A = new boolean [ R ] [ C ] ; for ( int n = 0 ; n < N ; n ++ ) { int r = in . nextInt ( ) - 1 ; int c = in . nextInt ( ) - 1 ; A [ r ] [ c ] = true ; } int answer = 0 ; for ( int fromR = 0 ; fromR < R ; fromR ++ ) { for ( int fromC = 0 ; fromC < C ; fromC ++ ) { for ( int toR = fromR ; toR < R ; toR ++ ) { for ( int toC = fromC ; toC < C ; toC ++ ) { int count = 0 ; for ( int r = fromR ; r <= toR ; r ++ ) { for ( int c = fromC ; c <= toC ; c ++ ) { if ( A [ r ] [ c ] ) { count ++ ; } } } if ( count >= K ) { answer ++ ; } } } } } System . out . println ( answer ) ; }   } ","r , c , n , k = map ( int , input ( ) . split ( ) )   M = [ [ ' * ' ] * c for i in range ( r ) ]   for i in range ( n ) : x , y = map ( int , input ( ) . split ( ) ) M [ x - 1 ] [ y - 1 ] = ' # '   def contain ( M , k , x1 , y1 , x2 , y2 ) : for i in range ( x1 , x2 + 1 ) : for j in range ( y1 , y2 + 1 ) : if M [ i ] [ j ] == ' # ' : k -= 1 return k <= 0   ans = 0 for x1 in range ( r ) : for y1 in range ( c ) : for x2 in range ( x1 , r ) : for y2 in range ( y1 , c ) : if contain ( M , k , x1 , y1 , x2 , y2 ) : ans += 1 print ( ans ) NEW_LINE " V116,"import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; import java . util . Stack ;   public class test {   public static void main ( String [ ] args ) {   Scanner enter = new Scanner ( System . in ) ; int n = enter . nextInt ( ) , m = enter . nextInt ( ) , k = enter . nextInt ( ) , rows [ ] = new int [ m + 1 ] , values [ ] = new int [ m + 1 ] , row = 0 , viability = 0 , max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { row = enter . nextInt ( ) ; viability = enter . nextInt ( ) ; if ( rows [ row ] == 0 ) { max += viability ; rows [ row ] = 1 ; values [ row ] = viability ; } else if ( rows [ row ] == 1 ) { if ( viability < values [ row ] ) { max -= values [ row ] ; max += viability ; values [ row ] = viability ; } } } System . out . println ( max > k ? k : max ) ; }   } ","n , m , k = list ( map ( int , input ( ) . split ( ) ) ) a = [ [ ] for i in range ( m ) ] for i in range ( n ) : r , c = list ( map ( int , input ( ) . split ( ) ) ) a [ r - 1 ] . append ( c ) b = 0 for i in range ( m ) : d = - 1 for j in a [ i ] : if d == - 1 or j < d : d = j b += dprint ( min ( b , k ) ) NEW_LINE " V117,"import java . lang . * ; import java . util . * ;   public class Abhishek {   public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; boolean pos = false ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; if ( a [ i ] >= 0 ) pos = true ; } Arrays . sort ( a ) ; long res = Long . MIN_VALUE ;   res = Math . max ( res , a [ n - 1 ] * a [ n - 2 ] * a [ n - 3 ] * a [ n - 4 ] * a [ n - 5 ] ) ; res = Math . max ( res , a [ 0 ] * a [ 1 ] * a [ n - 1 ] * a [ n - 2 ] * a [ n - 3 ] ) ; res = Math . max ( res , a [ 0 ] * a [ 1 ] * a [ 2 ] * a [ 3 ] * a [ n - 1 ] ) ;   System . out . println ( res ) ; } } } ","from sys import stdinfrom NEW_LINE math NEW_LINE import prod   input = stdin . readline   for test in range ( int ( input ( ) ) ) : n = int ( input ( ) ) NEW_LINE lst = sorted ( list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) , reverse = True ) NEW_LINE " V118,"import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int w = sc . nextInt ( ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int wc = 0 ; int hc = 0 ; for ( int i = w ; ( i & 1 ) == 0 ; i /= 2 ) { wc ++ ; } for ( int i = h ; ( i & 1 ) == 0 ; i /= 2 ) { hc ++ ; } if ( fastPower ( 2 , wc + hc ) >= n ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } public static int fastPower ( int a , int b ) { if ( b == 0 ) return 1 ; if ( ( b & 1 ) == 0 ) return fastPower ( a * a , b / 2 ) ; else return a * fastPower ( a , b - 1 ) ; } } ","import sys , mathimport NEW_LINE copyimport NEW_LINE heapq   from collections import NEW_LINE INDENT dequeinput = sys . stdin . readline   NEW_LINE DEDENT " V119,"import java . io . PrintWriter ; import java . util . * ; import java . lang . * ; public class Main { static int po ( int n ) { int a = 2 ; int res = 1 ; while ( n > 0 ) { if ( n % 2 == 0 ) { res *= a ; n -- ; } else { a *= a ; n /= 2 ; } } return res ; } static long f ( long num ) { HashSet < Long > h = new HashSet < > ( ) ; int res = 0 , flag = 1 ; while ( num > 0 ) { long n = num % 10 ; if ( ! h . contains ( n ) ) { h . add ( n ) ; num /= 10 ; res += n ; } else { flag = 0 ; break ; } } if ( flag == 0 ) { return - 1 ; } return res ; } public static void main ( String [ ] args ) { PrintWriter out1 = new PrintWriter ( System . out ) ; Scanner sc = new Scanner ( System . in ) ; ","n , m = map ( int , input ( ) . split ( ) ) a = set ( map ( int , input ( ) . split ( ) ) ) b = set ( map ( int , input ( ) . split ( ) ) )   c = a & bif c : print ( min ( c ) ) else : x , y = min ( a ) , min ( b ) print ( min ( x , y ) * 10 + max ( x , y ) ) NEW_LINE " V120,"import java . util . * ;   public class PaintingEggs_B {   public static void main ( String [ ] args ) { ","from sys import stdin , stdoutinput = stdin . readlineprint = stdout . writen = int ( input ( ) ) a , g = 0 , 0 sol = "" "" for i in range ( n ) : prva , druga = map ( int , input ( ) . split ( ) ) if a + prva - g <= 500 : a += prva print ( "" A "" ) else : g += druga print ( "" G "" ) NEW_LINE " V121,"import java . util . * ; import java . io . * ; public class TestClass { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int q = Integer . parseInt ( br . readLine ( ) ) ; while ( q -- > 0 ) { int nr [ ] = new int [ 2 ] ; int i = 0 ; for ( String s : br . readLine ( ) . split ( "" ▁ "" ) ) nr [ i ++ ] = Integer . parseInt ( s ) ; int n = nr [ 0 ] ; int r = nr [ 1 ] ; HashSet < Integer > set = new HashSet < > ( ) ; for ( String s : br . readLine ( ) . split ( "" ▁ "" ) ) set . add ( Integer . parseInt ( s ) ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; list . addAll ( set ) ; Collections . sort ( list , Collections . reverseOrder ( ) ) ; ","from sys import stdin , stdout , stderrimport time , mathfrom collections import defaultdict as dd , Counter def pn ( ob ) : stdout . write ( str ( ob ) ) def inp ( ) : return stdin . readline ( )   def main ( ) : t = int ( inp ( ) ) for testNumber in range ( 1 , t + 1 , 1 ) : process ( )   def process ( ) : n , r = map ( int , inp ( ) . split ( ) ) arr = list ( map ( int , inp ( ) . split ( ) ) )   arr . sort ( )   res = 0 missiles_launched = 0 i = n - 1 while ( i >= 0 ) : if ( arr [ i ] - missiles_launched * r <= 0 ) : break   while ( i - 1 >= 0 and arr [ i ] == arr [ i - 1 ] ) : i -= 1 missiles_launched += 1 i -= 1   pn ( str ( missiles_launched ) + ' \n ' )   if __name__ == ' _ _ main _ _ ' : main ( ) NEW_LINE " V122,"import java . util . Scanner ;   public class Main { static boolean flag ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; int d = in . nextInt ( ) ; fun ( a , b , c ) ; ","arr = sorted ( map ( int , input ( ) . split ( ) ) ) a , b , c , d = arr   if a + b > c or b + c > d : print ( "" TRIANGLE "" ) elif a + b == c or b + c == d : print ( "" SEGMENT "" ) else : print ( "" IMPOSSIBLE "" ) NEW_LINE " V123,"import java . io . * ; import java . util . * ;   public class Main { public static int [ ] d = new int [ 1000010 ] ; public static int [ ] e = new int [ 1000010 ] ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintStream out = System . out ; int n = in . nextInt ( ) , ans = 0 ; for ( int i = 2 , j ; i <= n ; i ++ ) { j = in . nextInt ( ) ; d [ i ] = 1 + d [ j ] ; } for ( int i = 1 ; i <= n ; i ++ ) { e [ d [ i ] ] ^= 1 ; ans += e [ d [ i ] ] * 2 - 1 ; } out . println ( ans ) ; } } ","n = int ( input ( ) ) ans = 1   A = list ( map ( int , input ( ) . split ( ) ) ) h = [ 0 for i in range ( n + 1 ) ] B = [ 0 for i in range ( n + 1 ) ]   for i in range ( n - 1 ) : h [ i + 2 ] = h [ A [ i ] ] + 1 B [ h [ i + 2 ] ] += 1 for x in B : if x % 2 != 0 : ans += 1 print ( ans ) NEW_LINE " V124,"import java . io . * ; import java . util . * ; import java . lang . * ; public class aim { public static void main ( String args [ ] ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int a [ ] = new int [ n ] ; int b [ ] = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) b [ i ] = sc . nextInt ( ) ; if ( a [ k - 1 ] < b [ m - l ] ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def solve ( na , nb , k , m , a , b ) : res_a = max ( a [ : k ] ) res_b = min ( b [ - m : ] ) return "" NO "" if res_a >= res_b else "" YES ""         def main ( ) : na , nb = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) k , m = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) a = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) b = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) NEW_LINE " V125,"import java . util . * ; public class rbk { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int r1 = s . nextInt ( ) ; int c1 = s . nextInt ( ) ; int r2 = s . nextInt ( ) ; int c2 = s . nextInt ( ) ; if ( ( r1 == r2 ) || ( c1 == c2 ) ) { System . out . print ( 1 + "" ▁ "" ) ; } else { System . out . print ( 2 + "" ▁ "" ) ; } if ( ( r1 + c1 ) % 2 != ( r2 + c2 ) % 2 ) { System . out . print ( 0 + "" ▁ "" ) ; } else { if ( ( r1 + c1 == r2 + c2 ) || ( r1 - c1 == r2 - c2 ) ) { System . out . print ( 1 + "" ▁ "" ) ; } else { System . out . print ( 2 + "" ▁ "" ) ; } } System . out . println ( Math . max ( Math . abs ( r1 - r2 ) , Math . abs ( c1 - c2 ) ) ) ; } } ","a , b , c , d = map ( int , input ( ) . split ( ) ) if ( a == c and b == d ) : rook = 0 elif ( a == c or b == d ) : rook = 1 else : rook = 1 + 1   king = max ( abs ( a - c ) , abs ( b - d ) )   if ( abs ( a - c ) % 2 != abs ( b - d ) % 2 ) : bishop = 0 else : if ( a == c and b == d ) : bishop = 0 elif ( abs ( a - c ) == abs ( b - d ) ) : bishop = 1 else : bishop = 1 + 1 print ( rook , bishop , king ) NEW_LINE " V126,"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . util . Arrays ; import java . io . IOException ; import java . io . UncheckedIOException ; import java . io . Closeable ; import java . io . Writer ; import java . io . OutputStreamWriter ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) throws Exception { Thread thread = new Thread ( null , new TaskAdapter ( ) , "" "" , 1 << 27 ) ; thread . start ( ) ; thread . join ( ) ; } static class TaskAdapter implements Runnable { @ Override public void run ( ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastInput in = new FastInput ( inputStream ) ; FastOutput out = new FastOutput ( outputStream ) ; BNastyaAndScoreboard solver = new BNastyaAndScoreboard ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } } static class BNastyaAndScoreboard { public void solve ( int testNumber , FastInput in , FastOutput out ) { int n = in . readInt ( ) ; int k = in . readInt ( ) ; int [ ] bits = new int [ 10 ] ; bits [ 0 ] = parse ( 123567 ) ; bits [ 1 ] = parse ( 36 ) ; bits [ 2 ] = parse ( 13457 ) ; bits [ 3 ] = parse ( 13467 ) ; bits [ 4 ] = parse ( 2346 ) ; bits [ 5 ] = parse ( 12467 ) ; bits [ 6 ] = parse ( 124567 ) ; bits [ 7 ] = parse ( 136 ) ; bits [ 8 ] = parse ( 1234567 ) ; bits [ 9 ] = parse ( 123467 ) ; ","import sysfrom collections import defaultdictD = [ ""1110111"" , ""0010010"" , ""1011101"" , ""1011011"" , ""0111010"" , ""1101011"" , ""1101111"" , ""1010010"" , ""1111111"" , ""1111011"" ] SIGN = [ bin ( i ) [ 2 : ] . zfill ( 7 ) for i in range ( 1 << 7 ) ] RESTORE = { SIGN [ i ] : i for i in range ( 1 << 7 ) } COST = [ [ - 1 ] * ( 10 ) for i in range ( 1 << 7 ) ] for i in range ( 1 << 7 ) : for j in range ( 10 ) : si = SIGN [ i ] sj = D [ j ] cost = 0 possible = True for k in range ( 7 ) : if si [ k ] == ""1"" and sj [ k ] == ""0"" : COST [ i ] [ j ] = - 1 possible = False break elif si [ k ] == ""0"" and sj [ k ] == ""1"" : cost += 1 if possible : COST [ i ] [ j ] = cost     def input ( ) : return sys . stdin . readline ( ) . rstrip ( )     NEW_LINE " V127,"import java . util . * ; import java . lang . * ; import java . io . * ;   public class FastIO { BufferedReader br ; StringTokenizer st ; public FastIO ( ) { ","n , m = map ( int , input ( ) . split ( ) ) a = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) s = a [ - 1 ] - a [ 0 ] for i in range ( n - 1 , m ) : s = min ( s , a [ i ] - a [ i - n + 1 ] ) print ( s ) NEW_LINE " V128,"import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   ","import mathimport collectionsimport bisect   def solve ( n , d , m ) : for i in range ( m ) : x , y = [ int ( s ) for s in input ( ) . split ( ) ] if d <= x + y and x + y <= 2 * n - d and - d <= x - y and x - y <= d : print ( "" YES "" ) else : print ( "" NO "" )   n , d = [ int ( s ) for s in input ( ) . split ( ) ] m = int ( input ( ) ) solve ( n , d , m ) NEW_LINE " V129,"   import java . util . * ; public class CodeForces910C { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ans = 1 , x = 0 , y = 0 , z = n ; while ( x < 4 || y < 2 ) { if ( z >= a & x < 4 ) { z -= a ; x += 1 ; } if ( z >= b & y < 2 ) { z -= b ; y += 1 ; } if ( x == 4 & y == 2 ) break ; if ( ( z < a || x == 4 ) && ( z < b || y == 2 ) ) { z = n ; ans += 1 ; } } System . out . println ( ans ) ; sc . close ( ) ; } } ","import osimport sysfrom io import BytesIO , IOBase   BUFSIZE = 8192     class FastIO ( IOBase ) : newlines = 0   def __init__ ( self , file ) : self . _fd = file . fileno ( ) self . buffer = BytesIO ( ) self . writable = "" x "" in file . mode or "" r "" not in file . mode self . write = self . buffer . write if self . writable else None   def read ( self ) : while True : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) if not b : break ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines = 0 return self . buffer . read ( )   def readline ( self ) : while self . newlines == 0 : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) self . newlines = b . count ( b "" \n "" ) + ( not b ) ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines -= 1 return self . buffer . readline ( )   def flush ( self ) : if self . writable : os . write ( self . _fd , self . buffer . getvalue ( ) ) self . buffer . truncate ( 0 ) , self . buffer . seek ( 0 )     class IOWrapper ( IOBase ) : def __init__ ( self , file ) : self . buffer = FastIO ( file ) self . flush = self . buffer . flush self . writable = self . buffer . writable self . write = lambda s : self . buffer . write ( s . encode ( "" ascii "" ) ) self . read = lambda : self . buffer . read ( ) . decode ( "" ascii "" ) self . readline = lambda : self . buffer . readline ( ) . decode ( "" ascii "" )     sys . stdin , sys . stdout = IOWrapper ( sys . stdin ) , IOWrapper ( sys . stdout ) input = lambda : sys . stdin . readline ( ) . rstrip ( "" \n "" ) NEW_LINE " V130,"  import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class experiment { static int M = 1_000_000_007 ; static int INF = Integer . MAX_VALUE ; static final FastScanner fs = new FastScanner ( ) ;   ","import mathn , m = map ( int , input ( ) . split ( ) ) A = list ( map ( int , input ( ) . split ( ) ) ) B = [ ] max = 0 last = 0 for i in range ( n ) : if math . ceil ( A [ i ] / m ) >= max : last = i max = math . ceil ( A [ i ] / m ) print ( last + 1 ) NEW_LINE " V131,"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 t = 1 ; t = sc . nextInt ( ) ; while ( t != 0 ) { int n = sc . nextInt ( ) ; int arr [ ] = new int [ n ] ; int s = 0 , mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; s += arr [ i ] ; mx = Math . max ( mx , arr [ i ] ) ; } if ( n == 1 ) { System . out . println ( "" T "" ) ; } else { if ( s - mx < mx ) { System . out . println ( "" T "" ) ; } else { if ( s % 2 == 1 ) { System . out . println ( "" T "" ) ; } else System . out . println ( "" HL "" ) ; } } t -= 1 ; } } } ","def stoned ( arr ) : NEW_LINE INDENT s = sum ( arr ) NEW_LINE if max ( arr ) > s // 2 : return "" T "" NEW_LINE if s % 2 == 0 : NEW_LINE INDENT return "" HL "" NEW_LINE DEDENT else : NEW_LINE INDENT return "" T "" NEW_LINE DEDENT DEDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT a = input ( ) NEW_LINE lst = list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) NEW_LINE print ( stoned ( lst ) ) NEW_LINE DEDENT " V132,"  import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; while ( input . hasNext ( ) ) { int n = input . nextInt ( ) ; System . out . println ( ( n + 1 ) / 2 - 1 ) ; } } }   ","print ( ( int ( input ( ) ) - 1 ) // 2 ) NEW_LINE " V133,"import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . InputStreamReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . StringTokenizer ;   public class B202 { static final boolean FILE_IO = false ; static final String output_file = "" output . txt "" ; static final String input_file = "" input . txt "" ;   public static void main ( String [ ] args ) { InputReader in = new InputReader ( ) ; PrintWriter out ; if ( FILE_IO ) { try { out = new PrintWriter ( output_file ) ; } catch ( FileNotFoundException e ) { throw new RuntimeException ( e ) ; } } else { out = new PrintWriter ( System . out ) ; } final long start = System . currentTimeMillis ( ) ; new Task1 ( ) . solve ( in , out ) ; final long duration = System . currentTimeMillis ( ) - start ; out . close ( ) ; }   static class Task1 { static final String sequence = ""0123"" ; static ArrayList < String > permutations ;   public void solve ( InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; HashMap < String , Integer > map = new HashMap < String , Integer > ( ) ; permutations = new ArrayList < String > ( ) ;   for ( int i = 0 ; i < n ; i ++ ) { String temp = in . next ( ) ; map . put ( temp , i ) ; }   findPermutations ( "" "" , sequence . substring ( 0 , n ) ) ; int [ ] inversions = new int [ permutations . size ( ) ] ; for ( int i = 0 ; i < permutations . size ( ) ; i ++ ) { inversions [ i ] = numberOfInversions ( permutations . get ( i ) ) ; ","import itertools   def check ( curr_words , line ) : if curr_words == [ ] : return True for i in range ( len ( line ) ) : if line [ i ] == curr_words [ 0 ] : return check ( curr_words [ 1 : ] , line [ i + 1 : ] ) return False   n = int ( input ( ) ) words = input ( ) . split ( ) m = int ( input ( ) ) res , idx = 0 , 0 for i in range ( m ) : line = input ( ) . split ( ) [ 1 : ] for p in itertools . permutations ( range ( n ) ) : curr_words = [ words [ j ] for j in p ] cnt = 0 for j in range ( n ) : cnt += len ( [ k for k in range ( j + 1 , n ) if p [ k ] < p [ j ] ] ) v = n * ( n - 1 ) // 2 - cnt + 1 if check ( curr_words , line [ : ] ) and v > res : res , idx = v , i + 1 if res > 0 : print ( idx ) print ( ' [ : ' + str ( ' | ' * res ) + ' : ] ' ) else : print ( ' Brand ▁ new ▁ problem ! ' ) NEW_LINE " V134,"import java . util . * ; import java . lang . * ; import java . io . * ;   public class B_Snow_Walking_Robot { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; ","import collections   n = int ( input ( ) ) for i in range ( n ) : move = input ( ) counter = collections . Counter ( move ) ver , hor = min ( counter [ ' U ' ] , counter [ ' D ' ] ) , min ( counter [ ' L ' ] , counter [ ' R ' ] ) if ver and hor : print ( 2 * ( ver + hor ) ) print ( "" L "" * hor + "" U "" * ver + "" R "" * hor + "" D "" * ver ) elif not ver and not hor : print ( ""0"" ) else : print ( ""2"" ) if ver : print ( "" UD "" ) elif hor : print ( "" LR "" ) NEW_LINE " V135,"import java . util . * ; public class kthlargest { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , q = sc . nextInt ( ) , a [ ] = new int [ n ] , c [ ] = new int [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) c [ a [ i ] = sc . nextInt ( ) ] ++ ; while ( q -- > 0 ) { int t1 = sc . nextInt ( ) , t2 = sc . nextInt ( ) ; if ( t1 == 1 ) { if ( a [ t2 - 1 ] == 0 ) { c [ 1 ] ++ ; c [ 0 ] -- ; } else { c [ 1 ] -- ; c [ 0 ] ++ ; } a [ t2 - 1 ] = 1 - a [ t2 - 1 ] ; } else { System . out . println ( c [ 1 ] >= t2 ? 1 : 0 ) ; } } } } ","R = lambda : map ( int , input ( ) . split ( ) ) NEW_LINE n , q = R ( ) NEW_LINE r = sum ( a : = [ 0 , * R ( ) ] ) NEW_LINE while q : NEW_LINE INDENT q -= 1 ; NEW_LINE t , x = R ( ) NEW_LINE if t < 2 or print ( + ( x <= r ) ) : a [ x ] ^= 1 ; r += 2 * a [ x ] - 1 NEW_LINE DEDENT " V136,"import java . util . * ; import java . io . * ;   public class Main {   public static void main ( String [ ] args ) throws IOException , InterruptedException { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; long ax = sc . nextLong ( ) , ay = sc . nextLong ( ) ; long bx = sc . nextLong ( ) , by = sc . nextLong ( ) ; long cx = sc . nextLong ( ) , cy = sc . nextLong ( ) ; long dist1 = ( ax - bx ) * ( ax - bx ) + ( ay - by ) * ( ay - by ) ; long dist2 = ( cx - bx ) * ( cx - bx ) + ( cy - by ) * ( cy - by ) ; long dist3 = ( cx - ax ) * ( cx - ax ) + ( cy - ay ) * ( cy - ay ) ; ","ax , ay , bx , by , cx , cy = map ( int , input ( ) . split ( ) ) ans = ( by - ay ) * ( cx - bx ) == ( cy - by ) * ( bx - ax ) if ans : ans = 0 else : ans = 1 d1 = ( by - ay ) ** 2 + ( bx - ax ) ** 2 d2 = ( cy - by ) ** 2 + ( cx - bx ) ** 2 if d1 == d2 : ans2 = 1 else : ans2 = 0 if ans and ans2 : print ( "" Yes "" ) else : print ( "" No "" )   NEW_LINE " V137,"import java . math . * ; import java . util . * ; public class MagicalCalender { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int runs = sc . nextInt ( ) ; while ( runs -- > 0 ) { long n = sc . nextLong ( ) ; long r = sc . nextLong ( ) ; long out = 1 ; if ( r < n ) out = r * ( r + 1 ) / 2 ; else { out = n * ( n - 1 ) / 2 + 1 ; } System . out . println ( out ) ; } } } ","for _ in range ( int ( input ( ) ) ) : a , b = map ( int , input ( ) . split ( ) ) print ( min ( 1 + ( a * ( a - 1 ) // 2 ) , b * ( b + 1 ) // 2 ) ) NEW_LINE " V138,"import java . util . * ;   public class questionCF {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; ArrayList < Integer > a = new ArrayList < > ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int total = 0 ; if ( s . charAt ( i ) == ' B ' ) { count ++ ; for ( int j = i ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) == ' B ' ) { total ++ ; i ++ ; } else break ; } a . add ( total ) ; } } System . out . println ( a . size ( ) ) ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) System . out . print ( a . get ( i ) + "" ▁ "" ) ; } }   ","import mathn = int ( input ( ) ) s = input ( ) num = 0 nums = [ ]   for i in range ( n ) : if s [ i ] == ' W ' and num != 0 : nums . append ( num ) num = 0 elif s [ i ] == ' B ' : num += 1     if num != 0 : nums . append ( num )   print ( len ( nums ) ) print ( * nums )     NEW_LINE " V139,"import java . io . * ; import java . util . * ;   public class Main { static int M = 1_000_000_007 ;   private static boolean testCase ( int x , int y , String s ) { int [ ] [ ] positions = new int [ s . length ( ) ] [ 2 ] ; int currX = 0 , currY = 0 ;   for ( int i = 0 ; i < s . length ( ) ; i ++ ) { positions [ i ] = new int [ ] { currX , currY } ;   switch ( s . charAt ( i ) ) { case ' U ' : currY ++ ; break ; case ' D ' : currY -- ; break ; case ' L ' : currX -- ; break ; case ' R ' : currX ++ ; break ; } }   if ( currX != 0 ) { for ( int [ ] position : positions ) { if ( ( x - position [ 0 ] ) % currX == 0 ) { int k = ( x - position [ 0 ] ) / currX ;   if ( k >= 0 && position [ 1 ] + k * currY == y ) { return true ; } } } } else if ( currY != 0 ) { for ( int [ ] position : positions ) { if ( ( y - position [ 1 ] ) % currY == 0 ) { int k = ( y - position [ 1 ] ) / currY ;   if ( k >= 0 && position [ 0 ] + k * currX == x ) { return true ; } } } } else { for ( int [ ] position : positions ) { if ( x == position [ 0 ] && y == position [ 1 ] ) { return true ; } } }     return false ; }   public static void main ( String [ ] args ) { FastScanner in = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; ","def R ( ) : return map ( int , input ( ) . split ( ) ) def I ( ) : return int ( input ( ) ) def S ( ) : return str ( input ( ) )   def L ( ) : return list ( R ( ) )   from collections import Counter   import mathimport sys   from itertools import permutations   import bisect   a , b = R ( )   s = S ( ) l = len ( s ) step = [ ]   x , y = 0 , 0   d = { ' U ' : ( 0 , 1 ) , ' D ' : ( 0 , - 1 ) , ' L ' : ( - 1 , 0 ) , ' R ' : ( 1 , 0 ) }   step . append ( ( 0 , 0 ) )   for i in range ( l ) : dx , dy = d [ s [ i ] ] x += dx y += dy   step . append ( ( x , y ) )   tx , ty = step [ l ]   for j in range ( l ) : xj , yj = step [ j ]   if tx == 0 and ty == 0 : if a == xj and b == yj : print ( ' Yes ' ) exit ( )   else : continue   if tx == 0 and ( a != xj or ( b - yj ) % ty != 0 or ( ( b - yj ) % ty == 0 and ( b - yj ) / ty < 0 ) ) : continue   if ty == 0 and ( b != yj or ( a - xj ) % tx != 0 or ( ( a - xj ) % tx == 0 and ( a - xj ) / tx < 0 ) ) : continue   if tx == 0 or ty == 0 : print ( ' Yes ' ) exit ( )   if ( a - xj ) % tx == 0 and ( b - yj ) % ty == 0 and ( a - xj ) / tx == ( b - yj ) / ty >= 0 : print ( ' Yes ' ) exit ( )     print ( ' No ' )                   NEW_LINE " V140,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . List ; import java . util . Random ; import java . util . StringTokenizer ;   ","f = lambda : map ( int , input ( ) . split ( ) ) n , p = f ( ) s = [ 0 ] * nx , y = - p , 0 for i in range ( n ) : a , b = f ( ) x += a y += b s [ i ] = ( a , b ) s . sort ( key = lambda q : q [ 0 ] / q [ 1 ] ) for a , b in s : if b * x > a * y : x -= a y -= b   print ( y / x if x > 0 else - 1 ) NEW_LINE " V141,"import java . util . * ; public class Swim3 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { long p = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; System . out . println ( Math . min ( ( a - p % a ) % a , Math . min ( ( b - p % b ) % b , ( c - p % c ) % c ) ) ) ; } } } ","for s in [ * open ( 0 ) ] [ 1 : ] : p , * a = map ( int , s . split ( ) ) ; print ( min ( - p % x for x in a ) ) NEW_LINE " V142,"import java . util . Scanner ;   public class A1438 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; StringBuilder output = new StringBuilder ( ) ; for ( int t = 0 ; t < T ; t ++ ) { int N = in . nextInt ( ) ; for ( int n = 0 ; n < N ; n ++ ) { output . append ( ""1 ▁ "" ) ; } output . append ( ' \n ' ) ; } System . out . print ( output ) ; }   } ","for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) NEW_LINE a = [ ] NEW_LINE i = 0 NEW_LINE while i < n : print ( 1 , end = "" ▁ "" ) NEW_LINE i += 1 NEW_LINE print ( "" "" ) NEW_LINE " V143,"import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   ","import sys , math , itertoolsfrom collections import Counter , deque , defaultdictfrom bisect import bisect_left , bisect_right from heapq import heappop , heappush , heapify , nlargestfrom copy import deepcopymod = 10 ** 9 + 7 INF = float ( ' inf ' ) def inp ( ) : return int ( sys . stdin . readline ( ) ) def inpl ( ) : return list ( map ( int , sys . stdin . readline ( ) . split ( ) ) ) def inpl_1 ( ) : return list ( map ( lambda x : int ( x ) - 1 , sys . stdin . readline ( ) . split ( ) ) ) def inps ( ) : return sys . stdin . readline ( ) def inpsl ( x ) : tmp = sys . stdin . readline ( ) ; return tmp [ : x ] def err ( x ) : print ( x ) ; exit ( )   for _ in range ( inp ( ) ) : l , r = inpl ( ) y = r // l * l print ( l , y ) NEW_LINE " V144,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ; import java . util . * ;   public class CF576A { public static void main ( String [ ] args ) { FastReader input = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ;   boolean [ ] prime = new boolean [ 1000 + 1 ] ; Arrays . fill ( prime , true ) ;   prime [ 0 ] = false ; prime [ 1 ] = false ;   for ( int i = 2 ; i <= 1000 ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j <= 1000 ; j += i ) { prime [ j ] = false ; } } }   int x = input . nextInt ( ) ;   ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 2 ; i <= x ; i ++ ) { if ( prime [ i ] ) { for ( int j = i ; j <= x ; j *= i ) { if ( j <= x ) { list . add ( j ) ; } } } }   System . out . println ( list . size ( ) ) ; for ( int i : list ) System . out . print ( i + "" ▁ "" ) ;      ","def prime ( n ) : for i in range ( 2 , n ) : if n % i == 0 : return False return Truen = int ( input ( ) ) ans = [ ] for i in range ( 2 , n + 1 ) : if prime ( i ) : ans . append ( i ) k = 2 while i ** k <= n : ans . append ( i ** k ) k += 1 print ( len ( ans ) ) print ( * ans ) NEW_LINE " V145,"import java . util . Scanner ;    public class Code {   private static boolean isPalindrom ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - 1 - i ) ) { return false ; } } return true ; }   public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; String s = cin . next ( ) ; int cnt = 0 ; while ( true ) { if ( isPalindrom ( s ) ) { break ; } int last = Integer . parseInt ( s . substring ( 3 ) ) ; if ( last != 59 ) { last ++ ; s = s . substring ( 0 , 3 ) + ( last <= 9 ? ""0"" + last : last ) ; } else { int begin = Integer . parseInt ( s . substring ( 0 , 2 ) ) ; if ( begin == 23 ) { cnt ++ ; break ; } begin ++ ; s = ( begin <= 9 ? ""0"" + begin : begin ) + "" : 00"" ; } cnt ++ ; } System . out . println ( cnt ) ;   } } ","hh , mm = input ( ) . split ( "" : "" ) def ispalindrome ( H , M ) : if ( H [ 0 ] == M [ 1 ] and H [ 1 ] == M [ 0 ] ) : return True return False   flag = minute = 0 while True : if ( ispalindrome ( hh , mm ) ) : print ( minute ) break if ( int ( mm [ 1 ] ) == 9 ) : temp = mm mm = str ( int ( temp [ 0 ] ) + 1 ) + ""0"" else : temp = mm mm = temp [ 0 ] + str ( int ( temp [ 1 ] ) + 1 ) minute += 1 if ( int ( mm ) > 59 ) : mm = ""00"" if ( int ( hh ) < 23 ) : temp = hh hh = str ( int ( temp ) + 1 ) if ( len ( hh ) < 2 ) : hh = ""0"" + hh else : hh = ""00"" NEW_LINE " V146,"import java . util . * ; import java . io . * ; import java . math . BigInteger ; import java . text . * ; public class Main { static long mod = 1000_000_007 ; static long mod1 = 998244353 ; static boolean fileIO = false ; static boolean memory = true ; static FastScanner f ; static PrintWriter pw ; static double eps = ( double ) 1e-6 ; static int oo = ( int ) 1e7 ; ","n , m = map ( int , input ( ) . split ( ) ) l = list ( map ( int , input ( ) . split ( ) ) )   s = [ i + 1 for i in range ( n ) ]   for i in range ( m ) : for j in range ( len ( s ) ) : if ( s [ j ] >= 0 and s [ j ] >= l [ i ] ) : s [ j ] = - ( l [ i ] )   for i in s : print ( abs ( i ) , end = "" ▁ "" ) NEW_LINE " V147,"import java . util . Scanner ;   public class Program { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int t = Integer . valueOf ( input . nextLine ( ) ) ;   for ( int i = 0 ; i < t ; i ++ ) { int n = input . nextInt ( ) ; int m = input . nextInt ( ) ;   String result = isPossible ( n , m ) ; System . out . println ( result ) ; }   }   private static String isPossible ( int n , int m ) { if ( n == 2 && m == 2 ) return "" YES "" ;   if ( n > 1 && m > 1 ) return "" NO "" ;   return "" YES "" ; }   } ","n = int ( input ( ) ) for i in range ( n ) : n , k = list ( map ( int , input ( ) . split ( ) ) ) if ( n == 1 or k == 1 ) or n == 2 and k == 2 : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE " V148,"import java . util . Scanner ;   public class _0590poster {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int mid = n % 2 == 0 ? n / 2 : n / 2 + 1 ; boolean fromStart = false ; if ( k <= mid ) { fromStart = true ; } if ( fromStart ) { for ( int i = 1 ; i < k ; i ++ ) { System . out . println ( "" LEFT "" ) ; } for ( int i = 1 ; i <= n ; i ++ ) { System . out . println ( "" PRINT ▁ "" + s . charAt ( i - 1 ) ) ; if ( i != n ) { System . out . println ( "" RIGHT "" ) ; } } } else { for ( int i = k ; i < n ; i ++ ) { System . out . println ( "" RIGHT "" ) ; } for ( int i = n ; i > 0 ; i -- ) { System . out . println ( "" PRINT ▁ "" + s . charAt ( i - 1 ) ) ; if ( i != 1 ) { System . out . println ( "" LEFT "" ) ; } } } }   } ","a , b = map ( int , input ( ) . split ( ) ) s = input ( ) x = 0 a -= 1 b -= 1   if ( b < a - b ) : for i in range ( b ) : print ( "" LEFT "" ) x = 1 else : for i in range ( a - b ) : print ( "" RIGHT "" ) x = - 1 s = s [ : : - 1 ]     for i in s [ : - 1 ] : print ( f "" PRINT ▁ { i } "" ) if x == - 1 : print ( "" LEFT "" ) else : print ( "" RIGHT "" )     print ( f "" PRINT ▁ { s [ -1 ] } "" ) NEW_LINE " V149,"import java . util . Scanner ; public class Main13 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; boolean [ ] h1 = new boolean [ x ] ; boolean [ ] v1 = new boolean [ x ] ; for ( int i = 0 ; i < x * x ; i ++ ) { int h = sc . nextInt ( ) ; int v = sc . nextInt ( ) ; if ( ! h1 [ h - 1 ] && ! v1 [ v - 1 ] ) { System . out . print ( ( i + 1 ) + "" ▁ "" ) ; h1 [ h - 1 ] = true ; v1 [ v - 1 ] = true ; } } } } ","n = int ( input ( ) )   arr1 = set ( ) arr2 = set ( )   for i in range ( n ** 2 ) : a , b = map ( int , input ( ) . split ( ) ) if a not in arr1 and b not in arr2 : print ( i + 1 , end = "" ▁ "" ) arr1 . add ( a ) arr2 . add ( b )         NEW_LINE " V150,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ;   public class Building {   public static void main ( String [ ] args ) { BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ;   try {   String [ ] line = bf . readLine ( ) . split ( "" ▁ "" ) ; int a = Integer . parseInt ( line [ 2 ] ) ; int b = Integer . parseInt ( line [ 3 ] ) ; int k = Integer . parseInt ( line [ 4 ] ) ; for ( int i = 0 ; i < k ; i ++ ) { String [ ] query = bf . readLine ( ) . split ( "" ▁ "" ) ; int ta = Integer . parseInt ( query [ 0 ] ) ; int fa = Integer . parseInt ( query [ 1 ] ) ; int tb = Integer . parseInt ( query [ 2 ] ) ; int fb = Integer . parseInt ( query [ 3 ] ) ;   if ( ta == tb ) System . out . println ( Math . abs ( fa - fb ) ) ; else { if ( fa < a ) System . out . println ( a - fa + Math . abs ( ta - tb ) + Math . abs ( a - fb ) ) ; else if ( fa > b ) System . out . println ( fa - b + Math . abs ( ta - tb ) + Math . abs ( b - fb ) ) ; else System . out . println ( Math . abs ( fa - fb ) + Math . abs ( ta - tb ) ) ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } ","n , h , a , b , k = map ( int , input ( ) . split ( ) ) for _ in range ( k ) : t1 , f1 , t2 , f2 = map ( int , input ( ) . split ( ) ) if t1 == t2 : ans = abs ( f1 - f2 ) else : if f1 < a : d1 = a elif f1 in range ( a , b + 1 ) : d1 = f1 else : d1 = b ans = abs ( d1 - f1 ) + abs ( t1 - t2 ) + abs ( d1 - f2 ) print ( ans ) NEW_LINE " V151,"import java . util . * ; import java . math . * ;   public class Main { public static long triangular ( long n ) { return ( n * ( n + 1 ) ) / 2L ; } public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int one = i * ( i + 1 ) ; if ( one > n ) { break ; } int remain = 2 * n - one ; int t = ( int ) Math . sqrt ( remain ) ; if ( ( t * ( t + 1 ) ) == remain ) { System . out . println ( "" YES "" ) ; return ; } } System . out . println ( "" NO "" ) ;   }   } ","def binary_search ( arr , low , high , x ) : if high >= low : mid = ( high + low ) // 2 if arr [ mid ] == x : return 1 elif arr [ mid ] > x : return binary_search ( arr , low , mid - 1 , x ) else : return binary_search ( arr , mid + 1 , high , x ) else : return 0   import mathn = int ( input ( ) ) n = n * ( 1 + 1 ) t = [ ] flag = 1 for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) : t . append ( i * ( i + 1 ) ) k = len ( t ) - 1 for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) : if ( binary_search ( t , 0 , k , n - i * ( i + 1 ) ) ) : print ( "" YES "" ) flag = 0 breakif ( flag ) : print ( "" NO "" ) NEW_LINE " V152,"import java . util . * ; public class Barralel { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { int n = in . nextInt ( ) ; int c = 0 ; while ( n >= 7 ) { n = n - 7 ; c ++ ; } while ( n >= 6 ) { n = n - 6 ; c ++ ; } while ( n >= 5 ) { n = n - 5 ; c ++ ; } while ( n >= 4 ) { n = n - 4 ; c ++ ; } while ( n >= 3 ) { n = n - 3 ; c ++ ; } while ( n >= 2 ) { n = n - 2 ; c ++ ; } while ( n >= 1 ) { n = n - 1 ; c ++ ; } System . out . println ( c ) ; } } } ","def string_list ( s , char ) : output_list = [ ] intermediator = "" "" for i in range ( len ( s ) ) : if s [ i ] != char : intermediator += s [ i ] if i == len ( s ) - 1 : output_list . append ( int ( intermediator ) ) else : if intermediator : output_list . append ( int ( intermediator ) ) intermediator = "" "" return output_list     def list_string ( l , char ) : output_str = "" "" for i in range ( len ( l ) - 1 ) : output_str += str ( l [ i ] ) + char output_str += str ( l [ len ( l ) - 1 ] ) return output_str     def merge_sort ( l ) : def merge ( l1 , l2 ) : i , j = 0 , 0 output_list = [ ] while i < len ( l1 ) and j < len ( l2 ) : if l1 [ i ] < l2 [ j ] : output_list . append ( l1 [ i ] ) i += 1 else : output_list . append ( l2 [ j ] ) j += 1 if i == len ( l1 ) : output_list += ( l2 [ j : ] ) else : output_list += ( l1 [ i : ] ) return output_list   def sorts ( l ) : if len ( l ) < 2 : return l else : mid = len ( l ) // 2 left = sorts ( l [ : mid ] ) right = sorts ( l [ mid : ] ) return merge ( left , right ) return sorts ( l )       def main_function ( ) : output_list = [ ] t = int ( input ( ) ) for i in range ( t ) : x = int ( input ( ) ) output_list . append ( x // 2 ) return list_string ( output_list , "" ▁ "" )       print ( main_function ( ) )   NEW_LINE " V153,"  import java . util . * ; import java . lang . * ; import java . io . * ;   public class Codechef { public static void main ( String [ ] args ) { ","n = int ( input ( ) ) NEW_LINE if n & ( n - 1 ) : NEW_LINE INDENT print ( "" NO "" ) else : NEW_LINE print ( "" YES "" ) NEW_LINE DEDENT " V154,"import java . util . * ; import java . io . * ;   public class _practise {   public static void main ( String args [ ] ) {   FastReader in = new FastReader ( ) ; PrintWriter so = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; long t = in . nextLong ( ) ; while ( t -- > 0 ) { int n = in . nextInt ( ) ; long a [ ] = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = in . nextLong ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] >= 0 ) { a [ i + 1 ] = a [ i + 1 ] + a [ i ] ; a [ i ] = 0 ; } ","t = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n = int ( input ( ) ) NEW_LINE a = [ int ( s ) for s in input ( ) . split ( "" ▁ "" ) ] NEW_LINE ans = 0 NEW_LINE for x in a : ans = max ( 0 , ans + x ) NEW_LINE print ( ans ) NEW_LINE " V155,"import java . util . * ; public class test { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long rook = sc . nextLong ( ) ; Set < Long > rows = new HashSet < Long > ( ) ; Set < Long > cols = new HashSet < Long > ( ) ; ","n , m = map ( int , input ( ) . split ( ) )     total = n * nlines = set ( ) len_lines = 0 cols = set ( ) len_cols = 0 res = [ ] for i in range ( m ) : x , y = map ( int , input ( ) . split ( ) )   aux = 0 if x not in lines : lines . add ( x ) aux += n - len_cols len_lines += 1   if y not in cols : cols . add ( y ) aux += n - len_lines len_cols += 1   total -= aux res . append ( str ( total ) )         print ( ' ▁ ' . join ( res ) )   NEW_LINE " V156,"import java . io . File ; import java . util . Arrays ; import java . util . Scanner ; import java . util . StringTokenizer ;   public class p013 { public static void main ( String args [ ] ) throws Exception { StringTokenizer stok = new StringTokenizer ( new Scanner ( System . in ) . useDelimiter ( "" \\ A "" ) . next ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; int n = Integer . parseInt ( stok . nextToken ( ) ) ; int k = Integer . parseInt ( stok . nextToken ( ) ) ; long x = Long . parseLong ( stok . nextToken ( ) ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Long . parseLong ( stok . nextToken ( ) ) ; } long [ ] xp = new long [ k + 1 ] ; xp [ 0 ] = 1 ; for ( int i = 1 ; i <= k ; i ++ ) xp [ i ] = x * xp [ i - 1 ] ; long [ ] pf = new long [ n + 2 ] , sf = new long [ n + 2 ] ; for ( int i = 1 ; i <= n ; i ++ ) pf [ i ] = a [ i - 1 ] | pf [ i - 1 ] ; for ( int i = n ; i >= 1 ; i -- ) sf [ i ] = a [ i - 1 ] | sf [ i + 1 ] ; long max = Integer . MIN_VALUE ; for ( int i = 1 ; i <= n ; i ++ ) max = Math . max ( max , pf [ i - 1 ] | sf [ i + 1 ] | ( a [ i - 1 ] * xp [ k ] ) ) ; System . out . println ( max ) ; } } ","n , k , x = list ( map ( int , input ( ) . split ( ) ) ) a = list ( map ( int , input ( ) . split ( ) ) ) c = x ** kpr = [ 0 ] su = [ 0 ] b = 0 for i in range ( n - 1 ) : b = a [ i ] | b pr . append ( b ) b = 0 for i in range ( n - 1 , 0 , - 1 ) : b = a [ i ] | b su . append ( b ) su = su [ : : - 1 ] d = [ ] for i in range ( n ) : d . append ( pr [ i ] | a [ i ] * c | su [ i ] ) print ( max ( d ) ) NEW_LINE " V157,"import java . util . Scanner ;   public class CuttingBanner {   public static void main ( String [ ] args ) { System . out . println ( helper ( ) ) ; } public static String helper ( ) { Scanner in = new Scanner ( System . in ) ; String s = in . next ( ) ; int length = s . length ( ) ; if ( length < 10 ) return "" NO "" ; String firstTen = s . substring ( 0 , 10 ) ; String lastTen = s . substring ( length - 10 , length ) ; ","import sysimport mathimport itertoolsimport functoolsimport collectionsimport operatorimport fileinputimport copy   ORDA = 97 NEW_LINE " V158,"import java . util . * ;   public class Solution { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; long arr [ ] = new long [ n ] ; long temp [ ] = new long [ n ] ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextLong ( ) ; sum += arr [ i ] ; temp [ i ] = arr [ i ] ; } if ( sum < k ) System . out . println ( "" - 1"" ) ; else { Arrays . sort ( arr ) ; long prev = 0 ; int i = 0 ; long itr = - 1 ; while ( i < n ) { long len = n - i ; if ( ( arr [ i ] - prev ) * len < k ) { k -= ( arr [ i ] - prev ) * len ; prev = arr [ i ] ; while ( i + 1 < n && arr [ i + 1 ] == arr [ i ] ) { i ++ ; } i ++ ; continue ; } long x = 0 ; if ( k % len == 0 ) x = k / len - 1L ; else x = k / len ; itr = prev + x + 1 ; k -= x * len ; break ; } StringBuffer str = new StringBuffer ( "" "" ) ; StringBuffer str2 = new StringBuffer ( "" "" ) ; if ( itr != - 1 ) { int j = 0 ; while ( j < n ) { if ( temp [ j ] >= itr ) { if ( k > 0 ) { if ( temp [ j ] != itr ) str . append ( ( j + 1 ) + "" ▁ "" ) ; k -- ; } else { str2 . append ( ( j + 1 ) + "" ▁ "" ) ; } } j ++ ; } str2 . append ( str ) ; System . out . println ( str2 ) ; } } } } ","from sys import stdin   n , k = [ int ( x ) for x in stdin . readline ( ) . split ( ) ]   a = [ int ( x ) for x in stdin . readline ( ) . split ( ) ]   if sum ( a ) < k : NEW_LINE INDENT print ( - 1 ) elif sum ( a ) == k : NEW_LINE passelse : diff = 0 NEW_LINE DEDENT kCopy = k NEW_LINE sortA = sorted ( a , reverse = True )   while sortA : nxt = sortA [ - 1 ] NEW_LINE nxt -= diff   if len ( sortA ) * nxt <= k : diff += nxt NEW_LINE k -= len ( sortA ) * nxt NEW_LINE sortA . pop ( ) else : break NEW_LINE p = k % len ( sortA ) NEW_LINE diff += k // len ( sortA ) NEW_LINE ind = 0   while p : if NEW_LINE a [ ind ] > diff : p -= 1 NEW_LINE ind += 1 NEW_LINE outL = [ ]   for x in range ( ind , len ( a ) ) : if NEW_LINE a [ x ] > diff : outL . append ( str ( x + 1 ) ) NEW_LINE for x in range ( ind ) : if NEW_LINE a [ x ] > diff + 1 : outL . append ( str ( x + 1 ) ) NEW_LINE if outL : print ( ' ▁ ' . join ( outL ) ) NEW_LINE " V159,"import java . lang . reflect . Array ; import java . text . DecimalFormat ; import java . util . * ; import java . io . * ;   public class Equal {    static class pair implements Comparable < pair > { int x ; int y ;   public pair ( int u , int v ) { this . x = u ; this . y = v ; }   @ Override public int compareTo ( pair o ) { if ( x == o . x ) { return y - o . y ; } return x - o . x ; } }   static double dis ( pair a , pair b ) { return Math . sqrt ( ( ( a . x - b . x ) * ( a . x - b . x ) ) + ( ( a . y - b . y ) * ( a . y - b . y ) ) ) ; }   static int c ; static int d ; static int e ;   static void extendedEuclid ( int a , int b ) { if ( b == 0 ) { c = 1 ; d = 0 ; e = a ; return ; } extendedEuclid ( b , a % b ) ; int x1 = d ; int y1 = c - ( a / b ) * d ; c = x1 ; d = y1 ; } static int [ ] rank ; static int [ ] p ; static int sets ; static int findSet ( int i ) { return ( p [ i ] == i ) ? i : ( p [ i ] = findSet ( p [ i ] ) ) ; } static boolean isSameSet ( int i , int j ) { return findSet ( i ) == findSet ( j ) ; } static void unionSet ( int i , int j ) { if ( ! isSameSet ( i , j ) ) { sets -- ; int x = findSet ( i ) ; int y = findSet ( j ) ; if ( rank [ x ] > rank [ y ] ) p [ y ] = x ; else { p [ x ] = y ; if ( rank [ x ] == rank [ y ] ) rank [ y ] ++ ; } } } static class SegmentTree { ","def solve ( str_ ) : res = "" "" for i in str_ : if i == ""7"" or i == ""4"" : res += i if len ( res ) > 0 : ans = int ( res ) else : ans = 0 return ans   a , b = map ( int , input ( ) . split ( ) ) while True : a += 1 a_str = str ( a ) res = "" "" if solve ( a_str ) == b : print ( a ) break NEW_LINE " V160,"import java . util . * ;   public class caisaandSugar { public static void main ( String args [ ] ) { Scanner input_scan = new Scanner ( System . in ) ; int n = input_scan . nextInt ( ) ; int s = input_scan . nextInt ( ) ; int x [ ] = new int [ n ] ; int y [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = input_scan . nextInt ( ) ; y [ i ] = input_scan . nextInt ( ) ; }   int min = 100 ; boolean check = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( min > y [ i ] && x [ i ] <= s ) { if ( x [ i ] == s ) { if ( y [ i ] == 0 ) { check = true ;   } } else if ( y [ i ] == 0 ) { check = true ; } else { min = y [ i ] ; check = true ; } } } if ( ! check ) System . out . println ( - 1 ) ; else if ( min == 100 ) System . out . println ( 0 ) ; else System . out . println ( 100 - min ) ; } } ","n , s = map ( int , input ( ) . split ( "" ▁ "" ) ) ans = - 1 for _ in range ( n ) : a , b = map ( int , input ( ) . split ( "" ▁ "" ) ) if a < s : if ( b != 0 ) : ans = max ( ans , 100 - b ) if a <= s and b == 0 : ans = max ( ans , 0 ) print ( ans ) NEW_LINE " V161,"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ;   public class TeamOlympiad { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; List < Integer > programmers = new ArrayList < > ( ) ; List < Integer > maths = new ArrayList < > ( ) ; List < Integer > sports = new ArrayList < > ( ) ;   for ( int i = 1 ; i <= n ; i ++ ) { int c = scanner . nextInt ( ) ; if ( c == 1 ) programmers . add ( i ) ; else if ( c == 2 ) maths . add ( i ) ; else sports . add ( i ) ; } int min = Math . min ( Math . min ( programmers . size ( ) , maths . size ( ) ) , sports . size ( ) ) ;   System . out . println ( min ) ; for ( int i = 0 ; i < min ; i ++ ) { System . out . printf ( "" % d ▁ % d ▁ % d \n "" , programmers . get ( i ) , maths . get ( i ) , sports . get ( i ) ) ; } } } ","n = int ( input ( ) ) l1 = [ int ( x ) for x in input ( ) . split ( ) ] c1 , c2 , c3 = l1 . count ( 1 ) , l1 . count ( 2 ) , l1 . count ( 3 ) pos_1 , pos_2 , pos_3 = [ ] , [ ] , [ ] for i in range ( len ( l1 ) ) : if l1 [ i ] == 1 : pos_1 . append ( i + 1 ) elif l1 [ i ] == 2 : pos_2 . append ( i + 1 ) elif l1 [ i ] == 3 : pos_3 . append ( i + 1 ) if c1 != 0 and c2 != 0 and c3 != 0 : teams = min ( c1 , c2 , c3 ) print ( teams ) for i in range ( teams ) : print ( pos_1 [ i ] , pos_2 [ i ] , pos_3 [ i ] ) else : print ( 0 ) NEW_LINE " V162,"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 ] ; ","import ioimport osimport mathinput = io . BytesIO ( os . read ( 0 , os . fstat ( 0 ) . st_size ) ) . readline NEW_LINE " V163,"import java . util . Scanner ;   public class NewMain1 {   public static void main ( String [ ] args ) { ","a , b , c = list ( map ( int , input ( ) . split ( ) ) )   size = a * c   wait = 0 while b * c < size - b * wait : wait += 1   print ( wait ) NEW_LINE " V164,"import java . awt . Point ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class B234 { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( "" input . txt "" ) ) ; int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; Point [ ] P = new Point [ N ] ; for ( int n = 1 ; n <= N ; n ++ ) { int light = in . nextInt ( ) ; P [ n - 1 ] = new Point ( light , n ) ; } Arrays . sort ( P , new Comparator < Point > ( ) { @ Override public int compare ( Point o1 , Point o2 ) { return o2 . x - o1 . x ; } } ) ; PrintWriter out = new PrintWriter ( new File ( "" output . txt "" ) ) ; out . println ( P [ K - 1 ] . x ) ; StringBuilder output = new StringBuilder ( ) ; for ( int k = 0 ; k < K ; k ++ ) { output . append ( P [ k ] . y ) . append ( ' ▁ ' ) ; } out . println ( output ) ; out . close ( ) ; } } ","F = open ( ' input . txt ' ) I = lambda : map ( int , F . readline ( ) . split ( ) ) n , k = I ( ) ; a = sorted ( zip ( I ( ) , range ( n ) ) ) [ : : - 1 ] print ( a [ k - 1 ] [ 0 ] , ' \n ' , * ( y + 1 for x , y in a [ : k ] ) , file = open ( ' output . txt ' , ' w ' ) ) NEW_LINE " V165,"import java . io . * ; import java . util . * ; import java . math . * ;   public class Main { public static void main ( String args [ ] ) throws Exception { FastScanner fs = new FastScanner ( ) ; ","from sys import stdout   def transpose ( m ) : NEW_LINE " V166,"import java . io . BufferedReader ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . * ;   import javafx . util . Pair ;   public class Main {   public static void main ( String args [ ] ) { FastScanner input = new FastScanner ( ) ; int tc = input . nextInt ( ) ; while ( tc -- > 0 ) { int n = input . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = input . nextInt ( ) ; } boolean r [ ] = new boolean [ n ] ; boolean l [ ] = new boolean [ n ] ; int max = 0 ; TreeSet < Integer > set = new TreeSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { max = Math . max ( max , a [ i ] ) ; set . add ( a [ i ] ) ; if ( set . size ( ) == max && max == i + 1 ) r [ i ] = true ; } max = 0 ; set = new TreeSet < > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { max = Math . max ( max , a [ i ] ) ; set . add ( a [ i ] ) ; if ( set . size ( ) == max && max == ( n - i ) ) l [ i ] = true ; } ","from collections import defaultdictdef check ( arr ) : arr . sort ( ) value = [ i + 1 for i in range ( len ( arr ) ) ] if ( arr == value ) : return True return False   for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) high = max ( l ) low = len ( l ) - high ans = [ ] if ( check ( l [ : low ] ) == True and check ( l [ low : ] ) == True ) : ans . append ( [ low , high ] ) if ( low != high and check ( l [ : high ] ) == True and check ( l [ high : ] ) == True ) : ans . append ( [ high , low ] ) print ( len ( ans ) ) for i in ans : print ( * i ) NEW_LINE " V167,"import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   ","n , pos , l , r = map ( int , input ( ) . split ( ) ) result = abs ( pos - l ) + r - l + 2 if ( l == 1 ) : if ( abs ( pos - r ) + 1 < result ) : result = abs ( pos - r ) + 1 if ( r == n ) : if ( abs ( pos - l ) + 1 < result ) : result = abs ( pos - l ) + 1 if ( l == 1 and r == n ) : result = 0 if ( abs ( pos - r ) + r - l + 2 < result ) : result = abs ( pos - r ) + r - l + 2 print ( result ) NEW_LINE " V168,"import java . util . * ;   public class watermelon { public static void main ( String args [ ] ) {   String word ; Scanner scanner = new Scanner ( System . in ) ; word = scanner . nextLine ( ) ;   for ( int i = 0 ; i < word . length ( ) ; i ++ ) { if ( i == 0 ) { char temp = word . toUpperCase ( ) . charAt ( 0 ) ; System . out . print ( temp ) ; } else { System . out . print ( word . charAt ( i ) ) ; } } } } ","dc = input ( ) t = dc . istitle ( ) if t : print ( dc ) else : s = list ( dc ) b = s . pop ( 0 ) b = b . upper ( ) s . insert ( 0 , b ) print ( ' ' . join ( s ) ) NEW_LINE " V169,"import java . util . Scanner ;   public class A924 { static int R ; static int C ;   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; R = in . nextInt ( ) ; C = in . nextInt ( ) ; boolean [ ] [ ] black = new boolean [ R ] [ C ] ; for ( int r = 0 ; r < R ; r ++ ) { String row = in . next ( ) ; for ( int c = 0 ; c < C ; c ++ ) { if ( row . charAt ( c ) == ' # ' ) { black [ r ] [ c ] = true ; } } } boolean ok = true ; main : for ( int r = 0 ; r < R ; r ++ ) { for ( int c = 0 ; c < C ; c ++ ) { if ( black [ r ] [ c ] ) { boolean [ ] rows = new boolean [ R ] ; boolean [ ] columns = new boolean [ C ] ; select ( r , c , black , rows , columns ) ; for ( int rr = 0 ; rr < R ; rr ++ ) { if ( rows [ rr ] ) { for ( int cc = 0 ; cc < C ; cc ++ ) { if ( columns [ cc ] && ! black [ rr ] [ cc ] ) { ok = false ; break main ; } } } } } } } System . out . println ( ok ? "" Yes "" : "" No "" ) ; }   static void select ( int rSel , int cSel , boolean [ ] [ ] black , boolean [ ] rows , boolean [ ] columns ) { if ( ! rows [ rSel ] ) { rows [ rSel ] = true ; for ( int c = 0 ; c < C ; c ++ ) { if ( black [ rSel ] [ c ] ) { select ( rSel , c , black , rows , columns ) ; } } } if ( ! columns [ cSel ] ) { columns [ cSel ] = true ; for ( int r = 0 ; r < R ; r ++ ) { if ( black [ r ] [ cSel ] ) { select ( r , cSel , black , rows , columns ) ; } } } }   } ","n , m = map ( int , input ( ) . split ( ) ) s = [ input ( ) for _ in range ( n ) ] l = [ ] for i in range ( n ) : se = set ( ) for j in range ( m ) : if s [ i ] [ j ] == ' # ' : se . add ( j ) for li in l : if len ( se & li ) != 0 and se != li : print ( ' No ' ) exit ( ) l . append ( se ) print ( ' Yes ' ) NEW_LINE " V170,"import java . util . Scanner ;   public class A1417 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int [ ] A = new int [ N ] ; int min = Integer . MAX_VALUE ; for ( int n = 0 ; n < N ; n ++ ) { int a = in . nextInt ( ) ; min = Math . min ( min , a ) ; A [ n ] = a ; } int answer = 0 ; for ( int a : A ) { answer += ( K - a ) / min ; } answer -= ( K - min ) / min ; System . out . println ( answer ) ; } }   } ","import sys , functools , collections , bisect , math , NEW_LINE INDENT heapqinput = sys . stdin . readline NEW_LINE DEDENT " V171,"import java . util . * ;   public class questionCF { static ArrayList < Integer > game ( ArrayList < Integer > list , int n ) { if ( n == 1 ) { list . add ( 1 ) ; return list ; } if ( n == 2 ) { list . add ( 2 ) ; return list ; } int count = 0 ; for ( int i = 1 ; true ; i = i * 2 ) { count ++ ; if ( i == n ) { list . add ( count ) ; return list ; } else if ( i > n ) { list . add ( count - 1 ) ; game ( list , n - ( i / 2 ) ) ; return list ; } } }   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > l = new ArrayList < > ( ) ; ArrayList < Integer > list = game ( l , n ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) System . out . print ( list . get ( i ) + "" ▁ "" ) ;   } } ","num = int ( input ( ) )   ans = [ ]   while num : ans . append ( 1 ) while len ( ans ) > 1 and ans [ - 1 ] == ans [ - 2 ] : x = ans . pop ( ) + 1 ans [ - 1 ] = x num -= 1 print ( * ans )   NEW_LINE " V172,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . Random ; import java . util . Arrays ; import java . util . StringTokenizer ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Collections ;   public class A { public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; StringBuffer ans = new StringBuffer ( ) ; int test = 1 ; while ( test -- > 0 ) { int n = sc . nextInt ( ) ; long even = 0 ; long odd = 0 ; long mod = ( long ) ( 1e9 + 7 ) ; long dp [ ] = new long [ n + 1 ] ; long sum = 0l ; for ( int i = n ; i >= 1 ; i -- ) { if ( i == n ) dp [ i ] = 1 ; else if ( i == n - 1 ) dp [ i ] = 2 ; else { dp [ i ] = 1 ; if ( i % 2 == 0 ) dp [ i ] = ( dp [ i ] + odd ) % mod ; else dp [ i ] = ( dp [ i ] + even ) % mod ; } if ( i % 2 == 0 ) even = ( even + dp [ i ] ) % mod ; else odd = ( odd + dp [ i ] ) % mod ; sum = ( sum + dp [ i ] ) % mod ; } ans . append ( sum + "" \n "" ) ; } System . out . print ( ans ) ; } static final Random random = new Random ( ) ; static void ruffleSort ( int [ ] a ) { int n = a . length ; ","n = int ( input ( ) ) if n != 1 : array = [ 1 for k in range ( n + 1 ) ] array [ 1 ] = 1 array [ 2 ] = 2 sumi = 3 for k in range ( 3 , n + 1 ) : array [ k ] = array [ k - 1 ] + array [ k - 2 ] % int ( 1e9 + 7 ) sumi += array [ k ] % int ( 1e9 + 7 ) print ( sumi % int ( 1e9 + 7 ) ) else : print ( 1 ) NEW_LINE " V173,"import java . util . Scanner ; import java . util . Arrays ; public class Ishu { static long gcd ( long a , long b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long t ; long n , ans = 1 ; t = scan . nextLong ( ) ; while ( t -- > 0 ) { n = scan . nextLong ( ) ; ans = 1 + ( ( 4 * n ) / gcd ( 4 * n , n + 1 ) ) ; System . out . println ( ans ) ; } } } ","from sys import stdin , stdoutfrom os import pathrd = lambda : stdin . readline ( ) . strip ( ) wr = stdout . writeif ( path . exists ( ' input . txt ' ) ) : stdin = open ( "" input . txt "" , "" r "" ) import time NEW_LINE " V174,"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Arrays ;    public class Solution {    public static void main ( String [ ] args ) throws Exception {   BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;   String input = br . readLine ( ) ; int n = Integer . parseInt ( input ) ; n *= 2 ; input = br . readLine ( ) ; int no = 0 ; int swaps = 0 ; int [ ] l = Arrays . stream ( input . split ( "" ▁ "" ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; for ( int i = 0 ; i < n ; ) { int match = l [ i ] ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( l [ j ] == match ) { no = j ; } } for ( int j = no ; j > i + 1 ; j -- ) { int temp = l [ j ] ; l [ j ] = l [ j - 1 ] ; l [ j - 1 ] = temp ; swaps ++ ; } i += 2 ; } System . out . println ( swaps ) ; }    }       ","import sysinput = sys . stdin . readline   '''   '''   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) swaps = 0 for i in range ( 0 , 2 * n , 2 ) : if a [ i ] == a [ i + 1 ] : continue c = a [ i ] j = i + 2 while c != a [ j ] : j += 1 MIN = i + 1 while j > MIN : a [ j ] , a [ j - 1 ] = a [ j - 1 ] , a [ j ] j -= 1 swaps += 1   print ( swaps ) NEW_LINE " V175,"import java . io . * ; import java . math . * ; import java . util . * ;   ","from sys import stdin , stdoutfrom os import pathrd = lambda : stdin . readline ( ) . strip ( ) wr = stdout . writeif ( path . exists ( ' input . txt ' ) ) : stdin = open ( "" input . txt "" , "" r "" ) import time , math NEW_LINE " V176,"import java . util . Scanner ;   public class Singleton_Pattern { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int input = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int z = 0 , n = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' z ' ) z ++ ; if ( s . charAt ( i ) == ' n ' ) n ++ ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ""1"" + "" ▁ "" ) ; }   for ( int i = 0 ; i < z ; i ++ ) { System . out . print ( ""0"" + "" ▁ "" ) ; }   } } ","a = [ * open ( 0 ) ] [ 1 ] . count ; print ( * [ 1 ] * a ( ' n ' ) + [ 0 ] * a ( ' r ' ) ) NEW_LINE " V177,"# include < cstdio > # include < cstring > # include < iostream > # include < algorithm > using namespace std ; const int maxn = 200010 ; typedef long long LL ; int n , k , a , b , q , c [ maxn ] [ 2 ] , s [ maxn ] ; int lowbit ( int x ) { return x & ( - x ) ; } void add ( int x , int y , int z ) { for ( int i = x ; i < maxn ; i += lowbit ( i ) ) c [ i ] [ z ] += y ; } int sum ( int x , int z ) { int ans = 0 ; for ( int i = x ; i ; i -= lowbit ( i ) ) ans += c [ i ] [ z ] ; return ans ; } int main ( ) { scanf ( "" % d % d % d % d % d "" , & n , & k , & a , & b , & q ) ; while ( q -- ) { int op ; scanf ( "" % d "" , & op ) ; if ( op == 1 ) { int x , y ; scanf ( "" % d % d "" , & x , & y ) ; int pre = s [ x ] ; s [ x ] += y ; add ( x , min ( b , s [ x ] ) - min ( b , pre ) , 0 ) ; add ( x , min ( a , s [ x ] ) - min ( a , pre ) , 1 ) ; } else { int x ; scanf ( "" % d "" , & x ) ; printf ( "" % d \n "" , sum ( x - 1 , 0 ) + sum ( n , 1 ) - sum ( x + k - 1 , 1 ) ) ; } } return 0 ; } ","import sysfrom math import *   def minp ( ) : return sys . stdin . readline ( ) . strip ( )   def mint ( ) : return int ( minp ( ) )   def mints ( ) : return map ( int , minp ( ) . split ( ) )   def add ( a , x , v ) : while x < len ( a ) : a [ x ] += v x |= x + 1 def get ( a , x ) : r = 0 while x >= 0 : r += a [ x ] x = ( x & ( x + 1 ) ) - 1 return r     n , k , a , b , q = mints ( ) h1 = [ 0 ] * nh2 = [ 0 ] * nz = [ 0 ] * nfor i in range ( q ) : t = tuple ( mints ( ) ) if t [ 0 ] == 1 : p = z [ t [ 1 ] - 1 ] pp = p + t [ 2 ] add ( h1 , t [ 1 ] - 1 , min ( a , pp ) - min ( a , p ) ) add ( h2 , t [ 1 ] - 1 , min ( b , pp ) - min ( b , p ) ) z [ t [ 1 ] - 1 ] = pp else : print ( get ( h2 , t [ 1 ] - 2 ) + get ( h1 , n - 1 ) - get ( h1 , t [ 1 ] + k - 2 ) ) NEW_LINE " V178,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import static java . lang . Math . * ; import static java . lang . System . out ; import java . util . * ; import java . io . PrintStream ; import java . io . PrintWriter ; public class A { static final int N = ( int ) ( 3e5 ) ; static final int mod = 1000000007 ; static final long temp = 998244353 ; static final long MOD = 1000000007 ; static final long M = ( long ) 1e9 + 7 ; static class Pair implements Comparable < Pair > { int first , second ; public Pair ( int aa , int bb ) { first = aa ; second = bb ; } public int compareTo ( Pair o ) { if ( this . second < o . second ) return - 1 ; if ( this . second > o . second ) return + 1 ; return this . first - o . first ; } } static class Tuple implements Comparable < Tuple > { long first , second , third ; public Tuple ( long first , long second , long third ) { this . first = first ; this . second = second ; this . third = third ; } public int compareTo ( Tuple o ) { return ( int ) ( o . third - this . third ) ; } } public static class DSU { int [ ] parent ; int [ ] rank ; ","for x in range ( int ( input ( ) ) ) : n = int ( input ( ) ) print ( n // 2 - 1 ) if n % 2 == 0 else print ( n // 2 ) NEW_LINE " V179,"import java . util . * ; public class FoxMinimalPath { private static boolean [ ] [ ] grid ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int l = ( int ) ( Math . log ( k ) / Math . log ( 2 ) ) ; int n = 2 + 2 * l ; for ( int i = 0 ; i <= l ; i ++ ) { if ( k / ( int ) Math . pow ( 2 , i ) % 2 == 1 ) n += l - i ; } grid = new boolean [ n ] [ n ] ; int lastA = 0 , lastB = 0 , ind = 2 ; for ( int i = 0 ; i < l ; i ++ ) { for ( int c = 0 ; c < 2 ; c ++ ) { connect ( ind , lastA ) ; connect ( ind , lastB ) ; ind ++ ; } lastA = ind - 2 ; lastB = ind - 1 ; } connect ( lastA , 1 ) ; connect ( lastB , 1 ) ; for ( int i = 0 ; i < l ; i ++ ) if ( k / ( int ) Math . pow ( 2 , i ) % 2 == 1 ) { connect ( ind , 2 * i ) ; if ( i > 0 ) connect ( ind , 2 * i + 1 ) ; for ( int j = i ; j < l - 1 ; j ++ ) connect ( ++ ind , ind - 1 ) ; connect ( ind ++ , 1 ) ; } System . out . println ( n ) ; for ( boolean [ ] arr : grid ) { for ( boolean b : arr ) System . out . print ( b ? "" Y "" : "" N "" ) ; System . out . println ( ) ; } } public static void connect ( int a , int b ) { grid [ a ] [ b ] = true ; grid [ b ] [ a ] = true ; } } ","N = int ( input ( ) ) b = bin ( N ) [ 2 : ] [ : : - 1 ] count = len ( b ) - 1   def print_matrix ( m ) : print ( len ( m ) ) for i in range ( len ( m ) ) : print ( "" "" . join ( m [ i ] ) )   m = [ [ ' N ' for i in range ( 2 * ( len ( b ) ) + count ) ] for j in range ( 2 * ( len ( b ) ) + count ) ] for i in range ( count - 1 ) : val = len ( m ) - count + i m [ val ] [ val + 1 ] = ' Y ' m [ val + 1 ] [ val ] = ' Y '   if count > 0 : m [ len ( m ) - 1 ] [ 1 ] = ' Y ' m [ 1 ] [ len ( m ) - 1 ] = ' Y '   NEW_LINE " V180,"import java . util . * ;   public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- != 0 ) { long m , s = 0 , d , x , y , a , b ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ;   m = Math . min ( x , y ) ; x = x - m ; y = y - m ; s = Math . min ( 2 * m * a , b * m ) ; s = s + x * a + y * a ; System . out . println ( s ) ; } } } ","for _ in range ( int ( input ( ) ) ) : x , y = [ int ( i ) for i in input ( ) . split ( ) ] a , b = [ int ( i ) for i in input ( ) . split ( ) ] print ( min ( ( max ( x , y ) - min ( x , y ) ) * a + min ( x , y ) * b , ( x + y ) * a ) ) NEW_LINE " V181,"import java . util . Scanner ;   public class CaterpillarClimbing {   public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int start = scan . nextInt ( ) , end = scan . nextInt ( ) , up = scan . nextInt ( ) , down = scan . nextInt ( ) , c = 0 ; start += up * 8 ; if ( down >= up && start < end ) { System . out . println ( "" - 1"" ) ; return ; } while ( start < end ) { start -= down * 12 ; start += up * 12 ; c ++ ; } System . out . println ( c ) ; }   } ","h1 , h2 = map ( int , input ( ) . split ( ) )   up , down = map ( int , input ( ) . split ( ) )   v = up - downif v <= 0 : if ( ( h2 - h1 ) <= 8 * up ) : print ( 0 ) else : print ( - 1 ) else : days = 0 h1 += 8 * up while h1 < h2 : h1 -= 12 * down h1 += 12 * up days += 1 print ( days ) NEW_LINE " V182,"import java . util . Scanner ;   public class NotWoolSequences { public static void main ( String [ ] args ) { Scanner l1 = new Scanner ( System . in ) ; long l2 = l1 . nextLong ( ) ; long l3 = l1 . nextLong ( ) ; Wool s2 = new Wool ( ) ; s2 . WoolSequences ( l2 , l3 ) ; } } class Wool { long M = 1000000009 ;   public void WoolSequences ( long l2 , long l3 ) { { long pot2 = 1 ; for ( int i = 1 ; i <= l3 ; i ++ ) { pot2 *= 2 ; pot2 %= M ; } long wyn = 1 ; for ( int i = 1 ; i <= l2 ; i ++ ) { wyn *= ( pot2 - i ) ; wyn %= M ; } System . out . println ( wyn ) ; } } } ","e = 10 ** 9 + 9 n , m = map ( int , input ( ) . split ( ) ) t = pow ( 2 , m , e ) r = 1 for i in range ( n ) : r = ( r * ( t - i - 1 ) ) % eprint ( r ) NEW_LINE " V183,"# include < algorithm > # include < iostream > using namespace std ; # define ll long long   ll gcd ( ll a , ll b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; }   ll t ; ll n ; ll a [ 1000000 ] ; ll k ;   int main ( ) { cin >> t ; while ( t -- ) { int bj = 0 ; cin >> n >> k ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [ i ] ; } ll dq = max ( a [ 1 ] , a [ 2 ] ) - min ( a [ 1 ] , a [ 2 ] ) ; ll sz = a [ 1 ] ; if ( ( k - sz ) % dq == 0 ) bj = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { ll s = ( a [ i ] - sz ) / dq ; ll js = min ( abs ( sz + s * dq - a [ i ] ) , min ( abs ( sz + ( s + 1 ) * dq - a [ i ] ) , abs ( sz + ( s - 1 ) * dq - a [ i ] ) ) ) ; dq = gcd ( js , dq ) ; if ( ( k - sz ) % dq == 0 ) { bj = 1 ; break ; } } if ( bj == 1 ) cout << "" YES "" << endl ; else cout << "" NO "" << endl ; } return 0 ; } ","import mathfor NEW_LINE _ in range ( int ( input ( ) ) ) : n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ * map ( int , input ( ) . split ( ) ) ] NEW_LINE x = a [ 1 ] - a [ 0 ] NEW_LINE for i in range ( 1 , n ) : x = math . gcd ( a [ i ] - a [ 0 ] , x ) NEW_LINE k -= a [ 0 ] NEW_LINE if k % x == 0 : NEW_LINE INDENT print ( "" YES "" ) else : NEW_LINE print ( "" NO "" ) NEW_LINE DEDENT " V184,"import java . util . Scanner ;   public class Loop {   static int N ; ","n , m = map ( int , input ( ) . split ( ' ▁ ' ) ) matiz = [ list ( input ( ) + ' . ' ) for i in range ( n ) ] matiz += [ list ( ' . ' * ( m + 1 ) ) ] def dfs ( ) : flag = False for i in range ( n ) : for j in range ( m ) : if matiz [ i ] [ j ] != ' . ' : d = 0 d += ( matiz [ i + 1 ] [ j ] == matiz [ i ] [ j ] ) d += ( matiz [ i - 1 ] [ j ] == matiz [ i ] [ j ] ) d += ( matiz [ i ] [ j + 1 ] == matiz [ i ] [ j ] ) d += ( matiz [ i ] [ j - 1 ] == matiz [ i ] [ j ] ) if d < 2 : matiz [ i ] [ j ] = ' . ' flag = True return flag for i in range ( 500 ) : dfs ( ) for i in range ( n ) : for j in range ( m ) : if matiz [ i ] [ j ] != ' . ' : print ( ' Yes ' ) exit ( ) print ( ' No ' ) NEW_LINE " V185,"import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Queue ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Vector ;   public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , t = in . nextInt ( ) ; int j = Integer . MAX_VALUE , ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int l = in . nextInt ( ) , r = in . nextInt ( ) ; if ( l >= t ) { if ( j > l ) { j = l ; ans = i ; } } else { int st = t - l ; int sum = st % r == 0 ? st / r : st / r + 1 ; sum = sum * r + l ; if ( j > sum ) { j = sum ; ans = i ; } } } System . out . println ( ans ) ; } } ","import math   n , t = list ( map ( int , input ( ) . split ( ) ) )   matrix = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ]   def calc_xi ( s , d ) : if t < s : return s u = math . ceil ( ( t - s ) / d ) return s + u * d   xis = [ calc_xi ( s , d ) for [ s , d ] in matrix ]   print ( xis . index ( min ( xis ) ) + 1 ) NEW_LINE " V186,"import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . io . * ; public class codeforces { static class Student { int x , y ; ","import osimport sysfrom io import BytesIO , IOBase   BUFSIZE = 8192     class FastIO ( IOBase ) : newlines = 0   def __init__ ( self , file ) : self . _fd = file . fileno ( ) self . buffer = BytesIO ( ) self . writable = "" x "" in file . mode or "" r "" not in file . mode self . write = self . buffer . write if self . writable else None   def read ( self ) : while True : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) if not b : break ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines = 0 return self . buffer . read ( )   def readline ( self ) : while self . newlines == 0 : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) self . newlines = b . count ( b "" \n "" ) + ( not b ) ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines -= 1 return self . buffer . readline ( )   def flush ( self ) : if self . writable : os . write ( self . _fd , self . buffer . getvalue ( ) ) self . buffer . truncate ( 0 ) , self . buffer . seek ( 0 )     class IOWrapper ( IOBase ) : def __init__ ( self , file ) : self . buffer = FastIO ( file ) self . flush = self . buffer . flush self . writable = self . buffer . writable self . write = lambda s : self . buffer . write ( s . encode ( "" ascii "" ) ) self . read = lambda : self . buffer . read ( ) . decode ( "" ascii "" ) self . readline = lambda : self . buffer . readline ( ) . decode ( "" ascii "" )     sys . stdin , sys . stdout = IOWrapper ( sys . stdin ) , IOWrapper ( sys . stdout ) input = lambda : sys . stdin . readline ( ) . rstrip ( "" \n "" ) NEW_LINE " V187,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ; import java . util . * ;   public class CF606A { public static void main ( String [ ] args ) { FastReader input = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ;   int a = input . nextInt ( ) ; int b = input . nextInt ( ) ; int c = input . nextInt ( ) ;   int d = input . nextInt ( ) ; int e = input . nextInt ( ) ; int f = input . nextInt ( ) ;   int got = 0 , need = 0 ;   if ( a - d >= 0 ) { got += ( a - d ) / 2 ; } else { need += Math . abs ( a - d ) ; }   if ( b - e >= 0 ) { got += ( b - e ) / 2 ; } else { need += Math . abs ( b - e ) ; }   if ( c - f >= 0 ) { got += ( c - f ) / 2 ; } else { need += Math . abs ( c - f ) ; }   if ( got >= need ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; }      ","    t = list ( map ( int , input ( ) . split ( ) ) )   g = list ( map ( int , input ( ) . split ( ) ) )     re = 0 for j in range ( 3 ) : if t [ j ] > g [ j ] : re += ( t [ j ] - g [ j ] ) // 2   u = 0     for k in range ( 3 ) : if t [ k ] < g [ k ] : if re >= g [ k ] - t [ k ] : re -= ( g [ k ] - t [ k ] ) else : print ( ' No ' ) u += 1 breakif u == 0 : print ( ' Yes ' ) NEW_LINE " V188,"import java . util . * ; import java . util . regex . * ;   public class Solution { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ n ] ; int res = 0 ; StringBuilder nums = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { boolean good = true ; for ( int j = 0 ; j < n ; j ++ ) { a [ i ] [ j ] = scan . nextInt ( ) ; if ( a [ i ] [ j ] == 1 || a [ i ] [ j ] == 3 ) { good = false ; } } if ( good ) { nums . append ( ( i + 1 ) + "" ▁ "" ) ; res ++ ; } } System . out . println ( res ) ; System . out . println ( nums ) ; } } ","def solve ( arr , n ) : good = [ ] for i in range ( n ) : is_good = True for j in arr [ i ] : if j not in [ - 1 , 0 , 2 ] : is_good = False break if is_good : good . append ( i + 1 ) print ( len ( good ) ) print ( * good )             def main ( ) : n = int ( input ( ) ) NEW_LINE " V189,"import java . util . * ;   public class CF { private static void sport ( int [ ] a ) { Arrays . sort ( a ) ; int n = a . length ; int ans = n ; int j = n / 2 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { while ( true ) { if ( j == n ) { System . out . println ( ans ) ; return ; } if ( a [ i ] * 2 <= a [ j ] ) { j ++ ; ans -- ; break ; } else { j ++ ; } } } System . out . println ( ans ) ; }   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sport ( a ) ; } } ","import math , sys , bisect , heapq , osfrom collections import defaultdict , Counter , dequefrom itertools import groupby , accumulatefrom functools import lru_cache NEW_LINE " V190,"import java . math . BigInteger ; import java . util . * ; import java . util . Comparator ; import java . lang . * ; import java . util . Arrays ;        public class geek { static class comp { int a , b ; public comp ( ) { } public comp ( int a , int b ) { this . a = a ; this . b = b ; }   }    public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; try { StringBuffer sb = new StringBuffer ( ) ;   int n = s . nextInt ( ) ; long b [ ] = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = s . nextLong ( ) ; } long x = 0 ; long a [ ] = new long [ n ] ; a [ 0 ] = b [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { x = Math . max ( a [ i - 1 ] , x ) ; a [ i ] = b [ i ] + x ;   } for ( int i = 0 ; i < n ; i ++ ) { sb . append ( a [ i ] + "" ▁ "" ) ; }   System . out . println ( sb ) ;           ","import sysdef get_list ( ) : return list ( map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) ) n = int ( sys . stdin . readline ( ) . strip ( ) ) ar = get_list ( ) prev = 0 for i in ar : print ( i + prev ) if ( i + prev ) > prev : prev += i NEW_LINE " V191,"import java . util . ArrayList ; import java . util . Scanner ;    public class PaperWork {   public static void main ( String [ ] args ) { ","n = int ( input ( ) ) lst = list ( map ( int , input ( ) . split ( ) ) ) k = 0 m = 0 folders = [ ] for i in range ( n ) : if lst [ i ] < 0 : k += 1 if k == 3 : folders . append ( i - m ) m = i k = 1 if m < n : folders . append ( n - m ) print ( len ( folders ) ) for i in range ( len ( folders ) ) : if i == len ( folders ) - 1 : print ( folders [ i ] , end = ' \n ' ) else : print ( folders [ i ] , end = ' ▁ ' ) NEW_LINE " V192,"import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { PrintWriter out ; FastReader sc ; long mod = ( long ) ( 1e9 + 7 ) ; int maxint = Integer . MAX_VALUE ; int minint = Integer . MIN_VALUE ; long maxlong = Long . MAX_VALUE ; long minlong = Long . MIN_VALUE ; public void sol ( ) { int a = ni ( ) ; if ( a % 2 == 0 ) { pl ( a + 4 + "" ▁ "" + 4 ) ; } else { pl ( a + 9 + "" ▁ "" + 9 ) ; } } public static void main ( String [ ] args ) { Main g = new Main ( ) ; g . out = new PrintWriter ( System . out ) ; g . sc = new FastReader ( ) ; int t = 1 ; ","n = int ( input ( ) ) print ( 9 * n , end = "" ▁ "" ) print ( 8 * n ) NEW_LINE " V193,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . io . PrintWriter ;        public class A {     public static void main ( String [ ] args ) throws IOException { FastReader sc = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int r1 = sc . nextInt ( ) ; int r2 = sc . nextInt ( ) ; int c1 = sc . nextInt ( ) ; int c2 = sc . nextInt ( ) ; int d1 = sc . nextInt ( ) ; int d2 = sc . nextInt ( ) ;   int x = ( d1 + c1 - r2 ) / 2 ; int a = r1 - x ; int b = c1 - x ; int c = r2 - c1 + x ;   if ( x < 10 && a < 10 && b < 10 && c < 10 && x > 0 && a > 0 && b > 0 && c > 0 && x != a && x != c && x != b && a != b && a != c && b != c && ( a + x ) == r1 && ( b + c ) == r2 && ( x + b ) == c1 && ( a + c ) == c2 && ( x + c ) == d1 && ( a + b ) == d2 ) { out . println ( x + "" ▁ "" + a ) ; out . println ( b + "" ▁ "" + c ) ; }   else out . println ( - 1 ) ;   out . close ( ) ; }       ","r1 , r2 = [ int ( y ) for y in input ( ) . split ( ) ] c1 , c2 = [ int ( y ) for y in input ( ) . split ( ) ] d1 , d2 = [ int ( y ) for y in input ( ) . split ( ) ] a = ( r1 + c1 - d2 ) // 2 b = r1 - ac = c1 - ad = d1 - aif a not in range ( 1 , 10 ) or b not in range ( 1 , 10 ) or c not in range ( 1 , 10 ) or d not in range ( 1 , 10 ) : print ( - 1 ) elif a == b or a == c or a == d or b == c or b == d or c == d : print ( - 1 ) elif a + b != r1 or c + d != r2 or a + c != c1 or b + d != c2 or a + d != d1 or b + c != d2 : print ( - 1 ) else : print ( a , b ) print ( c , d ) NEW_LINE " V194,"import java . util . * ; public class Main { public static Scanner sc = new Scanner ( System . in ) ; public static void setArray ( int arr [ ] [ ] ) { for ( int i = 0 ; i < arr . length ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { arr [ i ] [ j ] = sc . nextInt ( ) ; } } } public static void main ( String args [ ] ) { int n = sc . nextInt ( ) ; int arr [ ] [ ] = new int [ n ] [ 3 ] ; setArray ( arr ) ; int ocount = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { int icount = 0 ; for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ i ] [ j ] == 1 ) { icount ++ ; } } if ( icount >= 2 ) { ocount ++ ; } } System . out . println ( ocount ) ;      } } ","n = int ( input ( ) ) count = 0 for i in range ( 0 , n ) : x = input ( ) if x . count ( '1' ) >= 2 : count += 1 print ( count ) NEW_LINE " V195,"import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; import java . lang . Math ; public class Account { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; arr [ 0 ] = sc . nextInt ( ) ; int max = arr [ 0 ] , min = arr [ 0 ] , sum = 0 ; for ( int i = 1 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; sum += arr [ i ] ; if ( arr [ i ] > max ) max = arr [ i ] ; if ( arr [ i ] < min ) min = arr [ i ] ; } if ( n == 1 ) { ","n , c = map ( int , input ( ) . split ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) mn = min ( l ) mx = max ( l ) if mx - mn > c : print ( "" NO "" ) else : print ( "" YES "" ) for i in range ( n ) : h = l [ i ] for j in range ( mn ) : print ( 1 , end = "" ▁ "" ) for j in range ( h - mn ) : print ( j + 1 , end = "" ▁ "" ) print ( ) NEW_LINE " V196,"import java . io . * ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Map ; import java . util . StringTokenizer ;   public class A_MagicalBoxes_1600 { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; int N = sc . nextInt ( ) ; Map < Integer , Integer > boxes = new HashMap < > ( ) ; int largest = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int temp1 = Integer . parseInt ( sc . next ( ) ) ; int temp2 = Integer . parseInt ( sc . next ( ) ) ; if ( temp1 > largest ) largest = temp1 ; boxes . put ( temp1 , temp2 ) ; } int smallestBox = largest + 1 ; for ( int i : boxes . keySet ( ) ) { while ( boxes . get ( i ) > Math . pow ( 4 , smallestBox - i ) ) { smallestBox ++ ; } }   System . out . println ( smallestBox ) ;    out . close ( ) ; }   public static PrintWriter out ;   public static class MyScanner { BufferedReader br ; StringTokenizer st ;   public MyScanner ( ) { 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 ; }   } } ","from math import * n , o = int ( input ( ) ) , 0 for i in range ( n ) : r , t = map ( int , input ( ) . split ( ) ) r += ceil ( log ( t , 4 ) ) r += t == 1 o = max ( o , r ) print ( o ) NEW_LINE " V197,"import java . util . Scanner ;   public class lifewithoutzeros { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ;   int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = a + b ;   String a1 = Integer . toString ( a ) ; String b1 = Integer . toString ( b ) ; String c1 = Integer . toString ( c ) ;   a1 = a1 . replace ( ""0"" , "" "" ) ; a = Integer . parseInt ( a1 ) ; b1 = b1 . replace ( ""0"" , "" "" ) ; b = Integer . parseInt ( b1 ) ; c1 = c1 . replace ( ""0"" , "" "" ) ; int c2 = Integer . parseInt ( c1 ) ;     if ( c2 == a + b ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ;     } } ","a = input ( ) NEW_LINE b = input ( ) NEW_LINE c = int ( a ) + int ( b )   new_a = int ( str ( a ) . replace ( '0' , ' ' ) ) NEW_LINE new_b = int ( str ( b ) . replace ( '0' , ' ' ) ) NEW_LINE new_c = int ( str ( c ) . replace ( '0' , ' ' ) )   print ( "" YES "" if new_a + new_b == new_c else "" NO "" ) NEW_LINE " V198,"import java . util . * ;   public class Test {   public static void main ( String [ ] args ) {   Scanner scan = new Scanner ( System . in ) ;   String [ ] name = { "" Sheldon "" , "" Leonard "" , "" Penny "" , "" Rajesh "" , "" Howard "" } ;   int input = scan . nextInt ( ) - 1 ; int pow = 5 * ( int ) Math . pow ( 2 , log ( input / 5 ) ) ;   if ( input >= pow - 5 && input < 2 * pow - 5 ) res ( name , pow - 5 , input , pow / 5 ) ; else res ( name , 2 * pow - 5 , input , 2 * pow / 5 ) ;   } public static int log ( int n ) { if ( n <= 1 ) return 0 ;   return log ( n / 2 ) + 1 ; } public static void res ( String [ ] S , int low , int input , int pow ) {   int res = input - low ; System . out . println ( S [ res / pow ] ) ; } } ","import sys   n = int ( sys . stdin . readline ( ) )   iterations = 0 NEW_LINE prev_idx = 0 NEW_LINE idx = 1   step = 5 NEW_LINE width = 1   while idx <= n : prev_idx = idx NEW_LINE idx += step NEW_LINE step *= 2 NEW_LINE width *= 2   step //= 2 NEW_LINE width //= 2   assert n >= prev_idxif NEW_LINE n < prev_idx + width : print ( "" Sheldon "" ) elif n < prev_idx + 2 * width : print ( "" Leonard "" ) elif n < prev_idx + 3 * width : print ( "" Penny "" ) elif n < prev_idx + 4 * width : print ( "" Rajesh "" ) else : print ( "" Howard "" ) NEW_LINE " V199,"import java . util . Scanner ;   public class A1296 { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { int n = scanner . nextInt ( ) , odd = 0 , even = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int a = scanner . nextInt ( ) ; if ( a % 2 == 0 ) even ++ ; else odd ++ ; } System . out . println ( odd % 2 == 0 && even == 0 || odd == 0 ? "" NO "" : "" YES "" ) ; } } } ","from collections import Counter   def solve ( ) : n = int ( input ( ) ) sum , c_o , c_e = 0 , 0 , 0   array = list ( map ( int , input ( ) . split ( ) ) )   for i in array : if i % 2 : c_o += 1 else : c_e += 1 sum += i   if sum % 2 : return "" YES ""   else : if c_e == 0 and n % 2 == 0 : return "" NO "" if c_o == 0 : return "" NO "" return "" YES ""     for i in range ( int ( input ( ) ) ) : print ( solve ( ) ) NEW_LINE " V200,"import java . util . * ;   public class Test { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; long sum = 0 ; int min = 0 ;   for ( int i = 0 ; i < n ; i ++ ) { int x = input . nextInt ( ) ; if ( ( x & 1 ) == 1 && ( x < min || min == 0 ) ) { min = x ; } sum += x ; } System . out . println ( ( sum & 1 ) == 0 ? sum : sum - min ) ; } } ","def solve ( arr , n ) : arr = sorted ( arr ) res = sum ( arr ) if res % 2 == 0 : return res for i in range ( n ) : if arr [ i ] % 2 != 0 : res -= arr [ i ] if res % 2 == 0 : return res return 0           def main ( ) : NEW_LINE " V201,"import java . util . * ; import java . io . * ; import java . math . * ;   public class x828A { public static void main ( String hi [ ] ) throws Exception { BufferedReader infile = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( infile . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int A = Integer . parseInt ( st . nextToken ( ) ) ; int B = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] arr = new int [ N ] ; st = new StringTokenizer ( infile . readLine ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) arr [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; int res = 0 ; int half = 0 ; for ( int x : arr ) { if ( x == 2 ) { if ( B > 0 ) B -- ; else res += 2 ; } else { if ( A > 0 ) A -- ; else if ( B > 0 ) { B -- ; half ++ ; } else if ( half > 0 ) half -- ; else res ++ ; } } System . out . println ( res ) ; } } ","primLinea = input ( ) . split ( ) iteraciones = int ( primLinea [ 0 ] ) indiv = int ( primLinea [ 1 ] ) par = int ( primLinea [ 2 ] ) parParaIndiv = 0 personas = input ( ) . split ( ) negados = 0 for i in range ( 0 , iteraciones ) : costumer = int ( personas [ i ] ) if costumer == 1 : if indiv > 0 : indiv -= 1 elif par > 0 : par -= 1 parParaIndiv += 1 elif parParaIndiv > 0 : parParaIndiv -= 1 else : negados += 1 elif costumer == 2 : if par > 0 : par -= 1 else : negados += 2 print ( negados ) NEW_LINE " V202,"import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class Main { static InputReader in = new InputReader ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; static int oo = ( int ) 1e9 ; ","import sysimport mathfrom collections import defaultdict , dequeimport heapq   n , k = map ( int , sys . stdin . readline ( ) . split ( ) ) graph = defaultdict ( list ) st = 2 q = deque ( ) for i in range ( k ) : graph [ 1 ] . append ( st ) q . append ( st ) st += 1 leaves = [ 1 for _ in range ( k ) ] cnt = 0 while q and st <= n : a = q . popleft ( ) graph [ a ] . append ( st ) q . append ( st ) leaves [ ( cnt ) % k ] += 1 cnt += 1 st += 1 NEW_LINE " V203,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ;   public class Main { public static void main ( String [ ] args ) { InputStream is = System . in ; OutputStream os = System . out ; InputReader in = new InputReader ( is ) ; PrintWriter out = new PrintWriter ( os ) ; Solver solver = new Solver ( ) ; solver . solve ( in , out ) ; out . close ( ) ; }   static class Solver { void solve ( InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int cnt = 1 ; char [ ] s = in . next ( ) . toCharArray ( ) ; for ( int i = 1 ; i < s . length ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) cnt ++ ; } out . println ( Math . min ( cnt + 2 , n ) ) ; } } static class InputReader { BufferedReader br = null ; StringTokenizer st = null ; InputReader ( InputStream in ) { br = new BufferedReader ( new InputStreamReader ( in ) ) ; } String nextLine ( ) { String line = null ; try { line = br . readLine ( ) ; } catch ( IOException e ) { ","from sys import stdin , stdoutnmbr = lambda : int ( stdin . readline ( ) ) lst = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) for _ in range ( 1 ) : NEW_LINE " V204,"import java . util . * ; import java . io . * ;   public class P203B {   private static void solve ( ) { int n = nextInt ( ) ; int [ ] [ ] board = new int [ n ] [ n ] ;   int m = nextInt ( ) ;   for ( int i = 0 ; i < m ; i ++ ) { board [ nextInt ( ) - 1 ] [ nextInt ( ) - 1 ] = i + 1 ; }   int ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int black = 0 ; int max = 0 ; for ( int k = 0 ; k < 3 ; k ++ ) { for ( int l = 0 ; l < 3 ; l ++ ) { if ( i + k < n && j + l < n && board [ i + k ] [ j + l ] != 0 ) { black ++ ; max = Math . max ( board [ i + k ] [ j + l ] , max ) ; } } }   if ( black == 9 && ( ans == - 1 || ans > max ) ) { ans = max ; } } }   System . out . println ( ans ) ; }   private static void run ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ;   solve ( ) ;   out . close ( ) ; }   private static StringTokenizer st ; private static BufferedReader br ; private static PrintWriter out ;   private static String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { String s ; try { s = br . readLine ( ) ; } catch ( IOException e ) { return null ; } st = new StringTokenizer ( s ) ; } return st . nextToken ( ) ; }   private static int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   private static long nextLong ( ) { return Long . parseLong ( next ( ) ) ; }   public static void main ( String [ ] args ) { run ( ) ; } } ","R = lambda : map ( int , input ( ) . split ( ) ) n , m = R ( ) if n < 3 or m < 9 : print ( - 1 ) exit ( ) a = [ [ 0 ] * ( n - 2 ) for i in range ( n - 2 ) ] for i in range ( 1 , m + 1 ) : x , y = R ( ) x -= 1 y -= 1 for x0 in range ( x - 2 , x + 1 ) : for y0 in range ( y - 2 , y + 1 ) : if x0 < 0 or y0 < 0 or x0 >= n - 2 or y0 >= n - 2 : continue a [ x0 ] [ y0 ] += 1 if a [ x0 ] [ y0 ] == 9 : print ( i ) exit ( ) print ( - 1 ) NEW_LINE " V205,"import java . io . * ; import java . util . * ;   public class B { static ArrayList < Long > power = new ArrayList < > ( ) ; static ArrayList < Long > divisors = new ArrayList < > ( ) ; public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; dp ( ) ; long n = in . nextLong ( ) ; divisor ( n ) ; ","n = int ( input ( ) ) for i in range ( 2 , 10 ** 6 ) : while n % ( i * i ) == 0 : n //= iprint ( n ) NEW_LINE " V206,"import java . util . Scanner ;   public class JavaApplication1 {   public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; char letter ; letter = input . next ( ) . charAt ( 0 ) ; int shift = 0 ; if ( letter == ' R ' ) shift = - 1 ; else shift = 1 ; String keybord = "" qwertyuiopasdfghjkl ; zxcvbnm , . / "" ; String massage = "" "" ; String str = input . next ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int index = keybord . indexOf ( str . charAt ( i ) ) ; massage += keybord . charAt ( index + shift ) ; } System . out . println ( massage ) ; input . close ( ) ; } } ","s1 = ' qwertyuiop ' s2 = ' asdfghjkl ; ' s3 = ' zxcvbnm , . / ' shift = input ( ) s = input ( ) news = ' ' if ( shift == ' R ' ) :   for i in s : if i in s1 : u = s1 . index ( i ) news += s1 [ u - 1 ] elif i in s2 : u = s2 . index ( i ) news += s2 [ u - 1 ] elif i in s3 : u = s3 . index ( i ) news += s3 [ u - 1 ] print ( news ) else : for i in s : if i in s1 : u = s1 . index ( i ) news += s1 [ u + 1 ] elif i in s2 : u = s2 . index ( i ) news += s2 [ u + 1 ] elif i in s3 : u = s3 . index ( i ) news += s3 [ u + 1 ] print ( news )       NEW_LINE " V207,"import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . nio . file . Paths ; import java . util . Arrays ; import java . util . InputMismatchException ; import java . util . TreeSet ;   public class Main {   public Main ( ) throws FileNotFoundException { ","import sys , os , iodef rs ( ) : return sys . stdin . readline ( ) . rstrip ( ) def ri ( ) : return int ( sys . stdin . readline ( ) ) def ria ( ) : return list ( map ( int , sys . stdin . readline ( ) . split ( ) ) ) def ws ( s ) : sys . stdout . write ( s + ' \n ' ) def wi ( n ) : sys . stdout . write ( str ( n ) + ' \n ' ) def wia ( a ) : sys . stdout . write ( ' ▁ ' . join ( [ str ( x ) for x in a ] ) + ' \n ' ) import math , datetime , functools , itertools , operator , bisect , fractions , statisticsfrom collections import deque , defaultdict , OrderedDict , Counterfrom fractions import Fractionfrom decimal import Decimalfrom sys import stdoutfrom heapq import heappush , heappop , heapify , _heapify_max , _heappop_max , nsmallest , nlargest NEW_LINE " V208,"import java . util . * ; public class Contest8 { static Scanner scn = new Scanner ( System . in ) ; ","def STR ( ) : return list ( input ( ) ) def INT ( ) : return int ( input ( ) ) def MAP ( ) : return map ( int , input ( ) . split ( ) ) def MAP2 ( ) : return map ( float , input ( ) . split ( ) ) def LIST ( ) : return list ( map ( int , input ( ) . split ( ) ) ) def STRING ( ) : return input ( ) import stringimport sysfrom heapq import heappop , heappushfrom bisect import * from collections import deque , Counter , defaultdictfrom math import * from itertools import permutations , accumulatedx = [ - 1 , 1 , 0 , 0 ] dy = [ 0 , 0 , 1 , - 1 ] NEW_LINE " V209,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import static java . lang . Math . ceil ;    public class CF672ASummerCamp {   static BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static PrintWriter out = new PrintWriter ( System . out ) ;   public static void main ( String [ ] args ) throws IOException { int n = Integer . parseInt ( in . readLine ( ) ) ; String s = "" "" ; for ( int i = 1 ; i <= n ; i ++ ) { s += i ; } out . print ( s . charAt ( n - 1 ) ) ; out . close ( ) ; } } ","n = int ( input ( ) ) s = "" "" for i in range ( 1 , 1001 ) : s = s + str ( i ) print ( s [ n - 1 ] ) NEW_LINE " V210,"import java . util . Scanner ;   public class _0725ReverseaSubstring {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) < s . charAt ( i - 1 ) ) { System . out . println ( "" YES "" ) ; System . out . println ( ( i ) + "" ▁ "" + ( i + 1 ) ) ; return ; } } System . out . println ( "" NO "" ) ; }   } ","n = int ( input ( ) ) s = list ( input ( ) )     if s == sorted ( s ) : print ( "" NO "" ) else : print ( "" YES "" ) for i in range ( 0 , n - 1 ) : if s [ i ] > s [ i + 1 ] : print ( i + 1 , i + 2 ) break     NEW_LINE " V211,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import static java . lang . Math . * ; import static java . lang . System . out ; import java . util . * ; import java . io . PrintStream ; import java . io . PrintWriter ; public class A { static final int mod = 1000000007 ; static final long temp = 998244353 ; static final long MOD = 1000000007 ; static final long M = ( long ) 1e9 + 7 ; static class Pair implements Comparable < Pair > { int first , second ; public Pair ( int aa , int bb ) { first = aa ; second = bb ; } public int compareTo ( Pair o ) { if ( this . second < o . second ) return - 1 ; if ( this . second > o . second ) return + 1 ; return this . first - o . first ; } } static class Tuple implements Comparable < Tuple > { long first , second , third ; public Tuple ( long first , long second , long third ) { this . first = first ; this . second = second ; this . third = third ; } public int compareTo ( Tuple o ) { return ( int ) ( o . third - this . third ) ; } } public static class DSU { int [ ] parent ; int [ ] rank ; ","t = int ( input ( ) ) for _ in range ( t ) : s = input ( ) s = list ( s ) for i in range ( len ( s ) - 1 ) : if s [ i ] == s [ i + 1 ] : s [ i ] = "" ▁ "" s [ i + 1 ] = "" ▁ "" print ( "" "" . join ( sorted ( set ( s ) ) ) ) NEW_LINE " V212,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . io . StreamTokenizer ;   public class Main { public static int a , b , c ; public static StringBuilder ans = new StringBuilder ( ) ; public static String mod ;   public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StreamTokenizer st = new StreamTokenizer ( in ) ; PrintWriter pr = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; st . nextToken ( ) ; a = ( int ) st . nval ; st . nextToken ( ) ; b = ( int ) st . nval ; st . nextToken ( ) ; c = ( int ) st . nval ; if ( a >= b ) { mod = ""01"" ; } else { mod = ""10"" ; } for ( int i = 0 ; i < ( c + 1 ) / 2 ; i ++ ) { ans . append ( mod ) ; a -- ; b -- ; } if ( ( c & 1 ) == 0 ) { ans . append ( mod . charAt ( 0 ) ) ; if ( mod . charAt ( 0 ) == '0' ) { a -- ; } else { b -- ; } } if ( a != 0 ) { int temp = ans . indexOf ( ""0"" ) ; while ( a -- > 0 ) { ans . insert ( temp , '0' ) ; } } if ( b != 0 ) { int temp = ans . indexOf ( ""1"" ) ; while ( b -- > 0 ) { ans . insert ( temp , '1' ) ; } } pr . println ( ans ) ; pr . flush ( ) ; } } ","v = [ int ( i ) for i in input ( ) . split ( ) ]   a = v [ 0 ] - 1 b = v [ 1 ] - 1 x = v [ 2 ]   ans = [ '0' , '1' ] dif = 1   while a > 0 and b > 0 and dif < x : NEW_LINE " V213,"import java . util . Scanner ;    public class TheatreSquare_problem {   public static void main ( String [ ] args ) { ","import mathn , m , a = list ( map ( int , input ( ) . split ( ) ) ) print ( ( math . ceil ( n / a ) ) * ( math . ceil ( m / a ) ) ) NEW_LINE " V214,"import java . util . * ;   public class CF102 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] ar = new int [ n ] ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { ar [ i ] = sc . nextInt ( ) ; if ( k % ar [ i ] == 0 ) { min = Math . min ( min , k / ar [ i ] ) ; } } System . out . println ( min ) ; ","a , b = map ( int , input ( ) . split ( ) ) arr = sorted ( map ( int , input ( ) . split ( ) ) ) ans = float ( "" inf "" )   for n in arr : if b % n == 0 : if b // n < ans : ans = b // n     print ( ans ) NEW_LINE " V215,"import java . util . * ; import java . lang . * ; import java . io . * ;   public class modularExponentiation { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; public static void main ( String [ ] args ) throws java . lang . Exception { solve ( ) ; }   public static void solve ( ) throws IOException { int n = Integer . parseInt ( br . readLine ( ) ) ; int m = Integer . parseInt ( br . readLine ( ) ) ;   if ( n >= 33 ) { System . out . println ( m ) ; } else { System . out . println ( m % ( int ) Math . pow ( 2 , n ) ) ; }   } } ","n = int ( input ( ) ) m = int ( input ( ) ) if n >= 27 : print ( m ) else : print ( m % 2 ** n ) NEW_LINE " V216,"import java . io . * ; import java . math . * ; import java . security . * ; import java . text . * ; import java . time . LocalDate ; import java . time . LocalDateTime ; import java . util . * ; import java . util . concurrent . * ; import java . util . regex . * ;   public class Solution {   static class Reader { static BufferedReader reader ; static StringTokenizer tokenizer ;   static void init ( InputStream input ) { reader = new BufferedReader ( new InputStreamReader ( input ) ) ; tokenizer = new StringTokenizer ( "" "" ) ; }   static String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; }   static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; }   static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } } public static void main ( String [ ] args ) throws IOException { ","s = input ( ) ans = 0 for i in range ( len ( s ) ) : if i == 0 : ans += ( min ( abs ( ord ( s [ i ] ) - ord ( ' a ' ) ) , 26 - abs ( ord ( s [ i ] ) - ord ( ' a ' ) ) ) ) else : ans += ( min ( abs ( ord ( s [ i ] ) - ord ( s [ i - 1 ] ) ) , 26 - abs ( ord ( s [ i ] ) - ord ( s [ i - 1 ] ) ) ) ) print ( ans ) NEW_LINE " V217,"import java . util . Scanner ;   public class gigatower { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int i = 0 ; for ( i = a + 1 ; ; i ++ ) { ","n = int ( input ( ) ) + 1 c = 1 while '8' not in str ( n ) : n += 1 c += 1   print ( c ) NEW_LINE " V218,"import java . util . * ;   public class NewClass { static ArrayList < ArrayList < Integer > > graph = new ArrayList < ArrayList < Integer > > ( ) ; static ArrayList < Boolean > visited = new ArrayList < Boolean > ( ) ; static int count = 0 ; static boolean dfs ( int cn , int pn ) { if ( visited . get ( cn ) ) return true ; visited . set ( cn , Boolean . TRUE ) ; for ( int i : graph . get ( cn ) ) { if ( i != pn ) { count ++ ; if ( dfs ( i , cn ) ) return true ; } } return false ; } public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) , team = n ; for ( int i = 0 ; i < n ; i ++ ) { graph . add ( new ArrayList < Integer > ( ) ) ; visited . add ( Boolean . FALSE ) ; } for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) - 1 , b = sc . nextInt ( ) - 1 ; graph . get ( a ) . add ( b ) ; graph . get ( b ) . add ( a ) ; } for ( int i = 0 ; i < n ; i ++ ) { count = 0 ; boolean b = dfs ( i , - 1 ) ; if ( b && count % 2 != 0 ) { team -- ; } } if ( team % 2 != 0 ) team -- ; System . out . println ( n - team ) ; } } ","import pdb   def correct_colouring ( x0 , edges , visited , colouring ) : s = [ x0 ] visited [ x0 ] = True colouring [ x0 ] = 1 while s : x = s . pop ( ) for neigh in edges [ x ] : if not visited [ neigh ] : visited [ neigh ] = True colouring [ neigh ] = - colouring [ x ] s . append ( neigh ) elif colouring [ neigh ] == colouring [ x ] : return False return True   def solve ( ) : n , m = map ( int , input ( ) . split ( ) ) edges = [ [ ] for _ in range ( n + 1 ) ] for _ in range ( m ) : i , j = map ( int , input ( ) . split ( ) ) edges [ i ] . append ( j ) edges [ j ] . append ( i ) visited = [ False for _ in range ( n + 1 ) ] colouring = [ 0 for _ in range ( n + 1 ) ] removed = 0 for x0 in range ( 1 , n + 1 ) : if not visited [ x0 ] : correct = correct_colouring ( x0 , edges , visited , colouring ) if not correct : removed += 1 if ( n - removed ) % 2 : removed += 1 print ( removed )   if __name__ == ' _ _ main _ _ ' : solve ( ) NEW_LINE " V219,"import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) { Scanner s = new Scanner ( System . in ) ; int t = s . nextInt ( ) ; while ( t -- != 0 ) { String str = s . next ( ) ; int one = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == '1' ) { one ++ ; } } int min = Math . min ( one , str . length ( ) - one ) ; String ans = "" DA "" ; if ( min % 2 == 0 ) { ans = "" NET "" ; } System . out . println ( ans ) ; } } } ","for i in range ( int ( input ( ) ) ) : s = input ( ) if min ( s . count ( '1' ) , s . count ( '0' ) ) % 2 != 0 : print ( ' DA ' ) else : print ( ' NET ' )   NEW_LINE " V220,"import java . util . Scanner ;   public class B { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; while ( n -- > 0 ) { int ind = in . nextInt ( ) , z = 0 ; for ( int i = 0 ; i < ind ; i ++ ) { int bh = in . nextInt ( ) ; if ( bh == 0 ) { z ++ ; } } if ( z >= ( ind / 2 ) ) { println ( ind / 2 ) ; for ( int i = 1 ; i <= ind / 2 ; i ++ ) { print ( '0' + "" ▁ "" ) ; } } else { if ( ( ind / 2 ) % 2 == 0 ) { println ( ind / 2 ) ; for ( int i = 0 ; i < ( ind / 2 ) ; i ++ ) { print ( '1' + "" ▁ "" ) ; } } else { println ( ind / 2 + 1 ) ; for ( int i = 0 ; i < ( ind / 2 ) + 1 ; i ++ ) { print ( '1' + "" ▁ "" ) ; } } } println ( ) ; } } static void print ( Object o ) { System . out . print ( o ) ; } static void println ( Object o ) { print ( o ) ; println ( ) ; } static void println ( ) { print ( ' \n ' ) ; } } ","t = int ( input ( ) ) NEW_LINE for i in range ( t ) : n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE count0 = 0 NEW_LINE count1 = 0 NEW_LINE for i in range ( n ) : if NEW_LINE a [ i ] == 1 : count1 += 1 else : count0 += 1 NEW_LINE if count1 <= n // 2 : res = [ 0 ] * ( n - count1 ) NEW_LINE print ( len ( res ) ) NEW_LINE print ( * res ) else : if count1 % 2 != 0 : NEW_LINE INDENT res = [ 1 ] * ( n - count0 - 1 ) else : NEW_LINE res = [ 1 ] * ( n - count0 ) NEW_LINE DEDENT print ( len ( res ) ) NEW_LINE print ( * res ) NEW_LINE " V221,"import java . util . Scanner ; public class Ishu { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int i ; boolean flag = false ; long x , n , y , temp , sum = 0 ; n = scan . nextLong ( ) ; x = scan . nextLong ( ) ; y = scan . nextLong ( ) ; temp = y - ( n - 1 ) ; if ( temp > 0 ) { sum = n - 1 ; sum += temp * temp ; if ( sum >= x ) flag = true ; } if ( flag ) { for ( i = 1 ; i <= n - 1 ; ++ i ) System . out . println ( 1 ) ; System . out . println ( temp ) ; } else System . out . println ( - 1 ) ; } } ","n , x , y = map ( int , input ( ) . split ( ) )   print ( - 1 if n > y or ( y - n + 1 ) ** 2 + ( n - 1 ) < x else '1 \n ' * ( n - 1 ) + str ( y - n + 1 ) ) NEW_LINE " V222,"import java . util . Scanner ;   public class Stairs { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ;   int n = scan . nextInt ( ) ; int [ ] number = new int [ 5000 ] ; StringBuilder sb = new StringBuilder ( ) ;   for ( int i = 0 ; i < n ; i ++ ) { number [ scan . nextInt ( ) - 1 ] ++ ; }   int max = 0 ; int count = 0 ; for ( int i = 0 ; i < 5000 ; i ++ ) { if ( number [ i ] > 0 ) { sb . append ( i + 1 + "" ▁ "" ) ; number [ i ] -- ; count ++ ; max = i ; } }   for ( int i = max - 1 ; i >= 0 ; i -- ) { if ( number [ i ] > 0 ) { sb . append ( i + 1 + "" ▁ "" ) ; count ++ ; } }   System . out . println ( count + "" \n "" + sb ) ; } } ","n = int ( input ( ) ) karts = list ( map ( int , input ( ) . split ( ) ) ) output = [ ] output2 = [ ] karts . sort ( )   repeat = 0 for i in range ( n - 1 , 0 , - 1 ) : if karts [ i ] == karts [ i - 1 ] : repeat += 1 if repeat == 1 : output2 . append ( karts [ i ] ) else : repeat = 0 output . append ( karts [ i ] ) output . append ( karts [ 0 ] ) if len ( output2 ) > 0 and output [ 0 ] == output2 [ 0 ] : output2 . pop ( 0 )   print ( len ( output2 ) + len ( output ) ) for i in range ( len ( output2 ) - 1 , - 1 , - 1 ) : print ( output2 [ i ] , end = "" ▁ "" ) print ( * output ) NEW_LINE " V223,"import java . io . * ; import java . util . * ;   public class D implements Runnable { public static void main ( String [ ] args ) { new Thread ( null , new D ( ) , "" _ cf "" , 1 << 28 ) . start ( ) ; }   int [ ] [ ] pascals ; int MOD = ( int ) 1e9 + 7 ; int n ; long m ; int [ ] [ ] dp ; long [ ] [ ] pc ; public void run ( ) { FastScanner fs = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; System . err . println ( "" Go ! "" ) ;   pascals = new int [ 101 ] [ ] ; for ( int i = 0 ; i < pascals . length ; i ++ ) { pascals [ i ] = new int [ i + 1 ] ; pascals [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j < pascals [ i ] . length ; j ++ ) { pascals [ i ] [ j ] += pascals [ i - 1 ] [ j - 1 ] ; pascals [ i ] [ j ] %= MOD ; if ( j < pascals [ i - 1 ] . length ) pascals [ i ] [ j ] += pascals [ i - 1 ] [ j ] ; pascals [ i ] [ j ] %= MOD ; } } n = fs . nextInt ( ) ; m = fs . nextLong ( ) ; pc = new long [ 101 ] [ 101 ] ;   for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { long ways = pascals [ n ] [ j ] ; long appear = 1 ; long use1 = ( m - n ) / n , use2 = ( m - n ) % n ; appear += use1 ; if ( i < use2 ) appear ++ ; ","n , m , k = map ( int , input ( ) . split ( ) ) M = int ( 1e9 + 7 ) N = n * niv = [ 0 ] * ( N + 1 ) iv [ 1 ] = 1 for i in range ( 2 , N + 1 ) : iv [ i ] = M - M // i * iv [ M % i ] % Mf1 = [ 1 ] * ( N + 1 ) for i in range ( 1 , N + 1 ) : f1 [ i ] = f1 [ i - 1 ] * i % Mf2 = [ 1 ] * ( N + 1 ) for i in range ( 1 , N + 1 ) : f2 [ i ] = f2 [ i - 1 ] * iv [ i ] % Mleft = m % n NEW_LINE " V224,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ;   public class B_Codeforces_Subsequences {   static String s = "" codeforces "" ; static long n ; static BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) throws IOException { n = Long . parseLong ( in . readLine ( ) ) ; if ( n == 1 ) { System . out . println ( "" codeforces "" ) ; } else { long a [ ] = new long [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { a [ i ] = 1 ; } char [ ] ch = s . toCharArray ( ) ; long k = 1 , x = 0 ; while ( n > k ) { long ok = a [ ( int ) ( x % 10 ) ] ; k = k / ok ; a [ ( int ) ( x % 10 ) ] ++ ; ok ++ ; k = k * ok ; x ++ ; } for ( int i = 0 ; i < 10 ; i ++ ) { for ( long j = 0 ; j < a [ i ] ; j ++ ) { System . out . print ( ch [ i ] ) ; } } System . out . println ( ) ; } } } ","import sys , os . pathif __name__ == ' _ _ main _ _ ' : if ( os . path . exists ( ' input . txt ' ) ) : sys . stdin = open ( "" input . txt "" , "" r "" ) sys . stdout = open ( "" output . txt "" , "" w "" ) k = int ( input ( ) ) r = k ** .1 st = "" codeforces "" ans = "" "" r = int ( r ) ind = 0 while ( ( r + 1 ) ** ( ind ) ) * ( r ** ( 10 - ind ) ) < k : ind += 1 for i in range ( 10 ) : for j in range ( r ) : ans += st [ i ] if i < ind : ans += st [ i ] print ( ans ) NEW_LINE " V225,"import java . util . * ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) {   int t = 1 ; while ( t -- > 0 ) { solve ( ) ; } } public static void solve ( ) { String str = s . next ( ) ; ArrayList < Integer > list1 = new ArrayList < > ( ) ; ArrayList < Integer > list2 = new ArrayList < > ( ) ; ArrayList < Integer > list3 = new ArrayList < > ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch == ' ( ' ) list1 . add ( i ) ; } for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) { char ch = str . charAt ( i ) ; if ( ch == ' ) ' ) list2 . add ( i ) ; } int flag = 5 ; for ( int i = 0 ; i < Math . min ( list1 . size ( ) , list2 . size ( ) ) ; i ++ ) { if ( list1 . get ( i ) < list2 . get ( i ) ) { list3 . add ( list2 . get ( i ) ) ; list3 . add ( list1 . get ( i ) ) ; flag = 4 ; } else break ; } if ( list3 . size ( ) == 0 ) { System . out . println ( ""0"" ) ; return ; } System . out . println ( ""1"" ) ; System . out . println ( list3 . size ( ) ) ; Collections . sort ( list3 ) ; for ( int i = 0 ; i < list3 . size ( ) ; i ++ ) { System . out . print ( ( list3 . get ( i ) + 1 ) + "" ▁ "" ) ; } } } ","import sysfrom os import pathif ( path . exists ( ' input . txt ' ) and path . exists ( ' output . txt ' ) ) : sys . stdout = open ( ' output . txt ' , ' w ' ) sys . stdin = open ( ' input . txt ' , ' r ' )   def main ( ) : s = input ( ) n = len ( s ) l , r = 0 , n - 1 left , right = [ ] , [ ] while l < r : while l < r and s [ l ] == ' ) ' : l += 1 while l < r and s [ r ] == ' ( ' : r -= 1 if l < r and s [ l ] == ' ( ' and s [ r ] == ' ) ' : left . append ( l + 1 ) right . append ( r + 1 ) l += 1 r -= 1   if not left : print ( 0 ) else : print ( f "" 1 \n { 2 ▁ * ▁ len ( left ) } "" ) for l in left : print ( l , end = ' ▁ ' ) for r in reversed ( right ) : print ( r , end = ' ▁ ' )     main ( ) NEW_LINE " V226,"import java . util . * ; import java . util . jar . JarOutputStream ;   public class Practise {   public static int [ ] [ ] dp ;   public static void main ( String [ ] args ) { ","s = input ( ) c = len ( s ) for i in range ( len ( s ) - 1 , 0 , - 1 ) : k = s [ 0 : i + 1 ] if ( k != k [ : : - 1 ] ) : print ( c ) exit ( ) c -= 1 if ( c == 1 ) : print ( ""0"" ) NEW_LINE " V227,"import java . io . * ; import java . util . * ;   public class B { public static void main ( String [ ] args ) throws IOException { FastReader fr = new FastReader ( ) ; PrintWriter pr = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int t = fr . nextInt ( ) ;   while ( t -- > 0 ) { int n = fr . nextInt ( ) ; TreeMap < Integer , List < Integer > > map = new TreeMap < > ( ) ;   for ( int i = 0 ; i < n ; i ++ ) { int add = fr . nextInt ( ) ; map . putIfAbsent ( add , new ArrayList < > ( ) ) ; map . get ( add ) . add ( i + 1 ) ; }   ","t = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = sorted ( a ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( 1 ) else : NEW_LINE mini = - 1 NEW_LINE DEDENT if b [ 0 ] != b [ 1 ] : NEW_LINE INDENT mini = b [ 0 ] else : NEW_LINE for NEW_LINE DEDENT i in range ( 1 , n - 1 ) : NEW_LINE if b [ i ] != b [ i + 1 ] and b [ i ] != b [ i - 1 ] : mini = b [ i ] NEW_LINE break NEW_LINE if mini == - 1 and b [ n - 1 ] != b [ n - 2 ] : mini = b [ n - 1 ] NEW_LINE if mini == - 1 : NEW_LINE INDENT print ( - 1 ) else : NEW_LINE print ( a . index ( mini ) + 1 ) NEW_LINE DEDENT " V228,"import java . util . Scanner ; public class MyClass { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int k = s . nextInt ( ) ; int n = s . nextInt ( ) ; int w = s . nextInt ( ) ; int x = 0 , y = 0 ; for ( int i = 1 ; i <= w ; i ++ ) { x = k * i ; y = y + x ; } if ( y > n ) { k = y - n ; System . out . println ( k ) ; } else System . out . println ( ""0"" ) ; } } ","z = 0 x = list ( map ( int , input ( ) . rstrip ( ) . split ( ) ) ) for i in range ( 1 , x [ 2 ] + 1 ) : z = z + ( i * x [ 0 ] ) if x [ 1 ] - z < 0 : print ( abs ( z - x [ 1 ] ) ) else : print ( 0 ) NEW_LINE " V229,"import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; if ( n == 1 ) System . out . println ( 9 ) ; else if ( n == 2 ) System . out . println ( 98 ) ; else if ( n == 3 ) System . out . println ( 989 ) ; else { System . out . print ( 989 ) ; int x = 0 ; while ( n -- > 3 ) { System . out . print ( x ) ; if ( x == 9 ) x = 0 ; else x ++ ; } System . out . println ( ) ; } } } } ","for t in range ( int ( input ( ) ) ) : n = int ( input ( ) ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( 9 ) elif n == 2 : NEW_LINE print ( 98 ) elif n == 3 : NEW_LINE print ( 989 ) else : NEW_LINE print ( 989 , end = ' ' ) NEW_LINE DEDENT for i in range ( n - 3 ) : print ( i % 10 , end = ' ' ) NEW_LINE print ( ) NEW_LINE " V230,"import java . util . * ; public class poi { public static void main ( String args [ ] ) { Scanner in = new Scanner ( System . in ) ; int t = 1 ; int i , j ; while ( t -- > 0 ) { int n = in . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } ","from sys import stdin , stdoutstdin . readlinedef mp ( ) : return list ( map ( int , stdin . readline ( ) . strip ( ) . split ( ) ) ) def it ( ) : return int ( stdin . readline ( ) . strip ( ) ) from collections import defaultdict as dd , Counter as C , dequefrom math import ceil   n = it ( ) l = mp ( ) ans = 1 flag = 0 for i in range ( n ) : if l [ i ] == 1 and flag == 0 : ind = i flag = 1 elif l [ i ] == 1 and flag : ans *= ( i - ind ) ind = iif not flag : print ( 0 ) else : print ( ans ) NEW_LINE " V231,"import java . util . * ; import java . io . * ; import java . util . stream . * ; public class Solution { public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; scan . nextLine ( ) ; String s = scan . nextLine ( ) ; System . out . println ( s . replaceAll ( "" ogo ( go ) * "" , "" * * * "" ) ) ; } } ","n = int ( input ( ) ) s = input ( )   while ' ogo ' in s : x = s . replace ( "" ogo "" , "" * * * "" , 1 ) while x != s : s = x x = s . replace ( "" * go "" , ' * ' )     print ( s ) NEW_LINE " V232,"import java . util . * ; public class P2 {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int sum = 0 ; if ( a [ n - 1 ] > 25 ) { sum = a [ n - 1 ] - 25 ; } System . out . println ( sum ) ; } } ","num = int ( input ( ) ) arr = list ( map ( int , input ( ) . split ( ) ) )   mx = max ( arr )   print ( max ( 0 , mx - 25 ) )                   NEW_LINE " V233,"import java . io . * ; import java . lang . * ; import java . util . * ;   public class GregAndGraph_295B { private static int n = 0 ; private static long [ ] [ ] graph ;   public static void main ( String [ ] args ) throws IOException { BufferedReader sc = new BufferedReader ( new InputStreamReader ( System . in ) ) ; n = Integer . parseInt ( sc . readLine ( ) ) ; graph = new long [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] line = sc . readLine ( ) . split ( "" \\ s "" ) ; for ( int j = 0 ; j < n ; j ++ ) { graph [ i ] [ j ] = Integer . parseInt ( line [ j ] ) ; } } int cnt = 0 ; long [ ] ans = new long [ n ] ; String [ ] downVertices = sc . readLine ( ) . split ( "" \\ s "" ) ; boolean [ ] vis = new boolean [ n ] ; for ( int p = n - 1 ; p >= 0 ; p -- ) { int down = Integer . parseInt ( downVertices [ p ] ) - 1 ; vis [ down ] = true ; for ( int u = 0 ; u < n ; u ++ ) { for ( int v = 0 ; v < n ; v ++ ) { graph [ u ] [ v ] = Math . min ( graph [ u ] [ v ] , graph [ u ] [ down ] + graph [ down ] [ v ] ) ; } }    long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( vis [ i ] && vis [ j ] ) { sum += graph [ i ] [ j ] ; } } } ans [ cnt ++ ] = sum ; }   for ( int i = n - 1 ; i >= 0 ; i -- ) { System . out . println ( ans [ i ] ) ; } } } ","import sysfrom functools import lru_cache , cmp_to_keyfrom heapq import merge , heapify , heappop , heappush NEW_LINE " V234,"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 ( ) ;   if ( N == 0 ) { out . println ( "" YES "" ) ; int [ ] a = { 1 , 2 , 2 , 3 } ; for ( int x : a ) out . println ( x ) ; return ; }   if ( N == 4 ) { int [ ] a = new int [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) a [ i ] = in . nextInt ( ) ; Arrays . sort ( a ) ; if ( range ( a ) != median ( a ) || median ( a ) != avg ( a ) ) NO ( ) ; else out . println ( "" YES "" ) ; }   if ( N == 1 ) { int a = in . nextInt ( ) ; ","if __name__ == "" _ _ main _ _ "" : boxes = int ( input ( ) ) candy_supply = [ ] for i in range ( boxes ) : candies = int ( input ( ) ) candy_supply . append ( candies ) candy_supply = sorted ( candy_supply ) if boxes == 4 : c_range = candy_supply [ 3 ] - candy_supply [ 0 ] a_mean = ( candy_supply [ 0 ] + candy_supply [ 1 ] + candy_supply [ 2 ] + candy_supply [ 3 ] ) / 4 median = ( candy_supply [ 2 ] + candy_supply [ 1 ] ) / 2 if c_range == a_mean == median : print ( ' YES ' ) else : print ( ' NO ' ) elif boxes == 0 : print ( ' YES ' ) candy_supply = [ 1 , 2 , 2 , 3 ] for box in candy_supply : print ( box ) elif boxes == 1 : print ( ' YES ' ) x1 = candy_supply [ 0 ] candy_supply . append ( 2 * x1 ) candy_supply . append ( 2 * x1 ) candy_supply . append ( 3 * x1 ) print ( candy_supply [ 1 ] ) print ( candy_supply [ 2 ] ) print ( candy_supply [ 3 ] ) elif boxes == 3 : NEW_LINE " V235,"import java . util . Scanner ;   public class music {   public static int helper ( int t , int s , int q ) { int ans = s ; int count = 0 ; while ( ans < t ) { ans = ans + ans * ( q - 1 ) ; count ++ ; } if ( count == 0 ) return 1 ; else return count ; }   public static void main ( String [ ] args ) { ","t , s , q = map ( int , input ( ) . split ( ) ) init = q count = 1 while ( init < t / s ) : init = init * q count = count + 1 print ( count ) NEW_LINE " V236,"import java . io . InputStream ; import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . BufferedWriter ; import java . io . Writer ; import java . io . OutputStreamWriter ; import java . io . IOException ; import java . util . InputMismatchException ; import java . io . PrintWriter ; import java . io . OutputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; OutputWriter out = new OutputWriter ( outputStream ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { public void solve ( int testNumber , InputReader in , OutputWriter out ) { int n = in . ri ( ) ; IntPair [ ] walls = new IntPair [ n ] ; ","import mathn = int ( input ( ) ) lis = [ ] wall = [ ] for _ in range ( n ) : a , b , c = map ( int , input ( ) . split ( ) ) lis . append ( [ a , b , c ] ) m = int ( input ( ) ) for _ in range ( m ) : a , b , c = map ( int , input ( ) . split ( ) ) wall . append ( [ a , b , c ] ) ans = 0 for i in range ( n ) : tmp = 1000000000000000 x , y , z = lis [ i ] for j in range ( m ) : a , b , c = wall [ j ] if a // z == 0 : continue else : cove = ( a // z ) * b tmp = min ( tmp , math . ceil ( ( 2 * ( x + y ) ) / cove ) * c ) ans += tmpprint ( ans ) NEW_LINE " V237,"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 IOException { ","  def check ( a , x ) : for i in range ( len ( a ) ) : if a [ i ] < len ( a ) - i : return False return True   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) a = sorted ( a )   piles = [ ]   for i in a : if len ( piles ) == 0 : piles . append ( [ i ] ) else : flg = 1 for j in range ( len ( piles ) ) : if len ( piles [ j ] ) <= i : piles [ j ] . append ( i ) flg = 0 break if flg : piles . append ( [ i ] )   print ( len ( piles ) )       NEW_LINE " V238,"import java . util . Scanner ;   public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int [ ] arr = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } boolean flag = false ; for ( int i = 2 ; i < n ; i ++ ) { if ( ( arr [ i ] > arr [ i - 1 ] && ( arr [ i ] > arr [ i + 1 ] ) ) ) { flag = true ; int j = i - 1 ; int k = i + 1 ; System . out . println ( "" YES "" ) ; System . out . println ( j + "" ▁ "" + i + "" ▁ "" + k ) ; break ; } } if ( ! flag ) System . out . println ( "" NO "" ) ; flag = false ; } } }   ","t = int ( input ( ) ) for _ in range ( t ) : n = int ( input ( ) ) ali = list ( map ( int , input ( ) . split ( ) ) ) q = - 1 w = - 1 e = - 1 f = 0 for i in range ( 1 , n - 1 ) : if ( ali [ i ] > ali [ i - 1 ] and ali [ i ] > ali [ i + 1 ] ) : f = 1 q = i w = i + 1 e = i + 2 break if ( f == 1 ) : print ( "" YES "" ) print ( q , w , e ) else : print ( "" NO "" ) NEW_LINE " V239,"import java . util . * ; import java . math . * ; public class UnluckyTicket { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char [ ] temp = sc . next ( ) . toCharArray ( ) ; int [ ] arr1 = new int [ n ] ; int [ ] arr2 = new int [ n ] ; int p2 = n ; for ( int i = 0 ; i < n ; i ++ ) { arr1 [ i ] = temp [ i ] - '0' ; arr2 [ i ] = temp [ p2 ] - '0' ; p2 ++ ; } Arrays . sort ( arr1 ) ; Arrays . sort ( arr2 ) ; p2 = n ; boolean less = false ; boolean more = false ; boolean equal = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr1 [ i ] < arr2 [ i ] ) less = true ; else if ( arr1 [ i ] > arr2 [ i ] ) more = true ; else equal = true ; p2 ++ ; } if ( ( less && ! more || more && ! less ) && ! equal ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def solution ( ) : n = int ( input ( ) ) num = str ( input ( ) ) first = [ int ( nm ) for nm in num [ : n ] ] second = [ int ( nm ) for nm in num [ n : ] ] idx = 0 first . sort ( ) second . sort ( )   while idx < n and first [ idx ] < second [ idx ] : idx += 1 if idx == n : print ( ' YES ' ) return idx = 0 while idx < n and first [ idx ] > second [ idx ] : idx += 1 if idx == n : print ( ' YES ' ) return print ( ' NO ' ) return     solution ( ) NEW_LINE " V240,"import java . util . * ; import java . util . Scanner ; import java . io . * ; import javax . lang . model . util . ElementScanner6 ; import static java . lang . System . out ; import java . util . Stack ; import java . util . Queue ; import java . util . LinkedList ;   public class B476M2 {   static int mod = ( int ) ( 1e9 + 7 ) ; static long MOD = ( long ) ( 1e9 + 7 ) ; static FastReader in = new FastReader ( ) ; static PrintWriter pr = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; public static void main ( String args [ ] ) {   int tc = 1 ; ","import math     def calc ( n , i ) : num1 , num2 = 1 , 1   for j in range ( i ) : num1 *= n - j num2 *= j + 1 return num1 / num2     str1 = input ( ) str2 = input ( )   value1 , value2 , cnt = 0 , 0 , 0 prob = { }   for char in str1 : if char == "" + "" : value1 += 1 elif char == "" - "" : value1 -= 1   for char in str2 : if char == "" + "" : value2 += 1 elif char == "" - "" : value2 -= 1 elif char == "" ? "" : cnt += 1   value = value1 - value2   for i in range ( len ( str1 ) // 2 + 1 ) : prob [ ( cnt - i ) * - 1 + i ] = calc ( cnt , i ) prob [ ( ( cnt - i ) * - 1 + i ) * - 1 ] = calc ( cnt , i )   if cnt == 0 and value == 0 : print ( 1.0 ) elif cnt == 0 and value != 0 : print ( 0.0 ) else : if value in prob : print ( prob [ value ] / math . pow ( 2 , cnt ) ) else : print ( 0.0 ) NEW_LINE " V241,"import java . util . * ; import java . lang . * ; import java . io . * ;   ","cases = int ( input ( ) ) NEW_LINE while cases : cases -= 1 NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE arr = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ln = a * b NEW_LINE cut = ( a - 1 ) // 2 * b NEW_LINE a -= ( a - 1 ) // 2 NEW_LINE arr = arr [ cut : ]   ans = 0 NEW_LINE for i in range ( 0 , ln - cut , a ) : ans += arr [ i ] NEW_LINE " V242,"import java . io . * ; import java . util . * ;     public class A { ","n = int ( input ( ) ) print ( ' First ' if any ( int ( i ) % 2 != 0 for i in input ( ) . split ( ) ) else ' Second ' )     ''' c = 0flag = 0for ▁ i ▁ in ▁ range ( n ) : ▁ ▁ ▁ ▁ if ▁ a [ i ] %2 ! = 0 : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ flag = 1 ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ breakif ▁ flag = = 1 : ▁ ▁ ▁ ▁ print ( ' First ' ) else : ▁ ▁ ▁ ▁ print ( ' Second ' ) ▁ ''' NEW_LINE " V243,"import java . util . * ; import java . io . * ;   public class Bear_And_Prime_100 {   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 ( ) ) ; }   String nextLine ( ) { String str = "" "" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; }   }   public static void shuffle ( int [ ] a ) { Random r = new Random ( ) ;   for ( int i = 0 ; i <= a . length - 2 ; i ++ ) { int j = i + r . nextInt ( a . length - i ) ;   swap ( a , i , j ) ; } }   public static void swap ( int [ ] a , int i , int j ) { int temp = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = temp ; }   public static void main ( String [ ] args ) { ","print ( "" composite "" if sum ( input ( ) == ' yes ' for i in [ 2 , 3 , 4 , 5 , 7 , 9 , 11 , 13 , 17 , 19 , 23 , 25 , 29 , 31 , 37 , 41 , 43 , 47 , 49 ] if not print ( i ) ) > 1 else "" prime "" ) NEW_LINE " V244,"    import java . awt . * ; import java . io . IOException ; import java . util . Comparator ; import java . util . Scanner ;   public class Main {   ","n = int ( input ( ) ) minX = 10 ** 10 maxX = - ( 10 ** 10 ) minY = 10 ** 10 maxY = - ( 10 ** 10 ) for i in range ( n ) : mine = list ( map ( int , input ( ) . split ( ) ) ) minX = min ( mine [ 0 ] , minX ) maxX = max ( mine [ 0 ] , maxX ) minY = min ( mine [ 1 ] , minY ) maxY = max ( mine [ 1 ] , maxY ) print ( max ( maxX - minX , maxY - minY ) ** 2 ) NEW_LINE " V245,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Random ; import java . util . StringTokenizer ; import java . util . List ; import java . util . Collections ; import java . util . Map ; import java . util . HashMap ; import java . util . Comparator ; import java . util . stream . IntStream ; import java . util . ArrayDeque ; import java . util . PriorityQueue ; import java . util . Set ; import java . util . HashSet ; public class Main { private static FastScanner fs = new FastScanner ( ) ; private static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { int n = fs . nextInt ( ) ; while ( n -- > 0 ) { int x = fs . nextInt ( ) , y = fs . nextInt ( ) , z = fs . nextInt ( ) ;   int arr [ ] = new int [ ] { x , y , z } ; Arrays . sort ( arr ) ; if ( arr [ 1 ] != arr [ 2 ] ) { System . out . println ( "" NO "" ) ; } else { System . out . println ( "" YES "" ) ; System . out . println ( arr [ 0 ] + "" ▁ "" + arr [ 0 ] + "" ▁ "" + arr [ 2 ] ) ; } }     } static class Node implements Comparable < Node > { Integer start ; Integer end ; public int compareTo ( Node a ) { int v = start . compareTo ( a . start ) ; ","t = int ( input ( ) ) for _ in range ( t ) : l = list ( map ( int , input ( ) . split ( ) ) ) l . sort ( ) if l [ 1 ] == l [ 2 ] : print ( "" Yes "" ) print ( l [ 0 ] , l [ 0 ] , l [ 1 ] ) else : print ( "" No "" ) NEW_LINE " V246,"import java . io . * ; import java . util . * ; import java . math . * ;   public class B { public static void main ( String [ ] args ) throws IOException { FastScanner fs = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;   ","import syss = [ item . strip ( ) for item in sys . stdin ]   l = 0 for item in s : l = max ( l , len ( item ) ) arr = [ ] one = 0 two = 1 arr . append ( [ ' * ' for _ in range ( l + 2 ) ] ) for item in s : temp = [ ' * ' ] z = len ( item ) temp += [ ' ▁ ' for _ in range ( ( l - z + one ) // 2 ) ] temp += [ c for c in item ] temp += [ ' ▁ ' for _ in range ( ( l - z + two ) // 2 ) ] temp . append ( ' * ' ) if ( l - z ) % 2 == 1 : one = 1 - one two = 1 - two arr . append ( temp ) arr . append ( [ ' * ' for _ in range ( l + 2 ) ] ) for item in arr : print ( ' ' . join ( item ) ) NEW_LINE " V247,"  import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . Scanner ;       public class problem4 { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int numClusters = scan . nextInt ( ) ; int numFiles = scan . nextInt ( ) ;   Clusters clusters = new Clusters ( numClusters ) ; clusters . loadClusters ( scan , numFiles ) ;   ArrayList < Move > moves = new ArrayList < Move > ( ) ;   ","import sysn , m , * inp = map ( int , sys . stdin . read ( ) . split ( ) )   inp . reverse ( ) f = [ [ 0 for x in range ( 201 ) ] for y in range ( 201 ) ] NEW_LINE " V248,"import java . util . * ; import java . io . * ; public class Main implements Runnable { FastScanner sc ; PrintWriter pw ; final class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner ( ) { try { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } public long nlo ( ) { return Long . parseLong ( next ( ) ) ; } public String next ( ) { if ( st . hasMoreTokens ( ) ) return st . nextToken ( ) ; try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } public int ni ( ) { return Integer . parseInt ( next ( ) ) ; } public String nli ( ) { String line = "" "" ; if ( st . hasMoreTokens ( ) ) line = st . nextToken ( ) ; else try { return br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } while ( st . hasMoreTokens ( ) ) line += "" ▁ "" + st . nextToken ( ) ; return line ; } public double nd ( ) { return Double . parseDouble ( next ( ) ) ; } } public static void main ( String [ ] args ) { new Thread ( null , new Main ( ) , "" codeforces "" , 1 << 25 ) . start ( ) ; } public void run ( ) { sc = new FastScanner ( ) ; pw = new PrintWriter ( System . out ) ; solve ( ) ; pw . flush ( ) ; pw . close ( ) ; } public long gcd ( long a , long b ) { return b == 0L ? a : gcd ( b , a % b ) ; } public long ppow ( long a , long b , long mod ) { if ( b == 0L ) return 1L ; long tmp = 1 ; while ( b > 1L ) { if ( ( b & 1L ) == 1 ) tmp *= a ; a *= a ; a %= mod ; tmp %= mod ; b >>= 1 ; } return ( tmp * a ) % mod ; } ","from sys import stdin , stdout   n , m = [ int ( x ) for x in stdin . readline ( ) . split ( ) ]   if n == 2 : c = 1 way = [ ] mult = 1 for x in range ( m - 1 , - 1 , - 1 ) : way . append ( c ) c += x * mult mult *= - 1 for x in way : print ( 1 , x ) for x in way [ : : - 1 ] : print ( 2 , x ) elif n == 1 : c = 1 way = [ ] mult = 1 for x in range ( m - 1 , - 1 , - 1 ) : way . append ( c ) c += x * mult mult *= - 1 for x in way : print ( 1 , x )   elif m == 2 : c = 1 way = [ ] mult = 1 for x in range ( n - 1 , - 1 , - 1 ) : way . append ( c ) c += x * mult mult *= - 1 for x in way : print ( x , 1 ) for x in way [ : - 1 : - 1 ] : print ( x , 2 )   elif m == 1 : c = 1 way = [ ] mult = 1 for x in range ( n - 1 , - 1 , - 1 ) : way . append ( c ) c += x * mult mult *= - 1 for x in way : print ( x , 1 ) else : outStr = ' ' for x in range ( n // 2 ) : for y in range ( 1 , m + 1 ) : stdout . write ( str ( x + 1 ) + ' ▁ ' + str ( y ) + ' \n ' ) stdout . write ( str ( n - x ) + ' ▁ ' + str ( m + 1 - y ) + ' \n ' ) if n % 2 == 1 : c = 1 way = [ ] mult = 1 for x in range ( m - 1 , - 1 , - 1 ) : way . append ( c ) c += x * mult mult *= - 1 for x in way : stdout . write ( str ( n // 2 + 1 ) + ' ▁ ' + str ( x ) + ' \n ' )         NEW_LINE " V249,"  import java . util . * ; import java . lang . * ; import java . io . * ; import java . math . * ;    public class file {    ","n = int ( input ( ) ) A = list ( map ( int , input ( ) . split ( ) ) ) A = [ a - 1 for a in A ] C = [ [ ] for i in range ( n ) ] for i , a in enumerate ( A ) : C [ a ] . append ( i ) from collections import defaultdictINF = 10 ** 18 dp = defaultdict ( lambda : INF ) dp [ ( 0 , 0 ) ] = 0 for i in range ( n ) : nx = defaultdict ( lambda : INF ) for ( s , d ) , v in dp . items ( ) : ns = C [ i ] [ 0 ] nd = C [ i ] [ 1 ] nv = v + abs ( ns - s ) + abs ( nd - d ) nx [ ( ns , nd ) ] = min ( nx [ ( ns , nd ) ] , nv ) ns = C [ i ] [ 1 ] nd = C [ i ] [ 0 ] nv = v + abs ( ns - s ) + abs ( nd - d ) nx [ ( ns , nd ) ] = min ( nx [ ( ns , nd ) ] , nv ) dp = nxprint ( min ( dp . values ( ) ) ) NEW_LINE " V250,"import java . util . * ; import java . lang . * ; import java . io . * ;   public class FastIO { BufferedReader br ; StringTokenizer st ; public FastIO ( ) { ","def solve ( arr , n ) : res = [ ] for i in range ( n - 2 ) : temp = arr [ : ] temp . pop ( i + 1 ) max_val = 0 for j in range ( n - 2 ) : if temp [ j + 1 ] - temp [ j ] > max_val : max_val = temp [ j + 1 ] - temp [ j ] res . append ( max_val )   return min ( res )           def main ( ) : n = int ( input ( ) ) arr = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) NEW_LINE " V251,"import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ;   public class temp4 { 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 ( ) ) ; } String nextLine ( ) { String str = "" "" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } static class Print { private final BufferedWriter bw ; public Print ( ) { bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; } public void print ( String str ) throws IOException { bw . append ( str ) ; } public void println ( String str ) throws IOException { print ( str ) ; bw . append ( "" \n "" ) ; } public void close ( ) throws IOException { bw . close ( ) ; } } public static void main ( String [ ] args ) throws IOException { FastReader scn = new FastReader ( ) ; ","num = int ( input ( ) ) arr = list ( map ( int , input ( ) . split ( ) ) ) + [ 10000 ]   sub_arr = [ ] mx = 0 ans_arr = [ ] for i in range ( num ) : if arr [ i + 1 ] - arr [ i ] == 1 : sub_arr . append ( arr [ i ] ) else : if sub_arr : sub_arr . append ( arr [ i ] ) if len ( sub_arr ) > mx : mx = len ( sub_arr ) ans_arr = sub_arr [ : ] if len ( sub_arr ) == mx > 1 and ( sub_arr [ 0 ] == 1 or sub_arr [ - 1 ] == 1000 ) : ans_arr = sub_arr [ : ] sub_arr = [ ] if not ans_arr : print ( 0 ) elif ans_arr [ 0 ] == 1 or ans_arr [ - 1 ] == 1000 : print ( max ( 0 , mx - 1 ) ) else : print ( max ( 0 , mx - 2 ) ) NEW_LINE " V252,"import java . util . * ;   public class Absolutezero {    public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int flag = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; if ( i != s . length ( ) - 1 ) { char ch1 = s . charAt ( i + 1 ) ; if ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' && ch != ' n ' ) { if ( ch1 == ' a ' || ch1 == ' e ' || ch1 == ' i ' || ch1 == ' o ' || ch1 == ' u ' ) {   } else { flag = 1 ; break ; } } } else { if ( ch == ' a ' || ch == ' e ' || ch == ' i ' || ch == ' o ' || ch == ' u ' || ch == ' n ' ) {   } else { flag = 1 ; break ; } } } if ( flag == 0 ) { System . out . println ( "" YES "" ) ; } else { System . out . println ( "" NO "" ) ; }    }   }   ","s = input ( )   ok = { "" a "" , "" o "" , "" u "" , "" i "" , "" e "" } nn = { "" n "" }   if s [ - 1 ] not in ok . union ( nn ) : print ( "" NO "" ) else : for i in range ( len ( s ) - 1 ) : if s [ i ] not in ok . union ( nn ) and s [ i + 1 ] not in ok : print ( "" NO "" ) exit ( ) print ( "" YES "" )       NEW_LINE " V253,"  import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . util . ArrayList ; import java . util . Comparator ; import java . util . List ; import java . util . PriorityQueue ; import java . util . Scanner ;   public class P037B {   public class Spell { private int pow ; private int dmg ; private int index ; public Spell ( int pow , int dmg , int index ) { this . pow = pow ; this . dmg = dmg ; this . index = index ; }   public int getPow ( ) { return pow ; } public void setPow ( int pow ) { this . pow = pow ; } public int getDmg ( ) { return dmg ; } public void setDmg ( int dmg ) { this . dmg = dmg ; } public int getIndex ( ) { return index ; } public void setIndex ( int index ) { this . index = index ; } }   public class Cast { private int second ; private int index ; public Cast ( int second , int index ) { this . second = second ; this . index = index ; } public int getSecond ( ) { return second ; } public void setSecond ( int second ) { this . second = second ; } public int getIndex ( ) { return index ; } public void setIndex ( int index ) { this . index = index ; } } public void solve ( ) { ","import itertoolsimport math N , x , y = [ int ( n ) for n in input ( ) . split ( ) ] pills = [ ] for i in range ( N ) : pills . append ( tuple ( int ( n ) for n in input ( ) . split ( ) ) + ( i + 1 , ) ) pills . sort ( ) rques = xqauto = 0 time = 0 used = [ ] possible = set ( ) while rques > 0 : while len ( pills ) > 0 and pills [ - 1 ] [ 0 ] >= 100 * rques / x : possible . add ( pills . pop ( ) [ 1 : ] ) if len ( possible ) > 0 : best = max ( possible ) used . append ( ( best , time ) ) possible . remove ( best ) qauto += best [ 0 ] elif qauto <= y : print ( ' NO ' ) break rques = min ( rques + y - qauto , x ) time += 1 else : print ( ' YES ' ) print ( time , len ( used ) ) for scroll in used : print ( scroll [ 1 ] , scroll [ 0 ] [ 1 ] ) NEW_LINE " V254,"import java . io . * ; import java . util . * ; public class reconnaisance { public static void main ( String [ ] args ) throws IOException { BufferedReader f = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( f . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int d = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] array = new int [ n ] ; int ans = 0 ; st = new StringTokenizer ( f . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( Math . abs ( array [ i ] - array [ j ] ) <= d ) { ans ++ ; } } } out . println ( ans - n ) ; out . close ( ) ; } } ","n , d = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) sets = 0 a . sort ( ) for i in range ( 0 , n - 1 ) : A = a [ i ] for j in range ( i + 1 , n ) : B = a [ j ] diff = B - A if diff <= d : sets += 1 else : breakprint ( 2 * sets ) NEW_LINE " V255,"import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   ","n , b , p = map ( int , input ( ) . split ( ) ) ans = 0 x = nwhile ( n > 1 ) : ans = ( ( n // 2 ) * 2 * b ) + ( n // 2 ) + ans n = ( n // 2 ) + ( n - ( ( n // 2 ) * 2 ) ) print ( ans , x * p ) NEW_LINE " V256,"import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . Double . parseDouble ; import static java . lang . Math . PI ; import static java . lang . Math . min ; import static java . lang . System . arraycopy ; import static java . lang . System . exit ; import static java . util . Arrays . copyOf ;   import java . util . LinkedList ; import java . io . FileReader ; import java . io . FileWriter ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Set ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . HashMap ; import java . util . NoSuchElementException ; import java . util . PriorityQueue ; import java . util . StringTokenizer ; import java . util . Comparator ; import java . lang . StringBuilder ; import java . util . Collections ; public class Solution {   static int scanInt ( ) throws IOException { return parseInt ( scanString ( ) ) ; }   static long scanLong ( ) throws IOException { return parseLong ( scanString ( ) ) ; } static double scanDouble ( ) throws IOException { return parseDouble ( scanString ( ) ) ; }   static String scanString ( ) throws IOException { if ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } static String scanLine ( ) throws IOException { return in . readLine ( ) ; }   static void printCase ( String str ) { out . print ( "" Case ▁ # "" + test + "" : ▁ "" + str ) ; }   static void printlnCase ( ) { out . println ( "" Case ▁ # "" + test + "" : "" ) ; }   static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static StringBuilder str ; public static void main ( String [ ] args ) { try { long startTime = System . currentTimeMillis ( ) ;   in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ; ","def solve ( ) : s = input ( ) digit_sum = 0 even_cnt = 0 zero_cnt = 0 for x in s : if int ( x ) == 0 : zero_cnt += 1 elif int ( x ) % 2 == 0 : even_cnt += 1 digit_sum += int ( x ) if digit_sum % 3 == 0 and ( zero_cnt >= 2 or even_cnt >= 1 and zero_cnt >= 1 ) : print ( ' red ' ) else : print ( ' cyan ' )   t = int ( input ( ) ) for _ in range ( t ) : solve ( ) NEW_LINE " V257,"import java . util . * ; public class ch1 { public static void main ( String [ ] args ) throws Exception { int a , b = 0 ; char ch ; Scanner reader = new Scanner ( System . in ) ; a = reader . nextInt ( ) ; String str = reader . next ( ) ; for ( int i = 0 ; i < a ; ++ i ) { if ( str . charAt ( i ) == ' + ' ) ++ b ; else if ( b > 0 ) -- b ; } System . out . print ( b ) ; } } ","n = int ( input ( ) ) a = 0 m = 0 i = n - 1 s = str ( input ( ) ) while ( i >= 0 ) : if s [ i ] == ' + ' : m += 1 else : m -= 1 a = max ( a , m ) i -= 1 print ( a )           NEW_LINE " V258,"import java . util . * ; public class P2 {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int d = 0 ; int C = 0 ; int S = 0 ; if ( s . length ( ) >= 5 ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) >= 48 && s . charAt ( i ) <= 57 ) { d ++ ; } else if ( s . charAt ( i ) >= 65 && s . charAt ( i ) <= 90 ) { C ++ ; } else if ( s . charAt ( i ) >= 97 && s . charAt ( i ) <= 122 ) { S ++ ; } } if ( d >= 1 && C >= 1 && S >= 1 ) { System . out . println ( "" Correct "" ) ; } else { System . out . println ( "" Too ▁ weak "" ) ; } } else System . out . println ( "" Too ▁ weak "" ) ; } }   ","s = input ( )   ln = cap = low = digit = False     for char in s : if len ( s ) > 4 : ln = True if char . isupper ( ) : cap = True if char . islower ( ) : low = True if char . isdigit ( ) : digit = True   if ln == cap == low == digit != False : print ( "" Correct "" ) else : print ( "" Too ▁ weak "" )   NEW_LINE " V259,"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintStream ; import java . util . * ;   ","from sys import stdin , stdoutfrom os import pathrd = lambda : stdin . readline ( ) . strip ( ) wr = stdout . writeif ( path . exists ( ' input . txt ' ) ) : stdin = open ( "" input . txt "" , "" r "" ) import time , math NEW_LINE " V260,"import java . io . * ; import java . lang . * ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . BufferedReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . io . IOException ; import java . util . Arrays ; import java . util . Random ; import java . util . StringTokenizer ; import java . math . BigInteger ;   public class Birthday { ","from math import ceiln , m , k , p = map ( int , input ( ) . split ( ) )   if n - k < p : print ( - 1 ) else : an = ceil ( ( p + k + m - 1 ) // m ) if an * m > n : print ( - 1 ) else : print ( an ) NEW_LINE " V261,"import java . util . * ;   public class VasyaAndWrestling_B {   public static void main ( String [ ] args ) { ","ans1 = 0 ans2 = 0 l1 = [ ] l2 = [ ] for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) if ( n > 0 ) : ans1 += n l1 . append ( n ) else : ans2 += abs ( n ) l2 . append ( - n ) if ( ans1 > ans2 or ( ans1 == ans2 and l1 > l2 ) or ( l1 == l2 and n > 0 ) ) : print ( "" first "" ) else : print ( "" second "" ) NEW_LINE " V262,"import java . util . Scanner ; public class AA { public static void main ( String [ ] args ) { int y , x ; Scanner ob = new Scanner ( System . in ) ; int a = ob . nextInt ( ) ; int b = ob . nextInt ( ) ; x = a / b ; y = a + x ; x = ( x + a % b ) ; while ( x > b ) { y += x / b ; x = ( x / b + x % b ) ; }   if ( x == b ) { y += 1 ; } System . out . println ( y ) ; } } ","a , b = map ( int , input ( ) . split ( ) ) cur , dead = a , 0 h = awhile cur > 0 : dead += cur cur = dead // b dead = dead % b h += cur   print ( h ) NEW_LINE " V263,"import java . util . * ; import java . io . * ; import java . math . BigInteger ; import java . text . * ; public class Main { static long mod = 1000_000_007 ; static long mod1 = 998244353 ; static boolean fileIO = false ; static boolean memory = true ; static FastScanner f ; static PrintWriter pw ; static double eps = ( double ) 1e-6 ; static int oo = ( int ) 1e9 ;   public static void solve ( ) throws Exception { int n = f . ni ( ) ; int k = f . ni ( ) ; int y = n / k ; StringBuffer ans = new StringBuffer ( "" "" ) ; for ( int i = 0 ; i < k ; ++ i ) { char c = ( char ) ( i + ' a ' ) ; for ( int j = 0 ; j < n / k ; ++ j ) { ans . append ( c ) ; } } int x = ans . length ( ) ; for ( int i = 0 ; i < n - x ; ++ i ) ans . append ( "" a "" ) ; pn ( ans ) ; } public static void main ( String [ ] args ) throws Exception { if ( memory ) new Thread ( null , new Runnable ( ) { public void run ( ) { try { new Main ( ) . run ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } } , "" "" , 1 << 28 ) . start ( ) ; else new Main ( ) . run ( ) ; } void run ( ) throws Exception { if ( System . getProperty ( "" ONLINE _ JUDGE "" ) == null ) { f = new FastScanner ( "" "" ) ; pw = new PrintWriter ( System . out ) ; } else { f = new FastScanner ( ) ; pw = new PrintWriter ( System . out ) ; ","import sysfrom string import ascii_lowercase   def main ( ) : _ , * l = map ( int , sys . stdin . read ( ) . strip ( ) . split ( ) ) out = [ ] for i , j in zip ( l [ : : 2 ] , l [ 1 : : 2 ] ) : r = ascii_lowercase [ : j ] out . append ( i // j * r + r [ : i % j ] ) return out print ( * main ( ) , sep = ' \n ' ) NEW_LINE " V264,"import java . io . * ; import java . util . * ; public class Main { static InputReader in = new InputReader ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; static int oo = ( int ) 1e9 ; ","import math def dist ( p1 , p2 ) : return math . sqrt ( ( p1 [ 0 ] - p2 [ 0 ] ) ** 2 + ( p1 [ 1 ] - p2 [ 1 ] ) ** 2 ) def cross ( p1 , p2 ) : return p1 [ 0 ] * p2 [ 1 ] - p1 [ 1 ] * p2 [ 0 ] def parse_point ( line ) : tokens = line . split ( ) return int ( tokens [ 0 ] ) , int ( tokens [ 1 ] ) n = int ( input ( ) ) pt = [ parse_point ( input ( ) ) for _ in range ( n ) ] res = 1e100 pr1 , pr2 = None , Nonefor i in range ( len ( pt ) ) : pr1 = pt [ i - 2 ] pr2 = pt [ i - 1 ] cur = pt [ i ] p1 = ( pr1 [ 0 ] - pr2 [ 0 ] , pr1 [ 1 ] - pr2 [ 1 ] ) p2 = ( cur [ 0 ] - pr2 [ 0 ] , cur [ 1 ] - pr2 [ 1 ] ) c = dist ( pr1 , cur )   if abs ( cross ( p1 , p2 ) / 2 ) / c < res : res = abs ( cross ( p1 , p2 ) / 2 ) / c print ( res ) NEW_LINE " V265,"import java . util . * ; import java . io . * ; import java . math . * ;     public class A {   private static long INF = 2000000000L , M = 1000000007 , MM = 998244353 ; private static int N = 0 ;   public static void process ( ) throws IOException {   int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; String a [ ] = new String [ n + 1 ] ; String b [ ] = new String [ m + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . next ( ) ; for ( int i = 0 ; i < m ; i ++ ) b [ i ] = sc . next ( ) ; int q = sc . nextInt ( ) ; while ( q -- != 0 ) { int nn = sc . nextInt ( ) - 1 ; int aa = nn % n ; int bb = nn % m ; println ( a [ aa ] + "" "" + b [ bb ] ) ; }   }   ","a , b = map ( int , input ( ) . strip ( ) . split ( ) ) c = input ( ) . strip ( ) . split ( ) d = input ( ) . strip ( ) . split ( ) e = int ( input ( ) . strip ( ) ) for i in range ( e ) : f = int ( input ( ) . strip ( ) ) print ( c [ ( ( f - 1 ) ) % a ] + d [ ( f - 1 ) % b ] ) NEW_LINE " V266,"import java . io . * ;   public class questionCF { public static void main ( String [ ] args ) throws IOException {   BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String month [ ] = { "" January "" , "" February "" , "" March "" , "" April "" , "" May "" , "" June "" , "" July "" , "" August "" , "" September "" , "" October "" , "" November "" , "" December "" } ; String s = br . readLine ( ) ; int k = Integer . parseInt ( br . readLine ( ) ) ; int ind = 0 ; for ( int i = 0 ; i < month . length ; i ++ ) if ( month [ i ] . equals ( s ) ) { ind = i ; break ; } int mod = k % 12 ; if ( ( ind + mod ) >= 12 ) System . out . println ( month [ ( ind + mod ) - 12 ] ) ; else System . out . println ( month [ ind + mod ] ) ; } } ","months = [ ' January ' , ' February ' , ' March ' , ' April ' , ' May ' , ' June ' , ' July ' , ' August ' , ' September ' , ' October ' , ' November ' , ' December ' ] month , skip = input ( ) , int ( input ( ) ) years = int ( skip / 12 )   remaining = skip - years * 12 if remaining + months . index ( month ) <= 11 : print ( months [ remaining + months . index ( month ) ] ) else : print ( months [ remaining + months . index ( month ) - 12 ] ) NEW_LINE " V267,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ;   public class KvassAndFairNut { private static final FastReader in = new FastReader ( ) ; private static final PrintWriter out = new PrintWriter ( System . out ) ;   public static void main ( String [ ] args ) { Solver sol = new Solver ( ) ; int tt = 1 ; sol . solve ( tt ) ; out . close ( ) ; }   private static final class Solver { public void solve ( int testCase ) { int n = in . nextInt ( ) ; long s = Long . parseLong ( in . next ( ) ) ; int [ ] a = new int [ n ] ; long sum = 0L ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = in . nextInt ( ) ; sum += a [ i ] ; min = Math . min ( min , a [ i ] ) ; } if ( sum < s ) out . println ( - 1 ) ; else { out . println ( Math . min ( min , ( sum - s ) / n ) ) ; } } }   private static final class FastReader { private BufferedReader br ; private StringTokenizer st ;   public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) , 1 << 16 ) ; st = null ; }   public String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return st . nextToken ( ) ; }   public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } ","import os , sys , bisectfrom collections import defaultdict , Counter , deque ; from functools import lru_cache NEW_LINE " V268,"import java . io . * ; import java . util . * ;   public class Solution { static MyScanner sc ; private static PrintWriter out ; static long M2 = 1_000_000_000L + 7 ;   public static void main ( String [ ] s ) throws Exception { StringBuilder stringBuilder = new StringBuilder ( ) ; ","def main ( a , b , l , r ) :     qL = ( l - 1 ) // ( 2 * a + 2 * b )   rL = ( l - 1 ) % ( 2 * a + 2 * b ) + 1     qR = ( r - 1 ) // ( 2 * a + 2 * b )   rR = ( r - 1 ) % ( 2 * a + 2 * b ) + 1   NEW_LINE " V269,"import java . util . Scanner ;   public class A {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . nextInt ( ) ; while ( d > 0 ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { arr [ i - 1 ] ++ ; arr [ i ] -- ; break ; } } d -- ; } System . out . println ( arr [ 0 ] ) ; } } }   ","def solve ( ) : n , k = map ( int , input ( ) . split ( ) )   arr = [ int ( i ) for i in input ( ) . split ( ) ]   price = 1   while k >= price and price < len ( arr ) : if arr [ price ] == 0 : price += 1 continue   arr [ price ] -= 1 k -= price arr [ 0 ] += 1   print ( arr [ 0 ] )   t = int ( input ( ) )   while t : solve ( ) t -= 1 NEW_LINE " V270,"import java . io . * ; import java . math . * ; import java . util . * ;   import static java . util . Arrays . fill ; import static java . lang . Math . * ; import static java . util . Arrays . sort ; import static java . util . Collections . sort ;   public class YoungTable {   public static int mod = 1000000007 ; public static long INF = ( 1L << 60 ) ; static FastScanner2 in = new FastScanner2 ( ) ; static OutputWriter out = new OutputWriter ( System . out ) ;   static class Pair { int x , y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } public static void main ( String [ ] args ) {   Map < Integer , Pair > map = new HashMap < > ( ) ; int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] [ ] b = new int [ 51 ] [ 51 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < a [ i ] ; j ++ ) { int x = in . nextInt ( ) ; map . put ( x , new Pair ( i , j ) ) ; b [ i ] [ j ] = x ; } } int put = 1 ; int ans = 0 ; ArrayList < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < a [ i ] ; j ++ ) { Pair p = map . get ( put ) ; ","def find ( A , target ) : for i in range ( len ( A ) ) : for j in range ( len ( A [ i ] ) ) : if A [ i ] [ j ] == target : return [ i + 1 , j + 1 ] n = int ( input ( ) ) C = list ( map ( int , input ( ) . split ( ) ) ) X = [ ] for i in range ( n ) : Y = list ( map ( int , input ( ) . split ( ) ) ) X . append ( Y ) cnt = 1   tot = 0 ans = [ ] for i in range ( len ( X ) ) : for j in range ( len ( X [ i ] ) ) : t = find ( X , cnt ) X [ t [ 0 ] - 1 ] [ t [ 1 ] - 1 ] , X [ i ] [ j ] = X [ i ] [ j ] , X [ t [ 0 ] - 1 ] [ t [ 1 ] - 1 ] if t [ 0 ] != i + 1 or t [ 1 ] != j + 1 : ans . append ( str ( i + 1 ) + "" ▁ "" + str ( j + 1 ) + "" ▁ "" + str ( t [ 0 ] ) + "" ▁ "" + str ( t [ 1 ] ) ) tot += 1 cnt += 1 print ( tot ) for i in ans : print ( i ) NEW_LINE " V271,"  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 t ; t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int rem ; int mx = a > b ? a : b ; int mn = a < b ? a : b ; b = mx ; a = mn ; if ( a == 1 && b == n ) System . out . println ( n - 1 ) ; else if ( b + x > n ) { rem = ( b + x ) - n ; b = n ; if ( a - rem <= 0 ) a = 1 ; else a = a - rem ; System . out . println ( b - a ) ; } else System . out . println ( b + x - a ) ; } } } ","a = int ( input ( ) ) for i in range ( a ) : b , c , d , e = map ( int , input ( ) . split ( ) ) f = min ( b - 1 , abs ( e - d ) + c ) print ( f ) NEW_LINE " V272,"import java . util . * ; import java . lang . * ; import java . io . * ;   public class A_Yellow_Cards { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; ","a1 = int ( input ( ) ) a2 = int ( input ( ) ) k1 = int ( input ( ) ) k2 = int ( input ( ) ) n = int ( input ( ) ) def minc ( a1 , a2 , k1 , k2 , n ) : res = 0 if k1 > k2 : n = n - ( ( k1 - 1 ) * a1 ) if n <= 0 : return res else : n = n - ( ( k2 - 1 ) * a2 ) if n <= 0 : return res else : res = abs ( ( a1 + a2 ) - abs ( ( a1 + a2 ) - n ) ) return res else : n = n - ( ( k2 - 1 ) * a2 ) if n <= 0 : return res else : n = n - ( ( k1 - 1 ) * a1 ) if n <= 0 : return res else : res = abs ( ( a1 + a2 ) - abs ( ( a1 + a2 ) - n ) ) return res   def maxc ( a1 , a2 , k1 , k2 , n ) : res = 0 if k1 > k2 : k1 , k2 = k2 , k1 a1 , a2 = a2 , a1 if n <= a1 * k1 : res = n // k1 else : res = a1 + ( n - a1 * k1 ) // k2 return res   print ( minc ( a1 , a2 , k1 , k2 , n ) , end = ' ▁ ' ) print ( maxc ( a1 , a2 , k1 , k2 , n ) ) NEW_LINE " V273,"# include < bits / stdc ++ . h > using namespace std ; const int N = 1e6 + 7 ;   bool vis [ N ] ; int main ( ) { int n ; scanf ( "" % d "" , & n ) ; printf ( ""1 ▁ "" ) ; int y = n ; for ( int i = 1 ; i <= n ; i ++ ) { int x ; scanf ( "" % d "" , & x ) ; vis [ x ] = true ; while ( vis [ y ] ) y -- ; printf ( "" % d ▁ "" , 1 + i - ( n - y ) ) ; } return 0 ; } ","import sysinput = sys . stdin . readline   n = int ( input ( ) ) p = list ( map ( int , input ( ) . split ( ) ) ) flag = [ 1 ] * nr = n - 1 cnt = 0   print ( 1 , end = ' ▁ ' )   for i in range ( n - 1 ) : flag [ p [ i ] - 1 ] = 0 while flag [ r ] == 0 : r -= 1 cnt += 1 print ( i + 2 - cnt , end = ' ▁ ' )   print ( 1 ) NEW_LINE " V274,"import java . util . Scanner ;   public class main {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int p1 = sc . nextInt ( ) ; int p2 = sc . nextInt ( ) ; int p3 = sc . nextInt ( ) ; int t1 = sc . nextInt ( ) ; int t2 = sc . nextInt ( ) ; int [ ] l = new int [ n ] ; int [ ] r = new int [ n ] ;   int totalTime = 0 ;   for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = sc . nextInt ( ) ; r [ i ] = sc . nextInt ( ) ; }   for ( int i = 0 ; i < n ; i ++ ) { if ( i + 1 == n ) { totalTime += ( r [ i ] - l [ i ] ) * p1 ; } else { totalTime += ( r [ i ] - l [ i ] ) * p1 ; int timeLeft = l [ i + 1 ] - r [ i ] ; if ( timeLeft >= t1 + t2 ) { totalTime += t1 * p1 + t2 * p2 + ( timeLeft - t1 - t2 ) * p3 ; } else if ( timeLeft >= t1 ) { totalTime += t1 * p1 + ( timeLeft - t1 ) * p2 ; } else { totalTime += timeLeft * p1 ; } } }   System . out . print ( totalTime ) ; } }   ","n , p1 , p2 , p3 , t1 , t2 = map ( int , input ( ) . split ( ) ) l , r = map ( int , input ( ) . split ( ) ) power = ( r - l ) * p1last_time = rfor _ in range ( n - 1 ) : l , r = map ( int , input ( ) . split ( ) ) if l - last_time <= t1 : power += ( l - last_time ) * p1 elif l - last_time <= t1 + t2 : power += t1 * p1 + ( l - last_time - t1 ) * p2 else : power += t1 * p1 + t2 * p2 + ( l - last_time - t1 - t2 ) * p3 power += ( r - l ) * p1 last_time = rprint ( power ) NEW_LINE " V275,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . StringTokenizer ;   public class B { static FastReader scan = new FastReader ( ) ; static PrintWriter out = new PrintWriter ( System . out ) ;   public static void main ( String [ ] args ) { Solver solver = new Solver ( ) ; int testCases = 1 ; while ( testCases -- > 0 ) solver . solve ( ) ; out . close ( ) ; }   static class Solver { void solve ( ) { int x = scan . nextInt ( ) ; while ( x -- > 0 ) { int n = scan . nextInt ( ) , l = scan . nextInt ( ) , r = scan . nextInt ( ) ; if ( l > n ) { out . println ( "" No "" ) ; } else { long get = n / l , diff = r - l , m = n % l ; if ( diff * get >= m ) out . println ( "" Yes "" ) ; else out . println ( "" No "" ) ; } } } } ","class CodeforcesTask397BSolution : def __init__ ( self ) : self . result = ' ' self . t = 0 self . queries = [ ]   def read_input ( self ) : self . t = int ( input ( ) ) for _ in range ( self . t ) : self . queries . append ( [ int ( x ) for x in input ( ) . split ( "" ▁ "" ) ] )   def process_task ( self ) : res = [ ] for query in self . queries : k = query [ 0 ] // query [ 1 ] res . append ( "" Yes "" if k * query [ 2 ] >= query [ 0 ] else "" No "" ) self . result = "" \n "" . join ( res )   def get_result ( self ) : return self . result     if __name__ == "" _ _ main _ _ "" : Solution = CodeforcesTask397BSolution ( ) Solution . read_input ( ) Solution . process_task ( ) print ( Solution . get_result ( ) ) NEW_LINE " V276,"import java . io . * ; import java . util . * ; public class Ishu { static Scanner scan = new Scanner ( System . in ) ; static void tc ( ) { int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; long sum = 0l ; int [ ] a = new int [ n ] ; int i , j ; int [ ] oper = new int [ n ] ;   for ( i = 0 ; i < n ; ++ i ) { a [ i ] = scan . nextInt ( ) ; sum += a [ i ] ; } int last = a [ n - 1 ] ; int cur = n ; double ans = 0.0 ; Arrays . sort ( a , 0 , n ) ; i = 0 ; j = n - 1 ; int temp = m ; while ( m > 0 && i <= j ) { if ( cur == 1 ) { ans = a [ n - 1 ] + Math . min ( k - oper [ n - 1 ] , m ) ; break ; } double one = ( sum - a [ i ] ) / ( double ) ( cur - 1 ) ; double two = ( sum + 1 ) / ( double ) ( cur ) ; if ( one >= two ) { sum -= a [ i ++ ] ; cur -- ; ans = one ; } else { sum ++ ; a [ j ] ++ ; oper [ j ] ++ ; if ( oper [ j ] == k ) -- j ; ans = two ; } m -- ; } if ( temp >= n ) { temp -= n - 1 ; temp = Math . min ( temp , k ) ; ans = Math . max ( ans , temp + last ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int t = 1 ; ","n , p , t = map ( int , input ( ) . split ( ) ) arr = sorted ( map ( int , input ( ) . split ( ) ) ) arr = [ 0 ] + arr [ : : - 1 ] for i in range ( 1 , n + 1 ) : arr [ i ] += arr [ i - 1 ] maxi = 0 count = 0 for i in range ( n , 0 , - 1 ) : if ( t == - 1 ) : break maxi = max ( maxi , ( arr [ i ] + max ( 0 , min ( i * p , t ) ) ) / i ) t -= 1 print ( maxi ) NEW_LINE " V277,"import java . util . Scanner ;   public class A1463 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int C = in . nextInt ( ) ; int sum = A + B + C ; boolean possible = ( sum % 9 == 0 ) && Math . min ( Math . min ( A , B ) , C ) >= sum / 9 ; System . out . println ( possible ? "" YES "" : "" NO "" ) ; } }   } ","from collections import Countert = int ( input ( ) ) NEW_LINE for _ in range ( t ) : a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE q = a + b + c NEW_LINE e = min ( a , b , c ) NEW_LINE w = q // 9 NEW_LINE if ( q % 9 == 0 and e >= w ) : NEW_LINE INDENT print ( "" YES "" ) else : NEW_LINE print ( "" NO "" ) NEW_LINE DEDENT " V278,"import java . util . * ; import java . util . Scanner ; import java . io . * ; import javax . lang . model . util . ElementScanner6 ; import static java . lang . System . out ; import java . util . Stack ; import java . util . Queue ; import java . util . LinkedList ;   public class B463M2 {   static int mod = ( int ) ( 1e9 + 7 ) ; static long MOD = ( long ) ( 1e9 + 7 ) ; static FastReader in = new FastReader ( ) ; static PrintWriter pr = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; public static void main ( String args [ ] ) {   int tc = 1 ; ","n = input ( ) arr = [ int ( i ) for i in input ( ) . split ( ) ]   print ( max ( arr ) ) NEW_LINE " V279,"import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   ","inp = lambda : map ( int , input ( ) . split ( ) ) n , m , k = inp ( )   data = [ ( 0 , 0 , i ) for i in range ( n + m ) ]   for i in range ( k ) : query , id , color = inp ( ) if query == 1 : data [ id - 1 ] = ( i , color , id - 1 ) else : data [ id - 1 + n ] = ( i , color , id - 1 + n )   data . sort ( ) field = [ [ 0 ] * m for _ in range ( n ) ]     for _ , color , id in data : if color != 0 : if id < n : for i in range ( m ) : field [ id ] [ i ] = color else : for i in range ( n ) : field [ i ] [ id - n ] = color   for i in range ( n ) : print ( * field [ i ] ) NEW_LINE " V280,"import java . util . Scanner ;   public class A1426 { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { int n = scanner . nextInt ( ) , x = scanner . nextInt ( ) , l ; if ( n == 1 || n == 2 ) { System . out . println ( 1 ) ; } if ( n > 2 ) { l = ( n - 2 ) / x ; if ( ( n - 2 ) % x == 0 ) { l ++ ; } else if ( ( n - 2 ) % x != 0 ) { l += 2 ; } System . out . println ( l ) ; } } } } ","from math import ceilt = int ( input ( ) ) NEW_LINE for x in range ( t ) : a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == 1 or a == 2 : print ( 1 ) NEW_LINE continue NEW_LINE a -= 2 NEW_LINE print ( ceil ( a / b ) + 1 ) NEW_LINE " V281,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; public class div3_praca { ","from sys import stdin , stdoutimport math , bisectfrom collections import Counter , deque , defaultdictL = lambda : list ( map ( int , stdin . readline ( ) . strip ( ) . split ( ) ) ) M = lambda : map ( int , stdin . readline ( ) . strip ( ) . split ( ) ) I = lambda : int ( stdin . readline ( ) . strip ( ) ) S = lambda : stdin . readline ( ) . strip ( ) C = lambda : stdin . readline ( ) . strip ( ) . split ( ) def pr ( a ) : return ( "" ▁ "" . join ( list ( map ( str , a ) ) ) ) NEW_LINE " V282,"import java . io . * ; import java . util . * ; import java . util . List ;   public class AA implements Runnable { static int mod9 = 1000000007 ; public void run ( ) { InputReader sc = new InputReader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int i = 0 , j = 0 , k = 0 ; int t = 0 ; ","n , x1 , y1 , x2 , y2 = map ( int , input ( ) . split ( ) ) NEW_LINE d = { }   if x1 == 0 : d [ ( x1 , y1 ) ] = 1 NEW_LINE if x1 == n : d [ ( x1 , y1 ) ] = - 1 NEW_LINE if x2 == 0 : d [ ( x2 , y2 ) ] = 1 NEW_LINE if x2 == n : d [ ( x2 , y2 ) ] = - 1 NEW_LINE if y1 == 0 : d [ ( x1 , y1 ) ] = 2 NEW_LINE if y1 == n : d [ ( x1 , y1 ) ] = - 2 NEW_LINE if y2 == 0 : d [ ( x2 , y2 ) ] = 2 NEW_LINE if y2 == n : d [ ( x2 , y2 ) ] = - 2   if abs ( abs ( d [ ( x1 , y1 ) ] ) - abs ( d [ ( x2 , y2 ) ] ) ) == 1 : NEW_LINE INDENT print ( min ( 4 * n - ( abs ( x1 - x2 ) + abs ( y1 - y2 ) ) , ( abs ( x1 - x2 ) + abs ( y1 - y2 ) ) ) ) elif ( x1 == 0 and x2 == n ) or ( x1 == n and x2 == 0 ) : NEW_LINE print ( min ( 4 * n - ( y1 + y2 + n ) , y1 + y2 + n ) ) elif ( y1 == 0 and y2 == n ) or ( y1 == n and y2 == 0 ) : NEW_LINE print ( min ( 4 * n - ( x1 + x2 + n ) , x1 + x2 + n ) ) elif ( x1 == 0 and x2 == 0 ) or ( x1 == n and x2 == n ) : NEW_LINE print ( abs ( y2 - y1 ) ) elif ( y1 == 0 and y2 == 0 ) or ( y1 == n and y2 == n ) : NEW_LINE print ( abs ( x2 - x1 ) ) NEW_LINE DEDENT " V283,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . * ;   import javafx . util . Pair ;   public class Main {   public static void main ( String [ ] args ) {   FastScanner input = new FastScanner ( ) ; int n = input . nextInt ( ) ; String s = input . next ( ) ; int letter [ ] = new int [ 26 ] ; int max = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) >= ' A ' && s . charAt ( i ) <= ' Z ' ) { count = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( letter [ j ] > 0 ) count ++ ; } Arrays . fill ( letter , 0 ) ; max = Math . max ( max , count ) ; } else { letter [ s . charAt ( i ) - ' a ' ] ++ ; } } count = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( letter [ j ] > 0 ) count ++ ; } max = Math . max ( max , count ) ; System . out . println ( max ) ;   }   static class FastScanner {   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 ( ) ) ; }   long nextLong ( ) {   return Long . parseLong ( next ( ) ) ; }   double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; }   String nextLine ( ) throws IOException { return br . readLine ( ) ; } }   } ","n = input ( ) s = str ( input ( ) ) a = set ( ) res = 0 for i in s : if i . islower ( ) : a . add ( i ) res = max ( res , len ( a ) ) else : a . clear ( ) print ( res ) NEW_LINE " V284,"import java . io . * ; import java . util . * ; public class Ishu { static Scanner scan = new Scanner ( System . in ) ; static void tc ( ) { long x = scan . nextLong ( ) ; long [ ] a = new long [ 100001 ] ; int i ; for ( i = 1 ; i <= 100000 ; ++ i ) a [ i ] = ( ( ( long ) ( i ) ) * ( i + 1 ) ) / 2 ; if ( x < 0 ) x *= ( - 1 ) ; int ans = 0 ; for ( i = 0 ; i < 100001 ; ++ i ) { if ( a [ i ] >= x ) { ans = i ; break ; } } ","x = abs ( int ( input ( ) ) ) k , s , i = 0 , 0 , 1 while s < x or ( s - x ) % 2 == 1 : s += i i += 1 print ( i - 1 ) NEW_LINE " V285,"import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { PrintWriter out ; FastReader sc ; long mod = ( long ) ( 1e9 + 7 ) ; long maxlong = Long . MAX_VALUE ; long minlong = Long . MIN_VALUE ; public void sol ( ) { int [ ] ar = new int [ 4 ] ; int sum = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { ar [ i ] = ni ( ) ; sum += ar [ i ] ; } sort ( ar ) ; if ( ( sum - ar [ 3 ] ) == ar [ 3 ] || ( ar [ 0 ] + ar [ 3 ] ) == ( ar [ 1 ] + ar [ 2 ] ) ) yes ( ) ; else no ( ) ; } public static void main ( String [ ] args ) { Main g = new Main ( ) ; g . out = new PrintWriter ( System . out ) ; g . sc = new FastReader ( ) ; int t = 1 ; ","def string_to_list ( s , char ) : collector = "" "" output_list = [ ] for i in range ( len ( s ) ) : if s [ i ] != char : collector += s [ i ] if i == len ( s ) - 1 : output_list . append ( int ( collector ) ) else : output_list . append ( int ( collector ) ) collector = "" "" return output_list     NEW_LINE " V286,"import java . io . * ; import java . util . * ; import java . math . * ; ","from collections import Counter   def solve ( ) : str1 = input ( ) str2 = input ( ) count , j = 1 , 0   for i in range ( len ( str2 ) ) : if str1 [ j ] == str2 [ i ] : count += 1 j += 1   return count         print ( solve ( ) ) NEW_LINE " V287,"import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ;   public class Wrath {   public static void main ( String [ ] args ) throws IOException {   BufferedReader ob = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( ob . readLine ( ) ) ; String s [ ] = ob . readLine ( ) . split ( "" ▁ "" ) ; int a [ ] = new int [ n ] ; for ( int i = 0 , j = n - 1 ; i < n ; i ++ , j -- ) { a [ i ] = Integer . parseInt ( s [ j ] ) ; } int count = 0 ; for ( int i = 0 ; i < n ; ) { int x = a [ i ] ; if ( x == 0 ) { i ++ ; continue ; } int y = i ; for ( int j = a [ i ] ; j >= 0 && i < n ; j -- , i ++ ) { if ( i == y ) continue ; int temp = a [ i ] ; j = Math . max ( temp , j ) ; count ++ ; } } System . out . println ( n - count ) ; } } ","n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) ans = 0 x = nfor i in range ( n - 1 , - 1 , - 1 ) : if ( i < x ) : ans += 1 x = min ( x , i - l [ i ] ) print ( ans ) NEW_LINE " V288,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . PriorityQueue ; import java . util . Random ; import java . util . StringTokenizer ; import java . util . TreeSet ;   public class A {   public static void main ( String [ ] args ) throws IOException {   FastScanner sc = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; TreeSet < Long > set = new TreeSet < Long > ( ) ; int k = sc . nextInt ( ) ; ArrayList < Long > lis = new ArrayList < Long > ( ) ; lis . add ( 1L ) ; for ( int i = 1 ; i <= 100 ; i ++ ) { long sum = 0 ; int min = max ( 0 , i - k ) ; for ( int j = min ; j < i ; j ++ ) sum += lis . get ( j ) ; lis . add ( sum ) ; } ","s , k = map ( int , input ( ) . split ( ) ) f = [ 0 ] f . append ( 1 ) while ( True ) : cur = sum ( f [ - k : ] ) if cur > s : break f . append ( cur ) f = list ( set ( f ) ) f . sort ( ) ans = [ ] i = len ( f ) - 1 while ( s and i > 0 ) : if f [ i ] <= s : s -= f [ i ] ans . append ( f [ i ] ) i -= 1 print ( len ( ans ) + 1 ) print ( * ( ans + [ 0 ] ) ) NEW_LINE " V289,"import java . util . * ;   public class ICPC { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int counta = 0 ; int countB = 0 ; int countb = 0 ; int countu = 0 ; int counts = 0 ; int countl = 0 ; int countr = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; if ( ch == ' a ' ) { counta ++ ; } else if ( ch == ' B ' ) { countB ++ ; } else if ( ch == ' b ' ) { countb ++ ; } else if ( ch == ' u ' ) { countu ++ ;   } else if ( ch == ' s ' ) { counts ++ ; } else if ( ch == ' l ' ) { countl ++ ; } else if ( ch == ' r ' ) { countr ++ ; }   } if ( counta >= 2 && countB > 0 && countb > 0 && countl > 0 && countr > 0 && counts > 0 && countu >= 2 ) { int [ ] ar = { countB , countb , countl , counts , countr , counta / 2 , countu / 2 } ; Arrays . sort ( ar ) ; System . out . println ( ar [ 0 ] ) ; } else { System . out . println ( 0 ) ; }      }      static int countSetBits ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; }   public List < Integer > getDivisors ( int n ) { List < Integer > list = new ArrayList < > ( ) ; for ( int d = 2 ; d * d <= n ; d ++ ) { while ( n % d == 0 ) { list . add ( d ) ; n /= d ; } } if ( n > 1 ) { list . add ( n ) ; } return list ; }   public int lcm ( int n1 , int n2 ) { int gcd = 1 ; for ( int i = 1 ; i <= n1 && i <= n2 ; ++ i ) { ","def solve ( s ) : d = { ' B ' : 0 , ' u ' : 0 , ' l ' : 0 , ' b ' : 0 , ' a ' : 0 , ' u ' : 0 , ' r ' : 0 , ' s ' : 0 } for c in s : if c in ' Bulbbasaur ' : d [ c ] += 1 min_val = 1000000000 l = [ ' a ' , ' u ' ] for i in d : if not d [ i ] : return 0 if d [ ' a ' ] < 2 or d [ ' u ' ] < 2 : return 0 if i in l and d [ i ] // 2 < min_val : min_val = d [ i ] // 2 if d [ i ] < min_val : min_val = d [ i ] return min_val   def main ( ) : NEW_LINE " V290,"   import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . math . BigInteger ; import java . util . * ;    public class Main { public static void main ( String [ ] args ) throws IOException { File f1 = new File ( "" input . txt "" ) ; File f2 = new File ( "" output . txt "" ) ; Scanner input = new Scanner ( f1 ) ; FileWriter output = new FileWriter ( f2 ) ; int n = input . nextInt ( ) ; String s = input . next ( ) ; char ch [ ] = s . toCharArray ( ) ; int L = 0 ; int R = 0 ; for ( int i = 0 , j = s . length ( ) / 2 ; i < s . length ( ) / 2 ; i ++ , j ++ ) { if ( ch [ i ] == ' L ' && ch [ j ] == ' L ' ) { output . write ( ( i + 1 ) + "" ▁ "" + ( j + 1 ) + "" \n "" ) ; } else if ( ch [ i ] == ' L ' && ch [ j ] == ' R ' ) { output . write ( ( i + 1 ) + "" ▁ "" + ( j + 1 ) + "" \n "" ) ; } else if ( ch [ i ] == ' R ' && ch [ j ] == ' R ' ) { output . write ( ( i + 1 ) + "" ▁ "" + ( j + 1 ) + "" \n "" ) ; } else { output . write ( ( j + 1 ) + "" ▁ "" + ( i + 1 ) + "" \n "" ) ; } } output . close ( ) ; } }   ","s = open ( ' input . txt ' ) . readlines ( ) [ 1 ] ; n = len ( s ) // 2 for i in range ( n ) : print ( * [ i + 1 + n , i + 1 ] [ : : 2 * ( s [ i ] > ' L ' ) - 1 ] , file = open ( ' output . txt ' , ' a ' ) ) NEW_LINE " V291,"import java . util . * ; import java . io . * ; ","start , end , k = input ( ) , input ( ) , int ( input ( ) ) n , mod = len ( end ) , 10 ** 9 + 7 dp = [ 1 , 0 ] psum = 1 for i in range ( k ) : dp [ 0 ] = psum - dp [ 0 ] dp [ 1 ] = psum - dp [ 1 ] psum = ( dp [ 0 ] + ( ( n - 1 ) * dp [ 1 ] ) % mod ) % modans = 0 for i in range ( n ) : if start [ i : ] + start [ : i ] == end : if i == 0 : ans += dp [ 0 ] else : ans += dp [ 1 ] print ( ans % mod ) NEW_LINE " V292,"import java . io . * ; import java . util . * ; public class MyClass { public static void main ( String args [ ] ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String s [ ] = br . readLine ( ) . split ( "" ▁ "" ) ; int count = 0 ; int max = Integer . parseInt ( s [ 0 ] ) ; int min = Integer . parseInt ( s [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { int val = Integer . parseInt ( s [ i ] ) ; if ( val > max ) { max = val ; count ++ ; } if ( val < min ) { min = val ; count ++ ; } } System . out . println ( count ) ; } } ","n = int ( input ( ) ) p = input ( ) list = p . split ( "" ▁ "" ) for i in range ( 0 , n ) : list [ i ] = int ( list [ i ] ) l = 0 h = 0 max = list [ 0 ] min = list [ 0 ] for i in range ( 1 , n ) : if list [ i ] > max : max = list [ i ] h = h + 1 if list [ i ] < min : min = list [ i ] l = l + 1 print ( l + h ) NEW_LINE " V293,"import java . util . * ; public class General { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int count = 0 ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = s . nextInt ( ) ; } int min = arr [ 0 ] ; int index1 = 0 ; int max = arr [ 0 ] ; int index2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { max = arr [ i ] ; index2 = i ; } else if ( arr [ i ] == max ) { if ( index2 > i ) { index2 = i ; } } if ( arr [ i ] < min ) { min = arr [ i ] ; index1 = i ; } else if ( arr [ i ] == min ) { if ( index1 < i ) { index1 = i ; } } } if ( n == 1 ) { System . out . println ( count ) ; } else { count = index2 + ( ( n - 1 ) - index1 ) ; if ( index1 < index2 ) { count -- ; } System . out . println ( count ) ; } } } ","n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) mxi = a . index ( max ( a ) ) a . reverse ( ) mni = n - 1 - a . index ( min ( a ) ) res = mxi + n - 1 - mniif mxi > mni : res -= 1 print ( res ) NEW_LINE " V294,"  import java . util . * ; import java . lang . * ; import java . io . * ;   public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner in = new Scanner ( System . in ) ; double MOD = 1e9 + 7 ; long n = in . nextInt ( ) ; int [ ] [ ] m = new int [ ( int ) n + 2 ] [ ( int ) n + 2 ] ; m [ 1 ] [ 1 ] = 1 ; for ( int i = 2 ; i < n + 2 ; i ++ ) { m [ i ] [ 1 ] = m [ i - 1 ] [ i - 1 ] ; for ( int j = 2 ; j <= i ; j ++ ) m [ i ] [ j ] = ( int ) ( ( m [ i ] [ j - 1 ] + m [ i - 1 ] [ j - 1 ] ) % MOD ) ; } System . out . println ( m [ ( int ) ( n + 1 ) ] [ ( int ) n ] ) ; } } ","n = int ( input ( ) ) + 1 d = 1000000007 g = [ [ 1 ] * n for i in range ( n ) ] for i in range ( 1 , n ) : g [ i ] [ 0 ] = g [ i - 1 ] [ i - 1 ] for j in range ( 1 , i + 1 ) : g [ i ] [ j ] = ( g [ i ] [ j - 1 ] + g [ i - 1 ] [ j - 1 ] ) % dprint ( ( g [ - 1 ] [ - 1 ] - g [ - 1 ] [ 0 ] ) % d ) NEW_LINE " V295,"  import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; public class er10a { ",""""""" def ▁ main ( ) : ▁ ▁ ▁ ▁ t ▁ = ▁ int ( input ( ) ) ▁ ▁ ▁ ▁ for ▁ _ ▁ in ▁ range ( t ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ n , m ▁ = ▁ sep ( ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ a = list ( sep ( ) ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ b = list ( sep ( ) ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ans = 0 ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ a ▁ = ▁ sorted ( a , reverse = True ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ for ▁ i ▁ in ▁ range ( n ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ a [ i ] > = i + 1 : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ans + = b [ i ] ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ else : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ans + = b [ a [ i ] -1 ] ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( ans ) if ▁ _ _ name _ _ ▁ = = ▁ ' _ _ main _ _ ' : ▁ ▁ ▁ ▁ main ( ) """"""   """""" def ▁ main ( ) : ▁ ▁ ▁ ▁ n = int ( input ( ) ) ▁ ▁ ▁ ▁ x ▁ = ▁ int ( input ( ) ) ▁ ▁ ▁ ▁ p = 7 - x ▁ ▁ ▁ ▁ for ▁ i ▁ in ▁ range ( n ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ c ▁ = ▁ list ( sep ( ) ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ x ▁ in ▁ c ▁ or ▁ p ▁ in ▁ c : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( "" NO "" ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ break ▁ ▁ ▁ ▁ else : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( "" YES "" ) if ▁ _ _ name _ _ ▁ = = ▁ ' _ _ main _ _ ' : ▁ ▁ ▁ ▁ main ( ) """""" """""" def ▁ main ( ) : ▁ ▁ ▁ ▁ s , k ▁ = ▁ sep ( ) ▁ ▁ ▁ ▁ a = [ 0,1 ] ▁ ▁ ▁ ▁ ans = [ ] ▁ ▁ ▁ ▁ # print ( ans ) ▁ ▁ ▁ ▁ while ( a [ -1 ] < s ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ a . append ( sum ( a [ - k : ] ) ) ▁ ▁ ▁ ▁ a . reverse ( ) ▁ ▁ ▁ ▁ # print ( list ( a ) ) ▁ ▁ ▁ ▁ for ▁ i ▁ in ▁ a : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ i < = s : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ans . append ( i ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ s - = i ▁ ▁ ▁ ▁ print ( len ( ans ) ) ▁ ▁ ▁ ▁ print ( * ans ) if ▁ _ _ name _ _ ▁ = = ▁ ' _ _ main _ _ ' : ▁ ▁ ▁ ▁ main ( ) """"""   def sep ( ) : return map ( int , input ( ) . split ( ) ) """""" def ▁ main ( ) : ▁ ▁ ▁ ▁ n ▁ = ▁ int ( input ( ) ) ▁ ▁ ▁ ▁ a ▁ = ▁ list ( sep ( ) ) ▁ ▁ ▁ ▁ d ▁ = ▁ { } ▁ ▁ ▁ ▁ f ▁ = ▁ True ▁ ▁ ▁ ▁ for ▁ i ▁ in ▁ range ( n ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ ( f ▁ = = ▁ False ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ break ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ for ▁ j ▁ in ▁ range ( i ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ # ▁ print ( d )   ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ ( a [ i ] ▁ + ▁ a [ j ] ▁ in ▁ d ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ii , ▁ jj ▁ = ▁ d [ a [ i ] ▁ + ▁ a [ j ] ] ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ ( len ( set ( [ i , ▁ j , ▁ ii , ▁ jj ] ) ) ▁ = = ▁ 4 ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( ' YES ' ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ f ▁ = ▁ False ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( i ▁ + ▁ 1 , ▁ j ▁ + ▁ 1 , ▁ ii ▁ + ▁ 1 , ▁ jj ▁ + ▁ 1 ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ break ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ else : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ d [ a [ i ] ▁ + ▁ a [ j ] ] ▁ = ▁ ( i , ▁ j )   ▁ ▁ ▁ ▁ if ▁ ( f ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( ' NO ' ) if ▁ _ _ name _ _ ▁ = = ▁ ' _ _ main _ _ ' : ▁ ▁ ▁ ▁ main ( ) """""" """""" def ▁ main ( ) : ▁ ▁ ▁ ▁ s = input ( ) ▁ ▁ ▁ ▁ d = { } ▁ ▁ ▁ ▁ i = - 1 ▁ ▁ ▁ ▁ for ▁ _ ▁ in ▁ range ( 10 ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ i + = 1 ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ t ▁ = ▁ input ( ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ d [ t ] = i ▁ ▁ ▁ ▁ # print ( d ) ▁ ▁ ▁ ▁ j = 0 ▁ ▁ ▁ ▁ while ( j < 80 ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( d [ s [ j : 10 + j ] ] , end = "" "" ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ j + = 10if ▁ _ _ name _ _ ▁ = = ▁ ' _ _ main _ _ ' : ▁ ▁ ▁ ▁ main ( ) """""" import mathdef prime ( x ) : if x == 1 : return False else : for i in range ( 2 , int ( math . sqrt ( x ) ) + 1 ) : if ( x % i == 0 ) : return False else : return Truedef main ( ) : n , a , b = sep ( ) n = 6 * n flag = 0 if a > b : flag = 1 a , b = min ( a , b ) , max ( a , b ) ans = ( a , b ) tans = 1e12 if a * b < n : for l in range ( a , int ( n ** 0.5 ) + 2 ) : tmp = l * math . ceil ( n / l ) if tans > tmp and math . ceil ( n / l ) >= b : tans = tmp ans = ( l , math . ceil ( n / l ) ) else : pass print ( ans [ 0 ] * ans [ 1 ] ) if flag == 1 : print ( ans [ 1 ] , ans [ 0 ] ) else : print ( ans [ 0 ] , ans [ 1 ] ) if __name__ == ' _ _ main _ _ ' : main ( ) NEW_LINE " V296,"import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ;   public class Main { public static int [ ] arr = new int [ 150000 + 1 ] ; public static int find ( int i ) { return arr [ i ] == i ? i : ( arr [ i ] = find ( arr [ i ] ) ) ; } public static void merge ( int x , int y ) { int xp = find ( x ) ; int yp = find ( y ) ; arr [ yp ] = xp ; }   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; int [ ] count = new int [ n + 1 ] ; long [ ] p = new long [ n + 1 ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = i ; } List < Integer > lines = new LinkedList < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int x = scanner . nextInt ( ) ; int y = scanner . nextInt ( ) ; lines . add ( x ) ; merge ( x , y ) ; } for ( Integer x : lines ) { count [ find ( x ) ] += 1 ; } for ( int i = 0 ; i < n + 1 ; i ++ ) { p [ find ( i ) ] += 1 ; } for ( int i = 0 ; i < n + 1 ; i ++ ) { if ( i == find ( i ) ) { if ( p [ i ] * ( p [ i ] - 1 ) / 2 != count [ i ] ) { System . out . println ( "" NO "" ) ; return ; } } } System . out . println ( "" YES "" ) ;   } } ","import sysfrom math import sqrt , gcd , ceil , log NEW_LINE " V297,"import java . util . Scanner ;   public class NewMain {   public static void main ( String [ ] args ) { ","if __name__ == ' _ _ main _ _ ' : s = input ( ) d = [ 2 , 7 , 2 , 3 , 3 , 4 , 2 , 5 , 1 , 2 ] print ( d [ int ( s [ 0 ] ) ] * d [ int ( s [ 1 ] ) ] ) NEW_LINE " V298,"import java . util . Scanner ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class question { public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int n , k , p , x , y , flag = 0 ; List < Integer > arrtest = new ArrayList < > ( ) ; List < Integer > solution = new ArrayList < > ( ) ; n = scan . nextInt ( ) ; k = scan . nextInt ( ) ; p = scan . nextInt ( ) ; x = scan . nextInt ( ) ; y = scan . nextInt ( ) ; for ( int i = 0 ; i < k ; i ++ ) { arrtest . add ( scan . nextInt ( ) ) ; } ","from sys import stdin , stdoutfrom collections import Counternmbr = lambda : int ( input ( ) ) lst = lambda : list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( 1 ) : NEW_LINE " V299,"import java . util . * ; public class XeniaandDivisors {   public static void main ( String [ ] args ) { ","n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) if 5 not in l and 7 not in l : try : if 2 in l and 4 not in l and 6 not in l : raise Exception if l . count ( 1 ) != n // 3 or l . count ( 4 ) > l . count ( 2 ) : raise Exception if l . count ( 3 ) > l . count ( 6 ) or l . count ( 2 ) + l . count ( 3 ) != l . count ( 4 ) + l . count ( 6 ) : raise Exception except Exception as e : print ( - 1 ) else : if l . count ( 3 ) != 0 : for j in range ( l . count ( 3 ) ) : print ( 1 , 3 , 6 ) for j in range ( l . count ( 6 ) - l . count ( 3 ) ) : print ( 1 , 2 , 6 ) for j in range ( l . count ( 2 ) - l . count ( 6 ) + l . count ( 3 ) ) : print ( 1 , 2 , 4 ) else : for j in range ( l . count ( 6 ) ) : print ( 1 , 2 , 6 ) for j in range ( l . count ( 2 ) - l . count ( 6 ) ) : print ( 1 , 2 , 4 ) else : print ( - 1 ) NEW_LINE " V300,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ;   public class CF1343A { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int t = Integer . parseInt ( br . readLine ( ) ) ; while ( t -- > 0 ) { long n = Long . parseLong ( br . readLine ( ) ) ; for ( int k = 29 ; k > 1 ; k -- ) { int num = ( int ) Math . pow ( 2 , k ) - 1 ; if ( ( n % num ) == 0 ) { System . out . println ( String . format ( "" % s "" , n / num ) ) ; break ; } } } } } ","from math import ceil , log2   for t in range ( int ( input ( ) ) ) : n = int ( input ( ) ) x = n for k in range ( 2 , ceil ( log2 ( n ) ) + 1 ) : if n % ( 2 ** k - 1 ) == 0 : x = n // ( 2 ** k - 1 ) break print ( x ) NEW_LINE " V301,"import java . io . * ; import java . util . * ;   public class Task1103B { private static InputReader in ; private static PrintWriter out ; private static boolean autoFlush = true ; static final int inf = ( int ) 1e9 + 7 ; static final long infL = ( long ) 1e18 + 7 ;   static class Testcase { public boolean ask ( int x , int y ) { int a = 1 ; boolean b = ( x % a < y % a ) ; out . println ( b ? "" y "" : "" x "" ) ; return b ; }   public boolean query ( int x , int y ) { ","import sys   def ask ( x , y ) : print ( f "" ? ▁ { x } ▁ { y } "" ) sys . stdin . flush ( ) ans = input ( ) if ans == "" e "" : exit ( ) return ans == "" y ""     while True : s = input ( ) if s == "" mistake "" or s == "" end "" : exit ( ) lower = 0 while ask ( lower , max ( 2 * lower , 1 ) ) : lower = max ( 1 , 2 * lower ) lo = lower hi = max ( 1 , lower * 2 ) while lo + 1 < hi : mid = ( lo + hi ) // 2 if ask ( lower , mid ) : lo = mid else : hi = mid print ( f "" ! ▁ { hi } "" ) NEW_LINE " V302,"import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . Vector ; public class NewClass1 { public static void main ( String [ ] args ) { Scanner ob = new Scanner ( System . in ) ; int t = ob . nextInt ( ) ; while ( t -- > 0 ) { int n = ob . nextInt ( ) ; int a [ ] = new int [ n ] ; int b [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = ob . nextInt ( ) ; b [ a [ i ] - 1 ] = i ; } int s ; int e = n ; for ( int i = a . length - 1 ; i >= 0 ; i -- ) { s = b [ i ] ; if ( s < e ) { for ( int j = s ; j < e ; j ++ ) { System . out . print ( a [ j ] + "" ▁ "" ) ; } e = s ; } } System . out . println ( ) ; } } } ","for s in [ * open ( 0 ) ] [ 2 : : 2 ] : NEW_LINE INDENT a = * map ( int , s . split ( ) ) , ; NEW_LINE i = 7 ** 6 NEW_LINE for x , j in sorted ( zip ( a , range ( i ) ) ) [ : : - 1 ] : print ( * a [ j : i ] ) ; i = min ( i , j ) NEW_LINE DEDENT " V303,"import java . io . * ; import java . util . * ; ","n , m = map ( int , input ( ) . split ( ) ) ; a = list ( map ( int , input ( ) . split ( ) ) ) ; p = 0 ; t = [ 0 ] * 3 for i in range ( n ) : if ( a [ i ] < a [ p ] ) : p = i if ( n == 2 ) : print ( '0 \n 1 ▁ 1 \n ' ) else : a . sort ( ) ; t [ 0 ] = min ( a [ 0 ] + a [ 1 ] + m , a [ 1 ] + a [ 2 ] ) ; t [ 1 ] = max ( a [ 0 ] + a [ n - 1 ] + m , a [ n - 2 ] + a [ n - 1 ] ) ; t [ 2 ] = ( a [ n - 2 ] + a [ n - 1 ] ) - ( a [ 0 ] + a [ 1 ] ) if ( t [ 1 ] - t [ 0 ] > t [ 2 ] ) : p = n else : t [ 2 ] = t [ 1 ] - t [ 0 ] print ( t [ 2 ] ) for i in range ( n ) : print ( int ( i == p ) + 1 , end = ' ▁ ' ) NEW_LINE " V304,"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . StringTokenizer ;   public class Solution { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; long [ ] dp = new long [ n + 1 ] ; Arrays . fill ( dp , Long . MAX_VALUE ) ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { StringTokenizer sToken = new StringTokenizer ( reader . readLine ( ) ) ; int t = Integer . parseInt ( sToken . nextToken ( ) ) ; int x = Integer . parseInt ( sToken . nextToken ( ) ) ; for ( int j = n ; j > - 1 ; j -- ) { if ( dp [ Math . max ( 0 , j - t - 1 ) ] == Long . MAX_VALUE ) continue ; dp [ j ] = Math . min ( dp [ j ] , dp [ Math . max ( 0 , j - t - 1 ) ] + x ) ; } } System . out . println ( dp [ n ] ) ; } } ","n = int ( input ( ) ) t , c = [ ] , [ ] for i in range ( n ) : tt , cc = list ( map ( int , input ( ) . split ( ) ) ) t . append ( tt ) c . append ( cc )   def find ( i : int , cnt : int ) -> int : if cnt >= n : return 0 if i == n : return int ( 1e18 ) return min ( find ( i + 1 , cnt ) , c [ i ] + find ( i + 1 , cnt + 1 + t [ i ] ) )   f = [ int ( 1e18 ) ] * ( n + 1 ) f [ 0 ] = 0 NEW_LINE " V305,"import java . util . * ; public class Sol { public static void main ( String args [ ] ) { Scanner ob = new Scanner ( System . in ) ; int m = ob . nextInt ( ) ; int t = 0 ; while ( m > 0 ) { if ( m >= 100 ) { m -= 100 ; t ++ ; continue ; } else if ( m >= 20 ) { m -= 20 ; t ++ ; continue ; } else if ( m >= 10 ) { m -= 10 ; t ++ ; continue ; } else if ( m >= 5 ) { m -= 5 ; t ++ ; continue ; } else { m -= 1 ; t ++ ; } } System . out . println ( t ) ; } } ","n = int ( input ( ) ) c = 0 ; while n > 0 : NEW_LINE " V306,"import java . util . Scanner ;   public class Parallelepiped { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int s1 = scanner . nextInt ( ) ; int s2 = scanner . nextInt ( ) ; int s3 = scanner . nextInt ( ) ; int a = ( int ) Math . sqrt ( ( s1 * s3 ) / s2 ) ; int b = ( int ) Math . sqrt ( ( s1 * s2 ) / s3 ) ; int c = ( int ) Math . sqrt ( ( s2 * s3 ) / s1 ) ; System . out . println ( 4 * ( a + b + c ) ) ; } } ","import math as mpdef parallelepiped ( areas ) : a = areas [ 0 ] / areas [ 1 ] b2 = mp . sqrt ( areas [ 2 ] / a ) a1 = areas [ 1 ] / b2 b1 = areas [ 0 ] / a1 edge_sum = ( 4 * a1 ) + ( 4 * b1 ) + ( 4 * b2 ) return ( int ( edge_sum ) )   areas = list ( map ( int , input ( ) . split ( ) ) ) result = parallelepiped ( areas ) print ( result ) NEW_LINE " V307,"import java . util . * ; import java . math . * ; public class KsenaiPan { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] arr = sc . next ( ) . toCharArray ( ) ; ArrayList < Character > l = new ArrayList < > ( ) ; ArrayList < Character > r = new ArrayList < > ( ) ; boolean fl = false ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == ' | ' ) fl = true ; else { if ( ! fl ) { l . add ( arr [ i ] ) ; } else r . add ( arr [ i ] ) ; } } char [ ] in = sc . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < in . length ; i ++ ) { if ( l . size ( ) < r . size ( ) ) l . add ( in [ i ] ) ; else r . add ( in [ i ] ) ; } if ( l . size ( ) == r . size ( ) ) { for ( char out : l ) System . out . print ( out ) ; System . out . print ( "" | "" ) ; for ( char out : r ) System . out . print ( out ) ; } else System . out . println ( "" Impossible "" ) ; } } ","a , b = input ( ) . split ( ' | ' ) c = input ( ) for i in range ( len ( c ) ) : if len ( a ) <= len ( b ) : a += c [ i ] elif len ( a ) > len ( b ) : b += c [ i ] if len ( a ) == len ( b ) : print ( a + ' | ' + b ) else : print ( ' Impossible ' ) NEW_LINE " V308,"import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 || b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } static int cpFact ( int x , int y ) { while ( gcd ( x , y ) != 1 ) { x = x / gcd ( x , y ) ; } return x ; } public static void main ( String [ ] args ) { int x = 15 ; int y = 3 ; System . out . println ( cpFact ( x , y ) ) ; x = 14 ; y = 28 ; System . out . println ( cpFact ( x , y ) ) ; x = 7 ; y = 3 ; System . out . println ( cpFact ( x , y ) ) ; } } ","def gcd ( a , b ) : NEW_LINE INDENT if a == 0 or b == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if a == b : NEW_LINE INDENT return a NEW_LINE DEDENT if a > b : NEW_LINE INDENT return gcd ( a - b , b ) NEW_LINE DEDENT return gcd ( a , b - a ) NEW_LINE DEDENT def cpFact ( x , y ) : NEW_LINE INDENT while gcd ( x , y ) != 1 : NEW_LINE INDENT x = x / gcd ( x , y ) NEW_LINE DEDENT return int ( x ) NEW_LINE DEDENT x = 15 NEW_LINE y = 3 NEW_LINE print ( cpFact ( x , y ) ) NEW_LINE x = 14 NEW_LINE y = 28 NEW_LINE print ( cpFact ( x , y ) ) NEW_LINE x = 7 NEW_LINE y = 3 NEW_LINE print ( cpFact ( x , y ) ) NEW_LINE " V309,"import java . io . * ; import java . util . * ; class GFG { static long powerNumbers ( int n ) { HashSet < Long > v = new HashSet < Long > ( ) ; for ( long i = 2 ; i * i * i <= n ; i ++ ) { long j = i * i ; while ( j * i <= n ) { j *= i ; long s = ( long ) Math . sqrt ( j ) ; if ( s * s != j ) v . add ( j ) ; } } return v . size ( ) + ( long ) Math . sqrt ( n ) ; } public static void main ( String args [ ] ) { System . out . print ( powerNumbers ( 50 ) ) ; } } ","import math NEW_LINE def powerNumbers ( n ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( 2 , int ( math . pow ( n , 1.0 / 3.0 ) ) + 1 ) : NEW_LINE INDENT j = i * i NEW_LINE while ( j * i <= n ) : NEW_LINE INDENT j = j * i NEW_LINE s = int ( math . sqrt ( j ) ) NEW_LINE if ( s * s != j ) : NEW_LINE INDENT v . append ( j ) NEW_LINE DEDENT DEDENT DEDENT v . sort ( ) NEW_LINE v = list ( dict . fromkeys ( v ) ) NEW_LINE return len ( v ) + int ( math . sqrt ( n ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( powerNumbers ( 50 ) ) NEW_LINE DEDENT " V310,"import java . util . * ; class GFG { static void nPermute ( char [ ] str , int n ) { Arrays . sort ( str ) ; int i = 1 ; do { if ( i == n ) break ; i ++ ; } while ( next_permutation ( str ) ) ; System . out . println ( String . valueOf ( str ) ) ; } static boolean next_permutation ( char [ ] p ) { for ( int a = p . length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { char t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void main ( String [ ] args ) { String str = "" GEEKSFORGEEKS "" ; int n = 100 ; nPermute ( str . toCharArray ( ) , n ) ; } } ","def next_permutation ( L ) : NEW_LINE INDENT n = len ( L ) NEW_LINE i = n - 2 NEW_LINE while i >= 0 and L [ i ] >= L [ i + 1 ] : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT if i == - 1 : NEW_LINE INDENT return False NEW_LINE DEDENT j = i + 1 NEW_LINE while j < n and L [ j ] > L [ i ] : NEW_LINE INDENT j += 1 NEW_LINE DEDENT j -= 1 NEW_LINE L [ i ] , L [ j ] = L [ j ] , L [ i ] NEW_LINE left = i + 1 NEW_LINE right = n - 1 NEW_LINE while left < right : NEW_LINE INDENT L [ left ] , L [ right ] = L [ right ] , L [ left ] NEW_LINE left += 1 NEW_LINE right -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def nPermute ( string , n ) : NEW_LINE INDENT string = list ( string ) NEW_LINE new_string = [ ] NEW_LINE string . sort ( ) NEW_LINE j = 2 NEW_LINE while next_permutation ( string ) : NEW_LINE INDENT new_string = string NEW_LINE if j == n : NEW_LINE INDENT break NEW_LINE DEDENT j += 1 NEW_LINE DEDENT print ( ' ' . join ( new_string ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" GEEKSFORGEEKS "" NEW_LINE n = 100 NEW_LINE nPermute ( string , n ) NEW_LINE DEDENT " V311,"import java . util . * ; class GFG { static int sz = ( int ) 1e3 ; static HashSet < Integer > fib = new HashSet < Integer > ( ) ; static void fibonacci ( ) { int prev = 0 , curr = 1 , len = 2 ; fib . add ( prev ) ; fib . add ( curr ) ; while ( len <= sz ) { int temp = curr + prev ; fib . add ( temp ) ; prev = curr ; curr = temp ; len ++ ; } } static void printArray ( int arr [ ] , int len ) { for ( int i = 0 ; i < len ; i ++ ) { System . out . print ( arr [ i ] + "" ▁ "" ) ; } } static void removeFibonacci ( int arr [ ] , int len ) { fibonacci ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( fib . contains ( arr [ i ] ) ) { for ( int j = i ; j < len - 1 ; j ++ ) { arr [ j ] = arr [ j + 1 ] ; } i -- ; len -- ; } } printArray ( arr , len ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 5 , 3 , 8 , 7 , 10 , 11 , 14 , 15 } ; int len = arr . length ; removeFibonacci ( arr , len ) ; } } ","sz = 1000 NEW_LINE fib = set ( ) NEW_LINE def fibonacci ( ) : NEW_LINE INDENT prev , curr , length = 0 , 1 , 2 NEW_LINE fib . add ( prev ) NEW_LINE fib . add ( curr ) NEW_LINE while ( length <= sz ) : NEW_LINE INDENT temp = curr + prev NEW_LINE fib . add ( temp ) NEW_LINE prev = curr NEW_LINE curr = temp NEW_LINE length += 1 NEW_LINE DEDENT DEDENT def printArray ( arr , length ) : NEW_LINE INDENT for i in range ( length ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT def removeFibonacci ( arr , length ) : NEW_LINE INDENT fibonacci ( ) NEW_LINE for i in fib : NEW_LINE INDENT if i in arr : NEW_LINE INDENT arr . remove ( i ) NEW_LINE length -= 1 NEW_LINE DEDENT DEDENT printArray ( arr , length ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 4 , 6 , 5 , 3 , 8 , 7 , 10 , 11 , 14 , 15 ] NEW_LINE length = len ( arr ) NEW_LINE removeFibonacci ( arr , length ) NEW_LINE DEDENT " V312,"class GFG { static long product ( int [ ] [ ] mat , int n ) { long d1 = 0 , d2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return 1L * d1 * d2 ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 5 , 8 , 1 } , { 5 , 10 , 3 } , { - 6 , 17 , - 9 } } ; int n = mat . length ; System . out . print ( product ( mat , n ) ) ; } } ","def product ( mat , n ) : NEW_LINE INDENT d1 = 0 NEW_LINE d2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT d1 += mat [ i ] [ i ] NEW_LINE d2 += mat [ i ] [ n - i - 1 ] NEW_LINE DEDENT return d1 * d2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 5 , 8 , 1 ] , [ 5 , 10 , 3 ] , [ - 6 , 17 , - 9 ] ] NEW_LINE n = len ( mat ) NEW_LINE print ( product ( mat , n ) ) NEW_LINE DEDENT " V313,"import java . util . * ; public class GfG { private static String remainingDigit ( String S , int N ) { char c [ ] = S . toCharArray ( ) ; int del [ ] = { 0 , 0 } ; int count [ ] = { 0 , 0 } ; Queue < Integer > q = new LinkedList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = c [ i ] == '1' ? 1 : 0 ; count [ x ] ++ ; q . add ( x ) ; } while ( count [ 0 ] > 0 && count [ 1 ] > 0 ) { int t = q . poll ( ) ; if ( del [ t ] > 0 ) { del [ t ] -- ; count [ t ] -- ; } else { del [ t ^ 1 ] ++ ; q . add ( t ) ; } } if ( count [ 0 ] > 0 ) return ""0"" ; return ""1"" ; } public static void main ( String args [ ] ) { String S = ""1010100100000"" ; int N = S . length ( ) ; System . out . print ( remainingDigit ( S , N ) ) ; } } ","from collections import deque ; NEW_LINE def remainingDigit ( S , N ) : NEW_LINE INDENT c = [ i for i in S ] NEW_LINE de = [ 0 , 0 ] NEW_LINE count = [ 0 , 0 ] NEW_LINE q = deque ( ) NEW_LINE for i in c : NEW_LINE INDENT x = 0 NEW_LINE if i == '1' : NEW_LINE INDENT x = 1 NEW_LINE DEDENT count [ x ] += 1 NEW_LINE q . append ( x ) NEW_LINE DEDENT while ( count [ 0 ] > 0 and count [ 1 ] > 0 ) : NEW_LINE INDENT t = q . popleft ( ) NEW_LINE if ( de [ t ] > 0 ) : NEW_LINE INDENT de [ t ] -= 1 NEW_LINE count [ t ] -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT de [ t ^ 1 ] += 1 NEW_LINE q . append ( t ) NEW_LINE DEDENT DEDENT if ( count [ 0 ] > 0 ) : NEW_LINE INDENT return ""0"" NEW_LINE DEDENT return ""1"" NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = ""1010100100000"" NEW_LINE N = len ( S ) NEW_LINE print ( remainingDigit ( S , N ) ) NEW_LINE DEDENT " V314,"import java . io . * ; import java . util . * ; class GFG { static void incrementVector ( Vector < Integer > a ) { int n = a . size ( ) ; a . set ( n - 1 , a . get ( n - 1 ) + 1 ) ; int carry = a . get ( n - 1 ) / 10 ; a . set ( n - 1 , a . get ( n - 1 ) % 10 ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( carry == 1 ) { a . set ( i , a . get ( i ) + 1 ) ; carry = a . get ( i ) / 10 ; a . set ( i , a . get ( i ) % 10 ) ; } } if ( carry == 1 ) a . add ( 0 , 1 ) ; } public static void main ( String [ ] args ) { Vector < Integer > vect = new Vector < Integer > ( ) ; vect . add ( 1 ) ; vect . add ( 7 ) ; vect . add ( 8 ) ; vect . add ( 9 ) ; incrementVector ( vect ) ; for ( int i = 0 ; i < vect . size ( ) ; i ++ ) System . out . print ( vect . get ( i ) + "" ▁ "" ) ; } } ","import math NEW_LINE def incrementVector ( a ) : NEW_LINE INDENT n = len ( a ) NEW_LINE a [ n - 1 ] += 1 NEW_LINE carry = a [ n - 1 ] / 10 NEW_LINE a [ n - 1 ] = a [ n - 1 ] % 10 NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( carry == 1 ) : NEW_LINE INDENT a [ i ] += 1 NEW_LINE carry = a [ i ] / 10 NEW_LINE a [ i ] = a [ i ] % 10 NEW_LINE DEDENT DEDENT if ( carry == 1 ) : NEW_LINE INDENT a . insert ( 0 , 1 ) NEW_LINE DEDENT DEDENT vect = [ 1 , 7 , 8 , 9 ] NEW_LINE incrementVector ( vect ) NEW_LINE for i in range ( 0 , len ( vect ) ) : NEW_LINE INDENT print ( vect [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT " V315,"import java . util . * ; class GFG { static int max_element ( int a [ ] ) { int m = a [ 0 ] ; for ( int i = 0 ; i < a . length ; i ++ ) m = Math . max ( a [ i ] , m ) ; return m ; } static int primeCount ( int arr [ ] , int n ) { int max_val = max_element ( arr ) ; boolean prime [ ] = new boolean [ max_val + 1 ] ; for ( int p = 0 ; p <= max_val ; p ++ ) prime [ p ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( prime [ arr [ i ] ] ) count ++ ; return count ; } static int [ ] getPrefixArray ( int arr [ ] , int n , int pre [ ] ) { pre [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } return pre ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 4 , 8 , 4 } ; int n = arr . length ; int pre [ ] = new int [ n ] ; pre = getPrefixArray ( arr , n , pre ) ; System . out . println ( primeCount ( pre , n ) ) ; } } ","def primeCount ( arr , n ) : NEW_LINE INDENT max_val = max ( arr ) NEW_LINE prime = [ True ] * ( max_val + 1 ) NEW_LINE prime [ 0 ] = prime [ 1 ] = False NEW_LINE p = 2 NEW_LINE while p * p <= max_val : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT for i in range ( p * 2 , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if prime [ arr [ i ] ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT def getPrefixArray ( arr , n , pre ) : NEW_LINE INDENT pre [ 0 ] = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT pre [ i ] = pre [ i - 1 ] + arr [ i ] NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 4 , 8 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE pre = [ None ] * n NEW_LINE getPrefixArray ( arr , n , pre ) NEW_LINE print ( primeCount ( pre , n ) ) NEW_LINE DEDENT " V316,"class GFG { static int sum ( int k , int n ) { int sum = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { int p = 1 ; for ( int j = 0 ; j < n - i ; j ++ ) { p = p * k ; } for ( int j = 0 ; j < i ; j ++ ) { p = p * ( k - 1 ) ; } sum = sum + p ; } return sum ; } public static void main ( String [ ] args ) { int n = 3 ; int K = 3 ; System . out . println ( sum ( K , n ) ) ; } } ","def Sum ( k , n ) : NEW_LINE INDENT Summ = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT p = 1 NEW_LINE for j in range ( n - i ) : NEW_LINE INDENT p = p * k NEW_LINE DEDENT for j in range ( i ) : NEW_LINE INDENT p = p * ( k - 1 ) NEW_LINE DEDENT Summ = Summ + p NEW_LINE DEDENT return Summ NEW_LINE DEDENT n = 3 NEW_LINE K = 3 NEW_LINE print ( Sum ( K , n ) ) NEW_LINE " V317,"class GFG { static long power ( long a , long n ) { if ( n == 0 ) return 1 ; long p = power ( a , n / 2 ) ; p = p * p ; if ( n % 2 == 1 ) p = p * a ; return p ; } static int countIntegers ( long l , long r ) { long ans = 0 , i = 1 ; long v = power ( 2 , i ) ; while ( v <= r ) { while ( v <= r ) { if ( v >= l ) ans ++ ; v = v * 3 ; } i ++ ; v = power ( 2 , i ) ; } if ( l == 1 ) ans ++ ; return ( int ) ans ; } public static void main ( String [ ] args ) { long l = 12 , r = 21 ; System . out . println ( countIntegers ( l , r ) ) ; } } ","def power ( a , n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT p = power ( a , n // 2 ) NEW_LINE p = p * p NEW_LINE if n & 1 : NEW_LINE INDENT p = p * a NEW_LINE DEDENT return p NEW_LINE DEDENT def countIntegers ( l , r ) : NEW_LINE INDENT ans , i = 0 , 1 NEW_LINE v = power ( 2 , i ) NEW_LINE while v <= r : NEW_LINE INDENT while v <= r : NEW_LINE INDENT if v >= l : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT v = v * 3 NEW_LINE DEDENT i += 1 NEW_LINE v = power ( 2 , i ) NEW_LINE DEDENT if l == 1 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT l , r = 12 , 21 NEW_LINE print ( countIntegers ( l , r ) ) NEW_LINE DEDENT " V318,"class GFG { static final int DP_s = 9 ; static int getNumMonotone ( int len ) { int [ ] [ ] DP = new int [ len ] [ DP_s ] ; for ( int i = 0 ; i < DP_s ; ++ i ) DP [ 0 ] [ i ] = i + 1 ; for ( int i = 0 ; i < len ; ++ i ) DP [ i ] [ 0 ] = 1 ; for ( int i = 1 ; i < len ; ++ i ) for ( int j = 1 ; j < DP_s ; ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j ] + DP [ i ] [ j - 1 ] ; return DP [ len - 1 ] [ DP_s - 1 ] ; } public static void main ( String [ ] args ) { System . out . println ( getNumMonotone ( 10 ) ) ; } } ","DP_s = 9 NEW_LINE def getNumMonotone ( ln ) : NEW_LINE INDENT DP = [ [ 0 ] * DP_s for i in range ( ln ) ] NEW_LINE for i in range ( DP_s ) : NEW_LINE INDENT DP [ 0 ] [ i ] = i + 1 NEW_LINE DEDENT for i in range ( ln ) : NEW_LINE INDENT DP [ i ] [ 0 ] = 1 NEW_LINE DEDENT for i in range ( 1 , ln ) : NEW_LINE INDENT for j in range ( 1 , DP_s ) : NEW_LINE INDENT DP [ i ] [ j ] = DP [ i - 1 ] [ j ] + DP [ i ] [ j - 1 ] NEW_LINE DEDENT DEDENT return DP [ ln - 1 ] [ DP_s - 1 ] NEW_LINE DEDENT print ( getNumMonotone ( 10 ) ) NEW_LINE " V319,"import java . io . * ; class GFG { public static void main ( String [ ] args ) { System . out . println ( Integer . bitCount ( 4 ) ) ; System . out . println ( Integer . bitCount ( 15 ) ) ; } } ","print ( bin ( 4 ) . count ( '1' ) ) ; NEW_LINE print ( bin ( 15 ) . count ( '1' ) ) ; NEW_LINE " V320,"class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; void printPaths ( Node node ) { int path [ ] = new int [ 1000 ] ; printPathsRecur ( node , path , 0 ) ; } void printPathsRecur ( Node node , int path [ ] , int pathLen ) { if ( node == null ) return ; path [ pathLen ] = node . data ; pathLen ++ ; if ( node . left == null && node . right == null ) printArray ( path , pathLen ) ; else { printPathsRecur ( node . left , path , pathLen ) ; printPathsRecur ( node . right , path , pathLen ) ; } } void printArray ( int ints [ ] , int len ) { int i ; for ( i = 0 ; i < len ; i ++ ) { System . out . print ( ints [ i ] + "" ▁ "" ) ; } System . out . println ( "" "" ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 2 ) ; tree . root . left . left = new Node ( 3 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 2 ) ; tree . printPaths ( tree . root ) ; } } ","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 printPaths ( root ) : NEW_LINE INDENT path = [ ] NEW_LINE printPathsRec ( root , path , 0 ) NEW_LINE DEDENT def printPathsRec ( root , path , pathLen ) : NEW_LINE INDENT if root is None : NEW_LINE INDENT return NEW_LINE DEDENT if ( len ( path ) > pathLen ) : NEW_LINE INDENT path [ pathLen ] = root . data NEW_LINE DEDENT else : NEW_LINE INDENT path . append ( root . data ) NEW_LINE DEDENT pathLen = pathLen + 1 NEW_LINE if root . left is None and root . right is None : NEW_LINE INDENT printArray ( path , pathLen ) NEW_LINE DEDENT else : NEW_LINE INDENT printPathsRec ( root . left , path , pathLen ) NEW_LINE printPathsRec ( root . right , path , pathLen ) NEW_LINE DEDENT DEDENT def printArray ( ints , len ) : NEW_LINE INDENT for i in ints [ 0 : len ] : NEW_LINE INDENT print ( i , "" ▁ "" , end = "" "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT 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 . left = Node ( 2 ) NEW_LINE printPaths ( root ) NEW_LINE " V321,"class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static int countRectangles ( int l , int w ) { int squareSide = __gcd ( l , w ) ; return ( l * w ) / ( squareSide * squareSide ) ; } public static void main ( String [ ] args ) { int l = 4 , w = 6 ; System . out . println ( countRectangles ( l , w ) ) ; } } ","import math NEW_LINE def countRectangles ( l , w ) : NEW_LINE INDENT squareSide = math . gcd ( l , w ) NEW_LINE return ( l * w ) / ( squareSide * squareSide ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT l = 4 NEW_LINE w = 6 NEW_LINE ans = countRectangles ( l , w ) NEW_LINE print ( int ( ans ) ) NEW_LINE DEDENT " V322,"class GFG { static void factorize ( long n ) { int count = 0 ; while ( ! ( n % 2 > 0 ) ) { n >>= 1 ; count ++ ; } if ( count > 0 ) { System . out . println ( ""2"" + "" ▁ "" + count ) ; } for ( long i = 3 ; i <= ( long ) Math . sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n = n / i ; } if ( count > 0 ) { System . out . println ( i + "" ▁ "" + count ) ; } } if ( n > 2 ) { System . out . println ( n + "" ▁ "" + ""1"" ) ; } } public static void main ( String [ ] args ) { long n = 1000000000000000000L ; factorize ( n ) ; } } ","import math NEW_LINE def factorize ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( ( n % 2 > 0 ) == False ) : NEW_LINE INDENT n >>= 1 ; NEW_LINE count += 1 ; NEW_LINE DEDENT if ( count > 0 ) : NEW_LINE INDENT print ( 2 , count ) ; NEW_LINE DEDENT for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE n = int ( n / i ) ; NEW_LINE DEDENT if ( count > 0 ) : NEW_LINE INDENT print ( i , count ) ; NEW_LINE DEDENT i += 2 ; NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT print ( n , 1 ) ; NEW_LINE DEDENT DEDENT n = 1000000000000000000 ; NEW_LINE factorize ( n ) ; NEW_LINE " V323,"class GFG { static class Node { int data ; Node left , right ; } ; static class INT { int a ; INT ( int a ) { this . a = a ; } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static void printInorder ( Node node ) { if ( node == null ) return ; printInorder ( node . left ) ; System . out . printf ( "" % d ▁ "" , node . data ) ; printInorder ( node . right ) ; } static Node conBinaryTreeUtil ( int pre [ ] , int preM [ ] , INT preIndex , int l , int h , int size ) { if ( preIndex . a >= size || l > h ) return null ; Node root = newNode ( pre [ preIndex . a ] ) ; ++ ( preIndex . a ) ; if ( l == h ) return root ; int i ; for ( i = l ; i <= h ; ++ i ) if ( pre [ preIndex . a ] == preM [ i ] ) break ; if ( i <= h ) { root . left = conBinaryTreeUtil ( pre , preM , preIndex , i , h , size ) ; root . right = conBinaryTreeUtil ( pre , preM , preIndex , l + 1 , i - 1 , size ) ; } return root ; } static void conBinaryTree ( Node root , int pre [ ] , int preMirror [ ] , int size ) { INT preIndex = new INT ( 0 ) ; int preMIndex = 0 ; root = conBinaryTreeUtil ( pre , preMirror , preIndex , 0 , size - 1 , size ) ; printInorder ( root ) ; } public static void main ( String args [ ] ) { int preOrder [ ] = { 1 , 2 , 4 , 5 , 3 , 6 , 7 } ; int preOrderMirror [ ] = { 1 , 3 , 7 , 6 , 2 , 5 , 4 } ; int size = preOrder . length ; Node root = new Node ( ) ; conBinaryTree ( root , preOrder , preOrderMirror , size ) ; } } ","class newNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT def prInorder ( node ) : NEW_LINE INDENT if ( node == None ) : NEW_LINE INDENT return NEW_LINE DEDENT prInorder ( node . left ) NEW_LINE print ( node . data , end = "" ▁ "" ) NEW_LINE prInorder ( node . right ) NEW_LINE DEDENT def constructBinaryTreeUtil ( pre , preM , preIndex , l , h , size ) : NEW_LINE INDENT if ( preIndex >= size or l > h ) : NEW_LINE INDENT return None , preIndex NEW_LINE DEDENT root = newNode ( pre [ preIndex ] ) NEW_LINE preIndex += 1 NEW_LINE if ( l == h ) : NEW_LINE INDENT return root , preIndex NEW_LINE DEDENT i = 0 NEW_LINE for i in range ( l , h + 1 ) : NEW_LINE INDENT if ( pre [ preIndex ] == preM [ i ] ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( i <= h ) : NEW_LINE INDENT root . left , preIndex = constructBinaryTreeUtil ( pre , preM , preIndex , i , h , size ) NEW_LINE root . right , preIndex = constructBinaryTreeUtil ( pre , preM , preIndex , l + 1 , i - 1 , size ) NEW_LINE DEDENT return root , preIndex NEW_LINE DEDENT def constructBinaryTree ( root , pre , preMirror , size ) : NEW_LINE INDENT preIndex = 0 NEW_LINE preMIndex = 0 NEW_LINE root , x = constructBinaryTreeUtil ( pre , preMirror , preIndex , 0 , size - 1 , size ) NEW_LINE prInorder ( root ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT preOrder = [ 1 , 2 , 4 , 5 , 3 , 6 , 7 ] NEW_LINE preOrderMirror = [ 1 , 3 , 7 , 6 , 2 , 5 , 4 ] NEW_LINE size = 7 NEW_LINE root = newNode ( 0 ) NEW_LINE constructBinaryTree ( root , preOrder , preOrderMirror , size ) NEW_LINE DEDENT " V324,"class GFG { static int checkIfStartsWithCapital ( String str ) { if ( str . charAt ( 0 ) >= ' A ' && str . charAt ( 0 ) <= ' Z ' ) return 1 ; else return 0 ; } static void check ( String str ) { if ( checkIfStartsWithCapital ( str ) == 1 ) System . out . println ( "" Accepted "" ) ; else System . out . println ( "" Not ▁ Accepted "" ) ; } public static void main ( String [ ] args ) { String str = "" GeeksforGeeks "" ; check ( str ) ; str = "" geeksforgeeks "" ; check ( str ) ; } } ","def checkIfStartsWithCapital ( string ) : NEW_LINE INDENT if ( string [ 0 ] >= ' A ' and string [ 0 ] <= ' Z ' ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT def check ( string ) : NEW_LINE INDENT if ( checkIfStartsWithCapital ( string ) ) : NEW_LINE INDENT print ( "" Accepted "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Not ▁ Accepted "" ) ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" GeeksforGeeks "" ; NEW_LINE check ( string ) ; NEW_LINE string = "" geeksforgeeks "" ; NEW_LINE check ( string ) ; NEW_LINE DEDENT " V325,"class Test { static boolean checkPolygonWithMidpoints ( int arr [ ] , int N , int midpoints ) { for ( int j = 0 ; j < midpoints ; j ++ ) { int val = 1 ; for ( int k = j ; k < N ; k += midpoints ) { val &= arr [ k ] ; } if ( val != 0 && N / midpoints > 2 ) { System . out . println ( "" Polygon ▁ possible ▁ with ▁ side ▁ length ▁ "" + N / midpoints ) ; return true ; } } return false ; } static void isPolygonPossible ( int arr [ ] , int N ) { int limit = ( int ) Math . sqrt ( N ) ; for ( int i = 1 ; i <= limit ; i ++ ) { if ( N % i == 0 ) { if ( checkPolygonWithMidpoints ( arr , N , i ) || checkPolygonWithMidpoints ( arr , N , ( N / i ) ) ) return ; } } System . out . println ( "" Not ▁ possible "" ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 } ; isPolygonPossible ( arr , arr . length ) ; } } ","from math import sqrt NEW_LINE def checkPolygonWithMidpoints ( arr , N , midpoints ) : NEW_LINE INDENT for j in range ( midpoints ) : NEW_LINE INDENT val = 1 NEW_LINE for k in range ( j , N , midpoints ) : NEW_LINE INDENT val &= arr [ k ] NEW_LINE DEDENT if ( val and N // midpoints > 2 ) : NEW_LINE INDENT print ( "" Polygon ▁ possible ▁ with ▁ side ▁ length "" , ( N // midpoints ) ) NEW_LINE return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def isPolygonPossible ( arr , N ) : NEW_LINE INDENT limit = sqrt ( N ) NEW_LINE for i in range ( 1 , int ( limit ) + 1 ) : NEW_LINE INDENT if ( N % i == 0 ) : NEW_LINE INDENT if ( checkPolygonWithMidpoints ( arr , N , i ) or checkPolygonWithMidpoints ( arr , N , ( N // i ) ) ) : NEW_LINE INDENT return NEW_LINE DEDENT DEDENT DEDENT print ( "" Not ▁ possiblen "" ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE isPolygonPossible ( arr , N ) NEW_LINE DEDENT " V326,"class GFG { static boolean isToOne ( int n ) { return ( n > 0 ) ; } public static void main ( String [ ] args ) { int n = 5 ; if ( isToOne ( n ) == true ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isToOne ( n ) : NEW_LINE INDENT return ( n > 0 ) NEW_LINE DEDENT n = 5 NEW_LINE if isToOne ( n ) == True : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V327,"import java . util . * ; class GFG { static int distinctSubString ( String P , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { boolean [ ] freq = new boolean [ 26 ] ; String s = "" "" ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; if ( freq [ pos ] == true ) break ; freq [ pos ] = true ; s += P . charAt ( j ) ; S . add ( s ) ; } } return S . size ( ) ; } public static void main ( String [ ] args ) { String S = "" abba "" ; int N = S . length ( ) ; System . out . print ( distinctSubString ( S , N ) ) ; } } ","def distinctSubstring ( P , N ) : NEW_LINE INDENT S = dict ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT freq = [ False ] * 26 NEW_LINE s = "" "" NEW_LINE for j in range ( i , N ) : NEW_LINE INDENT pos = ord ( P [ j ] ) - ord ( ' a ' ) NEW_LINE if ( freq [ pos ] == True ) : NEW_LINE INDENT break NEW_LINE DEDENT freq [ pos ] = True NEW_LINE s += P [ j ] NEW_LINE S [ s ] = 1 NEW_LINE DEDENT DEDENT return len ( S ) NEW_LINE DEDENT S = "" abba "" NEW_LINE N = len ( S ) NEW_LINE print ( distinctSubstring ( S , N ) ) NEW_LINE " V328,"class Solution { static int minimumX ( int n , int k ) { int ans = Integer . MAX_VALUE ; for ( int rem = k - 1 ; rem > 0 ; rem -- ) { if ( n % rem == 0 ) ans = Math . min ( ans , rem + ( n / rem ) * k ) ; } return ans ; } public static void main ( String args [ ] ) { int n = 4 , k = 6 ; System . out . println ( minimumX ( n , k ) ) ; n = 5 ; k = 5 ; System . out . println ( minimumX ( n , k ) ) ; } } ","def minimumX ( n , k ) : NEW_LINE INDENT ans = 10 ** 18 NEW_LINE for i in range ( k - 1 , 0 , - 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT ans = min ( ans , i + ( n / i ) * k ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT n , k = 4 , 6 NEW_LINE print ( minimumX ( n , k ) ) NEW_LINE n , k = 5 , 5 NEW_LINE print ( minimumX ( n , k ) ) NEW_LINE " V329,"import java . util . * ; class solution { static int findMinDifference ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int diff1 = arr [ n - 1 ] - arr [ 1 ] ; int diff2 = arr [ n - 2 ] - arr [ 0 ] ; return Math . min ( diff1 , diff2 ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 4 , 3 , 4 } ; int n = arr . length ; System . out . print ( findMinDifference ( arr , n ) ) ; } } ","def findMinDifference ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE diff1 = arr [ n - 1 ] - arr [ 1 ] NEW_LINE diff2 = arr [ n - 2 ] - arr [ 0 ] NEW_LINE return min ( diff1 , diff2 ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 2 , 4 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMinDifference ( arr , n ) ) NEW_LINE DEDENT " V330,"import java . io . * ; class GFG { public static void main ( String [ ] args ) { int a = 5 , b = 7 , c = 10 ; if ( a <= b && a <= c ) System . out . println ( a + "" ▁ is ▁ the ▁ smallest "" ) ; else if ( b <= a && b <= c ) System . out . println ( b + "" ▁ is ▁ the ▁ smallest "" ) ; else System . out . println ( c + "" ▁ is ▁ the ▁ smallest "" ) ; } } ","a , b , c = 5 , 7 , 10 NEW_LINE if ( a <= b and a <= c ) : NEW_LINE INDENT print ( a , "" is ▁ the ▁ smallest "" ) NEW_LINE DEDENT elif ( b <= a and b <= c ) : NEW_LINE INDENT print ( b , "" is ▁ the ▁ smallest "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( c , "" is ▁ the ▁ smallest "" ) NEW_LINE DEDENT " V331,"class GFG { static int MAX = 100005 ; static boolean [ ] isPrime = new boolean [ MAX ] ; static void sieveOfEratostheneses ( ) { isPrime [ 1 ] = true ; for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( ! isPrime [ i ] ) { for ( int j = 2 * i ; j < MAX ; j += i ) isPrime [ j ] = true ; } } } static int findPrime ( int n ) { int num = n + 1 ; while ( num > 0 ) { if ( ! isPrime [ num ] ) return num ; num = num + 1 ; } return 0 ; } static int minNumber ( int arr [ ] , int n ) { sieveOfEratostheneses ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( ! isPrime [ sum ] ) return 0 ; int num = findPrime ( sum ) ; return num - sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 8 , 12 } ; int n = arr . length ; System . out . println ( minNumber ( arr , n ) ) ; } } ","isPrime = [ 1 ] * 100005 NEW_LINE def sieveOfEratostheneses ( ) : NEW_LINE INDENT isPrime [ 1 ] = False NEW_LINE i = 2 NEW_LINE while i * i < 100005 : NEW_LINE INDENT if ( isPrime [ i ] ) : NEW_LINE INDENT j = 2 * i NEW_LINE while j < 100005 : NEW_LINE INDENT isPrime [ j ] = False NEW_LINE j += i NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT return NEW_LINE DEDENT def findPrime ( n ) : NEW_LINE INDENT num = n + 1 NEW_LINE while ( num ) : NEW_LINE INDENT if isPrime [ num ] : NEW_LINE INDENT return num NEW_LINE DEDENT num += 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def minNumber ( arr ) : NEW_LINE INDENT sieveOfEratostheneses ( ) NEW_LINE s = 0 NEW_LINE for i in range ( 0 , len ( arr ) ) : NEW_LINE INDENT s += arr [ i ] NEW_LINE DEDENT if isPrime [ s ] == True : NEW_LINE INDENT return 0 NEW_LINE DEDENT num = findPrime ( s ) NEW_LINE return num - s NEW_LINE DEDENT arr = [ 2 , 4 , 6 , 8 , 12 ] NEW_LINE print ( minNumber ( arr ) ) NEW_LINE " V332,"class GFG { static boolean isPower ( int n ) { for ( int x = 2 ; x <= Math . sqrt ( n ) ; x ++ ) { int y = 2 ; double p = Math . pow ( x , y ) ; while ( p <= n && p > 0 ) { if ( p == n ) return true ; y ++ ; p = Math . pow ( x , y ) ; } } return false ; } public static void main ( String [ ] args ) { for ( int i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) System . out . print ( i + "" ▁ "" ) ; } } ","import math NEW_LINE def isPower ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT for x in range ( 2 , ( int ) ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT y = 2 NEW_LINE p = ( int ) ( math . pow ( x , y ) ) NEW_LINE while ( p <= n and p > 0 ) : NEW_LINE INDENT if ( p == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT y = y + 1 NEW_LINE p = math . pow ( x , y ) NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT for i in range ( 2 , 100 ) : NEW_LINE INDENT if ( isPower ( i ) ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V333,"import java . io . * ; class GFG { static int minMovesToSort ( int arr [ ] , int n ) { int moves = 0 ; int i , mn = arr [ n - 1 ] ; for ( i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > mn ) moves += arr [ i ] - mn ; mn = arr [ i ] ; } return moves ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 2 , 8 , 4 } ; int n = arr . length ; System . out . println ( minMovesToSort ( arr , n ) ) ; } } ","def minMovesToSort ( arr , n ) : NEW_LINE INDENT moves = 0 NEW_LINE mn = arr [ n - 1 ] NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] > mn ) : NEW_LINE INDENT moves += arr [ i ] - mn NEW_LINE DEDENT mn = arr [ i ] NEW_LINE DEDENT return moves NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 3 , 5 , 2 , 8 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minMovesToSort ( arr , n ) ) NEW_LINE DEDENT " V334,"import java . util . * ; class GFG { static class Node { Node left ; Node right ; int data ; Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } ; static class Info { int num_BST ; int max ; int min ; boolean isBST ; Info ( int a , int b , int c , boolean d ) { num_BST = a ; max = b ; min = c ; isBST = d ; } Info ( ) { } } ; static Info NumberOfBST ( Node root ) { if ( root == null ) return new Info ( 0 , Integer . MIN_VALUE , Integer . MAX_VALUE , true ) ; if ( root . left == null && root . right == null ) return new Info ( 1 , root . data , root . data , true ) ; Info L = NumberOfBST ( root . left ) ; Info R = NumberOfBST ( root . right ) ; Info bst = new Info ( ) ; bst . min = Math . min ( root . data , ( Math . min ( L . min , R . min ) ) ) ; bst . max = Math . max ( root . data , ( Math . max ( L . max , R . max ) ) ) ; if ( L . isBST && R . isBST && root . data > L . max && root . data < R . min ) { bst . isBST = true ; bst . num_BST = 1 + L . num_BST + R . num_BST ; } else { bst . isBST = false ; bst . num_BST = L . num_BST + R . num_BST ; } return bst ; } public static void main ( String args [ ] ) { Node root = new Node ( 5 ) ; root . left = new Node ( 9 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 6 ) ; root . right . right = new Node ( 4 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 7 ) ; System . out . print ( NumberOfBST ( root ) . num_BST ) ; } } ","INT_MIN = - 2 ** 31 NEW_LINE INT_MAX = 2 ** 31 NEW_LINE class newNode ( ) : 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 NumberOfBST ( root ) : NEW_LINE INDENT if ( root == None ) : NEW_LINE INDENT return 0 , INT_MIN , INT_MAX , True NEW_LINE DEDENT if ( root . left == None and root . right == None ) : NEW_LINE INDENT return 1 , root . data , root . data , True NEW_LINE DEDENT L = NumberOfBST ( root . left ) NEW_LINE R = NumberOfBST ( root . right ) NEW_LINE bst = [ 0 ] * 4 NEW_LINE bst [ 2 ] = min ( root . data , ( min ( L [ 2 ] , R [ 2 ] ) ) ) NEW_LINE bst [ 1 ] = max ( root . data , ( max ( L [ 1 ] , R [ 1 ] ) ) ) NEW_LINE if ( L [ 3 ] and R [ 3 ] and root . data > L [ 1 ] and root . data < R [ 2 ] ) : NEW_LINE INDENT bst [ 3 ] = True NEW_LINE bst [ 0 ] = 1 + L [ 0 ] + R [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT bst [ 3 ] = False NEW_LINE bst [ 0 ] = L [ 0 ] + R [ 0 ] NEW_LINE DEDENT return bst NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = newNode ( 5 ) NEW_LINE root . left = newNode ( 9 ) NEW_LINE root . right = newNode ( 3 ) NEW_LINE root . left . left = newNode ( 6 ) NEW_LINE root . right . right = newNode ( 4 ) NEW_LINE root . left . left . left = newNode ( 8 ) NEW_LINE root . left . left . right = newNode ( 7 ) NEW_LINE print ( NumberOfBST ( root ) [ 0 ] ) NEW_LINE DEDENT " V335,"import java . io . * ; public class GFG { static int calculateSum ( int n ) { return ( int ) ( ( 2 * Math . pow ( ( n * ( n + 1 ) / 2 ) , 2 ) ) ) + ( ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( "" Sum ▁ = ▁ "" + calculateSum ( n ) ) ; } } ","def calculateSum ( n ) : NEW_LINE INDENT return ( ( 2 * ( n * ( n + 1 ) / 2 ) ** 2 ) + ( ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ) ) NEW_LINE DEDENT n = 4 NEW_LINE print ( "" Sum ▁ = "" , calculateSum ( n ) ) NEW_LINE " V336,"class GFG { static boolean isNonHypotenuse ( int n ) { while ( n % 2 == 0 ) { n = n / 2 ; } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { if ( ( i - 1 ) % 4 == 0 ) return false ; while ( n % i == 0 ) { n = n / i ; } } } if ( n > 2 && ( n - 1 ) % 4 == 0 ) return false ; else return true ; } public static void test ( int n ) { System . out . println ( "" Testing ▁ for ▁ "" + n + "" ▁ : ▁ "" ) ; if ( isNonHypotenuse ( n ) ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } public static void main ( String args [ ] ) { int n = 11 ; test ( n ) ; n = 10 ; test ( n ) ; } } ","from math import sqrt NEW_LINE def isNonHypotenuse ( n ) : NEW_LINE INDENT while ( n % 2 == 0 ) : NEW_LINE INDENT n = n // 2 NEW_LINE DEDENT for i in range ( 3 , int ( sqrt ( n ) ) + 1 , 2 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( ( i - 1 ) % 4 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT while ( n % i == 0 ) : NEW_LINE INDENT n = n // i NEW_LINE DEDENT DEDENT DEDENT if ( n > 2 and ( n - 1 ) % 4 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT def test ( n ) : NEW_LINE INDENT print ( "" Testing ▁ for "" , n , "" : "" , end = "" ▁ "" ) NEW_LINE if ( isNonHypotenuse ( n ) ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 11 NEW_LINE test ( n ) NEW_LINE n = 10 NEW_LINE test ( n ) NEW_LINE DEDENT " V337,"import java . io . * ; class GFG { static void printSquares ( int n ) { int square = 0 , odd = 1 ; for ( int x = 0 ; x < n ; x ++ ) { System . out . print ( square + "" ▁ "" ) ; square = square + odd ; odd = odd + 2 ; } } public static void main ( String [ ] args ) { int n = 5 ; printSquares ( n ) ; } } ","def printSquares ( n ) : NEW_LINE INDENT square = 0 NEW_LINE odd = 1 NEW_LINE for x in range ( 0 , n ) : NEW_LINE INDENT print ( square , end = "" ▁ "" ) NEW_LINE square = square + odd NEW_LINE odd = odd + 2 NEW_LINE DEDENT DEDENT n = 5 ; NEW_LINE printSquares ( n ) NEW_LINE " V338,"class GFG { static String revAlternateK ( String s , int k , int len ) { for ( int i = 0 ; i < s . length ( ) ; ) { if ( i + k > len ) break ; s = s . substring ( 0 , i ) + new String ( new StringBuilder ( s . substring ( i , i + k ) ) . reverse ( ) ) + s . substring ( i + k ) ; i += 2 * k ; } return s ; } public static void main ( String [ ] args ) { String s = "" geeksforgeeks "" ; int len = s . length ( ) ; int k = 3 ; System . out . println ( revAlternateK ( s , k , len ) ) ; } } ","def revAlternateK ( s , k , Len ) : NEW_LINE INDENT i = 0 NEW_LINE while ( i < len ( s ) ) : NEW_LINE INDENT if ( i + k > Len ) : NEW_LINE INDENT break NEW_LINE DEDENT ss = s [ i : i + k ] NEW_LINE s = s [ : i ] + ss [ : : - 1 ] + s [ i + k : ] NEW_LINE i += 2 * k NEW_LINE DEDENT return s ; NEW_LINE DEDENT s = "" geeksforgeeks "" NEW_LINE Len = len ( s ) NEW_LINE k = 3 NEW_LINE print ( revAlternateK ( s , k , Len ) ) NEW_LINE " V339,"import java . io . * ; class GFG { static int countRotationsDivBy8 ( String n ) { int len = n . length ( ) ; int count = 0 ; if ( len == 1 ) { int oneDigit = n . charAt ( 0 ) - '0' ; if ( oneDigit % 8 == 0 ) return 1 ; return 0 ; } if ( len == 2 ) { int first = ( n . charAt ( 0 ) - '0' ) * 10 + ( n . charAt ( 1 ) - '0' ) ; int second = ( n . charAt ( 1 ) - '0' ) * 10 + ( n . charAt ( 0 ) - '0' ) ; if ( first % 8 == 0 ) count ++ ; if ( second % 8 == 0 ) count ++ ; return count ; } int threeDigit ; for ( int i = 0 ; i < ( len - 2 ) ; i ++ ) { threeDigit = ( n . charAt ( i ) - '0' ) * 100 + ( n . charAt ( i + 1 ) - '0' ) * 10 + ( n . charAt ( i + 2 ) - '0' ) ; if ( threeDigit % 8 == 0 ) count ++ ; } threeDigit = ( n . charAt ( len - 1 ) - '0' ) * 100 + ( n . charAt ( 0 ) - '0' ) * 10 + ( n . charAt ( 1 ) - '0' ) ; if ( threeDigit % 8 == 0 ) count ++ ; threeDigit = ( n . charAt ( len - 2 ) - '0' ) * 100 + ( n . charAt ( len - 1 ) - '0' ) * 10 + ( n . charAt ( 0 ) - '0' ) ; if ( threeDigit % 8 == 0 ) count ++ ; return count ; } public static void main ( String [ ] args ) { String n = ""43262488612"" ; System . out . println ( "" Rotations : ▁ "" + countRotationsDivBy8 ( n ) ) ; } } ","def countRotationsDivBy8 ( n ) : NEW_LINE INDENT l = len ( n ) NEW_LINE count = 0 NEW_LINE if ( l == 1 ) : NEW_LINE INDENT oneDigit = int ( n [ 0 ] ) NEW_LINE if ( oneDigit % 8 == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT if ( l == 2 ) : NEW_LINE INDENT first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) NEW_LINE second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] ) NEW_LINE if ( first % 8 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( second % 8 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT threeDigit = 0 NEW_LINE for i in range ( 0 , ( l - 2 ) ) : NEW_LINE INDENT threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) ) NEW_LINE if ( threeDigit % 8 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) ) NEW_LINE if ( threeDigit % 8 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) ) NEW_LINE if ( threeDigit % 8 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = ""43262488612"" NEW_LINE print ( "" Rotations : "" , countRotationsDivBy8 ( n ) ) NEW_LINE DEDENT " V340,"class GFG { static void printValue ( char digit ) { switch ( digit ) { case '0' : System . out . print ( "" Zero ▁ "" ) ; break ; case '1' : System . out . print ( "" One ▁ "" ) ; break ; case '2' : System . out . print ( "" Two ▁ "" ) ; break ; case '3' : System . out . print ( "" Three ▁ "" ) ; break ; case '4' : System . out . print ( "" Four ▁ "" ) ; break ; case '5' : System . out . print ( "" Five ▁ "" ) ; break ; case '6' : System . out . print ( "" Six ▁ "" ) ; break ; case '7' : System . out . print ( "" Seven ▁ "" ) ; break ; case '8' : System . out . print ( "" Eight ▁ "" ) ; break ; case '9' : System . out . print ( "" Nine ▁ "" ) ; break ; } } static void printWord ( String N ) { int i , length = N . length ( ) ; for ( i = 0 ; i < length ; i ++ ) { printValue ( N . charAt ( i ) ) ; } } public static void main ( String [ ] args ) { String N = ""123"" ; printWord ( N ) ; } } ","def printValue ( digit ) : NEW_LINE INDENT if digit == '0' : NEW_LINE INDENT print ( "" Zero ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '1' : NEW_LINE INDENT print ( "" One ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '2' : NEW_LINE INDENT print ( "" Two ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '3' : NEW_LINE INDENT print ( "" Three "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '4' : NEW_LINE INDENT print ( "" Four ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '5' : NEW_LINE INDENT print ( "" Five ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '6' : NEW_LINE INDENT print ( "" Six ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '7' : NEW_LINE INDENT print ( "" Seven "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '8' : NEW_LINE INDENT print ( "" Eight "" , end = "" ▁ "" ) NEW_LINE DEDENT elif digit == '9' : NEW_LINE INDENT print ( "" Nine ▁ "" , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT def printWord ( N ) : NEW_LINE INDENT i = 0 NEW_LINE length = len ( N ) NEW_LINE while i < length : NEW_LINE INDENT printValue ( N [ i ] ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT N = ""123"" NEW_LINE printWord ( N ) NEW_LINE " V341,"class GFG { static int findSplTripletsSum ( int a [ ] , int b [ ] , int c [ ] , int p , int q , int r ) { int sum = 0 ; for ( int i = 0 ; i < p ; i ++ ) { for ( int j = 0 ; j < q ; j ++ ) { for ( int k = 0 ; k < r ; k ++ ) { if ( a [ i ] <= b [ j ] && c [ k ] <= b [ j ] ) { sum += ( a [ i ] + b [ j ] ) * ( b [ j ] + c [ k ] ) ; } } } } return sum ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 4 , 5 } ; int B [ ] = { 2 , 3 } ; int C [ ] = { 2 , 1 , 3 } ; int p = A . length ; int q = B . length ; int r = C . length ; System . out . print ( "" Sum ▁ of ▁ values ▁ of ▁ all ▁ special ▁ triplets ▁ = ▁ "" + findSplTripletsSum ( A , B , C , p , q , r ) + "" \n "" ) ; } } ","def findSplTripletsSum ( a , b , c , p , q , r ) : NEW_LINE INDENT summ = 0 NEW_LINE for i in range ( p ) : NEW_LINE INDENT for j in range ( q ) : NEW_LINE INDENT for k in range ( r ) : NEW_LINE INDENT if ( a [ i ] <= b [ j ] and c [ k ] <= b [ j ] ) : NEW_LINE INDENT summ += ( a [ i ] + b [ j ] ) * ( b [ j ] + c [ k ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT return summ NEW_LINE DEDENT A = [ 1 , 4 , 5 ] NEW_LINE B = [ 2 , 3 ] NEW_LINE C = [ 2 , 1 , 3 ] NEW_LINE p = len ( A ) NEW_LINE q = len ( B ) NEW_LINE r = len ( C ) NEW_LINE print ( "" Sum ▁ of ▁ values ▁ of ▁ all ▁ special ▁ triplets ▁ = ▁ "" , findSplTripletsSum ( A , B , C , p , q , r ) ) NEW_LINE " V342,"import java . util . * ; class GFG { static int nthDigit ( int a , int n , int b ) { for ( int i = 1 ; i < n ; i ++ ) a = a / b ; return a % b ; } public static void main ( String [ ] args ) { int a = 100 ; int n = 3 ; int b = 4 ; System . out . print ( nthDigit ( a , n , b ) ) ; } } ","def nthDigit ( a , n , b ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT a = a // b NEW_LINE DEDENT return a % b NEW_LINE DEDENT a = 100 NEW_LINE n = 3 NEW_LINE b = 4 NEW_LINE print ( nthDigit ( a , n , b ) ) NEW_LINE " V343,"class Solution { static int sum ( int n ) { if ( n == 1 ) { return 2 ; } else { return ( n * ( n + 1 ) + sum ( n - 1 ) ) ; } } public static void main ( String args [ ] ) { int n = 2 ; System . out . println ( sum ( n ) ) ; } } ","def sum ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( n * ( n + 1 ) + sum ( n - 1 ) ) ; NEW_LINE DEDENT DEDENT n = 2 ; NEW_LINE print ( sum ( n ) ) ; NEW_LINE " V344,"class GFG { static int TEN = 10 ; static int minNum ( char [ ] str , int len ) { int res = Integer . MAX_VALUE ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '4' || str [ i ] == '8' ) { res = Math . min ( res , str [ i ] - '0' ) ; } } for ( int i = 0 ; i < len - 1 ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { int num = ( str [ i ] - '0' ) * TEN + ( str [ j ] - '0' ) ; if ( num % 4 == 0 ) { res = Math . min ( res , num ) ; } } } return ( ( res == Integer . MAX_VALUE ) ? - 1 : res ) ; } public static void main ( String [ ] args ) { String str = ""17"" ; int len = str . length ( ) ; System . out . print ( minNum ( str . toCharArray ( ) , len ) ) ; } } ","import sys NEW_LINE TEN = 10 NEW_LINE def minNum ( str , len1 ) : NEW_LINE INDENT res = sys . maxsize NEW_LINE for i in range ( len1 ) : NEW_LINE INDENT if ( str [ i ] == '4' or str [ i ] == '8' ) : NEW_LINE INDENT res = min ( res , ord ( str [ i ] ) - ord ( '0' ) ) NEW_LINE DEDENT DEDENT for i in range ( len1 - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , len1 , 1 ) : NEW_LINE INDENT num = ( ord ( str [ i ] ) - ord ( '0' ) ) * TEN + \ NEW_LINE INDENT ( ord ( str [ j ] ) - ord ( '0' ) ) NEW_LINE DEDENT if ( num % 4 == 0 ) : NEW_LINE INDENT res = min ( res , num ) NEW_LINE DEDENT DEDENT DEDENT if ( res == sys . maxsize ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return res NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = ""17"" NEW_LINE len1 = len ( str ) NEW_LINE print ( minNum ( str , len1 ) ) NEW_LINE DEDENT " V345,"public class GFG { static boolean isPower ( int a ) { if ( a == 1 ) return true ; for ( int i = 2 ; i * i <= a ; i ++ ) { double val = Math . log ( a ) / Math . log ( i ) ; if ( ( val - ( int ) val ) < 0.00000001 ) return true ; } return false ; } public static void main ( String [ ] args ) { int n = 16 ; System . out . println ( isPower ( n ) ? "" Yes "" : "" No "" ) ; } } ","from math import * NEW_LINE def isPower ( a ) : NEW_LINE INDENT if a == 1 : NEW_LINE INDENT return True NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( a ) ) + 1 ) : NEW_LINE INDENT val = log ( a ) / log ( i ) NEW_LINE if ( round ( ( val - int ( val ) ) , 8 ) < 0.00000001 ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 16 NEW_LINE if isPower ( n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V346,"public class GFG { static long countNonDecreasing ( int n ) { int N = 10 ; long count = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { count *= ( N + i - 1 ) ; count /= i ; } return count ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . print ( countNonDecreasing ( n ) ) ; } } ","def countNonDecreasing ( n ) : NEW_LINE INDENT N = 10 NEW_LINE count = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT count = int ( count * ( N + i - 1 ) ) NEW_LINE count = int ( count / i ) NEW_LINE DEDENT return count NEW_LINE DEDENT n = 3 ; NEW_LINE print ( countNonDecreasing ( n ) ) NEW_LINE " V347,"import java . util . * ; class GFG { static int height ; static int search ( int arr [ ] , int strt , int end , int value ) { for ( int i = strt ; i <= end ; i ++ ) if ( arr [ i ] == value ) return i ; return - 1 ; } static int getHeight ( int in [ ] , int level [ ] , int start , int end , int n ) { if ( start > end ) return 0 ; int getIndex = search ( in , start , end , level [ 0 ] ) ; if ( getIndex == - 1 ) return 0 ; int leftCount = getIndex - start ; int rightCount = end - getIndex ; int [ ] newLeftLevel = new int [ leftCount ] ; int [ ] newRightLevel = new int [ rightCount ] ; int lheight = 0 , rheight = 0 ; int k = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = start ; j < getIndex ; j ++ ) { if ( level [ i ] == in [ j ] ) { newLeftLevel [ k ] = level [ i ] ; k ++ ; break ; } } } k = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = getIndex + 1 ; j <= end ; j ++ ) { if ( level [ i ] == in [ j ] ) { newRightLevel [ k ] = level [ i ] ; k ++ ; break ; } } } if ( leftCount > 0 ) lheight = getHeight ( in , newLeftLevel , start , getIndex - 1 , leftCount ) ; if ( rightCount > 0 ) rheight = getHeight ( in , newRightLevel , getIndex + 1 , end , rightCount ) ; height = Math . max ( lheight + 1 , rheight + 1 ) ; newRightLevel = null ; newLeftLevel = null ; return height ; } public static void main ( String [ ] args ) { int in [ ] = { 4 , 8 , 10 , 12 , 14 , 20 , 22 } ; int level [ ] = { 20 , 8 , 22 , 4 , 12 , 10 , 14 } ; int n = in . length ; height = 0 ; System . out . println ( getHeight ( in , level , 0 , n - 1 , n ) ) ; } } ","def search ( arr , start , end , value ) : NEW_LINE INDENT for i in range ( start , end + 1 ) : NEW_LINE INDENT if arr [ i ] == value : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT def getHeight ( inOrder , levelOrder , start , end , height , n ) : NEW_LINE INDENT if start > end : NEW_LINE INDENT return 0 NEW_LINE DEDENT getIndex = search ( inOrder , start , end , levelOrder [ 0 ] ) NEW_LINE if getIndex == - 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT leftCount = getIndex - start NEW_LINE rightCount = end - getIndex NEW_LINE newLeftLevel = [ None for _ in range ( leftCount ) ] NEW_LINE newRightLevel = [ None for _ in range ( rightCount ) ] NEW_LINE lheight , rheight , k = 0 , 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( start , getIndex ) : NEW_LINE INDENT if levelOrder [ i ] == inOrder [ j ] : NEW_LINE INDENT newLeftLevel [ k ] = levelOrder [ i ] NEW_LINE k += 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT k = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( getIndex + 1 , end + 1 ) : NEW_LINE INDENT if levelOrder [ i ] == inOrder [ j ] : NEW_LINE INDENT newRightLevel [ k ] = levelOrder [ i ] NEW_LINE k += 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if leftCount > 0 : NEW_LINE INDENT lheight = getHeight ( inOrder , newLeftLevel , start , getIndex - 1 , height , leftCount ) NEW_LINE DEDENT if rightCount > 0 : NEW_LINE INDENT rheight = getHeight ( inOrder , newRightLevel , getIndex + 1 , end , height , rightCount ) NEW_LINE DEDENT height = max ( lheight + 1 , rheight + 1 ) NEW_LINE return height NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT inOrder = [ 4 , 8 , 10 , 12 , 14 , 20 , 22 ] NEW_LINE levelOrder = [ 20 , 8 , 22 , 4 , 12 , 10 , 14 ] NEW_LINE n , h = len ( inOrder ) , 0 NEW_LINE print ( getHeight ( inOrder , levelOrder , 0 , n - 1 , h , n ) ) NEW_LINE DEDENT " V348,"class GFG { static class Node { int data ; Node left , right ; } ; static String str ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static void treeToString ( Node root ) { if ( root == null ) return ; str += ( Character . valueOf ( ( char ) ( root . data + '0' ) ) ) ; if ( root . left == null && root . right == null ) return ; str += ( ' ( ' ) ; treeToString ( root . left ) ; str += ( ' ) ' ) ; if ( root . right != null ) { str += ( ' ( ' ) ; treeToString ( root . right ) ; str += ( ' ) ' ) ; } } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; str = "" "" ; treeToString ( root ) ; System . out . println ( str ) ; } } ","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 treeToString ( root : Node , string : list ) : NEW_LINE INDENT if root is None : NEW_LINE INDENT return NEW_LINE DEDENT string . append ( str ( root . data ) ) NEW_LINE if not root . left and not root . right : NEW_LINE INDENT return NEW_LINE DEDENT string . append ( ' ( ' ) NEW_LINE treeToString ( root . left , string ) NEW_LINE string . append ( ' ) ' ) NEW_LINE if root . right : NEW_LINE INDENT string . append ( ' ( ' ) NEW_LINE treeToString ( root . right , string ) NEW_LINE string . append ( ' ) ' ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT root = Node ( 1 ) NEW_LINE root . left = Node ( 2 ) NEW_LINE root . right = Node ( 3 ) NEW_LINE root . left . left = Node ( 4 ) NEW_LINE root . left . right = Node ( 5 ) NEW_LINE root . right . right = Node ( 6 ) NEW_LINE string = [ ] NEW_LINE treeToString ( root , string ) NEW_LINE print ( ' ' . join ( string ) ) NEW_LINE DEDENT " V349,"import java . util . * ; class GFG { static void triangular_series ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) System . out . printf ( "" % d ▁ "" ; , i * ( i + 1 ) / 2 ) ; } public static void main ( String [ ] args ) { int n = 5 ; triangular_series ( n ) ; } } ","def triangular_series ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( i * ( i + 1 ) // 2 , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT n = 5 NEW_LINE triangular_series ( n ) NEW_LINE " V350,"import java . io . * ; class GFG { static int lds ( int arr [ ] , int n ) { int lds [ ] = new int [ n ] ; int i , j , max = 0 ; for ( i = 0 ; i < n ; i ++ ) lds [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] < arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < lds [ i ] ) max = lds [ i ] ; return max ; } public static void main ( String [ ] args ) { int arr [ ] = { 15 , 27 , 14 , 38 , 63 , 55 , 46 , 65 , 85 } ; int n = arr . length ; System . out . print ( "" Length ▁ of ▁ LDS ▁ is ▁ "" + lds ( arr , n ) ) ; } } ","def lds ( arr , n ) : NEW_LINE INDENT lds = [ 0 ] * n NEW_LINE max = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT lds [ i ] = 1 NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT if ( arr [ i ] < arr [ j ] and lds [ i ] < lds [ j ] + 1 ) : NEW_LINE INDENT lds [ i ] = lds [ j ] + 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( max < lds [ i ] ) : NEW_LINE INDENT max = lds [ i ] NEW_LINE DEDENT DEDENT return max NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 15 , 27 , 14 , 38 , 63 , 55 , 46 , 65 , 85 ] NEW_LINE n = len ( arr ) NEW_LINE print ( "" Length ▁ of ▁ LDS ▁ is "" , lds ( arr , n ) ) NEW_LINE DEDENT " V351,"import java . io . * ; class GFG { static int n = 3 ; static int dotProduct ( int vect_A [ ] , int vect_B [ ] ) { int product = 0 ; for ( int i = 0 ; i < n ; i ++ ) product = product + vect_A [ i ] * vect_B [ i ] ; return product ; } static void crossProduct ( int vect_A [ ] , int vect_B [ ] , int cross_P [ ] ) { cross_P [ 0 ] = vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ; cross_P [ 1 ] = vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ; cross_P [ 2 ] = vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ; } public static void main ( String [ ] args ) { int vect_A [ ] = { 3 , - 5 , 4 } ; int vect_B [ ] = { 2 , 6 , 5 } ; int cross_P [ ] = new int [ n ] ; System . out . print ( "" Dot ▁ product : "" ) ; System . out . println ( dotProduct ( vect_A , vect_B ) ) ; System . out . print ( "" Cross ▁ product : "" ) ; crossProduct ( vect_A , vect_B , cross_P ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( cross_P [ i ] + "" ▁ "" ) ; } } ","n = 3 NEW_LINE def dotProduct ( vect_A , vect_B ) : NEW_LINE INDENT product = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT product = product + vect_A [ i ] * vect_B [ i ] NEW_LINE DEDENT return product NEW_LINE DEDENT def crossProduct ( vect_A , vect_B , cross_P ) : NEW_LINE INDENT cross_P . append ( vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ) NEW_LINE cross_P . append ( vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ) NEW_LINE cross_P . append ( vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT vect_A = [ 3 , - 5 , 4 ] NEW_LINE vect_B = [ 2 , 6 , 5 ] NEW_LINE cross_P = [ ] NEW_LINE print ( "" Dot ▁ product : "" , end = "" ▁ "" ) NEW_LINE print ( dotProduct ( vect_A , vect_B ) ) NEW_LINE print ( "" Cross ▁ product : "" , end = "" ▁ "" ) NEW_LINE crossProduct ( vect_A , vect_B , cross_P ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( cross_P [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V352,"class GFG { static long partitions ( int n ) { long p [ ] = new long [ n + 1 ] ; p [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { int k = 1 ; while ( ( k * ( 3 * k - 1 ) ) / 2 <= i ) { p [ i ] += ( k % 2 != 0 ? 1 : - 1 ) * p [ i - ( k * ( 3 * k - 1 ) ) / 2 ] ; if ( k > 0 ) { k *= - 1 ; } else { k = 1 - k ; } } } return p [ n ] ; } public static void main ( String [ ] args ) { int N = 20 ; System . out . println ( partitions ( N ) ) ; } } ","def partitions ( n ) : NEW_LINE INDENT p = [ 0 ] * ( n + 1 ) NEW_LINE p [ 0 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT k = 1 NEW_LINE while ( ( k * ( 3 * k - 1 ) ) / 2 <= i ) : NEW_LINE INDENT p [ i ] += ( ( 1 if k % 2 else - 1 ) * p [ i - ( k * ( 3 * k - 1 ) ) // 2 ] ) NEW_LINE if ( k > 0 ) : NEW_LINE INDENT k *= - 1 NEW_LINE DEDENT else : NEW_LINE INDENT k = 1 - k NEW_LINE DEDENT DEDENT DEDENT return p [ n ] NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = 20 NEW_LINE print ( partitions ( N ) ) NEW_LINE DEDENT " V353,"class GFG { static boolean isSquarePossible ( int arr [ ] , int n , int l ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= l ) cnt ++ ; if ( cnt >= l ) return true ; } return false ; } static int maxArea ( int arr [ ] , int n ) { int l = 0 , r = n ; int len = 0 ; while ( l <= r ) { int m = l + ( ( r - l ) / 2 ) ; if ( isSquarePossible ( arr , n , m ) ) { len = m ; l = m + 1 ; } else r = m - 1 ; } return ( len * len ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 5 , 5 } ; int n = arr . length ; System . out . println ( maxArea ( arr , n ) ) ; } } ","def isSquarePossible ( arr , n , l ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] >= l : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT if cnt >= l : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def maxArea ( arr , n ) : NEW_LINE INDENT l , r = 0 , n NEW_LINE len = 0 NEW_LINE while l <= r : NEW_LINE INDENT m = l + ( ( r - l ) // 2 ) NEW_LINE if isSquarePossible ( arr , n , m ) : NEW_LINE INDENT len = m NEW_LINE l = m + 1 NEW_LINE DEDENT else : NEW_LINE INDENT r = m - 1 NEW_LINE DEDENT DEDENT return ( len * len ) NEW_LINE DEDENT arr = [ 1 , 3 , 4 , 5 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxArea ( arr , n ) ) NEW_LINE " V354,"import java . io . * ; class GFG { static int findEvenPair ( int A [ ] , int N ) { int evenPair = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] | A [ j ] ) % 2 == 0 ) evenPair ++ ; } } return evenPair ; } public static void main ( String [ ] args ) { int A [ ] = { 5 , 6 , 2 , 8 } ; int N = A . length ; System . out . println ( findEvenPair ( A , N ) ) ; } } ","def findEvenPair ( A , N ) : NEW_LINE INDENT evenPair = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( A [ i ] | A [ j ] ) % 2 == 0 : NEW_LINE INDENT evenPair += 1 NEW_LINE DEDENT DEDENT DEDENT return evenPair NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT A = [ 5 , 6 , 2 , 8 ] NEW_LINE N = len ( A ) NEW_LINE print ( findEvenPair ( A , N ) ) NEW_LINE DEDENT " V355,"import java . io . * ; class GFG { static int pairORSum ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) ans += arr [ i ] | arr [ j ] ; return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; System . out . println ( pairORSum ( arr , n ) ) ; } } ","def pairORSum ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( ( i + 1 ) , n ) : NEW_LINE INDENT ans = ans + arr [ i ] | arr [ j ] NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( pairORSum ( arr , n ) ) NEW_LINE " V356,"class GFG { static int MAX = 26 ; static boolean targetstring ( String str1 , String str2 ) { int l1 = str1 . length ( ) ; int l2 = str2 . length ( ) ; if ( l1 != l2 ) return false ; int [ ] map = new int [ MAX ] ; for ( int i = 0 ; i < l1 ; i ++ ) map [ str1 . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < l2 ; i ++ ) { map [ str2 . charAt ( i ) - ' a ' ] -- ; if ( map [ str2 . charAt ( i ) - ' a ' ] < 0 ) return false ; } return true ; } public static void main ( String args [ ] ) { String str1 = "" geeksforgeeks "" ; String str2 = "" geegeeksksfor "" ; if ( targetstring ( str1 , str2 ) ) System . out . print ( "" YES "" ) ; else System . out . print ( "" NO "" ) ; } } ","MAX = 26 NEW_LINE def targetstring ( str1 , str2 ) : NEW_LINE INDENT l1 = len ( str1 ) NEW_LINE l2 = len ( str2 ) NEW_LINE if ( l1 != l2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT map = [ 0 ] * MAX NEW_LINE for i in range ( l1 ) : NEW_LINE INDENT map [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( l2 ) : NEW_LINE INDENT map [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] -= 1 NEW_LINE if ( map [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] < 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str1 = "" geeksforgeeks "" NEW_LINE str2 = "" geegeeksksfor "" NEW_LINE if ( targetstring ( str1 , str2 ) ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT DEDENT " V357,"import java . util . * ; class GFG { static int maxLength ( String s , int n ) { int ans = Integer . MIN_VALUE ; Vector < Integer > A = new Vector < Integer > ( ) ; Vector < Integer > L = new Vector < Integer > ( ) ; Vector < Integer > R = new Vector < Integer > ( ) ; int [ ] freq = new int [ n + 5 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( s . charAt ( j ) - ' a ' == i ) count ++ ; freq [ j ] = count ; } for ( int j = 1 ; j < n ; j ++ ) { L . add ( ( 2 * freq [ j - 1 ] ) - j ) ; R . add ( ( 2 * freq [ j ] ) - j ) ; } int max_len = Integer . MIN_VALUE ; int min_val = Integer . MAX_VALUE ; for ( int j = 0 ; j < L . size ( ) ; j ++ ) { min_val = Math . min ( min_val , L . get ( j ) ) ; A . add ( min_val ) ; int l = 0 , r = j ; while ( l <= r ) { int mid = ( l + r ) >> 1 ; if ( A . get ( mid ) <= R . get ( j ) ) { max_len = Math . max ( max_len , j - mid + 1 ) ; r = mid - 1 ; } else { l = mid + 1 ; } } } ans = Math . max ( ans , max_len ) ; A . clear ( ) ; R . clear ( ) ; L . clear ( ) ; } return ans ; } public static void main ( String [ ] args ) { String s = "" ababbbacbcbcca "" ; int n = s . length ( ) ; System . out . println ( maxLength ( s , n ) ) ; } } ","import sys NEW_LINE def maxLength ( s , n ) : NEW_LINE INDENT ans = - ( sys . maxsize + 1 ) ; NEW_LINE A , L , R = [ ] , [ ] , [ ] ; NEW_LINE freq = [ 0 ] * ( n + 5 ) ; NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT count = 0 ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( ord ( s [ j ] ) - ord ( ' a ' ) == i ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT freq [ j ] = count ; NEW_LINE DEDENT for j in range ( n ) : NEW_LINE INDENT L . append ( ( 2 * freq [ j - 1 ] ) - j ) ; NEW_LINE R . append ( ( 2 * freq [ j ] ) - j ) ; NEW_LINE DEDENT max_len = - ( sys . maxsize + 1 ) ; NEW_LINE min_val = sys . maxsize ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT min_val = min ( min_val , L [ j ] ) ; NEW_LINE A . append ( min_val ) ; NEW_LINE l = 0 ; r = j ; NEW_LINE while ( l <= r ) : NEW_LINE INDENT mid = ( l + r ) >> 1 ; NEW_LINE if ( A [ mid ] <= R [ j ] ) : NEW_LINE INDENT max_len = max ( max_len , j - mid + 1 ) ; NEW_LINE r = mid - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT l = mid + 1 ; NEW_LINE DEDENT DEDENT DEDENT ans = max ( ans , max_len ) ; NEW_LINE A . clear ( ) ; NEW_LINE R . clear ( ) ; NEW_LINE L . clear ( ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" ababbbacbcbcca "" ; NEW_LINE n = len ( s ) ; NEW_LINE print ( maxLength ( s , n ) ) ; NEW_LINE DEDENT " V358,"class GFG { static boolean isPrime ( int p ) { double checkNumber = Math . pow ( 2 , p ) - 1 ; double nextval = 4 % checkNumber ; for ( int i = 1 ; i < p - 1 ; i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ; return ( nextval == 0 ) ; } public static void main ( String [ ] args ) { int p = 7 ; double checkNumber = Math . pow ( 2 , p ) - 1 ; if ( isPrime ( p ) ) System . out . println ( ( int ) checkNumber + "" ▁ is ▁ Prime . "" ) ; else System . out . println ( ( int ) checkNumber + "" ▁ is ▁ not ▁ Prime . "" ) ; } } ","def isPrime ( p ) : NEW_LINE INDENT checkNumber = 2 ** p - 1 NEW_LINE nextval = 4 % checkNumber NEW_LINE for i in range ( 1 , p - 1 ) : NEW_LINE INDENT nextval = ( nextval * nextval - 2 ) % checkNumber NEW_LINE DEDENT if ( nextval == 0 ) : return True NEW_LINE else : return False NEW_LINE DEDENT p = 7 NEW_LINE checkNumber = 2 ** p - 1 NEW_LINE if isPrime ( p ) : NEW_LINE INDENT print ( checkNumber , ' is ▁ Prime . ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( checkNumber , ' is ▁ not ▁ Prime ' ) NEW_LINE DEDENT " V359,"import java . io . * ; import java . util . Arrays ; class GFG { static int minOps ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int max = arr [ arr . length - 1 ] ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ; else res += ( max - arr [ i ] ) / k ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 21 , 33 , 9 , 45 , 63 } ; int n = arr . length ; int k = 6 ; System . out . println ( minOps ( arr , n , k ) ) ; } } ","def minOps ( arr , n , k ) : NEW_LINE INDENT max1 = max ( arr ) NEW_LINE res = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( ( max1 - arr [ i ] ) % k != 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT res += ( max1 - arr [ i ] ) / k NEW_LINE DEDENT DEDENT return int ( res ) NEW_LINE DEDENT arr = [ 21 , 33 , 9 , 45 , 63 ] NEW_LINE n = len ( arr ) NEW_LINE k = 6 NEW_LINE print ( minOps ( arr , n , k ) ) NEW_LINE " V360,"class GFG { static int minChanges ( char [ ] str , int n ) { int count = 0 , zeros = 0 , ones = 0 ; if ( str [ 0 ] != '1' ) { count ++ ; ones ++ ; } for ( int i = 1 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) zeros ++ ; else ones ++ ; if ( zeros > ones ) { zeros -- ; ones ++ ; count ++ ; } } return count ; } public static void main ( String [ ] args ) { char [ ] str = ""0000"" . toCharArray ( ) ; int n = str . length ; System . out . print ( minChanges ( str , n ) ) ; } } ","def minChanges ( str , n ) : NEW_LINE INDENT count , zeros , ones = 0 , 0 , 0 NEW_LINE if ( ord ( str [ 0 ] ) != ord ( '1' ) ) : NEW_LINE INDENT count += 1 NEW_LINE ones += 1 NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT if ( ord ( str [ i ] ) == ord ( '0' ) ) : NEW_LINE INDENT zeros += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ones += 1 NEW_LINE DEDENT if ( zeros > ones ) : NEW_LINE INDENT zeros -= 1 NEW_LINE ones += 1 NEW_LINE count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = ""0000"" NEW_LINE n = len ( str ) NEW_LINE print ( minChanges ( str , n ) ) NEW_LINE DEDENT " V361,"public class GFG { static final int MAX = 1000001 ; static int primeUpto [ ] = new int [ MAX ] ; static void SieveOfEratosthenes ( ) { int isPrime [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) isPrime [ i ] = 1 ; isPrime [ 0 ] = isPrime [ 1 ] = 0 ; for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( isPrime [ i ] == 1 ) { for ( int j = i * 2 ; j < MAX ; j += i ) isPrime [ j ] = 0 ; } } for ( int i = 1 ; i < MAX ; i ++ ) { primeUpto [ i ] = primeUpto [ i - 1 ] ; if ( isPrime [ i ] == 1 ) primeUpto [ i ] ++ ; } } static int countOfNumbers ( int N , int K ) { SieveOfEratosthenes ( ) ; int low = 1 , high = N , ans = 0 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( mid - primeUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } ans = ans != 0 ? N - ans + 1 : 0 ; return ans ; } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; System . out . println ( countOfNumbers ( N , K ) ) ; } } ","MAX = 1000001 NEW_LINE MAX_sqrt = MAX ** ( 0.5 ) NEW_LINE primeUpto = [ 0 ] * ( MAX ) NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT isPrime = [ 1 ] * ( MAX ) NEW_LINE isPrime [ 0 ] , isPrime [ 1 ] = 0 , 0 NEW_LINE for i in range ( 2 , int ( MAX_sqrt ) ) : NEW_LINE INDENT if isPrime [ i ] == 1 : NEW_LINE INDENT for j in range ( i * 2 , MAX , i ) : NEW_LINE INDENT isPrime [ j ] = 0 NEW_LINE DEDENT DEDENT DEDENT for i in range ( 1 , MAX ) : NEW_LINE INDENT primeUpto [ i ] = primeUpto [ i - 1 ] NEW_LINE if isPrime [ i ] == 1 : NEW_LINE INDENT primeUpto [ i ] += 1 NEW_LINE DEDENT DEDENT DEDENT def countOfNumbers ( N , K ) : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE low , high , ans = 1 , N , 0 NEW_LINE while low <= high : NEW_LINE INDENT mid = ( low + high ) >> 1 NEW_LINE if mid - primeUpto [ mid ] >= K : NEW_LINE INDENT ans = mid NEW_LINE high = mid - 1 NEW_LINE DEDENT else : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT DEDENT return ( N - ans + 1 ) if ans else 0 NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N , K = 10 , 3 NEW_LINE print ( countOfNumbers ( N , K ) ) NEW_LINE DEDENT " V362,"class GFG { static boolean isRectangle ( int a , int b , int c , int d ) { if ( a == b && a == c && a == d && c == d && b == c && b == d ) return true ; else if ( a == b && c == d ) return true ; else if ( a == d && c == b ) return true ; else if ( a == c && d == b ) return true ; else return false ; } public static void main ( String [ ] args ) { int a = 1 , b = 2 , c = 3 , d = 4 ; if ( isRectangle ( a , b , c , d ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isRectangle ( a , b , c , d ) : NEW_LINE INDENT if a == b == c == d : NEW_LINE INDENT return True NEW_LINE DEDENT elif a == b and c == d : NEW_LINE INDENT return True NEW_LINE DEDENT elif a == d and c == b : NEW_LINE INDENT return True NEW_LINE DEDENT elif a == c and d == b : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT a , b , c , d = 1 , 2 , 3 , 4 NEW_LINE print ( "" Yes "" if isRectangle ( a , b , c , d ) else "" No "" ) NEW_LINE " V363,"public class GFG { public static int countSubArrays ( int arr [ ] , int x ) { int count = 0 ; int start = - 1 , end = - 1 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] < x ) { if ( start == - 1 ) { start = i ; end = i ; } else { end = i ; } } else { if ( start != - 1 && end != - 1 ) { int length = end - start + 1 ; count = count + ( ( length * ( length + 1 ) ) / 2 ) ; } start = - 1 ; end = - 1 ; } } if ( start != - 1 && end != - 1 ) { int length = end - start + 1 ; count = count + ( ( length * ( length + 1 ) ) / 2 ) ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 7 , 8 , 2 , 3 , 9 } ; int x = 6 ; System . out . println ( countSubArrays ( arr , x ) ) ; } } ","def countSubArrays ( arr , x , n ) : NEW_LINE INDENT count = 0 ; NEW_LINE start = - 1 ; end = - 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] < x ) : NEW_LINE INDENT if ( start == - 1 ) : NEW_LINE INDENT start = i ; NEW_LINE end = i ; NEW_LINE DEDENT else : NEW_LINE INDENT end = i ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( start != - 1 and end != - 1 ) : NEW_LINE INDENT length = end - start + 1 ; NEW_LINE count = count + ( ( length * ( length + 1 ) ) / 2 ) ; NEW_LINE DEDENT start = - 1 ; NEW_LINE end = - 1 ; NEW_LINE DEDENT DEDENT if ( start != - 1 and end != - 1 ) : NEW_LINE INDENT length = end - start + 1 ; NEW_LINE count = count + ( ( length * ( length + 1 ) ) / 2 ) ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT arr = [ 1 , 5 , 7 , 8 , 2 , 3 , 9 ] ; NEW_LINE x = 6 ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( countSubArrays ( arr , x , n ) ) ; NEW_LINE " V364,"import java . io . * ; class GFG { static float circumferenceparallelogram ( float a , float b ) { return ( ( 2 * a ) + ( 2 * b ) ) ; } public static void main ( String arg [ ] ) { float a = 10 , b = 8 ; System . out . print ( "" Circumference ▁ of ▁ a ▁ given ▁ Parallelogram ▁ is ▁ : "" ) ; System . out . println ( circumferenceparallelogram ( a , b ) ) ; } } ","def circumferenceparallelogram ( a , b ) : NEW_LINE INDENT return ( ( 2 * a ) + ( 2 * b ) ) NEW_LINE DEDENT a = 10 NEW_LINE b = 8 NEW_LINE print ( "" Circumference ▁ of ▁ a ▁ given ▁ Parallelogram ▁ is ▁ : "" , round ( circumferenceparallelogram ( a , b ) , 4 ) ) NEW_LINE " V365,"import java . util . * ; class GFG { static int singleNumber ( int a [ ] , int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i : a ) { s . add ( i ) ; } int arr_sum = 0 ; for ( int i : a ) { arr_sum += i ; } int set_sum = 0 ; for ( int i : s ) { set_sum += i ; } return ( 3 * set_sum - arr_sum ) / 2 ; } public static void main ( String [ ] args ) { int a [ ] = { 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 } ; int n = a . length ; System . out . println ( "" The ▁ element ▁ with ▁ single ▁ "" + "" occurrence ▁ is ▁ "" + singleNumber ( a , n ) ) ; } } ","def singleNumber ( nums ) : NEW_LINE INDENT return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2 NEW_LINE DEDENT a = [ 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 ] NEW_LINE print ( "" The ▁ element ▁ with ▁ single ▁ occurrence ▁ is ▁ "" , int ( singleNumber ( a ) ) ) NEW_LINE " V366,"import java . io . * ; class Nth { public int nthTerm ( int N ) { return ( N * ( ( N / 2 ) + ( ( N % 2 ) * 2 ) + N ) ) ; } } class GFG { public static void main ( String [ ] args ) { int N = 5 ; Nth a = new Nth ( ) ; System . out . println ( "" Nth ▁ term ▁ for ▁ N ▁ = ▁ "" + N + "" ▁ : ▁ "" + a . nthTerm ( N ) ) ; } } ","def nthTerm ( N ) : NEW_LINE INDENT return ( N * ( ( N // 2 ) + ( ( N % 2 ) * 2 ) + N ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 5 NEW_LINE print ( "" Nth ▁ term ▁ for ▁ N ▁ = ▁ "" , N , "" ▁ : ▁ "" , nthTerm ( N ) ) NEW_LINE DEDENT " V367,"import java . io . * ; class Ratio { static boolean isRatioPossible ( int lowCost , int upCost , int lowQuant , int upQuant , int r ) { for ( int i = lowQuant ; i <= upQuant ; i ++ ) { int ans = i * r ; if ( lowCost <= ans && ans <= upCost ) return true ; } return false ; } public static void main ( String args [ ] ) { int lowCost = 14 , upCost = 30 , lowQuant = 5 , upQuant = 12 , r = 9 ; if ( isRatioPossible ( lowCost , upCost , lowQuant , upQuant , r ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isRatioPossible ( lowCost , upCost , lowQuant , upQuant , r ) : NEW_LINE INDENT for i in range ( lowQuant , upQuant + 1 ) : NEW_LINE INDENT ans = i * r NEW_LINE if ( lowCost <= ans and ans <= upCost ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT lowCost = 14 ; upCost = 30 NEW_LINE lowQuant = 5 ; upQuant = 12 ; r = 9 NEW_LINE if ( isRatioPossible ( lowCost , upCost , lowQuant , upQuant , r ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V368,"class MatrixChainMultiplication { static int MatrixChainOrder ( int p [ ] , int i , int j ) { if ( i == j ) return 0 ; int min = Integer . MAX_VALUE ; for ( int k = i ; k < j ; k ++ ) { int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( count < min ) min = count ; } return min ; } public static void main ( String args [ ] ) { int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 , 3 } ; int n = arr . length ; System . out . println ( "" Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ "" + MatrixChainOrder ( arr , 1 , n - 1 ) ) ; } } ","import sys NEW_LINE def MatrixChainOrder ( p , i , j ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT return 0 NEW_LINE DEDENT _min = sys . maxsize NEW_LINE for k in range ( i , j ) : NEW_LINE INDENT count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ) NEW_LINE if count < _min : NEW_LINE INDENT _min = count ; NEW_LINE DEDENT DEDENT return _min ; NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( "" Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ "" , MatrixChainOrder ( arr , 1 , n - 1 ) ) ; NEW_LINE " V369,"import java . util . * ; class GFG { static int countDigit ( long n ) { if ( n == 0 ) return 0 ; return 1 + countDigit ( n / 10 ) ; } public static void main ( String [ ] args ) { long n = 345289467 ; System . out . print ( "" Number ▁ of ▁ digits ▁ : ▁ "" + countDigit ( n ) ) ; } } ","def countDigit ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return 1 + countDigit ( n // 10 ) NEW_LINE DEDENT n = 345289467 NEW_LINE print ( "" Number ▁ of ▁ digits ▁ : ▁ % ▁ d "" % ( countDigit ( n ) ) ) NEW_LINE " V370,"import java . util . Stack ; class GFG { static void printPrevSmaller ( int arr [ ] , int n ) { Stack < Integer > S = new Stack < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( ! S . empty ( ) && S . peek ( ) >= arr [ i ] ) { S . pop ( ) ; } if ( S . empty ( ) ) { System . out . print ( "" _ , ▁ "" ) ; } else { System . out . print ( S . peek ( ) + "" , ▁ "" ) ; } S . push ( arr [ i ] ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 0 , 2 , 5 } ; int n = arr . length ; printPrevSmaller ( arr , n ) ; } } ","import math as mt NEW_LINE def printPrevSmaller ( arr , n ) : NEW_LINE INDENT S = list ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT while ( len ( S ) > 0 and S [ - 1 ] >= arr [ i ] ) : NEW_LINE INDENT S . pop ( ) NEW_LINE DEDENT if ( len ( S ) == 0 ) : NEW_LINE INDENT print ( "" _ , ▁ "" , end = "" "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( S [ - 1 ] , end = "" , ▁ "" ) NEW_LINE DEDENT S . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT arr = [ 1 , 3 , 0 , 2 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE printPrevSmaller ( arr , n ) NEW_LINE " V371,"class GFG { static double wastedWater ( double V , double M , double N ) { double wasted_amt , amt_per_min , time_to_fill ; amt_per_min = M - N ; time_to_fill = V / amt_per_min ; wasted_amt = N * time_to_fill ; return wasted_amt ; } public static void main ( String [ ] args ) { double V , M , N ; V = 700 ; M = 10 ; N = 3 ; System . out . println ( wastedWater ( V , M , N ) ) ; V = 1000 ; M = 100 ; N = 50 ; System . out . println ( wastedWater ( V , M , N ) ) ; } } ","def wastedWater ( V , M , N ) : NEW_LINE INDENT amt_per_min = M - N NEW_LINE time_to_fill = V / amt_per_min NEW_LINE wasted_amt = N * time_to_fill NEW_LINE return wasted_amt NEW_LINE DEDENT V = 700 NEW_LINE M = 10 NEW_LINE N = 3 NEW_LINE print ( wastedWater ( V , M , N ) ) NEW_LINE V = 1000 NEW_LINE M = 100 NEW_LINE N = 50 NEW_LINE print ( wastedWater ( V , M , N ) ) NEW_LINE " V372,"public class GFG { static final int NO_OF_CHARS = 256 ; static char getSecondMostFreq ( String str ) { int [ ] count = new int [ NO_OF_CHARS ] ; int i ; for ( i = 0 ; i < str . length ( ) ; i ++ ) ( count [ str . charAt ( i ) ] ) ++ ; int first = 0 , second = 0 ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( count [ i ] > count [ first ] ) { second = first ; first = i ; } else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ; } return ( char ) second ; } public static void main ( String args [ ] ) { String str = "" geeksforgeeks "" ; char res = getSecondMostFreq ( str ) ; if ( res != ' \0' ) System . out . println ( "" Second ▁ most ▁ frequent ▁ char "" + "" ▁ is ▁ "" + res ) ; else System . out . println ( "" No ▁ second ▁ most ▁ frequent "" + "" character "" ) ; } } ","def getSecondMostFreq ( str ) : NEW_LINE INDENT NO_OF_CHARS = 256 NEW_LINE count = [ 0 ] * NO_OF_CHARS NEW_LINE for i in range ( len ( str ) ) : NEW_LINE INDENT count [ ord ( str [ i ] ) ] += 1 NEW_LINE DEDENT first , second = 0 , 0 NEW_LINE for i in range ( NO_OF_CHARS ) : NEW_LINE INDENT if count [ i ] > count [ first ] : NEW_LINE INDENT second = first NEW_LINE first = i NEW_LINE DEDENT elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) : NEW_LINE INDENT second = i NEW_LINE DEDENT DEDENT return chr ( second ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str = "" geeksforgeeks "" NEW_LINE res = getSecondMostFreq ( str ) NEW_LINE if res != ' \0' : NEW_LINE INDENT print ( "" Second ▁ most ▁ frequent ▁ char ▁ is "" , res ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No ▁ second ▁ most ▁ frequent ▁ character "" ) NEW_LINE DEDENT DEDENT " V373,"import java . io . * ; class GFG { static float exponential ( int n , float x ) { float sum = 1 ; for ( int i = n - 1 ; i > 0 ; -- i ) sum = 1 + x * sum / i ; return sum ; } public static void main ( String [ ] args ) { int n = 10 ; float x = 1 ; System . out . println ( "" e ^ x ▁ = ▁ "" + exponential ( n , x ) ) ; } } ","def exponential ( n , x ) : NEW_LINE INDENT sum = 1.0 NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT sum = 1 + x * sum / i NEW_LINE DEDENT print ( "" e ^ x ▁ = "" , sum ) NEW_LINE DEDENT n = 10 NEW_LINE x = 1.0 NEW_LINE exponential ( n , x ) NEW_LINE " V374,"import java . io . * ; import java . util . * ; public class GFG { static int solve ( int [ ] A , int n ) { int i , cnt = 0 , j ; int [ ] parent = new int [ n + 1 ] ; int [ ] vis = new int [ n + 1 ] ; for ( i = 0 ; i < n + 1 ; i ++ ) { parent [ i ] = - 1 ; vis [ i ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { j = i ; if ( parent [ j ] == - 1 ) { while ( parent [ j ] == - 1 ) { parent [ j ] = i ; j = ( j + A [ j ] + 1 ) % n ; } if ( parent [ j ] == i ) { while ( vis [ j ] == 0 ) { vis [ j ] = 1 ; cnt ++ ; j = ( j + A [ j ] + 1 ) % n ; } } } } return cnt ; } public static void main ( String args [ ] ) { int [ ] A = { 0 , 0 , 0 , 2 } ; int n = A . length ; System . out . print ( solve ( A , n ) ) ; } } ","def solve ( A , n ) : NEW_LINE INDENT cnt = 0 NEW_LINE parent = [ None ] * ( n + 1 ) NEW_LINE vis = [ None ] * ( n + 1 ) NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT parent [ i ] = - 1 NEW_LINE vis [ i ] = 0 NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT j = i NEW_LINE if ( parent [ j ] == - 1 ) : NEW_LINE INDENT while ( parent [ j ] == - 1 ) : NEW_LINE INDENT parent [ j ] = i NEW_LINE j = ( j + A [ j ] + 1 ) % n NEW_LINE DEDENT if ( parent [ j ] == i ) : NEW_LINE INDENT while ( vis [ j ] == 0 ) : NEW_LINE INDENT vis [ j ] = 1 NEW_LINE cnt = cnt + 1 NEW_LINE j = ( j + A [ j ] + 1 ) % n NEW_LINE DEDENT DEDENT DEDENT DEDENT return cnt NEW_LINE DEDENT A = [ 0 , 0 , 0 , 2 ] NEW_LINE n = len ( A ) NEW_LINE print ( solve ( A , n ) ) NEW_LINE " V375,"import java . util . * ; class GFG { static int getCount ( int [ ] v , int n ) { Arrays . sort ( v ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int tmp = n - 1 - upperBound ( v , n , v [ i ] - 1 ) ; if ( tmp == v [ i ] ) cnt ++ ; } return cnt ; } static int upperBound ( int [ ] array , int length , int value ) { int low = 0 ; int high = length ; while ( low < high ) { final int mid = ( low + high ) / 2 ; if ( value >= array [ mid ] ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static void main ( String [ ] args ) { int n = 4 ; int [ ] v = { 1 , 2 , 3 , 4 } ; System . out . println ( getCount ( v , n ) ) ; } } ","from bisect import bisect as upper_bound NEW_LINE def getCount ( v , n ) : NEW_LINE INDENT v = sorted ( v ) NEW_LINE cnt = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT tmp = n - 1 - upper_bound ( v , v [ i ] - 1 ) NEW_LINE if ( tmp == v [ i ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT n = 4 NEW_LINE v = [ ] NEW_LINE v . append ( 1 ) NEW_LINE v . append ( 2 ) NEW_LINE v . append ( 3 ) NEW_LINE v . append ( 4 ) NEW_LINE print ( getCount ( v , n ) ) NEW_LINE " V376,"class GFG { static String lexNext ( String str , int n ) { char [ ] s = str . toCharArray ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != ' z ' ) { s [ i ] ++ ; return String . valueOf ( s ) ; } s [ i ] = ' a ' ; } return null ; } static public void main ( String [ ] args ) { String S = "" abcdeg "" , T = "" abcfgh "" ; int n = S . length ( ) ; String res = lexNext ( S , n ) ; if ( res != T ) { System . out . println ( res ) ; } else { System . out . println ( "" - 1"" ) ; } } } ","def lexNext ( s , n ) : NEW_LINE INDENT for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if s [ i ] != ' z ' : NEW_LINE INDENT k = ord ( s [ i ] ) NEW_LINE s [ i ] = chr ( k + 1 ) NEW_LINE return ' ' . join ( s ) NEW_LINE DEDENT s [ i ] = ' a ' NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT S = "" abcdeg "" NEW_LINE T = "" abcfgh "" NEW_LINE n = len ( S ) NEW_LINE S = list ( S ) NEW_LINE res = lexNext ( S , n ) NEW_LINE if res != T : NEW_LINE INDENT print ( res ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT " V377,"public class GFG { static int bridge_length ( int trainLength , int Speed , int Time ) { return ( ( Time * Speed ) - trainLength ) ; } public static void main ( String [ ] args ) { int trainLength = 120 ; int Speed = 30 ; int Time = 18 ; System . out . print ( "" Length ▁ of ▁ bridge ▁ = ▁ "" + bridge_length ( trainLength , Speed , Time ) + "" ▁ meters "" ) ; } } ","def bridge_length ( trainLength , Speed , Time ) : NEW_LINE INDENT return ( ( Time * Speed ) - trainLength ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT trainLength = 120 NEW_LINE Speed = 30 NEW_LINE Time = 18 NEW_LINE print ( "" Length ▁ of ▁ bridge ▁ = ▁ "" , bridge_length ( trainLength , Speed , Time ) , "" meters "" ) NEW_LINE DEDENT " V378,"class GFG { static final int MAX = 1000006 ; static void sieve ( int count [ ] ) { for ( int i = 2 ; i * i <= MAX ; i ++ ) { if ( count [ i ] == 0 ) { for ( int j = 2 * i ; j < MAX ; j += i ) count [ j ] ++ ; count [ i ] = 1 ; } } } static int query ( int count [ ] , int l , int r ) { int sum = 0 ; for ( int i = l ; i <= r ; i ++ ) sum += count [ i ] ; return sum ; } public static void main ( String [ ] args ) { int count [ ] = new int [ MAX ] ; sieve ( count ) ; System . out . println ( query ( count , 6 , 10 ) + "" ▁ "" + query ( count , 1 , 5 ) ) ; } } ","MAX = 100006 ; NEW_LINE count = [ 0 ] * MAX ; NEW_LINE def sieve ( ) : NEW_LINE INDENT i = 2 ; NEW_LINE while ( i * i <= MAX ) : NEW_LINE INDENT if ( count [ i ] == 0 ) : NEW_LINE INDENT for j in range ( 2 * i , MAX , i ) : NEW_LINE INDENT count [ j ] += 1 ; NEW_LINE DEDENT count [ i ] = 1 ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT DEDENT def query ( l , r ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT sum += count [ i ] ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT sieve ( ) ; NEW_LINE print ( query ( 6 , 10 ) , query ( 1 , 5 ) ) ; NEW_LINE " V379,"class GFG { static boolean canBecomeEmpty ( String str , String sub_str ) { while ( str . length ( ) > 0 ) { int idx = str . indexOf ( sub_str ) ; if ( idx == - 1 ) { break ; } str = str . replaceFirst ( sub_str , "" "" ) ; } return ( str . length ( ) == 0 ) ; } public static void main ( String [ ] args ) { String str = "" GEEGEEKSKS "" , sub_str = "" GEEKS "" ; if ( canBecomeEmpty ( str , sub_str ) ) { System . out . print ( "" \n Yes "" ) ; } else { System . out . print ( "" \n No "" ) ; } } } ","def canBecomeEmpty ( string , sub_str ) : NEW_LINE INDENT while len ( string ) > 0 : NEW_LINE INDENT idx = string . find ( sub_str ) NEW_LINE if idx == - 1 : NEW_LINE INDENT break NEW_LINE DEDENT string = string . replace ( sub_str , "" "" , 1 ) NEW_LINE DEDENT return ( len ( string ) == 0 ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" GEEGEEKSKS "" NEW_LINE sub_str = "" GEEKS "" NEW_LINE if canBecomeEmpty ( string , sub_str ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V380,"import java . util . * ; class GFG { static void printOrder ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; for ( int j = n - 1 ; j >= n / 2 ; j -- ) System . out . print ( arr [ j ] + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , 7 } ; int n = arr . length ; printOrder ( arr , n ) ; } } ","def printOrder ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE i = 0 NEW_LINE while ( i < n / 2 ) : NEW_LINE INDENT print arr [ i ] , NEW_LINE i = i + 1 NEW_LINE DEDENT j = n - 1 NEW_LINE while j >= n / 2 : NEW_LINE INDENT print arr [ j ] , NEW_LINE j = j - 1 NEW_LINE DEDENT DEDENT arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE printOrder ( arr , n ) NEW_LINE " V381,"import java . util . * ; class GFG { static int countSwap ( String str ) { int n = str . length ( ) ; char s [ ] = str . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int left = i ; int right = n - left - 1 ; while ( left < right ) { if ( s [ left ] == s [ right ] ) { break ; } else { right -- ; } } if ( left == right ) { return - 1 ; } else { for ( int j = right ; j < n - left - 1 ; j ++ ) { char t = s [ j ] ; s [ j ] = s [ j + 1 ] ; s [ j + 1 ] = t ; count ++ ; } } } return count ; } public static void main ( String [ ] args ) { String s = "" geeksfgeeks "" ; int count = countSwap ( s ) ; System . out . println ( count ) ; } } ","def CountSwap ( s , n ) : NEW_LINE INDENT s = list ( s ) NEW_LINE count = 0 NEW_LINE ans = True NEW_LINE for i in range ( n // 2 ) : NEW_LINE INDENT left = i NEW_LINE right = n - left - 1 NEW_LINE while left < right : NEW_LINE INDENT if s [ left ] == s [ right ] : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT right -= 1 NEW_LINE DEDENT DEDENT if left == right : NEW_LINE INDENT ans = False NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT for j in range ( right , n - left - 1 ) : NEW_LINE INDENT ( s [ j ] , s [ j + 1 ] ) = ( s [ j + 1 ] , s [ j ] ) NEW_LINE count += 1 NEW_LINE DEDENT DEDENT DEDENT if ans : NEW_LINE INDENT print ( count ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' - 1' ) NEW_LINE DEDENT DEDENT s = ' geeksfgeeks ' NEW_LINE n = len ( s ) NEW_LINE CountSwap ( s , n ) NEW_LINE " V382,"import java . util . * ; class solution { static boolean divisible ( String N , int digit ) { int ans = 0 ; for ( int i = 0 ; i < N . length ( ) ; i ++ ) { ans = ( ans * 10 + ( N . charAt ( i ) - '0' ) ) ; ans %= digit ; } return ( ans == 0 ) ; } static int allDigits ( String N ) { Boolean [ ] divide = new Boolean [ 10 ] ; Arrays . fill ( divide , Boolean . FALSE ) ; divide [ 1 ] = true ; for ( int digit = 2 ; digit <= 9 ; digit ++ ) { if ( divisible ( N , digit ) ) divide [ digit ] = true ; } int result = 0 ; for ( int i = 0 ; i < N . length ( ) ; i ++ ) { if ( divide [ N . charAt ( i ) - '0' ] == true ) result ++ ; } return result ; } public static void main ( String args [ ] ) { String N = ""122324"" ; System . out . println ( allDigits ( N ) ) ; } } ","def divisible ( N , digit ) : NEW_LINE INDENT ans = 0 ; NEW_LINE for i in range ( len ( N ) ) : NEW_LINE INDENT ans = ( ans * 10 + ( ord ( N [ i ] ) - ord ( '0' ) ) ) ; NEW_LINE ans %= digit ; NEW_LINE DEDENT return ( ans == 0 ) ; NEW_LINE DEDENT def allDigits ( N ) : NEW_LINE INDENT divide = [ False ] * 10 ; NEW_LINE divide [ 1 ] = True ; NEW_LINE for digit in range ( 2 , 10 ) : NEW_LINE INDENT if ( divisible ( N , digit ) ) : NEW_LINE INDENT divide [ digit ] = True ; NEW_LINE DEDENT DEDENT result = 0 ; NEW_LINE for i in range ( len ( N ) ) : NEW_LINE INDENT if ( divide [ ( ord ( N [ i ] ) - ord ( '0' ) ) ] == True ) : NEW_LINE INDENT result += 1 ; NEW_LINE DEDENT DEDENT return result ; NEW_LINE DEDENT N = ""122324"" ; NEW_LINE print ( allDigits ( N ) ) ; NEW_LINE " V383,"import java . util . * ; class GFG { static long getPairs ( Vector < Integer > A , Vector < Integer > B , int n ) { int [ ] D = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { D [ i ] = A . get ( i ) - B . get ( i ) ; } Arrays . sort ( D ) ; long total = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( D [ i ] > 0 ) { total += n - i - 1 ; } else { int k = upper_bound ( D , 0 , D . length , - D [ i ] ) ; total += n - k ; } } return total ; } static int upper_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } public static void main ( String [ ] args ) { int n = 5 ; Vector < Integer > A = new Vector < Integer > ( ) ; Vector < Integer > B = new Vector < Integer > ( ) ; A . add ( 4 ) ; A . add ( 8 ) ; A . add ( 2 ) ; A . add ( 6 ) ; A . add ( 2 ) ; B . add ( 4 ) ; B . add ( 5 ) ; B . add ( 4 ) ; B . add ( 1 ) ; B . add ( 3 ) ; System . out . print ( getPairs ( A , B , n ) ) ; } } ","import bisect NEW_LINE def getPairs ( A , B , n ) : NEW_LINE INDENT D = [ 0 ] * ( n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT D [ i ] = A [ i ] - B [ i ] NEW_LINE DEDENT D . sort ( ) NEW_LINE total = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( D [ i ] > 0 ) : NEW_LINE INDENT total += n - i - 1 NEW_LINE DEDENT else : NEW_LINE INDENT k = bisect . bisect_right ( D , - D [ i ] , 0 , len ( D ) ) NEW_LINE total += n - k NEW_LINE DEDENT DEDENT return total NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 5 NEW_LINE A = [ ] NEW_LINE B = [ ] NEW_LINE A . append ( 4 ) ; NEW_LINE A . append ( 8 ) ; NEW_LINE A . append ( 2 ) ; NEW_LINE A . append ( 6 ) ; NEW_LINE A . append ( 2 ) ; NEW_LINE B . append ( 4 ) ; NEW_LINE B . append ( 5 ) ; NEW_LINE B . append ( 4 ) ; NEW_LINE B . append ( 1 ) ; NEW_LINE B . append ( 3 ) ; NEW_LINE print ( getPairs ( A , B , n ) ) NEW_LINE DEDENT " V384,"import java . util . * ; class GFG { static int MAX = 100002 ; static int f ( int i , int m , char s [ ] , int memoize [ ] [ ] ) { if ( i == s . length ) { return 0 ; } if ( memoize [ i ] [ m ] != - 1 ) { return memoize [ i ] [ m ] ; } int x = s [ i ] - '0' ; int ans = ( ( x + m ) % 3 == 0 && x % 2 == 0 ) ? 1 + f ( i + 1 , ( m + x ) % 3 , s , memoize ) : f ( i + 1 , ( m + x ) % 3 , s , memoize ) ; memoize [ i ] [ m ] = ans ; return memoize [ i ] [ m ] ; } static int countDivBy6 ( char s [ ] ) { int n = s . length ; int [ ] [ ] memoize = new int [ n + 1 ] [ 3 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { memoize [ i ] [ j ] = - 1 ; } } int ans = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == '0' ) { ans ++ ; } else { ans += f ( i , 0 , s , memoize ) ; } } return ans ; } public static void main ( String [ ] args ) { char s [ ] = ""4806"" . toCharArray ( ) ; System . out . println ( countDivBy6 ( s ) ) ; } } ","def f ( i , m , s , memoize ) : NEW_LINE INDENT if ( i == len ( s ) ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( memoize [ i ] [ m ] != - 1 ) : NEW_LINE INDENT return memoize [ i ] [ m ] NEW_LINE DEDENT x = ord ( s [ i ] ) - ord ( '0' ) NEW_LINE ans = ( ( ( x + m ) % 3 == 0 and x % 2 == 0 ) + f ( i + 1 , ( m + x ) % 3 , s , memoize ) ) NEW_LINE memoize [ i ] [ m ] = ans NEW_LINE return memoize [ i ] [ m ] NEW_LINE DEDENT def countDivBy6 ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE memoize = [ [ - 1 ] * 3 for i in range ( n + 1 ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] == '0' ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += f ( i , 0 , s , memoize ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = ""4806"" NEW_LINE print ( countDivBy6 ( s ) ) NEW_LINE DEDENT " V385,"class Main { static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) { int i = 0 ; int j = 0 ; int count ; int m1 = - 1 , m2 = - 1 ; for ( count = 0 ; count <= n ; count ++ ) { if ( i == n ) { m1 = m2 ; m2 = ar2 [ 0 ] ; break ; } else if ( j == n ) { m1 = m2 ; m2 = ar1 [ 0 ] ; break ; } if ( ar1 [ i ] < ar2 [ j ] ) { m1 = m2 ; m2 = ar1 [ i ] ; i ++ ; } else { m1 = m2 ; m2 = ar2 [ j ] ; j ++ ; } } return ( m1 + m2 ) / 2 ; } public static void main ( String [ ] args ) { int ar1 [ ] = { 1 , 12 , 15 , 26 , 38 } ; int ar2 [ ] = { 2 , 13 , 17 , 30 , 45 } ; int n1 = ar1 . length ; int n2 = ar2 . length ; if ( n1 == n2 ) System . out . println ( "" Median ▁ is ▁ "" + getMedian ( ar1 , ar2 , n1 ) ) ; else System . out . println ( "" arrays ▁ are ▁ of ▁ unequal ▁ size "" ) ; } } ","def getMedian ( ar1 , ar2 , n ) : NEW_LINE INDENT i = 0 NEW_LINE j = 0 NEW_LINE m1 = - 1 NEW_LINE m2 = - 1 NEW_LINE count = 0 NEW_LINE while count < n + 1 : NEW_LINE INDENT count += 1 NEW_LINE if i == n : NEW_LINE INDENT m1 = m2 NEW_LINE m2 = ar2 [ 0 ] NEW_LINE break NEW_LINE DEDENT elif j == n : NEW_LINE INDENT m1 = m2 NEW_LINE m2 = ar1 [ 0 ] NEW_LINE break NEW_LINE DEDENT if ar1 [ i ] < ar2 [ j ] : NEW_LINE INDENT m1 = m2 NEW_LINE m2 = ar1 [ i ] NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m1 = m2 NEW_LINE m2 = ar2 [ j ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT return ( m1 + m2 ) / 2 NEW_LINE DEDENT ar1 = [ 1 , 12 , 15 , 26 , 38 ] NEW_LINE ar2 = [ 2 , 13 , 17 , 30 , 45 ] NEW_LINE n1 = len ( ar1 ) NEW_LINE n2 = len ( ar2 ) NEW_LINE if n1 == n2 : NEW_LINE INDENT print ( "" Median ▁ is ▁ "" , getMedian ( ar1 , ar2 , n1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Doesn ' t ▁ work ▁ for ▁ arrays ▁ of ▁ unequal ▁ size "" ) NEW_LINE DEDENT " V386,"class GFG { static final int INT_SIZE = 32 ; static class TrieNode { int value ; TrieNode [ ] arr = new TrieNode [ 2 ] ; public TrieNode ( ) { value = 0 ; arr [ 0 ] = null ; arr [ 1 ] = null ; } } static TrieNode root ; static void insert ( int pre_xor ) { TrieNode temp = root ; for ( int i = INT_SIZE - 1 ; i >= 0 ; i -- ) { int val = ( pre_xor & ( 1 << i ) ) >= 1 ? 1 : 0 ; if ( temp . arr [ val ] == null ) temp . arr [ val ] = new TrieNode ( ) ; temp = temp . arr [ val ] ; } temp . value = pre_xor ; } static int query ( int pre_xor ) { TrieNode temp = root ; for ( int i = INT_SIZE - 1 ; i >= 0 ; i -- ) { int val = ( pre_xor & ( 1 << i ) ) >= 1 ? 1 : 0 ; if ( temp . arr [ 1 - val ] != null ) temp = temp . arr [ 1 - val ] ; else if ( temp . arr [ val ] != null ) temp = temp . arr [ val ] ; } return pre_xor ^ ( temp . value ) ; } static int maxSubarrayXOR ( int arr [ ] , int n ) { root = new TrieNode ( ) ; insert ( 0 ) ; int result = Integer . MIN_VALUE ; int pre_xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { pre_xor = pre_xor ^ arr [ i ] ; insert ( pre_xor ) ; result = Math . max ( result , query ( pre_xor ) ) ; } return result ; } public static void main ( String args [ ] ) { int arr [ ] = { 8 , 1 , 2 , 12 } ; int n = arr . length ; System . out . println ( "" Max ▁ subarray ▁ XOR ▁ is ▁ "" + maxSubarrayXOR ( arr , n ) ) ; } } ","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 class Trie : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . root = Node ( 0 ) NEW_LINE DEDENT def insert ( self , pre_xor ) : NEW_LINE INDENT self . temp = self . root NEW_LINE for i in range ( 31 , - 1 , - 1 ) : NEW_LINE INDENT val = pre_xor & ( 1 << i ) NEW_LINE if val : NEW_LINE INDENT if not self . temp . right : NEW_LINE INDENT self . temp . right = Node ( 0 ) NEW_LINE DEDENT self . temp = self . temp . right NEW_LINE DEDENT if not val : NEW_LINE INDENT if not self . temp . left : NEW_LINE INDENT self . temp . left = Node ( 0 ) NEW_LINE DEDENT self . temp = self . temp . left NEW_LINE DEDENT DEDENT self . temp . data = pre_xor NEW_LINE DEDENT def query ( self , xor ) : NEW_LINE INDENT self . temp = self . root NEW_LINE for i in range ( 31 , - 1 , - 1 ) : NEW_LINE INDENT val = xor & ( 1 << i ) NEW_LINE if val : NEW_LINE INDENT if self . temp . left : NEW_LINE INDENT self . temp = self . temp . left NEW_LINE DEDENT elif self . temp . right : NEW_LINE INDENT self . temp = self . temp . right NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if self . temp . right : NEW_LINE INDENT self . temp = self . temp . right NEW_LINE DEDENT elif self . temp . left : NEW_LINE INDENT self . temp = self . temp . left NEW_LINE DEDENT DEDENT DEDENT return xor ^ self . temp . data NEW_LINE DEDENT def maxSubArrayXOR ( self , n , Arr ) : NEW_LINE INDENT self . insert ( 0 ) NEW_LINE result = - float ( ' inf ' ) NEW_LINE pre_xor = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT pre_xor = pre_xor ^ Arr [ i ] NEW_LINE self . insert ( pre_xor ) NEW_LINE result = max ( result , self . query ( pre_xor ) ) NEW_LINE DEDENT return result NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT Arr = [ 8 , 1 , 2 , 12 ] NEW_LINE n = len ( Arr ) NEW_LINE trie = Trie ( ) NEW_LINE print ( trie . maxSubArrayXOR ( n , Arr ) ) NEW_LINE DEDENT " V387,"public class GfG { static int minCost ( int n , int arr [ ] , int cost ) { int sum = 0 , totalCost = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) sum += arr [ i ] ; totalCost += cost * sum ; arr [ n - 1 ] += sum ; totalCost += ( 2 * cost * arr [ n - 1 ] ) ; return totalCost ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 5 } ; int n = arr . length ; int cost = 1 ; System . out . println ( minCost ( n , arr , cost ) ) ; } } ","def minCost ( n , arr , cost ) : NEW_LINE INDENT Sum , totalCost = 0 , 0 NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT Sum += arr [ i ] NEW_LINE DEDENT totalCost += cost * Sum NEW_LINE arr [ n - 1 ] += Sum NEW_LINE totalCost += ( 2 * cost * arr [ n - 1 ] ) NEW_LINE return totalCost NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 2 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE cost = 1 NEW_LINE print ( minCost ( n , arr , cost ) ) NEW_LINE DEDENT " V388,"class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } static int productOfNodes ( Node head ) { Node ptr = head ; int product = 1 ; while ( ptr != null ) { product *= ptr . data ; ptr = ptr . next ; } return product ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 7 ) ; head = push ( head , 6 ) ; head = push ( head , 8 ) ; head = push ( head , 4 ) ; head = push ( head , 1 ) ; System . out . println ( "" Product ▁ = ▁ "" + productOfNodes ( 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 push ( head , data ) : NEW_LINE INDENT if not head : NEW_LINE INDENT return Node ( data ) NEW_LINE DEDENT new_node = Node ( data ) NEW_LINE new_node . next = head NEW_LINE head = new_node NEW_LINE return head NEW_LINE DEDENT def productOfNodes ( head ) : NEW_LINE INDENT ptr = head NEW_LINE product = 1 NEW_LINE while ( ptr ) : NEW_LINE INDENT product *= ptr . data NEW_LINE ptr = ptr . next NEW_LINE DEDENT return product NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 7 ) NEW_LINE head = push ( head , 6 ) NEW_LINE head = push ( head , 8 ) NEW_LINE head = push ( head , 4 ) NEW_LINE head = push ( head , 1 ) NEW_LINE print ( "" Product ▁ = ▁ { } "" . format ( productOfNodes ( head ) ) ) NEW_LINE DEDENT " V389,"import java . io . * ; class GFG { static int maxLength ( String s , int n ) { int dp [ ] [ ] = new int [ n ] [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ; for ( int l = 2 ; l < n ; l ++ ) { for ( int i = 0 , j = l ; j < n ; i ++ , j ++ ) { if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ; for ( int k = i ; k < j ; k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ; } } return dp [ 0 ] [ n - 1 ] ; } public static void main ( String [ ] args ) { String s = "" ( ) ( ( ( ( ( ( ) "" ; int n = s . length ( ) ; System . out . println ( maxLength ( s , n ) ) ; } } ","def maxLength ( s , n ) : NEW_LINE INDENT dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if ( s [ i ] == ' ( ' and s [ i + 1 ] == ' ) ' ) : NEW_LINE INDENT dp [ i ] [ i + 1 ] = 2 NEW_LINE DEDENT DEDENT for l in range ( 2 , n ) : NEW_LINE INDENT i = - 1 NEW_LINE for j in range ( l , n ) : NEW_LINE INDENT i += 1 NEW_LINE if ( s [ i ] == ' ( ' and s [ j ] == ' ) ' ) : NEW_LINE INDENT dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] NEW_LINE DEDENT for k in range ( i , j ) : NEW_LINE INDENT dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT return dp [ 0 ] [ n - 1 ] NEW_LINE DEDENT s = "" ( ) ( ( ( ( ( ( ) "" NEW_LINE n = len ( s ) NEW_LINE print ( maxLength ( s , n ) ) NEW_LINE " V390,"import java . util . * ; class GFG { static Vector < Integer > processQueries ( int Q [ ] , int m , int n ) { int [ ] a = new int [ m + 1 ] ; int [ ] pos = new int [ m + 1 ] ; for ( int i = 1 ; i <= m ; i ++ ) { a [ i - 1 ] = i ; pos [ i ] = i - 1 ; } Vector < Integer > ans = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int q = Q [ i ] ; int p = pos [ q ] ; ans . add ( p ) ; for ( int j = p ; j > 0 ; j -- ) { a [ j ] = a [ j ] + a [ j - 1 ] ; a [ j - 1 ] = a [ j ] - a [ j - 1 ] ; a [ j ] = a [ j ] - a [ j - 1 ] ; pos [ a [ j ] ] = j ; } pos [ a [ 0 ] ] = 0 ; } return ans ; } public static void main ( String [ ] args ) { int Q [ ] = { 3 , 1 , 2 , 1 } ; int n = Q . length ; int m = 5 ; Vector < Integer > ans = new Vector < Integer > ( ) ; ans = processQueries ( Q , m , n ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) System . out . print ( ans . get ( i ) + "" ▁ "" ) ; } } ","def processQueries ( Q , m , n ) : NEW_LINE INDENT a = [ 0 ] * ( m + 1 ) ; pos = [ 0 ] * ( m + 1 ) ; NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT a [ i - 1 ] = i ; NEW_LINE pos [ i ] = i - 1 ; NEW_LINE DEDENT ans = [ ] ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT q = Q [ i ] ; NEW_LINE p = pos [ q ] ; NEW_LINE ans . append ( p ) ; NEW_LINE for i in range ( p , 0 , - 1 ) : NEW_LINE INDENT a [ i ] , a [ i - 1 ] = a [ i - 1 ] , a [ i ] ; NEW_LINE pos [ a [ i ] ] = i ; NEW_LINE DEDENT pos [ a [ 0 ] ] = 0 ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT Q = [ 3 , 1 , 2 , 1 ] ; NEW_LINE n = len ( Q ) ; NEW_LINE m = 5 ; NEW_LINE ans = [ ] ; NEW_LINE ans = processQueries ( Q , m , n ) ; NEW_LINE for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( ans [ i ] , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT " V391,"import java . io . * ; class GFG { static int countSubarrays ( int a [ ] , int n , int x ) { int count = 0 ; int number = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { count += 1 ; } else { number += ( count ) * ( count + 1 ) / 2 ; count = 0 ; } } if ( count != 0 ) number += ( count ) * ( count + 1 ) / 2 ; return number ; } public static void main ( String [ ] args ) { int a [ ] = { 3 , 4 , 5 , 6 , 7 , 2 , 10 , 11 } ; int n = a . length ; int k = 5 ; System . out . println ( countSubarrays ( a , n , k ) ) ; } } ","def countSubarrays ( a , n , x ) : NEW_LINE INDENT count = 0 NEW_LINE number = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] > x ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT number += ( count ) * ( count + 1 ) / 2 NEW_LINE count = 0 NEW_LINE DEDENT DEDENT if ( count ) : NEW_LINE INDENT number += ( count ) * ( count + 1 ) / 2 NEW_LINE DEDENT return int ( number ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 3 , 4 , 5 , 6 , 7 , 2 , 10 , 11 ] NEW_LINE n = len ( a ) NEW_LINE k = 5 NEW_LINE print ( countSubarrays ( a , n , k ) ) NEW_LINE DEDENT " V392,"import java . util . * ; class GFG { static int findNthOccur ( String str , char ch , int N ) { int occur = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ch ) { occur += 1 ; } if ( occur == N ) return i ; } return - 1 ; } public static void main ( String [ ] args ) { String str = "" geeks "" ; char ch = ' e ' ; int N = 2 ; System . out . print ( findNthOccur ( str , ch , N ) ) ; } } ","def findNthOccur ( string , ch , N ) : NEW_LINE INDENT occur = 0 ; NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if ( string [ i ] == ch ) : NEW_LINE INDENT occur += 1 ; NEW_LINE DEDENT if ( occur == N ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT return - 1 ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" geeks "" ; NEW_LINE ch = ' e ' ; NEW_LINE N = 2 ; NEW_LINE print ( findNthOccur ( string , ch , N ) ) ; NEW_LINE DEDENT " V393,"class GFG { static boolean isCommonBase ( String base , String s1 , String s2 ) { for ( int j = 0 ; j < s1 . length ( ) ; ++ j ) { if ( base . charAt ( j % base . length ( ) ) != s1 . charAt ( j ) ) { return false ; } } for ( int j = 0 ; j < s2 . length ( ) ; ++ j ) { if ( base . charAt ( j % base . length ( ) ) != s2 . charAt ( j ) ) { return false ; } } return true ; } static int countCommonBases ( String s1 , String s2 ) { int n1 = s1 . length ( ) , n2 = s2 . length ( ) ; int count = 0 ; for ( int i = 1 ; i <= Math . min ( n1 , n2 ) ; i ++ ) { String base = s1 . substring ( 0 , i ) ; if ( isCommonBase ( base , s1 , s2 ) ) { count ++ ; } } return count ; } public static void main ( String [ ] args ) { String s1 = "" pqrspqrs "" ; String s2 = "" pqrspqrspqrspqrs "" ; System . out . println ( countCommonBases ( s1 , s2 ) ) ; } } ","def isCommonBase ( base , s1 , s2 ) : NEW_LINE INDENT for j in range ( len ( s1 ) ) : NEW_LINE INDENT if ( base [ j % len ( base ) ] != s1 [ j ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT for j in range ( len ( s2 ) ) : NEW_LINE INDENT if ( base [ j % len ( base ) ] != s2 [ j ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def countCommonBases ( s1 , s2 ) : NEW_LINE INDENT n1 = len ( s1 ) NEW_LINE n2 = len ( s2 ) NEW_LINE count = 0 NEW_LINE for i in range ( 1 , min ( n1 , n2 ) + 1 ) : NEW_LINE INDENT base = s1 [ 0 : i ] NEW_LINE if ( isCommonBase ( base , s1 , s2 ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s1 = "" pqrspqrs "" NEW_LINE s2 = "" pqrspqrspqrspqrs "" NEW_LINE print ( countCommonBases ( s1 , s2 ) ) NEW_LINE DEDENT " V394,"import java . util . * ; class GFG { static int pow ( int x , int y ) { if ( y == 1 ) return x ; if ( y == 0 ) return 1 ; int temp = pow ( x , y / 2 ) ; temp *= temp ; if ( y % 2 == 1 ) temp *= x ; return temp ; } static int noOfPermutations ( int [ ] a , int n ) { if ( n == 1 ) { return 1 ; } Arrays . sort ( a ) ; if ( a [ n - 1 ] == a [ n - 2 ] ) { return 0 ; } int x = 0 ; for ( int i = 0 ; i < n - 2 ; ++ i ) { if ( a [ i ] == a [ i + 1 ] ) { if ( a [ i ] == a [ i + 2 ] ) { return 0 ; } x ++ ; i ++ ; } } return pow ( 2 , n - 2 * x - 1 ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 2 , 3 , 4 } ; int n = a . length ; int num = noOfPermutations ( a , n ) ; System . out . print ( num ) ; } } ","def pow ( x , y ) : NEW_LINE INDENT if ( y == 1 ) : NEW_LINE INDENT return x NEW_LINE DEDENT if ( y == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT temp = pow ( x , y // 2 ) NEW_LINE temp *= temp NEW_LINE if ( y & 1 ) : NEW_LINE INDENT temp *= x NEW_LINE DEDENT return temp NEW_LINE DEDENT def noOfPermutations ( a , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT a . sort ( ) NEW_LINE if ( a [ n - 1 ] == a [ n - 2 ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT x = 0 NEW_LINE for i in range ( n - 2 ) : NEW_LINE INDENT if ( a [ i ] == a [ i + 1 ] ) : NEW_LINE INDENT if ( a [ i ] == a [ i + 2 ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT x += 1 NEW_LINE i += 1 NEW_LINE DEDENT DEDENT return pow ( 2 , n - 2 * x - 1 ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 1 , 2 , 2 , 3 , 4 ] NEW_LINE n = len ( a ) NEW_LINE num = noOfPermutations ( a , n ) NEW_LINE print ( num ) NEW_LINE DEDENT " V395,"class GFG { static int toggleBitsFromLToR ( int n , int l , int r ) { if ( r < l ) return n ; int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; return ( n ^ num ) ; } static int smallNumWithNSetAndMUnsetBits ( int n , int m ) { int num = ( 1 << ( n + m ) ) - 1 ; return toggleBitsFromLToR ( num , n , n + m - 1 ) ; } public static void main ( String [ ] args ) { int n = 2 , m = 2 ; System . out . println ( smallNumWithNSetAndMUnsetBits ( n , m ) ) ; } } ","def toggleBitsFromLToR ( n , l , r ) : NEW_LINE INDENT if ( r < l ) : NEW_LINE INDENT return n NEW_LINE DEDENT num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) NEW_LINE return ( n ^ num ) NEW_LINE DEDENT def smallNumWithNSetAndMUnsetBits ( n , m ) : NEW_LINE INDENT num = ( 1 << ( n + m ) ) - 1 NEW_LINE return toggleBitsFromLToR ( num , n , n + m - 1 ) ; NEW_LINE DEDENT n = 2 NEW_LINE m = 2 NEW_LINE ans = smallNumWithNSetAndMUnsetBits ( n , m ) NEW_LINE print ( ans ) NEW_LINE " V396,"import java . util . * ; import java . io . * ; class GFG { static void generateNumbers ( int m ) { ArrayList < Integer > numbers = new ArrayList < > ( ) ; int k_max , x ; for ( int y = 0 ; y < 10 ; y ++ ) { k_max = ( int ) ( Math . pow ( 10 , m - 2 ) * ( 10 * y + 1 ) ) / ( int ) ( Math . pow ( 10 , m - 1 ) + y ) ; for ( int k = 1 ; k <= k_max ; k ++ ) { x = ( int ) ( y * ( Math . pow ( 10 , m - 1 ) - k ) ) / ( 10 * k - 1 ) ; if ( ( int ) ( y * ( Math . pow ( 10 , m - 1 ) - k ) ) % ( 10 * k - 1 ) == 0 ) numbers . add ( 10 * x + y ) ; } } Collections . sort ( numbers ) ; for ( int i = 0 ; i < numbers . size ( ) ; i ++ ) System . out . println ( numbers . get ( i ) ) ; } public static void main ( String args [ ] ) { int m = 3 ; generateNumbers ( m ) ; } } ","from math import log10 NEW_LINE def generateNumbers ( m ) : NEW_LINE INDENT numbers = [ ] NEW_LINE for y in range ( 1 , 10 ) : NEW_LINE INDENT k_max = ( ( 10 ** ( m - 2 ) * ( 10 * y + 1 ) ) // ( 10 ** ( m - 1 ) + y ) ) NEW_LINE for k in range ( 1 , k_max + 1 ) : NEW_LINE INDENT x = ( ( y * ( 10 ** ( m - 1 ) - k ) ) // ( 10 * k - 1 ) ) NEW_LINE if ( ( y * ( 10 ** ( m - 1 ) - k ) ) % ( 10 * k - 1 ) == 0 ) : NEW_LINE INDENT numbers . append ( 10 * x + y ) NEW_LINE DEDENT DEDENT DEDENT for n in sorted ( numbers ) : NEW_LINE INDENT print ( n ) NEW_LINE DEDENT DEDENT m = 3 NEW_LINE generateNumbers ( m ) NEW_LINE " V397,"class GFG { static void arrange ( int arr [ ] , int n , int x ) { for ( int i = 1 ; i < n ; i ++ ) { int diff = Math . abs ( arr [ i ] - x ) ; int j = i - 1 ; if ( Math . abs ( arr [ j ] - x ) > diff ) { int temp = arr [ i ] ; while ( j >= 0 && Math . abs ( arr [ j ] - x ) > diff ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } } static void print ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 5 , 3 , 9 , 2 } ; int n = arr . length ; int x = 7 ; arrange ( arr , n , x ) ; print ( arr , n ) ; } } ","def arrange ( arr , n , x ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT diff = abs ( arr [ i ] - x ) NEW_LINE j = i - 1 NEW_LINE if ( abs ( arr [ j ] - x ) > diff ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE while ( abs ( arr [ j ] - x ) > diff and j >= 0 ) : NEW_LINE INDENT arr [ j + 1 ] = arr [ j ] NEW_LINE j -= 1 NEW_LINE DEDENT arr [ j + 1 ] = temp NEW_LINE DEDENT DEDENT DEDENT def print_1 ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 10 , 5 , 3 , 9 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE x = 7 NEW_LINE arrange ( arr , n , x ) NEW_LINE print_1 ( arr , n ) NEW_LINE DEDENT " V398,"import java . io . * ; class GFG { static boolean check ( String s , int m ) { int l = s . length ( ) ; int c1 = 0 ; int c2 = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( s . charAt ( i ) == '0' ) { c2 = 0 ; c1 ++ ; } else { c1 = 0 ; c2 ++ ; } if ( c1 == m || c2 == m ) return true ; } return false ; } public static void main ( String [ ] args ) { String s = ""001001"" ; int m = 2 ; if ( check ( s , m ) ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def check ( s , m ) : NEW_LINE INDENT l = len ( s ) ; NEW_LINE c1 = 0 ; NEW_LINE c2 = 0 ; NEW_LINE for i in range ( 0 , l - 1 ) : NEW_LINE INDENT if ( s [ i ] == '0' ) : NEW_LINE INDENT c2 = 0 ; NEW_LINE c1 = c1 + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT c1 = 0 ; NEW_LINE c2 = c2 + 1 ; NEW_LINE DEDENT if ( c1 == m or c2 == m ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT s = ""001001"" ; NEW_LINE m = 2 ; NEW_LINE if ( check ( s , m ) ) : NEW_LINE INDENT print ( "" YES "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) ; NEW_LINE DEDENT " V399,"class GFG { static int maxOperations ( int X , int Y ) { if ( X > Y ) return - 1 ; int diff = Y - X ; if ( diff == 1 ) return - 1 ; if ( diff % 2 == 0 ) return ( diff / 2 ) ; return ( 1 + ( ( diff - 3 ) / 2 ) ) ; } public static void main ( String [ ] args ) { int X = 5 , Y = 16 ; System . out . println ( maxOperations ( X , Y ) ) ; } } ","def maxOperations ( X , Y ) : NEW_LINE INDENT if ( X > Y ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT diff = Y - X ; NEW_LINE if ( diff == 1 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT if ( diff % 2 == 0 ) : NEW_LINE INDENT return ( diff // 2 ) ; NEW_LINE DEDENT return ( 1 + ( ( diff - 3 ) // 2 ) ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT X = 5 ; Y = 16 ; NEW_LINE print ( maxOperations ( X , Y ) ) ; NEW_LINE DEDENT " V400,"public class LargestNumber { static String swap ( String str , int i , int j ) { char ch [ ] = str . toCharArray ( ) ; char temp = ch [ i ] ; ch [ i ] = ch [ j ] ; ch [ j ] = temp ; String c = String . valueOf ( ch ) ; return c ; } static int largestNum ( int num ) { String num_in_str = "" "" + num ; String temp = num_in_str ; for ( int i = 0 ; i < num_in_str . length ( ) ; i ++ ) { for ( int j = i + 1 ; j < num_in_str . length ( ) ; j ++ ) { num_in_str = swap ( num_in_str , i , j ) ; if ( temp . compareTo ( num_in_str ) < 0 ) temp = num_in_str ; num_in_str = swap ( num_in_str , i , j ) ; } } return Integer . parseInt ( temp ) ; } public static void main ( String [ ] s ) { int num = 423 ; System . out . println ( largestNum ( num ) ) ; num = 2736 ; System . out . println ( largestNum ( num ) ) ; num = 4596 ; System . out . println ( largestNum ( num ) ) ; } } ","def largestNum ( num ) : NEW_LINE INDENT num_to_str = list ( str ( num ) ) NEW_LINE temp = num_to_str [ : ] NEW_LINE for i in range ( len ( num_to_str ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( num_to_str ) ) : NEW_LINE INDENT // Swapping current pair NEW_LINE num_to_str [ i ] , num_to_str [ j ] = num_to_str [ j ] , num_to_str [ i ] NEW_LINE if num_to_str > temp : NEW_LINE INDENT temp = num_to_str [ : ] NEW_LINE DEDENT num_to_str [ i ] , num_to_str [ j ] = num_to_str [ j ] , num_to_str [ i ] NEW_LINE DEDENT DEDENT return int ( "" "" . join ( temp ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT A = int ( 432 ) NEW_LINE print ( largestNum ( A ) ) NEW_LINE A = int ( 2736 ) NEW_LINE print ( largestNum ( A ) ) NEW_LINE A = int ( 4596 ) NEW_LINE print ( largestNum ( A ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V401,"import java . util . * ; class GFG { static boolean checkPandigital ( int b , String n ) { if ( n . length ( ) < b ) return false ; boolean hash [ ] = new boolean [ b ] ; Arrays . fill ( hash , false ) ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { if ( n . charAt ( i ) >= '0' && n . charAt ( i ) <= '9' ) hash [ n . charAt ( i ) - '0' ] = true ; else if ( n . charAt ( i ) - ' A ' <= b - 11 ) hash [ n . charAt ( i ) - ' A ' + 10 ] = true ; } for ( int i = 0 ; i < b ; i ++ ) if ( hash [ i ] == false ) return false ; return true ; } public static void main ( String [ ] args ) { int b = 13 ; String n = ""1298450376ABC "" ; if ( checkPandigital ( b , n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def checkPandigital ( b , n ) : NEW_LINE INDENT if ( len ( n ) < b ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT hash = [ 0 ] * b ; NEW_LINE for i in range ( len ( n ) ) : NEW_LINE INDENT if ( n [ i ] >= '0' and n [ i ] <= '9' ) : NEW_LINE INDENT hash [ ord ( n [ i ] ) - ord ( '0' ) ] = 1 ; NEW_LINE DEDENT elif ( ord ( n [ i ] ) - ord ( ' A ' ) <= b - 11 ) : NEW_LINE INDENT hash [ ord ( n [ i ] ) - ord ( ' A ' ) + 10 ] = 1 ; NEW_LINE DEDENT DEDENT for i in range ( b ) : NEW_LINE INDENT if ( hash [ i ] == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT return 1 ; NEW_LINE DEDENT b = 13 ; NEW_LINE n = ""1298450376ABC "" ; NEW_LINE if ( checkPandigital ( b , n ) ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE DEDENT " V402,"import java . util . * ; class Solution { static int __builtin_popcount ( int n ) { int count = 0 ; while ( n > 0 ) { if ( n % 2 == 1 ) count ++ ; n = n / 2 ; } return count ; } static void count_values ( int n ) { int set_bits = __builtin_popcount ( n ) ; System . out . println ( ( int ) Math . pow ( 2 , set_bits ) ) ; } public static void main ( String args [ ] ) { int n = 27 ; count_values ( n ) ; } } ","from math import pow NEW_LINE def __builtin_popcount ( n ) : NEW_LINE INDENT count = 0 NEW_LINE while n > 0 : NEW_LINE INDENT if n % 2 == 1 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT n = n // 2 NEW_LINE DEDENT return count NEW_LINE DEDENT def count_values ( n ) : NEW_LINE INDENT set_bits = __builtin_popcount ( n ) NEW_LINE print ( int ( pow ( 2 , set_bits ) ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 27 NEW_LINE count_values ( n ) NEW_LINE DEDENT " V403,"import java . util . * ; class GFG { static boolean oneDigit ( int num ) { return ( num >= 0 && num < 10 ) ; } static boolean isPalUtil ( int num , int dupNum ) { if ( oneDigit ( num ) ) return ( num == ( dupNum ) % 10 ) ; if ( ! isPalUtil ( num / 10 , dupNum ) ) return false ; dupNum /= 10 ; return ( num % 10 == ( dupNum ) % 10 ) ; } static boolean isPal ( int num ) { if ( num < 0 ) num = - num ; int dupNum = num ; return isPalUtil ( num , dupNum ) ; } static void printPalPrimesLessThanN ( int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; Arrays . fill ( prime , true ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= n ; i += p ) { prime [ i ] = false ; } } } for ( int p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] && isPal ( p ) ) { System . out . print ( p + "" ▁ "" ) ; } } } public static void main ( String [ ] args ) { int n = 100 ; System . out . printf ( "" Palindromic ▁ primes ▁ smaller ▁ than ▁ or ▁ "" + "" equal ▁ to ▁ % d ▁ are ▁ : \n "" , n ) ; printPalPrimesLessThanN ( n ) ; } } ","def oneDigit ( num ) : NEW_LINE INDENT return ( num >= 0 and num < 10 ) ; NEW_LINE DEDENT def isPalUtil ( num , dupNum ) : NEW_LINE INDENT if ( oneDigit ( num ) ) : NEW_LINE INDENT return ( num == ( dupNum ) % 10 ) ; NEW_LINE DEDENT if ( not isPalUtil ( int ( num / 10 ) , dupNum ) ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT dupNum = int ( dupNum / 10 ) ; NEW_LINE return ( num % 10 == ( dupNum ) % 10 ) ; NEW_LINE DEDENT def isPal ( num ) : NEW_LINE INDENT if ( num < 0 ) : NEW_LINE INDENT num = - num ; NEW_LINE DEDENT dupNum = num ; NEW_LINE return isPalUtil ( num , dupNum ) ; NEW_LINE DEDENT def printPalPrimesLessThanN ( n ) : NEW_LINE INDENT prime = [ True ] * ( n + 1 ) ; NEW_LINE p = 2 ; NEW_LINE while ( p * p <= n ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( p * 2 , n + 1 , p ) : NEW_LINE INDENT prime [ i ] = False ; NEW_LINE DEDENT DEDENT p += 1 ; NEW_LINE DEDENT for p in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( prime [ p ] and isPal ( p ) ) : NEW_LINE INDENT print ( p , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT DEDENT n = 100 ; NEW_LINE print ( "" Palindromic ▁ primes ▁ smaller "" , "" than ▁ or ▁ equal ▁ to "" , n , "" are ▁ : "" ) ; NEW_LINE printPalPrimesLessThanN ( n ) ; NEW_LINE " V404,"class GFG { static int n = 6 , m = 6 ; static void maxSum ( long arr [ ] [ ] ) { long [ ] [ ] dp = new long [ n + 1 ] [ 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { long m1 = 0 , m2 = 0 , m3 = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( ( j / ( m / 3 ) ) == 0 ) { m1 = Math . max ( m1 , arr [ i ] [ j ] ) ; } else if ( ( j / ( m / 3 ) ) == 1 ) { m2 = Math . max ( m2 , arr [ i ] [ j ] ) ; } else if ( ( j / ( m / 3 ) ) == 2 ) { m3 = Math . max ( m3 , arr [ i ] [ j ] ) ; } } dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i ] [ 2 ] ) + m1 ; dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 2 ] ) + m2 ; dp [ i + 1 ] [ 2 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i ] [ 0 ] ) + m3 ; } System . out . print ( Math . max ( Math . max ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) , dp [ n ] [ 2 ] ) + "" \n "" ) ; } public static void main ( String [ ] args ) { long arr [ ] [ ] = { { 1 , 3 , 5 , 2 , 4 , 6 } , { 6 , 4 , 5 , 1 , 3 , 2 } , { 1 , 3 , 5 , 2 , 4 , 6 } , { 6 , 4 , 5 , 1 , 3 , 2 } , { 6 , 4 , 5 , 1 , 3 , 2 } , { 1 , 3 , 5 , 2 , 4 , 6 } } ; maxSum ( arr ) ; } } ","import numpy as np NEW_LINE n = 6 ; m = 6 ; NEW_LINE def maxSum ( arr ) : NEW_LINE INDENT dp = np . zeros ( ( n + 1 , 3 ) ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT m1 = 0 ; m2 = 0 ; m3 = 0 ; NEW_LINE for j in range ( m ) : NEW_LINE INDENT if ( ( j // ( m // 3 ) ) == 0 ) : NEW_LINE INDENT m1 = max ( m1 , arr [ i ] [ j ] ) ; NEW_LINE DEDENT elif ( ( j // ( m // 3 ) ) == 1 ) : NEW_LINE INDENT m2 = max ( m2 , arr [ i ] [ j ] ) ; NEW_LINE DEDENT elif ( ( j // ( m // 3 ) ) == 2 ) : NEW_LINE INDENT m3 = max ( m3 , arr [ i ] [ j ] ) ; NEW_LINE DEDENT DEDENT dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 2 ] ) + m1 ; NEW_LINE dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 2 ] ) + m2 ; NEW_LINE dp [ i + 1 ] [ 2 ] = max ( dp [ i ] [ 1 ] , dp [ i ] [ 0 ] ) + m3 ; NEW_LINE DEDENT print ( max ( max ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) , dp [ n ] [ 2 ] ) ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 6 , 4 , 5 , 1 , 3 , 2 ] , [ 1 , 3 , 5 , 2 , 4 , 6 ] ] ; NEW_LINE maxSum ( arr ) ; NEW_LINE DEDENT " V405,"import java . util . * ; class GFG { public static int smallestKFreq ( int a [ ] , int n , int k ) { HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( m . containsKey ( a [ i ] ) ) m . put ( a [ i ] , m . get ( a [ i ] ) + 1 ) ; else m . put ( a [ i ] , 1 ) ; int res = Integer . MAX_VALUE ; Set < Integer > s = m . keySet ( ) ; for ( int temp : s ) if ( m . get ( temp ) == k ) res = Math . min ( res , temp ) ; return ( res != Integer . MAX_VALUE ) ? res : - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 3 , 1 } ; int k = 2 ; System . out . println ( smallestKFreq ( arr , arr . length , k ) ) ; } } ","from collections import defaultdict NEW_LINE import sys NEW_LINE def smallestKFreq ( arr , n , k ) : NEW_LINE INDENT mp = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT res = sys . maxsize NEW_LINE res1 = sys . maxsize NEW_LINE for key , values in mp . items ( ) : NEW_LINE INDENT if values == k : NEW_LINE INDENT res = min ( res , key ) NEW_LINE DEDENT DEDENT return res if res != res1 else - 1 NEW_LINE DEDENT arr = [ 2 , 2 , 1 , 3 , 1 ] NEW_LINE k = 2 NEW_LINE n = len ( arr ) NEW_LINE print ( smallestKFreq ( arr , n , k ) ) NEW_LINE " V406,"import java . io . * ; class GFG { static int divSum ( int n ) { int result = 0 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + n + 1 ) ; } public static void main ( String [ ] args ) { int n = 30 ; System . out . println ( divSum ( n ) ) ; } } ","import math NEW_LINE def divSum ( n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( 2 , ( int ) ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( i == ( n / i ) ) : NEW_LINE INDENT result = result + i NEW_LINE DEDENT else : NEW_LINE INDENT result = result + ( i + n // i ) NEW_LINE DEDENT DEDENT DEDENT return ( result + n + 1 ) NEW_LINE DEDENT n = 30 NEW_LINE print ( divSum ( n ) ) NEW_LINE " V407,"class GFG { static char NthCharacter ( int n ) { String s = "" "" ; int c = 1 ; for ( int i = 1 ; ; i ++ ) { if ( c < 10 ) s += Integer . toString ( c ) ; else { String s1 = "" "" ; int dup = c ; while ( dup > 0 ) { s1 += Integer . toString ( dup % 10 ) ; dup /= 10 ; } StringBuilder temp = new StringBuilder ( ) ; temp . append ( s1 ) ; temp = temp . reverse ( ) ; s += temp ; } c ++ ; if ( s . length ( ) >= n ) { return s . charAt ( n - 1 ) ; } } } public static void main ( String [ ] args ) { int n = 11 ; System . out . println ( NthCharacter ( n ) ) ; } } ","def NthCharacter ( n ) : NEW_LINE INDENT s = "" "" NEW_LINE c = 1 NEW_LINE while ( True ) : NEW_LINE INDENT if ( c < 10 ) : NEW_LINE INDENT s += chr ( 48 + c ) NEW_LINE DEDENT else : NEW_LINE INDENT s1 = "" "" NEW_LINE dup = c NEW_LINE while ( dup > 0 ) : NEW_LINE INDENT s1 += chr ( ( dup % 10 ) + 48 ) NEW_LINE dup //= 10 NEW_LINE DEDENT s1 = "" "" . join ( reversed ( s1 ) ) NEW_LINE s += s1 NEW_LINE DEDENT c += 1 NEW_LINE if ( len ( s ) >= n ) : NEW_LINE INDENT return s [ n - 1 ] NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 11 NEW_LINE print ( NthCharacter ( n ) ) NEW_LINE DEDENT " V408,"import java . io . * ; import java . util . Arrays ; class GFG { static int MaxTotalRectangleArea ( int [ ] a , int n ) { Arrays . sort ( a ) ; int sum = 0 ; boolean flag = false ; int len = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) { flag = true ; len = a [ i + 1 ] ; i ++ ; } else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) { sum = sum + a [ i + 1 ] * len ; flag = false ; i ++ ; } } return sum ; } public static void main ( String args [ ] ) { int [ ] a = { 10 , 10 , 10 , 10 , 11 , 10 , 11 , 10 , 9 , 9 , 8 , 8 } ; int n = a . length ; System . out . print ( MaxTotalRectangleArea ( a , n ) ) ; } } ","def MaxTotalRectangleArea ( a , n ) : NEW_LINE INDENT a . sort ( reverse = True ) NEW_LINE sum = 0 NEW_LINE flag = False NEW_LINE len = 0 NEW_LINE i = 0 NEW_LINE while ( i < n - 1 ) : NEW_LINE INDENT if ( i != 0 ) : NEW_LINE INDENT i = i + 1 NEW_LINE DEDENT if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) : NEW_LINE INDENT flag = True NEW_LINE len = a [ i + 1 ] NEW_LINE i = i + 1 NEW_LINE DEDENT elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) : NEW_LINE INDENT sum = sum + a [ i + 1 ] * len NEW_LINE flag = False NEW_LINE i = i + 1 NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT a = [ 10 , 10 , 10 , 10 , 11 , 10 , 11 , 10 , 9 , 9 , 8 , 8 ] NEW_LINE n = len ( a ) NEW_LINE print ( MaxTotalRectangleArea ( a , n ) ) NEW_LINE " V409,"class GFG { static int smallestIndexsum ( int arr [ ] , int n ) { int i = n - 1 ; while ( i >= 0 && arr [ i ] % 2 == 1 ) i -- ; int sum = 0 ; for ( int j = 0 ; j <= i ; j ++ ) sum += arr [ j ] ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 5 , 6 , 3 , 3 } ; int n = arr . length ; System . out . println ( smallestIndexsum ( arr , n ) ) ; } } ","def smallestIndexsum ( arr , n ) : NEW_LINE INDENT i = n - 1 ; NEW_LINE while ( i >= 0 and arr [ i ] % 2 == 1 ) : NEW_LINE INDENT i -= 1 ; NEW_LINE DEDENT sum = 0 ; NEW_LINE for j in range ( 0 , i + 1 ) : NEW_LINE INDENT sum += arr [ j ] ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 5 , 6 , 3 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( smallestIndexsum ( arr , n ) ) ; NEW_LINE DEDENT " V410,"class GFG { static int bitwiseAndOdd ( int n ) { int result = 1 ; for ( int i = 3 ; i <= n ; i = i + 2 ) { result = ( result & i ) ; } return result ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( bitwiseAndOdd ( n ) ) ; } } ","def bitwiseAndOdd ( n ) : NEW_LINE INDENT result = 1 ; NEW_LINE for i in range ( 3 , n + 1 , 2 ) : NEW_LINE INDENT result = ( result & i ) ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 10 ; NEW_LINE print ( bitwiseAndOdd ( n ) ) ; NEW_LINE DEDENT " V411,"import java . io . * ; public class GFG { static int sn ( int n , int an ) { return ( n * ( 1 + an ) ) / 2 ; } static int trace ( int n , int m ) { int an = 1 + ( n - 1 ) * ( m + 1 ) ; int rowmajorSum = sn ( n , an ) ; an = 1 + ( n - 1 ) * ( n + 1 ) ; int colmajorSum = sn ( n , an ) ; return rowmajorSum + colmajorSum ; } static public void main ( String [ ] args ) { int N = 3 , M = 3 ; System . out . println ( trace ( N , M ) ) ; } } ","def sn ( n , an ) : NEW_LINE INDENT return ( n * ( 1 + an ) ) / 2 ; NEW_LINE DEDENT def trace ( n , m ) : NEW_LINE INDENT an = 1 + ( n - 1 ) * ( m + 1 ) ; NEW_LINE rowmajorSum = sn ( n , an ) ; NEW_LINE an = 1 + ( n - 1 ) * ( n + 1 ) ; NEW_LINE colmajorSum = sn ( n , an ) ; NEW_LINE return int ( rowmajorSum + colmajorSum ) ; NEW_LINE DEDENT N = 3 ; NEW_LINE M = 3 ; NEW_LINE print ( trace ( N , M ) ) ; NEW_LINE " V412,"import java . io . * ; class GFG { static String allBitsSetInTheGivenRange ( int n , int l , int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( new_num == 0 ) return "" Yes "" ; return "" No "" ; } public static void main ( String [ ] args ) { int n = 17 ; int l = 2 ; int r = 4 ; System . out . println ( allBitsSetInTheGivenRange ( n , l , r ) ) ; } } ","def allBitsSetInTheGivenRange ( n , l , r ) : NEW_LINE INDENT num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) NEW_LINE new_num = n & num NEW_LINE if ( new_num == 0 ) : NEW_LINE INDENT return "" Yes "" NEW_LINE DEDENT return "" No "" NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 17 NEW_LINE l = 2 NEW_LINE r = 4 NEW_LINE print ( allBitsSetInTheGivenRange ( n , l , r ) ) NEW_LINE DEDENT " V413,"class Test { static int findEqualPoint ( int arr [ ] , int n ) { int distArr [ ] = new int [ n ] ; int i = 0 , di = 0 ; while ( i < n ) { distArr [ di ++ ] = i ++ ; while ( i < n && arr [ i ] == arr [ i - 1 ] ) i ++ ; } return ( di & 1 ) != 0 ? distArr [ di >> 1 ] : - 1 ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 4 , 5 , 6 , 6 , 6 , 7 } ; int index = findEqualPoint ( arr , arr . length ) ; System . out . println ( index != - 1 ? "" Equal ▁ Point ▁ = ▁ "" + arr [ index ] : "" Equal ▁ Point ▁ does ▁ not ▁ exists "" ) ; } } ","def findEqualPoint ( arr , n ) : NEW_LINE INDENT distArr = [ 0 ] * n NEW_LINE i = 0 NEW_LINE di = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT distArr [ di ] = i NEW_LINE di += 1 NEW_LINE i += 1 NEW_LINE while ( i < n and arr [ i ] == arr [ i - 1 ] ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT DEDENT return distArr [ di >> 1 ] if ( di & 1 ) else - 1 NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 4 , 5 , 6 , 6 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE index = findEqualPoint ( arr , n ) NEW_LINE if ( index != - 1 ) : NEW_LINE INDENT print ( "" Equal ▁ Point ▁ = ▁ "" , arr [ index ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Equal ▁ Point ▁ does ▁ "" + "" not ▁ exists "" ) NEW_LINE DEDENT " V414,"class GFG { static int M = 3 ; static int N = 3 ; static void reverseArray ( int arr [ ] [ ] ) { for ( int i = 0 ; i < M ; i ++ ) { int start = 0 ; int end = N - 1 ; while ( start < end ) { int temp = arr [ i ] [ start ] ; arr [ i ] [ start ] = arr [ i ] [ end ] ; arr [ i ] [ end ] = temp ; start ++ ; end -- ; } } for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { System . out . print ( arr [ i ] [ j ] + "" ▁ "" ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; reverseArray ( arr ) ; } } ","M = 3 ; N = 3 ; NEW_LINE def reverseArray ( arr ) : NEW_LINE INDENT for i in range ( M ) : NEW_LINE INDENT start = 0 ; NEW_LINE end = N - 1 ; NEW_LINE while ( start < end ) : NEW_LINE INDENT arr [ i ] [ start ] , arr [ i ] [ end ] = arr [ i ] [ end ] , arr [ i ] [ start ] ; NEW_LINE start += 1 ; NEW_LINE end -= 1 ; NEW_LINE DEDENT DEDENT for i in range ( M ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT print ( arr [ i ] [ j ] , end = ' ▁ ' ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; NEW_LINE reverseArray ( arr ) ; NEW_LINE DEDENT " V415,"import java . util . * ; class Solution { static void printAllSubsetsRec ( int arr [ ] , int n , Vector < Integer > v , int sum ) { if ( sum == 0 ) { for ( int i = 0 ; i < v . size ( ) ; i ++ ) System . out . print ( v . get ( i ) + "" ▁ "" ) ; System . out . println ( ) ; return ; } if ( n == 0 ) return ; printAllSubsetsRec ( arr , n - 1 , v , sum ) ; Vector < Integer > v1 = new Vector < Integer > ( v ) ; v1 . add ( arr [ n - 1 ] ) ; printAllSubsetsRec ( arr , n - 1 , v1 , sum - arr [ n - 1 ] ) ; } static void printAllSubsets ( int arr [ ] , int n , int sum ) { Vector < Integer > v = new Vector < Integer > ( ) ; printAllSubsetsRec ( arr , n , v , sum ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 5 , 8 , 4 , 6 , 11 } ; int sum = 13 ; int n = arr . length ; printAllSubsets ( arr , n , sum ) ; } } ","def printAllSubsetsRec ( arr , n , v , sum ) : NEW_LINE INDENT if ( sum == 0 ) : NEW_LINE INDENT for value in v : NEW_LINE INDENT print ( value , end = "" ▁ "" ) NEW_LINE DEDENT print ( ) NEW_LINE return NEW_LINE DEDENT if ( n == 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT printAllSubsetsRec ( arr , n - 1 , v , sum ) NEW_LINE v1 = [ ] + v NEW_LINE v1 . append ( arr [ n - 1 ] ) NEW_LINE printAllSubsetsRec ( arr , n - 1 , v1 , sum - arr [ n - 1 ] ) NEW_LINE DEDENT def printAllSubsets ( arr , n , sum ) : NEW_LINE INDENT v = [ ] NEW_LINE printAllSubsetsRec ( arr , n , v , sum ) NEW_LINE DEDENT arr = [ 2 , 5 , 8 , 4 , 6 , 11 ] NEW_LINE sum = 13 NEW_LINE n = len ( arr ) NEW_LINE printAllSubsets ( arr , n , sum ) NEW_LINE " V416,"class GFG { static String bin [ ] = { ""000"" , ""001"" , ""010"" , ""011"" , ""100"" , ""101"" , ""110"" , ""111"" } ; static int maxFreq ( String s ) { String binary = "" "" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { binary += bin [ s . charAt ( i ) - '0' ] ; } binary = binary . substring ( 0 , binary . length ( ) - 1 ) ; int count = 1 , prev = - 1 , i , j = 0 ; for ( i = binary . length ( ) - 1 ; i >= 0 ; i -- , j ++ ) if ( binary . charAt ( i ) == '1' ) { count = Math . max ( count , j - prev ) ; prev = j ; } return count ; } public static void main ( String [ ] args ) { String octal = ""13"" ; System . out . println ( maxFreq ( octal ) ) ; } } ","bin = [ ""000"" , ""001"" , ""010"" , ""011"" , ""100"" , ""101"" , ""110"" , ""111"" ] ; NEW_LINE def maxFreq ( s ) : NEW_LINE INDENT binary = "" "" ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT binary += bin [ ord ( s [ i ] ) - ord ( '0' ) ] ; NEW_LINE DEDENT binary = binary [ 0 : len ( binary ) - 1 ] ; NEW_LINE count = 1 ; prev = - 1 ; j = 0 ; NEW_LINE for i in range ( len ( binary ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( binary [ i ] == '1' ) : NEW_LINE INDENT count = max ( count , j - prev ) ; NEW_LINE prev = j ; NEW_LINE DEDENT j += 1 ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT octal = ""13"" ; NEW_LINE print ( maxFreq ( octal ) ) ; NEW_LINE DEDENT " V417,"import java . util . Comparator ; import java . util . PriorityQueue ; public class GFG { static final int MAX_CHAR = 26 ; static class IntCompare implements Comparator < Integer > { @ Override public int compare ( Integer arg0 , Integer arg1 ) { if ( arg0 > arg1 ) return - 1 ; else if ( arg0 < arg1 ) return 1 ; else return 0 ; } } static int minStringValue ( String str , int k ) { int l = str . length ( ) ; if ( k >= l ) return 0 ; int [ ] frequency = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < l ; i ++ ) frequency [ str . charAt ( i ) - ' a ' ] ++ ; Comparator < Integer > c = new IntCompare ( ) ; PriorityQueue < Integer > q = new PriorityQueue < > ( c ) ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( frequency [ i ] != 0 ) q . add ( frequency [ i ] ) ; } while ( k != 0 ) { int temp = q . peek ( ) ; q . poll ( ) ; temp = temp - 1 ; q . add ( temp ) ; k -- ; } int result = 0 ; while ( ! q . isEmpty ( ) ) { int temp = q . peek ( ) ; result += temp * temp ; q . poll ( ) ; } return result ; } public static void main ( String args [ ] ) { String str = "" abbccc "" ; int k = 2 ; System . out . println ( minStringValue ( str , k ) ) ; str = "" aaab "" ; k = 2 ; System . out . println ( minStringValue ( str , k ) ) ; } } ","from queue import PriorityQueue NEW_LINE MAX_CHAR = 26 NEW_LINE def minStringValue ( str , k ) : NEW_LINE INDENT l = len ( str ) NEW_LINE if ( k >= l ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT frequency = [ 0 ] * MAX_CHAR NEW_LINE for i in range ( 0 , l ) : NEW_LINE INDENT frequency [ ord ( str [ i ] ) - 97 ] += 1 NEW_LINE DEDENT q = PriorityQueue ( ) NEW_LINE for i in range ( 0 , MAX_CHAR ) : NEW_LINE INDENT q . put ( - frequency [ i ] ) NEW_LINE DEDENT while ( k > 0 ) : NEW_LINE INDENT temp = q . get ( ) NEW_LINE temp = temp + 1 NEW_LINE q . put ( temp , temp ) NEW_LINE k = k - 1 NEW_LINE DEDENT result = 0 ; NEW_LINE while not q . empty ( ) : NEW_LINE INDENT temp = q . get ( ) NEW_LINE temp = temp * ( - 1 ) NEW_LINE result += temp * temp NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str = "" abbccc "" NEW_LINE k = 2 NEW_LINE print ( minStringValue ( str , k ) ) NEW_LINE str = "" aaab "" NEW_LINE k = 2 NEW_LINE print ( minStringValue ( str , k ) ) NEW_LINE DEDENT " V418,"class GFG { static boolean isHeap ( int arr [ ] , int i , int n ) { if ( i > ( n - 2 ) / 2 ) { return true ; } if ( arr [ i ] >= arr [ 2 * i + 1 ] && arr [ i ] >= arr [ 2 * i + 2 ] && isHeap ( arr , 2 * i + 1 , n ) && isHeap ( arr , 2 * i + 2 , n ) ) { return true ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 } ; int n = arr . length - 1 ; if ( isHeap ( arr , 0 , n ) ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } } ","def isHeap ( arr , i , n ) : NEW_LINE INDENT if i > int ( ( n - 2 ) / 2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( arr [ i ] >= arr [ 2 * i + 1 ] and arr [ i ] >= arr [ 2 * i + 2 ] and isHeap ( arr , 2 * i + 1 , n ) and isHeap ( arr , 2 * i + 2 , n ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 90 , 15 , 10 , 7 , 12 , 2 , 7 , 3 ] NEW_LINE n = len ( arr ) - 1 NEW_LINE if isHeap ( arr , 0 , n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V419,"class Fibonacci { static int fibonacci ( int n ) { int a = 0 ; int b = 1 ; int c = 0 ; if ( n <= 1 ) return n ; for ( int i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } static boolean isMultipleOf10 ( int n ) { int f = fibonacci ( 30 ) ; return ( f % 10 == 0 ) ; } public static void main ( String [ ] args ) { int n = 30 ; if ( isMultipleOf10 ( n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def fibonacci ( n ) : NEW_LINE INDENT a = 0 NEW_LINE b = 1 NEW_LINE if ( n <= 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT c = a + b NEW_LINE a = b NEW_LINE b = c NEW_LINE DEDENT return c NEW_LINE DEDENT def isMultipleOf10 ( n ) : NEW_LINE INDENT f = fibonacci ( 30 ) NEW_LINE return ( f % 10 == 0 ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 30 NEW_LINE if ( isMultipleOf10 ( n ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V420,"import java . io . * ; class GFG { static void printPascal ( int n ) { for ( int line = 0 ; line < n ; line ++ ) { for ( int i = 0 ; i <= line ; i ++ ) System . out . print ( binomialCoeff ( line , i ) + "" ▁ "" ) ; System . out . println ( ) ; } } static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } public static void main ( String args [ ] ) { int n = 7 ; printPascal ( n ) ; } } ","def printPascal ( n ) : NEW_LINE INDENT for line in range ( 0 , n ) : NEW_LINE INDENT for i in range ( 0 , line + 1 ) : NEW_LINE INDENT print ( binomialCoeff ( line , i ) , "" ▁ "" , end = "" "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT def binomialCoeff ( n , k ) : NEW_LINE INDENT res = 1 NEW_LINE if ( k > n - k ) : NEW_LINE INDENT k = n - k NEW_LINE DEDENT for i in range ( 0 , k ) : NEW_LINE INDENT res = res * ( n - i ) NEW_LINE res = res // ( i + 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT n = 7 NEW_LINE printPascal ( n ) NEW_LINE " V421,"import java . io . * ; public class GFG { static int findSum ( int n ) { n -- ; int sum = 0 ; sum += ( n * ( n + 1 ) ) / 2 ; sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; return sum ; } static public void main ( String [ ] args ) { int n = 3 ; System . out . println ( findSum ( n ) ) ; } } ","def findSum ( n ) : NEW_LINE INDENT n -= 1 NEW_LINE sum = 0 NEW_LINE sum += ( n * ( n + 1 ) ) / 2 NEW_LINE sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 NEW_LINE return int ( sum ) NEW_LINE DEDENT n = 3 NEW_LINE print ( findSum ( n ) ) NEW_LINE " V422,"import java . io . * ; import java . util . * ; import java . math . * ; class GFG { static int NO_OF_CHARS = 256 ; static boolean canFormPalindrome ( String str ) { int count [ ] = new int [ NO_OF_CHARS ] ; Arrays . fill ( count , 0 ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) count [ ( int ) ( str . charAt ( i ) ) ] ++ ; int odd = 0 ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) { if ( ( count [ i ] & 1 ) == 1 ) odd ++ ; if ( odd > 1 ) return false ; } return true ; } public static void main ( String args [ ] ) { if ( canFormPalindrome ( "" geeksforgeeks "" ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; if ( canFormPalindrome ( "" geeksogeeks "" ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","NO_OF_CHARS = 256 NEW_LINE def canFormPalindrome ( st ) : NEW_LINE INDENT count = [ 0 ] * ( NO_OF_CHARS ) NEW_LINE for i in range ( 0 , len ( st ) ) : NEW_LINE INDENT count [ ord ( st [ i ] ) ] = count [ ord ( st [ i ] ) ] + 1 NEW_LINE DEDENT odd = 0 NEW_LINE for i in range ( 0 , NO_OF_CHARS ) : NEW_LINE INDENT if ( count [ i ] & 1 ) : NEW_LINE INDENT odd = odd + 1 NEW_LINE DEDENT if ( odd > 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if ( canFormPalindrome ( "" geeksforgeeks "" ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT if ( canFormPalindrome ( "" geeksogeeks "" ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V423,"class GFG { static int nthTerm ( int N ) { int nth = 0 , first_term = 12 ; nth = ( int ) ( ( first_term * ( Math . pow ( 2 , N - 1 ) ) ) + 11 * ( ( Math . pow ( 2 , N - 1 ) ) - 1 ) ) ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( nthTerm ( N ) + "" \n "" ) ; } } ","def nthTerm ( N ) : NEW_LINE INDENT nth = 0 ; first_term = 12 ; NEW_LINE nth = ( first_term * ( pow ( 2 , N - 1 ) ) ) + \ NEW_LINE INDENT 11 * ( ( pow ( 2 , N - 1 ) ) - 1 ) ; NEW_LINE DEDENT return nth ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = 5 ; NEW_LINE print ( nthTerm ( N ) ) ; NEW_LINE DEDENT " V424,"import java . io . * ; public class GFG { static boolean Arrive ( int a , int b , int n ) { if ( n >= Math . abs ( a ) + Math . abs ( b ) && ( n - ( Math . abs ( a ) + Math . abs ( b ) ) ) % 2 == 0 ) return true ; return false ; } int main ( ) { return 0 ; } public static void main ( String [ ] args ) { int a = 5 , b = 5 , n = 11 ; if ( Arrive ( a , b , n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def Arrive ( a , b , n ) : NEW_LINE INDENT if ( n >= abs ( a ) + abs ( b ) and ( n - ( abs ( a ) + abs ( b ) ) ) % 2 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT a = 5 NEW_LINE b = 5 NEW_LINE n = 11 NEW_LINE if ( Arrive ( a , b , n ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V425,"class GFG { static int ack ( int m , int n ) { if ( m == 0 ) { return n + 1 ; } else if ( ( m > 0 ) && ( n == 0 ) ) { return ack ( m - 1 , 1 ) ; } else if ( ( m > 0 ) && ( n > 0 ) ) { return ack ( m - 1 , ack ( m , n - 1 ) ) ; } else return n + 1 ; } public static void main ( String args [ ] ) { System . out . println ( ack ( 1 , 2 ) ) ; } } ","def A ( m , n , s = "" % ▁ s "" ) : NEW_LINE INDENT print ( s % ( "" A ( % ▁ d , ▁ % ▁ d ) "" % ( m , n ) ) ) NEW_LINE if m == 0 : NEW_LINE INDENT return n + 1 NEW_LINE DEDENT if n == 0 : NEW_LINE INDENT return A ( m - 1 , 1 , s ) NEW_LINE DEDENT n2 = A ( m , n - 1 , s % ( "" A ( % ▁ d , ▁ % % ▁ s ) "" % ( m - 1 ) ) ) NEW_LINE return A ( m - 1 , n2 , s ) NEW_LINE DEDENT print ( A ( 1 , 2 ) ) NEW_LINE " V426,"class GFG { static int findCost ( String str , int arr [ ] , int n ) { long costofC = 0 , costofO = 0 , costofD = 0 , costofE = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == ' c ' ) costofC += arr [ i ] ; else if ( str . charAt ( i ) == ' o ' ) costofO = Math . min ( costofC , costofO + arr [ i ] ) ; else if ( str . charAt ( i ) == ' d ' ) costofD = Math . min ( costofO , costofD + arr [ i ] ) ; else if ( str . charAt ( i ) == ' e ' ) costofE = Math . min ( costofD , costofE + arr [ i ] ) ; } return ( int ) costofE ; } public static void main ( String [ ] args ) { String str = "" geekcodergeeks "" ; int arr [ ] = { 1 , 2 , 1 , 3 , 4 , 2 , 6 , 4 , 6 , 2 , 3 , 3 , 3 , 2 } ; int n = arr . length ; System . out . print ( findCost ( str , arr , n ) ) ; } } ","def findCost ( str , arr , n ) : NEW_LINE INDENT costofC , costofO = 0 , 0 NEW_LINE costofD , costofE = 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( str [ i ] == ' c ' ) : NEW_LINE INDENT costofC += arr [ i ] NEW_LINE DEDENT elif ( str [ i ] == ' o ' ) : NEW_LINE INDENT costofO = min ( costofC , costofO + arr [ i ] ) NEW_LINE DEDENT elif ( str [ i ] == ' d ' ) : NEW_LINE INDENT costofD = min ( costofO , costofD + arr [ i ] ) NEW_LINE DEDENT elif ( str [ i ] == ' e ' ) : NEW_LINE INDENT costofE = min ( costofD , costofE + arr [ i ] ) NEW_LINE DEDENT DEDENT return costofE NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = "" geekcodergeeks "" NEW_LINE arr = [ 1 , 2 , 1 , 3 , 4 , 2 , 6 , 4 , 6 , 2 , 3 , 3 , 3 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findCost ( str , arr , n ) ) NEW_LINE DEDENT " V427,"import java . io . * ; import java . util . * ; class Kadane { public static void main ( String [ ] args ) { int [ ] a = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; System . out . println ( "" Maximum ▁ contiguous ▁ sum ▁ is ▁ "" + maxSubArraySum ( a ) ) ; } static int maxSubArraySum ( int a [ ] ) { int size = a . length ; int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } } ","from sys import maxint NEW_LINE def maxSubArraySum ( a , size ) : NEW_LINE INDENT max_so_far = - maxint - 1 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_so_far < max_ending_here ) : NEW_LINE INDENT max_so_far = max_ending_here NEW_LINE DEDENT if max_ending_here < 0 : NEW_LINE INDENT max_ending_here = 0 NEW_LINE DEDENT DEDENT return max_so_far NEW_LINE DEDENT a = [ - 13 , - 3 , - 25 , - 20 , - 3 , - 16 , - 23 , - 12 , - 5 , - 22 , - 15 , - 4 , - 7 ] NEW_LINE print "" Maximum ▁ contiguous ▁ sum ▁ is "" , maxSubArraySum ( a , len ( a ) ) NEW_LINE " V428,"import java . io . * ; class GFG { static int factorial ( int a , int b ) { int res = 1 ; for ( int i = 1 ; i <= ( a + b ) ; i ++ ) res = res * i ; for ( int i = 1 ; i <= a ; i ++ ) res = res / i ; for ( int i = 1 ; i <= b ; i ++ ) res = res / i ; return res ; } static void Ksmallest ( int x , int y , int k ) { if ( x == 0 && y == 0 ) return ; else if ( x == 0 ) { y -- ; System . out . print ( "" V "" ) ; Ksmallest ( x , y , k ) ; } else if ( y == 0 ) { x -- ; System . out . print ( "" H "" ) ; Ksmallest ( x , y , k ) ; } else { if ( factorial ( x - 1 , y ) > k ) { System . out . print ( "" H "" ) ; Ksmallest ( x - 1 , y , k ) ; } else { System . out . print ( "" V "" ) ; Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) ; } } } public static void main ( String [ ] args ) { int x = 2 , y = 2 , k = 2 ; Ksmallest ( x , y , k ) ; } } ","def factorial ( a , b ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , a + b + 1 ) : NEW_LINE INDENT res = res * i NEW_LINE DEDENT for i in range ( 1 , a + 1 ) : NEW_LINE INDENT res = res // i NEW_LINE DEDENT for i in range ( 1 , b + 1 ) : NEW_LINE INDENT res = res // i NEW_LINE DEDENT return res NEW_LINE DEDENT def Ksmallest ( x , y , k ) : NEW_LINE INDENT if x == 0 and y == 0 : NEW_LINE INDENT return NEW_LINE DEDENT elif x == 0 : NEW_LINE INDENT y -= 1 NEW_LINE print ( "" V "" , end = "" "" ) NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT elif y == 0 : NEW_LINE INDENT x -= 1 NEW_LINE print ( "" H "" , end = "" "" ) NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT else : NEW_LINE INDENT if factorial ( x - 1 , y ) > k : NEW_LINE INDENT print ( "" H "" , end = "" "" ) NEW_LINE Ksmallest ( x - 1 , y , k ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" V "" , end = "" "" ) NEW_LINE Ksmallest ( x , y - 1 , k - factorial ( x - 1 , y ) ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT x , y , k = 2 , 2 , 2 NEW_LINE Ksmallest ( x , y , k ) NEW_LINE DEDENT " V429,"import java . util . * ; class GFG { static int MaxIncreasingSub ( int arr [ ] , int n , int k ) { int dp [ ] [ ] = new int [ n ] [ k + 1 ] , ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < k + 1 ; j ++ ) dp [ i ] [ j ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i ] [ 1 ] = arr [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { for ( int l = 1 ; l <= k - 1 ; l ++ ) { if ( dp [ j ] [ l ] != - 1 ) { dp [ i ] [ l + 1 ] = Math . max ( dp [ i ] [ l + 1 ] , dp [ j ] [ l ] + arr [ i ] ) ; } } } } } for ( int i = 0 ; i < n ; i ++ ) { if ( ans < dp [ i ] [ k ] ) ans = dp [ i ] [ k ] ; } return ( ans == - 1 ) ? 0 : ans ; } public static void main ( String args [ ] ) { int n = 8 , k = 3 ; int arr [ ] = { 8 , 5 , 9 , 10 , 5 , 6 , 21 , 8 } ; int ans = MaxIncreasingSub ( arr , n , k ) ; System . out . println ( ans ) ; } } ","def MaxIncreasingSub ( arr , n , k ) : NEW_LINE INDENT dp = [ - 1 ] * n NEW_LINE ans = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT dp [ i ] = [ - 1 ] * ( k + 1 ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT dp [ i ] [ 1 ] = arr [ i ] NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT if arr [ j ] < arr [ i ] : NEW_LINE INDENT for l in range ( 1 , k ) : NEW_LINE INDENT if dp [ j ] [ l ] != - 1 : NEW_LINE INDENT dp [ i ] [ l + 1 ] = max ( dp [ i ] [ l + 1 ] , dp [ j ] [ l ] + arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ans < dp [ i ] [ k ] : NEW_LINE INDENT ans = dp [ i ] [ k ] NEW_LINE DEDENT DEDENT return ( 0 if ans == - 1 else ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n , k = 8 , 3 NEW_LINE arr = [ 8 , 5 , 9 , 10 , 5 , 6 , 21 , 8 ] NEW_LINE ans = MaxIncreasingSub ( arr , n , k ) NEW_LINE print ( ans ) NEW_LINE DEDENT " V430,"class GFG { static int max_xor ( int arr [ ] , int n ) { int maxXor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { maxXor = Math . max ( maxXor , arr [ i ] ^ arr [ j ] ) ; } } return maxXor ; } public static void main ( String [ ] args ) { int arr [ ] = { 25 , 10 , 2 , 8 , 5 , 3 } ; int n = arr . length ; System . out . println ( max_xor ( arr , n ) ) ; } } ","def max_xor ( arr , n ) : NEW_LINE INDENT maxXor = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT maxXor = max ( maxXor , \ arr [ i ] ^ arr [ j ] ) ; NEW_LINE DEDENT DEDENT return maxXor ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 25 , 10 , 2 , 8 , 5 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( max_xor ( arr , n ) ) ; NEW_LINE DEDENT " V431,"class GFG { static int countAnomalies ( int arr [ ] , int n , int k ) { int cnt = 0 ; int i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( Math . abs ( arr [ i ] - ( sum - arr [ i ] ) ) > k ) cnt ++ ; return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 } ; int n = arr . length ; int k = 1 ; System . out . print ( countAnomalies ( arr , n , k ) ) ; } } ","def countAnomalies ( arr , n , k ) : NEW_LINE INDENT cnt = 0 NEW_LINE i , Sum = 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT Sum += arr [ i ] NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( abs ( arr [ i ] - ( Sum - arr [ i ] ) ) > k ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT arr = [ 1 , 3 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE k = 1 NEW_LINE print ( countAnomalies ( arr , n , k ) ) NEW_LINE " V432,"import java . util . * ; class GFG { static int cntWays ( String str , int n ) { int x = n + 1 ; int ways = x * x * ( x * x - 1 ) / 12 ; return ways ; } public static void main ( String [ ] args ) { String str = "" ab "" ; int n = str . length ( ) ; System . out . println ( cntWays ( str , n ) ) ; } } ","def cntWays ( string , n ) : NEW_LINE INDENT x = n + 1 ; NEW_LINE ways = x * x * ( x * x - 1 ) // 12 ; NEW_LINE return ways ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" ab "" ; NEW_LINE n = len ( string ) ; NEW_LINE print ( cntWays ( string , n ) ) ; NEW_LINE DEDENT " V433,"import java . io . * ; class GFG { static int divisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) sum += ( n / i ) * i ; return sum ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( divisorSum ( n ) ) ; n = 5 ; System . out . println ( divisorSum ( n ) ) ; } } ","def divisorSum ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += int ( n / i ) * i NEW_LINE DEDENT return int ( sum ) NEW_LINE DEDENT n = 4 NEW_LINE print ( divisorSum ( n ) ) NEW_LINE n = 5 NEW_LINE print ( divisorSum ( n ) ) NEW_LINE " V434,"class GFG { static void printString ( char [ ] str , int n ) { int ones = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( str [ i ] == '1' ) ones ++ ; boolean used = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '2' && ! used ) { used = true ; for ( int j = 0 ; j < ones ; j ++ ) System . out . print ( ""1"" ) ; } if ( str [ i ] != '1' ) System . out . print ( str [ i ] ) ; } if ( ! used ) for ( int j = 0 ; j < ones ; j ++ ) System . out . print ( ""1"" ) ; } public static void main ( String [ ] args ) { String str = ""100210"" ; int n = str . length ( ) ; printString ( str . toCharArray ( ) , n ) ; } } ","def printString ( Str1 , n ) : NEW_LINE INDENT ones = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( Str1 [ i ] == '1' ) : NEW_LINE INDENT ones += 1 NEW_LINE DEDENT DEDENT used = False NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( Str1 [ i ] == '2' and used == False ) : NEW_LINE INDENT used = 1 NEW_LINE for j in range ( ones ) : NEW_LINE INDENT print ( ""1"" , end = "" "" ) NEW_LINE DEDENT DEDENT if ( Str1 [ i ] != '1' ) : NEW_LINE INDENT print ( Str1 [ i ] , end = "" "" ) NEW_LINE DEDENT DEDENT if ( used == False ) : NEW_LINE INDENT for j in range ( ones ) : NEW_LINE INDENT print ( ""1"" , end = "" "" ) NEW_LINE DEDENT DEDENT DEDENT Str1 = ""100210"" NEW_LINE n = len ( Str1 ) NEW_LINE printString ( Str1 , n ) NEW_LINE " V435,"import java . io . * ; class GFG { static int bitAtGivenPosSetOrUnset ( int n , int k ) { int new_num = n >> ( k - 1 ) ; return ( new_num & 1 ) ; } public static void main ( String [ ] args ) { int n = 10 , k = 2 ; if ( bitAtGivenPosSetOrUnset ( n , k ) == 1 ) System . out . println ( "" Set "" ) ; else System . out . println ( "" Unset "" ) ; } } ","import math NEW_LINE def bitAtGivenPosSetOrUnset ( n , k ) : NEW_LINE INDENT new_num = n >> ( k - 1 ) NEW_LINE return ( new_num & 1 ) NEW_LINE DEDENT n = 10 NEW_LINE k = 2 NEW_LINE if ( bitAtGivenPosSetOrUnset ( n , k ) ) : NEW_LINE INDENT print ( "" Set "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Unset "" ) NEW_LINE DEDENT " V436,"import java . util . HashMap ; class GFG { static int commonWords ( String [ ] s ) { int m , i , j ; String str ; HashMap < String , Boolean > has = new HashMap < > ( ) ; String [ ] ans1 = new String [ 100 ] ; boolean [ ] ans2 = new boolean [ 100 ] ; int track = 0 ; m = s . length ; i = 0 ; while ( i < s [ 0 ] . length ( ) ) { str = "" "" ; while ( i < s [ 0 ] . length ( ) && s [ 0 ] . charAt ( i ) != ' ▁ ' ) { str += s [ 0 ] . charAt ( i ) ; i ++ ; } i ++ ; if ( str . compareTo ( "" "" ) != 0 ) { ans1 [ track ] = str ; ans2 [ track ] = true ; track ++ ; } } for ( j = 1 ; j < m ; j ++ ) { has . clear ( ) ; i = 0 ; while ( i < s [ j ] . length ( ) ) { str = "" "" ; while ( i < s [ j ] . length ( ) && s [ j ] . charAt ( i ) != ' ▁ ' ) { str += s [ j ] . charAt ( i ) ; i ++ ; } i ++ ; if ( str . compareTo ( "" "" ) != 0 ) has . put ( str , true ) ; } for ( int k = 0 ; k < track ; k ++ ) { if ( ans2 [ k ] != false && ! has . containsKey ( ans1 [ k ] ) ) ans2 [ k ] = false ; else if ( ans2 [ k ] != false && has . containsKey ( ans1 [ k ] ) && has . get ( ans1 [ k ] ) == true ) has . put ( ans1 [ k ] , false ) ; } } int cnt = 0 ; for ( int k = 0 ; k < track ; k ++ ) if ( ans2 [ k ] == true ) cnt ++ ; return cnt ; } public static void main ( String [ ] args ) { String [ ] s = { "" there ▁ is ▁ a ▁ cow "" , "" cow ▁ is ▁ our ▁ mother "" , "" cow ▁ gives ▁ us ▁ milk ▁ and ▁ milk ▁ is ▁ sweet "" , "" there ▁ is ▁ a ▁ boy ▁ who ▁ loves ▁ cow "" } ; System . out . println ( commonWords ( s ) ) ; } } ","from collections import defaultdict NEW_LINE def commonWords ( S ) : NEW_LINE INDENT has = defaultdict ( lambda : False ) NEW_LINE ans = [ ] NEW_LINE m = len ( S ) NEW_LINE i = 0 NEW_LINE while i < len ( S [ 0 ] ) : NEW_LINE INDENT string = "" "" NEW_LINE while i < len ( S [ 0 ] ) and S [ 0 ] [ i ] != ' ▁ ' : NEW_LINE INDENT string += S [ 0 ] [ i ] NEW_LINE i += 1 NEW_LINE DEDENT i += 1 NEW_LINE if string != "" "" : NEW_LINE INDENT ans . append ( [ string , True ] ) NEW_LINE DEDENT DEDENT for j in range ( 1 , m ) : NEW_LINE INDENT has . clear ( ) NEW_LINE i = 0 NEW_LINE while i < len ( S [ j ] ) : NEW_LINE INDENT string = "" "" NEW_LINE while i < len ( S [ j ] ) and S [ j ] [ i ] != ' ▁ ' : NEW_LINE INDENT string += S [ j ] [ i ] NEW_LINE i += 1 NEW_LINE DEDENT i += 1 NEW_LINE if string != "" "" : NEW_LINE INDENT has [ string ] = True NEW_LINE DEDENT DEDENT for k in range ( 0 , len ( ans ) ) : NEW_LINE INDENT if ( ans [ k ] [ 1 ] != False and has [ ans [ k ] [ 0 ] ] == False ) : NEW_LINE INDENT ans [ k ] [ 1 ] = False NEW_LINE DEDENT elif ( ans [ k ] [ 1 ] != False and has [ ans [ k ] [ 0 ] ] == True ) : NEW_LINE INDENT has [ ans [ k ] [ 0 ] ] = False NEW_LINE DEDENT DEDENT DEDENT cnt = 0 NEW_LINE for k in range ( 0 , len ( ans ) ) : NEW_LINE INDENT if ans [ k ] [ 1 ] == True : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT S = [ ] NEW_LINE S . append ( "" there ▁ is ▁ a ▁ cow "" ) NEW_LINE S . append ( "" cow ▁ is ▁ our ▁ mother "" ) NEW_LINE S . append ( "" cow ▁ gives ▁ us ▁ milk ▁ and ▁ milk ▁ is ▁ sweet "" ) NEW_LINE S . append ( "" there ▁ is ▁ a ▁ boy ▁ who ▁ loves ▁ cow "" ) NEW_LINE print ( commonWords ( S ) ) NEW_LINE DEDENT " V437,"import java . util . * ; class solution { static double circlearea ( double a ) { if ( a < 0 ) return - 1 ; double A = ( 3.14 * 3 * Math . pow ( a , 2 ) ) / 4 ; return A ; } public static void main ( String arr [ ] ) { double a = 4 ; System . out . println ( circlearea ( a ) ) ; } } ","def circlearea ( a ) : NEW_LINE INDENT if a < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT A = ( 3.14 * 3 * pow ( a , 2 ) ) / 4 NEW_LINE return A NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = 4 NEW_LINE print ( circlearea ( a ) ) NEW_LINE DEDENT " V438,"import java . util . * ; class GFG { static void checkTypeOfTriangle ( int a , int b , int c ) { int sqa = ( int ) Math . pow ( a , 2 ) ; int sqb = ( int ) Math . pow ( b , 2 ) ; int sqc = ( int ) Math . pow ( c , 2 ) ; if ( sqa == sqa + sqb || sqb == sqa + sqc || sqc == sqa + sqb ) { System . out . print ( "" Right - angled ▁ Triangle "" ) ; } else if ( sqa > sqc + sqb || sqb > sqa + sqc || sqc > sqa + sqb ) { System . out . print ( "" Obtuse - angled ▁ Triangle "" ) ; } else { System . out . print ( "" Acute - angled ▁ Triangle "" ) ; } } public static void main ( String [ ] args ) { int a , b , c ; a = 2 ; b = 2 ; c = 2 ; checkTypeOfTriangle ( a , b , c ) ; } } ","def checkTypeOfTriangle ( a , b , c ) : NEW_LINE INDENT sqa = pow ( a , 2 ) NEW_LINE sqb = pow ( b , 2 ) NEW_LINE sqc = pow ( c , 2 ) NEW_LINE if ( sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb ) : NEW_LINE INDENT print ( "" Right - angled ▁ Triangle "" ) NEW_LINE DEDENT elif ( sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb ) : NEW_LINE INDENT print ( "" Obtuse - angled ▁ Triangle "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Acute - angled ▁ Triangle "" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 2 NEW_LINE b = 2 NEW_LINE c = 2 NEW_LINE checkTypeOfTriangle ( a , b , c ) NEW_LINE DEDENT " V439,"public class GFG { public static int cubesum ( int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( 2 * i + 1 ) * ( 2 * i + 1 ) * ( 2 * i + 1 ) ; return sum ; } public static void main ( String args [ ] ) { int a = 5 ; System . out . println ( cubesum ( a ) ) ; } } ","def cubeSum ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sum += ( 2 * i + 1 ) * ( 2 * i + 1 ) * ( 2 * i + 1 ) NEW_LINE DEDENT return sum NEW_LINE DEDENT print ( cubeSum ( 2 ) ) NEW_LINE " V440,"class GFG { static void multiply ( int F [ ] [ ] , int M [ ] [ ] ) { int x = F [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 0 ] ; int y = F [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 1 ] ; int z = F [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 0 ] ; int w = F [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 1 ] ; F [ 0 ] [ 0 ] = x ; F [ 0 ] [ 1 ] = y ; F [ 1 ] [ 0 ] = z ; F [ 1 ] [ 1 ] = w ; } static void power ( int F [ ] [ ] , int n ) { if ( n == 0 || n == 1 ) { return ; } int M [ ] [ ] = { { 1 , 1 } , { 1 , 0 } } ; power ( F , n / 2 ) ; multiply ( F , F ) ; if ( n % 2 != 0 ) { multiply ( F , M ) ; } } static int countWays ( int n ) { int F [ ] [ ] = { { 1 , 1 } , { 1 , 0 } } ; if ( n == 0 ) { return 0 ; } power ( F , n ) ; return F [ 0 ] [ 0 ] ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( countWays ( n ) ) ; } } ","def multiply ( F , M ) : NEW_LINE INDENT x = F [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 0 ] NEW_LINE y = F [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 1 ] NEW_LINE z = F [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 0 ] NEW_LINE w = F [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 1 ] NEW_LINE F [ 0 ] [ 0 ] = x NEW_LINE F [ 0 ] [ 1 ] = y NEW_LINE F [ 1 ] [ 0 ] = z NEW_LINE F [ 1 ] [ 1 ] = w NEW_LINE DEDENT def power ( F , n ) : NEW_LINE INDENT if ( n == 0 or n == 1 ) : NEW_LINE INDENT return NEW_LINE DEDENT M = [ [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE power ( F , n // 2 ) NEW_LINE multiply ( F , F ) NEW_LINE if ( n % 2 != 0 ) : NEW_LINE INDENT multiply ( F , M ) NEW_LINE DEDENT DEDENT def countWays ( n ) : NEW_LINE INDENT F = [ [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT power ( F , n ) NEW_LINE return F [ 0 ] [ 0 ] NEW_LINE DEDENT n = 5 NEW_LINE print ( countWays ( n ) ) NEW_LINE " V441,"class GFG { static long answer ( int n ) { int [ ] dp = new int [ 10 ] ; int [ ] prev = new int [ 10 ] ; if ( n == 1 ) return 10 ; for ( int j = 0 ; j <= 9 ; j ++ ) dp [ j ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { prev [ j ] = dp [ j ] ; } for ( int j = 0 ; j <= 9 ; j ++ ) { if ( j == 0 ) dp [ j ] = prev [ j + 1 ] ; else if ( j == 9 ) dp [ j ] = prev [ j - 1 ] ; else dp [ j ] = prev [ j - 1 ] + prev [ j + 1 ] ; } } long sum = 0 ; for ( int j = 1 ; j <= 9 ; j ++ ) sum += dp [ j ] ; return sum ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( answer ( n ) ) ; } } ","def answer ( n ) : NEW_LINE INDENT dp = [ 0 ] * 10 NEW_LINE prev = [ 0 ] * 10 NEW_LINE if ( n == 1 ) : NEW_LINE INDENT return 10 NEW_LINE DEDENT for j in range ( 0 , 10 ) : NEW_LINE INDENT dp [ j ] = 1 NEW_LINE DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT for j in range ( 0 , 10 ) : NEW_LINE INDENT prev [ j ] = dp [ j ] NEW_LINE DEDENT for j in range ( 0 , 10 ) : NEW_LINE INDENT if ( j == 0 ) : NEW_LINE INDENT dp [ j ] = prev [ j + 1 ] NEW_LINE DEDENT elif ( j == 9 ) : NEW_LINE INDENT dp [ j ] = prev [ j - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ j ] = prev [ j - 1 ] + prev [ j + 1 ] NEW_LINE DEDENT DEDENT DEDENT sum = 0 NEW_LINE for j in range ( 1 , 10 ) : NEW_LINE INDENT sum = sum + dp [ j ] NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 2 NEW_LINE print ( answer ( n ) ) NEW_LINE " V442,"class GFG { static double PHI = 1.6180339 ; static int f [ ] = { 0 , 1 , 1 , 2 , 3 , 5 } ; static int fib ( int n ) { if ( n < 6 ) return f [ n ] ; int t = 5 ; int fn = 5 ; while ( t < n ) { fn = ( int ) Math . round ( fn * PHI ) ; t ++ ; } return fn ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( n + "" th ▁ Fibonacci ▁ Number ▁ = ▁ "" + fib ( n ) ) ; } } ","PHI = 1.6180339 NEW_LINE f = [ 0 , 1 , 1 , 2 , 3 , 5 ] NEW_LINE def fib ( n ) : NEW_LINE INDENT if n < 6 : NEW_LINE INDENT return f [ n ] NEW_LINE DEDENT t = 5 NEW_LINE fn = 5 NEW_LINE while t < n : NEW_LINE INDENT fn = round ( fn * PHI ) NEW_LINE t += 1 NEW_LINE DEDENT return fn NEW_LINE DEDENT n = 9 NEW_LINE print ( n , "" th ▁ Fibonacci ▁ Number ▁ = "" , fib ( n ) ) NEW_LINE " V443,"public class GFG { static void printHutStar ( int n ) { int i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) System . out . print ( "" ▁ "" ) ; for ( j = 0 ; j < ( 2 * i + 1 ) ; j ++ ) System . out . print ( "" * "" ) ; System . out . println ( ) ; } for ( i = 0 ; i < 3 ; i ++ ) { for ( j = 0 ; j < 3 ; j ++ ) System . out . print ( "" * "" ) ; for ( j = 0 ; j < ( 2 * n - 7 ) ; j ++ ) System . out . print ( "" ▁ "" ) ; for ( j = 0 ; j < 3 ; j ++ ) System . out . print ( "" * "" ) ; System . out . println ( ) ; } } public static void main ( String args [ ] ) { int n = 7 ; printHutStar ( n ) ; } } ","def printHutStar ( n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT print ( ' ▁ ' , end = ' ' ) NEW_LINE DEDENT for j in range ( 0 , 2 * i + 1 ) : NEW_LINE INDENT print ( ' * ' , end = ' ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT for i in range ( 3 ) : NEW_LINE INDENT for j in range ( 3 ) : NEW_LINE INDENT print ( ' * ' , end = ' ' ) NEW_LINE DEDENT for j in range ( 2 * n - 7 ) : NEW_LINE INDENT print ( ' ▁ ' , end = ' ' ) NEW_LINE DEDENT for j in range ( 3 ) : NEW_LINE INDENT print ( ' * ' , end = ' ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT n = 7 NEW_LINE printHutStar ( n ) NEW_LINE " V444,"import java . io . * ; import java . math . * ; class GFG { static int Modulo ( int a , char b [ ] ) { int mod = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) mod = ( mod * 10 + b [ i ] - '0' ) % a ; return mod ; } static int LastDigit ( char a [ ] , char b [ ] ) { int len_a = a . length , len_b = b . length ; if ( len_a == 1 && len_b == 1 && b [ 0 ] == '0' && a [ 0 ] == '0' ) return 1 ; if ( len_b == 1 && b [ 0 ] == '0' ) return 1 ; if ( len_a == 1 && a [ 0 ] == '0' ) return 0 ; int exp = ( Modulo ( 4 , b ) == 0 ) ? 4 : Modulo ( 4 , b ) ; int res = ( int ) ( Math . pow ( a [ len_a - 1 ] - '0' , exp ) ) ; return res % 10 ; } public static void main ( String args [ ] ) throws IOException { char a [ ] = ""117"" . toCharArray ( ) , b [ ] = { '3' } ; System . out . println ( LastDigit ( a , b ) ) ; } } ","import math NEW_LINE def Modulo ( a , b ) : NEW_LINE INDENT mod = 0 NEW_LINE for i in range ( 0 , len ( b ) ) : NEW_LINE INDENT mod = ( mod * 10 + ( int ) ( b [ i ] ) ) % a NEW_LINE DEDENT return mod NEW_LINE DEDENT def LastDigit ( a , b ) : NEW_LINE INDENT len_a = len ( a ) NEW_LINE len_b = len ( b ) NEW_LINE if ( len_a == 1 and len_b == 1 and b [ 0 ] == '0' and a [ 0 ] == '0' ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( len_b == 1 and b [ 0 ] == '0' ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( len_a == 1 and a [ 0 ] == '0' ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( ( Modulo ( 4 , b ) == 0 ) ) : NEW_LINE INDENT exp = 4 NEW_LINE DEDENT else : NEW_LINE INDENT exp = Modulo ( 4 , b ) NEW_LINE DEDENT res = math . pow ( ( int ) ( a [ len_a - 1 ] ) , exp ) NEW_LINE return res % 10 NEW_LINE DEDENT a = [ '1' , '1' , '7' ] NEW_LINE b = [ '3' ] NEW_LINE print ( LastDigit ( a , b ) ) NEW_LINE " V445,"import java . io . * ; import java . math . * ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static boolean miillerTest ( int d , int n ) { int a = 2 + ( int ) ( Math . random ( ) % ( n - 4 ) ) ; int x = power ( a , d , n ) ; if ( x == 1 || x == n - 1 ) return true ; while ( d != n - 1 ) { x = ( x * x ) % n ; d *= 2 ; if ( x == 1 ) return false ; if ( x == n - 1 ) return true ; } return false ; } static boolean isPrime ( int n , int k ) { if ( n <= 1 || n == 4 ) return false ; if ( n <= 3 ) return true ; int d = n - 1 ; while ( d % 2 == 0 ) d /= 2 ; for ( int i = 0 ; i < k ; i ++ ) if ( ! miillerTest ( d , n ) ) return false ; return true ; } public static void main ( String args [ ] ) { int k = 4 ; System . out . println ( "" All ▁ primes ▁ smaller ▁ "" + "" than ▁ 100 : ▁ "" ) ; for ( int n = 1 ; n < 100 ; n ++ ) if ( isPrime ( n , k ) ) System . out . print ( n + "" ▁ "" ) ; } } ","import random NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT res = 1 ; NEW_LINE x = x % p ; NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p ; NEW_LINE DEDENT y = y >> 1 ; NEW_LINE x = ( x * x ) % p ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT def miillerTest ( d , n ) : NEW_LINE INDENT a = 2 + random . randint ( 1 , n - 4 ) ; NEW_LINE x = power ( a , d , n ) ; NEW_LINE if ( x == 1 or x == n - 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT while ( d != n - 1 ) : NEW_LINE INDENT x = ( x * x ) % n ; NEW_LINE d *= 2 ; NEW_LINE if ( x == 1 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT if ( x == n - 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT def isPrime ( n , k ) : NEW_LINE INDENT if ( n <= 1 or n == 4 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT d = n - 1 ; NEW_LINE while ( d % 2 == 0 ) : NEW_LINE INDENT d //= 2 ; NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT if ( miillerTest ( d , n ) == False ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT k = 4 ; NEW_LINE print ( "" All ▁ primes ▁ smaller ▁ than ▁ 100 : ▁ "" ) ; NEW_LINE for n in range ( 1 , 100 ) : NEW_LINE INDENT if ( isPrime ( n , k ) ) : NEW_LINE INDENT print ( n , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT " V446,"class GFG { static int remainderWith7 ( String num ) { int series [ ] = { 1 , 3 , 2 , - 1 , - 3 , - 2 } ; int series_index = 0 ; int result = 0 ; for ( int i = num . length ( ) - 1 ; i >= 0 ; i -- ) { int digit = num . charAt ( i ) - '0' ; result += digit * series [ series_index ] ; series_index = ( series_index + 1 ) % 6 ; result %= 7 ; } if ( result < 0 ) result = ( result + 7 ) % 7 ; return result ; } public static void main ( String [ ] args ) { String str = ""12345"" ; System . out . print ( "" Remainder ▁ with ▁ 7 ▁ is ▁ "" + remainderWith7 ( str ) ) ; } } ","def remainderWith7 ( num ) : NEW_LINE INDENT series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ] ; NEW_LINE series_index = 0 ; NEW_LINE result = 0 ; NEW_LINE for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) : NEW_LINE INDENT digit = ord ( num [ i ] ) - 48 ; NEW_LINE result += digit * series [ series_index ] ; NEW_LINE series_index = ( series_index + 1 ) % 6 ; NEW_LINE result %= 7 ; NEW_LINE DEDENT if ( result < 0 ) : NEW_LINE INDENT result = ( result + 7 ) % 7 ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT str = ""12345"" ; NEW_LINE print ( "" Remainder ▁ with ▁ 7 ▁ is "" , remainderWith7 ( str ) ) ; NEW_LINE " V447,"import java . util . * ; class GFG { public static int nthTerm ( int n ) { return ( n * n ) + ( n * n * n ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( nthTerm ( n ) ) ; } } ","def nthTerm ( n ) : NEW_LINE INDENT return ( n * n ) + ( n * n * n ) NEW_LINE DEDENT n = 4 NEW_LINE print ( nthTerm ( n ) ) NEW_LINE " V448,"import java . util . * ; class GFG { static void findTriplets ( int x ) { Vector < Integer > fact = new Vector < Integer > ( ) ; HashSet < Integer > factors = new HashSet < Integer > ( ) ; for ( int i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { fact . add ( i ) ; if ( x / i != i ) fact . add ( x / i ) ; factors . add ( i ) ; factors . add ( x / i ) ; } } boolean found = false ; int k = fact . size ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int a = fact . get ( i ) ; for ( int j = 0 ; j < k ; j ++ ) { int b = fact . get ( j ) ; if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) { System . out . print ( a + "" ▁ "" + b + "" ▁ "" + ( x / ( a * b ) ) ) ; found = true ; break ; } } if ( found ) break ; } if ( ! found ) System . out . print ( "" - 1"" ) ; } public static void main ( String [ ] args ) { int x = 105 ; findTriplets ( x ) ; } } ","from math import sqrt NEW_LINE def findTriplets ( x ) : NEW_LINE INDENT fact = [ ] ; NEW_LINE factors = set ( ) ; NEW_LINE for i in range ( 2 , int ( sqrt ( x ) ) ) : NEW_LINE INDENT if ( x % i == 0 ) : NEW_LINE INDENT fact . append ( i ) ; NEW_LINE if ( x / i != i ) : NEW_LINE INDENT fact . append ( x // i ) ; NEW_LINE DEDENT factors . add ( i ) ; NEW_LINE factors . add ( x // i ) ; NEW_LINE DEDENT DEDENT found = False ; NEW_LINE k = len ( fact ) ; NEW_LINE for i in range ( k ) : NEW_LINE INDENT a = fact [ i ] ; NEW_LINE for j in range ( k ) : NEW_LINE INDENT b = fact [ j ] ; NEW_LINE if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) : NEW_LINE INDENT print ( a , b , x // ( a * b ) ) ; NEW_LINE found = True ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( found ) : NEW_LINE INDENT break ; NEW_LINE DEDENT DEDENT if ( not found ) : NEW_LINE INDENT print ( "" - 1"" ) ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT x = 105 ; NEW_LINE findTriplets ( x ) ; NEW_LINE DEDENT " V449,"import java . util . * ; class GFG { static void unique_combination ( int l , int sum , int K , Vector < Integer > local , Vector < Integer > A ) { if ( sum == K ) { System . out . print ( "" { "" ) ; for ( int i = 0 ; i < local . size ( ) ; i ++ ) { if ( i != 0 ) System . out . print ( "" ▁ "" ) ; System . out . print ( local . get ( i ) ) ; if ( i != local . size ( ) - 1 ) System . out . print ( "" , ▁ "" ) ; } System . out . println ( "" } "" ) ; return ; } for ( int i = l ; i < A . size ( ) ; i ++ ) { if ( sum + A . get ( i ) > K ) continue ; if ( i == 1 && A . get ( i ) == A . get ( i - 1 ) && i > l ) continue ; local . add ( A . get ( i ) ) ; unique_combination ( i + 1 , sum + A . get ( i ) , K , local , A ) ; local . remove ( local . size ( ) - 1 ) ; } } static void Combination ( Vector < Integer > A , int K ) { Collections . sort ( A ) ; Vector < Integer > local = new Vector < Integer > ( ) ; unique_combination ( 0 , 0 , K , local , A ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 10 , 1 , 2 , 7 , 6 , 1 , 5 } ; Vector < Integer > A = new Vector < > ( Arrays . asList ( arr ) ) ; int K = 8 ; Combination ( A , K ) ; } } ","def unique_combination ( l , sum , K , local , A ) : NEW_LINE INDENT if ( sum == K ) : NEW_LINE INDENT print ( "" { "" , end = "" "" ) NEW_LINE for i in range ( len ( local ) ) : NEW_LINE INDENT if ( i != 0 ) : NEW_LINE INDENT print ( "" ▁ "" , end = "" "" ) NEW_LINE DEDENT print ( local [ i ] , end = "" "" ) NEW_LINE if ( i != len ( local ) - 1 ) : NEW_LINE INDENT print ( "" , ▁ "" , end = "" "" ) NEW_LINE DEDENT DEDENT print ( "" } "" ) NEW_LINE return NEW_LINE DEDENT for i in range ( l , len ( A ) , 1 ) : NEW_LINE INDENT if ( sum + A [ i ] > K ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( i == 1 and A [ i ] == A [ i - 1 ] and i > l ) : NEW_LINE INDENT continue NEW_LINE DEDENT local . append ( A [ i ] ) NEW_LINE unique_combination ( i + 1 , sum + A [ i ] , K , local , A ) NEW_LINE local . remove ( local [ len ( local ) - 1 ] ) NEW_LINE DEDENT DEDENT def Combination ( A , K ) : NEW_LINE INDENT A . sort ( reverse = False ) NEW_LINE local = [ ] NEW_LINE unique_combination ( 0 , 0 , K , local , A ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 10 , 1 , 2 , 7 , 6 , 1 , 5 ] NEW_LINE K = 8 NEW_LINE Combination ( A , K ) NEW_LINE DEDENT " V450,"import java . util . * ; class GFG { static int countPairs ( int a [ ] , int n ) { int mn = Integer . MAX_VALUE ; int mx = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { mn = Math . min ( mn , a [ i ] ) ; mx = Math . max ( mx , a [ i ] ) ; } int c1 = 0 ; int c2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == mn ) c1 ++ ; if ( a [ i ] == mx ) c2 ++ ; } if ( mn == mx ) return n * ( n - 1 ) / 2 ; else return c1 * c2 ; } public static void main ( String [ ] args ) { int a [ ] = { 3 , 2 , 1 , 1 , 3 } ; int n = a . length ; System . out . print ( countPairs ( a , n ) ) ; } } ","def countPairs ( a , n ) : NEW_LINE INDENT mn = + 2147483647 NEW_LINE mx = - 2147483648 NEW_LINE for i in range ( n ) : NEW_LINE INDENT mn = min ( mn , a [ i ] ) NEW_LINE mx = max ( mx , a [ i ] ) NEW_LINE DEDENT c1 = 0 NEW_LINE c2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] == mn ) : NEW_LINE INDENT c1 += 1 NEW_LINE DEDENT if ( a [ i ] == mx ) : NEW_LINE INDENT c2 += 1 NEW_LINE DEDENT DEDENT if ( mn == mx ) : NEW_LINE INDENT return n * ( n - 1 ) // 2 NEW_LINE DEDENT else : NEW_LINE INDENT return c1 * c2 NEW_LINE DEDENT DEDENT a = [ 3 , 2 , 1 , 1 , 3 ] NEW_LINE n = len ( a ) NEW_LINE print ( countPairs ( a , n ) ) NEW_LINE " V451,"class LPS { static int max ( int x , int y ) { return ( x > y ) ? x : y ; } static int lps ( String seq ) { int n = seq . length ( ) ; int i , j , cl ; int L [ ] [ ] = new int [ n ] [ n ] ; for ( i = 0 ; i < n ; i ++ ) L [ i ] [ i ] = 1 ; for ( cl = 2 ; cl <= n ; cl ++ ) { for ( i = 0 ; i < n - cl + 1 ; i ++ ) { j = i + cl - 1 ; if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ; else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ; else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ; } } return L [ 0 ] [ n - 1 ] ; } public static void main ( String args [ ] ) { String seq = "" GEEKSFORGEEKS "" ; int n = seq . length ( ) ; System . out . println ( "" The ▁ lnegth ▁ of ▁ the ▁ lps ▁ is ▁ "" + lps ( seq ) ) ; } } ","def lps ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT L [ i ] [ i ] = 1 NEW_LINE DEDENT for cl in range ( 2 , n + 1 ) : NEW_LINE INDENT for i in range ( n - cl + 1 ) : NEW_LINE INDENT j = i + cl - 1 NEW_LINE if str [ i ] == str [ j ] and cl == 2 : NEW_LINE INDENT L [ i ] [ j ] = 2 NEW_LINE DEDENT elif str [ i ] == str [ j ] : NEW_LINE INDENT L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 NEW_LINE DEDENT else : NEW_LINE INDENT L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ; NEW_LINE DEDENT DEDENT DEDENT return L [ 0 ] [ n - 1 ] NEW_LINE DEDENT seq = "" GEEKS ▁ FOR ▁ GEEKS "" NEW_LINE n = len ( seq ) NEW_LINE print ( "" The ▁ length ▁ of ▁ the ▁ LPS ▁ is ▁ "" + str ( lps ( seq ) ) ) NEW_LINE " V452,"class GFG { static int lenDoubleString ( String s ) { int l = s . length ( ) ; String first_half = s . substring ( 0 , l / 2 ) ; String second_half = "" "" ; if ( l % 2 == 0 ) second_half = s . substring ( l / 2 ) ; else second_half = s . substring ( l / 2 + 1 ) ; second_half = reverse ( second_half ) ; System . out . println ( first_half + second_half ) ; if ( l % 2 == 0 ) System . out . println ( l ) ; else System . out . println ( l - 1 ) ; return Integer . MIN_VALUE ; } static String reverse ( String input ) { char [ ] temparray = input . toCharArray ( ) ; int left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . valueOf ( temparray ) ; } public static void main ( String [ ] args ) { String n = "" abba "" ; lenDoubleString ( n ) ; n = "" abcdedcba "" ; lenDoubleString ( n ) ; } } ","def lenDoubleString ( s ) : NEW_LINE INDENT l = len ( s ) NEW_LINE first_half = s [ 0 : l // 2 ] NEW_LINE second_half = "" "" NEW_LINE if l % 2 == 0 : NEW_LINE INDENT second_half = s [ l // 2 : ] NEW_LINE DEDENT else : NEW_LINE INDENT second_half = s [ l // 2 + 1 : ] NEW_LINE DEDENT second_half = second_half [ : : - 1 ] NEW_LINE print ( first_half + second_half ) NEW_LINE if l % 2 == 0 : NEW_LINE INDENT print ( l ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( l - 1 ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = "" abba "" NEW_LINE lenDoubleString ( n ) NEW_LINE n = "" abcdedcba "" NEW_LINE lenDoubleString ( n ) NEW_LINE DEDENT " V453,"import java . io . * ; class GFG { static int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } static int ncr ( int n , int r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } public static void main ( String [ ] args ) { int m = 3 , n = 4 , k = 5 ; int totalTriangles = ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) ; System . out . println ( totalTriangles ) ; } } ","def factorial ( n ) : NEW_LINE INDENT fact = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT fact = fact * i NEW_LINE DEDENT return fact NEW_LINE DEDENT def ncr ( n , r ) : NEW_LINE INDENT return ( factorial ( n ) // ( factorial ( r ) * factorial ( n - r ) ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT m = 3 NEW_LINE n = 4 NEW_LINE k = 5 NEW_LINE totalTriangles = ( ncr ( m + n + k , 3 ) - ncr ( m , 3 ) - ncr ( n , 3 ) - ncr ( k , 3 ) ) NEW_LINE print ( totalTriangles ) NEW_LINE DEDENT " V454,"class GFG { static boolean isEven ( int n ) { if ( ( n ^ 1 ) == n + 1 ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 100 ; System . out . print ( isEven ( n ) == true ? "" Even "" : "" Odd "" ) ; } } ","def isEven ( n ) : NEW_LINE INDENT if ( n ^ 1 == n + 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 100 ; NEW_LINE print ( "" Even "" ) if isEven ( n ) else print ( "" Odd "" ) ; NEW_LINE DEDENT " V455,"class GFG { static void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; } static void generateArr ( int A [ ] , int n ) { int [ ] B = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; for ( int j = 0 ; j < i ; j ++ ) { if ( A [ j ] % A [ i ] == 0 ) cnt ++ ; } B [ i ] = cnt ; } printArr ( B , n ) ; } public static void main ( String args [ ] ) { int A [ ] = { 3 , 5 , 1 } ; int n = A . length ; generateArr ( A , n ) ; } } ","def printArr ( arr , n ) : NEW_LINE INDENT for i in arr : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT def generateArr ( A , n ) : NEW_LINE INDENT B = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if ( A [ j ] % A [ i ] == 0 ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT B [ i ] = cnt NEW_LINE DEDENT printArr ( B , n ) NEW_LINE DEDENT A = [ 3 , 5 , 1 ] NEW_LINE n = len ( A ) NEW_LINE generateArr ( A , n ) NEW_LINE " V456,"class GFG { static int minXOR ( int arr [ ] , int n ) { int min_xor = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ; return min_xor ; } public static void main ( String args [ ] ) { int arr [ ] = { 9 , 5 , 3 } ; int n = arr . length ; System . out . println ( minXOR ( arr , n ) ) ; } } ","def minXOR ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE min_xor = 999999 NEW_LINE val = 0 NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , n - 1 ) : NEW_LINE INDENT val = arr [ i ] ^ arr [ j ] NEW_LINE min_xor = min ( min_xor , val ) NEW_LINE DEDENT DEDENT return min_xor NEW_LINE DEDENT arr = [ 9 , 5 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minXOR ( arr , n ) ) NEW_LINE " V457,"class Test { static boolean isPowerOfTwo ( int x ) { return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ; } public static void main ( String [ ] args ) { System . out . println ( isPowerOfTwo ( 31 ) ? "" Yes "" : "" No "" ) ; System . out . println ( isPowerOfTwo ( 64 ) ? "" Yes "" : "" No "" ) ; } } ","def isPowerOfTwo ( x ) : NEW_LINE INDENT return ( x and ( not ( x & ( x - 1 ) ) ) ) NEW_LINE DEDENT if ( isPowerOfTwo ( 31 ) ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT if ( isPowerOfTwo ( 64 ) ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT " V458,"import java . io . * ; class GFG { static String areAllBitsSet ( int n ) { if ( n == 0 ) return "" No "" ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) return "" No "" ; n = n >> 1 ; } return "" Yes "" ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . println ( areAllBitsSet ( n ) ) ; } } ","def areAllBitsSet ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return "" No "" NEW_LINE DEDENT while ( n > 0 ) : NEW_LINE INDENT if ( ( n & 1 ) == 0 ) : NEW_LINE INDENT return "" No "" NEW_LINE DEDENT n = n >> 1 NEW_LINE DEDENT return "" Yes "" NEW_LINE DEDENT n = 7 NEW_LINE print ( areAllBitsSet ( n ) ) NEW_LINE " V459,"import java . io . * ; class GFG { static int findevenPair ( int [ ] A , int N ) { int i , j ; int evenPair = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] & A [ j ] ) % 2 == 0 ) evenPair ++ ; } } return evenPair ; } public static void main ( String [ ] args ) { int [ ] a = { 5 , 1 , 3 , 2 } ; int n = a . length ; System . out . println ( findevenPair ( a , n ) ) ; } } ","def findevenPair ( A , N ) : NEW_LINE INDENT evenPair = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( ( A [ i ] & A [ j ] ) % 2 == 0 ) : NEW_LINE INDENT evenPair += 1 NEW_LINE DEDENT DEDENT DEDENT return evenPair NEW_LINE DEDENT a = [ 5 , 1 , 3 , 2 ] NEW_LINE n = len ( a ) NEW_LINE print ( findevenPair ( a , n ) ) NEW_LINE " V460,"import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int countTriplets ( int n , Vector < pair > points ) { Set < pair > pts = new HashSet < pair > ( ) ; int ct = 0 ; for ( int i = 0 ; i < n ; i ++ ) pts . add ( points . get ( i ) ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { int x = points . get ( i ) . first + points . get ( j ) . first ; int y = points . get ( i ) . second + points . get ( j ) . second ; if ( x % 2 == 0 && y % 2 == 0 ) if ( ! pts . contains ( new pair ( x / 2 , y / 2 ) ) ) ct ++ ; } return ct ; } public static void main ( String args [ ] ) { Vector < pair > points = new Vector < > ( ) ; points . add ( new pair ( 1 , 1 ) ) ; points . add ( new pair ( 2 , 2 ) ) ; points . add ( new pair ( 3 , 3 ) ) ; int n = points . size ( ) ; System . out . println ( countTriplets ( n , points ) ) ; } } ","def countTriplets ( n , points ) : NEW_LINE INDENT pts = [ ] NEW_LINE ct = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT pts . append ( points [ i ] ) ; NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT x = points [ i ] [ 0 ] + points [ j ] [ 0 ] ; NEW_LINE y = points [ i ] [ 1 ] + points [ j ] [ 1 ] ; NEW_LINE if ( x % 2 == 0 and y % 2 == 0 ) : NEW_LINE INDENT if [ x // 2 , y // 2 ] in pts : NEW_LINE INDENT ct += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return ct NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT points = [ [ 1 , 1 ] , [ 2 , 2 ] , [ 3 , 3 ] ] NEW_LINE n = len ( points ) NEW_LINE print ( countTriplets ( n , points ) ) NEW_LINE DEDENT " V461,"import java . util . * ; class Main { static void printTwoOdd ( int arr [ ] , int size ) { int xor2 = arr [ 0 ] ; int set_bit_no ; int i ; int n = size - 2 ; int x = 0 , y = 0 ; for ( i = 1 ; i < size ; i ++ ) xor2 = xor2 ^ arr [ i ] ; set_bit_no = xor2 & ~ ( xor2 - 1 ) ; for ( i = 0 ; i < size ; i ++ ) { if ( ( arr [ i ] & set_bit_no ) > 0 ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } System . out . println ( "" The ▁ two ▁ ODD ▁ elements ▁ are ▁ "" + x + "" ▁ & ▁ "" + y ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 4 , 5 , 2 , 3 , 3 , 1 } ; int arr_size = arr . length ; printTwoOdd ( arr , arr_size ) ; } } ","def printTwoOdd ( arr , size ) : NEW_LINE INDENT xor2 = arr [ 0 ] NEW_LINE set_bit_no = 0 NEW_LINE n = size - 2 NEW_LINE x , y = 0 , 0 NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT xor2 = xor2 ^ arr [ i ] NEW_LINE DEDENT set_bit_no = xor2 & ~ ( xor2 - 1 ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT if ( arr [ i ] & set_bit_no ) : NEW_LINE INDENT x = x ^ arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT y = y ^ arr [ i ] NEW_LINE DEDENT DEDENT print ( "" The ▁ two ▁ ODD ▁ elements ▁ are "" , x , "" & "" , y ) NEW_LINE DEDENT arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 3 , 1 ] NEW_LINE arr_size = len ( arr ) NEW_LINE printTwoOdd ( arr , arr_size ) NEW_LINE " V462,"import java . io . * ; class GFG { static double trianglearea ( double a ) { if ( a < 0 ) return - 1 ; double area = ( 3 * Math . sqrt ( 3 ) * Math . pow ( a , 2 ) ) / 4 ; return area ; } public static void main ( String [ ] args ) { double a = 6 ; System . out . println ( trianglearea ( a ) ) ; } } ","import math NEW_LINE def trianglearea ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT area = ( 3 * math . sqrt ( 3 ) * math . pow ( a , 2 ) ) / 4 ; NEW_LINE return area ; NEW_LINE DEDENT a = 6 ; NEW_LINE print ( trianglearea ( a ) ) NEW_LINE " V463,"import java . util . * ; class GFG { static int calculate ( int a [ ] , int n ) { Arrays . sort ( a ) ; int count = 1 ; int answer = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] == a [ i - 1 ] ) { count += 1 ; } else { answer = answer + ( count * ( count - 1 ) ) / 2 ; count = 1 ; } } answer = answer + ( count * ( count - 1 ) ) / 2 ; return answer ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 1 , 2 , 4 } ; int n = a . length ; System . out . println ( calculate ( a , n ) ) ; } } ","def calculate ( a ) : NEW_LINE INDENT a . sort ( ) NEW_LINE count = 1 NEW_LINE answer = 0 NEW_LINE for i in range ( 1 , len ( a ) ) : NEW_LINE INDENT if a [ i ] == a [ i - 1 ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT answer = answer + count * ( count - 1 ) // 2 NEW_LINE count = 1 NEW_LINE DEDENT DEDENT answer = answer + count * ( count - 1 ) // 2 NEW_LINE return answer NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 1 , 2 , 1 , 2 , 4 ] NEW_LINE print ( calculate ( a ) ) NEW_LINE DEDENT " V464,"import java . io . * ; class GFG { static int countPrimeFactors ( int n ) { int count = 0 ; while ( n % 2 == 0 ) { n = n / 2 ; count ++ ; } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { n = n / i ; count ++ ; } } if ( n > 2 ) count ++ ; return ( count ) ; } static void printKAlmostPrimes ( int k , int n ) { for ( int i = 1 , num = 2 ; i <= n ; num ++ ) { if ( countPrimeFactors ( num ) == k ) { System . out . print ( num + "" ▁ "" ) ; i ++ ; } } return ; } public static void main ( String [ ] args ) { int n = 10 , k = 2 ; System . out . println ( "" First ▁ "" + n + "" ▁ "" + k + "" - almost ▁ prime ▁ numbers ▁ : ▁ "" ) ; printKAlmostPrimes ( k , n ) ; } } ","import math NEW_LINE def countPrimeFactors ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n = n / 2 ; NEW_LINE count += 1 ; NEW_LINE DEDENT i = 3 ; NEW_LINE while ( i <= math . sqrt ( n ) ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT n = n / i ; NEW_LINE count += 1 ; NEW_LINE DEDENT i = i + 2 ; NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT return ( count ) ; NEW_LINE DEDENT def printKAlmostPrimes ( k , n ) : NEW_LINE INDENT i = 1 ; NEW_LINE num = 2 NEW_LINE while ( i <= n ) : NEW_LINE INDENT if ( countPrimeFactors ( num ) == k ) : NEW_LINE INDENT print ( num , end = "" "" ) ; NEW_LINE print ( "" ▁ "" , end = "" "" ) ; NEW_LINE i += 1 ; NEW_LINE DEDENT num += 1 ; NEW_LINE DEDENT return ; NEW_LINE DEDENT n = 10 ; NEW_LINE k = 2 ; NEW_LINE print ( "" First ▁ n ▁ k - almost ▁ prime ▁ numbers : "" ) ; NEW_LINE printKAlmostPrimes ( k , n ) ; NEW_LINE " V465,"class GFG { static int LAS [ ] [ ] = new int [ 1000 ] [ 2 ] ; static int solve ( int arr [ ] , int n , int i , int pos ) { if ( i == n ) return 0 ; if ( LAS [ i ] [ pos ] == 1 ) return LAS [ i ] [ pos ] ; int inc = 0 , exc = 0 ; if ( arr [ i ] > 0 && pos == 1 ) { pos = 0 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } else if ( arr [ i ] < 0 && pos == 0 ) { pos = 1 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } exc = solve ( arr , n , i + 1 , pos ) ; LAS [ i ] [ pos ] = Math . max ( inc , exc ) ; return LAS [ i ] [ pos ] ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , 3 , 4 , 5 , - 6 , 8 , - 99 } ; int n = arr . length ; System . out . println ( Math . max ( solve ( arr , n , 0 , 0 ) , solve ( arr , n , 0 , 1 ) ) ) ; } } ","import numpy as np NEW_LINE LAS = np . zeros ( ( 1000 , 2 ) ) NEW_LINE for i in range ( 1000 ) : NEW_LINE INDENT for j in range ( 2 ) : NEW_LINE INDENT LAS [ i ] [ j ] = False NEW_LINE DEDENT DEDENT def solve ( arr , n , i , pos ) : NEW_LINE INDENT if ( i == n ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( LAS [ i ] [ pos ] ) : NEW_LINE INDENT return LAS [ i ] [ pos ] ; NEW_LINE DEDENT inc = 0 ; exc = 0 ; NEW_LINE if ( arr [ i ] > 0 and pos == True ) : NEW_LINE INDENT pos = False ; NEW_LINE inc = 1 + solve ( arr , n , i + 1 , pos ) ; NEW_LINE DEDENT elif ( arr [ i ] < 0 and pos == False ) : NEW_LINE INDENT pos = True ; NEW_LINE inc = 1 + solve ( arr , n , i + 1 , pos ) ; NEW_LINE DEDENT exc = solve ( arr , n , i + 1 , pos ) ; NEW_LINE LAS [ i ] [ pos ] = max ( inc , exc ) ; NEW_LINE return LAS [ i ] [ pos ] ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ - 1 , 2 , 3 , 4 , 5 , - 6 , 8 , - 99 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( max ( solve ( arr , n , 0 , 0 ) , solve ( arr , n , 0 , 1 ) ) ) ; NEW_LINE DEDENT " V466,"import java . util . * ; class GFG { static void expressDigit ( int arr [ ] , int n ) { int min = 9 , index = 0 , temp = 0 ; temp = arr [ 0 ] ; for ( int i = 1 ; i < 10 ; i ++ ) { if ( arr [ i ] < min ) { min = arr [ i ] ; index = i ; } } if ( temp < min ) { System . out . print ( 1 ) ; for ( int i = 1 ; i <= temp + 1 ; i ++ ) System . out . print ( 0 ) ; } else { for ( int i = 0 ; i < min ; i ++ ) System . out . print ( index ) ; System . out . print ( index ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 2 , 1 , 1 , 3 , 1 , 1 , 1 } ; int N = 10 ; expressDigit ( arr , N ) ; } } ","def expressDigit ( arr , n ) : NEW_LINE INDENT min = 9 NEW_LINE index = 0 NEW_LINE temp = 0 NEW_LINE temp = arr [ 0 ] NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT if ( arr [ i ] < min ) : NEW_LINE INDENT min = arr [ i ] NEW_LINE index = i NEW_LINE DEDENT DEDENT if ( temp < min ) : NEW_LINE INDENT print ( 1 , end = "" "" ) NEW_LINE for i in range ( 1 , temp + 1 ) : NEW_LINE INDENT print ( 0 , end = "" "" ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( min ) : NEW_LINE INDENT print ( index , end = "" "" ) NEW_LINE DEDENT print ( index ) NEW_LINE DEDENT DEDENT arr = [ 2 , 2 , 1 , 2 , 1 , 1 , 3 , 1 , 1 , 1 ] NEW_LINE N = 10 NEW_LINE expressDigit ( arr , N ) NEW_LINE " V467,"import java . util . Arrays ; class GFG { static int maxProduct ( int arr [ ] , int n ) { if ( n < 3 ) { return - 1 ; } Arrays . sort ( arr ) ; return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 10 , - 3 , 5 , 6 , - 20 } ; int n = arr . length ; int max = maxProduct ( arr , n ) ; if ( max == - 1 ) { System . out . println ( "" No ▁ Triplet ▁ Exists "" ) ; } else { System . out . println ( "" Maximum ▁ product ▁ is ▁ "" + max ) ; } } } ","def maxProduct ( arr , n ) : NEW_LINE INDENT if n < 3 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT arr . sort ( ) NEW_LINE return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ - 10 , - 3 , 5 , 6 , - 20 ] NEW_LINE n = len ( arr ) NEW_LINE _max = maxProduct ( arr , n ) NEW_LINE if _max == - 1 : NEW_LINE INDENT print ( "" No ▁ Triplet ▁ Exists "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Maximum ▁ product ▁ is "" , _max ) NEW_LINE DEDENT DEDENT " V468,"import java . io . * ; class GFG { static int R = 4 ; static int C = 4 ; static int getTotalCoverageOfMatrix ( int [ ] [ ] mat ) { int res = 0 ; for ( int i = 0 ; i < R ; i ++ ) { boolean isOne = false ; for ( int j = 0 ; j < C ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } isOne = false ; for ( int j = C - 1 ; j >= 0 ; j -- ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } } for ( int j = 0 ; j < C ; j ++ ) { boolean isOne = false ; for ( int i = 0 ; i < R ; i ++ ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } isOne = false ; for ( int i = R - 1 ; i >= 0 ; i -- ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } } return res ; } static public void main ( String [ ] args ) { int [ ] [ ] mat = { { 0 , 0 , 0 , 0 } , { 1 , 0 , 0 , 1 } , { 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 } } ; System . out . println ( getTotalCoverageOfMatrix ( mat ) ) ; } } ","R = 4 NEW_LINE C = 4 NEW_LINE def getTotalCoverageOfMatrix ( mat ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( R ) : NEW_LINE INDENT isOne = False NEW_LINE for j in range ( C ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT isOne = True NEW_LINE DEDENT elif ( isOne ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT isOne = False NEW_LINE for j in range ( C - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT isOne = True NEW_LINE DEDENT elif ( isOne ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT for j in range ( C ) : NEW_LINE INDENT isOne = False NEW_LINE for i in range ( R ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT isOne = True NEW_LINE DEDENT elif ( isOne ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT isOne = False NEW_LINE for i in range ( R - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT isOne = True NEW_LINE DEDENT elif ( isOne ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT return res NEW_LINE DEDENT mat = [ [ 0 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 ] ] NEW_LINE print ( getTotalCoverageOfMatrix ( mat ) ) NEW_LINE " V469,"import java . util . Arrays ; class GfG { static boolean isPalindrome ( String str , int i , int j ) { while ( i < j ) { if ( str . charAt ( i ) != str . charAt ( j ) ) return false ; i ++ ; j -- ; } return true ; } static int countPrimePalindrome ( String str , int len ) { boolean [ ] prime = new boolean [ len + 1 ] ; Arrays . fill ( prime , true ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p <= len ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * p ; i <= len ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int j = 2 ; j <= len ; j ++ ) { if ( prime [ j ] ) { for ( int i = 0 ; i + j - 1 < len ; i ++ ) { if ( isPalindrome ( str , i , i + j - 1 ) ) count ++ ; } } } return count ; } public static void main ( String [ ] args ) { String s = "" geeksforgeeks "" ; int len = s . length ( ) ; System . out . println ( countPrimePalindrome ( s , len ) ) ; } } ","import math as mt NEW_LINE def isPalindrome ( str1 , i , j ) : NEW_LINE INDENT while ( i < j ) : NEW_LINE INDENT if ( str1 [ i ] != str1 [ j ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def countPrimePalindrome ( str1 , Len ) : NEW_LINE INDENT prime = [ True for i in range ( Len + 1 ) ] NEW_LINE prime [ 0 ] , prime [ 1 ] = False , False NEW_LINE for p in range ( 2 , mt . ceil ( mt . sqrt ( Len + 1 ) ) ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( 2 * p , Len + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT count = 0 NEW_LINE for j in range ( 2 , Len + 1 ) : NEW_LINE INDENT if ( prime [ j ] ) : NEW_LINE INDENT for i in range ( Len + 1 - j ) : NEW_LINE INDENT if ( isPalindrome ( str1 , i , i + j - 1 ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return count NEW_LINE DEDENT s = "" geeksforgeeks "" NEW_LINE Len = len ( s ) NEW_LINE print ( countPrimePalindrome ( s , Len ) ) NEW_LINE " V470,"import java . io . * ; class GFG { static int MAX = 100001 ; static int [ ] isPrime = new int [ MAX ] ; static int sieve ( ) { for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( isPrime [ p ] == 0 ) { for ( int i = p * 2 ; i < MAX ; i += p ) isPrime [ i ] = 1 ; } } return - 1 ; } static int findSubset ( int [ ] a , int n ) { int cnt1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] == 1 ) cnt1 ++ ; if ( cnt1 > 0 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] != 1 ) && ( isPrime [ a [ i ] + 1 ] == 0 ) ) { System . out . println ( cnt1 + 1 ) ; for ( int j = 0 ; j < cnt1 ; j ++ ) System . out . print ( 1 + "" ▁ "" ) ; System . out . println ( a [ i ] ) ; return 0 ; } } } if ( cnt1 >= 2 ) { System . out . println ( cnt1 ) ; for ( int i = 0 ; i < cnt1 ; i ++ ) System . out . print ( 1 + "" ▁ "" ) ; System . out . println ( ) ; return 0 ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ a [ i ] + a [ j ] ] == 0 ) { System . out . println ( 2 ) ; System . out . println ( a [ i ] + "" ▁ "" + a [ j ] ) ; return 0 ; } } } System . out . println ( - 1 ) ; return - 1 ; } public static void main ( String args [ ] ) { sieve ( ) ; int [ ] A = new int [ ] { 2 , 1 , 1 } ; int n = A . length ; findSubset ( A , n ) ; } } ","import math as mt NEW_LINE MAX = 100001 NEW_LINE isPrime = [ 0 for i in range ( MAX ) ] NEW_LINE def sieve ( ) : NEW_LINE INDENT for p in range ( 2 , mt . ceil ( mt . sqrt ( MAX ) ) ) : NEW_LINE INDENT if ( isPrime [ p ] == 0 ) : NEW_LINE INDENT for i in range ( 2 * p , MAX , p ) : NEW_LINE INDENT isPrime [ i ] = 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT def findSubset ( a , n ) : NEW_LINE INDENT cnt1 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] == 1 ) : NEW_LINE INDENT cnt1 += 1 NEW_LINE DEDENT DEDENT if ( cnt1 > 0 ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( ( a [ i ] != 1 ) and ( isPrime [ a [ i ] + 1 ] == 0 ) ) : NEW_LINE INDENT print ( cnt1 + 1 ) NEW_LINE for j in range ( cnt1 ) : NEW_LINE INDENT print ( ""1"" , end = "" ▁ "" ) NEW_LINE DEDENT print ( a [ i ] ) NEW_LINE return 0 NEW_LINE DEDENT DEDENT DEDENT if ( cnt1 >= 2 ) : NEW_LINE INDENT print ( cnt1 ) NEW_LINE for i in range ( cnt1 ) : NEW_LINE INDENT print ( ""1"" , end = "" ▁ "" ) NEW_LINE DEDENT print ( "" \n "" ) NEW_LINE return 0 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( isPrime [ a [ i ] + a [ j ] ] == 0 ) : NEW_LINE INDENT print ( 2 ) NEW_LINE print ( a [ i ] , "" ▁ "" , a [ j ] ) NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT sieve ( ) NEW_LINE A = [ 2 , 1 , 1 ] NEW_LINE n = len ( A ) NEW_LINE findSubset ( A , n ) NEW_LINE " V471,"class GFG { static int minMoves ( int n ) { String s = Integer . toString ( n ) ; int ans = Integer . MAX_VALUE ; int len = s . length ( ) ; for ( int i = 0 ; i < len ; ++ i ) { for ( int j = 0 ; j < len ; ++ j ) { if ( i == j ) continue ; char t [ ] = s . toCharArray ( ) ; int cur = 0 ; for ( int k = i ; k < len - 1 ; ++ k ) { swap ( t , k , k + 1 ) ; ++ cur ; } for ( int k = j - ( ( j > i ) ? 1 : 0 ) ; k < len - 2 ; ++ k ) { swap ( t , k , k + 1 ) ; ++ cur ; } int pos = - 1 ; for ( int k = 0 ; k < len ; ++ k ) { if ( t [ k ] != '0' ) { pos = k ; break ; } } for ( int k = pos ; k > 0 ; -- k ) { swap ( t , k , k - 1 ) ; ++ cur ; } long nn = Integer . parseInt ( String . valueOf ( t ) ) ; if ( nn % 25 == 0 ) ans = Math . min ( ans , cur ) ; } } if ( ans == Integer . MAX_VALUE ) return - 1 ; return ans ; } static void swap ( char t [ ] , int i , int j ) { char temp = t [ i ] ; t [ i ] = t [ j ] ; t [ j ] = temp ; } public static void main ( String [ ] args ) { int n = 509201 ; System . out . println ( minMoves ( n ) ) ; } } ","import sys NEW_LINE def minMoves ( n ) : NEW_LINE INDENT s = str ( n ) ; NEW_LINE ans = sys . maxsize ; NEW_LINE len1 = len ( s ) ; NEW_LINE for i in range ( len1 ) : NEW_LINE INDENT for j in range ( len1 ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT t = s ; NEW_LINE cur = 0 ; NEW_LINE list1 = list ( t ) ; NEW_LINE for k in range ( i , len1 - 1 ) : NEW_LINE INDENT e = list1 [ k ] ; NEW_LINE list1 [ k ] = list1 [ k + 1 ] ; NEW_LINE list1 [ k + 1 ] = e ; NEW_LINE cur += 1 ; NEW_LINE DEDENT t = ' ' . join ( list1 ) ; NEW_LINE list1 = list ( t ) ; NEW_LINE for k in range ( j - ( j > i ) , len1 - 2 ) : NEW_LINE INDENT e = list1 [ k ] ; NEW_LINE list1 [ k ] = list1 [ k + 1 ] ; NEW_LINE list1 [ k + 1 ] = e ; NEW_LINE cur += 1 ; NEW_LINE DEDENT t = ' ' . join ( list1 ) ; NEW_LINE pos = - 1 ; NEW_LINE for k in range ( len1 ) : NEW_LINE INDENT if ( t [ k ] != '0' ) : NEW_LINE INDENT pos = k ; NEW_LINE break ; NEW_LINE DEDENT DEDENT for k in range ( pos , 0 , - 1 ) : NEW_LINE INDENT e = list1 [ k ] ; NEW_LINE list1 [ k ] = list1 [ k + 1 ] ; NEW_LINE list1 [ k + 1 ] = e ; NEW_LINE cur += 1 ; NEW_LINE DEDENT t = ' ' . join ( list1 ) ; NEW_LINE nn = int ( t ) ; NEW_LINE if ( nn % 25 == 0 ) : NEW_LINE INDENT ans = min ( ans , cur ) ; NEW_LINE DEDENT DEDENT DEDENT if ( ans == sys . maxsize ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT n = 509201 ; NEW_LINE print ( minMoves ( n ) ) ; NEW_LINE " V472,"import java . io . * ; class GFG { static double findSum ( long n ) { return Math . sqrt ( 3 ) * ( n * ( n + 1 ) / 2 ) ; } public static void main ( String [ ] args ) { long n = 10 ; System . out . println ( findSum ( n ) ) ; } } ","import math NEW_LINE def findSum ( n ) : NEW_LINE INDENT return math . sqrt ( 3 ) * ( n * ( n + 1 ) / 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 NEW_LINE print ( findSum ( n ) ) NEW_LINE DEDENT " V473,"import java . io . * ; class GFG { static int merge ( int arr [ ] , int temp [ ] , int left , int mid , int right ) { int inv_count = 0 ; int i = left ; int j = mid ; int k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] <= arr [ j ] ) temp [ k ++ ] = arr [ i ++ ] ; else { temp [ k ++ ] = arr [ j ++ ] ; inv_count = inv_count + ( mid - i ) ; } } while ( i <= mid - 1 ) temp [ k ++ ] = arr [ i ++ ] ; while ( j <= right ) temp [ k ++ ] = arr [ j ++ ] ; for ( i = left ; i <= right ; i ++ ) arr [ i ] = temp [ i ] ; return inv_count ; } static int _mergeSort ( int arr [ ] , int temp [ ] , int left , int right ) { int mid , inv_count = 0 ; if ( right > left ) { mid = ( right + left ) / 2 ; inv_count = _mergeSort ( arr , temp , left , mid ) ; inv_count += _mergeSort ( arr , temp , mid + 1 , right ) ; inv_count += merge ( arr , temp , left , mid + 1 , right ) ; } return inv_count ; } static int countSwaps ( int arr [ ] , int n ) { int temp [ ] = new int [ n ] ; return _mergeSort ( arr , temp , 0 , n - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 20 , 6 , 4 , 5 } ; int n = arr . length ; System . out . println ( "" Number ▁ of ▁ swaps ▁ is ▁ "" + countSwaps ( arr , n ) ) ; } } ","def merge ( arr , temp , left , mid , right ) : NEW_LINE INDENT inv_count = 0 NEW_LINE i = left NEW_LINE j = mid NEW_LINE k = left NEW_LINE while ( ( i <= mid - 1 ) and ( j <= right ) ) : NEW_LINE INDENT if ( arr [ i ] <= arr [ j ] ) : NEW_LINE INDENT temp [ k ] = arr [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT temp [ k ] = arr [ j ] NEW_LINE k += 1 NEW_LINE j += 1 NEW_LINE inv_count = inv_count + ( mid - i ) NEW_LINE DEDENT DEDENT while ( i <= mid - 1 ) : NEW_LINE INDENT temp [ k ] = arr [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT while ( j <= right ) : NEW_LINE INDENT temp [ k ] = arr [ j ] NEW_LINE k += 1 NEW_LINE j += 1 NEW_LINE DEDENT for i in range ( left , right + 1 , 1 ) : NEW_LINE INDENT arr [ i ] = temp [ i ] NEW_LINE DEDENT return inv_count NEW_LINE DEDENT def _mergeSort ( arr , temp , left , right ) : NEW_LINE INDENT inv_count = 0 NEW_LINE if ( right > left ) : NEW_LINE INDENT mid = int ( ( right + left ) / 2 ) NEW_LINE inv_count = _mergeSort ( arr , temp , left , mid ) NEW_LINE inv_count += _mergeSort ( arr , temp , mid + 1 , right ) NEW_LINE inv_count += merge ( arr , temp , left , mid + 1 , right ) NEW_LINE DEDENT return inv_count NEW_LINE DEDENT def countSwaps ( arr , n ) : NEW_LINE INDENT temp = [ 0 for i in range ( n ) ] NEW_LINE return _mergeSort ( arr , temp , 0 , n - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 20 , 6 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( "" Number ▁ of ▁ swaps ▁ is "" , countSwaps ( arr , n ) ) NEW_LINE DEDENT " V474,"import java . util . * ; class GFG { static int n ; static int solve ( int i , int x , int dp [ ] [ ] ) { if ( i < 0 ) { return x == 3 ? 1 : 0 ; } if ( dp [ i ] [ x ] != - 1 ) { return dp [ i ] [ x ] ; } dp [ i ] [ x ] = solve ( i - 1 , 0 , dp ) ; dp [ i ] [ x ] += solve ( i - 1 , x + 1 , dp ) ; return dp [ i ] [ x ] ; } public static void main ( String [ ] args ) { n = 4 ; int dp [ ] [ ] = new int [ n ] [ 4 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 4 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( int i = 0 ; i < n ; i ++ ) { dp [ i ] [ 3 ] = ( 1 << ( i + 1 ) ) ; } System . out . print ( solve ( n - 1 , 0 , dp ) ) ; } } ","def solve ( i , x , dp ) : NEW_LINE INDENT if ( i < 0 ) : NEW_LINE INDENT return x == 3 NEW_LINE DEDENT if ( dp [ i ] [ x ] != - 1 ) : NEW_LINE INDENT return dp [ i ] [ x ] NEW_LINE DEDENT dp [ i ] [ x ] = solve ( i - 1 , 0 , dp ) NEW_LINE dp [ i ] [ x ] += solve ( i - 1 , x + 1 , dp ) NEW_LINE return dp [ i ] [ x ] NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 4 ; NEW_LINE dp = [ [ 0 for i in range ( n ) ] for j in range ( 4 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( 4 ) : NEW_LINE INDENT dp [ i ] [ j ] = - 1 NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT dp [ i ] [ 3 ] = ( 1 << ( i + 1 ) ) NEW_LINE DEDENT print ( solve ( n - 1 , 0 , dp ) ) NEW_LINE DEDENT " V475,"class GFG { static int minCost ( int [ ] cost , int n ) { int totalCost = 0 ; int boardingBus = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( cost [ boardingBus ] > cost [ i ] ) { totalCost += ( ( i - boardingBus ) * cost [ boardingBus ] ) ; boardingBus = i ; } } totalCost += ( ( n - boardingBus ) * cost [ boardingBus ] ) ; return totalCost ; } public static void main ( String [ ] args ) { int [ ] cost = { 4 , 7 , 8 , 3 , 4 } ; int n = cost . length ; System . out . print ( minCost ( cost , n ) ) ; } } ","def minCost ( cost , n ) : NEW_LINE INDENT totalCost = 0 NEW_LINE boardingBus = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( cost [ boardingBus ] > cost [ i ] ) : NEW_LINE INDENT totalCost += ( ( i - boardingBus ) * cost [ boardingBus ] ) NEW_LINE boardingBus = i NEW_LINE DEDENT DEDENT totalCost += ( ( n - boardingBus ) * cost [ boardingBus ] ) NEW_LINE return totalCost NEW_LINE DEDENT cost = [ 4 , 7 , 8 , 3 , 4 ] NEW_LINE n = len ( cost ) NEW_LINE print ( minCost ( cost , n ) ) NEW_LINE " V476,"import java . util . * ; class GFG { static int countSquares ( int m , int n ) { if ( n < m ) { int temp = m ; m = n ; n = temp ; } return n * ( n + 1 ) * ( 3 * m - n + 1 ) / 6 ; } public static void main ( String [ ] args ) { int m = 4 ; int n = 3 ; System . out . print ( "" Count ▁ of ▁ squares ▁ is ▁ "" + countSquares ( m , n ) ) ; } } ","def countSquares ( m , n ) : NEW_LINE INDENT if ( n < m ) : NEW_LINE INDENT temp = m NEW_LINE m = n NEW_LINE n = temp NEW_LINE DEDENT return n * ( n + 1 ) * ( 3 * m - n + 1 ) // 6 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT m = 4 NEW_LINE n = 3 NEW_LINE print ( "" Count ▁ of ▁ squares ▁ is "" , countSquares ( m , n ) ) NEW_LINE DEDENT " V477,"import java . util . * ; class GfG { static int N = 100005 ; static int MAX = 10000002 ; static int lpd [ ] = new int [ MAX ] ; static void preCompute ( ) { lpd [ 0 ] = lpd [ 1 ] = 1 ; for ( int i = 2 ; i * i < MAX ; i ++ ) { for ( int j = i * 2 ; j < MAX ; j += i ) { if ( lpd [ j ] == 0 ) { lpd [ j ] = i ; } } } for ( int i = 2 ; i < MAX ; i ++ ) { if ( lpd [ i ] == 0 ) { lpd [ i ] = i ; } } } static int maxLengthSubsequence ( int arr [ ] , int n ) { int dp [ ] = new int [ N ] ; Map < Integer , Integer > pos = new HashMap < Integer , Integer > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { while ( arr [ i ] > 1 ) { int p = lpd [ arr [ i ] ] ; if ( pos . containsKey ( p ) ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ pos . get ( p ) ] ) ; } pos . put ( p , i ) ; while ( arr [ i ] % p == 0 ) arr [ i ] /= p ; } } int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 13 , 2 , 8 , 6 , 3 , 1 , 9 } ; int n = arr . length - 1 ; preCompute ( ) ; System . out . println ( maxLengthSubsequence ( arr , n ) ) ; } } ","import math as mt NEW_LINE N = 100005 NEW_LINE MAX = 1000002 NEW_LINE lpd = [ 0 for i in range ( MAX ) ] NEW_LINE def preCompute ( ) : NEW_LINE INDENT lpd [ 0 ] , lpd [ 1 ] = 1 , 1 NEW_LINE for i in range ( 2 , mt . ceil ( mt . sqrt ( MAX ) ) ) : NEW_LINE INDENT for j in range ( 2 * i , MAX , i ) : NEW_LINE INDENT if ( lpd [ j ] == 0 ) : NEW_LINE INDENT lpd [ j ] = i NEW_LINE DEDENT DEDENT DEDENT for i in range ( 2 , MAX ) : NEW_LINE INDENT if ( lpd [ i ] == 0 ) : NEW_LINE INDENT lpd [ i ] = i NEW_LINE DEDENT DEDENT DEDENT def maxLengthSubsequence ( arr , n ) : NEW_LINE INDENT dp = [ 1 for i in range ( N + 1 ) ] NEW_LINE pos = dict ( ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT while ( arr [ i ] > 1 ) : NEW_LINE INDENT p = lpd [ arr [ i ] ] NEW_LINE if ( p in pos . keys ( ) ) : NEW_LINE INDENT dp [ i ] = max ( dp [ i ] , 1 + dp [ pos [ p ] ] ) NEW_LINE DEDENT pos [ p ] = i NEW_LINE while ( arr [ i ] % p == 0 ) : NEW_LINE INDENT arr [ i ] //= p NEW_LINE DEDENT DEDENT DEDENT ans = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans = max ( ans , dp [ i ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 13 , 2 , 8 , 6 , 3 , 1 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE preCompute ( ) NEW_LINE print ( maxLengthSubsequence ( arr , n ) ) NEW_LINE " V478,"import java . io . * ; class GFG { static void Swap ( int [ ] array , int position1 , int position2 ) { int temp = array [ position1 ] ; array [ position1 ] = array [ position2 ] ; array [ position2 ] = temp ; } static int partition ( int [ ] arr , int low , int high ) { int pivot = arr [ high ] ; int i = ( low - 1 ) ; for ( int j = low ; j <= high - 1 ; j ++ ) { if ( arr [ j ] <= pivot ) { i ++ ; Swap ( arr , i , j ) ; } } Swap ( arr , i + 1 , high ) ; return ( i + 1 ) ; } static void quickSort ( int [ ] arr , int low , int high ) { if ( low < high ) { int pi = partition ( arr , low , high ) ; quickSort ( arr , low , pi - 1 ) ; quickSort ( arr , pi + 1 , high ) ; } } static void printArray ( int [ ] arr , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) System . out . print ( "" ▁ "" + arr [ i ] ) ; System . out . println ( ) ; } static public void main ( String [ ] args ) { int [ ] arr = { 10 , 7 , 8 , 9 , 1 , 5 } ; int n = arr . length ; quickSort ( arr , 0 , n - 1 ) ; System . out . println ( "" Sorted ▁ array : ▁ "" ) ; printArray ( arr , n ) ; } } ","def partition ( arr , low , high ) : NEW_LINE INDENT pivot = arr [ high ] NEW_LINE i = ( low - 1 ) NEW_LINE for j in range ( low , high ) : NEW_LINE INDENT if ( arr [ j ] <= pivot ) : NEW_LINE INDENT i += 1 NEW_LINE arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE DEDENT DEDENT arr [ i + 1 ] , arr [ high ] = arr [ high ] , arr [ i + 1 ] NEW_LINE return ( i + 1 ) NEW_LINE DEDENT def quickSort ( arr , low , high ) : NEW_LINE INDENT if ( low < high ) : NEW_LINE INDENT pi = partition ( arr , low , high ) NEW_LINE quickSort ( arr , low , pi - 1 ) NEW_LINE quickSort ( arr , pi + 1 , high ) NEW_LINE DEDENT DEDENT def printArray ( arr , size ) : NEW_LINE INDENT for i in range ( size ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT arr = [ 10 , 7 , 8 , 9 , 1 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE quickSort ( arr , 0 , n - 1 ) NEW_LINE print ( "" Sorted ▁ array : "" ) NEW_LINE printArray ( arr , n ) NEW_LINE " V479,"import java . util . * ; import java . lang . * ; class GFG { public static int gcdExtended ( int a , int b , int x , int y ) { if ( a == 0 ) { x = 0 ; y = 1 ; return b ; } int x1 = 1 , y1 = 1 ; int gcd = gcdExtended ( b % a , a , x1 , y1 ) ; x = y1 - ( b / a ) * x1 ; y = x1 ; return gcd ; } public static void main ( String [ ] args ) { int x = 1 , y = 1 ; int a = 35 , b = 15 ; int g = gcdExtended ( a , b , x , y ) ; System . out . print ( "" gcd ( "" + a + "" ▁ , ▁ "" + b + "" ) ▁ = ▁ "" + g ) ; } } ","def gcdExtended ( a , b ) : NEW_LINE INDENT if a == 0 : NEW_LINE INDENT return b , 0 , 1 NEW_LINE DEDENT gcd , x1 , y1 = gcdExtended ( b % a , a ) NEW_LINE x = y1 - ( b // a ) * x1 NEW_LINE y = x1 NEW_LINE return gcd , x , y NEW_LINE DEDENT a , b = 35 , 15 NEW_LINE g , x , y = gcdExtended ( a , b ) NEW_LINE print ( "" gcd ( "" , a , "" , "" , b , "" ) ▁ = ▁ "" , g ) NEW_LINE " V480,"public class Test { public static int floorSqrt ( int x ) { if ( x == 0 || x == 1 ) return x ; int start = 1 , end = x , ans = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( mid * mid == x ) return mid ; if ( mid * mid < x ) { start = mid + 1 ; ans = mid ; } else end = mid - 1 ; } return ans ; } public static void main ( String args [ ] ) { int x = 11 ; System . out . println ( floorSqrt ( x ) ) ; } } ","def floorSqrt ( x ) : NEW_LINE INDENT if ( x == 0 or x == 1 ) : NEW_LINE INDENT return x NEW_LINE DEDENT start = 1 NEW_LINE end = x NEW_LINE while ( start <= end ) : NEW_LINE INDENT mid = ( start + end ) // 2 NEW_LINE if ( mid * mid == x ) : NEW_LINE INDENT return mid NEW_LINE DEDENT if ( mid * mid < x ) : NEW_LINE INDENT start = mid + 1 NEW_LINE ans = mid NEW_LINE DEDENT else : NEW_LINE INDENT end = mid - 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT x = 11 NEW_LINE print ( floorSqrt ( x ) ) NEW_LINE " V481,"import java . util . * ; class GFG { static void shortestDistance ( String S , char X ) { int prev = Integer . MAX_VALUE ; Vector < Integer > ans = new Vector < > ( ) ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == X ) prev = i ; ans . add ( i - prev ) ; } prev = Integer . MAX_VALUE ; for ( int i = S . length ( ) - 1 ; i >= 0 ; i -- ) { if ( S . charAt ( i ) == X ) prev = i ; ans . set ( i , Math . min ( ans . get ( i ) , prev - i ) ) ; } for ( Integer val : ans ) System . out . print ( val + "" ▁ "" ) ; } public static void main ( String [ ] args ) { String S = "" geeksforgeeks "" ; char X = ' g ' ; shortestDistance ( S , X ) ; } } ","def shortestDistance ( S , X ) : NEW_LINE INDENT prev = float ( ' - inf ' ) NEW_LINE ans = [ ] NEW_LINE for i , j in enumerate ( S ) : NEW_LINE INDENT if j == X : NEW_LINE INDENT prev = i NEW_LINE DEDENT ans . append ( i - prev ) NEW_LINE DEDENT prev = float ( ' inf ' ) NEW_LINE for i in range ( len ( S ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if S [ i ] == X : NEW_LINE INDENT prev = i NEW_LINE DEDENT ans [ i ] = min ( ans [ i ] , prev - i ) NEW_LINE DEDENT return ans NEW_LINE DEDENT S = "" geeksforgeeks "" NEW_LINE X = "" g "" NEW_LINE print ( shortestDistance ( S , X ) ) NEW_LINE " V482,"import java . math . * ; class GFG { static int MAX = 100001 ; static double dp [ ] = new double [ MAX ] ; static double probability ( int k , int n ) { double ans = 0.0 ; for ( int i = k ; i <= n ; ++ i ) { double res = dp [ n ] - dp [ i ] - dp [ n - i ] - n ; ans += Math . pow ( 2.0 , res ) ; } return ans ; } static void precompute ( ) { for ( int i = 2 ; i < MAX ; ++ i ) dp [ i ] = ( Math . log ( i ) / Math . log ( 2 ) ) + dp [ i - 1 ] ; } public static void main ( String args [ ] ) { precompute ( ) ; System . out . println ( probability ( 2 , 3 ) ) ; System . out . println ( probability ( 3 , 6 ) ) ; System . out . println ( probability ( 500 , 1000 ) ) ; } } ","from math import log2 NEW_LINE MAX = 100001 NEW_LINE dp = [ 0 ] * MAX NEW_LINE def probability ( k , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( k , n + 1 ) : NEW_LINE INDENT res = dp [ n ] - dp [ i ] - dp [ n - i ] - n NEW_LINE ans = ans + pow ( 2.0 , res ) NEW_LINE DEDENT return ans NEW_LINE DEDENT def precompute ( ) : NEW_LINE INDENT for i in range ( 2 , MAX ) : NEW_LINE INDENT dp [ i ] = log2 ( i ) + dp [ i - 1 ] NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT precompute ( ) NEW_LINE print ( probability ( 2 , 3 ) ) NEW_LINE print ( probability ( 3 , 6 ) ) NEW_LINE print ( probability ( 500 , 1000 ) ) NEW_LINE DEDENT " V483,"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int maximumXOR ( int n , int l , int r ) { int x = 0 ; for ( int i = ( int ) ( Math . log ( r ) / Math . log ( 2 ) ) ; i >= 0 ; -- i ) { if ( ( n & ( 1 << i ) ) > 0 ) { if ( ( x > r ) || ( x + ( 1 << i ) - 1 < l ) ) x ^= ( 1 << i ) ; } else { if ( ( x ^ ( 1 << i ) ) <= r ) x ^= ( 1 << i ) ; } } return n ^ x ; } public static void main ( String args [ ] ) { int n = 7 , l = 2 , r = 23 ; System . out . println ( "" The ▁ output ▁ is ▁ "" + maximumXOR ( n , l , r ) ) ; } } ","import math NEW_LINE def maximumXOR ( n , l , r ) : NEW_LINE INDENT x = 0 NEW_LINE for i in range ( int ( math . log2 ( r ) ) , - 1 , - 1 ) : NEW_LINE INDENT if ( n & ( 1 << i ) ) : NEW_LINE INDENT if ( x > r ) or ( x + ( 1 << i ) - 1 < l ) : NEW_LINE INDENT x ^= ( 1 << i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( x ^ ( 1 << i ) ) <= r : NEW_LINE INDENT x ^= ( 1 << i ) NEW_LINE DEDENT DEDENT DEDENT return n ^ x NEW_LINE DEDENT n = 7 NEW_LINE l = 2 NEW_LINE r = 23 NEW_LINE print ( "" The ▁ output ▁ is "" , maximumXOR ( n , l , r ) ) NEW_LINE " V484,"import java . io . * ; class GFG { static double edgeDisjoint ( int n ) { double result = 0 ; result = Math . floor ( n / 2 ) ; return result ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( ( int ) edgeDisjoint ( n ) ) ; } } ","import math NEW_LINE def edgeDisjoint ( n ) : NEW_LINE INDENT result = 0 NEW_LINE result = math . floor ( n / 2 ) NEW_LINE return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 4 NEW_LINE print ( int ( edgeDisjoint ( n ) ) ) NEW_LINE DEDENT " V485,"import java . io . * ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return __gcd ( a - b , b ) ; return __gcd ( a , b - a ) ; } static long Probability ( int sum , int times ) { float favorable = 0 , total = 36 ; long probability = 0 ; for ( int i = 1 ; i <= 6 ; i ++ ) { for ( int j = 1 ; j <= 6 ; j ++ ) { if ( ( i + j ) == sum ) favorable ++ ; } } int gcd1 = __gcd ( ( int ) favorable , ( int ) total ) ; favorable = favorable / ( float ) gcd1 ; total = total / ( float ) gcd1 ; probability = ( long ) Math . pow ( total , times ) ; return probability ; } public static void main ( String [ ] args ) { int sum = 7 , times = 7 ; System . out . println ( ""1"" + "" / "" + Probability ( sum , times ) ) ; } } ","from math import * NEW_LINE def Probability ( sum , times ) : NEW_LINE INDENT favorable , total , probability = 0.0 , 36.0 , 0 NEW_LINE for i in range ( 7 ) : NEW_LINE INDENT for j in range ( 7 ) : NEW_LINE INDENT if ( ( i + j ) == sum ) : NEW_LINE INDENT favorable += 1 NEW_LINE DEDENT DEDENT DEDENT gcd1 = gcd ( int ( favorable ) , int ( total ) ) NEW_LINE favorable = favorable / gcd1 NEW_LINE total = total / gcd1 NEW_LINE probability = pow ( total , times ) NEW_LINE return int ( probability ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT sum , times = 7 , 7 NEW_LINE print ( ""1"" , "" / "" , Probability ( sum , times ) ) NEW_LINE DEDENT " V486,"import java . io . * ; class GFG { static int NumberOfSolutions ( int a , int b , int c , int d ) { int ans = 0 ; for ( int i = a ; i <= b ; i ++ ) if ( d >= Math . max ( c , i + 1 ) ) ans += d - Math . max ( c , i + 1 ) + 1 ; return ans ; } public static void main ( String [ ] args ) { int a = 2 , b = 3 , c = 3 , d = 4 ; System . out . println ( NumberOfSolutions ( a , b , c , d ) ) ; } } ","def NumberOfSolutions ( a , b , c , d ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT if d >= max ( c , i + 1 ) : NEW_LINE INDENT ans += d - max ( c , i + 1 ) + 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a , b , c , d = 2 , 3 , 3 , 4 NEW_LINE print ( NumberOfSolutions ( a , b , c , d ) ) NEW_LINE DEDENT " V487,"import java . util . * ; class GFG { static String reverse ( char [ ] str , int len , int l , int r ) { if ( l < 0 || r >= len || l > r ) return "" Invalid ▁ range ! "" ; while ( l < r ) { char c = str [ l ] ; str [ l ] = str [ r ] ; str [ r ] = c ; l ++ ; r -- ; } String string = new String ( str ) ; return string ; } public static void main ( String [ ] args ) { String str = "" geeksforgeeks "" ; int len = str . length ( ) ; int l = 5 , r = 7 ; System . out . println ( reverse ( str . toCharArray ( ) , len , l , r ) ) ; } } ","def reverse ( string , length , l , r ) : NEW_LINE INDENT if ( l < 0 or r >= length or l > r ) : NEW_LINE INDENT return string ; NEW_LINE DEDENT string = list ( string ) NEW_LINE while ( l < r ) : NEW_LINE INDENT c = string [ l ] ; NEW_LINE string [ l ] = string [ r ] ; NEW_LINE string [ r ] = c ; NEW_LINE l += 1 ; NEW_LINE r -= 1 ; NEW_LINE DEDENT return "" "" . join ( string ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" geeksforgeeks "" ; NEW_LINE length = len ( string ) ; NEW_LINE l = 5 ; r = 7 ; NEW_LINE print ( reverse ( string , length , l , r ) ) ; NEW_LINE DEDENT " V488,"import java . util . * ; class GFG { public static int MAX = 1000000 ; static ArrayList < Integer > primes = new ArrayList < Integer > ( ) ; static void sieveSundaram ( ) { boolean [ ] marked = new boolean [ MAX ] ; for ( int i = 1 ; i <= ( Math . sqrt ( MAX ) - 1 ) / 2 ; i ++ ) { for ( int j = ( i * ( i + 1 ) ) << 1 ; j <= MAX / 2 ; j += 2 * i + 1 ) { marked [ j ] = true ; } } primes . add ( 2 ) ; for ( int i = 1 ; i <= MAX / 2 ; i ++ ) { if ( marked [ i ] == false ) { primes . add ( 2 * i + 1 ) ; } } } static int calculatePrimorial ( int n ) { int result = 1 ; for ( int i = 0 ; i < n ; i ++ ) { result = result * primes . get ( i ) ; } return result ; } public static void main ( String [ ] args ) { int n = 5 ; sieveSundaram ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { System . out . println ( "" Primorial ( P # ) ▁ of ▁ "" + i + "" ▁ is ▁ "" + calculatePrimorial ( i ) ) ; } } } ","import math NEW_LINE MAX = 1000000 ; NEW_LINE primes = [ ] ; NEW_LINE def sieveSundaram ( ) : NEW_LINE INDENT marked = [ False ] * ( int ( MAX / 2 ) + 1 ) ; NEW_LINE for i in range ( 1 , int ( ( math . sqrt ( MAX ) - 1 ) / 2 ) + 1 ) : NEW_LINE INDENT for j in range ( ( ( i * ( i + 1 ) ) << 1 ) , ( int ( MAX / 2 ) + 1 ) , ( 2 * i + 1 ) ) : NEW_LINE INDENT marked [ j ] = True ; NEW_LINE DEDENT DEDENT primes . append ( 2 ) ; NEW_LINE for i in range ( 1 , int ( MAX / 2 ) ) : NEW_LINE INDENT if ( marked [ i ] == False ) : NEW_LINE INDENT primes . append ( 2 * i + 1 ) ; NEW_LINE DEDENT DEDENT DEDENT def calculatePrimorial ( n ) : NEW_LINE INDENT result = 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT result = result * primes [ i ] ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT n = 5 ; NEW_LINE sieveSundaram ( ) ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( "" Primorial ( P # ) ▁ of "" , i , "" is "" , calculatePrimorial ( i ) ) ; NEW_LINE DEDENT " V489,"import java . util . * ; class GFG { static int countOccurrances ( int n , int d ) { int count = 0 ; while ( n > 0 ) { count = ( n % 10 == d ) ? count + 1 : count ; n = n / 10 ; } return count ; } public static void main ( String args [ ] ) { int d = 2 ; int n = 214215421 ; System . out . println ( countOccurrances ( n , d ) ) ; } } ","def countOccurrances ( n , d ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( n % 10 == d ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT n = n // 10 NEW_LINE DEDENT return count NEW_LINE DEDENT d = 2 NEW_LINE n = 214215421 NEW_LINE print ( countOccurrances ( n , d ) ) NEW_LINE " V490,"import java . util . * ; class GFG { static void SieveOfEratosthenes ( boolean prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int sumOfElements ( int arr [ ] , int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; Arrays . fill ( prime , true ) ; SieveOfEratosthenes ( prime , n + 1 ) ; int i , j ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( m . containsKey ( arr [ i ] ) ) m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; else m . put ( arr [ i ] , 1 ) ; } int sum = 0 ; for ( Map . Entry < Integer , Integer > entry : m . entrySet ( ) ) { int key = entry . getKey ( ) ; int value = entry . getValue ( ) ; if ( prime [ value ] ) { sum += ( key ) ; } } return sum ; } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 4 , 6 , 5 , 4 , 6 } ; int n = arr . length ; System . out . println ( sumOfElements ( arr , n ) ) ; } } ","import math as mt NEW_LINE def SieveOfEratosthenes ( prime , p_size ) : NEW_LINE INDENT prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE for p in range ( 2 , mt . ceil ( mt . sqrt ( p_size + 1 ) ) ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( p * 2 , p_size + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def SumOfElements ( arr , n ) : NEW_LINE INDENT prime = [ True for i in range ( n + 1 ) ] NEW_LINE SieveOfEratosthenes ( prime , n + 1 ) NEW_LINE i , j = 0 , 0 NEW_LINE m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in m . keys ( ) : NEW_LINE INDENT m [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT Sum = 0 NEW_LINE for i in m : NEW_LINE INDENT if ( prime [ m [ i ] ] ) : NEW_LINE INDENT Sum += ( i ) NEW_LINE DEDENT DEDENT return Sum NEW_LINE DEDENT arr = [ 5 , 4 , 6 , 5 , 4 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( SumOfElements ( arr , n ) ) NEW_LINE " V491,"import java . util . * ; class Geeks_For_Geeks { public static int [ ] sortArrays ( int [ ] arr ) { int length = arr . length ; for ( int j = 0 ; j < length - 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { int temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = - 1 ; } } return arr ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 99 , 9 , 8 , 7 , 6 , 0 , 5 , 4 , 3 } ; System . out . println ( "" Original ▁ array : ▁ "" + Arrays . toString ( arr ) ) ; arr = sortArrays ( arr ) ; System . out . println ( "" Sorted ▁ array : ▁ "" + Arrays . toString ( arr ) ) ; } } ","def sortArrays ( arr ) : NEW_LINE INDENT length = len ( arr ) NEW_LINE j = 0 NEW_LINE while j < length - 1 : NEW_LINE INDENT if ( arr [ j ] > arr [ j + 1 ] ) : NEW_LINE INDENT temp = arr [ j ] NEW_LINE arr [ j ] = arr [ j + 1 ] NEW_LINE arr [ j + 1 ] = temp NEW_LINE j = - 1 NEW_LINE DEDENT j += 1 NEW_LINE DEDENT return arr NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 99 , 9 , 8 , 7 , 6 , 0 , 5 , 4 , 3 ] NEW_LINE print ( "" Original ▁ array : ▁ "" , arr ) NEW_LINE arr = sortArrays ( arr ) NEW_LINE print ( "" Sorted ▁ array : ▁ "" , arr ) NEW_LINE DEDENT " V492,"class Geeks { static boolean check ( int i , int val ) { if ( i - val < 0 ) return false ; else return true ; } static double MinimumPrimes ( int n ) { double [ ] dp ; dp = new double [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] = 1e9 ; dp [ 0 ] = dp [ 2 ] = dp [ 3 ] = dp [ 5 ] = dp [ 7 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( check ( i , 2 ) ) dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - 2 ] ) ; if ( check ( i , 3 ) ) dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - 3 ] ) ; if ( check ( i , 5 ) ) dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - 5 ] ) ; if ( check ( i , 7 ) ) dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - 7 ] ) ; } if ( dp [ n ] == ( 1e9 ) ) return - 1 ; else return dp [ n ] ; } public static void main ( String args [ ] ) { int n = 12 ; int minimal = ( int ) MinimumPrimes ( n ) ; if ( minimal != - 1 ) System . out . println ( "" Minimum ▁ number ▁ of ▁ single ▁ "" + "" digit ▁ primes ▁ required : ▁ "" + minimal ) ; else System . out . println ( "" Not ▁ Possible "" ) ; } } ","def check ( i , val ) : NEW_LINE INDENT if i - val < 0 : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT def MinimumPrimes ( n ) : NEW_LINE INDENT dp = [ 10 ** 9 ] * ( n + 1 ) NEW_LINE dp [ 0 ] = dp [ 2 ] = dp [ 3 ] = dp [ 5 ] = dp [ 7 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if check ( i , 2 ) : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 2 ] ) NEW_LINE DEDENT if check ( i , 3 ) : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 3 ] ) NEW_LINE DEDENT if check ( i , 5 ) : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 5 ] ) NEW_LINE DEDENT if check ( i , 7 ) : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , 1 + dp [ i - 7 ] ) NEW_LINE DEDENT DEDENT if dp [ n ] == 10 ** 9 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return dp [ n ] NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 12 NEW_LINE minimal = MinimumPrimes ( n ) NEW_LINE if minimal != - 1 : NEW_LINE INDENT print ( "" Minimum ▁ number ▁ of ▁ single ▁ digit ▁ primes ▁ required ▁ : ▁ "" , minimal ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Not ▁ possible "" ) NEW_LINE DEDENT DEDENT " V493,"import java . io . * ; class GFG { static int binomialCoeff ( int n , int k ) { int C [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } public static void main ( String [ ] args ) { int n = 5 , k = 3 ; System . out . println ( "" Total ▁ number ▁ of ▁ "" + "" different ▁ ways ▁ are ▁ "" + binomialCoeff ( n - 1 , k - 1 ) ) ; } } ","def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ [ 0 for i in range ( k + 1 ) ] for i in range ( n + 1 ) ] NEW_LINE for i in range ( 0 , n + 1 , 1 ) : NEW_LINE INDENT for j in range ( 0 , min ( i , k ) + 1 , 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] NEW_LINE DEDENT DEDENT DEDENT return C [ n ] [ k ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE k = 3 NEW_LINE print ( "" Total ▁ number ▁ of ▁ different ▁ ways ▁ are "" , binomialCoeff ( n - 1 , k - 1 ) ) NEW_LINE DEDENT " V494,"public class FINDSUM { static long mod = 1000000007 ; public static long findSum ( long n ) { return ( ( n % mod ) * ( n % mod ) ) % mod ; } public static void main ( String [ ] args ) { long n = 229137999 ; System . out . print ( findSum ( n ) ) ; } } ","mod = 1000000007 NEW_LINE def findSum ( n ) : NEW_LINE INDENT return ( ( n % mod ) * ( n % mod ) ) % mod NEW_LINE DEDENT n = 229137999 NEW_LINE print ( findSum ( n ) ) NEW_LINE " V495,"import java . io . * ; class GFG { static void print ( int n , int k ) { int rem = 1 ; for ( int i = 0 ; i < k ; i ++ ) { System . out . print ( ( 10 * rem ) / n ) ; rem = ( 10 * rem ) % n ; } } public static void main ( String [ ] args ) { int n = 7 , k = 3 ; print ( n , k ) ; System . out . println ( ) ; n = 21 ; k = 4 ; print ( n , k ) ; } } ","import math NEW_LINE def Print ( n , k ) : NEW_LINE INDENT rem = 1 NEW_LINE for i in range ( 0 , k ) : NEW_LINE INDENT print ( math . floor ( ( ( 10 * rem ) / n ) ) , end = "" "" ) NEW_LINE rem = ( 10 * rem ) % n NEW_LINE DEDENT DEDENT n = 7 NEW_LINE k = 3 NEW_LINE Print ( n , k ) ; NEW_LINE print ( "" ▁ "" ) NEW_LINE n = 21 NEW_LINE k = 4 NEW_LINE Print ( n , k ) ; NEW_LINE " V496,"class GFG { public static void main ( String [ ] args ) { int [ ] [ ] matrix = new int [ 5 ] [ 5 ] ; int row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } System . out . printf ( "" The ▁ matrix ▁ is \n "" ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { System . out . printf ( "" % d\t "" , matrix [ row_index ] [ column_index ] ) ; } System . out . printf ( "" \n "" ) ; } System . out . printf ( "" \n Elements ▁ below ▁ Secondary "" + "" ▁ diagonal ▁ are : \n "" ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index + column_index ) > size - 1 ) System . out . printf ( "" % d , ▁ "" , matrix [ row_index ] [ column_index ] ) ; } } } } ","if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT matrix = [ [ 0 for i in range ( 5 ) ] for j in range ( 5 ) ] NEW_LINE DEDENT row_index , column_index , x , size = 0 , 0 , 0 , 5 ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT x += 1 ; NEW_LINE matrix [ row_index ] [ column_index ] = x ; NEW_LINE DEDENT DEDENT print ( "" The ▁ matrix ▁ is "" ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = "" \t "" ) ; NEW_LINE DEDENT print ( "" "" ) ; NEW_LINE DEDENT print ( "" \n Elements ▁ below ▁ Secondary ▁ diagonal ▁ are : "" ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT if ( ( row_index + column_index ) > size - 1 ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = "" , ▁ "" ) ; NEW_LINE DEDENT DEDENT DEDENT " V497,"import java . util . HashSet ; class GFG { static int findProduct ( int arr [ ] , int n ) { int prod = 1 ; HashSet < Integer > s = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! s . contains ( arr [ i ] ) ) { prod *= arr [ i ] ; s . add ( arr [ i ] ) ; } } return prod ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 } ; int n = arr . length ; System . out . println ( findProduct ( arr , n ) ) ; } } ","def findProduct ( arr , n ) : NEW_LINE INDENT prod = 1 NEW_LINE s = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] not in s . keys ( ) ) : NEW_LINE INDENT prod *= arr [ i ] NEW_LINE s [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT return prod NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findProduct ( arr , n ) ) NEW_LINE " V498,"class GFG { static int findNumber ( int n ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { int [ ] count = new int [ 10 ] ; int x = i ; int count1 = 0 , count2 = 0 ; while ( x > 0 ) { count [ x % 10 ] ++ ; x /= 10 ; count1 ++ ; } for ( int j = 0 ; j < 10 ; j ++ ) { if ( count [ j ] == 1 ) count2 ++ ; } if ( count1 == count2 ) return i ; } return - 1 ; } public static void main ( String [ ] args ) { int n = 8490 ; System . out . println ( findNumber ( n ) ) ; } } ","def findNumber ( n ) : NEW_LINE INDENT i = n - 1 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT count = [ 0 for i in range ( 10 ) ] NEW_LINE x = i NEW_LINE count1 = 0 NEW_LINE count2 = 0 NEW_LINE while ( x ) : NEW_LINE INDENT count [ x % 10 ] += 1 NEW_LINE x = int ( x / 10 ) NEW_LINE count1 += 1 NEW_LINE DEDENT for j in range ( 0 , 10 , 1 ) : NEW_LINE INDENT if ( count [ j ] == 1 ) : NEW_LINE INDENT count2 += 1 NEW_LINE DEDENT DEDENT if ( count1 == count2 ) : NEW_LINE INDENT return i NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 8490 NEW_LINE print ( findNumber ( n ) ) NEW_LINE DEDENT " V499,"class GFG { static final int modd = 1000000007 ; static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % p ; } y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int ways ( int n , int m ) { return ( int ) ( power ( m - 1 , n - 1 , modd ) * m % modd ) ; } public static void main ( String [ ] args ) { int n = 5 , m = 5 ; System . out . println ( ways ( n , m ) ) ; } } ","modd = 1000000007 NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def ways ( n , m ) : NEW_LINE INDENT return power ( m - 1 , n - 1 , modd ) * m % modd NEW_LINE DEDENT n , m = 5 , 5 NEW_LINE print ( ways ( n , m ) ) NEW_LINE " V500,"class GFG { static void q1 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( "" Yes "" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q2 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( "" No "" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q3 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( "" Yes "" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q4 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( "" No "" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q0 ( String s , int i ) { if ( i == s . length ( ) ) { System . out . println ( "" No "" ) ; return ; } if ( s . charAt ( i ) == ' a ' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } public static void main ( String [ ] args ) { String s = "" abbaabb "" ; q0 ( s , 0 ) ; } } ","def q1 ( s , i ) : NEW_LINE INDENT if ( i == len ( s ) ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE return ; NEW_LINE DEDENT if ( s [ i ] == ' a ' ) : NEW_LINE INDENT q1 ( s , i + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT q2 ( s , i + 1 ) ; NEW_LINE DEDENT DEDENT def q2 ( s , i ) : NEW_LINE INDENT if ( i == len ( s ) ) : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE return ; NEW_LINE DEDENT if ( s [ i ] == ' a ' ) : NEW_LINE INDENT q1 ( s , i + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT q2 ( s , i + 1 ) ; NEW_LINE DEDENT DEDENT def q3 ( s , i ) : NEW_LINE INDENT if ( i == len ( s ) ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE return ; NEW_LINE DEDENT if ( s [ i ] == ' a ' ) : NEW_LINE INDENT q4 ( s , i + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT q3 ( s , i + 1 ) ; NEW_LINE DEDENT DEDENT def q4 ( s , i ) : NEW_LINE INDENT if ( i == s . length ( ) ) : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE return ; NEW_LINE DEDENT if ( s [ i ] == ' a ' ) : NEW_LINE INDENT q4 ( s , i + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT q3 ( s , i + 1 ) ; NEW_LINE DEDENT DEDENT def q0 ( s , i ) : NEW_LINE INDENT if ( i == len ( s ) ) : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE return ; NEW_LINE DEDENT if ( s [ i ] == ' a ' ) : NEW_LINE INDENT q1 ( s , i + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT q3 ( s , i + 1 ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = "" abbaabb "" ; NEW_LINE q0 ( s , 0 ) ; NEW_LINE DEDENT " V501,"import java . io . * ; class GFG { static float heightCalculate ( int H , int n , int m ) { float N = ( float ) ( n * 1.0 ) ; float M = ( float ) ( m * 1.0 ) ; float h = H * ( float ) Math . sqrt ( N / ( N + M ) ) ; return h ; } public static void main ( String [ ] args ) { int H = 10 , n = 3 , m = 4 ; System . out . print ( heightCalculate ( H , n , m ) ) ; } } ","from math import sqrt NEW_LINE def heightCalculate ( H , n , m ) : NEW_LINE INDENT N = n * 1.0 NEW_LINE M = m * 1.0 NEW_LINE h = H * sqrt ( N / ( N + M ) ) NEW_LINE return h NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT H = 10 NEW_LINE n = 3 NEW_LINE m = 4 NEW_LINE print ( "" { 0 : . 6 } "" . format ( heightCalculate ( H , n , m ) ) ) ; NEW_LINE DEDENT " V502,"import java . io . * ; class GFG { static int CountWays ( int n , boolean flag ) { if ( n == 0 ) return 1 ; int sum = 0 ; if ( flag == false && n > 1 ) sum = sum + CountWays ( n - 1 , false ) + CountWays ( n - 2 , true ) ; else sum = sum + CountWays ( n - 1 , false ) ; return sum ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( CountWays ( n , false ) ) ; } } ","def CountWays ( n , flag ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT sum = 0 NEW_LINE if flag == False and n > 1 : NEW_LINE INDENT sum = sum + CountWays ( n - 1 , False ) + CountWays ( n - 2 , True ) NEW_LINE DEDENT else : NEW_LINE INDENT sum = sum + CountWays ( n - 1 , False ) NEW_LINE DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE print ( CountWays ( n , False ) ) NEW_LINE DEDENT " V503,"import java . io . * ; import java . util . * ; class GFG { static void printVector ( Vector < Integer > v ) { System . out . println ( v . size ( ) ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) System . out . print ( v . get ( i ) + "" ▁ "" ) ; System . out . println ( ) ; } static void findTwoGroup ( int n ) { int sum = n * ( n + 1 ) / 2 ; int group1Sum = sum / 2 ; Vector < Integer > group1 = new Vector < Integer > ( ) ; Vector < Integer > group2 = new Vector < Integer > ( ) ; for ( int i = n ; i > 0 ; i -- ) { if ( group1Sum - i >= 0 ) { group1 . add ( i ) ; group1Sum -= i ; } else { group2 . add ( i ) ; } } printVector ( group1 ) ; printVector ( group2 ) ; } public static void main ( String [ ] args ) { int n = 5 ; findTwoGroup ( n ) ; } } ","import math NEW_LINE def printVector ( v ) : NEW_LINE INDENT print ( len ( v ) ) NEW_LINE for i in range ( 0 , len ( v ) ) : NEW_LINE INDENT print ( v [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT def findTwoGroup ( n ) : NEW_LINE INDENT sum = n * ( n + 1 ) / 2 NEW_LINE group1Sum = sum / 2 NEW_LINE group1 = [ ] NEW_LINE group2 = [ ] NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT if ( group1Sum - i >= 0 ) : NEW_LINE INDENT group1 . append ( i ) NEW_LINE group1Sum -= i NEW_LINE DEDENT else : NEW_LINE INDENT group2 . append ( i ) NEW_LINE DEDENT DEDENT printVector ( group1 ) NEW_LINE printVector ( group2 ) NEW_LINE DEDENT n = 5 NEW_LINE findTwoGroup ( n ) NEW_LINE " V504,"class GFG { static void printNumbers ( int a [ ] , int n , int x ) { boolean flag = false ; for ( int i = 0 ; i < n ; i ++ ) { int num = a [ i ] ; int g = __gcd ( num , x ) ; while ( g != 1 ) { num /= g ; g = __gcd ( num , x ) ; } if ( num == 1 ) { flag = true ; System . out . print ( a [ i ] + "" ▁ "" ) ; } } if ( ! flag ) System . out . println ( "" There ▁ are ▁ no ▁ such ▁ numbers "" ) ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int x = 60 ; int a [ ] = { 2 , 5 , 10 , 7 , 17 } ; int n = a . length ; printNumbers ( a , n , x ) ; } } ","from math import gcd NEW_LINE def printNumbers ( a , n , x ) : NEW_LINE INDENT flag = False NEW_LINE for i in range ( n ) : NEW_LINE INDENT num = a [ i ] NEW_LINE g = gcd ( num , x ) NEW_LINE while ( g != 1 ) : NEW_LINE INDENT num //= g NEW_LINE g = gcd ( num , x ) NEW_LINE DEDENT if ( num == 1 ) : NEW_LINE INDENT flag = True ; NEW_LINE print ( a [ i ] , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT if ( not flag ) : NEW_LINE INDENT print ( "" There ▁ are ▁ no ▁ such ▁ numbers "" ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT x = 60 NEW_LINE a = [ 2 , 5 , 10 , 7 , 17 ] NEW_LINE n = len ( a ) NEW_LINE printNumbers ( a , n , x ) NEW_LINE DEDENT " V505,"import java . util . * ; class GFG { static String maxNumber ( String str , int n ) { int [ ] freq = new int [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == ' z ' ) freq [ 0 ] ++ ; else if ( str . charAt ( i ) == ' n ' ) freq [ 1 ] ++ ; } String num = "" "" ; for ( int i = 0 ; i < freq [ 1 ] ; i ++ ) num += '1' ; for ( int i = 0 ; i < freq [ 0 ] ; i ++ ) num += '0' ; return num ; } public static void main ( String [ ] args ) { String str = "" roenenzooe "" ; int n = str . length ( ) ; System . out . println ( maxNumber ( str , n ) ) ; } } ","def maxNumber ( string , n ) : NEW_LINE INDENT freq = [ 0 , 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( string [ i ] == ' z ' ) : NEW_LINE INDENT freq [ 0 ] += 1 ; NEW_LINE DEDENT elif ( string [ i ] == ' n ' ) : NEW_LINE INDENT freq [ 1 ] += 1 ; NEW_LINE DEDENT DEDENT num = "" "" ; NEW_LINE for i in range ( freq [ 1 ] ) : NEW_LINE INDENT num += '1' ; NEW_LINE DEDENT for i in range ( freq [ 0 ] ) : NEW_LINE INDENT num += '0' ; NEW_LINE DEDENT return num ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" roenenzooe "" ; NEW_LINE n = len ( string ) ; NEW_LINE print ( maxNumber ( string , n ) ) ; NEW_LINE DEDENT " V506,"import java . io . * ; class Emirp { public static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } public static boolean isEmirp ( int n ) { if ( isPrime ( n ) == false ) return false ; int rev = 0 ; while ( n != 0 ) { int d = n % 10 ; rev = rev * 10 + d ; n /= 10 ; } return isPrime ( rev ) ; } public static void main ( String args [ ] ) throws IOException { int n = 13 ; if ( isEmirp ( n ) == true ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isPrime ( n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def isEmirp ( n ) : NEW_LINE INDENT n = int ( n ) NEW_LINE if isPrime ( n ) == False : NEW_LINE INDENT return False NEW_LINE DEDENT rev = 0 NEW_LINE while n != 0 : NEW_LINE INDENT d = n % 10 NEW_LINE rev = rev * 10 + d NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return isPrime ( rev ) NEW_LINE DEDENT n = 13 NEW_LINE if isEmirp ( n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V507,"class GFG { static int substrDeletion ( String str , int len ) { int count0 = 0 , count1 = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) count0 ++ ; else count1 ++ ; } return Math . min ( count0 , count1 ) ; } public static void main ( String [ ] args ) { String str = ""010"" ; int len = str . length ( ) ; System . out . println ( substrDeletion ( str , len ) ) ; } } ","def substrDeletion ( string , length ) : NEW_LINE INDENT count0 = 0 ; NEW_LINE count1 = 0 ; NEW_LINE for i in range ( length ) : NEW_LINE INDENT if ( string [ i ] == '0' ) : NEW_LINE INDENT count0 += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT count1 += 1 ; NEW_LINE DEDENT DEDENT return min ( count0 , count1 ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = ""010"" ; NEW_LINE length = len ( string ) ; NEW_LINE print ( substrDeletion ( string , length ) ) ; NEW_LINE DEDENT " V508,"import java . util . * ; class GFG { static boolean IsPossible ( String s ) { int n = s . length ( ) ; HashSet < Character > count = new HashSet < > ( ) ; HashMap < Character , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { count . add ( s . charAt ( i ) ) ; map . put ( s . charAt ( i ) , map . get ( s . charAt ( i ) ) == null ? 1 : map . get ( s . charAt ( i ) ) + 1 ) ; } if ( count . size ( ) == 1 ) return true ; if ( count . size ( ) > 2 ) return false ; String newString = count . toArray ( ) . toString ( ) ; int j = 0 ; char it = newString . charAt ( j ) ; int x = 0 , y = 0 ; x = map . get ( it ) == null ? 0 : map . get ( it ) ; j ++ ; it = newString . charAt ( j ) ; y = map . get ( it ) == null ? 0 : map . get ( it ) ; if ( Math . abs ( x - y ) <= 1 ) return true ; return false ; } public static void main ( String [ ] args ) { String s = "" aaaddad "" ; if ( IsPossible ( s ) ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def IsPossible ( s ) : NEW_LINE INDENT n = len ( s ) ; NEW_LINE count = set ( ) ; NEW_LINE map = dict . fromkeys ( s , 0 ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT count . add ( s [ i ] ) ; NEW_LINE map [ s [ i ] ] += 1 ; NEW_LINE DEDENT if ( len ( count ) == 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT if ( len ( count ) > 2 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT j = 0 NEW_LINE it = list ( count ) [ j ] ; NEW_LINE x = 0 ; y = 0 ; NEW_LINE x = map [ it ] ; NEW_LINE j += 1 NEW_LINE it = list ( count ) [ j ] ; NEW_LINE y = map [ it ] ; NEW_LINE if ( abs ( x - y ) <= 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" aaaddad "" ; NEW_LINE if ( IsPossible ( s ) ) : NEW_LINE INDENT print ( "" YES "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) ; NEW_LINE DEDENT DEDENT " V509,"import java . io . * ; class GFG { static void radius ( double n , double d ) { System . out . print ( "" The ▁ side ▁ of ▁ each ▁ square ▁ is ▁ "" + d / ( ( n - 1 ) * Math . sqrt ( 2 ) ) ) ; } public static void main ( String [ ] args ) { double d = 42 , n = 4 ; radius ( n , d ) ; } } ","def radius ( n , d ) : NEW_LINE INDENT print ( "" The ▁ side ▁ of ▁ each ▁ square ▁ is ▁ "" , d / ( ( n - 1 ) * ( 2 ** ( 1 / 2 ) ) ) ) ; NEW_LINE DEDENT d = 42 ; n = 4 ; NEW_LINE radius ( n , d ) ; NEW_LINE " V510,"import java . io . * ; class GFG { static void modularEquation ( int a , int b ) { if ( a < b ) { System . out . println ( "" No ▁ solution ▁ possible ▁ "" ) ; return ; } if ( a == b ) { System . out . println ( "" Infinite ▁ Solution ▁ possible ▁ "" ) ; return ; } int count = 0 ; int n = a - b ; int y = ( int ) Math . sqrt ( a - b ) ; for ( int i = 1 ; i <= y ; ++ i ) { if ( n % i == 0 ) { if ( n / i > b ) count ++ ; if ( i > b ) count ++ ; } } if ( y * y == n && y > b ) count -- ; System . out . println ( count ) ; } public static void main ( String [ ] args ) { int a = 21 , b = 5 ; modularEquation ( a , b ) ; } } ","import math NEW_LINE def modularEquation ( a , b ) : NEW_LINE INDENT if ( a < b ) : NEW_LINE INDENT print ( "" No ▁ solution ▁ possible ▁ "" ) NEW_LINE return NEW_LINE DEDENT if ( a == b ) : NEW_LINE INDENT print ( "" Infinite ▁ Solution ▁ possible ▁ "" ) NEW_LINE return NEW_LINE DEDENT count = 0 NEW_LINE n = a - b NEW_LINE y = ( int ) ( math . sqrt ( a - b ) ) NEW_LINE for i in range ( 1 , y + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n / i > b ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT if ( i > b ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT DEDENT if ( y * y == n and y > b ) : NEW_LINE INDENT count = count - 1 NEW_LINE DEDENT print ( count ) NEW_LINE DEDENT a = 21 NEW_LINE b = 5 NEW_LINE modularEquation ( a , b ) NEW_LINE " V511,"class GFG { static int reverseNum ( int x ) { String s = Integer . toString ( x ) ; String str = "" "" ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { str = str + s . charAt ( i ) ; } int rev = Integer . parseInt ( str ) ; return rev ; } static boolean isMysteryNumber ( int n ) { for ( int i = 1 ; i <= n / 2 ; i ++ ) { int j = reverseNum ( i ) ; if ( i + j == n ) { System . out . println ( i + "" ▁ "" + j ) ; return true ; } } System . out . println ( "" Not ▁ a ▁ Mystery ▁ Number "" ) ; return false ; } public static void main ( String [ ] args ) { int n = 121 ; isMysteryNumber ( n ) ; } } ","def reverseNum ( x ) : NEW_LINE INDENT s = str ( x ) NEW_LINE s = s [ : : - 1 ] NEW_LINE return int ( s ) NEW_LINE DEDENT def isMysteryNumber ( n ) : NEW_LINE INDENT for i in range ( 1 , n // 2 + 1 ) : NEW_LINE INDENT j = reverseNum ( i ) NEW_LINE if i + j == n : NEW_LINE INDENT print ( i , j ) NEW_LINE return True NEW_LINE DEDENT DEDENT print ( "" Not ▁ a ▁ Mystery ▁ Number "" ) NEW_LINE return False NEW_LINE DEDENT n = 121 NEW_LINE isMysteryNumber ( n ) NEW_LINE " V512,"class GFG { public static int solve ( int [ ] [ ] dp , int wt , int K , int M , int used ) { if ( wt < 0 ) { return 0 ; } if ( wt == 0 ) { if ( used == 1 ) { return 1 ; } return 0 ; } if ( dp [ wt ] [ used ] != - 1 ) { return dp [ wt ] [ used ] ; } int ans = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { if ( i >= M ) { ans += solve ( dp , wt - i , K , M , used | 1 ) ; } else { ans += solve ( dp , wt - i , K , M , used ) ; } } return dp [ wt ] [ used ] = ans ; } public static void main ( String [ ] args ) { int W = 3 , K = 3 , M = 2 ; int [ ] [ ] dp = new int [ W + 1 ] [ 2 ] ; for ( int i = 0 ; i < W + 1 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } System . out . print ( solve ( dp , W , K , M , 0 ) + "" \n "" ) ; } } ","import numpy as np NEW_LINE def solve ( dp , wt , K , M , used ) : NEW_LINE INDENT if ( wt < 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( wt == 0 ) : NEW_LINE INDENT if ( used ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT if ( dp [ wt ] [ used ] != - 1 ) : NEW_LINE INDENT return dp [ wt ] [ used ] NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 1 , K + 1 ) : NEW_LINE INDENT if ( i >= M ) : NEW_LINE INDENT ans += solve ( dp , wt - i , K , M , used | 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += solve ( dp , wt - i , K , M , used ) NEW_LINE DEDENT DEDENT dp [ wt ] [ used ] = ans NEW_LINE return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT W = 3 NEW_LINE K = 3 NEW_LINE M = 2 NEW_LINE dp = np . ones ( ( W + 1 , 2 ) ) ; NEW_LINE dp = - 1 * dp NEW_LINE print ( solve ( dp , W , K , M , 0 ) ) NEW_LINE DEDENT " V513,"import java . util . Vector ; class Test { static void printDivisors ( int n ) { Vector < Integer > v = new Vector < > ( ) ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) System . out . printf ( "" % d ▁ "" , i ) ; else { System . out . printf ( "" % d ▁ "" , i ) ; v . add ( n / i ) ; } } } for ( int i = v . size ( ) - 1 ; i >= 0 ; i -- ) System . out . printf ( "" % d ▁ "" , v . get ( i ) ) ; } public static void main ( String args [ ] ) { System . out . println ( "" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ "" ) ; printDivisors ( 100 ) ; } } ","import math NEW_LINE def printDivisors ( n ) : NEW_LINE INDENT list = [ ] NEW_LINE for i in range ( 1 , int ( math . sqrt ( n ) + 1 ) ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n / i == i ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE list . append ( int ( n / i ) ) NEW_LINE DEDENT DEDENT DEDENT for i in list [ : : - 1 ] : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT print ( "" The ▁ divisors ▁ of ▁ 100 ▁ are : ▁ "" ) NEW_LINE printDivisors ( 100 ) NEW_LINE " V514,"import java . util . * ; class GFG { static boolean isSubSequence ( String str1 , String str2 ) { int m = str1 . length ( ) , n = str2 . length ( ) ; int j = 0 ; for ( int i = 0 ; i < n && j < m ; i ++ ) { if ( str1 . charAt ( j ) == str2 . charAt ( i ) ) { j ++ ; } } return ( j == m ) ; } static String findLongestString ( Vector < String > dict , String str ) { String result = "" "" ; int length = 0 ; for ( String word : dict ) { if ( length < word . length ( ) && isSubSequence ( word , str ) ) { result = word ; length = word . length ( ) ; } } return result ; } public static void main ( String [ ] args ) { String [ ] arr = { "" ale "" , "" apple "" , "" monkey "" , "" plea "" } ; Vector dict = new Vector ( Arrays . asList ( arr ) ) ; String str = "" abpcplea "" ; System . out . println ( findLongestString ( dict , str ) ) ; } } ","def isSubSequence ( str1 , str2 ) : NEW_LINE INDENT m = len ( str1 ) ; NEW_LINE n = len ( str2 ) ; NEW_LINE j = 0 ; NEW_LINE i = 0 ; NEW_LINE while ( i < n and j < m ) : NEW_LINE INDENT if ( str1 [ j ] == str2 [ i ] ) : NEW_LINE INDENT j += 1 ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT return ( j == m ) ; NEW_LINE DEDENT def findLongestString ( dict1 , str1 ) : NEW_LINE INDENT result = "" "" ; NEW_LINE length = 0 ; NEW_LINE for word in dict1 : NEW_LINE INDENT if ( length < len ( word ) and isSubSequence ( word , str1 ) ) : NEW_LINE INDENT result = word ; NEW_LINE length = len ( word ) ; NEW_LINE DEDENT DEDENT return result ; NEW_LINE DEDENT dict1 = [ "" ale "" , "" apple "" , "" monkey "" , "" plea "" ] ; NEW_LINE str1 = "" abpcplea "" ; NEW_LINE print ( findLongestString ( dict1 , str1 ) ) ; NEW_LINE " V515,"import java . util . Arrays ; import java . lang . Math ; class GFG { public static int lenoflongestnonpalindrome ( String s ) { int max1 = 1 , len = 0 ; char [ ] new_str = s . toCharArray ( ) ; for ( int i = 0 ; i < new_str . length - 1 ; i ++ ) { if ( new_str [ i ] == new_str [ i + 1 ] ) len = 0 ; else if ( i > 0 && ( new_str [ i + 1 ] == new_str [ i - 1 ] ) ) len = 1 ; else len ++ ; max1 = Math . max ( max1 , len + 1 ) ; } if ( max1 == 1 ) return 0 ; else return max1 ; } public static void main ( String [ ] args ) { String s = "" synapse "" ; System . out . println ( lenoflongestnonpalindrome ( s ) ) ; } } ","def lenoflongestnonpalindrome ( s ) : NEW_LINE INDENT max1 , length = 1 , 0 NEW_LINE for i in range ( 0 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == s [ i + 1 ] : NEW_LINE INDENT length = 0 NEW_LINE DEDENT elif s [ i + 1 ] == s [ i - 1 ] and i > 0 : NEW_LINE INDENT length = 1 NEW_LINE DEDENT else : NEW_LINE INDENT length += 1 NEW_LINE DEDENT max1 = max ( max1 , length + 1 ) NEW_LINE DEDENT if max1 == 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return max1 NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" synapse "" NEW_LINE print ( lenoflongestnonpalindrome ( s ) ) NEW_LINE DEDENT " V516,"class GFG { static char MAX_CHAR = 26 ; static void countFreq ( String str , int freq [ ] , int len ) { for ( int i = 0 ; i < len ; i ++ ) { freq [ str . charAt ( i ) - ' a ' ] ++ ; } } static boolean canMakePalindrome ( int freq [ ] , int len ) { int count_odd = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( freq [ i ] % 2 != 0 ) { count_odd ++ ; } } if ( len % 2 == 0 ) { if ( count_odd > 0 ) { return false ; } else { return true ; } } if ( count_odd != 1 ) { return false ; } return true ; } static String findOddAndRemoveItsFreq ( int freq [ ] ) { String odd_str = "" "" ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( freq [ i ] % 2 != 0 ) { freq [ i ] -- ; odd_str = odd_str + ( char ) ( i + ' a ' ) ; return odd_str ; } } return odd_str ; } static String findPalindromicString ( String str ) { int len = str . length ( ) ; int freq [ ] = new int [ MAX_CHAR ] ; countFreq ( str , freq , len ) ; if ( ! canMakePalindrome ( freq , len ) ) { return "" No ▁ Palindromic ▁ String "" ; } String odd_str = findOddAndRemoveItsFreq ( freq ) ; String front_str = "" "" , rear_str = "" ▁ "" ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { String temp = "" "" ; if ( freq [ i ] != 0 ) { char ch = ( char ) ( i + ' a ' ) ; for ( int j = 1 ; j <= freq [ i ] / 2 ; j ++ ) { temp = temp + ch ; } front_str = front_str + temp ; rear_str = temp + rear_str ; } } return ( front_str + odd_str + rear_str ) ; } public static void main ( String [ ] args ) { String str = "" malayalam "" ; System . out . println ( findPalindromicString ( str ) ) ; } } ","MAX_CHAR = 26 ; NEW_LINE def countFreq ( str1 , freq , len1 ) : NEW_LINE INDENT for i in range ( len1 ) : NEW_LINE INDENT freq [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1 ; NEW_LINE DEDENT DEDENT def canMakePalindrome ( freq , len1 ) : NEW_LINE INDENT count_odd = 0 ; NEW_LINE for i in range ( MAX_CHAR ) : NEW_LINE INDENT if ( freq [ i ] % 2 != 0 ) : NEW_LINE INDENT count_odd += 1 ; NEW_LINE DEDENT DEDENT if ( len1 % 2 == 0 ) : NEW_LINE INDENT if ( count_odd > 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT else : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT if ( count_odd != 1 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT def findOddAndRemoveItsFreq ( freq ) : NEW_LINE INDENT odd_str = "" "" ; NEW_LINE for i in range ( MAX_CHAR ) : NEW_LINE INDENT if ( freq [ i ] % 2 != 0 ) : NEW_LINE INDENT freq [ i ] -= 1 ; NEW_LINE odd_str += chr ( i + ord ( ' a ' ) ) ; NEW_LINE return odd_str ; NEW_LINE DEDENT DEDENT return odd_str ; NEW_LINE DEDENT def findPalindromicString ( str1 ) : NEW_LINE INDENT len1 = len ( str1 ) ; NEW_LINE freq = [ 0 ] * MAX_CHAR ; NEW_LINE countFreq ( str1 , freq , len1 ) ; NEW_LINE if ( canMakePalindrome ( freq , len1 ) == False ) : NEW_LINE INDENT return "" No ▁ Palindromic ▁ String "" ; NEW_LINE DEDENT odd_str = findOddAndRemoveItsFreq ( freq ) ; NEW_LINE front_str = "" "" ; NEW_LINE rear_str = "" ▁ "" ; NEW_LINE for i in range ( MAX_CHAR ) : NEW_LINE INDENT temp = "" "" ; NEW_LINE if ( freq [ i ] != 0 ) : NEW_LINE INDENT ch = chr ( i + ord ( ' a ' ) ) ; NEW_LINE for j in range ( 1 , int ( freq [ i ] / 2 ) + 1 ) : NEW_LINE INDENT temp += ch ; NEW_LINE DEDENT front_str += temp ; NEW_LINE rear_str = temp + rear_str ; NEW_LINE DEDENT DEDENT return ( front_str + odd_str + rear_str ) ; NEW_LINE DEDENT str1 = "" malayalam "" ; NEW_LINE print ( findPalindromicString ( str1 ) ) ; NEW_LINE " V517,"import java . util . * ; class GFG { static void twistedTOH ( int n , char first , char middle , char last ) { if ( n == 1 ) { System . out . println ( "" Move ▁ disk ▁ "" + n + "" ▁ from ▁ rod ▁ "" + first + "" ▁ to ▁ "" + middle + "" ▁ and ▁ then ▁ to ▁ "" + last ) ; return ; } twistedTOH ( n - 1 , first , middle , last ) ; System . out . println ( "" Move ▁ disk ▁ "" + n + "" ▁ from ▁ rod ▁ "" + first + "" ▁ to ▁ "" + middle ) ; twistedTOH ( n - 1 , last , middle , first ) ; System . out . println ( "" Move ▁ disk ▁ "" + n + "" ▁ from ▁ rod ▁ "" + middle + "" ▁ to ▁ "" + last ) ; twistedTOH ( n - 1 , first , middle , last ) ; } public static void main ( String [ ] args ) { int n = 2 ; twistedTOH ( n , ' A ' , ' B ' , ' C ' ) ; } } ","def twistedTOH ( n , first , middle , last ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT print ( "" Move ▁ disk "" , n , "" from ▁ rod "" , first , "" to "" , middle , "" and ▁ then ▁ to "" , last ) NEW_LINE return NEW_LINE DEDENT twistedTOH ( n - 1 , first , middle , last ) NEW_LINE print ( "" Move ▁ disk "" , n , "" from ▁ rod "" , first , "" to "" , middle ) NEW_LINE twistedTOH ( n - 1 , last , middle , first ) NEW_LINE print ( "" Move ▁ disk "" , n , "" from ▁ rod "" , middle , "" to "" , last ) NEW_LINE twistedTOH ( n - 1 , first , middle , last ) NEW_LINE DEDENT n = 2 NEW_LINE twistedTOH ( n , ' A ' , ' B ' , ' C ' ) NEW_LINE " V518,"class GFG { static int countSetBits ( int n ) { int bitCount = 0 ; for ( int i = 1 ; i <= n ; i ++ ) bitCount += countSetBitsUtil ( i ) ; return bitCount ; } static int countSetBitsUtil ( int x ) { if ( x <= 0 ) return 0 ; return ( x % 2 == 0 ? 0 : 1 ) + countSetBitsUtil ( x / 2 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( "" Total ▁ set ▁ bit ▁ count ▁ is ▁ "" ) ; System . out . print ( countSetBits ( n ) ) ; } } ","def countSetBits ( n ) : NEW_LINE INDENT bitCount = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT bitCount += countSetBitsUtil ( i ) NEW_LINE DEDENT return bitCount NEW_LINE DEDENT def countSetBitsUtil ( x ) : NEW_LINE INDENT if ( x <= 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( 0 if int ( x % 2 ) == 0 else 1 ) + countSetBitsUtil ( int ( x / 2 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE print ( "" Total ▁ set ▁ bit ▁ count ▁ is "" , countSetBits ( n ) ) NEW_LINE DEDENT " V519,"import java . io . * ; class GFG { static int bit ( int x ) { int ans = 0 ; while ( x > 0 ) { x /= 2 ; ans ++ ; } return ans ; } static boolean check ( int d , int x ) { if ( bit ( x / d ) <= bit ( d ) ) return true ; return false ; } static int bs ( int n ) { int l = 1 , r = ( int ) Math . sqrt ( n ) ; while ( l < r ) { int m = ( l + r ) / 2 ; if ( check ( m , n ) ) r = m ; else l = m + 1 ; } if ( ! check ( l , n ) ) return l + 1 ; else return l ; } static int countDivisor ( int n ) { return n - bs ( n ) + 1 ; } static public void main ( String [ ] args ) { int n = 5 ; System . out . println ( countDivisor ( n ) ) ; } } ","import math NEW_LINE def bit ( x ) : NEW_LINE INDENT ans = 0 NEW_LINE while ( x ) : NEW_LINE INDENT x /= 2 NEW_LINE ans = ans + 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT def check ( d , x ) : NEW_LINE INDENT if ( bit ( x / d ) <= bit ( d ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False ; NEW_LINE DEDENT def bs ( n ) : NEW_LINE INDENT l = 1 NEW_LINE r = int ( math . sqrt ( n ) ) NEW_LINE while ( l < r ) : NEW_LINE INDENT m = int ( ( l + r ) / 2 ) NEW_LINE if ( check ( m , n ) ) : NEW_LINE INDENT r = m NEW_LINE DEDENT else : NEW_LINE INDENT l = m + 1 NEW_LINE DEDENT DEDENT if ( check ( l , n ) == False ) : NEW_LINE INDENT return math . floor ( l + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT return math . floor ( l ) NEW_LINE DEDENT DEDENT def countDivisor ( n ) : NEW_LINE INDENT return n - bs ( n ) + 1 NEW_LINE DEDENT n = 5 NEW_LINE print ( countDivisor ( n ) ) NEW_LINE " V520,"import java . io . * ; class GFG { static boolean isPresent ( int B [ ] , int m , int x ) { for ( int i = 0 ; i < m ; i ++ ) if ( B [ i ] == x ) return true ; return false ; } static int findMaxSubarraySumUtil ( int A [ ] , int B [ ] , int n , int m ) { int max_so_far = - 2147483648 , curr_max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPresent ( B , m , A [ i ] ) ) { curr_max = 0 ; continue ; } curr_max = Math . max ( A [ i ] , curr_max + A [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; } static void findMaxSubarraySum ( int A [ ] , int B [ ] , int n , int m ) { int maxSubarraySum = findMaxSubarraySumUtil ( A , B , n , m ) ; if ( maxSubarraySum == - 2147483648 ) { System . out . println ( "" Maximum ▁ Subarray ▁ Sum "" + "" ▁ "" + "" can ' t ▁ be ▁ found "" ) ; } else { System . out . println ( "" The ▁ Maximum ▁ Subarray ▁ Sum ▁ = ▁ "" + maxSubarraySum ) ; } } public static void main ( String [ ] args ) { int A [ ] = { 3 , 4 , 5 , - 4 , 6 } ; int B [ ] = { 1 , 8 , 5 } ; int n = A . length ; int m = B . length ; findMaxSubarraySum ( A , B , n , m ) ; } } ","INT_MIN = - 2147483648 NEW_LINE def isPresent ( B , m , x ) : NEW_LINE INDENT for i in range ( 0 , m ) : NEW_LINE INDENT if B [ i ] == x : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def findMaxSubarraySumUtil ( A , B , n , m ) : NEW_LINE INDENT max_so_far = INT_MIN NEW_LINE curr_max = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if isPresent ( B , m , A [ i ] ) == True : NEW_LINE INDENT curr_max = 0 NEW_LINE continue NEW_LINE DEDENT curr_max = max ( A [ i ] , curr_max + A [ i ] ) NEW_LINE max_so_far = max ( max_so_far , curr_max ) NEW_LINE DEDENT return max_so_far NEW_LINE DEDENT def findMaxSubarraySum ( A , B , n , m ) : NEW_LINE INDENT maxSubarraySum = findMaxSubarraySumUtil ( A , B , n , m ) NEW_LINE if maxSubarraySum == INT_MIN : NEW_LINE INDENT print ( ' Maximum ▁ Subarray ▁ Sum ▁ cant ▁ be ▁ found ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' The ▁ Maximum ▁ Subarray ▁ Sum ▁ = ' , maxSubarraySum ) NEW_LINE DEDENT DEDENT A = [ 3 , 4 , 5 , - 4 , 6 ] NEW_LINE B = [ 1 , 8 , 5 ] NEW_LINE n = len ( A ) NEW_LINE m = len ( B ) NEW_LINE findMaxSubarraySum ( A , B , n , m ) NEW_LINE " V521,"class GFG { static void findArea ( float a , float b ) { float Area ; Area = ( float ) 3.142 * a * b ; System . out . println ( "" Area : ▁ "" + Area ) ; } public static void main ( String [ ] args ) { float a = 5 , b = 4 ; findArea ( a , b ) ; } } ","def findArea ( a , b ) : NEW_LINE INDENT Area = 3.142 * a * b ; NEW_LINE print ( "" Area : "" , round ( Area , 2 ) ) ; NEW_LINE DEDENT a = 5 ; NEW_LINE b = 4 ; NEW_LINE findArea ( a , b ) ; NEW_LINE " V522,"class GFG { static void perfectSquares ( float l , float r ) { int number = ( int ) Math . ceil ( Math . sqrt ( l ) ) ; int n2 = number * number ; number = ( number * 2 ) + 1 ; while ( ( n2 >= l && n2 <= r ) ) { System . out . print ( n2 + "" ▁ "" ) ; n2 = n2 + number ; number += 2 ; } } public static void main ( String [ ] args ) { int l = 2 , r = 24 ; perfectSquares ( l , r ) ; } } ","from math import ceil , sqrt NEW_LINE def perfectSquares ( l , r ) : NEW_LINE INDENT number = ceil ( sqrt ( l ) ) ; NEW_LINE n2 = number * number ; NEW_LINE number = ( number * 2 ) + 1 ; NEW_LINE while ( ( n2 >= l and n2 <= r ) ) : NEW_LINE INDENT print ( n2 , end = "" ▁ "" ) ; NEW_LINE n2 = n2 + number ; NEW_LINE number += 2 ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT l = 2 ; r = 24 ; NEW_LINE perfectSquares ( l , r ) ; NEW_LINE DEDENT " V523,"import java . io . * ; class GFG { static void printPermutation ( int n , int k ) { int i , mx = n ; for ( i = 1 ; i <= k ; i ++ ) { System . out . print ( mx + "" ▁ "" ) ; mx -- ; } for ( i = 1 ; i <= mx ; i ++ ) System . out . print ( i + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 3 ; if ( K >= N - 1 ) System . out . print ( "" Not ▁ Possible "" ) ; else printPermutation ( N , K ) ; } } ","def printPermutation ( n , k ) : NEW_LINE INDENT mx = n NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT print ( mx , end = "" ▁ "" ) NEW_LINE mx -= 1 NEW_LINE DEDENT for i in range ( 1 , mx + 1 ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N , K = 5 , 3 NEW_LINE if K >= N - 1 : NEW_LINE INDENT print ( "" Not ▁ Possible "" ) NEW_LINE DEDENT else : NEW_LINE INDENT printPermutation ( N , K ) NEW_LINE DEDENT DEDENT " V524,"import java . io . * ; class GFG { public static int countSetBits ( int n ) { if ( n == 0 ) return 0 ; else return 1 + countSetBits ( n & ( n - 1 ) ) ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( countSetBits ( n ) ) ; } } ","def countSetBits ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 + countSetBits ( n & ( n - 1 ) ) NEW_LINE DEDENT DEDENT n = 9 NEW_LINE print ( countSetBits ( n ) ) NEW_LINE " V525,"public class GFG { static void manipulateString ( String str ) { char [ ] str1 = str . toCharArray ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int asc = str1 [ i ] ; int rem = asc - ( 26 - ( str1 [ i ] - 97 ) ) ; int m = rem % 26 ; str1 [ i ] = ( char ) ( m + ' a ' ) ; } String str2 = String . valueOf ( str1 ) ; System . out . println ( str2 ) ; } public static void main ( String [ ] args ) { String str = "" geeksforgeeks "" ; manipulateString ( str ) ; } } ","def manipulateString ( str ) : NEW_LINE INDENT for i in range ( len ( str ) ) : NEW_LINE INDENT asc = ord ( str [ i ] ) NEW_LINE rem = asc - ( 26 - ( ord ( str [ i ] ) - ord ( ' a ' ) ) ) NEW_LINE m = rem % 26 NEW_LINE str [ i ] = chr ( m + ord ( ' a ' ) ) NEW_LINE DEDENT print ( ' ' . join ( str ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str = "" geeksforgeeks "" NEW_LINE str = list ( str ) NEW_LINE manipulateString ( str ) NEW_LINE DEDENT " V526,"class GFG { static boolean arraySortedOrNot ( int arr [ ] , int n ) { if ( n == 0 || n == 1 ) return true ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 20 , 23 , 23 , 45 , 78 , 88 } ; int n = arr . length ; if ( arraySortedOrNot ( arr , n ) ) System . out . print ( "" Yes \n "" ) ; else System . out . print ( "" No \n "" ) ; } } ","def arraySortedOrNot ( arr , n ) : NEW_LINE INDENT if ( n == 0 or n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i - 1 ] > arr [ i ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT arr = [ 20 , 23 , 23 , 45 , 78 , 88 ] NEW_LINE n = len ( arr ) NEW_LINE if ( arraySortedOrNot ( arr , n ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V527,"class GFG { static void cumm ( int [ ] x , int [ ] y , int [ ] cummx , int [ ] cummy , int [ ] cummx2 , int [ ] cummy2 , int n ) { for ( int i = 1 ; i <= n ; i ++ ) { cummx [ i ] = cummx [ i - 1 ] + x [ i ] ; cummy [ i ] = cummy [ i - 1 ] + y [ i ] ; cummx2 [ i ] = cummx2 [ i - 1 ] + x [ i ] * x [ i ] ; cummy2 [ i ] = cummy2 [ i - 1 ] + y [ i ] * y [ i ] ; } } static int calHammeredDistance ( int n , int [ ] x , int [ ] y ) { int [ ] cummx = new int [ n + 1 ] ; int [ ] cummy = new int [ n + 1 ] ; int [ ] cummx2 = new int [ n + 1 ] ; int [ ] cummy2 = new int [ n + 1 ] ; cumm ( x , y , cummx , cummy , cummx2 , cummy2 , n ) ; int hdx = 0 , hdy = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { hdx += ( i - 1 ) * x [ i ] * x [ i ] + cummx2 [ i - 1 ] - 2 * x [ i ] * cummx [ i - 1 ] ; hdy += ( i - 1 ) * y [ i ] * y [ i ] + cummy2 [ i - 1 ] - 2 * y [ i ] * cummy [ i - 1 ] ; } int total = hdx + hdy ; return total ; } public static void main ( String [ ] args ) { int n = 3 ; int [ ] x = new int [ n + 1 ] ; int [ ] y = new int [ n + 1 ] ; x [ 2 ] = 1 ; y [ 0 ] = 1 ; System . out . print ( calHammeredDistance ( n , x , y ) ) ; } } ","def cumm ( x , y , cummx , cummy , cummx2 , cummy2 , n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT cummx [ i ] = cummx [ i - 1 ] + x [ i ] NEW_LINE cummy [ i ] = cummy [ i - 1 ] + y [ i ] NEW_LINE cummx2 [ i ] = cummx2 [ i - 1 ] + x [ i ] * x [ i ] NEW_LINE cummy2 [ i ] = cummy2 [ i - 1 ] + y [ i ] * y [ i ] NEW_LINE DEDENT DEDENT def calHammeredDistance ( n , x , y ) : NEW_LINE INDENT cummx = [ 0 ] * ( n + 1 ) NEW_LINE cummy = [ 0 ] * ( n + 1 ) NEW_LINE cummx2 = [ 0 ] * ( n + 1 ) NEW_LINE cummy2 = [ 0 ] * ( n + 1 ) NEW_LINE cumm ( x , y , cummx , cummy , cummx2 , cummy2 , n ) NEW_LINE hdx , hdy = 0 , 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT hdx += ( ( i - 1 ) * x [ i ] * x [ i ] + cummx2 [ i - 1 ] - 2 * x [ i ] * cummx [ i - 1 ] ) NEW_LINE hdy += ( ( i - 1 ) * y [ i ] * y [ i ] + cummy2 [ i - 1 ] - 2 * y [ i ] * cummy [ i - 1 ] ) NEW_LINE DEDENT total = hdx + hdy NEW_LINE return total NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 3 NEW_LINE x = [ 0 , 0 , 1 , 0 ] NEW_LINE y = [ 1 , 0 , 0 , 0 ] NEW_LINE print ( calHammeredDistance ( n , x , y ) ) NEW_LINE DEDENT " V528,"import java . util . Vector ; class GFG { static Vector < Integer > solve ( int v [ ] ) { Vector < Integer > res = new Vector < Integer > ( ) ; int all3 = v [ 0 ] + v [ 1 ] + v [ 2 ] ; res . add ( all3 - v [ 1 ] * 2 ) ; res . add ( all3 - v [ 2 ] * 2 ) ; res . add ( all3 - v [ 0 ] * 2 ) ; return res ; } static void findVertex ( int xmid [ ] , int ymid [ ] ) { Vector < Integer > V1 = solve ( xmid ) ; Vector < Integer > V2 = solve ( ymid ) ; for ( int i = 0 ; i < 3 ; i ++ ) { System . out . println ( V1 . get ( i ) + "" ▁ "" + V2 . get ( i ) ) ; } } public static void main ( String [ ] args ) { int xmid [ ] = { 5 , 4 , 5 } ; int ymid [ ] = { 3 , 4 , 5 } ; findVertex ( xmid , ymid ) ; } } ","N = 3 NEW_LINE def solve ( v ) : NEW_LINE INDENT res = [ ] NEW_LINE all3 = v [ 0 ] + v [ 1 ] + v [ 2 ] NEW_LINE res . append ( all3 - v [ 1 ] * 2 ) NEW_LINE res . append ( all3 - v [ 2 ] * 2 ) NEW_LINE res . append ( all3 - v [ 0 ] * 2 ) NEW_LINE return res NEW_LINE DEDENT def findVertex ( xmid , ymid ) : NEW_LINE INDENT V1 = solve ( xmid ) NEW_LINE V2 = solve ( ymid ) NEW_LINE for i in range ( 0 , 3 ) : NEW_LINE INDENT print ( V1 [ i ] , end = "" ▁ "" ) NEW_LINE print ( V2 [ i ] ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT xmid = [ 5 , 4 , 5 ] NEW_LINE ymid = [ 3 , 4 , 5 ] NEW_LINE findVertex ( xmid , ymid ) NEW_LINE DEDENT " V529,"import java . util . * ; class GFG { static int countSubString ( char [ ] S , char L [ ] , int n ) { int [ ] freq = new int [ 26 ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { freq [ ( int ) ( L [ i ] - ' a ' ) ] = 1 ; } int count = 0 ; for ( int x : S ) { if ( freq [ ( int ) ( x - ' a ' ) ] > 0 ) { ans += ( count * count + count ) / 2 ; count = 0 ; } else count ++ ; } ans += ( count * count + count ) / 2 ; return ans ; } public static void main ( String [ ] args ) { String S = "" abcpxyz "" ; char L [ ] = { ' a ' , ' p ' , ' q ' } ; int n = L . length ; System . out . print ( countSubString ( S . toCharArray ( ) , L , n ) ) ; } } ","def countSubstring ( S , L , n ) : NEW_LINE INDENT freq = [ 0 for i in range ( 26 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ ( ord ( L [ i ] ) - ord ( ' a ' ) ) ] = 1 NEW_LINE DEDENT count , ans = 0 , 0 NEW_LINE for x in S : NEW_LINE INDENT if ( freq [ ord ( x ) - ord ( ' a ' ) ] ) : NEW_LINE INDENT ans += ( count * count + count ) // 2 NEW_LINE count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT ans += ( count * count + count ) // 2 NEW_LINE return ans NEW_LINE DEDENT S = "" abcpxyz "" NEW_LINE L = [ ' a ' , ' p ' , ' q ' ] NEW_LINE n = len ( L ) NEW_LINE print ( countSubstring ( S , L , n ) ) NEW_LINE " V530,"import java . util . * ; import java . lang . * ; public class GfG { public static int solve ( int low , int high , int T ) { while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( ( mid * ( mid + 1 ) ) == T ) return mid ; if ( mid > 0 && ( mid * ( mid + 1 ) ) > T && ( mid * ( mid - 1 ) ) <= T ) return mid - 1 ; if ( ( mid * ( mid + 1 ) ) > T ) high = mid - 1 ; else low = mid + 1 ; } return - 1 ; } public static void main ( String argc [ ] ) { int T = 15 ; int ans = solve ( 1 , T , 2 * T ) ; if ( ans != - 1 ) ans -- ; System . out . println ( "" Number ▁ of ▁ stair ▁ steps ▁ = ▁ "" + ans ) ; } } ","def solve ( low , high , T ) : NEW_LINE INDENT while low <= high : NEW_LINE INDENT mid = int ( ( low + high ) / 2 ) NEW_LINE if ( mid * ( mid + 1 ) ) == T : NEW_LINE INDENT return mid NEW_LINE DEDENT if ( mid > 0 and ( mid * ( mid + 1 ) ) > T and ( mid * ( mid - 1 ) ) <= T ) : NEW_LINE INDENT return mid - 1 NEW_LINE DEDENT if ( mid * ( mid + 1 ) ) > T : NEW_LINE INDENT high = mid - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT T = 15 NEW_LINE ans = solve ( 1 , T , 2 * T ) NEW_LINE if ans != - 1 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT print ( "" Number ▁ of ▁ stair ▁ steps ▁ = ▁ "" , ans ) NEW_LINE " V531,"import java . io . * ; class GFG { static int findMaxAverage ( int arr [ ] , int n , int k ) { if ( k > n ) return - 1 ; int sum = arr [ 0 ] ; for ( int i = 1 ; i < k ; i ++ ) sum += arr [ i ] ; int max_sum = sum , max_end = k - 1 ; for ( int i = k ; i < n ; i ++ ) { sum = sum + arr [ i ] - arr [ i - k ] ; if ( sum > max_sum ) { max_sum = sum ; max_end = i ; } } return max_end - k + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 12 , - 5 , - 6 , 50 , 3 } ; int k = 4 ; int n = arr . length ; System . out . println ( "" The ▁ maximum ▁ average "" + "" ▁ subarray ▁ of ▁ length ▁ "" + k + "" ▁ begins ▁ at ▁ index ▁ "" + findMaxAverage ( arr , n , k ) ) ; } } ","def findMaxAverage ( arr , n , k ) : NEW_LINE INDENT if ( k > n ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT sum = arr [ 0 ] NEW_LINE for i in range ( 1 , k ) : NEW_LINE INDENT sum += arr [ i ] NEW_LINE DEDENT max_sum = sum NEW_LINE max_end = k - 1 NEW_LINE for i in range ( k , n ) : NEW_LINE INDENT sum = sum + arr [ i ] - arr [ i - k ] NEW_LINE if ( sum > max_sum ) : NEW_LINE INDENT max_sum = sum NEW_LINE max_end = i NEW_LINE DEDENT DEDENT return max_end - k + 1 NEW_LINE DEDENT arr = [ 1 , 12 , - 5 , - 6 , 50 , 3 ] NEW_LINE k = 4 NEW_LINE n = len ( arr ) NEW_LINE print ( "" The ▁ maximum ▁ average ▁ subarray ▁ of ▁ length "" , k , "" begins ▁ at ▁ index "" , findMaxAverage ( arr , n , k ) ) NEW_LINE " V532,"public class GFG { public static float circlearea ( double a , double b ) { if ( a < 0 || b < 0 ) return - 1 ; float A = ( float ) ( ( 3.14 * Math . pow ( a , 2 ) * Math . pow ( b , 2 ) ) / ( 4 * ( Math . pow ( a , 2 ) + Math . pow ( b , 2 ) ) ) ) ; return A ; } public static void main ( String [ ] args ) { float a = 8 , b = 10 ; System . out . println ( circlearea ( a , b ) ) ; } } ","def circlearea ( a , b ) : NEW_LINE INDENT if ( a < 0 or b < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT A = ( ( 3.14 * pow ( a , 2 ) * pow ( b , 2 ) ) / ( 4 * ( pow ( a , 2 ) + pow ( b , 2 ) ) ) ) NEW_LINE return A NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = 8 NEW_LINE b = 10 NEW_LINE print ( circlearea ( a , b ) ) NEW_LINE DEDENT " V533,"class GFG { public static int countDyckPaths ( int n ) { int res = 1 ; for ( int i = 0 ; i < n ; ++ i ) { res *= ( 2 * n - i ) ; res /= ( i + 1 ) ; } return res / ( n + 1 ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( "" Number ▁ of ▁ Dyck ▁ Paths ▁ is ▁ "" + countDyckPaths ( n ) ) ; } } ","def countDyckPaths ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT res *= ( 2 * n - i ) NEW_LINE res /= ( i + 1 ) NEW_LINE DEDENT return res / ( n + 1 ) NEW_LINE DEDENT n = 4 NEW_LINE print ( "" Number ▁ of ▁ Dyck ▁ Paths ▁ is ▁ "" , str ( int ( countDyckPaths ( n ) ) ) ) NEW_LINE " V534,"class GFG { static String multiply ( String num1 , String num2 ) { int len1 = num1 . length ( ) ; int len2 = num2 . length ( ) ; if ( len1 == 0 || len2 == 0 ) return ""0"" ; int result [ ] = new int [ len1 + len2 ] ; int i_n1 = 0 ; int i_n2 = 0 ; for ( int i = len1 - 1 ; i >= 0 ; i -- ) { int carry = 0 ; int n1 = num1 . charAt ( i ) - '0' ; i_n2 = 0 ; for ( int j = len2 - 1 ; j >= 0 ; j -- ) { int n2 = num2 . charAt ( j ) - '0' ; int sum = n1 * n2 + result [ i_n1 + i_n2 ] + carry ; carry = sum / 10 ; result [ i_n1 + i_n2 ] = sum % 10 ; i_n2 ++ ; } if ( carry > 0 ) result [ i_n1 + i_n2 ] += carry ; i_n1 ++ ; } int i = result . length - 1 ; while ( i >= 0 && result [ i ] == 0 ) i -- ; if ( i == - 1 ) return ""0"" ; String s = "" "" ; while ( i >= 0 ) s += ( result [ i -- ] ) ; return s ; } public static void main ( String [ ] args ) { String str1 = ""1235421415454545454545454544"" ; String str2 = ""1714546546546545454544548544544545"" ; if ( ( str1 . charAt ( 0 ) == ' - ' || str2 . charAt ( 0 ) == ' - ' ) && ( str1 . charAt ( 0 ) != ' - ' || str2 . charAt ( 0 ) != ' - ' ) ) System . out . print ( "" - "" ) ; if ( str1 . charAt ( 0 ) == ' - ' && str2 . charAt ( 0 ) != ' - ' ) { str1 = str1 . substring ( 1 ) ; } else if ( str1 . charAt ( 0 ) != ' - ' && str2 . charAt ( 0 ) == ' - ' ) { str2 = str2 . substring ( 1 ) ; } else if ( str1 . charAt ( 0 ) == ' - ' && str2 . charAt ( 0 ) == ' - ' ) { str1 = str1 . substring ( 1 ) ; str2 = str2 . substring ( 1 ) ; } System . out . println ( multiply ( str1 , str2 ) ) ; } } ","def multiply ( num1 , num2 ) : NEW_LINE INDENT len1 = len ( num1 ) NEW_LINE len2 = len ( num2 ) NEW_LINE if len1 == 0 or len2 == 0 : NEW_LINE INDENT return ""0"" NEW_LINE DEDENT result = [ 0 ] * ( len1 + len2 ) NEW_LINE i_n1 = 0 NEW_LINE i_n2 = 0 NEW_LINE for i in range ( len1 - 1 , - 1 , - 1 ) : NEW_LINE INDENT carry = 0 NEW_LINE n1 = ord ( num1 [ i ] ) - 48 NEW_LINE i_n2 = 0 NEW_LINE for j in range ( len2 - 1 , - 1 , - 1 ) : NEW_LINE INDENT n2 = ord ( num2 [ j ] ) - 48 NEW_LINE summ = n1 * n2 + result [ i_n1 + i_n2 ] + carry NEW_LINE carry = summ // 10 NEW_LINE result [ i_n1 + i_n2 ] = summ % 10 NEW_LINE i_n2 += 1 NEW_LINE DEDENT if ( carry > 0 ) : NEW_LINE INDENT result [ i_n1 + i_n2 ] += carry NEW_LINE DEDENT i_n1 += 1 NEW_LINE DEDENT i = len ( result ) - 1 NEW_LINE while ( i >= 0 and result [ i ] == 0 ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT if ( i == - 1 ) : NEW_LINE INDENT return ""0"" NEW_LINE DEDENT s = "" "" NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT s += chr ( result [ i ] + 48 ) NEW_LINE i -= 1 NEW_LINE DEDENT return s NEW_LINE DEDENT str1 = ""1235421415454545454545454544"" NEW_LINE str2 = ""1714546546546545454544548544544545"" NEW_LINE if ( ( str1 [ 0 ] == ' - ' or str2 [ 0 ] == ' - ' ) and ( str1 [ 0 ] != ' - ' or str2 [ 0 ] != ' - ' ) ) : NEW_LINE INDENT print ( "" - "" , end = ' ' ) NEW_LINE DEDENT if ( str1 [ 0 ] == ' - ' and str2 [ 0 ] != ' - ' ) : NEW_LINE INDENT str1 = str1 [ 1 : ] NEW_LINE DEDENT elif ( str1 [ 0 ] != ' - ' and str2 [ 0 ] == ' - ' ) : NEW_LINE INDENT str2 = str2 [ 1 : ] NEW_LINE DEDENT elif ( str1 [ 0 ] == ' - ' and str2 [ 0 ] == ' - ' ) : NEW_LINE INDENT str1 = str1 [ 1 : ] NEW_LINE str2 = str2 [ 1 : ] NEW_LINE DEDENT print ( multiply ( str1 , str2 ) ) NEW_LINE " V535,"class CountMultiples { static int ans [ ] ; static void countSieve ( int arr [ ] , int n ) { int MAX = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) MAX = Math . max ( arr [ i ] , MAX ) ; int cnt [ ] = new int [ MAX + 1 ] ; ans = new int [ MAX + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) ++ cnt [ arr [ i ] ] ; for ( int i = 1 ; i <= MAX ; ++ i ) for ( int j = i ; j <= MAX ; j += i ) ans [ i ] += cnt [ j ] ; return ; } static int countMultiples ( int k ) { return ans [ k ] ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 4 , 9 , 15 , 21 , 20 } ; int n = 6 ; countSieve ( arr , n ) ; int k = 2 ; System . out . println ( countMultiples ( k ) ) ; k = 3 ; System . out . println ( countMultiples ( k ) ) ; k = 5 ; System . out . println ( countMultiples ( k ) ) ; } } ","ans = [ ] NEW_LINE def countSieve ( arr , n ) : NEW_LINE INDENT MAX = max ( arr ) NEW_LINE global ans NEW_LINE ans = [ 0 ] * ( MAX + 1 ) NEW_LINE cnt = [ 0 ] * ( MAX + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT cnt [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in range ( 1 , MAX + 1 ) : NEW_LINE INDENT for j in range ( i , MAX + 1 , i ) : NEW_LINE INDENT ans [ i ] += cnt [ j ] NEW_LINE DEDENT DEDENT DEDENT def countMultiples ( k ) : NEW_LINE INDENT return ( ans [ k ] ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 2 , 4 , 9 , 15 , 21 , 20 ] NEW_LINE n = len ( arr ) NEW_LINE countSieve ( arr , n ) NEW_LINE k = 2 NEW_LINE print ( countMultiples ( 2 ) ) NEW_LINE k = 3 NEW_LINE print ( countMultiples ( 3 ) ) NEW_LINE k = 5 NEW_LINE print ( countMultiples ( 5 ) ) NEW_LINE DEDENT " V536,"import java . io . * ; class GFG { static int number_of_teams ( int M ) { int N1 , N2 , sqr ; sqr = ( int ) Math . sqrt ( 1 + ( 8 * M ) ) ; N1 = ( 1 + sqr ) / 2 ; N2 = ( 1 - sqr ) / 2 ; if ( N1 > 0 ) return N1 ; return N2 ; } public static void main ( String [ ] args ) { int M = 45 ; System . out . println ( number_of_teams ( M ) ) ; } } ","import math NEW_LINE def number_of_teams ( M ) : NEW_LINE INDENT N1 , N2 , sqr = 0 , 0 , 0 NEW_LINE sqr = math . sqrt ( 1 + ( 8 * M ) ) NEW_LINE N1 = ( 1 + sqr ) / 2 NEW_LINE N2 = ( 1 - sqr ) / 2 NEW_LINE if ( N1 > 0 ) : NEW_LINE INDENT return int ( N1 ) NEW_LINE DEDENT return int ( N2 ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT M = 45 NEW_LINE print ( number_of_teams ( M ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V537,"import java . io . * ; class GFG { private static int _popcnt32 ( long number ) { int counter = 0 ; while ( number > 0 ) { if ( number % 2 == 1 ) { counter ++ ; } number = number / 2 ; } return counter ; } static long maximize ( long a ) { int n = _popcnt32 ( a ) ; long res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res = ( int ) res | ( 1 << ( 32 - i ) ) ; return Math . abs ( res ) ; } public static void main ( String args [ ] ) { long a = 1 ; System . out . print ( maximize ( a ) ) ; } } ","def _popcnt32 ( number ) : NEW_LINE INDENT counter = 0 NEW_LINE while ( number > 0 ) : NEW_LINE INDENT if ( number % 2 == 1 ) : NEW_LINE INDENT counter = counter + 1 NEW_LINE DEDENT number = int ( number / 2 ) NEW_LINE DEDENT return counter NEW_LINE DEDENT def maximize ( a ) : NEW_LINE INDENT n = _popcnt32 ( a ) NEW_LINE res = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT res = int ( res | ( 1 << ( 32 - i ) ) ) NEW_LINE DEDENT return abs ( res ) NEW_LINE DEDENT a = 1 NEW_LINE print ( maximize ( a ) ) NEW_LINE " V538,"import java . io . * ; class GFG { static int series ( int n ) { return ( 8 * n * n ) + 1 ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( series ( n ) ) ; } } ","def series ( n ) : NEW_LINE INDENT print ( ( 8 * n ** 2 ) + 1 ) NEW_LINE DEDENT series ( 5 ) NEW_LINE " V539,"import java . util . Collections ; import java . util . Vector ; class GFG { static void sortMultiples ( int arr [ ] , int n , int x ) { Vector < Integer > v = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) { v . add ( arr [ i ] ) ; } } Collections . sort ( v ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) { arr [ i ] = v . get ( j ++ ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 125 , 3 , 15 , 6 , 100 , 5 } ; int x = 5 ; int n = arr . length ; sortMultiples ( arr , n , x ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + "" ▁ "" ) ; } } } ","def sortMultiples ( arr , n , x ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( arr [ i ] % x == 0 ) : NEW_LINE INDENT v . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT v . sort ( reverse = False ) NEW_LINE j = 0 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( arr [ i ] % x == 0 ) : NEW_LINE INDENT arr [ i ] = v [ j ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 125 , 3 , 15 , 6 , 100 , 5 ] NEW_LINE x = 5 NEW_LINE n = len ( arr ) NEW_LINE sortMultiples ( arr , n , x ) NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V540,"import java . io . * ; class GFG { static int power [ ] = new int [ 31 ] ; static int pre [ ] = new int [ 31 ] ; static void PowerOfTwo ( ) { int x = 1 ; for ( int i = 0 ; i < 31 ; i ++ ) { power [ i ] = x ; x *= 2 ; } pre [ 0 ] = 1 ; for ( int i = 1 ; i < 31 ; i ++ ) pre [ i ] = pre [ i - 1 ] + power [ i ] ; } static int Sum ( int n ) { int ans = n * ( n + 1 ) / 2 ; for ( int i = 0 ; i < 31 ; i ++ ) { if ( power [ i ] > n ) { ans -= 2 * pre [ i - 1 ] ; break ; } } return ans ; } public static void main ( String [ ] args ) { PowerOfTwo ( ) ; int n = 4 ; System . out . println ( Sum ( n ) ) ; } } ","power = [ 0 ] * 31 NEW_LINE pre = [ 0 ] * 31 NEW_LINE def PowerOfTwo ( ) : NEW_LINE INDENT x = 1 NEW_LINE for i in range ( 31 ) : NEW_LINE INDENT power [ i ] = x NEW_LINE x *= 2 NEW_LINE DEDENT pre [ 0 ] = 1 NEW_LINE for i in range ( 1 , 31 ) : NEW_LINE INDENT pre [ i ] = pre [ i - 1 ] + power [ i ] NEW_LINE DEDENT DEDENT def Sum ( n ) : NEW_LINE INDENT ans = n * ( n + 1 ) // 2 NEW_LINE for i in range ( 31 ) : NEW_LINE INDENT if ( power [ i ] > n ) : NEW_LINE INDENT ans -= 2 * pre [ i - 1 ] NEW_LINE break NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT PowerOfTwo ( ) NEW_LINE n = 4 NEW_LINE print ( Sum ( n ) ) NEW_LINE DEDENT " V541,"import java . io . * ; class GFG { static boolean DivisibleBy41 ( int first , int second , int c , int n ) { int digit [ ] = new int [ n ] ; digit [ 0 ] = first ; digit [ 1 ] = second ; for ( int i = 2 ; i < n ; i ++ ) digit [ i ] = ( digit [ i - 1 ] * c + digit [ i - 2 ] ) % 10 ; int ans = digit [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) ans = ( ans * 10 + digit [ i ] ) % 41 ; if ( ans % 41 == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int first = 1 , second = 2 , c = 1 , n = 3 ; if ( DivisibleBy41 ( first , second , c , n ) ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def DivisibleBy41 ( first , second , c , n ) : NEW_LINE INDENT digit = [ 0 ] * n NEW_LINE digit [ 0 ] = first NEW_LINE digit [ 1 ] = second NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT digit [ i ] = ( digit [ i - 1 ] * c + digit [ i - 2 ] ) % 10 NEW_LINE DEDENT ans = digit [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT ans = ( ans * 10 + digit [ i ] ) % 41 NEW_LINE DEDENT if ( ans % 41 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT first = 1 NEW_LINE second = 2 NEW_LINE c = 1 NEW_LINE n = 3 NEW_LINE if ( DivisibleBy41 ( first , second , c , n ) ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT " V542,"class GFG { static long mod = 1000000007L ; static long mult ( long a , long b ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; } static long calculate_factors ( long n ) { long ans , cnt ; cnt = 0 ; ans = 1 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { cnt = 0 ; while ( n % i == 0 ) { cnt ++ ; n = n / i ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } } if ( n > 2 ) { ans = mult ( ans , ( 2 ) ) ; } return ans % mod ; } public static void main ( String [ ] args ) { long n = 193748576239475639L ; mod = 17 ; System . out . print ( calculate_factors ( n ) + "" \n "" ) ; } } ","from math import sqrt NEW_LINE mod = 1000000007 NEW_LINE def mult ( a , b ) : NEW_LINE INDENT return ( ( a % mod ) * ( b % mod ) ) % mod NEW_LINE DEDENT def calculate_factors ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE ans = 1 NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT cnt += 1 NEW_LINE n = n // 2 NEW_LINE DEDENT if ( cnt ) : NEW_LINE INDENT ans = mult ( ans , ( cnt + 1 ) ) NEW_LINE DEDENT for i in range ( 3 , int ( sqrt ( n ) ) , 2 ) : NEW_LINE INDENT cnt = 0 NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT cnt += 1 NEW_LINE n = n // i NEW_LINE DEDENT if ( cnt ) : NEW_LINE INDENT ans = mult ( ans , ( cnt + 1 ) ) NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT ans = mult ( ans , 2 ) NEW_LINE DEDENT return ans % mod NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 19374857 NEW_LINE mod = 17 NEW_LINE print ( calculate_factors ( n ) ) NEW_LINE DEDENT " V543,"class GFG { static int MAX = 100 ; static void binomialCoeff ( int n , int C [ ] ) { C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . min ( i , n ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } } static int summation ( int n ) { int C [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) C [ i ] = 0 ; binomialCoeff ( n , C ) ; int sum = 0 ; for ( int i = 0 ; i <= n ; i ++ ) sum += ( i * C [ i ] ) ; return sum ; } public static void main ( String args [ ] ) { int n = 2 ; System . out . println ( summation ( n ) ) ; } } ","MAX = 100 NEW_LINE def binomialCoeff ( n , C ) : NEW_LINE INDENT C [ 0 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , n ) , - 1 , - 1 ) : NEW_LINE INDENT C [ j ] = C [ j ] + C [ j - 1 ] NEW_LINE DEDENT DEDENT DEDENT def summation ( n ) : NEW_LINE INDENT C = [ 0 ] * MAX NEW_LINE binomialCoeff ( n , C ) NEW_LINE sum = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT sum += ( i * C [ i ] ) NEW_LINE DEDENT return sum NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 2 NEW_LINE print ( summation ( n ) ) NEW_LINE DEDENT " V544,"class GFG { static boolean digitWell ( int n , int m , int k ) { int cnt = 0 ; while ( n > 0 ) { if ( n % 10 == m ) ++ cnt ; n /= 10 ; } return cnt == k ; } static int findInt ( int n , int m , int k ) { int i = n + 1 ; while ( true ) { if ( digitWell ( i , m , k ) ) return i ; i ++ ; } } public static void main ( String [ ] args ) { int n = 111 , m = 2 , k = 2 ; System . out . println ( findInt ( n , m , k ) ) ; } } ","def digitWell ( n , m , k ) : NEW_LINE INDENT cnt = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( n % 10 == m ) : NEW_LINE INDENT cnt = cnt + 1 ; NEW_LINE DEDENT n = ( int ) ( n / 10 ) ; NEW_LINE DEDENT return cnt == k ; NEW_LINE DEDENT def findInt ( n , m , k ) : NEW_LINE INDENT i = n + 1 ; NEW_LINE while ( True ) : NEW_LINE INDENT if ( digitWell ( i , m , k ) ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT i = i + 1 ; NEW_LINE DEDENT DEDENT n = 111 ; m = 2 ; k = 2 ; NEW_LINE print ( findInt ( n , m , k ) ) ; NEW_LINE " V545,"import java . util . * ; class GFG { static class Node { int data ; Node next ; } static void printList ( Node node ) { while ( node != null ) { System . out . print ( node . data + "" ▁ "" ) ; node = node . next ; } System . out . println ( ) ; } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } static Node insertBeg ( Node head , int val ) { Node temp = newNode ( val ) ; temp . next = head ; head = temp ; return head ; } static void rearrangeOddEven ( Node head ) { Stack < Node > odd = new Stack < Node > ( ) ; Stack < Node > even = new Stack < Node > ( ) ; int i = 1 ; while ( head != null ) { if ( head . data % 2 != 0 && i % 2 == 0 ) { odd . push ( head ) ; } else if ( head . data % 2 == 0 && i % 2 != 0 ) { even . push ( head ) ; } head = head . next ; i ++ ; } while ( odd . size ( ) > 0 && even . size ( ) > 0 ) { int k = odd . peek ( ) . data ; odd . peek ( ) . data = even . peek ( ) . data ; even . peek ( ) . data = k ; odd . pop ( ) ; even . pop ( ) ; } } public static void main ( String args [ ] ) { Node head = newNode ( 8 ) ; head = insertBeg ( head , 7 ) ; head = insertBeg ( head , 6 ) ; head = insertBeg ( head , 5 ) ; head = insertBeg ( head , 3 ) ; head = insertBeg ( head , 2 ) ; head = insertBeg ( head , 1 ) ; System . out . println ( "" Linked ▁ List : "" ) ; printList ( head ) ; rearrangeOddEven ( head ) ; System . out . println ( "" Linked ▁ List ▁ after ▁ "" + "" Rearranging : "" ) ; printList ( head ) ; } } ","class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = next NEW_LINE DEDENT 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 ( "" \n "" ) NEW_LINE DEDENT def newNode ( key ) : NEW_LINE INDENT temp = Node ( 0 ) NEW_LINE temp . data = key NEW_LINE temp . next = None NEW_LINE return temp NEW_LINE DEDENT def insertBeg ( head , val ) : NEW_LINE INDENT temp = newNode ( val ) NEW_LINE temp . next = head NEW_LINE head = temp NEW_LINE return head NEW_LINE DEDENT def rearrangeOddEven ( head ) : NEW_LINE INDENT odd = [ ] NEW_LINE even = [ ] NEW_LINE i = 1 NEW_LINE while ( head != None ) : NEW_LINE INDENT if ( head . data % 2 != 0 and i % 2 == 0 ) : NEW_LINE INDENT odd . append ( head ) NEW_LINE DEDENT elif ( head . data % 2 == 0 and i % 2 != 0 ) : NEW_LINE INDENT even . append ( head ) NEW_LINE DEDENT head = head . next NEW_LINE i = i + 1 NEW_LINE DEDENT while ( len ( odd ) != 0 and len ( even ) != 0 ) : NEW_LINE INDENT odd [ - 1 ] . data , even [ - 1 ] . data = even [ - 1 ] . data , odd [ - 1 ] . data NEW_LINE odd . pop ( ) NEW_LINE even . pop ( ) NEW_LINE DEDENT return head NEW_LINE DEDENT head = newNode ( 8 ) NEW_LINE head = insertBeg ( head , 7 ) NEW_LINE head = insertBeg ( head , 6 ) NEW_LINE head = insertBeg ( head , 5 ) NEW_LINE head = insertBeg ( head , 3 ) NEW_LINE head = insertBeg ( head , 2 ) NEW_LINE head = insertBeg ( head , 1 ) NEW_LINE print ( "" Linked ▁ List : "" ) NEW_LINE printList ( head ) NEW_LINE rearrangeOddEven ( head ) NEW_LINE print ( "" Linked ▁ List ▁ after ▁ "" , "" Rearranging : "" ) NEW_LINE printList ( head ) NEW_LINE " V546,"import java . lang . * ; import java . io . * ; class GFG { public static void digit_product_Sum ( int N ) { int a [ ] = new int [ N + 1 ] ; int product = 1 ; a [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { product = a [ i - 1 ] / 10 ; if ( product == 0 ) product = 1 ; else product = a [ i - 1 ] % 10 ; int val = a [ i - 1 ] / 10 ; if ( val == 0 ) val = a [ i - 1 ] ; a [ i ] = a [ i - 1 ] + ( val * product ) ; } for ( int i = 0 ; i < N ; i ++ ) System . out . print ( a [ i ] + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int N = 10 ; digit_product_Sum ( N ) ; } } ","def digit_product_Sum ( N ) : NEW_LINE INDENT a = [ 0 ] * ( N + 1 ) ; NEW_LINE product = 1 ; NEW_LINE a [ 0 ] = 1 ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT product = int ( a [ i - 1 ] / 10 ) ; NEW_LINE if ( product == 0 ) : NEW_LINE INDENT product = 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT product = a [ i - 1 ] % 10 ; NEW_LINE DEDENT val = int ( a [ i - 1 ] / 10 ) ; NEW_LINE if ( val == 0 ) : NEW_LINE INDENT val = a [ i - 1 ] ; NEW_LINE DEDENT a [ i ] = a [ i - 1 ] + ( val * product ) ; NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT print ( a [ i ] , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT N = 10 ; NEW_LINE digit_product_Sum ( N ) ; NEW_LINE " V547,"public class GFG { static int SquareCube ( long N ) { int cnt = 0 , i = 1 ; while ( ( int ) ( Math . pow ( i , 6 ) ) <= N ) { ++ cnt ; ++ i ; } return cnt ; } public static void main ( String [ ] args ) { long N = 100000 ; System . out . println ( SquareCube ( N ) ) ; } } ","def SquareCube ( N ) : NEW_LINE INDENT cnt , i = 0 , 1 NEW_LINE while ( i ** 6 <= N ) : NEW_LINE INDENT cnt += 1 NEW_LINE i += 1 NEW_LINE DEDENT return cnt NEW_LINE DEDENT N = 100000 NEW_LINE print ( SquareCube ( N ) ) NEW_LINE " V548,"import java . util . * ; class GFG { static void createHash ( HashSet < Integer > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr < maxElement ) { int temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } static void findFibonacciPair ( int n ) { HashSet < Integer > hash = new HashSet < Integer > ( ) ; createHash ( hash , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . contains ( i ) && hash . contains ( n - i ) ) { System . out . print ( i + "" , ▁ "" + ( n - i ) + "" \n "" ) ; return ; } } System . out . print ( "" - 1 \n "" ) ; } public static void main ( String [ ] args ) { int N = 90 ; findFibonacciPair ( N ) ; } } ","def createHash ( hash1 , maxElement ) : NEW_LINE INDENT prev , curr = 0 , 1 NEW_LINE hash1 . add ( prev ) NEW_LINE hash1 . add ( curr ) NEW_LINE while ( curr < maxElement ) : NEW_LINE INDENT temp = curr + prev NEW_LINE hash1 . add ( temp ) NEW_LINE prev = curr NEW_LINE curr = temp NEW_LINE DEDENT DEDENT def findFibonacciPair ( n ) : NEW_LINE INDENT hash1 = set ( ) NEW_LINE createHash ( hash1 , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i in hash1 and ( n - i ) in hash1 ) : NEW_LINE INDENT print ( i , "" , ▁ "" , ( n - i ) ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( "" - 1"" ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = 90 NEW_LINE findFibonacciPair ( N ) NEW_LINE DEDENT " V549,"import java . util . * ; class GFG { static int Max_Sum ( int a [ ] , int n ) { int [ ] b = new int [ n ] ; int S = 0 ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = res ; res += a [ i ] ; S += a [ i ] ; res = Math . max ( res , - S ) ; } int ans = S ; ans = Math . max ( ans , res ) ; int g = 0 ; for ( int i = n - 1 ; i >= 0 ; -- i ) { g -= a [ i ] ; ans = Math . max ( ans , g + b [ i ] ) ; } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { - 6 , 10 , - 3 , 10 , - 2 } ; int n = a . length ; System . out . println ( "" Maximum ▁ sum ▁ is : ▁ "" + Max_Sum ( a , n ) ) ; } } ","def Max_Sum ( a , n ) : NEW_LINE INDENT b = [ 0 for i in range ( n ) ] NEW_LINE S = 0 NEW_LINE res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT b [ i ] = res NEW_LINE res += a [ i ] NEW_LINE S += a [ i ] NEW_LINE res = max ( res , - S ) NEW_LINE DEDENT ans = S NEW_LINE ans = max ( ans , res ) NEW_LINE g = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT g -= a [ i ] NEW_LINE ans = max ( ans , g + b [ i ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT a = [ - 6 , 10 , - 3 , 10 , - 2 ] NEW_LINE n = len ( a ) NEW_LINE print ( "" Maximum ▁ sum ▁ is : "" , Max_Sum ( a , n ) ) NEW_LINE " V550,"import java . util . * ; class GFG { static int MAX = 100 ; static void permutatedRows ( int mat [ ] [ ] , int m , int n , int r ) { LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ; for ( int j = 0 ; j < n ; j ++ ) s . add ( mat [ r ] [ j ] ) ; for ( int i = 0 ; i < m ; i ++ ) { if ( i == r ) continue ; int j ; for ( j = 0 ; j < n ; j ++ ) if ( ! s . contains ( mat [ i ] [ j ] ) ) break ; if ( j != n ) continue ; System . out . print ( i + "" , ▁ "" ) ; } } public static void main ( String [ ] args ) { int m = 4 , n = 4 , r = 3 ; int mat [ ] [ ] = { { 3 , 1 , 4 , 2 } , { 1 , 6 , 9 , 3 } , { 1 , 2 , 3 , 4 } , { 4 , 3 , 2 , 1 } } ; permutatedRows ( mat , m , n , r ) ; } } ","def permutatedRows ( mat , m , n , r ) : NEW_LINE INDENT s = set ( ) NEW_LINE for j in range ( n ) : NEW_LINE INDENT s . add ( mat [ r ] [ j ] ) NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT if i == r : NEW_LINE INDENT continue NEW_LINE DEDENT for j in range ( n ) : NEW_LINE INDENT if mat [ i ] [ j ] not in s : NEW_LINE INDENT j = j - 2 NEW_LINE break ; NEW_LINE DEDENT DEDENT if j + 1 != n : NEW_LINE INDENT continue NEW_LINE DEDENT print ( i ) NEW_LINE DEDENT DEDENT m = 4 NEW_LINE n = 4 NEW_LINE r = 3 NEW_LINE mat = [ [ 3 , 1 , 4 , 2 ] , [ 1 , 6 , 9 , 3 ] , [ 1 , 2 , 3 , 4 ] , [ 4 , 3 , 2 , 1 ] ] NEW_LINE permutatedRows ( mat , m , n , r ) NEW_LINE " V551,"import java . util . Arrays ; import java . util . Comparator ; class Interval { int start , end ; Interval ( int start , int end ) { this . start = start ; this . end = end ; } } public class MergeOverlappingIntervals { public static void mergeIntervals ( Interval arr [ ] ) { Arrays . sort ( arr , new Comparator < Interval > ( ) { public int compare ( Interval i1 , Interval i2 ) { return i2 . start - i1 . start ; } } ) ; int index = 0 ; for ( int i = 1 ; i < arr . length ; i ++ ) { if ( arr [ index ] . end >= arr [ i ] . start ) { arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ; arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ; } else { arr [ index ] = arr [ i ] ; index ++ ; } } System . out . print ( "" The ▁ Merged ▁ Intervals ▁ are : ▁ "" ) ; for ( int i = 0 ; i <= index ; i ++ ) { System . out . print ( "" [ "" + arr [ i ] . start + "" , "" + arr [ i ] . end + "" ] "" ) ; } } public static void main ( String args [ ] ) { Interval arr [ ] = new Interval [ 4 ] ; arr [ 0 ] = new Interval ( 6 , 8 ) ; arr [ 1 ] = new Interval ( 1 , 9 ) ; arr [ 2 ] = new Interval ( 2 , 4 ) ; arr [ 3 ] = new Interval ( 4 , 7 ) ; mergeIntervals ( arr ) ; } } ","def mergeIntervals ( arr ) : NEW_LINE INDENT arr . sort ( key = lambda x : x [ 0 ] ) NEW_LINE m = [ ] NEW_LINE s = - 10000 NEW_LINE max = - 100000 NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT a = arr [ i ] NEW_LINE if a [ 0 ] > max : NEW_LINE INDENT if i != 0 : NEW_LINE INDENT m . append ( [ s , max ] ) NEW_LINE DEDENT max = a [ 1 ] NEW_LINE s = a [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT if a [ 1 ] >= max : NEW_LINE INDENT max = a [ 1 ] NEW_LINE DEDENT DEDENT DEDENT if max != - 100000 and [ s , max ] not in m : NEW_LINE INDENT m . append ( [ s , max ] ) NEW_LINE DEDENT print ( "" The ▁ Merged ▁ Intervals ▁ are ▁ : "" , end = "" ▁ "" ) NEW_LINE for i in range ( len ( m ) ) : NEW_LINE INDENT print ( m [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT arr = [ [ 6 , 8 ] , [ 1 , 9 ] , [ 2 , 4 ] , [ 4 , 7 ] ] NEW_LINE mergeIntervals ( arr ) NEW_LINE " V552,"import java . io . * ; class GFG { static int MAX = 1000000 ; static boolean prime [ ] = new boolean [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < MAX + 1 ; i ++ ) prime [ i ] = true ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } } static int findDiff ( int arr [ ] , int n ) { int min = MAX + 2 , max = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] == true ) { if ( arr [ i ] > max ) max = arr [ i ] ; if ( arr [ i ] < min ) min = arr [ i ] ; } } return ( max == - 1 ) ? - 1 : ( max - min ) ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int n = 4 ; int arr [ ] = { 1 , 2 , 3 , 5 } ; int res = findDiff ( arr , n ) ; if ( res == - 1 ) System . out . print ( "" No ▁ prime ▁ numbers "" ) ; else System . out . println ( "" Difference ▁ is ▁ "" + res ) ; } } ","MAX = 1000000 NEW_LINE prime = [ True ] * ( MAX + 1 ) NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime [ 1 ] = False NEW_LINE p = 2 NEW_LINE c = 0 NEW_LINE while ( p * p <= MAX ) : NEW_LINE INDENT c += 1 NEW_LINE if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , MAX + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT DEDENT def findDiff ( arr , n ) : NEW_LINE INDENT min = MAX + 2 NEW_LINE max = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( prime [ arr [ i ] ] == True ) : NEW_LINE INDENT if ( arr [ i ] > max ) : NEW_LINE INDENT max = arr [ i ] NEW_LINE DEDENT if ( arr [ i ] < min ) : NEW_LINE INDENT min = arr [ i ] NEW_LINE DEDENT DEDENT DEDENT return - 1 if ( max == - 1 ) else ( max - min ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE n = 4 NEW_LINE arr = [ 1 , 2 , 3 , 5 ] NEW_LINE res = findDiff ( arr , n ) NEW_LINE if ( res == - 1 ) : NEW_LINE INDENT print ( "" No ▁ prime ▁ numbers "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Difference ▁ is ▁ "" , res ) NEW_LINE DEDENT DEDENT " V553,"class GFG { static float find_Area ( float a ) { float R = a * ( float ) ( 2.0 - Math . sqrt ( 2 ) ) ; float area = ( float ) ( ( 3.14 * R * R ) / 2.0 ) ; return area ; } public static void main ( String [ ] args ) { float a = 4 ; System . out . println ( "" ▁ Area ▁ of ▁ semicircle ▁ = ▁ "" + find_Area ( a ) ) ; } } ","from math import sqrt NEW_LINE def find_Area ( a ) : NEW_LINE INDENT R = a * ( 2.0 - sqrt ( 2 ) ) ; NEW_LINE area = 3.14 * R * R / 2.0 ; NEW_LINE return area ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = 4 ; NEW_LINE print ( "" Area ▁ of ▁ semicircle ▁ = "" , find_Area ( a ) ) ; NEW_LINE DEDENT " V554,"class GFG { static long discard_count = 0 ; static long power ( long a , long n ) { if ( n == 0 ) return 1 ; long p = power ( a , n / 2 ) ; p = p * p ; if ( n % 2 == 1 ) p = p * a ; return p ; } static void solve ( int i , int n , float sum , float k , float [ ] a , float [ ] prefix ) { if ( sum > k ) { discard_count += power ( 2 , n - i ) ; return ; } if ( i == n ) return ; float rem = prefix [ n - 1 ] - prefix [ i ] ; if ( sum + a [ i ] + rem > k ) solve ( i + 1 , n , sum + a [ i ] , k , a , prefix ) ; if ( sum + rem > k ) solve ( i + 1 , n , sum , k , a , prefix ) ; } static int countSubsequences ( int [ ] arr , int n , long K ) { float sum = 0.0f ; float k = ( float ) Math . log ( K ) ; float [ ] prefix = new float [ n ] ; float [ ] a = new float [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = ( float ) Math . log ( arr [ i ] ) ; sum += a [ i ] ; } prefix [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; } long total = power ( 2 , n ) - 1 ; if ( sum <= k ) { return ( int ) total ; } solve ( 0 , n , 0.0f , k , a , prefix ) ; return ( int ) ( total - discard_count ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 8 , 7 , 2 } ; int n = arr . length ; long k = 50 ; System . out . print ( countSubsequences ( arr , n , k ) ) ; } } ","from math import log2 NEW_LINE discard_count = 0 NEW_LINE def power ( a , n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT p = power ( a , n // 2 ) NEW_LINE p = p * p NEW_LINE if ( n & 1 ) : NEW_LINE INDENT p = p * a NEW_LINE DEDENT return p NEW_LINE DEDENT def solve ( i , n , sum , k , a , prefix ) : NEW_LINE INDENT global discard_count NEW_LINE if ( sum > k ) : NEW_LINE INDENT discard_count += power ( 2 , n - i ) NEW_LINE return ; NEW_LINE DEDENT if ( i == n ) : NEW_LINE INDENT return NEW_LINE DEDENT rem = prefix [ n - 1 ] - prefix [ i ] NEW_LINE if ( sum + a [ i ] + rem > k ) : NEW_LINE INDENT solve ( i + 1 , n , sum + a [ i ] , k , a , prefix ) NEW_LINE DEDENT if ( sum + rem > k ) : NEW_LINE INDENT solve ( i + 1 , n , sum , k , a , prefix ) NEW_LINE DEDENT DEDENT def countSubsequences ( arr , n , K ) : NEW_LINE INDENT sum = 0.0 NEW_LINE k = log2 ( K ) NEW_LINE prefix = [ 0 ] * n NEW_LINE a = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] = log2 ( arr [ i ] ) NEW_LINE sum += a [ i ] NEW_LINE DEDENT prefix [ 0 ] = a [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT prefix [ i ] = prefix [ i - 1 ] + a [ i ] NEW_LINE DEDENT total = power ( 2 , n ) - 1 NEW_LINE if ( sum <= k ) : NEW_LINE INDENT return total NEW_LINE DEDENT solve ( 0 , n , 0.0 , k , a , prefix ) NEW_LINE return total - discard_count NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 4 , 8 , 7 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE k = 50 ; NEW_LINE print ( countSubsequences ( arr , n , k ) ) NEW_LINE DEDENT " V555,"class GFG { static String tribWord ( int n ) { String Sn_1 = ""1"" ; String Sn_2 = ""12"" ; String Sn_3 = ""1213"" ; String tmp ; for ( int i = 3 ; i <= n ; i ++ ) { tmp = Sn_3 ; Sn_3 += ( Sn_2 + Sn_1 ) ; Sn_1 = Sn_2 ; Sn_2 = tmp ; } return Sn_3 ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . print ( tribWord ( n ) ) ; } } ","def tribWord ( n ) : NEW_LINE INDENT Sn_1 = ""1"" NEW_LINE Sn_2 = ""12"" NEW_LINE Sn_3 = ""1213"" NEW_LINE for i in range ( 3 , n + 1 ) : NEW_LINE INDENT tmp = Sn_3 NEW_LINE Sn_3 += ( Sn_2 + Sn_1 ) NEW_LINE Sn_1 = Sn_2 NEW_LINE Sn_2 = tmp NEW_LINE DEDENT return Sn_3 NEW_LINE DEDENT n = 6 NEW_LINE print ( tribWord ( n ) ) NEW_LINE " V556,"import java . io . * ; public class Interchange { static void interchangeFirstLast ( int m [ ] [ ] ) { int rows = m . length ; for ( int i = 0 ; i < m [ 0 ] . length ; i ++ ) { int t = m [ 0 ] [ i ] ; m [ 0 ] [ i ] = m [ rows - 1 ] [ i ] ; m [ rows - 1 ] [ i ] = t ; } } public static void main ( String args [ ] ) throws IOException { int m [ ] [ ] = { { 8 , 9 , 7 , 6 } , { 4 , 7 , 6 , 5 } , { 3 , 2 , 1 , 8 } , { 9 , 9 , 7 , 7 } } ; interchangeFirstLast ( m ) ; for ( int i = 0 ; i < m . length ; i ++ ) { for ( int j = 0 ; j < m [ 0 ] . length ; j ++ ) System . out . print ( m [ i ] [ j ] + "" ▁ "" ) ; System . out . println ( ) ; } } } ","def interchangeFirstLast ( mat , n , m ) : NEW_LINE INDENT rows = n NEW_LINE for i in range ( n ) : NEW_LINE INDENT t = mat [ 0 ] [ i ] NEW_LINE mat [ 0 ] [ i ] = mat [ rows - 1 ] [ i ] NEW_LINE mat [ rows - 1 ] [ i ] = t NEW_LINE DEDENT DEDENT mat = [ [ 8 , 9 , 7 , 6 ] , [ 4 , 7 , 6 , 5 ] , [ 3 , 2 , 1 , 8 ] , [ 9 , 9 , 7 , 7 ] ] NEW_LINE n = 4 NEW_LINE m = 4 NEW_LINE interchangeFirstLast ( mat , n , m ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT print ( mat [ i ] [ j ] , end = "" ▁ "" ) NEW_LINE DEDENT print ( "" \n "" ) NEW_LINE DEDENT " V557,"import java . util . * ; class GFG { static int minimumValue ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int answer = 0 ; for ( int i = 0 ; i < k ; i ++ ) answer += arr [ i ] * arr [ i ] ; return answer * ( 2 * k - 2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 21 , 5 , 3 , 8 } , k = 3 ; int n = arr . length ; System . out . print ( minimumValue ( arr , n , k ) ) ; } } ","def minimumValue ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE answer = 0 ; NEW_LINE for i in range ( k ) : NEW_LINE INDENT answer += arr [ i ] * arr [ i ] ; NEW_LINE DEDENT return answer * ( 2 * k - 2 ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 21 , 5 , 3 , 8 ] ; NEW_LINE k = 3 ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( minimumValue ( arr , n , k ) ) ; NEW_LINE DEDENT " V558,"import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static float findRadiusOfcircumcircle ( float l , float b ) { if ( l < 0 || b < 0 ) return - 1 ; float radius = ( float ) Math . sqrt ( Math . pow ( l , 2 ) + Math . pow ( b , 2 ) ) / 2 ; return radius ; } public static void main ( String args [ ] ) { float l = 4 , b = 3 ; System . out . println ( findRadiusOfcircumcircle ( l , b ) ) ; } } ","import math NEW_LINE def findRadiusOfcircumcircle ( l , b ) : NEW_LINE INDENT if ( l < 0 or b < 0 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT radius = ( math . sqrt ( pow ( l , 2 ) + pow ( b , 2 ) ) / 2 ) ; NEW_LINE return radius ; NEW_LINE DEDENT l = 4 ; NEW_LINE b = 3 ; NEW_LINE print ( findRadiusOfcircumcircle ( l , b ) ) ; NEW_LINE " V559,"class GFG { static int __gcd ( int a , int b ) { if ( a == 0 || b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return __gcd ( a - b , b ) ; return __gcd ( a , b - a ) ; } static int findValue ( int x , int y , int z ) { int g = __gcd ( y , z ) ; return ( x * g ) / __gcd ( x , g ) ; } public static void main ( String [ ] args ) { int x = 30 , y = 40 , z = 400 ; System . out . print ( findValue ( x , y , z ) ) ; } } ","def __gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 or b == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( a == b ) : NEW_LINE INDENT return a NEW_LINE DEDENT if ( a > b ) : NEW_LINE INDENT return __gcd ( a - b , b ) NEW_LINE DEDENT return __gcd ( a , b - a ) NEW_LINE DEDENT def findValue ( x , y , z ) : NEW_LINE INDENT g = __gcd ( y , z ) NEW_LINE return ( x * g ) / __gcd ( x , g ) NEW_LINE DEDENT x = 30 NEW_LINE y = 40 NEW_LINE z = 400 NEW_LINE print ( "" % d "" % findValue ( x , y , z ) ) NEW_LINE " V560,"import java . io . * ; class GFG { static float area ( float r ) { if ( r < 0 ) return - 1 ; float area = ( float ) ( 3.14 * Math . pow ( r / ( 2 * Math . sqrt ( 2 ) ) , 2 ) ) ; return area ; } public static void main ( String [ ] args ) { float a = 5 ; System . out . println ( area ( a ) ) ; } } ","from math import pow , sqrt NEW_LINE def area ( r ) : NEW_LINE INDENT if ( r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = 3.14 * pow ( r / ( 2 * sqrt ( 2 ) ) , 2 ) ; NEW_LINE return area ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 5 NEW_LINE print ( "" { 0 : . 6 } "" . format ( area ( a ) ) ) NEW_LINE DEDENT " V561,"import java . util . Arrays ; class GFG { static int calculate_min_sum ( int [ ] a , int n ) { Arrays . sort ( a ) ; int min_sum = 0 ; for ( int i = 1 ; i < n ; i += 2 ) { min_sum += Math . abs ( a [ i ] - a [ i - 1 ] ) ; } return min_sum ; } static int calculate_max_sum ( int [ ] a , int n ) { Arrays . sort ( a ) ; int max_sum = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { max_sum += Math . abs ( a [ n - 1 - i ] - a [ i ] ) ; } return max_sum ; } public static void main ( String [ ] args ) { int [ ] a = { 10 , - 10 , 20 , - 40 } ; int n = a . length ; System . out . println ( "" The ▁ minimum ▁ sum ▁ of ▁ pairs ▁ is ▁ "" + calculate_min_sum ( a , n ) ) ; System . out . println ( "" The ▁ maximum ▁ sum ▁ of ▁ pairs ▁ is ▁ "" + calculate_max_sum ( a , n ) ) ; } } ","def calculate_min_sum ( a , n ) : NEW_LINE INDENT a . sort ( ) NEW_LINE min_sum = 0 NEW_LINE for i in range ( 1 , n , 2 ) : NEW_LINE INDENT min_sum += abs ( a [ i ] - a [ i - 1 ] ) NEW_LINE DEDENT return min_sum NEW_LINE DEDENT def calculate_max_sum ( a , n ) : NEW_LINE INDENT a . sort ( ) NEW_LINE max_sum = 0 NEW_LINE for i in range ( n // 2 ) : NEW_LINE INDENT max_sum += abs ( a [ n - 1 - i ] - a [ i ] ) NEW_LINE DEDENT return max_sum NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 10 , - 10 , 20 , - 40 ] NEW_LINE n = len ( a ) NEW_LINE print ( "" The ▁ minimum ▁ sum ▁ of ▁ pairs ▁ is "" , calculate_min_sum ( a , n ) ) NEW_LINE print ( "" The ▁ maximum ▁ sum ▁ of ▁ pairs ▁ is "" , calculate_max_sum ( a , n ) ) NEW_LINE DEDENT " V562,"import java . io . * ; class GFG { static int sumOfDigits ( int n ) { int res = 0 ; while ( n > 0 ) { res += n % 10 ; n /= 10 ; } return res ; } static int findNumber ( int n ) { int i = n - 1 ; while ( i > 0 ) { if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) return i ; i -- ; } return - 1 ; } public static void main ( String [ ] args ) { int n = 824 ; System . out . println ( findNumber ( n ) ) ; } } ","def sumOfDigits ( n ) : NEW_LINE INDENT res = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT res += n % 10 NEW_LINE n /= 10 NEW_LINE DEDENT return res ; NEW_LINE DEDENT def findNumber ( n ) : NEW_LINE INDENT i = n - 1 ; NEW_LINE while ( i > 0 ) : NEW_LINE INDENT if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) : NEW_LINE INDENT return i NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT return - 1 ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 824 ; NEW_LINE print ( findNumber ( n ) ) NEW_LINE DEDENT " V563,"public class GFG { public static int getMaxLength ( int arr [ ] ) { int l = arr . length ; int i = 0 , maxlen = 0 ; while ( i < l ) { int j = i ; while ( i + 1 < l && ( Math . abs ( arr [ i ] - arr [ i + 1 ] ) == 1 || Math . abs ( arr [ i ] - arr [ i + 1 ] ) == 0 ) ) { i ++ ; } int currLen = i - j + 1 ; if ( maxlen < currLen ) maxlen = currLen ; if ( j == i ) i ++ ; } maxlen = ( maxlen == 1 ) ? 0 : maxlen ; return maxlen ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 } ; System . out . print ( getMaxLength ( arr ) ) ; } } ","def getMaxLength ( arr , n ) : NEW_LINE INDENT l = n ; NEW_LINE i = 0 ; maxlen = 0 ; NEW_LINE while ( i < l ) : NEW_LINE INDENT j = i ; NEW_LINE while ( i + 1 < l and ( abs ( arr [ i ] - arr [ i + 1 ] ) == 1 or abs ( arr [ i ] - arr [ i + 1 ] ) == 0 ) ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT currLen = i - j + 1 ; NEW_LINE if ( maxlen < currLen ) : NEW_LINE INDENT maxlen = currLen ; NEW_LINE DEDENT if ( j == i ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT DEDENT return maxlen ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 2 , 4 ] ; NEW_LINE n = len ( arr ) NEW_LINE print ( getMaxLength ( arr , n ) ) ; NEW_LINE DEDENT " V564,"import java . util . * ; public class BinaryTree { Node root ; static class Node { int val ; Node left , right ; Node ( int v ) { val = v ; left = null ; right = null ; } } BinaryTree ( Node r ) { root = r ; } BinaryTree ( ) { } public boolean isSymmetric ( Node root ) { Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root . left ) ; q . add ( root . right ) ; while ( ! q . isEmpty ( ) ) { Node tempLeft = q . remove ( ) ; Node tempRight = q . remove ( ) ; if ( tempLeft == null && tempRight == null ) continue ; if ( ( tempLeft == null && tempRight != null ) || ( tempLeft != null && tempRight == null ) ) return false ; if ( tempLeft . val != tempRight . val ) return 0 ; q . add ( tempLeft . left ) ; q . add ( tempRight . right ) ; q . add ( tempLeft . right ) ; q . add ( tempRight . left ) ; } return true ; } public static void main ( String [ ] args ) { Node n = new Node ( 1 ) ; BinaryTree bt = new BinaryTree ( n ) ; bt . root . left = new Node ( 2 ) ; bt . root . right = new Node ( 2 ) ; bt . root . left . left = new Node ( 3 ) ; bt . root . left . right = new Node ( 4 ) ; bt . root . right . left = new Node ( 4 ) ; bt . root . right . right = new Node ( 3 ) ; if ( bt . isSymmetric ( bt . root ) ) System . out . println ( "" The ▁ given ▁ tree ▁ is ▁ Symmetric "" ) ; else System . out . println ( "" The ▁ given ▁ tree ▁ is ▁ not ▁ Symmetric "" ) ; } } ","class newNode : NEW_LINE INDENT def __init__ ( self , key ) : NEW_LINE INDENT self . key = key NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def isSymmetric ( root ) : NEW_LINE INDENT if ( root == None ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( not root . left and not root . right ) : NEW_LINE INDENT return True NEW_LINE DEDENT q = [ ] NEW_LINE q . append ( root ) NEW_LINE q . append ( root ) NEW_LINE leftNode = 0 NEW_LINE rightNode = 0 NEW_LINE while ( not len ( q ) ) : NEW_LINE INDENT leftNode = q [ 0 ] NEW_LINE q . pop ( 0 ) NEW_LINE rightNode = q [ 0 ] NEW_LINE q . pop ( 0 ) NEW_LINE if ( leftNode . key != rightNode . key ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( leftNode . left and rightNode . right ) : NEW_LINE INDENT q . append ( leftNode . left ) NEW_LINE q . append ( rightNode . right ) NEW_LINE DEDENT elif ( leftNode . left or rightNode . right ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( leftNode . right and rightNode . left ) : NEW_LINE INDENT q . append ( leftNode . right ) NEW_LINE q . append ( rightNode . left ) NEW_LINE DEDENT elif ( leftNode . right or rightNode . left ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = newNode ( 1 ) NEW_LINE root . left = newNode ( 2 ) NEW_LINE root . right = newNode ( 2 ) NEW_LINE root . left . left = newNode ( 3 ) NEW_LINE root . left . right = newNode ( 4 ) NEW_LINE root . right . left = newNode ( 4 ) NEW_LINE root . right . right = newNode ( 3 ) NEW_LINE if ( isSymmetric ( root ) ) : NEW_LINE INDENT print ( "" The ▁ given ▁ tree ▁ is ▁ Symmetric "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" The ▁ given ▁ tree ▁ is ▁ not ▁ Symmetric "" ) NEW_LINE DEDENT DEDENT " V565,"class Squares { public static int numberOfSquares ( int base ) { base = ( base - 2 ) ; base = base / 2 ; return base * ( base + 1 ) / 2 ; } public static void main ( String args [ ] ) { int base = 8 ; System . out . println ( numberOfSquares ( base ) ) ; } } ","def numberOfSquares ( base ) : NEW_LINE INDENT base = ( base - 2 ) NEW_LINE base = base / 2 NEW_LINE return base * ( base + 1 ) / 2 NEW_LINE DEDENT base = 8 NEW_LINE print ( numberOfSquares ( base ) ) NEW_LINE " V566,"import java . io . * ; class GFG { static int modInverse ( int a , int prime ) { a = a % prime ; for ( int x = 1 ; x < prime ; x ++ ) if ( ( a * x ) % prime == 1 ) return x ; return - 1 ; } static void printModIverses ( int n , int prime ) { for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( modInverse ( i , prime ) + "" ▁ "" ) ; } public static void main ( String args [ ] ) { int n = 10 , prime = 17 ; printModIverses ( n , prime ) ; } } ","def modInverse ( a , prime ) : NEW_LINE INDENT a = a % prime NEW_LINE for x in range ( 1 , prime ) : NEW_LINE INDENT if ( ( a * x ) % prime == 1 ) : NEW_LINE INDENT return x NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT def printModIverses ( n , prime ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( modInverse ( i , prime ) , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT n = 10 NEW_LINE prime = 17 NEW_LINE printModIverses ( n , prime ) NEW_LINE " V567,"public class Arc { static double arcLength ( double diameter , double angle ) { double pi = 22.0 / 7.0 ; double arc ; if ( angle >= 360 ) { System . out . println ( "" Angle ▁ cannot "" + "" ▁ be ▁ formed "" ) ; return 0 ; } else { arc = ( pi * diameter ) * ( angle / 360.0 ) ; return arc ; } } public static void main ( String args [ ] ) { double diameter = 25.0 ; double angle = 45.0 ; double arc_len = arcLength ( diameter , angle ) ; System . out . println ( arc_len ) ; } } ","import math NEW_LINE def arcLength ( diameter , angle ) : NEW_LINE INDENT if angle >= 360 : NEW_LINE INDENT print ( "" Angle ▁ cannot ▁ be ▁ formed "" ) NEW_LINE return 0 NEW_LINE DEDENT else : NEW_LINE INDENT arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 ) NEW_LINE return arc NEW_LINE DEDENT DEDENT diameter = 25.0 NEW_LINE angle = 45.0 NEW_LINE arc_len = arcLength ( diameter , angle ) NEW_LINE print ( arc_len ) NEW_LINE " V568,"class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static int countBits ( int n ) { if ( n == 0 ) return 0 ; else return ( ( n & 1 ) == 0 ? 1 : 0 ) + countBits ( n >> 1 ) ; } static int maxGcd ( int n ) { if ( countBits ( n ) == 0 ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return n / i ; } } } else { int val = 0 ; int power = 1 ; int dupn = n ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) { val += power ; } power = power * 2 ; n = n >> 1 ; } return __gcd ( val ^ dupn , val & dupn ) ; } return 1 ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( maxGcd ( n ) ) ; n = 15 ; System . out . println ( maxGcd ( n ) ) ; } } ","from math import gcd , sqrt NEW_LINE def countBits ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( ( n & 1 ) == 0 ) + countBits ( n >> 1 ) ) NEW_LINE DEDENT DEDENT def maxGcd ( n ) : NEW_LINE INDENT if ( countBits ( n ) == 0 ) : NEW_LINE INDENT for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT return int ( n / i ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT val = 0 NEW_LINE power = 1 NEW_LINE dupn = n NEW_LINE while ( n ) : NEW_LINE INDENT if ( ( n & 1 ) == 0 ) : NEW_LINE INDENT val += power NEW_LINE DEDENT power = power * 2 NEW_LINE n = n >> 1 NEW_LINE DEDENT return gcd ( val ^ dupn , val & dupn ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE print ( maxGcd ( n ) ) NEW_LINE n = 15 NEW_LINE print ( maxGcd ( n ) ) NEW_LINE DEDENT " V569,"class GFG { static void findNumberOfDigits ( long n , int base ) { int dig = ( int ) ( Math . floor ( Math . log ( n ) / Math . log ( base ) ) + 1 ) ; System . out . println ( "" The ▁ Number ▁ of ▁ digits ▁ of ▁ Number ▁ "" + n + "" ▁ in ▁ base ▁ "" + base + "" ▁ is ▁ "" + dig ) ; } public static void main ( String [ ] args ) { long n = 1446 ; int base = 7 ; findNumberOfDigits ( n , base ) ; } } ","import math NEW_LINE def findNumberOfDigits ( n , base ) : NEW_LINE INDENT dig = ( math . floor ( math . log ( n ) / math . log ( base ) ) + 1 ) NEW_LINE print ( "" The ▁ Number ▁ of ▁ digits ▁ of "" . format ( n , base , dig ) ) DEDENT n = 1446 NEW_LINE base = 7 NEW_LINE findNumberOfDigits ( n , base ) NEW_LINE " V570,"public class GFG { static final int MAX = 256 ; static String lastNonRepeating ( String str , int n ) { int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) ] ++ ; for ( int i = n - 1 ; i >= 0 ; i -- ) { char ch = str . charAt ( i ) ; if ( freq [ ch ] == 1 ) return ( "" "" + ch ) ; } return "" - 1"" ; } public static void main ( String [ ] args ) { String str = "" GeeksForGeeks "" ; int n = str . length ( ) ; System . out . println ( lastNonRepeating ( str , n ) ) ; } } ","MAX = 256 ; NEW_LINE def lastNonRepeating ( string , n ) : NEW_LINE INDENT freq = [ 0 ] * MAX ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ ord ( string [ i ] ) ] += 1 ; NEW_LINE DEDENT for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT ch = string [ i ] ; NEW_LINE if ( freq [ ord ( ch ) ] == 1 ) : NEW_LINE INDENT return ( "" "" + ch ) ; NEW_LINE DEDENT DEDENT return "" - 1"" ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" GeeksForGeeks "" ; NEW_LINE n = len ( string ) ; NEW_LINE print ( lastNonRepeating ( string , n ) ) ; NEW_LINE DEDENT " V571,"public class GFG { static void diagonalsMinMax ( int [ ] [ ] mat ) { int n = mat . length ; if ( n == 0 ) return ; int principalMin = mat [ 0 ] [ 0 ] , principalMax = mat [ 0 ] [ 0 ] ; int secondaryMin = mat [ n - 1 ] [ 0 ] , secondaryMax = mat [ n - 1 ] [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( mat [ i ] [ i ] < principalMin ) { principalMin = mat [ i ] [ i ] ; } if ( mat [ i ] [ i ] > principalMax ) { principalMax = mat [ i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] < secondaryMin ) { secondaryMin = mat [ n - 1 - i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] > secondaryMax ) { secondaryMax = mat [ n - 1 - i ] [ i ] ; } } System . out . println ( "" Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ ▁ "" + principalMin ) ; System . out . println ( "" Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ "" + principalMax ) ; System . out . println ( "" Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ "" + secondaryMin ) ; System . out . println ( "" Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ "" + secondaryMax ) ; } static public void main ( String [ ] args ) { int [ ] [ ] matrix = { { 1 , 2 , 3 , 4 , - 10 } , { 5 , 6 , 7 , 8 , 6 } , { 1 , 2 , 11 , 3 , 4 } , { 5 , 6 , 70 , 5 , 8 } , { 4 , 9 , 7 , 1 , - 5 } } ; diagonalsMinMax ( matrix ) ; } } ","n = 5 NEW_LINE def diagonalsMinMax ( mat ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT principalMin = mat [ 0 ] [ 0 ] NEW_LINE principalMax = mat [ 0 ] [ 0 ] NEW_LINE secondaryMin = mat [ n - 1 ] [ 0 ] NEW_LINE secondaryMax = mat [ n - 1 ] [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( mat [ i ] [ i ] < principalMin ) : NEW_LINE INDENT principalMin = mat [ i ] [ i ] NEW_LINE DEDENT if ( mat [ i ] [ i ] > principalMax ) : NEW_LINE INDENT principalMax = mat [ i ] [ i ] NEW_LINE DEDENT if ( mat [ n - 1 - i ] [ i ] < secondaryMin ) : NEW_LINE INDENT secondaryMin = mat [ n - 1 - i ] [ i ] NEW_LINE DEDENT if ( mat [ n - 1 - i ] [ i ] > secondaryMax ) : NEW_LINE INDENT secondaryMax = mat [ n - 1 - i ] [ i ] NEW_LINE DEDENT DEDENT print ( "" Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ "" , principalMin ) NEW_LINE print ( "" Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ "" , principalMax ) NEW_LINE print ( "" Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ "" , secondaryMin ) NEW_LINE print ( "" Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ "" , secondaryMax ) NEW_LINE DEDENT matrix = [ [ 1 , 2 , 3 , 4 , - 10 ] , [ 5 , 6 , 7 , 8 , 6 ] , [ 1 , 2 , 11 , 3 , 4 ] , [ 5 , 6 , 70 , 5 , 8 ] , [ 4 , 9 , 7 , 1 , - 5 ] ] NEW_LINE diagonalsMinMax ( matrix ) NEW_LINE " V572,"import java . util . * ; class solution { static long getNthTerm ( long N ) { return ( ( int ) Math . pow ( N , 2 ) + N + 1 ) ; } public static void main ( String arr [ ] ) { long N = 11 ; System . out . println ( getNthTerm ( N ) ) ; } } ","def getNthTerm ( N ) : NEW_LINE INDENT return ( pow ( N , 2 ) + N + 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 11 NEW_LINE print ( getNthTerm ( N ) ) NEW_LINE DEDENT " V573,"class GFG { static int findOddPair ( int A [ ] , int N ) { int oddPair = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] | A [ j ] ) % 2 != 0 ) oddPair ++ ; } } return oddPair ; } public static void main ( String [ ] args ) { int A [ ] = { 5 , 6 , 2 , 8 } ; int N = A . length ; System . out . println ( findOddPair ( A , N ) ) ; } } ","def findOddPair ( A , N ) : NEW_LINE INDENT oddPair = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( ( A [ i ] | A [ j ] ) % 2 != 0 ) : NEW_LINE INDENT oddPair += 1 NEW_LINE DEDENT DEDENT DEDENT return oddPair NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT A = [ 5 , 6 , 2 , 8 ] NEW_LINE N = len ( A ) NEW_LINE print ( findOddPair ( A , N ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V574,"import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void init ( int degree [ ] , pair [ ] edges , int n ) { for ( int i = 0 ; i < n ; i ++ ) { degree [ i ] = 0 ; } for ( int i = 0 ; i < edges . length ; i ++ ) { degree [ edges [ i ] . first ] ++ ; degree [ edges [ i ] . second ] ++ ; } } static void performQueries ( pair [ ] edges , int [ ] q , int n ) { int [ ] degree = new int [ n ] ; init ( degree , edges , n ) ; for ( int i = 0 ; i < q . length ; i ++ ) { int node = q [ i ] ; if ( node == 0 ) { System . out . println ( "" No "" ) ; continue ; } if ( degree [ node ] == 1 ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } public static void main ( String [ ] args ) { int n = 6 ; pair [ ] edges = { new pair ( 0 , 1 ) , new pair ( 0 , 2 ) , new pair ( 1 , 3 ) , new pair ( 1 , 4 ) , new pair ( 4 , 5 ) } ; int [ ] q = { 0 , 3 , 4 , 5 } ; performQueries ( edges , q , n ) ; } } ","def init ( degree , edges , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT degree [ i ] = 0 ; NEW_LINE DEDENT for i in range ( len ( edges ) ) : NEW_LINE INDENT degree [ edges [ i ] [ 0 ] ] += 1 ; NEW_LINE degree [ edges [ i ] [ 1 ] ] += 1 ; NEW_LINE DEDENT DEDENT def performQueries ( edges , q , n ) : NEW_LINE INDENT degree = [ 0 ] * n ; NEW_LINE init ( degree , edges , n ) ; NEW_LINE for i in range ( len ( q ) ) : NEW_LINE INDENT node = q [ i ] ; NEW_LINE if ( node == 0 ) : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE continue ; NEW_LINE DEDENT if ( degree [ node ] == 1 ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 6 ; NEW_LINE edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 4 , 5 ] ] ; NEW_LINE q = [ 0 , 3 , 4 , 5 ] ; NEW_LINE performQueries ( edges , q , n ) ; NEW_LINE DEDENT " V575,"class GFG { static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) { int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ; int i = 0 ; while ( i < n ) { int j = 0 ; if ( i % 2 != 0 ) { while ( ++ j <= W ) { if ( wt [ i ] <= j ) { mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ; } else { mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ; } } } else { while ( ++ j <= W ) { if ( wt [ i ] <= j ) { mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ; } else { mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ; } } } i ++ ; } return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ; } public static void main ( String [ ] args ) { int val [ ] = { 7 , 8 , 4 } , wt [ ] = { 3 , 8 , 6 } , W = 10 , n = 3 ; System . out . println ( KnapSack ( val , wt , n , W ) ) ; } } ","def KnapSack ( val , wt , n , W ) : NEW_LINE INDENT mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ] NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT j = 0 NEW_LINE if i % 2 == 0 : NEW_LINE INDENT while j < W : NEW_LINE INDENT j += 1 NEW_LINE if wt [ i ] <= j : NEW_LINE INDENT mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) NEW_LINE DEDENT else : NEW_LINE INDENT mat [ 1 ] [ j ] = mat [ 0 ] [ j ] NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT while j < W : NEW_LINE INDENT j += 1 NEW_LINE if wt [ i ] <= j : NEW_LINE INDENT mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) NEW_LINE DEDENT else : NEW_LINE INDENT mat [ 0 ] [ j ] = mat [ 1 ] [ j ] NEW_LINE DEDENT DEDENT DEDENT i += 1 NEW_LINE DEDENT if n % 2 == 0 : NEW_LINE INDENT return mat [ 0 ] [ W ] NEW_LINE DEDENT else : NEW_LINE INDENT return mat [ 1 ] [ W ] NEW_LINE DEDENT DEDENT val = [ 7 , 8 , 4 ] NEW_LINE wt = [ 3 , 8 , 6 ] NEW_LINE W = 10 NEW_LINE n = 3 NEW_LINE print ( KnapSack ( val , wt , n , W ) ) NEW_LINE " V576,"class GFG { static int numberOfPaths ( int m , int n ) { if ( m == 1 || n == 1 ) return 1 ; return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ; } public static void main ( String args [ ] ) { System . out . println ( numberOfPaths ( 3 , 3 ) ) ; } } ","def numberOfPaths ( m , n ) : NEW_LINE INDENT if ( m == 1 or n == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) NEW_LINE DEDENT m = 3 NEW_LINE n = 3 NEW_LINE print ( numberOfPaths ( m , n ) ) NEW_LINE " V577,"import java . io . * ; import java . util . * ; class GFG { static int minimumCost ( int cost [ ] , int n ) { int dp [ ] = new int [ n ] ; if ( n == 1 ) return cost [ 0 ] ; dp [ 0 ] = cost [ 0 ] ; dp [ 1 ] = cost [ 1 ] ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) + cost [ i ] ; } return Math . min ( dp [ n - 2 ] , dp [ n - 1 ] ) ; } public static void main ( String args [ ] ) { int a [ ] = { 16 , 19 , 10 , 12 , 18 } ; int n = a . length ; System . out . print ( minimumCost ( a , n ) ) ; } } ","def minimumCost ( cost , n ) : NEW_LINE INDENT dp = [ None ] * n NEW_LINE if n == 1 : NEW_LINE INDENT return cost [ 0 ] NEW_LINE DEDENT dp [ 0 ] = cost [ 0 ] NEW_LINE dp [ 1 ] = cost [ 1 ] NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT dp [ i ] = min ( dp [ i - 1 ] , dp [ i - 2 ] ) + cost [ i ] NEW_LINE DEDENT return min ( dp [ n - 2 ] , dp [ n - 1 ] ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 16 , 19 , 10 , 12 , 18 ] NEW_LINE n = len ( a ) NEW_LINE print ( minimumCost ( a , n ) ) NEW_LINE DEDENT " V578,"public class GFG { static double sum ( int x , int n ) { double total = 1.0 ; double previous = 1.0 ; for ( int i = 1 ; i <= n ; i ++ ) { previous = ( previous * x ) / ( i + 1 ) ; total = total + previous ; } return total ; } public static void main ( String [ ] args ) { int x = 5 , n = 4 ; System . out . print ( "" Sum ▁ is : ▁ "" + sum ( x , n ) ) ; } } ","def sum ( x , n ) : NEW_LINE INDENT total = 1.0 ; NEW_LINE previous = 1.0 ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT previous = ( previous * x ) / ( i + 1 ) ; NEW_LINE total = total + previous ; NEW_LINE DEDENT return total ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 5 ; NEW_LINE n = 4 ; NEW_LINE print ( "" Sum ▁ is : ▁ "" , sum ( x , n ) ) ; NEW_LINE DEDENT " V579,"class Test { static int arr [ ] = new int [ ] { 1 , 2 , 2 , 4 } ; static int countIncreasing ( int n ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ j - 1 ] ) cnt ++ ; else break ; } } return cnt ; } public static void main ( String [ ] args ) { System . out . println ( "" Count ▁ of ▁ strictly ▁ increasing ▁ subarrays ▁ is ▁ "" + countIncreasing ( arr . length ) ) ; } } ","def countIncreasing ( arr , n ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if arr [ j ] > arr [ j - 1 ] : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return cnt NEW_LINE DEDENT arr = [ 1 , 2 , 2 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( "" Count ▁ of ▁ strictly ▁ increasing ▁ subarrays ▁ is "" , countIncreasing ( arr , n ) ) NEW_LINE " V580,"class GFG { static boolean isBinary ( int number ) { while ( number > 0 ) { int digit = number % 10 ; if ( digit > 1 ) return false ; number /= 10 ; } return true ; } public static void main ( String a [ ] ) { int n = 1000111 ; System . out . println ( isBinary ( n ) ) ; } } ","def isBinary ( number ) : NEW_LINE INDENT while ( number > 0 ) : NEW_LINE INDENT digit = number % 10 NEW_LINE if ( digit > 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT number //= 10 NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 1000111 NEW_LINE if ( isBinary ( n ) == 1 ) : NEW_LINE INDENT print ( "" true "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" false "" ) NEW_LINE DEDENT DEDENT " V581,"public class Improve { static boolean isVowel ( char c ) { String vowel = "" aeiou "" ; for ( int i = 0 ; i < vowel . length ( ) ; ++ i ) if ( vowel . charAt ( i ) == c ) return true ; return false ; } static boolean printRLE ( String str , String typed ) { int n = str . length ( ) , m = typed . length ( ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) != typed . charAt ( j ) ) return false ; if ( isVowel ( str . charAt ( i ) ) == false ) { j ++ ; continue ; } int count1 = 1 ; while ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) { count1 ++ ; i ++ ; } int count2 = 1 ; while ( j < m - 1 && typed . charAt ( j ) == str . charAt ( i ) ) { count2 ++ ; j ++ ; } if ( count1 > count2 ) return false ; } return true ; } public static void main ( String args [ ] ) { String name = "" alex "" , typed = "" aaalaeex "" ; if ( printRLE ( name , typed ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isVowel ( c ) : NEW_LINE INDENT vowel = "" aeiou "" NEW_LINE for i in range ( len ( vowel ) ) : NEW_LINE INDENT if ( vowel [ i ] == c ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def printRLE ( str , typed ) : NEW_LINE INDENT n = len ( str ) NEW_LINE m = len ( typed ) NEW_LINE j = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if str [ i ] != typed [ j ] : NEW_LINE INDENT return False NEW_LINE DEDENT if isVowel ( str [ i ] ) == False : NEW_LINE INDENT j = j + 1 NEW_LINE continue NEW_LINE DEDENT count1 = 1 NEW_LINE while ( i < n - 1 and ( str [ i ] == str [ i + 1 ] ) ) : NEW_LINE INDENT count1 = count1 + 1 NEW_LINE i = i + 1 NEW_LINE DEDENT count2 = 1 NEW_LINE while ( j < m - 1 and typed [ j ] == str [ i ] ) : NEW_LINE INDENT count2 = count2 + 1 NEW_LINE j = j + 1 NEW_LINE DEDENT if count1 > count2 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT name = "" alex "" NEW_LINE typed = "" aaalaeex "" NEW_LINE if ( printRLE ( name , typed ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V582,"import java . io . * ; class GFG { static int avg_of_even_num ( int n ) { return n + 1 ; } public static void main ( String [ ] args ) { int n = 8 ; System . out . println ( avg_of_even_num ( n ) ) ; } } ","def avg_of_even_num ( n ) : NEW_LINE INDENT return n + 1 NEW_LINE DEDENT n = 8 NEW_LINE print ( avg_of_even_num ( n ) ) NEW_LINE " V583,"class GFG { static int solve ( int n , int base ) { int result = 0 ; while ( n > 0 ) { int remainder = n % base ; result = result + remainder ; n = n / base ; } return result ; } static void printSumsOfDigits ( int n ) { for ( int base = 2 ; base < n ; ++ base ) System . out . print ( solve ( n , base ) + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int n = 8 ; printSumsOfDigits ( n ) ; } } ","def solve ( n , base ) : NEW_LINE INDENT result = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT remainder = n % base NEW_LINE result = result + remainder NEW_LINE n = int ( n / base ) NEW_LINE DEDENT return result NEW_LINE DEDENT def printSumsOfDigits ( n ) : NEW_LINE INDENT for base in range ( 2 , n ) : NEW_LINE INDENT print ( solve ( n , base ) , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT n = 8 NEW_LINE printSumsOfDigits ( n ) NEW_LINE " V584,"import java . util . * ; class GFG { static void printDiamond ( int n ) { System . out . println ( ) ; int i , j = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i ; j < n ; j ++ ) System . out . print ( "" * "" ) ; for ( j = 0 ; j < 2 * i + 1 ; j ++ ) System . out . print ( "" ▁ "" ) ; for ( j = i ; j < n ; j ++ ) System . out . print ( "" * "" ) ; System . out . println ( ) ; } for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = 0 ; j < i + 2 ; j ++ ) System . out . print ( "" * "" ) ; for ( j = 0 ; j < 2 * ( n - 1 - i ) - 1 ; j ++ ) System . out . print ( "" ▁ "" ) ; for ( j = 0 ; j < i + 2 ; j ++ ) System . out . print ( "" * "" ) ; System . out . println ( ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( "" Inverse ▁ Diamond ▁ Pattern ▁ for ▁ n ▁ = ▁ "" + n ) ; printDiamond ( n ) ; n = 7 ; System . out . println ( "" \n Inverse ▁ Diamond ▁ Pattern ▁ for ▁ n ▁ = ▁ "" + n ) ; printDiamond ( n ) ; } } ","def printDiamond ( n ) : NEW_LINE INDENT print ( "" "" ) NEW_LINE j = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT print ( "" * "" , end = "" "" ) NEW_LINE DEDENT for j in range ( 0 , 2 * i + 1 ) : NEW_LINE INDENT print ( "" ▁ "" , end = "" "" ) NEW_LINE DEDENT for j in range ( i , n ) : NEW_LINE INDENT print ( "" * "" , end = "" "" ) NEW_LINE DEDENT print ( "" "" ) NEW_LINE DEDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT for j in range ( 0 , i + 2 ) : NEW_LINE INDENT print ( "" * "" , end = "" "" ) NEW_LINE DEDENT for j in range ( 0 , 2 * ( n - 1 - i ) - 1 ) : NEW_LINE INDENT print ( "" ▁ "" , end = "" "" ) NEW_LINE DEDENT for j in range ( 0 , i + 2 ) : NEW_LINE INDENT print ( "" * "" , end = "" "" ) NEW_LINE DEDENT print ( "" "" ) NEW_LINE DEDENT print ( "" "" ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( "" Inverse ▁ Diamond ▁ Pattern ▁ for ▁ n ▁ = ▁ "" , n ) NEW_LINE printDiamond ( n ) NEW_LINE n = 7 NEW_LINE print ( "" \n Inverse ▁ Diamond ▁ Pattern ▁ for ▁ n ▁ = ▁ "" , n ) NEW_LINE printDiamond ( n ) NEW_LINE DEDENT " V585,"import java . io . * ; class GFG { static long center_pentadecagonal_num ( long n ) { return ( 15 * n * n - 15 * n + 2 ) / 2 ; } public static void main ( String [ ] args ) { long n = 3 ; System . out . print ( n + "" th ▁ number ▁ : ▁ "" ) ; System . out . println ( center_pentadecagonal_num ( n ) ) ; n = 10 ; System . out . print ( n + "" th ▁ number ▁ : ▁ "" ) ; System . out . println ( center_pentadecagonal_num ( n ) ) ; } } ","def center_pentadecagonal_num ( n ) : NEW_LINE INDENT return ( 15 * n * n - 15 * n + 2 ) // 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( n , "" rd ▁ number ▁ : ▁ "" , center_pentadecagonal_num ( n ) ) NEW_LINE n = 10 NEW_LINE print ( n , "" th ▁ number ▁ : ▁ "" , center_pentadecagonal_num ( n ) ) NEW_LINE DEDENT " V586,"import java . io . * ; class GFG { static int findevenPair ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( A [ i ] % 2 != 0 ) count ++ ; int oddCount = count * ( count - 1 ) / 2 ; return ( N * ( N - 1 ) / 2 ) - oddCount ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 1 , 3 , 2 } ; int n = a . length ; System . out . print ( findevenPair ( a , n ) ) ; } } ","def findevenPair ( A , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT if ( A [ i ] % 2 != 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT oddCount = count * ( count - 1 ) / 2 NEW_LINE return ( int ) ( ( N * ( N - 1 ) / 2 ) - oddCount ) NEW_LINE DEDENT a = [ 5 , 1 , 3 , 2 ] NEW_LINE n = len ( a ) NEW_LINE print ( findevenPair ( a , n ) ) NEW_LINE " V587,"import java . util . * ; class GFG { static int pairCount ( int arr [ ] , int n ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; Vector < Boolean > prime = new Vector < > ( max_val + 1 ) ; for ( int i = 0 ; i < max_val + 1 ; i ++ ) { prime . add ( true ) ; } prime . add ( 0 , Boolean . FALSE ) ; prime . add ( 1 , Boolean . FALSE ) ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime . get ( p ) == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) { prime . add ( i , Boolean . FALSE ) ; } } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime . get ( arr [ i ] ) ) { count ++ ; } } return ( count * ( count - 1 ) ) / 2 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int n = arr . length ; System . out . println ( pairCount ( arr , n ) ) ; } } ","from math import sqrt NEW_LINE def pairCount ( arr , n ) : NEW_LINE INDENT max_val = arr [ 0 ] NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( arr [ i ] > max_val ) : NEW_LINE INDENT max_val = arr [ i ] NEW_LINE DEDENT DEDENT prime = [ True for i in range ( max_val + 1 ) ] NEW_LINE prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE k = int ( sqrt ( max_val ) ) + 1 NEW_LINE for p in range ( 2 , k , 1 ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT count = 0 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( prime [ arr [ i ] ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return ( count * ( count - 1 ) ) / 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( int ( pairCount ( arr , n ) ) ) NEW_LINE DEDENT " V588,"class GFG { static int GIF ( double n ) { return ( int ) Math . floor ( n ) ; } public static void main ( String [ ] args ) { double n = 2.3 ; System . out . println ( GIF ( n ) ) ; } } ","import math NEW_LINE def GIF ( n ) : NEW_LINE INDENT return int ( math . floor ( n ) ) ; NEW_LINE DEDENT n = 2.3 ; NEW_LINE print ( GIF ( n ) ) ; NEW_LINE " V589,"import java . io . * ; class GFG { static int min_element ( int a [ ] ) { int min = Integer . MAX_VALUE , i ; for ( i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] < min ) min = a [ i ] ; } return min ; } static int findSmallest ( int a [ ] , int n ) { int smallest = min_element ( a ) ; for ( int i = 1 ; i < n ; i ++ ) if ( a [ i ] % smallest >= 1 ) return - 1 ; return smallest ; } public static void main ( String args [ ] ) { int a [ ] = { 25 , 20 , 5 , 10 , 100 } ; int n = a . length ; System . out . println ( findSmallest ( a , n ) ) ; } } ","def min_element ( a ) : NEW_LINE INDENT m = 10000000 NEW_LINE for i in range ( 0 , len ( a ) ) : NEW_LINE INDENT if ( a [ i ] < m ) : NEW_LINE INDENT m = a [ i ] NEW_LINE DEDENT DEDENT return m NEW_LINE DEDENT def findSmallest ( a , n ) : NEW_LINE INDENT smallest = min_element ( a ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( a [ i ] % smallest >= 1 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT return smallest NEW_LINE DEDENT a = [ 25 , 20 , 5 , 10 , 100 ] NEW_LINE n = len ( a ) NEW_LINE print ( findSmallest ( a , n ) ) NEW_LINE " V590,"class MatrixChainMultiplication { static int MatrixChainOrder ( int p [ ] , int n ) { int m [ ] [ ] = new int [ n ] [ n ] ; int i , j , k , L , q ; for ( i = 1 ; i < n ; i ++ ) m [ i ] [ i ] = 0 ; for ( L = 2 ; L < n ; L ++ ) { for ( i = 1 ; i < n - L + 1 ; i ++ ) { j = i + L - 1 ; if ( j == n ) continue ; m [ i ] [ j ] = Integer . MAX_VALUE ; for ( k = i ; k <= j - 1 ; k ++ ) { q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ] ; if ( q < m [ i ] [ j ] ) m [ i ] [ j ] = q ; } } } return m [ 1 ] [ n - 1 ] ; } public static void main ( String args [ ] ) { int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 } ; int size = arr . length ; System . out . println ( "" Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ "" + MatrixChainOrder ( arr , size ) ) ; } } ","import sys NEW_LINE def MatrixChainOrder ( p , n ) : NEW_LINE INDENT m = [ [ 0 for x in range ( n ) ] for x in range ( n ) ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT m [ i ] [ i ] = 0 NEW_LINE DEDENT for L in range ( 2 , n ) : NEW_LINE INDENT for i in range ( 1 , n - L + 1 ) : NEW_LINE INDENT j = i + L - 1 NEW_LINE m [ i ] [ j ] = sys . maxint NEW_LINE for k in range ( i , j ) : NEW_LINE INDENT q = m [ i ] [ k ] + m [ k + 1 ] [ j ] + p [ i - 1 ] * p [ k ] * p [ j ] NEW_LINE if q < m [ i ] [ j ] : NEW_LINE INDENT m [ i ] [ j ] = q NEW_LINE DEDENT DEDENT DEDENT DEDENT return m [ 1 ] [ n - 1 ] NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE size = len ( arr ) NEW_LINE print ( "" Minimum ▁ number ▁ of ▁ multiplications ▁ is ▁ "" + str ( MatrixChainOrder ( arr , size ) ) ) NEW_LINE " V591,"class GFG { static int numbers ( int n , int arr [ ] , int m ) { int isZero = 0 , isFive = 0 ; int result = 0 ; if ( m < n ) { return - 1 ; } for ( int i = 0 ; i < m ; i ++ ) { if ( arr [ i ] == 0 ) { isZero = 1 ; } if ( arr [ i ] == 5 ) { isFive = 1 ; } } if ( isZero == 1 && isFive == 1 ) { result = 2 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else if ( isZero == 1 || isFive == 1 ) { result = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { result = result * ( -- m ) ; } } else { result = - 1 ; } return result ; } public static void main ( String [ ] args ) { int n = 3 , m = 6 ; int arr [ ] = { 2 , 3 , 5 , 6 , 7 , 9 } ; System . out . println ( numbers ( n , arr , m ) ) ; } } ","def numbers ( n , arr , m ) : NEW_LINE INDENT isZero = 0 NEW_LINE isFive = 0 NEW_LINE result = 0 NEW_LINE if ( m < n ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT isZero = 1 NEW_LINE DEDENT if ( arr [ i ] == 5 ) : NEW_LINE INDENT isFive = 1 NEW_LINE DEDENT DEDENT if ( isZero and isFive ) : NEW_LINE INDENT result = 2 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT m -= 1 NEW_LINE result = result * ( m ) NEW_LINE DEDENT DEDENT elif ( isZero or isFive ) : NEW_LINE INDENT result = 1 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT m -= 1 NEW_LINE result = result * ( m ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result = - 1 NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 3 NEW_LINE m = 6 NEW_LINE arr = [ 2 , 3 , 5 , 6 , 7 , 9 ] NEW_LINE print ( numbers ( n , arr , m ) ) NEW_LINE DEDENT " V592,"class GFG { static int findMinRemoval ( int arr [ ] , int n ) { int temp , value = 0 ; int maximum = 0 ; if ( n == 1 ) return 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 && i != n - 1 ) { value = value + Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; temp = Math . abs ( arr [ i ] - arr [ i + 1 ] ) + Math . abs ( arr [ i ] - arr [ i - 1 ] ) - Math . abs ( arr [ i - 1 ] - arr [ i + 1 ] ) ; } else if ( i == 0 ) { value = value + Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; temp = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; } else temp = Math . abs ( arr [ i ] - arr [ i - 1 ] ) ; maximum = Math . max ( maximum , temp ) ; } return ( value - maximum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 2 , 10 } ; int n = arr . length ; System . out . print ( findMinRemoval ( arr , n ) + "" \n "" ) ; } } ","def findMinRemoval ( arr , n ) : NEW_LINE INDENT value = 0 NEW_LINE maximum = 0 NEW_LINE if ( n == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( i != 0 and i != n - 1 ) : NEW_LINE INDENT value = value + abs ( arr [ i ] - arr [ i + 1 ] ) NEW_LINE temp = ( abs ( arr [ i ] - arr [ i + 1 ] ) + abs ( arr [ i ] - arr [ i - 1 ] ) - abs ( arr [ i - 1 ] - arr [ i + 1 ] ) ) NEW_LINE DEDENT elif ( i == 0 ) : NEW_LINE INDENT value = value + abs ( arr [ i ] - arr [ i + 1 ] ) NEW_LINE temp = abs ( arr [ i ] - arr [ i + 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT temp = abs ( arr [ i ] - arr [ i - 1 ] ) NEW_LINE DEDENT maximum = max ( maximum , temp ) NEW_LINE DEDENT return ( value - maximum ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 5 , 3 , 2 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMinRemoval ( arr , n ) ) NEW_LINE DEDENT " V593,"class OddOccurrence { static int getOddOccurrence ( int arr [ ] , int arr_size ) { int i ; for ( i = 0 ; i < arr_size ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < arr_size ; j ++ ) { if ( arr [ i ] == arr [ j ] ) count ++ ; } if ( count % 2 != 0 ) return arr [ i ] ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 2 , 3 , 5 , 4 , 5 , 2 , 4 , 3 , 5 , 2 , 4 , 4 , 2 } ; int n = arr . length ; System . out . println ( getOddOccurrence ( arr , n ) ) ; } } ","def getOddOccurrence ( arr , arr_size ) : NEW_LINE INDENT for i in range ( 0 , arr_size ) : NEW_LINE INDENT count = 0 NEW_LINE for j in range ( 0 , arr_size ) : NEW_LINE INDENT if arr [ i ] == arr [ j ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if ( count % 2 != 0 ) : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ 2 , 3 , 5 , 4 , 5 , 2 , 4 , 3 , 5 , 2 , 4 , 4 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( getOddOccurrence ( arr , n ) ) NEW_LINE " V594,"import java . util . * ; class GFG { static void ComputePrefixXor ( int arr [ ] , int PrefixXor [ ] , int n ) { PrefixXor [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; } static int Xor_Sum ( int arr [ ] , int n ) { int [ ] PrefixXor = new int [ n ] ; ComputePrefixXor ( arr , PrefixXor , n ) ; int sum = 0 , index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) { sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; index = i ; } } return index + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 } ; int n = arr . length ; System . out . println ( Xor_Sum ( arr , n ) ) ; } } ","def ComputePrefixXor ( arr , PrefixXor , n ) : NEW_LINE INDENT PrefixXor [ 0 ] = arr [ 0 ] ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; NEW_LINE DEDENT DEDENT def Xor_Sum ( arr , n ) : NEW_LINE INDENT PrefixXor = [ 0 ] * n ; NEW_LINE ComputePrefixXor ( arr , PrefixXor , n ) ; NEW_LINE sum , index = 0 , 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) : NEW_LINE INDENT sum = PrefixXor [ i ] + \ NEW_LINE INDENT ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; NEW_LINE DEDENT index = i ; NEW_LINE DEDENT DEDENT return index + 1 ; NEW_LINE DEDENT arr = [ 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( Xor_Sum ( arr , n ) ) ; NEW_LINE " V595,"class GFG { static int LucasSum ( int N ) { int sum = 0 ; int a = 2 , b = 1 , c ; sum += a ; while ( b <= N ) { sum += b ; c = a + b ; a = b ; b = c ; } return sum ; } public static void main ( String [ ] args ) { int N = 20 ; System . out . println ( LucasSum ( N ) ) ; } } ","def LucasSum ( N ) : NEW_LINE INDENT Sum = 0 NEW_LINE a = 2 NEW_LINE b = 1 NEW_LINE c = 0 NEW_LINE Sum += a NEW_LINE while ( b <= N ) : NEW_LINE INDENT Sum += b NEW_LINE c = a + b NEW_LINE a = b NEW_LINE b = c NEW_LINE DEDENT return Sum NEW_LINE DEDENT N = 20 NEW_LINE print ( LucasSum ( N ) ) NEW_LINE " V596,"import java . io . * ; class GFG { static boolean isPalindrome ( String str ) { int l = 0 ; int h = str . length ( ) - 1 ; while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ; return true ; } static int minRemovals ( String str ) { if ( str . charAt ( 0 ) == '') return 0 ; if ( isPalindrome ( str ) ) return 1 ; return 2 ; } public static void main ( String [ ] args ) { System . out . println ( minRemovals ( ""010010"" ) ) ; System . out . println ( minRemovals ( ""0100101"" ) ) ; } } ","def isPalindrome ( str ) : NEW_LINE INDENT l = 0 NEW_LINE h = len ( str ) - 1 NEW_LINE while ( h > l ) : NEW_LINE INDENT if ( str [ l ] != str [ h ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT l = l + 1 NEW_LINE h = h - 1 NEW_LINE DEDENT return 1 NEW_LINE DEDENT def minRemovals ( str ) : NEW_LINE INDENT if ( str [ 0 ] == ' ' ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( isPalindrome ( str ) ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 2 NEW_LINE DEDENT print ( minRemovals ( ""010010"" ) ) NEW_LINE print ( minRemovals ( ""0100101"" ) ) NEW_LINE " V597,"import java . io . * ; import java . util . * ; import java . math . * ; class GFG { static boolean pronic_check ( int n ) { int x = ( int ) ( Math . sqrt ( n ) ) ; if ( x * ( x + 1 ) == n ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 56 ; if ( pronic_check ( n ) == true ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","import math NEW_LINE def pronic_check ( n ) : NEW_LINE INDENT x = ( int ) ( math . sqrt ( n ) ) NEW_LINE if ( x * ( x + 1 ) == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT n = 56 NEW_LINE if ( pronic_check ( n ) == True ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT " V598,"import java . io . * ; class GFG { static int centered_square_num ( int n ) { return n * n + ( ( n - 1 ) * ( n - 1 ) ) ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . print ( n + "" th ▁ Centered "" + "" ▁ square ▁ number : ▁ "" + centered_square_num ( n ) ) ; } } ","def centered_square_num ( n ) : NEW_LINE INDENT return n * n + ( ( n - 1 ) * ( n - 1 ) ) NEW_LINE DEDENT n = 7 NEW_LINE print ( "" % sth ▁ Centered ▁ square ▁ number : ▁ "" % n , centered_square_num ( n ) ) NEW_LINE " V599,"class GFG { static void solve ( int interval [ ] [ ] , int N , int Q ) { int Mark [ ] = new int [ Q ] ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i ] [ 0 ] - 1 ; int r = interval [ i ] [ 1 ] - 1 ; for ( int j = l ; j <= r ; j ++ ) Mark [ j ] ++ ; } int count = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { if ( Mark [ i ] != 0 ) count ++ ; } int count1 [ ] = new int [ Q ] ; if ( Mark [ 0 ] == 1 ) count1 [ 0 ] = 1 ; for ( int i = 1 ; i < Q ; i ++ ) { if ( Mark [ i ] == 1 ) count1 [ i ] = count1 [ i - 1 ] + 1 ; else count1 [ i ] = count1 [ i - 1 ] ; } int maxindex = 0 ; int maxcoverage = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i ] [ 0 ] - 1 ; int r = interval [ i ] [ 1 ] - 1 ; int elem1 ; if ( l != 0 ) elem1 = count1 [ r ] - count1 [ l - 1 ] ; else elem1 = count1 [ r ] ; if ( count - elem1 >= maxcoverage ) { maxcoverage = count - elem1 ; maxindex = i ; } } System . out . println ( "" Maximum ▁ Coverage ▁ is ▁ "" + maxcoverage + "" ▁ after ▁ removing ▁ interval ▁ at ▁ index ▁ "" + maxindex ) ; } public static void main ( String [ ] args ) { int interval [ ] [ ] = { { 1 , 4 } , { 4 , 5 } , { 5 , 6 } , { 6 , 7 } , { 3 , 5 } } ; int N = interval . length ; int Q = 7 ; solve ( interval , N , Q ) ; } } ","def solve ( interval , N , Q ) : NEW_LINE INDENT Mark = [ 0 for i in range ( Q ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT l = interval [ i ] [ 0 ] - 1 NEW_LINE r = interval [ i ] [ 1 ] - 1 NEW_LINE for j in range ( l , r + 1 ) : NEW_LINE INDENT Mark [ j ] += 1 NEW_LINE DEDENT DEDENT count = 0 NEW_LINE for i in range ( Q ) : NEW_LINE INDENT if ( Mark [ i ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT count1 = [ 0 for i in range ( Q ) ] NEW_LINE if ( Mark [ 0 ] == 1 ) : NEW_LINE INDENT count1 [ 0 ] = 1 NEW_LINE DEDENT for i in range ( 1 , Q ) : NEW_LINE INDENT if ( Mark [ i ] == 1 ) : NEW_LINE INDENT count1 [ i ] = count1 [ i - 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT count1 [ i ] = count1 [ i - 1 ] NEW_LINE DEDENT DEDENT maxindex = 0 NEW_LINE maxcoverage = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT l = interval [ i ] [ 0 ] - 1 NEW_LINE r = interval [ i ] [ 1 ] - 1 NEW_LINE elem1 = 0 NEW_LINE if ( l != 0 ) : NEW_LINE INDENT elem1 = count1 [ r ] - count1 [ l - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT elem1 = count1 [ r ] NEW_LINE DEDENT if ( count - elem1 >= maxcoverage ) : NEW_LINE INDENT maxcoverage = count - elem1 NEW_LINE maxindex = i NEW_LINE DEDENT DEDENT print ( "" Maximum ▁ Coverage ▁ is "" , maxcoverage , "" after ▁ removing ▁ interval ▁ at ▁ index "" , maxindex ) NEW_LINE DEDENT interval = [ [ 1 , 4 ] , [ 4 , 5 ] , [ 5 , 6 ] , [ 6 , 7 ] , [ 3 , 5 ] ] NEW_LINE N = len ( interval ) NEW_LINE Q = 7 NEW_LINE solve ( interval , N , Q ) NEW_LINE " V600,"import java . util . * ; class GFG { static int minIncrementForUnique ( int [ ] A ) { HashMap < Integer , Integer > mpp = new HashMap < Integer , Integer > ( ) ; for ( int i : A ) { if ( mpp . containsKey ( i ) ) mpp . put ( i , mpp . get ( i ) + 1 ) ; else mpp . put ( i , 1 ) ; } Vector < Integer > taken = new Vector < Integer > ( ) ; int ans = 0 ; for ( int x = 0 ; x < 100000 ; x ++ ) { if ( mpp . containsKey ( x ) && mpp . get ( x ) >= 2 ) taken . add ( x * ( mpp . get ( x ) - 1 ) ) ; else if ( taken . size ( ) > 0 && ( ( mpp . containsKey ( x ) && mpp . get ( x ) == 0 ) || ! mpp . containsKey ( x ) ) ) { ans += x - taken . get ( taken . size ( ) - 1 ) ; taken . remove ( taken . size ( ) - 1 ) ; } } return ans ; } public static void main ( String [ ] args ) { int [ ] A = { 3 , 2 , 1 , 2 , 1 , 7 } ; System . out . print ( minIncrementForUnique ( A ) ) ; } } ","import collections NEW_LINE def minIncrementForUnique ( A ) : NEW_LINE INDENT count = collections . Counter ( A ) NEW_LINE taken = [ ] NEW_LINE ans = 0 NEW_LINE for x in range ( 100000 ) : NEW_LINE INDENT if count [ x ] >= 2 : NEW_LINE INDENT taken . extend ( [ x ] * ( count [ x ] - 1 ) ) NEW_LINE DEDENT elif taken and count [ x ] == 0 : NEW_LINE INDENT ans += x - taken . pop ( ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT A = [ 3 , 2 , 1 , 2 , 1 , 7 ] NEW_LINE print ( minIncrementForUnique ( A ) ) NEW_LINE " V601,"class GFG { static int findLargest ( int [ ] arr , int n ) { int gcd = 0 ; for ( int i = 0 ; i < n ; i ++ ) gcd = __gcd ( arr [ i ] , gcd ) ; return gcd ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 9 } ; int n = arr . length ; System . out . print ( findLargest ( arr , n ) ) ; } } ","from math import gcd as __gcd NEW_LINE def findLargest ( arr , n ) : NEW_LINE INDENT gcd = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT gcd = __gcd ( arr [ i ] , gcd ) NEW_LINE DEDENT return gcd NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 6 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findLargest ( arr , n ) ) NEW_LINE DEDENT " V602,"import java . util . * ; class GFG { static boolean isPerfectPower ( int n ) { if ( n == 1 ) { return true ; } for ( int x = 2 ; x <= Math . sqrt ( n ) ; x ++ ) { int y = 2 ; int p = ( int ) Math . pow ( x , y ) ; while ( p <= n && p > 0 ) { if ( p == n ) { return true ; } y ++ ; p = ( int ) Math . pow ( x , y ) ; } } return false ; } static boolean isStrongNumber ( int n ) { HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; while ( n % 2 == 0 ) { n = n / 2 ; if ( count . containsKey ( 2 ) ) { count . put ( 2 , count . get ( 2 ) + 1 ) ; } else { count . put ( 2 , 1 ) ; } } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { n = n / i ; if ( count . containsKey ( i ) ) { count . put ( i , count . get ( i ) + 1 ) ; } else { count . put ( i , 1 ) ; } } } if ( n > 2 ) { if ( count . containsKey ( n ) ) { count . put ( n , count . get ( n ) + 1 ) ; } else { count . put ( n , 1 ) ; } } int flag = 0 ; for ( Map . Entry < Integer , Integer > b : count . entrySet ( ) ) { if ( b . getValue ( ) == 1 ) { flag = 1 ; break ; } } if ( flag == 1 ) { return false ; } else { return true ; } } static boolean isTrojan ( int n ) { if ( ! isPerfectPower ( n ) && isStrongNumber ( n ) ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int n = 108 ; if ( isTrojan ( n ) ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } } ","from math import sqrt , pow NEW_LINE def isPerfectPower ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT for x in range ( 2 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT y = 2 NEW_LINE p = pow ( x , y ) NEW_LINE while ( p <= n and p > 0 ) : NEW_LINE INDENT if ( p == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT y += 1 NEW_LINE p = pow ( x , y ) NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def isStrongNumber ( n ) : NEW_LINE INDENT count = { i : 0 for i in range ( n ) } NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n = int ( n / 2 ) NEW_LINE count [ 2 ] += 1 NEW_LINE DEDENT for i in range ( 3 , int ( sqrt ( n ) ) + 1 , 2 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT n = int ( n / i ) NEW_LINE count [ i ] += 1 NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT count [ n ] += 1 NEW_LINE DEDENT flag = 0 NEW_LINE for ket , value in count . items ( ) : NEW_LINE INDENT if ( value == 1 ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT def isTrojan ( n ) : NEW_LINE INDENT if ( isPerfectPower ( n ) == False and isStrongNumber ( n ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 108 NEW_LINE if ( isTrojan ( n ) ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT DEDENT " V603,"import java . lang . * ; class GFG { public static int binomialCoeff ( int n , int k ) { int [ ] [ ] C = new int [ n + 1 ] [ k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } public static int count ( int n , int k ) { int sum = 0 ; for ( int j = 1 ; j <= k ; j ++ ) { sum = sum + binomialCoeff ( n , j ) ; } return sum ; } public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; int n = 3 , k = 2 ; System . out . print ( count ( n , k ) ) ; int n1 = 5 , k1 = 2 ; System . out . print ( count ( n1 , k1 ) ) ; } } ","def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ] ; NEW_LINE i , j = 0 , 0 ; NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , k ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; NEW_LINE DEDENT DEDENT DEDENT return C [ n ] [ k ] ; NEW_LINE DEDENT def count ( n , k ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for j in range ( 1 , k + 1 ) : NEW_LINE INDENT sum = sum + binomialCoeff ( n , j ) ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 ; NEW_LINE k = 2 ; NEW_LINE print ( count ( n , k ) , end = "" "" ) ; NEW_LINE n1 = 5 ; NEW_LINE k1 = 2 ; NEW_LINE print ( count ( n1 , k1 ) ) ; NEW_LINE DEDENT " V604,"import java . util . TreeMap ; class Count { static int countPairs ( int [ ] a , int n ) { TreeMap < Integer , Integer > map = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { map . put ( a [ i ] , 1 ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( map . get ( a [ i ] ) < 1 ) continue ; int cur = 1 ; while ( cur <= a [ i ] ) cur <<= 1 ; if ( map . containsKey ( cur - a [ i ] ) ) { if ( cur - a [ i ] == a [ i ] && map . get ( a [ i ] ) == 1 ) continue ; count ++ ; map . put ( cur - a [ i ] , map . get ( cur - a [ i ] ) - 1 ) ; map . put ( a [ i ] , map . get ( a [ i ] ) - 1 ) ; } } return count ; } public static void main ( String [ ] args ) { int [ ] a = { 3 , 11 , 14 , 5 , 13 } ; int n = a . length ; System . out . println ( countPairs ( a , n ) ) ; } } ","def countPairs ( a , n ) : NEW_LINE INDENT mp = dict . fromkeys ( a , 0 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ a [ i ] ] += 1 NEW_LINE DEDENT a . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( mp [ a [ i ] ] < 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT cur = 1 NEW_LINE while ( cur <= a [ i ] ) : NEW_LINE INDENT cur = cur << 1 NEW_LINE DEDENT if ( cur - a [ i ] in mp . keys ( ) ) : NEW_LINE INDENT if ( cur - a [ i ] == a [ i ] and mp [ a [ i ] ] == 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT count += 1 NEW_LINE mp [ cur - a [ i ] ] -= 1 NEW_LINE mp [ a [ i ] ] -= 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 3 , 11 , 14 , 5 , 13 ] NEW_LINE n = len ( a ) NEW_LINE print ( countPairs ( a , n ) ) NEW_LINE DEDENT " V605,"public class GFG { static int startingPoint ( int Length , int Speed1 , int Speed2 ) { int result1 = 0 , result2 = 0 ; int time1 = Length / Speed1 ; int time2 = Length / Speed2 ; result1 = __gcd ( time1 , time2 ) ; result2 = time1 * time2 / ( result1 ) ; return result2 ; } static int __gcd ( int a , int b ) { if ( b == 0 ) { return a ; } return __gcd ( b , a % b ) ; } static float firstTime ( int Length , int Speed1 , int Speed2 ) { float result = 0 ; int relativeSpeed = Math . abs ( Speed1 - Speed2 ) ; result = ( ( float ) Length / relativeSpeed ) ; return result ; } public static void main ( String [ ] args ) { int L = 30 , S1 = 5 , S2 = 2 ; float first_Time = firstTime ( L , S1 , S2 ) ; int starting_Point = startingPoint ( L , S1 , S2 ) ; System . out . println ( "" Met ▁ first ▁ time ▁ after ▁ "" + first_Time + "" ▁ hrs "" ) ; System . out . println ( "" Met ▁ at ▁ starting ▁ point ▁ after ▁ "" + starting_Point + "" ▁ hrs "" ) ; } } ","from math import gcd NEW_LINE def startingPoint ( Length , Speed1 , Speed2 ) : NEW_LINE INDENT result1 = 0 NEW_LINE result2 = 0 NEW_LINE time1 = Length // Speed1 NEW_LINE time2 = Length // Speed2 NEW_LINE result1 = gcd ( time1 , time2 ) NEW_LINE result2 = time1 * time2 // ( result1 ) NEW_LINE return result2 NEW_LINE DEDENT def firstTime ( Length , Speed1 , Speed2 ) : NEW_LINE INDENT result = 0 NEW_LINE relativeSpeed = abs ( Speed1 - Speed2 ) NEW_LINE result = Length / relativeSpeed NEW_LINE return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT L = 30 NEW_LINE S1 = 5 NEW_LINE S2 = 2 NEW_LINE first_Time = firstTime ( L , S1 , S2 ) NEW_LINE starting_Point = startingPoint ( L , S1 , S2 ) NEW_LINE print ( "" Met ▁ first ▁ time ▁ after "" , first_Time , "" hrs "" ) NEW_LINE print ( "" Met ▁ at ▁ starting ▁ point ▁ after "" , starting_Point , "" hrs "" ) NEW_LINE DEDENT " V606,"class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } static long findWays ( int n ) { if ( ( n & 1 ) != 0 ) return 0 ; return catalan ( n / 2 ) ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( "" Total ▁ possible ▁ expressions ▁ of ▁ length ▁ "" + n + "" ▁ is ▁ "" + findWays ( 6 ) ) ; } } ","def binomialCoeff ( n , k ) : NEW_LINE INDENT res = 1 ; NEW_LINE if ( k > n - k ) : NEW_LINE INDENT k = n - k ; NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT res *= ( n - i ) ; NEW_LINE res /= ( i + 1 ) ; NEW_LINE DEDENT return int ( res ) ; NEW_LINE DEDENT def catalan ( n ) : NEW_LINE INDENT c = binomialCoeff ( 2 * n , n ) ; NEW_LINE return int ( c / ( n + 1 ) ) ; NEW_LINE DEDENT def findWays ( n ) : NEW_LINE INDENT if ( n & 1 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT return catalan ( int ( n / 2 ) ) ; NEW_LINE DEDENT n = 6 ; NEW_LINE print ( "" Total ▁ possible ▁ expressions ▁ of ▁ length "" , n , "" is "" , findWays ( 6 ) ) ; NEW_LINE " V607,"import java . io . * ; class GFG { static void print_sequence ( int n , int k ) { int b = n / ( k * ( k + 1 ) / 2 ) ; if ( b == 0 ) { System . out . println ( "" - 1"" ) ; } else { int r = 1 ; for ( int x = 1 ; x * x <= n ; x ++ ) { if ( n % x != 0 ) continue ; if ( x <= b && x > r ) r = x ; if ( n / x <= b && n / x > r ) r = n / x ; } for ( int i = 1 ; i < k ; i ++ ) System . out . print ( r * i + "" ▁ "" ) ; int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ; System . out . println ( res ) ; } } public static void main ( String [ ] args ) { int n = 24 ; int k = 4 ; print_sequence ( n , k ) ; n = 24 ; k = 5 ; print_sequence ( n , k ) ; n = 6 ; k = 4 ; print_sequence ( n , k ) ; } } ","def print_sequence ( n , k ) : NEW_LINE INDENT b = int ( n / ( k * ( k + 1 ) / 2 ) ) ; NEW_LINE if b == 0 : NEW_LINE INDENT print ( "" - 1"" ) NEW_LINE DEDENT else : NEW_LINE INDENT r = 1 ; NEW_LINE x = 1 NEW_LINE while x ** 2 <= n : NEW_LINE INDENT if n % x != 0 : NEW_LINE INDENT continue ; NEW_LINE DEDENT elif x <= b and x > r : NEW_LINE INDENT r = x NEW_LINE DEDENT elif n / x <= b and n / x > r : NEW_LINE INDENT r = n / x NEW_LINE DEDENT x = x + 1 NEW_LINE DEDENT i = 1 NEW_LINE while i < k : NEW_LINE INDENT print ( r * i , end = "" ▁ "" ) NEW_LINE i = i + 1 NEW_LINE DEDENT last_term = n - ( r * ( k * ( k - 1 ) / 2 ) ) NEW_LINE print ( last_term ) NEW_LINE DEDENT DEDENT print_sequence ( 24 , 4 ) NEW_LINE print_sequence ( 24 , 5 ) NEW_LINE print_sequence ( 6 , 4 ) NEW_LINE " V608,"import java . io . * ; class GFG { static int maxLen = 10 ; static int dp [ ] = new int [ maxLen ] ; static boolean [ ] visit = new boolean [ maxLen ] ; static int maxSum ( int arr [ ] , int i , int n , int k ) { if ( i >= n ) return 0 ; if ( visit [ i ] ) return dp [ i ] ; visit [ i ] = true ; int tot = 0 ; dp [ i ] = maxSum ( arr , i + 1 , n , k ) ; for ( int j = i ; j < ( i + k ) && ( j < n ) ; j ++ ) { tot += arr [ j ] ; dp [ i ] = Math . max ( dp [ i ] , tot + maxSum ( arr , j + 2 , n , k ) ) ; } return dp [ i ] ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , - 3 , 4 , 5 } ; int k = 2 ; int n = arr . length ; System . out . println ( maxSum ( arr , 0 , n , k ) ) ; } } ","maxLen = 10 NEW_LINE dp = [ 0 ] * maxLen ; NEW_LINE visit = [ 0 ] * maxLen ; NEW_LINE def maxSum ( arr , i , n , k ) : NEW_LINE INDENT if ( i >= n ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( visit [ i ] ) : NEW_LINE INDENT return dp [ i ] ; NEW_LINE DEDENT visit [ i ] = 1 ; NEW_LINE tot = 0 ; NEW_LINE dp [ i ] = maxSum ( arr , i + 1 , n , k ) ; NEW_LINE j = i NEW_LINE while ( j < i + k and j < n ) : NEW_LINE INDENT tot += arr [ j ] ; NEW_LINE dp [ i ] = max ( dp [ i ] , tot + maxSum ( arr , j + 2 , n , k ) ) ; NEW_LINE j += 1 NEW_LINE DEDENT return dp [ i ] ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ - 1 , 2 , - 3 , 4 , 5 ] ; NEW_LINE k = 2 ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( maxSum ( arr , 0 , n , k ) ) ; NEW_LINE DEDENT " V609,"public class GFG { public static void findIndices ( int arr [ ] , int n ) { int leftMin = 0 , rightMin = 0 ; int leftMax = 0 , rightMax = 0 ; int min = arr [ 0 ] , max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < min ) { leftMin = rightMin = i ; min = arr [ i ] ; } else if ( arr [ i ] == min ) rightMin = i ; if ( arr [ i ] > max ) { leftMax = rightMax = i ; max = arr [ i ] ; } else if ( arr [ i ] == max ) rightMax = i ; } System . out . println ( "" Minimum ▁ left ▁ : ▁ "" + leftMin ) ; System . out . println ( "" Minimum ▁ right ▁ : ▁ "" + rightMin ) ; System . out . println ( "" Maximum ▁ left ▁ : ▁ "" + leftMax ) ; System . out . println ( "" Maximum ▁ right ▁ : ▁ "" + rightMax ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 } ; int n = arr . length ; findIndices ( arr , n ) ; } } ","def findIndices ( arr , n ) : NEW_LINE INDENT leftMin , rightMin = 0 , 0 NEW_LINE leftMax , rightMax = 0 , 0 NEW_LINE min_element = arr [ 0 ] NEW_LINE max_element = arr [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] < min_element ) : NEW_LINE INDENT leftMin = rightMin = i NEW_LINE min_element = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] == min_element ) : NEW_LINE INDENT rightMin = i NEW_LINE DEDENT if ( arr [ i ] > max_element ) : NEW_LINE INDENT leftMax = rightMax = i NEW_LINE max_element = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] == max_element ) : NEW_LINE INDENT rightMax = i NEW_LINE DEDENT DEDENT print ( "" Minimum ▁ left ▁ : ▁ "" , leftMin ) NEW_LINE print ( "" Minimum ▁ right ▁ : ▁ "" , rightMin ) NEW_LINE print ( "" Maximum ▁ left ▁ : ▁ "" , leftMax ) NEW_LINE print ( "" Maximum ▁ right ▁ : ▁ "" , rightMax ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE findIndices ( arr , n ) NEW_LINE DEDENT " V610,"class GFG { static final int MAX = 100 ; static boolean search ( int mat [ ] [ ] , int m , int n , int x ) { int i = m - 1 , j = 0 ; while ( i >= 0 && j < n ) { if ( mat [ i ] [ j ] == x ) return true ; if ( mat [ i ] [ j ] > x ) i -- ; else j ++ ; } return false ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 10 , 20 , 30 , 40 } , { 15 , 25 , 35 , 45 } , { 27 , 29 , 37 , 48 } , { 32 , 33 , 39 , 50 } , { 50 , 60 , 70 , 80 } } ; if ( search ( mat , 5 , 4 , 29 ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def search ( mat , m , n , x ) : NEW_LINE INDENT i , j = m - 1 , 0 NEW_LINE while ( i >= 0 and j < n ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == x ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT if ( mat [ i ] [ j ] > x ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT j += 1 NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] , [ 50 , 60 , 70 , 80 ] ] NEW_LINE if ( search ( mat , 5 , 4 , 29 ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V611,"import java . util . Arrays ; class GFG { static int minOperations ( int [ ] arr , int n ) { int maxi , result = 0 ; int [ ] freq = new int [ 1000001 ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; freq [ x ] ++ ; } maxi = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; for ( int i = 1 ; i <= maxi ; i ++ ) { if ( freq [ i ] != 0 ) { for ( int j = i * 2 ; j <= maxi ; j = j + i ) { freq [ j ] = 0 ; } result ++ ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 2 , 4 , 4 , 4 } ; int n = arr . length ; System . out . println ( minOperations ( arr , n ) ) ; } } ","def minOperations ( arr , n ) : NEW_LINE INDENT result = 0 NEW_LINE freq = [ 0 ] * 1000001 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT freq [ arr [ i ] ] += 1 NEW_LINE DEDENT maxi = max ( arr ) NEW_LINE for i in range ( 1 , maxi + 1 ) : NEW_LINE INDENT if freq [ i ] != 0 : NEW_LINE INDENT for j in range ( i * 2 , maxi + 1 , i ) : NEW_LINE INDENT freq [ j ] = 0 NEW_LINE DEDENT result += 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 2 , 4 , 2 , 4 , 4 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minOperations ( arr , n ) ) NEW_LINE DEDENT " V612,"class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void FindRatio ( int a , int b , int c ) { int up = Math . abs ( b - c ) ; int down = Math . abs ( c - a ) ; int g = gcd ( up , down ) ; up /= g ; down /= g ; System . out . println ( up + "" : "" + down ) ; } public static void main ( String [ ] args ) { int a = 4 , b = 10 , c = 6 ; FindRatio ( a , b , c ) ; } } ","from math import gcd NEW_LINE def FindRatio ( a , b , c ) : NEW_LINE INDENT up = abs ( b - c ) NEW_LINE down = abs ( c - a ) NEW_LINE g = gcd ( up , down ) NEW_LINE up //= g NEW_LINE down //= g NEW_LINE print ( up , "" : "" , down ) NEW_LINE DEDENT a = 4 NEW_LINE b = 10 NEW_LINE c = 6 NEW_LINE FindRatio ( a , b , c ) NEW_LINE " V613,"class GFG { static void CalculatePairs ( int a [ ] , int n ) { int cnt_zero = 0 ; int cnt_one = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) cnt_zero += 1 ; else cnt_one += 1 ; } int total_XOR_pairs = cnt_zero * cnt_one ; int total_AND_pairs = ( cnt_one ) * ( cnt_one - 1 ) / 2 ; int total_OR_pairs = cnt_zero * cnt_one + ( cnt_one ) * ( cnt_one - 1 ) / 2 ; System . out . println ( "" cntXOR ▁ = ▁ "" + total_XOR_pairs ) ; System . out . println ( "" cntAND ▁ = ▁ "" + total_AND_pairs ) ; System . out . println ( "" cntOR ▁ = ▁ "" + total_OR_pairs ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 4 , 2 } ; int n = a . length ; CalculatePairs ( a , n ) ; } } ","def CalculatePairs ( a , n ) : NEW_LINE INDENT cnt_zero = 0 NEW_LINE cnt_one = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( a [ i ] % 2 == 0 ) : NEW_LINE INDENT cnt_zero += 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt_one += 1 NEW_LINE DEDENT DEDENT total_XOR_pairs = cnt_zero * cnt_one NEW_LINE total_AND_pairs = ( cnt_one ) * ( cnt_one - 1 ) / 2 NEW_LINE total_OR_pairs = cnt_zero * cnt_one + ( cnt_one ) * ( cnt_one - 1 ) / 2 NEW_LINE print ( "" cntXOR ▁ = ▁ "" , int ( total_XOR_pairs ) ) NEW_LINE print ( "" cntAND ▁ = ▁ "" , int ( total_AND_pairs ) ) NEW_LINE print ( "" cntOR ▁ = ▁ "" , int ( total_OR_pairs ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 1 , 3 , 4 , 2 ] NEW_LINE n = len ( a ) NEW_LINE CalculatePairs ( a , n ) NEW_LINE DEDENT " V614,"import java . util . * ; import java . lang . * ; public class GfG { public static int subset ( int ar [ ] , int n ) { int res = 0 ; Arrays . sort ( ar ) ; for ( int i = 0 ; i < n ; i ++ ) { int count = 1 ; for ( ; i < n - 1 ; i ++ ) { if ( ar [ i ] == ar [ i + 1 ] ) count ++ ; else break ; } res = Math . max ( res , count ) ; } return res ; } public static void main ( String argc [ ] ) { int arr [ ] = { 5 , 6 , 9 , 3 , 4 , 3 , 4 } ; int n = 7 ; System . out . println ( subset ( arr , n ) ) ; } } ","def subset ( ar , n ) : NEW_LINE INDENT res = 0 NEW_LINE ar . sort ( ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT count = 1 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if ar [ i ] == ar [ i + 1 ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT res = max ( res , count ) NEW_LINE DEDENT return res NEW_LINE DEDENT ar = [ 5 , 6 , 9 , 3 , 4 , 3 , 4 ] NEW_LINE n = len ( ar ) NEW_LINE print ( subset ( ar , n ) ) NEW_LINE " V615,"class GFG { static int [ ] pref = new int [ 100010 ] ; static int isPerfectSquare ( int x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ? x : 0 ; } static void compute ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfectSquare ( i ) ; } } static void printSum ( int L , int R ) { int sum = pref [ R ] - pref [ L - 1 ] ; System . out . print ( sum + "" ▁ "" ) ; } public static void main ( String [ ] args ) { compute ( ) ; int Q = 4 ; int arr [ ] [ ] = { { 1 , 10 } , { 1 , 100 } , { 2 , 25 } , { 4 , 50 } } ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } } ","from math import sqrt , floor NEW_LINE pref = [ 0 ] * 100010 ; NEW_LINE def isPerfectSquare ( x ) : NEW_LINE INDENT sr = sqrt ( x ) ; NEW_LINE rslt = x if ( sr - floor ( sr ) == 0 ) else 0 ; NEW_LINE return rslt ; NEW_LINE DEDENT def compute ( ) : NEW_LINE INDENT for i in range ( 1 , 100001 ) : NEW_LINE INDENT pref [ i ] = pref [ i - 1 ] + isPerfectSquare ( i ) ; NEW_LINE DEDENT DEDENT def printSum ( L , R ) : NEW_LINE INDENT sum = pref [ R ] - pref [ L - 1 ] ; NEW_LINE print ( sum , end = "" ▁ "" ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT compute ( ) ; NEW_LINE Q = 4 ; NEW_LINE arr = [ [ 1 , 10 ] , [ 1 , 100 ] , [ 2 , 25 ] , [ 4 , 50 ] ] ; NEW_LINE for i in range ( Q ) : NEW_LINE INDENT printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; NEW_LINE DEDENT DEDENT " V616,"import java . util . * ; class GFG { static boolean isToOneRec ( int n , HashSet < Integer > s ) { if ( n == 1 ) { return true ; } if ( s . contains ( n ) ) { return false ; } return ( n % 2 == 1 ) ? isToOneRec ( 3 * n + 1 , s ) : isToOneRec ( n / 2 , s ) ; } static boolean isToOne ( int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; return isToOneRec ( n , s ) ; } public static void main ( String [ ] args ) { int n = 5 ; if ( isToOne ( n ) ) { System . out . print ( "" Yes "" ) ; } else { System . out . print ( "" No "" ) ; } } } ","def isToOneRec ( n : int , s : set ) -> bool : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return True NEW_LINE DEDENT if n in s : NEW_LINE INDENT return False NEW_LINE DEDENT if n % 2 : NEW_LINE INDENT return isToOneRec ( 3 * n + 1 , s ) NEW_LINE DEDENT else : NEW_LINE INDENT return isToOneRec ( n // 2 , s ) NEW_LINE DEDENT DEDENT def isToOne ( n : int ) -> bool : NEW_LINE INDENT s = set ( ) NEW_LINE return isToOneRec ( n , s ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 5 NEW_LINE if isToOne ( n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V617,"public class GFG { static int ways ( int n ) { int first = 2 ; int second = 3 ; int res = 0 ; for ( int i = 3 ; i <= n ; i ++ ) { res = first + second ; first = second ; second = res ; } return res ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . print ( "" Total ▁ ways ▁ are : ▁ "" + ways ( n ) ) ; } } ","def ways ( n ) : NEW_LINE INDENT first = 2 ; NEW_LINE second = 3 ; NEW_LINE res = 0 ; NEW_LINE for i in range ( 3 , n + 1 ) : NEW_LINE INDENT res = first + second ; NEW_LINE first = second ; NEW_LINE second = res ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT n = 7 ; NEW_LINE print ( "" Total ▁ ways ▁ are : ▁ "" , ways ( n ) ) ; NEW_LINE " V618,"class GFG { static int N = 100 ; static void pre_process ( boolean dp [ ] [ ] , char [ ] s ) { int n = s . length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = false ; } } for ( int j = 1 ; j <= n ; j ++ ) { for ( int i = 0 ; i <= n - j ; i ++ ) { if ( j <= 2 ) { if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = true ; } } else if ( s [ i ] == s [ i + j - 1 ] ) { dp [ i ] [ i + j - 1 ] = dp [ i + 1 ] [ i + j - 2 ] ; } } } } static void answerQuery ( int l , int r , boolean dp [ ] [ ] ) { if ( dp [ l ] [ r ] ) { System . out . println ( "" Yes "" ) ; } else { System . out . println ( "" No "" ) ; } } public static void main ( String [ ] args ) { String s = "" abaaab "" ; boolean [ ] [ ] dp = new boolean [ N ] [ N ] ; pre_process ( dp , s . toCharArray ( ) ) ; int queries [ ] [ ] = { { 0 , 1 } , { 1 , 5 } } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) { answerQuery ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , dp ) ; } } } ","N = 100 NEW_LINE def pre_process ( dp , s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT dp [ i ] [ j ] = False NEW_LINE DEDENT DEDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT for i in range ( n - j + 1 ) : NEW_LINE INDENT if ( j <= 2 ) : NEW_LINE INDENT if ( s [ i ] == s [ i + j - 1 ] ) : NEW_LINE INDENT dp [ i ] [ i + j - 1 ] = True NEW_LINE DEDENT DEDENT elif ( s [ i ] == s [ i + j - 1 ] ) : NEW_LINE INDENT dp [ i ] [ i + j - 1 ] = dp [ i + 1 ] [ i + j - 2 ] NEW_LINE DEDENT DEDENT DEDENT DEDENT def answerQuery ( l , r , dp ) : NEW_LINE INDENT if ( dp [ l ] [ r ] ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT s = "" abaaab "" NEW_LINE dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ] NEW_LINE pre_process ( dp , s ) NEW_LINE queries = [ [ 0 , 1 ] , [ 1 , 5 ] ] NEW_LINE q = len ( queries ) NEW_LINE for i in range ( q ) : NEW_LINE INDENT answerQuery ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , dp ) NEW_LINE DEDENT " V619,"import java . util . * ; class GFG { static int distribution ( int arr [ ] , int n ) { Set < Integer > resources = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) resources . add ( arr [ i ] ) ; return Math . min ( resources . size ( ) , n / 2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 1 , 3 , 4 } ; int n = arr . length ; System . out . print ( distribution ( arr , n ) + "" \n "" ) ; } } ","def distribution ( arr , n ) : NEW_LINE INDENT resources = set ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT resources . add ( arr [ i ] ) ; NEW_LINE DEDENT return min ( len ( resources ) , n // 2 ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 2 , 1 , 3 , 4 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( distribution ( arr , n ) , "" "" ) ; NEW_LINE DEDENT " V620,"class GFG { static int countOdd ( int [ ] arr , int n ) { int odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) odd ++ ; } return odd ; } static int countValidPairs ( int [ ] arr , int n ) { int odd = countOdd ( arr , n ) ; return ( odd * ( odd - 1 ) ) / 2 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( countValidPairs ( arr , n ) ) ; } } ","def countOdd ( arr , n ) : NEW_LINE INDENT odd = 0 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 1 ) : NEW_LINE INDENT odd = odd + 1 ; NEW_LINE DEDENT DEDENT return odd ; NEW_LINE DEDENT def countValidPairs ( arr , n ) : NEW_LINE INDENT odd = countOdd ( arr , n ) ; NEW_LINE return ( odd * ( odd - 1 ) ) / 2 ; NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( int ( countValidPairs ( arr , n ) ) ) ; NEW_LINE " V621,"import java . util . * ; class Solution { static boolean isBinary ( int n ) { while ( n != 0 ) { int temp = n % 10 ; if ( temp != 0 && temp != 1 ) { return false ; } n = n / 10 ; } return true ; } static void formBinaryStr ( int n , int a [ ] ) { boolean flag = true ; String s = "" "" ; for ( int i = 0 ; i < n ; i ++ ) { if ( isBinary ( a [ i ] ) ) s += "" "" + a [ i ] ; else { flag = false ; break ; } } if ( flag ) System . out . print ( s + "" \n "" ) ; else System . out . print ( "" - 1 \n "" ) ; } public static void main ( String args [ ] ) { int a [ ] = { 10 , 1 , 0 , 11 , 10 } ; int N = a . length ; formBinaryStr ( N , a ) ; } } ","def isBinary ( n ) : NEW_LINE INDENT while n != 0 : NEW_LINE INDENT temp = n % 10 NEW_LINE if temp != 0 and temp != 1 : NEW_LINE INDENT return False NEW_LINE DEDENT n = n // 10 NEW_LINE DEDENT return True NEW_LINE DEDENT def formBinaryStr ( n , a ) : NEW_LINE INDENT flag = True NEW_LINE s = "" "" NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if isBinary ( a [ i ] ) == True : NEW_LINE INDENT s += str ( a [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag == True : NEW_LINE INDENT print ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT cout << "" - 1 \n "" NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 10 , 1 , 0 , 11 , 10 ] NEW_LINE N = len ( a ) NEW_LINE formBinaryStr ( N , a ) NEW_LINE DEDENT " V622,"class GFG { static void bonacciseries ( int n , int m ) { int a [ ] = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) a [ i ] = 0 ; a [ n - 1 ] = 1 ; a [ n ] = 1 ; for ( int i = n + 1 ; i < m ; i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ; for ( int i = 0 ; i < m ; i ++ ) System . out . print ( a [ i ] + "" ▁ "" ) ; } public static void main ( String args [ ] ) { int N = 5 , M = 15 ; bonacciseries ( N , M ) ; } } ","def bonacciseries ( n , m ) : NEW_LINE INDENT a = [ 0 for i in range ( m ) ] NEW_LINE a [ n - 1 ] = 1 NEW_LINE a [ n ] = 1 NEW_LINE for i in range ( n + 1 , m ) : NEW_LINE INDENT a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] NEW_LINE DEDENT for i in range ( 0 , m ) : NEW_LINE INDENT print ( a [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N , M = 5 , 15 NEW_LINE bonacciseries ( N , M ) NEW_LINE DEDENT " V623,"class GFG { static int countPairs ( int arr [ ] , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] != arr [ j ] ) cnt ++ ; } } return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } } ","def countPairs ( arr , n ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( arr [ i ] != arr [ j ] ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT DEDENT DEDENT return cnt ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 2 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( countPairs ( arr , n ) ) ; NEW_LINE DEDENT " V624,"import java . util . * ; class GFG { static void generate ( Set < String > st , String s ) { if ( s . length ( ) == 0 ) { return ; } if ( ! st . contains ( s ) ) { st . add ( s ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String t = s ; t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ; generate ( st , t ) ; } } return ; } public static void main ( String args [ ] ) { String s = "" xyz "" ; TreeSet < String > st = new TreeSet < > ( ) ; generate ( st , s ) ; for ( String str : st ) { System . out . println ( str ) ; } } } ","def generate ( st , s ) : NEW_LINE INDENT if len ( s ) == 0 : NEW_LINE INDENT return NEW_LINE DEDENT if s not in st : NEW_LINE INDENT st . add ( s ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT t = list ( s ) . copy ( ) NEW_LINE t . remove ( s [ i ] ) NEW_LINE t = ' ' . join ( t ) NEW_LINE generate ( st , t ) NEW_LINE DEDENT DEDENT return NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" xyz "" NEW_LINE st = set ( ) NEW_LINE generate ( st , s ) NEW_LINE for i in st : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT DEDENT " V625,"class GFG { static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) { int i , w ; int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) { for ( w = 0 ; w <= W ; w ++ ) { if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ; else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ; else K [ i ] [ w ] = K [ i - 1 ] [ w ] ; } } int res = K [ n ] [ W ] ; System . out . println ( res ) ; w = W ; for ( i = n ; i > 0 && res > 0 ; i -- ) { if ( res == K [ i - 1 ] [ w ] ) continue ; else { System . out . print ( wt [ i - 1 ] + "" ▁ "" ) ; res = res - val [ i - 1 ] ; w = w - wt [ i - 1 ] ; } } } public static void main ( String arg [ ] ) { int val [ ] = { 60 , 100 , 120 } ; int wt [ ] = { 10 , 20 , 30 } ; int W = 50 ; int n = val . length ; printknapSack ( W , wt , val , n ) ; } } ","def printknapSack ( W , wt , val , n ) : NEW_LINE INDENT K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for w in range ( W + 1 ) : NEW_LINE INDENT if i == 0 or w == 0 : NEW_LINE INDENT K [ i ] [ w ] = 0 NEW_LINE DEDENT elif wt [ i - 1 ] <= w : NEW_LINE INDENT K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) NEW_LINE DEDENT else : NEW_LINE INDENT K [ i ] [ w ] = K [ i - 1 ] [ w ] NEW_LINE DEDENT DEDENT DEDENT res = K [ n ] [ W ] NEW_LINE print ( res ) NEW_LINE w = W NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT if res <= 0 : NEW_LINE INDENT break NEW_LINE DEDENT if res == K [ i - 1 ] [ w ] : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( wt [ i - 1 ] ) NEW_LINE res = res - val [ i - 1 ] NEW_LINE w = w - wt [ i - 1 ] NEW_LINE DEDENT DEDENT DEDENT val = [ 60 , 100 , 120 ] NEW_LINE wt = [ 10 , 20 , 30 ] NEW_LINE W = 50 NEW_LINE n = len ( val ) NEW_LINE printknapSack ( W , wt , val , n ) NEW_LINE " V626,"import java . util . * ; class GFG { static int findSum ( int arr [ ] , int n ) { int sum = 0 ; HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! s . contains ( arr [ i ] ) ) { sum += arr [ i ] ; s . add ( arr [ i ] ) ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 } ; int n = arr . length ; System . out . println ( findSum ( arr , n ) ) ; } } ","def findSum ( arr , n ) : NEW_LINE INDENT s = set ( ) NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] not in s : NEW_LINE INDENT s . add ( arr [ i ] ) NEW_LINE DEDENT DEDENT for i in s : NEW_LINE INDENT sum = sum + i NEW_LINE DEDENT return sum NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findSum ( arr , n ) ) NEW_LINE " V627,"class GFG { static int sumOfDigit ( int n , int b ) { int unitDigit , sum = 0 ; while ( n > 0 ) { unitDigit = n % b ; sum += unitDigit ; n = n / b ; } return sum ; } public static void main ( String [ ] args ) { int n = 50 ; int b = 2 ; System . out . print ( sumOfDigit ( n , b ) ) ; } } ","def sumOfDigit ( n , b ) : NEW_LINE INDENT unitDigit = 0 NEW_LINE sum = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT unitDigit = n % b NEW_LINE sum += unitDigit NEW_LINE n = n // b NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 50 NEW_LINE b = 2 NEW_LINE print ( sumOfDigit ( n , b ) ) NEW_LINE " V628,"import java . io . * ; class GFG { static int minflip ( int [ ] arr1 , int [ ] arr2 , int [ ] arr3 , int p , int q , int n ) { int flip = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] > 0 ^ arr2 [ i ] > 0 != arr3 [ i ] > 0 ) flip ++ ; return ( flip <= p + q ) ? flip : - 1 ; } static public void main ( String [ ] args ) { int [ ] arr1 = { 1 , 0 , 1 , 1 , 1 , 1 , 1 } ; int [ ] arr2 = { 0 , 1 , 1 , 1 , 1 , 0 , 0 } ; int [ ] arr3 = { 1 , 1 , 1 , 1 , 0 , 0 , 1 } ; int n = arr1 . length ; int p = 2 , q = 4 ; System . out . println ( minflip ( arr1 , arr2 , arr3 , p , q , n ) ) ; } } ","def minflip ( arr1 , arr2 , arr3 , p , q , n ) : NEW_LINE INDENT flip = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr1 [ i ] ^ arr2 [ i ] != arr3 [ i ] ) : NEW_LINE INDENT flip += 1 NEW_LINE DEDENT DEDENT return flip if ( flip <= p + q ) else - 1 NEW_LINE DEDENT arr1 = [ 1 , 0 , 1 , 1 , 1 , 1 , 1 ] NEW_LINE arr2 = [ 0 , 1 , 1 , 1 , 1 , 0 , 0 ] NEW_LINE arr3 = [ 1 , 1 , 1 , 1 , 0 , 0 , 1 ] NEW_LINE n = len ( arr1 ) NEW_LINE p = 2 NEW_LINE q = 4 NEW_LINE print ( minflip ( arr1 , arr2 , arr3 , p , q , n ) ) NEW_LINE " V629,"class GFG { static int checkArray ( int [ ] arr , int n ) { return ( ( arr [ 0 ] % 2 ) > 0 && ( arr [ n - 1 ] % 2 ) > 0 && ( n % 2 ) > 0 ) ? 1 : 0 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( checkArray ( arr , n ) ) ; } } ","def checkArray ( arr , n ) : NEW_LINE INDENT return ( ( arr [ 0 ] % 2 ) and ( arr [ n - 1 ] % 2 ) and ( n % 2 ) ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) ; NEW_LINE if checkArray ( arr , n ) : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT " V630,"import java . util . * ; class solution { static void pattern ( int N ) { int i , j , k = 0 , space = 1 , rows = N ; for ( i = rows ; i >= 1 ; i -- ) { for ( j = 1 ; j <= i ; j ++ ) { System . out . print ( "" * "" ) ; } if ( i != rows ) { for ( k = 1 ; k <= space ; k ++ ) { System . out . print ( "" ▁ "" ) ; } space = space + 2 ; } for ( j = i ; j >= 1 ; j -- ) { if ( j != rows ) System . out . print ( "" * "" ) ; } System . out . print ( "" \n "" ) ; } System . out . print ( "" \n "" ) ; } public static void main ( String args [ ] ) { int N = 6 ; pattern ( N ) ; } } ","def pattern ( N ) : NEW_LINE INDENT k , space , rows = 0 , 1 , N NEW_LINE for i in range ( rows , 0 , - 1 ) : NEW_LINE INDENT for j in range ( 1 , i + 1 ) : NEW_LINE INDENT print ( ' * ' , end = ' ' ) NEW_LINE DEDENT if i != rows : NEW_LINE INDENT for k in range ( 1 , space + 1 ) : NEW_LINE INDENT print ( ' ▁ ' , end = ' ' ) NEW_LINE DEDENT space += 2 NEW_LINE DEDENT for j in range ( i , 0 , - 1 ) : NEW_LINE INDENT if j != rows : NEW_LINE INDENT print ( ' * ' , end = ' ' ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT N = 6 NEW_LINE pattern ( N ) NEW_LINE " V631,"class GFG { static int discreteLogarithm ( int a , int b , int m ) { int n = ( int ) ( Math . sqrt ( m ) + 1 ) ; int an = 1 ; for ( int i = 0 ; i < n ; ++ i ) an = ( an * a ) % m ; int [ ] value = new int [ m ] ; for ( int i = 1 , cur = an ; i <= n ; ++ i ) { if ( value [ cur ] == 0 ) value [ cur ] = i ; cur = ( cur * an ) % m ; } for ( int i = 0 , cur = b ; i <= n ; ++ i ) { if ( value [ cur ] > 0 ) { int ans = value [ cur ] * n - i ; if ( ans < m ) return ans ; } cur = ( cur * a ) % m ; } return - 1 ; } public static void main ( String [ ] args ) { int a = 2 , b = 3 , m = 5 ; System . out . println ( discreteLogarithm ( a , b , m ) ) ; a = 3 ; b = 7 ; m = 11 ; System . out . println ( discreteLogarithm ( a , b , m ) ) ; } } ","import math ; NEW_LINE def discreteLogarithm ( a , b , m ) : NEW_LINE INDENT n = int ( math . sqrt ( m ) + 1 ) ; NEW_LINE an = 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT an = ( an * a ) % m ; NEW_LINE DEDENT value = [ 0 ] * m ; NEW_LINE cur = an ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( value [ cur ] == 0 ) : NEW_LINE INDENT value [ cur ] = i ; NEW_LINE DEDENT cur = ( cur * an ) % m ; NEW_LINE DEDENT cur = b ; NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT if ( value [ cur ] > 0 ) : NEW_LINE INDENT ans = value [ cur ] * n - i ; NEW_LINE if ( ans < m ) : NEW_LINE INDENT return ans ; NEW_LINE DEDENT DEDENT cur = ( cur * a ) % m ; NEW_LINE DEDENT return - 1 ; NEW_LINE DEDENT a = 2 ; NEW_LINE b = 3 ; NEW_LINE m = 5 ; NEW_LINE print ( discreteLogarithm ( a , b , m ) ) ; NEW_LINE a = 3 ; NEW_LINE b = 7 ; NEW_LINE m = 11 ; NEW_LINE print ( discreteLogarithm ( a , b , m ) ) ; NEW_LINE " V632,"public class MaximumAbsoluteDifference { private static int calculateDiff ( int i , int j , int [ ] array ) { return Math . abs ( array [ i ] - array [ j ] ) + Math . abs ( i - j ) ; } private static int maxDistance ( int [ ] array ) { int result = 0 ; for ( int i = 0 ; i < array . length ; i ++ ) { for ( int j = i ; j < array . length ; j ++ ) { result = Math . max ( result , calculateDiff ( i , j , array ) ) ; } } return result ; } public static void main ( String [ ] args ) { int [ ] array = { - 70 , - 64 , - 6 , - 56 , 64 , 61 , - 57 , 16 , 48 , - 98 } ; System . out . println ( maxDistance ( array ) ) ; } } ","def calculateDiff ( i , j , arr ) : NEW_LINE INDENT return abs ( arr [ i ] - arr [ j ] ) + abs ( i - j ) NEW_LINE DEDENT def maxDistance ( arr , n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT if ( calculateDiff ( i , j , arr ) > result ) : NEW_LINE INDENT result = calculateDiff ( i , j , arr ) NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT arr = [ - 70 , - 64 , - 6 , - 56 , 64 , 61 , - 57 , 16 , 48 , - 98 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxDistance ( arr , n ) ) NEW_LINE " V633,"public class GFG { static int zeroUpto ( int digits ) { int first = ( int ) ( ( Math . pow ( 10 , digits ) - 1 ) / 9 ) ; int second = ( int ) ( ( Math . pow ( 9 , digits ) - 1 ) / 8 ) ; return 9 * ( first - second ) ; } static int toInt ( char c ) { return ( int ) ( c ) - 48 ; } static int countZero ( String num ) { int k = num . length ( ) ; int total = zeroUpto ( k - 1 ) ; int non_zero = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { if ( num . charAt ( i ) == '0' ) { non_zero -- ; break ; } non_zero += ( toInt ( num . charAt ( i ) ) - 1 ) * ( Math . pow ( 9 , k - 1 - i ) ) ; } int no = 0 , remaining = 0 , calculatedUpto = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { no = no * 10 + ( toInt ( num . charAt ( i ) ) ) ; if ( i != 0 ) calculatedUpto = calculatedUpto * 10 + 9 ; } remaining = no - calculatedUpto ; int ans = zeroUpto ( k - 1 ) + ( remaining - non_zero - 1 ) ; return ans ; } static public void main ( String [ ] args ) { String num = ""107"" ; System . out . println ( "" Count ▁ of ▁ numbers ▁ from ▁ 1"" + "" ▁ to ▁ "" + num + "" ▁ is ▁ "" + countZero ( num ) ) ; num = ""1264"" ; System . out . println ( "" Count ▁ of ▁ numbers ▁ from ▁ 1"" + "" ▁ to ▁ "" + num + "" ▁ is ▁ "" + countZero ( num ) ) ; } } ","def zeroUpto ( digits ) : NEW_LINE INDENT first = int ( ( pow ( 10 , digits ) - 1 ) / 9 ) ; NEW_LINE second = int ( ( pow ( 9 , digits ) - 1 ) / 8 ) ; NEW_LINE return 9 * ( first - second ) ; NEW_LINE DEDENT def countZero ( num ) : NEW_LINE INDENT k = len ( num ) ; NEW_LINE total = zeroUpto ( k - 1 ) ; NEW_LINE non_zero = 0 ; NEW_LINE for i in range ( len ( num ) ) : NEW_LINE INDENT if ( num [ i ] == '0' ) : NEW_LINE INDENT non_zero -= 1 ; NEW_LINE break ; NEW_LINE DEDENT non_zero += ( ( ( ord ( num [ i ] ) - ord ( '0' ) ) - 1 ) * ( pow ( 9 , k - 1 - i ) ) ) ; NEW_LINE DEDENT no = 0 ; NEW_LINE remaining = 0 ; NEW_LINE calculatedUpto = 0 ; NEW_LINE for i in range ( len ( num ) ) : NEW_LINE INDENT no = no * 10 + ( ord ( num [ i ] ) - ord ( '0' ) ) ; NEW_LINE if ( i != 0 ) : NEW_LINE INDENT calculatedUpto = calculatedUpto * 10 + 9 ; NEW_LINE DEDENT DEDENT remaining = no - calculatedUpto ; NEW_LINE ans = zeroUpto ( k - 1 ) + ( remaining - non_zero - 1 ) ; NEW_LINE return ans ; NEW_LINE DEDENT num = ""107"" ; NEW_LINE print ( "" Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to "" , num , "" is "" , countZero ( num ) ) ; NEW_LINE num = ""1264"" ; NEW_LINE print ( "" Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to "" , num , "" is "" , countZero ( num ) ) ; NEW_LINE " V634,"class GFG { static class Node { int data ; Node next ; Node ( int x ) { data = x ; next = null ; } } ; static void printList ( Node head ) { if ( head == null ) return ; Node temp = head ; do { System . out . print ( temp . data + "" - > "" ) ; temp = temp . next ; } while ( temp != head ) ; System . out . println ( head . data ) ; } static Node deleteK ( Node head_ref , int k ) { Node head = head_ref ; if ( head == null ) return null ; Node curr = head , prev = null ; while ( true ) { if ( curr . next == head && curr == head ) break ; printList ( head ) ; for ( int i = 0 ; i < k ; i ++ ) { prev = curr ; curr = curr . next ; } if ( curr == head ) { prev = head ; while ( prev . next != head ) prev = prev . next ; head = curr . next ; prev . next = head ; head_ref = head ; } else if ( curr . next == head ) { prev . next = head ; } else { prev . next = curr . next ; } } return head ; } static Node insertNode ( Node head_ref , int x ) { Node head = head_ref ; Node temp = new Node ( x ) ; if ( head == null ) { temp . next = temp ; head_ref = temp ; return head_ref ; } else { Node temp1 = head ; while ( temp1 . next != head ) temp1 = temp1 . next ; temp1 . next = temp ; temp . next = head ; } return head ; } public static void main ( String args [ ] ) { Node head = null ; head = insertNode ( head , 1 ) ; head = insertNode ( head , 2 ) ; head = insertNode ( head , 3 ) ; head = insertNode ( head , 4 ) ; head = insertNode ( head , 5 ) ; head = insertNode ( head , 6 ) ; head = insertNode ( head , 7 ) ; head = insertNode ( head , 8 ) ; head = insertNode ( head , 9 ) ; int k = 4 ; head = deleteK ( head , k ) ; } } ","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 prList ( head ) : NEW_LINE INDENT if ( head == None ) : NEW_LINE INDENT return NEW_LINE DEDENT temp = head NEW_LINE print ( temp . data , end = "" - > "" ) NEW_LINE temp = temp . next NEW_LINE while ( temp != head ) : NEW_LINE INDENT print ( temp . data , end = "" - > "" ) NEW_LINE temp = temp . next NEW_LINE DEDENT print ( head . data ) NEW_LINE DEDENT def deleteK ( head_ref , k ) : NEW_LINE INDENT head = head_ref NEW_LINE if ( head == None ) : NEW_LINE INDENT return NEW_LINE DEDENT curr = head NEW_LINE prev = None NEW_LINE while True : NEW_LINE INDENT if ( curr . next == head and curr == head ) : NEW_LINE INDENT break NEW_LINE DEDENT prList ( head ) NEW_LINE for i in range ( k ) : NEW_LINE INDENT prev = curr NEW_LINE curr = curr . next NEW_LINE DEDENT if ( curr == head ) : NEW_LINE INDENT prev = head NEW_LINE while ( prev . next != head ) : NEW_LINE INDENT prev = prev . next NEW_LINE DEDENT head = curr . next NEW_LINE prev . next = head NEW_LINE head_ref = head NEW_LINE DEDENT elif ( curr . next == head ) : NEW_LINE INDENT prev . next = head NEW_LINE DEDENT else : NEW_LINE INDENT prev . next = curr . next NEW_LINE DEDENT DEDENT DEDENT def insertNode ( head_ref , x ) : NEW_LINE INDENT head = head_ref NEW_LINE temp = Node ( x ) NEW_LINE if ( head == None ) : NEW_LINE INDENT temp . next = temp NEW_LINE head_ref = temp NEW_LINE return head_ref NEW_LINE DEDENT else : NEW_LINE INDENT temp1 = head NEW_LINE while ( temp1 . next != head ) : NEW_LINE INDENT temp1 = temp1 . next NEW_LINE DEDENT temp1 . next = temp NEW_LINE temp . next = head NEW_LINE DEDENT return head NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = insertNode ( head , 1 ) NEW_LINE head = insertNode ( head , 2 ) NEW_LINE head = insertNode ( head , 3 ) NEW_LINE head = insertNode ( head , 4 ) NEW_LINE head = insertNode ( head , 5 ) NEW_LINE head = insertNode ( head , 6 ) NEW_LINE head = insertNode ( head , 7 ) NEW_LINE head = insertNode ( head , 8 ) NEW_LINE head = insertNode ( head , 9 ) NEW_LINE k = 4 NEW_LINE deleteK ( head , k ) NEW_LINE DEDENT " V635,"class GFG { static int possibleways ( int n ) { if ( n % 2 == 1 ) return 0 ; else if ( n % 4 == 0 ) return n / 4 - 1 ; else return n / 4 ; } public static void main ( String [ ] args ) { int n = 20 ; System . out . println ( possibleways ( n ) ) ; } } ","def possibleways ( n ) : NEW_LINE INDENT if ( n % 2 == 1 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT elif ( n % 4 == 0 ) : NEW_LINE INDENT return n // 4 - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return n // 4 ; NEW_LINE DEDENT DEDENT n = 20 ; NEW_LINE print ( possibleways ( n ) ) ; NEW_LINE " V636,"import java . io . * ; class GFG { static int numberOfWays ( int x ) { int dp [ ] = new int [ x + 1 ] ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( int i = 2 ; i <= x ; i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ; return dp [ x ] ; } public static void main ( String [ ] args ) { int x = 3 ; System . out . println ( numberOfWays ( x ) ) ; } } ","def numberOfWays ( x ) : NEW_LINE INDENT if x == 0 or x == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) ) NEW_LINE DEDENT DEDENT x = 3 NEW_LINE print ( numberOfWays ( x ) ) NEW_LINE " V637,"class GFG { static int properDivisorSum ( int n ) { int sum = 0 ; int i ; for ( i = 1 ; i <= n ; ++ i ) sum += ( n / i ) * i ; return sum - n * ( n + 1 ) / 2 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( properDivisorSum ( n ) ) ; n = 5 ; System . out . println ( properDivisorSum ( n ) ) ; } } ","def properDivisorSum ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += ( n // i ) * i NEW_LINE DEDENT return sum - n * ( n + 1 ) // 2 NEW_LINE DEDENT n = 4 NEW_LINE print ( properDivisorSum ( n ) ) NEW_LINE n = 5 NEW_LINE print ( properDivisorSum ( n ) ) NEW_LINE " V638,"import java . io . * ; class GFG { static double diff ( double n , double mid ) { if ( n > ( mid * mid * mid ) ) return ( n - ( mid * mid * mid ) ) ; else return ( ( mid * mid * mid ) - n ) ; } static double cubicRoot ( double n ) { double start = 0 , end = n ; double e = 0.0000001 ; while ( true ) { double mid = ( start + end ) / 2 ; double error = diff ( n , mid ) ; if ( error <= e ) return mid ; if ( ( mid * mid * mid ) > n ) end = mid ; else start = mid ; } } public static void main ( String [ ] args ) { double n = 3 ; System . out . println ( "" Cube ▁ root ▁ of ▁ "" + n + "" ▁ is ▁ "" + cubicRoot ( n ) ) ; } } ","def diff ( n , mid ) : NEW_LINE INDENT if ( n > ( mid * mid * mid ) ) : NEW_LINE INDENT return ( n - ( mid * mid * mid ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( mid * mid * mid ) - n ) NEW_LINE DEDENT DEDENT def cubicRoot ( n ) : NEW_LINE INDENT start = 0 NEW_LINE end = n NEW_LINE e = 0.0000001 NEW_LINE while ( True ) : NEW_LINE INDENT mid = ( start + end ) / 2 NEW_LINE error = diff ( n , mid ) NEW_LINE if ( error <= e ) : NEW_LINE INDENT return mid NEW_LINE DEDENT if ( ( mid * mid * mid ) > n ) : NEW_LINE INDENT end = mid NEW_LINE DEDENT else : NEW_LINE INDENT start = mid NEW_LINE DEDENT DEDENT DEDENT n = 3 NEW_LINE print ( "" Cubic ▁ root ▁ of "" , n , "" is "" , round ( cubicRoot ( n ) , 6 ) ) NEW_LINE " V639,"class GFG { static int getMin ( int arr [ ] , int i , int n ) { return ( n == 1 ) ? arr [ i ] : Math . min ( arr [ i ] , getMin ( arr , i + 1 , n - 1 ) ) ; } static int getMax ( int arr [ ] , int i , int n ) { return ( n == 1 ) ? arr [ i ] : Math . max ( arr [ i ] , getMax ( arr , i + 1 , n - 1 ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; System . out . print ( "" Minimum ▁ element ▁ of ▁ array : ▁ "" + getMin ( arr , 0 , n ) + "" \n "" ) ; System . out . println ( "" Maximum ▁ element ▁ of ▁ array : ▁ "" + getMax ( arr , 0 , n ) ) ; } } ","def getMin ( arr , n ) : NEW_LINE INDENT return min ( arr ) ; NEW_LINE DEDENT def getMax ( arr , n ) : NEW_LINE INDENT return max ( arr ) ; NEW_LINE DEDENT arr = [ 12 , 1234 , 45 , 67 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( "" Minimum ▁ element ▁ of ▁ array : ▁ "" , getMin ( arr , n ) ) ; NEW_LINE print ( "" Maximum ▁ element ▁ of ▁ array : ▁ "" , getMax ( arr , n ) ) ; NEW_LINE " V640,"import java . io . * ; class GFG { public static void printPascal ( int n ) { for ( int line = 1 ; line <= n ; line ++ ) { int C = 1 ; for ( int i = 1 ; i <= line ; i ++ ) { System . out . print ( C + "" ▁ "" ) ; C = C * ( line - i ) / i ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int n = 5 ; printPascal ( n ) ; } } ","def printPascal ( n ) : NEW_LINE INDENT for line in range ( 1 , n + 1 ) : NEW_LINE INDENT C = 1 ; NEW_LINE for i in range ( 1 , line + 1 ) : NEW_LINE INDENT print ( C , end = "" ▁ "" ) ; NEW_LINE C = int ( C * ( line - i ) / i ) ; NEW_LINE DEDENT print ( "" "" ) ; NEW_LINE DEDENT DEDENT n = 5 ; NEW_LINE printPascal ( n ) ; NEW_LINE " V641,"import java . util . Arrays ; class GFG { static void fillWithFreq ( int arr [ ] , int n ) { int temp [ ] = new int [ n ] ; Arrays . fill ( temp , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) temp [ arr [ i ] ] += 1 ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = temp [ i ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 3 , 4 , 5 , 5 , 4 , 5 , 6 , 7 } ; int n = arr . length ; fillWithFreq ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; } } ","def fillWithFreq ( arr , n ) : NEW_LINE INDENT temp = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT temp [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT arr [ i ] = temp [ i ] NEW_LINE DEDENT DEDENT arr = [ 5 , 2 , 3 , 4 , 5 , 5 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE fillWithFreq ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT " V642,"class GFG { public static void main ( String [ ] args ) { String str = "" Mr ▁ John ▁ Smith ▁ ▁ ▁ "" ; str = str . trim ( ) ; str = str . replaceAll ( "" \\ s "" , "" % 20"" ) ; System . out . println ( str ) ; } } ","s = "" Mr ▁ John ▁ Smith ▁ "" NEW_LINE s = s . strip ( ) NEW_LINE s = s . replace ( ' ▁ ' , "" % 20"" ) NEW_LINE print ( s ) NEW_LINE " V643,"import java . util . * ; class GFG { static int cntgloves ( int arr [ ] , int n ) { int count = 0 ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n - 1 😉 { if ( arr [ i ] == arr [ i + 1 ] ) { count ++ ; i = i + 2 ; } else { i ++ ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 5 , 2 , 3 , 5 , 2 , 2 , 1 } ; int n = arr . length ; System . out . println ( cntgloves ( arr , n ) ) ; } } ","def cntgloves ( arr , n ) : NEW_LINE INDENT count = 0 ; NEW_LINE arr . sort ( ) ; NEW_LINE i = 0 ; NEW_LINE while i < ( n - 1 ) : NEW_LINE INDENT if ( arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE i = i + 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 6 , 5 , 2 , 3 , 5 , 2 , 2 , 1 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( cntgloves ( arr , n ) ) ; NEW_LINE DEDENT " V644,"import java . io . * ; class GFG { static int inversegrayCode ( int n ) { int inv = 0 ; for ( ; n != 0 ; n = n >> 1 ) inv ^= n ; return inv ; } public static void main ( String [ ] args ) { int n = 15 ; System . out . println ( inversegrayCode ( n ) ) ; } } ","def inversegrayCode ( n ) : NEW_LINE INDENT inv = 0 ; NEW_LINE while ( n ) : NEW_LINE INDENT inv = inv ^ n ; NEW_LINE n = n >> 1 ; NEW_LINE DEDENT return inv ; NEW_LINE DEDENT n = 15 ; NEW_LINE print ( inversegrayCode ( n ) ) ; NEW_LINE " V645,"import java . util . * ; class GFG { static boolean isPerfectSquare ( int [ ] arr , int n ) { HashMap < Integer , Integer > umap = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( umap . containsKey ( arr [ i ] ) ) umap . put ( arr [ i ] , umap . get ( arr [ i ] ) + 1 ) ; else umap . put ( arr [ i ] , 1 ) ; } Iterator < Map . Entry < Integer , Integer > > iterator = umap . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Map . Entry < Integer , Integer > entry = iterator . next ( ) ; if ( entry . getValue ( ) % 2 == 1 ) return false ; } return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 7 , 7 } ; int n = arr . length ; if ( isPerfectSquare ( arr , n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isPerfectSquare ( arr , n ) : NEW_LINE INDENT umap = dict . fromkeys ( arr , n ) ; NEW_LINE for key in arr : NEW_LINE INDENT umap [ key ] += 1 ; NEW_LINE DEDENT for key in arr : NEW_LINE INDENT if ( umap [ key ] % 2 == 1 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 2 , 2 , 7 , 7 ] ; NEW_LINE n = len ( arr ) NEW_LINE if ( isPerfectSquare ( arr , n ) ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE DEDENT DEDENT " V646,"class GFG { static void findPairs ( int arr [ ] , int n ) { int cntEven = 0 , cntOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) cntEven ++ ; else cntOdd ++ ; } int evenPairs = 0 ; evenPairs += ( ( cntEven * ( cntEven - 1 ) ) / 2 ) ; evenPairs += ( ( cntOdd * ( cntOdd - 1 ) ) / 2 ) ; int oddPairs = 0 ; oddPairs += ( cntEven * cntOdd ) ; System . out . println ( "" Odd ▁ pairs ▁ = ▁ "" + oddPairs ) ; System . out . println ( "" Even ▁ pairs ▁ = ▁ "" + evenPairs ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; findPairs ( arr , n ) ; } } ","def findPairs ( arr , n ) : NEW_LINE INDENT cntEven = 0 ; cntOdd = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT cntEven += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT cntOdd += 1 ; NEW_LINE DEDENT DEDENT evenPairs = 0 ; NEW_LINE evenPairs += ( ( cntEven * ( cntEven - 1 ) ) // 2 ) ; NEW_LINE evenPairs += ( ( cntOdd * ( cntOdd - 1 ) ) // 2 ) ; NEW_LINE oddPairs = 0 ; NEW_LINE oddPairs += ( cntEven * cntOdd ) ; NEW_LINE print ( "" Odd ▁ pairs ▁ = ▁ "" , oddPairs ) ; NEW_LINE print ( "" Even ▁ pairs ▁ = ▁ "" , evenPairs ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE findPairs ( arr , n ) ; NEW_LINE DEDENT " V647,"class GFG { static void shuffle ( int N , int key ) { int NO_OF_BITS = N ; int reverse_num = 0 , temp ; for ( int i = 0 ; i < NO_OF_BITS ; i ++ ) { temp = ( key & ( 1 << i ) ) ; if ( temp > 0 ) reverse_num |= ( 1 << ( ( NO_OF_BITS - 1 ) - i ) ) ; } System . out . print ( reverse_num ) ; } public static void main ( String [ ] args ) { int N = 3 ; int key = 3 ; shuffle ( N , key ) ; } } ","def shuffle ( N , key ) : NEW_LINE INDENT NO_OF_BITS = N NEW_LINE reverse_num = 0 NEW_LINE for i in range ( NO_OF_BITS ) : NEW_LINE INDENT temp = ( key & ( 1 << i ) ) NEW_LINE if ( temp ) : NEW_LINE INDENT reverse_num |= ( 1 << ( ( NO_OF_BITS - 1 ) - i ) ) NEW_LINE DEDENT DEDENT print ( reverse_num ) NEW_LINE DEDENT N = 3 NEW_LINE key = 3 NEW_LINE shuffle ( N , key ) NEW_LINE " V648,"public class Subarray_Inversions { static int inversion_count ( int n , int k , int [ ] a ) { int count = 0 ; for ( int start = 0 ; start < n - k + 1 ; start ++ ) { int end = start + k ; count += bubble_count ( a , start , end ) ; } return count ; } public static int bubble_count ( int [ ] arr , int start , int end ) { int count = 0 ; for ( int i = start ; i < end ; i ++ ) { for ( int j = i + 1 ; j < end ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int n = 10 ; int [ ] arr = { 15 , 51 , 44 , 44 , 76 , 50 , 29 , 88 , 48 , 50 } ; int k = 5 ; long result = inversion_count ( n , k , arr ) ; System . out . println ( result ) ; } } ","def bubble_count ( arr , start , end ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( start , end ) : NEW_LINE INDENT for j in range ( i + 1 , end ) : NEW_LINE INDENT if ( arr [ i ] > arr [ j ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT DEDENT return count ; NEW_LINE DEDENT def inversion_count ( n , k , a ) : NEW_LINE INDENT count = 0 ; NEW_LINE for start in range ( 0 , n - k + 1 ) : NEW_LINE INDENT end = start + k ; NEW_LINE count += bubble_count ( a , start , end ) ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 ; NEW_LINE arr = [ 15 , 51 , 44 , 44 , 76 , 50 , 29 , 88 , 48 , 50 ] ; NEW_LINE k = 5 ; NEW_LINE result = inversion_count ( n , k , arr ) ; NEW_LINE print ( result ) ; NEW_LINE DEDENT " V649,"import java . io . * ; class GFG { static void _printParenthesis ( char str [ ] , int pos , int n , int open , int close ) { if ( close == n ) { for ( int i = 0 ; i < str . length ; i ++ ) System . out . print ( str [ i ] ) ; System . out . println ( ) ; return ; } else { if ( open > close ) { str [ pos ] = ' } ' ; _printParenthesis ( str , pos + 1 , n , open , close + 1 ) ; } if ( open < n ) { str [ pos ] = ' { ' ; _printParenthesis ( str , pos + 1 , n , open + 1 , close ) ; } } } static void printParenthesis ( char str [ ] , int n ) { if ( n > 0 ) _printParenthesis ( str , 0 , n , 0 , 0 ) ; return ; } public static void main ( String [ ] args ) { int n = 3 ; char [ ] str = new char [ 2 * n ] ; printParenthesis ( str , n ) ; } } ","def printParenthesis ( str , n ) : NEW_LINE INDENT if ( n > 0 ) : NEW_LINE INDENT _printParenthesis ( str , 0 , n , 0 , 0 ) ; NEW_LINE DEDENT return ; NEW_LINE DEDENT def _printParenthesis ( str , pos , n , open , close ) : NEW_LINE INDENT if ( close == n ) : NEW_LINE INDENT for i in str : NEW_LINE INDENT print ( i , end = "" "" ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE return ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( open > close ) : NEW_LINE INDENT str [ pos ] = ' } ' ; NEW_LINE _printParenthesis ( str , pos + 1 , n , open , close + 1 ) ; NEW_LINE DEDENT if ( open < n ) : NEW_LINE INDENT str [ pos ] = ' { ' ; NEW_LINE _printParenthesis ( str , pos + 1 , n , open + 1 , close ) ; NEW_LINE DEDENT DEDENT DEDENT n = 3 ; NEW_LINE str = [ "" "" ] * 2 * n ; NEW_LINE printParenthesis ( str , n ) ; NEW_LINE " V650,"import java . io . * ; class GFG { static int fun ( int x ) { int y = ( x / 4 ) * 4 ; int ans = 0 ; for ( int i = y ; i <= x ; i ++ ) ans ^= i ; return ans ; } static int query ( int x ) { if ( x == 0 ) return 0 ; int k = ( x + 1 ) / 2 ; return ( ( x %= 2 ) != 0 ) ? 2 * fun ( k ) : ( ( fun ( k - 1 ) * 2 ) ^ ( k & 1 ) ) ; } static void allQueries ( int q , int l [ ] , int r [ ] ) { for ( int i = 0 ; i < q ; i ++ ) System . out . println ( ( query ( r [ i ] ) ^ query ( l [ i ] - 1 ) ) ) ; } public static void main ( String [ ] args ) { int q = 3 ; int [ ] l = { 2 , 2 , 5 } ; int [ ] r = { 4 , 8 , 9 } ; allQueries ( q , l , r ) ; } } ","def fun ( x ) : NEW_LINE INDENT y = ( x // 4 ) * 4 NEW_LINE ans = 0 NEW_LINE for i in range ( y , x + 1 ) : NEW_LINE INDENT ans ^= i NEW_LINE DEDENT return ans NEW_LINE DEDENT def query ( x ) : NEW_LINE INDENT if ( x == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT k = ( x + 1 ) // 2 NEW_LINE if x % 2 == 0 : NEW_LINE INDENT return ( ( fun ( k - 1 ) * 2 ) ^ ( k & 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( 2 * fun ( k ) ) NEW_LINE DEDENT DEDENT def allQueries ( q , l , r ) : NEW_LINE INDENT for i in range ( q ) : NEW_LINE INDENT print ( query ( r [ i ] ) ^ query ( l [ i ] - 1 ) ) NEW_LINE DEDENT DEDENT q = 3 NEW_LINE l = [ 2 , 2 , 5 ] NEW_LINE r = [ 4 , 8 , 9 ] NEW_LINE allQueries ( q , l , r ) NEW_LINE " V651,"class GFG { static String isDivisible ( long n ) { long temp = n ; int sum = 0 ; while ( n != 0 ) { int k = ( int ) n % 10 ; sum += k ; n /= 10 ; } if ( temp % sum == 0 ) return "" YES "" ; return "" NO "" ; } public static void main ( String [ ] args ) { long n = 123 ; System . out . println ( isDivisible ( n ) ) ; } } ","def isDivisible ( n ) : NEW_LINE INDENT temp = n NEW_LINE sum = 0 ; NEW_LINE while ( n ) : NEW_LINE INDENT k = n % 10 ; NEW_LINE sum += k ; NEW_LINE n /= 10 ; NEW_LINE DEDENT if ( temp % sum == 0 ) : NEW_LINE INDENT return "" YES "" ; NEW_LINE DEDENT return "" NO "" ; NEW_LINE DEDENT n = 123 ; NEW_LINE print ( isDivisible ( n ) ) ; NEW_LINE " V652,"import java . io . * ; class GFG { static void find ( int n , int m ) { if ( n <= 2 * m ) System . out . println ( "" Minimum ▁ "" + 0 ) ; else System . out . println ( "" Minimum ▁ "" + ( n - 2 * m ) ) ; int i ; for ( i = 1 ; i <= n ; i ++ ) { if ( i * ( i - 1 ) / 2 >= m ) break ; } System . out . println ( "" Maximum ▁ "" + ( n - i ) ) ; } public static void main ( String [ ] args ) { int n = 4 ; int m = 2 ; find ( n , m ) ; } } ","def find ( n , m ) : NEW_LINE INDENT if ( n <= 2 * m ) : NEW_LINE INDENT print ( "" Minimum ▁ "" , 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Minimum ▁ "" , n - 2 * m ) NEW_LINE DEDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( i * ( i - 1 ) // 2 >= m ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( "" Maximum ▁ "" , n - i ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE m = 2 NEW_LINE find ( n , m ) NEW_LINE DEDENT " V653,"class GfG { static boolean isVowel ( char c ) { if ( c == ' a ' || c == ' e ' || c == ' i ' || c == ' o ' || c == ' u ' ) return true ; return false ; } static boolean checkPossibility ( String s1 , String s2 ) { int l1 = s1 . length ( ) ; int l2 = s2 . length ( ) ; if ( l1 != l2 ) return false ; for ( int i = 0 ; i < l1 ; i ++ ) { if ( isVowel ( s1 . charAt ( i ) ) && isVowel ( s2 . charAt ( i ) ) ) continue ; else if ( ! ( isVowel ( s1 . charAt ( i ) ) ) && ! ( isVowel ( s2 . charAt ( i ) ) ) ) continue ; else return false ; } return true ; } public static void main ( String [ ] args ) { String S1 = "" abcgle "" ; String S2 = "" ezggli "" ; if ( checkPossibility ( S1 , S2 ) == true ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isVowel ( c ) : NEW_LINE INDENT if ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def checkPossibility ( s1 , s2 ) : NEW_LINE INDENT l1 = len ( s1 ) NEW_LINE l2 = len ( s2 ) NEW_LINE if ( l1 != l2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( l1 ) : NEW_LINE INDENT if ( isVowel ( s1 [ i ] ) and isVowel ( s2 [ i ] ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif ( ( isVowel ( s1 [ i ] ) ) == False and ( isVowel ( s2 [ i ] ) == False ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT S1 , S2 = "" abcgle "" , "" ezggli "" NEW_LINE if ( checkPossibility ( S1 , S2 ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V654,"class GFG { static void findNthTerm ( int N ) { int ans ; if ( N % 2 == 0 ) { ans = ( N / 2 ) * 6 + ( N / 2 ) * 2 ; } else { ans = ( N / 2 + 1 ) * 6 + ( N / 2 ) * 2 ; } System . out . print ( ans + "" \n "" ) ; } public static void main ( String [ ] args ) { int N = 3 ; findNthTerm ( N ) ; } } ","def findNthTerm ( N ) : NEW_LINE INDENT ans = 0 ; NEW_LINE if ( N % 2 == 0 ) : NEW_LINE INDENT ans = ( N // 2 ) * 6 + ( N // 2 ) * 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( N // 2 + 1 ) * 6 + ( N // 2 ) * 2 ; NEW_LINE DEDENT print ( ans ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 ; NEW_LINE findNthTerm ( N ) ; NEW_LINE DEDENT " V655,"import java . io . * ; class GFG { static int N = 4 ; static void multiply ( int mat1 [ ] [ ] , int mat2 [ ] [ ] , int res [ ] [ ] ) { int i , j , k ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { res [ i ] [ j ] = 0 ; for ( k = 0 ; k < N ; k ++ ) res [ i ] [ j ] += mat1 [ i ] [ k ] * mat2 [ k ] [ j ] ; } } } public static void main ( String [ ] args ) { int mat1 [ ] [ ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int mat2 [ ] [ ] = { { 1 , 1 , 1 , 1 } , { 2 , 2 , 2 , 2 } , { 3 , 3 , 3 , 3 } , { 4 , 4 , 4 , 4 } } ; int res [ ] [ ] = new int [ N ] [ N ] ; int i , j ; multiply ( mat1 , mat2 , res ) ; System . out . println ( "" Result ▁ matrix "" + "" ▁ is ▁ "" ) ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) System . out . print ( res [ i ] [ j ] + "" ▁ "" ) ; System . out . println ( ) ; } } } ","def matrix_multiplication ( M , N ) : NEW_LINE INDENT R = [ [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 ] ] NEW_LINE for i in range ( 0 , 4 ) : NEW_LINE INDENT for j in range ( 0 , 4 ) : NEW_LINE INDENT for k in range ( 0 , 4 ) : NEW_LINE INDENT R [ i ] [ j ] += M [ i ] [ k ] * N [ k ] [ j ] NEW_LINE DEDENT DEDENT DEDENT for i in range ( 0 , 4 ) : NEW_LINE INDENT for j in range ( 0 , 4 ) : NEW_LINE INDENT print ( R [ i ] [ j ] , end = "" ▁ "" ) NEW_LINE DEDENT print ( "" \n "" , end = "" "" ) NEW_LINE DEDENT DEDENT M = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] NEW_LINE N = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] NEW_LINE matrix_multiplication ( M , N ) NEW_LINE " V656,"import java . io . * ; class GFG { static int [ ] dp = new int [ 1024 ] ; static int get_binary ( int u ) { int ans = 0 ; while ( u > 0 ) { int rem = u % 10 ; ans |= ( 1 << rem ) ; u /= 10 ; } return ans ; } static int recur ( int u , int [ ] array , int n ) { if ( u == 0 ) return 0 ; if ( dp [ u ] != - 1 ) return dp [ u ] ; for ( int i = 0 ; i < n ; i ++ ) { int mask = get_binary ( array [ i ] ) ; if ( ( mask | u ) == u ) { dp [ u ] = Math . max ( Math . max ( 0 , dp [ u ^ mask ] ) + array [ i ] , dp [ u ] ) ; } } return dp [ u ] ; } static int solve ( int [ ] array , int n ) { for ( int i = 0 ; i < ( 1 << 10 ) ; i ++ ) { dp [ i ] = - 1 ; } int ans = 0 ; for ( int i = 0 ; i < ( 1 << 10 ) ; i ++ ) { ans = Math . max ( ans , recur ( i , array , n ) ) ; } return ans ; } static public void main ( String [ ] args ) { int [ ] array = { 22 , 132 , 4 , 45 , 12 , 223 } ; int n = array . length ; System . out . println ( solve ( array , n ) ) ; } } ","dp = [ 0 ] * 1024 ; NEW_LINE def get_binary ( u ) : NEW_LINE INDENT ans = 0 ; NEW_LINE while ( u ) : NEW_LINE INDENT rem = u % 10 ; NEW_LINE ans |= ( 1 << rem ) ; NEW_LINE u //= 10 ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT def recur ( u , array , n ) : NEW_LINE INDENT if ( u == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( dp [ u ] != - 1 ) : NEW_LINE INDENT return dp [ u ] ; NEW_LINE DEDENT temp = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT mask = get_binary ( array [ i ] ) ; NEW_LINE if ( ( mask | u ) == u ) : NEW_LINE INDENT dp [ u ] = max ( max ( 0 , dp [ u ^ mask ] ) + array [ i ] , dp [ u ] ) ; NEW_LINE DEDENT DEDENT return dp [ u ] ; NEW_LINE DEDENT def solve ( array , n ) : NEW_LINE INDENT i = 0 NEW_LINE while ( i < ( 1 << 10 ) ) : NEW_LINE INDENT dp [ i ] = - 1 ; NEW_LINE i += 1 NEW_LINE DEDENT ans = 0 ; NEW_LINE i = 0 NEW_LINE while ( i < ( 1 << 10 ) ) : NEW_LINE INDENT ans = max ( ans , recur ( i , array , n ) ) ; NEW_LINE i += 1 NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT array = [ 22 , 132 , 4 , 45 , 12 , 223 ] ; NEW_LINE n = len ( array ) ; NEW_LINE print ( solve ( array , n ) ) ; NEW_LINE DEDENT " V657,"import java . io . * ; class GFG { static int findSum ( int N , int K ) { int ans = 0 ; int y = N / K ; int x = N % K ; ans = ( K * ( K - 1 ) / 2 ) * y + ( x * ( x + 1 ) ) / 2 ; return ans ; } static public void main ( String [ ] args ) { int N = 10 , K = 2 ; System . out . println ( findSum ( N , K ) ) ; } } ","def findSum ( N , K ) : NEW_LINE INDENT ans = 0 ; NEW_LINE y = N / K ; NEW_LINE x = N % K ; NEW_LINE ans = ( ( K * ( K - 1 ) / 2 ) * y + ( x * ( x + 1 ) ) / 2 ) ; NEW_LINE return int ( ans ) ; NEW_LINE DEDENT N = 10 ; NEW_LINE K = 2 ; NEW_LINE print ( findSum ( N , K ) ) ; NEW_LINE " V658,"import java . io . * ; class GFG { static int decimalToBinary ( int N ) { int B_Number = 0 ; int cnt = 0 ; while ( N != 0 ) { int rem = N % 2 ; double c = Math . pow ( 10 , cnt ) ; B_Number += rem * c ; N /= 2 ; cnt ++ ; } return B_Number ; } public static void main ( String [ ] args ) { int N = 17 ; System . out . println ( decimalToBinary ( N ) ) ; } } ","def decimalToBinary ( N ) : NEW_LINE INDENT B_Number = 0 NEW_LINE cnt = 0 NEW_LINE while ( N != 0 ) : NEW_LINE INDENT rem = N % 2 NEW_LINE c = pow ( 10 , cnt ) NEW_LINE B_Number += rem * c NEW_LINE N //= 2 NEW_LINE cnt += 1 NEW_LINE DEDENT return B_Number NEW_LINE DEDENT N = 17 NEW_LINE print ( decimalToBinary ( N ) ) NEW_LINE " V659,"public class GFG { static boolean isTriPerfect ( int n ) { int sum = 1 + n ; int i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) { if ( n / i == i ) sum = sum + i ; else sum = sum + i + n / i ; } i += 1 ; } if ( sum == 3 * n & n != 1 ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 120 ; if ( isTriPerfect ( n ) ) System . out . println ( n + "" ▁ is ▁ a ▁ Triperfect ▁ number "" ) ; } } ","def isTriPerfect ( n ) : NEW_LINE INDENT sum = 1 + n NEW_LINE i = 2 NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT if n / i == i : NEW_LINE INDENT sum = sum + i NEW_LINE DEDENT else : NEW_LINE INDENT sum = sum + i + n / i NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT return ( True if sum == 3 * n and n != 1 else False ) NEW_LINE DEDENT n = 120 NEW_LINE if isTriPerfect ( n ) : NEW_LINE INDENT print ( n , "" is ▁ a ▁ Triperfect ▁ number "" ) NEW_LINE DEDENT " V660,"import java . io . * ; import java . util . * ; class GFG { static int xorEqualsOrCount ( int N ) { int count = 0 ; int bit ; while ( N > 0 ) { bit = N % 2 ; if ( bit == 0 ) count ++ ; N = N / 2 ; } return ( int ) Math . pow ( 2 , count ) ; } public static void main ( String args [ ] ) { int N = 7 ; System . out . println ( xorEqualsOrCount ( N ) ) ; } } ","def xorEqualsOrCount ( N ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N > 0 ) : NEW_LINE INDENT bit = N % 2 NEW_LINE if bit == 0 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT N //= 2 NEW_LINE DEDENT return int ( pow ( 2 , count ) ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = 7 NEW_LINE print ( xorEqualsOrCount ( N ) ) NEW_LINE DEDENT " V661,"import java . util . * ; import java . lang . * ; public class GfG { public static boolean judgeSquareSum ( int c ) { for ( long a = 0 ; a * a <= c ; a ++ ) { int b = c - ( int ) ( a * a ) ; if ( binary_search ( 0 , b , b ) ) return true ; } return false ; } public static boolean binary_search ( long s , long e , int n ) { if ( s > e ) return false ; long mid = s + ( e - s ) / 2 ; if ( mid * mid == n ) return true ; if ( mid * mid > n ) return binary_search ( s , mid - 1 , n ) ; return binary_search ( mid + 1 , e , n ) ; } public static void main ( String argc [ ] ) { int c = 17 ; System . out . println ( judgeSquareSum ( c ) ) ; } } ","def judgeSquareSum ( c ) : NEW_LINE INDENT a = 0 ; NEW_LINE while ( a * a <= c ) : NEW_LINE INDENT b = c - int ( a * a ) ; NEW_LINE if ( binary_search ( 0 , b , b ) ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT a += 1 ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT def binary_search ( s , e , n ) : NEW_LINE INDENT if ( s > e ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT mid = s + int ( ( e - s ) / 2 ) ; NEW_LINE if ( int ( mid * mid ) == n ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT if ( int ( mid * mid ) > n ) : NEW_LINE INDENT return binary_search ( s , mid - 1 , n ) ; NEW_LINE DEDENT return binary_search ( mid + 1 , e , n ) ; NEW_LINE DEDENT c = 17 ; NEW_LINE if ( judgeSquareSum ( c ) ) : NEW_LINE INDENT print ( "" true "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" false "" ) ; NEW_LINE DEDENT " V662,"class GFG { static boolean isOdd ( int [ ] arr , int n ) { int l , r , flag = 0 , flag1 = 0 , sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( arr [ i ] % 2 == 0 && flag == 0 ) { flag = 1 ; l = arr [ i ] ; } if ( arr [ i ] % 2 != 0 && flag1 == 0 ) { r = arr [ i ] ; flag1 = 1 ; } } if ( sum % 2 != 0 ) { return true ; } else { if ( flag1 == 1 && flag == 1 ) return true ; else return false ; } } public static void main ( String [ ] args ) { int ar [ ] = { 5 , 4 , 4 , 5 , 1 , 3 } ; int n = ar . length ; boolean res = isOdd ( ar , n ) ; if ( res == true ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isOdd ( arr , n ) : NEW_LINE INDENT flag = 0 ; flag1 = 0 ; sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += arr [ i ] ; NEW_LINE if ( arr [ i ] % 2 == 0 and flag == 0 ) : NEW_LINE INDENT flag = 1 ; NEW_LINE l = arr [ i ] ; NEW_LINE DEDENT if ( arr [ i ] % 2 != 0 and flag1 == 0 ) : NEW_LINE INDENT r = arr [ i ] ; NEW_LINE flag1 = 1 ; NEW_LINE DEDENT DEDENT if ( sum % 2 != 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( flag1 == 1 and flag == 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 5 , 4 , 4 , 5 , 1 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE res = isOdd ( arr , n ) ; NEW_LINE if ( res ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE DEDENT DEDENT " V663,"import java . io . * ; class GFG { static int nthTerm ( int n ) { return 3 * ( int ) Math . pow ( n , 2 ) + 2 * n - 5 ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } } ","def nthTerm ( n ) : NEW_LINE INDENT return 3 * pow ( n , 2 ) + 2 * n - 5 NEW_LINE DEDENT N = 4 NEW_LINE print ( nthTerm ( N ) ) NEW_LINE " V664,"import java . util . * ; class GFG { static int MAX = 26 ; static String smallestStr ( char [ ] str , int n ) { int i , j = 0 ; int [ ] chk = new int [ MAX ] ; for ( i = 0 ; i < MAX ; i ++ ) chk [ i ] = - 1 ; for ( i = 0 ; i < n ; i ++ ) { if ( chk [ str [ i ] - ' a ' ] == - 1 ) chk [ str [ i ] - ' a ' ] = i ; } for ( i = 0 ; i < n ; i ++ ) { boolean flag = false ; for ( j = 0 ; j < str [ i ] - ' a ' ; j ++ ) { if ( chk [ j ] > chk [ str [ i ] - ' a ' ] ) { flag = true ; break ; } } if ( flag ) break ; } if ( i < n ) { char ch1 = str [ i ] ; char ch2 = ( char ) ( j + ' a ' ) ; for ( i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ch1 ) str [ i ] = ch2 ; else if ( str [ i ] == ch2 ) str [ i ] = ch1 ; } } return String . valueOf ( str ) ; } public static void main ( String [ ] args ) { String str = "" ccad "" ; int n = str . length ( ) ; System . out . println ( smallestStr ( str . toCharArray ( ) , n ) ) ; } } ","MAX = 256 NEW_LINE def smallestStr ( str , n ) : NEW_LINE INDENT i , j = 0 , 0 NEW_LINE chk = [ 0 for i in range ( MAX ) ] NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT chk [ i ] = - 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( chk [ ord ( str [ i ] ) ] == - 1 ) : NEW_LINE INDENT chk [ ord ( str [ i ] ) ] = i NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT flag = False NEW_LINE for j in range ( ord ( str [ i ] ) ) : NEW_LINE INDENT if ( chk [ j ] > chk [ ord ( str [ i ] ) ] ) : NEW_LINE INDENT flag = True NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( i < n ) : NEW_LINE INDENT ch1 = ( str [ i ] ) NEW_LINE ch2 = chr ( j ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( str [ i ] == ch1 ) : NEW_LINE INDENT str [ i ] = ch2 NEW_LINE DEDENT elif ( str [ i ] == ch2 ) : NEW_LINE INDENT str [ i ] = ch1 NEW_LINE DEDENT DEDENT DEDENT return "" "" . join ( str ) NEW_LINE DEDENT st = "" ccad "" NEW_LINE str = [ i for i in st ] NEW_LINE n = len ( str ) NEW_LINE print ( smallestStr ( str , n ) ) NEW_LINE " V665,"import java . util . * ; class GFG { static int N = 3 ; static int numberOfCells ( int mat [ ] [ ] ) { boolean [ ] [ ] row = new boolean [ N ] [ N ] ; boolean [ ] [ ] col = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { if ( mat [ i ] [ j ] == 1 ) { row [ i ] [ j ] = ( j + 1 < N ) ? row [ i ] [ j + 1 ] : true ; } else { row [ i ] [ j ] = false ; } } } for ( int j = 0 ; j < N ; j ++ ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( mat [ i ] [ j ] == 1 ) { col [ i ] [ j ] = ( i + 1 < N ) ? col [ i + 1 ] [ j ] : true ; } else { col [ i ] [ j ] = false ; } } } int cnt = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ i ] [ j ] && col [ i ] [ j ] ) { cnt ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( col [ i ] [ N - 1 ] ) cnt ++ ; } for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( row [ N - 1 ] [ j ] ) cnt ++ ; } return cnt ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 0 , 1 , 1 } , { 0 , 1 , 1 } , { 0 , 1 , 1 } } ; System . out . print ( numberOfCells ( mat ) ) ; } } ","N = 3 NEW_LINE def numberOfCells ( mat ) : NEW_LINE INDENT row = [ [ False for i in range ( N ) ] for i in range ( N ) ] NEW_LINE col = [ [ False for i in range ( N ) ] for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT if j + 1 < N : NEW_LINE INDENT row [ i ] [ j ] = row [ i ] [ j + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT row [ i ] [ j ] = True NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT row [ i ] [ j ] = False NEW_LINE DEDENT DEDENT DEDENT for j in range ( N ) : NEW_LINE INDENT for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT if i + 1 < N : NEW_LINE INDENT col [ i ] [ j ] = col [ i + 1 ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT col [ i ] [ j ] = True NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT col [ i ] [ j ] = False NEW_LINE DEDENT DEDENT DEDENT cnt = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j in range ( N - 1 ) : NEW_LINE INDENT if ( row [ i ] [ j ] and col [ i ] [ j ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT if ( col [ i ] [ N - 1 ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT for j in range ( N - 1 ) : NEW_LINE INDENT if ( row [ N - 1 ] [ j ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT mat = [ [ 0 , 1 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 1 , 1 ] ] NEW_LINE print ( numberOfCells ( mat ) ) NEW_LINE " V666,"class GFG { static void printRLE ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int count = 1 ; while ( i + 1 < s . length ( ) && s . charAt ( i ) == s . charAt ( i + 1 ) ) { i ++ ; count ++ ; } System . out . print ( s . charAt ( i ) + "" "" + count + "" ▁ "" ) ; } System . out . println ( ) ; } public static void main ( String args [ ] ) { printRLE ( "" GeeeEEKKKss "" ) ; printRLE ( "" ccccOddEEE "" ) ; } } ","def printRLE ( s ) : NEW_LINE INDENT i = 0 NEW_LINE while ( i < len ( s ) - 1 ) : NEW_LINE INDENT count = 1 NEW_LINE while s [ i ] == s [ i + 1 ] : NEW_LINE INDENT i += 1 NEW_LINE count += 1 NEW_LINE if i + 1 == len ( s ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( str ( s [ i ] ) + str ( count ) , end = "" ▁ "" ) NEW_LINE i += 1 NEW_LINE DEDENT print ( ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT printRLE ( "" GeeeEEKKKss "" ) NEW_LINE printRLE ( "" cccc0ddEEE "" ) NEW_LINE DEDENT " V667,"import java . util . HashMap ; class Test { static int arr [ ] = new int [ ] { 1 , 5 , 7 , - 1 , 5 } ; static int getPairsCount ( int n , int sum ) { HashMap < Integer , Integer > hm = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ; hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ; } int twice_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ; if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ; } return twice_count / 2 ; } public static void main ( String [ ] args ) { int sum = 6 ; System . out . println ( "" Count ▁ of ▁ pairs ▁ is ▁ "" + getPairsCount ( arr . length , sum ) ) ; } } ","import sys NEW_LINE def getPairsCount ( arr , n , sum ) : NEW_LINE INDENT m = [ 0 ] * 1000 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT m [ arr [ i ] ] NEW_LINE m [ arr [ i ] ] += 1 NEW_LINE DEDENT twice_count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT twice_count += m [ sum - arr [ i ] ] NEW_LINE if ( sum - arr [ i ] == arr [ i ] ) : NEW_LINE INDENT twice_count -= 1 NEW_LINE DEDENT DEDENT return int ( twice_count / 2 ) NEW_LINE DEDENT arr = [ 1 , 5 , 7 , - 1 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE sum = 6 NEW_LINE print ( "" Count ▁ of ▁ pairs ▁ is "" , getPairsCount ( arr , n , sum ) ) NEW_LINE " V668,"class GFG { public static void main ( String [ ] args ) { int matrix [ ] [ ] = new int [ 5 ] [ 5 ] , row_index , column_index , x = 0 , size = 5 ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { matrix [ row_index ] [ column_index ] = ++ x ; } } System . out . printf ( "" The ▁ matrix ▁ is \n "" ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { System . out . printf ( "" % d\t "" , matrix [ row_index ] [ column_index ] ) ; } System . out . printf ( "" \n "" ) ; } System . out . printf ( "" \n Boundary ▁ Elements ▁ are : \n "" ) ; for ( row_index = 0 ; row_index < size ; row_index ++ ) { for ( column_index = 0 ; column_index < size ; column_index ++ ) { if ( ( row_index == 0 || row_index == size - 1 || column_index == 0 || column_index == size - 1 ) ) { System . out . printf ( "" % d , ▁ "" , matrix [ row_index ] [ column_index ] ) ; } } } } } ","if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT matrix = [ [ 0 for i in range ( 5 ) ] for j in range ( 5 ) ] NEW_LINE row_index , column_index , x , size = 0 , 0 , 0 , 5 ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT x += 1 ; NEW_LINE matrix [ row_index ] [ column_index ] = x ; NEW_LINE DEDENT DEDENT print ( "" The ▁ matrix ▁ is "" ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = "" \t "" ) ; NEW_LINE DEDENT print ( "" "" ) ; NEW_LINE DEDENT print ( "" \n Boundary ▁ Elements ▁ are : "" ) ; NEW_LINE for row_index in range ( size ) : NEW_LINE INDENT for column_index in range ( size ) : NEW_LINE INDENT if ( ( row_index == 0 or row_index == size - 1 \ or column_index == 0 or column_index == size - 1 ) ) : NEW_LINE INDENT print ( matrix [ row_index ] [ column_index ] , end = "" , ▁ "" ) ; NEW_LINE DEDENT DEDENT DEDENT DEDENT " V669,"class GFG { public static boolean isPrime ( char c ) { return ( c == '2' || c == '3' || c == '5' || c == '7' ) ; } public static void decrease ( StringBuilder s , int i ) { if ( s . charAt ( i ) <= '2' ) { s . deleteCharAt ( i ) ; s . setCharAt ( i , '7' ) ; } else if ( s . charAt ( i ) == '3' ) s . setCharAt ( i , '2' ) ; else if ( s . charAt ( i ) <= '5' ) s . setCharAt ( i , '3' ) ; else if ( s . charAt ( i ) <= '7' ) s . setCharAt ( i , '5' ) ; else s . setCharAt ( i , '7' ) ; return ; } public static String primeDigits ( StringBuilder s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! isPrime ( s . charAt ( i ) ) ) { while ( i >= 0 && s . charAt ( i ) <= '2' ) i -- ; if ( i < 0 ) { i = 0 ; decrease ( s , i ) ; } else decrease ( s , i ) ; for ( int j = i + 1 ; j < s . length ( ) ; j ++ ) s . setCharAt ( j , '7' ) ; break ; } } return s . toString ( ) ; } public static void main ( String [ ] args ) { StringBuilder s = new StringBuilder ( ""45"" ) ; System . out . println ( primeDigits ( s ) ) ; s = new StringBuilder ( ""1000"" ) ; System . out . println ( primeDigits ( s ) ) ; s = new StringBuilder ( ""7721"" ) ; System . out . println ( primeDigits ( s ) ) ; s = new StringBuilder ( ""7221"" ) ; System . out . println ( primeDigits ( s ) ) ; s = new StringBuilder ( ""74545678912345689748593275897894708927680"" ) ; System . out . println ( primeDigits ( s ) ) ; } } ","def isPrime ( c ) : NEW_LINE INDENT return ( c == '2' or c == '3' or c == '5' or c == '7' ) NEW_LINE DEDENT def decrease ( s , i ) : NEW_LINE INDENT if ( s [ i ] <= '2' ) : NEW_LINE INDENT s [ i ] = '7' NEW_LINE DEDENT elif ( s [ i ] == '3' ) : NEW_LINE INDENT s [ i ] = '2' NEW_LINE DEDENT elif ( s [ i ] <= '5' ) : NEW_LINE INDENT s [ i ] = '3' NEW_LINE DEDENT elif ( s [ i ] <= '7' ) : NEW_LINE INDENT s [ i ] = '5' NEW_LINE DEDENT else : NEW_LINE INDENT s [ i ] = '7' NEW_LINE DEDENT DEDENT def primeDigits ( s ) : NEW_LINE INDENT s = [ i for i in s ] NEW_LINE i = 0 NEW_LINE while i < len ( s ) : NEW_LINE INDENT if ( isPrime ( s [ i ] ) == False ) : NEW_LINE INDENT while ( s [ i ] <= '2' and i >= 0 ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT if ( i < 0 ) : NEW_LINE INDENT i = 0 NEW_LINE decrease ( s , i ) NEW_LINE DEDENT else : NEW_LINE INDENT decrease ( s , i ) NEW_LINE DEDENT for j in range ( i + 1 , len ( s ) ) : NEW_LINE INDENT s [ j ] = '7' NEW_LINE DEDENT break NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return "" "" . join ( s ) NEW_LINE DEDENT s = ""45"" NEW_LINE print ( primeDigits ( s ) ) NEW_LINE s = ""1000"" NEW_LINE print ( primeDigits ( s ) ) NEW_LINE s = ""7721"" NEW_LINE print ( primeDigits ( s ) ) NEW_LINE s = ""7221"" NEW_LINE print ( primeDigits ( s ) ) NEW_LINE s = ""74545678912345689748593275897894708927680"" NEW_LINE print ( primeDigits ( s ) ) NEW_LINE " V670,"import java . io . * ; class GFG { static int N = 1000005 ; static int primeFactors [ ] = new int [ N ] ; static void findPrimeFactors ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( primeFactors [ i ] == 0 ) for ( int j = i ; j < N ; j += i ) primeFactors [ j ] = primeFactors [ j / i ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) primeFactors [ i ] += primeFactors [ i - 1 ] ; } public static void main ( String [ ] args ) { findPrimeFactors ( ) ; int a = 6 , b = 3 ; System . out . println ( primeFactors [ a ] - primeFactors [ b ] ) ; } } ","N = 1000005 NEW_LINE primeFactors = [ 0 ] * N ; NEW_LINE def findPrimeFactors ( ) : NEW_LINE INDENT for i in range ( 2 , N ) : NEW_LINE INDENT if ( primeFactors [ i ] == 0 ) : NEW_LINE INDENT for j in range ( i , N , i ) : NEW_LINE INDENT primeFactors [ j ] = primeFactors [ j // i ] + 1 ; NEW_LINE DEDENT DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT primeFactors [ i ] += primeFactors [ i - 1 ] ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT findPrimeFactors ( ) ; NEW_LINE a = 6 ; b = 3 ; NEW_LINE print ( primeFactors [ a ] - primeFactors [ b ] ) ; NEW_LINE DEDENT " V671,"import java . io . * ; import java . util . * ; class GFG { static void findNDigitNumsUtil ( int n , char out [ ] , int index , int evenSum , int oddSum ) { if ( index > n ) return ; if ( index == n ) { if ( Math . abs ( evenSum - oddSum ) == 1 ) { out [ index ] = ''; System . out . print ( out ) ; System . out . print ( "" ▁ "" ) ; } return ; } if ( index % 2 != 0 ) { for ( int i = 0 ; i <= 9 ; i ++ ) { out [ index ] = ( char ) ( i + '0' ) ; findNDigitNumsUtil ( n , out , index + 1 , evenSum , oddSum + i ) ; } } else { for ( int i = 0 ; i <= 9 ; i ++ ) { out [ index ] = ( char ) ( i + '0' ) ; findNDigitNumsUtil ( n , out , index + 1 , evenSum + i , oddSum ) ; } } } static void findNDigitNums ( int n ) { char [ ] out = new char [ n + 1 ] ; int index = 0 ; int evenSum = 0 , oddSum = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) { out [ index ] = ( char ) ( i + '0' ) ; findNDigitNumsUtil ( n , out , index + 1 , evenSum + i , oddSum ) ; } } public static void main ( String [ ] args ) { int n = 3 ; findNDigitNums ( n ) ; } } ","def findNDigitNumsUtil ( n , out , index , evenSum , oddSum ) : NEW_LINE INDENT if ( index > n ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( index == n ) : NEW_LINE INDENT if ( abs ( evenSum - oddSum ) == 1 ) : NEW_LINE INDENT out [ index ] = ' ' NEW_LINE out = ' ' . join ( out ) NEW_LINE print ( out , end = "" ▁ "" ) NEW_LINE DEDENT return NEW_LINE DEDENT if ( index & 1 ) : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT out [ index ] = chr ( i + ord ( '0' ) ) NEW_LINE findNDigitNumsUtil ( n , out , index + 1 , evenSum , oddSum + i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT out [ index ] = chr ( i + ord ( '0' ) ) NEW_LINE findNDigitNumsUtil ( n , out , index + 1 , evenSum + i , oddSum ) NEW_LINE DEDENT DEDENT DEDENT def findNDigitNums ( n ) : NEW_LINE INDENT out = [ 0 ] * ( n + 1 ) NEW_LINE index = 0 NEW_LINE evenSum = 0 NEW_LINE oddSum = 0 NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT out [ index ] = chr ( i + ord ( '0' ) ) NEW_LINE findNDigitNumsUtil ( n , out , index + 1 , evenSum + i , oddSum ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 3 NEW_LINE findNDigitNums ( n ) NEW_LINE DEDENT " V672,"import java . util . Arrays ; import java . io . * ; class GFG { static int ksmallest ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; if ( k < arr [ 0 ] ) return k ; if ( k == arr [ 0 ] ) return arr [ 0 ] + 1 ; if ( k > arr [ n - 1 ] ) return k + n ; if ( arr [ 0 ] == 1 ) k -- ; else k -= ( arr [ 0 ] - 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { int c = arr [ i ] - arr [ i - 1 ] - 1 ; if ( k <= c ) return arr [ i - 1 ] + k ; else k -= c ; } return arr [ n - 1 ] + k ; } public static void main ( String [ ] args ) { int k = 1 ; int arr [ ] = { 1 } ; int n = arr . length ; System . out . println ( ksmallest ( arr , n , k ) ) ; } } ","def ksmallest ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE if ( k < arr [ 0 ] ) : NEW_LINE INDENT return k ; NEW_LINE DEDENT if ( k == arr [ 0 ] ) : NEW_LINE INDENT return arr [ 0 ] + 1 ; NEW_LINE DEDENT if ( k > arr [ n - 1 ] ) : NEW_LINE INDENT return k + n ; NEW_LINE DEDENT if ( arr [ 0 ] == 1 ) : NEW_LINE INDENT k -= 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT k -= ( arr [ 0 ] - 1 ) ; NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT c = arr [ i ] - arr [ i - 1 ] - 1 ; NEW_LINE if ( k <= c ) : NEW_LINE INDENT return arr [ i - 1 ] + k ; NEW_LINE DEDENT else : NEW_LINE INDENT k -= c ; NEW_LINE DEDENT DEDENT return arr [ n - 1 ] + k ; NEW_LINE DEDENT k = 1 ; NEW_LINE arr = [ 1 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( ksmallest ( arr , n , k ) ) ; NEW_LINE " V673,"import java . util . * ; class Solution { static class NodeDetails { int data ; int min , max ; } ; static boolean levelOrderIsOfBST ( int arr [ ] , int n ) { if ( n == 0 ) return true ; Queue < NodeDetails > q = new LinkedList < NodeDetails > ( ) ; int i = 0 ; NodeDetails newNode = new NodeDetails ( ) ; newNode . data = arr [ i ++ ] ; newNode . min = Integer . MIN_VALUE ; newNode . max = Integer . MAX_VALUE ; q . add ( newNode ) ; while ( i != n && q . size ( ) > 0 ) { NodeDetails temp = q . peek ( ) ; q . remove ( ) ; newNode = new NodeDetails ( ) ; if ( i < n && ( arr [ i ] < ( int ) temp . data && arr [ i ] > ( int ) temp . min ) ) { newNode . data = arr [ i ++ ] ; newNode . min = temp . min ; newNode . max = temp . data ; q . add ( newNode ) ; } newNode = new NodeDetails ( ) ; if ( i < n && ( arr [ i ] > ( int ) temp . data && arr [ i ] < ( int ) temp . max ) ) { newNode . data = arr [ i ++ ] ; newNode . min = temp . data ; newNode . max = temp . max ; q . add ( newNode ) ; } } if ( i == n ) return true ; return false ; } public static void main ( String args [ ] ) { int arr [ ] = { 7 , 4 , 12 , 3 , 6 , 8 , 1 , 5 , 10 } ; int n = arr . length ; if ( levelOrderIsOfBST ( arr , n ) ) System . out . print ( "" Yes "" ) ; else System . out . print ( "" No "" ) ; } } ","INT_MIN , INT_MAX = float ( ' - inf ' ) , float ( ' inf ' ) NEW_LINE class NodeDetails : NEW_LINE INDENT def __init__ ( self , data , min , max ) : NEW_LINE INDENT self . data = data NEW_LINE self . min = min NEW_LINE self . max = max NEW_LINE DEDENT DEDENT def levelOrderIsOfBST ( arr , n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT q = [ ] NEW_LINE i = 0 NEW_LINE newNode = NodeDetails ( arr [ i ] , INT_MIN , INT_MAX ) NEW_LINE i += 1 NEW_LINE q . append ( newNode ) NEW_LINE while i != n and len ( q ) != 0 : NEW_LINE INDENT temp = q . pop ( 0 ) NEW_LINE if i < n and ( arr [ i ] < temp . data and arr [ i ] > temp . min ) : NEW_LINE INDENT newNode = NodeDetails ( arr [ i ] , temp . min , temp . data ) NEW_LINE i += 1 NEW_LINE q . append ( newNode ) NEW_LINE DEDENT if i < n and ( arr [ i ] > temp . data and arr [ i ] < temp . max ) : NEW_LINE INDENT newNode = NodeDetails ( arr [ i ] , temp . data , temp . max ) NEW_LINE i += 1 NEW_LINE q . append ( newNode ) NEW_LINE DEDENT DEDENT if i == n : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 7 , 4 , 12 , 3 , 6 , 8 , 1 , 5 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE if levelOrderIsOfBST ( arr , n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V674,"class GFG { public static void main ( String args [ ] ) { int marks [ ] = { 25 , 65 , 46 , 98 , 78 , 65 } ; int max_marks = marks . length * 100 ; int total = 0 ; char grade = ' F ' ; for ( int i = 0 ; i < marks . length ; i ++ ) { total += marks [ i ] ; } double percentage = ( ( double ) ( total ) / max_marks ) * 100 ; if ( percentage >= 90 ) { grade = ' A ' ; } else { if ( percentage >= 80 && percentage <= 89 ) { grade = ' B ' ; } else { if ( percentage >= 60 && percentage <= 79 ) { grade = ' C ' ; } else { if ( percentage >= 33 && percentage <= 59 ) { grade = ' D ' ; } else { grade = ' F ' ; } } } } System . out . println ( grade ) ; } } ","if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT marks = [ 25 , 65 , 46 , 98 , 78 , 65 ] NEW_LINE max_marks = len ( marks ) * 100 NEW_LINE total = 0 NEW_LINE grade = ' F ' NEW_LINE for i in range ( len ( marks ) ) : NEW_LINE INDENT total += marks [ i ] NEW_LINE DEDENT percentage = ( ( total ) / max_marks ) * 100 NEW_LINE if ( percentage >= 90 ) : NEW_LINE INDENT grade = ' A ' NEW_LINE DEDENT else : NEW_LINE INDENT if ( percentage >= 80 and percentage <= 89 ) : NEW_LINE INDENT grade = ' B ' NEW_LINE DEDENT else : NEW_LINE INDENT if ( percentage >= 60 and percentage <= 79 ) : NEW_LINE INDENT grade = ' C ' NEW_LINE DEDENT else : NEW_LINE INDENT if ( percentage >= 33 and percentage <= 59 ) : NEW_LINE INDENT grade = ' D ' NEW_LINE DEDENT else : NEW_LINE INDENT grade = ' F ' NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( grade ) NEW_LINE DEDENT " V675,"import java . io . * ; class GFG { static void printPartition ( int n , int m ) { int k = n / m ; int ct = n % m ; int i ; for ( i = 1 ; i <= ct ; i ++ ) System . out . print ( k + 1 + "" ▁ "" ) ; for ( ; i <= m ; i ++ ) System . out . print ( k + "" ▁ "" ) ; } public static void main ( String [ ] args ) { int n = 5 , m = 2 ; printPartition ( n , m ) ; } } ","def printPartition ( n , m ) : NEW_LINE INDENT k = int ( n / m ) NEW_LINE ct = n % m NEW_LINE for i in range ( 1 , ct + 1 , 1 ) : NEW_LINE INDENT print ( k + 1 , end = "" ▁ "" ) NEW_LINE DEDENT count = i NEW_LINE for i in range ( count , m , 1 ) : NEW_LINE INDENT print ( k , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE m = 2 NEW_LINE printPartition ( n , m ) NEW_LINE DEDENT " V676,"class GFG { static int prevComplement ( int n , int b ) { int maxDigit , maxNum = 0 , digits = 0 , num = n ; while ( n != 0 ) { digits ++ ; n = n / 10 ; } maxDigit = b - 1 ; while ( ( digits -- ) > 0 ) { maxNum = maxNum * 10 + maxDigit ; } return maxNum - num ; } static int complement ( int n , int b ) { return prevComplement ( n , b ) + 1 ; } public static void main ( String args [ ] ) { System . out . println ( prevComplement ( 25 , 7 ) ) ; System . out . println ( complement ( 25 , 7 ) ) ; } } ","def prevComplement ( n , b ) : NEW_LINE INDENT maxNum , digits , num = 0 , 0 , n NEW_LINE while n > 1 : NEW_LINE INDENT digits += 1 NEW_LINE n = n // 10 NEW_LINE DEDENT maxDigit = b - 1 NEW_LINE while digits : NEW_LINE INDENT maxNum = maxNum * 10 + maxDigit NEW_LINE digits -= 1 NEW_LINE DEDENT return maxNum - num NEW_LINE DEDENT def complement ( n , b ) : NEW_LINE INDENT return prevComplement ( n , b ) + 1 NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( prevComplement ( 25 , 7 ) ) NEW_LINE print ( complement ( 25 , 7 ) ) NEW_LINE DEDENT " V677,"class GFG { static int N = 1000 ; static int countPairs ( int arr [ ] , int n ) { int size = ( 2 * N ) + 1 ; int freq [ ] = new int [ size ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; freq [ x + N ] ++ ; } int ans = 0 ; for ( int i = 0 ; i < size ; i ++ ) { if ( freq [ i ] > 0 ) { ans += ( ( freq [ i ] ) * ( freq [ i ] - 1 ) ) / 2 ; for ( int j = i + 2 ; j < 2001 ; j += 2 ) { if ( freq [ j ] > 0 && ( freq [ ( i + j ) / 2 ] > 0 ) ) { ans += ( freq [ i ] * freq [ j ] ) ; } } } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 5 , 1 , 3 , 5 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } } ","N = 1000 NEW_LINE def countPairs ( arr , n ) : NEW_LINE INDENT size = ( 2 * N ) + 1 NEW_LINE freq = [ 0 for i in range ( size ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = arr [ i ] NEW_LINE freq [ x + N ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( size ) : NEW_LINE INDENT if ( freq [ i ] > 0 ) : NEW_LINE INDENT ans += int ( ( ( freq [ i ] ) * ( freq [ i ] - 1 ) ) / 2 ) NEW_LINE for j in range ( i + 2 , 2001 , 2 ) : NEW_LINE INDENT if ( freq [ j ] > 0 and ( freq [ int ( ( i + j ) / 2 ) ] > 0 ) ) : NEW_LINE INDENT ans += ( freq [ i ] * freq [ j ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 2 , 5 , 1 , 3 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countPairs ( arr , n ) ) NEW_LINE DEDENT " V678,"import java . io . * ; public class GFG { static int countToMake0lternate ( String s ) { int result = 0 ; for ( int i = 0 ; i < ( s . length ( ) - 1 ) ; i ++ ) if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) result ++ ; return result ; } static public void main ( String [ ] args ) { System . out . println ( countToMake0lternate ( ""000111"" ) ) ; System . out . println ( countToMake0lternate ( ""11111"" ) ) ; System . out . println ( countToMake0lternate ( ""01010101"" ) ) ; } } ","def countToMake0lternate ( s ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( len ( s ) - 1 ) : NEW_LINE INDENT if ( s [ i ] == s [ i + 1 ] ) : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( countToMake0lternate ( ""000111"" ) ) NEW_LINE print ( countToMake0lternate ( ""11111"" ) ) NEW_LINE print ( countToMake0lternate ( ""01010101"" ) ) NEW_LINE DEDENT " V679,"class GFG { static void numOfSubseq ( int arr [ ] , int n ) { int i , inc_count , dec_count ; int max [ ] = new int [ n ] ; int min [ ] = new int [ n ] ; int k1 = 0 , k2 = 0 ; if ( arr [ 0 ] < arr [ 1 ] ) min [ k1 ++ ] = 0 ; else max [ k2 ++ ] = 0 ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) min [ k1 ++ ] = i ; if ( arr [ i ] > arr [ i - 1 ] && arr [ i ] > arr [ i + 1 ] ) max [ k2 ++ ] = i ; } if ( arr [ n - 1 ] < arr [ n - 2 ] ) min [ k1 ++ ] = n - 1 ; else max [ k2 ++ ] = n - 1 ; if ( min [ 0 ] == 0 ) { inc_count = k2 ; dec_count = k1 - 1 ; } else { inc_count = k2 - 1 ; dec_count = k1 ; } System . out . println ( "" Increasing ▁ Subsequence "" + "" ▁ Count : ▁ "" + inc_count ) ; System . out . println ( "" Decreasing ▁ Subsequence "" + "" ▁ Count : ▁ "" + dec_count ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 8 , 11 , 13 , 10 , 15 , 14 , 16 , 20 } ; int n = arr . length ; numOfSubseq ( arr , n ) ; } } ","def numOfSubseq ( arr , n ) : NEW_LINE INDENT i , inc_count , dec_count = 0 , 0 , 0 ; NEW_LINE max = [ 0 ] * n ; NEW_LINE min = [ 0 ] * n ; NEW_LINE k1 = 0 ; NEW_LINE k2 = 0 ; NEW_LINE if ( arr [ 0 ] < arr [ 1 ] ) : NEW_LINE INDENT min [ k1 ] = 0 ; NEW_LINE k1 += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT max [ k2 ] = 0 ; NEW_LINE k2 += 1 ; NEW_LINE DEDENT for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) : NEW_LINE INDENT min [ k1 ] = i ; NEW_LINE k1 += 1 ; NEW_LINE DEDENT if ( arr [ i ] > arr [ i - 1 ] and arr [ i ] > arr [ i + 1 ] ) : NEW_LINE INDENT max [ k2 ] = i ; NEW_LINE k2 += 1 ; NEW_LINE DEDENT DEDENT if ( arr [ n - 1 ] < arr [ n - 2 ] ) : NEW_LINE INDENT min [ k1 ] = n - 1 ; NEW_LINE k1 += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT max [ k2 ] = n - 1 ; NEW_LINE k2 += 1 ; NEW_LINE DEDENT if ( min [ 0 ] == 0 ) : NEW_LINE INDENT inc_count = k2 ; NEW_LINE dec_count = k1 - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT inc_count = k2 - 1 ; NEW_LINE dec_count = k1 ; NEW_LINE DEDENT print ( "" Increasing ▁ Subsequence ▁ Count : ▁ "" , inc_count ) ; NEW_LINE print ( "" Decreasing ▁ Subsequence ▁ Count : ▁ "" , dec_count ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 8 , 11 , 13 , 10 , 15 , 14 , 16 , 20 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE numOfSubseq ( arr , n ) ; NEW_LINE DEDENT " V680,"public class gfg { static int N = 10000 ; static long arr [ ] = new long [ N ] ; static void seive ( ) { for ( int i = 2 ; i * i < N ; i ++ ) { if ( arr [ i ] == 0 ) { for ( int j = 2 ; i * j < N ; j ++ ) { arr [ i * j ] += i ; } } } } static long sum ( int l , int r ) { seive ( ) ; long [ ] pref_arr = new long [ r + 1 ] ; pref_arr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i <= r ; i ++ ) { pref_arr [ i ] = pref_arr [ i - 1 ] + arr [ i ] ; } if ( l == 1 ) return ( pref_arr [ r ] ) ; else return ( pref_arr [ r ] - pref_arr [ l - 1 ] ) ; } public static void main ( String [ ] args ) { int l = 5 , r = 10 ; System . out . println ( sum ( l , r ) ) ; } } ","N = 10000 ; NEW_LINE arr = [ 0 ] * N ; NEW_LINE def seive ( ) : NEW_LINE INDENT i = 2 ; NEW_LINE while ( i * i < N ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT j = 2 ; NEW_LINE while ( i * j < N ) : NEW_LINE INDENT arr [ i * j ] += i ; NEW_LINE j += 1 ; NEW_LINE DEDENT DEDENT i += 1 ; NEW_LINE DEDENT DEDENT def sum ( l , r ) : NEW_LINE INDENT seive ( ) ; NEW_LINE pref_arr = [ 0 ] * ( r + 1 ) ; NEW_LINE pref_arr [ 0 ] = arr [ 0 ] ; NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT pref_arr [ i ] = pref_arr [ i - 1 ] + arr [ i ] ; NEW_LINE DEDENT if ( l == 1 ) : NEW_LINE INDENT return ( pref_arr [ r ] ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( pref_arr [ r ] - pref_arr [ l - 1 ] ) ; NEW_LINE DEDENT DEDENT l = 5 ; NEW_LINE r = 10 ; NEW_LINE print ( sum ( l , r ) ) ; NEW_LINE " V681,"import java . lang . * ; class GFG { static double PI = 3.14159265 ; public static double area_cicumscribed ( double c ) { return ( c * c * ( PI / 4 ) ) ; } public static void main ( String [ ] args ) { double c = 8.0 ; System . out . println ( area_cicumscribed ( c ) ) ; } } ","PI = 3.14159265 NEW_LINE def area_cicumscribed ( c ) : NEW_LINE INDENT return ( c * c * ( PI / 4 ) ) NEW_LINE DEDENT c = 8.0 NEW_LINE print ( area_cicumscribed ( c ) ) NEW_LINE " V682,"import java . util . * ; class GFG { static int N = 3 ; static int M = 3 ; static int majorityInMatrix ( int arr [ ] [ ] ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mp . containsKey ( arr [ i ] [ j ] ) ) mp . put ( arr [ i ] [ j ] , mp . get ( arr [ i ] [ j ] ) + 1 ) ; else mp . put ( arr [ i ] [ j ] , 1 ) ; } } int countMajority = 0 ; Iterator < HashMap . Entry < Integer , Integer > > itr = mp . entrySet ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { HashMap . Entry < Integer , Integer > entry = itr . next ( ) ; if ( entry . getValue ( ) >= ( ( N * M ) / 2 ) ) { countMajority ++ ; } } return countMajority ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 2 , 2 } , { 1 , 3 , 2 } , { 1 , 2 , 6 } } ; System . out . println ( majorityInMatrix ( mat ) ) ; } } ","N = 3 NEW_LINE M = 3 NEW_LINE def majorityInMatrix ( arr ) : NEW_LINE INDENT mp = { i : 0 for i in range ( 7 ) } NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT for j in range ( len ( arr ) ) : NEW_LINE INDENT mp [ arr [ i ] [ j ] ] += 1 NEW_LINE DEDENT DEDENT countMajority = 0 NEW_LINE for key , value in mp . items ( ) : NEW_LINE INDENT if ( value >= ( int ( ( N * M ) / 2 ) ) ) : NEW_LINE INDENT countMajority += 1 NEW_LINE DEDENT DEDENT return countMajority NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 1 , 2 , 2 ] , [ 1 , 3 , 2 ] , [ 1 , 2 , 6 ] ] NEW_LINE print ( majorityInMatrix ( mat ) ) NEW_LINE DEDENT " V683,"class GFG { static void printSumSeries ( int N ) { float sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += 1.0 / ( 2 * i - 1 ) ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int N = 6 ; printSumSeries ( N ) ; } } ","def printSumSeries ( N ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT sum += 1.0 / ( 2 * i - 1 ) ; NEW_LINE DEDENT print ( sum ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT N = 6 ; NEW_LINE printSumSeries ( N ) ; NEW_LINE DEDENT " V684,"class GFG { static int deleteElement ( int A [ ] , int L , int R , int N ) { int i , j = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( i <= L || i >= R ) { A [ j ] = A [ i ] ; j ++ ; } } return j ; } public static void main ( String args [ ] ) { int A [ ] = new int [ ] { 5 , 8 , 11 , 15 , 26 , 14 , 19 , 17 , 10 , 14 } ; int L = 2 , R = 7 ; int n = A . length ; int res_size = deleteElement ( A , L , R , n ) ; for ( int i = 0 ; i < res_size ; i ++ ) System . out . print ( A [ i ] + "" ▁ "" ) ; } } ","def deleteElement ( A , L , R , N ) : NEW_LINE INDENT j = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if i <= L or i >= R : NEW_LINE INDENT A [ j ] = A [ i ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT return j NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT A = [ 5 , 8 , 11 , 15 , 26 , 14 , 19 , 17 , 10 , 14 ] NEW_LINE L , R = 2 , 7 NEW_LINE n = len ( A ) NEW_LINE res_size = deleteElement ( A , L , R , n ) NEW_LINE for i in range ( res_size ) : NEW_LINE INDENT print ( A [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V685,"import java . util . * ; class GFG { static boolean areElementsContiguous ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] > 1 ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 } ; int n = arr . length ; if ( areElementsContiguous ( arr , n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def areElementsContiguous ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i - 1 ] > 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT return 1 NEW_LINE DEDENT arr = [ 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE if areElementsContiguous ( arr , n ) : print ( "" Yes "" ) NEW_LINE else : print ( "" No "" ) NEW_LINE " V686,"class GFG { final static int maxin = 10001 ; static int divisors [ ] = new int [ maxin + 1 ] ; static void Calc_Max_Div ( int arr [ ] , int n ) { int vis [ ] = new int [ maxin + 1 ] ; for ( int i = 0 ; i < maxin + 1 ; i ++ ) vis [ i ] = 1 ; vis [ 0 ] = vis [ 1 ] = 0 ; for ( int i = 1 ; i <= maxin ; i ++ ) divisors [ i ] = i ; for ( int i = 4 ; i <= maxin ; i += 2 ) { vis [ i ] = 0 ; divisors [ i ] = i / 2 ; } for ( int i = 3 ; i <= maxin ; i += 2 ) { if ( divisors [ i ] != i ) { divisors [ i ] = i / divisors [ i ] ; } if ( vis [ i ] == 1 ) { for ( int j = i * i ; j < maxin ; j += i ) { vis [ j ] = 0 ; if ( divisors [ j ] == j ) divisors [ j ] = i ; } } } for ( int i = 0 ; i < n ; i ++ ) { if ( divisors [ arr [ i ] ] == arr [ i ] ) System . out . print ( "" - 1 ▁ "" ) ; else System . out . print ( divisors [ arr [ i ] ] + "" ▁ "" ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 6 , 7 , 8 , 9 , 10 } ; int n = arr . length ; Calc_Max_Div ( arr , n ) ; } } ","maxin = 100001 ; NEW_LINE divisors = [ 0 ] * ( maxin + 1 ) ; NEW_LINE def Calc_Max_Div ( arr , n ) : NEW_LINE INDENT vis = [ 1 ] * ( maxin + 1 ) ; NEW_LINE vis [ 0 ] = vis [ 1 ] = 0 ; NEW_LINE for i in range ( 1 , maxin + 1 ) : NEW_LINE INDENT divisors [ i ] = i ; NEW_LINE DEDENT for i in range ( 4 , maxin + 1 , 2 ) : NEW_LINE INDENT vis [ i ] = 0 ; NEW_LINE divisors [ i ] = i // 2 ; NEW_LINE DEDENT for i in range ( 3 , maxin + 1 , 2 ) : NEW_LINE INDENT if ( divisors [ i ] != i ) : NEW_LINE INDENT divisors [ i ] = i // divisors [ i ] ; NEW_LINE DEDENT if ( vis [ i ] == 1 ) : NEW_LINE INDENT for j in range ( i * i , maxin , i ) : NEW_LINE INDENT vis [ j ] = 0 ; NEW_LINE if ( divisors [ j ] == j ) : NEW_LINE INDENT divisors [ j ] = i ; NEW_LINE DEDENT DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( divisors [ arr [ i ] ] == arr [ i ] ) : NEW_LINE INDENT print ( "" - 1 ▁ "" , end = "" "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( divisors [ arr [ i ] ] , end = "" ▁ "" ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 5 , 6 , 7 , 8 , 9 , 10 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE Calc_Max_Div ( arr , n ) ; NEW_LINE DEDENT " V687,"class GFG { static int MAX = 100000 ; static int sequence [ ] = new int [ MAX + 1 ] ; static void vanEckSequence ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { sequence [ i ] = 0 ; } for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( sequence [ j ] == sequence [ i ] ) { sequence [ i + 1 ] = i - j ; break ; } } } } static int getCount ( int n ) { int count = 1 ; int i = n - 1 ; while ( sequence [ i + 1 ] != 0 ) { count ++ ; i = i - sequence [ i + 1 ] ; } return count ; } public static void main ( String [ ] args ) { vanEckSequence ( ) ; int n = 5 ; System . out . println ( getCount ( n ) ) ; n = 11 ; System . out . println ( getCount ( n ) ) ; } } ","MAX = 10000 NEW_LINE sequence = [ 0 ] * ( MAX + 1 ) ; NEW_LINE def vanEckSequence ( ) : NEW_LINE INDENT for i in range ( MAX ) : NEW_LINE INDENT for j in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( sequence [ j ] == sequence [ i ] ) : NEW_LINE INDENT sequence [ i + 1 ] = i - j ; NEW_LINE break ; NEW_LINE DEDENT DEDENT DEDENT DEDENT def getCount ( n ) : NEW_LINE INDENT count = 1 ; NEW_LINE i = n - 1 ; NEW_LINE while ( sequence [ i + 1 ] != 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE i = i - sequence [ i + 1 ] ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT vanEckSequence ( ) ; NEW_LINE n = 5 ; NEW_LINE print ( getCount ( n ) ) ; NEW_LINE n = 11 ; NEW_LINE print ( getCount ( n ) ) ; NEW_LINE DEDENT " V688,"class GFG { static int countGreater ( int arr [ ] , int n , int k ) { int l = 0 ; int r = n - 1 ; int leftGreater = n ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return ( n - leftGreater ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 } ; int n = arr . length ; int k = 7 ; System . out . println ( countGreater ( arr , n , k ) ) ; } } ","def countGreater ( arr , n , k ) : NEW_LINE INDENT l = 0 NEW_LINE r = n - 1 NEW_LINE leftGreater = n NEW_LINE while ( l <= r ) : NEW_LINE INDENT m = int ( l + ( r - l ) / 2 ) NEW_LINE if ( arr [ m ] > k ) : NEW_LINE INDENT leftGreater = m NEW_LINE r = m - 1 NEW_LINE DEDENT else : NEW_LINE INDENT l = m + 1 NEW_LINE DEDENT DEDENT return ( n - leftGreater ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 ] NEW_LINE n = len ( arr ) NEW_LINE k = 7 NEW_LINE print ( countGreater ( arr , n , k ) ) NEW_LINE DEDENT " V689,"import java . util . * ; import java . lang . * ; public class GfG { public static int counLastDigitK ( int low , int high , int k ) { int count = ( high - low ) / 10 ; if ( high % 10 >= k ) count ++ ; if ( low % 10 > k ) count -- ; return count ; } public static void main ( String argc [ ] ) { int low = 3 , high = 35 , k = 3 ; System . out . println ( counLastDigitK ( low , high , k ) ) ; } } ","def counLastDigitK ( low , high , k ) : NEW_LINE INDENT count = ( high - low ) / 10 NEW_LINE if ( high % 10 >= k ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( low % 10 > k ) : NEW_LINE INDENT count -= 1 NEW_LINE DEDENT return int ( count ) NEW_LINE DEDENT low = 3 NEW_LINE high = 35 NEW_LINE k = 3 NEW_LINE print ( counLastDigitK ( low , high , k ) ) NEW_LINE " V690,"class GFG { static boolean squareRootExists ( int n , int p ) { n = n % p ; for ( int x = 2 ; x < p ; x ++ ) if ( ( x * x ) % p == n ) return true ; return false ; } public static void main ( String [ ] args ) { int p = 7 ; int n = 2 ; if ( squareRootExists ( n , p ) ) System . out . print ( "" Yes "" ) ; else System . out . print ( "" No "" ) ; } } ","def squareRootExists ( n , p ) : NEW_LINE INDENT n = n % p NEW_LINE for x in range ( 2 , p , 1 ) : NEW_LINE INDENT if ( ( x * x ) % p == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT p = 7 NEW_LINE n = 2 NEW_LINE if ( squareRootExists ( n , p ) == True ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V691,"public class GFG { public static long findWays ( int f , int d , int s ) { long mem [ ] [ ] = new long [ d + 1 ] [ s + 1 ] ; mem [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= d ; i ++ ) { for ( int j = i ; j <= s ; j ++ ) { mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ] ; if ( j - f - 1 >= 0 ) mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ] ; } } return mem [ d ] [ s ] ; } public static void main ( String [ ] args ) { System . out . println ( findWays ( 4 , 2 , 1 ) ) ; System . out . println ( findWays ( 2 , 2 , 3 ) ) ; System . out . println ( findWays ( 6 , 3 , 8 ) ) ; System . out . println ( findWays ( 4 , 2 , 5 ) ) ; System . out . println ( findWays ( 4 , 3 , 5 ) ) ; } } ","def findWays ( f , d , s ) : NEW_LINE INDENT mem = [ [ 0 for i in range ( s + 1 ) ] for j in range ( d + 1 ) ] NEW_LINE mem [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , d + 1 ) : NEW_LINE INDENT for j in range ( 1 , s + 1 ) : NEW_LINE INDENT mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ] NEW_LINE if j - f - 1 >= 0 : NEW_LINE INDENT mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ] NEW_LINE DEDENT DEDENT DEDENT return mem [ d ] [ s ] NEW_LINE DEDENT print ( findWays ( 4 , 2 , 1 ) ) NEW_LINE print ( findWays ( 2 , 2 , 3 ) ) NEW_LINE print ( findWays ( 6 , 3 , 8 ) ) NEW_LINE print ( findWays ( 4 , 2 , 5 ) ) NEW_LINE print ( findWays ( 4 , 3 , 5 ) ) NEW_LINE " V692,"class GFG { static long nextFibonacci ( int n ) { double a = n * ( 1 + Math . sqrt ( 5 ) ) / 2.0 ; return Math . round ( a ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( nextFibonacci ( n ) ) ; } } ","from math import * NEW_LINE def nextFibonacci ( n ) : NEW_LINE INDENT a = n * ( 1 + sqrt ( 5 ) ) / 2.0 NEW_LINE return round ( a ) NEW_LINE DEDENT n = 5 NEW_LINE print ( nextFibonacci ( n ) ) NEW_LINE " V693,"class GFG { static int maxLCM ( int n ) { return ( n * ( n - 1 ) ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( maxLCM ( n ) ) ; } } ","def maxLCM ( n ) : NEW_LINE INDENT return ( n * ( n - 1 ) ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 3 ; NEW_LINE print ( maxLCM ( n ) ) ; NEW_LINE DEDENT " V694,"class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void printPrime ( int n ) { for ( int i = 2 ; i <= n ; i ++ ) { if ( isPrime ( i ) ) System . out . print ( i + "" ▁ "" ) ; } } public static void main ( String [ ] args ) { int n = 7 ; printPrime ( n ) ; } } ","def isPrime ( n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def printPrime ( n ) : NEW_LINE INDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if isPrime ( i ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 7 NEW_LINE printPrime ( n ) NEW_LINE DEDENT " V695,"import java . util . * ; class solution { static void divide ( int a , int b ) { for ( int i = 2 ; i <= Math . min ( a , b ) ; i ++ ) { while ( a % i == 0 && b % i == 0 ) { a = a / i ; b = b / i ; } } System . out . println ( "" A ▁ = ▁ "" + a + "" , ▁ B ▁ = ▁ "" + b ) ; } public static void main ( String args [ ] ) { int A = 10 , B = 15 ; divide ( A , B ) ; } } ","def divide ( a , b ) : NEW_LINE INDENT for i in range ( 2 , min ( a , b ) + 1 ) : NEW_LINE INDENT while ( a % i == 0 and b % i == 0 ) : NEW_LINE INDENT a = a // i NEW_LINE b = b // i NEW_LINE DEDENT DEDENT print ( "" A ▁ = "" , a , "" , ▁ B ▁ = "" , b ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT A , B = 10 , 15 NEW_LINE divide ( A , B ) NEW_LINE DEDENT " V696,"import java . io . * ; class GFG { static void ReplaceElements ( int [ ] arr , int n ) { if ( n <= 1 ) return ; int prev = arr [ 0 ] ; arr [ 0 ] = arr [ 0 ] ^ arr [ 1 ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) { int curr = arr [ i ] ; arr [ i ] = prev ^ arr [ i + 1 ] ; prev = curr ; } arr [ n - 1 ] = prev ^ arr [ n - 1 ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; ReplaceElements ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; } } ","def ReplaceElements ( arr , n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return NEW_LINE DEDENT prev = arr [ 0 ] NEW_LINE arr [ 0 ] = arr [ 0 ] ^ arr [ 1 ] NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT curr = arr [ i ] NEW_LINE arr [ i ] = prev ^ arr [ i + 1 ] NEW_LINE prev = curr NEW_LINE DEDENT arr [ n - 1 ] = prev ^ arr [ n - 1 ] NEW_LINE DEDENT arr = [ 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE ReplaceElements ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT " V697,"import java . util . * ; class GFG { static int countOne ( int n ) { int count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } if ( count % 2 == 0 ) return 1 ; else return 0 ; } static int sumDigits ( int n ) { int sum = 0 ; while ( n != 0 ) { sum += n % 10 ; n /= 10 ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 9 , 15 } ; int n = arr . length ; int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( countOne ( arr [ i ] ) == 1 ) total_sum += sumDigits ( arr [ i ] ) ; } System . out . println ( total_sum ) ; } } ","def countOne ( n ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n ) : NEW_LINE INDENT n = n & ( n - 1 ) NEW_LINE count += 1 NEW_LINE DEDENT if ( count % 2 == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def summDigits ( n ) : NEW_LINE INDENT summ = 0 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT summ += n % 10 NEW_LINE n //= 10 NEW_LINE DEDENT return summ NEW_LINE DEDENT arr = [ 4 , 9 , 15 ] NEW_LINE n = len ( arr ) NEW_LINE total_summ = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( countOne ( arr [ i ] ) ) : NEW_LINE INDENT total_summ += summDigits ( arr [ i ] ) NEW_LINE DEDENT DEDENT print ( total_summ ) NEW_LINE " V698,"class GFG { static long countPairs ( int [ ] arr , int n ) { int count_2 = 0 , count_others = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 2 ) { count_2 ++ ; } else if ( arr [ i ] > 2 ) { count_others ++ ; } } long ans = 1L * count_2 * count_others + ( 1L * count_others * ( count_others - 1 ) ) / 2 ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 0 , 3 , 1 , 2 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } } ","import math as mt NEW_LINE def countPairs ( arr , n ) : NEW_LINE INDENT count_2 , count_others = 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] == 2 : NEW_LINE INDENT count_2 += 1 NEW_LINE DEDENT elif arr [ i ] > 2 : NEW_LINE INDENT count_others += 1 NEW_LINE DEDENT DEDENT ans = ( count_2 * count_others + ( count_others * ( count_others - 1 ) ) // 2 ) NEW_LINE return ans NEW_LINE DEDENT arr = [ 5 , 0 , 3 , 1 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countPairs ( arr , n ) ) NEW_LINE " V699,"import java . io . * ; class GFG { static int N = 3 ; static boolean checkCentrosymmetricted ( int n , int m [ ] [ ] ) { int mid_row ; if ( ( n & 1 ) > 0 ) mid_row = n / 2 + 1 ; else mid_row = n / 2 ; for ( int i = 0 ; i < mid_row ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( m [ i ] [ j ] != m [ n - i - 1 ] [ n - j - 1 ] ) return false ; } } return true ; } public static void main ( String [ ] args ) { int n = 3 ; int m [ ] [ ] = { { 1 , 3 , 5 } , { 6 , 8 , 6 } , { 5 , 3 , 1 } } ; if ( checkCentrosymmetricted ( n , m ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def checkCentrosymmetricted ( n , m ) : NEW_LINE INDENT mid_row = 0 ; NEW_LINE if ( ( n & 1 ) > 0 ) : NEW_LINE INDENT mid_row = n / 2 + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT mid_row = n / 2 ; NEW_LINE DEDENT for i in range ( int ( mid_row ) ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( m [ i ] [ j ] != m [ n - i - 1 ] [ n - j - 1 ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT DEDENT return True ; NEW_LINE DEDENT n = 3 ; NEW_LINE m = [ [ 1 , 3 , 5 ] , [ 6 , 8 , 6 ] , [ 5 , 3 , 1 ] ] ; NEW_LINE if ( checkCentrosymmetricted ( n , m ) ) : NEW_LINE INDENT print ( "" Yes "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) ; NEW_LINE DEDENT " V700,"import java . util . * ; class GFG { static int MAX_LEN = 1005 ; static int MAX_CHAR = 26 ; static int [ ] [ ] cnt = new int [ MAX_LEN ] [ MAX_CHAR ] ; static void preProcess ( String s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ i ] [ s . charAt ( i ) - ' a ' ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) cnt [ i ] [ j ] += cnt [ i - 1 ] [ j ] ; } } static int findCharFreq ( int l , int r , char c ) { return ( cnt [ r ] [ ( c ) - 97 ] - cnt [ l ] [ ( c ) - 97 ] ) ; } public static void main ( String [ ] args ) { String s = "" geeksforgeeks "" ; int Q = 4 ; preProcess ( s ) ; System . out . println ( findCharFreq ( 0 , 5 , ' e ' ) ) ; System . out . println ( findCharFreq ( 2 , 6 , ' f ' ) ) ; System . out . println ( findCharFreq ( 4 , 7 , ' m ' ) ) ; System . out . println ( findCharFreq ( 0 , 12 , ' e ' ) ) ; } } ","MAX_LEN , MAX_CHAR = 1005 , 26 NEW_LINE cnt = [ [ 0 for i in range ( MAX_CHAR ) ] for j in range ( MAX_LEN ) ] NEW_LINE def preProcess ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT cnt [ i ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( 0 , 26 ) : NEW_LINE INDENT cnt [ i ] [ j ] += cnt [ i - 1 ] [ j ] NEW_LINE DEDENT DEDENT DEDENT def findCharFreq ( l , r , c ) : NEW_LINE INDENT return ( cnt [ r ] [ ord ( c ) - 97 ] - cnt [ l - 1 ] [ ord ( c ) - 97 ] ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" geeksforgeeks "" NEW_LINE Q = 4 NEW_LINE preProcess ( s ) NEW_LINE print ( findCharFreq ( 0 , 5 , ' e ' ) ) NEW_LINE print ( findCharFreq ( 2 , 6 , ' f ' ) ) NEW_LINE print ( findCharFreq ( 4 , 7 , ' m ' ) ) NEW_LINE print ( findCharFreq ( 0 , 12 , ' e ' ) ) NEW_LINE DEDENT " V701,"import java . util . * ; class GFG { static void minimumColors ( int N , int E , int U [ ] , int V [ ] ) { Vector < Integer > [ ] adj = new Vector [ N ] ; int [ ] count = new int [ N ] ; int [ ] colors = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { adj [ i ] = new Vector < Integer > ( ) ; colors [ i ] = 1 ; } for ( int i = 0 ; i < N ; i ++ ) { adj [ V [ i ] - 1 ] . add ( U [ i ] - 1 ) ; count [ U [ i ] - 1 ] ++ ; } Queue < Integer > Q = new LinkedList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( count [ i ] == 0 ) { Q . add ( i ) ; } } while ( ! Q . isEmpty ( ) ) { int u = Q . peek ( ) ; Q . remove ( ) ; for ( int x : adj [ u ] ) { count [ x ] -- ; if ( count [ x ] == 0 ) { Q . add ( x ) ; } if ( colors [ x ] <= colors [ u ] ) { colors [ x ] = 1 + colors [ u ] ; } } } int minColor = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { minColor = Math . max ( minColor , colors [ i ] ) ; } System . out . print ( minColor + "" \n "" ) ; } public static void main ( String [ ] args ) { int N = 5 , E = 6 ; int U [ ] = { 1 , 2 , 3 , 1 , 2 , 3 } ; int V [ ] = { 3 , 3 , 4 , 4 , 5 , 5 } ; minimumColors ( N , E , U , V ) ; } } ","from collections import deque NEW_LINE def minimumColors ( N , E , U , V ) : NEW_LINE INDENT adj = [ [ ] for i in range ( N ) ] NEW_LINE count = [ 0 ] * N NEW_LINE colors = [ 1 ] * ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT adj [ V [ i ] - 1 ] . append ( U [ i ] - 1 ) NEW_LINE count [ U [ i ] - 1 ] += 1 NEW_LINE DEDENT Q = deque ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( count [ i ] == 0 ) : NEW_LINE INDENT Q . append ( i ) NEW_LINE DEDENT DEDENT while len ( Q ) > 0 : NEW_LINE INDENT u = Q . popleft ( ) NEW_LINE for x in adj [ u ] : NEW_LINE INDENT count [ x ] -= 1 NEW_LINE if ( count [ x ] == 0 ) : NEW_LINE INDENT Q . append ( x ) NEW_LINE DEDENT if ( colors [ x ] <= colors [ u ] ) : NEW_LINE INDENT colors [ x ] = 1 + colors [ u ] NEW_LINE DEDENT DEDENT DEDENT minColor = - 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT minColor = max ( minColor , colors [ i ] ) NEW_LINE DEDENT print ( minColor ) NEW_LINE DEDENT N = 5 NEW_LINE E = 6 NEW_LINE U = [ 1 , 2 , 3 , 1 , 2 , 3 ] NEW_LINE V = [ 3 , 3 , 4 , 4 , 5 , 5 ] NEW_LINE minimumColors ( N , E , U , V ) NEW_LINE " V702,"import java . io . * ; import static java . lang . Math . * ; class Quadratic { void findRoots ( int a , int b , int c ) { if ( a == 0 ) { System . out . println ( "" Invalid "" ) ; return ; } int d = b * b - 4 * a * c ; double sqrt_val = sqrt ( abs ( d ) ) ; if ( d > 0 ) { System . out . println ( "" Roots ▁ are ▁ real ▁ and ▁ different ▁ \n "" ) ; System . out . println ( ( double ) ( - b + sqrt_val ) / ( 2 * a ) + "" \n "" + ( double ) ( - b - sqrt_val ) / ( 2 * a ) ) ; } else { System . out . println ( "" Roots ▁ are ▁ complex ▁ \n "" ) ; System . out . println ( - ( double ) b / ( 2 * a ) + "" ▁ + ▁ i "" + sqrt_val + "" \n "" + - ( double ) b / ( 2 * a ) + "" ▁ - ▁ i "" + sqrt_val ) ; } } public static void main ( String args [ ] ) { Quadratic obj = new Quadratic ( ) ; int a = 1 , b = - 7 , c = 12 ; obj . findRoots ( a , b , c ) ; } } ","import math NEW_LINE def findRoots ( a , b , c ) : NEW_LINE INDENT if a == 0 : NEW_LINE INDENT print ( "" Invalid "" ) NEW_LINE return - 1 NEW_LINE DEDENT d = b * b - 4 * a * c NEW_LINE sqrt_val = math . sqrt ( abs ( d ) ) NEW_LINE if d > 0 : NEW_LINE INDENT print ( "" Roots ▁ are ▁ real ▁ and ▁ different ▁ "" ) NEW_LINE print ( ( - b + sqrt_val ) / ( 2 * a ) ) NEW_LINE print ( ( - b - sqrt_val ) / ( 2 * a ) ) NEW_LINE DEDENT elif d == 0 : NEW_LINE INDENT print ( "" Roots ▁ are ▁ real ▁ and ▁ same "" ) NEW_LINE print ( - b / ( 2 * a ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Roots ▁ are ▁ complex "" ) NEW_LINE print ( - b / ( 2 * a ) , "" ▁ + ▁ i "" , sqrt_val ) NEW_LINE print ( - b / ( 2 * a ) , "" ▁ - ▁ i "" , sqrt_val ) NEW_LINE DEDENT DEDENT a = 1 NEW_LINE b = - 7 NEW_LINE c = 12 NEW_LINE findRoots ( a , b , c ) NEW_LINE " V703,"import java . util . * ; class GFG { static final int N = 3 ; static final int M = 3 ; static int sumOddOccurring ( int arr [ ] [ ] ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mp . get ( arr [ i ] [ j ] ) == null ) mp . put ( arr [ i ] [ j ] , 1 ) ; else mp . put ( arr [ i ] [ j ] , ( mp . get ( arr [ i ] [ j ] ) + 1 ) ) ; } } int sum = 0 ; Set < Map . Entry < Integer , Integer > > st = mp . entrySet ( ) ; for ( Map . Entry < Integer , Integer > me : st ) { if ( me . getValue ( ) % 2 == 0 ) { int x = me . getValue ( ) ; sum += ( me . getKey ( ) ) * ( me . getValue ( ) ) ; } } return sum ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 1 , 2 , 3 } , { 1 , 3 , 2 } , { 1 , 5 , 6 } } ; System . out . print ( sumOddOccurring ( mat ) ) ; } } ","import sys NEW_LINE N = 3 NEW_LINE M = 3 NEW_LINE def sumOddOccuring ( arr ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if arr [ i ] [ j ] in mp : NEW_LINE INDENT mp [ arr [ i ] [ j ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ arr [ i ] [ j ] ] = 1 NEW_LINE DEDENT DEDENT DEDENT s = 0 NEW_LINE for i in mp : NEW_LINE INDENT if mp [ i ] % 2 == 0 : NEW_LINE INDENT x = mp [ i ] NEW_LINE s += i * mp [ i ] NEW_LINE DEDENT DEDENT return s NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT mat = [ [ 1 , 2 , 3 ] , [ 1 , 3 , 2 ] , [ 1 , 5 , 6 ] ] NEW_LINE print ( sumOddOccuring ( mat ) ) NEW_LINE DEDENT " V704,"import java . util . * ; class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) { return false ; } if ( n <= 3 ) { return true ; } if ( n % 2 == 0 || n % 3 == 0 ) { return false ; } for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % p ; } y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static void findPrimefactors ( HashSet < Integer > s , int n ) { while ( n % 2 == 0 ) { s . add ( 2 ) ; n = n / 2 ; } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { while ( n % i == 0 ) { s . add ( i ) ; n = n / i ; } } if ( n > 2 ) { s . add ( n ) ; } } static int findPrimitive ( int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; if ( isPrime ( n ) == false ) { return - 1 ; } int phi = n - 1 ; findPrimefactors ( s , phi ) ; for ( int r = 2 ; r <= phi ; r ++ ) { boolean flag = false ; for ( Integer a : s ) { if ( power ( r , phi / ( a ) , n ) == 1 ) { flag = true ; break ; } } if ( flag == false ) { return r ; } } return - 1 ; } public static void main ( String [ ] args ) { int n = 761 ; System . out . println ( "" ▁ Smallest ▁ primitive ▁ root ▁ of ▁ "" + n + "" ▁ is ▁ "" + findPrimitive ( n ) ) ; } } ","from math import sqrt NEW_LINE def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = 5 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = i + 6 NEW_LINE DEDENT return True NEW_LINE DEDENT def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def findPrimefactors ( s , n ) : NEW_LINE INDENT while ( n % 2 == 0 ) : NEW_LINE INDENT s . add ( 2 ) NEW_LINE n = n // 2 NEW_LINE DEDENT for i in range ( 3 , int ( sqrt ( n ) ) , 2 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT s . add ( i ) NEW_LINE n = n // i NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT s . add ( n ) NEW_LINE DEDENT DEDENT def findPrimitive ( n ) : NEW_LINE INDENT s = set ( ) NEW_LINE if ( isPrime ( n ) == False ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT phi = n - 1 NEW_LINE findPrimefactors ( s , phi ) NEW_LINE for r in range ( 2 , phi + 1 ) : NEW_LINE INDENT flag = False NEW_LINE for it in s : NEW_LINE INDENT if ( power ( r , phi // it , n ) == 1 ) : NEW_LINE INDENT flag = True NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == False ) : NEW_LINE INDENT return r NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT n = 761 NEW_LINE print ( "" Smallest ▁ primitive ▁ root ▁ of "" , n , "" is "" , findPrimitive ( n ) ) NEW_LINE " V705,"class GFG { static final int max = 50009 ; static void find_Indices ( int arr [ ] , int n ) { int sum [ ] = new int [ max ] ; int index_1 , index_2 , index_3 , index ; int k , i ; for ( i = 1 , k = 0 ; i <= n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ k ++ ] ; double ans = - ( 1e15 ) ; index_1 = index_2 = index_3 = - 1 ; for ( int l = 0 ; l <= n ; l ++ ) { index = 0 ; double vmin = ( 1e15 ) ; for ( int r = l ; r <= n ; r ++ ) { if ( sum [ r ] < vmin ) { vmin = sum [ r ] ; index = r ; } if ( sum [ l ] + sum [ r ] - vmin > ans ) { ans = sum [ l ] + sum [ r ] - vmin ; index_1 = l ; index_2 = index ; index_3 = r ; } } } System . out . print ( index_1 + "" ▁ "" + index_2 + "" ▁ "" + index_3 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , 3 } ; int n = arr . length ; find_Indices ( arr , n ) ; } } ","max = 50009 NEW_LINE def find_Indices ( arr , n ) : NEW_LINE INDENT sum = [ 0 for i in range ( max ) ] NEW_LINE k = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum [ i ] = sum [ i - 1 ] + arr [ k ] ; NEW_LINE k += 1 NEW_LINE DEDENT ans = - ( 1e15 ) NEW_LINE index_1 = index_2 = index_3 = - 1 NEW_LINE for l in range ( n + 1 ) : NEW_LINE INDENT index = 0 NEW_LINE vmin = ( 1e15 ) NEW_LINE for r in range ( l , n + 1 ) : NEW_LINE INDENT if ( sum [ r ] < vmin ) : NEW_LINE INDENT vmin = sum [ r ] NEW_LINE index = r NEW_LINE DEDENT if ( sum [ l ] + sum [ r ] - vmin > ans ) : NEW_LINE INDENT ans = sum [ l ] + sum [ r ] - vmin NEW_LINE index_1 = l NEW_LINE index_2 = index NEW_LINE index_3 = r NEW_LINE DEDENT DEDENT DEDENT print ( index_1 , "" ▁ "" , index_2 , "" ▁ "" , index_3 ) NEW_LINE DEDENT arr = [ - 1 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE find_Indices ( arr , n ) NEW_LINE " V706,"class GFG { static int countWays ( int n , int l , int r ) { int tL = l , tR = r ; int [ ] L = new int [ 3 ] ; int [ ] R = new int [ 3 ] ; L [ l % 2 ] = l ; R [ r % 2 ] = r ; l ++ ; r -- ; if ( l <= tR && r >= tL ) { L [ l % 2 ] = l ; R [ r % 2 ] = r ; } int cnt0 = 0 , cnt1 = 0 ; if ( R [ 0 ] > 0 && L [ 0 ] > 0 ) cnt0 = ( R [ 0 ] - L [ 0 ] ) / 2 + 1 ; if ( R [ 1 ] > 0 && L [ 1 ] > 0 ) cnt1 = ( R [ 1 ] - L [ 1 ] ) / 2 + 1 ; int [ ] [ ] dp = new int [ n + 1 ] [ 3 ] ; dp [ 1 ] [ 0 ] = cnt0 ; dp [ 1 ] [ 1 ] = cnt1 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] [ 0 ] = ( cnt0 * dp [ i - 1 ] [ 0 ] + cnt1 * dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = ( cnt0 * dp [ i - 1 ] [ 1 ] + cnt1 * dp [ i - 1 ] [ 0 ] ) ; } return dp [ n ] [ 0 ] ; } public static void main ( String [ ] args ) { int n = 2 , l = 1 , r = 3 ; System . out . println ( countWays ( n , l , r ) ) ; } } ","def countWays ( n , l , r ) : NEW_LINE INDENT tL , tR = l , r NEW_LINE L = [ 0 for i in range ( 2 ) ] NEW_LINE R = [ 0 for i in range ( 2 ) ] NEW_LINE L [ l % 2 ] = l NEW_LINE R [ r % 2 ] = r NEW_LINE l += 1 NEW_LINE r -= 1 NEW_LINE if ( l <= tR and r >= tL ) : NEW_LINE INDENT L [ l % 2 ] , R [ r % 2 ] = l , r NEW_LINE DEDENT cnt0 , cnt1 = 0 , 0 NEW_LINE if ( R [ 0 ] and L [ 0 ] ) : NEW_LINE INDENT cnt0 = ( R [ 0 ] - L [ 0 ] ) // 2 + 1 NEW_LINE DEDENT if ( R [ 1 ] and L [ 1 ] ) : NEW_LINE INDENT cnt1 = ( R [ 1 ] - L [ 1 ] ) // 2 + 1 NEW_LINE DEDENT dp = [ [ 0 for i in range ( 2 ) ] for i in range ( n + 1 ) ] NEW_LINE dp [ 1 ] [ 0 ] = cnt0 NEW_LINE dp [ 1 ] [ 1 ] = cnt1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = ( cnt0 * dp [ i - 1 ] [ 0 ] + cnt1 * dp [ i - 1 ] [ 1 ] ) NEW_LINE dp [ i ] [ 1 ] = ( cnt0 * dp [ i - 1 ] [ 1 ] + cnt1 * dp [ i - 1 ] [ 0 ] ) NEW_LINE DEDENT return dp [ n ] [ 0 ] NEW_LINE DEDENT n , l , r = 2 , 1 , 3 NEW_LINE print ( countWays ( n , l , r ) ) NEW_LINE " V707,"import java . math . BigInteger ; class GFG { static void printPair ( int g , int l ) { int n = g * l ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { int first = i ; int second = n / i ; int gcd = __gcd ( first , second ) ; if ( gcd == g && l % first == 0 && l % second == 0 ) { System . out . println ( first + "" ▁ "" + second ) ; return ; } } } } private static int __gcd ( int a , int b ) { BigInteger b1 = new BigInteger ( "" "" + a ) ; BigInteger b2 = new BigInteger ( "" "" + b ) ; BigInteger gcd = b1 . gcd ( b2 ) ; return gcd . intValue ( ) ; } public static void main ( String [ ] args ) { int g = 3 , l = 12 ; printPair ( g , l ) ; } } ","def printPair ( g , l ) : NEW_LINE INDENT n = g * l ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT first = i ; NEW_LINE second = n // i ; NEW_LINE gcd = __gcd ( first , second ) ; NEW_LINE if ( gcd == g and l % first == 0 and l % second == 0 ) : NEW_LINE INDENT print ( first , "" ▁ "" , second ) ; NEW_LINE return ; NEW_LINE DEDENT DEDENT DEDENT DEDENT def __gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a ; NEW_LINE DEDENT else : NEW_LINE INDENT return __gcd ( b , a % b ) ; NEW_LINE DEDENT DEDENT g = 3 ; NEW_LINE l = 12 ; NEW_LINE printPair ( g , l ) ; NEW_LINE " V708,"import java . util . * ; class GFG { static int count_pairs ( String s1 [ ] , String s2 [ ] , int n1 , int n2 ) { HashMap < String , Integer > mp = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < n1 ; i ++ ) mp . put ( s1 [ i ] , 0 ) ; for ( int i = 0 ; i < n1 ; i ++ ) mp . put ( s1 [ i ] , mp . get ( s1 [ i ] ) + 1 ) ; int cnt = 0 ; for ( int i = 0 ; i < n2 ; i ++ ) { if ( mp . get ( s2 [ i ] ) > 0 ) { cnt ++ ; mp . put ( s2 [ i ] , mp . get ( s2 [ i ] ) - 1 ) ; } } return cnt ; } public static void main ( String [ ] args ) { String s1 [ ] = { "" abc "" , "" def "" } ; String s2 [ ] = { "" abc "" , "" abc "" } ; int n1 = s1 . length ; int n2 = s2 . length ; System . out . println ( count_pairs ( s1 , s2 , n1 , n2 ) ) ; } } ","def count_pairs ( s1 , s2 , n1 , n2 ) : NEW_LINE INDENT mp = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) } NEW_LINE for i in range ( n1 ) : NEW_LINE INDENT mp [ s1 [ i ] ] += 1 NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( n2 ) : NEW_LINE INDENT if ( mp [ s2 [ i ] ] > 0 ) : NEW_LINE INDENT cnt += 1 NEW_LINE mp [ s2 [ i ] ] -= 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s1 = [ "" abc "" , "" def "" ] NEW_LINE s2 = [ "" abc "" , "" abc "" ] NEW_LINE n1 = len ( s1 ) NEW_LINE n2 = len ( s2 ) NEW_LINE print ( count_pairs ( s1 , s2 , n1 , n2 ) ) NEW_LINE DEDENT " V709,"class MergeArrays { void moveToEnd ( int mPlusN [ ] , int size ) { int i , j = size - 1 ; for ( i = size - 1 ; i >= 0 ; i -- ) { if ( mPlusN [ i ] != - 1 ) { mPlusN [ j ] = mPlusN [ i ] ; j -- ; } } } void merge ( int mPlusN [ ] , int N [ ] , int m , int n ) { int i = n ; int j = 0 ; int k = 0 ; while ( k < ( m + n ) ) { if ( ( i < ( m + n ) && mPlusN [ i ] <= N [ j ] ) || ( j == n ) ) { mPlusN [ k ] = mPlusN [ i ] ; k ++ ; i ++ ; } else { mPlusN [ k ] = N [ j ] ; k ++ ; j ++ ; } } } void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; System . out . println ( "" "" ) ; } public static void main ( String [ ] args ) { MergeArrays mergearray = new MergeArrays ( ) ; int mPlusN [ ] = { 2 , 8 , - 1 , - 1 , - 1 , 13 , - 1 , 15 , 20 } ; int N [ ] = { 5 , 7 , 9 , 25 } ; int n = N . length ; int m = mPlusN . length - n ; mergearray . moveToEnd ( mPlusN , m + n ) ; mergearray . merge ( mPlusN , N , m , n ) ; mergearray . printArray ( mPlusN , m + n ) ; } } ","NA = - 1 NEW_LINE def moveToEnd ( mPlusN , size ) : NEW_LINE INDENT i = 0 NEW_LINE j = size - 1 NEW_LINE for i in range ( size - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( mPlusN [ i ] != NA ) : NEW_LINE INDENT mPlusN [ j ] = mPlusN [ i ] NEW_LINE j -= 1 NEW_LINE DEDENT DEDENT DEDENT def merge ( mPlusN , N , m , n ) : NEW_LINE INDENT i = n NEW_LINE j = 0 NEW_LINE k = 0 NEW_LINE while ( k < ( m + n ) ) : NEW_LINE INDENT if ( ( i < ( m + n ) and mPlusN [ i ] <= N [ j ] ) or ( j == n ) ) : NEW_LINE INDENT mPlusN [ k ] = mPlusN [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mPlusN [ k ] = N [ j ] NEW_LINE k += 1 NEW_LINE j += 1 NEW_LINE DEDENT DEDENT DEDENT def printArray ( arr , size ) : NEW_LINE INDENT for i in range ( size ) : NEW_LINE INDENT print ( arr [ i ] , "" ▁ "" , end = "" "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT mPlusN = [ 2 , 8 , NA , NA , NA , 13 , NA , 15 , 20 ] NEW_LINE N = [ 5 , 7 , 9 , 25 ] NEW_LINE n = len ( N ) NEW_LINE m = len ( mPlusN ) - n NEW_LINE moveToEnd ( mPlusN , m + n ) NEW_LINE merge ( mPlusN , N , m , n ) NEW_LINE printArray ( mPlusN , m + n ) NEW_LINE " V710,"class GFG { static boolean isDivisibleby17 ( int n ) { if ( n == 0 || n == 17 ) return true ; if ( n < 17 ) return false ; return isDivisibleby17 ( ( int ) ( n >> 4 ) - ( int ) ( n & 15 ) ) ; } public static void main ( String [ ] args ) { int n = 35 ; if ( isDivisibleby17 ( n ) == true ) System . out . printf ( "" % d ▁ is ▁ divisible ▁ by ▁ 17"" , n ) ; else System . out . printf ( "" % d ▁ is ▁ not ▁ divisible ▁ by ▁ 17"" , n ) ; } } ","def isDivisibleby17 ( n ) : NEW_LINE INDENT if ( n == 0 or n == 17 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n < 17 ) : NEW_LINE INDENT return False NEW_LINE DEDENT return isDivisibleby17 ( ( int ) ( n >> 4 ) - ( int ) ( n & 15 ) ) NEW_LINE DEDENT n = 35 NEW_LINE if ( isDivisibleby17 ( n ) ) : NEW_LINE INDENT print ( n , "" is ▁ divisible ▁ by ▁ 17"" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( n , "" is ▁ not ▁ divisible ▁ by ▁ 17"" ) NEW_LINE DEDENT " V711,"import java . io . * ; import java . util . * ; class GFG { static int min1 = Integer . MAX_VALUE ; static int count = 0 ; public int permutation ( String str1 , int i , int n , int p ) { if ( i == n ) { int q = Integer . parseInt ( str1 ) ; if ( q - p > 0 && q < min1 ) { min1 = q ; count = 1 ; } } else { for ( int j = i ; j <= n ; j ++ ) { str1 = swap ( str1 , i , j ) ; permutation ( str1 , i + 1 , n , p ) ; str1 = swap ( str1 , i , j ) ; } } return min1 ; } public String swap ( String str , int i , int j ) { char ch [ ] = str . toCharArray ( ) ; char temp = ch [ i ] ; ch [ i ] = ch [ j ] ; ch [ j ] = temp ; return String . valueOf ( ch ) ; } public static void main ( String [ ] args ) { int A = 213 ; int B = 111 ; GFG gfg = new GFG ( ) ; String str1 = Integer . toString ( A ) ; int len = str1 . length ( ) ; int h = gfg . permutation ( str1 , 0 , len - 1 , B ) ; if ( count == 1 ) System . out . println ( h ) ; else System . out . println ( - 1 ) ; } } ","min1 = 10 ** 9 NEW_LINE _count = 0 NEW_LINE def permutation ( str1 , i , n , p ) : NEW_LINE INDENT global min1 , _count NEW_LINE if ( i == n ) : NEW_LINE INDENT str1 = "" "" . join ( str1 ) NEW_LINE q = int ( str1 ) NEW_LINE if ( q - p > 0 and q < min1 ) : NEW_LINE INDENT min1 = q NEW_LINE _count = 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for j in range ( i , n + 1 ) : NEW_LINE INDENT str1 [ i ] , str1 [ j ] = str1 [ j ] , str1 [ i ] NEW_LINE permutation ( str1 , i + 1 , n , p ) NEW_LINE str1 [ i ] , str1 [ j ] = str1 [ j ] , str1 [ i ] NEW_LINE DEDENT DEDENT return min1 NEW_LINE DEDENT A = 213 NEW_LINE B = 111 NEW_LINE str2 = str ( A ) NEW_LINE str1 = [ i for i in str2 ] NEW_LINE le = len ( str1 ) NEW_LINE h = permutation ( str1 , 0 , le - 1 , B ) NEW_LINE if _count == 1 : NEW_LINE INDENT print ( h ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT " V712,"import java . io . * ; class GFG { static int stepRequired ( int n ) { return Integer . bitCount ( n - 1 ) ; } public static void main ( String [ ] args ) { int n = 94 ; System . out . println ( stepRequired ( n ) ) ; } } ","def stepRequired ( n ) : NEW_LINE INDENT return bin ( 94 ) . count ( '1' ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 94 NEW_LINE print ( stepRequired ( n ) ) NEW_LINE DEDENT " V713,"import java . io . * ; class GFG { static int countMultiples ( int n ) { int res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( i % 3 == 0 || i % 7 == 0 ) res ++ ; return res ; } public static void main ( String [ ] args ) { System . out . print ( "" Count ▁ = ▁ "" ) ; System . out . println ( countMultiples ( 25 ) ) ; } } ","def countMultiples ( n ) : NEW_LINE INDENT res = 0 ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( i % 3 == 0 or i % 7 == 0 ) : NEW_LINE INDENT res += 1 ; NEW_LINE DEDENT DEDENT return res ; NEW_LINE DEDENT print ( "" Count ▁ = "" , countMultiples ( 25 ) ) ; NEW_LINE " V714,"class GFG { static final int arr [ ] = { 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 , 3 , 4 } ; public static int countKeyPressed ( String str , int len ) { int count = 0 ; for ( int i = 0 ; i < len ; i ++ ) count = count + arr [ str . charAt ( i ) - ' a ' ] ; return count ; } public static void main ( String [ ] args ) { String str = "" abcdef "" ; int len = str . length ( ) ; System . out . print ( countKeyPressed ( str , len ) ) ; } } ","arr = [ 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 1 , 2 , 3 , 4 ] ; NEW_LINE def countKeyPressed ( string , length ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( length ) : NEW_LINE INDENT count += arr [ ord ( string [ i ] ) - ord ( ' a ' ) ] ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT string = "" abcdef "" ; NEW_LINE length = len ( string ) ; NEW_LINE print ( countKeyPressed ( string , length ) ) ; NEW_LINE DEDENT " V715,"public class SumOfSeries { static int fact ( int n ) { if ( n == 1 ) return 1 ; return n * fact ( n - 1 ) ; } static double sum ( int x , int n ) { double total = 1.0 ; for ( int i = 1 ; i <= n ; i ++ ) { total = total + ( Math . pow ( x , i ) / fact ( i + 1 ) ) ; } return total ; } public static void main ( String [ ] args ) { int x = 5 , n = 4 ; System . out . print ( "" Sum ▁ is : ▁ "" + sum ( x , n ) ) ; } } ","def fact ( n ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return n * fact ( n - 1 ) NEW_LINE DEDENT DEDENT def sum ( x , n ) : NEW_LINE INDENT total = 1.0 NEW_LINE for i in range ( 1 , n + 1 , 1 ) : NEW_LINE INDENT total = total + ( pow ( x , i ) / fact ( i + 1 ) ) NEW_LINE DEDENT return total NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 5 NEW_LINE n = 4 NEW_LINE print ( "" Sum ▁ is : ▁ { 0 : . 4f } "" . format ( sum ( x , n ) ) ) NEW_LINE DEDENT " V716,"import java . util . * ; class GFG { static int longestPermutation ( int arr [ ] , int n ) { HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . containsKey ( arr [ i ] ) ) { freq . put ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; } else { freq . put ( arr [ i ] , 1 ) ; } } int len = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ! freq . containsKey ( i ) ) { break ; } len ++ ; } return len ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 6 , 5 } ; int n = arr . length ; System . out . print ( longestPermutation ( arr , n ) ) ; } } ","from collections import defaultdict NEW_LINE def longestPermutation ( a , n ) : NEW_LINE INDENT freq = defaultdict ( int ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ a [ i ] ] += 1 NEW_LINE DEDENT length = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( freq [ i ] == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT length += 1 NEW_LINE DEDENT return length NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 3 , 2 , 1 , 6 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( longestPermutation ( arr , n ) ) NEW_LINE DEDENT " V717,"class GFG { static int __gcd ( int a , int b ) { if ( a == 0 || b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return __gcd ( a - b , b ) ; return __gcd ( a , b - a ) ; } static int findLCM ( int arr [ ] , int n ) { int lcm = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { lcm = ( lcm * arr [ i ] ) / __gcd ( arr [ i ] , lcm ) ; } return lcm ; } static int countNumbers ( int arr [ ] , int n , int l , int r ) { int lcm = findLCM ( arr , n ) ; int count = ( r / lcm ) - ( ( l - 1 ) / lcm ) ; return count ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 4 , 2 } ; int n = arr . length ; int l = 1 , r = 10 ; System . out . println ( countNumbers ( arr , n , l , r ) ) ; } } ","import math NEW_LINE def findLCM ( arr , n ) : NEW_LINE INDENT lcm = arr [ 0 ] ; NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT lcm = ( lcm * arr [ i ] ) / math . gcd ( arr [ i ] , lcm ) ; NEW_LINE DEDENT return lcm ; NEW_LINE DEDENT def countNumbers ( arr , n , l , r ) : NEW_LINE INDENT lcm = int ( findLCM ( arr , n ) ) ; NEW_LINE count = ( r / lcm ) - ( ( l - 1 ) / lcm ) ; NEW_LINE print ( int ( count ) ) ; NEW_LINE DEDENT arr = [ 1 , 4 , 2 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE l = 1 ; NEW_LINE r = 10 ; NEW_LINE countNumbers ( arr , n , l , r ) ; NEW_LINE " V718,"class GFG { static int max_element ( int a [ ] , int n ) { int m = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) m = Math . max ( m , a [ i ] ) ; return m ; } static void findNum ( int a [ ] , int n , int b [ ] , int m ) { int x = max_element ( a , n ) ; int y = max_element ( b , m ) ; System . out . print ( x + "" ▁ "" + y ) ; } public static void main ( String args [ ] ) { int a [ ] = { 3 , 2 , 2 } ; int n = a . length ; int b [ ] = { 1 , 5 , 7 , 7 , 9 } ; int m = b . length ; findNum ( a , n , b , m ) ; } } ","def findNum ( a , n , b , m ) : NEW_LINE INDENT x = max ( a ) ; NEW_LINE y = max ( b ) ; NEW_LINE print ( x , y ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 3 , 2 , 2 ] ; NEW_LINE n = len ( a ) ; NEW_LINE b = [ 1 , 5 , 7 , 7 , 9 ] ; NEW_LINE m = len ( b ) ; NEW_LINE findNum ( a , n , b , m ) ; NEW_LINE DEDENT " V719,"import java . util . * ; class GFG { static void type1 ( int [ ] arr , int start , int limit ) { for ( int i = start ; i <= limit ; i ++ ) arr [ i ] ++ ; } static void type2 ( int [ ] arr , int [ ] [ ] query , int start , int limit ) { for ( int i = start ; i <= limit ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; } } public static void main ( String [ ] args ) { int n = 5 , m = 5 ; int [ ] arr = new int [ n + 1 ] ; int [ ] temp = { 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 } ; int [ ] [ ] query = new int [ 6 ] [ 4 ] ; int j = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { query [ i ] [ 0 ] = temp [ j ++ ] ; query [ i ] [ 1 ] = temp [ j ++ ] ; query [ i ] [ 2 ] = temp [ j ++ ] ; } for ( int i = 1 ; i <= m ; i ++ ) if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; System . out . println ( ) ; } } ","def type1 ( arr , start , limit ) : NEW_LINE INDENT for i in range ( start , limit + 1 ) : NEW_LINE INDENT arr [ i ] += 1 NEW_LINE DEDENT DEDENT def type2 ( arr , query , start , limit ) : NEW_LINE INDENT for i in range ( start , limit + 1 ) : NEW_LINE INDENT if ( query [ i ] [ 0 ] == 1 ) : NEW_LINE INDENT type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) NEW_LINE DEDENT elif ( query [ i ] [ 0 ] == 2 ) : NEW_LINE INDENT type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) NEW_LINE DEDENT DEDENT DEDENT n = 5 NEW_LINE m = 5 NEW_LINE arr = [ 0 for i in range ( n + 1 ) ] NEW_LINE temp = [ 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 ] NEW_LINE query = [ [ 0 for i in range ( 3 ) ] for j in range ( 6 ) ] NEW_LINE j = 0 NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT query [ i ] [ 0 ] = temp [ j ] NEW_LINE j += 1 NEW_LINE query [ i ] [ 1 ] = temp [ j ] NEW_LINE j += 1 NEW_LINE query [ i ] [ 2 ] = temp [ j ] NEW_LINE j += 1 NEW_LINE DEDENT for i in range ( 1 , m + 1 ) : NEW_LINE INDENT if ( query [ i ] [ 0 ] == 1 ) : NEW_LINE INDENT type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) NEW_LINE DEDENT elif ( query [ i ] [ 0 ] == 2 ) : NEW_LINE INDENT type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) NEW_LINE DEDENT DEDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT " V720,"import java . io . * ; class GFG { static int count ( int S [ ] , int m , int n ) { if ( n == 0 ) return 1 ; if ( n < 0 ) return 0 ; if ( m <= 0 && n >= 1 ) return 0 ; return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int m = arr . length ; System . out . println ( count ( arr , m , 4 ) ) ; } } ","def count ( S , m , n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( n < 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( m <= 0 and n >= 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return count ( S , m - 1 , n ) + count ( S , m , n - S [ m - 1 ] ) ; NEW_LINE DEDENT arr = [ 1 , 2 , 3 ] NEW_LINE m = len ( arr ) NEW_LINE print ( count ( arr , m , 4 ) ) NEW_LINE " V721,"import java . util . Vector ; class GFG { static Vector < Integer > Divisors ( int x ) { int c = 0 ; Vector < Integer > v = new Vector < Integer > ( ) ; while ( x % 2 == 0 ) { c ++ ; x /= 2 ; } v . add ( c ) ; c = 0 ; while ( x % 3 == 0 ) { c ++ ; x /= 3 ; } v . add ( c ) ; c = 0 ; while ( x % 7 == 0 ) { c ++ ; x /= 7 ; } v . add ( c ) ; v . add ( x ) ; return v ; } static int MinOperations ( int a , int b ) { Vector < Integer > va = Divisors ( a ) ; Vector < Integer > vb = Divisors ( b ) ; if ( va . get ( 3 ) != vb . get ( 3 ) ) { return - 1 ; } int minOperations = Math . abs ( va . get ( 0 ) - vb . get ( 0 ) ) + Math . abs ( va . get ( 1 ) - vb . get ( 1 ) ) + Math . abs ( va . get ( 2 ) - vb . get ( 2 ) ) ; return minOperations ; } public static void main ( String [ ] args ) { int a = 14 , b = 28 ; System . out . println ( MinOperations ( a , b ) ) ; } } ","def Divisors ( x ) : NEW_LINE INDENT c = 0 NEW_LINE v = [ ] NEW_LINE while ( x % 2 == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE x /= 2 NEW_LINE DEDENT v . append ( c ) NEW_LINE c = 0 NEW_LINE while ( x % 3 == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE x /= 3 NEW_LINE DEDENT v . append ( c ) NEW_LINE c = 0 NEW_LINE while ( x % 7 == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE x /= 7 NEW_LINE DEDENT v . append ( c ) NEW_LINE v . append ( x ) NEW_LINE return v NEW_LINE DEDENT def MinOperations ( a , b ) : NEW_LINE INDENT va = Divisors ( a ) NEW_LINE vb = Divisors ( b ) NEW_LINE if ( va [ 3 ] != vb [ 3 ] ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT minOperations = abs ( va [ 0 ] - vb [ 0 ] ) + abs ( va [ 1 ] - vb [ 1 ] ) + abs ( va [ 2 ] - vb [ 2 ] ) NEW_LINE return minOperations NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 14 NEW_LINE b = 28 NEW_LINE print ( MinOperations ( a , b ) ) NEW_LINE DEDENT " V722,"import java . util . Arrays ; import java . util . HashSet ; import java . util . Set ; public class DistinctElements { public static boolean areDistinct ( Integer arr [ ] ) { Set < Integer > s = new HashSet < Integer > ( Arrays . asList ( arr ) ) ; return ( s . size ( ) == arr . length ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 1 , 2 , 3 , 2 } ; if ( areDistinct ( arr ) ) System . out . println ( "" All ▁ Elements ▁ are ▁ Distinct "" ) ; else System . out . println ( "" Not ▁ all ▁ Elements ▁ are ▁ Distinct "" ) ; } } ","def areDistinct ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE s = set ( ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT s . add ( arr [ i ] ) NEW_LINE DEDENT return ( len ( s ) == len ( arr ) ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 2 ] NEW_LINE if ( areDistinct ( arr ) ) : NEW_LINE INDENT print ( "" All ▁ Elements ▁ are ▁ Distinct "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Not ▁ all ▁ Elements ▁ are ▁ Distinct "" ) NEW_LINE DEDENT " V723,"import java . util . * ; class GFG { static Vector < Integer > createSemiPrimeSieve ( int n ) { int v [ ] = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { v [ i ] = i ; } int countDivision [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { countDivision [ i ] = 2 ; } for ( int i = 2 ; i <= n ; i ++ ) { if ( v [ i ] == i && countDivision [ i ] == 2 ) { for ( int j = 2 * i ; j <= n ; j += i ) { if ( countDivision [ j ] > 0 ) { v [ j ] = v [ j ] / i ; countDivision [ j ] -- ; } } } } Vector < Integer > res = new Vector < > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { if ( v [ i ] == 1 && countDivision [ i ] == 0 ) { res . add ( i ) ; } } return res ; } public static void main ( String [ ] args ) { int n = 16 ; Vector < Integer > semiPrime = createSemiPrimeSieve ( n ) ; for ( int i = 0 ; i < semiPrime . size ( ) ; i ++ ) { System . out . print ( semiPrime . get ( i ) + "" ▁ "" ) ; } } } ","def createSemiPrimeSieve ( n ) : NEW_LINE INDENT v = [ 0 for i in range ( n + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT v [ i ] = i NEW_LINE DEDENT countDivision = [ 0 for i in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT countDivision [ i ] = 2 NEW_LINE DEDENT for i in range ( 2 , n + 1 , 1 ) : NEW_LINE INDENT if ( v [ i ] == i and countDivision [ i ] == 2 ) : NEW_LINE INDENT for j in range ( 2 * i , n + 1 , i ) : NEW_LINE INDENT if ( countDivision [ j ] > 0 ) : NEW_LINE INDENT v [ j ] = int ( v [ j ] / i ) NEW_LINE countDivision [ j ] -= 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT res = [ ] NEW_LINE for i in range ( 2 , n + 1 , 1 ) : NEW_LINE INDENT if ( v [ i ] == 1 and countDivision [ i ] == 0 ) : NEW_LINE INDENT res . append ( i ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 16 NEW_LINE semiPrime = createSemiPrimeSieve ( n ) NEW_LINE for i in range ( len ( semiPrime ) ) : NEW_LINE INDENT print ( semiPrime [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V724,"class Test { static boolean findPattern ( int n ) { int prev = n % 2 ; n = n / 2 ; while ( n > 0 ) { int curr = n % 2 ; if ( curr == prev ) return false ; prev = curr ; n = n / 2 ; } return true ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( findPattern ( n ) ? "" Yes "" : "" No "" ) ; } } ","def findPattern ( n ) : NEW_LINE INDENT prev = n % 2 NEW_LINE n = n // 2 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT curr = n % 2 NEW_LINE if ( curr == prev ) : NEW_LINE INDENT return False NEW_LINE DEDENT prev = curr NEW_LINE n = n // 2 NEW_LINE DEDENT return True NEW_LINE DEDENT n = 10 NEW_LINE print ( "" Yes "" ) if ( findPattern ( n ) ) else print ( "" No "" ) NEW_LINE " V725,"public class GFG { static int countSubstringWithEqualEnds ( String s ) { int result = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i ; j < n ; j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ; return result ; } public static void main ( String args [ ] ) { String s = "" abcab "" ; System . out . println ( countSubstringWithEqualEnds ( s ) ) ; } } ","def countSubstringWithEqualEnds ( s ) : NEW_LINE INDENT result = 0 ; NEW_LINE n = len ( s ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT if ( s [ i ] == s [ j ] ) : NEW_LINE INDENT result = result + 1 NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT s = "" abcab "" ; NEW_LINE print ( countSubstringWithEqualEnds ( s ) ) NEW_LINE " V726,"class GFG { public static int arraySum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 11 , 12 , 13 , 12 , 11 , 10 } ; int n = arr . length ; System . out . print ( arraySum ( arr , n ) ) ; } } ","def arraySum ( arr , n ) : NEW_LINE INDENT _sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT _sum = _sum + arr [ i ] NEW_LINE DEDENT return _sum NEW_LINE DEDENT arr = [ 10 , 11 , 12 , 13 , 12 , 11 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE print ( arraySum ( arr , n ) ) NEW_LINE " V727,"import java . io . * ; class GFG { static float InscribedCircleArea ( float n , float a ) { if ( a < 0 && n < 0 ) return - 1 ; float r = a / ( float ) ( 2 * Math . tan ( ( 180 / n ) * 3.14159 / 180 ) ) ; float Area = ( float ) ( 3.14 ) * ( r ) * ( r ) ; return Area ; } public static void main ( String [ ] args ) { float n = 6 ; float a = 4 ; System . out . println ( InscribedCircleArea ( n , a ) ) ; } } ","from math import tan NEW_LINE def InscribedCircleArea ( n , a ) : NEW_LINE INDENT if ( a < 0 and n < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT r = a / ( 2 * tan ( ( 180 / n ) * 3.14159 / 180 ) ) ; NEW_LINE Area = 3.14 * r * r NEW_LINE return Area NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 4 NEW_LINE n = 6 NEW_LINE print ( ' { 0 : . 6 } ' . format ( InscribedCircleArea ( n , a ) ) ) NEW_LINE DEDENT " V728,"import java . util . * ; class GFG { static int minChanges ( int arr [ ] , int n ) { Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } int maxElem = 0 ; for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) { maxElem = Math . max ( maxElem , entry . getValue ( ) ) ; } return n - maxElem ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 3 , 4 } ; int n = arr . length ; System . out . println ( minChanges ( arr , n ) ) ; } } ","def minChanges ( arr , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in mp . keys ( ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT maxElem = 0 NEW_LINE for x in mp : NEW_LINE INDENT maxElem = max ( maxElem , mp [ x ] ) NEW_LINE DEDENT return n - maxElem NEW_LINE DEDENT arr = [ 2 , 3 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minChanges ( arr , n ) ) NEW_LINE " V729,"class GFG { static int factorial ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) fact = fact * i ; return ( fact ) ; } static int result ( int n , int m ) { return ( factorial ( n ) - factorial ( n - m + 1 ) * factorial ( m ) ) ; } public static void main ( String args [ ] ) { System . out . println ( result ( 5 , 3 ) ) ; } } ","def factorial ( n ) : NEW_LINE INDENT fact = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT fact = fact * i NEW_LINE DEDENT return ( fact ) NEW_LINE DEDENT def result ( n , m ) : NEW_LINE INDENT return ( factorial ( n ) - factorial ( n - m + 1 ) * factorial ( m ) ) NEW_LINE DEDENT print ( result ( 5 , 3 ) ) NEW_LINE " V730,"class GFG { static int maxN = 31 ; static int maxW = 31 ; static int dp [ ] [ ] [ ] = new int [ maxN ] [ maxW ] [ maxW ] ; static int maxWeight ( int arr [ ] , int n , int w1_r , int w2_r , int i ) { if ( i == n ) return 0 ; if ( dp [ i ] [ w1_r ] [ w2_r ] != - 1 ) return dp [ i ] [ w1_r ] [ w2_r ] ; int fill_w1 = 0 , fill_w2 = 0 , fill_none = 0 ; if ( w1_r >= arr [ i ] ) fill_w1 = arr [ i ] + maxWeight ( arr , n , w1_r - arr [ i ] , w2_r , i + 1 ) ; if ( w2_r >= arr [ i ] ) fill_w2 = arr [ i ] + maxWeight ( arr , n , w1_r , w2_r - arr [ i ] , i + 1 ) ; fill_none = maxWeight ( arr , n , w1_r , w2_r , i + 1 ) ; dp [ i ] [ w1_r ] [ w2_r ] = Math . max ( fill_none , Math . max ( fill_w1 , fill_w2 ) ) ; return dp [ i ] [ w1_r ] [ w2_r ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 2 , 3 } ; for ( int i = 0 ; i < maxN ; i ++ ) for ( int j = 0 ; j < maxW ; j ++ ) for ( int k = 0 ; k < maxW ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; int n = arr . length ; int w1 = 10 , w2 = 3 ; System . out . println ( maxWeight ( arr , n , w1 , w2 , 0 ) ) ; } } ","def maxWeight ( arr , n , w1_r , w2_r , i ) : NEW_LINE INDENT if i == n : NEW_LINE INDENT return 0 NEW_LINE DEDENT if dp [ i ] [ w1_r ] [ w2_r ] != - 1 : NEW_LINE INDENT return dp [ i ] [ w1_r ] [ w2_r ] NEW_LINE DEDENT fill_w1 , fill_w2 , fill_none = 0 , 0 , 0 NEW_LINE if w1_r >= arr [ i ] : NEW_LINE INDENT fill_w1 = arr [ i ] + maxWeight ( arr , n , w1_r - arr [ i ] , w2_r , i + 1 ) NEW_LINE DEDENT if w2_r >= arr [ i ] : NEW_LINE INDENT fill_w2 = arr [ i ] + maxWeight ( arr , n , w1_r , w2_r - arr [ i ] , i + 1 ) NEW_LINE DEDENT fill_none = maxWeight ( arr , n , w1_r , w2_r , i + 1 ) NEW_LINE dp [ i ] [ w1_r ] [ w2_r ] = max ( fill_none , max ( fill_w1 , fill_w2 ) ) NEW_LINE return dp [ i ] [ w1_r ] [ w2_r ] NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 8 , 2 , 3 ] NEW_LINE maxN , maxW = 31 , 31 NEW_LINE dp = [ [ [ - 1 ] * maxW ] * maxW ] * maxN NEW_LINE n = len ( arr ) NEW_LINE w1 , w2 = 10 , 3 NEW_LINE print ( maxWeight ( arr , n , w1 , w2 , 0 ) ) NEW_LINE DEDENT " V731,"import java . io . * ; class Count { public static void main ( String args [ ] ) { String str = "" # GeeKs01fOr @ gEEks07"" ; int upper = 0 , lower = 0 , number = 0 , special = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch >= ' A ' && ch <= ' Z ' ) upper ++ ; else if ( ch >= ' a ' && ch <= ' z ' ) lower ++ ; else if ( ch >= '0' && ch <= '9' ) number ++ ; else special ++ ; } System . out . println ( "" Lower ▁ case ▁ letters ▁ : ▁ "" + lower ) ; System . out . println ( "" Upper ▁ case ▁ letters ▁ : ▁ "" + upper ) ; System . out . println ( "" Number ▁ : ▁ "" + number ) ; System . out . println ( "" Special ▁ characters ▁ : ▁ "" + special ) ; } } ","def Count ( str ) : NEW_LINE INDENT upper , lower , number , special = 0 , 0 , 0 , 0 NEW_LINE for i in range ( len ( str ) ) : NEW_LINE INDENT if str [ i ] >= ' A ' and str [ i ] <= ' Z ' : NEW_LINE INDENT upper += 1 NEW_LINE DEDENT elif str [ i ] >= ' a ' and str [ i ] <= ' z ' : NEW_LINE INDENT lower += 1 NEW_LINE DEDENT elif str [ i ] >= '0' and str [ i ] <= '9' : NEW_LINE INDENT number += 1 NEW_LINE DEDENT else : NEW_LINE INDENT special += 1 NEW_LINE DEDENT DEDENT print ( ' Upper ▁ case ▁ letters : ' , upper ) NEW_LINE print ( ' Lower ▁ case ▁ letters : ' , lower ) NEW_LINE print ( ' Number : ' , number ) NEW_LINE print ( ' Special ▁ characters : ' , special ) NEW_LINE DEDENT str = "" # GeeKs01fOr @ gEEks07"" NEW_LINE Count ( str ) NEW_LINE " V732,"class GFG { static int val ( char c ) { if ( c >= '0' && c <= '9' ) return ( int ) c - '0' ; else return ( int ) c - ' A ' + 10 ; } static int toDeci ( String str , int base ) { int len = str . length ( ) ; int power = 1 ; int num = 0 ; int i ; for ( i = len - 1 ; i >= 0 ; i -- ) { if ( val ( str . charAt ( i ) ) >= base ) { return - 1 ; } num += val ( str . charAt ( i ) ) * power ; power = power * base ; } return num ; } static void checkCorrespond ( String [ ] str , int x ) { int counter = 0 ; int n = str . length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 2 ; j <= 36 ; j ++ ) { if ( toDeci ( str [ i ] , j ) == x ) { counter ++ ; break ; } } } if ( counter == n ) System . out . print ( "" YES "" + "" \n "" ) ; else System . out . print ( "" NO "" + "" \n "" ) ; } public static void main ( String [ ] args ) { int x = 16 ; String [ ] str = { ""10000"" , ""20"" , ""16"" } ; checkCorrespond ( str , x ) ; } } ","def val ( c ) : NEW_LINE INDENT if ( c >= '0' and c <= '9' ) : NEW_LINE INDENT return int ( c ) NEW_LINE DEDENT else : NEW_LINE INDENT return c - ' A ' + 10 NEW_LINE DEDENT DEDENT def toDeci ( strr , base ) : NEW_LINE INDENT lenn = len ( strr ) NEW_LINE power = 1 NEW_LINE num = 0 NEW_LINE for i in range ( lenn - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( val ( strr [ i ] ) >= base ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT num += val ( strr [ i ] ) * power NEW_LINE power = power * base NEW_LINE DEDENT return num NEW_LINE DEDENT def checkCorrespond ( strr , x ) : NEW_LINE INDENT counter = 0 NEW_LINE n = len ( strr ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( 2 , 37 ) : NEW_LINE INDENT if ( toDeci ( strr [ i ] , j ) == x ) : NEW_LINE INDENT counter += 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( counter == n ) : NEW_LINE INDENT print ( "" YES "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) NEW_LINE DEDENT DEDENT x = 16 NEW_LINE strr = [ ""10000"" , ""20"" , ""16"" ] NEW_LINE checkCorrespond ( strr , x ) NEW_LINE " V733,"import java . util . * ; class GFG { static int count ( int x , int y ) { int ans = 0 ; Map < Integer , Integer > m = new HashMap < > ( ) ; while ( x % y != 0 ) { x = x % y ; ans ++ ; if ( m . containsKey ( x ) ) return - 1 ; m . put ( x , 1 ) ; x = x * 10 ; } return ans ; } public static void main ( String [ ] args ) { int res = count ( 1 , 2 ) ; if ( ( res == - 1 ) ) System . out . println ( "" INF "" ) ; else System . out . println ( res ) ; res = count ( 5 , 3 ) ; if ( ( res == - 1 ) ) System . out . println ( "" INF "" ) ; else System . out . println ( res ) ; res = count ( 3 , 5 ) ; if ( ( res == - 1 ) ) System . out . println ( "" INF "" ) ; else System . out . println ( res ) ; } } ","def count ( x , y ) : NEW_LINE INDENT ans = 0 NEW_LINE m = dict ( ) NEW_LINE while x % y != 0 : NEW_LINE INDENT x %= y NEW_LINE ans += 1 NEW_LINE if x in m : NEW_LINE INDENT return - 1 NEW_LINE DEDENT m [ x ] = 1 NEW_LINE x *= 10 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT res = count ( 1 , 2 ) NEW_LINE print ( "" INF "" ) if res == - 1 else print ( res ) NEW_LINE res = count ( 5 , 3 ) NEW_LINE print ( "" INF "" ) if res == - 1 else print ( res ) NEW_LINE res = count ( 3 , 5 ) NEW_LINE print ( "" INF "" ) if res == - 1 else print ( res ) NEW_LINE DEDENT " V734,"import java . io . * ; class GFG { static int nextPowerOf2 ( int n ) { int p = 1 ; if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ; while ( p < n ) p <<= 1 ; return p ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( nextPowerOf2 ( n ) ) ; } } ","def nextPowerOf2 ( n ) : NEW_LINE INDENT p = 1 NEW_LINE if ( n and not ( n & ( n - 1 ) ) ) : NEW_LINE INDENT return n NEW_LINE DEDENT while ( p < n ) : NEW_LINE INDENT p <<= 1 NEW_LINE DEDENT return p ; NEW_LINE DEDENT n = 5 NEW_LINE print ( nextPowerOf2 ( n ) ) ; NEW_LINE " V735,"import java . util . Vector ; class GFG { static long LCM ( int arr [ ] , int n ) { int max_num = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( max_num < arr [ i ] ) { max_num = arr [ i ] ; } } long res = 1 ; int x = 2 ; while ( x <= max_num ) { Vector < Integer > indexes = new Vector < > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] % x == 0 ) { indexes . add ( indexes . size ( ) , j ) ; } } if ( indexes . size ( ) >= 2 ) { for ( int j = 0 ; j < indexes . size ( ) ; j ++ ) { arr [ indexes . get ( j ) ] = arr [ indexes . get ( j ) ] / x ; } res = res * x ; } else { x ++ ; } } for ( int i = 0 ; i < n ; i ++ ) { res = res * arr [ i ] ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 10 , 20 , 35 } ; int n = arr . length ; System . out . println ( LCM ( arr , n ) ) ; } } ","def LCM ( arr , n ) : NEW_LINE INDENT max_num = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( max_num < arr [ i ] ) : NEW_LINE INDENT max_num = arr [ i ] ; NEW_LINE DEDENT DEDENT res = 1 ; NEW_LINE x = 2 ; NEW_LINE while ( x <= max_num ) : NEW_LINE INDENT indexes = [ ] ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( arr [ j ] % x == 0 ) : NEW_LINE INDENT indexes . append ( j ) ; NEW_LINE DEDENT DEDENT if ( len ( indexes ) >= 2 ) : NEW_LINE INDENT for j in range ( len ( indexes ) ) : NEW_LINE INDENT arr [ indexes [ j ] ] = int ( arr [ indexes [ j ] ] / x ) ; NEW_LINE DEDENT res = res * x ; NEW_LINE DEDENT else : NEW_LINE INDENT x += 1 ; NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT res = res * arr [ i ] ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 10 , 20 , 35 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( LCM ( arr , n ) ) ; NEW_LINE " V736,"class GFG { static int maxConsecutiveOnes ( int x ) { int count = 0 ; while ( x != 0 ) { x = ( x & ( x << 1 ) ) ; count ++ ; } return count ; } static int maxOnes ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int currMax = maxConsecutiveOnes ( arr [ i ] ) ; ans = Math . max ( ans , currMax ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; System . out . println ( maxOnes ( arr , n ) ) ; } } ","def maxConsecutiveOnes ( x ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( x != 0 ) : NEW_LINE INDENT x = ( x & ( x << 1 ) ) ; NEW_LINE count += 1 ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT def maxOnes ( arr , n ) : NEW_LINE INDENT ans = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT currMax = maxConsecutiveOnes ( arr [ i ] ) ; NEW_LINE ans = max ( ans , currMax ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( maxOnes ( arr , n ) ) ; NEW_LINE DEDENT " V737,"import java . io . * ; class GFG { static int countSegments ( int a [ ] , int n , int x ) { boolean flag = false ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { flag = true ; } else { if ( flag ) count += 1 ; flag = false ; } } if ( flag ) count += 1 ; return count ; } public static void main ( String [ ] args ) { int a [ ] = { 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 } ; int n = a . length ; int x = 13 ; System . out . println ( countSegments ( a , n , x ) ) ; } } ","def countSegments ( a , n , x ) : NEW_LINE INDENT flag = False NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] > x ) : NEW_LINE INDENT flag = True NEW_LINE DEDENT else : NEW_LINE INDENT if ( flag ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT flag = False NEW_LINE DEDENT DEDENT if ( flag ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 ] NEW_LINE n = len ( a ) NEW_LINE x = 13 NEW_LINE print ( countSegments ( a , n , x ) ) NEW_LINE DEDENT " V738,"class GFG { static void line ( double x0 , double y0 ) { double c = ( int ) ( 2 * y0 * x0 ) ; System . out . println ( y0 + "" x "" + "" ▁ + ▁ "" + x0 + "" y ▁ = ▁ "" + c ) ; } public static void main ( String [ ] args ) { double x0 = 4 , y0 = 3 ; line ( x0 , y0 ) ; } } ","def line ( x0 , y0 ) : NEW_LINE INDENT c = 2 * y0 * x0 NEW_LINE print ( y0 , "" x "" , "" + "" , x0 , "" y = "" , c ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x0 = 4 NEW_LINE y0 = 3 NEW_LINE line ( x0 , y0 ) NEW_LINE DEDENT " V739,"import java . util . * ; class GFG { static int minDiff ( int n , int x , int A [ ] ) { int mn = A [ 0 ] , mx = A [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) { mn = Math . min ( mn , A [ i ] ) ; mx = Math . max ( mx , A [ i ] ) ; } return Math . max ( 0 , mx - mn - 2 * x ) ; } public static void main ( String [ ] args ) { int n = 3 , x = 3 ; int A [ ] = { 1 , 3 , 6 } ; System . out . println ( minDiff ( n , x , A ) ) ; } } ","def minDiff ( n , x , A ) : NEW_LINE INDENT mn = A [ 0 ] NEW_LINE mx = A [ 0 ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT mn = min ( mn , A [ i ] ) NEW_LINE mx = max ( mx , A [ i ] ) NEW_LINE DEDENT return max ( 0 , mx - mn - 2 * x ) NEW_LINE DEDENT n = 3 NEW_LINE x = 3 NEW_LINE A = [ 1 , 3 , 6 ] NEW_LINE print ( minDiff ( n , x , A ) ) NEW_LINE " V740,"public class GFG { static int fact ( int num ) { int fact = 1 ; while ( num > 1 ) { fact *= num ; num -= 1 ; } return fact ; } static int catalan ( int n ) { return fact ( 2 * n ) / ( fact ( n ) * fact ( n + 1 ) ) ; } public static void main ( String [ ] args ) { int n = 5 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int i , k ; for ( k = 0 ; k < n ; k ++ ) { int s = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ k ] ) s += 1 ; } int catalan_leftBST = catalan ( s ) ; int catalan_rightBST = catalan ( n - s - 1 ) ; int totalBST = catalan_rightBST * catalan_leftBST ; System . out . print ( totalBST + "" ▁ "" ) ; } } } ","def fact ( num ) : NEW_LINE INDENT fact = 1 ; NEW_LINE while ( num > 1 ) : NEW_LINE INDENT fact = fact * num ; NEW_LINE num = num - 1 ; NEW_LINE DEDENT return fact ; NEW_LINE DEDENT def catalan ( n ) : NEW_LINE INDENT return fact ( 2 * n ) // ( fact ( n ) * fact ( n + 1 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE for k in range ( n ) : NEW_LINE INDENT s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] < arr [ k ] : NEW_LINE INDENT s += 1 NEW_LINE DEDENT DEDENT catalan_leftBST = catalan ( s ) NEW_LINE catalan_rightBST = catalan ( n - s - 1 ) NEW_LINE totalBST = catalan_rightBST * catalan_leftBST NEW_LINE print ( totalBST , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V741,"class GFG { static void nthPalindrome ( int n , int k ) { int temp = ( k & 1 ) != 0 ? ( k / 2 ) : ( k / 2 - 1 ) ; int palindrome = ( int ) Math . pow ( 10 , temp ) ; palindrome += n - 1 ; System . out . print ( palindrome ) ; if ( ( k & 1 ) > 0 ) palindrome /= 10 ; while ( palindrome > 0 ) { System . out . print ( palindrome % 10 ) ; palindrome /= 10 ; } System . out . println ( "" "" ) ; } public static void main ( String [ ] args ) { int n = 6 , k = 5 ; System . out . print ( n + "" th ▁ palindrome ▁ of ▁ "" + k + "" ▁ digit ▁ = ▁ "" ) ; nthPalindrome ( n , k ) ; n = 10 ; k = 6 ; System . out . print ( n + "" th ▁ palindrome ▁ of ▁ "" + k + "" ▁ digit ▁ = ▁ "" ) ; nthPalindrome ( n , k ) ; } } ","def nthPalindrome ( n , k ) : NEW_LINE INDENT if ( k & 1 ) : NEW_LINE INDENT temp = k // 2 NEW_LINE DEDENT else : NEW_LINE INDENT temp = k // 2 - 1 NEW_LINE DEDENT palindrome = 10 ** temp NEW_LINE palindrome = palindrome + n - 1 NEW_LINE print ( palindrome , end = "" "" ) NEW_LINE if ( k & 1 ) : NEW_LINE INDENT palindrome = palindrome // 10 NEW_LINE DEDENT while ( palindrome ) : NEW_LINE INDENT print ( palindrome % 10 , end = "" "" ) NEW_LINE palindrome = palindrome // 10 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE k = 5 NEW_LINE print ( n , "" th ▁ palindrome ▁ of "" , k , "" ▁ digit ▁ = ▁ "" , end = "" ▁ "" ) NEW_LINE nthPalindrome ( n , k ) NEW_LINE print ( ) NEW_LINE n = 10 NEW_LINE k = 6 NEW_LINE print ( n , "" th ▁ palindrome ▁ of "" , k , "" digit ▁ = ▁ "" , end = "" ▁ "" ) NEW_LINE nthPalindrome ( n , k ) NEW_LINE DEDENT " V742,"class GFG { static int sum , n ; static float getAvg ( int x ) { sum += x ; return ( ( ( float ) sum ) / ++ n ) ; } static void streamAvg ( float [ ] arr , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( ( int ) arr [ i ] ) ; System . out . println ( "" Average ▁ of ▁ "" + ( i + 1 ) + "" ▁ numbers ▁ is ▁ "" + avg ) ; } return ; } public static void main ( String [ ] args ) { float [ ] arr = new float [ ] { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = arr . length ; streamAvg ( arr , n ) ; } } ","def getAvg ( x , n , sum ) : NEW_LINE INDENT sum = sum + x ; NEW_LINE return float ( sum ) / n ; NEW_LINE DEDENT def streamAvg ( arr , n ) : NEW_LINE INDENT avg = 0 ; NEW_LINE sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT avg = getAvg ( arr [ i ] , i + 1 , sum ) ; NEW_LINE sum = avg * ( i + 1 ) ; NEW_LINE print ( "" Average ▁ of ▁ "" , end = "" "" ) ; NEW_LINE print ( i + 1 , end = "" "" ) ; NEW_LINE print ( "" ▁ numbers ▁ is ▁ "" , end = "" "" ) ; NEW_LINE print ( avg ) ; NEW_LINE DEDENT return ; NEW_LINE DEDENT arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE streamAvg ( arr , n ) ; NEW_LINE " V743,"class GFG { static int Permutations ( int n , int k ) { int ans = 1 ; if ( k >= 2 ) ans += ( n ) * ( n - 1 ) / 2 ; if ( k >= 3 ) ans += ( n ) * ( n - 1 ) * ( n - 2 ) * 2 / 6 ; if ( k >= 4 ) ans += ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) * 9 / 24 ; return ans ; } public static void main ( String [ ] args ) { int n = 5 , k = 2 ; System . out . println ( Permutations ( n , k ) ) ; } } ","def Permutations ( n , k ) : NEW_LINE INDENT ans = 1 NEW_LINE if k >= 2 : NEW_LINE INDENT ans += ( n ) * ( n - 1 ) // 2 NEW_LINE DEDENT if k >= 3 : NEW_LINE INDENT ans += ( ( n ) * ( n - 1 ) * ( n - 2 ) * 2 // 6 ) NEW_LINE DEDENT if k >= 4 : NEW_LINE INDENT ans += ( ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) * 9 // 24 ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n , k = 5 , 2 NEW_LINE print ( Permutations ( n , k ) ) NEW_LINE DEDENT " V744,"class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 || n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static Node deleteNonPrimeNodes ( Node head_ref ) { Node ptr = head_ref ; while ( ptr != null && ! isPrime ( ptr . data ) ) { Node temp = ptr ; ptr = ptr . next ; } head_ref = ptr ; if ( ptr == null ) return null ; Node curr = ptr . next ; while ( curr != null ) { if ( ! isPrime ( curr . data ) ) { ptr . next = curr . next ; curr = ptr . next ; } else { ptr = curr ; curr = curr . next ; } } return head_ref ; } static void printList ( Node head ) { while ( head != null ) { System . out . print ( head . data + "" ▁ "" ) ; head = head . next ; } } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 17 ) ; head = push ( head , 7 ) ; head = push ( head , 6 ) ; head = push ( head , 16 ) ; head = push ( head , 15 ) ; System . out . print ( "" Original ▁ List : ▁ "" ) ; printList ( head ) ; head = deleteNonPrimeNodes ( head ) ; System . out . print ( "" \n Modified ▁ List : ▁ "" ) ; 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 push ( head_ref , new_data ) : NEW_LINE INDENT new_node = Node ( new_data ) NEW_LINE new_node . data = new_data NEW_LINE new_node . next = head_ref NEW_LINE head_ref = new_node NEW_LINE return head_ref NEW_LINE DEDENT def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 5 , n + 1 , 6 ) : NEW_LINE INDENT if ( i * i < n + 2 and ( n % i == 0 or n % ( i + 2 ) == 0 ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def deleteNonPrimeNodes ( head_ref ) : NEW_LINE INDENT ptr = head_ref NEW_LINE while ( ptr != None and isPrime ( ptr . data ) != True ) : NEW_LINE INDENT temp = ptr NEW_LINE ptr = ptr . next NEW_LINE DEDENT head_ref = ptr NEW_LINE if ( ptr == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT curr = ptr . next NEW_LINE while ( curr != None ) : NEW_LINE INDENT if ( isPrime ( curr . data ) != True ) : NEW_LINE INDENT ptr . next = curr . next NEW_LINE curr = ptr . next NEW_LINE DEDENT else : NEW_LINE INDENT ptr = curr NEW_LINE curr = curr . next NEW_LINE DEDENT return head_ref NEW_LINE DEDENT DEDENT def printList ( head ) : NEW_LINE INDENT while ( head != None ) : NEW_LINE INDENT print ( head . data , end = "" ▁ "" ) NEW_LINE head = head . next NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 17 ) NEW_LINE head = push ( head , 7 ) NEW_LINE head = push ( head , 6 ) NEW_LINE head = push ( head , 16 ) NEW_LINE head = push ( head , 15 ) NEW_LINE print ( "" Original ▁ List : ▁ "" ) NEW_LINE printList ( head ) NEW_LINE head = deleteNonPrimeNodes ( head ) NEW_LINE print ( "" \n Modified ▁ List : ▁ "" ) NEW_LINE printList ( head ) NEW_LINE DEDENT " V745,"class GFG { static String findMinLenStr ( String str , int k ) { int n = str . length ( ) ; int st = 0 ; int end = 0 ; int cnt [ ] = new int [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) cnt [ i ] = 0 ; int distEle = 0 ; int currlen ; int minlen = n ; int startInd = - 1 ; while ( end < n ) { cnt [ str . charAt ( end ) - ' a ' ] ++ ; if ( cnt [ str . charAt ( end ) - ' a ' ] == 1 ) distEle ++ ; if ( distEle > k ) { while ( st < end && distEle > k ) { if ( cnt [ str . charAt ( st ) - ' a ' ] == 1 ) distEle -- ; cnt [ str . charAt ( st ) - ' a ' ] -- ; st ++ ; } } if ( distEle == k ) { while ( st < end && cnt [ str . charAt ( st ) - ' a ' ] > 1 ) { cnt [ str . charAt ( st ) - ' a ' ] -- ; st ++ ; } currlen = end - st + 1 ; if ( currlen < minlen ) { minlen = currlen ; startInd = st ; } } end ++ ; } return str . substring ( startInd , startInd + minlen ) ; } public static void main ( String args [ ] ) { String str = "" efecfefd "" ; int k = 4 ; System . out . println ( findMinLenStr ( str , k ) ) ; } } ","def findMinLenStr ( str , k ) : NEW_LINE INDENT n = len ( str ) NEW_LINE st = 0 NEW_LINE end = 0 NEW_LINE cnt = [ 0 ] * 26 NEW_LINE distEle = 0 NEW_LINE currlen = 0 NEW_LINE minlen = n NEW_LINE startInd = - 1 NEW_LINE while ( end < n ) : NEW_LINE INDENT cnt [ ord ( str [ end ] ) - ord ( ' a ' ) ] += 1 NEW_LINE if ( cnt [ ord ( str [ end ] ) - ord ( ' a ' ) ] == 1 ) : NEW_LINE INDENT distEle += 1 NEW_LINE DEDENT if ( distEle > k ) : NEW_LINE INDENT while ( st < end and distEle > k ) : NEW_LINE INDENT if ( cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] == 1 ) : NEW_LINE INDENT distEle -= 1 NEW_LINE DEDENT cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] -= 1 NEW_LINE st += 1 NEW_LINE DEDENT DEDENT if ( distEle == k ) : NEW_LINE INDENT while ( st < end and cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] > 1 ) : NEW_LINE INDENT cnt [ ord ( str [ st ] ) - ord ( ' a ' ) ] -= 1 NEW_LINE st += 1 NEW_LINE DEDENT currlen = end - st + 1 NEW_LINE if ( currlen < minlen ) : NEW_LINE INDENT minlen = currlen NEW_LINE startInd = st NEW_LINE DEDENT DEDENT end += 1 NEW_LINE DEDENT return str [ startInd : startInd + minlen ] NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str = "" efecfefd "" NEW_LINE k = 4 NEW_LINE print ( findMinLenStr ( str , k ) ) NEW_LINE DEDENT " V746,"class GFG { static int longestSubarray ( int arr [ ] , int n ) { int i , d ; int hash [ ] [ ] = new int [ 2 ] [ 10 ] ; for ( i = 0 ; i < 2 ; i ++ ) for ( int j = 0 ; j < 10 ; j ++ ) hash [ i ] [ j ] = 0 ; int currRow ; int maxLen = 1 ; int len = 0 ; int tmp ; tmp = arr [ 0 ] ; while ( tmp > 0 ) { hash [ 0 ] [ tmp % 10 ] = 1 ; tmp /= 10 ; } currRow = 1 ; for ( i = 1 ; i < n ; i ++ ) { tmp = arr [ i ] ; for ( d = 0 ; d <= 9 ; d ++ ) hash [ currRow ] [ d ] = 0 ; while ( tmp > 0 ) { hash [ currRow ] [ tmp % 10 ] = 1 ; tmp /= 10 ; } for ( d = 0 ; d <= 9 ; d ++ ) { if ( hash [ currRow ] [ d ] != 0 && hash [ 1 - currRow ] [ d ] != 0 ) { len ++ ; break ; } } if ( d == 10 ) { len = 1 ; } maxLen = Math . max ( maxLen , len ) ; currRow = 1 - currRow ; } return maxLen ; } public static void main ( String args [ ] ) { int arr [ ] = { 11 , 22 , 33 , 44 , 54 , 56 , 63 } ; int n = arr . length ; System . out . println ( longestSubarray ( arr , n ) ) ; } } ","import math NEW_LINE def longestSubarray ( arr , n ) : NEW_LINE INDENT i = d = 0 ; NEW_LINE HASH1 = [ [ 0 for x in range ( 10 ) ] for y in range ( 2 ) ] ; NEW_LINE currRow = 0 ; NEW_LINE maxLen = 1 ; NEW_LINE len1 = 0 ; NEW_LINE tmp = 0 ; NEW_LINE tmp = arr [ 0 ] ; NEW_LINE while ( tmp > 0 ) : NEW_LINE INDENT HASH1 [ 0 ] [ tmp % 10 ] = 1 ; NEW_LINE tmp = tmp // 10 ; NEW_LINE DEDENT currRow = 1 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT tmp = arr [ i ] ; NEW_LINE for d in range ( 0 , 10 ) : NEW_LINE INDENT HASH1 [ currRow ] [ d ] = 0 ; NEW_LINE DEDENT while ( tmp > 0 ) : NEW_LINE INDENT HASH1 [ currRow ] [ tmp % 10 ] = 1 ; NEW_LINE tmp = tmp // 10 ; NEW_LINE DEDENT for d in range ( 0 , 10 ) : NEW_LINE INDENT if ( HASH1 [ currRow ] [ d ] and HASH1 [ 1 - currRow ] [ d ] ) : NEW_LINE INDENT len1 += 1 ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( d == 10 ) : NEW_LINE INDENT len1 = 1 ; NEW_LINE DEDENT maxLen = max ( maxLen , len1 ) ; NEW_LINE currRow = 1 - currRow ; NEW_LINE DEDENT return maxLen ; NEW_LINE DEDENT arr = [ 11 , 22 , 33 , 44 , 54 , 56 , 63 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( longestSubarray ( arr , n ) ) ; NEW_LINE " V747,"class GFG { static int sumNatural ( int n ) { int sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } static int suminRange ( int l , int r ) { return sumNatural ( r ) - sumNatural ( l - 1 ) ; } public static void main ( String [ ] args ) { int l = 2 , r = 5 ; System . out . println ( "" Sum ▁ of ▁ Natural ▁ numbers ▁ from ▁ L ▁ to ▁ R ▁ is ▁ "" + suminRange ( l , r ) ) ; } } ","def sumNatural ( n ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) // 2 NEW_LINE return sum NEW_LINE DEDENT def suminRange ( l , r ) : NEW_LINE INDENT return sumNatural ( r ) - sumNatural ( l - 1 ) NEW_LINE DEDENT l = 2 ; r = 5 NEW_LINE print ( "" Sum ▁ of ▁ Natural ▁ numbers ▁ from ▁ L ▁ to ▁ R ▁ is ▁ "" , suminRange ( l , r ) ) NEW_LINE " V748,"public class GFG { static int findIndex ( String str ) { int len = str . length ( ) ; int open [ ] = new int [ len + 1 ] ; int close [ ] = new int [ len + 1 ] ; int index = - 1 ; open [ 0 ] = 0 ; close [ len ] = 0 ; if ( str . charAt ( 0 ) == ' ( ' ) open [ 1 ] = 1 ; if ( str . charAt ( len - 1 ) == ' ) ' ) close [ len - 1 ] = 1 ; for ( int i = 1 ; i < len ; i ++ ) { if ( str . charAt ( i ) == ' ( ' ) open [ i + 1 ] = open [ i ] + 1 ; else open [ i + 1 ] = open [ i ] ; } for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) == ' ) ' ) close [ i ] = close [ i + 1 ] + 1 ; else close [ i ] = close [ i + 1 ] ; } if ( open [ len ] == 0 ) return len ; if ( close [ 0 ] == 0 ) return 0 ; for ( int i = 0 ; i <= len ; i ++ ) if ( open [ i ] == close [ i ] ) index = i ; return index ; } public static void main ( String [ ] args ) { String str = "" ( ( ) ) ) ( ( ) ( ) ( ) ) ) ) "" ; System . out . println ( findIndex ( str ) ) ; } } ","def findIndex ( str ) : NEW_LINE INDENT l = len ( str ) NEW_LINE open = [ 0 ] * ( l + 1 ) NEW_LINE close = [ 0 ] * ( l + 1 ) NEW_LINE index = - 1 NEW_LINE open [ 0 ] = 0 NEW_LINE close [ l ] = 0 NEW_LINE if ( str [ 0 ] == ' ( ' ) : NEW_LINE INDENT open [ 1 ] = 1 NEW_LINE DEDENT if ( str [ l - 1 ] == ' ) ' ) : NEW_LINE INDENT close [ l - 1 ] = 1 NEW_LINE DEDENT for i in range ( 1 , l ) : NEW_LINE INDENT if ( str [ i ] == ' ( ' ) : NEW_LINE INDENT open [ i + 1 ] = open [ i ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT open [ i + 1 ] = open [ i ] NEW_LINE DEDENT DEDENT for i in range ( l - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( str [ i ] == ' ) ' ) : NEW_LINE INDENT close [ i ] = close [ i + 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT close [ i ] = close [ i + 1 ] NEW_LINE DEDENT DEDENT if ( open [ l ] == 0 ) : NEW_LINE INDENT return len NEW_LINE DEDENT if ( close [ 0 ] == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT for i in range ( l + 1 ) : NEW_LINE INDENT if ( open [ i ] == close [ i ] ) : NEW_LINE INDENT index = i NEW_LINE DEDENT DEDENT return index NEW_LINE DEDENT str = "" ( ( ) ) ) ( ( ) ( ) ( ) ) ) ) "" NEW_LINE print ( findIndex ( str ) ) NEW_LINE " V749,"public class GFG { static int findLen ( String A , int n , int k , char ch ) { int maxlen = 1 ; int cnt = 0 ; int l = 0 , r = 0 ; while ( r < n ) { if ( A . charAt ( r ) != ch ) ++ cnt ; while ( cnt > k ) { if ( A . charAt ( l ) != ch ) -- cnt ; ++ l ; } maxlen = Math . max ( maxlen , r - l + 1 ) ; ++ r ; } return maxlen ; } static int answer ( String A , int n , int k ) { int maxlen = 1 ; for ( int i = 0 ; i < 26 ; ++ i ) { maxlen = Math . max ( maxlen , findLen ( A , n , k , ( char ) ( i + ' A ' ) ) ) ; maxlen = Math . max ( maxlen , findLen ( A , n , k , ( char ) ( i + ' a ' ) ) ) ; } return maxlen ; } public static void main ( String [ ] args ) { int n = 5 , k = 2 ; String A = "" ABABA "" ; System . out . println ( "" Maximum ▁ length ▁ = ▁ "" + answer ( A , n , k ) ) ; n = 6 ; k = 4 ; String B = "" HHHHHH "" ; System . out . println ( "" Maximum ▁ length ▁ = ▁ "" + answer ( B , n , k ) ) ; } } ","def findLen ( A , n , k , ch ) : NEW_LINE INDENT maxlen = 1 NEW_LINE cnt = 0 NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE while r < n : NEW_LINE INDENT if A [ r ] != ch : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT while cnt > k : NEW_LINE INDENT if A [ l ] != ch : NEW_LINE INDENT cnt -= 1 NEW_LINE DEDENT l += 1 NEW_LINE DEDENT maxlen = max ( maxlen , r - l + 1 ) NEW_LINE r += 1 NEW_LINE DEDENT return maxlen NEW_LINE DEDENT def answer ( A , n , k ) : NEW_LINE INDENT maxlen = 1 NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT maxlen = max ( maxlen , findLen ( A , n , k , chr ( i + ord ( ' A ' ) ) ) ) NEW_LINE maxlen = max ( maxlen , findLen ( A , n , k , chr ( i + ord ( ' a ' ) ) ) ) NEW_LINE DEDENT return maxlen NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 5 NEW_LINE k = 2 NEW_LINE A = "" ABABA "" NEW_LINE print ( "" Maximum ▁ length ▁ = "" , answer ( A , n , k ) ) NEW_LINE n = 6 NEW_LINE k = 4 NEW_LINE B = "" HHHHHH "" NEW_LINE print ( "" Maximum ▁ length ▁ = "" , answer ( B , n , k ) ) NEW_LINE DEDENT " V750,"class Test { static boolean isTidy ( int num ) { int prev = 10 ; while ( num != 0 ) { int rem = num % 10 ; num /= 10 ; if ( rem > prev ) return false ; prev = rem ; } return true ; } public static void main ( String [ ] args ) { int num = 1556 ; System . out . println ( isTidy ( num ) ? "" Yes "" : "" No "" ) ; } } ","def isTidy ( num ) : NEW_LINE INDENT prev = 10 NEW_LINE while ( num ) : NEW_LINE INDENT rem = num % 10 NEW_LINE num /= 10 NEW_LINE if rem > prev : NEW_LINE INDENT return False NEW_LINE DEDENT prev = rem NEW_LINE DEDENT return True NEW_LINE DEDENT num = 1556 NEW_LINE if isTidy ( num ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V751,"class GFG { static boolean isPowerOfTwo ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) ; } static boolean isProthNumber ( int n ) { int k = 1 ; while ( k < ( n / k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( n / k ) ) return true ; } k = k + 2 ; } return false ; } public static void main ( String [ ] args ) { int n = 25 ; if ( isProthNumber ( n - 1 ) ) System . out . println ( "" YES "" ) ; else System . out . println ( "" NO "" ) ; } } ","def isPowerOfTwo ( n ) : NEW_LINE INDENT return ( n and ( not ( n & ( n - 1 ) ) ) ) NEW_LINE DEDENT def isProthNumber ( n ) : NEW_LINE INDENT k = 1 NEW_LINE while ( k < ( n // k ) ) : NEW_LINE INDENT if ( n % k == 0 ) : NEW_LINE INDENT if ( isPowerOfTwo ( n // k ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT k = k + 2 NEW_LINE DEDENT return False NEW_LINE int n = 25 ; NEW_LINE DEDENT if ( isProthNumber ( n - 1 ) ) : NEW_LINE INDENT print ( "" YES "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" NO "" ) ; NEW_LINE DEDENT " V752,"import java . util . * ; import static java . lang . Math . pow ; class Triangle { public static double numberOfTriangles ( int n ) { double ans = 2 * ( pow ( 3 , n ) ) - 1 ; return ans ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( numberOfTriangles ( n ) ) ; } } ","def numberOfTriangles ( n ) : NEW_LINE INDENT ans = 2 * ( pow ( 3 , n ) ) - 1 ; NEW_LINE return ans ; NEW_LINE DEDENT n = 2 NEW_LINE print ( numberOfTriangles ( n ) ) NEW_LINE " V753,"import java . io . * ; class GFG { static int maximumNumberDistinctPrimeRange ( int m , int n ) { long factorCount [ ] = new long [ n + 1 ] ; boolean prime [ ] = new boolean [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { factorCount [ i ] = 0 ; prime [ i ] = true ; } for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] == true ) { factorCount [ i ] = 1 ; for ( int j = i * 2 ; j <= n ; j += i ) { factorCount [ j ] ++ ; prime [ j ] = false ; } } } int max = ( int ) factorCount [ m ] ; int num = m ; for ( int i = m ; i <= n ; i ++ ) { if ( factorCount [ i ] > max ) { max = ( int ) factorCount [ i ] ; num = i ; } } return num ; } public static void main ( String [ ] args ) { int m = 4 , n = 6 ; System . out . println ( maximumNumberDistinctPrimeRange ( m , n ) ) ; } } ","def maximumNumberDistinctPrimeRange ( m , n ) : NEW_LINE INDENT factorCount = [ 0 ] * ( n + 1 ) NEW_LINE prime = [ False ] * ( n + 1 ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT factorCount [ i ] = 0 NEW_LINE prime [ i ] = True NEW_LINE DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( prime [ i ] == True ) : NEW_LINE INDENT factorCount [ i ] = 1 NEW_LINE for j in range ( i * 2 , n + 1 , i ) : NEW_LINE INDENT factorCount [ j ] += 1 NEW_LINE prime [ j ] = False NEW_LINE DEDENT DEDENT DEDENT max = factorCount [ m ] NEW_LINE num = m NEW_LINE for i in range ( m , n + 1 ) : NEW_LINE INDENT if ( factorCount [ i ] > max ) : NEW_LINE INDENT max = factorCount [ i ] NEW_LINE num = i NEW_LINE DEDENT DEDENT return num NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT m = 4 NEW_LINE n = 6 NEW_LINE print ( maximumNumberDistinctPrimeRange ( m , n ) ) NEW_LINE DEDENT " V754,"import java . io . * ; class GFG { static int findEvenPair ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 != 0 ) count ++ ; } int totalPairs = ( N * ( N - 1 ) / 2 ) ; int oddEvenPairs = count * ( N - count ) ; return totalPairs - oddEvenPairs ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 4 , 7 , 2 , 1 } ; int n = a . length ; System . out . println ( findEvenPair ( a , n ) ) ; } } ","def findEvenPair ( A , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT if ( A [ i ] % 2 != 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT totalPairs = ( N * ( N - 1 ) / 2 ) NEW_LINE oddEvenPairs = count * ( N - count ) NEW_LINE return ( int ) ( totalPairs - oddEvenPairs ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT a = [ 5 , 4 , 7 , 2 , 1 ] NEW_LINE n = len ( a ) NEW_LINE print ( findEvenPair ( a , n ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V755,"import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static String wordReverse ( String str ) { int i = str . length ( ) - 1 ; int start , end = i + 1 ; String result = "" "" ; while ( i >= 0 ) { if ( str . charAt ( i ) == ' ▁ ' ) { start = i + 1 ; while ( start != end ) result += str . charAt ( start ++ ) ; result += ' ▁ ' ; end = i ; } i -- ; } start = 0 ; while ( start != end ) result += str . charAt ( start ++ ) ; return result ; } public static void main ( String [ ] args ) { String str = "" I ▁ AM ▁ A ▁ GEEK "" ; System . out . print ( wordReverse ( str ) ) ; } } ","def wordReverse ( str ) : NEW_LINE INDENT i = len ( str ) - 1 NEW_LINE start = end = i + 1 NEW_LINE result = ' ' NEW_LINE while i >= 0 : NEW_LINE INDENT if str [ i ] == ' ▁ ' : NEW_LINE INDENT start = i + 1 NEW_LINE while start != end : NEW_LINE INDENT result += str [ start ] NEW_LINE start += 1 NEW_LINE DEDENT result += ' ▁ ' NEW_LINE end = i NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT start = 0 NEW_LINE while start != end : NEW_LINE INDENT result += str [ start ] NEW_LINE start += 1 NEW_LINE DEDENT return result NEW_LINE DEDENT str = ' I ▁ AM ▁ A ▁ GEEK ' NEW_LINE print ( wordReverse ( str ) ) NEW_LINE " V756,"import java . io . * ; public class GFG { static boolean validate ( long n ) { for ( int i = 0 ; i < 10 ; i ++ ) { long temp = n ; int count = 0 ; while ( temp > 0 ) { if ( temp % 10 == i ) count ++ ; if ( count > i ) return false ; temp /= 10 ; } } return true ; } static public void main ( String [ ] args ) { long n = 1552793 ; if ( validate ( n ) ) System . out . println ( "" True "" ) ; else System . out . println ( "" False "" ) ; } } ","def validate ( n ) : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT temp = n ; NEW_LINE count = 0 ; NEW_LINE while ( temp ) : NEW_LINE INDENT if ( temp % 10 == i ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT if ( count > i ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT temp //= 10 ; NEW_LINE DEDENT DEDENT return 1 ; NEW_LINE DEDENT n = 1552793 ; NEW_LINE geek = "" True "" if validate ( n ) else "" False "" ; NEW_LINE print ( geek ) ; NEW_LINE " V757,"public class GFG { static void towerOfHanoi ( int n , char from_rod , char to_rod , char aux_rod1 , char aux_rod2 ) { if ( n == 0 ) return ; if ( n == 1 ) { System . out . println ( "" Move ▁ disk ▁ "" + n + "" ▁ from ▁ rod ▁ "" + from_rod + "" ▁ to ▁ rod ▁ "" + to_rod ) ; return ; } towerOfHanoi ( n - 2 , from_rod , aux_rod1 , aux_rod2 , to_rod ) ; System . out . println ( "" Move ▁ disk ▁ "" + ( n - 1 ) + "" ▁ from ▁ rod ▁ "" + from_rod + "" ▁ to ▁ rod ▁ "" + aux_rod2 ) ; System . out . println ( "" Move ▁ disk ▁ "" + n + "" ▁ from ▁ rod ▁ "" + from_rod + "" ▁ to ▁ rod ▁ "" + to_rod ) ; System . out . println ( "" Move ▁ disk ▁ "" + ( n - 1 ) + "" ▁ from ▁ rod ▁ "" + aux_rod2 + "" ▁ to ▁ rod ▁ "" + to_rod ) ; towerOfHanoi ( n - 2 , aux_rod1 , to_rod , from_rod , aux_rod2 ) ; } public static void main ( String args [ ] ) { int n = 4 ; towerOfHanoi ( n , ' A ' , ' D ' , ' B ' , ' C ' ) ; } } ","def towerOfHanoi ( n , from_rod , to_rod , aux_rod1 , aux_rod2 ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT print ( "" Move ▁ disk "" , n , "" from ▁ rod "" , from_rod , "" c ▁ to ▁ rod "" , to_rod ) NEW_LINE return NEW_LINE DEDENT towerOfHanoi ( n - 2 , from_rod , aux_rod1 , aux_rod2 , to_rod ) NEW_LINE print ( "" Move ▁ disk "" , n - 1 , "" from ▁ rod "" , from_rod , "" c ▁ to ▁ rod "" , aux_rod2 ) NEW_LINE print ( "" Move ▁ disk "" , n , "" from ▁ rod "" , from_rod , "" c ▁ to ▁ rod "" , to_rod ) NEW_LINE print ( "" Move ▁ disk "" , n - 1 , "" from ▁ rod "" , aux_rod2 , "" c ▁ to ▁ rod "" , to_rod ) NEW_LINE towerOfHanoi ( n - 2 , aux_rod1 , to_rod , from_rod , aux_rod2 ) NEW_LINE DEDENT n = 4 NEW_LINE towerOfHanoi ( n , ' A ' , ' D ' , ' B ' , ' C ' ) NEW_LINE " V758,"import java . util . HashMap ; class MajorityElement { private static void findMajority ( int [ ] arr ) { HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( map . containsKey ( arr [ i ] ) ) { int count = map . get ( arr [ i ] ) + 1 ; if ( count > arr . length / 2 ) { System . out . println ( "" Majority ▁ found ▁ : - ▁ "" + arr [ i ] ) ; return ; } else map . put ( arr [ i ] , count ) ; } else map . put ( arr [ i ] , 1 ) ; } System . out . println ( "" ▁ No ▁ Majority ▁ element "" ) ; } public static void main ( String [ ] args ) { int a [ ] = new int [ ] { 2 , 2 , 2 , 2 , 5 , 5 , 2 , 3 , 3 } ; findMajority ( a ) ; } } ","def findMajority ( arr , size ) : NEW_LINE INDENT m = { } NEW_LINE for i in range ( size ) : NEW_LINE INDENT if arr [ i ] in m : NEW_LINE INDENT m [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT count = 0 NEW_LINE for key in m : NEW_LINE INDENT if m [ key ] > size / 2 : NEW_LINE INDENT count = 1 NEW_LINE print ( "" Majority ▁ found ▁ : - "" , key ) NEW_LINE break NEW_LINE DEDENT DEDENT if ( count == 0 ) : NEW_LINE INDENT print ( "" No ▁ Majority ▁ element "" ) NEW_LINE DEDENT DEDENT arr = [ 2 , 2 , 2 , 2 , 5 , 5 , 2 , 3 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE findMajority ( arr , n ) NEW_LINE " V759,"import java . io . * ; class GFG { static int MAX_K = 15 ; static int fac [ ] = new int [ MAX_K ] ; static void factorial ( int k ) { fac [ 0 ] = 1 ; for ( int i = 1 ; i <= k + 1 ; i ++ ) { fac [ i ] = ( i * fac [ i - 1 ] ) ; } } static int bin ( int a , int b ) { int ans = ( ( fac [ a ] ) / ( fac [ a - b ] * fac [ b ] ) ) ; return ans ; } static int sumofn ( int n , int k ) { int p = 0 ; int num1 , temp ; int arr [ ] = new int [ 1000 ] ; for ( int j = 1 ; j <= k ; j ++ ) { if ( j == 1 ) { num1 = ( n * ( n + 1 ) ) / 2 ; arr [ p ++ ] = num1 ; temp = num1 ; } else { temp = ( ( int ) Math . pow ( n + 1 , j + 1 ) - 1 - n ) ; for ( int s = 1 ; s < j ; s ++ ) { temp = temp - ( arr [ j - s - 1 ] * bin ( j + 1 , s + 1 ) ) ; } temp = temp / ( j + 1 ) ; arr [ p ++ ] = temp ; } } temp = arr [ p - 1 ] ; return temp ; } public static void main ( String [ ] args ) { int n = 5 , k = 2 ; factorial ( k ) ; System . out . println ( sumofn ( n , k ) ) ; } } ","MAX_K = 15 NEW_LINE fac = [ 1 for i in range ( MAX_K ) ] NEW_LINE def factorial ( k ) : NEW_LINE INDENT fac [ 0 ] = 1 NEW_LINE for i in range ( 1 , k + 2 ) : NEW_LINE INDENT fac [ i ] = ( i * fac [ i - 1 ] ) NEW_LINE DEDENT DEDENT def bin ( a , b ) : NEW_LINE INDENT ans = fac [ a ] // ( fac [ a - b ] * fac [ b ] ) NEW_LINE return ans NEW_LINE DEDENT def sumofn ( n , k ) : NEW_LINE INDENT p = 0 NEW_LINE num1 , temp = 1 , 1 NEW_LINE arr = [ 1 for i in range ( 1000 ) ] NEW_LINE for j in range ( 1 , k + 1 ) : NEW_LINE INDENT if j == 1 : NEW_LINE INDENT num1 = ( n * ( n + 1 ) ) // 2 NEW_LINE arr [ p ] = num1 NEW_LINE p += 1 NEW_LINE DEDENT else : NEW_LINE INDENT temp = pow ( n + 1 , j + 1 ) - 1 - n NEW_LINE for s in range ( 1 , j ) : NEW_LINE INDENT temp = temp - ( arr [ j - s - 1 ] * bin ( j + 1 , s + 1 ) ) NEW_LINE DEDENT temp = temp // ( j + 1 ) NEW_LINE arr [ p ] = temp NEW_LINE p += 1 NEW_LINE DEDENT DEDENT temp = arr [ p - 1 ] NEW_LINE return temp NEW_LINE DEDENT n , k = 5 , 2 NEW_LINE factorial ( k ) NEW_LINE print ( sumofn ( n , k ) ) NEW_LINE " V760,"import java . util . * ; class solution { static int countPattern ( int n , String pat ) { int pattern_int = 0 ; int power_two = 1 ; int all_ones = 0 ; for ( int i = pat . length ( ) - 1 ; i >= 0 ; i -- ) { int current_bit = pat . charAt ( i ) - '0' ; pattern_int += ( power_two * current_bit ) ; all_ones = all_ones + power_two ; power_two = power_two * 2 ; } int count = 0 ; while ( n != 0 && n >= pattern_int ) { if ( ( n & all_ones ) == pattern_int ) { count ++ ; } n = n >> 1 ; } return count ; } public static void main ( String args [ ] ) { int n = 500 ; String pat = ""10"" ; System . out . println ( countPattern ( n , pat ) ) ; } } ","def countPattern ( n , pat ) : NEW_LINE INDENT pattern_int = 0 NEW_LINE power_two = 1 NEW_LINE all_ones = 0 NEW_LINE i = len ( pat ) - 1 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT current_bit = ord ( pat [ i ] ) - ord ( '0' ) NEW_LINE pattern_int += ( power_two * current_bit ) NEW_LINE all_ones = all_ones + power_two NEW_LINE power_two = power_two * 2 NEW_LINE i -= 1 NEW_LINE DEDENT count = 0 NEW_LINE while ( n != 0 and n >= pattern_int ) : NEW_LINE INDENT if ( ( n & all_ones ) == pattern_int ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT n = n >> 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 500 NEW_LINE pat = ""10"" NEW_LINE print ( countPattern ( n , pat ) ) NEW_LINE DEDENT " V761,"class Divisible { public static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } static boolean isDivisible ( int x , int y ) { if ( y == 1 ) return true ; int z = gcd ( x , y ) ; if ( z == 1 ) return false ; return isDivisible ( x , y / z ) ; } public static void main ( String [ ] args ) { int x = 18 , y = 12 ; if ( isDivisible ( x , y ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT else : NEW_LINE INDENT return gcd ( b , a % b ) NEW_LINE DEDENT DEDENT def isDivisible ( x , y ) : NEW_LINE INDENT if ( y == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT z = gcd ( x , y ) ; NEW_LINE if ( z == 1 ) : NEW_LINE INDENT return false ; NEW_LINE DEDENT return isDivisible ( x , y / z ) ; NEW_LINE DEDENT x = 18 NEW_LINE y = 12 NEW_LINE if ( isDivisible ( x , y ) ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT " V762,"import java . util . * ; class GFG { static int LISusingLCS ( Vector < Integer > seq ) { int n = seq . size ( ) ; int L [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ; Vector < Integer > sortedseq = new Vector < Integer > ( seq ) ; Collections . sort ( sortedseq ) ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 || j == 0 ) L [ i ] [ j ] = 0 ; else if ( seq . get ( i - 1 ) == sortedseq . get ( j - 1 ) ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ n ] [ n ] ; } public static void main ( String args [ ] ) { Vector < Integer > sequence = new Vector < Integer > ( ) ; sequence . add ( 12 ) ; sequence . add ( 34 ) ; sequence . add ( 1 ) ; sequence . add ( 5 ) ; sequence . add ( 40 ) ; sequence . add ( 80 ) ; System . out . println ( LISusingLCS ( sequence ) ) ; } } ","def LISusingLCS ( seq ) : NEW_LINE INDENT n = len ( seq ) NEW_LINE L = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ] NEW_LINE sortedseq = sorted ( seq ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT if ( i == 0 or j == 0 ) : NEW_LINE INDENT L [ i ] [ j ] = 0 NEW_LINE DEDENT elif ( seq [ i - 1 ] == sortedseq [ j - 1 ] ) : NEW_LINE INDENT L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) NEW_LINE DEDENT DEDENT DEDENT return L [ n ] [ n ] NEW_LINE DEDENT sequence = [ 12 , 34 , 1 , 5 , 40 , 80 ] NEW_LINE print ( LISusingLCS ( sequence ) ) NEW_LINE " V763,"import java . util . * ; class GFG { static String findSmallest ( char [ ] s ) { int len = s . length ; int [ ] loccur = new int [ 26 ] ; Arrays . fill ( loccur , - 1 ) ; for ( int i = len - 1 ; i >= 0 ; -- i ) { int chI = s [ i ] - ' a ' ; if ( loccur [ chI ] == - 1 ) { loccur [ chI ] = i ; } } char [ ] sorted_s = s ; Arrays . sort ( sorted_s ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( s [ i ] != sorted_s [ i ] ) { int chI = sorted_s [ i ] - ' a ' ; int last_occ = loccur [ chI ] ; char temp = s [ last_occ ] ; s [ last_occ ] = s [ i ] ; s [ i ] = temp ; break ; } } return String . valueOf ( s ) ; } public static void main ( String [ ] args ) { String s = "" geeks "" ; System . out . print ( findSmallest ( s . toCharArray ( ) ) ) ; } } ","def findSmallest ( s ) : NEW_LINE INDENT length = len ( s ) ; NEW_LINE loccur = [ - 1 ] * 26 ; NEW_LINE for i in range ( length - 1 , - 1 , - 1 ) : NEW_LINE INDENT chI = ord ( s [ i ] ) - ord ( ' a ' ) ; NEW_LINE if ( loccur [ chI ] == - 1 ) : NEW_LINE INDENT loccur [ chI ] = i ; NEW_LINE DEDENT DEDENT sorted_s = s ; NEW_LINE sorted_s . sort ( ) ; NEW_LINE for i in range ( length ) : NEW_LINE INDENT if ( s [ i ] != sorted_s [ i ] ) : NEW_LINE INDENT chI = ord ( sorted_s [ i ] ) - ord ( ' a ' ) ; NEW_LINE last_occ = loccur [ chI ] ; NEW_LINE s [ i ] , s [ last_occ ] = s [ last_occ ] , s [ i ] NEW_LINE break ; NEW_LINE DEDENT DEDENT return "" "" . join ( s ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" geeks "" ; NEW_LINE print ( findSmallest ( list ( s ) ) ) ; NEW_LINE DEDENT " V764,"class Sequences { static int getTotalNumberOfSequences ( int m , int n ) { int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) { for ( int j = 0 ; j < n + 1 ; j ++ ) { if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ; else if ( i < j ) T [ i ] [ j ] = 0 ; else if ( j == 1 ) T [ i ] [ j ] = i ; else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ; } } return T [ m ] [ n ] ; } public static void main ( String [ ] args ) { int m = 10 ; int n = 4 ; System . out . println ( "" Total ▁ number ▁ of ▁ possible ▁ sequences ▁ "" + getTotalNumberOfSequences ( m , n ) ) ; } } ","def getTotalNumberOfSequences ( m , n ) : NEW_LINE INDENT T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ] NEW_LINE for i in range ( m + 1 ) : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT if i == 0 or j == 0 : NEW_LINE INDENT T [ i ] [ j ] = 0 NEW_LINE DEDENT elif i < j : NEW_LINE INDENT T [ i ] [ j ] = 0 NEW_LINE DEDENT elif j == 1 : NEW_LINE INDENT T [ i ] [ j ] = i NEW_LINE DEDENT else : NEW_LINE INDENT T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ] NEW_LINE DEDENT DEDENT DEDENT return T [ m ] [ n ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT m = 10 NEW_LINE n = 4 NEW_LINE print ( ' Total ▁ number ▁ of ▁ possible ▁ sequences ▁ ' , getTotalNumberOfSequences ( m , n ) ) NEW_LINE DEDENT " V765,"import java . util . * ; class solution { static float area ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 ) { double a = Math . pow ( ( y1 * z2 - y2 * z1 ) , 2 ) + Math . pow ( ( x1 * z2 - x2 * z1 ) , 2 ) + Math . pow ( ( x1 * y2 - x2 * y1 ) , 2 ) ; float area = ( float ) Math . sqrt ( a ) ; area = area / 2 ; return area ; } public static void main ( String arr [ ] ) { int x1 = - 2 ; int y1 = 0 ; int z1 = - 5 ; int x2 = 1 ; int y2 = - 2 ; int z2 = - 1 ; float a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) ; System . out . println ( "" Area = ▁ "" + a ) ; } } ","import math NEW_LINE def area ( x1 , y1 , z1 , x2 , y2 , z2 ) : NEW_LINE INDENT area = math . sqrt ( ( y1 * z2 - y2 * z1 ) ** 2 + ( x1 * z2 - x2 * z1 ) ** 2 + ( x1 * y2 - x2 * y1 ) ** 2 ) NEW_LINE area = area / 2 NEW_LINE return area NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT x1 = - 2 NEW_LINE y1 = 0 NEW_LINE z1 = - 5 NEW_LINE x2 = 1 NEW_LINE y2 = - 2 NEW_LINE z2 = - 1 NEW_LINE a = area ( x1 , y1 , z1 , x2 , y2 , z2 ) NEW_LINE print ( "" Area ▁ = ▁ "" , a ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT " V766,"class GFG { static float weightedMean ( int X [ ] , int W [ ] , int n ) { int sum = 0 , numWeight = 0 ; for ( int i = 0 ; i < n ; i ++ ) { numWeight = numWeight + X [ i ] * W [ i ] ; sum = sum + W [ i ] ; } return ( float ) ( numWeight ) / sum ; } public static void main ( String args [ ] ) { int X [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int W [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = X . length ; int m = W . length ; if ( n == m ) System . out . println ( weightedMean ( X , W , n ) ) ; else System . out . println ( "" - 1"" ) ; } } ","def weightedMean ( X , W , n ) : NEW_LINE INDENT sum = 0 NEW_LINE numWeight = 0 NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT numWeight = numWeight + X [ i ] * W [ i ] NEW_LINE sum = sum + W [ i ] NEW_LINE i = i + 1 NEW_LINE DEDENT return ( float ) ( numWeight / sum ) NEW_LINE DEDENT X = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] NEW_LINE W = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] NEW_LINE n = len ( X ) NEW_LINE m = len ( W ) NEW_LINE if ( n == m ) : NEW_LINE INDENT print weightedMean ( X , W , n ) NEW_LINE DEDENT else : NEW_LINE INDENT print "" - 1"" NEW_LINE DEDENT " V767,"class GFG { static int Log2n ( int n ) { return ( n > 1 ) ? 1 + Log2n ( n / 2 ) : 0 ; } static boolean isPowerOfd ( int n , int d ) { int count = 0 ; if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) { while ( n > 1 ) { n >>= 1 ; count += 1 ; } return ( count % ( Log2n ( d ) ) == 0 ) ; } return false ; } public static void main ( String [ ] args ) { int n = 64 , d = 8 ; if ( isPowerOfd ( n , d ) ) System . out . println ( n + "" ▁ is ▁ a ▁ power ▁ of ▁ "" + d ) ; else System . out . println ( n + "" ▁ is ▁ not ▁ a ▁ power ▁ of ▁ "" + d ) ; } } ","def Log2n ( n ) : NEW_LINE INDENT return ( 1 + Log2n ( n / 2 ) ) if ( n > 1 ) else 0 ; NEW_LINE DEDENT def isPowerOfd ( n , d ) : NEW_LINE INDENT count = 0 ; NEW_LINE if ( n and ( n & ( n - 1 ) ) == 0 ) : NEW_LINE INDENT while ( n > 1 ) : NEW_LINE INDENT n >>= 1 ; NEW_LINE count += 1 ; NEW_LINE DEDENT return ( count % ( Log2n ( d ) ) == 0 ) ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT n = 64 ; NEW_LINE d = 8 ; NEW_LINE if ( isPowerOfd ( n , d ) ) : NEW_LINE INDENT print ( n , "" is ▁ a ▁ power ▁ of "" , d ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( n , "" is ▁ not ▁ a ▁ power ▁ of "" , d ) ; NEW_LINE DEDENT " V768,"import java . util . * ; class GFG { static void printRepeating ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int index = arr [ i ] % n ; arr [ index ] += n ; } for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] / n ) > 1 ) System . out . println ( i + "" ▁ "" ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 6 , 3 , 1 , 3 , 6 , 6 } ; int arr_size = arr . length ; System . out . println ( "" The ▁ repeating ▁ elements ▁ are : ▁ "" ) ; printRepeating ( arr , arr_size ) ; } } ","def printRepeating ( arr , n ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT index = arr [ i ] % n NEW_LINE arr [ index ] += n NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] / n ) > 1 : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 1 , 6 , 3 , 1 , 3 , 6 , 6 ] NEW_LINE arr_size = len ( arr ) NEW_LINE print ( "" The ▁ repeating ▁ elements ▁ are : "" ) NEW_LINE printRepeating ( arr , arr_size ) NEW_LINE " V769,"import java . util . * ; class GFG { static void countFreq ( int [ ] a , int n ) { HashMap < Integer , Integer > hm = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ; SortedMap < Integer , Integer > st = new TreeMap < > ( ) ; for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) { st . put ( x . getKey ( ) , x . getValue ( ) ) ; } int cumul = 0 ; for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) { cumul += x . getValue ( ) ; System . out . println ( x . getKey ( ) + "" ▁ "" + cumul ) ; } } public static void main ( String [ ] args ) { int [ ] a = { 1 , 3 , 2 , 4 , 2 , 1 } ; int n = a . length ; countFreq ( a , n ) ; } } ","def countFreq ( a , n ) : NEW_LINE INDENT hm = { } NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT hm [ a [ i ] ] = hm . get ( a [ i ] , 0 ) + 1 NEW_LINE DEDENT st = set ( ) NEW_LINE for x in hm : NEW_LINE INDENT st . add ( ( x , hm [ x ] ) ) NEW_LINE DEDENT cumul = 0 NEW_LINE for x in sorted ( st ) : NEW_LINE INDENT cumul += x [ 1 ] NEW_LINE print ( x [ 0 ] , cumul ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 1 , 3 , 2 , 4 , 2 , 1 ] NEW_LINE n = len ( a ) NEW_LINE countFreq ( a , n ) NEW_LINE DEDENT " V770,"class GFG { static void checkIfPowerIsolated ( int num ) { int input = num ; int count = 0 ; int [ ] factor = new int [ num + 1 ] ; if ( num % 2 == 0 ) { while ( num % 2 == 0 ) { ++ count ; num /= 2 ; } factor [ 2 ] = count ; } for ( int i = 3 ; i * i <= num ; i += 2 ) { count = 0 ; while ( num % i == 0 ) { ++ count ; num /= i ; } if ( count > 0 ) factor [ i ] = count ; } if ( num > 1 ) factor [ num ] = 1 ; int product = 1 ; for ( int i = 0 ; i < num + 1 ; i ++ ) { if ( factor [ i ] > 0 ) product = product * factor [ i ] * i ; } if ( product == input ) System . out . print ( "" Power - isolated ▁ Integer \n "" ) ; else System . out . print ( "" Not ▁ a ▁ Power - isolated ▁ Integer \n "" ) ; } public static void main ( String [ ] args ) { checkIfPowerIsolated ( 12 ) ; checkIfPowerIsolated ( 18 ) ; checkIfPowerIsolated ( 35 ) ; } } ","def checkIfPowerIsolated ( num ) : NEW_LINE INDENT input1 = num ; NEW_LINE count = 0 ; NEW_LINE factor = [ 0 ] * ( num + 1 ) ; NEW_LINE if ( num % 2 == 0 ) : NEW_LINE INDENT while ( num % 2 == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE num //= 2 ; NEW_LINE DEDENT factor [ 2 ] = count ; NEW_LINE DEDENT i = 3 ; NEW_LINE while ( i * i <= num ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( num % i == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE num //= i ; NEW_LINE DEDENT if ( count > 0 ) : NEW_LINE INDENT factor [ i ] = count ; NEW_LINE DEDENT i += 2 ; NEW_LINE DEDENT if ( num > 1 ) : NEW_LINE INDENT factor [ num ] = 1 ; NEW_LINE DEDENT product = 1 ; NEW_LINE for i in range ( 0 , len ( factor ) ) : NEW_LINE INDENT if ( factor [ i ] > 0 ) : NEW_LINE INDENT product = product * factor [ i ] * i ; NEW_LINE DEDENT DEDENT if ( product == input1 ) : NEW_LINE INDENT print ( "" Power - isolated ▁ Integer "" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" Not ▁ a ▁ Power - isolated ▁ Integer "" ) ; NEW_LINE DEDENT DEDENT checkIfPowerIsolated ( 12 ) ; NEW_LINE checkIfPowerIsolated ( 18 ) ; NEW_LINE checkIfPowerIsolated ( 35 ) ; NEW_LINE " V771,"import java . util . * ; class GFG { static int [ ] seats = new int [ ] { 1 , 2 , 4 } ; public static int maxAmount ( int M , int N ) { PriorityQueue < Integer > q = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < M ; i ++ ) { q . add ( seats [ i ] ) ; } int ticketSold = 0 ; int ans = 0 ; while ( ticketSold < N && q . peek ( ) > 0 ) { ans = ans + q . peek ( ) ; int temp = q . peek ( ) ; q . poll ( ) ; q . add ( temp - 1 ) ; ticketSold ++ ; } return ans ; } public static void main ( String [ ] args ) { int M = seats . length ; int N = 3 ; System . out . print ( maxAmount ( M , N ) ) ; } } ","def maxAmount ( M , N , seats ) : NEW_LINE INDENT q = [ ] NEW_LINE for i in range ( M ) : NEW_LINE INDENT q . append ( seats [ i ] ) NEW_LINE DEDENT ticketSold = 0 NEW_LINE ans = 0 NEW_LINE q . sort ( reverse = True ) NEW_LINE while ( ticketSold < N and q [ 0 ] > 0 ) : NEW_LINE INDENT ans = ans + q [ 0 ] NEW_LINE temp = q [ 0 ] NEW_LINE q = q [ 1 : ] NEW_LINE q . append ( temp - 1 ) NEW_LINE q . sort ( reverse = True ) NEW_LINE ticketSold += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT seats = [ 1 , 2 , 4 ] NEW_LINE M = len ( seats ) NEW_LINE N = 3 NEW_LINE print ( maxAmount ( N , M , seats ) ) NEW_LINE DEDENT " V772,"import java . util . * ; class GFG { static void countPairs ( int arr [ ] , int n , int k ) { int i , j , cnt = 0 ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ i ] - arr [ j ] + k ) % k == 0 ) cnt += 1 ; } } System . out . print ( cnt + "" \n "" ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 3 , 3 } ; int k = 3 ; int n = arr . length ; countPairs ( arr , n , k ) ; } } ","def countPairs ( arr , n , k ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( ( arr [ i ] - arr [ j ] + k ) % k == 0 ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT DEDENT DEDENT print ( cnt ) ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 3 , 3 , 3 ] ; NEW_LINE k = 3 ; NEW_LINE n = len ( arr ) ; NEW_LINE countPairs ( arr , n , k ) ; NEW_LINE DEDENT " V773,"class GFG { static boolean canFormTeam ( int n , int m ) { if ( n >= 1 && m >= 2 ) return true ; if ( m >= 1 && n >= 2 ) return true ; return false ; } static int maxTeams ( int n , int m ) { int count = 0 ; while ( canFormTeam ( n , m ) ) { if ( n > m ) { n -= 2 ; m -= 1 ; } else { m -= 2 ; n -= 1 ; } count ++ ; } return count ; } public static void main ( String args [ ] ) { int n = 4 , m = 5 ; System . out . println ( maxTeams ( n , m ) ) ; } } ","def canFormTeam ( n , m ) : NEW_LINE INDENT if ( n >= 1 and m >= 2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( m >= 1 and n >= 2 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def maxTeams ( n , m ) : NEW_LINE INDENT count = 0 NEW_LINE while ( canFormTeam ( n , m ) ) : NEW_LINE INDENT if ( n > m ) : NEW_LINE INDENT n -= 2 NEW_LINE m -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT m -= 2 NEW_LINE n -= 1 NEW_LINE DEDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE m = 5 NEW_LINE print ( maxTeams ( n , m ) ) NEW_LINE DEDENT " V774,"class GFG { static void printUncommon ( String str1 , String str2 ) { int a1 = 0 , a2 = 0 ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { int ch = ( str1 . charAt ( i ) ) - ' a ' ; a1 = a1 | ( 1 << ch ) ; } for ( int i = 0 ; i < str2 . length ( ) ; i ++ ) { int ch = ( str2 . charAt ( i ) ) - ' a ' ; a2 = a2 | ( 1 << ch ) ; } int ans = a1 ^ a2 ; int i = 0 ; while ( i < 26 ) { if ( ans % 2 == 1 ) { System . out . print ( ( char ) ( ' a ' + i ) ) ; } ans = ans / 2 ; i ++ ; } } public static void main ( String [ ] args ) { String str1 = "" geeksforgeeks "" ; String str2 = "" geeksquiz "" ; printUncommon ( str1 , str2 ) ; } } ","def printUncommon ( str1 , str2 ) : NEW_LINE INDENT a1 = 0 ; a2 = 0 ; NEW_LINE for i in range ( len ( str1 ) ) : NEW_LINE INDENT ch = ord ( str1 [ i ] ) - ord ( ' a ' ) ; NEW_LINE a1 = a1 | ( 1 << ch ) ; NEW_LINE DEDENT for i in range ( len ( str2 ) ) : NEW_LINE INDENT ch = ord ( str2 [ i ] ) - ord ( ' a ' ) ; NEW_LINE a2 = a2 | ( 1 << ch ) ; NEW_LINE DEDENT ans = a1 ^ a2 ; NEW_LINE i = 0 ; NEW_LINE while ( i < 26 ) : NEW_LINE INDENT if ( ans % 2 == 1 ) : NEW_LINE INDENT print ( chr ( ord ( ' a ' ) + i ) , end = "" "" ) ; NEW_LINE DEDENT ans = ans // 2 ; NEW_LINE i += 1 ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT str1 = "" geeksforgeeks "" ; NEW_LINE str2 = "" geeksquiz "" ; NEW_LINE printUncommon ( str1 , str2 ) ; NEW_LINE DEDENT " V775,"import java . util . * ; class GFG { static class Node { int data ; Node next ; Node ( int data ) { this . data = data ; this . next = null ; } } ; static class treeNode { int data ; treeNode left ; treeNode right ; treeNode ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } ; static void print ( Node head ) { if ( head == null ) { return ; } Node temp = head ; while ( temp != null ) { System . out . print ( temp . data + "" ▁ "" ) ; temp = temp . next ; } } static Node sortedList ( Node head , treeNode root ) { if ( root == null ) { return head ; } head = sortedList ( head , root . left ) ; Node newNode = new Node ( root . data ) ; Node temp = head ; Node prev = null ; if ( temp == null ) { head = newNode ; } else { while ( temp != null ) { if ( temp . data > root . data ) { break ; } else { prev = temp ; temp = temp . next ; } } if ( temp == null ) { prev . next = newNode ; } else { if ( prev == null ) { newNode . next = temp ; head = newNode ; } else { newNode . next = temp ; prev . next = newNode ; } } } head = sortedList ( head , root . right ) ; return head ; } public static void main ( String [ ] args ) { treeNode root = new treeNode ( 10 ) ; root . left = new treeNode ( 15 ) ; root . right = new treeNode ( 2 ) ; root . left . left = new treeNode ( 1 ) ; root . left . right = new treeNode ( 5 ) ; Node head = sortedList ( null , root ) ; print ( head ) ; } } ","class Node : NEW_LINE INDENT def __init__ ( self , data = 0 ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT class treeNode : 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 print_ ( head ) : NEW_LINE INDENT if ( head == None ) : NEW_LINE INDENT return NEW_LINE DEDENT temp = head NEW_LINE while ( temp != None ) : NEW_LINE INDENT print ( temp . data , end = "" ▁ "" ) NEW_LINE temp = temp . next NEW_LINE DEDENT DEDENT def sortedList ( head , root ) : NEW_LINE INDENT if ( root == None ) : NEW_LINE INDENT return head NEW_LINE DEDENT head = sortedList ( head , root . left ) NEW_LINE newNode = Node ( root . data ) NEW_LINE temp = head NEW_LINE prev = None NEW_LINE if ( temp == None ) : NEW_LINE INDENT head = newNode NEW_LINE DEDENT else : NEW_LINE INDENT while ( temp != None ) : NEW_LINE INDENT if ( temp . data > root . data ) : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT prev = temp NEW_LINE temp = temp . next NEW_LINE DEDENT DEDENT if ( temp == None ) : NEW_LINE INDENT prev . next = newNode NEW_LINE DEDENT else : NEW_LINE INDENT if ( prev == None ) : NEW_LINE INDENT newNode . next = temp NEW_LINE head = newNode NEW_LINE DEDENT else : NEW_LINE INDENT newNode . next = temp NEW_LINE prev . next = newNode NEW_LINE DEDENT DEDENT DEDENT head = sortedList ( head , root . right ) NEW_LINE return head NEW_LINE DEDENT root = treeNode ( 10 ) NEW_LINE root . left = treeNode ( 15 ) NEW_LINE root . right = treeNode ( 2 ) NEW_LINE root . left . left = treeNode ( 1 ) NEW_LINE root . left . right = treeNode ( 5 ) NEW_LINE head = sortedList ( None , root ) NEW_LINE print_ ( head ) NEW_LINE " V776,"class GFG { static String longDivision ( String number , int divisor ) { String ans = "" "" ; int idx = 0 ; char [ ] num = number . toCharArray ( ) ; int temp = num [ idx ] - '0' ; while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - '0' ) ; idx += 1 ; while ( num . length > idx ) { ans += ( temp / divisor ) ; temp = ( temp % divisor ) * 10 + num [ idx ++ ] - '0' ; } if ( ans . length ( ) == 0 ) return ""0"" ; return ans ; } public static void main ( String [ ] args ) { String number = ""1248163264128256512"" ; int divisor = 125 ; System . out . println ( longDivision ( number , divisor ) ) ; } } ","import math NEW_LINE def longDivision ( number , divisor ) : NEW_LINE INDENT ans = "" "" ; NEW_LINE idx = 0 ; NEW_LINE temp = ord ( number [ idx ] ) - ord ( '0' ) ; NEW_LINE while ( temp < divisor ) : NEW_LINE INDENT temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) ) ; NEW_LINE idx += 1 ; NEW_LINE DEDENT idx += 1 ; NEW_LINE while ( ( len ( number ) ) > idx ) : NEW_LINE INDENT ans += chr ( math . floor ( temp // divisor ) + ord ( '0' ) ) ; NEW_LINE temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) ) ; NEW_LINE idx += 1 ; NEW_LINE DEDENT ans += chr ( math . floor ( temp // divisor ) + ord ( '0' ) ) ; NEW_LINE if ( len ( ans ) == 0 ) : NEW_LINE INDENT return ""0"" ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT number = ""1248163264128256512"" ; NEW_LINE divisor = 125 ; NEW_LINE print ( longDivision ( number , divisor ) ) ; NEW_LINE " V777,"import java . util . * ; class GFG { static boolean powerOfTwo ( int n ) { return ( ( n & n - 1 ) == 0 ) ; } static boolean onlyFirstAndLastAreSet ( int n ) { if ( n == 1 ) return true ; return powerOfTwo ( n - 1 ) ; } public static void main ( String [ ] args ) { int n = Integer . parseUnsignedInt ( ""9"" ) ; if ( onlyFirstAndLastAreSet ( n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def powerOfTwo ( n ) : NEW_LINE INDENT return ( not ( n & n - 1 ) ) NEW_LINE DEDENT def onlyFirstAndLastAreSet ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return powerOfTwo ( n - 1 ) NEW_LINE DEDENT n = 9 NEW_LINE if ( onlyFirstAndLastAreSet ( n ) ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT " V778,"import java . io . * ; class GFG { static int countUnmarked ( int N ) { if ( N % 2 == 0 ) return N / 2 ; else return N / 2 + 1 ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( "" Number ▁ of ▁ unmarked ▁ "" + "" elements : ▁ "" + countUnmarked ( N ) ) ; } } ","def countUnmarked ( N ) : NEW_LINE INDENT if ( N % 2 == 0 ) : NEW_LINE INDENT return N / 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT return N / 2 + 1 ; NEW_LINE DEDENT DEDENT N = 4 ; NEW_LINE print ( "" Number ▁ of ▁ unmarked ▁ elements : "" , int ( countUnmarked ( N ) ) ) ; NEW_LINE " V779,"import java . util . Arrays ; public class PrintMissing { static void printMissing ( int ar [ ] , int low , int high ) { Arrays . sort ( ar ) ; int index = ceilindex ( ar , low , 0 , ar . length - 1 ) ; int x = low ; while ( index < ar . length && x <= high ) { if ( ar [ index ] != x ) { System . out . print ( x + "" ▁ "" ) ; } else index ++ ; x ++ ; } while ( x <= high ) { System . out . print ( x + "" ▁ "" ) ; x ++ ; } } static int ceilindex ( int ar [ ] , int val , int low , int high ) { if ( val < ar [ 0 ] ) return 0 ; if ( val > ar [ ar . length - 1 ] ) return ar . length ; int mid = ( low + high ) / 2 ; if ( ar [ mid ] == val ) return mid ; if ( ar [ mid ] < val ) { if ( mid + 1 < high && ar [ mid + 1 ] >= val ) return mid + 1 ; return ceilindex ( ar , val , mid + 1 , high ) ; } else { if ( mid - 1 >= low && ar [ mid - 1 ] < val ) return mid ; return ceilindex ( ar , val , low , mid - 1 ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 4 } ; int low = 1 , high = 10 ; printMissing ( arr , low , high ) ; } } ","from bisect import bisect_left NEW_LINE def printMissing ( arr , n , low , high ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE ptr = bisect_left ( arr , low ) NEW_LINE index = ptr NEW_LINE i = index NEW_LINE x = low NEW_LINE while ( i < n and x <= high ) : NEW_LINE INDENT if ( arr [ i ] != x ) : NEW_LINE INDENT print ( x , end = "" ▁ "" ) NEW_LINE DEDENT else : NEW_LINE INDENT i = i + 1 NEW_LINE DEDENT x = x + 1 NEW_LINE DEDENT while ( x <= high ) : NEW_LINE INDENT print ( x , end = "" ▁ "" ) NEW_LINE x = x + 1 NEW_LINE DEDENT DEDENT arr = [ 1 , 3 , 5 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE low = 1 NEW_LINE high = 10 NEW_LINE printMissing ( arr , n , low , high ) ; NEW_LINE " V780,"import java . io . * ; class GFG { static int findMaxAverage ( int [ ] arr , int n , int k ) { if ( k > n ) return - 1 ; int [ ] csum = new int [ n ] ; csum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ; int max_sum = csum [ k - 1 ] , max_end = k - 1 ; for ( int i = k ; i < n ; i ++ ) { int curr_sum = csum [ i ] - csum [ i - k ] ; if ( curr_sum > max_sum ) { max_sum = curr_sum ; max_end = i ; } } return max_end - k + 1 ; } static public void main ( String [ ] args ) { int [ ] arr = { 1 , 12 , - 5 , - 6 , 50 , 3 } ; int k = 4 ; int n = arr . length ; System . out . println ( "" The ▁ maximum ▁ "" + "" average ▁ subarray ▁ of ▁ length ▁ "" + k + "" ▁ begins ▁ at ▁ index ▁ "" + findMaxAverage ( arr , n , k ) ) ; } } ","def findMaxAverage ( arr , n , k ) : NEW_LINE INDENT if k > n : NEW_LINE INDENT return - 1 NEW_LINE DEDENT csum = [ 0 ] * n NEW_LINE csum [ 0 ] = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT csum [ i ] = csum [ i - 1 ] + arr [ i ] ; NEW_LINE DEDENT max_sum = csum [ k - 1 ] NEW_LINE max_end = k - 1 NEW_LINE for i in range ( k , n ) : NEW_LINE INDENT curr_sum = csum [ i ] - csum [ i - k ] NEW_LINE if curr_sum > max_sum : NEW_LINE INDENT max_sum = curr_sum NEW_LINE max_end = i NEW_LINE DEDENT DEDENT return max_end - k + 1 NEW_LINE DEDENT arr = [ 1 , 12 , - 5 , - 6 , 50 , 3 ] NEW_LINE k = 4 NEW_LINE n = len ( arr ) NEW_LINE print ( "" The ▁ maximum ▁ average ▁ subarray ▁ of ▁ length "" , k , "" begins ▁ at ▁ index "" , findMaxAverage ( arr , n , k ) ) NEW_LINE " V781,"import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . Iterator ; import java . util . Map ; class GFG { static int findSum ( int arr [ ] , int N ) { Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ; int minFreq = Integer . MAX_VALUE ; minFreq = Collections . min ( mp . entrySet ( ) , Comparator . comparingInt ( Map . Entry :: getKey ) ) . getValue ( ) ; int sum = 0 ; for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) { if ( entry . getValue ( ) == minFreq ) { sum += entry . getKey ( ) * entry . getValue ( ) ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 20 , 30 , 40 , 40 } ; int N = arr . length ; System . out . println ( findSum ( arr , N ) ) ; } } ","import math as mt NEW_LINE def findSum ( arr , N ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in arr : NEW_LINE INDENT if i in mp . keys ( ) : NEW_LINE INDENT mp [ i ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ i ] = 1 NEW_LINE DEDENT DEDENT minFreq = 10 ** 9 NEW_LINE for itr in mp : NEW_LINE INDENT if mp [ itr ] < minFreq : NEW_LINE INDENT minFreq = mp [ itr ] NEW_LINE DEDENT DEDENT Sum = 0 NEW_LINE for itr in mp : NEW_LINE INDENT if mp [ itr ] == minFreq : NEW_LINE INDENT Sum += itr * mp [ itr ] NEW_LINE DEDENT DEDENT return Sum NEW_LINE DEDENT arr = [ 10 , 20 , 30 , 40 , 40 ] NEW_LINE N = len ( arr ) NEW_LINE print ( findSum ( arr , N ) ) NEW_LINE " V782,"import java . util . * ; class Eulerian { public static String fibWord ( int n ) { String Sn_1 = ""0"" ; String Sn = ""01"" ; String tmp ; for ( int i = 2 ; i <= n ; i ++ ) { tmp = Sn ; Sn += Sn_1 ; Sn_1 = tmp ; } return Sn ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . print ( fibWord ( n ) ) ; } } ","def fibWord ( n ) : NEW_LINE INDENT Sn_1 = ""0"" NEW_LINE Sn = ""01"" NEW_LINE tmp = "" "" NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT tmp = Sn NEW_LINE Sn += Sn_1 NEW_LINE Sn_1 = tmp NEW_LINE DEDENT return Sn NEW_LINE DEDENT n = 6 NEW_LINE print ( fibWord ( n ) ) NEW_LINE " V783,"class GFG { public static int gen ( int n ) { if ( n == 0 ) return 0 ; else if ( n == 1 ) return 1 ; else if ( n % 2 == 0 ) return 4 * gen ( n / 2 ) ; else if ( n % 2 == 1 ) return 4 * gen ( n / 2 ) + 1 ; return 0 ; } public static void moserDeBruijn ( int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( gen ( i ) + "" ▁ "" ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { int n = 15 ; System . out . println ( "" First ▁ "" + n + "" ▁ terms ▁ of ▁ "" + "" Moser - de ▁ Bruijn ▁ Sequence ▁ : ▁ "" ) ; moserDeBruijn ( n ) ; } } ","def gen ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif n % 2 == 0 : NEW_LINE INDENT return 4 * gen ( n // 2 ) NEW_LINE DEDENT elif n % 2 == 1 : NEW_LINE INDENT return 4 * gen ( n // 2 ) + 1 NEW_LINE DEDENT DEDENT def moserDeBruijn ( n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( gen ( i ) , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT n = 15 NEW_LINE print ( "" First "" , n , "" terms ▁ of ▁ "" , "" Moser - de ▁ Brujn ▁ Sequence : "" ) NEW_LINE moserDeBruijn ( n ) NEW_LINE " V784,"import java . io . * ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return __gcd ( a - b , b ) ; return __gcd ( a , b - a ) ; } static int MinDeletion ( int a [ ] , int n ) { int gcd = 0 ; for ( int i = 0 ; i < n ; i ++ ) gcd = __gcd ( gcd , a [ i ] ) ; if ( gcd > 1 ) return - 1 ; else return 0 ; } public static void main ( String [ ] args ) { int a [ ] = { 3 , 6 , 12 , 81 , 9 } ; int n = a . length ; System . out . print ( MinDeletion ( a , n ) ) ; } } ","from math import gcd NEW_LINE def MinDeletion ( a , n ) : NEW_LINE INDENT __gcd = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT __gcd = gcd ( __gcd , a [ i ] ) ; NEW_LINE DEDENT if ( __gcd > 1 ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 3 , 6 , 12 , 81 , 9 ] ; NEW_LINE n = len ( a ) NEW_LINE print ( MinDeletion ( a , n ) ) ; NEW_LINE DEDENT " V785,"class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 || n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static int nextPrime ( int N ) { if ( N <= 1 ) return 2 ; int prime = N ; boolean found = false ; while ( ! found ) { prime ++ ; if ( isPrime ( prime ) ) found = true ; } return prime ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( nextPrime ( N ) ) ; } } ","import math NEW_LINE def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 5 , int ( math . sqrt ( n ) + 1 ) , 6 ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def nextPrime ( N ) : NEW_LINE INDENT if ( N <= 1 ) : NEW_LINE INDENT return 2 NEW_LINE DEDENT prime = N NEW_LINE found = False NEW_LINE while ( not found ) : NEW_LINE INDENT prime = prime + 1 NEW_LINE if ( isPrime ( prime ) == True ) : NEW_LINE INDENT found = True NEW_LINE DEDENT DEDENT return prime NEW_LINE DEDENT N = 3 NEW_LINE print ( nextPrime ( N ) ) NEW_LINE " V786,"import java . util . * ; class GFG { static Set < Integer > st = new HashSet < Integer > ( ) ; static void generateNumbers ( int n , int num , int a , int b ) { if ( num > 0 && num < n ) st . add ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } static void printNumbers ( int n ) { for ( int i = 0 ; i <= 9 ; i ++ ) for ( int j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; System . out . print ( "" The ▁ numbers ▁ are : ▁ "" ) ; System . out . print ( st ) ; st . clear ( ) ; } public static void main ( String args [ ] ) { int n = 12 ; printNumbers ( n ) ; } } ","st = set ( ) NEW_LINE def generateNumbers ( n , num , a , b ) : NEW_LINE INDENT if ( num > 0 and num < n ) : NEW_LINE INDENT st . add ( num ) NEW_LINE DEDENT if ( num >= n ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( num * 10 + a > num ) : NEW_LINE INDENT generateNumbers ( n , num * 10 + a , a , b ) NEW_LINE DEDENT generateNumbers ( n , num * 10 + b , a , b ) NEW_LINE DEDENT def printNumbers ( n ) : NEW_LINE INDENT for i in range ( 10 ) : NEW_LINE INDENT for j in range ( i + 1 , 10 , 1 ) : NEW_LINE INDENT generateNumbers ( n , 0 , i , j ) NEW_LINE DEDENT DEDENT print ( "" The ▁ numbers ▁ are : "" , end = "" ▁ "" ) NEW_LINE l = list ( st ) NEW_LINE for i in l : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 12 NEW_LINE printNumbers ( n ) NEW_LINE DEDENT " V787,"import java . lang . Math ; import java . io . * ; class GFG { static boolean checkPerfectSquare ( double n ) { double d = Math . sqrt ( n ) ; if ( d * d == n ) return true ; return false ; } static int largestPerfectSquareNumber ( int a [ ] , double n ) { int maxi = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( checkPerfectSquare ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } public static void main ( String [ ] args ) { int [ ] a = { 16 , 20 , 25 , 2 , 3 , 10 } ; double n = a . length ; System . out . println ( largestPerfectSquareNumber ( a , n ) ) ; } } ","from math import sqrt NEW_LINE def checkPerfectSquare ( n ) : NEW_LINE INDENT d = sqrt ( n ) NEW_LINE if d * d == n : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def largestPerfectSquareNumber ( a , n ) : NEW_LINE INDENT maxi = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( checkPerfectSquare ( a [ i ] ) ) : NEW_LINE INDENT maxi = max ( a [ i ] , maxi ) NEW_LINE DEDENT DEDENT return maxi NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT a = [ 16 , 20 , 25 , 2 , 3 , 10 ] NEW_LINE n = len ( a ) NEW_LINE print ( largestPerfectSquareNumber ( a , n ) ) NEW_LINE DEDENT " V788,"import java . util . * ; class GFG { static boolean isVowel ( char c ) { return ( c == ' a ' || c == ' e ' || c == ' i ' || c == ' o ' || c == ' u ' ) ; } static int countSubstringsUtil ( char [ ] s ) { int count = 0 ; Map < Character , Integer > mp = new HashMap < > ( ) ; int n = s . length ; int start = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( s [ i ] ) ) { mp . put ( s [ i ] , mp . get ( s [ i ] ) + 1 ) ; } else { mp . put ( s [ i ] , 1 ) ; } while ( mp . containsKey ( ' a ' ) && mp . containsKey ( ' e ' ) && mp . containsKey ( ' i ' ) && mp . containsKey ( ' o ' ) && mp . containsKey ( ' u ' ) && mp . get ( ' a ' ) > 0 && mp . get ( ' e ' ) > 0 && mp . get ( ' i ' ) > 0 && mp . get ( ' o ' ) > 0 && mp . get ( ' u ' ) > 0 ) { count += n - i ; mp . put ( s [ start ] , mp . get ( s [ start ] ) - 1 ) ; start ++ ; } } return count ; } static int countSubstrings ( String s ) { int count = 0 ; String temp = "" "" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( isVowel ( s . charAt ( i ) ) ) { temp += s . charAt ( i ) ; } else { if ( temp . length ( ) > 0 ) count += countSubstringsUtil ( temp . toCharArray ( ) ) ; temp = "" "" ; } } if ( temp . length ( ) > 0 ) count += countSubstringsUtil ( temp . toCharArray ( ) ) ; return count ; } public static void main ( String [ ] args ) { String s = "" aeouisddaaeeiouua "" ; System . out . println ( countSubstrings ( s ) ) ; } } ","def isVowel ( c ) : NEW_LINE INDENT return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ; NEW_LINE DEDENT def countSubstringsUtil ( s ) : NEW_LINE INDENT count = 0 ; NEW_LINE mp = dict . fromkeys ( s , 0 ) ; NEW_LINE n = len ( s ) ; NEW_LINE start = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ s [ i ] ] += 1 ; NEW_LINE while ( mp [ ' a ' ] > 0 and mp [ ' e ' ] > 0 and mp [ ' i ' ] > 0 and mp [ ' o ' ] > 0 and mp [ ' u ' ] > 0 ) : NEW_LINE INDENT count += n - i ; NEW_LINE mp [ s [ start ] ] -= 1 ; NEW_LINE start += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT def countSubstrings ( s ) : NEW_LINE INDENT count = 0 ; NEW_LINE temp = "" "" ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( isVowel ( s [ i ] ) ) : NEW_LINE INDENT temp += s [ i ] ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( len ( temp ) > 0 ) : NEW_LINE INDENT count += countSubstringsUtil ( temp ) ; NEW_LINE DEDENT temp = "" "" ; NEW_LINE DEDENT DEDENT if ( len ( temp ) > 0 ) : NEW_LINE INDENT count += countSubstringsUtil ( temp ) ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" aeouisddaaeeiouua "" ; NEW_LINE print ( countSubstrings ( s ) ) ; NEW_LINE DEDENT " V789,"import java . io . * ; import java . util . * ; class GFG { public static int findMaxValue ( ) { int res = 2 ; long fact = 2 ; while ( true ) { if ( fact < 0 ) break ; res ++ ; fact = fact * res ; } return res - 1 ; } public static void main ( String [ ] args ) { System . out . println ( "" Maximum ▁ value ▁ of "" + "" ▁ integer ▁ "" + findMaxValue ( ) ) ; } } ","import sys NEW_LINE def findMaxValue ( ) : NEW_LINE INDENT res = 2 ; NEW_LINE fact = 2 ; NEW_LINE while ( True ) : NEW_LINE INDENT if ( fact < 0 or fact > sys . maxsize ) : NEW_LINE INDENT break ; NEW_LINE DEDENT res += 1 ; NEW_LINE fact = fact * res ; NEW_LINE DEDENT return res - 1 ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( "" Maximum ▁ value ▁ of ▁ integer : "" , findMaxValue ( ) ) ; NEW_LINE DEDENT " V790,"import java . util . * ; class Solution { static final int M = 20 ; static int dp [ ] [ ] [ ] [ ] = new int [ M ] [ M ] [ 2 ] [ 2 ] ; static int d , K ; static int count ( int pos , int cnt , int tight , int nonz , Vector < Integer > num ) { if ( pos == num . size ( ) ) { if ( cnt == K ) return 1 ; return 0 ; } if ( dp [ pos ] [ cnt ] [ tight ] [ nonz ] != - 1 ) return dp [ pos ] [ cnt ] [ tight ] [ nonz ] ; int ans = 0 ; int limit = ( ( tight != 0 ) ? 9 : num . get ( pos ) ) ; for ( int dig = 0 ; dig <= limit ; dig ++ ) { int currCnt = cnt ; if ( dig == d ) { if ( d != 0 || ( d == 0 && nonz != 0 ) ) currCnt ++ ; } int currTight = tight ; if ( dig < num . get ( pos ) ) currTight = 1 ; ans += count ( pos + 1 , currCnt , currTight , ( dig != 0 ? 1 : 0 ) , num ) ; } return dp [ pos ] [ cnt ] [ tight ] [ nonz ] = ans ; } static int solve ( int x ) { Vector < Integer > num = new Vector < Integer > ( ) ; while ( x != 0 ) { num . add ( x % 10 ) ; x /= 10 ; } Collections . reverse ( num ) ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; return count ( 0 , 0 , 0 , 0 , num ) ; } public static void main ( String args [ ] ) { int L = 11 , R = 100 ; d = 2 ; K = 1 ; System . out . print ( solve ( R ) - solve ( L - 1 ) ) ; } } ","M = 20 NEW_LINE dp = [ ] NEW_LINE d , K = None , None NEW_LINE def count ( pos , cnt , tight , nonz , num : list ) : NEW_LINE INDENT if pos == len ( num ) : NEW_LINE INDENT if cnt == K : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT if dp [ pos ] [ cnt ] [ tight ] [ nonz ] != - 1 : NEW_LINE INDENT return dp [ pos ] [ cnt ] [ tight ] [ nonz ] NEW_LINE DEDENT ans = 0 NEW_LINE limit = 9 if tight else num [ pos ] NEW_LINE for dig in range ( limit + 1 ) : NEW_LINE INDENT currCnt = cnt NEW_LINE if dig == d : NEW_LINE INDENT if d != 0 or not d and nonz : NEW_LINE INDENT currCnt += 1 NEW_LINE DEDENT DEDENT currTight = tight NEW_LINE if dig < num [ pos ] : NEW_LINE INDENT currTight = 1 NEW_LINE DEDENT ans += count ( pos + 1 , currCnt , currTight , ( nonz or dig != 0 ) , num ) NEW_LINE DEDENT dp [ pos ] [ cnt ] [ tight ] [ nonz ] = ans NEW_LINE return dp [ pos ] [ cnt ] [ tight ] [ nonz ] NEW_LINE DEDENT def solve ( x ) : NEW_LINE INDENT global dp , K , d NEW_LINE num = [ ] NEW_LINE while x : NEW_LINE INDENT num . append ( x % 10 ) NEW_LINE x //= 10 NEW_LINE DEDENT num . reverse ( ) NEW_LINE dp = [ [ [ [ - 1 , - 1 ] for i in range ( 2 ) ] for j in range ( M ) ] for k in range ( M ) ] NEW_LINE return count ( 0 , 0 , 0 , 0 , num ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT L = 11 NEW_LINE R = 100 NEW_LINE d = 2 NEW_LINE K = 1 NEW_LINE print ( solve ( R ) - solve ( L - 1 ) ) NEW_LINE DEDENT " V791,"class GfG { static int getMaxLength ( int arr [ ] , int n ) { int start = 0 ; int preCnt = 0 ; while ( start < n && arr [ start ] == 1 ) { preCnt ++ ; start ++ ; } int end = n - 1 ; int suffCnt = 0 ; while ( end >= 0 && arr [ end ] == 1 ) { suffCnt ++ ; end -- ; } if ( start > end ) return n ; int midCnt = 0 ; int result = 0 ; for ( int i = start ; i <= end ; i ++ ) { if ( arr [ i ] == 1 ) { midCnt ++ ; result = Math . max ( result , midCnt ) ; } else { midCnt = 0 ; } } return Math . max ( result , preCnt + suffCnt ) ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( getMaxLength ( arr , n ) ) ; } } ","def getMaxLength ( arr , n ) : NEW_LINE INDENT start = 0 NEW_LINE preCnt = 0 NEW_LINE while ( start < n and arr [ start ] == 1 ) : NEW_LINE INDENT preCnt = preCnt + 1 NEW_LINE start = start + 1 NEW_LINE DEDENT end = n - 1 NEW_LINE suffCnt = 0 NEW_LINE while ( end >= 0 and arr [ end ] == 1 ) : NEW_LINE INDENT suffCnt = suffCnt + 1 NEW_LINE end = end - 1 NEW_LINE DEDENT if ( start > end ) : NEW_LINE INDENT return n NEW_LINE DEDENT midCnt = 0 NEW_LINE i = start NEW_LINE result = 0 NEW_LINE while ( i <= end ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE INDENT midCnt = midCnt + 1 NEW_LINE result = max ( result , midCnt ) NEW_LINE DEDENT else : NEW_LINE INDENT midCnt = 0 NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT return max ( result , preCnt + suffCnt ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( getMaxLength ( arr , n ) ) NEW_LINE DEDENT " V792,"class GFG { static int findMin ( int arr [ ] , int n ) { int m = 0 ; for ( int i = 0 ; i < n ; i ++ ) m = Math . max ( m , arr [ i ] ) ; int cnt [ ] = new int [ m + 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 1 ; j * j <= arr [ i ] ; j ++ ) { if ( arr [ i ] % j == 0 ) { if ( j * j == arr [ i ] ) cnt [ j ] ++ ; else { cnt [ j ] ++ ; cnt [ arr [ i ] / j ] ++ ; } } } } for ( int i = 1 ; i <= m + 1 ; i ++ ) if ( cnt [ i ] == 0 ) { return i ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 12 , 6 } ; int n = arr . length ; System . out . println ( findMin ( arr , n ) ) ; } } ","def findMin ( arr , n ) : NEW_LINE INDENT m = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT m = max ( m , arr [ i ] ) NEW_LINE DEDENT cnt = [ 0 ] * ( m + 2 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT j = 1 NEW_LINE while j * j <= arr [ i ] : NEW_LINE INDENT if ( arr [ i ] % j == 0 ) : NEW_LINE INDENT if ( j * j == arr [ i ] ) : NEW_LINE INDENT cnt [ j ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt [ j ] += 1 NEW_LINE cnt [ arr [ i ] // j ] += 1 NEW_LINE DEDENT DEDENT j += 1 NEW_LINE DEDENT DEDENT for i in range ( 1 , m + 2 ) : NEW_LINE INDENT if ( cnt [ i ] == 0 ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ 2 , 12 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMin ( arr , n ) ) NEW_LINE " V793,"import java . util . * ; import java . lang . * ; class GFG { public static int minJumps ( int arr [ ] , int N ) { int MAX = 1000000 ; int [ ] fib = new int [ 30 ] ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( int i = 2 ; i < 30 ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; int [ ] DP = new int [ N + 2 ] ; DP [ 0 ] = 0 ; for ( int i = 1 ; i <= N + 1 ; i ++ ) DP [ i ] = MAX ; for ( int i = 1 ; i <= N + 1 ; i ++ ) { for ( int j = 1 ; j < 30 ; j ++ ) { if ( ( i == N + 1 || arr [ i - 1 ] == 1 ) && i - fib [ j ] >= 0 ) DP [ i ] = Math . min ( DP [ i ] , 1 + DP [ i - fib [ j ] ] ) ; } } if ( DP [ N + 1 ] != MAX ) return DP [ N + 1 ] ; else return - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 } ; int n = 11 ; int ans = minJumps ( arr , n ) ; System . out . println ( ans ) ; } } ","MAX = 1e9 NEW_LINE def minJumps ( arr , N ) : NEW_LINE INDENT fib = [ 0 for i in range ( 30 ) ] NEW_LINE fib [ 0 ] = 0 NEW_LINE fib [ 1 ] = 1 NEW_LINE for i in range ( 2 , 30 ) : NEW_LINE INDENT fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] NEW_LINE DEDENT DP = [ 0 for i in range ( N + 2 ) ] NEW_LINE DP [ 0 ] = 0 NEW_LINE for i in range ( 1 , N + 2 ) : NEW_LINE INDENT DP [ i ] = MAX NEW_LINE DEDENT for i in range ( 1 , N + 2 ) : NEW_LINE INDENT for j in range ( 1 , 30 ) : NEW_LINE INDENT if ( ( arr [ i - 1 ] == 1 or i == N + 1 ) and i - fib [ j ] >= 0 ) : NEW_LINE INDENT DP [ i ] = min ( DP [ i ] , 1 + DP [ i - fib [ j ] ] ) NEW_LINE DEDENT DEDENT DEDENT if ( DP [ N + 1 ] != MAX ) : NEW_LINE INDENT return DP [ N + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT arr = [ 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minJumps ( arr , n - 1 ) ) NEW_LINE " V794,"import java . util . * ; class GFG { static int getHermiteNumber ( int n ) { if ( n == 0 ) return 1 ; else if ( n == 1 ) return 1 ; else return - 2 * ( n - 1 ) * getHermiteNumber ( n - 2 ) ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( getHermiteNumber ( n ) ) ; } } ","def getHermiteNumber ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if n == 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return ( - 2 * ( n - 1 ) * getHermiteNumber ( n - 2 ) ) NEW_LINE DEDENT DEDENT n = 6 NEW_LINE print ( getHermiteNumber ( n ) ) ; NEW_LINE " V795,"class GFG { static void FindPoints ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 ) { int x5 = Math . max ( x1 , x3 ) ; int y5 = Math . max ( y1 , y3 ) ; int x6 = Math . min ( x2 , x4 ) ; int y6 = Math . min ( y2 , y4 ) ; if ( x5 > x6 || y5 > y6 ) { System . out . println ( "" No ▁ intersection "" ) ; return ; } System . out . print ( "" ( "" + x5 + "" , ▁ "" + y5 + "" ) ▁ "" ) ; System . out . print ( "" ( "" + x6 + "" , ▁ "" + y6 + "" ) ▁ "" ) ; int x7 = x5 ; int y7 = y6 ; System . out . print ( "" ( "" + x7 + "" , ▁ "" + y7 + "" ) ▁ "" ) ; int x8 = x6 ; int y8 = y5 ; System . out . print ( "" ( "" + x8 + "" , ▁ "" + y8 + "" ) ▁ "" ) ; } public static void main ( String args [ ] ) { int x1 = 0 , y1 = 0 , x2 = 10 , y2 = 8 ; int x3 = 2 , y3 = 3 , x4 = 7 , y4 = 9 ; FindPoints ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) ; } } ","def FindPoints ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) : NEW_LINE INDENT x5 = max ( x1 , x3 ) NEW_LINE y5 = max ( y1 , y3 ) NEW_LINE x6 = min ( x2 , x4 ) NEW_LINE y6 = min ( y2 , y4 ) NEW_LINE if ( x5 > x6 or y5 > y6 ) : NEW_LINE INDENT print ( "" No ▁ intersection "" ) NEW_LINE return NEW_LINE DEDENT print ( "" ( "" , x5 , "" , ▁ "" , y5 , "" ) ▁ "" , end = "" ▁ "" ) NEW_LINE print ( "" ( "" , x6 , "" , ▁ "" , y6 , "" ) ▁ "" , end = "" ▁ "" ) NEW_LINE x7 = x5 NEW_LINE y7 = y6 NEW_LINE print ( "" ( "" , x7 , "" , ▁ "" , y7 , "" ) ▁ "" , end = "" ▁ "" ) NEW_LINE x8 = x6 NEW_LINE y8 = y5 NEW_LINE print ( "" ( "" , x8 , "" , ▁ "" , y8 , "" ) ▁ "" ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT x1 = 0 NEW_LINE y1 = 0 NEW_LINE x2 = 10 NEW_LINE y2 = 8 NEW_LINE x3 = 2 NEW_LINE y3 = 3 NEW_LINE x4 = 7 NEW_LINE y4 = 9 NEW_LINE FindPoints ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) NEW_LINE DEDENT " V796,"class GFG { static int numberOfDigits ( int n ) { int cnt = 0 ; while ( n > 0 ) { cnt ++ ; n /= 10 ; } return cnt ; } static void cal ( int num ) { int digits = numberOfDigits ( num ) ; int powTen = ( int ) Math . pow ( 10 , digits - 1 ) ; for ( int i = 0 ; i < digits - 1 ; i ++ ) { int firstDigit = num / powTen ; int left = ( ( num * 10 ) + firstDigit ) - ( firstDigit * powTen * 10 ) ; System . out . print ( left + "" ▁ "" ) ; num = left ; } } public static void main ( String [ ] args ) { int num = 1445 ; cal ( num ) ; } } ","def numberofDigits ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE while n > 0 : NEW_LINE INDENT cnt += 1 NEW_LINE n //= 10 NEW_LINE DEDENT return cnt NEW_LINE DEDENT def cal ( num ) : NEW_LINE INDENT digit = numberofDigits ( num ) NEW_LINE powTen = pow ( 10 , digit - 1 ) NEW_LINE for i in range ( digit - 1 ) : NEW_LINE INDENT firstDigit = num // powTen NEW_LINE left = ( num * 10 + firstDigit - ( firstDigit * powTen * 10 ) ) NEW_LINE print ( left , end = "" ▁ "" ) NEW_LINE num = left NEW_LINE DEDENT DEDENT num = 1445 NEW_LINE cal ( num ) NEW_LINE " V797,"import java . io . * ; import java . util . * ; class GFG { public static void leastPrimeFactor ( int n ) { int [ ] least_prime = new int [ n + 1 ] ; least_prime [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( least_prime [ i ] == 0 ) { least_prime [ i ] = i ; for ( int j = 2 * i ; j <= n ; j += i ) if ( least_prime [ j ] == 0 ) least_prime [ j ] = i ; } } for ( int i = 1 ; i <= n ; i ++ ) System . out . println ( "" Least ▁ Prime ▁ factor ▁ of ▁ "" + + i + "" : ▁ "" + least_prime [ i ] ) ; } public static void main ( String [ ] args ) { int n = 10 ; leastPrimeFactor ( n ) ; } } ","def leastPrimeFactor ( n ) : NEW_LINE INDENT least_prime = [ 0 ] * ( n + 1 ) NEW_LINE least_prime [ 1 ] = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( least_prime [ i ] == 0 ) : NEW_LINE INDENT least_prime [ i ] = i NEW_LINE for j in range ( 2 * i , n + 1 , i ) : NEW_LINE INDENT if ( least_prime [ j ] == 0 ) : NEW_LINE INDENT least_prime [ j ] = i NEW_LINE DEDENT DEDENT DEDENT DEDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( "" Least ▁ Prime ▁ factor ▁ of ▁ "" , i , "" : ▁ "" , least_prime [ i ] ) NEW_LINE DEDENT DEDENT n = 10 NEW_LINE leastPrimeFactor ( n ) NEW_LINE " V798,"public class Test { public static void main ( String [ ] args ) { System . out . println ( isPower ( 10 , 1 ) ? 1 : 0 ) ; System . out . println ( isPower ( 1 , 20 ) ? 1 : 0 ) ; System . out . println ( isPower ( 2 , 128 ) ? 1 : 0 ) ; System . out . println ( isPower ( 2 , 30 ) ? 1 : 0 ) ; } public static boolean isPower ( int x , int y ) { if ( x == 1 ) return ( y == 1 ) ; int pow = 1 ; while ( pow < y ) pow = pow * x ; return ( pow == y ) ; } } ","def isPower ( x , y ) : NEW_LINE INDENT if ( x == 1 ) : NEW_LINE INDENT return ( y == 1 ) NEW_LINE DEDENT pow = 1 NEW_LINE while ( pow < y ) : NEW_LINE INDENT pow = pow * x NEW_LINE DEDENT return ( pow == y ) NEW_LINE DEDENT if ( isPower ( 10 , 1 ) ) : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT if ( isPower ( 1 , 20 ) ) : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT if ( isPower ( 2 , 128 ) ) : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT if ( isPower ( 2 , 30 ) ) : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT " V799,"import java . io . * ; class GFG { static void pattern ( int rows_no ) { int i , j , k ; for ( i = 1 ; i <= rows_no ; i ++ ) { for ( k = 1 ; k < i ; k ++ ) System . out . print ( "" ▁ "" ) ; for ( j = i ; j <= rows_no ; j ++ ) System . out . print ( j + "" ▁ "" ) ; System . out . println ( ) ; } for ( i = rows_no - 1 ; i >= 1 ; i -- ) { for ( k = 1 ; k < i ; k ++ ) System . out . print ( "" ▁ "" ) ; for ( j = i ; j <= rows_no ; j ++ ) System . out . print ( j + "" ▁ "" ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int rows_no = 7 ; pattern ( rows_no ) ; } } ","def pattern ( rows_no ) : NEW_LINE INDENT for i in range ( 1 , rows_no + 1 ) : NEW_LINE INDENT for k in range ( 1 , i ) : NEW_LINE INDENT print ( "" ▁ "" , end = "" "" ) NEW_LINE DEDENT for j in range ( i , rows_no + 1 ) : NEW_LINE INDENT print ( j , end = "" ▁ "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT for i in range ( rows_no - 1 , 0 , - 1 ) : NEW_LINE INDENT for k in range ( 1 , i ) : NEW_LINE INDENT print ( "" ▁ "" , end = "" "" ) NEW_LINE DEDENT for j in range ( i , rows_no + 1 ) : NEW_LINE INDENT print ( j , end = "" ▁ "" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT rows_no = 7 NEW_LINE pattern ( rows_no ) NEW_LINE " V800,"import java . util . * ; import java . lang . * ; public class GfG { public static void printSmall ( int arr [ ] , int n , int k ) { for ( int i = k ; i < n ; ++ i ) { int max_var = arr [ k - 1 ] ; int pos = k - 1 ; for ( int j = k - 2 ; j >= 0 ; j -- ) { if ( arr [ j ] > max_var ) { max_var = arr [ j ] ; pos = j ; } } if ( max_var > arr [ i ] ) { int j = pos ; while ( j < k - 1 ) { arr [ j ] = arr [ j + 1 ] ; j ++ ; } arr [ k - 1 ] = arr [ i ] ; } } for ( int i = 0 ; i < k ; i ++ ) System . out . print ( arr [ i ] + "" ▁ "" ) ; } public static void main ( String argc [ ] ) { int [ ] arr = { 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 } ; int n = 10 ; int k = 5 ; printSmall ( arr , n , k ) ; } } ","def printSmall ( arr , n , k ) : NEW_LINE INDENT for i in range ( k , n ) : NEW_LINE INDENT max_var = arr [ k - 1 ] NEW_LINE pos = k - 1 NEW_LINE for j in range ( k - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ j ] > max_var ) : NEW_LINE INDENT max_var = arr [ j ] NEW_LINE pos = j NEW_LINE DEDENT DEDENT if ( max_var > arr [ i ] ) : NEW_LINE INDENT j = pos NEW_LINE while ( j < k - 1 ) : NEW_LINE INDENT arr [ j ] = arr [ j + 1 ] NEW_LINE j += 1 NEW_LINE DEDENT arr [ k - 1 ] = arr [ i ] NEW_LINE DEDENT DEDENT for i in range ( 0 , k ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE k = 5 NEW_LINE printSmall ( arr , n , k ) NEW_LINE " V801,"class GFG { static String smallest ( String s ) { int l = s . length ( ) ; String ans = "" "" ; for ( int i = 0 ; i < l - 1 ; i ++ ) { if ( s . charAt ( i ) > s . charAt ( i + 1 ) ) { for ( int j = 0 ; j < l ; j ++ ) { if ( i != j ) { ans += s . charAt ( j ) ; } } return ans ; } } ans = s . substring ( 0 , l - 1 ) ; return ans ; } public static void main ( String [ ] args ) { String s = "" abcda "" ; System . out . println ( smallest ( s ) ) ; } } ","def smallest ( s ) : NEW_LINE INDENT l = len ( s ) NEW_LINE ans = "" "" NEW_LINE for i in range ( l ) : NEW_LINE INDENT if ( s [ i ] > s [ i + 1 ] ) : NEW_LINE INDENT for j in range ( l ) : NEW_LINE INDENT if ( i != j ) : NEW_LINE INDENT ans += s [ j ] NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT DEDENT ans = s [ 0 : l - 1 ] NEW_LINE return ans NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT s = "" abcda "" NEW_LINE print ( smallest ( s ) ) NEW_LINE DEDENT " V802,"import java . util . * ; class GFG { static int countBits ( int n ) { int count = 0 ; while ( n > 0 ) { count ++ ; n >>= 1 ; } return count ; } static int findNearestNumber ( int n ) { int cnt = countBits ( n ) ; cnt -= 1 ; if ( cnt % 2 == 1 ) { return 1 << ( cnt + 1 ) ; } else { int tempnum = 0 ; for ( int i = 0 ; i <= cnt ; i += 2 ) { tempnum += 1 << i ; } if ( tempnum < n ) { return ( 1 << ( cnt + 2 ) ) ; } else if ( tempnum == n ) { return n ; } for ( int i = 0 ; i <= cnt ; i += 2 ) { tempnum -= ( 1 << i ) ; if ( tempnum < n ) { return tempnum += ( 1 << i ) ; } } } return Integer . MIN_VALUE ; } public static void main ( String [ ] args ) { int n = 19 ; System . out . println ( findNearestNumber ( n ) ) ; } } ","def countBits ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE n >>= 1 ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT def findNearestNumber ( n ) : NEW_LINE INDENT cnt = countBits ( n ) ; NEW_LINE cnt -= 1 ; NEW_LINE if ( cnt % 2 ) : NEW_LINE INDENT return 1 << ( cnt + 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT tempnum = 0 ; NEW_LINE for i in range ( 0 , cnt + 1 , 2 ) : NEW_LINE INDENT tempnum += 1 << i ; NEW_LINE DEDENT if ( tempnum < n ) : NEW_LINE INDENT return ( 1 << ( cnt + 2 ) ) ; NEW_LINE DEDENT elif ( tempnum == n ) : NEW_LINE INDENT return n ; NEW_LINE DEDENT for i in range ( 0 , cnt + 1 , 2 ) : NEW_LINE INDENT tempnum -= ( 1 << i ) ; NEW_LINE if ( tempnum < n ) : NEW_LINE INDENT tempnum += ( 1 << i ) ; NEW_LINE return tempnum ; NEW_LINE DEDENT DEDENT DEDENT DEDENT n = 19 ; NEW_LINE print ( findNearestNumber ( n ) ) ; NEW_LINE " V803,"import java . util . * ; class GFG { static int run_tasks ( Queue < Integer > A , Queue < Integer > B ) { int total_time = 0 ; while ( ! A . isEmpty ( ) ) { int x = A . peek ( ) ; int y = B . peek ( ) ; if ( x == y ) { A . remove ( ) ; B . remove ( ) ; total_time ++ ; } else { A . remove ( ) ; A . add ( x ) ; total_time += 2 ; } } return total_time ; } public static void main ( String [ ] args ) { Queue < Integer > A = new LinkedList < Integer > ( ) ; A . add ( 3 ) ; A . add ( 2 ) ; A . add ( 1 ) ; A . add ( 4 ) ; Queue < Integer > B = new LinkedList < Integer > ( ) ; B . add ( 4 ) ; B . add ( 1 ) ; B . add ( 3 ) ; B . add ( 2 ) ; System . out . print ( run_tasks ( A , B ) ) ; } } ","from collections import deque NEW_LINE def run_tasks ( A , B ) : NEW_LINE INDENT total_time = 0 NEW_LINE while ( len ( A ) > 0 ) : NEW_LINE INDENT x = A . popleft ( ) NEW_LINE y = B . popleft ( ) NEW_LINE if ( x == y ) : NEW_LINE INDENT total_time += 1 NEW_LINE DEDENT else : NEW_LINE INDENT B . appendleft ( y ) NEW_LINE A . append ( x ) NEW_LINE total_time += 2 NEW_LINE DEDENT DEDENT return total_time NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = deque ( ) NEW_LINE A . append ( 3 ) NEW_LINE A . append ( 2 ) NEW_LINE A . append ( 1 ) NEW_LINE A . append ( 4 ) NEW_LINE B = deque ( ) NEW_LINE B . append ( 4 ) NEW_LINE B . append ( 1 ) NEW_LINE B . append ( 3 ) NEW_LINE B . append ( 2 ) NEW_LINE print ( run_tasks ( A , B ) ) NEW_LINE DEDENT " V804,"import java . io . * ; import java . util . * ; class GFG { static void findAllSequences ( int diff , char out [ ] , int start , int end ) { if ( Math . abs ( diff ) > ( end - start + 1 ) / 2 ) return ; if ( start > end ) { if ( diff == 0 ) { System . out . print ( out ) ; System . out . print ( "" ▁ "" ) ; } return ; } out [ start ] = '0' ; out [ end ] = '1' ; findAllSequences ( diff + 1 , out , start + 1 , end - 1 ) ; out [ start ] = out [ end ] = '1' ; findAllSequences ( diff , out , start + 1 , end - 1 ) ; out [ start ] = out [ end ] = '0' ; findAllSequences ( diff , out , start + 1 , end - 1 ) ; out [ start ] = '1' ; out [ end ] = '0' ; findAllSequences ( diff - 1 , out , start + 1 , end - 1 ) ; } public static void main ( String [ ] args ) { int n = 2 ; char [ ] out = new char [ 2 * n + 1 ] ; out [ 2 * n ] = ' \0' ; findAllSequences ( 0 , out , 0 , 2 * n - 1 ) ; } } ","def findAllSequences ( diff , out , start , end ) : NEW_LINE INDENT if ( abs ( diff ) > ( end - start + 1 ) // 2 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT if ( start > end ) : NEW_LINE INDENT if ( diff == 0 ) : NEW_LINE INDENT print ( ' ' . join ( list ( out ) ) , end = "" ▁ "" ) ; NEW_LINE DEDENT return ; NEW_LINE DEDENT out [ start ] = '0' ; NEW_LINE out [ end ] = '1' ; NEW_LINE findAllSequences ( diff + 1 , out , start + 1 , end - 1 ) ; NEW_LINE out [ start ] = out [ end ] = '1' ; NEW_LINE findAllSequences ( diff , out , start + 1 , end - 1 ) ; NEW_LINE out [ start ] = out [ end ] = '0' ; NEW_LINE findAllSequences ( diff , out , start + 1 , end - 1 ) ; NEW_LINE out [ start ] = '1' ; NEW_LINE out [ end ] = '0' ; NEW_LINE findAllSequences ( diff - 1 , out , start + 1 , end - 1 ) ; NEW_LINE DEDENT n = 2 ; NEW_LINE out = [ "" "" ] * ( 2 * n ) ; NEW_LINE findAllSequences ( 0 , out , 0 , 2 * n - 1 ) ; NEW_LINE " V805,"class GFG { static int Count_subarray ( int arr [ ] , int n ) { int total_sum = 0 , subarray_sum , remaining_sum , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { total_sum += arr [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { subarray_sum = 0 ; for ( int j = i ; j < n ; j ++ ) { subarray_sum += arr [ j ] ; remaining_sum = total_sum - subarray_sum ; if ( subarray_sum > remaining_sum ) { count += 1 ; } } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 9 , 12 , 6 } ; int n = arr . length ; System . out . print ( Count_subarray ( arr , n ) ) ; } } ","def Count_subarray ( arr , n ) : NEW_LINE INDENT total_sum = 0 ; NEW_LINE count = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT total_sum += arr [ i ] ; NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT subarray_sum = 0 ; NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT subarray_sum += arr [ j ] ; NEW_LINE remaining_sum = total_sum - subarray_sum ; NEW_LINE if ( subarray_sum > remaining_sum ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 10 , 9 , 12 , 6 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( Count_subarray ( arr , n ) ) ; NEW_LINE DEDENT " V806,"class GFG { static int count_setbits ( int N ) { int cnt = 0 ; while ( N > 0 ) { cnt += ( N & 1 ) ; N = N >> 1 ; } return cnt ; } static int countMultiples ( int n ) { int multiple [ ] = { 2 , 3 , 5 } ; int count = 0 , mask = ( int ) Math . pow ( 2 , 3 ) ; for ( int i = 1 ; i < mask ; i ++ ) { int prod = 1 ; for ( int j = 0 ; j < 3 ; j ++ ) { if ( ( i & 1 << j ) > 0 ) prod = prod * multiple [ j ] ; } if ( count_setbits ( i ) % 2 == 1 ) count = count + n / prod ; else count = count - n / prod ; } return count ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( countMultiples ( n ) ) ; } } ","def countMultiples ( n ) : NEW_LINE INDENT multiple = [ 2 , 3 , 5 ] NEW_LINE count = 0 NEW_LINE mask = int ( pow ( 2 , 3 ) ) NEW_LINE for i in range ( 1 , mask ) : NEW_LINE INDENT prod = 1 NEW_LINE for j in range ( 3 ) : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT prod = prod * multiple [ j ] NEW_LINE DEDENT DEDENT if ( bin ( i ) . count ( '1' ) % 2 == 1 ) : NEW_LINE INDENT count = count + n // prod NEW_LINE DEDENT else : NEW_LINE INDENT count = count - n // prod NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 NEW_LINE print ( countMultiples ( n ) ) NEW_LINE DEDENT " V807,"public class GFG { static int stringToInt ( String str ) { if ( str . length ( ) == 1 ) return ( str . charAt ( 0 ) - '0' ) ; double y = stringToInt ( str . substring ( 1 ) ) ; double x = str . charAt ( 0 ) - '0' ; x = x * Math . pow ( 10 , str . length ( ) - 1 ) + y ; return ( int ) ( x ) ; } public static void main ( String [ ] args ) { String str = ""1235"" ; System . out . print ( stringToInt ( str ) ) ; } } ","def stringToInt ( str ) : NEW_LINE INDENT if ( len ( str ) == 1 ) : NEW_LINE INDENT return ord ( str [ 0 ] ) - ord ( '0' ) ; NEW_LINE DEDENT y = stringToInt ( str [ 1 : ] ) ; NEW_LINE x = ord ( str [ 0 ] ) - ord ( '0' ) ; NEW_LINE x = x * ( 10 ** ( len ( str ) - 1 ) ) + y ; NEW_LINE return int ( x ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = ""1235"" ; NEW_LINE print ( stringToInt ( str ) ) ; NEW_LINE DEDENT " V808,"class GFG { static int calcFunction ( int n , int r ) { int finalDenominator = 1 ; int mx = Math . max ( r , n - r ) ; for ( int i = mx + 1 ; i <= n ; i ++ ) { int denominator = ( int ) Math . pow ( i , i ) ; int numerator = ( int ) Math . pow ( i - mx , i - mx ) ; finalDenominator = ( finalDenominator * denominator ) / numerator ; } return finalDenominator ; } public static void main ( String [ ] args ) { int n = 6 , r = 2 ; System . out . println ( ""1 / "" + calcFunction ( n , r ) ) ; } } ","def calcFunction ( n , r ) : NEW_LINE INDENT finalDenominator = 1 NEW_LINE mx = max ( r , n - r ) NEW_LINE for i in range ( mx + 1 , n + 1 ) : NEW_LINE INDENT denominator = pow ( i , i ) NEW_LINE numerator = pow ( i - mx , i - mx ) NEW_LINE finalDenominator = ( finalDenominator * denominator ) // numerator NEW_LINE DEDENT return finalDenominator NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 6 NEW_LINE r = 2 NEW_LINE print ( ""1 / "" , end = "" "" ) NEW_LINE print ( calcFunction ( n , r ) ) NEW_LINE DEDENT " V809,"import java . io . * ; class GFG { static int countDigits ( int n ) { double ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ans += Math . log10 ( i ) ; ans = ans * n ; return 1 + ( int ) Math . floor ( ans ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( countDigits ( n ) + "" \n "" ) ; } } ","import math NEW_LINE def countDigits ( n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans += math . log10 ( i ) NEW_LINE DEDENT ans = ans * n NEW_LINE return 1 + math . floor ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 4 NEW_LINE print ( countDigits ( n ) ) NEW_LINE DEDENT " V810,"import java . util . * ; class Geeks { static void ReplaceElements ( int arr [ ] , int n ) { int max_ele = arr [ 0 ] ; arr [ 0 ] = - 1 ; for ( int i = 1 ; i < n ; ++ i ) { if ( max_ele > arr [ i ] ) arr [ i ] = max_ele ; else if ( max_ele <= arr [ i ] ) { int temp = arr [ i ] ; arr [ i ] = max_ele ; max_ele = temp ; } } } public static void main ( String args [ ] ) { int arr [ ] = { 4 , 5 , 2 , 1 , 7 , 6 } ; int n = arr . length ; ReplaceElements ( arr , n ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . println ( arr [ i ] ) ; } } ","def ReplaceElements ( arr , n ) : NEW_LINE INDENT max_ele = arr [ 0 ] NEW_LINE arr [ 0 ] = - 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( max_ele > arr [ i ] ) : NEW_LINE INDENT arr [ i ] = max_ele NEW_LINE DEDENT elif ( max_ele <= arr [ i ] ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE arr [ i ] = max_ele NEW_LINE max_ele = temp NEW_LINE DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT arr = [ 4 , 5 , 2 , 1 , 7 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE ReplaceElements ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = "" ▁ "" ) NEW_LINE DEDENT DEDENT " V811,"class GFG { static long nthTerm ( long n ) { long nth ; if ( n % 2 == 0 ) nth = 2 * ( ( n * n ) - n ) ; else nth = ( 2 * n * n ) - n ; return nth ; } public static void main ( String [ ] args ) { long n ; n = 5 ; System . out . println ( nthTerm ( n ) ) ; n = 25 ; System . out . println ( nthTerm ( n ) ) ; n = 25000000 ; System . out . println ( nthTerm ( n ) ) ; n = 250000007 ; System . out . println ( nthTerm ( n ) ) ; } } ","def nthTerm ( n ) : NEW_LINE INDENT nth = 0 NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT nth = 2 * ( ( n * n ) - n ) NEW_LINE DEDENT else : NEW_LINE INDENT nth = ( 2 * n * n ) - n NEW_LINE DEDENT return nth NEW_LINE DEDENT n = 5 NEW_LINE print ( nthTerm ( n ) ) NEW_LINE n = 25 NEW_LINE print ( nthTerm ( n ) ) NEW_LINE n = 25000000 NEW_LINE print ( nthTerm ( n ) ) NEW_LINE n = 250000007 NEW_LINE print ( nthTerm ( n ) ) NEW_LINE " V812,"import java . io . * ; class GFG { static void decToHexa ( int n ) { char [ ] hexaDeciNum = new char [ 100 ] ; int i = 0 ; while ( n != 0 ) { int temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ; i ++ ; } else { hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ; i ++ ; } n = n / 16 ; } for ( int j = i - 1 ; j >= 0 ; j -- ) System . out . print ( hexaDeciNum [ j ] ) ; } public static void main ( String [ ] args ) { int n = 2545 ; decToHexa ( n ) ; } } ","def decToHexa ( n ) : NEW_LINE INDENT hexaDeciNum = [ '0' ] * 100 ; NEW_LINE i = 0 ; NEW_LINE while ( n != 0 ) : NEW_LINE INDENT temp = 0 ; NEW_LINE temp = n % 16 ; NEW_LINE if ( temp < 10 ) : NEW_LINE INDENT hexaDeciNum [ i ] = chr ( temp + 48 ) ; NEW_LINE i = i + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT hexaDeciNum [ i ] = chr ( temp + 55 ) ; NEW_LINE i = i + 1 ; NEW_LINE DEDENT n = int ( n / 16 ) ; NEW_LINE DEDENT j = i - 1 ; NEW_LINE while ( j >= 0 ) : NEW_LINE INDENT print ( ( hexaDeciNum [ j ] ) , end = "" "" ) ; NEW_LINE j = j - 1 ; NEW_LINE DEDENT DEDENT n = 2545 ; NEW_LINE decToHexa ( n ) ; NEW_LINE " V813,"class GFG { void fib ( int f [ ] ) { f [ 0 ] = 0 ; f [ 1 ] = 1 ; for ( int i = 2 ; i <= 59 ; i ++ ) f [ i ] = ( f [ i - 1 ] + f [ i - 2 ] ) % 10 ; } int findLastDigit ( long n ) { int f [ ] = new int [ 60 ] ; fib ( f ) ; int index = ( int ) ( n % 60L ) ; return f [ index ] ; } public static void main ( String [ ] args ) { long n ; GFG ob = new GFG ( ) ; n = 1 ; System . out . println ( ob . findLastDigit ( n ) ) ; n = 61 ; System . out . println ( ob . findLastDigit ( n ) ) ; n = 7 ; System . out . println ( ob . findLastDigit ( n ) ) ; n = 67 ; System . out . println ( ob . findLastDigit ( n ) ) ; } } ","def fib ( f , n ) : NEW_LINE INDENT f [ 0 ] = 0 ; NEW_LINE f [ 1 ] = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT f [ i ] = ( f [ i - 1 ] + f [ i - 2 ] ) % 10 ; NEW_LINE DEDENT return f ; NEW_LINE DEDENT def findLastDigit ( n ) : NEW_LINE INDENT f = [ 0 ] * 61 ; NEW_LINE f = fib ( f , 60 ) ; NEW_LINE return f [ n % 60 ] ; NEW_LINE DEDENT n = 1 ; NEW_LINE print ( findLastDigit ( n ) ) ; NEW_LINE n = 61 ; NEW_LINE print ( findLastDigit ( n ) ) ; NEW_LINE n = 7 ; NEW_LINE print ( findLastDigit ( n ) ) ; NEW_LINE n = 67 ; NEW_LINE print ( findLastDigit ( n ) ) ; NEW_LINE " V814,"class GFG { static void arrayConstruct ( int N ) { for ( int i = 2 ; i <= N ; i = i + 2 ) System . out . print ( i + "" ▁ "" ) ; for ( int i = 1 ; i < N - 1 ; i = i + 2 ) System . out . print ( i + "" ▁ "" ) ; System . out . print ( N - 1 + ( N / 2 ) + "" \n "" ) ; } static void createArray ( int N ) { if ( N % 4 == 0 ) arrayConstruct ( N ) ; else System . out . print ( - 1 + "" \n "" ) ; } public static void main ( String [ ] args ) { int N = 8 ; createArray ( N ) ; } } ","def arrayConstruct ( N ) : NEW_LINE INDENT for i in range ( 2 , N + 1 , 2 ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT for i in range ( 1 , N - 1 , 2 ) : NEW_LINE INDENT print ( i , end = "" ▁ "" ) NEW_LINE DEDENT print ( N - 1 + ( N // 2 ) ) NEW_LINE DEDENT def createArray ( N ) : NEW_LINE INDENT if ( N % 4 == 0 ) : NEW_LINE INDENT arrayConstruct ( N ) NEW_LINE DEDENT else : NEW_LINE INDENT cout << - 1 << endl NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 8 NEW_LINE createArray ( N ) NEW_LINE DEDENT " V815,"class GFG { static final int INT_BITS = 32 ; static int leftRotate ( int n , int d ) { return ( n << d ) | ( n >> ( INT_BITS - d ) ) ; } static int rightRotate ( int n , int d ) { return ( n >> d ) | ( n << ( INT_BITS - d ) ) ; } public static void main ( String arg [ ] ) { int n = 16 ; int d = 2 ; System . out . print ( "" Left ▁ Rotation ▁ of ▁ "" + n + "" ▁ by ▁ "" + d + "" ▁ is ▁ "" ) ; System . out . print ( leftRotate ( n , d ) ) ; System . out . print ( "" \n Right ▁ Rotation ▁ of ▁ "" + n + "" ▁ by ▁ "" + d + "" ▁ is ▁ "" ) ; System . out . print ( rightRotate ( n , d ) ) ; } } ","INT_BITS = 32 NEW_LINE def leftRotate ( n , d ) : NEW_LINE INDENT return ( n << d ) | ( n >> ( INT_BITS - d ) ) NEW_LINE DEDENT def rightRotate ( n , d ) : NEW_LINE INDENT return ( n >> d ) | ( n << ( INT_BITS - d ) ) & 0xFFFFFFFF NEW_LINE DEDENT n = 16 NEW_LINE d = 2 NEW_LINE print ( "" Left ▁ Rotation ▁ of "" , n , "" by "" , d , "" is "" , end = "" ▁ "" ) NEW_LINE print ( leftRotate ( n , d ) ) NEW_LINE print ( "" Right ▁ Rotation ▁ of "" , n , "" by "" , d , "" is "" , end = "" ▁ "" ) NEW_LINE print ( rightRotate ( n , d ) ) NEW_LINE " V816,"import java . lang . Math ; class GFG { static float Area ( float r ) { if ( r < 0 ) return - 1 ; float x = ( 2 * r ) / ( float ) ( Math . sqrt ( 5 ) ) ; float A = 0.70477f * ( float ) ( Math . pow ( x , 2 ) ) ; return A ; } public static void main ( String [ ] args ) { float r = 5 ; System . out . println ( Area ( r ) ) ; } } ","import math as mt NEW_LINE def Area ( r ) : NEW_LINE INDENT if ( r < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT x = ( 2 * r ) / mt . sqrt ( 5 ) NEW_LINE A = 0.70477 * pow ( x , 2 ) NEW_LINE return A NEW_LINE DEDENT r = 5 NEW_LINE print ( Area ( r ) ) NEW_LINE " V817,"import java . io . * ; class GFG { static int maxLength ( String s , int n ) { int invalidOpenBraces = 0 ; int invalidCloseBraces = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' ( ' ) { invalidOpenBraces ++ ; } else { if ( invalidOpenBraces == 0 ) { invalidCloseBraces ++ ; } else { invalidOpenBraces -- ; } } } return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ; } public static void main ( String [ ] args ) { String s = "" ( ) ( ( ( ( ( ( ) "" ; int n = s . length ( ) ; System . out . println ( maxLength ( s , n ) ) ; } } ","def maxLength ( s , n ) : NEW_LINE INDENT invalidOpenBraces = 0 ; NEW_LINE invalidCloseBraces = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == ' ( ' ) : NEW_LINE INDENT invalidOpenBraces += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( invalidOpenBraces == 0 ) : NEW_LINE INDENT invalidCloseBraces += 1 NEW_LINE DEDENT else : NEW_LINE INDENT invalidOpenBraces -= 1 NEW_LINE DEDENT DEDENT DEDENT return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) NEW_LINE DEDENT s = "" ( ) ( ( ( ( ( ( ) "" NEW_LINE n = len ( s ) NEW_LINE print ( maxLength ( s , n ) ) NEW_LINE " V818,"import java . io . * ; class GFG { static int count_odd_pair ( int n , int a [ ] ) { int odd = 0 , even = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } int ans = odd * ( odd - 1 ) ; return ans ; } static int count_even_pair ( int odd_product_pairs , int n ) { int total_pairs = ( n * ( n - 1 ) ) ; int ans = total_pairs - odd_product_pairs ; return ans ; } public static void main ( String [ ] args ) { int n = 6 ; int [ ] a = { 2 , 4 , 5 , 9 , 1 , 8 } ; int odd_product_pairs = count_odd_pair ( n , a ) ; int even_product_pairs = count_even_pair ( odd_product_pairs , n ) ; System . out . println ( "" Even ▁ Product ▁ Pairs ▁ = ▁ "" + even_product_pairs ) ; System . out . println ( "" Odd ▁ Product ▁ Pairs = ▁ "" + odd_product_pairs ) ; } } ","def count_odd_pair ( n , a ) : NEW_LINE INDENT odd = 0 NEW_LINE even = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if a [ i ] % 2 == 0 : NEW_LINE INDENT even = even + 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd = odd + 1 NEW_LINE DEDENT DEDENT ans = odd * ( odd - 1 ) NEW_LINE return ans NEW_LINE DEDENT def count_even_pair ( odd_product_pairs , n ) : NEW_LINE INDENT total_pairs = ( n * ( n - 1 ) ) NEW_LINE ans = total_pairs - odd_product_pairs NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE a = [ 2 , 4 , 5 , 9 , 1 , 8 ] NEW_LINE odd_product_pairs = count_odd_pair ( n , a ) NEW_LINE even_product_pairs = ( count_even_pair ( odd_product_pairs , n ) ) NEW_LINE print ( "" Even ▁ Product ▁ Pairs ▁ = ▁ "" , even_product_pairs ) NEW_LINE print ( "" Odd ▁ Product ▁ Pairs = ▁ "" , odd_product_pairs ) NEW_LINE DEDENT " V819,"class GFG { static int isPowerOfFour ( int n ) { if ( n == 0 ) return 0 ; while ( n != 1 ) { if ( n % 4 != 0 ) return 0 ; n = n / 4 ; } return 1 ; } public static void main ( String [ ] args ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) == 1 ) 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 if ( n == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT while ( n != 1 ) : NEW_LINE INDENT if ( n % 4 != 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT n = n // 4 NEW_LINE DEDENT return True NEW_LINE 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 " V820,"import java . io . * ; class GFG { static boolean isDivisible ( long n ) { while ( n / 100 > 0 ) { long d = n % 10 ; n /= 10 ; n -= d * 5 ; } return ( n % 17 == 0 ) ; } public static void main ( String [ ] args ) { long n = 19877658 ; if ( isDivisible ( n ) ) System . out . println ( "" Yes "" ) ; else System . out . println ( "" No "" ) ; } } ","def isDivisible ( n ) : NEW_LINE INDENT while ( n // 100 ) : NEW_LINE INDENT d = n % 10 NEW_LINE n //= 10 NEW_LINE n -= d * 5 NEW_LINE DEDENT return ( n % 17 == 0 ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT n = 19877658 NEW_LINE if isDivisible ( n ) : NEW_LINE INDENT print ( "" Yes "" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "" No "" ) NEW_LINE DEDENT DEDENT " V821,"public final class p191 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p191 ( ) . run ( ) ) ; } private static final int NUM_DAYS = 30 ; private static final int MAX_ABSENT = 2 ; private static final int MAX_LATE = 1 ; public String run ( ) { long [ ] [ ] [ ] numPrizeStrings = new long [ NUM_DAYS + 1 ] [ MAX_ABSENT + 1 ] [ MAX_LATE + 1 ] ; numPrizeStrings [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= NUM_DAYS ; i ++ ) { for ( int j = 0 ; j <= MAX_ABSENT ; j ++ ) { for ( int k = 0 ; k <= MAX_LATE ; k ++ ) { long sum ; if ( j == 0 ) { sum = 0 ; for ( int l = 0 ; l <= MAX_ABSENT ; l ++ ) sum += numPrizeStrings [ i - 1 ] [ l ] [ k ] ; if ( k > 0 ) { for ( int l = 0 ; l <= MAX_ABSENT ; l ++ ) sum += numPrizeStrings [ i - 1 ] [ l ] [ k - 1 ] ; } } else sum = numPrizeStrings [ i - 1 ] [ j - 1 ] [ k ] ; numPrizeStrings [ i ] [ j ] [ k ] = sum ; } } } long sum = 0 ; for ( int j = 0 ; j <= MAX_ABSENT ; j ++ ) { for ( int k = 0 ; k <= MAX_LATE ; k ++ ) sum += numPrizeStrings [ NUM_DAYS ] [ j ] [ k ] ; } return Long . toString ( sum ) ; } } ","def compute ( ) : NEW_LINE INDENT NUM_DAYS = 30 NEW_LINE MAX_ABSENT = 2 NEW_LINE MAX_LATE = 1 NEW_LINE num_prize_strings = create_nested_lists ( 0 , NUM_DAYS + 1 , MAX_ABSENT + 1 , MAX_LATE + 1 ) NEW_LINE num_prize_strings [ 0 ] [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , len ( num_prize_strings ) ) : NEW_LINE INDENT for j in range ( len ( num_prize_strings [ i ] ) ) : NEW_LINE INDENT for k in range ( len ( num_prize_strings [ i ] [ j ] ) ) : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT s = 0 NEW_LINE for l in range ( MAX_ABSENT + 1 ) : NEW_LINE INDENT s += num_prize_strings [ i - 1 ] [ l ] [ k ] NEW_LINE DEDENT if k > 0 : NEW_LINE INDENT for l in range ( MAX_ABSENT + 1 ) : NEW_LINE INDENT s += num_prize_strings [ i - 1 ] [ l ] [ k - 1 ] NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT s = num_prize_strings [ i - 1 ] [ j - 1 ] [ k ] NEW_LINE DEDENT num_prize_strings [ i ] [ j ] [ k ] = s NEW_LINE DEDENT DEDENT DEDENT ans = sum ( map ( sum , num_prize_strings [ NUM_DAYS ] ) ) NEW_LINE return str ( ans ) NEW_LINE DEDENT def create_nested_lists ( value , * dimensions ) : NEW_LINE INDENT if len ( dimensions ) == 0 : NEW_LINE INDENT raise ValueError ( ) NEW_LINE DEDENT elif len ( dimensions ) == 1 : NEW_LINE INDENT return [ value ] * dimensions [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT return [ create_nested_lists ( value , * dimensions [ 1 : ] ) for _ in range ( dimensions [ 0 ] ) ] NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V822,"public final class p044 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p044 ( ) . run ( ) ) ; } public String run ( ) { long minD = - 1 ; for ( int i = 2 ; ; i ++ ) { long pentI = pentagonalNumber ( i ) ; if ( minD != - 1 && pentI - pentagonalNumber ( i - 1 ) >= minD ) break ; for ( int j = i - 1 ; j >= 1 ; j -- ) { long pentJ = pentagonalNumber ( j ) ; long diff = pentI - pentJ ; if ( minD != - 1 && diff >= minD ) break ; else if ( isPentagonalNumber ( pentI + pentJ ) && isPentagonalNumber ( diff ) ) minD = diff ; } } return Long . toString ( minD ) ; } private static long pentagonalNumber ( int x ) { if ( x <= 0 ) throw new IllegalArgumentException ( ) ; return ( long ) x * ( x * 3 - 1 ) >>> 1 ; } private static boolean isPentagonalNumber ( long y ) { if ( y <= 0 ) return false ; long temp = y * 24 + 1 ; long sqrt = Library . sqrt ( temp ) ; return sqrt * sqrt == temp && sqrt % 6 == 5 ; } } ","import itertools NEW_LINE def compute ( ) : NEW_LINE INDENT pentanum = PentagonalNumberHelper ( ) NEW_LINE min_d = None NEW_LINE for i in itertools . count ( 2 ) : NEW_LINE INDENT pent_i = pentanum . term ( i ) NEW_LINE if min_d is not None and pent_i - pentanum . term ( i - 1 ) >= min_d : NEW_LINE INDENT break NEW_LINE DEDENT for j in range ( i - 1 , 0 , - 1 ) : NEW_LINE INDENT pent_j = pentanum . term ( j ) NEW_LINE diff = pent_i - pent_j NEW_LINE if min_d is not None and diff >= min_d : NEW_LINE INDENT break NEW_LINE DEDENT elif pentanum . is_term ( pent_i + pent_j ) and pentanum . is_term ( diff ) : NEW_LINE INDENT min_d = diff NEW_LINE DEDENT DEDENT DEDENT return str ( min_d ) NEW_LINE DEDENT class PentagonalNumberHelper : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . term_list = [ 0 ] NEW_LINE self . term_set = set ( ) NEW_LINE DEDENT def term ( self , x ) : NEW_LINE INDENT assert x > 0 NEW_LINE while len ( self . term_list ) <= x : NEW_LINE INDENT n = len ( self . term_list ) NEW_LINE term = ( n * ( n * 3 - 1 ) ) >> 1 NEW_LINE self . term_list . append ( term ) NEW_LINE self . term_set . add ( term ) NEW_LINE DEDENT return self . term_list [ x ] NEW_LINE DEDENT def is_term ( self , y ) : NEW_LINE INDENT assert y > 0 NEW_LINE while self . term_list [ - 1 ] < y : NEW_LINE INDENT n = len ( self . term_list ) NEW_LINE term = ( n * ( n * 3 - 1 ) ) >> 1 NEW_LINE self . term_list . append ( term ) NEW_LINE self . term_set . add ( term ) NEW_LINE DEDENT return y in self . term_set NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V823,"public final class p021 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p021 ( ) . run ( ) ) ; } public String run ( ) { int sum = 0 ; for ( int i = 1 ; i < 10000 ; i ++ ) { if ( isAmicable ( i ) ) sum += i ; } return Integer . toString ( sum ) ; } private static boolean isAmicable ( int n ) { int m = divisorSum ( n ) ; return m != n && divisorSum ( m ) == n ; } private static int divisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( n % i == 0 ) sum += i ; } return sum ; } } ","def compute ( ) : NEW_LINE INDENT divisorsum = [ 0 ] * 10000 NEW_LINE for i in range ( 1 , len ( divisorsum ) ) : NEW_LINE INDENT for j in range ( i * 2 , len ( divisorsum ) , i ) : NEW_LINE INDENT divisorsum [ j ] += i NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for i in range ( 1 , len ( divisorsum ) ) : NEW_LINE INDENT j = divisorsum [ i ] NEW_LINE if j != i and j < len ( divisorsum ) and divisorsum [ j ] == i : NEW_LINE INDENT ans += i NEW_LINE DEDENT DEDENT return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V824,"import java . util . Arrays ; public final class p122 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p122 ( ) . run ( ) ) ; } private static final int LIMIT = 200 ; private int [ ] minOperations ; private int numUnknown ; public String run ( ) { minOperations = new int [ LIMIT + 1 ] ; Arrays . fill ( minOperations , - 1 ) ; minOperations [ 0 ] = 0 ; minOperations [ 1 ] = 0 ; numUnknown = LIMIT - 1 ; for ( int ops = 1 ; numUnknown > 0 ; ops ++ ) { IntStack chain = new IntStack ( ops + 1 ) ; chain . push ( 1 ) ; exploreChains ( chain , ops ) ; } int sum = 0 ; for ( int x : minOperations ) sum += x ; return Integer . toString ( sum ) ; } private void exploreChains ( IntStack chain , int maxOps ) { if ( chain . size > maxOps || numUnknown == 0 ) return ; int max = chain . values [ chain . size - 1 ] ; for ( int i = chain . size - 1 ; i >= 0 ; i -- ) { for ( int j = i ; j >= 0 ; j -- ) { int x = chain . values [ i ] + chain . values [ j ] ; if ( x <= max ) break ; if ( x <= LIMIT ) { chain . push ( x ) ; if ( minOperations [ x ] == - 1 ) { minOperations [ x ] = chain . size - 1 ; numUnknown -- ; } exploreChains ( chain , maxOps ) ; chain . pop ( ) ; } } } } private static final class IntStack { public int [ ] values ; public int size ; public IntStack ( int capacity ) { values = new int [ capacity ] ; size = 0 ; } public void push ( int x ) { if ( size >= values . length ) throw new IllegalStateException ( ) ; values [ size ] = x ; size ++ ; } public int pop ( ) { if ( size <= 0 ) throw new IllegalStateException ( ) ; size -- ; return values [ size ] ; } } } ","import itertools NEW_LINE def compute ( ) : NEW_LINE INDENT LIMIT = 200 NEW_LINE minoperations = [ 0 , 0 ] + [ None ] * ( LIMIT - 1 ) NEW_LINE numunknown = [ LIMIT - 1 ] NEW_LINE def explore_chains ( chain , maxops ) : NEW_LINE INDENT if len ( chain ) > maxops or numunknown [ 0 ] == 0 : NEW_LINE INDENT return NEW_LINE DEDENT max = chain [ - 1 ] NEW_LINE for i in reversed ( range ( len ( chain ) ) ) : NEW_LINE INDENT for j in reversed ( range ( i + 1 ) ) : NEW_LINE INDENT x = chain [ i ] + chain [ j ] NEW_LINE if x <= max : NEW_LINE INDENT break NEW_LINE DEDENT if x <= LIMIT : NEW_LINE INDENT chain . append ( x ) NEW_LINE if minoperations [ x ] is None : NEW_LINE INDENT minoperations [ x ] = len ( chain ) - 1 NEW_LINE numunknown [ 0 ] -= 1 NEW_LINE DEDENT explore_chains ( chain , maxops ) NEW_LINE chain . pop ( ) NEW_LINE DEDENT DEDENT DEDENT DEDENT for ops in itertools . count ( 1 ) : NEW_LINE INDENT if numunknown [ 0 ] == 0 : NEW_LINE INDENT return str ( sum ( minoperations ) ) NEW_LINE DEDENT explore_chains ( [ 1 ] , ops ) NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V825,"public final class p004 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p004 ( ) . run ( ) ) ; } public String run ( ) { int maxPalin = - 1 ; for ( int i = 100 ; i < 1000 ; i ++ ) { for ( int j = 100 ; j < 1000 ; j ++ ) { int prod = i * j ; if ( Library . isPalindrome ( prod ) && prod > maxPalin ) maxPalin = prod ; } } return Integer . toString ( maxPalin ) ; } } ","def compute ( ) : NEW_LINE INDENT ans = max ( i * j for i in range ( 100 , 1000 ) for j in range ( 100 , 1000 ) if str ( i * j ) == str ( i * j ) [ : : - 1 ] ) NEW_LINE return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V826,"public final class p216 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p216 ( ) . run ( ) ) ; } private static final int LIMIT = 50000000 ; public String run ( ) { long [ ] sequence = new long [ LIMIT + 1 ] ; sequence [ 0 ] = sequence [ 1 ] = - 1 ; for ( int i = 2 ; i < sequence . length ; i ++ ) sequence [ i ] = 2L * i * i - 1 ; int count = 0 ; for ( int i = 2 ; i < sequence . length ; i ++ ) { long term = sequence [ i ] ; if ( term == 2L * i * i - 1 ) count ++ ; if ( 1 < term && term <= LIMIT * 2 ) { int p = ( int ) term ; for ( int j = i + p ; j < sequence . length ; j += p ) { assert sequence [ j ] % p == 0 ; do sequence [ j ] /= p ; while ( sequence [ j ] % p == 0 ) ; } for ( int j = i + ( p - i ) * 2 % p ; j < sequence . length ; j += p ) { assert sequence [ j ] % p == 0 ; do sequence [ j ] /= p ; while ( sequence [ j ] % p == 0 ) ; } } } return Integer . toString ( count ) ; } } ","def compute ( ) : NEW_LINE INDENT LIMIT = 50000000 NEW_LINE sequence = [ ( 2 * i * i - 1 ) for i in range ( LIMIT + 1 ) ] NEW_LINE sequence [ 0 ] = sequence [ 1 ] = - 1 NEW_LINE ans = 0 NEW_LINE for ( i , term ) in enumerate ( sequence ) : NEW_LINE INDENT if i < 2 : NEW_LINE INDENT continue NEW_LINE DEDENT if term == 2 * i * i - 1 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT if 1 < term <= LIMIT * 2 : NEW_LINE INDENT p = term NEW_LINE for j in range ( i + p , LIMIT + 1 , p ) : NEW_LINE INDENT while True : NEW_LINE INDENT sequence [ j ] //= p NEW_LINE if sequence [ j ] % p != 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT for j in range ( i + ( p - i ) * 2 % p , LIMIT + 1 , p ) : NEW_LINE INDENT while True : NEW_LINE INDENT sequence [ j ] //= p NEW_LINE if sequence [ j ] % p != 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V827,"public final class p009 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p009 ( ) . run ( ) ) ; } private static final int PERIMETER = 1000 ; public String run ( ) { for ( int a = 1 ; a < PERIMETER ; a ++ ) { for ( int b = a + 1 ; b < PERIMETER ; b ++ ) { int c = PERIMETER - a - b ; if ( a * a + b * b == c * c ) { return Integer . toString ( a * b * c ) ; } } } throw new AssertionError ( "" Not ▁ found "" ) ; } } ","def compute ( ) : NEW_LINE INDENT PERIMETER = 1000 NEW_LINE for a in range ( 1 , PERIMETER + 1 ) : NEW_LINE INDENT for b in range ( a + 1 , PERIMETER + 1 ) : NEW_LINE INDENT c = PERIMETER - a - b NEW_LINE if a * a + b * b == c * c : NEW_LINE INDENT return str ( a * b * c ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V828,"public final class p040 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p040 ( ) . run ( ) ) ; } public String run ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 1 ; i < 1000000 ; i ++ ) sb . append ( i ) ; int prod = 1 ; for ( int i = 0 ; i <= 6 ; i ++ ) prod *= sb . charAt ( Library . pow ( 10 , i ) - 1 ) - '0' ; return Integer . toString ( prod ) ; } } ","def compute ( ) : NEW_LINE INDENT s = "" "" . join ( str ( i ) for i in range ( 1 , 1000000 ) ) NEW_LINE ans = 1 NEW_LINE for i in range ( 7 ) : NEW_LINE INDENT ans *= int ( s [ 10 ** i - 1 ] ) NEW_LINE DEDENT return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V829,"import java . math . BigInteger ; public final class p014 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p014 ( ) . run ( ) ) ; } private static final int LIMIT = Library . pow ( 10 , 6 ) ; public String run ( ) { int maxArg = - 1 ; int maxChain = 0 ; for ( int i = 1 ; i < LIMIT ; i ++ ) { int chainLen = collatzChainLength ( BigInteger . valueOf ( i ) ) ; if ( chainLen > maxChain ) { maxArg = i ; maxChain = chainLen ; } } return Integer . toString ( maxArg ) ; } private static final BigInteger CACHE_SIZE = BigInteger . valueOf ( LIMIT ) ; private int [ ] collatzChainLength = new int [ CACHE_SIZE . intValue ( ) ] ; private int collatzChainLength ( BigInteger n ) { if ( n . signum ( ) < 0 ) throw new IllegalArgumentException ( ) ; if ( n . compareTo ( CACHE_SIZE ) >= 0 ) return collatzChainLengthDirect ( n ) ; int index = n . intValue ( ) ; if ( collatzChainLength [ index ] == 0 ) collatzChainLength [ index ] = collatzChainLengthDirect ( n ) ; return collatzChainLength [ index ] ; } private int collatzChainLengthDirect ( BigInteger n ) { if ( n . equals ( BigInteger . ONE ) ) return 1 ; else if ( ! n . testBit ( 0 ) ) return collatzChainLength ( n . shiftRight ( 1 ) ) + 1 ; else return collatzChainLength ( n . multiply ( BigInteger . valueOf ( 3 ) ) . add ( BigInteger . ONE ) ) + 1 ; } } ","import eulerlib , sys NEW_LINE def compute ( ) : NEW_LINE INDENT sys . setrecursionlimit ( 3000 ) NEW_LINE ans = max ( range ( 1 , 1000000 ) , key = collatz_chain_length ) NEW_LINE return str ( ans ) NEW_LINE DEDENT @ eulerlib . memoize NEW_LINE def collatz_chain_length ( x ) : NEW_LINE INDENT if x == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if x % 2 == 0 : NEW_LINE INDENT y = x // 2 NEW_LINE DEDENT else : NEW_LINE INDENT y = x * 3 + 1 NEW_LINE DEDENT return collatz_chain_length ( y ) + 1 NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V830,"import java . math . BigInteger ; import java . util . HashSet ; import java . util . Set ; public final class p203 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p203 ( ) . run ( ) ) ; } public String run ( ) { Set < Long > numbers = new HashSet < > ( ) ; long max = 0 ; for ( int n = 0 ; n <= 50 ; n ++ ) { for ( int k = 0 ; k <= n ; k ++ ) { BigInteger x = Library . binomial ( n , k ) ; if ( x . bitLength ( ) >= 64 ) throw new AssertionError ( "" Number ▁ too ▁ large ▁ to ▁ handle "" ) ; numbers . add ( x . longValue ( ) ) ; max = Math . max ( x . longValue ( ) , max ) ; } } int [ ] primes = Library . listPrimes ( ( int ) Library . sqrt ( max ) ) ; primesSquared = new long [ primes . length ] ; for ( int i = 0 ; i < primes . length ; i ++ ) primesSquared [ i ] = ( long ) primes [ i ] * primes [ i ] ; long sum = 0 ; for ( long n : numbers ) { if ( isSquarefree ( n ) ) sum += n ; } return Long . toString ( sum ) ; } private long [ ] primesSquared ; private boolean isSquarefree ( long n ) { for ( long p2 : primesSquared ) { if ( p2 > n ) break ; if ( n % p2 == 0 ) return false ; } return true ; } } ","import eulerlib NEW_LINE def compute ( ) : NEW_LINE INDENT numbers = set ( eulerlib . binomial ( n , k ) for n in range ( 51 ) for k in range ( n + 1 ) ) NEW_LINE maximum = max ( numbers ) NEW_LINE primes = eulerlib . list_primes ( eulerlib . sqrt ( maximum ) ) NEW_LINE primessquared = [ p * p for p in primes ] NEW_LINE def is_squarefree ( n ) : NEW_LINE INDENT for p2 in primessquared : NEW_LINE INDENT if p2 > n : NEW_LINE INDENT break NEW_LINE DEDENT if n % p2 == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT ans = sum ( n for n in numbers if is_squarefree ( n ) ) NEW_LINE return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V831,"import java . math . BigInteger ; public final class p080 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p080 ( ) . run ( ) ) ; } public String run ( ) { int sum = 0 ; for ( int i = 1 ; i <= 100 ; i ++ ) { BigInteger x = BigInteger . valueOf ( i ) ; x = x . multiply ( BigInteger . TEN . pow ( 100 * 2 ) ) ; BigInteger y = sqrt ( x ) ; if ( ! y . multiply ( y ) . equals ( x ) ) { String s = y . toString ( ) . substring ( 0 , 100 ) ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) sum += s . charAt ( j ) - '0' ; } } return Integer . toString ( sum ) ; } private static BigInteger sqrt ( BigInteger x ) { int i = 0 ; while ( BigInteger . TEN . pow ( i * 2 ) . compareTo ( x ) <= 0 ) i ++ ; BigInteger y = BigInteger . ZERO ; for ( ; i >= 0 ; i -- ) { int j ; BigInteger delta = null ; for ( j = 9 ; j >= 0 ; j -- ) { BigInteger temp = BigInteger . valueOf ( j ) . multiply ( BigInteger . TEN . pow ( i ) ) ; delta = y . shiftLeft ( 1 ) . add ( temp ) . multiply ( temp ) ; if ( delta . compareTo ( x ) <= 0 ) break ; } if ( j < 0 ) throw new AssertionError ( ) ; x = x . subtract ( delta ) ; y = y . add ( BigInteger . valueOf ( j ) . multiply ( BigInteger . TEN . pow ( i ) ) ) ; } return y ; } } ","import eulerlib NEW_LINE def compute ( ) : NEW_LINE INDENT DIGITS = 100 NEW_LINE MULTIPLIER = 100 ** DIGITS NEW_LINE ans = sum ( sum ( int ( c ) for c in str ( eulerlib . sqrt ( i * MULTIPLIER ) ) [ : DIGITS ] ) for i in range ( 100 ) if eulerlib . sqrt ( i ) ** 2 != i ) NEW_LINE return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V832,"public final class p039 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p039 ( ) . run ( ) ) ; } public String run ( ) { int maxPerimeter = 0 ; int maxTriangles = 0 ; for ( int p = 1 ; p <= 1000 ; p ++ ) { int triangles = countSolutions ( p ) ; if ( triangles > maxTriangles ) { maxTriangles = triangles ; maxPerimeter = p ; } } return Integer . toString ( maxPerimeter ) ; } private static int countSolutions ( int p ) { int count = 0 ; for ( int a = 1 ; a <= p ; a ++ ) { for ( int b = a ; b <= p ; b ++ ) { int c = p - a - b ; if ( b <= c && a * a + b * b == c * c ) count ++ ; } } return count ; } } ","def compute ( ) : NEW_LINE INDENT ans = max ( range ( 1 , 1001 ) , key = count_solutions ) NEW_LINE return str ( ans ) NEW_LINE DEDENT def count_solutions ( p ) : NEW_LINE INDENT result = 0 NEW_LINE for a in range ( 1 , p + 1 ) : NEW_LINE INDENT for b in range ( a , ( p - a ) // 2 + 1 ) : NEW_LINE INDENT c = p - a - b NEW_LINE if a * a + b * b == c * c : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V833,"public final class p549 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p549 ( ) . run ( ) ) ; } private static final int LIMIT = Library . pow ( 10 , 8 ) ; public String run ( ) { int [ ] smallestDivisibleFactorials = new int [ LIMIT + 1 ] ; for ( int i = 2 ; i < smallestDivisibleFactorials . length ; i ++ ) { if ( smallestDivisibleFactorials [ i ] == 0 ) { long power = 1 ; middle : for ( int j = i ; ; j += i ) { power *= i ; if ( power > LIMIT ) break ; for ( int inc = ( int ) power , k = inc ; k < smallestDivisibleFactorials . length ; k += inc ) smallestDivisibleFactorials [ k ] = Math . max ( j , smallestDivisibleFactorials [ k ] ) ; for ( int temp = j / i ; temp % i == 0 ; temp /= i ) { power *= i ; if ( power > LIMIT ) break middle ; } } } } long sum = 0 ; for ( int x : smallestDivisibleFactorials ) sum += x ; return Long . toString ( sum ) ; } } ","import itertools NEW_LINE def compute ( ) : NEW_LINE INDENT LIMIT = 10 ** 8 NEW_LINE smallestdivisiblefactorials = [ 0 ] * ( LIMIT + 1 ) NEW_LINE for i in range ( 2 , len ( smallestdivisiblefactorials ) ) : NEW_LINE INDENT if smallestdivisiblefactorials [ i ] == 0 : NEW_LINE INDENT power = 1 NEW_LINE for j in itertools . count ( i , i ) : NEW_LINE INDENT power *= i NEW_LINE if power > LIMIT : NEW_LINE INDENT break NEW_LINE DEDENT for k in range ( power , len ( smallestdivisiblefactorials ) , power ) : NEW_LINE INDENT smallestdivisiblefactorials [ k ] = max ( j , smallestdivisiblefactorials [ k ] ) NEW_LINE DEDENT temp = j // i NEW_LINE while temp % i == 0 : NEW_LINE INDENT power *= i NEW_LINE temp //= i NEW_LINE DEDENT DEDENT DEDENT DEDENT ans = sum ( smallestdivisiblefactorials ) NEW_LINE return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V834,"public final class p132 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p132 ( ) . run ( ) ) ; } public String run ( ) { int sum = 0 ; int count = 0 ; for ( int i = 2 ; count < 40 ; i ++ ) { if ( Library . isPrime ( i ) && repunitMod ( 1000000000 , i ) == 0 ) { sum += i ; count ++ ; } } return Integer . toString ( sum ) ; } private static int repunitMod ( int k , int m ) { return ( Library . powMod ( 10 , k , m * 9 ) - 1 ) / 9 ; } } ","import eulerlib , itertools NEW_LINE def compute ( ) : NEW_LINE INDENT cond = lambda i : eulerlib . is_prime ( i ) and repunit_mod ( 10 ** 9 , i ) == 0 NEW_LINE ans = sum ( itertools . islice ( filter ( cond , itertools . count ( 2 ) ) , 40 ) ) NEW_LINE return str ( ans ) NEW_LINE DEDENT def repunit_mod ( k , m ) : NEW_LINE INDENT return ( pow ( 10 , k , m * 9 ) - 1 ) // 9 NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V835,"import java . math . BigInteger ; public final class p005 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p005 ( ) . run ( ) ) ; } public String run ( ) { BigInteger allLcm = BigInteger . ONE ; for ( int i = 1 ; i <= 20 ; i ++ ) allLcm = lcm ( BigInteger . valueOf ( i ) , allLcm ) ; return allLcm . toString ( ) ; } private static BigInteger lcm ( BigInteger x , BigInteger y ) { return x . divide ( x . gcd ( y ) ) . multiply ( y ) ; } } ","import fractions NEW_LINE def compute ( ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( 1 , 21 ) : NEW_LINE INDENT ans *= i // fractions . gcd ( i , ans ) NEW_LINE DEDENT return str ( ans ) NEW_LINE DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V836,"import java . math . BigInteger ; public final class p178 implements EulerSolution { public static void main ( String [ ] args ) { System . out . println ( new p178 ( ) . run ( ) ) ; } private static final int LIMIT = 40 ; public String run ( ) { BigInteger [ ] [ ] [ ] [ ] ways = new BigInteger [ LIMIT + 1 ] [ 10 ] [ 10 ] [ 10 ] ; BigInteger sum = BigInteger . ZERO ; for ( int digits = 0 ; digits < ways . length ; digits ++ ) { for ( int head = 0 ; head < 10 ; head ++ ) { for ( int low = 0 ; low < 10 ; low ++ ) { for ( int high = 0 ; high < 10 ; high ++ ) { BigInteger val ; if ( digits <= 1 ) val = ( low == head && head == high ) ? BigInteger . ONE : BigInteger . ZERO ; else { val = BigInteger . ZERO ; BigInteger [ ] [ ] [ ] prevWays = ways [ digits - 1 ] ; if ( head - 1 >= low ) { val = val . add ( prevWays [ head - 1 ] [ low ] [ high ] ) ; if ( head == high ) val = val . add ( prevWays [ head - 1 ] [ low ] [ high - 1 ] ) ; } if ( head + 1 <= high ) { val = val . add ( prevWays [ head + 1 ] [ low ] [ high ] ) ; if ( head == low ) val = val . add ( prevWays [ head + 1 ] [ low + 1 ] [ high ] ) ; } } ways [ digits ] [ head ] [ low ] [ high ] = val ; if ( head > 0 && low == 0 && high == 9 ) sum = sum . add ( val ) ; } } } } return sum . toString ( ) ; } } ","import eulerlib NEW_LINE def compute ( ) : NEW_LINE INDENT LIMIT = 40 NEW_LINE ans = sum ( count_step_pandigital ( digits , head , 0 , 9 ) for digits in range ( LIMIT + 1 ) for head in range ( 1 , 10 ) ) NEW_LINE return str ( ans ) NEW_LINE DEDENT @ eulerlib . memoize NEW_LINE def count_step_pandigital ( digits , head , low , high ) : NEW_LINE INDENT assert digits >= 0 NEW_LINE assert low <= head <= high NEW_LINE if digits <= 1 : NEW_LINE INDENT return 1 if ( low == head == high ) else 0 NEW_LINE DEDENT else : NEW_LINE INDENT result = 0 NEW_LINE if head - 1 >= low : NEW_LINE INDENT result += count_step_pandigital ( digits - 1 , head - 1 , low , high ) NEW_LINE if head == high : NEW_LINE INDENT result += count_step_pandigital ( digits - 1 , head - 1 , low , high - 1 ) NEW_LINE DEDENT DEDENT if head + 1 <= high : NEW_LINE INDENT result += count_step_pandigital ( digits - 1 , head + 1 , low , high ) NEW_LINE if head == low : NEW_LINE INDENT result += count_step_pandigital ( digits - 1 , head + 1 , low + 1 , high ) NEW_LINE DEDENT DEDENT assert 0 <= result < 10 ** digits NEW_LINE return result NEW_LINE DEDENT DEDENT if __name__ == "" _ _ main _ _ "" : NEW_LINE INDENT print ( compute ( ) ) NEW_LINE DEDENT " V837,"class Solution { public boolean isToeplitzMatrix ( int [ ] [ ] matrix ) { for ( int r = 1 ; r < matrix . length ; ++ r ) for ( int c = 1 ; c < matrix [ 0 ] . length ; ++ c ) if ( matrix [ r - 1 ] [ c - 1 ] != matrix [ r ] [ c ] ) return false ; return true ; } } ","class Solution ( object ) : NEW_LINE INDENT def isToeplitzMatrix ( self , matrix ) : NEW_LINE INDENT for r in range ( len ( matrix ) - 1 ) : NEW_LINE INDENT for c in range ( len ( matrix [ 0 ] ) - 1 ) : NEW_LINE INDENT if matrix [ r ] [ c ] != matrix [ r + 1 ] [ c + 1 ] : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT DEDENT " V838,"class Solution { public int findKthLargest ( int [ ] nums , int k ) { shuffle ( nums ) ; k = nums . length - k ; int lo = 0 ; int hi = nums . length - 1 ; while ( lo < hi ) { final int j = partition ( nums , lo , hi ) ; if ( j < k ) { lo = j + 1 ; } else if ( j > k ) { hi = j - 1 ; } else { break ; } } return nums [ k ] ; } private int partition ( int [ ] a , int lo , int hi ) { int i = lo ; int j = hi + 1 ; while ( true ) { while ( i < hi && less ( a [ ++ i ] , a [ lo ] ) ) ; while ( j > lo && less ( a [ lo ] , a [ -- j ] ) ) ; if ( i >= j ) { break ; } exch ( a , i , j ) ; } exch ( a , lo , j ) ; return j ; } private void exch ( int [ ] a , int i , int j ) { final int tmp = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = tmp ; } private boolean less ( int v , int w ) { return v < w ; } private void shuffle ( int a [ ] ) { final Random random = new Random ( ) ; for ( int ind = 1 ; ind < a . length ; ind ++ ) { final int r = random . nextInt ( ind + 1 ) ; exch ( a , ind , r ) ; } } } ","class Solution ( object ) : NEW_LINE INDENT def findKthLargest ( self , nums , k ) : NEW_LINE INDENT random . shuffle ( nums ) NEW_LINE return self . quickSelection ( nums , 0 , len ( nums ) - 1 , len ( nums ) - k ) NEW_LINE DEDENT def quickSelection ( self , nums , start , end , k ) : NEW_LINE INDENT if start > end : NEW_LINE INDENT return float ( ' inf ' ) NEW_LINE DEDENT pivot = nums [ end ] NEW_LINE left = start NEW_LINE for i in range ( start , end ) : NEW_LINE INDENT if nums [ i ] <= pivot : NEW_LINE INDENT nums [ left ] , nums [ i ] = nums [ i ] , nums [ left ] NEW_LINE left += 1 NEW_LINE DEDENT DEDENT nums [ left ] , nums [ end ] = nums [ end ] , nums [ left ] NEW_LINE if left == k : NEW_LINE INDENT return nums [ left ] NEW_LINE DEDENT elif left < k : NEW_LINE INDENT return self . quickSelection ( nums , left + 1 , end , k ) NEW_LINE DEDENT else : NEW_LINE INDENT return self . quickSelection ( nums , start , left - 1 , k ) NEW_LINE DEDENT DEDENT DEDENT " V839,"class KthLargest { final PriorityQueue < Integer > q ; final int k ; public KthLargest ( int k , int [ ] nums ) { this . k = k ; q = new PriorityQueue < > ( k ) ; for ( int val : nums ) add ( val ) ; } public int add ( int val ) { if ( q . size ( ) < k ) q . offer ( val ) ; else if ( q . peek ( ) < val ) { q . poll ( ) ; q . offer ( val ) ; } return q . peek ( ) ; } } ","class KthLargest ( object ) : NEW_LINE INDENT def __init__ ( self , k , nums ) : NEW_LINE INDENT self . nums = nums NEW_LINE self . k = k NEW_LINE heapq . heapify ( self . nums ) NEW_LINE while len ( self . nums ) > k : NEW_LINE INDENT heapq . heappop ( self . nums ) NEW_LINE DEDENT DEDENT def add ( self , val ) : NEW_LINE INDENT if len ( self . nums ) < self . k : NEW_LINE INDENT heapq . heappush ( self . nums , val ) NEW_LINE DEDENT elif val > self . nums [ 0 ] : NEW_LINE INDENT heapq . heapreplace ( self . nums , val ) NEW_LINE DEDENT return self . nums [ 0 ] NEW_LINE DEDENT DEDENT " V840,"class Solution { public int compress ( char [ ] chars ) { int anchor = 0 , write = 0 ; for ( int read = 0 ; read < chars . length ; read ++ ) { if ( read + 1 == chars . length || chars [ read + 1 ] != chars [ read ] ) { chars [ write ++ ] = chars [ anchor ] ; if ( read > anchor ) { for ( char c : ( "" "" + ( read - anchor + 1 ) ) . toCharArray ( ) ) { chars [ write ++ ] = c ; } } anchor = read + 1 ; } } return write ; } } ","class Solution ( object ) : NEW_LINE INDENT def compress ( self , chars ) : NEW_LINE INDENT anchor = write = 0 NEW_LINE for read , c in enumerate ( chars ) : NEW_LINE INDENT if read + 1 == len ( chars ) or chars [ read + 1 ] != c : NEW_LINE INDENT chars [ write ] = chars [ anchor ] NEW_LINE write += 1 NEW_LINE if read > anchor : NEW_LINE INDENT for digit in str ( read - anchor + 1 ) : NEW_LINE INDENT chars [ write ] = digit NEW_LINE write += 1 NEW_LINE DEDENT DEDENT anchor = read + 1 NEW_LINE DEDENT DEDENT return write NEW_LINE DEDENT DEDENT " V841,"class Solution { public int pivotIndex ( int [ ] nums ) { int totalsum = 0 , leftsum = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) totalsum += nums [ i ] ; for ( int i = 0 ; i < nums . length ; i ++ ) { if ( leftsum == totalsum - leftsum - nums [ i ] ) return i ; leftsum += nums [ i ] ; } return - 1 ; } } ","class Solution ( object ) : NEW_LINE INDENT def pivotIndex ( self , nums ) : NEW_LINE INDENT totalsum = sum ( nums ) NEW_LINE leftsum = 0 NEW_LINE for i , v in enumerate ( nums ) : NEW_LINE INDENT if leftsum == totalsum - leftsum - v : NEW_LINE INDENT return i NEW_LINE DEDENT leftsum += v NEW_LINE DEDENT return - 1 NEW_LINE DEDENT DEDENT " V842,"class Solution { public int longestPalindrome ( String s ) { int [ ] count = new int [ 128 ] ; for ( char c : s . toCharArray ( ) ) count [ c ] ++ ; int ans = 0 ; for ( int v : count ) { ans += v / 2 * 2 ; if ( ans % 2 == 0 && v % 2 == 1 ) ans ++ ; } return ans ; } } ","class Solution : NEW_LINE INDENT def longestPalindrome ( self , s ) : NEW_LINE INDENT ans = 0 NEW_LINE char_map = { } NEW_LINE for c in s : NEW_LINE INDENT char_map [ c ] = char_map . get ( c , 0 ) + 1 NEW_LINE DEDENT for c in char_map . keys ( ) : NEW_LINE INDENT if char_map [ c ] % 2 == 0 : NEW_LINE INDENT ans += char_map . pop ( c ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += char_map [ c ] / 2 * 2 NEW_LINE DEDENT DEDENT if len ( char_map ) != 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT DEDENT " V843,"class Solution { public int missingNumber ( int [ ] nums ) { int res = nums . length ; for ( int i = 0 ; i < nums . length ; i ++ ) { res ^= i ; res ^= nums [ i ] ; } return res ; } } ","class Solution ( object ) : NEW_LINE INDENT def missingNumber ( self , nums ) : NEW_LINE INDENT res = len ( nums ) NEW_LINE for i , v in enumerate ( nums ) : NEW_LINE INDENT res ^= i NEW_LINE res ^= v NEW_LINE DEDENT return res NEW_LINE DEDENT DEDENT " V844,"class Solution { public List < String > subdomainVisits ( String [ ] cpdomains ) { Map < String , Integer > map = new HashMap ( ) ; for ( String cpdomain : cpdomains ) { int i = cpdomain . indexOf ( ' ▁ ' ) ; int n = Integer . valueOf ( cpdomain . substring ( 0 , i ) ) ; String domain = cpdomain . substring ( i + 1 ) ; for ( i = 0 ; i < domain . length ( ) ; ++ i ) { if ( domain . charAt ( i ) == ' . ' ) { String d = domain . substring ( i + 1 ) ; map . put ( d , map . getOrDefault ( d , 0 ) + n ) ; } } map . put ( domain , map . getOrDefault ( domain , 0 ) + n ) ; } List < String > res = new ArrayList ( ) ; for ( String domain : map . keySet ( ) ) res . add ( map . get ( domain ) + "" ▁ "" + domain ) ; return res ; } } ","class Solution ( object ) : NEW_LINE INDENT def subdomainVisits ( self , cpdomains ) : NEW_LINE INDENT domain_count = { } NEW_LINE for cpdomain in cpdomains : NEW_LINE INDENT count , domain = cpdomain . split ( ' ▁ ' ) NEW_LINE sub_domain = domain . split ( ' . ' ) NEW_LINE for i in range ( len ( sub_domain ) ) : NEW_LINE INDENT curr = ' . ' . join ( sub_domain [ i : ] ) NEW_LINE domain_count [ curr ] = domain_count . get ( curr , 0 ) + int ( count ) NEW_LINE DEDENT DEDENT return [ str ( v ) + ' ▁ ' + k for k , v in domain_count . items ( ) ] NEW_LINE DEDENT DEDENT " V845,"class Solution { public int [ ] plusOne ( int [ ] digits ) { return addToDigit ( digits , digits . length - 1 ) ; } private int [ ] addToDigit ( int [ ] digits , int index ) { if ( index == - 1 ) { int [ ] newDigits = new int [ digits . length + 1 ] ; newDigits [ 0 ] = 1 ; for ( int i = 0 ; i < digits . length ; i ++ ) { newDigits [ i + 1 ] = digits [ i ] ; } return newDigits ; } if ( digits [ index ] == 9 ) { digits [ index ] = 0 ; return addToDigit ( digits , index - 1 ) ; } else { digits [ index ] ++ ; return digits ; } } } ","class Solution ( object ) : NEW_LINE INDENT def plusOne ( self , digits ) : NEW_LINE INDENT ls = len ( digits ) NEW_LINE for index in reversed ( range ( ls ) ) : NEW_LINE INDENT if digits [ index ] < 9 : NEW_LINE INDENT digits [ index ] += 1 NEW_LINE return digits NEW_LINE DEDENT else : NEW_LINE INDENT digits [ index ] = 0 NEW_LINE DEDENT DEDENT digits . insert ( 0 , 1 ) NEW_LINE return digits NEW_LINE DEDENT DEDENT " V846,"class Solution { public boolean isPerfectSquare ( int num ) { int low = 1 ; int high = num ; while ( low <= high ) { long mid = ( low + high ) >>> 1 ; if ( mid * mid == num ) { return true ; } else if ( mid * mid < num ) { low = ( int ) mid + 1 ; } else { high = ( int ) mid - 1 ; } } return false ; } } ","class Solution ( object ) : NEW_LINE INDENT def isPerfectSquare ( self , num ) : NEW_LINE INDENT low , high = 1 , num NEW_LINE while low <= high : NEW_LINE INDENT mid = ( low + high ) / 2 NEW_LINE mid_square = mid * mid NEW_LINE if mid_square == num : NEW_LINE INDENT return True NEW_LINE DEDENT elif mid_square < num : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT DEDENT " V847,"class Solution { public char findTheDifference ( String s , String t ) { int total = t . charAt ( s . length ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) total += ( t . charAt ( i ) - s . charAt ( i ) ) ; return ( char ) total ; } } ","class Solution ( object ) : NEW_LINE INDENT def findTheDifference ( self , s , t ) : NEW_LINE INDENT res = ord ( t [ - 1 ] ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT res += ord ( t [ i ] ) NEW_LINE res -= ord ( s [ i ] ) NEW_LINE DEDENT return chr ( res ) NEW_LINE DEDENT DEDENT "