message stringlengths 2 59.7k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
from math import *
n=int(input())
count=0
for i in range(1,int(n/2)+1):
a=(i*(i+1))/2
b=str(a)
if b[-1]=='0':
x=n-int(a)
if x<0:
break
square_root=sqrt(8*x+1)
square_root1=str(square_root)
if square_root1[-1]=='0':
c=(square_root-1)/2
if c==0.0:
continue
else:
c=str(c)
if c[-1]=='0':
print('YES')
count=1
break
if count==0:
print('NO')
``` | instruction | 0 | 55,874 | 20 | 111,748 |
Yes | output | 1 | 55,874 | 20 | 111,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter
from math import *
from itertools import permutations
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
#for tt in range(INT()):
n = INT()
d = set()
for i in range(1, 100009):
j = (i*(i+1))//2
d.add(j)
f = 0
for i in d :
z = n - i
if z in d :
f = 1
#print(i , z)
break
if f :
print('YES')
else:
print('NO')
``` | instruction | 0 | 55,875 | 20 | 111,750 |
Yes | output | 1 | 55,875 | 20 | 111,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
from math import sqrt
n=int(input())
status="NO"
a=sqrt(n)
i,j=int(a),int(a)
while i>=1 and j<=n:
sum=(i*(i+1)/2)+(j*(j+1)/2)
if sum==n:
status="YES"
break
if sum>n:
i=i-1
if sum<n:
j=j+1
print(status)
``` | instruction | 0 | 55,876 | 20 | 111,752 |
Yes | output | 1 | 55,876 | 20 | 111,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
n=int(input())
a=[]
b=[]
i=int(0)
f=0
while(1):
a.append(int((i*(i+1))/2))
if(a[len(a)-1]>=n):
break
i=i+1
for i in range(len(a)):
b.append(n-a[i])
b.sort()
print("YES") if(set(a) & set(b)) else print("NO")
``` | instruction | 0 | 55,877 | 20 | 111,754 |
No | output | 1 | 55,877 | 20 | 111,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
n = int(input())
k = 1
done = False
if n < 1000:
limit = n
elif n in range(1000, 10000):
limit = 75
elif n in range(10000, 100000):
limit = 225
elif n in range(100000, 1000000):
limit = 725
elif n in range(1000000, 10000000):
limit = 2250
elif n in range(10000000, 100000000):
limit = 7250
else:
limit = 14000
while(k <= limit):
x = k * (k + 1)
for i in range(k, n):
y = i * (i + 1)
if (x + y) // 2 == n:
print("YES")
exit()
elif (x + y) // 2 > n:
break;
k += 1
if n == 999999999:
print("YES")
else:
print("NO")
``` | instruction | 0 | 55,878 | 20 | 111,756 |
No | output | 1 | 55,878 | 20 | 111,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
n=int(input())
l=[]
s=int ((2*n)**.5)
for i in range(0,s):
p=(i*(i+1))//2
l.append(p)
k=len(l)-1
i=1
found=0
while(k>i):
if (l[i]+l[k]==n):
found=1
break
elif(l[i]+l[k]<n):
i+=1
elif(l[i]+l[k]>n):
k=k-1
if (found==1):
print("YES")
else:
print("NO")
``` | instruction | 0 | 55,879 | 20 | 111,758 |
No | output | 1 | 55,879 | 20 | 111,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as <image>, where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input
The first input line contains an integer n (1 ≤ n ≤ 109).
Output
Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Examples
Input
256
Output
YES
Input
512
Output
NO
Note
In the first sample number <image>.
In the second sample number 512 can not be represented as a sum of two triangular numbers.
Submitted Solution:
```
import math
n=int(input())
def funky(n):
l=[]
x=int(math.sqrt(n))
for i in range(1,x+1):
l.append((i*(i+1))//2)
for i in l:
for j in l:
if i+j==n:
return 'YES'
return 'NO'
print(funky(n))
``` | instruction | 0 | 55,880 | 20 | 111,760 |
No | output | 1 | 55,880 | 20 | 111,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,071 | 20 | 112,142 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
a,b,c,d=map(int,input().split())
m=min(a,c,d)
print((256*m)+(32*min(a-m,b)))
``` | output | 1 | 56,071 | 20 | 112,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,072 | 20 | 112,144 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
def main():
x = list(map(int,input().split()))
ans =0
y = min(x[0],x[2],x[3])
ans += 256*y
x[0] -=y
x[2]-=y
x[3] -=y
ans+= 32*min(x[0],x[1])
print(ans)
main()
``` | output | 1 | 56,072 | 20 | 112,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,073 | 20 | 112,146 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
a,b,c,d=map(int,input().split())
p=min(a,c,d)
a-=p
q=min(a,b)
print(256*p+32*q)
``` | output | 1 | 56,073 | 20 | 112,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,074 | 20 | 112,148 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
import sys
k2,k3,k5,k6 = map(int,sys.stdin.readline().split())
a = min(k2,k5,k6)
b = min(k2-a,k3)
print(a*256 + b*32)
``` | output | 1 | 56,074 | 20 | 112,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,075 | 20 | 112,150 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
from typing import Iterator
def get_num_input() -> Iterator[int]:
return map(int, input().split())
def main() -> None:
twos: int
threes: int
fives: int
sixes: int
twos, threes, fives, sixes = get_num_input()
count: int = min(twos, fives, sixes)
print(256 * count + 32 * min(twos - count, threes))
if __name__ == "__main__":
ONLY_ONCE: bool = True
for _ in range(1 if ONLY_ONCE else int(input())):
main()
``` | output | 1 | 56,075 | 20 | 112,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,076 | 20 | 112,152 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/23 10:30
"""
k2, k3, k5, k6 = map(int, input().split())
k256 = min(k2, k5, k6)
k32 = max(0, min(k3, k2-k256))
print(k32*32 + k256*256)
``` | output | 1 | 56,076 | 20 | 112,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,077 | 20 | 112,154 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
l=list(map(int,input().split()))[:4]
g=l[1]
l.remove(g)
k=min(l)
j=l[0]-k
if j>=g:
sum=(((g)*32)+(k*256))
print(sum)
else:
sum=((j)*32)+(k*256)
print(sum)
``` | output | 1 | 56,077 | 20 | 112,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256. | instruction | 0 | 56,078 | 20 | 112,156 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
k2, k3, k5, k6 = map(int,input().split());s = min(k2,k5,k6);z = min(k3,k2 - min(k2,k5,k6));print(s*256+z*32)
``` | output | 1 | 56,078 | 20 | 112,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
# import sys
# sys.stdin=open('input.in','r')
# sys.stdout=open('output.out','w')
l=list(map(int,input().strip().split()[:4]))
k2=l[0]
k3=l[1]
k5=l[2]
k6=l[3]
z=min(k2,k5,k6)
l=min(k2-z,k3)
print((z*256)+(l*32))
``` | instruction | 0 | 56,079 | 20 | 112,158 |
Yes | output | 1 | 56,079 | 20 | 112,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
a, b, c, d = map(int, input().split())
tfs = min(a, c, d)
foo = tfs * 256
a -= tfs
foo += min(a, b) * 32
print(foo)
``` | instruction | 0 | 56,080 | 20 | 112,160 |
Yes | output | 1 | 56,080 | 20 | 112,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
l=list(map(int,input().split()))
sum=0
k=min(l[0],l[2],l[3])
sum+=256*(k)
l[0]-=k;l[2]-=k;l[3]-=k
sum+=32*(min(l[0],l[1]))
print(sum)
``` | instruction | 0 | 56,081 | 20 | 112,162 |
Yes | output | 1 | 56,081 | 20 | 112,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
k2,k3,k5,k6=map(int,input().split(" "))
a=min(k2,k5,k6)
k2=k2-a
b=min(k2,k3)
print(256*a+32*b)
``` | instruction | 0 | 56,082 | 20 | 112,164 |
Yes | output | 1 | 56,082 | 20 | 112,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
m=500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
h=500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
x=input().split()
a=[]
for i in range(len(x)):
if i==1 :
d=x[i]
else:
a.append(x[i])
for i in range(len(a)):
if m > int(a[i]):
m=int(a[i])
a.remove(str(m))
for i in range(len(a)):
a[i]=int(a[i])-m
a.append(d)
for i in range(len(a)):
if h>int(a[i]) :
h=int(a[i])
print((m*256)+(h*32))
``` | instruction | 0 | 56,083 | 20 | 112,166 |
No | output | 1 | 56,083 | 20 | 112,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
s=list(map(int,input().split()))
ans=0
mx=999999999
f='2356'
while 1:
mn=mx
for i in s:
if i!=0:mn=min(mn,i)
if mn==mx:break
cc=''
for i in range(4):
if s[i]:cc+=f[i];s[i]-=mn
ans+=int(cc)*mn
print(ans)
``` | instruction | 0 | 56,084 | 20 | 112,168 |
No | output | 1 | 56,084 | 20 | 112,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
# n=int(input())
# if(n%2==0):
# print("YES")
# else:
# print("NO")
# for _ in range(int(input())):
# n=(input())
# if(len(n)<=10):
# print(n)
# else:
# print(n[0]+str(len(n)-2)+n[len(n)-1])
# a=0
# for _ in range(int(input())):
# n=list(map(int,input().split()))
# count=0
# for i in range(len(n)):
# if(n[i]==1):
# count+=1
# else:
# count-=1
# if(count>0):
# a+=1
# print(a)
# n,m=map(int,input().split())
# a=list(map(int,input().split()))
# count=0
# for i in range(len(a)):
# if(a[i]>=a[m-1] and a[i]>0):
# count+=1
# print(count)
# n,m=map(int,input().split())
# # if((n*m)%2!=0):
# print((n*m)//2)
# # else:
# # print((n*m)//2)\
# x=0
# for _ in range(int(input())):
# n=input()
# if(n=="X++" or n=="++X"):
# x=x+1
# else:
# x=x-1
# print(x)
# n = input()
# m = input()
# n = n.lower()
# m = m.lower()
# if n == m:
# print("0")
# elif n > m:
# print('1')
# elif n <m:
# print('-1')
# matrix=[]
# min=[]
# one_line=0
# one_column=0
# for l in range(0,5):
# m=input().split()
# for col,ele in enumerate()
# a = list(map(int,input().split('+')))
# a.sort()
# print('+'.join([str(c) for c in a]))
# n=list(input())
# # if(n[0].islower()):
# n[0]=n[0].upper()
# else:
# pass
# print("".join(str(x)for x in n))
# n=list(input())
# s=input()
# count=0
# for i in range(1,len(s)):
# if(s[i]==s[i-1]):
# count+=1
# print(count)
# v=["A","O","Y","E","U","I","a","i","e","o","u","y"]
# n=list(input())
# x=[]
# for i in range(len(n)):
# if n[i] not in v:
# x.append(n[i])
# print("."+".".join(str(y.lower())for y in x))
# a=[]
# b=[]
# c=[]
# for _ in range(int(input())):
# x,y,z=map(int,input().split())
# a.append(x)
# b.append(y)
# c.append(z)
# print("YES" if sum(a)==sum(b)==sum(c)== 0 else "NO")
# m = "hello"
# n=input()
# j=0
# flag=0
# for i in range(len(n)):
# if(n[i]==m[j]):
# j=j+1
# if(j==5):
# flag=1
# break
# if(flag==1):
# print("YES")
# else:
# print("NO")
# a=set(list(input()))
# print("CHAT WITH HER!" if len(set(list(input())))%2==0 else "IGNORE HIM!")
# k,n,w=map(int,input().split())
# sum=0
# a=[]
# for i in range(w+1):
# sum+=k*i
# print((sum-n) if sum>n else 0)
# m,n = 0,0
# for i in range(5):
# a = map(int,input().split())
# for j in range(5):
# if a[j]!=0:
# m = i
# n = j
# break
# print(abs(m-2)+abs(n-2))
# l,b=map(int,input().split())
# c=0
# while(l<=b):
# l=l*3
# b=b*2
# c=c+1
# print(c)
# from math import ceil
# n,m,a=map(int,input().split())
# # print(ceil(n/a),ceil(m/a))
# c=ceil(n/a)*ceil(m/a)
# print(c)
# n=int(input())
# if(n%4==0 or n%7==0 or n%44==0 or n%47==0 or n%74==0 or n%444==0 or n%447==0 or n%474==0 or n%477==0):
# print("YES")
# else:
# print("NO")
# def tramCapacity():
# n = int(input().strip())
# pout, pin = map(int, input().strip().split())
# sm = pin
# mx = pin
# for i in range(n-1):
# pout, pin = map(int, input().strip().split())
# sm = sm - pout + pin
# if sm > mx:
# mx = sm
# return mx
# print(tramCapacity())
# n,k=map(int,input().split())
# for i in range(k):
# if(str(n)[-1]=="0"):
# n=n//10
# else:
# n=n-1
# print(n)
# n=int(input())
# n=int(input())
# if(n%5==0):
# print(n//5)
# else:
# print((n//5)+1)
# n=int(input())
# if(n%2==0):
# print(n//2)
# else:
# print("-"+str(n-((n-1)//2)))
# n=int(input())
# arr=list(map(int,input().split()))
# sum=sum(arr)
# deno=len(arr)*100
# print(format(((sum/deno)*100),'.12f'))
# k=int(input())
# l=int(input())
# m=int(input())
# n=int(input())
# d=int(input())
# count=0
# # if(d%k==0):
# # print(d)
# # elif(d%l==0):
# # print(d//l)
# # elif(d%m==0):
# # print(d//m)
# # elif(d%n==0):
# # print(d//n)
# # else:
# for i in range(1,d+1):
# if(i%k==0 or i%l==0 or i%m==0 or i%n==0):
# count+=1
# print(count)
# a,b=map(int,input().split())
# # if(n%m==0):
# # print(0)
# # else:
# # for i in range(m):
# # n=n+i
# # if(n%m==0):
# # print(i-1)
# # break
# # else:
# # continue
# x=((a+b)-1)/b
# print((b*x)-1)
# for _ in range(int(input())):
# a, b = map(int,input().split(" "))
# x=(a + b - 1) // b
# # print(x)
# print((b * x) - a)
# for _ in range(int(input())):
# n=int(input())
# print((n-1)//2)
# n=int(input())
# # n = int(input())
# if n%2 == 0:
# print(8, n-8)
# else:
# print(9, n-9)
# n=int(input())
# a=[]
# for i in range(len(n)):
# x=int(n)-int(n)%(10**i)
# a.append(x)
# print(a)
# # b=max(a)
# print(a[-1])
# for i in range(len(a)):
# a[i]=a[i]-a[-1]
# print(a)
# for _ in range(int(input())):
# n=int(input())
# p=1
# rl=[]
# x=[]
# while(n>0):
# dig=n%10
# r=dig*p
# rl.append(r)
# p*=10
# n=n//10
# for i in rl:
# if i !=0:
# x.append(i)
# print(len(x))
# print(" ".join(str(x)for x in x))
# n,m=map(int,input().split())
# print(str(min(n,m))+" "+str((max(n,m)-min(n,m))//2))
# arr=sorted(list(map(int,input().split())))
# s=max(arr)
# ac=arr[0]
# ab=arr[1]
# bc=arr[2]
# a=s-bc
# b=ab-a
# c=bc-b
# print(a,b,c)
# x=0
# q,t=map(int,input().split())
# for i in range(1,q+1):
# x=x+5*i
# if(x>240-t):
# print(i-1)
# break
# if(x<=240-t):
# print(q)
# # print(q)
# print(z)
# print(x)
# l=(240-t)-x
# print(l)
# if(((240-t)-x)>=0):
# print(q)
# else:
# print(q-1)
# n, L = map(int, input().split())
# arr = [int(x) for x in input().split()]
# arr.sort()
# x = arr[0] - 0
# y = L - arr[-1]
# r = max(x, y) * 2
# for i in range(1, n):
# r = max(r, arr[i] - arr[i-1])
# print(format(r/2,'.12f'))
# n,m=map(int,input().split())
# print(((m-n)*2)-1)
# for _ in range(int(input())):
# n=int(input())
# x=360/(180-n)
# # print(x)
# if(n==60 or n==90 or n==120 or n==108 or n==128.57 or n==135 or n==140 or n==144 or n==162 or n==180):
# print("YES")
# elif(x==round(x)):
# print("YES")
# else:
# print("NO")
# n,m=map(int,input().split())
# if(n<2 and m==10):
# print(-1)
# else:
# x=10**(n-1)
# print(x+(m-(x%m)))
# for _ in range(int(input())):
# n,k=map(int,input().split())
# a=list(map(int,input().split()))
# a.sort()
# c=0
# for i in range(1,n):
# c = (k-a[i])//a[0]
# # print(c)
# for _ in range(int(input())):
# x,y=map(int,input().split())
# a,b=map(int,input().split())
# q=a*(x+y)
# p=b*(min(x,y))+a*(abs(x-y))
# print(min(p,q))
# n,k=map(int,input().split())
# a=n//2+n%2
# print(a)
# if(k<=a):
# print(2*k-1)
# else:
# print(2*(k-a))
# a,b=map(int,input().split())
# count=0
# if(a>=b):
# print(a-b)
# else:
# while(b>a):
# if(b%2==0):
# b=int(b/2)
# count+=1
# else:
# b+=1
# count+=1
# print(count+(a-b))
# n=int(input())
# while n>5:
# n = n - 4
# n=(n-((n-4)%2))/2
# # print(n)
# if n==1:
# print('Sheldon')
# if n==2:
# print('Leonard')
# if n==3:
# print('Penny')
# if n==4:
# print('Rajesh')
# if n==5:
# print('Howard')
# n, m = (int(x) for x in input().split())
# if(n<m):
# print(-1)
# else:
# print((int((n-0.5)/(2*m))+1)*m)
# for _ in range(int(input())):
# n,k=map(int,input().split())
# print(k//n)
# print(k%n)
# if((k+(k//n))%n==0):
# print(k+(k//n)+1)
# else:
# print(k+(k//n))
# for i in range(int(input())):
# n,k=map(int,input().split())
# print((k-1)//(n-1) +k)
# for _ in range(int(input())):
# n,k = map(int,input().split())
# if (n >= k*k and n % 2 == k % 2):
# print("YES")
# else:
# print("NO")
# for _ in range(int(input())):
# n,x=map(int,input().split())
# a=list(map(int,input().split()))
# arr=[]
# # s=sum([i%2 for i in a])
# for i in a:
# j=i%2
# arr.append(j)
# s=sum(arr)
# # print(s)
# if s==0 or (n==x and s%2==0) or (s==n and x%2==0):
# print("No")
# else:
# print("Yes")
# a=int(input())
# print(a*(a*a+5)//6)
# n,m=map(int,input().split())
# a=[]
# k='YES'
# for i in range(m):
# a.append(list(map(int,input().split())))
# a.sort()
# for i in a:
# if i[0]<n:
# n=n+i[1]
# else:
# k='NO'
# break
# print(k)
# a=input()
# if('1'*7 in a or '0'*7 in a):
# print("YES")
# else:
# print("NO")
# s=int(input())
# for i in range(s):
# n=int(input())
# if (n//2)%2==1:
# print('NO')
# else:
# print('YES')
# for j in range(n//2):
# print(2*(j+1))
# for j in range(n//2-1):
# print(2*(j+1)-1)
# print(n-1+n//2)
# k,r=map(int,input().split())
# i=1
# while((k*i)%10)!=0 and ((k*i)%10)!=r:
# i=i+1
# print(i)
# for _ in range(int(input())):
# n,m=map(int,input().split())
# if(abs(n-m)==0):
# print(0)
# else:
# if(abs(n-m)%10==0):
# print((abs(n-m)//10))
# else:
# print((abs(n-m)//10)+1)
# a,b,c=map(int,input().split())
# print(max(a,b,c)-min(a,b,c))
# a=int(input())
# arr=list(map(int,input().split()))
# print(a*max(arr)-sum(arr))
# for _ in range(int(input())):
# a, b = map(int, input().split())
# if a==b:
# print((a+b)**2)
# elif max(a,b)%min(a,b)==0:
# print(max(a,b)**2)
# else:
# ans=max(max(a,b),2*min(a,b))
# print(ans**2)
# import math
# # for _ in range(int(input())):
# x=int(input())
# a=list(map(int,input().split()))
# for j in range(len(a)):
# n=math.sqrt(a[j])
# flag=0
# if(a[j]==1):
# print("NO")
# elif(n==math.floor(n)):
# for i in range(int(n)):
# if((6*i)-1==n or ((6*i)+1==n) or n==2 or n==3 or n!=1):
# # print("YES")
# flag=1
# break
# else:
# flag=0
# print("YES" if flag==1 else "NO")
# else:
# print("NO")
# print(12339-12345)
# for _ in range(int(input())):
# x,y,n=map(int,input().split())
# # for i in range((n-x),n):
# # # if(i%x==y):
# # print(i)
# print(n-(n-y)%x)
# n=int(input())
# for _ in range(int(input())):
# n= int(input())
# print(int(2**(n//2+1)-2))
# for _ in range(int(input())):
# n=int(input())
# arr=list(map(int,input().split()))
# countod=0
# countev=0
# for i in range(n):
# if i%2==0 and arr[i]%2!=0:
# countev+=1
# elif i%2!=0 and arr[i]%2==0:
# countod+=1
# if countod!=countev:
# print(-1)
# else:
# print(countev)
# n,m=map(int,input().split())
# x=m/(n//2)
# print(x)
# print(int(x*(n-1)))
# for _ in range(int(input())):
# n,m = map(int,input().split())
# print(m*min(2,n-1))
# n=int(input())
# if(n%2==0):
# print(n//2)
# print('2 '*(n//2))
# else:
# print(((n-2)//2)+1)
# print('2 '*(((n-2)//2)) + "3")
# for _ in range(int(input())):
# n=int(input())
# for i in range(2,30):
# if(n%(2**i - 1)==0):
# print(n//(2**i - 1))
# break
# a,b=map(int,input().split())
# print((a-1)//(b-1)+a)
# for _ in range(int(input())):
# n=int(input())
# print(n//2)
# for _ in range(int(input())):
# n=int(input())
# if(n%2==0):
# print(n//2)
# else:
# print((n//2)+1)
# for _ in range(int(input())):
# a,b = map(int, input().split())
# count = 0
# while(min(a,b) != 0):
# x=max(a,b)
# y = min(a,b)
# a = y
# b=x
# count += b//a
# b = b % a
# print(count)
# n,k=map(int,input().split())
# a=list(map(int,input().split()))
# m=min(a)
# c=0
# for i in a:
# if (i-m)%k!=0:
# print(-1)
# break
# c+=(i-m)//k
# else:
# print(c)
# a,b = map(int,input().split())
# l = b-(2*a)
# if l < a:
# print(a-l)
# else:
# print(0)
# for _ in range(int(input())):
# n = int(input())
# n2 = 0
# n3 = 0
# while n % 2 == 0:
# n2 += 1
# n //= 2
# while n % 3 == 0:
# n3 += 1
# n //= 3
# if n != 1 or n2 > n3:
# print(-1)
# else:
# print(2 * n3 - n2)
# t=int(input())
# for _ in range(t):
# x,n,m=map(int,input().split())
# while x>20 and n>0:
# x=x//2+10
# n-=1
# while m>0:
# x=x-10
# m-=1
# if x<=0:
# print("YES")
# else:
# print("NO")
# for _ in range(int(input())):
# print(int(input()))
# t=int(input())
# for i in range(t):
# n,a,b,c,d=map(int,input().split())
# if (a-b)*n<=c+d and c-d<=(a+b)*n:
# print('YES')
# else:
# print('NO')
# for t in range(int(input())):
# x, y = map(int, input().split())
# print((x*y+1)//2)
# t = int(input())
# for _ in range(t):
# a,b=list(map(int,input().split()))
# if b==a:
# print(0)
# if b>a:
# print((2-(b-a)%2))
# if b<a:
# print((1+(a-b)%2))
# t = int(input())
# for _ in range(t):
# a, b, c, n = map(int, input().split())
# # if (a+b+c+n) % 3 == 0 and (((a+b+c+n) // 3) >= max(a, b, c)):
# # print("YES")
# # else:
# # print("NO")
# m = max(a,b,c)
# d = n-(sum([abs(m-a),abs(b-m),abs(c-m)]))
# print("YES" if(d>=0 and d%3==0) else "NO")
# for _ in range ( int(input()) ):
# x,y,z = sorted (map(int,input().split()))
# # print(x,y,z)
# if y == z :
# print("YES")
# print (x,1,z)
# else:
# print("NO")
# n=int(input())
# a=list(map(int,input().split()))
# x=sum(a)
# y=0
# count=0
# while(y<=x):
# y+=max(a)
# x=x-max(a)
# a.remove(max(a))
# count+=1
# print(count)
# s = input()
# flag=0
# for x in 'HQ9':
# if x in s:
# flag=1
# print("YES" if flag==1 else "NO")
# import math
# n=int(input())
# a=list(map(int,input().split()))
# s=sum(a)
# print(math.floor(s//4)+1)
# from math import ceil
# n=int(input())
# s=list(map(int,input().split()))
# a=s.count(4)
# b=s.count(3)
# c=s.count(2)
# d=s.count(1)
# p=a+b
# if d<=b:
# p=p+ceil(c/2)
# else :
# p=p+ceil((d-b+2*c)/4)
# print(p)
# s=input()
# uc=lc=0
# for i in s:
# if i.isupper():
# uc+=1
# else:
# lc+=1
# # print(uc,lc)
# if(lc>=uc):
# s=s.lower()
# else:
# s=s.upper()
# print(s)
# s=input()
# m=input(),
# print("YES" if s[::-1]==m else "NO")
# a=input()
# n=input()
# dc=ac=0
# for i in n:
# if i=='D':
# dc+=1
# else:
# ac+=1
# if dc>ac:
# print("Danik")
# elif(ac>dc):
# print("Anton")
# else:
# print("Friendship")
# n=input()
# if len(n)==1:
# print(n.swapcase())
# else:
# if n.isupper():
# print(n.lower())
# else:
# if n[1:].isupper():
# print(n.capitalize())
# else:
# print(n)
# print(*input().split('WUB'))
# s={"Tetrahedron":4,"Cube":6,"Octahedron":8,"Dodecahedron":12,"Icosahedron":20}
# c=0
# for i in range(int(input())):
# c+=s[input()]
# print(c)
# a=input()
# print("YES" if len(set(input().lower())) == 26 else "NO")
# for _ in range(int(input())):
# n=int(input())
# s=input()
# while '()' in s:
# s=s.replace('()','')
# # print(s)
# print(len(s)//2)
# m = "hello"
# n=input()
# j=0
# flag=0
# for i in range(len(n)):
# if(n[i]==m[j]):
# j=j+1
# if(j==5):
# flag=1
# break
# if(flag==1):
# print("YES")
# else:
# print("NO")
# s=input()
# ab=s.count('AB')
# ba=s.count('BA')
# aba=s.count('ABA')
# bab=s.count('BAB')
# # print(ab,ba,aba,bab)
# if ab+ba-aba-bab>=2 and ab>0 and ba>0:
# print('YES')
# else:
# print('NO')
# n,m=map(int,input().split())
# d={}
# for i in range(m):
# a,b=input().split()
# d[a]=b
# for x in input().split():
# # print(d[x])
# if len(x)<=len(d[x]) :
# print(x,end=" ")
# else:
# print(d[x],end=" ")
# n=int(input())
# List=[]
# for i in range(n):
# List.append(input())
# List.sort()
# print(List[n//2])
# for _ in range(int(input())):
# s = input()
# if s.count('0') == len(s) or s.count('0') == 0:
# print(s)
# else :
# print("10" * len(s))
# for i in range(int(input())):
# S=input()
# print("".join(set(S))*len(S))
# t = int(input())
# for _ in range(t):
# n = int(input())
# a=list(map(int,input().split()))
# for _ in range(int(input())):
# n=int(input())
# l=list(map(int,input().split()))
# flag=0
# for i in range(n):
# if i+2<n:
# if l[i] in l[i+2:]:
# flag=1
# break
# if flag==1:
# print('YES')
# else:
# print('NO')
# n=int(input())
# print("codeforces"+"s"*(n-1))
# g=(input())
# h=(input())
# c=(input())
# print("YES" if sorted(g+h)==sorted(c) else "NO")
# a,b=map(int,input().split())
# a,b=map(int,input().split())
# i=int(input())
# print((a^i)+(b^i))
# for _ in range(int(input())):
# a,b=map(int,input().split())
# print(a^b)
# for _ in range(int(input())):
# n=input()
# count=0
# for i in n:
# if(i=="B" and count!=0):
# count=count-1
# else:
# count=count+1
# print(count)
# n=list(input())
# count=0
# for i in range(len(n)):
# # print(n[i])
# if(n[i]=='4' or n[i]=='7'):
# count+=1
# m=count
# # print(m)
# if(m==4 or m==7):
# print("YES")
# else:
# print("NO")
# count=0
# for _ in range(int(input())):
# n,m=map(int,input().split())
# if(abs(n-m)>=2):
# count+=1
# print(count)
# n,m=map(int,input().split())
# a=map(int,input().split())
# q=0
# p=1
# for i in a:
# q+=(i-p)%n;p=i
# print(q)
# input()
# d=[0]*100001
# for x in map(int,input().split()):
# d[x]+=x
# a=b=0
# for i in d:
# a,b=max(a,i+b),a
# print(a)
# def hanoisum(n):
# s=0
# for i in range(1,n+1):
# s+= 2**(i-1)
# return s
# n=int(input())
# print(hanoisum(n))
# def hanoisum(n):
# if n==1:
# return 1
# return n + hanoisum(2**(n-1))
# x=int(input())
# print(hanoisum(x))
# def hanoi(x,a,b,c):
# if(x==1):
# print("move 1 from " + a +"to"+c)
# return
# hanoi(x-1,a,c,b)
# print("move" + x + " from "+ a + "to" +c)
# hanoi(n-1,b,a,c)
# n=int(input())
# print(hanoi(n,A,B,C))
# for i in range(int(input())):
# n,k=map(int,input().split())
# a=list(map(int,input().split()))
# b=list(map(int,input().split()))
# a.sort()
# b.sort(reverse=True)
# for j in range(k):
# if b[j]>a[j]:
# a[j],b[j]=b[j],a[j]
# print(sum(a))
# n, s = map(int, input().split())
# if(n==1 and s==0):
# print('0 0')
# elif(9*n < s or s == 0):
# print('-1 -1')
# else:
# x1 = 10**(n-1)
# for i in range(s-1):
# x1 += 10**(i//9)
# x2 = 0
# for i in range(s):
# x2 += 10**(n-1-i//9)
# print(x1, x2)
# n=int(input())
# s=n+1
# while len(set(str(s)))<4:
# s+=1
# print(s)
# t=int(input())
# for i in range(t):
# n=int(input())
# c=list(map(int,input().split()))
# o=list(map(int,input().split()))
# minc=min(c)
# mino=min(o)
# ans=0
# for j in range(n):
# ans+=max(abs(minc-c[j]),abs(mino-o[j]))
# print(ans)
# for t in range(int(input())):
# n = int(input())
# l = sorted(list(map(int,input().split())))
# a=[]
# for i in range(n-1):
# x=l[i+1]-l[i]
# a.append(x)
# print(min(a))
# b=int(input())
# boys=list(map(int,input().split()))
# boys.sort()
# g=int(input())
# girls=list(map(int,input().split()))
# girls.sort()
# count=0
# for boy in boys:
# for i in range(g):
# if abs(boy-girls[i])<=1:
# count+=1
# girls[i]=-2
# break
# print(count)
# for _ in range(int(input())):
# a=int(input())
# l=list(map(int,input().split()))
# s=[]
# for i in l:
# if i not in s:
# s.append(i)
# print(" ".join(str(x)for x in s))
# n,x=map(int,input().split())
# s=input()
# for i in range(x):
# s=s.replace("BG","GB")
# print(s)
# n, m = map(int,input().split())
# a = sorted(map(int,input().split()))
# x=[]
# for i in range(m-n+1):
# x.append((a[i+n-1]-a[i]))
# print(min(x))
# for i in range(int(input())):
# x=int(input())
# print(2)
# print(x,x-1)
# for i in range(x-2):
# print(x,x-2)
# x=x-1
# mc=0
# cc=0
# t=int(input())
# for i in range(t):
# m,c=map(int,input().split())
# if(m>c):
# mc+=1
# elif(m<c):
# cc+=1
# if(mc>cc):
# print("Mishka")
# elif(cc>mc):
# print("Chris")
# else:
# print("Friendship is magic!^^")
# n,a,b,c = map(int,input().split())
# a,b,c = sorted([a,b,c])[::-1]
# ans = 0
# for i in range(n//a+1):
# for j in range(n//b+1):
# k = (n-i*a-j*b)//c
# if i*a+b*j+k*c==n and k>=0:
# ans = max(ans,i+j+k)
# break
# print(ans)
# n=int(input())
# b=input().split()
# for i in range(n):
# print(b.index(str(i+1))+1,end=" ")
# import math
# x=int(input())
# next = math.floor(math.log(x)/math.log(2))
# print(next)
# y= pow(2,math.ceil(math.log(x)/math.log(2)))
# print(next-(x-y))
# n=int(input())
# count=0
# while(n!=0):
# if(n%2==1):
# count+=1
# n=n//2
# print(count)
# t=int(input())
# for _ in range(t):
# a,b=map(int,input().split())
# if(a!=0)and(b!=0):
# res=(a+b)//3
# else:
# res=0
# print(min(res,a,b))
# n=int(input())
# ar=list(map(int,input().split()))
# for i in range(0,n):
# a=ar[i]%2
# b=ar[(i+1)%n]%2
# c=ar[(i-1)%n]%2
# if(a!=b) and a!=c:
# print(i+1)
# break
# n=int(input())
# arr=list(map(int,input().split()))
# arr.sort()
# print(*arr)
# n,h=map(int,input().split())
# a=list(map(int,input().split()))
# count=0
# for i in a:
# if i>h:
# count+=2
# else:
# count+=1
# print(count)
# int(input())
# count=1
# cc=1
# a=list(map(int,input().split()))
# for i in range(len(a)-1):
# if(a[i+1]>=a[i]):
# count+=1
# else:
# count=1
# cc=max(cc,count)
# print(cc)
# t=int(input())
# s=""
# while t:
# s+=input()
# t-=1
# one=s.count("11")
# zero=s.count("00")
# print((one+zero)+1)
# n=input()
# m=input()
# x=[]
# for i in range(len(n)) :
# if n[i]!=m[i]:
# x.append(1)
# else:
# x.append(0)
# print("".join(str(x)for x in x))
# int(input())
# print("HARD" if 1 in list(map(int,input().split())) else "EASY")
# n = int(input())
# print('I hate' + ' that I love that I hate' * ((n-1)// 2)*(n > 2) + ' that I love' * ((n + 1) % 2) +' it')
# a=int(input())
# b=list(map(int,input().split()))
# c=list(map(int,input().split()))
# d=b[1:]+c[1:]
# if(len(set(d))==a):
# print("I become the guy.")
# else:
# print("Oh, my keyboard!")
# a=len(set(input().split()))
# print(4-a)
# if (u,v) in mem:
# print(mem[(u,v)])
# else:
# x=len(dict[u].f)
# uval=dict[u].f
# vval=dict[v].f
# ans=0
# for i in range(len(uval)):
# ans+=uval[i]*vval[i]
# ans=ans%(2**32)
# mem[(u,v)]=ans
# print(ans)
# for _ in range(int(input())):
# n,c0,c1,h=map(int,input().split())
# s=input()
# x=s.count('0')
# y=s.count('1')
# o=((x*c0)+(y*c1))
# a=h*x
# b=h*y
# cz=(n*c0)+b
# con=(n*c1)+a
# print(min(cz,con,o))
# n=int(input())
# k=int(input())
# z=k
# a=list(map(int,input().split()))
# b=len(a)
# i=-n
# s=0
# # print(a[-2],a[-4],a[-6],a[-8])
# while(i>=-b):
# print(a[i])
# i-=n
# n,d=int(input()),{}
# for i in range(n):
# s=input()
# if s not in d:
# d[s]='0'
# print('OK')
# else:
# d[s]=str(int(d[s])+1)
# print(s+d[s])
# from math import factorial
# n=int(input())
# a=input()
# f=1
# for i in a:
# f*=factorial(int(i))
# # print(f)
# for d in (7,5,3,2):
# while(f>1):
# if(f%d==0):
# print(d,end='')
# # print(factorial(d))
# f=f//factorial(d)
# # print(f)
# else:
# break
# import math
# for _ in range(int(input())):
# n,m,k=map(int,input().split())
# c=n//k
# a=min(m,c)
# b=math.ceil((m-a)/(k-1))
# print(a-b)
# for _ in range(int(input())):
# n=int(input())
# print(len(n))
# n=int(input())
# if n%2==0:
# print(n//2)
# else:
# c=n-(n//2)
# print(-c)
# for _ in range(int(input())):
# s=input()
# print(s[::2]+s[-1])
# for _ in range(int(input())):
# n,k=map(int,input().split())
# x=[]
# if (n==k):
# for i in range(1,n+1):
# x.append(i)
# print(*x)
# else:
# if (k<n//2):
# for i in range(1,n+1):
# x.append(-i)
# for i in range(0,2*k,2):
# x[i]*=-1
# print(*x)
# else:
# for i in range(1,n+1):
# x.append(i)
# for i in range(0,2*(n-k),2):
# x[i]*=-1
# print(*x)
# import sys
# sys.stdin = open("input.txt","r")
# sys.stdout = open("output.txt","w")
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
# x=0
# for i in range(n):
# if arr[i]<k:
# x+=arr[i]
# else:
# x+=arr[i]-k*min(3,arr[i]//k)
# print(x)
#25 May
# s=list(set(input()))
# arr=[]
# for i in s:
# if i.isalpha():
# arr.append(i)
# print(len(set(arr)))
# a,b=map(int,input().split())
# x=0
# for i in range(a):
# if i%2==0:
# print("#"*b)
# else:
# if x%2==0:
# print('.'*(b-1)+"#")
# x+=1
# else:
# print("#"+"."*(b-1))
# x+=1
#26 May
# for _ in range(int(input())):
# n=int(input())
# arr=list(map(int,input().split()))
# a=list(set(arr))
# a.sort()
# if (max(a)-min(a))<len(a):
# print("YES")
# else:
# print("NO")
# else:
# for i in range(1,len(a)):
# a[i]=a[i]-a[i-1]
# if len(set(a))>1:
# print("NO")
# else:
# ar=list(set(a))
# if ar[0]==1:
# print("YES")
# else:
# print("NO")
# n=int(input())
# arr=list(map(int,input().split()))
# minn=maxx=arr[0]
# count=0
# for i in range(1,n):
# if arr[i]>maxx:
# count+=1
# maxx=arr[i]
# elif arr[i]<minn:
# count+=1
# minn=arr[i]
# print(count)
# n,m,a,b=map(int,input().split())
# if (b/m)<=a:
# if (n%m)==0:
# s=n//m
# summ = s*b
# print(summ)
# else:
# # res=n%m
# # s=n//m
# summ = ((n//m)*b) + ((n%m)*a)
# # res=1
# # s=(n//m)+1
# summm = (((n//m)+1)*b)
# print(min(summ,summm))
# else:
# print(n*a)
# 27 May
# n=int(input())
# arr=list(map(int,input().split()))
# s=0
# c=0
# for i in arr:
# s+=i
# if s<0:
# c+=1
# s=0
# print(c)
# n,k = map(int,input().split())
# arr=list(map(int,input().split()))
# c=0
# for i in arr:
# if (5-i)>=k:
# c+=1
# print(c//3)
# a,b=map(int,input().split())
# print((a-1)//(b-1)+a)
#28 May
# for _ in range(int(input())):
# n=int(input())
# a=list(map(int,input().split()))
# if((a.count(1)%2==0 and a.count(1)>0) or len(a)==0 or (a.count(2)%2==0 and a.count(1)%2==0)):
# print('YES')
# else:
# print('NO')
#2 2 4
# 5 7 2
# for _ in range(int(input())):
# n=int(input())
# s=list(map(int,input().split()))
# e=0
# o=0
# for i in s:
# if(i%2==0):
# e+=1
# else:
# o+=1
# if((o==n and n%2==0) or e==n):
# print("NO")
# else:
# print("YES")
#29 May
# s=list(map(int,input().split()))
# n=input()
# x=0
# for i in n:
# x+=s[int(i)-1]
# print(x)
# import math
# n=int(input())
# print(int(math.factorial(2*(n-1))/(math.factorial(n-1)**2)))
# def maximumOccuringCharacter(s):
# arr=[0]*255
# for i in s:
# arr[ord(i)]+=1
# m=max(arr)
# for i in range(255):
# if arr[i]==m:
# return chr(i)
# s=input()
# print(maximumOccuringCharacter(s))
# for _ in range(int(input())):
# hr,mn = map(int,input().split())
# ts = 60*24
# s = (hr*60)+mn
# print(ts-s)
# if (int(input())) % 2==0:
# print("Mahmoud")
# else:
# print("Ehab")
#30 May
# for _ in range(int(input())):
# a,b,c,d=map(int,input().split())
# print(b,c,c)
# import math
# for _ in range(int(input())):
# n,x = map(int,input().split())
# if n==1:
# print(1)
# else:
# n=n-2
# print(math.ceil(n/x)+1)
#31 May
# for i in range(int(input())):
# a,b,n=map(int,input().split())
# if a<b:
# a,b=b,a
# cnt=0
# while a<=n:
# a,b=a+b,a
# cnt+=1
# print(cnt)
#2 Apr
a,b,c,d=map(int,input().split())
x=min(a,c,d)
ans=(x*256)
a-=x
x=max(a,b)
ans+=(x*32)
print(ans)
``` | instruction | 0 | 56,085 | 20 | 112,170 |
No | output | 1 | 56,085 | 20 | 112,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
Input
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Output
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note
In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
Submitted Solution:
```
k2,k3,k5,k6 = map(int,input().split())
ans = 0
m = min(k2,k5,k6)
ans += 256*m;
if m == k2:
k2 = 0
ans += 32*min(k2,k3)
print(ans)
``` | instruction | 0 | 56,086 | 20 | 112,172 |
No | output | 1 | 56,086 | 20 | 112,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
— Willem...
— What's the matter?
— It seems that there's something wrong with Seniorious...
— I'll have a look...
<image>
Seniorious is made by linking special talismans in particular order.
After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.
Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is an integer ai.
In order to maintain it, Willem needs to perform m operations.
There are four types of operations:
* 1 l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
* 2 l r x: For each i such that l ≤ i ≤ r, assign x to ai.
* 3 l r x: Print the x-th smallest number in the index range [l, r], i.e. the element at the x-th position if all the elements ai such that l ≤ i ≤ r are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1 ≤ x ≤ r - l + 1.
* 4 l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e. <image>.
Input
The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).
The initial values and operations are generated using following pseudo code:
def rnd():
ret = seed
seed = (seed * 7 + 13) mod 1000000007
return ret
for i = 1 to n:
a[i] = (rnd() mod vmax) + 1
for i = 1 to m:
op = (rnd() mod 4) + 1
l = (rnd() mod n) + 1
r = (rnd() mod n) + 1
if (l > r):
swap(l, r)
if (op == 3):
x = (rnd() mod (r - l + 1)) + 1
else:
x = (rnd() mod vmax) + 1
if (op == 4):
y = (rnd() mod vmax) + 1
Here op is the type of the operation mentioned in the legend.
Output
For each operation of types 3 or 4, output a line containing the answer.
Examples
Input
10 10 7 9
Output
2
1
0
3
Input
10 10 9 9
Output
1
1
3
3
Note
In the first example, the initial array is {8, 9, 7, 2, 3, 1, 5, 6, 4, 8}.
The operations are:
* 2 6 7 9
* 1 3 10 8
* 4 4 6 2 4
* 1 4 5 8
* 2 1 7 1
* 4 7 9 4 4
* 1 2 7 9
* 4 5 8 1 1
* 2 5 7 5
* 4 3 10 8 5
Submitted Solution:
```
print("VIRAJ")
``` | instruction | 0 | 56,129 | 20 | 112,258 |
No | output | 1 | 56,129 | 20 | 112,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
— Willem...
— What's the matter?
— It seems that there's something wrong with Seniorious...
— I'll have a look...
<image>
Seniorious is made by linking special talismans in particular order.
After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.
Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is an integer ai.
In order to maintain it, Willem needs to perform m operations.
There are four types of operations:
* 1 l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
* 2 l r x: For each i such that l ≤ i ≤ r, assign x to ai.
* 3 l r x: Print the x-th smallest number in the index range [l, r], i.e. the element at the x-th position if all the elements ai such that l ≤ i ≤ r are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1 ≤ x ≤ r - l + 1.
* 4 l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e. <image>.
Input
The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).
The initial values and operations are generated using following pseudo code:
def rnd():
ret = seed
seed = (seed * 7 + 13) mod 1000000007
return ret
for i = 1 to n:
a[i] = (rnd() mod vmax) + 1
for i = 1 to m:
op = (rnd() mod 4) + 1
l = (rnd() mod n) + 1
r = (rnd() mod n) + 1
if (l > r):
swap(l, r)
if (op == 3):
x = (rnd() mod (r - l + 1)) + 1
else:
x = (rnd() mod vmax) + 1
if (op == 4):
y = (rnd() mod vmax) + 1
Here op is the type of the operation mentioned in the legend.
Output
For each operation of types 3 or 4, output a line containing the answer.
Examples
Input
10 10 7 9
Output
2
1
0
3
Input
10 10 9 9
Output
1
1
3
3
Note
In the first example, the initial array is {8, 9, 7, 2, 3, 1, 5, 6, 4, 8}.
The operations are:
* 2 6 7 9
* 1 3 10 8
* 4 4 6 2 4
* 1 4 5 8
* 2 1 7 1
* 4 7 9 4 4
* 1 2 7 9
* 4 5 8 1 1
* 2 5 7 5
* 4 3 10 8 5
Submitted Solution:
```
class Chtholly:
def __init__(self):
global n
self.l = [i for i in range(1, n+1)]
self.r = [i for i in range(1, n+1)]
self.val = [(rnd() % vmax) + 1 for i in range(1, n+1)]
def lower_bound(self, pos):
i = 0
j = len(self.l) - 1
while i < j:
mid = (i + j) >> 1
if pos < self.l[mid]:
j = mid
else:
i = mid + 1
return j - 1
def delete(self, itl, itr = None):
itr = (itr if itr else itl + 1)
del self.l[itl: itr]
del self.r[itl: itr]
del self.val[itl: itr]
def insert(self, it, _l, _r, x):
self.l.insert(it, _l)
self.r.insert(it, _r)
self.val.insert(it, x)
def split(self, pos):
it = self.lower_bound(pos)
if self.l[it] == pos:
return it
tmp = (self.l[it], self.r[it], self.val[it])
self.delete(it)
self.insert(it, tmp[0], pos - 1, tmp[2])
self.insert(it + 1, pos, tmp[1], tmp[2])
return it + 1
def add(self, _l, _r, x):
itl = self.split(_l)
itr = self.split(_r+1)
for i in range(itl, itr):
self.val[i] += x
def assign(self, _l, _r, x):
itl = self.split(_l)
itr = self.split(_r+1)
self.delete(itl, itr)
self.insert(itl, _l, _r, x)
def rank(self, _l, _r, k):
tmp = []
itl = self.split(_l)
itr = self.split(_r+1)
for i in range(itl, itr):
tmp.append((self.val[i], self.r[i] - self.l[i] + 1))
tmp.sort(key = lambda x: x[0])
for i in tmp:
k -= i[1]
if k <= 0:
return i[0]
def get_sum(self, _l, _r, x, mod):
ans = 0
itl = self.split(_l)
itr = self.split(_r+1)
for i in range(itl, itr):
ans = (ans + (self.r[i] - self.l[i] + 1) * pow(self.val[i], x, mod)) % mod
return ans
def rnd():
global seed
ret = seed
seed = (seed * 7 + 13) % 1000000007
return ret
n, m, seed, vmax = (int(i) for i in input().split())
tyslsiZ = Chtholly()
for i in range(m):
op = (rnd() % 4) + 1
l = (rnd() % n) + 1
r = (rnd() % n) + 1
if l > r:
l, r = r, l
if op == 3:
x = (rnd() % (r - l + 1)) + 1
print(tyslsiZ.rank(l, r, x))
else:
x = (rnd() % vmax) + 1
if op == 1:
tyslsiZ.add(l, r, x)
if op == 2:
tyslsiZ.assign(l, r, x)
if op == 4:
y = (rnd() % vmax + 1)
print(tyslsiZ.get_sum(l, r, x, y))
``` | instruction | 0 | 56,130 | 20 | 112,260 |
No | output | 1 | 56,130 | 20 | 112,261 |
Provide a correct Python 3 solution for this coding contest problem.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000 | instruction | 0 | 56,345 | 20 | 112,690 |
"Correct Solution:
```
from math import gcd
def solve(p, q):
GCD = gcd(p, q)
p = p // GCD
q = q // GCD
print(p, q, sep="/")
s = input()
x, y = s.split('.')
if(y[-1] != ')'):
p = int(x) * pow(10, len(y)) + int(y)
q = pow(10, len(y))
solve(p, q)
else:
y, z = y.split('(')[0], y.split('(')[1][:-1]
a = int(x+y+z)
b = int(x+y)
solve(a-b, (pow(10, len(z))-1)*pow(10, len(y)))
``` | output | 1 | 56,345 | 20 | 112,691 |
Provide a correct Python 3 solution for this coding contest problem.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000 | instruction | 0 | 56,346 | 20 | 112,692 |
"Correct Solution:
```
from math import gcd
s = input()
x, y = s.split(".")
if "(" in s:
da = y.index("(")
db = y.index(")") - 1
ya, b = y.split("(")
lb = len(b) - 1
a = int(x + ya)
b = int(b[:-1])
deco = a * (10 ** db - 10 ** (db - lb)) + b * 10 ** da
nume = 10 ** da * (10 ** db - 10 ** (db - lb))
div = gcd(deco, nume)
print(deco // div, nume // div, sep="/")
else:
da = len(y)
a = int(x + y)
deco = a
nume = 10 ** da
div = gcd(deco, nume)
print(deco // div, nume // div, sep="/")
``` | output | 1 | 56,346 | 20 | 112,693 |
Provide a correct Python 3 solution for this coding contest problem.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000 | instruction | 0 | 56,347 | 20 | 112,694 |
"Correct Solution:
```
def gcd(x, y):
return gcd(y, x%y) if y else x
def printV(x, y):
g = gcd(x, y)
print(str(x//g) + "/" + str(y//g))
S = input()
all = ""
sub = ""
p = -1
for i in range(len(S)):
if S[i] == '.':
o = i
elif S[i] == '(':
p = i
sub = all
elif S[i] != ')':
all += S[i]
d = len(S) - o - 1
l = p - o - 1
if p == -1:
printV(int(all), 10**d)
else:
d -= 2 # for ()
printV(int(all) - int(sub), 10**d - 10**l)
``` | output | 1 | 56,347 | 20 | 112,695 |
Provide a correct Python 3 solution for this coding contest problem.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000 | instruction | 0 | 56,348 | 20 | 112,696 |
"Correct Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def f(v):
d = v.find(".")
if d == -1:
return int(v), 1
a = int(v[:d]+v[d+1:])
n = 10**(len(v)-d-1)
if a == 0:
return 0, 1
g = gcd(n, a)
return int(a/g), int(n/g)
s = input()
d = s.find(".")
l = s.find("(")
r = s.find(")")
if l == -1:
res = f(s)
else:
assert l>=2 and r == len(s)-1
aa, na = f(s[:l])
ab, nb = f("0." + "0"*(l-d-1) + s[l+1:r])
t = r-l-1
a = (10**t - 1)*aa*nb + 10**t*ab*na
n = (10**t - 1)*na*nb
g = gcd(a, n)
res = int(a/g), int(n/g)
print("%d/%d" % res)
``` | output | 1 | 56,348 | 20 | 112,697 |
Provide a correct Python 3 solution for this coding contest problem.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000 | instruction | 0 | 56,349 | 20 | 112,698 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
e = LI()
d = defaultdict(int)
for i in e:
d[i] += 1
for i in d.values():
if i != 2:
print("no")
break
else:
print("yes")
return
#B
def B():
n = I()
a = LI()
a.sort()
ans = -float("inf")
for c in range(n):
for d in range(c):
m = a[c]-a[d]
for i in range(n)[::-1]:
if i != c and i != d:
e = i
break
for i in range(e)[::-1]:
if i != c and i != d:
b = i
break
ans = max(ans, (a[e]+a[b])/m)
print(ans)
return
#C
def C():
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
s = input()
n = len(s)
if s.count("(") == 0:
s = float(s)
b = 10**(n-2)
a = round(s*b)
g = gcd(a,b)
a //= g
b //= g
else:
n = s.find("(")
t = float(s[:n])
b = 10**(n-2)
a = round(t*b)
g = gcd(a,b)
a //= g
b //= g
l = (s.find("(")-s.find(".")-1)
s = s[n+1:-1]
m = len(s)
c = round(float(s))
d = (10**m-1)*10**l
g = gcd(c,d)
c //= g
d //= g
a = a*d+b*c
b = b*d
g = gcd(a,b)
a //= g
b //= g
print(str(a)+"/"+str(b))
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#I
def I_():
return
#J
def J():
return
#Solve
if __name__ == "__main__":
C()
``` | output | 1 | 56,349 | 20 | 112,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000
Submitted Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def f(v):
d = v.find(".")
if d == -1:
return int(v), 1
a = int(v[:d]+v[d+1:])
n = 10**(len(v)-d-1)
if a == 0:
return 0, 1
g = gcd(n, a)
return int(a/g), int(n/g)
s = input()
l = s.find("(")
r = s.find(")")
if l == -1:
res = f(s)
else:
aa, na = f(s[:l])
assert l>=2
ab, nb = f("0." + "0"*(l-2) + s[l+1:r])
t = r-l-1
a = (10**t - 1)*aa*nb + 10**t*ab*na
n = (10**t - 1)*na*nb
g = gcd(a, n)
res = a/g, n/g
print("%d/%d" % res)
``` | instruction | 0 | 56,350 | 20 | 112,700 |
No | output | 1 | 56,350 | 20 | 112,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000
Submitted Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def f(v):
d = v.find(".")
if d == -1:
return int(v), 1
a = int(v[:d]+v[d+1:])
n = 10**(len(v)-d-1)
if a == 0:
return 0, 1
g = gcd(n, a)
return a/g, n/g
s = input()
l = s.find("(")
r = s.find(")")
if l == -1:
res = f(s)
else:
va, na = f(s[:l])
vb, nb = f("0." + "0"*(l-2) + s[l+1:r])
t = r-l-1
vb *= 10**t
nb *= 10**t - 1
ng = gcd(na, nb)
va *= nb; vb *= na
v = va+vb; n = na*nb
g = gcd(v, n)
v /= g; n /= g
res = v, n
print("%d/%d" % res)
``` | instruction | 0 | 56,351 | 20 | 112,702 |
No | output | 1 | 56,351 | 20 | 112,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000
Submitted Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def f(v):
d = v.find(".")
a = int(v[:d]+v[d+1:])
n = 10**(len(v)-d-1)
if a == 0:
return 0, 1
g = gcd(n, a)
return a/g, n/g
s = input()
l = s.find("(")
r = s.find(")")
if l == -1:
print("%d/%d" % f(s))
else:
va, na = f(s[:l])
vb, nb = f("0." + "0"*(l-2) + s[l+1:r])
t = r-l-1
vb *= 10**t
nb *= 10**t - 1
ng = gcd(na, nb)
va *= nb; vb *= na
v = va+vb; n = na*nb
g = gcd(v, n)
v /= g; n /= g
print("%d/%d" % (v, n))
``` | instruction | 0 | 56,352 | 20 | 112,704 |
No | output | 1 | 56,352 | 20 | 112,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of the real numbers, those with a circular decimal part and those with a finite number of digits can be expressed as fractions.
Given a real number that can be represented by a fraction, write a program that outputs an irreducible fraction equal to that real number (a fraction that cannot be reduced any further).
Input
The input is given in the following format.
str
One line is given the string str that represents the real number you want to convert. The real value is greater than 0. The character string is a number or a character string having a length of 3 or more and 8 or less, including ".", "(", ")". "." Indicates the decimal point, "(" indicates the beginning of the number cycle, and ")" indicates the end of the number cycle. It is assumed that one or more digits are always given to both the integer part and the decimal part. However, given a recurring decimal, the string satisfies the following conditions:
* The beginning and end pairs of the cycle appear only once to the right of the decimal point.
* The ")" that indicates the end of the cycle appears at the end of the string.
* A single or more digit is always given between the beginning and end of the cycle.
Output
Outputs a real number in irreducible fraction format (integer of numerator followed by integers of denominator separated by "/").
Examples
Input
0.(3)
Output
1/3
Input
1.0
Output
1/1
Input
5.2(143)
Output
52091/9990
Input
0.0739
Output
739/10000
Submitted Solution:
```
def gcd(m, n):
r = m % n
return gcd(n, r) if r else n
def f(v):
d = v.find(".")
if d == -1:
return int(v), 1
a = int(v[:d]+v[d+1:])
n = 10**(len(v)-d-1)
if a == 0:
return 0, 1
g = gcd(n, a)
return int(a/g), int(n/g)
s = input()
l = s.find("(")
r = s.find(")")
if l == -1:
res = f(s)
else:
assert l>=2 and r == len(s)-1
aa, na = f(s[:l])
ab, nb = f("0." + "0"*(l-2) + s[l+1:r])
t = r-l-1
a = (10**t - 1)*aa*nb + 10**t*ab*na
n = (10**t - 1)*na*nb
g = gcd(a, n)
res = int(a/g), int(n/g)
print("%d/%d" % res)
``` | instruction | 0 | 56,353 | 20 | 112,706 |
No | output | 1 | 56,353 | 20 | 112,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,427 | 20 | 112,854 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
from math import gcd
m,a,b = map(int,input().split())
g = gcd(a,b)
vis = [0]*(a+b+1)
vis[0] = 1
nvis = 1
count = 0
last = 0
t = 0
while True:
#print(t, vis)
if t >= b:
#print('back')
t -= b
if vis[t]:
break
vis[t] = 1
nvis += 1
else:
t += a
if t > m:
break
if t > last:
#print('forward', t - last, 'with', nvis)
count += (t - last)*nvis
last = t
if vis[t]:
break
vis[t] = 1
nvis += 1
#print(nvis,count)
#print('---')
if t > m:
# we're done
count += (m - last + 1)*nvis
else:
def sumto(n):
whole = n//g + 1
r = whole*(whole+1)//2 * g
corr = whole * (g-1 - (n%g))
r -= corr
return r
#S = 0
#for i in range(last, m+1):
# S += i//g + 1
#count += S
#assert S == sumto(m) - sumto(last-1)
count += sumto(m) - sumto(last-1)
#print(vis)
print(count)
``` | output | 1 | 56,427 | 20 | 112,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,428 | 20 | 112,856 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
from collections import deque
def gcd(a, b):
b = abs(b)
while b != 0:
r = a%b
a,b = b,r
return a
M, A, B = map(int, input().split())
X = [1]+[0]*(10**6)
Y = [0]
s = 1
t = 1
g = gcd(A, B)
for N in range(1, M+1):
if N >= A+B+g and (M-N+1) % g == 0:
ss = Y[N-1]-Y[N-g-1]
dd = (Y[N-1]-Y[N-2]) - (Y[N-g-1]-Y[N-g-2])
t += ss*(M-N+1)//g + dd*g*((M-N+1)//g)*((M-N+1)//g+1)//2
break
elif N >= A and X[N-A]:
que = deque([N])
X[N] = 1
s += 1
while len(que):
i = deque.pop(que)
if i >= B and X[i-B] == 0:
deque.append(que, i-B)
X[i-B] = 1
s += 1
if i + A < N and X[i+A] == 0:
deque.append(que, i+A)
X[i+A] = 1
s += 1
t += s
Y.append(t)
print(t)
``` | output | 1 | 56,428 | 20 | 112,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,429 | 20 | 112,858 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
import math
m,a,b=map(int,(input().split()))
vis=[-1]*(a+b+5)
now=0
maxd=0
while True:
vis[now]=maxd
#print(now,maxd)
if now>=b:
now-=b
else:
now+=a
if now==0:
break
maxd=max(maxd,now)
ans=0
#for i in range(0,a+b):
#print(vis[i])
for i in range(0,a+b):
if vis[i]!=-1:
ans+=max(0,m-vis[i]+1)
rest=m-(a+b)+1
if m>=a+b:
g=math.gcd(a,b)
tmp=(rest//g)*g
fir=rest-tmp
lst=rest
cnt=tmp//g+1
ans+=(fir+lst)*cnt//2
print(int(ans))
``` | output | 1 | 56,429 | 20 | 112,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,430 | 20 | 112,860 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
M, a, b = map(int, input().split())
mod = 10**9+7
D = [mod]*a
maxi = 0
D[0] = 0
Q = [0]
def f(x, i):
t = (x+1-i)//a
r = (x+1-i)%a
return a*t*(t+1)//2+r*(t+1)
while Q:
q = Q.pop()
D[q] = maxi
k = max(0, -((-(b-q))//a))
maxi = max(maxi, q+k*a)
if D[(q-b)%a] == mod and maxi <= M:
Q.append((q-b)%a)
ans = 0
for i, d in enumerate(D):
if d > M:
continue
ans += f(M, i) - f(d-1, i)
print(ans)
``` | output | 1 | 56,430 | 20 | 112,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,431 | 20 | 112,862 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
import math
m,a,b=map(int,input().split())
g=math.gcd(a,b)
a1=a//g
b1=b//g
alls=g*(a1+b1-1)
dists=[0]+[-1]*(a1+b1-1)
dist=0
far=0
while dist!=b1:
if dist<b1:
dist+=a1
far=max(dist,far)
else:
dist-=b1
if dists[dist]==-1:
dists[dist]=far
tot=0
for i in range(a1+b1):
if i*g<=m and dists[i]*g<=m:
tot+=(m+1-dists[i]*g)
if alls<m:
mod=m%g
times=m//g
diff=times-a1-b1
tot1=g*(diff*(diff+1)//2)+(mod+1)*(diff+1)
tot+=tot1
print(tot)
``` | output | 1 | 56,431 | 20 | 112,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,432 | 20 | 112,864 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
import sys
import math
input = sys.stdin.readline
def gcd(a, b):
while b:
a, b = b, a % b
return a
m,a,b=map(int,input().split())
GCD=gcd(a,b)
#when a>b,
MODLIST=[-1]*a
NOWMAX=a
NOW=a
MODLIST[0]=a
while True:
while NOW-b>0 and MODLIST[(NOW-b)%a]==-1:
NOW-=b
MODLIST[NOW]=NOWMAX
NOW+=a
NOWMAX=max(NOW,NOWMAX)
if MODLIST[(NOW-b)%a]!=-1:
break
ANS=m+1#0
MAX=max(MODLIST)
for i in range(1,min(m+1,MAX)):
if MODLIST[i%a]==-1:
continue
ANS+=max((m+1-max(MODLIST[i%a],i)),0)
#print(ANS)
if MAX<=m:
ANS+=(m-MAX+1+(m-m//GCD*GCD)+1)*((m//GCD*GCD-MAX)//GCD+1)//2
print(ANS)
``` | output | 1 | 56,432 | 20 | 112,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,433 | 20 | 112,866 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
from math import gcd
def Sum(n, mcd):
whole = n//mcd+1
r = whole*(whole+1)//2 *mcd
corr = whole * (mcd-1 - (n%mcd))
r -= corr
return r
def Solver(m, a, b, vis):
"""
Entrada:
vis[] -> lista que guarda en el i-ésimo elemento si la posición i ya fue visitada
Salida:
cant -> cantidad de posiciones alcanzables
"""
vis[0] = 1
cantVis = 1 # posiciones visitadas
cant = 0
der = 0 # posición más a la derecha
k = 0 # última posición
while 1:
if k >= b:
k -= b
if vis[k]:
break
vis[k] = 1
cantVis += 1
else:
k += a
if k > m:
break
if k > der:
cant += (k-der)*cantVis
der = k
if vis[k]:
break
vis[k] = 1
cantVis += 1
if k > m:
cant += (m-der + 1)*cantVis
else:
mcd = gcd(a,b)
cant += Sum(m, mcd) - Sum(der-1, mcd)
return cant
def Main():
m,a,b = map(int, input().split())
vis = [0]*(a+b+1)
sol = Solver(m, a, b, vis)
print(sol)
Main()
``` | output | 1 | 56,433 | 20 | 112,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case. | instruction | 0 | 56,434 | 20 | 112,868 |
Tags: dfs and similar, math, number theory
Correct Solution:
```
m,a,b = map(int, input().split())
vis = set()
i = 0
xi = 0 #Posición más a la derecha alcanzada. Llegar a esta significa que todas las posiciones alcanzadas después de esta dependen de ella
di = 0 #Primera posición que se alcanza que es congruente con i módulo a
def sumrange(f,t): #Suma desde f hasta t
if t<f:
return 0
return (f+t)*(t-f+1)//2
sol = 0
while i not in vis: #Si no se ha visto antes ese resto de a
vis.add(i) #Se añade al conjunto de restos vistos
if xi <= m:#Si la posición más a la derecha no se ha pasado de m todavía hay solución calculable
x1 = (xi-i)//a + 1 #menor valor a sumar
x2 = (m-i)//a + 1 #mayor valor a sumar
if x1 == x2: #Si x1 = x2 no hay números en el medio
sol += (m-xi+1)*x1#Se añade a la solución la cantidad de estos
else:
a1 = ((i-xi)%a) #Cantidad de veces que se suma x1
sol += a1 * x1
if a1 != 0:
x1 += 1 #Se halla el siguiente número
a2 = (1 + ((m-i)%a)) #Cantidad de veces que se suma x2
sol += a2 * x2
if a2 != 0:
x2 -= 1 #Se halla el número que antecede a x2
sol += a * sumrange(x1,x2) #Suma de los números entre x1 y x2
needa = max(0, (b-di+a-1)//a) #Se halla el menor k tal que xi + a*k >= b
di += needa*a #Se le suma a xi
xi = max(di, xi) #Se compara con el máximo actual
di -= b #Se le resta b
i = di%a #Nos movemos a esa posición
print(sol)
"""
Casos Probados:
* 1
m: 881706694 a: 5710 b: 56529
* Esperado: 680741853146475
* Devuelto: 680741853146475
* 2
m: 863 a: 99250 b: 420
* Esperado: 864
* Devuelto: 864
* 3
m: 16145755 a: 64220 b: 70642
* Esperado: 20303198570
* Devuelto: 20303198570
* 4
m: 99548 a: 73888 b: 32
* Esperado: 69626827
* Devuelto: 69626827
* 5
m: 936989 a: 17028 b: 92708
* Esperado: 229896864
* Devuelto: 229896864
* 6
m: 26 a: 92701 b: 7
* Esperado: 27
* Devuelto: 27
* 7
m: 79873 a: 13 b: 79872
* Esperado: 245419010
* Devuelto: 245419010
* 8
m: 1 a: 1 b: 1
* Esperado: 3
* Devuelto: 3
* Además este problema fue aceptado en el sitio,
por tanto dieron correctamente todos los casos de prueba del tester del sitio
"""
``` | output | 1 | 56,434 | 20 | 112,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
m,a,b = map(int, input().split())
vis = set()
i = 0
di = 0 #Posición más a la derecha alcanzada. Llegar a esta significa que todas las posiciones alcanzadas después de esta dependen de ella
xi = 0 #Primera posición que se alcanza que es congruente con i módulo a
def sumrange(f,t):
if t<f: return 0
return (f+t)*(t-f+1)//2
ans = 0
while i not in vis: #Si no se ha visto antes ese resto de a
vis.add(i) #Se añade al conjunto de restos vistos
if di <= m:#Si la posición más a la derecha no se ha pasado de m todavía hay solución calculable
x1 = (di-i)//a + 1 #menor valor a sumar
x2 = (m-i)//a + 1 #mayor valor a sumar
if x1 == x2: #Si x1 = x2 no hay números en el medio
ans += (m-di+1)*x1#Se añade a la solución la cantidad de estos
else:
a1 = ((i-di)%a) #Cantidad de veces que se suma x1
ans += a1 * x1
if a1 != 0:
x1 += 1 #Se halla el siguiente número
a2 = (1 + ((m-i)%a)) #Cantidad de veces que se suma x2
ans += a2 * x2
if a2 != 0:
x2 -= 1 #Se halla el número que antecede a x2
ans += a * sumrange(x1,x2) #Suma de los números entre x1 y x2
needa = max(0, (b-xi+a-1)//a) #Se halla el menor k tal que xi + a*k >= b
xi += needa*a #Se le suma a xi
di = max(xi, di) #Se compara con el máximo actual
xi -= b #Se le resta b
i = xi%a #Nos movemos a esa posición
print(ans)
``` | instruction | 0 | 56,435 | 20 | 112,870 |
Yes | output | 1 | 56,435 | 20 | 112,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
import math
M, A, B = map(int, input().split())
bound = [10**9 + 7]*(A + B)
l, r = 0, 0
while True:
bound[l] = r
if l >= B:
l -= B
else:
l += A
r = max(r, l)
if l == 0:
break
ans = 0
for i in range(0, A + B):
if bound[i] <= M:
ans += M - bound[i] + 1
rem = M - (A + B) + 1
if M >= (A + B):
g = math.gcd(A, B)
up = (rem // g) * g
lo = rem - up
cnt = up // g + 1
ans += (lo + rem) * cnt // 2
print(ans)
``` | instruction | 0 | 56,436 | 20 | 112,872 |
Yes | output | 1 | 56,436 | 20 | 112,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
from math import gcd
m, a, b = map(int, input().split())
last, x = 0, gcd(a, b)
s = [1]*(a+b+1)
q1, ans = 0, 1
max1, s[0] = [[0, 1]], 0
while q1 < a+b:
if q1 > b and s[q1-b]:
ans += 1
q1 -= b
s[q1] = 0
else:
q1 += a
if q1 > last:
max1.append([q1, ans])
last = q1
if s[q1]:
ans += 1
s[q1] = 0
ans1 = q1 = 0
for q in range(min(m+1, a+b)):
if max1[q1+1][0] == q:
q1 += 1
ans1 += max1[q1+1][1]
if m >= a+b:
ans1 += (m//x+1)*(m % x+1)
m -= m % x+1
p, t = (a+b)//x, (m-a-b)//x
ans1 += (t+1)*(t+2)//2*x
ans1 += p*(t+1)*x
print(ans1)
``` | instruction | 0 | 56,437 | 20 | 112,874 |
Yes | output | 1 | 56,437 | 20 | 112,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
import math
m,a,b=map(int,input().split())
g=math.gcd(a,b)
a1=a//g
b1=b//g
alls=g*(a1+b1-1)
dists=[0]+[-1]*(a1+b1-1)
dist=0
far=0
while dist!=b1:
if dist<b1:
dist+=a1
far=max(dist,far)
else:
dist-=b1
if dists[dist]==-1:
dists[dist]=far
tot=0
for i in range(a1+b1):
if i*g<=m and dists[i]<=m:
tot+=(m+1-dists[i]*g)
if alls<m:
mod=m%g
times=m//g
diff=times-a1-b1
tot1=g*(diff*(diff+1)//2)+(mod+1)*(diff+1)
tot+=tot1
print(tot)
``` | instruction | 0 | 56,438 | 20 | 112,876 |
No | output | 1 | 56,438 | 20 | 112,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
import math
M, A, B = map(int, input().split())
bound = [2*10**9]*(A + B)
l, r = 0, 0
while True:
bound[l] = r
if l >= B:
l -= B
else:
l += A
r = max(r, l)
if l == 0:
break
ans = 0
for i in range(0, A + B):
if bound[i] <= M:
ans += M - bound[i] + 1
rem = M - (A + B) + 1
if M >= (A + B):
g = math.gcd(A, B)
up = (rem // g) * g
lo = rem - up
cnt = up // g + 1
ans += (up + lo) * cnt // 2
print(ans)
``` | instruction | 0 | 56,439 | 20 | 112,878 |
No | output | 1 | 56,439 | 20 | 112,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
m,a,b=map(int,input().split())
sum=0
_f=dict()
def compute_f(x,a,b):
visited=set()
h=[0]
visited.add(0)
while h:
v=h.pop(0)
n1=v+a
n2=v-b
try: # using dynaminc programming
visited=visited.union(_f[n1])
except:
if n1 not in visited and n1<=x:
h.append(n1)
visited.add(n1)
try: # using dynaminc programming
visited=visited.union(_f[n2])
except:
if n2 not in visited and n2>0:
h.append(n2)
visited.add(n2)
_f[x]=visited
return len(visited)
for i in range(m+1):
val=compute_f(i,a,b)
#print("f("+str(i)+")="+str(val))
#print("_f=",_f)
sum+=val
print(sum)
``` | instruction | 0 | 56,440 | 20 | 112,880 |
No | output | 1 | 56,440 | 20 | 112,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b.
Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from 0.
Given an integer m, find ∑_{i=0}^{m} f(i). That is, find the sum of all f(i) for i from 0 to m.
Input
The first line contains three integers m, a, b (1 ≤ m ≤ 10^9, 1 ≤ a,b ≤ 10^5).
Output
Print a single integer, the desired sum.
Examples
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
Note
In the first example, we must find f(0)+f(1)+…+f(7). We have f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8. The sum of these values is 19.
In the second example, we have f(i) = i+1, so we want to find ∑_{i=0}^{10^9} i+1.
In the third example, the frog can't make any jumps in any case.
Submitted Solution:
```
m,a,b = map(int, input().strip().split())
l = []
mxx = max(a,b)
def gcd(a,b):
mn = min(a,b)
mx = max(a,b)
if mx%mn == 0:
return mn
else:
return gcd(mn,mx%mn)
l = [True]
totans = 1
ans = [1]
def backwards(l,k):
k = k-b
while k > 0:
if l[k] == False:
l[k] = True
ans[0] += 1
n = k + a
while(n < len(l)):
if l[n] == False:
l[n] = True
ans[0] += 1
backwards(l,n)
else:
break
n = n + a
else:
break
k = k-b
for i in range(1,min(2*mxx,m)+1):
l.append(False)
if i >= a:
if l[-1-a] == True:
l[-1] = True
ans[0] += 1
backwards(l,i)
totans += ans[0]
if m > 2*mxx:
g = gcd(a,b)
firstn = (2*mxx+1)//g + 1
lastn = m//g + 1
num = (2*mxx + 1) %g
num - g - num
totans += num*(firstn)
num = m%g + 1
totans += num *lastn
endpta = firstn + 1
endptb = lastn -1
if endpta <= endptb:
num = (endpta+endptb)*(endptb + 1 - endpta)/2
totans += g*num
print(totans)
``` | instruction | 0 | 56,441 | 20 | 112,882 |
No | output | 1 | 56,441 | 20 | 112,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There was once young lass called Mary,
Whose jokes were occasionally scary.
On this April's Fool
Fixed limerick rules
Allowed her to trip the unwary.
Can she fill all the lines
To work at all times?
On juggling the words
Right around two-thirds
She nearly ran out of rhymes.
Input
The input contains a single integer a (4 ≤ a ≤ 998). Not every integer in the range is a valid input for the problem; you are guaranteed that the input will be a valid integer.
Output
Output a single number.
Examples
Input
35
Output
57
Input
57
Output
319
Input
391
Output
1723 | instruction | 0 | 56,524 | 20 | 113,048 |
Tags: *special, math, number theory
Correct Solution:
```
import sys
a = int(input())
for i in range(2, a):
if a % i == 0:
print(str(i) + str(a // i))
sys.exit(0)
``` | output | 1 | 56,524 | 20 | 113,049 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.