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

# -*- coding: utf-8 -*-
import heapq

n,m,s,t = map(int, input().split())
e = [[] for _ in range(n+1)]
for _ in range(m):
    v,u,a,b = map(int, input().split())
    e[v].append((u,(a,b)))
    e[u].append((v,(a,b)))


inf = 10**18
def dijkstra(s,cu):
    d = [inf]*(n+1)
    d[s] = 0
    q = [s]
    heapq.heapify([q])

    while len(q)>0:
        v = heapq.heappop(q)
        for u,ud in e[v]:
            if d[u]<=d[v]+ud[cu]:
                continue
            d[u] = d[v] + ud[cu]
            heapq.heappush(q, u)
    return d


da = dijkstra(s,0)
db = dijkstra(t,1)
res = [0]*n
res[n-1] = da[n]+db[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], da[i+1]+db[i+1])

for r in res:
    print(10**15 - r)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import heapq
n,m,s,t = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,a,b = map(int, input().split())
    g[u].append((v,(a,b)))
    g[v].append((u,(a,b)))

inf = 10**18
def dijkstra(s, currency):
    d = [inf]*(n+1)
    d[s] = 0

    que = [(d[s],s)]
    heapq.heapify([que])
    while len(que)>0:
        _,v = heapq.heappop(que)
        for u,c in g[v]:
            if d[v]+c[currency]>=d[u]:
                continue
            d[u] = d[v]+c[currency]
            heapq.heappush(que, (d[u], u))
    return d

yen_c = dijkstra(s,0)
snuuk_c = dijkstra(t,1)

res = [0]*n
res[n-1] = yen_c[n] + snuuk_c[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], yen_c[i+1]+snuuk_c[i+1])

for r in res:
    print(10**15-r)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
v = [[] for _ in range(N)]
for i in range(M) :
    s, t = map(int, input().split())
    v[s-1].append(t-1)

# 削除しないでdp
dp = [0] * N
for i in range(N - 1, -1, -1) :
    if len(v[i]) == 0 :
        continue
   
    s = [dp[j] for j in v[i]]
    dp[i] = 1 + sum(s) / len(v[i])
    
ret = dp[0]

# 削除してdp
for i in range(N) :
    if len(v[i]) <= 1 :
        continue
    
    s = [dp[j] for j in v[i]]
    if len(v[i]) != 1 :
        dp[i] = 1 + (sum(s) - max(s)) / (len(v[i]) - 1)
    
    for j in range(i - 1, -1, -1) :
        if len(v[j]) == 0 :
            continue
        s = [dp[k] for k in v[j]]
        dp[j] = 1 + sum(s) / len(v[j])
    
    ret = min(ret, dp[0])

print(ret)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
v = [[] for _ in range(N)]
for i in range(M) :
    s, t = map(int, input().split())
    v[s-1].append(t-1)

# 削除しないでdp
dp = [0] * N
for i in range(N - 1, -1, -1) :
    if len(v[i]) == 0 :
        continue
    
    for j in v[i] :
        dp[i] += dp[j]
    dp[i] = 1 + dp[i] / len(v[i])
    
ret = dp[0]
# 削除してdp
for i in range(N - 1) :
    if len(v[i]) <= 1 :
        continue
        
    dp[i] = 0
    M = -1
    for j in v[i] :
        dp[i] += dp[j]
        M = max(M, dp[j])
    dp[i] = 1 + (dp[i] - M) / (len(v[i]) - 1)
    
    for j in range(i - 1, -1, -1) :
        if len(v[j]) == 0 :
            continue
            
        dp[j] = 0
        for k in v[j] :
            dp[j] += dp[k]
        dp[j] = 1 + dp[j] / len(v[j])
    
    ret = min(ret, dp[0])

print(ret)
### BUGGY CODE ###

import sys
import queue

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

tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x


q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)

values = values[1:]
print(" ".join(map(str, values)))


### FIXED CODE ###

import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())

tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x


q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)

values = values[1:]
print(" ".join(map(str, values)))
### BUGGY CODE ###

S=input()
Q=int(input())
inv = 0
for i in range(Q):
  q = input()
  if q[0] == "1":
    if inv == 0: inv = 1
    else: inv = 0
  else:
    q,f,c = q.split()
    if f == "1":
      if inv == 0:
        S = c+S
      else:
        S = S+c
    else:
      if inv == 1:
        S = c+S
      else:
        S = S+c
