qyliang/CodeNanoFix huggingface dataset:
Title: Rank Checker

In the year 2020, there is data saved from the preliminary results of the 2020 Computer Koshien. This data includes a team's assigned serial number and the number of correct answers. The ranking is determined based on the number of correct answers, with higher numbers receiving higher ranks.

Create a program that takes input from the keyboard for the preliminary results data and the serial number of the team for which the rank is to be determined, and outputs the rank of that team.

Input:
The input data consists of two parts. The first part is the preliminary results data, and the second part is the inquiry for the team's rank. The format of the preliminary results data is as follows:
p1, s1
p2, s2
...
...
0, 0

Where pi (1 ≤ pi ≤ 100) and si (0 ≤ si ≤ 30) represent the serial number and the number of correct answers for the i-th team. The input ends when both the serial number and the number of correct answers are 0.

Following this, multiple inquiries are provided in the following format:
q1
q2
...

Each inquiry consists of one line with the serial number qi (1 ≤ qi ≤ 30). Process these inquiries until the end of the input. The number of inquiries does not exceed 100.

Output:
For each inquiry, output the team's rank on a separate line.

Sample Input:
1,20
2,20
3,30
4,10
5,10
6,20
0,0
1
2
4
5

Output for the Sample Input:
2
2
3
3

Note:
In the given input data, when the teams are sorted based on the number of correct answers, the order is as follows:
3,30
1,20
2,20
6,20
4,10
5,10

Here, the ranking is based on the number of correct answers, with the team with 30 correct answers being 1st, those with 20 correct answers being 2nd, and those with 10 correct answers being 3rd (note that this differs from the usual ranking, considering the number of top teams with 10 correct answers).

# Buggy version:
def Inquiry(team):
	ranking=1
	score=team_score[0][1]
	for i in team_score:
		if score>i[1]:
			ranking+=1
			score=i[1]
		if i[0]==team:
			return ranking

team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

print(team_score)
team_score.sort(key=lambda x:x[1],reverse=True)
print(team_score)

while True:
	try:
		team=int(input())
		print(Inquiry(team))
	
	except EOFError:
		break

# Fixed version:
def Inquiry(team):
	ranking=1
	score=team_score[0][1]
	for i in team_score:
		if score>i[1]:
			ranking+=1
			score=i[1]
		if i[0]==team:
			return ranking

team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

#print(team_score)
team_score.sort(key=lambda x:x[1],reverse=True)
#print(team_score)

while True:
	try:
		team=int(input())
		print(Inquiry(team))
	
	except EOFError:
		break

# Buggy version:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print({*c}.sort()[::-1].index(d[int(y)])+1)


# Fixed version:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1)
Title: Palindrome

There is data consisting of strings of half-width alphabet characters, with each line containing data of up to 100 characters. Some lines are symmetrical (read the same from left to right and right to left). Create a program to read this data and output the number of symmetrical strings within it. Note that a line consisting of only one character is considered symmetrical.

Input:
Multiple strings are given across multiple lines. Each line contains one string, and the number of strings does not exceed 50.

Output:
Output the number of symmetrical strings in a single line.

Sample Input:
abcba
sx
abcddcba
rttrd

Output for the Sample Input:
2

# Buggy version:
import sys
print(e[:-1]==e[-2::-1]for e in sys.stdin)


# Fixed version:
import sys
print(sum(e[:-1]==e[-2::-1]for e in sys.stdin))
Title: Passcode

New passcodes are difficult to remember. Although it's forbidden to write them down, it's hard to memorize. Therefore, I decided to embed numbers within a text to remember the passcode. Here, the sum of all the numbers will be the passcode.

Create a program that reads the embedded text and outputs the passcode.

Input:
Positive integers are embedded within multiple lines of text. Each line contains a string of characters, including alphanumeric characters, symbols, and spaces, or it may be empty. Each line is guaranteed to be within 80 characters, and the passcode is guaranteed to be less than or equal to 10,000.

