program prob1
    implicit none
    integer::i, j
    character(len=10)::s1, s2, s3
    read(*,*) s1, s2, s3

    write(*,'(3a)') char(ichar(s1(1:1)) - 32), char(ichar(s2(1:1)) - 32), char(ichar(s3(1:1)) - 32)
    stop
end program

Score : 100 points

Problem Statement

You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.
Print the acronym formed from the uppercased initial letters of the words.

Constraints

s_1, s_2 and s_3 are composed of lowercase English letters.

1 ≤ |s_i| ≤ 10 (1≤i≤3)

Input

Input is given from Standard Input in the following format:

s_1 s_2 s_3

Output

Print the answer.

Sample Input 1

atcoder beginner contest

Sample Output 1

ABC

The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.

Sample Input 2

resident register number

Sample Output 2

RRN

Sample Input 3

k nearest neighbor

Sample Output 3

KNN

Sample Input 4

async layered coding

Sample Output 4

ALC


program main
  implicit none

  integer(16)::a,b

  read(*,*)a
  read(*,*)b
  if ((a-b) > 0) then
    write(*,*)"GREATER"
  else if ((a-b) < 0) then
    write(*,*)"LESS"
  else
    write(*,*)"EQUAL"
  end if
end program main

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

Score : 200 points

Problem Statement

You are given two positive integers A and B. Compare the magnitudes of these numbers.

Constraints

1 ≤ A, B ≤ 10^{100}

Neither A nor B begins with a 0.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print GREATER if A>B, LESS if A<B and EQUAL if A=B.

Sample Input 1

36
24

Sample Output 1

GREATER

Since 36>24, print GREATER.

Sample Input 2

850
3777

Sample Output 2

LESS

Sample Input 3

9720246
22516266

Sample Output 3

LESS

Sample Input 4

123456789012345678901234567890
234567890123456789012345678901

Sample Output 4

LESS

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 alice_in_linear_land
  implicit none
  integer :: n, d, x(500000) = 0, q, p(500000) = 0, i
  integer :: a(500001) = 0, b(500001) = 0
  logical :: ok(500000) = .false.
  read(*,*) n, d
  read(*,*) x(1:n)
  read(*,*) q
  read(*,*) p(1:q)
  a(1) = d
  do i = 1, n
    a(i+1) = min(a(i),abs(a(i)-x(i)))
  end do
  b(n+1) = 1
  do i = n, 1, -1
    b(i) = b(i+1)
    if (b(i+1) > x(i)/2) b(i) = b(i+1)+x(i)
    ok(i) = a(i) >= b(i+1)
  end do
  do i = 1, q
    if (ok(p(i))) then
      write(*,'(a)') "YES"
    else
      write(*,'(a)') "NO"
    end if
  end do
end program alice_in_linear_land

Score : 900 points

Problem Statement

Alice lives on a line. Today, she will travel to some place in a mysterious vehicle.
Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by a distance of x if this move would shorten the distance between the vehicle and the destination, and it will stay at its position otherwise. Note that the vehicle may go past the destination when the distance between the vehicle and the destination is less than x.

Alice made a list of N numbers. The i-th number in this list is d_i. She will insert these numbers to the vehicle one by one.

However, a mischievous witch appeared. She is thinking of rewriting one number in the list so that Alice will not reach the destination after N moves.

She has Q plans to do this, as follows:

Rewrite only the q_i-th number in the list with some integer so that Alice will not reach the destination.

Write a program to determine whether each plan is feasible.

Constraints

1≤ N ≤ 5*10^5

1≤ Q ≤ 5*10^5

1≤ D ≤ 10^9

1≤ d_i ≤ 10^9(1≤i≤N)

1≤ q_i ≤ N(1≤i≤Q)

D and each d_i are integers.

Input

Input is given from Standard Input in the following format:

N D
d_1 d_2 ... d_N
Q
q_1 q_2 ... q_Q

Output

Print Q lines. The i-th line should contain YES if the i-th plan is feasible, and NO otherwise.

Sample Input 1

4 10
3 4 3 3
2
4 3

Sample Output 1

NO
YES

For the first plan, Alice will already arrive at the destination by the first three moves, and therefore the answer is NO.
For the second plan, rewriting the third number in the list with 5 will prevent Alice from reaching the destination as shown in the following figure, and thus the answer is YES.

Sample Input 2

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

Sample Output 2

YES
YES
YES
YES
YES

Alice will not reach the destination as it is, and therefore all the plans are feasible.

Sample Input 3

6 15
4 3 5 4 2 1
6
1 2 3 4 5 6

Sample Output 3

NO
NO
YES
NO
NO
YES


program beautiful
  implicit none

  integer :: a, b, c

  read(*,*) a, b, c

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

end program beautiful

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.


program tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 0, l = 1, i
  integer, allocatable :: p(:)
  read(*,*) n
  do while (rshift(n,k) > 0_8)
    k = k+1
  end do
  k = k-2
  p = [integer::]
  do i = k, 0, -1
    p = [p,l]
    l = l+1
    if (btest(n,i)) then
      p = [l,p]
      l = l+1
    end if
  end do
  write(*,'(i0)') 2*(l-1)
  write(*,'(i0)',advance='no') 1
  do i = 2, l-1
    write(*,'(x,i0)',advance='no') i
  end do
  do i = 1, l-1
    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 ABC057A
	integer(8)::A,B
    read(5,*)A,B
    print'(i0)',mod(A+B,24)
end program ABC057A

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.


program main
Integer :: a,b,c
read(*,*) a,b
print '(I2)', mod(a+b,24)
end program


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

read*,n

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


program digits_in_multiplication
  implicit none
  integer(8) :: n, m, h, l, i
  read(*,*) n
  m = int(ceiling(sqrt(real(n,8))),8)
  h = n/2_8
  l = 0_8
  do i = m, 1_8, -1_8
    if (mod(n,i).eq.0_8) then
      l = n/i
      exit
    end if
  end do
  if (l.eq.0_8) then
    write(*,'(i0)') int(log10(real(n,8))) + 1
  else
    write(*,'(i0)') int(log10(real(l,8))) + 1
  end if
