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

    interface double_merge_sort
        module procedure msd3232, msd6464
    end interface

contains
    recursive subroutine ms32(ar, fst, lst)
        integer(int32),intent(inout):: ar(:)
        integer(int32),intent(in):: fst,lst
        integer(int32):: mdl

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

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

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

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

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

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

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

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

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

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

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

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

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

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

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

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

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

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

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

        mdl = (fst+lst)/2

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

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

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

        li=fst
        ri=mdl+1
        ti=1

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

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

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

        deallocate(t1,t2)
    end subroutine

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

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

        mdl = (fst+lst)/2

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

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

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

        li=fst
        ri=mdl+1
        ti=1

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

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

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

        deallocate(t1,t2)
    end subroutine
end module

program main
    use,intrinsic :: iso_fortran_env
    use merge_sort_mod
    implicit none
    integer(int64):: n,i,j,ans
    integer(int64), allocatable:: a(:), b(:), c(:)
    integer(int64), allocatable:: ca(:), cb(:)

    read*, n
    allocate(a(n), b(n), c(n))
    allocate(ca(0:n), cb(0:n+1), source=0_8)
    read*, a(:)
    read*, b(:)
    read*, c(:)

    call merge_sort(a, 1_8, n)
    call merge_sort(b, 1_8, n)
    call merge_sort(c, 1_8, n)

    j=1
    cb(0) = n
    do i=1,n
        cb(i) = cb(i-1)
        do while(b(i) >= c(j))
            j=j+1
            cb(i)=cb(i)-1
            if (j > n) exit
        end do
    end do
    j=1
    ca(0)=n
    do i=1,n
        ca(i) = ca(i-1)
        do while(a(i) >= b(j))
            j=j+1
            ca(i)=ca(i)-1
            if (j > n) exit
        end do
    end do
    do i=n-1,1,-1
        cb(i)=cb(i)+cb(i+1)
    end do
    ans=0
    cb(0)=0
    do i=1,n
        ans=ans+cb(n+1-ca(i))
    end do
    print'(i0)', ans
end program main

Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

1 \leq N \leq 10^5

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

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

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87


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

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

Score : 100 points

Problem Statement

Takahashi is a user of a site that hosts programming contests.

When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:

Let the current rating of the user be a.

Suppose that the performance of the user in the contest is b.

Then, the new rating of the user will be the avarage of a and b.

For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.

Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.

Find the performance required to achieve it.

Constraints

0 \leq R, G \leq 4500

All input values are integers.

Input

Input is given from Standard Input in the following format:

R
G

Output

Print the performance required to achieve the objective.

Sample Input 1

2002
2017

Sample Output 1

2032

Takahashi's current rating is 2002.

If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.

Sample Input 2

4500
0

Sample Output 2

-4500

Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.

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 name

    implicit none
    integer N,K,num,i
    read*, N
    read*, K
    num = 1
    do i = 1, N, 1
        if ( num<K ) then
            num = num*2
        else
            num = num+K
        end if
    end do
    print*, num

end program

Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

Constraints

1 \leq N, K \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.


program ABC_076_B_AdditionandMultiplication
   implicit none
   integer N, K, countN, i
   read(*, *) N, K
   countN = 1
   do i = 1, N
       if(countN * 2 <= countN + K) then
	       countN = countN * 2
	   else
	       countN = countN + K
	   end if
   end do
   write(*, *) countN
end program ABC_076_B_AdditionandMultiplication


program main
	implicit none
	integer n,k
	integer ::i,a=1
	read(*,*)n,k
	do i=1,n
		if(a*2>a+k)then
			a=a+k
		else
			a=a*2
		endif
	enddo
	write(*,*)a
end program main


program code_festival_2017_qualc_c
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100000):: s, nox_s
    integer(int32):: ls, lnxs,i,j,ans

    read*, s
    ls = len_trim(s)
    nox_s = ''
    do i=1,ls
        if (s(i:i) == 'x') cycle
        nox_s = trim(nox_s) // s(i:i)
    end do
    lnxs = len_trim(nox_s)
    i=1
    j=lnxs

    do while(i <= j)
        if (nox_s(i:i) /= nox_s(j:j)) then
            print'(i0)', -1
            stop
        end if
        i=i+1
        j=j-1
    end do

    ans=0
    i=1
    j=ls
    do while(i <= j)
        if (s(i:i) == s(j:j)) then
            i=i+1
            j=j-1
            cycle
        else if (s(i:i) == 'x') then
            ans=ans+1
            i=i+1
        else
            j=j-1
            ans=ans+1
        end if
    end do
    print'(i0)', ans
end program code_festival_2017_qualc_c

Score : 400 points

Problem Statement

We have a string s consisting of lowercase English letters.
Snuke can perform the following operation repeatedly:

Insert a letter x to any position in s of his choice, including the beginning and end of s.

Snuke's objective is to turn s into a palindrome.
Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.

Notes

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

Constraints

1 \leq |s| \leq 10^5

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

If the objective is achievable, print the number of operations required.
If it is not, print -1 instead.

Sample Input 1

xabxa

Sample Output 1

2

One solution is as follows (newly inserted x are shown in bold):

xabxa → xaxbxa → xaxbxax

Sample Input 2

ab

Sample Output 2

-1

No sequence of operations can turn s into a palindrome.

Sample Input 3

a

Sample Output 3

0

s is a palindrome already at the beginning.

Sample Input 4

oxxx

Sample Output 4

3

One solution is as follows:

oxxx → xoxxx → xxoxxx → xxxoxxx


integer a,b,c
read*,a,b,c
if(a==b)then
	print"(i0)",c
else if(b==c)then
	print"(i0)",a
else
	print"(i0)",b
endif
end

Score : 100 points

Problem Statement

You are given three integers, A, B and C.

Among them, two are the same, but the remaining one is different from the rest.

For example, when A=5,B=7,C=5, A and C are the same, but B is different.

Find the one that is different from the rest among the given three integers.

Constraints

-100 \leq A,B,C \leq 100

A, B and C are integers.

The input satisfies the condition in the statement.

Input

Input is given from Standard Input in the following format:

A B C

Output

Among A, B and C, print the integer that is different from the rest.

Sample Input 1

5 7 5

Sample Output 1

7

This is the same case as the one in the statement.

Sample Input 2

1 1 7

Sample Output 2

7

In this case, C is the one we seek.

Sample Input 3

-100 100 100

Sample Output 3

-100


