dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class pair { int x , y ; pair ( int x , int y ) { this . x = x ; this . y = y ; } public String toString ( ) { return " ( " + this . x + " , ▁ " + this . y + " ) " ; } } class GFG { public static void maxZeros ( int [ ] [ ] mat , int n , int m ) { if ( n == 0 m == 0 ) return ; pair dp [ ] [ ] = new pair [ n + 1 ] [ m + 1 ] ; dp [ 0 ] [ 0 ] = new pair ( countTwos ( mat [ 0 ] [ 0 ] ) , countFives ( mat [ 0 ] [ 0 ] ) ) ; for ( int i = 1 ; i < n ; i ++ ) dp [ i ] [ 0 ] = add ( dp [ i - 1 ] [ 0 ] , new pair ( countTwos ( mat [ i ] [ 0 ] ) , countFives ( mat [ i ] [ 0 ] ) ) ) ; for ( int i = 1 ; i < m ; i ++ ) dp [ 0 ] [ i ] = add ( dp [ 0 ] [ i - 1 ] , new pair ( countTwos ( mat [ 0 ] [ i ] ) , countFives ( mat [ 0 ] [ i ] ) ) ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) { pair top = dp [ i - 1 ] [ j ] ; pair left = dp [ i ] [ j - 1 ] ; pair curr = new pair ( countTwos ( mat [ i ] [ j ] ) , countFives ( mat [ i ] [ j ] ) ) ; top = add ( top , curr ) ; left = add ( left , curr ) ; if ( check ( top , left ) ) dp [ i ] [ j ] = top ; else dp [ i ] [ j ] = left ; } } System . out . println ( Math . min ( dp [ n - 1 ] [ m - 1 ] . x , dp [ n - 1 ] [ m - 1 ] . y ) ) ; } public static boolean check ( pair one , pair two ) { int top = Math . min ( one . x , one . y ) ; int left = Math . min ( two . x , two . y ) ; if ( top > left ) return true ; else return false ; } public static int countTwos ( int num ) { int count = 0 ; while ( num != 0 && num % 2 == 0 ) { num /= 2 ; count ++ ; } return count ; } public static int countFives ( int num ) { int count = 0 ; while ( num != 0 && num % 5 == 0 ) { num /= 5 ; count ++ ; } return count ; } public static pair add ( pair one , pair two ) { pair np = new pair ( one . x + two . x , one . y + two . y ) ; return np ; } public static void main ( String [ ] args ) { int N = 3 , M = 4 ; int mat [ ] [ ] = { { 6 , 25 , 4 , 10 } , { 12 , 25 , 1 , 15 } , { 7 , 15 , 15 , 5 } } ; maxZeros ( mat , N , M ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j, num
Iterator variables: i, j
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int MAX = 100005 ; static Vector < Integer > SieveOfEratosthenes ( ) { boolean [ ] seive = new boolean [ MAX ] ; Arrays . fill ( seive , true ) ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( seive [ p ] == true ) { for ( int i = p * p ; i < MAX ; i += p ) { seive [ i ] = false ; } } } Vector < Integer > v = new Vector < Integer > ( ) ; for ( int p = 2 ; p < MAX ; p ++ ) { if ( seive [ p ] ) { v . add ( p ) ; } } return v ; } static void build ( int dp [ ] , int arr [ ] , int N ) { dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; Vector < Integer > prime = SieveOfEratosthenes ( ) ; int [ ] pref = new int [ N + 1 ] ; pref [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { pref [ i ] = pref [ i - 1 ] + arr [ i - 1 ] ; } for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; for ( int j = 0 ; j <= prime . size ( ) ; j ++ ) { int r = i - 1 ; int l = r - prime . get ( j ) + 1 ; if ( l < 0 ) break ; int temp = 0 ; temp = pref [ r + 1 ] - pref [ l ] ; if ( l - 2 >= 0 ) temp += dp [ l - 2 + 1 ] ; dp [ i ] = Math . max ( dp [ i ] , temp ) ; } } } static void maxSumSubseq ( int arr [ ] , int N ) { int [ ] dp = new int [ N + 1 ] ; build ( dp , arr , N ) ; System . out . print ( dp [ N ] ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 10 , 10 , 7 , 10 , 10 , 10 } ; int N = arr . length ; maxSumSubseq ( arr , N ) ; } }

