message stringlengths 2 20.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 1.95k 109k | cluster float64 17 17 | __index_level_0__ int64 3.91k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
Input
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
Output
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
Examples
Input
3 1
Output
3
1 2
2 3
3 1
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#from collections import Counter
#from fractions import Fraction
#s=iter(input())
# for _ in range(int(input())):
#from collections import deque
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
from collections import Counter
#for i in range(int(input())):
#n=int(input())
#n,k=map(int,input().split())
#arr = list(map(int, input().split()))
#for i in range(int(input())):
n,k=map(int,input().split())
if n-k<=k:
print(-1)
else:
print(n*(n-1)//2)
for i in range(1,n+1):
var=i+1
for j in range(k):
var=var%(n+1)
if var==0:
var+=1
print(i, var)
var+=1
``` | instruction | 0 | 4,552 | 17 | 9,104 |
No | output | 1 | 4,552 | 17 | 9,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
Input
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
Output
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
Examples
Input
3 1
Output
3
1 2
2 3
3 1
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
if k > n // 2:
print(-1)
exit()
print(n * k)
arr = list(range(1, n + 1)) + list(range(1, n // 2 + 1))
for i in range(arr[arr.index(max(arr))] ):
for j in range(1, k + 1):
print(arr[i], arr[j + i])
``` | instruction | 0 | 4,553 | 17 | 9,106 |
No | output | 1 | 4,553 | 17 | 9,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
Input
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
Output
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
Examples
Input
3 1
Output
3
1 2
2 3
3 1
Submitted Solution:
```
from sys import stdin,stdout
from collections import *
from math import ceil, floor , log, gcd
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF=float('inf')
def solve():
n,k=mp()
pr(n*k)
ans=[]
for i in range(1,n+1):
c=0
for j in range(1,n+1):
if c==k:
break
if i!=j:
ans.append((i,j))
c+=1
for i in ans:
print(*i)
for _ in range(1):
solve()
``` | instruction | 0 | 4,554 | 17 | 9,108 |
No | output | 1 | 4,554 | 17 | 9,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
Input
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
Output
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
Examples
Input
3 1
Output
3
1 2
2 3
3 1
Submitted Solution:
```
n,k = map(int,input().split())
s=[]
if (k >= n/2):
print(-1)
else:
print(n*k)
for i in range(n):
for j in range(k):
a = i+1
b = (i+j+2)%n
s.append("%d %d"%(a,b))
print("\n".join(s))
``` | instruction | 0 | 4,555 | 17 | 9,110 |
No | output | 1 | 4,555 | 17 | 9,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
import math
d=int(input())
for p in range(0,d):
m=0
n=0
a,b= list(map(int, input().split()))
if a==b:
print(0,0)
continue
x=math.gcd(a,b)
if a>b:
l=(a-b)
else:
l=(b-a)
if x==l:
print(x,0)
continue
q=a%l
w=l-q
print(l,min(q,w))
``` | instruction | 0 | 5,277 | 17 | 10,554 |
Yes | output | 1 | 5,277 | 17 | 10,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
# link: https://codeforces.com/contest/1543/problem/0
import os, sys, math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
from math import ceil
mod = 10 ** 9 + 7
# number of test cases
for _ in range(int(input())):
a,b = map(int, input().split())
if a==b:
print(0,0)
else:
if a == b-1 or b == a-1:
print(1,0)
else:
aa = a
bb = b
if aa < bb:
bb = bb - aa
aa = 0
else:
aa = aa - bb
bb = 0
first_num = aa
second_num = bb
if first_num == 0: intial_gcd = second_num
else: intial_gcd = first_num
# for first number
if a%intial_gcd == 0 and b%intial_gcd == 0:
print(intial_gcd, 0)
else:
s = 0
e = pow(10, 18)
till = 0
while s <= e:
m = s + (e - s) // 2
if intial_gcd*m >= a:
e = m - 1
till = intial_gcd * m
else:
s = m + 1
m1 = abs(till - a)
s = 0
e = pow(10, 18)
till = 0
while s <= e:
m = s + (e - s) // 2
if m*intial_gcd <= a:
s = m + 1
till = intial_gcd * m
else: e = m - 1
print(intial_gcd, min(abs(till - a), m1))
``` | instruction | 0 | 5,278 | 17 | 10,556 |
Yes | output | 1 | 5,278 | 17 | 10,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
for _ in range(int(input())):
a,b=map(int,input().split())
if a==b:
print(0,0)
else:
print(abs(a-b),min(a%abs(a-b),(max(a,b)-b%abs(b-a))+abs(b-a)-max(a,b)))
``` | instruction | 0 | 5,279 | 17 | 10,558 |
Yes | output | 1 | 5,279 | 17 | 10,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
import sys
import math
def read_ints():
inp = input().split()
inp = [int(x) for x in inp]
return inp
def read_strings():
inp = input().split()
s = [inp[i] for i in range(len(inp))]
return s
t = int(input())
for _ in range(t):
ab = read_ints()
a = ab[0]
b = ab[1]
maxe = 0
minm = 0
if a == b:
maxe = 0
minm = 0
else:
maxe = abs(a-b)
minm = min(a % maxe, maxe - (a % maxe))
ans = str(maxe) + " " + str(minm)
print(ans)
``` | instruction | 0 | 5,280 | 17 | 10,560 |
Yes | output | 1 | 5,280 | 17 | 10,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
"""
from sys import stdin, stdout
import math
from functools import reduce
import statistics
import numpy as np
import itertools
import operator
from sys import stdin, stdout
import math
from functools import reduce
import statistics
import numpy as np
import itertools
import sys
import operator
from collections import Counter
import decimal
"""
import math
import os
import sys
from math import ceil, floor, sqrt, gcd, factorial
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def prog_name():
a, b = map(int, input().split())
moves = 0
if a == b:
print(0, 0)
else:
if abs(a - b) == 1:
print(1, 0)
else:
g = max(a - b, b - a)
ans = max(a, b) // g
moves = g * (ans + 1)
print(max(a - b, b - a), min(min(a, b), moves - max(a, b)))
def main():
# init = time()
T = int(input())
for unique in range(T):
# print("Case #"+str(unique+1)+":",end = " ")
prog_name()
# print(time() - init)
if __name__ == "__main__":
main()
``` | instruction | 0 | 5,281 | 17 | 10,562 |
No | output | 1 | 5,281 | 17 | 10,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
a,b = map(int,input().split())
if a == b:
sys.stdout.write(str(0)+" "+str(0)+"\n")
continue
# if abs(a-b) == 1:
# sys.stdout.write(str(1) + " " + str(0) + "\n")
# continue
# if (a%2 == 0 and b%2 == 1) or (a%2 == 1 and b%2 == 0):
# sys.stdout.write(str() + " " + str(0) + "\n")
# continue
ans = max(a,b)-min(a,b)
sys.stdout.write(str(ans) + " " + str(min(a,b)) + "\n")
``` | instruction | 0 | 5,282 | 17 | 10,564 |
No | output | 1 | 5,282 | 17 | 10,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
import sys
import math
#sys.stdin=open('input.txt','r')
#sys.stdout=open('output.txt','w')
def solve():
#n=int(input())
a,b=map(int,input().split())
if(a==b):
print("0 0")
else:
r=abs(a-b)
z=max(a,b)
if(math.gcd(a,b)==r):
print(r,0)
else:
e=z//r
y1=((e+1)*r)-a
y2=abs(((e)*r)-a)
print(abs(a-b),min(y1,y2))
t=int(input())
while(t!=0):
solve()
t-=1
``` | instruction | 0 | 5,283 | 17 | 10,566 |
No | output | 1 | 5,283 | 17 | 10,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Welcome to Rockport City!
It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is given by gcd(a,b), where gcd(x, y) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers x and y. To make the race more exciting, you can perform two types of operations:
1. Increase both a and b by 1.
2. Decrease both a and b by 1. This operation can only be performed if both a and b are greater than 0.
In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.
Note that gcd(x,0)=x for any x ≥ 0.
Input
The first line of input contains a single integer t (1≤ t≤ 5⋅ 10^3) — the number of test cases.
The first and the only line of each test case contains two integers a and b (0≤ a, b≤ 10^{18}).
Output
For each test case, print a single line containing two integers.
If the fans can get infinite excitement, print 0 0.
Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.
Example
Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3
Note
For the first test case, you can apply the first operation 1 time to get a=9 and b=6. It can be shown that 3 is the maximum excitement possible.
For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to 1. Since the initial excitement is also 1, you don't need to apply any operation.
For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.
For the fourth test case, you can apply the second operation 3 times to get a=0 and b=6. Since, gcd(0,6)=6, the fans will get an excitement of 6.
Submitted Solution:
```
# import math
t=int(input())
for i in range(t):
a,b=map(int,input().split())
d=min(a,b)
if a==b:
print("0 0")
elif a==0 or b==0:
print(max(a,b),1)
elif a==1 or b==1:
print("1 0")
else:
print(max(a,b)-d,(max(a,b)-d)//2)
``` | instruction | 0 | 5,284 | 17 | 10,568 |
No | output | 1 | 5,284 | 17 | 10,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,375 | 17 | 10,750 |
Tags: brute force, implementation, math
Correct Solution:
```
from sys import *
t=int(stdin.readline())
mm=0
for i in range(t):
n,k,d1,d2=(int(z) for z in stdin.readline().split())
mm=2*max(d1,d2)-min(d1,d2)
if (k-2*d1-d2>=0 and (k-2*d1-d2)%3==0 and n-2*d2-d1-k>=0 and (n-2*d2-d1-k)%3==0) or (k-2*d2-d1>=0 and (k-2*d2-d1)%3==0 and n-2*d1-d2-k>=0 and (n-2*d1-d2-k)%3==0) or (k-d1-d2>=0 and (k-d1-d2)%3==0 and n-mm-k>=0 and (n-mm-k)%3==0) or (k-mm>=0 and (k-mm)%3==0 and n-d1-d2-k>=0 and (n-d1-d2-k)%3==0):
print("yes")
else:
print("no")
``` | output | 1 | 5,375 | 17 | 10,751 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,376 | 17 | 10,752 |
Tags: brute force, implementation, math
Correct Solution:
```
from sys import stdin
def solve(n, k, d1, d2):
d = n - k
# a >= b and c >= b
c1 = (k - d1 + 2 * d2) // 3
a1 = d1 - d2 + c1
b1 = k - a1 - c1
# a >= b and c < b
c2 = (k - d1 - 2 * d2) // 3
a2 = d1 + d2 + c2
b2 = k - a2 - c2
# a < b and c < b
c3 = (k + d1 - 2 * d2) // 3
a3 = c3 + d2 - d1
b3 = k - a3 - c3
# a < b and c >= b
c4 = (k + d1 + 2 * d2) // 3
a4 = c4 - d1 - d2
b4 = k - a4 - c4
if c1 * 3 == 2 * d2 - d1 + k and a1 >= 0 and b1 >= 0 and c1 >= 0:
_max = max(a1, b1, c1)
diff = sum(_max - e for e in [a1, b1, c1])
if d >= diff and (d - diff) % 3 == 0:
return True
if c2 * 3 == k - d1 - 2 * d2 and a2 >= 0 and b2 >= 0 and c2 >= 0:
_max = max(a2, b2, c2)
diff = sum(_max - e for e in [a2, b2, c2])
if d >= diff and (d - diff) % 3 == 0:
return True
if c3 * 3 == k + d1 - 2 * d2 and a3 >= 0 and b3 >= 0 and c3 >= 0:
_max = max(a3, b3, c3)
diff = sum(_max - e for e in [a3, b3, c3])
if d >= diff and (d - diff) % 3 == 0:
return True
if c4 * 3 == k + d1 + 2 * d2 and a4 >= 0 and b4 >= 0 and c4 >= 0:
_max = max(a4, b4, c4)
diff = sum(_max - e for e in [a4, b4, c4])
if d >= diff and (d - diff) % 3 == 0:
return True
return False
def main():
test = stdin.readlines()
output = []
for i in range(1, int(test[0]) + 1):
ans = 'yes' if solve(*map(int, test[i].split())) else 'no'
output.append(ans)
print('\n'.join(output))
if __name__ == "__main__":
main()
``` | output | 1 | 5,376 | 17 | 10,753 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,377 | 17 | 10,754 |
Tags: brute force, implementation, math
Correct Solution:
```
input=__import__('sys').stdin.readline
for _ in range(int(input())):
n,k,d1,d2 = map(int,input().split())
lis=[[2*d1+d2 , 2*d2+d1] , [2*d2+d1 , 2*d1+d2] , [2*max(d1,d2)-min(d1,d2) , d1+d2] , [d1+d2 , 2*max(d1,d2) - min(d1,d2)]]
flag=1
for i in lis:
if i[0]<=k and i[0]%3==k%3 and n-k-i[1]>=0 and (n-k-i[1])%3==0:
print("yes")
flag=0
break
if flag:
print("no")
``` | output | 1 | 5,377 | 17 | 10,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,378 | 17 | 10,756 |
Tags: brute force, implementation, math
Correct Solution:
```
t=int(input())
for j in range(t):
inp=[int(n) for n in input().split()]
n=inp[0]
k=inp[1]
d1=inp[2]
d2=inp[3]
if d2<d1:
s=d1
d1=d2
d2=s
if ((k>=2*d1+d2) and ((k-2*d1-d2)%3==0) and (n-k>=d1+2*d2) and ((n-k-d1-2*d2)%3==0)):
print('yes')
elif ((k>=2*d2+d1) and ((k-2*d2-d1)%3==0) and (n-k>=d2+2*d1) and ((n-k-d2-2*d1)%3==0)):
print('yes')
elif ((k>=d1+d2) and ((k-d1-d2)%3==0) and (n-k>=2*d2-d1) and ((n-k-2*d2+d1)%3==0)):
print('yes')
elif ((k>=2*d2-d1) and ((k-2*d2+d1)%3==0) and (n-k>=d1+d2) and ((n-k-d1-d2)%3==0)):
print('yes')
else:
print('no')
``` | output | 1 | 5,378 | 17 | 10,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,379 | 17 | 10,758 |
Tags: brute force, implementation, math
Correct Solution:
```
from sys import *
t=int(stdin.readline())
mm,mmm,mmmm,m=0,0,0,0
for i in range(t):
n,k,d1,d2=(int(z) for z in stdin.readline().split())
m=d1+d2
mm=2*max(d1,d2)-min(d1,d2)
mmm=2*d1+d2
mmmm=2*d2+d1
if (k-mmm>=0 and (k-mmm)%3==0 and n-mmmm-k>=0 and (n-mmmm-k)%3==0) or (k-mmmm>=0 and (k-mmmm)%3==0 and n-mmm-k>=0 and (n-mmm-k)%3==0) or (k-m>=0 and (k-m)%3==0 and n-mm-k>=0 and (n-mm-k)%3==0) or (k-mm>=0 and (k-mm)%3==0 and n-m-k>=0 and (n-m-k)%3==0):
print("yes")
else:
print("no")
``` | output | 1 | 5,379 | 17 | 10,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,380 | 17 | 10,760 |
Tags: brute force, implementation, math
Correct Solution:
```
import sys
import operator
input = sys.stdin.readline
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
"""
n, k, d1, d2
d1 = abs(w1-w2)
d2 = abs(w2-w3)
w1+w2+w3=k
1) w1 >= w2 and w2 >= w3
d1 = w1-w2
d2 = w2-w3
d1-d2 = w1+w3-2*w2
d1-d2-k = -3*w2
w1 = d1-(d1-d2-k)/3
w2 = -(d1-d2-k)/3
w3 = -(d1-d2-k)/3-d2
n/3-w1 >= 0
n/3-w2 >= 0
n/3-w3 >= 0
"""
n, k, d1, d2 = read_ints()
if n%3 != 0:
return 'no'
# w1 >= w2 and w2 >= w3
def check(n, k, d1, d2, op1, op2):
if (d1-d2-k)%3 != 0:
return False
w1 = d1-(d1-d2-k)//3
w2 = -(d1-d2-k)//3
w3 = -(d1-d2-k)//3-d2
if w1 >= 0 and w2 >= 0 and w3 >= 0 and n//3-w1 >= 0 and n//3-w2 >= 0 and n//3-w3 >= 0 and op1(w1, w2) and op2(w2, w3):
return True
return False
if check(n, k, d1, d2, operator.ge, operator.ge):
return 'yes'
if check(n, k, d1, -d2, operator.ge, operator.lt):
return 'yes'
if check(n, k, -d1, d2, operator.lt, operator.ge):
return 'yes'
if check(n, k, -d1, -d2, operator.lt, operator.lt):
return 'yes'
return 'no'
if __name__ == '__main__':
T = read_int()
for _ in range(T):
print(solve())
``` | output | 1 | 5,380 | 17 | 10,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,381 | 17 | 10,762 |
Tags: brute force, implementation, math
Correct Solution:
```
t = int(input())
ret = []
while t>0:
t-=1
n,k,d1,d2 = map(int,input().split())
# ans = []
y1 = (k-(d1-d2))//3
x1 = y1+d1
z1 = y1-d2
# ans = [y1,z1,x1]
# ans = sorted(ans)
# ans1 = 2*ans[2]-(ans[0]+ans[1])
ans1 = 2*x1-(z1+y1)
if x1+y1+z1==k and min(z1,y1)>=0 and ans1<=n-k and (n-k-ans1)%3==0:
ret.append('yes')
continue
# ans = []
y1 = (k-(d1+d2))//3
x1 = y1+d1
z1 = y1+d2
if d1>=d2:
# ans = [y1,z1,x1]
ans1 = 2*x1-(y1+z1)
else:
# ans = [y1,x1,z1]
ans1 = 2*z1-(y1+x1)
# ans = sorted(ans)
# ans1 = 2*ans[2]-(ans[0]+ans[1])
if x1+y1+z1==k and y1>=0 and ans1<=n-k and (n-k-ans1)%3==0:
ret.append('yes')
continue
y1 = (k-(d2-d1))//3
x1 = y1-d1
z1 = y1+d2
# ans = [x1,y1,z1]
# ans = sorted(ans)
ans1 = 2*z1-(x1+y1)
if x1+y1+z1==k and min(x1,y1)>=0 and ans1<=n-k and (n-k-ans1)%3==0:
ret.append('yes')
continue
y1 = (k+(d2+d1))//3
x1 = y1-d1
z1 = y1-d2
# ans = [x1,y1,z1]
# ans = sorted(ans)
ans1 = 2*y1-(x1+z1)
if x1+y1+z1==k and min(x1,z1)>=0 and ans1<=n-k and (n-k-ans1)%3==0:
ret.append('yes')
continue
# if d1>=d2:
# ans.append(2*d1-d2)
# ans.append(d2+2*(d1-d2))
# else:
# ans.append(2*d2-d1)
# ans.append(d1+2*(d2-d1))
# ans+=[d1+2*d2,d2+2*d1,d1+d2]
# done = False
# print(ans)
# for a in ans:
# # if (a==0 and (n-k)%3==0) or (a!=0 and (n-k)//a>1 and (n-k)%a==0):
# if (a<=n-k) and (n-k-a)%3==0:
# print(a)
# done = True
# break
# if done:
# print('yes')
# else:
ret.append('no')
print(*ret, sep = '\n')
``` | output | 1 | 5,381 | 17 | 10,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins). | instruction | 0 | 5,382 | 17 | 10,764 |
Tags: brute force, implementation, math
Correct Solution:
```
def check(n, k, d1, d2):
if (k-d1-d2) % 3 != 0:
return False
y = (k-d1-d2) // 3
x = y+d1
z = y+d2
t = n // 3
if x < 0 or y < 0 or z < 0:
return False
if x > t or y > t or z > t:
return False
return True
t = int(input())
for _ in range(t):
n, k, d1, d2 = map(int, input().split())
if n % 3 != 0:
print ('no')
continue
if check(n, k, d1, d2):
print ('yes')
continue
if check(n, k, -d1, d2):
print ('yes')
continue
if check(n, k, d1, -d2):
print ('yes')
continue
if check(n, k, -d1, -d2):
print ('yes')
continue
print ('no')
``` | output | 1 | 5,382 | 17 | 10,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
def check(d1,d2):
wa=0
wb=0
wc=0
# wa-wb=d1
# wb-wc=d2
# wa-wc=d1+d2
# wa+wb+wc=k
wa=2*d1+d2+k
if(wa%3): return False
wa//=3
wb=wa-d1
wc=wb-d2
if(wa<0 or wb<0 or wc<0): return False
wa,wb,wc=sorted((wa,wb,wc))
need=2*wc-wa-wb
have=n-k-need
# print(need,have,'-->',wa,wb,wc)
return have>=0 and have%3==0
for _ in range(Int()):
n,k,d1,d2=value()
d3,d4=-d1,-d2
d1=[d1,d3]
d2=[d2,d4]
ok=False
for i in d1:
for j in d2:
ok|=check(i,j)
if(ok): print("yes")
else: print("no")
``` | instruction | 0 | 5,383 | 17 | 10,766 |
Yes | output | 1 | 5,383 | 17 | 10,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
def main():
t = int(input())
for z in range(t):
n, k, d1, d2 = map(int, input().split())
if n % 3 != 0:
print('no')
continue
f = 0
for i in [-1, +1]:
for j in [-1, +1]:
w = (k - i * d1 - j * d2)
if f == 0 and (w % 3 == 0) and (n//3)>=(w//3)>=0 and (n//3)>=(w//3 + i * d1)>=0 and (n//3)>=(w//3 + j * d2)>=0:
print('yes')
f = 1
if f == 0:
print('no')
main()
``` | instruction | 0 | 5,384 | 17 | 10,768 |
Yes | output | 1 | 5,384 | 17 | 10,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
t = int(input())
for i in range(t):
n, k, a, b = map(int, input().split())
if n % 3 != 0:
print("no")
else:
for i in range(2):
for j in range(2):
flagf = False
if i == 0:
a1 = a
else:
a1 = -a
if j == 0:
b1 = b
else:
b1 = -b
t2 = (k - a1 + b1)/3
t1 = a1 + t2
t3 = t2 - b1
# print(t1, t2, t3)
flag1 = False
flag2 = False
# valores válidos
if (k-a1+b1) % 3 == 0 and t1 >= 0 and t2 >= 0 and t3 >= 0:
if t1 <= n/3 and t2 <= n/3 and t3 <= n/3:
if i == 0 and t1 >= t2:
flag1 = True
elif i == 1 and t1 < t2:
flag1 = True
if j == 0 and t2 >= t3:
flag2 = True
elif j == 1 and t2 < t3:
flag2 = True
if flag1 and flag2:
if t1 == t2 and t2 == t3 and (n-k) % 3 == 0:
flagf = True
break
else:
v = [t1, t2, t3]
v = sorted(v)
faltam = n-k
faltam -= v[2] - v[1]
faltam -= v[2] - v[0]
if faltam < 0:
break
elif faltam == 0 or faltam %3 == 0:
flagf = True
break
if flagf:
print("yes")
break
else:
print("no")
# 3 1 1 0
``` | instruction | 0 | 5,385 | 17 | 10,770 |
Yes | output | 1 | 5,385 | 17 | 10,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
from sys import stdin
def solve(n, k, d1, d2):
if (d1 + 2 * d2 + k) % 3 != 0:
return False
c = (d1 + 2 * d2 + k) // 3
a = c - d1 - d2
b = k - a - c
if a >= 0 and b >= 0 and c >= 0 and a + b + c == k:
_max = max(a, b, c)
diff = sum(_max - e for e in [a, b, c])
d = n - k
if d >= diff and (d - diff) % 3 == 0:
return True
return False
def main():
test = stdin.readlines()
output = []
for i in range(1, int(test[0]) + 1):
n, k, d1, d2 = map(int, test[i].split())
for i, j in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
if solve(n, k, i * d1, j * d2):
output.append('yes')
break
else:
output.append('no')
print('\n'.join(output))
if __name__ == "__main__":
main()
``` | instruction | 0 | 5,386 | 17 | 10,772 |
Yes | output | 1 | 5,386 | 17 | 10,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
from sys import *
t=int(stdin.readline())
for i in range(t):
n,k,d1,d2=(int(z) for z in stdin.readline().split())
p1=n-(2*d1+d2+k)
p2=n-(2*d2+d1+k)
if (p1>=0 and not p1%3) or (p2>=0 and not p2%3):
print("yes")
else:
print("no")
``` | instruction | 0 | 5,387 | 17 | 10,774 |
No | output | 1 | 5,387 | 17 | 10,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
for t in range(int(input())):
n,k,d1,d2=map(int,input().split())
x=(k+(2*d1)+d2)//3
a,b,c=x,x-d1,x-d1-d2
n1=n//3
#print(x,a,b,c)
if n%3!=0 or (abs(n1-a)+abs(n1-b)+abs(n1-c))!=(n-k) or a+b+c!=k or a>n1 or b>n1 or c>n1 :
print('no')
else:
print('yes')
``` | instruction | 0 | 5,388 | 17 | 10,776 |
No | output | 1 | 5,388 | 17 | 10,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
a = []
z = int(input())
for i in range(z):
n, k, d1, d2 = map(int, input().split())
d1, d2 = sorted((d1, d2, ))
zn = n - k
v1 = 2 * d1 + d2
if v1 <= zn:
a.append('yes')
else:
a.append('no')
print(*a, sep = '\n')
``` | instruction | 0 | 5,389 | 17 | 10,778 |
No | output | 1 | 5,389 | 17 | 10,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played.
You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.
You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?
Note that outcome of a match can not be a draw, it has to be either win or loss.
Input
The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).
Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.
Output
For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).
Examples
Input
5
3 0 0 0
3 3 0 0
6 4 1 0
6 3 3 0
3 3 3 2
Output
yes
yes
yes
no
no
Note
Sample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.
Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".
Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).
Submitted Solution:
```
for _ in range(int(input())):
n,k,d1,d2 = map(int,input().split())
lis=[[2*d1+d2 , 2*d2+d1] , [2*d2+d1 , 2*d1+d2] , [2*max(d1,2)-min(d1,d2) , d1+d2] , [d1+d2 , 2*max(d1,d2) - min(d1,d2)]]
flag=1
for i in lis:
if i[0]<=k and (k-i[0])%3==0 and n-k-i[1]>=0 and (n-k-i[1])%3==0:
print("yes")
flag=0
break
if flag:
print("no")
``` | instruction | 0 | 5,390 | 17 | 10,780 |
No | output | 1 | 5,390 | 17 | 10,781 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,613 | 17 | 11,226 |
"Correct Solution:
```
n = int(input())
a = []
for i in range(1,n+1):
s, p = input().split()
a.append((s, -1*int(p), i))
a.sort()
for i in a:
print(i[2])
``` | output | 1 | 5,613 | 17 | 11,227 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,614 | 17 | 11,228 |
"Correct Solution:
```
n = int(input())
l =[]
for i in range(n):
s,p = input().split()
p = int(p)
l.append([s,-p,i+1])
l.sort()
for k in range(n):
print(l[k][2])
``` | output | 1 | 5,614 | 17 | 11,229 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,615 | 17 | 11,230 |
"Correct Solution:
```
n=int(input())
data=[tuple(input().split()+[i+1]) for i in range(n)]
data.sort(key=lambda tup:(tup[0],-int(tup[1])))
for i in data:
print(i[2])
``` | output | 1 | 5,615 | 17 | 11,231 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,616 | 17 | 11,232 |
"Correct Solution:
```
n = int(input())
l = []
for i in range(1,n+1):
s,p = input().split()
l.append((s,-int(p),i))
l.sort()
for x in l:
print(x[2])
``` | output | 1 | 5,616 | 17 | 11,233 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,617 | 17 | 11,234 |
"Correct Solution:
```
n = int(input())
r = []
for i in range(n):
c, s = input().split()
r.append((c, -int(s), i+1))
r = sorted(r)
for x in r:
print(x[2])
``` | output | 1 | 5,617 | 17 | 11,235 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,618 | 17 | 11,236 |
"Correct Solution:
```
for*_,a in sorted([input().split()+[i]for i in range(int(input()))],key=lambda x:(x[0],-int(x[1]))):print(a+1)
``` | output | 1 | 5,618 | 17 | 11,237 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,619 | 17 | 11,238 |
"Correct Solution:
```
n=int(input())
sp=[]
for i in range(n):
s,p=map(str,input().split())
sp.append([s,-int(p),i+1])
sp.sort()
for ans in sp:
print(ans[-1])
``` | output | 1 | 5,619 | 17 | 11,239 |
Provide a correct Python 3 solution for this coding contest problem.
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
* The restaurants are arranged in lexicographical order of the names of their cities.
* If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
* 1 ≤ N ≤ 100
* S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
* 0 ≤ P_i ≤ 100
* P_i is an integer.
* P_i ≠ P_j (1 ≤ i < j ≤ N)
Input
Input is given from Standard Input in the following format:
N
S_1 P_1
:
S_N P_N
Output
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
Examples
Input
6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
Output
3
4
6
1
5
2
Input
10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100
Output
10
9
8
7
6
5
4
3
2
1 | instruction | 0 | 5,620 | 17 | 11,240 |
"Correct Solution:
```
N = int(input())
SP = []
for i in range(N):
S,P = input().split()
P = int(P)
SP.append((S,-P,i+1))
SP.sort()
for a,b,c in SP:
print(c)
``` | output | 1 | 5,620 | 17 | 11,241 |
Provide a correct Python 3 solution for this coding contest problem.
Problem Statement
You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website.
There are $M$ links between the websites, and we can move between websites using these links. You can assume that it doesn't take time to move between websites. These links are directed and websites may have links to themselves.
In each website $i$, there is an advertisement and we can get $p_i$ point(s) by watching this advertisement in $t_i$ seconds. When we start on or move into a website, we can decide whether to watch the advertisement or not. But we cannot watch the same advertisement more than once before using any link in the website, while we can watch it again if we have moved among websites and returned to the website using one or more links, including ones connecting a website to itself. Also we cannot watch the advertisement in website $i$ more than $k_i$ times.
You want to win this contest by collecting as many points as you can. So you decided to compute the maximum points that you can collect within $T$ seconds.
Input
The input consists of multiple datasets. The number of dataset is no more than $60$.
Each dataset is formatted as follows.
> $N$ $M$ $T$
> $p_1$ $t_1$ $k_1$
> :
> :
> $p_N$ $t_N$ $k_N$
> $a_1$ $b_1$
> :
> :
> $a_M$ $b_M$
The first line of each dataset contains three integers $N$ ($1 \le N \le 100$), $M$ ($0 \le M \le 1{,}000$) and $T$ ($1 \le T \le 10{,}000$), which denote the number of websites, the number of links, and the time limit, respectively. All the time given in the input is expressed in seconds.
The following $N$ lines describe the information of advertisements. The $i$-th of them contains three integers $p_i$ ($1 \le p_i \le 10{,}000$), $t_i$ ($1 \le t_i \le 10{,}000$) and $k_i$ ($1 \le k_i \le 10{,}000$), which denote the points of the advertisement, the time required to watch the advertisement, and the maximum number of times you can watch the advertisement in website $i$, respectively.
The following $M$ lines describe the information of links. Each line contains two integers $a_i$ and $b_i$ ($1 \le a_i,b_i \le N$), which mean that we can move from website $a_i$ to website $b_i$ using a link.
The end of input is indicated by a line containing three zeros.
Output
For each dataset, output the maximum points that you can collect within $T$ seconds.
Sample Input
5 4 10
4 3 1
6 4 3
3 2 4
2 2 1
8 5 3
1 2
2 3
3 4
4 5
3 3 1000
1000 1 100
1 7 100
10 9 100
1 2
2 3
3 2
1 0 5
25 25 2
1 0 25
25 25 2
5 5 100
1 1 20
1 1 20
10 1 1
10 1 1
10 1 1
1 2
2 1
3 4
4 5
5 3
3 3 100
70 20 10
50 15 20
90 10 10
1 2
2 2
2 3
0 0 0
Output for the Sample Input
15
2014
0
25
40
390
Example
Input
5 4 10
4 3 1
6 4 3
3 2 4
2 2 1
8 5 3
1 2
2 3
3 4
4 5
3 3 1000
1000 1 100
1 7 100
10 9 100
1 2
2 3
3 2
1 0 5
25 25 2
1 0 25
25 25 2
5 5 100
1 1 20
1 1 20
10 1 1
10 1 1
10 1 1
1 2
2 1
3 4
4 5
5 3
3 3 100
70 20 10
50 15 20
90 10 10
1 2
2 2
2 3
0 0 0
Output
15
2014
0
25
40
390 | instruction | 0 | 5,777 | 17 | 11,554 |
"Correct Solution:
```
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def scc(N, G, RG):
order = []
used = [0]*N
group = [None]*N
def dfs(s):
used[s] = 1
for t in G[s]:
if not used[t]:
dfs(t)
order.append(s)
def rdfs(s, col):
group[s] = col
used[s] = 1
for t in RG[s]:
if not used[t]:
rdfs(t, col)
for i in range(N):
if not used[i]:
dfs(i)
used = [0]*N
label = 0
for s in reversed(order):
if not used[s]:
rdfs(s, label)
label += 1
return label, group
def construct(N, G, label, group):
G0 = [set() for i in range(label)]
RG0 = [set() for i in range(label)]
GP = [[] for i in range(label)]
for v in range(N):
lbs = group[v]
for w in G[v]:
lbt = group[w]
if lbs == lbt:
continue
G0[lbs].add(lbt)
RG0[lbt].add(lbs)
GP[lbs].append(v)
return G0, RG0, GP
def solve():
N, M, T = map(int, readline().split())
if N == M == T == 0:
return False
V = [0]*N; W = [0]*N; C = [0]*N
for i in range(N):
V[i], W[i], C[i] = map(int, readline().split())
G = [[] for i in range(N)]
RG = [[] for i in range(N)]
SL = [0]*N
for i in range(M):
a, b = map(int, readline().split())
if a == b:
SL[a-1] = 1
else:
G[a-1].append(b-1)
RG[b-1].append(a-1)
label, group = scc(N, G, RG)
G0, RG0, GP = construct(N, G, label, group)
INF = 10**18
dp = [None]*label
zeros = [0] + [-INF]*T
que = deque()
deg = [0]*label
for i in range(label):
if len(RG0[i]) == 0:
que.append(i)
dp[i] = zeros[:]
deg[i] = len(RG0[i])
ans = 0
dp1 = [0]*(T+1)
while que:
v = que.popleft()
dp0 = dp[v]
if len(GP[v]) == 1 and not SL[GP[v][0]]:
e, = GP[v]
ve = V[e]; we = W[e]
for i in range(T, we-1, -1):
dp0[i] = max(dp0[i], dp0[i-we] + ve)
else:
deq = deque()
push = deq.append
popl = deq.popleft
pop = deq.pop
clear = deq.clear
for e in GP[v]:
ve = V[e]; we = W[e]; ce = C[e]
if T < we:
continue
if ce == 1:
for i in range(T, we-1, -1):
dp0[i] = max(dp0[i], dp0[i-we] + ve)
elif T <= we*ce:
for i in range(we, T+1):
dp0[i] = max(dp0[i], dp0[i-we] + ve)
else:
for k in range(we):
for i in range((T - k) // we + 1):
v0 = dp0[k] - i*ve
while deq and deq[-1][1] <= v0:
pop()
push((i, v0))
dp0[k] = deq[0][1] + i*ve
if deq[0][0] == i-ce:
popl()
k += we
clear()
ans = max(ans, max(dp0))
for w in G0[v]:
deg[w] -= 1
if deg[w] == 0:
que.append(w)
if dp[w] is None:
dp[w] = dp0[:]
else:
dp[w][:] = (max(p, q) for p, q in zip(dp[w], dp0))
write("%d\n" % ans)
return True
while solve():
...
``` | output | 1 | 5,777 | 17 | 11,555 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,509 | 17 | 13,018 |
"Correct Solution:
```
while 1:
M = int(input())
if M == 0:
break
S = []
for i in range(M):
t, *score = map(int, input().split())
frame = rd = cum = 0
L = len(score)
res = sum(score)
for i in range(L):
s = score[i]
if rd == 0:
cum = s
if s == 10:
res += score[i+1] + score[i+2]
frame += 1
else:
rd = 1
else:
cum += s
if cum == 10:
res += score[i+1]
frame += 1
rd = 0
if frame == 9:
break
S.append((-res, t))
S.sort()
for x, y in S:
print(y, -x)
``` | output | 1 | 6,509 | 17 | 13,019 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,510 | 17 | 13,020 |
"Correct Solution:
```
while 1:
m = int(input())
if m == 0:
break
result = []
for _ in range(m):
datas = list(map(int, input().split()))
student = datas.pop(0)
score = 0
frame = 1
while 1:
if frame == 10:
while datas != []:
score += datas.pop(0)
break
first = datas.pop(0)
if first == 10:
score += 10 + datas[0] + datas[1]
else:
second = datas.pop(0)
if first + second == 10:
score += 10 + datas[0]
else:
score += first + second
frame += 1
result.append([student, score])
result.sort()
result = sorted(result, reverse=True, key=lambda x: x[1])
for res in result:
print(res[0], res[1])
``` | output | 1 | 6,510 | 17 | 13,021 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,511 | 17 | 13,022 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0: break
num = []
for i in range(n):
score = list(map(int, input().split()))
score.extend([0,0,0])
cnt = 0
flag = 0
flame = 1
for j in range(len(score[1:])):
cnt+=score[j+1]
if flame >= 10:
pass
elif score[j+1] == 10 and flag == 0:
cnt+=score[j+2]+score[j+3]
flame+=1
elif score[j+1]+score[j]==10 and flag == 1:
cnt+=score[j+2]
flag = 0
flame+=1
elif flag == 1:
flag = 0
flame+=1
elif flag == 0:
flag = 1
num.append([score[0], cnt])
for i in sorted(num, key = lambda x: (-x[1], x[0])):
print(*i)
``` | output | 1 | 6,511 | 17 | 13,023 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,512 | 17 | 13,024 |
"Correct Solution:
```
def get_point(info):
info.reverse()
acc = 0
NORMAL, SPARE, STRIKE, DOUBLE = 0, 1, 2, 3
flag = NORMAL
game_num = 0
while info:
if game_num != 9:
down_num1 = info.pop()
if down_num1 != 10:
down_num2 = info.pop()
if flag == SPARE:
acc += down_num1 * 2 + down_num2
elif flag == STRIKE:
acc += down_num1 * 2 + down_num2 * 2
elif flag == DOUBLE:
acc += down_num1 * 3 + down_num2 * 2
else:
acc += down_num1 + down_num2
if down_num1 + down_num2 == 10:
flag = SPARE
else:
flag = NORMAL
else:
if flag in (SPARE, STRIKE):
acc += down_num1 * 2
elif flag == DOUBLE:
acc += down_num1 * 3
else:
acc += down_num1
if flag in (STRIKE, DOUBLE):
flag = DOUBLE
else:
flag = STRIKE
game_num += 1
else:
down_num1, down_num2 = info.pop(), info.pop()
if flag == SPARE:
acc += down_num1 * 2 + down_num2
elif flag == STRIKE:
acc += down_num1 * 2 + down_num2 * 2
elif flag == DOUBLE:
acc += down_num1 * 3 + down_num2 * 2
else:
acc += down_num1 + down_num2
if info:
acc += info.pop()
return acc
while True:
m = int(input())
if m == 0:
break
score = [list(map(int, input().split())) for _ in range(m)]
score_mp = [(info[0], get_point(info[1:])) for info in score]
score_mp.sort()
score_mp.sort(key=lambda x:-x[1])
for pair in score_mp:
print(*pair)
``` | output | 1 | 6,512 | 17 | 13,025 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,513 | 17 | 13,026 |
"Correct Solution:
```
FIRST = 1
SECOND = 2
while True:
score_count = int(input())
if score_count == 0:
break
score_list = []
for _ in range(score_count):
total_score = 0
score_data = [int(item) for item in input().split(" ")]
last_score = 0
frame_count = 1
ball_state = FIRST
for index, score in enumerate(score_data[1:], 1):
if frame_count == 10:
total_score += sum(score_data[index:])
break
if last_score + score == 10:
if ball_state == FIRST:
# ストライク
total_score += score + score_data[index + 1] + score_data[index + 2]
else:
# スペア
total_score += score + score_data[index + 1]
ball_state = FIRST
last_score = 0
frame_count += 1
else:
# 通常
total_score += score
if ball_state == FIRST:
ball_state = SECOND
last_score = score
else:
ball_state = FIRST
last_score = 0
frame_count += 1
score_list.append([score_data[0], total_score])
score_list.sort(key=lambda x: (-x[1], x[0]))
output = [str(id) + " " + str(score) for id, score in score_list]
print("\n".join(output))
``` | output | 1 | 6,513 | 17 | 13,027 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,514 | 17 | 13,028 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0152
"""
import sys
from sys import stdin
input = stdin.readline
def bowling_score(data):
name_id = data[0]
data = data[1:]
frame = 1
scores = [0] * 11
while frame <= 10:
if data[0] == 10:
scores[frame] = data[0] + data[1] + data[2]
data = data[1:]
frame += 1
elif data[0] + data[1] == 10:
scores[frame] = data[0] + data[1] + data[2]
data = data[2:]
frame += 1
else:
scores[frame] = data[0] + data[1]
data = data[2:]
frame += 1
return name_id, sum(scores[1:])
def main(args):
while True:
m = int(input())
if m == 0:
break
results = []
for _ in range(m):
data = [int(x) for x in input().split()]
name_id, score = bowling_score(data)
results.append([-score, name_id])
results.sort()
for s, i in results:
print(i, -s)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 6,514 | 17 | 13,029 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,515 | 17 | 13,030 |
"Correct Solution:
```
# coding: utf-8
# Your code here!
class Player:
id = 0
score = 0
def __init__(self, id, score):
self.id = id
self.score = score
def __lt__(self, other):
if self.score == other.score:
return self.id < other.id
else:
return self.score > other.score
while True:
N = int(input())
if N == 0:
break
players = []
for l in range(N):
line = [int(i) for i in input().split()]
line.append(0)
line.append(0)
score = 0
round = 0
i = 1
while round < 10:
if round < 9:
if line[i] < 10:
if line[i] + line[i+1] < 10:
score += line[i] + line[i+1]
else:
score += line[i] + line[i+1] + line[i+2]
i += 2
round += 1
else:
score += line[i] + line[i+1] + line[i+2]
i += 1
round += 1
else:
score += line[i] + line[i+1] + line[i+2]
round += 1
players.append(Player(line[0], score))
players.sort()
for i in range(N):
print(players[i].id, players[i].score)
``` | output | 1 | 6,515 | 17 | 13,031 |
Provide a correct Python 3 solution for this coding contest problem.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122 | instruction | 0 | 6,516 | 17 | 13,032 |
"Correct Solution:
```
def score(x):
s=0;t=1
for _ in[0]*10:
a=2;b=3
if x[t]==10:a=1
elif x[t]+x[t+1]!=10:b=2
s+=sum(x[t:t+b]);t+=a
return x[0],s
while 1:
n=int(input())
if n==0:break
A=sorted([score(list(map(int,input().split()))) for _ in [0]*n])
for a,b in sorted(A,key=lambda x:-x[1]):print(a,b)
``` | output | 1 | 6,516 | 17 | 13,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122
Submitted Solution:
```
# from sys import exit
while(True):
N = int(input())
if N == 0:
exit()
score = [[] for _ in range(N)]
ids = [0 for _ in range(N)]
for i in range(N):
score[i] = [int(n) for n in input().split()]
ids[i] = score[i][0]
cnt = 0 # フレームのための
frame = 0 # 10フレームの処理
sum = 0
ans = 0
# ストライクなら二回分、スペアなら一回分
double = 0
triple = 0
for s in score[i][1:]:
if triple and frame != 10:
ans += 3*s
# if i == 1:print(3*s, frame)
triple -= 1
double -= 1
elif double and frame != 10:
ans += 2*s
# if i == 1:print(2*s, frame)
double -= 1
else:
# if i == 1:print(s, frame)
ans += s
sum += s
cnt += 1
# ストライク
if cnt == 1 and s == 10:
cnt = 0
sum = 0
if double:
triple += 1
double = 2
else:
double += 2
frame+=1
# スペア
elif cnt == 2 and sum == 10:
if double:
triple += 1
else:
double += 1
# フレームのリセット
if (cnt == 2):
# print("AAA" + str(sum), cnt)
cnt = 0
sum = 0
frame+=1
score[i] = (ids[i], ans)
score = sorted(score, key=lambda x: x[0])
score = sorted(score, key=lambda x: -x[1])
for s in score:
print(s[0], s[1])
``` | instruction | 0 | 6,517 | 17 | 13,034 |
No | output | 1 | 6,517 | 17 | 13,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122
Submitted Solution:
```
# AOJ 0152 Bowling
# Python3 2018.6.21 bal4u
while True:
n = int(input())
if n == 0: break
tbl = {}
for _ in range(n):
p = list(map(int, input().split()))
id = int(p.pop(0))
sum = 0
for f in range(10-1):
if p[0] == 10:
sum += p[0]+p[1]+p[2]
else:
sum += p[0]+p[1]
if p[0]+p[1] == 10: sum += p[2]
p.pop(0)
p.pop(0)
sum += p[0]+p[1]
if p[0] == 10 or p[0]+p[1] == 10: sum += p[2] #10番フレーム
tbl[id] = sum
for i in sorted(tbl.items(), key=lambda x:(x[1],-x[0]), reverse=True): print(*i)
``` | instruction | 0 | 6,518 | 17 | 13,036 |
No | output | 1 | 6,518 | 17 | 13,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122
Submitted Solution:
```
# from sys import exit
while(True):
N = int(input())
if N == 0:
exit()
score = [[] for _ in range(N)]
ids = [0 for _ in range(N)]
for i in range(N):
score[i] = [int(n) for n in input().split()]
ids[i] = score[i][0]
cnt = 0 # フレームのための
frame = 0 # 10フレームの処理
sum = 0
ans = 0
# ストライクなら二回分、スペアなら一回分
double = 0
triple = 0
for s in score[i][1:]:
if triple and frame != 10:
ans += 3*s
# if i == 1:print(3*s, frame)
triple -= 1
double -= 1
elif double and frame != 10:
ans += 2*s
# if i == 1:print(2*s, frame)
double -= 1
else:
# if i == 1:print(s, frame)
ans += s
sum += s
cnt += 1
# ストライク
if cnt == 1 and s == 10:
cnt = 0
sum = 0
if double:
triple += 1
double = 2
else:
double += 2
frame+=1
# スペア
elif cnt == 2 and sum == 10:
if double:
triple += 1
else:
double += 1
# フレームのリセット
if (cnt == 2):
# print("AAA" + str(sum), cnt)
cnt = 0
sum = 0
frame+=1
score[i] = (ids[i], ans)
score = sorted(score, key=lambda x: x[0])
score = sorted(score, key=lambda x: -x[1])
n = len(score)
for s in score:
if n:
print(s[0], s[1], end=" \n")
else:
print(s[0], s[1])
``` | instruction | 0 | 6,519 | 17 | 13,038 |
No | output | 1 | 6,519 | 17 | 13,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I decided to do bowling as a recreation of the class. Create a program that inputs the pitching information for each participant and outputs the grade information in descending order of score. If there is a tie, output in ascending order of student ID number. However, it is assumed that the number of participants is 3 or more and 40 or less, and one game is thrown per person.
Bowling is a sport in which the player rolls the ball toward 10 pins arranged in an equilateral triangle with the vertices facing the player and knocks down the pins. The case where all the players fall in the first pitch is called a strike, and only that pitch advances to the next frame. If it is not a strike, leave the remaining pins and make a second pitch. A spare is when all the pitches have fallen on the second pitch. After the second pitch, proceed to the next frame.
One game consists of 10 frames, and each of the 1st to 9th frames can be pitched twice. At the beginning of each frame, all 10 pins are upright. In the 10th frame, if there is a strike or a spare, a total of 3 pitches will be thrown, otherwise 2 pitches will be made and the game will end.
Score example 1
<image>
Score example 2 (when the maximum score is 300 points)
<image>
How to calculate the score
* If there are no spares or strikes in each frame, the number of pins defeated in two pitches will be the score for that frame. (4th and 8th frames of score example 1)
* If you give a spare, in addition to the number of defeated 10 points, the number of defeated pins in the next pitch will be added to the score of this frame. (Relationship between the 1st frame and the 2nd frame of the score example 1) In the 1st frame of the score example 1, 20 points including 10 points (points) defeated by 1 throw of the 2nd frame will be scored. The calculation method is the same for the third frame.
* If you strike, the number of pins you defeated in the next two pitches will be added to the number of defeated 10 points. (Relationship between the 2nd frame and the 3rd frame of score example 1) Of course, there may be a strike during the following 2 throws. (Relationship between the 5th frame and the 6th and 7th frames of score example 1)
* If you give a spare or strike only in the 10th frame, the total number of pins you have thrown and defeated will be added as the score in the 10th frame.
* The total score of each frame is the score of one game, and the maximum score is 300 points.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
m
score1
score2
::
scorem
The number of participants m (3 ≤ m ≤ 40) is given in the first line, and the i-th participant information scorei is given in the following m lines. Each participant information is given in the following format, one line at a time.
id s1 s2 ... sn
The student ID number id (0 ≤ id ≤ 9999) is given first, followed by the number of fall pins of the jth throw sj (0 ≤ sj ≤ 10). It is assumed that the total number of pitches n is 12 or more and 21 or less, and the number of pins required for score calculation is given in just proportion.
Output
For each input dataset, the student ID number and score are output in descending order of score (if there is a tie, the student ID number is in ascending order). Please separate your student ID number and score with one space and output them on one line.
Example
Input
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
Output
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122
Submitted Solution:
```
# AOJ 0152 Bowling
# Python3 2018.6.20 bal4u
while True:
n = int(input())
if n == 0: break
tbl = {}
for _ in range(n):
p = list(map(int, input().split()))
id = p[0]
del p[0]
sum = k = 0
for f in range(9):
s = p[k]
if s == 10:
sum += 10+p[k+1]+p[k+2]
k += 1
else:
s += p[k+1]
sum += s
k += 2
if s == 10: sum += p[k]
sum += p[k] + p[k+1]
if p[k] == 10 or p[k]+p[k+1] == 10: sum += p[k+2]
tbl[id] = sum
ans = sorted(tbl.items(), key=lambda x:(x[1],-x[0]), reverse=True)
for i in ans: print(*i)
``` | instruction | 0 | 6,520 | 17 | 13,040 |
No | output | 1 | 6,520 | 17 | 13,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team.
Output
Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie.
Examples
Input
[]()[]8<
8<[]()8<
Output
TEAM 2 WINS
Input
8<8<()
[]8<[]
Output
TIE | instruction | 0 | 6,993 | 17 | 13,986 |
Tags: *special
Correct Solution:
```
s1 = input()
s2 = input()
n = len(s1)
bal = 0
for i in range(0, n, 2):
if s1[i] == '8' and s2[i] == '[':
bal += 1
if s1[i] == '8' and s2[i] == '(':
bal -= 1
if s1[i] == '(' and s2[i] == '[':
bal -= 1
if s1[i] == '(' and s2[i] == '8':
bal += 1
if s1[i] == '[' and s2[i] == '(':
bal += 1
if s1[i] == '[' and s2[i] == '8':
bal -= 1
if bal == 0:
print('TIE')
elif bal > 0:
print('TEAM 1 WINS')
else:
print('TEAM 2 WINS')
``` | output | 1 | 6,993 | 17 | 13,987 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.