Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

strings = []
cnts = []

for i in range(n):
    s = input()
    sd = {}
    for i in range(10):
        if s[i] in sd:
            sd[s[i]] += 1
        else:
            sd[s[i]] = 1

    new = True
    for i in range(len(strings)):
        match = True
        for key, value in strings[i].items():
            if key in sd:
                if sd[key] != value:
                    match = False
                    break
            else:
                match = False
                break

        if match:
            cnts[i] += 1
            new = False
            break

    if new:
        strings.append(sd)
        cnts.append(1)

print(sum(list(map(lambda x: x*(x-1)//2, cnts))))

Fixed submission:
n = int(input())

strings = {}

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

print(sum(list(map(lambda x: x*(x-1)//2, strings.values()))))
Buggy python submission (verdict: Runtime Error):
n = int(input())

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

print(n-max(difs.values()))

Fixed submission:
n = int(input())

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

if n == 1:
    print(1)
else:
    print(n-max(difs.values()))
Buggy python submission (verdict: Time Limit Exceeded):
h, w = list(map(int, input().split()))
grid = [input() for _ in range(h)]

cnt = [[0]*w for _ in range(h)]

yStarts = [-1] * w
yStrks = [0] * w

for y in range(h):
    xStart = -1
    xStrk = 0

    for x in range(w):
        if grid[y][x] == ".":
            if xStart == -1:
                xStart = x
            xStrk += 1

            if yStarts[x] == -1:
                yStarts[x] = y
            yStrks[x] += 1

        if grid[y][x] == "#" or x == w-1:
            if xStart != -1:
                xEnd = x if grid[y][x] == "." else x-1

                for x2 in range(xStart, xEnd+1):
                    cnt[y][x2] += (xEnd-xStart)+1

            xStart = -1
            xStrk = 0

        if grid[y][x] == "#" or y == h-1:
            if yStarts[x] != -1:
                yEnd = y if grid[y][x] == "." else y-1

                for y2 in range(yStarts[x], yEnd+1):
                    cnt[y2][x] += (yEnd-yStarts[x])+1

            yStarts[x] = -1
            yStrks[x] = 0

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, cnt[y][x]-1)

print(ans)

Fixed submission:
h, w = list(map(int, raw_input().split()))
grid = [raw_input() for _ in range(h)]

cnt = [[0]*w for _ in range(h)]

yStarts = [-1] * w
yStrks = [0] * w

for y in range(h):
    xStart = -1
    xStrk = 0

    for x in range(w):
        if grid[y][x] == ".":
            if xStart == -1:
                xStart = x
            xStrk += 1

            if yStarts[x] == -1:
                yStarts[x] = y
            yStrks[x] += 1

        if grid[y][x] == "#" or x == w-1:
            if xStart != -1:
                xEnd = x if grid[y][x] == "." else x-1

                for x2 in range(xStart, xEnd+1):
                    cnt[y][x2] += (xEnd-xStart)+1

            xStart = -1
            xStrk = 0

        if grid[y][x] == "#" or y == h-1:
            if yStarts[x] != -1:
                yEnd = y if grid[y][x] == "." else y-1

                for y2 in range(yStarts[x], yEnd+1):
                    cnt[y2][x] += (yEnd-yStarts[x])+1

            yStarts[x] = -1
            yStrks[x] = 0

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, cnt[y][x]-1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

heapq.heapify(a)
for i in range(m):
    b, c = list(map(int, input().split()))

    for j in range(b):
        if c > a[0]:
            heapq.heapreplace(a, c)
        else:
            break

print(sum(a))

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

cnt = {}

for i in range(n):
    if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1

for i in range(m):
    b, c = list(map(int, input().split()))

    if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b

cnts = sorted(cnt.items())
cnt = 0
tot = 0
last = (0, 0)

while cnt < n:
    last = cnts.pop()
    tot += last[0] * last[1]
    cnt += last[1]

tot -= (cnt-n)*last[0]
print(tot)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = list(map(int, input().split()))

cnt = 0
for i in range(n//r + 1):
    for j in range(n//g + 1):
        nb = (n - (i*r+j*g))/b

        if (nb >= 0) and (nb % 1 == 0):
            cnt += 1

print(cnt)

Fixed submission:
r, g, b, n = list(map(int, input().split()))

cnt = 0
for i in range(n//r + 1):
    for j in range(n//g + 1):
        nb = (n - (i*r+j*g))

        if (nb >= 0):
            if (nb % b == 0):
                cnt += 1
        else:
            break

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

surplus = []
short = []

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short.append(b[i]-a[i])

surplus = sorted(surplus)
taken = False
cnt = 0
for i in range(len(short)):
    cost = short.pop()
    cnt += 1

    while cost > 0:
        if len(surplus) == 0:
            print(-1)
           	exit()

        take = min(cost, surplus[-1])
        cost -= take
        surplus[-1] -= take

        if not taken:
            taken = True
            cnt += 1

        if surplus[-1] == 0:
            surplus.pop()
            taken = False

print(cnt)

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

surplus = []
short = []

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short.append(b[i]-a[i])

surplus = sorted(surplus)
taken = False
cnt = 0
for i in range(len(short)):
    cost = short.pop()
    cnt += 1

    while cost > 0:
        if len(surplus) == 0:
            print(-1)
            exit()

        take = min(cost, surplus[-1])
        cost -= take
        surplus[-1] -= take

        if not taken:
            taken = True
            cnt += 1

        if surplus[-1] == 0:
            surplus.pop()
            taken = False

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

dp = [-1] * n
dp[0] = 0

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

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

print(dp[n-1])

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

dp = [-1] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [-1] * n
dp[0] = 0

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

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

print(dp[n-1])

Fixed submission:
import sys

data = sys.stdin.readlines()

n, k = list(map(int, data[0].split()))
h = list(map(int, data[1].split()))

dp = [-1] * n
dp[0] = 0

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

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

print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n, w = list(map(int, raw_input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, raw_input().split()))
    weights.append(wi)
    values.append(vi)

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):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])

Fixed submission:
n, w = list(map(int, raw_input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, raw_input().split()))
    weights.append(wi)
    values.append(vi)

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):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])

Buggy python submission (verdict: Time Limit Exceeded):
n, w = list(map(int, input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, input().split()))
    weights.append(wi)
    values.append(vi)

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):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])

Fixed submission:
n, w = list(map(int, raw_input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, raw_input().split()))
    weights.append(wi)
    values.append(vi)

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):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])
Buggy python submission (verdict: Runtime Error):
h, w = list(map(int, input().split()))
m = 1000000007

