Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0
index = 0
for i in range(N-K+1):
    if ans < sum(p[i:i+K]):
        ans = sum(p[i:i+K])
        index = i

print(kitaiti(ans)+0.5*(K-1))


Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

s=[0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + p[i]

for i in range(N-K+1):
    val = s[K+i] - s[i]
    if ans<val:
        ans = val

print(kitaiti(ans)+0.5*(K-1))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

k = [0]*N

"""
def kitaiti(n):
    sum = 0
    for i in range(1,n+1):
        sum += i
    return sum / n
""" 
def kitaiti(n):
    return 0.5*n + 0.5

ans = 0
index = 0
for i in range(N-K+1):
    if ans < sum(p[i:i+K]):
        ans = sum(p[i:i+K])
        index = i

ans = 0
for i in range(K):
    ans += kitaiti(p[index + i])
print(ans)


Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

s=[0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + p[i]

for i in range(N-K+1):
    val = s[K+i] - s[i]
    if ans<val:
        ans = val

print(kitaiti(ans)+0.5*(K-1))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

k = [0]*N

def kitaiti(n):
    sum = 0
    for i in range(1,n+1):
        sum += i
    return sum / n
"""    
for i in range(N):
    k[i] = kitaiti(p[i])
"""
ans = 0
index = 0
for i in range(N-K+1):
#    ans = max(ans,sum(p[i:i+K]))
    if ans < sum(p[i:i+K]):
        ans = sum(p[i:i+K])
        index = i

ans = 0
for i in range(K):
    ans += kitaiti(p[index + i])
print(ans)


Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

s=[0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + p[i]

for i in range(N-K+1):
    val = s[K+i] - s[i]
    if ans<val:
        ans = val

print(kitaiti(ans)+0.5*(K-1))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

k = [0]*N

def kitaiti(n):
    sum = 0
    for i in range(1,n+1):
        sum += i
    return sum / n
    
for i in range(N):
    k[i] = kitaiti(p[i])
ans = 0
for i in range(N-K+1):
    ans = max(ans,sum(k[i:i+K]))
print(ans)
    


Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

s=[0]*(N+1)
for i in range(N):
    s[i+1] = s[i] + p[i]

for i in range(N-K+1):
    val = s[K+i] - s[i]
    if ans<val:
        ans = val

print(kitaiti(ans)+0.5*(K-1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = [list(map(int,input().split())) for _ in range(N)]

cnt = 0
for i in l:
    x = 0 if i[0]-i[1] < 0 else i[0]-i[1]
    i[1] = i[0]+i[1]
    i[0] = x
    
l.sort(key=lambda x:x[1])

while l:
    cnt+=1
    x = l.pop(0)
    delete = []
    for i in range(len(l)):
        if x[1] > l[i][0]:
            delete.append(i)

    for i in range(len(delete)):
        l.pop(delete[i]-i)

print(cnt)

Fixed submission:
N = int(input())
l = [list(map(int,input().split())) for _ in range(N)]

ans = N
for i in l:
    x = 0 if i[0]-i[1] < 0 else i[0]-i[1]
    i[1] = i[0]+i[1]
    i[0] = x
    
l.sort(key=lambda x:x[1])

right = 0
for i in range(N):
    if right > l[i][0]:
        ans-=1
    else:
        right = l[i][1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

for i in range(K):
    if A > 0:
        A -= 1
    else:
        B -= 1

print(A, B)

Fixed submission:
A, B, K = map(int, input().split())
 
if A >= K:
    print(A-K,B)
elif A+B-K >= 0:
    print(0, A+B-K)
else:
    print("0 0")
Buggy python submission (verdict: Time Limit Exceeded):
num_list = [int(i) for i in input().split()]

result = 0

max = num_list[0] * num_list[1]
for i in range(1, max + 1):
    amari_1 = i % num_list[0]
    amari_2 = i % num_list[1]
    if amari_1 == 0 and amari_2 == 0:
        result = i
        break

print(result)


Fixed submission:
num_list = [int(i) for i in input().split()]

result = 0

if num_list[0] < num_list[1]:
    A = num_list[0]
    B = num_list[1]
else:
    A = num_list[1]
    B = num_list[0]

while True:
    amari = A % B
    if amari == 0:
        break
    A = B
    B = amari

#最大公約数 B

#最小公倍数
result =  num_list[0] * num_list[1] // B

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

l = prime_factorize(N)
ans = 10 ** 12
for i in range(2**len(l)):
    a = 1
    b = 1
    for j in range(len(l)):
        if (i>>j & 1):
            a *= l[j]
        else:
            b *= l[j]
    if ans > a - 1 + b - 1:
        ans = a - 1 + b - 1
    
print(ans)

Fixed submission:
N = int(input())

ans = 10**12 * 2
for i in range(1, int(N**0.5) + 1):
    if N % i == 0:
        distance = i + N//i - 2
        if ans > distance:
            ans = distance

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list = list(map(int,input().split()))

ans=""
for i in range(1,N+1):
    ans += " " + str(list.index(i)+1)
    
print(ans)

Fixed submission:
N = int(input())
list = list(map(int,input().split()))

dic={}
ans=""

for i in range(N):
    dic[list[i]]=i+1
    
for i in range(1, N+1):
    ans += " " + str(dic[i])
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
list = list(map(int, input().split()))

cnt = 0
sum = 0

while sum <= X:
    sum += list[cnt]
    cnt += 1

print(cnt)

Fixed submission:
N,X = map(int,input().split())
list = list(map(int, input().split()))

cnt = 1
sum = 0

for i in list:
    sum += i
    if sum <= X:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
N,Q = map(int, input().split())
S = input()
SUM = [0] * (N + 1)
L = [0]*Q
R = [0]*Q


for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Fixed submission:
N,Q = map(int, input().split())
S = input()
SUM = [0] * (N + 1)
L = [0]*Q
R = [0]*Q


for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Buggy python submission (verdict: Runtime Error):
N,Q = map(int, input().split())
S = input()
SUM = [0] * (N + 1)
L = [0]*Q
R = [0]*Q


for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]
print(SUM)
for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Fixed submission:
N,Q = map(int, input().split())
S = input()
SUM = [0] * (N + 1)
L = [0]*Q
R = [0]*Q


for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])
Buggy python submission (verdict: Runtime Error):
   N, K = map(int, (input().split()))
    h = list(map(int, input().split()))

    dp = [float("inf")] * len(h)
    dp[0] = 0

    for i in range(len(h)):
        for j in range(1, min(i + 1, K + 1)):
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i])

    print(dp[N - 1])

Fixed submission:
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])




