dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int minimalLength ( int a [ ] , int n ) { int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ; int [ ] dp1 = new int [ n ] ; int i , j , k ; for ( i = 0 ; i < n + 1 ; i ++ ) { for ( j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( int size = 1 ; size <= n ; size ++ ) { for ( i = 0 ; i < n - size + 1 ; i ++ ) { j = i + size - 1 ; if ( i == j ) dp [ i ] [ j ] = a [ i ] ; else { for ( k = i ; k < j ; k ++ ) { if ( dp [ i ] [ k ] != - 1 && dp [ i ] [ k ] == dp [ k + 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i ] [ k ] + 1 ; } } } } for ( i = 0 ; i < n ; i ++ ) dp1 [ i ] = ( int ) 1e7 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( dp [ j ] [ i ] != - 1 ) { if ( j == 0 ) dp1 [ i ] = 1 ; else dp1 [ i ] = Math . min ( dp1 [ i ] , dp1 [ j - 1 ] + 1 ) ; } } } return dp1 [ n - 1 ] ; } public static void main ( String [ ] args ) { int n = 7 ; int a [ ] = { 3 , 3 , 4 , 4 , 4 , 3 , 3 } ; System . out . print ( minimalLength ( a , n ) ) ; } }

Index/key variables: i, j, k, n
Accumulator variables: i, j, k, size
Iterator variables: i, j, k, size
Class/struct names: GFG
Java program:
class GFG { static int [ ] [ ] [ ] dp = new int [ 100 ] [ 100 ] [ 100 ] ; static int MaximumScoreDP ( int l , int r , int prefix_sum [ ] , int num ) { if ( l > r ) return 0 ; if ( dp [ l ] [ r ] [ num ] != - 1 ) return dp [ l ] [ r ] [ num ] ; int current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; dp [ l ] [ r ] [ num ] = current_sum + Math . max ( MaximumScoreDP ( l + 1 , r , prefix_sum , num + 1 ) , MaximumScoreDP ( l , r - 1 , prefix_sum , num + 1 ) ) ; return dp [ l ] [ r ] [ num ] ; } static int findMaxScore ( int a [ ] , int n ) { int [ ] prefix_sum = new int [ n ] ; prefix_sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { for ( int l = 0 ; l < 100 ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } return MaximumScoreDP ( 0 , n - 1 , prefix_sum , 1 ) ; } public static void main ( String [ ] args ) { int n = 6 ; int A [ ] = { 1 , 2 , 3 , 4 , 2 , 6 } ; System . out . print ( findMaxScore ( A , n ) ) ; } }

Index/key variables: i, j, l, n, num, r
Accumulator variables: current_sum, i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
class GFG { static int [ ] [ ] [ ] memo = new int [ 32 ] [ 2 ] [ 2 ] ; static int dp ( int pos , int fl , int pr , String bin ) { if ( pos == bin . length ( ) ) return 1 ; if ( memo [ pos ] [ fl ] [ pr ] != - 1 ) return memo [ pos ] [ fl ] [ pr ] ; int val = 0 ; if ( bin . charAt ( pos ) == '0' ) val = val + dp ( pos + 1 , fl , 0 , bin ) ; else if ( bin . charAt ( pos ) == '1' ) val = val + dp ( pos + 1 , 1 , 0 , bin ) ; if ( pr == 0 ) { if ( fl == 1 ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } else if ( bin . charAt ( pos ) == '1' ) { val += dp ( pos + 1 , fl , 1 , bin ) ; } } return memo [ pos ] [ fl ] [ pr ] = val ; } static int findIntegers ( int num ) { String bin = " " ; while ( num > 0 ) { if ( num % 2 == 1 ) bin += "1" ; else bin += "0" ; num /= 2 ; } bin = reverse ( bin ) ; for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) memo [ i ] [ j ] [ l ] = - 1 ; } } return dp ( 0 , 0 , 0 , bin ) ; } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { int N = 12 ; System . out . print ( findIntegers ( N ) ) ; } }

