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()
  n,k=pM(split(readline()))
  h=pM(split(readline()))
  dp=BigInt[10000000 for i=1:n+k]
  dp[1]=0
  for i=1:n-1
    for j=1:k
      if i+j<=n
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
      end
    end
  end
  println(dp[n])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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()
  n,k=pM(split(readline()))
  h=pM(split(readline()))
  dp=[10000000 for i=1:n+k]
  dp[1]=0
  for i=1:n-1
    for j=1:k
      if i+j<=n
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
      end
    end
  end
  println(dp[n])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq K \leq 100

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N K
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

5 3
10 30 40 50 20

Sample Output 1

30

If we follow the path 1 → 2 → 5, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

3 1
10 20 10

Sample Output 2

20

If we follow the path 1 → 2 → 3, the total cost incurred would be |10 - 20| + |20 - 10| = 20.

Sample Input 3

2 100
10 10

Sample Output 3

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 4

10 4
40 10 20 70 80 10 20 70 80 60

Sample Output 4

40

If we follow the path 1 → 4 → 8 → 10, the total cost incurred would be |40 - 70| + |70 - 70| + |70 - 60| = 40.

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.


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()
  n,k=pM(split(readline()))
  h=pM(split(readline()))
  dp=[10000000 for i=1:n+k]
  dp[1]=0;dp[2]=abs(h[1]-h[2])
  for i=1:n-1
    for j=1:k
      if i+j<=n
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
      end
    end
  end
  println(dp[n])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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

function main()
	n,k = readline() |> split |> parseMap
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	for i in 2:min(k,n)
		m = 10000000000
		for j in 1:i-1
			m = min(m,dp[j]+abs(h[i]-h[j]))
		end
		dp[i] = m
	end
	for i in k+1:n
		m = 10000000000
		for j in 0:k-1
			m = min(m,dp[i-k+j]+abs(h[i]-h[i-k+j]))
		end
		dp[i] = m
	end
	println(dp[n])
end

main()


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

function main()
	n,k = readline() |> split |> parseMap
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	for i in 2:min(k,n)
		m = 100000
		for j in 1:i-1
			m = min(m,dp[j]+abs(h[i]-h[j]))
		end
		dp[i] = m
	end
	for i in k+1:n
		m = 100000
		for j in 0:k-1
			m = min(m,dp[i-k+j]+abs(h[i]-h[i-k+j]))
		end
		dp[i] = m
	end
	println(dp[n])
end

main()


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

function main()
	n,k = readline() |> split |> parseMap
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	for i in 2:min(k,n)
		m = 100000
		for j in 1:i-1
			m = min(m,dp[j]+abs(h[i]-h[j]))
		end
		dp[i] = m
	end
	for i in k+1:n
		m = 100000
		for j in 1:k
			m = min(m,dp[i-j]+abs(h[i]-h[i-j]))
		end
		dp[i] = m
	end
	println(dp[n])
end

main()


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

function main()
	n,k = readline() |> split |> parseMap
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	for i in 2:k
		m = 10000
		for j in 1:i-1
			m = min(m,dp[j]+abs(h[i]-h[j]))
		end
		dp[i] = m
	end
	for i in k+1:n
		m = 10000
		for j in 1:k
			m = min(m,dp[i-j]+abs(h[i]-h[i-j]))
		end
		dp[i] = m
	end
	println(dp[n])
end

main()


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

function main()
    n::Int,w::Int=parseMap(split(readline()))
    dp::Vector{Vector{Int}}=[[0 for j in 0:100010] for i in 1:110]
    data::Vector{Vector{Int}}=[parseMap(split(readline())) for i in 1:n]
    for i in 1:n
        for j in 0:w
            wi::Int,vi::Int=data[i]
            if j-wi>=0
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1-wi]+vi)
            end
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1])
        end
    end
    println(dp[n+1][w+1])
end
main()

Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^5

1 \leq w_i \leq W

1 \leq v_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.


p()=parse.(Int,split(readline()))
n,W=p().+1
t=zeros(Int,W)
for i=2:n;
  w,v=p()
  t[w+1:end].=max.(t[w+1:end],(t[1:end-w].+v))
end
println(t[W])


p()=parse.(Int,split(readline()))
n,W=p()
t=zeros(Int,W+1)
for i=1:n;
  w,v=p()
  t[w+1:end].=max.(t[w+1:end],(t[1:end-w].+v))
end
println(t[W+1])


macro p();:((x->parse(Int,x)).(split(readline())));end
n,W=@p
s=Meta.parse("w,v=@p;t[w+1:end].=max.(t[w+1:end],(t[1:end-w].+v));"^n)
macro d();s;end
t=zeros(Int,W+1)
@d
println(t[W+1])


macro p();:((x->parse(Int,x)).(split(readline())));end
n,W=@p
t=zeros(Int,W+1)
for i=1:n;w,v=@p;t[w:end].=max(t[w+1:end]...,(t[1:end-w-1].+v)...);end
println(t[W+1])


macro p();:((x->parse(Int,x)).(split(readline())));end
n,W=@p
t=zeros(Int,W+1)
eval(Meta.parse("w,v=@p;t[w:end].=max(t[w+1:end]...,(t[1:end-w-1].+v)...);"^n))
println(t[W+1])


function solve()
  n,w=parse.(Int,split(readline()))
  dp=zeros(Int,n+1,w+1)
  for i=1:n
    wi,vi=parse.(Int,split(readline()))
    for j=1:w+1
      dp[i+1,j]=max(dp[i,j],(j>wi ? dp[i,j-wi]+vi : 0))
    end
  end
  println(dp[n+1,w+1])
end
solve()


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()
  n,w=pM(split(readline()))
  dp=[Int[0 for i=1:w+1] for j=1:n+1]
  for i=1:n
    wi,vi=pM(split(readline()))
    for j=1:w
      if j-wi>0
        dp[i+1][j]=max(dp[i][j],dp[i][j-wi]+vi)
      end
      dp[i+1][j]=max(dp[i+1][j],dp[i][j])
    end
  end
  println(dp[n+1][w+1])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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()
  n,w=pM(split(readline()))
  dp=[Int[0 for i=1:w+1] for j=1:n+1]
  for i=2:n+1
    wi,vi=pM(split(readline()))
    for j=2:w+1
      if j-wi>0
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-wi]+vi)
      end
    end
  end
  println(dp[n+1][w+1])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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()
  n,w=pM(split(readline()))
  dp=[BigInt[0 for i=1:w+1] for j=1:n+1]
  for i=2:n+1
    wi,vi=pM(split(readline()))
    for j=wi+1:w+1
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-wi]+vi)
    end
  end
  println(dp[n+1][w+1])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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()
  n,w=pM(split(readline()))
  dp=[[0 for i=1:w+1] for j=1:n+1]
  for i=2:n+1
    wi,vi=pM(split(readline()))
    for j=wi+1:w+1
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-wi]+vi)
    end
  end
  println(dp[n+1][w+1])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


r() = [parse(Int,x) for x in readline() |> split]

function main()
    N,W = r()
    DP = zeros(Int,N+1,W+1)
    for i in 2:N+1
        w,v = r()
        for j in 1:W
            if j >= w
                DP[i,j+1] = max(DP[i-1,j+1], DP[i-1,j+1-w] + v)
            else
                DP[i,j+1] = DP[i-1,j+1]
            end
        end
        # println("DP = $DP")
    end
    println(maximum(DP))
end

main()


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

function main()
    N,W = readline() |> split |> parseMap
    VW = Array{Int64}(2,N)
    for i in 1:N
        VW[:,i] = readline() |> split |> parseMap
    end
    IW = VW[1,:]
    IV = VW[2,:]
    DP = zeros(Int64,N+1,W+10)
    for i in 1:N
        for j in 1:W+1
            if j+1 > IW[i]
                a = DP[i,j+1]
                b = DP[i,j+1 - IW[i]] + IV[i]
                DP[i+1,j+1] = max(a,b)
            else
                DP[i+1,j+1] = DP[i,j]
            end
        end
    end
    println(maximum(DP))
end

main()


N, W = map(int, input().split())

value = [0] * (W + 1)