end program digits_in_multiplication


program main
    implicit none
    integer:: n,a,b, i,j,k, c1,c2
    double precision, allocatable:: v(:)
    double precision:: ave, mnum
    character(1000):: cmnum

    read*, n, a, b
    allocate(v(n))
    read*, v(1:n)
    ! print*, "#1"
    call sort(v(1:n))
    ! print*, "#2"

    ave = dble(sum(v(n-a+1:n)))/dble(a)
    ! print*, "#3"

    c1 = count(v(1:n) == v(n-a+1))

    if (v(n) /= v(n-a)) then
        ! print*, "#4.1"
        c2 = count(v(n-a+1:n) == v(n-a+1))
        mnum = comb(c1,c2)
    else
        ! print*, "#4.2"
        c2 = min(c1,b)
        mnum = 0.d0
        do i = a, c2
            mnum = mnum + comb(c1,i)
        end do
    end if

    ! print*, c1,c2
    print'(f0.7)', ave
    write(cmnum,'(f0.0)') mnum
    ! print*, mnum
    print'(A)', cmnum(1:len_trim(cmnum)-1)

contains
function comb(n,m) result(ret)
    implicit none
    integer, intent(in):: n,m
    integer::i, end
    double precision, allocatable:: dp(:), ndp(:)
    double precision:: ret
    end = n + 1
    allocate(dp(0:end), ndp(0:end))
    dp(:) = 0.d0; ndp(:) = 0.d0
    dp(1) = 1.d0; ndp(1) = 1.d0
    do i = 1, n
        ndp(1:end) = ndp(1:end) + dp(0:end-1)
        dp(1:end) = ndp(1:end)
    end do
    ret = dp(m+1)
end function

subroutine sort(arr)
    implicit none
    integer:: i,j
    double precision,intent(inout):: arr(:)

    do i = 1,size(arr)
        do j = i, size(arr)
            if (arr(j) >= arr(i)) cycle
            call swap(arr(i), arr(j))
        end do
    end do
end subroutine

subroutine swap(a,b)
    implicit none
    double precision, intent(inout):: a,b
    double precision:: c
    c=a; a=b; b=c
end subroutine

end program

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 main
implicit none
character(1) :: a,b
logical      :: t
  read(*,*) a,b
  t = a=='H'
  if(t)then
    t = b=='H'
  else
    t = .not.b=='H'
  endif
  if(t)then
    print*,'H'
  else
    print*,'D'
  endif
end program main

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 ABC056B
    implicit none
    integer(8)::a,b,W,c,d
    read(5,*)W,a,b
    c=min(a,b)
    d=max(a,b)

    print'(i0)',max(d-c-W,0)
end program ABC056B

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 name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: x,i

    read*, x

    do i=1,100000
        if (((i-1)*i)/2 + 1 <= x .and. x <= (i*(i+1))/2) then
            print'(i0)', i
            stop
        end if
    end do
end program name

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


program ABC_056_C_GoHome
   implicit none
   integer(8) X, i ,S
   read(*, *) X
   do i = 1, 100000
      S = i * (i + 1) / 2
	  if(S >= X) then
	      write(*, *) i
		  exit
	  end if
   end do
end program ABC_056_C_GoHome


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(int64),allocatable:: a(:), cnt(:)

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

    call merge_sort(a,1_8,int(n,kind=int64))

    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


implicit none
integer :: n,i,k
read(*,*) n
k=1
do i=1,n
k=mod(k*i,10**9+7)
end do
write(*,'(i0)') k
end

Score : 200 points

Problem Statement

Snuke loves working out. He is now exercising N times.

Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.

Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

Constraints

1 ≤ N ≤ 10^{5}

Input

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

N

Output

Print the answer modulo 10^{9}+7.

Sample Input 1

3

Sample Output 1

6

After Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.

After Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.

After Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.

Sample Input 2

10

Sample Output 2

3628800

Sample Input 3

100000

Sample Output 3

457992974

Print the answer modulo 10^{9}+7.


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)=='x',i=1,n)]
    if(n<2)then
      if(t(1))then
        print*,'S'
      else
        print*,-1
      endif
      RETURN
    endif

    sw(1) = .TRUE.

    if(t(1))then
      sw(2) = sw(1)
    else
      sw(2) = .not.sw(1)
    endif

    do i=2,n-1
      if(t(i))then
        sw(i+1) = sw(i)
      else
        sw(i+1) = .not.sw(i)
      endif
    enddo

    if(sw(1).eqv.sw(N).and..not.t(N))then
      do i=1,n
        if(sw(i))then
          write(*,'(A)',advance='NO') 'S'
        else
          write(*,'(A)',advance='NO') 'W'
        endif
      enddo
    else
      print*,-1
    endif
  end subroutine wolv_or_sheep

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)', 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


read*,i,j

if( i==j )then
  print*,'Draw'
  stop
end if

if( i>j .or.i==1 )then
  print*,'Alice'
elseif( j>i .or. j==1 )then
  print*,'Bob'
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 piyo
      integer,parameter :: p=8
      integer(p) :: n,m, i,j, offsetR,offsetC
      character(:),allocatable :: a,b
      integer(p),allocatable :: imA(:,:),imB(:,:),tempA(:,:)

      read*,n,m
      allocate( character(n)::a )
      allocate( character(m)::b )
      allocate( imA(N,N), imB(M,M), tempA(M,M) )
      do i = 1,n
        read*,a
        do j = 1,n
          if(a(j:j)=='.')then
            imA(i,j) = 1
          else
            imA(i,j) = 0
          end if
        end do
      end do
      do i = 1,m
        read*,b
        do j = 1,m
          if(b(j:j)=='.')then
            imB(i,j) = 1
          else
            imB(i,j) = 0
          end if
        end do
      end do

      do offsetR = 0,(N-M)
        do offsetC = 0,(N-M)
          tempA = imA(1+offsetR:M+offsetR,1+offsetC:M+offsetC)
          tempA = abs(tempA(:,:) - imB(:,:))
          if( sum(tempA(:,:))==0 )then
            print*,'Yes'
            stop
          end if
        end do
      end do

      print*,'No'

      stop

      do i = 1,n
        print'(*(i1,x))',ima(i,:)
      end do
      do i = 1,m
        print'(*(i1,x))',imb(i,:)
      end do

      end

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.


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