Index/key variables: fl, i, j, l, pos, pr, r
Accumulator variables: bin, i, j, l, num, r, val
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
class GFG { static int TotalWays ( int n , int s , int k ) { int [ ] dp = new int [ n ] ; dp [ s - 1 ] = 1 ; for ( int i = s ; i < n ; i ++ ) { int idx = Math . max ( s - 1 , i - k ) ; for ( int j = idx ; j < i ; j ++ ) { dp [ i ] += dp [ j ] ; } } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int n = 5 ; int k = 2 ; int s = 2 ; System . out . print ( " Total ▁ Ways ▁ = ▁ " + TotalWays ( n , s , k ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int max_sum ( int arr [ ] , int n , int k ) { int dp [ ] = new int [ n ] ; dp [ 0 ] = Math . max ( 0 , arr [ 0 ] ) ; int i = 1 ; while ( i < k ) { dp [ i ] = Math . max ( dp [ i - 1 ] , arr [ i ] ) ; i ++ ; } i = k ; while ( i < n ) { dp [ i ] = Math . max ( dp [ i - 1 ] , arr [ i ] + dp [ i - k ] ) ; i ++ ; } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , - 2 , 4 , 3 , 1 } ; int n = arr . length ; int k = 4 ; System . out . println ( max_sum ( arr , n , k ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Class/struct names: GFG
Java program:
class GFG { final static long MOD = 1000000007 ; static long countStr ( int N ) { long dp [ ] [ ] = new long [ N + 1 ] [ 3 ] ; dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = 1 ; dp [ 1 ] [ 2 ] = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD ; dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD ; } long ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD ; return ans ; } public static void main ( String [ ] args ) { int N = 8 ; System . out . println ( countStr ( N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int CountOfOddSum ( int a [ ] [ ] , int n ) { int [ ] [ ] dp = new int [ n ] [ 2 ] ; int [ ] [ ] cnt = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { if ( a [ i ] [ j ] % 2 == 0 ) { cnt [ i ] [ 0 ] ++ ; } else { cnt [ i ] [ 1 ] ++ ; } } } dp [ 0 ] [ 0 ] = cnt [ 0 ] [ 0 ] ; dp [ 0 ] [ 1 ] = cnt [ 0 ] [ 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 0 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 1 ] ) ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] * cnt [ i ] [ 1 ] + dp [ i - 1 ] [ 1 ] * cnt [ i ] [ 0 ] ) ; } return dp [ n - 1 ] [ 1 ] ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 } , { 3 , 6 } } ; int n = a . length ; int ans = CountOfOddSum ( a , n ) ; System . out . println ( ans ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int LongestConsSeq ( int [ ] arr , int N ) { int maxval = 1 ; for ( int i = 0 ; i < N ; i += 1 ) { maxval = Math . max ( maxval , arr [ i ] ) ; } int [ ] [ ] dp = new int [ maxval + 1 ] [ 2 ] ; int ans = 1 ; for ( int i = 0 ; i < N ; i += 1 ) { dp [ arr [ i ] ] [ 0 ] = ( 1 + dp [ arr [ i ] - 1 ] [ 0 ] ) ; if ( arr [ i ] >= 2 ) dp [ arr [ i ] ] [ 1 ] = Math . max ( 1 + dp [ arr [ i ] - 1 ] [ 1 ] , 2 + dp [ arr [ i ] - 2 ] [ 0 ] ) ; else dp [ arr [ i ] ] [ 1 ] = 1 ; ans = Math . max ( ans , dp [ arr [ i ] ] [ 1 ] ) ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 4 , 5 } ; int N = arr . length ; System . out . println ( LongestConsSeq ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Main { public static boolean isStepNum ( int n ) { int prevDigit = - 1 ; while ( n > 0 ) { int curDigit = n % 10 ; if ( prevDigit != - 1 ) { if ( Math . abs ( curDigit - prevDigit ) != 1 ) return false ; } n /= 10 ; prevDigit = curDigit ; } return true ; } public static void displaySteppingNumbers ( int n , int m ) { for ( int i = n ; i <= m ; i ++ ) if ( isStepNum ( i ) ) System . out . print ( i + " ▁ " ) ; } public static void main ( String args [ ] ) { int n = 0 , m = 21 ; displaySteppingNumbers ( n , m ) ; } }

Accumulator variables: i, n
Iterator variables: i
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static Vector < Integer > v = new Vector < > ( ) ; static int [ ] [ ] [ ] [ ] dp = new int [ 18 ] [ 180 ] [ 180 ] [ 2 ] ; static int memo ( int index , int evenSum , int oddSum , int tight ) { if ( index == v . size ( ) ) { if ( evenSum > oddSum ) { return 1 ; } else { return 0 ; } } if ( dp [ index ] [ evenSum ] [ oddSum ] [ tight ] != - 1 ) { return dp [ index ] [ evenSum ] [ oddSum ] [ tight ] ; } int limit = ( tight > 0 ) ? v . get ( index ) : 9 ; int ans = 0 ; for ( int d = 0 ; d <= limit ; d ++ ) { int currTight = 0 ; if ( d == v . get ( index ) ) { currTight = tight ; } if ( d % 2 != 0 ) { ans += memo ( index + 1 , evenSum , oddSum + d , currTight ) ; else { ans += memo ( index + 1 , evenSum + d , oddSum , currTight ) ; } } dp [ index ] [ evenSum ] [ oddSum ] [ tight ] = ans ; return ans ; } static int CountNum ( int n ) { v . clear ( ) ; while ( n > 0 ) { v . add ( n % 10 ) ; n = n / 10 ; } Collections . reverse ( v ) ; for ( int i = 0 ; i < 18 ; i ++ ) { for ( int j = 0 ; j < 180 ; j ++ ) { for ( int k = 0 ; k < 180 ; k ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) { dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } } return memo ( 0 , 0 , 0 , 1 ) ; } public static void main ( String [ ] args ) { int L , R ; L = 2 ; R = 10 ; System . out . println ( CountNum ( R ) - CountNum ( L - 1 ) ) ; } }

Index/key variables: evenSum, i, index, j, k, l, oddSum, tight
Accumulator variables: ans, d, i, j, k, l
Iterator variables: d, i, j, k, l
Class/struct names: GFG
Java program:
class GFG { static int minCount ( int K ) { int memo [ ] = new int [ 100 ] ; for ( int i = 0 ; i < 100 ; i ++ ) { memo [ i ] = Integer . MAX_VALUE ; } memo [ 0 ] = 0 ; for ( int i = 1 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 1 ] + 1 , memo [ i ] ) ; } for ( int i = 10 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 10 ] + 1 , memo [ i ] ) ; } for ( int i = 25 ; i < 100 ; i ++ ) { memo [ i ] = Math . min ( memo [ i - 25 ] + 1 , memo [ i ] ) ; } int min_count = 0 ; while ( K > 0 ) { min_count += memo [ K % 100 ] ; K /= 100 ; } return min_count ; } public static void main ( String [ ] args ) { int K = 69 ; System . out . println ( minCount ( K ) ) ; } }

Index/key variables: i
Accumulator variables: K, i, min_count
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int N = 10000 ; static int count_required_sequence ( int n , int arr [ ] ) { int total_required_subsequence = 0 ; int total_n_required_subsequence = 0 ; int [ ] [ ] dp = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { int turn_required = 0 ; for ( int j = - 1 ; j <= 1 ; j ++ ) turn_required += dp [ arr [ i ] + j ] [ 0 ] ; int required_end_i = ( total_required_subsequence + turn_required ) ; int n_required_end_i = ( 1 + total_n_required_subsequence - turn_required ) ; total_required_subsequence += required_end_i ; total_n_required_subsequence += n_required_end_i ; dp [ arr [ i ] ] [ 1 ] += required_end_i ; dp [ arr [ i ] ] [ 0 ] += n_required_end_i ; } return total_required_subsequence ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 6 , 2 , 1 , 9 } ; int n = arr . length ; System . out . println ( count_required_sequence ( n , arr ) ) ; } }

Index/key variables: N, i
Accumulator variables: i, j, total_n_required_subsequence, total_required_subsequence, turn_required
Iterator variables: i, j
Class/struct names: GFG
Java program:
class Combination { private int [ ] Indices ; private int R ; private boolean [ ] Flags ; private int Start ; private int End ; public Combination ( int [ ] arr , int r ) { this . Indices = arr ; this . R = r ; } public void GetFirst ( ) { Flags = new boolean [ this . Indices . length ] ; for ( int i = 0 ; i < this . R ; ++ i ) { Flags [ i ] = true ; } this . Start = 0 ; this . End = this . R - 1 ; this . Output ( ) ; } public boolean HasNext ( ) { return End < ( this . Indices . length - 1 ) ; } public void Next ( ) { if ( this . Start == this . End ) { this . Flags [ this . End ] = false ; this . Flags [ this . End + 1 ] = true ; this . Start += 1 ; this . End += 1 ; while ( this . End + 1 < this . Indices . length && this . Flags [ this . End + 1 ] ) { ++ this . End ; } } else { if ( this . Start == 0 ) { Flags [ this . End ] = false ; Flags [ this . End + 1 ] = true ; this . End -= 1 ; } else { Flags [ this . End + 1 ] = true ; for ( int i = this . Start ; i <= this . End ; ++ i ) { Flags [ i ] = false ; } for ( int i = 0 ; i < this . End - this . Start ; ++ i ) { Flags [ i ] = true ; } this . End = this . End - this . Start - 1 ; this . Start = 0 ; } } this . Output ( ) ; } private void Output ( ) { for ( int i = 0 , count = 0 ; i < Indices . length && count < this . R ; ++ i ) { if ( Flags [ i ] ) { System . out . print ( Indices [ i ] ) ; System . out . print ( " ▁ " ) ; ++ count ; } } System . out . println ( ) ; } } class GFG { public static void main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 2 , 3 } ; int r = 3 ; Combination com = new Combination ( arr , r ) ; com . GetFirst ( ) ; while ( com . HasNext ( ) ) { com . Next ( ) ; } } }

