Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
r,g,b, = map(str, raw_input())
s = int(r+g+b)
print 'YES' if s % 4 == 0 else 'NO'

Fixed submission:
r,g,b, = map(str, raw_input().split())
s = int(r+g+b)
print 'YES' if s % 4 == 0 else 'NO'
Buggy python submission (verdict: Runtime Error):
import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra
f(map(int, raw_input().split()))

Fixed submission:
import collections
def f(n,ais):
	cc,extra = collections.Counter(),0
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
		else: extra +=1
	print len(cc) + (1 if (len(cc) == 0 and extra) else 0), min(10000, len(cc) + extra)
	#print min(cc.values() or [0]), max(cc.values() or [0]) + extra
f(int(raw_input()), map(int, raw_input().split()))

Buggy python submission (verdict: Runtime Error):

import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8:
		cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra
f(map(int, raw_input().split()))

Fixed submission:
import collections
def f(n,ais):
	cc,extra = collections.Counter(),0
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
		else: extra +=1
	print len(cc) + (1 if (len(cc) == 0 and extra) else 0), min(10000, len(cc) + extra)
	#print min(cc.values() or [0]), max(cc.values() or [0]) + extra
f(int(raw_input()), map(int, raw_input().split()))

Buggy python submission (verdict: Runtime Error):

import collections
n = int(raw_input())


def f(ais):
	extra = 0
	cc = collections.Counter()
	for ai in ais:
		if ai/400 < 8:
		cc[ai/400] +=1
	else:
		extra +=1
	print min(cc.values()), max(cc.values()) + extra


Fixed submission:
import collections
def f(n,ais):
	cc,extra = collections.Counter(),0
	for ai in ais:
		if ai/400 < 8: cc[ai/400] +=1
		else: extra +=1
	print len(cc) + (1 if (len(cc) == 0 and extra) else 0), min(10000, len(cc) + extra)
	#print min(cc.values() or [0]), max(cc.values() or [0]) + extra
f(int(raw_input()), map(int, raw_input().split()))
Buggy python submission (verdict: Runtime Error):
print sum(map(int, raw_input().split())) < 10 else 'error'

Fixed submission:
a,b= map(int, raw_input().split())
print a+b if (a+b < 10) else 'error'
Buggy python submission (verdict: Runtime Error):
n = int(raw_input()) 
r,cumul, ais, m = 0, 0, [int(raw_input()) for _ in range(n)],+float('inf')
for ai in ais:# in range(0, len(ais)):
	cumul += ai
	m = min(m, ais[i] if ai % 10 else +float('inf'))
	r = max(r, cumul - (m if cumul % 10 else 0))
print r

Fixed submission:
n = int(raw_input()) 
ais = [int(raw_input()) for _ in range(n)]
r = 0
cumul = 0
m = +float('inf')
for i in range(0, len(ais)):
	cumul += ais[i]
	if ais[i] % 10:
		m = min(m, ais[i])

	if cumul % 10 == 0:
		r = max(r, cumul - m)
	else:
		r = max(r, cumul)

print r

Buggy python submission (verdict: Runtime Error):
n ais = [int(raw_input())] + map(int, raw_input().split())

r = 0
cumul = 0
m = +float('inf')
for i in range(1, len(ais)):
	cumul += ais[i]
	
	if cumul % 10 == 0:

		r = max(r, cumul - m)
	else:
		m = min(m, ais[i])
		r = max(r, cumul)

print r

Fixed submission:
n = int(raw_input()) 
ais = [int(raw_input()) for _ in range(n)]
r = 0
cumul = 0
m = +float('inf')
for i in range(0, len(ais)):
	cumul += ais[i]
	if ais[i] % 10:
		m = min(m, ais[i])

	if cumul % 10 == 0:
		r = max(r, cumul - m)
	else:
		r = max(r, cumul)

print r
Buggy python submission (verdict: Runtime Error):
a,b = map(int, raw_input())
print (a + b) % 24

Fixed submission:
a,b = map(int, raw_input().split())
print (a + b) % 24
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
m = len(str(n))
for a in range(2, n ** 0.5 + 1):
	if n % a == 0:
		m = min(m, max(len(str(a)), len(str(n/a))))
print m

