dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; public class GFG { public static int maxValue ( int a [ ] , int n , int pos , int moves , int left , int dp [ ] [ ] ) { if ( moves == 0 || ( pos > n - 1 pos < 0 ) ) return 0 ; if ( dp [ pos ] [ left ] != - 1 ) return dp [ pos ] [ left ] ; int value = 0 ; if ( left > 0 && pos >= 1 ) value = Math . max ( value , a [ pos ] + maxValue ( a , n , pos - 1 , moves - 1 , left - 1 , dp ) ) ; if ( pos <= n - 1 ) value = Math . max ( value , a [ pos ] + maxValue ( a , n , pos + 1 , moves - 1 , left , dp ) ) ; return dp [ pos ] [ left ] = value ; } public static void main ( String args [ ] ) { int n = 5 ; int a [ ] = { 1 , 5 , 4 , 3 , 2 } ; int k = 1 ; int m = 4 ; int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ; for ( int i [ ] : dp ) Arrays . fill ( i , - 1 ) ; System . out . println ( ( a [ 0 ] + maxValue ( a , n , 1 , m , k , dp ) ) ) ; } }

Index/key variables: left, pos
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { public static int maximumSum ( int [ ] a , int count , int index , int n , int [ ] [ ] dp ) { if ( index == n ) return 0 ; if ( dp [ index ] [ count ] != - 1 ) return dp [ index ] [ count ] ; int take_element = a [ index ] * count + maximumSum ( a , count + 1 , index + 1 , n , dp ) ; int dont_take = maximumSum ( a , count , index + 1 , n , dp ) ; return dp [ index ] [ count ] = Math . max ( take_element , dont_take ) ; } public static void main ( String args [ ] ) { int n = 5 ; int a [ ] = { - 1 , - 9 , 0 , 5 , - 7 } ; int dp [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ; for ( int i [ ] : dp ) Arrays . fill ( i , - 1 ) ; System . out . println ( maximumSum ( a , 1 , 0 , n , dp ) ) ; } }

Index/key variables: count, index
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int N = 20 ; static boolean visited [ ] = new boolean [ N ] ; static int K ; static int removals = 0 ; static ArrayList < Integer > removed_nodes = new ArrayList < > ( ) ; static ArrayList < ArrayList < Integer > > adj = new ArrayList < > ( ) ; static int dfs ( int s ) { visited [ s ] = true ; int nodes = 1 ; for ( Integer child : adj . get ( s ) ) { if ( visited [ child ] ) continue ; nodes += dfs ( child ) ; } if ( nodes > K ) { removals ++ ; removed_nodes . add ( s ) ; nodes = 0 ; } return nodes ; } static void addEdge ( int a , int b ) { adj . get ( a ) . add ( b ) ; adj . get ( b ) . add ( a ) ; } public static void findRemovedNodes ( int K ) { dfs ( 1 ) ; System . out . println ( " Number ▁ of ▁ nodes " + " ▁ removed : ▁ " + removals ) ; System . out . print ( " Removed ▁ Nodes : ▁ " ) ; for ( int node : removed_nodes ) System . out . print ( node + " ▁ " ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < N ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 3 , 6 ) ; K = 3 ; findRemovedNodes ( K ) ; } }

