Harryxun/stf_run huggingface dataset:
N,M=map(int, input().split())

adj={i: set() for i in range(1,N+1)}
for i in range(M):
  x,y,z=map(int, input().split())
  adj[x].add(y)
  adj[y].add(x)
V=set()
def dfs(v):
  if v not in V:
    V.add(v)
    for u in adj[v]: dfs(u)
cnt=0
for i in range(1,N+1):
  if i not in V:
    cnt += 1
    dfs(i)
print(cnt)

### FIXED CODE ###

import sys
mod = 10**9+7
sys.setrecursionlimit(mod)
N,M=map(int, input().split())

adj={i: set() for i in range(1,N+1)}
for i in range(M):
  x,y,z=map(int, input().split())
  adj[x].add(y)
  adj[y].add(x)
V=set()
def dfs(v):
  if v not in V:
    V.add(v)
    for u in adj[v]: dfs(u)
cnt=0
for i in range(1,N+1):
  if i not in V:
    cnt += 1
    dfs(i)
print(cnt)
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
        um=m
        m=(lm+m)//2
    else:
#        print(m)
        break

for mi in range(m,0,-1):
    if rf(mi)!=(n+k):
        break
print(mi+1)



### FIXED CODE ###

import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
(n,),*s=[tuple(t[:-1])for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==y for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)

### FIXED CODE ###

