Harryxun/stf_run huggingface dataset:
import math

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

a=N//B

if a==0:
    x=N
    

elif N%B==0:
    x=a*B-1
else:
    x=B*a-1

while math.floor(A*x/B)==math.floor(A*(x-1)/B):
    x=x-1
    if x==1:
        break
ans=math.floor(A*x/B)-A*math.floor(x/B)
ans=max(ans)

print(ans)


### FIXED CODE ###

import math

def floor(A,B,t):
    return(math.floor(A*t/B)-A*math.floor(t/B))

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


ans=floor(A,B,min(B-1,N))

print(ans)
n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut >= throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)




### FIXED CODE ###

n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut > throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)
            break
def main():
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a%b)

    def lcm(a, b):
        return int(a / gcd(a, b)) * b
    
    n, m = map(int, input().split())
    A = list(set([int(x) for x in input().split()]))
    a_ = A[0]
    for a in A[1:]:
        a_lcm = lcm(a_, a)
        a_ = a_lcm
    if a_lcm / 2 > m:
        print(0)
    else:
        ans = int((m - (a_lcm / 2))) // a_lcm + 1
        print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import copy
# from math import gcd


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return (a // gcd(a, b)) * b
def main():
    n, m = map(int, input().split())
    A = set([int(x) for x in input().split()])
    a_lcm = 1
    for a in A:
        a_lcm = lcm(a_lcm, a)
        # mがlcmの半分よりも小さかったら0
        if (a_lcm / 2) > m:
            print(0)
            exit()
    for a in A:
        if (a_lcm / 2) % a == 0:
            print(0)
            exit()
    # # あとは定数倍の数調べて終わり
    ans = int((m - (a_lcm / 2)) // a_lcm) + 1
    print(ans)

if __name__ == '__main__':
    main()
def cape(iri):
    ima = set()
    for i in iri:
        for j in root[i]:
            if ans[j] == 0:
 #               print("now", i, j, ima)
                ans[j] = i
 #               print(root[j])
                root[j] -= iri #ここが重そう
 #               print(root[j])
                ima.add(j) #ここも重そう
#                print(ima)
#    print(ima)
    if ima != set():
        cape(ima)

N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
#print(root)
cape({1})
print("Yes")
for i in range(2, N + 1):
    print(ans[i])

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
root = [set() for i in range(N + 1)]
ans = [0 for i in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    root[a].add(b)
    root[b].add(a)
task = deque([1])
itta = {1}
while len(task) > 0:
    now = task.popleft()
    additional = root[now] - itta
    for i in additional:
        ans[i] = now
        itta.add(i)
    task.extend(list(additional))
print("Yes")
for i in range(2, N + 1):
    print(ans[i])
print (int(raw_input()) + int(raw_input()) % 24

### FIXED CODE ###

print sum(map(int, raw_input().split())) % 24
N_K=input()
pn=input()
list_pn=[]
# N,K,Pnの切り出し
for i in range(len(N_K)):
    if N_K[i]==" ":
        N =int(N_K[0:i])
        K =int(N_K[i+1:len(N_K)])
a = 0
for i in range(len(pn)):
    if pn[i]==" ":
        list_pn.append(int(pn[a:i]))
        a = i
list_pn.append(int(pn[a+1:len(pn)]))
# Pnの期待値を計算
pn_ave=[]
for i in range(N):
    pn_ave.append((list_pn[i]+1)/2)
# Sj+k-Sjの累積和を用いて考える
Sj = []
Sj.append(0)
S=0
for i in range(N):
    S += pn_ave[i]
    Sj.append(S)
Sk = []
for i in range(N-K+1):
    Sk.append(Sj[i+K]-Sj[i])
Sk.sort()
print(Sk[-1])

### FIXED CODE ###

N,K=map(int,input().split())
list_pn=list(map(int,input().split()))
# Pnの期待値を計算
pn_ave=[]
for i in range(N):
    pn_ave.append((list_pn[i]+1)/2)
# Sj+k-Sjの累積和を用いて考える
Sj = []
Sj.append(0)
S=0
for i in range(N):
    S += pn_ave[i]
    Sj.append(S)
# print(Sj)
Sk = []
for i in range(N-K+1):
    Sk.append(Sj[i+K]-Sj[i])
# print(Sk)
Sk.sort()
print(Sk[-1])
l, r = map(int, input().split())
if r - l > 3000:
  print(0)
else:
  ans = 2000
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % 2019)
print(ans)

### FIXED CODE ###

l, r = map(int, input().split())
mod = 2019
if r - l > 3000:
  print(0)
else:
  ans = mod
  for i in range(l, r + 1):
    for j in range(r, l, -1):
      #print(str(i) + ' ' + str(j))
      if j <= i: break
      ans = min(ans, (i * j) % mod)
  print(ans)
n, K = map(int, input().split())
heights = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0
 
for i in range(1, n):
 
    dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
    if i > 1:
        for k in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - k] + abs(heights[i] - heights[i - k]))
 
print(dp[n - 1])

### FIXED CODE ###

n = int(input())
heights = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]))