program prob5
    implicit none
    integer, allocatable::c(:,:), dist(:), cnt(:), ct(:,:), disted(:), ans(:,:)
    integer::n, m, i, j, k, a, b
    read(*,*) n, m
    allocate(c(n,n),dist(n),cnt(n),ct(n,n),disted(n),ans(n,n))
    c = 0
    do i = 1, m
        read(*,*) a, b
        c(a,b) = 1
        c(b,a) = 1
    end do
    ans = c
    do i = 1, n
        dist = 0
        disted = 0
        disted(i) = 1
        cnt = 0
        ct = c
        do j = 1, n
            if(ct(i,j) == 1) then
                dist(j) = 1
                cnt(j) = 1
                ct(i,j) = 0
                ct(j,i) = 0
                disted(j) = 1
            end if
        end do
        do while(sum(ct) > 0)
            do j = 1, n
                if(dist(j) == 1) then
                    do k = 1, n
                        if(ct(j,k) == 1) then
                            dist(k) = 1
                            if(cnt(k) > 0) then
                                ans(j,k) = 0
                                ans(k,j) = 0
                            end if
                            disted(k) = 1
                            cnt(k) = cnt(k) + 1
                            ct(j,k) = 0
                            ct(k,j) = 0
                        end if
                    end do
                end if
                dist(j) = 0
            end do
            write(*,*) cnt
        end do
    end do
    write(*,*) sum(ans)/2
    stop
end program

Score : 300 points

Problem Statement

You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.

The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.

An edge whose removal disconnects the graph is called a bridge.

Find the number of the edges that are bridges among the M edges.

Notes

A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M).

Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M).

An undirected graph is said to be connected when there exists a path between every pair of vertices.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq min(N(N−1)⁄2,50)

1 \leq a_i<b_i \leq N

The given graph does not contain self-loops and double edges.

The given graph is connected.

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

Print the number of the edges that are bridges among the M edges.

Sample Input 1

7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

Sample Output 1

4

The figure below shows the given graph:

The edges shown in red are bridges. There are four of them.

Sample Input 2

3 3
1 2
1 3
2 3

Sample Output 2

0

It is possible that there is no bridge.

Sample Input 3

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

Sample Output 3

5

It is possible that every edge is a bridge.


program prob52
    implicit none
    integer :: l
    character(100) :: s
    read(*,*) s
    l = len_trim(s)
    write(*,'(a)') s(1:l-8)

    stop
contains
end program prob52

Score : 100 points

Problem Statement

Rng is going to a festival.

The name of the festival is given to you as a string S, which ends with FESTIVAL, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.

Here, assume that the name of "a festival of s" is a string obtained by appending FESTIVAL to the end of s.
For example, CODEFESTIVAL is a festival of CODE.

Constraints

9 \leq |S| \leq 50

S consists of uppercase English letters.

S ends with FESTIVAL.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer to the question: "Rng is going to a festival of what?"

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE

This is the same as the example in the statement.

Sample Input 2

CODEFESTIVALFESTIVAL

Sample Output 2

CODEFESTIVAL

This string is obtained by appending FESTIVAL to the end of CODEFESTIVAL, so it is a festival of CODEFESTIVAL.

Sample Input 3

YAKINIKUFESTIVAL

Sample Output 3

YAKINIKU


character(50) S
read*,S
print"(A)",S(1: len_trim(S)-8)
end


program main
	implicit none
	character s*50
	read(*,*)s
	write(*,*)s(1:len_trim(s)-8)
end program main


program different_distribution
  implicit none
  integer :: n, a, b, ma, mb, i
  ma = 0
  mb = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a, b
    if (ma.lt.a) then
      ma = a
      mb = b
    end if
  end do
  write(*,'(i0)') ma+mb
  stop
end program different_distribution

Score : 200 points

Problem Statement

A group of people played a game. All players had distinct scores, which are positive integers.

Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i.

Find the maximum possible number of players in the game.

Constraints

1 \leq N \leq 10^5

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

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

If i ≠ j, A_i ≠ A_j.

There exists a possible outcome of the game that are consistent with the facts.

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Outputs

Print the maximum possible number of players in the game.

Sample Input 1

3
4 7
2 9
6 2

Sample Output 1

8

The maximum possible number of players is achieved when, for example, the players have the following scores: 12,9,8,7,5,2,1,0.

Sample Input 2

5
1 10
3 6
5 2
4 4
2 8

Sample Output 2

7

Sample Input 3

2
1 1000000000
1000000000 1

Sample Output 3

1000000001


implicit none
integer(8) :: i,j,k,n

read(5,*) n

do i = 1,int(3*n/4)
  do j = int(3*n/4), 3500
       if (4*i*j-N*i-N*j<=0) then
            continue
       else if (mod(N*i*j,4*i*j-N*i-N*j)==0) then
            goto 100
             endif
enddo
enddo

100 write(6,"(i0,1x,i0,1x,i0)") i,j,(N*i*j)/(4*i*j-N*i-N*j)

end

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 s*4
read*, s
if(s=='YAKI') then
	print*, "Yes"
else
	print*, "No"
end if
end

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


program name
    implicit none
    integer(4):: h,w,cnt
    integer(4):: a_cnt(ichar('a'):ichar('z'))
    character(:),allocatable:: a
    integer(4):: i,j
    logical :: b

    read*, h,w
    allocate(character(w):: a)
    a_cnt(:) = 0
    do i=1,h
        read*, a(:)
        do j=1,w
            a_cnt(ichar(a(j:j))) = a_cnt(ichar(a(j:j))) + 1
        end do
    end do

    a_cnt(:) = mod(a_cnt(:),4)

    if (mod(w,2) == 0 .and. mod(h,2) == 0) then
        b = sum(a_cnt) == 0
    else if(mod(w,2) /= 0 .and. mod(h,2) /= 0) then
        b = sum(mod(a_cnt,2)) <= 1
    else
        b = sum(mod(a_cnt,2)) == 0
    end if

    if (b) then
        print*, 'Yes'
    else
        print*, 'No'
    end if