Fixed submission:
n = int(raw_input())
m = len(str(n))
for a in range(2, int(n ** 0.5) + 1):
	if n % a == 0:
		m = min(m, max(len(str(a)), len(str(n/a))))
print m
Buggy python submission (verdict: Runtime Error):
a,b = raw_input().split()
if a == 'H':
	print b
else:
	h = {'H':'C', 'C':'H'}
	print h[b]

Fixed submission:
a,b = raw_input().split()
if a == 'H':
	print b
else:
	h = {'H':'D', 'D':'H'}
	print h[b]
Buggy python submission (verdict: Time Limit Exceeded):
import collections
ta = int(raw_input())
vis = set([0])
q = collections.deque([(0,0)])
while(q):
	x,t = q.popleft()
	if x == ta:
		print t
		break
	for nt in [x-t-1,x,x+t+1]:
		q.append((nt, t + 1))




Fixed submission:
import collections
target = int(raw_input())
t = 0
while(target):
	target -= min(target, t + 1)
	t +=1
print t
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())


c = 2 * (n / 11) if n > 11 else 0
h = {}
for i in range(1, 6+1):
	h[i] = 1
for i in range(7, 12):
	h[i] = 2
if n in h:
	print h[n]
else:
	print h[n % 11] + c


Fixed submission:
n = int(raw_input())


c = 2 * (n / 11)
h = {0:0}
for i in range(1, 6+1):
	h[i] = 1
for i in range(7, 12):
	h[i] = 2
if n in h:
	print h[n]
else:
	print h[n % 11] + c
Buggy python submission (verdict: Runtime Error):
words = [w[::-1] for w in ['dream','dreamer', 'erase', 'eraser']]
s = raw_input()[::-1]
while(i < len(s)):
	for w in words:
		if w == s[:len(w)]:
			i += len(w)
			break



print 'YES' if i == len(s) else 'NO'

Fixed submission:
words = ['dream','dreamer', 'erase', 'eraser']
s = raw_input()
dp = [False for _ in range(len(s))]

for j in range(len(s)):
	for w in words:
		b = dp[j - len(w)] if j - len(w) -1 >= 0 else True
		b &= j-len(w) +1 >= 0 and s[j- len(w)+1:j+1] == w
		if b:
			dp[j] = True
			break
print 'YES' if dp[-1] else 'NO'
Buggy python submission (verdict: Runtime Error):
ais = sorted(map(int, raw_input()).split())
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'

Fixed submission:
ais = sorted(map(int, raw_input().split()))
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'

Buggy python submission (verdict: Runtime Error):
ais = sorted(map(int, raw_input()))
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'

Fixed submission:
ais = sorted(map(int, raw_input().split()))
print 'Yes' if sum(ais[:2]) == ais[2] else 'No'
Buggy python submission (verdict: Runtime Error):

n,k = map(int, raw_input().split())
letters = [u for u in range(10) if u not in set(map(int, raw_input().split()))]
def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u

print dfs(0,n,letters)

Fixed submission:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Buggy python submission (verdict: Runtime Error):
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Fixed submission:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)
Buggy python submission (verdict: Time Limit Exceeded):


def sieveOfEratosthenes(N, s):

    
    prime = [False] * (N+1)

   
    for i in range(2, N+1, 2):
        s[i] = 2

    
    for i in range(3, N+1, 2):
        if (prime[i] == False):

            s[i] = i

            for j in range(i, int(N / i) + 1, 2):
                if (prime[i*j] == False):
                    prime[i*j] = True

                    
                    s[i * j] = i


def generatePrimeFactors(N):

    s = [0] * (N+1)

    sieveOfEratosthenes(N, s)


    curr = s[N]

    # Power of current prime factor
    cnt = 1
    ans=1


    while (N > 1):
        N //= s[N]

        # power
        if (curr == s[N]):
            cnt += 1
            continue

        ans*=(1+cnt)

        curr = s[N]
        cnt = 1
    return ans


N = int(input())
sumi=0
for i in range(1,N):
    sumi+=generatePrimeFactors(N-i)
print(sumi)


Fixed submission:
ans=0
n=int(input())
for i in range(1,n):
  ans+=(n-1)//i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math as mt

MAXN = 1000001

spf = [0 for i in range(MAXN)]



def sieve():
    spf[1] = 1
    for i in range(2, MAXN):

        
        spf[i] = i

    for i in range(4, MAXN, 2):
        spf[i] = 2

    for i in range(3, mt.ceil(mt.sqrt(MAXN))):

        if (spf[i] == i):

            for j in range(i * i, MAXN, i):

                if (spf[j] == j):
                    spf[j] = i



def getFactorization(x):
    ret = [0]*(x+1)
    while (x != 1):
        ret[spf[x]]+=1
        x = x // spf[x]

    return ret

sieve()
x = int(input())
ans = 0
for i in range(1,x):
    p = getFactorization(x-i)
    sumi=1
    for i in range(len(p)):
        sumi*=(1+p[i])
    ans+=sumi
print(ans)


Fixed submission:
ans=0
n=int(input())
for i in range(1,n):
  ans+=(n-1)//i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
f=0
n=int(input())
a=list(map(int,input().split()))
p = [0]*10**6
for i in range(0, len(a)):
    for j in range(2, int(math.sqrt(a[i]))+1):
        if a[i] % j == 0:
            p[j] += 1
    if max(p)>1:
        f=1
        break
if f==0:
    print("pairwise coprime")
else:
    _gcd=a[0]
    for i  in range(1,len(a)):
        _gcd=math.gcd(_gcd,a[i])
    if _gcd==1:
        print("setwise coprime")
    else:
        print("not coprime")
    

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
M = max(a)+1
if M == 2:
    print("pairwise coprime")
    exit()
count = [0]*(M)
prime = [2,3,5,7,11,13]
for i in range(14,int(M**0.5)+2):
    check = True
    for j in prime:
        if i%j == 0:
            check = False
            break
    if check:
        prime.append(i)
 
for i in a:
    for j in prime:
        if i < j:
            break
        if i%j==0:
            while i%j == 0:
                i //= j
            count[j] += 1
    if i > 1:
        count[i] += 1
 
ans = max(count)
 
if ans == 1:
    print("pairwise coprime")
elif ans == n:
    print("not coprime")
else:
    print("setwise coprime")

Buggy python submission (verdict: Time Limit Exceeded):
import math
f=0
n=int(input())
a=list(map(int,input().split()))
p = [0]*10**6
for i in range(0, len(a)):
    for j in range(2, int(math.sqrt(a[i]))+2):
        if a[i] % j == 0:
            p[i] += 1
    if max(p)>1:
        f=1
        break
if f==0:
    print("pairwise coprime")
else:
    _gcd=a[0]
    for i  in range(1,len(a)):
        _gcd=math.gcd(_gcd,a[i])
    if _gcd==1:
        print("setwise coprime")
    else:
        print("not coprime")
    

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
M = max(a)+1
if M == 2:
    print("pairwise coprime")
    exit()
count = [0]*(M)
prime = [2,3,5,7,11,13]
for i in range(14,int(M**0.5)+2):
    check = True
    for j in prime:
        if i%j == 0:
            check = False
            break
    if check:
        prime.append(i)
 
for i in a:
    for j in prime:
        if i < j:
            break
        if i%j==0:
            while i%j == 0:
                i //= j
            count[j] += 1
    if i > 1:
        count[i] += 1
 
ans = max(count)
 
if ans == 1:
    print("pairwise coprime")
elif ans == n:
    print("not coprime")
else:
    print("setwise coprime")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
l = []
 
 
for i in range(len(a) - 1):
    if a[i + 1] < a[i]:
        l.append(a[i]-a[i + 1])
        a[i + 1] = a[i]
print(sum(l))

Fixed submission:
import math
n,x,t=map(int,input().split())
ans=math.ceil(n/x)*t
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
k=int(input())
count=0
while(b<=a):
    b*=2
    count+=1
while(c<=b):
    c*=2
    count+=1
if count<=k:
    print("Yes")
else:
    print("No")

Fixed submission:
x=int(input())
if x>=400 and x<=599:
    print(8)
elif x>=600 and x<=799:
    print(7)
elif x>=800 and x<=999:
    print(6)
elif x>=1000 and x<=1199:
    print(5)
elif x>=1200 and x<=1399:
    print(4)
elif x>=1400 and x<=1599:
    print(3)
elif x>=1600 and x<=1799:
    print(2)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
prod=1
for i in range(0,k):
    prod=prod*a[i]
i=0
for j in range(k,len(a)):
    if a[j]>a[i]:
        print("Yes")
    else:
        print("No")
    i+=1


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
i=0
for j in range(k,len(a)):
    if a[j]>a[i]:
        print("Yes")
    else:
        print("No")
    i+=1
Buggy python submission (verdict: Runtime Error):
n=int(inpput())
print(int((n+n**2+n**3)))

Fixed submission:
n=int(input())
print(int(n+n**2+n**3))
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
P = list(map(int, input().split()))
diff, ans = 1000, -1
for i in range(0, 102):
    if (P.count(i)):
        continue
    if (abs(i - x) < diff):
        diff = abs(i - x)
        ans = i
print(ans)

Fixed submission:
a=list(map(int,input().split()))
print(a.index(0)+1)
Buggy python submission (verdict: Runtime Error):
import sys
from math import cos, radians, pi, sqrt
 
 
input = input().split()
 
A = int(input[0])
B = int(input[1])
H = int(input[2])
M = int(input[3])
 
rad = 2*pi*(H/12.0+(M/60.0)/12.0-M/60.0)
out = sqrt((pow(A,2)+pow(B,2))-(2*A*B*cos(rad)))
 
print(out)

Fixed submission:
s=input()
if int(s[-1]) == 2 or int(s[-1]) == 4 or int(s[-1]) == 5 or int(s[-1]) == 7 or int(s[-1]) ==9:
    print("hon")
elif int(s[-1]) == 0 or int(s[-1]) == 1 or int(s[-1]) == 6 or int(s[-1]) ==8:
    print("pon")
else:
    print("bon")
Buggy python submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
import math
a=[]
for i in range(1,min(m-1,q+1)):
    a.append(math.floor(n*i/m)-n*math.floor(i/m))
print(max(a))

Fixed submission:
A, B, N = map(int, input().split())
from math  import floor

def f(A, B, N):
    return floor(A*N/B)-A*floor(N/B)


print(f(A, B, min(B-1, N)))

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
import math
a=[]
for i in range(1,q+1):
    a.append(math.floor(n*i/m)-n*math.floor(i/m))
print(max(a))

Fixed submission:
A, B, N = map(int, input().split())
from math  import floor

def f(A, B, N):
    return floor(A*N/B)-A*floor(N/B)


print(f(A, B, min(B-1, N)))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
for i in range(0,len(s)-1,2):
    for j in range(i+1,len(s)):
        if int((s[i:j+1]))%2019==0:
            ans=ans+1
print(ans)
    
   

Fixed submission:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
for i in range(0,len(s)-1):
    for j in range(i+1,len(s)):
        if int((s[i:j+1]))%2019==0:
            ans=ans+1
print(ans)
    
   

Fixed submission:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
for i in range(int(input())):
    a=input()
    if a[0]=="1":
        s=s[::-1]
    elif a[0]=="2":
        if a[2]=="1":
            s=s[::-1]
            s=s+a[4]
            s=s[::-1]
        else:
            s=s+a[4]
print(s)          
            
        

Fixed submission:
from collections import deque
 
S = deque(list(input()))
Q = int(input())
rvs = False
 
for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            if rvs:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if rvs:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    else:
        rvs = not (rvs)
 
if rvs:
    S.reverse()
 
print("".join(S))
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
print(math.ceil(n/2)

Fixed submission:
import math
n=int(input())
print(math.ceil(n/2))
Buggy python submission (verdict: Runtime Error):
n,m=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(0,len(a)):
  if a[i]>=m:
    ans+=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(0,len(a)):
  if a[i]>=m:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
a=list(map(int,input().split()))
b=a[:]
b.sort()
index=[]
for i in range(0,len(b)):
    index.append(a.index(b[i])+1)
    
print(*index)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))

turn = [" " for _ in range(n)]
for i in range(n):
  turn[a[i]-1] = i+1

for i in range(n):
  print(turn[i], end=" ")
Buggy python submission (verdict: Runtime Error):
K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0
 
for i in range(1, N):
    l = []
    m = min(K, i)
    for j in range(1, m+1):
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    dp[i] = min(l)
print(dp[-1])

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0
 
