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

function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n = readline() |> parseInt
	d = readline() |> split |> parseMap
	z = zeros(Int,13)
	for i in 1:n
		z[d[i]+1]+=1
	end
	f = z[1]
	for i in 2:13
		if z[i]>2
			f = 1
		end
	end
	if f>0
		println(0)
	else
		a = Int[]
		base = zeros(Int,24)
		base[1] = 1
		for i in 1:12
			if z[i+1]==1
				push!(a,i)
			elseif z[i+1]>1
				base[i+1]+=1
				base[25-i]+=1
			end
		end
		l = length(a)
		z = zeros(Int,l)
		q = 0
		while z!=0
			c = copy(base)
			for i in 1:l
				if z[i]==0
					c[a[i]+1]+=1
				else
					c[25-a[i]]+=1
				end
			end
			dis = 24
			nd = 1
			for i in 2:24
				if c[i]>1
					dis = 0
				elseif c[i]==1
					dis = min(dis,nd)
					nd = 1
				else
					nd += 1
				end
			end
			if c[1]>1
				dis = 0
			elseif c[1]==1
				dis = min(dis,nd)
				nd = 1
			end
			q = max(q,dis)
			if isempty(z)
				z=0
			else
				z[l]+=1
				z=moveup(z,2)
			end
		end
		println(q)
	end
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.


n = string(readline())
a=0
for i=1:9
    occursin("$i$i$i",n) ? a=1 : a = 0
end
if a == 0
    println("No")
else println("Yes")
end

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

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

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()
  x = parse.(split(readline(), ""))
  if x[1]==x[2]==x[3] || x[2]==x[3]==x[4]
    print("Yes")
  else
    print("No")
  end
end

main()


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=readline()
    res=[[] for i in 1:4]
    push!(res[1],a[1])
    for i in 2:4
        for j in res[i-1]
            push!(res[i],join([j,'+',a[i]]))
            push!(res[i],join([j,'-',a[i]]))
        end
    end
    for i in res[4]
        num=parseInt(i[1])
        for j in 1:3
            if i[2*j]=='+'
                num+=parseInt(i[2*j+1])
            else
                num-=parseInt(i[2*j+1])
            end
        end
        if num==7
            println(i*"=7")
            break
        end
    end
end
main()

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


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

function func(x)
	s = 0
	while x > 0
		s += x%10
		x = div(x,10)
	end
	s
end

function main()
	h,w = readline() |> split |> parseMap
	c = Array{Int}(10,10)
	for i in 1:10
		c[:,i] = readline() |> split |> parseMap
	end
	a = Array{Int}(w,h)
	for i in 1:h
		a[:,i] = readline() |> split |> parseMap
	end

	for i in 1:10
		for j in 1:10
			for k in 1:10
				c[i,j] = min(c[i,j],c[i,k]+c[k,j])
			end
		end
	end
	total = 0
	for i in 1:w
		for j in 1:h
			if a[i,j] != -1
				total += c[2,a[i,j]+1]
			end
		end
	end
	println(total)
end

main()

Score : 400 points

Problem Statement

Joisino the magical girl has decided to turn every single digit that exists on this world into 1.

Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).

She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).

You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:

If A_{i,j}≠-1, the square contains a digit A_{i,j}.

If A_{i,j}=-1, the square does not contain a digit.

Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.

Constraints

1≤H,W≤200

1≤c_{i,j}≤10^3 (i≠j)

c_{i,j}=0 (i=j)

-1≤A_{i,j}≤9

All input values are integers.

There is at least one digit on the wall.

Input

Input is given from Standard Input in the following format:

H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}

Output

Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.

Sample Input 1

2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8

Sample Output 1

12

To turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.

The wall contains two 8s, so the minimum total MP required is 6×2=12.

Sample Input 2

5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Sample Output 2

0

Note that she may not need to change any digit.

Sample Input 3

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

Sample Output 3

47


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()
    x,y=split(readline())
    if x==y
        println("=")
    elseif x<y
        println("<")
    else
        println(">")
    end
end
main()

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.


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

main()

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


N, Z, W = parse.(split(readline(STDIN)))
a = parse.(split(readline(STDIN)))

ans = max(abs(W - a[N]), N > 1 ? abs(a[N-1] - a[N]) : typemin(Int))

println(ans)


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

dpx, dpy = fill(-1, N), fill(-1, N)

function f(isx, pos)
    if isx
        if dpx[pos] < 0
            dpx[pos] = max(abs(a[pos] - a[N]), pos < N-1 ? maximum([f(false, p) for p in pos+1:N-1]) : typemin(Int64))
        end
        return dpx[pos]
    else
        if dpy[pos] < 0
            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
        return dpy[pos]
    end
end

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


n = parse(Int, readline())
print(floor(Int, sqrt(n))^2)

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


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function maxp(a,x)
	count = 0
	for i in 1:length(a)
		if a[i] < x
			count += 1
		end
	end
	return(count)
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
	for i in 1:n
		push!(bb, maxp(a,b[i]))
	end
	sum = 0
	for i in 1:length(cc)
		for j in 1:cc[i]
			sum += bb[j]
		end
	end
	print(sum)
end

main()

Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N \leq 10^5

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

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

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

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

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

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

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

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

Sample Output 3

87


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.


function main()

  S = chomp(readline())

  check = false

  for i in 1:length(S)-1
    if S[i] == 'A' && S[i+1] == 'C'
      check = true
      break
    end
  end

  if check
    println("Yes")
  else
    println("No")
  end

end

main()

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


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)
sumdigits(n) = sum(digits(n))

n=parseInt(readline())
arr=Set{String}()
function dfs(cnt,s)
    if n==cnt
        push!(arr,s)
        return 0
    end
    for i in ["0","1","2"]
        dfs(cnt+1,s*i)
    end