integer a
read*, a
if(a .lt. 1200) then
	print*, 'ABC'
else
	print*, 'ARC'
end if
end

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 main
	implicit none
    integer x
	read(*, *) x
	if(x < 1200) then
		write(*, *) 'ABC'
	else
		write(*, *) 'ARC'
	end if
end program main


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

    read*, x
    mx = mod(x,11_8)
    print'(i0)', 2_8*(x/11_8)+and(mx,1_8)+and(mx/6_8,1_8)
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


module mod_binary_indexed_tree
  implicit none
  type fenwick_tree
    integer :: n
    integer, pointer :: arr(:)
  end type fenwick_tree
  private
  public :: fenwick_tree, init_bit, release_bit
  public :: add, summate, update, maximum
contains
  subroutine init_bit(bit,n)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: n
    bit%n = n
    allocate(bit%arr(n))
    bit%arr = 0
    return
  end subroutine init_bit
  subroutine release_bit(bit)
    implicit none
    type(fenwick_tree) :: bit
    if (associated(bit%arr)) deallocate(bit%arr)
    return
  end subroutine release_bit
  subroutine add(bit,i,v)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i, v
    integer :: x
    if (i.eq.0) return
    x = i
    do while (x.le.bit%n)
      bit%arr(x) = bit%arr(x)+v
      x = x+and(x,-x)
    end do
    return
  end subroutine add
  function summate(bit,i) result(s)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i
    integer :: x, s
    x = i
    s = 0
    do while (x.gt.0)
      s = s+bit%arr(x)
      x = x-and(x,-x)
    end do
    return
  end function summate
  subroutine update(bit,i,v)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i, v
    integer :: x
    x = i
    do while (x.le.bit%n)
      if (bit%arr(x).lt.v) bit%arr(x) = v
      x = x+and(x,-x)
    end do
    return
  end subroutine update
  function maximum(bit,i) result(m)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i
    integer :: x, m
    x = i
    m = 0
    do while (x.gt.0)
      m = max(m,bit%arr(x))
      x = x-and(x,-x)
    end do
    return
  end function maximum
end module mod_binary_indexed_tree
program snuke_line
  use mod_binary_indexed_tree
  implicit none
  type(fenwick_tree) :: bit
  integer :: n, m, a(300000,3), ans(100000), i, j, k, x
  a = 0
  ans = 0
  read(*,*) n, m
  do i = 1, n
    read(*,*) a(i,1), a(i,2)
    a(i,3) = a(i,2)-a(i,1)+1
  end do
  call quick_sort(a(1:n,1:3),3)
  call init_bit(bit,m+1)
  ans(1) = n
  j = 1
  do i = 2, m
    do while (j.le.n)
      if (a(j,3).gt.i) exit
      call add(bit,a(j,1),1)
      call add(bit,a(j,2)+1,-1)
      j = j+1
    end do
    x = n-j+1
    do k = i, m, i
      x = x+summate(bit,k)
    end do
    ans(i) = x
  end do
  do i = 1, m
    write(*,'(i0)') ans(i)
  end do
  stop
contains
  recursive subroutine quick_sort(a,i)
    implicit none
    integer, intent(inout) :: a(:,:)
    integer, intent(in) :: i
    integer :: p, c(size(a(1,:)))
    integer :: n, l, r, m
    n = size(a(:,1))
    l = 1
    r = n
    m = (l+r)/2
    p = a(l,i)+a(m,i)+a(r,i)-max(a(l,i),a(m,i),a(r,i))-min(a(l,i),a(m,i),a(r,i))
    do
      do while (a(l,i).lt.p)
        l = l+1
      end do
      do while (a(r,i).gt.p)
        r = r-1
      end do
      if (l.ge.r) exit
      c = a(l,:)
      a(l,:) = a(r,:)
      a(r,:) = c
      l = l+1
      r = r-1
    end do
    if (l.gt.2) call quick_sort(a(1:l-1,:),i)
    if (n.gt.r+1) call quick_sort(a(r+1:n,:),i)
    return
  end subroutine quick_sort
end program snuke_line

Score : 700 points

Problem Statement

Snuke has decided to play a game, where the player runs a railway company.
There are M+1 stations on Snuke Line, numbered 0 through M.
A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train.
For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.

There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.

There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M.
For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0.
Here, assume that it is not allowed to change trains.

Constraints

1 ≦ N ≦ 3 × 10^{5}

1 ≦ M ≦ 10^{5}

1 ≦ l_i ≦ r_i ≦ M

Input

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

N M
l_1 r_1
:
l_{N} r_{N}

Output

Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.

Sample Input 1

3 3
1 2
2 3
3 3

Sample Output 1

3
2
2

If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind 1, 2 and 3.

If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind 1 and 2.

If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind 2 and 3.

Sample Input 2

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

Sample Output 2

7
6
6
5
4
5
5
3
2


Score : 100 points

Problem Statement

There are two rectangles.
The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.
The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.

Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

Constraints

All input values are integers.

1≤A≤10^4

1≤B≤10^4

1≤C≤10^4

1≤D≤10^4

Input

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

A B C D

Output

Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

Sample Input 1

3 5 2 7

Sample Output 1

15

The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14.
Thus, the output should be 15, the larger area.

Sample Input 2

100 600 200 300

Sample Output 2

60000


program answer
  implicit none
  integer :: N, j, ans, count
  character(len=100) :: S
  character(len=1) :: ss

  ss='I'

  read(*,*) N
  read(*,*) S

  count=0
  ans=0

  do j = 1, N
     if(S(j:j)==ss(1:1)) then
        count=count+1
     else
        count=count-1
     end if

     if(count>ans) then
        ans=count
     end if
  end do

  write(*,*) ans

  stop
 end program answer

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.