Fixed submission:
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,K+1):
        if i - j >= 0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])


print(dp[N-1])


Fixed submission:
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0


for i in range(1, len(h)):
    for j in range(1,K+1):
        dp[i] = min(dp[i-j]+abs(h[i-1]-h[i-j-1]), dp[i])


print(dp[N-1])

Fixed submission:
N,K = map(int,(input().split()))
h = list(map(int,input().split()))

dp = [float("inf")]*len(h)
dp[0] = 0

for i in range(len(h)):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

if(N==1):
    if M==1:
       print(1)
    elif M==2:
        print(0)
    else:
        print(M-2)
elif(N==2):
    print(0)
else
    if M==1:
       print(1)
    elif M==2:
        print(0)
    else:
        print((N-2)*(M-2))

Fixed submission:
N,M = map(int,input().split())

if(N==1):
    if M==1:
       print(1)
    elif M==2:
        print(0)
    else:
        print(M-2)
elif(N==2):
    print(0)
else:
    if M==1:
       print(N-2)
    elif M==2:
        print(0)
    else:
        print((N-2)*(M-2))
Buggy python submission (verdict: Runtime Error):
m_Coin500 = int(input())
num_Coin100 = int(input())
num_Coin50 = int(input())
total = int(input())

count = 0

for i_Coin500 in range(num_Coin500 + 1):
    for i_Coin100 in range(num_Coin100 + 1):
        for i_Coin50 in range(num_Coin50 + 1):
            sum = 500*i_Coin500 + 100*i_Coin100 + 50*i_Coin50
            if total == sum:
                count += 1

print(count)

Fixed submission:
num_Coin500 = int(input())
num_Coin100 = int(input())
num_Coin50 = int(input())
total = int(input())

count = 0

for i_Coin500 in range(num_Coin500 + 1):
    for i_Coin100 in range(num_Coin100 + 1):
        for i_Coin50 in range(num_Coin50 + 1):
            sum = 500*i_Coin500 + 100*i_Coin100 + 50*i_Coin50
            if total == sum:
                count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
As = [int(n) for n in input().split()]

limit = 10**18

prod = 1
over = False
for A in As:
    prod *= A
    if prod == 0:
        print(0)
        sys.exit(0)
    if prod > limit:
        over = True

if over:
    print(-1)
else:
    print(prod)

Fixed submission:
import sys

N = int(input())

As = [int(n) for n in input().split()]
As_set = set(As)

limit = 10**18

prod = 1

if 0 in As_set:
    print(0)
    sys.exit(0)

over = False
for A in As:
    prod *= A
    if prod > limit:
        print(-1)
        sys.exit(0)

