alexjercan/bugnet huggingface dataset:
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

S = deque(input())
Q = int(input())
inversion_flag = False
for _ in range(Q):
    query_list = list(input().split())
    if query_list[0] == "1":
        inversion_flag = not inversion_flag
        continue
    C = query_list[2]
    if query_list[1] == "2":
        if inversion_flag:
            S.appendleft(C)
        else:
            S.append(C)
    else:
        if inversion_flag:
            S.append(C)
        else:
            S.appendleft(C)

S = list(S)
if inversion_flag:
    print(*S[::-1], sep="")
else:
    print(*S, sep="")


Error: TLE

Fixed submission:

S = list(input())
Q = int(input())
inversion_flag = False
for _ in range(Q):
    query_list = list(input().split())
    if query_list[0] == "1":
        inversion_flag = not inversion_flag
        continue
    C = query_list[2]
    if query_list[1] == "2":
        if inversion_flag:
            S.insert(0, C)
        else:
            S.append(C)
    else:
        if inversion_flag:
            S.append(C)
        else:
            S.insert(0, C)

if inversion_flag:
    print(*S[::-1], sep="")
else:
    print(*S, sep="")
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    query = [None] * Q
    for i in range(Q):
        query[i] = input().split()

    prefix = []
    surfix = []
    is_reversed = False
    for q in query:
        if q[0] == "1":
            is_reversed = not is_reversed
        else:
            F, C = q[1], q[2]
            if F == "1":
                if is_reversed:
                    surfix.append(C)
                else:
                    prefix.append(C)
            else:
                if is_reversed:
                    prefix.append(C)
                else:
                    surfix.append(C)

    ans = "".join(["".join(prefix)[::-1], S, "".join(surfix)])
    if is_reversed:
        ans = ans[::-1]

    print(ans)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    query = [None] * Q
    for i in range(Q):
        query[i] = input().split()

    ans = S
    is_reversed = False
    for q in query:
        if int(q[0]) == 1:
            is_reversed = not is_reversed
        else:
            F, C = int(q[1]), q[2]
            if F == 1:
                if is_reversed:
                    ans = "".join([ans, C])
                else:
                    ans = "".join([C, ans])
            else:
                if is_reversed:
                    ans = "".join([C, ans])
                else:
                    ans = "".join([ans, C])

    if is_reversed:
        ans = ans[::-1]

    print(ans)


if __name__ == "__main__":
    main()
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque


S = deque(input())
Q = int(input())
reverse_count = 0

for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        reverse_count += 1
    else:
        F, C = Query[1], Query[2]
        if F == "1":
            if reverse_count % 2 == 0:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if reverse_count % 2 == 0:
                S.append(C)
            else:
                S.appendleft(C)

if reverse_count % 2 == 1:
    S.reverse()
print("".join(S))


Error: TLE

Fixed submission:

from collections import deque


S = deque(input())
Q = int(input())

for _ in range(Q):
    Query = input().split()
    if Query[0] == "1":
        S = deque(reversed(S))
    else:
        F, C = Query[1], Query[2]
        if F == "1":
            S.appendleft(C)
        else:
            S.append(C)

print("".join(S))
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

s = input()
q = int(input())

s = deque(s)

rev = 0
for _ in range(q):
    que = input()
    if que[0] == "1":
        rev ^= 1

    else:
        t, f, c = que.split()
        if rev:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)

        else:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)

s = list(s)
if rev:
    print(*s[::-1], sep="")
else:
    print(*s, sep="")


Error: TLE

Fixed submission:

s = input()
q = int(input())

rev = 0
for _ in range(q):
    que = input()
    if que[0] == "1":
        rev ^= 1

    else:
        t, f, c = que.split()
        if rev:
            if f == "1":
                s = s + c
            else:
                s = c + s

        else:
            if f == "1":
                s = c + s
            else:
                s = s + c

if rev:
    print(s[::-1])
else:
    print(s)
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3
from collections import deque

s = input()
q = int(input())
deq = deque(s)
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        f = int(f) - 1
        if cur ^ f:
            deq.appendleft(c)
        else:
            deq.append(c)