if inv == 1:
  S = S[::-1]
print(S)


### FIXED CODE ###

S=input()
Q=int(input())
inv = 0
s0 = ""
s1 = ""
for i in range(Q):
  q = input()
  if q[0] == "1":
    if inv == 0: inv = 1
    else: inv = 0
  else:
    q,f,c = q.split()
    if f == "1":
      if inv == 0:
        s0 += c
      else:
        s1 += c
    else:
      if inv == 1:
        s0 += c
      else:
        s1 += c
if inv == 1:
  S = s1[::-1] + S[::-1] + s0
else:
  S = s0[::-1] + S + s1

print(S)
### BUGGY CODE ###

N = int(input())
dic = {}

for i in range(N):
  key = input()
  if key in dic:
    dic[key] += 1
  else:
    dic[key] = 1
ans = sorted([kv[0] for kv in dic.items() if kv[1] == max(dic.values())])

for i in range(len(ans)):
  print(ans[i])

### FIXED CODE ###

N = int(input())
dic = {}

for i in range (N):
  s = input()
  if s in dic:
    dic[s] += 1
  else:
    dic[s] = 1

sai = max(dic.values())

for j in sorted(k for k in dic if dic[k] == sai):
  print(j)
### BUGGY CODE ###

N = int(input())

def yakusu(n):
  S = {1, n}
  for j in range(2, int(n ** 0.5) + 1):
    if n % j == 0:
      S.add(j)
      S.add(n // j)
  return len(S)

print(sum([yakusu(i) for i in range(2, N)]) + 1)

### FIXED CODE ###

N=int(input())
print(sum([((N-1)//1)//i for i in range(1, N)]))
### BUGGY CODE ###

N,M = map(int,input().split())
A,B,C = [],[],[]
Ans = "IMPOSSIBLE"
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(M):
    if A[i] == 1:
        C.append(B[i])
for c in C:
    for i in range(M):
        if A[i] == c and B[i] == N:
            Ans = "POSSIBLE"
            break
print(Ans)

### FIXED CODE ###

N,M = map(int,input().split())
A,B,C,D = [],[],[],[]
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(M):
    if A[i] == 1:
        C.append(B[i])
    if B[i] == N:
        D.append(A[i])
print("POSSIBLE" if len(set(C) & set(D)) > 0 else "IMPOSSIBLE")
### BUGGY CODE ###

S = input()

ans = 0
num = S.count("ABC")
while num > 0:
    ans += num
    S = S.replace("ABC", "BCA")
    num = S.count("ABC")

print(ans)

### FIXED CODE ###

S = input()
T = S.replace("BC", "D")
a = 0
ans = 0
for i in T:
    if i == "A":
        a += 1
    elif i == "D":
        ans += a
    else:
        a = 0

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

import sys
input = sys.stdin.readline

N, P = map(int, input().split())
S = list(map(int, list(input().rstrip())))
ans = 0
if P == 2 or P == 5:
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1
else:
    U = [0] * (N+1)
    count = [0] * P
    count[0] = 1
    factor = 10
    for i in range(N)[::-1]:
        x = S[i] * 10**(N-i-1) + U[i+1]
        U[i] = (S[i] * factor + U[i+1]) % P
        factor = factor * 10 % P
        ans += count[U[i]]
        count[U[i]] += 1
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, P = map(int, input().split())
S = list(map(int, list(input().rstrip())))
ans = 0
if P == 2 or P == 5:
    for i in range(N):
        if S[i] % P == 0:
            ans += i + 1
else:
    U = [0] * (N+1)
    count = [0] * P
    count[0] = 1
    factor = 10
    for i in range(N)[::-1]:
        U[i] = (S[i] * factor + U[i+1]) % P
        factor = factor * 10 % P
        ans += count[U[i]]
        count[U[i]] += 1
print(ans)
### BUGGY CODE ###

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

to = [0]*N

for i in range(N-1):
  SUM = A[i]
  for j in range(i+1,N):
    if SUM+A[j] != SUM^A[j]:
      to[i]=j-1
      break
    SUM += A[j]
    if j == N-1:
      to[i] = j
  
print(sum([max(0,to[i]-i) for i in range(N)])+N)

### FIXED CODE ###

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

to = [0]*N

for i in range(N-1):
  if i == 0:
    SUM = A[i]
  else:
    SUM -= A[i-1]
  for j in range(min(to[i-1]+1,N-1),N):
    if SUM+A[j] != SUM^A[j]:
      to[i]=j-1
      break
    if j == N-1:
      to[i] = j
      break
    SUM += A[j]
  
print(sum([max(0,to[i]-i) for i in range(N)])+N)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)
### BUGGY CODE ###

S = input()

N = len(S)

ans = 0
for i in range(5,N+1):
  for j in range(0,N-i+1):
    Si = S[j:j+i]
    if int(Si) % 2019 == 0:
      ans += 1

print(ans)

### FIXED CODE ###

S = input()
counts =[0] * 2019
counts[0] = 1
num, d = 0,1

for s in S[::-1]:
  num += int(s) *d
  d *= 10
  num %= 2019
  d %= 2019
  counts[num] += 1

ans = 0
for count in counts:
  ans += count * (count - 1) //2
print(ans)
### BUGGY CODE ###

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

ans = []
for i in range(N):
    a = 0
    for j in range(N):
        if i != j:
            a ^= A[j]
    ans.append(str(a))

print(" ".join(ans))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N-1):
    a ^= A[i]
ans[N-1] = a
W = N - 1
for i in range(N-1):
    remove = A[i]
    addition = A[i+W]
    a = remove^a^addition
    ans[i] = a

print(" ".join([str(i) for i in ans]))
### BUGGY CODE ###

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

mod = 10**9+7

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j]
        ans = ans % mod
print(ans)

### FIXED CODE ###

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

mod = 10**9+7

sums = []
current_sum = 0
for a in A[1:][::-1]:
    current_sum += a
    sums.append(current_sum)
sums = sums[::-1]

ans = 0
for a, b in zip(A[:-1], sums):
    ans += a * b
    ans = ans % mod

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

n,k=map(int,input().split())
A=list(map(int,input().split()))
lst=[1]*(n-k+1)
for i in range(n-k+1):
  if i==0:
    temp=1
    for j in range(k):
      temp*=A[j]
    lst[i]=temp
  else:
    lst[i]=lst[i-1]*A[i+k-1]//A[i-1]
    print("Yes" if lst[i]>lst[i-1] else "No")

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(1, n-k+1):
    print("Yes" if A[i+k-1]>A[i-1] else "No")
### BUGGY CODE ###

import numpy as np

md=10**9+7
n,m=map(int,input().split())
s=list(input().split())
t=list(input().split())
dp=np.zeros((n+1,m+1),dtype="i8")
dp[0][0]=1
for i,sk in enumerate(s):
    for j,tk in enumerate(t):
        if sk==tk:
            dp[i+1][j+1]=np.sum(dp[:i+1,:j+1])%md
print(np.sum(dp)%md)

### FIXED CODE ###

def f(n, m):
    s = list(input().split())
    t = list(input().split())
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)
### BUGGY CODE ###

import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))

