Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
s = input()
k = int(input())
t = []
u = ""
v = []
a = 0

for i in range(k):
    t.append(s)
    
for j in range(len(t)):
    u += str(t[j])

for l in range(len(u)):
    v.append(u[l])
    
v.append("")
v.append("")
    
for m in range(len(v) - 2):
    if v[m] == v[m + 1] and v[m] != v[m - 1]:
        for n in range(len(v) - 1 - m):
            if not v[m] == v[n + m]:
                a += int(n / 2)
                break

print(a)

Fixed submission:
s = list(input())
n = len(s)
k = int(input())
ans = 0
if s.count(s[0]) == n:
    ans = (n * k) // 2
else:
    c = 1
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            c += 1
        else:
            ans += c // 2
            c = 1
    ans += c // 2
    ans *= k
    if s[0] == s[n - 1]:
        c1 = 0
        c2 = 0
        for i in range(n):
            if s[i] == s[0]:
                c1 += 1
            else:
                break
        for i in range(n - 1, -1, -1):
            if s[i] == s[n - 1]:
                c2 += 1
            else:
                break
        if not c1 // 2 + c2 // 2 == (c1 + c2) // 2:
            ans += k
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
s = input()
k = int(input())
t = []
u = ""
v = []
a = 0

for i in range(k):
    t.append(s)
    
for j in range(len(t)):
    u += str(t[j])

for l in range(len(u)):
    v.append(u[l])
    
v.append("")
v.append("")
    
for m in range(len(v) - 2):
    if v[m] == v[m + 1]:
        if v[m] != v[m - 1]:
            for n in range(len(v) - 1 - m):
                if not v[m] == v[n + m]:
                    a += int(n / 2)
                    break

print(a)


Fixed submission:
s = list(input())
n = len(s)
k = int(input())
ans = 0
if s.count(s[0]) == n:
    ans = (n * k) // 2
else:
    c = 1
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            c += 1
        else:
            ans += c // 2
            c = 1
    ans += c // 2
    ans *= k
    if s[0] == s[n - 1]:
        c1 = 0
        c2 = 0
        for i in range(n):
            if s[i] == s[0]:
                c1 += 1
            else:
                break
        for i in range(n - 1, -1, -1):
            if s[i] == s[n - 1]:
                c2 += 1
            else:
                break
        if not c1 // 2 + c2 // 2 == (c1 + c2) // 2:
            ans += k
            ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().rstrip().split(" ")
i = 0
j = 0
ans = []

for i in range(int(n)):
    for j in range(int(n)):
        if int(i) + 1 == int(a[j]):
            print(int(j) + 1 , end = " ")

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0] * n

for i in range(n):
    b[a[i] - 1] = i + 1
    
