dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int countObtuseAngles ( int a , int b , int k ) { int c1 = ( b - a ) - 1 ; int c2 = ( k - b ) + ( a - 1 ) ; if ( c1 == c2 ) return 0 ; return min ( c1 , c2 ) ; } public static void main ( String arg [ ] ) { int k = 6 , a = 1 , b = 3 ; System . out . print ( countObtuseAngles ( a , b , k ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static class Point { float x , y ; Point ( ) { x = y = 0 ; } Point ( float a , float b ) { x = a ; y = b ; } } ; static void printPoints ( Point source , float l , int m ) { Point a = new Point ( ) ; Point b = new Point ( ) ; if ( m == 0 ) { a . x = source . x + l ; a . y = source . y ; b . x = source . x - l ; b . y = source . y ; } else if ( Double . isInfinite ( m ) ) { a . x = source . x ; a . y = source . y + l ; b . x = source . x ; b . y = source . y - l ; } else { float dx = ( float ) ( l / Math . sqrt ( 1 + ( m * m ) ) ) ; float dy = m * dx ; a . x = source . x + dx ; a . y = source . y + dy ; b . x = source . x - dx ; b . y = source . y - dy ; } System . out . println ( a . x + " , ▁ " + a . y ) ; System . out . println ( b . x + " , ▁ " + b . y ) ; } public static void main ( String [ ] args ) { Point p = new Point ( 2 , 1 ) , q = new Point ( 1 , 0 ) ; printPoints ( p , ( float ) Math . sqrt ( 2 ) , 1 ) ; System . out . println ( ) ; printPoints ( q , 5 , 0 ) ; } }

Class/struct names: GFG, Point
Java program:
class GFG { static class point { int x , y ; public point ( int x , int y ) { super ( ) ; this . x = x ; this . y = y ; } } ; static class line { public line ( int a , int b , int c ) { this . a = a ; this . b = b ; this . c = c ; } int a , b , c ; line ( ) { } } ; static int evalPointOnLine ( point p , line curLine ) { int eval = curLine . a * p . x + curLine . b * p . y + curLine . c ; if ( eval > 0 ) return 1 ; return - 1 ; } static int minJumpToReachDestination ( point start , point dest , line lines [ ] , int N ) { int jumps = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int signStart = evalPointOnLine ( start , lines [ i ] ) ; int signDest = evalPointOnLine ( dest , lines [ i ] ) ; if ( signStart * signDest < 0 ) jumps ++ ; } return jumps ; } public static void main ( String [ ] args ) { point start = new point ( 1 , 1 ) ; point dest = new point ( - 2 , - 1 ) ; line [ ] lines = new line [ 3 ] ; lines [ 0 ] = new line ( 1 , 0 , 0 ) ; lines [ 1 ] = new line ( 0 , 1 , 0 ) ; lines [ 2 ] = new line ( 1 , 1 , - 2 ) ; System . out . print ( minJumpToReachDestination ( start , dest , lines , 3 ) ) ; } }

Index/key variables: i
Accumulator variables: i, jumps
Iterator variables: i
Class/struct names: GFG, line, point
Java program:
import java . util . * ; class GFG { static class Interval { int start , end ; Interval ( int start , int end ) { this . start = start ; this . end = end ; } } ; static int minDistanceToCoverIntervals ( Interval intervals [ ] , int N , int x ) { int rightMostStart = Integer . MIN_VALUE ; int leftMostEnd = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { if ( rightMostStart < intervals [ i ] . start ) rightMostStart = intervals [ i ] . start ; if ( leftMostEnd > intervals [ i ] . end ) leftMostEnd = intervals [ i ] . end ; } int res ; if ( rightMostStart > leftMostEnd ) res = - 1 ; else if ( rightMostStart <= x && x <= leftMostEnd ) res = 0 ; else res = ( x < rightMostStart ) ? ( rightMostStart - x ) : ( x - leftMostEnd ) ; return res ; } public static void main ( String [ ] args ) { int x = 3 ; Interval [ ] intervals = { new Interval ( 0 , 7 ) , new Interval ( 2 , 14 ) , new Interval ( 4 , 6 ) } ; int N = intervals . length ; int res = minDistanceToCoverIntervals ( intervals , N , x ) ; if ( res == - 1 ) System . out . print ( " Not ▁ Possible ▁ to ▁ " + "cover all intervalsNEW_LINE"); else System . out . print ( res + "NEW_LINE"); } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Interval
Java program:
import java . util . * ; class GFG { static void findTriangle ( int a [ ] , int n ) { int b [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = a [ i ] * a [ i ] ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; int x = 0 , y = 0 , z = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int p = i + 1 ; int q = i + 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { while ( p < n - 1 && b [ i ] + b [ j ] >= b [ p + 1 ] ) p ++ ; q = Math . max ( q , p ) ; while ( q < n - 1 && a [ i ] + a [ j ] > a [ q + 1 ] ) q ++ ; if ( b [ i ] + b [ j ] == b [ p ] ) { x += Math . max ( p - j - 1 , 0 ) ; y ++ ; z += q - p ; } else { x += Math . max ( p - j , 0 ) ; z += q - p ; } } } System . out . println ( " Acute ▁ Triangle : ▁ " + x ) ; System . out . println ( " Right ▁ Triangle : ▁ " + y ) ; System . out . println ( " Obtuse ▁ Triangle : ▁ " + z ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 9 , 10 , 12 , 15 } ; int n = arr . length ; findTriangle ( arr , n ) ; } }

Index/key variables: i, j, n, p
Accumulator variables: i, j, p, q, x, y, z
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) { float endAngle = 360 / percent + startAngle ; double polarradius = Math . sqrt ( x * x + y * y ) ; double Angle = Math . atan ( y / x ) ; if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( " Point " + " ( " + x + " , " + y + " ) " + " exist in the circle sectorNEW_LINE"); else System . out . print ( " Point " + " ( " + x + " , " + y + " ) " + " exist in the circle sectorNEW_LINE"); } public static void main ( String arg [ ] ) { int radius = 8 , x = 3 , y = 4 ; float percent = 12 , startAngle = 0 ; checkPoint ( radius , x , y , percent , startAngle ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class point { int x , y ; point ( ) { } public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int square ( int x ) { return x * x ; } static int a , b , c ; static void order ( ) { int [ ] copy = new int [ 3 ] ; copy [ 0 ] = a ; copy [ 1 ] = b ; copy [ 2 ] = c ; Arrays . sort ( copy ) ; a = copy [ 0 ] ; b = copy [ 1 ] ; c = copy [ 2 ] ; } static int euclidDistSquare ( point p1 , point p2 ) { return square ( p1 . x - p2 . x ) + square ( p1 . y - p2 . y ) ; } static String getSideClassification ( int a , int b , int c ) { if ( a == b && b == c ) return " Equilateral " ; else if ( a == b b == c ) return " Isosceles " ; else return " Scalene " ; } static String getAngleClassification ( int a , int b , int c ) { if ( a + b > c ) return " acute " ; else if ( a + b == c ) return " right " ; else return " obtuse " ; } static void classifyTriangle ( point p1 , point p2 , point p3 ) { a = euclidDistSquare ( p1 , p2 ) ; b = euclidDistSquare ( p1 , p3 ) ; c = euclidDistSquare ( p2 , p3 ) ; order ( ) ; System . out . println ( " Triangle ▁ is ▁ " + getAngleClassification ( a , b , c ) + " ▁ and ▁ " + getSideClassification ( a , b , c ) ) ; } public static void main ( String [ ] args ) { point p1 , p2 , p3 ; p1 = new point ( 3 , 0 ) ; p2 = new point ( 0 , 4 ) ; p3 = new point ( 4 , 7 ) ; classifyTriangle ( p1 , p2 , p3 ) ; p1 = new point ( 0 , 0 ) ; p2 = new point ( 1 , 1 ) ; p3 = new point ( 1 , 2 ) ; classifyTriangle ( p1 , p2 , p3 ) ; } }

Class/struct names: GFG, point
Java program:
import java . io . * ; class GFG { public static double polygonArea ( double X [ ] , double Y [ ] , int n ) { double area = 0.0 ; int j = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ; j = i ; } return Math . abs ( area / 2.0 ) ; } public static void main ( String [ ] args ) { double X [ ] = { 0 , 2 , 4 } ; double Y [ ] = { 1 , 3 , 7 } ; int n = 3 ; System . out . println ( polygonArea ( X , Y , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: area, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashSet ; class GFG { public static void findDifferenceArray ( int arr [ ] , int N ) { HashSet < Integer > S1 = new HashSet < Integer > ( ) ; HashSet < Integer > S2 = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { S1 . add ( arr [ j ] ) ; } for ( int j = i + 1 ; j < N ; j ++ ) { S2 . add ( arr [ j ] ) ; } System . out . print ( Math . abs ( S1 . size ( ) - S2 . size ( ) ) + " ▁ " ) ; S1 . clear ( ) ; S2 . clear ( ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 7 , 7 , 3 , 2 , 3 } ; int N = arr . length ; findDifferenceArray ( arr , N ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int maximumSubarraySum ( int arr [ ] , int N ) { HashMap < Integer , Integer > memo = new HashMap < > ( ) ; int res = Integer . MIN_VALUE ; int currsum = 0 , currval = 0 ; for ( int i = 0 ; i < N ; ++ i ) { currval = arr [ i ] ; currsum = currsum + currval ; if ( memo . containsKey ( currval ) ) { if ( currval > 0 ) res = Math . max ( res , currsum - memo . get ( currval ) + currval ) ; else res = Math . max ( res , currsum - memo . get ( currval ) + 2 * currval ) ; } else memo . put ( currval , currsum ) ; if ( currval < 0 ) currsum = currsum - currval ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , - 3 , 4 , 0 , - 1 , - 2 } ; int N = 6 ; System . out . println ( maximumSubarraySum ( arr , N ) ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double f ( double x , int p , double num ) { return Math . pow ( x , p ) - num ; } static double f_prime ( double x , int p ) { return p * Math . pow ( x , p - 1 ) ; } static double root ( double num , int p ) { double left = - num ; double right = num ; double x ; while ( true ) { x = ( left + right ) / 2.0 ; double value = f ( x , p , num ) ; double prime = f_prime ( x , p ) ; if ( value * prime <= 0 ) left = x ; else right = x ; if ( value < 0.000001 && value >= 0 ) { return x ; } } } public static void main ( String args [ ] ) { double P = 1234321 ; int N = 2 ; double ans = root ( P , N ) ; System . out . print ( ans ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minimumAdditionOperation ( int N ) { int count = 0 ; while ( N > 0 ) { if ( N % 2 == 1 ) { count ++ ; } N = N >> 1 ; } return count ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( minimumAdditionOperation ( N ) ) ; } }

Accumulator variables: count
Class/struct names: GFG
Java program:
class GFG { public static int minimumOperations ( int arr [ ] , int N ) { int mini = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; while ( arr [ i ] % 2 == 0 ) { arr [ i ] = arr [ i ] / 2 ; count ++ ; } if ( mini > count ) { mini = count ; } } return mini ; } public static void main ( String args [ ] ) { int arr [ ] = { 4 , 6 } ; int N = arr . length ; System . out . println ( minimumOperations ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int minimumSizeArr ( int A , int B ) { int currXor = 0 ; int reminder = ( A - 1 ) % 4 ; if ( reminder == 0 ) currXor = A - 1 ; else if ( reminder == 1 ) currXor = 1 ; else if ( reminder == 2 ) currXor = A ; int minSize = A ; if ( currXor == B ) return minSize ; else if ( ( currXor ^ B ) == A ) return minSize + 2 ; else return minSize + 1 ; } public static void main ( String [ ] args ) { int A = 1 ; int B = 999 ; System . out . println ( minimumSizeArr ( A , B ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countTriplets ( int N ) { int cnt = 0 ; for ( int A = 1 ; A <= N ; ++ A ) { for ( int B = 1 ; B <= N / A ; ++ B ) { cnt += N / ( A * B ) ; } } return cnt ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . println ( countTriplets ( N ) ) ; } }

Accumulator variables: cnt
Iterator variables: A, B
Class/struct names: GFG
Java program:
public class GFG { final static int maxn = 100001 ; static int gpf [ ] = new int [ maxn ] ; static void modifiedSieve ( ) { for ( int i = 0 ; i < maxn ; i ++ ) gpf [ i ] = 0 ; gpf [ 0 ] = 0 ; gpf [ 1 ] = 1 ; for ( int i = 2 ; i < maxn ; i ++ ) { if ( gpf [ i ] > 0 ) continue ; for ( int j = i ; j < maxn ; j += i ) { gpf [ j ] = Math . max ( i , gpf [ j ] ) ; } } } static int greatestValidInt ( int N ) { modifiedSieve ( ) ; for ( int i = N ; i > 0 ; i -- ) { if ( gpf [ i ] > Math . sqrt ( i ) ) { return i ; } } return - 1 ; } public static void main ( String [ ] args ) { int N = 25 ; System . out . println ( greatestValidInt ( N ) ) ; } }

Index/key variables: i, j, maxn
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void numberOfPasses ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; ++ i ) { -- arr [ i ] ; } for ( int i = 0 ; i < N ; ++ i ) { int cnt = 0 ; int k = i ; do { ++ cnt ; k = arr [ k ] ; } while ( k != i ) ; System . out . print ( cnt + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 4 , 6 , 2 , 1 , 5 , 3 } ; int N = arr . length ; numberOfPasses ( arr , N ) ; } }

Index/key variables: i, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double subfactorial ( int N ) { double res = 0 , fact = 1 ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { fact = fact * i ; if ( count % 2 == 0 ) res = res - ( 1 / fact ) ; else res = res + ( 1 / fact ) ; count ++ ; } return fact * ( 1 + res ) ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( ( int ) ( subfactorial ( N ) ) ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minOperations ( int A [ ] , int B [ ] , int N ) { int cnt = 0 ; int i = 0 ; while ( i < N ) { int j = 0 ; while ( j < N && i < N ) { if ( B [ i ] == A [ j ] ) { i ++ ; } j ++ ; } cnt ++ ; } return cnt ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 4 , 6 , 1 , 5 , 3 } ; int B [ ] = { 6 , 5 , 4 , 2 , 3 , 1 } ; int N = A . length ; System . out . print ( minOperations ( A , B , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: cnt, i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPairs ( int N ) { int res = 0 ; for ( int q = 1 ; q * q <= N ; q ++ ) { int maxP = Math . min ( 2 * N - q , N / q ) ; if ( maxP < q ) continue ; int cnt = maxP - q + 1 ; res += ( cnt / 2 + ( cnt & 1 ) ) ; } return res ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( countPairs ( N ) ) ; } }

Accumulator variables: q, res
Iterator variables: q
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maximizeSubset ( int N , int [ ] arr , int M , int x ) { if ( x == M ) { return 0 ; } int ans = 0 ; for ( int i = x ; i < M ; i ++ ) { if ( N % arr [ i ] == 0 ) { ans = Math . max ( ans , maximizeSubset ( N / arr [ i ] , arr , M , x + 1 ) + 1 ) ; } } return ans ; } public static void main ( String [ ] args ) { int N = 64 ; int [ ] arr = { 1 , 2 , 4 , 8 , 16 , 32 } ; int M = arr . length ; System . out . println ( maximizeSubset ( N , arr , M , 0 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countDistinctSums ( int N , int L , int R ) { int minSum = L * N ; int maxSum = R * N ; return maxSum - minSum + 1 ; } public static void main ( String [ ] args ) { int N = 2 , L = 1 , R = 3 ; System . out . print ( countDistinctSums ( N , L , R ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void setSumtoZero ( double arr [ ] , int N ) { int [ ] A = new int [ N ] ; int sum = 0 ; int m = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { sum += Math . ceil ( arr [ i ] ) ; A [ i ] = ( int ) Math . ceil ( arr [ i ] ) ; } if ( sum > 0 ) { m = Math . min ( sum , N ) ; for ( int i = 0 ; i < N && m > 0 ; i ++ ) { A [ i ] = ( int ) Math . floor ( arr [ i ] ) ; if ( A [ i ] != Math . floor ( arr [ i ] ) ) m -- ; } } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( A [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { double arr [ ] = { - 2 , - 2 , 4.5 } ; int N = arr . length ; setSumtoZero ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i, m, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int Get ( int [ ] graph , int a ) { return graph [ a ] = ( graph [ a ] == a ? a : Get ( graph , graph [ a ] ) ) ; } public static void Union ( int [ ] graph , int a , int b ) { a = Get ( graph , a ) ; b = Get ( graph , b ) ; graph [ a ] = b ; } public static void Queries ( int [ ] [ ] queries , int N , int M ) { int [ ] graph = new int [ N + 2 ] ; for ( int i = 1 ; i <= N + 1 ; i ++ ) { graph [ i ] = i ; } for ( int [ ] query : queries ) { if ( query [ 0 ] == 1 ) { Union ( graph , query [ 1 ] , query [ 1 ] + 1 ) ; } else { int a = Get ( graph , query [ 1 ] ) ; if ( a == N + 1 ) System . out . print ( - 1 ) ; else System . out . print ( graph [ a ] + " ▁ " ) ; } } } public static void main ( String args [ ] ) { int N = 5 ; int [ ] [ ] queries = { { 2 , 1 } , { 1 , 1 } , { 2 , 1 } , { 2 , 3 } } ; int Q = queries . length ; Queries ( queries , N , Q ) ; } }

Index/key variables: a, i
Accumulator variables: i
Iterator variables: i, query
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static long convertToBase9 ( long n ) { long ans = 0 ; long a = 1 ; while ( n > 0 ) { ans += ( a * ( n % 9 ) ) ; a *= 10 ; n /= 9 ; } return ans ; } static long getNthnumber ( long base9 , long K ) { long ans = 0 ; long a = 1 ; while ( base9 > 0 ) { int cur = ( int ) ( base9 % 10 ) ; if ( cur >= K ) { ans += a * ( cur + 1 ) ; } else { ans += a * cur ; } base9 /= 10 ; a *= 10 ; } return ans ; } public static void main ( String [ ] args ) { long N = 10 , K = 1 ; long base9 = convertToBase9 ( N ) ; System . out . println ( getNthnumber ( base9 , K ) ) ; } }

Accumulator variables: a, ans, base9, n
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static boolean binarySearch ( float [ ] arr , int size , float key ) { int low = 0 , high = size - 1 , mid ; while ( low <= high ) { mid = low + ( high - low ) / 2 ; if ( key > arr [ mid ] ) low = mid + 1 ; else if ( key < arr [ mid ] ) high = mid - 1 ; else return true ; } return false ; } static boolean twoPointers ( float [ ] arr , int N , float mean ) { int i = 0 , j = N - 1 ; while ( i < j ) { float temp = ( arr [ i ] + arr [ j ] ) / 2 ; if ( temp > mean ) j -- ; else if ( temp < mean ) i ++ ; else return true ; } return false ; } static boolean checkArray ( float [ ] arr , int N ) { float sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; float mean = sum / N ; if ( ( N & 1 ) != 0 ) return binarySearch ( arr , N , mean ) ; else return twoPointers ( arr , N , mean ) ; } public static void main ( String [ ] args ) { float [ ] arr = { 1.0f , 3.0f , 6.0f , 9.0f , 12.0f , 32.0f } ; int N = arr . length ; if ( checkArray ( arr , N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, j, mid
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int UniqueGeometricTerms ( int N , int a1 , int r1 , int a2 , int r2 ) { HashSet < Integer > S = new HashSet < Integer > ( ) ; int p1 = a1 ; for ( int i = 0 ; i < N ; i ++ ) { S . add ( p1 ) ; p1 = ( p1 * r1 ) ; } int p2 = a2 ; for ( int i = 0 ; i < N ; i ++ ) { S . add ( p2 ) ; p2 = ( p2 * r2 ) ; } return S . size ( ) ; } public static void main ( String [ ] args ) { int N = 5 ; int a1 = 3 , r1 = 2 , a2 = 2 , r2 = 3 ; System . out . print ( UniqueGeometricTerms ( N , a1 , r1 , a2 , r2 ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int minOperations ( int arr [ ] , int N , int K ) { Vector < pair > vp = new Vector < pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { vp . add ( new pair ( arr [ i ] , i ) ) ; } Collections . sort ( vp , ( a , b ) -> a . first - b . first ) ; int minCnt = 0 ; while ( ! vp . isEmpty ( ) ) { int val , ind ; val = vp . get ( vp . size ( ) - 1 ) . first ; ind = vp . get ( vp . size ( ) - 1 ) . second ; minCnt ++ ; while ( ! vp . isEmpty ( ) && vp . get ( vp . size ( ) - 1 ) . first == val && ind - vp . get ( vp . size ( ) - 1 ) . second + 1 <= K ) vp . remove ( vp . size ( ) - 1 ) ; } return minCnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 18 , 11 , 18 , 11 , 18 } ; int K = 3 ; int N = arr . length ; System . out . print ( minOperations ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, minCnt
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static void nearestLeft ( int arr [ ] , int N , int [ ] steps ) { int L = - N ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { L = - ( N - i ) ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { L = i ; } steps [ i ] = i - L ; } } static void nearestRight ( int arr [ ] , int N , int [ ] steps ) { int R = 2 * N ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { R = N + i ; break ; } } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { R = i ; } steps [ i ] = Math . min ( steps [ i ] , R - i ) ; } } static int accumulate ( int [ ] arr , int start , int end ) { int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) sum += arr [ i ] ; return sum ; } static int findSum ( int arr [ ] , int N , int M , int K ) { int [ ] steps = new int [ N ] ; int sum = accumulate ( arr , 0 , N ) ; if ( sum == 0 ) { return 0 ; } nearestLeft ( arr , N , steps ) ; nearestRight ( arr , N , steps ) ; for ( int i = 0 ; i < N ; i ++ ) sum += 2 * K * Math . max ( 0 , M - steps [ i ] ) ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 0 , 1 , 0 , 0 } ; int N = arr . length ; int M = 2 ; int K = 1 ; System . out . print ( findSum ( arr , N , M , K ) ) ; } }

Index/key variables: N, i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int getProduct ( int n ) { int product = 1 ; while ( n != 0 ) { product = product * ( n % 10 ) ; n = n / 10 ; } return product ; } public static int countPairs ( int L , int R ) { int cntPair = 0 ; for ( int a = L ; a <= R ; a ++ ) { for ( int b = a + 1 ; b <= R ; b ++ ) { int x = getProduct ( a ) ; int y = getProduct ( b ) ; if ( x != 0 && y != 0 && ( a * y ) == ( b * x ) ) { cntPair ++ ; } } } return cntPair ; } public static void main ( String args [ ] ) { int L = 1 ; int R = 100 ; System . out . println ( countPairs ( L , R ) ) ; } }

Accumulator variables: a, b, cntPair
Iterator variables: a, b
Class/struct names: GFG