Index/key variables: MAX, N, i, l, p
Accumulator variables: i, j, p, temp
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxScore ( int [ ] arr ) { int N = arr . length ; N ++ ; int [ ] [ ] dp = new int [ N + 1 ] [ 2 * ( N - 1 ) + 1 ] ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int s = 1 ; s <= 2 * ( N - 1 ) ; s ++ ) { for ( int j = 1 ; j <= N - 1 && j <= s ; j ++ ) { dp [ i ] [ s ] = Math . max ( dp [ i ] [ s ] , arr [ j - 1 ] + dp [ i - 1 ] [ s - j ] ) ; } } } return dp [ N ] [ 2 * ( N - 1 ) ] - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 0 } ; System . out . print ( maxScore ( arr ) ) ; } }

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int maxSum ( int a [ ] , int n , int k ) { if ( n <= 0 ) return 0 ; int option = maxSum ( a , n - 1 , k ) ; if ( k >= a [ n - 1 ] ) option = Math . max ( option , a [ n - 1 ] + maxSum ( a , n - 2 , k - a [ n - 1 ] ) ) ; return option ; } public static void main ( String [ ] args ) { int arr [ ] = { 50 , 10 , 20 , 30 , 40 } ; int N = arr . length ; int K = 100 ; System . out . println ( maxSum ( arr , N , K ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static boolean checkStr ( String str , int P , int Q ) { int N = str . length ( ) ; char prev = str . charAt ( 0 ) ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str . charAt ( i ) == prev ) { cnt ++ ; } else { if ( prev == '1' && cnt >= Q ) { return false ; } if ( prev == '0' && cnt >= P ) { return false ; } cnt = 1 ; } prev = str . charAt ( i ) ; } if ( prev == '1' && cnt >= Q ) { return false ; } if ( prev == '0' && cnt >= P ) { return false ; } return true ; } static int cntBinStr ( String str , int N , int P , int Q ) { int len = str . length ( ) ; if ( len == N ) { if ( checkStr ( str , P , Q ) ) return 1 ; return 0 ; } int X = cntBinStr ( str + '0' , N , P , Q ) ; int Y = cntBinStr ( str + '1' , N , P , Q ) ; return X + Y ; } public static void main ( String [ ] args ) { int N = 5 , P = 2 , Q = 3 ; System . out . println ( cntBinStr ( " " , N , P , Q ) ) ; } }

Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int binCoff ( int N , int R ) { int res = 1 ; if ( R > ( N - R ) ) { R = ( N - R ) ; } for ( int i = 0 ; i < R ; i ++ ) { res *= ( N - i ) ; res /= ( i + 1 ) ; } return res ; } static int cntPermutation ( int N ) { int cntPerm ; int C_2N_N = binCoff ( 2 * N , N ) ; cntPerm = C_2N_N / ( N + 1 ) ; return cntPerm ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; System . out . println ( cntPermutation ( N / 2 ) ) ; } }

Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void smallestPosition ( int m [ ] [ ] , int k ) { int n = m . length ; int mm = m [ 0 ] . length ; int [ ] [ ] xor = new int [ n ] [ mm ] ; PriorityQueue < Integer > minHeap = new PriorityQueue < > ( ) ; Map < Integer , int [ ] > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < mm ; j ++ ) { int a = i - 1 >= 0 ? xor [ i - 1 ] [ j ] : 0 ; int b = j - 1 >= 0 ? xor [ i ] [ j - 1 ] : 0 ; int c = ( i - 1 >= 0 && j - 1 >= 0 ) ? xor [ i - 1 ] [ j - 1 ] : 0 ; xor [ i ] [ j ] = m [ i ] [ j ] ^ a ^ b ^ c ; minHeap . add ( xor [ i ] [ j ] ) ; if ( minHeap . size ( ) > k ) { minHeap . poll ( ) ; } if ( ! map . containsKey ( xor [ i ] [ j ] ) ) map . put ( xor [ i ] [ j ] , new int [ ] { i , j } ) ; } } int kth_max_e = minHeap . poll ( ) ; System . out . println ( ( map . get ( kth_max_e ) [ 0 ] + 1 ) + " ▁ " + ( map . get ( kth_max_e ) [ 1 ] + 1 ) ) ; } public static void main ( String [ ] args ) { int m [ ] [ ] = { { 1 , 2 , 3 } , { 2 , 2 , 1 } , { 2 , 4 , 2 } } ; int k = 1 ; smallestPosition ( m , k ) ; } }

