Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

a = []
for i in range(n-1):
    if s[i:i+2] == "AC":
        a.append(1)
    else:
        a.append(0)

for i in range(q):
    l,r = map(int, input().split())
    print(sum(a[l-1:r-1]))




### FIXED CODE ###

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

a = [0] * (n+1)
for i in range(n-1):
    if s[i:i+2] == "AC":
        a[i+1] = a[i] + 1
    else:
        a[i+1] = a[i] 

for i in range(q):
    l,r = map(int, input().split())
    print(a[r-1] - a[l-1])
### BUGGY CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = [[0, dic[0]]]
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop(0)
        for s in t[1]:
            if visit[s]:
                point[s] += point[t[0]]
                visit[s] = False
                counter += 1
                next_visit.append([s, dic[s]])
    print(" ".join(map(str, point)))
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(input())
i=1
while True:
  if i%2==0 and i%n==0:
    break
  i+=1
print(i)

### FIXED CODE ###

n=int(input())
if n%2==0:
  print(n)
else:
  print(2*n)
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
ans = 0

for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += gcd(i+1,j+1,k+1)
print(ans)

### FIXED CODE ###

from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(gcd(i,j),k)
print(ans)
### BUGGY CODE ###

from collections import Counter
n=int(input())
p=sorted(list(map(int,input().split())))
s=set()
for x in p:
    i=1
    flag = True
    while i*i<=x:
        if x%i==0:
            a=x//i
            b=x//a
            if a in s or b in s:
                flag = False
                break
        i+=1
    if flag:
        s.add(x)

c = Counter(p)
for (k,v) in c.items():
    if v>1:
        s.discard(k)
print(len(s))

### FIXED CODE ###

n=int(input())
p=sorted(list(map(int,input().split())))
s=set()
m = 10**6+1
a=[True for _ in range(m)]
prev = 0
for x in p:
    if prev == x:
        s.discard(x)
        continue
    if a[x]:
        s.add(x)
    i = 2
    y = i*x
    while y<m:
        a[y] = False
        i+=1
        y = i*x
    prev=x

print(len(s))
### BUGGY CODE ###

import collections

N,K,Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
c = collections.Counter(A)

if (K - Q) > 0:
    for _ in range(N):
        print('Yes')
else:
    l = []
    for i,v in dict(c).items():
        if v >(Q - K):
            l.append(i-1)
    l.sort()
    for j in range(N):
        if j in l:
            print('Yes')
            l.pop(0)
#             if l == []:
#                 for _ in range(N-j-1):
#                     print('No')
#                 break
        else:
            print('No')

### FIXED CODE ###

import collections

N,K,Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
c = collections.Counter(A)

if (K - Q) > 0:
    for _ in range(N):
        print('Yes')
else:
    l = ['No'] * N
    for i,v in dict(c).items():
        if v >(Q - K):
            l[i-1] = 'Yes'
    for j in l:
        print(j)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  print(a.count(i+1))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
lst=[]
for i in range(n):
    lst.append(0)
for i in a:
    lst[i-1]+=1
for j in lst:
    print(j)
### BUGGY CODE ###

s = input()
n = len(s)
while '0' in s and '1' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
print(n - len(s))

### FIXED CODE ###

s = input()
a = s.count('0')
b = s.count('1')
print(a + b - abs(a - b))
### BUGGY CODE ###

from collections import defaultdict

n, m = map(int, input().split())
ps_list = [[i for i in input().split()] for j in range(m)]

ac_list = []
wa_dict = defaultdict(int)
num_wa = 0

for ps in ps_list:
    p = int(ps[0])
    s = ps[1]
    
    if s == 'AC' and p not in ac_list:
        ac_list.append(p)
        num_wa += wa_dict[p]
    elif p not in ac_list:
        wa_dict[p] += 1
            
num_ac = len(set(ac_list))
        
print(num_ac, num_wa)

### FIXED CODE ###

n, m = map(int, input().split())
ps_list = [[i for i in input().split()] for j in range(m)]

ac_list = []
wa_list = [0 for i in range(n)]
num_wa = 0
num_ac = 0

for ps in ps_list:
    p = int(ps[0])
    s = ps[1]
    
    if s == 'AC' and wa_list[p-1] != -1:
        ac_list.append(p)
        num_wa += wa_list[p-1]
        num_ac += 1
        wa_list[p-1] = -1
    elif wa_list[p-1] != -1:
        wa_list[p-1] += 1
        
