dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def printDiagonalTraversal ( nums ) :
    max_size = len ( nums )
    for i in range ( len ( nums ) ) :
        if ( max_size < len ( nums [ i ] ) ) :
            max_size = len ( nums [ i ] )
    v = [ [ ] for i in range ( 2 * max_size - 1 ) ]
    for i in range ( len ( nums ) ) :
        for j in range ( len ( nums [ i ] ) ) :
            v [ i + j ] . append ( nums [ i ] [ j ] )
    for i in range ( len ( v ) ) :
        v [ i ] = v [ i ] [ : : - 1 ]
        for j in range ( len ( v [ i ] ) ) :
            print ( v [ i ] [ j ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    printDiagonalTraversal ( arr )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math
def isValid ( s ) :
    n = int ( math . sqrt ( len ( s ) ) )
    check = s [ 0 ]
    for i in range ( n ) :
        x = i
        y = i
        while ( x >= 0 and y < n ) :
            if ( s [ n * x + y ] != check or s [ n * x + x ] != check ) :
                print ( " No " )
                return
            x -= 1
            y += 1
    print ( " Yes " )
str = " abacdaeaafaghaia "
isValid ( str )

Accumulator variables: x, y
Iterator variables: i
Python program:
N = 10
pref = [ 0 ] * N
power = [ 0 ] * N
def toDigit ( ch ) :
    return ( ord ( ch ) - ord ( '0' ) )
def powerOf10 ( ) :
    power [ 0 ] = 1
    for i in range ( 1 , N ) :
        power [ i ] = power [ i - 1 ] * 10
def precomputePrefix ( st , n ) :
    pref [ 0 ] = ( ord ( st [ 0 ] ) - ord ( '0' ) )
    for i in range ( 1 , n ) :
        pref [ i ] = ( pref [ i - 1 ] + toDigit ( st [ i ] ) )
def triangularNumber ( i ) :
    res = i * ( i + 1 ) // 2
    return res
def sumOfSubstrings ( st ) :
    n = len ( st )
    powerOf10 ( )
    precomputePrefix ( st , n )
    ans = 0
    for i in range ( n - 1 ) :
        ans += ( ( pref [ n - i - 2 ] * ( i + 1 ) + toDigit ( st [ n - i - 1 ] ) * triangularNumber ( n - i - 1 ) ) * power [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    st = "1234"
    print ( sumOfSubstrings ( st ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def OddLengthSum ( arr ) :
    sum = 0
    l = len ( arr )
    for i in range ( l ) :
        for j in range ( i , l , 2 ) :
            for k in range ( i , j + 1 , 1 ) :
                sum += arr [ k ]
    return sum
arr = [ 1 , 5 , 3 , 1 , 2 ]
print ( OddLengthSum ( arr ) )

Index/key variables: k
Accumulator variables: sum
Iterator variables: i, j, k
Python program:
def OddLengthSum ( arr ) :
    Sum = 0
    l = len ( arr )
    for i in range ( l ) :
        Sum += ( ( ( ( i + 1 ) * ( l - i ) + 1 ) // 2 ) * arr [ i ] )
    return Sum
arr = [ 1 , 5 , 3 , 1 , 2 ]
print ( OddLengthSum ( arr ) )

Index/key variables: i
Accumulator variables: Sum
Iterator variables: i
Python program:
def phi ( n ) :
    result = 1
    for p in range ( 2 , n ) :
        if ( __gcd ( p , n ) == 1 ) :
            result += 1
    return result
def sameEulerTotient ( n ) :
    return phi ( n ) == phi ( 2 * n )
def __gcd ( a , b ) :
    return a if b == 0 else __gcd ( b , a % b )
if __name__ == ' _ _ main _ _ ' :
    N = 13
    if ( sameEulerTotient ( N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: result
Iterator variables: p
Python program:
def solve ( arr , N ) :
    M = { }
    for i in range ( N ) :
        M [ i ] = arr [ i ]
    arr . sort ( )
    Count = { }
    for i in range ( N ) :
        Count [ arr [ i ] ] = pow ( 2 , N - i - 1 )
    for it in Count . values ( ) :
        print ( it , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 2 , 1 ]
    N = len ( arr )
    solve ( arr , N )

Index/key variables: i
Iterator variables: i, it
Python program:
def checkOdd ( ch ) :
    return ( ( ord ( ch ) - 48 ) & 1 )
def Insert_dash ( num_str ) :
    result_str = num_str
    x = 0
    while ( x < len ( num_str ) - 1 ) :
        if ( checkOdd ( num_str [ x ] ) and checkOdd ( num_str [ x + 1 ] ) ) :
            result_str = ( result_str [ : x + 1 ] + ' - ' + result_str [ x + 1 : ] )
            num_str = result_str
            x += 1
        x += 1
    return result_str
str = "1745389"
print ( Insert_dash ( str ) )

Index/key variables: x
Python program:
N = 3
M = 3
def checkReverseBitonic ( arr , n ) :
    f = 0
    for i in range ( 1 , n ) :
        if ( arr [ i ] < arr [ i - 1 ] ) :
            continue
        if ( arr [ i ] == arr [ i - 1 ] ) :
            return False
        else :
            f = 1
            break
    if ( i == n ) :
        return True
    for j in range ( i + 1 , n ) :
        if ( arr [ j ] > arr [ j - 1 ] ) :
            continue
        if ( arr [ i ] == arr [ i - 1 ] ) :
            return False
        else :
            if ( f == 1 ) :
                return False
    return True
def check ( arr ) :
    f = 0
    for i in range ( N ) :
        if ( not checkReverseBitonic ( arr [ i ] , M ) ) :
            print ( " No " )
            return
    for i in range ( N ) :
        temp = [ 0 ] * N
        for j in range ( N ) :
            temp [ j ] = arr [ j ] [ i ]
        if ( not checkReverseBitonic ( temp , N ) ) :
            print ( " No " )
            return
    print ( " Yes " )
if __name__ == " _ _ main _ _ " :
    m = [ [ 2 , 3 , 4 ] , [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ]
    check ( m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def string_modify ( s ) :
    alphabets = [ ]
    flag , hold_i = 0 , 0
    hold_l = s [ 0 ]
    for i in range ( 26 ) :
        alphabets . append ( chr ( i + ord ( ' a ' ) ) )
    difference = set ( )
    reconstruct = " "
    for i in range ( 1 , len ( s ) ) :
        difference . add ( ord ( s [ i ] ) - ord ( s [ i - 1 ] ) )
    if ( len ( difference ) == 1 ) :
        print ( " No ▁ modifications ▁ required " )
        return
    for it in difference :
        index = ord ( s [ 0 ] ) - ord ( ' a ' )
        reconstruct = " "
        flag = 0
        i = 0
        while ( ( i < len ( s ) ) and ( flag <= 1 ) ) :
            reconstruct += alphabets [ index ]
            index += it
            if ( index < 0 ) :
                index += 26
            index %= 26
            if ( reconstruct [ i ] != s [ i ] ) :
                flag += 1
                hold_i = i
                hold_l = s [ i ]
            i += 1
        if ( flag == 1 ) :
            s [ hold_i ] = reconstruct [ hold_i ]
            break
    if ( flag > 1 ) :
        hold_i = 0
        hold_l = s [ 0 ]
        temp = ( ord ( s [ 1 ] ) - ord ( ' a ' ) - ( ord ( s [ 2 ] ) - ord ( s [ 1 ] ) ) ) % 26
        if ( temp < 0 ) :
            temp += 26
        s [ 0 ] = alphabets [ temp ]
    print ( hold_i , " - > " , hold_l )
    print ( " " . join ( s ) )
s = list ( " aeimqux " )
string_modify ( s )

Index/key variables: hold_i, i, index, temp
Accumulator variables: alphabets, difference, flag, reconstruct
Iterator variables: i, it
Python program:
def evenSubMatrix ( N ) :
    even = 1
    odd = 2
    for i in range ( N ) :
        for j in range ( N ) :
            if ( ( i + j ) % 2 == 0 ) :
                print ( even , end = " ▁ " )
                even += 2
            else :
                print ( odd , end = " ▁ " )
                odd += 2
        print ( )
N = 4
evenSubMatrix ( N )

Accumulator variables: even, odd
Iterator variables: i, j
Python program:
def maximum_inversion ( n , k ) :
    answer = 0 ;
    k = min ( k , n // 2 ) ;
    left = 1 ;
    right = n ;
    while ( k > 0 ) :
        k -= 1 ;
        answer += 2 * ( right - left ) - 1 ;
        left += 1 ;
        right -= 1 ;
    print ( answer ) ;
if __name__ == ' _ _ main _ _ ' :
    N = 5 ;
    K = 3 ;
    maximum_inversion ( N , K ) ;
    N = 4 ;
    K = 1 ;
    maximum_inversion ( N , K ) ;

Accumulator variables: answer, k, left, right
Python program:
def helper ( s , pos ) :
    size = len ( s )
    if ( pos >= size ) :
        return True
    if ( s [ pos ] . isdigit ( ) == False ) :
        return False
    num = 0
    for i in range ( pos , size ) :
        num = num * 10 + ord ( s [ pos ] ) - 48
        if ( i + 1 + num > size ) :
            return False
        if ( helper ( s , i + 1 + num ) ) :
            return True
    return False
s = "123abc4db1c " ;
if ( helper ( s , 0 ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: pos
Iterator variables: i
Python program:
N_bonacci = [ 0 ] * 100
def N_bonacci_nums ( n , k ) :
    N_bonacci [ 0 ] = 1
    for i in range ( 1 , 51 ) :
        j = i - 1
        while j >= i - k and j >= 0 :
            N_bonacci [ i ] += N_bonacci [ j ]
            j -= 1
    ans = [ ]
    for i in range ( 50 , - 1 , - 1 ) :
        if ( n - N_bonacci [ i ] >= 0 ) :
            ans . append ( N_bonacci [ i ] )
            n -= N_bonacci [ i ]
    if ( len ( ans ) == 1 ) :
        ans . append ( 0 )
    print ( len ( ans ) )
    for i in ans :
        print ( i , end = " , ▁ " )
if __name__ == ' _ _ main _ _ ' :
    n = 21
    k = 5
    N_bonacci_nums ( n , k )

Index/key variables: i, j
Accumulator variables: ans, n
Iterator variables: i
Python program:
def solve ( n , k ) :
    d = k * ( k + 1 ) ;
    if ( ( 2 * n ) % d != 0 ) :
        print ( " - 1" ) ;
        return ;
    x1 = 2 * n // d ;
    for i in range ( 1 , k + 1 ) :
        print ( x1 * i , end = " ▁ " ) ;
n = 10 ; k = 4 ;
solve ( n , k ) ;

Iterator variables: i
Python program:
def checkBitonic ( s ) :
    i = 0
    j = 0
    for i in range ( 1 , len ( s ) ) :
        if ( s [ i ] > s [ i - 1 ] ) :
            continue ;
        if ( s [ i ] <= s [ i - 1 ] ) :
            break ;
    if ( i == ( len ( s ) - 1 ) ) :
        return True ;
    for j in range ( i + 1 , len ( s ) ) :
        if ( s [ j ] < s [ j - 1 ] ) :
            continue ;
        if ( s [ j ] >= s [ j - 1 ] ) :
            break ;
    i = j ;
    if ( i != len ( s ) - 1 ) :
        return False ;
    return True ;
s = " abcdfgcba "
if ( checkBitonic ( s ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findArray ( a , n , P ) :
    mi = min ( a )
    ctr = 0
    mi = max ( 0 , mi - 1 )
    for i in range ( n ) :
        a [ i ] -= mi
        ctr += mi
    i = P - 1
    start = - 1
    while ( 1 ) :
        if ( a [ i ] == 0 ) :
            start = i
            break
        a [ i ] -= 1
        ctr += 1
        i = ( i - 1 + n ) % n
    a [ start ] = ctr
    print ( * a , sep = ' , ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    P = 2
    arr = [ 3 , 2 , 0 , 2 , 7 ]
    findArray ( arr , N , P )

Index/key variables: i, start
Accumulator variables: ctr
Iterator variables: i
Python program:
def makeArray ( n ) :
    for i in range ( n ) :
        print ( ( i + 1 ) * n , end = " ▁ " )
n = 6 ;
makeArray ( n ) ;

Iterator variables: i
Python program:
def printOddFactorNumber ( n , m ) :
    for i in range ( n , m + 1 ) :
        if ( ( i > 0 ) and ( ( i & ( i - 1 ) ) != 0 ) ) :
            print ( i , end = " ▁ " )
N = 2
M = 10
printOddFactorNumber ( N , M )

Iterator variables: i
Python program:
def PrintSeries ( n ) :
    k = 2
    for i in range ( 0 , n ) :
        print ( k * ( 2 * k - 1 ) , end = ' ▁ ' )
        k = k + 2
n = 12
PrintSeries ( n )

Iterator variables: i
Python program:
def find ( S , N ) :
    pref = " "
    suff = " "
    mid = " "
    for i in range ( N ) :
        first = int ( S [ i ] . index ( " * " ) )
        last = int ( S [ i ] . rindex ( " * " ) )
        for z in range ( len ( pref ) ) :
            if ( z < first ) :
                if ( pref [ z ] != S [ i ] [ z ] ) :
                    return " * "
        for z in range ( len ( pref ) , first ) :
            pref += S [ i ] [ z ] ;
        for z in range ( len ( suff ) ) :
            if ( len ( S [ i ] ) - 1 - z > last ) :
                if ( suff [ z ] != S [ i ] [ len ( S [ i ] ) - 1 - z ] ) :
                    return " * "
        for z in range ( len ( suff ) , len ( S [ i ] ) - 1 - last ) :
            suff += S [ i ] [ len ( S [ i ] ) - 1 - z ]
        for z in range ( first , last + 1 ) :
            if ( S [ i ] [ z ] != ' * ' ) :
                mid += S [ i ] [ z ]
    suff = suff [ : : - 1 ]
    return pref + mid + suff
N = 3
s = [ " " for i in range ( N ) ]
s [ 0 ] = " pq * du * q "
s [ 1 ] = " pq * abc * q "
s [ 2 ] = " p * d * q "
print ( find ( s , N ) )

Index/key variables: i, z
Accumulator variables: mid, pref, suff
Iterator variables: i, z
Python program:
def check_string_exist ( S ) :
    size = len ( S )
    check = True
    for i in range ( size ) :
        if S [ i ] != S [ ( i + 2 ) % size ] :
            check = False
            break
    if check :
        print ( " Yes " )
    else :
        print ( " No " )
S = " papa "
check_string_exist ( S )

Index/key variables: i
Iterator variables: i
Boolean variables: check
Python program:
def getProduct ( n ) :
    product = 1
    while ( n != 0 ) :
        product = product * ( n % 10 )
        n = int ( n / 10 )
    return product
def productinRange ( l , r ) :
    if ( r - l > 9 ) :
        return 0
    else :
        p = 1
        for i in range ( l , r + 1 ) :
            p = p * getProduct ( i )
        return p
l = 11
r = 15
print ( productinRange ( l , r ) , end = ' ' )
l = 1
r = 15
print ( productinRange ( l , r ) )

Iterator variables: i
Python program:
def checkQwertyRow ( x ) :
    first_row = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , ' - ' , ' = ' ]
    second_row = [ ' Q ' , ' W ' , ' E ' , ' R ' , ' T ' , ' Y ' , ' U ' , ' I ' , ' O ' , ' P ' , ' [ ' , ' ] ' , ' q ' , ' w ' , ' e ' , ' r ' , ' t ' , ' y ' , ' u ' , ' i ' , ' o ' , ' p ' ]
    third_row = [ ' A ' , ' S ' , ' D ' , ' F ' , ' G ' , ' H ' , ' J ' , ' K ' , ' L ' , ' ; ' , ' : ' , ' a ' , ' s ' , ' d ' , ' f ' , ' g ' , ' h ' , ' j ' , ' k ' , ' l ' ]
    fourth_row = [ ' Z ' , ' X ' , ' C ' , ' V ' , ' B ' , ' N ' , ' M ' , ' , ' , ' . ' , ' / ' , ' z ' , ' x ' , ' c ' , ' v ' , ' b ' , ' n ' , ' m ' ]
    if ( first_row . count ( x ) > 0 ) :
        return 1
    elif ( second_row . count ( x ) > 0 ) :
        return 2
    elif ( third_row . count ( x ) > 0 ) :
        return 3
    elif ( fourth_row . count ( x ) > 0 ) :
        return 4
    return 0
def checkValidity ( str ) :
    x = str [ 0 ]
    row = checkQwertyRow ( x )
    for i in range ( len ( str ) ) :
        x = str [ i ]
        if ( row != checkQwertyRow ( x ) ) :
            return False
    return True
str = " GeeksforGeeks "
if ( checkValidity ( str ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def fib ( n ) :
    f0 = 0
    f1 = 1
    if ( n == 0 ) :
        return 0
    if ( n == 1 ) :
        return 1
    else :
        rem = n % 60
        if ( rem == 0 ) :
            return 0
        for i in range ( 2 , rem + 3 ) :
            f = ( f0 + f1 ) % 60
            f0 = f1
            f1 = f
        s = f1 - 1
        return ( s )
if __name__ == ' _ _ main _ _ ' :
    m = 10087887
    n = 2983097899
    final = fib ( n ) - fib ( m - 1 )
    print ( final % 10 )

Iterator variables: i
Python program:
import math
def printSinX ( N ) :
    Xi = 0 ;
    num = 1 ;
    while ( N > 0 ) :
        print ( " X " , num , " = " , Xi , end = " ▁ " ) ;
        print ( " sin ( X " , num , " ) ▁ = " , end = " ▁ " ) ;
        print ( " { : . 6f } " . format ( math . sin ( Xi ) ) ,   " " ) ;
        num += 1 ;
        Xi += 710 ;
        N = N - 1 ;
N = 5 ;
printSinX ( N )

Accumulator variables: Xi, num
Python program:
def sumBetweenZero ( arr , N ) :
    i = 0
    A = [ ]
    sum = 0
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            i += 1
            break
    k = i
    for i in range ( k , N , 1 ) :
        if ( arr [ i ] == 0 ) :
            A . append ( sum )
            sum = 0
        else :
            sum += arr [ i ]
    for i in range ( len ( A ) ) :
        print ( A [ i ] , end = ' ▁ ' )
    if ( len ( A ) == 0 ) :
        print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 3 , 4 , 0 , 4 , 4 , 0 , 2 , 1 , 4 , 0 , 3 ]
    N = len ( arr )
    sumBetweenZero ( arr , N )

Index/key variables: i
Accumulator variables: A, sum
Iterator variables: i
Python program:
def maximumSubsequence ( arr , N ) :
    M = { i : 0 for i in range ( 100 ) }
    for i in range ( N ) :
        M [ arr [ i ] ] += 1
    distinct_size = len ( M )
    maxFreq = 1
    for value in M . values ( ) :
        maxFreq = max ( maxFreq , value )
    print ( max ( min ( distinct_size , maxFreq - 1 ) , min ( distinct_size - 1 , maxFreq ) ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 ]
    N = len ( arr )
    maximumSubsequence ( arr , N )

Index/key variables: i
Iterator variables: i, value
Python program:
def countCharacters ( arr , chars ) :
    res = 0
    freq = dict ( )
    for i in range ( len ( chars ) ) :
        freq [ chars [ i ] ] = freq . get ( chars [ i ] , 0 ) + 1
    for st in arr :
        flag = True
        for c in st :
            if ( c not in freq ) :
                flag = False
                break
        if ( flag ) :
            res += len ( st )
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ " hi " , " data " , " geeksforgeeks " ]
    chars = " tiadhae "
    print ( countCharacters ( arr , chars ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: c, i, st
Boolean variables: flag
Python program:
def arrayConstruct ( N ) :
    for i in range ( 2 , N + 1 , 2 ) :
        print ( i , end = " ▁ " )
    for i in range ( 1 , N - 1 , 2 ) :
        print ( i , end = " ▁ " )
    print ( N - 1 + ( N // 2 ) )
def createArray ( N ) :
    if ( N % 4 == 0 ) :
        arrayConstruct ( N )
    else :
        cout << - 1 << endl
if __name__ == ' _ _ main _ _ ' :
    N = 8
    createArray ( N )

Iterator variables: i
Python program:
def distinctSubstring ( P , Q , K , N ) :
    S = set ( )
    for i in range ( N ) :
        sum = 0
        s = " "
        for j in range ( i , N ) :
            pos = ord ( P [ j ] ) - 97
            sum += ord ( Q [ pos ] ) - 48
            s += P [ j ]
            if ( sum <= K ) :
                S . add ( s )
            else :
                break
    return len ( S )
if __name__ == ' _ _ main _ _ ' :
    S = " abcde "
    W = "12345678912345678912345678"
    K = 5
    N = len ( S )
    print ( distinctSubstring ( S , W , K , N ) )

Index/key variables: j, pos
Accumulator variables: S, s, sum
Iterator variables: i, j
Python program:
def distinctSubstring ( P , Q , K , N ) :
    S = set ( )
    for i in range ( 0 , N ) :
        sum = 0 ;
        s = ' '
        for j in range ( i , N ) :
            pos = ord ( P [ j ] ) - 97
            sum = sum + ord ( Q [ pos ] ) - 48
            s += P [ j ]
            if ( sum <= K ) :
                S . add ( s )
            else :
                break
    return len ( S )
P = " abcde "
Q = "12345678912345678912345678"
K = 5
N = len ( P )
print ( distinctSubstring ( P , Q , K , N ) )

Index/key variables: j, pos
Accumulator variables: S, s
Iterator variables: i, j
Python program:
def printPattern ( n ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , 2 * n ) :
            if ( j == ( n - i + 1 ) or j == ( n + i - 1 ) ) :
                print ( " * ▁ " , end = " " )
            elif ( ( i >= 4 and i <= n - 4 ) and ( j == n - i + 4 or j == n + i - 4 ) ) :
                print ( " * ▁ " , end = " " )
            elif ( i == n or ( i == n - 4 and j >= n - ( n - 2 * 4 ) and j <= n + n - 2 * 4 ) ) :
                print ( " * ▁ " , end = " " )
            else :
                print ( " ▁ " + " ▁ " , end = " " )
        print ( )
N = 9
printPattern ( N )

Iterator variables: i, j
Python program:
def isKAlternating ( s , k ) :
    if ( len ( s ) < k ) :
        return False
    checker = 0
    for i in range ( k ) :
        bitAtIndex = ord ( s [ i ] ) - ord ( ' a ' )
        if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) :
            return False
        checker = checker | ( 1 << bitAtIndex )
    for i in range ( k , len ( s ) ) :
        if ( s [ i - k ] != s [ i ] ) :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    st = " acdeac "
    K = 4
    if ( isKAlternating ( st , K ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
import math
MAX = 100000
def findFactors ( N ) :
    temp = int ( math . sqrt ( N ) )
    factor = [ 1 ] * MAX
    len1 = 1
    while ( temp % 2 == 0 ) :
        factor [ len1 ] = 2
        len1 += 1
        factor [ len1 ] = 2
        len1 += 1
        temp //= 2
    sqt = math . sqrt ( temp )
    for j in range ( 3 , math . ceil ( sqt ) , 2 ) :
        while ( temp % j == 0 ) :
            factor [ len1 ] = j
            len1 += 1
            factor [ len1 ] = j
            len1 += 1
            temp //= j
    if ( temp > 2 ) :
        factor [ len1 ] = temp
        len1 += 1
        factor [ len1 ] = temp
        len1 += 1
    M = [ [ 0 for x in range ( MAX ) ] for y in range ( len1 ) ]
    tpc , tpr = 0 , 0
    M [ 0 ] [ 0 ] = 1
    j = 1
    while ( j < len1 ) :
        if ( factor [ j ] != factor [ j - 1 ] ) :
            tpr += 1
            M [ tpr ] [ 0 ] = factor [ j ]
            j += 1
            tpc = 1
        else :
            M [ tpr ] [ tpc ] = M [ tpr ] [ tpc - 1 ] * factor [ j ]
            j += 1
            tpc += 1
    arr1 = [ 0 ] * MAX
    arr2 = [ 0 ] * MAX
    l1 = l2 = 1
    arr1 [ 0 ] = 1
    arr2 [ 0 ] = 1
    for i in range ( 1 , tpr + 1 ) :
        j = 0
        while M [ i ] [ j ] != 0 :
            for k in range ( l1 ) :
                arr2 [ l2 ] = arr1 [ k ] * M [ i ] [ j ]
                l2 += 1
            j += 1
        for j in range ( l1 , l2 ) :
            arr1 [ j ] = arr2 [ j ]
        l1 = l2
    for i in range ( l2 ) :
        print ( arr2 [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N = 900
    findFactors ( N )

Index/key variables: i, j, k, l2, len1, tpc, tpr
Accumulator variables: temp
Iterator variables: i, j, k
Python program:
import numpy as np ;
matrix = np . zeros ( ( 100 , 100 ) ) ;
def printRequiredMatrix ( n ) :
    if ( n == 1 ) :
        print ( "1" ) ;
    elif ( n % 2 != 0 ) :
        print ( " - 1" ) ;
    else :
        for i in range ( n ) :
            matrix [ i ] [ i ] = n ;
        u = n - 1 ;
        for i in range ( n - 1 ) :
            matrix [ i ] [ u ] = i + 1 ;
            for j in range ( 1 , n // 2 ) :
                a = ( i + j ) % ( n - 1 ) ;
                b = ( i - j + n - 1 ) % ( n - 1 ) ;
                if ( a < b ) :
                    a , b = b , a
                matrix [ b ] [ a ] = i + 1 ;
        for i in range ( n ) :
            for j in range ( i ) :
                matrix [ i ] [ j ] = matrix [ j ] [ i ] + n ;
        for i in range ( n ) :
            for j in range ( n ) :
                print ( matrix [ i ] [ j ] , end = " ▁ " ) ;
            print ( ) ;
    print ( )
if __name__ == " _ _ main _ _ " :
    n = 1 ;
    printRequiredMatrix ( n ) ;
    n = 3 ;
    printRequiredMatrix ( n ) ;
    n = 6 ;
    printRequiredMatrix ( n ) ;

Index/key variables: a, b, i, j, u
Iterator variables: i, j
Python program:
def countSubstring ( S , n ) :
    ans = 0 ;
    i = 0 ;
    while ( i < n ) :
        cnt0 = 0 ; cnt1 = 0 ;
        if ( S [ i ] == '0' ) :
            while ( i < n and S [ i ] == '0' ) :
                cnt0 += 1 ;
                i += 1 ;
            j = i ;
            while ( j < n and S [ j ] == '1' ) :
                cnt1 += 1 ;
                j += 1 ;
        else :
            while ( i < n and S [ i ] == '1' ) :
                cnt1 += 1 ;
                i += 1 ;
            j = i ;
            while ( j < n and S [ j ] == '0' ) :
                cnt0 += 1 ;
                j += 1 ;
        ans += min ( cnt0 , cnt1 ) ;
    return ans ;
if __name__ == " _ _ main _ _ " :
    S = "0001110010" ;
    n = len ( S ) ;
    print ( countSubstring ( S , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, cnt0, cnt1