Index/key variables: i
Accumulator variables: End, Start
Iterator variables: i
Class/struct names: Combination, GFG
Java program:
import java . util . * ; class GFG { static int MAX_INDEX = 51 ; static int MAX_SUM = 2505 ; static int [ ] [ ] [ ] dp = new int [ MAX_INDEX ] [ MAX_SUM ] [ MAX_INDEX ] ; static int waysutil ( int index , int sum , int count , Vector < Integer > arr , int K ) { if ( index < 0 ) { return 0 ; } if ( index == 0 ) { if ( count == 0 ) { return 0 ; } int remainder = sum % count ; if ( remainder != 0 ) { return 0 ; } int average = sum / count ; if ( average == K ) { return 1 ; } } if ( dp [ index ] [ sum ] [ count ] != - 1 ) { return dp [ index ] [ sum ] [ count ] ; } int dontpick = waysutil ( index - 1 , sum , count , arr , K ) ; int pick = waysutil ( index - 1 , sum + arr . get ( index ) , count + 1 , arr , K ) ; int total = pick + dontpick ; dp [ index ] [ sum ] [ count ] = total ; return total ; } static int ways ( int N , int K , int [ ] arr ) { Vector < Integer > Arr = new Vector < > ( ) ; Arr . add ( - 1 ) ; for ( int i = 0 ; i < N ; ++ i ) { Arr . add ( arr [ i ] ) ; } for ( int i = 0 ; i < MAX_INDEX ; i ++ ) { for ( int j = 0 ; j < MAX_SUM ; j ++ ) { for ( int l = 0 ; l < MAX_INDEX ; l ++ ) { dp [ i ] [ j ] [ l ] = - 1 ; } } } int answer = waysutil ( N , 0 , 0 , Arr , K ) ; return answer ; } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 6 , 2 , 8 , 7 , 6 , 5 , 9 } ; int N = arr . length ; int K = 5 ; System . out . println ( ways ( N , K , arr ) ) ; } }