end

function main()
    a=parseMap(split(readline()))
    dfs(0,"")
    ans=0
    for i in arr
        for j in 1:n
            if i[j]=='0' && a[j]%2==0
                ans+=1
                break
            elseif i[j]=='1' && (a[j]-1)%2==0
                ans+=1
                break
            elseif i[j]=='2' && (a[j]+1)%2==0
                ans+=1
                break
            end
        end
    end
    println(ans)
end
main()

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


function main()

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

  if A == B
    println(C)
  elseif B == C
    println(A)
  else
    println(B)
  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


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 root(par::Vector{Int},x::Int)
    index=par[x]
    while par[index]!=index
        index=par[index]
    end
    return index
end

function unite(par::Vector{Int},x::Int,y::Int)
    rx,ry=root(par,x),root(par,y)
    if rx==ry
        return
    elseif rx>ry
        rx,ry=ry,rx
    end
    par[ry]=rx
end

function same(par::Vector{Int},x::Int,y::Int)
    return root(par,x)==root(par,y)
end

function main()
    n,m=parseMap(split(readline()))
    data=[parseMap(split(readline())) for i in 1:m]
    ans=0
    # 取り除く辺を全探索してUnion-Findを構築
    for ng in 1:m
        par=[i for i in 1:n]
        for i in 1:m
            if i==ng
                continue
            end
            unite(par,data[i][1],data[i][2])
        end
        renketsu=true
        r=root(par,1)
        for i in 2:n
            if root(par,i)!=r
                renketsu=false
                break
            end
        end
        if !renketsu
            ans+=1
        end
    end
    println(ans)
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.


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

function main()
	n,k = readline() |> split |> parseMap
	a = Array{Int}(2,n)
	for i in 1:n
		a[:,i] = readline() |> split |> parseMap
	end
	a = sortcols(a,by=x->x[1])
	m = 9223372036854775807
	for i in 1:n-k+1
		x = a[1,i+k-1]-a[1,i]
		uy = a[2,i]
		ly = a[2,i]
		for j in i+1:i+k-1
			uy = max(uy, a[2,j])
			ly = min(ly, a[2,j])
		end
		m = min(m, x*(uy-ly))
  end

	println(m)
end

main()

Score : 400 points

Problem Statement

We have N points in a two-dimensional plane.

The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i).

Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.

Here, points on the sides of the rectangle are considered to be in the interior.

Find the minimum possible area of such a rectangle.

Constraints

2 \leq K \leq N \leq 50

-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)

x_i≠x_j (1 \leq i<j \leq N)

y_i≠y_j (1 \leq i<j \leq N)

All input values are integers. (Added at 21:50 JST)

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1
:
x_{N} y_{N}

Output

Print the minimum possible area of a rectangle that satisfies the condition.

Sample Input 1

4 4
1 4
3 3
6 2
8 1

Sample Output 1

21

One rectangle that satisfies the condition with the minimum possible area has the following vertices: (1,1), (8,1), (1,4) and (8,4).

Its area is (8-1) × (4-1) = 21.

Sample Input 2

4 2
0 0
1 1
2 2
3 3

Sample Output 2

1

Sample Input 3

4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999

Sample Output 3

3999999996000000001

Watch out for integer overflows.


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
		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
		println(f==0?(n>>1)^2-m:div(n*(n-1),2)-m)
	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)
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
		println(0)
	else
		if n%2==1
			println(div(n*(n-1),2)-m)
		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
			println(f==0?div(n*(n-1),2)-div((n>>1)*(n>>1+1),2)-m:div(n*(n-1),2)-m)
		end
	end
end

main()


function main()
	N=parse(Int,readline())
	for h=1:3500,w=1:3500
		a=N*h*w
		b=4*h*w-N*(h+w)
		if b>0&&a%b==0
			println("$h $w $(div(a,b))")
			exit()
		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


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 = readline() |> parseInt
	p = 0
	q = 0
	for i in 1:n
		a,b = readline() |> split |> parseMap
		if p<a
			p = a
			q = b
		end
	end
	println(p+q)
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


N,M,K=map(x->parse(Int,x),split(readline()))
flag=false
for i=0:N,j=0:M
  if K==i*M+j*N-i*j
    flag=true
  end
end
println(flag?"Yes":"No")

Score : 200 points

Problem Statement

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column.
When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.
When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

1 \leq N,M \leq 1000

0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.

Sample Input 1

2 2 2

Sample Output 1

Yes

Press the buttons in the order of the first row, the first column.

Sample Input 2

2 2 1

Sample Output 2

No

Sample Input 3

3 5 8

Sample Output 3

Yes

Press the buttons in the order of the first column, third column, second row, fifth column.

Sample Input 4

7 9 20

Sample Output 4

No


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

function main()
	h,w = readline() |> split |> parseMap
	d = zeros(Int,26)
	for i in 1:h
		a = readline() |> chomp
		for j in 1:w
			d[Int(a[j])-96] += 1
		end
	end
	x = (h>>1)*(w>>1)
	y = h%2*(w>>1)+w%2*(h>>1)
	z = h*w%2
	ct = 0
	for i in 1:26
		if d[i]%2==1
			ct += 1
		end
	end
	if ct!=z
		println("No")
	else
		ct = 0
		for i in 1:26
			if d[i]%4==2
				ct += 1
			end
		end
		if ct>y
			println("No")
		else
			println("Yes")
		end
	end

end

main()

Score : 400 points

Problem Statement

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

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

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

Determine whether he can create a matrix satisfying the condition.

Note

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

Constraints

1 ≤ H, W ≤ 100

a_{ij} is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4
aabb
aabb
aacc

Sample Output 1

Yes

For example, the following matrix satisfies the condition.

