ZhenlongDai/ACPR huggingface dataset:
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


print(N + 1)


Failing test case input:
2 0
1 1
2 1
1 6
2 1
1 2
0 3
1 4
3 3
2 4
4 4

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
print(count.most_common(1)[0][1])

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque
N, M = map(int, input().split())
G = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].add(b - 1)
    G[b - 1].add(a - 1)
d = [0] * N
Q = deque()
for i in range(N):
    if d[i] != 0:
        continue
    Q.append(i)
    d[i] = 1
    while len(Q) > 0:
        q = Q.popleft()
        for g in G[q]:
            if d[g] != 0:
                continue
            d[q] += 1
            Q.append(g)
print(max(d))

Failing test case input:
10 4
6 1
3 1
5 6
2 6

Expected output:
5


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import deque
N, M = map(int, input().split())
G = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].add(b - 1)
    G[b - 1].add(a - 1)
d = [0] * N
Q = deque()
for i in range(N):
    if d[i] != 0:
        continue
    Q.append(i)
    d[i] = 1
    while len(Q) > 0:
        q = Q.pop()
        for g in G[q]:
            if d[g] != 0:
                continue
            d[i] += 1
            d[g] = -1
            Q.append(g)
print(max(d))
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(n)

else:
    for _ in range(m):
        a, b = map(int, input().split())
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i] and i in g:
            
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            
            ans = max(ans, count)

    print(ans)

Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 4
1 6
2 1
4 3
2 4
4 0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict, deque
n, m = map(int, input().split())
g = defaultdict(set)

if m == 0:
    print(1)

else:
    for _ in range(m):
        a, b = map(int, input().split())
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)


    visited = [False]*n
    ans = 0
    for i in range(n):
        if not visited[i]:
            
            count = 1
            q = deque([i])
            visited[i] = 1
            while q:
                node = q.pop()
                for nbr in g[node]:
                    if not visited[nbr]:
                        q.append(nbr)
                        visited[nbr] = True
                        count += 1
                
            
            ans = max(ans, count)

    print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())

tree = [-1] * N

def root(x):
  if tree[x] < 0:
    return x
  else:
    tree[x] = root(tree[x])
    return tree[x]

def unite(x, y):
  rx, ry = root(x), root(y)
  if rx == ry: return
  tree[rx] += tree[ry]
  tree[y] = x

def size(x):
  return -tree[root(x)]

for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  unite(a, b)

print(max(map(size, range(N))))


Failing test case input:
4 10
2 1
2 1
1 2
3 1
1 2
2 3
1 2
1 4
2 4
3 4

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10 ** 9)

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

tree = [-1] * N

def root(x):
  if tree[x] < 0:
    return x
  else:
    tree[x] = root(tree[x])
    return tree[x]

def unite(x, y):
  rx, ry = root(x), root(y)
  if rx == ry: return
  tree[rx] += tree[ry]
  tree[ry] = rx

def size(x):
  return -tree[root(x)]

for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  unite(a, b)

print(max(map(size, range(N))))
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n, m = map(int, input().split())  
par = [i for i in range(1, n + 1)]  




def find(x):
    if par[x - 1] == x:
        return x
    else:
        par[x - 1] = find(par[x - 1])
        return par[x - 1]



def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x - 1] = y



for j in range(m):
    a, b = map(int, input().split())
    union(a, b)



import collections
c = collections.Counter(par)
print(max(c.values()))


Failing test case input:
4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 1
2 3
2 4
2 4

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import collections
n, m = map(int, input().split())
par = list(range(2 * n))





def find(x):

    while par[x] != x:
        tmp = par[x]
        par[x] = par[par[x]]
        x = par[x]

    return x


def union(x, y):
    x1 = find(x)
    y1 = find(y)
    if x1 != y1:
        par[x1] = y1



for j in range(m):
    a, b = map(int, input().split())
    union(a - 1, b - 1)

s = [0 for i in range(n + 5)]


for k in range(n):
    s[find(k)] += 1

print(max(s))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)
if M > 0:  
  for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * N
  Max = 0
  
  
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)


Failing test case input:
5 3
1 2
3 4
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):

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

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)
if M > 0:  
  for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * N
  Max = 0
  for i in range(N):
    find(i)
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())


rooting = [[] for _ in range(N+1)]

for _ in range(M):
    A, B = map(int, input().split())
    rooting[A].append(B)
    rooting[B].append(A)


max_group_num = 1


visited = [0 for _ in range(N+1)]


for i in range(1, N+1):
    queue = [i]
    group_num = 1

    while not queue == []:
        h = queue.pop(0)

        if visited[h] == 1:
            break
        else:
            visited[h] = 1
        
        for n in rooting[h]:
            if visited[n] != 1:
                queue.append(n)
                group_num += 1
                visited[n] = 1

    max_group_num = max(max_group_num, group_num)

print(max_group_num)

Failing test case input:
4 10
2 1
2 1
1 2
2 1
1 2
2 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())


