To solve this optimization problem using linear programming and Gurobi in Python, we first need to define the decision variables, the objective function, and the constraints based on the given information.

Let's denote:
- \(x_s\) as the number of 1-minute social media commercials.
- \(x_t\) as the number of 1-minute television commercials.

The objective is to minimize the total cost of advertising. Given that a 1-minute social media ad costs $30,000 and a 1-minute television ad costs $50,000, the objective function can be formulated as:
\[ \text{Minimize:} \quad 30,000x_s + 50,000x_t \]

The constraints are based on the requirement that the commercials must be seen by at least 20 million young girls and 30 million middle-aged women. Since each social media commercial is seen by 5 million young girls and 1 million middle-aged women, and each television commercial is seen by 3 million young girls and 7 million middle-aged women, we can formulate the constraints as follows:
\[ 5,000,000x_s + 3,000,000x_t \geq 20,000,000 \]
\[ 1,000,000x_s + 7,000,000x_t \geq 30,000,000 \]

Additionally, \(x_s\) and \(x_t\) must be non-negative since the company cannot buy a negative number of commercials.

Now, let's translate these into Gurobi code in Python:

```python
from gurobipy import *

# Create a model
m = Model("Advertising")

# Define decision variables
x_s = m.addVar(vtype=GRB.CONTINUOUS, name="social_media_commercials")
x_t = m.addVar(vtype=GRB.CONTINUOUS, name="television_commercials")

# Objective function: Minimize total cost
m.setObjective(30000*x_s + 50000*x_t, GRB.MINIMIZE)

# Constraints
m.addConstr(5000000*x_s + 3000000*x_t >= 20000000, "young_girls_constraint")
m.addConstr(1000000*x_s + 7000000*x_t >= 30000000, "middle_aged_women_constraint")

# Optimize model
m.optimize()

# Print results
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Social Media Commercials: {x_s.x}")
    print(f"Television Commercials: {x_t.x}")
    print(f"Total Cost: ${30000*x_s.x + 50000*x_t.x:.2f}")
else:
    print("No optimal solution found.")
```