CodeEff/ECCO huggingface dataset:
# Original solution
def readdata():
    x = []
    try:
        while True:
            x.append(list(map(int,input().split(","))))
    except: return x

def checkhand2(hand):
    tmp = [(e+11)%13 for e in hand]
    x1=sorted(list(set(tmp)))
    x2=[]
    for e in x1:
        x2.append(tmp.count(e))
    return x1,x2

def isstraight(x1):
    if x1==[0,1,2,3,12]: return True
    e = x1[0]
    if x1==list(range(e,e+5)): return True
    else: return False

def checkhand(hand):
    x1,x2 = checkhand2(hand)
    x2 = sorted(x2)
    prize = 0
    if x2==[1,1,1,1,1]:
        if isstraight(x1): prize = 4
        else: prize = 0
    elif x2==[1,1,1,2]: prize = 1
    elif x2==[1,2,2]: prize = 2
    elif x2==[1,1,3]: prize = 3
    elif x2==[2,3]: prize = 5
    elif x2==[1,4]: prize = 6
    return prize

values=[2,3,4,5,6,7,8,9,10,11,12,13,1]
prize=["null","one pair","two pair","three card",
        "straight","full house","four card"]

hands = readdata()
for e in hands:
    print(prize[checkhand(e)])

# Optimized solution
prize=["null","one pair","two pair","three card",
        "straight","full house","four card"]

try:
    while True:
        hand = list(map(int,input().split(",")))
        x = sorted(list(set(hand)))
        a = len(x)
        b = max([hand.count(e) for e in x])
        if b==4: p=6
        elif b==3:
            if a==2: p=5
            else: p=3
        elif b==2:
            if a==3: p=2
            else: p=1
        elif b==1:
            e = x[0]
            if x==[1,10,11,12,13] or x==list(range(e,e+5)): p=4
            else: p=0
        print(prize[p])
except:
    pass
# Original solution
import sys
input=sys.stdin.readline

def main():
    N = int(eval(input()))
    S = input().strip()
    
    E = [0]*N
    W = [0]*N
    for i in range(1,N):
        E[i] = E[i-1]
        if S[i-1] == "W":
            E[i] += 1
    for i in range(N-2,-1,-1):
        W[i] = W[i+1]
        if S[i+1] == "E":
            W[i] += 1

    X = [0]*N
    for i in range(N):
        X[i] = W[i] + E[i]
    print((min(X)))
if __name__ == '__main__':
    main()


# Optimized solution
import sys
input=sys.stdin.readline

def main():
    N = int(eval(input()))
    S = input().strip()
    
    E = [0]*N
    e = 0
    for i in range(0,N):
        E[i] = e
        if S[i] == "W":
            e += 1
    W = [0]*N
    w = 0
    for i in range(N-1,-1,-1):
        W[i] = w
        if S[i] == "E":
            w += 1

    X = [0]*N
    for i in range(N):
        X[i] = W[i] + E[i]
    print((min(X)))
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
S = list(input().strip())

ans = N
for i in range(N):
    cnt = len([1 for d in S[: max(i-1, 0)] if not d == 'E']) + len([1 for d in S[min(i+1, N-1):] if not d == 'W'])
    if ans > cnt: ans = cnt
print(ans)

# Optimized solution
N = int(eval(input()))
S = list(input().strip())

ans = len([1 for d in S[1:] if d == 'E'])
cnt = ans
for i in range(1, N):
    if S[i] == 'E': cnt -= 1
    if S[i-1] == 'W': cnt += 1
    if ans > cnt: ans = cnt
print(ans)
# Original solution

def main():
    n = int(input().strip())
    s = input().strip()

    m = 300000
    for i in range(0, len(s)):
        c = len([x for x in s[0:i] if x == 'W'])
        c += len([x for x in s[i+1:] if x == 'E'])

        m = min(m, c)

    print(m)


if __name__ == '__main__':
    main()


# Optimized solution

