program main
  implicit none
  type arr_list
     integer :: N
     integer,allocatable :: point(:)
  end type arr_list
  type(arr_list),allocatable :: data(:)
  integer :: num(97:122)
  integer :: N, Q
  character(len=500000) :: S
  character(:),allocatable :: tmp
  character(len=1) :: c,b,c2
  integer :: a
  integer :: i,j, l,r
  integer :: out
  read(*,*) N
  read(*,*) S
  read(*,*) Q
  allocate(data(97:122))
  data(:)%N = 0
  num(:) = 0
  do i = 1,N
     data(ichar(S(i:i)))%N = data(ichar(S(i:i)))%N+1
  end do
  do i = 97,122
     if (data(i)%N > 0) allocate(data(i)%point(0:data(i)%N-1))
  end do
  do i = 1,N
     data(ichar(S(i:i)))%point( num(ichar(S(i:i))) ) = i-1
     num(ichar(S(i:i))) = num(ichar(S(i:i))) + 1
  end do
!  do i = 97,97+4
!     write(*,*) data(i)%point
!  end do
  do i = 1, Q
     read(*,'(i1,1x,a,1x,a)') a,b,c
     if (a == 1) then
        backspace(5)
        !read(*,'(i1,1x,g0,1x,a)') a,j,c
        read(*,*) a,j,c
        if (Q> 10000) then
           c2 = S(j:j)
           call insert_delete(data,j-1,c,c2)
        end if
        S(j:j) = c
     else
        backspace(5)
!        read(*,'(i1,1x,g0,1x,g0)') a,l,r
        read(*,*) a,l,r
        !tmp = S(l:r)
        !call count_char(S(l:r),out)
        if (Q> 10000) then
           call count_char(data,l-1,r-1,out)
        else
           tmp = S(l:r)
           call count_char2(tmp,out)
           deallocate(tmp)
        end if
        write(*,'(i0)') out
        !deallocate(tmp)
     end if

  end do
contains
  subroutine insert_delete(data,key,c,c2)
    implicit none
    type(arr_list) :: data(97:122)
    integer :: key ! key
    character :: c,c2 ! char
    integer,allocatable :: tmp(:)
    integer :: i,i2
    integer :: j
    integer :: n

    i = ichar(c)
    i2 = ichar(c2)
    if ( i /= i2) then ! insert and delete
       if (data(i)%N > 0) then
          j = found_point(data(i)%point(:),data(i)%n, key)
       else
          data(i)%N=data(i)%N+1
          allocate(data(i)%point(0:data(i)%N-1))
          data(i)%point(0:0) = key
          !
          ! delete
          !
          n = data(i2)%n
          data(i2)%n = data(i2)%n - 1
          if ( data(i2)%n > 0) then
             j = found_point(data(i2)%point(:),n, key)
             allocate(tmp(0:n-1))
             tmp(0:n-1) = data(i2)%point(0:n-1)
             deallocate( data(i2)%point )
             allocate( data(i2)%point(0:data(i2)%n-1) )
             data(i2)%point(0:j-1) = tmp(0:j-1)
             data(i2)%point(j:) = tmp(j+1:n-1)
             deallocate(tmp)
          else
             deallocate( data(i2)%point )
          end if
          return
       end if
       if ( j == data(i)%N) then ! out bound
          n = data(i)%n
          allocate(tmp(0:n-1))
          tmp(0:n-1) = data(i)%point(0:n-1)
          deallocate( data(i)%point )
          data(i)%n = data(i)%n + 1
          allocate( data(i)%point(0:data(i)%n-1) )
          data(i)%point(0:n-1) = tmp(0:n-1)
          data(i)%point(n) = key
          deallocate(tmp)
          !
          ! delete
          !
          n = data(i2)%n
          data(i2)%n = data(i2)%n - 1
          if ( data(i2)%n > 0) then
             j = found_point(data(i2)%point(:),n, key)
             allocate(tmp(0:n-1))
             tmp(0:n-1) = data(i2)%point(0:n-1)
             deallocate( data(i2)%point )
             allocate( data(i2)%point(0:data(i2)%n-1) )
             data(i2)%point(0:j-1) = tmp(0:j-1)
             data(i2)%point(j:) = tmp(j+1:n-1)
             deallocate(tmp)
          else
             deallocate( data(i2)%point )
          end if
          return
       else
          n = data(i)%n
          allocate(tmp(0:n-1))
          tmp(0:n-1) = data(i)%point(0:n-1)
          deallocate( data(i)%point )
          data(i)%n = data(i)%n + 1
          allocate( data(i)%point(0:data(i)%n-1) )
          if ( j == 0 ) then
             data(i)%point(0:0) = key
             data(i)%point(j+1:) = tmp(0:n-1)
          else
             data(i)%point(0:j-1) = tmp(0:j-1)
             data(i)%point(j) = key
             data(i)%point(j+1:) = tmp(j:n-1)
          end if
          deallocate(tmp)
          !
          ! delete
          !
          n = data(i2)%n
          data(i2)%n = data(i2)%n - 1
          if ( data(i2)%n > 0) then
             j = found_point(data(i2)%point(:),n, key)
             allocate(tmp(0:n-1))
             tmp(0:n-1) = data(i2)%point(0:n-1)
             deallocate( data(i2)%point )
             allocate( data(i2)%point(0:data(i2)%n-1) )
             data(i2)%point(0:j-1) = tmp(0:j-1)
             data(i2)%point(j:) = tmp(j+1:n-1)
             deallocate(tmp)
          else
             deallocate( data(i2)%point )
          end if
       end if
    end if
    return
  end subroutine insert_delete

  function found_point(a,n,key) result(ok)
    integer :: n
    integer :: a(0:n-1)
    integer :: key
    integer :: ng
    integer :: ok
    integer :: mid
    ng = -1
    ok = n
    do while( abs(ok-ng) > 1)
       mid = (ok + ng)/2
       if (isOK(mid,key,a,n)) then
          ok = mid
       else
          ng = mid
       end if
    end do
  end function found_point

  function isOK (index, key,a,n) result(out)
    integer :: n
    integer :: a(0:n-1)
    integer :: index, key
    logical :: out
    if ( a(index) >= key) then
       out = .true.
    else
       out = .false.
    end if
  end function isOK
  subroutine count_char(data,l,r,out)
    type(arr_list) :: data(97:122)
    integer :: l,r
    integer :: out
    integer :: N
    integer :: i, j, tmp
    out = 0
    do i = 97,122
       if ( data(i)%n > 0) then
          j = found_point(data(i)%point(:),data(i)%n,l)
          if ( j < data(i)%N) then
             if ( l<=data(i)%point(j) .and. data(i)%point(j) <= r) then
                out = out + 1
             end if
!!             if ( j+1 < data(i)%N) then
!!                if ( l<=data(i)%point(j) .and. data(i)%point(j) <= r) then
!!                   out = out + 1
!!                   cycle
!!                end if
!!                if ( data(i)%point(j) < l .and. data(i)%point(j+1) <= r) then
!!                   out = out + 1
!!                end if
!!             else
!!             end if
          end if
       end if
    end do
  end subroutine count_char

  subroutine count_char2(S,out)
    character(*) :: S
    integer :: out
    integer :: N
    integer :: i, tmp
    integer :: c(97:122)
    N = len_trim(S)
    c(97:122) = 0
    do i = 1,N
       tmp = ichar(S(i:i))
       c (tmp) = c(tmp) + 1
    end do
    out = count(c /=0)
  end subroutine count_char2
end program main


program ABC156_A
  integer::R
  read(5,*)N,R
  if(N<10) then
     write(6,*)R+100*(10-N)
  else
     write(6,*)R
  end if
end program ABC156_A

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

Takahashi is a member of a programming competition site, ButCoder.

Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.

The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \times (10 - K) when the member has participated in K contests.

Takahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.

Constraints

All values in input are integers.

1 \leq N \leq 100

0 \leq R \leq 4111

Input

Input is given from Standard Input in the following format:

N R

Output

Print his Inner Rating.

Sample Input 1

2 2919

Sample Output 1

3719

Takahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \times (10 - 2) = 800.

Thus, Takahashi's Inner Rating is 2919 + 800 = 3719.

Sample Input 2

22 3051

Sample Output 2

3051

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


program main
    integer :: n,r
    integer :: ro,rc
    read *,n,r
    ro=r
    if(n<10)then
        rc=ro+100*(10-n)
!        print *,ro,rc
    else
        rc=ro
    end if
    print '(i0)',rc
    stop
end program main


program test
implicit none
integer::N, R
read*, N, R
	if(N>=10)then
    	print*,R
    else
    	print*,R+100*(10-N)
    end if
end program test


program ABC156_B
  read(5,*)N,K
  M=1
  do while(N>=K)
     N=N/K
     M=M+1
  end do
  write(6,*)M
end program ABC156_B

Score : 200 points

Problem Statement

Given is an integer N. Find the number of digits that N has in base K.

Notes

For information on base-K representation, see Positional notation - Wikipedia.

Constraints

All values in input are integers.

1 \leq N \leq 10^9

2 \leq K \leq 10

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of digits that N has in base K.

Sample Input 1

11 2

Sample Output 1

4

In binary, 11 is represented as 1011.

Sample Input 2

1010101 10

Sample Output 2

7

Sample Input 3

314159265 3

Sample Output 3

18


program main
 implicit none
 integer N, K
 integer Nk
 integer keta
 integer i

 read *,N, K

 keta=0
 Nk=N
 do i=1,1000000000
  Nk=Nk/K
  keta =keta+1
  if (Nk<K) then
   keta=keta+1
   print '(i0)', keta
   exit
  end if
 end do

endprogram main


  Program Main

    Implicit None
    Integer(8)           :: N,K,M,digit

    N = 0
    K = 0
    digit = 1
    Read(*,*) N,K
    M = K
    N = N - M
    If (N == 0) digit = digit + 1
    M = M*(K-1)
    If (N>0)then
       Check:Do
                digit = digit + 1
                N = N - M
                If (N <= 0) then
                   Exit Check
                Elseif (N == 0) then
                      digit = digit + 1
                   Exit Check
                Endif
                M = M*K
             Enddo Check
    Endif

    Write(*,"(I0)") digit

  End Program


program main
  implicit none
  integer(8) :: N, K
  integer(8):: digit

  read(*,*) N,K
  digit = 0
  do while( N > 0 )
     N = N/K
     digit = digit + 1
  end do
  write(*,'(i0)') digit
  stop
end program main


program rally
    implicit none
    integer n, i
    integer :: ansgt = 0, anslt = 0, ans = 0, sum = 0
    integer :: avelt = 0, avegt = 0, ave = 0, amari = 0
    integer,allocatable :: x(:)
    read *, n
    allocate(x(n))
    read *, x(:n)
    do i = 1, n
        sum = sum + x(i)
    end do
    amari = mod(sum, n)
    if(amari == 0)then
        ave = sum / n
        do i = 1, n
            ans = ans + (x(i) - ave)**2
        end do
        print *, ans
    else
        ave = sum / n
        avegt = ave + 1
        avelt = ave
        do i = 1, n
            ansgt = ansgt + (x(i) - avegt)**2
            anslt = anslt + (x(i) - avelt)**2
        end do
        if(ansgt < anslt)then
            print *, ansgt
        else
            print *, anslt
        end if
    end if
end program

Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354


program rally
    implicit none
    integer n, i
    integer :: ans = 0, ave = 0, amari = 0
    integer,allocatable :: x(:)
    read *, n
    allocate(x(n))
    read *, x(:n)
    do i = 1, n
        ave = ave + x(i)
    end do
    amari = mod(ave, n)
    if(amari .eq. 0)then
        ave = ave / n
    else
        ave = ave / n + 1
    end if
    do i = 1, n
        ans = ans + (x(i) - ave)**2
    end do
    print *, ans
end program


program rally
  implicit none
  integer :: n, x(100) = 0, i, p
  read(*,*) n
  read(*,*) x(1:n)
  p = sum(x(1:n))/n
  write(*,'(i0)') min(sum((x(1:n)-p)*(x(1:n)-p)),sum((x(1:n)-p-1)*(x(1:n)-p-1)))
end program rally


module Factwithmod
  implicit none
  integer(16),allocatable,dimension(:)::Kaijo,comb
  contains
subroutine initiationFactorial(maxnum,mo)
  implicit none
  integer(16)::maxnum
  integer(16)::mo
  integer(16)::i

  allocate(Kaijo(0:maxnum))
  Kaijo(0)=1
  do i=1,maxnum
    Kaijo(i)=mod(Kaijo(i-1)*i,mo)
  end do
end subroutine

subroutine combination(n,maxnum,l)
implicit none
integer(16),intent(in)::n,maxnum,l
integer(16)::i
allocate(comb(maxnum))
comb(1)=N
do i=2,maxnum
    comb(i)=comb(i-1)*(N-i+1)*inv(i,l)
    comb(i)=mod(comb(i),l)
end do
end subroutine

function inv(K,L)
integer(16),intent(in)::k,l
integer(16) l2,y
integer(16) inv
inv=1
l2=l-2
y=k
do
  if(mod(l2,2)==1)inv=mod(inv*y,l)
  y=mod(y*y,l)
  l2=l2/2
  if(l2==0)exit
end do
end function

function permutation(n,k,mo)
implicit none
  integer(16)::n,k
  integer(16)::mo,permutation
  permutation=mod(Kaijo(N)*inv(Kaijo(N-K),mo),mo)
end function
end module Factwithmod
program ABC156b
    use Factwithmod
    implicit none
    integer(16)::N
    integer(16)::a,b
    integer(16)::mo=10**9+7
    integer(16)::allc
    integer(16)::ans
    read*,N,a,b
    call initiationFactorial(N,mo)
    call combination(N,b,mo)
    allc=power_func(2_16,N,mo)-1_16
    ans=allc-comb(a)-comb(b)
    ans=mod(ans,mo)
    if(ans<0)ans=ans+mo
    print"(i0)",ans
contains
integer(16) function power_func(a,n,mo)
    integer(16)::a,n,mo
    integer(16)::l2,y
    power_func=1
    l2=N
    y=a
    do
        if(mod(l2,2)==1)power_func=mod(power_func*y,mo)
        y=mod(y*y,mo)
        l2=l2/2
        if(l2==0)exit
    end do
end function power_func
end program ABC156b

Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

Print the count modulo (10^9 + 7).


program modularness
  implicit none
  integer :: k, q, d(0:5000) = 0, n, x, m, a, p, i, j
  read(*,*) k, q
  read(*,*) d(0:k - 1)
  do i = 1, q
    read(*,*) n, x, m
    p = 0
    x = mod(x, m)
    do j = 1, n - 1
      a = mod(x + d(mod(j - 1, k)), m)
      if (x < a) p = p + 1
      x = a
    end do
    write(*,'(i0)') p
  end do
end program modularness

Score : 600 points

Problem Statement

We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}.

Process the following q queries in order:

The i-th query contains three integers n_i, x_i, and m_i.
Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray}
Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i).

Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).

Constraints

All values in input are integers.

1 \leq k, q \leq 5000

0 \leq d_i \leq 10^9

2 \leq n_i \leq 10^9

0 \leq x_i \leq 10^9

2 \leq m_i \leq 10^9

Input

Input is given from Standard Input in the following format:

k q
d_0 d_1 ... d_{k - 1}
n_1 x_1 m_1
n_2 x_2 m_2
:
n_q x_q m_q

Output

Print q lines.

The i-th line should contain the response to the i-th query.

Sample Input 1

3 1
3 1 4
5 3 2

Sample Output 1

1

For the first query, the sequence {a_j} will be 3,6,7,11,14.

(a_0~\textrm{mod}~2) > (a_1~\textrm{mod}~2)

(a_1~\textrm{mod}~2) < (a_2~\textrm{mod}~2)

(a_2~\textrm{mod}~2) = (a_3~\textrm{mod}~2)

(a_3~\textrm{mod}~2) > (a_4~\textrm{mod}~2)

Thus, the response to this query should be 1.

Sample Input 2

7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12

Sample Output 2

224489796
214285714
559523809


program sample
	implicit none
    integer :: A,B,C

    read(*,*) A,B,C

    if (A==B .or. A==C .or. B==C) then
    	if (A==B .and. B==C) then
    		write(*,*) 'No'
        else
        	write(*,*) 'Yes'
        end if
    else
    	write(*,*) 'No'
    end if

    stop
end program sample

Score: 100 points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

Constraints

A, B, and C are all integers between 1 and 9 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

A and C are equal, but B is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

A, B, and C are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


program prob5
    implicit none
    integer :: a,b,c
    read(*,*) a,b,c

    if(a == b .and. b /= c) then
        write(*,*) "Yes"
        stop
    end if
    if(a == c .and. b /= c) then
        write(*,*) "Yes"
        stop
    end if
    if(c == b .and. a /= c) then
        write(*,*) "Yes"
        stop
    end if
    write(*,*) "No"

    stop
contains
end program prob5


program poll
  implicit none
  integer :: n, i, a(200000) = 0, m
  character(10) :: s(200000)
  read(*,*) n
  do i = 1, n
    read(*,*) s(i)
  end do
  call quick_sort(s(1:n))
  a(1) = 1
  do i = 2, n
    if (s(i) == s(i-1)) then
      a(i) = a(i-1)+1
    else
      a(i) = 1
    end if
  end do
  m = maxval(a(1:n))
  do i = 1, n
    if (a(i) == m) write(*,'(a)') trim(s(i))
  end do
