dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int [ ] f = new int [ 12 ] ; static void fact ( ) { f [ 0 ] = f [ 1 ] = 1 ; for ( int i = 2 ; i <= 10 ; i ++ ) f [ i ] = i * 1 * f [ i - 1 ] ; } static void solve ( int arr [ ] , int n , int k ) { fact ( ) ; int even = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; } if ( k > even ) System . out . print ( 0 + "NEW_LINE"); else { System . out . print ( f [ even ] / ( f [ k ] * f [ even - k ] ) ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 1 ; solve ( arr , n , k ) ; } }

Index/key variables: even, i, k
Accumulator variables: even, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { final static int MOD = 1000000007 ; static int nCrModp ( int n , int r ) { if ( n % 2 == 1 ) { return - 1 ; } int C [ ] = new int [ r + 1 ] ; Arrays . fill ( C , 0 ) ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % MOD ; } return C [ r ] ; } public static void main ( String s [ ] ) { int N = 6 ; System . out . println ( nCrModp ( N , N / 2 ) ) ; } }

Index/key variables: j, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printMinOperations ( int N ) { int dp [ ] = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) dp [ i ] = N ; dp [ 1 ] = 0 ; for ( int i = 2 ; i < N + 1 ; i ++ ) { if ( i % 2 == 0 && dp [ i ] > dp [ i / 2 ] + 1 ) dp [ i ] = dp [ i / 2 ] + 1 ; if ( i % 3 == 0 && dp [ i ] > dp [ i / 3 ] + 1 ) dp [ i ] = dp [ i / 3 ] + 1 ; if ( dp [ i ] > dp [ i - 1 ] + 1 ) dp [ i ] = dp [ i - 1 ] + 1 ; } System . out . println ( dp [ N ] ) ; Vector < Integer > seq = new Vector < Integer > ( ) ; while ( N > 1 ) { seq . add ( N ) ; if ( dp [ N - 1 ] == dp [ N ] - 1 ) N = N - 1 ; else if ( N % 2 == 0 && dp [ N / 2 ] == dp [ N ] - 1 ) N = N / 2 ; else N = N / 3 ; } seq . add ( 1 ) ; for ( int i = seq . size ( ) - 1 ; i >= 0 ; i -- ) System . out . print ( seq . get ( i ) + " ▁ " ) ; } public static void main ( String args [ ] ) { int X = 96234 ; printMinOperations ( X ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static void maxLength ( int arr [ ] , int n ) { int dp [ ] = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = 1 ; } for ( int i = n - 1 ; i > 1 ; i -- ) { for ( int j = 1 ; j <= Math . sqrt ( i ) ; j ++ ) { if ( i % j == 0 ) { int s = i / j ; if ( s == j ) { if ( arr [ i ] > arr [ s ] ) { dp [ s ] = Math . max ( dp [ i ] + 1 , dp [ s ] ) ; } } else { if ( s != i && arr [ i ] > arr [ s ] ) dp [ s ] = Math . max ( dp [ i ] + 1 , dp [ s ] ) ; if ( arr [ i ] > arr [ j ] ) { dp [ j ] = Math . max ( dp [ i ] + 1 , dp [ j ] ) ; } } } } } int max = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( dp [ i ] > max ) max = dp [ i ] ; } System . out . println ( max ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 4 , 2 , 3 , 6 , 4 , 9 } ; int size = arr . length ; maxLength ( arr , size ) ; } }

