#calcplex.com
BH="can't solve exactly"
BG='factor'
An='num'
Am='sqrt'
Al='acos'
Ak=enumerate
Aa='u-'
AZ='name'
AY='asin'
AX=list
AM='exp'
AL='tan'
AK='atan'
AC='abs'
A8='-'
A7='ln'
w='sin'
p='('
q=ValueError
n='cos'
m=range
l=tuple
b=max
W='fn'
R=False
O='v'
N='+'
M=True
K=str
G=None
F='^'
D='*'
B='q'
A=len
Ao=M
try:import ti_draw as AD,ti_system as BI
except ImportError:Ao=R
import math as Bp
A9='syntax error'
Ap='division by zero'
C=B,0,1
E=B,1,1
X=B,-1,1
x=B,2,1
d=B,1,2
AN=O,'pi'
Aq=O,'e'
BJ=F,x,d
Ab=F,(B,3,1),d
BK=D,d,BJ
BL=D,d,Ab
BM=D,(B,1,3),Ab
Ar={(0,1):C,(1,6):d,(1,4):BK,(1,3):BL,(1,2):E}
As={(0,1):C,(1,6):BM,(1,4):E,(1,3):Ab}
At={B:A for(A,B)in Ar.items()}
BN={B:A for(A,B)in As.items()}
Au=AY,Al,AK,Am,w,n,AL,AM,AC,A7,'pi'
BO=Au[:-1]
def y(a,b):
	if a<0:a=-a
	if b<0:b=-b
	while b:a,b=b,a%b
	return a
def c(p,d=1):
	if d==0:raise q(Ap)
	if d<0:p=-p;d=-d
	if p==0:return C
	A=p if p>0 else-p;D=d
	while D:A,D=D,A%D
	if A>1:p=p//A;d=d//A
	return B,p,d
def r(a,b):
	A=a[1]*b[2]+b[1]*a[2];E=a[2]*b[2]
	if A==0:return C
	D=A if A>0 else-A;F=E
	while F:D,F=F,D%F
	if D>1:A=A//D;E=E//D
	return B,A,E
def f(a,b):
	A=a[1]*b[1];E=a[2]*b[2]
	if A==0:return C
	D=A if A>0 else-A;F=E
	while F:D,F=F,D%F
	if D>1:A=A//D;E=E//D
	return B,A,E
def s(a):return B,-a[1],a[2]
def AA(a):return a[0]==B and a[2]==1
def g(e):
	A=e[0]
	if A==B or A==O:return()
	if A==F:return e[1],e[2]
	if A==W:return e[2],
	return e[1:]
def AE(out,n):
	A=[];B=0
	while B<n:A.append(out.pop());B+=1
	A.reverse();return A
def Av(e):
	C=0
	for A in e[1:]if e[0]==D else(e,):
		if A==(O,'x'):C+=1
		elif A[0]==F and A[1]==(O,'x')and A[2][0]==B and A[2][2]==1:C+=A[2][1]
	return C
def BP(e):return-Av(e),K(e)
def Aw(e):
	C=e[1]if e[0]==F else e
	if e[0]==B:A=0
	elif C[0]==O:A=1
	elif C[0]==W:A=2
	else:A=3
	return A,-Av(e),K(e)
def AF(c,base):
	A=base
	if c==E:return A
	if A[0]==D:return(D,c)+A[1:]
	return D,c,A
def Ax(a,d,n):
	if abs(n)*A(K(a)+K(d))>4000:return
	if n<0:a,d,n=d,a,-n
	return c(a**n,d**n)
def P(b,e):
	while M:
		if e==C:return E
		if e==E:return b
		if b==E:return E
		if b==C:
			if e[0]==B and e[1]<0:raise q(Ap)
			return C
		if b[0]==B and AA(e):
			K=Ax(b[1],b[2],e[1])
			if K:return K
		if b[0]==B and e==d and b[1]>0:
			H=b[1]*b[2];Q=1;G=2
			while G*G<=H:
				while H%(G*G)==0:H=H//(G*G);Q*=G
				G+=1
			O=c(Q,b[2])
			if H==1:return O
			if O==E:return F,(B,H,1),d
			return D,O,(F,(B,H,1),d)
		if b[0]==F and b[2][0]==B and e[0]==B:
			P=b[2];b=b[1]
			if P[2]==1 and P[1]%2==0 and e[2]!=1:b=W,AC,b
			e=f(P,e);continue
		if b[0]==W and b[1]==AC and e[0]==B and e[2]==1 and e[1]%2==0:b=b[2];continue
		if b[0]==B and e==(B,-1,2)and b[1]>0:b=B,b[2],b[1];e=d;continue
		if b[0]==D and AA(e):
			R=e[1];J=E;I=[]
			for G in b[1:]:
				L,N=(G[1],f(G[2],e))if G[0]==F and G[2][0]==B else(G,e)
				if L[0]==B and AA(N):
					K=Ax(L[1],L[2],N[1])
					if K:J=f(J,K);continue
				if N==C:continue
				I.append(L if N==E else(F,L,N))
			if J==C:return C
			I.sort(key=Aw)
			if not I:return J
			if J==E:return I[0]if A(I)==1 else(D,)+l(I)
			return(D,J)+l(I)
		return F,b,e
