dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . lang . * ; import java . util . * ; class GFG { static final long MAX = ( long ) 1e18 ; static long n , m ; static List < List < Long > > v = new ArrayList < > ( 151 ) ; static long [ ] [ ] dp = new long [ 151 ] [ 151 ] ; static long min_operation ( long i , long j , long val , long x ) { if ( i == n - 1 && j == m - 1 ) { if ( val > v . get ( ( int ) i ) . get ( ( int ) j ) ) { return dp [ ( int ) i ] [ ( int ) j ] = MAX ; } else { return dp [ ( int ) i ] [ ( int ) j ] = v . get ( ( int ) i ) . get ( ( int ) j ) - val ; } } if ( i == n j == m ) { return dp [ ( int ) i ] [ ( int ) j ] = MAX ; } if ( dp [ ( int ) i ] [ ( int ) j ] != - 1 ) { return dp [ ( int ) i ] [ ( int ) j ] ; } if ( val > v . get ( ( int ) i ) . get ( ( int ) j ) ) { return dp [ ( int ) i ] [ ( int ) j ] = MAX ; } long tmp = v . get ( ( int ) i ) . get ( ( int ) j ) - val ; tmp += Math . min ( min_operation ( i + 1 , j , val + x , x ) , min_operation ( i , j + 1 , val + x , x ) ) ; return dp [ ( int ) i ] [ ( int ) j ] = tmp ; } static long solve ( long x ) { long ans = Long . MAX_VALUE ; for ( long i = 0 ; i < n ; i ++ ) { for ( long j = 0 ; j < m ; j ++ ) { long val = v . get ( ( int ) i ) . get ( ( int ) j ) - x * ( i + j ) ; for ( int k = 0 ; k < dp . length ; k ++ ) for ( int l = 0 ; l < dp [ k ] . length ; l ++ ) dp [ k ] [ l ] = - 1 ; val = min_operation ( 0l , 0l , val , x ) ; ans = Math . min ( ans , val ) ; } } return ans ; } public static void main ( String [ ] args ) { n = 2 ; m = 2 ; long x = 3 ; v . add ( Arrays . asList ( 15l , 153l ) ) ; v . add ( Arrays . asList ( 135l , 17l ) ) ; System . out . println ( solve ( x ) ) ; } }

