function main()
	n = parse.(split(readline()))
	x = n[2]
	min = 1000
	for i in 1:n[1]
		m=parse(readline())
		if m < min
			min = m
		end
		x -= m
	end
	y = x%min
	z = convert(Int, (x-y)/min)
	print(z+n[1])
end

main()

Score : 200 points

Problem Statement

Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.

Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:

For each of the N kinds of doughnuts, make at least one doughnut of that kind.

At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.

Constraints

2 ≤ N ≤ 100

1 ≤ m_i ≤ 1000

m_1 + m_2 + ... + m_N ≤ X ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
m_1
m_2
:
m_N

Output

Print the maximum number of doughnuts that can be made under the condition.

Sample Input 1

3 1000
120
100
140

Sample Output 1

9

She has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.

Sample Input 2

4 360
90
90
90
90

Sample Output 2

4

Making one doughnut for each of the four kinds consumes all of her Moto.

Sample Input 3

5 3000
150
130
150
130
110

Sample Output 3

26


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c,x,y=parseMap(split(readline()))
    println(min(a+b,c*2)*min(x,y)+min(a,c*2)*(x-min(x,y))+min(b,c*2)*(y-min(x,y)))
end
main()

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

Score : 300 points

Problem Statement

"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Constraints

1 ≤ A, B, C ≤ 5000

1 ≤ X, Y ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.

Sample Input 1

1500 2000 1600 3 2

Sample Output 1

7900

It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.

Sample Input 2

1500 2000 1900 3 2

Sample Output 2

8500

It is optimal to directly buy three A-pizzas and two B-pizzas.

Sample Input 3

1500 2000 500 90000 100000

Sample Output 3

100000000

It is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.

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.


function main()

  (A,B,X) = map(x -> parse(Int,x), split(readline()))

  if A+B >= X && A <= X
    println("YES")
  else
    println("NO")
  end

end

main()

Score : 100 points

Problem Statement

There are a total of A + B cats and dogs.
Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.

Determine if it is possible that there are exactly X cats among these A + B animals.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

1 \leq X \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B X

Output

If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

Sample Input 1

3 5 4

Sample Output 1

YES

If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.

Sample Input 2

2 2 6

Sample Output 2

NO

Even if all of the B = 2 animals are cats, there are less than X = 6 cats in total.

Sample Input 3

5 3 2

Sample Output 3

NO

Even if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.


a, b, x = parse.(split(readline()))
if a <= x <= a+b
  print("YES")
else
  print("NO")
end


function main()
    a, b, x = split(readline())
    a = parse(Int, a)
    b = parse(Int, b)
    x = parse(Int, x)
    if a <= x && b >= x
        println("YES")
    else
        println("NO")
    end
end
main()


function main()
	n = parse(readline())
	x = parse.(split(readline()))
	y = sort(x)
	m1 = y[div(n,2)]
	m2 = y[div(n,2)+1]
	for i in 1:n
		if x[i] <= m1
			println(m2)
		else
			println(m1)
		end
	end
end

main()

Score : 300 points

Problem Statement

When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.

You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.

Find B_i for each i = 1, 2, ..., N.

Constraints

2 \leq N \leq 200000

N is even.

1 \leq X_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print N lines.
The i-th line should contain B_i.

Sample Input 1

4
2 4 4 3

Sample Output 1

4
3
3
4

Since the median of X_2, X_3, X_4 is 4, B_1 = 4.

Since the median of X_1, X_3, X_4 is 3, B_2 = 3.

Since the median of X_1, X_2, X_4 is 3, B_3 = 3.

Since the median of X_1, X_2, X_3 is 4, B_4 = 4.

Sample Input 2

2
1 2

Sample Output 2

2
1

Sample Input 3

6
5 5 4 4 3 3

Sample Output 3

4
4
4
4
4
4


n = parse(Int,readline())
a = map(x->parse(BigInt,x),split(readline()))
sort!(a)
m = div(a[n],2)
x = max(1,searchsortedlast(a,m))
y = min(n-1,searchsortedfirst(a,m))
println(a[n], ' ', binomial(a[n],a[x]) > binomial(a[n],a[y]) ? a[x] : a[y])

Score : 400 points

Problem Statement

Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

2 \leq n \leq 10^5

0 \leq a_i \leq 10^9

a_1,a_2,...,a_n are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print a_i and a_j that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:

\rm{comb}(4,2)=6

\rm{comb}(6,2)=15

\rm{comb}(6,4)=15

\rm{comb}(9,2)=36

\rm{comb}(9,4)=126

\rm{comb}(9,6)=84

\rm{comb}(11,2)=55

\rm{comb}(11,4)=330

\rm{comb}(11,6)=462

\rm{comb}(11,9)=55

Thus, we should print 11 and 6.

Sample Input 2

2
100 0

Sample Output 2

100 0


n = parse(Int,readline())
a = map(x->parse(Int,x),split(readline()))
sort!(a)
m = div(a[n],2)
x = max(1,searchsortedlast(a,m))
y = min(n-1,searchsortedfirst(a,m))
println(a[n], ' ', binomial(a[n],a[x]) > binomial(a[n],a[y]) ? a[x] : a[y])


function parseInt(x) parse(Int, x) end

function main()
	a = parseInt.(split(readline()))
	if a[2]-a[1] <= 2*a[3]
		for i in 0:a[2]-a[1]
			println(a[1]+i)
		end
	else
		for i in 1:a[3]
			println(a[1]+i-1)
		end
		for i in 1:a[3]
			println(a[2]-a[3]+i)
		end
	end
end

main()

Score : 200 points

Problem Statement

Print all the integers that satisfies the following in ascending order:

Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Constraints

1 \leq A \leq B \leq 10^9

1 \leq K \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print all the integers that satisfies the condition above in ascending order.

Sample Input 1

3 8 2

Sample Output 1

3
4
7
8

3 is the first smallest integer among the integers between 3 and 8.

4 is the second smallest integer among the integers between 3 and 8.

7 is the second largest integer among the integers between 3 and 8.

8 is the first largest integer among the integers between 3 and 8.

Sample Input 2

4 8 3

Sample Output 2

4
5
6
7
8

Sample Input 3

2 9 100

Sample Output 3

2
3
4
5
6
7
8
9


if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  l=sort(pM(split(readline())))
  ans=0
  i=fld(l[3]-l[1],2)
  ans+=i
  l[1]+=2i
  j=fld(l[3]-l[2],2)
  ans+=j
  l[2]+=2j
  c=count(isequal(l[3]),l)
  if c==1
    ans+=1
  elseif c==2
    ans+=2
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Score : 300 points

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

Choose two among A, B and C, then increase both by 1.

Choose one among A, B and C, then increase it by 2.

It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Constraints

0 \leq A,B,C \leq 50

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the minimum number of operations required to make A, B and C all equal.

Sample Input 1

2 5 4

Sample Output 1

2

We can make A, B and C all equal by the following operations:

Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.

Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.

Sample Input 2

2 6 3

Sample Output 2

5

Sample Input 3

31 41 5

Sample Output 3

23


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	q = readline() |> parseInt
	for i in 1:q
		a,b = readline() |> split |> parseMap
		temp = min(a,b)
		b = max(a,b)
		a = temp
		c = ceil(Int, sqrt(a*b))-1
		if a == b
			println(2*a-2)
		elseif a+1 == b
			println(2*a-2)
		elseif c*(c+1) >= a*b
			println(2*c-2)
		else
			println(2*c-1)
		end
	end
end

main()

Score : 700 points

Problem Statement

10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.

The score of a participant is the product of his/her ranks in the two contests.

Process the following Q queries:

In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

Constraints

1 \leq Q \leq 100

1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
A_1 B_1
:
A_Q B_Q

Output

For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.

Sample Input 1

8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Sample Output 1

1
12
4
11
14
57
31
671644785

Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).

In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	q = readline() |> parseInt
	for i in 1:q
		a,b = readline() |> split |> parseMap
		c = a*b
		r = floor(Int, sqrt(c))
		if div(c,r) == r
			println(2*(r-1))
		else
			if a == r || b == r
				println(2*(r-1))
			else
				println(2*r-1)
			end
		end
	end