grid = [input() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
dp[0][0] = 1

for y in range(h):
    for x in range(w):
        if grid[y][x] == ".":
            if y > 0:
                dp[y][x] += dp[y-1][x]
            if x > 0:
                dp[y][x] += dp[y][x-1]

            dp[y][x] %= m

print(dp[h-1][w-1])

Fixed submission:
h, w = list(map(int, input().split()))
m = 1000000007

grid = [input() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
dp[0][0] = 1

for y in range(h):
    for x in range(w):
        if grid[y][x] == ".":
            if y > 0:
                dp[y][x] += dp[y-1][x]
            if x > 0:
                dp[y][x] += dp[y][x-1]

            dp[y][x] %= m

print(dp[h-1][w-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(float, input().split()))

dp = [[0]*(i+2) for i in range(n)]
dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(1, n):
    for j in range(i+2):
        if j < i+1:
            dp[i][j] += dp[i-1][j]*(1-p[i])
        if j > 0:
            dp[i][j] += dp[i-1][j-1] * p[i]

print(sum(dp[n-1][(n//2)+1:]))

Fixed submission:
n = int(raw_input())
p = list(map(float, raw_input().split()))

dp = [[0]*(i+2) for i in range(n)]
dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(1, n):
    for j in range(i+2):
        if j < i+1:
            dp[i][j] += dp[i-1][j]*(1-p[i])
        if j > 0:
            dp[i][j] += dp[i-1][j-1] * p[i]

print(sum(dp[n-1][(n//2)+1:]))
Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
cnt = 0

def replace(match):
    global cnt
    if (match.group(1) == None):
        n = len(match.group(0))//2
        w = ["W" for i in range(n)]
        b = ["B" for i in range(n)]
        res = w + b
        cnt += n*(n+1)//2
    else:
        res = ["B" for i in range(len(match.group(1)) - 1)]
        res.insert(0, "W")
        cnt += len(match.group(1)) - 1

    return "".join(res)

while True:
    result = re.subn('(B{2,}W)|(BW)+', replace, s)

    if result[1] == 0:
        print(cnt)
        break
    else:
        s = result[0]

Fixed submission:
s = input()

b = 0
c = 0
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        c += b

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import re
s = input()
replaced = -1
c = 0

while replaced != 0:
    s, replaced = re.subn("BW", "WB", s)
    c += replaced

print(c)

Fixed submission:
s = input()

b = 0
c = 0
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        c += b

print(c)
Buggy python submission (verdict: Runtime Error):
k, s = list(map(int, input().split()))

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

primes = list(factors.keys())
exp = [0] * len(primes)
upper = s/k
ans = 1

while exp[0] <= factors[primes[0]]:
    num = 1
    for i in range(len(primes)):
        num *= pow(primes[i], exp[i])

    if num == upper:
        ans = num
        break
    elif num < upper:
        ans = max(ans, num)

    index = len(primes)-1
    done = False
    while not done:
        exp[index] += 1
        if exp[index] > factors[primes[index]]:
            if index == 0:
                break
            else:
                exp[index] = 0
                index -= 1
        else:
            done = True

print(ans)

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

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

if len(factors) == 0:
    print(1)
else:
    primes = list(factors.keys())
    exp = [0] * len(primes)
    upper = s/k
    ans = 1

    while exp[0] <= factors[primes[0]]:
        num = 1
        for i in range(len(primes)):
            num *= pow(primes[i], exp[i])

        if num == upper:
            ans = num
            break
        elif num < upper:
            ans = max(ans, num)

        index = len(primes)-1
        done = False
        while not done:
            exp[index] += 1
            if exp[index] > factors[primes[index]]:
                if index == 0:
                    break
                else:
                    exp[index] = 0
                    index -= 1
            else:
                done = True

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


first = {}
second = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in first:
            first[v[i]] += 1
        else:
            first[v[i]] = 1
    else:
        if v[i] in second:
            second[v[i]] += 1
        else:
            second[v[i]] = 1

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] > s2[2]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])

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

first = {}
second = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in first:
            first[v[i]] += 1
        else:
            first[v[i]] = 1
    else:
        if v[i] in second:
            second[v[i]] += 1
        else:
            second[v[i]] = 1

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] + s[1] > f[1] + s2[1]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])
Buggy python submission (verdict: Time Limit Exceeded):
n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

diff = max(max(xi) - x, x - min(xi))

for d in range(diff, 1, -1):
    xd = x%d
    sol = True

    for xval in xi:
        if ((xval % d) - xd)%d != 0:
            sol = False
            break

    if sol:
        print(d)
        break

Fixed submission:
n, x = list(map(int, input().split()))
xi = list(map(int, input().split()))

xi = [abs(xval - x) for xval in xi]

def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return gcd(b, a%b)

res = xi[0]
for i in range(1, len(xi)):
    res = gcd(res, xi[i])

print(res)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

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

pos = bisect_left(x, 0)
if x[pos] == 0:
    k -= 1
else:
    x.insert(pos, 0)

l = pos
r = pos+k

if r >= len(x):
    diff = r-len(x) + 1
    l -= diff
    r -= diff

ans = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])

while r >= pos:
    if l < 0:
        break

    dist = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])
    if dist < ans:
        ans = dist

    l -= 1
    r -= 1

print(ans)

Fixed submission:
from bisect import bisect_left

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

pos = bisect_left(x, 0)
if pos < len(x) and x[pos] == 0:
    k -= 1
else:
    x.insert(pos, 0)

l = pos
r = pos+k

if r >= len(x):
    diff = r-len(x) + 1
    l -= diff
    r -= diff

ans = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])

