program count_median
  implicit none
  integer :: n, i
  integer, dimension(200000) :: a = 0, b = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i), b(i)
  end do
  call quick_sort(a(1:n))
  call quick_sort(b(1:n))
  write(*,'(i0)') merge(b(n/2)+b(n/2+1)-a(n/2)-a(n/2+1)+1,b((n+1)/2)-a((n+1)/2)+1,mod(n,2) == 0)
contains
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program count_median
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
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"

@_QFEa = internal global [200000 x i32] zeroinitializer
@_QFEb = internal global [200000 x i32] zeroinitializer
@_QQcl.0d9918a2ebbeadfd81d4b7a1a0cd0435 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1306/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0d9918a2ebbeadfd81d4b7a1a0cd0435, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %9 = zext i32 %7 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0d9918a2ebbeadfd81d4b7a1a0cd0435, i32 7)
  %11 = add nsw i64 %indvars.iv, -1
  %12 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %11
  %13 = call i1 @_FortranAioInputInteger(ptr %10, ptr %12, i32 4)
  %14 = getelementptr [200000 x i32], ptr @_QFEb, i64 0, i64 %11
  %15 = call i1 @_FortranAioInputInteger(ptr %10, ptr %14, i32 4)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %9
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %3, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %17 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %7, %0 ]
  %18 = call i32 @llvm.smax.i32(i32 %17, i32 0)
  %19 = zext i32 %18 to i64
  store ptr @_QFEa, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 1
  store i64 %19, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  call void @_QFPquick_sort(ptr nonnull %2)
  %20 = load i32, ptr %3, align 4, !tbaa !3
  %21 = call i32 @llvm.smax.i32(i32 %20, i32 0)
  %22 = zext i32 %21 to i64
  store ptr @_QFEb, ptr %1, align 8, !tbaa !7
  %.fca.1.gep6 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep6, align 8, !tbaa !7
  %.fca.2.gep8 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep8, align 8, !tbaa !7
  %.fca.3.gep10 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep10, align 4, !tbaa !7
  %.fca.4.gep12 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep12, align 1, !tbaa !7
  %.fca.5.gep14 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep14, align 2, !tbaa !7
  %.fca.6.gep16 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep16, align 1, !tbaa !7
  %.fca.7.0.0.gep18 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep18, align 8, !tbaa !7
  %.fca.7.0.1.gep20 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %22, ptr %.fca.7.0.1.gep20, align 8, !tbaa !7
  %.fca.7.0.2.gep22 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep22, align 8, !tbaa !7
  call void @_QFPquick_sort(ptr nonnull %1)
  %23 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.0d9918a2ebbeadfd81d4b7a1a0cd0435, i32 11)
  %24 = load i32, ptr %3, align 4, !tbaa !3
  %25 = sdiv i32 %24, 2
  %narrow = add nsw i32 %25, -1
  %26 = sext i32 %narrow to i64
  %27 = getelementptr [200000 x i32], ptr @_QFEb, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !3
  %29 = sext i32 %25 to i64
  %30 = getelementptr [200000 x i32], ptr @_QFEb, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !3
  %32 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %26
  %33 = load i32, ptr %32, align 4, !tbaa !3
  %34 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %29
  %35 = load i32, ptr %34, align 4, !tbaa !3
  %.neg25 = add i32 %31, %28
  %36 = add i32 %33, %35
  %37 = sub i32 %.neg25, %36
  %38 = add i32 %24, 1
  %39 = sdiv i32 %38, 2
  %narrow23 = add nsw i32 %39, -1
  %40 = sext i32 %narrow23 to i64
  %41 = getelementptr [200000 x i32], ptr @_QFEb, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !3
  %43 = getelementptr [200000 x i32], ptr @_QFEa, i64 0, i64 %40
  %44 = load i32, ptr %43, align 4, !tbaa !3
  %45 = sub i32 %42, %44
  %46 = and i32 %24, 1
  %47 = icmp eq i32 %46, 0
  %.v = select i1 %47, i32 %37, i32 %45
  %48 = add i32 %.v, 1
  %49 = call i1 @_FortranAioOutputInteger32(ptr %23, i32 %48)
  %50 = call i32 @_FortranAioEndIoStatement(ptr %23)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none)