end

main()


function main()

  N = parse(Int,readline())
  (D,X) = map(x -> parse(Int,x), split(readline()))

  count = 0

  for i in 1:N

    A = parse(Int,readline())

    for j in 0:D

      if A*j + 1 <= D
        count += 1
      else
        break
      end

    end

  end

  println(count + X)

end

main()

Score : 200 points

Problem Statement

Some number of chocolate pieces were prepared for a training camp.
The camp had N participants and lasted for D days.
The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.
As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.

Find the number of chocolate pieces prepared at the beginning of the camp.

Constraints

1 \leq N \leq 100

1 \leq D \leq 100

1 \leq X \leq 100

1 \leq A_i \leq 100 (1 \leq i \leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
D X
A_1
A_2
:
A_N

Output

Find the number of chocolate pieces prepared at the beginning of the camp.

Sample Input 1

3
7 1
2
5
10

Sample Output 1

8

The camp has 3 participants and lasts for 7 days.
Each participant eats chocolate pieces as follows:

The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.

The second participant eats one chocolate piece on Day 1 and 6, for a total of two.

The third participant eats one chocolate piece only on Day 1, for a total of one.

Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.

Sample Input 2

2
8 20
1
10

Sample Output 2

29

Sample Input 3

5
30 44
26
18
81
18
6

Sample Output 3

56


function main()
	N=parse(Int,readline())
	A=[0]
	for a=map(x->parse(Int,x),split(readline()))
		push!(A,a)
	end
	push!(A,0)
	ans=0;
	for i=1:N+1
		ans+=abs(A[i+1]-A[i])
	end
	for i=2:N+1
		println(ans-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))
	end
end
main()

Score : 300 points

Problem Statement

There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.

You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.

However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i.
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.

For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Constraints

2 \leq N \leq 10^5

-5000 \leq A_i \leq 5000 (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_2 ... A_N

Output

Print N lines.
In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled.

Sample Input 1

3
3 5 -1

Sample Output 1

12
8
10

Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively.
For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:

For i = 1, the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.

For i = 2, the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.

For i = 3, the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.

Sample Input 2

5
1 1 1 2 0

Sample Output 2

4
4
4
2
4

Sample Input 3

6
-679 -2409 -3258 3095 -3291 -4462

Sample Output 3

21630
21630
19932
8924
21630
19288


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	a,b = readline() |> split |> parseMap
	x = zeros(Int,100,100)
	for i in 1:a-1
		if div(i,48)%2 == 1
			x[div(i,48)+2,2*(i%47)+2] = 1
		else
			x[div(i,48)+2,2*(i%47)+3] = 1
		end
	end
	for i in 1:b-1
		if div(i,48)%2 == 1
			x[52+div(i,48),2*(i%47)+2] = 1
		else
			x[52+div(i,48),2*(i%47)+3] = 1
		end
	end
	for i in 1:50
		for j in 1:100
			if x[i,j] == 1
				print('.')
			else
				print('#')
			end
		end
	    println("")
	end
	for i in 51:100
		for j in 1:100
			if x[i,j] == 1
				print('#')
			else
				print('.')
			end
		end
		println("")
	end
end

main()

Score : 500 points

Problem Statement

You are given two integers A and B.

Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:

Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.

The set of the squares painted white is divided into exactly A connected components.

The set of the squares painted black is divided into exactly B connected components.

It can be proved that there always exist one or more solutions under the conditions specified in Constraints section.
If there are multiple solutions, any of them may be printed.

Notes

Two squares painted white, c_1 and c_2, are called connected when the square c_2 can be reached from the square c_1 passing only white squares by repeatedly moving up, down, left or right to an adjacent square.

A set of squares painted white, S, forms a connected component when the following conditions are met:

Any two squares in S are connected.

No pair of a square painted white that is not included in S and a square included in S is connected.

A connected component of squares painted black is defined similarly.

Constraints

1 \leq A \leq 500

1 \leq B \leq 500

Input

Input is given from Standard Input in the following format:

A B

Output

Output should be in the following format:

In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.

Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:

If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be ..

If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be #.

Sample Input 1

2 3

Sample Output 1

3 3
##.
..#
#.#

This output corresponds to the grid below:

Sample Input 2

7 8

Sample Output 2

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

Sample Input 3

1 1

Sample Output 3

4 2
..
#.
##
##

Sample Input 4

3 14

Sample Output 4

8 18
..................
..................
....##.......####.
....#.#.....#.....
...#...#....#.....
..#.###.#...#.....
.#.......#..#.....
#.........#..####.


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	red = Array{Int}(3,n)
	blu = Array{Int}(3,n)
	for i in 1:n
		red[1:2,i] = readline() |> split |> parseMap
		red[3,i] = min(red[1,i],red[2,i])
	end
	for i in 1:n
		blu[1:2,i] = readline() |> split |> parseMap
		blu[3,i] = min(blu[1,i],blu[2,i])
	end
	red = sortcols(red, by = x->x[3])
	blu = sortcols(blu, by = x->x[3])
	p = 0
	r = 1
	b = 1
	while r <= n && b <= n
		if red[1,r] < blu[1,b] && red[2,r] < blu[2,r]
			r += 1
			b += 1
			p += 1
		else
			b += 1
		end
	end
	println(p)
end

main()

Score : 400 points

Problem Statement

On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

All input values are integers.

1 \leq N \leq 100

0 \leq a_i, b_i, c_i, d_i < 2N

a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.

b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

Output

Print the maximum number of friendly pairs.

Sample Input 1

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

Sample Output 1

2

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

Sample Input 2

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

Sample Output 2

2

For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4).

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0

It is possible that no pair can be formed.

Sample Input 4

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

Sample Output 4

5

Sample Input 5

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

Sample Output 5

4


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    println(join([readline()[1],readline()[2],readline()[3]]))
end
main()

Score : 100 points

Problem Statement

We have a 3×3 square grid, where each square contains a lowercase English letters.
The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.

Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

Constraints

Input consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

c_{11}c_{12}c_{13}
c_{21}c_{22}c_{23}
c_{31}c_{32}c_{33}

Output

Print the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

Sample Input 1

ant
obe
rec

Sample Output 1

abc

The letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc.

Sample Input 2

edu
cat
ion

Sample Output 2

ean


function main()

  (N,M) = map(x -> parse(Int,x), split(readline()))

  ans = N*M

  ans -= 2M + 2N - 4

  println(abs(ans))

end

main()

Score : 300 points

Problem Statement

There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, and initially every card faces up.

We will perform the following operation once for each square contains a card:

For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.

It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed.
Find the number of cards that face down after all the operations.

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of cards that face down after all the operations.

Sample Input 1

2 2

Sample Output 1

0

We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.

Sample Input 2

1 7

Sample Output 2

5

After all the operations, all cards except at both ends face down.

Sample Input 3

314 1592

Sample Output 3

496080


function main()

  N = parse(Int,readline())

  println(div(N,3))

end

main()

Score : 100 points

Problem Statement

There are N students in a school.

We will divide these students into some groups, and in each group they will discuss some themes.

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.

Constraints

1 \leq N \leq 1000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N

Output

If you can form at most x groups consisting of three or more students, print x.

Sample Input 1

8

Sample Output 1

2

For example, you can form a group of three students and another of five students.

Sample Input 2

2

Sample Output 2

0

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.

Sample Input 3

9

Sample Output 3

3


function solve()
    N = parse(Int64, readline())
    S = [chomp(readline()) for s in 1:N]

	numMARCH = [0, 0, 0, 0, 0]
    MARCH = ["M", "A", "R", "C", "H"]

  	for name in S
        for (i, m) in enumerate(MARCH)
            if name[1] == m[1]
                numMARCH[i] += 1
            end
        end
    end

    nonzero = numMARCH[numMARCH .!= 0]
    if length(nonzero) < 3
        println(0)
        return
    end

  	combinations::Int64 = 0
    for i in 1:length(nonzero)
    	for j in i+1:length(nonzero)
            for k in j+1:length(nonzero)
                combinations += nonzero[i]*nonzero[j]*nonzero[k]
            end
        end
    end
    println(combinations)

