# 商品データ: (商品名, 価格, 評価, レビュー数)
products = [
    ("item1", 3000, 4.8, 20),
    ("item2", 1800, 4.2, 200),
    ("item3", 5000, 4.9, 5),
    ("item4", 2500, 4.5, 80),
]

recommendations = []

for name, price, rating, reviews in products:
    # --- スコア計算のロジック ---
    # 1. 信頼度スコア: レビュー数が少なくても評価が高い商品（item3など）の急浮上を防ぐため、
    #    レビュー数も加味した総合スコアを計算します。
    total_score = rating * (1 - (1 / (reviews + 1)))
    
    # 2. コスパスコア: 1円あたりの総合スコア（分かりやすく1000倍しています）
    cost_performance = (total_score / price) * 1000
    
    recommendations.append({
        "name": name,
        "price": price,
        "rating": rating,
        "reviews": reviews,
        "total_score": round(total_score, 2),
        "cp_score": round(cost_performance, 2)
    })

# --- 1. 総合おすすめ順（スコアが高い順）でソートして表示 ---
print("🏆 【総合おすすめランキング】（評価×レビューの信頼度）")
sorted_by_score = sorted(recommendations, key=lambda x: x["total_score"], reverse=True)
for i, p in enumerate(sorted_by_score, 1):
    print(f"{i}位: {p['name']} (スコア: {p['total_score']}) - 価格: {p['price']}円, 評価: {p['rating']}, レビュー: {p['reviews']}件")

print("\n" + "="*50 + "\n")

# --- 2. コスパおすすめ順（価格あたりの満足度が高い順）でソートして表示 ---
print("💰 【コスパおすすめランキング】（価格の手頃さ重視）")
sorted_by_cp = sorted(recommendations, key=lambda x: x["cp_score"], reverse=True)
for i, p in enumerate(sorted_by_cp, 1):
    print(f"{i}位: {p['name']} (コスパ: {p['cp_score']}) - 価格: {p['price']}円, 評価: {p['rating']}, レビュー: {p['reviews']}件")