end program name

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 palindrome_phobia
  implicit none
  character(100) :: s
  integer :: h, w, n(26), i, j, g(3)
  logical :: f
  read(*,*) h, w
  n = 0
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      n(ichar(s(j:j))-96) = n(ichar(s(j:j))-96)+1
    end do
  end do
  g(1) = mod(h,2)*mod(w,2)
  g(2) = mod(w,2)*(h/2)+mod(h,2)*(w/2)
  g(3) = (h/2)*(w/2)
  do while (g(1).gt.0)
    do i = 1, 26
      if (mod(n(i),2).eq.1) then
        n(i) = n(i)-1
        exit
      end if
    end do
    g(1) = g(1)-1
  end do
  do while (g(2).gt.0)
    f = .false.
    do i = 1, 26
      if (mod(n(i),4).eq.2) then
        n(i) = n(i)-2
        f = .true.
        exit
      end if
    end do
    if (f) then
      g(2) = g(2)-1
      cycle
    end if
    if (g(1).eq.1) exit
    do i = 1, 26
      if (n(i).eq.0) cycle
      if (mod(n(i),4).eq.0) then
        n(i) = n(i)-4
        exit
      end if
    end do
    g(2) = g(2)-2
  end do
  do while (g(3).gt.0)
    do i = 1, 26
      if (n(i).eq.0) cycle
      if (mod(n(i),4).eq.0) then
        n(i) = n(i)-4
        exit
      end if
    end do
    g(3) = g(3)-1
  end do
  if (sum(n).eq.0) then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
  stop
end program palindrome_phobia


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

Score : 100 points

Problem Statement

We have an N \times N square grid.

We will paint each square in the grid either black or white.

If we paint exactly A squares white, how many squares will be painted black?

Constraints

1 \leq N \leq 100

0 \leq A \leq N^2

Inputs

Input is given from Standard Input in the following format:

N
A

Outputs

Print the number of squares that will be painted black.

Sample Input 1

3
4

Sample Output 1

5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.

Sample Input 2

19
100

Sample Output 2

261

Sample Input 3

10
0

Sample Output 3

100

As zero squares will be painted white, all the squares will be painted black.


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(*,*) k-abs(k-2*a)
        stop
    end if
    allocate(x(n))
    read(*,*) x
    m=0
    do i=1,n
        m=m+k-abs(k-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),i
	integer::summ=0
	read(*,*)n,k
	read(*,*)x(1:n)
	do i=1,n
		summ=summ+min(abs(x(i)),abs(x(i)-k))
	enddo
	write(*,*)summ*2
end program main


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


program ABC073A
    implicit none
    integer(8)::N
    read(5,*)N

    if(N/10==9.or.mod(N,10)==9)then
        print'(A)',"Yes"
    else
        print'(A)',"No"
    end if
end program ABC073A

Score : 100 points

Problem Statement

It is September 9 in Japan now.

You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

Constraints

10≤N≤99

Input

Input is given from Standard Input in the following format:

N

Output

If 9 is contained in the decimal notation of N, print Yes; if not, print No.

Sample Input 1

29

Sample Output 1

Yes

The one's digit of 29 is 9.

Sample Input 2

72

Sample Output 2

No

72 does not contain 9.

Sample Input 3

91

Sample Output 3

Yes


character a*2
read*, a
if(a(1:1)=='9' .or. a(2:2)=='9') then
	print*, 'Yes'
else
	print*, 'No'
end if
end


program main
	implicit none
	integer n,modn
	read(*,*)n
	modn=mod(n,10)
	n=n-modn
	if(n==90 .or. modn==9)then
		write(*,"(a3)")"YES"
	else
		write(*,"(a2)")"NO"
	endif
end program main


program sample
    implicit none

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

    read(*,*) n
    allocate(a(n))
    do i=1,n
        read(*,*)a(i)
    end do
    call msort(a)
    b=0
    m=0
    do i=1,n-1
        if(a(i)==a(i+1))then
            a(i)=0
            a(i+1)=0

        else if(a(i)==0)then
            cycle
        else
            m=m+1
        end if
    end do
    if (a(n)/=0)then
        m=m+1
    end if

    write(*,*)m
    stop
    contains

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

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

    n = size(x)

    if(n == 1) then
      return
    end if

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

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

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

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

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

    deallocate(tmp)
    return
  end subroutine msort
end program sample

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

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

    read(*,*) n
    allocate(a(n))
    do i=1,n
        read(*,*)a(i)
    end do
    call msort(a)
    b=0
    m=0
    do i=1,n-1
        if(a(i)==a(i+1))then
            a(i)=0
            a(i+1)=0

        else if(a(i)==0)then
            cycle
        else
            m=m+1
        end if
    end do
    write(*,*)m
    stop
    contains

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

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

    n = size(x)

    if(n == 1) then
      return
    end if

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

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

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

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

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

    deallocate(tmp)
    return
  end subroutine msort
end program sample


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,c,ans,na
    integer(int32), allocatable:: a(:)
    read*, n
    allocate(a(n))
    do i=1,n
        read*, a(i)
    end do

    call merge_sort(a,1,n)
    na=0
    c=0
    ans=0
    do i=1,n
        if (na == a(i)) then
            c=c+1
        else
            ans=ans+and(c,1)
            c=1
            na=a(i)
        end if
    end do
    print*, ans

contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: 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(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst, mdl, lst
        integer(4),allocatable:: tmp(:)
        integer(4):: 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(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name


program main
implicit none
integer :: i, j, k
integer :: n
integer , allocatable :: a(:), b(:)

read(*,*) n
allocate( a(n) )
do i = 1 ,n
   read(*,*) a(i)
end do
call heapsort( n , a )
j = 1
k = 0
do i = 2, n
   if( a(i-1) /= a(i) ) then
      if( mod(j,2) == 1 ) then
         k = k + 1
      end if
      j = 0
   end if
   j = j+1
end do
if( mod(j,2) == 1 ) then
   k = k+1
end if
write(*,'(i0)') k
stop
contains
subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)

  integer ::i,k,j,l
  integer :: t

  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
        end if
     end if
     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
        end if
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        end if
     end do
     array(i)=t
  end do
end subroutine heapsort
end program main


program main
implicit none
integer :: i, j, k
integer :: n
integer , allocatable :: a(:), b(:)

read(*,*) n
allocate( a(n), b(n) )
b(1) = 0
do i = 1, n
   read(*,*) a(i)
   k = 1
   do j = 1, i
      if( a(i) == b(j) ) then
         k = 0
         b(j) = 0
      end if
   end do
   if( k == 1 ) then
      b(i) = a(i)
   else
      b(i) = 0
   end if
end do
j = 0
do i = 1,  n
   if( b(i) /= 0 ) then
      j = j + 1
   end if
end do
write(*,'(i0)')  j

end program main


implicit none
integer(8):: i,j,k,n,m,ans
integer(8),allocatable,dimension(:):: num,count

read (5,*) n

allocate(num(n))
allocate(count(n))
count=0
ans=0
m=1
count(1)=1

do i=1,n
    read (5,*) num(i)
enddo

call heapsort(n,num)

do i = 2,n
    if (num(m)==num(i)) then
        count(m)=count(m)+1
    else
        ans=ans+mod(count(m),2)
        m=i
        count(m)=1
    endif
enddo

if(num(n)/=num(n-1)) then
    ans=ans+1
endif

write(6,"(i0)") ans
end

!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    double precision,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


program ABC072B
    implicit none
    integer(8)::i
    integer(8)::t_len=1
    character(100000)::s,t
    read(5,*)s

    do i=1,len_trim(s)
        if(mod(i,2)==1)then
            t(t_len:t_len)=s(i:i)
            t_len=t_len+1
        end if
    end do

    print'(A)',t(1:t_len-1)
end program ABC072B

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 sandglass
  implicit none
  integer :: x, k, q, a(100000), tt(200000,2), ans(100000), i
  integer :: tlft, trit, alft, arit, t0, t1, s
  logical :: rev
  a = 0
  tt = 0
  ans = 0
  read(*,*) x
  read(*,*) k
  read(*,*) tt(1:k,1)
  read(*,*) q
  do i = 1, q
    read(*,*) tt(k+i,1), a(i)
    tt(k+i,2) = i
  end do
  call merge_sort(tt(1:k+q,1:2))
  tlft = 0
  trit = x
  alft = 0
  arit = x
  rev = .false.
  t0 = 0
  do i = 1, k+q
    t1 = tt(i,1)
    s = tt(i,2)
    alft = alft-(t1-t0)
    if (alft.lt.0) then
      tlft = tlft-alft
      if (tlft.gt.x) tlft = x
      alft = 0
    end if
    arit = arit-(t1-t0)
    if (arit.lt.0) then
      trit = trit+arit
      if (trit.lt.0) trit = 0
      arit = 0
    end if
    if (tlft.ge.trit) then
      if (rev) then
        tlft = trit-1
        if (tlft.lt.0) tlft = 0
      else
        trit = tlft+1
        if (trit.gt.x) trit = x
      end if
    end if
    !write(*,'(6(i0,x))') t0, t1, tlft, trit, alft, arit
    t0 = t1
    if (s.eq.0) then
      rev = .not.rev
      alft = x-alft
      arit = x-arit
      cycle
    end if
    if (a(s).le.tlft) then
      ans(s) = alft
    else if (a(s).ge.trit) then
      ans(s) = arit
    else
      ans(s) = a(s)-tlft+alft
      if (rev) ans(s) = -a(s)+tlft+alft
    end if
    if (rev) ans(s) = x-ans(s)
  end do
  do i = 1, q
    write(*,'(i0)') ans(i)
  end do
  stop
contains
  subroutine merge_sort(c)
    implicit none
    integer, intent(inout) :: c(:,:)
    integer :: n, m, l, u, i
    n = size(c(:,1))
    m = n
    l = 1
    do while (m.gt.1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(c(2*(i-1)*l+1:(2*i-1)*l,:),c((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merger(c1,c2)
    implicit none
    integer, intent(inout) :: c1(:,:), c2(:,:)
    integer :: c(size(c1(:,1))+size(c2(:,1)),size(c2(1,:)))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1(:,1))
    n2 = size(c2(:,1))
    do while ((i1.le.n1).and.(i2.le.n2))
      if (c1(i1,1).le.c2(i2,1)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2,:) = c1(i1:n1,:)
    else if (i2.le.n2) then
      c(i1+i2-1:n1+n2,:) = c2(i2:n2,:)
    end if
    c1 = c(1:n1,:)
    c2 = c(n1+1:n1+n2,:)
    return
  end subroutine merger
end program sandglass

Score : 700 points

Problem Statement

We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand.
When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.

The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second.
When the upper bulb no longer contains any sand, nothing happens.

Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).

We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.

You are given Q queries.
Each query is in the form of (t_i,a_i).
For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.

Constraints

1≤X≤10^9

1≤K≤10^5

1≤r_1<r_2< .. <r_K≤10^9

1≤Q≤10^5

0≤t_1<t_2< .. <t_Q≤10^9

0≤a_i≤X (1≤i≤Q)

All input values are integers.

Input

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

X
K
r_1 r_2 .. r_K
Q
t_1 a_1
t_2 a_2
:
t_Q a_Q

Output

For each query, print the answer in its own line.

Sample Input 1

180
3
60 120 180
3
30 90
61 1
180 180

Sample Output 1

60
1
120

In the first query, 30 out of the initial 90 grams of sand will drop from bulb A, resulting in 60 grams.
In the second query, the initial 1 gram of sand will drop from bulb A, and nothing will happen for the next 59 seconds. Then, we will turn over the sandglass, and 1 second after this, bulb A contains 1 gram of sand at the time in question.

Sample Input 2

100
1
100000
4
0 100
90 100
100 100
101 100

Sample Output 2

100
10
0
0

In every query, the upper bulb initially contains 100 grams, and the question in time comes before we turn over the sandglass.

Sample Input 3

100
5
48 141 231 314 425
7
0 19
50 98
143 30
231 55
342 0
365 100
600 10

Sample Output 3

19
52
91
10
58
42
100


program main
    use,intrinsic :: iso_fortran_env
    implicit none
    character(200000):: a
    integer(int64):: i,l,ia,ans
    integer(int64):: cnt(ichar("a"):ichar("z"))

    read*, a
    cnt(:) = 0
    l = len_trim(a)
    do i=1,l
        ia = ichar(a(i:i))
        cnt(ia) = cnt(ia) + 1
    end do

    ans = (l*(l-1))/2
    do i=ichar("a"),ichar("z")
        ans=ans-(cnt(i)*(cnt(i)-1))/2
    end do
    print'(i0)', ans+1
end program main

Score : 500 points

Problem Statement

You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.

You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.

You can perform this operation at most once.

How many different strings can you obtain?

Constraints

1 \leq |A| \leq 200,000

A consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

A

Output

Print the number of different strings you can obtain by reversing any substring in A at most once.

Sample Input 1

aatt

Sample Output 1

5

You can obtain aatt (don't do anything), atat (reverse A[2..3]), atta (reverse A[2..4]), ttaa (reverse A[1..4]) and taat (reverse A[1..3]).

Sample Input 2

xxxxxxxxxx

Sample Output 2

1

Whatever substring you reverse, you'll always get xxxxxxxxxx.

Sample Input 3

abracadabra

Sample Output 3

44


program prob2
    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
contains
end program prob2

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


integer a,b,c
read*,a,b,c
if(abs(a-b)<abs(a-c))then
	print"(A)","A"
else
	print"(A)","B"
endif
end


program main
    character (20) :: cx, ca, cb
    integer :: x, a, b
    read *, cx, ca, cb
    read (cx, *) x
    read (ca, *) a
    read (cb, *) b
    if (abs(x-a) < abs(x-b)) then
        print *, "A"
    else
        print *, "B"
    end if
end program main


program main
    integer(8) :: answer = 1
    integer(8) :: m = 1000000007
    integer :: num
    character (52) :: s1, s2
    character :: s(52) = '_'
    integer :: a = 0, start = 1
    logical :: flag = .true.

    read *, num
    read *, s1
    read *, s2
    s1 = trim(s1)
    s2 = trim(s2)

    if(s1(1:1) == s2(2:2)) then
        answer = 6
        start = start + 2
        flag = .true.
    else
        answer = 3
        start = start + 1
        flag = .false.
    end if

    do i=start,num-1
        if (i+a >= num) then
            exit
        end if

        if (flag) then
            if (s1(i + a:i + a) /= s2(i+a:i+a)) then
                a = a + 1
                answer = mod(answer*3, m)
                flag = .true.
            else
                flag = .false.
            end if
        else
            if (s1(i + a:i + a) /= s2(i+a:i+a)) then
                a = a + 1
                answer = mod(answer*2, m)
                flag = .true.
            else
                answer = mod(answer*2, m)
                flag = .false.
            end if
        end if
    end do

    print *, answer
end program main

Score : 400 points

Problem Statement

We have a board with a 2 \times N grid.
Snuke covered the board with N dominoes without overlaps.
Here, a domino can cover a 1 \times 2 or 2 \times 1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:

Each domino is represented by a different English letter (lowercase or uppercase).

The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

1 \leq N \leq 52

|S_1| = |S_2| = N

S_1 and S_2 consist of lowercase and uppercase English letters.

S_1 and S_2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.

Sample Input 1

3
aab
ccb

Sample Output 1

6

There are six ways as shown below:

Sample Input 2

1
Z
Z

Sample Output 2

3

Note that it is not always necessary to use all the colors.

Sample Input 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

958681902


program main
    integer(8) :: answer = 1
    integer(8) :: m = 1000000007
    integer :: num
    character (52) :: s1, s2
    character :: s(52) = '_'
    integer :: a = 0, start = 1
    logical :: flag = .true.

    read *, num
    read *, s1
    read *, s2
    s1 = trim(s1)

    if(s1(1:1) == s1(2:2)) then
        answer = 6
        start = start + 2
        flag = .true.
    else
        answer = 3
        start = start + 1
        flag = .false.
    end if

    do i=start,num-1
        if (i+a >= num) then
            exit
        end if

        if (flag) then
            if (s1(i + a:i + a) == s1(i+1+a:i+1+a)) then
                a = a + 1
                answer = mod(answer*3, m)
                flag = .true.
            else
                flag = .false.
            end if
        else
            if (s1(i + a:i+a) == s1(i+1+a:i+1+a)) then
                a = a + 1
                answer = mod(answer*2, m)
                flag = .true.
            else
                answer = mod(answer*2, m)
                flag = .false.
            end if
        end if
    end do

    print *, answer
end program main


program main
  implicit none

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

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

  b(:) = 0
  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 ::  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

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 sample
	implicit none
    integer ::a,b

    read(*,*) a,b

    write(*,*) (a-1)*(b-1)

    stop
end program sample

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 main
	implicit none
	integer :: n,a=0,b=0
	integer(4) i,j(100000)
	read(*,*)n
	read(*,*)j(1:n)
	do i=1,n
		if(mod(j(i),4)==0)a=a+1
		if(mod(j(i),2)==1)b=b+1
	enddo
	a=int(a*1.5)
	if(b>a)then
		write(*,'(a2)')"No"
	else
		write(*,'(a3)')"Yes"
	endif
end program main

Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


program main
  implicit none
  integer :: n
  integer :: h, w
  integer, allocatable :: an(:)
  integer, allocatable :: masu(:)
  integer :: i, j, cnt

  read *, h, w
  read *, n

  allocate(an(n))
  allocate(masu(h*w))

  read *, an(1:n)

  cnt = 1
  do i = 1, n
    masu(cnt:cnt+an(i)-1) = i
    cnt = cnt + an(i)
  enddo

  do i = 1, h
    if(mod(i,2)==0)then
      print *, (masu(h*(i-1)+j),j = 1,w,1)
    else
      print *, (masu(h*(i-1)+j),j = w,1,-1)
    endif
  enddo

end program

Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares.
Snuke is painting these squares in colors 1, 2, ..., N.
Here, the following conditions should be satisfied:

For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.

For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.

Constraints

1 ≤ H, W ≤ 100

1 ≤ N ≤ H W

a_i ≥ 1

a_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

H W
N
a_1 a_2 ... a_N

Output

Print one way to paint the squares that satisfies the conditions.
Output in the following format:

c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

Sample Input 1

2 2
3
2 1 1

Sample Output 1

1 1
2 3

Below is an example of an invalid solution:

1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.

Sample Input 2

3 5
5
1 2 3 4 5

Sample Output 2

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

Sample Input 3

1 1
1
1

Sample Output 3

1


program prob76
    implicit none
    character(3) :: s
    read(*,*) s
    write(*,'(2a)') "ABC",s

    stop
contains
end program prob76

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 main
    implicit none
    integer :: n,i

    read(*,*)n
    if (n >= 64) then
      write(*,*)64
    else if (n >= 32) then
      write(*,*)32
    else if (n >= 16) then
      write(*,*)16
    else if (n >= 8) then
      write(*,*)8
    else if (n >= 4) then
      write(*,*)4
    else if (n >= 2) then
      write(*,*)2
    else
      write(*,*)1
    end if
end program main

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 decrease
  implicit none
  integer :: n, i
  integer(8) :: a(50), m, t
  a = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  t = 0_8
  do
    m = maxval(a(1:n))
    if (m.lt.int(n,8)) exit
    m = 0_8
    do i = 1, n
      m = m + a(i)/int(n,8)
    end do
    do i = 1, n
      a(i) = a(i) + m - (a(i)/int(n,8))*int(n+1,8)
    end do
    t = t + m
  end do
  write(*,'(i0)') t
  stop
end program decrease

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.)

Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.

You are given the sequence a_i. Find the number of times we will perform the above operation.

Constraints

2 ≤ N ≤ 50

0 ≤ a_i ≤ 10^{16} + 1000

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the number of times the operation will be performed.

Sample Input 1

4
3 3 3 3

Sample Output 1

0

Sample Input 2

3
1 0 3

Sample Output 2

1

Sample Input 3

2
2 2

Sample Output 3

2

Sample Input 4

7
27 0 0 0 0 0 0

Sample Output 4

3

Sample Input 5

10
1000 193 256 777 0 1 1192 1234567891011 48 425

Sample Output 5

1234567894848


program sample
	integer ::A,B,C

    read(*,*) A,B
    C=A+B

    if (mod(A,3)==0 .or. mod(B,3)==0 .or. mod(C,3)==0) then
    	write(*,*) 'possible'
    else
    	write(*,*) 'Impossible'
    end if
    stop
end program sample

Score : 100 points

Problem Statement

Snuke is giving cookies to his three goats.

He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).

Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

Constraints

1 \leq A,B \leq 100

Both A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.

Sample Input 1

4 5

Sample Output 1

Possible

If Snuke gives nine cookies, each of the three goats can have three cookies.

Sample Input 2

1 1

Sample Output 2

Impossible

Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.


program ABC067A
    implicit none
    integer(8)::A,B
    read(5,*)A,B
    if(mod(A,3)==0.or.mod(B,3)==0.or.mod(A+B,3)==0)then
        print'(A)',"Possible"
    else
        print'(A)',"Impossible"
    end if
end program ABC067A


      program main
      read(*,*) i, j
      if (mod(i,3).eq.0) then
        write(*,*) "Possible"
      else if (mod(j,3).eq.0) then
        write(*,*) "Possible"
      else if (mod(i+j,3).eq.0) then
        write(*,*) "Possible"
      else
        write(*,*) "Impossible"
      end if
      end


INTEGER M,K
INTEGER,ALLOCATABLE,DIMENSION(:)::L
INTEGER ANSWER
READ*,M,K
ALLOCATE(L(M))
READ*,L
CALL HEAPSORT(M,L)
ANSWER=0
DO I=0,K-1
  ANSWER=ANSWER+L(M-I)
ENDDO
PRINT"(I0)",ANSWER

CONTAINS

subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)

  integer ::i,k,j,l
  integer :: 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

Score : 200 points

Problem Statement

Snuke has N sticks.
The length of the i-th stick is l_i.

Snuke is making a snake toy by joining K of the sticks together.

The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

Constraints

1 \leq K \leq N \leq 50

1 \leq l_i \leq 50

l_i is an integer.

Input

Input is given from Standard Input in the following format:

N K
l_1 l_2 l_3 ... l_{N}

Output

Print the answer.

Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

Sample Input 2

15 14
50 26 27 21 41 7 42 35 7 5 5 36 39 1 45

Sample Output 2

386


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 main
	implicit none
    integer a, b,c
    read(*, *) a, b, c
    write(*, *) min(a+b, b+c, c+a)
end program main


program main
	implicit none
	integer n, i
	integer, allocatable :: a(:)
	read(*, *) n
	allocate(a(1: n))
	read(*, *) a(1: n)
	if(n == 1) then
		write(*, *)	a(1)
	else
		if(mod(n,2) == 0) then
			do i = n, 2, -2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			do i = 1, n-3, 2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			write(*, '(I0)') a(n-1)
		else
			do i = n, 1, -2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			do i = 2, n-3, 2
				write(*, '(I0)', advance = 'NO') a(i)
				write(*, '(a)', advance = 'NO') ' '
			end do
			write(*, '(I0)') a(n-1)
		end if
	end if
end program main

Score : 300 points

Problem Statement

You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.

The i-th operation is as follows:

Append a_i to the end of b.

Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

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

0 \leq a_i \leq 10^9

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print n integers in a line with spaces in between.
The i-th integer should be b_i.

Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3

After step 1 of the first operation, b becomes: 1.

After step 2 of the first operation, b becomes: 1.

After step 1 of the second operation, b becomes: 1, 2.

After step 2 of the second operation, b becomes: 2, 1.

After step 1 of the third operation, b becomes: 2, 1, 3.

After step 2 of the third operation, b becomes: 3, 1, 2.

After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.

After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.

Thus, the answer is 4 2 1 3.

Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

As shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.

Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7


program sample
  implicit none
  integer(8) :: n,i,b
integer(8),allocatable :: a(:)

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

b=1
do i=1,n
   b=a(b)
   if(a(b)==2)then
      write(*,*) i
      stop
   endif
end do

write(*,*) -1

end program sample

Score : 200 points

Problem Statement

Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.

The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.
These buttons are numbered 1 through N.
When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.
When Button i is not lighten up, nothing will happen by pressing it.

Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.

Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N

Input

Input is given from Standard Input in the following format:

N
a_1
a_2
:
a_N

Output

Print -1 if it is impossible to lighten up Button 2.
Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.

Sample Input 1

3
3
1
2

Sample Output 1

2

Press Button 1, then Button 3.

Sample Input 2

4
3
4
1
2

Sample Output 2

-1

Pressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.

Sample Input 3

5
3
3
4
2
4

Sample Output 3

3


program name
    implicit none
    integer(4):: n,i,cnt
    integer(4),allocatable:: a(:)
    logical,allocatable:: pulled(:)

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

    do i=1,n
        read*, a(i)
    end do

    pulled(:) = .false.
    i=1
    cnt = 0
    do while(.not.(pulled(2)))
        i = a(i)
        if (pulled(i)) then
            print*, -1
            stop
        end if
        pulled(i) = .true.
        cnt=cnt+1
    end do

    print*, cnt

end program name


program main
  implicit none

  integer :: n,a(100000),i,j,c=0,f=1

  read(*,*)n
  do i = 1, n
    read(*,*)a(i)
  end do

  do i = 1, n
    c = c + 1
    f = a(f)
    if (f == 2) then
      write(*,*)c
      stop
    end if
  end do
  write(*,*)-1
end program main


program trained
  implicit none
  integer :: n, a(100000) = 0, i, k
  read(*,*) n
  do i = 1, n
    read(*,*) a(i)
  end do
  i = 1
  do k = 1, n
    i = a(i)
    if (i == 2) then
      write(*,'(i0)') k
      stop
    end if
  end do
  write(*,'(i0)') -1
end program trained


program name
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100):: s
    integer(int32):: ans,i,si,osi,dst,inf=1000000000

    read*, s
    ans=inf
    do i=ichar('a'),ichar('z')
        ! print*, '--',char(i)
        dst=0
        osi=0
        do si=1,len_trim(s)
            if (s(si:si) == char(i)) then
                dst=max(dst,si-osi-1)
                osi=si
            end if
        end do
        ! print*, dst,len_trim(s)-osi-1
        dst=max(dst,len_trim(s)-osi)
        osi=inf
        do si=1,len_trim(s)
            if (s(si:si)==char(i)) then
                osi=si
                exit
            end if
        end do
        ! print*, osi-1,dst
        ans=min(ans, max(osi-1,dst))
    end do
    print'(i0)', ans
