giulio98/xlcost-single-prompt huggingface dataset:
# check if count of even divisors of n is equal to count of odd divisors | python3 program for the above approach ; function to check if count of even and odd divisors are equal ; to store the count of even factors and odd factors ; loop till [ 1 , sqrt ( n ) ] ; if divisors are equal add only one ; check for even divisor ; odd divisor ; check for both divisor i . e . , i and n / i ; check if i is odd or even ; check if n / i is odd or even ; return true if count of even_div and odd_div are equals ; 

import math


def divisorsSame(n):
    even_div = 0
    odd_div = 0
    for i in range(1, int(math .sqrt(n))):
        if (n % i == 0):
            if (n // i == i):
                if (i % 2 == 0):
                    even_div += 1
                else:
                    odd_div += 1
            else:
                if (i % 2 == 0):
                    even_div += 1
                else:
                    odd_div += 1
                if (n // (i % 2) == 0):
                    even_div += 1
                else:
                    odd_div += 1
    return (even_div == odd_div)


N = 6
if (divisorsSame(N) == 0):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# check if n is a balanced prime number or not | utility function to check if a number is prime or not ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; function that returns true if n is a balanced prime ; if n is not a prime number or n is the first prime then return false ; initialize previous_prime to n - 1 and next_prime to n + 1 ; find next prime number ; find previous prime number ; arithmetic mean ; if n is a weak prime ; 
def isPrime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if (n % i == 0 or n % (i + 2) == 0):
            return False
        i += 6
    return True


def isBalancedPrime(n):
    if not isPrime(n) or n == 2:
        return False
    previous_prime = n - 1
    next_prime = n + 1
    while not isPrime(next_prime):
        next_prime += 1
    while not isPrime(previous_prime):
        previous_prime -= 1
    mean = (previous_prime + next_prime) / 2
    if n == mean:
        return True
    else:
        return False


n = 53
if isBalancedPrime(n):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# count of nodes having odd divisors in the given subtree for q queries | python3 implementation to count the number of nodes having odd number of divisors for each query ; adjacency list for tree . ; array for values and answer at ith node . ; function to check whether n has odd divisors or not ; dfs function to pre - compute the answers ; initialize the count ; repeat for every child ; increase the count if current node has odd number of divisors ; 

import math
N = 100001
adj = [[]for i in range(N)]
a = [0 for i in range(N)]
ans = [0 for i in range(N)]


def hasOddNumberOfDivisors(n):
    if (math .sqrt(n) == int(math .sqrt(n))):
        return True
    return False


def dfs(node, parent):
    count = 0
    for i in adj[node]:
        if (i != parent):
            count += dfs(i, node)
    if (hasOddNumberOfDivisors(a[node])):
        count += 1
    ans[node] = count
    return count


if __name__ == "__main__":
    n = 5
    i = 0
    q = [4, 1, 5, 3]
    adj[1].append(2)
    adj[2].append(1)
    adj[2].append(3)
    adj[3].append(2)
    adj[3].append(4)
    adj[4].append(3)
    adj[1].append(5)
    adj[5].append(1)
    a[1] = 4
    a[2] = 9
    a[3] = 14
    a[4] = 100
    a[5] = 5
    dfs(1, -1)
    for i in range(len(q)):
        print(ans[q[i]], end=' ')

# Expected output:
1 3 0 1
# minimum cost to make all array elements equal using given operations | python3 implementation to find the minimum cost to make all array elements equal ; checks if the value is less than middle element of the array ; function that returns the cost of making all elements equal to current element ; compute the lower bound of current element ; calculate the requirement of add operation ; calculate the requirement of subtract operation ; compute minimum of left and right ; computing the total cost of add and subtract operations ; function that prints minimum cost of making all elements equal ; sort the given array ; calculate minimum from a + r and m ; compute prefix sum and store in pref array ; find the minimum cost from the given elements ; finding the minimum cost from the other cases where minimum cost can occur ; printing the minimum cost of making all elements equal ; 
def lowerBound(array, length, value):
    low = 0
    high = length
    while (low < high):
        mid = (low + high) // 2
        if (value <= array[mid]):
            high = mid
        else:
            low = mid + 1
    return low


def costCalculation(current, arr, n, pref, a, r, minimum):
    index = lowerBound(arr, len(arr), current)
    left = index * current - pref[index]
    right = (pref[n] - pref[index] - (n - index) * current)
    res = min(left, right)
    left -= res
    right -= res
    total = res * minimum
    total += left * a
    total += right * r
    return total


def solve(arr, n, a, r, m):
    arr .sort()
    minimum = min(a + r, m)
    pref = [0] * (n + 1)
    for i in range(n):
        pref[i + 1] = pref[i] + arr[i]
    ans = 10000
    for i in range(n):
        ans = min(ans, costCalculation(arr[i], arr, n, pref, a, r, minimum))
    ans = min(ans, costCalculation(pref[n] // n, arr, n, pref, a, r, minimum))
    ans = min(
        ans,
        costCalculation(
            pref[n] //
            n +
            1,
            arr,
            n,
            pref,
            a,
            r,
            minimum))
    print(ans)


if __name__ == "__main__":
    arr = [5, 5, 3, 6, 5]
    A = 1
    R = 2
    M = 4
    size = len(arr)
    solve(arr, size, A, R, M)

# Expected output:
4
# count of integers up to n which represent a binary number | python3 program to count the number of integers upto n which are of the form of binary representations ; function to return the count ; if the current last digit is 1 ; add 2 ^ ( ctr - 1 ) possible integers to the answer ; if the current digit exceeds 1 ; set answer as 2 ^ ctr - 1 as all possible binary integers with ctr number of digits can be obtained ; 

from math import *


def countBinaries(N):
    ctr = 1
    ans = 0
    while (N > 0):
        if (N % 10 == 1):
            ans += pow(2, ctr - 1)
        elif (N % 10 > 1):
            ans = pow(2, ctr) - 1
        ctr += 1
        N //= 10
    return ans


if __name__ == '__main__':
    N = 20
    print(int(countBinaries(N)))

# Expected output:
3
# count of integers up to n which represent a binary number | function to return the count ; precompute and store the powers of 2 ; if the current last digit is 1 ; add 2 ^ ( ctr - 1 ) possible integers to the answer ; if the current digit exceeds 1 ; set answer as 2 ^ ctr - 1 as all possible binary integers with ctr number of digits can be obtained ; 
def countBinaries(N):
    powersOfTwo = [0] * 11
    powersOfTwo[0] = 1
    for i in range(1, 11):
        powersOfTwo[i] = powersOfTwo[i - 1] * 2
    ctr = 1
    ans = 0
    while (N > 0):
        if (N % 10 == 1):
            ans += powersOfTwo[ctr - 1]
        elif (N % 10 > 1):
            ans = powersOfTwo[ctr] - 1
        ctr += 1
        N = N // 10
    return ans


N = 20
print(countBinaries(N))

# Expected output:
3
# find the sum of the first nth centered hexadecagonal number | centered_hexadecagonal number function ; formula to calculate nth centered_hexadecagonal number & return it into main function . ; function to find the sum of the first n centered hexadecagonal number ; variable to store the sum ; loop to iterate through the first n numbers ; find the sum ; 
def Centered_Hexadecagonal_num(n):
    return (8 * n * n - 8 * n + 1)


def sum_Centered_Hexadecagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_Hexadecagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_Hexadecagonal_num(n))

# Expected output:
325
# find the sum of the first n centered heptagonal number | function to find n - th centered heptagonal number ; formula to calculate nth centered heptagonal number ; function to find the sum of the first n centered heptagonal numbers ; variable to store the sum ; iterate through the range 1 to n ; 
def center_heptagonal_num(n):
    return (7 * n * n - 7 * n + 2) // 2


def sum_center_heptagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += center_heptagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_center_heptagonal_num(n))

# Expected output:
145
# find the sum of the first n centered dodecagonal number | function to find the n - th centered dodecagonal number ; formula to calculate nth centered_dodecagonal number ; function to find the sum of the first n centered_dodecagonal number ; variable to store the sum ; iterating from 1 to n ; finding the sum ; 
def Centered_Dodecagonal_num(n):
    return 6 * n * (n - 1) + 1


def sum_Centered_Dodecagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_Dodecagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_Dodecagonal_num(n))

# Expected output:
245
# find the sum of the first n centered octagonal number | function to find n - th centered octagonal number ; formula to calculate nth centered octagonal number ; function to find the sum of the first n centered octagonal numbers ; variable to store the sum ; iterating through the first n numbers ; 
def center_Octagonal_num(n):
    return (4 * n * n - 4 * n + 1)


def sum_center_Octagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += center_Octagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_center_Octagonal_num(n))

