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

import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

ans = 0
for k in dic:
  if dic[k] >= 2:
    ans += C(dic[k], 2)

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  if tmp == 2:
    print(ans - 1)
  if tmp > 2:
    print(ans - (C(tmp, 2) - C(tmp-1, 2)))

### FIXED CODE ###

import math

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = tmp * (tmp - 1) // 2
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)
### BUGGY CODE ###

K,S = map(int,input().split())
g = 0
for x in range(0,K+1):
    for y in range(x,K+1):
        for z in range(y,K+1):
            if x+y+z == S:
                if x == y == z:g += 1
                elif x == y or y == z:g += 3
                else:g += 6
print(g)

### FIXED CODE ###

K,S = map(int,input().split())
t = 0
#c = 0
for x in range(max(0,S-2*K),min(S//3+1,K+1)):
    if S-x > 2 * K:
        pass
    else:
        for y in range(max(x,S-x-K),min((S-x)//2+1,K+1)):
            #c += 1
            z = S - x - y
            if z < y:
                #print('pass')
                pass
            else:
                #print(x,y,z)
                if x == y == z:
                    t += 1
                elif x == y or y == z:
                    t += 3
                else:
                    t += 6
print(t)
### BUGGY CODE ###

import numpy as np

def convert(L):
    dp = np.zeros((L.shape[0],L.shape[1]), dtype='int')
    for i in range(L.shape[0]):
        l=L[i]
        for j in range(L.shape[1]):
            if l[j]:
                if j == 0:
                    dp[i][j] = 1
                else:
                    dp[i][j] = dp[i][j-1] + 1
            else:
                dp[i][j] = 0
    return dp
H,W=map(int,input().split())
L= np.zeros((H,W),dtype='bool')
for i in range(H):
    L[i]=list(map(lambda x: False if x=="#" else True,list(input()) ))

ans = convert(L) + np.fliplr(convert(np.fliplr(L))) + convert(L.T).T + np.flipud(convert(np.flipud(L).T).T) - 3
print(np.max(ans))

### FIXED CODE ###

import numpy as np

H,W = map(int,input().split())
temp = np.array([list(input()) for _ in range(H)])
# 周りに壁を、0,1化
map = np.zeros((H+2,W+2),dtype=np.int32)
map[1:-1,1:-1][temp == '.'] = 1

# x軸正方向の集計
def F():
  x = map.copy()
  for row in range(1,H+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形
  x = x.cumsum(axis = 1)
  return x

# y軸
def G():
  x = map.T.copy()
  for row in range(1,W+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) # cumsumで求められるように変形
  x = x.cumsum(axis = 1)
  return x.T

answer = np.zeros_like(map)
# x軸
answer += F()
# 逆順
map = map[:,::-1]
answer += F()[:,::-1]
map = map[:,::-1]

# y軸
answer += G()
# 逆順
map = map[::-1,:]
answer += G()[::-1,:]

answer = np.max(answer) - 3
print(answer)
### BUGGY CODE ###

N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
xset=set([x[0] for x in P])
yset=set([x[1] for x in P])

minA=float('inf')
for l in xset:
    for r in xset:
        if r<=l:continue
        for d in yset:
            for u in yset:
                if u<=d:continue
                area=(r-l)*(u-d)
                if area>=minA:continue
                if len([p for p in P if l<=p[0]<=r and d<=p[1]<=u])==K:
                    area=(r-l)*(u-d)
                    minA=area
print(minA)

### FIXED CODE ###

N,K=map(int,input().split())
P= [list(map(int, input().split())) for i in range(N)]
P=sorted(P)
pi=list(enumerate(P))
minA=float("inf")
for il,xyl in pi[:N-1]:
    left=xyl[0]
    for ir,xyr in pi[il+1:]:
        right=xyr[0]
        insd=[xy_ for i,xy_ in pi if xyl[0]<=xy_[0]<=xyr[0]]
        insd=sorted(insd,key=lambda xx:xx[1])
        in_L=len(insd)
        if in_L<K:continue
        for jd in range(in_L-K+1):
            ju=jd+K-1
            down=insd[jd][1]
            upper=insd[ju][1]
            minA=min(minA,(upper-down)*(right-left))

print(minA)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
q = int(input())

for i in range(q):
    b,c = list(map(int,input().split()))
    if a.count(b) != 0:
        for j in range(n):
            if a[j] == b:
                a[j] = c
    print(sum(a))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
q = int(input())
count = 0
s = sum(a)

L = [0] * (10**5+1)
for aa in a:
    L[aa] += 1
for _ in range(q):
    b, c = list(map(int, input().split()))
    L[c] += L[b]
    s += L[b] * (c-b)
    L[b] = 0
    print(s)
### BUGGY CODE ###

N=int(input())
# https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9
print(0,flush=True)
s=str(input())
temp=s
tempway='right'
l=0
def is_ok():
    if temp==s and (mid-l)%2==1:
        if tempway=='right':
            return True
        else: return False
    elif temp!=s and (mid-l)%2==0:
        if tempway=='right':
            return False
        else: return True
    else:
        exit()


def bin_search_meguru():
    """
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng, okは,とり得る最小の値-1,とり得る最大の値+1
    """
    global ng
    global ok
    global mid
    global tempway

    # 適当にいじる
    ng = -1  # ind=0が条件を満たすこともあるため
    ok = N  # ind=len(a)-1が条件を満たさないこともあるため

    # いじらない
    # okとngのどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        print(mid,flush=True)
        s=str(input())
        if is_ok():
            ok = mid
            tempway='left'
        else:
            ng = mid
            l=mid
            tempway='right'
bin_search_meguru()

### FIXED CODE ###

N = int(input())


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        exit()
    return s


root = query(0)


def is_ok(ind):
    # 左ならTrue
    response = query(ind)
    if ind % 2 == 1:
        return root == response
    else:
        return root != response


def bin_search_meguru():
    """
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng, okは,とり得る最小の値-1,とり得る最大の値+1
    """

    # 適当にいじる
    ng = -1  # ind=0が条件を満たすこともあるため
    ok = N  # ind=len(a)-1が条件を満たさないこともあるため

    # いじらない
    # okとngのどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return False


bin_search_meguru()
### BUGGY CODE ###

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

from itertools import accumulate
l=[0]+list(accumulate(a))
s=l[-1]
ans=10000000000000
import bisect
for i in range(2,N-1):
    ll=l[0:i+1]
    lr=l[i:N+1]
    lls=ll[-1]
    lrs=lr[-1]-lr[0]
    n=bisect.bisect_left(ll,lls//2)
    if n+1>=len(ll):
        n=len(ll)-2
    elif n+1<0:
        n=1
    if min(abs(lls-ll[n]*2),abs(lls-ll[n-1]*2),abs(lls-ll[n+1]*2))==abs(lls-ll[n]*2):
        s=ll[n]
        t=lls-ll[n]
    elif min(abs(lls-ll[n]*2),abs(lls-ll[n-1]*2),abs(lls-ll[n+1]*2))==abs(lls-ll[n-1]*2):
        s=ll[n-1]
        t=lls-ll[n-1]
    else:
        s=ll[n+1]
        t=lls-ll[n+1]
        
    
        
    n=bisect.bisect_left(lr,lr[0]+lrs//2)
    if n+1>=len(lr):
        n=len(lr)-2
    elif n-1<0:
        n=1
    if min(abs(lrs-lr[n]*2+2*lr[0]),abs(lrs-lr[n-1]*2+2*lr[0]),abs(lrs-lr[n+1]*2+2*lr[0]))==abs(lrs-lr[n]*2+2*lr[0]):
        u=lr[n]-lr[0]
        v=lrs-lr[n]+lr[0]
    elif min(abs(lrs-lr[n]*2+2*lr[0]),abs(lrs-lr[n-1]*2+2*lr[0]),abs(lrs-lr[n+1]*2+2*lr[0]))==abs(lrs-lr[n-1]*2+2*lr[0]):
        u=lr[n-1]-lr[0]
        v=lrs-lr[n-1]+lr[0]
    else:
        u=lr[n+1]-lr[0]
        v=lrs-lr[n+1]+lr[0]
    

    ans=min(ans,max(s,t,u,v)-min(s,t,u,v))

print(ans)
    
    







### FIXED CODE ###

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

for i in range(n-1):
    a[i+1]+=a[i]

j=0
k=2
ans=10**9

for i in range(1,n-1):
    while abs(a[j]*2-a[i])>abs(a[j+1]*2-a[i]):
        j+=1
    while abs(a[k]*2-a[i]-a[n-1])>abs(a[k+1]*2-a[i]-a[n-1]):
        k+=1
    t=[a[j],a[i]-a[j],a[k]-a[i],a[n-1]-a[k]]
    ans=min(ans,max(t)-min(t))
print(ans)
### BUGGY CODE ###

def main():
    n, frnd, blck = map(int, input().split())
    blst = [set() for i in range(n)]
    flst = [set() for i in range(n)]
    alst = [set() for i in range(n)]
    for _ in range(frnd):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        flst[a].add(b)
        flst[b].add(a)
        alst[a] = alst[a] | alst[b] | flst[a] | flst[b]
        alst[b] = alst[a] | alst[b] | flst[a] | flst[b]
        for v in alst[a]:
            alst[v] = alst[v] | alst[b]
    for _ in range(blck):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        blst[c].add(d)
        blst[d].add(c)
    for i in range(n):
        if i in alst[i]:
            alst[i].remove(i)
        for v in flst[i]:
            if v in alst[i]:
                alst[i].remove(v)
        for v in blst[i]:
            if v in alst[i]:
                alst[i].remove(v)
    for i in range(n):
        print(len(alst[i]), end="")
        if i < n:
            print(" ", end="")

if __name__ == "__main__":
    main()

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n, frnd, blck = map(int, input().split())
    blst = [set() for i in range(n)]
    flst = [set() for i in range(n)]
    uf = UnionFind(n)
    for _ in range(frnd):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        flst[a].add(b)
        flst[b].add(a)
        uf.union(a, b)
    for _ in range(blck):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        blst[c].add(d)
        blst[d].add(c)
    for i in range(n):
        ans = uf.size(i) - len(flst[i]) - 1
        for v in blst[i]:
            if uf.same(i, v):
                ans -= 1
        print(ans, end="")
        if i < n:
            print(" ", end="")

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

from collections import defaultdict
n, k = list(map(int, input().split()))
li = list(map(int, input().split()))

s = set(li)
ns = [li.count(i) for i in s]
ns.sort()

if len(ns) <= k:
    print(0)
else:
    print(sum(ns[:-k]))


### FIXED CODE ###

n, k = list(map(int, input().split()))
li = list(map(int, input().split()))
li.sort()

ar = []
tmp = -1
for a in li:
    if a != tmp:
        tmp = a
        ar.append(1)
    else:
        ar[-1] += 1
ar.sort()

if len(ar) <= k:
    print(0)
else:
    print(sum(ar[:-k]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = []
            for i in range(1, K+1):
                if n-i >= 0:
                    work.append(rec(n-i)+abs(h[n-i]-h[n]))
            dp[n] = min(work)
    return dp[n]
rec(N-1)
print(dp[N-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N,dtype=int)
for i in range(1, N):
    s=max(0, i-K)
    dp[i] = min(dp[s:i]+abs(h[s:i]-h[i]))
print(dp[-1])
### BUGGY CODE ###


n = int(input())
r = ['0']
for i in range(n):
    k = 0
    tmp = input()
    for j in range(len(r)):
        if(tmp == r[j]):
            k += 1
            break;
    
    if(k == 0):
        r.append(tmp)
        

print(len(r)-1)

### FIXED CODE ###


n = int(input())
str = [input() for i in range(n)]
str.sort()
k = 1
for i in range(n-1):
    if(str[i] != str[i + 1]):
        k += 1




print(k)
### BUGGY CODE ###

N,M = map(int,input().split())
X = {}
for i in map(int,input().split()):
    if i in X.keys():
        X[i] += 1
    else:
        X[i] = 1
for _ in range(M):
    b,c = map(int,input().split())
    if c in X.keys():
        X[c] += b
    else:
        X[c] = b

K = sorted(list(X.keys()),reverse=True)
res = 0
for k in K:
    if N >= X[k]:
        res += k*X[k]
        N -= X[k]
    else:
        res += k*N
        break

print(res)

### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(M)]
A.sort()
X.sort(key=lambda x:-x[1])

j = 0
for i in range(N):
    if X[j][1] < A[i]:
        break
    else:
        X[j][0] -= 1
        A[i] = X[j][1]
    if X[j][0] == 0:
        j += 1
    if j == M:
        break

print(sum(A))
### BUGGY CODE ###

from collections import Counter

N, *A = map(int, open(0).read().split())

ctr = Counter(A)
memo = set()
ans = 0

for a in sorted(A):
    if a == 1:
        if ctr[a] == 1:
            ans = 1
        break

    for i in range(1, int(a ** 0.5) + 1):
        if a % i == 0:
            if (i in memo) or (a // i in memo):
                break
    else:
        if ctr[a] == 1:
            ans += 1

    memo.add(a)
        
print(ans)


### FIXED CODE ###

from collections import Counter

N, *A = map(int, open(0).read().split())

m = max(A) + 1
ok = [True] * m
ctr = Counter(A)
ans = 0
for a in sorted(A):
    if ok[a] and ctr[a] == 1:
        ans += 1
        
    for j in range(2 * a, m, a):
        ok[j] = False
            
print(ans)
### BUGGY CODE ###

import numpy  as np
N,M=map(int,input().split())
high_list=list(map(int,input().split()))
pathlist=[]
for i in range(M):
    pathlist.append(list(map(int,input().split())))
waylist=np.array([[0]*N]*N)
#i行目にi番目から行ける展望台をすべて入れる
for n in range(1,N+1):
    for m in pathlist:
        if(n in m):#もし経路に入っていたら
            if(m[0]==n):#自身じゃない方の高さを代入
                waylist[n-1][m[1]-1]=high_list[m[1]-1]
            else:
                waylist[n-1][m[0]-1]=high_list[m[0]-1]

answer=0
for n in range(N):
    if(waylist[n].max()<high_list[n]):
        answer=answer+1

print(answer)




### FIXED CODE ###

N,M=map(int,input().split())
high_list=list(map(int,input().split()))
highest=[True]*N
for i in range(M):
    a,b=map(int,input().split())
    if(high_list[a-1]>=high_list[b-1]):
        highest[b-1]=False
    if(high_list[a-1]<=high_list[b-1]):
        highest[a-1]=False
print(sum(highest))
### BUGGY CODE ###

import heapq as h
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
hen=[[] for i in range(0,N)]
for i in range(0,M):
    u,v=map(int,input().split())
    hen[u-1].append(v-1)

S,T=map(int,input().split())

ans=[-1 for i in range(0,N)]
ans[S-1]=0

q=[]
q.append(S-1)
h.heapify(q)
sub=[]
h.heapify(sub)
count=0
flag=1
while flag==1:
    flag=0
    while q!=[]:
        x=h.heappop(q)
        for p in hen[x]:
                h.heappush(sub,p)
        if q==[]:
            count+=1
            if count%3==0:
                for j in sub:
                    if ans[j]==-1:
                        ans[j]=count//3
                        flag=1
            else:
                flag=1
            q=sub
            sub=[]
            h.heapify(sub)
            break

print(ans[T-1])


### FIXED CODE ###

import heapq as h

N,M=map(int,input().split())
hen={(i,j):[] for i in range(0,N) for j in range(0,3)}
for i in range(0,M):
    u,v=map(int,input().split())
    hen[(u-1,0)].append((v-1,1))
    hen[(u-1,1)].append((v-1,2))
    hen[(u-1,2)].append((v-1,0))

S,T=map(int,input().split())

start=(S-1,0)
goal=(T-1,0)

distance={(i,j):-1 for i in range(0,N) for j in range(0,3)}

q=[]
q.append(start)
distance[start]=0
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in hen[x]:
            if distance[p]==-1:
                h.heappush(sub,p)
                distance[p]=distance[x]+1
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

if distance[goal]==-1:
    print(-1)
else:
    print(distance[goal]//3)
### BUGGY CODE ###

def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return result

n=int(input())
l1=list(map(int,input().split()))
m=int(input())
l2=list(map(int,input().split()))

x=list_difference(l2,l1)


if x==[]: print('YES')
else: print('NO')

### FIXED CODE ###

from collections import Counter

n = int(input())
l1 = list(map(int,input().split()))
l1_cnt = Counter(l1) 

m = int(input())
l2 = list(map(int,input().split()))
l2_cnt = Counter(l2) 
l2_set=set(l2)

for i in l2_set:
    if l2_cnt[i]<=l1_cnt[i]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')
### BUGGY CODE ###

# N分木におけるxの親は、0-indexedのときに、(x - 1) // N
# 一度0-indexedに戻すため、最初に-1したうえで、(x - 1) // Nを繰り返す
# 初めて一致した点が(0-indexedにおける)答えなので、+1して答え

import sys
readline = sys.stdin.readline

import numpy as np
from numba import jit

N,Q = map(int,readline().split())
P = [tuple(map(int,readline().split())) for i in range(Q)]
P = np.array(P,dtype = int)

@jit('i8(i8,i8[:])')
def solve(N,P):
  ans = np.zeros(len(P), dtype = int)
  for i in range(len(P)):
    v = P[i][0] - 1
    w = P[i][1] - 1
    while v != w:
      if v > w:
        v = (v - 1) // N
      else:
        w = (w - 1) // N
    ans[i] = v + 1
  return ans

ans = solve(N,P)
for a in ans:
  print(a)


### FIXED CODE ###

# N分木におけるxの親は、0-indexedのときに、(x - 1) // N
# 一度0-indexedに戻すため、最初に-1したうえで、(x - 1) // Nを繰り返す
# 初めて一致した点が(0-indexedにおける)答えなので、+1して答え

import sys
readline = sys.stdin.readline

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

for i in range(Q):
  v,w = map(int,readline().split())
  if N == 1:
    print(min(v,w))
    continue
  v -= 1
  w -= 1
  while v != w:
    if v > w:
      v = (v - 1) // N
    else:
      w = (w - 1) // N
  print(v + 1)
### BUGGY CODE ###

n,m = map(int, input().split())
Y = [[] for _ in range(n)]
L = []
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append(yi)
    L.append(yi)
for i in range(n):
    Y[i].sort()
    for k in range(len(Y[i])):
        L[L.index(Y[i][k])] = str(i+1).rjust(6,"0") + str(k+1).rjust(6,"0")
for j in range(len(L)): print(L[j])


### FIXED CODE ###

n,m = map(int, input().split())
Y = [[] for _ in range(n)]
for i in range(m):
    p,yi = map(int, input().split())
    Y[p-1].append((yi,i))
ans = [-1 for _ in range(m)]
for i,d in enumerate(Y):
    d.sort()
    for k,(a,b) in enumerate(d):
        ans[b] = str(i+1).rjust(6,"0") + str(k+1).rjust(6,"0")
print(*ans, sep = "\n")
### BUGGY CODE ###

# -*- coding: utf-8 -*-


k, s = map(int, input().split())

ans = 0

if s == 3*k:
    ans = 1
elif s > 3*k:
    ans = 0
elif s == k:
    ans = int((k + 1) * (k + 2) / 2)
else:
    l = k
    
    while l >= 0:
        t_sum = s - l
        m = s - t_sum
        
        if t_sum > 2*k:
            break
        
        if m < k:
            m = k
            
        while m >= 0:
            n = s - l - m
            
            if n > k or l + m + n < s:
                break
            
            while n >= 0:
                if l + m + n == s:
                    ans += 1
                if l + m + n < s:
                    break

                n -=1
            m -= 1
        l -= 1

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Aug  3 13:34:09 2020

@author: ito
"""


# -*- coding: utf-8 -*-

k, s = map(int, input().split())

ans = 0

for x in range(k+1):
    for y in range(k+1):
        
        sat_z = s - x - y
        
        if sat_z >= 0 and sat_z <= k:
            ans += 1
            
print(ans)
### BUGGY CODE ###

a = list(input())
res = ''
for i in a:
  if i == '?':
    res += 'D'
  else:
    res += i
    
print(res)


### FIXED CODE ###

a = input()
a = a.replace('?', 'D')
print(a)
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())
    reverse = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            reverse = not(reverse)
        else:
            if query[1] == "1":
                if reverse:
                    s = "".join([s, query[2]])
                else:
                    s = "".join([query[2], s])
            else:
                if reverse:
                    s = "".join([query[2], s])
                else:
                    s = "".join([s, query[2]])
    if reverse:
        print(s[::-1])
    else:
        print(s)
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    reverse = 0
    head = ""
    tail = ""
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            reverse = not(reverse)
        else:
            if (reverse^int(query[1]))&1:
                head += query[2]
            else:
                tail += query[2]
    s = head[::-1] + s + tail
    if reverse&1:
        print(s[::-1])
    else:
        print(s)
if __name__ == "__main__":
    main()