abba
acca
abba

Sample Input 2

2 2
aa
bb

Sample Output 2

No

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

Sample Input 3

5 1
t
w
e
e
t

Sample Output 3

Yes

For example, the following matrix satisfies the condition.

t
e
w
e
t

Sample Input 4

2 5
abxba
abyba

Sample Output 4

No

Sample Input 5

1 1
z

Sample Output 5

Yes


function main()
	H,W=map(x->parse(Int,x),split(readline()))
	cnt=zeros(Int,26)
	for _=1:H
		for c=chomp(readline())
			cnt[Int(c)-96]+=1
		end
	end
	c4=c2=c1=0
	if H%2==1&&W%2==1
		c1=1
		c2=div(H-1,2)+div(W-1,2)
	elseif H%2==1&&W%2==0
		c2=div(W,2)
	elseif H%2==0&&W%2==1
		c2=div(H,2)
	end
	c4=div(H*W-c1-2c2,4)
	for i=1:26
		t=min(c4,div(cnt[i],4))
		c4-=t
		cnt[i]-=4t
	end
	for i=1:26
		t=min(c2,div(cnt[i],2))
		c2-=t
		cnt[i]-=2t
	end
	println(c4==c2==0&&sum(cnt)==c1 ? "Yes" : "No")
end
main()


Score : 100 points

Problem Statement

We have an N \times N square grid.

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

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

Constraints

1 \leq N \leq 100

0 \leq A \leq N^2

Inputs

Input is given from Standard Input in the following format:

N
A

Outputs

Print the number of squares that will be painted black.

Sample Input 1

3
4

Sample Output 1

5

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

Sample Input 2

19
100

Sample Output 2

261

Sample Input 3

10
0

Sample Output 3

100

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


n = parse(Int, readline())
a = parse(Int, readline())
println(n^2 - a)


function main()

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

  ans = 0

  for i in 1:N

    ans += min(2x[i],2abs(K-x[i]))

  end

  println(ans)

end

main()

Score : 200 points

Problem Statement

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

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

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

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

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

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

Constraints

1 \leq N \leq 100

1 \leq K \leq 100

0 < x_i < K

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
K
x_1 x_2 ... x_N

Outputs

Print the minimum possible total distance covered by robots.

Sample Input 1

1
10
2

Sample Output 1

4

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

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

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

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

Sample Input 2

2
9
3 6

Sample Output 2

12

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

Sample Input 3

5
20
11 12 9 17 12

Sample Output 3

74


const a,b,c,d,e,f = map(x -> parse(Int,x), split(readline()))
ai = bi = ci = di = 0
const amax = fld(30,a)
const bmax = fld(30,b)
const cmax = fld(3000,c)
const dmax = fld(3000,d)
wat = 100
sug = 0
iwat = 0
isug = 0

for ai = 0:amax,bi = 0:bmax,ci = 0:cmax,di = 0:dmax
    iwat = 100*(ai*a+bi*b)
    isug = ci*c+di*d
    if iwat+isug <= f && isug/iwat <= e/100
        if isug*wat > sug*iwat
            wat = iwat
            sug = isug
        end
    end
end
print("$(wat+sug) $sug")

Score : 300 points

Problem Statement

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

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

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

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

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

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

Snuke will make sugar water with the highest possible density.

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

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

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

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

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

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

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

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

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

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

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

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

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

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934


function solve(A, B, C, D, E, F)
    i = j = k = l = 0
    max = -Inf
    solution = (i, j, k, l)
    ok() = k * C + l * D ≤ E * (i * A + j * B) && 100 * i * A + 100 * j * B + k * C + l * D ≤ F
    while ok()
        while ok()
            while ok()
                while ok()
                    x = 100 * (k * C + l * D) / (i * 100A + j * 100B + k * C + l * D)
                    if x > max
                        solution = (i, j, k, l)
                        max = x
                    end
                    l += 1
                end
                l = 0
                k += 1
            end
            k = l = 0
            j += 1
        end
        j = k = l = 0
        i += 1
    end
    i, j, k, l = solution
    println(i * 100A + j * 100B + k * C + l * D, " ", k * C + l * D)
end

A, B, C, D, E, F = [parse(Int, x) for x in split(readline())]
solve(A, B, C, D, E, F)


function main()

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

  if in("9",N)
    println("Yes")
  else
    println("No")
  end

end

main()

Score : 100 points

Problem Statement

It is September 9 in Japan now.

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

Constraints

10≤N≤99

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

29

Sample Output 1

Yes

The one's digit of 29 is 9.

Sample Input 2

72

Sample Output 2

No

72 does not contain 9.

Sample Input 3

91

Sample Output 3

Yes


function main()

  N = parse(Int,readline())

  dict = Dict()

  for i in 1:N
    A = chomp(readline())
    dict[A] = get(dict,A,0) + 1
  end

  ans = 0

  for i in keys(dict)
    if dict[i] % 2 == 1
      ans += 1
    end
  end

  println(ans)

end

main()

Score : 300 points

Problem Statement

You are playing the following game with Joisino.

Initially, you have a blank sheet of paper.

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

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

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

Constraints

1≤N≤100000

1≤A_i≤1000000000(=10^9)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

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

Sample Input 1

3
6
2
6

Sample Output 1

1

The game proceeds as follows:

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

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

6 is written on the sheet, so erase 6.

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

Sample Input 2

4
2
5
5
2

Sample Output 2

0

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

Sample Input 3

6
12
22
16
22
18
12

Sample Output 3

2


function f(D,X,u)
	if isempty(X)
		return 0
	end
	ret=1145141919810
	for i=1:length(X)
		W=Int[]
		for j=1:length(X)
			if i!=j
				push!(W,X[j])
			end
		end
		ret=min(ret,f(D,W,X[i])+D[u][X[i]])
	end
	ret
