dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int nthFibo ( int n ) { double a = ( Math . pow ( 5 , 0.5 ) + 1 ) / 2 ; double b = ( - 1 * ( Math . pow ( 5 , 0.5 ) ) + 1 ) / 2 ; double r = Math . pow ( 5 , 0.5 ) ; double ans = ( Math . pow ( a , n ) - Math . pow ( b , n ) ) / r ; return ( int ) ans ; } static int nearFibo ( int X ) { double a = ( Math . pow ( 5 , 0.5 ) + 1 ) / 2 ; int n = ( int ) ( Math . log ( ( Math . pow ( 5 , 0.5 ) ) * X ) / Math . log ( a ) ) ; int nth = nthFibo ( n ) ; int nplus = nthFibo ( n + 1 ) ; if ( Math . abs ( X - nth ) < Math . abs ( X - nplus ) ) return nth ; else return nplus ; } static int getCost ( int arr [ ] , int n ) { int cost = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int fibo = nearFibo ( arr [ i ] ) ; cost += Math . abs ( arr [ i ] - fibo ) ; } return cost ; } public static void main ( String [ ] args ) { int arr [ ] = { 56 , 34 , 23 , 98 , 7 } ; int n = arr . length ; System . out . print ( getCost ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int getMaxPairSum ( int [ ] arr , int N , int K ) { int [ ] preMax = new int [ N ] ; preMax [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { preMax [ i ] = Math . max ( preMax [ i - 1 ] , arr [ i ] ) ; } int res = Integer . MIN_VALUE ; for ( int i = K ; i < N ; i ++ ) { res = Math . max ( res , arr [ i ] + preMax [ i - K ] ) ; } return res ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 8 , 6 , 3 } ; int K = 3 ; int N = arr . length ; System . out . print ( getMaxPairSum ( arr , N , K ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void sumOfInfiniteAGP ( double a , double d , double r ) { double ans = a / ( 1 - r ) + ( d * r ) / ( 1 - r * r ) ; System . out . print ( ans ) ; } public static void main ( String [ ] args ) { double a = 0 , d = 1 , r = 0.5 ; sumOfInfiniteAGP ( a , d , r ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int countPairs ( int arr [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] % arr [ j ] == 0 arr [ j ] % arr [ i ] == 0 ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 2 } ; int N = arr . length ; System . out . print ( countPairs ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int CountPairs ( int arr [ ] , int N ) { int res = 0 ; Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Integer c = mp . get ( arr [ i ] ) ; mp . put ( arr [ i ] , ( c == null ) ? 1 : c + 1 ) ; } Iterator < Map . Entry < Integer , Integer > > itr = mp . entrySet ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { Map . Entry < Integer , Integer > entry = itr . next ( ) ; int x = ( int ) entry . getKey ( ) ; int y = ( int ) entry . getValue ( ) ; if ( x == 1 ) { res += N - 1 ; continue ; } res += ( y * ( y - 1 ) ) / 2 ; for ( int j = 2 ; j <= Math . sqrt ( x ) ; j ++ ) { if ( x % j == 0 ) { res += mp . get ( j ) ; if ( j != x / j ) res += mp . get ( ( int ) x / j ) ; } } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 2 } ; int N = arr . length ; System . out . println ( CountPairs ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int countbits ( int n ) { int count = 0 ; while ( n != 0 ) { if ( ( n & 1 ) != 0 ) count ++ ; n = n / 2 ; } return count ; } static int BitProduct ( int arr [ ] , int N ) { int product = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int bits = countbits ( arr [ i ] ) ; product *= bits ; } return product ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 1 , 5 } ; int N = arr . length ; System . out . print ( BitProduct ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, product
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } static int getSumUtil ( int st [ ] , int ss , int se , int qs , int qe , int si ) { if ( qs <= ss && qe >= se ) return st [ si ] ; if ( se < qs ss > qe ) return 0 ; int mid = getMid ( ss , se ) ; return getSumUtil ( st , ss , mid , qs , qe , 2 * si + 1 ) + getSumUtil ( st , mid + 1 , se , qs , qe , 2 * si + 2 ) ; } static int getSum ( int st [ ] , int n , int qs , int qe ) { if ( qs < 0 qe > n - 1 qs > qe ) { System . out . println ( " Invalid ▁ Input " ) ; return - 1 ; } return getSumUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; } static int constructSTUtil ( int arr [ ] , int ss , int se , int st [ ] , int si ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return arr [ ss ] ; } int mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ; return st [ si ] ; } static int [ ] constructST ( int arr [ ] , int n ) { int x = ( int ) ( Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) ) ; int max_size = 2 * ( int ) Math . pow ( 2 , x ) - 1 ; int st [ ] = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } static void OddDivisorsSum ( int n , int q , int arr [ ] , int Query [ ] [ ] ) { for ( int i = 0 ; i < n ; i ++ ) { int sq = ( int ) Math . sqrt ( arr [ i ] ) ; if ( sq * sq != arr [ i ] ) arr [ i ] = 0 ; } int st [ ] = constructST ( arr , n ) ; for ( int i = 0 ; i < q ; i ++ ) { int l = Query [ i ] [ 0 ] ; int r = Query [ i ] [ 1 ] ; System . out . print ( getSum ( st , n , l , r ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 5 , 6 , 9 } ; int N = arr . length ; int Q = 3 ; int Query [ ] [ ] = { { 0 , 2 } , { 1 , 3 } , { 1 , 4 } } ; OddDivisorsSum ( N , Q , arr , Query ) ; } }

Index/key variables: i, max_size, si, ss
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void OddDivisorsSum ( int n , int q , int [ ] a , int [ ] [ ] Query ) { int [ ] DP = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = ( int ) ( Math . sqrt ( a [ i ] ) ) ; if ( x * x == a [ i ] ) DP [ i ] = a [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { DP [ i ] = DP [ i - 1 ] + DP [ i ] ; } for ( int i = 0 ; i < q ; i ++ ) { int l = Query [ i ] [ 0 ] ; int r = Query [ i ] [ 1 ] ; if ( l == 0 ) { System . out . print ( DP [ r ] + " ▁ " ) ; } else { System . out . print ( DP [ r ] - DP [ l - 1 ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 5 , 6 , 9 } ; int N = arr . length ; int Q = 3 ; int [ ] [ ] Query = { { 0 , 2 } , { 1 , 3 } , { 1 , 4 } } ; OddDivisorsSum ( N , Q , arr , Query ) ; } }

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findSubset ( int [ ] arr ) { int N = arr . length ; Map < Integer , Integer > map = new HashMap < > ( ) ; int totSum = 0 ; int s = 0 ; int flag = 0 ; ArrayList < Integer > ans = new ArrayList < > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { totSum += arr [ i ] ; map . put ( arr [ i ] , map . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } Arrays . sort ( arr ) ; int i = N - 1 ; while ( i >= 0 ) { int frq = map . get ( arr [ i ] ) ; if ( ( frq + ans . size ( ) ) < ( N - ( frq + ans . size ( ) ) ) ) { for ( int k = 0 ; k < frq ; k ++ ) { ans . add ( arr [ i ] ) ; totSum -= arr [ i ] ; s += arr [ i ] ; i -- ; } } else { i -= frq ; } if ( s > totSum ) { flag = 1 ; break ; } } if ( flag == 1 ) { for ( i = ans . size ( ) - 1 ; i >= 0 ; i -- ) { System . out . print ( ans . get ( i ) + " ▁ " ) ; } } else { System . out . print ( - 1 ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 3 , 2 , 4 , 1 , 2 } ; findSubset ( arr ) ; } }

Index/key variables: i
Accumulator variables: i, k, s, totSum
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minStepK ( int arr [ ] , int N , int K ) { int E = 0 ; int S = 0 ; for ( int i = 0 ; i < N ; i ++ ) { S += arr [ i ] ; if ( arr [ i ] % 2 == 0 ) E += 1 ; } if ( S >= K ) return 0 ; else if ( S + E < K ) return - 1 ; else return K - S ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 1 , 0 , 1 } ; int N = arr . length ; int K = 4 ; System . out . println ( minStepK ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: E, S, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int Rotate ( int n , int f ) { int temp = n ; int maxi = n ; int mini = n ; for ( int idx = 0 ; idx < 7 ; idx ++ ) { if ( temp % 2 == 1 ) { temp >>= 1 ; temp += Math . pow ( 2 , 7 ) ; } else temp >>= 1 ; mini = Math . min ( mini , temp ) ; maxi = Math . max ( maxi , temp ) ; } if ( f == 1 ) return ( maxi ) ; else return ( mini ) ; } static int calcMinDiff ( int arr [ ] , int n ) { int caseOne = 0 ; int sumOfodd = 0 ; int sumOfeven = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) sumOfodd += Rotate ( arr [ i ] , 0 ) ; else sumOfeven += Rotate ( arr [ i ] , 1 ) ; } caseOne = Math . abs ( sumOfodd - sumOfeven ) ; int caseTwo = 0 ; sumOfodd = 0 ; sumOfeven = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) sumOfodd += Rotate ( arr [ i ] , 1 ) ; else sumOfeven += Rotate ( arr [ i ] , 0 ) ; } caseTwo = Math . abs ( sumOfodd - sumOfeven ) ; return Math . max ( caseOne , caseTwo ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 123 , 86 , 234 , 189 } ; int n = arr . length ; System . out . print ( ( calcMinDiff ( arr , n ) ) ) ; } }

Index/key variables: i
Accumulator variables: i, idx, sumOfeven, sumOfodd, temp
Iterator variables: i, idx
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void minimumDiff ( int [ ] arr , int N ) { int res = arr [ 0 ] , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; int min_diff = sum ; for ( int i = 0 ; i < N ; i ++ ) { if ( Math . abs ( sum - ( arr [ i ] * N ) ) < min_diff ) { min_diff = Math . abs ( sum - ( arr [ i ] * N ) ) ; res = arr [ i ] ; } } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . length ; minimumDiff ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int sum ( int arr [ ] , int N , int K ) { int sum = 0 ; ArrayList < Integer > v = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { v . add ( arr [ i ] ) ; } boolean flag = false ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( ! flag && v . get ( i ) % K == 0 ) v . add ( v . get ( i ) / K ) ; else { flag = true ; } sum = sum + v . get ( i % N ) ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 8 , 2 } ; int K = 2 ; int N = arr . length ; System . out . println ( sum ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
public class GFG { public static int primeDivisors ( int [ ] arr , int N ) { int K = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { K = Math . max ( K , arr [ i ] ) ; } int [ ] prime = new int [ K + 1 ] ; prime [ 0 ] = 1 ; prime [ 1 ] = 1 ; for ( int i = 2 ; i < K + 1 ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = 2 * i ; j < K + 1 ; j += i ) { prime [ j ] = 1 ; } } } int [ ] factor = new int [ K + 1 ] ; factor [ 0 ] = 0 ; factor [ 1 ] = 1 ; for ( int i = 2 ; i < K + 1 ; i ++ ) { factor [ i ] += 1 ; for ( int j = i ; j < K + 1 ; j += i ) { factor [ j ] += 1 ; } } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( prime [ factor [ arr [ i ] ] ] == 0 ) count ++ ; } return count ; } public static void main ( String args [ ] ) { int [ ] arr = { 10 , 13 , 17 , 25 } ; int N = arr . length ; System . out . println ( primeDivisors ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void SieveOfEratosthenes ( int n , boolean prime [ ] ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) { prime [ i ] = false ; } } } } static void countPrime ( int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; for ( int i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } SieveOfEratosthenes ( n , prime ) ; int dp [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = 0 ; } dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] += dp [ i - 1 ] ; if ( prime [ i ] == true && prime [ i - 2 ] == true ) { dp [ i ] ++ ; } } System . out . print ( dp [ n ] ) ; } public static void main ( String [ ] args ) { int N = 6 ; countPrime ( N ) ; } }

Index/key variables: i, n, p
Accumulator variables: i, p
Iterator variables: i, p
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int findMinSum ( int mat [ ] [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int res = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( i != j ) { res |= mat [ i ] [ j ] ; } } sum += res ; } return sum ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { - 1 , 2 , 3 } , { 9 , - 1 , 7 } , { 4 , 5 , - 1 } } ; int N = mat . length ; System . out . println ( findMinSum ( mat , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, res, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . Map . Entry ; class GFG { static int findGCD ( int a , int b ) { if ( b == 0 ) return a ; return findGCD ( b , a % b ) ; } static int findLCM ( int a , int b ) { return ( a * b ) / findGCD ( a , b ) ; } static void uniqueElementsLCM ( int arr [ ] , int N ) { HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { freq . put ( arr [ i ] , freq . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } int lcm = 1 ; for ( Entry < Integer , Integer > i : freq . entrySet ( ) ) { if ( i . getValue ( ) == 1 ) { lcm = findLCM ( lcm , i . getKey ( ) ) ; } } if ( lcm == 1 ) lcm = - 1 ; System . out . print ( lcm ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 1 , 3 , 3 , 4 } ; int N = arr . length ; uniqueElementsLCM ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxAdjacentDifference ( ArrayList < Integer > A ) { int diff = 0 ; for ( int i = 1 ; i < ( int ) A . size ( ) ; i ++ ) { diff = Math . max ( diff , A . get ( i ) - A . get ( i - 1 ) ) ; } return diff ; } static int MinimumValue ( int arr [ ] , int N ) { int MinValue = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { ArrayList < Integer > new_arr = new ArrayList < > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; new_arr . add ( arr [ j ] ) ; } MinValue = Math . min ( MinValue , maxAdjacentDifference ( new_arr ) ) ; } return MinValue ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 7 , 8 } ; int N = arr . length ; System . out . print ( MinimumValue ( arr , N ) ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int mod = 1000000007 ; static int power ( int x , int y ) { int res = 1 ; x = x % mod ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } static int antisymmetricRelation ( int N ) { return ( power ( 2 , N ) * power ( 3 , ( N * N - N ) / 2 ) ) % mod ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . print ( antisymmetricRelation ( N ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { final static int mod = 1000000007 ; public static int power ( int x , int y ) { int res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } public static int asymmetricRelation ( int N ) { return power ( 3 , ( N * N - N ) / 2 ) ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . print ( asymmetricRelation ( N ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void crossProduct ( int vect_A [ ] , int vect_B [ ] , int cross_P [ ] ) { cross_P [ 0 ] = vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ; cross_P [ 1 ] = vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ; cross_P [ 2 ] = vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ; } static void checkCollinearity ( int x1 , int y1 , int z1 , int x2 , int y2 , int z2 ) { int A [ ] = { x1 , y1 , z1 } ; int B [ ] = { x2 , y2 , z2 } ; int cross_P [ ] = new int [ 3 ] ; crossProduct ( A , B , cross_P ) ; if ( cross_P [ 0 ] == 0 && cross_P [ 1 ] == 0 && cross_P [ 2 ] == 0 ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int x1 = 4 , y1 = 8 , z1 = 12 ; int x2 = 8 , y2 = 16 , z2 = 24 ; checkCollinearity ( x1 , y1 , z1 , x2 , y2 , z2 ) ; } }

Class/struct names: GFG
Java program:
class GFG { static double kineticEnergy ( double M , double V ) { double KineticEnergy ; KineticEnergy = 0.5 * M * V * V ; return KineticEnergy ; } static double potentialEnergy ( double M , double H ) { double PotentialEnergy ; PotentialEnergy = M * 9.8 * H ; return PotentialEnergy ; } public static void main ( String [ ] args ) { double M = 5.5 , H = 23.5 , V = 10.5 ; System . out . println ( " Kinetic ▁ Energy ▁ = ▁ " + kineticEnergy ( M , V ) ) ; System . out . println ( " Potential ▁ Energy ▁ = ▁ " + potentialEnergy ( M , H ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void countPairs ( int arr [ ] , int N ) { int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; } if ( N - even >= 1 ) { System . out . println ( even ) ; return ; } System . out . println ( 0 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 4 , 7 , 2 } ; int N = arr . length ; countPairs ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: even, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void distribute ( int N , int K , int M , int arr [ ] ) { int distribution [ ] = new int [ N ] ; int ptr = K - 1 ; int rem = M ; while ( rem > 0 ) { if ( rem >= arr [ ptr ] ) { distribution [ ptr ] += arr [ ptr ] ; rem -= arr [ ptr ] ; } else { distribution [ ptr ] += rem ; rem = 0 ; } ptr = ( ptr + 1 ) % N ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( distribution [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 2 , 1 , 4 } ; int M = 11 , S = 2 ; int N = arr . length ; distribute ( N , S , M , arr ) ; } }

Index/key variables: N, i, ptr
Accumulator variables: i, rem
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void sumOfSquaredDifferences ( int arr [ ] , int N ) { int ans = 0 ; int sumA = 0 , sumB = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sumA += ( arr [ i ] * arr [ i ] ) ; sumB += arr [ i ] ; } sumA = N * sumA ; sumB = ( sumB * sumB ) ; ans = sumA - sumB ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 8 , 4 } ; int N = arr . length ; sumOfSquaredDifferences ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, sumA, sumB
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void waysToRemove ( int n , int m ) { int ans = 0 ; if ( m == 1 ) { System . out . println ( n ) ; return ; } for ( int d = 0 ; d >= 0 ; d ++ ) { int len = m + ( m - 1 ) * d ; if ( len > n ) break ; ans += ( n - len ) + 1 ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int N = 5 , M = 3 ; waysToRemove ( N , M ) ; } }

Accumulator variables: ans, d
Iterator variables: d
Class/struct names: GFG
Java program:
import java . util . LinkedList ; import java . util . Queue ; class GFG { static void countStairs ( int n , int x , int a , int b ) { int [ ] vis = new int [ n + 1 ] ; int [ ] moves = { + a , - a , + b , - b } ; Queue < Integer > q = new LinkedList < Integer > ( ) ; q . add ( x ) ; vis [ x ] = 1 ; while ( ! q . isEmpty ( ) ) { int currentStair = q . peek ( ) ; q . remove ( ) ; for ( int j = 0 ; j < 4 ; j ++ ) { int newStair = currentStair + moves [ j ] ; if ( newStair > 0 && newStair <= n && vis [ newStair ] == 0 ) { q . add ( newStair ) ; vis [ newStair ] = 1 ; } } } int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( vis [ i ] == 1 ) cnt ++ ; System . out . print ( cnt ) ; } public static void main ( String args [ ] ) { int N = 10 , S = 2 , A = 5 , B = 7 ; countStairs ( N , S , A , B ) ; } }

Index/key variables: i, j, newStair, x
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void smallerNumbers ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { count ++ ; } } System . out . print ( count + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 1 , 1 , 2 } ; int N = arr . length ; smallerNumbers ( arr , N ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, 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 void minimumOperations ( int X , int Y ) { int GCD = gcd ( X , Y ) ; X = X / GCD ; Y = Y / GCD ; int count = 0 ; while ( X != Y ) { if ( Y > X ) { int t = X ; X = Y ; Y = t ; } if ( X % 2 == 0 ) { X = X / 2 ; } else if ( X % 3 == 0 ) { X = X / 3 ; } else if ( X % 5 == 0 ) { X = X / 5 ; } else { System . out . print ( " - 1" ) ; return ; } count += 1 ; } System . out . println ( count ) ; } static public void main ( String args [ ] ) { int X = 15 , Y = 20 ; minimumOperations ( X , Y ) ; } }

Accumulator variables: count
Class/struct names: GFG
Java program:
class GFG { static int minOperations ( int a [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += a [ i ] ; } ans -= n ; for ( int x = 1 ; ; x ++ ) { int curPow = 1 , curCost = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curCost += Math . abs ( a [ i ] - curPow ) ; curPow *= x ; } if ( curPow / x > ans + a [ n - 1 ] ) break ; ans = Math . min ( ans , curCost ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 7 } ; int N = arr . length ; System . out . print ( minOperations ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, curCost, curPow, i, x
Iterator variables: i, x
Class/struct names: GFG