end

solve()

Score : 300 points

Problem Statement

There are N people. The name of the i-th person is S_i.

We would like to choose three people so that the following conditions are met:

The name of every chosen person begins with M, A, R, C or H.

There are no multiple people whose names begin with the same letter.

How many such ways are there to choose three people, disregarding order?

Note that the answer may not fit into a 32-bit integer type.

Constraints

1 \leq N \leq 10^5

S_i consists of uppercase English letters.

1 \leq |S_i| \leq 10

S_i \neq S_j (i \neq j)

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If there are x ways to choose three people so that the given conditions are met, print x.

Sample Input 1

5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

Sample Output 1

2

We can choose three people with the following names:

MASHIKE, RUMOI, HABORO

MASHIKE, RUMOI, HOROKANAI

Thus, we have two ways.

Sample Input 2

4
ZZ
ZZZ
Z
ZZZZZZZZZZ

Sample Output 2

0

Note that there may be no ways to choose three people so that the given conditions are met.

Sample Input 3

5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO

Sample Output 3

7


function main()
	N=parse.(Int,readline())
	a=sort(parse.(Int,split(readline())),rev=true)

	diff=0
	for i=1:length(a)
		if i%2==0
			diff-=a[i]
		else
			diff+=a[i]
		end
	end
	println(diff)
end

main()

Score: 200 points

Problem Statement

We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

Constraints

N is an integer between 1 and 100 (inclusive).

a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 a_3 ... a_N

Output

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

Sample Input 1

2
3 1

Sample Output 1

2

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.

Sample Input 2

3
2 7 4

Sample Output 2

5

First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.

Sample Input 3

4
20 18 2 18

Sample Output 3

18


n=parse(Int,readline())
a=parse.(Int,split(readline()))
sort!(a,rev=true)
Alice=0
Bob=0
for i=1:2:n
    global Alice += a[i]
end
    for j=1:2:n-1
        global Bob += a[j+1]
    end
println(Alice-Bob)


   N = parse(Int, readline())
    a = map(x -> parse(Int, x), split(readline()))

    sort!(a, rev=true)

    alice = 0
    bob = 0
    for i = 1:N
        if i % 2 == 1
            alice += a[i]
        else
            bob += a[i]
        end
    end

    println(alice - bob)
end

main()


A=[((a,b,c)=map(x->parse(Int,x),split(s));(b-a,c-b)) for s=readlines()]
if A[1]==A[2]==A[3]
  println("Yes")
else
  println("No")
end

Score: 300 points

Problem Statement

We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.

According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.

Determine if he is correct.

Constraints

c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}

Output

If Takahashi's statement is correct, print Yes; otherwise, print No.

Sample Input 1

1 0 1
2 1 2
1 0 1

Sample Output 1

Yes

Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.

Sample Input 2

2 2 2
2 1 2
2 2 2

Sample Output 2

No

Takahashi is incorrect in this case.

Sample Input 3

0 8 8
0 8 8
0 8 8

Sample Output 3

Yes

Sample Input 4

1 8 6
2 9 7
0 7 7

Sample Output 4

No


x,a,b=[parse(readline())for i in 1:3]
print((x-a)%b)

Score : 100 points

Problem Statement

You went shopping to buy cakes and donuts with X yen (the currency of Japan).

First, you bought one cake for A yen at a cake shop.
Then, you bought as many donuts as possible for B yen each, at a donut shop.

How much do you have left after shopping?

Constraints

1 \leq A, B \leq 1 000

A + B \leq X \leq 10 000

X, A and B are integers.

Input

Input is given from Standard Input in the following format:

X
A
B

Output

Print the amount you have left after shopping.

Sample Input 1

1234
150
100

Sample Output 1

84

You have 1234 - 150 = 1084 yen left after buying a cake.
With this amount, you can buy 10 donuts, after which you have 84 yen left.

Sample Input 2

1000
108
108

Sample Output 2

28

Sample Input 3

579
123
456

Sample Output 3

0

Sample Input 4

7477
549
593

Sample Output 4

405


X = parse(readline())
A = parse(readline())
B = parse(readline())
mon = X-A
print(mon-div(mon,B)*B)


(X, A, B) = parse.([readline() for _=1:3])
print((X - A) % B)


function main()
	N,M=map(x->parse(Int32,x),split(readline()))
	G=[Array{Pair{Int32,Int32}}(0) for _=1:N]
	for s=readlines()
		L,R,D=map(x->parse(Int32,x),split(s))
		push!(G[L],R=>D)
		push!(G[R],L=>-D)
	end
	dist=ones(Int,N)*1145141919810
	function dfs(u,x)
		dist[u]=x
		ret=true
		for (v,t)=G[u]
			if dist[v]!=1145141919810
				if x+t!=dist[v]
					ret=false
				end
			else
				if !dfs(v,x+t)
					ret=false
				end
			end
		end
		ret
	end
	flag=true
	for i=1:N
		if dist[i]==1145141919810
			if !dfs(i,0)
				flag=false
			end
		end
	end
	if flag
		println("Yes")
	else
		println("No")
	end
end
main()

Score : 400 points

Problem Statement

There are N people standing on the x-axis.
Let the coordinate of Person i be x_i.
For every i, x_i is an integer between 0 and 10^9 (inclusive).
It is possible that more than one person is standing at the same coordinate.

You will given M pieces of information regarding the positions of these people.
The i-th piece of information has the form (L_i, R_i, D_i).
This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.

It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.

Constraints

1 \leq N \leq 100 000

0 \leq M \leq 200 000

1 \leq L_i, R_i \leq N (1 \leq i \leq M)

0 \leq D_i \leq 10 000 (1 \leq i \leq M)

L_i \neq R_i (1 \leq i \leq M)

If i \neq j, then (L_i, R_i) \neq (L_j, R_j) and (L_i, R_i) \neq (R_j, L_j).

D_i are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M

Output

If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.

Sample Input 1

3 3
1 2 1
2 3 1
1 3 2

Sample Output 1

Yes

Some possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).

Sample Input 2

3 3
1 2 1
2 3 1
1 3 5

Sample Output 2

No

If the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information.

Sample Input 3

4 3
2 1 1
2 3 5
3 4 2

Sample Output 3

Yes

Sample Input 4

10 3
8 7 100
7 9 100
9 8 100

Sample Output 4

No

Sample Input 5

100 0

Sample Output 5

Yes


function main()
	N = parse(Int, readline())
	arr = [parse.(Int,split(readline())) for _=1:N]
	pushfirst!(arr, [0,0,0])

	can = true
	for i= 1:N
		dt = arr[i+1][1] - arr[i][1]
		dist = abs(arr[i+1][2] - arr[i][2]) + abs(arr[i+1][3] - arr[i][3])
		if dt < dist; can = false;end
		if dt%2 != dist%2;can = false; end
	end

	print(can ? "Yes" : "No")

end

main()

Score : 300 points

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.

If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

Constraints

1 ≤ N ≤ 10^5

0 ≤ x_i ≤ 10^5

0 ≤ y_i ≤ 10^5

1 ≤ t_i ≤ 10^5

t_i < t_{i+1} (1 ≤ i ≤ N-1)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

Sample Input 1

2
3 1 2
6 1 1

Sample Output 1

Yes

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

Sample Input 2

1
2 100 100

Sample Output 2

No

It is impossible to be at (100,100) two seconds after being at (0,0).

Sample Input 3

2
5 1 1
100 1 1

Sample Output 3

No


parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	b = zeros(Int,k,k)
	w = zeros(Int,k,k)
	for i in 1:n
		x,y,c = readline() |> chomp |> split
		x = parseInt(x)
		y = parseInt(y)
		s = div(x,k)+div(y,k)
		if s%2==0
			if c[1]=='B'
				b[x%k+1,y%k+1]+=1
			else
				w[x%k+1,y%k+1]+=1
			end
		else
			if c[1]=='W'
				b[x%k+1,y%k+1]+=1
			else
				w[x%k+1,y%k+1]+=1
			end
		end
	end
	bb = zeros(Int,k+1,k+1)
	ww = zeros(Int,k+1,k+1)
	for i in 1:k
		for j in 1:k
			bb[i+1,j+1]=bb[i+1,j]+b[i,j]
			ww[i+1,j+1]=ww[i+1,j]+w[i,j]
		end
	end
	for i in 1:k
		for j in 1:k
			bb[i+1,j+1]+=bb[i,j+1]
			ww[i+1,j+1]+=ww[i,j+1]
		end
	end
	s = 0
	for i in 1:k
		for j in 1:k
			s = max(s,bb[k+1,k+1]-bb[i,k+1]-bb[k+1,j]+bb[i,j]+ww[i,k+1]+ww[k+1,j]-ww[i,j],ww[k+1,k+1]-ww[i,k+1]-ww[k+1,j]+ww[i,j]+bb[i,k+1]+bb[k+1,j]-bb[i,j])
		end
	end
	println(s)
end

main()

Score : 500 points

Problem Statement

AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K.
Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square.
Below is an example of a checked pattern of side 3:

AtCoDeer has N desires.
The i-th desire is represented by x_i, y_i and c_i.
If c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white.
At most how many desires can he satisfy at the same time?

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 1000

0 ≤ x_i ≤ 10^9

0 ≤ y_i ≤ 10^9

If i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).

c_i is B or W.

N, K, x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N

Output

Print the maximum number of desires that can be satisfied at the same time.

Sample Input 1

4 3
0 1 W
1 2 W
5 3 B
5 4 B

Sample Output 1

4

He can satisfy all his desires by painting as shown in the example above.

Sample Input 2

2 1000
0 0 B
0 1 W

Sample Output 2

2

Sample Input 3

6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

Sample Output 3

4


const lines=readlines()
input()=shift!(lines)
int(s)=parse(Int32,s)
intLine()=map(int,split(input()))
function nextLine(k)
    x,y,c=split(input())
    int(x)%2k+1,(int(y)+(c=="W")k)%2k+1
end
function solve(k,g)
    m=0
    for i=1:2k,j=1:2k
        a=0
        for x=-1:2,y=-1:2
            (x+y)%2!=0&&continue
            v,w=i+x*k,j+y*k
            v>0<w&&(a+=g[min(2k,v)][min(2k,w)])
            v>k&&w>0&&(a-=g[min(2k,v-k)][min(2k,w)])
            w>k&&v>0&&(a-=g[min(2k,v)][min(2k,w-k)])
            v>k<w&&(a+=g[min(2k,v-k)][min(2k,w-k)])
        end
        m=max(m,a)
    end
    m
end
function main()
    n,k=intLine()
    g=Array{Int32,1}[[0for j=1:2k]for i=1:2k]
    for i=1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    println(solve(k,cumsum(map(cumsum,g))))
end
main()


const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function nextLine(k::Int32)
    x,y,c=split(input())
    intSub(x)%2k+1,(intSub(y)+(c=="W")k)%2k+1
end
function main()
    n,k=intLine()
    g=Array{Int32,1}[[0for j in 1:2k]for i in 1:2k]
    for i in 1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    g=cumsum(map(cumsum,g))
    m=0
    for i in 1:2k
        for j in 1:2k
            a=0
            for x in-1:1
                for y in-1:1
                    if(x+y)%2!=0;continue;end
                    v,w=i+x*k,j+y*k
                    if v>0<w;a+=g[min(2k,v)][min(2k,w)];end
                    if v>k&&w>0;a-=g[min(2k,v-k)][min(2k,w)];end
                    if w>k&&v>0;a-=g[min(2k,v)][min(2k,w-k)];end
                    if v>k<w;a+=g[min(2k,v-k)][min(2k,w-k)];end
                end
            end
            m=max(m,a)
        end
    end
    println(m)
end
main()


const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function nextLine(k::Int32)
    x,y,c=split(input())
    intSub(x)%2k+1,(intSub(y)+(c=="W")k)%2k+1
end
function main()
    n,k=intLine()
    g=Array{Int32,1}[[0for j in 1:2k]for i in 1:2k]
    for i in 1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    g=cumsum(map(cumsum,g))
    m=0
    for i in 1:2k
        for j in 1:2k
            a=0
            for x in -1:2
                for y in -1:2
                    if(x+y)%2!=0;continue;end
                    v,w=i+x*k,j+y*k
                    if v>0<w;a+=g[min(2k,v)][min(2k,w)];end
                    if v>k&&w>0;a-=g[min(2k,v-k)][min(2k,w)];end
                    if w>k&&v>0;a-=g[min(2k,v)][min(2k,w-k)];end
                    if v>k<w;a+=g[min(2k,v-k)][min(2k,w-k)];end
                end
            end
            m=max(m,a)
        end
    end
    println(m)
end
main()


lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine()=map(intSub,split(input()))
function nextLine(k::Int)
    x,y,c=split(input())
    intSub(x)%2k+1,(intSub(y)+(c=="W")k)%2k+1
end
in(x::Int,y::Int,r::Int)=0<x<=r&&0<y<=r
function main()
    n,k=intLine()
    g=[[0for j in 1:2k]for i in 1:2k]
    for i in 1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    g=cumsum(map(cumsum,g))
    m=0
    for i in 1:2k
        for j in 1:2k
            a=0
            for x in 0:2
                for y in 0:2
                    if (x+y)%2>0;continue;end
                    v,w=i+x*k,j+y*k
                    a+=g[min(2k,v)][min(2k,w)]
                    if v>k;a-=g[min(2k,v-k)][min(2k,w)];end
                    if w>k;a-=g[min(2k,v)][min(2k,w-k)];end
                    if w>k<v;a+=g[min(2k,v-k)][min(2k,w-k)];end
                end
            end
            m=max(m,a)
        end
    end
    println(m)
end
main()


Score : 100 points

Problem Statement

On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.

After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.

Constraints

S is a string of length 10.

The first eight characters in S are 2017/01/.

The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

Replace the first four characters in S with 2018 and print it.

Sample Input 1

2017/01/07

Sample Output 1

2018/01/07

Sample Input 2

2017/01/31

Sample Output 2

2018/01/31


S = readline()
print(S[1:3]*"8"*S[5:end])


parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	x = [0 for i in 1:n]
	for i in 1:n
		x[i] = parseInt(readline())
	end
	x = sort(x)
	count = 1
	for i in 2:n
		if x[i] > x[i-1]
			count += 1
		end
	end
	print(count)
end

main()

Score : 200 points

Problem Statement

An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.

Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

Constraints

1 ≤ N ≤ 100

1 ≤ d_i ≤ 100

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
d_1
:
d_N

Output

Print the maximum number of layers in a kagami mochi that can be made.

Sample Input 1

4
10
8
8
6

Sample Output 1

3

If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.

Sample Input 2

3
15
15
15

Sample Output 2

1

When all the mochi have the same diameter, we can only have a 1-layered kagami mochi.

Sample Input 3

7
50
30
50
100
50
80
30

Sample Output 3

4


Score : 100 points

Problem Statement

How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?

Constraints

1≤M≤23

M is an integer.

Input

Input is given from Standard Input in the following format:

M

Output

If we have x hours until New Year at M o'clock on 30th, December, print x.

Sample Input 1

21

Sample Output 1

27

We have 27 hours until New Year at 21 o'clock on 30th, December.

Sample Input 2

12

Sample Output 2

36


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

prime_memo = Dict{Int, Bool}()
like_memo = Dict{Int, Bool}()

function isPrime(n)
    if haskey(prime_memo, n)
        return prime_memo[n]
    end

    if n == 1
        return false
    end
    for i in 2:sqrt(n)
        if n % i == 0
            prime_memo[n] = false
            return false
        end
    end
    prime_memo[n] = true
    return true
end