end
p(x)=map(y->parse(Int,y),split(x))
function main()
	N,M,R=p(readline())
	r=p(readline())
	D=[[1145141919810 for _=1:N] for _=1:N]
	for i=1:N
		D[i][i]=0
	end
	for s=readlines()
		a,b,c=p(s)
		D[a][b]=D[b][a]=c
	end
	for k=1:N,i=1:N,j=1:N
		D[i][j]=min(D[i][j],D[i][k]+D[k][j])
	end
	ans=1145141919810
	for i=1:R
		now=Int[]
		for j=1:R
			if i!=j
				push!(now,r[j])
			end
		end
		ans=min(ans,f(D,now,r[i]))
	end
	println(ans)
end
main()

Score : 400 points

Problem Statement

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

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

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

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

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

Constraints

2≤N≤200

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

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

r_i≠r_j (i≠j)

1≤A_i,B_i≤N, A_i≠B_i

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

1≤C_i≤100000

Every town can be reached from every town by road.

All input values are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

4

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

Sample Input 3

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

Sample Output 3

3


Score : 100 points

Problem Statement

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

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

Constraints

1≤X≤10^9

1≤t≤10^9

X and t are integers.

Input

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

X t

Output

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

Sample Input 1

100 17

Sample Output 1

83

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

Sample Input 2

48 58

Sample Output 2

0

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

Sample Input 3

1000000000 1000000000

Sample Output 3

0


s=readline()
for i=1:endof(s)
	if i%2==1
		print(s[i])
	end
end

Score : 200 points

Problem Statement

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

Constraints

Each character in s is a lowercase English letter.

1≤|s|≤10^5

Input

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

s

Output

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

Sample Input 1

atcoder

Sample Output 1

acdr

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

Sample Input 2

aaaa

Sample Output 2

aa

Sample Input 3

z

Sample Output 3

z

Sample Input 4

fukuokayamaguchi

Sample Output 4

fkoaaauh


parseInt(x) = parse(Int, x)

x, a, b = map(parseInt,split(readline()))

println(abs(x - a) < abs(x - b) ? 'A' : 'B')

Score : 100 points

Problem Statement

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

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

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

Constraints

1 \leq x \leq 1000

1 \leq a \leq 1000

1 \leq b \leq 1000

x, a and b are pairwise distinct.

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

Input

Input is given from Standard Input in the following format:

x a b

Output

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

Sample Input 1

5 2 7

Sample Output 1

B

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

Sample Input 2

1 999 1000

Sample Output 2

A


parseInt(x) = parse(Int, x)

x, a, b = map(parseInt(split(readline())))

println(abs(x - a) < abs(x - b) ? 'A' : 'B')


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

count = Dict()

for a in A
    count[a] = get(count,a,0) + 1
end

count2 = sort([x for x in count if x.second >= 2],by = x->x.first,rev = true)
count4 = sort([x for x in count if x.second >= 4],by = x->x.first,rev = true)

ans = 0

if length(count2) > 2
    ans = count2[1].first * count2[2].first
end

if length(count4) > 0
    ans = max(ans, count4[1].first * count4[1].first)
end

if length(count2) > 1 && length(count4) > 1
    ans = max(ans, count2[1].first * count4[1].first)
end

println(ans)

Score : 300 points

Problem Statement

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

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

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20


N = readline()

if N = reverse(N)
  println("Yes")
else
  println("No")
end

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

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

Constraints

100≤N≤999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

575

Sample Output 1

Yes

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

Sample Input 2

123

Sample Output 2

No

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

Sample Input 3

812

Sample Output 3

No


n = parse(Int, readline())

if n % 10 == div(n, 100)
    println("Yes")
else
    println("No")
end


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

function main()
	a = parseInt.(split(readline()))
	if a[1] < a[3]
		if a[2] < a[4]
			print(max(a[2]-a[3], 0))
		else
			print(a[4]-a[3])
		end
	else
		if a[4] < a[2]
			print(max(a[4]-a[1], 0))
		else
			print(a[2]-a[1])
		end
	end
end

main()

Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

Sample Input 1

0 75 25 100

Sample Output 1

50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

Sample Input 2

0 33 66 99

Sample Output 2

0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

Sample Input 3

10 90 20 80

Sample Output 3

60


parseInt(x) = parse(Int, x)
function main()
	n = parseInt(readline())
	t = Array{Int}(n)
	for i in 1:n
		t[i] = readline() |> parseInt
	end
	print(lcm(t))
end
main()

Score : 300 points

Problem Statement

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

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

Now, Dolphin starts all the clocks simultaneously.

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

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

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

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

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

Sample Input 1

2
2
3

Sample Output 1

6

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

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

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

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

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000


inputs = split(deadline(), ' ')
inputs = map(x -> parse(Int, x), inputs)

m = inputs[0]
n = inputs[1]

print((m - 1) * (n - 1))

Score : 100 points

Problem Statement

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

Constraints

2 ≤ n, m ≤ 100

Input

Input is given from Standard Input in the following format:

n m

Output

Print the number of blocks in K-city.

Sample Input 1

3 4

Sample Output 1

6

There are six blocks, as shown below:

Sample Input 2

2 2

Sample Output 2

1

There are one block, as shown below:


x = chomp(readline())
l=length(x)
print(x[1], l-2, x[l])

Score : 200 points

Problem Statement

The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.

You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

Constraints

3 ≤ |s| ≤ 100 (|s| denotes the length of s.)

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the abbreviation of s.

Sample Input 1

internationalization

Sample Output 1

i18n

Sample Input 2

smiles

Sample Output 2

s4s

Sample Input 3

xyz

Sample Output 3

