dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class GFG { public static boolean isPrime ( int n ) { if ( n % 2 == 0 ) return false ; for ( int i = 3 ; i * i <= n ; i += 2 ) if ( n % i == 0 ) return false ; return true ; } public static int nextPrime ( int start ) { int next = start + 1 ; while ( ! isPrime ( next ) ) next ++ ; return next ; } public static boolean areAdjacentPrimes ( int a , int b , int c ) { if ( ! isPrime ( a ) || ! isPrime ( b ) || ! isPrime ( c ) ) return false ; int next = nextPrime ( a ) ; if ( next != b ) return false ; if ( nextPrime ( b ) != c ) return false ; return true ; } public static void main ( String [ ] args ) { if ( areAdjacentPrimes ( 11 , 13 , 19 ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Accumulator variables: i, next
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int checkSemiprime ( int num ) { int cnt = 0 ; for ( int i = 2 ; cnt < 2 && i * i <= num ; ++ i ) while ( num % i == 0 ) { num /= i ; ++ cnt ; } if ( num > 1 ) ++ cnt ; return cnt == 2 ? 1 : 0 ; } static void semiprime ( int n ) { if ( checkSemiprime ( n ) != 0 ) System . out . printf ( "TrueNEW_LINE"); else System . out . printf ( "FalseNEW_LINE"); } public static void main ( String [ ] args ) { int n = 6 ; semiprime ( n ) ; n = 8 ; semiprime ( n ) ; } }

Accumulator variables: num
Iterator variables: i
Class/struct names: GFG
Java program:
public class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + i * i ; return sum ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
public class GfG { static int sumOfSeries ( int n ) { return ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; } public static void main ( String s [ ] ) { int n = 10 ; System . out . println ( sumOfSeries ( n ) ) ; } }

Class/struct names: GfG
Java program:
import java . io . * ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] [ ] C = new int [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } static int maxcoefficientvalue ( int n ) { if ( n % 2 == 0 ) return binomialCoeff ( n , n / 2 ) ; else return binomialCoeff ( n , ( n + 1 ) / 2 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( maxcoefficientvalue ( n ) ) ; } }

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) { return a ; } else { return __gcd ( b , a % b ) ; } } static int LCM ( int x , int y , int z ) { int ans = ( ( x * y ) / ( __gcd ( x , y ) ) ) ; return ( ( z * ans ) / ( __gcd ( ans , z ) ) ) ; } static int findDivisible ( int n , int x , int y , int z ) { int lcm = LCM ( x , y , z ) ; int ndigitnumber = ( int ) Math . pow ( 10 , n - 1 ) ; int reminder = ndigitnumber % lcm ; if ( reminder == 0 ) return ndigitnumber ; ndigitnumber += lcm - reminder ; if ( ndigitnumber < Math . pow ( 10 , n ) ) return ndigitnumber ; else return 0 ; } static public void main ( String [ ] args ) { int n = 4 , x = 2 , y = 3 , z = 5 ; int res = findDivisible ( n , x , y , z ) ; if ( res != 0 ) System . out . println ( res ) ; else System . out . println ( " Not ▁ possible " ) ; } }