# Expected output:
165
# find the sum of the first n centered decagonal numbers | function to find the n - th centred decagonal number ; formula to calculate nth centered_decagonal number & return it into main function . ; function to find the sum of the first n centered decagonal numbers ; variable to store the sum ; iterating through the range ; 
def Centered_decagonal_num(n):
    return (5 * n * n - 5 * n + 1)


def sum_Centered_decagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_decagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_decagonal_num(n))

# Expected output:
205
# find the sum of the first n centered octadecagonal numbers | function to find the n - th centered octadecagonal number ; formula to calculate nth centered octadecagonal number ; function to find the sum of the first n centered octadecagonal numbers ; variable to store the sum ; iterating through the range 1 to n ; 
def center_octadecagon_num(n):
    return (9 * n * n - 9 * n + 1)


def sum_center_octadecagon_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += center_octadecagon_num(i)
    return summ


if __name__ == '__main__':
    n = 3
    print(sum_center_octadecagon_num(n))

# Expected output:
75
# find the sum of the first nth centered pentadecagonal number | function to find the centered_pentadecagonal number ; formula to calculate n - th centered_pentadecagonal number ; function to find the sum of the first n centered_pentadecagonal numbers ; variable to store the sum ; 
def Centered_Pentadecagonal_num(n):
    return (15 * n * n - 15 * n + 2) // 2


