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

Fixed submission:
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Buggy submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Buggy submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))

Buggy submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 2N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))




    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))
Problem p03112 (python)

Fixed submission:
import bisect
A, B, Q =  map(int, (input().split(' ')))
power = 10**11+1
a_list = [-power]+[int(input()) for _ in range(A)] + [power]
b_list = [-power]+[int(input()) for _ in range(B)] + [power]
for _ in range(Q):
    x = int(input())
    right_s = abs(x - a_list[bisect.bisect_left(a_list, x)])
    right_t = abs(x - b_list[bisect.bisect_left(b_list, x)])
    left_s = abs(x - a_list[bisect.bisect_right(a_list, x)-1])
    left_t = abs(x - b_list[bisect.bisect_right(b_list, x)-1])
    print(
            min(
                max(left_t, left_s),
                max(right_t, right_s),
                left_t + (left_t + right_s),
                left_s + (left_s + right_t),
                right_t + (right_t + left_s),
                right_s + (right_s + left_t)
            )
    )

Buggy submission (verdict: Runtime Error):
import bisect
A, B, Q =  map(int, (input().split(' ')))

a_list = [-100001]+[int(input()) for _ in range(A)] + [100001]
b_list = [-100001]+[int(input()) for _ in range(B)] + [100001]
for _ in range(Q):
    x = int(input())
    right_s = abs(x - a_list[bisect.bisect_left(a_list, x)])
    right_t = abs(x - b_list[bisect.bisect_left(b_list, x)])
    left_s = abs(x - a_list[bisect.bisect_right(a_list, x)-1])
    left_t = abs(x - b_list[bisect.bisect_right(b_list, x)-1])
    print(
            min(
                max(left_t, left_s),
                max(right_t, right_s),
                left_t + (left_t + right_s),
                left_s + (left_s + right_t),
                right_t + (right_t + left_s),
                right_s + (right_s + left_t)
            )
    )
Problem p03147 (python)

Fixed submission:
N = int(input())
h_list = list(map(int, input().split(' ')))


def mizuyari(h_list, l, r):
    num_mizuyari = min(h_list[l:r+1])
    h_list = [h - num_mizuyari if l <= x and x <= r else h for x, h in enumerate(h_list)]
    zero_posi = h_list[l:].index(0) + l
    if l == zero_posi:
        first_non_zero_posi = [x for x, h in enumerate(h_list) if h != 0]
        if not first_non_zero_posi:
            print(sum_mizuyari + num_mizuyari)
            exit()
        l = first_non_zero_posi[0]
        if list(range(l, len(h_list))) == first_non_zero_posi:
            return h_list, num_mizuyari, l, len(h_list)
        zero_posi = h_list[l:].index(0) + l
    new_r = zero_posi - 1
    return h_list, num_mizuyari, l, new_r
l = 0
r = len(h_list) - 1
sum_mizuyari = 0
while True:
    h_list, num_mizuyari, l, r = mizuyari(h_list, l, r)
    sum_mizuyari += num_mizuyari

Buggy submission (verdict: Runtime Error):
N = int(input())
h_list = list(map(int, input().split(' ')))


def mizuyari(h_list, l, r):
    import pdb;pdb.set_trace()
    num_mizuyari = min(h_list[l:r+1])
    h_list = [h - num_mizuyari if l <= x and x <= r else h for x, h in enumerate(h_list)]
    zero_posi = h_list[l:].index(0) + l
    if l == zero_posi:
        first_non_zero_posi = [x for x, h in enumerate(h_list) if h != 0]
        if not first_non_zero_posi:
            print(sum_mizuyari + num_mizuyari)
            exit()
        l = first_non_zero_posi[0]
        if list(range(l, len(h_list))) == first_non_zero_posi:
            return h_list, num_mizuyari, l, len(h_list)
        zero_posi = h_list[l:].index(0) + l
    new_r = zero_posi - 1
    return h_list, num_mizuyari, l, new_r
l = 0
r = len(h_list) - 1
sum_mizuyari = 0
while True:
    h_list, num_mizuyari, l, r = mizuyari(h_list, l, r)
    sum_mizuyari += num_mizuyari
