message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input contains two space-separated integers n and bx (1 ≤ n ≤ 10, 2 ≤ bx ≤ 40), where n is the number of digits in the bx-based representation of X.
The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi < bx) — the digits of X. They are given in the order from the most significant digit to the least significant one.
The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10, 2 ≤ by ≤ 40, bx ≠ by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1, y2, ..., ym (0 ≤ yi < by) — the digits of Y.
There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.
Output
Output a single character (quotes for clarity):
* '<' if X < Y
* '>' if X > Y
* '=' if X = Y
Examples
Input
6 2
1 0 1 1 1 1
2 10
4 7
Output
=
Input
3 3
1 0 2
2 5
2 4
Output
<
Input
7 16
15 15 4 0 0 7 10
7 9
4 8 0 3 1 5 0
Output
>
Note
In the first sample, X = 1011112 = 4710 = Y.
In the second sample, X = 1023 = 215 and Y = 245 = 1123, thus X < Y.
In the third sample, <image> and Y = 48031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y.
Submitted Solution:
```
from math import *
n,x = map(int,input().split())
a = list(map(int,input().split()))
m,y = map(int,input().split())
b = list(map(int,input().split()))
a.reverse()
b.reverse()
#print(a,b)
res1 = 0
for i in range(len(a)):
res1+=int(a[i])**i
res2 = 0
for i in range(len(b)):
res2+=int(b[i])**i
if res1==res2:
print('=')
quit()
if res1<res2:
print('<')
quit()
print('>')
``` | instruction | 0 | 7,124 | 20 | 14,248 |
No | output | 1 | 7,124 | 20 | 14,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input contains two space-separated integers n and bx (1 ≤ n ≤ 10, 2 ≤ bx ≤ 40), where n is the number of digits in the bx-based representation of X.
The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi < bx) — the digits of X. They are given in the order from the most significant digit to the least significant one.
The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10, 2 ≤ by ≤ 40, bx ≠ by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1, y2, ..., ym (0 ≤ yi < by) — the digits of Y.
There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.
Output
Output a single character (quotes for clarity):
* '<' if X < Y
* '>' if X > Y
* '=' if X = Y
Examples
Input
6 2
1 0 1 1 1 1
2 10
4 7
Output
=
Input
3 3
1 0 2
2 5
2 4
Output
<
Input
7 16
15 15 4 0 0 7 10
7 9
4 8 0 3 1 5 0
Output
>
Note
In the first sample, X = 1011112 = 4710 = Y.
In the second sample, X = 1023 = 215 and Y = 245 = 1123, thus X < Y.
In the third sample, <image> and Y = 48031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y.
Submitted Solution:
```
def trans( nums , n , b ):
res = 0
for i in reversed( range( n ) ):
res = res*b+nums[i]
return res
if __name__ == "__main__":
n , bx = [int(x) for x in input().split()]
numXArray = [int(x) for x in input().split()]
numX = trans( numXArray , n , bx )
m , by = [int(x) for x in input().split()]
numYArray = [int(x) for x in input().split()]
numY = trans( numYArray , m , by )
if numX < numY:
print("<")
elif numX > numY:
print(">")
else:
print("=")
``` | instruction | 0 | 7,125 | 20 | 14,250 |
No | output | 1 | 7,125 | 20 | 14,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input contains two space-separated integers n and bx (1 ≤ n ≤ 10, 2 ≤ bx ≤ 40), where n is the number of digits in the bx-based representation of X.
The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi < bx) — the digits of X. They are given in the order from the most significant digit to the least significant one.
The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10, 2 ≤ by ≤ 40, bx ≠ by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1, y2, ..., ym (0 ≤ yi < by) — the digits of Y.
There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.
Output
Output a single character (quotes for clarity):
* '<' if X < Y
* '>' if X > Y
* '=' if X = Y
Examples
Input
6 2
1 0 1 1 1 1
2 10
4 7
Output
=
Input
3 3
1 0 2
2 5
2 4
Output
<
Input
7 16
15 15 4 0 0 7 10
7 9
4 8 0 3 1 5 0
Output
>
Note
In the first sample, X = 1011112 = 4710 = Y.
In the second sample, X = 1023 = 215 and Y = 245 = 1123, thus X < Y.
In the third sample, <image> and Y = 48031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y.
Submitted Solution:
```
n, bx = map(int, input().strip().split())
x = int("".join(input().strip().split()), bx)
m, by = map(int, input().strip().split())
y = int("".join(input().strip().split()), by)
if x == y:
print("=")
elif x < y:
print("<")
else:
print(">")
``` | instruction | 0 | 7,126 | 20 | 14,252 |
No | output | 1 | 7,126 | 20 | 14,253 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,350 | 20 | 14,700 |
"Correct Solution:
```
n = int(input())
def dfs(s):
if int(s) > n:
return 0
if all(s.count(c)>0 for c in '753'):
t = 1
else:
t = 0
for c in '753':
t += dfs(s+c)
return t
print(dfs('0'))
``` | output | 1 | 7,350 | 20 | 14,701 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,351 | 20 | 14,702 |
"Correct Solution:
```
import itertools as t
N=int(input())
a,X=0,[]
for j in range(len(str(N))+1):X+=list(t.product((3,5,7),repeat=j))
for i in X:
s=''
for j in i:s+=str(j)
if len(set(i))==3and int(s)<=N:a+=1
print(a)
``` | output | 1 | 7,351 | 20 | 14,703 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,352 | 20 | 14,704 |
"Correct Solution:
```
def dfs(n,lst,s):
if int(s) >n:
return
if all([c in s for c in "753"]):
lst.append(s)
for c in "753":
dfs(n,lst,s+c)
lst=[]
n =int(input())
for c in "753":
dfs(n,lst,c)
print(len(lst))
``` | output | 1 | 7,352 | 20 | 14,705 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,353 | 20 | 14,706 |
"Correct Solution:
```
x = int(input())
def sft(s):
if int(s) > x:
return 0
if all(s.count(c) > 0 for c in '753'):
ret = 1
else:
ret = 0
for c in '753':
ret += sft(s + c)
return ret
print(sft('0'))
``` | output | 1 | 7,353 | 20 | 14,707 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,354 | 20 | 14,708 |
"Correct Solution:
```
def dfs(s):
if int(s) > N:
return 0
res = 1 if all(s.count(c) > 0 for c in '753') else 0
for c in '753':
res += dfs(s + c)
return res
N = int(input())
print(dfs('0'))
``` | output | 1 | 7,354 | 20 | 14,709 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,355 | 20 | 14,710 |
"Correct Solution:
```
N = int(input())
def func(s):
if int(s)>N:
return 0
ret = 1 if all(s.count(c)>0 for c in '753') else 0
for c in '753':
ret += func(s+c)
return ret
print(func('0'))
``` | output | 1 | 7,355 | 20 | 14,711 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,356 | 20 | 14,712 |
"Correct Solution:
```
n = int(input())
def nngg(m):
if int(m) > n:
return 0
ret = 1 if all(m.count(s)>0 for s in '375') else 0
for s in '357':
ret += nngg(m+s)
return ret
print(nngg('0'))
``` | output | 1 | 7,356 | 20 | 14,713 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484 | instruction | 0 | 7,357 | 20 | 14,714 |
"Correct Solution:
```
def dfs(s, t):
if int(s) > t:
return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0
for c in '753':
ret += dfs(s+c, t)
return ret
n = int(input())
print(dfs('0', n))
``` | output | 1 | 7,357 | 20 | 14,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
from itertools import product
n = int(input())
ans = 0
S = []
for i in range(10):
S += list(product("357",repeat=i))
for s in S:
if len(set(s)) > 2 and int("".join(s)) <= n:
ans += 1
print(ans)
``` | instruction | 0 | 7,358 | 20 | 14,716 |
Yes | output | 1 | 7,358 | 20 | 14,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
N = int(input())
def dfs(s):
if int(s)>N:
return 0;
ret = 1 if all(s.count(c) > 0 for c in "753") else 0
for c in "753":
ret += dfs(s+c)
return ret
print(dfs("0"))
``` | instruction | 0 | 7,359 | 20 | 14,718 |
Yes | output | 1 | 7,359 | 20 | 14,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
# 写経
n=int(input())
def dfs(s):
if int(s)>n:return 0
ret=1 if all(s.count(c)>0 for c in '753') else 0
for c in '753':
ret+=dfs(s+c)
return ret
print(dfs('0'))
``` | instruction | 0 | 7,360 | 20 | 14,720 |
Yes | output | 1 | 7,360 | 20 | 14,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
n=int(input())
def dfs(s):
if int(s)>n:
return 0
if all(s.count(i)>0 for i in '753'):
ans=1
else:
ans=0
for i in '753':
ans+=dfs(s+i)
return ans
print(dfs('0'))
``` | instruction | 0 | 7,361 | 20 | 14,722 |
Yes | output | 1 | 7,361 | 20 | 14,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
N = int(input())
def dfs(s):
print(s)
if int(s) > N:
return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0
for c in '753':
ret += dfs(s + c)
return ret
print(dfs('0'))
``` | instruction | 0 | 7,362 | 20 | 14,724 |
No | output | 1 | 7,362 | 20 | 14,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
def shichigo(s):
if '3' not in s:
return False
if '5' not in s:
return False
if '7' not in s:
return False
x = s.replace('3','').replace('5','').replace('7','')
if x=='':
return True
return False
n = input()
# k = 桁数-1
k = len(n)-1
# k桁までの753数
ans = 0
for i in range(1,k+1):
ans += 3**i - 3*2**i + 3
# nの桁の753数/3
a = 3**k - 2**(k+1) + 1
f = int(n[0])
if f<3:
print(ans)
exit()
elif f==3:
for i in range(3*10**k,int(n)+1):
if shichigo(str(i)):
ans += 1
elif f<5:
ans += a
elif f ==5:
ans += a
for i in range(5*10**k,int(n)+1):
if shichigo(str(i)):
ans += 1
elif f<7:
ans += 2*a
elif f==7:
ans += 2*a
for i in range(7*10**k,int(n)+1):
if shichigo(str(i)):
ans += 1
else:
ans += 3*a
print(ans)
``` | instruction | 0 | 7,363 | 20 | 14,726 |
No | output | 1 | 7,363 | 20 | 14,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
num753 = []
num753.append([0,0,0,0,0,0,0]) #3,5,7,35,37,57,357
num753.append([1,1,1,0,0,0,0])
for i in range(1,10):
num753.append([num753[i][0],num753[i][1],num753[i][2],num753[i][0]+num753[i][1]+num753[i][3]*2,num753[i][0]+num753[i][2]+num753[i][4]*2,num753[i][1]+num753[i][2]+num753[i][5]*2,num753[i][3]+num753[i][4]+num753[i][5]+num753[i][6]*3])
N = input()
ans = 0
for i in range(len(N)):
ans += num753[i][6]
check3 = False
check5 = False
check7 = False
for i in range(len(N)):
if int(N[i])<3:
break
if int(N[i])==3:
if i==len(N)-1:
if check5 and check7:
ans += 1
check3 = True
continue
ans += num753[len(N)-i-1][5]+num753[len(N)-i-1][6]
if check5:
ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][4]
if check7:
ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][3]
if check5 and check7:
ans += num753[len(N)-i-1][0]
if int(N[i])<5:
break
if int(N[i])==5:
if i==len(N)-1:
if check5 and check7:
ans += 1
if check3 and check7:
ans += 1
check5 = True
continue
ans += num753[len(N)-i-1][4]+num753[len(N)-i-1][6]
if check3:
ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][5]
if check7:
ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][3]
if check3 and check7:
ans += num753[len(N)-i-1][1]
if int(N[i])<7:
break
if int(N[i])==7:
check7 = True
if i==len(N)-1:
if check5 and check7:
ans += 1
if check3 and check7:
ans += 1
if check3 and check5:
ans += 1
continue
ans += num753[len(N)-i-1][3]+num753[len(N)-i-1][6]
if check3:
ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][5]
if check5:
ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][4]
if check3 and check5:
ans += num753[len(N)-i-1][2]
break
print(ans)
``` | instruction | 0 | 7,364 | 20 | 14,728 |
No | output | 1 | 7,364 | 20 | 14,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
* When the number is written in base ten, each of the digits `7`, `5` and `3` appears at least once, and the other digits never appear.
Constraints
* 1 \leq N < 10^9
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).
Examples
Input
575
Output
4
Input
3600
Output
13
Input
999999999
Output
26484
Submitted Solution:
```
def cnct(lint,lim):
global list753
global list357
global list333
lint1=str(lint)+"3"
lint1int=int(lint1)
if lint1int<lim and not lint1int in list357:
list357.add(lint1int)
cnct(lint1int,lim)
lint2=str(lint)+"5"
lint2int=int(lint2)
if lint2int<lim and not lint2int in list357:
list357.add(lint2int)
cnct(lint2int,lim)
lint3=str(lint)+"7"
lint3int=int(lint3)
if lint3int<lim and not lint3int in list357:
list357.add(lint3int)
cnct(lint3int,lim)
lint4="3"+str(lint)
lint4int=int(lint4)
if lint4int<lim and not lint4int in list357:
list357.add(lint4int)
cnct(lint4int,lim)
lint5="5"+str(lint)
lint5int=int(lint5)
if lint5int<lim and not lint5int in list357:
list357.add(lint5int)
cnct(lint5int,lim)
lint6="7"+str(lint)
lint6int=int(lint6)
if lint6int<lim and not lint6int in list357:
list357.add(lint6int)
cnct(lint6int,lim)
def D(lint):
lista=list(str(lint))
if lista.count("3") and lista.count("5") and lista.count("7"):
return True
else:
return False
list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
if not D(c):
list333.remove(c)
print(len(list333))
``` | instruction | 0 | 7,365 | 20 | 14,730 |
No | output | 1 | 7,365 | 20 | 14,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,735 | 20 | 15,470 |
Tags: greedy, math
Correct Solution:
```
ans = ""
for i in range(int(input())):
n, m = [int(s) for s in input().split()]
a = (m - (n % m)) % m
ans += str(a) + "\n"
print(ans)
``` | output | 1 | 7,735 | 20 | 15,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,736 | 20 | 15,472 |
Tags: greedy, math
Correct Solution:
```
T = int(input())
for t in range(T):
n, s = input().split()
fixn = n
n_list = [0] + [int(i) for i in n]
m = len(n_list)
s = int(s)
cur_sum = sum(n_list)
ans = 0
right_pointer = m-1
while cur_sum > s:
while n_list[right_pointer] == 0:
right_pointer -= 1
# now i stop at the first non-zero
n_list[right_pointer-1] += 1
n_list[right_pointer] = 0
new_pointer = right_pointer -1
while n_list[new_pointer] >= 10:
n_list[new_pointer] %= 10
n_list[new_pointer-1] += 1
new_pointer -= 1
cur_sum = sum(n_list)
# now evaluate the difference
tmp = 0
for i in range(m):
tmp *= 10
tmp += n_list[i]
print(tmp - int(fixn))
``` | output | 1 | 7,736 | 20 | 15,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,737 | 20 | 15,474 |
Tags: greedy, math
Correct Solution:
```
T=int(input())
for t in range(T):
a,b=map(int,input().split())
f=a//b
if a%b==0:
print(0)
else:
print(b*(f+1)-a)
``` | output | 1 | 7,737 | 20 | 15,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,738 | 20 | 15,476 |
Tags: greedy, math
Correct Solution:
```
import sys
input = sys.stdin.readline
sm = lambda x: sum(map(int, str(x)))
for _ in range(int(input())):
n, s = map(int, input().split())
res = 0
while sm(n) > s:
t = 0
while n % pow(10, t) == 0: t += 1
d = -n % pow(10, t)
res += d
n += d
print(res)
``` | output | 1 | 7,738 | 20 | 15,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,739 | 20 | 15,478 |
Tags: greedy, math
Correct Solution:
```
n = int(input())
c = []
for i in range(n):
a, b = input().split()
a, b = int(a), int(b)
if a % b != 0:
c.append(b - a % b)
else:
c.append(0)
for i in c:
print(i)
``` | output | 1 | 7,739 | 20 | 15,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,740 | 20 | 15,480 |
Tags: greedy, math
Correct Solution:
```
R = lambda:map(int,input().split())
t = int(input())
for _ in range(t):
a,b = R()
if a%b == 0: print (0)
else: print ( b - a%b)
``` | output | 1 | 7,740 | 20 | 15,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,741 | 20 | 15,482 |
Tags: greedy, math
Correct Solution:
```
# cook your dish here
t=int(input())
for _ in range(t):
a,b=map(int,input().split())
f=1
if a%b==0:
f=0
print("0")
elif a<b:
f=0
print(b-a)
if f==1:
n=a//b
n+=1
d=b*n
print(d-a)
``` | output | 1 | 7,741 | 20 | 15,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999 | instruction | 0 | 7,742 | 20 | 15,484 |
Tags: greedy, math
Correct Solution:
```
def get_x(n):
x=0
while(n>0):
x+=n%10
n=n//10
return x
def find(k, s):
pos = 1
init = get_x(k)
n=0
while(init > s):
n += pos*(10-k%10)
pos*=10
k = k//10 + 1
init = get_x(k)
return n
for i in range(int(input())):
k, s = [int(j) for j in input().split()]
print(find(k,s))
``` | output | 1 | 7,742 | 20 | 15,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
t=int(input())
c=0
for i in range(0,t):
a,b=input().split()
a=int(a)
b=int(b)
c=0
if(a%b==0):
c=0
else:
c=b-(a%b)
print(c)
``` | instruction | 0 | 7,743 | 20 | 15,486 |
Yes | output | 1 | 7,743 | 20 | 15,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
T = int(input())
for i in range(T):
a, b = map(int, input().split())
div = int(a/b)
if a % b == 0:
print(0)
continue
else:
print((div + 1) * b - a)
``` | instruction | 0 | 7,744 | 20 | 15,488 |
Yes | output | 1 | 7,744 | 20 | 15,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
from datetime import datetime
instanteInicial = datetime.now()
instanteFinal = datetime.now()
testcases = input()
testcases = int(testcases)
for i in range (testcases):
entrada = input().split(" ")
a = int(entrada[0])
b = int(entrada[1])
if a % b == 0:
print(0)
continue
moves = 0
first = True
status = ((a // b) + 1) * b
print(status - a)
``` | instruction | 0 | 7,745 | 20 | 15,490 |
Yes | output | 1 | 7,745 | 20 | 15,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
if a % b == 0:
print(0)
else:
div = a % b
print(b-div)
``` | instruction | 0 | 7,746 | 20 | 15,492 |
Yes | output | 1 | 7,746 | 20 | 15,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
import sys
import argparse
def main():
for _ in(range(int(input()))):
ns = list(map(int,input().split()))
n, s = ns
ss = str(n)
l = "1" + len(ss) * "0"
l = int(l)
steps = l - n
ss = list(map(int,list(ss)))
lss = len(ss)
if sum(ss) == s:
print('0')
else:
strx = ""
tmpsum = 0
for i in range(0,lss):
for j in range(ss[i]+1, 9):
tmp = strx + str(j) + "0" * (lss-i-1)
tmp = int(tmp)
tsum = tmpsum + j
if tsum < s:
steps = min(steps, tmp - n)
strx += str(ss[i])
tmpsum += ss[i]
print(steps)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--file', dest='filename', default=None)
args = parser.parse_args()
if args.filename is not None:
sys.stdin = open(args.filename)
main()
``` | instruction | 0 | 7,747 | 20 | 15,494 |
No | output | 1 | 7,747 | 20 | 15,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
for i in range(int(input())):
(a, b) = map(int, input().split(' '))
c = 0
if a==b:
c+=1
else:
while(1):
if a%b == 0:
break
else:
a += 1
c += 1
print(c)
print(c)
``` | instruction | 0 | 7,748 | 20 | 15,496 |
No | output | 1 | 7,748 | 20 | 15,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).
Output
For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
Example
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Submitted Solution:
```
print(input())
``` | instruction | 0 | 7,749 | 20 | 15,498 |
No | output | 1 | 7,749 | 20 | 15,499 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t tickets, each of which was lucky.
When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.
Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.
What maximum number of tickets could Vasya get after that?
Input
The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.
Output
Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.
Examples
Input
3
123 123 99
Output
1
Input
6
1 1 1 23 10 3
Output
1 | instruction | 0 | 7,922 | 20 | 15,844 |
Tags: greedy
Correct Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n, = I()
l = I()
a = [0]*3
for i in l:
a[i%3] += 1
print(a[0]//2 + min(a[1], a[2]))
``` | output | 1 | 7,922 | 20 | 15,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,419 | 20 | 16,838 |
Tags: brute force, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
S=input().strip()
L=len(S)
ANS1=[0]*(L+10)
ANS2=[0]*(L+10)
ANS3=[0]*(L+10)
for i in range(L-2):
if S[i]==S[i+1]==S[i+2]:
ANS1[i]=1
for i in range(L-4):
if S[i]==S[i+2]==S[i+4]:
ANS2[i]=1
for i in range(L-6):
if S[i]==S[i+3]==S[i+6]:
ANS3[i]=1
SCORE=0
for i in range(L):
if ANS1[i]==1:
SCORE+=max(0,L-i-2)
elif ANS1[i+1]==1:
SCORE+=max(0,L-i-3)
elif ANS1[i+2]==1:
SCORE+=max(0,L-i-4)
elif ANS2[i]==1:
SCORE+=max(0,L-i-4)
elif ANS2[i+1]==1:
SCORE+=max(0,L-i-5)
elif ANS1[i+3]==1:
SCORE+=max(0,L-i-5)
elif ANS1[i+4]==1:
SCORE+=max(0,L-i-6)
elif ANS2[i+2]==1:
SCORE+=max(0,L-i-6)
elif ANS3[i]==1:
SCORE+=max(0,L-i-6)
elif ANS1[i+5]==1:
SCORE+=max(0,L-i-7)
elif ANS2[i+3]==1:
SCORE+=max(0,L-i-7)
elif ANS3[i+1]==1:
SCORE+=max(0,L-i-7)
else:
SCORE+=max(0,L-i-8)
#print(SCORE)
print(SCORE)
``` | output | 1 | 8,419 | 20 | 16,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,420 | 20 | 16,840 |
Tags: brute force, two pointers
Correct Solution:
```
def parse(c, n):
l = [-1] * n
for x in c:
se = set(x)
for i in range(len(x) - 1):
for j in range(i + 1, len(x)):
k = x[j] - x[i]
if k > 20:
break
if x[i] + k + k >= n:
break
if x[i] + k + k in se:
l[x[i] + k + k] = x[i]
break
res = 0
prex = -1
# print(l)
for i in range(n):
if l[i] <= prex:
continue
res = res + (l[i] - prex) * (n - i);
# print(prex + 1, l[i], i + 1, n)
prex = l[i]
return res
if __name__ == '__main__':
s = input()
one = [i for i in range(len(s)) if s[i] == '1']
zero = [i for i in range(len(s)) if s[i] == '0']
# print(one)
# print(zero)
ans = parse((one, zero), len(s))
print(ans)
``` | output | 1 | 8,420 | 20 | 16,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,421 | 20 | 16,842 |
Tags: brute force, two pointers
Correct Solution:
```
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
s = input()
n = len(s)
ans = 0
for i in range(n):
m = 10**6
for k in range(1,5):
for j in range(i,i+7):
if(j + 2*k >= n):
break
if(s[j] == s[j+k] and s[j] == s[j+2*k]):
m = min(m,j+2*k)
if(m != 10**6):
ans += n-m
print(ans)
``` | output | 1 | 8,421 | 20 | 16,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,422 | 20 | 16,844 |
Tags: brute force, two pointers
Correct Solution:
```
s=input()
def pri(l,r):
k=1
while r-2*k>=l:
if s[r]!=s[r-k] or s[r-k]!=s[r-2*k]:
k+=1
continue
return False
return True
ans=0
for i in range(len(s)):
j=i
while j<len(s) and pri(i,j):
j+=1
ans+=len(s)-j
print(ans)
``` | output | 1 | 8,422 | 20 | 16,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,423 | 20 | 16,846 |
Tags: brute force, two pointers
Correct Solution:
```
s = input()
n = len(s)
l = 0
ans = 0
for i in range(n):
for j in range(i - 1, l, -1):
if 2 * j - i < l:
break
if s[i] == s[j] == s[j + j - i]:
ans += ((2 * j - i) - l + 1) * (n - i)
l = (2 * j - i + 1)
print(ans)
``` | output | 1 | 8,423 | 20 | 16,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,424 | 20 | 16,848 |
Tags: brute force, two pointers
Correct Solution:
```
import sys
S = sys.stdin.readline()
S = S.strip()
n = len(S)
ans = 0
def check(i, j) :
if j - i < 3 :
return False
for x in range(i, j) :
for k in range(1, j - i) :
if x + 2 * k >= j :
break
if S[x] == S[x+k] == S[x + 2 * k] :
return True
return False
for i in range(n) :
for j in range(i + 1, min(i + 100, n+1)) :
if check(i, j) :
ans += n - j + 1
break
print(ans)
``` | output | 1 | 8,424 | 20 | 16,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0. | instruction | 0 | 8,425 | 20 | 16,850 |
Tags: brute force, two pointers
Correct Solution:
```
s = input()
n = len(s)
a = [n] * (n + 1)
ans = 0
for i in range(n - 1, -1, -1):
a[i] = a[i + 1]
j = 1
while i + j + j < a[i]:
if s[i] == s[i + j] and s[i] == s[i + j + j]:
a[i] = i + j + j
j += 1
ans += n - a[i]
print(ans)
``` | output | 1 | 8,425 | 20 | 16,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
s = input()
le = len(s)
m = [le] * (le + 1)
ans = 0
for i in range(le - 1, -1, -1):
m[i] = m[i + 1]
k = 1
while k * 2 + i < m[i]:
if s[i] == s[i + k] and s[i] == s[i + 2 * k]:
m[i] = i + 2 * k
k += 1
ans += le - m[i]
print(ans)
``` | instruction | 0 | 8,427 | 20 | 16,854 |
Yes | output | 1 | 8,427 | 20 | 16,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
from sys import stdin
s=stdin.readline().strip()
x=-1
ans=0
for i in range(len(s)):
for j in range(1,10):
if (i-2*j)>=0 and s[i]==s[i-j] and s[i-j]==s[i-2*j]:
if (i-2*j)>x:
ans+=(i-2*j-x)*(len(s)-i)
x=i-2*j
print(ans)
``` | instruction | 0 | 8,428 | 20 | 16,856 |
Yes | output | 1 | 8,428 | 20 | 16,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
#!/usr/bin/env python
# https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py
import os
import sys,math
from io import BytesIO, IOBase
s=None
def isGood(l,r):
global s
for i in range(l,r+1):
p1=i-1; p2=i+1
while p1>=l and p2<=r:
if s[p1]==s[p2]==s[i]:
return True
p1-=1; p2+=1
return False
def main():
global s
s=input()
n=len(s)
ans = 0
for i in range(n):
for j in range(9):
if i+j<n and isGood(i,i+j):
ans+=(n-i-j)
break
print(ans)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 8,429 | 20 | 16,858 |
Yes | output | 1 | 8,429 | 20 | 16,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
import sys
from collections import deque
#from functools import *
#from fractions import Fraction as f
#from copy import *
#from bisect import *
#from heapq import *
#from math import gcd,ceil,sqrt
#from itertools import permutations as prm,product
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def string(s):
return "".join(s)
def fori(n):
return [fi() for i in range(n)]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def bo(i):
return ord(i)-ord('A')
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def cil(n,m):
return n//m+int(n%m>0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j):
return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=1
while t>0:
t-=1
s=si()
n=len(s)
p=[n]*(n+1)
ans=0
for i in range(n):
k=1
while i+2*k<n:
if s[i]==s[i+k]==s[i+2*k]:
p[i]=i+2*k
break
k+=1
for i in range(n-2,-1,-1):
p[i]=min(p[i],p[i+1])
ans+=(n-p[i])
print(ans)
``` | instruction | 0 | 8,430 | 20 | 16,860 |
Yes | output | 1 | 8,430 | 20 | 16,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
s = input()
l = 0
r = len(s)
count = 0
def findxk(l, r):
for x in range(l, r-2):
for k in range(1, (r+1-x)//2):
if s[x] == s[x+k] and s[x] == s[x+2*k]:
return True, x, k
return False, 0, 0
while l < len(s) -2:
valid, x, k = findxk(l,r)
if valid:
count += (x-l+1) * (r-x-2*k)
l = x+1
else:
break
print(count)
``` | instruction | 0 | 8,431 | 20 | 16,862 |
No | output | 1 | 8,431 | 20 | 16,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
s = input()
n = len(s)
ans = 0
for l in range(n):
for k in range(1,n):
if l+2*k >= n:
break
if s[l] == s[l+k] and s[l+k] == s[l+2*k]:
ans += n - (l+2*k)
break
print(ans)
``` | instruction | 0 | 8,432 | 20 | 16,864 |
No | output | 1 | 8,432 | 20 | 16,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
s = input()
l = 0
count = 0
def findxk(l):
for x in range(l, len(s)):
k = 1
while x + 2 * k < len(s):
if s[x] == s[x+k] and s[x] == s[x+k*2]:
return True, x+2*k
k += 1
return False, 0
while l < len(s) -2:
valid, r = findxk(l)
if valid:
count += len(s) - r
l+=1
else:
break
print(count)
``` | instruction | 0 | 8,433 | 20 | 16,866 |
No | output | 1 | 8,433 | 20 | 16,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find this number of pairs for Rash.
Input
The first line contains the string s (1 ≤ |s| ≤ 300 000), consisting of zeros and ones.
Output
Output one integer: the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Examples
Input
010101
Output
3
Input
11001100
Output
0
Note
In the first example, there are three l, r pairs we need to count: 1, 6; 2, 6; and 1, 5.
In the second example, there are no values x, k for the initial string, so the answer is 0.
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(50001)]
pp=[]
def SieveOfEratosthenes(n=50000):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
for i in range(50001):
if prime[i]:
pp.append(i)
#---------------------------------running code------------------------------------------
s=input()
n=len(s)
c=0
for i in range (n-2):
for j in range (i+2,n):
if (i+j)%2==0:
if s[i]==s[(i+j)//2]==s[j]:
c+=n-j
print(i,j,n-j)
break
print(c)
``` | instruction | 0 | 8,434 | 20 | 16,868 |
No | output | 1 | 8,434 | 20 | 16,869 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.