program main
	implicit none
	real*8 c
	integer h,n,w
	read(*,*)c
	c=4/c
	do h=1,3500
		do n=h,3500
			do w=n,3500
				if(abs(c-(1/real(n)+1/real(h)+1/real(w)))<=0.000001)goto 10
			enddo
		enddo
	enddo
10 write(*,*)h,n,w
end program main

Score : 300 points

Problem Statement

You are given an integer N.

Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.

If there are multiple solutions, any of them will be accepted.

Constraints

It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.

Inputs

Input is given from Standard Input in the following format:

N

Outputs

Print a triple of positive integers h, n and w that satisfies the condition, in the following format:

h n w

Sample Input 1

2

Sample Output 1

1 2 2

4/2 = 1/1 + 1/2 + 1/2.

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

It is allowed to use an integer exceeding 3500 in a solution.

Sample Input 3

4664

Sample Output 3

3498 3498 3498


character(4) S
read*,S
print"(A)",merge("Yes"," No",S=="YAKI")
end

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

Score : 100 points

Problem Statement

Ringo is giving a present to Snuke.

Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes grilled things starting with YAKI in Japanese, and does not like other things.

You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with YAKI.

Constraints

1 \leq |S| \leq 10

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S starts with YAKI, print Yes; otherwise, print No.

Sample Input 1

YAKINIKU

Sample Output 1

Yes

YAKINIKU starts with YAKI.

Sample Input 2

TAKOYAKI

Sample Output 2

No

TAKOYAKI (a Japanese snack. tako: octopus) does not start with YAKI.

Sample Input 3

YAK

Sample Output 3

No

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 prob6
    implicit none
    integer::H, W, i, j, tmp
    character(len=100)::S
    integer::c(26)
    read(*,*) H, W
    c = 0
    do i = 1, H
        read(*,*) S
        do j = 1, W
            tmp = ichar(S(j:j)) - ichar('a') + 1
            c(tmp) = c(tmp) + 1
        end do
    end do
    if(mod(H*W,2) == 0) then
    	tmp = 0
        do i = 1, 26
            if(mod(c(i),2) == 1) then
                write(*,'(a)') "No"
                stop
            else
            	tmp = tmp + 1
            end if
        end do
        if(mod(tmp,2) == 0) then
        	write(*,'(a)') "No"
         	stop
        end if
    else
        tmp = 0
        do i = 1, 26
            if(mod(c(i),2) == 1) then
                tmp = tmp + 1
            end if
        end do
        if(tmp /= 1) then
            write(*,'(a)') "No"
        end if
    end if
    write(*,'(a)') "Yes"
    stop
end program

Score : 400 points

Problem Statement

We have an H-by-W matrix.
Let a_{ij} be the element at the i-th row from the top and j-th column from the left.
In this matrix, each a_{ij} is a lowercase English letter.

Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A.
Here, he wants to satisfy the following condition:

Every row and column in A' can be read as a palindrome.

Determine whether he can create a matrix satisfying the condition.

Note

A palindrome is a string that reads the same forward and backward.
For example, a, aa, abba and abcba are all palindromes, while ab, abab and abcda are not.

Constraints

1 ≤ H, W ≤ 100

a_{ij} is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}

Output

If Snuke can create a matrix satisfying the condition, print Yes; otherwise, print No.

Sample Input 1

3 4
aabb
aabb
aacc

Sample Output 1

Yes

For example, the following matrix satisfies the condition.

abba
acca
abba

Sample Input 2

2 2
aa
bb

Sample Output 2

No

It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in A.

Sample Input 3

5 1
t
w
e
e
t

Sample Output 3

Yes

For example, the following matrix satisfies the condition.

t
e
w
e
t

Sample Input 4

2 5
abxba
abyba

Sample Output 4

No

Sample Input 5

1 1
z

Sample Output 5

Yes


program sample
    implicit none

    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:)

    read(*,*) n

    read(*,*) k
    if (n==1)then
        read(*,*)a
        write(*,*) n-abs(n-2*a)
        stop
    end if
    allocate(x(k))
    read(*,*) x
    m=0
    do i=1,k
        m=m+n-abs(n-2*x(i))
    end do
    write(*,*)m
    deallocate(x)
    stop
end program sample

Score : 200 points

Problem Statement

There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.

In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.

When activated, each type of robot will operate as follows.

When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints

1 \leq N \leq 100

1 \leq K \leq 100

0 < x_i < K

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
K
x_1 x_2 ... x_N

Outputs

Print the minimum possible total distance covered by robots.

Sample Input 1

1
10
2

Sample Output 1

4

There are just one ball, one type-A robot and one type-B robot.

If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.

Similarly, if the type-B robot is used, the total distance covered will be 16.

Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.

Sample Input 2

2
9
3 6

Sample Output 2

12

The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.

Sample Input 3

5
20
11 12 9 17 12

Sample Output 3

74


program main
  implicit none

  integer :: n,k,x(100)=0,i,s=0
  read(*,*)n
  read(*,*)k
  read(*,*)(x(i),i=1,n)

  do i = 1, n
    s = s + 2*min(x(i), abs(x(i) - k))
  end do

  write(*,*)s
end program main


INTEGER N,K,A
INTEGER,ALLOCATABLE,DIMENSION(:)::X
READ*,N,K
ALLOCATE(X(N))
READ*,X
A=0
DO I=1,N
  A=A+MIN(K-X(I),X(I))*2
END DO
PRINT"(I0)",A
END


implicit none
integer :: a,b,c,d,e,f,n_a,i,j,k,l,S
double precision :: youeki, yousitu,noudo,Li,T

read(5,*) a,b,c,d,e,f
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))

do i=0, 3+n_a
do j=0, 3+int((f-100*i*a)/(100*b))
do k=0, 3+int((f-100*i*a-100*j*b-k*c)/d)
do l=0, 3+int((f-100*i*a-100*j*b-k*c)/d)
    S=100*a*i+100*b*j+c*k+d*l
    T=c*k+d*l
    if (S/=0) then
        Li=100.0*T/S
        if (S<=f .and. Li<=100.0*e/(100.0+e) .and. Li>=noudo) then
          noudo=Li
          youeki=S
          yousitu=T
        endif
    endif

end do
end do
end do
end do

write(6,'(i0," "i0)') int(youeki),int(yousitu)
end

Score : 300 points

Problem Statement

Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.

Operation 1: Pour 100A grams of water into the beaker.

Operation 2: Pour 100B grams of water into the beaker.

Operation 3: Put C grams of sugar into the beaker.

Operation 4: Put D grams of sugar into the beaker.

In our experimental environment, E grams of sugar can dissolve into 100 grams of water.

Snuke will make sugar water with the highest possible density.

The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.

We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

A, B, C, D, E and F are all integers.

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.

We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:

If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.

If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934


implicit none
integer :: a,b,c,d,e,f,n_a,i,j,k,l
double precision :: youeki, yousitu,noudo,Li,S,T

read(5,*) a,b,c,d,e,f
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))

do i=0, 3+n_a
do j=0, 3+int((f-100*i*a)/(100*b))
do k=0, 3+int((f-100*i*a-100*j*b-k*c)/d)
do l=0, 3+int((f-100*i*a-100*j*b-k*c)/d)
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if (S/=0) then
        Li=100.0*T/S
        if (S<=f .and. Li<=100.0*e/(100.0+e) .and. Li>=noudo) then
          noudo=Li
          youeki=S
          yousitu=T
        endif
    endif

end do
end do
end do
end do

write(6,'(i0," "i0)') int(youeki),int(yousitu)
end


integer(16)N
integer(16),allocatable,dimension(:)::A
integer(16)tmp,tmpcnt,ans
read*,N
allocate(A(N))
do i=1,N
  read*,A(i)
end do
call heapsort(N,A)
tmp=0;tmpcnt=0;ans=0
do i=1,N
  if(A(i)==tmp)then
    tmpcnt=xor(tmpcnt,1)
  else
    ans=ans+tmpcnt
    tmp=A(i)
    tmpcnt=1
   endif
end do
ans=ans+tmpcnt
print"(i0)",ans
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

Score : 300 points

Problem Statement

You are playing the following game with Joisino.

Initially, you have a blank sheet of paper.

Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.

Then, you are asked a question: How many numbers are written on the sheet now?

The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Constraints

1≤N≤100000

1≤A_i≤1000000000(=10^9)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print how many numbers will be written on the sheet at the end of the game.

Sample Input 1

3
6
2
6

Sample Output 1

1

The game proceeds as follows:

6 is not written on the sheet, so write 6.

2 is not written on the sheet, so write 2.

6 is written on the sheet, so erase 6.

Thus, the sheet contains only 2 in the end. The answer is 1.

