def binary_search(a, x):
    low = 0
    high = len(a) - 1

    while low <= high:
        mid = (low + high) // 2

        if a[mid] == x:
            return mid
        elif a[mid] < x:
            low = mid + 1
        else:
            high = mid - 1

    return -1


a = [10, 20, 30, 40, 50]
x = 30

result = binary_search(a, x)

if result == -1:
    print("Element not found")
else:
    print("Element found at position", result + 1)