while r >= pos:
    if l < 0:
        break

    dist = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])
    if dist < ans:
        ans = dist

    l -= 1
    r -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
index = a.index(1)
cnt = 0

if (n==k):
    print(1)
else:
    if index <= (k - 1):
        cnt += 1
        i = k - 1
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1
    elif index >= (n - k):
        cnt += 1
        i = n - k
        while i >= 1:
            i -= (k-1)
            cnt += 1
    else:
        i = index
        while i >= 1:
            i -= (k-1)
            cnt += 1

        i = index
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1

    print(cnt)

Fixed submission:
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

print(math.ceil((n-1)/(k-1)))
Buggy python submission (verdict: Runtime Error):
N = int(input().remove(" ", ""))

print("Yes" if round(N**0.5)**2 == N else "No")

Fixed submission:
N = int(input().replace(" ", ""))
 
print("Yes" if round(N**0.5)**2 == N else "No")
Buggy python submission (verdict: Runtime Error):
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x":
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x":
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)

Fixed submission:
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x" and l < len(s)-1:
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x" and r > 0:
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [False] * int(1e9)

cnt = 0
for i in range(n):
    ai = int(input()) - 1
    a[ai] = not a[ai]

    if a[ai]:
        cnt += 1
    else:
        cnt -= 1

print(cnt)

Fixed submission:
n = int(input())
a = {}

cnt = 0
for i in range(n):
    ai = int(input()) - 1

    if ai in a:
        cnt -= 1
        del a[ai]
    else:
        cnt += 1
        a[ai] = 1

print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [False] * 100000

cnt = 0
for i in range(n):
    ai = int(input()) - 1
    a[ai] = not a[ai]

    if a[ai]:
        cnt += 1
    else:
        cnt -= 1

print(cnt)

Fixed submission:
n = int(input())
a = {}

cnt = 0
for i in range(n):
    ai = int(input()) - 1

    if ai in a:
        cnt -= 1
        del a[ai]
    else:
        cnt += 1
        a[ai] = 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 == 1:
    b.reverse()

print(" ".join(map(str, b)))

Fixed submission:
from collections import deque
n = int(input())
a = list(map(int, input().split()))

b = deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 == 1:
    b.reverse()

print(" ".join(map(str, b)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
buttons = [int(input()) for i in range(N)]
visited = [1]

cur = 1
count = 0
for i in range(N):
    cur = buttons[cur-1]
    count += 1

    if cur in visited:
        print(-1)
        exit()

    visited.append(cur)

    if cur == 2:
        print(count)
        exit()

print(-1)

Fixed submission:
N = int(input())
buttons = [int(input()) for i in range(N)]

cur = 1
for i in range(N):
    cur = buttons[cur-1]

    if cur == 2:
        print(i+1)
        exit()

print(-1)
Buggy python submission (verdict: Runtime Error):
if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break

Fixed submission:
n = int(input())
s = input()
t = input()

if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break