题目链接
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
using namespace std;
#define In inline
#define PI atan(1.0)*4
#define enter puts("")
#define MaxN 0x3f3f3f3f
#define MinN 0xc0c0c0c0
#define bug(x) cerr<<#x<<'='<<x<<' '
#define ALL(a) a.begin(), a.end()
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define mset(a,b) memset(a,b,sizeof(a))
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair< int , int > pii;
In ll read ( )
{
ll ans = 0 ;
char ch = getchar ( ) , las = ' ' ;
while ( ! isdigit ( ch) ) las = ch, ch = getchar ( ) ;
while ( isdigit ( ch) ) ans = ( ans << 1 ) + ( ans << 3 ) + ch - '0' , ch = getchar ( ) ;
if ( las == '-' ) ans = - ans;
return ans;
}
In void write ( ll x)
{
if ( x < 0 ) x = - x, putchar ( '-' ) ;
if ( x >= 10 ) write ( x / 10 ) ;
putchar ( x% 10 + '0' ) ;
}
ll max ( ll a, ll b) {
if ( a > b) return a;
return b;
}
const int N = 100010 ;
int t;
ll a[ N] ;
int main ( )
{
t = read ( ) ;
rep ( kcase, 1 , t) {
mset ( a, 0 ) ;
string s;
cin >> s;
printf ( "Case #%d: " , kcase) ;
int cnt = 1 , idx = 1 ;
bool check = 0 ;
rep ( i, 1 , s. length ( ) - 1 )
if ( s[ i] == s[ i- 1 ] ) cnt ++ ;
else {
a[ idx ++ ] = cnt;
if ( cnt == 1 ) check = 1 ;
cnt = 1 ;
}
if ( cnt == 1 ) check = 1 ;
a[ idx] = cnt;
ll res = a[ 1 ] * a[ 1 ] ;
ll max_ = 0 ;
rep ( i, 2 , idx) {
res + = ( ll) a[ i] * a[ i] ;
max_ = max ( max_, 2 * ( a[ i- 1 ] - a[ i] + 1 ) ) ;
}
res + = max_;
if ( check) {
ll max_around = 0 ;
ll _res = 0 ;
rep ( i, 1 , idx)
if ( a[ i] == 1 )
if ( 2 * ( a[ i- 1 ] + a[ i+ 1 ] + a[ i- 1 ] * a[ i+ 1 ] ) > max_around) max_around = 2 * ( a[ i- 1 ] + a[ i+ 1 ] + a[ i- 1 ] * a[ i+ 1 ] ) ;
rep ( i, 1 , idx)
_res + = ( ll) a[ i] * a[ i] ;
_res + = max_around;
if ( _res > res) res = _res;
}
cout << res << "\n" ;
}
return 0 ;
}