Buggy python submission (verdict: Runtime Error):
import copy
s = input()
k = [0] * 6
t = []
while True:
    i = 0
    if "+" in s[1:]:
        i = 1 + s[1:].index("+")
    if "-" in s[1:]:
        if i > 0:i = min(i, 1 + s[1:].index("-"))
        else:i = 1 + s[1:].index("-")
    if i == 0:
        k[0] = int(s)
        break
    j = s.index("x")
    if j + 3 == i:
        if j == 0:k[int(s[j + 2])] = 1
        else:k[int(s[j + 2])] = int(s[:j])
    else:
        if j == 0:k[1] = 1
        else:k[1] = int(s[:j])
    s = s[i:]
while True:
    if k[-1] == 0:k.pop()
    else:break
while True:
    i = 1
    while i <= abs(k[0]):
        if k[0] % i == 0:
            j = k[0] // i
            kn = copy.deepcopy(k)
            for l in range(len(kn) - 1):
                if kn[l] % j == 0:
                    kn[l + 1] -= kn[l] // j
                    kn[l] //= j
                else:
                    break
            else:
                if kn[-1] == 0:
                    kn.pop()
                    t.append(j)
                    k = copy.deepcopy(kn)
                    break
            j *= -1
            kn = copy.deepcopy(k)
            for l in range(len(kn) - 1):
                if kn[l] % j == 0:
                    kn[l + 1] -= kn[l] // j
                    kn[l] //= j
                else:
                    break
            else:
                if kn[-1] == 0:
                    kn.pop()
                    t.append(j)
                    k = copy.deepcopy(kn)
                    break
        i += 1
    if len(k) == 2:
        t.append(k[0])
        break
t.sort()
s = ""
for i in t:s += "(x{})".format(i) if i < 0 else "(x+{})".format(i)
print(s)


Fixed submission:
import copy
s = input()
k = [0] * 6
t = []
while True:
    i = 0
    if "+" in s[1:]:
        i = 1 + s[1:].index("+")
    if "-" in s[1:]:
        if i > 0:i = min(i, 1 + s[1:].index("-"))
        else:i = 1 + s[1:].index("-")
    if i == 0:
        k[0] = int(s)
        break
    j = s.index("x")
    if j + 3 == i:
        if j == 0:k[int(s[j + 2])] = 1
        else:k[int(s[j + 2])] = int(s[:j])
    else:
        if j == 0:k[1] = 1
        elif j == 1:k[1] = int(s[0] + "1")
        else:k[1] = int(s[:j])
    s = s[i:]
while True:
    if k[-1] == 0:k.pop()
    else:break
while True:
    i = 1
    while i <= abs(k[0]):
        if k[0] % i == 0:
            j = k[0] // i
            kn = copy.deepcopy(k)
            for l in range(len(kn) - 1):
                if kn[l] % j == 0:
                    kn[l + 1] -= kn[l] // j
                    kn[l] //= j
                else:
                    break
            else:
                if kn[-1] == 0:
                    kn.pop()
                    t.append(j)
                    k = copy.deepcopy(kn)
                    break
            j *= -1
            kn = copy.deepcopy(k)
            for l in range(len(kn) - 1):
                if kn[l] % j == 0:
                    kn[l + 1] -= kn[l] // j
                    kn[l] //= j
                else:
                    break
            else:
                if kn[-1] == 0:
                    kn.pop()
                    t.append(j)
                    k = copy.deepcopy(kn)
                    break
        i += 1
    if len(k) == 2:
        t.append(k[0])
        break
t.sort()
s = ""
for i in t:s += "(x{})".format(i) if i < 0 else "(x+{})".format(i)
print(s)