Index/key variables: N, child, s
Accumulator variables: i, nodes, removals
Iterator variables: child, i, node
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static class pair { int first , second ; pair ( int f , int s ) { this . first = f ; this . second = s ; } } static final int N = ( int ) 1e5 + 5 ; static ArrayList < ArrayList < pair > > v ; static int [ ] dp = new int [ N ] ; static int [ ] leaves = new int [ N ] ; static int n ; static void dfs ( int a , int par ) { int leaf = 1 ; for ( pair i : v . get ( a ) ) { if ( i . first == par ) continue ; leaf = 0 ; dfs ( i . first , a ) ; } if ( leaf == 1 ) { leaves [ a ] += 1 ; } else { for ( pair i : v . get ( a ) ) { if ( i . first == par ) continue ; leaves [ a ] += leaves [ i . first ] ; dp [ a ] = dp [ a ] + dp [ i . first ] + leaves [ i . first ] * i . second ; } } } static void dfs2 ( int a , int par ) { for ( pair i : v . get ( a ) ) { if ( i . first == par ) continue ; int leafOutside = leaves [ a ] - leaves [ i . first ] ; dp [ i . first ] += ( dp [ a ] - dp [ i . first ] ) ; dp [ i . first ] += i . second * ( leafOutside - leaves [ i . first ] ) ; leaves [ i . first ] += leafOutside ; dfs2 ( i . first , a ) ; } } static void answerQueries ( int [ ] queries ) { dfs ( 1 , 0 ) ; dfs2 ( 1 , 0 ) ; for ( int i = 0 ; i < queries . length ; i ++ ) { System . out . println ( dp [ queries [ i ] ] ) ; } } public static void main ( String [ ] args ) { n = 5 ; v = new ArrayList < > ( ) ; for ( int i = 0 ; i <= n ; i ++ ) v . add ( new ArrayList < pair > ( ) ) ; v . get ( 1 ) . add ( new pair ( 4 , 4 ) ) ; v . get ( 4 ) . add ( new pair ( 1 , 4 ) ) ; v . get ( 1 ) . add ( new pair ( 2 , 2 ) ) ; v . get ( 2 ) . add ( new pair ( 1 , 2 ) ) ; v . get ( 2 ) . add ( new pair ( 3 , 3 ) ) ; v . get ( 3 ) . add ( new pair ( 2 , 3 ) ) ; v . get ( 2 ) . add ( new pair ( 5 , 5 ) ) ; v . get ( 5 ) . add ( new pair ( 2 , 5 ) ) ; int [ ] queries = { 1 , 3 , 5 } ; answerQueries ( queries ) ; } }

Index/key variables: N, a, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int N = 7 ; static int countChanges ( int matrix [ ] [ ] , int n , int m ) { int i , j , dist = n + m - 1 ; int Max_element = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { Max_element = Math . max ( Max_element , matrix [ i ] [ j ] ) ; } } int freq [ ] [ ] = new int [ dist ] [ Max_element + 1 ] ; for ( i = 0 ; i < dist ; i ++ ) { for ( j = 0 ; j < Max_element + 1 ; j ++ ) freq [ i ] [ j ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { freq [ i + j ] [ matrix [ i ] [ j ] ] ++ ; } } int min_changes_sum = 0 ; for ( i = 0 ; i < dist / 2 ; i ++ ) { int maximum = 0 ; int total_values = 0 ; for ( j = 0 ; j < Max_element + 1 ; j ++ ) { maximum = Math . max ( maximum , freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ) ; total_values += freq [ i ] [ j ] + freq [ n + m - 2 - i ] [ j ] ; } min_changes_sum += total_values - maximum ; } return min_changes_sum ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 7 , 0 , 3 , 1 , 8 , 1 , 3 } , { 0 , 4 , 0 , 1 , 0 , 4 , 0 } , { 3 , 1 , 8 , 3 , 1 , 0 , 7 } } ; int minChanges = countChanges ( mat , 3 , 7 ) ; System . out . print ( minChanges ) ; } }

