Problem:
Score : 100 points

Problem Statement

There are three airports A, B and C, and flights between each pair of airports in both directions.

A one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.

Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport.

What is the minimum possible sum of the flight times?

Constraints

1 \leq P,Q,R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

P Q R

Output

Print the minimum possible sum of the flight times.

Sample Input 1

1 3 4

Sample Output 1

4

The sum of the flight times in the route A \rightarrow B \rightarrow C: 1 + 3 = 4 hours

The sum of the flight times in the route A \rightarrow C \rightarrow C: 4 + 3 = 7 hours

The sum of the flight times in the route B \rightarrow A \rightarrow C: 1 + 4 = 5 hours

The sum of the flight times in the route B \rightarrow C \rightarrow A: 3 + 4 = 7 hours

The sum of the flight times in the route C \rightarrow A \rightarrow B: 4 + 1 = 5 hours

The sum of the flight times in the route C \rightarrow B \rightarrow A: 3 + 1 = 4 hours

The minimum of these is 4 hours.

Sample Input 2

3 2 3

Sample Output 2

5

Solution in PyPy2 (5.6.0) (judge verdict: Runtime Error)

from collections import deque

def solve():
    H, W = [int(_) for _ in raw_input().split()]
    S = []
    for i in range(H):
        Si = [_ for _ in raw_input()]
        S.append(Si)
    rowm = [None] * H
    for i in range(H):
        start = -1
        end = 0
        save = (start, end, i)
        for j in range(W):
            if S[i][j] == '.':
                end = j
            else:
                start = j
                end = j
            if end - start > save[1] - save[0]:
                save = (start, end, i)
        rowm[i] = save
    colm = [None] * W
    for j in range(W):
        start = -1
        end = 0
        save = (start, end, j)
        for i in range(H):
            if S[i][j] == '.':
                end = i
            else:
                start = i
                end = i
            if end - start > save[1] - save[0]:
                save = (start, end, j)
        colm[j] = save
    rowm.sort(key = lambda x: x[1] - x[0], reverse = True)
    colm.sort(key = lambda x: x[1] - x[0], reverse = True)
    def max_ans(i,j):
        s1, e1, row = rowm[i]
        s2, e2, col = colm[j]
        return e1 - s1 + e2 - s2 - 1
    # priority queue
    ij_set = set()
    ij_set.add((0, 0))
    queue = deque()
    queue.append((max_ans(0, 0), 0,0))
    def AddToQueue(_ele):
        if len(queue) == 0:
            queue.append(_ele)
        else:
            cnt = 0
            while cnt < len(queue) and queue[cnt][0] >= _ele[0]:
                cnt += 1
            ij = (_ele[1], _ele[2])
            if not (ij in ij_set):
                queue.insert(cnt, _ele)
                ij_set.add(ij)
    ret = 1
    while len(queue) > 0:
        ans, i, j = queue.popleft()
        s1, e1, row = rowm[i]
        s2, e2, col = colm[j]
        if ans == 1:
            ret = ans
            break
        if row >= s2 and row <=e2 and col >= s1 and col <= e1:
            ret = ans
            break
        if i + 1 < H:
            AddToQueue((max_ans(i+1,j), i+1, j))
        if j + 1 < W:
            AddToQueue((max_ans(i,j+1), i, j+1))
    print ret

if __name__ == '__main__':
    solve()