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

# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        dp = [False] * (len(S) + 1)

        words = ["dream", "dreamer", "erase", "eraser"]

        dp[0] = True
        for i in range(len(S)):
            if not dp[i]:
                continue
            for word in words:
                if S[i:].startswith(word):
                    dp[i + len(word)] = True

        print('YES' if dp[len(S)] else 'NO')


# Run main
if __name__ == '__main__':
    AtCoder().main()

### FIXED CODE ###

# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()

        while len(S) > 0:
            if S[:11] == 'dreameraser':
                S = S[11:]
            elif S[:10] == 'dreamerase':
                S = S[10:]
            elif S[:7] == 'dreamer':
                S = S[7:]
            elif S[:6] == 'eraser':
                S = S[6:]
            elif S[:5] == 'dream' or S[:5] == 'erase':
                S = S[5:]
            else:
                print('NO')
                exit()
        print('YES')


# Run main
if __name__ == '__main__':
    AtCoder().main()
### BUGGY CODE ###

s = input()
res = s.count('ABC')

for i in range(len(s)):
  s = s.replace('ABC', 'BCA')
  res += s.count('ABC')
  
  
print(res)

### FIXED CODE ###

import re
import sys
input = sys.stdin.readline

s = input()
s = s.replace('BC', 'D')
s = re.split('[BC]', s)
res = 0

for kk in s:
  if not kk:
    continue
  d = 0
  for a in kk[::-1]:
    if a == 'D':
      d += 1
    else:
      res += d
    
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 1
    
    if k == n:
        for a in A:
            ans *= a
        print(ans%(10**9+7))
        
    elif k%2==1 and all([a<0 for a in A]):
        A = sorted(A, key=lambda x:abs(x))
        for a in A[:k]:
            ans*=a
        print(ans%(10**9+7))

    else:
        A = sorted(A, key=lambda x:abs(x), reverse=True)
        x1, x2 = None, None
        for a in A[:k]:
            ans*=a
            if a >= 0 and (x1 is None or a < x1): x1 = a
            if a < 0 and (x2 is None or a > x2): x2 = a
            
        if ans >= 0:
            print(ans%(10**9+7))
        else:
            y1, y2 = None, None
            for a in A[k:]:
                if a < 0 and (y1 is None or a < y1): y1 = a
                if a >= 0 and (y2 is None or a > y2): y2 = a
            
            tmp = [ans]
            if x1!=None and y1!=None:
                tmp.append(ans//x1*y1)
            if x2!=None and y2!=None:
                tmp.append(ans//x2*y2)
            ans = max(tmp)
            print(ans%(10**9+7))            
main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    A = sorted(map(int, input().split()))
    mod = 10**9 + 7
    ans, sign = 1, 1

    l, r = 0, n-1

    if k%2:
        ans = A[r]
        r-=1
        k-=1
        if ans < 0:
            sign = -1
    while k:
        x = A[l]*A[l+1]
        y = A[r]*A[r-1]

        if x*sign > y*sign:
            ans = x%mod * ans%mod
            l+=2
        else:
            ans = y%mod * ans%mod
            r-=2
        k-=2
    print((ans+mod)%mod)
main()
### BUGGY CODE ###

n = int(input())
dif = list(map(int, input().split()))
divide = 0
for k in range(min(dif), max(dif)+1):
    count_over = 0
    count_under = 0
    for i in range(len(dif)):
        if dif[i] >= k:
            count_over += 1
        else:
            count_under += 1
    if count_over == count_under:
        divide += 1
print(divide)

### FIXED CODE ###

n = int(input())
dif = list(map(int, input().split()))
dif.sort()

divide = 0

medium = int((len(dif)) / 2)


if (len(dif)) %2 != 0:
    print(divide)
else:
    divide = dif[medium] - dif[medium-1]
    print(divide)
### BUGGY CODE ###

MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        mask = 1 << (N-1)
        for iW in range(N):
            if A2 & mask:
                 dp[patW ^ mask] += dpNow
                 dp[patW ^ mask] %= MOD
            mask >>= 1

print(dp[0])


### FIXED CODE ###

MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

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

s=input()
k=int(input())

se=set()
for i in range(len(s)):
	for j in range(i,len(s)):
		se.add(s[i:j+1])
print(sorted(list(se))[k-1])


### FIXED CODE ###

s=input()
k=int(input())

se=set()
for i in range(len(s)):
	for j in range(i,i+5):
		se.add(s[i:j+1])
print(sorted(list(se))[k-1])
### BUGGY CODE ###

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

ans = 0
for i, j in enumerate(P):
    if min(P[:i + 1]) >= j:
        ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
p_min = P[0]
for i, j in enumerate(P):
    if p_min >= j:
        ans += 1
        p_min = j

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

import sys
input = sys.stdin.readline
import functools

def multiplication2(n,a):
    acc = functools.reduce(lambda x,y:x*y, a)
    if 10**18 < acc:
        acc = -1

    return acc

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    acc = functools.reduce(lambda x,y:x*y, a)
    if 10**18 < acc:
        acc = -1
    print(acc)
    #print(multiplication2(n,a))


### FIXED CODE ###

import sys
input = sys.stdin.readline
import functools

def multiplication2(n,a):
    #acc = functools.reduce(lambda x,y:x*y, a)
    acc = 1
    a_sorted = sorted(a)
    if a_sorted[0] == 0:
        return 0
    
    for s in a_sorted:

        acc = acc*s
        if 10**18 < acc:
            acc = -1
            break
    return acc

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(multiplication2(n,a))
### BUGGY CODE ###

N = int(input())
X = list(map(int, input().split()))

for i in range(0, N):
    if i == 0:
        l = X[1:N]
    else:
        l = X[0:i] + X[i+1:N]
    l.sort()
    mid = N // 2 - 1
    print(l[mid])


### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
sX = sorted(X)
mid = N // 2 - 1

for x in X:
    if sX[mid] >= x:
        print(sX[mid + 1])
    else:
        print(sX[mid])
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
L.sort()
count = 0

for i in range(N):
  for j in range(i+1,N):
    summation = L[i] + L[j]
    subtract  = L[j] - L[i]
    D=L.copy()
    del D[j]
    del D[i]
    #E=[ D[k] for k in range(N) if k!= i and k!= j ]
    #求めるものはjよりも長くsummationよりも小さいもの
    ##summationより小さいかを二分探索
    high = N-3
    low = j-2
    if D[0] >= summation:
      upper = 0 #1つも満たさない
      #print(L[i],L[j],D,upper)
    elif D[-1] < summation:
      upper = N-1-j #すべてOK
    else:
      while high > low+1:
        mid =(high + low) // 2
        if D[mid] >= summation: #大きすぎ
          high = mid
          # mid = low
        else: #小さすぎかちょうど
          low = mid
          # mid =high 
      upper = high +1-j
    #print("summation",summation,D,upper)
    count += upper #-lower
print(count)  

### FIXED CODE ###

from bisect import bisect_left
 
N = int(input())
L = sorted(list(map(int, input().split())))
 
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a = L[i]
        b = L[j]
        idx = bisect_left(L, a + b)
        ans += idx - 1 - j
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = 1
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else -Dc
        if Dc < 0:
           Pattern *= LRsub
        LRsub += Dc

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)
### BUGGY CODE ###

input()
a = list(map(int,input().split()))
sa = list(set(a))
sa.sort(reverse=True)
ans = 0
count = 0

for i in sa:
    if count>=2:
        break

    if a.count(i)>=2:
        if count==0:
            ans = i
            count +=1
            if a.count(i)>3:
                if count < 2:
                    ans *= i
                    count +=1
        else:
            ans *= i
            count +=1


print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)
### BUGGY CODE ###