print(prod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
As = [int(n) for n in input().split()]

limit = 10**18

prod = 1
over = False
for A in As:
    prod *= A
    if prod == 0:
        print(0)
        sys.exit(0)
    if prod > limit:
        over = True

if over:
    print(-1)
else:
    print(prod)

Fixed submission:
import sys

N = int(input())

As = [int(n) for n in input().split()]
As_set = set(As)

limit = 10**18

prod = 1

if 0 in As_set:
    print(0)
    sys.exit(0)

over = False
for A in As:
    prod *= A
    if prod > limit:
        print(-1)
        sys.exit(0)

print(prod)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(input())
As = [int(n) for n in input().split()]

limit = 10**18
over = False

prod = 1
for A in As:
    prod *= A
    if prod > limit:
        over = True
    if prod == 0:
        print(0)
        sys.exit(0)

if over:
    print(-1)
    sys.exit(0)
else:
    print(prod)

Fixed submission:
import sys

N = int(input())

As = [int(n) for n in input().split()]
As_set = set(As)

limit = 10**18

prod = 1

if 0 in As_set:
    print(0)
    sys.exit(0)

over = False
for A in As:
    prod *= A
    if prod > limit:
        print(-1)
        sys.exit(0)

print(prod)
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
A = int(A)
B = int(B)*100 + int(B[-2:])

print(A*B // 100)

Fixed submission:
A, B = input().split()
A = int(A)
B = int(B[:-3])*100 + int(B[-2:])

print(A*B // 100)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B, N = [int(n) for n in input().split()]

max = 0
for x in range(N+1):
    val = A * ((x / B) % 1) - ((A*x/B) % 1)
    # val = math.floor(A*x/B) - A*math.floor(x/B)
    if val > max:
        max = val
print(int(max))

Fixed submission:
A, B, N = [int(n) for n in input().split()]

print(int(A*min(N,B-1)/B))

Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B, N = [int(n) for n in input().split()]

max = 0
for x in range(N+1):
    # val = A * ((x / B) % 1) - ((A*x/B) % 1)
    val = math.floor(A*x/B) - A*math.floor(x/B)
    if val > max:
        max = val
print(int(max))

Fixed submission:
A, B, N = [int(n) for n in input().split()]

print(int(A*min(N,B-1)/B))
Buggy python submission (verdict: Time Limit Exceeded):
import math

k = int(input())

total = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            total += math.gcd(math.gcd(a,b),c)

print(total)


Fixed submission:
import math

k = int(input())

total = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            abc = {a,b,c}
            div = 1
            if len(abc) == 2:
                div = 3
            elif len(abc) == 1:
                div = 1
            elif len(abc) == 3:
                div = 6
            #print(str(a) + " " + str(b) + " " + str(c))
            add = div * math.gcd(math.gcd(a,b),c)
            #print(len(abc))
            #print(div)
            #print(add)
            total += add

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

total = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            chars = set()
            chars.add(S[i])
            chars.add(S[j])
            chars.add(S[k])
            if len(chars) == 3:
                if j - i != k - j:
                    total += 1

print(total)


Fixed submission:
N = int(input())
S = input()

r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    if S[i] == 'G':
        g += 1
    if S[i] == 'B':
        b += 1

rgb_tot = r*g*b
#print(rgb_tot)

for i in range(N):
    first = S[i]
    for j in range(i,N):
        if 2*j - i < N:
            if first != S[j] and first != S[2*j-i] and S[j] != S[2*j-i]:
                #print("%d %d %d" % (i,j,2*j-i))
                #print(rgb_tot)
                rgb_tot -= 1

print(rgb_tot)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

total = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                if j - i != k - j:
                    total += 1

print(total)


Fixed submission:
N = int(input())
S = input()

r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    if S[i] == 'G':
        g += 1
    if S[i] == 'B':
        b += 1

rgb_tot = r*g*b
#print(rgb_tot)

for i in range(N):
    first = S[i]
    for j in range(i,N):
        if 2*j - i < N:
            if first != S[j] and first != S[2*j-i] and S[j] != S[2*j-i]:
                #print("%d %d %d" % (i,j,2*j-i))
                #print(rgb_tot)
                rgb_tot -= 1

print(rgb_tot)
Buggy python submission (verdict: Runtime Error):
in = input().split()

print('%s %s %s' % (in[2],in[0],in[1]))


Fixed submission:
x = input().split()

print('%s %s %s' % (x[2],x[0],x[1]))

Buggy python submission (verdict: Runtime Error):
in = input()

print('%s %s %s' % (in[2],in[0],in[1]))

Fixed submission:
x = input().split()

print('%s %s %s' % (x[2],x[0],x[1]))
Buggy python submission (verdict: Time Limit Exceeded):
list_input = [int(n) for n in input().split()]

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    N = abs(N - K)

print(N)


Fixed submission:
list_input = [int(n) for n in input().split()]

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    if N >= K:
        N = N % K
    else:
        N = K - N
print(N)
Buggy python submission (verdict: Runtime Error):
string = input()

if string[2] == string[3] and string[4] == string[5]:
  print 'Yes'
else:
  print 'No'

Fixed submission:
string = input()

if string[2] == string[3] and string[4] == string[5]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
circum_total = [int(n) for n in input().split()]

circum = circum_total[0]
total = circum_total[1]

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

def dist_from_node_forward(node_index, distances):
    forward_distances = distances[node_index:]
    forward_distances.extend([n + circum for n in distances[:node_index]])
    #print(forward_distances)
    dist = 0
    for index in range(1,len(forward_distances)):
        dist += forward_distances[index] - forward_distances[index-1]
    #print(dist)
    return(dist)

def dist_from_node_backward(node_index, distances):
    before = [distances[node_index]]
    before.extend(list(reversed(distances[:node_index])))
    before.append(0)
    #print(before)
    after = list(distances[node_index:])
    after.pop(0)
    #print(after)
    before.extend(list(reversed([n - circum for n in after])))
    #print(before)
    dist = 0
    for index in range(1,len(before)):
        dist += before[index-1] - before[index]
    #print(dist)
    return(dist)

def mindist(node_index, distances):
    return min(dist_from_node_forward(node_index,distances),dist_from_node_backward(node_index,distances))

minimum = circum

for i in range(len(distances)):
    minimum = min(minimum,mindist(i,distances))

print(minimum)


Fixed submission:
circum_total = [int(n) for n in input().split()]

circum = circum_total[0]
total = circum_total[1]

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

mindist = circum
for index in range(len(distances)):
    if index == len(distances) - 1:
        rightdist = distances[0] + circum - distances[index]
    else:
        rightdist = distances[index+1] - distances[index]
    if index == 0:
        leftdist = distances[index] - distances[index-1] + circum
    else:
        leftdist = distances[index] - distances[index-1]
    maxdist = max(rightdist,leftdist)
    mindist = min(mindist, circum - maxdist)

print(mindist)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = [int(n) for n in input().split()]

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

def waystochoose(k):
    total = 0
    for val in vals:
        if val == k:
            total += (vals[val] - 1)*(vals[val] - 2) // 2
        else:
            total += vals[val]*(vals[val]-1) // 2
    return total

checked = {}
for k in range(len(As)):
    if not As[k] in checked:
        ways = waystochoose(As[k])
        print(ways)
        checked[As[k]] = ways
    else:
        print(checked[As[k]])


Fixed submission:
N = int(input())
As = [int(n) for n in input().split()]

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

#print(vals)

choose2 = {}
for val in vals:
    num = vals[val]
    choose2[val] = num*(num - 1) // 2

#print(choose2)

total = 0
for k in choose2:
    total += choose2[k]
#print("total: " + str(total))

for Ak in As:
    print(total - (vals[Ak] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = [int(n) for n in input().split()]

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

for k in range(len(As)):
    Ak = As[k]
    total = 0
    for val in vals:
        if val == Ak:
            total += (vals[val] - 1)*(vals[val] - 2) // 2
        else:
            total += vals[val]*(vals[val]-1) // 2
    print(total)


Fixed submission:
N = int(input())
As = [int(n) for n in input().split()]

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

#print(vals)

choose2 = {}
for val in vals:
    num = vals[val]
    choose2[val] = num*(num - 1) // 2

#print(choose2)

total = 0
for k in choose2:
    total += choose2[k]
#print("total: " + str(total))

for Ak in As:
    print(total - (vals[Ak] - 1))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

q = deque(S)

for i in range(Q):
    T = input().split()
    if len(T) == 1:
        q.reverse()
    else:
        F = int(T[1])
        C = T[2]
        if F == 1:
            q.appendleft(C)
        else:
            q.append(C)

print(''.join(q))


Fixed submission:
from collections import deque

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

q = deque(S)

parity = 0
for i in range(Q):
    T = input().split()
    if len(T) == 1:
        parity = (parity + 1) % 2
        #q.reverse()
    else:
        F = int(T[1])
        C = T[2]

        if parity == 0:
            if F == 1:
                q.appendleft(C)
            else:
                q.append(C)
        else:
            if F == 1:
                q.append(C)
            else:
                q.appendleft(C)

if parity == 1:
    q.reverse()

print(''.join(q))