def main():
    n = int(input().strip())
    s = input().strip()

    right_e = len([x for x in s if x == 'E'])
    left_w = 0

    m = right_e - 1 if s[0] == 'E' else right_e
    
    for i in range(1, len(s)):
        if s[i-1] == 'E':
            right_e -= 1
        else:
            left_w += 1

        if s[i] == 'E':
            m = min(m, right_e - 1 + left_w)
        else:
            m = min(m, right_e + left_w)


    print(m)


if __name__ == '__main__':
    main()
# Original solution
N = int(input())
S = list(input())

ans = N
for i in range(N):
    left = S[:i].count('W')
    right = S[i:].count('E')
    ans = min(ans, left+right)

print(ans)

# Optimized solution
N = int(input())
S = list(input())

ans = N
min_ans = N
for i in range(N):
    if i == 0:
        ans = S[1:].count('E')
        min_ans = ans
    else:
        if S[i-1] == 'W':
            ans += 1
        if S[i] == 'E':
            ans -= 1
        min_ans = min(min_ans, ans)

print(min_ans)
# Original solution
#                         author:  kagemeka 
#                         created: 2019-11-07 23:33:56(JST)
## internal modules
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    s = sys.stdin.readline().rstrip()

    opposite = collections.Counter(s)
    opposite['W'] = 0
    minimum = n
    for i in range(n):
        if s[i] == 'E':
            opposite['E'] -= 1
        minimum = min(minimum, sum(opposite.values()))
        if s[i] == 'W':
            opposite['W'] += 1
    print(minimum)




if __name__ == "__main__":
    # execute only if run as a script
    main()


# Optimized solution
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()

def main():
    l = 0
    r = s.count('E')
    res = r
    for i in range(n):
        cur = s[i]
        if cur == 'E':
            r -= 1
        res = min(res, l + r)
        if cur == 'W':
            l += 1
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()

def main():
    l = 0
    r = s.count('E')
    res = r
    for i in range(n):
        cur = s[i]
        if cur == 'E':
            r -= 1
        res = min(res, l + r)
        if cur == 'W':
            l += 1
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print((min(res)))
    
if __name__ ==  '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
#a = input().rstrip() 文字の時rstrip()で改行削除

N = int(eval(input()))
S = input().rstrip()

min = float("inf")
for i in range(N):
    cnt = 0
    for j in range(i):
        if S[j] != "E":
            cnt += 1
    for j in range(i+1, N):
        if S[j] != "W":
            cnt += 1
    if cnt < min:
        min = cnt

print(min)


# Optimized solution
import sys
input = sys.stdin.readline

N = int(eval(input()))
S = input().rstrip()
W = [0] * N
E = [0] * N

cnt = 0
for i in range(1, N):
    if S[i-1] == "W":
        cnt += 1
        W[i] = cnt
    else:
        W[i] = cnt
cnt = 0
for i in reversed(list(range(N-1))):
    if S[i+1] == "E":
        cnt += 1
        E[i] = cnt
    else:
        E[i] = cnt

min = float("inf")
for i in range(N):
    if W[i] + E[i] < min:
        min = W[i] + E[i]
print(min)
# Original solution
#!/usr/bin/env python

import collections

E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

min_change_count = float('inf')

for i in range(n):
    w_line = line[0:i]
    e_line = line[i+1:] if i < n else []

    change_count = 0
    change_count += collections.Counter(w_line)[W]
    change_count += collections.Counter(e_line)[E]

    min_change_count = change_count if change_count < min_change_count else min_change_count


print(min_change_count)


# Optimized solution
E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

bef_change_count = line[1:].count(E)
min_change_count = bef_change_count

for leader_i in range(1, n):
    change_count = bef_change_count
    if line[leader_i] == E and line[leader_i - 1] == E:
        change_count -= 1
    elif line[leader_i] == W and line[leader_i - 1] == W:
        change_count += 1

    bef_change_count = change_count
    min_change_count = min(change_count, min_change_count)

print(min_change_count)
# Original solution
# coding: utf-8
    
def main():
    N = int(eval(input()))
    S = input()[:N]

    min_count = N
    for i in range(N):
        count = S[:i].count('W') + S[i+1:].count('E')
        if count < min_count:
            min_count = count

    print(min_count)

