giulio98/xlcost-single-prompt huggingface dataset:
# central angle of a n sided regular polygon | function to calculate central angle of a polygon ; calculate the angle ; 
def calculate_angle(n):
    total_angle = 360
    return (total_angle // n)


N = 5
print(calculate_angle(N))

# Expected output:
72
# program to calculate the area of kite | function to return the area of kite ; use above formula ; 
def areaOfKite(d1, d2):
    area = (d1 * d2) / 2
    return area


d1 = 4
d2 = 6
print("Area of Kite = ", areaOfKite(d1, d2))

# Expected output:
Area of Kite =  12.0
# program to calculate the area of kite | python implementation of the approach ; function to return the area of the kite ; convert angle degree to radians ; use above formula ; 

import math
PI = 3.14159 / 180


def areaOfKite(a, b, angle):
    angle = angle * PI
    area = a * b * math .sin(angle)
    return area


a = 4
b = 7
angle = 78
print("Area of Kite = ", areaOfKite(a, b, angle))

# Expected output:
Area of Kite =  27.388126126418715
# program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given | python3 program to calculate angle on the circumference subtended by the chord when the central angle subtended by the chord is 
def angleOncirCumference(z):
    return (z / 2)


angle = 65
z = angleOncirCumference(angle)
print("The angle is", (z), "degrees")

# Expected output:
The angle is 32.5 degrees
# maximum and minimum value of a quadratic function | function to print the maximum and minimum values of the quadratic function ; calculate the value of second part ; print the values ; open upward parabola function ; open downward parabola function ; if a = 0 then it is not a quadratic function ; 
def PrintMaxMinValue(a, b, c):
    secondPart = c * 1.0 - (b * b / (4.0 * a))
    if (a > 0):
        print("Maxvalue =", "Infinity")
        print("Minvalue = ", secondPart)
    elif (a < 0):
        print("Maxvalue = ", secondPart)
        print("Minvalue =", "-Infinity")
    else:
        print("Not a quadratic function")


if __name__ == "__main__":
    a = -1
    b = 3
    c = -2
    PrintMaxMinValue(a, b, c)

# Expected output:
Maxvalue =  0.25
Minvalue = -Infinity
# percentage increase in the cylinder if the height is increased by given percentage but radius remains constant | python3 program to find percentage increase in the cylinder if the height is increased by given percentage but radius remains constant ; 
def newvol(x):
    print("percentage increase in the volume of the cylinder is ", x, "%")


x = 10.0
newvol(x)

# Expected output:
percentage increase in the volume of the cylinder is  10.0 %
# find the side of the squares which are inclined diagonally and lined in a row | python program to find side of the squares inclined and touch each other externally at vertices and are lined in a row and distance between the centers of first and last squares is given ; 
def radius(n, d):
    print("The side of each square is ", d / ((n - 1) * (2 ** (1 / 2))))


d = 42
n = 4
radius(n, d)

# Expected output:
The side of each square is  9.899494936611664
# program to calculate area of inner circle which passes through center of outer circle and touches its circumference | function calculate the area of the inner circle ; the radius cannot be negative ; area of the circle ; 
def innerCirclearea(radius):
    if (radius < 0):
        return -1
    r = radius / 2
    Area = (3.14 * pow(r, 2))
    return Area


if __name__ == "__main__":
    radius = 4
    print("Area of circle c2 =", innerCirclearea(radius))

# Expected output:
Area of circle c2 = 12.56
# angle subtended by the chord when the angle subtended by another chord of same length is given | python3 program to find the angle subtended at the center by the chord when the angle subtended at center by another chord of equal length is given ; 
def angleequichord(z):
    print("The angle subtended at", "the center is", z, "degrees")


if __name__ == "__main__":
    z = 48
    angleequichord(z)

# Expected output:
The angle subtended at the center is 48 degrees
# distance of chord from center when distance between center and another equal length chord is given | python 3 program to find the distance of chord from center when distance between center and another equal length chord is given ; 
def lengequichord(z):
    print("The distance between the", "chord and the center is", z)


if __name__ == "__main__":
    z = 48
    lengequichord(z)

# Expected output:
The distance between the chord and the center is 48
# length of the perpendicular bisector of the line joining the centers of two circles | python program to find the length of the perpendicular bisector of the line joining the centers of two circles in which one lies completely inside touching the bigger circle at one point ; 
def lengperpbisect(r1, r2):
    z = 2 * (((r1 * r1) - ((r1 - r2) * (r1 - r2) / 4))**(1 / 2))
    print("The length of the perpendicular bisector is ", z)


r1 = 5
r2 = 3
lengperpbisect(r1, r2)

# Expected output:
The length of the perpendicular bisector is  9.797958971132712
# length of the chord the circle if length of the another chord which is equally inclined through the diameter is given | python3 program to find the length of the chord of the circle if length of the other chord which is equally inclined through the diameter is given ; 
def lengchord(z):
    print("The length is ", end="")
    print(z)


z = 48
lengchord(z)

# Expected output:
The length is 48
# distance between centers of two intersecting circles if the radii and common chord length is given | python program to find the distance between centers of two intersecting circles if the radii and common chord length is given ; 
def distcenter(r1, r2, x):
    z = (((r1 * r1) - (x / 2 * x / 2))**(1 / 2)) + \
        (((r2 * r2) - (x / 2 * x / 2))**(1 / 2))
    print("distance between thecenters is ", end="")
    print(int(z))


r1 = 24
r2 = 37
x = 40
distcenter(r1, r2, x)

# Expected output:
distance between thecenters is 44
# exterior angle of a cyclic quadrilateral when the opposite interior angle is given | python program to find the exterior angle of a cyclic quadrilateral when the opposite interior angle is given ; 
def angleextcycquad(z):
    print("The exterior angle of the", end="")
    print("cyclic quadrilateral is ", end="")
    print(z, " degrees")


z = 48
angleextcycquad(z)

# Expected output:
The exterior angle of thecyclic quadrilateral is 48  degrees
# angle between a chord and a tangent when angle in the alternate segment is given | python3 program to find the angle between a chord and a tangent when angle in the alternate segment is given ; 
def anglechordtang(z):
    print("The angle between tangent", "and the chord is", z, "degrees")


z = 48
anglechordtang(z)

# Expected output:
The angle between tangent and the chord is 48 degrees
# print all perfect numbers from an array whose sum of digits is also a perfect number | function to check if a number is perfect number or not ; stores sum of proper divisors ; if sum of digits is equal to n , then it 's a perfect number ; otherwise , not a perfect number ; function to find the sum of digits of a number ; stores sum of digits ; return sum of digits ; function to count perfect numbers from an array whose sum of digits is also perfect ; traverse the array ; if number is perfect ; stores sum of digits of the number ; if that is also perfect number ; print that number ; 
def isPerfect(N):
    sumOfDivisors = 1
    for i in range(2, int(N / 2) + 1):
        if (N % i == 0):
            sumOfDivisors += i
    if (sumOfDivisors == N):
        return True
    else:
        return False


def sumOfDigits(N):
    sum = 0
    while (N != 0):
        sum += (N % 10)
        N = N // 10
    return sum


def countPerfectNumbers(arr, N):
    for i in range(N):
        if (isPerfect(arr[i])):
            sum = sumOfDigits(arr[i])
            if (isPerfect(sum)):
                print(arr[i], end=" ")


if __name__ == '__main__':
    arr = [3, 8, 12, 28, 6]
    N = len(arr)
    countPerfectNumbers(arr, N)

# Expected output:
6
# sum of bitwise and of the sum of all leaf and non | structure of a binary tree node ; helper function to allocate a new node with the given data and left and right pointers as none ; function to calculate the sum of bitwise and of the sum of all leaf nodes and non - leaf nodes for each level ; initialize a queue and append root to it ; store the required answer ; stores the sum of leaf nodes at the current level ; stores the sum of non - leaf nodes at the current level ; get the size of the queue ; iterate for all the nodes in the queue currently ; dequeue a node from queue ; check if the node is a leaf node ; if true , update the leaf node sum ; otherwise , update the non - leaf node sum ; enqueue left and right children of removed node ; update the answer ; return the answer ; 

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self .val = val
        self .left = left
        self .right = right


def findSum(root):
    que = [root]
    ans = 0
    while (len(que)):
        leaf = 0
        nonleaf = 0
        length = len(que)
        while length:
            temp = que .pop(0)
            if not temp .left and not temp .right:
                leaf += temp .val
            else:
                nonleaf += temp .val
            if temp .left:
                que .append(temp .left)
            if temp .right:
                que .append(temp .right)
            length -= 1
        ans += leaf & nonleaf
    return ans


root = TreeNode(5)
root .left = TreeNode(3)
root .right = TreeNode(9)
root .left .left = TreeNode(6)
root .left .right = TreeNode(4)
root .left .left .right = TreeNode(7)
print(findSum(root))

# Expected output:
5
# minimize replacements to make every element in an array exceed every element in another given array | function to find the minimize replacements to make every element in the array a [ ] strictly greater than every element in b [ ] or vice - versa ; store the final result ; create two arrays and initialize with 0 s ; traverse the array a [ ] ; increment prefix_a [ a [ i ] ] by 1 ; traverse the array b [ ] ; increment prefix_b [ b [ i ] ] by 1 ; calculate prefix sum of the array a [ ] ; calculate prefix sum of the array b [ ] ; iterate over the range [ 0 , 9 ] ; make every element in array a [ ] strictly greater than digit i and make every element in the array b [ ] less than digit i ; make every element in array b [ ] strictly greater than digit i and make every element in array a [ ] less than digit i ; print the answer ; 
def MinTime(a, b, n, m):
    ans = float('inf')
    prefix_a = [0] * 10
    prefix_b = [0] * 10
    for i in range(n):
        prefix_a[a[i]] += 1
    for i in range(m):
        prefix_b[b[i]] += 1
    for i in range(1, 10):
        prefix_a[i] += prefix_a[i - 1]
    for i in range(1, 10):
        prefix_b[i] += prefix_b[i - 1]
    for i in range(1, 10):
        ans = min(ans, prefix_a[i] + m - prefix_b[i])
        ans = min(ans, n - prefix_a[i] + prefix_b[i])
    print(ans)


A = [0, 0, 1, 3, 3]
B = [2, 0, 3]
N = len(A)
M = len(B)
MinTime(A, B, N, M)

# Expected output:
3
# fizz buzz implementation | set 2 | function to generate fizzbuzz sequence ; stores count of multiples of 3 and 5 respectively ; iterate from 1 to n ; increment count3 by 1 ; increment count5 by 1 ; initialize a boolean variable to check if none of the condition matches ; check if the value of count3 is equal to 3 ; reset count3 to 0 , and set flag as true ; check if the value of count5 is equal to 5 ; reset count5 to 0 , and set flag as true ; if none of the condition matches ; 
def fizzBuzz(N):
    count3 = 0
    count5 = 0
    for i in range(1, N + 1):
        count3 += 1
        count5 += 1
        flag = False
        if (count3 == 3):
            print("Fizz", end="")
            count3 = 0
            flag = True
        if (count5 == 5):
            print("Buzz", end="")
            count5 = 0
            flag = True
        if (not flag):
            print(i, end="")
        print(end=" ")


if __name__ == '__main__':
    N = 15
    fizzBuzz(N)

# Expected output:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
# check if diagonal elements of a matrix are prime or not | stores if a number is prime or not ; function to generate and store primes using sieve of eratosthenes ; set all numbers as prime memset ( prime , true , sizeof ( prime ) ) ; if p is a prime ; set all its multiples as non - prime ; function to check if all diagonal elements are prime or not ; stores if all diagonal elements are prime or not ; precompute primes ; traverse the range [ 0 , n - 1 ] ; check if numbers on the cross diagonal and main diagonal are primes or not ; if true , then pr " yes " ; otherwise , pr " no " ; 

prime = [True] * 1000005


def SieveOfEratosthenes(N):
    prime[0] = False
    prime[1] = False
    for p in range(2, N + 1):
        if p * p > N:
            break
        if (prime[p]):
            for i in range(p * p, N + 1, p):
                prime[i] = False


def checkElementsOnDiagonal(M, N):
    flag = 1
    SieveOfEratosthenes(1000000)
    for i in range(N):
        flag &= (prime[M[i][i]] and prime[M[i][N - 1 - i]])
    if (flag):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    M = [[1, 2, 3, 13], [5, 3, 7, 8], [1, 2, 3, 4], [5, 6, 7, 7]]
    N = len(M)
    checkElementsOnDiagonal(M, N)

# Expected output:
No
# generate a circular permutation with number of mismatching bits between pairs of adjacent elements exactly 1 | function to find the permutation of integers from a given range such that number of mismatching bits between pairs of adjacent elements is 1 ; initialize an arraylist to store the resultant permutation ; store the index of rotation ; iterate over the range [ 0 , n - 1 ] ; traverse all the array elements up to ( 2 ^ k ) - th index in reverse ; if current element is s ; check if s is zero ; rotate the array by index value to the left ; 
def circularPermutation(n, start):
    res = [0]
    ret = []
    index, add = -1, 1
    for k in range(n):
        add = 1 << k
        for i in range(len(res) - 1, -1, -1):
            if (res[i] + add == start):
                index = len(res)
            res .append(res[i] + add)
        add = 1 << k
    if (start == 0):
        return res
    while (len(ret) < len(res)):
        ret .append(res[index])
        index = (index + 1) % len(res)
    return ret


if __name__ == '__main__':
    N, S = 2, 3
    print(circularPermutation(N, S))

# Expected output:
[3, 2, 0, 1]
# count pairs from an array having equal sum and quotient | function to count all pairs ( i , j ) such that a [ i ] + [ j ] = a [ i ] / a [ j ] ; stores total count of pairs ; generate all possible pairs ; if a valid pair is found ; increment count ; return the final count ; 
def countPairs(a, n):
    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            if (a[j] != 0 and a[i] % a[j] == 0):
                if ((a[i] + a[j]) == (a[i] // a[j])):
                    count += 1
    return count


if __name__ == '__main__':
    arr = [-4, -3, 0, 2, 1]
    N = len(arr)
    print(countPairs(arr, N))

# Expected output:
1
# count pairs from an array having equal sum and quotient | function to find number of pairs with equal sum and quotient from a given array ; store the count of pairs ; stores frequencies ; traverse the array ; if y is neither 1 or 0 ; evaluate x ; increment count by frequency of x ; update map ; prthe final count ; 
def countPairs(a, n):
    count = 0
    mp = {}
    for i in range(n):
        y = a[i]
        if (y != 0 and y != 1):
            x = (((y * 1.0) // (1 - y)) * y)
            count += mp .get(x, 0)
        mp[y] = mp .get(y, 0) + 1
    return count


arr = [-4, -3, 0, 2, 1]
N = len(arr)
print(countPairs(arr, N))

# Expected output:
1
# queries to count numbers from a range which does not contain digit k in their decimal or octal representation | function to check if the given digit ' k ' is present in the decimal and octal representations of num or not ; stores if the digit exists or not ; iterate till nums is non - zero ; find the remainder ; if the remainder is k ; function to count the numbers in the range [ 1 , n ] such that it doesn ' t ▁ contain ▁ the ▁ digit ▁ ' k ' in its decimal and octal representation ; stores count of numbers in the range [ 0 , i ] that contains the digit ' k ' in its octal or decimal representation ; traverse the range [ 0 , 1e6 + 5 ] ; check if i contains the digit ' k ' in its decimal or octal representation ; update pref [ i ] ; print the answer of queries ; 
def contains(num, K, base):
    isThere = 0
    while (num):
        remainder = num % base
        if (remainder == K):
            isThere = 1
        num //= base
    return isThere


def count(n, k, v):
    pref = [0] * 1000005
    for i in range(1, 10 ** 6 + 5):
        present = contains(i, k, 10) or contains(i, k, 8)
        pref[i] += pref[i - 1] + present
    for i in range(n):
        print(v[i][1] - v[i][0] + 1 -
              (pref[v[i][1]] - pref[v[i][0] - 1]), end=" ")


if __name__ == '__main__':
    K = 7
    Q = [[2, 5], [1, 15]]
    N = len(Q)
    count(N, K, Q)

# Expected output:
4 13
# count tiles of dimensions 2 * 1 that can be placed in an m * n rectangular board that satisfies the given conditions | function to count tiles of dimensions 2 x 1 that can be placed in a grid of dimensions m * n as per given conditions ; number of tiles required ; 
def numberOfTiles(N, M):
    if (N % 2 == 1):
        return -1
    return (N * M) // 2


N = 2
M = 4
print(numberOfTiles(N, M))

# Expected output:
4
# check if an array can be converted to another given array by swapping pairs of unequal elements | function to check if arr1 [ ] can be converted to arr2 [ ] by swapping pair ( i , j ) such that i < j and arr [ i ] is 1 and arr [ j ] is 0 ; stores the differences of prefix sum of arr1 and arr2 ; stores the count of 1 and zero of arr1 ; stores the count of 1 and zero of arr2 ; iterate in the range [ 0 , n - 1 ] ; if arr1 [ i ] is 1 , then increment arr1_one by one ; otherwise increment arr1_zero by one ; if arr2 [ i ] is 1 , then increment arr2_one by one ; otherwise increment arr2_zero by one ; check if number of 1 s and 0 s of arr1 is equal to number of 1 s and 0 s of arr2 respectievly ; iterate over the range [ 0 , n - 1 ] ; increment count by differences arr1 [ i ] and arr2 [ i ] ; check if number of 1 's in  arr2 are more than arr1 and  then print "no" ; finally , print " yes " ; 
def canMakeEqual(arr1, arr2, N):
    count = 0
    arr1_one = 0
    arr1_zero = 0
    arr2_one = 0
    arr2_zero = 0
    for i in range(N):
        if (arr1[i] == 1):
            arr1_one += 1
        elif (arr1[i] == 0):
            arr1_zero += 1
        if (arr2[i] == 1):
            arr2_one += 1
        elif (arr2[i] == 0):
            arr2_zero += 1
    if (arr1_one != arr2_one or arr1_zero != arr2_zero):
        print("No")
        return
    for i in range(N):
        count = count + (arr1[i] - arr2[i])
        if (count < 0):
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    arr1 = [0, 1, 1, 0]
    arr2 = [0, 0, 1, 1]
    N = len(arr1)
    canMakeEqual(arr1, arr2, N)

# Expected output:
Yes
# check for each subarray whether it consists of all natural numbers up to its length or not | function to check if a subarray of size i exists that contain all the numbers in the range [ 1 , i ] ; store the position of each element of arr [ ] ; traverse the array ; insert the position of arr [ i ] ; store position of each element from the range [ 1 , n ] ; iterate over the range [ 1 , n ] ; insert the index of i into st ; find the smallest element of st ; find the largest element of st ; if distance between the largest and smallest element of arr [ ] till i - th index is equal to i ; 
def checksubarrayExist1_N(arr, N):
    pos = {}
    for i in range(N):
        pos[arr[i]] = i
    st = {}
    for i in range(1, N + 1):
        st[pos[i]] = 1
        Min = sorted(list(st .keys()))[0]
        Max = sorted(list(st .keys()))[-1]
        if (Max - Min + 1 == i):
            print("True", end=" ")
        else:
            print("False", end=" ")


if __name__ == '__main__':
    arr = [1, 4, 3, 2]
    N = len(arr)
    checksubarrayExist1_N(arr, N)

# Expected output:
True False False True
# check if a pair of integers a and b can coincide by shifting them by distances arr [ ( a % n + n ) % n ] and arr [ ( b % n + n ) % n ] | function to check if two integers coincide at a point ; store the final position of integers a and b ; iterate over the range [ 0 , n ] ; store the final position of the integer i ; if temp is present in the map ; print yes and return ; mark its final position as visited ; if every integer stored in the map is unique ; 
def checkSamePosition(arr, n):
    mp = {}
    for i in range(n):
        temp = ((i + arr[i]) % n + n) % n
        if temp in mp:
            print("Yes")
            return
        if (temp in mp):
            mp[temp] += 1
        else:
            mp[temp] = mp .get(temp, 0) + 1
    print("No")


if __name__ == '__main__':
    arr = [5, 4, 3]
    N = len(arr)
    checkSamePosition(arr, N)

# Expected output:
Yes
# sum of fibonacci numbers | set 2 | python program for the above approach ; function to find the sum of first n + 1 fibonacci numbers ; apply the formula ; prthe result ; 

import math


def sumFib(N):
    num = round(pow((pow(5, 1 / 2) + 1) / 2.0, N + 2) / pow(5, 1 / 2))
    print(num - 1)


if __name__ == '__main__':
    N = 3
    sumFib(N)

# Expected output:
4
# sum of fibonacci numbers | set 2 | pyhton3 program for the above approach ; function to find the sum of first n + 1 fibonacci numbers ; apply the formula ; print the result ; 

import math


def sumFib(N):
    num = (1 - math .sqrt(5)) / 2
    val = round(abs(1 / (pow(num, N + 2) + pow(num, N + 1) +
                pow(num, N) + pow(num, N - 1))) - 1)
    print(val)


if __name__ == '__main__':
    N = 3
    sumFib(N)

# Expected output:
4
# minimum number of pigs required to find the poisonous bucket | python program for the above approach ; function to find the minimum number of pigs required to find the poisonous bucket ; prthe result ; 

import math


def poorPigs(buckets, minutesToDie, minutesToTest):
    print(math .ceil(math .log(buckets) //
          math .log((minutesToTest // minutesToDie) + 1)))


if __name__ == '__main__':
    N = 1000
    M = 15
    P = 60
    poorPigs(N, M, P)

# Expected output:
4
# maximum product of the remaining pair after repeatedly replacing pairs of adjacent array elements with their sum | python program for the above approach ; function to find the maximum product possible after repeatedly replacing pairs of adjacent array elements with their sum ; store the maximum product ; store the prefix sum ; store the total sum of array ; traverse the array to find the total sum ; iterate in the range [ 0 , n - 2 ] ; add arr [ i ] to prefix_sum ; store the value of prefix_sum ; store the value of ( total sum - prefix sum ) ; update the maximum product ; print the answer ; 

import sys


def maxProduct(arr, N):
    max_product = -sys .maxsize
    prefix_sum = 0
    sum = 0
    for i in range(N):
        sum += arr[i]
    for i in range(N - 1):
        prefix_sum += arr[i]
        X = prefix_sum
        Y = sum - prefix_sum
        max_product = max(max_product, X * Y)
    print(max_product)


if __name__ == '__main__':
    arr = [2, 3, 5, 6, 7]
    N = len(arr)
    maxProduct(arr, N)

# Expected output:
130