Index/key variables: i, j, n, s
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxProfit ( int price [ ] , int n ) { int buy1 , profit1 , buy2 , profit2 ; buy1 = buy2 = Integer . MAX_VALUE ; profit1 = profit2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { buy1 = Math . min ( buy1 , price [ i ] ) ; profit1 = Math . max ( profit1 , price [ i ] - buy1 ) ; buy2 = Math . min ( buy2 , price [ i ] - profit1 ) ; profit2 = Math . max ( profit2 , price [ i ] - buy2 ) ; } return profit2 ; } public static void main ( String [ ] args ) { int price [ ] = { 2 , 30 , 15 , 10 , 8 , 25 , 80 } ; int n = price . length ; System . out . print ( " Maximum ▁ Profit ▁ = ▁ " + maxProfit ( price , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMaximumScore ( int [ ] a , int n ) { @ SuppressWarnings ( " unchecked " ) HashMap < Integer , Integer > freq = new HashMap ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . containsKey ( a [ i ] ) ) { freq . put ( a [ i ] , freq . get ( a [ i ] ) + 1 ) ; } else { freq . put ( a [ i ] , 1 ) ; } } int [ ] dp = new int [ Arrays . stream ( a ) . max ( ) . getAsInt ( ) + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = freq . get ( 1 ) ; for ( int i = 2 ; i < dp . length ; i ++ ) dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ i - 2 ] + freq . get ( i ) * i ) ; return dp [ dp . length - 1 ] ; } public static void main ( String [ ] args ) { int n ; n = 3 ; int [ ] a = { 1 , 2 , 3 } ; System . out . print ( findMaximumScore ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int maximizeSum ( int [ ] arr ) { int n = arr . length ; int sum = 0 ; for ( int i = 0 ; i < n ; i = i + 2 ) sum += arr [ i ] ; int leftDP [ ] = new int [ n / 2 ] ; int rightDP [ ] = new int [ n / 2 ] ; int c = 0 ; for ( int i = 1 ; i < n ; i = i + 2 ) { int leftDiff = arr [ i ] - arr [ i - 1 ] ; if ( c - 1 < 0 ) leftDP = leftDiff ; else { if ( leftDP > 0 ) leftDP = leftDiff + leftDP ; else leftDP [ i ] = leftDiff ; } int rightDiff ; if ( i + 1 >= arr . length ) rightDiff = 0 ; else rightDiff = arr [ i ] - arr [ i + 1 ] ; if ( c - 1 < 0 ) rightDP = rightDiff ; else { if ( rightDP > 0 ) rightDP = rightDiff + rightDP ; else rightDP = rightDiff ; } c ++ ; } int max = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { max = Math . max ( max , Math . max ( leftDP [ i ] , rightDP [ i ] ) ) ; } return max + sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 8 , 4 , 5 , 7 , 6 , 8 , 9 , 7 , 3 } ; int ans = maximizeSum ( arr ) ; System . out . println ( ans ) ; } }

Index/key variables: i
Accumulator variables: c, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int validsubsequences ( int arr [ ] , int n ) { long dp [ ] [ ] = new long [ n + 1 ] [ 2 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] [ 0 ] = 0 ; dp [ i ] [ 1 ] = 0 ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] % 2 != 0 ) { dp [ i ] [ 1 ] += 1 ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 0 ] ; } else { dp [ i ] [ 0 ] += 1 ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 1 ] ; } } return ( int ) ( dp [ n ] [ 0 ] + dp [ n ] [ 1 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 6 , 9 , 7 } ; int n = arr . length ; System . out . print ( validsubsequences ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static long getCount ( int n , int k ) { if ( n == 1 ) return 10 ; long dp [ ] [ ] = new long [ n + 1 ] [ 11 ] ; for ( int i = 1 ; i <= 9 ; i ++ ) dp [ 1 ] [ i ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { int l = Math . max ( 0 , j - k ) ; int r = Math . min ( 9 , j + k ) ; dp [ i ] [ l ] += dp [ i - 1 ] [ j ] ; dp [ i ] [ r + 1 ] -= dp [ i - 1 ] [ j ] ; } for ( int j = 1 ; j <= 9 ; j ++ ) dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } long count = 0 ; for ( int i = 0 ; i <= 9 ; i ++ ) count += dp [ n ] [ i ] ; return count ; } public static void main ( String [ ] args ) { int n = 2 , k = 1 ; System . out . println ( getCount ( n , k ) ) ; } }

Index/key variables: i, j, l, n
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int X = 6 ; static final int Z = 2 ; static boolean existPath ( int V , int edges [ ] [ ] , int u , int v ) { boolean [ ] [ ] mat = new boolean [ V ] [ V ] ; for ( int i = 0 ; i < X ; i ++ ) mat [ edges [ i ] [ 0 ] ] [ edges [ i ] [ 1 ] ] = true ; for ( int k = 0 ; k < V ; k ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { mat [ i ] [ j ] = mat [ i ] [ j ] || mat [ i ] [ k ] && mat [ k ] [ j ] ; } } } if ( u >= V v >= V ) { return false ; } if ( mat [ u ] [ v ] ) return true ; return false ; } public static void main ( String [ ] args ) { int V = 4 ; int edges [ ] [ ] = { { 0 , 2 } , { 0 , 1 } , { 1 , 2 } , { 2 , 3 } , { 2 , 0 } , { 3 , 3 } } ; int u = 1 , v = 3 ; if ( existPath ( V , edges , u , v ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } }

Index/key variables: V, i, j, k, u, v
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int calculate_maximum_splits ( int arr [ ] , int N ) { int pre [ ] = { 0 , - 1 , - 1 } ; int [ ] dp = new int [ N ] ; Arrays . fill ( dp , 0 ) ; int C = 0 ; for ( int i = 0 ; i < N ; i ++ ) { C = C + arr [ i ] ; C = C % 3 ; if ( pre [ C ] == - 1 ) { if ( 1 <= i ) dp [ i ] = dp [ i - 1 ] ; } else { dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ pre [ C ] ] + 1 ) ; } pre [ C ] = i ; } return dp [ N - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 36 , 1 , 9 , 2 , 0 , 1 , 8 , 1 } ; int N = arr . length ; System . out . println ( calculate_maximum_splits ( arr , N ) ) ; } }