end program name

Score : 300 points

Problem Statement

Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:

For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.

There is a string s consisting of lowercase English letters.
Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.
Find the minimum necessary number of operations.

Constraints

1 ≤ |s| ≤ 100

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum necessary number of operations to achieve the objective.

Sample Input 1

serval

Sample Output 1

3

One solution is: serval → srvvl → svvv → vvv.

Sample Input 2

jackal

Sample Output 2

2

One solution is: jackal → aacaa → aaaa.

Sample Input 3

zzz

Sample Output 3

0

All the characters in s are the same from the beginning.

Sample Input 4

whbrjpjyhsrywlqjxdbrbaomnw

Sample Output 4

8

In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.


program plus_minus_rectangle
  implicit none
  integer :: h, w, x, y, a(500,500), s(0:500,0:500), i, j
  a = 0
  s = 0
  read(*,*) h, w, x, y
  if (mod(h,x).eq.0.and.mod(w,y).eq.0) then
    write(*,'(a)') "No"
  end if
  write(*,'(a)') "Yes"
  do i = 1, h, x
    do j = 1, w, y
      a(i,j) = 1
      if (i+x-1.le.h.and.j+y-1.le.w) a(i+x-1,j+y-1) = -2
    end do
  end do
  do i = 1, h
    call output(a(i,1:w))
  end do
  stop
