Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce

import sys

input = sys.stdin.readline

# N個整数
n, q = list(map(int, input().split()))

s = input()

ans = set()

qq = [''] * q

for i in range(q):
    t, d = input().split()
    qq[i] = t + d


##i番目の呪文を唱える直前にposにいるゴーレムの数を返す
def dfs(pos, i):
    ret = 0
    start = -1
    ##このマスから移動した呪文までを見る必要がある
    for ii in range(i - 1, -1, -1):
        if qq[ii][0] == s[pos]:
            start = ii
            break
    if start == -1:
        ret += 1

    if pos != 0:
        # 0でなければ左からposの位置へ動くものを見つける
        for ii in range(i - 1, start, -1):
            if qq[ii] == s[pos - 1] + 'R':
                ret += dfs(pos - 1, ii)

    if pos != n - 1:
        # 右からposの位置へ動く呪文を見つける
        for ii in range(i - 1, -1, -1):
            if qq[ii] == s[pos + 1]+'L':
                ret += dfs(pos + 1, ii)
    #print(pos, i, ret)

    return ret


ret = 0

for ii in range(q - 1, -1, -1):
    if qq[ii] == s[0] + 'L':
        ret += dfs(0, ii)

for ii in range(q - 1, -1, -1):
    if qq[ii] == s[n - 1] + 'R':
        ret += dfs(n - 1, ii)

print(n-ret)

# 1整数
# n = int(input())

# 空白区切りリスト整数
# b = list(map(int, input().split()))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce

import sys

input = sys.stdin.readline

# N個整数
n, q = list(map(int, input().split()))

s = input()

ans = set()

qq = [''] * q

for i in range(q):
    t, d = input().split()
    qq[i] = t + d


##最初にマスiにいるゴーレムが左に抜けられるかどうか
def hidari(i):
    for qn in range(q):
        if qq[qn][0] == s[i]:
            if qq[qn][1] == 'R':
                i += 1
                if i >= n:
                    return False
            else:
                i -= 1
                if i < 0:
                    return True
    return False


# 右に抜けられるかどうか
def migi(i):
    for qn in range(q):
        if qq[qn][0] == s[i]:
            if qq[qn][1] == 'R':
                i += 1
                if i >= n:
                    return True
            else:
                i -= 1
                if i < 0:
                    return False
    return False


##左に抜けられるかどうかの最大のにぶたんwithめぐる
ok = -1
ng = n
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    #print(mid, hidari(mid))
    if hidari(mid):
        ok = mid
    else:
        ng = mid
n_hidari = ok

##右に抜けられるかどうかの最大のにぶたんwithめぐる
ok = n
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
   # print(mid, migi(mid))
    if migi(mid):
        ok = mid
    else:
        ng = mid
n_migi = ok
#print(n_migi,n_hidari)
print(max(0, n_migi - n_hidari-1))
s=input().splitlines()
count = 0
if(s[0]==1):
    count+=1
if(s[1]==1):
    count+=1
if(s[2]==2):
    count+=1

print(count)

### FIXED CODE ###

s=input()
print(s.count("1"))
manhattan = lambda x,y: abs(x[0] - y[0]) + abs(x[1] - y[1])

def solve():
    n = int(input())
    table = [[0, 0, 0]] + list(map(int, input().rstrip("\n").split()) for i in range(n))

    for i in range(1, len(table)):
        t = (table[i][0] - table[i - 1][0] - manhattan(table[i - 1][1:], table[i][1:]))
        if t < 0 or t % 2 != 0:
            return "No"
    return "Yes"

print(solve())


### FIXED CODE ###

a, b = map(int, input().split())
print("Odd" if (a * b) % 2 else "Even")
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, m = [int(x) for x in input().split()]
    s = input()
    t = input()
    g = gcd(n, m)
    ans = n * m // g
    a, b = n // g, m // g
    x, y = 0, 0
    for i in range(g):
        if s[x] != x[y]:
            print(-1)
            return
        x += a
        y += b
    print(ans)
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 2 2 2 2

"""


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, m = [int(x) for x in input().split()]
    s = input()
    t = input()
    g = gcd(n, m)
    ans = n * m // g
    a, b = n // g, m // g
    x, y = 0, 0
    for i in range(g):
        if s[x] != t[y]:
            print(-1)
            return
        x += a
        y += b
    print(ans)
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 2 2 2 2

"""
import math
from functools import reduce
import copy
N = int(input())
A = list(map(int,input().split()))