for _ in range(N):
  w, v = map(int, input().split())
  i = value.index(max(value[:W-w+1]))
  value[w+i] = max(v + value[i], value[w+i])
  value[w] = max(v, value[w])
print(max(value))


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

function main()
	n,w = readline() |> split |> parseMap
	vw = Array{Int}(2,n)
	for i in 1:n
		vw[:,i] = readline() |> split |> parseMap
	end
	dp = zeros(Int,n,w+1)
	dp[1,vw[1,1]+1] = vw[2,1]
	for i in 2:n
		for j in 1:w
			if j-vw[1,i] >= 0
				dp[i,j+1] = max(dp[i-1,j+1],dp[i-1,j+1-vw[1,i]]+vw[2,i])
			else
				dp[i,j+1] = dp[i-1,j+1]
			end
		end
	end
	println(maximum(dp))
end

main()


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

function main()
	n,w = readline() |> split |> parseMap
	vw = Array{Int}(2,n)
	for i in 1:n
		vw[:,i] = readline() |> split |> parseMap
	end
	dp = zeros(Int,n,w)
	dp[1,vw[1,1]] = vw[2,1]
	for i in 2:n
		for j in 1:w
			if j-vw[1,i] > 0
				dp[i,j] = max(i-1,dp[j-vw[1,i]],dp[i-1,j-vw[1,i]]+vw[2,i])
			else
				dp[i,j] = dp[i-1,j]
			end
		end
	end
	println(maximum(dp))
end

main()


input = readline()
num = parse(Int64, input)
if num == 25
  println("Christmas")
end
if num == 24
  println("Christmas Eve")
end
if num == 23
  println("Christmas Eve Eve")
end
if num == 22
  println("Christmas Eve Eve")
end

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
D = parse(readline())
if D == 25
    println("Christmas")
elseif D == 24
    println("Christmas Eve")
elseif D == 23
    println("Christmas Eve Eve")
elseif D == 22
    println("Christmas Eve Eve Eve")
end


function main()

  D = parse(Int,readline())
  S = "Christmas"

  for i in 1:25-D

    S *= " Eve"

  end

  println(S)

end

main()


const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    d=25-int(input())
    println("Christmas",repeat(" Eve",d))
end
main()


x = parse(Int, readline())
if x == 25
  print("Christmas")
elseif x == 24
  print("Christmas Eve")
elseif x == 23
  print("Christmas Eve Eve")
else
  print("Christmas Eve Eve Eve")
end


function main()
	n = parse(Int64, readline())
	s = "Christmas"
	for i in n:25
		s = s * " Eve"
	end
	println(s)
end

main()


n=parse(readline());
if n==25
  print("Christmas");
elseif n==24
  print("Christmas Eve");
elseif n==23
  print("Christmas Eve Eve");
else
  print("Christmas Eve Eve Eve");
end


D= parse(readline())

if D==25
println("Christmas")
elseif D==24
println("Christmas Eve")
elseif D==23
println("Christmas Eve Eve")
elseif D==22
println("Christmas Eve Eve Eve")
end


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

function main()
    n=parseInt(readline())
    data=sort([parseMap(split(readline())) for i in 1:n],by=x->x[3],rev=true)
    if n==1
        ans=join(data[1]," ")
    else
        ans="-1 -1 -1"
        for i in 0:100
            for j in 0:100
                flg=true
                dis=abs(data[1][1]-i)+abs(data[1][2]-j)
                hight=data[1][3]
                for (x,y,h) in data
                    if h>0 && abs(x-i)+abs(y-j)+h != dis+hight
                        flg=false
                    end
                end
                for (x,y,h) in data
                    if h!=max(dis+hight-abs(x-i)+-abs(y-j),0)
                        flg=false
                    end
                end
                if flg==true && dis+hight>0
                    ans="$i $j $(dis+hight)"
                    break
                end
            end
            if ans!="-1 -1 -1"
                break
            end
        end
    end
    println(ans)
end
main()

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

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

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

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

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


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

function main()
    n=parseInt(readline())
    data=[parseMap(split(readline())) for i in 1:n]
    if n==1
        ans=join(data[1]," ")
    else
        ans="-1 -1 -1"
        for i in 0:100
            for j in 0:100
                flg=true
                dis=abs(data[1][1]-i)+abs(data[1][2]-j)
                hight=data[1][3]
                for (x,y,h) in data
                    if h>0 && abs(x-i)+abs(y-j)+h != dis+hight
                        flg=false
                    end
                end
                if flg==true
                    ans="$i $j $(dis+hight)"
                    break
                end
            end
            if ans!="-1 -1 -1"
                break
            end
        end
    end
    println(ans)
end
main()


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

piramids = sort(collect(piramids), by=x->x.h)

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(piramid.y - Y)
                if h_max == 1
                    return 1
                end
                if kizyun_h <= h_max
                    ok += 1
                end
            end
        end
        if ok == N && kizyun_h >= 1
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

piramids = sort(collect(piramids), by=x->x.h)

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if h_max == 1
                    return 1
                end
                if H <= h_max
                    ok += 1
                end
            end
        end
        if ok == N && kizyun_h >= 1
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

piramids = sort(collect(piramids), by=x->x.h)

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                return 100000000000000
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if H <= h_max
                    ok += 1
                end
            end
        end
        if ok == N && kizyun_h >= 1
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

piramids = sort(collect(piramids), by=x->x.h)

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if H <= h_max
                    ok += 1
                end
            end
        end
        if ok == N && kizyun_h >= 1
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if H <= h_max
                    ok += 1
                end
            end
        end
        if ok == N && kizyun_h >= 1
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if H <= h_max
                    ok += 1
                end
            end
        end
        if ok == N
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            if piramid.h != 0
                H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
                if kizyun_h == H
                    ok += 1
                end
            else
                h_max = abs(piramid.x - X) + abs(Y - piramid.y)
                if H >= h_max
                    ok += 1
                end
            end
        end
        if ok == N
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

type piramid
    x :: Int
    y :: Int
    h :: Int
end

function main()
N = parseInt(readline())
piramids = []
for _ in 1:N
    x,y,h = parseMap(split(readline()))
    push!(piramids,piramid(x,y,h))
end

for X in 0:100
    for Y in 0:100
        ok = 0
        kizyun_piramid =  piramids[1]
        kizyun_h = kizyun_piramid.h + abs(kizyun_piramid.x - X) + abs(kizyun_piramid.y - Y)
        for i in 1:N
            piramid = piramids[i]
            H = piramid.h + abs(piramid.x - X) + abs(piramid.y - Y)
            if kizyun_h == H
                ok += 1
            end
        end
        if ok == N
            return "$X $Y $kizyun_h"
        end
    end
end
end

println(main())


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

function main()
	n = readline() |> parseInt
	x = Array{Int}(3,n)
	for i in 1:n
		x[:,i] = readline() |> split |> parseMap
	end
	s = [0,0,0]
	for i in 1:n
		if x[3,i] != 0
			s = x[:,i]
			break
		end
	end
	for i in 0:100
		for j in 0:100
			flg = 0
			h = [i,j,s[3]+abs(i-s[1])+abs(j-s[2])]
			for k in 1:n
				if max(h[3]-abs(i-x[1,k])-abs(j-x[2,k]),0) != x[3,k]
					flg = 1
					break
				end
			end
			if flg == 0
				print(i, " ", j, " ", h[3])
			end
		end
	end
end

main()


N = parse(Int64, readline(STDIN))
data = [map(x -> parse(Int64,x), split(readline(STDIN))) for _ in 1:N]

function calHeight(H,X,x,Y,y)
    val = H - abs(X-x) - abs(Y-y)
    if val < 0
        return 0
    else
        return val
    end
end

function fit(H, X, Y, datas)
    for (x,y,h) in datas
        if h != calHeight(H,X,x,Y,y)
            return false
        end
    end
    return true
end

function cal(datas)
    for H in 1:1000000000
        for X in 0:100
            for Y in 0:100
                if fit(H, X, Y, datas)
                    @printf("%d %d %d", X, Y, H)
                    return
                end
            end
        end
    end
end

cal(data)


function main()

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

  sort!(A,rev = true)

  println(10*A[1]+A[2]+A[3])

end

main()

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    a,b,c=sort(intLine())
    println(a+b+10c)