Index/key variables: dist, i, j
Accumulator variables: i, j, min_changes_sum, total_values
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] [ ] [ ] dp = new int [ 1002 ] [ 10 ] [ 2 ] [ 2 ] ; static int possibleNumbers ( int pos , int previous , int tight , int start , String N , int K ) { if ( pos == N . length ( ) ) return 1 ; if ( dp [ pos ] [ previous ] [ tight ] [ start ] != - 1 ) return dp [ pos ] [ previous ] [ tight ] [ start ] ; int res = 0 ; int upper_limit = ( tight == 1 ) ? ( N . charAt ( pos ) - '0' ) : 9 ; int new_tight ; if ( start == 0 ) { res = possibleNumbers ( pos + 1 , previous , 0 , 0 , N , K ) ; for ( int i = 1 ; i <= upper_limit ; i ++ ) { new_tight = ( tight > 0 && i == upper_limit ) ? 1 : 0 ; res += possibleNumbers ( pos + 1 , i , new_tight , 1 , N , K ) ; } } else { for ( int i = 0 ; i <= upper_limit ; i ++ ) { new_tight = ( tight > 0 && i == upper_limit ) ? 1 : 0 ; if ( Math . abs ( i - previous ) <= K ) res += possibleNumbers ( pos + 1 , i , new_tight , 1 , N , K ) ; } } dp [ pos ] [ previous ] [ tight ] [ start ] = res ; return dp [ pos ] [ previous ] [ tight ] [ start ] ; } public static void main ( String [ ] args ) { String N = "20" ; int K = 2 ; for ( int i = 0 ; i < 1002 ; i ++ ) for ( int j = 0 ; j < 10 ; j ++ ) for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; System . out . print ( possibleNumbers ( 0 , 0 , 1 , 0 , N , K ) + "NEW_LINE"); } }

Index/key variables: i, j, k, l, pos, previous, start, tight
Accumulator variables: i, j, k, l, res
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int mergeTwoNumbers ( int [ ] numbers ) { int len , i , j , k ; int n = numbers . length ; if ( numbers . length == 0 ) { return 0 ; } int [ ] prefixSum = new int [ n + 1 ] ; for ( i = 1 ; i <= n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + numbers [ i - 1 ] ; } int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ; for ( len = 2 ; len <= n ; len ++ ) { for ( i = 1 ; i <= n - len + 1 ; i ++ ) { j = i + len - 1 ; int sum = prefixSum [ j ] - prefixSum [ i - 1 ] ; dp [ i ] [ j ] = Integer . MAX_VALUE ; for ( k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] + sum ) ; } } } return dp [ 1 ] [ n ] ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 6 , 4 , 4 , 6 } ; System . out . print ( mergeTwoNumbers ( arr1 ) + "NEW_LINE"); } }