for i in range(n):
    print(b[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().rstrip().split(" ")
i = 0
j = 0
ans = []

for i in range(int(n)):
    for j in range(int(n)):
        if int(i) + 1 == int(a[j]):
            ans.append(int(j) + 1)
            
for k in range(int(n)):
    print(ans[k] , end = " ")

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0] * n

for i in range(n):
    b[a[i] - 1] = i + 1
    
for i in range(n):
    print(b[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().rstrip().split()
i = 0
j = 0
ans = []

for i in range(int(n)):
    for j in range(int(n)):
        if int(i) + 1 == int(a[j]):
            ans.append(int(j) + 1)
            
for k in range(int(n)):
    print(ans[k] , end = " ")

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0] * n

for i in range(n):
    b[a[i] - 1] = i + 1
    
for i in range(n):
    print(b[i],end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [-i for i in a]
heapq.heapify(a)
for i in range(m):
    c = heapq.heappop(a)
    c = -c // 2
    heapq.heappush(a, -c)
    if sum(a) == 0:
        break
print(-sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [-i for i in a]
heapq.heapify(a)
for i in range(m):
    c = heapq.heappop(a)
    c = -c // 2
    heapq.heappush(a, -c)
    if a[0] == 0:
        break
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

for i in range(n):
    ans += i
    
print(ans)


Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = []
m = 0

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)
    
t.sort()

for i in range(n):
    for j in range(n - i - 1):
        if t[i] == t[i + j + 1]:
            m += 1
        else:
            break
        
print(m)
    

Fixed submission:
n = int(input())
d = {}
ans = 0
for _ in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in d:
        d[s] += 1
        ans += d[s]
    else:
        d.update({s : 0})
print(ans)

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

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)
    
for i in range(n):
    for j in range(n - i - 1):
        if t[i] == t[j + i + 1]:
            m += 1
        
print(m)

Fixed submission:
n = int(input())
d = {}
ans = 0
for _ in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in d:
        d[s] += 1
        ans += d[s]
    else:
        d.update({s : 0})
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[0] * (m + 1) for _ in range(n + 1)]
dpsum = [[0] * (m + 1) for _ in range(n + 1)]
mod = pow(10, 9) + 7
for i in range(1, n + 1):
    for j in range(1, m + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = 1
            if not i == 1 and not j == 1:
                dp[i][j] += dpsum[i - 1][j - 1]
                dp[i][j] %= mod
        dpsum[i][j] = dpsum[i - 1][j] + dpsum[i][j - 1] - dpsum[i - 1][j - 1] + dp[i][j]
        dpsum[i][j] %= mod
ans = dpsum[n][m] + 1
print(ans)

Fixed submission:
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[0] * (m + 1) for _ in range(n + 1)]
dpsum = [[0] * (m + 1) for _ in range(n + 1)]
mod = pow(10, 9) + 7
for i in range(1, n + 1):
    for j in range(1, m + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = 1
            if not i == 1 and not j == 1:
                dp[i][j] += dpsum[i - 1][j - 1]
                dp[i][j] %= mod
        dpsum[i][j] = dpsum[i - 1][j] + dpsum[i][j - 1] - dpsum[i - 1][j - 1] + dp[i][j]
        dpsum[i][j] %= mod
ans = dpsum[n][m] + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
t = [[-1] * w for _ in range(h)]
cnt = [0] * 2005
ans = 0
for i in range(h):
    x = 1
    cnt[1] = 0
    for j in range(w):
        if s[i][j] == ".":
            t[i][j] = x
            cnt[x] += 1
        else:
            x += 1
            cnt[x] = 0
    for j in range(w):
        if not t[i][j] == -1:
            t[i][j] = cnt[t[i][j]]
for j in range(w):
    x = 1
    cnt[1] = 0
    for i in range(h):
        if s[i][j] == ".":
            s[i][j] = x
            cnt[x] += 1
        else:
            x += 1
            cnt[x] = 0
    for i in range(h):
        if not s[i][j] == "#":
            ans = max(ans, t[i][j] + cnt[s[i][j]] - 1)
print(ans)

Fixed submission:
h, w = map(int, input().split())
t = ["#"] * (w + 2)
s = [["#"] + list(input()) + ["#"] for _ in range(h)]
s.append(t)
s.insert(0, t)
dp_n = [[0] * (w + 2) for _ in range(h + 2)]
dp_s = [[0] * (w + 2) for _ in range(h + 2)]
dp_e = [[0] * (w + 2) for _ in range(h + 2)]
dp_w = [[0] * (w + 2) for _ in range(h + 2)]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == ".":
            dp_n[i][j] += dp_n[i - 1][j] + 1
        if s[h + 1 - i][j] == ".":
            dp_s[h + 1 - i][j] += dp_s[h + 2 - i][j] + 1
for j in range(1, w + 1):
    for i in range(1, h + 1):
        if s[i][j] == ".":
            dp_w[i][j] += dp_w[i][j - 1] + 1
        if s[i][w + 1 - j] == ".":
            dp_e[i][w + 1 - j] += dp_e[i][w + 2 - j] + 1
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        c = dp_n[i][j] + dp_s[i][j] + dp_e[i][j] + dp_w[i][j] - 3
        if c > ans:
            ans = c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n , m = map(int,input().split())
a = [1] * n
ans = 0

for i in range(m):
    l , r = map(int,input().split())
    for j in range(n):
        if l > j + 1 or j + 1 > r:
            a[j] = 0
            
for i in range(n):
    ans += a[i]
    
print(ans)        

Fixed submission:
n , m = map(int,input().split())
a , b = 1 , 100000

for i in range(m):
    l , r = map(int,input().split())
    if a <= l:
        a = l
    if b >= r:
        b = r
        
c = b - a + 1
if c > 0:
    print(c)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
"""
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b.sort(key = lambda x : x[1], reverse = True)
a.sort()
i = 0
j = 0
c = 1
ans = sum(a)
while True:
    if i >= m:
        break
    for _ in range(b[i][0]):
        if j >= n:
            c = 0
            break
        if a[j] < b[i][1]:
            ans += b[i][1] - a[j]
            j += 1
        else:
            c = 0
            break
    i += 1
    if c == 0:
        break
print(ans)
"""
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b.sort(key = lambda x : x[1], reverse = True)
c = n
for i in range(m):
    if c - b[i][0] >= 0:
        a = a + ([b[i][1]] * b[i][0])
        c -= b[i][0]
    else:
        a = a + ([b[i][1]] * c)
        break
a.sort(reverse = True)
print(sum(a[0 : n]))

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b.sort(key = lambda x : x[1], reverse = True)
a.sort()
i = 0
j = 0
c = 1
ans = sum(a)
while True:
    if i >= m:
        break
    for _ in range(b[i][0]):
        if j >= n:
            c = 0
            break
        if a[j] < b[i][1]:
            ans += b[i][1] - a[j]
            j += 1
        else:
            c = 0
            break
    i += 1
    if c == 0:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
ans = 0
for i in range(3001):
    if r * i > n:
        break
    for j in range(3001):
        if r * i + g * j > n:
            break
        if (n - r * i - g * j) % b == 0:
            ans += 1
print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(3001):
    if r * i > n:
        break
    for j in range(3001):
        if r * i + g * j > n:
            break
        if (n - r * i - g * j) % b == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs():
    global ans
    while q:
        p = q.popleft()
        for u in v:
            x, y = p[0] + u[0], p[1] + u[1]
            if 0 <= x < h and 0 <= y < w:
                if s[x][y] == -1:
                    s[x][y] = s[p[0]][p[1]] + 1
                    q.append([x, y])
                    ans = max(ans, s[x][y])
    return

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[-1] * w for _ in range(h)]
v = [[1, 0], [-1, 0], [0, 1], [0, -1]]
q = deque()
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            s[i][j] = 0
            q.append([i, j])
bfs()
print(ans)

Fixed submission:
from collections import deque

def bfs():
    global ans
    while q:
        p = q.popleft()
        for u in v:
            x, y = p[0] + u[0], p[1] + u[1]
            if 0 <= x < h and 0 <= y < w:
                if s[x][y] == -1:
                    s[x][y] = s[p[0]][p[1]] + 1
                    q.append([x, y])
                    ans = max(ans, s[x][y])
    return

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[-1] * w for _ in range(h)]
v = [[1, 0], [-1, 0], [0, 1], [0, -1]]
q = deque()
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            s[i][j] = 0
            q.append([i, j])
