#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;
scalar_t__ abs(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int main() {
  int num_stack;
  int stack[64];
  int count, i;
  int avr, num_move;
  count = 1;
  while (scanf("%d\n", &num_stack) != EOF && num_stack != 0) {
    for (avr = 0, i = 0; i < num_stack; i++) {
      scanf("%d", &stack[i]);
      avr += stack[i];
    }
    avr /= num_stack;
    num_move = 0;
    for (i = 0; i < num_stack; i++) {
      num_move += abs(avr - stack[i]);
    }
    num_move /= 2;
    printf("Set #%d\n", count);
    printf("The minimum number of moves is %d.\n", num_move);
    printf("\n");
    count++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x114(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e80(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x121(%rbp)
je     1184 <main+0x54>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x121(%rbp)
mov    -0x121(%rbp),%al
test   $0x1,%al
jne    1197 <main+0x67>
jmp    12dc <main+0x1ac>
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1209 <main+0xd9>
movslq -0x118(%rbp),%rax
lea    -0x110(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2a(%rip),%rdi
call   1050 <scanf@plt>
movslq -0x118(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%eax
add    -0x11c(%rbp),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11ab <main+0x7b>
mov    -0x8(%rbp),%ecx
mov    -0x11c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127e <main+0x14e>
mov    -0x11c(%rbp),%edi
movslq -0x118(%rbp),%rax
sub    -0x110(%rbp,%rax,4),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0x120(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x120(%rbp)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    122f <main+0xff>
mov    -0x120(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x120(%rbp)
mov    -0x114(%rbp),%esi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x120(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    114c <main+0x1c>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xeb0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
je     1271 <main+0x131>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1271 <main+0x131>
mov    $0x1,%r15d
lea    0xe75(%rip),%r12
lea    0xc(%rsp),%r13
mov    $0x0,%ebp
test   %eax,%eax
jle    1212 <main+0xd2>
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    (%rbx),%r14d
add    $0x1,%rbp
movslq 0xc(%rsp),%rcx
add    $0x4,%rbx
cmp    %rcx,%rbp
jl     11b0 <main+0x70>
mov    %r14d,%eax
cltd
idiv   %ecx
test   %ecx,%ecx
jle    1210 <main+0xd0>
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
sub    0x10(%rsp,%rbx,4),%edi
call   1040 <abs@plt>
add    %eax,%ebp
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0xb0>
jmp    1212 <main+0xd2>
xchg   %ax,%ax
xor    %ebp,%ebp
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
lea    0xde1(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdbb(%rip),%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
je     1271 <main+0x131>
add    $0x1,%r15d
mov    0xc(%rsp),%eax
test   %eax,%eax
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x118,%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
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"Set #%d\0A\00"
@.str.3 = [36 x i8] c"The minimum number of moves is %d.\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
br label %8
8: ; preds = %59, %0
%9 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%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* %2
%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 %69
17: ; preds = %15
store i32 0, i32* %6
store i32 0, i32* %5
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %24
%26 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, %30
store i32 %32, i32* %6
br label %33
33: ; preds = %22
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %18
36: ; preds = %18
%37 = load i32, i32* %2
%38 = load i32, i32* %6
%39 = sdiv i32 %38, %37
store i32 %39, i32* %6
store i32 0, i32* %7
store i32 0, i32* %5
br label %40
40: ; preds = %56, %36
%41 = load i32, i32* %5
%42 = load i32, i32* %2
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %59
44: ; preds = %40
%45 = load i32, i32* %6
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = sub nsw i32 %45, %49
%51 = call i64 @abs(i32 %50)
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = add nsw i64 %53, %51
%55 = trunc i64 %54 to i32
store i32 %55, i32* %7
br label %56
56: ; preds = %44
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %40
59: ; preds = %40
%60 = load i32, i32* %7
%61 = sdiv i32 %60, 2
store i32 %61, i32* %7
%62 = load i32, i32* %4
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %7
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %8
69: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@EOF = global i64 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"Set #%d\0A\00"
@.str.3 = [36 x i8] c"The minimum number of moves is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [64 x i32]* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i64, i64* @EOF
%7 = icmp ne i64 %5, %6
%8 = load i32, i32* %1
%9 = icmp ne i32 %8, 0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %55
11: ; preds = %0, %42
%12 = phi i32 [ %52, %42 ], [ %8, %0 ]
%13 = phi i32 [ %48, %42 ], [ 1, %0 ]
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %42
15: ; preds = %11, %15
%16 = phi i64 [ %22, %15 ], [ 0, %11 ]
%17 = phi i32 [ %21, %15 ], [ 0, %11 ]
%18 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %16
%19 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %18
%21 = add nsw i32 %20, %17
%22 = add nuw nsw i64 %16, 1
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %15, label %26
26: ; preds = %15
%27 = sdiv i32 %21, %23
%28 = icmp sgt i32 %23, 0
br i1 %28, label %29, label %42
29: ; preds = %26, %29
%30 = phi i64 [ %38, %29 ], [ 0, %26 ]
%31 = phi i32 [ %37, %29 ], [ 0, %26 ]
%32 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %30
%33 = load i32, i32* %32
%34 = sub nsw i32 %27, %33
%35 = call i64 @abs(i32 %34)
%36 = trunc i64 %35 to i32
%37 = add i32 %31, %36
%38 = add nuw nsw i64 %30, 1
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %29, label %42
42: ; preds = %29, %11, %26
%43 = phi i32 [ 0, %26 ], [ 0, %11 ], [ %37, %29 ]
%44 = sdiv i32 %43, 2
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%47 = call i32 @putchar(i32 10)
%48 = add nuw nsw i32 %13, 1
%49 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%50 = load i64, i64* @EOF
%51 = icmp ne i64 %49, %50
%52 = load i32, i32* %1
%53 = icmp ne i32 %52, 0
%54 = select i1 %51, i1 %53, i1 false
br i1 %54, label %11, label %55
55: ; preds = %42, %0
ret i32 0
}