dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
def findMaxGCD ( arr , N ) :
    high = 0
    for i in range ( 0 , N ) :
        high = max ( high , arr [ i ] )
    count = [ 0 ] * ( high + 1 )
    for i in range ( 0 , N ) :
        count [ arr [ i ] ] += 1
    counter = 0
    for i in range ( high , 0 , - 1 ) :
        j = i
        while ( j <= high ) :
            if ( count [ j ] > 0 ) :
                counter += count [ j ]
            j += i
            if ( counter == 2 ) :
                return i
        counter = 0
def maxlen ( i , j ) :
    a = 0
    if i >= N or j >= N :
        return 0
    if math . gcd ( arr [ i ] , arr1 [ j ] ) == maxgcd and arr [ i ] != arr1 [ j ] :
        a = max ( a , 1 + maxlen ( i , j + 1 ) )
        return a
    return max ( maxlen ( i + 1 , j ) , maxlen ( i , j + 1 ) )
arr = [ 1 , 2 , 8 , 5 , 6 ]
N = len ( arr )
arr1 = sorted ( arr )
maxgcd = findMaxGCD ( arr , N )
print ( maxlen ( 0 , 0 ) )

Index/key variables: i, j
Accumulator variables: counter
Iterator variables: i
Python program:
from math import sqrt , floor
dp = [ [ [ ] for j in range ( 105 ) ] for k in range ( 105 ) ]
countPaths = 0
def isPerfectSquare ( n ) :
    sr = sqrt ( n )
    return ( ( sr - floor ( sr ) ) == 0 )
def countUniquePaths ( a , m , n , ans ) :
    global dp
    global countPaths
    dp [ 0 ] [ 0 ] . append ( a [ 0 ] [ 0 ] )
    for i in range ( 1 , m ) :
        a [ i ] [ 0 ] *= a [ i - 1 ] [ 0 ]
        dp [ i ] [ 0 ] . append ( a [ i ] [ 0 ] )
    for i in range ( 1 , n ) :
        a [ 0 ] [ i ] *= a [ 0 ] [ i - 1 ]
        dp [ 0 ] [ i ] . append ( a [ 0 ] [ i ] )
    for i in range ( 1 , m ) :
        for j in range ( 1 , n ) :
            top = dp [ i - 1 ] [ j ]
            left = dp [ i ] [ j - 1 ]
            curr = [ ]
            for k in range ( len ( top ) ) :
                curr . append ( top [ k ] * a [ i ] [ j ] )
            for k in range ( len ( left ) ) :
                curr . append ( left [ k ] * a [ i ] [ j ] )
            dp [ i ] [ j ] = curr
    for i in dp [ m - 1 ] [ n - 1 ] :
        if ( isPerfectSquare ( i ) ) :
            countPaths += 1
if __name__ == ' _ _ main _ _ ' :
    M = 3
    N = 4
    mat = [ [ 1 , 2 , 3 , 1 ] , [ 3 , 1 , 2 , 4 ] , [ 2 , 3 , 1 , 1 ] ]
    countUniquePaths ( mat , M , N , 1 )
    print ( countPaths )

Index/key variables: i, j, k
Accumulator variables: countPaths, curr
Iterator variables: i, j, k
Python program:
import sys
MAX = 100000
dp = [ - 1 ] * ( MAX + 1 )
denomination = [ ]
def countMinCoins ( n , C , m ) :
    if ( n == 0 ) :
        dp [ 0 ] = 0
        return 0
    if ( dp [ n ] != - 1 ) :
        return dp [ n ]
    ret = sys . maxsize
    for i in range ( m ) :
        if ( C [ i ] <= n ) :
            x = countMinCoins ( n - C [ i ] , C , m )
            if ( x != sys . maxsize ) :
                ret = min ( ret , 1 + x )
    dp [ n ] = ret
    return ret