bfs()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
m = [0]
l = [n, 0, 0, 0, 0, 0]
ans = 0
for i in range(5):
    m.append(int(input()))
while l[5] < n:
    for i in range(4, -1, -1):
        if l[i] != 0:
            if l[i] <= m[i + 1]:
                l[i + 1] += l[i]
                l[i] = 0
            else:
                l[i + 1] += m[i + 1]
                l[i] -= m[i + 1]
    ans += 1
                
print(ans)

Fixed submission:
n = int(input())
m = []
for i in range(5):
    m.append(int(input()))
ans = int(n / min(m))
if n % min(m) != 0:
    ans += 5
else:
    ans += 4
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
c = 0
for i in range(min(a, b), 1, -1):
    if a % i == 0 and b % i == 0:
        c += 1
    if c == k:
        ans = i
        break
print(ans)

Fixed submission:
a, b, k = map(int, input().split())
c = []
for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        c.append(i)
print(c[k - 1])
Buggy python submission (verdict: Runtime Error):
import heapq

n, k = map(int, input().split())
a = [0] * (n + 1)
typecnt = 0
h = []
heapq.heapify(h)
for _ in range(n):
    t, d = map(int, input().split())
    if a[t] == 0:
        typecnt += 1
        a[t] = 1
    heapq.heappush(h, [-d, t])
