giulio98/xlcost-single-prompt huggingface dataset:
# ormiston prime pairs | function to check if the number is a prime or not ; corner cases ; this is checked so that we can skip middle five numbers in below loop ; function to update the frequency array such that freq [ i ] stores the frequency of digit i in n ; while there are digits left to process ; update the frequency of the current digit ; remove the last digit ; function that returns true if a and b are anagrams of each other ; to store the frequencies of the digits in a and b ; update the frequency of the digits in a ; update the frequency of the digits in b ; match the frequencies of the common digits ; if frequency differs for any digit then the numbers are not anagrams of each other ; returns true if n1 and n2 are ormiston primes ; 
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 = i + 6
    return True


TEN = 10


def updateFreq(n, freq):
    while (n):
        digit = n % TEN
        freq[digit] += 1
        n = n // TEN


def areAnagrams(a, b):
    freqA = [0] * TEN
    freqB = [0] * TEN
    updateFreq(a, freqA)
    updateFreq(b, freqB)
    for i in range(TEN):
        if (freqA[i] != freqB[i]):
            return False
    return True


def OrmistonPrime(n1, n2):
    return (isPrime(n1) and isPrime(n2) and areAnagrams(n1, n2))


n1, n2 = 1913, 1931
if (OrmistonPrime(n1, n2)):
    print("YES")
else:
    print("NO")

# Expected output:
YES
# decakismyriagon number | function to find the n - th decakismyriagon number ; 
def DecakismyriagonNum(N):
    return (99998 * N * N - 99996 * N) // 2


N = 3
print(DecakismyriagonNum(N))

# Expected output:
299997
# zygodrome number | function to check if n is an zygodrome number ; convert n to string ; adding a space at the beginning and end of the string ; traverse the string ; if any character is not same as prev and next then return false ; 
def iszygodromeNum(N):
    s = str(N)
    s = ' ' + s + ' '
    i = 1
    while i < len(s) - 1:
        if ((s[i] != s[i - 1]) and (s[i] != s[i + 1])):
            return False
        i += 1
    return True


if __name__ == '__main__':
    n = 1122
    if iszygodromeNum(n):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# loeschian number | python3 program for the above approach ; function to check if n is a loeschian number ; iterate [ 0 , sqrt ( n ) ] for x ; iterate [ 0 , sqrt ( n ) ] for y ; check the given criteria ; if no such pair found then return false ; 

import math


def isLoeschian(n):
    for x in range(1, (int)(math .sqrt(n)) + 1):
        for y in range(1, (int)(math .sqrt(n)) + 1):
            if (x * x + x * y + y * y == n):
                return True
    return False


