#!/user/bin/python3


n = int(raw_input(' No. of Process : '))

array = []

wait_time = 0.0


for i in xrange(n):

	array.append([])
	print ' '
	array[i].append(raw_input('Enter Process Name please: ' ))

	array[i].append(int(raw_input('Enter Arrival Time please ')))
	array[i].append(int(raw_input('Enter Burst Time please :')))
	print 'ok '

array.sort(key = lambda array:array[1])

wait = []
j = 1
service = []
service.append(array[0][1])
wait.append(service[0] - array[0][1])

while (j<n):
	service.append(service[j-1] + array[j-1][2])
	wait.append(service[j] - array[j][1])
	wait_time += wait[j]
	j += 1

print 'Process Name \tArrival Time \t Burst Time \t Service Time \t Waiting Time'
for i in xrange(n):
	print '\t',array[i][0] ,'\t\t\t\t' ,array[i][1] ,'\t\t\t\t', array[i][2], '\t\t\t\t',service[i],'\t\t2\t\t',wait[i]


print 'Average Waiting Time : ',(wait_time/(n*1.0))
print 'Total Waiting Time : ',wait_time