a,b,k = map(int,input().split())
n = []
for i in range(a,b+1):
    n.append(i)
n.sort
if 2*k >= len(n):
    for i in n:
        print(i)
else:
    a = []
    a.extend(n[:k])
    a.extend(n[-k:])
    for i in a:
        print(i)
    

### FIXED CODE ###

a,b,k = map(int,input().split())
ans = []
if 2*k <= b-a+1:
    for i in range(k):
        ans.append(a+i)
        ans.append(b-i)
    ans = list(set(ans))
    ans = sorted(ans)
    for i in ans:
        print(i)
else:
    for i in range(a,b+1):
        print(i)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
bit = 0

for i in range(n):
  kkk = ( 1<<(a[i]-1) ) -1
  if bit&kkk == 0:
    ans += 1
  bit += 2**(a[i]-1)
  
    
  
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
mini = 10**9
ans = 0
for i in range(n):
  if a[i] < mini:
    ans += 1
    mini = a[i]
    
print(ans)
### BUGGY CODE ###

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

if k >= 100:
    k = 100

dp = [[0] * 2 for i in range(n)]

ans = l[:]

for i in range(k):
    for j in range(n):
        tmp = ans[j] + 0.5
        dp[j][0] = (j+1 - tmp)
        dp[j][1] = (j+1 + tmp)

    ans = [0] * n

    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1

else:
    print(*ans)


### FIXED CODE ###

import numpy as np
from numba import njit

@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

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

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)
### BUGGY CODE ###

import re

S = input()
ct = 0