end
main()


scan() = parse.(Int,split(readline()))
n, m, x, y = scan()
xmax = max(x,maximum(scan()))
ymin = min(y,minimum(scan()))
println(xmax < ymin ? "No War" : "War")

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


function scan() parse.(Int,split(readline())) end
n, m, x, y = scan()
xs = append!(scan(),x)
ys = append!(scan(),y)
println(maximum(xs) < minimum(ys) ? "No War" : "War")


function main()

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

  check = false

  for i in X:Y

    if maximum(x) < i && minimum(y) >= i
      check = true
      println("No War")
      break
    end

  end

  if check == false
    println("War")
  end

end

main()


const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    N,M,X,Y=intLine()
    x=zeros(Int32,N+1)
    for (i,v)=enumerate(intLine());x[i]=v;end
    x[end]=X
    y=zeros(Int32,M+1)
    for (i,v)=enumerate(intLine());y[i]=v;end
    y[end]=Y
    println("No "^(maximum(x)<minimum(y)),"War")
end
main()


function main()
	a = parse.(split(readline()))
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	max = -100
	min = 100
	for i in 1:a[1]
		if max <= x[i]
			max = x[i]
		end
	end
	for i in 1:a[2]
		if min >= y[i]
			min = y[i]
		end
	end
	if a[3] >= a[4] || max >= min || max >= a[4] || min <= a[3]
		print("War")
	else
		print("No War")
	end
end

main()


function main()
	a = parse.(split(readline()))
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	max = -100
	min = 100
	for i in 1:a[1]
		if max <= x[i]
			max = x[i]
		end
	end
	for i in 1:a[2]
		if min >= y[i]
			min = y[i]
		end
	end
	if a[3] >= a[4]
		print("War")
	elseif max >= min
		print("War")
	else
		print("No War")
	end
end

main()


function main()
    N, M, X, Y = parse.(split(readline()))
    a = parse.(split(readline()))
    b = parse.(split(readline()))
    append!(a, [X])
    append!(b, [Y])
    if maximum(a) < minimum(b)
        print("No War")
    else
        print("War")
    end
end
main()


function main()
    # スペース区切りの整数の入力
    N,M,X,Y = map(x -> parse(Int, x), split(readline()))
    Xs = map(x -> parse(Int, x), split(readline()))
    Ys = map(x -> parse(Int, x), split(readline()))

    # 出
    Xss = append!([X],Xs)
    Yss = append!([Y],Ys)

    xss = sort(Xss)
    yss = sort(Yss)
    if xss[end] < yss[1]
        print("No War")
    end
    if xss[end] >= yss[1]
        print("War")
    end
end
main()


A,B = parse.(split(readline()))
if (A * B) % 2 == 1
  println("Yes")
else
  println("No")
end

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


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

function main()
    a,b=parseMap(split(readline()))
    println(ifelse(a*b%2==0,"No","Yes"))
end
main()


x = parse.(split(readline()))
print(ifelse(x[1]*x[2]%2 != 0,"Yes","No"))


function main()
	x = parse.(split(readline()))
	print(ifelse(x[1]*x[2]%2 != 0,"Yes","No"))
end

main()


function gcd(a,b)
	r = a%b
	while r != 0
		a = b
		b = r
		r = a%b
	end

	return(b)
end

function main()
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	r = abs(x[2]-y[1])
	for i in 2:x[1]
		if r == 1
			break
		else
			s = abs(x[2]-y[i])
			if s>r
				r = gcd(s,r)
			else
				r = gcd(r,s)
			end
		end
	end
	print(r)
end

main()


function main()
	x = split(readline())
	a = parse(Int64, x[1])
	b = parse(Int64, x[2])
	if a*b%2 != 0
		print("Yes")
	else
		print("No")
	end
end

main()


function main()
	x = split(readline())
	a = parse(Int64, x[1])
	b = parse(Int64, x[2])
	if a*b%2 != 0
		print("Yes")
	else
		print("No")
	end
end


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()
  n=pI(readline())
  seen=String[]
  pre=chomp(readline())
  push!(seen,pre)
  flag=true
  for i=1:n-1
    s=chomp(readline())
    if pre[end]!=s[1] || (s in seen)
      flag=false
    end
    pre=s
    push!(seen,s)
  end
  println(flag ? "Yes" : "No")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


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

function main()
    n=parseInt(readline())
    w=[chomp(readline()) for i in 1:n]
    ans="Yes"
    for i in 2:n
        if w[i][1]!=w[i-1][end]
            ans="No"
        end
        for j in 1:i-1
            if w[i]==w[j]
                ans="No"
            end
        end
    end
    println(ans)
end
main()


const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    n=int(input())
    w=input()
    s=Set{String}([w])
    for i=1:n-1
        v=input()
        if in(v,s)||w[end-1]!=v[1]
            println("No")
            exit()
        end
        push!(s,v)
        w=v
    end
    println("Yes")
end
main()


const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function main()
    n=int(input())
    w=input()
    s=Set{String}([w])
    for i=1:n-1
        v=input()
        if in(v,s)||w[end]!=v[1]
            println("No")
            exit()
        end
        push!(s,v)
        w=v
    end
    println("Yes")
end
main()


function main()
	n = parse(readline())
	w = ["" for i in 1:n]
	flag = 0
	w[1] = readline()
	for i in 1:n-1
		x = split(w[i], "")
		l = length(x)
		w[i+1] = readline()
		y = split(w[i+1], "")
		for j in 1:i
			if w[j] == w[i+1]
				flag = 1
				break
			elseif x[l-1] != y[1]
				flag = 1
				break
			end
		end
	end
	if flag == 0
		print("Yes")
	else
		print("No")
	end
end

main()


function main()
	n = parse(readline())
	w = ["" for i in 1:n]
	flag = 0
	w[1] = readline()
	for i in 1:n-1
		x = split(w[i], "")
		l = length(x)
		w[i+1] = readline()
		y = split(w[i+1], "")
		for j in 1:i
			if w[j] == w[i+1]
				flag = 1
				break
			elseif x[l] != y[1]
				flag = 1
				break
			end
		end
	end
	if flag == 0
		print("Yes")
	else
		print("No")
	end
end

main()


n=parse(Int,readline())
s=[]
for i=1:n
	push!(s,chomp(readline()))
end
f=0
for i=2:n
	if s[i-1][length(s[i-1])]!=s[i][1]
		f+=1
	end
	for j=1:i-1
		if s[i]==s[j]
			f+=1
		end
	end
end
println(f>0?"No":"Yes")


n = parse(Int64, readline())
data = [readline() for _ in 1:n]
function check_siritori(data)
    done_text_arr = []
    for text in data
        if length(done_text_arr) > 0
            for done_text in done_text_arr
                if done_text == text
                    return false
                end
            end
            if split(done_text_arr[end], "")[end] != split(text, "")[1]
                return false
            end
        end
        push!(done_text_arr, text)
    end
    return true
end
if check_siritori(data)
    text = "Yes"
else
    text = "No"
end
print(text)


n = parse.(Int64, readline())
data = [readline() for _ in 1:n]
function check_siritori(data)
    done_text_arr = []
    for text in data
        if length(done_text_arr) > 0
            for done_text in done_text_arr
                if done_text == text
                    return false
                end
            end
            if split(done_text_arr[end], "")[end] != split(text, "")[1]
                return false
            end
        end
        push!(done_text_arr, text)
    end
    return true
end
if check_siritori(data)
    text = "Yes"
else
    text = "No"
end
print(text)


n = parse.(Int64, readline(STDIN))
data = [readline(STDIN) for _ in 1:n]

function check_siritori(data)
    done_text_arr = []
    for text in data
        if length(done_text_arr) > 0
            for done_text in done_text_arr
                if done_text == text
                    return false
                end
            end
            if split(done_text_arr[end], "")[end] != split(text, "")[1]
                return false
            end
        end
        push!(done_text_arr, text)
    end
    return true
end

if check_siritori(data)
    answer = "Yes"
else
    answer = "No"
end

print(answer)


function main()

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

  ans = abs(X-x[1])

  for i in 2:N
    ans = gcd(ans,abs(X-x[i]))
  end

  println(ans)

end

