#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ EOF;
int count_space(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, int *);
int main() {
  char line[32];
  int num_lines, num_spaces;
  int total_spaces, min_spaces;
  int i;
  while (scanf("%d\n", &num_lines) != EOF && num_lines != 0) {
    total_spaces = 0;
    min_spaces = 99;
    for (i = 0; i < num_lines; i++) {
      gets(line);
      num_spaces = count_space(line);
      if (min_spaces > num_spaces)
        min_spaces = num_spaces;
      total_spaces += num_spaces;
    }
    printf("%d\n", total_spaces - min_spaces * num_lines);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e7d(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x45(%rbp)
je     1181 <main+0x41>
cmpl   $0x0,-0x34(%rbp)
setne  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    1191 <main+0x51>
jmp    120d <main+0xcd>
movl   $0x0,-0x3c(%rbp)
movl   $0x63,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11f0 <main+0xb0>
lea    -0x30(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x30(%rbp),%rdi
call   1040 <count_space@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    11d9 <main+0x99>
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a6 <main+0x66>
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%eax
imul   -0x34(%rbp),%eax
sub    %eax,%esi
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
je     1200 <main+0xc0>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1200 <main+0xc0>
lea    0x10(%rsp),%r13
lea    0xe79(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax)
mov    $0x63,%ebx
test   %eax,%eax
jle    11d0 <main+0x90>
xor    %r12d,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r13,%rdi
call   1050 <gets@plt>
mov    %r13,%rdi
call   1040 <count_space@plt>
cmp    %eax,%ebx
cmovg  %eax,%ebx
add    %eax,%ebp
add    $0x1,%r12d
mov    0xc(%rsp),%eax
cmp    %eax,%r12d
jl     11a0 <main+0x60>
jmp    11d2 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
xor    %ebp,%ebp
imul   %eax,%ebx
sub    %ebx,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
je     1200 <main+0xc0>
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
br label %8
8: ; preds = %39, %0
%9 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %46
17: ; preds = %15
store i32 0, i32* %5
store i32 99, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%24 = call i32 @gets(i8* %23)
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%26 = call i32 @count_space(i8* %25)
store i32 %26, i32* %4
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = icmp sgt i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load i32, i32* %4
store i32 %31, i32* %6
br label %32
32: ; preds = %30, %22
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %36
36: ; preds = %32
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %18
39: ; preds = %18
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = load i32, i32* %3
%43 = mul nsw i32 %41, %42
%44 = sub nsw i32 %40, %43
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %8
46: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i64, i64* @EOF
%7 = icmp ne i64 %5, %6
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %39
11: ; preds = %0, %26
%12 = phi i32 [ %36, %26 ], [ %8, %0 ]
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %11, %14
%15 = phi i32 [ %23, %14 ], [ 0, %11 ]
%16 = phi i32 [ %21, %14 ], [ 99, %11 ]
%17 = phi i32 [ %22, %14 ], [ 0, %11 ]
%18 = call i32 @gets(i8* %3)
%19 = call i32 @count_space(i8* %3)
%20 = icmp sgt i32 %16, %19
%21 = select i1 %20, i32 %19, i32 %16
%22 = add nsw i32 %19, %17
%23 = add nuw nsw i32 %15, 1
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %14, label %26
26: ; preds = %14, %11
%27 = phi i32 [ 0, %11 ], [ %22, %14 ]
%28 = phi i32 [ 99, %11 ], [ %21, %14 ]
%29 = phi i32 [ %12, %11 ], [ %24, %14 ]
%30 = mul nsw i32 %29, %28
%31 = sub nsw i32 %27, %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%34 = load i64, i64* @EOF
%35 = icmp ne i64 %33, %34
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 0
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %11, label %39
39: ; preds = %26, %0
ret i32 0
}