Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def solve():
  n = int(input())
  s = input()

  ans = 10**15
  a = s.count(".")
  b = s.count("#")
  for i in range(n+1):
   s1 = s[0:i]
   s2 = s[i::]
   tp = s1.count('#')
   tp2 = s2.count(".")
   ans = min(ans,tp+tp2)
  print(ans)
solve()

### FIXED CODE ###

def solve():
  n = int(input())
  s = input()
  
  leftblack = 0
  leftwhite = 0
  rightblack = s.count('#')
  rightwhite = s.count(".")
  
  ans = leftblack+rightwhite
  
  for i in range(n):
    if s[i] == "#":
      leftblack += 1
      rightblack -= 1
    else:
      leftwhite += 1
      rightwhite -= 1
    ans = min(ans,leftblack+rightwhite)
  
  print(ans)
solve()
### BUGGY CODE ###

def isSquare(x):
  f = 1
  while f * f <= x:
    if f * f == x:
      return True
    else:
      f += 1
  return False

N = int(input())
f = N
while True:
  if isSquare(f):
    print(f)
    exit()
  f -= 1

### FIXED CODE ###

def isSquare(x):
  return x == round(x**(1/2))**2

N = int(input())
f = N
while True:
  if isSquare(f):
    print(f)
    exit()
  else:
    f -= 1
### BUGGY CODE ###

n = int(input())
a = list( map(int,input().split()) )

ans = 1
for i in a:
  ans *= i
if ans > 10**18:
  ans = -1

print(ans)

### FIXED CODE ###

n = int(input())
a = list( map(int,input().split()) )

c = set(a)

ans = 1
if 0 in c :
  ans = 0
else :
  for i in a:
    ans *= i
    if ans > 10**18:
      ans = -1
      break 

print(ans)
### BUGGY CODE ###

#方針...ユークリッドの互除法を用いて2整数が互いに素かどうかを判定する関数を設計
#       O(route n)で2整数の公約数をリストとして出力する関数を設計
#       あとはbit探索
import math

def judge_disjoint(a,b):

    while (a!=0 and b!=0):
        if b<a:
            a,b = b,a
        b = b%a
    if (a==1 or b==1):
        return True
    else:
        return False