integer N,tmp
integer(8)ans
integer NumOfPrime(168),primenumbers(168)
read*,N
NumOfPrime=0
call getprime(1000,primenumbers)
do i=2,N
  tmp=i
  do j=1,168
    do while(mod(tmp,primenumbers(j))==0)
      NumOfPrime(j)=NumOfPrime(j)+1
      tmp=tmp/primenumbers(j)
    end do
  end do
end do
ans=1
do i=1,168
  ans=mod(ans*(NumOfPrime(i)+1),10**9+7)
end do
print"(i0)",ans
contains
subroutine getprime(N,array)
  integer N
  integer,dimension(:)::array
  integer ind
  logical pr
  array(1)=2;ind=1
  do i=3,N
    pr=.true.
    do j=1,ind
      if(mod(i,array(j))==0)then
        pr=.false.
        exit
      endif
    end do
    if(pr)then
      array(ind+1)=i;ind=ind+1
    endif
  end do
end subroutine
end

Score : 300 points

Problem Statement

You are given an integer N.
Find the number of the positive divisors of N!, modulo 10^9+7.

Constraints

1≤N≤10^3

Input

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

N

Output

Print the number of the positive divisors of N!, modulo 10^9+7.

Sample Input 1

3

Sample Output 1

4

There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.

Sample Input 2

6

Sample Output 2

30

Sample Input 3

1000

Sample Output 3

972926972


program main
    implicit none
    integer, parameter:: inf = 10000
    integer, allocatable:: dist(:,:), a(:), b(:), c(:)
    integer:: n, m, i, j, k
    integer:: ans

    read*, n, m
    allocate(dist(m,m), a(m),b(m),c(m))

    do i = 1, m
        read*, a(i), b(i), c(i)
    end do

    dist(:,:) = inf

    do i = 1, m
        dist(i,i) = 0
    end do

    do i = 1, m
        dist(a(i),b(i)) = min(dist(a(i),b(i)),c(i))
        dist(b(i),a(i)) = min(dist(b(i),a(i)),c(i))

    end do

    do k = 1, m
        do i =1, m
            do j = 1, m
                dist(i, j) = min(dist(i,j), dist(i,k) + dist(k,j))
            end do
        end do
    end do

    ans = m

    do i = 1, m
        do j = 1, m
            if (dist(i,b(j)) == dist(i,a(j)) + c(j)) then
                ans = ans - 1
                exit
            end if
        end do
    end do

    print'(i0)', ans

end program

Score : 100 points

Problem Statement

As a New Year's gift, Dolphin received a string s of length 19.

The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].

Dolphin wants to convert the comma-separated string s into a space-separated string.

Write a program to perform the conversion for him.

Constraints

The length of s is 19.

The sixth and fourteenth characters in s are ,.

The other characters in s are lowercase English letters.

Input

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

s

Output

Print the string after the conversion.

Sample Input 1

happy,newyear,enjoy

Sample Output 1

happy newyear enjoy

Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.

Sample Input 2

haiku,atcoder,tasks

Sample Output 2

haiku atcoder tasks

Sample Input 3

abcde,fghihgf,edcba

Sample Output 3

abcde fghihgf edcba


program main
implicit none
integer :: sx, sy, tx, ty
integer :: ix, iy, i, j, k
character :: res*20000

read(*,*) sx, sy, tx, ty

i = tx -sx
j = ty -sy
k = 1
do ix = k, k+i-1
   res(ix:ix) = 'R'
end do
k = k+i
do iy = k, k+j-1
   res(iy:iy) = 'U'
end do
k = k+j
do ix = k, k+i-1
   res(ix:ix) = 'L'
end do
k = k+i
do iy = k, k+j-1
   res(iy:iy) = 'D'
end do
k = k+j
res(k:k) = 'D'
k = k+1
do ix = k, k+i
   res(ix:ix) = 'R'
end do
k = k+i+1
do iy = k, k+j
   res(iy:iy) = 'U'
end do
k = k+j+1
res(k:k+1) = 'LU'
k = k+2
do ix = k, k+i
   res(ix:ix) = 'L'
end do
k = k+i+1
do iy = k, k+j
   res(iy:iy) = 'D'
end do
k = k +j+1
res(k:k) = 'R'
write(*,*) res(1:k)

end program main

Score : 300 points

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.

Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.

Here, both the x- and y-coordinates before and after each movement must be integers.

He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).

Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).

Under this condition, find a shortest path for him.

Constraints

-1000 ≤ sx < tx ≤ 1000

-1000 ≤ sy < ty ≤ 1000

sx,sy,tx and ty are integers.

Input

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

sx sy tx ty

Output

Print a string S that represents a shortest path for Dolphin.

The i-th character in S should correspond to his i-th movement.

The directions of the movements should be indicated by the following characters:

U: Up

D: Down

L: Left

R: Right

If there exist multiple shortest paths under the condition, print any of them.

Sample Input 1

0 0 1 2

Sample Output 1

UURDDLLUUURRDRDDDLLU

One possible shortest path is:

Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)

Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)

Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)

Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)

Sample Input 2

-2 -2 1 1

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL


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

    read*, x,y
    ans = 2000000000
    if (y-x >= 0) then
        ans=min(ans,y-x)
    end if

    if (y-(-x) >= 0) then
        ans = min(ans,y-(-x)+1)
    end if

    if ((-y) - x >= 0)then
        ans = min(ans,(-y)-x+1)
    end if

    if ((-y)-(-x) >= 0) then
        ans = min(ans,(-y)-(-x)+2)
    end if

    print'(i0)', ans
end program name

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.


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

if (s=="+" ) then
    write(*,*) a+b
else
    write(*,*) a-b
endif
end

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 prob2
    implicit none
    integer :: N, M
    integer, allocatable, dimension(:) :: T, P, X
    integer :: ans, i, j
    read(*,*) N
    allocate(T(N))
    read(*,*) T
    read(*,*) M
    allocate(P(M))
    allocate(X(M))
    do i = 1, M
        read(*,*) P(i), X(i)
    end do
    do i = 1, M
        ans = 0
        do j = 1, N
            if(j == P(i)) then
                ans = ans + X(i)
            else
                ans = ans + T(j)
            end if
        end do
        write(*,*) ans
    end do

    deallocate(T, P, X)

    stop
contains
end program prob2

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,ans
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

ans = 1
do i = 1, n/2
  ans = mod(ans*2,10**9+7)
end do

print'(i0)', ans

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 ABC049A
    implicit none
    character(1)::c
    read(5,*)c
    if(c=="a".or.c=="e".or.c=="i".or.c=="o".or.c=="u")then
        print'(A)',"vowel"
    else
        print'(A)',"consonant"
    end if
end program ABC049A

Score : 100 points

Problem Statement

Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u.

Constraints

c is a lowercase English letter.

Input

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

c

Output

If c is a vowel, print vowel. Otherwise, print consonant.

Sample Input 1

a

Sample Output 1

vowel

Since a is a vowel, print vowel.

Sample Input 2

z

Sample Output 2

consonant

Sample Input 3

s

Sample Output 3

consonant


program main
implicit none
integer :: i, j, k
character :: c*100
integer :: h, w

read(*,*) h, w
do i = 1, h
   read(*,*) c(1:w)
   write(*,*) c(1:w)
   write(*,*) c(1:w)
end do

end program main


Score : 900 points

Problem Statement

There is a string S of length N consisting of characters 0 and 1. You will perform the following operation for each i = 1, 2, ..., m:

Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and extending through the r_i-th character.

Here, the sequence l_i is non-decreasing.

How many values are possible for S after the M operations, modulo 1000000007(= 10^9+7)?

Constraints

2≦N≦3000

1≦M≦3000

S consists of characters 0 and 1.

The length of S equals N.

1≦l_i < r_i≦N

l_i ≦ l_{i+1}

Input

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

N M
S
l_1 r_1
:
l_M r_M

Output

Print the number of the possible values for S after the M operations, modulo 1000000007.

Sample Input 1

5 2
01001
2 4
3 5

Sample Output 1

6

After the first operation, S can be one of the following three: 01001, 00101 and 00011.

After the second operation, S can be one of the following six: 01100, 01010, 01001, 00011, 00101 and 00110.

Sample Input 2

9 3
110111110
1 4
4 6
6 9

Sample Output 2

26

Sample Input 3

11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11

Sample Output 3

143


program ABC048A
    implicit none
    character(100)::s1,s2,s3
    read(5,*)s1,s2,s3
    print'(A,A,A)',s1(1:1),s2(1:1),s3(1:1)
end program ABC048A

Score : 100 points

Problem Statement

Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

Snuke has decided to abbreviate the name of the contest as "AxC".
Here, x is the uppercase English letter at the beginning of s.

Given the name of the contest, print the abbreviation of the name.

Constraints

The length of s is between 1 and 100, inclusive.

The first character in s is an uppercase English letter.

The second and subsequent characters in s are lowercase English letters.

Input

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

AtCoder s Contest

Output

Print the abbreviation of the name of the contest.

Sample Input 1

AtCoder Beginner Contest

Sample Output 1

ABC

The contest in which you are participating now.

Sample Input 2

AtCoder Snuke Contest

Sample Output 2

ASC

This contest does not actually exist.

Sample Input 3

AtCoder X Contest

Sample Output 3

AXC


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

read(*,*) s
t = 'A'//s(1:1)//'C'
write(*,*) t

end program main


program main
  implicit none
  integer(8) :: a, b, x
  read *, a, b, x
  a = max(0_8, a)
  print "(i0)", b / x - (a - 1) / x
end program main

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 ABC048B
    implicit none
    integer(8)::a,b,x
    read(5,*)a,b,x
    if(a==0)then
        print'(i0)',b/x
    else
        print'(i0)',b/x-(a-1)/x
    end if
end program ABC048B


program main
  implicit none

  integer(16) :: a,b,x,aa,bb

  read(*,*)a,b,x
  if (a == b) then
    write(*,*)0
    stop
  end if
  aa = a/x
  bb = b/x
  if (mod(a,x) == 0) then
    write(*,'(i0)')bb-aa+1
  else
    write(*,'(i0)')bb-aa
  end if
end program main


PROGRAM ATCODER

implicit none
integer(16) :: a,b,x

read(*,*) a,b,x

if(a == 0)then
  write(*,'(i0)') b/x+1
else
  write(*,'(i0)') (b/x+1)-((a-1)/x+1)
end if

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER


program kode_festival
  implicit none
  integer :: n , a(262144), b(131072), m, i, k
  a = 0
  b = 0
  read(*,*) n
  m = 2**n
  do i = 1, m
    read(*,*) a(i)
  end do
  do k = 1, n
    m = m/2
    do i = 1, m
      if (a(2*i-1).eq.a(2*i)) then
        b(i) = a(2*i-1)
      else
        b(i) = max(a(2*i-1),a(2*i))-min(a(2*i-1),a(2*i))
      end if
    end do
    a(1:m) = b(1:m)
  end do
  write(*,'(i0)') a(1)
  stop
end program kode_festival

Score : 100 points

Problem Statement

Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)

This year, 2^N stones participated. The hardness of the i-th stone is A_i.

In the contest, stones are thrown at each other in a knockout tournament.

When two stones with hardness X and Y are thrown at each other, the following will happen:

When X > Y:
The stone with hardness Y will be destroyed and eliminated.
The hardness of the stone with hardness X will become X-Y.

When X = Y:
One of the stones will be destroyed and eliminated.
The hardness of the other stone will remain the same.

When X < Y:
The stone with hardness X will be destroyed and eliminated.
The hardness of the stone with hardness Y will become Y-X.

The 2^N stones will fight in a knockout tournament as follows:

The following pairs will fight: (the 1-st stone versus the 2-nd stone), (the 3-rd stone versus the 4-th stone), ...