Index/key variables: MAX_INDEX, MAX_SUM, count, i, index, j, l, sum
Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int arrSize = 51 ; static int maxSum = 201 ; static int MAX = 100 ; static int inf = 999999 ; static int dp [ ] [ ] = new int [ arrSize ] [ maxSum ] ; static int visit [ ] [ ] = new int [ arrSize ] [ maxSum ] ; static int RetClose ( int a , int b , int s ) { if ( Math . abs ( a - s ) < Math . abs ( b - s ) ) return a ; else return b ; } static int MinDiff ( int i , int sum , int arr [ ] , int n ) { if ( i == n ) return 0 ; if ( visit [ i ] [ sum + MAX ] > 0 ) return dp [ i ] [ sum + MAX ] ; visit [ i ] [ sum + MAX ] = 1 ; dp [ i ] [ sum + MAX ] = RetClose ( arr [ i ] + MinDiff ( i + 1 , sum + arr [ i ] , arr , n ) , MinDiff ( i + 1 , sum , arr , n ) , - 1 * sum ) ; return dp [ i ] [ sum + MAX ] ; } static void FindClose ( int arr [ ] , int n ) { int ans = inf ; for ( int i = 1 ; i <= n ; i ++ ) ans = RetClose ( arr [ i - 1 ] + MinDiff ( i , arr [ i - 1 ] , arr , n ) , ans , 0 ) ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 25 , - 9 , - 10 , - 4 , - 7 , - 33 } ; int n = arr . length ; FindClose ( arr , n ) ; } }