Index/key variables: i, j, k, n
Accumulator variables: i, k, len
Iterator variables: i, k, len
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { static int [ ] dp1 = new int [ 100005 ] ; static int [ ] dp2 = new int [ 100005 ] ; static void dfs1 ( int u , int par , Vector < Vector < Integer > > g , int [ ] weight ) { dp1 [ u ] = weight [ u ] ; for ( int c = 0 ; c < g . get ( u ) . size ( ) ; c ++ ) { if ( g . get ( u ) . get ( c ) != par ) { dfs1 ( g . get ( u ) . get ( c ) , u , g , weight ) ; dp1 [ u ] += Math . max ( 0 , dp1 [ g . get ( u ) . get ( c ) ] ) ; } } } static void dfs2 ( int u , int par , Vector < Vector < Integer > > g , int [ ] weight ) { if ( par != 0 ) { int maxSumAncestors = dp2 [ par ] - Math . max ( 0 , dp1 [ u ] ) ; dp2 [ u ] = dp1 [ u ] + Math . max ( 0 , maxSumAncestors ) ; } for ( int c = 0 ; c < g . get ( u ) . size ( ) ; c ++ ) { if ( g . get ( u ) . get ( c ) != par ) { dfs2 ( g . get ( u ) . get ( c ) , u , g , weight ) ; } } } static void addEdge ( int u , int v , Vector < Vector < Integer > > g ) { g . get ( u ) . add ( v ) ; g . get ( v ) . add ( u ) ; } static void maxSumSegments ( Vector < Vector < Integer > > g , int [ ] weight , int n ) { dfs1 ( 1 , 0 , g , weight ) ; for ( int i = 1 ; i < n + 1 ; i ++ ) dp2 [ i ] = dp1 [ i ] ; dfs2 ( 1 , 0 , g , weight ) ; } static void printAns ( int n ) { for ( int i = 1 ; i < n ; i ++ ) System . out . print ( dp2 [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 7 ; Vector < Vector < Integer > > g = new Vector < Vector < Integer > > ( ) ; for ( int i = 0 ; i < 100005 ; i ++ ) { g . add ( new Vector < Integer > ( ) ) ; } addEdge ( 1 , 2 , g ) ; addEdge ( 1 , 3 , g ) ; addEdge ( 2 , 4 , g ) ; addEdge ( 2 , 5 , g ) ; addEdge ( 3 , 6 , g ) ; addEdge ( 4 , 7 , g ) ; int [ ] weight = new int [ n + 1 ] ; weight [ 1 ] = - 8 ; weight [ 2 ] = 9 ; weight [ 3 ] = 7 ; weight [ 4 ] = - 4 ; weight [ 5 ] = 5 ; weight [ 6 ] = - 10 ; weight [ 7 ] = - 6 ; maxSumSegments ( g , weight , n ) ; printAns ( n ) ; } }

Index/key variables: i, par, u
Accumulator variables: c, i
Iterator variables: c, i
Class/struct names: Main
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int countPairs ( int [ ] arr , int N ) { int maxm = arr [ 0 ] ; for ( int j = 1 ; j < N ; j ++ ) { if ( maxm < arr [ j ] ) { maxm = arr [ j ] ; } } int i , k = 0 ; int [ ] bitscount = new int [ maxm + 1 ] ; Arrays . fill ( bitscount , 0 ) ; for ( i = 1 ; i <= maxm ; i *= 2 ) bitscount [ i ] = 1 ; for ( i = 1 ; i <= maxm ; i ++ ) { if ( bitscount [ i ] == 1 ) k = i ; if ( bitscount [ i ] == 0 ) { bitscount [ i ] = bitscount [ k ] + bitscount [ i - k ] ; } } Map < Integer , Integer > setbits = new HashMap < > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { setbits . put ( bitscount [ arr [ j ] ] , setbits . getOrDefault ( bitscount [ arr [ j ] ] , 0 ) + 1 ) ; } int ans = 0 ; for ( int it : setbits . values ( ) ) { ans += it * ( it - 1 ) / 2 ; } return ans ; } public static void main ( String [ ] args ) { int N = 12 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 } ; System . out . println ( countPairs ( arr , N ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: ans, i, j
Iterator variables: i, it, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void depthFirst ( int v , List < List < Integer > > graph , boolean [ ] visited , List < Integer > storeChain ) { visited [ v ] = true ; storeChain . add ( v ) ; for ( int i : graph . get ( v ) ) { if ( visited [ i ] == false ) { depthFirst ( i , graph , visited , storeChain ) ; } } } static int subarraySum ( int arr [ ] , int n ) { int maxSubarraySum = arr [ 0 ] ; int currentMax = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { currentMax = Math . max ( arr [ i ] , arr [ i ] + currentMax ) ; maxSubarraySum = Math . max ( maxSubarraySum , currentMax ) ; } return maxSubarraySum ; } static void maxSubarraySum ( List < List < Integer > > graph , int vertices , List < Integer > values ) { boolean [ ] visited = new boolean [ 1001 ] ; int maxSum = Integer . MIN_VALUE ; for ( int i = 1 ; i <= vertices ; i ++ ) { if ( visited [ i ] == false ) { int sizeChain ; int tempSum ; List < Integer > storeChain = new ArrayList < Integer > ( ) ; depthFirst ( i , graph , visited , storeChain ) ; sizeChain = storeChain . size ( ) ; int [ ] chainValues = new int [ sizeChain + 1 ] ; for ( int j = 0 ; j < sizeChain ; j ++ ) { int temp = values . get ( storeChain . get ( j ) - 1 ) ; chainValues [ j ] = temp ; } tempSum = subarraySum ( chainValues , sizeChain ) ; if ( tempSum > maxSum ) { maxSum = tempSum ; } } } System . out . print ( " Maximum ▁ subarray ▁ sum ▁ among ▁ all ▁ " ) ; System . out . print ( " connected ▁ components ▁ = ▁ " ) ; System . out . print ( maxSum ) ; } public static void main ( String [ ] args ) { List < List < Integer > > graph = new ArrayList ( ) ; for ( int i = 0 ; i < 1001 ; i ++ ) graph . add ( new ArrayList < Integer > ( ) ) ; int E = 4 , V = 7 ; List < Integer > values = new ArrayList < Integer > ( ) ; values . add ( 3 ) ; values . add ( 2 ) ; values . add ( 4 ) ; values . add ( - 2 ) ; values . add ( 0 ) ; values . add ( - 1 ) ; values . add ( - 5 ) ; graph . get ( 1 ) . add ( 2 ) ; graph . get ( 2 ) . add ( 1 ) ; graph . get ( 3 ) . add ( 4 ) ; graph . get ( 4 ) . add ( 3 ) ; graph . get ( 4 ) . add ( 5 ) ; graph . get ( 5 ) . add ( 4 ) ; graph . get ( 6 ) . add ( 7 ) ; graph . get ( 7 ) . add ( 6 ) ; maxSubarraySum ( graph , V , values ) ; } }

Index/key variables: i, j, v
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] dp = new int [ 1000 ] [ 1000 ] ; static int solve ( int n , int k , int m ) { if ( n == 0 && k == 0 ) return 1 ; if ( n == 0 && k != 0 ) return 0 ; if ( n != 0 && k == 0 ) return 0 ; if ( n < 0 k < 0 ) return 0 ; if ( dp [ n ] [ k ] > 0 ) return dp [ n ] [ k ] ; int ans = 0 ; for ( int j = 1 ; j <= m ; j ++ ) { ans += solve ( n - j , k - 1 , m ) ; } return dp [ n ] [ k ] = ans ; } public static void main ( String [ ] args ) { int N = 7 , K = 4 , M = 3 ; System . out . print ( solve ( N , K , M ) ) ; } }

Index/key variables: k, n
Accumulator variables: ans, j
Iterator variables: j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printMatrix ( int [ ] [ ] A ) { for ( int i = 0 ; i < A . length ; i ++ ) { for ( int j = 0 ; j < A [ 0 ] . length ; j ++ ) System . out . print ( A [ i ] [ j ] + " ▁ " ) ; System . out . print ( 'NEW_LINE'); } } static void copyMatrix ( int [ ] [ ] A , int [ ] [ ] B ) { int row = B . length ; int col = B [ 0 ] . length ; for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) { A [ i ] [ j ] = B [ i ] [ j ] ; } } } static int [ ] [ ] getMaxNeighbour ( int [ ] [ ] A , int K ) { int [ ] [ ] ans = new int [ A . length ] [ A [ 0 ] . length ] ; copyMatrix ( ans , A ) ; for ( int q = 1 ; q <= K ; q ++ ) { for ( int i = 0 ; i < A . length ; i ++ ) { for ( int j = 0 ; j < A [ 0 ] . length ; j ++ ) { int maxi = ans [ i ] [ j ] ; if ( i > 0 ) maxi = Math . max ( maxi , ans [ i - 1 ] [ j ] ) ; if ( j > 0 ) maxi = Math . max ( maxi , ans [ i ] [ j - 1 ] ) ; if ( i < A . length - 1 ) maxi = Math . max ( maxi , ans [ i + 1 ] [ j ] ) ; if ( j < A [ 0 ] . length - 1 ) maxi = Math . max ( maxi , ans [ i ] [ j + 1 ] ) ; A [ i ] [ j ] = maxi ; } } copyMatrix ( ans , A ) ; } return ans ; } public static void main ( String [ ] args ) { int [ ] [ ] B = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; printMatrix ( getMaxNeighbour ( B , 2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, q
Iterator variables: i, j, q
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static ArrayList < Integer > prime = new ArrayList < Integer > ( ) ; static boolean [ ] isprime = new boolean [ 1000 ] ; static int [ ] [ ] [ ] dp = new int [ 200 ] [ 20 ] [ 1000 ] ; static void sieve ( ) { for ( int i = 0 ; i < 1000 ; i ++ ) isprime [ i ] = true ; for ( int i = 2 ; i * i < 1000 ; i ++ ) { if ( isprime [ i ] ) { for ( int j = i * i ; j < 1000 ; j += i ) { isprime [ j ] = false ; } } } for ( int i = 2 ; i < 1000 ; i ++ ) { if ( isprime [ i ] ) { prime . add ( i ) ; } } } static int CountWays ( int i , int j , int sum , int n , int k ) { if ( i >= prime . size ( ) - 1 sum > n ) { return 0 ; } if ( sum == n ) { if ( j == k ) { return 1 ; } return 0 ; } if ( j == k ) return 0 ; if ( dp [ i ] [ j ] [ sum ] != 0 ) return dp [ i ] [ j ] [ sum ] ; int inc = 0 , exc = 0 ; inc = CountWays ( i + 1 , j + 1 , sum + prime . get ( i ) , n , k ) ; exc = CountWays ( i + 1 , j , sum , n , k ) ; return dp [ i ] [ j ] [ sum ] = inc + exc ; } public static void main ( String [ ] args ) { sieve ( ) ; int N = 100 , K = 5 ; System . out . println ( CountWays ( 0 , 0 , 0 , N , K ) ) ; } }

Index/key variables: i, j, sum
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] factors = new Vector [ 100005 ] ; static int [ ] dp = new int [ 100005 ] ; static void precompute ( ) { for ( int i = 1 ; i <= 100000 ; i ++ ) { for ( int j = i ; j <= 100000 ; j += i ) factors [ j ] . add ( i ) ; } } static int solve ( int arr [ ] , int n ) { for ( int i = 0 ; i < 100005 ; i ++ ) { dp [ i ] = Integer . MAX_VALUE ; } dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j : factors [ arr [ i ] ] ) { if ( i + j < n ) dp [ i + j ] = Math . min ( dp [ i + j ] , 1 + dp [ i ] ) ; } } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < factors . length ; i ++ ) factors [ i ] = new Vector < Integer > ( ) ; precompute ( ) ; int arr [ ] = { 2 , 8 , 16 , 55 , 99 , 100 } ; int n = arr . length ; System . out . print ( solve ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int dp [ ] [ ] = new int [ 5000 ] [ 1029 ] ; static int getmask ( int val ) { int mask = 0 ; int prime [ ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 } ; for ( int i = 0 ; i < 15 ; i ++ ) { if ( val % prime [ i ] == 0 ) { mask = mask | ( 1 << i ) ; } } return mask ; } static int calculate ( int pos , int mask , int a [ ] , int n ) { if ( pos == n || mask == ( int ) ( 1 << n - 1 ) ) return 0 ; if ( dp [ pos ] [ mask ] != - 1 ) return dp [ pos ] [ mask ] ; int size = 0 ; size = Math . max ( size , calculate ( pos + 1 , mask , a , n ) ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; size = Math . max ( size , 1 + calculate ( pos + 1 , new_mask , a , n ) ) ; } return dp [ pos ] [ mask ] = size ; } static int largestSubset ( int a [ ] , int n ) { for ( int i = 0 ; i < 5000 ; i ++ ) Arrays . fill ( dp [ i ] , - 1 ) ; return calculate ( 0 , 0 , a , n ) ; } public static void main ( String args [ ] ) { int A [ ] = { 2 , 3 , 13 , 5 , 14 , 6 , 7 , 11 } ; int N = A . length ; System . out . println ( largestSubset ( A , N ) ) ; } }