Index/key variables: C, N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int prime [ ] = new int [ 1000001 ] ; static void seiveOfEratosthenes ( ) { for ( int i = 2 ; i < 1000001 ; i ++ ) { prime [ i ] = 1 ; } for ( int i = 2 ; i * i < 1000001 ; i ++ ) { if ( prime [ i ] == 1 ) { for ( int j = i * i ; j < 1000001 ; j += i ) { prime [ j ] = 0 ; } } } } static void CountElements ( int arr [ ] , int n , int L , int R ) { seiveOfEratosthenes ( ) ; int countPrime [ ] = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { countPrime [ i ] = countPrime [ i - 1 ] + prime [ arr [ i - 1 ] ] ; } System . out . print ( countPrime [ R ] - countPrime [ L - 1 ] + "NEW_LINE"); return ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 5 , 8 } ; int N = arr . length ; int L = 1 , R = 3 ; CountElements ( arr , N , L , R ) ; } }

Index/key variables: R, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
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 OddDivisorsCount ( int n , int q , int a [ ] , pair [ ] Query ) { int DP [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = ( int ) Math . sqrt ( a [ i ] ) ; if ( x * x == a [ i ] ) DP [ i ] = 1 ; } for ( int i = 1 ; i < n ; i ++ ) { DP [ i ] = DP [ i - 1 ] + DP [ i ] ; } int l , r ; for ( int i = 0 ; i < q ; i ++ ) { l = Query [ i ] . first ; r = Query [ i ] . second ; if ( l == 0 ) { System . out . print ( DP [ r ] + "NEW_LINE"); } else { System . out . print ( DP [ r ] - DP [ l - 1 ] + "NEW_LINE"); } } } public static void main ( String [ ] args ) { int N = 5 ; int Q = 3 ; int arr [ ] = { 2 , 4 , 5 , 6 , 9 } ; pair [ ] Query = { new pair ( 0 , 2 ) , new pair ( 1 , 3 ) , new pair ( 1 , 4 ) } ; OddDivisorsCount ( N , Q , arr , Query ) ; } }

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
class GFG { static int n , k ; static int [ ] [ ] [ ] [ ] dp = new int [ 1024 ] [ 2048 ] [ 2 ] [ 2 ] ; static int Ways ( int col , int comp , int row1 , int row2 ) { if ( comp > k ) return 0 ; if ( col > n ) { if ( comp == k ) return 1 ; else return 0 ; } if ( dp [ col ] [ comp ] [ row1 ] [ row2 ] != - 1 ) return dp [ col ] [ comp ] [ row1 ] [ row2 ] ; else { int ans = 0 ; if ( col == 1 ) { ans = ( ans + Ways ( col + 1 , comp + 1 , 0 , 0 ) + Ways ( col + 1 , comp + 1 , 1 , 1 ) ) ; ans = ( ans + Ways ( col + 1 , comp + 2 , 0 , 1 ) + Ways ( col + 1 , comp + 2 , 1 , 0 ) ) ; } else { if ( ( row1 > 0 && row2 > 0 ) || ( row1 == 0 && row2 == 0 ) ) { ans = ( ( ( ans + Ways ( col + 1 , comp + 1 , 0 , 0 ) ) + Ways ( col + 1 , comp + 1 , 1 , 0 ) ) + Ways ( col + 1 , comp + 1 , 0 , 1 ) ) ; ans = ( ans + Ways ( col + 1 , comp , 1 , 1 ) ) ; } if ( row1 > 0 && row2 == 0 ) { ans = ( ( ( ans + Ways ( col + 1 , comp , 0 , 0 ) ) + Ways ( col + 1 , comp , 1 , 1 ) ) + Ways ( col + 1 , comp , 1 , 0 ) ) ; ans = ( ans + Ways ( col + 1 , comp + 2 , 0 , 1 ) ) ; } if ( row1 == 0 && row2 > 0 ) { ans = ( ( ( ans + Ways ( col + 1 , comp , 0 , 0 ) ) + Ways ( col + 1 , comp , 1 , 1 ) ) + Ways ( col + 1 , comp , 0 , 1 ) ) ; ans = ( ans + Ways ( col + 1 , comp + 2 , 1 , 0 ) ) ; } } return dp [ col ] [ comp ] [ row1 ] [ row2 ] = ans ; } } public static void main ( String [ ] args ) { n = 2 ; k = 1 ; for ( int i = 0 ; i < 1024 ; i ++ ) for ( int j = 0 ; j < 2048 ; j ++ ) for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; System . out . print ( Ways ( 1 , 0 , 0 , 0 ) ) ; } }