Output:
Output the passcode (the sum of the positive integers in the text) in a single line.

Sample Input:
Thereare100yenonthetable.Iam17yearsold.
Ishouldgohomeat6pm.

Output for the Sample Input:
123

# Buggy version:
ans = ""
while True:
    try:
        memo = input()
    except:
        break
    for m in memo:
        ans = ans+m if m.isdigit() else ans+"@"
print(sum(ans.replace("@", " ").split()))

# Fixed version:
ans = ""
while True:
    try:
        memo = input()
    except:
        break
    for m in memo:
        ans = ans+m if m.isdigit() else ans+"@"
print(sum(map(int, ans.replace("@", " ").split())))

# Buggy version:
import re
try:
    ls = num = []
    result = 0
    while True:
        ls.append(input())
except:
    for i in ls:
        for s in range(re.findall(r'\d+', i)):
            result += int(s)
    print(result)

# Fixed version:
import re
try:
    ls = []
    while True:
        ls.append(input())
except:
    result = 0
    for i in ls:
        for s in re.findall(r'\d+', i):
            result += int(s)
    print(result)

# Buggy version:
import re

l=0
try:
 while True:
  x=input()
  for i in re.findall(r'\d+',x):
      lst+=int(i)
except:
   print(l)

# Fixed version:
import re

l=0
try:
 while True:
  x=input()
  for i in re.findall(r'\d+',x):
      l+=int(i)
except:
   print(l)
Title: Tic-Tac-Toe

Tic-tac-toe is a game played on a 3x3 grid where players take turns placing either a circle (○) or a cross (×) in the grid. The game is won when either circles or crosses form a line vertically, horizontally, or diagonally (refer to Figures 1-3).

Figures:
1. Circle wins
2. Cross wins
3. Draw

In tic-tac-toe, players take turns placing circles and crosses until one of them forms a line. Therefore, a scenario where both circles and crosses form a line simultaneously, as shown in Figure 4, is not possible. It is guaranteed that such impossible scenarios will not be given as input.

Figure:
4. Impossible scenario

Create a program that reads the tic-tac-toe board and outputs the result of the game.

Input:
The input consists of multiple datasets. Each dataset contains a single string representing the board on one line. The board string uses lowercase letters 'o' for circles, 'x' for crosses, and 's' for empty spaces, arranged in the order of the grid shown in the diagram.

The number of datasets does not exceed 50.

Output:
For each dataset, output 'o' if circles win, 'x' if crosses win, or 'd' if the game is a draw.

Sample Input:
ooosxssxs
xoosxsosx
ooxxxooxo

Output for the Sample Input:
o
x
d

# Buggy version:
import sys
f = sys.stdin

vlines = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

for line in f:
    result = 'd'
    for v in vlines:
        if 's' != a and line[v[0]]== line[v[1]] == line[v[2]]:
            result = line[v[0]]
            break
    print(result)

# Fixed version:
import sys
f = sys.stdin


vlines = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

for line in f:
    result = 'd'
    for v in vlines:
        if 's' !=  line[v[0]] and line[v[0]]== line[v[1]] == line[v[2]]:
            result = line[v[0]]
            break
    print(result)
Title: Video Tape

There is a 120-minute video tape in standard recording mode. When the tape is completely rewound and recorded in standard mode, a certain counter value is reached. Create a program that takes this counter value (hours, minutes, seconds) as input, and calculates the remaining tape length (recordable time) and outputs it in the format of hours:minutes:seconds.

Input:
Multiple data sets are given. Each data set is as follows:
T H S
T, H, S are integers representing hours, minutes, and seconds.
When T, H, S are all -1, it marks the end of input. The number of data sets does not exceed 50.

Output:
For each data set:
On the 1st line, output the remaining tape length for standard recording in hours, minutes, seconds separated by a colon.
On the 2nd line, output the remaining tape length for 3 times recording in hours, minutes, seconds separated by a colon.

Sample Input:
1 30 0
-1 -1 -1