while True:
  D = re.findall('A+BC',S)
  if len(D)==0:
    break
  for d in D:
    num = len(d)-2
    R=re.subn(d, 'BC'+'A'*num, S)
    S=R[0]
    ct+=R[1]*num
print(ct)

### FIXED CODE ###

import re

S = input()
ct = 0

na = 0
bf = False
ct = 0
for s in S:
  if s =='A':
    if bf==True:
      na = 1
    else:
      na += 1
    bf = False
      
  if s == 'B':
    if na > 0 and bf==False:
      bf = True
    else:
      na = 0
      bf = False
  if s == 'C':
    if bf:
      ct += na
    else:
      na = 0
    bf = False
print(ct)
### BUGGY CODE ###

def d():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    # print('A = {}'.format(A))
    warps = [1]

    for i in range(K):
        city = A[warps[-1] - 1]
        # print('city, warps = {}, {}'.format(city, warps))
        if city in warps:
            loop_start_index = warps.index(city)
            Kn = (K - loop_start_index) % (len(warps) - loop_start_index)
            print(warps[loop_start_index + Kn])
            return
        else:
            warps.append(city)
    print(warps[-1])


##########
if __name__ == "__main__":
    d()


### FIXED CODE ###

def d():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    # print('A = {}'.format(A))
    warps = [1]
    w = {}

    for i in range(K):
        city = A[warps[-1] - 1]
        # print('city, warps = {}, {}'.format(city, warps))
        if city in w:
            lsi = warps.index(city)
            Kn = (K - lsi) % (len(warps) - lsi)
            print(warps[lsi + Kn])
            return
        else:
            warps.append(city)
            w[city] = city
    print(warps[-1])


def dd():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    v = []
    w = {}
    now = 0
    for i in range(K):
        print('i, v, w, now = {}, {}, {}, {}'.format(i, v, w, now))
        p = A[now]
        now = p-1
        if p in w:
            j = v.index(p)
            df = i-j
            Kn = (K-i-1) % df
            p = v[j+Kn]
            break
        else:
            v.append(p)
            w[p] = p
    print(p)


##########
if __name__ == "__main__":
    d()
### BUGGY CODE ###

n=int(input())
p=set(['3','5','7'])
ans=0
for i in range(357,n+1):
  ans+=((len(p-set(str(i)))==0) and (len(set(str(i))-p)==0))
print(ans)

### FIXED CODE ###

N=int(input())

nums=[]
all=set(['3','5','7'])
def dfs(x):
  if x>N:
    return
  if x>=357:
    if len(all-set(list(str(x))))==0:
      nums.append(x)
  for i in (3,5,7):
    dfs(x*10+i)

dfs(0)
print(len(nums))
### BUGGY CODE ###

s = str(input())
n = int(input())

for _ in range(n):
    q = input()

    # 反転の場合
    if q[0] == "1":
        s = s[::-1]
        continue

    # q = q.split()

    if q[2] == "1":
        s = q[4] + s

    if q[2] == "2":
        s = s + q[4]

print(s)


### FIXED CODE ###

s = str(input())
n = int(input())

stat = 0
front = ""
back = ""

for _ in range(n):
    q = input()

    # 反転の場合
    if q[0] == "1":
        stat = (stat + 1) % 2
        continue

    judge = int(q[2])
    if stat == 1:
        if judge == 1:
            judge = 2
        elif judge == 2:
            judge = 1

    if judge == 1:
        front = q[4] + front 

    if judge == 2:
        back = back + q[4]

s = front + s + back
if stat == 1:
    s = s[::-1]

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