ans = ""
while len(deq) > 0:
    ans += deq.popleft() if cur else deq.pop()
print(ans)


Error: TLE

Fixed submission:

#!/usr/bin/env python3
s = input()
q = int(input())
li = ["", s]
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        if f == "1":
            li[cur ^ 1] += c
        else:
            li[cur] += c
ans = li[0][::-1] + li[1]
if cur == 0:
    ans = ans[::-1]
print(ans)
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

S = list(input())
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
mae = []
ato = []
is_reverse = False
for q in query:
    if q[0] == "1":
        is_reverse = not is_reverse
    else:
        if is_reverse:
            if q[1] == "2":
                mae.append(q[2])
            else:
                ato.append(q[2])
        else:
            if q[1] == "1":
                mae.append(q[2])
            else:
                ato.append(q[2])
mae.reverse()
mae.extend(S)
mae.extend(ato)
if is_reverse:
    mae.reverse()
    print("".join(mae))
else:
    print("".join(mae))


Error: TLE

Fixed submission:

S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
is_reverse = False
for q in query:
    if q[0] == "1":
        is_reverse = not is_reverse
    else:
        if is_reverse:
            if q[1] == "2":
                S = q[2] + S
            else:
                S += q[2]
        else:
            if q[1] == "1":
                S = q[2] + S
            else:
                S += q[2]

if is_reverse:
    print(S[::-1])
else:
    print(S)
Problem p02756 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque


def main():
    s = input()
    q = int(input())
    d = deque(s)
    is_reversed = False

    for _ in range(q):
        query = list(input().split())

        if query[0] == "1":
            if is_reversed:
                is_reversed = False
            else:
                is_reversed = True

        elif query[0] == "2":
            if query[1] == "1":
                if is_reversed:
                    d.append(query[2])
                else:
                    d.appendleft(query[2])
            elif query[1] == "2":
                if is_reversed:
                    d.appendleft(query[2])
                else:
                    d.append(query[2])

    if is_reversed:
        print(*(list(d)[::-1]), sep="")
    else:
        print(*list(d), sep="")


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

def main():
    s = input()
    q = int(input())

    for _ in range(q):
        query = list(input())
        if query[0] == "1":
            s = s[::-1]
        elif query[0] == "2":
            if query[2] == "1":
                s = query[4] + s
            elif query[2] == "2":
                s = s + query[4]

    print(s)


if __name__ == "__main__":
    main()
Problem p02757 (Python) — buggy submission, verdict: Time Limit Exceeded

n, p = map(int, input().split())
s = input()

ans = 0
if p == 2:
    for i, char in enumerate(s):
        if int(char) % 2 == 0:
            ans += i + 1
    print(ans)

elif p == 5:
    for i, char in enumerate(s):
        if int(char) % 5 == 0:
            ans += i + 1
    print(ans)

else:
    a = [0] * (n + 1)
    for i in range(n):
        a[i + 1] = a[i] + int(s[n - i - 1]) * pow(10, i, p)
        a[i + 1] %= p
    memo = {}
    for i in range(n + 1):
        if a[i] not in memo:
            memo[a[i]] = 1
        else:
            memo[a[i]] += 1
    for i in memo:
        ans += memo[i] * (memo[i] - 1) // 2
    print(ans)


Error: TLE

Fixed submission:

import copy

n, p = list(map(int, input().split()))
s = input()


memo = {}
ans = 0
for i in range(n):
    memo2 = {int(s[i]) % p: 1}
    for j in memo:
        if (j * 10 + int(s[i])) % p not in memo2:
            memo2[(j * 10 + int(s[i])) % p] = memo[j]
        else:
            memo2[(j * 10 + int(s[i])) % p] += memo[j]
    memo = copy.deepcopy(memo2)
    if 0 in memo:
        ans += memo[0]
print(ans)
Problem p02757 (Python) — buggy submission, verdict: Time Limit Exceeded

n, p = map(int, input().split())