Output for the Sample Input:
00:30:00
01:30:00

# Buggy version:
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1\n'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)


# Fixed version:
p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1 -1 -1'):
 h,m,s=map(int,e.split())
 d=7200-h*3600-m*60-s
 p(d);p(d*3)
Title: BMI

Obesity is considered a cause of many adult diseases. In the past, it was largely irrelevant to high school students, except for a few exceptions. However, due to excessive exam preparation leading to lack of exercise or stress-induced overeating, it has become increasingly realistic. This may become a significant concern for high school students.

You are tasked with creating a program as an assistant to the school nurse to identify students with suspected obesity based on their data.

The method involves calculating the BMI (Body Mass Index) using the following formula:

BMI = weight / (height * height)

A BMI of 22 is considered standard, and above 25 indicates suspected obesity.

Create a program that calculates the BMI for each student based on their weight and height, and outputs the student ID for those with a BMI of 25 or higher.

Input:
The input is given in the following format:
s1, w1, h1
s2, w2, h2
...

Where si (1 ≤ si ≤ 2,000), wi (1 ≤ wi ≤ 200), and hi (1.0 ≤ hi ≤ 2.0) represent the student ID (integer), weight (real number), and height (real number) for the ith student.

There are no more than 50 students.

Output:
Output the student ID of those with a BMI of 25 or higher in the order they were inputted, each on a new line.

Sample Input:
1001,50.0,1.60 
1002,60.0,1.70 
1003,70.0,1.80 
1004,80.0,1.70 
1005,90.0,1.60 

Output for the Sample Input:
1004
1005

# Buggy version:
def bmi(w,h):
    return w / (h ** 2)

s,w,h = [],[],[]
while True:
    try:
        tmp = input().split(',')
        s.append(float(tmp[0]))
        w.append(float(tmp[1]))
        h.append(float(tmp[2]))
    except EOFError:
        break
f = []
for i in range(len(s)):
    if bmi(w[i],h[i]) >= 25:
      f.append(s[i])
if len(f) != 1 and len(f) != 0:
    for i in range(len(f)-1):
        print(f[i])
if len(f) != 1 and len(f) != 0:
    print(f[-1])
elif len(f) == 1:
    print(f[0])

# Fixed version:
def bmi(w,h):
    return w / (h ** 2)

s,w,h = [],[],[]
while True:
    try:
        tmp = input().split(',')
        s.append(int(tmp[0]))
        w.append(float(tmp[1]))
        h.append(float(tmp[2]))
    except EOFError:
        break
f = []
for i in range(len(s)):
    if bmi(w[i],h[i]) >= 25:
      f.append(s[i])
if len(f) != 1 and len(f) != 0:
    for i in range(len(f)-1):
        print(f[i])
if len(f) != 1 and len(f) != 0:
    print(f[-1])
elif len(f) == 1:
    print(f[0])

# Buggy version:
try:
    s, w, h = map(float, input().split(','))
    if w / h**2 >= 25:
        print(int(s))
except:
    pass

# Fixed version:
try:
    while True: 
        s, w, h = map(float, input().split(','))
        if w / h**2 >= 25:
            print(int(s))
except:
    pass

# Buggy version:
import sys
l=[list(map(float,i.split(","))) for i in sys.stdin]
bmi=lambda i:i[1]/(i[2]**2)
[print(int(i[0])) for i in l bmi(i)>=25]


# Fixed version:
import sys
l=[list(map(float,i.split(","))) for i in sys.stdin]
bmi=lambda i:i[1]/(i[2]**2)
[print(int(i[0])) for i in l if bmi(i)>=25]
Title: Merry-Go-Round

In an amusement park, there is a merry-go-round, a classic ride where various vehicles such as horses and carriages are fixed on a large disc that rotates, causing the vehicles to move up and down. In a particular amusement park, the merry-go-round is equipped with two 4-seater carriages, two 2-seater cars, and four 1-seater horses, arranged in a specific order. Customers at the park wait at one of the eight boarding locations shown in Figure 1.

