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

import sys
def rec(N,dp,i,j,k):
    if dp[i][j][k]>=0:return dp[i][j][k]
    if all([i==0,j==0,k==0]):return 0.0
    res=0.0
    if i>0:res+=rec(N,dp,i-1,j,k)*i
    if j>0:res+=rec(N,dp,i+1,j-1,k)*j
    if k>0:res+=rec(N,dp,i,j+1,k-1)*k
    res+=N
    res*=1.0/(i+j+k)
    dp[i][j][k]=res
    return dp[i][j][k]
def main():
    N=int(sys.stdin.readline())
    a=tuple(map(int,sys.stdin.readline().split()))
    n1,n2,n3=a.count(1),a.count(2),a.count(3)
    dp=[[[-1 for _ in range(310)] for _ in range(310)] for _ in range(310)]
    print(rec(N,dp,n1,n2,n3))
if __name__=='__main__':main()

### FIXED CODE ###

import sys
def rec(N,dp,i,j,k):
    if dp[i][j][k]>=0.0:return dp[i][j][k]
    if all([i==0,j==0,k==0]):return 0.0
    res=0.0
    if i>0:res+=rec(N,dp,i-1,j,k)*i
    if j>0:res+=rec(N,dp,i+1,j-1,k)*j
    if k>0:res+=rec(N,dp,i,j+1,k-1)*k
    res=(res+N)*1.0/(i+j+k)
    dp[i][j][k]=res
    return dp[i][j][k]
def main():
    N=int(sys.stdin.readline())
    a=tuple(map(int,sys.stdin.readline().split()))
    n1,n2,n3=a.count(1),a.count(2),a.count(3)
    dp=[[[-1.0 for _ in range(n3+1)] for _ in range(n2+n3+1)] for _ in range(n1+n2+n3+1)]
    print(rec(N,dp,n1,n2,n3))
if __name__=='__main__':main()
### BUGGY CODE ###

[l,r] = [int(i) for i in input().split()]

mod = []	
if abs(l-r) == 1:
	print(l*r%2019)

else:
	for i in range(l,r):
		for j in range(l+1,r+1):
			rem = i%2019 *j%2019
			mod.append(rem)

	print(min(mod))	

### FIXED CODE ###

L, R = list(map(int, input().split(' ')))
#print(L, R)
 
min = 2019
for i in range(L, R):
    for j in range(i + 1, R + 1):
        mod_ij = (i * j) % 2019
        if min > mod_ij:
            min = mod_ij
            if min == 0:
                break
    if min == 0:
        break
print(min)
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
moves = ((1, 0), (-1, 0), (0, 1), (0, -1))
cnt = [[float('inf') for _ in range(w)] for _ in range(h)]
ans = 0
start = []
q = deque([])

def bfs():
  searched = [[0 for _ in range(w)] for _ in range(h)]
  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      if 0 <= y+dy < h and 0 <= x+dx < w and searched[y+dy][x+dx] == 0 and a[y+dy][x+dx] == '.' and cnt[y+dy][x+dx] > cnt[y][x]+1:
        searched[y+dy][x+dx] = 1
        q.append([y+dy, x+dx])
        cnt[y+dy][x+dx] = cnt[y][x]+1

for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      start.append([i, j])
      cnt[i][j] = 0
      q.append([i, j])

bfs()
for i in range(h):
  for j in range(w):
    ans = max(ans, cnt[i][j])

print(ans)

### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
moves = ((1, 0), (-1, 0), (0, 1), (0, -1))
cnt = [[float('inf') for _ in range(w)] for _ in range(h)]
ans = 0
searched = [[0 for _ in range(w)] for _ in range(h)]
q = deque([])

def bfs():
  while q:
    y, x = q.popleft()
    for dy, dx in moves:
      next_y = y + dy
      next_x = x + dx 
      if 0 <= next_y < h and 0 <= next_x < w and searched[next_y][next_x] == 0 and a[next_y][next_x] == '.' and cnt[next_y][next_x] > cnt[y][x]+1:
        searched[next_y][next_x] = 1
        q.append([next_y, next_x])
        cnt[next_y][next_x] = cnt[y][x]+1

for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      cnt[i][j] = 0
      searched[i][j] = 1
      q.append([i, j])