Accumulator variables: ndigitnumber
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int squaresum ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( squaresum ( n ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static double distance ( int x1 , int y1 , int x2 , int y2 ) { return Math . sqrt ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) * 1.0 ) ; } public static void main ( String [ ] args ) { System . out . println ( Math . round ( distance ( 3 , 4 , 4 , 3 ) * 100000.0 ) / 100000.0 ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static boolean isDivisible ( String S ) { int n = S . length ( ) ; if ( S . charAt ( n - 1 ) != '5' && S . charAt ( n - 1 ) != '0' ) return false ; int sum = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) sum += ( int ) S . charAt ( i ) ; if ( sum % 3 == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { String S = "15645746327462384723984023940239" ; if ( isDivisible ( S ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; String S1 = "15645746327462384723984023940235" ; if ( isDivisible ( S1 ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class ShortestPath { static final int V = 4 ; static final int INF = Integer . MAX_VALUE ; int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) { if ( k == 0 && u == v ) return 0 ; if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ; if ( k <= 0 ) return INF ; int res = INF ; for ( int i = 0 ; i < V ; i ++ ) { if ( graph [ u ] [ i ] != INF && u != i && v != i ) { int rec_res = shortestPath ( graph , i , v , k - 1 ) ; if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ; } } return res ; } public static void main ( String [ ] args ) { int graph [ ] [ ] = new int [ ] [ ] { { 0 , 10 , 3 , 2 } , { INF , 0 , INF , 7 } , { INF , INF , 0 , 6 } , { INF , INF , INF , 0 } } ; ShortestPath t = new ShortestPath ( ) ; int u = 0 , v = 3 , k = 2 ; System . out . println ( " Weight ▁ of ▁ the ▁ shortest ▁ path ▁ is ▁ " + t . shortestPath ( graph , u , v , k ) ) ; } }

Index/key variables: i, u, v
Accumulator variables: i
Iterator variables: i
Class/struct names: ShortestPath
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class ShortestPath { static final int V = 4 ; static final int INF = Integer . MAX_VALUE ; int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) { int sp [ ] [ ] [ ] = new int [ V ] [ V ] [ k + 1 ] ; for ( int e = 0 ; e <= k ; e ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { sp [ i ] [ j ] [ e ] = INF ; if ( e == 0 && i == j ) sp [ i ] [ j ] [ e ] = 0 ; if ( e == 1 && graph [ i ] [ j ] != INF ) sp [ i ] [ j ] [ e ] = graph [ i ] [ j ] ; if ( e > 1 ) { for ( int a = 0 ; a < V ; a ++ ) { if ( graph [ i ] [ a ] != INF && i != a && j != a && sp [ a ] [ j ] [ e - 1 ] != INF ) sp [ i ] [ j ] [ e ] = Math . min ( sp [ i ] [ j ] [ e ] , graph [ i ] [ a ] + sp [ a ] [ j ] [ e - 1 ] ) ; } } } } } return sp [ u ] [ v ] [ k ] ; } public static void main ( String [ ] args ) { int graph [ ] [ ] = new int [ ] [ ] { { 0 , 10 , 3 , 2 } , { INF , 0 , INF , 7 } , { INF , INF , 0 , 6 } , { INF , INF , INF , 0 } } ; ShortestPath t = new ShortestPath ( ) ; int u = 0 , v = 3 , k = 2 ; System . out . println ( " Weight ▁ of ▁ the ▁ shortest ▁ path ▁ is ▁ " + t . shortestPath ( graph , u , v , k ) ) ; } }

Index/key variables: V, a, e, i, j, k, u, v
Accumulator variables: a, e, i, j
Iterator variables: a, e, i, j
Class/struct names: ShortestPath
Java program:
class GFG { static int N = 8 ; static int INF = Integer . MAX_VALUE ; public static int shortestDist ( int [ ] [ ] graph ) { int [ ] dist = new int [ N ] ; dist [ N - 1 ] = 0 ; for ( int i = N - 2 ; i >= 0 ; i -- ) { dist [ i ] = INF ; for ( int j = i ; j < N ; j ++ ) { if ( graph [ i ] [ j ] == INF ) { continue ; } dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ; } } return dist [ 0 ] ; } public static void main ( String [ ] args ) { int [ ] [ ] graph = new int [ ] [ ] { { INF , 1 , 2 , 5 , INF , INF , INF , INF } , { INF , INF , INF , INF , 4 , 11 , INF , INF } , { INF , INF , INF , INF , 9 , 5 , 16 , INF } , { INF , INF , INF , INF , INF , INF , 2 , INF } , { INF , INF , INF , INF , INF , INF , INF , 18 } , { INF , INF , INF , INF , INF , INF , INF , 13 } , { INF , INF , INF , INF , INF , INF , INF , 2 } } ; System . out . println ( shortestDist ( graph ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right ; } } class BinaryTree { Node root ; void reverseLevelOrder ( Node node ) { int h = height ( node ) ; int i ; for ( i = h ; i >= 1 ; i -- ) { printGivenLevel ( node , i ) ; } } void printGivenLevel ( Node node , int level ) { if ( node == null ) return ; if ( level == 1 ) System . out . print ( node . data + " ▁ " ) ; else if ( level > 1 ) { printGivenLevel ( node . left , level - 1 ) ; printGivenLevel ( node . right , level - 1 ) ; } } int height ( Node node ) { if ( node == null ) return 0 ; else { int lheight = height ( node . left ) ; int rheight = height ( node . right ) ; if ( lheight > rheight ) return ( lheight + 1 ) ; else return ( rheight + 1 ) ; } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " Level ▁ Order ▁ traversal ▁ of ▁ binary ▁ tree ▁ is ▁ : ▁ " ) ; tree . reverseLevelOrder ( tree . root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static int V = 4 ; static class Edge { int from , weight ; Edge ( int from , int weight ) { this . from = from ; this . weight = weight ; } } static Vector < Edge > [ ] edges = new Vector [ V ] ; static { for ( int i = 0 ; i < V ; i ++ ) edges [ i ] = new Vector < > ( ) ; } static void addedge ( int u , int v , int w ) { edges [ v ] . add ( new Edge ( u , w ) ) ; } static void shortestpath ( int [ ] [ ] dp ) { for ( int i = 0 ; i <= V ; i ++ ) for ( int j = 0 ; j < V ; j ++ ) dp [ i ] [ j ] = - 1 ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { for ( int k = 0 ; k < edges [ j ] . size ( ) ; k ++ ) { if ( dp [ i - 1 ] [ edges [ j ] . elementAt ( k ) . from ] != - 1 ) { int curr_wt = dp [ i - 1 ] [ edges [ j ] . elementAt ( k ) . from ] + edges [ j ] . elementAt ( k ) . weight ; if ( dp [ i ] [ j ] == - 1 ) dp [ i ] [ j ] = curr_wt ; else dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , curr_wt ) ; } } } } } static double minAvgWeight ( ) { int [ ] [ ] dp = new int [ V + 1 ] [ V ] ; shortestpath ( dp ) ; double [ ] avg = new double [ V ] ; for ( int i = 0 ; i < V ; i ++ ) avg [ i ] = - 1 ; for ( int i = 0 ; i < V ; i ++ ) { if ( dp [ V ] [ i ] != - 1 ) { for ( int j = 0 ; j < V ; j ++ ) if ( dp [ j ] [ i ] != - 1 ) avg [ i ] = Math . max ( avg [ i ] , ( ( double ) dp [ V ] [ i ] - dp [ j ] [ i ] ) / ( V - j ) ) ; } } double result = avg [ 0 ] ; for ( int i = 0 ; i < V ; i ++ ) if ( avg [ i ] != - 1 && avg [ i ] < result ) result = avg [ i ] ; return result ; } public static void main ( String [ ] args ) { addedge ( 0 , 1 , 1 ) ; addedge ( 0 , 2 , 10 ) ; addedge ( 1 , 2 , 3 ) ; addedge ( 2 , 3 , 2 ) ; addedge ( 3 , 1 , 0 ) ; addedge ( 3 , 0 , 8 ) ; System . out . printf ( " % .5f " , minAvgWeight ( ) ) ; } }

Index/key variables: V, i, j, v
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: Edge, GFG
Java program:
class GFG { static int findCount ( String s ) { int [ ] freq = new int [ 26 ] ; int [ ] [ ] dp = new int [ 26 ] [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { for ( int j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ s . charAt ( i ) - ' a ' ] += freq [ j ] ; } freq [ s . charAt ( i ) - ' a ' ] ++ ; } int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) ans = Math . max ( freq [ i ] , ans ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { ans = Math . max ( dp [ i ] [ j ] , ans ) ; } } return ans ; } public static void main ( String [ ] args ) { String str = " acbab " ; System . out . print ( findCount ( str ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { public static void constructArray ( int N , int K , int X ) { int [ ] ans = new int [ K ] ; ans [ 0 ] = X ; for ( int i = 0 ; i < N ; ++ i ) { System . out . print ( ans [ i % K ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 5 , K = 2 , X = 4 ; constructArray ( N , K , X ) ; } }

Index/key variables: K
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void game ( int [ ] v , int n ) { HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! m . containsKey ( v [ i ] ) ) m . put ( v [ i ] , 1 ) ; else m . replace ( v [ i ] , m . get ( v [ i ] ) + 1 ) ; } int count = 0 ; int check = 0 ; for ( Map . Entry < Integer , Integer > i : m . entrySet ( ) ) { if ( i . getValue ( ) > 1 ) { if ( i . getValue ( ) >= 4 && i . getValue ( ) % 2 == 0 ) check ++ ; count ++ ; } } boolean flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) System . out . println ( " Yes " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 2 , 3 , 3 , 5 } ; int size = arr . length ; game ( arr , size ) ; } }

Index/key variables: i
Accumulator variables: check, count, i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int mod = 1000000007 ; static int solve ( int A [ ] , int n ) { int i , cnt = 0 , j ; int [ ] parent = new int [ n ] ; int [ ] vis = new int [ n ] ; Arrays . fill ( parent , - 1 ) ; Arrays . fill ( vis , 0 ) ; for ( i = 0 ; i < n ; i ++ ) { j = i ; if ( parent [ j ] == - 1 ) { while ( parent [ j ] == - 1 ) { parent [ j ] = i ; j = __gcd ( j , A [ j ] ) % n ; } if ( parent [ j ] == i ) { while ( vis [ j ] == 0 ) { vis [ j ] = 1 ; cnt ++ ; j = __gcd ( j , A [ j ] ) % n ; } } } } return cnt ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 1 , 6 , 2 } ; int n = A . length ; System . out . print ( solve ( A , n ) ) ; } }

Index/key variables: j, n
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 10000 ; @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] adj = new Vector [ N ] ; static int [ ] lvl = new int [ N ] , dist1 = new int [ N ] , dist2 = new int [ N ] ; static void AddEdge ( int u , int v ) { adj [ u ] . add ( v ) ; adj [ v ] . add ( u ) ; } static int end1 , end2 , maxi ; static void findFirstEnd ( int u , int p ) { lvl [ u ] = 1 + lvl [ p ] ; if ( lvl [ u ] > maxi ) { maxi = lvl [ u ] ; end1 = u ; } for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) { if ( adj [ u ] . elementAt ( i ) != p ) { findFirstEnd ( adj [ u ] . elementAt ( i ) , u ) ; } } } static void clear ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) { lvl [ i ] = 0 ; } maxi = 0 ; dist1 [ 0 ] = dist2 [ 0 ] = - 1 ; } static void findSecondEnd ( int u , int p ) { lvl [ u ] = 1 + lvl [ p ] ; if ( lvl [ u ] > maxi ) { maxi = lvl [ u ] ; end2 = u ; } for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) { if ( adj [ u ] . elementAt ( i ) != p ) { findSecondEnd ( adj [ u ] . elementAt ( i ) , u ) ; } } } static void findDistancefromFirst ( int u , int p ) { dist1 [ u ] = 1 + dist1 [ p ] ; for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) { if ( adj [ u ] . elementAt ( i ) != p ) { findDistancefromFirst ( adj [ u ] . elementAt ( i ) , u ) ; } } } static void findDistancefromSecond ( int u , int p ) { dist2 [ u ] = 1 + dist2 [ p ] ; for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) { if ( adj [ u ] . elementAt ( i ) != p ) { findDistancefromSecond ( adj [ u ] . elementAt ( i ) , u ) ; } } } static void findNodes ( ) { int n = 5 ; AddEdge ( 1 , 2 ) ; AddEdge ( 1 , 3 ) ; AddEdge ( 3 , 4 ) ; AddEdge ( 3 , 5 ) ; findFirstEnd ( 1 , 0 ) ; clear ( n ) ; findSecondEnd ( end1 , 0 ) ; findDistancefromFirst ( end1 , 0 ) ; findDistancefromSecond ( end2 , 0 ) ; for ( int i = 1 ; i <= n ; i ++ ) { int x = dist1 [ i ] ; int y = dist2 [ i ] ; if ( x >= y ) { System . out . print ( end1 + " ▁ " ) ; } else { System . out . print ( end2 + " ▁ " ) ; } } } public static void main ( String [ ] args ) { for ( int i = 0 ; i < N ; i ++ ) { adj [ i ] = new Vector < > ( ) ; } findNodes ( ) ; } }

