dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static class pair { double first , second ; public pair ( double first , double second ) { this . first = first ; this . second = second ; } } static void construct ( int n , pair ans_pair ) { if ( ans_pair . first == - 1 ) { System . out . print ( " Not ▁ possible " ) ; return ; } double a1 = ans_pair . first ; double a2 = ans_pair . second ; double r = a2 / a1 ; System . out . print ( "The resultant sequence is:NEW_LINE"); for ( int i = 1 ; i <= n ; i ++ ) { int ai = ( int ) ( a1 * Math . pow ( r , i - 1 ) ) ; System . out . print ( ai + " ▁ " ) ; } } static void findMinimumOperations ( double [ ] a , int n ) { int ans = Integer . MAX_VALUE ; int c [ ] = { - 1 , 0 , 1 } ; int possibilities = 3 ; int pos1 = - 1 , pos2 = - 1 ; for ( int i = 0 ; i < possibilities ; i ++ ) { for ( int j = 0 ; j < possibilities ; j ++ ) { double a1 = a [ 1 ] + c [ i ] ; double a2 = a [ 2 ] + c [ j ] ; int temp = ( int ) ( Math . abs ( a1 - a [ 1 ] ) + Math . abs ( a2 - a [ 2 ] ) ) ; if ( a1 == 0 a2 == 0 ) continue ; double r = a2 / a1 ; for ( int pos = 3 ; pos <= n ; pos ++ ) { double ai = a1 * Math . pow ( r , pos - 1 ) ; if ( a [ pos ] == ai ) { continue ; } else if ( a [ pos ] + 1 == ai a [ pos ] - 1 == ai ) { temp ++ ; } else { temp = Integer . MAX_VALUE ; break ; } } if ( temp < ans ) { ans = temp ; pos1 = ( int ) a1 ; pos2 = ( int ) a2 ; } } } if ( ans == - 1 ) { System . out . print ( " - 1" ) ; return ; } System . out . print ( " Minimum ▁ Number ▁ of ▁ Operations ▁ are ▁ " + ans + "NEW_LINE"); pair ans_pair = new pair ( pos1 , pos2 ) ; construct ( n , ans_pair ) ; } public static void main ( String [ ] args ) { double a [ ] = { 0 , 7 , 20 , 49 , 125 } ; int n = a . length ; findMinimumOperations ( a , n - 1 ) ; } }

