giulio98/xlcost-single-prompt huggingface dataset:
# program to print pentatope numbers upto nth term | function to generate nth tetrahedral number ; function to print pentatope number series upto nth term . ; initialize prev as 0. it store the sum of all previously generated pentatope numbers ; loop to print pentatope series ; find ith tetrahedral number ; add ith tetrahedral number to sum of all previously generated tetrahedral number to get ith pentatope number ; update sum of all previously generated tetrahedral number ; 
def findTetrahedralNumber(n):
    return (int((n * (n + 1) * (n + 2)) / 6))


def printSeries(n):
    prev = 0
    for i in range(1, n + 1):
        curr = findTetrahedralNumber(i)
        curr = curr + prev
        print(curr, end=' ')
        prev = curr


n = 10
printSeries(n)

# Expected output:
1 5 15 35 70 126 210 330 495 715
# program to print pentatope numbers upto nth term | function to print pentatope series up to nth term ; loop to print pentatope number series ; calculate and print ith pentatope number ; 
def printSeries(n):
    for i in range(1, n + 1):
        num = int(i * (i + 1) * (i + 2) * (i + 3) // 24)
        print(num, end=' ')


n = 10
printSeries(n)

# Expected output:
1 5 15 35 70 126 210 330 495 715
# program to print tetrahedral numbers upto nth term | function to generate nth triangular number ; function to print tetrahedral number series up to n ; initialize prev as 0. it stores the sum of all previously generated triangular number ; loop to print series ; find ith triangular number ; add ith triangular number to sum of all previously generated triangular number to get ith tetrahedral number ; update sum of all previously generated triangular number ; 
def findTriangularNumber(n):
    return (n * (n + 1)) / 2


def printSeries(n):
    prev = 0
    for i in range(1, n + 1):
        curr = findTriangularNumber(i)
        curr = int(curr + prev)
        print(curr, end=' ')
        prev = curr


n = 10
printSeries(n)

# Expected output:
1 4 10 20 35 56 84 120 165 220
# program to print tetrahedral numbers upto nth term | function to print tetrahedral series up to n ; loop to print series ; calculate and print ith tetrahedral number ; 
def printSeries(n):
    for i in range(1, n + 1):
        num = i * (i + 1) * (i + 2) // 6
        print(num, end=' ')


n = 10
printSeries(n)

# Expected output:
1 4 10 20 35 56 84 120 165 220
# number of odd and even results for every value of x in range [ min , max ] after performing n steps | function that prints the number of odd and even results ; if constant at layer i is even , beven is true , otherwise false . if the coefficient of x at layer i is even , aeven is true , otherwise false . ; if any of the coefficients at any layer is found to be even , then the product of all the coefficients will always be even . ; checking whether the constant added after all layers is even or odd . ; assuming input x is even . ; assuming input x is odd . ; displaying the counts . ; 
def count_even_odd(min, max, steps):
    beven = True
    aeven = False
    n = 2
    for i in range(0, n):
        a = steps[i][0]
        b = steps[i][1]
        if (not (aeven or a & 1)):
            aeven = True
        if (beven):
            if (b & 1):
                beven = False
        elif (not (a & 1)):
            if (not (b & 1)):
                beven = True
        else:
            if (b & 1):
                beven = True
    if (beven):
        even = (int(max / 2) - int((min - 1) / 2))
        odd = 0
    else:
        even = (int(max / 2) - int((min - 1) / 2))
        odd = 0
    if (not (beven ^ aeven)):
        even += (max - min + 1 - int(max / 2) + int((min - 1) / 2))
    else:
        odd += (max - min + 1 - int(max / 2) + int((min - 1) / 2))
    print("even = ", even, ", odd = ", odd, sep="")


min = 1
max = 4
steps = [[1, 2], [3, 4]]
count_even_odd(min, max, steps)

# Expected output:
even = 2, odd = 2
# maximum number of ones in a n * n matrix with 
def getMaxOnes(n, x):
    zeroes = (int)(n / x)
    zeroes = zeroes * zeroes
    total = n * n
    ans = total - zeroes
    return ans


n = 5
x = 2
print(getMaxOnes(n, x))

# Expected output:
21
# minimum operations required to make all the elements distinct in an array | function that returns minimum number of changes ; hash - table to store frequency ; increase the frequency of elements ; traverse in the map to sum up the ( occurrences - 1 ) of duplicate elements ; 
def minimumOperations(a, n):
    mp = dict()
    for i in range(n):
        if a[i] in mp .keys():
            mp[a[i]] += 1
        else:
            mp[a[i]] = 1
    count = 0
    for it in mp:
        if (mp[it] > 1):
            count += mp[it] - 1
    return count


a = [2, 1, 2, 3, 3, 4, 3]
n = len(a)
print(minimumOperations(a, n))

# Expected output:
3
# check if a m | python 3 program to check if m - th fibonacci divides n - th fibonacci ; exceptional case for f ( 2 ) ; if none of the above cases , hence not divisible ; 
def check(n, m):
    if (n == 2 or m == 2 or n % m == 0):
        print("Yes")
    else:
        print("No")


m = 3
n = 9
check(n, m)

# Expected output:
Yes
# minimum number of mails required to distribute all the questions | python3 code to find the minimum number of mails ; function returns the min no of mails required ; using the formula derived above ; no of questions ; no of students ; maximum no of questions a mail can hold ; 

import math


def MinimumMail(n, k, x):
    m = ((n - 1) + int(math .ceil((n - 1) * 1.0 / x) *
         (n - 1) + math .ceil(n * 1.0 / x) * (k - n)))
    return m


N = 4
K = 9
X = 2
print(MinimumMail(N, K, X))

# Expected output:
19
# program to find the area of an ellipse | function to find area of an ellipse . ; formula to find the area of an ellipse . ; display the result ; 
def findArea(a, b):
    Area = 3.142 * a * b
    print("Area:", round(Area, 2))


a = 5
b = 4
findArea(a, b)

# Expected output:
Area: 62.84
# compute power of power k times % m | python3 program for computing x ^ x ^ x ^ x . . % m ; function to compute the given value ; compute power k times ; 

import math


def calculate(x, k, m):
    result = x
    k = k - 1
    while (k):
        result = math .pow(result, x)
        if (result > m):
            result = result % m
        k = k - 1
    return int(result)


x = 5
k = 2
m = 3
print(calculate(x, k, m))

# Expected output:
2
# recursive program to check if number is palindrome or not | recursive function that returns the reverse of digits ; base case ; stores the reverse of a number ; 
def rev(n, temp):
    if (n == 0):
        return temp
    temp = (temp * 10) + (n % 10)
    return rev(n / 10, temp)


n = 121
temp = rev(n, 0)
if (temp != n):
    print("yes")
else:
    print("no")

# Expected output:
yes
# program to find greater value between a ^ n and b ^ n | python3 code for finding greater between the a ^ n and b ^ n ; function to find the greater value ; if n is even ; 

import math


def findGreater(a, b, n):
    if ((n & 1) > 0):
        a = abs(a)
        b = abs(b)
    if (a == b):
        print("a^n is equal to b^n")
    elif (a > b):
        print("a^n is greater than b^n")
    else:
        print("b^n is greater than a^n")


a = 12
b = 24
n = 5
findGreater(a, b, n)

# Expected output:
b^n is greater than a^n
# print first n fibonacci numbers using direct formula | python3 code to print fibonacci numbers till n using direct formula . ; function to calculate fibonacci using recurrence relation formula ; using direct formula ; 

import math


def fibonacci(n):
    for i in range(n):
        fib = ((pow((1 + math .sqrt(5)), i) -
               pow((1 - math .sqrt(5)), i)) / (pow(2, i) * math .sqrt(5)))
        print(int(fib), end=" ")


n = 8
fibonacci(n)

# Expected output:
0 1 1 2 3 5 8 13
# centered hexadecagonal number | centered hexadecagonal function ; formula to calculate nth centered hexadecagonal number ; 
def center_hexadecagonal_num(n):
    return 8 * n * n - 8 * n + 1


if __name__ == '__main__':
    n = 2
    print(n, "nd centered hexadecagonal " +
          "number : ", center_hexadecagonal_num(n))
    n = 12
    print(n, "th centered hexadecagonal " +
          "number : ", center_hexadecagonal_num(n))

# Expected output:
2 nd centered hexadecagonal number :  17
12 th centered hexadecagonal number :  1057
# check if the n | python3 program to check if the nth is odd or even in a sequence where each term is sum of previous two term ; return if the nth term is even or odd . ; return true if odd ; 

MAX = 100


def findNature(a, b, n):
    seq = [0] * MAX
    seq[0] = a
    seq[1] = b
    for i in range(2, n + 1):
        seq[i] = seq[i - 1] + seq[i - 2]
    return (seq[n] & 1)


a = 2
b = 4
n = 3
if (findNature(a, b, n)):
    print("Odd")
else:
    print("Even")

# Expected output:
Even
# program to compare m ^ n and n ^ m | python3 program to compare which is greater m ^ n or n ^ m ; function to compare m ^ n and n ^ m ; m ^ n ; n ^ m ; 

import math


def check(m, n):
    RHS = m * math .log(n)
    LHS = n * math .log(m)
    if (LHS > RHS):
        print("m^n > n^m")
    elif (LHS < RHS):
        print("m^n < n^m")
    else:
        print("m^n = n^m")


m = 987654321
n = 123456987
check(m, n)

# Expected output:
m^n < n^m
# lcm of two large numbers | python3 program to find lcm of two large numbers ; function to calculate lcm of two large numbers ; convert string ' a ' and ' b ' into integer ; calculate multiplication of both integers ; calculate gcd of two integers ; calculate lcm using formula : lcm * gcd = x * y ; 

import math


def lcm(a, b):
    s = int(a)
    s1 = int(b)
    mul = s * s1
    gcd = math .gcd(s, s1)
    lcm = mul // gcd
    return lcm


if __name__ == '__main__':
    a = "36594652830916364940473625749407"
    b = "448507083624364748494746353648484939"
    print(lcm(a, b))

# Expected output:
443593541011902763984944550799004089258248037004507648321189937329
# find the gcd that lies in given range | return the greatest common divisor of two numbers ; return the gretest common divisor of a and b which lie in the given range . ; loop from 1 to sqrt ( gcd ( a , b ) . ; if i divides the gcd ( a , b ) , then find maximum of three numbers res , i and g / i ; 
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)