bfs()
for i in range(h):
  for j in range(w):
    ans = max(ans, cnt[i][j])

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

N,Q = map(int,input().split())
s = input()
L = []
for i in range(Q):
  L.append(list(input().split()))
def judge_left(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return True
    if x == N:
      return False
  return False
def judge_right(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return False
    if x == N:
      return True
  return False
ok = -1
ng = N
while ng-ok > 1:
  mid = (ng+ok)//2
  if judge_left(mid):
    ok = mid
  else:
    ng = mid
left = ok+1

ok = N
ng = -1
while ok-ng > 1:
  mid = (ng+ok)//2
  if judge_right(mid):
    ok = mid
  else:
    ng = mid
right = N-ok
print(max(N-left-right,0))

### FIXED CODE ###

N,Q = map(int,input().split())
s = input()
L = []
for i in range(Q):
  L.append(list(input().split()))
def judge_left(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return True
    if x == N:
      return False
  return False
def judge_right(x):
  for i in range(Q):
    if L[i][0] == s[x]:
      if L[i][1] == 'L':
        x -= 1
      else:
        x += 1
    if x == -1:
      return False
    if x == N:
      return True
  return False
ok = -1
ng = N
while ng-ok > 1:
  mid = (ng+ok)//2
  if judge_left(mid):
    ok = mid
  else:
    ng = mid
left = ok+1

ok = N
ng = -1
while ok-ng > 1:
  mid = (ng+ok)//2
  if judge_right(mid):
    ok = mid
  else:
    ng = mid
right = N-ok
print(max(N-left-right,0))
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = input()
    ans = 0
    password = [0, 0, 0]
    for i in range(1000):
        for j in range(3):
            password[j] = i // (10 ** j) % 10
        index = 2
        for k in range(n):
            if password[index] == int(s[k]):
                index -= 1
            if index == -1:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

n = int(input())
s = input()
ans = 0
password = [0, 0, 0]
for i in range(1000):
    for j in range(3):
        password[2 - j] = i // (10 ** j) % 10
    if str(password[0]) in s:
        index = s.index(str(password[0]))
        if str(password[1]) in s[index + 1:]:
            index2 = index + 1 + s[index + 1:].index(str(password[1]))
            if str(password[2]) in s[index2 + 1:]:
                ans += 1
print(ans)
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
ans = 0
for aa in range(a):
    k -=1
    ans+=1
    if k == 0:
        print(ans)
        exit()
for bb in range(b):
        k -=1
        if k == 0:
            print(ans)
            exit()
for bb in range(c):
        k -=1
        ans -= 1
        if k == 0:
            print(ans)
            exit()

### FIXED CODE ###

a,b,c,k = map(int,input().split())
aa=a
if k == 0:
    print(0)
elif a > k:
    print(k)
elif a+b >= k:
    print(a)
else:
    ab = a+b
    ans = aa-(k-ab)
    print(ans)
### BUGGY CODE ###

n,s=open(0);a=i=j=0
while j<3e7:f=s[i:j]in s[j:];a=max(a,j*f-i);j+=f;i+=f^1
print(a)

### FIXED CODE ###

from subprocess import*
with open('e.cpp','w')as f:f.write(r"""
#include<iostream>
using namespace std;
main(){
  int n;
  string s;
  cin>>n>>s;
  int a=0;
  for(int i=0;i<n;++i){
    int t=0;
    for(int j=0;j<n-i;++j){
      t=(t+1)*(s[j]==s[j+i]);
      a=max(a,min(t,i));
    }
  }
  cout<<a;
}""")
call(('g++','e.cpp'))
call('./a.out')
### BUGGY CODE ###

def get_input_line():
    return list(map(int, input().split()))
n, k = get_input_line()
p_list = get_input_line()

def calc_dice_score(p):
    return 0.5*(p+1)

def calc_score(score_list):
    return sum(score_list)

dice_scores = [calc_dice_score(p) for p in p_list]

score_list = []

for i in range(n- k + 1):
    score_list.append(sum(dice_scores[i:i+k]))
print(max(score_list))

### FIXED CODE ###

import collections

def get_input_line():
    return list(map(int, input().split()))
n, k = get_input_line()
p_list = get_input_line()

def calc_dice_score(p):
    return 0.5*(p+1)

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0] * n

max_score = 0
tmp_score = 0

for i in range(k):
    dice_scores[i] = 0.5*(p_list[i]+1)
    tmp_score += dice_scores[i]

max_score = tmp_score
for i in range(1, n- k + 1):
    dice_scores[i+k-1] = 0.5*(p_list[i+k-1]+1)
    tmp_score -= dice_scores[i-1]
    tmp_score += dice_scores[i+k-1]
    max_score = max(max_score, tmp_score)
print(max_score)
### BUGGY CODE ###

S = str(input())
s = S
while '01' in s or '10' in s:
    s = s.replace('01','')
    s = s.replace('10','')
print(len(S) - len(s))

### FIXED CODE ###

S = str(input())
s = S
cont0 = s.count('0')
cont1 = s.count('1')
if cont0 > cont1:
    print(cont1 * 2)
else:
    print(cont0 * 2)
### BUGGY CODE ###

N=int(input())

dp=[-1 for i in range(N)]

def comb(num):
    if dp[num]!=-1:
        return dp[num]
    dp[num]=(num*(num-1))//2
    return dp[num]

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

dict={i:0 for i in A}

for i in A:
    dict[i]+=1

for i in A:
    num=0
    for j in dict.keys():
        if j==i:
            num+=comb(dict[j]-1)
            continue
        num+=comb(dict[j])
    print(num)

### FIXED CODE ###

import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

for i in range(N):
    ans=num-(nums[A[i]]-1)
    print(ans)
### BUGGY CODE ###

S = input()

N = len(S)
l = [int(x) for x in list(str(S))]

count = 0
idx = 0
len_S = 0

while True:
    if len(l) <= 1:
        break
    if (l[idx] == 0 and l[idx+1] == 1) or (l[idx] == 1 and l[idx+1] == 0):
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        continue
    if idx+1 == len(l)-1:
        break
    idx += 1

print(count)

### FIXED CODE ###

S = input()

l0 = 0
l1 = 0

for i in S:
    if i == '0':
        l0 += 1
    elif i == '1':
        l1 += 1

ans = min(l0, l1) * 2

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

a = int(input())
b = list(map(int, input().split(" ")))
flag = True
for i in b:
  if (b.count(i) >= 2):
    flag = False

if (flag == True):
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a = int(input())
b = list(map(int, input().split(" ")))
t = set(b)
bb = list(t)

if (len(b) == len(bb)):
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

H, N = map(int, input().split(" "))
dp = [1e10 for i in range(H + 1)]
dp[0] = 0

for i in range(N):
    A, B = map(int, input().split(" "))
    for j in range(H + 1):
        if dp[j] != 1e10:
            dp[min(j + A, H)] = min(dp[min(j + A, H)], dp[j] + B)
print(dp[H])


### FIXED CODE ###

import sys
input = sys.stdin.readline

H, N = map(int, input().split(" "))
dp = [1e10 for i in range(H + 1)]
dp[0] = 0

for i in range(N):
    A, B = map(int, input().split(" "))
    for j in range(H + 1):
        if dp[j] != 1e10:
            dp[min(j + A, H)] = min(dp[min(j + A, H)], dp[j] + B)
print(dp[H])
### BUGGY CODE ###

N , M = map(int, input().split())

L=[[0]*2 for i in range(M)]

for i in range(M):
    L[i][0] , L[i][1] = map(int, input().split())

A=[10**10]*M
B=[10**10]*M

L=sorted(L ,key=lambda x: x[0])

for i in range(M):
    if L[i][0] == 1:
        A[i]=L[i][1]
    else:
        break

L=sorted(L ,key=lambda x: -x[1])

for i in range(M):
    if L[i][1] == N:
        B[i]=L[i][0]
    else:
        break

for i in A:
    if i == 10**10 : 
        print("IMPOSSIBLE")
        exit()

    for j in B:
        if i == j:
            print("POSSIBLE")
            exit()
        if j == 10**10 : break
print("IMPOSSIBLE")


### FIXED CODE ###

N , M = map(int, input().split())

L=[[0]*2 for i in range(M)]

for i in range(M):
    L[i][0] , L[i][1] = map(int, input().split())

A=[0]*M
B=[0]*M

L=sorted(L ,key=lambda x: x[0])

for i in range(M):
    if L[i][0] == 1:
        A[i]=L[i][1]
    else:
        break
A=A[0:i]

L=sorted(L ,key=lambda x: -x[1])

for i in range(M):
    if L[i][1] == N:
        B[i]=L[i][0]
    else:
        break
B=B[0:i]

if((len(A)==0)or(len(B)==0)):
    print("IMPOSSIBLE")
    exit()
if((max(A)<min(B))or(max(B)<min(A))):
    print("IMPOSSIBLE")
    exit()

A.sort()
B.sort()
i=0
j=0
while((i<len(A))and(j<len(B))):
    if A[i] == B[j]:
        print("POSSIBLE")
        exit()
    elif A[i] > B[j]:j+=1
    else:i+=1
print("IMPOSSIBLE")
### BUGGY CODE ###

N =int(input())
nums = [int(input()) for _ in range(N)]

v = nums 
#max(v[0:0],W[i],W[i+1])):
#1番目を除いたmax
ans_f= max(v[1:N])
print(ans_f)
#forの範囲はiは1からN-1まで
i=N-1
#print(v[i:N]) #i+1番目からN番目の要素まで
#print(v[0:i])
#print(v[i+1:N])
for i in range(1,N-1,1):
    max1=max(v[0:i])
    max2=max(v[i+1:N])
    maxp=max(max1,max2)
    print(maxp)

ans_e= max(v[0:N-1])
print(ans_e)

### FIXED CODE ###

N =int(input())
nums = [int(input()) for _ in range(N)]

v = nums 
v_sort = sorted(v, reverse=True)
v_max=v_sort[0]
v_max2=v_sort[1]

for i in range(N):
    if(v[i]!=v_max):
        print(v_max)
    else:
        print(v_max2)
### BUGGY CODE ###

K,S=map(int,input().split())
ans=0
for x in range(0,K+1):
  for y in range(0,K+1):
    for z in range(0,K+1):
      if x+y+z==S:
        ans+=1
print(ans)

### FIXED CODE ###

K,S=map(int,input().split())
ans=0
for x in range(K+1):
  for y in range(K+1):
    if 0<=S-x-y<=K:
      ans+=1
print(ans)
### BUGGY CODE ###

from scipy.sparse import*
i=lambda:map(int,input().split())
f=csgraph.floyd_warshall
n,m,l=i()
d=eval('[0]*-~n,'*-~n)
exec('a,b,c=i();d[a][b]=c;'*m)
d=f(f(d,0)<=l)
q,=i()
while q:s,t=i();t=d[s,t];print((t<9e9and int(t))-1);q-=1

### FIXED CODE ###

from scipy.sparse import*
s=csgraph.floyd_warshall
n,m,l,*t=map(int,open(0).read().split())
d=eval('[9e9]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c
d=s(d)
d[d>l]=9e9
d[d<=l]=1
d=s(d)
d[d>9e9]=9e9
for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1))
### BUGGY CODE ###

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

a.sort(reverse=True)

ans = 0
while len(a) > 1:
    x = a[0]
    del a[0]
    temp = (1 << x.bit_length()) - x
    if temp in a:
        ans += 1
        a.remove(temp)

print(ans)



### FIXED CODE ###

from collections import Counter

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

a.sort(reverse=True)
c = Counter(a)

ans = 0
for x in a:
    if c[x] == 0:
        continue
    temp = (1 << x.bit_length()) - x
    c[x] -= 1
    if temp in c.keys():
        if c[temp] > 0:
            c[temp] -= 1
            ans += 1

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

from collections import Counter
n,m=map(int,input().split())
c=Counter()
for i in range(m):
    l,r=list(map(int,input().split()))
    idcard=list(range(l,r+1))
    c+=Counter(idcard)
cnt=0
for i in range(1,n+1):
    if c[i]==m:
        cnt+=1
print(cnt)

### FIXED CODE ###

n,m=map(int,input().split())
l_max=0
r_min=10**5+1
for i in range(m):
    l,r=map(int,input().split())
    l_max=max(l_max,l)
    r_min=min(r_min,r)
print(max(0,r_min-l_max+1))
### BUGGY CODE ###

N, Q = map(int, input().split())
ruisekiwa = [0] * (N + 1)
lists = []
S = str(input())
for t in range(1, len(S)):
    if S[t - 1] == "A" and S[t] == "C":
        for k in range(t, len(ruisekiwa)):
            ruisekiwa[k] += 1
for i in range(Q):
    l, r = map(int, input().split())
    ans = ruisekiwa[r - 1] - ruisekiwa[l - 1]
    lists.append(ans)
for m in range(len(lists)):
    print(lists[m])

### FIXED CODE ###

N, Q = map(int, input().split())
ruisekiwa = [0]
lists = []
cnt = 0
S = str(input())
for t in range(1, N):
    if S[t - 1] == "A" and S[t] == "C":
        cnt += 1
    ruisekiwa.append(cnt)
ruisekiwa.append(cnt)
for i in range(Q):
    l, r = map(int, input().split())
    ans = ruisekiwa[r - 1] - ruisekiwa[l - 1]
    lists.append(ans)
for m in range(len(lists)):
    print(lists[m])
### BUGGY CODE ###

import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

def comb(n,k):
    nCk = 1
    MOD = 998244353

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

def main():
   # file_input()
    N,M,K=map(int, input().split())

    mod=998244353
    ans=0
    for k in range(K+1):
        ans+=M*comb(N-1,k)*pow(M-1,N-1-k,mod)

    print(ans%mod)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os

def file_input():
    f = open('ABC167/input.txt', 'r')
    sys.stdin = f

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

def init_cmb(N,p):
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def main():
    #file_input()
    N,M,K=map(int, input().split())

    mod=998244353
    ans=0

    init_cmb(N,mod)
    for k in range(K+1):
        ans+=M*cmb(N-1,k,mod)*pow(M-1,N-1-k,mod)

    print(ans%mod)

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

import bisect
import math

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

a.sort()

ans = 0
for i in range(n) :
  h = 0
  m = a[i]*2
  for j in range(math.ceil(math.log(1000000000,2))+1) :
    mg = bisect.bisect_left(a,m)
    if mg <= n-1 and m == a[mg] :
      mg += 1
    m = sum(a[:mg])*2
  if mg >= n :
    ans += 1
  
print(ans)

### FIXED CODE ###

import bisect
import math

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

a.sort()

n1 = math.ceil(math.log(1000000000,2))+1

s = [0 for _ in range(n)]
s[0] = a[0]
for i in range(1,n) :
  s[i] = s[i-1]+a[i]

ans = 0
for i in range(n) :
  h = 0
  m = a[i]*2
  for j in range(n1) :
    mg = bisect.bisect_left(a,m)
    if mg <= n-1 and m == a[mg] :
      mg += 1
    m = s[mg-1]*2
    if m >= a[n-1] :
      ans += 1
      break
  
print(ans)
### BUGGY CODE ###

import numpy as np
def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0 for _ in range(Q)]
C = [0 for _ in range(Q)]
for i in range(Q):
  B[i], C[i] = map(int, input().split())
  