main()

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


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

function main()
    n,x=parseMap(split(readline()))
    xi=parseMap(split(readline()))
    push!(xi,x)
    sort!(xi)
    dif=[xi[i+1]-xi[i] for i in 1:n]
    ans=dif[1]
    for i in 1:n-1
        ans=gcd(dif[i],ans)
    end
    println(ans)
end
main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N,X = parseMap(split(readline()))
x = parseMap(split(readline()))
distance = x .- X
println(gcd(distance))


N,X=map(x->parse(Int,x),split(readline()))
A=map(x->parse(Int,x),split(readline()))
push!(A,X)
t=0
for i=1:N
	t=gcd(t,A[i+1]-A[i])
end
println(t)


function euclid(n,m)
    while n!=0
        tmp=n
        n=m % n
        m=tmp
    end
    return m
end

n,X=parse.(Int64, split(readline()))
x=parse.(Int64, split(readline()))
y=abs.(x-X*map(Int64, ones(n)))
println(reduce(euclid,y))


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

function gcd(x,y)
	r = x%y
	while r > 0
		temp = r
		r = y%r
		y = temp
	end
	return(y)
end

function main()
	n = parseInt.(split(readline()))
	x = parseInt.(split(readline()))
	if n[1] == 1
		print(abs(x[1]-n[2]))
	else
		y = [0 for i in 1:n[1]]
		for i in 1:n[1]
			y[i] = abs(x[i]-n[2])
		end
		gcdd = gcd(y[1],y[2])
		if n[1] >= 3
			for i in 3:n[1]
				gcdd = gcd(gcdd, y[i])
			end
		end
		print(gcdd)
	end
end

main()


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

function gcd(x,y)
	r = x%y
	while r > 0
		temp = r
		r = y%r
		y = temp
	end
	return(y)
end

function main()
	n = parseInt.(split(readline()))
	x = parseInt.(split(readline()))
	y = [0 for i in 1:n[1]]
	for i in 1:n[1]
		y[i] = abs(x[i]-n[2])
	end
	gcdd = gcd(y[1],y[2])
	for i in 3:n[1]
		gcdd = gcd(gcdd, y[i])
	end

	print(gcdd)
end

main()


function gcd(a,b)
	r = a%b
	while r != 0
		a = b
		b = r
		r = a%b
	end

	return(b)
end

function main()
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	r = abs(x[2]-y[1])
	for i in 2:x[1]
		if r == 1
			break
		else
			s = abs(x[2]-y[i])
			if s>r
				r = gcd(s,r)
			else
				r = gcd(r,s)
			end
		end
	end
	print(r)
end

main()


function gcd(a,b)
	if a < b
		tmp = a
		a = b
		b = tmp
	end

	r = a%b
	while r != 0
		a = b
		b = r
		r = a%b
	end

	return(b)
end

function main()
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	r = abs(x[2]-y[1])
	for i in 2:x[1]
		if r == 1
			break
		else
			s = abs(x[2]-y[i])
			r = gcd(s,r)
		end
	end
	print(r)
end

main()


function gcd(a,b)
	if a < b
		tmp = a
		a = b
		b = tmp
	end

	r = a%b
	while r != 0
		a = b
		b = r
		r = a%b
	end

	return(b)
end

function main()
	x = parse.(split(readline()))
	y = parse.(split(readline()))
	r = abs(x[2]-y[1])
	for i in 2:x[1]
		s = abs(x[2]-y[i])
		r = gcd(s,r)
	end
	print(r)
end

main()


d, n = parse.(Int,split(readline()))
println((n==100 ? n+1 : n) * 100^d)

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

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

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


function f()
    D, N = parse.(Int,split(readline()))
    out = (N-Int(floor((N-1)/99)))*100^D
    #if (N == 100)
        #out = 101*100^D
    #end
    println(out)
end
f()


function f()
    D, N = parse.(Int,split(readline()))
    out = N*100^D
    println(out)
end
f()


d,n=parse.(split(readline()))
d+= d==100?1:0
print(n,"00"^d)


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

function main()
    d,n=parseMap(split(readline()))
    if n==100
        n+=1
    end
    println(n*(100^d))
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)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    d,n=parseMap(split(readline()))
    println(n*(100^d))
end
main()


function main()

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

  if N == "100"
    print("101")
  else
    print(N)
  end

  if D == "1"
    println("00")
  elseif D == "2"
    println("0000")
  else
    println()
  end

end

main()


function main()

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

  if N == "100"
    print(D == "0" ? "0":"1")
  else
    print(N)
  end

  if D == "1"
    println("00")
  elseif D == "2"
    println("0000")
  else
    println()
  end

end

main()


function main()

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

  print(N)

  if D == "1"
    println("00")
  elseif D == "2"
    println("0000")
  else
    println()
  end

end

main()


function main()

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

  print(N)

  for i in 1:D
    print("00")
  end

end

main()


N,D=map(x->parse(Int,x),split(readline()))
if D==100
  D+=1
end
println(D*100^N)


function abc100_b()

	# STEP.01
	# get the number of the slice of cake
	D, N = Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )

	if Base.isequal( N, 100 )
		num_presents = 101*100^D
	else
		num_presents = N*100^D
	end

	# STEP.02
	Base.println( Base.STDOUT, num_presents )

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc100_b()


function abc100_b()

	# STEP.01
	# get the number of the slice of cake
	D, N = Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )

	if Base.isequal( N, 100 )
		num_presents = 101*100^D
	else
		num_presents = N*100^D
	end

	# STEP.02
	Base.println( Base.STDOUT, num_presents )

	# STEP.TRUE_END
	return nothing

end

#==================================================================================================#

Main.abc100_b()


function abc100_b()

	# STEP.01
	# get the number of the slice of cake
	D, N = Base.parse.( Int, Base.split( Base.readline( Base.STDIN ) ) )

	if Base.isequal( N, 100 )
		num_presents = 101*100^D
	else
		num_presents = 100^D
	end

	# STEP.TRUE_END
	return Core.nothing

end

#==================================================================================================#

Main.abc100_b()


function main()
  x = parse.(split(readline()))
  y = x[2]*(100^x[1])
  if x[2] == 100
    y+= 1*100^x[1]
  end
  print(y)
end

main()


function main()
  x = parse.(split(readline()))
  y = x[2]*(100^x[1])
  if x[2] == 100
    y+= 1
  end
  print(y)
end

main()


function main()
  x = parse.(split(readline()))
  print(x[2]*(100^x[1]))
end

main()


function main()
	a = parse.(Int,readline())
	b = parse.(Int,readline())
	c = parse.(Int,readline())
	x = parse.(Int,readline())

	cnt=0
	for i=0:a
		for j=0:b
			for k=0:c
				if x == 500i+100j+50k
					cnt+=1
				end
			end
		end
	end
	println(cnt)
end

main()

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


a = parse(Int, readline())
b = parse(Int, readline())
c = parse(Int, readline())
x = parse(Int, readline())

ans = 0
for i in 0:a
  for j in 0:b
    for k in 0:c
      if i*500+j*100+k*50==x
        global ans += 1
      end
    end
  end
end

println(ans)


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

function main()
    a,b,c,x=[parseInt(readline()) for i in 1:4]
    ans=0
    for i in 0:a,j in 0:b,k in 0:c
        if 500*i+100*j+50*k==x
            ans+=1
        end
    end
    println(ans)

end
main()


A,B,C,X=map(x->parse(Int,x),split(readline()))
ans=0
for i=0:A,j=0:B,k=0:C
  ans+=i*500+j*100+k*50==X
end
println(ans)


function main()
	a = parse(readline())
	b = parse(readline())
	c = parse(readline())
	x = parse(readline())
	ca = 0
	count = 0
	while ca*500 <= x && ca <= a
		cb = 0
		y = x-ca*500
		while cb*100 <= y && cb <= b
			z = y-cb*100
			p = z%50
			q = (z-p)/50
			if q <= c && p == 0
				count +=1
			end
			cb += 1
		end
		ca += 1
	end
	print(count)
end

main()


A = parse(readline())
B = parse(readline())
C = parse(readline())
X = parse(readline())
counter = 0
for i in 0:A
    for j in 0:B
        for k in 0:C
            counter += 500i + 100j + 50k == X ? 1:0
        end
    end