n,*s=[t[:-1]for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==''.join(y)for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzoku=0
i=0 #A[i]を参照する
while i<len(A):
	a=A[i]
	manzoku+=a
	if A[i+1]-A[i]==1 :
		manzoku+=C[a]
	i+=1
print('manzoku')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sum =0;
for i in range(len(a)):
    sum += b[a[i]-1]
    if i +1 < n and a[i+1] - a[i] == 1:
        sum += c[a[i]-1]
print(sum)
n,k=map(int,input().split())
p=list(map(int,input().split()))
q=[(1+pp)/2 for pp in p]
ans=0
c=[0]
for qq in q:
      c.append(c[-1]+qq)
ans=0

for qq in range(k,1+n):
  ans=max(ans,c[qq]-c[qq-k])

print(ans)


### FIXED CODE ###

h,w=map(int,input().split())
s=[input() for _ in range(h)]
from collections import deque
ans=0
dd=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(h):
  for j in range(w):
    if  s[i][j]=="#":
          continue
    
    g=[[0]*w for _ in range(h)]
    v=[[0]*w for _ in range(h)]
    g[i][j]=1
    q=deque([(j,i)])
    while q:
      x,y=q.popleft()
      for dx,dy in dd:
        nx=x+dx
        ny=y+dy
        if not 0<=nx<w:
          continue
        if not 0<=ny<h:
          continue
        if g[ny][nx]:
          continue
        if s[ny][nx]=="#":
          continue
        g[ny][nx]=1
        v[ny][nx]=v[y][x]+1
        q.append((nx,ny))
    for ii in v:
      ans=max(ans,max(ii))

print(ans)
def A(lst,hand):
    if len(lst) == 0:
        return
    else:
        return lst.pop(0)

def B(lst,hand):
    if len(lst) == 0:
        return
    else:
        return lst.pop(len(lst)-1)

def C(lst,hand):
    if len(hand) == 0:
        return
    else:
        lst.insert(0 , hand.pop( hand.index(min(hand)) ))

def D(lst,hand):
    if len(hand) == 0:
        return
    else:
        lst.append(hand.pop( hand.index(min(hand))) )

import random

if __name__ == "__main__":
    N,K = map(int, input().split())
    V = input().split()
    V = [int(i) for i in V]
    hand = []

    for l in range(1000):
        V_copy = [i for i in V]
        hand_copy = []
        for i in range(K):
            rand = random.randint(1,4)
            if rand == 1:
                hand_copy.append(A(V_copy,hand_copy))
            elif rand == 2:
                hand_copy.append(B(V_copy,hand_copy))
            elif rand == 3:
                C(V_copy,hand_copy)
            else:
                D(V_copy,hand_copy)
        hand.append(hand_copy)

    x = []
    for i in range(1000):
        x.append(sum(hand[i]))
    print(max(x))

### FIXED CODE ###

def MAP(): return map(int,input().split())

n,k = MAP()
*v, = MAP()

operation = min(n,k) #取り出すMAX回数
ans=0

for i in range(1,operation+1):
    for j in range(i+1):
        A = j   #左側から取り出す回数
        B = i-j    #右側から取り出す回数
        t = v[:A]
        if B>0:
            t+=v[-B:]
        t.sort()

        l = min(k-i,i-1)
        for ll in range(l):
            if t[ll] >= 0:
                l = ll
                break
        s = sum(t[l:])
        ans = max(ans,s)

print(ans)
N=int(input())
count=0
for i in range(105,N+1,2):
    divisor=0
    for j in range(1,i+1):
        if　i%j==0:
          divisor+=1
    if　divisor==8:
      count+=1
print(count)

### FIXED CODE ###

N=int(input())
count=0
for i in range(105,N+1,2):
    divisor=0
    for j in range(1,i+1):
        if(i%j==0):divisor+=1
    if(divisor==8):count+=1
print(count)
N,M=map(int, input().split())

uf=[i for i in range(N+1)]
nc=[1 for i in range(N+1)]

def find(i):
	if uf[i] == i:
		return i
	else:
		uf[i] = find(uf[i])
		return uf[i]

def union(i, j):
	gi, gj = find(i), find(j)
	if gi != gj:
		uf[gi] = gj
		diff = nc[gj] * nc[gi]
		nc[gj] += nc[gi]
		return diff
	return 0

su = N*(N-1)//2
ans = []

for x,y in reversed([list(map(int, input().split())) for _ in range(M)]):
	ans.insert(0, su)
	su -= union(x,y)

for a in ans:
	print(a)


### FIXED CODE ###

import sys
sys.setrecursionlimit(65536)

N,M=map(int, input().split())
bridge=[[int(x) for x in input().split()] for _ in range(M)]

uf=[i for i in range(N+1)]
nc=[1 for i in range(N+1)]

def find(i):
	if uf[i] == i:
		return i
	else:
		uf[i] = find(uf[i])
		return uf[i]

def union(i, j):
	gi, gj = find(i), find(j)
	if gi != gj:
		uf[gi] = gj
		diff = nc[gj] * nc[gi]
		nc[gj] += nc[gi]
		return diff
	return 0

su = N*(N-1)//2
ans = [-1]*M

for i in range(M-1, -1, -1):
	ans[i] = su
	x,y = bridge[i]
	su -= union(x, y)

print("\n".join(map(str, ans)))
n = int(input())
ls = list(map(int,input().split()))
a = min(ls)
b = max(ls)
c = len(ls)
s = 0
def sub(p,q):
    return p-q
ans = []
aaa = [0]*(b-a+2)
for i in range(a,b+1):
    new = [i]*(c)
    ans = map(sub,ls,new)
    ans = list(map(str,ans))
    s = ans.count("-1") + ans.count("1") + ans.count("0")
    aaa[i] = s
print(max(aaa))

### FIXED CODE ###

n = int(input())
ls = list(map(int,input().split()))
di = [0]*(max(ls)+3)
for i in ls:
    di[i] += 1
    di[i+1] += 1
    di[i+2] += 1
print(max(di))
import math
r = int(input())
print(math.pi * r * r, 2 * math.pi * r)


### FIXED CODE ###

from math import pi
r = float(input())
print("{0} {1}".format(r * r * pi, (r + r) * pi))
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in range(n.size()):
  co = co * n[i]
co--;

print(co % 1000000007)

### FIXED CODE ###

N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[index] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)
# AtCoder

lst = [int(input()) for _ in range(5)]

n = len(lst)
diffs = []
for i in range(n):
    dif = 10 - int(str(lst[i])[-1])
    diffs.append(dif)

s = []
for i in diffs:
    if i == 10:
        continue
    s.append(i)
mx = max(s)
s.remove(mx)
print(sum(s)+sum(lst))