def L(args):
	S=[];N=[];O=A(args)-1
	while O>=0:N.append(args[O]);O-=1
	while N:
		G=N.pop()
		if G[0]==D:
			Q=A(G)-1
			while Q>=1:N.append(G[Q]);Q-=1
		else:S.append(G)
	H=E;M={};T=[]
	for G in S:
		if G[0]==B:
			H=f(H,G)
			if H==C:return C
			continue
		if G[0]==F and G[2][0]==B:I,K=G[1],G[2]
		else:I,K=G,E
		if I in M:M[I]=r(M[I],K)
		else:M[I]=K;T.append(I)
	if H==C:return C
	J=[]
	for I in T:
		K=M[I]
		if K==C:continue
		L=P(I,K)
		if L==E:continue
		if L[0]==B:H=f(H,L);continue
		if L[0]==D:
			for R in L[1:]:
				if R[0]==B:H=f(H,R)
				else:J.append(R)
			continue
		J.append(L)
	if H==C:return C
	J.sort(key=Aw)
	if not J:return H
	if H==E:
		if A(J)==1:return J[0]
		return(D,)+l(J)
	return(D,H)+l(J)
def Q(args):
	S=[];M=[];O=A(args)-1
	while O>=0:M.append(args[O]);O-=1
	while M:
		H=M.pop()
		if H[0]==N:
			P=A(H)-1
			while P>=1:M.append(H[P]);P-=1
		else:S.append(H)
	L=C;J={};Q=[]
	for H in S:
		if H[0]==B:L=r(L,H);continue
		if H[0]==D and H[1][0]==B:R=H[2:];I=H[1];G=R[0]if A(R)==1 else(D,)+R
		else:I,G=E,H
		if G in J:J[G]=r(J[G],I)
		else:J[G]=I;Q.append(G)
	for G in Q:
		if G[0]==F and G[2]==x and G[1][0]==W and G[1][1]==w:
			T=F,(W,n,G[1][2]),x;I=J[G]
			if I!=C and J.get(T)==I:J[G]=C;J[T]=C;L=r(L,I)
	K=[]
	for G in Q:
		I=J[G]
		if I==C:continue
		K.append(AF(I,G))
	K.sort(key=BP)
	if L!=C:K.append(L)
	if not K:return C
	if A(K)==1:return K[0]
	return(N,)+l(K)
def Ac(v):
	if v[0]==B:return B,-v[1],v[2]
	if v[0]==D and v[1][0]==B:A=v[1];return(D,(B,-A[1],A[2]))+v[2:]
	return D,X,v