x1z


b1=b2=b4=0
readline()
for a=map(x->parse(Int,x),split(readline()))
  if a%4==0
    b4+=1
  elseif a%2==0
    b2+=1
  else
    b1+=1
  end
end
println(b4+(b2==0)>=b1 ? "Yes" : "No")

Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


Score : 100 points

Problem Statement

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

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

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

Constraints

100 ≤ N ≤ 999

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

100

Sample Output 1

ABC100

The 100th round of ABC is ABC100.

Sample Input 2

425

Sample Output 2

ABC425

Sample Input 3

999

Sample Output 3

ABC999


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()
  println(2^floor(Int,log2(pI(readline()))))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Score : 200 points

Problem Statement

Takahashi loves numbers divisible by 2.

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

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

For example,

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

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

3 can be divided by 2 zero times.

Constraints

1 ≤ N ≤ 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

7

Sample Output 1

4

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

Sample Input 2

32

Sample Output 2

32

Sample Input 3

1

Sample Output 3

1

Sample Input 4

100

Sample Output 4

64


function main()

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

  T = Tuple[]

  check_1 = []
  check_N = []

  for i in 1:M
    (a, b) = map(x -> parse(Int, x), split(readline()))
    if a == 1
      push!(check_1, b)
    elseif b == N
      push!(check_N, a)
    end
  end

  ans = false

  for i in check_1, j in check_N
    if i == j
      ans = true
    end
  end

  if ans
    println("POSSIBLE")
  else
    println("IMPOSSIBLE")
  end

end

main()

Score : 300 points

Problem Statement

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

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

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

Help him.

Constraints

3 ≤ N ≤ 200 000

1 ≤ M ≤ 200 000

1 ≤ a_i < b_i ≤ N

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

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

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

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

Sample Input 1

3 2
1 2
2 3

Sample Output 1

POSSIBLE

Sample Input 2

4 3
1 2
2 3
3 4

Sample Output 2

IMPOSSIBLE

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

Sample Input 3

100000 1
1 99999

Sample Output 3

IMPOSSIBLE

Sample Input 4

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

Sample Output 4

POSSIBLE

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


function main()

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

  T = Tuple[]

  for i in 1:M
    (a, b) = map(x -> parse(Int, x), split(readline()))
    push!(T, (a, b))
  end

  ans = false

  for i in 1:M

    if T[i][1] == 1
      for j in 1:M
        if T[j][1] == T[i][2] && T[j][2] == N
          ans = true
        end
      end
    end

  end

  if ans
    println("POSSIBLE")
  else
    println("IMPOSSIBLE")
  end

end

main()


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

function main()
	n, m = parseMap(split(readline()))
	x = [Int64[] for i in 1:n]
	for i in 1:m
		a, b = parseMap(split(readline()))
		push!(x[a], b)
		push!(x[b], a)
	end
	flg = 0
	for i in 2:n-1
		if 1 in x[i] && n in x[i]
			print("POSSIBLE")
			flg = 1
			break
		end
	end
	if flg == 0
		print("IMPOSSIBLE")
	end
end

main()


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

function main()
	k = readline() |> parseInt
	x = div(k,50)
	y = k%50
	a = Int[i-1 for i in 1:50]
	a.+= x
	for i in 1:y
		a[i] += 51
	end
	a.-=y
	println(a)
end
main()

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller.

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

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

You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

Constraints

0 ≤ K ≤ 50 \times 10^{16}

Input

Input is given from Standard Input in the following format:

K

Output

Print a solution in the following format:

N
a_1 a_2 ... a_N

Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.

Sample Input 1

0

Sample Output 1

4
3 3 3 3

Sample Input 2

1

Sample Output 2

3
1 0 3

Sample Input 3

2

Sample Output 3

2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].

Sample Input 4

3

Sample Output 4

7
27 0 0 0 0 0 0

Sample Input 5

1234567894848

Sample Output 5

10
1000 193 256 777 0 1 1192 1234567891011 48 425


read N K;julia -E"A=parse.(split(readline()));(maximum(A)<$K||$K%gcd(A)?"'"IM":"")~"POSSIBLE"'

Score : 300 points

Problem Statement

There is a box containing N balls. The i-th ball has the integer A_i written on it.
Snuke can perform the following operation any number of times:

Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.

Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq K \leq 10^9

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

If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.

Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5.
Next, take out 3 and 5, and return them back along with abs(3-5)=2.
Finally, take out 9 and 2, and return them back along with abs(9-2)=7.
Now we have 7 in the box, and the answer is therefore POSSIBLE.

Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.

Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

The box already contains 11 before we do anything. The answer is therefore POSSIBLE.

Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE


a,b = parse.(split(readline()))
if a%3==0 || b%3 == 0 || (a+b)%3==0
  print("Possible")
else
  print("Impossible")
end

Score : 100 points

Problem Statement

Snuke is giving cookies to his three goats.

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

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

Constraints

1 \leq A,B \leq 100

Both A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

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

Sample Input 1

4 5

Sample Output 1

Possible

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

Sample Input 2

1 1

Sample Output 2

Impossible

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


a, b = parse.(split(readline()))
if (a+b)%3 == 0
  println("Possible")
else
  println("Impossible")
end


(a, b) = parse.([Int], split(readline()))

if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0
    println("Possible")
else
    println("Impossible")
end


(n, k) = parse.([Int], split(readline()))
ls = parse.([Int], split(readline()))

println(sum(reverse!(sort!(ls))[1:k]))

Score : 200 points

Problem Statement

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

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

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

Constraints

1 \leq K \leq N \leq 50

1 \leq l_i \leq 50

l_i is an integer.

Input

Input is given from Standard Input in the following format:

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

Output

Print the answer.

Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

12

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

Sample Input 2

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

