Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02603 (python)

Fixed submission:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]

    aa = []
    t = A[0]
    start = A[0]
    for ai in A[1:]:
        if t <= ai:
            t = ai
            if start is None:
                start = ai
            continue
        aa.append(
            (start, t)
        )
        t = ai
        start = ai
    if start is not None:
        aa.append((start, A[-1]))

    m = 1000
    for a, b in aa:
        if a is None:
            continue
        c = m // a
        m += (b - a) * c
    print(m)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache
import itertools

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    # N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]
    # T1, T2, T3 = [int(a) for a in input().split()]

    aa = []
    t = A[0]
    start = A[0]
    for ai in A[1:]:
        if t <= ai:
            t = ai
            if start is None:
                start = ai
            continue
        aa.append(
            (start, t)
        )
        t = ai
        start = None
    if start is not None:
        aa.append((start, A[-1]))

    m = 1000
    for a, b in aa:
        c = m // a
        m += (b - a) * c
    print(m)


if __name__ == "__main__":
    main()
Problem p02713 (python)

Fixed submission:
from collections import deque, Counter
from itertools import chain, combinations
import json
import bisect
import sys
import math

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7

mem = {}


def gcd(a, b, c):
    if (a, b, c) not in mem:
        mem[(a, b, c)] = math.gcd(math.gcd(a, b), c)
    return mem[(a, b, c)]


def main():
    K = int(input())
    t1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                t1 += gcd(a, b, c) * 6
    t2 = 0
    for ab in range(1, K + 1):
        for c in range(ab + 1, K + 1):
            t2 += math.gcd(ab, c) * 6
    t3 = 0
    for abc in range(1, K + 1):
        t3 += abc
    print(t1 + t2 + t3)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np
import bisect
import sys
import math

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7

mem = {}


def gcd(a, b, c):
    if (a, b, c) not in mem:
        mem[(a, b, c)] = math.gcd(math.gcd(a, b), c)
    return mem[(a, b, c)]


def main():
    K = int(input())
    t1 = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                t1 += gcd(a, b, c) * 6
    t2 = 0
    for ab in range(1, K + 1):
        for c in range(ab + 1, K + 1):
            t2 += math.gcd(ab, c) * 6
    t3 = 0
    for abc in range(1, K + 1):
        t3 += abc
    print(t1 + t2 + t3)


if __name__ == "__main__":
    main()
Problem p02716 (python)

Fixed submission:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    @lru_cache(None)
    def f(i, j):
        if i < 0 or j < 0:
            return -INF
        if i == 0:
            return -INF
        if abs(j - i // 2 - 1) >= 2:
            return -INF
        if j == 0:
            return 0
        if j == 1:
            return max(A[:i])
        return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))

    print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque, Counter
from itertools import chain, combinations
import json
import numpy as np
import bisect
import sys
import math
import bisect

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7


def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    DP = np.zeros((N + 1, N + 1))
    DP[1][1] = A[0]

    for i in range(2, N + 1):
        a = math.floor((i - 1) / 2)
        b = math.floor((i + 1) / 2)
        for j in range(a, b + 1):
            DP[i][j] = max(DP[i - 1][j], DP[i - 2][j - 1] + A[i - 1])
    print(int(DP[N][math.floor(N / 2)]))


if __name__ == "__main__":
    main()
Problem p02801 (python)

Fixed submission:
from collections import deque
from itertools import chain, combinations
import json




def main():
    a = "abcdefghijklmnopqrstuvwxyz"
    c=input()
    print(a[a.index(c)+1])

    # N = int(input())
    # A = [int(a) for a in input().split()]
    # B = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    print()


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
from itertools import chain, combinations
import json
from typing import List




def main():
    a = "abcdefghijklmnopqrstuvwxyz"
    c=input()
    print(a[a.index(c)+1])

    # N = int(input())
    # A = [int(a) for a in input().split()]
    # B = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]
    print()


if __name__ == "__main__":
    main()
Problem p02850 (python)

Fixed submission:
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def keta(n):
    if n < 10:
        return 1
    return math.floor(math.log10(n - 1)) + 1


def check(A, B, X, n):
    return A * n + B * keta(n) <= X