def sum_Centered_Pentadecagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_Pentadecagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_Pentadecagonal_num(n))

# Expected output:
305
# program to check if n is a octagonal number | python3 program for the above approach ; function to check if n is a octagonal number ; condition to check if the number is a octagonal number ; 

from math import sqrt


def isoctagonal(N):
    n = (2 + sqrt(12 * N + 4)) / 6
    return (n - int(n)) == 0


if __name__ == "__main__":
    N = 8
    if (isoctagonal(N)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# program to check if n is a pentadecagonal number | python3 program for the above approach ; function to check if n is a pentadecagon number ; condition to check if the number is a pentadecagon number ; 

from math import sqrt


def isPentadecagon(N):
    n = (11 + sqrt(104 * N + 121)) / 26
    return (n - int(n) == 0)


if __name__ == "__main__":
    N = 15
    if (isPentadecagon(N)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# program to check if n is a tetradecagonal number | python3 program for the above approach ; function to check if n is a tetradecagonal number ; condition to check if the number is a tetradecagonal number ; 

import math


def istetradecagonal(N):
    n = (10 + math .sqrt(96 * N + 100)) / 24
    if (n - int(n)) == 0:
        return True
    return False


N = 11
if (istetradecagonal(N)):
    print("Yes")
else:
    print("No")

# Expected output:
No
# find the sum of the first nth icosagonal numbers | function to calculate the n - th icosagonal number ; formula to calculate nth icosagonal number & return it ; function to find the sum of the first n icosagonal numbers ; variable to store the sum ; loop to iterate through the first n values and find the sum of first n icosagonal numbers ; function to get the icosagonal_num ; 
def Icosagonal_num(n):
    return (18 * n * n - 16 * n) // 2


def sum_Icosagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Icosagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Icosagonal_num(n))

# Expected output:
375
# find the sum of the first n centered pentagonal number | function to find the centered_pentagonal number ; formula to calculate nth centered_pentagonal number & return it into main function . ; function to find the sum of the first n centered_pentagonal numbers ; to get the sum ; function to get the centered_pentagonal_num ; 
def Centered_Pentagonal_num(n):
    return (5 * n * n - 5 * n + 2) // 2


def sum_Centered_Pentagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_Pentagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_Pentagonal_num(n))