def Ay(p,d):
	p%=2*d;B=R
	if p>=d:B=M;p-=d
	if 2*p>d:p=d-p
	C=y(p,d);A=Ar.get((p//C,d//C))
	if A is not G and B:A=Ac(A)
	return A
def t(name,a):
	I=name
	if I==Am:return P(a,d)
	T=R
	if I in(w,AL,AY,AK,n,AC):
		O,Q=AI(a)
		if O:a=Q;T=I not in(n,AC)
	H=G
	if a[0]==B:
		if I==A7 and a==E:H=C
		elif I==AM and a==C:H=E
		elif(I==w or I==AL)and a==C:H=C
		elif I==n and a==C:H=E
		elif I==AC:H=a
	if H is G and I in(w,n,AL):
		M=G
		if a==AN:M=1,1
		elif a[0]==D and A(a)==3 and a[1][0]==B and a[2]==AN:M=a[1][1],a[1][2]
		if M:
			J,K=M
			if I==w:H=Ay(J,K)
			elif I==n:H=Ay(J*2+K,K*2)
			else:
				J%=K;U=2*J>K
				if U:J=K-J
				V=y(J,K);H=As.get((J//V,K//V))
				if H is not G and U:H=Ac(H)
	if H is G and I in(AY,AK):
		L=(BN if I==AK else At).get(a)
		if L:H=C if L[0]==0 else AF(c(L[0],L[1]),AN)
	if H is G and I==Al:
		O,Q=AI(a);L=At.get(Q)
		if L:
			N,S=L
			if O:N=-N
			if S==2*N:H=C
			else:H=AF(c(S-2*N,2*S),AN)
	if H is G and I==A7:
		if a==Aq:H=E
		elif a[0]==F and a[1]==Aq:H=a[2]
		elif a[0]==W and a[1]==AM:H=a[2]
	if H is G and I==AM and a[0]==W and a[1]==A7:H=a[2]
	if H is G:H=W,I,a
	return Ac(H)if T else H
def z(e):
	I=[(e,0)];C=[]
	while I:
		E,M=I.pop()
		if M==0:
			G=E[0]
			if G==B or G==O:C.append(E);continue
			K=g(E);I.append((E,1));J=A(K)-1
			while J>=0:I.append((K[J],0));J-=1
		else:
			G=E[0];H=AE(C,A(g(E)))
			if G==N:C.append(Q(H))
			elif G==D:C.append(L(H))
			elif G==F:C.append(P(H[0],H[1]))
			else:C.append(t(E[1],H[0]))
	return C[0]
def Ad(e):
	if e[0]==N:return AX(e[1:])
	return[e]
def A0(e):
	R=[(e,0)];C=[]
	while R:
		G,X=R.pop()
		if X==0:
			I=G[0]
			if I==B or I==O:C.append(G);continue
			V=g(G);R.append((G,1));T=A(V)-1
			while T>=0:R.append((V[T],0));T-=1
		else:
			I=G[0];J=AE(C,A(g(G)))
			if I==N:C.append(Q(J))
			elif I==D:
				H=[E]
				for Y in J:
					Z=Ad(Y);K=[]
					for U in H:
						for M in Z:K.append(L([U,M]))
					H=K
				C.append(Q(H))
			elif I==F:
				M,S=J[0],J[1]
				if AA(S)and 0<=S[1]<=24 and M[0]==N:
					H=[E];W=0
					while W<S[1]:
						a=Ad(M);K=[]
						for U in H:
							for b in a:K.append(L([U,b]))
						H=Ad(Q(K));W+=1
					C.append(Q(H))
				else:C.append(P(M,S))
			else:C.append(t(G[1],J[0]))
	return C[0]
def BQ(e,var):
	W=[(e,0)];I=[]
	while W:
		J,k=W.pop()
		if k==0:
			T=J[0]
			if T==B:I.append((J,C));continue
			if T==O:I.append((J,E if J[1]==var else C));continue
			c=g(J);W.append((J,1));S=A(c)-1
			while S>=0:W.append((c[S],0));S-=1
		else:
			T=J[0];K=AE(I,A(g(J)))
			if T==N:
				U=[];f=[]
				for(Z,G)in K:U.append(Z);f.append(G)
				I.append((Q(U),Q(f)))
			elif T==D:
				U=[]
				for(Z,G)in K:U.append(Z)
				h=[]
				for S in m(A(K)):
					if K[S][1]==C:continue
					i=[K[S][1]]
					for j in m(A(K)):
						if j!=S:i.append(U[j])
					h.append(L(i))
				I.append((L(U),Q(h)))
			elif T==F:
				V,a=K[0];Y,b=K[1];R=P(V,Y)
				if b==C:l=P(V,Q([Y,X]));I.append((R,L([Y,l,a])))
				elif a==C:I.append((R,L([R,t(A7,V),b])))
				else:o=L([b,t(A7,V)]);p=L([Y,a,P(V,X)]);I.append((R,L([R,Q([o,p])])))
			else:
				H=J[1];M,r=K[0];R=t(H,M)
				if H==w:G=t(n,M)
				elif H==n:G=L([X,t(w,M)])
				elif H==AL:G=P(t(n,M),(B,-2,1))
				elif H==A7:G=P(M,X)
				elif H==AM:G=R
				elif H==AY:G=P(Q([E,L([X,P(M,x)])]),(B,-1,2))
				elif H==Al:G=L([X,P(Q([E,L([X,P(M,x)])]),(B,-1,2))])
				elif H==AK:G=P(Q([E,P(M,x)]),X)
				elif H==Am:G=L([d,P(M,(B,-1,2))])
				else:raise q('cannot differentiate '+H)
				I.append((R,L([G,r])))
	return I[0][1]
def Bq(e,var,rep):
	E=[(e,0)];D=[]
	while E:
		C,J=E.pop();F=C[0]
		if J==0:
			if F==B:D.append(C);continue
			if F==O:D.append(rep if C[1]==var else C);continue
			H=g(C);E.append((C,1));G=A(H)-1
			while G>=0:E.append((H[G],0));G-=1
		else:
			I=AE(D,A(g(C)))
			if F==W:D.append((W,C[1],I[0]))
			else:D.append((F,)+l(I))
	return D[0]
def Az(A,B):
	C={}
	for E in A:
		for F in B:D=E+F;G=f(A[E],B[F]);C[D]=r(C[D],G)if D in C else G
	return C
def A_(e,var):
	P=[(e,0)];I=[]
	while P:
		K,X=P.pop()
		if X==0:
			L=K[0]
			if L==B:I.append({0:K});continue
			if L==O:I.append({1:E}if K[1]==var else G);continue
			V=g(K);P.append((K,1));T=A(V)-1
			while T>=0:P.append((V[T],0));T-=1
		else:
			L=K[0];Q=AE(I,A(g(K)))
			if G in Q:I.append(G);continue
			if L==N:
				H={}
				for M in Q:
					for J in M:H[J]=r(H[J],M[J])if J in H else M[J]
				I.append(H)
			elif L==D:
				H={0:E}
				for M in Q:H=Az(H,M)
				I.append(H)
			elif L==F:
				Y=Q[0];U=K[2]
				if not(AA(U)and 0<=U[1]<=24):I.append(G);continue
				H={0:E};W=0
				while W<U[1]:H=Az(H,Y);W+=1
				I.append(H)
			else:I.append(G)
	R=I[0]
	if R is G:return
	S={}
	for J in R:
		if R[J]!=C:S[J]=R[J]
	if not S:S={0:C}
	return S
def B0(co):
	B=co;J=b(B.keys());E=1
	for H in B:E=E*B[H][2]//y(E,B[H][2])
	D=[]
	for F in m(J+1):I=B[F]if F in B else C;D.append(I[1]*(E//I[2]))
	G=0
	for K in D:G=y(G,K)
	if G>1:
		for F in m(A(D)):D[F]=D[F]//G
	return D,c(G,E)
def B1(n):
	if n<0:n=-n
	if n==0:return[1]
	B=[];A=1
	while A*A<=n and A<=4096:
		if n%A==0:
			B.append(A)
			if A!=n//A:B.append(n//A)
		A+=1
	B.sort();return B
def BR(ints):
	C=ints;B=0
	while B<A(C)-1 and C[B]==0:B+=1
	return B,C[B:]if B>0 else C
def B2(ints):
	B=ints;H=[];I=0
	while A(B)>2 and I<40:
		I+=1;E=R
		for N in B1(B[0]):
			for F in B1(B[A(B)-1]):
				for O in(1,-1):
					G=O*N
					if y(G,F)!=1:continue
					J=[0]*(A(B)-1);D=AX(B);C=A(D)-1;K=M
					while C>=1:
						if D[C]%F!=0:K=R;break
						L=D[C]//F;J[C-1]=L;D[C-1]+=L*G;C-=1
					if K and D[0]==0:H.append((F,G));B=J;E=M;break
				if E:break
			if E:break
		if not E:break
	return H,B
def B3(t):
	G,C=E,{}
	for A in t[1:]if t[0]==D else(t,):
		if A[0]==B:G=A
		elif A[0]==F and A[2][0]==B:C[A[1]]=A[2]
		else:C[A]=E
	return G,C
def Ae(e,var):
	P=var;D=A0(z(e));R=[]
	if D[0]==N:
		C,J=B3(D[1])
		if C[1]<0:C=s(C)
		for T in D[2:]:
			U,a=B3(T);C=c(y(C[1],U[1]),C[2]*U[2]//y(C[2],U[2]));d={}
			for H in a:
				if H in J:V,W=J[H],a[H];d[H]=V if V[1]*W[2]<=W[1]*V[2]else W
			J=d
		if J or C!=E:
			f=[(B,C[2],C[1])]
			if C!=E:R.append(C)
			for H in sorted(J,key=K):X=J[H];R.append(H if X==E else(F,H,X));f.append((F,H,s(X)))
			g=[]
			for T in D[1:]:g.append(L([T]+f))
			D=Q(g)
	Y=A_(D,P)
	if Y is G or b(Y.keys())<1:return L(R+[D])if R else D
	k,h=B0(Y);l,S=B2(k);I=R
	if h!=E:I.append(h)
	for(i,n)in l:o=(O,P)if i==1 else AF((B,i,1),(O,P));I.append(Q([o,(B,-n,1)]))
	Z=[]
	for M in m(A(S)):
		if S[M]:p=(O,P)if M==1 else(F,(O,P),(B,M,1));Z.append((B,S[M],1)if M==0 else AF((B,S[M],1),p))
	if Z:
		j=Q(Z)
		if j!=E:I.append(j)
	if not I:return D
	if A(I)==1:return I[0]
	return L(I)
def BS(t):
	C={};E=[]
	for A in t[1:]if t[0]==D else(t,):
		if A[0]==F and A[2][0]==B and A[2][1]<0:C[K(A[1])]=[A[1],s(A[2])]
		else:E.append(A)
	return E,C
def B4(e):
	M=e
	for V in m(3):
		if e[0]==D and A(K(e))<2000 and any(A[0]==N for A in e[1:]):e=A0(e)
		if e[0]==N and A(e)<=9:
			B={};P=[]
			for T in e[1:]:
				O,J=BS(T);P.append((O,J))
				for(H,G)in J.items():
					if H not in B or B[H][1][1]*G[1][2]<G[1][1]*B[H][1][2]:B[H]=G
			if B:
				L=[]
				for(O,J)in P:
					I=AX(O)
					for(H,G)in B.items():
						Q=J.get(H);R=r(G[1],s(Q[1]))if Q else G[1]
						if R!=C:I.append((F,G[0],R))
					L.append(I[0]if A(I)==1 else(D,)+l(I)if I else E)
				U=A0(z(L[0]if A(L)==1 else(N,)+l(L)));S=z((D,U)+l((F,A[0],s(A[1]))for A in B.values()))
				if A(K(S))<A(K(e)):e=S
		if A(K(e))<A(K(M)):M=e
		else:break
	return M
def AO(e):
	D={};E=[e]
	while E:
		C=E.pop()
		if C[0]==O:
			if C[1]!='pi'and C[1]!='e':D[C[1]]=1
		elif C[0]!=B:
			for F in g(C):E.append(F)
	if'x'in D or A(D)!=1:return'x'
	for F in D:return F
def B5(a,b,c):
	D=r(f(b,b),f((B,-4,1),f(a,c)))
	if D[1]<0:return[]
	E=P(D,d);F=P(f(x,a),X);A=L([Q([s(b),E]),F]);C=L([Q([s(b),L([X,E])]),F])
	if A==C:return[A]
	return[C,A]if a[1]>0 else[A,C]
def BT(e,var):
	Q=A0(z(e));D=A_(Q,var)
	if D is G:return G,M
	I=b(D.keys())
	if I==0:return'all'if D[0]==C else[],M
	if I==1:L=D[1];N=D.get(0,C);return[c(-N[1]*L[2],N[2]*L[1])],M
	if I==2:
		E=[]
		for H in B5(D[2],D.get(1,C),D.get(0,C)):E.append(A0(H))
		return E,M
	J,W=B0(D);S,J=BR(J);E=[]
	if S>0:E.append(C)
	T,F=B2(J)
	for(U,V)in T:E.append(c(V,U))
	O=M
	if A(F)==2:E.append(c(-F[0],F[1]))
	elif A(F)==3:
		for H in B5((B,F[2],1),(B,F[1],1),(B,F[0],1)):E.append(A0(H))
	elif A(F)>3:O=R
	P={};K=[]
	for H in E:
		if H not in P:P[H]=1;K.append(H)
	K.sort(key=lambda v:v[1]/v[2]if v[0]==B else 9e9);return K,O
def BU(a):
	if a[2]==1:return K(a[1])
	return'%d/%d'%(a[1],a[2])
def BV(src):
	C=src;F=[];B=0;J=A(C)
	while B<J:
		D=C[B]
		if D==' ':B+=1;continue
		if D in'0123456789.':
			E=B;K=R
			while E<J and(C[E]in'0123456789'or C[E]=='.'and not K):
				if C[E]=='.':K=M
				E+=1
			F.append((An,C[B:E]));B=E;continue
		if'a'<=D<='z'or'A'<=D<='Z':
			H=G
			for I in Au:
				if C[B:B+A(I)].lower()==I:H=I;break
			if H:F.append((AZ,H));B+=A(H)
			else:F.append((AZ,D.lower()));B+=1
			continue
		if D in'+-*/^()':F.append(('op',D));B+=1;continue
		raise q(A9)
	return F
def BW(txt):
	B=txt
	if'.'in B:D=B.index('.');C=B[D+1:];E=B[:D];F=A(C);G=int(E+C if E+C else'0');return c(G,10**F)
	return c(int(B))
AP={N:1,A8:1,D:2,'/':2,Aa:3,F:4}
BX=F,Aa
def AG(out,op):
	C=op;A=out
	if C==Aa:B=A.pop();A.append((D,X,B));return
	if C[0]=='f':B=A.pop();A.append((W,C[1:],B));return
	E=A.pop();B=A.pop()
	if C==N:A.append((N,B,E))
	elif C==A8:A.append((N,B,(D,X,E)))
	elif C==D:A.append((D,B,E))
	elif C=='/':A.append((D,B,(F,E,X)))
	else:A.append((F,B,E))
def BY(src):
	I=BV(src)
	if not I:raise q(A9)
	C=[];B=[];F=M;E=0
	while E<A(I):
		J,G=I[E]
		if not F and(J!='op'or G==p):
			while B and B[-1]!=p and AP.get(B[-1],5)>=AP[D]:AG(C,B.pop())
			B.append(D)
		if J==An or J==AZ:
			P=J==AZ and G in BO and E+1<A(I)and I[E+1]==('op',p)
			if P:B.append('f'+G);F=M
			else:
				if J==An:C.append(BW(G))
				else:C.append((O,G))
				F=R
			E+=1;continue
		H=G
		if H==p:B.append(p);F=M;E+=1;continue
		if H==')':
			while B and B[-1]!=p:AG(C,B.pop())
			if not B:raise q(A9)
			B.pop()
			if B and B[-1][0]=='f'and A(B[-1])>1:AG(C,B.pop())
			F=R;E+=1;continue
		if H==A8 and F:B.append(Aa);E+=1;continue
		if F:raise q(A9)
		K=AP[H]
		while B and B[-1]!=p:
			Q=B[-1];L=AP.get(Q,5)
			if L>K or L==K and H not in BX:AG(C,B.pop())
			else:break
		B.append(H);F=M;E+=1
	while B:
		N=B.pop()
		if N==p:raise q(A9)
		AG(C,N)
	if A(C)!=1:raise q(A9)
	return C[0]
AB=10
BZ=12
def H(s):return AB*A(s),BZ,0,[('t',0,0,s)]
def AH(ops,dx,dy):
	B=[]
	for A in ops:
		C=A[0]
		if C=='t':B.append(('t',A[1]+dx,A[2]+dy,A[3]))
		elif C=='r':B.append(('r',A[1]+dx,A[2]+dy,A[3],A[4]))
		else:B.append(('l',A[1]+dx,A[2]+dy,A[3]+dx,A[4]+dy))
	return B
def i(boxes):
	B=0;C=0;D=0;E=[]
	for A in boxes:
		for F in AH(A[3],B,0):E.append(F)
		B+=A[0];C=b(C,A[1]);D=b(D,A[2])
	return B,C,D,E
def A1(nb,db):
	B=db;A=nb;C=b(A[0],B[0])+8;E=-5;D=[];G=E-3-A[2]
	for F in AH(A[3],(C-A[0])//2,G):D.append(F)
	H=E+3+B[1]
	for F in AH(B[3],(C-B[0])//2,H):D.append(F)
	D.append(('r',0,E-1,C,2));return C,A[1]-G,H+B[2],D
def Ba(bb,eb):
	A=bb;B=4-A[1];C=AX(A[3])
	for D in AH(eb[3],A[0],B):C.append(D)
	E=b(A[1],eb[1]-B);F=b(A[2],B+eb[2]);return A[0]+eb[0],E,F,C
def Bb(rb):
	A=rb;B=9;C=-(A[1]+5);D=[]
	for E in AH(A[3],B,0):D.append(E)
	D.extend((('l',0,-4,3,0),('l',3,0,B-3,C),('l',B-3,C,B+A[0]+3,C)));return B+A[0]+4,-C,A[2],D
def AQ(b):return i([H(p),b,H(')')])
def AI(e):
	if e[0]==B and e[1]<0:return M,(B,-e[1],e[2])
	if e[0]==D and e[1][0]==B and e[1][1]<0:
		F=B,-e[1][1],e[1][2];C=e[2:]
		if F==E:return M,C[0]if A(C)==1 else(D,)+C
		return M,(D,F)+C
	return R,e
def Af(e):
	X='1';Y=[(e,0)];L=[]
	while Y:
		C,t=Y.pop();Q=C[0]
		if t==0:
			if Q==B:
				if C[2]==1:L.append((H(K(C[1])),4 if C[1]>=0 else 0,R))
				else:
					k=C[1]if C[1]>0 else-C[1];l=A1(H(K(k)),H(K(C[2])))
					if C[1]<0:l=i([H(A8),l])
					L.append((l,4,R))
				continue
			if Q==O:L.append((H(C[1]),4,R));continue
			Y.append((C,1))
			if Q==N:
				G=A(C)-1
				while G>=1:Y.append((AI(C[G])[1],0));G-=1
				continue
			Z=(C[1],C[2])if Q==F else(C[2],)if Q==W else C[1:];G=A(Z)-1
			while G>=0:Y.append((Z[G],0));G-=1
			continue
		k=2 if Q==F else 1 if Q==W else A(C)-1;I=[];G=0
		while G<k:I.append(L.pop());G+=1
		I.reverse()
		if Q==W:
			n=I[0][0]
			if I[0][2]:n=A1(H(X),n)
			L.append((i([H(C[1]),AQ(n)]),4,R))
		elif Q==F:
			f=C[2];S=f[0]==B and f[1]<0;g=s(f)if S else f;U=I[0][0]
			if I[0][2]:U=A1(H(X),U)
			if g==d:L.append((Bb(U),4,S));continue
			if g==E:L.append((U,I[0][1],S));continue
			u=U if I[0][1]>=3 and not I[0][2]else AQ(U)
			if g[0]==B:h=H(BU(g))
			else:
				h=I[1][0]
				if I[1][2]:h=A1(H(X),h)
			L.append((Ba(u,h),3,S))
		elif Q==D:
			V=[];a=[];b=R;Z=C[1:]
			for G in m(A(Z)):
				J,T,o=I[G];P=Z[G]
				if o:a.append((J,T));continue
				if P[0]==B:
					if P[2]==1 and P[1]==-1:b=M;continue
					if P[2]!=1:
						if P[1]==-1:b=M
						elif P[1]!=1:V.insert(0,(H(K(P[1])),4))
						a.append((H(K(P[2])),4));continue
					if P[1]<0:b=M;V.insert(0,(H(K(-P[1])),4))
					else:V.insert(0,(H(K(P[1])),4))
					continue
				V.append((J,T))
			p=[]
			for(J,T)in V:
				if T<2 and(A(V)>1 or not a):J=AQ(J)
				p.append(J)
			q=[]
			for(J,T)in a:
				if T<2 and A(a)>1:J=AQ(J)
				q.append(J)
			c=i(p)if p else H(X)
			if q:c=A1(c,i(q))
			if b:c=i([H(A8),c])
			L.append((c,0 if b else 2,R))
		else:
			j=[]
			for G in m(1,A(C)):
				S=AI(C[G])[0]
				if G==1:
					if S:j.append(H(A8))
				else:j.append(H(' - 'if S else' + '))
				r=I[G-1][0]
				if I[G-1][2]:r=A1(H(X),r)
				j.append(r)
			L.append((i(j),1,R))
	J,T,o=L[0]
	if o:return A1(H(X),J)
	return J
def Bc(ops):
	E=[];F=[]
	for B in ops:(E if B[0]=='t'else F).append(B)
	E.sort(key=lambda o:(o[2],o[1]));C=[]
	for B in E:
		if C:
			D=C[A(C)-1]
			if D[2]==B[2]and D[1]+AB*A(D[3])==B[1]:C[A(C)-1]='t',D[1],D[2],D[3]+B[3];continue
		C.append(B)
	for B in F:C.append(B)
	return C
if Ao:
	J,B6=AD.get_screen_dim();a=AD.draw_text;j=AD.fill_rect
	def T(c):AD.set_color(c[0],c[1],c[2])
	Ag=14,17,23;B7=46,51,58;AR=235,238,242;B8=135,142,152;AS=77,154,235;Bd=255,120,110;Ah=255,200,60;B9=dict(zip((102,103,32,51,85,75,65,55,63,64,104,61,52,53,54,81),'0 . x ^ + - * / ( ) - ^2 sin( cos( tan( ln('.split()))
	for A2 in m(9):B9[92-10*(A2//3)+A2%3]=K(A2+1)
	Be=dict(zip((65,55,61,81,52,53,54),'e pi sqrt( exp( asin( acos( atan('.split()));BA={}
	for(A2,Bf)in Ak(b')*+34567=>?@AGHIJKQRSTU[\\]'):BA[Bf]=chr(97+A2)
	Bg=dict(zip((11,12,13,14,15),'simp expand factor ddx solve'.split()));Bh='SIMP EXPD FACT d/dx SOLV'.split();Bi='SOLV: solve expr = 0\nALPHA+key = letters a-z\nCLEAR = clear/quit'.split('\n');Y='';U=0;I=0;V=G;A3=0;e=0;o=['VARS = help'];AJ=B8;A4='READY'
	def Bj():
		T(Ag);j(-1,-1,J+2,B6+2);T(B7);j(-1,-1,J+2,21);j(-1,190,J+2,20);j(-1,56,J+2,2);T(AR);a(6,22,'CALC');T(AS);a(46,22,'PLEX');T(AR);a(96,22,'CAS');T(AS)
		for(A,B)in Ak(Bh):a(63*A+12,211,B)
	def Z():
		T(B7);j(140,3,J-140+1,15)
		if I:T(Ah);a(146,22,'2nd'if I==1 else'A')
		B=V and AT(0)[1]>J-8;T(Ah if B else AR);C='2ND+ARROWS'if B else A4;a(J-10*A(C)-6,22,C)
	def u():T(Ag);j(-1,30,J+2,24);T(AR);A=b(U-29,0);a(6,48,'>'+Y[A:A+30]);B=U-A+1;T(AS);j(6+10*B,44,9,3)
	def Bk(res):
		D=res;K=Af(D)
		if K[0]<=J-10 or D[0]!=N:return[K]
		F=[];B=[];G=0
		for L in m(1,A(D)):
			M,O=AI(D[L]);I=Af(O);E=A8 if M else N if L>1 else'';C=H(' '+E+' 'if E else'')
			if B and G+C[0]+I[0]>J-10:
				F.append(i(B));B=[];G=0
				if E:C=H(E+' ')
			if C[0]:B.append(C)
			B.append(I);G+=C[0]+I[0]
		if B:F.append(i(B))
		return F
	def Bl(ex):global V,o,AJ,A4;V=G;A='! '+K(ex);o=[A[:31],A[31:62]];AJ=Bd;A4='ERROR'
	def AT(i):
		C=0;B=0
		for A in V[i:]:
			C+=A[1]+A[2]+10
			if A[0]>B:B=A[0]
		return C,B
	def v():
		T(Ag);j(-1,58,J+2,132);T(AJ)
		if V:
			S,U=AT(0);c=U>J-8
			if S<=130:C=58+(132-S)//2;K=0
			else:C=62;K=A3
			H=K
			while H<A(V):
				D=V[H]
				if H>K and C+D[1]+D[2]>186:break
				L=C+D[1];I=4-e if c else(J-D[0])//2
				for B in Bc(D[3]):
					if B[0]=='t':
						W=L+B[2]+6;G=I+B[1];E=B[3]
						if G<0:X=(9-G)//AB;E=E[X:];G+=AB*X
						if G+AB*A(E)>J:E=E[:(J-G)//AB]
						if E and 76<=W<=195:a(G,W,E)
					elif B[0]=='r':
						R=L+B[2];Y=b(I+B[1],0);Z=min(I+B[1]+B[3],J)-Y
						if Z>=2 and R>=58 and R+B[4]<=189:j(Y,R,Z,B[4])
					else:
						M=I+B[1];N=I+B[3];P=L+B[2];Q=L+B[4]
						if min(P,Q)>=58 and b(P,Q)<=189:
							if P==Q:M=b(M,0);N=min(N,J-1)
							if 0<=M<N<J:AD.draw_line(M,P,N,Q)
				C+=D[1]+D[2]+10;H+=1
			T(Ah)
			if K>0:a(J-16,76,F)
			if H<A(V):a(J-16,195,O)
			if e:a(2,130,'<')
			if U-e>J-8:a(J-12,130,'>')
			return
		C=76
		for d in o[:7]:a(6,C,d[:31]);C+=19
	Bj();Z();u();v();Ai='0';BB=M
	while BB:
		S=BI.get_key(0)
		if S==0 or S==Ai:Ai=S;continue
		Ai=S
		if S==21:I=0 if I==1 else 1;Z();continue
		if S==31:I=0 if I==2 else 2;Z();continue
		if S==45:
			if not Y:BB=R;continue
			Y='';U=I=A3=e=0;V=G;o=[];A4='READY';Z();u();v();continue
		if S==44:V=G;o=Bi;AJ=B8;A4='HELP';I=0;Z();v();continue
		if S==23:
			if U>0:Y=Y[:U-1]+Y[U:];U-=1;u()
			continue
		if S==24:
			if I==1 and e:e=b(e-90,0);I=0;Z();v()
			elif I:
				if I==1:U=0
				I=0;Z();u()
			elif U>0:U-=1;u()
			continue
		if S==26:
			if I==1 and V:
				BC=AT(0)[1]-J+8
				if e<BC:e=min(e+90,BC);I=0;Z();v();continue
			if I:
				if I==1:U=A(Y)
				I=0;Z();u()
			elif U<A(Y):U+=1;u()
			continue
		if I and S in(34,25):I=0;Z()
		if S==34:
			if V and AT(A3)[0]>130:A3+=1;v()
			continue
		if S==25:
			if A3>0:A3-=1;v()
			continue
		Bm=(B9,Be,BA)[I];Aj=Bm.get(S)
		if Aj is not G:
			if I:I=0;Z()
			if A(Y)<120:Y=Y[:U]+Aj+Y[U:];U+=A(Aj);u()
			continue
		if I:I=0;Z()
		A5=Bg.get(S,'simp'if S==105 else G)
		if not(A5 and Y.strip()):continue
		A4='...';Z()
		try:
			A6=z(BY(Y));h=V=G;A3=e=0;o=[]
			if A5=='simp':h=B4(A6)
			elif A5=='expand':h=A0(A6)
			elif A5==BG:h=Ae(A6,AO(A6))
			elif A5=='ddx':h=B4(z(BQ(A6,'x')))
			else:
				BD=AO(A6);AU,BE=BT(A6,BD)
				if AU=='all':o=['always true']
				elif AU is G:o=[BH]
				elif not AU:o=['no real solution']if BE else[BH]
				else:
					AV=[H(BD+' = ')]
					for(A2,Bn)in Ak(AU):
						if A2:AV.append(H(',  '))
						AV.append(Af(Bn))
					if not BE:AV.append(H(', ...'))
					V=[i(AV)]
			if h is not G and A5!=BG and h[0]==D:
				AW=[]
				for k in h[1:]:
					if k[0]==N:AW.append(Ae(k,AO(k)))
					elif k[0]==F and k[1][0]==N and AA(k[2]):AW.append((F,Ae(k[1],AO(k[1])),k[2]))
					else:AW.append(k)
				BF=z((D,)+l(AW))
				if A(K(BF))<A(K(h)):h=BF
			if h is not G:V=Bk(h)
			AJ=AS;A4=A5.upper()
		except Exception as Bo:Bl(Bo)
		Z();v()
	T((0,0,0));j(-1,-1,J+2,B6+2)