Index/key variables: col, comp, i, j, k, l, row1, row2
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static boolean [ ] primes = new boolean [ 1000001 ] ; static int maxn = 1000000 ; static void sieve ( ) { Arrays . fill ( primes , true ) ; primes [ 0 ] = false ; primes [ 1 ] = false ; for ( int i = 2 ; i * i <= maxn ; i ++ ) { if ( primes [ i ] ) { for ( int j = i * i ; j <= maxn ; j += i ) primes [ j ] = false ; } } } static String toBinary ( int n ) { String r = " " ; while ( n != 0 ) { r = ( n % 2 == 0 ? "0" : "1" ) + r ; n /= 2 ; } return ( r == " " ) ? "0" : r ; } static void PrimeSplit ( String str ) { String temp ; int cnt = 0 ; ArrayList < String > ans = new ArrayList < > ( ) ; int bt = 1 << ( str . length ( ) - 1 ) ; int n = str . length ( ) ; for ( int i = 0 ; i < bt ; i ++ ) { temp = toBinary ( i ) + "0" ; int j = 0 , x = n - temp . length ( ) , y ; while ( j < x ) { temp = "0" + temp ; j ++ ; } j = 0 ; x = 0 ; y = - 1 ; String sp = " " , tp = " " ; boolean flag = false ; while ( j < n ) { sp += str . charAt ( j ) ; if ( temp . charAt ( j ) == '1' ) { tp += sp + ' , ' ; y = Integer . parseInt ( sp ) ; if ( ! primes [ y ] ) { flag = true ; break ; } sp = " " ; } j ++ ; } tp += sp ; if ( sp != " " ) { y = Integer . parseInt ( sp ) ; if ( ! primes [ y ] ) flag = true ; } if ( ! flag ) ans . add ( tp ) ; } if ( ans . size ( ) == 0 ) { System . out . println ( - 1 ) ; } for ( String i : ans ) { System . out . println ( i ) ; } } public static void main ( String [ ] args ) { String str = "11373" ; sieve ( ) ; PrimeSplit ( str ) ; } }