for i in range(Q):
  index = my_index(A, B[i])
  while(index != -1):
    A[index] = C[i]
    index = my_index(A, B[i])

  print(np.sum(A))

### FIXED CODE ###

import collections
import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0 for _ in range(Q)]
C = [0 for _ in range(Q)]
for i in range(Q):
  B[i], C[i] = map(int, input().split())
  
a = collections.Counter(A)
S = np.sum(A)
for i in range(Q):
  S += (C[i]-B[i]) * a[B[i]]
  a[C[i]] += a[B[i]]
  a[B[i]] = 0

  print(S)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
r = []
for i,c in zip(range(1, N + 1), range(N)):
    r.append(A.index(i)  + 1)
print(" ".join(map(str, r)))

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A = np.argsort(A)
for a in A:
    print(str(a + 1) + " " , end="")
### BUGGY CODE ###

n, m, Q = map(int, input().split())
lr = sorted([list(map(int, input().split())) for _ in range(m)])
pq = [list(map(int, input().split())) for _ in range(Q)]
a = [k[0] for k in lr]
for i in pq:
  p = i[0]
  q = i[1]
  ans = 0
  b = a[:]
  b.append(p)
  b = sorted(b)
  for j in lr[b.index(p):]:
    l = j[0]
    r = j[1]
    if p <= l and r <= q:
      ans += 1
  print(ans)