from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(1,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()

### FIXED CODE ###

from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(h,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
l = map(int, input().split())
re = 1
for i in l:
  re *= i

if re > 10 ** 18:
	print(-1)
else:
	print(re)


### FIXED CODE ###

def func(l):
	if 0 in l:
		return 0
	re = 1
	for i in l:
		re *= i
		if re > 10 ** 18:
			return -1
	return re
	
n = int(input())
l = list(map(int, input().split()))
print(func(l))
### BUGGY CODE ###

import sys
def main():
  n,q,*c=map(int,sys.stdin.buffer.read().split())
  a=[0]*q
  j,*b=t=[0]*9**6
  for i in sorted(range(q),key=lambda x:c[x+x-~n]):
    l,r=c[i+i+n],c[i+i-~n]
    while j<r:
      k=c[j]
      j+=1
      x,y,b[k]=b[k]+1,j+1,j
      while x<=n:
        t[x]+=1
        x=x+(x&-x)
      while y<=n:
        t[y]-=1
        y=y+(y&-y)
    s=0
    while l:
      s=s+t[l]
      l=l-(l&-l)
    a[i]=s
  print(' '.join(map(str,a)))
main()

### FIXED CODE ###

import sys
from operator import itemgetter
buf = sys.stdin.buffer
input = buf.readline
class BIT:
    def __init__(self, n):
        self.n = n
        self.tree = [0] * (n + 1)
    def add(self, i, x):
        n, tree = self.n, self.tree
        while i <= n:
            tree[i] += x
            i += i & -i
    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & -i
        return s
def main():
    n, q = map(int, input().split())
    res = [0] * q
    *c, = map(int, input().split())
    q = [(i, l, r) for i, (l, r) in enumerate(zip(*[map(int, buf.read().split())] * 2))]
    q.sort(key=itemgetter(2))
    bit = BIT(n + 2)
    add, sum = bit.add, bit.sum
    b = [1] * (n + 1)
    j = 1
    for i, l, r in q:
        while j <= r:
            d = c[j - 1]
            j += 1
            k = b[d]
            b[d] = j
            add(k + 1, 1)
            add(j + 1, -1)
        res[i] = sum(l + 1)
    print(' '.join(map(str, res)))
main()
### BUGGY CODE ###

#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans_dict = {}
    for k in ball_dict:
        ans = 0
        for l in ball_dict:
            if k == l:
                ans += (ball_dict[l] - 1) * (ball_dict[l] - 2) // 2
            else:
                ans += ball_dict[l] * (ball_dict[l] - 1) // 2
        ans_dict.setdefault(k, ans)

    for i in range(n):
        print(ans_dict[a[i]])

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
Q = deque()
h = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            Q.append([i, j])
        else:
            h += 1
Qtmp = deque()

yudrl = [0, 1, 0, -1]
xudrl = [1, 0, -1, 0]

c = 0
while h > 0:
    c += 1
    while len(Q) > 0:
        Qtmp.append(Q.pop())
    while len(Qtmp) > 0:
        q = Qtmp.pop()

        for i in range(4):
            y = q[0] + yudrl[i]
            x = q[1] + xudrl[i]

            if y < 0 or y > H - 1 or x < 0 or x > W - 1:
                continue
            if A[y][x] == '#':
                continue
            A[y][x] = '#'
            h -= 1
            Q.append([y, x])
print(c)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
Q = deque()
h = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            Q.append([i, j])
        else:
            h += 1
Qtmp = deque()

yudrl = [0, 1, 0, -1]
xudrl = [1, 0, -1, 0]

c = 0
while h > 0:
    c += 1
    while len(Q) > 0:
        Qtmp.append(Q.pop())
    while len(Qtmp) > 0:
        q = Qtmp.pop()

        for i in range(4):
            y = q[0] + yudrl[i]
            x = q[1] + xudrl[i]

            if y < 0 or y > H - 1 or x < 0 or x > W - 1:
                continue
            if A[y][x] == '#':
                continue
            A[y][x] = '#'
            h -= 1
            Q.append([y, x])
print(c)
### BUGGY CODE ###

import math


def solve(n, pts):
    ans = [0] * n
    _sin, _cos = math.sin, math.cos

    div = 200000
    pi2 = math.pi * 2
    for k in range(div):
        a = pi2 * k / div
        tmp_max, tmp_i = 0, 0
        for i, (x, y) in enumerate(pts):
            b = x * _sin(a) + y * _cos(a)
            if tmp_max < b:
                tmp_max, tmp_i = b, i
        ans[tmp_i] += 1
    return [v / div for v in ans]


n = int(input())
pts = [list(map(int, input().split())) for _ in range(n)]
print('\n'.join(map(str, solve(n, pts))))


### FIXED CODE ###

import numpy as np
from scipy.spatial import ConvexHull
from scipy.spatial.qhull import QhullError


def solve(n, pts):
    ans = [0] * n

    try:
        hull = ConvexHull(pts)
    except QhullError:
        lm = np.argmin(pts, axis=0)
        rm = np.argmax(pts, axis=0)
        if lm[0] != rm[0]:
            l, r = lm[0], rm[0]
        elif lm[1] != rm[0]:
            l, r = lm[1], rm[0]
        else:
            l, r = lm[0], rm[1]
        ans[l] = ans[r] = 0.5
        return ans

    ps = np.array(list(map(pts.__getitem__, hull.vertices)))
    vs = ps - np.roll(ps, 1, axis=0)

    vt = vs.T
    vt[0] *= -1
    arcs = np.arctan2(*vt)
    arcs = np.append(arcs, arcs[0])
    da = np.diff(arcs) / (2 * np.pi) % 1

    for i, a in zip(hull.vertices, da):
        ans[i] = a

    return ans


n = int(input())
pts = [list(map(int, input().split())) for _ in range(n)]
print('\n'.join(map(str, solve(n, pts))), end='')