Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

past = []
offset = 0
cnt = 0
idx = 0
fl = False
for i in range(k):
  if fl:
    break
  past.append(now)
  now = a[now]
  try:
    idx = past.index(now)
    cnt = i-idx+1
    fl = True
    break
  except:
    pass

now = 0
for i in range(k % cnt):
  now = a[now]

print(offset + now+1)

Fixed submission:
n,k=map(int,input().split())

now = 0
a=list(map(int,input().split()))

s = []
od = [-1]*(n+1)
c=1
l=0

v=1

while od[v] == -1:
  od[v] = len(s)
  s.append(v)
  v = a[v-1]

c=len(s)-od[v]
l=od[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

past = []
offset = 0
cnt = 0
idx = 0
for i in range(k):
    past.append(now)
    now = a[now]
    try:
      idx = past.index(now)
      cnt = i-idx+1
      break
    except:
      pass

now = 0
for i in range(k % cnt):
  now = a[now]

print(offset + now+1)

Fixed submission:
n,k=map(int,input().split())

now = 0
a=list(map(int,input().split()))

s = []
od = [-1]*(n+1)
c=1
l=0

v=1

while od[v] == -1:
  od[v] = len(s)
  s.append(v)
  v = a[v-1]

c=len(s)-od[v]
l=od[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

cnt = 0
for i in range(k):
    now = a[now]
    if now == 0:
      cnt = i+1
      break
  
now = 0
for i in range(k % cnt):
  now = a[now]

print(now+1)

Fixed submission:
n,k=map(int,input().split())

now = 0
a=list(map(int,input().split()))

s = []
od = [-1]*(n+1)
c=1
l=0

v=1

while od[v] == -1:
  od[v] = len(s)
  s.append(v)
  v = a[v-1]

c=len(s)-od[v]
l=od[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0
for i in range(n):
  for j in range(i,n):
    if abs(j-i) == a[i]+a[j]:
      ans+=1

print(ans)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=nl()

ans=0

nums = dict()

for i in range(n):
  num_i = i+a[i]
  if num_i not in nums:
    nums[num_i]=0
  nums[num_i]+=1

for j in range(n):
  num_j = j-a[j]
  if num_j in nums:
    ans+=nums[num_j]

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,q = map(int,input().split())

a=[]
b=[]
c=[]
d=[]

max_= 0

def dfs(A):
  global max_
  ans = 0
  last = A[-1]
  if len(A) == n+1:
    for i in range(n):
      if A[b[i]]-A[a[i]] == c[i]:
        ans += d[i]
    max_ = max(max_, ans)
    return
  for i in range(last, m+1):
    dfs(A+[i])  


for i in range(q):
  aa,bb,cc,dd = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc)
  d.append(dd)
  
dfs([1])

print(max_)





Fixed submission:
n,m,q = map(int,input().split())

a=[]
b=[]
c=[]
d=[]

max_= 0

def dfs(A):
  global max_
  ans = 0
  last = A[-1]
  if len(A) == n+1:
    for i in range(q):
      if A[b[i]]-A[a[i]] == c[i]:
        ans += d[i]
    max_ = max(max_, ans)
    return
  for i in range(last, m+1):
    dfs(A+[i])  


for i in range(q):
  aa,bb,cc,dd = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc)
  d.append(dd)
  
dfs([1])

print(max_)

Buggy python submission (verdict: Runtime Error):
n,m,q = map(int,input().split())

a=[]
b=[]
c=[]
d=[]

max_= 0

def dfs(A):
  global max_
  ans = 0
  last = A[-1]
  if len(A) == n+1:
    for i in range(n):
      if A[b[i]]-A[a[i]] == c[i]:
        ans += d[i]
    max_ = max(max_, ans)
    return
  for i in range(last, m+1):
    dfs(A+[i])  


for i in range(q):
  aa,bb,cc,dd = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc)
  d.append(dd)
  
dfs([1])

print(max_)





Fixed submission:
n,m,q = map(int,input().split())

a=[]
b=[]
c=[]
d=[]

max_= 0

def dfs(A):
  global max_
  ans = 0
  last = A[-1]
  if len(A) == n+1:
    for i in range(q):
      if A[b[i]]-A[a[i]] == c[i]:
        ans += d[i]
    max_ = max(max_, ans)
    return
  for i in range(last, m+1):
    dfs(A+[i])  


for i in range(q):
  aa,bb,cc,dd = map(int, input().split())
  a.append(aa)
  b.append(bb)
  c.append(cc)
  d.append(dd)
  
dfs([1])

print(max_)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = input()

cnt=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if j-i == k-j:
        continue
      if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
        cnt+=1