Problem p03148 (python)

Fixed submission:
from collections import Counter
N, K =  map(int, (input().split(' ')))
sushi = [tuple(map(int, input().split(' '))) for _ in range(N)]
all_sushi = sorted(sushi, key=lambda x: -x[1])
default_sushi = all_sushi[:K]
amari = all_sushi[K:]
len_amari = len(amari)
counter = Counter([i[0] for i in default_sushi])
result = []
def calc_value(sushi):
    return sum([i[1] for i in sushi]) + len(counter)**2

fs = []
def change_sushi(sushi):
    oishisa = sum([i[1] for i in sushi])
    fs.append(oishisa + len(counter)**2)
    amari_index = 0
    for s in sushi[::-1]:
        if counter[s[0]] >= 2:
            while amari_index < len_amari:
                a = amari[amari_index]
                amari_index += 1
                if a[0] not in counter:
                    counter[s[0]] -= 1
                    counter[a[0]] += 1
                    oishisa = oishisa - s[1] + a[1]
                    fs.append(oishisa + len(counter)**2)
                    break
    print(max(fs))
    exit()
            
    
def get_sushi(sushi):
    #result.append(calc_value(sushi))
    changed_sushi = change_sushi(sushi)
    #if not changed_sushi:
        #print(max(result))
        #return
    #get_sushi(changed_sushi)

get_sushi(default_sushi)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, K =  map(int, (input().split(' ')))
sushi = [tuple(map(int, input().split(' '))) for _ in range(N)]
all_sushi = sorted(sushi, key=lambda x: -x[1])
default_sushi = all_sushi[:K]
amari = all_sushi[K:]
counter = Counter([i[0] for i in default_sushi])
result = []
def calc_value(sushi):
    return sum([i[1] for i in sushi]) + len(counter)**2

fs = []
def change_sushi(sushi):
    oishisa = sum([i[1] for i in sushi])
    fs.append(oishisa + len(counter)**2)
    amari_index = 0
    for s in sushi[::-1]:
        if counter[s[0]] >= 2:
            while True:
                a = amari[amari_index]
                amari_index += 1
                if a[0] not in counter:
                    counter[s[0]] -= 1
                    counter[a[0]] += 1
                    oishisa = oishisa - s[1] + a[1]
                    fs.append(oishisa + len(counter)**2)
                    break
    print(max(fs))
    exit()
            
    
def get_sushi(sushi):
    #result.append(calc_value(sushi))
    changed_sushi = change_sushi(sushi)
    #if not changed_sushi:
        #print(max(result))
        #return
    #get_sushi(changed_sushi)

get_sushi(default_sushi)
Problem p03294 (python)

Fixed submission:
import fractions
import operator
from functools import reduce
N = int(input())
a_list = list(map(int, input().split(' ')))

def lcm_list(numbers):
    return reduce(operator.mul, numbers) // reduce(fractions.gcd, numbers)

m = lcm_list(a_list) - 1

print(sum([m % a for a in a_list]))

Buggy submission (verdict: Runtime Error):
import math
import operator
from functools import reduce
N = int(input())
a_list = list(map(int, input().split(' ')))

def lcm_list(numbers):
    return reduce(operator.mul, numbers) // reduce(math.gcd, numbers)

m = lcm_list(a_list) - 1

print(sum([m % a for a in a_list]))
Problem p02683 (python)

Fixed submission:
n,m,x=map(int,input().split())
a=[]
ans=-1
t=[0]*(m+1)
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(2 ** n):
    for j in range(n):
        if (i >> j) & 1:
            for lnd,l in enumerate(a[j]):
                t[lnd]+=l
    if ans==-1 or ans > t[0]:
        if min(t[1:m+1]) >= x:
            ans = t[0]
    t=[0]*(m+1)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
a=[]
ans=-1
t=[0]*(m+1)
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(2 ** n):
    for j in range(n):
        if (i >> j) & 1:
            for lnd,l in enumerate(a[j]):
                t[lnd]+=l
    if ans==-1 or ans > t[0]:
        if min(t[1:m]) >= x:
            ans = t[0]
    t=[0]*(m+1)