s = list(input())

ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    d = [0] * (n + 1)
    ten = 1
    for i in range(n - 1, -1, -1):
        a = int(s[i]) * ten % p
        ten *= 10
        ten %= p
        d[i - 1] = (d[i] + a) % p
    cnt = [0] * p
    for i in range(n, -1, -1):
        ans += cnt[d[i]]
        cnt[d[i]] += 1

print(ans)


Error: TLE

Fixed submission:

n, p = map(int, input().split())
s = list(input())

ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    d = [0] * (n + 1)
    for i in range(n - 1, -1, -1):
        a = (int(s[i]) * 10 ** ((n - 1) - i)) % p
        d[i - 1] = (d[i] + a) % p
    cnt = [0] * p
    for i in range(n, -1, -1):
        ans += cnt[d[i]]
        cnt[d[i]] += 1

print(ans)
Problem p02757 (Python) — buggy submission, verdict: Runtime Error

N, P = map(int, input().split())
num = input().strip()
ans = 0
if P == 2:
    for idx, nu in enumerate(num):
        if nu in "24680":
            ans += idx + 1
elif P == 5:
    for idx, nu in enumerate(num):
        if nu in "50":
            ans += idx + 1
else:
    nnum = [0] * N
    base = 1
    for i in range(N - 1, -1, -1):
        nnum[i] = (int(num[i]) * base) % P
        base = (base * 10) % P
    for i in range(1, N):
        nnum[i] = (nnum[i] + nnum[i - 1]) % P
    dp = [0] * P
    for i in range(N):
        if nnum[i] == 0:
            ans += 1 + dp[nnum[i]]
        else:
            ans += dp[nnum[i]]
        dp[nnum[i]] += 1
print(ans)


Error: 0

Fixed submission:

N, P = map(int, input().split())
num = input().strip()
dp = [0] * N
ans = 0
last = 0
for i in range(N):
    last = (10 * last + int(num[i])) % P
    if last == 0:
        ans += 1 + dp[last]
        dp[last] += 1
    else:
        ans += dp[last]
        dp[last] += 1
print(ans)
Problem p02757 (Python) — buggy submission, verdict: Runtime Error

N, P = map(int, input().split())
S = input()
now = 0
hyou = [0] * P
hyou[0] = 1
cnt = 1
ans = 0

if P == 2 or P == 5:
    for i, t in enumerate(S[::-1]):
        temp = int(t)
        if temp % P == 0:

            ans += N - i
    print(ans)
    exit()

for i, t in enumerate(S[::-1]):
    now = (now + int(t) * pow(10, i, P)) % P
    ans += hyou[now]
    hyou[now] += 1

print(ans)


Error: 0

Fixed submission:

# li = [[0] * 4 for i in range(3)]

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

N, P = map(int, input().split())

S = input()


memo = {}


def dfs(n):
    # print(n)
    if n in memo:
        return memo[n]

    i = n + 1
    while i <= N:
        temp_int = int(S[n:i])
        # print(temp_int)
        if temp_int % P == 0:
            memo[n] = 1 + dfs(i)
            return memo[n]

        i += 1
    return 0


ans = 0
for i in range(N):
    temp = dfs(i)
    ans += temp

print(ans)
Problem p02759 (Python) — buggy submission, verdict: Runtime Error

