--SP-超极限加速同调
function c87593001.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CANNOT_DISABLE)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCost(c87593001.cost)
	e1:SetTarget(c87593001.target)
	e1:SetOperation(c87593001.activate)
	c:RegisterEffect(e1)
end
function c87593001.cfilter1(c,e,tp,sc)
	local lc=Duel.GetLocationCount(tp,LOCATION_MZONE)
	local rg=Duel.GetMatchingGroup(c87593001.cfilter2,tp,LOCATION_GRAVE,0,c,e,tp)
	return c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_TUNER) and c:IsFaceup() and lc>=2 and c:IsCanBeSynchroMaterial()
		and rg:CheckWithSumEqual(Card.GetLevel,sc:GetLevel()-c:GetLevel(),2,lc) and c:IsAbleToRemove()
end
function c87593001.cfilter2(c,e,tp)
	return c:IsType(TYPE_SYNCHRO) and not c:IsType(TYPE_TUNER) and c:IsCanBeSynchroMaterial()
	and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c87593001.spfilter(c,e,tp)
	return c:IsType(TYPE_SYNCHRO) and c:GetLevel()>=9 and c:GetLevel()<=12 and c:IsCanBeSpecialSummoned(e,0,tp,true,false)
		and Duel.IsExistingMatchingCard(c87593001.cfilter1,tp,LOCATION_MZONE,0,1,nil,e,tp,c)
end
function c87593001.cost(e,tp,eg,ep,ev,re,r,rp,chk)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_SZONE,LOCATION_SZONE,nil,87593200):GetFirst()
	if f:GetControler()==tp then cou=0x871 else cou=0x872 end
	if chk==0 then return f:GetCounter(cou)>=12 and f:IsCanRemoveCounter(tp,cou,6,REASON_COST) end
	f:RemoveCounter(tp,cou,6,REASON_COST)
end
function c87593001.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then
	return Duel.IsExistingMatchingCard(c87593001.spfilter,tp,LOCATION_EXTRA,0,1,nil,e,tp) end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA)
end
function c87593001.activate(e,tp,eg,ep,ev,re,r,rp)
	local lc=Duel.GetLocationCount(tp,LOCATION_MZONE)
	if lc<2 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local g=Duel.SelectMatchingCard(tp,c87593001.spfilter,tp,LOCATION_EXTRA,0,1,1,nil,e,tp):GetFirst()
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
	local g1=Duel.SelectMatchingCard(tp,c87593001.cfilter1,tp,LOCATION_MZONE,0,1,1,nil,e,tp,g)
	local rg=Duel.GetMatchingGroup(c87593001.cfilter2,tp,LOCATION_GRAVE,0,nil,e,tp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
	local g2=rg:SelectWithSumEqual(tp,Card.GetLevel,g:GetLevel()-g1:GetFirst():GetLevel(),2,lc)
	g1:Merge(g2)
	if Duel.SpecialSummon(g2,0,tp,tp,false,false,POS_FACEUP_ATTACK)==g2:GetCount()
	and Duel.Remove(g1,POS_FACEUP,REASON_EFFECT+REASON_SYNCHRO+REASON_MATERIAL)==g1:GetCount() then
		g:SetMaterial(g1)
		Duel.SpecialSummon(g,SUMMON_TYPE_SYNCHRO,tp,tp,true,false,POS_FACEUP_ATTACK)
		g:CompleteProcedure()
	end
end