end
print(counter)


a = parse(Int64,readline())
b = parse(Int64,readline())
c = parse(Int64,readline())
x = parse(Int64,readline())

res = 0
for i = 0:a+1, j = 0:b+1, k = 0:c+1
  if 500*i+100*j+50*k == x
    res += 1
  end
end
print(res)


a = parse(Int64,readline())
b = parse(Int64,readline())
c = parse(Int64,readline())
x = parse(Int64,readline())

res = 0
for i = 0:a+1, j = 0:b+1, k = 0:c+1
  if 500*i+100*j+50*k == x
    res += 1
end
print(res)


function main()
    A = parse(Int, readline())
    B = parse(Int, readline())
    C = parse(Int, readline())
    X = parse(Int, readline())

    res = 0
    for a = 0:A
        for b = 0:B
            for c = 0:C
                total = 500 * a + 100 * b + 50 * c
                if total == X
                    res += 1
                end
            end
        end
    end

    println(res)
end

main()


function main()
    a = parse(readline())
    b = parse(readline())
    c = parse(readline())
    x = parse(readline())
    count = 0
    for i in 0:a
        for j in 0:b
            for k in 0:c
                s = 500i + 100j + 50k
                if s == x
                    count += 1
                end
            end
        end
    end
    println("$count")
end

main()


println(prod(parse.(Int,split(readline())))%2==0 ? "Even" : "Odd")

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


a,b = parse.(Int,split(readline()))
println((a*b)%2==0 ? "Even" :  "Odd")


f(input) =  input[1]*input[2] % 2 == 0 ? print("Even") : print("Odd")
input = parse.(Int, split(readline()))
f(input)


f(a, b) =  a*b % 2 == 0 ? print("Even") : print("Odd")
f(readline(), readline())


function main()
	a,b= parse.(Int, split(readline()))
	println(a * b % 2 == 0 ? "Even" : "Odd")
end

main()


(a, b) = split(readline())
a = parse(Int, a)
b = parse(Int, b)

if a*b % 2 == 0
  println("Even")
else
  println("Odd")
end


(a, b) = split(readline())
a = parse(Int, a)
b = parse(Int, b)

if a*b % 2 == 0
  println("Even")
else
  println("odd")
end


let
  a, b = map(x -> parse(Int, x), readline() |> split)
  println( (a * b) % 2 == 0 ? "Even" : "Odd")
end


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

function main()
    a,b=parseMap(split(readline()))
    println(ifelse(a*b%2==0,"Even","Odd"))
end
main()


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

if iseven(a*b)
    println("Even")
else
    println("Odd")
end


function main()

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

  if a*b % 2 == 0
    println("Even")
  else
    println("Odd")
  end

end

main()


a, b = parse.(Int, split(readline()))
print((a*b)%2==0 ? "Even" : "Odd")


# AtCoder Beginner Contest 086 A
# [URL]      https://atcoder.jp/contests/abc086/tasks/abc086_a
# [compiler] Version 0.5.0

#==================================================================================================#

function abc086_a()

	# STEP.01
	# get the number of the slice of cake
	a,b = Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )

	# STEP.02
	# output the result
	if Base.iseven( a*b )
		Base.println( Base.STDOUT, "Even")
	else
		Base.println( Base.STDOUT, "Odd" )
	end

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc086_a()


function main()
	ab = parse.(split(readline()))
	if (ab[1]*ab[2])%2 == 1
		print("Odd")
	else
		print("Even")
	end
end

main()


function main()
    (a,b) = map(x -> parse(Int, x), split(readline()))

    if (a * b) % 2 == 0
        println("Even")
    else
        println("Odd")
    end
end

main()


function main()
    if any(iseven.(parse.(split(readline()))))
        println("Even")
    else
        println("Odd")
    end
end
main()


function main()
    if any(iseven.(parse.(split(readline()))))
        println("Odd")
    else
        println("Even")
    end
end
main()


function main()
    (a, b) = map(x -> parse(Int, x), split(readline()))
    c = a * b
    if c % 2 == 0
        println("Even")
    else
        println("Odd")
    end
end

main()


function main()
    (a, b) = map(x -> parse(Int, x), split(readline()))

    if a % 2 == 1 && b % 2 == 1
        println("Odd")
    else
        println("Even")
    end
end

main()


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

if a % 2 == 1 && b % 2 == 1
    println("Odd")
else
    println("Even")
end


N = split(readline())
if parse(Int,N[1]) %2 == 0 || parse(Int,N[2]) %2 == 0
  print("Even")
else
  print("Odd")
end


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

if a * b % 2 == 1
    println("Odd")
else
    println("Even")
end


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

function main()
    n,y=parseMap(split(readline()))
    ans="-1 -1 -1"
    for i in 0:n,j in 0:n
        if i+j<=n && 10000*i+5000*j+1000*(n-i-j)==y
            ans="$i $j $(n-i-j)"
            break
        end
    end
    println(ans)
end
main()

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


N,Y=map(x->parse(Int,x),split(readline()))
for i=0:N,j=0:N-i
  k=N-i-j
  if 10000i+5000j+1000k==Y
    println("$i $j $k")
    exit()
  end
end
println("-1 -1 -1")


function f(n, y)
	a = [-1, -1, -1]
	p = y%10000
	q = convert(Int, (y-p)/10000)
	for i in 0:q
		if i <= n
			m = y - i*10000
			r = m%5000
			s = convert(Int, (m-r)/5000)
			for j in 0:s
				if i + j <= n
					o = m - j*5000
					if o%1000 ==0 && i + j + o/1000 == n
						a[1] = i
						a[2] = j
						a[3] = convert(Int, o/1000)
					end
				end
			end
		end
	end
	return(a)
end

function main()
	n = parse.(split(readline()))
	ans = f(n[1], n[2])
	print(ans[1], " ", ans[2], " ", ans[3])
end

main()


function main()
	n = parse.(split(readline()))
	ans = [-1, -1, -1]
	p = n[2]%10000
	q = convert(Int, (n[2]-p)/10000)
	for i in 0:q
		flg = 0
		if i <= n[1]
			m = n[2] - i*10000
			r = m%5000
			s = convert(Int, (m-r)/5000)
			for j in 0:s
				if i + j <= n[1]
					o = m - j*5000
					if o%1000 ==0 && i + j + o/1000 == n[1]
						ans[1] = i
						ans[2] = j
						ans[3] = convert(Int, o/1000)
						flg = 1
						break
					end
				end
			end
			if flg == 1
			break
		end
	end
	print(ans[1], " ", ans[2], " ", ans[3])
end

main()


function main()
    (N, Y) = map(x -> parse(Int, x), split(readline()))
    res10000 = res5000 = res1000 = -1
    for a = 0:N
        for b = 0:N - a
            c = N - a - b
            total = 10000 * a + 5000 * b + 1000 * c
            if total == Y
                res10000 = a
                res5000 = b
                res1000 = c
            end
        end
    end

    println("$res10000 $res5000 $res1000")
end

main()


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

function main()
	n,hp = readline() |> split |> parseMap
	x = Tuple{Int,Int}[]
	maxa = 0
	for i in 1:n[1]
		a,b = readline() |> split |> parseMap
		push!(x,(a,b))
		maxa = max(maxa,a)
	end
	useb = Int[]
	for i in 1:n
		if x[i][2] > maxa
			push!(useb, x[i][2])
		end
	end
	useb = sort(useb, rev=true)
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()

Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


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

function main()
	n,hp = readline() |> split |> parseMap
	x = Array{Int}(2,n)
	maxa = 0
	for i in 1:n
		x[:,i] = readline() |> split |> parseMap
		maxa = max(maxa,x[1,i])
	end
	useb = Int[]
	for i in 1:n
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


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

function main()
	n,hp = readline() |> split |> parseMap
	x = Tuple{Int,Int}[]
	for i in 1:n[1]
		a,b = readline() |> split |> parseMap
		push!(x,(a,b))
	end
	println("done")
end

main()


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

