Harryxun/stf_run huggingface dataset:
# データ構造: Union Find (素集合データ構造)
#  前提
#    グラフ（頂点と辺からなる集合）上の各頂点が、どの連結成分に属しているかを管理するときに使う
#    具体的には、各連結成分ごとに適当な1点を親として、同じ連結成分に属する他の点が子になるように配置する
#  できること
#    1, ある頂点の親を返す (つまり、どの連結成分に属するかがわかる)
#    2, 新たな辺が与えられた時、必要なら連結成分の統合を行う

# 以下、事前準備。(本処理は42行目から)
# 上記1,2を実現する関数を作成する。

# 0, 前提
par = [-1]*n
#  配列parの要素par[i]には、
#    頂点iが子の場合に 親頂点の番号
#    頂点iが親の場合に 属する連結成分の頂点数を格納する。(区別のため負数として表記)
#  例: par = [2, 2, -3, -1, 5, -1]
#    点0,1,2からなる連結成分、点3からなる連結成分、点4,5からなる連結成分がある場合。

# 1, 頂点xの親を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
      
# 2, 頂点xとyが属する連結成分を結合する
def unite(x,y):
    x = find(x)
    y = find(y) 
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

# 以下、本処理
# 求めるもの：各連結成分の頂点数のうち、最大のもの
n, m = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1 for _ in range(n)]
 
for _ in range(m): #各辺について
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  unite(a,b) #辺の両端(頂点aとb)が統合される
  
print(-min(par))
# 各連結成分の頂点数は、配列parの中に負数として記録されている。
# 連結成分の最大の頂点数を求めたければ、そのminをとって-1倍すればよい。

### FIXED CODE ###

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

n, m = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for _ in range(m):
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  unite(a,b)
  
print(-min(par))
k = int(input())
    s = str(input())
    if len(s) <= k:
        print(s)
    else:
        print(s[:k]+'...')

### FIXED CODE ###

k = int(input())
s = input()
if k >= len(s):
  print(s)
else:
  print(s[:k]+"...")
n,m=map(int,input().split())
# Union-Find
a=list(range(n))
def find(x):
  if a[x]==x:
    return x
  a[x] = find(a[x])
  return a[x]

for _ in range(m):
  x,y=map(int,input().split())
  a[find(y-1)]=find(x-1)

count=[0]*n
for i in range(n):
  count[find(i)] += 1
print(max(count))


### FIXED CODE ###

n,m=map(int,input().split())
# Union-Find
a=list(range(n))
def find(x):
  g = x
  while g != a[g]: g = a[g]
  a[x] = g
  return g

for _ in range(m):
  x,y=map(int,input().split())
  x,y=find(x-1),find(y-1)
  if x == y: continue
  a[y]=x

count=[0]*n
for i in range(n):
  count[find(i)] += 1