print(dp[n - 1])
#coding:utf-8

elements[] = input().split()
w = elements[0]
h = elements[1]
x = elements[2]
y = elements[3]
r = elements[4]

if x<0 OR y<0:
    print("No")

elif x>=r AND y>=r AND x+r<=w AND y+r<=h:
        print("Yes")
else:
    print("No")



### FIXED CODE ###

# coding: utf-8
# Your code here!

#coding:utf-8

elements = input().split()
w = int(elements[0])
h = int(elements[1])
x = int(elements[2])
y = int(elements[3])
r = int(elements[4])

if x<=0 or y<=0:
    print("No")

elif x>=r and y>=r and x+r<=w and y+r<=h:
        print("Yes")
else:
    print("No")
import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B
 
N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)
 
K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))

### FIXED CODE ###

#!python3.8
# -*- coding: utf-8 -*-
# tokiomarine2020/tokiomarine2020_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    print(S[:3])
    return

main()
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

Rmin = 0
Rmax = 0
Cmin = 0
Cmax = 0

#行方向への探索
for r in range(H):
    #列方向への検索
    for c in range(W):
        #爆弾の場合、周りを加算
        if S[r][c] == ".":
            S[r][c] = 0
        elif S[r][c] == "#":
            if r == 0 :
                Rmin = r
                Rmax = r+2
            elif r == H-1:
                Rmin = r-1
                Rmax = r+1
            else:
                Rmin = r-1
                Rmax = r+2

            if c == 0:
                Cmin = c
                Cmax = c+2
            elif c == W-1:
                Cmin = c-1
                Cmax = c+1
            else:
                Cmin = c-1
                Cmax = c+2
            for i in range(Rmin,Rmax):
                for t in range(Cmin,Cmax):
                    if S[i][t] == "." or S[i][t] == 0:
                        S[i][t] = 1
                    elif not S[i][t] == "#":
                        S[i][t] += 1

for i in range(H):
    a =map(str,S[i])
    print(''.join(a))

### FIXED CODE ###

H,W = map(int,input().split())
S = [list(input()) for i in range(H)]

Rmin = 0
Rmax = 0
Cmin = 0
Cmax = 0

#行方向への探索
for r in range(H):
    #列方向への検索
    for c in range(W):
        #爆弾の場合、周りを加算
        if S[r][c] == ".":
            S[r][c] = 0
        elif S[r][c] == "#":
            if r == 0 and H == 1:
                Rmin = r
                Rmax = 1
            elif r == 0:    
                Rmin = r
                Rmax = r+2
            elif r == H-1:
                Rmin = r-1
                Rmax = r+1
            else:
                Rmin = r-1
                Rmax = r+2

            if c == 0 and W ==1 :
                Cmin = c
                Cmax = 1
            elif c == 0:
                Cmin = c
                Cmax = c+2
            elif c == W-1:
                Cmin = c-1
                Cmax = c+1
            else:
                Cmin = c-1
                Cmax = c+2
            for i in range(Rmin,Rmax):
                for t in range(Cmin,Cmax):
                    if S[i][t] == "." or S[i][t] == 0:
                        S[i][t] = 1
                    elif not S[i][t] == "#":
                        S[i][t] += 1

for i in range(H):
    a = map(str,S[i])
    print(''.join(a))
S_dash = list(map(str, input()))
T = list(map(str, input()))


for i in reversed(range(len(S_dash) - len(T) + 1)):
	flg = 1
	for j in range(len(T)):
		if S_dash[i + j] != "?" and S_dash[i + j] != T[j]:
			flg = 0
			break
	if flg:
		for j in range(len(T)):
			S_dash[i + j] = T[j]
		break
		
if flg:
	for i in range(len(S_dash)):
		if S_dash[i] == "?":
			print("a", end = "")
		else:
			print(S_dash[i], end = "")
else:
	print("UNRESTORABLE")