def maxDivisorRange(a, b, l, h):
    g = gcd(a, b)
    res = -1
    i = l
    while (i * i <= g and i <= h):
        if (g % i == 0):
            res = max(res, max(i, g / i))
        i += 1
    return int(res)


if __name__ == "__main__":
    a = 3
    b = 27
    l = 1
    h = 5
    print(maxDivisorRange(a, b, l, h))

# Expected output:
3
# number expressed as sum of five consecutive integers | function to check if a number can be expressed as sum of five consecutive integer . ; if n is 0 ; if n is positive , increment loop by 1. ; if n is negative , decrement loop by 1. ; running loop from 0 to n - 4 ; check if sum of five consecutive integer is equal to n . ; 
def checksum(n):
    if n == 0:
        print("-2 -1 0 1 2")
        return 0
    inc = 0
    if n > 0:
        inc = 1
    else:
        inc = -1
    for i in range(0, n - 3, inc):
        if i + i + 1 + i + 2 + i + 3 + i + 4 == n:
            print(i, " ", i + 1, " ", i + 2, " ", i + 3, " ", i + 4)
            return 0
    print("-1")


n = 15
checksum(n)

# Expected output:
1   2   3   4   5
# number expressed as sum of five consecutive integers | function to check if a number can be expressed as sum of five consecutive integers . ; if n is multiple of 5 ; else print " - 1" . ; 
def checksum(n):
    n = int(n)
    if n % 5 == 0:
        print(int(n / 5 - 2), " ", int(n / 5 - 1), " ",
              int(n / 5), " ", int(n / 5 + 1), " ", int(n / 5 + 2))
    else:
        print("-1")