print(max(count))
n, m, q = map(int, input().split())
cumlr = [[0] * n for i in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    cumlr[l-1][r-1] += 1

for i in range(n):
    for j in reversed(range(1, n)):
        cumlr[i][j-1] += cumlr[i][j]
for i in range(n):
    for j in range(n-1):
        cumlr[j+1][i] += cumlr[j][i]

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

### FIXED CODE ###

n, m, Q = map(int, input().split())
M = [[0]*n for _ in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    M[r-1][l-1] += 1

for q in range(n):
    for p in reversed(range(1, n)):
        M[q][p-1] += M[q][p]
for p in range(n):
    for q in range(n-1):
        M[q+1][p] += M[q][p]

for i in range(Q):
    p, q = map(int, input().split())
    print(M[q-1][p-1])
n=int(input())
a=list(map(int,input().split()))
a.sort()
mx=0
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=0
  comb=1
  for i in range(1,asmall+1): comb*=alarge-i+1
  for i in range(1,asmall+1): comb/=i
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
  comb=1
  for i in range(1,asmall+1): comb*=alarge-i+1
  for i in range(1,asmall+1): comb/=i
print("{} {}".format(alarge,asmall))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
alarge=a[n-1]
if a[0]>=alarge/2:
  asmall=a[0]
else:
  j=0
  while a[j]<alarge/2:
    j+=1
  if alarge<=a[j-1]+a[j]:
    asmall=a[j-1]
  else:
    asmall=a[j]
print("{} {}".format(alarge,asmall))
import heapq
from bisect import bisect_left,bisect
n = int(input())
s = list(input())
q = int(input())
al=[[] for i in range(26)]
for i in range(26):
    heapq.heapify(al[i])

for i in range(n):
    heapq.heappush(al[ord(s[i])-ord("a")],i)

for i in range(q):
    a , b , x = input().split()
    if a == "1":
        al[ord(s[int(b)-1])-ord("a")].remove(int(b)-1)
        heapq.heappush(al[ord(x)-ord("a")],int(b)-1)
    elif a == "2":
        b = int(b)-1
        x = int(x)-1
        cou = 0
        for j in range(26):
            l = bisect_left(al[j],b)
            r = bisect(al[j],x)
            if l != r:
                cou += 1
        print(cou)

### FIXED CODE ###

def main():
    from bisect import bisect_left,bisect
    n = int(input())
    s = list(input())
    q = int(input())
    al=[[] for i in range(26)]
    for i in range(n):
        al[ord(s[i])-97].append(i)
    ans = []
    for i in range(q):
        a , b , x = input().split()
        if a == "1":
            al[ord(s[int(b)-1])-97].pop(bisect_left(al[ord(s[int(b)-1])-97],int(b)-1))
            al[ord(x)-97].insert(bisect_left(al[ord(x)-97],int(b)-1),int(b)-1)
            s[int(b)-1] = x
        elif a == "2":
            b = int(b)-1
            x = int(x)-1
            cou = 0
            for j in range(26):
                l = bisect_left(al[j],b)
                r = bisect(al[j],x)
                if l != r:
                    cou += 1
            ans.append(cou)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()
s = int(input())
k = int(inout())

print(s[0] if s[0] != 1 else s[1])

### FIXED CODE ###

S = input()
K = input()

#A = int(l[0])


length_1 = len(S)
K = int(K)

i =int(S)
v_1 = []
#cnt = []
while i > 0:
    v_1.append( i % 10 )
    #cnt.append(1)
    i //= 10 # 必須
v_1.reverse()

length_n = 0
target_v_num = 0

while length_n < K:
    V = v_1[target_v_num]
    length_n = length_n + 1
    if V > 1:
        length_n = length_n + K
    target_v_num = target_v_num + 1


print(V)
File Edit Options Buffers Tools Python Help
import sys

l1 = sys.stdin.readline()
l2 = sys.stdin.readline()

nums = [int(x) for x in l1.rstrip('\n').split(' ')]
l2 = int(l2)

out = max(nums)

for i in xrange(l2):
  out *= 2
print out

### FIXED CODE ###

import sys
 
l1 = sys.stdin.readline()
l2 = sys.stdin.readline()
 
nums = [int(x) for x in l1.rstrip('\n').split(' ')]
l2 = int(l2)
 
out = max(nums)
 
for i in xrange(l2):
  out *= 2
print out + sum(nums) - max(nums)
s=str(input())
a=s.replace(s[3],'8')'
print(a)

### FIXED CODE ###

print("2018"+input()[4:])
s=list(input())
        v=list("CODEFESTIVAL2016")
        cnt=0
        for i in range(16):
            if s[i]!=v[i]:
                cnt+=1
        print(cnt)

### FIXED CODE ###

s=input()
v="CODEFESTIVAL2016"
cnt=0
for i in range(16):
    if s[i]==v[i]:
        cnt+=1
print(16-cnt)
import sys
input=sys.stdin.readline

N,D,A=map(int,input().split())
L=[]
for i in range(N):
    x,h=map(int,input().split())
    L.append([x,h])
L.sort()

import math

ans=0
S=0
P=0
RL=[0]
RC=[0]
cnt=0
for i in range(N):
    while RL[P]<L[i][0] and P<i:
        cnt+=RC[P]
        P+=1
    if L[i][1]-S+cnt>0:
        ans+=math.ceil((L[i][1]-S+cnt)/A)
        RL=RL[:len(RL)-1]
        RC=RC[:len(RC)-1]
        RL+=[L[i][0]+2*D]
        RC+=[math.ceil((L[i][1]-S+cnt)/A)*A]
        S+=math.ceil((L[i][1]-S+cnt)/A)*A
    #print(i,ans,P)
print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

N,D,A=map(int,input().split())
L=[]
for i in range(N):
    x,h=map(int,input().split())
    L.append([x,h])
L.sort()

import math

ans=0
S=0
P=0
RL=[0]
RC=[0]
cnt=0
for i in range(N):
    for j in range(P,len(RL)):
        if RL[P]<L[i][0]:
            cnt+=RC[P]
            P+=1
        else:
            break
    if L[i][1]-S+cnt>0:
        ans+=math.ceil((L[i][1]-S+cnt)/A)
        
        RL+=[L[i][0]+2*D]
        RC+=[math.ceil((L[i][1]-S+cnt)/A)*A]
        S+=math.ceil((L[i][1]-S+cnt)/A)*A
    #print(i,ans,P,RL,RC,S,cnt)
print(ans)
N, K = map(int, input())
print(N - (K - 1))


### FIXED CODE ###

N, K = map(int, input().split())
print(N - (K - 1))
print(A)
# 全探索で間に合う？
def is_match(a, b):
    return (a==b).all()
flag = False
for i in range(N):
    for j in range(N):
        x_left = i
        x_right = i + M
        y_up = j
        y_under = j + M
        if x_right >= N or y_under >= N:
            continue
        if is_match(B, A[x_left:x_right, y_up:y_under]):
            flag = True
if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())

A = []
for i in range(N):
    tmp = input()
    A.append([0 if s=="." else 1 for s in tmp])
B = []
for i in range(M):
    tmp = input()
    B.append([0 if s=="." else 1 for s in tmp])
    
A = np.array(A)
B = np.array(B)

def is_match(a, b):
    return (a==b).all()
flag = False
for i in range(N):
    for j in range(N):
        x_left = i
        x_right = i + M
        y_up = j
        y_under = j + M
        if x_right > N or y_under > N:
            continue
        if is_match(B, A[x_left:x_right, y_up:y_under]):
            flag = True
if flag:
    print("Yes")
else:
    print("No")
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
for i in range(1,N+2):
    D += L[i-1]
    if D>X:
        print(i)
        exit()

### FIXED CODE ###

N, X = map(int, input().split())
L = list(map(int, input().split()))
count = 1
D = 0
for i in range(N):
    D += L[i]
    if D<=X:
        count += 1
print(count)
N = int input()
a = list(map(int,input().split()))
b = 0

for i in range(N):
  if a[i] % != 2:
    if a[i] % != 3 or a[i] % != 5:
      b = 1
      break
if b == 0:
  print("APPROVED")
else:
  print("DENIDED")


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
c = 0
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] %3 != 0 :
            if A[i] %5 != 0:
                c = 1
                break