The merry-go-round always stops with the vehicles perfectly aligned with the boarding locations. Each waiting customer at locations 0 to 7 is expected to board the vehicle that stops in front of them. Customers cannot rush to another location to board a different vehicle. To efficiently entertain the customers, the stopping positions of the merry-go-round need to be adjusted to minimize the number of customers who cannot board.

Create a program that reads the number of customers waiting at locations 0 to 7 and outputs the optimal stopping positions for the vehicles to minimize the number of customers who cannot board.

Input:
The input consists of multiple datasets. Each dataset is given in the following format:
p0 p1 p2 p3 p4 p5 p6 p7

Output:
For each dataset, output the stopping positions for the vehicles at locations 0 to 7 as c0, c1, ..., c7, separated by a space.

Note: If there are multiple ways to minimize the number of customers who cannot board, output any one of those ways. The number of datasets does not exceed 100.

Sample Input:
2 3 1 4 0 1 0 1
4 2 3 2 2 2 1 1

Output for the Sample Input:
1 4 1 4 1 2 1 2
4 1 4 1 2 1 2 1

# Buggy version:
mgr = [4, 1, 4, 1, 2, 1, 2, 1]

while True:
    try:
        p = list(map(int, input().split(' ')))
        v = []
        for i in range(8):
            q = mgr[i:] + mgr[:i]
            sum_v = sum(p) - sum(p[j]-q[j] if p[j]-q[j] >= 0 else 0 for j in range(8))
            v.append(sum_v)
        if v.count(max(v)) > 1:
            mv = max(v)
            ans = []
            for i in range(8):
                if v[i] == mv:
                    ans.append(int("".join(map(str, mgr[i:] + mgr[:i]))))
            print(" ".join(list(str(min(ans)))))
        else:
            i = v.index(max(v))
            print(mgr[i:] + mgr[:i])
    except:
        break

# Fixed version:
mgr = [4, 1, 4, 1, 2, 1, 2, 1]

while True:
    try:
        p = list(map(int, input().split(' ')))
        v = []
        for i in range(8):
            q = mgr[i:] + mgr[:i]
            sum_v = sum(p) - sum(p[j]-q[j] if p[j]-q[j] >= 0 else 0 for j in range(8))
            v.append(sum_v)
        if v.count(max(v)) > 1:
            mv = max(v)
            ans = []
            for i in range(8):
                if v[i] == mv:
                    ans.append(int("".join(map(str, mgr[i:] + mgr[:i]))))
            print(" ".join(list(str(min(ans)))))
        else:
            i = v.index(max(v))
            print(" ".join(map(str, mgr[i:] + mgr[:i])))
    except:
        break
Convert the given Gregorian calendar date into the corresponding Japanese era (wareki) and output the result. If the input date is before the Meiji era, output "pre-meiji". The first year of each era should be displayed as "1 year" instead of "元年". Process multiple sets of input data until the end of input, with a maximum of 50 data sets. Output the era, year, month, and day separated by spaces on a single line, or "pre-meiji" if the date is before the Meiji era.

# Buggy version:
import sys
f = sys.stdin

from datetime import date

eras = {'pre-meiji':{'start':None, 'end':date(1868,9,7)},
'meiji':{'start':date(1868, 9, 8), 'end':date(1912,7,29)},
'taisho ':{'start':date(1912, 7, 30), 'end':date(1926,12,24)},
'showa ':{'start':date(1926, 12, 25), 'end':date(1989,1,7)},
'heisei ':{'start':date(1989, 1, 8), 'end':None}}

for line in f:
    y, m, d = map(int, line.split())
    target = date(y,m,d)
    for era_name, period in eras.items():
        if (period['start'] is None or period['start'] <= target) and(period['end'] is None or target <= period['end']):
            if era_name == 'pre-meiji':
                print(era_name)
            else:
                print(era_name, target.year - period['start'].year + 1, target.month, target.day)
            break
            