Index/key variables: i, j, mm, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int longestPalSubstr ( String str ) { int n = str . length ( ) ; int maxLength = 1 , start = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { for ( int j = i ; j < str . length ( ) ; j ++ ) { int flag = 1 ; for ( int k = 0 ; k < ( j - i + 1 ) / 2 ; k ++ ) if ( str . charAt ( i + k ) != str . charAt ( j - k ) ) flag = 0 ; if ( flag != 0 && ( j - i + 1 ) > maxLength ) { start = i ; maxLength = j - i + 1 ; } } } return maxLength ; } public static void main ( String [ ] args ) { String str = " forgeeksskeegfor " ; System . out . print ( longestPalSubstr ( str ) ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] [ ] dp = new int [ 101 ] [ 101 ] [ 101 ] ; static int helper ( int arr [ ] , int left , int right , int count , int m ) { if ( left > right ) return 0 ; if ( dp [ left ] [ right ] [ count ] != - 1 ) { return dp [ left ] [ right ] [ count ] ; } int ans = ( count + 1 ) * m + helper ( arr , left + 1 , right , 0 , m ) ; for ( int i = left + 1 ; i <= right ; ++ i ) { if ( arr [ i ] == arr [ left ] ) { ans = Math . max ( ans , helper ( arr , left + 1 , i - 1 , 0 , m ) + helper ( arr , i , right , count + 1 , m ) ) ; } } dp [ left ] [ right ] [ count ] = ans ; return ans ; } static int maxPoints ( int arr [ ] , int n , int m ) { int len = n ; for ( int i = 0 ; i < 101 ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) { for ( int k = 0 ; k < 101 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } return helper ( arr , 0 , len - 1 , 0 , m ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 2 , 2 , 3 , 4 , 3 , 1 } ; int M = 3 ; int N = arr . length ; System . out . print ( maxPoints ( arr , N , M ) ) ; } }

Index/key variables: count, i, j, k, left, right
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static int inf = 1000000008 ; public static int minSteps ( int m , int n ) { if ( n == m ) return 0 ; if ( m > n ) return inf ; int min_cost = inf ; for ( int i = 2 ; i < m ; i += 2 ) { if ( m % i == 0 ) { min_cost = Math . min ( min_cost , m / i + minSteps ( m + i , n ) ) ; } } return min_cost ; } public static void main ( String args [ ] ) { int M = 6 ; int N = 24 ; int minimum_cost = minSteps ( M , N ) ; minimum_cost = minimum_cost == inf ? - 1 : minimum_cost ; System . out . println ( minimum_cost ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minCountOfNumbers ( int N ) { int k = N % 10 ; int z = N - ( 9 * ( 9 - k ) ) ; if ( z >= 9 && z % 10 == 9 ) { return 10 - k ; } else return - 1 ; } public static void main ( String [ ] args ) { int N = 156 ; System . out . print ( minCountOfNumbers ( N ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void manipulation ( int [ ] [ ] matrix , int [ ] q ) { int x1 = q [ 0 ] , y1 = q [ 1 ] , x2 = q [ 2 ] , y2 = q [ 3 ] ; for ( int i = x1 - 1 ; i < x2 ; i ++ ) { for ( int j = y1 - 1 ; j < y2 ; j ++ ) { if ( matrix [ i ] [ j ] == 1 ) matrix [ i ] [ j ] = 0 ; else matrix [ i ] [ j ] = 1 ; } } } static void queries_fxn ( int [ ] [ ] matrix , int [ ] [ ] queries ) { for ( int [ ] q : queries ) manipulation ( matrix , q ) ; } public static void main ( String [ ] args ) { int [ ] [ ] matrix = { { 0 , 1 , 0 } , { 1 , 1 , 0 } } ; int [ ] [ ] queries = { { 1 , 1 , 2 , 3 } , { 1 , 1 , 1 , 1 } , { 1 , 2 , 2 , 3 } } ; queries_fxn ( matrix , queries ) ; System . out . print ( " [ " ) ; for ( int i = 0 ; i < matrix . length ; i ++ ) { System . out . print ( " [ " ) ; for ( int j = 0 ; j < matrix [ i ] . length ; j ++ ) System . out . print ( matrix [ i ] [ j ] + " ▁ " ) ; if ( i == matrix . length - 1 ) System . out . print ( " ] " ) ; else System . out . print ( " ] , ▁ " ) ; } System . out . print ( " ] " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j, q
Class/struct names: GFG
Java program:
class GFG { static int INF = ( int ) 1e7 ; static int min_op ( int cur , int M ) { if ( cur > M ) return INF ; if ( cur == M ) return 0 ; int op = INF ; for ( int i = 2 ; i * i <= cur ; i ++ ) { if ( cur % i == 0 ) { if ( i % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + i , M ) ) ; } if ( ( cur / i ) != i && ( cur / i ) % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + ( cur / i ) , M ) ) ; } } } return op ; } static void min_operations ( int N , int M ) { int op = min_op ( N , M ) ; if ( op >= INF ) System . out . print ( " - 1" ) ; else System . out . print ( op + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 6 , M = 24 ; min_operations ( N , M ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { private static int [ ] findPrimeFactors ( int n ) { int [ ] primeFactors = new int [ 9 ] ; int j = 0 ; if ( n % 2 == 0 ) { primeFactors [ j ++ ] = 2 ; while ( n % 2 == 0 ) n >>= 1 ; } for ( int i = 3 ; i * i <= n ; i += 2 ) { if ( n % i == 0 ) { primeFactors [ j ++ ] = i ; while ( n % i == 0 ) n /= i ; } } if ( n > 2 ) primeFactors [ j ++ ] = n ; return Arrays . copyOfRange ( primeFactors , 0 , j ) ; } private static void findShortestSubsequence ( int [ ] dp , int [ ] a , int index , int [ ] primeFactors ) { int n = a . length ; for ( int j = index ; j < n ; j ++ ) { int bitmask = 0 ; for ( int p = 0 ; p < primeFactors . length ; p ++ ) { if ( a [ j ] % primeFactors [ p ] == 0 ) { bitmask ^= ( 1 << p ) ; } } for ( int i = 0 ; i < dp . length ; i ++ ) { if ( dp [ i ] == n + 1 ) continue ; dp [ bitmask & i ] = Math . min ( dp [ bitmask & i ] , dp [ i ] + 1 ) ; } } } private static void printMinimumLength ( int [ ] a ) { int min = a . length + 1 ; for ( int i = 0 ; i < a . length - 1 ; i ++ ) { int [ ] primeFactors = findPrimeFactors ( a [ i ] ) ; int n = primeFactors . length ; int [ ] dp = new int [ 1 << n ] ; Arrays . fill ( dp , a . length + 1 ) ; int setBits = ( 1 << n ) - 1 ; dp [ setBits ] = 1 ; findShortestSubsequence ( dp , a , i + 1 , primeFactors ) ; min = Math . min ( dp [ 0 ] , min ) ; } if ( min == a . length + 1 ) System . out . println ( - 1 ) ; else System . out . println ( min ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 6 , 12 , 3 } ; printMinimumLength ( arr ) ; } }

Index/key variables: i, j, p, setBits
Accumulator variables: bitmask, i, j, n, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; public class GFG { public static int xorSum ( int a [ ] , int n , int mask , int [ ] dp ) { if ( dp [ mask ] != - 1 ) { return dp [ mask ] ; } int max_value = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( i != j && ( mask & ( 1 << i ) ) == 0 && ( mask & ( 1 << j ) ) == 0 ) { max_value = Math . max ( max_value , ( a [ i ] ^ a [ j ] ) + xorSum ( a , n , ( mask | ( 1 << i ) | ( 1 << j ) ) , dp ) ) ; } } } return dp [ mask ] = max_value ; } public static void main ( String args [ ] ) { int n = 4 ; int arr [ ] = { 1 , 2 , 3 , 4 } ; int dp [ ] = new int [ ( 1 << n ) + 5 ] ; Arrays . fill ( dp , - 1 ) ; System . out . println ( xorSum ( arr , n , 0 , dp ) ) ; } }

Index/key variables: i, j, mask
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static long [ ] fib = new long [ 101 ] ; static long [ ] dp1 = new long [ 101 ] ; static long [ ] dp2 = new long [ 101 ] ; static long [ ] v = new long [ 101 ] ; static void fibonacci ( ) { fib [ 1 ] = 1 ; fib [ 2 ] = 2 ; for ( int i = 3 ; i <= 87 ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } static long find ( int num ) { int cnt = 0 ; for ( int i = 87 ; i > 0 ; i -- ) { if ( num >= fib [ i ] ) { v [ cnt ++ ] = i ; num -= fib [ i ] ; } } for ( int i = 0 ; i < cnt / 2 ; i ++ ) { long t = v [ i ] ; v [ i ] = v [ cnt - i - 1 ] ; v [ cnt - i - 1 ] = t ; } dp1 [ 0 ] = 1 ; dp2 [ 0 ] = ( v [ 0 ] - 1 ) / 2 ; for ( int i = 1 ; i < cnt ; i ++ ) { dp1 [ i ] = dp1 [ i - 1 ] + dp2 [ i - 1 ] ; dp2 [ i ] = ( ( v [ i ] - v [ i - 1 ] ) / 2 ) * dp2 [ i - 1 ] + ( ( v [ i ] - v [ i - 1 ] - 1 ) / 2 ) * dp1 [ i - 1 ] ; } return ( dp1 [ cnt - 1 ] + dp2 [ cnt - 1 ] ) ; } public static void main ( String [ ] args ) { fibonacci ( ) ; int num = 13 ; System . out . print ( find ( num ) ) ; } }

Index/key variables: i
Accumulator variables: cnt, i, num
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void countNums ( int N ) { int l = ( int ) Math . pow ( 10 , N - 1 ) , r = ( int ) Math . pow ( 10 , N ) - 1 ; int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { int xor = 0 , temp = i ; while ( temp > 0 ) { xor = xor ^ ( temp % 10 ) ; temp /= 10 ; } if ( xor <= 9 ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int N = 2 ; countNums ( N ) ; } }

Accumulator variables: count, i, temp
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void main_fun ( int arr [ ] , int n ) { int [ ] [ ] dp = new int [ 4 ] [ n ] ; if ( arr [ 0 ] == 0 ) dp [ 0 ] [ 0 ] = 1 ; else dp [ 1 ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 1 ; else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ; } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) dp [ 1 ] [ i ] = Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ; else dp [ 1 ] [ i ] = dp [ 1 ] [ i - 1 ] ; } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { dp [ 2 ] [ i ] = Math . max ( dp [ 2 ] [ i - 1 ] + 1 , Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ) ; } else dp [ 2 ] [ i ] = dp [ 2 ] [ i - 1 ] ; } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) { dp [ 3 ] [ i ] = Math . max ( dp [ 3 ] [ i - 1 ] + 1 , Math . max ( dp [ 2 ] [ i - 1 ] + 1 , Math . max ( dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ) ) ) ; } else dp [ 3 ] [ i ] = dp [ 3 ] [ i - 1 ] ; } int ans = Math . max ( dp [ 2 ] [ n - 1 ] , Math . max ( dp [ 1 ] [ n - 1 ] , Math . max ( dp [ 0 ] [ n - 1 ] , dp [ 3 ] [ n - 1 ] ) ) ) ; System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int n = 4 ; int arr [ ] = { 0 , 1 , 0 , 1 } ; main_fun ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void SubarrayWithMaxSum ( Vector < Integer > nums ) { int endIndex = 0 , currMax = nums . get ( 0 ) ; int globalMax = nums . get ( 0 ) ; for ( int i = 1 ; i < nums . size ( ) ; ++ i ) { currMax = Math . max ( nums . get ( i ) , nums . get ( i ) + currMax ) ; if ( currMax > globalMax ) { globalMax = currMax ; endIndex = i ; } } int startIndex = endIndex ; while ( startIndex >= 0 ) { globalMax -= nums . get ( startIndex ) ; if ( globalMax == 0 ) break ; startIndex -- ; } for ( int i = startIndex ; i <= endIndex ; ++ i ) { System . out . print ( nums . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { Vector < Integer > arr = new Vector < Integer > ( ) ; arr . add ( - 2 ) ; arr . add ( - 5 ) ; arr . add ( 6 ) ; arr . add ( - 2 ) ; arr . add ( - 3 ) ; arr . add ( 1 ) ; arr . add ( 5 ) ; arr . add ( - 6 ) ; SubarrayWithMaxSum ( arr ) ; } }

Accumulator variables: globalMax, startIndex
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static ArrayList < Integer > primes ; static int M = 100005 ; static void sieve ( ) { primes = new ArrayList < > ( ) ; boolean mark [ ] = new boolean [ M ] ; for ( int i = 2 ; i < M ; i ++ ) mark [ i ] = true ; for ( int i = 2 ; i * i < M ; i ++ ) { if ( mark [ i ] ) { for ( int j = i * i ; j < M ; j += i ) mark [ j ] = false ; } } for ( int i = 2 ; i < M ; i ++ ) if ( mark [ i ] ) primes . add ( i ) ; } static void countPrimonacci ( int l , int r ) { ArrayList < Integer > dp = new ArrayList < > ( ) ; dp . add ( 1 ) ; dp . add ( 1 ) ; int i = 2 ; HashSet < Integer > s = new HashSet < > ( ) ; while ( true ) { int x = 0 ; for ( int j = 0 ; j < primes . size ( ) ; j ++ ) { int p = primes . get ( j ) ; if ( p >= i ) break ; x += dp . get ( i - p ) ; } if ( x >= l && x <= r ) s . add ( x ) ; if ( x > r ) break ; dp . add ( x ) ; i ++ ; } System . out . println ( s . size ( ) ) ; } public static void main ( String [ ] args ) { sieve ( ) ; int L = 1 , R = 10 ; countPrimonacci ( L , R ) ; } }

Index/key variables: M, i, j
Accumulator variables: i, j, x
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = ( int ) ( 1e5 + 5 ) ; static int MOD = 1000000007 ; static int [ ] dp = new int [ N ] ; static void countStrings ( int K , int [ ] [ ] Q ) { dp [ 0 ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; if ( i >= K ) dp [ i ] = ( dp [ i ] + dp [ i - K ] ) % MOD ; } for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] = ( dp [ i ] + dp [ i - 1 ] ) % MOD ; } for ( int i = 0 ; i < Q . length ; i ++ ) { int ans = dp [ Q [ i ] [ 1 ] ] - dp [ Q [ i ] [ 0 ] - 1 ] ; if ( ans < 0 ) ans = ans + MOD ; System . out . print ( ans + "NEW_LINE"); } } public static void main ( String [ ] args ) { int K = 3 ; int [ ] [ ] Q = { { 1 , 4 } , { 3 , 7 } } ; countStrings ( K , Q ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; public class Main { public static long minSum ( int n , int num [ ] , int price [ ] ) { long dp [ ] = new long [ n ] ; Arrays . fill ( dp , Integer . MAX_VALUE ) ; long ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( num [ j ] > num [ i ] ) { dp [ j ] = ( long ) Math . min ( ( long ) dp [ j ] , ( long ) price [ i ] + ( long ) price [ j ] ) ; ans = Math . min ( ans , ( long ) dp [ i ] + ( long ) price [ j ] ) ; } } } return ans != Integer . MAX_VALUE ? ans : - 1 ; } public static void main ( String [ ] args ) { int num [ ] = { 2 , 4 , 6 , 7 , 8 } ; int price [ ] = { 10 , 20 , 100 , 20 , 40 } ; int n = price . length ; System . out . println ( minSum ( n , num , price ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; 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 countStrings ( int N ) { if ( N % 2 == 1 ) return 0 ; else { N /= 2 ; long c = binomialCoeff ( 2 * N , N ) ; return c / ( N + 1 ) ; } } public static void main ( String [ ] args ) { int N = 6 ; System . out . print ( countStrings ( N ) + " ▁ " ) ; } }

Accumulator variables: N, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int solve ( int n , int k , int mod , int dp [ ] ) { if ( n < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( dp [ n ] != - 1 ) return dp [ n ] ; int cnt = 0 ; for ( int i = 2 ; i <= k ; i += 2 ) { cnt = ( cnt % mod + solve ( n - i , k , mod , dp ) % mod ) % mod ; } dp [ n ] = cnt ; return cnt ; } public static void main ( String [ ] args ) { int mod = ( int ) ( 1e9 + 7 ) ; int n = 4 , k = 2 ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) dp [ i ] = - 1 ; int ans = solve ( n , k , mod , dp ) ; System . out . println ( ans ) ; } }

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