### FIXED CODE ###

import math
l = [int(input()) for i in range(5)]
ans = 0
c = 0
for i in l:
    times = math.ceil(i/10)*10-i
    if times != 0:
        c = max(c, times)
    ans += math.ceil(i/10)*10
print(ans-c)
[a,b]=map(int,input().split())
if a*b=15:
  print("*")
else:
  if a+b=15:
    print("+")
    else:
      print("x")

### FIXED CODE ###

[a,b]=map(int,input().split())
if a*b==15:
  print("*")
else:
  if a+b==15:
    print("+")
  else:
    print("x")
#include <stdio.h>

int main()
{

    int s;
    scanf("%d", &s);
    int a = int(s / 60);
    int b = int(a / 60);
    int c = int(b / 60);
    printf("%d:%d:%d\n", a, b, c);
    return 0;
}


### FIXED CODE ###

s = int(input())
a, b = divmod(s, 60)
c, d = divmod(a, 60)
print("{}:{}:{}".format(c, d, b))
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    p = max(list1, key = lambda x:x[1])
    income += p[1]
    list1.pop(list1.index(p))
      
print(income)

### FIXED CODE ###

from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)
#問題C
N = int(input())
s = []

naka=0
a_kazu=0
b_kazu=0
b_a_kazu=0
for i in range(N):
    a = str(input())
    naka+=a.count("AB")
    if (a[0]=="B" and a[-1]=="A"):
        b_a_kazu+=1
    elif a[0]=="B":
        b_kazu+=1
    elif a[-1]=="A":
        a_kazu+=1
if b_a_kazu==0:
    print(naka+min(a_kazu, b_kazu))
else:
    if a_kazu==0 and b_kazu==0:
        print(naka+(b_a_kazu-1))
    elif a_lazu==0 or b_kazu==0:
        print(naka+(b_a_kazu))
    else:
        print()
    print(naka+(b_a_kazu-1)+min(a_kazu+1, b_kazu+1))

### FIXED CODE ###

#問題C
N = int(input())

naka=0
a_kazu=0
b_kazu=0
b_a_kazu=0
for i in range(N):
    a = str(input())
    naka+=a.count("AB")
    if (a[0]=="B" and a[-1]=="A"):
        b_a_kazu+=1
    elif a[0]=="B":
        b_kazu+=1
    elif a[-1]=="A":
        a_kazu+=1
if b_a_kazu==0:
    print(naka+min(a_kazu, b_kazu))
else:
    if (a_kazu==0 and b_kazu==0):
        print(naka+(b_a_kazu-1))
    elif (a_kazu==0 or b_kazu==0):
        print(naka+(b_a_kazu))
    else:
        print(naka+(b_a_kazu-1)+min(a_kazu+1, b_kazu+1))
a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al_1.append((b_lis))
for i in al_1:
    print(' '.join([str(v) for v in i]))


### FIXED CODE ###

a, b = map(int, input().split())
al = []
b_lis = []

for _ in range(a):
    g = list(map(int, input().split()))
    g.append(sum(g))
    al.append(g)
for i in range(b+1):
    p = 0
    for j in range(a):
        p += al[j][i]
    b_lis.append(p)
al.append((b_lis))
for i in al:
    print(' '.join([str(v) for v in i]))
import collections

n = int(input())
v = list(map(int, input().split()))