if c == 0:
    print("APPROVED")
else:
    print("DENIED")
from collections import deque

N = int(input())

q = {}

for i in range(N):
    q[i] = []

for _ in range(N - 1):
    _u, _v, _w = map(int, input().split())

    q[_u - 1].append((_v - 1, _w))
    q[_v - 1].append((_u - 1, _w))

ans = [None] * N
ans[0] = 0


def search(x, parent_num):
    for s in q[x]:
        if ans[s[0]] is None:
            ans[s[0]] = (parent_num + s[1]) % 2
            search(s[0], ans[s[0]])


search(0, 0)

for i in range(N):
    print(ans[i])


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)

N = int(input())

q = {}

for i in range(N):
    q[i] = []

for _ in range(N - 1):
    _u, _v, _w = map(int, input().split())

    q[_u - 1].append((_v - 1, _w))
    q[_v - 1].append((_u - 1, _w))

ans = [None] * N
ans[0] = 0


def search(x, parent_num):
    for s in q[x]:
        if ans[s[0]] is None:
            ans[s[0]] = (parent_num + s[1]) % 2
            search(s[0], ans[s[0]])


search(0, 0)

for i in range(N):
    print(ans[i])
N = int(input())
c = 0
tail_A = 0
head_B = 0
B_A = 0
def count(S):
    if len(S) == 1:
        return 0
    c = 0
    for i in range(len(S)-1):
        if S[i] == 'A' and S[i+1] == 'B':
            c += 1
    return c