# Expected output:
105
# find the sum of the first nth centered tridecagonal numbers | function to calculate the n - th centered tridecagonal number ; formula to calculate nth centered tridecagonal number & return it ; function to find the sum of the first n centered tridecagonal numbers ; variable to store the sum ; loop to iterate and find the sum of first n centered tridecagonal numbers ; 
def Centered_tridecagonal_num(n):
    return (13 * n * (n - 1) + 2) // 2


def sum_Centered_tridecagonal_num(n):
    summ = 0
    for i in range(1, n + 1):
        summ += Centered_tridecagonal_num(i)
    return summ


if __name__ == '__main__':
    n = 5
    print(sum_Centered_tridecagonal_num(n))

# Expected output:
265
# program to check if n is a concentric hexagonal number | python3 program to check if n is a concentric hexagonal number ; function to check if the number is a concentric hexagonal number ; condition to check if the number is a concentric hexagonal number ; 

import math


def isConcentrichexagonal(N):
    n = math .sqrt((2 * N) / 3)
    return (n - int(n)) == 0


N = 6
if isConcentrichexagonal(N):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# count sexy prime pairs in the given array | a utility function that find the prime numbers till n ; resize the prime number ; loop till sqrt ( n ) to find prime numbers and make their multiple false in the bool array prime ; function that returns the count of spp ( sexy prime pair ) pairs ; find the maximum element in the given array arr [ ] ; function to calculate the prime numbers till n ; to store the count of pairs ; to store the frequency of element in the array arr [ ] ; sort before traversing the array ; traverse the array and find the pairs with spp ( sexy prime pair ) s ; if current element is prime , then check for ( current element + 6 ) ; return the count of pairs ; 
def computePrime(N):
    Prime = [True] * (N + 1)
    Prime[0] = False
    Prime[1] = False
    i = 2
    while i * i <= N:
        if (Prime[i]):
            for j in range(i * i, N, i):
                Prime[j] = False
        i += 1
    return Prime


def countSexyPairs(arr, n):
    maxE = max(arr)
    Prime = computePrime(maxE)
    count = 0
    freq = [0] * (maxE + 6)
    for i in range(n):
        freq[arr[i]] += 1
    arr .sort()
    for i in range(n):
        if (Prime[arr[i]]):
            if ((arr[i] + 6) <= (maxE) and freq[arr[i] + 6]
                    > 0 and Prime[arr[i] + 6]):
                count += 1
    return count


if __name__ == "__main__":
    arr = [6, 7, 5, 11, 13]
    n = len(arr)
    print(countSexyPairs(arr, n))

# Expected output:
2
# count of ways to write n as a sum of three numbers | function to find the number of ways ; check if number is less than 2 ; calculate the sum ; 
def countWays(N):
    if (N <= 2):
        print("-1")
    else:
        ans = (N - 1) * (N - 2) / 2
    print(ans)


if __name__ == '__main__':
    N = 5
    countWays(N)

# Expected output:
6.0
# logarithm tricks for competitive programming | python3 implementation to check that a integer is a power of two ; function to check if the number is a power of two ; 

import math


def isPowerOfTwo(n):
    return (
        math .ceil(
            math .log(n) //
            math .log(2)) == math .floor(
            math .log(n) //
            math .log(2)))


if __name__ == '__main__':
    N = 8
    if isPowerOfTwo(N):
        print('Yes')
    else:
        print('No')

# Expected output:
Yes
# count of pairs having bit size at most x and bitwise or equal to x | function to count the pairs ; initializing answer with 1 ; iterating through bits of x ; check if bit is 1 ; multiplying ans by 3 if bit is 1 ; 
def count_pairs(x):
    ans = 1
    while (x > 0):
        if (x % 2 == 1):
            ans = ans * 3
        x = x // 2
    return ans


if __name__ == '__main__':
    X = 6
    print(count_pairs(X))

# Expected output:
9
# find the kth number which is not divisible by n | python3 implementation for above approach ; function to find the kth not divisible by n ; lowest possible value ; highest possible value ; to store the kth non divisible number of n ; using binary search ; calculating mid value ; sol would have the value by subtracting all multiples of n till mid ; check if sol is greater than k ; h should be reduced to find minimum possible value ; check if sol is less than k then l will be mid + 1 ; check if sol is equal to k ; ans will be mid ; h would be reduced to find any more possible value ; print the answer ; 