rooting = [[] for _ in range(N+1)]

for _ in range(M):
    A, B = map(int, input().split())
    rooting[A].append(B)
    rooting[B].append(A)


max_group_num = 1


visited = [0 for _ in range(N+1)]


for i in range(1, N+1):
    if  visited[i] == 1:
        continue
    visited[i] = 1
    queue = [i]
    group_num = 1

    while not queue == []:
        h = queue.pop(0)
        for n in rooting[h]:
            if visited[n] != 1:
                queue.append(n)
                group_num += 1
                visited[n] = 1

    max_group_num = max(max_group_num, group_num)

print(max_group_num)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)

st = deque([1])
check = [0]*(N+1)
check[1] = 1
mark = [0]*(N+1)
ans = 0
while st:
  cnt = 0
  s = st.popleft()
  for t in l[s]:
    if check[t] == 0:
      mark[t] = s
      check[t] = 1
      st.append(t)
      cnt += 1
  ans = max(ans,cnt)
print(ans+1)

Failing test case input:
5 2
1 4
3 4
4 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)
ans = 1
check = [0]*(N+1)
for i in range(1,N+1):
  st = deque([i])
  check[i] = 1
  cnt = 1
  while st:
    s = st.popleft()
    for t in l[s]:
      if check[t] == 0:
        check[t] = 1
        st.append(t)
        cnt += 1
  ans = max(ans,cnt)
print(ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())

par = [i + 1 for i in range(n)]
rank = [1] * n
size = [1] * n

def find(x):
    if par[x - 1] == x:
        return x
    else:
        return find(par[x - 1])

def union(x, y):
    x = find(x)
    y = find(y)
    if rank[x - 1] < rank[y - 1]:
        par[x - 1] = y
        size[y - 1] += size[x - 1]
    else:
        par[y - 1] = x
        size[x - 1] += size[y - 1]
        if rank[x - 1] == rank[y - 1]:
            rank[x - 1] += 1

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

print(max(size))

Failing test case input:
4 10
1 1
2 1
1 2
2 1
1 2
1 3
1 4
1 3
2 4
3 4

Expected output:
4


Actual output:
208


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

par = [i + 1 for i in range(n)]
rank = [1] * n
size = [1] * n

def find(x):
    if par[x - 1] == x:
        return x
    else:
        return find(par[x - 1])

def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x - 1] < rank[y - 1]:
        par[x - 1] = y
        size[y - 1] += size[x - 1]
    else:
        par[y - 1] = x
        size[x - 1] += size[y - 1]
        if rank[x - 1] == rank[y - 1]:
            rank[x - 1] += 1

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

print(max(size))

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())


root = list(range(n + 1))




cnt = [1] * (n + 1)


def find(i):
    if i == root[i]:
        return i
    root[i] = find(root[i])
    return root[i]

def union(u, v):
    fu, fv = find(u), find(v)
    if fu == fv:
        return
    root[max(u, v)] = min(fu, fv)
    cnt[min(fu, fv)] += cnt[max(u, v)]



for i in range(m):
    u, v = map(int, input().split())
    union(u, v)




print(max(cnt))


Failing test case input:
10 4
3 2
3 1
5 9
2 6

Expected output:
4


Actual output:
3


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


root = list(range(n + 1))




cnt = [1] * (n + 1)


def find(i):
    if i == root[i]:
        return i
    root[i] = find(root[i])
    return root[i]

def union(u, v):
    fu, fv = find(u), find(v)
    if fu == fv:
        return
    cnt[min(fu, fv)] += cnt[max(fu, fv)]
    root[max(fu, fv)] = min(fu, fv)



for i in range(m):
    u, v = map(int, input().split())
    union(u, v)




print(max(cnt))
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque

N, M = map(int, input().split())
l = [[] for i in range(N)]
for i in range(M):
        a, b = map(int, input().split())
        l[a - 1].append(b - 1)
        l[b - 1].append(a - 1)
m = 0 
for i in range(N):
        if set(l[i]):
                l[i] = set(l[i])    
queue = deque([0])
c = []
while queue:
        now = queue.popleft()
        c.append(now)
        d = 0 
        for i in l[now]:
                if i in c:
                        continue
                else:
                        d += 1
                        queue.append(i)
        m = max(m, d)

print(m + 1)

Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import queue
N, M = map(int, input().split())
l = [[] for i in range(N)]
for i in range(M):
        a, b = map(int, input().split())
        l[a - 1].append(b - 1)
        l[b - 1].append(a - 1)
c = [0] * N 
ans = 1
q = queue.Queue()
for j in range(N):
        q.put(l[j])
        u = 0 
        while not q.empty():
                temp = q.get()
                for k in temp:
                        if c[k]:
                                continue
                        c[k] = 1 
                        u += 1
                        q.put(l[k])
        ans = max(ans, u)
print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
  else:
    par[y] = x
  