for _ in range(N):
    s = input()
    c += count(s)
    if s[-1] == 'A':
        if s[0] == 'B':
            B_A += 1
        else:
            tail_A += 1
    else:
        if s[0] == 'B':
            head_B += 1

if tail_A > 0 and head_B > 0:
    c = c + B_A + 1
    tail_A -= 1
    head_B -= 1
elif tail_A == 0 and head_B > 0:
    c = c + B_A
    head_B -= 1
elif tail_A > 0 and head_B == 0:
    c = c + B_A
    tail_A -= 1
else:
    c = c + B_A - 1

c += min(tail_A, head_B)
print(c)


### FIXED CODE ###

N, K = list(map(int, input().split()))
print(N-K+1)
import Re
a=input()
b=re.compile('^[^L][^R]*[^L]?$')
if a.match(b):
print('Yes')
else:
print('No')

### FIXED CODE ###

import re #与えられた条件にマッチする文字列か判定
a = input()
b = re.compile(r'^([^L][^R])*[^L]?$')
if b.match(a):
    print('Yes')
else:
    print('No')
s =input()
v = ['a','e','i','o','u']
for i in v:
  if s = i:
    print(vowel)
  else:
    print(consonant

### FIXED CODE ###

c = input()
if c in 'aeiou':
  print('vowel')
else:
  print('consonant')
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
x,y = map(int, input().split())

xs = []
ys = []
isx = True
i = 0
n = len(s)
while i<n and s[i]=="F":
    x -= 1
    i += 1

while i<n:
    c = 0
    while i<n and s[i]=="F":
        i += 1
        c += 1
    if isx and c>0:
        xs.append(c)
    elif c>0:
        ys.append(c)
    isx = not isx
    i += 1
    
def sub(l, target):
    # lの一部の符号を反転してtargetを作れるか
    val = sum(l)
    prev = [False] * (2*(val+1))
    prev[val] = True
    current = None
    for num in l:
        current = [False] * (2*(val+1))
        for i in range(2*(val+1)):
            if i-num>=0 and prev[i-num]:
                current[i] = True
            if i+num<(2*val+2) and prev[i+num]:
                current[i] = True
        prev = current
    if current is None:
        current = prev
    return current[target+val]

if sum(abs(item) for item in xs)>=x and sum(abs(item) for item in ys)>=y and sub(xs, x) and sub(ys, y):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
x,y = map(int, input().split())

xs = []
ys = []
isx = True
i = 0
n = len(s)
while i<n and s[i]=="F":
    x -= 1
    i += 1

while i<n:
    c = 0
    while i<n and s[i]=="F":
        i += 1
        c += 1
    if isx and c>0:
        xs.append(c)
    elif c>0:
        ys.append(c)
    isx = not isx
    i += 1
    
def sub(l, target):
    # lの一部の符号を反転してtargetを作れるか
    val = sum(l)
    prev = [False] * (2*(val+1))
    prev[val] = True
    current = None
    for num in l:
        current = [False] * (2*(val+1))
        for i in range(2*(val+1)):
            if i-num>=0 and prev[i-num]:
                current[i] = True
            if i+num<(2*val+2) and prev[i+num]:
                current[i] = True
        prev = current
    if current is None:
        current = prev
    return current[target+val]

if sum(abs(item) for item in xs)>=abs(x) and sum(abs(item) for item in ys)>=abs(y) and sub(xs, x) and sub(ys, y):
    print("Yes")
else:
    print("No")
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)


### FIXED CODE ###

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0 and l:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)
K = int(input())
X = int(input())
s = X-K+1
e = X+K-1
for i in range(s,e):
    print(i)

### FIXED CODE ###