function isLike(n)
    if haskey(like_memo, n)
        return like_memo[n]
    end
    like_memo[n] =  isPrime(n) && isPrime((n + 1) ÷ 2)
    return like_memo[n]
end

function main()
    A = Array{Int}(undef, 10^5)
    for i in 1:10^5 - 1
        if isLike(i)
            A[i + 1] = A[i] + 1
        else
            A[i + 1] = A[i]
        end
    end
    Q = parseInt(readline())
    for _ in 1:Q
        l, r = parseMap(split(readline()))
        if l == 1
            println(A[r])
        else
            println(A[r + 1] - A[l])
        end

    end
end

main()

Score : 400 points

Problem Statement

We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.

You are given Q queries.

In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Constraints

1≤Q≤10^5

1≤l_i≤r_i≤10^5

l_i and r_i are odd.

All input values are integers.

Input

Input is given from Standard Input in the following format:

Q
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

Sample Input 1

1
3 7

Sample Output 1

2

3 is similar to 2017, since both 3 and (3+1)/2=2 are prime.

5 is similar to 2017, since both 5 and (5+1)/2=3 are prime.

7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime.

Thus, the response to the first query should be 2.

Sample Input 2

4
13 13
7 11
7 11
2017 2017

Sample Output 2

1
0
0
1

Note that 2017 is also similar to 2017.

Sample Input 3

6
1 53
13 91
37 55
19 51
73 91
13 49

Sample Output 3

4
4
1
1
1
2


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

prime_memo = Dict{Int, Bool}()
like_memo = Dict{Int, Bool}()

function isPrime(n)
    if haskey(prime_memo, n)
        return prime_memo[n]
    end

    if n == 1
        return false
    end
    for i in 2:sqrt(n)
        if n % i == 0
            prime_memo[n] = false
            return false
        end
    end
    prime_memo[n] = true
    return true
end

function isLike(n)
    if haskey(like_memo, n)
        return like_memo[n]
    end
    like_memo[n] =  isPrime(n) && isPrime((n + 1) ÷ 2)
    return like_memo[n]
end

function main()
    A = Array{Int}(undef, 10^5)
    for i in 1:10^5 - 1
        if isLike(i)
            A[i + 1] = A[i] + 1
        else
            A[i + 1] = A[i]
        end
    end

    Q = parseInt(readline())
    for _ in 1:Q
        l, r = parseMap(split(readline()))
        if l == 1
            println(A[r])
        else
            println(A[r] - A[l - 1])

        end

    end
end

main()


parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)
test(x) = x*x

function main()
  q = parseInt(readline())
  x = Array{Int}(2,q)
  for i in 1:q
    x[:,i] = readline() |> split |> parseMap
  end
  x = map(test,x)
  print("こう書くとさらに加速する")
end

main()


a,b,c,d = map(x->parse(x),split(readline()))
answer(x,y) = println(x>y?"Left":x<y?"Right":"Balanced")
answer(a+b,c+d)

Score : 100 points

Problem Statement

A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.

Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Constraints

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Sample Input 1

3 8 7 1

Sample Output 1

Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.

Sample Input 2

3 4 5 2

Sample Output 2

Balanced

The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.

Sample Input 3

1 7 6 4

Sample Output 3

Right

The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.


parseInt(x) = parse(Int, x)

function main()
	x,y = readline() |> split |> t->parseInt.(t)
	count = 1
	while x <= y+1
		x *= 2
		count += 1
	end
	print(count-1)
end

main()

Score : 300 points

Problem Statement

As a token of his gratitude, Takahashi has decided to give his mother an integer sequence.
The sequence A needs to satisfy the conditions below:

A consists of integers between X and Y (inclusive).

For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.

Find the maximum possible length of the sequence.

Constraints

1 \leq X \leq Y \leq 10^{18}

All input values are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the maximum possible length of the sequence.

Sample Input 1

3 20

Sample Output 1

3

The sequence 3,6,18 satisfies the conditions.

Sample Input 2

25 100

Sample Output 2

3

Sample Input 3

314159265 358979323846264338

Sample Output 3

31


s=chomp(readline())
ans=length(s)
for i=1:length(s)-1
  if s[i]!=s[i+1]
    s[T=end]
    ans=min(ans,max(i,T-i))
  end
end
println(ans)

Score : 500 points

Problem Statement

You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.

Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.

Constraints

1\leq |S|\leq 10^5

S_i(1\leq i\leq N) is either 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.

Sample Input 1

010

Sample Output 1

2

We can turn all the characters of S into 0 by the following operations:

Perform the operation on the segment S[1,3] with length 3. S is now 101.

Perform the operation on the segment S[1,2] with length 2. S is now 011.

Perform the operation on the segment S[2,3] with length 2. S is now 000.

Sample Input 2

100000000

Sample Output 2

8

Sample Input 3

00001111

Sample Output 3

4


a,b = parse.(Int,split(readline()))
println(convert(Int,ceil((a+b)/2)))

Score : 100 points

Problem Statement

You are given two positive integers a and b.
Let x be the average of a and b.
Print x rounded up to the nearest integer.

Constraints

a and b are integers.

1 \leq a, b \leq 100

Input

Input is given from Standard Input in the following format:

a b

Output

Print x rounded up to the nearest integer.

Sample Input 1

1 3

Sample Output 1

2

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.

Sample Input 2

7 4

Sample Output 2

6

The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.

Sample Input 3

5 5

Sample Output 3

5


ParseInt(x) = parse(Int,x)
ParseMap(x::Array{SubString{String},1}) = map(ParseInt,x)
function main()
  a,b = ParseMap(split(readline()))
  println((Int)((a + b + 1) / 2))
end
main()


Score : 200 points

Problem Statement

You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.

Notes

For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:

N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.

There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.

For example, xy < xya and atcoder < atlas.

Constraints

The lengths of s and t are between 1 and 100 (inclusive).

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If it is possible to satisfy s' < t', print Yes; if it is not, print No.

Sample Input 1

yx
axy

Sample Output 1

Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

Sample Input 2

ratcode
atlas

Sample Output 2

Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.

Sample Input 3

cd
abc

Sample Output 3

No

No matter how we rearrange cd and abc, we cannot achieve our objective.

Sample Input 4

w
ww

Sample Output 4

Yes

Sample Input 5

zzz
zzz

Sample Output 5

No


let
  a=parse.(Int,split(readlines()[2]))
  s=0
  for i=unique(a)
    c=count(isequal(i),a)
    s+=c<i ? c : c-i end
  println(s) end

Score : 300 points

Problem Statement

You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.

Here, an sequence b is a good sequence when the following condition holds true:

For each element x in b, the value x occurs exactly x times in b.

For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.

Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of elements that needs to be removed so that a will be a good sequence.

Sample Input 1

4
3 3 3 3

Sample Output 1

1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

Remove one occurrence of 10^9. Then, () is a good sequence.

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5


p(x)=parse(Int64,x)

function main()
  a=parse(Int64, readline())
  b=map(p,split(readline()))
  c=Dict{Int64,Int64}()
  n=length(b)
  temp=0
  for i in b
    if temp !== n
     if haskey(c,i)
       a = count(x->x==i,b)
       temp+=a
       a[i]=a
      end
    else
      break
    end
  end
   temp2=0
    for i in c
      a,b=i
      if a>b
        temp2+=b
       else
        temp2+=b-a
      end

    end
print(temp2)
end
main()


readline()
D=Dict{Int,Int}()
for a=map(x->parse(Int,x),split(readline()))
	D[a]=get(D,a,0)+1
end
ans=0
for (k,v)=D
	ans+=k<=v ? v-k : v
end
println(ans)


lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine()=map(intSub,split(input()))
function main()
  n=int(input())
  a=intLine()
end
main()


parseInt(x) = parse(Int,x)
function main()
  n = parseInt(readline())
  a = parseInt.(split(readline()))
  print("定義だけしてみる")
end

main()


function main()
  n = parse(readline())
  a = parse.(split(readline()))
  print("simplest")
end

main()


parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	a = map(parseInt, split(readline()))
	d = Dict{Int, Int}()
	for i in 1:n
		if haskey(d,a[i])
			d[a[i]] += 1
		else
			d[a[i]]=1
		end
	end
	count = 0
	for i in keys(d)
		if i < d[i]
			count += d[i]-i
		elseif i > d[i]
			count += d[i]
		end
	end
	print(count)
end

main()


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = chomp(readline())
	x,y = readline() |> split |> parseMap
	h = Int[]
	v = Int[]
	f = 0
	c = 0
	for i in 1:length(s)
		if s[i] == 'T'
			if f == 0
				push!(h,c)
				f = 1
			else
				push!(v,c)
				f = 0
			end
			c = 0
		else
			c += 1
		end
	end
	if s[length(s)] == 'F'
		if f == 0
			push!(h,c)
		else
			push!(v,c)
		end
	end
	sh = sum(h)
	dph = zeros(Int,length(h), 2*sh+1)
	if length(h)>0
		dph[1,sh+1+h[1]] = 1
	end
	for i in 2:length(h)
		for j in 1:2*sh+1
			if j <= h[i]
				dph[i,j] = dph[i-1,j+h[i]]
			elseif j >= 2*sh+1-h[i]
				dph[i,j] = dph[i-1,j-h[i]]
			else
				dph[i,j] = max(dph[i-1,j+h[i]], dph[i-1,j-h[i]])
			end
		end
	end
	sv = sum(v)
	dpv = zeros(Int,length(v), 2*sv+1)
	if length(v)>0
		dpv[1,sv+1+v[1]] = 1
		dpv[1,sv+1-v[1]] = 1
	end
	for i in 2:length(v)
		for j in 1:2*sv+1
			if j <= v[i]
				dpv[i,j] = dpv[i-1,j+v[i]]
			elseif j >= 2*sv+1-v[i]
				dpv[i,j] = dpv[i-1,j-v[i]]
			else
				dpv[i,j] = max(dpv[i-1,j+v[i]], dpv[i-1,j-v[i]])
			end
		end
	end
	if sh+x+1<0||sh+x+1>2*sh+1||sv+y+1<0||sv+y+1>2*sv+1
		println("No")
	elseif length(h) == 0 && length(v) == 0
		println(x==0&&y==0?"Yes":"No")
	elseif length(h) == 0
		println(x==0&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	elseif length(v) == 0
		println(dph[length(h),sh+x+1]==1&&y==0?"Yes":"No")
	else
		println(dph[length(h),sh+x+1]==1&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	end
end
main()

Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No


n = parse(Int, readline())
numbers = tryparse.(Int,split(readline()))

count = 0
num = 0
total = 0
for i = 1:n
  global total |= numbers[i]
end

while total&1 ==0
 global total >>= 1
 global count += 1
end

println(count)

Score : 200 points

Problem Statement

There are N positive integers written on a blackboard: A_1, ..., A_N.

Snuke can perform the following operation when all integers on the blackboard are even:

Replace each integer X on the blackboard by X divided by 2.

Find the maximum possible number of operations that Snuke can perform.

Constraints

1 \leq N \leq 200

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible number of operations that Snuke can perform.

Sample Input 1

3
8 12 40

Sample Output 1

2

Initially, [8, 12, 40] are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.

After the operation is performed once, [4, 6, 20] are written on the blackboard.
Since all those integers are again even, he can perform the operation.

After the operation is performed twice, [2, 3, 10] are written on the blackboard.
Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.

Thus, Snuke can perform the operation at most twice.

Sample Input 2

4
5 6 8 10

Sample Output 2

0

Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.

Sample Input 3

6
382253568 723152896 37802240 379425024 404894720 471526144

Sample Output 3

8


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,k=parseMap(split(readline()))
    a=parseMap(split(readline()))
    cnt=Dict{Int,Int}()
    for i in a
        if haskey(cnt,i)
            cnt[i]+=1
        else
            cnt[i]=1
        end
    end
    val=sort(collect(values(cnt)),rev=true)
    ans=0
    len=length(val)
    if len>k
        for i in k+1:len
            ans+=val[i]
        end
    end
    println(ans)
end
main()

Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

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

Sample Output 3

3


N=parse(Int,readline())
A=map(x->parse(Int,x),split(readline()))
mi=Mi=1
for i=2:N
	if A[mi]>A[i]
		mi=i
	end
	if A[Mi]<A[i]
		Mi=i
	end
end
ans=Array{Pair{Int,Int}}(0)
if -A[mi]<=A[Mi]
	for i=1:N
		if i!=Mi
			push!(ans,Mi=>i)
			A[i]+=A[Mi]
		end
	end
else
	for i=1:N
		if i!=mi
			push!(ans,mi=>i)
			A[i]+=A[mi]
		end

	end
end
if A[1]>=0
	for i=1:N-1
		push!(ans,i=>i+1)
	end
else
	for i=N:-1:2
		push!(ans,i=>i-1)
	end
end
println(length(ans))
for (k,v)=ans
	println("$k $v")
end

Score : 600 points

Problem Statement

Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is a_{i}.

He can perform the following operation any number of times:

Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.

He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations.
It can be proved that such a sequence of operations always exists under the constraints in this problem.

Condition: a_1 \leq a_2 \leq ... \leq a_{N}

Constraints

2 \leq N \leq 50

-10^{6} \leq a_i \leq 10^{6}

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Let m be the number of operations in your solution. In the first line, print m.
In the i-th of the subsequent m lines, print the numbers x and y chosen in the i-th operation, with a space in between.
The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations.

Sample Input 1

3
-2 5 -1

Sample Output 1

2
2 3
3 3

After the first operation, a = (-2,5,4).

After the second operation, a = (-2,5,8), and the condition is now satisfied.

Sample Input 2

2
-1 -3

Sample Output 2

1
2 1

After the first operation, a = (-4,-3) and the condition is now satisfied.

Sample Input 3

5
0 0 0 0 0

Sample Output 3

0

The condition is satisfied already in the beginning.


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	if minimum(a)>0
		println(n-1)
		for i in 1:n-1
			println(i," ",i+1)
		end
	elseif maximum(a)<0
		println(n-1)
		for i in n:-1:2
			println(i," ",i-1)
		end
	else
		r = indmax(a)
		l = indmin(a)
		println(2*n-1)
		if a[r]>-a[l]
			for i in 1:n
				println(i," ",r)
			end
			for i in 1:n-1
				println(i," ",i+1)
			end
		else
			for i in 1:n
				println(i," ",l)
			end
			for i in n:-1:2
				println(i," ",i-1)
			end
		end
	end
end

main()


function main()

  (N,A,B) = map(x -> parse(Int,x), split(readline()))

  println(min(A*N,B))

end

main()

Score : 100 points

Problem Statement

You are parking at a parking lot. You can choose from the following two fee plans:

Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.

Plan 2: The fee will be B yen, regardless of the duration.

Find the minimum fee when you park for N hours.

Constraints

1≤N≤20

1≤A≤100

1≤B≤2000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

When the minimum fee is x yen, print the value of x.

Sample Input 1

7 17 120

Sample Output 1

119

If you choose Plan 1, the fee will be 7×17=119 yen.

If you choose Plan 2, the fee will be 120 yen.

Thus, the minimum fee is 119 yen.

Sample Input 2

5 20 100

Sample Output 2

100

The fee might be the same in the two plans.

Sample Input 3

6 18 100

Sample Output 3

100


function main()
	N,C=map(x->parse(Int,x),split(readline()))
	M=[[0 for _=1:10^5] for _=1:C]
	for s=readlines()
		L,R,c=map(x->parse(Int,x),split(s))
		for i=L:R
			M[c][i]=1
		end
	end
	ans=0
	for i=1:10^5
		now=0
		for j=1:C
			if M[j][i]==1
				now+=1

			end
		end
		ans=max(ans,now)
	end
	println(ans)
end
main()

Score : 400 points

Problem Statement

Joisino is planning to record N TV programs with recorders.

The TV can receive C channels numbered 1 through C.

The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.

Here, there will never be more than one program that are broadcast on the same channel at the same time.

When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).

Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

Constraints

1≤N≤10^5

1≤C≤30

1≤s_i<t_i≤10^5

1≤c_i≤C

If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N C
s_1 t_1 c_1
:
s_N t_N c_N

Output

When the minimum required number of recorders is x, print the value of x.

Sample Input 1

3 2
1 7 2
7 8 1
8 12 1

Sample Output 1

2

Two recorders can record all the programs, for example, as follows:

With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.

With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Sample Input 2

3 4
1 3 2
3 4 4
1 4 3

Sample Output 2

3

There may be a channel where there is no program to record.

Sample Input 3

9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3

Sample Output 3

2


function main()
    N = pread(Int)
    ds = readvec(Int, N)
    mt = maximum(ds)
    for d in 0:23
        for i in 1:N, j in 1:i-1
            as = ds[i], (24 - ds[i]) % 24
            bs = ds[j], (24 - ds[j]) % 24
            tmp = maximum([abs(a-b) for a in as, b in bs])
            if tmp < mt
                mt = tmp
            end
        end
    end
    println(mt)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()

Score : 500 points

Problem Statement

In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.

Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours.
The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours.
Here, we are using 24-hour notation.
That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example.

Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours.

Find the maximum possible value of s.

Constraints

1 \leq N \leq 50

0 \leq D_i \leq 12

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the maximum possible value of s.

Sample Input 1

3
7 12 8

Sample Output 1

4

For example, consider the situation where it is 7, 12 and 16 o'clock in each person's city at the moment when it is 0 o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is 4 hours.

Sample Input 2

2
11 11

Sample Output 2

2

Sample Input 3

1
0

Sample Output 3

0

Note that Takahashi himself is also a participant.


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n = readline()
    if n[1] == n[2] == n[3] || n[2] == n[3] == n[4]
        println("Yes")
    else
        println("No")
    end
end
main()

Score : 100 points

Problem Statement

We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.

You are given a 4-digit integer N. Answer the question: Is N good?

Constraints

1000 ≤ N ≤ 9999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is good, print Yes; otherwise, print No.

Sample Input 1

1118

Sample Output 1

Yes

N is good, since it contains three consecutive 1.

Sample Input 2

7777

Sample Output 2

Yes

An integer is also good when all the digits are the same.

Sample Input 3

1234

Sample Output 3

No


function main()

  N = split(chomp(readline()),"")

  if N[1] == N[2] == N[3] || N[2] == N[3] == N[4]
    println("Yes")
  else
    println("No")
  end

end

main()


s=readline()
print(maximum(count(x->x==i,s)for i in '0':'9')>2?"Yes":"No")


if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  l=chomp(readline())
  a,b,c,d=[pI(i) for i=l]
  if a+b+c+d==7
    println(a,"+",b,"+",c,"+",d,"=7")
  elseif a+b+c-d==7
    println(a,"+",b,"+",c,"-",d,"=7")
  elseif a+b-c+d==7
    println(a,"+",b,"-",c,"+",d,"=7")
  elseif a+b-c-d==7
    println(a,"+",b,"-",c,"-",d,"=7")
  elseif a-b+c+d==7
    println(a,"-",b,"+",c,"+",d,"=7")
  elseif a-b+c-d==7
    println(a,"-",b,"+",c,"-",d,"=7")
  elseif a-b-c+d==7
    println(a,"-",b,"-",c,"+",d,"=7")
  elseif a-b-c-d==7
    println(a,"-",b,"-",c,"-",d,"=7")
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7


Score : 100 points

Problem Statement

In programming, hexadecimal notation is often used.

In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.

In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.

When X and Y are seen as hexadecimal numbers, which is larger?

Constraints

Each X and Y is A, B, C, D, E or F.

Input

Input is given from Standard Input in the following format:

X Y

Output

If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.

Sample Input 1

A B

Sample Output 1

<

10 < 11.

Sample Input 2

E C

Sample Output 2

>

14 > 12.

Sample Input 3

F F

Sample Output 3

=

15 = 15.


Score : 500 points

Problem Statement

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.

Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:

Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.

The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.

X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints

All input values are integers.

1 \leq N \leq 2000

1 \leq Z, W, a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

If X draws all the cards first, the score will be |1000 - 100| = 900.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,z,w = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	if n == 1
		println(abs(a[n]-w))
	else
		println(max(abs(a[n]-w),abs(a[n]-a[n-1])))
	end
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,z,w = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	maxim = 0
	for i in 1:-1
		pmax = max(z,maximum(a[1:i]))
		pmin = min(z,maximum(a[1,i]))
		maxim = max(maxim,min(abs(a[i+1:n].-pmax)),min(abs(a[i+1:n].-pmin)))
	end
	maxim = max(maxim,abs(max(z,maximum(a))-w),abs(min(z,maximum(a))-w))
	println(maxim)
end

main()


N, Z, W = parse.(split(readline(STDIN)))
a = parse.(split(readline(STDIN)))
unshift!(a, W)
N += 1

dpx, dpy = Vector{Int}(N), Vector{Int}(N)

function f(isx, pos)
    if isx
        return dpx[pos] = max(abs(a[pos] - a[N]), pos < N-1 ? maximum([f(false, p) for p in pos+1:N-1]) : typemin(Int64))
    else
        return dpy[pos] = min(abs(a[pos] - a[N]), pos < N-1 ? minimum([f(true, p) for p in pos+1:N-1]) : typemax(Int64))
    end
end

ans = f(true, 1)
println(ans)


Score : 200 points

Problem Statement

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

1 \leq N \leq 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the largest square number not exceeding N.

Sample Input 1

10

Sample Output 1

9

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.

Sample Input 2

81

Sample Output 2

81

Sample Input 3

271828182

Sample Output 3

271821169


N=parse(Int,readline())
A=sort(map(x->parse(Int,x),split(readline())))
B=sort(map(x->parse(Int,x),split(readline())))
C=sort(map(x->parse(Int,x),split(readline())))
x=[0 for _=1:N]
id=1
for a=A
	while id<=N&&B[id]<=a
		id+=1
	end
	if id<=N
		x[id]+=1
	end
end
y=[0 for _=1:N]
now=0
id=1
for i=1:N
	now+=x[i]
	while id<=N&&C[id]<=B[i]
		id+=1
	end
	if id<=N
		y[id]+=now
	end
end
now=0
ans=0
for i=1:N
	now+=y[i]
	ans+=now
end
println(ans)

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


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = parseInt(readline())
	a = parseMap(split(readline()))
	a = sort(a)
	b = parseMap(split(readline()))
	b = sort(b)
	bb = Int[]
	c = parseMap(split(readline()))
	cc = Int[]

	print("f")
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function maxp(a,x)
	count = 1
	while a[count] < x && count<length(a)
		count += 1
	end
	if a[length(a)] < x
		count += 1
	end
	return(count-1)
end

function main()
	n = parseInt(readline())
	a = parseMap(split(readline()))
	a = sort(a)
	b = parseMap(split(readline()))
	b = sort(b)
	bb = Int[]
	c = parseMap(split(readline()))
	c = sort(c)
	cc = Int[]
	for i in 1:n
		push!(cc, maxp(b,c[i]))
	end
	push!(bb, maxp(a,b[1]))
	for i in 2:n
		push!(bb, maxp(a,b[i])+bb[length(bb)])
	end
	sum = 0
	for i in 1:length(cc)
    	if cc[i] > 0
			sum += bb[cc[i]]
    	end
    end
	print(sum)
end

main()


N = parse(Int,input())
a = parse.(Int,split(input()))
b = parse.(Int,split(input()))
c = parse.(Int,split(input()))

# N = 6
# a = [3, 14, 159, 2, 6, 53]
# b = [58, 9, 79, 323, 84, 6]
# c = [2643, 383, 2, 79, 50, 288]

sort!(a, rev=true)
sort!(b, rev=true)
sort!(c, rev=true)

alist = map(ai->count(map(bi-> ai<bi, b)), a)
blist = map(bi->count(map(ci-> bi<ci, c)), b)

# alist = [sum(list(map(lambda bi: 1 if ai < bi else 0, b))) for ai in a]
# # # blist = [smaller_than_c(bi) for bi in b]
# blist = [sum(list(map(lambda ci: 1 if bi < ci else 0, c))) for bi in b]
#
# # sum(list(map(lambda ai: 1 if ai < bi else 0, b)))
# [sum([blist[j] for j in range(alist[i])]) for i in range(N)]
# print(sum([sum([blist[j] for j in range(alist[i])]) for i in range(N)]))
# println(sum[blist[j] for j=1:alist[i], i = 1:N])
println(sum([sum(blist[1:alist[i]]) for i = 1:N]))


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

R = parseInt(readline())
G = parseInt(readline())

println(2G - R)

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.


s=readline()
for i=2:length(s)
  if s[i-1:i]=="AC"
    println("Yes")
    exit()
  end
end
println("No")

Score : 100 points

Problem Statement

Snuke built an online judge to hold a programming contest.

When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring.
(The judge can return any two-character substring of S.)

Determine whether the judge can return the string AC as the verdict to a program.

Constraints

2 \leq |S| \leq 5

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If the judge can return the string AC as a verdict to a program, print Yes; if it cannot, print No.

Sample Input 1

BACD

Sample Output 1

Yes

The string AC appears in BACD as a contiguous substring (the second and third characters).

Sample Input 2

ABCD

Sample Output 2

No

Although the string ABCD contains both A and C (the first and third characters), the string AC does not appear in ABCD as a contiguous substring.

Sample Input 3

CABD

Sample Output 3

No

Sample Input 4

ACACA

Sample Output 4

Yes

Sample Input 5

XX

Sample Output 5

No


N=parse(Int,readline())
c=0
for a=map(x->parse(Int,x),split(readline()))
  c+=1-a%2
end
println(3^N-2^c)

Score : 200 points

Problem Statement

We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are similar when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N).