function main()
	n,hp = readline() |> split |> parseMap
	x = Tuple{Int,Int}[]
	maxa = 0
	for i in 1:n[1]
		a,b = readline() |> split |> parseMap
		push!(x,(a,b))
		maxa = max(maxa,a)
	end
	useb = Int[]
	for i in 1:n
		if x[i][2] > maxa
			push!(useb, x[i][2])
		end
	end
	useb = sort(useb, rev=true)
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


function main()
	lines=readlines()
	N,H=map(x->parse(Int,x),split(shift!(lines)))
	A=Array{Int}(0)
	B=Array{Int}(0)
	for s=lines
		a,b=map(x->parse(Int,x),split(s))
		push!(A,a)
		push!(B,b)
	end
	a=maximum(A)
	ans=0
	sort!(B)
	reverse!(B)
	for b=B
		if b<a||H<0
			break
		end
		H-=b
		ans+=1
	end
	println(ans+cld(max(H,0),a))
end
main()


function main()
	lines=readlines()
	N,H=map(x->parse(Int,x),split(shift!(lines)))
	A=Array{Int}(0)
	B=Array{Int}(0)
	for s=lines
		a,b=map(x->parse(Int,x),split(s))
		push!(A,a)
		push!(B,b)
	end
	a=maximum(A)
	ans=0
	sort!(B)
	reverse!(B)
	for b=B
		if b<a||H<0
			break
		end
		H-=b
		ans+=1
	end
	println(ans+cld(min(H,0),a))
end
main()


function main()
	lines=readlines()
	N,H=map(x->parse(Int,x),split(shift!(lines)))
	A=Array{Int}(0)
	B=Array{Int}(0)
	for s=lines
		a,b=map(x->parse(Int,x),split(s))
		push!(A,a)
		push!(B,b)
	end
	a=maximum(A)
	ans=0
	sort!(B)
	reverse!(B)
	for b=B
		if b<a||H<0
			break
		end
		H-=b
		ans+=1
	end
	println(ans+cld(H,a))
end
main()


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

function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = readline() |> split |> x -> parseMap(x)
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


parseInt(x) = parse(Int, x)

function main()
	n,h = map(parseInt, split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = map(parseInt, split(readline()))
	end
    print("Perfect!")
end


parseInt(x) = parse(Int, x)

function main()
	n,h = map(parseInt, split(readline()))
    a,b = Array{Int}(n)
	for i in 1:n
		a[i],b[i] = map(parseInt, split(readline()))
	end
    print("OK")
end

main()


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

function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = readline() |> split |> x -> parseMap(x)
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


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

function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = readline() |> split |> x -> parseMap(x)
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


function parseInt(x) parse(Int, x) end
function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = readline() |> split |> x -> map(parseInt, x)
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


function parseInt(x) parse(Int128, x) end
function main()
	n = parseInt.(split(readline()))
	x = Array{Int128}(2, n[1])
	for i in 1:n[1]
		x[:,i] = map(parseInt, split(readline()))
	end
	maxa = maximum(x[1,:])
	useb = Int128[]
	for i in 1:n[1]
		if x[2,i] >= maxa
			push!(useb, x[2,i])
		end
	end
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


function parseInt(x) parse(Int, x) end
function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = map(parseInt, split(readline()))
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] >= maxa
			push!(useb, x[2,i])
		end
	end
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()


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

function main()
	n = parseInt.(split(readline()))
	for i in 1:n[1]
		x = map(parseInt,split(readline()))
	end

	print("fuck")
end

main()


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