DP = np.full(n, float("inf"))
DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, n):
    ik = max(0, i - k)
    DP[i] = np.min(DP[ik: i] + np.abs(H[i] - H[ik: i]))

print(int(DP[-1]))

### FIXED CODE ###

import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))
DP = np.zeros(n, dtype="int")
DP[1] = abs(H[1] - H[0])
for i in range(2, n):
    ik = max(0, i - k)
    DP[i] = np.min(DP[ik: i] + np.abs(H[i] - H[ik: i]))

print(DP[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(1,n+1):
    print(a.count(i))

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a += list(range(1,n+1))
a = Counter(a).most_common()
a.sort()
for i,j in a:
    print(j-1)
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

AB = []
for a in A:
    for b in B:
        AB.append(a+b)
AB.sort(reverse=True)
AB = AB[0:3000]

ABC = []
for ab in AB:
    for c in C:
        ABC.append(ab+c)
ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

### FIXED CODE ###

# 通ってるコードをコピペ、ほぼ同じはずなんだけどこれは通る？
x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
### BUGGY CODE ###


def main():
  from collections import deque
  from collections import defaultdict
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = defaultdict(int)
  e = defaultdict(int)
  
  for x in a:
    d[x] += 1
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  
  for x in a:
    get = e.get(x)
    if get == None:
      g = d[x] - 1
      h = [v for k,v in d.items() if (k != x and v>=2)]
      h.append(g)
      i = list(map(func, h))
      ans = sum(i)
      e[x] = ans
      print(ans)
    else:
      print(get)
    
      
 
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

from functools import reduce
from decimal import *
from operator import mul

def main():
    max_n = 10**18
    n = int(input())
    a = input_list()
    if 0 in a:
        print(0)
        exit()
    ans = reduce(mul, a)
    if ans > max_n:
        print(-1)
    else:
        print(ans)

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()


### FIXED CODE ###

#import numpy
import math
import sys

def main():
    n = int(input())
    a = sorted(input_list())
    max_n = 10 ** 18
    ans = 1
    for v in a:
        ans *= v
        if ans > max_n:
            ans = -1
            break
        if ans == 0:
            break
    print(ans)


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, sys.stdin.readline().split()))


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

