program main
  implicit none
  integer(8) :: n, i, j, k, p, q, m, y(0:5), dp(0:12), dppre(0:12)
  character(10 ** 5) :: s

  m = 10 ** 9 + 7
  y(0:5) = (/1, 10, 9, 12, 3, 4/)
  dp(0) = 1  ! dp(x) は (その桁までの値 % 13) == x となる通りの数
  dp(1:) = 0

  read (*, *) s
  n = len_trim(s)
  do i = 1, n  ! 1の位から順に
    dppre(:) = dp(:)
    dp(:) = 0
    j = n - i + 1
    if (s(j:j) == "?") then
      do p = 0, 9
        q = y(modulo(i - 1, 6_8)) * p  ! これだけ値が増える
        do k = 0, 12  ! もらうDP
          dp(k) = modulo(dp(k) + dppre(modulo(k - q, 13_8)), m)
        end do
      end do
    else
      read (s(j:j), *) p
      q = y(modulo(i - 1, 6_8)) * p  ! これだけ値が増える
      do k = 0, 12  ! もらうDP
        dp(k) = modulo(dp(k) + dppre(modulo(k - q, 13_8)), m)
      end do
    end if
  end do
  write (*, "(i0)") dp(5)
end program main

; 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"

@_QFEdp = internal unnamed_addr global [13 x i64] undef
@_QFEdppre = internal unnamed_addr global [13 x i64] undef
@_QFEs = internal global [100000 x i8] undef
@_QFEy = internal unnamed_addr global [6 x i64] undef
@_QQro.6xi8.c0a9cabdaa9dc8c8461d3d3218befc58 = internal unnamed_addr constant [6 x i64] [i64 1, i64 10, i64 9, i64 12, i64 3, i64 4]
@_QQcl.098ffcedde1d0136e4b7dc4636c19284 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3671/source.f\00"
@_QQcl.3F = linkonce constant [1 x i8] c"?"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) @_QFEy, ptr noundef nonnull align 16 dereferenceable(48) @_QQro.6xi8.c0a9cabdaa9dc8c8461d3d3218befc58, i64 48, i1 false), !tbaa !3
  store i64 1, ptr @_QFEdp, align 16, !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(96) getelementptr inbounds ([13 x i64], ptr @_QFEdp, i64 0, i64 1), i8 0, i64 96, i1 false), !tbaa !3
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.098ffcedde1d0136e4b7dc4636c19284, i32 11)
  %3 = tail call i1 @_FortranAioInputAscii(ptr %2, ptr nonnull @_QFEs, i64 100000)
  %4 = tail call i32 @_FortranAioEndIoStatement(ptr %2)
  br label %5

5:                                                ; preds = %0, %5
  %6 = phi i64 [ 99999, %0 ], [ %10, %5 ]
  %7 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !3
  %9 = icmp eq i8 %8, 32
  %10 = add nsw i64 %6, -1
  %11 = icmp ne i64 %6, 0
  %12 = and i1 %9, %11
  br i1 %12, label %5, label %13

13:                                               ; preds = %5
  %14 = shl i64 %6, 32
  %sext = add i64 %14, 4294967296
  %15 = ashr exact i64 %sext, 32
  %16 = select i1 %9, i64 0, i64 %15
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.preheader25, label %._crit_edge

.preheader25:                                     ; preds = %13, %.loopexit
  %18 = phi i64 [ %83, %.loopexit ], [ 1, %13 ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) @_QFEdppre, ptr noundef nonnull align 16 dereferenceable(104) @_QFEdp, i64 104, i1 false), !tbaa !3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(104) @_QFEdp, i8 0, i64 104, i1 false), !tbaa !3
  %19 = sub nsw i64 %16, %18
  %20 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %19
  %21 = call i32 @_FortranACharacterCompareScalar1(ptr %20, ptr nonnull @_QQcl.3F, i64 1, i64 1)
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.preheader, label %53

.preheader:                                       ; preds = %.preheader25
  %23 = add nsw i64 %18, -1
  %.urem = urem i64 %23, 6
  %24 = getelementptr [6 x i64], ptr @_QFEy, i64 0, i64 %.urem
  %25 = load i64, ptr %24, align 8, !tbaa !3
  br label %26

26:                                               ; preds = %.preheader, %50
  %27 = phi i64 [ 0, %.preheader ], [ %51, %50 ]
  %28 = mul i64 %25, %27
  br label %29