function main()
	n = parseInt.(split(readline()))
	for i in 1:n[1]
		x = map(parseInt,(split(readline()))
	end

	print("fuck")
end

main()


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

function main()
	n = parseInt.(split(readline()))
	ab = [0,0]
	for i in 1:n[1]
		ab = readline() |> split |> y -> parseInt.(y)
	end

	print("fuck")
end

main()


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

function main()
	n = parseInt.(split(readline()))
	ab = ""
	for i in 1:n[1]
		ab = readline()
	end

	print("fuck")
end

main()


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

function main()
	n = parseInt.(split(readline()))
	ab = Array{Int}(2,n[1])
	for i in 1:n[1]
		ab[:,i] = readline() |> split |> x -> parseInt.(x)
	end
	maxa = maximum(ab[1,:])

	print(maxa)
end

main()


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

function sub(maxa, useb, h)
  hp = h
  count = 0
  for i in 1:length(useb)
    if hp > 0
      hp -= useb[i]
      count += 1
    end
  end
  if hp > 0
    if hp%maxa == 0
      count += div(hp, maxa)
    else
      count += div(hp, maxa)+1
    end
  end
  print(count)
end

function main()
  n = parseInt.(split(readline()))
  ab = Array{Int}(2,n[1])
  for i in 1:n[1]
    ab[:,i] = readline() |> split |> x -> parseInt.(x)
  end
  maxa = maximum(ab[1,:])
  useb = Int[]
  for i in 1:n[1]
    if ab[2,i] > maxa
      push!(useb, ab[2,i])
    end
  end
  sub(maxa, useb, n[2])
end

main()


function parseInt(x) parse(Int, x) end
function main()
  n = parseInt.(split(readline()))
  ab = Array{Int}(2,n[1])
  for i in 1:n[1]
    ab[:,1] = parseInt.(split(readline()))
  end
  maxa = maximum(ab[1,:])
  useb = Int[]
  for i in 1:n[1]
    if ab[2,i] > maxa
      push!(useb, ab[2,i])
    end
  end
  hp = n[2]
  count = 0
  for i in 1:length(useb)
    if hp > 0
      hp -= useb[i]
      count += 1
    end
  end
  if hp > 0
    if hp%maxa == 0
      count += div(hp, maxa)
    else
      count += div(hp, maxa)+1
    end
  end
  print(count)
end

main()


function parseInt(x) parse(Int, x) end
function main()
  n = parseInt.(split(readline()))
  a = [0 for i in 1:n[1]]
  b = [0 for i in 1:n[1]]
  for i in 1:n[1]
    x = parseInt.(split(readline()))
  	a[i] = x[1]
  	b[i] = x[2]
  end
  maxa = maximum(a)
  useb = Int[]
  for i in 1:n[1]
    if b[i] > maxa
      push!(useb, b[i])
    end
  end
  hp = n[2]
  count = 0
  for i in 1:length(useb)
    if hp > 0
      hp -= useb[i]
      count += 1
    end
  end
  if hp > 0
    if hp%maxa == 0
      count += div(hp, maxa)
    else
      count += div(hp, maxa)+1
    end
  end
  print(count)
end

main()


n, h = parse.(split(readline()))
a = []
b = []
for i in 1:n
	tmp = parse.(split(readline()))
	push!(a, tmp[1])
	push!(b, tmp[2])
end

amax = findfirst(a, maximum(a))

for i in 1:amax-1
	h -= b[i]
end

count = Int(ceil(h/a[amax])) + amax-1

print(count)


n, h = parse.(split(readline()))
a = []
b = []
for i in 1:n
	tmp = parse.(split(readline()))
	push!(a, tmp[1])
	push!(b, tmp[2])
end

amax = findfirst(a, maximum(a))
count = 1

while h > 0
	if count <= amax
		h - b[count]
	else
		h - a[amax]
	end
	count += 1
end

print(count)


function main()
	N,A,B = parse.(Int,split(readline()))
	res=0
	for n = 1:N
		total=0
		for c in string(n)
			total+=parse.(Int,c)
		end

		if A<=total<=B
			res+=n
		end
	end
	println(res)
end

main()

Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


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 kakuketanowa(n::Int)
  s=string(n)
  S=0
  for i=s
    S+=parse(Int,i)
  end
  return S
end
function main()
  n,a,b=pM(split(readline()))
  ans=0
  for i=1:n
    if a<=kakuketanowa(i)<=b
      ans+=i
    end
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
sumdigits(n, base=10) = sum(digits(n, base=10))

function main()
    n,a,b=parseMap(split(readline()))
    ans=0
    for i in 1:n
        if a<=sumdigits(i)<=b
            ans+=i
        end
    end
    println(ans)
end
main()


N,A,B=map(x->parse(Int,x),split(readline()))
ans=0
for i=1:N
  now=i
  sum=0
  while now>0
    sum+=now%10
    now÷=10
  end
  if A<=sum<=B
    ans+=i
  end
end
println(ans)


function verifier(n::Int, a::Int, b::Int)
    sumLevel = 0
    while n != 0
        sumLevel += n % 10
        n = div(n, 10)
    end

    if (a <= sumLevel <= b)
        true
    else
        false
    end
end

prior(a, b) = n -> verifier(n, a, b)

n, a, b = parse.(Int, split(readline()))
nums = [ x for x = 1:n ]

filter(prior(a, b), nums)

println(result |> sum)


parseInt(x) = parse(Int, x)

function ss(n)
	m = n
	sum = 0
	for i in 1:5
		sum +=m%(10)
		m = div(m, 10)
	end
	return(sum)
end

function main()
	n = readline() |> split |> x -> parseInt.(x)
	sum = 0
	for i in 1:n[1]
		if n[2] <= ss(i) <= n[3]
			sum += i
		end
	end
	print(sum)
end

main()


function wa(x)
    res = 0
    while x > 0
        res += x % 10
        x = div(x, 10)
    end
    return res
end

function main()
    n, a, b = map(x -> parse(Int64, x), split(readline()))

    ans = 0
    for x in 1:n
        if a <= wa(x) <= b
            ans += x
        end
    end
    println(ans)
end

main()


function digit_sum(n::Int)
  ret=0
  while n>0
  	ret+=n%10
    n=div(n,10)
  end
  ret
end

n,a,b=parse.(split(readline()))
sum=0
for i in 1:n
  ds=digit_sum(i)
  if a<=ds<=b
    sum+=i
  end
end
println(sum)


(n,a,b)=map(x->parse(Int,x),split(readline()))
s=0
for i=1:n
	x=i
	m=0
	while x>0
		m+=x%10
		x=div(x,10)
	end
	if a<=m<=b
		s+=i
	end
end
print(s)


Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


ParseInt(x) = parse(Int,x)
ParseMap(x::Array{SubString{String},1}) = map(ParseInt,x)
function main()
    a = chomp(readline())
    cnt = 0
    if a[1] == '1'
        cnt += 1
        end
        if a[2] == '1'
            cnt += 1
            end
            if a[3] == '1'
                cnt += 1
                end
                println(cnt)
end
main()


s = readline()
count = 0
for i in 1:3
  if s[i] == '1'
    global count += 1
  end
end

print(count)


s = readline()
count = 0
for i in 1:length(s)
  if parse(Int, s[i]) == 1
    global count += 1
  end
end
print(count)


s = readline()
count = 0
for i in 1:length(s)
  if s[i] == 1
    global count += 1
  end
end
print(count)


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

function main()
    println(count(i->i=='1',chomp(readline())))
end
main()


input = chomp(readline())
s = map(x -> parse(Int,x),split(input,""))
r = sum([x for x in s if x == 1])
println(r)


input = readline()
s = map(x -> parse(Int,x),split(input,""))
r = sum([x for x in s if x == 1])
println(r)


function main()

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

  ans = 0

  for i in 1:3

    if s[i] == "1"
      ans += 1
    end

  end

  println(ans)

end

main()


function main()

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

  ans = 0

  for 1:3

    if s[i] == "1"
      ans += 1
    end

  end

  println(ans)

end

main()


function main()
    S = readline()
    res = 0
    for i in 1:3
        res += Int(S[i]-'0')
    end
    println(res)
end

main()


# AtCoder Beginner Contest 081 A
# [URL]      https://atcoder.jp/contests/abc081/tasks/abc081_a
# [compiler] Version 0.5.0
# [reference]
# <1> https://atcoder.jp/contests/abc081/submissions/3181551

#==================================================================================================#
function isTargetNum( char, target )
	return Base.ifelse( Base.isequal(char, target), 1, 0 )
end

function abc081_a()

	# STEP.01
	# get the target positive numbers
	buffer = Base.readline( Base.STDIN )

	# STEP.02
	# count up the target letter
	count =  Base.zero( Core.Int16 )
	count += Main.isTargetNum( buffer[1], '1' )
	count += Main.isTargetNum( buffer[2], '1' )
	count += Main.isTargetNum( buffer[3], '1' )

	# STEP.03
	# output the result
	Base.println( Base.STDOUT, count )

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc081_a()


function main()
	s = parse.(split(readline(), ""))
	x = 0
	for i in 1:3
		x += s[i]
	end
	print(x)
end

main()


function main()
    str = readline()
    ans = 0

    for c in str
        ans += (c =='1') ? 1 : 0
    end
    println(ans)
end

main()


function main()
    s = readline()

    counter = 0
    if s[1] == '1'; counter += 1; end
    if s[2] == '1'; counter += 1; end
    if s[3] == '1'; counter += 1; end

    println(counter)
end

main()


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

function main()
	s = readline() |> chomp
	t = readline() |> chomp
	d = String[]
	for i in 1:length(s)-length(t)+1
		f = 0
		for j in 1:length(t)
			if s[i+j-1]!=t[j] && s[i+j-1]!= '?'
				f = 1
			end
		end
		if f == 0
			push!(d,replace(s[1:i-1]*t*s[i+length(t):length(s)],"?" => "a"))
		end
	end
	if length(d) == 0
		println("UNRESTORABLE")
	else
		d = sort(d)
		println(d[1])
	end
end

main()

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


function check(s::Char,t::Char)
    s==t || s=='?'
end
change(x::Char) = x=='?' ? 'a' : x
function main()
    s,t=chomp.(readlines())
    ans=String[]
    for start=1:length(s)-length(t)+1
        if all([check(s[i],t[i-start+1]) for i=start:start+length(t)-1])
            k= start==length(s)-length(t)+1 ? s[1:start-1]*t : s[1:start-1]*t*s[start+length(t):end]
            push!(ans,k)
        end
    end
    isempty(ans) ? print("UNRESTORABLE") : foreach(x->print(change(x)),minimum(ans))
end
main()


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

function main()
    s=chomp(readline())
    t=chomp(readline())
    n=length(s)
    l=length(t)
    ans="UNRESTORABLE"
    flg1=false
    for i in n-l+1:-1:1
        tmp=s[i:i+l-1]
        if tmp==t
            ans=s
            flg1=true
            break
        end
    end
    if !flg1
        for i in n-l+1:-1:1
            tmp=s[i:i+l-1]
            flg=true
            for j in 1:l
                if tmp[j]!=t[j] && tmp[j]!='?'
                    flg=false
                    break
                end
            end
            if flg
                ans=s[1:i-1]*t*s[i+l:end]
                break
            end
        end
    end
    for i in 1:length(ans)
        if ans[i]=='?'
            ans=ans[1:i-1]*"a"*ans[i+1:end]
        end
    end
    println(ans)
end
main()


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

function main()
    s=chomp(readline())
    t=chomp(readline())
    n=length(s)
    l=length(t)
    ans="UNRESTORABLE"
    flg1=false
    for i in n-l+1:-1:1
        tmp=s[i:i+l-1]
        if tmp==t
            ans=s
            flg1=true
            break
        end
    end
    if !flg1
        for i in n-l+1:-1:1
            tmp=s[i:i+l-1]
            flg=true
            for j in 1:l
                if tmp[j]!=t[j] && tmp[j]!='?'
                    flg=false
                    break
                end
            end
            if flg
                ans=s[1:i-1]*t
                break
            end
        end
    end
    for i in 1:length(ans)
        if ans[i]=='?'
            ans=ans[1:i-1]*"a"*ans[i+1:end]
        end
    end
    println(ans)
end
main()


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

function main()
    s=chomp(readline())
    t=chomp(readline())
    n=length(s)
    l=length(t)
    ans="UNRESTORABLE"
    for i in n-l+1:-1:1
        tmp=s[i:i+l-1]
        flg=true
        for j in 1:l
            if tmp[j]!=t[j] && tmp[j]!='?'
                flg=false
                break
            end
        end
        if flg
            ans=s[1:i-1]*t
            break
        end
    end
    for i in 1:length(ans)
        if ans[i]=='?'
            ans=ans[1:i-1]*"a"*ans[i+1:end]
        end
    end
    println(ans)
end
main()


s=chomp(readline())
t=chomp(readline())
A=String[]
for i=1:length(s)-length(t)+1
	flag=true
	for j=1:length(t)
		if s[i+j-1]!='?'&&s[i+j-1]!=t[j]
			flag=false
		end
	end
	if flag
		push!(A,join(i<=k<i+length(t) ? t[k-i+1] : s[k]=='?' ? 'a' : s[k] for k=1:length(s)))
	end
end
println(isempty(A) ? "UNRESTORABLE" : minimum(A))


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

function main()
	s = chomp(readline())
	t = chomp(readline())
	ls = length(s)
	lt = length(t)
	gflg = 0
	initial = 0
	for i in 0:ls-lt
		lflg = 0
		for j in 1:lt
			if s[ls-lt-i+j] != t[j] && s[ls-lt-i+j] != '?'
				lflg = 1
				break
			end
		end
		if lflg == 0
			initial = ls-lt-i+1
			gflg = 1
			break
		end
	end
	if gflg == 0
		println("UNRESTORABLE")
	else
		for i in 1:initial-1
			if s[i] == '?'
				print('a')
			else
				print(s[i])
			end
		end
		print(t)
		for i in initial+lt:ls
			if s[i] == '?'
				print('a')
			else
				print(s[i])
			end
		end
	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()
    h,w=parseMap(split(readline()))
    s=[readline() for i in 1:h]
    ans=""
    for i in 1:h
        for j in 1:w
            if s[i][j]=='#'
                ans=join([ans,'#'])
                continue
            end
            res=0
            for (y,x) in [(i-1,j-1),(i-1,j),(i-1,j+1),(i,j-1),(i,j+1),(i+1,j-1),(i+1,j),(i+1,j+1)]
                try
                    if s[y][x]=='#'
                        res+=1
                    end
                catch
                    1+1
                end
            end
            ans=join([ans,string(res)])
        end
        ans=join([ans,"\n"])
    end
    println(ans)
end
main()

Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

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

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310


function main()

  (H,W) = map(x -> parse(Int,x), split(readline()))

  S = ["" for i in 1:H,j in 1:W]
  nums = zeros(Int,H,W)

  for i in 1:H
    S[i,:] = split(chomp(readline()),"")
  end

  for i in 1:H,j in 1:W

    if S[i,j] == "#"

      if i-1 > 0
        nums[i-1,j] +=1
      end
      if i-1 > 0 && j+1 <= W
        nums[i-1,j+1] +=1
      end
      if j+1 <= W
        nums[i,j+1] +=1
      end
      if i+1 <= H && j+1 <= W
        nums[i+1,j+1] +=1
      end
      if i+1 <= H
        nums[i+1,j] +=1
      end
      if i+1 <= H && j-1 > 0
        nums[i+1,j-1] +=1
      end
      if j-1 > 0
        nums[i,j-1] +=1
      end
      if i-1 > 0 && j-1 > 0
        nums[i-1,j-1] +=1
      end

    end

  end

  for i in 1:H,j in 1:W

    if S[i,j] == "#"
      print("#")
    else
      print(nums[i,j])
    end

    if j == W
      println()
    end

  end

end

main()


function f()
    input = map(x->parse(Int, x), split(chomp(readline()), " "))

    h = input[1]
    w = input[2]
    s = []
    c = ""

    for i in 1:h
        push!(s, chomp(readline()))
    end

    for i in 1:h
        s_tmp = ""
        for j in 1:w
            if s[i][j] == '#'
                c = "#"
            else
                c = 0
                if j != w c += Int(s[i][j+1] == '#') end
                if i != h && j != w c += Int(s[i+1][j+1] == '#') end
                if i != h c += Int(s[i+1][j] == '#') end
                if i != h && j != 1 c += Int(s[i+1][j-1] == '#') end
                if j != 1 c += Int(s[i][j-1] == '#') end
                if i != 1 && j != 1 c += Int(s[i-1][j-1] == '#') end
                if i != 1 c += Int(s[i-1][j] == '#') end
                if i != 1 && j != w c += Int(s[i-1][j+1] == '#') end
            end
            if c == 0
                s_tmp = s_tmp * "."
            elseif c == "#"
                s_tmp = s_tmp * c
            else
                s_tmp = s_tmp * string(c)
            end
        end
        s[i] = s_tmp
    end
    return s
end
f()


h,w=map(x->parse(Int,x),split(readline()))
s=[];
for i=1:h
	push!(s,readline())
end
dx=[0,1,0,-1,1,1,-1,-1]
dy=[1,0,-1,0,1,-1,1,-1]
for i=1:h
	for j=1:w
		if s[i][j]=='#'
			print('#')
		else
			c=0
			for r=1:8
				x=i+dx[r]
				y=j+dy[r]
				if 0<x<=h&&0<y<=w&&s[x][y]=='#'
					c+=1
				end
			end
			print(c)
		end
	end
	println()
end


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

function main()
	n = readline() |> parseInt
	x = 0
	for i in 1:n
		l,r = readline() |> split |> parseMap
		x+=(r-l+1)
	end
	println(x)
end

main()

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
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())
    ans=0
    for i in 1:n
        l,r=parseMap(split(readline()))
        ans+=r-l+1
    end
    println(ans)