Index/key variables: arrSize, i, maxSum
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int totalPaths ( int i , int j , int n , int grid [ ] [ ] , int dp [ ] [ ] ) { if ( i < 0 j < 0 i >= n j >= n ) return 0 ; if ( dp [ i ] [ j ] == - 1 ) { if ( grid [ i ] [ j ] == 1 ) dp [ i ] [ j ] = totalPaths ( i , j + 1 , n , grid , dp ) ; else if ( grid [ i ] [ j ] == 2 ) dp [ i ] [ j ] = totalPaths ( i + 1 , j , n , grid , dp ) ; else dp [ i ] [ j ] = totalPaths ( i , j + 1 , n , grid , dp ) + totalPaths ( i + 1 , j , n , grid , dp ) ; } return dp [ i ] [ j ] ; } static int maxSumPath ( int i , int j , int n , int grid [ ] [ ] , int dp [ ] [ ] ) { if ( i < 0 j < 0 i >= n j >= n ) return 0 ; if ( dp [ i ] [ j ] == - 1 ) { if ( grid [ i ] [ j ] == 1 ) dp [ i ] [ j ] = grid [ i ] [ j ] + maxSumPath ( i , j + 1 , n , grid , dp ) ; else if ( grid [ i ] [ j ] == 2 ) dp [ i ] [ j ] = grid [ i ] [ j ] + maxSumPath ( i + 1 , j , n , grid , dp ) ; else dp [ i ] [ j ] = grid [ i ] [ j ] + Math . max ( maxSumPath ( i , j + 1 , n , grid , dp ) , maxSumPath ( i + 1 , j , n , grid , dp ) ) ; } return dp [ i ] [ j ] ; } public static void main ( String [ ] args ) { int grid [ ] [ ] = { { 1 , 1 , 3 , 2 , 1 } , { 3 , 2 , 2 , 1 , 2 } , { 1 , 3 , 3 , 1 , 3 } , { 1 , 2 , 3 , 1 , 2 } , { 1 , 1 , 1 , 3 , 1 } } ; int n = grid . length ; int dp [ ] [ ] = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) Arrays . fill ( dp [ i ] , - 1 ) ; dp [ n - 1 ] [ n - 1 ] = 1 ; System . out . println ( " Total ▁ paths : ▁ " + totalPaths ( 0 , 0 , n , grid , dp ) ) ; for ( int i = 0 ; i < n ; i ++ ) Arrays . fill ( dp [ i ] , - 1 ) ; dp [ n - 1 ] [ n - 1 ] = grid [ n - 1 ] [ n - 1 ] ; System . out . println ( " Maximum ▁ sum : ▁ " + maxSumPath ( 0 , 0 , n , grid , dp ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MAX = 100000 ; static int bitscount = 32 ; static int [ ] [ ] prefix_count = new int [ bitscount ] [ MAX ] ; static void findPrefixCount ( int arr [ ] , int n ) { for ( int i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( int j = 1 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ; } } } static int rangeOr ( int l , int r ) { int ans = 0 ; for ( int i = 0 ; i < bitscount ; i ++ ) { int x ; if ( l == 0 ) x = prefix_count [ i ] [ r ] ; else x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ; if ( x != 0 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 5 , 3 , 5 , 2 , 3 } ; int n = arr . length ; findPrefixCount ( arr , n ) ; int queries [ ] [ ] = { { 1 , 3 } , { 4 , 5 } } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ; } }

Index/key variables: MAX, bitscount, i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { static int palindromeSubStrs ( String s ) { int [ ] [ ] dp = new int [ s . length ( ) ] [ s . length ( ) ] ; int st , end , i , len ; HashMap < String , Boolean > m = new HashMap < > ( ) ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { dp [ i ] [ i ] = 1 ; m . put ( s . substring ( i , i + 1 ) , true ) ; } for ( i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { dp [ i ] [ i + 1 ] = 1 ; m . put ( s . substring ( i , i + 2 ) , true ) ; } else dp [ i ] [ i + 1 ] = 0 ; } for ( len = 3 ; len <= s . length ( ) ; len ++ ) { for ( st = 0 ; st <= s . length ( ) - len ; st ++ ) { end = st + len - 1 ; if ( s . charAt ( st ) == s . charAt ( end ) && dp [ st + 1 ] [ end - 1 ] == 1 ) { dp [ st ] [ end ] = 1 ; m . put ( s . substring ( st , end + 1 ) , true ) ; } else dp [ st ] [ end ] = 0 ; } } return m . size ( ) ; } public static void main ( String [ ] args ) { String s = " abaaa " ; System . out . println ( palindromeSubStrs ( s ) ) ; } }

Index/key variables: end, i, st
Accumulator variables: i, len, st
Iterator variables: i, len, st
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int n = 4 , m = 4 ; static int arr [ ] [ ] = { { 1 , 0 , 3 , - 1 } , { 3 , 5 , 1 , - 2 } , { - 2 , 0 , 1 , 1 } , { 2 , 1 , - 1 , 1 } } ; static int cache [ ] [ ] [ ] = new int [ 5 ] [ 5 ] [ 5 ] ; static int sum ( int i1 , int j1 , int i2 , int j2 ) { if ( i1 == i2 && j1 == j2 ) { return arr [ i1 ] [ j1 ] ; } return arr [ i1 ] [ j1 ] + arr [ i2 ] [ j2 ] ; } static int maxSumPath ( int i1 , int j1 , int i2 ) { int j2 = i1 + j1 - i2 ; if ( i1 >= n i2 >= n j1 >= m j2 >= m ) { return 0 ; } if ( cache [ i1 ] [ j1 ] [ i2 ] != - 1 ) { return cache [ i1 ] [ j1 ] [ i2 ] ; } int ans = Integer . MIN_VALUE ; ans = Math . max ( ans , maxSumPath ( i1 + 1 , j1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 , j1 + 1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 , j1 + 1 , i2 + 1 ) + sum ( i1 , j1 , i2 , j2 ) ) ; ans = Math . max ( ans , maxSumPath ( i1 + 1 , j1 , i2 ) + sum ( i1 , j1 , i2 , j2 ) ) ; cache [ i1 ] [ j1 ] [ i2 ] = ans ; return ans ; } public static void main ( String args [ ] ) { for ( int i = 0 ; i < 5 ; i ++ ) for ( int i1 = 0 ; i1 < 5 ; i1 ++ ) for ( int i2 = 0 ; i2 < 5 ; i2 ++ ) cache [ i ] [ i1 ] [ i2 ] = - 1 ; System . out . println ( maxSumPath ( 0 , 0 , 0 ) ) ; } }

Index/key variables: i, i1, i2, j1, j2
Accumulator variables: i, i1, i2
Iterator variables: i, i1, i2
Class/struct names: GFG
Java program:
class GFG { static void BellmanFord ( int graph [ ] [ ] , int V , int E , int src ) { int [ ] dis = new int [ V ] ; for ( int i = 0 ; i < V ; i ++ ) dis [ i ] = Integer . MAX_VALUE ; dis [ src ] = 0 ; for ( int i = 0 ; i < V - 1 ; i ++ ) { for ( int j = 0 ; j < E ; j ++ ) { if ( dis [ graph [ j ] [ 0 ] ] != Integer . MAX_VALUE && dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] < dis [ graph [ j ] [ 1 ] ] ) dis [ graph [ j ] [ 1 ] ] = dis [ graph [ j ] [ 0 ] ] + graph [ j ] [ 2 ] ; } } for ( int i = 0 ; i < E ; i ++ ) { int x = graph [ i ] [ 0 ] ; int y = graph [ i ] [ 1 ] ; int weight = graph [ i ] [ 2 ] ; if ( dis [ x ] != Integer . MAX_VALUE && dis [ x ] + weight < dis [ y ] ) System . out . println ( " Graph ▁ contains ▁ negative " + " ▁ weight ▁ cycle " ) ; } System . out . println ( " Vertex ▁ Distance ▁ from ▁ Source " ) ; for ( int i = 0 ; i < V ; i ++ ) System . out . println ( i + " TABSYMBOL TABSYMBOL " + dis [ i ] ) ; } public static void main ( String [ ] args ) { int graph [ ] [ ] = { { 0 , 1 , - 1 } , { 0 , 2 , 4 } , { 1 , 2 , 3 } , { 1 , 3 , 2 } , { 1 , 4 , 2 } , { 3 , 2 , 5 } , { 3 , 1 , 1 } , { 4 , 3 , - 3 } } ; BellmanFord ( graph , V , E , 0 ) ; } }