x = int(input())
if x % 2 == 0:
    print(x // 2)
else:
    print(x // 2 + 1)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s333296086.py", line 4, in <module>
    print(int(input()) // 2 + 1)
EOFError: EOF when reading a line


Fixed submission:

if int(input()) % 2 == 0:
    print(int(input()) // 2)
else:
    print(int(input()) // 2 + 1)
Problem p02759 (Python) — buggy submission, verdict: Runtime Error

import math

N = int(input())

print(math.ceil(N / 2))


Error: ValueError: not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s176257737.py", line 13, in <module>
    N, X = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)


Fixed submission:

N, X = 6, 1
ARR = [1, 6, 1, 2, 0, 4]

N, X = 3, 3
ARR = [2, 2, 2]

N, X = 5, 9
ARR = [3, 1, 4, 1, 5]

N, X = 2, 0
ARR = [5, 5]

N, X = map(int, input().split())

ARR = list(map(int, input().split()))


def calculate(n, x, arr):
    result = 0
    for i in range(1, n):
        sSum = arr[i - 1] + arr[i]
        if sSum <= x:
            continue

        diff = sSum - x

        if diff <= arr[i]:
            arr[i] -= diff
            result += diff
        else:
            result += diff
            arr[i] = 0

    print(result)


calculate(N, X, ARR)
Problem p02759 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
print((n + 1) // 2)


Error: TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s809156396.py", line 3, in <module>
    if n % 2 == 0:
TypeError: not all arguments converted during string formatting


Fixed submission:

n = input()
paper = 0
if n % 2 == 0:
    paper = n / 2
else:
    paper = n / 2 + 1
print(paper)
Problem p02759 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3


def main():
    N = int(input())
    print(-(-N // 2))


main()


Error: TypeError: bad operand type for unary -: 'map'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s289619736.py", line 9, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s289619736.py", line 6, in main
    print(-(-N // 2))
TypeError: bad operand type for unary -: 'map'


Fixed submission:

#!/usr/bin/env python3


def main():
    N = map(int, open(0).read().split())
    print(-(-N // 2))


main()
Problem p02760 (Python) — buggy submission, verdict: Runtime Error

bingo = [input().split() for _ in range(3)]

n = int(input())

nums = [input() for _ in range(n)]

check = [[] for _ in range(3)]

for i in range(3):
    for j in range(3):
        if bingo[i][j] in nums:
            check[i].append(True)
        else:
            check[i].append(False)

ANS = "No"

for i in range(3):
    if (check[i][0]) and (check[i][1]) and (check[i][2]):
        ANS = "Yes"
for i in range(3):
    if (check[0][i]) and (check[1][i]) and (check[2][i]):
        ANS = "Yes"
if (check[0][0]) and (check[1][1]) and (check[2][2]):
    ANS = "Yes"
if (check[0][2]) and (check[1][1]) and (check[2][0]):
    ANS = "Yes"

print(ANS)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02760/Python/s062828081.py", line 11, in <module>
    check[i].append(False)
IndexError: list index out of range


Fixed submission:

bingo = [input().split() for _ in range(3)]

n = int(input())

nums = [[] for _ in range(3)]

check = list()

for i in range(3):
    for j in range(3):
        check[i].append(False)
        if bingo[i][j] in nums:
            check[i][j] = True

ANS = "No"

for i in range(3):
    if (check[i][0]) and (check[i][1]) and (check[i][2]):
        ANS = "Yes"
for i in range(3):
    if (check[0][i]) and (check[1][i]) and (check[2][i]):
        ANS = "Yes"
if (check[0][0]) and (check[1][1]) and (check[2][2]):
    ANS = "Yes"
if (check[0][2]) and (check[1][1]) and (check[2][0]):
    ANS = "Yes"

print(ANS)
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())


def answer():
    digs = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        if digs[s] not in {c, -1}:
            return -1
        digs[s] = c
    if digs[0] == -1:
        digs[0] = int(N > 1)
    elif digs[0] == 0 and N > 1:
        return -1
    for i in range(1, N):
        if digs[i] == -1:
            digs[i] = 0
    return "".join(map(str, digs))


print(answer())


Error: 0

Fixed submission:

N, M = map(int, input().split())


def answer():
    digs = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        if s == 0 and c == 0:
            return -1
        if digs[s] not in {c, -1}:
            return -1
        digs[s] = c
    if digs[0] == -1:
        digs[0] = 1
    if digs[1] == -1:
        digs[1] = 0
    if digs[2] == -1:
        digs[2] = 0
    return "".join(map(str, digs))


print(answer())
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
if M == 0:
    if N == 1:
        print(0)
    else:
        print("1" + "0" * (N - 1))
    exit()

dic = {}
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit()
    n = dic.get(s)
    if n is not None and n != c:
        print(-1)
        exit()
    dic[s] = c

lst = [0] * N
for k, v in dic.items():
    lst[k - 1] = v

if len(lst) != 1 and lst[0] == 0:
    lst[0] = 1

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


Error: 0

Fixed submission:

N, M = map(int, input().split())
lst = [0] * N
if M == 0 and N != 1:
    lst[0] = 1
else:
    dic = {}
    for _ in range(M):
        s, c = map(int, input().split())
        n = dic.get(s)
        if n is not None and n != c:
            print(-1)
            exit()
        dic[s] = c

for k, v in dic.items():
    lst[k - 1] = v

if N != 1 and lst[0] == 0:
    print(-1)
    exit()

if len(lst) != 0 and lst[0] == 0:
    lst[0] = 1

print("".join(map(str, lst)))
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

for x in range(1000):
    ok = True
    s = str(x)
    if len(s) != n:
        continue
    if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
        continue
    print(x)
    exit(0)

print(-1)


Error: 1

Fixed submission:

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

for x in range(1000):
    ok = True
    s = str(x)
    if len(s) != n:
        continue
    if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
        continue
    print(x)
    exit(1)

print(-1)
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())

K = [0, -1, -1, -1]
ans = -1
for i in range(M):
    s, c = map(int, input().split())
    if not N == 1 and s == 1 and c == 0:
        break
    if K[s] >= 0 and not K[s] == c:
        break
    K[s] = c
else:
    if K[1] == -1 and N >= 2:
        K[1] = 1
    if K[1] == -1 and N == 1:
        K[1] = 0
    if K[2] == -1:
        K[2] = 0
    if K[3] == -1:
        K[3] = 0

    ans = "".join(map(str, K[1 : N + 1]))

print(ans)


Error: WA

Fixed submission:

N, M = map(int, input().split())

S = [0] * M
C = [0] * M

for i in range(M):
    S[i], C[i] = input().split()

ans = -1
for i in range(10 * (N - 1) + 1, 10 * N):
    for s, c in zip(S, C):
        if not str(i)[int(s) - 1] == c:
            break
    else:
        ans = i
        break
    if not ans == -1:
        break
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if int(t[s - 1]) != c:
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)


Error: WA

Fixed submission:

N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if t[int(s)] != int(c):
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

import math

n, m = map(int, input().split(" "))

ans = list([0 for _ in range(n)])

err = False
for i in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        if n == 1:
            print(0)
            exit()
        err = True
    elif ans[s - 1] == 0:
        ans[s - 1] = c
    elif not ans[s - 1] == c:
        err = True

if ans[0] == 0:
    ans[0] = 1

if (n == 1 and ans[0] == 0) or (n == 1 and m == 0):
    print(0)
    exit()

if err:
    print(-1)
    exit()

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


Error: 0

Fixed submission:

import sys

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if a[0] == 1 and a[1] == 0:
        print(-1)
        sys.exit()
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)
Problem p02761 (Python) — buggy submission, verdict: Runtime Error

def main():
    N, M = map(int, input().split())
    P = {tuple(map(int, input().split())) for _ in range(M)}
    P = sorted(P)
    ans = [0 for _ in range(N)]

    if N == 1 and M == 0:
        print(0)
        return

    if N == 2 and M == 0:
        print(10)
        return

    if N == 3 and M == 0:
        print(100)
        return

    if N > 1 and (1, 0) in P:
        print(-1)
        return

    if N > 1 and P[0][0] != 1:
        ans[0] = 1

    for i in range(len(P) - 1):
        if P[i][0] == P[i + 1][0]:
            print(-1)
            return

    for p in P:
        ans[p[0] - 1] = p[1]

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


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

def main():
    N, M = map(int, input().split())
    P = {tuple(map(int, input().split())) for _ in range(M)}
    P = sorted(P)
    ans = [0 for _ in range(N)]

    if N > 1 and (1, 0) in P:
        print(-1)
        return

    if N > 1 and P[0][0] != 1:
        ans[0] = 1

    for i in range(len(P) - 1):
        if P[i][0] == P[i + 1][0]:
            print(-1)
            return

    for p in P:
        ans[p[0] - 1] = p[1]

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


if __name__ == "__main__":
    main()