Sample Input 2

4
2
5
5
2

Sample Output 2

0

It is possible that no number is written on the sheet in the end.

Sample Input 3

6
12
22
16
22
18
12

Sample Output 3

2


program main
    integer :: N,M,R,a,b,c
    integer :: rr(8)
    integer :: g(200,200)
    logical :: used(8)
    integer, parameter :: INF = 100000000
    integer :: ans
    common g, R, rr, ans
    ans = INF
    do i=1,200
        do j=1,200
            g(i,j) = INF
        end do
    end do
    do i=1,8
        used(i) = .false.
    end do

    read *, N,M,R

    read *, (rr(i), i=1,R)

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

    do i = 1,N
        do j=1,N
            do k=1,N
                if(g(j,k) > g(j,i)+g(i,k) ) then
                    g(j,k) = g(j,i) + g(i,k)
                end if
            end do
        end do
    end do

    call dfs(0, 1, -1)

    print *, ans

contains
    recursive subroutine dfs(dist, c, now_pos)
        integer :: dist, c, now_pos
        integer :: R, ans
        integer :: rr(8)
        logical :: used(8)
        integer :: g(200,200)
        common g, R, rr, ans, used
        if(now_pos == R) then
            if(ans > dist) then
                ans = dist
            end if
        else
            do i=1,8
                if(used(i) .eqv. .false.) then
                    used(i) = .true.
                    if(now_pos == -1) then
                        call dfs(0, c, rr(i))
                    else
                        call dfs(dist + g(now_pos, rr(i)), c+1, rr(i))
                    end if
                    used(i) = .false.
                end if
            end do
        end if
    end subroutine dfs
end program main

Score : 400 points

Problem Statement

There are N towns in the State of Atcoder, connected by M bidirectional roads.

The i-th road connects Town A_i and B_i and has a length of C_i.

Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).

She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.

If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?

Constraints

2≤N≤200

1≤M≤N×(N-1)/2

2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)

r_i≠r_j (i≠j)

1≤A_i,B_i≤N, A_i≠B_i

(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)

1≤C_i≤100000

Every town can be reached from every town by road.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M R
r_1 ... r_R
A_1 B_1 C_1
:
A_M B_M C_M

Output

Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.

Sample Input 1

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

Sample Output 1

2

For example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.

Sample Input 2

3 3 2
1 3
2 3 2
1 3 6
1 2 2

Sample Output 2

4

The shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4.

Sample Input 3

4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6

Sample Output 3

3


integer a,b
read*,a,b
print"(i0)",max(0,a-b)
end

Score : 100 points

Problem Statement

We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.

How many grams of sand will the upper bulb contains after t seconds?

Constraints

1≤X≤10^9

1≤t≤10^9

X and t are integers.

Input

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

X t

Output

Print the number of sand in the upper bulb after t second.

Sample Input 1

100 17

Sample Output 1

83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

Sample Input 2

48 58

Sample Output 2

0

All 48 grams of sand will be gone, resulting in 0 grams.

Sample Input 3

1000000000 1000000000

Sample Output 3

0


program main
	implicit none
	integer X, t
	read(*, *) X, t
	if(X <= t) then
		write(*, *) 0
	else
		write(*, *) X - t
	end if
end program main


program main
    integer :: x, t

    read *, x, t
    if (x - t >= 0) then
        print *, x-t
    else
        print *, '0'
    end if
end program main


implicit none
integer::a,b
read(5,*) a,b

write(6,*) max(0,a-b)

end


program odd_string
  implicit none
  character(100000) :: s
  integer           :: n, i
  read(*,*) s
  s = adjustl(s)
  n = len_trim(s)
  do i = 1, n, 2
    write(*,'(a)',advance='no') s(i:i)
  end do
  write(*,*)
end program odd_string

Score : 200 points

Problem Statement

You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.

Constraints

Each character in s is a lowercase English letter.

1≤|s|≤10^5

Input

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

s

Output

Print the string obtained by concatenating all the characters in the odd-numbered positions.

Sample Input 1

atcoder

Sample Output 1

acdr

Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.

Sample Input 2

aaaa

Sample Output 2

aa

Sample Input 3

z

Sample Output 3

z

Sample Input 4

fukuokayamaguchi

Sample Output 4

