#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}
int main(){
	int n,i,r=0,t=1;
	int arr[999];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&arr[i]);
	qsort(arr,n,4,compare);
	for(i=0;i<n;i++){
		r+=t*arr[i];
		t=-t;
	}
	printf("%d\n",r);
	return 0;
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_598/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_598/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@.str.1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @compare(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i32, ptr %b, align 4, !tbaa !5
  %1 = load i32, ptr %a, align 4, !tbaa !5
  %sub = sub nsw i32 %0, %1
  ret i32 %sub
}

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #1 {
entry:
  %n = alloca i32, align 4
  %arr = alloca [999 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %n) #5
  call void @llvm.lifetime.start.p0(i64 3996, ptr nonnull %arr) #5
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n)
  %0 = load i32, ptr %n, align 4, !tbaa !5
  %cmp19 = icmp sgt i32 %0, 0
  br i1 %cmp19, label %for.body, label %entry.for.end_crit_edge

entry.for.end_crit_edge:                          ; preds = %entry
  %.pre = sext i32 %0 to i64
  br label %for.end

for.body:                                         ; preds = %entry, %for.body
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  %arrayidx = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %arrayidx)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %1 = load i32, ptr %n, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %cmp = icmp slt i64 %indvars.iv.next, %2
  br i1 %cmp, label %for.body, label %for.end

for.end:                                          ; preds = %for.body, %entry.for.end_crit_edge
  %conv.pre-phi = phi i64 [ %.pre, %entry.for.end_crit_edge ], [ %2, %for.body ]
  call void @qsort(ptr noundef nonnull %arr, i64 noundef %conv.pre-phi, i64 noundef 4, ptr noundef nonnull @compare) #5
  %3 = load i32, ptr %n, align 4, !tbaa !5
  %cmp321 = icmp sgt i32 %3, 0
  br i1 %cmp321, label %for.body5.preheader, label %for.end10

for.body5.preheader:                              ; preds = %for.end
  %wide.trip.count = zext i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %4 = icmp ult i32 %3, 4
  br i1 %4, label %for.end10.loopexit.unr-lcssa, label %for.body5.preheader.new

for.body5.preheader.new:                          ; preds = %for.body5.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %for.body5

for.body5:                                        ; preds = %for.body5, %for.body5.preheader.new
  %indvars.iv28 = phi i64 [ 0, %for.body5.preheader.new ], [ %indvars.iv.next29.3, %for.body5 ]
  %r.023 = phi i32 [ 0, %for.body5.preheader.new ], [ %add.3, %for.body5 ]
  %niter = phi i64 [ 0, %for.body5.preheader.new ], [ %niter.next.3, %for.body5 ]
  %arrayidx7 = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv28
  %5 = load i32, ptr %arrayidx7, align 16, !tbaa !5
  %add = add nsw i32 %5, %r.023
  %indvars.iv.next29 = or i64 %indvars.iv28, 1
  %arrayidx7.1 = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv.next29
  %6 = load i32, ptr %arrayidx7.1, align 4, !tbaa !5
  %indvars.iv.next29.1 = or i64 %indvars.iv28, 2
  %arrayidx7.2 = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv.next29.1
  %7 = load i32, ptr %arrayidx7.2, align 8, !tbaa !5
  %indvars.iv.next29.2 = or i64 %indvars.iv28, 3
  %arrayidx7.3 = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv.next29.2
  %8 = load i32, ptr %arrayidx7.3, align 4, !tbaa !5
  %9 = add i32 %add, %7
  %10 = add i32 %6, %8
  %add.3 = sub i32 %9, %10
  %indvars.iv.next29.3 = add nuw nsw i64 %indvars.iv28, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %for.end10.loopexit.unr-lcssa, label %for.body5

for.end10.loopexit.unr-lcssa:                     ; preds = %for.body5, %for.body5.preheader
  %add.lcssa.ph = phi i32 [ undef, %for.body5.preheader ], [ %add.3, %for.body5 ]
  %indvars.iv28.unr = phi i64 [ 0, %for.body5.preheader ], [ %indvars.iv.next29.3, %for.body5 ]
  %r.023.unr = phi i32 [ 0, %for.body5.preheader ], [ %add.3, %for.body5 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %for.end10, label %for.body5.epil

for.body5.epil:                                   ; preds = %for.end10.loopexit.unr-lcssa, %for.body5.epil
  %indvars.iv28.epil = phi i64 [ %indvars.iv.next29.epil, %for.body5.epil ], [ %indvars.iv28.unr, %for.end10.loopexit.unr-lcssa ]
  %t.024.epil = phi i32 [ %sub.epil, %for.body5.epil ], [ 1, %for.end10.loopexit.unr-lcssa ]
  %r.023.epil = phi i32 [ %add.epil, %for.body5.epil ], [ %r.023.unr, %for.end10.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %for.body5.epil ], [ 0, %for.end10.loopexit.unr-lcssa ]
  %arrayidx7.epil = getelementptr inbounds [999 x i32], ptr %arr, i64 0, i64 %indvars.iv28.epil
  %11 = load i32, ptr %arrayidx7.epil, align 4, !tbaa !5
  %mul.epil = mul nsw i32 %11, %t.024.epil
  %add.epil = add nsw i32 %mul.epil, %r.023.epil
  %sub.epil = sub nsw i32 0, %t.024.epil
  %indvars.iv.next29.epil = add nuw nsw i64 %indvars.iv28.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %for.end10, label %for.body5.epil, !llvm.loop !9

for.end10:                                        ; preds = %for.end10.loopexit.unr-lcssa, %for.body5.epil, %for.end
  %r.0.lcssa = phi i32 [ 0, %for.end ], [ %add.lcssa.ph, %for.end10.loopexit.unr-lcssa ], [ %add.epil, %for.body5.epil ]
  %call11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %r.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 3996, ptr nonnull %arr) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %n) #5
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nofree "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