Index/key variables: i, j, pos
Accumulator variables: i, j, pos, temp
Iterator variables: i, j, pos
Class/struct names: GFG, pair
Java program:
import java . io . * ; import java . util . * ; class GFG { static void findOrderMRT ( int [ ] L , int n ) { Arrays . sort ( L ) ; System . out . print ( " Optimal ▁ order ▁ in ▁ which ▁ " + " programs ▁ are ▁ to ▁ be ▁ stored ▁ is : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( L [ i ] + " ▁ " ) ; System . out . println ( ) ; double MRT = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j <= i ; j ++ ) sum += L [ j ] ; MRT += sum ; } MRT /= n ; System . out . print ( " Minimum ▁ Retrieval ▁ Time " + " ▁ of ▁ this ▁ order ▁ is ▁ " + MRT ) ; } public static void main ( String [ ] args ) { int [ ] L = { 2 , 5 , 4 } ; int n = L . length ; findOrderMRT ( L , n ) ; } }

Index/key variables: i, j
Accumulator variables: MRT, i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MinOperation ( int a [ ] , int n , int k ) { int result = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( a [ i ] != 1 && a [ i ] > k ) { result = result + Math . min ( a [ i ] % k , k - a [ i ] % k ) ; } else { result = result + k - a [ i ] ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 6 } ; int n = arr . length ; int k = 5 ; System . out . println ( MinOperation ( arr , n , k ) ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int maxProductSubset ( int a [ ] , int n ) { if ( n == 1 ) { return a [ 0 ] ; } int max_neg = Integer . MIN_VALUE ; int count_neg = 0 , count_zero = 0 ; int prod = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count_zero ++ ; continue ; } if ( a [ i ] < 0 ) { count_neg ++ ; max_neg = Math . max ( max_neg , a [ i ] ) ; } prod = prod * a [ i ] ; } if ( count_zero == n ) { return 0 ; } if ( count_neg % 2 == 1 ) { if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) { return 0 ; } prod = prod / max_neg ; } return prod ; } public static void main ( String [ ] args ) { int a [ ] = { - 1 , - 1 , - 2 , 4 , 3 } ; int n = a . length ; System . out . println ( maxProductSubset ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: count_neg, count_zero, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find ( int [ ] arr , int pos , int m , boolean [ ] isRunning ) { int [ ] d = new int [ m + 1 ] ; for ( int i = m - 1 ; i > pos ; i -- ) { if ( isRunning [ arr [ i ] ] ) d [ arr [ i ] ] = i ; } int maxipos = 0 ; for ( int ele : d ) maxipos = Math . max ( ele , maxipos ) ; return maxipos ; } static int mincost ( int n , int m , int [ ] arr ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] freqarr = new Vector [ m ] ; for ( int i = 0 ; i < freqarr . length ; i ++ ) freqarr [ i ] = new Vector < Integer > ( ) ; int [ ] newvec = new int [ m + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) freqarr [ m - 1 ] . add ( newvec [ i ] ) ; for ( int i = m - 2 ; i > 0 ; i -- ) { Vector < Integer > nv = new Vector < > ( ) ; nv = freqarr [ i + 1 ] ; nv . insertElementAt ( arr [ i + 1 ] + 1 , arr [ i + 1 ] ) ; freqarr [ i ] = nv ; } boolean [ ] isRunning = new boolean [ m + 1 ] ; int cost = 0 ; int truecount = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int ele = arr [ i ] ; if ( isRunning [ ele ] == true ) continue ; else { if ( truecount < n ) { cost += 1 ; truecount += 1 ; isRunning [ ele ] = true ; } else { int mini = 100000 ; int miniind = 0 ; for ( int j = 0 ; j <= m ; j ++ ) { if ( isRunning [ j ] && mini > freqarr [ i ] . get ( j ) ) { mini = freqarr [ i ] . get ( j ) ; miniind = j ; } } if ( mini == 0 ) { isRunning [ miniind ] = false ; isRunning [ ele ] = true ; cost += 1 ; } else { int farpos = find ( arr , i , m , isRunning ) ; isRunning [ arr [ farpos ] ] = false ; isRunning [ ele ] = true ; cost += 1 ; } } } } return cost ; } public static void main ( String [ ] args ) { int n1 = 3 ; int m1 = 6 ; int [ ] arr1 = { 1 , 2 , 1 , 3 , 4 , 1 } ; System . out . print ( mincost ( n1 , m1 , arr1 ) + "NEW_LINE"); int n2 = 2 ; int m2 = 6 ; int [ ] arr2 = { 1 , 2 , 1 , 3 , 2 , 1 } ; System . out . print ( mincost ( n2 , m2 , arr2 ) + "NEW_LINE"); int n3 = 3 ; int m3 = 31 ; int [ ] arr3 = { 7 , 11 , 17 , 10 , 7 , 10 , 2 , 9 , 2 , 18 , 8 , 10 , 20 , 10 , 3 , 20 , 17 , 17 , 17 , 1 , 15 , 10 , 8 , 3 , 3 , 18 , 13 , 2 , 10 , 10 , 11 } ; System . out . print ( mincost ( n3 , m3 - 8 , arr3 ) + "NEW_LINE"); } }

Index/key variables: ele, farpos, i, j, m, miniind
Accumulator variables: cost, i, j, truecount
Iterator variables: ele, i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void calcFiboTerms ( ArrayList < Integer > fiboterms , int k ) { int i = 3 , nextTerm = 0 ; fiboterms . add ( 0 ) ; fiboterms . add ( 1 ) ; fiboterms . add ( 1 ) ; while ( true ) { nextTerm = fiboterms . get ( i - 1 ) + fiboterms . get ( i - 2 ) ; if ( nextTerm > k ) return ; fiboterms . add ( nextTerm ) ; i ++ ; } } public static int fibMinTerms ( int k ) { ArrayList < Integer > fiboterms = new ArrayList < Integer > ( ) ; calcFiboTerms ( fiboterms , k ) ; int count = 0 , j = fiboterms . size ( ) - 1 ; while ( k > 0 ) { count += ( k / fiboterms . get ( j ) ) ; k %= ( fiboterms . get ( j ) ) ; j -- ; } return count ; } public static void main ( String [ ] args ) { int k = 17 ; System . out . println ( fibMinTerms ( k ) ) ; } }