def common_divisor(a,b):
    ls_a=[]
    ls_b=[]
    A = int(math.sqrt(a))
    B = int(math.sqrt(b))
    for i in range(1,A+1):
        if (a%i==0):
            ls_a.append(i)
            ls_a.append(a//i)
    for i in range(1,B+1):
        if (b%i==0):
            ls_b.append(i)
            ls_b.append(b//i)
    ls = list(set(ls_a) & set(ls_b))
    return ls

A,B = list(map(int,input().split()))
ls = common_divisor(A,B)
N = len(ls)
ans = 0

for bit in range(2**N):
    candidates=[]
    flag=True
    for i in range(N):
        if(1<<i & bit):
            candidates.append(ls[i])
    for i in range(len(candidates)-1):
        for j in range(i+1,len(candidates)):
            if (not judge_disjoint(candidates[i],candidates[j])):
                flag = False
    if(flag):
        ans = max(ans,len(candidates))
        
print(ans)


### FIXED CODE ###

#方針...gcd(A,B)の約数の中で素数or1となるものの個数を調べれば良い(O(route N))
import fractions
import math

def prime_fac(N):
    primes = {1:1}
    n = int(math.sqrt(N))
    for i in range(2,n+1):
        if N%i==0:
            primes[i] = 0
            while N%i==0:
                primes[i] += 1
                N = N//i
    if (N!=1):
        primes[N] = 1
    return primes

A,B = list(map(int,input().split()))
C = fractions.gcd(A,B)
primes = prime_fac(C)

print(len(primes))
### BUGGY CODE ###

def gcd(x, y):
    while y:
        amari = x % y
        x = y
        y = amari
    return x

def gcd_list(numbers):
    gcdv = numbers[0]
    for n in range(1, len(numbers)):
        gcdv = gcd(gcdv, numbers[n])
    return gcdv

def main():
    n = int(input())
    a = [int(a) for a in input().split()]

    maxv = 0
    for nn in range(n):
        gcdv = gcd_list(a[:nn]+a[nn+1:])
        if gcdv > maxv:
            maxv = gcdv
    print(maxv)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
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

def main():
    N = INT()
    A = LIST()
    L = [0] * N
    R = [0] * N
    M = [0] * N
    for i in range(N - 1):
        L[i + 1] = gcd(L[i], A[i])
        R[N - i - 2] = gcd(R[N - i - 1], A[N - i - 1])
    maxv = 0
    for i in range(N):
        M[i] = gcd(L[i], R[i])
        if maxv < M[i]:
            maxv = M[i]
    print(maxv)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

def main():
    N, Q = map(int, input().split())
    S = input()
    ans = [None] * N
    
    for i in range(N):
        ans[i] = S[i:].count('AC')
    for i in range(Q):
        l, r = map(int, input().split())
        print(ans[l-1] - ans[r-1])

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def main():
    N, Q = map(int, input().split())
    S = input()
    ans = [None] * N
    ans[0] = S.count('AC')
    for i in range(1,N):
        ans[i] = ans[i-1]
        if S[i-1:i+1] == 'AC':
            ans[i] -= 1

    for i in range(Q):
        l, r = map(int, input().split())
        print(ans[l-1] - ans[r-1])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,M = map(int, input().split())
X = list(map(int,input().split()))
if N >= M:
  print(0)
else:
  X = sorted(X)
  list = []
  for i in range(M-1):
    list.append(X[i+1]-X[i])
    list = sorted(list)
    list1 = list[:M-N]
  print(sum(list1))

### FIXED CODE ###

N,M = map(int, input().split())
X = list(map(int,input().split()))
if N >= M:
  print(0)
else:
  X = sorted(X)
  list = [X[i]-X[i-1] for i in range(1,M)]
  list = sorted(list)
  list1 = list[:M-N]
  print(sum(list1))
### BUGGY CODE ###

N=int(input())
number=[]
for i in range(N):
    number.append(int(input()))
for i in range(N):
    a = number[i]
    del number[i]
    print(max(number))
    number.insert(i,a)

### FIXED CODE ###

N = int(input())
number = []
for i in range(N):
    number.append(int(input()))
sorted_number = sorted(number,reverse=True)
max_number = sorted_number[0]
second_number = sorted_number[1]

for i in number:
    if i != max_number:
        print(max_number)
    else:
        print(second_number)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))

A.sort()
B=[1]*n

from math import sqrt
def eratosu():
  # if not isinstance(n,int):
  #   raise TypeError("nがint型になってねえぞ")
  # if n<2:
  #   raise ValueError('nが2よりちっちぇえぞ')
  primec = 0
  # limit = sqrt(n)
  data = A  #2,3,4,...,n
  while len(data)>0:
    p = data[0]
    # if limit <= p:
    #     return prime + data
    if len(data)>1:
        if data[1]==p:
            primec-=1
    primec+=1 
    data = [e  for e in data if e % p != 0]
  return primec 

# for i in range(n):
#     if i>0:
#         if A[i]==A[i-1]: B[i]=0 ; B[i-1]=0 ; continue
    # if B[i]==1:
    #     for j in range(i+1,n):
    #         if A[j]%A[i]==0:
    #             B[j]=0
print(eratosu())

# print(sum(B))


### FIXED CODE ###

n=int(input())
A=sorted(list(map(int,input().split())))
B=[0]*(1+A[-1])
for i in A:
    B[i]+=1
    if B[i]==1:
        for j in range(2*i,A[-1]+1,i):
            B[j]+=1
    else:
        continue
