#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__ abs(double);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int mnum;
  double iniSpend[1000];
  double sum, avg, distanceSum;
  scanf("%d", &mnum);
  while (mnum != 0) {
    int ctr;
    sum = 0;
    for (ctr = 0; ctr < mnum; ctr++) {
      scanf("%lf", &iniSpend[ctr]);
      sum += iniSpend[ctr];
    }
    avg = sum / mnum;
    distanceSum = 0;
    for (ctr = 0; ctr < mnum; ctr++) {
      distanceSum += abs(iniSpend[ctr] - avg);
    }
    printf("%.2lf\n", distanceSum / 2);
    scanf("%d", &mnum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebf(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1293 <main+0x163>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f58(%rbp)
ff
movl   $0x0,-0x1f6c(%rbp)
mov    -0x1f6c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d9 <main+0xa9>
movslq -0x1f6c(%rbp),%rax
lea    -0x1f50(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x1f6c(%rbp),%rax
movsd  -0x1f50(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x1f58(%rbp),%xmm0
ff
movsd  %xmm0,-0x1f58(%rbp)
ff
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f6c(%rbp)
jmp    1173 <main+0x43>
movsd  -0x1f58(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f60(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f68(%rbp)
ff
movl   $0x0,-0x1f6c(%rbp)
mov    -0x1f6c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125c <main+0x12c>
movslq -0x1f6c(%rbp),%rax
movsd  -0x1f50(%rbp,%rax,8),%xmm0
ff ff
subsd  -0x1f60(%rbp),%xmm0
ff
call   1030 <abs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x1f68(%rbp),%xmm0
ff
movsd  %xmm0,-0x1f68(%rbp)
ff
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f6c(%rbp)
jmp    1207 <main+0xd7>
movsd  -0x1f68(%rbp),%xmm0
ff
movsd  0xd94(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd98(%rip),%rdi
call   1040 <printf@plt>
lea    0xd85(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
jmp    1154 <main+0x24>
xor    %eax,%eax
add    $0x1f70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f68,%rsp
lea    0xec0(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     125c <main+0x12c>
lea    0xea4(%rip),%r13
lea    0xea1(%rip),%r14
lea    0xe93(%rip),%r15
lea    0xc(%rsp),%r12
jmp    11ad <main+0x7d>
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
mulsd  0xe74(%rip),%xmm0
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     125c <main+0x12c>
test   %eax,%eax
jle    1180 <main+0x50>
xorps  %xmm1,%xmm1
lea    0x20(%rsp),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x18(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsd  0x18(%rsp),%xmm1
addsd  (%rbx),%xmm1
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x8,%rbx
cmp    %rax,%rbp
jl     11c0 <main+0x90>
test   %eax,%eax
jle    1180 <main+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm1,0x18(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp,%rbx,8),%xmm0
subsd  %xmm1,%xmm0
call   1030 <abs@plt>
movsd  0x18(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xe0>
jmp    1184 <main+0x54>
xor    %eax,%eax
add    $0x1f68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [7 x i8] c"%.2lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x double]
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %54, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %59
12: ; preds = %9
store double 0.000000e+00, double* %4
store i32 0, i32* %7
br label %13
13: ; preds = %28, %12
%14 = load i32, i32* %7
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %19
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %20)
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %23
%25 = load double, double* %24
%26 = load double, double* %4
%27 = fadd double %26, %25
store double %27, double* %4
br label %28
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %13
31: ; preds = %13
%32 = load double, double* %4
%33 = load i32, i32* %2
%34 = sitofp i32 %33 to double
%35 = fdiv double %32, %34
store double %35, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
br label %36
36: ; preds = %51, %31
%37 = load i32, i32* %7
%38 = load i32, i32* %2
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %54
40: ; preds = %36
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %42
%44 = load double, double* %43
%45 = load double, double* %5
%46 = fsub double %44, %45
%47 = call i64 @abs(double %46)
%48 = sitofp i64 %47 to double
%49 = load double, double* %6
%50 = fadd double %49, %48
store double %50, double* %6
br label %51
51: ; preds = %40
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %36
54: ; preds = %36
%55 = load double, double* %6
%56 = fdiv double %55, 2.000000e+00
%57 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %56)
%58 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
59: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [7 x i8] c"%.2lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x double]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [1000 x double]* %2 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %46, label %8
8: ; preds = %0, %39
%9 = phi i32 [ %44, %39 ], [ %6, %0 ]
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %8, %11
%12 = phi i64 [ %18, %11 ], [ 0, %8 ]
%13 = phi double [ %17, %11 ], [ 0.000000e+00, %8 ]
%14 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 0, i64 %12
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %14)
%16 = load double, double* %14
%17 = fadd double %13, %16
%18 = add nuw nsw i64 %12, 1
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %11, label %22
22: ; preds = %11
%23 = sitofp i32 %19 to double
%24 = fdiv double %17, %23
%25 = icmp sgt i32 %19, 0
br i1 %25, label %26, label %39
26: ; preds = %22, %26
%27 = phi i64 [ %35, %26 ], [ 0, %22 ]
%28 = phi double [ %34, %26 ], [ 0.000000e+00, %22 ]
%29 = getelementptr inbounds [1000 x double], [1000 x double]* %2, i64 0, i64 %27
%30 = load double, double* %29
%31 = fsub double %30, %24
%32 = call i64 @abs(double %31)
%33 = sitofp i64 %32 to double
%34 = fadd double %28, %33
%35 = add nuw nsw i64 %27, 1
%36 = load i32, i32* %1
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %26, label %39
39: ; preds = %26, %8, %22
%40 = phi double [ 0.000000e+00, %22 ], [ 0.000000e+00, %8 ], [ %34, %26 ]
%41 = fmul double %40, 5.000000e-01
%42 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %41)
%43 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%44 = load i32, i32* %1
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %8
46: ; preds = %39, %0
ret i32 0
}