Accumulator variables: count, i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void digitsNum ( int N ) { if ( N == 0 ) System . out . println ( "0" ) ; if ( N % 9 != 0 ) System . out . print ( ( N % 9 ) ) ; for ( int i = 1 ; i <= ( N / 9 ) ; ++ i ) System . out . print ( "9" ) ; for ( int i = 1 ; i <= N ; ++ i ) System . out . print ( "0" ) ; System . out . print ( " " ) ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( " The ▁ number ▁ is ▁ : ▁ " ) ; digitsNum ( N ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void printVector ( Vector < Integer > v ) { System . out . println ( v . size ( ) ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) System . out . print ( v . get ( i ) + " ▁ " ) ; System . out . println ( ) ; } static void findTwoGroup ( int n ) { int sum = n * ( n + 1 ) / 2 ; int group1Sum = sum / 2 ; Vector < Integer > group1 = new Vector < Integer > ( ) ; Vector < Integer > group2 = new Vector < Integer > ( ) ; for ( int i = n ; i > 0 ; i -- ) { if ( group1Sum - i >= 0 ) { group1 . add ( i ) ; group1Sum -= i ; } else { group2 . add ( i ) ; } } printVector ( group1 ) ; printVector ( group2 ) ; } public static void main ( String [ ] args ) { int n = 5 ; findTwoGroup ( n ) ; } }

Accumulator variables: group1Sum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxDifference ( int arr [ ] , int N , int k ) { int M , S = 0 , S1 = 0 , max_difference = 0 ; for ( int i = 0 ; i < N ; i ++ ) S += arr [ i ] ; int temp ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] < arr [ j ] ) { temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } } M = Math . max ( k , N - k ) ; for ( int i = 0 ; i < M ; i ++ ) S1 += arr [ i ] ; max_difference = S1 - ( S - S1 ) ; return max_difference ; } public static void main ( String args [ ] ) { int arr [ ] = { 8 , 4 , 5 , 2 , 10 } ; int N = arr . length ; int k = 2 ; System . out . println ( maxDifference ( arr , N , k ) ) ; } }

