## Problem Description and Formulation

The problem is a linear programming optimization problem. The goal is to maximize profit by determining the optimal number of pens and pencils to buy and sell, given certain constraints.

### Variables

- \(x\): Number of pens to buy and sell
- \(y\): Number of pencils to buy and sell

### Objective Function

The profit from selling \(x\) pens is \(3x\) and from selling \(y\) pencils is \(1y\). The objective is to maximize the total profit:

\[ \text{Maximize:} \quad 3x + y \]

### Constraints

1. **Inventory Cost Constraint**: The cost of buying \(x\) pens at $2 each and \(y\) pencils at $1 each must not exceed $500.

\[ 2x + y \leq 500 \]

2. **Pen Sales Constraint**: At least 100 pens but at most 150 pens are sold.

\[ 100 \leq x \leq 150 \]

3. **Pencil Sales Constraint**: The number of pencils sold is at most twice the amount of pens sold.

\[ y \leq 2x \]

4. **Non-Negativity Constraint**: The number of pens and pencils cannot be negative.

\[ x \geq 0, \quad y \geq 0 \]

However, given that \(x \geq 100\), the \(x \geq 0\) constraint is implicitly satisfied.

## Gurobi Code

```python
import gurobi

def solve_problem():
    # Create a new model
    model = gurobi.Model()

    # Define variables
    x = model.addVar(lb=100, ub=150, name="Pens")
    y = model.addVar(lb=0, name="Pencils")

    # Objective function: Maximize profit
    model.setObjective(3*x + y, gurobi.GRB.MAXIMIZE)

    # Inventory cost constraint
    model.addConstr(2*x + y <= 500, name="Inventory_Cost")

    # Pencil sales constraint
    model.addConstr(y <= 2*x, name="Pencil_Sales")

    # Solve the model
    model.optimize()

    # Print the solution
    if model.status == gurobi.GRB.OPTIMAL:
        print(f"Optimal solution: Pens = {x.varValue}, Pencils = {y.varValue}")
        print(f"Max Profit: {model.objVal}")
    else:
        print("No optimal solution found")

solve_problem()
```

This code defines the optimization problem using Gurobi's Python interface, sets up the objective function and constraints according to the problem description, and solves the model to find the optimal number of pens and pencils to maximize profit.