Index/key variables: i, j, y
Accumulator variables: i, j, n, sp, tp
Iterator variables: i, j
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countStableNum ( String str , int N ) { int count1 [ ] [ ] = new int [ N ] [ 10 ] ; int count2 [ ] [ ] = new int [ N ] [ 10 ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < 10 ; j ++ ) count1 [ i ] [ j ] = count2 [ i ] [ j ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i != 0 ) { for ( int j = 0 ; j < 10 ; j ++ ) { count1 [ i ] [ j ] += count1 [ i - 1 ] [ j ] ; } } count1 [ i ] [ str . charAt ( i ) - '0' ] ++ ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( i != N - 1 ) { for ( int j = 0 ; j < 10 ; j ++ ) { count2 [ i ] [ j ] += count2 [ i + 1 ] [ j ] ; } } count2 [ i ] [ str . charAt ( i ) - '0' ] ++ ; } int ans = 0 ; for ( int i = 1 ; i < N - 1 ; i ++ ) { if ( str . charAt ( i ) == '9' ) continue ; int c1 = count1 [ i - 1 ] [ str . charAt ( i ) - '0' ] ; int c2 = count2 [ i + 1 ] [ str . charAt ( i ) - '0' + 1 ] ; if ( c2 == 0 ) continue ; ans = ( ans + ( c1 * ( ( c2 * ( c2 - 1 ) / 2 ) ) ) ) ; } return ans ; } public static void main ( String [ ] args ) { String str = "224353" ; int N = str . length ( ) ; System . out . println ( countStableNum ( str , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countSubsequenceUtil ( int ind , int sum , int [ ] A , int N , int [ ] [ ] dp ) { if ( ind == N ) return 1 ; if ( dp [ ind ] [ sum ] != - 1 ) return dp [ ind ] [ sum ] ; if ( A [ ind ] <= sum ) { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) + countSubsequenceUtil ( ind + 1 , sum - A [ ind ] , A , N , dp ) ; } else { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) ; } return dp [ ind ] [ sum ] ; } static int countSubsequence ( int [ ] A , int N , int X ) { int [ ] [ ] dp = new int [ N ] [ X + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < X + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return countSubsequenceUtil ( 0 , X , A , N , dp ) - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 25 , 13 , 40 } , X = 50 ; int N = arr . length ; System . out . print ( countSubsequence ( arr , N , X ) ) ; } }