### FIXED CODE ###

S_prime = list(map(str, input()))
T = list(map(str, input()))

len_S = len(S_prime)
len_T = len(T)

un = 1

for i in reversed(range(0, len_S - len_T + 1)):
	match = 1
	for j in range(i, i + len_T):
		# print(S_prime[j], T[j - i])
		if S_prime[j] == "?": continue
		if not S_prime[j] == T[j - i]:
			match = 0
			break
	if match:
		un = 0
		# print(i)
		init = i
		break
		
if un:
	print("UNRESTORABLE")
else:
	for i in range(init, init + len_T):
		S_prime[i] = T[i - init]
	
	for i in range(len_S):
		if S_prime[i] == "?":
			print("a", end = "")
		else:
			print(S_prime[i], end = "")
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
ov=o.values()+[0]
ev=e.values()+[0]
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    else:
      mo=sorted(ov)[-2]
  print(n-mo-me)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
o['x']=0
e['x']=0
ov=o.values()
ev=e.values()
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    elif mo<me:
      mo=sorted(ov)[-2]
    else:
      mo=max(sorted(ev)[-2],sorted(ov)[-2])
  print(n-mo-me)
s = input()
t = input()
     
if s == t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz':
		print('Yes')
        exit(0)
else:        
print('No')

### FIXED CODE ###

s = input()
t = input()
     
if s == t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz':
		print('Yes')
		exit(0)       

print('No')
import collections
N = map(int, input().split())
A = list(map(int, input().split()))
Q = map(int, input().split())
 
base = 0
cnt = collections.Counter(A)
 
for i in range(N):
    base += A[i]
    
Ans = []
Ans.append(base + (C[0]-B[0]) * cnt[B[0]])
 
for i in range(Q-1):
  b ,c = map(int, input().split())
  Ans.append(Ans[i] + (c-b) * cnt[b])
  cnt[c] += cnt[b]
  cnt[b] = 0

print(Ans)

### FIXED CODE ###

import collections

n = int(input())
A = list(map(int, input().split()))
q = int(input())

CNT = collections.Counter(A)
ANS = []
ans = sum(A)

for i in range(q):
    b, c = map(int, input().split())
    t = CNT[b]
    ans +=(c - b) * t
    ANS.append(ans)
    CNT[c] += t
    CNT[b] = 0

for i in ANS:
    print(i)
cost = input()[0]
dvi, mod = dvimod(int(cost), 1000)
bills = dvi + 1
change = bills - mod
print(change)

### FIXED CODE ###

cost = input()
cost = int(cost)
div, mod = divmod(cost, 1000)
if mod == 0:
    bills = div
    change = 0
else:
    bills = div + 1
    change = 1000 - mod
print(change)
import numpy as np
from scipy.sparse.csgraph import shortest_path
import heapq
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append([w, v])
    edge[v].append([w, u])

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

Path_from_0 = dijkstra_heap(0)
for i in range(n):
    print(Path_from_0[i] % 2)



### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import shortest_path
import heapq
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append([w, v])
    edge[v].append([w, u])

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

Path_from_0 = dijkstra_heap(0)
for i in range(n):
    print(Path_from_0[i] % 2)
import random

class Dice():
    
    def __init__(self, *n):
       self.rolls = n

    def spin(self, order):
        if order == "N":
            self.rolls = [
                self.rolls[1],
                self.rolls[5],
                self.rolls[2],
                self.rolls[3],
                self.rolls[0],
                self.rolls[4]
            ]
        if order == "E":
            self.rolls = [
                self.rolls[3],
                self.rolls[1],
                self.rolls[0],
                self.rolls[5],
                self.rolls[4],
                self.rolls[2]
            ]
        if order == "S":
            self.rolls = [
                self.rolls[4],
                self.rolls[0],
                self.rolls[2],
                self.rolls[3],
                self.rolls[5],
                self.rolls[1]
            ]
        if order == "W":
            self.rolls = [
                self.rolls[2],
                self.rolls[1],
                self.rolls[5],
                self.rolls[0],
                self.rolls[4],
                self.rolls[3]
            ]
        return self.rolls[0]

d = Dice(*[int(i) for i in input().split()])
directions = ['N','E','S','W']
for _ in range(int(input())):
    a,b = [int(i) for i in input().split()]
    while a != d.rolls[0] or d.rolls[1] != b:
        d.spin(directions[random.randint(0,3)])
    print(d.rolls[2])

### FIXED CODE ###