print(num_ac, num_wa)
### BUGGY CODE ###

import sys

line = sys.stdin.readline().strip()
n,m,k = map(int, line.split())
roots = list(range(n))
linked = [0]*n
for i in range(m):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c, d = min(a,b)-1, max(a,b) - 1
    linked[c] += 1 
    linked[d] += 1
    while c != roots[c]:
        c = roots[c]
    while d != roots[d]:
        d = roots[d]
    e,f = min(c,d), max(c,d)
    roots[f] = e


for i in range(n):
    cursor = i
    while cursor != roots[cursor]:
       cursor = roots[cursor]
    roots[i] = cursor

#print(roots)
res = [0]*n
for i in range(k):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c,d = a-1, b-1
    # same group blacklist
    if roots[c] == roots[d]:
        res[c] -= 1
        res[d] -= 1 
set_sizes = dict()

rs = list(set(roots))
for r in rs:
    count = 0
    for one in roots:
        if one == r:
            count += 1
    set_sizes[r] = count

for i in range(n):
    r = roots[i]
    res[i] += (set_sizes[r]-1-linked[i])
print (" ".join(map(str, res)))

### FIXED CODE ###

import sys

line = sys.stdin.readline().strip()
n,m,k = map(int, line.split())
roots = [-1]*n
linked = [0]*n
def find_root(x):
    if roots[x] < 0:
        return x
    else:
        roots[x] = find_root(roots[x])
        return roots[x]
def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if (x==y):
        return
    if roots[x] > roots[y]:
        c, d = y,x
        x,y = c,d
    roots[x] += roots[y]
    roots[y] = x

for i in range(m):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c, d = a-1,b-1
    linked[c] += 1 
    linked[d] += 1
    unite(c,d)
#print(roots)
blacks = [[]for i in range(n)]
for i in range(k):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c,d = a-1, b-1
    blacks[c].append(d)
    blacks[d].append(c)
res = []
for i in range(n):
    r = -roots[find_root(i)] - 1 - linked[i]
    for one in blacks[i]:
        if find_root(one) == find_root(i):
            r -= 1
    res.append(r)
    
print (" ".join(map(str, res)))
### BUGGY CODE ###

n,aa,bb = map(int, input().split())
mod = 10 ** 9 + 7

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

ans = power_func(2, n, mod) - 1

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

ans -= comb(n,aa,mod) + comb(n,bb,mod)
ans %= mod

print(ans)

### FIXED CODE ###

n,a,b = map(int, input().split())
mod = 10 ** 9 + 7

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

ans = power_func(2, n, mod) - 1

comb = [1] * (b + 1)

for i in range(b):
    comb[i + 1] = comb[i] * (n - i) * pow(i + 1,mod - 2, mod) % mod

ans -= comb[a] + comb[b]
ans %= mod


print(ans)
### BUGGY CODE ###

from math import gcd
from functools import reduce

K = int(input())

res = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            res += reduce(gcd,(a,b,c))

print(res)


### FIXED CODE ###

from math import gcd

K = int(input())

res = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        tmp = gcd(a,b)
        for c in range(1,K+1):
            res += gcd(tmp,c)

print(res)
### BUGGY CODE ###

s = input()
t = input()

for i in range(len(s)):
  if s[i] == t[i]:
    continue
  else:
    tmp = s[i]
    s = s.replace(t[i],'X')
    s = s.replace(s[i],t[i])
    s = s.replace('X',tmp)
if s == t:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
t = input()

slist,tlist = [[] for _ in range(26)],[[] for _ in range(26)]

for i in range(len(s)):
  slist[ord(s[i])-ord('a')].append(str(i))
  tlist[ord(t[i])-ord('a')].append(str(i))

stargets,ttargets = [],[]
for x in range(26):
  if len(slist[x]) > 0:
    stargets.append(''.join(slist[x]))
  if len(tlist[x]) > 0:
    ttargets.append(''.join(tlist[x]))
stargets.sort()
ttargets.sort()
if stargets == ttargets:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

s = input()
t = input()
ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for _ in range(ls+1)]

for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
# #print(dp[ls][lt])
# for i in range(ls+1):
#     print(dp[i])

ans = ''
i = ls
j = lt
while (i>0 and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)

### FIXED CODE ###