N = 19
if (isLoeschian(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# program to print the series 2 , 15 , 41 , 80 , 132 , 197 … till n terms | function to print the series ; generate the ith term and ; 
def printSeries(N):
    ith_term = 0
    for i in range(1, N + 1):
        ith_term = (13 * i * (i - 1)) / 2 + 2
        print(int(ith_term), ", ", end="")


if __name__ == '__main__':
    N = 7
    printSeries(N)

# Expected output:
2 , 15 , 41 , 80 , 132 , 197 , 275 ,
# possible pairs forming a pythagorean triple with a given value | function to generate all possible pairs ; vector to store all the possible pairs ; checking all the possible pair in the range of [ 1 , c ) ; if the pair satisfies the condition push it in the vector ; 
def Pairs(C):
    ans = []
    for i in range(C):
        for j in range(i + 1, C):
            if ((i * i) + (j * j) == (C * C)):
                ans .append([i, j])
    return ans


if __name__ == "__main__":
    C = 13
    ans = Pairs(C)
    if (len(ans) == 0):
        print("No valid pair exist")
        exit()
    for i in range(len(ans)):
        print("(" + str(ans[i][0]) + ", " + str(ans[i][1]) + ")")

# Expected output:
(5, 12)
# how to calculate strike rate of a batsman | function to calculate strike rate of a batsman ; 
def strikerate(bowls, runs):
    z = (float(runs) / bowls) * 100
    return z


A = 264
B = 173
print(strikerate(B, A))

# Expected output:
152.60115606936415
# check if a number exists with x divisors out of which y are composite | python3 program to check if a number exists having exactly x positive divisors out of which y are composite divisors ; count the number of times 2 divides n ; check for all possible numbers that can divide it ; if n at the end is a prime number . ; function to check if any such number exists ; 

import math


def factorize(N):
    count = 0
    cnt = 0
    while ((N % 2) == 0):
        N = N // 2
        count += 1
    cnt = cnt + count
    sq = int(math .sqrt(N))
    for i in range(3, sq, 2):
        count = 0
        while (N % i == 0):
            count += 1
            N = N // i
        cnt = cnt + count
    if (N > 2):
        cnt = cnt + 1
    return cnt


def ifNumberExists(X, Y):
    C = X - Y - 1
    dsum = factorize(X)
    if (dsum >= C):
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    X = 6
    Y = 4
    ifNumberExists(X, Y)

# Expected output:
YES
# nearest prime number in the array of every array element | python3 program to find nearest prime number in the array for all array elements ; create a boolean array and set all entries it as false . a value in prime [ i ] will be true if i is not a prime , else false ; sieve of eratosthenes function ; update all multiples of i greater than or equal to the square of it numbers which are multiple of i and are less than i ^ 2 are already been marked . ; function to find nearest prime number for all elements ; compute and store all prime numbers up to maxm ; store the indices of all primes ; if no primes are present in the array ; store the current prime ; if the no further primes exist in the array ; for all indices less than that of the current prime ; if the current prime is nearer ; if the next prime is nearer ; make the next prime as the current ; 

maxi = 10000000
prime = [False] * (maxi)


def SieveOfEratosthenes(maxm):
    prime[0] = prime[1] = True
    for i in range(2, maxm + 1):
        if i * i > maxm:
            break
        if (not prime[i]):
            for j in range(i * i, maxm + 1, i):
                prime[j] = True


def print_nearest_prime(arr, N):
    maxm = max(arr)
    SieveOfEratosthenes(maxm)
    primes = []
    for i in range(N):
        if (not prime[arr[i]]):
            primes .append(i)
    if len(primes) == 0:
        for i in range(N):
            print(-1, end=" ")
        return
    curr = 0
    for i in range(N):
        if (curr == len(primes) - 1 or i <= primes[curr]):
            print(arr[primes[curr]], end=" ")
            continue
        if (abs(primes[curr] - i) < abs(primes[curr + 1] - i)):
            print(arr[primes[curr]], end=" ")
        else:
            curr += 1
            print(arr[primes[curr]], end=" ")


if __name__ == '__main__':
    N = 6
    arr = [8, 7, 12, 15, 3, 11]
    print_nearest_prime(arr, N)

# Expected output:
7 7 7 3 3 11
# find position of given term in a series formed with only digits 4 and 7 allowed | function to find the position of the number n ; to store the position of n ; iterate through all digit of n ; if current digit is 7 ; if current digit is 4 ; print the final position ; 
def findPosition(n):
    i = 0
    pos = 0
    while (n > 0):
        if (n % 10 == 7):
            pos = pos + pow(2, i + 1)
        else:
            pos = pos + pow(2, i)
        i += 1
        n = n // 10
    print(pos)


if __name__ == '__main__':
    N = 777
    findPosition(N)

# Expected output:
14
# average of cubes of first n natural numbers | function to find average of cubes ; storing sum of cubes of numbers in sum ; calculate sum of cubes ; return average ; 
def findAverageOfCube(n):
    sum = 0
    for i in range(1, n + 1):
        sum += i * i * i
    return round(sum / n, 6)


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

# Expected output:
12.0
# maximum number of 0 s that can be flipped such that array has no adjacent 1 s | maximum number of 0 s that can be replaced by 1 ; check for three consecutive 0 s ; flip the bit ; increase the count ; 
def canReplace(arr, n):
    i = 0
    count = 0
    while (i < n):
        if (arr[i] == 0 and (i == 0 or arr[i - 1] == 0)
                and (i == n - 1 or arr[i + 1] == 0)):
            arr[i] = 1
            count += 1
        i += 1
    return count


if __name__ == '__main__':
    arr = [1, 0, 0, 0, 1]
    print(canReplace(arr, 5))

# Expected output:
1
# sum of first n star numbers | function to find the sum of the first n star number ; variable to store the sum ; 
def sum_star_num(n):
    summ = 2 * n * (n + 1) * (n - 1) + n
    return summ


n = 3
print(sum_star_num(n))

# Expected output:
51
# count distinct median possible for an array using given ranges of elements | function to count the number of distinct medians of an array where each array elements are given by a range ; loop to store the starting and end range in the array ; condition to check if the length of the array is odd ; 
def solve(n, vec):
    a = []
    b = []
    for pr in vec:
        a .append(pr[0])
        b .append(pr[1])
    a .sort()
    b .sort()
    if ((n & 1)):
        left = a[n // 2]
        right = b[n // 2]
        ans = right - left + 1
    else:
        left = (a[n // 2] + a[n // 2 - 1])
        right = (b[n // 2] + b[n // 2 - 1])
        ans = right - left + 1
    print(ans)


if __name__ == "__main__":
    N = 3
    vec = [(100, 100), (10, 10000), (1, 1000000000)]
    solve(N, vec)

# Expected output:
9991
# count of pairs from array with sum equal to twice their bitwise and | python3 implementation to find the pairs with equal sum and twice the bitwise and of the pairs ; map to store the occurrence of elements of array ; function to find the pairs with equal sum and twice the bitwise and of the pairs ; loop to find the frequency of elements of array ; function to find the count such pairs in the array ; if an element occurs more than once then the answer will by incremented by nc2 times ; 

from collections import defaultdict
mp = defaultdict(int)


def find_pairs(arr, n):
    ans = 0
    for i in range(n):
        mp[arr[i]] += 1
    for i in mp .values():
        count = i
        if (count > 1):
            ans += ((count * (count - 1)) // 2)
    return ans


if __name__ == "__main__":
    arr = [1, 2, 3, 3, 4, 5, 5, 7, 8]
    arr_size = len(arr)
    print(find_pairs(arr, arr_size))

# Expected output:
2
# 360 | function to find the nth 360 - gon number ; 
def gonNum360(n):
    return (358 * n * n - 356 * n) // 2


n = 3
print(gonNum360(n))

# Expected output:
1077
# 120 | function to find the nth 120 - gon number ; 
def gonNum120(n):
    return (118 * n * n - 116 * n) // 2


n = 3
print(gonNum120(n))

# Expected output:
357
# tetracontaoctagonal number | function to find the nth tetracontaoctagonal number ; 
def TetracontaoctagonalNum(n):
    return (46 * n * n - 44 * n) / 2


n = 3
print(TetracontaoctagonalNum(n))

# Expected output:
141.0
# 257 | function to find the nth 257 - gon number ; 
def gonNum257(n):
    return (255 * n * n - 253 * n) // 2


n = 3
print(gonNum257(n))

# Expected output:
768
# tetracontadigonal number | function to find the nth tetracontadigonal number ; 
def TetracontadigonalNum(n):
    return int((40 * n * n - 38 * n) / 2)


n = 3
print(TetracontadigonalNum(n))

# Expected output:
123
# index of smallest triangular number with n digits | python3 implementation of the above approach ; function to return index of smallest triangular no n digits ; 

import math


def findIndex(n):
    x = math .sqrt(2 * math .pow(10, (n - 1)))
    return round(x)


n = 3
print(findIndex(n))

# Expected output:
14
# program to find the lcm of two prime numbers | function to return the lcm of two prime numbers ; if the two numbers are equal then return any one of a and b ; else return product of the numbers ; 
def findLCMPrime(a, b):
    if (a == b):
        return a
    return a * b


if __name__ == "__main__":
    a = 3
    b = 5
    print(findLCMPrime(a, b))

# Expected output:
15
# smallest multiple of n with exactly n digits in its binary number representation | python3 program to find smallest multiple of n with exactly n digits in binary number system . ; function to find smallest multiple of n with exactly n digits in binary number representation . ; 

from math import ceil


def smallestNumber(N):
    print(N * ceil(pow(2, (N - 1)) / N))


N = 3
smallestNumber(N)

# Expected output:
6
# find the largest n digit multiple of n | python3 program to find largest multiple of n containing n digits ; function to find the largest n digit multiple of n ; 

from math import floor


def smallestNumber(N):
    print(N * floor((pow(10, N) - 1) / N))


if __name__ == '__main__':
    N = 2
    smallestNumber(N)

# Expected output:
98
# icosikaiheptagonal number | function to find the nth icosikaiheptagonal number ; 
def icosikaiheptagonalNum(n):
    return (25 * n * n - 23 * n) // 2


n = 3
print("3rd icosikaiheptagonal Number is ", icosikaiheptagonalNum(n))

# Expected output:
3rd icosikaiheptagonal Number is  78
# program to check if n is a triacontagonal number | python3 program to check whether a number is an triacontagonal number or not ; function to check whether a number is an triacontagonal number or not ; condition to check whether a number is an triacontagonal number or not ; 

import math


def istriacontagonal(N):
    n = (26 + math .sqrt(224 * N + 676)) // 56
    return (n - int(n)) == 0


i = 30
if (istriacontagonal(i)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# check whether one root of the quadratic equation is twice of other or not | function to find the required answer ; 
def checkSolution(a, b, c):
    if (2 * b * b == 9 * a * c):
        print("Yes")
    else:
        print("No")


a = 1
b = 3
c = 2
checkSolution(a, b, c)

# Expected output:
Yes
# parity of the given mathematical expression using given n numbers | python3 program to determine the parity of the given mathematical expression ; iterating through the given integers ; if any odd number is present , then s is even parity ; else , s is odd parity ; 
def getParity(n, A):
    for x in A:
        if (x & 1):
            print("Even")
            return
    print("Odd")


if __name__ == '__main__':
    N = 3
    A = [2, 3, 1]
    getParity(N, A)

# Expected output:
Even
# count of digits after concatenation of first n positive integers | python3 program to find the number of digits after concatenating the first n positive integers ; function to find the number of digits after concatenating the first n positive integers ; 

from math import log10, floor


def numberOfDigits(N):
    nod = floor(log10(N) + 1)
    toDecrease = (pow(10, nod) - 1) // 9
    print((N + 1) * nod - toDecrease)


if __name__ == '__main__':
    N = 13
    numberOfDigits(N)

# Expected output:
17
# length of maximum product subarray | function that returns the maximum length subarray having non zero product ; zeroindex list to store indexex of zero ; if zeroindex list is empty then maxlength is as size of array ; if zeroindex list is not empty ; first zero is on index 2 that means two numbers positive , before index 2 so as their product is positive to ; checking for other indexex ; if the difference is greater than maxlen then maxlen is updated ; to check the length of remaining array after last zeroindex ; 
def Maxlength(arr, N):
    zeroindex = []
    for i in range(N):
        if (arr[i] == 0):
            zeroindex .append(i)
    if (len(zeroindex) == 0):
        maxlen = N
    else:
        maxlen = zeroindex[0]
        for i in range(0, len(zeroindex) - 1):
            if (zeroindex[i + 1] - zeroindex[i] - 1 > maxlen):
                maxlen = zeroindex[i + 1] - zeroindex[i] - 1
        if (N - zeroindex[len(zeroindex) - 1] - 1 > maxlen):
            maxlen = N - zeroindex[len(zeroindex) - 1] - 1
    print(maxlen)


if __name__ == "__main__":
    N = 9
    arr = [7, 1, 0, 1, 2, 0, 9, 2, 1]
    Maxlength(arr, N)

# Expected output:
3
# check if sum of exactly k elements of the array can be odd or not | function returns true if it is possible to have odd sum ; counting number of odd and even elements ; 
def isPossible(arr, N, K):
    oddCount = 0
    evenCount = 0
    for i in range(N):
        if (arr[i] % 2 == 0):
            evenCount += 1
        else:
            oddCount += 1
    if (evenCount == N or (oddCount == N and K %
                           2 == 0) or (K == N and oddCount % 2 == 0)):
        return False
    else:
        return True


if __name__ == '__main__':
    arr = [1, 2, 3, 4, 5, 8]
    K = 5
    N = len(arr)
    if (isPossible(arr, N, K)):
        print("Possible")
    else:
        print("Not Possible")

# Expected output:
Possible
# find the last two digits of factorial of a given number | function to print the last two digits of n ! ; for n >= 10 , n ! % 100 will always be 0 ; calculating n ! % 100 ; 
def lastTwoDigits(N):
    if (N >= 10):
        print("00", end="")
        return
    fac = 1
    for i in range(1, N + 1):
        fac = (fac * i) % 100
    print(fac)


if __name__ == '__main__':
    N = 7
    lastTwoDigits(N)

# Expected output:
40
# product of n terms of a given geometric series | function to calculate product of geometric series ; return the final product with the above formula ; 
def productOfGP(a, r, n):
    return pow(a, n) * pow(r, n * (n - 1) // 2)


a = 1
r = 2
N = 4
print(productOfGP(a, r, N))

# Expected output:
64
# product of n terms of a given geometric series | python3 program for the above approach ; function to calculate product of n terms of geometric series ; find the product of first and the last term ; return the sqrt of the above expression to find the product ; 

import math


def productOfGP(a, r, n):
    an = a * pow(r, n - 1)
    return (math .sqrt(pow(a * an, n)))


a = 1
r = 2
N = 4
print(productOfGP(a, r, N))

# Expected output:
64.0
# find two numbers such that difference of their squares equal to n | python3 program to find two numbers with difference of their squares equal to n ; function to check and print the required two positive integers ; iterate till sqrt ( n ) to find factors of n ; check if x is one of the factors of n ; store the factor ; compute the other factor ; check if the two factors are of the same parity ; compute a and b ; if no pair exists ; 

from math import sqrt


def solve(n):
    for x in range(1, int(sqrt(n)) + 1):
        if (n % x == 0):
            small = x
            big = n // x
            if (small % 2 == big % 2):
                a = (small + big) // 2
                b = (big - small) // 2
                print(a, b)
                return
    print(-1)


if __name__ == "__main__":
    n = 7
    solve(n)

# Expected output:
4 3
# probability that an arbitrary positive divisor of 10 ^ x is an integral multiple of 10 ^ y | python3 program to find the probability of an arbitrary positive divisor of xth power of 10 to be a multiple of yth power of 10 ; function to calculate and print the required probability ; count of potential divisors of x - th power of 10 which are also multiples of y - th power of 10 ; count of divisors of x - th power of 10 ; calculate gcd ; print the reduced fraction probability ; 

from math import *


def prob(x, y):
    num = abs(x - y + 1) * abs(x - y + 1)
    den = (x + 1) * (x + 1)
    gcd1 = gcd(num, den)
    print(num // gcd1, end="")
    print("/", end="")
    print(den // gcd1)


if __name__ == '__main__':
    X = 2
    Y = 1
    prob(X, Y)

# Expected output:
4/9
# program to check if n is a chiliagon number | python3 for the above approach ; function to check that if n is chiliagon number or not ; condition to check if n is a chiliagon number ; 

import math


def is_Chiliagon(N):
    n = (996 + math .sqrt(7984 * N + 992016)) // 1996
    return (n - int(n)) == 0


N = 1000
if (is_Chiliagon(N)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# count of common subarrays in two different permutations of 1 to n | python3 implementation of above approach ; initialising map for index mapping ; mapping elements of a ; modify elements of b according to map ; changing b [ i ] as the index of b [ i ] in a ; count of common subarrays ; traversing array b ; while consecutive elements are found , we increment k ; add number of subarrays with length k to total count ; 
def commonSubarrays(A, B, N):
    Map = [0 for i in range(N + 1)]
    for i in range(N):
        Map[A[i]] = i
    for i in range(N):
        B[i] = Map[B[i]]
    count = 0
    i = 0
    while i < N:
        K = 1
        i += 1
        while i < N and B[i] == B[i - 1] + 1:
            i += 1
            K += 1
        count = count + ((K) * (K + 1)) // 2
    return count


N = 3
A = [1, 2, 3]
B = [2, 3, 1]
print(commonSubarrays(A, B, N))
N = 5
A = [1, 2, 3, 4, 5]
B = [2, 3, 1, 4, 5]
print(commonSubarrays(A, B, N))

# Expected output:
4
7
# represent n as sum of k even or k odd numbers with repetitions allowed | function to find the array with all the even / odd elements ; first let 's check  kth is odd or even ; if last element is also an odd number then we can choose odd elements for our answer ; add 1 in the array ( k - 1 ) times ; add last odd element ; if array of even elements would be the answer then k - 1 elements would be 2 ; if last element is also an even number then we can choose even elements for our answer ; add 2 in the array ( k - 1 ) times ; add last even element ; printing the array ; 
def getArrayOfSizeK(n, k):
    ans = []
    odd = n - ((k - 1) * 1)
    if (odd > 0 and odd % 2 != 0):
        for i in range(k - 1):
            ans .append(1)
        ans .append(odd)
    even = n - ((k - 1) * 2)
    if (even > 0 and even % 2 == 0 and len(ans) == 0):
        for i in range(k - 1):
            ans .append(2)
        ans .append(even)
    if (len(ans) > 0):
        for i in range(k):
            print(ans[i], end=" ")
    else:
        print("NO")


if __name__ == "__main__":
    n, k = 10, 3
    getArrayOfSizeK(n, k)

# Expected output:
2 2 6
# check whether a given number n is a nude number or not | check if all digits of num divide num ; array to store all digits of the given number ; if any of the condition is true for any digit then n is not a nude number ; 
def checkDivisbility(num):
    digit = 0
    N = num
    while (num != 0):
        digit = num % 10
        num = num // 10
        if (digit == 0 or N % digit != 0):
            return False
    return True


if __name__ == '__main__':
    N = 128
    result = checkDivisbility(N)
    if (result):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes