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

for i in range(len(s)):
  if s[i] == "A":
    st = i+1
    break

for i in range(len(s)):
  if s[::-1][i] == "Z":
    en = len(s)-i
    break

print(en - st + 1)

Fixed submission:
s = input()
sr = s[::-1]

for i in range(len(s)):
  if s[i] == "A" :
    st = i+1
    break

for i in range(len(s)):
  if sr[i] == "Z":
    en = len(s)-i
    break

print(en - st + 1)
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    dic=[[] for _ in range(100001)]
    mark=[0]*N
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A-1].append(B-1)
        dic[B-1].append(A-1)
    
    def dfs(idx):
        if mark[idx]:
            return
        mark[idx]=1
        for a in dic[idx]:
            dfs(a)

    i=0
    count=0
    while True:
        if not mark[i]:
            count+=1
            dfs(i)
        i+=1
        if i==N:
            break
    
    print(count-1)
main()

Fixed submission:
def main():
    import sys
    from collections import deque

    N,M=list(map(int,sys.stdin.readline().split()))
    dic=[[] for _ in range(100001)]
    sys.setrecursionlimit(100001)
    mark=[0]*N
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A-1].append(B-1)
        dic[B-1].append(A-1)


    i=0
    count=0
    while True:
        if not mark[i]:
            count+=1
            d=deque()
            d.appendleft(i)
            while d:
                a=d.popleft()
                mark[a]=1
                for j in dic[a]:
                    if mark[j]:
                        continue
                    
                    d.appendleft(j)
        i+=1
        if i==N:
            break
    
    print(count-1)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from bisect import bisect_left
    N,K=list(map(int,sys.stdin.readline().split()))
    A=[0]*N
    for i in range(N):
        A[i]=int(sys.stdin.readline())

    dp=[0]*(N+1)
    dp[0]=1
    if abs(A[0]-A[1])<=K:
        dp[1]=2
    else:
        dp[1]=1
    
    for i in range(2,N):
        mx=-1
        for j in range(1,100):
            if abs(A[i-j]-A[i])<=K:
                mx=max(mx,dp[i-2]+1)

        dp[i]=mx        

    print(max(dp))


main()

Fixed submission:
def main():
    import sys
    from bisect import bisect_left
    N,K=list(map(int,sys.stdin.readline().split()))
    A=[0]*N
    for i in range(N):
        A[i]=int(sys.stdin.readline())

    dp=[0]*(N+1)
    dp[0]=1
    if abs(A[0]-A[1])<=K:
        dp[1]=2
    else:
        dp[1]=1
    
    for i in range(2,N):
        mx=1
        for j in range(1,105):
            if i-j<0:
                break
            if abs(A[i-j]-A[i])<=K:
                mx=max(mx,dp[i-j]+1)

        dp[i]=mx

    print(max(dp))


main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import deque

    N,M=list(map(int,sys.stdin.readline().split()))
    dic=[[] for _ in range(100001)]
    sys.setrecursionlimit(100001)
    mark=[0]*N
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A-1].append(B-1)
        dic[B-1].append(A-1)


    i=0
    count=0
    while True:
        if not mark[i]:
            count+=1
            d=deque()
            d.appendleft(i)
            while d:
                a=d.popleft()
                mark[a]=1
                for j in dic[a]:
                    if mark[j]:
                        continue
                    
                    d.appendleft(j)
        i+=1
        if i==N:
            break
    
    print(count-1)
main()

Fixed submission:
def main():
    import sys
    from bisect import bisect_left
    N,K=list(map(int,sys.stdin.readline().split()))
    A=[0]*N
    for i in range(N):
        A[i]=int(sys.stdin.readline())

    dp=[0]*(N+1)
    dp[0]=1
    if abs(A[0]-A[1])<=K:
        dp[1]=2
    else:
        dp[1]=1
    
    for i in range(2,N):
        mx=1
        for j in range(1,105):
            if i-j<0:
                break
            if abs(A[i-j]-A[i])<=K:
                mx=max(mx,dp[i-j]+1)

        dp[i]=mx

    print(max(dp))


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if start-time.time()>=1.2:
            print(-1)
            return
main()

Fixed submission:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if time.time()-start>=1.5:
            print(-1)
            return
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if start-time.time()>=1.8:
            print(-1)
            return
main()

Fixed submission:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if time.time()-start>=1.5:
            print(-1)
            return
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1


main()

Fixed submission:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if time.time()-start>=1.5:
            print(-1)
            return