The following pairs will fight: (the winner of (1-st versus 2-nd) versus the winner of (3-rd versus 4-th)), (the winner of (5-th versus 6-th) versus the winner of (7-th versus 8-th)), ...

And so forth, until there is only one stone remaining.

Determine the eventual hardness of the last stone remaining.

Constraints

1 \leq N \leq 18

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_{2^N}

Output

Print the eventual hardness of the last stone remaining.

Sample Input 1

2
1
3
10
19

Sample Output 1

7

Sample Input 2

3
1
3
2
4
6
8
100
104

Sample Output 2

2


program segment_on_grid_paper
  implicit none
  integer :: a, b, c, d, x, y, y0, y1, i
  integer(8) :: m
  read(*,*) a, b, c, d
  x = abs(c-a)
  y = abs(d-b)
  y0 = 0
  m = 0_8
  do i = 1, x
    y1 = ceiling(real(y,8)*real(i,8)/real(x,8))
    m = m+int(y1-y0,8)
    y0 = floor(real(y,8)*real(i,8)/real(x,8))
  end do
  write(*,'(i0)') m
  stop
end program segment_on_grid_paper

Score : 100 points

Problem Statement

Takahashi is drawing a segment on grid paper.

From a certain square, a square that is x squares to the right and y squares above, is denoted as square (x, y).

When Takahashi draws a segment connecting the lower left corner of square (A, B) and the lower left corner of square (C, D), find the number of the squares crossed by the segment.

Here, the segment is said to cross a square if the segment has non-empty intersection with the region within the square, excluding the boundary.

Constraints

1 \leq A, B, C, D \leq 10^9

At least one of A \neq C and B \neq D holds.

Input

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

A B C D

Output

Print the number of the squares crossed by the segment.

Sample Input 1

1 1 3 4

Sample Output 1

4

Sample Input 2

2 3 10 7

Sample Output 2

8


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)
  dp(1:n,1) = a(1:n)
  do j = 2, k
    do i = 1, n
      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


module mod_linked_list
  implicit none

  type t_node
    private
    integer :: item
    type(t_node), pointer :: prev => null()
    type(t_node), pointer :: next => null()
  end type t_node

  type t_linked_list
    private
    integer :: num = 0
    type(t_node), pointer :: head => null()
    type(t_node), pointer :: tail => null()
  contains
    procedure :: add_first => add_first
    procedure :: add_last => add_last
    procedure :: poll_first => poll_first
    procedure :: poll_last => poll_last
    procedure :: peek_first => peek_first
    procedure :: peek_last => peek_last
    procedure :: clear => clear
    procedure :: get => get
    procedure :: remove => remove
    procedure :: replace => replace
    procedure :: first_index_of => first_index_of
    procedure :: last_index_of => last_index_of
    procedure :: size => size_of
  end type t_linked_list

contains

  function new_node(item) result(node)
    integer, intent(in) :: item
    type(t_node), pointer :: node
    allocate(node)
    node%item = item
  end

  subroutine add_first(this,item)
    class(t_linked_list), intent(inout) :: this
    integer, intent(in) :: item
    type(t_node), pointer :: node
    node => new_node(item)
    if (associated(this%tail)) then
      node%next => this%head
      this%head%prev => node
    else
      this%tail => node
    end if
    this%head => node
    this%num = this%num+1
  end

  subroutine add_last(this,item)
    class(t_linked_list), intent(inout) :: this
    integer, intent(in) :: item
    type(t_node), pointer :: node
    node => new_node(item)
    if (associated(this%head)) then
      node%prev => this%tail
      this%tail%next => node
    else
      this%head => node
    end if
    this%tail => node
    this%num = this%num+1
  end

  function poll_first(this) result(item)
    class(t_linked_list), intent(inout) :: this
    integer :: item
    type(t_node), pointer :: node
    item = this%head%item
    node => this%head%next
    deallocate(this%head)
    this%head => node
    if (associated(node)) then
      node%prev => null()
    else
      this%tail => null()
    end if
    this%num = this%num-1
  end

  function poll_last(this) result(item)
    class(t_linked_list), intent(inout) :: this
    integer :: item
    type(t_node), pointer :: node
    item = this%tail%item
    node => this%tail%prev
    deallocate(this%tail)
    this%tail => node
    if (associated(node)) then
      node%next => null()
    else
      this%head => null()
    end if
    this%num = this%num-1
  end

  function peek_first(this) result(item)
    class(t_linked_list), intent(in) :: this
    integer :: item
    item = this%head%item
  end

  function peek_last(this) result(item)
    class(t_linked_list), intent(in) :: this
    integer :: item
    item = this%tail%item
  end

  subroutine clear(this)
    class(t_linked_list), intent(inout) :: this
    type(t_node), pointer :: node, next
    if (.not.associated(this%head)) return
    node => this%head
    do while (associated(node%next))
      next => node%next
      deallocate(node)
      node => next
    end do
    this%head => null()
    this%tail => null()
    this%num = 0
  end

  function get(this,i) result(item)
    class(t_linked_list), intent(in) :: this
    integer, intent(in) :: i
    integer :: item, idx
    type(t_node), pointer :: node
    if (i <= (this%num+1)/2) then
      idx = 1
      node => this%head
      do while (idx < i)
        node => node%next
        idx = idx+1
      end do
    else
      idx = this%num
      node => this%tail
      do while (idx > i)
        node => node%prev
        idx = idx-1
      end do
    end if
    item = node%item
  end

  function remove(this,i) result(item)
    class(t_linked_list), intent(inout) :: this
    integer, intent(in) :: i
    integer :: item, idx
    type(t_node), pointer :: node
    if (i == 1) then
      item = poll_first(this)
      return
    end if
    if (i == this%num) then
      item = poll_last(this)
      return
    end if
    if (i <= (this%num+1)/2) then
      idx = 1
      node => this%head
      do while (idx < i)
        node => node%next
        idx = idx+1
      end do
    else
      idx = this%num
      node => this%tail
      do while (idx > i)
        node => node%prev
        idx = idx-1
      end do
    end if
    item = node%item
    node%prev%next => node%next
    node%next%prev => node%prev
    deallocate(node)
    this%num = this%num-1
  end

  subroutine replace(this,i,item)
    class(t_linked_list), intent(inout) :: this
    integer, intent(in) :: i, item
    integer :: idx
    type(t_node), pointer :: node
    if (i <= (this%num+1)/2) then
      idx = 1
      node => this%head
      do while (idx < i)
        node => node%next
        idx = idx+1
      end do
    else
      idx = this%num
      node => this%tail
      do while (idx > i)
        node => node%prev
        idx = idx-1
      end do
    end if
    node%item = item
  end

  subroutine show_all(this)
    type(t_linked_list), intent(in) :: this
    type(t_node), pointer :: node, next
    if (.not.associated(this%head)) return
    node => this%head
    write(*,'(i0)',advance='no') node%item
    do while (associated(node%next))
      node => node%next
      write(*,'(x,i0)',advance='no') node%item
    end do
    write(*,*)
  end

  function first_index_of(this,item) result(idx)
    class(t_linked_list), intent(in) :: this
    integer, intent(in) :: item
    integer :: idx
    type(t_node), pointer :: node
    idx = 1
    node => this%head
    do while (associated(node))
      if (node%item == item) return
      node => node%next
      idx = idx+1
    end do
    idx = -1
  end

  function last_index_of(this,item) result(idx)
    class(t_linked_list), intent(in) :: this
    integer, intent(in) :: item
    integer :: idx
    type(t_node), pointer :: node
    idx = this%num
    node => this%tail
    do while (associated(node))
      if (node%item == item) return
      node => node%prev
      idx = idx-1
    end do
    idx = -1
  end

  integer function size_of(this)
    class(t_linked_list), intent(in) :: this
    size_of = this%num
  end