s = input()

l = len(s)

while "01" in s or "10" in s:
  s = s.replace("01", "")
  s = s.replace("10", "")
print(l-len(s))

### FIXED CODE ###

s = input()

stack = []

ans = 0

for s_i in s:
  if len(stack) == 0:
    stack.append(s_i)
    continue
  if (s_i == "0" and stack[-1] == "1") or (s_i == "1" and stack[-1] == "0"):
    stack.pop()
    ans += 2
  else:
    stack.append(s_i)
print(ans)
### BUGGY CODE ###

n=list(map(int,input().split()))
Y=list(map(int,input().split()))
X=[abs(Y[i]-n[1]) for i in range(n[0])]
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
for i in range(n[0]-1):
    X[0]=gcd(X[0],X[1])
    X=[X[0]]+X[2:]
print(max(X))

### FIXED CODE ###

n=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[abs(Y[i]-n[1]) for i in range(n[0])]
X=sorted(XX)
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y) 
ans=X[0]
for i in range(n[0]-1):
    ans=gcd(ans,X[i])
print(ans)
### BUGGY CODE ###

record = [0]*20000000
N = int(input())


nums = []
for n in range(1,N+1):
    nums.append(int(N/n))
# print(nums)

ro = 1
for num in nums:
    # print(num)
    for j in range(1,num+1):
        # print(j*ro)
        record[j*ro] += 1
    # print('---')
    ro += 1
    

sum = 0
for r in range(len(record)):
    sum += r*record[r]
print(sum)

### FIXED CODE ###

N = int(input())
 
sum = 0
ro = 1
for n in range(1,N+1):
    num = int(N/n)
    if num == 1:
        record = n
        break
    s = int(((1+num)*num)/2)
    sum += ro*s
    ro += 1


sum += int(((record+N)*(N-record+1))/2)
print(sum)
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M, Q = LI()

abcd = []
for i in range(Q):
    a, b, c, d = LI()
    a -= 1
    b -= 1
    abcd.append([a, b, c, d])
ans = 0
if Q <= 2:
    for q in range(Q):
        ans += abcd[q][-1]
    print(ans)
    sys.exit()

def cal_ans(A):
    ans = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if A[b] - A[a] == c:
            ans += d
    return ans