print(cnt)


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = input()

rs=0
gs=0
bs=0

for i in range(n):
  if s[i]=='R':
    rs+=1
  elif s[i]=='G':
    gs+=1
  else:
    bs+=1

total = rs*gs*bs

for i in range(n):
  for j in range(i+1,n):
    k=j+j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        total-=1

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

LIMIT = 12
luns = []


def make_lunlun(l):
    if len(l) == LIMIT:
        return
    luns.append(int(''.join(list(map(str,l)))))

    if l[-1]!=0:
        make_lunlun(l+[(l[-1]-1)%10])
    make_lunlun(l+[(l[-1])%10])
    if l[-1]!=9:
        make_lunlun(l+[(l[-1]+1)%10])


for i in range(1,10):
    make_lunlun([i])

print(sorted(luns)[k-1])

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

luns = []


def make_lunlun(l):
    if l > 3234566667:
        return
    luns.append(l)

    last = l-l//10*10

    if last!=0:
        make_lunlun(l*10 + last-1)
    make_lunlun(l*10+last)
    if last!=9:
        make_lunlun(l*10 + last+1)


for i in range(1,10):
    make_lunlun(i)

print(sorted(luns)[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

def is_lunlun(n):
  nn = [int(_) for _ in str(n)]

  last = 0
  for i in range(len(nn)):
    if i > 0:
      if abs(nn[i] - last) > 1:
        return False
    last = nn[i]
  return True

cnt = 0

for i in range(1,10**10):
  if(is_lunlun(i)):
    if cnt == k-1:
      print(i)
      exit()
    cnt+=1

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

luns = []


def make_lunlun(l):
    if l > 3234566667:
        return
    luns.append(l)

    last = l-l//10*10

    if last!=0:
        make_lunlun(l*10 + last-1)
    make_lunlun(l*10+last)
    if last!=9:
        make_lunlun(l*10 + last+1)


for i in range(1,10):
    make_lunlun(i)

print(sorted(luns)[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

ni = lambda: int(input())
nm = lambda: map(int, input().split())
# nl = lambda: list(map(int, input().split()))

n,x,y=nm()

class Node:
  def __init__(self,x):
    self.val = x
    self.left=[]
    self.right=[]

nodes = [Node(i) for i in range(n)]
for i in range(n-1):
  nodes[i].right.append(nodes[i+1])
  nodes[i+1].left.append(nodes[i])

nodes[x-1].right.append(nodes[y-1])
nodes[y-1].left.append(nodes[x-1])

gl_dist = [0]*n


for i in range(n):
  dist = [-1]*n
  dist[i]=0
  q = deque()
  q.append(nodes[i])
  while len(q) > 0:
    node = q.popleft()
    nv = node.val
    nl = node.left
    nr = node.right

    for nli in nl:
      if dist[nli.val] == -1:
        dist[nli.val] = dist[nv]+1
        q.append(nli)
    for nri in nr:
      if dist[nri.val] == -1:
        dist[nri.val] = dist[nv]+1
        q.append(nri)

  for j in range(i+1,n):
    # print("{} to {} is {}".format(i,j,dist[j]))
    if dist[j] != -1:
      gl_dist[dist[j]]+=1

for i in range(1,n):
  print(gl_dist[i])
# print(gl_dist)


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,x,y = nm()

dist = [0]*n

for i in range(1,n+1):
  for j in range(i+1,n+1):
    naive = j-i
    cand = naive
    if i<x:
      if x<=j<=y:
        cand = x-i+1+y-j
      elif j>y:
        cand = x-i+1+j-y
    elif x<=i<=y:
      if j<=y:
        cand = i-x+1+y-j
      else:
        cand = i-x+1+j-y
    d = min(naive,cand)
    dist[d]+=1

for i in range(1,n):
  print(dist[i])
Buggy python submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(float, input().split())
if (a+b+2*sqrt(a*b)-c)**100<1>>40:
  print('Yes')
else:
  print('No')


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(int, input().split())
if 4*a*b<(c-a-b)**2 and (c-a-b)>=0:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=float(input())

if sqrt(a)+sqrt(b)<sqrt(c):
  print('Yes')
else:
  print('No')


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(int, input().split())
if 4*a*b<(c-a-b)**2 and (c-a-b)>=0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))

for i in range(n-k+1):
  mx = max(sum(pp[i:i+k]),mx)
print(mx)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))
pd = [0]*(n+1)



for i in range(1,n+1):
  pd[i] = pd[i-1] + pp[i-1]




for i in range(n-k+1):
  mx = max(pd[i+k]-pd[i],mx)

print(mx)

Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