def findSolution ( n , C , m ) :
    if ( n == 0 ) :
        for it in denomination :
            print ( it , end = " ▁ " )
        return
    for i in range ( m ) :
        if ( n - C [ i ] >= 0 and dp [ n - C [ i ] ] + 1 == dp [ n ] ) :
            denomination . append ( C [ i ] )
            findSolution ( n - C [ i ] , C , m )
            break
def countMinCoinsUtil ( X , C , N ) :
    isPossible = countMinCoins ( X , C , N )
    if ( isPossible == sys . maxsize ) :
        print ( " - 1" )
    else :
        findSolution ( X , C , N )
if __name__ == ' _ _ main _ _ ' :
    X = 21
    arr = [ 2 , 3 , 4 , 5 ]
    N = len ( arr )
    countMinCoinsUtil ( X , arr , N )

Index/key variables: i, n
Accumulator variables: denomination
Iterator variables: i, it
Python program:
def binCoff ( n , r ) :
    val = 1
    if ( r > ( n - r ) ) :
        r = ( n - r )
    for i in range ( r ) :
        val *= ( n - i )
        val //= ( i + 1 )
    return val
def findWays ( n ) :
    n = n - 1
    a = binCoff ( 2 * n , n )
    b = a // ( n + 1 )
    ans = b
    return ans
if __name__ == " _ _ main _ _ " :
    n = 4
    print ( findWays ( n ) )

Accumulator variables: val
Iterator variables: i
Python program:
dp = [ [ 0 ] * 1010 ] * 1010
def solve ( s , t ) :
    n = len ( s )
    r = 0
    for j in range ( 0 , n ) :
        for i in range ( 0 , n ) :
            dp [ i ] [ j ] = 0
            if ( i > 0 ) :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j ] )
            if ( s [ i ] == t [ j ] ) :
                ans = 1
                if ( i > 0 and j > 0 ) :
                    ans = 1 + dp [ i - 1 ] [ j - 1 ]
                dp [ i ] [ j ] = max ( dp [ i ] [ j ] , ans )
                r = max ( r , dp [ i ] [ j ] )
    return ( n - r )