import sys


def kthNonDivisible(N, K):
    L = 1
    H = sys .maxsize
    ans = 0
    while (L <= H):
        mid = (L + H) // 2
        sol = mid - mid // N
        if (sol > K):
            H = mid - 1
        elif (sol < K):
            L = mid + 1
        else:
            ans = mid
            H = mid - 1
    print(ans)


N = 3
K = 7
kthNonDivisible(N, K)

# Expected output:
10
# print any pair of integers with sum of gcd and lcm equals to n | function to print the required pair ; print the pair ; 
def printPair(n):
    print("1", end=" ")
    print(n - 1)


n = 14
printPair(n)

# Expected output:
1 13
# find the length of largest subarray in which all elements are autobiographical numbers | function to check number is autobiographical ; convert integer to string ; iterate for every digit to check for their total count ; check occurrence of every number and count them ; check if any position mismatches with total count them return with false else continue with loop ; function to return the length of the largest subarray whose every element is a autobiographical number ; utility function which checks every element of array for autobiographical number ; check if element arr [ i ] is an autobiographical number ; increment the current length ; update max_length value ; return the final result ; 
def isAutoBiographyNum(number):
    count = 0
    NUM = str(number)
    size = len(NUM)
    for i in range(size):
        position = ord(NUM[i]) - ord('0')
        count = 0
        for j in range(size):
            digit = ord(NUM[j]) - ord('0')
            if (digit == i):
                count += 1
        if (position != count):
            return False
    return True


def checkArray(arr, n):
    current_length = 0
    max_length = 0
    for i in range(n):
        if (isAutoBiographyNum(arr[i])):
            current_length += 1
        else:
            current_length = 0
        max_length = max(max_length, current_length)
    return max_length


if __name__ == "__main__":
    arr = [21200, 1, 1303, 1210, 2020]
    n = len(arr)
    print(checkArray(arr, n))

# Expected output:
2
# find prime adam integers in the given range [ l , r ] | python3 program to find all prime adam numbers in the given range ; reversing a number by taking remainder at a time ; function to check if a number is a prime or not ; iterating till the number ; checking for factors ; returning 1 if the there are no factors of the number other than 1 or itself ; function to check whether a number is an adam number or not ; reversing given number ; squaring given number ; squaring reversed number ; reversing the square of the reversed number ; checking if the square of the number and the square of its reverse are equal or not ; function to find all the prime adam numbers in the given range ; if the first number is greater than the second number , print invalid ; iterating through all the numbers in the given range ; checking for prime number ; checking for adam number ; 
def reverse(a):
    rev = 0
    while (a != 0):
        r = a % 10
        rev = rev * 10 + r
        a = a // 10
    return (rev)


def prime(a):
    k = 0
    for i in range(2, a):
        if (a % i == 0):
            k = 1
            break
    if (k == 1):
        return (0)
    else:
        return (1)


def adam(a):
    r1 = reverse(a)
    s1 = a * a
    s2 = r1 * r1
    r2 = reverse(s2)
    if (s1 == r2):
        return (1)
    else:
        return (0)


def find(m, n):
    if (m > n):
        print("INVALIDINPUT")
    else:
        c = 0
    for i in range(m, n):
        l = prime(i)
        k = adam(i)
        if ((l == 1) and (k == 1)):
            print(i, "	", end=" ")


L = 5
R = 100
find(L, R)

# Expected output:
11 	 13 	 31
# determine whether the given integer n is a peculiar number or not | function to get sum of digits of a number ; function to check if the number is peculiar ; store a duplicate of n ; 
def sumDig(n):
    s = 0
    while (n != 0):
        s = s + int(n % 10)
        n = int(n / 10)
    return s


def Pec(n):
    dup = n
    dig = sumDig(n)
    if (dig * 3 == dup):
        return "Yes"
    else:
        return "No"


n = 36
if Pec(n):
    print("Yes")
else:
    print("No")

# Expected output:
Yes