<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def inputindex(input):

 """Handler for showing keyboard or mouse page with day and total links."""

    stats = {}
    countminmax = "SUM(count) AS count, MIN(day) AS first, MAX(day) AS last"
    tables = ("moves", "clicks", "scrolls") if "mouse" == input else ("keys", "combos")
    for table in tables:
        stats[table] = db.fetchone("counts", countminmax, type=table)
        stats[table]["days"] = db.fetch("counts", order="day DESC", type=table)
    return bottle.template("input.tpl", locals(), conf=conf)