giulio98/xlcost-single-prompt huggingface dataset:
# minimize prize count required such that smaller value gets less prize in an adjacent pair | function to find the minimum number of required such that adjacent smaller elements gets less number of prizes ; loop to iterate over every elements of the array ; loop to find the consecutive smaller elements at left ; loop to find the consecutive smaller elements at right ; 
def findMinPrizes(arr, n):
    totalPrizes = 0
    for i in range(n):
        x = 1
        j = i
        while (j > 0 and arr[j] > arr[j - 1]):
            x += 1
            j -= 1
        j = i
        y = 1
        while (j < n - 1 and arr[j] > arr[j + 1]):
            y += 1
            j += 1
        totalPrizes += max(x, y)
    print(totalPrizes)


arr = [1, 2, 2, 3]
n = len(arr)
findMinPrizes(arr, n)

# Expected output:
6
# number of ways to split n as sum of k numbers from the given range | python3 implementation to count the number of ways to divide n in k groups such that each group has elements in range [ l , r ] ; dp table ; function to count the number of ways to divide the number n in k groups such that each group has number of elements in range [ l , r ] ; base case ; if n is divides completely into less than k groups ; if the subproblem has been solved , use the value ; put all possible values greater equal to prev ; function to count the number of ways to divide the number n ; initialize dp table as - 1 ; 

mod = 1000000007
dp = [[-1 for j in range(1000)]for i in range(1000)]


def calculate(pos, left, k, L, R):
    if (pos == k):
        if (left == 0):
            return 1
        else:
            return 0
    if (left == 0):
        return 0
    if (dp[pos][left] != -1):
        return dp[pos][left]
    answer = 0
    for i in range(L, R + 1):
        if (i > left):
            break
        answer = (answer + calculate(pos + 1, left - i, k, L, R)) % mod
    dp[pos][left] = answer
    return answer


def countWaystoDivide(n, k, L, R):
    return calculate(0, n, k, L, R)


if __name__ == "__main__":
    N = 12
    K = 3
    L = 1
    R = 5
    print(countWaystoDivide(N, K, L, R))

# Expected output:
10
# minimum number of squares whose sum equals to given number n | set 2 | function for finding minimum square numbers ; arr [ i ] of array arr store minimum count of square number to get i ; sqrnum [ i ] store last square number to get i ; find minimum count of square number for all value 1 to n ; in worst case it will be arr [ i - 1 ] + 1 we use all combination of a [ i - 1 ] and add 1 ; check for all square number less or equal to i ; if it gives less count then update it ; v stores optimum square number whose sum give n ; 
def minSqrNum(n):
    arr = [0] * (n + 1)
    sqrNum = [0] * (n + 1)
    v = []
    for i in range(n + 1):
        arr[i] = arr[i - 1] + 1
        sqrNum[i] = 1
        k = 1
        while (k * k <= i):
            if (arr[i] > arr[i - k * k] + 1):
                arr[i] = arr[i - k * k] + 1
                sqrNum[i] = k * k
            k += 1
    while (n > 0):
        v .append(sqrNum[n])
        n -= sqrNum[n]
    return v


n = 10
v = minSqrNum(n)
for i in range(len(v)):
    print(v[i], end="")
    if (i < len(v) - 1):
        print(" + ", end="")

# Expected output:
1 + 9