Index/key variables: N, i, p, u, v
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } static int digitSum ( int num ) { int sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num /= 10 ; } return sum ; } static void sumAndProduct ( Node head_ref ) { int prod = 1 ; int sum = 0 ; Node ptr = head_ref ; while ( ptr != null ) { if ( ( digitSum ( ptr . data ) % 2 != 1 ) ) { prod *= ptr . data ; sum += ptr . data ; } ptr = ptr . next ; } System . out . print ( " Sum ▁ = ▁ " + sum + "NEW_LINE"); System . out . print ( " Product ▁ = ▁ " + prod ) ; } public static void main ( String [ ] args ) { Node head = null ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 8 ) ; head = push ( head , 16 ) ; head = push ( head , 15 ) ; sumAndProduct ( head ) ; } }

Accumulator variables: num, prod, sum
Class/struct names: GFG, Node
Java program:
import java . util . * ; import java . io . * ; class GFG { public static String ShortestPalindrome ( String s ) { int n = s . length ( ) ; Vector < String > v = new Vector < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int l = i ; int r = i ; String ans1 = " " ; String ans2 = " " ; while ( l >= 0 && r < n && s . charAt ( l ) == s . charAt ( r ) ) { ans1 += s . charAt ( l ) ; l -- ; r ++ ; } l = i - 1 ; r = i ; while ( l >= 0 && r < n && s . charAt ( l ) == s . charAt ( r ) ) { ans2 += s . charAt ( l ) ; l -- ; r ++ ; } v . add ( ans1 ) ; v . add ( ans2 ) ; } String ans = v . get ( 0 ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( v . get ( i ) != " " ) { if ( ans . charAt ( 0 ) >= v . get ( i ) . charAt ( 0 ) ) { ans = v . get ( i ) ; } } } return ans ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; System . out . println ( ShortestPalindrome ( s ) ) ; } }