contains
  subroutine output(a)
    implicit none
    integer, intent(in) :: a(:)
    integer :: n, i
    n = size(a)
    do i = 1, n
      write(*,'(i0,x)',advance='no') a(i)
    end do
    write(*,*)
    return
  end subroutine output
end program plus_minus_rectangle

Score : 700 points

Problem Statement

You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W).
Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:

The matrix has H rows and W columns.

Each element of the matrix is an integer between -10^9 and 10^9 (inclusive).

The sum of all the elements of the matrix is positive.

The sum of all the elements within every subrectangle with h rows and w columns in the matrix is negative.

Constraints

1 ≤ h ≤ H ≤ 500

1 ≤ w ≤ W ≤ 500

Input

Input is given from Standard Input in the following format:

H W h w

Output

If there does not exist a matrix that satisfies all of the conditions, print No.

Otherwise, print Yes in the first line, and print a matrix in the subsequent lines in the following format:

a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}

Here, a_{ij} represents the (i,\ j) element of the matrix.

Sample Input 1

3 3 2 2

Sample Output 1

Yes
1 1 1
1 -4 1
1 1 1

The sum of all the elements of this matrix is 4, which is positive.
Also, in this matrix, there are four subrectangles with 2 rows and 2 columns as shown below. For each of them, the sum of all the elements inside is -1, which is negative.