s = " abcde "
t = " edacb "
print ( solve ( s , t ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def longestSubstring ( s : str , n : int ) :
    index = dict ( )
    answer = 0
    mask = 0
    index [ mask ] = - 1
    for i in range ( n ) :
        temp = ord ( s [ i ] ) - 97
        mask ^= ( 1 << temp )
        if mask in index . keys ( ) :
            answer = max ( answer , i - index [ mask ] )
        else :
            index [ mask ] = i
        for j in range ( 26 ) :
            mask2 = mask ^ ( 1 << j )
            if mask2 in index . keys ( ) :
                answer = max ( answer , i - index [ mask2 ] )
    return answer
s = " adbabd "
n = len ( s )
print ( longestSubstring ( s , n ) )

Index/key variables: i, mask, mask2
Iterator variables: i, j
Python program:
def countNums ( N ) :
    dp = [ [ 0 for i in range ( 16 ) ] for j in range ( N ) ] ;
    for i in range ( 1 , 10 ) :
        dp [ 0 ] [ i ] = 1 ;
    for i in range ( 1 , N ) :
        for j in range ( 0 , 10 ) :
            for k in range ( 0 , 16 ) :
                xor = j ^ k ;
                dp [ i ] [ xor ] += dp [ i - 1 ] [ k ] ;
    count = 0 ;
    for i in range ( 0 , 10 ) :
        count += dp [ N - 1 ] [ i ] ;
    print ( count ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 1 ;
    countNums ( N ) ;

Index/key variables: i, k, xor
Accumulator variables: count
Iterator variables: i, j, k
Python program:
def count ( a , M , N ) :
    cnt = 0
    for i in range ( 1 , M + 1 ) :
        for j in range ( N ) :
            if ( i % a [ j ] == 0 ) :
                cnt += 1
                break
    return cnt
lst = [ 2 , 3 , 5 , 7 ]
m = 100
n = len ( lst )
print ( count ( lst , m , n ) )

Index/key variables: j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
dp = [ [ 0 ] * 10 for j in range ( 15 ) ]
def solve ( n , last , k ) :
    if ( n == 1 ) :
        if ( last == k ) :
            return ( k - 1 )
        else :
            return 1
    if ( dp [ n ] [ last ] ) :
        return dp [ n ] [ last ]
    if ( last == k ) :
        dp [ n ] [ last ] = ( ( k - 1 ) * solve ( n - 1 , k , k ) + ( k - 1 ) * solve ( n - 1 , 1 , k ) )
        return dp [ n ] [ last ]
    else :
        dp [ n ] [ last ] = solve ( n - 1 , k , k )
        return dp [ n ] [ last ]
n = 2
k = 3
x = solve ( n , k , k ) + solve ( n , 1 , k )
print ( x )

Index/key variables: last, n
Python program:
def Print ( occ , s ) :
    for i in range ( 1 , len ( s ) + 1 ) :
        print ( s [ 0 : i ] , " occur " , occ [ i ] , " times . " )
def prefix_function ( s ) :
    LPS = [ 0 for i in range ( len ( s ) ) ]
    for i in range ( 1 , len ( s ) ) :
        j = LPS [ i - 1 ]
        while ( j > 0 and s [ i ] != s [ j ] ) :
            j = LPS [ j - 1 ]
        if ( s [ i ] == s [ j ] ) :
            LPS [ i ] = j + 1
        else :
            LPS [ i ] = 0
    return LPS
def count_occurence ( s ) :
    n = len ( s )
    LPS = prefix_function ( s )
    occ = [ 0 for i in range ( n + 1 ) ]
    for i in range ( n ) :
        occ [ LPS [ i ] ] += 1
    for i in range ( n - 1 , 0 , - 1 ) :
        occ [ LPS [ i - 1 ] ] += occ [ i ]
    for i in range ( n + 1 ) :
        occ [ i ] += 1
    Print ( occ , s )
A = " ABACABA "
count_occurence ( A )

Index/key variables: i, j
Iterator variables: i
Python program:
def maximumSum ( A , B , length , X , Y ) :
    l = length
    l1 = min ( length , X )
    l2 = min ( length , Y )
    dp = [ [ 0 for i in range ( l2 + 1 ) ] for i in range ( l1 + 1 ) ]
    dp [ 0 ] [ 0 ] = 0
    max_sum = - 10 * 9
    for i in range ( 1 , l1 + 1 ) :
        dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + A [ i - 1 ]
        max_sum = max ( max_sum , dp [ i ] [ 0 ] )
    for i in range ( 1 , l2 + 1 ) :
        dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + B [ i - 1 ]
        max_sum = max ( max_sum , dp [ 0 ] [ i ] )
    for i in range ( 1 , l1 + 1 ) :
        for j in range ( 1 , l2 + 1 ) :
            if ( i + j <= l ) :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] + A [ i + j - 1 ] , dp [ i ] [ j - 1 ] + B [ i + j - 1 ] )
            max_sum = max ( dp [ i ] [ j ] , max_sum )
    return max_sum
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 , 4 , 5 ]
    B = [ 5 , 4 , 3 , 2 , 1 ]
    X = 3
    Y = 2
    N = len ( A )
    print ( maximumSum ( A , B , N , X , Y ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def reduceZero ( N ) :
    dp = [ 1e9 for i in range ( N + 1 ) ]
    dp [ 0 ] = 0
    for i in range ( N + 1 ) :
        for c in str ( i ) :
            dp [ i ] = min ( dp [ i ] , dp [ i - ( ord ( c ) - 48 ) ] + 1 )
    return dp [ N ]
N = 25
print ( reduceZero ( N ) )

Index/key variables: N, i
Iterator variables: c, i
Python program:
import numpy as np
dp = np . ones ( ( ( 100002 , 21 , 3 ) ) )
dp = - 1 * dp
def possibleBinaries ( pos , ones , sum , k ) :
    if ( ones == k ) :
        return 0
    if ( pos == 0 ) :
        return 1 if ( sum == 0 ) else 0
    if ( dp [ pos ] [ ones ] [ sum ] != - 1 ) :
        return dp [ pos ] [ ones ] [ sum ]
    ret = ( possibleBinaries ( pos - 1 , ones + 1 , ( sum + 1 ) % 2 , k ) + possibleBinaries ( pos - 1 , 0 , sum , k ) )
    dp [ pos ] [ ones ] [ sum ] = ret
    return dp [ pos ] [ ones ] [ sum ]
N = 3
K = 2
print ( int ( possibleBinaries ( N , 0 , 0 , K ) ) )

Index/key variables: ones, pos, sum
Python program:
class Solution :
    def __init__ ( self , N , K , B ) :
        self . ncr = [ ]
        for i in range ( 101 ) :
            temp = [ ]
            for j in range ( 101 ) :
                temp . append ( - 1 )
            self . ncr . append ( temp )
        self . n = N
        self . k = K
        self . A = [ 0 ] + B
    def f ( self , n , k ) :
        if k == 0 :
            return 1
        if n == k :
            return 1
        if n < k :
            return 0
        if self . ncr [ n ] [ k ] != - 1 :
            return self . ncr [ n ] [ k ]
        self . ncr [ n ] [ k ] = ( self . f ( n - 1 , k ) + self . f ( n - 1 , k - 1 ) )
        return self . ncr [ n ] [ k ]
    def pairsPower ( self ) :
        pre = [ ]
        for i in range ( self . n + 1 ) :
            temp = [ ]
            for j in range ( self . k + 1 ) :
                temp . append ( 0 )
            pre . append ( temp )
        ans = 0
        self . A . sort ( )
        for i in range ( 1 , self . n + 1 ) :
            pre [ i ] [ 0 ] = 1
            for j in range ( 1 , self . k + 1 ) :
                pre [ i ] [ j ] = ( self . A [ i ] * pre [ i ] [ j - 1 ] )
            if i != 1 :
                for j in range ( self . k + 1 ) :
                    pre [ i ] [ j ] = ( pre [ i ] [ j ] + pre [ i - 1 ] [ j ] )
        for i in range ( self . n , 1 , - 1 ) :
            for j in range ( self . k + 1 ) :
                val = self . f ( self . k , j )
                val1 = ( pow ( self . A [ i ] , self . k - j ) * pre [ i - 1 ] [ j ] )
                val = val * val1
                if j % 2 == 0 :
                    ans = ans + val
                else :
                    ans = ans - val
        ans = 2 * ans
        return ans
if __name__ == ' _ _ main _ _ ' :
    N = 3
    K = 3
    arr = [ 1 , 2 , 3 ]
    obj = Solution ( N , K , arr )
    print ( obj . pairsPower ( ) )

Index/key variables: i, j, k, n
Accumulator variables: pre, temp
Iterator variables: i, j
Class/struct names: Solution
Python program:
MOD = 1000000007
dp = [ [ [ 0 for i in range ( 101 ) ] for i in range ( 101 ) ] for i in range ( 101 ) ]
N , M , K = 0 , 0 , 0
def Initialize ( ) :
    for i in range ( 101 ) :
        for j in range ( 101 ) :
            for z in range ( 101 ) :
                dp [ i ] [ j ] [ z ] = - 1
def CountWays ( i , j , k ) :
    if ( i >= N or i < 0 or j >= M or j < 0 or k < 0 ) :
        return 0
    if ( i == 0 and j == 0 and k == 0 ) :
        return 1
    if ( dp [ i ] [ j ] [ k ] != - 1 ) :
        return dp [ i ] [ j ] [ k ]
    else :
        dp [ i ] [ j ] [ k ] = ( CountWays ( i + 1 , j , k - 1 ) % MOD + CountWays ( i - 1 , j , k - 1 ) % MOD + CountWays ( i , j - 1 , k - 1 ) % MOD + CountWays ( i , j + 1 , k - 1 ) % MOD + CountWays ( i , j , k - 1 ) % MOD ) % MOD
    return dp [ i ] [ j ] [ k ]
if __name__ == ' _ _ main _ _ ' :
    N = 3
    M = 3
    K = 4
    Initialize ( )
    print ( CountWays ( 0 , 0 , K ) )

Index/key variables: i, j, k, z
Iterator variables: i, j, z
Python program:
prime = [ True ] * 1000000
def SieveOfEratosthenes ( ) :
    global prime
    prime [ 0 ] = prime [ 1 ] = False
    p = 2
    while p * p <= 100000 :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , 100001 , p ) :
                prime [ i ] = False
        p += 1
def distinctPrimeSubSeq ( a , n , k ) :
    SieveOfEratosthenes ( )
    primes = [ ]
    for i in range ( n ) :
        if ( prime [ a [ i ] ] ) :
            primes . append ( a [ i ] )
    l = len ( primes )
    primes . sort ( )
    b = [ ]
    dp = [ ]
    sum = 0
    i = 0
    while i < l :
        count = 1
        x = a [ i ]
        i += 1
        while ( i < l and a [ i ] == x ) :
            count += 1
            i += 1
        b . append ( count )
        dp . append ( count )
        sum += count
    of_length = 2
    leng = len ( dp )
    ans = 0
    while ( of_length <= k ) :
        freq = 0
        prev = 0
        for i in range ( leng - 1 ) :
            freq += dp [ i ]
            j = sum - freq
            subseq = b [ i ] * j
            ans += subseq
            dp [ i ] = subseq
            prev += dp [ i ]
        leng -= 1
        sum = prev
        of_length += 1
    ans += ( l + 1 )
    return ans
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 2 , 3 , 3 , 4 , 5 ]
    n = len ( a )
    k = 3
    print ( distinctPrimeSubSeq ( a , n , k ) )

