program sample
  implicit none

  integer :: a, b, c

  read(*,*) a,b,c

  if(b-a==c-b) then
     write(*,*) 'YES'
  else
     write(*,*) 'NO'
  end if
   stop
 end program sample

Score : 100 points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

Determine whether the arrangement of the poles is beautiful.

Constraints

1 \leq a,b,c \leq 100

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.

Sample Input 1

2 4 6

Sample Output 1

YES

Since 4-2 = 6-4, this arrangement of poles is beautiful.

Sample Input 2

2 5 6

Sample Output 2

NO

Since 5-2 \neq 6-5, this arrangement of poles is not beautiful.

Sample Input 3

3 2 1

Sample Output 3

YES

Since 1-2 = 2-3, this arrangement of poles is beautiful.


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

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 tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 40, p(80) = 0, i
  read(*,*) n
  do while (k > 0)
    if (n >= lshift(1_8,k)-1_8) exit
    k = k-1
  end do
  do i = 1, k
    p(i) = i
  end do
  n = n-lshift(1_8,k)+1_8
  do i = k-1, 0, -1
    if (n < lshift(1_8,i)) cycle
    p(i+1:k+1) = p(i:k)
    k = k+1
    p(i) = k
    n = n-lshift(1_8,i)
  end do
  do i = 1, k
    p(k+i) = i
  end do
  write(*,'(i0)') 2*k
  write(*,'(i0)',advance='no') p(1)
  do i = 2, 2*k
    write(*,'(x,i0)',advance='no') p(i)
  end do
  write(*,*)
end program tautonym_puzzle

Score : 1000 points

Problem Statement

We will call a string x good if it satisfies the following condition:

Condition: x can be represented as a concatenation of two copies of another string y of length at least 1.

For example, aa and bubobubo are good; an empty string, a, abcabcabc and abba are not good.

Eagle and Owl created a puzzle on good strings.
Find one string s that satisfies the following conditions. It can be proved that such a string always exists under the constraints in this problem.

1 ≤ |s| ≤ 200

Each character of s is one of the 100 characters represented by the integers 1 through 100.

Among the 2^{|s|} subsequences of s, exactly N are good strings.

Constraints

1 ≤ N ≤ 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

In the first line, print |s|, the length of s.
In the second line, print the elements in s in order, with spaces in between. Any string that satisfies the above conditions will be accepted.

Sample Input 1

7

Sample Output 1

4
1 1 1 1

There are two good strings that appear as subsequences of s: (1,1) and (1,1,1,1). There are six occurrences of (1,1) and one occurrence of (1,1,1,1), for a total of seven.

Sample Input 2

299

Sample Output 2

23
32 11 11 73 45 8 11 83 83 8 45 32 32 10 100 73 32 83 45 73 32 11 10


program main
  implicit none
  integer(16)::N,A,B
  integer(16),allocatable,dimension(:,:)::C
  integer(16),allocatable,dimension(:)::v
  integer(16)::i
  integer(16),parameter::mo=10**9+7_16
  real(16)::ANS1
  integer(16)::ANS2
  integer(16)::cnt,cnt2
  read*,N,A,B
  allocate(v(N))
  read*,v
  call heapsort(N,v)
  ANS1=0
  do i=N,N-A+1,-1
   ANS1=ANS1+v(i)
  end do
  ANS1=ANS1/real(A)
  print"(f0.20)",ANS1
  call comb_table(N)

  if(v(N)/=v(N-A+1))then
   cnt=0
   do i=N,1,-1
      if(v(i)/=v(N-A+1))exit
      cnt=cnt+1
   end do
   cnt2 = count(v(n-a+1:n) == v(n-a+1))
   ANS2=C(cnt,cnt2)
  else
   cnt=A
   do i=N-A,1,-1
      if(v(i)/=v(N))exit
      cnt=cnt+1
   end do
   ANS2=0
   do i=A,B
      ANS2=ANS2+C(cnt,i)
   end do
  endif
  print"(i0)",ANS2
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
subroutine comb_table(N)
   integer(16)::N
   integer(16)::i,j
   allocate(C(0:N,0:N))
   C=0
   do i=0,N
      do j=0,i
         if(j==0 .or. j==i)then
            C(i,j)=1
         else
            C(i,j)=C(i-1,j-1)+C(i-1,j)
         endif
      end do
   end do
end subroutine
end program main

Score : 100 points

Problem Statement

Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.

In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".

The current time is A o'clock, and a contest will begin in exactly B hours.
When will the contest begin? Answer in 24-hour time.

Constraints

0 \leq A,B \leq 23

A and B are integers.

Input

The input is given from Standard Input in the following format:

A B

Output

Print the hour of the starting time of the contest in 24-hour time.

Sample Input 1

9 12

Sample Output 1

21

In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.

Sample Input 2

19 0

Sample Output 2

19

The contest has just started.

Sample Input 3

23 2

Sample Output 3

1

The contest will begin at 1 o'clock the next day.


integer,parameter :: p = 8
integer(p) :: n,i

do i = ceiling(sqrt(real(n))),1,-1
  if( mod(n,i)==0 ) exit
end do

print*,max(digit(i),digit(n/i))

contains
function digit( n ) result( i )
  integer(p) :: i,n
  i = 0
  do while( n/=0 )
    n = n / 10
    i = i + 1
  end do
end function

end

Score : 300 points

Problem Statement

You are given an integer N.

For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.

For example, F(3,11) = 2 since 3 has one digit and 11 has two digits.

Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Constraints

1 \leq N \leq 10^{10}

N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Sample Input 1

10000

Sample Output 1

3

F(A,B) has a minimum value of 3 at (A,B)=(100,100).

Sample Input 2

1000003

Sample Output 2

7

There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.

Sample Input 3

9876543210

Sample Output 3

6


integer(16) N,ans,i
read*,N
ans=huge(ans)
do i=1,N
  if(i*i>N)exit
  if(mod(N,i)==0)then
    do j=10,0,-1
      if(N/i>=10**j)then
        ans=min(ans,j+1)
        exit
      endif
    end do
  endif
end do
print"(I0)",ans
end


program main
  implicit none
  integer(16)::N,A,B
  integer(16),allocatable,dimension(:,:)::C
  integer(16),allocatable,dimension(:)::v
  integer(16)::i
  integer(16),parameter::mo=10**9+7_16
  real(16)::ANS1
  integer(16)::ANS2
  integer(16)::cnt,cnt2
  read*,N,A,B
  allocate(v(N))
  read*,v
  call heapsort(N,v)
  ANS1=0
  do i=N,N-A+1,-1
   ANS1=ANS1+v(i)
  end do
  ANS1=ANS1/real(A)
  print"(f0.20)",ANS1
  call comb_table(N)

  if(v(N)/=v(N-A+1))then
   cnt=count(v(1:n) == v(n-a+1))
   cnt2 = count(v(n-a+1:n) == v(n-a+1))
   ANS2=C(cnt,cnt2)
  else
   cnt=A
   do i=N-A,1,-1
      if(v(i)/=v(N))exit
      cnt=cnt+1
   end do
   ANS2=0
   do i=A,B
      ANS2=ANS2+C(cnt,i)
   end do
  endif
  print"(i0)",ANS2
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
subroutine comb_table(N)
   integer(16)::N
   integer(16)::i,j
   allocate(C(0:N,0:N))
   C=0
   do i=0,N
      do j=0,i
         if(j==0 .or. j==i)then
            C(i,j)=1
         else
            C(i,j)=C(i-1,j-1)+C(i-1,j)
         endif
      end do
   end do
end subroutine
end program main

Score : 400 points

Problem Statement

You are given N items.

The value of the i-th item (1 \leq i \leq N) is v_i.

Your have to select at least A and at most B of these items.

Under this condition, find the maximum possible arithmetic mean of the values of selected items.

Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

The input is given from Standard Input in the following format:

N A B
v_1
v_2
...
v_N

Output

Print two lines.

The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.

The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.

There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

There can be multiple ways to select items so that the mean of the values will be maximized.

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1