end module mod_linked_list

program tokaido
  use mod_linked_list
  implicit none
  integer :: n, m, a(200000) = 0, x, s = 0, d, i, j
  integer :: dp(0:1000000) = 0, tmp
  type(t_linked_list) :: deque, tmp1, tmp2
  read(*,*) n
  read(*,*) a(1:n-1)
  if (n > 3) s = sum(a(3:n-1))
  d = a(1)-a(2)
  do i = 0, s-1
    call deque%add_last(i)
  end do
  do i = 3, n-1
    do j = 0, a(i)
      call tmp1%add_last(deque%peek_first())
      call tmp2%add_last(deque%poll_first())
    end do
    do j = 0, a(i)
      call deque%add_first(tmp1%poll_last())
    end do
    tmp = tmp2%poll_first()
    do j = 1, a(i)
      call deque%add_first(tmp2%poll_first())
      tmp = deque%poll_last()
    end do
  end do
  do i = 0, s-1
    dp(i) = deque%poll_first()
  end do
  read(*,*) m
  do i = 1, m
    read(*,*) x
    if (x >= s) then
      write(*,'(i0)') x-s+d
      cycle
    end if
    write(*,'(i0)') dp(x)+d
  end do
end program tokaido

Score : 1600 points

Problem Statement

There are N squares in a row, numbered 1 through N from left to right.
Snuke and Rng are playing a board game using these squares, described below:

First, Snuke writes an integer into each square.

Each of the two players possesses one piece. Snuke places his piece onto square 1, and Rng places his onto square 2.

The player whose piece is to the left of the opponent's, moves his piece. The destination must be a square to the right of the square where the piece is currently placed, and must not be a square where the opponent's piece is placed.

Repeat step 3. When the pieces cannot be moved any more, the game ends.

The score of each player is calculated as the sum of the integers written in the squares where the player has placed his piece before the end of the game.

Snuke has already written an integer A_i into square i (1≦i≦N-1), but not into square N yet.
He has decided to calculate for each of M integers X_1,X_2,...,X_M, if he writes it into square N and the game is played, what the value "(Snuke's score) - (Rng's score)" will be.
Here, it is assumed that each player moves his piece to maximize the value "(the player's score) - (the opponent's score)".

Constraints

3≦N≦200,000

0≦A_i≦10^6

The sum of all A_i is at most 10^6.

1≦M≦200,000

0≦X_i≦10^9

Partial Scores

700 points will be awarded for passing the test set satisfying M=1.

Additional 900 points will be awarded for passing the test set without additional constraints.

Input

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

N
A_1 A_2 ... A_{N-1}
M
X_1
X_2
:
X_M

Output

For each of the M integers X_1, ..., X_M, print the value "(Snuke's score) - (Rng's score)" if it is written into square N, one per line.

Sample Input 1

5
2 7 1 8
1
2

Sample Output 1

0

The game proceeds as follows, where S represents Snuke's piece, and R represents Rng's.

Both player scores 10, thus "(Snuke's score) - (Rng's score)" is 0.

Sample Input 2

9
2 0 1 6 1 1 2 6
5
2016
1
1
2
6

Sample Output 2

2001
6
6
7
7


program main
read*,i,j,k
if(mod(i+j+k,2)==0)then
print*,"Yes"
else
print*,"No"
endif
end program main

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 main
  implicit none

  integer :: h,w,n,xmin=200,xmax=0,ymin=200,ymax=0,i,x,y,a

  read(*,*)w,h,n
  do i = 1, n
    read(*,*)x,y,a
    if (a == 1) then
      if (x < xmin) then
        xmin = x
      end if
    else if (a == 2) then
      if (x > xmax) then
        xmax = x
      end if
    else if (a == 3) then
      if (y < ymin) then
        ymin = y
      end if
    else if (a == 4) then
      if (y > ymax) then
        ymax = y
      end if
    end if
  end do

  if ((xmin > xmax) .or. (ymin > ymax)) then
    write(*,*)0
  else
    write(*,*)(xmax - xmin)*(ymax - ymin)
  end if