Index/key variables: i, p
Accumulator variables: ans, b, count, dp, freq, leng, of_length, prev, primes, sum
Iterator variables: i
Python program:
def findMinPrizes ( arr , n ) :
    totalPrizes = 0
    for i in range ( n ) :
        x = 1
        j = i
        while ( j > 0 and arr [ j ] > arr [ j - 1 ] ) :
            x += 1
            j -= 1
        j = i
        y = 1
        while ( j < n - 1 and arr [ j ] > arr [ j + 1 ] ) :
            y += 1
            j += 1
        totalPrizes += max ( x , y )
    print ( totalPrizes )
arr = [ 1 , 2 , 2 , 3 ]
n = len ( arr )
findMinPrizes ( arr , n )

Index/key variables: j
Accumulator variables: totalPrizes, x, y
Iterator variables: i
Python program:
mod = 1000000007
dp = [ [ - 1 for j in range ( 1000 ) ] for i in range ( 1000 ) ]
def calculate ( pos , left , k , L , R ) :
    if ( pos == k ) :
        if ( left == 0 ) :
            return 1
        else :
            return 0
    if ( left == 0 ) :
        return 0
    if ( dp [ pos ] [ left ] != - 1 ) :
        return dp [ pos ] [ left ]
    answer = 0
    for i in range ( L , R + 1 ) :
        if ( i > left ) :
            break
        answer = ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod
    dp [ pos ] [ left ] = answer
    return answer