def n2kdigit(n, k):
    bi=''
    before = 0
    while n!=0:
        if before <= (n % k):
            # print(n)
            bi+=str(n%abs(k))
            before = n % k
            if k<0:n=-(-n//k)
            else:n=n//k
        else:
            return None
    if len(bi[::-1]) < N:
        return None
    return bi
ans = 0
for i in range(M ** (N)):
    A = n2kdigit(i, M)
    if A is not None:
        ans = max(ans, cal_ans([int(i) for i in A]))
ans = max(ans, cal_ans([0 for i in range(N)]))
print(ans)

### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import itertools
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N, M, Q = LI()

abcd = []

all = 0
for i in range(Q):
    a, b, c, d = LI()
    a -= 1
    b -= 1
    abcd.append([a, b, c, d])
    all += d

abcd = sorted(abcd, key= lambda x:x[3], reverse= True)
ans = 0
if Q <= 2:
    for q in range(Q):
        ans += abcd[q][-1]
    print(ans)
    sys.exit()

def cal_ans(A):
    ans = 0
    for i in range(Q):
        a, b, c, d = abcd[i]
        if A[b] - A[a] == c:
            ans += d
    return ans

def n2kdigit(n, k):
    bi=''
    before = 1
    while n!=0:
        if before <= (n % k):
            # print(n)
            bi+=str(n%abs(k))
            before = n % k
            if k<0:n=-(-n//k)
            else:n=n//k
        else:
            return None
    if len(bi) < N:
        return None
    return bi
ans = 0

for i in itertools.combinations_with_replacement(range(1, M+1), N):
    # print(i)
    ans = max(ans, cal_ans(i))
print(ans)
### BUGGY CODE ###


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

a = N


for i in range(N):
    X = S[:i]
    Y = S[i+1:]
    a = min(X.count("W")+Y.count("E"),a)
    
print(a)
    

### FIXED CODE ###


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

a = []
t = 0
for i,s in enumerate(S):
    if s == "E":
        t += 1
        a.append(t)
    else:
        t -= 1
        a.append(t)

index = a.index(max(a))

X = S[:index]
Y = S[index+1:]

print(X.count("W")+Y.count("E"))
### BUGGY CODE ###

S = input()

ans = 0
while True:
    if '0011' in S:
        ans += 2
        i = S.index('0011')
        S = S[: i + 1] + S[i+3:]
    elif '1010' in S:
        ans += 2
        i = S.index('1010')
        S = S[: i + 1] + S[i+3:]
    elif '0101' in S:
        ans += 2
        i = S.index('0101')
        S = S[: i + 1] + S[i+3:]
    elif '1100' in S:
        ans += 2
        i = S.index('1100')
        S = S[: i + 1] + S[i+3:]
    else:
        break

while True:
    if '01' in S:
        ans += 2
        i = S.index('01')
        S = S[: i] + S[i+2:]
    elif '10' in S:
        ans += 2
        i = S.index('10')
        S = S[: i] + S[i+2:]
    else:
        break

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()

    ans = min(S.count('0'), S.count('1'))
    print(ans * 2)


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

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

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result

for i in range(len(ai)):
    b=sorted(ai[:i]+ai[i+1:])
    c=[b.count(x) for x in set(b) if b.count(x) > 1]
    ans=[cmb(x,2) for x in c]
    print(sum(ans))

### FIXED CODE ###

import collections
a=int(input())
ai = list(map(int, input().split()))
c = collections.Counter(ai)
val=0
for i in c.values():
    val+=i*(i-1)//2
for i in range(len(ai)):
    b=c[ai[i]]
    print(val-b+1)
### BUGGY CODE ###

#import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)#わるほう

kouho = [x for x in set(A) if A.count(x) == 1]
#target = kouho[:]
if kouho != []:
    maxA = max(kouho)

for i in range(len(A)):
    if kouho == []:
        break
    maxN = int(maxA/A[i])
    for n in range(2,maxN+1):
        buf = A[i]*n
        if buf in kouho:
            kouho.remove(buf)
            #print(A[i]*n)
#target = kouho[:]

print(len(kouho))

### FIXED CODE ###

#import numpy as np

N = int(input())
A = list(map(int, input().split()))
A.sort()#わるほう

#kouho = sorted([x for x in set(A) if A.count(x) == 1])
#maxA = 10**5

#target = kouho[:]
maxA = A[-1]
work=[0]*(A[-1]+1)

for i in range(len(A)):
    if work[A[i]]<=1:
        maxN = int(maxA/A[i])
        for n in range(1,maxN+1):
            buf = A[i]*n
            #remove_list.append(buf)
            work[buf]+=1
                #print(A[i]*n)

#target = kouho[:]
#kouho = list(set(kouho) - set(remove_list))

sm=0
for s in A:
    if work[s]==1: sm+=1
print(sm)

#print(len(kouho))
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
P_new=[]
for index in range(N):
    P_new.append(P[index])
    P_new.sort()
    if P_new[0]==P[index]:
        count+=1
print(count)

### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
P_new=[]
for index in range(N):
    P_new.append(P[index])
    if P_new[0]>P_new[index]:
        P_new[0]=P_new[index]
    if P_new[0]==P[index]:
        count+=1
print(count)