fkoaaauh


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i, ans
    integer(int32), allocatable:: a(:), numc(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    allocate(numc(0:maxval(a)), source=0)
    do i=1,n
        numc(a(i)) = numc(a(i)) + 1
    end do
    ans=0

    do i=1,ubound(numc,1)-1
        ans=max(ans,sum(numc(i-1:i+1)))
    end do

    print*, ans
end program name

Score : 300 points

Problem Statement

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

1≤N≤10^5

0≤a_i<10^5 (1≤i≤N)

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 maximum possible number of i such that a_i=X.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i, ans
    integer(int32), allocatable:: a(:), numc(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    allocate(numc(0:maxval(a)), source=0)
    do i=1,n
        numc(a(i)) = numc(a(i)) + 1
    end do
    ans=0

    do i=1,ubound(numc,1)-2
        ans=max(ans,sum(numc(i-1:i+1)))
    end do

    print*, ans
end program name


program prob4
    implicit none
    integer::N, i, ans, mode
    integer, allocatable::p(:)
    read(*,*) N
    allocate(p(N))
    read(*,*) p
    ans = 0
    mode = 0
    do i = 2, N
        if(i > 1 .and. p(i) == i .and. p(i-1) == i-1) then
            if(mode == 0) then
                ans = ans + 1
                mode = 1
            else
                mode = 0
            end if
        else if(p(i) == i) then
            ans = ans + 1
            mode = 0
        end if
    end do
    if(p(1) == 1 .and. p(2) /= 2) then
        ans = ans + 1
    end if
    write(*,*) ans
    deallocate(p)
    stop
end program

Score : 400 points

Problem Statement

You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.
You can perform the following operation any number of times (possibly zero):

Operation: Swap two adjacent elements in the permutation.

You want to have p_i ≠ i for all 1≤i≤N.
Find the minimum required number of operations to achieve this.

Constraints

2≤N≤10^5

p_1,p_2,..,p_N is a permutation of 1,2,..,N.

Input

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

N
p_1 p_2 .. p_N

Output

Print the minimum required number of operations

Sample Input 1

5
1 4 3 5 2

Sample Output 1

2

Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition.
This is the minimum possible number, so the answer is 2.

Sample Input 2

2
1 2

Sample Output 2

1

Swapping 1 and 2 satisfies the condition.

Sample Input 3

2
2 1

Sample Output 3

0

The condition is already satisfied initially.

Sample Input 4

9
1 2 4 9 5 8 7 3 6

Sample Output 4

3


program sample
    implicit none

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

    read(*,*) n
    allocate(x(n))
    read(*,*)x
    a=0
    m=0
    do i=1,n
        if(x(i)==i)then
            if(a==0)then
                a=1
            else
                a=0
                m=m+1
            end if
        elseif(a==1)then
            a=0
            m=m+1
        end if
    end do
    if(a==1)then
        m=m+1
    end if

    write(*,*) m

    stop
end program sample


program derangement
  implicit none
  integer :: n, a(100000), i, b(100000), m
  a = 0
  b = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    b(i) = 1
    if (a(i).eq.i) then
      b(i) = -1
    end if
  end do
  m = 0
  do i = 1, n-1
    if (b(i).lt.0) then
      b(i) = 1
      b(i+1) = 1
      m = m + 1
    end if
  end do
  write(*,'(i0)') m
  stop
end program derangement


program main
	implicit none
	integer(8) :: Q, H, S, D, N

	read(*, *) Q, H, S, D
	read(*, *) N

	if(mod(N,2) == 0) then
		Q = 8*Q
		H = 4*H
		S = 2*S
		write(*, *) N/2 * min(Q,H,S,D)
	else
		Q = min(2*H,4*Q,S)
		write(*, *) min(N*Q,N/2 * D+Q)
	end if
end program main

Score : 300 points

Problem Statement

You've come to your favorite store Infinitesco to buy some ice tea.

The store sells ice tea in bottles of different volumes at different costs.
Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.
The store has an infinite supply of bottles of each type.

You want to buy exactly N liters of ice tea. How many yen do you have to spend?

Constraints

1 \leq Q, H, S, D \leq 10^8

1 \leq N \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

Q H S D
N

Output

Print the smallest number of yen you have to spend to buy exactly N liters of ice tea.

Sample Input 1

20 30 70 90
3

Sample Output 1

150

Buy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.

Sample Input 2

10000 1000 100 10
1

Sample Output 2

100

Even though a 2-liter bottle costs just 10 yen, you need only 1 liter.
Thus, you have to buy a 1-liter bottle for 100 yen.

Sample Input 3

10 100 1000 10000
1

Sample Output 3

40

Now it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.

Sample Input 4

12345678 87654321 12345678 87654321
123456789

Sample Output 4

1524157763907942


program sample
    implicit none

    integer(8) :: i,j,m,n
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)

    read(*,*) n,i,j
    if (abs(n-i)>abs(n-j) )then
        write(*,*) j
    else
        write(*,*) i
    end if

    stop
end program sample

Score : 100 points

Problem Statement

Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer to Snuke's residence.

Here, the distance between two points s and t on a number line is represented by |s-t|.

Constraints

1 \leq x \leq 1000

1 \leq a \leq 1000

1 \leq b \leq 1000

x, a and b are pairwise distinct.

The distances between Snuke's residence and stores A and B are different.

Input

Input is given from Standard Input in the following format:

x a b

Output

If store A is closer, print A; if store B is closer, print B.

Sample Input 1

5 2 7

Sample Output 1

B

The distances between Snuke's residence and stores A and B are 3 and 2, respectively.
Since store B is closer, print B.

Sample Input 2

1 999 1000

Sample Output 2

A


program main
	implicit none
    integer::x,a,b
    read(*,*) x,a,b

    if (abs(x-a)>abs(x-b))then
    	write(*,*) 'B'
    else
    	write(*,*) 'A'
    end if
    stop
end program main


program main
    integer n
    integer :: a(10**5)
    integer, allocatable :: str_a(:)
    integer, allocatable :: ans(:)
    integer(8) :: first=0, second=0
    integer(8) :: answer
    integer restart

    read *, n
    read *, (a(i), i=1,n)
    str_a = a(1:n)
    ans = quick(str_a)

    do i=1,n-1
        if(ans(i)==ans(i+1)) then
            first = ans(i)
            restart = i+2
            exit
        end if
    end do

    if (result < n) then
        do i=restart,n-1
            if(ans(i)==ans(i+1)) then
                second = ans(i)
                exit
            end if
        end do
    end if

    answer = first * second
    print *, answer

contains
    recursive function quick(a) result(r)
        integer, intent(in) :: a(:)
        integer, allocatable :: r(:)
        integer :: p
        if(size(a) < 2) then
            r = a
        else
            p = a(1)
            r = [quick(pack(a(2:), a(2:) > p)), pack(a, a == p), quick(pack(a(2:), a(2:) < p))]
        end if
    end function quick
end program main

Score : 300 points

Problem Statement

We have N sticks with negligible thickness.
The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20


program main
    integer n
    integer :: a(10**5)
    integer, allocatable :: str_a(:)
    integer, allocatable :: ans(:)
    integer :: first=0, second=0
    integer(8) :: answer
    integer restart

    read *, n
    read *, (a(i), i=1,n)
    str_a = a(1:n)
    ans = quick(str_a)

    do i=1,n-1
        if(ans(i)==ans(i+1)) then
            first = ans(i)
            restart = i+2
            exit
        end if
    end do

    if (result < n) then
        do i=restart,n-1
            if(ans(i)==ans(i+1)) then
                second = ans(i)
                exit
            end if
        end do
    end if

    print *, ans
    answer = first * second
    print *, answer

contains
    recursive function quick(a) result(r)
        integer, intent(in) :: a(:)
        integer, allocatable :: r(:)
        integer :: p
        if(size(a) < 2) then
            r = a
        else
            p = a(1)
            r = [quick(pack(a(2:), a(2:) > p)), pack(a, a == p), quick(pack(a(2:), a(2:) < p))]
        end if
    end function quick
end program main


program rec
	implicit none
    integer :: n, i,j,c1,c2
    integer(8),allocatable :: a(:)
    integer(8) :: l1, l2, s1, s2
    logical :: status
    read(*,*) n
    allocate(a(n))
    read(*,*) a
    call heapsort(a)

    s1 = 0
    s2 = 0
    c1 = n
    do i = n - 1, 1, -1
    	l1 = a(i)
        l2 = a(i+1)
    	if(l1 == l2) then
        	s1 = l1
        	c1 = i
        	exit
        else
        	l1 = a(i)
            l2 = a(i-1)
        end if
    end do
    do i = c1 - 2, 1, -1
    	l1 = a(i)
        l2 = a(i+1)
    	if(l1 == l2) then
        	s2 = l1
        	c1 = i
        	exit
        else
        	l1 = a(i)
            l2 = a(i-1)
        end if
    end do

    write(*,*) s1*s2

	stop
contains
	subroutine heapsort(array)
    implicit none
    integer(8):: array(:)
    integer ::i,k,j,l
    integer(8) :: t

    n=size(array)

    if (n==1) then
       return
    end if

    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 == 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
       end do
       array(i)=t
    end do
    return
  end subroutine heapsort

end program rec


program main
  implicit none

  integer :: n, i, cnt
  integer(16) :: ans
  integer(16), allocatable :: a(:)

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

  ans = 0
  cnt = 0
  read(*,*) a
  call quicksort(a, 1, n)
  do i = n, 2, -1
     if(a(i) == a(i-1)) then
        ans = a(i)
        cnt = i
        exit
     end if
  end do

  do i = cnt-2, 2, -1
     if(a(i) == a(i-1)) then
        ans = ans * a(i)
        exit
     end if
     if(i == 2) then
        ans = 0
     end if

  end do

  write(*,*) ans

  stop

contains
  recursive subroutine quicksort(a, first, last)
    implicit none
    integer(16) ::  a(*)
    integer :: first, last
    integer :: i, j
    integer ::  x, t

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

end program main


program prob1
    implicit none
    integer::i, j
    character(len=3)::x
    read(*,*) x
    if(x(1:1) .eq. x(3:3)) then
        write(*,'(a)') "Yes"
    else
        write(*,'(a)') "No"
    end if
    stop
end program

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

Constraints

100≤N≤999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a palindromic number, print Yes; otherwise, print No.

Sample Input 1

575

Sample Output 1

Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

Sample Input 2

123

Sample Output 2

No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

Sample Input 3

812

Sample Output 3

No


program main
    use,intrinsic :: iso_fortran_env
    implicit none
    character(3):: n

    read*, n

    if (n(1:1)==n(3:3)) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if

end program main


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

    read(*,*) n
    allocate(x(n))
    do i=1,n
    read(*,*)x(i)
    end do
    a=x(1)
    m=a
    do i=2,n
        b=max(a,x(i))
        a=min(a,x(i))
        do j=1,1000000000
            if(mod(b,a)==0)then
                exit
            else
                c=mod(b,a)
                b=a
                a=c
            end if
        end do
        m=m*(x(i)/a)
        a=m
    end do

    write(*,*)m
    stop
end program sample

Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

The correct answer is at most 10^{18} seconds.

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3

Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:

Clock 1: 2, 4, 6, ... seconds after the beginning

Clock 2: 3, 6, 9, ... seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000


program prob4
    implicit none
    integer::n, i
    integer(16)::t, ans, a, b, c
    read(*,*) n
    read(*,*) t
    ans = t
    do i = 2, n
        read(*,*) t
        a = ans
        b = t
        c = mod(a,b)
        do while(c > 0)
            a = b
            b = c
            c = mod(a,b)
        end do
        ans = ans/b*t
    end do
    write(*,*) ans
    stop
end program


program main
	implicit none
	integer i,n
	integer(8)t(100),a,b,x
	read(*,*)n
	do i=1,n
		read(*,*)t(i)
	enddo
	if(n==1)then
		write(*,*)t(1)
	else
		a=t(1)
		b=t(2)
		do i=1,n-1
			x=a/euc(a,b)*b
			a=x
			b=t(i+2)
		enddo
		write(*,'(i0)')x
	endif
contains
function euc(a,b)
	integer*8 a,b,x,euc
	if(a<b)then
		x=a
		a=b
		b=x
	endif
	do
		x=mod(a,b)
		if(x==0)exit
		a=b
		b=x
	enddo
	euc=b
end function
end program main


program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m

    read*, n,m
    print'(i0)', (n-1)*(m-1)

end program main

Score : 100 points

Problem Statement

In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

Constraints

2 ≤ n, m ≤ 100

Input

Input is given from Standard Input in the following format:

n m

Output

Print the number of blocks in K-city.

Sample Input 1

3 4

Sample Output 1

6

There are six blocks, as shown below:

Sample Input 2

2 2

Sample Output 2

1

There are one block, as shown below:


program name

    implicit none
    character(len=3) num_char
    read*, num_char
    print*, "ABC"//num_char

end program

Score : 100 points

Problem Statement

This contest, AtCoder Beginner Contest, is abbreviated as ABC.

When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.

What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

Constraints

100 ≤ N ≤ 999

Input

Input is given from Standard Input in the following format:

N

Output

Print the abbreviation for the N-th round of ABC.

Sample Input 1

100

Sample Output 1

ABC100

The 100th round of ABC is ABC100.

Sample Input 2

425

Sample Output 2

ABC425

Sample Input 3

999

Sample Output 3

ABC999


program test
	implicit none
	integer n, k
	read *, n
	k = 2
	do while (k<=n)
		k = k*2
	end do
	print '(i0)', k/2
end program test

Score : 200 points

Problem Statement

Takahashi loves numbers divisible by 2.

You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.

Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.

For example,

6 can be divided by 2 once: 6 -> 3.

8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.

3 can be divided by 2 zero times.

Constraints

1 ≤ N ≤ 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

7

Sample Output 1

4

4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.

Sample Input 2

32

Sample Output 2

32

Sample Input 3

1

Sample Output 3

1

Sample Input 4

100

Sample Output 4

64


program abc068c
  implicit none
  integer n, m, a, b, i
  logical,allocatable :: x(:), y(:)

  read *, n,m
  allocate(x(n),y(n))

  x = .false.
  y = .false.

  do i = 1,m
     read *, a,b
     if (a == 1) x(b) = .true.
     if (b == n) y(a) = .true.
  end do

  if (count(x.and.y) > 0) then
     print *, 'POSSIBLE'
  else
     print *, 'IMPOSSIBLE'
  end if
end program abc068c

Score : 300 points

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.

Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

3 ≤ N ≤ 200 000

1 ≤ M ≤ 200 000

1 ≤ a_i < b_i ≤ N

(a_i, b_i) \neq (1, N)

If i \neq j, (a_i, b_i) \neq (a_j, b_j).

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

POSSIBLE

Sample Input 2

4 3
1 2
2 3
3 4

Sample Output 2

IMPOSSIBLE

You have to use three boat services to get to Island 4.

Sample Input 3

100000 1
1 99999

Sample Output 3

IMPOSSIBLE

Sample Input 4

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

Sample Output 4

POSSIBLE

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.


integer N,M
integer,allocatable,dimension(:,:)::A
logical,allocatable,dimension(:)::SPORTS
integer,allocatable,dimension(:)::CONTESTANTS
integer ans,preans
read*,N,M
allocate(A(N,M))
do i=1,N
  read*,A(i,:)
end do

allocate(SPORTS(M),CONTESTANTS(M))
SPORTS=.TRUE.

ans=huge(ans)

do i=1,M
  CONTESTANTS=0
  do j=1,N
    do k=1,M
      if(SPORTS(A(j,k)))then
        CONTESTANTS(A(j,k))=CONTESTANTS(A(j,k))+1
        exit
      endif
    end do
  end do
  preans=maxval(CONTESTANTS)
  do j=1,M
    if(CONTESTANTS(j)==preans)then
      SPORTS(j)=.FALSE.
      exit
    endif
  end do
  ans=min(ans,preans)
end do

print"(I0)",ans

end

Score : 700 points

Problem Statement

Takahashi is hosting an sports meet.
There are N people who will participate. These people are conveniently numbered 1 through N.
Also, there are M options of sports for this event. These sports are numbered 1 through M.
Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.

Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}.
Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.

Takahashi is worried that one of the sports will attract too many people.
Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.
Find the minimum possible number of the participants in the sport with the largest number of participants.

Constraints

1 \leq N \leq 300

1 \leq M \leq 300

A_{i1} , A_{i2} , ... , A_{iM} is a permutation of the integers from 1 to M.

Input

Input is given from Standard Input in the following format:

N M
A_{11} A_{12} ... A_{1M}
A_{21} A_{22} ... A_{2M}
:
A_{N1} A_{N2} ... A_{NM}

Output

Print the minimum possible number of the participants in the sport with the largest number of participants.

Sample Input 1

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

Sample Output 1

2

Assume that Sports 1, 3 and 4 are selected to be played. In this case, Person 1 will participate in Sport 1, Person 2 in Sport 3, Person 3 in Sport 3 and Person 4 in Sport 4.
Here, the sport with the largest number of participants is Sport 3, with two participants.
There is no way to reduce the number of participants in the sport with the largest number of participants to 1. Therefore, the answer is 2.

Sample Input 2

3 3
2 1 3
2 1 3
2 1 3

Sample Output 2

3

Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.
Therefore, the answer is 3.


program ringring
  implicit none
  integer :: n(3)
  read(*,*) n(:)
  write(*,'(i0)') sum(n)-maxval(n)
end program ringring

Score : 100 points

Problem Statement

Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.

He has very high awareness of safety, and decides to buy two bells, one for each hand.

The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.
Find the minimum total price of two different bells.

Constraints

1 \leq a,b,c \leq 10000

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print the minimum total price of two different bells.

Sample Input 1

700 600 780

Sample Output 1

1300

Buying a 700-yen bell and a 600-yen bell costs 1300 yen.

Buying a 700-yen bell and a 780-yen bell costs 1480 yen.

Buying a 600-yen bell and a 780-yen bell costs 1380 yen.

The minimum among these is 1300 yen.

Sample Input 2

10000 10000 10000

Sample Output 2

20000

Buying any two bells costs 20000 yen.


program name
    implicit none
    integer(4):: n,i,ans
    character(200):: s

    read*, s(:)
    n = len_trim(s)
    ans = 0
    do i=1,n/2-1
        if (s(1:i) == s(i+1:2*i)) ans=max(ans,i)
    end do
    print*, ans*2
end program name

Score : 200 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

You are given an even string S consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S.
It is guaranteed that such a non-empty string exists for a given input.

Constraints

2 \leq |S| \leq 200

S is an even string consisting of lowercase English letters.

There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the length of the longest even string that can be obtained.

Sample Input 1

abaababaab

Sample Output 1

6

abaababaab itself is even, but we need to delete at least one character.

abaababaa is not even.

abaababa is not even.

abaabab is not even.

abaaba is even. Thus, we should print its length, 6.

Sample Input 2

xxxx

Sample Output 2

2

xxx is not even.

xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

The longest even string that can be obtained is abcabc, whose length is 6.

Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

The longest even string that can be obtained is akasakaakasaka, whose length is 14.


program ABC066B
    implicit none
    integer(8)::i
    integer(8)::result=0
    character(200)::S
    read(5,*)S

    do i=1,len_trim(S)/2-1
        if(S(1:i)==S(i+1:2*i))then
            if(i>result)then
                result=i
            end if
        end if
    end do

    print'(i0)',2*result
end program ABC066B


program main
	implicit none
	integer i, counter
	character(200) S
	read(*, *) S
	counter = 0
	do i = 2, len_trim(S)-2
		if(S(1:(len_trim(S)-i)/2) == S(1+(len_trim(S)-i)/2:len_trim(S)-i)) then
			write(*, *) len_trim(S)-i
			counter = 1
			exit
		end if
	end do
	if(counter == 0) then
		write(*, *) 1
	end if
end program main


program name

    implicit none
    integer X,A,B
    read*, X,A,B
    if ( B-A<0 ) then
        print*, "delicious"
    else
        if ( B-A<=X ) then
            print*, "safe"
        else
            print*, "dangerous"
        end if
    end if

end program

Score : 100 points

Problem Statement

Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.

Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.

Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.

Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

Constraints

1 ≤ X,A,B ≤ 10^9

Input

Input is given from Standard Input in the following format:

X A B

Output

Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

Sample Input 1

4 3 6

Sample Output 1

safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.

Sample Input 2

6 5 1

Sample Output 2

delicious

He ate the food by the "best-by" date. It was delicious for him.

Sample Input 3

3 7 12

Sample Output 3

dangerous

He ate the food five days after the "best-by" date. It was harmful for him.


read*,i,j,k
i = j*10+k

if( mod(i,4)==0 )then
  print*,'YES'
else
  print*,'NO'
end if
end

Score : 100 points

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.

An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.

We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.

Is this integer a multiple of 4?

Constraints

1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

Sample Input 1

4 3 2

Sample Output 1

YES

432 is a multiple of 4, and thus YES should be printed.

Sample Input 2

2 3 4

Sample Output 2

NO

234 is not a multiple of 4, and thus NO should be printed.