for i in range(M):
  a, b = map(int, input().split())
  unite(a - 1, b - 1)
  
ans = [0] * N
Max = 0
for i in par:
  ans[i] += 1
for i in ans:
  if i > Max:
    Max = i
  
print(Max)

Failing test case input:
5 3
1 2
3 5
3 1

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)
if M > 0:  
  for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * N
  Max = 0
  for i in range(N):
    find(i)
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)
Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict,deque
n,m = map(int,input().split())

d = defaultdict(list)

if m==0:
    print(1)
    exit()

visited = [-1] + [False]*n
for i in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
maxi = 1
for i in range(n):
    if visited[i]:
        continue
    cnt = 0
    que = deque([i])
    while que:
        v = que.pop()
        visited[v] = True
        cnt += 1
        for j in d[v]:
            if not visited[j]:
                que.append(j)
    maxi = max(maxi,cnt)
print(maxi)


Failing test case input:
4 10
2 1
2 1
1 2
2 1
1 2
2 3
1 4
1 4
2 4
3 4

Expected output:
4


Actual output:
11


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
n,m = map(int,input().split())

d = defaultdict(list)

if m==0:
    print(1)
    exit()

visited = [-1] + [False]*n
for i in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
maxi = 1
for i in range(1,n+1):
    if visited[i]:
        continue
    cnt = 0
    que = deque([i])
    while que:
        v = que.pop()
        if not visited[v]:
            visited[v] = True
            cnt += 1
        for j in d[v]:
            if not visited[j]:
                que.append(j)
    maxi = max(maxi,cnt)
print(maxi)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = (int(x) for x in input().split())
import collections
Parent = [i for i in range(N)]
def fp(i):
    global Parent
    if Parent[i] == i:
        return i
    else:
        Parent[i] = fp(Parent[i])
        return Parent[i]

for _ in range(M):
    a, b = (int(x) for x in input().split())
    c, d = min(a,b)-1, max(a,b)-1
    Parent[d] = min(fp(c), fp(d))

Groupsize = collections.defaultdict(lambda:0)
for i in range(N):
    i = fp(i)
    Groupsize[i] +=1
ans = max(gs for gs in Groupsize.values())
print(ans)

Failing test case input:
10 4
6 1
3 1
5 6
2 6

Expected output:
5


Actual output:
3


Fixed submission (verdict: Accepted):
N, M = (int(x) for x in input().split())
import collections
Parent = [i for i in range(N)]
def fp(i):
    global Parent
    if Parent[i] == i:
        return i
    else:
        Parent[i] = fp(Parent[i])
        return Parent[i]

for _ in range(M):
    a, b = (int(x) for x in input().split())
    par_a, par_b = fp(a-1), fp(b-1)
    if par_a < par_b:
        Parent[par_b] = par_a
    else:
        Parent[par_a] = par_b

Groupsize = collections.defaultdict(lambda:0)
for i in range(N):
    i = fp(i)
    Groupsize[i] +=1
ans = max(gs for gs in Groupsize.values())
print(ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

s = set()
ans = 0
for i in range(1, n+1):
    if i not in s:
        s.add(i)
        tmp = [i]
        for ti in t[i]:
            if ti not in s:
                tmp.append(ti)
                s.add(ti)
        ans = max(ans, len(tmp))
print(ans)


Failing test case input:
5 2
1 4
3 4
3 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

q = deque()
s = set()
ans = 0
for i in range(1, n+1):
    if i not in s:
        q.append(i)
        s.add(i)
        tmp = [i]
        while q:
            v = q.popleft()
            for ti in t[v]:
                if ti not in s:
                    tmp.append(ti)
                    q.append(ti)
                    s.add(ti)
    ans = max(ans, len(tmp))
print(ans)

Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)
ans = 0

for i in range(1,N+1):
  st = deque([i])
  cnt = 0
  check = [0]*(N+1)
  mark = [0]*(N+1)
  while st:
    s = st.popleft()
    for t in l[s]:
      if check[t] == 0:
        mark[t] = s
        check[t] = 1
        st.append(t)
        cnt += 1
  ans = max(ans,cnt)
print(ans)

Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 4
1 6
2 1
4 3
2 4
4 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)
ans = 1
check = [0]*(N+1)
for i in range(1,N+1):
  st = deque([i])
  check[i] = 1
  cnt = 1
  while st:
    s = st.popleft()
    for t in l[s]:
      if check[t] == 0:
        check[t] = 1
        st.append(t)
        cnt += 1
  ans = max(ans,cnt)
print(ans)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)


check = [0]*(N+1)

mark = [0]*(N+1)
ans = 0

for i in range(1,N+1):
  st = deque([i])
  cnt = 0
  while st:
    s = st.popleft()
    for t in l[s]:
      if check[t] == 0:
        mark[t] = s
        check[t] = 1
        st.append(t)
        cnt += 1
  ans = max(ans,cnt)
print(ans)