Index/key variables: V, i, j, src, x, y
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static int m [ ] , a [ ] [ ] , x [ ] ; static ArrayList < Integer > g [ ] ; static int ans = 0 ; static void dfs ( int u , int p ) { for ( int v : g [ u ] ) { if ( v != p ) { dfs ( v , u ) ; for ( int i = 0 ; i < 22 ; i ++ ) a [ u ] [ i ] += a [ v ] [ i ] ; } } int pp = 0 ; for ( int i = 0 ; i < 22 ; i ++ ) { if ( ! ( ( a [ u ] [ i ] > 0 && x [ i ] - a [ u ] [ i ] > 0 ) || ( a [ u ] [ i ] == 0 && x [ i ] == 0 ) ) ) { pp = 1 ; break ; } } if ( pp == 0 ) ans ++ ; } public static void main ( String args [ ] ) { int n = 4 ; g = new ArrayList [ n + 1 ] ; m = new int [ n + 1 ] ; m [ 1 ] = 1 ; m [ 2 ] = 3 ; m [ 3 ] = 2 ; m [ 4 ] = 3 ; a = new int [ n + 1 ] [ 22 ] ; x = new int [ 22 ] ; for ( int i = 1 ; i <= n ; i ++ ) { g [ i ] = new ArrayList < > ( ) ; int y = m [ i ] ; int k = 0 ; while ( y != 0 ) { int p = y % 2 ; if ( p == 1 ) { x [ k ] ++ ; a [ i ] [ k ] ++ ; } y = y / 2 ; k ++ ; } } g [ 1 ] . add ( 2 ) ; g [ 2 ] . add ( 1 ) ; g [ 1 ] . add ( 3 ) ; g [ 3 ] . add ( 1 ) ; g [ 1 ] . add ( 4 ) ; g [ 4 ] . add ( 1 ) ; dfs ( 1 , 0 ) ; System . out . println ( ans ) ; } }

Index/key variables: i, k, u, v
Accumulator variables: ans, i, k
Iterator variables: i, v
Class/struct names: GFG