ans=0
for i in A:
  if B[i]==1: ans+=1

print(ans)
### BUGGY CODE ###

s = input()
Q = int(input())
for i in range(Q):
    tmp = list(input())
    if len(tmp)==1:
        s = s[::-1]
    else:
        f,c = tmp[2], tmp[4]
        if f=='1':
            s = '{}{}'.format(c,s)
        elif f=='2':
            s = '{}{}'.format(s,c)
print(s)



### FIXED CODE ###

from collections import deque
s = input()
Q = int(input())
s = deque([s])
rev = 1
for i in range(Q):
    tmp = list(input().split())
    if len(tmp)==1:
        rev *= -1
    else:
        f,c = tmp[1], tmp[2]
        if rev > 0:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(list(s))
print(s if rev > 0 else s[::-1])
### BUGGY CODE ###


# def solve(N: int):
#     for i in range(1, 3501):
#         for j in range(1, 3501):
#             z = 4*i*j - N*j - N*i
#             if z != 0:
#                 h, r = divmod((N*i*j), z)
#                 if r == 0 and 0 <= h:
#                     print(h, i, j)
#                     exit()
            

#     return

N = int(input())
# solve(N)

for i in range(1, 3501):
    for j in range(1, 3501):
        z = 4*i*j - N*j - N*i
        if z != 0:
            h, r = divmod((N*i*j), z)
            if r == 0 and 0 <= h:
                print(h, i, j)
                exit()
            


# # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
# def main():
#     def iterate_tokens():
#         for line in sys.stdin:
#             for word in line.split():
#                 yield word
#     tokens = iterate_tokens()
#     N = int(next(tokens))  # type: int
#     solve(N)

# if __name__ == '__main__':
#     main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            z = 4*i*j - N*(j+i)
            if z > 0:
                h, r = divmod((N*i*j), z)
                if r == 0:
                    print(h, i, j)
                    exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


# #!/usr/bin/env python3
# n = int(input())
# for i in range(1, 3501):
#   for j in range(1, 3501):
#     seed = 4 * i * j - n * (i + j) 
#     if seed > 0:
#       k, mod = divmod(n * i * j, seed) 
#       if mod == 0:
#         print(i, j, k)
#         exit()
### BUGGY CODE ###

import sys

N, M = map(int, input().split())

s = []
e = []

for _ in range(M):
	tmp = list(map(int, input().split()))
	if 1 in tmp:
		s.append(max(tmp))
	elif N in tmp:
		e.append(min(tmp))

for ss in s:
	if ss in e:
		print("POSSIBLE")
		sys.exit()
print("IMPOSSIBLE")

### FIXED CODE ###

import sys

N, M = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(M)]
B = []

for i in range(M):
	if 1 in A[i]:
		B.append(A[i][1])
	elif N in A[i]:
		B.append(A[i][0])

C = set(B)

if len(C) == len(B):
	print("IMPOSSIBLE")
else:
	print("POSSIBLE")
### BUGGY CODE ###

import numpy as np
def isprime(x):
  if x==1:
    return False
  if x==2:
    return True
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

