Harryxun/stf_run huggingface dataset:
n, k = tuple(map(int, input().split(' ')))
r, s, p = tuple(map(int, input().split(' ')))
t = (input())
point = {'r':p, 's':r, 'p':s, 'any':0}
st = {i:t[i] for i in range(k)}
ans1 = sum(map(lambda x: point[x], t[:k]))
ans2 = 0
for i in range(k, n):
    h = t[i]
    m = i%k
    if st[m] != h:
        ans2 += point[h]
        st[m] = h
    else:
        st[m] = 'any' 
print(ans1 + ans2)
return

### FIXED CODE ###

n, k = tuple(map(int, input().split(' ')))
r, s, p = tuple(map(int, input().split(' ')))
t = (input())
def char2int(c):
    if c == 'r':
        return p
    elif c == 's':
        return r
    else:
        return s
st = {i:t[i] for i in range(k)}
ans1 = sum(map(char2int, t[:k]))
ans2 = 0
for i in range(k, n):
    h = t[i]
    m = i%k
    if st[m] != h:
        ans2 += char2int(h)
        st[m] = h
    else:
        st[m] = 'any' 
print(ans1 + ans2)
import sys
input = sys.stdin.buffer.readline
class SkewHeap:
  def __init__(self, init_val = None, left = None, right = None):
    self.val = init_val
    self.left = left
    self.right = right
    self.root = None
  def heapmeld(self, h1, h2):
    if h1 == None: return h2
    if h2 == None: return h1
    if h1.val > h2.val:
      h1.val, h1.left, h1.right, h2.val, h2.left, h2.right = h2.val, h2.left, h2.right, h1.val, h1.left, h1.right
    h1.right = self.heapmeld(h2, h1.right)
    return h1
  def heappop(self):
    if self.root == None:
      res = self.val
      h = self.heapmeld(self.left, self.right)
      if h == None: h = SkewHeap(None)
      self.val, self.left, self.right = h.val, h.left, h.right
      return res
    res = self.root.val
    self.root = self.heapmeld(self.root.left, self.root.right)
    return res
  def heappush(self, x):
    h = SkewHeap(x)
    self.root = self.heapmeld(self.root, h)
N, M = map(int, input().split())
a = list(map(int, input().split()))
h = SkewHeap()
res = 0
for e in a:
  h.heappush(-e)
