integer,allocatable,dimension(:)::a,b,c,d
integer N,M,shortest,SpotName
read*,N,M
allocate(a(N))
allocate(b(N))
allocate(c(M))
allocate(d(M))
do i=1,N
  read*,a(i),b(i)
end do
!本当はなー！!!!N回回す後ろの作業といっしょにしたかったんだけどなああああああ
!後ろのデータ読み取るための処置が面倒くさいからー全部読み込むことにした
do i=1,M
  read*,c(i),d(i)
end do
do i=1,N
  shortest=10**9
  do j=1,M
    if (shortest > abs(a(i)-c(j))+abs(b(i)-d(j)) ) then
      SpotName = j
      shortest = abs(a(i)-c(j))+abs(b(i)-d(j))
    end if
  end do
  print"(I0)",SpotName
end do
end
; 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.0 = internal unnamed_addr global ptr null
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEd.0 = internal unnamed_addr global ptr null
@_QQcl.f24372918acd9dd2c416461edbc6aecd = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7425/source.f\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f24372918acd9dd2c416461edbc6aecd, i32 3)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEb.0, align 8, !tbaa !7
  %13 = load i32, ptr %1, align 4, !tbaa !3
  %14 = call i32 @llvm.smax.i32(i32 %13, i32 0)
  %15 = zext i32 %14 to i64
  %16 = shl nuw nsw i64 %15, 2
  %17 = call ptr @malloc(i64 %16)
  store ptr %17, ptr @_QFEc.0, align 8, !tbaa !7
  %18 = call ptr @malloc(i64 %16)
  store ptr %18, ptr @_QFEd.0, align 8, !tbaa !7
  %19 = icmp sgt i32 %7, 0
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %20 = 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 ]
  %21 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f24372918acd9dd2c416461edbc6aecd, i32 9)
  %.unpack496 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %22 = add nsw i64 %indvars.iv, -1
  %23 = getelementptr i32, ptr %.unpack496, i64 %22
  %24 = call i1 @_FortranAioInputInteger(ptr %21, ptr %23, i32 4)
  %.unpack508 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %25 = add nsw i64 %indvars.iv, -1
  %26 = getelementptr i32, ptr %.unpack508, i64 %25
  %27 = call i1 @_FortranAioInputInteger(ptr %21, ptr %26, i32 4)
  %28 = call i32 @_FortranAioEndIoStatement(ptr %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %20
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %29 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %13, %0 ]
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph522.preheader, label %._crit_edge523

.lr.ph522.preheader:                              ; preds = %._crit_edge
  %31 = zext i32 %29 to i64
  br label %.lr.ph522

.lr.ph522:                                        ; preds = %.lr.ph522.preheader, %.lr.ph522
  %indvars.iv534 = phi i64 [ 1, %.lr.ph522.preheader ], [ %indvars.iv.next535, %.lr.ph522 ]
  %32 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f24372918acd9dd2c416461edbc6aecd, i32 14)
  %.unpack472 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %33 = add nsw i64 %indvars.iv534, -1
  %34 = getelementptr i32, ptr %.unpack472, i64 %33
  %35 = call i1 @_FortranAioInputInteger(ptr %32, ptr %34, i32 4)
  %.unpack484 = load ptr, ptr @_QFEd.0, align 8, !tbaa !7
  %36 = add nsw i64 %indvars.iv534, -1
  %37 = getelementptr i32, ptr %.unpack484, i64 %36
  %38 = call i1 @_FortranAioInputInteger(ptr %32, ptr %37, i32 4)
  %39 = call i32 @_FortranAioEndIoStatement(ptr %32)
  %indvars.iv.next535 = add nuw nsw i64 %indvars.iv534, 1
  %exitcond537.not = icmp eq i64 %indvars.iv534, %31
  br i1 %exitcond537.not, label %._crit_edge523, label %.lr.ph522

._crit_edge523:                                   ; preds = %.lr.ph522, %._crit_edge
  %40 = load i32, ptr %2, align 4, !tbaa !3
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %.lr.ph531.preheader, label %._crit_edge532

.lr.ph531.preheader:                              ; preds = %._crit_edge523
  %42 = zext i32 %40 to i64
  br label %.lr.ph531

.lr.ph531:                                        ; preds = %.lr.ph531.preheader, %._crit_edge528
  %indvars.iv542 = phi i64 [ 1, %.lr.ph531.preheader ], [ %indvars.iv.next543, %._crit_edge528 ]
  %.0529 = phi i32 [ undef, %.lr.ph531.preheader ], [ %.1.lcssa, %._crit_edge528 ]
  %43 = load i32, ptr %1, align 4, !tbaa !3
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %.lr.ph527, label %._crit_edge528

.lr.ph527:                                        ; preds = %.lr.ph531
  %45 = zext i32 %43 to i64
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %46 = add nsw i64 %indvars.iv542, -1
  %47 = getelementptr i32, ptr %.unpack, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !3
  %.unpack436 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %.unpack448 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %49 = add nsw i64 %indvars.iv542, -1
  %50 = getelementptr i32, ptr %.unpack448, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !3
  %.unpack460 = load ptr, ptr @_QFEd.0, align 8, !tbaa !7
  br label %52

52:                                               ; preds = %.lr.ph527, %52
  %indvars.iv538 = phi i64 [ 1, %.lr.ph527 ], [ %indvars.iv.next539, %52 ]
  %.1525 = phi i32 [ %.0529, %.lr.ph527 ], [ %spec.select520, %52 ]
  %.0382524 = phi i32 [ 1000000000, %.lr.ph527 ], [ %spec.select, %52 ]
  %53 = add nsw i64 %indvars.iv538, -1
  %54 = getelementptr i32, ptr %.unpack436, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !3
  %56 = sub i32 %48, %55
  %57 = call i32 @llvm.abs.i32(i32 %56, i1 false)
  %58 = add nsw i64 %indvars.iv538, -1
  %59 = getelementptr i32, ptr %.unpack460, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !3
  %61 = sub i32 %51, %60
  %62 = call i32 @llvm.abs.i32(i32 %61, i1 false)
  %63 = add i32 %62, %57
  %64 = icmp sgt i32 %.0382524, %63
  %spec.select = call i32 @llvm.smin.i32(i32 %.0382524, i32 %63)
  %65 = trunc i64 %indvars.iv538 to i32
  %spec.select520 = select i1 %64, i32 %65, i32 %.1525
  %indvars.iv.next539 = add nuw nsw i64 %indvars.iv538, 1
  %exitcond541.not = icmp eq i64 %indvars.iv538, %45
  br i1 %exitcond541.not, label %._crit_edge528, label %52

._crit_edge528:                                   ; preds = %52, %.lr.ph531
  %.1.lcssa = phi i32 [ %.0529, %.lr.ph531 ], [ %spec.select520, %52 ]
  %66 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.f24372918acd9dd2c416461edbc6aecd, i32 24)
  %67 = call i1 @_FortranAioOutputInteger32(ptr %66, i32 %.1.lcssa)
  %68 = call i32 @_FortranAioEndIoStatement(ptr %66)
  %indvars.iv.next543 = add nuw nsw i64 %indvars.iv542, 1
  %exitcond545.not = icmp eq i64 %indvars.iv542, %42
  br i1 %exitcond545.not, label %._crit_edge532, label %.lr.ph531

._crit_edge532:                                   ; preds = %._crit_edge528, %._crit_edge523
  ret void
}

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 i32 @llvm.smax.i32(i32, i32) #1

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
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}