end
main()


function main()

  N = parse(Int,readline())

  count = 0

  for i in 1:N

    l,r = map(x -> parse(Int,x), split(readline()))
    count += abs(l-r)+1

  end

  println(count)

end

main()


function main()
    N = parse(readline())
    l = Array{Int64,1}(zeros(N))
    r = Array{Int64,1}(zeros(N))
    ANSWER = Int64(0)
    for i = 1:N
        l[i], r[i] = parse.(split(readline()))
        ANSWER += r[i] - l[i] + 1
    end
    print(ANSWER)
end

main()


n = parse(Int, readline())
ans = 0
for i in 1:n
    (l, r) = parse.([Int], split(readline()))
    ans += r - l + 1
end
println(ans)


S = Set(Array{Char,1}(readline()))
ans = "None"

for c in 'a':'z'
    if !in(c,S)
        global ans = c
        break
    end
end

println(ans)

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


function main()

  S = split(readline(),"")

  check = false

  for i in 0:25

    if !in(string('a'+i),S)
      check = true
      println('a'+i)
      break
    end

  end

  if !check

    println("None")

  end

end

main()


function main()
	s = sort(collect(chomp(readline())))
	x = 97
	flg = 0
	if Int(s[1]) >97
		print("a")
	else
		for i in 2:length(s)
			if Int(s[i])-Int(s[i-1]) > 1
				print(Char(Int(s[i-1])+1))
				flg = 1
				break
			end
		end
		if flg == 0
			if Int(s[length(s)]) < 122
				print(Char(Int(s[length(s)])+1))
			else
				print("None")
			end
		end
	end
end
main()


s = collect(chomp(readline()))
s = sort(s)
min = 97
flg = 0
for i in 1:length(s)
	if Int(s[i]) > min
		min +=1
		if Int(s[i]) > min
			print(Char(Int(s[i])-1))
			flg = 1
			break
		end
	end
end
if flg==0
	print("None")
end


function solve()
    N, A, B = parse.(Int, split(readline()))
    if(A > B)
        println(0)
        return
    end
    if(N == 1)
        println(B-A+1)
        return
    end

    smin = A*(N-1) + B
    smax = B*(N-1) + A

    println(smax - smin + 1)
end

solve()

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


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

function main()
	n,a,b = readline() |> split |> parseMap
	if a==b
		println(1)
	elseif n==1||a>b
		println(0)
	elseif n == 2
		println(1)
	else
		println(b*(n-1)+a-a*(n-1)-b+1)
	end
end

main()


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

function main()
	n,a,b = readline() |> split |> parseMap
	if a==b
		println(1)
	elseif n==1||a<b
		println(0)
	elseif n == 2
		println(1)
	else
		println(b*(n-1)+a-a*(n-1)-b+1)
	end
end

main()


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

function main()
	n,a,b = readline() |> split |> parseMa@
	if n == 1&&a!=b
		println(0)
	elseif a>b
		println(0)
	else
		println((b-a)*(n-2)+1)
	end
end
main()


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

if a == b
    println(1)
elseif b < a || n == 1
    println(0)
elseif n == 2
    println(1)
else
    println((n - 2) * (b - a)  + 1)
end