S = input().split()
K = int(S[0])
X = int(S[1])
s = X-K+1
e = X+K-1
for i in range(s, e):
    print(str(i)+' ')
print(e)
import math
N = int(input())
print(int(2 * N / (math.gcd(2, N)) ))

### FIXED CODE ###

N = int(input())
if N % 2 == 0:
	print(N)
else:
	print(2 * N)
a,b,c,d = map(int,input().split())
if abs(a-b)<=d:
        if abs(b-c)<=d:
                print("Yes")
        elif:
                print('No')
elif abs(a-c)<=d:
        print("Yes")
else:
        print("No")


### FIXED CODE ###

a,b,c,d = map(int,input().split())
if abs(a-b)<=d:
        if abs(b-c)<=d:
                print("Yes")
        else:
                print("No")
elif abs(a-c)<=d:
        print("Yes")
else:
        print("No")
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if max(a) < k:
    print("IMPOSSIBLE")
    exit()
m = 10**9
for i in range(n-1):
    m = min(m, abs(a[i+1]-a[i]))
for i in range(n):
    if abs(a[i]-k) % m == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


### FIXED CODE ###

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

a = sorted(list(set(a)))

if a[-1] < k:
    print("IMPOSSIBLE")
    exit()

n = len(a)

if n > 1:
    m = 10**9
    for i in range(n-1):
        if a[i] != a[i+1]:
            m = min(m, abs(a[i+1]-a[i]))
    for i in range(n):
        if abs(a[i]-k) % m == 0:
            print("POSSIBLE")
            exit()
else:
    if a[0] == k:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx):
    while b[b_idx]+prog<=k or b_idx<m:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    if b_idx==m:
        break
    a_idx-=1
    prog-=a[a_idx]

print(mx)

### FIXED CODE ###

import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
prog=0
a_idx=0
b_idx=0

while a_idx<n:
    if a[a_idx]+prog>k:
        break
    prog+=a[a_idx]
    a_idx+=1

if a_idx==n:
    while b_idx<m:
        if b[b_idx]+prog>k:
            break
        prog+=b[b_idx]
        b_idx+=1

mx=a_idx+b_idx

if mx==n+m:
    print(mx)
    sys.exit()

for i in range(a_idx+1):
    while b_idx<m and b[b_idx]+prog<=k:
        prog+=b[b_idx]
        b_idx+=1
    if a_idx+b_idx>mx:
        mx=a_idx+b_idx
    if b_idx==m:
        break
    if a_idx==0:
        break
    a_idx-=1
    prog-=a[a_idx]

print(mx)
def postorder(g):
    parent_stack = [None]
    dfs_stack = [(0, None)]            
    while dfs_stack:
        u, prev = dfs_stack.pop()
        dfs_stack.extend((t, u) for d, t in g[u])
        while parent_stack[-1] != prev:
            yield parent_stack.pop()
        parent_stack.append(u)
    while parent_stack[-1] is not None:
        yield parent_stack.pop()

from sys import stdin
from collections import defaultdict
readline = stdin.readline


n = int(readline())
g = defaultdict(list)
for _ in range(n - 1):
    s, t, d = map(int, readline().split())
    g[s].append((d, t))
diameter = []
dp = [0] * n
for i in postorder(g):
    if len(g[i]) == 0:
        continue
    candidate = sorted(d + dp[t] for d, t in g[i])
    dp[i] = candidate[-1]
    diameter.append(dp[i] if len(g[i]) == 1 else sum(candidate[-2:]))

print(max(diameter))

### FIXED CODE ###

def postorder(g):
    parent_stack = []
    dfs_stack = [(0, None)]            
    while dfs_stack:
        u, prev = dfs_stack.pop()
        dfs_stack.extend((t, u) for d, t in g[u])
        while parent_stack and parent_stack[-1] != prev:
            yield parent_stack.pop()
        parent_stack.append(u)
    while parent_stack:
        yield parent_stack.pop()

from sys import stdin
from collections import defaultdict
readline = stdin.readline

n = int(readline())
g = defaultdict(list)
for _ in range(n - 1):
    s, t, d = map(int, readline().split())
    g[s].append((d, t))