print(ans)
Problem p03136 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
s=max(l)
l.sort()
l.remove(s)
if sum(l[0:len(l)+1]) > s:
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
s=max(l)
l.sort()
l.remove(s)
if sum(s[0:len(s)+1]) > s:
 print("Yes")
else:
 print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input(),split()))
s=max(l)
l.sort()
l.remove(s)
if sum(s[0:len(s)+1]) > s:
 print("Yes")
else:
 print("No")
Problem p04043 (python)

Fixed submission:
l=list(map(int,input().split()))
if l.count(5) == 2 and 7 in l:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print("".join(s))
Problem p04044 (python)

Fixed submission:
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print("".join(s))

Buggy submission (verdict: Runtime Error):
vn,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print("".join(s))
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())
p = list(map(int,input().split()))
for i in range(100):
    pFlag = True
    mFlag = True
    for j in range(len(p)):
        if p[j] == x+i:
            pFlag = False
        if p[j] == x-i:
            mFlag = False
    if mFlag:
        a = (-1)* i
        break
    if pFlag:
        a = i
        break
print(x+a)

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
p = list(map(int,input().split()))
for i in range(50):
    pFlag = True
    mFlag = True
    for j in range(len(p)):
        if p[j] == x+i:
            pFlag = False
        if p[j] == x-i:
            mFlag = False
    if mFlag:
        a = (-1)* i
        break
    if pFlag:
        a = i
        break
print(x+a)
Problem p02761 (python)

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

ans = [0 for i in range(n)]

for i in range(m):
    r,s = map(int,input().split())
    if n != 1 and r-1 == 0 and s == 0:
        ans = [-1]
        break
    if ans[r-1] != 0 and ans[r-1] != s:
        ans = [-1]
        break
    ans[r-1] = s
if n != 1 and ans[0] == 0:
    ans[0] = 1
sum = ""
for i in range(len(ans)):
    sum += str(ans[i])
print(sum)

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

ans = [0 for i in range(n)]

for i in range(m):
    r,s = map(int,input().split())
    if r-1 == 0 and s = 0:
        ans = [-1]
        break
    if ans[r-1] != 0 and ans[r-1] != s:
        ans = [-1]
        break
    ans[r-1] = s
if ans[0] == 0:
    ans[0] = 1
sum = ""
for i in range(len(ans)):
    sum += str(ans[i])
print(sum)
Problem p02923 (python)

Fixed submission:
n = int(input())
count = 0
recount = -1
h = list(map(int,input().split()))
for i in range(n-1):
    if h[i] >= h[i + 1]:
        count += 1
    else:
        recount = max(recount,count)
        count = 0
print(max(recount,count))

Buggy submission (verdict: Runtime Error):
n = int(input())
count = 1
rcount = 1
h = list(map(int,input().split()))
for i in range(n-1):
    if h[i] >= h[i + 1]:
        count += 1
    else:
        recount = max(recount,count)
        count = 0
print(max(recount,count))

Buggy submission (verdict: Runtime Error):
n = int(input())
count = 1
rcount = 1
h = list(map(int,input().split()))
for i in range(n-1):
    if h[i] >= h[i + 1]:
        count += 1
    else:
        recount = count
        count = 0
print(max(recount,count))
Problem p02999 (python)

Fixed submission:
x,a = map(int,input().split())
if x < a:
        print(0)
else:
        print(10)

Buggy submission (verdict: Runtime Error):
h,w,x,y = map(int,input().split())
ans1 = (h*w)/2
if h == 2*x and w == 2*y:
    ans2 = 1
else:
    ans2 = 0
print(ans1,ans2)
Problem p03001 (python)

Fixed submission:
h,w,x,y = map(int,input().split())
ans1 = (h*w)/2
if h == 2*x and w == 2*y:
    ans2 = 1
else:
    ans2 = 0
print(ans1,ans2)

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())
first = min(x*h,(w-x)*h)
second =min(y*w,(h-y)*w)
if first == second:
        print(f"{first:6f} 1")