end program main

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 main
  implicit none
  integer w,h,n,x,y,a,i
  integer,allocatable::m(:,:)
  read*,w,h,n
  allocate(m(w,h))
  m=1;
  do i=1,n
     read*,x,y,a
     if(a==1) then
        m(1:x,:)=0
     elseif(a==2)then
	m(x+1:w,:)=0
     elseif(a==3)then
	m(:,1:y)=0
     else
        m(:,y+1:h)=0
     end if

  end do
  print*,sum(m)
end program main


PROGRAM ATCODER

implicit none
integer :: n,t,i,num,dp,ans=0
integer,allocatable :: a(:)

read(*,*) n,t
allocate(a(n))
read(*,*) (a(i), i=1,n)

dp = 0
num = 1
do i = 1,n
  call chmax(dp,maxval(a(i:n))-a(i),num,i)
end do

do i = 1,n
  if(maxval(a(i:n))-a(i) == dp)then
    ans = ans + 1
  end if
end do

write(*,'(i0)') ans

contains
!!!!!! サブルーチンは↓
subroutine chmax(dp,x,num,i)
implicit none
integer :: dp, x, num, i

if (dp < x) then
  dp = x
  num = i
  return
end if

end subroutine
!!!!!!

END PROGRAM ATCODER

Score : 400 points

Problem Statement

There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.

Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:

Move: When at town i (i < N), move to town i + 1.

Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.

For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)

During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.

Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.

Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Constraints

1 ≦ N ≦ 10^5

1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

A_i are distinct.

2 ≦ T ≦ 10^9

In the initial state, Takahashi's expected profit is at least 1 yen.

Input

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

N T
A_1 A_2 ... A_N

Output

Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.

Sample Input 1

3 2
100 50 200

Sample Output 1

1

In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:

Move from town 1 to town 2.

Buy one apple for 50 yen at town 2.

Move from town 2 to town 3.

Sell one apple for 200 yen at town 3.

If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1.

There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.

Sample Input 2

5 8
50 30 40 10 20

Sample Output 2

2

Sample Input 3

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

Sample Output 3

2


program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,m,n

    read(*,*) n
    read(*,*)s
    read(*,*)t

    do i=1,n,-1
        if(s(n+1-i:n) .eq. t(1:i))then
            m=2*n-i
            write(*,*) m
            stop
        end if
    enddo
    write(*,*) n

    stop
end program sample

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 .or. n<x) 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 main
	implicit none
    integer(8)::k,t
    integer(8),allocatable::a(:)
    read(*,*) k,t
    allocate(a(t))
    read(*,*) a
    call msort(a)
    if(t==1)then
    	write(*,*) a(1)-1
    else

    	write(*,*) max(a(t)- (sum(a)-a(t)) -1,0)
    end if
    deallocate(a)

    stop
contains
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)

    n = size(x)

    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do

    deallocate(tmp)
    return
  end subroutine msort
end program main

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.


program two_alpinists
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: t(100000), a(100000), m
  integer :: n, i
  t = 0_8
  a = 0_8
  read(*,*) n
  read(*,*) t(1:n)
  read(*,*) a(1:n)
  if (t(n).ne.a(1)) then
    write(*,'(i0)') 0
    stop
  end if
  m = 1_8
  do i = 2, n-1
    if (t(i).gt.a(i).or.t(i).ne.t(i-1)) cycle
    m = mod(m*t(i),md)
  end do
  do i = n-1, 2, -1
    if (a(i).gt.t(i).or.a(i).ne.a(i+1)) cycle
    m = mod(m*a(i),md)
  end do
  write(*,'(i0)') m
  stop
end program two_alpinists

Score : 400 points

Problem Statement

Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.
The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N.
Mr. Takahashi traversed the range from the west and Mr. Aoki from the east.

The height of Mt. i is h_i, but they have forgotten the value of each h_i.
Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. i (including Mt. i).
Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i.

We know that the height of each mountain h_i is a positive integer.
Compute the number of the possible sequences of the mountains' heights, modulo 10^9 + 7.

Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.
In such a case, output 0.

Constraints

1 ≤ N ≤ 10^5

1 ≤ T_i ≤ 10^9

1 ≤ A_i ≤ 10^9

T_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)

A_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)

Input

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

N
T_1 T_2 ... T_N
A_1 A_2 ... A_N

Output

Print the number of possible sequences of the mountains' heights, modulo 10^9 + 7.

Sample Input 1

5
1 3 3 3 3
3 3 2 2 2

Sample Output 1

4

The possible sequences of the mountains' heights are:

1, 3, 2, 2, 2

1, 3, 2, 1, 2

1, 3, 1, 2, 2

1, 3, 1, 1, 2

for a total of four sequences.

Sample Input 2

5
1 1 1 2 2
3 2 1 1 1

Sample Output 2

0

The records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.

Sample Input 3

10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Sample Output 3

884111967

Don't forget to compute the number modulo 10^9 + 7.

Sample Input 4

1
17
17

Sample Output 4

1

Some mountain ranges consist of only one mountain.


program main
implicit none
integer :: i, j, k
integer :: a(3)

read(*,*) a
k = 0
do i = 1, 2
   do j = i+1, 3
      if( a(i) /= a(j) ) then
         k = k + 1
      end if
   end do
end do
write(*,'(i0)') max(k,1)

end program main

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 ATCODER

implicit none
integer(16) :: n,k,count,i,j

read(*,*) n,k    !ここが入力欄

count = k*(k-1)**(n-1)

! ここに出力結果
write(*,'(i0)') count

contains
!!!!!! サブルーチンは↓

!!!!!!

END PROGRAM ATCODER

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.


program main
	implicit none
    integer::i,ans
    character(16)::s,t
    t='CODEFESTIVAL2016'
    read(*,*)s
    ans=16
    do i=1,16
    	if(s(i:i)==t(i:i))then
        	ans=ans-1
        end if
    end do
    write(*,*)ans
    stop
end program main

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 prob57
    implicit none
    character(16) :: s,t
    integer :: i, c
    read(*,*) s
    t = 'CODEFESTIVAL2016'
    c = 0
    do i = 1, 16
        if(s(i:i) /= t(i:i)) then
            c = c + 1
        end if
    end do
    write(*,*) c
    stop
contains
end program prob57