def countWaystoDivide ( n , k , L , R ) :
    return calculate ( 0 , n , k , L , R )
if __name__ == " _ _ main _ _ " :
    N = 12
    K = 3
    L = 1
    R = 5
    print ( countWaystoDivide ( N , K , L , R ) )

Index/key variables: left, pos
Iterator variables: i
Python program:
def minSqrNum ( n ) :
    arr = [ 0 ] * ( n + 1 )
    sqrNum = [ 0 ] * ( n + 1 )
    v = [ ]
    for i in range ( n + 1 ) :
        arr [ i ] = arr [ i - 1 ] + 1
        sqrNum [ i ] = 1
        k = 1 ;
        while ( k * k <= i ) :
            if ( arr [ i ] > arr [ i - k * k ] + 1 ) :
                arr [ i ] = arr [ i - k * k ] + 1
                sqrNum [ i ] = k * k
            k += 1
    while ( n > 0 ) :
        v . append ( sqrNum [ n ] )
        n -= sqrNum [ n ] ;
    return v
n = 10
v = minSqrNum ( n )
for i in range ( len ( v ) ) :
    print ( v [ i ] , end = " " )
    if ( i < len ( v ) - 1 ) :
        print ( " ▁ + ▁ " , end = " " )

Index/key variables: i, n
Accumulator variables: k, v
Iterator variables: i
Java program:
import java . util . * ; class GFG { static int maxPresum ( int [ ] a , int [ ] b ) { int X = Math . max ( a [ 0 ] , 0 ) ; for ( int i = 1 ; i < a . length ; i ++ ) { a [ i ] += a [ i - 1 ] ; X = Math . max ( X , a [ i ] ) ; } int Y = Math . max ( b [ 0 ] , 0 ) ; for ( int i = 1 ; i < b . length ; i ++ ) { b [ i ] += b [ i - 1 ] ; Y = Math . max ( Y , b [ i ] ) ; } return X + Y ; } public static void main ( String [ ] args ) { int [ ] A = { 2 , - 1 , 4 , - 5 } ; int [ ] B = { 4 , - 3 , 12 , 4 , - 3 } ; System . out . print ( maxPresum ( A , B ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean sumOfTwoCubes ( int n ) { int lo = 1 , hi = ( int ) Math . cbrt ( n ) ; while ( lo <= hi ) { int curr = ( lo * lo * lo + hi * hi * hi ) ; if ( curr == n ) return true ; if ( curr < n ) lo ++ ; else hi -- ; } return false ; } public static void main ( String [ ] args ) { int N = 28 ; if ( sumOfTwoCubes ( N ) ) { System . out . println ( " True " ) ; } else { System . out . println ( " False " ) ; } } }

Accumulator variables: hi, lo
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static long findNthNumber ( long N ) { long result = 0 ; long p = 1 ; while ( N > 0 ) { result += ( p * ( N % 9 ) ) ; N = N / 9 ; p = p * 10 ; } return result ; } public static void main ( String [ ] args ) { int N = 9 ; System . out . print ( findNthNumber ( N ) ) ; } }

Accumulator variables: result
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int check ( int A , int B ) { if ( A == B ) { return 1 ; } int dig1 = ( int ) Math . floor ( Math . log10 ( A ) + 1 ) ; int dig2 = ( int ) Math . floor ( Math . log10 ( B ) + 1 ) ; if ( dig1 != dig2 ) { return 0 ; } int temp = A ; while ( true ) { int power = ( int ) Math . pow ( 10 , dig1 - 1 ) ; int firstdigit = A / power ; A = A - firstdigit * power ; A = A * 10 + firstdigit ; if ( A == B ) { return 1 ; } if ( A == temp ) { return 0 ; } } } public static void main ( String [ ] args ) { int A = 967 , B = 679 ; if ( check ( A , B ) == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void sameProductQuadruples ( int [ ] nums , int N ) { int [ ] umap = new int [ 10000 ] ; int res = 0 ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = i + 1 ; j < N ; ++ j ) { int prod = nums [ i ] * nums [ j ] ; res += 8 * umap [ prod ] ; ++ umap [ prod ] ; } } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 6 } ; int N = arr . length ; sameProductQuadruples ( arr , N ) ; } }

