//google_codejam_a.java import java.util.Scanner; public class google_codejam_a { public static void main(String args[]){ new google_codejam_a().go();} Scanner in = new Scanner(System.in); public void go(){ int total = in.nextInt(); for (int i = 0; i < total; i++) { /* for each case: int result = 0; add up each digit from left, check sum with next left most digit, */ int max = in.nextInt(); int a = in.nextInt(); int standing = 0; int result = 0; for (int index = 0; index < max + 1; index++) { int curr = a / (int) Math.pow(10, max - index); if (standing < result) { result += index - standing; standing += index - standing; } standing += curr; } System.out.printf("Case #%d: %d\n", i + 1, result); } } }