Problem 775

G(N) = sum_{n=1..N} g(n) mod 1e9+7, g(n) = 6n - smin(n), N = 10^16. Pure Flow port of the native C helper. MOD = 1e9+7 so i64 products are safe (no __int128 needed). N < 2^63 so i64 arithmetic is sufficient.

Answer946791106
Output946791106
StatusPASS
Native helperno
Runtime50 ms
Peak memory1104 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)?
Space complexityO(1)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 775: Saving Paper
# G(N) = sum_{n=1..N} g(n) mod 1e9+7, g(n) = 6n - smin(n), N = 10^16.
# Pure Flow port of the native C helper. MOD = 1e9+7 so i64 products are
# safe (no __int128 needed). N < 2^63 so i64 arithmetic is sufficient.

const MOD: i64 = 1000000007

import euler.nt { isqrt }

# floor(cuberoot(x)) for x >= 0 via integer binary search.
function icbrt_floor(x: i64) -> i64 {
    if x == 0 {
        return 0
    }
    let mut lo: i64 = 0
    let mut hi: i64 = 1
    while hi * hi * hi <= x {
        hi = hi * 2
    }
    while lo + 1 < hi {
        let mid: i64 = lo + (hi - lo) / 2
        if mid * mid * mid <= x {
            lo = mid
        } else {
            hi = mid
        }
    }
    return lo
}

# Count of 'turn' positions in the first m steps of the square spiral layer:
# c(m) = max(0, isqrt(4m-1) - 1).
function c_count(m: i64) -> i64 {
    if m <= 1 {
        return 0
    }
    return isqrt(4 * m - 1) - 1
}

# F(t) = sum_{m=1..t} c_count(m), O(1) via block structure of floor(sqrt).
function c_prefix_sum(t: i64) -> i64 {
    if t <= 1 {
        return 0
    }
    let a: i64 = isqrt(t)

    # sum_{i=1..a-1} (4i^2 + i) = (a-1)*a*(8a-1)/6
    let base: i64 = (a - 1) * a * (8 * a - 1) / 6

    let sq: i64 = a * a
    if t == sq {
        return base
    }

    # m in [a^2+1, a^2+a]: c(m) = 2a-1
    let mut end_even: i64 = t
    if end_even > sq + a {
        end_even = sq + a
    }
    let cnt_even: i64 = end_even - (sq + 1) + 1
    let mut partial: i64 = cnt_even * (2 * a - 1)

    # m in [a^2+a+1, (a+1)^2]: c(m) = 2a
    if t > sq + a {
        let cnt_odd: i64 = t - (sq + a + 1) + 1
        partial = partial + cnt_odd * (2 * a)
    }
    return base + partial
}

function mulmod(a: i64, b: i64) -> i64 {
    return a % MOD * (b % MOD) % MOD
}

# S(N) = sum_{n=1..N} smin(n) mod mod.
function sum_smin_mod(N: i64) -> i64 {
    if N <= 0 {
        return 0
    }
    let mut total: i64 = 6 % MOD
    if N == 1 {
        return total
    }

    let k_max: i64 = icbrt_floor(N - 1)
    let mut k: i64 = 1
    while k <= k_max {
        let k3: i64 = k * k * k
        if k3 + 1 > N {
            break
        }
        let full: i64 = (k + 1) * (k + 1) * (k + 1) - k3
        let mut L: i64 = N - k3
        if L > full {
            L = full
        }

        let k2: i64 = k * k
        let cap2: i64 = k * (k + 1)

        let mut lenA: i64 = L
        if lenA > k2 {
            lenA = k2
        }
        let mut rem: i64 = L - lenA
        let mut lenB: i64 = 0
        let mut lenC: i64 = 0
        if rem > 0 {
            lenB = rem
            if lenB > cap2 {
                lenB = cap2
            }
            rem = rem - lenB
            if rem > 0 {
                lenC = rem
            }
        }

        let c_k2: i64 = c_count(k2)
        let c_kk1: i64 = c_count(cap2)

        # sum of (c(pz)+c(qz)+c(rz)) across the block
        let mut sum_c: i64 = c_prefix_sum(lenA)
        if lenB != 0 {
            sum_c = sum_c + lenB * c_k2 + c_prefix_sum(lenB)
        }
        if lenC != 0 {
            sum_c = sum_c + lenC * (c_k2 + c_kk1) + c_prefix_sum(lenC)
        }

        # sum of per-n constant term bv (4/8/12) across the block
        let sum_bv: i64 = 4 * lenA + 8 * lenB + 12 * lenC

        # block = L*(6*k2) + sum_bv + 2*sum_c, all mod.
        let term1: i64 = mulmod(L % MOD, (6 * k2) % MOD)
        let term2: i64 = (sum_bv % MOD + mulmod(2 % MOD, sum_c % MOD)) % MOD
        let block: i64 = (term1 + term2) % MOD
        total = (total + block) % MOD

        k = k + 1
    }
    return total
}