ans = 0
mintype = 0
m = []
heapq.heapify(m)
for _ in range(k):
    d, t = heapq.heappop(h)
    if a[t] == 1:
        mintype += 1
        a[t] = 0
    else:
        heapq.heappush(m, -d)
    ans -= d
cnt = ans
ans += mintype * mintype
for j in range(mintype, typecnt):
    bonus = (j + 1) * (j + 1)
    while h:
        d, t = heapq.heappop(h)
        if a[t] == 1:
            a[t] = 0
            l = heapq.heappop(m)
            cnt -= (d + l)
            ans = max(ans, cnt + bonus)
            break
print(ans)

Fixed submission:
import heapq

n, k = map(int, input().split())
a = [0] * (n + 1)
typecnt = 0
h = []
heapq.heapify(h)
for _ in range(n):
    t, d = map(int, input().split())
    if a[t] == 0:
        typecnt += 1
        a[t] = 1
    heapq.heappush(h, [-d, t])
ans = 0
mintype = 0
m = []
heapq.heapify(m)
for _ in range(k):
    d, t = heapq.heappop(h)
    if a[t] == 1:
        mintype += 1
        a[t] = 0
    else:
        heapq.heappush(m, -d)
    ans -= d
cnt = ans
ans += mintype * mintype
for j in range(mintype, typecnt):
    if not m:
        break
    bonus = (j + 1) * (j + 1)
    while h:
        d, t = heapq.heappop(h)
        if not m:
            break
        if a[t] == 1:
            a[t] = 0
            l = heapq.heappop(m)
            cnt -= (d + l)
            ans = max(ans, cnt + bonus)
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp0 = [[0] * (k + 1)] * n
dp1 = [0] * n
for i in range(1, n):
    for j in range(k + 1):
        if j <= i and j != 0:
            dp0[i][j] = dp1[i - j] + abs(h[i] - h[i - j])
        else:
            dp0[i][j] = 10 ** 9
    dp1[i] = min(dp0[i])
print(dp1[n - 1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp0 = [[0] * (k + 1)] * n
dp1 = [0] * n
for i in range(1, n):
    for j in range(k + 1):
        if j <= i and j != 0:
            dp0[i][j] = dp1[i - j] + abs(h[i] - h[i - j])
        else:
            dp0[i][j] = 10 ** 9
    dp1[i] = min(dp0[i])
print(dp1[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
p.insert(0, [0, 0])
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j >= p[i][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p[i][0]] + p[i][1])
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[n][w])

Fixed submission:
n, w = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
p.insert(0, [0, 0])
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j >= p[i][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p[i][0]] + p[i][1])
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[n][w])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [0] + list(map(float, input().split()))
q = [1 - p[i] for i in range(n + 1)]
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
    for j in range(n + 1):
        dp[i][j] = dp[i - 1][j] * q[i]
        if not j == 0:
            dp[i][j] += dp[i - 1][j - 1] * p[i]