### FIXED CODE ###

def getSumRange(L, R):
    ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1]
    return ans

n, m, Q = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
p = [0] * Q
q = [0] * Q
for i in range(Q):
    p[i], q[i] = map(int, input().split())

sum = [[0] * (n + 1) for i in range(n + 1)]
for i in range(m):
    sum[L[i]][R[i]] += 1
for i in range(n + 1):
    for j in range(n + 1):
        sum[i][j] += sum[i - 1][j]
        sum[i][j] += sum[i][j - 1]
        sum[i][j] -= sum[i - 1][j - 1]

for i in range(Q):
    ans = getSumRange(p[i], q[i])
    print(ans)
### BUGGY CODE ###

k,s = map(int,input().split())
cnt = 0
for x in range(s + 1):
	for y in range(s + 1 - x):
		if x <= k and y <= k and s - x - y <= k:
			cnt += 1
print(cnt)


### FIXED CODE ###

k,s = map(int,input().split())
cnt = 0
M = min(s + 1,k + 1)
for x in range(M):
	for y in range(min(s + 1 - x,k + 1)):
		if s - x - y <= k:
			cnt += 1
print(cnt)
### BUGGY CODE ###

import itertools
while 1:
	n = input()
	if n == 0: break
	xy = sorted([map(int,raw_input().split()) for i in range(n)])
	dxy = [[xy1[0]-xy2[0],xy1[1]-xy2[1]] for xy1,xy2 in itertools.combinations(xy,2)]
	for i in range(len(dxy)-1,-1,):
		if dxy.count(dxy[i]) < 2: del dxy[i]
	dxy = sorted(dxy, key = lambda d:d[0]**2 + d[1]**2, reverse = True) 
	for dx,dy in dxy:
		if dxy.count([dy,-dx]) > 1 or dxy.count([-dy,-dx]) > 1:
			print dx**2 + dy**2
			break
	else:
		print 0

