description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
res = n * (n - 1) // 2
cur = 1
for i in range(1, n):
if s[i] == s[i - 1]:
cur += 1
else:
res -= cur
cur = 1
s = s[::-1]
cur = 0
for i in range(1, n):
if s[i] == s[i - 1]:
cur += 1
else:
res -= cur
cur = 0
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
def comp(a):
if a == "A":
return "B"
else:
return "A"
n = int(input())
s = input()
ans = n * (n - 1) // 2
groups = [0]
prev = s[0]
for i in range(1, n):
if s[i] != prev:
groups.append(i)
prev = s[i]
for i in range(0, len(groups) - 2):
ans -= groups[i + 2] - groups[i] - 1
if len(groups) > 1:
ans -= n - groups[-2] - 1
print(ans)
|
FUNC_DEF IF VAR STRING RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
ans = n * (n + 1) / 2 - n
count, i = 0, 0
l = list()
while i < n:
c = s[i]
val = 0
while i < n and s[i] == c:
i += 1
val += 1
l.append(val)
count += len(l) - 1
l = list(map(list, list(zip(l, l[1:]))))
for a, b in l:
count += a - 1 + b - 1
print(int(ans - count))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
x = s[0]
l = 1
r = 0
for i in range(1, n):
y = s[i]
if x == y:
r += i
if l < i:
r -= 1
l += 1
else:
r += i - l
l = 1
x = y
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
tt = n * (n - 1) // 2
s = input().lower()
ss = 0
for i in range(0, n):
if s[i] == "a":
j = i - 1
while j > -1 and s[j] == "b":
ss += 1
j -= 1
j = i + 1
while j < n and s[j] == "b":
ss += 1
j += 1
for i in range(0, n):
if s[i] == "b":
j = i - 1
while j > -1 and s[j] == "a":
ss += 1
j -= 1
j = i + 1
while j < n and s[j] == "a":
ss += 1
j += 1
print(tt - ss + s.count("ab") + s.count("ba"))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
input = sys.stdin.readline
n = int(input())
S = input().strip()
A = []
B = []
for i in range(n):
if S[i] == "A":
A.append(i)
else:
B.append(i)
BE = [-1] * n
for i in range(1, len(A)):
BE[A[i]] = A[i - 1]
for i in range(1, len(B)):
BE[B[i]] = B[i - 1]
LEN = n + 10
BIT = [0] * (LEN + 1)
def update(v, w):
while v <= LEN:
BIT[v] += w
v += v & -v
def getvalue(v):
ANS = 0
while v != 0:
ANS += BIT[v]
v -= v & -v
return ANS
ANS = 0
for i in range(n):
if BE[i] != -1:
update(BE[i] + 1, 1)
ANS += getvalue(BE[i] + 1)
print(ANS)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
prev_b = -1
prev_a = -1
ans = 0
for i in range(n):
if s[i] == "B":
ans += prev_b + 1
if prev_b + 1 == i and prev_a != -1:
ans -= 1
prev_b = i
else:
ans += prev_a + 1
if prev_a + 1 == i and prev_b != -1:
ans -= 1
prev_a = i
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
def main():
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find_root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def size(self, x):
return -self.root[self.find_root(x)]
N = int(input())
s = input().rstrip("\n")
UF = UnionFind(N + 1)
for i in range(N - 1):
if s[i] == s[i + 1]:
UF.unite(i + 1, i + 2)
ans = N * (N - 1) // 2
for i in range(N - 1):
if s[i] != s[i + 1]:
ans -= UF.size(i + 1) + UF.size(i + 2) - 1
print(ans)
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
if n == 1:
print(0)
exit(0)
s = input()
K = []
lc = s[0]
cnt = 0
for i in s:
if i == lc:
cnt += 1
else:
K.append(cnt)
cnt = 1
lc = i
K.append(cnt)
bad = 3 * n - K[0] - K[-1] - (len(K) - 1)
print(n * (n + 1) // 2 - bad)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
count = 0
prev = s[0]
groups = [1]
for i in range(1, n):
if prev == s[i]:
groups[-1] += 1
else:
prev = s[i]
groups.append(1)
for i in range(0, len(groups) - 1):
count += groups[i] + groups[i + 1] - 1
print(n * (n - 1) // 2 - count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
zz = 1
sys.setrecursionlimit(10**5)
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 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 ii():
return input().rstrip()
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 gtc(tc, ans):
print("Case #" + str(tc) + ":", ans)
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, n, m):
return 0 <= i < n and 0 <= j < m
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
uu = t
while t > 0:
t -= 1
n = fi()
s = ii()
d = {}
ans = c = 0
for i in range(n):
if i > 0 and s[i] != s[i - 1]:
ans += i - d.get(s[i], 0) - 1
c += 1
d[s[i]] = i + 1
d = {}
s = s[::-1]
for i in range(n):
if i > 0 and s[i] != s[i - 1]:
ans += i - d.get(s[i], 0) - 1
c += 1
d[s[i]] = i + 1
print(n * (n - 1) // 2 - ans - c // 2)
|
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
from sys import stdin
n = int(input())
s = stdin.read(n)
ans = n * (n - 1) // 2
k = 0
m = 0
for i in range(1, n):
p = s[i - 1]
t = s[i]
if p == t:
k += 1
else:
ans -= k * (1 << m) + 1
m |= 1
k = 0
else:
ans -= k * m
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
from sys import stdin, stdout
n = int(stdin.readline().strip())
s = stdin.readline().strip()
acumA = [(0) for i in range(n + 3)]
acumB = [(0) for i in range(n + 3)]
dictA = [(-1) for i in range(n + 3)]
dictB = [(-1) for i in range(n + 3)]
for i in range(n):
if i != 0:
acumA[i] += acumA[i - 1]
acumB[i] += acumB[i - 1]
if s[i] == "A":
acumA[i] += 1
dictA[acumA[i]] = i
if s[i] == "B":
acumB[i] += 1
dictB[acumB[i]] = i
ans = 0
for i in range(n - 1):
if s[i] == "A":
if dictA[acumA[i] + 1] == -1:
continue
x = dictB[acumB[i] + 1]
if x == -1:
x = n
ans += x - i - 1
x = dictB[acumB[i] + 1]
if x == -1:
continue
x = max(dictB[acumB[i] + 1], dictA[acumA[i] + 1] - 1)
ans += n - x - 1
else:
if dictB[acumB[i] + 1] == -1:
continue
x = dictA[acumA[i] + 1]
if x == -1:
x = n
ans += x - i - 1
x = dictA[acumA[i] + 1]
if x == -1:
continue
x = max(dictA[acumA[i] + 1], dictB[acumB[i] + 1] - 1)
ans += n - x - 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
readline = sys.stdin.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep="\n")
def solve():
n = ni()
s = ns() + "$"
c = n * (n - 1) // 2
l = list()
k = s[0]
t = 0
for x in s:
if x == k:
t += 1
else:
l.append(t)
k = x
t = 1
m = len(l)
for i in range(m - 1):
x, y = l[i], l[i + 1]
c -= x + y - 1
print(c)
return
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
x = str(input())
count = 1
ans = n * (n - 1) / 2
dp = []
for i in range(1, n):
if x[i] == x[i - 1]:
count += 1
if x[i] != x[i - 1]:
dp.append(count)
count = 1
if i == n - 1:
dp.append(count)
for i in range(len(dp)):
if len(dp) == 1:
pass
elif i == 0:
ans -= dp[i + 1]
elif i == len(dp) - 1:
ans -= dp[i - 1]
else:
ans -= dp[i - 1] + dp[i + 1]
print(int(ans + len(dp) - 1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
arr = []
for i in range(n):
c = 0 if s[i] == "A" else 1
if not arr or arr[-1][0] != c:
arr.append([c, 1])
else:
arr[-1][1] += 1
cnt = (n * n + n) // 2
if len(arr) == 1:
print(cnt - n)
exit()
for i in range(0, len(arr)):
cnt -= arr[i][1] + (arr[i][1] if i != 0 and i != len(arr) - 1 else 0)
print(cnt - n + len(arr) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
cnt = n
for x in range(2):
cur = 1
for i in range(1, n):
if s[i] == s[i - 1]:
cur += 1
else:
cnt += cur - x
cur = 1
s = s[::-1]
print(n * (n + 1) // 2 - cnt)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
def solve():
n = int(input())
s = input()
res = n * (n - 1) // 2
cur = 1
start = 0
end = n - 1
for i in range(1, n):
if s[i] == s[i - 1]:
cur += 1
else:
res -= cur - 1
start = i
cur = 1
break
for i in range(n - 2, -1, -1):
if s[i] == s[i + 1]:
cur += 1
else:
res -= cur - 1
end = i + 1
cur = 1
break
for i in range(start, end + 1):
if s[i] == s[i - 1]:
cur += 1
else:
res -= 2 * cur - 1
cur = 1
print(res)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
a, b, c = -1, -1, 0
for i in range(n):
if s[i] == "A":
c += i - a - 1
a = i
else:
c += i - b - 1
b = i
t = s[::-1]
a, b = -1, -1
for i in range(n):
if t[i] == "A":
c += max(0, i - a - 2)
a = i
else:
c += max(0, i - b - 2)
b = i
print(n * (n - 1) // 2 - c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
X = input()
X = input()
a, b, c, d, k = 0, 0, 1, 1, 1
l = len(X)
for i in range(1, l):
if X[i] == X[i - 1]:
if c != 1:
c += 1
b += 1
else:
c += 1
b += d
else:
if c != 1:
b += 2 - c - k
d = c
c = 1
else:
b += d - k
d = 1
c = 1
k = 0
a += b
print(a)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N = INT()
S = input()
total = (N + 1) * N // 2
ans = total - N
L = []
cnt = 1
for i in range(1, N):
if S[i - 1] == S[i]:
cnt += 1
else:
L.append(cnt)
cnt = 1
R = []
cnt = 1
for i in range(N - 2, -1, -1):
if S[i + 1] == S[i]:
cnt += 1
else:
R.append(cnt)
cnt = 1
ans -= sum(L) + sum(R) - len(L)
print(ans)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
from sys import setrecursionlimit, stdin
setrecursionlimit(10**7)
def iin():
return int(stdin.readline())
def lin():
return list(map(int, stdin.readline().split()))
def main():
n = iin()
s = list(input())
ans = n * (n - 1) // 2
for i in range(2):
ch = 1
for j in range(1, n):
if s[j] == s[j - 1]:
ch += 1
else:
ans -= ch - i
ch = 1
s = s[::-1]
print(ans)
main()
|
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
N = int(input())
S = list(input())
pre = S[0]
A = []
a = 0
for s in S:
if s == pre:
a += 1
else:
A.append(a)
a = 1
pre = s
A.append(a)
q = 0
for i in range(len(A) - 1):
q += A[i] + A[i + 1] - 1
ans = N * (N - 1) // 2 - q
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import itertools
n = int(input())
s = input()
x = []
for k, g in itertools.groupby(s):
l = len(list(g))
x += [l]
bad = 0
for f, g in zip(x, x[1:]):
bad += f + g - 1
good = n * (n + 1) // 2 - n - bad
print(good)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
from itertools import groupby
n = int(input())
a = [len(list(v)) for k, v in groupby(input())]
ans = n * (n - 1) // 2
for x, y in zip(a, a[1:]):
ans -= x + y - 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
tab = []
count = 1
for i in range(1, n):
if s[i] == s[i - 1]:
count += 1
else:
if count > 0:
tab.append(count)
count = 1
if count > 0:
tab.append(count)
dis = 0
k = len(tab)
if k == 0 or k == 1:
dis = 0
else:
dis += tab[1]
dis += tab[-2]
dis -= k - 1
for i in range(1, k - 1):
dis += tab[i - 1]
dis += tab[i + 1]
print(n * (n - 1) // 2 - dis)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
length = int(input())
s = input()
substrings = sum(range(length + 1))
substrings -= length
transitioned = False
journey = 0
i = 0
current_character = s[i]
journey += 1
i += 1
while i < length:
if s[i] == current_character:
journey += 1
else:
if journey > 1:
if i == journey:
substrings -= journey - 1
else:
substrings -= 2 * journey - 2
substrings -= 1
transitioned = True
journey = 1
current_character = s[i]
i += 1
if journey > 1 and transitioned:
substrings -= journey - 1
print(substrings)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
def solve():
n = int(input())
array = input()
i, j = 0, 0
totalBadString = 0
l = [0, 0]
l[ord(array[i]) - 65] += 1
while i < n - 1 and j < n:
if l[0] == 1 and l[1] >= 1 or l[1] == 1 and l[0] >= 1:
if l[0] == 1 and l[1] == 1:
expectedValue = array[j]
while array[j] == expectedValue:
totalBadString += 1
j += 1
if j < n:
l[ord(array[j]) - 65] += 1
else:
break
i += 1
l[ord(array[i - 1]) - 65] -= 1
else:
while l[0] == 1 and l[1] >= 1 or l[1] == 1 and l[0] >= 1:
totalBadString += 1
i += 1
l[ord(array[i - 1]) - 65] -= 1
i -= 1
totalBadString -= 1
l[ord(array[i]) - 65] += 1
else:
j += 1
if j < n:
l[ord(array[j]) - 65] += 1
else:
break
print(n * (n - 1) // 2 - totalBadString)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
S = input()
pa = -1
pb = -1
cnt = 0
for i, s in enumerate(S):
if s == "A":
if pa == -1:
pa = i
else:
cnt += pa + 1
if S[i - 1] == "A" and pb != -1:
cnt -= 1
pa = i
if s == "B":
if pb == -1:
pb = i
else:
cnt += pb + 1
if S[i - 1] == "B" and pa != -1:
cnt -= 1
pb = i
print(cnt)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
readline = sys.stdin.readline
N = int(readline())
S = [(1 if s == "A" else 0) for s in readline().strip()]
ans = 0
L1 = [None] * (N + 1)
L2 = [None] * (N + 1)
for i in range(N - 1, -1, -1):
s = S[i]
L1[i] = L1[i + 1]
L2[i] = L2[i + 1]
if s == 1:
L1[i] = i
else:
L2[i] = i
for i in range(N - 1):
s = S[i]
sn = S[i + 1]
if s == sn:
if s == 1:
if L2[i] is not None:
ans -= 1
elif L1[i] is not None:
ans -= 1
elif s == 1:
if L1[i + 1] is None:
ans -= N - i - 1
else:
ans -= L1[i + 1] - (i + 1)
elif L2[i + 1] is None:
ans -= N - i - 1
else:
ans -= L2[i + 1] - (i + 1)
print((N - 1) * N // 2 + ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER IF VAR VAR NONE VAR NUMBER IF VAR VAR NONE VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NONE VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NONE VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
blocks = 1
first = 1
last = 1
while first < n and s[first] == s[first - 1]:
first += 1
while last < n and s[-last - 1] == s[-last]:
last += 1
for i in range(1, n):
if s[i] != s[i - 1]:
blocks += 1
print(n * (n - 1) // 2 - (2 * n + 1 - first - last - blocks))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = list(input())
u = []
k = 1
for i in range(1, n):
if s[i] != s[i - 1]:
u.append(k)
k = 1
else:
k += 1
u.append(k)
ans = n * (n - 1) // 2
for i in range(1, len(u)):
ans -= u[i - 1]
ans -= u[i]
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
import sys
def main():
n = int(input())
s = input()
groupSizes = []
sz = 0
for i in range(n):
if i - 1 >= 0 and s[i] != s[i - 1]:
groupSizes.append(sz)
sz = 0
sz += 1
groupSizes.append(sz)
badCnts = 0
m = len(groupSizes)
for i in range(m):
if i + 1 < m:
badCnts += groupSizes[i + 1]
if i - 1 >= 0:
badCnts += groupSizes[i - 1]
badCnts -= m - 1
ans = n * (n - 1) // 2 - badCnts
print(ans)
return
input = lambda: sys.stdin.readline().rstrip("\r\n")
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultValFactory, dimensionArr):
dv = defaultValFactory
da = dimensionArr
if len(da) == 1:
return [dv() for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
p = int(input())
s = input()
i = 0
cnt_Bad = 0
leng = 0
while i < len(s):
if s[i] == "A":
i += 1
while i < len(s) and s[i] == "B":
i += 1
leng += 1
else:
i += 1
cnt_Bad += leng
i = 0
leng = 0
while i < len(s):
if s[i] == "B":
i += 1
while i < len(s) and s[i] == "A":
i += 1
leng += 1
else:
i += 1
cnt_Bad += leng
i = len(s) - 1
leng = 0
while i >= 0:
if s[i] == "B":
i -= 1
while i >= 0 and s[i] == "A":
i -= 1
leng += 1
else:
i -= 1
cnt_Bad += leng
i = len(s) - 1
leng = 0
while i >= 0:
if s[i] == "A":
i -= 1
while i >= 0 and s[i] == "B":
i -= 1
leng += 1
else:
i -= 1
cnt_Bad += leng
i = 0
leng = 0
while i < len(s) - 1:
if s[i] == "B" and s[i + 1] == "A" or s[i] == "A" and s[i + 1] == "B":
leng += 1
i += 1
cnt_Bad -= leng
print((len(s) ** 2 - len(s)) // 2 - cnt_Bad)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
a = list(input())
A = B = -1
index = [0] * n
arr = 0
is_a = -1
is_b = -1
for i in range(n - 1, -1, -1):
if a[i] == "A":
index[i] = A
if A == -1:
is_a = i
A = i
else:
index[i] = B
if B == -1:
is_b = i
B = i
for i in range(n):
if index[i] - 1 == i:
if a[i] == "A":
if is_b >= i:
arr -= 1
elif is_a >= i:
arr -= 1
if index[i] != -1:
arr += n - index[i]
print(arr)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR IF VAR VAR STRING IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input().rstrip()
s += "#"
ans = (n - 1) * n // 2
if "A" not in s or "B" not in s:
print(ans)
exit()
cnt = 0
counts = []
for i, ch in enumerate(s):
if i == 0:
prev = ch
cnt += 1
continue
if prev == ch:
cnt += 1
else:
counts.append(cnt)
cnt = 1
prev = ch
for c1, c2 in zip(counts, counts[1:]):
ans -= c1 + c2 - 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF STRING VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
The string $t_1t_2 \dots t_k$ is good if each letter of this string belongs to at least one palindrome of length greater than 1.
A palindrome is a string that reads the same backward as forward. For example, the strings A, BAB, ABBA, BAABBBAAB are palindromes, but the strings AB, ABBBAA, BBBA are not.
Here are some examples of good strings: $t$ = AABBB (letters $t_1$, $t_2$ belong to palindrome $t_1 \dots t_2$ and letters $t_3$, $t_4$, $t_5$ belong to palindrome $t_3 \dots t_5$); $t$ = ABAA (letters $t_1$, $t_2$, $t_3$ belong to palindrome $t_1 \dots t_3$ and letter $t_4$ belongs to palindrome $t_3 \dots t_4$); $t$ = AAAAA (all letters belong to palindrome $t_1 \dots t_5$);
You are given a string $s$ of length $n$, consisting of only letters A and B.
You have to calculate the number of good substrings of string $s$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 3 \cdot 10^5$) β the length of the string $s$.
The second line contains the string $s$, consisting of letters A and B.
-----Output-----
Print one integer β the number of good substrings of string $s$.
-----Examples-----
Input
5
AABBB
Output
6
Input
3
AAA
Output
3
Input
7
AAABABB
Output
15
-----Note-----
In the first test case there are six good substrings: $s_1 \dots s_2$, $s_1 \dots s_4$, $s_1 \dots s_5$, $s_3 \dots s_4$, $s_3 \dots s_5$ and $s_4 \dots s_5$.
In the second test case there are three good substrings: $s_1 \dots s_2$, $s_1 \dots s_3$ and $s_2 \dots s_3$.
|
n = int(input())
s = input()
ans = int(n * (n - 1) / 2)
c = 0
for i in range(n):
if s[i] == "A":
c += 1
else:
if c > 1:
ans -= c - 1
c = 0
c = 0
for i in range(n):
if s[i] == "B":
c += 1
else:
if c > 1:
ans -= c - 1
c = 0
s = s[::-1]
c = 0
for i in range(n):
if s[i] == "A":
c += 1
else:
if c > 1:
ans -= c - 1
c = 0
c = 0
for i in range(n):
if s[i] == "B":
c += 1
else:
if c > 1:
ans -= c - 1
c = 0
c = 0
if s[0] == "A":
c += 1
for i in range(n):
if s[i] == "A":
c += 1
elif c >= 1:
ans -= 1
c = 0
c = 0
if s[0] == "B":
c += 1
for i in range(n):
if s[i] == "B":
c += 1
elif c >= 1:
ans -= 1
c = 0
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed $3$. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.
Your character has also found an artifact that boosts the damage of some of your actions: every $10$-th card you play deals double damage.
What is the maximum possible damage you can deal during $n$ turns?
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the number of turns.
Then $n$ blocks of input follow, the $i$-th block representing the cards you get during the $i$-th turn.
Each block begins with a line containing one integer $k_i$ ($1 \le k_i \le 2 \cdot 10^5$) β the number of cards you get during $i$-th turn. Then $k_i$ lines follow, each containing two integers $c_j$ and $d_j$ ($1 \le c_j \le 3$, $1 \le d_j \le 10^9$) β the parameters of the corresponding card.
It is guaranteed that $\sum \limits_{i = 1}^{n} k_i \le 2 \cdot 10^5$.
-----Output-----
Print one integer β the maximum damage you may deal.
-----Example-----
Input
5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100
Output
263
-----Note-----
In the example test the best course of action is as follows:
During the first turn, play all three cards in any order and deal $18$ damage.
During the second turn, play both cards and deal $7$ damage.
During the third turn, play the first and the third card and deal $13$ damage.
During the fourth turn, play the first and the third card and deal $25$ damage.
During the fifth turn, play the only card, which will deal double damage ($200$).
|
from sys import exit, stdin, stdout
n = int(input())
inf = 10**18
dp = [([-inf] * 10) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n):
k = int(stdin.readline())
cards = []
for j in range(k):
c, d = map(int, stdin.readline().split())
cards.append((c, d))
cards.sort(reverse=True)
cards_by_cost = [[] for i in range(3)]
for c, d in cards:
cards_by_cost[c - 1].append(d)
for j in range(3):
cards_by_cost[j] = cards_by_cost[j][:3]
for prev_played in range(10):
val = dp[i][prev_played]
dp[i + 1][prev_played] = max(dp[i + 1][prev_played], val)
for num_played in range(len(cards_by_cost[0])):
pld = num_played + prev_played + 1
if pld >= 10:
dp[i + 1][pld % 10] = max(
dp[i + 1][pld % 10],
val + sum(cards_by_cost[0][: num_played + 1]) + cards_by_cost[0][0],
)
else:
dp[i + 1][pld] = max(
dp[i + 1][pld], val + sum(cards_by_cost[0][: num_played + 1])
)
if len(cards_by_cost[1]) > 0 and len(cards_by_cost[0]) > 0:
pld = 2 + prev_played
c0 = cards_by_cost[0][0]
c1 = cards_by_cost[1][0]
if pld >= 10:
dp[i + 1][pld % 10] = max(
dp[i + 1][pld % 10], val + c0 + c1 + max(c0, c1)
)
else:
dp[i + 1][pld] = max(dp[i + 1][pld], val + c0 + c1)
if len(cards_by_cost[1]) > 0:
pld = 1 + prev_played
if pld >= 10:
dp[i + 1][pld % 10] = max(
dp[i + 1][pld % 10], val + 2 * cards_by_cost[1][0]
)
else:
dp[i + 1][pld] = max(dp[i + 1][pld], val + cards_by_cost[1][0])
if len(cards_by_cost[2]) > 0:
pld = 1 + prev_played
if pld >= 10:
dp[i + 1][pld % 10] = max(
dp[i + 1][pld % 10], val + 2 * cards_by_cost[2][0]
)
else:
dp[i + 1][pld] = max(dp[i + 1][pld], val + cards_by_cost[2][0])
ans = max(dp[n][i] for i in range(10))
stdout.write(str(ans) + "\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
input = sys.stdin.readline
a = [(0, 0), (2, 0), (0, 0), (2, 1)]
h = [(1, 0), (1, 0), (3, 0), (1, 0)]
z = [(0, 0), (0, 0), (0, 0), (0, 0)]
def f_s(x):
r = 0
for i in range(1, x + 1):
si = str(i)
sii = str(i - 1)
if len(si) > len(sii):
sii = "0" + sii
for j in range(len(si)):
r += si[j] != sii[j]
return r
def f(x):
r = x
while x != 0:
x //= 10
r += x
return r
def solve():
l, r = map(int, input().split())
print(f(r) - f(l))
for i in range(int(input())):
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = t = int(input().strip())
for _ in range(t):
l, r = map(int, input().strip().split())
ans, ok = 0, 1
while ok <= r:
ans += r // ok - l // ok
ok *= 10
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
a, b = input().split()
m, n = len(a), len(b)
a = "0" * (n - m) + a
ans = 0
for i in range(1, 1 + len(b)):
ans += int(b[:i]) - int(a[:i])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for _ in range(t):
a, b = list(map(int, input().split()))
ans1 = b
i = 10
while i <= b:
ans1 += b // i
i *= 10
ans0 = a
i = 10
while i <= a:
ans0 += a // i
i *= 10
print(ans1 - ans0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = list(map(int, input().split(" ")))
res = r - l
while r > 0:
r //= 10
l //= 10
res += r - l
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
a, b = map(str, input().split())
x = a[::-1]
y = b[::-1]
n = len(x)
m = len(b)
l = [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111]
ans = 0
for i in range(m):
c = ord(y[i]) - 48
ans += c * l[i]
for i in range(n):
c = ord(x[i]) - 48
ans -= c * l[i]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def s(n):
l = len(str(n))
ret = 0
for i in str(n):
ret += int(i * l)
l -= 1
return ret
for _ in range(int(input())):
a, b = input().split()
a, b = int(a), int(b)
print(s(b) - s(a))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
n = int(input())
while n:
a, b = list(map(int, input().split()))
ans = 0
cnt = 0
while b:
q = b % 10
q = 10 if not q else q
ans += b - a
b //= 10
a //= 10
cnt += 1
print(ans)
n -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
def solve():
l, r = map(int, input().split())
ans = 0
while r > 0:
ans += r - l
r //= 10
l //= 10
print(ans)
for i in range(t):
solve()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
from sys import maxsize
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
def get_list_string():
return list(map(str, sys.stdin.readline().strip().split()))
def get_string():
return sys.stdin.readline().strip()
def get_int():
return int(sys.stdin.readline().strip())
def get_print_int(x):
sys.stdout.write(str(x) + "\n")
def get_print(x):
sys.stdout.write(x + "\n")
def get_print_int_same(x):
sys.stdout.write(str(x) + " ")
def get_print_same(x):
sys.stdout.write(x + " ")
def solve():
for _ in range(get_int()):
l, r = get_ints()
ans = 0
while r:
ans += r - l
r //= 10
l //= 10
get_print_int(ans)
solve()
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for _ in range(t):
l, r = map(int, input().split())
n = len(str(r))
ans = 0
for i in range(n):
currl = l // 10**i
currr = r // 10**i
ans += currr - currl
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
T = int(input())
for t in range(T):
l, r = map(int, input().split())
ans = 0
for i in range(10):
div = 10**i
ans += r // div - l // div
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for u in range(int(input())):
l, r = map(int, input().split())
ans = 0
f = 1
while f <= r:
ans += r // f
f *= 10
f = 1
while f <= l:
ans -= l // f
f *= 10
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for tt in range(t):
l, r = input().strip().split(" ")
l = int(l)
r = int(r)
ll = l // 10
rr = r // 10
while ll:
l += ll
ll = ll // 10
while rr:
r += rr
rr = rr // 10
print(r - l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
a = int(input())
for i in range(a):
s = input()
s = s.split()
num1, num2 = int(s[0]), int(s[1])
digit = 0
ans = 0
while True:
cnt = num2 // 10**digit - num1 // 10**digit
if cnt == 0:
break
ans += cnt
digit += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def main():
def solve(arr):
ans = 0
l, r = arr
while l > 0 or r > 0:
ans += r - l
r = r // 10
l = l // 10
return ans
number_tests = int(input())
for _ in range(number_tests):
arr = list(map(int, input().split()))
print(solve(arr))
main()
|
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for _ in range(t):
l, r = map(int, input().split())
c1 = r - l
for i in range(1, 10):
c1 += r // 10**i
c2 = 0
for i in range(1, 10):
c2 += l // 10**i
print(c1 - c2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
out = []
def get_sum(l, r):
sum = r - l
dr = r // 10
dl = l // 10
while dr > 0:
sum += dr - dl
dr = dr // 10
dl = dl // 10
return sum
for i in range(t):
l, r = map(int, input().split())
out.append(get_sum(l, r))
for i in range(t):
print(out[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for i in range(t):
l, r = map(str, input().split())
ans, pres = 0, 0
while len(l) < len(r):
l = "0" + l
for i in range(len(l)):
if l[i] == r[i] and pres == 0:
continue
el1 = int(l[i])
el2 = int(r[i])
if pres == 0:
ans = el2 - el1
pres = ans
else:
temp = 10 - el1 + (pres - 1) * 10 + el2
ans += temp
pres = temp
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = map(int, input().split())
ansl = 0
ansr = 0
ansl += l - 1
ansr += r - 1
while l:
ansl += l // 10
l //= 10
while r:
ansr += r // 10
r //= 10
print(ansr - ansl)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def f(n):
val, ans = 1, 0
while n:
v = n % 10
ans += val * v
n //= 10
val = 10 * val + 1
return ans
for _ in range(int(input())):
l, r = map(int, input().split())
print(f(r) - f(l))
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
dic = {
(10): 11,
(100): 111,
(1000): 1111,
(10000): 11111,
(100000): 111111,
(1000000): 1111111,
(10000000): 11111111,
(100000000): 111111111,
(1000000000): 1111111111,
}
def foo(diff):
start = 0
ans = 0
while diff >= test[-1]:
if diff >= test[start]:
divisor = diff // test[start]
ans += dic[test[start]] * divisor
diff -= divisor * test[start]
start += 1
if start > 8:
break
ans += diff
return ans
test = list(dic.keys())
test.sort(reverse=True)
t = int(input())
for i in range(t):
n = input()
l, r = n.split(" ")
l = int(l)
r = int(r)
rans = foo(r)
lans = foo(l)
print(rans - lans)
|
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
a = b = c = d = e = f = g = h = j = 0
ans = 0
for i in range(t):
ll, r = input().split(" ")
ll, r = int(ll), int(r)
a = r // 10 - ll // 10
b = r // 100 - ll // 100
c = r // 1000 - ll // 1000
d = r // 10000 - ll // 10000
e = r // 100000 - ll // 100000
f = r // 1000000 - ll // 1000000
g = r // 10000000 - ll // 10000000
h = r // 100000000 - ll // 100000000
j = r // 1000000000 - ll // 1000000000
ans = r - ll + a + b + c + d + e + f + g + h + j
print(ans)
ans = 0
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def func(r):
if r == 1:
return 0
total_digits = len(str(r))
nums_divisible_by_ten = [(0) for i in range(total_digits + 1)]
starting = total_digits - 1
count = 0
while starting > 0:
divisor = 10**starting
nums_divisible_by_ten[starting] = r // divisor - count
count = r // divisor
starting -= 1
total_sum = 0
for j in range(1, total_digits + 1):
total_sum += nums_divisible_by_ten[j] * (j + 1)
total_sum += r - sum(nums_divisible_by_ten) - 1
return total_sum
t = int(input())
for i in range(t):
l, r = map(int, input().split())
print(func(r) - func(l))
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for i in range(int(input())):
r, l = map(int, input().split())
ans = 0
while l >= 1:
ans += l - r
r //= 10
l //= 10
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def main(l, r):
res = 0
while l or r:
res += r - l
l //= 10
r //= 10
return res
t = int(input().strip())
for _ in range(t):
l, r = map(int, input().strip().split())
print(main(l, r))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def count(n):
ans = (
n // 10
+ n // 100
+ n // 1000
+ n // 10000
+ +(n // 100000)
+ n // 1000000
+ n // 10000000
+ n // 100000000
+ n // 1000000000
)
return ans
for _ in range(int(input())):
a, b = map(int, input().split())
left = a + count(a)
right = b + count(b)
print(right - left)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for i in range(0, t):
l, r = map(int, input().split())
a = 0
while l != 0 or r != 0:
a = a + abs(l - r)
l //= 10
r //= 10
print(a)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def fun(n):
s, c = 10, n - 1
while s <= n:
c += n // s
s *= 10
return c
for _ in range(int(input())):
l, r = list(map(int, input().split()))
print(fun(r) - fun(l))
|
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def sol1toA(A):
count = A - 1
while A > 0:
A = A // 10
count += A
return count
def sol(a, b):
return sol1toA(b) - sol1toA(a)
x = int(input())
for _ in range(x):
A = list(map(int, input().split()))
print(sol(A[0], A[1]))
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
test_cases = int(input())
for test_case in range(test_cases):
l, r = list(map(int, input().split()))
ans = 0
while r > 0:
ans += r - l
r = int(r / 10)
l = int(l / 10)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
while t:
l, r = map(int, input().split())
c = r - l
s = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
sum = 0
while c > 0:
for i in range(10):
a = c // 10 ** s[i]
if a > 0:
c = c - a * 10 ** s[i]
d = s[i]
k = r - c
o = k
k = list(str(k))
l = list(str(l))
K = len(k)
L = len(l)
if K == L + 1 and L >= s[i] + 1:
sum = sum + 1
K = K - 1
m = 1
del k[0]
if L - s[i] - 1 > 0:
for p in range(L - s[i] - 1):
if l[p] != k[p]:
sum = sum + (L - s[i] - 1 - p)
break
for j in range(d + 1):
sum = sum + a * 10**j
l = o
print(sum)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def interesting_function(l, r):
result = 0
while r > 0:
result += r - l
r //= 10
l //= 10
print(result)
t = int(input())
for _ in range(t):
inputs = list(map(str, input().split()))
interesting_function(int(inputs[0]), int(inputs[1]))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
d = [
0,
10,
110,
1110,
11110,
111110,
1111110,
11111110,
111111110,
1111111110,
11111111110,
111111111110,
]
t = int(input())
for _ in range(t):
l, r = map(int, input().split())
lans = 0
rans = 0
mult = 1
count = 0
while l > 0:
ldigit = l % 10
if ldigit > 0:
count += 1
lans += ldigit * d[mult - 1] + (ldigit - 1)
l = int(l / 10)
mult = mult + 1
lans += count - 1
mult = 1
count = 0
while r > 0:
ldigit = r % 10
if ldigit > 0:
count += 1
rans += ldigit * d[mult - 1] + (ldigit - 1)
r = int(r / 10)
mult = mult + 1
rans += count - 1
print(rans - lans)
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def calc(x):
f = 1
ans = []
while f <= x:
ans.append(x // f)
f *= 10
return sum(ans)
for case in range(int(input())):
l, r = [int(x) for x in input().split()]
print(calc(r) - calc(l))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for z in range(t):
l, r = map(int, input().split())
ans = 0
x = str(l)[::-1]
y = str(r)[::-1]
for i in range(0, len(y)):
s = int("1" * (i + 1))
tp1 = int(y[i]) % 10 ** (i + 1)
ans += tp1 * s
for i in range(0, len(x)):
s = int("1" * (i + 1))
tp1 = int(x[i]) % 10 ** (i + 1)
ans -= tp1 * s
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for t in range(int(input())):
x, y = input().split()
x = int(x)
y = int(y)
r = 0
while y:
r += y - x
x //= 10
y //= 10
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for i in range(int(input())):
l, r = list(map(int, input().split()))
a = 0
b = 0
for i in range(1, 10):
a += l // 10**i
b += r // 10**i
print(b - a + r - l)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = map(int, input().split())
ans = r - l
cnt = 0
x = r
y = l
sc = 0
while y != 0:
y = y // 10
sc = sc + y
while x != 0:
x = x // 10
cnt = cnt + x
print(cnt - sc + ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for i in range(t):
l, r = map(int, input().split())
res = r - l
while r // 10 >= 10:
r //= 10
l //= 10
res += r - l
print(r // 10 - l // 10 + res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in [*open(0)][1:]:
q, w = _.split()
q, e = "000000000" + q, 0
for i in range(len(w)):
e += int(w) - int(q)
w = w[:-1]
q = q[:-1]
print(e)
|
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def funct(l, r):
out = 0
for i in range(0, 13):
f = 10**i
out = out + (r // f - l // f)
return out
for _ in range(int(input())):
l, r = map(int, input().split())
print(funct(l, r))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
input = sys.stdin.readline
def f(a):
ok = 0
while a > 0:
ok += a
a = a // 10
return ok
t = int(input())
for you in range(t):
l = input().split()
a = int(l[0])
b = int(l[1])
print(f(b) - f(a))
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = map(int, input().split())
x = r - l
y = (
x
+ (r // 10 - l // 10)
+ (r // 100 - l // 100)
+ (r // 1000 - l // 1000)
+ (r // 10000 - l // 10000)
+ (r // 100000 - l // 100000)
+ (r // 1000000 - l // 1000000)
+ (r // 10000000 - l // 10000000)
+ (r // 100000000 - l // 100000000)
+ (r // 1000000000 - l // 1000000000)
)
print(y)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
a, b = map(str, input().split())
a = a[::-1]
b = b[::-1]
aa = 0
bb = 0
for i in range(len(b)):
bb += int((i + 1) * "1") * int(b[i])
for i in range(len(a)):
aa += int((i + 1) * "1") * int(a[i])
print(bb - aa)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
L, R = [int(x) for x in input().split()]
ans = R - L
cnt_r = 0
cnt_l = 0
for i in range(1, 20):
cnt_r += R // pow(10, i)
cnt_l += L // pow(10, i)
ans += cnt_r - cnt_l
print(ans)
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def count(s):
ans = 0
for i in range(len(s), 0, -1):
ans += int(s[:i])
return ans
for t in range(int(input())):
l, r = input().split()
print(count(r) - count(l))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def f(l, r):
if r == 0:
return 0
else:
return r - l + f(l // 10, r // 10)
t = int(input())
for _ in range(t):
l, r = map(int, input().split())
print(f(l, r))
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for j in range(t):
l, r = map(int, input().split())
count = 0
sum = 0
ll = str(l)
sum += 1
rr = str(r)
sum += 1
ll = (len(rr) - len(ll)) * "0" + ll
sum += 1
n = len(rr)
sum += 1
for i in range(n):
sum += 1
s1 = int(ll[: n - i])
sum += 1
s2 = int(rr[: n - i])
sum += 1
count += s2 - s1
sum += 1
i += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
oneee = 64656
l, r = map(int, input().split())
dxds = 3545
t = r
zsfv = 6435
ans = 0
segdvz = 5844
a1 = [0] * len(str(t))
tdgssge = True
z = str(l)[::-1]
for i in range(len(str(l))):
drgdrg = False
a1[-(i + 1)] = int(z[i])
sef = 354
a2 = [int(i) for i in str(t)]
p1 = str()
sgv = 58
p2 = str()
sefds = 35435
for i in range(len(a2)):
dxgv = 3543543
p1 += str(a2[i])
xdgvsrv = 3434
p2 += str(a1[i])
sgdvsef = 34354
ans += int(p1) - int(p2)
afeaesd = 34535
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for s in [*open(0)][1:]:
r = 0
k = -1
for x in map(int, s.split()):
while x:
r += k * x
x //= 10
k = 1
print(r)
|
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for w in range(t):
l, r = [x for x in input().split()]
a = [int(x) for x in l]
b = [int(x) for x in r]
count = 0
while len(a) > 0 or len(b) > 0:
s_a = 0
s_b = 0
for i in range(len(a)):
s_a += a[i]
s_a *= 10
for i in range(len(b)):
s_b += b[i]
s_b *= 10
s_a //= 10
s_b //= 10
count += s_b - s_a
if len(a) > 0:
a.pop()
b.pop()
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = map(int, input().split())
s = int("1" + (len(str(r)) - 1) * "0")
i = s
prev = 0
ans = 0
prod = len(str(s))
while i > 0:
boom = r // i - l // i - prev
prev += boom
ans += boom * prod
i //= 10
prod -= 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
while t > 0:
t -= 1
a = [int(i) for i in input().split(" ")]
f, e = a[0], a[1]
out = e - f
while e > 0:
out += e // 10 - f // 10
f //= 10
e //= 10
print(out)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
def solve():
l, r = map(int, input().split())
answer = 0
while r > 0:
answer += r - l
r //= 10
l //= 10
return answer
t = int(input())
while t > 0:
t -= 1
print(solve())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
for jj in range(t):
l, r = list(map(int, input().split()))
l = str(l)
r = str(r)
while len(l) != len(r):
l = "0" + l
ans = 0
old = 0
for i in range(len(l)):
diff = int(r[i]) - int(l[i])
ans += old * 10 + diff
old = old * 10 + diff
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
import sys
def calc(a):
count = 0
while a > 0:
count = count + a
a = int(a / 10)
return count
t = int(sys.stdin.readline())
while t > 0:
l, r = map(int, sys.stdin.readline().split())
p = calc(l)
q = calc(r)
print(q - p)
t = t - 1
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
a = int(input())
for _ in range(a):
inp = input().split()
l = 0
r = 0
l = int(inp[0])
r = int(inp[1])
ans = 0
while l + r > 0:
ans += l - r
l = l // 10
r = r // 10
if ans <= 1111111110:
ans = abs(ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
while t > 0:
t -= 1
l, r = [int(x) for x in input().split()]
num1 = str(l)
num2 = str(r)
ans = 0
while len(num1) != len(num2):
num1 = "0" + num1
for i in range(len(num1)):
k1 = int(num1[: i + 1])
k2 = int(num2[: i + 1])
ans += k2 - k1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
for _ in range(int(input())):
l, r = map(int, input().split())
t = l
count = 0
a = 1
while t // a > 0:
count += t // a
a *= 10
t = r
c = 0
a = 1
while t // a > 0:
c += t // a
a *= 10
print(c - count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
t = int(input())
ans = []
for i in range(t):
l, r = map(int, input().split())
res = 0
for i in range(len(str(r))):
res += r // 10**i - l // 10**i
ans.append(res)
print(*ans, sep="\n")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$).
-----Output-----
For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
-----Examples-----
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
-----Note-----
None
|
from sys import stdin
input = stdin.readline
t = int(input())
def solve(n):
res, mul = 0, 1
for i in range(12):
res += n // mul
mul = mul * 10
return res
for _ in range(t):
l, r = map(int, input().split())
print(solve(r) - solve(l))
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.