if __name__ == '__main__':
    main()


# Optimized solution
# coding: utf-8
    
def main():
    N = int(eval(input()))
    S = input()[:N]

    min_count = count = S[1:].count('E')
    for i in range(1, N):
        if S[i - 1] == 'W':
            count += 1
        if S[i] == 'E':
            count -= 1
            if count < min_count:
                min_count = count

    print(min_count)

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-

#----------
N = int(input().strip())
A_list = list(input().strip())
#----------

count = N
for i_leader in range(len(A_list)):
    ahead_list = A_list[:i_leader]
    behind_list = A_list[i_leader+1:]
    
    turn_W_to_E = len( [ i for i in ahead_list if i == "W"] )
    turn_E_to_W = len( [ i for i in behind_list if i == "E"] )
    turn_member = turn_W_to_E + turn_E_to_W
    
    if turn_member < count:
        count = turn_member

print(count)


# Optimized solution
# -*- coding: utf-8 -*-

#----------
N = int(input().strip())
A_list = list(input().strip())
#----------
W_member_sum_0_to_N = [0]*len(A_list)
E_member_sum_N_to_0 = [0]*len(A_list)

cnt=0
for i in range(len(A_list)):
    if A_list[i] == "W":
        cnt += 1
    W_member_sum_0_to_N[i] += cnt

cnt=0
for i in range(len(A_list)-1,-1,-1):
    if A_list[i] == "E":
        cnt += 1
    E_member_sum_N_to_0[i] += cnt
        

count = N
for i_leader in range(len(A_list)):
    if i_leader == 0:
        turn_member = E_member_sum_N_to_0[i_leader+1]
    elif i_leader == len(A_list)-1:
        turn_member = W_member_sum_0_to_N[i_leader-1]
    else:
        turn_member = W_member_sum_0_to_N[i_leader-1] + E_member_sum_N_to_0[i_leader+1]

    if turn_member < count:
        count = turn_member


print(count)
# Original solution
n = eval(input())
l = list(input())
ans = n

for i in range(0, n):
  tmp = l[:i].count("W") + l[i+1:].count("E")
  if tmp < ans:
    ans = tmp

print(ans)

# Optimized solution
n = eval(input())
l = list(input())
left = 0
right = l.count("E")
count = []

for i in range(0, n):
	if l[i] == "E":
		right -= 1

	count += [left + right]

	if l[i] == "W":
		left += 1

print(min(count))
# Original solution
N = int(eval(input()))
S = list(input().strip())

Is = [1 if s == 'W' else 0 for s in S]

res = N
for i in range(0,N):
 left = Is[:max(i - 1,0)]
 right = Is[min(i + 1,N - 1):]
 tmp = sum(left) + (len(right) - sum(right))
 res = min(tmp,res)

print(res)

# Optimized solution
N = int(eval(input()))
S = list(input().strip())

cnt = S[1:].count('E')

res = cnt
for i in range(1,N):
    if S[i] == 'E':
        cnt -= 1
    if S[i - 1] == "W":
        cnt += 1
    res = min(res,cnt)

print(res)
# Original solution
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    RS = S[::-1]
    S = 'x' + S
    RS = 'x' + RS
    slist = []
    rslist = []
    ss = 0
    rss = 0
    for i in range(N):
        if S[i] == 'W':
            ss += 1
        if RS[i] == 'E':
            rss += 1
        slist.append(ss)
        rslist.insert(0,rss)
    #print(S)
    #print(RS)
    #print(list( zip(slist, rslist)))
    print((min([s + r for s, r in zip(slist, rslist)])))

#
# main
#
# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

# Optimized solution
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    RS = S[::-1]
    S = 'x' + S
    RS = 'x' + RS
    slist = []
    rslist = []
    ss = 0
    rss = 0
    for i in range(N):
        if S[i] == 'W':
            ss += 1
        if RS[i] == 'E':
            rss += 1
        slist.append(ss)
        #rslist.insert(0,rss)
        rslist.append(rss)
    #print(S)
    #print(RS)
    #print(list( zip(slist, rslist)))
    rslist.reverse()
    print((min([s + r for s, r in zip(slist, rslist)])))