### FIXED CODE ###

while 1:
	n = input()
	if n == 0: break
	xy = [map(int,raw_input().split()) for i in range(n)]
	S = set(map(tuple,xy))
	ans = 0
	for i in range(n-1):
		x1,y1 = xy[i]
		for j in range(i+1,n):
			x2,y2 = xy[j]
			a = (x2-y2+y1,y2+x2-x1)
			b = (x1-y2+y1,y1+x2-x1)
			if a in S and b in S:
				ans = max(ans,(x1-x2)**2 + (y1-y2)**2)
	print ans
### BUGGY CODE ###

import sys
K=input()
if int(K)%2==0:
    print(-1)
    sys.exit()

S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**7):
    if S%K==0:
        print(ans)
        break
    else:
        S=(S*10)%K+7
        ans+=1
else:
    print(-1)

### FIXED CODE ###

import sys
K=input()
if int(K)%2==0:
    print(-1)
    sys.exit()

S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
    if S%K==0:
        print(ans)
        break
    else:
        S=(S*10)%K+7
        ans+=1
else:
    print(-1)
### BUGGY CODE ###

import numpy as np
from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

for i in range(n-1):
    ans += a[i] * sum(a[i+1:n])
    ans = ans % MOD

print(ans)

### FIXED CODE ###

from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

k = 0
s = [0] * n
for i in range(n-1, 0, -1):
    k += a[i] % MOD
    s[i] = k

for i in range(n-1):
    ans += a[i] * s[i+1]

ans = ans % MOD

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

N,M=map(int, input().split())
G=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

siru=[-1]*(N-1)#2~~N
que=[0]

while len(que)>0:
    #print(que)
    now=que.pop(0)
    nexlist=G[now]
    for nex in nexlist:
        if nex==0:
            continue
        if siru[nex-1]==-1:
            siru[nex-1]=now
            que.append(nex)
X=siru.count(-1)
if X>=1:
    print("No")
else:
    print("Yes")
    for num in siru:
        print(num+1)


### FIXED CODE ###

N,M=map(int, input().split())
G=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

siru=[-1]*(N-1)#2~~N
que=[0]

while len(que)>0:
    #print(que)
    now=que.pop(0)
    nexlist=G[now]
    for nex in nexlist:
        if nex==0:
            continue
        if siru[nex-1]==-1:
            siru[nex-1]=now
            que.append(nex)
X=siru.count(-1)
if X>=1:
    print("No")
else:
    print("Yes")
    for num in siru:
        print(num+1)