# Fixed version:
import sys
f = sys.stdin

from datetime import date

eras = {'pre-meiji':{'start':None, 'end':date(1868,9,7)},
'meiji':{'start':date(1868, 9, 8), 'end':date(1912,7,29)},
'taisho':{'start':date(1912, 7, 30), 'end':date(1926,12,24)},
'showa':{'start':date(1926, 12, 25), 'end':date(1989,1,7)},
'heisei':{'start':date(1989, 1, 8), 'end':None}}

for line in f:
    y, m, d = map(int, line.split())
    target = date(y,m,d)
    for era_name, period in eras.items():
        if (period['start'] is None or period['start'] <= target) and(period['end'] is None or target <= period['end']):
            if era_name == 'pre-meiji':
                print(era_name)
            else:
                print(era_name, target.year - period['start'].year + 1, target.month, target.day)
            break
Title: Search Engine

Internet search engines such as Google automatically gather and categorize web pages from around the world to create a massive database. They also analyze user-input search keywords to generate queries for database searches.

In both cases, complex processing is performed to achieve efficient searches, but the basic step in all cases is to extract words from the text.

Your challenge is to extract words from a given English text. For this task, the target text will be English sentences with clear word boundaries.

Target Text:
- English text of up to 1024 characters without line breaks
- Delimiters: spaces, periods, and commas
- Extracted words: words with 3 to 6 characters (ignore words with 2 or fewer characters or 7 or more characters)

Input:
- A single line of English text consisting of delimiters and alphanumeric characters

Output:
- Output the extracted words separated by a single space on a single line.

Sample Input:
Rain, rain, go to Spain.

Output for the Sample Input:
Rain rain Spain

Sample Input 2:
Win today's preliminary contest and be qualified to visit University of Aizu.

Output for the Sample Input 2:
Win and visit Aizu

# Buggy version:
import re

s = re.split("[ .,]", input())
sl = len(s)
ans = list()

for i in range(sl) :
  if(2 < len(s[i]) and len(s[i]) < 7) :
    ans.append(s[i])
  else :
    pass

ansl = len(ans)
print(ansl)
for i in range(ansl) :
  if(i == ansl - 1) :
    print(ans[i])
  else :
    print(ans[i], end = (" "))


# Fixed version:
import re

s = re.split("[ .,]", input())
sl = len(s)
ans = list()

for i in range(sl) :
  if(2 < len(s[i]) and len(s[i]) < 7) :
    ans.append(s[i])
  else :
    pass

ansl = len(ans)

for i in range(ansl) :
  if(i == ansl - 1) :
    print(ans[i])
  else :
    print(ans[i], end = (" "))

# Buggy version:
print(' '.join([w for w in input().replace(',', '').replace('.', '').split(', ') if len(w) > 2 and len(w) < 7]))

# Fixed version:
print(' '.join([w for w in input().replace(',', '').replace('.', '').split(' ') if len(w) > 2 and len(w) < 7]))

# Buggy version:
print(*filter(lambda x: 2 < len(x) < 7, input().strip(",.").split()))

# Fixed version:
print(*filter(lambda x:2<len(x)<7,map(lambda x:x.strip('.,'),input().split())))

# Buggy version:
import re
print(*[x for x in re.split(r'\s|"|,|\.',input())if 2<len(s)<7])


# Fixed version:
import re
print(*[x for x in re.split(r'\s|"|,|\.',input())if 2<len(x)<7])
Title: Shortest Path

In the given diagram, arrange integers (0 to 99) in a triangular pattern. Create a program that reads this triangular data and, starting from the top, follows a specific rule to move to the bottom, outputting the maximum sum of integers passed.

- At each step, you can move to the bottom left or bottom right along the diagonal.
  
For example, in the given diagram, by selecting 7, 3, 8, 7, 5, 7, 8, 3, 7, the sum is maximized to 55 (7+3+8+7+5+7+8+3+7=55).