define void @_QFPquick_sort(ptr nocapture readonly %0) local_unnamed_addr #0 {
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %4 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  %5 = load i64, ptr %4, align 8, !tbaa !7
  %6 = trunc i64 %5 to i32
  %7 = add i32 %6, 1
  %8 = sdiv i32 %7, 2
  %9 = load ptr, ptr %0, align 8, !tbaa !7
  %10 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  %11 = load i64, ptr %10, align 8, !tbaa !7
  %12 = load i32, ptr %9, align 4, !tbaa !3
  %narrow = add nsw i32 %8, -1
  %13 = sext i32 %narrow to i64
  %14 = mul i64 %11, %13
  %15 = getelementptr i8, ptr %9, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !3
  %sext = shl i64 %5, 32
  %17 = ashr exact i64 %sext, 32
  %18 = add nsw i64 %17, -1
  %19 = mul i64 %18, %11
  %20 = getelementptr i8, ptr %9, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !3
  %22 = tail call i32 @llvm.smax.i32(i32 %12, i32 %16)
  %23 = tail call i32 @llvm.smax.i32(i32 %22, i32 %21)
  %24 = tail call i32 @llvm.smin.i32(i32 %12, i32 %16)
  %25 = tail call i32 @llvm.smin.i32(i32 %24, i32 %21)
  %.neg52 = add i32 %16, %12
  %26 = add i32 %.neg52, %21
  %27 = add i32 %25, %23
  %28 = sub i32 %26, %27
  br label %.outer

.outer:                                           ; preds = %66, %1
  %.047.ph = phi i32 [ %36, %66 ], [ 1, %1 ]
  %.0.ph = phi i32 [ %45, %66 ], [ %6, %1 ]
  br label %29

29:                                               ; preds = %29, %.outer
  %.047 = phi i32 [ %36, %29 ], [ %.047.ph, %.outer ]
  %30 = sext i32 %.047 to i64
  %31 = add nsw i64 %30, -1
  %32 = mul i64 %31, %11
  %33 = getelementptr i8, ptr %9, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !3
  %35 = icmp slt i32 %34, %28
  %36 = add i32 %.047, 1
  br i1 %35, label %29, label %.preheader

.preheader:                                       ; preds = %29
  %37 = getelementptr i8, ptr %9, i64 %32
  br label %38

38:                                               ; preds = %38, %.preheader
  %.1 = phi i32 [ %45, %38 ], [ %.0.ph, %.preheader ]
  %39 = sext i32 %.1 to i64
  %40 = add nsw i64 %39, -1
  %41 = mul i64 %40, %11
  %42 = getelementptr i8, ptr %9, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !3
  %44 = icmp sgt i32 %43, %28
  %45 = add i32 %.1, -1
  br i1 %44, label %38, label %46

46:                                               ; preds = %38
  %.not = icmp slt i32 %.047, %.1
  br i1 %.not, label %66, label %47

47:                                               ; preds = %46
  %48 = add i32 %.047, -1
  %49 = icmp sgt i32 %48, 1
  br i1 %49, label %50, label %52

50:                                               ; preds = %47
  %51 = zext i32 %48 to i64
  store ptr %9, ptr %2, align 8, !tbaa !7
  %.fca.1.gep30 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep30, align 8, !tbaa !7
  %.fca.2.gep32 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep32, align 8, !tbaa !7
  %.fca.3.gep34 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep34, align 4, !tbaa !7
  %.fca.4.gep36 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep36, align 1, !tbaa !7
  %.fca.5.gep38 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep38, align 2, !tbaa !7
  %.fca.6.gep40 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep40, align 1, !tbaa !7
  %.fca.7.0.0.gep42 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep42, align 8, !tbaa !7
  %.fca.7.0.1.gep44 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 1
  store i64 %51, ptr %.fca.7.0.1.gep44, align 8, !tbaa !7
  %.fca.7.0.2.gep46 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 2
  store i64 %11, ptr %.fca.7.0.2.gep46, align 8, !tbaa !7
  call void @_QFPquick_sort(ptr nonnull %2)
  br label %52

52:                                               ; preds = %50, %47
  %53 = add i32 %.1, 1
  %54 = icmp slt i32 %53, %6
  br i1 %54, label %55, label %65

55:                                               ; preds = %52
  %56 = sext i32 %53 to i64
  %57 = load i64, ptr %10, align 8, !tbaa !7
  %58 = load ptr, ptr %0, align 8, !tbaa !7
  %59 = add nsw i64 %56, -1
  %60 = mul i64 %57, %59
  %61 = getelementptr i8, ptr %58, i64 %60
  %62 = sub nsw i64 %17, %56
  %63 = tail call i64 @llvm.smax.i64(i64 %62, i64 -1)
  %64 = add nsw i64 %63, 1
  store ptr %61, ptr %3, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 1
  store i64 %64, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 7, i64 0, i64 2
  store i64 %57, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  call void @_QFPquick_sort(ptr nonnull %3)
  br label %65

65:                                               ; preds = %55, %52
  ret void

66:                                               ; preds = %46
  %67 = getelementptr i8, ptr %9, i64 %41
  %68 = xor i32 %43, %34
  store i32 %68, ptr %37, align 4, !tbaa !3
  %69 = load i32, ptr %67, align 4, !tbaa !3
  %70 = xor i32 %69, %68
  store i32 %70, ptr %67, align 4, !tbaa !3
  %71 = load i32, ptr %37, align 4, !tbaa !3
  %72 = xor i32 %71, %70
  store i32 %72, ptr %37, align 4, !tbaa !3
  br label %.outer
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { nofree nosync nounwind memory(readwrite, inaccessiblemem: none) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