s = input()
t = input()
ls = len(s)
lt = len(t)

dp = [[0]*(lt+1) for _ in range(ls+1)]

for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
# #print(dp[ls][lt])
# for i in range(ls+1):
#     print(dp[i])

ans = ''
i = ls
j = lt
while (i>0 and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
def bfs(v,G,queue,dist):
    dist[0] = 0
    seen[v] = True
    for vertex in G[v]:
        if seen[vertex]:
            continue
        elif vertex in queue:
            continue
        queue.append(vertex)
        dist[vertex] = dist[v] + 1
    for elements in queue:
        queue.remove(elements)
        bfs(elements,G,queue,dist)
N,M = map(int,input().split())
dist = [-1 for _ in range(N)]
seen = [False for _ in range(N)]
G = dict()
for i in range(N):
    G[i] = []   
for _ in range(M):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
queue = []
count = 0
ans = []
bfs(0,G,queue,dist)
for v in range(1,N): 
    L = [el for el in G[v] if dist[el] + 1 == dist[v]]
    if L == []:
        print("No")
        sys.exit(0)
    else:
        ans.append(L[0])
print("Yes")
for el in ans:
    print(el+1)

### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**9)
    from sys import stdin
    def input() : return stdin.readline().rstrip()
    N,M = map(int,input().split())
    dist = [-1] * N
    G = dict()
    for i in range(N):
        G[i] = []   
    for _ in range(M):
        a,b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    q = [0]
    pre = [0] * N
    dist[0] = 0
    while (q != []):
        v = q[0]
        q.remove(q[0])
        for vertex in G[v]:
            if dist[vertex] != -1:
                continue
            dist[vertex] = dist[v] + 1
            pre[vertex] = v
            q.append(vertex)
    print("Yes")
    for v in range(1,N): 
        print(pre[v]+1)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

H, W, M = map(int, input().split())
countH = [[h, 0] for h in range(H)]
countW = [[w, 0] for w in range(W)]
Bh = {}

for i in range(M):
  h, w = map(int, input().split())
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h][1] += 1
  countW[w][1] += 1

countH.sort(reverse=True, key=lambda x: x[1])
countW.sort(reverse=True, key=lambda x: x[1])
#print(countH)
#print(countW)
#rint(Bh)

maxh = countH[0][1]
maxw = countW[0][1]
ans = maxh + maxw
ch = [countH[0][0]]
i = 1
while i < H and countH[i][1]==maxh:
  ch.append(countH[i][0])
  i += 1
cw = [countW[0][0]]
i = 1
while i < W and countW[i][1]==maxw:
  cw.append(countW[i][0])
  i += 1
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if h not in Bh or w not in Bh[h]:
      flag = True
if flag:
  print(ans)
else:
  print(ans-1)

### FIXED CODE ###

H, W, M = map(int, input().split())
countH = [[h, 0] for h in range(H)]
countW = [[w, 0] for w in range(W)]
Bh = {}

for i in range(M):
  h, w = map(int, input().split())
  h, w = h-1, w-1
  if h in Bh:
    Bh[h].add(w)
  else:
    Bh[h] = {w}
  countH[h][1] += 1
  countW[w][1] += 1

countH.sort(reverse=True, key=lambda x: x[1])
countW.sort(reverse=True, key=lambda x: x[1])
#print(countH)
#print(countW)
#rint(Bh)

maxh = countH[0][1]
maxw = countW[0][1]
ans = maxh + maxw
ch = [countH[0][0]]
i = 1
while i < H and countH[i][1]==maxh:
  ch.append(countH[i][0])
  i += 1
cw = [countW[0][0]]
i = 1
while i < W and countW[i][1]==maxw:
  cw.append(countW[i][0])
  i += 1
flag = False
for h in ch:
  for w in cw:
    #print(h,w)
    if w not in Bh[h]:
      flag = True
      break
if flag:
  print(ans)
else:
  print(ans-1)
### BUGGY CODE ###

n,k = map(int,input().split())
tree = [int(input()) for _ in range(n)]
tree.sort()
ans = int(1e15)
for i in range(n-k+1):
    ans = min(max(tree[i:i+k]) - min(tree[i:i+k]), ans)
print(ans)


### FIXED CODE ###

n,k= map(int,input().split())
tree = []
for i in range(n):
    tree.append(int(input()))