Sample Output 2

386


function main()

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

  Su = 0
  Ar = sum(a)
  ans = 10^10

  for i in 1:N-1
    Su += a[i]
    Ar -= a[i]
    ans = min(ans,abs(Su-Ar))
  end

  println(ans)

end

main()

Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.

They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

Constraints

2 \leq N \leq 2 \times 10^5

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

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Print the answer.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.


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=parseInt(readline())
    a=parseMap(split(readline()))
    l=[0 for i in 1:n]
    l[1]=a[1]
    for i in 2:n
        l[i]=l[i-1]+a[i]
    end
    ans=10^10
    for i in 1:n-1
        ans=min(ans,abs(l[i]-(l[end]-l[i])))
    end
    println(ans)
end
main()


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
function same(uf::Array{Int,1},x,y);root(uf,x)==root(uf,y)?true:false;end
function unite(uf::Array{Int,1},x,y);l=root(uf,x);r=root(uf,y);if l<r;uf[l]+=uf[r];uf[r]=l;elseif l>r;uf[r]+=uf[l];uf[l]=r;end;end

function main()
	n = readline() |> parseInt
	e = [Int[] for i in 1:n]
	da = Array{Int}(2,n-1)
	for i in 1:n-1
		da[:,i] = readline() |> split |> parseMap
		push!(e[da[1,i]],da[2,i])
		push!(e[da[2,i]],da[1,i])
	end
	c = -ones(Int,n)
	c[1] = 0
	d = -ones(Int,n)
	d[n] = 0
	s = Int[1]
	while !isempty(s)
		now = shift!(s)
		for i in 1:length(e[now])
			if c[e[now][i]] < 0
				push!(s,e[now][i])
				c[e[now][i]] = c[now]+1
			end
		end
	end
	s = Int[n]
	while !isempty(s)
		now = shift!(s)
		for i in 1:length(e[now])
			if d[e[now][i]] < 0
				push!(s,e[now][i])
				d[e[now][i]] = d[now]+1
			end
		end
	end
	th = div(c[n]+1,2)
	ti = c[n]-th
	o = 1
	p = n
	for i in 2:n-1
		if c[i]==th && d[i]==ti
			o = i
		end
		if c[i] == th+1 && d[i] == ti-1
			p = i
		end
	end
	uf = -ones(Int,n)
	for i in 1:n-1
		if da[:,i] != [o,p] && da[:,i] != [p,o]
			unite(uf,da[1,i],da[2,i])
		end
	end
	println(uf[root(uf,1)]<=uf[root(uf,n)]?"Fennec":"Snuke")
end

main()

Score : 400 points

Problem Statement

Fennec and Snuke are playing a board game.

On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.

Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored.
Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell.
More specifically, each player performs the following action in her/his turn:

Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.

Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.

A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Constraints

2 \leq N \leq 10^5

1 \leq a_i, b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

If Fennec wins, print Fennec; if Snuke wins, print Snuke.

Sample Input 1

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

Sample Output 1

Fennec

For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.

Sample Input 2

4
1 4
4 2
2 3

Sample Output 2

Snuke


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

function main()
	n,a,b,c,d = readline() |> split |> parseMap
	f = 0
	for i in 0:n-1
		if i*(-d)+(n-i-1)*c<=b-a<=i*(-c)+(n-i-1)*d
			f = 1
		end
	end
	println(f==1?"YES":"NO")
end

main()

Score : 400 points

Problem Statement

There are N squares in a row.
The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.

Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:

For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).

As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares.
Determine whether it is possible to fill the squares under the condition.

Constraints

3 \leq N \leq 500000

0 \leq A \leq 10^9

0 \leq B \leq 10^9

0 \leq C \leq D \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B C D

Output

Print YES if it is possible to fill the squares under the condition; print NO otherwise.

Sample Input 1

5 1 5 2 4

Sample Output 1

YES

For example, fill the squares with the following integers: 1, -1, 3, 7, 5, from left to right.

Sample Input 2

4 7 6 4 5

Sample Output 2

NO

Sample Input 3

48792 105960835 681218449 90629745 90632170

Sample Output 3

NO

Sample Input 4

491995 412925347 825318103 59999126 59999339

Sample Output 4

YES


(n, a, b, c, d) = parse.([Int], split(readline()))

f(m) = a + m * c - (n - 1 - m) * d <= b && b <= a + m * d - (n - 1 - m) * c
println(any(map(f, [m for m in 0:n-1]))? "YES" : "NO")


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

function main()
	n,m = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	f = zeros(Int,n)
	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
	for i in keys(d)
		for j in 0:d[i]-1
			if i-j>0
				f[i-j] += 1
			end
		end
	end
	s = 0
	for i in 1:n
		if f[i] == 0
			s += 1
		end
	end
	for i in 1:m
		x,y = readline() |> split |> parseMap
		if a[x]-d[a[x]]+1>0
			f[a[x]-d[a[x]]+1] -= 1
			if f[a[x]-d[a[x]]+1] == 0
				s += 1
			end
		end
		d[a[x]] -= 1
		if haskey(d,y)
			d[y] += 1
		else
			d[y] = 1
		end
		a[x] = y
		if y-d[y]+1>0
			if f[y-d[y]+1] == 0
				s -= 1
			end
			f[y-d[y]+1] += 1
		end
		println(s)
	end
end

main()

Score : 1000 points

Problem Statement

There are N balls in a row.
Initially, the i-th ball from the left has the integer A_i written on it.

When Snuke cast a spell, the following happens:

Let the current number of balls be k. All the balls with k written on them disappear at the same time.

Snuke's objective is to vanish all the balls by casting the spell some number of times.
This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable.

By the way, the integers on these balls sometimes change by themselves.
There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j.

After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.

Constraints