In particular, any integer sequence is similar to itself.

You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N.

How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?

Constraints

1 \leq N \leq 10

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of integer sequences that satisfy the condition.

Sample Input 1

2
2 3

Sample Output 1

7

There are seven integer sequences that satisfy the condition:

1, 2

1, 4

2, 2

2, 3

2, 4

3, 2

3, 4

Sample Input 2

3
3 3 3

Sample Output 2

26

Sample Input 3

1
100

Sample Output 3

1

Sample Input 4

10
90 52 56 71 44 8 13 30 57 84

Sample Output 4

58921


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c=parseMap(split(readline()))
    if a==b
        println(c)
    elseif a==c
        println(b)
    else
        println(a)
    end
end
main()

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


function find(parent,u)
	if u==parent[u]
		u
	else
		parent[u]=find(parent,parent[u])
	end
end
function check(E,N)
	parent=collect(1:N)
	size=ones(Int,N)
	for (u,v)=E
		u=find(parent,u)
		v=find(parent,v)
		if u!=v
			if size[u]<size[v]
				parent[u]=v
				size[v]+=size[u]
			else
				parent[v]=u
				size[u]+=size[v]
			end
		end
	end
	length(unique(find(parent,i) for i=1:N))==1
end
function main()
	lines=readlines()
	N,M=map(x->parse(Int,x),split(shift!(lines)))
	E=Pair{Int,Int}[]
	for s=lines
		x,y=map(x->parse(Int,x),split(s))
		push!(E,x=>y)
	end
	cnt=0
	for i=1:M
		F=Pair{Int,Int}[]
		for j=1:i-1
			push!(F,E[j])
		end
		for j=i+1:M
			push!(F,E[j])
		end
		if !check(F,N)
			cnt+=1
		end
	end
	println(cnt)