def like2017(x):
  return (isprime(x) and isprime((x+1)//2))

a=[like2017(i) for i in range(10**5+1)]

a_cum=np.cumsum(a)

q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(a_cum[r]-a_cum[l-1])

### FIXED CODE ###

from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)
### BUGGY CODE ###

N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    A,B=map(int,input().split())
    E[A-1].append(B-1)
    E[B-1].append(A-1)
MOD=10**9+7

#頂点xから伸びる部分木に含まれる頂点の個数のリストを返す
def get_sub_tree_node_nums(x):
    ret=[]
    used=[False]*N
    used[x]=True
    for s in E[x]:
        n=1
        stack=[s]
        used[s]=True
        while stack:
            node=stack.pop()
            for ss in E[node]:
                if not used[ss]:
                    stack.append(ss)
                    n+=1
                    used[ss]=True
        ret.append(n)
    return ret

def solve():
    ans=0
    inv2=pow(2,MOD-2,MOD)
    #p0=すべての部分木に黒頂点が1つも含まれない確率
    p0=pow(1<<(N-1),MOD-2,MOD)
    for i in range(N):
        p=0
        subnodes = get_sub_tree_node_nums(i)
        if len(subnodes)>=2:
            #p0*(p1-1)=どれか1つの各部分木に黒頂点が1つ以上含まれる確率
            p1=1
            for s in subnodes:
                p1+=(1<<s)-1
                p1%=MOD
            p=1-(p0*p1)
            p%=MOD
            #頂点iが白の確率
            p=p*inv2%MOD
        ans+=p
        ans%=MOD
    print(ans)

solve()

### FIXED CODE ###

N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    A,B=map(int,input().split())
    E[A-1].append(B-1)
    E[B-1].append(A-1)
MOD=10**9+7

#dp=子ノードの数+1(自分)
dp=[1]*N

root=0
parent=[0]*N
order=[]
def dfs():
    parent[root]=root
    stack=[root]
    while stack:
        node=stack.pop()
        order.append(node)
        for ss in E[node]:
            if parent[node]!=ss:
                stack.append(ss)
                parent[ss]=node

pow2=[1]*(N+1)
for i in range(1,len(pow2)):
    pow2[i]=pow2[i-1]*2%MOD

def solve():
    ans=0
    inv2=pow(2,MOD-2,MOD)
    #p0=すべての部分木に黒頂点が1つも含まれない確率
    p0=pow(pow2[N-1],MOD-2,MOD)
    for i in reversed(order):
        if root!=i:
            dp[parent[i]]+=dp[i]
        p=0
        if len(E[i])>=2:
            #p0*(p1-1)=どれか1つの各部分木に黒頂点が1つ以上含まれる確率
            p1=1
            for s in E[i]:
                size=0
                if parent[i]!=s:
                    size=dp[s]
                elif i!=root:
                    size=N-dp[i]
                else:
                    continue
                p1+=pow2[size]-1
            p=1-(p0*p1)
            p%=MOD
        ans+=p
        ans%=MOD
    #頂点iが白の確率
    ans=ans*inv2%MOD
    print(ans)

dfs()
solve()
### BUGGY CODE ###

class Ship:
  def __init__(self, land_from, land_to):
    self.land_from = land_from - 1
    self.land_to = land_to - 1

N, M = map(int, input().split())

ships = []
for _ in range(M):
  f, t = map(int, input().split())
  ships.append(Ship(f, t))

# 到達可能島リスト
reachable_islands = [float('inf') for _ in range(N)]
# 初期位置は到達可能なのでTrue
reachable_islands[0] = 0
# 探索予定島
search_list = [0]

# 新たな島に移動できたなら次も探索する
while len(search_list):
  now_island = search_list.pop(0)
  # 各到達可能な島ごとに移動シミュレーション
  if reachable_islands[now_island] == float('inf'):
      continue
  # 全ての船についてシミュレート
  for ship in ships:
    # 現在地の島発の船かつ目標島が到達済みでなければ移動シミュレート実行
    if now_island == ship.land_from \
       and reachable_islands[ship.land_to] > reachable_islands[ship.land_from] + 1:
      # 到達済の印をつける
      reachable_islands[ship.land_to] = reachable_islands[ship.land_from] + 1
      # 到着島を探索予定リストに追加
      search_list.append(ship.land_to)

# 最後の島が到達可能であるかを判定
if reachable_islands[N - 1] == 2:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')


### FIXED CODE ###

class Ship:
  def __init__(self, land_from, land_to):
    self.land_from = land_from - 1
    self.land_to = land_to - 1

N, M = map(int, input().split())

mid_from = set()
mid_to = set()

ships = []
for _ in range(M):
  f, t = map(int, input().split())
  ship = Ship(f, t)
  if ship.land_from == 0:
    mid_from.add(ship.land_to)
  if ship.land_to == N - 1:
    mid_to.add(ship.land_from)

# 最後の島が到達可能であるかを判定
if mid_from & mid_to:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
### BUGGY CODE ###


#D
import bisect


n,m = map(int,input().split())
a = list(map(int,input().split()))

a.sort()

for i in range(m):
    a[-1] //= 2
    tmp = a.pop(-1)
    k = bisect.bisect_left(a,tmp)
    a.insert(k,tmp)
        
    
print(sum(a))

### FIXED CODE ###

#優先度付きキュー -> 最小値をO(logN)で取り出す
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))

a = [-x for x in a]

#aを優先度付きキューに変更
heapq.heapify(a)

for _ in range(m):
   
    tmp = heapq.heappop(a)
    tmp = (-tmp // 2) * -1
    heapq.heappush(a,tmp)
        
    
print(sum(a) * -1)
### BUGGY CODE ###

n = int(input())
A = [int(input()) for i in range(n)]

b = list()
for a in A:
    b.append(a)
    if len(set(b)) != len(b):
        b.pop(-1)
        b.remove(a)
print(len(b))


### FIXED CODE ###

n = int(input())
A = [int(input()) for i in range(n)]

b = set()
lenB = 0
for a in A:
    b.add(a)
    lenB += 1
    if len(b) != lenB:
        b.remove(a)
        lenB -= 2
print(len(b))
### BUGGY CODE ###

import random

n = int(input())
a = [int(i) for i in input().split()]

for j in range(100000):
	chk = 0
	for i in range(n-1): 
		if a[i] == a[i-1] ^ a[i+1]:
			chk += 1
		else:
			break			
	if a[n-1] == a[n-2] ^ a[0]:
		chk += 1
	if chk == n:
		print("Yes")	
		break
	else:
		random.shuffle(a)
if j == 99999:
	print("No")

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
    elif num > LR[i][1]-1:
      break
  print(ans)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])
### BUGGY CODE ###

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

c = []
flag = False
for i in ab:
    a, b = i[0], i[1]
    for i in c:
        if a in i or b in i:
            i.add(a)
            i.add(b)
            if len(i) == n:
                flag = True
    else:
        c.append(set())
        c[-1].add(a)
        c[-1].add(b)
    if flag:
        break
if m == 0:
    print(1)
else:
    print(max(map(len, c)))

### FIXED CODE ###

class Union:
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uni = Union(n)
for a, b in ab:
    a -= 1
    b -= 1
    uni.unite(a, b)
print(-min(uni.parents))
### BUGGY CODE ###

S = list(input())
Q = int(input())

tfc = [[] for _ in range(Q)]


for i in range(Q):
    tfc[i] = input().split()
    if int(tfc[i][0])==1:
        S = S[::-1]
    else:
        if int(tfc[i][1])==1:
            S.insert(0,tfc[i][2])
        else:
            S.append(tfc[i][2])
print("".join(S))

### FIXED CODE ###

S = list(input())
Q = int(input())

from collections import deque

S = deque(S)

tfc = [[] for _ in range(Q)]

swich = 0
for i in range(Q):
    tfc[i] = input().split()
    
    if int(tfc[i][0])==1:
        swich += 1
    else:
        if swich%2==0:
            if int(tfc[i][1])==1:
                S.appendleft(tfc[i][2])
            else:
                S.append(tfc[i][2])
        else:
            if int(tfc[i][1])==1:
                S.append(tfc[i][2])
            else:
                S.appendleft(tfc[i][2])

if swich%2==1:
    S = reversed(S)
    print("".join(S))
else:
    print("".join(S))
### BUGGY CODE ###

import itertools

mod = 10**9 + 7

N = int(input())

A = list(map(int, input().split()))