program sample
	implicit none
    character(len=1) ::a,b

    read(*,*) a,b

    if (a==b) then
    	write(*,*) 'H'
    else
    	write(*,*) 'D'
	end if

    stop
end program sample

Score : 100 points

Problem Statement

Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given two characters a and b as the input. Each of them is either H or D, and carries the following information:

If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.
If b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.

Given this information, determine whether TopCoDeer is honest.

Constraints

a=H or a=D.

b=H or b=D.

Input

The input is given from Standard Input in the following format:

a b

Output

If TopCoDeer is honest, print H. If he is dishonest, print D.

Sample Input 1

H H

Sample Output 1

H

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.

Sample Input 2

D H

Sample Output 2

D

In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.

Sample Input 3

D D

Sample Output 3

H


program main
    use,intrinsic :: iso_fortran_env
    implicit none
    character(1):: a,b
    read*, a,b
    if (a==b) then
        print'(a)', 'H'
    else
        print'(a)', 'D'
    end if

end program main


program main
implicit none
integer :: W,a,b,d
  read(*,*) W,a,b
  d = ABS( b - a )
  if(d<W)then
    print*,0
  else
    print*,d-w
  endif
end program main

Score : 200 points

Problem Statement

AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.
Find the minimum distance it needs to be moved.

Constraints

All input values are integers.

1≤W≤10^5

1≤a,b≤10^5

Input

The input is given from Standard Input in the following format:

W a b

Output

Print the minimum distance the second rectangle needs to be moved.

Sample Input 1

3 2 6

Sample Output 1

1

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.

Sample Input 2

3 1 3

Sample Output 2

0

The rectangles are already connected, and thus no move is needed.

Sample Input 3

5 10 1

Sample Output 3

4


program main
	implicit none
	integer    :: W, a, b
	read(*, *) W, a, b
	if(a <= b .AND. b <= a+W) then
		write(*, *) 0
	else if(a+W < b) then
		write(*, *) b-(a+W)
	else
		write(*, *) a-(b+W)
	end if
end program main


program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)

    read(*,*)k
    do i=1,k/2+1
        m=m+i
        if(m>=k)then

            ans=i

            write(*,*)ans
            stop
        end if
    end do

    stop
end program sample

Score : 200 points

Problem Statement

There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.
During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.
That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.
The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.
Find the earliest possible time to reach coordinate X.

Constraints

X is an integer.

1≤X≤10^9

Input

The input is given from Standard Input in the following format:

X

Output

Print the earliest possible time for the kangaroo to reach coordinate X.

Sample Input 1

6

Sample Output 1

3

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.

Sample Input 2

2

Sample Output 2

2

He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.

Sample Input 3

11

Sample Output 3

5


module merge_sort_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    private
    public:: merge_sort, double_merge_sort
    interface merge_sort
        module procedure ms32, ms64
    end interface

    interface double_merge_sort
        module procedure msd3232, msd6464
    end interface