for i in range(n-k+1):
  mx = max(sum(map(exp,p[i:i+k])),mx)
print(mx)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))
pd = [0]*(n+1)



for i in range(1,n+1):
  pd[i] = pd[i-1] + pp[i-1]




for i in range(n-k+1):
  mx = max(pd[i+k]-pd[i],mx)

print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

INF = 10**10

h,n = nm()

dp = [INF] * (h+1)

dp[0] = 0

for i in range(n):
  a,b = nm()

  for j in range(h):
    nj = min(j+a,h) 
    dp[nj]=min(dp[nj],dp[j]+b) # ダメージがj+aの時のコスト

print(dp[h])


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

INF = 10**10

h,n = nm()

dp = [INF] * (h+1)

dp[0] = 0

for i in range(n):
  a,b = nm()

  for j in range(h):
    nj = min(j+a,h) 
    dp[nj]=min(dp[nj],dp[j]+b) # ダメージがj+aの時のコスト

print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())

for i in range(k):
  if(a>0):
    a-=1
    continue
  if(b>0):
    b-=1
    continue

print("{0} {1}".format(a,b))

Fixed submission:
a,b,k = map(int, input().split())

if(a<k):
  k -= a
  a = 0
else:
  tmp = k
  k=0
  a -= tmp
  
if(b<k):
  b = 0
else:
  b -= k

print("{0} {1}".format(a,b))
Buggy python submission (verdict: Runtime Error):
import math

x = int(input())

def is_prime(n):
  for i in range(int(math.sqrt(n))):
    if(n%i==0):
      return False
  return True

for i in range(x, x+100):
  if is_prime(i):
    print(i)
    exit()

Fixed submission:
import math

x = int(input())

def is_prime(n):
  for i in range(2, int(math.sqrt(n))):
    if(n%i==0):
      return False
  return True

for i in range(x, x+100):
  if is_prime(i):
    print(i)
    exit()

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

n = 10**5+10

x = int(input())

nums = [1 for i in range(n)]

for i in range(2, n):
  if nums[i] == 0:
    continue
  if (i>=x):
    print(i)
    exit()
  for j in range(i+1, n):
    if j%i==0:
      nums[j] = 0


Fixed submission:
import math

x = int(input())

def is_prime(n):
  for i in range(2, int(math.sqrt(n))):
    if(n%i==0):
      return False
  return True

for i in range(x, x+100):
  if is_prime(i):
    print(i)
    exit()

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())

if(a<k):
  k -= a
  a = 0
else:
  tmp = k
  k -= a
  a -= tmp
  
if(b<k):
  b = 0
else:
  b -= k

print("{0} {1}".format(a,b))

Fixed submission:
import math

x = int(input())

def is_prime(n):
  for i in range(2, int(math.sqrt(n))):
    if(n%i==0):
      return False
  return True

for i in range(x, x+100):
  if is_prime(i):
    print(i)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()]

a = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a.add(''.join([s[i],s[j],s[k]]))

print(len(a))


Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()][::-1]

a = set()
ans=0
ii = set()
for i in range(n-2):
  if s[i] in ii:
    continue
  ii.add(s[i])
  jj = set()
  for j in range(i+1,n-1):
    if s[j] in jj:
      continue
    jj.add(s[j])
    kk = set()
    for k in range(j+1,n):
      if k not in kk:
        ans+=1
        kk.add(s[k])
        a.add(''.join([s[k],s[j],s[i]]))
    
print(len(a))
Buggy python submission (verdict: Time Limit Exceeded):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

n = ni()
nn = n
mn = 10**12
nums = [1]

i=2
while i<=math.ceil(math.sqrt(n)+1):
  while n%i==0:
    nums.append(i)
  i+=1

for num in nums:
  other = nn//num
  mn = min(mn, num+other-2)

print(mn)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

n = ni()
nn = n
mn = 10**12
nums = [1]

i=2
while i<=math.ceil(math.sqrt(n)+1):
  if n%i==0:
    nums.append(i)
  i+=1

for num in nums:
  other = nn//num
  mn = min(mn, num+other-2)

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

dp = [float('inf')] * (2 ** N)


dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c = sum(1 << (i - 1) for i in map(int, input().split()))
    for x in range(2 ** N):
        dp[c | x] = min(dp[c | x], dp[x] + a)

if dp[-1]==float('inf'):
    print(-1)
else:
    print(dp[-1])

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

dp = [float('inf')] * (2 ** N)


dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c = sum(1 << (i - 1) for i in map(int, input().split()))
    for x in range(2 ** N):
        dp[c | x] = min(dp[c | x], dp[x] + a)

if dp[-1]==float('inf'):
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(1000 * 1000)

