9 lines
No EOL
461 B
Haskell
9 lines
No EOL
461 B
Haskell
import Data.List
|
|
s(x:y:z)=([x,y],1):s(y:z);s _=[]
|
|
m((x,i):z)|(h,t)<-span((==x).fst)z=(x,i+sum(map snd h)):m t;m _ = []
|
|
c#(s,i)|Just a<-map((*i)<$>)<$>lookup s c=a
|
|
t=((m.sort).).(=<<).(#)
|
|
c i=foldr(\([a,b],i)x->(a,i):(b,i):x)[(head i,1),(last i,1)]
|
|
d i (x,r)|a<-map((`div`2).snd)$m$sort$c x(iterate(t r)(s x)!!i)=maximum a-minimum a
|
|
u(a:b)c=(a:b,[([a,c],1),(c:b,1)])
|
|
main=interact$show.((,).d 40<*>d 10).(\(x:_,_:y)->(x,map(u.take 2<*>(!!6))y)).break(==[]).lines |