1 \leq N \leq 200000

1 \leq M \leq 200000

1 \leq A_i \leq N

1 \leq X_j \leq N

1 \leq Y_j \leq N

Subscore

In the test set worth 500 points, N \leq 200 and M \leq 200.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N
X_1 Y_1
X_2 Y_2
:
X_M Y_M

Output

Print M lines.
The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable.

Sample Input 1

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

Sample Output 1

0
1
1

After the first change, the integers on the balls become 2, 1, 3, 4, 5, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.

After the second change, the integers on the balls become 2, 5, 3, 4, 5, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.

After the third change, the integers on the balls become 2, 5, 3, 4, 4, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.

Sample Input 2

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

Sample Output 2

0
1
2
3

Sample Input 3

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

Sample Output 3

1
0
1
2
2
3
3
3
3
2


function main()

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

  pop!(s)

  count = 0

  while true

    if length(s) % 2 == 0

      for i in 1:div(length(s),2)

        if s[i] == s[i+div(length(s),2)]
          count += 1
        else
          check = false
        end

      end

    end

    if count == div(length(s),2)
      break
    elseif length(s) == 0
      break
    end

    pop!(s)
    count = 0
  end

  println(length(s))

end

main()

Score : 200 points

Problem Statement

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

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

Constraints

2 \leq |S| \leq 200

S is an even string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

abaababaab

Sample Output 1

6

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

abaababaa is not even.

abaababa is not even.

abaabab is not even.

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

Sample Input 2

xxxx

Sample Output 2

2

xxx is not even.

xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

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

Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

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


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=parseInt(readline())
    a=parseMap(split(readline()))
    b=Vector{Int}()
    muki=true
    for i in a
        push!(b,i)
        reverse!(b)
    end
    println(join(b," "))
end
main()

Score : 300 points

Problem Statement

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

The i-th operation is as follows:

Append a_i to the end of b.

Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

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

0 \leq a_i \leq 10^9

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

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

Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3

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

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

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

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

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

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

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

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

Thus, the answer is 4 2 1 3.

Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

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

Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7


N=parse(Int,readline())
ap=[0 for _=1:N]
id=1
L=R=-1
for a=map(x->parse(Int,x),split(readline()))
	if ap[a]>0
		L,R=ap[a],id
		break
	end
	ap[a]=id
	id+=1
end
mod=10^9+7
F=Int[1]
for i=1:N+1
	push!(F,F[end]*i%mod)
end
I=[1 for _=1:N+2]
I[N+2]=invmod(F[N+2],mod)
for i=N+1:-1:1
	I[i]=I[i+1]*i%mod
end
b(n,r)=n>=r ? F[n+1]*I[n-r+1]%mod*I[r+1]%mod : 0
for k=1:N+1
	println((b(N+1,k)-b(L+N-R,k-1)+mod)%mod)
end

Score : 600 points

Problem Statement

You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.
It is known that each of the n integers 1,...,n appears at least once in this sequence.

For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Notes

If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

Constraints

1 \leq n \leq 10^5

1 \leq a_i \leq n

Each of the integers 1,...,n appears in the sequence.

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_{n+1}

Output

Print n+1 lines.
The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.

Sample Input 1

3
1 2 1 3

Sample Output 1

3
5
4
1

There are three subsequences with length 1: 1 and 2 and 3.

There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.

There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.

There is one subsequence with length 4: 1,2,1,3.

Sample Input 2

1
1 1

Sample Output 2

1
1

There is one subsequence with length 1: 1.

There is one subsequence with length 2: 1,1.

Sample Input 3

32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9

Sample Output 3

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

Be sure to print the numbers modulo 10^9+7.


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function abmp(a,b,p);if b==0;1;elseif b%2==0;k=abmp(a,div(b,2),p);(k*k)%p;else;(a*abmp(a,b-1,p))%p;end;end;;
function binarr(n,p);z=1;for i in 1:n;z=z*i%p;end;fac=Array{Int}(n+1);inv=Array{Int}(n+1);inv[n+1]=abmp(z,p-2,p)
for i in 0:n-1;inv[n-i]=(inv[n+1-i]*(n-i))%p;end;for i in 0:n;fac[i+1]=(((z*inv[i+1])%p)*inv[n+1-i])%p;end;fac;end;
mod(a,p)=a<0?a+p:a

function main()
	p = 10^9+7
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	c = zeros(Int,n)
	d = [0,0]
	for i in 1:n+1
		if c[a[i]] == 0
			c[a[i]] = i
		else
			d[1] = c[a[i]]
			d[2] = i
			break
		end
	end
	b = binarr(n+1,p)
	l = binarr(d[1]+n-d[2],p)
	for i in 1:n+1
		if i<=d[1]+n-d[2]+1
			println(mod(b[i+1]-l[i],p))
		else
			println(b[i+1])
		end
	end
end

main()


X,A,B=map(x->parse(Int,x),split(readline()))
println(-A+B<=0 ? "delicious" : -A+B<=X ? "safe" : "dangerous")

Score : 100 points

Problem Statement

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

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

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

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

Constraints

1 ≤ X,A,B ≤ 10^9

Input

Input is given from Standard Input in the following format:

X A B

Output

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

Sample Input 1

4 3 6

Sample Output 1

safe

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

Sample Input 2

6 5 1

Sample Output 2

delicious

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

Sample Input 3

3 7 12

Sample Output 3

dangerous

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


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

function main()
	p = 10^9+7
	n,m = readline() |> split |> parseMap
	if abs(n-m)>1
		println(0)
	elseif n==m
		x = 2
		for i in 1:n
			x=x*i%p
		end
		for i in 1:m
			x=x*i%p
		end
		println(x)
	else
		x = 1
		for i in 1:n
			x=x*i%p
		end
		for i in 1:m
			x=x*i%p
		end
		println(x)
	end