Accumulator variables: ans1, ans2, i, l, r
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getMinimumOps ( Vector < Integer > ar ) { int n = ar . size ( ) ; int small = Collections . min ( ar ) ; int large = Collections . max ( ar ) ; int [ ] [ ] dp = new int [ n ] [ large + 1 ] ; for ( int j = small ; j <= large ; j ++ ) { dp [ 0 ] [ j ] = Math . abs ( ar . get ( 0 ) - j ) ; } for ( int i = 1 ; i < n ; i ++ ) { int minimum = Integer . MAX_VALUE ; for ( int j = small ; j <= large ; j ++ ) { minimum = Math . min ( minimum , dp [ i - 1 ] [ j ] ) ; dp [ i ] [ j ] = minimum + Math . abs ( ar . get ( i ) - j ) ; } } int ans = Integer . MAX_VALUE ; for ( int j = small ; j <= large ; j ++ ) { ans = Math . min ( ans , dp [ n - 1 ] [ j ] ) ; } return ans ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 1 , 2 , 1 , 4 , 3 } ; Vector < Integer > ar = new Vector < > ( Arrays . asList ( arr ) ) ; System . out . println ( getMinimumOps ( ar ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int getMinimumOps ( int ar [ ] , int k ) { int n = ar . length ; int dp [ ] [ ] = new int [ n ] [ k + 1 ] ; dp [ 0 ] [ 1 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int maxGroups = Math . min ( k , i + 1 ) ; for ( int j = 1 ; j <= maxGroups ; j ++ ) { dp [ i ] [ j ] = Integer . MAX_VALUE ; if ( j == 1 ) { int freq [ ] = new int [ 100000 ] ; int freqOfMode = 0 ; for ( int it = 0 ; it <= i ; it ++ ) { freq [ ar [ it ] ] ++ ; int newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; } dp [ i ] [ 1 ] = ( i + 1 ) - freqOfMode ; } else { int freq [ ] = new int [ 100000 ] ; int freqOfMode = 0 ; for ( int it = i ; it >= j - 1 ; it -- ) { freq [ ar [ it ] ] ++ ; int newElementFreq = freq [ ar [ it ] ] ; if ( newElementFreq > freqOfMode ) freqOfMode = newElementFreq ; int elementsToChange = i - it + 1 ; elementsToChange -= freqOfMode ; dp [ i ] [ j ] = Math . min ( dp [ it - 1 ] [ j - 1 ] + elementsToChange , dp [ i ] [ j ] ) ; } } } } return dp [ n - 1 ] [ k ] ; } public static void main ( String args [ ] ) { int k = 3 ; int ar [ ] = { 3 , 1 , 3 , 3 , 2 , 1 , 8 , 5 } ; System . out . println ( getMinimumOps ( ar , k ) ) ; } }

Index/key variables: i, it, j, k, n
Accumulator variables: elementsToChange, i, it, j
Iterator variables: i, it, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static int lcm ( int x , int y ) { int temp = ( x * y ) / __gcd ( x , y ) ; return temp ; } static void findNumbers ( int a [ ] , int n , int b [ ] , int m ) { int lcmA = 1 , gcdB = 0 ; for ( int i = 0 ; i < n ; i ++ ) lcmA = lcm ( lcmA , a [ i ] ) ; for ( int i = 0 ; i < m ; i ++ ) gcdB = __gcd ( gcdB , b [ i ] ) ; if ( gcdB % lcmA != 0 ) { System . out . print ( " - 1" ) ; return ; } int num = lcmA ; while ( num <= gcdB ) { if ( gcdB % num == 0 ) System . out . print ( num + " ▁ " ) ; num += lcmA ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 2 , 4 } ; int b [ ] = { 16 , 32 , 64 } ; int n = a . length ; int m = b . length ; findNumbers ( a , n , b , m ) ; } }

Index/key variables: i
Accumulator variables: i, num
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static int power ( int x , int y ) { int res = 1 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = res * x ; y = y >> 1 ; x = x * x ; } return res ; } static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void FindProbability ( int n ) { int up = binomialCoeff ( 2 * n , n ) ; int down = power ( 2 , 2 * n ) ; int g = gcd ( up , down ) ; up /= g ; down /= g ; System . out . println ( up + " / " + down ) ; } public static void main ( String [ ] args ) { int N = 8 ; FindProbability ( N ) ; } }

Accumulator variables: down, res, up
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void main ( String [ ] args ) { int N = 4 , i , j , min ; System . out . println ( " Value ▁ of ▁ N : ▁ " + N ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; System . out . print ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; System . out . print ( N - min + 1 ) ; } System . out . println ( ) ; } for ( i = N - 1 ; i >= 1 ; i -- ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; System . out . print ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; System . out . print ( N - min + 1 ) ; } System . out . println ( ) ; } } }

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