Index/key variables: i, j
Accumulator variables: S, S1, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . math . * ; class GFG { static int minproduct ( int a [ ] , int b [ ] , int n , int k ) { int diff = 0 , res = 0 ; int temp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int pro = a [ i ] * b [ i ] ; res = res + pro ; if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; int d = Math . abs ( pro - temp ) ; if ( d > diff ) diff = d ; } return res - diff ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 3 , 4 , 5 , 4 } ; int b [ ] = { 3 , 4 , 2 , 3 , 2 } ; int n = 5 , k = 3 ; System . out . println ( minproduct ( a , b , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int count ( int n ) { if ( n < 4 ) return - 1 ; int rem = n % 4 ; if ( rem == 0 ) return n / 4 ; if ( rem == 1 ) { if ( n < 9 ) return - 1 ; return ( n - 9 ) / 4 + 1 ; } if ( rem == 2 ) return ( n - 6 ) / 4 + 1 ; if ( rem == 3 ) { if ( n < 15 ) return - 1 ; return ( n - 15 ) / 4 + 2 ; } return 0 ; } public static void main ( String [ ] args ) { int n = 90 ; System . out . println ( count ( n ) ) ; n = 143 ; System . out . println ( count ( n ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int policeThief ( char arr [ ] , int n , int k ) { int res = 0 ; ArrayList < Integer > thi = new ArrayList < Integer > ( ) ; ArrayList < Integer > pol = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == ' P ' ) pol . add ( i ) ; else if ( arr [ i ] == ' T ' ) thi . add ( i ) ; } int l = 0 , r = 0 ; while ( l < thi . size ( ) && r < pol . size ( ) ) { if ( Math . abs ( thi . get ( l ) - pol . get ( r ) ) <= k ) { res ++ ; l ++ ; r ++ ; } else if ( thi . get ( l ) < pol . get ( r ) ) l ++ ; else r ++ ; } return res ; } public static void main ( String args [ ] ) { int k , n ; char arr1 [ ] = new char [ ] { ' P ' , ' T ' , ' T ' , ' P ' , ' T ' } ; k = 2 ; n = arr1 . length ; System . out . println ( " Maximum ▁ thieves ▁ caught : ▁ " + policeThief ( arr1 , n , k ) ) ; char arr2 [ ] = new char [ ] { ' T ' , ' T ' , ' P ' , ' P ' , ' T ' , ' P ' } ; k = 2 ; n = arr2 . length ; System . out . println ( " Maximum ▁ thieves ▁ caught : ▁ " + policeThief ( arr2 , n , k ) ) ; char arr3 [ ] = new char [ ] { ' P ' , ' T ' , ' P ' , ' T ' , ' T ' , ' P ' } ; k = 3 ; n = arr3 . length ; System . out . println ( " Maximum ▁ thieves ▁ caught : ▁ " + policeThief ( arr3 , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, l, r, res
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int minRotation ( int input , int unlock_code ) { int rotation = 0 ; int input_digit , code_digit ; while ( input > 0 unlock_code > 0 ) { input_digit = input % 10 ; code_digit = unlock_code % 10 ; rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ; input /= 10 ; unlock_code /= 10 ; } return rotation ; } public static void main ( String [ ] args ) { int input = 28756 ; int unlock_code = 98234 ; System . out . println ( " Minimum ▁ Rotation ▁ = ▁ " + minRotation ( input , unlock_code ) ) ; } }

Accumulator variables: input, rotation, unlock_code
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; public class GFG { static void preprocess ( int [ ] coin , int n ) { Arrays . sort ( coin ) ; for ( int i = 1 ; i <= n - 1 ; i ++ ) coin [ i ] += coin [ i - 1 ] ; } static int minCost ( int [ ] coin , int n , int k ) { int coins_needed = ( int ) Math . ceil ( 1.0 * n / ( k + 1 ) ) ; return coin [ coins_needed - 1 ] ; } static public void main ( String [ ] args ) { int [ ] coin = { 8 , 5 , 3 , 10 , 2 , 1 , 15 , 25 } ; int n = coin . length ; preprocess ( coin , n ) ; int k = 3 ; System . out . println ( minCost ( coin , n , k ) ) ; k = 7 ; System . out . println ( minCost ( coin , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) { int allocation [ ] = new int [ n ] ; for ( int i = 0 ; i < allocation . length ; i ++ ) allocation [ i ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int wstIdx = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( wstIdx == - 1 ) wstIdx = j ; else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ; } } if ( wstIdx != - 1 ) { allocation [ i ] = wstIdx ; blockSize [ wstIdx ] -= processSize [ i ] ; } } System . out . println ( " Process No . Process Size Block no . "); for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( " ▁ " + ( i + 1 ) + " TABSYMBOL TABSYMBOL " + processSize [ i ] + " TABSYMBOL TABSYMBOL " ) ; if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ; else System . out . print ( " Not ▁ Allocated " ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int blockSize [ ] = { 100 , 500 , 200 , 300 , 600 } ; int processSize [ ] = { 212 , 417 , 112 , 426 } ; int m = blockSize . length ; int n = processSize . length ; worstFit ( blockSize , m , processSize , n ) ; } }

Index/key variables: i, j, n, wstIdx
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int maximumSum ( int arr [ ] , int n , int k ) { for ( int i = 1 ; i <= k ; i ++ ) { int min = + 2147483647 ; int index = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] < min ) { min = arr [ j ] ; index = j ; } } if ( min == 0 ) break ; arr [ index ] = - arr [ index ] ; } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } public static void main ( String arg [ ] ) { int arr [ ] = { - 2 , 0 , 5 , - 1 , 2 } ; int k = 4 ; int n = arr . length ; System . out . print ( maximumSum ( arr , n , k ) ) ; } }

Index/key variables: i, index, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; public class GFG { static int sol ( int arr [ ] , int k ) { Arrays . sort ( arr ) ; int sum = 0 ; int i = 0 ; while ( k > 0 ) { if ( arr [ i ] >= 0 ) k = 0 ; else { arr [ i ] = ( - 1 ) * arr [ i ] ; k = k - 1 ; } i ++ ; } for ( int j = 0 ; j < arr . length ; j ++ ) { sum += arr [ j ] ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , 0 , 5 , - 1 , 2 } ; System . out . println ( sol ( arr , 4 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int sumArray ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } return sum ; } static int maximizeSum ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( k != 0 && arr [ i ] < 0 ) { arr [ i ] *= - 1 ; k -- ; continue ; } break ; } if ( i == n ) i -- ; if ( k == 0 k % 2 == 0 ) { return sumArray ( arr , n ) ; } if ( i != 0 && Math . abs ( arr [ i ] ) >= Math . abs ( arr [ i - 1 ] ) ) { i -- ; } arr [ i ] *= - 1 ; return sumArray ( arr , n ) ; } public static void main ( String args [ ] ) { int n = 5 ; int k = 4 ; int arr [ ] = { - 3 , - 2 , - 1 , 5 , 6 } ; System . out . print ( maximizeSum ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, k, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int firstFit ( int weight [ ] , int n , int c ) { int res = 0 ; int [ ] bin_rem = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] ) { bin_rem [ j ] = bin_rem [ j ] - weight [ i ] ; break ; } } if ( j == res ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } } return res ; } public static void main ( String [ ] args ) { int weight [ ] = { 2 , 5 , 4 , 7 , 1 , 3 , 8 } ; int c = 10 ; int n = weight . length ; System . out . print ( " Number ▁ of ▁ bins ▁ required ▁ in ▁ First ▁ Fit ▁ : ▁ " + firstFit ( weight , n , c ) ) ; } }