#
# main
#
# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)
# Original solution
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline()
    count = 0
    s1 = []
    for i, x in enumerate(S):
        if x == 'W':
            count += 1
        s1.append(count)
    count = 0
    s2 = []
    for i, x in enumerate(S[::-1]):
        if x == 'E':
            count += 1
        s2.append(count)
    s2.reverse()

    result = N
    for i in range(N):
        count = 0
        idx = i - 1
        if idx >= 0:
            count += s1[idx]
        idx = i + 1
        if idx < N:
            count += s2[idx]
        result = min(result, count)

    print(result)


if __name__ == '__main__':
    main()


# Optimized solution
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    spam1 = [0]
    for x in S[:-1]:
        spam1 += [spam1[-1] + 1 if x == 'W' else spam1[-1]]
    spam2 = [0]
    for x in S[::-1][:-1]:
        spam2 += [spam2[-1] + 1 if x == 'E' else spam2[-1]]
    spam2 = spam2[::-1]
    print((min([spam1[i] + spam2[i] for i in range(N)])))


if __name__ == '__main__':
    main()
# Original solution
from sys import stdin
import collections

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

people = []

for i in range(N):
    people.append(S[i])

tmp = collections.Counter(people[1:])
tmp2 = tmp['E']
tmp3 = collections.Counter(people[:N-1])
tmp4 = tmp['W']
minv = min(tmp2, tmp4)

for i in range(1, N-2):
    front = people[:i+1]
    tail = people[i+2:]
    tmp4 = collections.Counter(front)['W'] + collections.Counter(tail)['E']
    if tmp4 < minv:
        minv = tmp4

print(minv)


# Optimized solution
from sys import stdin
import collections

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

people = []

for i in range(N):
    people.append(S[i])

tmp = collections.Counter(people[1:])
num_return = tmp['E']
minv = num_return

for i in range(1, N):
    if people[i] == 'E':
        num_return -= 1
    if people[i-1] == 'W':
        num_return += 1
    if num_return < minv:
        minv = num_return

print(minv)
# Original solution
N = int(input())
S = str(input())
opt_cnt = N
for i in range(N):
    first = S[:i]
    second = S[i+1:]
    cnt = first.count('W') + second.count('E')
    if opt_cnt > cnt:
        opt_cnt = cnt
print(opt_cnt)


# Optimized solution
def opt(N, S):
    if N == 1:
        return 0
    else:
        split = int(N/2)
        return min(opt(split,S[:split])+S[split:].count('E'),S[:split].count('W')+opt(N - split,S[split:]))

Num = int(input())
Str = str(input())
print((opt(Num, Str)))
# Original solution
N = int(input())
S = input()

score_list = []
for i in range(N):
	E_num = S[i+1:].count('E')
	W_num = S[:i].count('W')
	score_list.append(E_num+W_num)

print(min(score_list))

# Optimized solution
N = int(input())
S = input()

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	if S[i+1]=='E':
		num-=1
	score_list.append(num)
	
print(min(score_list))
# Original solution
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    ans = pre
    for Si in S:
        if pre < ans:
            ans = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print((pre if pre < ans else ans))
    return


main()


# Optimized solution
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    cur = pre
    for Si in S:
        if pre < cur:
            cur = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print((pre if pre < cur else cur))
    return


main()
# Original solution
def 解():
    iN = int(eval(input()))
    sS = input().rstrip()

    aE= [0]*iN #東向かされる人
    aW= [0]*iN #西向かされる人
    for i in range(1,iN):
        if sS[i-1] == "W":
            aE[i] = aE[i-1]+1
        else:
            aE[i] = aE[i-1]
    iMinCost = aE[iN-1]
    for i in range(iN-2,-1,-1):
        if sS[i+1]=="E":
            aW[i] = aW[i+1]+1
        else:
            aW[i] = aW[i+1]
        iMinCost = min(iMinCost,aW[i]+aE[i])
    print(iMinCost)

