message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0 | instruction | 0 | 55,564 | 9 | 111,128 |
"Correct Solution:
```
n,a=int(input()),0
while n:
n>>=1
a+=1
print(a)
``` | output | 1 | 55,564 | 9 | 111,129 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0 | instruction | 0 | 55,565 | 9 | 111,130 |
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
cnt = 0
if n == 0:
print(0)
exit()
while 2**cnt < n :
cnt += 1
if 2**cnt == n:
cnt += 1
print(cnt)
``` | output | 1 | 55,565 | 9 | 111,131 |
Provide a correct Python 3 solution for this coding contest problem.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0 | instruction | 0 | 55,566 | 9 | 111,132 |
"Correct Solution:
```
n = int(input())
print(0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0))
``` | output | 1 | 55,566 | 9 | 111,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0
Submitted Solution:
```
n = int(input())
print(1 if n == 0 else len(str(bin(n))[2:]))
``` | instruction | 0 | 55,567 | 9 | 111,134 |
No | output | 1 | 55,567 | 9 | 111,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0
Submitted Solution:
```
n = int(input())
print(1 if n == 0 else len(str(bin(n))[2:]), "\n")
``` | instruction | 0 | 55,568 | 9 | 111,136 |
No | output | 1 | 55,568 | 9 | 111,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0
Submitted Solution:
```
n = int(input())
print(0 if n == 0 else len(str(bin(n))[2:]), "\n")
``` | instruction | 0 | 55,569 | 9 | 111,138 |
No | output | 1 | 55,569 | 9 | 111,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem statement
Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.
input
n
Constraint
* An integer
* 0 ≤ n ≤ 1018
output
Print the answer on one line, and print a newline at the end.
sample
Sample input 1
0
Sample output 1
0
Sample input 2
Four
Sample output 2
3
Sample input 3
31
Sample output 3
Five
Sample input 4
36028797018963968
Sample output 4
56
Example
Input
0
Output
0
Submitted Solution:
```
n = int(input())
print(len(str(bin(n))[2:]))
``` | instruction | 0 | 55,570 | 9 | 111,140 |
No | output | 1 | 55,570 | 9 | 111,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | instruction | 0 | 57,250 | 9 | 114,500 |
Tags: brute force, greedy, math
Correct Solution:
```
t = int(input())
for i in range(0,t):
a,b,c = map(int,input().split())
count = 0
if b == 0:
print(0)
if b == 1:
if c>=2:
print(3)
else:
print(0)
if b>=2 :
if c==0 or c==1:
if a==0:
print(0)
if a>=1:
p=b//2
count+=p
print(min(count,a)*3)
if c>=2:
p=c//2
count+=min(p,b)
b=b-p
if a==0:
print(count*3)
if a>=1:
if b>0:
q=b//2
count = count + min(q,a)
print(count*3)
else:
print(count*3)
``` | output | 1 | 57,250 | 9 | 114,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | instruction | 0 | 57,251 | 9 | 114,502 |
Tags: brute force, greedy, math
Correct Solution:
```
t=int(input())
while t:
a,b,c=map(int,input().split())
ans=3*min(b,c//2)
b-=min(b,c//2)
c-=2*min(b,c//2)
ans+=3*min(a,b//2)
print(ans)
t-=1
``` | output | 1 | 57,251 | 9 | 114,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | instruction | 0 | 57,253 | 9 | 114,506 |
Tags: brute force, greedy, math
Correct Solution:
```
for _ in range(int(input())):
a,b,c=map(int,input().split())
z1=c//2
if b<z1:
z1=b
z2=(b-z1)//2
if z2>a:
z2=a
print((z1+z2)*3)
``` | output | 1 | 57,253 | 9 | 114,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | instruction | 0 | 57,254 | 9 | 114,508 |
Tags: brute force, greedy, math
Correct Solution:
```
n = int(input())
for k in range(n):
a,b,c = [int(i) for i in input().split()]
ans = 0
if b == 0:
print(0)
else:
if b-c//2 >= 0:
ans += c//2 + 2*(c//2)
b -= c//2
else:
ans += b + 2*b
print(ans)
continue
if a-b//2 >= 0:
ans += b//2 + 2*(b//2)
else:
ans += a + 2*a
print(ans)
``` | output | 1 | 57,254 | 9 | 114,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 ≤ a,b,c ≤ 100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | instruction | 0 | 57,256 | 9 | 114,512 |
Tags: brute force, greedy, math
Correct Solution:
```
# !/usr/bin/env python3
# encoding: UTF-8
# Last Modified: 17/Oct/2019 07:07:55 PM
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT), Gwalior
import sys
import os
from io import IOBase, BytesIO
def main():
for tc in range(int(input())):
a, b, c = get_ints()
ans = 0
while b > 0 and c > 1:
ans += 3
b -= 1
c -= 2
while a > 0 and b > 1:
ans += 3
a -= 1
b -= 2
print(ans)
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill():
pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill()
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
py2 = round(0.5)
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2 == 1:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
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)
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().strip()
if __name__ == "__main__":
main()
``` | output | 1 | 57,256 | 9 | 114,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,476 | 9 | 114,952 |
Tags: brute force, implementation
Correct Solution:
```
def present(lst):
if lst.count(100) % 2 == 1 or lst.count(200) % 2 == 1 and lst.count(100) == 0:
return "NO"
return "YES"
n = int(input())
a = [int(i) for i in input().split()]
print(present(a))
``` | output | 1 | 57,476 | 9 | 114,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,477 | 9 | 114,954 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
M = sorted(map(lambda x: int(x) // 100, input().split()))
if sum(M) & 1:
print("NO")
else:
goal = sum(M) // 2
if goal & 1:
if M[0] == 1:
print("YES")
else:
print("NO")
else:
print("YES")
``` | output | 1 | 57,477 | 9 | 114,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,478 | 9 | 114,956 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
v=[int(i) for i in input().split()]
one,two=0,0
for i in v:
if(i==100):
one=one+1
else:
two=two+1
if(two%2!=0):
if(one>1 and one%2==0):
print("YES")
else:
print("NO")
else:
if(one%2==0):
print("YES")
else:
print("NO")
``` | output | 1 | 57,478 | 9 | 114,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,479 | 9 | 114,958 |
Tags: brute force, implementation
Correct Solution:
```
import math
def cmp(a):
return a[1]*10000+a[0]
n = int(input())
array = list(map(int, input().split(' ')))
two = 0
one = 0
for i in range(n):
if array[i]==100:
one+=1;
else:
two+=1;
sone = one
stwo = two
for i in range(two):
if one>1:
one-=2
two-=1
if one%2 == 0 and two %2==0:
print("YES")
exit(0)
one = sone
two = stwo
one = one%2
two = two%2
if one == 0 and two == 0:
print("YES")
else:
print("NO")
``` | output | 1 | 57,479 | 9 | 114,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,480 | 9 | 114,960 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
x = list(map(int, input().split()))
if n == 1:
print('NO')
else:
if ((sum(x) // 2) // 10) % 10 != 0 or (n % 2 != 0 and len(set(x)) == 1):
print('NO')
else:
print('YES')
``` | output | 1 | 57,480 | 9 | 114,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,481 | 9 | 114,962 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
nums = [int(x)//100 for x in input().split()]
if sum(nums)%2 == 1 or (min(nums)==2 and sum(nums)%4!=0):
print("NO")
else:
print("YES")
``` | output | 1 | 57,481 | 9 | 114,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,482 | 9 | 114,964 |
Tags: brute force, implementation
Correct Solution:
```
'''
Created on Nov 6, 2014
@author: GersonSales
'''
n_maca = int(input())
peso_maca = list(map(int, input().split()))
quant_1 = peso_maca.count(100)
quant_2 = peso_maca.count(200)
if n_maca>=1:
print("YES" if quant_1%2 == 0 and (quant_2%2 == 0 or quant_1 > 0) else "NO")
else:
print ("NO")
``` | output | 1 | 57,482 | 9 | 114,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | instruction | 0 | 57,483 | 9 | 114,966 |
Tags: brute force, implementation
Correct Solution:
```
def equal_apples (apples):
two_g = 0
one_g = 0
for x in apples :
if x == '200' :
two_g += 1
else:
one_g += 1
if two_g%2 == 0 :
if one_g%2 == 0:
return "YES"
else:
return "NO"
else:
if one_g < 2 :
return "NO"
else:
one_g -= 2
if one_g %2 == 0:
return "YES"
else:
return "NO"
n = int(input())
apples = input().split()
print (equal_apples(apples))
``` | output | 1 | 57,483 | 9 | 114,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
n=int(input())
s=list(map(int,input().split()))
a=sum(s)
s.count(100)
s.count(200)
if (a//2)%100==0:
if s.count(100)%2==0 and s.count(200)%2==0:
print('YES')
exit()
if s.count(100)>1 and s.count(200)%2==1:
print('YES')
exit()
print('NO')
``` | instruction | 0 | 57,484 | 9 | 114,968 |
Yes | output | 1 | 57,484 | 9 | 114,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
if len(set(a))==1 and a[0] == 200 and len(a)%2==1:
print('NO')
exit()
if n == 1:
print('NO')
exit()
k = sum(a)
if k//2%100 == 50:
print('NO')
else:
print('YES')
``` | instruction | 0 | 57,485 | 9 | 114,970 |
Yes | output | 1 | 57,485 | 9 | 114,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
n = int( input() )
w = list( map( int, input().split() ) )
w1, w2 = 0, 0
w.sort( reverse = True )
for num in w:
if ( w1 <= w2 ):
w1 += num
else:
w2 += num
print ( "YES" ) if ( w1 == w2 ) else print ( "NO" )
``` | instruction | 0 | 57,486 | 9 | 114,972 |
Yes | output | 1 | 57,486 | 9 | 114,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
def main():
n = int(input())
a = 0
b = 0
nums = list(map(int, input().split(' ')))
s = 0
for num in nums:
if num == 100:
a += 1
else:
b += 1
s += num
if s % 200 != 0:
return False
half = s // 2
for i in range(0, b + 1):
if 200 * i <= half and half - 200 * i <= a * 100:
return True
return False
print("YES") if main() else print("NO")
``` | instruction | 0 | 57,487 | 9 | 114,974 |
Yes | output | 1 | 57,487 | 9 | 114,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
n=int(input())
w=list(map(int,input().split()))
if 100 not in w:
if w.count(200)%2!=0:
print("NO")
exit()
elif 200 not in w:
if w.count(100)%2!=0:
print("NO")
exit()
else:
a=w.count(100)
b=w.count(200)
if a%b!=0:
print("NO")
exit()
print("YES")
``` | instruction | 0 | 57,488 | 9 | 114,976 |
No | output | 1 | 57,488 | 9 | 114,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
from collections import Counter
n = int(input())
#n,m = map(int,input().split())
l = list(map(int,input().split()))
#k = int(input())
t = sum(l)//100
if t%2 ==0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 57,489 | 9 | 114,978 |
No | output | 1 | 57,489 | 9 | 114,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
# A. Kitahara Haruki's Gift
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=0
i=0
if (sum(a)//100)%2!=0:
print("NO")
else:
while c<(sum(a)//2) and i<n:
c+=a[i]
i+=1
if c==sum(a)//2 and sum(a)//2==(sum(a)-c):
print("YES")
else:
print("NO")
``` | instruction | 0 | 57,490 | 9 | 114,980 |
No | output | 1 | 57,490 | 9 | 114,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
Submitted Solution:
```
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
import math
n=ii()
a=li()
s=0
for i in a:
if i==100:
s+=1
else:
s+=2
if s%2 or n==1:
print("NO")
else:
print("YES")
``` | instruction | 0 | 57,491 | 9 | 114,982 |
No | output | 1 | 57,491 | 9 | 114,983 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,800 | 9 | 115,600 |
"Correct Solution:
```
n = int(input())
a, b, c = [list(map(int, input().split())) for _ in range(3)]
ans = sum(b)
last = -1
for x in a:
if last+1 == x:
ans += c[last-1]
last = x
print(ans)
``` | output | 1 | 57,800 | 9 | 115,601 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,801 | 9 | 115,602 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
print(sum(b + [c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1]))
``` | output | 1 | 57,801 | 9 | 115,603 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,802 | 9 | 115,604 |
"Correct Solution:
```
n=int(input())
ans=0
l=[list(map(int,input().split())) for i in range(3)]
for i in range(1,n+1):
ans+=l[1][l[0][i-1]-1]
if i!=n and l[0][i]==l[0][i-1]+1:
ans+=l[2][l[0][i-1]-1]
print(ans)
``` | output | 1 | 57,802 | 9 | 115,605 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,803 | 9 | 115,606 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
x=sum(B)
for i in range(len(A)-1):
if A[i+1]==A[i]+1:
x+=C[A[i]-1]
print(x)
``` | output | 1 | 57,803 | 9 | 115,607 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,804 | 9 | 115,608 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
n=sum(list(map(int,input().split())))
C=list(map(int,input().split()))
C.append(0)
for i in range(N-1):
if A[i+1]==A[i]+1:
n+=C[A[i]-1]
print(n)
``` | output | 1 | 57,804 | 9 | 115,609 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,805 | 9 | 115,610 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=sum(b)
for i in range(n-1):
if a[i]+1==a[i+1]:
d+=c[a[i]-1]
print(d)
``` | output | 1 | 57,805 | 9 | 115,611 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,806 | 9 | 115,612 |
"Correct Solution:
```
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
ans=sum(B)
for i in range(n-1):
if A[i]+1==A[i+1]:
ans+=C[A[i]-1]
print(ans)
``` | output | 1 | 57,806 | 9 | 115,613 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150 | instruction | 0 | 57,807 | 9 | 115,614 |
"Correct Solution:
```
N = int(input())
A = input().split()
B = input().split()
C = input().split()
s = 0
k = int(A[0])
for i in range(N):
n = int(A[i])
s += int(B[n-1])
if k+1 == n:
s += int(C[n-2])
k = n
print(s)
``` | output | 1 | 57,807 | 9 | 115,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=B[0]
for i in range(1,n):
s+=B[i]
if A[i-1]==A[i]-1:
s+=C[A[i-1]-1]
print(s)
``` | instruction | 0 | 57,808 | 9 | 115,616 |
Yes | output | 1 | 57,808 | 9 | 115,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
n = int(input())
abc = []
for i in range(3):
abc += [[int(i) for i in input().split()]]
ps = sum(abc[1])
for i in range(n-1):
if abc[0][i]+1 == abc[0][i+1]:
ps += abc[2][abc[0][i]-1]
print(ps)
``` | instruction | 0 | 57,809 | 9 | 115,618 |
Yes | output | 1 | 57,809 | 9 | 115,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
R = lambda:list(map(int,input().split()))
input()
a, b, c = R(), R(), R()
print(sum(b) + sum(c[i - 1] for i, j in zip(a, a[1:]) if j == i + 1))
``` | instruction | 0 | 57,810 | 9 | 115,620 |
Yes | output | 1 | 57,810 | 9 | 115,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
sm = sum(b)
for n in range(1,N):
if a[n] - a[n-1] == 1:
sm += c[a[n]-2]
print(sm)
``` | instruction | 0 | 57,811 | 9 | 115,622 |
Yes | output | 1 | 57,811 | 9 | 115,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
n = int(input())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
lc = list(map(int,input().split()))
con = 0
for i in range(len(la)-1):
if la[(i+1)%3]==la[i]+1:
con += lc[la[i]-1]
print(sum(lb)+con)
``` | instruction | 0 | 57,812 | 9 | 115,624 |
No | output | 1 | 57,812 | 9 | 115,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C.append(0)
ans = sum(B)+sum(C)-C[A[-1]-1]
print(ans)
``` | instruction | 0 | 57,813 | 9 | 115,626 |
No | output | 1 | 57,813 | 9 | 115,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
n=int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m=0
# 0で初期化すると最初が1の時にだめ
at=0
for i,ai in enumerate(a):
m+=b[ai-1]
if ai == at+1:
m+=c[at-1]
at=ai
print(m)
``` | instruction | 0 | 57,814 | 9 | 115,628 |
No | output | 1 | 57,814 | 9 | 115,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
Find the sum of the satisfaction points he gained.
Constraints
* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}
Output
Print the sum of the satisfaction points Takahashi gained, as an integer.
Examples
Input
3
3 1 2
2 5 4
3 6
Output
14
Input
4
2 3 4 1
13 5 8 24
45 9 15
Output
74
Input
2
1 2
50 50
50
Output
150
Submitted Solution:
```
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
r = 0
a = 0
for i in range(N):
r += B[A[i]-1]
if A[i]-1 > len(C):
continue
elif A[i] == a+1 :
r += C[a-1]
a = A[i]
print(r)
``` | instruction | 0 | 57,815 | 9 | 115,630 |
No | output | 1 | 57,815 | 9 | 115,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime and his n friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n-1 players except himself. The game stops when one person will have all the biscuits.
As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.
For convenience, as the answer can be represented as a rational number p/q for coprime p and q, you need to find the value of (p ⋅ q^{-1})mod 998 244 353. You can prove that qmod 998 244 353 ≠ 0.
Input
The first line contains one integer n\ (2≤ n≤ 100 000): the number of people playing the game.
The second line contains n non-negative integers a_1,a_2,...,a_n\ (1≤ a_1+a_2+...+a_n≤ 300 000), where a_i represents the number of biscuits the i-th person own at the beginning.
Output
Print one integer: the expected value of the time that the game will last, modulo 998 244 353.
Examples
Input
2
1 1
Output
1
Input
2
1 2
Output
3
Input
5
0 0 0 0 35
Output
0
Input
5
8 4 2 0 1
Output
801604029
Note
For the first example, in the first second, the probability that player 1 will give the player 2 a biscuit is 1/2, and the probability that player 2 will give the player 1 a biscuit is 1/2. But anyway, the game will stop after exactly 1 second because only one player will occupy all biscuits after 1 second, so the answer is 1. | instruction | 0 | 58,182 | 9 | 116,364 |
Tags: math, probabilities
Correct Solution:
```
import os
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
# list(map(int, input().split()))
#####################################################################################
class CF(object):
def __init__(self):
self.mod = 998244353
self.n = int(input())
self.a = list(map(int, input().split()))
self.tot = sum(self.a)
self.dp = [[0,0] for _ in range(self.tot+1)]
def inv(self, x):
return pow(x, self.mod - 2, self.mod)
def gao(self):
self.dp[0] = [0,1]
self.dp[1] = [(1-self.n+self.mod)%self.mod, 1]
for k in range(1, self.tot):
temp = self.inv(self.tot-k)
self.dp[k+1][0] = -self.tot*(self.n - 1) - self.dp[k][0] * (2*k - self.tot- k*self.n) - self.dp[k-1][0] *k*(self.n-1)
self.dp[k+1][0] *= temp
self.dp[k+1][0] = (self.dp[k+1][0] %self.mod+self.mod)%self.mod
self.dp[k+1][1] = -self.dp[k][1]*(2*k - self.tot- k*self.n) - self.dp[k-1][1]*k*(self.n-1)
self.dp[k+1][1] *= temp
self.dp[k+1][1] = (self.dp[k+1][1] %self.mod+self.mod)%self.mod
alpha = -self.dp[self.tot][0]*self.inv(self.dp[self.tot][1])
alpha = (alpha%self.mod + self.mod)%self.mod
#print(alpha)
ans=0
for i in range(self.n):
ans += self.dp[self.a[i]][0] + self.dp[self.a[i]][1] * alpha
ans = (ans%self.mod+self.mod)%self.mod
ans -= alpha * (self.n - 1)
ans = (ans%self.mod+self.mod)%self.mod
ans *= self.inv(self.n)
ans = (ans%self.mod+self.mod)%self.mod
print(ans)
def main(self):
self.gao()
pass
if __name__ == "__main__":
cf = CF()
cf.main()
pass
'''
dp[k+1] *(tot-k) = -tot*(n-1) - dp[k]*(2*k - tot- k*n ) - dp[k-1] *k*(n-1)
'''
``` | output | 1 | 58,182 | 9 | 116,365 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime and his n friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n-1 players except himself. The game stops when one person will have all the biscuits.
As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.
For convenience, as the answer can be represented as a rational number p/q for coprime p and q, you need to find the value of (p ⋅ q^{-1})mod 998 244 353. You can prove that qmod 998 244 353 ≠ 0.
Input
The first line contains one integer n\ (2≤ n≤ 100 000): the number of people playing the game.
The second line contains n non-negative integers a_1,a_2,...,a_n\ (1≤ a_1+a_2+...+a_n≤ 300 000), where a_i represents the number of biscuits the i-th person own at the beginning.
Output
Print one integer: the expected value of the time that the game will last, modulo 998 244 353.
Examples
Input
2
1 1
Output
1
Input
2
1 2
Output
3
Input
5
0 0 0 0 35
Output
0
Input
5
8 4 2 0 1
Output
801604029
Note
For the first example, in the first second, the probability that player 1 will give the player 2 a biscuit is 1/2, and the probability that player 2 will give the player 1 a biscuit is 1/2. But anyway, the game will stop after exactly 1 second because only one player will occupy all biscuits after 1 second, so the answer is 1. | instruction | 0 | 58,183 | 9 | 116,366 |
Tags: math, probabilities
Correct Solution:
```
import sys
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
class mint:
def __init__(self, x):
self.__x = x % md
def __repr__(self):
return str(self.__x)
def __neg__(self):
return mint(-self.__x)
def __add__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x + other)
def __sub__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x - other)
def __rsub__(self, other):
return mint(other - self.__x)
def __mul__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * other)
__radd__ = __add__
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * pow(other, md - 2, md))
def __rtruediv__(self, other):
return mint(other * pow(self.__x, md - 2, md))
def __pow__(self, power, modulo=None):
return mint(pow(self.__x, power, md))
md = 998244353
def main():
n=II()
aa=LI()
sa=sum(aa)
# dp[i]...ev from i-1 to i
dp=[mint(0)]*(sa+1)
for i in range(1,sa+1):
dp[i]=((i-1)*dp[i-1]+sa)*(n-1)/(sa+1-i)
#print(*dp)
for i in range(sa):dp[i+1]+=dp[i]
ans=-(n-1)*dp[-1]
for a in aa:ans+=dp[sa]-dp[a]
print(ans/n)
main()
``` | output | 1 | 58,183 | 9 | 116,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Slime and his n friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the i-th player has a_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a_1 + a_2 + … + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n-1 players except himself. The game stops when one person will have all the biscuits.
As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.
For convenience, as the answer can be represented as a rational number p/q for coprime p and q, you need to find the value of (p ⋅ q^{-1})mod 998 244 353. You can prove that qmod 998 244 353 ≠ 0.
Input
The first line contains one integer n\ (2≤ n≤ 100 000): the number of people playing the game.
The second line contains n non-negative integers a_1,a_2,...,a_n\ (1≤ a_1+a_2+...+a_n≤ 300 000), where a_i represents the number of biscuits the i-th person own at the beginning.
Output
Print one integer: the expected value of the time that the game will last, modulo 998 244 353.
Examples
Input
2
1 1
Output
1
Input
2
1 2
Output
3
Input
5
0 0 0 0 35
Output
0
Input
5
8 4 2 0 1
Output
801604029
Note
For the first example, in the first second, the probability that player 1 will give the player 2 a biscuit is 1/2, and the probability that player 2 will give the player 1 a biscuit is 1/2. But anyway, the game will stop after exactly 1 second because only one player will occupy all biscuits after 1 second, so the answer is 1. | instruction | 0 | 58,184 | 9 | 116,368 |
Tags: math, probabilities
Correct Solution:
```
MOD = 998244353
n = int(input())
a = list(map(int, input().split()))
tot = sum(a)
def inv(x):
return pow(x, MOD - 2, MOD)
l = [0, pow(n, tot, MOD) - 1]
for i in range(1, tot):
aC = i
cC = (n - 1) * (tot - i)
curr = (aC + cC) * l[-1]
curr -= tot * (n - 1)
curr -= aC * l[-2]
curr *= inv(cC)
curr %= MOD
l.append(curr)
out = 0
for v in a:
out += l[tot - v]
out %= MOD
zero = l[tot]
out -= (n - 1) * zero
out *= inv(n)
print(out % MOD)
``` | output | 1 | 58,184 | 9 | 116,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.
A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.
Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.
He continue to go to supermaket and try to get the discounted box lunch for n days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
Constraints
* 1 ≤ n ≤ 100,000
Input
Input consists of several datasets.
Input for a single dataset is given as a single integer n.
Input terminates with a dataset where n = 0.
Output
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
Example
Input
1
2
3
0
Output
1.00000000
1.50000000
2.12500000
Submitted Solution:
```
# -*- coding: utf-8 -*-
days = []
day = int(input())
while day != 0:
days.append(day)
day = int(input())
max_day = max(days)
probs = [1.0] + [0.0 for _ in range(1,max_day)]
for i in range(1,max_day):
probs[i] = 1 - probs[i-1] + probs[i-1]*probs[i-1]/2
for day in days:
print(str(sum(probs[:day])))
``` | instruction | 0 | 58,797 | 9 | 117,594 |
No | output | 1 | 58,797 | 9 | 117,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.
A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.
Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.
He continue to go to supermaket and try to get the discounted box lunch for n days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
Constraints
* 1 ≤ n ≤ 100,000
Input
Input consists of several datasets.
Input for a single dataset is given as a single integer n.
Input terminates with a dataset where n = 0.
Output
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
Example
Input
1
2
3
0
Output
1.00000000
1.50000000
2.12500000
Submitted Solution:
```
code="""
#include <bits/stdc++.h>
using namespace std;
#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
print_tuple<Cdr...>(os,t);
os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
print_tuple<Args...>(os<<'(',t);
return os<<')';
}
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
os<<'[';
for(auto i=begin(c);i!=end(c);++i)
os<<(i==begin(c)?"":" ")<<*i;
return os<<']';
}
constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
int main()
{
for(int n;cin>>n && n;){
map<pii,double> dp;
dp[mp(0,0)]=1;
rep(_,n){
map<pii,double> dp2;
for(auto p:dp){
if(p.second<1e-6) continue;
int cnt,cur; tie(cnt,cur)=p.first;
dp2[mp(cnt+1,cur+1)]+=p.second*1./(1<<cur);
dp2[mp(cnt,0)]+=p.second*(1-1./(1<<cur));
}
swap(dp,dp2);
}
double res=0;
for(auto p:dp)
res+=p.first.first*p.second;
printf("%.8f",res); puts("");
}
}
"""
import os,tempfile
(_,filename)=tempfile.mkstemp(".cpp")
f=open(filename,"w")
f.write(code)
f.close()
os.system("g++ -std=c++11 {} -o ./a.out".format(filename))
os.system("./a.out")
``` | instruction | 0 | 58,798 | 9 | 117,596 |
No | output | 1 | 58,798 | 9 | 117,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.
A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.
Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.
He continue to go to supermaket and try to get the discounted box lunch for n days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
Constraints
* 1 ≤ n ≤ 100,000
Input
Input consists of several datasets.
Input for a single dataset is given as a single integer n.
Input terminates with a dataset where n = 0.
Output
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
Example
Input
1
2
3
0
Output
1.00000000
1.50000000
2.12500000
Submitted Solution:
```
dp=[.0]*100001
dp[1]=1.
for i in range(2,100001):
a,b,j=.5,1,1
while j<i and b> 1e-5:
dp[i]+=b*(1-a)*(j+dp[i-j-1])
b*=a;a/=2;j+=1
dp[i]+=i*b
while 1:
n=int(input())
if n==0:break
print(dp[n])
``` | instruction | 0 | 58,799 | 9 | 117,598 |
No | output | 1 | 58,799 | 9 | 117,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.