contains
    recursive subroutine ms32(ar, fst, lst)
        integer(int32),intent(inout):: ar(:)
        integer(int32),intent(in):: fst,lst
        integer(int32):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap32(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call ms32(ar, fst, mdl)
        call ms32(ar, mdl+1, lst)
        call merge32(ar, fst, mdl, lst)
    end subroutine

    subroutine merge32(ar, fst, mdl, lst)
        integer(int32),intent(inout):: ar(:)
        integer(int32),intent(in):: fst, mdl, lst
        integer(int32),allocatable:: tmp(:)
        integer(int32):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

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

    subroutine swap32(x,y)
        integer(int32),intent(inout):: x,y
        integer(int32):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine

    recursive subroutine ms64(ar, fst, lst)
        integer(int64),intent(inout):: ar(:)
        integer(int64),intent(in):: fst,lst
        integer(int64):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap64(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call ms64(ar, fst, mdl)
        call ms64(ar, mdl+1, lst)
        call merge64(ar, fst, mdl, lst)
    end subroutine

    subroutine merge64(ar, fst, mdl, lst)
        integer(int64),intent(inout):: ar(:)
        integer(int64),intent(in):: fst, mdl, lst
        integer(int64),allocatable:: tmp(:)
        integer(int64):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

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

    subroutine swap64(x,y)
        integer(int64),intent(inout):: x,y
        integer(int64):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine

    recursive subroutine msd3232(ar1, ar2, fst, lst)
        integer(int32),intent(inout):: ar1(:),ar2(:)
        integer(int32),intent(in):: fst,lst
        integer(int32):: mdl

        if (lst - fst < 2) then
            if (ar1(fst) > ar1(lst)) then
                call swap32(ar1(fst), ar1(lst))
                call swap32(ar2(fst), ar2(lst))
            end if
            return
        end if

        mdl = (fst+lst)/2

        call msd3232(ar1,ar2,fst,mdl)
        call msd3232(ar1,ar2,mdl+1,lst)
        call merged3232(ar1,ar2,fst,mdl,lst)
    end subroutine

    subroutine merged3232(ar1,ar2,fst,mdl,lst)
        integer(int32),intent(inout):: ar1(:),ar2(:)
        integer(int32),intent(in):: fst,mdl,lst
        integer(int32),allocatable:: t1(:),t2(:)
        integer(int32):: li,ri,ti

        allocate(t1(lst-fst+1), t2(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while(li <= mdl .and. ri <= lst)
            if (ar1(li) <= ar1(ri)) then
                t1(ti) = ar1(li)
                t2(ti) = ar2(li)
                li=li+1
            else
                t1(ti) = ar1(ri)
                t2(ti) = ar2(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            t1(ti:) = ar1(li:mdl)
            t2(ti:) = ar2(li:mdl)
        else
            t1(ti:) = ar1(ri:lst)
            t2(ti:) = ar2(ri:lst)
        end if

        ar1(fst:lst) = t1(:)
        ar2(fst:lst) = t2(:)

        deallocate(t1,t2)
    end subroutine

    recursive subroutine msd6464(ar1, ar2, fst, lst)
        integer(int64),intent(inout):: ar1(:),ar2(:)
        integer(int64),intent(in):: fst,lst
        integer(int64):: mdl

        if (lst - fst < 2) then
            if (ar1(fst) > ar1(lst)) then
                call swap64(ar1(fst), ar1(lst))
                call swap64(ar2(fst), ar2(lst))
            end if
            return
        end if

        mdl = (fst+lst)/2

        call msd6464(ar1,ar2,fst,mdl)
        call msd6464(ar1,ar2,mdl+1,lst)
        call merged6464(ar1,ar2,fst,mdl,lst)
    end subroutine

    subroutine merged6464(ar1,ar2,fst,mdl,lst)
        integer(int64),intent(inout):: ar1(:),ar2(:)
        integer(int64),intent(in):: fst,mdl,lst
        integer(int64),allocatable:: t1(:),t2(:)
        integer(int64):: li,ri,ti

        allocate(t1(lst-fst+1), t2(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while(li <= mdl .and. ri <= lst)
            if (ar1(li) <= ar1(ri)) then
                t1(ti) = ar1(li)
                t2(ti) = ar2(li)
                li=li+1
            else
                t1(ti) = ar1(ri)
                t2(ti) = ar2(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            t1(ti:) = ar1(li:mdl)
            t2(ti:) = ar2(li:mdl)
        else
            t1(ti:) = ar1(ri:lst)
            t2(ti:) = ar2(ri:lst)
        end if

        ar1(fst:lst) = t1(:)
        ar2(fst:lst) = t2(:)

        deallocate(t1,t2)
    end subroutine
end module

program agc011
    use,intrinsic :: iso_fortran_env
    use merge_sort_mod
    implicit none
    integer(int32):: n,i
    integer(int32),allocatable:: a(:), cnt(:)

    read*, n
    allocate(a(n))
    allocate(cnt(n), source=1)
    read*, a(:)

    call merge_sort(a,1,n)

    do i=1,n-1
        if (a(i)*2 >= a(i+1)) cnt(i+1) = cnt(i)+cnt(i+1)
        a(i+1)=a(i+1)+a(i)
    end do
    print'(i0)', cnt(n)
end program agc011

Score : 400 points

Problem Statement

Snuke found N strange creatures.
Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.

Every creature can absorb another creature whose size is at most twice the size of itself.
When a creature of size A and color B absorbs another creature of size C and color D (C \leq 2 \times A), they will merge into one creature of size A+C and color B.
Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other.

Snuke has been watching these creatures merge over and over and ultimately become one creature.
Find the number of the possible colors of this creature.

Constraints

2 \leq N \leq 100000

1 \leq A_i \leq 10^9

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 … A_N

Output

Print the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature.

Sample Input 1

3
3 1 4

Sample Output 1

2

The possible colors of the last remaining creature are colors 1 and 3.
For example, when the creature of color 3 absorbs the creature of color 2, then the creature of color 1 absorbs the creature of color 3, the color of the last remaining creature will be color 1.

Sample Input 2

5
1 1 1 1 1

Sample Output 2

5

There may be multiple creatures of the same size.

Sample Input 3

6
40 1 30 2 7 20

Sample Output 3

4


program main
implicit none
integer :: n

  read(*,*) n
  call wolv_or_sheep(n)

contains

  subroutine wolv_or_sheep(n)
  integer,intent(in) :: n
  character(n)       :: s
  logical            :: t(n),sw(n)
  integer            :: i

    read(*,'(A)') s
    t(:) = [(s(i:i)=='o',i=1,n)]

    call test_seq(n,t,.TRUE.,.TRUE.)
    call test_seq(n,t,.TRUE.,.FALSE.)
    call test_seq(n,t,.FALSE.,.TRUE.)
    call test_seq(n,t,.FALSE.,.FALSE.)

    print*,-1

  end subroutine wolv_or_sheep

  subroutine test_seq(n,t,a1,a2)
  integer,intent(in) :: n
  logical,intent(in) :: t(n),a1,a2
  logical            :: res(n),accept
  integer            :: i
!
    res(1) = a1
    res(2) = a2
!
    do i=2,n-1
      if(t(i).eqv.res(i))then
        res(i+1) = res(i-1)
      else
        res(i+1) = .not.res(i-1)
      endif
    enddo
!
    accept = res(n-1).eqv.res(1)

    if(res(n))then
      accept = accept.and.t(n).or..not.accept.and..not.t(n)
    else
      accept = .not.accept.and.t(n).or.accept.and..not.t(n)
    endif
!
    if(accept)then
      do i=1,n
        if(res(i))then
          write(*,'(A)',advance='NO') 'S'
        else
          write(*,'(A)',advance='NO') 'W'
        endif
      enddo
      write(*,'(A)') ''
      STOP
    endif
!
  end subroutine test_seq
!
end program main

Score : 500 points

Problem Statement

Snuke, who loves animals, built a zoo.

There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.

There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.

Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.

More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.

Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.

Constraints

3 ≤ N ≤ 10^{5}

s is a string of length N consisting of o and x.

Input

The input is given from Standard Input in the following format:

N
s

Output

If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.

t is a string of length N consisting of S and W.

If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

Sample Input 1

6
ooxoox

Sample Output 1

SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o.

Sample Input 2

3
oox

Sample Output 2

-1

Print -1 if there is no valid assignment of species.

Sample Input 3

10
oxooxoxoox

Sample Output 3

SSWWSSSWWS


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,m

    read*, n,m

    m=m-2*n
    print'(i0)', n+m/4
end program name

Score : 300 points

Problem Statement

Snuke loves puzzles.

Today, he is working on a puzzle using S- and c-shaped pieces.
In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below:

Snuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces.

Find the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.

Constraints

1 ≤ N,M ≤ 10^{12}

Input

The input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

1 6

Sample Output 1

2

Two Scc groups can be created as follows:

Combine two c-shaped pieces into one S-shaped piece

Create two Scc groups, each from one S-shaped piece and two c-shaped pieces

Sample Input 2

12345 678901

Sample Output 2

175897


integer a,b
read*, a, b
if(a == 1) a= 14

if(b == 1) b = 14

if(a > b) then
	print*, 'Alice'
else if(b > a) then
	print*, 'Bob'
else
	print*, 'Draw'
end if
end

Score : 100 points

Problem Statement

Alice and Bob are playing One Card Poker.

One Card Poker is a two-player game using playing cards.

Each card in this game shows an integer between 1 and 13, inclusive.

The strength of a card is determined by the number written on it, as follows:

Weak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong

One Card Poker is played as follows:

Each player picks one card from the deck. The chosen card becomes the player's hand.

The players reveal their hands to each other. The player with the stronger card wins the game.

If their cards are equally strong, the game is drawn.

You are watching Alice and Bob playing the game, and can see their hands.

The number written on Alice's card is A, and the number written on Bob's card is B.

Write a program to determine the outcome of the game.

Constraints

1≦A≦13

1≦B≦13

A and B are integers.

Input

The input is given from Standard Input in the following format:

A B

Output

Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.

Sample Input 1

8 6

Sample Output 1

Alice

8 is written on Alice's card, and 6 is written on Bob's card.
Alice has the stronger card, and thus the output should be Alice.

Sample Input 2

1 1

Sample Output 2

Draw

Since their cards have the same number, the game will be drawn.

Sample Input 3

13 1

Sample Output 3

Bob


program name

    implicit none
    integer A,B
    read*, A,B
    if ( A==1 .or. B==1 ) then
        if (A==B) then
            print*, "Draw"
        elseif (A>B) then
            print*, "Bob"
        else
            print*, "Alice"
        end if
    else
        if (A==B) then
            print*, "Draw"
        elseif (A>B) then
            print*, "Alice"
        else
            print*, "Bob"
        end if
    end if
end program


implicit none
integer (8):: a,b,c
character(1) :: s
read(*,*) a, b

if (a==1 ) then
    a=14
endif

if (b==1 ) then
    b=14
endif

if (a>b) then
    write(*,*) "Alice"
else if (b>a) then
    write(*,*) "Bob"
else
     write(*,*) "Draw"
endif

end


program ABC054B
    implicit none
    character(50)::s
    integer(8)::N,M,i,j,k,l,conv
    integer(8)::mask_sum=0
    integer(8)::flg=0
    integer(8),dimension(50,50)::img,mask
    read(5,*)N,M

    do i=1,N
        read(5,*)s
        do j=1,N
            if(s(j:j)==".")then
                img(j,i)=1
            else
                img(j,i)=0
            end if
        end do
    end do

    do i=1,M
        read(5,*)s
        do j=1,M
            if(s(j:j)==".")then
                mask(j,i)=1
                mask_sum=mask_sum+1
            else
                mask(j,i)=0
            end if
        end do
    end do

    do i=0,N-M
        do j=0,N-M
            conv=0
            do k=1,M
                do l=1,M
                    if(mask(l,k)==img(l+j,k+i))conv=conv+1
                end do
            end do
            if(conv==M*M)then
                flg=1
                exit
            end if
        end do
        if(flg==1)exit
    end do

    if(flg==1)then
        print'(A)',"Yes"
    else
        print'(A)',"No"
    end if
end program ABC054B

Score : 200 points

Problem Statement

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.

Constraints

1≦M≦N≦50

A_i is a string of length N consisting of # and ..

B_i is a string of length M consisting of # and ..

Input

The input is given from Standard Input in the following format:

N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

Sample Input 1

3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Sample Input 2

4 1
....
....
....
....
#

Sample Output 2

No

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.


program ABC054B
    implicit none
    character(50)::s
    integer(8)::N,M,i,j,k,l,conv
    integer(8)::mask_sum=0
    integer(8)::flg=0
    integer(8),dimension(50,50)::img,mask
    read(5,*)N,M

    do i=1,N
        read(5,*)s
        do j=1,N
            if(s(j:j)==".")then
                img(j,i)=1
            else
                img(j,i)=0
            end if
        end do
    end do

    do i=1,M
        read(5,*)s
        do j=1,M
            if(s(j:j)==".")then
                mask(j,i)=1
                mask_sum=mask_sum+1
            else
                mask(j,i)=0
            end if
        end do
    end do

    do i=1,N-M
        do j=1,N-M
            conv=0
            do k=1,M
                do l=1,M
                    if(mask(l,k)==img(l+j,k+i))conv=conv+1
                end do
            end do
            if(conv==M*M)then
                flg=1
                exit
            end if
        end do
        if(flg==1)exit
    end do

    if(flg==1)then
        print'(A)',"Yes"
    else
        print'(A)',"No"
    end if
end program ABC054B


integer N
integer,allocatable,dimension(:)::A
integer oddcnt,evencnt
read*,N
allocate(A(N))
read*,A

oddcnt=0
do i=1,N
  if(and(A(i),1)==1)oddcnt=oddcnt+1
end do
evencnt=N-oddcnt
print"(A)",merge("YES"," NO",mod(oddcnt,2)==0 .and. mod(evencnt+oddcnt/2,2)==0)
end

Score : 300 points

Problem Statement

There are N integers written on a blackboard. The i-th integer is A_i.

Takahashi will repeatedly perform the following operation on these numbers:

Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them.

Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j.

Determine whether it is possible to have only one integer on the blackboard.

Constraints

2 ≦ N ≦ 10^5

1 ≦ A_i ≦ 10^9

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 … A_N

Output

If it is possible to have only one integer on the blackboard, print YES. Otherwise, print NO.

Sample Input 1

3
1 2 3

Sample Output 1

YES

It is possible to have only one integer on the blackboard, as follows:

Erase 1 and 3 from the blackboard, then write 4. Now, there are two integers on the blackboard: 2 and 4.

Erase 2 and 4 from the blackboard, then write 6. Now, there is only one integer on the blackboard: 6.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

NO


Score : 100 points

Problem Statement

Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.

You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.

Constraints

1 ≦ x ≦ 3{,}000

x is an integer.

Input

The input is given from Standard Input in the following format:

x

Output

Print the answer.

Sample Input 1

1000

Sample Output 1

ABC

Smeke's current rating is less than 1200, thus the output should be ABC.

Sample Input 2

2000

Sample Output 2

ARC

Smeke's current rating is not less than 1200, thus the output should be ARC.


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: x,mx

    read*, x
    mx = mod(x,11_8)
    print'(i0)', 2*(x/11_8)+and(mx,1)+and(mx/6,1)
end program name

Score : 300 points

Problem Statement

Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.

Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:

Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.

For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure.
If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward.
Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.

Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.

Constraints

1 ≦ x ≦ 10^{15}

x is an integer.

Input

The input is given from Standard Input in the following format:

x

Output

Print the answer.

Sample Input 1

7

Sample Output 1

2

Sample Input 2

149696127901

Sample Output 2

27217477801


program ARC068C
    implicit none
    integer(8)::x
    integer(8)::result=0
    read(5,*)x

    result=x/11
    result=result*2

    if(mod(x,11)>=7)then
        result=result+2
    else
        result=result+1
    end if

    print'(i0)',result

end program ARC068C


program sample
    implicit none
    character(100)::s
    character(3)::ans
    integer(8) :: i,j,m,n,max
    integer(8),allocatable :: x(:),y(:)

    read(*,*)n
    read(*,*)s
    m=0
    max=0
    do i=1,n
        if(s(i:i) .eq. 'I')then
            m=m+1
            if(m>max)then
                max=m
            end if
        else
            m=m-1
        endif
    end do

    write(*,*)max
    stop
end program sample

Score : 200 points

Problem Statement

You have an integer variable x.
Initially, x=0.

Some person gave you a string S of length N, and using the string you performed the following operation N times.
In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.

Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Constraints

1≤N≤100

|S|=N

No characters except I and D occur in S.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the maximum value taken by x during the operations.

Sample Input 1

5
IIDID

Sample Output 1

2

After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.

Sample Input 2

7
DDIDDII

Sample Output 2

0

The initial value x=0 is the maximum value taken by x, thus the output should be 0.


program prob2
    implicit none
    character(105) :: s
    integer :: n, i, ans, anss
    read(*,*) n, s
    ans = 0
    anss = 0
    do i = 1, n
        if(s(i:i) == 'I')then
            ans = ans + 1
        else
            ans = ans - 1
        end if
        anss = max(anss, ans)
    end do
    write(*,*) anss

    stop
contains
end program prob2


program main
implicit none
integer :: i, j, k
integer :: n
character :: s*100

read(*,*) n
read(*,*) s(1:n)
j = 0
k = 0
do i = 1, n
   if( s(i:i) == 'I' ) then
      j = j + 1
   else
      j = j - 1
   end if
   if( j .ge. k ) then
      k = j
   end if
end do
write(*,'(i0)') k

end program main


program AGC008A
    implicit none
    integer(8)::x,y
    integer(8)::result=0
    read(5,*)x,y

    result=result+abs(abs(x)-abs(y))

    if(x*y>=0 .and. x>y)then
        result=result+2
    else if(x*y<0)then
        result=result+1
    end if

    print'(i0)',result

end program AGC008A

Score : 300 points

Problem Statement

Snuke has a calculator. It has a display and two buttons.

Initially, the display shows an integer x.
Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order:

Button A: When pressed, the value on the display is incremented by 1.

Button B: When pressed, the sign of the value on the display is reversed.

Find the minimum number of times Snuke needs to press the buttons to achieve his objective.
It can be shown that the objective is always achievable regardless of the values of the integers x and y.

Constraints

x and y are integers.

|x|, |y| ≤ 10^9

x and y are different.

Input

The input is given from Standard Input in the following format:

x y

Output

Print the minimum number of times Snuke needs to press the buttons to achieve his objective.

Sample Input 1

10 20

Sample Output 1

10

Press button A ten times.

Sample Input 2

10 -10

Sample Output 2

1

Press button B once.

Sample Input 3

-10 -20

Sample Output 3

12

Press the buttons as follows:

Press button B once.

Press button A ten times.

Press button B once.


program AGC008A
    implicit none
    integer(8)::x,y
    integer(8)::result=0
    read(5,*)x,y

    result=result+abs(abs(x)-abs(y))

    if(x*y>0 .and. x>y)then
        if(x>0)then
            result=result+2
        else
            result=result+1
        end if
    else if(x*y<0)then
        result=result+1
    end if

    print'(i0)',result

end program AGC008A


program main
character(1) a
read*,i,a,j
if(a=='-')then
print*,i-j
else
print*,i+j
endif
end program main

Score : 100 points

Problem Statement

Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.

Constraints

1≦A,B≦10^9

op is either + or -.

Input

The input is given from Standard Input in the following format:

A op B

Output

Evaluate the formula and print the result.

Sample Input 1

1 + 2

Sample Output 1

3

Since 1 + 2 = 3, the output should be 3.

Sample Input 2

5 - 7

Sample Output 2

-2


program ABC050B
    implicit none
    integer(8)::N,P,X,i,M,result
    integer(8),dimension(100)::T
    read(5,*)N,(T(i),i=1,N),M
    result=sum(T(1:N))

    do i=1,M
        read(5,*)P,X
        print'(i0)',result+X-T(P)
    end do
end program ABC050B

Score : 200 points

Problem Statement

Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are N problems, numbered 1 through N.
Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).

Also, there are M kinds of drinks offered to the contestants, numbered 1 through M.
If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.
It does not affect the time to solve the other problems.

A contestant is allowed to take exactly one of the drinks before the start of the contest.
For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.
Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.
Your task is to write a program to calculate it instead of her.

Constraints

All input values are integers.

1≦N≦100

1≦T_i≦10^5

1≦M≦100

1≦P_i≦N

1≦X_i≦10^5

Input

The input is given from Standard Input in the following format:

N
T_1 T_2 ... T_N
M
P_1 X_1
P_2 X_2
:
P_M X_M

Output

For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.

Sample Input 1

3
2 1 4
2
1 1
2 3

Sample Output 1

6
9

If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.

If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.

Sample Input 2

5
7 2 3 8 5
3
4 2
1 7
4 13

Sample Output 2

19
25
30


PROGRAM ATCODER

implicit none
integer(16) :: n,i
integer(16),allocatable :: a(:)

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

call hs(n,a)

do i = n-1, 0, -2
  if ( i == 0 ) then
    if ( a(1) /= 0 ) stop
    exit
  end if
  if ( 2*i /= a(i)+a(i+1) ) then
    print'(i0)', 0
    stop
  end if
end do

print'(i0)', mod(2**(n/2),1000000007)

contains
!!!!!! サブルーチンは↓
subroutine hs(n,array)
  implicit none
  integer(16),intent(in)::n
  integer(16),intent(inout)::array(1:n)

  integer(16)::i,k,j,l,m
  integer(16)::t

  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(l)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine hs
!!!!!!

END PROGRAM ATCODER

Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

Any order would be inconsistent with the reports, thus the answer is 0.

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16


program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,h,w
    integer(8)::a,b,c,d
    character(10000),allocatable::x(:),y(:)

    read(*,*) h,w
    allocate(x(h),y(2*h))
    do i=1,h
        read(*,*)s
        write(*,*)s
        write(*,*)s
        !y(i*2-1)=x(i)
        !y(i*2)=x(i)
    end do

    stop
end program sample


integer H,W
character(150),allocatable,dimension(:)::C
read*,H,W
allocate(C(H))
read*,C
do i=1,H
	print"(A)",trim(C(i))
    print"(A)",trim(C(i))
enddo
end


integer(16) a,b,x
read*,a,b,x
print"(i0)",b/x-a/x+merge(1,0,mod(a,x)==0)
end

Score : 200 points

Problem Statement

You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?

Constraints

0 ≤ a ≤ b ≤ 10^{18}

1 ≤ x ≤ 10^{18}

Input

The input is given from Standard Input in the following format:

a b x

Output

Print the number of the integers between a and b, inclusive, that are divisible by x.

Sample Input 1

4 8 2

Sample Output 1

3

There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.

Sample Input 2

0 5 1

Sample Output 2

6

There are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.

Sample Input 3

9 9 2

Sample Output 3

0

There are no integer between 9 and 9, inclusive, that is divisible by 2.

Sample Input 4

1 1000000000000000000 3

Sample Output 4

333333333333333333

Watch out for integer overflows.


program struck_out
  implicit none
  integer :: n, m, k, i, j, l
  integer(8) :: a(100000), dp(0:100000,300)
  a = 0_8
  dp = 0_8
  read(*,*) n, m, k
  read(*,*) a(1:n)
  do i = 1, n
    dp(i,1) = a(i)
    do j = 2, k
      l = max(0,i-m)
      dp(i,j) = int(j,8)*a(i)+maxval(dp(l:i-1,j-1))
    end do
  end do
  write(*,'(i0)') maxval(dp(1:n,k))
  stop
end program struck_out

Score : 700 points

Problem Statement

There are N panels arranged in a row in Takahashi's house, numbered 1 through N. The i-th panel has a number A_i written on it. Takahashi is playing by throwing balls at these panels.

Takahashi threw a ball K times. Let the panel hit by a boll in the i-th throw be panel p_i. He set the score for the i-th throw as i \times A_{p_i}.

He was about to calculate the total score for his throws, when he realized that he forgot the panels hit by balls, p_1,p_2,...,p_K. The only fact he remembers is that for every i (1 ≦ i ≦ K-1), 1 ≦ p_{i+1}-p_i ≦ M holds. Based on this fact, find the maximum possible total score for his throws.

Constraints

1 ≦ M ≦ N ≦ 100,000

1 ≦ K ≦ min(300,N)

1 ≦ A_i ≦ 10^{9}

Partial Scores

In the test set worth 100 points, M = N.

In the test set worth another 200 points, N ≦ 300 and K ≦ 30.

In the test set worth another 300 points, K ≦ 30.

Input

The input is given from Standard Input in the following format:

N M K
A_1 A_2 … A_N

Output

Print the maximum possible total score for Takahashi's throws.

Sample Input 1

5 2 3
10 2 8 10 2

Sample Output 1

56

The total score is maximized when panels 1,3 and 4 are hit, in this order.

Sample Input 2

5 5 2
5 2 10 5 9

Sample Output 2

28

This case satisfies the additional constraint M = N for a partial score.

Sample Input 3

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

Sample Output 3

5000000078


Score : 100 points

Problem Statement

Two students of AtCoder Kindergarten are fighting over candy packs.

There are three candy packs, each of which contains a, b, and c candies, respectively.

Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.

Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Constraints

1 ≦ a, b, c ≦ 100

Input

The input is given from Standard Input in the following format:

a b c

Output

If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

Sample Input 1

10 30 20

Sample Output 1

Yes

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.

Sample Input 2

30 30 100

Sample Output 2

No

In this case, the student who gets the pack with 100 candies always has more candies than the other.

Note that every pack must be given to one of them.

Sample Input 3

56 25 31

Sample Output 3

Yes


      PROGRAM piyo
      IMPLICIT NONE
      integer :: w,h,n
      integer,allocatable :: x(:),y(:),a(:)
      integer :: i
      logical,allocatable :: rect(:,:)

      read*,w,h,n
      allocate( x(n),y(n),a(n) )
      do i = 1,n
        read*,x(i),y(i),a(i)
      end do

      allocate( rect(1:w,1:h) )
      rect = .true.

      do i = 1,n
        select case( a(i) )
          case( 1 )
            rect(1:x(i),:) = .false.
          case( 2 )
            rect(x(i)+1:w,:) = .false.
          case( 3 )
            rect(:,1:y(i)) = .false.
          case( 4 )
            rect(:,y(i)+1:h) = .false.
        end select
      end do

      print*,count( rect )

      END PROGRAM

Score : 200 points

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

If a_i = 1, he painted the region satisfying x < x_i within the rectangle.

If a_i = 2, he painted the region satisfying x > x_i within the rectangle.

If a_i = 3, he painted the region satisfying y < y_i within the rectangle.

If a_i = 4, he painted the region satisfying y > y_i within the rectangle.

Find the area of the white region within the rectangle after he finished painting.

Constraints

1 ≦ W, H ≦ 100

1 ≦ N ≦ 100

0 ≦ x_i ≦ W (1 ≦ i ≦ N)

0 ≦ y_i ≦ H (1 ≦ i ≦ N)

W, H (21:32, added), x_i and y_i are integers.

a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

Input

The input is given from Standard Input in the following format:

W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

Output

Print the area of the white region within the rectangle after Snuke finished painting.

Sample Input 1

5 4 2
2 1 1
3 3 4

Sample Output 1

9

The figure below shows the rectangle before Snuke starts painting.

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

Now, the area of the white region within the rectangle is 9.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n, edge(4)
    integer(int32):: x,y,a,i

    edge(:) = 0
    read*, edge(2), edge(4), n

    do i = 1, n
        read*, x,y,a
        select case (a)
            case(1)
                edge(1) = max(edge(1),x)
            case(2)
                edge(2) = min(edge(2),x)
            case(3)
                edge(3) = max(edge(3),y)
            case(4)
                edge(4) = min(edge(4),y)
        end select
    end do

    if (edge(2) >= edge(1) .and. edge(4) >= edge(3)) then
        print'(i0)', (edge(2)-edge(1))*(edge(4)-edge(3))
    else
        print'(i0)', 0
    end if
end program name


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,overlap
    character(:),allocatable:: s,t

    read*, n
    allocate(character(n):: s,t)
    read*, s
    read*, t

    overlap=0
    do i=n-1,0,-1
        if (s(n-i:n) == t(1:1+i)) then
            print'(i0)', 2*n-(i+1)
            stop
        end if
    end do
    print'(i0)', 2*n
end program name

Score : 200 points

Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.

The first N characters equal to the string s.

The last N characters equal to the string t.

Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100

The lengths of s and t are both N.

s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5

The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2

The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4

The shortest string is expr.


program	main
  implicit none
  integer n,x,i
  read*,n,x
  if(x<n) then
     print*,'No'
  else
     print*,'Yes'
     print'(i0)',(/(i,i=n-x+1,n+x-1)/)
  end if
end program main

Score : 400 points

Problem Statement

We have a pyramid with N steps, built with blocks.
The steps are numbered 1 through N from top to bottom.
For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.
The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with N=4 steps

Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:

The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks

Afterwards, he erased all integers written into the blocks.
Now, he only remembers that the integer written into the block of step 1 was x.

Construct a permutation of (1, 2, ..., 2N-1) that could have been written into the blocks of step N, or declare that Snuke's memory is incorrect and such a permutation does not exist.

Constraints

2≤N≤10^5

1≤x≤2N-1

Input

The input is given from Standard Input in the following format:

N x

Output

If no permutation of (1, 2, ..., 2N-1) could have been written into the blocks of step N, print No.

Otherwise, print Yes in the first line, then print 2N-1 lines in addition.

The i-th of these 2N-1 lines should contain the i-th element of a possible permutation.

Sample Input 1

4 4

Sample Output 1

Yes
1
6
3
7
4
5
2

This case corresponds to the figure in the problem statement.

Sample Input 2

2 1

Sample Output 2

No

No matter what permutation was written into the blocks of step N, the integer written into the block of step 1 would be 2.


program sample
    implicit none

    integer(8) :: i,j,m,n,k,t
    integer(8),allocatable :: x(:),y(:)

    read(*,*) k,t
    allocate(x(t))
    read(*,*)x
    m=maxval(x)
    n=sum(x)-m
    if (m-n-1<0)then
        write(*,*)0
    else
    write(*,*) m-n-1
    end if

    stop
end program sample

Score : 200 points

Problem Statement

There are K pieces of cakes.
Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.

There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.

Eating the same type of cake two days in a row would be no fun,
so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.

Compute the minimum number of days on which the same type of cake as the previous day will be eaten.

Constraints

1 ≤ K ≤ 10000

1 ≤ T ≤ 100

1 ≤ a_i ≤ 100

a_1 + a_2 + ... + a_T = K

Input

The input is given from Standard Input in the following format:

K T
a_1 a_2 ... a_T

Output

Print the minimum number of days on which the same type of cake as the previous day will be eaten.

Sample Input 1

7 3
3 2 2

Sample Output 1

0

For example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1, he can avoid eating the same type of cake as the previous day.

Sample Input 2

6 3
1 4 1

Sample Output 2

1

There are 6 cakes.
For example, if Mr. Takahashi eats cakes in the order of 2, 3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the previous day only on the fourth day.
Since this is the minimum number, the answer is 1.

Sample Input 3

100 1
100

Sample Output 3

99

Since Mr. Takahashi has only one type of cake, he has no choice but to eat the same type of cake as the previous day from the second day and after.


Score : 100 points

Problem Statement

AtCoDeer the deer recently bought three paint cans.
The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.
Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.

Since he is forgetful, he might have bought more than one paint can in the same color.
Count the number of different kinds of colors of these paint cans and tell him.

Constraints

1≦a,b,c≦100

Input

The input is given from Standard Input in the following format:

a b c

Output

Print the number of different kinds of colors of the paint cans.

Sample Input 1

3 1 4

Sample Output 1

3

Three different colors: 1, 3, and 4.

Sample Input 2

3 3 33

Sample Output 2

2

Two different colors: 3 and 33.


program main
  implicit none
  integer(8) :: n, k
  read (*, *) n, k
  write (*, "(i0)") k * (k - 1) ** (n - 1)
end program main

Score : 200 points

Problem Statement

There are N balls placed in a row.
AtCoDeer the deer is painting each of these in one of the K colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.

Find the number of the possible ways to paint the balls.

Constraints

1≦N≦1000

2≦K≦1000

The correct answer is at most 2^{31}-1.

Input

The input is given from Standard Input in the following format:

N K

Output

Print the number of the possible ways to paint the balls.

Sample Input 1

2 2

Sample Output 1

2

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

Sample Input 2

1 10

Sample Output 2

10

Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.


integer N,K,answer
read*,N,K
answer=K
do i=2,N
	answer =answer*(k-1)
end do
print"(I0)",answer
end


integer cnt
character(16) mihon,S
mihon="CODEFESTIVAL2016"
read*,S
cnt=0
do i=1,16
  if(mihon(i:i)/=S(i:i))cnt=cnt+1
end do
print"(i0)",cnt
end

Score : 100 points

Problem Statement

CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.

He intended to write CODEFESTIVAL2016 on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.

So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to CODEFESTIVAL2016.

Find the minimum number of iterations for the rewrite operation.

Constraints

S is 16 characters long.

S consists of uppercase and lowercase alphabet letters and numerals.

Input

Inputs are provided from Standard Input in the following form.

S

Output

Output an integer representing the minimum number of iterations needed for the rewrite operation.

Sample Input 1

C0DEFESTIVAL2O16

Sample Output 1

2

The second character 0 must be changed to O and the 14th character O changed to 0.

Sample Input 2

FESTIVAL2016CODE

Sample Output 2

16


program sample
    implicit none
    real(8)::z
    integer(8) :: a,b,c,i,j,m,n,k,x,y
    character::s !文字列

    read(*,*)n,a,b

    read(*,*)s
    x=0
    y=0
    k=len_trim(s)
    do i=1,k
        if (s(i:i)=='a')then
            if (x+y<a+b)then
                x=x+1
                write(*,*)'Yes'
            else
                write(*,*)'No'
            end if
        else if (s(i:i)=='b')then
            if (x+y<a+b)then
                if (y<b)then
                    y=y+1
                    write(*,*)'Yes'
                else
                    write(*,*)'No'
                end if
            else
                write(*,*)'No'
            end if

        else
            write(*,*)'No'
        end if

    end do

    stop
end program sample

Score : 200 points

Problem Statement

There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.

Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.

A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.

An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.

A string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.

Write a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.

Constraints

1≦N,A,B≦100000

A+B≦N

S is N characters long.

S consists only of the letters a, b and c.

Input

Inputs are provided from Standard Input in the following form.

N A B
S

Output

Output N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.

Sample Input 1

10 2 3
abccabaabb

Sample Output 1

Yes
Yes
No
No
Yes
Yes
Yes
No
No
No

The first, second, fifth, sixth, and seventh participants pass the Qualification contests.

Sample Input 2

12 5 2
cabbabaacaba

Sample Output 2

No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No

The sixth participant is third among overseas students and thus does not pass the Qualification contests.

Sample Input 3

5 2 2
ccccc

Sample Output 3

No
No
No
No
No


program sample
    implicit none
    real(8)::z
    integer(8) :: a,b,c,i,j,m,n,k,x,y
    character(1),allocatable ::s(:) !文字列

    read(*,*)n,a,b
    allocate(s(n))
    read(*,*)s
    x=0
    y=0

    do i=1,n
        if (s(i)=='a')then
            if (x+y<a+b)then
                x=x+1
                write(*,*)'Yes'
            else
                write(*,*)'No'
            end if
        else if (s(i)=='b')then
            if (x+y<a+b)then
                if (y<b)then
                    y=y+1
                    write(*,*)'Yes'
                end if
            else
                write(*,*)'No'
            end if

        else
            write(*,*)'No'
        end if

    end do
    deallocate(s)
    stop
end program sample


program sample
    implicit none
    real(8)::x,y,z
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    character(1),allocatable ::s(:) !文字列

    read(*,*)n,a,b
    allocate(s(n))
    read(*,*)s
    a1=0
    b1=0

    do i=1,n
        if (s(i)=='a')then
            if (a1+b1<a+b)then
                a1=a1+1
                write(*,*)'Yes'
            else
                write(*,*)'No'
            end if
        else if (s(i)=='b')then
            if (a1+b1<a+b)then
                if (b1<b)then
                    b1=b1+1
                    write(*,*)'Yes'
                end if
            else
                write(*,*)'No'
            end if

        else
            write(*,*)'No'
        end if

    end do
    deallocate(s)
    stop
end program sample


implicit none
integer(8) :: a,b,c,d
character(12) :: s
read(*,*) s
write(*,*) s(1:4)//" "//s(5:12)

!if ( len_trim(s)>=a .and. len_trim(s)<=b ) then
!    write(*,*)  "YES"
!else
!    write(*,*) "NO"
!endif

end

Score : 100 points

Problem Statement

This contest is CODE FESTIVAL.
However, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.

So he has decided to make a program that puts the single space he omitted.

You are given a string s with 12 letters.
Output the string putting a single space between the first 4 letters and last 8 letters in the string s.

Constraints

s contains exactly 12 letters.

All letters in s are uppercase English letters.

Input

The input is given from Standard Input in the following format:

s

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s.
Put a line break at the end.

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE FESTIVAL

Putting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.

Sample Input 2

POSTGRADUATE

Sample Output 2

POST GRADUATE

Sample Input 3

ABCDEFGHIJKL

Sample Output 3

ABCD EFGHIJKL


program codefestival_2016_qualA_c
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100000):: s
    integer(int32):: k,n,i,cost,nind

    read*, s
    n = len_trim(s)
    read*, k

    do i=1,n
        cost = 1+ichar('z') - ichar(s(i:i))
        if (cost <= k) then
            s(i:i) = 'a'
            k=k-cost
        end if
    end do
    nind = (ichar(s(n:n)) - ichar('a'))

    s(n:n) = char(mod(nind+k, ichar('z')-ichar('a')+1) + ichar('a'))

    print'(a)', trim(s)
end program codefestival_2016_qualA_c

Score : 400 points

Problem Statement

Mr. Takahashi has a string s consisting of lowercase English letters.
He repeats the following operation on s exactly K times.

Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of z is a.

For example, if you perform an operation for the second letter on aaz, aaz becomes abz.
If you then perform an operation for the third letter on abz, abz becomes aba.

Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s.
Find the such string.

Constraints

1≤|s|≤10^5

All letters in s are lowercase English letters.

1≤K≤10^9

Input

The input is given from Standard Input in the following format:

s
K

Output

Print the lexicographically smallest string after performing exactly K operations on s.

Sample Input 1

xyz
4

Sample Output 1

aya

For example, you can perform the following operations: xyz, yyz, zyz, ayz, aya.

Sample Input 2

a
25

Sample Output 2

z

You have to perform exactly K operations.

Sample Input 3

codefestival
100

Sample Output 3

aaaafeaaivap


program main
	implicit none
    integer::a,b,c
    read(*,*)a
    read(*,*)b
    read(*,*)c
    write(*,*) (a+b)*c/2
    stop
end program main

Score : 100 points

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints

1≦a≦100

1≦b≦100

1≦h≦100

All input values are integers.

h is even.

Input

The input is given from Standard Input in the following format:

a
b
h

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

Sample Input 1

3
4
2

Sample Output 1

7

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

Sample Input 2

4
4
4

Sample Output 2

16

In this case, a parallelogram is given, which is also a trapezoid.


program ManyFormulas

implicit none
integer :: I, J
integer(8) :: len, co, checker, K
character(10) :: S
integer(8), dimension(512) :: num, counter

read(*,*) S
len = len_trim(S)

do I = 1, 512
num(I) = 0
end do

do I = 1, 2**(len-1)
 do J = 1, 512
 counter(J) = 0
 end do
 counter(len) = len
 do J = 1, len-1
  if (btest(I-1,J-1)) then
  counter(J) = J
  end if
 end do
!write(*,*) (counter(J),J=1,3)
checker = 1
 do J = 1, len
  if (counter(J)/=0) then
  read(S(checker:counter(J)),*) K
!  write(*,*) K
  num(I) = num(I) + K
  checker = counter(J) + 1
  end if
 end do
end do

write(*,*) sum(num)

end program

Score : 300 points

Problem Statement

You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.

All strings that can be obtained in this way can be evaluated as formulas.

Evaluate all possible formulas, and print the sum of the results.

Constraints

1 \leq |S| \leq 10

All letters in S are digits between 1 and 9, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the sum of the evaluated value over all possible formulas.

Sample Input 1

125

Sample Output 1

176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125

1+25=26

12+5=17

1+2+5=8

Thus, the sum is 125+26+17+8=176.

Sample Input 2

9999999999

Sample Output 2

12656242944


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

  read(*,*) A, B, C

  if (mod(A,2) == 0 .or. mod(B,2) == 0 .or. mod(C,2) == 0) then
     write(*,*) 0
  else
     write(*,*) min(A*B, B*C, C*A)
  end if
  stop
end program cuboid

Score : 200 points

Problem Statement

We have a rectangular parallelepiped of size A×B×C, built with blocks of size 1×1×1. Snuke will paint each of the A×B×C blocks either red or blue, so that:

There is at least one red block and at least one blue block.

The union of all red blocks forms a rectangular parallelepiped.

The union of all blue blocks forms a rectangular parallelepiped.

Snuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference.

Constraints

2≤A,B,C≤10^9

Input

The input is given from Standard Input in the following format:

A B C

Output

Print the minimum possible difference between the number of red blocks and the number of blue blocks.

Sample Input 1

3 3 3

Sample Output 1

9

For example, Snuke can paint the blocks as shown in the diagram below.
There are 9 red blocks and 18 blue blocks, thus the difference is 9.

Sample Input 2

2 2 4

Sample Output 2

0

For example, Snuke can paint the blocks as shown in the diagram below.
There are 8 red blocks and 8 blue blocks, thus the difference is 0.

Sample Input 3

5 3 5

Sample Output 3

15

For example, Snuke can paint the blocks as shown in the diagram below.
There are 45 red blocks and 30 blue blocks, thus the difference is 9.


program beautiful
implicit none
character(len=100) :: s
integer :: i, c(26), j

read(*,*) s
c = 0
do i = 1, len_trim(s)
j = ichar(s(i:i))-ichar('a') + 1
c(j) = c(j) + 1
end do
do i = 1, 26
if (mod(c(i),2) == 1 ) then
write(*,'(a)') 'No'
stop
end if
end do
write(*,'(a)') 'Yes'
stop
end program beautiful

Score : 200 points

Problem Statement

Let w be a string consisting of lowercase letters.
We will call w beautiful if the following condition is satisfied:

Each lowercase letter of the English alphabet occurs even number of times in w.

You are given the string w. Determine if w is beautiful.

Constraints

1 \leq |w| \leq 100

w consists of lowercase letters (a-z).

Input

The input is given from Standard Input in the following format:

w

Output

Print Yes if w is beautiful. Print No otherwise.

Sample Input 1

abaccaba

Sample Output 1

Yes

a occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.

Sample Input 2

hthth

Sample Output 2

No


program ABC044B
    implicit none
    integer(8)::i,flg
    character(100)::w
    integer(8),dimension(26)::C
    read(5,*)w
    flg=0
    C=0
    do i=1,len_trim(w)
        C(ichar(w(i:i))-96)=C(ichar(w(i:i))-96)+1
    end do

    do i=1,26
        if(mod(C(i),2)==1)then
            flg=1
            exit
        end if
    end do

    if(flg==0)print'(A)',"Yes"
    if(flg==1)print'(A)',"No"
end program ABC044B


program main
  implicit none
  integer(8) :: n, s, sqrt_n, b, p
  read(*, *) n
  read(*, *) s

  if (n < s) then
    write(*, "(i0)") -1
    stop 0
  else if (n == s) then
    write(*, "(i0)") n + 1
    stop 0
  end if

  sqrt_n = integer_sqrt(n)

  do b = 2, sqrt_n
    if (f(b, n) == s) then
      write(*, "(i0)") b
      stop 0
    end if
  end do

  do p = 1, sqrt_n
    b = (n - s) / p + 1
    if (b >= 2) then
      if (f(b, n) == s) then
        write(*, "(i0)") b
        stop 0
      end if
    end if
  end do

  write(*, "(i0)") -1

  contains

  function integer_sqrt(n)
    implicit none
    integer(8), intent(in) :: n
    integer(8) :: integer_sqrt, i
    if (n < 0) stop 101
    do i = 0, n + 1
      if (i ** 2 > n) then
        integer_sqrt = i - 1
        exit
      end if
    end do
  end function integer_sqrt

  recursive function f(b, n) result(res)
    implicit none
    integer(8), intent(in) :: b, n
    integer(8) :: res
    if (n < b) then
      res = n
    else
      res = f(b, n / b) + mod(n, b)
    end if
  end function f
end program main

Score : 500 points

Problem Statement

For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows:

f(b,n) = n, when n < b

f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b

Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b,
and n \ {\rm mod} \ b denotes the remainder of n divided by b.

Less formally, f(b,n) is equal to the sum of the digits of n written in base b.
For example, the following hold:

f(10,\,87654)=8+7+6+5+4=30

f(100,\,87654)=8+76+54=138

You are given integers n and s.
Determine if there exists an integer b (b \geq 2) such that f(b,n)=s.
If the answer is positive, also find the smallest such b.

Constraints

1 \leq n \leq 10^{11}

1 \leq s \leq 10^{11}

n,\,s are integers.

Input

The input is given from Standard Input in the following format:

n
s

Output

If there exists an integer b (b \geq 2) such that f(b,n)=s, print the smallest such b.
If such b does not exist, print -1 instead.

Sample Input 1

87654
30

Sample Output 1

10

Sample Input 2

87654
138

Sample Output 2

100

Sample Input 3

87654
45678

Sample Output 3

-1

Sample Input 4

31415926535
1

Sample Output 4

31415926535

Sample Input 5

1
31415926535

Sample Output 5

-1


program sequential_operations_on_sequence
  implicit none
  integer :: n, q, i, j, x, u = 1, l, r, m
  integer(8) :: p(100000) = 0_8, k, t(100000) = 0_8, ans(100001) = 0_8
  read(*,*) n, q
  p(1) = int(n,8)
  do i = 1, q
    u = u+1
    read(*,*) p(u)
    do while (u > 1 .and. p(u-1) >= p(u))
      p(u-1) = p(u)
      u = u-1
    end do
  end do
  t(u) = 1_8
  do i = u, 1, -1
    j = i
    k = p(i)
    do
      r = j
      l = 0
      do while (r-l > 1)
        m = (l+r)/2
        if (p(m) > k) then
          r = m
        else
          l = m
        end if
      end do
      if (l == 0) then
        x = int(k,4)
        ans(1) = ans(1)+t(i)
        ans(x+1) = ans(x+1)-t(i)
        exit
      else
        j = l
        t(j) = t(j)+t(i)*(k/p(j))
        k = mod(k,p(j))
      end if
    end do
  end do
  write(*,'(i0)') ans(1)
  do i = 2, n
    ans(i) = ans(i)+ans(i-1)
    write(*,'(i0)') ans(i)
  end do
end program sequential_operations_on_sequence

Score : 1400 points

Problem Statement

Snuke got an integer sequence from his mother, as a birthday present. The sequence has N elements, and the i-th of them is i.
Snuke performs the following Q operations on this sequence. The i-th operation, described by a parameter q_i, is as follows:

Take the first q_i elements from the sequence obtained by concatenating infinitely many copy of the current sequence, then replace the current sequence with those q_i elements.

After these Q operations, find how many times each of the integers 1 through N appears in the final sequence.

Constraints

1 ≦ N ≦ 10^5

0 ≦ Q ≦ 10^5

1 ≦ q_i ≦ 10^{18}

All input values are integers.

Input

The input is given from Standard Input in the following format:

N Q
q_1
:
q_Q

Output

Print N lines. The i-th line (1 ≦ i ≦ N) should contain the number of times integer i appears in the final sequence after the Q operations.

Sample Input 1

5 3
6
4
11

Sample Output 1

3
3
3
2
0

After the first operation, the sequence becomes: 1,2,3,4,5,1.

After the second operation, the sequence becomes: 1,2,3,4.

After the third operation, the sequence becomes: 1,2,3,4,1,2,3,4,1,2,3.

In this sequence, integers 1,2,3,4,5 appear 3,3,3,2,0 times, respectively.

Sample Input 2

10 10
9
13
18
8
10
10
9
19
22
27

Sample Output 2

7
4
4
3
3
2
2
2
0
0


integer N
integer,allocatable,dimension(:)::a
integer ans,kouho
read*,N
allocate(a(N))
read*,a
ans=huge(ans)
do i=minval(a),maxval(a)
  kouho=0
  do j=1,N
    kouho=kouho+(i-a(j))**2
  end do
  ans=min(ans,kouho)
end do
print"(i0)",ans
end

Score : 200 points

Problem Statement

Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.

He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).

Find the minimum total cost to achieve his objective.

Constraints

1≦N≦100

-100≦a_i≦100

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum total cost to achieve Evi's objective.

Sample Input 1

2
4 8

Sample Output 1

8

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

Sample Input 2

3
1 1 3

Sample Output 2

3

Transforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note that Evi has to pay (1-2)^2 dollar separately for transforming each of the two 1s.

Sample Input 3

3
4 2 5

Sample Output 3

5

Leaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve the total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.

Sample Input 4

4
-100 -100 -100 -100

Sample Output 4

0

Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is 0.


program main
  implicit none
  integer(8) :: n, i, to, res, mi
  integer(8), allocatable :: a(:)
  read(*, *) n
  allocate(a(n))
  read(*, *) (a(i), i = 1, n)

  mi = huge(0_8)
  do to = -100, 100
    res = 0
    do i = 1, n
      res = res + (a(i) - to) ** 2
    end do
    mi = min(mi, res)
  end do

  write(*, "(i0)") mi

  deallocate(a)
  contains
end


program	main
  implicit none
  integer(2)::n,i
  integer,allocatable::a(:)
  read*,n
  allocate(a(n))
  read*,a
  print*,minval((/(dot_product(a+i,a+i),i=-100,100)/))
end program main


program iroha_easy
    implicit none
    integer a, b, c
    read *, a, b, c
    if(a .eq. 5 .and. b .eq. 5 .and. c .eq. 7)then
        print *, 'YES'
    else if(a .eq. 5 .and. b .eq. 7 .and. c .eq. 5)then
        print *, 'YES'
    else if(a .eq. 7 .and. b .eq. 5 .and. c .eq. 5)then
        print *, 'YES'
    else
        print *, 'NO'
    end if
end program

Score : 100 points

Problem Statement

Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

Constraints

1≦A,B,C≦10

Input

The input is given from Standard Input in the following format:

A B C

Output

If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.

Sample Input 1

5 5 7

Sample Output 1

YES

Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.

Sample Input 2

7 7 5

Sample Output 2

NO


program main
implicit none
integer :: a, b, c

read(*,*) a, b, c
if( a==5 ) then
   if( b== 5 ) then
      if( c == 7 ) then
         write(*,*) 'YES'
         stop
      end if
   else if( b == 7 ) then
      if ( c== 5 ) then
         write(*,*) 'YES'
         stop
      end if
   end if
else if( a== 7 ) then
   if( b==5.and.c==5 ) then
      write(*,*) 'YES'
      stop
   end if
end if
write(*,*) 'NO'

end program main


PROGRAM ATCODER

implicit none
integer :: a(3), c5, c7,i

read(*,*) (a(i), i=1,3)   !ここが入力欄

! ここに計算式
c5 = 0 ; c7 = 0
do i = 1, 3
if (a(i) == 5)then
	c5 = c5 + 1
else if (a(i) == 7)then
	c7 = c7 + 1
end if
end do

! ここに出力結果
if (c5 == 2 .and. c7 == 1) then
	write(*,'(a)') 'YES'
else
	write(*,'(a)') 'NO'
end if

END PROGRAM ATCODER