Index/key variables: i, mask, pos
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MaximumSum ( int a [ ] , int n ) { int [ ] [ ] dp = new int [ n + 1 ] [ 2 ] ; dp [ 2 ] [ 1 ] = a [ 1 ] ; dp [ 2 ] [ 0 ] = a [ 0 ] ; for ( int i = 3 ; i < n + 1 ; i ++ ) { if ( i % 2 == 1 ) { int temp = Math . max ( ( Math . max ( dp [ i - 3 ] [ 1 ] , dp [ i - 3 ] [ 0 ] ) ) , Math . max ( dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] ) ) ; dp [ i ] [ 1 ] = a [ i - 1 ] + temp ; dp [ i ] [ 0 ] = Math . max ( ( Math . max ( a [ i - 2 ] + dp [ i - 2 ] [ 0 ] , a [ i - 2 ] + dp [ i - 3 ] [ 1 ] ) ) , Math . max ( a [ i - 2 ] + dp [ i - 3 ] [ 0 ] , a [ i - 3 ] + dp [ i - 3 ] [ 0 ] ) ) ; } else { dp [ i ] [ 1 ] = a [ i - 1 ] + ( Math . max ( ( Math . max ( dp [ i - 2 ] [ 1 ] , dp [ i - 2 ] [ 0 ] ) ) , dp [ i - 1 ] [ 0 ] ) ) ; dp [ i ] [ 0 ] = a [ i - 2 ] + dp [ i - 2 ] [ 0 ] ; } } return Math . max ( dp [ n ] [ 1 ] , dp [ n ] [ 0 ] ) ; } static int max ( int [ ] arr ) { return 1 ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = A . length ; System . out . print ( MaximumSum ( A , N ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int divisorGame ( int N , int A , int dp [ ] [ ] ) { if ( N == 1 N == 3 ) return 0 ; if ( N == 2 ) return 1 ; if ( dp [ N ] [ A ] != - 1 ) return dp [ N ] [ A ] ; int ans = ( A == 1 ) ? 0 : 1 ; for ( int i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { if ( A == 1 ) ans |= divisorGame ( N - i , 0 , dp ) ; else ans &= divisorGame ( N - i , 1 , dp ) ; } } return dp [ N ] [ A ] = ans ; } public static void main ( String [ ] args ) { int N = 3 ; int [ ] [ ] dp = new int [ N + 1 ] [ 2 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } if ( divisorGame ( N , 1 , dp ) == 1 ) System . out . print ( " Player ▁ A ▁ wins " ) ; else System . out . print ( " Player ▁ B ▁ wins " ) ; } }

Index/key variables: A, N, i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 100 ; static int countMountains ( int a [ ] [ ] , int n ) { int [ ] [ ] A = new int [ n + 2 ] [ n + 2 ] ; int count = 0 ; for ( int i = 0 ; i < n + 2 ; i ++ ) { for ( int j = 0 ; j < n + 2 ; j ++ ) { if ( ( i == 0 ) || ( j == 0 ) || ( i == n + 1 ) || ( j == n + 1 ) ) { A [ i ] [ j ] = Integer . MIN_VALUE ; } else { A [ i ] [ j ] = a [ i - 1 ] [ j - 1 ] ; } } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( ( A [ i ] [ j ] > A [ i - 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j ] ) && ( A [ i ] [ j ] > A [ i ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j - 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i - 1 ] [ j + 1 ] ) && ( A [ i ] [ j ] > A [ i + 1 ] [ j - 1 ] ) ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int n = 3 ; System . out . print ( countMountains ( a , n ) ) ; } }

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