class Dice():

    def __init__(self, *n):
       self.rolls = n

    def spin(self, order):
        if order == "N":
            self.rolls = [
                self.rolls[1],
                self.rolls[5],
                self.rolls[2],
                self.rolls[3],
                self.rolls[0],
                self.rolls[4]
            ]
        if order == "E":
            self.rolls = [
                self.rolls[3],
                self.rolls[1],
                self.rolls[0],
                self.rolls[5],
                self.rolls[4],
                self.rolls[2]
            ]
        if order == "S":
            self.rolls = [
                self.rolls[4],
                self.rolls[0],
                self.rolls[2],
                self.rolls[3],
                self.rolls[5],
                self.rolls[1]
            ]
        if order == "W":
            self.rolls = [
                self.rolls[2],
                self.rolls[1],
                self.rolls[5],
                self.rolls[0],
                self.rolls[4],
                self.rolls[3]
            ]
        return self.rolls[0]


d = Dice(*[int(i) for i in input().split()])
for order in list(input()):
    l = d.spin(order)
print(l)
A, B, K = map(int, input().split())

if K>=A + B:
	print ("0 0")
elif K>=A:
	print (str(0) + ' ' + str(B-(K-A)))
else:
  	print (str(A-K) + ' ' +str(B))


### FIXED CODE ###

S, T = input().split()
print (T+S)
n, k = input().split()
p = list(map(int, input().split()))

n, k = int(n), int(k)

s = []
a = 0
ans = 0

for i in range(n):
    c = 0
    a += p[i]
    s.append(a)
    
    if i <= 2:
        continue
    else:
        c = a - s[i - k + 1]
        c += k
        if c > ans:
            ans = c

print(ans / 2)


### FIXED CODE ###

N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e
#print(Data2)
sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

class UnionFind:
    def __init__(self, size):
        self.rank=[0]*size
        self.par =range(size)
        self.grp =size

    def find(self, x):
        if x==self.par[x]: return x

        self.par[x]=self.find(self.par[x])
        return self.par[x]

    def same(self, x, y): #2つの頂点が同じグループであるかを判定する
        return self.find(x)==self.find(y)

    def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する
        x,y=self.find(x),self.find(y)
        if x==y:
            return

        self.grp-=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def group_num(self):
        return self.grp
    def ra(self):
        return self.rank

n,k,l=map(int,raw_input().split())
uf=UnionFind(n)
q1,q2=[],[]
ans=[0]*n
for i in range(k):
    a,b=map(int,raw_input().split())
    uf.unite(a-1,b-1)
    q1.append((a-1,b-1))
    ans[a-1]=1
    ans[b-1]=1

for i in range(l):
    a,b=map(int,raw_input().split())
    if ans[a-1]==0: ans[a-1]=1
    if ans[b-1]==0: ans[b-1]=1
    if uf.same(a-1,b-1):
        ans[a-1]=2
        ans[b-1]=2

uf=UnionFind(n)
for i in q2:
    uf.unite(i[0],i[1])
for i in q1:
    if uf.same(i[0],i[1]):
        ans[i[0]]=2
        ans[i[1]]=2
    
print ' '.join(map(str,ans))

### FIXED CODE ###

t=raw_input()
#t=t.replace('eraser','').replace('dreamer','').replace('erase','').replace('dream','')
while len(t):
    if len(t)>10 and t[:11]=='dreameraser':
        t=t[11:]
    elif len(t)>9 and t[:10]=='dreamerase':
        t=t[10:]
    elif len(t)>6 and t[:7]=='dreamer':
        t=t[7:]
    elif len(t)>4 and t[:5]=='dream':
        t=t[5:]
    elif len(t)>5 and t[:6]=='eraser':
        t=t[6:]
    elif len(t)>4 and t[:5]=='erase':
        t=t[5:]
    else:
        break
print 'YES' if t=='' else 'NO'
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            break
            flag = True
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            break
            flag = True
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)


### FIXED CODE ###

from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            flag = True
            break
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            flag = True
            break
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)
n = int(input())
dD = [map(int, input().split()) for _ in range(5)]
d,D = [list(i) for i in zip(*dD)]
count = 0

for i in range(n-1):
  if d[i] == D[i]:
    count += 1
  else:
    count *= 0

if count >= 3:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
d = [list(map(int,input().split())) for i in range(n)]
count = 0

# [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6]]

for i in d:
  if i[0] == i[1]:
    count += 1
  else:
    count = 0
  if count == 3:
    print('Yes')
    exit()
print('No')