29:                                               ; preds = %26, %29
  %30 = phi i64 [ 0, %26 ], [ %49, %29 ]
  %31 = getelementptr [13 x i64], ptr @_QFEdp, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !3
  %33 = sub i64 %30, %28
  %34 = srem i64 %33, 13
  %35 = icmp slt i64 %33, 0
  %36 = icmp ne i64 %34, 0
  %37 = and i1 %35, %36
  %38 = add nsw i64 %34, 13
  %39 = select i1 %37, i64 %38, i64 %34
  %40 = getelementptr [13 x i64], ptr @_QFEdppre, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !3
  %42 = add i64 %41, %32
  %43 = srem i64 %42, 1000000007
  %44 = icmp slt i64 %42, 0
  %45 = icmp ne i64 %43, 0
  %46 = and i1 %44, %45
  %47 = add nsw i64 %43, 1000000007
  %48 = select i1 %46, i64 %47, i64 %43
  store i64 %48, ptr %31, align 8, !tbaa !3
  %49 = add nuw nsw i64 %30, 1
  %exitcond31.not = icmp eq i64 %49, 13
  br i1 %exitcond31.not, label %50, label %29

50:                                               ; preds = %29
  %51 = add nuw nsw i64 %27, 1
  %exitcond32.not = icmp eq i64 %51, 10
  br i1 %exitcond32.not, label %52, label %26

52:                                               ; preds = %50
  store i64 10, ptr %1, align 8, !tbaa !3
  br label %.loopexit

53:                                               ; preds = %.preheader25
  %54 = call ptr @_FortranAioBeginInternalListInput(ptr %20, i64 1, ptr null, i64 0, ptr nonnull @_QQcl.098ffcedde1d0136e4b7dc4636c19284, i32 25)
  %55 = call i1 @_FortranAioInputInteger(ptr %54, ptr nonnull %1, i32 8)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %54)
  %57 = add nsw i64 %18, -1
  %.urem33 = urem i64 %57, 6
  %58 = getelementptr [6 x i64], ptr @_QFEy, i64 0, i64 %.urem33
  %59 = load i64, ptr %58, align 8, !tbaa !3
  %60 = load i64, ptr %1, align 8, !tbaa !3
  %61 = mul i64 %60, %59
  br label %62

62:                                               ; preds = %53, %62
  %63 = phi i64 [ 0, %53 ], [ %82, %62 ]
  %64 = getelementptr [13 x i64], ptr @_QFEdp, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !3
  %66 = sub i64 %63, %61
  %67 = srem i64 %66, 13
  %68 = icmp slt i64 %66, 0
  %69 = icmp ne i64 %67, 0
  %70 = and i1 %68, %69
  %71 = add nsw i64 %67, 13
  %72 = select i1 %70, i64 %71, i64 %67
  %73 = getelementptr [13 x i64], ptr @_QFEdppre, i64 0, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !3
  %75 = add i64 %74, %65
  %76 = srem i64 %75, 1000000007
  %77 = icmp slt i64 %75, 0
  %78 = icmp ne i64 %76, 0
  %79 = and i1 %77, %78
  %80 = add nsw i64 %76, 1000000007
  %81 = select i1 %79, i64 %80, i64 %76
  store i64 %81, ptr %64, align 8, !tbaa !3
  %82 = add nuw nsw i64 %63, 1
  %exitcond.not = icmp eq i64 %82, 13
  br i1 %exitcond.not, label %.loopexit, label %62

.loopexit:                                        ; preds = %62, %52
  %83 = add nuw nsw i64 %18, 1
  %exitcond34.not = icmp eq i64 %16, %18
  br i1 %exitcond34.not, label %._crit_edge, label %.preheader25

._crit_edge:                                      ; preds = %.loopexit, %13
  %84 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.098ffcedde1d0136e4b7dc4636c19284, i32 32)
  %85 = load i64, ptr getelementptr inbounds ([13 x i64], ptr @_QFEdp, i64 0, i64 5), align 8, !tbaa !3
  %86 = call i1 @_FortranAioOutputInteger64(ptr %84, i64 %85)
  %87 = call i32 @_FortranAioEndIoStatement(ptr %84)
  ret void
}

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

declare i1 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

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

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

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

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}