n = 15
checksum(n)

# Expected output:
1   2   3   4   5
# number of transpositions in a permutation | python program to find the number of transpositions in a permutation ; this array stores which element goes to which position ; this function returns the size of a component cycle ; if it is already visited ; this functio returns the number of transpositions in the permutation ; initializing visited [ ] array ; building the goesto [ ] array ; 

N = 1000001
visited = [0] * N
goesTo = [0] * N


def dfs(i):
    if (visited[i] == 1):
        return 0
    visited[i] = 1
    x = dfs(goesTo[i])
    return (x + 1)


def noOfTranspositions(P, n):
    for i in range(1, n + 1):
        visited[i] = 0
    for i in range(n):
        goesTo[P[i]] = i + 1
    transpositions = 0
    for i in range(1, n + 1):
        if (visited[i] == 0):
            ans = dfs(i)
            transpositions += ans - 1
    return transpositions


if __name__ == "__main__":
    permutation = [5, 1, 4, 3, 2]
    n = len(permutation)
    print(noOfTranspositions(permutation, n))

# Expected output:
3
# n | function to find the nth term of series ; loop to add 4 th powers ; 
def sumOfSeries(n):
    ans = 0
    for i in range(1, n + 1):
        ans = ans + i * i * i * i
    return ans


n = 4
print(sumOfSeries(n))