Index/key variables: i, j, n, res
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int getMinOperations ( int A , int B , int prevA , int prevB , int dp [ ] [ ] ) { if ( A == prevA && B == prevB ) { return Integer . MAX_VALUE ; } if ( A == 0 && B == 0 ) { return 0 ; } if ( dp [ A ] [ B ] != - 1 ) { return dp [ A ] [ B ] ; } int ans1 = getMinOperations ( A / 2 , B , A , B , dp ) ; if ( ans1 != Integer . MAX_VALUE ) { ans1 += 1 ; } int ans2 = getMinOperations ( A , B / 2 , A , B , dp ) ; if ( ans2 != Integer . MAX_VALUE ) { ans2 += 1 ; } int ans3 = getMinOperations ( ( int ) Math . sqrt ( A * B ) , ( int ) Math . sqrt ( A * B ) , A , B , dp ) ; if ( ans3 != Integer . MAX_VALUE ) { ans3 += 2 ; } return dp [ A ] [ B ] = Math . min ( ans1 , Math . min ( ans2 , ans3 ) ) ; } public static void main ( String [ ] args ) { int A = 53 , B = 16 ; int mx = Math . max ( A , B ) ; int dp [ ] [ ] = new int [ mx + 1 ] [ mx + 1 ] ; for ( int i = 0 ; i <= mx ; i ++ ) { for ( int j = 0 ; j <= mx ; j ++ ) dp [ i ] [ j ] = - 1 ; } System . out . println ( getMinOperations ( A , B , - 1 , - 1 , dp ) ) ; } }