module ABC064

	! <module>s to import
	use, intrinsic :: iso_fortran_env

	! require all variables to be explicitly declared
	implicit none

	! accessibility of <subroutine>s and <function>s in this <module>
	public  :: ABC064_A

	! contained <subroutine>s and <function>s are below
	contains

	subroutine ABC064_A

		! variables for this <subroutine>
		character( len=3, kind=1 ) :: stat
		integer( kind= INT16 )     :: r, g, b, target

		! STEP.01
		! read out the target positive integers
		read *, r, g, b

		! STEP.02
		! judge whether the target integer is the multiplie of 4 or not
		if( mod( 10*((10*r)+g)+b, 4 ) .eq. 0 ) then
			stat = 'YES'
		else
			stat = 'NO'
		end if

		! STEP.03
		! output the result
		write( unit=OUTPUT_UNIT, fmt='(A)', advance='yes' ) trim( stat )

		! STEP.END
		return

	end subroutine ABC064_A

end module ABC064

program main

	! <module>s to import
	use, non_intrinsic :: ABC064

	! require all variables to be explicitly declared
	implicit none

	call ABC064_A

end program main


program abc064c
  logical :: color(0:7) = .false.
  integer :: n
  integer,dimension(:),allocatable :: a
  read *, n
  allocate(a(n))
  read *, a
  color(pack(a,a<3200)/400) = .true.
  print *, count(color), count(color)+count(a>=3200)
end program abc064c

Score : 300 points

Problem Statement

In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:

Rating 1-399 : gray

Rating 400-799 : brown

Rating 800-1199 : green

Rating 1200-1599 : cyan

Rating 1600-1999 : blue

Rating 2000-2399 : yellow

Rating 2400-2799 : orange

Rating 2800-3199 : red

Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.

Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.

Find the minimum and maximum possible numbers of different colors of the users.

Constraints

1 ≤ N ≤ 100

1 ≤ a_i ≤ 4800

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

Sample Input 1

4
2100 2500 2700 2700

Sample Output 1

2 2

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.

Sample Input 2

5
1100 1900 2800 3200 3200

Sample Output 2

3 5

The user with rating 1100 is "green", the user with rating 1900 is blue and the user with rating 2800 is "red".

If the fourth user picks "red", and the fifth user picks "blue", there are three different colors. This is one possible scenario for the minimum number of colors.

If the fourth user picks "purple", and the fifth user picks "black", there are five different colors. This is one possible scenario for the maximum number of colors.

Sample Input 3

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

Sample Output 3

1 1

All the users are "green", and thus there is one color.


integer a,b
read*,a,b
if(a+b>=10)then
	print"(A)","error"
else
	print"(i0)",a+b
endif
end

Score : 100 points

Problem Statement

You are given two integers A and B as the input. Output the value of A + B.

However, if A + B is 10 or greater, output error instead.

Constraints

A and B are integers.

1 ≤ A, B ≤ 9

Input

Input is given from Standard Input in the following format:

A B

Output

If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

Sample Input 1

6 3

Sample Output 1

9

Sample Input 2

6 4

Sample Output 2

error


program prob2
    implicit none
    character(len=30)::s
    integer::c(26), i, l, tmp
    c = 0
    read(*,*) s
    l = len_trim(s)
    do i = 1, l
        tmp = ichar(s(i:i)) - ichar('a') + 1
        if(c(tmp) == 1) then
            write(*,'(a)') "no"
            stop
        else
        	c(tmp) = 1
        end if
    end do
    write(*,'(a)') "yes"
    stop
end program

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

Constraints

2 ≤ |S| ≤ 26, where |S| denotes the length of S.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If all the characters in S are different, print yes (case-sensitive); otherwise, print no.

Sample Input 1

uncopyrightable

Sample Output 1

yes

Sample Input 2

different

Sample Output 2

no

Sample Input 3

no

Sample Output 3

yes


program varied
  implicit none
  character(26) :: s
  integer       :: n, i, m(26), c
  read(*,*) s
  s = adjustl(s)
  n = len_trim(s)
  m = 0
  do i = 1, n
    c = ichar(s(i:i)) - 96
    m(c) = m(c) + 1
  end do
  if (maxval(m) > 1) then
    write(*,'(a)') "no"
  else
    write(*,'(a)') "yes"
  end if
end program varied


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

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

    call merge_sort(s,1,n)
    ss = sum(s)

    if (mod(ss,10) /= 0) then
        print*, ss
        stop
    end if

    do i=1,n
        if (mod(s(i),10) /= 0) then
            print*, ss-s(i)
            stop
        end if
    end do

    print*, 0
