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 |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,879 | 20 | 109,758 |
Tags: brute force, implementation
Correct Solution:
```
s = input()
a,b = s.count('4'),s.count('7')
if a==b and a==0:
print(-1)
elif a>=b:
print(4)
else:
print(7)
``` | output | 1 | 54,879 | 20 | 109,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,880 | 20 | 109,760 |
Tags: brute force, implementation
Correct Solution:
```
n=input()
m={
'4':0,
'7':0
}
for i in n:
if i in m:
m[i]+=1
if m['4']==0 and m['7']==0:
print(-1)
else:
if m['4']==m['7'] or m['4']>=m['7'] :
print(4)
else:
print(7)
``` | output | 1 | 54,880 | 20 | 109,761 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,881 | 20 | 109,762 |
Tags: brute force, implementation
Correct Solution:
```
n=list(input())
a,b=0,0
for i in n:
if i=="4":
a+=1
elif i=="7":
b+=1
if(a==b==0):
print("-1")
elif(a>=b):
print(4)
else:
print(7)
``` | output | 1 | 54,881 | 20 | 109,763 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,882 | 20 | 109,764 |
Tags: brute force, implementation
Correct Solution:
```
n = input()
if "4" in n and "7" not in n:
print(4)
elif "7" in n and "4" not in n:
print(7)
elif "4" and "7" not in n:
print(-1)
else:
if n.count("4")==n.count("7") or n.count("4")>n.count("7"):
print("4")
else:print("7")
``` | output | 1 | 54,882 | 20 | 109,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,883 | 20 | 109,766 |
Tags: brute force, implementation
Correct Solution:
```
s=input().strip()
n=len(s)
flag=0
for i in range(len(s)):
if(int(s[i]) == 4 or int(s[i]) == 7):
flag=1
break
if(flag == 0):
print(-1)
else:
c=0
c1=0
for i in range(len(s)):
if(int(s[i]) == 4):
c+=1
elif(int(s[i]) == 7):
c1+=1
if(c >= c1):
print(4)
else:
print(7)
``` | output | 1 | 54,883 | 20 | 109,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7". | instruction | 0 | 54,884 | 20 | 109,768 |
Tags: brute force, implementation
Correct Solution:
```
def main(s):
fours = len(list(filter(lambda c: c == '4', s)))
sevens = len(list(filter(lambda c: c == '7', s)))
if fours == 0 and sevens == 0:
return -1
if fours >= sevens:
return "4"
else:
return "7"
print(main(list(input())))
``` | output | 1 | 54,884 | 20 | 109,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
s = str(input())
#a = list(map(int,input().split()))
n = len(s)
i = 0
k4 = 0
k7 = 0
while i < n:
if s[i] == '4':
k4 = k4 + 1
if s[i] == '7':
k7 = k7 + 1
i = i +1
if (k7 == 0 and k4 == 0):
print(-1)
else:
if k7 > k4:
print(7)
else:
print(4)
``` | instruction | 0 | 54,885 | 20 | 109,770 |
Yes | output | 1 | 54,885 | 20 | 109,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
#from dust i have come dust i will be
n=input()
f=0
s=0
for i in range(len(n)):
if n[i]=='4':
f+=1
elif n[i]=='7':
s+=1
if f==0 and s==0:
print(-1)
else:
if s>f:
print(7)
else:
print(4)
``` | instruction | 0 | 54,886 | 20 | 109,772 |
Yes | output | 1 | 54,886 | 20 | 109,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
s=input()
cnt1=0
cnt2=0
for i in s:
if i is '4':
cnt1=cnt1+1
if i is '7':
cnt2=cnt2+1
if cnt1 is 0 and cnt2 is 0:
print(-1)
else:
print(4 if cnt1>=cnt2 else 7)
``` | instruction | 0 | 54,887 | 20 | 109,774 |
Yes | output | 1 | 54,887 | 20 | 109,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
def main():
s=list(input())
z,f=0,0
for char in s:
if char=='4':
f+=1
elif char=='7':
z+=1
if f>z:
print(4)
elif z>f:
print(7)
else:
if z:
print(4)
else:
print(-1)
#----------------------------------------------------------------------------------------
def nouse0():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse1():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse2():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
def nouse3():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse4():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
def nouse5():
# This is to save my code from plag due to use of FAST IO template in it.
a=420
b=420
print(f'i am nitish{(a+b)//2}')
# endregion
if __name__ == '__main__':
main()
``` | instruction | 0 | 54,888 | 20 | 109,776 |
Yes | output | 1 | 54,888 | 20 | 109,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
l=list(input())
r=l.count("7")
y=l.count("4")
if r>0 and y>0:
if r>y:
print("7")
else:
print("4")
else:
print(-1)
``` | instruction | 0 | 54,889 | 20 | 109,778 |
No | output | 1 | 54,889 | 20 | 109,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
from collections import Counter
s=input()
l1=list(Counter(list(s)).values())
l2=list(Counter(list(s)).keys())
c=max(l1)
ans=8
for i in range(len(l1)):
if l1[i]==c and int(l2[i]) in [4,7] and int(l2[i])<ans:
ans=int(l2[i])
if ans==8:
print(-1)
else:
print(ans)
``` | instruction | 0 | 54,890 | 20 | 109,780 |
No | output | 1 | 54,890 | 20 | 109,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
from collections import Counter
s = str(input())
d = dict(Counter(s))
try:
if d['4'] >= d['7']:
print('4')
else:
print('7')
except KeyError:
print('-1')
``` | instruction | 0 | 54,891 | 20 | 109,782 |
No | output | 1 | 54,891 | 20 | 109,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was delivered a string s, containing only digits. He needs to find a string that
* represents a lucky number without leading zeroes,
* is not empty,
* is contained in s as a substring the maximum number of times.
Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
Output
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
Examples
Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.
In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".
In the second sample s has no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7".
Submitted Solution:
```
s=input()
c,d=0,0
for i in s:
if i=="4":
c+=1
elif i=="7":
d+=1
if c>d:
print("4")
elif d>c:
print("7")
elif d==c and d!=0:
print("7")
else:
print("-1")
``` | instruction | 0 | 54,892 | 20 | 109,784 |
No | output | 1 | 54,892 | 20 | 109,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 54,997 | 20 | 109,994 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
import sys
input=sys.stdin.readline
a,b,k=map(int,input().split())
if a==0 or b==1 :
if k==0 :
print("YES")
for i in range(b) :
print(1,end="")
for i in range(a) :
print(0,end="")
print()
for i in range(b) :
print(1,end="")
for i in range(a) :
print(0,end="")
print()
else :
print("NO")
else :
if k>b-1+a-1 :
print("NO")
else :
print("YES")
for i in range(b) :
print(1,end="")
for i in range(a) :
print(0,end="")
print()
if k<=a :
for i in range(b-1) :
print(1,end="")
for i in range(k) :
print(0,end="")
print(1,end="")
for i in range(a-k):
print(0,end="")
print()
else :
for i in range(a+b-k-1) :
print(1,end="")
print(0,end="")
for i in range(k-a) :
print(1,end="")
for i in range(a-1) :
print(0,end="")
print(1)
``` | output | 1 | 54,997 | 20 | 109,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 54,998 | 20 | 109,996 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a, b, k = map(int, input().split())
if a >= k and b > 1:
print("YES")
for i in range(b - 1):
print(1, end='')
for i in range(a - k):
print(0, end='')
print(1, end='')
for i in range(k):
print(0, end='')
print()
for i in range(b - 1):
print(1, end='')
for i in range(a):
print(0, end='')
print(1, end='')
elif a + b - 2 >= k and a > 0 and b > 1:
print("YES")
for i in range(b):
print(1, end='')
for i in range(a):
print(0, end='')
print()
print(1, end='')
for i in range(b - 2 - (k - a)):
print(1, end='')
print(0, end='')
for i in range(k - a):
print(1, end='')
for i in range(a - 1):
print(0, end='')
print(1, end='')
elif k == 0:
print("YES")
for i in range(b):
print(1, end='')
for i in range(a):
print(0, end='')
print()
for i in range(b):
print(1, end='')
for i in range(a):
print(0, end='')
else:
print("NO")
``` | output | 1 | 54,998 | 20 | 109,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 54,999 | 20 | 109,998 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a,b,k=map(int,input().split())
n=a+b
if k==n:
print("no")
elif k==0:
print("yes")
s=["1"]*(b)+["0"]*(a)
print("".join(s))
print("".join(s))
elif a==0:
print("no")
elif k==n-1:
print('no')
else:
if (k+1)<=b:
print("yes")
res1=["1"]+["1"]*(k)+["0"]+["1"]*(b-(k+1))+["0"]*(a-1)
res2=["1","0"]+["1"]*(k)+["1"]*(b-(k+1))+["0"]*(a-1)
print("".join(res1))
print("".join(res2))
#print(bin(int("".join(res1[::-1]), 2) - int("".join(res2),2)).count("1"))
else:
if b==1:
print('No')
else:
print("yes")
res1=["0"]+["1"]*(b-2)+["0"]*(k-b+1)+["1"]+["0"]*(n-k-2)+["1"]
res2=["1"]*(b-1)+["0"]*(a)+["1"]
print("".join(res1[::-1]))
print("".join(res2[::-1]))
#print(bin(int("".join(res1[::-1]),2)-int("".join(res2[::-1]),2)).count("1"))
``` | output | 1 | 54,999 | 20 | 109,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 55,000 | 20 | 110,000 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a,b,k=map(int,input().split());
if a==k==0 and b==1:
print("Yes");
print(1);
print(1);
elif k>(a+b-2) or (b==1 and k>0) or (a==0 and k>0):
print("No");
elif k==0:
sa='1';
sb='1';
b-=1;
while(b):
sa+='1';
sb+='1';
b-=1;
while(a):
sa+='0';
sb+='0';
a-=1;
print("Yes");
print(sa);
print(sb);
else:
sa='1';
sb='1';
b-=1;
sa+='1';
sb+='0';
k-=1;
b-=1;
a-=1;
ss='0'*a + '1'*b;
sa+=ss[:k]+'0'+ss[k:];
sb+=ss[:k]+'1'+ss[k:];
print("Yes");
print(sa);
print(sb);
``` | output | 1 | 55,000 | 20 | 110,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 55,001 | 20 | 110,002 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a, b, k = map(int, input().strip().split())
if k == 0:S = "1"*b + "0"*a;print("Yes\n"+S+"\n"+S)
elif a == 0 or b == 1:print("No")
else:
if k <= a+b-2:S = "1"*(b-1) + "0"*(a-1);print(f"Yes\n{S[:a+b-k-1]}1{S[a+b-k-1:]}0\n{S[:a+b-k-1]}0{S[a+b-k-1:]}1")
else:print("No")
``` | output | 1 | 55,001 | 20 | 110,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 55,002 | 20 | 110,004 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
inf = 10**16
md = 10**9+7
# md = 998244353
a, b, k = MI()
if a == 0:
if k == 0:
print("Yes")
s = "1"*b
print(s)
print(s)
else:
print("No")
exit()
if b == 1:
if k == 0:
print("Yes")
s = "1"+"0"*a
print(s)
print(s)
else:
print("No")
exit()
if k > a+b-2:
print("No")
exit()
s = [1]*b+[0]*a
t = [1]*b+[0]*a
cur = min(k, a)
t[b-1] = 0
t[b-1+cur] = 1
i = b-2
for _ in range(k-cur):
t[i] = 0
t[i+1] = 1
i -= 1
print("Yes")
print(*s, sep="")
print(*t, sep="")
# def to10(aa):
# res=0
# base=1
# for a in aa[::-1]:
# res+=a*base
# base*=2
# return res
#
# ans=to10(s)-to10(t)
# print(bin(ans)[2:])
``` | output | 1 | 55,002 | 20 | 110,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 55,003 | 20 | 110,006 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a, b, k = map(int, input().split())
b -= 1
if a == 0:
if k == 0:
x = '1'*b
y = '1'*b
else:
x = None
y = None
elif b == 0:
if k == 0:
x = '0'*a
y = '0'*a
else:
x = None
y = None
else:
if k >= a+b:
x = None
y = None
else:
if k <= b:
x = '0'*(a-1) + '1'*k + '0' + '1'*(b-k)
y = '0'*a+'1'*b
else:
x = '0'*(a+b-1-k) + '1' + '0'*(k-b) + '1'*(b-1) + '0'
y = '0'*a+'1'*b
if x is None:
print("No")
else:
print("Yes")
x = '1'+x
y = '1'+y
print(x)
print(y)
``` | output | 1 | 55,003 | 20 | 110,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three integers a, b, k.
Find two binary integers x and y (x ≥ y) such that
1. both x and y consist of a zeroes and b ones;
2. x - y (also written in binary form) has exactly k ones.
You are not allowed to use leading zeros for x and y.
Input
The only line contains three integers a, b, and k (0 ≤ a; 1 ≤ b; 0 ≤ k ≤ a + b ≤ 2 ⋅ 10^5) — the number of zeroes, ones, and the number of ones in the result.
Output
If it's possible to find two suitable integers, print "Yes" followed by x and y in base-2.
Otherwise print "No".
If there are multiple possible answers, print any of them.
Examples
Input
4 2 3
Output
Yes
101000
100001
Input
3 2 1
Output
Yes
10100
10010
Input
3 2 5
Output
No
Note
In the first example, x = 101000_2 = 2^5 + 2^3 = 40_{10}, y = 100001_2 = 2^5 + 2^0 = 33_{10}, 40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}. Hence x-y has 3 ones in base-2.
In the second example, x = 10100_2 = 2^4 + 2^2 = 20_{10}, y = 10010_2 = 2^4 + 2^1 = 18, x - y = 20 - 18 = 2_{10} = 10_{2}. This is precisely one 1.
In the third example, one may show, that it's impossible to find an answer. | instruction | 0 | 55,004 | 20 | 110,008 |
Tags: bitmasks, constructive algorithms, greedy, math
Correct Solution:
```
a, b, k = map(int,input().split())
if b==1:
if k==0:
print("Yes")
print('1'+'0'*a)
print('1'+'0'*a)
else:
print("No")
elif a==0:
if k==0:
print("Yes")
print('1'*b)
print('1'*b)
else:
print("No")
elif k <= a:
print("Yes")
LCP = (a-k)*'0'+(b-2)*'1'
zer = '0'*k
print('1'+LCP+'1'+zer)
print('1'+LCP+zer+'1')
elif a < k < a+b-1:
print("Yes")
n = k-a
m = b-1-n
print('1'*b+'0'*a)
print('1'*m+'0'+'1'*n+'0'*(a-1)+'1')
else:
print("No")
``` | output | 1 | 55,004 | 20 | 110,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,077 | 20 | 110,154 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0]!=0:
print(-1)
exit()
s = sum(a)%3
if s!=0:
b = next((i for i, v in enumerate(a) if v%3==s), None)
if b is None:
del a[next((i for i, v in enumerate(a) if v%3==3-s), None)]
del a[next((i for i, v in enumerate(a) if v%3==3-s), None)]
else:
del a[b]
a.reverse()
if a[0]==0:
print(0)
else:
print(''.join(map(str,a)))
``` | output | 1 | 55,077 | 20 | 110,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,078 | 20 | 110,156 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq
#sys.setrecursionlimit(300000)
#^^^TAKE CARE FOR MEMORY LIMIT^^^
def main():
pass
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
def countcon(s, i):
c = 0
ch = s[i]
for i in range(i, len(s)):
if (s[i] == ch):
c += 1
else:
break
return (c)
def lis(arr):
n = len(arr)
lis = [1] * n
for i in range(1, n):
for j in range(0, i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
lis[i] = lis[j] + 1
maximum = 0
for i in range(n):
maximum = max(maximum, lis[i])
return maximum
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0
i = 0
while j < m and i < n:
if str1[j] == str2[i]:
j = j + 1
i = i + 1
return j == m
def maxfac(n):
root = int(n ** 0.5)
for i in range(2, root + 1):
if (n % i == 0):
return (n // i)
return (n)
def p2(n):
c=0
while(n%2==0):
n//=2
c+=1
return c
def seive(n):
primes=[True]*(n+1)
primes[1]=primes[0]=False
for i in range(2,n+1):
if(primes[i]):
for j in range(i+i,n+1,i):
primes[j]=False
p=[]
for i in range(0,n+1):
if(primes[i]):
p.append(i)
return(p)
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def denofactinverse(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return (pow(fac,m-2,m))
def numofact(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return(fac)
def getPos(l,m):
for i in range(n-1,-1,-1):
if(l[i]%3==m):
return [i]
m=3-m
rv=[]
for i in range(n-1,-1,-1):
if(l[i]%3==m):
rv.append(i)
if(len(rv)==2):
break
if(len(rv)==2):
return rv
else:
return [-1]
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
if(l[-1]!=0):
print(-1)
else:
su=sum(l)%3
#print(su)
if(su==0):
l=list(map(str,l))
if(l[0]=="0"):
l=["0"]
print("".join(l))
else:
pos=getPos(l,su)
#print(pos)
if(pos==[-1]):
print(-1)
else:
#print("HEY")
l=list(map(str,l))
if(len(pos)==1):
l=l[:pos[0]]+l[pos[0]+1:]
else:
pos1=pos[0]
pos2=pos[1]
l=l[:pos2]+l[pos2+1:pos1]+l[pos1+1:]
if(l[0]=="0"):
l=["0"]
print("".join(l))
``` | output | 1 | 55,078 | 20 | 110,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,079 | 20 | 110,158 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
if d.get(0):
d[0] -= 1
s = sum(a)
if s % 3 == 1:
b = False
for elem in [1, 4, 7]:
if d.get(elem):
b = True
d[elem] -= 1
s -= elem
break
if not b:
for elem in [2, 5, 8]:
if d.get(elem):
d[elem] -= 1
s -= elem
break
if s % 3 == 2:
b = False
for elem in [2, 5, 8]:
if d.get(elem):
d[elem] -= 1
s -= elem
b = True
break
if not b:
k = 0
for elem in [1, 4, 7]:
if d.get(elem):
if k < 2:
if d[elem] >= 2:
d[elem] -= 2
s -= 2 * elem
k = 2
elif d[elem] > 0:
d[elem] -= 1
s -= elem
k += 1
else:
break
if s % 3 == 0:
nzero = False
for i in range(9, -1, -1):
if d.get(i):
if i > 0:
if d[i] > 0:
nzero = True
print(str(i) * d[i], end='')
elif nzero:
print(str(i) * d[i], end='')
print(0)
exit()
print(-1)
``` | output | 1 | 55,079 | 20 | 110,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,080 | 20 | 110,160 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst = lambda: list(map(int,input().split()))
for _ in range(1):#nmbr():
n=nmbr()
a=sorted(lst(),reverse=True)
sm=sum(a)
ans=[]
if a[-1]!=0:
print(-1)
continue
r0=[];r1=[];r2=[]
for v in a:
if v%3==0:r0+=[v]
elif v%3==1:r1+=[v]
elif v%3==2:r2+=[v]
if sm%3==0:
for v in a:ans+=[v]
elif sm%3==1:
time=0
rem=rem1=rem2=-1
if r1:
rem=r1[-1]
time=1
elif len(r2)>=2:
rem1=r2[-1]
rem2=r2[-2]
time=2
if time==0:
print(-1)
continue
if time==1:
r1.pop()
else:
r2.pop()
r2.pop()
for v in r0:ans+=[v]
for v in r1:ans+=[v]
for v in r2:ans+=[v]
elif sm%3==2:
time=0
rem=rem1=rem2=-1
if r2:
rem=r2[-1]
time=1
elif len(r1)>=2:
rem1=r1[-1]
rem2=r1[-2]
time=2
if time==0:
print(-1)
continue
if time==1:
r2.pop()
else:
r1.pop()
r1.pop()
for v in r0:ans+=[v]
for v in r1:ans+=[v]
for v in r2:ans+=[v]
if ans[0]==ans[-1]==0:print(0)
else:
for v in sorted(ans,reverse=True):stdout.write(str(v))
``` | output | 1 | 55,080 | 20 | 110,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,081 | 20 | 110,162 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
def diminish(count, k):
for d in range(k, 10, 3):
if count[d] > 0:
count[d] -= 1
return True
return False
def solve(count, sum):
if sum%3 == 1:
if not diminish(count, 1):
if not diminish(count, 2) or not diminish(count, 2):
print(0)
return
elif sum%3 == 2:
if not diminish(count, 2):
if not diminish(count, 1) or not diminish(count, 1):
print(0)
return
max = 0
for d in range(1, 10):
if count[d] > 0:
max = d
if max == 0:
print(0)
return
digits = []
for d in range(9, -1, -1):
for i in range(count[d]):
digits.append(str(d))
print(''.join(digits))
n = int(input())
digits = [int(s) for s in input().split()]
count = { d: 0 for d in range(0, 10) }
for d in digits:
count[d] += 1
if count[0] == 0:
print(-1)
else:
solve(count, sum(digits))
``` | output | 1 | 55,081 | 20 | 110,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,082 | 20 | 110,164 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
def vyvod(sp):
if set(sp)=={0}:
print(0)
exit()
sp.sort(reverse=True)
for i in sp:
print(i, end='')
exit()
n=int(input())
sp=list(map(int, input().split()))
d=sum(sp)%3
if sp.count(0)==0:
print(-1)
exit()
if d==0:
vyvod(sp)
elif d==1:
sp.sort()
count2=0
sum1=-1
sum2=[]
for i in sp:
if i%3==1 and sum1==-1:
sum1=i
elif i%3==2 and count2<2:
count2+=1
sum2.append(i)
if sum1==-1 and len(sum2)<2:
print(-1)
elif sum1==-1:
del sp[sp.index(sum2[0])]
del sp[sp.index(sum2[1])]
vyvod(sp)
elif len(sum2)<2:
del sp[sp.index(sum1)]
vyvod(sp)
else:
f=min(sum1, sum(sum2))
if f==sum1:
del sp[sp.index(sum1)]
else:
del sp[sp.index(sum2[0])]
del sp[sp.index(sum2[1])]
vyvod(sp)
else:
sp.sort()
count1=0
sum2=-1
sum1=[]
for i in sp:
if i%3==2 and sum2==-1:
sum2=i
elif i%3==1 and count1<2:
count1+=1
sum1.append(i)
if sum2==-1 and len(sum1)<2:
print(-1)
elif sum2==-1:
del sp[sp.index(sum1[0])]
del sp[sp.index(sum1[1])]
vyvod(sp)
elif len(sum1)<2:
del sp[sp.index(sum2)]
vyvod(sp)
else:
f=min(sum2, sum(sum1))
if f==sum2:
del sp[sp.index(sum2)]
else:
del sp[sp.index(sum1[0])]
del sp[sp.index(sum1[1])]
vyvod(sp)
exit()
``` | output | 1 | 55,082 | 20 | 110,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,083 | 20 | 110,166 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from collections import Counter
input()
tmp=[int(i) for i in input().split()]
d=Counter(tmp)
s=sum(tmp)%3
f=False
if d[0]==0:
print(-1)
else:
if s==2:
if d[2]>0:
d[2]-=1
elif d[5]>0:
d[5]-=1
elif d[8]>0:
d[8]-=1
else:
if d[1]>0:
d[1]-=1
elif d[4]>0:
d[4]-=1
elif d[7]>0:
d[7]-=1
else:
f=True
if d[1]>0:
d[1]-=1
elif d[4]>0:
d[4]-=1
elif d[7]>0:
d[7]-=1
else:
f=True
elif s==1:
if d[1]>0:
d[1]-=1
elif d[4]>0:
d[4]-=1
elif d[7]>0:
d[7]-=1
else:
if d[2]>0:
d[2]-=1
elif d[5]>0:
d[5]-=1
elif d[8]>0:
d[8]-=1
else:
f=True
if d[2]>0:
d[2]-=1
elif d[5]>0:
d[5]-=1
elif d[8]>0:
d[8]-=1
else:
f=True
if f:
print(0)
else:
k=("".join([str(i)*d[i] for i in reversed(sorted(d.keys()))]))
if k[0]=="0":
print("0")
else:
print(k)
``` | output | 1 | 55,083 | 20 | 110,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number. | instruction | 0 | 55,084 | 20 | 110,168 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
def s():
input()
a = list(map(int,input().split()))
a.sort(reverse = True)
if a[-1] == 0:
r = sum(a) % 3
if r == 0:
if a[0] > 0:print(*a,sep = '')
else:print(0)
else:
for i,v in reversed(list(enumerate(a))):
if v%3 == r:
a.pop(i)
if a[0] > 0:print(*a,sep = '')
else:print(0)
break
else:
c = 0
for i,v in reversed(list(enumerate(a))):
if v%3 == 3 - r:
c+=1
a.pop(i)
if c == 2:
if a[0] > 0:print(*a,sep = '')
else:print(0)
break
else:
print(-1)
else:
print(-1)
s()
``` | output | 1 | 55,084 | 20 | 110,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
n=int(input())
l=list(map(int,input().split()))
a=[[],[],[]]
l.sort()
if l[0]!=0:
print(-1)
exit()
else:
for i in l:a[i%3].append(i)
if sum(l)%3==1:
if len(a[1])>=1:
a[1].pop(0)
elif len(a[2])>=2:
a[2].pop(0)
a[2].pop(0)
if sum(l)%3==2:
if len(a[2])>=1:
a[2].pop(0)
elif len(a[1])>=2:
a[1].pop(0)
a[1].pop(0)
ans=''
for i in a:
for j in i:
ans+=str(j)
ans=sorted(ans,reverse=True)
ans=''.join(ans)
if int(ans)==0:
print(0)
else:
string=''
for i in ans:
string+=i
print(string)
``` | instruction | 0 | 55,085 | 20 | 110,170 |
Yes | output | 1 | 55,085 | 20 | 110,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
n=int(input())
arr=list(map(int,input().split()))
a=[[],[],[]]
c0=0
s=0
for i in arr:
s+=i
if i==0:
c0+=1
a[i%3].append(i)
if not c0:
print(-1)
exit()
a[0].sort(reverse=True)
a[1].sort(reverse=True)
a[2].sort(reverse=True)
inc=[]
if s%3:
if len(a[s%3]):
a[s%3].pop()
elif len(a[3-s%3])>=2:
a[3-s%3].pop()
a[3-s%3].pop()
elif len(a[0]):
print(int(''.join(map(str,a[0]))))
else:
print(-1)
exit()
inc+=a[0]
inc+=a[1]
inc+=a[2]
inc.sort(reverse=True)
print(int(''.join(map(str,inc))))
``` | instruction | 0 | 55,086 | 20 | 110,172 |
Yes | output | 1 | 55,086 | 20 | 110,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
"""
Template written to be used by Python Programmers.
Use at your own risk!!!!
Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
arr.sort()
# If all 0 elements.
if arr.count(0) == n:
outln(0)
exit()
# If 0 not present.
if arr.count(0) == 0:
outln(-1)
exit()
dp = dd(list)
for i in arr:
dp[i % 3].append(i)
s = sum(arr)
if s % 3 == 2:
if len(dp[2]) > 0:
arr.remove(dp[2][0])
elif len(dp[1]) > 1:
arr.remove(dp[1][0])
arr.remove(dp[1][1])
elif s % 3 == 1:
if len(dp[1]) > 0:
arr.remove(dp[1][0])
elif len(dp[2]) > 1:
arr.remove(dp[2][0])
arr.remove(dp[2][1])
s = sum(arr)
if s % 3 == 0 and s > 0:
arr.sort(reverse=True)
outln(''.join(map(str, arr)))
exit()
outln(0)
``` | instruction | 0 | 55,087 | 20 | 110,174 |
Yes | output | 1 | 55,087 | 20 | 110,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
n=I()
a=L()
a.sort()
cnt=sum([a[i]==0 for i in range(n)])
if cnt==n:
print('0')
exit()
if a[0]!=0:
print('-1')
exit()
dp=[0]*3
for i in range(3):
dp[i]=[0]*(n+1)
dp[1][0]=-1
dp[2][0]=-1
for i in range(n):
for j in range(3):
dp[j][i+1]=dp[j][i]
r=(j-a[i])%3
if dp[r][i]>=0 and dp[j][i+1]<dp[r][i]+1:
dp[j][i+1]=dp[r][i]+1
j=0
if dp[0][n]==0:
print('-1')
exit()
ans=''
for i in range(n,0,-1):
r=(j-a[i-1])%3
if dp[j][i]==dp[r][i-1]+1:
cnt+=1
ans+=str(a[i-1])
j=r
i=0
while i<len(ans) and ans[i]=='0': i+=1
if i==len(ans):
print('0')
else:
print(ans[i:])
``` | instruction | 0 | 55,088 | 20 | 110,176 |
Yes | output | 1 | 55,088 | 20 | 110,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
# from sys import stdin,stdout
# input = stdin.readline
# print = stdout.write
from math import *
n=int(input())
ar=list(map(int,input().split()))
ans=[]
d={}
for i in range(n):
if(d.get(ar[i])==None):
d[ar[i]]=1
else:
d[ar[i]]+=1
# print(d)
if(d.get(0)==None):
print(-1)
else:
ans=""
for i in range(1,10):
if(d.get(i)!=None):
a=d[i]
if(i%3==0):
ans=str(i)*a+ans
else:
ans=str(i)*(a - a%3)+ans
if(ans==""):
print(0)
else:
ans+="0"*d[0]
print(ans)
``` | instruction | 0 | 55,089 | 20 | 110,178 |
No | output | 1 | 55,089 | 20 | 110,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
def summod(l):
s = 0
for i in range(len(l)):
s += l[i]
s = s % 3
if s == 1:
if 1 in l:
l.remove(1)
elif 4 in l:
l.remove(4)
elif 7 in l:
l.remove(7)
elif l.count(2) > 1:
l.remove(2)
l.remove(2)
elif 2 in l and 5 in l:
l.remove(2)
l.remove(5)
elif l.count(5) > 1:
l.remove(5)
l.remove(5)
elif 2 in l and 8 in l:
l.remove(2)
l.remove(5)
elif 5 in l and 8 in l:
l.remove(5)
l.remove(8)
else:
l.remove(8)
l.remove(8)
elif s == 2:
if 2 in l:
l.remove(2)
elif 5 in l:
l.remove(5)
elif 8 in l:
l.remove(8)
elif l.count(1) > 1:
l.remove(1)
l.remove(1)
elif 1 in l and 4 in l:
l.remove(1)
l.remove(4)
elif l.count(4) > 1:
l.remove(4)
l.remove(4)
elif 1 in l and 7 in l:
l.remove(1)
l.remove(7)
elif 4 in l and 7 in l:
l.remove(4)
l.remove(7)
else:
l.remove(7)
l.remove(7)
st = ''
for i in range(len(l)):
st += str(l[i])
return st
input()
l = list(map(int,input().split()))
l = list(reversed(sorted(l)))
if 0 not in l:
print(-1)
else:
print(summod(l))
``` | instruction | 0 | 55,090 | 20 | 110,180 |
No | output | 1 | 55,090 | 20 | 110,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
ans = 0
def construct(mult=None):
f2 = freq[:]
a, b, c = mult // 100, (mult // 10) % 10, mult % 10
f2[0] -= 1
if not f2[b]:
return False
f2[b] -= 1
if a and not f2[a]:
return False
if a or f2[a]:
f2[a] -= 1
po = 1000
else:
po = 100
curr = mult
i = 0
while i < 10:
if not f2[i]:
i += 1
continue
curr += po * i
f2[i] -= 1
po *= 10
global ans
ans = max(ans, curr)
n = int(input())
nums = list(map(int, input().split()))
freq = [0 for _ in range(10)]
for x in nums:
freq[x] += 1
if not freq[0]:
print(-1)
exit(0)
for mult in range(0, 300, 30):
construct(mult)
print(ans)
``` | instruction | 0 | 55,091 | 20 | 110,182 |
No | output | 1 | 55,091 | 20 | 110,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.
Each digit is allowed to occur in the number the same number of times it occurs in the set.
Input
A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.
Output
On a single line print the answer to the problem. If such number does not exist, then you should print -1.
Examples
Input
1
0
Output
0
Input
11
3 4 5 4 5 3 5 3 4 4 0
Output
5554443330
Input
8
3 2 5 1 5 2 2 3
Output
-1
Note
In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.
Submitted Solution:
```
def vyvod(sp):
sp.sort(reverse=True)
for i in sp:
print(i, end='')
exit()
n=int(input())
sp=list(map(int, input().split()))
d=sum(sp)%3
if sp.count(0)==0:
print(-1)
exit()
if d==0:
vyvod(sp)
elif d==1:
sp.sort()
count2=0
sum1=-1
sum2=[]
for i in sp:
if i%3==1 and sum1==-1:
sum1=i
elif i%3==2 and count2<2:
count2+=1
sum2.append(i)
if sum1==-1 and len(sum2)<2:
print(-1)
elif sum1==-1:
del sp[sp.index(sum2[0])]
del sp[sp.index(sum2[1])]
vyvod(sp)
elif len(sum2)<2:
del sp[sp.index(sum1)]
vyvod(sp)
else:
f=min(sum1, sum(sum2))
if f==sum1:
del sp[sp.index(sum1)]
else:
del sp[sp.index(sum2[0])]
del sp[sp.index(sum2[1])]
vyvod(sp)
else:
sp.sort()
count1=0
sum2=-1
sum1=[]
for i in sp:
if i%3==2 and sum2==-1:
sum2=i
elif i%3==1 and count1<2:
count1+=1
sum1.append(i)
if sum2==-1 and len(sum1)<2:
print(-1)
elif sum2==-1:
del sp[sp.index(sum1[0])]
del sp[sp.index(sum1[1])]
vyvod(sp)
elif len(sum1)<2:
del sp[sp.index(sum2)]
vyvod(sp)
else:
f=min(sum2, sum(sum1))
if f==sum2:
del sp[sp.index(sum2)]
else:
del sp[sp.index(sum1[0])]
del sp[sp.index(sum1[1])]
vyvod(sp)
exit()
``` | instruction | 0 | 55,092 | 20 | 110,184 |
No | output | 1 | 55,092 | 20 | 110,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
Input
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Output
Print a single number — the answer to the problem.
Examples
Input
3 2
-1 1 2
Output
1
Input
2 3
-2 -2
Output
2
Note
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | instruction | 0 | 55,130 | 20 | 110,260 |
Tags: implementation, math
Correct Solution:
```
import math
n,x = map(int,input().split())
a = abs(sum(list(map(int,input().split()))))
print(int(math.ceil(a/x)))
``` | output | 1 | 55,130 | 20 | 110,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
Input
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Output
Print a single number — the answer to the problem.
Examples
Input
3 2
-1 1 2
Output
1
Input
2 3
-2 -2
Output
2
Note
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | instruction | 0 | 55,132 | 20 | 110,264 |
Tags: implementation, math
Correct Solution:
```
import math
st=[int(i) for i in input().split(" ")]
n=st[0]
x=st[1]
s=0
a=[int(n) for n in input().split(" ")]
for i in range(len(a)):
s+=a[i]
k=(math.ceil(abs(s)/abs(x)))
print(k)
``` | output | 1 | 55,132 | 20 | 110,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
Input
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Output
Print a single number — the answer to the problem.
Examples
Input
3 2
-1 1 2
Output
1
Input
2 3
-2 -2
Output
2
Note
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | instruction | 0 | 55,135 | 20 | 110,270 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
s = abs(sum([int(i) for i in input().split()]))
print((s + k - 1) // k)
# Mon Aug 12 2019 15:00:31 GMT+0300 (MSK)
``` | output | 1 | 55,135 | 20 | 110,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,865 | 20 | 111,730 |
Tags: binary search, brute force, implementation
Correct Solution:
```
import bisect
def binarySearch3(lst,x):
i = bisect.bisect_left(lst,x)
if i != len(lst) and lst[i] == x:
return i
return -1
if __name__ == '__main__':
n=int(input())
a=[i*(i+1)//2 for i in range(1,1000000)]
for i in a:
if binarySearch3(a,n-i)!=-1:
print("YES")
exit(0)
if n-i<0:
break
print("NO")
``` | output | 1 | 55,865 | 20 | 111,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,866 | 20 | 111,732 |
Tags: binary search, brute force, implementation
Correct Solution:
```
def check_number( arr, no ) :
i = 0
j = len( arr ) - 1
while i <= j :
if arr[i] + arr[j] == no :
return "YES"
elif arr[i] + arr[j] > no :
j -= 1
else :
i += 1
return "NO"
def check_funky( n ) :
i = 1
arr = []
while i * ( i + 1 ) // 2 <= 10 ** 9 :
arr.append(i * ( i + 1 ) // 2)
i += 1
return check_number( arr, n )
if __name__ == "__main__" :
n = int(input())
print(check_funky( n ))
``` | output | 1 | 55,866 | 20 | 111,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,867 | 20 | 111,734 |
Tags: binary search, brute force, implementation
Correct Solution:
```
def binarySearch(arr, l, r, x):
while l <= r:
mid = int(l + (r - l)/2);
if arr[mid] == x:
return True
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return False
max = 100000 + 1
n = int(input())
array = [0 for k in range(max)]
array[0] = 0
found = False
for i in range(1,max):
array[i] = array[i-1]+i
for i in range(1,max):
if(binarySearch(array,1,max,n-array[i])):
print("YES")
found = True
break
if not found:
print("NO")
``` | output | 1 | 55,867 | 20 | 111,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,868 | 20 | 111,736 |
Tags: binary search, brute force, implementation
Correct Solution:
```
#_________________ Mukul Mohan Varshney _______________#
#Template
import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt,floor,factorial,gcd,log,ceil
from collections import deque,Counter,defaultdict
from itertools import permutations, combinations
import itertools
#define function
def Int(): return int(sys.stdin.readline())
def Mint(): return map(int,sys.stdin.readline().split())
def Lstr(): return list(sys.stdin.readline().strip())
def Str(): return sys.stdin.readline().strip()
def Mstr(): return map(str,sys.stdin.readline().strip().split())
def List(): return list(map(int,sys.stdin.readline().split()))
def Hash(): return dict()
def Mod(): return 1000000007
def Ncr(n,r,p): return ((fact[n])*((ifact[r]*ifact[n-r])%p))%p
def Most_frequent(list): return max(set(list), key = list.count)
def Mat2x2(n): return [List() for _ in range(n)]
def Lcm(x,y): return (x*y)//gcd(x,y)
def dtob(n): return bin(n).replace("0b","")
def btod(n): return int(n,2)
def common(l1, l2):
return set(l1).intersection(l2)
# Driver Code
def solution():
#for _ in range(Int()):
n=Int()
t=[]
p=0
i=1
while(1):
a=(i*(i+1))//2
if(a>=n):
break
t.append(a)
if n-a in t:
print("YES")
break
else:
p+=1
i+=1
if(p==len(t)):
print("NO")
#Call the solve function
if __name__ == "__main__":
solution()
``` | output | 1 | 55,868 | 20 | 111,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,869 | 20 | 111,738 |
Tags: binary search, brute force, implementation
Correct Solution:
```
arr=[1]*(10**5)
d={}
for i in range(1,10**5):
arr[i]=(i)*(i+1)//2
d[arr[i]]=1
n=int(input())
for i in arr:
a=i
b=n-i
if(b<=0):
break
if(b in d):
print("YES")
exit()
print("NO")
``` | output | 1 | 55,869 | 20 | 111,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,870 | 20 | 111,740 |
Tags: binary search, brute force, implementation
Correct Solution:
```
n = int(input())
fn = []
k=1
while True:
num = (k*(k+1))//2
if num>n:
break
fn.append(num)
k+=1
i=0
j=len(fn)-1
while i<=j:
if fn[i]+fn[j]==n:
print("YES")
break
elif fn[i]+fn[j]<n:
i+=1
else:
j-=1
if i>j or fn[i]+fn[j]!=n:
print("NO")
``` | output | 1 | 55,870 | 20 | 111,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,871 | 20 | 111,742 |
Tags: binary search, brute force, implementation
Correct Solution:
```
import math
from bisect import bisect_left
def BinarySearch(a, x):
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
else:
return -1
n=int(input())
possible_nums = []
i=1
a = 0
while a<=n:
a = (math.pow(i,2)+i)/2
if(a<=n):
possible_nums.append(a)
i+=1
possible = 0
for a in possible_nums:
diff = n-a
i = BinarySearch(possible_nums,diff)
if i>=0:
print("YES")
possible = 1
break
else:
continue
if not possible:
print("NO")
``` | output | 1 | 55,871 | 20 | 111,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 55,872 | 20 | 111,744 |
Tags: binary search, brute force, implementation
Correct Solution:
```
import math
funk = []
n = int(input())
for i in range(2*int(math.sqrt(n))+1):
funk.append(i*(i+1)// 2)
i = 1
j = len(funk) - 1
while j >= i:
if funk[i] + funk[j] > n:
j -= 1
elif funk[i] + funk[j] < n:
i += 1
else:
print("YES")
exit()
print("NO")
``` | output | 1 | 55,872 | 20 | 111,745 |
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
def fun(n):
return (n*(n+1)/2)
n = int(input())
j = int(pow(n*2,0.5))
arr = [fun(i) for i in range(j+1)]
i=1
while(i<=j):
a = arr[j]+arr[i]
if(a==n):
print("YES")
break
elif(a<n):
i+=1
elif(a>n):
j-=1
else:
print("NO")
``` | instruction | 0 | 55,873 | 20 | 111,746 |
Yes | output | 1 | 55,873 | 20 | 111,747 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.