# Arup Guha
# Answers to Spr 2020 Part B Final Exam

# Question 1
'''
money = int(input("How many cents do you have total?\n"))
dollars = money//100
cents = money%100
print("You have",dollars,"dollars and",cents,"cents.")


# Question 2
age = int(input("How old are you?\n"))
preexist = input("Do you have any pre-exisiting conditions?(yes/no)\n")

if age >= 65 or preexist == "yes":
    print("Please stay at home always.")
else:
    print("You may leave the house for limited important activities.")


#Question 3
n = int(input("What is the size of your four square grid?\n"))

# row is the row number
for row in range(2*n+3):

    # col is the column number.
    for col in range(2*n+3):

        # All rows or columns divisible by n+1 have stars.
        if row%(n+1) == 0 or col%(n+1) == 0:
            print("*", end="")

        # Everything else has a space.
        else:
            print(" ", end="")

    # Need to advance to the next line.
    print()

# Question 4
def harmonic(n):
    # Code goes here
    res = 0
    for i in range(1, n+1):
        res = res + 1/i
    return res
    
print(harmonic(1))
print(harmonic(3))
print(harmonic(100))


# Made up Function Question
# void function, print the character c, n times
def printChar(c, n):
    for i in range(n):
        print(c, end="")

printChar("$", 20)
printChar("\n", 1)


# Made up Function Question 2
# fibonacci numbers 1, 1, 2, 3, 5, 8, 13, ...
# You add the last two to get the next one and the first 2 are 1
# Write a function that takes in n and returns the nth fibonacci number
def fib(n):
    if n == 1 or n == 2:
        return 1

    prev = 1
    cur = 1
    newfib = 0
    for i in range(3, n+1):

        # Add the last two.
        newfib = prev + cur

        # My new prev is the old cur.
        prev = cur

        # My new cur is the newly calculated fib
        cur = newfib

    return newfib

for i in range(1, 15):
    print(i, fib(i))
'''
    
# Fix for #5 in Part A
'''
for j in range(len(studentGrades[i])):
    if studentGrades[i][minIdx] > studentGrades[i][j]:
        minIdx = j
'''

# Last question on part B
fooditems = {}
file = open("donations.txt", "r")
numitems = int(file.readline().rstrip())

# Read through each item.
for i in range(numitems):

    # Get the item.
    food = file.readline().rstrip()

    # If we never saw it, add it.
    if not food in fooditems:
        fooditems[food] = 1

    # Otherwise, add 1 to its quantity.
    else:
        fooditems[food] += 1

    # This is what was request.
    print(food,fooditems[food])

# Close file.
file.close()