# G(N) = sum_{n=1..N} g(n) mod mod, g(n) = 6n - smin(n).
function G_mod(N: i64) -> i64 {
    # sum_{n=1..N} 6n = 3N(N+1)
    let sum6: i64 = mulmod(mulmod(3, N % MOD), (N + 1) % MOD)
    let S: i64 = sum_smin_mod(N)
    let mut r: i64 = (sum6 - S) % MOD
    if r < 0 {
        r = r + MOD
    }
    return r
}

function main() -> i32 {
    printf("%lld\n", G_mod(10000000000000000))
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t icbrt_floor_i64(int64_t x);
int64_t c_count_i64(int64_t m);
int64_t c_prefix_sum_i64(int64_t t);
int64_t mulmod_i64_i64(int64_t a, int64_t b);
int64_t sum_smin_mod_i64(int64_t N);
int64_t G_mod_i64(int64_t N);
int32_t main(void);

static const int64_t MOD = 1000000007;

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}

int64_t icbrt_floor_i64(int64_t x) {
    if (x == 0) {
        return 0;
    }
    int64_t lo = 0;
    int64_t hi = 1;
    while (((hi * hi) * hi) <= x) {
        hi = (hi * 2);
    }
    while ((lo + 1) < hi) {
        int64_t mid = (lo + FLOW_CHECKED_DIV(((hi - lo)), (2)));
        if (((mid * mid) * mid) <= x) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}

int64_t c_count_i64(int64_t m) {
    if (m <= 1) {
        return 0;
    }
    return (isqrt_i64(((4 * m) - 1)) - 1);
}

int64_t c_prefix_sum_i64(int64_t t) {
    if (t <= 1) {
        return 0;
    }
    int64_t a = isqrt_i64(t);
    int64_t base = FLOW_CHECKED_DIV(((((a - 1) * a) * ((8 * a) - 1))), (6));
    int64_t sq = (a * a);
    if (t == sq) {
        return base;
    }
    int64_t end_even = t;
    if (end_even > (sq + a)) {
        end_even = (sq + a);
    }
    int64_t cnt_even = ((end_even - (sq + 1)) + 1);
    int64_t partial = (cnt_even * ((2 * a) - 1));
    if (t > (sq + a)) {
        int64_t cnt_odd = ((t - ((sq + a) + 1)) + 1);
        partial = (partial + (cnt_odd * (2 * a)));
    }
    return (base + partial);
}

int64_t mulmod_i64_i64(int64_t a, int64_t b) {
    return FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((a), (MOD)) * FLOW_CHECKED_MOD((b), (MOD)))), (MOD));
}

int64_t sum_smin_mod_i64(int64_t N) {
    if (N <= 0) {
        return 0;
    }
    int64_t total = FLOW_CHECKED_MOD((6), (MOD));
    if (N == 1) {
        return total;
    }
    int64_t k_max = icbrt_floor_i64((N - 1));
    int64_t k = 1;
    while (k <= k_max) {
        int64_t k3 = ((k * k) * k);
        if ((k3 + 1) > N) {
            break;
        }
        int64_t full = ((((k + 1) * (k + 1)) * (k + 1)) - k3);
        int64_t L = (N - k3);
        if (L > full) {
            L = full;
        }
        int64_t k2 = (k * k);
        int64_t cap2 = (k * (k + 1));
        int64_t lenA = L;
        if (lenA > k2) {
            lenA = k2;
        }
        int64_t rem = (L - lenA);
        int64_t lenB = 0;
        int64_t lenC = 0;
        if (rem > 0) {
            lenB = rem;
            if (lenB > cap2) {
                lenB = cap2;
            }
            rem = (rem - lenB);
            if (rem > 0) {
                lenC = rem;
            }
        }
        int64_t c_k2 = c_count_i64(k2);
        int64_t c_kk1 = c_count_i64(cap2);
        int64_t sum_c = c_prefix_sum_i64(lenA);
        if (lenB != 0) {
            sum_c = ((sum_c + (lenB * c_k2)) + c_prefix_sum_i64(lenB));
        }
        if (lenC != 0) {
            sum_c = ((sum_c + (lenC * (c_k2 + c_kk1))) + c_prefix_sum_i64(lenC));
        }
        int64_t sum_bv = (((4 * lenA) + (8 * lenB)) + (12 * lenC));
        int64_t term1 = mulmod_i64_i64(FLOW_CHECKED_MOD((L), (MOD)), FLOW_CHECKED_MOD(((6 * k2)), (MOD)));
        int64_t term2 = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((sum_bv), (MOD)) + mulmod_i64_i64(FLOW_CHECKED_MOD((2), (MOD)), FLOW_CHECKED_MOD((sum_c), (MOD))))), (MOD));
        int64_t block = FLOW_CHECKED_MOD(((term1 + term2)), (MOD));
        total = FLOW_CHECKED_MOD(((total + block)), (MOD));
        k = (k + 1);
    }
    return total;
}