main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    N=int(sys.stdin.readline())
    X=sys.stdin.readline()

    no=X.count('1')
    np=no+1
    nm=no-1

    np_mods=[-1]*N
    nm_mods=[-1]*N
    
    np_mods[0]=1
    nm_mods[0]=1
    
    for i in range(1,N):
        np_mods[i]=(np_mods[i-1]*2)%np
        nm_mods[i]=(nm_mods[i-1]*2)%nm

    np_mods.reverse()
    nm_mods.reverse()

    np_mods_sum=0
    nm_mods_sum=0
    for i in range(N):
        if X[i]=='1':
            np_mods_sum+=np_mods[i]
            nm_mods_sum+=nm_mods[i]

    for i in range(N):
        if X[i]=='0':
            n=(np_mods_sum+np_mods[i])%np

        else:
            n=(nm_mods_sum-nm_mods[i])%nm

        if n==0:
            print(1)
            continue
        count=1
        while True:
            bs=str(bin(n))[2:]
            k=bs.count('1')
            n=n%k
            count+=1
            if n==0:
                break
        print(count)

main()

Fixed submission:
def main():
    import sys
    N=int(sys.stdin.readline())
    X=sys.stdin.readline()

    no=X.count('1')
    np=no+1
    nm=no-1
    nm_flag=bool(nm)

    np_mods=[-1]*N
    nm_mods=[-1]*N
    
    np_mods[0]=1
    nm_mods[0]=1
    
    for i in range(1,N):
        np_mods[i]=(np_mods[i-1]*2)%np
        if nm_flag:
            nm_mods[i]=(nm_mods[i-1]*2)%nm

    np_mods.reverse()
    nm_mods.reverse()
    
    np_mods_sum=0
    nm_mods_sum=0
    for i in range(N):
        if X[i]=='1':
            np_mods_sum+=np_mods[i]
            nm_mods_sum+=nm_mods[i]

    for i in range(N):
        if X[i]=='0':
            n=(np_mods_sum+np_mods[i])%np

        else:
            if nm_flag:
                n=(nm_mods_sum-nm_mods[i])%nm
            else:
                print(0)
                continue
        if n==0:
            print(1)
            continue
        count=1
        while True:
            bs=str(bin(n))[2:]
            k=bs.count('1')
            n=n%k
            count+=1
            if n==0:
                break
        print(count)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    N=int(sys.stdin.readline())
    r=0
    for i in range(1,N+1):
        r+=(i+N-N%i)*(N//i)//2
        print(i,r,(i+N-N%i)*(N//i)//2,N-N%i)

    
main()

Fixed submission:
def main():
    import sys
    N=int(sys.stdin.readline())
    r=0
    for i in range(1,N+1):
        r+=(i+N-N%i)*(N//i)//2

    print(r)

    
main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import defaultdict,deque
    sys.setrecursionlimit(10**5+2)

    N,M=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(list)
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A].append(B)
        dic[B].append(A)
    
    L=[-1]*(N+1)
    R=[-1]*(N+1)


    d = deque()
    d.append((1,1))
    while len(d):
        now,count=d.pop()
        for goto in dic[now]:
            if L[goto]==-1 or count<L[goto]:
                L[goto]=count
                R[goto]=now
                d.append((goto,count+1))

    if any(x+1 for x in R[2:]):
        print('Yes')
        for x in R[2:]:
            print(x)
    else:
        print('No')
    


main()

Fixed submission:
def main():
    import sys
    from collections import defaultdict,deque
    sys.setrecursionlimit(10**5+2)

    N,M=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(list)
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A].append(B)
        dic[B].append(A)
    
    L=[-1]*(N+1)
    R=[-1]*(N+1)


    d = deque()
    d.append((1,1))
    while len(d):
        now,count=d.popleft()
        for goto in dic[now]:
            if L[goto]==-1 or count<L[goto]:
                L[goto]=count
                R[goto]=now
                d.append((goto,count+1))

    if any(x+1 for x in R[2:]):
        print('Yes')
        for x in R[2:]:
            print(x)
    else:
        print('No')
    


main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import defaultdict
    sys.setrecursionlimit(10**5+2)
    
    N,M=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(list)
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A].append(B)
        dic[B].append(A)

    L=[-1]*(N+1)
    R=[-1]*(N+1)

    def dfs(now,count):
        for goto in dic[now]:
            if L[goto]==-1 or count<L[goto]:
                L[goto]=count
                R[goto]=now
                dfs(goto,count+1)

    dfs(1,1)
    if any(x+1 for x in R[2:]):
        print('Yes')
        for x in R[2:]:
            print(x)
    else:
        print('No')
    


main()

Fixed submission:
def main():
    import sys
    from collections import defaultdict,deque
    sys.setrecursionlimit(10**5+2)

    N,M=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(list)
    for i in range(M):
        A,B=list(map(int,sys.stdin.readline().split()))
        dic[A].append(B)
        dic[B].append(A)
    
    L=[-1]*(N+1)
    R=[-1]*(N+1)


    d = deque()
    d.append((1,1))
    while len(d):
        now,count=d.popleft()
        for goto in dic[now]:
            if L[goto]==-1 or count<L[goto]:
                L[goto]=count
                R[goto]=now
                d.append((goto,count+1))

    if any(x+1 for x in R[2:]):
        print('Yes')
        for x in R[2:]:
            print(x)
    else:
        print('No')
    


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    S=sys.stdin.readline().strip()
    L=[0]*len(S)

    now=0
    for i in range(len(S)):
        now+=int(S[-i-1])*10**i
        L[-i-1]=now%2019

    dic=Counter(L)
    
    output=0
    for val in dic.values():
        if val!=1:
            output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()


Fixed submission:
def pow_with_mod(x, n, m):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m

def main():
    import sys
    S=sys.stdin.readline().strip()
    N=len(S)
    L=[0]*2019
    now=0
    for i in range(N):
        now+=int(S[-i-1])*pow_with_mod(10, i, 2019)
        now%=2019
        L[now]+=1  
    print(L[0]+sum([x*(x-1)//2 for x in L]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import defaultdict
    S=sys.stdin.readline().strip()
    L=[0]*len(S)

    now=0
    for i in range(len(S)):
        now+=int(S[-i-1])*10**i
        L[-i-1]=now%2019

    dic=defaultdict(int)
    for a in L:
        dic[a]+=1

    
    output=0
    for _,val in dic.items():
        output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()


Fixed submission:
def pow_with_mod(x, n, m):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m

def main():
    import sys
    S=sys.stdin.readline().strip()
    N=len(S)
    L=[0]*2019
    now=0
    for i in range(N):
        now+=int(S[-i-1])*pow_with_mod(10, i, 2019)
        now%=2019
        L[now]+=1  
    print(L[0]+sum([x*(x-1)//2 for x in L]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import defaultdict
    S=sys.stdin.readline().strip()
    L=[0]*len(S)
    for i in range(len(S)):
        L[-i-1]=int(S[-i-1:])%2019

    dic=defaultdict(int)
    for a in L:
        dic[a]+=1

    
    output=0
    for _,val in dic.items():
        output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()

Fixed submission:
def pow_with_mod(x, n, m):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m

def main():
    import sys
    S=sys.stdin.readline().strip()
    N=len(S)
    L=[0]*2019
    now=0
    for i in range(N):
        now+=int(S[-i-1])*pow_with_mod(10, i, 2019)
        now%=2019
        L[now]+=1  
    print(L[0]+sum([x*(x-1)//2 for x in L]))
main()
Buggy python submission (verdict: Runtime Error):
import math
def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()


Fixed submission:
import math
def cmb(n, r):
    if n<2:
        return 0

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb 

def cmb(n,r):
    return comb(n, r, exact=True)

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()


Fixed submission:
import math
def cmb(n, r):
    if n<2:
        return 0

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
def cmb(n, r):
    if n==0:
        return 0

    if n==1 and r==2:
        return 0
    if n==2 and r==2:
        return 1

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    import sys
    from collections import defaultdict

    N=int(sys.stdin.readline())
    AL=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(int)
    for a in AL:
        dic[a]+=1


    K=[cmb(v,2) for k,v in dic.items()]
    total=sum(K)

    for i in range(N):
        a=dic[AL[i]]
        print(total-cmb(a,2)+cmb(a-1,2))

main()

Fixed submission:


def cmb(n,r):#r==2固定
    return n*(n-1)//2

def main():
    import sys
    from collections import defaultdict

    N=int(sys.stdin.readline())
    AL=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(int)
    for a in AL:
        dic[a]+=1


    K=[cmb(v,2) for k,v in dic.items()]
    total=sum(K)

    for i in range(N):
        a=dic[AL[i]]
        print(total-cmb(a,2)+cmb(a-1,2))

main()
Buggy python submission (verdict: Runtime Error):
def main():
    import numpy as np
    A=[]
    for _ in range(3):
        A.append(list(map(int,input().split())))
    
    R=np.zeros((3,3))
    K=[]
    for a in A:
        K+=a

    N=int(input())
    for i in range(N):
        b=int(input())
        if b not in K:
            continue
        
        idx=K.index(b)
        R[idx//3,idx%3]=1

    if any( all(x) for x in R.tolist()) or any(all(x) for x in R.T.tolist()):
        print('Yes')
    elif R[0,0] and R[1,1] and R[2,2] or R[0,2] and R[1,1] and R[2,0]:
        print('Yes')
    else:
        print('No')
        
main()


Fixed submission:
def main():
    import numpy as np
    A=[]
    for _ in range(3):
        A.append(list(map(int,input().split())))
    
    R=np.zeros((3,3))
    K=[]
    for a in A:
        K+=a

    N=int(input())
    for i in range(N):
        b=int(input())
        if b not in K:
            continue
        
        idx=K.index(b)
        R[idx//3,idx%3]=1

    if any( all(x) for x in R.tolist()) or any(all(x) for x in R.T.tolist()):
        print('Yes')
    elif R[0,0] and R[1,1] and R[2,2] or R[0,2] and R[1,1] and R[2,0]:
        print('Yes')
    else:
        print('No')
        
main()
Buggy python submission (verdict: Runtime Error):
def cmb(n, r, mod,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod



def main():
    mod = 10**9+7 #出力の制限
    N = 10**4
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    A.sort()
    if K==1:
        print(0)
        return

    rcom=[0]*N
    rcom[0]=A[-1]
    for i in range(1,N):
        rcom[i]=rcom[i-1]+A[-i-1]

    lcom=[0]*N
    lcom[0]=A[0]
    for i in range(1,N):
        lcom[i]=lcom[i-1]+A[i]

    result=0
    for i in range(N-1):
        result+=(rcom[i]-lcom[i])*cmb(N-2-i,K-2,mod,g1,g2)
        result%=(10**9+7)

    print(result)

main()

Fixed submission:
def cmb(n, r, mod,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod



def main():
    mod = 10**9+7 #出力の制限
    N = 10**5+1
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    A.sort()
    if K==1:
        print(0)
        return

    rcom=[0]*N
    rcom[0]=A[-1]
    for i in range(1,N):
        rcom[i]=rcom[i-1]+A[-i-1]

    lcom=[0]*N
    lcom[0]=A[0]
    for i in range(1,N):
        lcom[i]=lcom[i-1]+A[i]

    result=0
    for i in range(N-1):
        result+=(rcom[i]-lcom[i])*cmb(N-2-i,K-2,mod,g1,g2)
        result%=(10**9+7)

    print(result)

main()
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
def solve():

    A,B=map(int,input().split())

    
    return lcm(A,B)
print(solve())


Fixed submission:

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
def solve():

    A,B=map(int,input().split())

    
    return lcm(A,B)
print(solve())

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
def solve():

    A,B=map(int,input().split())

    
    return lcm(A,B)
print(solve())


Fixed submission:

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
def solve():

    A,B=map(int,input().split())

    
    return lcm(A,B)
print(solve())
Buggy python submission (verdict: Runtime Error):
import math

def solve():
    X,Y=[int(x) for x in input().split()]
    if (2*Y-X)%3 or (2*X-Y)%3:
        return 0
    
    a=(2*X-Y)//3
    b=(2*Y-X)//3

    n=a+b
    r=a
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))%(10**9+7)

    
print(solve())


Fixed submission:
from operator import mul
from functools import reduce

def cmb(n, r, mod,g1,g2):

    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


def solve():
    X,Y=[int(x) for x in input().split()]
    if (2*Y-X)%3 or (2*X-Y)%3:
        return 0
    
    a=(2*X-Y)//3
    b=(2*Y-X)//3
    

    n=a+b
    r=a

    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    mod = 10**9+7
    N = 10**6
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
        
    return cmb(n,r,mod,g1,g2)

    
print(solve())
Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())
S=input()

def ran(num):
    count = 1
    result = ''
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result = result + str(num[i])
                count = 1
        except:
            result = result + str(num[i])
            
    # 結果をprint
    return result

print(len(ran(S)))


Fixed submission:
"""
N=int(input())
L=[int(x) for x in input().split()]
L.sort()
count=0


for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[k]>=L[i]+L[j]:
                break
            count+=1
            
print(count)
"""
N=int(input())
S=input()
result=N
for i in range(N):
    if i+1==N:
        break
    
    if S[i]==S[i+1]:
        result-=1

print(result)