解()


# Optimized solution
def 解():
    iN = int(eval(input()))
    sS = input().rstrip()

    aE= [0]*iN #東向かされる人
    for i in range(1,iN):
        if sS[i-1] == "W":
            aE[i] = aE[i-1]+1
        else:
            aE[i] = aE[i-1]
    iMinCost = aE[iN-1]
    iW = 0 #西向かされる人
    for i in range(iN-2,-1,-1):
        if sS[i+1]=="E":
            iW += 1
        iMinCost = min(iMinCost,iW+aE[i])
    print(iMinCost)

解()
# Original solution
#abc098c

n=int(input())
s=input()
res=float('inf')
for i in range(len(s)):
 s1=s[:i]
 s2=s[i+1:]
 res=min(s1.count('W')+s2.count('E'),res)
print(res)


# Optimized solution
#abc098c

n=int(input())
s=input()
cnt=s[1:].count('E')
res=cnt
for i in range(1,n):
 if s[i-1]=='W':
  cnt+=1
 if s[i]=='E':
  cnt-=1
 res=min(cnt,res)
print(res)
# Original solution
def solve():
    N = int(input())
    S = input() # str
    min_need_change = N
    for i in range(N):
        count = 0
        for j in range(0, i):
            if S[j] == 'W':
                count += 1
        for j in range(i+1, N):
            if S[j] == 'E':
                count += 1
        if count < min_need_change:
            min_need_change = count
    print(str(min_need_change))

if __name__ == '__main__':
    solve()


# Optimized solution
def solve():
    N = int(input())
    S = input() # str
    count = 0
    for i in range(1, N): # count for leader is the 1st person case
        if S[i] == 'E':
            count += 1
    min_need_change = count
    for i in range(1,N): # count for leader is the 2nd, ... (N + 1)th person cases
        if S[i] == 'E':
            count -= 1
        if S[i - 1] == 'W':
            count += 1
        if count < min_need_change:
            min_need_change = count
    print(str(min_need_change))

if __name__ == '__main__':
    solve()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())

# 適当に番兵を入れておく
INF = 10**12
L = [INF] # -1倍していれる
R = [INF]
SL = 0; SR = 0

def pushL(x):
    global SL
    heappush(L,-x)
    SL += x
def popL():
    global SL
    x = -heappop(L)
    SL -= x
    return x
def pushR(x):
    global SR
    heappush(R,x)
    SR += x
def popR():
    global SR
    x = heappop(R)
    SR -= x
    return x

add = 0 # 全体に共通に加わってるもの

answer = []
for q in query:
    if len(q) == 1:
        # 値を求める
        x = -L[0]
        f = SR - SL + x * (len(L)-len(R))
        answer.append('{} {}'.format(x,f+add))
        continue
    # 更新
    a,b = q[1:]
    add += b
    b = popL(); c = popR()
    a,b,c = sorted([a,b,c])
    pushL(a); pushR(c)
    if len(L) > len(R):
        pushR(b)
    else:
        pushL(b)

print(('\n'.join(answer)))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())

# 適当に番兵を入れておく
INF = 10**12
L = [INF] # -1倍していれる
R = [INF]
SL = 0; SR = 0

add = 0 # 全体に共通に加わってるもの

answer = []
for q in query:
    if len(q) == 1:
        # 値を求める
        x = -L[0]
        f = SR - SL + x * (len(L)-len(R))
        answer.append('{} {}'.format(x,f+add))
        continue
    # 更新
    a,b = q[1:]
    add += b
    
    b = -heappop(L); SL -= b
    c = heappop(R); SR -= c
    a,b,c = sorted([a,b,c])
    heappush(L,-a); SL += a
    heappush(R,c); SR += c
    if len(L) > len(R):
        heappush(R,b); SR += b
    else:
        heappush(L,-b); SL += b

print(('\n'.join(answer)))
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())

# 適当に番兵を入れておく
INF = 10**12
L = [INF] # -1倍していれる
R = [INF]
SL = 0; SR = 0