int64_t G_mod_i64(int64_t N) {
    int64_t sum6 = mulmod_i64_i64(mulmod_i64_i64(3, FLOW_CHECKED_MOD((N), (MOD))), FLOW_CHECKED_MOD(((N + 1)), (MOD)));
    int64_t S = sum_smin_mod_i64(N);
    int64_t r = FLOW_CHECKED_MOD(((sum6 - S)), (MOD));
    if (r < 0) {
        r = (r + MOD);
    }
    return r;
}

int32_t main(void) {
    printf("%lld\n", G_mod_i64(10000000000000000));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114) : (i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117) : (i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @icbrt_floor(%arg0: i64) -> i64 {
    %175 = arith.constant 0 : i32
    %177 = arith.extsi %175 : i32 to i64
    %176 = arith.cmpi eq, %arg0, %177 : i64
    cf.cond_br %176, ^bb42, ^bb43
    ^bb42:
      %178 = arith.constant 0 : i32
      %179 = arith.extsi %178 : i32 to i64
      func.return %179 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %180 = arith.constant 0 : i32
    %181 = arith.extsi %180 : i32 to i64
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x i64 : (i64) -> !llvm.ptr
    llvm.store %181, %183 : i64, !llvm.ptr
    %184 = arith.constant 1 : i32
    %185 = arith.extsi %184 : i32 to i64
    %186 = llvm.mlir.constant(1 : i64) : i64
    %187 = llvm.alloca %186 x i64 : (i64) -> !llvm.ptr
    llvm.store %185, %187 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %188 = llvm.load %187 : !llvm.ptr -> i64
    %189 = llvm.load %187 : !llvm.ptr -> i64
    %190 = arith.muli %188, %189 : i64
    %191 = llvm.load %187 : !llvm.ptr -> i64
    %192 = arith.muli %190, %191 : i64
    %193 = arith.cmpi sle, %192, %arg0 : i64
    cf.cond_br %193, ^bb46, ^bb47
    ^bb46:
      %194 = llvm.load %187 : !llvm.ptr -> i64
      %195 = arith.constant 2 : i32
      %197 = arith.extsi %195 : i32 to i64
      %196 = arith.muli %194, %197 : i64
      llvm.store %196, %187 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    cf.br ^bb48
    ^bb48:
    %198 = llvm.load %183 : !llvm.ptr -> i64
    %199 = arith.constant 1 : i32
    %201 = arith.extsi %199 : i32 to i64
    %200 = arith.addi %198, %201 : i64
    %202 = llvm.load %187 : !llvm.ptr -> i64
    %203 = arith.cmpi slt, %200, %202 : i64
    cf.cond_br %203, ^bb49, ^bb50
    ^bb49:
      %204 = llvm.load %183 : !llvm.ptr -> i64
      %205 = llvm.load %187 : !llvm.ptr -> i64
      %206 = llvm.load %183 : !llvm.ptr -> i64
      %207 = arith.subi %205, %206 : i64
      %208 = arith.constant 2 : i32
      %210 = arith.extsi %208 : i32 to i64
      %209 = arith.divsi %207, %210 : i64
      %211 = arith.addi %204, %209 : i64
      %212 = arith.muli %211, %211 : i64
      %213 = arith.muli %212, %211 : i64
      %214 = arith.cmpi sle, %213, %arg0 : i64
      cf.cond_br %214, ^bb51, ^bb52
      ^bb51:
        llvm.store %211, %183 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        llvm.store %211, %187 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb53:
      cf.br ^bb48
    ^bb50:
    %215 = llvm.load %183 : !llvm.ptr -> i64
    func.return %215 : i64
  }
  func.func @c_count(%arg0: i64) -> i64 {
    %216 = arith.constant 1 : i32
    %218 = arith.extsi %216 : i32 to i64
    %217 = arith.cmpi sle, %arg0, %218 : i64
    cf.cond_br %217, ^bb54, ^bb55
    ^bb54:
      %219 = arith.constant 0 : i32
      %220 = arith.extsi %219 : i32 to i64
      func.return %220 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %222 = arith.constant 4 : i32
    %224 = arith.extsi %222 : i32 to i64
    %223 = arith.muli %224, %arg0 : i64
    %225 = arith.constant 1 : i32
    %227 = arith.extsi %225 : i32 to i64
    %226 = arith.subi %223, %227 : i64
    %221 = func.call @isqrt(%226) : (i64) -> i64
    %228 = arith.constant 1 : i32
    %230 = arith.extsi %228 : i32 to i64
    %229 = arith.subi %221, %230 : i64
    func.return %229 : i64
  }
  func.func @c_prefix_sum(%arg0: i64) -> i64 {
    %231 = arith.constant 1 : i32
    %233 = arith.extsi %231 : i32 to i64
    %232 = arith.cmpi sle, %arg0, %233 : i64
    cf.cond_br %232, ^bb57, ^bb58
    ^bb57:
      %234 = arith.constant 0 : i32
      %235 = arith.extsi %234 : i32 to i64
      func.return %235 : i64
    ^bb58:
      cf.br ^bb59
    ^bb59:
    %236 = func.call @isqrt(%arg0) : (i64) -> i64
    %237 = arith.constant 1 : i32
    %239 = arith.extsi %237 : i32 to i64
    %238 = arith.subi %236, %239 : i64
    %240 = arith.muli %238, %236 : i64
    %241 = arith.constant 8 : i32
    %243 = arith.extsi %241 : i32 to i64
    %242 = arith.muli %243, %236 : i64
    %244 = arith.constant 1 : i32
    %246 = arith.extsi %244 : i32 to i64
    %245 = arith.subi %242, %246 : i64
    %247 = arith.muli %240, %245 : i64
    %248 = arith.constant 6 : i32
    %250 = arith.extsi %248 : i32 to i64
    %249 = arith.divsi %247, %250 : i64
    %251 = arith.muli %236, %236 : i64
    %252 = arith.cmpi eq, %arg0, %251 : i64
    cf.cond_br %252, ^bb60, ^bb61
    ^bb60:
      func.return %249 : i64
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %253 = llvm.mlir.constant(1 : i64) : i64
    %254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %254 : i64, !llvm.ptr
    %255 = llvm.load %254 : !llvm.ptr -> i64
    %256 = arith.addi %251, %236 : i64
    %257 = arith.cmpi sgt, %255, %256 : i64
    cf.cond_br %257, ^bb63, ^bb64
    ^bb63:
      %258 = arith.addi %251, %236 : i64
      llvm.store %258, %254 : i64, !llvm.ptr
      cf.br ^bb65
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %259 = llvm.load %254 : !llvm.ptr -> i64
    %260 = arith.constant 1 : i32
    %262 = arith.extsi %260 : i32 to i64
    %261 = arith.addi %251, %262 : i64
    %263 = arith.subi %259, %261 : i64
    %264 = arith.constant 1 : i32
    %266 = arith.extsi %264 : i32 to i64
    %265 = arith.addi %263, %266 : i64
    %267 = arith.constant 2 : i32
    %269 = arith.extsi %267 : i32 to i64
    %268 = arith.muli %269, %236 : i64
    %270 = arith.constant 1 : i32
    %272 = arith.extsi %270 : i32 to i64
    %271 = arith.subi %268, %272 : i64
    %273 = arith.muli %265, %271 : i64
    %274 = llvm.mlir.constant(1 : i64) : i64
    %275 = llvm.alloca %274 x i64 : (i64) -> !llvm.ptr
    llvm.store %273, %275 : i64, !llvm.ptr
    %276 = arith.addi %251, %236 : i64
    %277 = arith.cmpi sgt, %arg0, %276 : i64
    cf.cond_br %277, ^bb66, ^bb67
    ^bb66:
      %278 = arith.addi %251, %236 : i64
      %279 = arith.constant 1 : i32
      %281 = arith.extsi %279 : i32 to i64
      %280 = arith.addi %278, %281 : i64
      %282 = arith.subi %arg0, %280 : i64
      %283 = arith.constant 1 : i32
      %285 = arith.extsi %283 : i32 to i64
      %284 = arith.addi %282, %285 : i64
      %286 = llvm.load %275 : !llvm.ptr -> i64
      %287 = arith.constant 2 : i32
      %289 = arith.extsi %287 : i32 to i64
      %288 = arith.muli %289, %236 : i64
      %290 = arith.muli %284, %288 : i64
      %291 = arith.addi %286, %290 : i64
      llvm.store %291, %275 : i64, !llvm.ptr
      cf.br ^bb68
    ^bb67:
      cf.br ^bb68
    ^bb68:
    %292 = llvm.load %275 : !llvm.ptr -> i64
    %293 = arith.addi %249, %292 : i64
    func.return %293 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64) -> i64 {
    %294 = llvm.mlir.addressof @MOD : !llvm.ptr
    %295 = llvm.load %294 : !llvm.ptr -> i64
    %296 = arith.remsi %arg0, %295 : i64
    %297 = llvm.mlir.addressof @MOD : !llvm.ptr
    %298 = llvm.load %297 : !llvm.ptr -> i64
    %299 = arith.remsi %arg1, %298 : i64
    %300 = arith.muli %296, %299 : i64
    %301 = llvm.mlir.addressof @MOD : !llvm.ptr
    %302 = llvm.load %301 : !llvm.ptr -> i64
    %303 = arith.remsi %300, %302 : i64
    func.return %303 : i64
  }
  func.func @sum_smin_mod(%arg0: i64) -> i64 {
    %304 = arith.constant 0 : i32
    %306 = arith.extsi %304 : i32 to i64
    %305 = arith.cmpi sle, %arg0, %306 : i64
    cf.cond_br %305, ^bb69, ^bb70
    ^bb69:
      %307 = arith.constant 0 : i32
      %308 = arith.extsi %307 : i32 to i64
      func.return %308 : i64
    ^bb70:
      cf.br ^bb71
    ^bb71:
    %309 = arith.constant 6 : i32
    %310 = llvm.mlir.addressof @MOD : !llvm.ptr
    %311 = llvm.load %310 : !llvm.ptr -> i64
    %313 = arith.extsi %309 : i32 to i64
    %312 = arith.remsi %313, %311 : i64
    %314 = llvm.mlir.constant(1 : i64) : i64
    %315 = llvm.alloca %314 x i64 : (i64) -> !llvm.ptr
    llvm.store %312, %315 : i64, !llvm.ptr
    %316 = arith.constant 1 : i32
    %318 = arith.extsi %316 : i32 to i64
    %317 = arith.cmpi eq, %arg0, %318 : i64
    cf.cond_br %317, ^bb72, ^bb73
    ^bb72:
      %319 = llvm.load %315 : !llvm.ptr -> i64
      func.return %319 : i64
    ^bb73:
      cf.br ^bb74
    ^bb74:
    %321 = arith.constant 1 : i32
    %323 = arith.extsi %321 : i32 to i64
    %322 = arith.subi %arg0, %323 : i64
    %320 = func.call @icbrt_floor(%322) : (i64) -> i64
    %324 = arith.constant 1 : i32
    %325 = arith.extsi %324 : i32 to i64
    %326 = llvm.mlir.constant(1 : i64) : i64
    %327 = llvm.alloca %326 x i64 : (i64) -> !llvm.ptr
    llvm.store %325, %327 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %328 = llvm.load %327 : !llvm.ptr -> i64
    %329 = arith.cmpi sle, %328, %320 : i64
    cf.cond_br %329, ^bb76, ^bb77
    ^bb76:
      %330 = llvm.load %327 : !llvm.ptr -> i64
      %331 = llvm.load %327 : !llvm.ptr -> i64
      %332 = arith.muli %330, %331 : i64
      %333 = llvm.load %327 : !llvm.ptr -> i64
      %334 = arith.muli %332, %333 : i64
      %335 = arith.constant 1 : i32
      %337 = arith.extsi %335 : i32 to i64
      %336 = arith.addi %334, %337 : i64
      %338 = arith.cmpi sgt, %336, %arg0 : i64
      cf.cond_br %338, ^bb78, ^bb79
      ^bb78:
        cf.br ^bb77
      ^bb79:
        cf.br ^bb80
      ^bb80:
      %339 = llvm.load %327 : !llvm.ptr -> i64
      %340 = arith.constant 1 : i32
      %342 = arith.extsi %340 : i32 to i64
      %341 = arith.addi %339, %342 : i64
      %343 = llvm.load %327 : !llvm.ptr -> i64
      %344 = arith.constant 1 : i32
      %346 = arith.extsi %344 : i32 to i64
      %345 = arith.addi %343, %346 : i64
      %347 = arith.muli %341, %345 : i64
      %348 = llvm.load %327 : !llvm.ptr -> i64
      %349 = arith.constant 1 : i32
      %351 = arith.extsi %349 : i32 to i64
      %350 = arith.addi %348, %351 : i64
      %352 = arith.muli %347, %350 : i64
      %353 = arith.subi %352, %334 : i64
      %354 = arith.subi %arg0, %334 : i64
      %355 = llvm.mlir.constant(1 : i64) : i64
      %356 = llvm.alloca %355 x i64 : (i64) -> !llvm.ptr
      llvm.store %354, %356 : i64, !llvm.ptr
      %357 = llvm.load %356 : !llvm.ptr -> i64
      %358 = arith.cmpi sgt, %357, %353 : i64
      cf.cond_br %358, ^bb81, ^bb82
      ^bb81:
        llvm.store %353, %356 : i64, !llvm.ptr
        cf.br ^bb83
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %359 = llvm.load %327 : !llvm.ptr -> i64
      %360 = llvm.load %327 : !llvm.ptr -> i64
      %361 = arith.muli %359, %360 : i64
      %362 = llvm.load %327 : !llvm.ptr -> i64
      %363 = llvm.load %327 : !llvm.ptr -> i64
      %364 = arith.constant 1 : i32
      %366 = arith.extsi %364 : i32 to i64
      %365 = arith.addi %363, %366 : i64
      %367 = arith.muli %362, %365 : i64
      %368 = llvm.load %356 : !llvm.ptr -> i64
      %369 = llvm.mlir.constant(1 : i64) : i64
      %370 = llvm.alloca %369 x i64 : (i64) -> !llvm.ptr
      llvm.store %368, %370 : i64, !llvm.ptr
      %371 = llvm.load %370 : !llvm.ptr -> i64
      %372 = arith.cmpi sgt, %371, %361 : i64
      cf.cond_br %372, ^bb84, ^bb85
      ^bb84:
        llvm.store %361, %370 : i64, !llvm.ptr
        cf.br ^bb86
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %373 = llvm.load %356 : !llvm.ptr -> i64
      %374 = llvm.load %370 : !llvm.ptr -> i64
      %375 = arith.subi %373, %374 : i64
      %376 = llvm.mlir.constant(1 : i64) : i64
      %377 = llvm.alloca %376 x i64 : (i64) -> !llvm.ptr
      llvm.store %375, %377 : i64, !llvm.ptr
      %378 = arith.constant 0 : i32
      %379 = arith.extsi %378 : i32 to i64
      %380 = llvm.mlir.constant(1 : i64) : i64
      %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
      llvm.store %379, %381 : i64, !llvm.ptr
      %382 = arith.constant 0 : i32
      %383 = arith.extsi %382 : i32 to i64
      %384 = llvm.mlir.constant(1 : i64) : i64
      %385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
      llvm.store %383, %385 : i64, !llvm.ptr
      %386 = llvm.load %377 : !llvm.ptr -> i64
      %387 = arith.constant 0 : i32
      %389 = arith.extsi %387 : i32 to i64
      %388 = arith.cmpi sgt, %386, %389 : i64
      cf.cond_br %388, ^bb87, ^bb88
      ^bb87:
        %390 = llvm.load %377 : !llvm.ptr -> i64
        llvm.store %390, %381 : i64, !llvm.ptr
        %391 = llvm.load %381 : !llvm.ptr -> i64
        %392 = arith.cmpi sgt, %391, %367 : i64
        cf.cond_br %392, ^bb90, ^bb91
        ^bb90:
          llvm.store %367, %381 : i64, !llvm.ptr
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        %393 = llvm.load %377 : !llvm.ptr -> i64
        %394 = llvm.load %381 : !llvm.ptr -> i64
        %395 = arith.subi %393, %394 : i64
        llvm.store %395, %377 : i64, !llvm.ptr
        %396 = llvm.load %377 : !llvm.ptr -> i64
        %397 = arith.constant 0 : i32
        %399 = arith.extsi %397 : i32 to i64
        %398 = arith.cmpi sgt, %396, %399 : i64
        cf.cond_br %398, ^bb93, ^bb94
        ^bb93:
          %400 = llvm.load %377 : !llvm.ptr -> i64
          llvm.store %400, %385 : i64, !llvm.ptr
          cf.br ^bb95
        ^bb94:
          cf.br ^bb95
        ^bb95:
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %401 = func.call @c_count(%361) : (i64) -> i64
      %402 = func.call @c_count(%367) : (i64) -> i64
      %404 = llvm.load %370 : !llvm.ptr -> i64
      %403 = func.call @c_prefix_sum(%404) : (i64) -> i64
      %405 = llvm.mlir.constant(1 : i64) : i64
      %406 = llvm.alloca %405 x i64 : (i64) -> !llvm.ptr
      llvm.store %403, %406 : i64, !llvm.ptr
      %407 = llvm.load %381 : !llvm.ptr -> i64
      %408 = arith.constant 0 : i32
      %410 = arith.extsi %408 : i32 to i64
      %409 = arith.cmpi ne, %407, %410 : i64
      cf.cond_br %409, ^bb96, ^bb97
      ^bb96:
        %411 = llvm.load %406 : !llvm.ptr -> i64
        %412 = llvm.load %381 : !llvm.ptr -> i64
        %413 = arith.muli %412, %401 : i64
        %414 = arith.addi %411, %413 : i64
        %416 = llvm.load %381 : !llvm.ptr -> i64
        %415 = func.call @c_prefix_sum(%416) : (i64) -> i64
        %417 = arith.addi %414, %415 : i64
        llvm.store %417, %406 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      %418 = llvm.load %385 : !llvm.ptr -> i64
      %419 = arith.constant 0 : i32
      %421 = arith.extsi %419 : i32 to i64
      %420 = arith.cmpi ne, %418, %421 : i64
      cf.cond_br %420, ^bb99, ^bb100
      ^bb99:
        %422 = llvm.load %406 : !llvm.ptr -> i64
        %423 = llvm.load %385 : !llvm.ptr -> i64
        %424 = arith.addi %401, %402 : i64
        %425 = arith.muli %423, %424 : i64
        %426 = arith.addi %422, %425 : i64
        %428 = llvm.load %385 : !llvm.ptr -> i64
        %427 = func.call @c_prefix_sum(%428) : (i64) -> i64
        %429 = arith.addi %426, %427 : i64
        llvm.store %429, %406 : i64, !llvm.ptr
        cf.br ^bb101
      ^bb100:
        cf.br ^bb101
      ^bb101:
      %430 = arith.constant 4 : i32
      %431 = llvm.load %370 : !llvm.ptr -> i64
      %433 = arith.extsi %430 : i32 to i64
      %432 = arith.muli %433, %431 : i64
      %434 = arith.constant 8 : i32
      %435 = llvm.load %381 : !llvm.ptr -> i64
      %437 = arith.extsi %434 : i32 to i64
      %436 = arith.muli %437, %435 : i64
      %438 = arith.addi %432, %436 : i64
      %439 = arith.constant 12 : i32
      %440 = llvm.load %385 : !llvm.ptr -> i64
      %442 = arith.extsi %439 : i32 to i64
      %441 = arith.muli %442, %440 : i64
      %443 = arith.addi %438, %441 : i64
      %445 = llvm.load %356 : !llvm.ptr -> i64
      %446 = llvm.mlir.addressof @MOD : !llvm.ptr
      %447 = llvm.load %446 : !llvm.ptr -> i64
      %448 = arith.remsi %445, %447 : i64
      %449 = arith.constant 6 : i32
      %451 = arith.extsi %449 : i32 to i64
      %450 = arith.muli %451, %361 : i64
      %452 = llvm.mlir.addressof @MOD : !llvm.ptr
      %453 = llvm.load %452 : !llvm.ptr -> i64
      %454 = arith.remsi %450, %453 : i64
      %444 = func.call @mulmod(%448, %454) : (i64, i64) -> i64
      %455 = llvm.mlir.addressof @MOD : !llvm.ptr
      %456 = llvm.load %455 : !llvm.ptr -> i64
      %457 = arith.remsi %443, %456 : i64
      %459 = arith.constant 2 : i32
      %460 = llvm.mlir.addressof @MOD : !llvm.ptr
      %461 = llvm.load %460 : !llvm.ptr -> i64
      %463 = arith.extsi %459 : i32 to i64
      %462 = arith.remsi %463, %461 : i64
      %464 = llvm.load %406 : !llvm.ptr -> i64
      %465 = llvm.mlir.addressof @MOD : !llvm.ptr
      %466 = llvm.load %465 : !llvm.ptr -> i64
      %467 = arith.remsi %464, %466 : i64
      %458 = func.call @mulmod(%462, %467) : (i64, i64) -> i64
      %468 = arith.addi %457, %458 : i64
      %469 = llvm.mlir.addressof @MOD : !llvm.ptr
      %470 = llvm.load %469 : !llvm.ptr -> i64
      %471 = arith.remsi %468, %470 : i64
      %472 = arith.addi %444, %471 : i64
      %473 = llvm.mlir.addressof @MOD : !llvm.ptr
      %474 = llvm.load %473 : !llvm.ptr -> i64
      %475 = arith.remsi %472, %474 : i64
      %476 = llvm.load %315 : !llvm.ptr -> i64
      %477 = arith.addi %476, %475 : i64
      %478 = llvm.mlir.addressof @MOD : !llvm.ptr
      %479 = llvm.load %478 : !llvm.ptr -> i64
      %480 = arith.remsi %477, %479 : i64
      llvm.store %480, %315 : i64, !llvm.ptr
      %481 = llvm.load %327 : !llvm.ptr -> i64
      %482 = arith.constant 1 : i32
      %484 = arith.extsi %482 : i32 to i64
      %483 = arith.addi %481, %484 : i64
      llvm.store %483, %327 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %485 = llvm.load %315 : !llvm.ptr -> i64
    func.return %485 : i64
  }
  func.func @G_mod(%arg0: i64) -> i64 {
    %488 = arith.constant 3 : i32
    %489 = llvm.mlir.addressof @MOD : !llvm.ptr
    %490 = llvm.load %489 : !llvm.ptr -> i64
    %491 = arith.remsi %arg0, %490 : i64
    %492 = arith.extsi %488 : i32 to i64
    %487 = func.call @mulmod(%492, %491) : (i64, i64) -> i64
    %493 = arith.constant 1 : i32
    %495 = arith.extsi %493 : i32 to i64
    %494 = arith.addi %arg0, %495 : i64
    %496 = llvm.mlir.addressof @MOD : !llvm.ptr
    %497 = llvm.load %496 : !llvm.ptr -> i64
    %498 = arith.remsi %494, %497 : i64
    %486 = func.call @mulmod(%487, %498) : (i64, i64) -> i64
    %499 = func.call @sum_smin_mod(%arg0) : (i64) -> i64
    %500 = arith.subi %486, %499 : i64
    %501 = llvm.mlir.addressof @MOD : !llvm.ptr
    %502 = llvm.load %501 : !llvm.ptr -> i64
    %503 = arith.remsi %500, %502 : i64
    %504 = llvm.mlir.constant(1 : i64) : i64
    %505 = llvm.alloca %504 x i64 : (i64) -> !llvm.ptr
    llvm.store %503, %505 : i64, !llvm.ptr
    %506 = llvm.load %505 : !llvm.ptr -> i64
    %507 = arith.constant 0 : i32
    %509 = arith.extsi %507 : i32 to i64
    %508 = arith.cmpi slt, %506, %509 : i64
    cf.cond_br %508, ^bb102, ^bb103
    ^bb102:
      %510 = llvm.load %505 : !llvm.ptr -> i64
      %511 = llvm.mlir.addressof @MOD : !llvm.ptr
      %512 = llvm.load %511 : !llvm.ptr -> i64
      %513 = arith.addi %510, %512 : i64
      llvm.store %513, %505 : i64, !llvm.ptr
      cf.br ^bb104
    ^bb103:
      cf.br ^bb104
    ^bb104:
    %514 = llvm.load %505 : !llvm.ptr -> i64
    func.return %514 : i64
  }
  func.func @main() -> i32 {
    %515 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %517 = arith.constant 9999995705032704 : i32
    %518 = arith.extsi %517 : i32 to i64
    %516 = func.call @G_mod(%518) : (i64) -> i64
    %519 = llvm.call @printf(%515, %516) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %520 = arith.constant 0 : i32
    func.return %520 : i32
  }
}