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 a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,168 | 20 | 66,336 |
"Correct Solution:
```
n=int(input())
if n==1 or n==2:
print(0)
exit()
d=0
for i in range(1,int(n**0.5)+1):
if n%i==0:
if i!=n//i and i!=n//i-1:
d=d+n//i-1
print(d)
``` | output | 1 | 33,168 | 20 | 66,337 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,169 | 20 | 66,338 |
"Correct Solution:
```
import math
n=int(input())
rt=int(math.sqrt(n+1))-1
r=1
ans=0
while r<=rt:
if n%r==0: ans+=n//r-1
r+=1
print(ans)
``` | output | 1 | 33,169 | 20 | 66,339 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,170 | 20 | 66,340 |
"Correct Solution:
```
N = int(input())
x,r = 1,0
while x*x < N:
if N%x==0:
if x>1 and N//(x-1)==N%(x-1):
r += x-1
t = N//x-1
if N//t==N%t:
r += t
x += 1
print(r)
``` | output | 1 | 33,170 | 20 | 66,341 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,171 | 20 | 66,342 |
"Correct Solution:
```
import math
N=int(input())
ans=0
for i in range(1, math.ceil(N**0.5)):
if N % i == 0:
if i < N//i-1:
ans+=N//i-1
print(ans)
``` | output | 1 | 33,171 | 20 | 66,343 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916 | instruction | 0 | 33,172 | 20 | 66,344 |
"Correct Solution:
```
N = int(input())
S = 0
for i in range(1, int(N**(1/2))+1):
if N % i == 0 and N // i > i + 1:
S += N // i - 1
print(S)
``` | output | 1 | 33,172 | 20 | 66,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
N = int(input())
print(sum(N // n - 1 for n in range(1, int(N ** 0.5) + 1) if not N % n and n < N // n - 1))
``` | instruction | 0 | 33,173 | 20 | 66,346 |
Yes | output | 1 | 33,173 | 20 | 66,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
n=int(input())
print(sum(n//i-1 for i in range(1,int((n+1)**0.5)) if n%i<1))
``` | instruction | 0 | 33,174 | 20 | 66,348 |
Yes | output | 1 | 33,174 | 20 | 66,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
import math
N = int(input())
a = math.ceil(N**0.5)-1
cnt=0
for i in range(1,a+1):
if N%i == 0:
if i < (N//i)-1:
cnt += (N//i)-1
print(cnt)
``` | instruction | 0 | 33,175 | 20 | 66,350 |
Yes | output | 1 | 33,175 | 20 | 66,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
from functools import reduce
n = int(input())
print(reduce(lambda x,y:x+y, { n//i - 1 for i in range(1, int(n**0.5)+1) if n%i==0 and n//i-i>=2 }, 0))
``` | instruction | 0 | 33,176 | 20 | 66,352 |
Yes | output | 1 | 33,176 | 20 | 66,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
import math
N = int(input())
ans = 0
for m in range(1,math.ceil(N**(1/2))):
if (N-m)%m == 0 and m < (N-m)%m:
ans += int((N-m)/m)
if N == 1:
ans = 0
if N == 2:
ans = 0
if N == 3:
ans = 2
if N == 6:
ans = 5
print(ans)
``` | instruction | 0 | 33,177 | 20 | 66,354 |
No | output | 1 | 33,177 | 20 | 66,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
import math
n = int(input())
ans = 0
for i in range(2, math.ceil(n**0.5)):
if n % i == 0:
ans += n//i - 1
ans += n//1 - 1
print(ans)
``` | instruction | 0 | 33,178 | 20 | 66,356 |
No | output | 1 | 33,178 | 20 | 66,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
N=int(input())
a=0
for i in range(1,10**6+1):
if N%i:
continue
if i*i>=N:
break
a+=N//i-1
print(a)
``` | instruction | 0 | 33,179 | 20 | 66,358 |
No | output | 1 | 33,179 | 20 | 66,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:
* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.
Find all favorite numbers and print the sum of those.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^{12}
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
8
Output
10
Input
1000000000000
Output
2499686339916
Submitted Solution:
```
from math import sqrt
N = int(input())
ans = 0
for i in range(1, int(sqrt(N))+1):
print(i)
if N%i == 0 and i < N//i-1:
ans += N//i-1
print(ans)
``` | instruction | 0 | 33,180 | 20 | 66,360 |
No | output | 1 | 33,180 | 20 | 66,361 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,266 | 20 | 66,532 |
"Correct Solution:
```
# coding: utf-8
r=list('mcxi')
m=r[::-1]
n=int(input())
for i in range(n):
a,b=input().split()
x=int(''.join(['0' if len(a.split(c))==1 else '1' if a.split(c)[0]=='' or a.split(c)[0][-1] in 'mcxi' else a.split(c)[0][-1] for c in r]))
y=int(''.join(['0' if len(b.split(c))==1 else '1' if b.split(c)[0]=='' or b.split(c)[0][-1] in 'mcxi' else b.split(c)[0][-1] for c in r]))
ans=str(x+y)[::-1]
s=''
for j in range(len(ans)):
if(ans[j]!='0'):
s+=m[j]+(ans[j] if ans[j]!='1' else '')
print(s[::-1])
``` | output | 1 | 33,266 | 20 | 66,533 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,267 | 20 | 66,534 |
"Correct Solution:
```
mcxi = "mcxi"
mcxinum = [1000, 100, 10, 1]
n = int(input())
for z in range(n):
nums = list(input().split())
ans = 0
for num in nums:
for ind, c in enumerate(mcxi):
if c in num:
prestr, num = num.split(c)
pre = 1
if prestr:
pre = int(prestr)
ans += pre * mcxinum[ind]
ansstr = ""
for j in range(4):
dig = mcxinum[j]
if ans >= dig:
dign = ans // dig
if dign > 1:
ansstr += str(dign)
ansstr += mcxi[j]
ans %= dig
print(ansstr)
``` | output | 1 | 33,267 | 20 | 66,535 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,268 | 20 | 66,536 |
"Correct Solution:
```
d = {'m':1000,'c':100,'x':10,'i':1}
k = ['i','x','c','m']
def digit(s):
r,p = 0,1
for x in s:
if x.isdigit(): p = int(x)
else:
r += p*d[x]
p = 1
return r
for _ in range(int(input())):
a,b = input().split()
s = digit(a)+digit(b)
r = []
for i,x in enumerate(reversed(str(s))):
if x!='0': r += [x+k[i]] if x!='1' else [k[i]]
print(*reversed(r),sep='')
``` | output | 1 | 33,268 | 20 | 66,537 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,269 | 20 | 66,538 |
"Correct Solution:
```
import re
for i in range(int(input())):
s=input().replace(" ","")
print(re.sub(r'0.','',''.join([i+j for(i,j)in zip(str(10000+sum([eval(i[0]+'0'*'ixcm'.find(i[1]))for i in['1'+i for i in''.join(re.split(r'\d\w',s))]+re.findall(r'\d\w',s)])),list('1mcxi'))]).replace('1','')))
``` | output | 1 | 33,269 | 20 | 66,539 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,270 | 20 | 66,540 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**5)
def L(): return [x for x in input().split()]
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LI_(): return [-1*int(x) for x in input().split()]
def II(): return int(input())
def IF(): return float(input())
def LM(func,n): return [[func(x) for x in input().split()]for i in range(n)]
mod = 1000000007
inf = float('INF')
dic = {"m":1000,"c":100,"x":10,"i":1}
def MCXI(S):
ret = 0
for d in "mcxi":
i =S.find(d)
if i >=1 and "2"<=S[i-1]<="9":
ret += int(S[i-1])*dic[d]
elif i>=0:
ret += dic[d]
return ret
def mcxi(n):
S = ""
for d in "ixcm":
if n%10 == 1:
S += d
elif n%10 > 1:
S += d
S += str(n%10)
n //= 10
return S[::-1]
n = II()
for i in range(n):
a,b = L()
a = MCXI(a)
b= MCXI(b)
print(mcxi(a+b))
``` | output | 1 | 33,270 | 20 | 66,541 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,271 | 20 | 66,542 |
"Correct Solution:
```
#2005_c
n = int(input())
k = list("mcxi")
for i in range(n):
d = {"m":0,"c":0,"x":0,"i":0}
a,b = input().split()
a = list(a)
b = list(b)
a.insert(0,1)
b.insert(0,1)
for j in range(1,len(a)):
if a[j] in k:
if a[j-1] in k:
d[a[j]] += 1
else:
d[a[j]] += int(a[j-1])
for j in range(1,len(b))[::-1]:
if b[j] in k:
if b[j-1] in k:
d[b[j]] += 1
else:
d[b[j]] += int(b[j-1])
if d[b[j]] >= 10:
l = b[j]
while d[l] >= 10:
d[l] -= 10
l = k[k.index(l)-1]
d[l] += 1
for j in k:
if d[j]:
if d[j] == 1:
print(j,end = "")
else:
print(str(d[j])+j,end = "")
print()
``` | output | 1 | 33,271 | 20 | 66,543 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,272 | 20 | 66,544 |
"Correct Solution:
```
def encode(n):
ns = []
mcxi = ['m','c','x','i']
v = 1000
for i in range(4):
m = 0
while n >= v:
n -= v
m += 1
v = int(v/10)
if m > 0:
ns.append(str(m)+mcxi[i])
return ''.join(ns).replace('1','')
def decode(s):
coe = 1
n = 0
for c in s:
if c in map(str, range(2,10)):
coe = int(c)
elif c == 'm':
n += coe * 1000
coe = 1
elif c == 'c':
n += coe * 100
coe = 1
elif c == 'x':
n += coe * 10
coe = 1
elif c == 'i':
n += coe * 1
coe = 1
return n
n = int(input())
for i in range(n):
ns = input().split()
s = decode(ns[0]) + decode(ns[1])
print(encode(s))
``` | output | 1 | 33,272 | 20 | 66,545 |
Provide a correct Python 3 solution for this coding contest problem.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i | instruction | 0 | 33,273 | 20 | 66,546 |
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
PATTERN = re.compile(r"[2-9]*[mcxi]")
NUMBERS = "23456789"
TABLE = {"m": 1000, "c": 100, "x": 10, "i": 1}
def mcxi2int(mcxi_str):
answer = 0
for segment in re.findall(PATTERN, mcxi_str):
answer += TABLE[segment[-1]] * \
(int(segment[0]) if segment[0] in NUMBERS else 1)
return answer
def int2mcxi(number):
mcxi_prefixes = dict()
mcxi_prefixes["m"], cxi = divmod(number, 1000)
mcxi_prefixes["c"], xi = divmod(cxi, 100)
mcxi_prefixes["x"], mcxi_prefixes["i"] = divmod(xi, 10)
result = ""
for char in "mcxi":
if mcxi_prefixes[char] == 1:
result += char
elif mcxi_prefixes[char] > 1:
result += str(mcxi_prefixes[char]) + char
return result
if __name__ == "__main__":
n = int(input())
for i in range(n):
mcxi1, mcxi2 = input().split()
print(int2mcxi(mcxi2int(mcxi1) + mcxi2int(mcxi2)))
``` | output | 1 | 33,273 | 20 | 66,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
n = int(input())
S = ["m", "c", "x", "i"]
X = [1000, 100, 10, 1]
N = [str(i) for i in range(2, 10)]
for i in range(n) :
A, B = map(str, input().split())
A = list(A)
B = list(B)
ans = 0
for j in range(len(A)) :
if(A[j] in S) :
if(j != 0 and A[j - 1] in N) :
ans += int(A[j - 1]) * X[S.index(A[j])]
else :
ans += X[S.index(A[j])]
else :
pass
for j in range(len(B)) :
if(B[j] in S) :
if(j != 0 and B[j - 1] in N) :
ans += int(B[j - 1]) * X[S.index(B[j])]
else :
ans += X[S.index(B[j])]
else :
pass
ANS = list(str(ans))
l = len(ANS)
for j in range(l) :
if(ANS[j] == "0") :
pass
elif(ANS[j] == "1") :
print(S[j + (4 - l)], end = "")
else :
print(ANS[j], S[j + (4 - l)], sep = "", end = "")
print()
``` | instruction | 0 | 33,274 | 20 | 66,548 |
Yes | output | 1 | 33,274 | 20 | 66,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
ans_list = []
n = int(input())
def mcxl2digit(s):
ans = 0
dig = 1
for i in range(len(s)):
if "2" <= s[i] <= "9":
dig = int(s[i])
else:
if s[i] == "m":
key = 1000
elif s[i] == "c":
key = 100
elif s[i] == "x":
key = 10
else:
key = 1
ans += key * dig
dig = 1
return ans
def digit2mcxl(i):
return_list = []
m = i // 1000
if m != 0 and m != 1:
return_list.append(str(m))
if m != 0:
return_list.append("m")
i = i % 1000
c = i // 100
if c != 0 and c != 1:
return_list.append(str(c))
if c != 0:
return_list.append("c")
i = i % 100
x = i // 10
if x != 0 and x != 1:
return_list.append(str(x))
if x != 0:
return_list.append("x")
i = i % 10
l = i
if l != 0 and l != 1:
return_list.append(str(l))
if l != 0:
return_list.append("i")
return return_list
for i in range(n):
a, b = input().split()
ans = (mcxl2digit(a) + mcxl2digit(b))
#print(a, b, mcxl2digit(a), mcxl2digit(b))
#print(ans)
ans = digit2mcxl(ans)
ans_list.append(ans)
for i in ans_list:
print("".join(i))
``` | instruction | 0 | 33,275 | 20 | 66,550 |
Yes | output | 1 | 33,275 | 20 | 66,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
import re;[print(re.sub(r'0.','',''.join([str(10000+sum([eval(i[0]+'0'*'ixcm'.find(i[1]))for i in['1'+i for i in''.join(re.split(r'\d\w',s))]+re.findall(r'\d\w',s)]))[i]+'1mcxi'[i]for i in range(5)]).replace('1','')))for s in[input().replace(" ","")for i in range(int(input()))]]
``` | instruction | 0 | 33,276 | 20 | 66,552 |
Yes | output | 1 | 33,276 | 20 | 66,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
fs = [input().split() for i in range(n)]
check = "mcxi"
for f2 in fs:
v = [0, 0, 0, 0]
for f in f2:
for i in range(len(f)):
for c in range(4):
if check[c] == f[i]:
if i==0:
tmp = 1
else:
tmp = 1 if f[i-1] in check else int(f[i-1])
v[c] += tmp
break
for i in range(3, 0, -1):
if v[i] > 9:
v[i] -= 10
v[i-1] += 1
for i in range(4):
if v[i] > 0:
print(check[i] if v[i] == 1 else str(v[i])+check[i], end="")
print()
``` | instruction | 0 | 33,277 | 20 | 66,554 |
Yes | output | 1 | 33,277 | 20 | 66,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
trial = int(input())
numlist = [str(n) for n in range(2,10)]
cases = []
for t in range(trial):
cases.append(input().split(" "))
print(cases)
for case in range(len(cases)):
num = 0
for ba in range(2):
for n in range(len(cases[case][ba])):
if cases[case][ba][n] == "m":
if n - 1 == 0:
num += int(cases[case][ba][n-1]) * 1000
else:
num += 1000
elif cases[case][ba][n] == "c":
if (n - 1 == 0 and cases[case][ba][n-1] != "m") or cases[case][ba][n-1] in numlist:
num += int(cases[case][ba][n-1]) * 100
else:
num += 100
elif cases[case][ba][n] == "x":
if (n - 1 == 0 and cases[case][ba][n-1] not in ["m","c"]) in numlist:
num += int(cases[case][ba][n-1]) * 10
else:
num += 10
elif cases[case][ba][n] == "i":
if (n - 1 == 0 and cases[case][ba][n-1] not in ["m","c","x"]) or cases[case][ba][n-1] in numlist:
num += int(cases[case][ba][n-1]) * 1
else:
num += 1
else:
num = str(num)
answer = ""
print(num)
for n in range(len(num)):
if len(num) - 1 - n == 3:
if num[n] == "1":
answer += "m"
elif num[n] == "0":
pass
else:
answer += str(num[n]) + "m"
if len(num) - 1 - n == 2:
if num[n] == "1":
answer += "c"
elif num[n] == "0":
pass
else:
answer += str(num[n]) + "c"
if len(num) - 1 - n == 1:
if num[n] == "1":
answer += "x"
elif num[n] == "0":
pass
else:
answer += str(num[n]) + "x"
if len(num) - 1 - n == 0:
if num[n] == "1":
answer += "i"
elif num[n] == "0":
pass
else:
answer += str(num[n]) + "i"
else:
print(answer)
``` | instruction | 0 | 33,278 | 20 | 66,556 |
No | output | 1 | 33,278 | 20 | 66,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
a={'m':1000,'c':100,'x':10,'i':1}
for _ in range(int(input())):
b,s,t=input(),0,1
for x in b:
if x==' ':continue
if x in a:s+=a[x]*t;t=1
else:t=int(x)
ans=''
for k in ['m','c','x','i']:
c,s=divmod(s,a[k])
if c:ans+=['',str(c)][c!=0]+k
print(ans)
``` | instruction | 0 | 33,279 | 20 | 66,558 |
No | output | 1 | 33,279 | 20 | 66,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
n=int(input())
for i in range(n):
s0,s1=map(str,input().split())
ans=""
ans0=0
ans1=0
ans2=0
p=1
for j in range(len(s0)):
if s0[j]!="m" and s0[j]!="c" and s0[j]!="x" and s0[j]!="i" :
p=int(s0[j])
continue
if s0[j]=="m":
ans0+=p*1000
p=1
if s0[j]=="c":
ans0+=p*100
p=1
if s0[j]=="x":
ans0+=p*10
p=1
if s0[j]=="i":
ans0+=p*1
p=1
for k in range(len(s1)):
if s1[k]!="m" and s1[k]!="c" and s1[k]!="x" and s1[k]!="i" :
p=int(s1[k])
continue
if s1[k]=="m":
ans1+=p*1000
p=1
if s1[k]=="c":
ans1+=p*100
p=1
if s1[k]=="x":
ans1+=p*10
p=1
if s1[k]=="i":
ans1+=p*1
p=1
print(ans0)
print(ans1)
ans2=ans0+ans1
while ans2>0:
if ans2>=1000:
sans2=str(ans2)
if sans2[0]=="1":
ans=ans+"m"
else:
ans=ans+sans2[0]+"m"
ans2=int(sans2[1:])
continue
if ans2>=100:
sans2=str(ans2)
if sans2[0]=="1":
ans=ans+"c"
else:
ans=ans+sans2[0]+"c"
ans2=int(sans2[1:])
continue
if ans2>=10:
sans2=str(ans2)
if sans2[0]=="1":
ans=ans+"x"
else:
ans=ans+sans2[0]+"x"
ans2=int(sans2[1:])
continue
if ans2>=1:
sans2=str(ans2)
if sans2[0]=="1":
ans=ans+"i"
else:
ans=ans+sans2[0]+"i"
break
print(ans)
``` | instruction | 0 | 33,280 | 20 | 66,560 |
No | output | 1 | 33,280 | 20 | 66,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system.
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system.
For example, character strings
> "5m2c3x4i", "m2c4i" and "5m2c3x"
correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit.
For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an MCXI-string.
An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively.
Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result.
Input
The input is as follows. The first line contains a positive integer n (<= 500) that indicates the number of the following lines. The k+1 th line is the specification of the k th computation (k=1, ..., n).
> n
> specification1
> specification2
> ...
> specificationn
>
Each specification is described in a line:
> MCXI-string1 MCXI-string2
The two MCXI-strings are separated by a space.
You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999.
Output
For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output.
Example
Input
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
Output
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
Submitted Solution:
```
ans_list = []
n = int(input())
def mcxl2digit(s):
ans = 0
dig = 1
for i in range(len(s)):
if "2" <= s[i] <= "9":
dig = int(s[i])
else:
if s[i] == "m":
key = 1000
elif s[i] == "c":
key = 100
elif s[i] == "x":
key = 10
else:
key = 1
ans += key * dig
dig = 1
return ans
def digit2mcxl(i):
return_list = []
m = i // 1000
if m != 0 and m != 1:
return_list.append(str(m))
if m != 0:
return_list.append("m")
i = i % 1000
c = i // 100
if c != 0 and c != 1:
return_list.append(str(c))
if c != 0:
return_list.append("c")
i = i % 100
x = i // 10
if x != 0 and x != 1:
return_list.append(str(x))
if x != 0:
return_list.append("x")
i = i % 10
l = i
if l != 0 and l != 1:
return_list.append(str(l))
if l != 0:
return_list.append("l")
return return_list
for i in range(n):
a, b = input().split()
ans = (mcxl2digit(a) + mcxl2digit(b))
#print(a, b, mcxl2digit(a), mcxl2digit(b))
#print(ans)
ans = digit2mcxl(ans)
ans_list.append(ans)
for i in ans_list:
print("".join(i))
``` | instruction | 0 | 33,281 | 20 | 66,562 |
No | output | 1 | 33,281 | 20 | 66,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,320 | 20 | 66,640 |
Tags: implementation
Correct Solution:
```
n = int(input())
A = list(map(int, input()))
S = [A[0]]
for i in range(1, n):
if A[i] != 0:
S.append(A[i] + S[len(S) - 1])
ans = "NO"
for d in S:
k = 2
for i in range(len(S) - 1):
if d * k == S[i]:
k += 1
if S[len(S) - 1] == d * k:
ans = "YES"
break
print(ans)
``` | output | 1 | 33,320 | 20 | 66,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,321 | 20 | 66,642 |
Tags: implementation
Correct Solution:
```
n = int(input())
digits = [int(d) for d in input()]
ret = "NO"
for i in range(n - 1):
sum1 = 0
for i2 in range(i + 1):
sum1 += digits[i2]
next1 = i + 1
temp = 0
reseted = False
#print("try with sum = " + str(sum1))
while next1 != n:
temp += digits[next1]
#print(str(temp))
next1 += 1
if temp > sum1:
break
if temp == sum1:
reseted = True
temp = 0
if temp == 0 and reseted:
ret = "YES"
break;
print(ret)
``` | output | 1 | 33,321 | 20 | 66,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,322 | 20 | 66,644 |
Tags: implementation
Correct Solution:
```
n = int(input())
number = input()
sum = 0
flag = False
counter = 0
for i in range (n) :
sum = sum + int(number[i])
if (sum == 0 and n > 1) :
flag = True
for i in range (2, sum+1) :
if (sum % i == 0) :
for j in range (n) :
counter = counter + int(number[j])
if (counter == sum/i) :
counter = 0
if (counter == 0) :
flag = True
counter = 0
break
counter = 0
if (flag == True) :
print ("YES")
else :
print ("NO")
``` | output | 1 | 33,322 | 20 | 66,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,323 | 20 | 66,646 |
Tags: implementation
Correct Solution:
```
a=int(input())
b=list(map(int,input().replace('',' ').split()));k=0;o=sum(b)
for i in range(452):
j=0;s=0;p=[]
while j<a:
if s+b[j]<i:s+=b[j]
elif s+b[j]==i:p+=[s+b[j]];s=0
else:p=[];break
j+=1
if s==0 and len(p)!=1 and len(set(p))==1 and p.count(i)==len(p):exit(print("YES"))
print("NO")
``` | output | 1 | 33,323 | 20 | 66,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,324 | 20 | 66,648 |
Tags: implementation
Correct Solution:
```
def main():
n = int(input())
s = input()
maxi = -1
for x in range(901):
f = False
acc = 0
cnt = 0
for y in range(n):
if acc + int(s[y]) > x:
f = True
break
elif acc + int(s[y]) == x:
acc = 0
cnt += 1
else:
acc += int(s[y])
if f:
continue
elif acc == 0 and cnt >= 2:
maxi = x
if maxi == -1:
print("NO")
else:
print("YES")
if __name__ == '__main__':
main()
``` | output | 1 | 33,324 | 20 | 66,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,325 | 20 | 66,650 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = input()
s = str(s).strip('0')
n = len(s)
m = []
for i in s:
m.append(int(i))
from itertools import accumulate
ac = list(accumulate(m))
res = 0
if n==0:
res = 1
for i in range(n-1):
check = 1
if ac[i] == 0:
for j in ac[i+1:]:
if j==0:
res=1
else:
res=0
else:
for j in range(i+1,n):
if ac[j]%ac[i]==0:
if ac[j]//ac[i]==check+1:
check += 1
if(j==n-1):
check = -1
elif ac[j]//ac[i]==check:
if(j==n-1):
check = -1
else:
res = 0
break
if check==-1:
res = 1
break
if res:
print("YES")
else:
print("NO")
``` | output | 1 | 33,325 | 20 | 66,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,326 | 20 | 66,652 |
Tags: implementation
Correct Solution:
```
import sys
n = int(input())
s = input()
s2 = ''
maxx = 0
all_zero = True
for i in s:
maxx += int(i)
if i != '0':
all_zero = False
s2 += i
s = s2
n = len(s)
if all_zero:
print("YES")
sys.exit()
for i in range(0, maxx):
start = 0
p = 0
summ = 0
while start + p < n:
summ += int(s[start + p])
if summ == i:
if (start + p == n - 1):
print("YES")
sys.exit()
summ = 0
start = start + p;
p = 0
elif summ >= i:
break
p += 1
print("NO")
``` | output | 1 | 33,326 | 20 | 66,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum. | instruction | 0 | 33,327 | 20 | 66,654 |
Tags: implementation
Correct Solution:
```
n = int(input())
aS = list(map(int, input()))
a = []
for i in aS:
if i > 0:
a.append(i)
n = len(a)
if n == 0:
print("YES")
exit()
cur = 0
for i in range(n - 1):
cur += a[i]
ans = True
co = i + 1
while co < n:
ad = 0
while co < n and ad < cur:
ad += a[co]
co += 1
if ad != cur:
ans = False
break
if ans:
print('YES')
exit()
print('NO')
``` | output | 1 | 33,327 | 20 | 66,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n = int(input())
s = input()
for i in range(9*n+1):
c = 0
cur = 0
for j in s:
cur += int(j)
if cur == i:
c += 1
cur = 0
if cur == 0 and c > 1:
print("YES")
break
else:
print("NO")
``` | instruction | 0 | 33,328 | 20 | 66,656 |
Yes | output | 1 | 33,328 | 20 | 66,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
import sys
n = int(input())
array = list(input())
for i in range(n):
array[i] = int(array[i])
for i in range(sum(array) + 1):
if sum(array) == 0 or (i != 0 and sum(array) % i == 0 and i < sum(array)):
k = 0
l = 0
for j in array:
k = k + j
if k == i:
k = 0
l += 1
elif k > i:
break
if k == 0 and l > 1:
print("YES")
sys.exit()
print("NO")
``` | instruction | 0 | 33,329 | 20 | 66,658 |
Yes | output | 1 | 33,329 | 20 | 66,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n = int(input())
inp = input()
a = [int(x) for x in inp.strip()]
s = sum(a)
if len(a) == 1:
print('NO')
elif s == 0:
print('YES')
else:
for k in range(1, s):
if s % k != 0:
continue
ss = 0
for i in range(len(a)):
ss += a[i]
if ss > k:
break
elif ss == k:
ss = 0
else:
print('YES')
break
else:
print('NO')
``` | instruction | 0 | 33,330 | 20 | 66,660 |
Yes | output | 1 | 33,330 | 20 | 66,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
def check(s,n):
for j in range(len(s)):
if sum([int(letter) for letter in s[:j+1]]) == n:
if j == len(s)-1:
return True
else:
return check(s[j+1:],n)
elif sum([int(letter) for letter in s[:j+1]]) > n:
return False
def solve(x):
x = x.replace("0","")
if x == "":
return "YES"
for j in range(len(x)):
N = sum([int(letter) for letter in x[:j]])
if check(x[j:],N):
return "YES"
return "NO"
n = int(input())
x = input()
print(solve(x))
``` | instruction | 0 | 33,331 | 20 | 66,662 |
Yes | output | 1 | 33,331 | 20 | 66,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n=int(input())
m=str(input())
for i in range(1,n):
for l in range(i,n):
str0=m[:i]
str1=m[i:l]
str2=m[l:]
s0=0
s1=0
s2=0
for ii in range(len(str0)):
s0+=int(str0[ii])
for ii in range(len(str1)):
s1+=int(str1[ii])
for ii in range(len(str2)):
s2+=int(str2[ii])
if s0==s1==s2 and len(str1)>0 and len(str2)>0 and len(str0)>0:
print('YES')
exit()
print('NO')
``` | instruction | 0 | 33,332 | 20 | 66,664 |
No | output | 1 | 33,332 | 20 | 66,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n = int(input())
b = list(input())
for i in range(len(b)):
b[i] = int(b[i])
s = sum(b)
t = False
k=0
for j in range(s-1):
if(s%(j+1)==0):
for i in range(n):
k += b[i]
if((k==j+1)&(i+1 == n)):
k = 0
t = True
elif(k == (j+1)):
k = 0
elif(k> j+1):
break
k = 0
if(t):
print('YES')
else:
print('NO')
``` | instruction | 0 | 33,333 | 20 | 66,666 |
No | output | 1 | 33,333 | 20 | 66,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n=int(input())
s=list(map(int,input()))
sum1=0
for i in range(n):
sum1+=s[i]
sum2=0
m=i+1;
for j in range(i+1,n,1):
sum2+=s[j]
if(sum2>sum1):
sum2-=s[m]
m+=1
if(sum2==sum1):
sum3=sum(s[j+1:n])
if(sum1==sum3):
print("YES")
exit(0)
print("NO")
``` | instruction | 0 | 33,334 | 20 | 66,668 |
No | output | 1 | 33,334 | 20 | 66,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Vasya found a golden ticket β a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
Input
The first line contains one integer n (2 β€ n β€ 100) β the number of digits in the ticket.
The second line contains n digits a_1 a_2 ... a_n (0 β€ a_i β€ 9) β the golden ticket. Digits are printed without spaces.
Output
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
Examples
Input
5
73452
Output
YES
Input
4
1248
Output
NO
Note
In the first example the ticket can be divided into 7, 34 and 52: 7=3+4=5+2.
In the second example it is impossible to divide ticket into segments with equal sum.
Submitted Solution:
```
n=int(input())
x=list(map(int,list(input())))
s=sum(x)
a=0
for i in range(2,n+1):
if s%i==0:
j=0
while j<n:
a+=x[j]
if a>s/i:
break
elif a==s/i:
a=0
j+=1
if a==0:
print('YES')
exit()
if i==n:
print('NO')
``` | instruction | 0 | 33,335 | 20 | 66,670 |
No | output | 1 | 33,335 | 20 | 66,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
#input=sys.stdin.readline
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())
def inp():
return int(input())
def st():
return input().rstrip('\n')
n,m=ma()
r=[set() for i in range(m)]
for i in range(n):
s=st()
for j in range(m):
r[j].add(s[j])
re=1
p=1000000009
for i in r:
re=re*len(i)
re=re%p
print(re%p)
``` | instruction | 0 | 33,627 | 20 | 67,254 |
No | output | 1 | 33,627 | 20 | 67,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
Input
The only line of input contains an integer a ( - 109 β€ a β€ 109).
Output
Print the minimum b in a line.
Examples
Input
179
Output
1
Input
-1
Output
9
Input
18
Output
10
Note
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0. | instruction | 0 | 33,765 | 20 | 67,530 |
Tags: brute force
Correct Solution:
```
n=int(input())
cnt=0
def ch(n):
n=abs(n)
while(n>0):
t=int(n%10)
if(t==8):
return True
n/=10
return False
cnt+=1
n+=1
while(ch(n)==False):
n+=1
cnt+=1
#print(n,cnt)
print(cnt)
``` | output | 1 | 33,765 | 20 | 67,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
Input
The only line of input contains an integer a ( - 109 β€ a β€ 109).
Output
Print the minimum b in a line.
Examples
Input
179
Output
1
Input
-1
Output
9
Input
18
Output
10
Note
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0. | instruction | 0 | 33,766 | 20 | 67,532 |
Tags: brute force
Correct Solution:
```
n = int(input())
b = 0
while True:
n += 1
b += 1
digits = list(map(int,list(str(abs(n)))))
if 8 in digits:
print(b)
break
``` | output | 1 | 33,766 | 20 | 67,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
Input
The only line of input contains an integer a ( - 109 β€ a β€ 109).
Output
Print the minimum b in a line.
Examples
Input
179
Output
1
Input
-1
Output
9
Input
18
Output
10
Note
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0. | instruction | 0 | 33,767 | 20 | 67,534 |
Tags: brute force
Correct Solution:
```
a = int(input())
res = 1
a += 1
while '8' not in str(a):
res += 1
a += 1
print(res)
``` | output | 1 | 33,767 | 20 | 67,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while 42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
Input
The only line of input contains an integer a ( - 109 β€ a β€ 109).
Output
Print the minimum b in a line.
Examples
Input
179
Output
1
Input
-1
Output
9
Input
18
Output
10
Note
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0. | instruction | 0 | 33,768 | 20 | 67,536 |
Tags: brute force
Correct Solution:
```
n = int(input())
if -8 <= n <= 7:
print(8-n)
elif n >= 8:
n += 1
temp = list(str(n))
if temp.count('8') > 0:
print(1)
elif temp[len(temp)-1] == '9':
carry = 1
temp.insert(0, '0')
i = len(temp)-1
while i >= 0:
if temp[i] == '9':
temp[i] = '0'
else:
temp[i] = str(int(temp[i])+carry)
break
i -= 1
if temp[0] == '0':
temp.pop(0)
if temp.count('8') == 0:
temp[len(temp)-1] = '8'
ans = int(''.join(temp))
print(ans-n+1)
else:
temp[len(temp)-1] = '8'
ans = int(''.join(temp))
print(ans-n+1)
else:
n = abs(n)
n -= 1
temp = list(str(n))
if temp.count('8') > 0:
print(1)
elif temp[len(temp)-1] == '9':
print(2)
else:
i = len(temp)-2
while i >= 0:
if temp[i] == '0':
temp[i] = '9'
else:
temp[i] = str(int(temp[i])-1)
break
i -= 1
if temp[0] == '0':
temp.pop(0)
if temp.count('8') == 0:
temp[len(temp)-1] = '8'
ans = int(''.join(temp))
for i in range(1, 11):
ans += 1
if str(ans).count('8') == 0:
ans -= 1
result = True
break
print(n-ans+1)
``` | output | 1 | 33,768 | 20 | 67,537 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.