add = 0 # 全体に共通に加わってるもの

answer = []
for q in query:
    if len(q) == 1:
        # 値を求める
        x = -L[0]
        f = SR - SL + x * (len(L)-len(R))
        answer.append('{} {}'.format(x,f+add))
        continue
    # 更新
    a,b = q[1:]
    add += b
    
    b = -heappop(L); SL -= b
    c = heappop(R); SR -= c
    a,b,c = sorted([a,b,c])
    heappush(L,-a); SL += a
    heappush(R,c); SR += c
    if len(L) > len(R):
        heappush(R,b); SR += b
    else:
        heappush(L,-b); SL += b

print(('\n'.join(answer)))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

Q = int(readline())
query = (tuple(map(int,line.split())) for line in readlines())

# 適当に番兵を入れておく
INF = 10**12
L = [INF] # -1倍していれる
R = [INF]
sumL = 0; sumR = 0 # 和
lenL = 0; lenR = 0 # 長さ

add = 0 # 全体に共通に加わってるもの

answer = []
for q in query:
    if len(q) == 1:
        # 値を求める
        x = -L[0]
        f = sumR - sumL + x * (lenL - lenR)
        answer.append('{} {}'.format(x,f+add))
        continue
    # 更新
    a,b = q[1:]
    add += b
    
    b = -heappop(L); sumL -= b
    c = heappop(R); sumR -= c
    a,b,c = sorted([a,b,c])
    heappush(L,-a); sumL += a
    heappush(R,c); sumR += c
    if lenL > lenR:
        heappush(R,b); sumR += b; lenR += 1
    else:
        heappush(L,-b); sumL += b; lenL += 1

print(('\n'.join(answer)))
# Original solution
import bisect as bis
Q = int(eval(input()))
minval = 0
argminval = -(10**9)
L, R = [-(10**9)], [10**9]
lenL, lenR = 0, 0

def listupdate(items, new):
    ind = bis.bisect_left(items, new)
    ret = items[:ind]+[new]+items[ind:]
    return ret

for _ in range(Q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        ai, bi = qi[1], qi[2]
        LC, RC = L[-1], R[0]
        if lenL == lenR:
            if ai < RC:
                L = listupdate(L, ai)
            else:
                L = listupdate(L, RC)
                R = listupdate(R[1:], ai)
            lenL += 1
            argminval = L[-1]
            minval += abs(argminval - ai) + bi
        else:
            if ai < LC:
                L = listupdate(L[:-1], ai)
                R = listupdate(R, LC)
            else:
                R = listupdate(R, ai)
            lenR += 1
            minval += abs(argminval - ai) + bi
            argminval = L[-1]
    else:
        print(("{} {}".format(argminval, minval)))

# Optimized solution
import heapq as hq
Q = int(eval(input()))
minval = 0
argminval = -(10**9)
#aを大きい方と小さい方に分けて最小ヒープで管理(Lは最大が欲しいので-1掛けておく)
L, R = [10**9], [10**9]
lenL, lenR = 0, 0

for _ in range(Q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        ai, bi = qi[1], qi[2]
        LC, RC = -1*L[0], R[0] #左右それぞれで中央に一番近いもの
        if lenL == lenR:
            if ai < RC:
                #Lにaiを追加
                hq.heappush(L, -1*ai)
            else:
                #RCをLに移動, Rにaiを追加
                hq.heappop(R)
                hq.heappush(L, -1*RC)
                hq.heappush(R, ai)
            lenL += 1
            #新しいargminで最小値更新
            argminval = -1*L[0]
            minval += abs(argminval - ai) + bi
        else:
            if ai < LC:
                #LCをRに移動, Lにaiを追加
                hq.heappop(L)
                hq.heappush(L, -1*ai)
                hq.heappush(R, LC)
            else:
                #Rにaiを追加
                hq.heappush(R, ai)
            lenR += 1
            #古いargminで最小値更新
            minval += abs(argminval - ai) + bi
            argminval = -1*L[0]
    else:
        print(("{} {}".format(argminval, minval)))