tree.sort()
ans = int(1e10)
for i in range(n-k+1):
    a = tree[i+k-1] - tree[i]
    ans = min(ans, a)
print(ans)
### BUGGY CODE ###

n,ng = map(int,input().split())
nglist = list(int(input()) for i in range(ng))

MOD   = 10**9+7 
dp    = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):

  if i in nglist:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = dp[i-2] + dp[i-1]

print(dp[n] % MOD)

### FIXED CODE ###

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

MOD    = 10**9+7 
nglist = [0]*(n+1)
dp     = [0]*(n+1)
dp[0]  = 1

for i in range(ng):
  x = int(input())
  nglist[x] = 1
 
for i in range(1,n+1):

  if nglist[i]==1:
    dp[i] = 0
    continue

  if i==1:
    dp[1] = dp[0]
    continue
  
  dp[i] = (dp[i-2] + dp[i-1]) % MOD

print(dp[n])
### BUGGY CODE ###

s=input()
MOD=10**9+7
dp=[[0 for i in range(13)] for j in range(2)]

if s[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1

for i in range(1,len(s)):
  c = -1 if s[i]=='?' else int(s[i])
  for k in range(13):
    dp[i%2][k]=0

  if c==-1:
    for j in range(10):
      for k in range(13):
        dp[i%2][(k*10+j)%13]+=dp[(i-1)%2][k]
  else:
    for k in range(13):
      dp[i%2][(k*10+c)%13]+=dp[(i-1)%2][k]

  for j in range(13):
    dp[i%2][j]%=MOD
    
print(dp[(len(s)-1)%2][5])


### FIXED CODE ###

S=input()
a=[0]*13
a[0]= 1

for c in S:
  dp=[0]*13
  for i in range(13):
    dp[(i*10)%13]=a[i]%(10**9+7)
  dp+=dp

  if c=='?':
    for i in range(13):
      a[i]=sum(dp[i+4:i+14])
  else:
    for i in range(13):
      a[i]=dp[i+13-int(c)]

print(a[5]%(10**9+7))
### BUGGY CODE ###

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


count = 0

for x in range(1,n+1):
  for y in gate:
    if x < y[0] or y[1] < x:
      break
  else:
    count += 1
    
print(count)
  

### FIXED CODE ###

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

minv = gate[0][0]
maxv = gate[0][1]

for x in gate:
  minv = max(minv,x[0])
  maxv = min(maxv,x[1])
  
print(maxv-minv+1 if maxv-minv+1 >= 1 else 0)
### BUGGY CODE ###

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
Mod = 10**9 + 7
a.sort()
c = [0] * (n+1)
c[k - 1] = 1
for i in range(n+1):
    if i >= k:
        c[i] = (c[i - 1]*i) // (i - k + 1)
ans = 0
for i in range(1, n + 1):
    ans += (a[i - 1] * (c[i - 1] - c[n - i])) % Mod
print(ans % Mod)

### FIXED CODE ###

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
Mod = 10**9 + 7
a.sort()
c = [0] * (n+1)
c[k - 1] = 1
for i in range(n+1):
    if i >= k:
        c[i] = ((c[i - 1]*i * pow(i - k + 1, Mod - 2, Mod))) % Mod
ans = 0
for i in range(1, n + 1):
    ans += (a[i - 1] * (c[i - 1] - c[n - i])) % Mod
print(ans % Mod)
### BUGGY CODE ###

#
# author Sidratul
#

from functools import reduce

if __name__ == '__main__':
    n = input()
    a = list(map(int, input().split(' ')))
    s = reduce((lambda x, y: x*y), a)
    if s > 10**18:
        print(-1)
    else:
        print(s)

### FIXED CODE ###

#
# author Sidratul
#

from math import prod

if __name__ == '__main__':
    n = input()
    a = list(map(int, input().split(' ')))
    s = 1
    a.sort()
    x = True
    for i in range(len(a)):
        s = s * a[i]
        if s > 10**18:
            print(-1)
            x = False
            break
    if x:
        print(s)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, M = LI()
    S = LI()
    T = LI()
    dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
    for j in range(1, 1 + N):
        for i in range(1, 1 + M):
            if S[j - 1] == T[i - 1]:
                dp[j][i] = (dp[j][i - 1] + dp[j - 1][i]) % MOD
            else:
                dp[j][i] = (dp[j][i - 1] + dp[j - 1][i] - dp[j - 1][i - 1]) % MOD
    ans = dp[-1][-1]
    return ans

print(main())

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, M = LI()
    S = LI()
    T = LI()
    dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
    for j in range(1, 1 + N):
        for i in range(1, 1 + M):
            if S[j - 1] == T[i - 1]:
                dp[j][i] = (dp[j][i - 1] + dp[j - 1][i]) % MOD
            else:
                dp[j][i] = (dp[j][i - 1] + dp[j - 1][i] - dp[j - 1][i - 1]) % MOD
    ans = dp[-1][-1]
    return ans

print(main())
### BUGGY CODE ###

N, K = map(int, input().split())
while N > abs(N - K):
  N = abs(N - K)
print(N)

### FIXED CODE ###

N, K = map(int, input().split())
if abs(N - N // K * K) > abs(N - (N // K + 1) * K):
  print(abs(N - (N // K + 1) * K))
else:
  print(abs(N - N // K * K))
### BUGGY CODE ###

def test(s):
  list_s = []
  for i in range(2 ** len(s)):
    list_test = []
    for j in range(len(s)):
      if(i >> j) & 1 == 1:
        list_test.append(s[j])

    list_s.append(list_test)

  return list_s

def main():
  s = list(input())
  t = list(input())

  list_s = test(s)
  list_t = test(t)

  lcs = list(map(list, set(map(tuple, list_s)) & set(map(tuple, list_t))))
  lcs = list(lcs)
  
  max = 0
  num = ['']
  for i in lcs:
    if(len(i) > max):
      max = len(i)
      num.append(i)

  print(''.join(num[-1]))

if __name__ == '__main__':
  main()


### FIXED CODE ###

s = list(input())
t = list(input())

dp = [[0] * (len(t) + 1) for i in range(len(s) + 1)]
num = []

for i in range(len(s)):
  for j in range(len(t)):
    if(s[i] == t[j]):
      dp[i + 1][j + 1] = dp[i][j] + 1
    else:
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1])

ans = ''
i = len(s)
j = len(t)

while(j > 0 and i > 0):
  if(dp[i - 1][j] == dp[i][j]):
    i -= 1
  elif(dp[i][j - 1] == dp[i][j]):
    j -= 1
  else:
    ans += s[i - 1]
    i -= 1
    j -= 1

print(ans[::-1])
### BUGGY CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



def gcd_ab(a,b):
  while a != b:
    if a > b:
      a,b = [b,a]
    if a == 0:
      return b
    b = b-a
  return a


if __name__ == "__main__": 
  N = int(input())
  An = list(map(int, sys.stdin.readline().rstrip().split()))
  cum = [[0,0] for i in range(N+2)]

  for i in range(N):
    cum[i+1][0] = gcd_ab(cum[i][0], An[i])
    cum[N-i][1] = gcd_ab(cum[N-i+1][1], An[N-i-1])

  ans = 0
  for i in range(1,N+1):
    ans = max(ans, gcd_ab(cum[i-1][0], cum[i+1][1]))
  print(ans)

### FIXED CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


def gcd_ab(a,b):
  a,b = sorted([a,b])
  if a == 0:
    return b
  return gcd_ab(b%a, a)

if __name__ == "__main__": 
  N = int(input())
  An = list(map(int, sys.stdin.readline().rstrip().split()))
  cum = [[0,0] for i in range(N+2)]

  for i in range(N):
    cum[i+1][0] = gcd_ab(cum[i][0], An[i])
    cum[N-i][1] = gcd_ab(cum[N-i+1][1], An[N-i-1])

  ans = [0 for i in range(N)]
  for i in range(1,N+1):
    ans[i-1] = gcd_ab(cum[i-1][0], cum[i+1][1])
  print(max(ans))
### BUGGY CODE ###

n=int(input())
a = list(map(int, input().split()))
b=[0]*60
ans=0
count=0
mod=10**9+7

for i in range(60):
    for j in range(n):
        if a[j]>>i&1==1:
            count+=1

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*( b[i]*(n-b[i]) )


print(ans%mod)

### FIXED CODE ###

n=int(input())
a = list(map(int, input().split()))
b=[0]*60
ans=0
count=0
mod=10**9+7

for i in range(60):
    for j in range(n):
        if a[j]>>i&1==1:
            count+=1

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*( b[i]*(n-b[i]) )


print(ans%mod)