Sample Input 2

2 4 1 2

Sample Output 2

No

Sample Input 3

3 4 2 3

Sample Output 3

Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7


program main
   integer N
   integer, allocatable :: a(:)
   read(*, *) N
   allocate(a(1: N))
   read(*, *) a(1: N)
   write(*, *) maxval(a(:)) - minval(a(:))
end program main

Score : 200 points

Problem Statement

It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.

There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.

Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.

Constraints

1 ≤ N ≤ 100

0 ≤ a_i ≤ 1000

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 distance to be traveled.

Sample Input 1

4
2 3 7 9

Sample Output 1

7

The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.

It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.

Sample Input 2

8
3 1 4 1 5 9 2 6

Sample Output 2

8

There may be more than one house at a position.


program name
    implicit none
    integer(4):: n
    integer(4),allocatable:: a(:)
    integer(4):: over
    integer(4):: i,j
    logical:: iro(9)

    read*, n
    allocate(a(n))
    read*, a(:)
    iro(:) = .false.
    over = 0

    do i=1,n
        do j=0,4800
            if (j*400 <= a(i) .and. a(i) < (j+1)*400) then
                if (j < 8) then
                    iro(j+1) = .true.
                else
                    iro(9) = .true.
                    over=over+1
                end if
            end if
        end do
    end do

    print*, tsum(iro)
    print*, tsum(iro)+over -1

contains
    function tsum(larr) result(ret)
        logical:: larr(:)
        integer(4):: ret
        integer(4):: i
        ret=0
        do i=1,size(larr)
            if (larr(i)) ret=ret+1
        end do
    end function
end program name

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.


program prob4
    implicit none
    integer::i, j, l, r, n, mode
    character(len=100)::S
    character(len=300)::ans, tmp
    read(*,*) n
    read(*,*) S
    ans = ""
    l = 0
    r = 0
    do i = 1, n
        if(S(i:i) .eq. "(") then
            if(r > 0) then
                do j = 1, r
                    ans = ")" // trim(ans)
                end do
                do j = 1, r
                    ans = "(" // trim(ans)
                end do
                r = 0
                l = 0
            end if
            l = l + 1
        else
            if(l > 0) then
                do j = 1, l
                    ans = trim(ans) // "("
                end do
                do j = 1, l
                    ans = trim(ans) // ")"
                end do
                l = 0
                r = 0
            end if
            r = r + 1
        end if
    end do
    if(r > 0) then
        do i = 1, r-1
            ans = trim(ans) // ")"
        end do
        do i = 1, r-1
            ans = "(" // trim(ans)
        end do
    else if(l > 0) then
        do i = 1, l-1
            ans = trim(ans) // "("
        end do
        do i = 1, l-1
            ans = trim(ans) // "9"
        end do
    end if
    write(*,'(a)') trim(ans)
    stop
end program

Score : 400 points

Problem Statement

You are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.

Here, a correct bracket sequence is defined as follows:

() is a correct bracket sequence.

If X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence.

If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.