contains
    recursive subroutine merge_sort(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 swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(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 swap(x,y)
        integer(int32),intent(inout):: x,y
        integer(int32):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

Score : 300 points

Problem Statement

You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.

However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

Constraints

All input values are integers.

1 ≤ N ≤ 100

1 ≤ s_i ≤ 100

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the maximum value that can be displayed as your grade.

Sample Input 1

3
5
10
15

Sample Output 1

25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.

Sample Input 2

3
10
10
15

Sample Output 2

35

Your grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.

Sample Input 3

3
10
20
30

Sample Output 3

0

Regardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.


program bugged
implicit none
integer :: N
integer, allocatable, dimension(:, :) :: score
integer :: i, k
integer :: max_score

read *, N

allocate(score(N, 2))
do i = 1, N

    score(i, 1) = i
    read *, score(i, 2)

end do

call heap_sort(score, N)

do i = 1, N

    max_score = max_score + score(i, 2)

end do

k = 1
do while (mod(max_score, 10) == 0 .and. max_score > 0)

    max_score = max_score - score(k, 2)
    k = k + 1

end do

print '(I0)', max_score

end program bugged

! heap sort
subroutine heap_sort( list, n )
implicit none

integer :: n
integer, dimension( n, 2 ) :: list

integer :: i, k
integer, dimension( 2 ) :: temporary

do k = n/2, 1, -1

    temporary( 1 ) = list( k, 1 )
    temporary( 2 ) = list( k, 2 )

    call make_heap( n, list, k, n, temporary )

end do

do k = n, 2, -1

    temporary( 1 ) = list( k, 1 )
    temporary( 2 ) = list( k, 2 )

    list( k, 1 ) = list( 1, 1 )
    list( k, 2 ) = list( 1, 2 )

    call make_heap( n, list, 1, k-1, temporary )

end do

!-----------------------------------------------------------------------------------
contains
    subroutine make_heap( n, list, root, leaf, var )
    implicit none

    integer :: n, root, leaf
    integer, dimension( n, 2 ) :: list
    integer, dimension( 2 ) :: var

    ! local
    integer :: i, j

    i = root
    j = i * 2

    ! 条件を満たすまで無限ループ
    do
        if ( j > leaf ) exit

        if ( j < leaf ) then

            if ( list( j, 2 ) < list( j + 1, 2 ) ) j = j + 1

        end if

        if ( list( j, 2 )  >  var( 2 ) ) then

            list( i, 1 ) = list( j, 1 )
            list( i, 2 ) = list( j, 2 )

            i = j
            j = i * 2

        else

            j = leaf + 1

        endif

    end do

    list( i, 1 ) = var( 1 )
    list( i, 2 ) = var( 2 )

    end subroutine make_heap

!----------------------------------------------------------------------------------

end subroutine heap_sort


program mirrored
  implicit none
  integer :: d, n, x(0:10), i, j, k
  integer(8) :: b(0:18) = 1_8, ans = 0_8, v(0:10)
  read(*,*) d
  if (mod(d,9) /= 0) then
    write(*,'(i0)') 0
    stop
  end if
  do i = 1, 18
    b(i) = 10_8*b(i-1)
  end do
  d = d/9
  do i = 1, 18
    n = (i+1)/2
    x = 0
    v = 0_8
    do j = 0, n-1
      do k = j, i-j-1
        v(j) = v(j)+b(k)
      end do
    end do
    ans = ans+num(int(d,8),i,0,n,x(0:n-1),v(0:n-1))
  end do
  write(*,'(i0)') ans
  stop
contains
  recursive function num(d,l,t,n,x,v) result(ret)
    implicit none
    integer, intent(in) :: l, t, n
    integer, intent(inout) :: x(0:n-1)
    integer(8), intent(in) :: d
    integer(8), intent(inout) :: v(0:n-1)
    integer :: i
    integer(8) :: ret
    ret = 0_8
    if (t == n) then
      if (d /= 0) return
      ret = 1_8
      ret = ret*int(9-abs(x(0)),8)
      do i = 1, n-1
        ret = ret*int(10-abs(x(i)),8)
      end do
      if (mod(l,2) == 0) ret = ret*10_8
      return
    end if
    do i = -9, 9
      if (-v(t) < d+v(t)*int(i,8) .and. d+v(t)*int(i,8) < v(t)) then
        x(t) = i
        ret = ret+num(d+v(t)*int(i,8),l,t+1,n,x,v)
      end if
    end do
    return
  end function num
end program mirrored

Score : 800 points

Problem Statement

For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.

You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?

Constraints

D is an integer.

1 ≤ D < 10^9

Input

Input is given from Standard Input in the following format:

D

Output

Print the number of the positive integers N such that rev(N) = N + D.

Sample Input 1

63

Sample Output 1

2

There are two positive integers N such that rev(N) = N + 63: N = 18 and 29.

Sample Input 2

75

Sample Output 2

0

There are no positive integers N such that rev(N) = N + 75.

Sample Input 3

864197532

Sample Output 3

1920


Score : 100 points

Problem Statement

Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

Constraints

x and y are integers.

1 ≤ x < y ≤ 12

Input

Input is given from Standard Input in the following format:

x y

Output

If x and y belong to the same group, print Yes; otherwise, print No.

Sample Input 1

1 3

Sample Output 1

Yes

Sample Input 2

2 4

Sample Output 2

No


program main
 implicit none
  integer a,b,c,d
  b=0
  read*,a,b
  c=0
  if(a==1.or.a==3.or.a==5.or.a==7.or.a==8.or.a==10.or.a==12)c=c+1
  if(b==1.or.b==3.or.b==5.or.b==7.or.b==8.or.b==10.or.b==12)c=c+1
  if(c==2)print*,'Yes'
  d=0
  if(a==4.or.a==6.or.a==9.or.a==11)d=d+1

  if(b==4.or.b==6.or.b==9.or.b==11)d=d+1
  if(d==2)print*,'Yes'
  if(a==2.or.b==2) then
    print*,'No'
  else if (c==1.and.d==1)then
  print*,'No'
  end if
end program


Score : 100 points

Problem Statement

You are given three integers A, B and C.
Determine whether C is not less than A and not greater than B.

Constraints

-100≤A,B,C≤100

A, B and C are all integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

If the condition is satisfied, print Yes; otherwise, print No.

Sample Input 1

1 3 2

Sample Output 1

Yes

C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.

Sample Input 2

6 5 4

Sample Output 2

No

C=4 is less than A=6, and thus the output should be No.

Sample Input 3

2 2 2

Sample Output 3

Yes


program main
	implicit none
	integer(8) N, K, i, S
	integer(8), allocatable :: a(:), b(:)
	read(*, *) N, K
	allocate(a(1:N))
	allocate(b(1:N))
	do i = 1, N
		read(*, *) a(i), b(i)
	end do
	S = 0
	do i = 1, N
		S = S + b(i)
		if(K <= S) then
			write(*, *) a(i)
			exit
		end if
	end do
end program main

Score : 300 points

Problem Statement

There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

Constraints

1≤N≤10^5

1≤a_i,b_i≤10^5

1≤K≤b_1…+…b_n

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

The resulting array is the same as the one in the problem statement.

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1


program main
    implicit none
    integer:: n,m, i,j,k
    integer, allocatable:: a(:), b(:)
    integer(8), allocatable:: c(:), sc(:)
    integer(8):: inf = 1000000000
    logical, allocatable:: is_updated(:)

    read*, n, m
    allocate(a(m), b(m), c(m), sc(n),is_updated(n))

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

    sc(1:n)=-inf*2000000
    sc(1)=0

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
            end if
            ! print*, sc
        end do
    end do

    is_updated(1:n) = .false.

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
                is_updated(b(i)) = .true.
            end if
            if (is_updated(a(i)))then
                is_updated(b(i)) = .true.
            end if
            ! print*, sc
        end do
    end do

    if (is_updated(n)) then
        print*, 'inf'
    else
        print*, sc(n)
    end if

end program

Score : 400 points

Problem Statement

There is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.

Initially, the piece is placed at vertex 1, and the score of the player is set to 0.
The player can move the piece as follows:

When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.

The player can end the game only when the piece is placed at vertex N.
The given graph guarantees that it is possible to traverse from vertex 1 to vertex N.

When the player acts optimally to maximize the score at the end of the game, what will the score be?
If it is possible to increase the score indefinitely, print inf.

Constraints

2≤N≤1000

1≤M≤min(N(N-1),2000)

1≤a_i,b_i≤N (1≤i≤M)

a_i≠b_i (1≤i≤M)

a_i≠a_j or b_i≠b_j (1≤i<j≤M)

-10^9≤c_i≤10^9 (1≤i≤M)

c_i is an integer.

In the given graph, there exists a path from vertex 1 to vertex N.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print inf.

Sample Input 1

3 3
1 2 4
2 3 3
1 3 5

Sample Output 1

7

There are two ways to move the piece to vertex N=3:

vertex 1 → vertex 2 → vertex 3 : score 4+3=7

vertex 1 → vertex 3 : score 5

Thus, the maximum possible score at the end of the game is 7.

Sample Input 2

2 2
1 2 1
2 1 1

Sample Output 2

inf

It is possible to increase the score indefinitely by alternating between vertex 1 and 2.

Sample Input 3

6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000

Sample Output 3

-5000000000


program main
    implicit none
    integer(8):: inf = 1000000000
    integer(4):: n,m, i,j,k
    integer(8), allocatable:: a(:),b(:),c(:)
    integer(8), allocatable:: dist(:)

    read*, n, m
    allocate(a(m), b(m), c(m), dist(n))
    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    c = c*(-1)
    dist(1:n) = inf*1000
    ! print*, dist
    dist(1) = 0

    do j = 1, m
        do i = 1, m
            ! print*, dist(b(i)), dist(a(i)) + c(i)
            if (dist(b(i)) <= dist(a(i)) + c(i))cycle
            dist(b(i)) = dist(a(i)) + c(i)
            ! print*, dist
            if(j <= m-1) cycle
            print*, 'inf'
            stop
        end do
    end do

    print'(i0)', -1*dist(n)

end program


program main
    implicit none
    integer(4):: inf = 1000000000
    integer(4):: n,m, i,j,k
    integer(8), allocatable:: a(:),b(:),c(:)
    integer(kind=8), allocatable:: dist(:)

    read*, n, m
    allocate(a(m), b(m), c(m), dist(n))
    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    c = c*(-1)
    dist(1:n) = inf*10
    dist(1) = 0

    do j = 1, m
        do i = 1, m
            ! print*, dist(b(i)), dist(a(i)) + c(i)
            if (dist(b(i)) <= dist(a(i)) + c(i))cycle
            dist(b(i)) = dist(a(i)) + c(i)
            ! print*, dist
            if(j <= m-1) cycle
            print*, 'inf'
            stop
        end do
    end do

    print'(i0)', -1*dist(n)

end program


program main
    implicit none
    integer(4):: inf = 1000000000
    integer(4):: n,m, i,j,k
    integer(8), allocatable:: a(:),b(:),c(:)
    integer(kind=8), allocatable:: dist(:)

    read*, n, m
    allocate(a(m), b(m), c(m), dist(n))
    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    c = c*(-1)
    dist(1:n) = inf*10
    dist(1) = 0

    do j = 1, m
        do i = 1, m
            print*, dist(b(i)), dist(a(i)) + c(i)
            if (dist(b(i)) <= dist(a(i)) + c(i))cycle
            dist(b(i)) = dist(a(i)) + c(i)
            print*, dist
            if(j <= m-1) cycle
            print*, 'inf'
            stop
        end do
    end do

    print*, -dist(n)

end program


program prob3
    implicit none
    integer :: a,b,c,cnt,tmp1, tmp2
    read(*,*) a,b,c

    if(a == b .and. b == c) then
        write(*,'(a)') '-1'
        stop
    end if

    cnt = 0
    do while(mod(a,2) == 0 .and. mod(b,2) == 0 .and. mod(c,2) == 0)
        tmp1 = (a+b)/2
        tmp2 = (b+c)/2
        b = (c+a)/2
        c = tmp1
        a = tmp2
        cnt = cnt + 1
    end do

    write(*,'(i9)') cnt

    stop
contains
end program prob3

Score : 300 points

Problem Statement

Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:

Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.

This action will be repeated until there is a person with odd number of cookies in hand.

How many times will they repeat this action?
Note that the answer may not be finite.

Constraints

1 ≤ A,B,C ≤ 10^9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times the action will be performed by the three people, if this number is finite.
If it is infinite, print -1 instead.

Sample Input 1

4 12 20

Sample Output 1

3

Initially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,

After the first action, they have 16, 12 and 8.

After the second action, they have 10, 12 and 14.

After the third action, they have 13, 12 and 11.

Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.

Sample Input 2

14 14 14

Sample Output 2

-1

Sample Input 3

454 414 444

Sample Output 3

1


program geonowe
implicit none
integer :: a,b,c,i

read(*,*) a,b,c

do i = 1, b
	if ( mod(a*i,b) == c ) then
		write(*,'(a)') 'YES'
        stop
    end if
end do
write(*,'(a)') 'NO'
stop

end program geonowe

Score : 200 points

Problem Statement

We ask you to select some number of positive integers, and calculate the sum of them.

It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.

Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.

If the objective is achievable, print YES. Otherwise, print NO.

Constraints

1 ≤ A ≤ 100

1 ≤ B ≤ 100

0 ≤ C < B

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

7 5 1

Sample Output 1

YES

For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.

Sample Input 2

2 2 1

Sample Output 2

NO

The sum of even numbers, no matter how many, is never odd.

Sample Input 3

1 100 97

Sample Output 3

YES

You can select 97, since you may select multiples of 1, that is, all integers.

Sample Input 4

40 98 58

Sample Output 4

YES

Sample Input 5

77 42 36

Sample Output 5

NO


program sample
    implicit none

    integer(8) :: i,j,m,n,a,b,c
    integer(8),allocatable :: x(:),y(:)

    read(*,*) a,b,c
    do i=1,b
        if (mod(a*i,b)==c)then
            write(*,*)'YES'
            stop
        endif
    end do

    write(*,*) 'NO'

    stop
end program sample


program main
	implicit none
    integer A, B, C, S, i
	read(*, *) A, B, C
	S = 0
	do i = 1, 100000000
		S = S + A
		if(mod(S, B) == C) then
			write(*, *) 'YES'
			S = -1
			exit
		end if
	end do
	if(S /= -1) then
		write(*, *) 'NO'
	end if
end program main


program ABC060C
    implicit none
    integer(8)::N,T,i,result,ls,le
    integer(8),allocatable,dimension(:)::L
    read(5,*)N,T
    allocate(L(N))
    read(5,*)(L(i),i=1,N)
    result=0
    ls=L(1)
    le=L(1)

    if(N>=2)then
        do i=1,N-1
            if(L(i+1)-L(i)<=T)then
                le=L(i+1)
            else
                result=result+le-ls+T
                ls=L(i+1)
                le=L(i+1)
            end if
        end do
        result=result+le-ls+T
        print'(i0)',result
    else
        print'(i0)',T
    end if

end program ABC060C

Score : 300 points

Problem Statement

In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.

N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.

How long will the shower emit water in total?

Constraints

1 ≤ N ≤ 200,000

1 ≤ T ≤ 10^9

0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9

T and each t_i are integers.

Input

Input is given from Standard Input in the following format:

N T
t_1 t_2 ... t_N

Output

Assume that the shower will emit water for a total of X seconds. Print X.

Sample Input 1

2 4
0 3

Sample Output 1

7

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

Sample Input 2

2 4
0 5

Sample Output 2

8

One second after the shower stops emission of water triggered by the first person, the switch is pushed again.

Sample Input 3

4 1000000000
0 1000 1000000 1000000000

Sample Output 3

2000000000

Sample Input 4

1 1
0

Sample Output 4

1

Sample Input 5

9 10
0 3 5 7 100 110 200 300 311

Sample Output 5

67


integer(16) N,T
integer(16),allocatable,dimension(:)::times
integer(16) ans
read*,N,T
allocate(times(N))
read*,times
ans=0
do i=1,N-1
  ans=ans+min(T,times(i+1)-times(i))
end do
print"(i0)",ans+T
end


program ABC060C
    implicit none
    integer::n,t,i,ans = 0
    integer,allocatable::s(:)
    integer,allocatable::a(:)
    read*,n,t
    allocate(a(n))
    read*,a
    do i = 1,n-1
        if (a(i+1)-a(i) < t) then
            ans = ans + a(i+1)-a(i)
        else
            ans = ans + t
        end if
    end do
    print*,ans
end program ABC060C


module mod_segment_tree
  implicit none
  integer(8), parameter :: inf = 100000000000_8
  type t_segment_tree
    private
    integer(8) :: deflt = inf
    integer :: n, p
    integer(8), pointer :: arr(:) => null()
  contains
    procedure :: init => init_segtree
    procedure :: release => release_segtree
    procedure :: update => update
    procedure :: query => query
    procedure :: default => set_default
    procedure :: change => change_default
  end type
contains
  integer function op(x,y)
    integer(8), intent(in) :: x, y
    op = min(x,y)
  end
  subroutine init_segtree(this,n)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: n
    integer :: p
    p = 1
    do while (p < n)
      p = 2*p
    end do
    this%n = n
    this%p = p
    allocate(this%arr(2*p-1))
    this%arr = this%deflt
  end
  subroutine release_segtree(this)
    class(t_segment_tree), intent(inout) :: this
    if (associated(this%arr)) deallocate(this%arr)
  end
  subroutine set_default(this,i)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer :: x
    x = i+this%p-1
    this%arr(x) = this%deflt
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  subroutine change_default(this,deflt)
    class(t_segment_tree), intent(inout) :: this
    integer(8), intent(in) :: deflt
    this%deflt = deflt
  end
  subroutine update(this,i,v)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer(8), intent(in) :: v
    integer :: x
    x = i+this%p-1
    this%arr(x) = v
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  integer(8) function query(this,a,b)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: a, b
    integer :: l, r
    query = this%deflt
    l = a+this%p-1
    r = b+this%p-1
    do while (l <= r)
      if (mod(l,2) == 1) then
        query = op(query,this%arr(l))
        l = l+1
      end if
      if (mod(r,2) == 0) then
        query = op(query,this%arr(r))
        r = r-1
      end if
      l = l/2
      r = r/2
    end do
  end
end module mod_segment_tree
program many_moves
  use mod_segment_tree
  implicit none
  type(t_segment_tree) :: plus, minus
  integer :: n, q, a, b, x(200000) = 0, i, j
  integer(8) :: ans = inf, offset = 0_8, tmp, v1, v2
  read(*,*) n, q, a, b
  read(*,*) x(1:q)
  call plus%init(n)
  call minus%init(n)
  call set(a,0_8)
  do i = 1, q
    tmp = int(abs(x(i)-b),8)
    v1 = rmq(x(i))
    v2 = get(b)+tmp
    call set(b,min(v1,v2)-tmp)
    offset = offset+tmp
    b = x(i)
  end do
  do i = 1, n
    ans = min(ans,get(i))
  end do
  write(*,'(i0)') ans
contains
  subroutine set(i,v)
    integer, intent(in) :: i
    integer(8), intent(in) :: v
    call plus%update(i,v+int(i,8))
    call minus%update(i,v-int(i,8))
  end
  integer(8) function get(i)
    integer, intent(in) :: i
    get = plus%query(i,i)-int(i,8)+offset
  end
  integer(8) function rmq(i)
    integer, intent(in) :: i
    rmq = min(minus%query(1,i-1)+int(i,8),plus%query(i,n)-int(i,8))
  end
end program many_moves

Score : 900 points

Problem Statement

There are N squares in a row. The squares are numbered 1, 2, ..., N from left to right.

You have two pieces, initially placed on square A and B, respectively.
You will be asked to process Q queries of the following kind, in the order received:

Given an integer x_i, move one of the two pieces of your choice to square x_i.

Here, it takes you one second to move a piece one square.
That is, the time it takes to move a piece from square X to Y is |X-Y| seconds.

Your objective is to process all the queries in the shortest possible time.

You may only move the pieces in response to queries, and you may not move both pieces at the same time.
Also, it is not allowed to rearrange the order in which queries are given.
It is, however, allowed to have both pieces in the same square at the same time.

Constraints

1 ≤ N, Q ≤ 200,000

1 ≤ A, B ≤ N

1 ≤ x_i ≤ N

Input

Input is given from Standard Input in the following format:

N Q A B
x_1 x_2 ... x_Q

Output

Let the shortest possible time to process all the queries be X seconds. Print X.

Sample Input 1

8 3 1 8
3 5 1

Sample Output 1

7

All the queries can be processed in seven seconds, by:

moving the piece at square 1 to 3

moving the piece at square 8 to 5

moving the piece at square 3 to 1

Sample Input 2

9 2 1 9
5 1

Sample Output 2

4

The piece at square 9 should be moved first.

Sample Input 3

9 2 1 9
5 9

Sample Output 3

4

The piece at square 1 should be moved first.

Sample Input 4

11 16 8 1
1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7

Sample Output 4

21


program answer
  implicit none
  character(len=10) :: a, b, c
  character(len=26) :: s
  character(len=26) :: t
  integer(8) :: i

  read(*,*) a, b, c

  t="abcdefghijklmnopqrstuvwxyz"

  s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  do i = 1, 26
     if(a(1:1)==t(i:i)) then
        a(1:1)=s(i:i)
     end if

     if(b(1:1)==t(i:i)) then
        b(1:1)=s(i:i)
     end if

     if(c(1:1)==t(i:i)) then
        c(1:1)=s(i:i)
     end if
  end do

  write(*,*)  a(1:1), b(1:1), c(1:1)
  stop
  end program answer

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


implicit none
integer (8):: a,b,c
character(10) :: s, ss, sss
read(*,*) s, ss, sss

write(*,*) char( ichar(s(1:1))-32 ) //char( ichar(ss(1:1))-32 ) //char( ichar(sss(1:1))-32 )

end


program main
implicit none
integer(8) :: i, j, k, nc
integer(8) :: n, sum, sign
integer(8) , allocatable :: a(:)

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

if( a(1) .le. 0 ) then
   sign = -1
else
   sign = 1
end if
sum = a(1)
nc  = 0
do i = 2, n
   sign = sign *(-1)
   if( (sum+a(i))*sign < 0 ) then
      nc = nc+abs(sum+a(i))+1
      a(i) = sign*(abs(sum+a(i))+1) +a(i)
   end if
   sum = sum + a(i)
end do
write(*,'(i0)') nc
end program main

Score : 300 points

Problem Statement

You are given an integer sequence of length N. The i-th term in the sequence is a_i.
In one operation, you can select a term and either increment or decrement it by one.

At least how many operations are necessary to satisfy the following conditions?

For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.

For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.

Constraints

2 ≤ n ≤ 10^5

|a_i| ≤ 10^9

Each a_i is an integer.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print the minimum necessary count of operations.

Sample Input 1

4
1 -3 1 0

Sample Output 1

4

For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.

Sample Input 2

5
3 -6 4 -5 7

Sample Output 2

0

The given sequence already satisfies the conditions.

Sample Input 3

6
-1 4 3 2 -5 4

Sample Output 3

8


program sample
  implicit none
  integer a, b, c
  read(*,*) a, b, c
  if ( a - b == b - c)then
   write(*,*) "YES"

  else
   Write(*,*) "NO"
  endif

  stop
end program sample

Score : 100 points

Problem Statement

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

Determine whether the arrangement of the poles is beautiful.

Constraints

1 \leq a,b,c \leq 100

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

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

Sample Input 1

2 4 6

Sample Output 1

YES

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

Sample Input 2

2 5 6

Sample Output 2

NO

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

Sample Input 3

3 2 1

Sample Output 3

YES

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


program mgmg2020A
    implicit none
    integer(8)::a,b,c
    read*,a,b,c
    if(b-a==c-b)then
        print'(A)',"YES"
    else
        print'(A)',"NO"
    end if
end program mgmg2020A


integer a,b,c
read*,a,b,c
if (a+c==2*b)then
	print"(A)","YES"
else
	print"(A)","NO"
endif
end


implicit none

integer::a,b,c
read(5,*) a,b,c
if (b-a==c-b) then
    write(6,*) "YES"
else
    write(6,*) "NO"
endif

end


implicit none
character(50) :: o,e
integer :: no, ne, io, ie

read *, o
read *, e

no = len_trim(o)
ne = len_trim(e)

io = 0
ie = 0
do while (io < no)
   io = io + 1
   write(6,'(1a)',advance='no') o(io:io)

   if (ie < ne) then
      ie = ie + 1
      write(6,'(1a)',advance='no') e(ie:ie)
   endif
enddo

write(6,'(a)') ''
end

Score : 200 points

Problem Statement

Snuke signed up for a new website which holds programming competitions.
He worried that he might forget his password, and he took notes of it.
Since directly recording his password would cause him trouble if stolen,
he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.

You are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order.
Restore the original password.

Constraints

O and E consists of lowercase English letters (a - z).

1 \leq |O|,|E| \leq 50

|O| - |E| is either 0 or 1.

Input

Input is given from Standard Input in the following format:

O
E

Output

Print the original password.

Sample Input 1

xyz
abc

Sample Output 1

xaybzc

The original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.

Sample Input 2

atcoderbeginnercontest
atcoderregularcontest

Sample Output 2

aattccooddeerrbreeggiunlnaerrccoonntteesstt


program infinite_sequence
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: dp(0:1000000) = 0_8, m, s
  integer :: n, i
  read(*,*) n
  dp(1) = int(n,8)
  dp(2) = mod(int(n,8)*int(n,8),md)
  s = dp(1)+dp(2)
  m = mod(int(n-1,8)*int(n-1,8),md)
  do i = 3, n
    dp(i) = modulo(m+s+int(n-i+2,8)-dp(i-2),md)
    s = mod(s+dp(i),md)
  end do
  write(*,'(i0)') dp(n)
end program infinite_sequence

Score : 1000 points

Problem Statement

How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions?

The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j.

For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j = a_k.

Find the count modulo 10^9+7.

Constraints

1 \leq n \leq 10^6

Input

Input is given from Standard Input in the following format:

n

Output

Print how many sequences satisfy the conditions, modulo 10^9+7.

Sample Input 1

2

Sample Output 1

4

The four sequences that satisfy the conditions are:

1, 1, 1, ...

1, 2, 2, ...

2, 1, 1, ...

2, 2, 2, ...

Sample Input 2

654321

Sample Output 2

968545283


program prob3
    implicit none
    integer::N, i, j
    integer, allocatable::a(:)
    integer(16)::ans
    read(*,*) N
    allocate(a(3*N))
    read(*,*) a
    call heapsort(3*N,a)
    ans = 0
    do i = 3*N-1, N+1, -2
        ans = ans + a(i)
    end do
    write(*,*) ans
    stop
contains
    subroutine heapsort(n,array)
        implicit none
        integer,intent(in) :: n
        integer,intent(inout) :: array(1:n)

        integer ::i,k,j,l
        double precision :: 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 heapsort
end program

Score : 300 points

Problem Statement

There are 3N participants in AtCoder Group Contest.
The strength of the i-th participant is represented by an integer a_i.
They will form N teams, each consisting of three participants.
No participant may belong to multiple teams.

The strength of a team is defined as the second largest strength among its members.
For example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.

Find the maximum possible sum of the strengths of N teams.

Constraints

1 ≤ N ≤ 10^5

1 ≤ a_i ≤ 10^{9}

a_i are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{3N}

Output

Print the answer.

Sample Input 1

2
5 2 8 5 1 5

Sample Output 1

10

The following is one formation of teams that maximizes the sum of the strengths of teams:

Team 1: consists of the first, fourth and fifth participants.

Team 2: consists of the second, third and sixth participants.

Sample Input 2

10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 2

10000000000

The sum of the strengths can be quite large.


program tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 0, l = 1, i
  integer, allocatable :: p(:)
  read(*,*) n
  n = n+1_8
  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.


integer a, b
read*, a,b
print*, mod(a+b,24)
end


PROGRAM main
  implicit none
  integer(8) :: N
  integer(8) :: i

  read *, N

  do i = int(sqrt(dble(N))), N
    if(mod(N,i) == 0)then
      print "(i0)", max(int(log10(dble(i))), int(log10(dble(N/i))))+1
      exit
    endif
  enddo

END PROGRAM main

Score : 300 points

Problem Statement

You are given an integer N.

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

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

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

Constraints

1 \leq N \leq 10^{10}

N is an integer.

Input

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

N

Output

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

Sample Input 1

10000

Sample Output 1

3

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

Sample Input 2

1000003

Sample Output 2

7

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

Sample Input 3

9876543210

Sample Output 3

6


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


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

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

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

Score : 400 points

Problem Statement

You are given N items.

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

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

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

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

Constraints

1 \leq N \leq 50

1 \leq A,B \leq N

1 \leq v_i \leq 10^{15}

Each v_i is an integer.

Input

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

N A B
v_1
v_2
...
v_N

Output

Print two lines.

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

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

Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

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

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

Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

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

Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1


program prob18
    implicit none
    character :: a,b
    logical :: c,d
    read(*,*) a,b
    if(a == 'H') then
        c = .true.
    else
        c = .false.
    end if

    if(b == 'H') then
        d = .true.
    else
        d = .false.
    end if

    if(xor(c,d)) then
        write(*,'(a)') 'D'
    else
        write(*,'(a)') 'H'
    end if

    stop
contains
end program prob18

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


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

if (d==h ) then
    write(*,*) "H"
else
    write(*,*) "D"
endif

end


integer N
read*,N
print"(i0)",N*800-(N/15)*200
end

Score : 100 points

Problem Statement

Snuke has a favorite restaurant.

The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.

So far, Snuke has ordered N meals at the restaurant.
Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.
Find x-y.

Constraints

1 ≤ N ≤ 100

Input

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

N

Output

Print the answer.

Sample Input 1

20

Sample Output 1

15800

So far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.

Sample Input 2

60

Sample Output 2

47200

Snuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen.