1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11645 - Bits
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=78&problem=2692&mosmsg=Submission+received+with+ID+8041076
*
* @author Evgeni Pavlidis
* @version 1.0, 06/17/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 0.340
*/

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
long n, pow, caseNumber = 1;
BigInteger result;

BigInteger[] bits = new BigInteger[64];
BigInteger two = new BigInteger("2");


// precalc the adjacent bits of numbers that are a power of 2
bits[0] = BigInteger.ZERO;
bits[1] = BigInteger.ZERO;
bits[2] = BigInteger.ZERO;
bits[3] = BigInteger.ONE;
for(int i = 4; i < 64; i++)
bits[i] = bits[i-1].multiply(two).add(BigInteger.valueOf(1L << (i-3)));

while((n = Long.parseLong(reader.readLine())) >= 0)
{
result = BigInteger.ZERO;

pow = 1;
// sum up all kombination with powers of 2
for(int i = 1; i < 64; i++, pow = pow << 1)
if((pow & n) > 0)
result = result.add(bits[i]);

pow = 1;
// sum up remaining adjacent bits
for(int i = 1; i < 63; i++, pow = pow << 1)
if((pow & n) > 0 && (((pow << 1) & n) > 0))
result = result.add(BigInteger.valueOf(n % pow + 1));

System.out.println("Case " + caseNumber++ + ": " + result);
}
}
}