# Expected output:
354
# number of unmarked integers in a special sieve | python3 program to determine the number of unmarked integers in a special sieve ; 
def countUnmarked(N):
    if (N % 2 == 0):
        return N / 2
    else:
        return N / 2 + 1


N = 4
print("Number of unmarked elements:", int(countUnmarked(N)))

# Expected output:
Number of unmarked elements: 2
# sum of series 1 * 1 ! + 2 * 2 ! + …… . . + n * n ! | python program to find sum of the series . ; function to calculate required series ; 
def factorial(n):
    res = 1
    for i in range(2, n + 1):
        res = res * i
    return res


def calculateSeries(n):
    return factorial(n + 1) - 1


n = 3
print(calculateSeries(n))

# Expected output:
23
# sum of series 1 * 1 * 2 ! + 2 * 2 * 3 ! + …… . . + n * n * ( n + 1 ) ! | python program to find sum of the series . ; function to calculate required series ; 

import math


def factorial(n):
    res = 1
    i = 2
    for i in (n + 1):
        res = res * i
    return res


def calculateSeries(n):
    return (2 + (n * n + n - 2) * math .factorial(n + 1))


n = 3
print(calculateSeries(n))

# Expected output:
242
# aspiring number | function to calculate sum of all proper divisors ; 1 is a proper divisor ; note that this loop runs till square root of n ; if divisors are equal , take only one of them ; otherwise take both ; calculate sum of all proper divisors only ; function to get last number of aliquot sequence . ; calculate next term from previous term ; returns true if n is perfect ; to store sum of divisors ; find all divisors and add them ; if sum of divisors is equal to n , then n is a perfect number ; returns true if n is aspiring else returns false ; checking condition for aspiring ; 
def getSum(n):
    sum = 0
    for i in range(1, int((n) ** (1 / 2)) + 1):
        if not n % i:
            if n // i == i:
                sum += i
            else:
                sum += i
                sum += (n // i)
    return sum - n


def getAliquot(n):

    s = set()
    s.add(n)
    next = 0

    while (n > 0):
        n = getSum(n)

        if n not in s:
            return n

        s.add(n)

    return 0


def isPerfect(n):
    sum = 1
    for i in range(2, int((n ** (1 / 2))) + 1):
        if not n % i:
            sum += (i + n // i)
    if sum == n and n != 1:
        return True

    return False


def isAspiring(n):
    alq = getAliquot(n)
    if (isPerfect(alq) and not isPerfect(n)):
        return True
    else:
        return False


n = 25
if (isAspiring(n)):
    print("Aspiring")
else:
    print("Not Aspiring")

# Expected output:
Aspiring
# forming smallest array with given constraints | return the size of smallest array with given constraint . ; 
def minimumLength(x, y, z):
    return (1 + abs(x - y) + abs(y - z))


x = 3
y = 1
z = 2
print(minimumLength(x, y, z))

# Expected output:
4
# find the other | function to find the other - end point of diameter ; find end point for x coordinates ; find end point for y coordinates ; 
def endPointOfDiameterofCircle(x1, y1, c1, c2):
    print("x2 =", (2 * c1 - x1), end=" ")
    print("y2 =", (2 * c2 - y1))


x1 = -4
y1 = -1
c1 = 3
c2 = 5
endPointOfDiameterofCircle(x1, y1, c1, c2)

# Expected output:
x2 = 10 y2 = 11
# centered heptagonal number | function to find centered heptagonal number ; formula to calculate nth centered heptagonal number ; 
def centered_heptagonal_num(n):
    return (7 * n * n - 7 * n + 2) // 2


n = 5
print("%sth Centered heptagonal number : " % n, centered_heptagonal_num(n))

# Expected output:
5th Centered heptagonal number :  71
# sum of square | function to find sum of sum of square of first n natural number ; 
def findSum(n):
    summ = 0
    for i in range(1, n + 1):
        summ = (summ + ((i * (i + 1) * (2 * i + 1)) / 6))
    return summ


n = 3
print(int(findSum(n)))

# Expected output:
20
# check if a given matrix is hankel or not | python 3 program to check if given matrix is hankel matrix or not . ; function to check if given matrix is hankel matrix or not . ; for each row ; for each column ; checking if i + j is less than n ; checking if the element is equal to the corresponding diagonal constant ; checking if the element is equal to the corresponding diagonal constant ; 

N = 4


def checkHankelMatrix(n, m):
    for i in range(0, n):
        for j in range(0, n):
            if (i + j < n):
                if (m[i][j] != m[i + j][0]):
                    return False
            else:
                if (m[i][j] != m[i + j - n + 1][n - 1]):
                    return False
    return True


n = 4
m = [[1, 2, 3, 5, ], [2, 3, 5, 8, ], [3, 5, 8, 0, ], [5, 8, 0, 9]]
(print("Yes")if checkHankelMatrix(n, m)else print("No"))

# Expected output:
Yes
# check if a number can be expressed as power | set 2 ( using log ) | python3 program to find if a number can be expressed as x raised to power y . ; find log n in different bases and check if the value is an integer ; 

import math


def isPower(n):
    for x in range(2, int(math .sqrt(n)) + 1):
        f = math .log(n) / math .log(x)
        if ((f - int(f)) == 0.0):
            return True
    return False


for i in range(2, 100):
    if (isPower(i)):
        print(i, end=" ")

# Expected output:
4 8 9 16 25 27 32 36 49 64 81
# queries on sum of odd number digit sums of all the factors of a number | python program to answer queries on sum of sum of odd number digits of all the factors of a number ; finding sum of odd digit number in each integer . ; for each number ; using previous number sum , finding the current number num of odd digit also , adding last digit if it is odd . ; finding sum of sum of odd digit of all the factors of a number . ; for each possible factor ; adding the contribution . ; wrapper def ; 

N = 100
digitSum = [0] * N
factorDigitSum = [0] * N


def sumOddDigit():
    global N, digitSum, factorDigitSum
    for i in range(1, N):
        digitSum[i] = (digitSum[int(i / 10)] + int(i & 1) * (i % 10))


def sumFactor():
    global N, digitSum, factorDigitSum
    j = 0
    for i in range(1, N):
        j = i
        while (j < N):
            factorDigitSum[j] = (factorDigitSum[j] + digitSum[i])
            j = j + i


def wrapper(q, n):
    global N, digitSum, factorDigitSum
    for i in range(0, N):
        digitSum[i] = 0
        factorDigitSum[i] = 0
    sumOddDigit()
    sumFactor()
    for i in range(0, q):
        print("{} ".format(factorDigitSum[n[i]]), end="")


q = 2
n = [10, 36]
wrapper(q, n)

# Expected output:
7 18
# number of digits in the nth number made of given four digits | efficient function to calculate number of digits in the nth number constructed by using 6 , 1 , 4 and 9 as digits in the ascending order . ; number of digits increase after every i - th number where i increases in powers of 4. ; 
def number_of_digits(n):
    i = 4
    res = 1
    sum = 0
    while (True):
        i *= 4
        res += 1
        sum += i
        if (sum >= n):
            break
    return res


n = 21
print(number_of_digits(n))

# Expected output:
3
# print prime numbers from 1 to n in reverse order | python3 program to print all primes between 1 to n in reverse order using sieve of eratosthenes ; create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . a value in prime [ i ] will finally be false if i is not a prime , else true . ; if prime [ p ] is not changed , then it is a prime ; update all multiples of p ; print all prime numbers in reverse order ; static 
def Reverseorder(n):
    prime = [True] * (n + 1)

    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range((p * 2), (n + 1), p):
                prime[i] = False
        p += 1
    for p in range(n, 1, -1):
        if (prime[p]):
            print(p, end=" ")


N = 25
print("Prime number in reverse order")

if (N == 1):
    print("No prime no exist in this range")
else:
    Reverseorder(N)

# Expected output:
Prime number in reverse order
23 19 17 13 11 7 5 3 2
# vantieghems theorem for primality test | python3 code to verify vantieghem 's theorem ; check if above condition is satisfied ; product of previous powers of 2 ; 
def checkVantieghemsTheorem(limit):
    prod = 1
    for n in range(2, limit):
        if n == 2:
            print(2, "is prime")
        if (((prod - n) % ((1 << n) - 1)) == 0):
            print(n, "is prime")
        prod *= ((1 << n) - 1)


checkVantieghemsTheorem(10)

# Expected output:
2 is prime
3 is prime
5 is prime
7 is prime
# count numbers formed by given two digit with sum having given digits | python 3 program to count the number of numbers formed by digits a and b exactly of a length n such that the sum of the digits of the number thus formed is of digits a and b . ; function to check if sum of digits is made of a and b ; sum of digits is 0 ; if any of digits in sum is other than a and b ; calculate the modinverse v of a number in o ( log n ) ; q is quotient ; m is remainder now , process same as euclid 's algo ; update y and x ; make x positive ; function to pregenerate factorials ; function to pre calculate the modinverse of factorials ; calculates the modinverse of the last factorial ; precalculates the modinverse of all factorials by formulae ; function that returns the value of nci ; function that returns the count of numbers ; function call to pre - calculate the factorials and modinverse of factorials ; if a and b are same ; 

mod = 1000000007
N = 1000005
fact = [0] * N
invfact = [0] * N


def check(x, a, b):
    if (x == 0):
        return 0
    while (x):
        if (x % 10 != a and x % 10 != b):
            return 0
        x //= 10
    return 1


def modInverse(a, m):
    m0 = m
    y = 0
    x = 1
    if (m == 1):
        return 0
    while (a > 1):
        q = a // m
        t = m
        m = a % m
        a = t
        t = y
        y = x - q * y
        x = t
    if (x < 0):
        x += m0
    return x


def pregenFact():
    fact[0] = fact[1] = 1
    for i in range(1, 1000001):
        fact[i] = fact[i - 1] * i % mod


def pregenInverse():
    invfact[0] = invfact[1] = 1
    invfact[1000000] = modInverse(fact[1000000], mod)
    for i in range(999999, 0, -1):
        invfact[i] = ((invfact[i + 1] * (i + 1)) % mod)


def comb(big, small):
    return (fact[big] * invfact[small] % mod * invfact[big - small] % mod)


def count(a, b, n):
    pregenFact()
    pregenInverse()
    if (a == b):
        return (check(a * n, a, b))
    ans = 0
    for i in range(n + 1):
        if (check(i * a + (n - i) * b, a, b)):
            ans = (ans + comb(n, i)) % mod
    return ans


if __name__ == "__main__":
    a = 3
    b = 4
    n = 11028
    print(count(a, b, n))

# Expected output:
461668105
# finding n | function to generate a fixed number ; 
def magicOfSequence(N):
    sum = 0
    for i in range(1, N + 1):
        sum += (i * i * i + i * 2)
    return sum


N = 4
print(magicOfSequence(N))

# Expected output:
120