ans = 0
for i, j in itertools.combinations(A, 2):
    ans += ((i%mod)*(j%mod))

print(ans%mod)

### FIXED CODE ###

N = int(input())

mod = 10**9 + 7

A = [int(i)%mod for i in input().split()]

S = [0]*N

ans = 0
for i in range(N-1):
    if i == 0:
        S[i] = sum(A) - A[i]
    else:
        S[i] = (S[i-1] - A[i])
    ans +=  (A[i]*S[i])%mod

print(ans%mod)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict

s = ns()
d = defaultdict(int)
d[0] += 1
k = 0
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*(10**k)
    n%=2019
    d[n] += 1
    k+=1

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict

s = ns()
d = defaultdict(int)
d[0] += 1
k = 1
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*k%2019
    n%=2019
    d[n] += 1
    k = (k*10)%2019

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)
### BUGGY CODE ###

import string

ALPHABETS = string.ascii_lowercase

s = input()
N = len(s)
MAX = 2 * 10 ** 5
a = 0
dp = {}
dp[0] = 0
bits = [2 ** i for i in range(26)]

for c in s:
    a = a ^ bits[ALPHABETS.index(c)]
    dp[a] = min(dp.get(a, MAX), min([dp.get(a ^ 2 ** j, MAX) if not j == -1 else dp.get(a ^ 0, MAX) for j in range(-1, 26)]) + 1)

print(dp[a] if dp[a] != 0 else 1)


### FIXED CODE ###

s = input()
N = len(s)
a = 0
dp = {}
dp[0] = 0
bits = [2 ** i for i in range(26)]

for c in s:
    a = a ^ bits[ord(c)-ord('a')]
    dp[a] = min(dp.get(a, N), min([dp.get(a ^ bit, N) for bit in bits]) + 1)

print(dp[a] if dp[a] != 0 else 1)
### BUGGY CODE ###

n,q = map(int,input().split())
S = list(input())
l = [0]*q
r = [0]*q
for i in range(q):
    l,r = map(int,input().split())
    count = 0
    for i in range(l-1,r-1): #最後にAが出ても意味ないのでr-1でカット
        if(S[i]=='A'):
            if(S[i+1]=='C'):
                count += 1
    print(count)


### FIXED CODE ###

n,q = map(int,input().split())
S = list(input())
a = [0]*n

for i in range(1,n):
    a[i] = a[i-1]
    if (S[i-1]=='A')and(S[i]=='C'):
        a[i] += 1 
for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

a,b,c,d,e,f = map(int,input().split())

water = []
suger = []
for i in range(f//(100*a)+1):
    for j in range(f//(100*b)+1):
        if 100*a*i + 100*b*j <= f and 100*a*i + 100*b*j not in water:
            water.append(100*a*i+100*b*j)

for i in range(f//c+1):
    for j in range(f//d+1):
        if c*i+d*j not in suger:
            suger.append(c*i+d*j)
max = 0
maxs = [100*a,0]
for w in water:
    for s in suger:
        if w+s > 0 and w//100*e >= s and w + s <= f and max < s/(w+s):
            max = s/(w+s)
            maxs = [w,s]

print(sum(maxs),maxs[1])



### FIXED CODE ###

a,b,c,d,e,f = map(int,input().split())

water = []
suger = []
for i in range(f//(100*a)+1):
    for j in range(f//(100*b)+1):
        if 100*a*i + 100*b*j <= f and 100*a*i + 100*b*j not in water:
            water.append(100*a*i+100*b*j)

for i in range(f//c+1):
    for j in range(f//d+1):
        if c*i+d*j not in suger:
            suger.append(c*i+d*j)
max = 0
maxs = [100*a,0]
for w in water:
    for s in suger:
        if w+s > 0 and w//100*e >= s and w + s <= f and max < s/(w+s):
            max = s/(w+s)
            maxs = [w,s]

print(sum(maxs),maxs[1])