dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . Arrays ; class Test { static int arr [ ] = new int [ ] { 10 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; static int maxSum ( ) { int arrSum = 0 ; int currVal = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { arrSum = arrSum + arr [ i ] ; currVal = currVal + ( i * arr [ i ] ) ; } int maxVal = currVal ; for ( int j = 1 ; j < arr . length ; j ++ ) { currVal = currVal + arrSum - arr . length * arr [ arr . length - j ] ; if ( currVal > maxVal ) maxVal = currVal ; } return maxVal ; } public static void main ( String [ ] args ) { System . out . println ( " Max ▁ sum ▁ is ▁ " + maxSum ( ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Test
Java program:
class GfG { static class Node { int data ; Node left , right ; } static void printOddNodes ( Node root , boolean isOdd ) { if ( root == null ) return ; if ( isOdd == true ) System . out . print ( root . data + " ▁ " ) ; printOddNodes ( root . left , ! isOdd ) ; printOddNodes ( root . right , ! isOdd ) ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; printOddNodes ( root , true ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . * ; import java . io . * ; class GFG { static int maxSum ( int arr [ ] , int n ) { int res = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int curr_sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int index = ( i + j ) % n ; curr_sum += j * arr [ index ] ; } res = Math . max ( res , curr_sum ) ; } return res ; } public static void main ( String args [ ] ) { int arr [ ] = { 8 , 3 , 1 , 2 } ; int n = arr . length ; System . out . println ( maxSum ( arr , n ) ) ; } }

Index/key variables: index
Accumulator variables: curr_sum, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int maxSum ( int arr [ ] , int n ) { int cum_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) cum_sum += arr [ i ] ; int curr_val = 0 ; for ( int i = 0 ; i < n ; i ++ ) curr_val += i * arr [ i ] ; int res = curr_val ; for ( int i = 1 ; i < n ; i ++ ) { int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ; curr_val = next_val ; res = Math . max ( res , next_val ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 3 , 1 , 2 } ; int n = arr . length ; System . out . println ( maxSum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: cum_sum, curr_val, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int solve ( int [ ] arr , int n ) { int k = arr . length ; int mp [ ] = new int [ n + 2 ] ; for ( int i = 0 ; i <= n ; i ++ ) { mp [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { mp [ arr [ i ] ] = 1 ; } int leftSegment = arr [ 0 ] - 1 ; for ( int i = 1 ; i < k ; i ++ ) { leftSegment = Math . max ( leftSegment , arr [ i ] - arr [ i - 1 ] - 1 ) ; } int rightSegment = n - arr [ k - 1 ] ; int maxSegment = Math . max ( leftSegment , rightSegment ) ; int tim ; if ( ( maxSegment & 1 ) == 1 ) tim = ( maxSegment / 2 ) + 1 ; else tim = maxSegment / 2 ; return tim ; } public static void main ( String [ ] args ) { int N = 5 ; int arr [ ] = { 1 , 4 } ; System . out . println ( solve ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class LinearSearch { static int countRotations ( int arr [ ] , int n ) { int min = arr [ 0 ] , min_index = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( min > arr [ i ] ) { min = arr [ i ] ; min_index = i ; } } return min_index ; } public static void main ( String [ ] args ) { int arr [ ] = { 15 , 18 , 2 , 3 , 6 , 12 } ; int n = arr . length ; System . out . println ( countRotations ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: LinearSearch
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class BinarySearch { static int countRotations ( int arr [ ] , int low , int high ) { if ( high < low ) return 0 ; if ( high == low ) return low ; int mid = low + ( high - low ) / 2 ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ; if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ; if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ; return countRotations ( arr , mid + 1 , high ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 15 , 18 , 2 , 3 , 6 , 12 } ; int n = arr . length ; System . out . println ( countRotations ( arr , 0 , n - 1 ) ) ; } }

Index/key variables: high, mid
Class/struct names: BinarySearch
Java program:
class LeftRotate { static void preprocess ( int arr [ ] , int n , int temp [ ] ) { for ( int i = 0 ; i < n ; i ++ ) temp [ i ] = temp [ i + n ] = arr [ i ] ; } static void leftRotate ( int arr [ ] , int n , int k , int temp [ ] ) { int start = k % n ; for ( int i = start ; i < start + n ; i ++ ) System . out . print ( temp [ i ] + " ▁ " ) ; System . out . print ( "NEW_LINE"); } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int temp [ ] = new int [ 2 * n ] ; preprocess ( arr , n , temp ) ; int k = 2 ; leftRotate ( arr , n , k , temp ) ; k = 3 ; leftRotate ( arr , n , k , temp ) ; k = 4 ; leftRotate ( arr , n , k , temp ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: LeftRotate
Java program:
import java . util . Arrays ; class Main { public static void Desired_Array ( int v [ ] ) { int n = v . length ; Arrays . sort ( v ) ; int i = n - 1 ; while ( i > 0 ) { int p = v [ n - 1 ] ; for ( int j = n - 1 ; j >= i ; j -- ) { v [ j ] = v [ j - 1 ] ; } v [ i ] = p ; i -- ; } for ( int x = 0 ; x < v . length ; x ++ ) { System . out . print ( v [ x ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int v [ ] = { 1 , 2 , 3 , 4 , 5 } ; Desired_Array ( v ) ; int v1 [ ] = { 1 , 12 , 2 , 10 , 4 , 16 , 6 } ; Desired_Array ( v1 ) ; } }

Index/key variables: i, j, x
Accumulator variables: i, j, x
Iterator variables: j, x
Class/struct names: Main
Java program:
import java . io . * ; class GFG { static void leftRotate ( int arr [ ] , int n , int k ) { for ( int i = k ; i < k + n ; i ++ ) System . out . print ( arr [ i % n ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; k = 3 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; k = 4 ; leftRotate ( arr , n , k ) ; System . out . println ( ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class Geeks_For_Geeks { public static int [ ] sortArrays ( int [ ] arr ) { int length = arr . length ; for ( int j = 0 ; j < length - 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { int temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = - 1 ; } } return arr ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 99 , 9 , 8 , 7 , 6 , 0 , 5 , 4 , 3 } ; System . out . println ( " Original ▁ array : ▁ " + Arrays . toString ( arr ) ) ; arr = sortArrays ( arr ) ; System . out . println ( " Sorted ▁ array : ▁ " + Arrays . toString ( arr ) ) ; } }

Index/key variables: j
Accumulator variables: j
Iterator variables: j
Class/struct names: Geeks_For_Geeks
Java program:
import java . util . * ; class Geeks_For_Geeks { public static char [ ] sortArrays ( char [ ] arr ) { int length = arr . length ; for ( int j = 0 ; j < arr . length - 1 ; j ++ ) { int d1 = arr [ j ] ; int d2 = arr [ j + 1 ] ; if ( d1 > d2 ) { char temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = - 1 ; } } return arr ; } public static void main ( String args [ ] ) { String geeks = " GEEKSFORGEEKS " ; char arr [ ] = geeks . toCharArray ( ) ; System . out . println ( " Original ▁ array : ▁ " + Arrays . toString ( arr ) ) ; arr = sortArrays ( arr ) ; System . out . println ( " Sorted ▁ array : ▁ " + Arrays . toString ( arr ) ) ; } }

Index/key variables: j
Accumulator variables: j
Iterator variables: j
Class/struct names: Geeks_For_Geeks
Java program:
import java . util . * ; import java . io . * ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class GFG { public static int findLevel ( Node root , int data ) { if ( data < root . data ) return - 1 ; if ( data == root . data ) return 0 ; int cur_level = 0 ; while ( true ) { cur_level ++ ; root = root . left ; if ( root . data == data ) return - 2 ; if ( root . data < data && ( root . left == null root . left . data > data ) ) { break ; } } return cur_level ; } public static int traversePath ( Node root , ArrayList < Integer > path ) { for ( int i = 0 ; i < path . size ( ) ; i ++ ) { int direction = path . get ( i ) ; if ( direction == 0 ) { if ( root . left == null ) return - 1 ; root = root . left ; } else { if ( root . right == null ) return - 1 ; root = root . right ; } } return root . data ; } static ArrayList < Integer > generateGray ( int n , int x ) { ArrayList < Integer > gray = new ArrayList < Integer > ( ) ; int i = 0 ; while ( x > 0 ) { gray . add ( x % 2 ) ; x = x / 2 ; i ++ ; } Collections . reverse ( gray ) ; for ( int j = 0 ; j < n - i ; j ++ ) gray . add ( 0 , 0 ) ; return gray ; } public static boolean binarySearch ( Node root , int start , int end , int data , int level ) { if ( end >= start ) { int mid = ( start + end ) / 2 ; ArrayList < Integer > encoding = generateGray ( level , mid ) ; int element_found = traversePath ( root , encoding ) ; if ( element_found == - 1 ) return binarySearch ( root , start , mid - 1 , data , level ) ; if ( element_found == data ) return true ; if ( element_found < data ) return binarySearch ( root , mid + 1 , end , data , level ) ; else return binarySearch ( root , start , mid - 1 , data , level ) ; } return false ; } public static boolean findKey ( Node root , int data ) { int level = findLevel ( root , data ) ; if ( level == - 1 ) return false ; if ( level == - 2 ) return true ; return binarySearch ( root , 0 , ( int ) Math . pow ( 2 , level ) - 1 , data , level ) ; } public static void main ( String [ ] args ) { Node root = new Node ( 5 ) ; root . left = new Node ( 8 ) ; root . right = new Node ( 10 ) ; root . left . left = new Node ( 13 ) ; root . left . right = new Node ( 23 ) ; root . right . left = new Node ( 25 ) ; root . right . right = new Node ( 30 ) ; root . left . left . left = new Node ( 32 ) ; root . left . left . right = new Node ( 40 ) ; root . left . right . left = new Node ( 50 ) ; int arr [ ] = { 5 , 8 , 9 } ; int n = arr . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( findKey ( root , arr [ i ] ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } }

Index/key variables: i
Accumulator variables: cur_level, i, j
Iterator variables: i, j
Class/struct names: GFG, Node
Java program:
import java . util . * ; public class TwistedMatrix { static int MAX = 1000 ; static void ToSpiral ( int m , int n , int Sorted [ ] , int a [ ] [ ] ) { int index = 0 ; int k = 0 , l = 0 ; while ( k < m && l < n ) { for ( int i = l ; i < n ; ++ i ) { a [ k ] [ i ] = Sorted [ index ] ; index ++ ; } k ++ ; for ( int i = k ; i < m ; ++ i ) { a [ i ] [ n - 1 ] = Sorted [ index ] ; index ++ ; } n -- ; if ( k < m ) { for ( int i = n - 1 ; i >= l ; -- i ) { a [ m - 1 ] [ i ] = Sorted [ index ] ; index ++ ; } m -- ; } if ( l < n ) { for ( int i = m - 1 ; i >= k ; -- i ) { a [ i ] [ l ] = Sorted [ index ] ; index ++ ; } l ++ ; } } } public static int [ ] convert2Dto1D ( int y [ ] [ ] , int m , int n ) { int index = 0 ; int x [ ] = new int [ m * n ] ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { x [ index ] = y [ i ] [ j ] ; index ++ ; } } return x ; } public static void PrintMatrix ( int a [ ] [ ] , int m , int n ) { for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { System . out . print ( a [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static int [ ] SortArray ( int x [ ] ) { Arrays . sort ( x ) ; return x ; } public static void convertMatrixToSortedSpiral ( int y [ ] [ ] , int m , int n ) { int a [ ] [ ] = new int [ MAX ] [ MAX ] ; int x [ ] = new int [ m * n ] ; x = convert2Dto1D ( y , m , n ) ; x = SortArray ( x ) ; ToSpiral ( m , n , x , a ) ; PrintMatrix ( a , m , n ) ; } public static void main ( String [ ] args ) { int m = 4 , n = 3 ; int y [ ] [ ] = { { 2 , 5 , 12 } , { 22 , 45 , 55 } , { 1 , 6 , 8 } , { 13 , 56 , 10 } } ; convertMatrixToSortedSpiral ( y , m , n ) ; } }

Index/key variables: MAX, i, index, j, k, l
Accumulator variables: i, index, j, k, l, m, n
Iterator variables: i, j
Class/struct names: TwistedMatrix
Java program:
import java . io . * ; class GFG { static void reverseArray ( int arr [ ] , int start , int end ) { while ( start < end ) { int temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; start ++ ; end -- ; } } static void rightRotate ( int arr [ ] , int d , int n ) { reverseArray ( arr , 0 , n - 1 ) ; reverseArray ( arr , 0 , d - 1 ) ; reverseArray ( arr , d , n - 1 ) ; } static void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = arr . length ; int k = 3 ; rightRotate ( arr , k , n ) ; printArray ( arr , n ) ; } }

Index/key variables: end, i, start
Accumulator variables: end, i, start
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static void printOddNodes ( Node root ) { if ( root == null ) return ; Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; boolean isOdd = true ; while ( true ) { int nodeCount = q . size ( ) ; if ( nodeCount == 0 ) break ; while ( nodeCount > 0 ) { Node node = q . peek ( ) ; if ( isOdd == true ) System . out . print ( node . data + " ▁ " ) ; q . remove ( ) ; if ( node . left != null ) q . add ( node . left ) ; if ( node . right != null ) q . add ( node . right ) ; nodeCount -- ; } isOdd = ! isOdd ; } } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; printOddNodes ( root ) ; } }

Accumulator variables: nodeCount
Boolean variables: isOdd
Class/struct names: GfG, Node
Java program:
class GFG { static int maxHamming ( int arr [ ] , int n ) { int brr [ ] = new int [ 2 * n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ n + i ] = arr [ i ] ; int maxHam = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int currHam = 0 ; for ( int j = i , k = 0 ; j < ( i + n ) ; j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ; if ( currHam == n ) return n ; maxHam = Math . max ( maxHam , currHam ) ; } return maxHam ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 8 } ; int n = arr . length ; System . out . print ( maxHamming ( arr , n ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: currHam, i, j, k
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class arr_rot { static void leftRotate ( int arr [ ] , int n , int k ) { int mod = k % n ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ ( i + mod ) % n ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , n , k ) ; k = 3 ; leftRotate ( arr , n , k ) ; k = 4 ; leftRotate ( arr , n , k ) ; } }

Iterator variables: i
Class/struct names: arr_rot
Java program:
import java . util . Arrays ; import java . util . Comparator ; public class MinimumCirclesTobeRemoved { private class Circle implements Comparator < Circle > { int start ; int end ; public int compare ( Circle a , Circle b ) { if ( a . end == b . end ) { return ( a . start - b . start ) ; } return a . end - b . end ; } } public void CountCircles ( int [ ] c , int [ ] r , int n ) { Circle diameter [ ] = new Circle [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { diameter [ i ] = new Circle ( ) ; diameter [ i ] . start = ( c [ i ] - r [ i ] ) ; diameter [ i ] . end = ( c [ i ] + r [ i ] ) ; } Arrays . sort ( diameter , new Circle ( ) ) ; int count = 0 ; int curr = diameter [ 0 ] . end ; for ( int i = 1 ; i < n ; i ++ ) { if ( diameter [ i ] . start > curr ) { curr = diameter [ i ] . end ; } else { count ++ ; } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { MinimumCirclesTobeRemoved a = new MinimumCirclesTobeRemoved ( ) ; int [ ] c = new int [ ] { 1 , 2 , 3 , 4 } ; int [ ] r = new int [ ] { 1 , 1 , 1 , 1 } ; a . CountCircles ( c , r , c . length ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Circle, MinimumCirclesTobeRemoved
Java program:
import java . io . * ; import java . util . * ; class GFG { static void leftRotate ( Integer arr [ ] , int k , int n ) { Collections . rotate ( Arrays . asList ( arr ) , n - k ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { Integer arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = arr . length ; int k = 2 ; leftRotate ( arr , k , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findElement ( int [ ] arr , int [ ] [ ] ranges , int rotations , int index ) { for ( int i = rotations - 1 ; i >= 0 ; i -- ) { int left = ranges [ i ] [ 0 ] ; int right = ranges [ i ] [ 1 ] ; if ( left <= index && right >= index ) { if ( index == left ) index = right ; else index -- ; } } return arr [ index ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int rotations = 2 ; int [ ] [ ] ranges = { { 0 , 2 } , { 0 , 3 } } ; int index = 1 ; System . out . println ( findElement ( arr , ranges , rotations , index ) ) ; } }

Index/key variables: i, index
Accumulator variables: i, index
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String sort ( String s ) { char [ ] c = new char [ s . length ( ) + 1 ] ; c = s . toCharArray ( ) ; Arrays . sort ( c ) ; int al_c = 0 , nu_c = 0 ; while ( c [ al_c ] < 97 ) al_c ++ ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) < 97 ) s = s . substring ( 0 , i ) + c [ nu_c ++ ] + s . substring ( i + 1 ) ; else s = s . substring ( 0 , i ) + c [ al_c ++ ] + s . substring ( i + 1 ) ; } return s ; } public static void main ( String [ ] args ) { String s = " d4c3b2a1" ; System . out . println ( sort ( s ) ) ; } }

Index/key variables: al_c
Accumulator variables: al_c, i, nu_c
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { public static void splitArr ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { int x = arr [ 0 ] ; for ( int j = 0 ; j < n - 1 ; ++ j ) arr [ j ] = arr [ j + 1 ] ; arr [ n - 1 ] = x ; } } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 10 , 5 , 6 , 52 , 36 } ; int n = arr . length ; int position = 2 ; splitArr ( arr , 6 , position ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { public static void SplitAndAdd ( int [ ] A , int length , int rotation ) { int [ ] tmp = new int [ length * 2 ] ; System . arraycopy ( A , 0 , tmp , 0 , length ) ; System . arraycopy ( A , 0 , tmp , length , length ) ; for ( int i = rotation ; i < rotation + length ; i ++ ) A [ i - rotation ] = tmp [ i ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 10 , 5 , 6 , 52 , 36 } ; int n = arr . length ; int position = 2 ; SplitAndAdd ( arr , n , position ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } static void sort_shell_metzner ( int arr [ ] , int n ) { int i , j , k , l , m , temp ; m = n ; while ( m > 0 ) { m /= 2 ; k = n - m ; j = 0 ; do { i = j ; do { l = i + m ; if ( l < n && arr [ i ] > arr [ l ] ) { swap ( arr , i , l ) ; i -= m ; } else { break ; } } while ( i >= 0 ) ; j ++ ; } while ( j <= k ) ; } } static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 0 , - 2 , 8 , 5 , 1 } ; int n = arr . length ; sort_shell_metzner ( arr , n ) ; printArray ( arr , n ) ; } }

Index/key variables: i, j, l
Accumulator variables: i, j, m
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void fixArray ( int ar [ ] , int n ) { int i , j , temp ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( ar [ j ] == i ) { temp = ar [ j ] ; ar [ j ] = ar [ i ] ; ar [ i ] = temp ; break ; } } } for ( i = 0 ; i < n ; i ++ ) { if ( ar [ i ] != i ) { ar [ i ] = - 1 ; } } System . out . println ( " Array ▁ after ▁ Rearranging " ) ; for ( i = 0 ; i < n ; i ++ ) { System . out . print ( ar [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n , ar [ ] = { - 1 , - 1 , 6 , 1 , 9 , 3 , 2 , - 1 , 4 , - 1 } ; n = ar . length ; fixArray ( ar , 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 class pair { int first , second ; pair ( int f , int s ) { first = f ; second = s ; } } static int getFinalSum ( int a [ ] , int n , pair queries [ ] , int q , int k ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) answer += a [ i ] ; Vector < Integer > contribution = new Vector < Integer > ( ) ; for ( int i = 0 ; i < q ; i ++ ) { contribution . add ( queries [ i ] . second - queries [ i ] . first + 1 ) ; } Comparator < Integer > Comp = new Comparator < Integer > ( ) { public int compare ( Integer e1 , Integer e2 ) { if ( e1 > e2 ) return - 1 ; else return 1 ; } } ; Collections . sort ( contribution , Comp ) ; int i = 0 ; while ( i < k ) { answer += ( int ) contribution . get ( i ) ; i ++ ; } return answer ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 1 , 2 , 2 , 2 , 3 } ; int n = a . length ; pair queries [ ] = new pair [ 5 ] ; queries [ 0 ] = new pair ( 0 , 4 ) ; queries [ 1 ] = new pair ( 1 , 2 ) ; queries [ 2 ] = new pair ( 2 , 5 ) ; queries [ 3 ] = new pair ( 2 , 3 ) ; queries [ 4 ] = new pair ( 2 , 4 ) ; int q = queries . length ; int k = 3 ; System . out . println ( getFinalSum ( a , n , queries , q , k ) ) ; } }

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG, pair