Index/key variables: i, j, prod
Accumulator variables: res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int MOD = 1000000007 ; static int power ( int x , int y , int p ) { p = MOD ; int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static void totalWays ( int N , int M ) { int X = N / 2 ; int S = ( X * ( X + 1 ) ) % MOD ; System . out . println ( power ( S , M , MOD ) ) ; } public static void main ( String [ ] args ) { int N = 5 , M = 2 ; totalWays ( N , M ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void isCycleExists ( int [ ] arr , int N ) { for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 4 , 5 } ; int N = arr . length ; isCycleExists ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void getMax ( int arr [ ] , int N , int K ) { for ( int i = 1 ; i < N ; i ++ ) { int cur_val = arr [ i ] ; while ( K >= i ) { if ( cur_val > 0 ) { arr [ 0 ] = arr [ 0 ] + 1 ; cur_val = cur_val - 1 ; K = K - i ; } else break ; } } System . out . print ( arr [ 0 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 3 , 2 } ; int N = arr . length ; int K = 5 ; getMax ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int minSwaps ( int [ ] [ ] b ) { int n = b . length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( b [ 0 ] [ 0 ] ^ b [ 0 ] [ j ] ^ b [ i ] [ 0 ] ^ b [ i ] [ j ] ) == 1 ) { return - 1 ; } } } int rowSum = 0 ; int colSum = 0 ; int rowSwap = 0 ; int colSwap = 0 ; for ( int i = 0 ; i < n ; i ++ ) { rowSum += b [ i ] [ 0 ] ; colSum += b [ 0 ] [ i ] ; int cond1 = 0 ; int cond2 = 0 ; if ( b [ i ] [ 0 ] == i % 2 ) cond1 = 1 ; if ( b [ 0 ] [ i ] == i % 2 ) cond2 = 1 ; rowSwap += cond1 ; colSwap += cond2 ; } if ( rowSum != n / 2 && rowSum != ( n + 1 ) / 2 ) return - 1 ; if ( colSum != n / 2 && colSum != ( n + 1 ) / 2 ) return - 1 ; if ( n % 2 == 1 ) { if ( ( colSwap % 2 ) == 1 ) colSwap = n - colSwap ; if ( ( rowSwap % 2 ) == 1 ) rowSwap = n - rowSwap ; } else { colSwap = Math . min ( colSwap , n - colSwap ) ; rowSwap = Math . min ( rowSwap , n - rowSwap ) ; } return ( rowSwap + colSwap ) / 2 ; } public static void main ( String [ ] args ) { int [ ] [ ] M = { { 0 , 1 , 1 , 0 } , { 0 , 1 , 1 , 0 } , { 1 , 0 , 0 , 1 } , { 1 , 0 , 0 , 1 } } ; int ans = minSwaps ( M ) ; System . out . println ( ans ) ; } }

Index/key variables: i, j
Accumulator variables: colSum, colSwap, i, j, rowSum, rowSwap
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class Main { public static void count_setbit ( int N ) { int result = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { if ( ( ( 1 << i ) & N ) > 0 ) { result ++ ; } } System . out . println ( result ) ; } public static void main ( String [ ] args ) { int N = 43 ; count_setbit ( N ) ; } }

Accumulator variables: i, result
Iterator variables: i
Class/struct names: Main
Java program:
class GFG { static int mod = 1000000007 ; static int ValOfTheExpression ( int n ) { int [ ] factorial = new int [ n + 1 ] ; factorial [ 0 ] = factorial [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { factorial [ i ] = ( ( factorial [ i - 1 ] % mod ) * ( i % mod ) ) % mod ; } int [ ] dp = new int [ n + 1 ] ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] = ( ( dp [ i - 1 ] % mod ) * ( factorial [ i ] % mod ) ) % mod ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( ValOfTheExpression ( n ) ) ; } }

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