"""
Model exploration for FreeExile Piecewise Exponential EXP Curve (Levels 1-100 across 7 segments).
Segments:
  1: L in [1, 20]   (Fast acceleration, onboarding)
  2: L in [21, 40]  (Acts I-II, smooth deceleration)
  3: L in [41, 60]  (Acts III-IV, endgame prep)
  4: L in [61, 80]  (Atlas T1-T10, steady linear/moderate progression)
  5: L in [81, 90]  (T11-T13, steepening)
  6: L in [91, 99]  (T14-T16, exponential ramp)
  7: L = 99 -> 100  (Hardcore soft-wall: delta >= 30% of lifetime EXP 1-99)

Constraints:
  - Delta EXP(L) > Delta EXP(L-1) for all L in [2, 99] (strictly monotonically increasing)
  - Total EXP 1..20 < 0.1% total EXP (0.001)
  - Level 99->100 delta EXP >= 30% of total lifetime EXP (1-99)
  - Seamless boundary transitions (no negative jumps)
"""

import math

def generate_curve():
    delta_exp = {}
    
    # Let's design the base delta EXP for each level L in 1..99
    # Level L means advancing from L to L+1.
    
    # Segment 1: L = 1..20
    # Smooth polynomial growth: e.g. base * L^2.2
    # At L=1: 600
    # At L=20: ~60,000
    for l in range(1, 21):
        delta_exp[l] = int(500 * (l ** 2.3) + 100 * l)
    
    # Segment 2: L = 21..40
    # Acts I-II: moderate power-exponential growth
    # Match at L=20: delta_exp[20] = int(500 * 20^2.3 + 2000) = int(500 * 998.8 + 2000) = 501,427
    base_20 = delta_exp[20]
    for l in range(21, 41):
        step = l - 20
        delta_exp[l] = int(base_20 * ((1 + 0.085 * step) ** 2.4))
        
    # Segment 3: L = 41..60
    # Acts III-IV & Endgame prep: accelerating
    base_40 = delta_exp[40]
    for l in range(41, 61):
        step = l - 40
        delta_exp[l] = int(base_40 * math.exp(0.092 * step))
        
    # Segment 4: L = 61..80
    # Atlas T1-T10: steady linear/moderate growth
    # Notice requirement: "cấp 60-80 tăng tuyến tính ổn định"
    base_60 = delta_exp[60]
    # Linear increment per level:
    # Say delta_exp[l] = base_60 + k * (l - 60)
    # But wait, to keep delta_exp strictly increasing and smooth, k must be positive
    # If delta_exp is increasing linearly, Delta(Delta E) is constant (linear progression of required XP)
    k_linear = int(base_60 * 0.12)
    for l in range(61, 81):
        step = l - 60
        delta_exp[l] = int(base_60 + k_linear * step)
        
    # Segment 5: L = 81..90
    # T11-T13: steepening exponential
    base_80 = delta_exp[80]
    for l in range(81, 91):
        step = l - 80
        delta_exp[l] = int(base_80 * math.exp(0.145 * step))
        
    # Segment 6: L = 91..99
    # T14-T16: steep vertical exponential ramp ("tăng dựng đứng")
    base_90 = delta_exp[90]
    for l in range(91, 99):
        step = l - 90
        delta_exp[l] = int(base_90 * math.exp(0.24 * step))
        
    # Segment 7: L = 99 -> 100
    # Hardcore soft-wall:
    # We need delta_exp[99] >= 0.30 * sum(delta_exp[1..98])
    lifetime_1_to_99 = sum(delta_exp[l] for l in range(1, 99))
    target_99_to_100 = int(lifetime_1_to_99 * 0.33)  # 33% of lifetime 1-99
    # Ensure it is strictly greater than delta_exp[98]
    if target_99_to_100 <= delta_exp[98]:
        target_99_to_100 = int(delta_exp[98] * 1.5)
    delta_exp[99] = target_99_to_100

    # Total lifetime 1-100:
    total_lifetime = sum(delta_exp[l] for l in range(1, 100))
    exp_1_20 = sum(delta_exp[l] for l in range(1, 21))
    ratio_1_20 = exp_1_20 / total_lifetime
    ratio_99_100 = delta_exp[99] / lifetime_1_to_99
    ratio_99_100_total = delta_exp[99] / total_lifetime

    print(f"Total Lifetime EXP (1->100): {total_lifetime:,}")
    print(f"EXP 1->20: {exp_1_20:,} ({ratio_1_20 * 100:.4f}% of total, must be < 0.1%)")
    print(f"EXP 1->99: {lifetime_1_to_99:,}")
    print(f"Delta EXP 99->100: {delta_exp[99]:,} ({ratio_99_100 * 100:.2f}% of 1-99, must be >= 30%)")
    print(f"Delta EXP 99->100 as % of total: {ratio_99_100_total * 100:.2f}% (must be 25-35%)")

    # Check monotonicity
    monotonic = True
    for l in range(2, 100):
        if delta_exp[l] <= delta_exp[l-1]:
            print(f"Violation at {l}: {delta_exp[l]} <= {delta_exp[l-1]}")
            monotonic = False
    print(f"Strict Monotonicity: {monotonic}")

    return delta_exp

if __name__ == '__main__':
    generate_curve()