Failing test case input:
2 0
1 1
1 2
0 6
-1 1
1 2
1 3
2 0
4 6
2 4
4 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]

for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)
ans = 1
check = [0]*(N+1)
for i in range(1,N+1):
  st = deque([i])
  check[i] = 1
  cnt = 1
  while st:
    s = st.popleft()
    for t in l[s]:
      if check[t] == 0:
        check[t] = 1
        st.append(t)
        cnt += 1
  ans = max(ans,cnt)
print(ans)

Problem: p02573
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict

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

if m==0:
    print(1)
    exit()

direction = [-1]+[False]*n
d = defaultdict(list)

for i in range(m):
    a,b = map(int,input().split())
    if direction[a] == False and direction[b] == False:
        direction[a] = a
        direction[b] = a
        d[a] += [a,b]
    elif direction[a] == False:
        direction[a] = direction[b]
        d[direction[b]].append(a)
    elif direction[b] == False:
        direction[b] = direction[a]
        d[direction[a]].append(b)

maxi = 1
for alist in d.values():
    maxi = max(maxi,len(alist))
print(maxi)

Failing test case input:
4 2
1 1
2 1
1 2
2 1
1 2
1 3
1 4
3 3
2 4
4 4

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
n,m = map(int,input().split())

d = defaultdict(list)

if m==0:
    print(1)
    exit()

visited = [-1] + [False]*n
for i in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
maxi = 1
for i in range(1,n+1):
    if visited[i]:
        continue
    cnt = 0
    que = deque([i])
    while que:
        v = que.pop()
        if not visited[v]:
            visited[v] = True
            cnt += 1
        for j in d[v]:
            if not visited[j]:
                que.append(j)
    maxi = max(maxi,cnt)
print(maxi)
Problem: p02573
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

used = [-1]*N
for i in range(N):
    if used[i] >= 0:
        continue
    q = deque()
    q.append(i)
    while q:
        temp = q.popleft()
        for e in E[temp]:
            if used[e] == i:
                continue
            used[e] = i
            q.append(e)

ans = [0]*N
for c in used:
    ans[c] += 1
print(max(ans))

Failing test case input:
4 0
1 1
1 1
1 6
-1 1
1 2
1 3
2 0
4 3
2 4
4 -1

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

used = [-1]*N
for i in range(N):
    if used[i] >= 0:
        continue
    q = deque()
    q.append(i)
    used[i] = i
    while q:
        temp = q.popleft()
        for e in E[temp]:
            if used[e] == i:
                continue
            used[e] = i
            q.append(e)

L = [0]*N
for c in used:
    L[c] += 1
ans = max(L)
print(ans)
Problem: p03081
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, q = map(int, input().split())
s = input()
tds = [input().split() for _ in range(q)]
tds.reverse()

l = 0
r = n - 1

for t, d in tds:
    if s[l] == t and d == "L":
        l += 1
    elif s[r] == t and d == "R":
        r -= 1
    if l > r:
        break

print(r - l + 1)

Failing test case input:
8 3
AABCBDBA
B L
B R
A R

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):


n, q = map(int, input().split())
s = input()
tds = [input().split() for _ in range(q)]
tds.reverse()

l = 0
r = n - 1

for t, d in tds:
    if s[l] == t and d == "L":
        l += 1
    if l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    if r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    if l > r:
        break

print(r - l + 1)

Problem: p03081
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,q= map(int,input().split())
s = [0]+list(input())+[0]
td = [input().split() for _ in range(q)]
l,r = 0,n+1
for i,j in td[::-1]:
  if s[l+1]==i and j=='L':
    l+=1
  if s[r-1]==i and j=='R':
    r-=1
print(max(0,r-l-1))

Failing test case input:
3 3
CCA
A L
B L
A R
@ R

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,q= map(int,input().split())
s = [0]+list(input())+[0]
td = [input().split() for _ in range(q)]
l,r = 0,n+1
for i,j in td[::-1]:
  if s[l+1]==i and j=='L':
    l+=1
  elif s[l]==i and j=='R':
    l-=1
  if s[r-1]==i and j=='R':
    r-=1
  elif s[r]==i and j=='L':
    r+=1
print(max(0,r-l-1))

Problem: p03081
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,Q = map(int,input().split())
S = "_"+ input() +"_"
td = [input().split() for _ in range(Q)]

l = 0
r = N+1
for i in range(Q-1,-1,-1): 
    t,d = td[i]
    if t == S[l+1] and d == "L":
        l += 1
    if t == S[r-1] and d == "R":
        r -= 1
print(max(0,r-l-1))


Failing test case input:
3 4
ABB
A L
B L
B R
@ R

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N,Q = map(int,input().split())
S = "_"+ input() +"_"
td = [input().split() for _ in range(Q)]

l = 0
r = N+1
for i in range(Q-1,-1,-1): 
    t,d = td[i]
    if t == S[l] and d == "R":
        l -= 1
    elif t == S[l+1] and d == "L":
        l += 1
    if t == S[r] and d == "L":
        r += 1
    elif t == S[r-1] and d == "R":
        r -= 1