end

main()

Score : 300 points

Problem Statement

Snuke has N dogs and M monkeys. He wants them to line up in a row.

As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.

How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Constraints

1 ≤ N,M ≤ 10^5

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of possible arrangements, modulo 10^9+7.

Sample Input 1

2 2

Sample Output 1

8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

Sample Input 2

3 2

Sample Output 2

12

Sample Input 3

1 8

Sample Output 3

0

Sample Input 4

100000 100000

Sample Output 4

530123477


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

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	f = 0
	ma = maximum(a)
	mi = minimum(a)
	if ma-mi>1
		f = 1
	else
		ax = 0
		ix = 0
		for i in 1:n
			if a[i]==ma
				ax+=1
			else
				ix+=1
			end
		end
		if ix+ax>>1<ma
			f = 1
		elseif ix+1>ma
			f = 1
		end
		if ax==n&&ma==n-1
			f = 0
		end
	end
	println(f==0?"Yes":"No")
end
main()

Score : 700 points

Problem Statement

There are N cats.
We number them from 1 through N.

Each of the cats wears a hat.
Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."

Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N-1

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.

Sample Input 1

3
1 2 2

Sample Output 1

Yes

For example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.

Sample Input 2

3
1 1 2

Sample Output 2

No

From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.
Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.
Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.

Sample Input 3

5
4 3 4 3 4

Sample Output 3

No

Sample Input 4

3
2 2 2

Sample Output 4

Yes

Sample Input 5

4
2 2 2 2

Sample Output 5

Yes

Sample Input 6

5
3 3 3 3 3

Sample Output 6

No


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

function main()
	hh,ww,h,w = readline() |> split |> parseMap
	if hh==h&&ww==w
		println("No")
	elseif (h==2&&hh%2==0)||(w==2&&ww%2==0)
		println("No")
	else
		println("Yes")
		for i in 1:hh
			for j in 1:ww-1
				if i%h==0&&j%w==0
					print(-2*h*w+1," ")
				else
					print(2, " ")
				end
			end
			if i%h==0&&ww%w==0
				println(-2*h*w+1)
			else
				println(2)
			end
		end
	end
end

main()

Score : 700 points

Problem Statement

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

The matrix has H rows and W columns.

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

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

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

Constraints

1 ≤ h ≤ H ≤ 500

1 ≤ w ≤ W ≤ 500

Input

Input is given from Standard Input in the following format:

H W h w

Output

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

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

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

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

Sample Input 1

3 3 2 2

Sample Output 1

Yes
1 1 1
1 -4 1
1 1 1

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

Sample Input 2

2 4 1 2

Sample Output 2

No

Sample Input 3

3 4 2 3

Sample Output 3

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


function main()
    r,g,b = map(x->parse(Int,x),split(readline()))
    if (10g + b)%4 == 0
        print("YES")
    else
        print("NO")
    end
end
main()

Score : 100 points

Problem Statement

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

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

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

Is this integer a multiple of 4?

Constraints

1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

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

Sample Input 1

4 3 2

Sample Output 1

YES

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

Sample Input 2

2 3 4

Sample Output 2

NO

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


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=parseInt(readline())
    a=parseMap(split(readline()))
    color=[0 for i in 1:9]
    for i in a
        for j in 1:8
            if 400*(j-1)<=i<400*j
                color[j]+=1
            end
        end
        if 3200<=i
            color[9]+=1
        end
    end
    MIN=max(count(i->i>0,color[1:8]),1)
    MAX=count(i->i>0,color[1:8])+color[9]
    println("$MIN $MAX")
end
main()

Score : 300 points

Problem Statement

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

Rating 1-399 : gray

Rating 400-799 : brown

Rating 800-1199 : green

Rating 1200-1599 : cyan

Rating 1600-1999 : blue

Rating 2000-2399 : yellow

Rating 2400-2799 : orange

Rating 2800-3199 : red

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

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

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

Constraints

1 ≤ N ≤ 100

1 ≤ a_i ≤ 4800

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

4
2100 2500 2700 2700

Sample Output 1

2 2

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

Sample Input 2

5
1100 1900 2800 3200 3200

Sample Output 2

3 5

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

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

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

Sample Input 3

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

Sample Output 3

1 1

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


N = parse(Int, readline())
S = chomp(readline())

br = 0
pre = ""
suf = ""
for i in 1:N
    if S[i] == '('
        br += 1
    elseif br == 0
        pre *= "("
    else
        br -= 1
    end
end
for i in 1:br
    suf *= ")"
end
println(pre * S * suf)

Score : 400 points

Problem Statement

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

Here, a correct bracket sequence is defined as follows:

() is a correct bracket sequence.

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

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

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

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

Constraints

The length of S is N.

1 ≤ N ≤ 100

S consists of ( and ).

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

3
())

Sample Output 1

(())

Sample Input 2

6
)))())

Sample Output 2

(((()))())

Sample Input 3

8
))))((((

Sample Output 3

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


Score : 100 points

Problem Statement

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

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

Constraints

A and B are integers.

1 ≤ A, B ≤ 9

Input

Input is given from Standard Input in the following format:

A B

Output

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

Sample Input 1

6 3

Sample Output 1

9

Sample Input 2

6 4

Sample Output 2

error


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()
    s=join(sort(collect(chomp(readline()))))
    l=length(s)
    ans="yes"
    for i in 2:l
        if s[i]==s[i-1]
            ans="no"
        end
    end
    println(ans)
end
main()

Score : 200 points

Problem Statement

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

Constraints

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

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

uncopyrightable

Sample Output 1

yes

Sample Input 2

different

Sample Output 2

no

Sample Input 3

no

Sample Output 3

yes