Input:
A sequence of integers separated by commas, arranged in a triangular shape as shown in the input example. There are less than 100 rows of data.

Output:
Output the maximum sum of integers passed according to the rule.

Sample Input:
7
3,8
8,1,0
2,7,4,4
4,5,2,6,5
2,7,4,4
8,1,0
3,8
7

Sample Output:
55

# Buggy version:
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 for j in range(len(s[i])):
  t=j-len(s[i])>len(s[i-1])
  s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])


# Fixed version:
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 k=len(s[i]);b=k>len(s[i-1])
 for j in range(k):t=j-b;s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])
Title: Ice Fishing Contest

In Hikaru Lake, an ice fishing contest for smelt was held. The person who caught the most smelt is the winner.

Create a program that reads a list of participant numbers and the number of smelt caught, and outputs the winner's number and the number of smelt caught. If there are multiple winners, output the one with the smallest participant number.

Input:
The input is given in the following format:
n
a1 v1
a2 v2
...
an vn

n (1 <= n <= 20) is the number of participants. ai represents the participant number, which is a unique integer between 1 and n. vi (0 <= vi <= 100) is the number of smelt caught by participant ai.

Output:
Output the winner's participant number and the number of smelt caught separated by a space on a single line.

Input Example:
6
1 14
2 25
3 42
4 11
5 40
6 37

Output Example:
3 42

# Buggy version:
from operator import itemgetter
n = int(input())
rs = [list(map(int(),input().split())) for i in range(n)]
rs = sorted(rs,key=itemgetter(0))
print(' '.join(map(str, sorted(rs, key=itemgetter(1),reverse=True)[0])))

# Fixed version:
from operator import itemgetter
n = int(input())
rs = [list(map(int,input().split())) for i in range(n)]
rs = sorted(rs,key=itemgetter(0))
print(' '.join(map(str, sorted(rs, key=itemgetter(1),reverse=True)[0])))
Title: "Wakasagi Fishing Tournament 2"

In Hiyohara Lake, a wakasagi fishing tournament took place. This time, catch and release is being encouraged.

Participants' numbers and the number of fish caught or released are read sequentially as events. Create a program to output the participant number and the number of fish they have at hand immediately after each event. If multiple participants have the most fish (or if all participants have 0 fish), output the one with the smallest participant number.

Input:
The input is given in the following format:
n q
a1 v1
a2 v2
...
aq vq

n (1 ≤ n ≤ 1000000) represents the number of participants, and q (1 ≤ q ≤ 100000) represents the number of events. ai (1 ≤ ai ≤ n) and vi (-100 ≤ vi ≤ 100) indicate that participant ai caught or released vi fish in the ith event. vi is positive for catching, negative for releasing, and never 0.

Output:
For each event, output the participant number and the number of fish they have at hand, separated by a single space on one line.

Example Input 1:
3 5
1 4 
2 5 
1 3
3 6
2 7

Example Output 1:
1 4
2 5
1 7
1 7
2 12

Example Input 2:
3 5
1 4 
2 5 
2 -3
3 4
1 -1

Example Output 2:
1 4
2 5
1 4
1 4
3 4

# Buggy version:
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>maxv:w,m=a,s[a]
 elif s[a]==maxv:w=min(w,a)
 print(w,m)


# Fixed version:
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>m:w,m=a,s[a]
 elif s[a]==m and a<w:w=a
 print(w,m)

# Buggy version:
import queue
n,q=map(int,input().split())
p=queue.PriorityQueue()
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v;p.put((-s[a],a))
 while 1:
  t=p.get();print('___',t)
  if -t[0]==s[t[1]]:print(t[1],-t[0],s);p.put(t);break


# Fixed version:
import queue
n,q=map(int,input().split())
p=queue.PriorityQueue()
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v;p.put((-s[a],a))
 while 1:
  t=p.get()
  if -t[0]==s[t[1]]:print(t[1],-t[0]);p.put(t);break