diameter = [0]
dp = [0] * n
for i in postorder(g):
    if len(g[i]) == 0:
        continue
    candidate = sorted(d + dp[t] for d, t in g[i])
    dp[i] = candidate[-1]
    diameter.append(dp[i] if len(candidate) == 1 else sum(candidate[-2:]))

print(max(diameter))
n = str(input())
count = 0
for j in range(len(n) - 4):
  for i in range(len(n) - 3 - j):
    if(int(n[i:4 + i + j]) % 2019 == 0):
       count += 1

print(count)


### FIXED CODE ###

x,y = map(int, input().split())
if(x <= y):
  print('unsafe')
else:
  print('safe')
a, b = map(int, input().split())
 
if a > 13:
  return b
elif a < 6:
  return 0
elif a >= 6 and a <= 12: 
  return int(b/2)

### FIXED CODE ###

a, b = map(int, input().split())
 
if a < 6:
  print(0)
elif a <= 12:
  print(int(b/2))
else: 
  print(b)
N, P = map(int, input().split())
S = input()

res = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
else:
    mp = [0]*len(S)
    mp[0] = 1
    cur = 0
    p10 = 1
    for c in S[::-1]:
        cur = (cur + int(c)*p10) % P
        res += mp[cur]
        mp[cur] += 1
        p10 *= 10
        p10 %= P

print(res)

### FIXED CODE ###

N, P = map(int, input().split())
S = input()

res = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            res += i + 1
else:
    mp = [0]*P
    mp[0] = 1
    cur = 0
    p10 = 1
    for c in S[::-1]:
        cur = (cur + int(c)*p10) % P
        res += mp[cur]
        mp[cur] += 1
        p10 *= 10
        p10 %= P

print(res)
a,b=map(int,input().split());print('NPeogsaittiivvee'[a>0or(b-a)%2::2]*(a*b>0)or'Zero')

### FIXED CODE ###

a,b=map(int,input().split());print('Zero'*(a+b==0or abs(a+b)<abs(a)+abs(b))or'NPeogsaittiivvee'[a>0or(b-a)%2::2])
x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' x >= b-1 else 'dangerous')

### FIXED CODE ###

x, a, b = map(int, input().split())
print('delicious' if a >= b else 'safe' if x >= b-a else 'dangerous')
N, D = map(int, input().split())
B=2*D
A=N//2B+1
print(A)

### FIXED CODE ###

N, D = map(int, input().split())
B=2*D+1
if N % B == 0:
  A=N//B
else:
  A=N//B+1
print(A)
import math
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=min(w-abs(ax-bx),abs(ax-bx))
dy=min(h-abs(ay-by),abs(ay-by))
ans=1
if dx*2==w:ans*=2
if dy*2==h:ans*=2
ans*=comb(dx+dy,dx)
print(ans%100000007)

### FIXED CODE ###

from math import factorial
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=abs(ax-bx)
dx=min(dx,w-dx)
dy=abs(ay-by)
dy=min(dy,h-dy)
an=1
if dx*2==w:an*=2
if dy*2==h:an*=2
an*=comb(dx+dy,dx)
print(an%int(1E8+7))
A,B,C,D = map(int,input().split())
while true:
  A -= D
  B -= C
  if A <= 0 or B <= 0:
     break
if A <= 0:
   print('No')
else:
   print('Yes')

### FIXED CODE ###

import math
A,B,C,D = map(int,input().split())
E = math.ceil(A/D)
F = math.ceil(C/B)
if E >= F:
  print('Yes')
else:
  print('No')
N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(M):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b] - l[a] == c:
            x += d
    ans = max([ans, x])
print(ans)


### FIXED CODE ###

N, M, Q = [int(_) for _ in input().split()]
ABCD = [[int(_) for _ in input().split()] for _ in range(Q)]
cand = [[i] for i in list(range(1, M + 1))]
for i in range(N - 1):
    candn = []
    for l in cand:
        j = l[-1]
        candn += [l + [k] for k in range(j, M + 1)]
    cand = candn
ans = 0
for l in cand:
    x = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            x += d
    ans = max([ans, x])
print(ans)