contains
  subroutine swap(a,b)
    character(10), intent(inout) :: a, b
    character(10) :: c
    c = a
    a = b
    b = c
  end
  recursive subroutine quick_sort(a)
    character(10), intent(inout) :: a(:)
    integer :: n, l, r
    character(10) :: p
    n = size(a)
    l = 1
    r = n
    p = a((n+1)/2)
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      call swap(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program poll

Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

1 \leq N \leq 2 \times 10^5

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


program main
      implicit none
      integer :: n, i, cnt, maxs
      character(10), allocatable :: s(:)

      read *, n
      allocate( s(n) )
      do i = 1, n
        read *, s(i)
      end do

      call quicksort1( s, 1, n )

      cnt = 0
      maxs = 1
      do i = 1, n
        if ( s(i) == s(i+1) ) then
          cnt = cnt + 1
        else
          if ( maxs <= cnt ) then
            maxs = cnt
          end if
          cnt = 0
        end if
      end do

      cnt = 0
      do i = 1, n
        if ( maxs == 1 ) then
              print *, s(i)
        else
          if ( s(i) == s(i+1) ) then
            cnt = cnt + 1
          else
            if ( maxs == cnt ) then
              print *, s(i)
            end if
            cnt = 0
          end if
        end if
      end do

end program main
recursive subroutine quicksort1( namec, first, last )

  implicit none
  character(10), intent(inout) :: namec(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  character(100)::x,t
  integer::i,j

  x = namec((first+last)/2)
  i = first
  j = last
  do
     do while ( LGT( x, namec(i) ) )
        i=i+1
     end do
     do while ( LGT( namec(j), x ) )
        j=j-1
     end do
     if (i >= j) exit
     t = namec(i)
     namec(i) = namec(j)
     namec(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1( namec, first, i-1  )
  if (j+1 < last)  call quicksort1( namec, j+1  , last )

  return

end subroutine quicksort1


program test03_2
 implicit none
 integer N
 character(len=10),allocatable :: S(:)
 character(len=10),allocatable :: Smax(:)
 integer,allocatable :: Sk(:)
 integer :: kaisuu=1, maxkaisuu=0
 integer i, ii
 integer :: j=1
 integer :: yatta=0

 read *, N
 allocate(S(N))
 allocate(Sk(N))
 allocate(Smax(N))
 do i=1,N
  read *, S(i)
! S(i)=trim(S(i))
 end do

Smax='a'
Sk=1

 call quicksort1(S,1,N)

 do i=2,N
  if (S(i)==S(i-1)) then
   Sk(i)=Sk(i-1)+1
!print *,i, S(i) ,Sk(i), 'yes'
  else
   Sk(i)=1
!print *,i, S(i) ,Sk(i), 'no'
  end if
 !print *,i, S(i) ,Sk(i)
 end do

 yatta=MAXVAL(Sk)
!print *, 'yatta=',yatta

 print *,''
 do i=1,N
  if ( Sk(i) == yatta ) then
   print '(A)', trim(S(i))
  end if
 end do

!print *,''
!print '(A)', S(1)

contains
recursive subroutine quicksort1(a, first, last)
  implicit none
   character(len=10),intent(inout)::a(*)
   integer,intent(in)::first,last

   character(len=10)::x,t
   integer::i,j

   x = a((first+last)/2)
   i = first
   j = last
   do
     do while (a(i) < x)
       i=i+1
     end do
     do while (x < a(j))
       j=j-1
     end do
     if (i >= j) exit
      t = a(i)
      a(i) = a(j)
      a(j) = t
      i=i+1
      j=j-1
   end do
   if (first < i-1) call quicksort1(a, first, i-1)
   if (j+1 < last)  call quicksort1(a, j+1, last)
 return
end subroutine quicksort1

endprogram test03_2


      module charaSort
      implicit none

      contains
      recursive function sort( s ) result( r )
        implicit none
        character(10),intent(in) :: s(:)
        character(10) :: r( size(s) )

        if( size(s)>1 )then
          r = [sort( pack(s, s<s(1)) ), &
               pack(s,s==s(1)), &
               sort( pack(s, s>s(1)) )]
        else
          r = s
        end if
      end function
      end module

      PROGRAM Poll
      use charaSort
      IMPLICIT NONE
      integer(16) :: n
      character(10),allocatable :: s(:)
      character(10),allocatable :: note1(:)
      integer(16) :: i,counter,piyo,c
      integer(16),allocatable :: note2(:)
      logical,allocatable :: flag(:)

      read*,n
      allocate( s(1:n) )
      allocate(note1(n),note2(n),flag(n))
      do i = 1,n
        read'(a)',s(i)
      end do

      counter = 1
      note1(1) = s(1)
      note2(:) = 0
      outer:do i = 2,n
        do c = 1,counter
          if( note1(c)==s(i) )then
            note2(c) = note2(c) + 1
            cycle
          end if
        end do
        counter = counter + 1
        note1(counter) = s(i)
      end do outer

      flag = note2==maxval(note2)
      piyo = count( flag )

      deallocate( note1 )
      allocate( note1(piyo) )

      note1 = pack( s,flag )
      note1 = sort( note1 )

      do i = 1,piyo
        print*,note1(i)
      end do

      END PROGRAM


      module charaSort
      implicit none

      contains
      recursive function sort( s ) result( r )
        implicit none
        character(10),intent(in) :: s(:)
        character(10) :: r( size(s) )

        if( size(s)>1 )then
          r = [sort( pack(s, s<s(1)) ), &
               pack(s,s==s(1)), &
               sort( pack(s,s>s(1)) )]
        else
          r = s
        end if
      end function
      end module

      PROGRAM Poll
      use charaSort
      IMPLICIT NONE
      integer(16) :: n
      character(10),allocatable :: s(:)
      character(10),allocatable :: note1(:)
      integer(16) :: i,counter
      integer(16),allocatable :: note2(:)
      logical,allocatable :: flag(:)

      read*,n
      allocate( s(1:n) )
      allocate(note1(n),note2(n),flag(n))
      do i = 1,n
        read*,s(i)
      end do

      s = sort(s)

      counter = 1
      note1(1) = s(1)
      note2(:) = 0
      do i = 2,n
        if(note1(counter)==s(i))then
          note2(counter) = note2(counter) + 1
        else
          counter = counter + 1
          note1(counter) = s(i)
        end if
      end do

      flag = note2==maxval(note2)

      do i = 1,counter
        if(flag(i))then
          print*,note1(i)
        end if
      end do

      END PROGRAM


      module charaSort
      implicit none

      contains
      recursive function sort( s ) result( r )
        implicit none
        character(10),intent(in) :: s(:)
        character(10) :: r( size(s) )

        if( size(s)>1 )then
          r = [sort( pack(s, s<s(1)) ), &
               pack(s,s==s(1)), &
               sort( pack(s,s>s(1)) )]
        else
          r = s
        end if
      end function
      end module

      PROGRAM Poll
      use charaSort
      IMPLICIT NONE
      integer(16) :: n
      character(10),allocatable :: s(:)
      character(10),allocatable :: note1(:)
      integer(16) :: i,counter
      integer(16),allocatable :: note2(:)
      logical,allocatable :: flag(:)

      read*,n
      allocate( s(1:n) )
      do i = 1,n
        read*,s(i)
      end do

      s = sort(s)
      allocate(note1(n),note2(n))
      counter = 1
      note1(1) = s(1)
      note2(:) = 0
      do i = 2,n
        if(note1(counter)==s(i))then
          note2(counter) = note2(counter) + 1
        else
          counter = counter + 1
          note1(counter) = s(i)
        end if
      end do

      allocate(flag(counter))
      flag = note2==maxval(note2)

      do i = 1,counter
        if(flag(i))then
          print*,note1(i)
        end if
      end do

      END PROGRAM


module mod_unweighted_graph
  implicit none
  type t_list
    integer, allocatable :: at(:, :)
  end type
  type unweighted_graph
    type(t_list), allocatable :: list(:)
  end type
  interface unweighted_graph
    module procedure :: newug0
  end interface unweighted_graph
contains
  type(unweighted_graph) function newug0(n, m, a, b, e, undirected) result(res)
    integer, intent(in) :: n, m, a(:), b(:), e(:)
    logical, optional, intent(in) :: undirected
    logical :: u
    integer :: c(n), i
    u = merge(undirected, .true., present(undirected))
    c = 0
    do i = 1, m
      c(a(i)) = c(a(i)) + 1
      if (u) c(b(i)) = c(b(i)) + 1
    end do
    allocate(res%list(n))
    do i = 1, n
      allocate(res%list(i)%at(c(i), 2))
    end do
    do i = m, 1, -1
      res%list(a(i))%at(c(a(i)), 1) = b(i)
      res%list(a(i))%at(c(a(i)), 2) = e(i)
      c(a(i)) = c(a(i)) - 1
      if (u) then
        res%list(b(i))%at(c(b(i)), 1) = a(i)
        res%list(b(i))%at(c(b(i)), 2) = e(i)
        c(b(i)) = c(b(i)) - 1
      end if
    end do
  end
end module mod_unweighted_graph
module mod_two_dim_merge_sort
  implicit none
  integer, private, parameter :: intkind = 4
contains
  logical function less(a, b) result(res)
    integer(intkind), intent(in) :: a(:), b(:)
    res = a(1) < b(1)
  end
  subroutine merge_sort(a)
    integer(intkind), intent(inout) :: a(:, :)
    integer :: n, m, l, i, u
    n = size(a, 1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m / 2
        u = min(2 * i * l, n)
        call merger(a(2 * (i - 1) * l + 1:(2 * i - 1) * l, :), &
        a((2 * i - 1) * l + 1:u, :))
      end do
      l = 2 * l
      m = (m + 1) / 2
    end do
  end
  subroutine merger(a1, a2)
    integer(intkind), intent(inout) :: a1(:, :), a2(:, :)
    integer(intkind) :: a(size(a1, 1) + size(a2, 1), size(a1, 2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1, 1)
    n2 = size(a2, 1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (less(a1(i1, :), a2(i2, :))) then
        a(i1 + i2 - 1, :) = a1(i1, :)
        i1 = i1 + 1
      else
        a(i1 + i2 - 1, :) = a2(i2, :)
        i2 = i2 + 1
       end if
    end do
    if (i1 <= n1) then
      a(i1 + i2 - 1:n1 + n2, :) = a1(i1:n1, :)
    else
      a(i1 + i2 - 1:n1 + n2, :) = a2(i2:n2, :)
    end if
    a1 = a(1:n1, :)
    a2 = a(n1 + 1:n1 + n2, :)
  end
end module mod_two_dim_merge_sort
program perils_in_parallel
  use mod_unweighted_graph
  use mod_two_dim_merge_sort
  implicit none
  integer :: n, m, cnt = 0, i, j, l, r, p
  integer :: a(100000, 2) = 0, x(200000, 3) = 0, y(200000, 1) = 0, z(100001) = 0
  logical :: used(100000) = .false.
  type(unweighted_graph) :: g
  read(*,*) n, m
  do i = 1, n
    read(*,*) a(i, :)
  end do
  call merge_sort(a(1:n, :))
  z(1) = a(1, 2)
  do i = 2, n
    z(i) = xor(a(i, 2), a(i - 1, 2))
  end do
  z(n + 1) = a(n, 2)
  do i = 1, m
    j = cnt + 1
    read(*,*) x(j, 1:2)
    x(j, 3) = i
    if (x(j, 1) > a(n, 1)) cycle
    if (x(j, 2) < a(1, 1)) cycle
    l = 0
    r = n
    do while (r - l > 1)
      p = (l + r) / 2
      if (x(j, 1) <= a(p, 1)) then
        r = p
      else
        l = p
      end if
    end do
    x(j, 1) = r
    l = 1
    r = n + 1
    do while (r - l > 1)
      p = (l + r) / 2
      if (x(j, 2) >= a(p, 1)) then
        l = p
      else
        r = p
      end if
    end do
    x(j, 2) = r
    if (x(j, 1) < x(j, 2)) cnt = cnt + 1
  end do
  m = cnt
  g = unweighted_graph(n + 1, m, x(1:m, 1), x(1:m, 2), x(1:m, 3))
  p = 0
  do i = 1, n + 1
    if (used(i)) cycle
    if (btest(dfs(g, i), 0)) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  write(*,'(i0)') p
  if (p > 0) then
    call merge_sort(y(1:p, :))
    write(*,'(i0)',advance='no') y(1, 1)
    do i = 2, p
      write(*,'(x,i0)',advance='no') y(i, 1)
    end do
  end if
  write(*,*)
contains
  recursive integer function dfs(this, v) result(res)
    type(unweighted_graph), intent(in) :: this
    integer, intent(in) :: v
    integer :: i, u, tmp
    used(v) = .true.
    res = z(v)
    do i = 1, size(this%list(v)%at, 1)
      u = this%list(v)%at(i, 1)
      if (used(u)) cycle
      tmp = dfs(this, u)
      if (btest(tmp, 0)) then
        p = p + 1
        y(p, 1) = this%list(v)%at(i, 2)
      end if
      res = xor(res, tmp)
    end do
  end
end program perils_in_parallel

Score: 600 points

Problem Statement

After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.

Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.

There are N bombs, numbered 1 to N, planted in our country. Bomb i is planted at the coordinate A_i. It is currently activated if B_i=1, and deactivated if B_i=0.

The device has M cords numbered 1 to M. If we cut Cord j, the states of all the bombs planted between the coordinates L_j and R_j (inclusive) will be switched - from activated to deactivated, and vice versa.

Determine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

A_i are pairwise distinct.

B_i is 0 or 1. (1 \leq i \leq N)

1 \leq M \leq 2 \times 10^5

1 \leq L_j \leq R_j \leq 10^9\ (1 \leq j \leq M)

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_N B_N
L_1 R_1
:
L_M R_M

Output

If it is impossible to deactivate all the bombs at the same time, print -1. If it is possible to do so, print a set of cords that should be cut, as follows:

k
c_1 c_2 \dots c_k

Here, k is the number of cords (possibly 0), and c_1, c_2, \dots, c_k represent the cords that should be cut. 1 \leq c_1 < c_2 < \dots < c_k \leq M must hold.

Sample Input 1

3 4
5 1
10 1
8 0
1 10
4 5
6 7
8 9

Sample Output 1

2
1 4

There are two activated bombs at the coordinates 5, 10, and one deactivated bomb at the coordinate 8.

Cutting Cord 1 switches the states of all the bombs planted between the coordinates 1 and 10, that is, all of the three bombs.

Cutting Cord 4 switches the states of all the bombs planted between the coordinates 8 and 9, that is, Bomb 3.

Thus, we can deactivate all the bombs by cutting Cord 1 and Cord 4.

Sample Input 2

4 2
2 0
3 1
5 1
7 0
1 4
4 7

Sample Output 2

-1

Cutting any set of cords will not deactivate all the bombs at the same time.

Sample Input 3

3 2
5 0
10 0
8 0
6 9
66 99

Sample Output 3

0

All the bombs are already deactivated, so we do not need to cut any cord.

Sample Input 4

12 20
536130100 1
150049660 1
79245447 1
132551741 0
89484841 1
328129089 0
623467741 0
248785745 0
421631475 0
498966877 0
43768791 1
112237273 0
21499042 142460201
58176487 384985131
88563042 144788076
120198276 497115965
134867387 563350571
211946499 458996604
233934566 297258009
335674184 555985828
414601661 520203502
101135608 501051309
90972258 300372385
255474956 630621190
436210625 517850028
145652401 192476406
377607297 520655694
244404406 304034433
112237273 359737255
392593015 463983307
150586788 504362212
54772353 83124235

Sample Output 4

5
1 7 8 9 11

If there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.


program main
    implicit none

    integer :: a,b
    character(10) :: s,t,u

    read( *, * )  s, t
    read(*,*) a,b
    read(*,*) u

    if (u.eq.s) then
       a=a-1
    elseif(u.eq.t) then
       b=b-1
    endif

    print *,a,b
end program main

Score : 100 points

Problem Statement

We have A balls with the string S written on each of them and B balls with the string T written on each of them.

From these balls, Takahashi chooses one with the string U written on it and throws it away.

Find the number of balls with the string S and balls with the string T that we have now.

Constraints

S, T, and U are strings consisting of lowercase English letters.

The lengths of S and T are each between 1 and 10 (inclusive).

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

Takahashi chose a ball with red written on it and threw it away.
Now we have two balls with the string S and four balls with the string T.

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

Takahashi chose a ball with blue written on it and threw it away.
Now we have five balls with the string S and four balls with the string T.


program main
implicit none
integer :: i, j, k, a, b
character(10) :: s, t, u

read(*,*) s, t
read(*,*) a, b
read(*,*) u
if( s == u ) then
   a = a-1
else
   b = b-1
end if
write(*,'(i0, a1, i0)') a,'', b

end program main


program abc65
 implicit none
 integer(8)::N,ia,ib,ic,j=1
 integer(8),allocatable::a(:)
 read(*,*)N
 allocate(a(N))
 read(*,*)(a(ia),ia=1,N)
 do ib=1,N-1
  do ic=ib+1,N
   if(a(ib)==a(ic))then
    j=0
    goto 1
   end if
  end do
 end do
 1 if(j==0)then
    print'(a)',"NO"
   else
    print'(a)',"YES"
   end if
 deallocate(a)
end program abc65

Score : 300 points

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


program DorN
    implicit none
    integer(8) n, i
    integer :: f = 0
    integer(8),allocatable :: a(:)
    read *, n
    allocate(a(n))
    read *, a(1:n)
    do i = 1, n-1
        if(a(i) .eq. a(i+1))then
            f = f + 1
            exit
        end if
        if(f .ge. 1)exit
    end do
    if(f .ge. 1)then
        print *, 'NO'
    else
        print *, 'YES'
    end if
end program


  Program Main

    Implicit None

    Integer, Allocatable :: A(:)
    Integer(8)           :: i,j,N
    Logical              :: eq

    eq = .False.
    N  = 0
    Read(*,*) N
    Allocate (A(N)); A(:) = 0.0d0
    Read(*,*)(A(i),i=1,N)

    Check:Do i = 1,N-1
             Do j = i+1,N
                If (A(i) == A(j)) then
                   eq = .True.
                   Exit Check
                Endif
             Enddo
          Enddo Check

    If (.not.eq) then
       Write(*,"(a)")"YES"
    Else
       Write(*,"(a)")"NO"
    Endif

    Deallocate(A)

  End Program


      MODULE qSortMod
      implicit none
      interface qSort
        module procedure :: i16qSort
        module procedure :: i4qSort
      end interface
      contains

      pure recursive function i16qSort( a ) result( r )
          !ref
          !https://t.doujin-constant.net/
          !post/143374686394/fortranをより使いこなしたquick-sort
          !
          !left is Bigger!
        implicit none
        integer(16),intent(in) :: a(:)
        integer(16) :: r( size(a) )
        !integer(16),allocatable :: r(:) !is OK

        if( size(a)>1 )then
          r = [ qSort( pack( a(:),a(:)> a(1) ) ), &
                       pack( a(:),a(:)==a(1) )  , &
                qSort( pack( a(:),a(:)< a(1) ) ) ]
        else
          r = a
        end if
      end function i16qSort

      pure recursive function i4qSort( a ) result( r )
        implicit none
        integer(4),intent(in) :: a(:)
        integer(4) :: r( size(a) )

        if( size(a)>1 )then
          r=[qSort(pack(a,a>a(1))),pack(a,a==a(1)),qSort(pack(a,a<a(1)))]
        else
          r = a
        end if
      end function i4qSort
      END MODULE qSortMod

      PROGRAM piyo
      USE qSortMod
      IMPLICIT NONE
      INTEGER(16) :: n
      integer(16),allocatable :: a(:)
      integer(16) :: i

      read*,n
      allocate( a(n) )
      read*,a(:)

      a = qSort( a )

      do i = 1,n-1
        if( a(i)==a(i+1) )then
          print*,'NO'
          STOP
        end if
      end do

      print*,'YES'

      END PROGRAM


  Program Main

    Implicit None

    Real*8               :: q
    Integer, Allocatable :: p(:),s(:)
    Integer(8)           :: i,j,N,K,max_s,l

    N = 0; K = 0; max_s = 0
    Read(*,*) N,K
    Allocate (p(N)); p(:) = 0
    Allocate (s(N)); s(:) = 0
    Read(*,*)(p(i),i=1,N)

    Do i = 1,N-K+1
       Do j = i,i+K-1
          s(i) = s(i) + p(j)
       Enddo
       If (s(i) > max_s) then
          max_s = s(i)
          l = i
       Endif
    Enddo

    Do i = l,l+K-1
       q = q + (Dble(p(i))+1.0d0)/2.0d0
    Enddo

    Write(*,"(F0.7)") q

  End Program

Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000


program main
    implicit none
    integer(4):: n,k,i,j
    integer(4),allocatable:: p(:)
    real(8),allocatable:: s(:), ar(:)
    real(8):: ans=0
    read*, n, k
    allocate(p(n),s(0:n))
    read*, p(:)
    ! p(:) = [(i,i=1,n)]

    s(1:) = dble(p(:)-1)/2d0+1
    s(0) = 0
    do i=1,n
        s(i) = s(i) + s(i-1)
    end do

    do i=0,n-k+1
        ans = max(ans, s(i+k)-s(i))
    end do
    print*, ans
end program main


program main
    implicit none
    integer(4):: n,k,i
    integer(4),allocatable:: p(:)
    real(8),allocatable:: s(:)
    real(8):: ans
    read*, n, k
    allocate(p(n))
    read*, p(:)

    call merge_sort(p(:),1,n)

    allocate(s(p(1)))
    s(1) = 1d0
    do i=2, p(1)
        s(i) = s(i-1)+dble(i)
    end do

    do i=1,p(1)
        s(i) = s(i)/dble(i)
    end do

    ans = 0

    do i=1,k
        ans = ans + s(p(i))
    end do
    print*, ans

contains
recursive subroutine merge_sort(ar,fst,lst)
    integer(4):: ar(:),fst,lst
    integer(4):: tmp, mdl
    if(lst-fst < 2) then
        if (ar(fst) < ar(lst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mdl = (fst+lst)/2
    call merge_sort(ar(:), fst, mdl)
    call merge_sort(ar(:), mdl+1, lst)
    call merge(ar(:), fst, mdl, lst)

end subroutine

subroutine merge(ar,fst,mdl,lst)
    integer(4)::ar(:),fst,mdl,lst
    integer(4):: l,r,t
    integer(4),pointer:: tmp(:)

    allocate(tmp(lst-fst+1))
    l=fst
    r=mdl+1
    t=1
    do while(l <= mdl .and. r <= lst)
        if (ar(l) > ar(r)) then
            tmp(t) = ar(l)
            l=l+1
        else
            tmp(t) = ar(r)
            r=r+1
        end if
        t=t+1
    end do

    if (r > lst) then
        tmp(t:) = ar(l:mdl)
    else
        tmp(t:) = ar(r:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine
end program main


program main

  implicit none

  integer    :: n, k
  integer,allocatable :: p(:)
  real   ,allocatable :: h(:)
  real   ,allocatable :: sh(:)
  integer :: i, j

  read(*,*) n, k
  allocate( p(n) )
  allocate( h(n) )
  read(*,*) p

  h = 0e0
  do i = 1, n
    do j = 1, p(i)
      h(i) = h(i) + j
    end do
    h(i) = h(i) / p(i)
  end do

  allocate( sh(n-k+1) )
  do i = 1, n-k+1
    sh(i) = sum( h(i:i+k-1) )
  end do

  print*, maxval( sh )
end program main

recursive subroutine quicksort1(a, first, last)
  !call quicksort1( a, 1, n )
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


program prob9
    implicit none
    integer :: h,a
    read(*,*) h, a

    write(*,*) (h-1) / a + 1

    stop
contains
end program prob9

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A.
There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.

Sample Input 1

10 4

Sample Output 1

3

After one attack, the monster's health will be 6.

After two attacks, the monster's health will be 2.

After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


program main
  implicit none
  integer :: h, a
  read *, h, a
  print "(i0)", ceiling(h / dble(a))
end program main


program example
	implicit none

	integer :: H,A,i=0

    read(*,*)H,A

    do

    	if (H-A>0) then
        	H=H-A
            i=i+1
        else
        	i=i+1
        	exit
        end if
    end do

    write(*,*) i

end program example


program serval_monstar

implicit none
integer :: i
real(8) :: h,a
read(*,*) h,a
i = ceiling(h/a)
write(*,*)i

end program serval_monstar


program abc63
 implicit none
 integer(8)::N,K,ia,ib,ic,id,swap,c=0
 integer(8),allocatable::H(:)
 read(*,*)N,K
 allocate(H(N))
 read(*,*)(H(ia),ia=1,N)
 do ib=1,N-1
  do ic=1,N-ib
   if(H(ic)<H(ic+1))then
    swap=H(ic)
    H(ic)=H(ic+1)
    H(ic+1)=swap
   end if
  end do
 end do
 print'(i0)',sum(H(K+1:N))
 deallocate(H)
end program abc63

Score : 300 points

Problem Statement

Fennec is fighting with N monsters.

The health of the i-th monster is H_i.

Fennec can do the following two actions:

Attack: Fennec chooses one monster. That monster's health will decrease by 1.

Special Move: Fennec chooses one monster. That monster's health will become 0.

There is no way other than Attack and Special Move to decrease the monsters' health.

Fennec wins when all the monsters' healths become 0 or below.

Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 2 \times 10^5

1 \leq H_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 ... H_N

Output

Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

Sample Input 1

3 1
4 1 5

Sample Output 1

5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.

Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.

Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


program main
      implicit none
      integer(4) :: n, k, i
      integer(8), allocatable :: h(:)
      integer(16) :: cnt

      read *, n, k
      allocate( h(n) )
      read *, h

      call quicksort1(h,1,n)

      n=n-k
      cnt = 0
      do i = 1, n
        cnt = cnt+h(i)
      end do
      print *, cnt

end program main
recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


program main
  implicit none
  integer :: n, i, k
  integer(8), allocatable :: h(:)
  read (*, *) n, k
  allocate (h(n))
  read (*, *) h(:)
  call quicksort(h)
  if (k >= n) then
    write (*, "(i0)") 0
  else
    write (*, "(i0)") sum(h(1:n - k))
  end if

  contains

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(4) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


program main

  implicit none

  integer    :: n, k, i, j
  integer(8),allocatable :: h(:)
  integer(8) :: sumh

  read(*,*) n,k
  allocate( h(n) )
  read(*,*) h
  call quicksort1( h, 1, n )

  sumh = 0

  if( n - k > 0 ) then
    do i = 1 ,n-k
      sumh = sumh + h(i)
    end do
  end if

  write(*,*) sumh

end program main

recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


!
! The below module was made in reference to
! https://ufcpp.net/study/algorithm/col_heap.html
!
module heappq

  implicit none
  integer(8),allocatable :: hp(:)

contains
subroutine heapinit(n)

  integer, intent(in) :: n

  allocate( hp(n) ); hp = 0

end subroutine heapinit

subroutine heappush( newnp, newn )

  integer, intent(in)    :: newn
  integer(8), intent(in)    :: newnp
  integer :: i,ln
  integer(8) :: tmp

  ln = newn
  hp(ln) = newnp

  do while ( ln /= 1 )
    i = ln/2
    if ( hp(i) < hp(ln) ) then
      tmp    = hp(ln)
      hp(ln) = hp(i)
      hp(i)  = tmp
    end if
    ln = i
  end do

end subroutine heappush

end module heappq

program main

  use heappq

  implicit none

  integer    :: n, k, i, j
  integer(8),allocatable :: h(:)

  read(*,*) n,k
  allocate( h(n) )
  read(*,*) h

  if ( k >= n ) then
    print*, "0"
  else if ( k == 0 ) then
    print*, sum(h)
  else

    call heapinit(n)

    do i = 1, n
      call heappush( h(i), i )
    end do

    h = hp
    print*, h

    if( mod( k, 2 ) == 0 ) then
      print*, sum( h(1:k) )
    else
      if( h(k) >= h(k+1)) then
        print*, sum( h(1:k) )
      else
        print*, sum( h(1:k+1) ) - h(k)
      end if
    end if

  end if

end program main


program main
    implicit none
    integer(8)::h, at_num, at_all
    read*,h
    at_num = 1
    at_all = 0
    do while(h > 1)
        at_all = at_all + at_num
        h = h / 2
        at_num = at_num * 2
    end do
    at_all = at_all + at_num

    print*, at_all

end program main

Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775


program main

  implicit none

  integer(8)    :: h, i, n, num

  read(*,*) h

  if( h == 1 ) then
    print*, "0"
    stop
  else if( h == 3 ) then
    print*, "1"
    stop
  end if

  n = 0
  do
    h = int( h / 2, kind=8 )
    n = n + 1
    if( h < 2 ) exit
  end do

  num = 1
  do i = 1, n
    num = num + 2**i
  end do

  print*, num

end program main


program main

  implicit none

  integer(8)    :: h, i, n, num

  read(*,*) h
  if( h == 1 ) then
    print*, "0"
    stop
  end if
  n = 0
  do
    n = n + 1
    h = h / 2
    if( h <= 1 ) exit
  end do

  num = 1
  do i = 1, n
    num = num + 2**i
  end do

  print*, num

end program main


program silver_fox_vs_monster
  implicit none
  integer(8), parameter :: inf = 1001001001001_8
  integer :: n, i, l, r, m
  integer(8) :: d, a, x(0:200001,2) = 0, y(0:200001,2) = 0, p1 = 0, p2 = 0, t
  read(*,*) n, d, a
  do i = 1, n
    read(*,*) x(i,:)
  end do
  call merge_sort(x(1:n,:))
  x(0,1) = -inf
  x(n+1,1) = inf
  y = x
  i = 1
  do while (i <= n)
    do while (x(i,2) <= 0 .and. i <= n)
      i = i+1
    end do
    if (i > n) exit
    l = i
    r = n+1
    do while (r-l > 1)
      m = (l+r)/2
      if (x(m,1) > x(i,1)+d*2) then
        r = m
      else
        l = m
      end if
    end do
    t = (x(i,2)+a-1)/a
    p1 = p1+t
    x(i:l,2) = x(i:l,2)-t*a
  end do
  x = y
  i = n
  do while (i >= 1)
    do while (x(i,2) <= 0 .and. i >= 1)
      i = i-1
    end do
    if (i < 1) exit
    l = 0
    r = i
    do while (r-l > 1)
      m = (l+r)/2
      if (x(m,1) < x(i,1)-d*2) then
        l = m
      else
        r = m
      end if
    end do
    t = (x(i,2)+a-1)/a
    p2 = p2+t
    x(r:i,2) = x(r:i,2)-t*a
  end do
  write(*,'(i0)') min(p1,p2)
contains
  subroutine merge_sort(a)
    integer(8), intent(inout) :: a(:,:)
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(a1,a2)
    integer(8), intent(inout) :: a1(:,:), a2(:,:)
    integer(8) :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1,1)
    n2 = size(a2,1)
    do while (i1 <= n1 .and. i2 <= n2)
      if (a1(i1,1) < a2(i2,1)) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
  end
end program silver_fox_vs_monster

Score : 600 points

Problem Statement

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A.
There is no way other than bombs to decrease the monster's health.

Silver Fox wins when all the monsters' healths become 0 or below.

Find the minimum number of bombs needed to win.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq D \leq 10^9

1 \leq A \leq 10^9

0 \leq X_i \leq 10^9

1 \leq H_i \leq 10^9

X_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D A
X_1 H_1
:
X_N H_N

Output

Print the minimum number of bombs needed to win.

Sample Input 1

3 3 2
1 2
5 4
9 2

Sample Output 1

2

First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.

Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.

Now, all the monsters' healths are 0.
We cannot make all the monsters' health drop to 0 or below with just one bomb.

Sample Input 2

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5

Sample Output 2

5

We should use five bombs at the coordinate 5.

Sample Input 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


program main
      implicit none
      integer :: n, m

      read *, n, m

      if ( n == m ) then
        print *, 'Yes'
      else
        print *, 'No'
      end if
end program main

Score : 100 points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has N test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed M cases out of the N test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


program comparing_strings
  implicit none
  integer :: a, b, i
  read(*,*) a, b
  do i = 1, max(a,b)
    write(*,'(i0)',advance='no') min(a,b)
  end do
  write(*,*)
end program comparing_strings

Score : 200 points

Problem Statement

Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Constraints

1 \leq a \leq 9

1 \leq b \leq 9

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)

Sample Input 1

4 3

Sample Output 1

3333

We have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.

Sample Input 2

7 7

Sample Output 2

7777777


program test02
 implicit none
!character a, b
 integer a, b
 integer i, ii, j, jj

 read(5,*) a, b

 if ( a < b ) then
  do i=1,b
  write (*,fmt='(i0)',advance='no') a
  end do
 else
  do j=1,a
  write (*,fmt='(i0)',advance='no') b
  end do
 end if

endprogram test02


program test03
 implicit none
 integer,allocatable :: a(:)
 integer N
 integer i, j, jj
 integer :: yesf=0
 integer :: no=0

 read(5,*) N
 allocate(a(N))

 read(5,*) (a(i), i=1,N)

 do j=1,N
  if ( j/=1 ) then
   do jj=1,j
    if ( a(jj-1) < a(j) ) then
     no = 1
    end if
   end do
  end if
!print *,no
 if ( no==0 ) then
  yesf=yesf+1
 end if
 no=0
end do

 write (*,fmt='(i0)') yesf

endprogram test03

Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

1 \leq N \leq 2 \times 10^5

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


program B3
  implicit none

  integer :: n, i , j, cnt, min
  integer,allocatable,dimension(:) :: P

  read(*,*) n
  allocate(P(n))
  read(*,*) (P(j), j=1,n)

  cnt=1
  min=P(1)
  do i=2,n
     if(P(i).gt.min)  goto 300
     ! do j = 1,i-1
     !    if(P(j).lt.P(i))  then
     !       goto 300
     !    endif
     ! enddo
     cnt=cnt+1
     min=P(i)
300  continue
  enddo

  print *, cnt

end program B3


program B3
  implicit none

  integer :: n, i , j, cnt, min
  integer,allocatable,dimension(:) :: P

  read(*,*) n
  allocate(P(n))
  read(*,*) (P(j), j=1,n)

  cnt=1
  min=P(1)
  do i=2,n
     if(P(i).gt.min)  goto 300
     do j = 1,i-1
        if(P(j).lt.P(i))  then
           goto 300
        endif
     enddo
     cnt=cnt+1
     min=P(i)
300  continue
  enddo

  print *, cnt

end program B3


program handstand2
  implicit none
  integer :: n, i, a, b
  integer(8) :: c(9,9) = 0, x = 0
  read(*,*) n
  do i = 1, n
    a = mod(i,10)
    if (a == 0) cycle
    b = i
    do while (b >= 10)
      b = b/10
    end do
    c(a,b) = c(a,b)+1
  end do
  do a = 1, 9
    do b = 1, 9
      x = x+c(a,b)*c(b,a)
    end do
  end do
  write(*,'(i0)') x
end program handstand2

Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

1 \leq N \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008


program ABC152D
    implicit none
    integer(8)::N,i,j,top,tail
    integer(8)::result=0
    integer(8),dimension(10,10)::C
    read(5,*)N
    C=0

    do i=1,N
        tail=mod(i,10)
        j=i
        top=i
        do
            j=j/10
            if(j==0)then
                exit
            end if
            top=j
        end do
        C(top+1,tail+1)=C(top+1,tail+1)+1
    end do

    do i=1,10
        do j=1,10
            result=result+C(i,j)*C(j,i)
        end do
    end do

    print'(i0)',result
end program ABC152D


program Handstand2

  implicit none

  integer N
  integer a, b
  real logA,logB
  integer intLogA, intLogB
  integer a1, a2, b1, b2
  integer :: count = 0

  read *, N
  do a = 1, N
    do b = 1, N
      logA = log10(real(a))
      logB = log10(real(b))
      intLogA = 10 ** int(logA)
      intLogB = 10 ** int(logB)
      logA = real(intLogA)
      logB = real(intLogB)
      a1 = a / logA
      a2 = mod(a,10)
      b1 = b / logB
      b2 = mod(b,10)
      if (a1 == b2 .and. a2 == b1) then
        ! print *,a,b
        count = count + 1
      end if
    end do
  end do

  print '(i0)', count

end program


module mod_generate_fn
    private
type term
    integer(4):: factor,multiplier
end type
type factorized_num
    type(term), pointer:: num(:)
end type

public factorized_num, generate_fn, init_fn, calc_ldb, div_fn, multipl_fn
contains
subroutine generate_fn(x, fx)
    integer(4):: x, now_x
    type(factorized_num):: fx
    integer(4):: i

    now_x = x
    do i=2, nint(sqrt(real(x)))
        do while (mod(now_x, i) == 0)
            call add_factor_to_fn(fx, i)
            now_x = now_x / i
        end do
    end do

    if (now_x /= 1)then
        call add_factor_to_fn(fx, now_x)
    end if
    ! call print_fn(fx, 'pm')
end subroutine

subroutine init_fn(fx)
    type(factorized_num):: fx
    allocate(fx%num(0))
end subroutine

subroutine add_factor_to_fn(fx,pn)
    type(factorized_num):: fx, tmp
    integer(4):: now_size
    integer(4):: pn, i

    now_size = size(fx%num(:))
    do i=1, size(fx%num(:))
        if (fx%num(i)%factor == pn) then
            fx%num(i)%multiplier = fx%num(i)%multiplier + 1
            return
        end if
    end do
    ! not found num in fx%num(:)%factor--------------------
    call append_fn(fx, pn, 1)
end subroutine

subroutine print_fn(fn, word)
    type(factorized_num):: fn
    integer:: i
    character(*):: word

    print"(a5' : ----------------')", word
    do i = 1, size(fn%num(:))
        print"(i7' * 'i7)", fn%num(i)%factor, fn%num(i)%multiplier
    end do
end subroutine

subroutine calc_ldb(fldb, fn)
    type(factorized_num):: fldb, fn
    integer(4):: i,j
    integer(4):: fac, mul
    logical:: fac_exist

    do i=1,size(fn%num(:))
        fac = fn%num(i)%factor
        mul = fn%num(i)%multiplier
        fac_exist = .false.

        do j=1, size(fldb%num(:))
            if (fldb%num(j)%factor == fac)then
                fldb%num(j)%multiplier = max(fldb%num(j)%multiplier,mul)
                fac_exist = .true.
                exit
            end if
        end do

        if (.not. fac_exist) call append_fn(fldb,fac,mul)
        ! call print_fn(fldb,'ldb')
    end do
end subroutine

subroutine div_fn(fx, fy, ret)
    type(factorized_num):: fx,fy,ret
    integer(4):: ix,iy, fy_size,fx_size, i
    call init_fn(ret)
    fx_size = size(fx%num(:))
    fy_size = size(fy%num(:))
    ix = 1
    iy = 1

    do while(ix <= fx_size .and. iy <= fy_size)
        if (fy%num(iy)%factor /= fx%num(ix)%factor) then

            block
                integer:: fac, mul
                fac = fx%num(ix)%factor
                mul = fx%num(ix)%multiplier
                call append_fn(ret,fac,mul)
            end block
            ix = ix+1
        else

            block
                integer(4):: fac, mul_x, mul_y
                fac = fx%num(ix)%factor
                mul_x = fx%num(ix)%multiplier
                mul_y = fy%num(iy)%multiplier
                call append_fn(ret, fac, mul_x-mul_y)
            end block
            ix = ix+1
            iy = iy+1
        end if
    end do

    do i = ix, fx_size; block
        integer:: fac, mul
        fac = fx%num(i)%factor
        mul = fx%num(i)%multiplier
        call append_fn(ret,fac,mul)
    end block;end do
    ! call print_fn(ret,'b')
    end subroutine

subroutine append_fn(fx, fac, mul)
    type(factorized_num):: fx,tmp
    integer(4):: now_size, fac, mul

    now_size = size(fx%num(:))
    allocate(tmp%num(now_size))
    tmp%num(:) = fx%num(:)
    deallocate(fx%num)
    allocate(fx%num(now_size+1))
    fx%num(:now_size) = tmp%num(:)
    deallocate(tmp%num)
    fx%num(now_size+1)%factor = fac
    fx%num(now_size+1)%multiplier = mul
end subroutine

function multipl_fn(fx) result(x)
    type(factorized_num):: fx
    integer(8):: x
    integer(4):: fx_size, i, fac, mul
    integer(4), parameter:: big = 1000000007

    fx_size = size(fx%num(:))
    x = 1
    do i=1, fx_size
        fac = fx%num(i)%factor
        mul = fx%num(i)%multiplier
        x = x*fac**mul
        if (x >= big) x = mod(x,big)
    end do
end function
end module

program flatten
    use mod_generate_fn
    implicit none
    integer(4):: n, i
    integer(4), allocatable:: a(:)
    integer(4), parameter:: big = 1000000007
    integer(8) :: sumb,b
    type(factorized_num), allocatable:: fa(:)
    type(factorized_num):: fldb, fb

    read*, n
    allocate(a(n), fa(n))
    read*, a(:)

    call init_fn(fldb)

    do i = 1,n
        call init_fn(fa(i))
        call generate_fn(a(i), fa(i))
        call calc_ldb(fldb,fa(i))
    end do

    sumb = 0

    do i = 1,n
        call div_fn(fldb,fa(i),fb)
        b = multipl_fn(fb)
        sumb = sumb + b
        if (sumb >= big) sumb = mod(sumb,big)
    end do

    print*, sumb
end program flatten

Score : 500 points

Problem Statement

Given are N positive integers A_1,...,A_N.

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

Print the sum modulo (10^9+7).


module mod_tree_map
  implicit none

  type t_entry
    private
    integer :: key
    integer :: val
  end type t_entry

  type t_node
    private
    type(t_node), pointer :: left => null(), right => null()
    integer :: level = 1
    type(t_entry), pointer :: e => null()
  end type t_node

  type t_tree_map
    private
    type(t_node), pointer :: root => null()
    integer :: deflt = 0
  end type t_tree_map

contains

  function new_entry(key,val) result(e)
    integer, intent(in) :: key
    integer, intent(in) :: val
    type(t_entry), pointer :: e
    e => null()
    allocate(e)
    e%key = key
    e%val = val
  end

  function new_node(e) result(n)
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: n
    n => null()
    allocate(n)
    n%e => e
  end

  integer function level(n)
    type(t_node), pointer, intent(in) :: n
    level = 0
    if (.not.associated(n)) return
    level = n%level
  end

  logical function is_leaf(n)
    type(t_node), pointer, intent(in) :: n
    is_leaf = associated(n) .and. .not.associated(n%left) .and. &
    &         .not.associated(n%right)
  end

  recursive function tree_size(n) result(s)
    type(t_node), pointer, intent(in) :: n
    integer :: s
    s = 0
    if (.not.associated(n)) return
    s = 1+tree_size(n%left)+tree_size(n%right)
  end

  function skew(n) result(l)
    type(t_node), pointer, intent(in) :: n
    type(t_node), pointer :: l
    l => n
    if (.not.(associated(n) .and. associated(n%left) .and. &
    &   n%left%level == n%level)) return
    l => n%left
    n%left => l%right
    l%right => n
  end

  function split(n) result(r)
    type(t_node), pointer, intent(in) :: n
    type(t_node), pointer :: r
    r => n
    if (.not.(associated(n) .and. associated(n%right) .and. &
    &   associated(n%right%right) .and. n%right%right%level == n%level)) return
    r => n%right
    n%right => r%left
    r%left => n
    r%level = r%level+1
  end

  function predecessor(n) result(p)
    type(t_node), pointer, intent(in) :: n
    type(t_node), pointer :: p
    p => null()
    if (.not.associated(n%left)) return
    p => n%left
    do while (associated(p%right))
      p => p%right
    end do
  end

  function successor(n) result(s)
    type(t_node), pointer, intent(in) :: n
    type(t_node), pointer :: s
    s => null()
    if (.not.associated(n%right)) return
    s => n%right
    do while (associated(s%left))
      s => s%left
    end do
  end

  recursive function insert(n,e) result(t)
    type(t_node), pointer, intent(in) :: n
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: t
    t => new_node(e)
    if (.not.associated(n)) return
    t => n
    if (e%key < t%e%key) then
      t%left => insert(t%left,e)
    else if (e%key > t%e%key) then
      t%right => insert(t%right,e)
    else
      t%e => e
    end if
    t => skew(t)
    t => split(t)
  end

  recursive function delete(n,e) result(t)
    type(t_node), pointer, intent(in) :: n
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: t, l
    t => n
    if (.not.associated(n)) return
    if (e%key < t%e%key) then
      t%left => delete(t%left,e)
    else if (e%key > t%e%key) then
      t%right => delete(t%right,e)
    else
      if (is_leaf(t)) return
      if (.not.associated(t%left)) then
        l => successor(t)
        t%right => delete(t%right,l%e)
        t%e => l%e
      else
        l => predecessor(t)
        t%left => delete(t%left,l%e)
        t%e => l%e
      end if
    end if
    t => decrease_level(t)
    t => skew(t)
    t%right => skew(t%right)
    if (associated(t%right)) t%right%right => skew(t%right%right)
    t => split(t)
    t%right => split(t%right)
  end

  function decrease_level(n) result(t)
    type(t_node), pointer, intent(in) :: n
    type(t_node), pointer :: t
    integer :: should_be
    t => n
    should_be = min(level(t%left),level(t%right))+1
    if (t%level > should_be) then
      t%level = should_be
      if (level(t%right) > should_be) t%right%level = should_be
    end if
  end

  recursive subroutine release_tree(t)
    type(t_node), pointer, intent(inout) :: t
    if (.not.associated(t)) return
    call release_tree(t%left)
    call release_tree(t%right)
    deallocate(t)
  end

  recursive subroutine get_keys_list(t,keys,num)
    type(t_node), pointer, intent(in) :: t
    integer, intent(inout) :: keys(:)
    integer, intent(inout) :: num
    if (.not.associated(t)) return
    call get_keys_list(t%left,keys,num)
    num = num+1
    keys(num) = t%e%key
    call get_keys_list(t%right,keys,num)
  end

  integer function size_of(map)
    type(t_tree_map), intent(in) :: map
    size_of = tree_size(map%root)
  end

  subroutine clear(map)
    type(t_tree_map), intent(inout) :: map
    call release_tree(map%root)
    map%root => null()
  end

  subroutine set_default(map,deflt)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: deflt
    map%deflt = deflt
  end

  subroutine put_entry(map,e)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    map%root => insert(map%root,e)
  end

  subroutine remove_entry(map,e)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    map%root => delete(map%root,e)
  end

  function get_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    do while (associated(n))
      if (e%key < n%e%key) then
        n => n%left
      else if (e%key > n%e%key) then
        n => n%right
      else
        ret => n%e
        return
      end if
    end do
  end

  function contain_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: n
    logical :: ret
    ret = .false.
    n => map%root
    do while (associated(n))
      if (e%key < n%e%key) then
        n => n%left
      else if (e%key > n%e%key) then
        n => n%right
      else
        ret = .true.
        return
      end if
    end do
  end

  function get_first_entry(map) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    if (.not.associated(n)) return
    do while (associated(n%left))
      n => n%left
    end do
    ret => n%e
  end

  function poll_first_entry(map) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    if (.not.associated(n)) return
    do while (associated(n%left))
      n => n%left
    end do
    ret => n%e
    map%root => delete(map%root,ret)
  end

  function get_last_entry(map) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    if (.not.associated(n)) return
    do while (associated(n%right))
      n => n%right
    end do
    ret => n%e
  end

  function poll_last_entry(map) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    if (.not.associated(n)) return
    do while (associated(n%right))
      n => n%right
    end do
    ret => n%e
    map%root => delete(map%root,ret)
  end

  function floor_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    do while (associated(n))
      if (e%key < n%e%key) then
        n => n%left
      else if (e%key > n%e%key) then
        if (.not.associated(ret)) then
          ret => n%e
          cycle
        end if
        if (e%key-ret%key > e%key-n%e%key) ret => n%e
        n => n%right
      else
        ret => n%e
        return
      end if
    end do
  end

  function lower_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_entry), pointer :: ret
    ret => floor_entry(map,new_entry(e%key-1,0))
  end

  function ceiling_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_node), pointer :: n
    type(t_entry), pointer :: ret
    ret => null()
    n => map%root
    do while (associated(n))
      if (e%key < n%e%key) then
        if (.not.associated(ret)) then
          ret => n%e
          cycle
        end if
        if (e%key-ret%key < e%key-n%e%key) ret => n%e
        n => n%left
      else if (e%key > n%e%key) then
        n => n%right
      else
        ret => n%e
        return
      end if
    end do
  end

  function higher_entry(map,e) result(ret)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer, intent(in) :: e
    type(t_entry), pointer :: ret
    ret => ceiling_entry(map,new_entry(e%key+1,0))
  end

  subroutine get_keys(map,keys,num)
    type(t_tree_map), intent(inout) :: map
    integer, intent(inout) :: keys(:)
    integer, intent(inout) :: num
    keys = 0
    num = 0
    call get_keys_list(map%root,keys,num)
  end

  subroutine put(map,key,val)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    integer, intent(in) :: val
    call put_entry(map,new_entry(key,val))
  end

  subroutine remove(map,key)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    call remove_entry(map,new_entry(key,0))
  end

  function get(map,key) result(val)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    type(t_entry), pointer :: tmp
    integer :: val
    val = map%deflt
    tmp => get_entry(map,new_entry(key,0))
    if (.not.associated(tmp)) return
    val = tmp%val
  end

  logical function contain(map,key)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    contain = contain_entry(map,new_entry(key,0))
  end

  function get_first_key(map) result(key)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer :: tmp
    integer :: key
    key = map%deflt
    tmp => get_first_entry(map)
    if (.not.associated(tmp)) return
    key = tmp%key
  end

  function get_last_key(map) result(key)
    type(t_tree_map), intent(inout) :: map
    type(t_entry), pointer :: tmp
    integer :: key
    key = map%deflt
    tmp => get_last_entry(map)
    if (.not.associated(tmp)) return
    key = tmp%key
  end

  function floor_key(map,key) result(ret)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    type(t_entry), pointer :: tmp
    integer :: ret
    ret = map%deflt
    tmp => floor_entry(map,new_entry(key,0))
    if (.not.associated(tmp)) return
    ret = tmp%key
  end

  function lower_key(map,key) result(ret)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    type(t_entry), pointer :: tmp
    integer :: ret
    ret = map%deflt
    tmp => lower_entry(map,new_entry(key,0))
    if (.not.associated(tmp)) return
    ret = tmp%key
  end

  function ceiling_key(map,key) result(ret)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    type(t_entry), pointer :: tmp
    integer :: ret
    ret = map%deflt
    tmp => ceiling_entry(map,new_entry(key,0))
    if (.not.associated(tmp)) return
    ret = tmp%key
  end

  function higher_key(map,key) result(ret)
    type(t_tree_map), intent(inout) :: map
    integer, intent(in) :: key
    type(t_entry), pointer :: tmp
    integer :: ret
    ret = map%deflt
    tmp => higher_entry(map,new_entry(key,0))
    if (.not.associated(tmp)) return
    ret = tmp%key
  end

end module mod_tree_map
program ABC152E
    use mod_tree_map
    implicit none
    integer::N
    integer,allocatable,dimension(:)::A
    type(t_tree_map),allocatable,dimension(:)::AYK
    type(t_tree_map)::KYK
    integer::NXT(10**6)
    integer::i,j,k,cnt,JIND
    integer(16)::PLUS,KAKE
    integer::ans=0,mo=10**9+7
    open(1,file='max_01', status='old')
    !read(1,*) N
    read*,N
    allocate(A(N),AYK(N))
    read*,A
    !read(1,*)A
    do i=1,N
        do j=2,int(sqrt(real(A(i))+1))
            if(mod(A(i),j)/=0)cycle
            cnt=0
            do while(mod(A(i),j)==0)
                cnt=cnt+1
                A(i)=A(i)/j
            end do
            if(cnt/=0)then
                call put(AYK(i),j,cnt)
                if(get(KYK,j)<cnt)then
                    call put(KYK,j,cnt)
                endif
            endif
        end do
        if(A(i)/=1)then
            call put(AYK(i),A(i),1)
            if(get(KYK,A(i))<1)then
                call put(KYK,A(i),1)
            endif
        endif
    end do
    NXT=0
    NXT(1)=get_first_key(KYK)
    do i=1,10**5-1
        NXT(i+1)=higher_key(KYK,NXT(i))
        if(NXT(i+1)==0)exit
    end do
    do i=1,N
        JIND=1
        j=NXT(1)
        PLUS=1
        do while(j/=0)
            KAKE=j**(get(KYK,j)-get(AYK(i),j))
            if(KAKE>=mo)KAKE=mod(KAKE,mo)
            PLUS=PLUS*KAKE
            if(PLUS>=mo)PLUS=mod(PLUS,mo)
            JIND=JIND+1
            j=NXT(JIND)
        end do
        ANS=mod(ANS+PLUS,mo)
    end do
    print"(i0)",ANS
contains
end program ABC152E


program ap
  implicit none
  integer :: ans, larg, cnttai,in
  integer :: h, w , n, i, sumers, csum, err, j, jc(1)
  integer,allocatable,dimension(:) :: X, xmax, xmin
  integer,allocatable,dimension(:) :: L, cnt,ers
  integer,allocatable,dimension(:,:) :: taio

  read(*,*) n

  allocate( X(n) )
  allocate( L(n) )
  allocate( xmax(n) )
  allocate( xmin(n) )
  allocate( cnt(n) )
  allocate( ers(n) )
  allocate( taio(n,n) )

  do i=1,n
     read(*,*) X(i), L(i)
     xmax(i)=X(i)+L(i)
     xmin(i)=X(i)-L(i)
  enddo

  ers(:)=0
  cnt(:)=0
  sumers=0
  csum=0
  taio(:,:)=0
  do i=1,n
     do j=1,n
        if(i.eq.j) goto 300
        w=0
        if(xmax(i).gt.xmin(j).and.xmax(i).le.xmax(j)) then
           w=w+1
        endif
        if(xmin(i).lt.xmax(j).and.xmin(i).ge.xmin(j)) then
           w=w+1
        endif

        if(w.eq.2) then
           ers(j)=1
           taio(j,i)=1
!           print *, i, j
        elseif(w.eq.1) then
           taio(j,i)=1
        endif
        300 continue
     enddo
  enddo
  do j=1,n
     do i=1,n
        csum=csum+taio(j,i)
     enddo
  enddo
  err=0

  do j=1,n
     if(ers(j).eq.1) then
        do i=1,n
           cnttai=cnttai+taio(j,i)
        enddo
        csum=csum-cnttai*2
        taio(j,:)=0
        taio(:,j)=0
        err=err+1
     endif
  enddo

  if(sum(taio).le.0) goto 400

  cnt(:)=0
  do j =1,n
     do i=1,n
        cnt(j)=cnt(j)+taio(j,i)
     enddo
  enddo

  do i=1,n

     cnt(:)=0
     do j =1,n
        do in=1,n
           cnt(j)=cnt(j)+taio(j,in)
        enddo
     enddo

     jc=maxloc(cnt)
     err=err+1
!     cnt(jc(1))=0
     taio(jc(i),:)=0
     taio(:,jc(i))=0
     do j =1,n
        do in=1,n
           larg=larg+taio(j,in)
        enddo
     enddo
     if(larg.le.0) goto 400

  enddo
400 continue

  print *,  n-err

end program ap

Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

0 \leq X_i \leq 10^9 (1 \leq i \leq N)

1 \leq L_i \leq 10^9 (1 \leq i \leq N)

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,s
    integer(int32), allocatable:: ans(:)

    read*, n,k,s
    allocate(ans(n))
    ans(:) = 1000000000
    ans(1:k) = s
    print*, ans(:)
end program name

Score : 400 points

Problem Statement

Given are three integers N, K, and S.

Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below.
We can prove that, under the conditions in Constraints, such a sequence always exists.

There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq N and A_l + A_{l + 1} + \cdots + A_r = S.

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N

1 \leq S \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K S

Output

Print a sequence satisfying the condition, in the following format:

A_1 A_2 ... A_N

Sample Input 1

4 2 3

Sample Output 1

1 2 3 4

Two pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement.

Sample Input 2

5 3 100

Sample Output 2

50 50 50 30 70


program next_alphabet
    implicit none
    character(1):: c
    character(26), parameter:: alphabet = "abcdefghijklmnopqrstuvwxyz"
    integer:: i

    read*, c
    do i=1, 26
        if (alphabet(i:i) == c)then
            print*, alphabet(i+1:i+1)
            stop
        end if
    end do
end program next_alphabet

Score : 100 points

Problem Statement

Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.

Constraints

C is a lowercase English letter that is not z.

Input

Input is given from Standard Input in the following format:

C

Output

Print the letter that follows C in alphabetical order.

Sample Input 1

a

Sample Output 1

b

a is followed by b.

Sample Input 2

y

Sample Output 2

z

y is followed by z.


program main
  implicit none
  integer(8) :: n, m, i, j, cor, pna, w
  integer(8), allocatable :: p(:)
  character(2), allocatable :: s(:)

  read(*,*) n, m
  allocate(p(m))
  allocate(s(m))
  do i = 1, m
     read(*,*) p(i), s(i)
  end do

  cor = 0
  pna = 0
  do i = 1, n
     w = 0
     do j = 1, m
        if(p(j) == i) then
           if(s(j) == 'WA') then
              w = w + 1
           else
              cor = cor + 1
              pna = pna + w
              exit
           end if
        end if
     end do
  end do

  write(*,*) cor, pna
end program main

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


program welcome_to_atcoder
    implicit none
    integer(4):: n, m, i, all_ac, all_pena
    integer(4), allocatable:: p(:),pena(:)
    character(2), allocatable:: s(:)
    logical, allocatable:: is_ac(:)
    read*, n, m
    allocate(p(m), s(m), is_ac(n), pena(n))
    do i=1, m
        read*, p(i),s(i)
    end do
    is_ac(:) = .false.
    pena(:) = 0
    do i=1, m
        if (s(i) == "AC") then
            is_ac(p(i)) = .true.
        else
            if (.not. is_ac(p(i))) pena(p(i)) = pena(p(i)) + 1
        end if
    end do

    all_ac = 0
    all_pena = 0

    do i=1, n
        if (is_ac(i)) then
            all_ac = all_ac + 1
            all_pena = all_pena + pena(i)
        end if
    end do

    print"(i01xi0)", all_ac, all_pena

end program welcome_to_atcoder


program test03
 implicit none
 integer N, M
 integer i
 integer,allocatable :: AC(:)
 integer,allocatable :: WA(:)
 integer Nnum
 character Nkek*2
 integer :: allAC=0, allWA=0

 read *, N, M
 allocate(AC(N))
 allocate(WA(N))
 AC=0; WA=0

 do i=1,M
  read *, Nnum, Nkek
  if ( Nkek == 'AC' ) then
   AC(Nnum)=1
  else
   if ( AC(Nnum) == 0 ) then
   WA(Nnum)=WA(Nnum)+1
   end if
  end if
 end do

 do i=1,N
  allAC=allAC+AC(i)
  if ( AC(i) == 1 ) then
   allWA=allWA+WA(i)
  end if
 end do

 print '(i0,A,i0)', allAC, ' ',allWA

endprogram test03


program main
implicit none
integer i,j,k,m,n,n_answer,n_penalty
integer,allocatable :: p(:),S(:)
character(2) chr
read(*,*) n,m
allocate(p(m))
allocate(S(m))
S(:)=0
do i=1,m
   read(*,*) p(i),chr
   if (chr=='AC') then
      S(i)=1
   else if (chr=='WA') then
      S(i)=2
   end if
end do
n_answer=0; n_penalty=0
do i=1,n
   do j=1,m
   !write(*,*) 'i,j',i,j
   if(p(j)==i .and. S(j)==1) then
      n_answer = n_answer + 1
      do k=1,j-1
         if(p(k)==i) then
            if (S(k)==2) then
               n_penalty = n_penalty + 1
            end if
         end if
         !write(*,*) 'k,pen',k,n_penalty
       end do
       exit
    end if
    end do
end do
write(*,'(i0,a,i0)') n_answer,' ',n_penalty
end program main


program main

  implicit none

  integer    :: n, m, i, j
  integer(8) :: nac, nwa
  integer,allocatable :: p(:), jj(:)
  character(2),allocatable ::  s(:)

  read(*,*) n, m
  allocate( p(m) )
  allocate( s(m) )
  allocate( jj(n) ); jj = 0

  do i = 1, m
    read(*,*) p(i), s(i)
  end do

  do i = 1, m
    if ( s(i) == "AC" .and. jj( p(i) ) == 0 ) then
      nac = nac + 1
      jj( p(i) ) = jj( p(i) ) + 1
    else if ( s(i) == "WA" .and. jj( p(i) ) == 0 ) then
      nwa = nwa + 1
    end if
  end do

  print*, nac, nwa

end program main


program main

  implicit none

  integer :: n, m, i, j, nac, nwa
  integer,allocatable :: p(:)
  character(2),allocatable ::  s(:)

  read(*,*) n, m
  allocate( p(m) )
  allocate( s(m) )

  do i = 1, m
    read(*,*) p(i), s(i)
  end do

  nac = 0; nwa = 0
  do j = 1, n
    do i = 1, m
      if ( s(i) == "WA" .and. j == p(i) ) then
        nwa = nwa + 1
!        print*, j, i, nwa, nac
      end if
      if ( s(i) == "AC" .and. j == p(i) ) then
        nac = nac + 1
!        print*, j, i, nwa, nac
        exit
      end if
    end do
  end do

  print*, nac, nwa

end program main


program welcome_to_atcoder
  implicit none
  integer :: n, m, p, wa(100000) = 0, i, a = 0, w = 0
  logical :: ac(100000) = .false.
  character(1) :: s
  read(*,*) n, m
  do i = 1, m
    read(*,*) p, s
    ac(p) = ac(p) .or. s == "A"
    if (ac(p)) cycle
    wa(p) = wa(p)+1
  end do
  do i = 1, n
    if (ac(i)) then
      a = a+1
      w = w+wa(i)
    end if
  end do
  write(*,'(i0,x,i0)') a, w
end program welcome_to_atcoder


program ABC151D
    implicit none
    integer::H,W
    character(20)::S
    integer,allocatable,dimension(:,:)::maze
    integer,allocatable,dimension(:,:)::Route
    integer::i,j
    integer::ans
    read*,H,W
    allocate(maze(H,W))
    maze=0
    do i=1,H
        read*,S
        do j=1,W
            if(S(j:j)==".")maze(i,j)=1
        end do
    end do
    allocate(Route(point(H,W),point(H,W)))
    Route=1000
    do i=1,W
        if(maze(geti(i),getj(i))==1)then
            Route(i,i)=0
            if(i/=1)then
                if(maze(geti(i),getj(i)-1)==1)then
                    Route(i,i-1)=1
                    Route(i-1,i)=1
                endif
            endif
        endif
    end do
    do i=W+1,H*W
        if(maze(geti(i),getj(i))==1)then
            Route(i,i)=0
            if(geti(i)/=1)then
                if(maze(geti(i),getj(i)-1)==1)then
                    Route(i,i-1)=1
                    Route(i-1,i)=1
                endif
            endif
            if(maze(geti(i)-1,getj(i))==1)then
                Route(i,i-W)=1
                Route(i-W,i)=1
            endif
        endif
    end do
    call Warshall_Floyd(H*W,Route)
    ans=0
    do i=1,H*W
        do j=1,H*W
            if(Route(i,j)/=1000)ans=max(ans,Route(i,j))
        end do
    end do
    print"(i0)",ans
contains
function point(i,j)
    integer::i,j
    integer::point
    point=(i-1)*W+j
end function
function geti(i)
    integer::i
    integer::geti
    geti=(i-1)/W +1
end function
function getj(i)
    integer::i
    integer::getj
    getj=mod(i-1,W)+1
end function
subroutine Warshall_Floyd(n,Route)
  !nは頂点の数、Routeは全ての経路の長さを記録したもの
  !以下の型宣言は場合に応じて変えること
  implicit none
  integer, intent(in) :: n
  integer, intent(inout) :: Route(n, n)
  integer :: i, j, k

    do k = 1, n
      do i = 1, n
        do j = 1, n
          Route(j, i) = min( Route(j, i), Route(j, k) + Route(k, i))
        end do
      end do
    end do
end subroutine Warshall_Floyd
end program ABC151D

Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.


Score : 600 points

Problem Statement

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

2 \leq N \leq 50

0 \leq x_i \leq 1000

0 \leq y_i \leq 1000

The given N points are all different.

The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum radius of a circle such that all the N points are inside or on it.

Your output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

Both points are contained in the circle centered at (0.5,0) with a radius of 0.5.

Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Sample Output 3

6.726812023536805158

If the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.