Problem:


Sum and Average

販売単価と販売数量を読み込んで、販売金額の総合計と販売数量の平均を出力するプログラムを作成してください。

Input

入力は以下の形式で与えられます。

販売単価,販売数量
販売単価,販売数量
:
:

カンマで区切られた販売単価と販売数量の組が、複数行に渡って与えられます。入力される値はすべて 0 以上 1,000 以下で、販売単価と販売数量の組の数は 100 を超えません。

Output

１行目に販売金額の総合計（整数）、２行目に販売数量の平均(整数）を出力してください。
販売数量の平均に端数（小数点以下の数）が生じた場合は小数点以下第 1 位を四捨五入してください。

Sample Input

100,20
50,10
70,35

Output for the Sample Input

4950
22



Sample input:
100,20
50,10
70,35


Sample output:
4950
22

Submission status: Accepted

Solution code:
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
print(sum(a*n for a,n in s))
print(int([sum(x)for x in zip(*s)][1]/len(s)+.5))

Submission status: Accepted

Solution code:
import sys
s=m=k=0
for e in sys.stdin:
 a,n=map(int,e.split(','))
 s+=a*n;m+=n;k+=1
print(s)
print(int(m/k+.5))

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_HALF_UP
c = p = i = 0
while 1:
    try:
        v, n = map(int, input().split(","))
        i += 1
        c += n
        p += n * v
    except:break
print(p)
print(Decimal(c / i).quantize(Decimal('0'), rounding=ROUND_HALF_UP))

Submission status: Accepted

Solution code:
num_sum = 0
value_sum = 0
count = 0
while True:
  try:
    value, num = map(int, input().split(","))
    num_sum += num
    value_sum += value * num
    count += 1
  except EOFError:
    break

average = int(num_sum / count + 0.5) if num_sum % count else num_sum // count

print(value_sum)
print(average)

Submission status: Accepted

Solution code:
import sys
a=[list(map(int,i.split(","))) for i in sys.stdin]
print(sum(map(lambda x:x[0]*x[1],a)))
print(int(sum(map(lambda x:x[1],a))/len(a)+0.5))

Submission status: Accepted

Solution code:
# AOJ 0045: Sum and Average
# Python3 2018.6.12 bal4u

sum = 0
n = 0
k = 0
while True:
    try:
        a, b = list(map(int, input().split(',')))
        sum += a*b
        n += b
        k += 1
    except EOFError:
        break
        
print(sum)
if n % k > (k-1)//2:
	print(n//k + 1)
else:
	print(n//k)

Submission status: Accepted

Solution code:
total, num, cnt = 0, 0, 0
try:
    while True:
        n, m = map(int, input().split(","))
        total += n*m
        num += m
        cnt += 1
except EOFError:
    print(total)
    n = num/cnt
    n = int(n) if n%1 < 0.5 else int(n)+1
    print(n)

Submission status: Accepted

Solution code:
sougou,heikin=[],[]
t=" "
while True:
  try:
    ans = raw_input()
    ans+=t
    for i in range(len(ans)):
      if ans[i] == ",":
        sougou.append(int(ans[:i]))
        heikin.append(int(ans[i+1:]))
  except EOFError:  break 
a,b=0,0
for i in range(len(heikin)):
  a+=heikin[i]*sougou[i]
  b+=heikin[i]
if float(b)/len(heikin)> int(float(b)/len(heikin)):
  c = int(float(b)/len(heikin))+1
else: c = int(b)
if __name__ == '__main__':
  print "%d\n%d"%(a,c)

Submission status: Accepted

Solution code:
import sys,math
price,amount=[],[]
for line in sys.stdin.readlines():
    line=map(int,line.strip().split(","))
    price.append(line[0])
    amount.append(line[1])
tp=sum([price[i]*amount[i] for i in xrange(len(price))])
ta=sum(amount)
print tp
print int(math.ceil((ta+0.0)/(len(amount)+0.0)))

Submission status: Accepted

Solution code:
total = 0
count = 0
rows = 0

while True:
    try:
        at,n = map(int, raw_input().split(","))
    except EOFError as e:
        break
    total += at * n
    count += n
    rows += 1

print("%d" % (total,))
print("%d" % (int(count/float(rows) + 0.5),))

Submission status: Accepted

Solution code:
total = 0
count = 0
rows = 0

while True:
    try:
        at,n = map(int, raw_input().split(","))
    except EOFError as e:
        break
    total += at * n
    count += n
    rows += 1

print("%d" % (total,))
print("%d" % (round(count/float(rows)),))

Submission status: Accepted

Solution code:
import sys
sum_n,kazu,c=0,0.0,0.0
for line in sys.stdin:
    line=map(int,line.strip().split(","))
    sum_n+=line[0]*line[1]
    kazu+=line[1]
    c+=1
print "{}\n{}".format(sum_n,int(round(kazu/c)))

Submission status: Accepted

Solution code:

import sys


total = 0
number = 0
i = 0

for line in sys.stdin:
    price, num = tuple(map(int, line.split(',')))
    total += price * num
    number += num
    i += 1
print total
print int(round(float(number) / float(i)))

Submission status: Accepted

Solution code:
import math

nsum = 0 
naverage = 0 
i = 0 
while True:
    try:

        price,num = map(int,raw_input().split(","))
        nsum += num*price
        naverage += num 
        i += 1

    except EOFError:
        break

print nsum
print int(round(float(naverage)/float(i)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

price = 0
num = 0
for i, line in enumerate(stdin, 1):
    p, n = (int(s) for s in line.split(','))
    price += p * n
    num += n

print(price)
print(int(num / i + 0.5))

Submission status: Accepted

Solution code:
grs = 0 ; num = 0 ; tim = 0
while True:
	try:
		x = map(float,raw_input().split(','))
		a = x[0] * x[1]
		grs += int(a)
		num += x[1]
		tim += 1
		continue
	except: break
print grs
print int(round(float(num) / float(tim),0))

Submission status: Accepted

Solution code:
import sys

r = []
for s in sys.stdin:
    r.append(map(int, s.split(',')))
print sum([i[0]*i[1] for i in r])
print int(float(sum(([i[1] for i in r]))) / len(r) + 0.5)

Submission status: Accepted

Solution code:
import sys

l = [map(int,i.split(',')) for i in sys.stdin]
print sum([i*j for i,j in l])
print int(round(1.0* sum([j for i,j in l]) / len(l)))

Submission status: Accepted

Solution code:
a=0
b=0
c=0
while True:
    try: p,n=input()
    except: break
    a += p*n
    b += n
    c += 1
print "%d\n%d" %(a,round(1.0*b/c))

Submission status: Accepted

Solution code:
import sys

a=0
b=0
c=0
for line in sys.stdin:
    p,n=map(int,line.split(','))
    a += p*n
    b += n
    c += 1
d = int(round(1.0*b/c))
print "{}\n{}".format(a,d)

Submission status: Accepted

Solution code:
i, all, sum = 0, 0, 0
while True:
    try:
        price, n = map(int, raw_input().split(","))
        i += 1; all += n; sum += price*n
    except:
        break
    
print sum
print int(round(float(all)/i))

Submission status: Accepted

Solution code:
import sys
a=0
b=0
c=0
x=[map(int,s[:-1].split(",")) for s in sys.stdin]
for p,n in x:
    a += p*n
    b += n
    c += 1
print "%d\n%d" %(a,round(1.0*b/c))

Submission status: Accepted

Solution code:
import sys
a=0
b=0
c=0
for s in sys.stdin:
    p,n = map(int,s.split(","))
    a += p*n
    b += n
    c += 1
print "%d\n%d" %(a,round(1.0*b/c))

Submission status: Accepted

Solution code:
a=0
b=0
c=0
while 1:
    try: p,n=input()
    except: break
    a += p*n; b += n; c += 1
print "%d\n%d" %(a,round(1.0*b/c))

Submission status: Accepted

Solution code:
try:
    a, b = [], []
    while True:
        p, q = map(int, raw_input().split(','))
        a.append(p * q)
        b.append(q)
except EOFError:
    pass
print sum(a)
print int(round(float(sum(b)) / len(b)))

Submission status: Accepted

Solution code:
from itertools import starmap
from operator import mul

items = []
while 1:
    try:
        price, amount = map(int, raw_input().split(','))
    except EOFError:
        break
    items.append((price, amount))
print sum(starmap(mul, items))
print int(round(1.0 * sum(map(lambda a: a[1], items)) / len(items)))

Submission status: Accepted

Solution code:
import sys

s = c = n = 0
for line in sys.stdin:
    x, y = map(int, line.split(','))
    s += x * y
    c += y
    n += 1
print(s)
print(int(c / n + 0.5))

Submission status: Accepted

Solution code:
A = []
while True:
    try:
        a = list(map(int, input().split(',')))
    except:
        break
    A.append(a)

Sum = 0
N = 0
for i in range(len(A)):
    Sum += A[i][0] * A[i][1]
    N += A[i][1]
N_average = N / len(A)
N_average_int = N // len(A)

if 0 <= N_average - N_average_int <0.5:
    N_average = int(N_average_int)
else:
    N_average = int(N_average_int) + 1

print(Sum)
print(N_average)

Submission status: Accepted

Solution code:
import math
k = []
s = 0
while True:
    try:
        lst = list(map(int, input().split(',')))
        s += lst[0]*lst[1]
        k.append(lst[1])

    except EOFError:
        break

a = sum(k)/len(k)
print(s)
print(math.floor(a + 0.5))

Submission status: Accepted

Solution code:
#空リスト作成
kei = []
ko = []

#EOFErrorが出た場合終わる
try:
    while True:
        
        #標準入力し、金額と個数をリストに加える
        a,b = map(int,input().split(","))
        kei.append(a * b)
        ko.append(b)
except EOFError:
    
    #金額の合計を出力する
    print(sum(kei))
    
    #平均値を出力する
    i = int(sum(ko) / len(ko) * 10)
    if i % 10 <= 4:print(i // 10)
    else:print(i // 10 + 1)

Submission status: Accepted

Solution code:
total_cost = 0
total_amount = 0
n = 0

while True :
    try :
        cost, amount = map(int, input().split(','))
        n += 1
        total_cost += cost * amount
        total_amount += amount
        
    except EOFError :
        break

print(total_cost)
float_total_amount = total_amount / n - total_amount // n
if float_total_amount < 0.5 :
    print(total_amount // n)
else :
    print(total_amount // n + 1)

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    su = 0; cnt = 0; i = 0
    for line in readlines():
        a, b = map(int, line.split(","))
        su += a*b
        cnt += b
        i += 1
    x = (cnt // i)
    if (2*x+1)*i <= 2*cnt:
        x += 1
    write("%d\n%d\n" % (su, x))
solve()

Submission status: Accepted

Solution code:
from decimal import *
sum = 0
cnt = 0
nums = 0
while 1:
    try:
        price, num = (int(x) for x in input().split(','))
        sum += price * num
        cnt += 1
        nums += num
    except EOFError:
        break

print(sum)
nums = Decimal(nums / cnt).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
print(nums)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    ### intチェック
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    ### 幾何学問題用
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    ### 絶対値
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート（代入する必要なし）
# N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def get_input():
    N = []
    while True:
        try:
            #N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
            N.append([int(x) for x in input().split(',')])
        except EOFError:
            break
    return N

D = get_input()

A = 0
B = 0

for d in D:
    A += (d[0]*d[1])
    B += d[1]

B = B/len(D)

print(A)

if B%1 < 0.5:
    B = B // 1
else:
    B = int(B // 1) + 1

print(B)

Submission status: Accepted

Solution code:
import sys
  
total = 0
quantity = 0
count = 0

for s in sys.stdin:
    p, q = map(int, s.split(','))
    total += p * q
    quantity += q
    count += 1

avg_f = quantity / count
avg = int(avg_f)+1 if avg_f*10%10 >= 5 else int(avg_f)

print(total)
print(avg)

Submission status: Accepted

Solution code:

c = 0
s = 0
num = 0
while True:
    try:
        p, n = [int(x) for x in input().split(",")]
        s += p * n
        c += n
        num += 1
    except:
        break
print(s)
av = c // num
if c%num >= num//2:
    av +=1
print(av)

Submission status: Accepted

Solution code:
def round_off(a):
    return int((2*a+1)//2)


sum1, sum2, count = 0, 0, 0
while 1:
    try:
        a, b = map(int, input().split(','))
        sum1 += a * b
        sum2 += b
        count += 1
    except:
        break

print(sum1)
print(round_off(sum2/count))

Submission status: Accepted

Solution code:
ans_n=0
ans_k=0
count=0
while True:
    try:
        N=list(map(int,input().split(",")))
        ans_n +=N[0]*N[1]
        ans_k +=N[1]
        count +=1
    except:
        print(ans_n)
        ans=ans_k/count
        if int(ans)+0.5<=ans:
            ans=int(ans+1)
        print(ans)
        break

Submission status: Accepted

Solution code:
def round_(i):
    if int(i*10)%10 < 4:
        return int(i)
    else:
        return int(i) + 1

tot = 0
qua = 0
count = 0
while(1):
    try:
        p,q = [int(i) for i in input().split(",")]
        count += 1
        tot += p*q
        qua += q
    except EOFError:
        print(tot)
        print(round_(qua/count))
        break

Submission status: Accepted

Solution code:
import statistics
from decimal import Decimal, ROUND_HALF_UP

pricelist = []
numlist = []
while 1:
    try:
        price, num = map(int, input().split(","))
        pricelist.append(price)
        numlist.append(num)
    except:
        break

sum = 0
mean = statistics.mean(numlist)
for price, num in zip(pricelist, numlist):
    sum += price * num

print(sum)
print(Decimal(str(mean)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def sum_and_average(_input):
    _sum_list = []
    _avg_list = []

    while 1:
        try:
            _sum, _avg = [int(e) for e in _input]
            _sum_list.append(_sum)
            _avg_list.append(_avg)
        except EOFError:
            break
    return sum(_sum_list), (sum(_avg_list) / len(_avg_list))

if __name__ == '__main__':
    _sum, _avg = sum_and_average(input().split())
    print(round(_sum, 1), round(_avg, 1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def sum_and_average():
    _sum_list = []
    _avg_list = []

    while 1:
        try:
            _sum, _avg = [int(e) for e in input().split()]
            _sum_list.append(_sum)
            _avg_list.append(_avg)
        except EOFError:
            break
    return sum(_sum_list), (sum(_avg_list) / len(_avg_list))

if __name__ == '__main__':
    _sum, _avg = sum_and_average()
    print(round(_sum, 1), round(_avg, 1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


_sum_list = []
_avg_list = []

while 1:
    try:
        _sum, _avg = [int(e) for e in input().split()]
        _sum_list.append(_sum)
        _avg_list.append(_avg)
    except EOFError:
        break


_sum, _avg = sum(_sum_list), sum(_avg_list) / len(_avg_list)
print(round(_sum, 1), round(_avg, 1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

_sum_list = []
_avg_list = []

while 1:
    try:
        _sum, _avg = [int(e) for e in input().split()]
        _sum_list.append(_sum)
        _avg_list.append(_avg)
    except:
        break


_sum, _avg = sum(_sum_list), sum(_avg_list) / len(_avg_list)
print(round(_sum, 1), round(_avg, 1))

Submission status: Runtime Error

Solution code:
a, b = [], []
while True:
    try:
        x, y = map(int, line.strip().split(","))
        a, b = a+[x*y], b+[y]
    except:
        break
print(sum(a))
print(round(sum(b)/len(b)))

Submission status: Runtime Error

Solution code:
# _*_ coding: utf-8 _*_

sum = 0
total = 0
cnt = 0

while True:
	s = input()
	
	if s == '':
		break
	
	list = s.split(',')
	sum += int(list[0])*int(list[1])
	total += int(list[1])
	cnt += 1

ave = total / cnt + 0.5

print(sum)
print(int(ave))

Submission status: Runtime Error

Solution code:
sum = 0
total = 0
cnt = 0

while True:
	s = input()
	
	if s == '':
		break
	
	list = s.split(',')
	sum += int(list[0])*int(list[1])
	total += int(list[1])
	cnt += 1

ave = total / cnt + 0.5

print(sum)
print(int(ave))

Submission status: Runtime Error

Solution code:
try:
    while True:
        result = result2 = count = 0
        a, b = map(int, input().split(','))
        result += a*b
        result2 += b
        count += 1
except:
    print(result,"{0:.1f}".format(result2/count))

Submission status: Runtime Error

Solution code:
total=0
s=0
i=0
while True:
 try:
  a,b = map(int,input().split(','))
  total += a*b
  s+=b
  i+=1
 except:
   result=s/i
   print(total)
   print(round(result))

Submission status: Runtime Error

Solution code:
total=0
s=0
i=0
try: 
 while True:
  a,b = map(int,input().split(','))
  total += a*b
  s+=b
  i+=1
except:
   result=s/i
   print(total)
   print(round(result))

Submission status: Runtime Error

Solution code:
total=0
s=0
i=0
try:
 while True:
  a,b = map(int,input().split(','))
  total += a*b
  s+=b
  i+=1
except:
result=s/i 
print(total)
print(round(result))

Submission status: Runtime Error

Solution code:
try:
    result = result2 = count = 0
    while True:
        a, b = map(int, input().split(','))
        result += a*b
        result2 += b
        count += 1
except:
    print(result)
    print((round(result2/count+0.5))

Submission status: Runtime Error

Solution code:
i, all, sum = 0, 0, 0
while True:
    try:
        price, n = map(int, raw_input().split(",")))
        i += 1; all += n; sum += price
    except
        break
    
print sum
print int(round(float(all)/i))

Submission status: Runtime Error

Solution code:
i, all, sum = 0, 0, 0
while True:
    try:
        price, n = map(int, raw_input().split(","))
        i += 1; all += n; sum += price
    except
        break
    
print sum
print int(round(float(all)/i))

Submission status: Runtime Error

Solution code:
import sys

s = c = 0
for line in sys.stdin:
    x, y = map(int line.split())
    s += x * y
    c += y
print(s, round(s / c))

Submission status: Runtime Error

Solution code:
import sys

s = c = 0
for line in sys.stdin:
    x, y = map(int line.split(','))
    s += x * y
    c += y
print(s, round(s / c))

Submission status: WA: Presentation Error

Solution code:
a=0
b=0
c=0
while True:
    try: p,n=input()
    except: break
    a += p*n
    b += n
    c += 1
print a,"\n%d" %round(1.0*b/c)