for _ in range(M):
  h.heappush(-(-h.heappop() // 2))
for _ in range(N):
  res -= h.heappop()
print(res)

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
for _ in range(M):
  p = heapq.heappop(A)
  p = -p
  p //= 2
  p = -p
  heapq.heappush(A, p)
print(-sum(A))
"""
最大公約数をもっとも落としている数Xを削る（＝見ないことにする）、という発想に置き換える。
方針１：
Xを特定する。
どうやって特定する？
各Aを素因数分解する。このとき、他の

方針２：
約数をカウントする。すべてのAの約数をカウントして総和する。
このとき、カウントがN個になる約数は初期状態での公約数である。
一方で、カウントがN-1個の約数は、その約数をもたない数が一つだけ存在するということなので、
そのような数Aを削ったときに、公約数になる。
したがって、カウントがN-1個以上の約数のうち最大のものが、数Xを削ったときの最大公約数である。
問題はどうやって約数をカウントするかだ。愚直にやるとO(N√max(A))かかるため間に合わない。
ただ、約数の数自体はせいぜい1000個くらいのはず。いったん素因数分解してから、各素因数を何個累乗させるかで考えればよいか。
"""
def main():
    N = int(input())
    A = list(map(int,input().split()))
    count = {}

    for a in A:
        tmp = []
        d = 2
        while d*d <= a:
            while a%d == 0:
                tmp.append(d)
                a //= d
            d += 1
        if a != 1:
            tmp.append(a)
        divides = [1]
        for k,v in Counter(tmp).items():
            M = len(divides)
            for i in range(1,v+1):
                for j in range(M):
                    divides.append(divides[j]*pow(k,i))
        
        for d in divides:
            if d not in count:
                count[d] = 0
            count[d] += 1

    ans = 0
    for k,v in count.items():
        if v >= N-1:
            ans = max(ans,k)
    print(ans)
main()

### FIXED CODE ###

"""
問題文を言い換えると、「最大公約数が最大になるように数字を一つ書き換えろ」ということ。
さらに言い換えると、「最大公約数が最大になるように数字を一つ消せ」ということ。
単純な線形探索でできるか？→NO

最大公約数を小さくする要因となっている数字を一つ消す。
どういう数字が最大公約数を小さくする要因になっているか？
他の数字と共通する素因数が少ない、小さい、次数が小さい。ただ、この3つを総合的に判断するのは難しすぎる。
素因数分解はやめて、単純に約数で探せばよいか。
各Aの約数を昇順で列挙しておく。
まずA1は必ず残すと仮定して、A1の約数の大きい方から順番に、ほかのAの約数になるかどうかを調べる。
その約数を含んでいないAが一つだけ存在するとき、そのAを消せば、その約数が最大公約数となる。

次に、A1を消す場合の最大公約数も求めて、A1を含める場合の最大公約数と比較して大きい方を採用する。
"""

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

#A1を必ず入れる場合の最大公約数を求める。
yakusu = []

a = A[0]
d = 1
while d*d < a:
    if a % d == 0:
        yakusu.append(d)
        yakusu.append(a//d)
    d += 1
if d*d == a:
    yakusu.append(d)
yakusu.sort(reverse=True)

ans = 1
for v in yakusu:
    cnt = 0
    for i in range(1,N):
        if A[i]%v != 0:
            cnt += 1
    if cnt <= 1:
        ans = v
        break

#A1を入れない場合の最大公約数を求める。
import math
g = A[1]
for i in range(2,N):
    g = math.gcd(g,A[i])

ans = max(ans,g)

print(ans)
import math
import sys

N = int(input())

for i in reversed(range(int(math.sqrt(N)))):
  if N % i == 0:
    print(i + N / i)
    sys.exit()

### FIXED CODE ###

import math

N = int(input())
a = N + 1
b = round(math.sqrt(N))

for i in range(b):
  j = i + 1
  if N % j == 0:
    if a > j + N / j:
      a = j + N / j
print(round(a) - 2)
N = int(input())
al = [int(an) for an in input().split()]
a = [ "4" if al[i]%4==0 else "k" if al[i]%2!=0 else "g" for i in range(N)]
print(a)
if a.count("k") == a.count("4") or len(a) == a.count(g):
	print("Yes")
elif (a.count("k") - 1) == a.count("4")  and a.count("g")==0:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

N = int(input())
al = [int(an) for an in input().split()]
a = [ "4" if al[i]%4==0 else "k" if al[i]%2!=0 else "g" for i in range(N)]
if a.count("k") == a.count("4") or len(a) == a.count("g") + a.count("4"):
	print("Yes")
elif (a.count("k") - 1) == a.count("4")  and a.count("g")==0:
	print("Yes")
else:
	print("No")
a, b = map(int, raw_imput().split())

 if a < b:
  print 'a < b' 
 elif a > b:
  print 'a > b'
 elif a == b:
  print 'a == b'

### FIXED CODE ###

a, b = map(int, raw_input().split())
 
if a < b:
 print "a < b"
elif a > b:
 print "a > b"
elif a == b:
 print "a == b"
import math
n = int(input())
h = list(map(int, input().split()))
#print(n)
#print(h)
counter = 0
countMax = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    counter +=1
    countMax = max(counter,countMax)
    else:
      counter = 0
print(countMax)


### FIXED CODE ###

import math
n = int(input())
h = list(map(int, input().split()))
#print(n)
#print(h)
counter = 0
countMax = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    counter +=1
    countMax = max(counter,countMax)
  else:
    counter = 0
print(countMax)
N,A = map(int,input().split())

M = N*N-A

print(M)


### FIXED CODE ###

N = int(input())
A = int(input())

print(N**2-A)
n,*a=map(open(0).read().split())
if 0 in a:
  print(0)
  exit()
s=1
for i in a:
  s*=i
  if s>10**18:
    print(-1)
    exit()
print(s)

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
if 0 in a:
  print(0)
  exit()
s=1
for i in a:
  s*=i
  if s>10**18:
    print(-1)
    exit()
print(s)
n, m = map(int, input().split())
p = [int(i) for i in input().split()]
graph = [[] for _ in range(n+1)]
group = [0]*n+1
ans = 0
for _ in range(m):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
for i, num in enumerate(p,1):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i
        space.extend(graph[point])
    ans += group[num]-group[i]
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
# p = [int(i) for i in input().split()]
p = map(int,input().split())
# graph = [[]]*(N+1)
graph = [[] for _ in range(N+1)]
group = [0]*(N+1)
ans = 0
for _ in range(M):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
for i, num in enumerate(p, 1):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i
        space.extend(graph[point])
    ans += (group[num] == group[i])
print(ans)
n = int(input())
a_s = map(int, input().split(' '))
b_s = map(int, input().split(' '))
c_s = map(int, input().split(' '))

i = 0
a = a_s[i]
b = b_s[a]

before_a = a
sas = b
for i in range(1, n):
  a = a_s[i]
  b = b_s[a]
  sas += b
  if before_a + 1 == a:
    sas += c_s[i-1]
  before_a = a
print(sas)

### FIXED CODE ###

n = int(input())
a_s = list(map(int, input().split(' ')))
b_s = list(map(int, input().split(' ')))
c_s = list(map(int, input().split(' ')))

sat = 0
for a_i in range(0, n):
    i = a_s[a_i] - 1
    b = b_s[i]
    sat += b
    if a_i < n-1 and a_s[a_i] +1 == a_s[a_i+1]:
        if i >= 0:
            sat += c_s[i]
print(sat)
import numpy as np
import sys
sys.setrecursionlimit(100000)


def main():
    n, m, x = map(int, input().split())
    cl = [None]*n
    al = [None]*n
    for i in range(n):
        cl[i], *al[i] = map(int, input().split())
    
    def dfs(i, cost, A):
        if i == n-1:
            global ans
            if all([a >= x for a in A]) and cost < ans:
                ans = cost
            return
        i += 1
        dfs(i, cost, A[:])
        dfs(i, cost+cl[i], A[:]+al[i])
    
    dfs(-1, 0, np.array([0]*n))
    
    print(ans)
        

if __name__ == "__main__":
    ans = 10**7
    main()

### FIXED CODE ###

import numpy as np
import sys
sys.setrecursionlimit(100000)

def main():
    n, m, x = map(int, input().split())
    cl = [None]*n
    al = [None]*n
    total = np.array([0]*m)
    global ans
    ans = 10**7
    for i in range(n):
        c, *a = map(int, input().split())
        a = np.array(a)
        cl[i] = c
        al[i] = a
        total += a
    def dfs(i, cost, A):
        i += 1
        if i == n:
            global ans
            if all([ai >= x for ai in A]) and ans > cost:
                ans = cost
            return
        dfs(i, cost, A[:])
        dfs(i, cost+cl[i], A[:]+al[i])
    dfs(-1, 0, np.array([0]*m))
    if ans == 10**7:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    main()
N = int(input())
A = list((map(int,input().split())))
B = list((map(int,input().split())))
C = list((map(int,input().split())))
 
total = sum(B)
point = 0
for i in range(len(A) - 1):
    if A[i] + 1 == A[i+1]:
        point = point+C[A[i-1]]
        print(point)
print(total+point)

### FIXED CODE ###

n=int(input())
print(n**3)
d={}
d['a']=list(input())
d['b']=list(input())
d['c']=list(input())
now='a'
while True:
  if d[now]>1:
    now=d[now].pop(0)
  else:
    print(now.upper())
    exit()

### FIXED CODE ###

d={}
d['a']=list(input())
d['b']=list(input())
d['c']=list(input())
now='a'
while True:
  if len(d[now])>0:
    now=d[now].pop(0)
  else:
    print(now.upper())
    exit()
N,M,P = map(int,input().split())
edge = [[]for i in range(N)]
cost = [-float('inf')]*N
A = [-1]*N
cost[0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    edge[a-1].append([b-1,c-P])

for i in range(N-1):
    for j in range(N):
        for b,c in edge[j]:
            if cost[b] < cost[j]+c:
                cost[b] = cost[j]+c
                A[b] = j

if A[0] != -1:
    print(-1)
    exit()
p = N-1
while p != -1 or p != N:
    A[p],p = N,A[p]
if p == -1:
    print(max(cost[-1],0))
else:
    print(-1)

### FIXED CODE ###

N,M,P = map(int,input().split())
edge = []
cost = [-float('inf')]*N
cost[0] = 0
for i in range(M):
    a,b,c = map(int,input().split())
    edge.append([a-1,b-1,c-P])

for i in range(N-1):
    for a,b,c in edge:
        cost[b] = max(cost[b],cost[a]+c)


for a,b,c in edge:
    if cost[b] < cost[a]+c:
        cost[b] = float('inf')


for i in range(N-1):
    for a,b,c in edge:
        cost[b] = max(cost[b],cost[a]+c)

if cost[-1] == float('inf'):
    print(-1)
else:
    print(max(cost[-1],0))
v = {a, e, i, o, u}
if input() in v:
  print("vowel")
else:
  print("consonant")

### FIXED CODE ###

v = set("aeiou")
if input() in v:
  print("vowel")
else:
  print("consonant")
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
gap = float("")
for i in range(n):
    print(gap)
    if abs(t - h[i] * 0.006 - a) < gap:
        ans = i + 1
        gap = abs(t - h[i] * 0.006 - a)
print(ans)

### FIXED CODE ###

n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
gap = float("inf")
for i in range(n):
    if abs(t - h[i] * 0.006 - a) < gap:
        ans = i + 1
        gap = abs(t - h[i] * 0.006 - a)
print(ans)
import sys
sys.setrecursionlimit(200000)
N = int(input())
T = [int(input()) for _ in range(N)]
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)

def lcm(a,b):
    g = gcd(a,b)
    return a*b//g

l = lcm(T[0],T[1])
for i in range(2,N):
    l = lcm(l,T[i])
print(l)

### FIXED CODE ###

"""
すべての秒数の最小公倍数を求める
Gを最大公約数として持つX,Yの最小公倍数はG*X/G*Y/G
"""
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
N = int(input())
T = [int(input()) for _ in range(N)]
tmp = T[0]
for i in range(1,N):
    t = T[i]
    g = gcd(tmp,t)
    tmp = g*(tmp//g)*(t//g)
print(tmp)
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.tsize = [1]*n

    
    def root(self,x):
        return x if self.par[x] == -1 else self.root(self.par[x])

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        if x_r != y_r:
            #update size
            self.tsize[y_r] += self.tsize[x_r]
            #update parent (y_r is root)
            self.par[x_r] = y_r

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]


def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]


def main():
    n,m = tuple([int(t)for t in input().split()])

    bridge = [tuple([int(t)-1 for t in input().split()])for _ in [0]*m]
    bridge = bridge[::-1]

    uf = UnionFind(n)
    ans = [n*(n-1)//2]
    for a_i,b_i in bridge:
        if not uf.isSame(a_i,b_i):
            ans.append(ans[-1]-uf.size(a_i)*uf.size(b_i))
            uf.unite(a_i,b_i)
        else:
            ans.append(ans[-1])
    ans.pop()
    for a in ans[::-1]:
        print(a)



if __name__ == "__main__":
    main()
def bubbleSort(A, N): # N 個の要素を含む 0-オリジンの配列 A
    A = list(map(int, A.split()))
    flag = 1 # 逆の隣接要素が存在する
    count = 0  # 交換回数
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                # A[j] と A[j-1] を交換
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
    print(" ".join(map(str,A)))
    print(count)

N = int(input())
A = input()
bubbleSort(A, N)


### FIXED CODE ###

def BS(A, N):
    A = list(map(int, A.split()))
    flag = 1
    count = 0 
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                unk = A[j]
                A[j] = A[j-1]
                A[j-1] = unk
                flag = 1
                count = count +1
    print(" ".join(map(str,A)))
    print(count)
 
N = int(input())
A = input()
BS(A, N)
N, X=map(int, input().split)
A=[int(input(for _ in range(N)))]
print((X-sum(A))//min(A)+N)

### FIXED CODE ###

N, X=map(int, input().split())
A=[int(input()) for _ in range(N)]
rest=X-sum(A)
print(rest//min(A)+N)
N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

N,M=map(int,input().split())
G = [[] for _ in range(N)]
for i in range(M):
  x,y=map(int,input().split())
  G[x-1].append(y-1)
  
dp = [-1]*N

def rec(v):
  if dp[v] != -1:
    return dp[v]
  res = 0
  for next_v in G[v]:
    res = max(res, rec(next_v)+1)
  dp[v] = res
  return dp[v]
  
for i in range(N):
  dp[i] = rec(i)
  
print(max(dp))
N,K=map(int,input().split())
X=list(map(int,input().split()))
if X[0]>=0:
    b=X[K]
elif X[-1]<=0:
    b=X[-K]
elif 0 in X:
    a=0
    b=10**9
    for i in range(N):
        if X[i]==0:
            a=i
            break
    for j in range(max(0,K-1-a),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
else:
    a=0
    b=10**9
    for i in range(N):
        if X[i]>0:
            a=i
            break
    for j in range(max(-1,K-a-1),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
        print(X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])),j,X[a+j],X[a+j-K+1],min(K-a+1,N-a+1))   
print(b)

### FIXED CODE ###

N,K=map(int,input().split())
X=list(map(int,input().split()))
if X[0]>=0:
    b=X[K-1]
elif X[-1]<=0:
    b=abs(X[-K])
elif 0 in X:
    a=0
    b=10**9
    for i in range(N):
        if X[i]==0:
            a=i
            break
    for j in range(max(0,K-1-a),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
else:
    a=0
    b=10**9
    for i in range(N):
        if X[i]>0:
            a=i
            break
    for j in range(max(-1,K-a-1),min(K,N-a)):
        if b>X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1])):
            b=X[a+j]-X[a+j-K+1]+min(abs(X[a+j]),abs(X[a+j-K+1]))
print(b)
N = int(input())
S = input()

ANS = ""

for MOJI in S:
  i = ord(MOJI) + N
  if i > 90:
    i = i - 26
  ANS.append(chr(i))

### FIXED CODE ###

N = int(input())
S = input()

ANS = ""

for MOJI in S:
  i = ord(MOJI) + N
  if i > 90:
    i = i - 26
  ANS = ANS + chr(i)

print(ANS)
import numpy

x1,x2,x3,x4 = map(float, input().split())
n = (x3 - x1)**2 + (x4 - x2)**2
ans = numpy.sqrt(n)
print(ans)


### FIXED CODE ###

import math

x1,x2,x3,x4 = map(float, input().split())
n = (x3 - x1)**2 + (x4 - x2)**2
ans = math.sqrt(n)
print(ans)
N, M = map(int,input().split())
if M == 1:
  print(0)
  exit()
X = list(map(int,input().split()))
X.sort()
dif = {}
for i in range(M-1):
  dif[i] = X[i+1]-X[i]
  
sorted_dif = sorted(dif.items(), key=lambda x:x[1], reverse=True)
difs = 0
for i in range(N-1):
  difs += sorted_dif[i][1]

print(X[-1]-X[0]-difs)

### FIXED CODE ###

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

if N >= M:
  print(0)
  exit()
  
X = list(map(int,input().split()))
X.sort()

dif = {}
for i in range(M-1):
  dif[i] = X[i+1]-X[i]
  
sorted_dif = sorted(dif.items(), key=lambda x:x[1], reverse=True)
difs = 0
for i in range(N-1):
  difs += sorted_dif[i][1]

print(X[-1]-X[0]-difs)
S=input()
N=len(S)
if N<5:
  print(0)
  exit()
A={}
for i in range(N-4+1):
  a=int(S[i:])%2019
  A.setdefault(a,0)
  A[a]+=1

ans=0
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

for i in A.values():
  if i>1:
    ans+=cmb(i,2)
ans+=A[0]
print(ans)

### FIXED CODE ###

s=input()
n=0
ans=0
A=[0]*2019
A[0]=1
for i,j in enumerate(reversed(s)):
  n=(n+int(j)*pow(10,i,2019))%2019
  #print(i,n)
  A[n]+=1
for i in A:
  ans+=i*(i-1)//2
print(ans)
N = int(input())

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

sumw = sum(W)
for i in range(N):
	ans = abs(sum(W[:,i+1])-sum(W[i+1:]))
	if ans < sumw:
		sumw = ans

print(sumw)

### FIXED CODE ###

N = int(input())

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

sumw = sum(W)
for i in range(N):
	ans = abs(sum(W[:i+1])-sum(W[i+1:]))
	if ans < sumw:
		sumw = ans

print(sumw)
X, Y = map(int, input().split())

if Y < X*2 :
  print("No")
  eit()
  
if Y % 2 == 0:
  print("Yes")
else:
  print("No")
  
  

### FIXED CODE ###

X, Y = map(int, input().split())

if Y < X*2 :
  print("No")
  exit()

elif Y > X*4:
  print("No")
  exit()
    
if Y % 2 == 0:
  print("Yes")
else:
  print("No")
n = int(input())

a = []

for i in range(n):
  	# input as str
	s, p = input().split()
    # p -> integer
	p = int(score)
    # create list
	a.append((s, p, i+1))

# sort
a.sort(key=lambda x:x[1], reverse=True)

# sort
a.sort(key=lambda x:x[0])

# output
for i in range(n):
	print(a[i][2])

### FIXED CODE ###

a,p=map(int,input().split())
tmp = 3*a+p
print(tmp//2)
a, b = map(int, raw_input().split())
return (a*b (a+b)*b)

### FIXED CODE ###

a,b=map(int,raw_input().split())
print a*b,(a+b)*2
N = int(input())
list = list(map(int, input().split()))
no = 1
ans = list[0]
for i in range(N):
  ans = ans*list[no]
  no += 1
print(ans if ans <= 10**18 else "-1")

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        print(0)
        exit()
    for i in A:
        ans *= i
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)
resolve()
n=int(input())
s=input()

def rev(x):
    if x=="S":
        return "W"
    else:
        return "S"

def wolfsheep(xy):
    global n,s
    result=[xy[0],xy[1]]

    for i in range(1,n+1):
        if result[i]=="S":
            s+=s[0]
            if s[i]=="o":
                result.append(result[i-1])
            else:
                result.append(rev(result[i-1]))
        else:
            if s[i]=="o":
                result.append(rev(result[i-1]))
            else:
                result.append(result[i-1])

    if result[0]==result[n] and result[1]==result[n+1]:
        return result
    else:
        return 0

#SWパターン
tmp= wolfsheep("SW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

#SSパターン
tmp= wolfsheep("SS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WWパターン
tmp= wolfsheep("WW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WSパターン
tmp= wolfsheep("WS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

print(-1)

### FIXED CODE ###

n=int(input())
s=list(input())

def rev(x):
    if x=="S":
        return "W"
    else:
        return "S"

def wolfsheep(xy):
    global n,s
    result=[xy[0],xy[1]]

    for i in range(1,n+1):
        s+=s[0]
        if result[i]=="S":
            if s[i]=="o":
                result.append(result[i-1])
            else:
                result.append(rev(result[i-1]))
        else:
            if s[i]=="o":
                result.append(rev(result[i-1]))
            else:
                result.append(result[i-1])

    if result[0]==result[n] and result[1]==result[n+1]:
        return result
    else:
        return 0

#SWパターン
tmp= wolfsheep("SW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

#SSパターン
tmp= wolfsheep("SS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WWパターン
tmp= wolfsheep("WW")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()
#WSパターン
tmp= wolfsheep("WS")
if tmp!=0:
    print("".join(tmp[:-2]))
    exit()

print(-1)