def gcd_list(numbers):
    return reduce(math.gcd,numbers)
ans = 0
count = 0
for i in range(N):
    B = copy.copy(A)
    a = B.pop(i)
    gcd = gcd_list(B)
    ans = max(ans,gcd)

print(ans)

### FIXED CODE ###

import fractions
N=int(input())
A=list(map(int,input().split()))

def gcd(x,y):
    if x==0:
        return y
    else:
        return gcd(y%x,x)

L=[0 for _ in range(N+1)]
L[0]=0
for i in range(N):
    L[i+1]=gcd(L[i],A[i])

R=[0 for i in range(N+1)]
R[N-1]=A[N-1]
for i in range(1,N)[::-1]:
    R[i-1]=gcd(R[i],A[i-1])

ans=0
for i in range(N):
    ans=max(ans,gcd(L[i],R[i+1]))
print(ans)
A=int(input())
A.sort()
print(A[2]-A[0])

### FIXED CODE ###

A=list(map(int,input().split()))
A.sort()
print(A[2]-A[0])
a, b, c = map(int, input().split())
print('{} {} {}'.format(c, a, b)

### FIXED CODE ###

a, b, c = map(int, input().split())
print('{} {} {}'.format(c, a, b))
pack = list(map(int,input().split())).sort()
if pack[0] + pack[1] == pack[2]:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

pack = sorted(list(map(int,input().split())))
if pack[0] + pack[1] == pack[2]:
    print('Yes')
else:
    print('No')
a,b,c = map(int, input().split())
for i in range(B+1):
    if i*a%b == c:
        print("YES")
    else:
        print("NO")

### FIXED CODE ###

a,b,c = map(int, input().split())
cnt = 0
for i in range(b+1):
    if i*a%b == c:
        cnt =+ 1
        break
    else:
        continue
print("YES" if cnt == 1 else "NO")
n=int(input())
elif n<2**1:
  print(1)
elif n<2**2:
  print(2)
elif n<2**3:
  print(4)
elif n<2**4:
  print(8)
elif n<2**5:
  print(16)
elif n<2**6:
  print(32)
elif n<2**7:
  print(64)
  

### FIXED CODE ###

n=int(input())
if n<2**1:
  print(1)
elif n<2**2:
  print(2)
elif n<2**3:
  print(4)
elif n<2**4:
  print(8)
elif n<2**5:
  print(16)
elif n<2**6:
  print(32)
elif n<2**7:
  print(64)
def p_c():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    for i in range(N):
        a = A.copy()
        a.pop(i)
        print(max(a))


if __name__ == '__main__':
    p_b()

### FIXED CODE ###

def p_c():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    m = max(A)
    a = A.index(m)
    A.pop(a)
    b = max(A)

    for i in range(N):
        if i == a:
            print(b)
        else:
            print(m)


if __name__ == '__main__':
    p_c()
haiku = int(input())
x = haiku.split(' ')
num_5 = 0
num_7 = 0

for v in x:
	if x[v] == 5:
		num_5 ++
	elif x[v] == 7:
		num_7 ++

if num_5 == 2 and num_7 == 1:
	print('YES')
else:
	print('NO')

### FIXED CODE ###

haiku = input()
x = haiku.split()
num_5 = 0
num_7 = 0

for v in x:
    v = int(v)
    if v == 5:
        num_5 += 1
    elif v == 7:
        num_7 += 1

if num_5 == 2 and num_7 == 1:
    print('YES')
else:
    print('NO')
H, W = map(int, input().split())
S = []
S.append('.' * (H + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (H + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")


### FIXED CODE ###

H, W = map(int, input().split())
S = []
S.append('.' * (W + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (W + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")
import math
i = list(map(int, input().split()))
c=math.gcd(i[0],i[1])
print(i[0]*i[1]/c)

### FIXED CODE ###

import fractions
i=list(map(int, input().split()))
a=i[0]
b=i[1]
c=fractions.gcd(a,b)
print(i[0]*i[1]//c)
A, B, C = int(input().split())
if (A == B) or (B == C) or (C == A):
  if (A == B) and (B == C):
    print("No")
  else:
    print("Yes")
else:
  print("No")


### FIXED CODE ###

A, B, C = map(int, input().split())
if (A == B) or (B == C) or (C == A):
  if (A == B) and (B == C):
    print("No")
  else:
    print("Yes")
else:
  print("No")
list = ["Sunny","Cloudy","Rainy"]
s = str(input())
a = list.index(s)
if a == 2:
    a == -1
print(list[a+1])

### FIXED CODE ###

list = ["Sunny","Cloudy","Rainy"]
s = str(input())
a = list.index(s)
if a == 2:
    a = -1
print(list[a+1])
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))


### FIXED CODE ###

import math
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))
s = input()
s_len = len(s)
if s_len % 2:
  print("No")
else:
  prev = 0
  count = 0
  for i in range(1, (s_len//2)+1):
    if [prev:i*2] != "hi":
      print("No")
      break
    else:
      count += 1
  if count == s_len:
    print("Yes")

### FIXED CODE ###

s = input()
s_len = len(s)
if s_len % 2:
  print("No")
else:
  prev = 0
  count = 0
  for i in range(1, (s_len//2)+1):
    if s[prev*2:i*2] != "hi":
      print("No")
      break
    else:
      count += 1
      prev = i
  if count == s_len // 2:
    print("Yes")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 1 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 2 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[a[i-1]] += 1
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
    print(sum((c[0:len(c)-k])))
else:
    print(0)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[a[i]-1] += 1
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
    print(sum((c[0:len(c)-k])))
else:
    print(0)
n, m = map(int, input().split())

to = [[] for _ in range(110000)]
ans = [0] * 110000
queue = []
passed = [0] * 110000
passed[1] = 1

def search(i):
  global queue
  global passed
  global ans
  for j in to[i]:
    if passed[j] == 0:
      queue.append(j)
      passed[j] = 1
      ans[j] = i
  if queue:
    return search(queue.pop(0))
  


for _ in range(m):
  a, b = map(int, input().split())
  to[a].append(b)
  to[b].append(a)

search(1)

print("Yes")
for i in ans[2:n + 1]:
  print(i)

### FIXED CODE ###

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

to = [[] for _ in range(110000)]
ans = [0] * 110000
queue = []
passed = [0] * 110000
passed[1] = 1

def search(i):
  global queue
  global passed
  global ans
  for j in to[i]:
    if passed[j] == 0:
      queue.append(j)
      passed[j] = 1
      ans[j] = i
  


for _ in range(m):
  a, b = map(int, input().split())
  to[a].append(b)
  to[b].append(a)

search(1)
queue.append(1)

while queue:
  que = queue.pop(0)
  search(que)


print("Yes")
for i in ans[2:n + 1]:
  print(i)
n = int(input())

max_N = 1000000
memo = [False]*max_N

# 貰う DPではなく、再帰を使ったメモ化再帰
def f(n):
	if n < 6:
		return n
	if memo[n]:
		return memo[n]
	
	ans = n
	# メモ化
	x = 6
	while x <= n:
		ans = min(ans, f(n-x)+1)
		x *= 6
	
	x = 9
	while x <= n:
		ans = min(ans, f(n-x)+1)
		x *= 9
	
	return ans
		
	
print(f(n))

### FIXED CODE ###

N = int(input())
dp = dict()

dp[0] = 0
for n in range(1, N+1):
  ans = dp[n-1] + 1
  
  # メモ化
  x = 6
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 6
  
  x = 9
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 9
    
  dp[n] = ans
  
print(dp[N])
S = input()

if S[0]==S[1] and S[2]==S[3]　and S[0]!=S[2]:
        print('Yes')

elif S[1]==S[2] and  S[0]==S[3] and S[0]!=S[1]:
        print('Yes')
        
elif S[1]==S[3] and  S[0]==S[2] and S[0]!=S[1]:
        print('Yes')

else :
    print('No')


### FIXED CODE ###

S = input()
 
if S[1]==S[2]==S[3]==S[0]:
        print('No')
        
elif S[0]==S[1] and S[2]==S[3]:
        print('Yes')
 
elif S[1]==S[2] and  S[0]==S[3]:
        print('Yes')
        
elif S[1]==S[3] and  S[0]==S[2]:
        print('Yes')
 
else :
    print('No')
N,K= map(int, input().split())

A=[]

for i range(K)
    d = int(input())
    A[i] = [int(x) for x in input().split()]

print("A")

### FIXED CODE ###

Sunuke=[]

N, K = map(int, input().split()) 
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))

    Sunuke.extend(A)

print(N-(len(set(Sunuke))))
N = int(input())
L = list(map(int, input().split()))
 
ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if(L[i] != L[j] and L[i] != L[k] and L[j] != L[k] and abs(L[j]-L[k]) < L[i] and L[i] < L[j]+L[k]):
          ans +=1
          
print(ans)

### FIXED CODE ###

S = input()
 
ans = 0
if S == 'RRR': ans = 3
else:
  if ('RR' in S): ans = 2
  else:
    if('R' in S): ans = 1
    else: ans = 0
 
print(ans)
N,M=map(int,input().split())

base=M//N
answer=[0]*N
j=0

for i in range(base,base//2+1,-1):
    if M%i==0:
        answer[j]=i
        break
    elif M%(base-i+1)==0:
        answer[j]=base-i+1
        j+=1
print(max(answer))

### FIXED CODE ###

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

base=M//N
li=[]


for i in range(1,int(pow(M,1/2))+1):
    if i<=base and M%i==0:
        li.append(i)
    if M%i==0 and M//i<=base:
        li.append(M//i)

print(max(li))
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))

### FIXED CODE ###

import math
import numpy as np

def cmb(n, r, mod):
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )

x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

  A = np.array([[1, 2],[2, 1]])
  b = np.array([x, y])
  N = np.linalg.solve(A, b)
  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))
  else:
      print(0)
else:
  print(0)
n,t=map(int,input().split())
a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
    c.append([a[0],0])
else:
    d[0]=a[0]
for i in range(1,n-1):
    if a[i]>a[i+1] and a[i-1]<a[i]:
        d[i]=a[i]
    if a[i]<a[i+1] and a[i-1]>a[i]:
        c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
    E=max(d[i[1]:])-i[0]
    e[E]+=1
print(max(e))

### FIXED CODE ###

a,b=map(int,input().split())
k=list(map(int,input().split()))

sa=0
ans=1

n=k[a-1]

for i in range(a-2,-1,-1):
    if k[i]>n:
        n=k[i]
    tmp=n-k[i]
    if tmp>sa:
        sa=tmp
        ans=1
    elif tmp==sa:
        ans+=1

    

print(ans)
import numpy as np
import itertools

H, W, K = list(map(int, input().split())) 
c = [input().split() for l in range(H)]
b=[]
d=[]
for m in range(len(c)):
  for item in c[m]:
    item_mod = item.replace("."  , "0")
    item_mod = item_mod.replace("#" , "1")
    b.append(item_mod)
  d.append(b)
  b=[]

C_arr = np.array(d , dtype = "int")

In = np.array(list(itertools.product([0,1] , repeat=H)))
Out = np.array(list(itertools.product([0,1] , repeat=W)))

ans = 0
for i in range(2**H):
  for j in range(2**W):
    In_matrix = np.diag(In[i])
    Out_matrix = np.diag(Out[j])

    In_C = np.dot(In_matrix , C_arr)
    In_C_Out = np.dot(In_C , Out_matrix)

    ICO = In_C_Out.flatten()
    ICO = ICO.tolist()

    if ICO.count(1) == K:
      ans += 1

print(ans)

### FIXED CODE ###

H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

t = int(input())

print(arr[t+1])

### FIXED CODE ###

arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
t=int(input())
print(arr[t-1])
a = input();
print(int(a.split()[0])*int(a.split()[1]),int(a.split()[0]) * 2 + int(a.split()[1])*2, end=" ")

### FIXED CODE ###

a = input();
print(int(a.split()[0])*int(a.split()[1]),int(a.split()[0]) * 2 + int(a.split()[1])*2, end="\n")
data = [
    [[0 for r in range(10)] for f in range(3)] for b in range(4)
]

# ??\?????????????????????????????§????????????????????????????????????
count = int(input())
for c in range(count):
    c, f, r, v = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v


for bi, b in enumerate(data):
    for f in b:
        for r in f:
            print(' {0}'.format(r), end='')

        print()

    if bi < 3:
        print('#' * 20)

### FIXED CODE ###

data = [
    [[0 for r in range(10)] for f in range(3)] for b in range(4)
]
    
count = int(input())
for c in range(count):
    b,f,r,v = [int(i) for i in input().split()]
    data[b-1] [f-1] [r-1] += v
    
for bi, b in enumerate(data):
    for f in b:
        for r in f:
            print(' {0}'.format(r), end='')
        print()
    if bi < 3:
        print('#' * 20)
sunuke=[]
for i in range(17):
    for j in range(1,10):
        sunuke.append(j*10**i+(10**i-1))

for i in range(int(input())):
    print(sunuke[i])

### FIXED CODE ###

def f(n):
    s=str(n)
    return sum([int(s[i]) for i in range(len(s))])

sunuke=[]
for i in range(16):
    for j in range(1,500):
        sunuke.append(j*(10**i)-1)

sunuke=list(set(sunuke))
sunuke.sort()
sunuke.pop(0)
L=len(sunuke)

tmp1,tmp2=sunuke[L-1],f(sunuke[L-1])
ans=[sunuke[L-1]]
for i in range(len(sunuke)-2,-1,-1):
    x=sunuke[i]
    if x*tmp2<=tmp1*f(x):
        ans.append(x)
        tmp1,tmp2=x,f(x)

ans.sort()

    

for i in range(int(input())):
    print(ans[i])
n.m=map(int,input().split())
print((n-1)*(m-1))

### FIXED CODE ###

n,m=map(int,input().split())
print((n-1)*(m-1))
s = list(input())
L = 0
R = 0
tmp = []
for i in range(len(s)):
    if s[i] == "<":
        L += 1
    if s[i] == ">":
        R += 1
    if i == len(s)-1:
        if L == 0 or R == 0:
            tmp.append(L)
            tmp.append(R)
            L = 0
            R = 0
            break
        elif L > R:
            tmp.append(L)
            tmp.append(R-1)
            L = 0
            R = 0
            break
        elif L < R:
            tmp.append(L-1)
            tmp.append(R)
            L = 0
            R = 0
            break
    if s[i] == ">" and s[i+1] == "<":
        if L == 0 or R == 0:
            tmp.append(L)
            tmp.append(R)
            L = 0
            R = 0
        elif L > R:
            tmp.append(L)
            tmp.append(R-1)
            L = 0
            R = 0
        elif L < R:
            tmp.append(L-1)
            tmp.append(R)
            L = 0
            R = 0
ans = 0
for i in range(len(tmp)):
    if tmp[i] % 2 == 0:
        ans += (tmp[i] * (tmp[i] + 1) // 2)
    else:
        ans += ((tmp[i] - 1) * ((tmp[i] - 1) + 1) // 2 + tmp[i])
print(ans)

### FIXED CODE ###

s = input()
n = len(s)
L=[0]
R=[0]
cnt = 0

for i in range(n):
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
    L.append(cnt)
cnt = 0
s = s[::-1]
for i in range(n):
    if s[i]  == '>':
        cnt += 1
    else:
        cnt = 0
    R.append(cnt)

R = R[::-1]
ans = 0
for i in range(n+1):
    ans += max(R[i], L[i])

print(ans)
n = list(input())
print(int(n[-3] + n[-2] + n[-1]))

### FIXED CODE ###

n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print(1000 - (n % 1000))
s = input()
k = int(input())

s_list = []
times = 0
flow = 0

#s = s[len(s)-1] + s

print(s.count(s[len(s)-1]))

for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1 :
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



### FIXED CODE ###

s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []

s = sum(t)

for i in range(m):
    p.attend(input().split())

for i in range(m):
    print(s-t[i]+p[i])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s+x-a[p-1])
N, M = list(map(int, input().split())) # 整数
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
    

m_lis= [0 for i in range(M)]
for i in range(N):
    for j in range(a[i][0]):
        m_lis[a[i][j+1]]+=1
        
        

count=0
for i in range(N+1):
    if m_lis[i]==N:
        count+=1
        
print(count)

### FIXED CODE ###

N, M = list(map(int, input().split())) # 整数
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
    

m_lis= [0 for i in range(M+1)]
for i in range(N):
    for j in range(a[i][0]):
        m_lis[a[i][j+1]]+=1
        
        

count=0
for i in range(M+1):
    if m_lis[i]==N:
        count+=1
        
print(count)