Index/key variables: N, i, ind, j, sum
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int waysToDecode2 ( char [ ] s ) { int n = s . length ; int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 1 ; if ( s [ 0 ] == '0' ) return 0 ; dp [ 1 ] = ( ( s [ 0 ] == ' * ' ) ? 9 : 1 ) ; for ( int i = 2 ; i <= n ; i ++ ) { char first = s [ i - 2 ] ; char second = s [ i - 1 ] ; if ( second == ' * ' ) { dp [ i ] += 9 * dp [ i - 1 ] ; } else if ( second > '0' ) dp [ i ] += dp [ i - 1 ] ; if ( first == '1' first == '2' ) { if ( second == ' * ' ) { if ( first == '1' ) dp [ i ] += 9 * dp [ i - 2 ] ; else if ( first == '2' ) dp [ i ] += 6 * dp [ i - 2 ] ; } else if ( ( ( first - '0' ) * 10 + ( second - '0' ) ) <= 26 ) { dp [ i ] += dp [ i - 2 ] ; } } else if ( first == ' * ' ) { if ( second == ' * ' ) { dp [ i ] += 15 * dp [ i - 2 ] ; } else if ( second <= '6' ) { dp [ i ] += 2 * dp [ i - 2 ] ; } else { dp [ i ] += dp [ i - 2 ] ; } } } return dp [ n ] ; } public static void main ( String [ ] args ) { String str = "12*3" ; System . out . print ( waysToDecode2 ( str . toCharArray ( ) ) + "NEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void goodInteger ( int arr [ ] , int n , int h , int l , int r ) { int [ ] [ ] dp = new int [ n + 1 ] [ h ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < h ; j ++ ) dp [ i ] [ j ] = - 1 ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < h ; j ++ ) { if ( dp [ i ] [ j ] != - 1 ) { int h1 = ( j + arr [ i ] ) % h ; int h2 = ( j + arr [ i ] - 1 ) % h ; dp [ i + 1 ] [ h1 ] = Math . max ( dp [ i + 1 ] [ h1 ] , dp [ i ] [ j ] + ( ( h1 >= l && h1 <= r ) ? 1 : 0 ) ) ; dp [ i + 1 ] [ h2 ] = Math . max ( dp [ i + 1 ] [ h2 ] , dp [ i ] [ j ] + ( ( h2 >= l && h2 <= r ) ? 1 : 0 ) ) ; } } } int ans = 0 ; for ( int i = 0 ; i < h ; i ++ ) { if ( dp [ n ] [ i ] != - 1 ) ans = Math . max ( ans , dp [ n ] [ i ] ) ; } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { int A [ ] = { 16 , 17 , 14 , 20 , 20 , 11 , 22 } ; int H = 24 ; int L = 21 ; int R = 23 ; int size = A . length ; goodInteger ( A , size , H , L , R ) ; } }

Index/key variables: h, h1, h2, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Query { int L , R ; public Query ( int l , int r ) { super ( ) ; L = l ; R = r ; } } ; static void fillPrefixArray ( int arr [ ] , int n , int prefixArray [ ] ) { prefixArray [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { prefixArray [ i ] = prefixArray [ i - 1 ] + arr [ i ] ; } else { prefixArray [ i ] = prefixArray [ i - 1 ] - arr [ i ] ; } } } static int findResultUtil ( int prefixArray [ ] , int L , int R ) { int result ; if ( L == 0 ) { result = prefixArray [ R ] ; } else { result = prefixArray [ R ] - prefixArray [ L - 1 ] ; } if ( L % 2 == 1 ) { result = result * ( - 1 ) ; } return result ; } static void findResult ( int arr [ ] , int n , Query q [ ] , int m ) { int [ ] prefixArray = new int [ n ] ; fillPrefixArray ( arr , n , prefixArray ) ; for ( int i = 0 ; i < m ; i ++ ) { System . out . print ( findResultUtil ( prefixArray , q [ i ] . L , q [ i ] . R ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 } ; int n = arr . length ; Query q [ ] = { new Query ( 2 , 5 ) , new Query ( 6 , 8 ) , new Query ( 1 , 7 ) , new Query ( 4 , 8 ) , new Query ( 0 , 5 ) } ; int m = q . length ; findResult ( arr , n , q , m ) ; } }

Index/key variables: R, i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Query
Java program:
import java . util . * ; class GFG { static int validSubArrLength ( int arr [ ] , int N , int K ) { int [ ] dp = new int [ N + 1 ] ; int pos = 0 ; int ans = 0 ; int mx = 0 ; int pre = 0 ; Deque < Integer > q = new LinkedList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { while ( ! q . isEmpty ( ) && arr [ q . getLast ( ) ] < arr [ i ] ) q . removeLast ( ) ; q . add ( i ) ; if ( i == 0 ) { mx = arr [ i ] ; dp [ i ] = arr [ i ] ; } else if ( mx <= arr [ i ] ) { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; mx = arr [ i ] ; } else { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; } if ( pre == 0 ) pos = 0 ; else pos = pre - 1 ; while ( ( i - pre + 1 ) * mx - ( dp [ i ] - dp [ pos ] ) > K && pre < i ) { pos = pre ; pre ++ ; while ( ! q . isEmpty ( ) && q . peek ( ) < pre && pre < i ) { q . removeFirst ( ) ; mx = arr [ q . peek ( ) ] ; } } ans = Math . max ( ans , i - pre + 1 ) ; } return ans ; } public static void main ( String [ ] args ) { int N = 6 ; int K = 8 ; int arr [ ] = { 2 , 7 , 1 , 3 , 4 , 5 } ; System . out . print ( validSubArrLength ( arr , N , K ) ) ; } }

Index/key variables: i, pos
Accumulator variables: i, pre
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isKPartitionPossible ( int arr [ ] , int N , int K ) { if ( K == 1 ) return true ; if ( N < K ) return false ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % K != 0 ) return false ; int target = sum / K ; int [ ] dp = new int [ ( 1 << 15 ) ] ; for ( int i = 0 ; i < ( 1 << N ) ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; for ( int mask = 0 ; mask < ( 1 << N ) ; mask ++ ) { if ( dp [ mask ] == - 1 ) continue ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( ( mask & ( 1 << i ) ) == 0 ) && dp [ mask ] + arr [ i ] <= target ) { dp [ mask ( 1 << i ) ] = ( dp [ mask ] + arr [ i ] ) % target ; } } } if ( dp [ ( 1 << N ) - 1 ] == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 4 , 5 , 3 , 3 } ; int N = arr . length ; int K = 3 ; if ( isKPartitionPossible ( arr , N , K ) ) { System . out . print ( " Partitions ▁ into ▁ equal ▁ " ) ; System . out . print ( "sum is possible.NEW_LINE"); } else { System . out . print ( " Partitions ▁ into ▁ equal ▁ " ) ; System . out . print ( "sum is not possible.NEW_LINE"); } } }

Index/key variables: i, mask
Accumulator variables: i, mask, sum
Iterator variables: i, mask
Class/struct names: GFG