Index/key variables: k, l
Accumulator variables: i, j, k, l, tmp
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int printAllSubsetsRec ( int arr [ ] , int n , ArrayList < Integer > v , int sum ) { if ( sum == 0 ) { return ( int ) v . size ( ) ; } if ( sum < 0 ) return Integer . MAX_VALUE ; if ( n == 0 ) return Integer . MAX_VALUE ; int x = printAllSubsetsRec ( arr , n - 1 , v , sum ) ; v . add ( arr [ n - 1 ] ) ; int y = printAllSubsetsRec ( arr , n , v , sum - arr [ n - 1 ] ) ; v . remove ( v . size ( ) - 1 ) ; return Math . min ( x , y ) ; } static int printAllSubsets ( int arr [ ] , int n , int sum ) { ArrayList < Integer > v = new ArrayList < > ( ) ; return printAllSubsetsRec ( arr , n , v , sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 4 , 3 , 5 , 6 } ; int sum = 6 ; int n = arr . length ; System . out . println ( printAllSubsets ( arr , n , sum ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int Count ( int S [ ] , int m , int n ) { int [ ] [ ] table = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { table [ 0 ] [ i ] = Integer . MAX_VALUE - 1 ; } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( S [ i - 1 ] > j ) { table [ i ] [ j ] = table [ i - 1 ] [ j ] ; } else { table [ i ] [ j ] = Math . min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) ; } } } return table [ m ] [ n ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 9 , 6 , 5 , 1 } ; int m = arr . length ; System . out . print ( Count ( arr , m , 11 ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static final int INF = 10000000 ; static int maximum ( int A , int B , int C , int D ) { return Math . max ( Math . max ( A , B ) , Math . max ( C , D ) ) ; } static int maxProductUtil ( int X , int Y , int [ ] A , int [ ] B , int [ ] [ ] dp ) { if ( X < 0 Y < 0 ) return - INF ; if ( dp [ X ] [ Y ] != - 1 ) return dp [ X ] [ Y ] ; dp [ X ] [ Y ] = maximum ( A [ X ] * B [ Y ] + maxProductUtil ( X - 1 , Y - 1 , A , B , dp ) , A [ X ] * B [ Y ] , maxProductUtil ( X - 1 , Y , A , B , dp ) , maxProductUtil ( X , Y - 1 , A , B , dp ) ) ; return dp [ X ] [ Y ] ; } static int maxProduct ( int A [ ] , int N , int B [ ] , int M ) { int [ ] [ ] dp = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return maxProductUtil ( N - 1 , M - 1 , A , B , dp ) ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , 6 , - 2 , - 5 } ; int b [ ] = { - 3 , 4 , - 2 , 8 } ; int n = a . length ; int m = b . length ; System . out . print ( maxProduct ( a , n , b , m ) ) ; } }

Index/key variables: M, N, X, Y, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void twoStringsEquality ( String s , String t ) { int n = s . length ( ) ; int [ ] [ ] dp = new int [ n ] [ n + 1 ] ; if ( s . charAt ( n - 1 ) == t . charAt ( 0 ) ) dp [ n - 1 ] [ 1 ] = 1 ; if ( s . charAt ( n - 1 ) == t . charAt ( n - 1 ) ) dp [ n - 1 ] [ 0 ] = 1 ; for ( int i = n - 1 ; i > 0 ; i -- ) { for ( int j = 0 ; j <= n - i ; j ++ ) { if ( dp [ i ] [ j ] > 0 ) { if ( s . charAt ( i - 1 ) == t . charAt ( j ) ) dp [ i - 1 ] [ j + 1 ] = 1 ; if ( s . charAt ( i - 1 ) == t . charAt ( i + j - 1 ) ) dp [ i - 1 ] [ j ] = 1 ; } } } boolean ans = false ; for ( int i = 0 ; i <= n ; i ++ ) { if ( dp [ 0 ] [ i ] == 1 ) { ans = true ; break ; } } if ( ans == true ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } public static void main ( String [ ] args ) { String S = " abab " ; String T = " baab " ; twoStringsEquality ( S , T ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: ans
Class/struct names: GFG
Java program:
class GFG { static int findSum ( int [ ] arr , int n ) { int totalSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { totalSum += arr [ i ] ; } int [ ] [ ] dp = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { dp [ 0 ] [ i ] = 1 ; dp [ 1 ] [ i ] = arr [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { if ( dp [ 0 ] [ i ] < dp [ 0 ] [ j ] + 1 ) { dp [ 0 ] [ i ] = dp [ 0 ] [ j ] + 1 ; dp [ 1 ] [ i ] = dp [ 1 ] [ j ] + arr [ i ] ; } else if ( dp [ 0 ] [ i ] == dp [ 0 ] [ j ] + 1 ) { dp [ 1 ] [ i ] = Math . min ( dp [ 1 ] [ i ] , dp [ 1 ] [ j ] + arr [ i ] ) ; } } } } int maxm = 0 ; int subtractSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp [ 0 ] [ i ] > maxm ) { maxm = dp [ 0 ] [ i ] ; subtractSum = dp [ 1 ] [ i ] ; } else if ( dp [ 0 ] [ i ] == maxm ) { subtractSum = Math . min ( subtractSum , dp [ 1 ] [ i ] ) ; } } return totalSum - subtractSum ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 1 , 2 , 3 , 8 } ; int n = arr . length ; System . out . print ( findSum ( arr , n ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, totalSum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int count ( int n ) { if ( n == 2 ) return 1 ; else if ( n == 4 ) return 2 ; else if ( n == 6 ) return 4 ; int table [ ] = new int [ n + 1 ] ; int i ; for ( i = 0 ; i < n + 1 ; i ++ ) table [ i ] = 0 ; table [ 0 ] = 0 ; table [ 2 ] = 1 ; table [ 4 ] = 2 ; table [ 6 ] = 4 ; for ( i = 8 ; i <= n ; i = i + 2 ) { table [ i ] = table [ i - 2 ] + table [ i - 4 ] + table [ i - 6 ] ; } return table [ n ] ; } public static void main ( String args [ ] ) { int n = 8 ; System . out . print ( count ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MOD = 1000000007 ; static boolean isPrime ( String number ) { int num = Integer . valueOf ( number ) ; for ( int i = 2 ; i * i <= num ; i ++ ) { if ( ( num % i ) == 0 ) return false ; } return num > 1 ? true : false ; } static int countPrimeStrings ( String number , int i ) { if ( i == 0 ) return 1 ; int cnt = 0 ; for ( int j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number . charAt ( i - j ) != '0' && isPrime ( number . substring ( i - j , i ) ) ) { cnt += countPrimeStrings ( number , i - j ) ; cnt %= MOD ; } } return cnt ; } public static void main ( String [ ] args ) { String s1 = "3175" ; int l = s1 . length ( ) ; System . out . print ( countPrimeStrings ( s1 , l ) ) ; } }

Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MOD = 1000000007 ; static boolean [ ] sieve = new boolean [ 1000000 ] ; static void buildSieve ( ) { Arrays . fill ( sieve , true ) ; sieve [ 0 ] = false ; sieve [ 1 ] = false ; for ( int p = 2 ; p * p <= 1000000 ; p ++ ) { if ( sieve [ p ] == true ) { for ( int i = p * p ; i < 1000000 ; i += p ) sieve [ i ] = false ; } } } static boolean isPrime ( String number ) { int num = Integer . valueOf ( number ) ; return sieve [ num ] ; } static int rec ( String number , int i , int [ ] dp ) { if ( dp [ i ] != - 1 ) return dp [ i ] ; int cnt = 0 ; for ( int j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number . charAt ( i - j ) != '0' && isPrime ( number . substring ( i - j , i ) ) ) { cnt += rec ( number , i - j , dp ) ; cnt %= MOD ; } } return dp [ i ] = cnt ; } static int countPrimeStrings ( String number ) { int n = number . length ( ) ; int [ ] dp = new int [ n + 1 ] ; Arrays . fill ( dp , - 1 ) ; dp [ 0 ] = 1 ; return rec ( number , n , dp ) ; } public static void main ( String [ ] args ) { buildSieve ( ) ; String s1 = "3175" ; System . out . print ( countPrimeStrings ( s1 ) + "NEW_LINE"); } }

Index/key variables: i, num, p
Accumulator variables: cnt, i, j, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int squareOfZeroes ( int [ ] [ ] matrix ) { int lastIdx = matrix . length - 1 ; Map < String , Boolean > cache = new HashMap < String , Boolean > ( ) ; return ( hasSquareOfZeroes ( matrix , 0 , 0 , lastIdx , lastIdx , cache ) ) ? 1 : 0 ; } static boolean hasSquareOfZeroes ( int [ ] [ ] matrix , int r1 , int c1 , int r2 , int c2 , Map < String , Boolean > cache ) { if ( r1 >= r2 c1 >= c2 ) return false ; String key = r1 + " - " + c1 + " - " + r2 + " - " + c2 ; if ( cache . containsKey ( key ) ) return cache . get ( key ) ; cache . put ( key , isSquareOfZeroes ( matrix , r1 , c1 , r2 , c2 ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 - 1 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 + 1 , r2 - 1 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 , r2 , c2 - 1 , cache ) || hasSquareOfZeroes ( matrix , r1 + 1 , c1 + 1 , r2 , c2 , cache ) || hasSquareOfZeroes ( matrix , r1 , c1 , r2 - 1 , c2 - 1 , cache ) ) ; return cache . get ( key ) ; } static boolean isSquareOfZeroes ( int [ ] [ ] matrix , int r1 , int c1 , int r2 , int c2 ) { for ( int row = r1 ; row < r2 + 1 ; row ++ ) { if ( matrix [ row ] [ c1 ] != 0 matrix [ row ] [ c2 ] != 0 ) return false ; } for ( int col = c1 ; col < c2 + 1 ; col ++ ) { if ( matrix [ r1 ] [ col ] != 0 matrix [ r2 ] [ col ] != 0 ) return false ; } return true ; } public static void main ( String [ ] args ) { int [ ] [ ] matrix = { { 1 , 1 , 1 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 1 , 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 1 , 0 , 1 } , { 0 , 1 , 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 1 } } ; int ans ; ans = squareOfZeroes ( matrix ) ; if ( ans == 1 ) { System . out . println ( " True " ) ; } else { System . out . println ( " False " ) ; } } }

Index/key variables: c1, c2, col, r1, r2, row
Accumulator variables: col, row
Iterator variables: col, row
Class/struct names: GFG
Java program:
class GFG { public static void CountWays ( int a , int b , int c ) { int x = b + c + 1 ; int [ ] arr = new int [ x ] ; for ( int i = a ; i <= b ; i ++ ) { for ( int j = b ; j <= c ; j ++ ) { arr [ i + j ] ++ ; } } for ( int i = 1 ; i < x ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int a = 1 ; int b = 2 ; int c = 2 ; CountWays ( a , b , c ) ; } }

Index/key variables: i, x
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void CountWays ( int a , int b , int c ) { int x = b + c + 2 ; int arr [ ] = new int [ x ] ; for ( int i = 1 ; i <= b ; i ++ ) { arr [ i + b ] ++ ; arr [ i + c + 1 ] -- ; } for ( int i = 1 ; i < x - 1 ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; System . out . print ( arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int a = 1 ; int b = 2 ; int c = 2 ; CountWays ( a , b , c ) ; } }

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void differentStrings ( String s ) { int n = s . length ( ) ; int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i - 1 ) && ( s . charAt ( i ) == '1' || s . charAt ( i ) == '2' ) ) dp [ i + 1 ] = dp [ i ] + dp [ i - 1 ] ; else dp [ i + 1 ] = dp [ i ] ; } System . out . println ( dp [ n ] ) ; } public static void main ( String [ ] args ) { String S = "0111022110" ; differentStrings ( S ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int Col = 3 ; static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int sumPathCost ( int grid [ ] [ ] , int m , int n ) { int sum = 0 , count ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { count = nCr ( i + j , i ) * nCr ( m + n - i - j , m - i ) ; sum += count * grid [ i ] [ j ] ; } } return sum ; } public static void main ( String [ ] args ) { int m = 2 ; int n = 2 ; int grid [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; System . out . println ( sumPathCost ( grid , m , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int K ; static int N ; static Vector < Integer > v = new Vector < > ( ) ; static int [ ] [ ] [ ] [ ] [ ] dp = new int [ 20 ] [ 1000 ] [ 10 ] [ 2 ] [ 2 ] ; static void init ( int x ) { for ( int i = 0 ; i < 20 ; i ++ ) for ( int j = 0 ; j < 1000 ; j ++ ) for ( int k = 0 ; k < 10 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) for ( int m = 0 ; m < 2 ; m ++ ) dp [ i ] [ j ] [ k ] [ l ] [ m ] = - 1 ; v . clear ( ) ; while ( x > 0 ) { v . add ( x % 10 ) ; x /= 10 ; } Collections . reverse ( v ) ; N = v . size ( ) ; } static int fun ( int pos , int sum , int st , int check , int f ) { if ( pos == N ) { return ( sum == 0 && check == 1 ) ? 1 : 0 ; } if ( dp [ pos ] [ sum ] [ st ] [ check ] [ f ] != - 1 ) return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] ; int lmt = 9 ; if ( f == 0 ) lmt = v . get ( pos ) ; int ans = 0 ; for ( int digit = 0 ; digit <= lmt ; digit ++ ) { int nf = f ; int new_sum = ( sum + digit ) % K ; int new_check = check ; int new_st = st ; if ( f == 0 && digit < lmt ) nf = 1 ; if ( check == 0 && digit != 0 ) { new_st = digit ; new_check = 1 ; } if ( pos == N - 1 && new_st == digit ) continue ; ans += fun ( pos + 1 , new_sum , new_st , new_check , nf ) ; } return dp [ pos ] [ sum ] [ st ] [ check ] [ f ] = ans ; } static void findCount ( int L , int R , int K ) { init ( R ) ; int r_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; init ( L - 1 ) ; int l_ans = fun ( 0 , 0 , 0 , 0 , 0 ) ; System . out . print ( r_ans - l_ans ) ; } public static void main ( String [ ] args ) { int L = 10 ; int R = 20 ; K = 2 ; findCount ( L , R , K ) ; } }

Index/key variables: check, f, i, j, k, l, m, pos, st, sum
Accumulator variables: ans, digit, i, j, k, l, m, x
Iterator variables: digit, i, j, k, l, m
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minSumProd ( String S , int K ) { int len = S . length ( ) ; if ( K > len ) return - 1 ; if ( K == len ) return 0 ; int [ ] dp = new int [ len ] ; int count_zero = 0 , count_one = 0 ; for ( int j = 0 ; j < len ; j ++ ) { if ( S . charAt ( j ) == '0' ) count_zero ++ ; else count_one ++ ; dp [ j ] = count_zero * count_one ; } for ( int i = 1 ; i < K ; i ++ ) { for ( int j = len - 1 ; j >= i ; j -- ) { count_zero = 0 ; count_one = 0 ; dp [ j ] = Integer . MAX_VALUE ; for ( int k = j ; k >= i ; k -- ) { if ( S . charAt ( k ) == '0' ) count_zero ++ ; else count_one ++ ; dp [ j ] = Math . min ( dp [ j ] , count_zero * count_one + dp [ k - 1 ] ) ; } } } return dp [ len - 1 ] ; } public static void main ( String [ ] args ) { String S = "1011000110110100" ; int K = 5 ; System . out . print ( minSumProd ( S , K ) ) ; } }

Index/key variables: j, len
Accumulator variables: count_one, count_zero, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minPrizes ( int arr [ ] , int n ) { int [ ] dpLeft = new int [ n ] ; dpLeft [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { dpLeft [ i ] = dpLeft [ i - 1 ] + 1 ; } else { dpLeft [ i ] = 1 ; } } int [ ] dpRight = new int [ n ] ; dpRight [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) { dpRight [ i ] = dpRight [ i + 1 ] + 1 ; } else { dpRight [ i ] = 1 ; } } int totalPrizes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { totalPrizes += Math . max ( dpLeft [ i ] , dpRight [ i ] ) ; } System . out . print ( totalPrizes + "NEW_LINE"); return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 3 } ; int n = arr . length ; minPrizes ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: i, totalPrizes
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { public static int get_max_sum ( int arr [ ] , int n ) { HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . containsKey ( arr [ i ] ) ) { int x = freq . get ( arr [ i ] ) ; freq . replace ( arr [ i ] , x + 1 ) ; } else freq . put ( arr [ i ] , 1 ) ; } int [ ] dp = new int [ 100001 ] ; for ( int i = 0 ; i < 100001 ; i ++ ) dp [ i ] = 0 ; dp [ 0 ] = 0 ; if ( freq . containsKey ( 0 ) ) dp [ 1 ] = freq . get ( 0 ) ; else dp [ 1 ] = 0 ; for ( int i = 2 ; i <= 100000 ; i ++ ) { int temp = ( freq . containsKey ( i ) ) ? freq . get ( i ) : 0 ; dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ i - 2 ] + i * temp ) ; } return dp [ 100000 ] ; } public static void main ( String [ ] args ) { int N = 3 ; int arr [ ] = { 2 , 2 , 3 } ; System . out . println ( get_max_sum ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int minFlip ( String a ) { int n = a . length ( ) ; int dp [ ] [ ] = new int [ n + 1 ] [ 2 ] ; if ( a . charAt ( 0 ) == '1' ) { dp [ 0 ] [ 0 ] = 1 ; } else dp [ 0 ] [ 0 ] = 0 ; if ( a . charAt ( 0 ) == '0' ) dp [ 0 ] [ 1 ] = 1 ; else dp [ 0 ] [ 1 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a . charAt ( i ) == '1' ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 1 ; } else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ; if ( a . charAt ( i ) == '0' ) { dp [ i ] [ 1 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + 1 ; } else dp [ i ] [ 1 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; } int answer = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { answer = Math . min ( answer , dp [ i ] [ 1 ] + dp [ n - 1 ] [ 0 ] - dp [ i ] [ 0 ] ) ; } return Math . min ( answer , dp [ n - 1 ] [ 0 ] ) ; } public static void main ( String [ ] args ) { String s = "1100111000101" ; System . out . println ( minFlip ( s ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int LIIDS ( int arr [ ] , int N ) { int [ ] dp = new int [ N + 1 ] ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { dp [ i ] = 1 ; } for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = i + i ; j <= N ; j += i ) { if ( j < arr . length && arr [ j ] > arr [ i ] ) { dp [ j ] = Math . max ( dp [ j ] , dp [ i ] + 1 ) ; } } ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 7 , 9 , 10 } ; int N = arr . length ; System . out . println ( LIIDS ( 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 boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static int findSubarraySum ( int arr [ ] , int n , int K ) { Map < Integer , Integer > prevSum = new HashMap < > ( ) ; int res = 0 ; int currsum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { currsum += arr [ i ] ; if ( currsum == K ) { res ++ ; } if ( prevSum . containsKey ( currsum - K ) ) res += ( prevSum . get ( currsum - K ) ) ; prevSum . put ( currsum , prevSum . getOrDefault ( currsum , 0 ) + 1 ) ; } return res ; } static void countSubarray ( int arr [ ] , int n , int K ) { for ( int i = 0 ; i < n ; i ++ ) { if ( isPerfectSquare ( arr [ i ] ) ) { arr [ i ] = 1 ; } else { arr [ i ] = 0 ; } } System . out . println ( findSubarraySum ( arr , n , K ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 9 , 2 } ; int K = 2 ; int N = arr . length ; countSubarray ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: currsum, i, res
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int mod = 1000000007 ; static int calculate ( int pos , int left , int k , int L , int R ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; int answer = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( i > left ) break ; answer = ( ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod ) ; } return answer ; } static int countWaystoDivide ( int n , int k , int L , int R ) { return calculate ( 0 , n , k , L , R ) ; } public static void main ( String [ ] args ) { int N = 12 ; int K = 3 ; int L = 1 ; int R = 5 ; System . out . print ( countWaystoDivide ( N , K , L , R ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void PossibleSum ( int n , int m , int [ ] [ ] v , int k ) { int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { if ( dp [ i ] [ j ] == 1 ) { for ( int d = 0 ; d < m ; d ++ ) { if ( ( j + v [ i ] [ d ] ) <= k ) { dp [ i + 1 ] [ j + v [ i ] [ d ] ] = 1 ; } } } } } if ( dp [ n ] [ k ] == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int N = 2 , M = 10 , K = 5 ; int [ ] [ ] arr = new int [ ] [ ] { { 4 , 0 , 15 , 3 , 2 , 20 , 10 , 1 , 5 , 4 } , { 4 , 0 , 10 , 3 , 2 , 25 , 4 , 1 , 5 , 4 } } ; PossibleSum ( N , M , arr , K ) ; } }

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