Your solution gets AC in PyPy, just change input() to raw_input(). Problems of this kind are often impossible to pass here in pure Python.
As the problem is set with many single-case testfiles, the runtime is heavily distorted by interpreter startup lag so you won’t see much of a result of optimizations. However it’s always better to use variables rather than sequence access if possible, also simplifying the operations within the nested loops could help. Here’s how I’d write it:
def alternating_seq(a, n):
if n == 1:
return 1
dp = [1] * n
res = 0
for i, vi in enumerate(a[1:], 1):
dpi = 1
for j, vj in enumerate(a[:i]):
if dpi <= dp[j] and (-vi > vj > 0 or vi > -vj > 0):
dpi = 1 + dp[j]
if dpi > res:
res = dpi
dp[i] = dpi
return res
n = int(input())
a = [int(i) for i in input().split()]
print(alternating_seq(a, n))
PS. Watch out when using list slicing in a loop in PyPy, sometimes it’s heavy on the memory.