print(max(0,r-l-1))
Problem: p03081
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, q = map(int, input().split())
s = input()
tds = [input().split() for _ in range(q)]
tds.reverse()

l = 0
r = n - 1

for t, d in tds:
    if s[l] == t and d == "L":
        l += 1
    elif s[r] == t and d == "R":
        r -= 1
    if l > r:
        break
print(l, r)
print(r - l + 1)


Failing test case input:
3 3
ACB
B L
B L
A R
@ S

Expected output:
3


Actual output:
0 2
3


Fixed submission (verdict: Accepted):


n, q = map(int, input().split())
s = input()
tds = [input().split() for _ in range(q)]
tds.reverse()

l = 0
r = n - 1

for t, d in tds:
    if s[l] == t and d == "L":
        l += 1
    if l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    if r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    if l > r:
        break

print(r - l + 1)
Problem: p02797
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K, S = map(int, input().split())
ans = []
for i in range(N):
    if i < K:
        ans.append(S)
    else:
        ans.append(1)
print(' '.join(map(str, ans)))   

Failing test case input:
5 3 101

Expected output:
101 101 101 102 102


Actual output:
101 101 101 1 1


Fixed submission (verdict: Accepted):
N, K, S = map(int, input().split())
ans = []
for i in range(N):
    if i < K:
        ans.append(S)
    elif S == 1:
        ans.append(2)
    elif S == 2:
        ans.append(3)
    else:
        ans.append(S 
print(' '.join(map(str, ans)))

Problem: p02797
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K, S = map(int, input().split())
a = [S]*K + [S+1]*(N-K)
print(" ".join([str(i) for i in a]))


Failing test case input:
5 3 100

Expected output:
50 50 50 30 70

Actual output:
100 100 100 101 101


Fixed submission (verdict: Accepted):
N, K, S = map(int, input().split())
m = 1
a = [S]*K + [S
print(" ".join([str(i) for i in a]))

Problem: p02797
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k , s = map(int, input().split())
ans = []
for i in range(k):
  ans.append(str(s))
for i in range(n-k):
  ans.append(str(s+1))
print(" ".join(ans))

Failing test case input:
5 3 100

Expected output:
50 50 50 30 70

Actual output:
100 100 100 101 101


Fixed submission (verdict: Accepted):
n, k , s = map(int, input().split())
ans = []
for i in range(k):
  ans.append(str(s))
for i in range(n-k):
  if s == 1:
    s = 10
  ans.append(str(s
print(" ".join(ans))

Problem: p02797
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K,S = map(int,input().split())
for i in range(K):
    print(S,end=' ')
for j in range(N-K):
    print(2*S,end=' ')
print()

Failing test case input:
5 2 0

Expected output:
0 0 1 1 1


Actual output:
0 0 0 0 0 


Fixed submission (verdict: Accepted):
N,K,S = map(int,input().split())

if S > (10**9)
    T = 1
else:
    T = S*2
for i in range(K):
    print(S,end=' ')
for j in range(N-K):
    print(T,end=' ')
print()
Problem: p03781
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	
	sys.stdin = open(name)

x = int(input())
chk = 0
i = 1

while chk < x:
	chk = chk + i
	i = i + 1
	print(chk,i)

print(i-1)


Failing test case input:
2248

Expected output:
67


Actual output:
1 2
3 3
6 4
10 5
15 6
21 7
28 8
36 9
45 10
55 11
66 12
78 13
91 14
105 15
120 16
136 17
153 18
171 19
190 20
210 21
231 22
253 23
276 24
300 25
325 26
351 27
378 28
406 29
435 30
465 31
496 32
528 33
561 34
595 35
630 36
666 37
703 38
741 39
780 40
820 41
861 42
903 43
946 44
990 45
1035 46
1081 47
1128 48
1176 49
1225 50
1275 51
1326 52
1378 53
1431 54
1485 55
1540 56
1596 57
1653 58
1711 59
1770 60
1830 61
1891 62
1953 63
2016 64
2080 65
2145 66
2211 67
2278 68
67


Fixed submission (verdict: Accepted):
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	
	sys.stdin = open(name)

x = int(input())
chk = 0
i = 1

while chk < x:
	chk = chk + i
	i = i + 1
	

print(i-1)

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=0
i=1
while a<N:
  a+=i
  i+=1
print(i)
  

Failing test case input:
8030

Expected output:
127


Actual output:
128


Fixed submission (verdict: Accepted):
N=int(input())
a=0
i=0
while a<N:
  i+=1
  a+=i
print(i)

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = int(input())

t=0
x=0
while(x+t<X):
    t += 1
    x += t
    
print(min([X-x+t,x+(2*t)-X+1]))

Failing test case input:
1053

Expected output:
46


Actual output:
63


Fixed submission (verdict: Accepted):
X = int(input())

t=0
x=0
while(True):
    t += 1
    x += t
    if x>=X:break
    
print(t)

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
from collections import deque
X = int(input())
place = 0
for i in range(1, 10**9):
    if X-(place + i) > i:
        place += i
    elif X == place +i:
        print(i)
        break

Failing test case input:
4584

Expected output:
96


Actual output:
119


Fixed submission (verdict: Accepted):
import sys
import math
from collections import deque
X = int(input())
sum = 0
for i in range(1, 10**9):
    sum += i
    if sum >= X:
        print(i)
        break

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x=int(input())

for i in range(1,x+1):
    if x == i:
        print(i)
        break
    elif x-i >= i+1:
        x-=i 

Failing test case input:
12423

Expected output:
158


Actual output:
177


Fixed submission (verdict: Accepted):
x=int(input())
dis_sum=0
for i in range(1,x+1):
    dis_sum+=i
    if dis_sum>=x:
        print(i)
        break
Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x=abs(int(input()))

for i in range(1,x+1):
    if x == i:
        print(i)
        break
    elif x-i >= i+1:
        x-=i 

Failing test case input:
19255

Expected output:
196


Actual output:
340


Fixed submission (verdict: Accepted):
x=int(input())
dis_sum=0
for i in range(1,x+1):
    dis_sum+=i
    if dis_sum>=x:
        print(i)
        break

Problem: p03781
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
i = 1
while n > 0:
  n -= i
  i += 1
print(i)

Failing test case input:
1896

Expected output:
62


Actual output:
63


Fixed submission (verdict: Accepted):
n = int(input())
i = 1
while n > 0:
  n -= i
  i += 1
print(i-1)

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = int(input())

cnt = 1

while True:
    if x < cnt:
        print(cnt -1 + x)
        exit()
    x -= cnt
    if x == 0:
        print(cnt)
        exit()
    cnt += 1


Failing test case input:
9009

Expected output:
134


Actual output:
231


Fixed submission (verdict: Accepted):
x = int(input())

cnt = 1
temp = 0
while True:
    temp += cnt
    if x <= temp:
        print(cnt)
        exit()
    cnt += 1

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x=int(input())
for i in range(100000):
  if i * i+1 >= 2 * x:
    print(i)
    quit()

Failing test case input:
19255

Expected output:
196


Actual output:
197


Fixed submission (verdict: Accepted):
x=int(input())
for i in range(100000):
  if i * (i+1) >= 2 * x:
    print(i)
    quit()

Problem: p03781
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = int(input())

t=0
x=0
while(x+t<X):
    t += 1
    x += t
    
print(X-x+t)

Failing test case input:
4225

Expected output:
92


Actual output:
130


Fixed submission (verdict: Accepted):
X = int(input())

t=0
x=0
while(True):
    t += 1
    x += t
    if x>=X:break
    
print(t)

Problem: p03781
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x = int(input())

n = int((2*x)**0.5)

for i in range(n, n+3):
    if i*(i+1) > x*2:
        print(i)
        exit()

Failing test case input:
2850

Expected output:
75


Actual output:
76


Fixed submission (verdict: Accepted):
x = int(input())

n = int((2*x)**0.5)

for i in range(n, n+3):
    if i*(i+1) >= x*2:
        print(i)
        exit()
Problem: p03232
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  sum+= x
  sum= sum%(10**9 +7)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(10**9 +7)
print(ans)

Failing test case input:
10
4 2 2 11 30 22 2 128 21 512

Expected output:
315367784


Actual output:
635391818


Fixed submission (verdict: Accepted):
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(p)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(p)
print(ans)

Problem: p03232
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
for i in range(1,n+1):
  sum+= 1/i
  sum= sum
  SUM.append(sum)
ans=0
x=math.factorial(n)%(10**9 +7)
for i in range(n):
  ans+= number[i]*x*(SUM[n-1-i]+SUM[i]-1)
  ans=ans
print(ans)

Failing test case input:
10
0 2 1 15 64 7 2 9 -1 131

Expected output:
721954226


Actual output:
2721954240.0


Fixed submission (verdict: Accepted):
import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(p)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(p)
print(ans)
Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import fractions
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()


def lcm(x, y):
    return (x * y) 


if max(n, m) % min(n, m) == 0:
    print(-1)
else:
    print(lcm(n, m))

Failing test case input:
3 4
dniusrayvkuaisa
aumnudjus

Expected output:
-1


Actual output:
12


Fixed submission (verdict: Accepted):
import fractions
import sys
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()


def lcm(x, y):
    return (x * y) 


g = fractions.gcd(n, m)
for i in range(g):
    if s[n 
        print(-1)
        sys.exit()
print(lcm(n, m))

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import collections
import itertools as it
import math

 

n, m = map(int, input().split())
s = input()
t = input()





def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b 

lcm_ = lcm(n, m)
if lcm_ == max(n, m):
    print(-1)
else:
    print(lcm_)


Failing test case input:
21 9
dnsusr`yukuaiia
rujdunuma

Expected output:
-1


Actual output:
189


Fixed submission (verdict: Accepted):

import collections
import itertools as it
import math



n, m = map(int, input().split())
s = input()
t = input()





def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

g = gcd(n, m) 
a = n 
b = m 
for i in range(g):
    if s[i*a] != t[i*b]:
        print(-1)
        break
else:
    print(n * m

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = (int(i) for i in input().split())
s = input()
t = input()
def gcd(a,b):
	if a%b: return gcd(b,a%b)
	else: return b
g = gcd(n,m)
print(g)

Failing test case input:
3 2
acq
af

Expected output:
6


Actual output:
1


Fixed submission (verdict: Accepted):
n,m = (int(i) for i in input().split())
s = input()
t = input()
def gcd(a,b):
	if a%b: return gcd(b,a%b)
	else: return b
g = gcd(n,m)
ng, mg = n
if all(s[i*ng] == t[i*mg] for i in range(g)) :
    print(n*m
else :
    print(-1)

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if max(x,y) % min(x,y)==0:
    return min(x,y)
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  print(n*m)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)


Failing test case input:
3 2
dniusrayukuaisa
amunudjur

Expected output:
-1


Actual output:
6


Fixed submission (verdict: Accepted):
n,m=map(int, input().split())
s=input()
t=input()
def euc(x,y):
  if max(x,y) % min(x,y)==0:
    return min(x,y)
  else:
    return euc(max(x,y) % min (x,y),min(x,y))
d=euc(n,m)
ans=n*int(m/d)
if d==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  for i in range(d):
    if s[i*int(n/d)]!=t[i*int(m/d)]:
      ans=-1
  print(ans)
Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int,input().split())
S = input()
T = input()
flag = True
def lcm(a, b): 
    def gcd(a, b): 
        while b:
            a, b = b, a % b
        return a
    return a * b 
L = lcm(N,M)

if S[0] == T[0]:
    flag = True
else:
    flag = False
if flag:
    print(L)
else:
    print(-1)


Failing test case input:
3 3
abcdef
abb

Expected output:
-1


Actual output:
9


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
S = input()
T = input()
flag = True
def lcm(a, b): 
    def gcd(a, b): 
        while b:
            a, b = b, a % b
        return a
    return a * b 
L = lcm(N,M)
def gcd(a, b): 
    while b:
        a, b = b, a % b
    return a

flag = True
for i in range(gcd(N,M)):
    if S[i*N
        pass
    else:
        flag = False
if flag:
    print(L)
else:
    print(-1)

Problem: p03231
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)


def lcm(a, b):
	return a * b 
n,m = map(int,input().split())
s = input()
t = input()
mx = max(n,m)
mn = min(n,m)
if mx / mn % 1 == 0:
    c = mx
    if mn == len(s):
        if s == t[::c]:
            print(mx)
        else:
            print(-1)
    else:
        if t == s[::c]:
            print(mx)
        else:
            print(-1)
else:
    if s[0] == t[0]:
        print(lcm(n,m))
    else:
        print(-1)

Failing test case input:
3 3
abcdef
abc

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)


def lcm(a, b):
	return a * b 
n,m = map(int,input().split())
s = input()
t = input()
mx = max(n,m)
mn = min(n,m)
if mx / mn % 1 == 0:
    c = mx
    if mn == len(s):
        if s == t[::c]:
            print(t[::c])
            print(mx)
        else:
            print(-1)
    else:
        if t == s[::c]:
            print(s[::c])
            print(mx)
        else:
            print(-1)
else:
    num = lcm(n,m)
    mmx = num 
    mmn = num 
    ber = lcm(mmx,mmn)
    if mn == len(s):
        if s[::ber
            print(num)
        else:
            print(-1)
    else:
        if s[::ber
            print(num)
        else:
            print(-1)

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) 

n, m = map(int, input().split())
s = input()
t = input()
if n == m and s == t:
    print(n)
elif max(n, m) % min(n, m) == 0:
    print(-1)
else:
    print(lcm(n, m))

Failing test case input:
3 4
dniusrazvkuaisa
sujdunmua

Expected output:
-1


Actual output:
12


Fixed submission (verdict: Accepted):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) 

n, m = map(int, input().split())
s = input()
t = input()
L = lcm(n, m)
l = lcm(L 
for i in range(0, L, l):
    if s[i 
        print(-1)
        exit()
print(L)
Problem: p03231
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    N, M = (int(i) for i in input().split())
    S = input()
    T = input()

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    def lcm(x, y):
        return x*y
    L = lcm(N, M)
    if L == N or L == M:
        print(-1)
    else:
        print(L)


if __name__ == '__main__':
    main()


Failing test case input:
3 6
dniusr`yukuaisa
amunudjur

Expected output:
-1


Actual output:
18


Fixed submission (verdict: Accepted):
def main():
    N, M = (int(i) for i in input().split())
    S = input()
    T = input()

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    def lcm(x, y):
        return x*y
    L = lcm(N, M)

    match = lcm(L
    for a in range(0, L, match):
        if S[a * N
            return print(-1)
    else:
        print(L)


if __name__ == '__main__':
    main()

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import fractions
def lcm(x, y):
    return (x * y) 

n,m = map(int, input().split())
s = input()
t = input()

g = lcm(n,m)

if g == n or g == m:
    if n < m:
        sm = n
        ls = s
        bs = t
    else:
        sm = m
        ls = t
        bs = s
    a = g
    flg = False
    for i in range(sm):
        if bs[i * a] != ls[i]:
            flg = True
            break
    if flg:
        print(-1)
    else:
        print(g)
else:
    print(g)


Failing test case input:
2 2
acq
af

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
import fractions
def lcm(x, y):
    return (x * y) 

n,m = map(int, input().split())
s = input()
t = input()

if s[0] != t[0]:
    print(-1)
    exit()

g = lcm(n,m)

if n < m:
    sm = n
    bi = m
    ls = s
    bs = t
else:
    sm = m
    bi = n
    ls = t
    bs = s
a = g
b = g
flg = False
for i in range(sm):
    p = i * a
    if p % b == 0:
        if bs[p
            flg = True
            break
if flg:
    print(-1)
else:
    print(g)

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import fractions


def lcm(x, y):
    return (x * y) 

n,m = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
koubai = lcm(n,m)

n_k = koubai
m_k = koubai

print(koubai)

Failing test case input:
4 1
aar
`e

Expected output:
-1


Actual output:
4


Fixed submission (verdict: Accepted):
from sys import stdin
import fractions


def lcm(x, y):
    return (x * y) 

n,m = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
koubai = lcm(n,m)

if s[::koubai
    print(koubai)
else:
    print(-1)
Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def Euclidean(a, b):
    if a<b:
        a, b = b, a
    while True:
        m = a%b
        if m==0 or b==1:
            return b
        a = b
        b = m

N, M = list(map(int, input().split()))
S = input().rstrip()
T = input().rstrip()

gcm = Euclidean(N, M)
gcd = int(N*M/gcm)


for i in range(min(N, M)):
    if S[i]!=T[i]:
        if i==0:
            print(-1)
        else:
            print(i*gcd)
        exit()
print(-1)

Failing test case input:
1 1
`br
`e

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
def Euclidean(a, b):
    if a<b:
        a, b = b, a
    while True:
        m = a%b
        if m==0 or b==1:
            return b
        a = b
        b = m

N, M = list(map(int, input().split()))
S = input().rstrip()
T = input().rstrip()

if S[0]!=T[0]:
    print(-1)
    exit()

gcm = Euclidean(N, M)
gcd = int(N*M/gcm)


if N<M:
    N, M = M, N
    S, T = T, S



a = int(gcd/M)
b = int(gcd/N)
ab = a*b
for i in range(int(gcd/ab)):
    
    if S[i*a]!=T[i*b]:
        print(-1)
        exit()
print(gcd)

Problem: p03231
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, M = map(int, input().split())
S = input()
T = input()

lenS = len(S)
lenT = len(T)


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x * y 


lcmnum = lcm(lenS, lenT)

if S[0] != T[0]:
    print(-1)
    exit()

if S == T:
    print(lenS)
    exit()

if lcmnum == lenS or lcmnum == lenT:
    print(-1)
else:
    print(lcmnum)


Failing test case input:
1 2
acq
ae

Expected output:
2


Actual output:
6


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
S = input()
T = input()


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x * y 


n_lcm = lcm(len(S), len(T))
gcd_nm = gcd(N, M)

s_step = N 
t_step = M 

for i in range(gcd_nm):
    if S[i * N 
        print(-1)
        exit()
print(n_lcm)

Problem: p03231
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
s = str(input())
t = str(input())
a = 0
def get_gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return get_gcd(b, a % b)
def get_lcm(a, b, gcd):
    lcm = a * b 
    return lcm
saisyou = get_lcm(n,m,get_gcd(n,m))
if saisyou == n or saisyou == m:
    print(-1)
else:
    print(saisyou)

Failing test case input:
12 10
dnsusrayukuaiia
rujdunuma

Expected output:
-1


Actual output:
120


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
s = str(input())
t = str(input())
def get_gcd(a, b): 
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return get_gcd(b, a % b)
def get_lcm(a, b, gcd): 
    lcm = a * b 
    return lcm
lcm = get_lcm(n,m,get_gcd(n,m)) 
lcm2 = get_lcm(lcm/n,lcm/m,get_gcd(lcm/n,lcm/m)) 
ans = 0
for i in range(int(lcm
    if s[int(i*lcm2
        pass
    else:
        ans = 1
        break
if ans == 1:
    print(-1)
else:
    print(lcm)