Every correct bracket sequence can be derived from the rules above.

Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.

Constraints

The length of S is N.

1 ≤ N ≤ 100

S consists of ( and ).

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.

Sample Input 1

3
())

Sample Output 1

(())

Sample Input 2

6
)))())

Sample Output 2

(((()))())

Sample Input 3

8
))))((((

Sample Output 3

(((())))(((())))


implicit none

integer::a,b
read(5,*) a,b
if (a+b<10) then
    write(6,*) a+b
else
    write(6,*) "error"
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 main
  implicit none
  character(26) :: s
  integer :: i, j, n
  read(*, *) s
  n = len(trim(s))
  do i = 1, n
    do j = i + 1, n
      if (s(i:i) == s(j:j)) then
        write(*, "(a)") "no"
        stop 0
      end if
    end do
  end do
  write(*, "(a)") "yes"
end program main

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


read*,i,j
if(i==2.or.j==2)then
print*,"No"
else
print*,"Yes"
endif
end

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 ABC062B
    implicit none
    integer(8)::H,W,i
    character(100),dimension(100)::A
    read(5,*)H,W
    read(5,*)(A(i),i=1,H)

    do i=1,W+2
        write(*,'(A)',advance='no')"#"
    end do
    print'(A)',""

    do i=1,H
        write(*,'(A)',advance='no')"#"
        write(*,'(A)',advance='no')A(i)(1:W)
        write(*,'(A)',advance='no')"#"
        print'(A)',""
    end do

    do i=1,W+2
        write(*,'(A)',advance='no')"#"
    end do
    print'(A)',""
end program ABC062B

Score : 200 points

Problem Statement

You are given a image with a height of H pixels and a width of W pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the i-th row from the top and j-th column from the left is a_{ij}.

Put a box around this image and output the result. The box should consist of # and have a thickness of 1.

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_{1W}
:
a_{H1} ... a_{HW}

Output

Print the image surrounded by a box that consists of # and has a thickness of 1.

Sample Input 1

2 3
abc
arc

Sample Output 1

#####
#abc#
#arc#
#####

Sample Input 2

1 1
z

Sample Output 2

###
#z#
###


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

    read(*,*) A,B,C

    if (C >= A .and. C<=B) then
    	write(*,*) "Yes"
    else
    	write(*,*) "No"
    end if

    stop
end program sample

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 ABC061C
    implicit none
    integer(8)::N,K,a,b,i,count
    integer(8),dimension(100000)::L
    read(5,*)N,K
    L=0
    count=0

    do i=1,N
        read(5,*)a,b
        L(a)=L(a)+b
    end do

    do i=1,100000
        count=count+L(i)
        if(count>=K)then
            print'(i0)',i
            exit
        end if
    end do
end program ABC061C

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
   integer(8) N, K, i
   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
   do i = 1, N
       if(1 <= K .and. K <= b(i)) then
	       write(*, *) a(i)
	       exit
	   else
	       K = K - b(i)
	   end if
   end do
end program main


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*100
    ! 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

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

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

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

    if (mod(a,2)==1 .or. mod(b,2)==1 .or. mod(c,2)==1) then
        write(*,*)0
        stop
    end if

    x=abs(a-b)
    y=abs(b-c)
    m=0
    do while(mod(x,2)==0 .and. mod(y,2)==0)
        x=x/2
        y=y/2
        m=m+1
    end do

    write(*,*)m

    stop
end program sample

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 cookie
  implicit none
  integer :: A, B, C, a1, b1, c1, count, ma, mb, mc

  read(*,*) A, B, C
  ma = A
  mb = B
  mc = C

  count = 0
  do while (.true.)
     count = count + 1
     c1 = (A + B) / 2
     a1 = (B + C) / 2
     b1 = (C + A) / 2
     if (mod(c1,2) == 1 .or. mod(a1,2) == 1 .or. mod(b1,2) == 1) then
        exit
     else if ((a1 == ma .and. b1 == mb) .or. (a1 == ma .and. b1 == mc) .or. &
          &   (a1 == mb .and. b1 == ma) .or. (a1 == mb .and. b1 == mc) .or. &
          &   (a1 == mc .and. b1 == ma) .or. (a1 == mc .and. b1 == mb)) then
        write(*,*) -1
        stop
     end if
     A = a1
     B = b1
     C = c1
  end do

  write(*,*) count

  stop
end program cookie


program sample
	implicit none
    integer(8) :: x,y,z,a,b,c,count

    read(*,*) x,y,z

    count=0
    if (x==y .and. y==z) then
    	write(*,*) -1
    else
    	do while(.true.)
    		if (mod(x+y,2) == 0 .and. mod(y+z,2) ==0 .and. mod(x+z,2) ==0) then
    			count = count+1
    		    a=(y+z)/2
    		    b=(x+z)/2
     		    c=(x+y)/2
      	     	x=a
     	    	y=b
       	    	z=c
    		else
    			write(*,*) count
    	 	    exit
    		end if
   		end do
    end if

    stop
end program sample


character a*10, b*10, c*10
integer lena, lenb
read*, a, b, c
lena=len_trim(a)
lenb=len_trim(b)
if(a(lena:lena) == b(1:1) .and. b(lenb:lenb) == c(1:1)) then
	print*, 'YES'
else
	print*,'NO'
end if
end

Score : 100 points

Problem Statement

You are given three strings A, B and C. Check whether they form a word chain.

More formally, determine whether both of the following are true:

The last character in A and the initial character in B are the same.

The last character in B and the initial character in C are the same.

If both are true, print YES. Otherwise, print NO.

Constraints

A, B and C are all composed of lowercase English letters (a - z).

1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

rng gorilla apple

Sample Output 1

YES

They form a word chain.

Sample Input 2

yakiniku unagi sushi

Sample Output 2

NO

A and B form a word chain, but B and C do not.

Sample Input 3

a a a

Sample Output 3

YES

Sample Input 4

aaaaaaaaab aaaaaaaaaa aaaaaaaaab

Sample Output 4

NO


program sentou
  implicit none
  integer :: n, t, s(200000) = 0, i, x = 0
  read(*,*) n, t
  read(*,*) s(1:n)
  x = t
  do i = 1, n-1
    x = x+min(s(i+1)-s(i),t)
  end do
  write(*,'(i0)') x
end program sentou

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


character a,b,c;
read*,a,b,c;
print"(a)",char(ichar(a(1:1))-32)//char(ichar(b(1:1))-32)//char(ichar(c(1:1))-32)
end

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