dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def printArr ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " " )
def compare ( num1 , num2 ) :
    A = str ( num1 )
    B = str ( num2 )
    return int ( A + B ) <= int ( B + A )
def sort ( arr ) :
    for i in range ( len ( arr ) ) :
        for j in range ( i + 1 , len ( arr ) ) :
            if compare ( arr [ i ] , arr [ j ] ) == False :
                arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
def printSmallest ( N , arr ) :
    sort ( arr )
    printArr ( arr , N )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 6 , 2 , 9 , 21 , 1 ]
    N = len ( arr )
    printSmallest ( N , arr )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def stableSelectionSort ( a , n ) :
    for i in range ( n ) :
        min_idx = i
        for j in range ( i + 1 , n ) :
            if a [ min_idx ] > a [ j ] :
                min_idx = j
        key = a [ min_idx ]
        while min_idx > i :
            a [ min_idx ] = a [ min_idx - 1 ]
            min_idx -= 1
        a [ i ] = key
def printArray ( a , n ) :
    for i in range ( n ) :
        print ( " % d " % a [ i ] , end = " ▁ " )
a = [ 4 , 5 , 3 , 2 , 4 , 1 ]
n = len ( a )
stableSelectionSort ( a , n )
printArray ( a , n )

Index/key variables: i, j, min_idx
Iterator variables: i, j
Python program:
def isPossible ( a , b , n , k ) :
    a . sort ( reverse = True )
    b . sort ( )
    for i in range ( n ) :
        if ( a [ i ] + b [ i ] < k ) :
            return False
    return True
a = [ 2 , 1 , 3 ]
b = [ 7 , 8 , 9 ]
k = 10
n = len ( a )
if ( isPossible ( a , b , n , k ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def setBitCount ( num ) :
    count = 0
    while ( num ) :
        if ( num & 1 ) :
            count += 1
        num = num >> 1
    return count
def sortBySetBitCount ( arr , n ) :
    count = [ ]
    for i in range ( n ) :
        count . append ( [ ( - 1 ) * setBitCount ( arr [ i ] ) , arr [ i ] ] )
    count . sort ( key = lambda x : x [ 0 ] )
    for i in range ( len ( count ) ) :
        print ( count [ i ] [ 1 ] , end = " ▁ " )
arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
n = len ( arr )
sortBySetBitCount ( arr , n )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def canReach ( s , L , R ) :
    dp = [ 0 for _ in range ( len ( s ) ) ]
    dp [ 0 ] = 1
    pre = 0
    for i in range ( 1 , len ( s ) ) :
        if ( i >= L ) :
            pre += dp [ i - L ]
        if ( i > R ) :
            pre -= dp [ i - R - 1 ]
        dp [ i ] = ( pre > 0 ) and ( s [ i ] == '0' )
    return dp [ len ( s ) - 1 ]
if __name__ == " _ _ main _ _ " :
    S = "01101110"
    L = 2
    R = 3
    if canReach ( S , L , R ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: pre
Iterator variables: i
Python program:
N = 10 ** 5 + 5
visited = [ 0 ] * N
def construct_tree ( weights , n ) :
    minimum = min ( weights )
    maximum = max ( weights )
    if ( minimum == maximum ) :
        print ( " No " )
        return
    else :
        print ( " Yes " )
    root = weights [ 0 ]
    visited [ 1 ] = 1
    for i in range ( n ) :
        if ( weights [ i ] != root and visited [ i + 1 ] == 0 ) :
            print ( 1 , i + 1 )
            visited [ i + 1 ] = 1
    notroot = 0
    for i in range ( n ) :
        if ( weights [ i ] != root ) :
            notroot = i + 1
            break
    for i in range ( n ) :
        if ( weights [ i ] == root and visited [ i + 1 ] == 0 ) :
            print ( notroot , i + 1 )
            visited [ i + 1 ] = 1
if __name__ == ' _ _ main _ _ ' :
    weights = [ 1 , 2 , 1 , 2 , 5 ]
    N = len ( weights )
    construct_tree ( weights , N )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def minCost ( s , k ) :
    n = len ( s )
    ans = 0
    for i in range ( k ) :
        a = [ 0 ] * 26
        for j in range ( i , n , k ) :
            a [ ord ( s [ j ] ) - ord ( ' a ' ) ] += 1
        min_cost = sys . maxsize - 1
        for ch in range ( 26 ) :
            cost = 0
            for tr in range ( 26 ) :
                cost += abs ( ch - tr ) * a [ tr ]
            min_cost = min ( min_cost , cost )
        ans += min_cost
    print ( ans )
S = " abcdefabc "
K = 3
minCost ( S , K )

Index/key variables: j, tr
Accumulator variables: ans, cost
Iterator variables: ch, i, j, tr
Python program:
N = 10000
adj = { }
used = [ 0 for i in range ( N ) ]
max_matching = 0
def AddEdge ( u , v ) :
    if u not in adj :
        adj [ u ] = [ ]
    if v not in adj :
        adj [ v ] = [ ]
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
def Matching_dfs ( u , p ) :
    global max_matching
    for i in range ( len ( adj [ u ] ) ) :
        if ( adj [ u ] [ i ] != p ) :
            Matching_dfs ( adj [ u ] [ i ] , u )
    if ( not used [ u ] and not used [ p ] and p != 0 ) :
        max_matching += 1
        used [ u ] = 1
        used [ p ] = 1
def maxMatching ( ) :
    Matching_dfs ( 1 , 0 )
    print ( max_matching )
n = 5
AddEdge ( 1 , 2 )
AddEdge ( 1 , 3 )
AddEdge ( 3 , 4 )
AddEdge ( 3 , 5 )
maxMatching ( )

Index/key variables: i, p, u, v
Iterator variables: i
Python program:
import sys
def getMinCost ( A , B , N ) :
    mini = sys . maxsize
    for i in range ( N ) :
        mini = min ( mini , min ( A [ i ] , B [ i ] ) )
    return mini * ( 2 * N - 1 )
N = 3
A = [ 1 , 4 , 2 ]
B = [ 10 , 6 , 12 ]
print ( getMinCost ( A , B , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def printVector ( arr ) :
    if ( len ( arr ) != 1 ) :
        for i in range ( len ( arr ) ) :
            print ( arr [ i ] , end = " ▁ " )
        print ( )
def findWays ( arr , i , n ) :
    if ( n == 0 ) :
        printVector ( arr )
    for j in range ( i , n + 1 ) :
        arr . append ( j )
        findWays ( arr , j , n - j )
        del arr [ - 1 ]
if __name__ == ' _ _ main _ _ ' :
    n = 4
    arr = [ ]
    findWays ( arr , 1 , n )

Index/key variables: i
Accumulator variables: arr
Iterator variables: i, j
Python program:
def DivideString ( s , n , k ) :
    c = 0
    no = 1
    c1 = 0
    c2 = 0
    fr = [ 0 ] * 26
    ans = [ ]
    for i in range ( n ) :
        fr [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 26 ) :
        if ( fr [ i ] == k ) :
            c += 1
        if ( fr [ i ] > k and fr [ i ] != 2 * k ) :
            c1 += 1
            ch = chr ( ord ( ' a ' ) + i )
        if ( fr [ i ] == 2 * k ) :
            c2 += 1
            ch1 = chr ( ord ( ' a ' ) + i )
    for i in range ( n ) :
        ans . append ( "1" )
    mp = { }
    if ( c % 2 == 0 or c1 > 0 or c2 > 0 ) :
        for i in range ( n ) :
            if ( fr [ ord ( s [ i ] ) - ord ( ' a ' ) ] == k ) :
                if ( s [ i ] in mp ) :
                    ans [ i ] = '2'
                else :
                    if ( no <= ( c // 2 ) ) :
                        ans [ i ] = '2'
                        no += 1
                        mp [ s [ i ] ] = 1
        if ( c % 2 == 1 and c1 > 0 ) :
            no = 1
            for i in range ( n ) :
                if ( s [ i ] == ch and no <= k ) :
                    ans [ i ] = '2'
                    no += 1
        if ( c % 2 == 1 and c1 == 0 ) :
            no = 1
            flag = 0
            for i in range ( n ) :
                if ( s [ i ] == ch1 and no <= k ) :
                    ans [ i ] = '2'
                    no += 1
                if ( fr [ s [ i ] - ' a ' ] == k and flag == 0 and ans [ i ] == '1' ) :
                    ans [ i ] = '2'
                    flag = 1
        print ( " " . join ( ans ) )
    else :
        print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
    S = " abbbccc "
    N = len ( S )
    K = 1
    DivideString ( S , N , K )

Index/key variables: i
Accumulator variables: ans, c, c1, c2, no
Iterator variables: i
Python program:
def check ( S , prices , type1 , n ) :
    for j in range ( 0 , n ) :
        for k in range ( j + 1 , n ) :
            if ( ( type1 [ j ] == 0 and type1 [ k ] == 1 ) or ( type1 [ j ] == 1 and type1 [ k ] == 0 ) ) :
                if ( prices [ j ] + prices [ k ] <= S ) :
                    return " Yes " ;
    return " No " ;
prices = [ 3 , 8 , 6 , 5 ] ;
type1 = [ 0 , 1 , 1 , 0 ] ;
S = 10 ;
n = 4 ;
print ( check ( S , prices , type1 , n ) ) ;

Index/key variables: j, k
Iterator variables: j, k
Python program:
def getLargestSum ( N ) :
    for i in range ( 1 , int ( N ** ( 1 / 2 ) ) + 1 ) :
        for j in range ( i + 1 , int ( N ** ( 1 / 2 ) ) + 1 ) :
            k = N // j ;
            a = k * i ;
            b = k * j ;
            if ( a <= N and b <= N and a * b % ( a + b ) == 0 ) :
                max_sum = max ( max_sum , a + b ) ;
    return max_sum ;
if __name__ == " _ _ main _ _ " :
    N = 25 ;
    max_sum = getLargestSum ( N ) ;
    print ( max_sum ) ;

Iterator variables: i, j
Python program:
def encryptString ( string , n ) :
    i , cnt = 0 , 0
    encryptedStr = " "
    while i < n :
        cnt = i + 1
        while cnt > 0 :
            encryptedStr += string [ i ]
            cnt -= 1
        i += 1
    return encryptedStr
if __name__ == " _ _ main _ _ " :
    string = " geeks "
    n = len ( string )
    print ( encryptString ( string , n ) )

Index/key variables: i
Accumulator variables: cnt, encryptedStr
Python program:
def minDiff ( n , x , A ) :
    mn = A [ 0 ]
    mx = A [ 0 ]
    for i in range ( 0 , n ) :
        mn = min ( mn , A [ i ] )
        mx = max ( mx , A [ i ] )
    return max ( 0 , mx - mn - 2 * x )
n = 3
x = 3
A = [ 1 , 3 , 6 ]
print ( minDiff ( n , x , A ) )

Index/key variables: i
Iterator variables: i
Python program:
def swapCount ( s ) :
    chars = s
    countLeft = 0
    countRight = 0
    swap = 0
    imbalance = 0 ;
    for i in range ( len ( chars ) ) :
        if chars [ i ] == ' [ ' :
            countLeft += 1
            if imbalance > 0 :
                swap += imbalance
                imbalance -= 1
        elif chars [ i ] == ' ] ' :
            countRight += 1
            imbalance = ( countRight - countLeft )
    return swap
s = " [ ] ] [ ] [ " ;
print ( swapCount ( s ) )
s = " [ [ ] [ ] ] " ;
print ( swapCount ( s ) )

Index/key variables: i
Accumulator variables: countLeft, countRight, imbalance, swap
Iterator variables: i
Python program:
def longestSubSequence ( A , N ) :
    dp = [ 0 ] * N
    for i in range ( N ) :
        dp [ i ] = 1
        for j in range ( i ) :
            if ( A [ j ] [ 0 ] < A [ i ] [ 0 ] and A [ j ] [ 1 ] > A [ i ] [ 1 ] ) :
                dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )
    print ( dp [ N - 1 ] )
if __name__ == ' _ _ main _ _ ' :
    A = [ [ 1 , 2 ] , [ 2 , 2 ] , [ 3 , 1 ] ]
    N = len ( A )
    longestSubSequence ( A , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findWays ( N , dp ) :
    if ( N == 0 ) :
        return 1
    if ( dp [ N ] != - 1 ) :
        return dp [ N ]
    cnt = 0
    for i in range ( 1 , 7 ) :
        if ( N - i >= 0 ) :
            cnt = ( cnt + findWays ( N - i , dp ) )
    dp [ N ] = cnt
    return dp [ N ]
if __name__ == " _ _ main _ _ " :
    N = 4
    dp = [ - 1 ] * ( N + 1 )
    print ( findWays ( N , dp ) )

Index/key variables: N
Iterator variables: i
Python program:
def findWays ( N ) :
    dp = [ 0 ] * ( N + 1 ) ;
    dp [ 0 ] = 1 ;
    for i in range ( 1 , N + 1 ) :
        dp [ i ] = 0 ;
        for j in range ( 1 , 7 ) :
            if ( i - j >= 0 ) :
                dp [ i ] = dp [ i ] + dp [ i - j ] ;
    print ( dp [ N ] ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 4 ;
    findWays ( N ) ;

Index/key variables: N, i
Iterator variables: i, j
Python program:
INF = 1e9 + 9
class TrieNode ( ) :
    def __init__ ( self ) :
        self . child = [ None ] * 26
def insert ( idx , s , root ) :
    temp = root
    for i in range ( idx , len ( s ) ) :
        if temp . child [ ord ( s [ i ] ) - ord ( ' a ' ) ] == None :
            temp . child [ ord ( s [ i ] ) - ord ( ' a ' ) ] = TrieNode ( )
        temp = temp . child [ ord ( s [ i ] ) - ord ( ' a ' ) ]
def minCuts ( S1 , S2 ) :
    n1 = len ( S1 )
    n2 = len ( S2 )
    root = TrieNode ( )
    for i in range ( n2 ) :
        insert ( i , S2 , root )
    dp = [ INF ] * ( n1 + 1 )
    dp [ 0 ] = 0
    for i in range ( n1 ) :
        temp = root
        for j in range ( i + 1 , n1 + 1 ) :
            if temp . child [ ord ( S1 [ j - 1 ] ) - ord ( ' a ' ) ] == None :
                break
            dp [ j ] = min ( dp [ j ] , dp [ i ] + 1 )
            temp = temp . child [ ord ( S1 [ j - 1 ] ) - ord ( ' a ' ) ]
    if dp [ n1 ] >= INF :
        return - 1
    else :
        return dp [ n1 ]
S1 = " abcdab "
S2 = " dabc "
print ( minCuts ( S1 , S2 ) )

Index/key variables: i, j, n1
Iterator variables: i, j
Class/struct names: TrieNode
Python program:
def largestSquare ( matrix , R , C , q_i , q_j , K , Q ) :
    countDP = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]
    countDP [ 0 ] [ 0 ] = matrix [ 0 ] [ 0 ]
    for i in range ( 1 , R ) :
        countDP [ i ] [ 0 ] = ( countDP [ i - 1 ] [ 0 ] + matrix [ i ] [ 0 ] )
    for j in range ( 1 , C ) :
        countDP [ 0 ] [ j ] = ( countDP [ 0 ] [ j - 1 ] + matrix [ 0 ] [ j ] )
    for i in range ( 1 , R ) :
        for j in range ( 1 , C ) :
            countDP [ i ] [ j ] = ( matrix [ i ] [ j ] + countDP [ i - 1 ] [ j ] + countDP [ i ] [ j - 1 ] - countDP [ i - 1 ] [ j - 1 ] )
    for q in range ( 0 , Q ) :
        i = q_i [ q ]
        j = q_j [ q ]
        min_dist = min ( i , j , R - i - 1 , C - j - 1 )
        ans = - 1
        l = 0
        u = min_dist
        while ( l <= u ) :
            mid = int ( ( l + u ) / 2 )
            x1 = i - mid
            x2 = i + mid
            y1 = j - mid
            y2 = j + mid
            count = countDP [ x2 ] [ y2 ]
            if ( x1 > 0 ) :
                count -= countDP [ x1 - 1 ] [ y2 ]
            if ( y1 > 0 ) :
                count -= countDP [ x2 ] [ y1 - 1 ]
            if ( x1 > 0 and y1 > 0 ) :
                count += countDP [ x1 - 1 ] [ y1 - 1 ]
            if ( count <= K ) :
                ans = 2 * mid + 1
                l = mid + 1
            else :
                u = mid - 1
        print ( ans )
matrix = [ [ 1 , 0 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 1 , 0 ] ]
K = 9
Q = 1
q_i = [ 1 ]
q_j = [ 2 ]
largestSquare ( matrix , 4 , 5 , q_i , q_j , K , Q )

Index/key variables: i, j, q, x2, y2
Accumulator variables: count
Iterator variables: i, j, q
Java program:
import java . util . * ; class GFG { static int minSum ( int A [ ] , int N ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; if ( mp . containsKey ( A [ i ] ) ) { mp . put ( A [ i ] , mp . get ( A [ i ] ) + 1 ) ; } else { mp . put ( A [ i ] , 1 ) ; } } int minSum = Integer . MAX_VALUE ; for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { minSum = Math . min ( minSum , sum - ( it . getKey ( ) * it . getValue ( ) ) ) ; } return minSum ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 6 , 6 } ; int N = arr . length ; System . out . print ( minSum ( arr , N ) + "NEW_LINE"); } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maxAdjacent ( int [ ] arr , int N ) { ArrayList < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { int prev = arr [ 0 ] ; int maxi = Integer . MIN_VALUE ; for ( int j = 1 ; j < N ; j ++ ) { if ( i == j ) continue ; maxi = Math . max ( maxi , Math . abs ( arr [ j ] - prev ) ) ; prev = arr [ j ] ; } res . add ( maxi ) ; } for ( int x : res ) { System . out . print ( x + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 7 , 8 } ; int N = arr . length ; maxAdjacent ( arr , N ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findSize ( int N ) { if ( N == 0 ) return 1 ; if ( N == 1 ) return 1 ; int Size = 2 * findSize ( N / 2 ) + 1 ; return Size ; } static int CountOnes ( int N , int L , int R ) { if ( L > R ) { return 0 ; } if ( N <= 1 ) { return N ; } int ret = 0 ; int M = N / 2 ; int Siz_M = findSize ( M ) ; if ( L <= Siz_M ) { ret += CountOnes ( N / 2 , L , Math . min ( Siz_M , R ) ) ; } if ( L <= Siz_M + 1 && Siz_M + 1 <= R ) { ret += N % 2 ; } if ( Siz_M + 1 < R ) { ret += CountOnes ( N / 2 , Math . max ( 1 , L - Siz_M - 1 ) , R - Siz_M - 1 ) ; } return ret ; } public static void main ( String [ ] args ) { int N = 7 , L = 2 , R = 5 ; System . out . println ( CountOnes ( N , L , R ) ) ; } }

Accumulator variables: ret
Class/struct names: GFG
Java program:
class GFG { static boolean prime ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void minDivisior ( int n ) { if ( prime ( n ) ) { System . out . print ( 1 + " ▁ " + ( n - 1 ) ) ; } else { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { System . out . print ( n / i + " ▁ " + ( n / i * ( i - 1 ) ) ) ; break ; } } } } public static void main ( String [ ] args ) { int N = 4 ; minDivisior ( N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int Landau = Integer . MIN_VALUE ; static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a * b ) / gcd ( a , b ) ; } static void findLCM ( Vector < Integer > arr ) { int nth_lcm = arr . get ( 0 ) ; for ( int i = 1 ; i < arr . size ( ) ; i ++ ) nth_lcm = lcm ( nth_lcm , arr . get ( i ) ) ; Landau = Math . max ( Landau , nth_lcm ) ; } static void findWays ( Vector < Integer > arr , int i , int n ) { if ( n == 0 ) findLCM ( arr ) ; for ( int j = i ; j <= n ; j ++ ) { arr . add ( j ) ; findWays ( arr , j , n - j ) ; arr . remove ( arr . size ( ) - 1 ) ; } } static void Landau_function ( int n ) { Vector < Integer > arr = new Vector < > ( ) ; findWays ( arr , 1 , n ) ; System . out . print ( Landau ) ; } public static void main ( String [ ] args ) { int N = 4 ; Landau_function ( N ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static boolean isPrime ( int n ) { if ( n == 1 ) return true ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static void checkExpression ( int n ) { if ( isPrime ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int N = 3 ; checkExpression ( N ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean checkArray ( int n , int k , int arr [ ] ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) cnt += 1 ; } if ( cnt >= k && cnt % 2 == k % 2 ) return true ; else return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 7 , 5 , 3 , 1 } ; int n = arr . length ; int k = 4 ; if ( checkArray ( n , k , arr ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static long func ( int arr [ ] , int n ) { double ans = 0 ; int maxx = 0 ; double freq [ ] = new double [ 100005 ] ; int temp ; for ( int i = 0 ; i < n ; i ++ ) { temp = arr [ i ] ; freq [ temp ] ++ ; maxx = Math . max ( maxx , temp ) ; } for ( int i = 1 ; i <= maxx ; i ++ ) { freq [ i ] += freq [ i - 1 ] ; } for ( int i = 1 ; i <= maxx ; i ++ ) { if ( freq [ i ] != 0 ) { double j ; double cur = Math . ceil ( 0.5 * i ) - 1.0 ; for ( j = 1.5 ; ; j ++ ) { int val = Math . min ( maxx , ( int ) ( Math . ceil ( i * j ) - 1.0 ) ) ; int times = ( int ) ( freq [ i ] - freq [ i - 1 ] ) , con = ( int ) ( j - 0.5 ) ; ans += times * con * ( freq [ ( int ) val ] - freq [ ( int ) cur ] ) ; cur = val ; if ( val == maxx ) break ; } } } return ( long ) ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . print ( func ( arr , n ) + "NEW_LINE"); } }

Index/key variables: i, temp
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void insert_element ( int a [ ] , int n ) { int Xor = 0 ; int Sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { Xor ^= a [ i ] ; Sum += a [ i ] ; } if ( Sum == 2 * Xor ) { System . out . println ( "0" ) ; return ; } if ( Xor == 0 ) { System . out . println ( "1" ) ; System . out . println ( Sum ) ; return ; } int num1 = Sum + Xor ; int num2 = Xor ; System . out . print ( "2" ) ; System . out . println ( num1 + " ▁ " + num2 ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 } ; int n = a . length ; insert_element ( a , n ) ; } }

Index/key variables: i
Accumulator variables: Sum, Xor, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void checkSolution ( int a , int b , int c ) { if ( a == c ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int a = 2 , b = 0 , c = 2 ; checkSolution ( a , b , c ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static void checkSunnyNumber ( int N ) { if ( isPerfectSquare ( N + 1 ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int N = 8 ; checkSunnyNumber ( N ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int countValues ( int n ) { int answer = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { int k = n ; while ( k >= i ) { if ( k % i == 0 ) k /= i ; else k -= i ; } if ( k == 1 ) answer ++ ; } return answer ; } public static void main ( String args [ ] ) { int N = 6 ; System . out . print ( countValues ( N ) ) ; } }

Accumulator variables: answer, i, k
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void printKNumbers ( int N , int K ) { for ( int i = 0 ; i < K - 1 ; i ++ ) System . out . print ( 1 + " ▁ " ) ; System . out . print ( N - K + 1 ) ; } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; printKNumbers ( N , K ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int NthSmallest ( int K ) { Queue < Integer > Q = new LinkedList < > ( ) ; int x = 0 ; for ( int i = 1 ; i < 10 ; i ++ ) Q . add ( i ) ; for ( int i = 1 ; i <= K ; i ++ ) { x = Q . peek ( ) ; Q . remove ( ) ; if ( x % 10 != 0 ) { Q . add ( x * 10 + x % 10 - 1 ) ; } Q . add ( x * 10 + x % 10 ) ; if ( x % 10 != 9 ) { Q . add ( x * 10 + x % 10 + 1 ) ; } } return x ; } public static void main ( String [ ] args ) { int N = 16 ; System . out . print ( NthSmallest ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int nearest ( int n ) { int prevSquare = ( int ) Math . sqrt ( n ) ; int nextSquare = prevSquare + 1 ; prevSquare = prevSquare * prevSquare ; nextSquare = nextSquare * nextSquare ; int ans = ( n - prevSquare ) < ( nextSquare - n ) ? ( prevSquare - n ) : ( nextSquare - n ) ; return ans ; } public static void main ( String [ ] args ) { int n = 14 ; System . out . println ( nearest ( n ) ) ; n = 16 ; System . out . println ( nearest ( n ) ) ; n = 18 ; System . out . println ( nearest ( n ) ) ; } }

Class/struct names: GFG