h, w, a, b = map(int, input().split())


def check_mat(m):
    # print()
    # print(m)
    zeros_h = [0] * w

    for i in range(h):
        zeros_w = 0
        for j in range(w):
            if m[i][j] == 0:
                zeros_w += 1
                zeros_h[j] += 1

        if min(zeros_w, w - zeros_w) != a:
            return 0
    # print(zeros_h)
    for i in range(w):
        if min(zeros_h[i], h - zeros_h[i]) != b:
            return 0
    return 1


def check(l, cnt):
    if cnt == h * w:
        mm = []
        for i in range(h):
            mm.append([])
            for j in range(w):
                mm[-1].append(l[i * w + j])
        if check_mat(mm) == 1:
            return mm
        else:
            return None
    mm1 = check(l + [1], cnt + 1)
    if mm1:
        return mm1
    mm2 = check(l + [0], cnt + 1)
    if mm2:
        return mm2


mm = check([], 0)

for i in range(h):
    for j in range(w):
        print(mm[i][j], end='')
    print()


Fixed submission:
h, w, a, b = map(int, input().split())

ans = []

for i in range(h):
    ans.append([])
    for j in range(w):
        if i < b and j < a:
            ans[i].append(0)
        elif i >= b and j >= a:
            ans[i].append(0)
        else:
            ans[i].append(1)

for i in range(h):
    for j in range(w):
        print(ans[i][j], end='')
    print()
Buggy python submission (verdict: Runtime Error):
import math


def kaijo(n):
    if n == 0:
        return 1
    return n * kaijo(n - 1)


a, b = map(int,input().split())

ans = 0
for i in range(5):
    if b == 0:
        ans = 0
        break
    if a == b:
        ans = 1
        break
    if a ** i < b:
        continue
    ans = math.floor(b / (a ** (i - 1))) + kaijo(i-1)
    break

print(ans)


Fixed submission:
a, b = map(int, input().split())

plgcnt = 0
tapcnt = 1

flg=0

while(True):
    if tapcnt >= b:
        print(plgcnt)
        break
    tapcnt += a - 1
    plgcnt += 1

Buggy python submission (verdict: Runtime Error):
import math


def kaijo(n):
    if n == 0:
        return 1
    return n * kaijo(n - 1)


a, b = map(int,input().split())

ans = 0
for i in range(5):
    if b == 0:
        ans = 0
        break
    if a == b:
        ans = 1
        break
    if a ** i < b:
        continue
    ans = math.floor(b / (a ** (i - 1))) + kaijo(i-1)
    break

print(ans)


Fixed submission:
a, b = map(int, input().split())

plgcnt = 0
tapcnt = 1

flg=0

while(True):
    if tapcnt >= b:
        print(plgcnt)
        break
    tapcnt += a - 1
    plgcnt += 1
Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np

n = int(input())
sraw = []

for nn in range(n):
    sraw.append(sorted(input().encode()))

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)


Fixed submission:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
sraw = []

for nn in range(n):
    sraw.append(sorted(input().encode()))

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)


Fixed submission:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
sraw = []

for nn in range(n):
    sraw.append(sorted(input()))

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)


Fixed submission:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []

for nn in range(n):
    s.append(sorted(input()))

ans = 0

sorted(s)

l = len(s)

for ss in range(0, l):
    for sss in range(ss+1, l):

        if s[ss] == s[sss]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = []


for i in range(N-1):
    R.append(V[i]/C[i])

RR = reversed(R)
RA = np.argsort(RR)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[r]
    Csum += C[r]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)


Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = [N]


for i in range(N-1):
    R[i] = V[i]/C[i]

RA = np.argsort(-R)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[i]
    Csum += C[i]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)


Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        for j in range(i, n):
            ss[j+1] += 1


for i in range(q):
    l, r = map(int, input().split())
    print(ss[r-1] - ss[l-1])



Fixed submission:
n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        ss[i+1] = 1

sss = [0] * (n+1)
cnt = 0
for i in range(n+1):
    cnt += ss[i]
    sss[i] = cnt


for i in range(q):
    l, r = map(int, input().split())
    print(sss[r-1] - sss[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        for j in range(i, n):
            ss[j+1] += 1


for i in range(q):
    l, r = map(int, input().split())
    print(ss[r-1] - ss[l-1])



Fixed submission:
n, q = map(int, input().split())
s = input()

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        ss[i+1] = 1

sss = [0] * (n+1)
cnt = 0
for i in range(n+1):
    cnt += ss[i]
    sss[i] = cnt


for i in range(q):
    l, r = map(int, input().split())
    print(sss[r-1] - sss[l-1])