Index/key variables: A, B, i, j
Accumulator variables: ans1, ans2, ans3, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int maxDiffSum ( int [ ] arr , int n ) { int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int maxVal = arr [ i ] , minVal = arr [ i ] ; for ( int j = i ; j >= 0 ; j -- ) { minVal = Math . min ( minVal , arr [ j ] ) ; maxVal = Math . max ( maxVal , arr [ j ] ) ; if ( j - 1 >= 0 ) dp [ i ] = Math . max ( dp [ i ] , maxVal - minVal + dp [ j - 1 ] ) ; else dp [ i ] = Math . max ( dp [ i ] , maxVal - minVal ) ; } } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 8 , 1 , 7 , 9 , 2 } ; int N = arr . length ; System . out . print ( maxDiffSum ( arr , N ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { public static int MOD = 1000000007 ; public static long modPow ( long x , long y ) { long r = 1 , a = x ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) { r = ( r * a ) % MOD ; } a = ( a * a ) % MOD ; y /= 2 ; } return r ; } public static long modInverse ( long x ) { return modPow ( x , MOD - 2 ) ; } public static long modDivision ( long p , long q ) { return ( p * modInverse ( q ) ) % MOD ; } public static long C ( long n , int k ) { if ( k > n ) { return 0 ; } long p = 1 , q = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { q = ( q * i ) % MOD ; p = ( p * ( n - i + 1 ) ) % MOD ; } return modDivision ( p , q ) ; } public static long countArrays ( int N , int K ) { long res = 1 ; for ( int p = 2 ; p <= K / p ; p ++ ) { int c = 0 ; while ( K % p == 0 ) { K /= p ; c ++ ; } res = ( res * C ( N - 1 + c , c ) ) % MOD ; } if ( N > 1 ) { res = ( res * N ) % MOD ; } return res ; } public static void main ( String args [ ] ) { int N = 3 , K = 5 ; System . out . println ( countArrays ( N , K ) ) ; } }

Accumulator variables: K, c, i, p, y
Iterator variables: i, p
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { public static int minSessions ( int [ ] codeTime , int [ ] [ ] dp , int ones , int n , int mask , int currTime , int WorkingSessionTime ) { if ( currTime > WorkingSessionTime ) return Integer . MAX_VALUE ; if ( mask == ones ) return 1 ; if ( dp [ mask ] [ currTime ] != - 1 ) return dp [ mask ] [ currTime ] ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( mask & ( 1 << i ) ) == 0 ) { int inc = minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , currTime + codeTime [ i ] , WorkingSessionTime ) ; int inc_next = 1 + minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , codeTime [ i ] , WorkingSessionTime ) ; ans = Math . min ( ans , Math . min ( inc , inc_next ) ) ; } } return dp [ mask ] [ currTime ] = ans ; } public static int solve ( int [ ] codeTime , int n , int WorkingSessionTime ) { int [ ] [ ] dp = new int [ ( 1 << 14 ) ] [ ] ; for ( int i = 0 ; i < 1 << 14 ; i ++ ) { dp [ i ] = new int [ 15 ] ; Arrays . fill ( dp [ i ] , - 1 ) ; } int ones = ( 1 << n ) - 1 ; int ans = minSessions ( codeTime , dp , ones , n , 0 , 0 , WorkingSessionTime ) ; if ( WorkingSessionTime < 6 ) { if ( ans % 2 == 0 ) ans = ans / 2 ; else ans = ( ans / 2 ) + 1 ; } return ans ; } public static void main ( String args [ ] ) { int [ ] codeTime = { 1 , 2 , 3 , 1 , 1 , 3 } ; int n = codeTime . length ; int WorkingSessionTime = 4 ; System . out . println ( solve ( codeTime , n , WorkingSessionTime ) ) ; } }

Index/key variables: currTime, i, mask
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static final int MAXN = 100005 ; static final int dp [ ] [ ] = new int [ MAXN ] [ 10 ] ; static int solve ( int len , int gap ) { if ( dp [ len ] [ gap ] != - 1 ) { return dp [ len ] [ gap ] ; } if ( len == 0 gap == 0 ) { return 1 ; } if ( gap < 0 ) { return 0 ; } int ans = 0 ; for ( int i = 0 ; i <= gap ; i ++ ) { ans += solve ( len - 1 , gap - i ) ; } return dp [ len ] [ gap ] = ans ; } static int countValidStrings ( String S ) { for ( int i = 0 ; i < MAXN ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } int N = S . length ( ) ; int L = 1 , R = 9 ; int cnt = 0 ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) != ' ? ' ) { R = S . charAt ( i ) - '0' ; ans *= solve ( cnt , R - L ) ; L = R ; R = 9 ; cnt = 0 ; } else { cnt ++ ; } } ans *= solve ( cnt , R - L ) ; return ans ; } public static void main ( String [ ] args ) { String S = "1 ? ? ?2" ; System . out . println ( countValidStrings ( S ) ) ; } }

Index/key variables: MAXN, gap, i, j, len
Accumulator variables: ans, cnt, i, j
Iterator variables: i, j
Class/struct names: GFG