def main():
    N = int(input())
    ab = [[int(a) - 1 for a in input().split()] for _ in range(N - 1)]

    tree = defaultdict(list)
    # res = {}

    for i, (a, b) in enumerate(ab):
        # aa = tt[a]
        # aa.append((b, i))
        # tt[a] = aa
        if a not in tree:
            tree[a] = []
        tree[a].append((b, i))

    # def p(tt, parent):
    #     children = tt[parent]
    #     res[parent]=children
    #     # res = {parent: children}
    #     for c, ii in children:
    #         p(tt, c)
    #     return res
    #
    #
    # tree = p(tt, 0)

    colors = len(tree[0])
    for k, v in tree.items():
        if k == 0:
            continue
        colors = max(colors, len(v) + 1)

    print(colors)

    res = [None] * (N - 1)

    def solve(pos, parentcol):
        children = tree[pos]
        for iii, (c, i) in enumerate(children):
            res[i] = (parentcol + 1 + iii) % colors
            solve(c, res[i])

    solve(0, -1)

    for i in range(N - 1):
        print(res[i] + 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def keta(n):
    if n < 10:
        return 1
    return math.floor(math.log10(n - 1)) + 1


def check(A, B, X, n):
    return A * n + B * keta(n) <= X


def p(tt, parent):
    children = tt[parent]
    for i in range(len(children)):
        if children[i][0] == parent:
            children.remove(children[i])
            break

    res = {parent: children}
    for c, ii in children:
        tt[c].remove((parent, ii))
        res = {**res, **p(tt, c)}
    return res


def main():
    N = int(input())
    ab = [[int(a) - 1 for a in input().split()] for _ in range(N - 1)]

    tt = defaultdict(list)

    for i, (a, b) in enumerate(ab):
        aa = tt[a]
        aa.append((b, i))
        tt[a] = aa
        a, b = b, a
        aa = tt[a]
        aa.append((b, i))
        tt[a] = aa

    tree = p(tt, 0)
    # print(tree)

    colors = len(tree[0])
    for k, v in tree.items():
        if k == 0:
            continue
        colors = max(colors, len(v) + 1)

    print(colors)

    res = [None] * (N - 1)

    def solve(pos, parentcol):
        children = tt[pos]
        for iii, (c, i) in enumerate(children):
            res[i] = (parentcol + 1 + iii) % colors
            solve(c, res[i])

    solve(0, -1)

    for i in range(N - 1):
        print(res[i] + 1)


if __name__ == '__main__':
    main()
Problem p02900 (python)

Fixed submission:
import math


def gcdf(a, b):
    if a > b:
        a, b = b, a
    if b%a==0:
        return a
    return gcdf(a, b % a)


def f(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append(i)

    if temp != 1:
        arr.append(temp)

    if arr == []:
        arr.append(n)

    return arr


def main():
    # return
    # N = int(input())
    # N,= [int(a) for a in input().split()]
    A, B = [int(a) for a in input().split()]

    gcd = gcdf(A, B)

    if gcd == 1:
        print(1)
    else:
        print(len(f(gcd)) + 1)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math


def f(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append(i)

    if temp != 1:
        arr.append(temp)

    if arr == []:
        arr.append(n)

    return arr


def main():
    # return
    # N = int(input())
    # N,= [int(a) for a in input().split()]
    A, B = [int(a) for a in input().split()]

    gcd = math.gcd(A, B)

    if gcd == 1:
        print(1)
    else:
        print(len(f(gcd)) + 1)


if __name__ == "__main__":
    main()
Problem p02939 (python)

Fixed submission:
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def f(n):
    if n == 0:
        return 0, False
    a = n // 3
    b = n % 3
    if b == 0:
        return a * 2, 0
    if b == 1:
        return a * 2 + 1, 1

    return a * 2 + 1, 2


def solve(s):
    last = s[0]
    c = 1
    res = 0
    last_flag = False
    for cc in s[1:]:
        if last == cc:
            c += 1
            continue

        k, k_flag = f(c)
        if k_flag == 0:
            res += k
        elif k_flag == 1:
            res += k
            last_flag = False
        else:
            if last_flag:
                res += k + 1
                last_flag = False
            else:
                res += k
                last_flag = True
        c = 1
        last = cc
    k, k_flag = f(c)
    if k_flag == 0:
        res += k
    elif k_flag == 1:
        res += k
    else:
        if last_flag:
            res += k + 1
        else:
            res += k
    return res


def main():
    s = input()
    # N = int(input())
    print(solve(s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

input = sys.stdin.readline

sys.setrecursionlimit(10000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def solve(pre, s):
    if len(s) == 1:
        if pre != s:
            return 1
        return None
    for i in range(1, len(s)):
        if pre == s[:i]:
            continue
        r = solve(s[:i], s[i:])
        if r is not None:
            return r + 1
    if pre != s:
        return 1


def main():
    s = input().strip()
    # N = int(input())
    print(solve("", s))
    # N, A, B = [int(a) for a in input().split()]
    # A = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]


if __name__ == '__main__':
    main()
Problem p03261 (python)

Fixed submission:
import math


def main():
    N = int(input())
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
from collections import defaultdict


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    if len(set(W)) != len(W):
        print("No")
        return

    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
from collections import defaultdict


def main():
    N, = [int(a) for a in input()]
    W = [input() for _ in range(N)]

    a = []
    for w in W:
        if w in a:
            print("No")
            return
        a.append(w)
        if len(a) == 1:
            continue
        if a[-2][-1] != a[-1][0]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()
Problem p03263 (python)

Fixed submission:
import math


def main():
    H, W = [int(a) for a in input().split()]
    A = [[int(a) for a in input().split()] for _ in range(H)]

    od = None
    res = []
    for i in range(H):
        if i % 2 == 0:
            r = range(W)
        else:
            r = reversed(range(W))
        for j in r:
            cell = A[i][j]
            if od is None:
                if cell % 2 != 0:
                    od = i, j
            else:
                res.append((od[0],od[1], i, j))
                if cell % 2 == 0:
                    od = i, j
                else:
                    od = None

    print(len(res))
    for a, b, c, d in res:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math


def main():
    H, W = [int(a) for a in input().split()]
    A = [[int(a) for a in input().split()] for _ in range(H)]

    od = None
    res = []
    for i in range(H):
        if i % 2 == 0:
            r = range(W)
        else:
            r = reversed(range(W))
        for j in r:
            cell = A[i][j]
            if od is None:
                if cell % 2 != 0:
                    od = i, j
            else:
                res.append((*od, i, j))
                if cell % 2 == 0:
                    od = i, j
                else:
                    od = None

    print(len(res))
    for a, b, c, d in res:
        print(a+1, b+1, c+1, d+1)


if __name__ == '__main__':
    main()
Problem p03567 (python)

Fixed submission:

def main():
    s = input()
    i = "AC" in s
    if i:
        print("Yes")
    else:
        print("No")
    # print(123)
    # b = [int(a) for a in input().split(" ")]
    # print(b)
    # [input() for a in range(3)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

import sys
from typing import List


def main(arg: List[str]):
    s = input()
    i = "AC" in s
    if i:
        print("Yes")
    else:
        print("No")
    # print(123)
    # b = [int(a) for a in input().split(" ")]
    # print(b)
    # [input() for a in range(3)]


if __name__ == "__main__":
    main(sys.argv)
Problem p03569 (python)

Fixed submission:
import functools


def check(s):
    result = 0
    sss = s

    while True:
        if len(sss) <= 1:
            break
        head = sss[0]
        tail = sss[-1]
        if head == tail:
            sss = sss[1:-1]
            continue
        if head == "x":
            result += 1
            sss = sss[1:]
            continue
        if tail == "x":
            result += 1
            sss = sss[:-1]
            continue
        return -1
    return result

def main():
    n = check(input())
    print(n)

    # total = functools.reduce(lambda a, b: a * (2 if b % 2 == 1 else 1),A)
    # print(pow(3 ,len(A)-1)*total)
    # # print(123)
    # b = [int(a) for a in input().split(" ")]
    # print(b)
    # [input() for a in range(3)]


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import functools

def check(s):
    if len(s)==0 or len(s)==1:
        return 0
    head = s[0]
    tail = s[-1]
    if head ==tail:
        return check(s[1:-1])
    if head =="x":
        return 1+check(s[1:])
    if tail =="x":
        return 1+check(s[:-1])
    return -1

def main():
    n = check(input())
    print(n)

    # total = functools.reduce(lambda a, b: a * (2 if b % 2 == 1 else 1),A)
    # print(pow(3 ,len(A)-1)*total)
    # # print(123)
    # b = [int(a) for a in input().split(" ")]
    # print(b)
    # [input() for a in range(3)]


if __name__ == "__main__":
    main()
Problem p02641 (python)

Fixed submission:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*102
for i in p:
    flag[i] = True
for j in range(0, 102):
    l = max(0, x-j)
    r = min(101, x+j)
    if not flag[l]:
        print(l)
        sys.exit()
    if not flag[r]:
        print(r)
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*100
for i in p:
    flag[i-1] = True
for j in range(0, n+1):
    l = max(0, x-1-j)
    r = min(100, x-1+j)
    if not flag[l]:
        print(l+1)
        sys.exit()
    if not flag[r]:
        print(r+1)
        sys.exit()
Problem p02767 (python)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp, hp)
print(hp)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))
xmin = min(x)
xmax = max(x)
hp = 10e10
for p in range(xmin, xmax+1):
    temp = 0
    for xi in x:
        temp += (xi-p)*(xi-p)
    hp = min(temp,)
print(hp)
Problem p02678 (python)

Fixed submission:
import itertools
import math
import fractions
import functools
import copy
from collections import deque

n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)


a = [-1]*n
d = deque([0])
while d:
    f = d.popleft()
    for i in g[f]:
        if a[i] == -1:
            a[i] = f
            d.append(i)

print("Yes")
for i in range(1,n):
    print(a[i]+1)

Buggy submission (verdict: Runtime Error):
import itertools
import math
import fractions
import functools
import copy
from collections import deque

n, m = map(int, input().split())
ab = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

ans = [-1] * n
d = deque([0])

while d:
    f = d.popleft()
    for i in ab[f]:
        if ans[i] == -1:
            ans[i] = f
            d.append(i)

print("Yes")
for i in range(1,n):
    print(ans[i]+1)
Problem p02718 (python)

Fixed submission:
N, M = map(int, input().split())
vote = list(map(int, input().split()))
sum = sum(vote)
allowedList = []


for i in range(0,len(vote)):
    if sum / 4 / M <= vote[i]:
        allowedList.append(vote[i])


if len(allowedList) >= M:
    print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
vote = list(map(int, input().split()))
sum = sum(vote)
cnt = 0


for i in range(0,len(vote)):
    if sum / 4 / M <= vote[i]:
        cnt++


if cnt >= M:
    print("Yes")
else: print("No")
Problem p02861 (python)

Fixed submission:
import itertools
import math

n = int(input())
x = []
y = []
index = []
for i in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    index.append(i)

distance = 0
for v in itertools.permutations(index):
    for i in range(n-1):
        distance += math.sqrt((x[v[i]] - x[v[i+1]]) **
                              2 + (y[v[i]]-y[v[i+1]])**2)


print(distance/math.factorial(n))

Buggy submission (verdict: Runtime Error):

n = int(input())
x = []
y = []
index = []
for i in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    index.append(i)

distance = 0
for v in itertools.permutations(index):
    for i in range(n-1):
        distance += math.sqrt((x[v[i]] - x[v[i+1]]) **
                              2 + (y[v[i]]-y[v[i+1]])**2)


print(distance/math.factorial(n))
Problem p02922 (python)

Fixed submission:
import math
a, b = map(int, input().split())
print(math.ceil((b-1)/(a-1)))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(math.ceil((b-1)/(a-1)))
Problem p02947 (python)

Fixed submission:
import math
n = int(input())

dic = {}


def twoKimuawaseSum(num):
    result = 0
    for i in range(1, num):
        result += i
    return result


for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += twoKimuawaseSum(num)
print(math.floor(sum))

Buggy submission (verdict: Runtime Error):
import math
import itertools
from scipy.special import comb
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += comb(num, 2)
print(math.floor(sum))

Buggy submission (verdict: Runtime Error):
import math
import itertools
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(math.floor(sum))

Buggy submission (verdict: Runtime Error):
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(math.floor(sum))

Buggy submission (verdict: Runtime Error):
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1

sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += math.factorial(num) / 2
print(int(sum))