for i in range(1, N):
    l = []
    m = min(K, i)
    for j in range(1, m+1):
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    dp[i] = min(l)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
 #https://atcoder.jp/contests/agc008/submissions/15248942
 import sys
 import math
 
 sys.setrecursionlimit(10 ** 8)
 ini = lambda: int(sys.stdin.readline())
 inm = lambda: map(int, sys.stdin.readline().split())
 inl = lambda: list(inm())
 ins = lambda: sys.stdin.readline().rstrip()
 debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
 
 N = ini()
 c = input()
 
 R = c.count('R')
 left = c[:R]
 ans = left.count('W')
 
 print(ans)


Fixed submission:
#https://atcoder.jp/contests/agc008/submissions/15248942
import sys
import math

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
c = input()

R = c.count('R')
W = c.count('W')
left = c[:R]

ans = min(R,W)
ans = min(ans,left.count('W'))

print(ans)
Buggy python submission (verdict: Runtime Error):
N = ini()
print(int((N*(N+1))/2))
'''
sum = 0
for i in range(N):
    sum += (i+1)
print(sum)
'''

Fixed submission:
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
print(int((N*(N+1))/2))
'''
sum = 0
for i in range(N):
    sum += (i+1)
print(sum)
'''
Buggy python submission (verdict: Runtime Error):
# -*- coding: Shift-JIS -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)

class UnionFind:
    """素集合を木構造として管理する。"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.n = n
        self.cnt = n
 
    def root(self, x):
        """要素xの代表元を求める。O(α(N))"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
 
    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を併合する。O(α(N))"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1
        return True
 
    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める。O(α(N))"""
        return self.root(x) == self.root(y)
 
    def size(self, x):
        """要素xを含む集合の要素数を求める。O(α(N))"""
        return -self.parent[self.root(x)]
 
    def count(self):
        """集合の個数を求める。O(1)"""
        return self.cnt
 
    def groups(self):
        """集合を列挙する。list[list[int]]で返す。O(N)"""
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            res[self.root(i)].append(i)
        return [group for group in res if group]

N,Q = map(int,readline().split())
uf = UnionFind(N)

for _ in range(Q):
    x,y = map(int,readline().split())
    x-=1; y-=1
    uf.merge(x,y)

print(uf.count()-1)


Fixed submission:
# -*- coding: utf-8 -*-
import sys 
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
road = [[] for _ in range(N+1)]
visit = [0]*(N+1)

for i in range(M):
    x,y = map(int,readline().split())
    road[x].append(y)
    road[y].append(x)
  
def dfs(v,prev):
    for x in road[v]:
        if x == prev:
            continue
        if visit[x] != 0:
            continue
        visit[x] = 1
        dfs(x,v)
    return 

count = 0     
for i in range(1,N+1):
    if visit[i] == 0:
        dfs(i,-1)
        count += 1

print(count-1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: Shift-JIS -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353

class BIT2:
    """ 区間加算BIT(区間加算・区間合計取得) """
    def __init__(self, N):
        self.N = (N+1)
        self.data0 = [0] * (N+1)
        self.data1 = [0] * (N+1)
        
    def _add(self, data, k, x):
        while k < self.N: #k <= Nと同義
            data[k] += x
            k += k & -k

    def _sum(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def sum(self, l, r):
        """ 区間[l,r)の和を取得 """
        return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1)
    
N, K = map(int, readline().split())
bit = BIT2(N)
d = []
for _ in range(K):
    L,R = map(int, readline().split())
    d.append((L,R))
    
d = sorted(d)
bit.add(1,2,1)

for i in range(2,N+1):
    for k in range(K):
        L,R = d[k]
        if i-L > 0:
            tmp = bit.sum(max(1,i-R),i-L+1)%MOD
            bit.add(i,i+1,tmp)
        else:
            break
print(bit.sum(N,N+1))

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353
N, K = map(int, readline().split())
data = []
for _ in range(K):
    L,R = map(int, readline().split())
    data.append((L,R))
    
data = sorted(data)
A = [0]*(N+1)
A[1] = 1
S = [0]*(N+1)
S[1] = 1

for i in range(2,N+1):
    for k in range(K):
        L,R = data[k]
        A[i] += (S[max(0,i-L)]- S[max(0,i-R-1)]) % MOD
        A[i] %= MOD
    S[i] = (S[i-1] + A[i]) % MOD

print(A[N])