else:
        print(f"{max(first,second):6f} 0")

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())
first = min(x*h,(w-x)*h)
second =min(y*w,(h-y)*w)
if first == second:
        print(f"{float(first)} 0")
else:
        print(f"{float(max(first,second))} 0")
Problem p03035 (python)

Fixed submission:
a,b =map(int,input().split()) 
if a < 6:
        print(0)
elif a< 13:
        print(b//2)
else:
        print(b)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
for i in range(m):
        bb,cc =map(int,input().split())
        b.append(bb)
        c.append(cc)
a.sort()
for i in range(m):
        for j in range(b[i]):
                if a[j] < c[i]:
                        a[j] = c[i]
                elif a[j] >=c[i]:
                        continue
        a.sort()
print(sum(a))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
for i in range(m):
        bb,cc =map(int,input().split())
        b.append(bb)
        c.append(cc)
a.sort()
for i in range(m):
        for j in range(b[i]):
                if a[j] < c[i]:
                        a[j] = c[i]
                a.sort()
print(sum(a))
Problem p03071 (python)

Fixed submission:
A,B = map(int,input().split())
i = 0
X = 0
if(A != B):
    while i <= 1: 
        X += max(A,B)
        i += 1
    print(X-1)
else:
    print(A + B)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
i = 0
X = 0
if(A != B):
    while i <= 1: 
        X += max(A,B)
        i += 1
    print(X-1)
else:
print(A + B)
Problem p03103 (python)

Fixed submission:
n,m = map(int,input().split())
mat = []
for i in range(n):
    mat.append(list(map(int,input().split())))
#ここまで情報のインプット

#基本方針はまだ扱っていない最小のお金を持つ栄養ドリンクをとっていく。
#つまりは値がちいさいものから順に在庫が切れるまで選択するということ。

ans = 0
i = 0
mat.sort()
#値でsortする
while True:
    if m - mat[i][1] > 0:
        ans += mat[i][1]*mat[i][0]
        m -= mat[i][1]
        i += 1
    else:
        ans += mat[i][0] *m
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    P,Y = map(int,input().split())
    a.append(P)
    b.append(Y)
#ここまで情報のインプット

#基本方針はまだ扱っていない最小のお金を持つ栄養ドリンクをとっていく。
#つまりは値がちいさいものから順に在庫が切れるまで選択するということ。

count = 0
ans = 0
i = 0
A = sorted(a)
if n-m < n//2:
    while i < n:
        if m-b[a.index(A[i])] > 0:
            m -= b[a.index(A[i])]
            ans += A[i] * b[a.index(A[i])]
        else:
            ans += A[i]* m
            break
        i+=1
else:
    while i < n:
        if m-b[a.index(A[(i+1)*(-1)])] > 0:
            m -= b[a.index(A[(i+1)*(i-1)])]
            ans += A([i+1)*(-1)] * b[a.index(A[(i+1)*(-1)])]
        else:
            ans += A[(i+1)*(-1)] * m
            break
        i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
2 3
1 32
2 63
1 12
Problem p03294 (python)

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

def gcd(c, b):
    if b == 0:
        return c
    return gcd(b,c%b)

for i in range(n-1):
    ans = ans*a[i+1] // gcd(ans,a[i+1])
sum = 0
for i in range(n):
    sum += (ans-1)%a[i]
print(sum)

Buggy submission (verdict: Runtime Error):
n= int(input())
a =list(map(int,input().split()))
ans = a[0]

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

for i in range(n-1):
    ans = ans*a[i+1] / gcd(ans,a[i+1])
sum = 0
for i in range(n):
    sum += (ans-1)%a[i]
print(int(sum))
Problem p02613 (python)

Fixed submission:
n = int(input())
stat2id = {
  "AC": 0,
  "WA": 1,
  "TLE": 2,
  "RE": 3,
}
id2stat = {i:s for s,i in stat2id.items()}
count = [0 for _ in range(4)]

for i in range(n):
  s = input()
  count[stat2id[s]] += 1
for i, c in enumerate(count):
  print(id2stat[i], "x", c)

Buggy submission (verdict: Runtime Error):
n = int(input())
stat2id = {
  "AC": 0,
  "WA": 1,
  "TLE": 2,
  "RE": 3,
}
id2stat = {i:s for s,i in stat2id.items()}
count = [0 for _ in range(4)]

for i in range(n):
  s = input()
  count[s] += 1
for i, c in enumerate(count):
  print(id2stat[i], "x", c)
Problem p02658 (python)

Fixed submission:
n = int(input())
an = list(map(int, input().split()))
s = 1
flg = False
for a in an:
  s = s * a
  if s > 10**18 or s< 0:
    flg = True
    break
if 0 in an:
  print(0)
elif flg:
  print(-1)
else:
  print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
an = list(map(int, input().split()))
s = 1
flg = False
for a in an:
  s = s * a
  if s > 10**18 or s< 0:
    flg = True
    break
if 0 in s:
  print(0)
elif flg:
  print(-1)
else:
  print(s)
Problem p02690 (python)

Fixed submission:
x = int(input())

flg = False
for a in range(-118, 120):
  for b in range(-118, 120):
    if a**5 - b**5 == x:
      print(a, b)
      flg = True
      break
  if flg:
    break

Buggy submission (verdict: Runtime Error):
a = 0
x = int(input())

while True:
  b = (x-a**5) ** (1/5)
  if b.is_integer() :
    print(a, int(b))
    break
  b = (a**5-x) ** (1/5)
  if b.is_integer() :
    print(a, int(b))
    break
  
  a += 1
Problem p02742 (python)

Fixed submission:
HW = input().split()
H = int(HW[0])
W = int(HW[1])


tmp = H // 2
tmp2 = H - tmp
wt = W // 2
wt2 = W - wt
ans = tmp * wt + tmp2 * wt2

if H == 1:
  ans = 1
elif W == 1:
  ans = 1

print(ans)

Buggy submission (verdict: Runtime Error):
HW = input().split()
H = int(HW[0])
W = int(HW[1])
 
tmp = H // 2
tmp2 = H - tmp
wt = W // 2
wt2 = W - wt
ans = tmp * wt + tmp2 * wt2

if H % 2 == 0:
  h1 = H // 2
  h2 = H // 2
else:
  h1 = H//2 + 1
  h2 = H//2
if W % 2 == 0:
  w1 = W//2
  w2 = W//2
else:
  w1 = W//2+1
  w2 = w//2
  
ans = h1*w1+h2*w2  
print(ans)
Problem p02761 (python)

Fixed submission:
NM = input().split()
N = int(NM[0])
M = int(NM[1])

from collections import defaultdict
sc = defaultdict(lambda: -1)
flg = False
for i in range(M):
  scc = input().split()
  if sc[scc[0]] == -1:
    sc[scc[0]] = scc[1]
  else:
    if scc[0] == "1" and scc[1] == 0 and N != 1:
      flg = True
      break
    elif sc[scc[0]] != scc[1]:
      flg = True
      break
if not flg:
  if N == 1:
    string = ["0"]
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    print(string)
  else:
    string = ["0"]*N
    string[0] = "1"
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    if string == "0"*N:
      print(-1)
    else:
      print(string)

else:
  print("-1")

Buggy submission (verdict: Runtime Error):
NM = input().split()
N = int(NM[0])
M = int(NM[1])

sc = []
flg = False
for i in range(M):
  scc = input().split()
  sc.append([int(scc[0]), int(scc[1])])
  if int(scc[0]) == 1 and int(scc[1]) == 0:
    flg = True
else:
  string = ["0"]*N
  sc.sort(key=lambda x: x[0])
  s = []
  for i in range(M):
    if flg:
      break
    if i != M-1:
      if s and sc[i][0] == s[0][0]:
        s.append(sc[i])
      elif not s:
        s.append(sc[i])
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        s = []
        s.append(sc[i])
    else:
      if sc[i][0] == s[0][0]:
        s.append(sc[i])
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        string[int(sc[i][0])-1] = str(sc[i][1])


if flg:
  print(-1)
else:
  string = "".join(string)
  if string == "0"*N:
    print('-1')
  else:
    print("".join(string))