v0 = [v[i] for i in range(0,n,2)]
v1 = [v[i] for i in range(1,n,2)]

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
v0next = v0cnt.most_common()[1]
v1next = v1cnt.most_common()[1]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        if v0most[1] == n//2:
            ans = n//2
        else:
            if v0next[1] > v1next[1]:
                ans = n - v1most[1] - v0next[1]
            else:
                ans = n - v0most[1] - v1next[1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1next[1]
    else:
        ans = n - v1most[1] - v0next[1]

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 29 16:33:51 2018
ABC111C
@author: maezawa
"""

import collections

n = int(input())
v = list(map(int, input().split()))

v0 = [v[i] for i in range(0,n,2)]
v1 = [v[i] for i in range(1,n,2)]

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
if len(v0cnt) > 1:
    v0next = v0cnt.most_common()[1]
if len(v1cnt) > 1:
    v1next = v1cnt.most_common()[1]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        if v0most[1] == n//2:
            ans = n//2
        else:
            if v0next[1] > v1next[1]:
                ans = n - v1most[1] - v0next[1]
            else:
                ans = n - v0most[1] - v1next[1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1next[1]
    else:
        ans = n - v1most[1] - v0next[1]

print(ans)
N=int(input())
a=sorted(map(int,input().split()),reversed=True)
ans=sum(((-1)**i)*x for i,x in enumerate(a))
print(ans)

### FIXED CODE ###

N=int(input())
a=sorted(map(int,input().split()),reverse=True)
ans=sum(((-1)**i)*x for i,x in enumerate(a))
print(ans)
yha

### FIXED CODE ###

x = int(input())
if (x >= 30):
    print('Yes')
else:
    print('No')
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in n:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = 3**n
    exc = 1
    for i in range(n):
        if A[i]%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()
N=int(input())
S=list(map(lambda x: ord(x),input()))
MOD = 10e9 + 7


# 各文字列について、出現回数+1(1つ取るか、一切とらない)
# それを全部かければ良い

AppearCount = [ 0 for _ in range(26)]

for n in range(N):
	AppearCount[S[n]-ord('a')] += 1

ans = 1

for n in range(N):
	if AppearCount[n] != 0:
		ans *= (AppearCount[n]+1)
		if MOD <= ans:
			ans -= MOD

print(ans-1)

### FIXED CODE ###

N=int(input())
S=list(map(lambda x: ord(x),input()))
MOD = 10**9 + 7 # 1e9 + 7

# 各文字列について、出現回数+1(1つ取るか、一切とらない)
# それを全部かければ良い

AppearCount = [ 0 for _ in range(26)]

for n in range(N):
	AppearCount[S[n]-ord('a')] += 1

ans = 1
bFirst = True

for a in AppearCount:
	if a != 0:
		ans *= (a+1)
		while MOD < ans:
			ans -= MOD

ans -= 1

while MOD <= ans:
	ans -= MOD

print(ans)
in_string = input()
in_arr = in_string.split()
N = in_arr[0]
A = in_arr[1]
B = in_arr[2]

if ((B-A) % 2) == 0:
    print((B-A)/2)
else:
    if (N-B) > A-1:
        print(int(A+((B-A)-1)/2))
    else:
        print(int(N-B+1+((N-(A+N-B+1))/2)))
        

### FIXED CODE ###

in_string = raw_input()
in_arr = in_string.split()
N = int(in_arr[0])
A = int(in_arr[1])
B = int(in_arr[2])

if ((B-A) % 2) == 0:
    print(int((B-A)/2))
else:
    if (N-B) > A-1:
        print(int(A+(B-A-1)/2))
    else:
        print(int(N-B+1+((N-(A+N-B+1))/2)))
import numpy as np

p = 998244353

a,b,c,d = map(int,input().split())
dp = [[0 for _ in range(d+1)] for k in range(c+1)]
for i in range(a, c+1):
	for j in range(b, d+1):
		if i == a:
			if j == b:
				dp[i][j] = 1
			else:
				dp[i][j] = dp[i][j-1] * i % p
		elif j == b:
			dp[i][j] = dp[i-1][j] * j % p
		else:
			dp[i][j] = (dp[i-1][j]*j + dp[i][j-1]*i - dp[i-1][j-1]*(i-1)*(j-1)) % p

print(dp[c][d])

### FIXED CODE ###


p = 998244353

a,b,c,d = map(int,input().split())
dp = [[0 for _ in range(d+1)] for k in range(c+1)]
for i in range(a, c+1):
	for j in range(b, d+1):
		if i == a:
			if j == b:
				dp[i][j] = 1
			else:
				dp[i][j] = dp[i][j-1] * i % p
		elif j == b:
			dp[i][j] = dp[i-1][j] * j % p
		else:
			dp[i][j] = (dp[i-1][j]*j + dp[i][j-1]*i - dp[i-1][j-1]*(i-1)*(j-1)) % p

print(dp[c][d])
def main():
  a = []
  ans = "No"
  hit_examples = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
  for i in range(3):
    a.extend(list(map(int, input().split())))
  n = int(input())
  b = []
  for i in range(n):
    b.append(int(input()))
  for b_value in b:
    for i in range(len(a)):
      if b_value == a[i]:
        a[i] = -1

  for hit_example in hit_examples:
    cnt = 0
    for i in range(len(a)):
      if a[i] == -1 and i in hit_example:
        cnt += 1
      if cnt == 3:
        ans = "Yes"
        print(ans)
        return
  print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

n = int(input())
ans = 0
if n % 2 == 0:
  ans = int(n / 2)
else:
  ans = int(n / 2) + 1
print(ans)
gen = get_input()

S = list(input())

count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1

count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1

print(min(count, count2))

### FIXED CODE ###

S = list(input())
 
count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1
 
count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1
 
print(min(count, count2))
N = input()
s = list(map(int, input().split()))
if "Y" in s:
  print("Four")
else:
  print("Three")

### FIXED CODE ###

N = input()
s = list(input().split())
if "Y" in s:
  print("Four")
else:
  print("Three")
from collections import deque
 
qx = deque([])
qy = deque([])
 
nowx = 0
nowy = 0
tmpx = 0
tmpy = 0
 
ans = -1
cnt = 1
m = []
 
sx=[0,1,0,-1]
sy=[1,0,-1,0]
H,W = map(int, input().split())
for i in range(H):
    m.append(list(input()))
f = 0
p=[[999 for i in range(W)] for j in range(H)]
 
qx.append(nowx)
qy.append(nowy)
p[nowx][nowy]=0
 
while(len(qx) > 0 and f == 0):
    nowx = qx.popleft()
    nowy = qy.popleft()
    for i in range(4):
        tmpx = nowx + sx[i]
        tmpy = nowy + sy[i]
        if (tmpx < 0 or tmpx > W-1 or tmpy < 0 or tmpy > H-1):
            continue
        if (m[tmpy][tmpx] == '#'):
            continue
        if (tmpx == W-1 and tmpy == H-1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            ans = p[nowy][nowx]+1
            f = 1
            break
        if (p[tmpy][tmpx] > p[nowy][nowx]+1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            qx.append(tmpx)
            qy.append(tmpy)
 
ans2 = sum(x.count('.') for x in m) - ans -1 
print(ans2)
 
from collections import deque

qx = deque([])
qy = deque([])

nowx = 0
nowy = 0
tmpx = 0
tmpy = 0

ans = 0
cnt = 1
m = []

sx=[0,1,0,-1]
sy=[1,0,-1,0]
H,W = map(int, input().split())
for i in range(H):
    m.append(list(input()))
f = 0
p=[[999 for i in range(W)] for j in range(H)]

qx.append(nowx)
qy.append(nowy)
p[nowx][nowy]=0

while(len(qx) > 0 and f == 0):
    nowx = qx.popleft()
    nowy = qy.popleft()
    for i in range(4):
        tmpx = nowx + sx[i]
        tmpy = nowy + sy[i]
        if (tmpx < 0 or tmpx > W-1 or tmpy < 0 or tmpy > H-1):
            continue
        if (m[tmpy][tmpx] == '#'):
            continue
        if (tmpx == W-1 and tmpy == H-1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            ans = p[nowy][nowx]+1
            f = 1
            break
        if (p[tmpy][tmpx] > p[nowy][nowx]+1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            qx.append(tmpx)
            qy.append(tmpy)

if(ans == -1):
    ans2 = -1
else:
    ans2 = sum(x.count('.') for x in m) - ans -1 
print(ans2)


### FIXED CODE ###

from collections import deque

qx = deque([])
qy = deque([])

nowx = 0
nowy = 0
tmpx = 0
tmpy = 0

ans = -1
ans2 = 0
cnt = 1
m = []

sx=[0,1,0,-1]
sy=[1,0,-1,0]
H,W = map(int, input().split())
for i in range(H):
    m.append(list(input()))
f = 0
p=[[999 for i in range(W)] for j in range(H)]

qx.append(nowx)
qy.append(nowy)
p[nowx][nowy]=0

while(len(qx) > 0 and f == 0):
    nowx = qx.popleft()
    nowy = qy.popleft()
    for i in range(4):
        tmpx = nowx + sx[i]
        tmpy = nowy + sy[i]
        if (tmpx < 0 or tmpx > W-1 or tmpy < 0 or tmpy > H-1):
            continue
        if (m[tmpy][tmpx] == '#'):
            continue
        if (tmpx == W-1 and tmpy == H-1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            ans = p[nowy][nowx]+1
            f = 1
            break
        if (p[tmpy][tmpx] > p[nowy][nowx]+1):
            p[tmpy][tmpx] = p[nowy][nowx]+1
            qx.append(tmpx)
            qy.append(tmpy)

if(ans == -1):
    ans2 = -1
else:
    ans2 = sum(x.count('.') for x in m) - ans -1 
print(ans2)
t = input()

s = list(t)

for i in range(len(s)):
    if s[i] == '?':
        if i == 0:
            s[i] = 'D'
        if i < len(s) and s[i + 1] == 'P':
            s[i] = 'D'
        elif s[i - 1] == 'P':
            s[i] = 'D'
        elif s[i - 1] == 'D':
            s[i] = 'P'

print(''.join(s))

### FIXED CODE ###

t = input()

s = list(t)

for i in range(len(s)):
    if s[i] == '?':
        if i > 0 and s[i - 1] == 'P':
            s[i] = 'D'
        elif i < len(s) - 1 and s[i + 1] == 'D':
            s[i] = 'P'
        else:
            s[i] = 'D'

print(''.join(s))
import sys
input=sys.stdin.readline

s=int(input())

INF=10**9+7

def modcomb(n,k,m):
    fac=[0]*(n+1)
    finv=[0]*(n+1)
    inv=[0]*(n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,n+1):
        fac[i]=fac[i-1]*i%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m

ans=0
for n in range(1,667):
    if s-3*n>=0:
        ans=(ans+modcomb(s-2*n-1,n-1,INF))%INF

print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

s=int(input())

INF=10**9+7

def modcomb(n,k,m):
    fac=[0]*(n+1)
    finv=[0]*(n+1)
    inv=[0]*(n+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,n+1):
        fac[i]=fac[i-1]*i%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m

ans=0
if s==3:
    ans=1
else:
    for n in range(1,667):
        if s-3*n>=0:
            ans=(ans+modcomb(s-2*n-1,n-1,INF))%INF

print(ans)
n = int(input())
nums = list(map(int, input().split(' ')))

for i in range(len(nums)):
    key = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > key:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = key
    print(' '.join(map(str, nums)))

### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))

for i in range(len(nums)):
    key = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > key:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = key
    print(' '.join(map(str, nums)))
A = list(map(int, input().split())) 
return max(0,A[0]-2*A[1])

### FIXED CODE ###

A = list(map(int, input().split())) 
print(max(0,A[0]-2*A[1]))
def main():
    num = int(K)
    if num >= len(S):
        print(S)
    else:
        print(S[:num]+'...')

K, S = input().split()

main()


### FIXED CODE ###

def main():
    num = int(K)
    if num >= len(S):
        print(S)
    else:
        print(S[:num]+'...')

K = int(input())
S = input()

main()
from collections import Counter
n = int(input())
dic = {}
b = []
for i in range(n):
    a = input()
    b.append(a)
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
M = max(dic.values())
for j, k in sorted(dic.items):
    if k == M:
        print(j)


### FIXED CODE ###


n = int(input())
dic = {}
b = []
for i in range(n):
    a = input()
    b.append(a)
for o in b:
    if o in dic:
        dic[o] += 1
    else:
        dic[o] = 1
M = max(dic.values())
for j,k in sorted(dic.items()):
    if k == M:
        print(j)