end
main()

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.


s = chomp(readline())
println(s[1:length(s)-8])

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


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function root(uf::Array{Int,1},x);s=x;while uf[s]>0;s=uf[s];end;s;end
same(uf::Array{Int,1},x,y)=root(uf,x)==root(uf,y)?true:false;
function unite(uf::Array{Int,1},x,y);l=root(uf,x);r=root(uf,y);if l!=r;if uf[l]<uf[r];uf[l]+=uf[r];uf[r]=l;else;uf[r]+=uf[l];uf[l]=r;end;end;end

function main()
	n,m = readline() |> split |> parseMap
	d = zeros(Int,n)
	e = Tuple{Int,Int}[(0,0) for i in 1:m]
	for i in 1:m
		a,b = readline() |> split |> parseMap
		d[a] += 1
		d[b] += 1
		e[i] = (a,b)
	end
	fo = 0
	fn = 0
	for i in 1:n
		if d[i]==1
			fo += 1
		elseif d[i]==n-1
			fn += 1
		end
	end
	if fo==n-1&&fn==1&&m+1==n
		println(0)
	else
		uf = -ones(Int,2*n)
		for i in 1:m
			unite(uf,e[i][1],e[i][2]+n)
			unite(uf,e[i][1]+n,e[i][2])
		end
		f = 0
		for i in 1:n
			if same(uf,i,n+i)
				f = 1
				break
			end
		end
		if f==1
			println(div(n*(n-1),2)-m)
		elseif n%2==0
			println((n>>1)^2-m)
		else
			println((n>>1)*(n>>1+1)-m)
		end
	end
end

main()

Score : 500 points

Problem Statement

Rng has a connected undirected graph with N vertices.
Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i.

Rng will add new edges to the graph by repeating the following operation:

Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.

Find the maximum possible number of edges that can be added.

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i,B_i \leq N

The graph has no self-loops or multiple edges.

The 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

Find the maximum possible number of edges that can be added.

Sample Input 1

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

Sample Output 1

4

If we add edges as shown below, four edges can be added, and no more.

Sample Input 2

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

Sample Output 2

5

Five edges can be added, for example, as follows:

Add an edge connecting Vertex 5 and Vertex 3.

Add an edge connecting Vertex 5 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 1.

Add an edge connecting Vertex 4 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 3.


parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    flg=false
    for h in 1:3500
        for w in h:3500
            res=n*h*w/(4*h*w-n*w-n*h)
            if res>0 && isinteger(res)
                println("$h $w $(Int(res))")
                flg=true
                break
            end
        end
        if flg
            break
        end
    end
end
main()

Score : 300 points

Problem Statement

You are given an integer N.

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

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

Constraints

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

Inputs

Input is given from Standard Input in the following format:

N

Outputs

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

h n w

Sample Input 1

2

Sample Output 1

1 2 2

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

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

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

Sample Input 3

4664

Sample Output 3

3498 3498 3498


parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	f = 0
	for i in 1:3500
		for j in 1:3500
			if 4*i*j-n*i-n*j>0
				if (n*i*j)%(4*i*j-n*i-n*j)==0
					println(i, " ", j, " ", div(n*i*j,4*i*j-n*i-n*j))
					f = 1
					break
				end
			end
		end
		if f == 1
			break
		end
	end
end

main()


Score : 100 points

Problem Statement

Snuke prepared 6 problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.

You are given a string S of length 6.
If the i-th character of s is 1, it means that the i-th problem prepared by Snuke is accepted to be used; 0 means that the problem is not accepted.

How many problems prepared by Snuke are accepted to be used in the contest?

Constraints

The length of S is 6.

S consists of 0 and 1.

Inputs

Input is given from Standard Input in the following format:

S

Outputs

Print the number of problems prepared by Snuke that are accepted to be used in the contest.

Sample Input 1

111100

Sample Output 1

4

The first, second, third and fourth problems are accepted, for a total of four.

Sample Input 2

001001

Sample Output 2

2

Sample Input 3

000000

Sample Output 3

0


parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N = parseInt(readline())
    min_score = 10^18
    min_ = -1
    for i in 1:N
        a,b = parsed_data = readline() |> split |> parseMap
        if b<min_score
            min_score = b
            min_ = a
        end

  end
  println(min_score+min_)
end

main()

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