[Cpp]
# Include <iostream>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <map>
Using namespace std;
Const int oo = 1000000;
Int main ()
{
Map <int, int> mymap;
Int t, l, n, co, a, B, ca = 0;
Map <int, int >:: iterator it1, it2;
Scanf ("% d", & t );
While (t --)
{
Mymap. clear ();
Mymap [oo] = 1, mymap [-oo] = 1;
Scanf ("% d", & l, & n );
Co = 0;
Int ans = 0, dir;
While (n --)
{
Scanf ("% d", & );
If ()
{
It1 = mymap. lower_bound (co );
If (it1-> first = co)
{
It1-> second --;
If (it1-> second = 0) mymap. erase (it1 );
}
Else
{
It1 --;
It2 = mymap. upper_bound (co );
If (it1-> first =-oo & it2-> first = oo) continue;
If (co-it1-> first = it2-> first-co)
{
If (dir = 1)
{
It2-> second --;
Ans + = it2-> first-co;
Co = it2-> first;
If (it2-> second = 0) mymap. erase (it2 );
}
Else
{
It1-> second --;
Ans + = co-it1-> first;
Co = it1-> first;
If (it1-> second = 0) mymap. erase (it1 );
}
}
Else if (it2-> first-co <co-it1-> first)
{
Dir = 1;
Ans + = it2-> first-co;
Co = it2-> first;
It2-> second --;
If (it2-> second = 0) mymap. erase (it2 );
}
Else
{
Dir = 0;
Ans + = co-it1-> first;
Co = it1-> first;
It1-> second --;
If (it1-> second = 0) mymap. erase (it1 );
}
}
}
Else
{
Scanf ("% d", & B );
Mymap [B] ++;
}
}
Printf ("Case % d: % d \ n", ++ ca, ans );
}
Return 0;
}
# Include <iostream>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <map>
Using namespace std;
Const int oo = 1000000;
Int main ()
{
Map <int, int> mymap;
Int t, l, n, co, a, B, ca = 0;
Map <int, int >:: iterator it1, it2;
Scanf ("% d", & t );
While (t --)
{
Mymap. clear ();
Mymap [oo] = 1, mymap [-oo] = 1;
Scanf ("% d", & l, & n );
Co = 0;
Int ans = 0, dir;
While (n --)
{
Scanf ("% d", & );
If ()
{
It1 = mymap. lower_bound (co );
If (it1-> first = co)
{
It1-> second --;
If (it1-> second = 0) mymap. erase (it1 );
}
Else
{
It1 --;
It2 = mymap. upper_bound (co );
If (it1-> first =-oo & it2-> first = oo) continue;
If (co-it1-> first = it2-> first-co)
{
If (dir = 1)
{
It2-> second --;
Ans + = it2-> first-co;
Co = it2-> first;
If (it2-> second = 0) mymap. erase (it2 );
}
Else
{
It1-> second --;
Ans + = co-it1-> first;
Co = it1-> first;
If (it1-> second = 0) mymap. erase (it1 );
}
}
Else if (it2-> first-co <co-it1-> first)
{
Dir = 1;
Ans + = it2-> first-co;
Co = it2-> first;
It2-> second --;
If (it2-> second = 0) mymap. erase (it2 );
}
Else
{
Dir = 0;
Ans + = co-it1-> first;
Co = it1-> first;
It1-> second --;
If (it1-> second = 0) mymap. erase (it1 );
}
}
}
Else
{
Scanf ("% d", & B );
Mymap [B] ++;
}
}
Printf ("Case % d: % d \ n", ++ ca, ans );
}
Return 0;
}