ans = 0
for i in range((n + 1) // 2):
    ans += dp[n][n - i]
print(ans)

Fixed submission:
n = int(input())
p = [0] + list(map(float, input().split()))
q = [1 - p[i] for i in range(n + 1)]
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
    for j in range(n + 1):
        dp[i][j] = dp[i - 1][j] * q[i]
        if not j == 0:
            dp[i][j] += dp[i - 1][j - 1] * p[i]
ans = 0
for i in range((n + 1) // 2):
    ans += dp[n][n - i]
print(ans)
Buggy python submission (verdict: Runtime Error):
def prime_factorize(n):
    ans = []
    for i in range(2, int(n ** (1 / 2)) + 1):
        while True:
            if not n % i == 0:
                break
            ans.append(i)
            n /= i
        if n == 1:
            break
    if n != 1:
        ans.append(int(n))
    return ans

def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

n, m = map(int, input().split())
mod = 10 ** 9 + 7
s = prime_factorize(m)
c = 0
d = s[0]
ans = 1
for i in range(len(s)):
    if d == s[i]:
        c += 1
    else:
        d = s[i]
        ans *= comb(n - 1 + c, c, mod)
        ans %= mod
        c = 1
ans *= comb(n - 1 + c, c, mod)
ans %= mod
print(ans)

Fixed submission:
def prime_factorize(n):
    ans = []
    for i in range(2, int(n ** (1 / 2)) + 1):
        while True:
            if not n % i == 0:
                break
            ans.append(i)
            n /= i
        if n == 1:
            break
    if n != 1:
        ans.append(int(n))
    return ans

def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

n, m = map(int, input().split())
mod = 10 ** 9 + 7
s = prime_factorize(m)
if m == 1:
    s = [1]
c = 0
d = s[0]
ans = 1
for i in range(len(s)):
    if d == s[i]:
        c += 1
    else:
        d = s[i]
        ans *= comb(n - 1 + c, c, mod)
        ans %= mod
        c = 1
ans *= comb(n - 1 + c, c, mod)
ans %= mod
if m == 1:
    ans = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n == 1:
    ans = 0
elif n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [[0] * 21 for _ in range(n)]
for i in range(n):
    j = 0
    k = 1
    while True:
        if a[i] == 0:
            break
        if (a[i] // k) % 2 == 1:
            b[i][j] = 1
            a[i] -= k
        k *= 2
        j += 1
ans = 0
for i in range(n):
    s = b[i]
    j = 1
    ans += 1
    while True:
        if i + j >= n or j >= 21:
            break
        for k in range(n):
            s[k] += b[i + j][k]
        if max(s) >= 2:
            break
        else:
            ans += 1
        j += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m, x, c = 0, 0, 0
j = 0
ans = 0
for i in range(n):
    m += a[i]
    x ^= a[i]
    c += 1
    if not m == x:
        while True:
            if m == x:
                break
            x ^= a[j]
            m -= a[j]
            j += 1
            c -= 1
    ans += c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(input()) for _ in range(n)]
ans = 0
alphcnt = [0] * 26
for i in range(n):
    for j in range(n):
        alphcnt[ord(s[i][j]) - 97] += 1
if max(alphcnt) == pow(n, 2):
    print(pow(n, 2))
    exit()
for k in range(n):
    c = 1
    for i in range(n - 1):
        for j in range(i + 1, n):
            if not s[(i + k) % n][j] == s[(j + k) % n][i]:
                c = 0
                break
        if c == 0:
            break
    if c == 1:
        ans += n
print(ans)

Fixed submission:
n = int(input())
s = [list(input()) for _ in range(n)]
ans = 0
alphcnt = [0] * 26
for i in range(n):
    for j in range(n):
        alphcnt[ord(s[i][j]) - 97] += 1
if max(alphcnt) == pow(n, 2):
    print(pow(n, 2))
    exit()
for k in range(n):
    c = 1
    for i in range(n - 1):
        for j in range(i + 1, n):
            if not s[(i + k) % n][j] == s[(j + k) % n][i]:
                c = 0
                break
        if c == 0:
            break
    if c == 1:
        ans += n
print(ans)