module AtCoder

	export readline

	function readline(T)
  		return Base.parse(T, Base.readline(Base.stdin))
	end

end

module ABC162

	import Main.AtCoder
	export task_a

	function task_a(target_integer::Core.UInt16)

  		given_integer = AtCoder.readline(Core.UInt16)
  		data_digits   = Base.digits(given_integer)

  		for itr = 1:1:Base.size(data_digits, 1)
    		if (data_digits[itr] == target_integer)
      			return "Yes"
    		end
  		end

  		return "No"

	end

end

Base.println(ABC162.task_a(Base.convert(Core.UInt16, 7)))


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

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes

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.


x = parse(Int, readline())
function mygcd(a,b,c)
    if(a==b && b==c)
        return a
    end
    max = div(maximum((a,b,c)),2)
    GCD = 0
    for i in [i for i = 1:max]
        if(a%i==0 && b%i==0 && c%i==0)
            GCD = i
        end
    end
    return GCD
end

function sp_comb(a,b,c)
    if(a > b && b > c)
        return 6
    elseif(a > b && b == c)
        return 3
    elseif(a == b && b > c)
        return 3
    else
        return 1
    end
end

function mysum(K)
    S = 0
    for a in [i for i = 1:K]
        for b in [i for i = 1:a]
            for c in [i for i = 1:c]
                S = S + gcd(a,b,c)*sp_comb(a,b,c)
            end
        end
    end
    return S
end


x = parse(Int, readline())

function mygcd(a,b,c)
    if(a==b && b==c)
        return a
    end
    max = div(maximum((a,b,c)),2)
    GCD = 0
    for i in [i for i = 1:max]
        if(a%i==0 && b%i==0 && c%i==0)
            GCD = i
        end
    end
    return GCD
end

function mysum(K)
    S = 0
    for a in [i for i = 1:K]
        for b in [i for i = 1:K]
            for c in [i for i = 1:K]
                S = S + gcd(a,b,c)
            end
        end
    end
    return S
end
println(mysum(x))


x = readline()

y = string(x)

if y[1] =="7" || y[2] =="7" || y[3] =="7"
    print("Yes")
else
    print("No")
end


x = readline()

y = map(parse, split(x))

if(y[1] == 7):
    println("Yes")
elseif(y[2] == 7):
    println("Yes")
elseif(y[3] == 7):
    println("Yes")
else:
    println("No")


function main()

  N = readline()

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

end

main()


import Base: iterate, length

struct Combination{T}
    arr::Array{T,1}
    picks::Int
end

function length(combi::Combination)
    m = length(combi.arr)
    n = combi.picks

    result = 1
    for i in 1:n
        result *= (m - i + 1)
        result = div(result, i)
    end
    result
end

function nextstate(arraysize::Int, state::Array{Int})
    if state[1] == arraysize - length(state) + 1
        return [0]
    end

    if state[end] < arraysize
        state[end] += 1
        return state
    end

    targetindex = length(state) - 1

    while targetindex > 0
        if state[targetindex] + 1 === state[targetindex+1]
            targetindex -= 1
        else
            state[targetindex] += 1
            for i in (targetindex+1):length(state)
                state[i] = state[i-1] + 1
            end
            return state
        end
    end
    # ここに来ることは無いはず
    return state
end

function iterate(combi::Combination, state)
    if state == [0]
        return nothing
    end
    arraysize = length(combi.arr)
    value = combi.arr[state]
    state = nextstate(arraysize, state)
    return (value, state)
end

function iterate(combi::Combination)
    if combi.picks > length(combi.arr)
        return nothing
    end
    if combi.picks === 0
        return (typeof(combi.arr)[], [0])
    end
    state = collect(1:(combi.picks))
    value = combi.arr[state]
    arraysize = length(combi.arr)
    return (value, nextstate(arraysize, state))
end

function main()
    n = parse(Int, readline())
    s = readline()
    array = collect(1:n)
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    for i in 1:n
        c = s[i]
        if c == 'R'
            push!(counts[1], i)
            x += 1
        elseif c == 'G'
            push!(counts[2], i)
            y += 1
        else
            push!(counts[3], i)
            z += 1
        end
    end

    for i in 1:x
        for j in 1:y
            for k in 1:z
                if counts[2][j] - counts[1][i] == counts[3][k] - counts[2][j]
                    #カウントしない
                else
                    count += 1
                end
            end
        end
    end

    println(count)
end

main()


function main()
    s = readline()
    if findfirst("7", s) == nothing
        println("No")
    else
        println("Yes")
    end
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N = readline()
flag = false
for n in N
    if n == '7'
        flag = true
    end
end

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

main()


function main()
    K=parse(Int,readline())
    ans = 0
    for a in 1:K
        for b in 1:K
            for c in 1:K
                ans += gcd(a,b,c)
            end
        end
    end
    println(ans)
end

main()

Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


function solve()
    k = parse(Int, readline())
    ret = 0
    for a=1:k, b=1:k, c=1:k
        ret += gcd(a, b, c)
    end
    ret
end

println(solve())


parseInt(x) = parse(Int,x)

function main()
    K = parseInt(readline())
    c = 0
    for i=1:K, j=1:K, k=1:K
        c += gcd(i,j,k)
    end
    println(c)
end

main()


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

function main()
    K = parseInt(readline())
    c = 0
    for i=1:K, j=1:K, k=1:K
        c += gcd(i,j,k)
    end
    println(c)
end

main()


quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = parse.(Int, split(readline()))

function main()
  K = in_1()
  s = 0
  for a in 1:K
    for b in 1:K
      gcd_ab = gcd(a, b)
      for c in 1:K
        s += gcd(a, b, c)
      end
    end
  end
  println(s)
end

isempty(ARGS) && main()


(() -> begin
  k = readline() |> x->parse.(Int,x)
  ans = 0
  for a in 1:k
    for b in 1:k
      tmp = gcd(a, b)
      for c in 1:k
        ans += gcd(tmp, c)
      end
    end
  end
  println(ans)
end)()


function f(k)
    sum::UInt128=0
    for a=1:k,b=1:k,c=1:k
        sum += gcd(a,b,c)
    end
    return sum
end
k=parse(Int,readline())
print(f(k))


k=parse(Int,readline())
[gcd(a,b,c) for a=1:k,b=1:k,c=1:k]|>println∘sum


k=parse(Int,readline())
[gcd(a,b,c) for a=1:k,b=1:k,c=1:k]|>sum|>println


  k = parse(Int, readline())
  ans = 0
  for a = 1:k, b = 1:k, c = 1:k
    ans += gcd(a,b,c)
  end
  println(ans)


function main()
  k = parse(Int, readline())
  ans = 0
  for a = 1:k, b = 1:k, c = 1:k
    ans += gcd(a,b,c)
  end
  println(ans)
end

main()


n = parse(Int, readline())

function cal(i, j, k)
  ans = gcd(gcd(i, j), k)

  if i == j == k
    ans
  elseif i == j || j == k || k == i
    ans * 3
  else
    ans * 6
  end
end

println(sum([
  cal(i, j, k)
  for i in 1:n
  for j in i:n
  for k in j:n
]))


K=parse(Int,readline())
println(sum(1:K .|>i->sum(1:K .|>j->sum(1:K .|>k->gcd(i,j,k)))))


function main()
    k = parse(Int, readline())
    sum = 0
    for a in 1:k
        for b in 1:k
            @simd for c in 1:k
                sum += gcd(a,b,c)
            end
        end
    end
    println(sum)
end

main()


function main()
    k = parse(Int, readline())
    sum = 0
    for a in 1:k
        @simd for b in 1:k
            for c in 1:k
                sum += gcd(a,b,c)
            end
        end
    end
    println(sum)
end

main()


let
  K = parse(Int, readline())
  a = 0
  for l = 1:K, m = 1:K, n = 1:K
    a += gcd(l, m, n)
  end
  println(a)
end


x = parse(Int, readline())

function mygcd(a,b,c)
    if(a==b && b==c)
        return a
    end
    max = div(maximum((a,b,c)),2)
    GCD = 0
    for i in [i for i = 1:max]
        if(a%i==0 && b%i==0 && c%i==0)
            GCD = i
        end
    end
    return GCD
end

function mysum(K)
    S = 0
    for a in [i for i = 1:K]
        for b in [i for i = 1:K]
            for c in [i for i = 1:K]
                S = S + mygcd(a,b,c)
            end
        end
    end
    return S
end
println(mysum(x))


function main()

  K = parse(Int, readline())

  ans = 0

  for i in 1:K, j in 1:K, k in 1:K
    ans += gcd(i, j, k)
  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()
    k=parseInt(readline())
    ans=0
    for i in 1:k
        for j in 1:k
            for l in 1:k
                ans+=gcd(i,j,l)
            end
        end
    end
    println(ans)
end
main()


using DataStructures

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

function main()
    K = readline() |> parseInt
    dd = DefaultDict{Int,Int}(0)
    for i in 1:K
        for j in 1:K
            dd[gcd(i,j)] += 1
        end
    end
    ans = 0
    for key in keys(dd)
        for k in 1:K
           ans += gcd(key,k)*dd[key]
        end
    end
    println(ans)
end

main()


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

function main()
	n = readline() |> parseInt
	s = 0
	for i in 1:n
		for j in 1:n
			for k in 1:n
				s += gcd(i,j,k)
			end
		end
	end
	println(s)
end

main()


K=parse(Int,readline())

function main(K)
    s=0
    for i in 1:K , j in  1:K , k in 1:K
        s+=gcd(i,j,k)
    end
    s
end

print(main(K))


function main()
    k = parse(Int, readline())
    sum = 0
    for a in 1:k
        for b in 1:k
            for c in 1:k
                sum += gcd(a,b,c)
            end
        end
    end
    println(sum)
end

main()


function RGBTriplets()
    N = parse(Int, readline())
    S = readline()
    r, g, b = 0, 0, 0
    for s in S
        if s =='R'
            r+=1
        elseif s == 'G'
            g+=1
        else
            b+=1
        end
    end
    counter = 0
    for i in 1:N-1
        for j in i+1:N
            k = 2j - i
            k > N && break
            (S[i] ≠ S[j]) && (S[j] ≠ S[k]) && (S[k] ≠ S[i]) && (counter += 1)
        end
    end
    return println(r*g*b - counter)
end
RGBTriplets()

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


function countRGB(s)
    numR = numG = numB = 0
    for c in s
        if c == 'R'
            numR += 1
        elseif c == 'G'
            numG += 1
        elseif c == 'B'
            numB += 1
        end
    end
    (numR, numG, numB)
end

function numequaldistance(s)
    ret = 0
    for i = 1:length(s)-2
        for d = 1:(length(s)-i)÷2
            j = i+d
            k = j+d
            if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
                ret += 1
            end
        end
    end
    ret
end

function solve()
    readline()
    s = readline()
    numR, numG, numB = countRGB(s)
    ned = numequaldistance(s)
    numR*numG*numB - ned
end

println(solve())


(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()
  ans = count("R", s) * count("G", s) * count("B", s)
  for i in 1:n-2
    for j in i+1:n-1
      k = 2 * j - i
      if k <= length(s) && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        ans -= 1
      end
    end
  end
  println(ans)
end)()


(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()
  ans = count("R", s) * count("G", s) * count("B", s)
  for i in 1:n-2
    for j in i+1:n-1
      k = 2 * j - i
      if k <= n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        ans -= 1
      end
    end
  end
  println(ans)
end)()


(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()
  dict = Dict([['R',0],['G',0],['B',0]])
  for i in 1:n
    dict[s[i]] += 1
  end
  ans = dict['R'] * dict['G'] * dict['B']
  for i in 1:n-2
    for j in i+1:n-1
      k = 2 * j - i
      if k <= n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        ans -= 1
      end
    end
  end
  println(ans)
end)()


(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()
  dict = Dict([['R',0],['G',0],['B',0]])
  for i in 1:n
    dict[s[i]] += 1
  end
  ans = dict['R'] * dict['G'] * dict['B']
  for i in 1:n-2
    for j in i+1:n-1
      k = 2 * j - i
      if k > n
        break
      end
      if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        ans -= 1
      end
    end
  end
  println(ans)
end)()


(() -> begin
  n = readline() |> x->parse.(Int,x)
  s = readline()

  ans = 0
  for i in 1:(n-2)
    s_i = s[i]
    for j in i+1:(n-1)
      s_j = s[j]
      if s_i == s_j
        continue
      end
      for k in j+1:n
        s_k = s[k]
        if s_i != s_k && s_j != s_k && j - i != k - j
          ans += 1
        end
      end
    end
  end
  println(ans)
end)()


quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = parse.(Int, split(readline()))

function main()
  N = in_1()
  S0 = readline()
  @assert length(S0) == N
  S = [(s=='R' ? 1 : s=='G' ? 2 : 4) for s in S0]
  d2 = Dict{Tuple{Int, Int}, Int}()
  for i in 1:N-2
    s1 = S[i]
    for j in i+1:N-1
      s2 = S[j]
      s1 != s2 || continue
      v = get!(d2, (j, s1+s2), 0)
      d2[(j, s1+s2)] = v+1
    end
  end

  c = 0
  for k in 3:N
    s3 = S[k]
    c += sum(get(d2, (j, 7-s3), 0) for j in 2:k-1)
  end

  jufuku = 0
  for k in 3:N
    s3 = S[k]
    for j in 2:k-1
      i = j - (k-j)
      i > 0 || continue
      S[i] + S[j] + s3 == 7 && (jufuku += 1)
    end
  end

  println(c-jufuku)
end

isempty(ARGS) && main()


quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = parse.(Int, split(readline()))

function main()
  N = in_1()
  S0 = readline()
  S = [(s=='R' ? 1 : s=='G' ? 2 : 4) for s in S0]
  ans = 0
  for (i, s1) in enumerate(S[1:end-2])
    for j in i+1:length(S)-1
      s2 = S[j]
      s1s2 = s1+s2
      for k in j+1:length(S)
        j-i != k-j || continue
        s3 = S[k]
        s1s2+s3==7 || continue
        ans += 1
      end
    end
  end
  println(ans)
end

isempty(ARGS) && main()


quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = parse.(Int, split(readline()))

function main()
  N = in_1()
  S0 = readline()
  S = [(s=='R' ? 1 : s=='G' ? 2 : 4) for s in S0]
  d = Dict{Int, typeof(Dict(3=>Int[], 5=>Int[], 6=>Int[]))}()
  for i1 in 1:length(S)-2
    s1 = S[i1]
    for i2 in i1+1:length(S)-1
      s2 = S[i2]
      d2 = get!(d, i2, Dict(3=>Int[], 5=>Int[], 6=>Int[]))
      if s1 != s2
        dval = push!(d2[s1+s2], i2-i1)
      end
    end
  end

  s = 0
  for i3 in 3:length(S)
    s3 = S[i3]
    for i2 in 2:i3-1
      dval = d[i2][7-s3]
      s += count(!isequal(i3-i2), dval)
    end
  end
  println(s)
end

isempty(ARGS) && main()


import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

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

delimset = Set([0x0a, 0x20])

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

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

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

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

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

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

function othernum(i,j)
    ij = i+j
    3 - ij%3
end

function main()
    N, S = reads(Int, String)
    SI = map(x -> begin x == 'R' && return 1; x == 'G' && return 2; x == 'B' && return 3 end, collect(S))
    d = zeros(Int, 3, N)

    for j in 1:3
        d[j,1] = 0
    end
    d[SI[begin],1] = 1

    for i in 2:length(SI)
        for j in 1:3
            d[j,i] = d[j,i-1]
        end
        d[SI[i],i] += 1
    end

    if N <= 3
        println(0)
        return
    end

    c = 0
    for i in 1:length(SI)-2, j in i+1:length(SI)-1
        if SI[i] != SI[j]
            k = othernum(SI[i],SI[j])
            c += d[k,N] - d[k,j]
            c -= (2j-i<=N && SI[2j-i]==k) ? 1 : 0
        end
    end
    println(c)
end

main()


function main()
  n = parse(Int, readline())
  s = chomp(readline())

  # # 3文字未満の場合、条件を満たす組は存在しない
  if n < 3
    println(0)
    exit()
  end

  # 間隔が等しい場合の数を先に求める
  cnt = 0
  for d in 1:div(n-1,2)
    for i in 1:(n-2*d)
      j = i + d
      k = j + d
      if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
        cnt += 1
      end
    end
  end

  r = 0
  g = 0
  b = 0
  ans = 0
  for i in 1:n
    if s[i] == 'R'
      ans += g * b
      r += 1
    elseif s[i] == 'G'
      ans += r * b
      g += 1
    elseif s[i] == 'B'
      ans += r * g
      b += 1
    end
  end

  println(ans - cnt)
end

main()


function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    hoge = 0
    @simd for i in 1:n
        aa = min(i-1, n-i)
        @simd for j in 1:aa
            if s[i] != s[i-j] != s[i+j] != s[i]
                # println(s[i], s[i-j], s[i+j])
                hoge += 1
            end
        end
        c = s[i]
        if c == 'R'
            x += 1
        elseif c == 'G'
            y += 1
        else
            z += 1
        end
    end
    println(x*y*z-hoge)
end

main()


function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    hoge = 0
    for i in 1:n
        aa = min(i-1, n-i)
        @simd for j in 1:aa
            if s[i] != s[i-j] != s[i+j] != s[i]
                # println(s[i], s[i-j], s[i+j])
                hoge += 1
            end
        end
        c = s[i]
        if c == 'R'
            x += 1
        elseif c == 'G'
            y += 1
        else
            z += 1
        end
    end
    println(x*y*z-hoge)
end

main()


function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    hoge = 0
    @simd for i in 1:n
        aa = min(i-1, n-i)
        for j in 1:aa
            if s[i] != s[i-j] != s[i+j] != s[i]
                # println(s[i], s[i-j], s[i+j])
                hoge += 1
            end
        end
        c = s[i]
        if c == 'R'
            x += 1
        elseif c == 'G'
            y += 1
        else
            z += 1
        end
    end
    println(x*y*z-hoge)
end

main()


function main()
    x = readlines()
    x1 = parse(Int, x[1])
    x2 = x[2]
    println(mysum(x1,x2))
end

function RGB(i::Char,j::Char,k::Char)
    if(i == j || i==k)
        return false
    elseif(j == k)
        return false
    else
        return true
    end
end

function mysum(x1::Int,x2::String)
    S = 0
    for j in [j for j = 2:x1-1]
        for i in [i for i = 1:j-1]
                for k in [k for k = j+1:x1]
                        if(j-i == k-j)
                            continue
                        elseif(RGB(x2[i],x2[j],x2[k]))
                            S +=1
                        else
                            continue
                        end
                end
        end
    end
    return S
end
main()


x = readlines()
x1 = parse(Int, x[1])
x2 = x[2]

function RGB(i::Char,j::Char,k::Char)
    if(i == j || i==k)
        return false
    elseif(j == k)
        return false
    else
        return true
    end
end

function mysum(x1,x2)
    S = 0
    for j in [j for j = 2:x1-1]
        for i in [i for i = 1:j-1]
                for k in [k for k = j+1:x1]
                        if(j-i == k-j)
                            continue
                        elseif(RGB(x2[i],x2[j],x2[k]))
                            S +=1
                        else
                            continue
                        end

                end
        end
    end
    return S
end
println(mysum(x1,x2))


function main()

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

  ans = 0

  for i in 1:N-2, j in i+1:N-1, k in j+1:N
    if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && j - i != k - j
      ans += 1
    end
  end

  println(ans)

end

main()


function main()

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

  ans = 0

  for i in 1:N, j in i:N, k in j:N
    if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && j - i != k - j
      ans += 1
    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()
    n=parseInt(readline())
    s=chomp(readline())
    cnt=[Vector{Int}() for i in 1:3]
    color=[0 for i in 1:n]
    for i in 1:n
        if s[i]=='R'
            push!(cnt[1],i)
            color[i]=1
        elseif s[i]=='G'
            push!(cnt[2],i)
            color[i]=2
        else
            push!(cnt[3],i)
            color[i]=3
        end
    end
    l=[length(cnt[i]) for i in 1:3]
    ans=0
    for i in 1:n
        for j in i+1:n
            if s[i]==s[j]
                continue
            end
            if (s[i]=='R' && s[j]=='G') || (s[j]=='R' && s[i]=='G')
                res=searchsortedfirst(cnt[3],j)
                if l[3]<res
                    continue
                end
                ans+=l[3]-res+1
                if cnt[3][res]<=j+j-i<=n &&  color[j+j-i]==3
                    ans-=1
                end
            elseif (s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')
                res=searchsortedfirst(cnt[2],j)
                if l[2]<res
                    continue
                end
                ans+=l[2]-res+1
                if cnt[2][res]<=j+j-i<=n && color[j+j-i]==2
                    ans-=1
                end
            else
                res=searchsortedfirst(cnt[1],j)
                if l[1]<res
                    continue
                end
                ans+=l[1]-res+1
                if cnt[1][res]<=j+j-i<=n &&  color[j+j-i]==1
                    ans-=1
                end
            end
        end
    end
    println(ans)
end
main()


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

r=0
g=0
b=0
for i in 1:N
    S[i]=='R' && (global r+=1)
    S[i]=='G' && (global g+=1)
    S[i]=='B' && (global b+=1)
end

s=0

for t in 1:(N÷2)
    for i in 1:(N-2t)
        j,k=i+t,i+2t
        if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k] )
            global s+=1
        end
    end
end
print(r*g*b-s)


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

s=0
for i in 1:(N-2)
    for j in (i+1):(N-1)
        if S[i]!=S[j]
            for k in (j+1):N
                if(S[i]!=S[k] && S[j]!=S[k] && ((j-i) != (k-j) ))
                    global s+=1
                end
            end
        end
    end
end
print(s)


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

s=0
for i in 1:(N-2)
    for j in (i+1):(N-1)
        if S[i]!=S[j]
            for k in (j+1):N
                #println(i,j,k)
                if(S[i]!=S[k] && S[j]!=S[k] && ((j-i) != (k-j) ))
                    s+=1
                end
            end
        end
    end
end
print(s)


function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    hoge = 0
    for i in 1:n
        aa = min(i-1, n-i)
        for j in 1:aa
            if s[i] != s[i-j] != s[i+j] != s[i]
                # println(s[i], s[i-j], s[i+j])
                hoge += 1
            end
        end
        c = s[i]
        if c == 'R'
            x += 1
        elseif c == 'G'
            y += 1
        else
            z += 1
        end
    end
    println(x*y*z-hoge)
end

main()


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

function main()
	n = readline() |> parseInt
	s = readline() |> chomp
	t = zeros(Int,n)
	dp = zeros(Int,n)
	r = zeros(Int,n+1)
	g = zeros(Int,n+1)
	b = zeros(Int,n+1)
	for i in 1:n
		r[i+1]=r[i]
		g[i+1]=g[i]
		b[i+1]=b[i]
		if s[i]=='R'
			r[i+1]+=1
		elseif s[i]=='G'
			g[i+1]+=1
			t[i]=1
		else
			b[i+1]+=1
			t[i]=2
		end
	end
	for i in 1:n
		if s[i]=='R'
			dp[i]=g[i]*(b[n+1]-b[i+1])+b[i]*(g[n+1]-g[i+1])
			for j in 1:min(i-1,n-i)
				if t[i-j]!=t[i+j]&&t[i-j]!=t[i]&&t[i+j]!=t[i]
					dp[i]-=1
				end
			end
		elseif s[i]=='G'
			dp[i]=r[i]*(b[n+1]-b[i+1])+b[i]*(r[n+1]-r[i+1])
			for j in 1:min(i-1,n-i)
				if t[i-j]!=t[i+j]&&t[i-j]!=t[i]&&t[i+j]!=t[i]
					dp[i]-=1
				end
			end
		else
			dp[i]=r[i]*(g[n+1]-g[i+1])+g[i]*(r[n+1]-r[i+1])
			for j in 1:min(i-1,n-i)
				if t[i-j]!=t[i+j]&&t[i-j]!=t[i]&&t[i+j]!=t[i]
					dp[i]-=1
				end
			end
		end
	end
	println(sum(dp))
end

main()


function main()
    n = parse(Int, readline())
    s = readline()
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    for i in 1:n
        c = s[i]
        if c == 'R'
            push!(counts[1], i)
            x += 1
        elseif c == 'G'
            push!(counts[2], i)
            y += 1
        else
            push!(counts[3], i)
            z += 1
        end
    end

    for i in 1:x
        for j in 1:y
            for k in 1:z
                a,b,c = counts[1][i], counts[2][j], counts[3][k]
                if b - a == c - b
                    #カウントしない
                else
                    count += 1
                end
            end
        end
    end

    println(count)
end

main()


import Base: iterate, length

struct Combination{T}
    arr::Array{T,1}
    picks::Int
end

function length(combi::Combination)
    m = length(combi.arr)
    n = combi.picks

    result = 1
    for i in 1:n
        result *= (m - i + 1)
        result = div(result, i)
    end
    result
end

function nextstate(arraysize::Int, state::Array{Int})
    if state[1] == arraysize - length(state) + 1
        return [0]
    end

    if state[end] < arraysize
        state[end] += 1
        return state
    end

    targetindex = length(state) - 1

    while targetindex > 0
        if state[targetindex] + 1 === state[targetindex+1]
            targetindex -= 1
        else
            state[targetindex] += 1
            for i in (targetindex+1):length(state)
                state[i] = state[i-1] + 1
            end
            return state
        end
    end
    # ここに来ることは無いはず
    return state
end

function iterate(combi::Combination, state)
    if state == [0]
        return nothing
    end
    arraysize = length(combi.arr)
    value = combi.arr[state]
    state = nextstate(arraysize, state)
    return (value, state)
end

function iterate(combi::Combination)
    if combi.picks > length(combi.arr)
        return nothing
    end
    if combi.picks === 0
        return (typeof(combi.arr)[], [0])
    end
    state = collect(1:(combi.picks))
    value = combi.arr[state]
    arraysize = length(combi.arr)
    return (value, nextstate(arraysize, state))
end

function main()
    n = parse(Int, readline())
    s = readline()
    array = collect(1:n)
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    for i in 1:n
        c = s[i]
        if c == 'R'
            push!(counts[1], i)
            x += 1
        elseif c == 'G'
            push!(counts[2], i)
            y += 1
        else
            push!(counts[3], i)
            z += 1
        end
    end

    for i in x
        for j in y
            for k in z
                if counts[2][j] - counts[1][i] == counts[3][k] - counts[2][j]
                    #カウントしない
                else
                    count += 1
                end
            end
        end
    end

    println(count)
end

main()


import Base: iterate, length

struct Combination{T}
    arr::Array{T,1}
    picks::Int
end

function length(combi::Combination)
    m = length(combi.arr)
    n = combi.picks

    result = 1
    for i in 1:n
        result *= (m - i + 1)
        result = div(result, i)
    end
    result
end

function nextstate(arraysize::Int, state::Array{Int})
    if state[1] == arraysize - length(state) + 1
        return [0]
    end

    if state[end] < arraysize
        state[end] += 1
        return state
    end

    targetindex = length(state) - 1

    while targetindex > 0
        if state[targetindex] + 1 === state[targetindex+1]
            targetindex -= 1
        else
            state[targetindex] += 1
            for i in (targetindex+1):length(state)
                state[i] = state[i-1] + 1
            end
            return state
        end
    end
    # ここに来ることは無いはず
    return state
end

function iterate(combi::Combination, state)
    if state == [0]
        return nothing
    end
    arraysize = length(combi.arr)
    value = combi.arr[state]
    state = nextstate(arraysize, state)
    return (value, state)
end

function iterate(combi::Combination)
    if combi.picks > length(combi.arr)
        return nothing
    end
    if combi.picks === 0
        return (typeof(combi.arr)[], [0])
    end
    state = collect(1:(combi.picks))
    value = combi.arr[state]
    arraysize = length(combi.arr)
    return (value, nextstate(arraysize, state))
end

function main()
    n = parse(Int, readline())
    s = readline()
    array = collect(1:n)
    count = 0
    counts = [Int[], Int[], Int[]] #RGB
    x,y,z = 0,0,0
    for i in 1:n
        c = s[i]
        if c == 'R'
            push!(counts[1], i)
            x += 1
        elseif c == 'G'
            push!(counts[2], i)
            y += 1
        else
            push!(counts[3], i)
            z += 1
        end
    end

    for i in x
        for j in y
            for k in z
                if j - i == k - j
                    #カウントしない
                else
                    count += 1
                end
            end
        end
    end

    println(count)
end

main()


X, Y, Z = map(x -> parse(Int, x), readline() |> split)
println("$Z $X $Y")

Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


X, Y, Z = map(x -> parse(Int, x), readline() |> split)
println("$Y $Z $X")


line = readline()
x, y, z = [parse(Int, x) for x in split(line)]
println("$z $x $y")


function main()
  a,b,c = split(readline())
  println(c, " ", a, " ", b)
end
main()


x=readline()
y=readline()
z=readline()
print("$z $x $y")


x=readline()
y=readline()
z=readline()
print(z)
print(x)
print(y)


function main()
    x, y, z = parse.(Int, split(readline()));
    println(z, " ", x, " ", y)
end


a = readline()
x = parse(Int,a[1])
y = parse(Int,a[3])
z = parse(Int,a[5])
println(z," ",x," ",y)


const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

parseint(x) = parse(int, x)
function readint()
  moji = readline(stdin)
  moji = split(moji)
  return map(parseint,moji)

end

function main()

  a,b,c = readint()
  println(c," ",a," ",b)

end

main()


input = readline()
x, y, z = split(input)
print(z, " ", x, " ", y)


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

function main()
    x,y,z = parseMap(split(readline()))
    println("$z $x $y")
end

main()


X,Y,Z=map(x->parse(Int,x),split(readline()," "))
print(Z," ",X," ",Y)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
X,Y,Z = parseMap(split(readline()))

println("$Z $X $Y")


a,b,c=split(readline())
println("$c $a $b")


function main()

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

  println(Z, " ", X, " ", Y)

end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
X,Y,Z = parseMap(split(readline()))

println("$Z $X $Y")
end

main()


let
  input() = readline()
  N, M = map(x -> parse(Int, x), input() |> split)
  A = map(x -> parse(Int, x), input() |> split)
  sumA = sum(A)
  choice = 0
  for i in 1:N
    A[i] >= sumA/4M && (choice += 1)
  end
  if choice >= M
    println("Yes")
  else
    println("No")
  end
end

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


readintegers() = [parse(Int, x) for x in split(readline())]

n, m = readintegers()
votes = readintegers()

votes = sort!(votes, rev=true)
threshold = 1/(4m) * sum(votes)
sol = votes[m] >= threshold ? "Yes" : "No"

print(sol)


function f(n,m,a)
    for i=1:n
        sum=0
        if a[i]*4>=m
            sum+=1
        end
        if sum==m
            print("Yes")
            exit()
        end
    end
    print("No")
end

n,m=[parse(Int,i) for i in split(readline())]
a=[parse(Int,i) for i in split(readline())]
f(n,m,a)


n,m=[parse(Int,i) for i in split(readline())]
a=[parse(Int,i) for i in split(readline())]
print(count(i->(i>=+(a...)/4/m),a)>=m?"Yes":"No")


n,m=[parse(Int,i) for i in split(readline())]
a=[parse(Int,i) for i in split(readline())]
print(count(i->(i>=sum(a)/4/m),a)>=m?"Yes":"No")


x = parse.(split(readline()))
y = parse.(split(readline()))

M = x[2]
S = sum(y)
const T = S/(4*M)
frag = 0
ys = sort(y,rev=true)
for i in [i for i = 1:M]
    if(ys[i] < T)
        frag=1
    	break
    end
end
if frag == 1
    println("No")
else
    println("Yes")


n, m = parse.(Int, split(readline()))
a = parse.(Int, split(readline()))
th = sum(a) / 4m
count = 0
for i in 1:n
    if a[i] >= th
        count += 1
    end
end
if count >= m
    print("Yes")
else
    print("No")
end


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

function main()
    N, M = parseMap(split(readline()))
    A = parseMap(split(readline()))
    sort!(A, rev=true)
    if A[M] < sum(A)/(4*M)
        println("No")
    else
        println("Yes")
    end
end

main()


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

function main()
    N, M = parseMap(split(readline()))
    A = parseMap(split(readline()))
    if A[M] < sum(A)/(4*M)
        println("No")
    else
        println("Yes")
    end
end

main()


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

sn=sum(Ai)
m_num=sum(4M*(Ai).>=sn)
if m_num >= M
	print("Yes")
else
  print("No")
end


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

function main()
	n,m = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	s = sum(a)
	k = 0
	for i in 1:n
		if a[i]>=s/(4*m)
			k += 1
		end
	end
	println(k>=m?"Yes":"No")
end

main()


N,M=map(x->parse(Int,x),split(readline()))
A=map(x->parse(Int,x),split(readline()))
S=sum(A)
c=0
for a=A
  if a*4*M>=S
    c+=1
  end
end
println(c>=M ? "Yes" : "No")


function main()

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

  check = sum(A) * (1 / 4M)
  ans = false
  count = 0

  for i in 1:N

    if check <= A[i]
      count += 1
    end

    if count >= M
      ans = true
      break
    end

  end

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

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()
    x,y,a,b,c=parseMap(split(readline()))
    p=sort(parseMap(split(readline())),rev=true)
    q=sort(parseMap(split(readline())),rev=true)
    r=sort(parseMap(split(readline())),rev=true)
    ans=sum(p[1:x])+sum(q[1:y])
    xi,yi=x,y
    for i in r
        if xi>0 && yi>0
            if p[xi]<q[yi] && i>p[xi]
                ans+=i-p[xi]
                xi-=1
            elseif i>q[yi]
                ans+=i-q[yi]
                yi-=1
            end
        elseif xi>0 && i>p[xi]
            ans+=i-p[xi]
            xi-=1
        elseif yi>0 && i>q[yi]
            ans+=i-q[yi]
            yi-=1
        else
            break
        end
    end
    println(ans)
end
main()

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


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()
    x,y,a,b,c=parseMap(split(readline()))
    p=sort(parseMap(split(readline())),rev=true)
    q=sort(parseMap(split(readline())),rev=true)
    r=sort(parseMap(split(readline())),rev=true)
    ans=sum(p[1:x])+sum(q[1:y])
    xi,yi=x,y
    for i in r
        if i<min(p[xi],q[yi])
            break
        end
        if xi>0
            if p[xi]<q[yi]
                ans+=i-p[xi]
                xi-=1
            end
        elseif yi>0
            ans+=i-q[yi]
            yi-=1
        else
            break
        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()
    x,y,a,b,c=parseMap(split(readline()))
    p=sort(parseMap(split(readline())),rev=true)
    q=sort(parseMap(split(readline())),rev=true)
    r=sort(parseMap(split(readline())),rev=true)
    ans=sum(p[1:x])+sum(q[1:y])
    xi,yi=x,y
    for i in r
        if xi>0 && p[xi]<q[yi] && i>p[xi]
            ans+=i-p[xi]
            xi-=1
        elseif yi>0 && i>q[yi]
            ans+=i-q[yi]
            yi-=1
        else
            break
        end
    end
    println(ans)
end
main()


function main()
  X,Y,A,B,C=map(x->parse(Int,x),split(readline()))
  p=sort(map(x->-parse(Int,x),split(readline())))
  q=sort(map(x->-parse(Int,x),split(readline())))
  r=map(x->-parse(Int,x),split(readline()))
  for i=1:X
    push!(r,p[i])
  end
  for i=1:Y
    push!(r,q[i])
  end
  sort!(r)
  println(-sum(r[1:X+Y]))
end
main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function heap(a::Array{Int,1})
	h = [a[1]]
	for i in 2:length(a)
		hpush(h,a[i])
	end
	h
end

function hpush(h::Array{Int,1},x)
	push!(h,x)
	l = length(h)
	if l>1
		k = l>>1
		while h[k]>x&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Int,1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if h[2*k]>=z
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k]>=z&&h[2*k+1]>=z
					break
				else
					t = h[2*k]<h[2*k+1]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
	x,y,a,b,c = readline() |> split |> parseMap
	p = readline() |> split |> parseMap
	q = readline() |> split |> parseMap
	r = readline() |> split |> parseMap
	p = sort(p,rev=true)
	q = sort(q,rev=true)
	hp = Int[]
	hq = Int[]
	for i in 1:x
		hpush(hp,p[i])
	end
	for i in 1:y
		hpush(hq,q[i])
	end
	for i in 1:c
		if hq[1]<=hp[1]
			if hq[1]<r[i]
				hpop(hq)
				hpush(hq,r[i])
			elseif hp[1]<r[i]
				hpop(hp)
				hpush(hp,r[i])
			end
		else
			if hp[1]<r[i]
				hpop(hp)
				hpush(hp,r[i])
			elseif hq[1]<r[i]
				hpop(hq)
				hpush(hq,r[i])
			end
		end
	end
	println(sum(hp)+sum(hq))
end

main()


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

X,Y,A,B,C = parseMap(split(readline()))
P = parseMap(split(readline()))
Q = parseMap(split(readline()))
R = parseMap(split(readline()))

sort!(P)
sort!(Q)
sort!(R)

a = 1
for i in 1:X+Y
    a += 1
end

println(a)


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

  if x > 0
    print("No")
    return;
  end

  if x^2 <= 4*a*b
    print("No")
    return;
  end

  println("Yes")
end; main()

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


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

  if x > 0
    print("No")
    return;
  end

  if x^2 < 4*a*b
    print("No")
    return;
  end

  println("Yes")
end; main()


function main()

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

    x = c - a - b

    hantei = x^2 - 4a * b

    if x > 0 && hantei > 0

        print("Yes")

    else

        print("No")

    end

end

main()


function main()

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

    hantei = (c - a - b)^2 - 4a*b

    if hantei > 0

        print("Yes")

    else
        print("No")

    end

end

main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	ra::BigFloat=sqrt(a)
	rb::BigFloat=sqrt(b)
	rc::BigFloat=sqrt(c)
	println(ra+rb<rc?"Yes":"No")
end

main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	ra::BigFloat=sqrt(a)
	rb::BigFloat=sqrt(b)
	rc::BigFloat=sqrt(b)
	println(ra+rb<rc?"Yes":"No")
end

main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	ra::BigFloat=sqrt(a)
	rb::BigFloat=sqrt(b)
	rc::BigFloat=sqrt(b)
	println(a+b<c?"Yes":"No")
end

main()


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

function main()
    a,b,c=parseMap(split(readline()))
    if c-(a+b)>=0 && 4*a*b<(c-(a+b))^2
        println("Yes")
    else
        println("No")
    end
end
main()


function main()

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

  if 10^5*sqrt(a) + 10^5*sqrt(b) < 10^5*sqrt(c)
    println("Yes")
  else
    println("No")
  end

end

main()


function main()

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

  if sqrt(a) + sqrt(b) < sqrt(c)
    println("Yes")
  else
    println("No")
  end

end

main()


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

function main()
    a,b,c=parseMap(split(readline()))
    if c-(a+b)<0 || 4*a*b>(c-(a+b))^2
        println("No")
    else
        println("Yes")
    end
end
main()


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

function main()
    a,b,c=split(readline())
    if sqrt(parseFloat(a))+sqrt(parseFloat(b))<sqrt(parseFloat(c))
        println("Yes")
    else
        println("No")
    end
end
main()


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

function main()
    a,b,c=split(readline())
    if sqrt(parse(BigFloat,a))+sqrt(parse(BigFloat,b))<sqrt(parse(BigFloat,c))
        println("Yes")
    else
        println("No")
    end
end
main()


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

function main()
    a,b,c=parseMap(split(readline()))
    if sqrt(BigFloat(a))+sqrt(BigFloat(b))<sqrt(BigFloat(c))
        println("Yes")
    else
        println("No")
    end
end
main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	println((c-a-b)^2>4*a*b&&a<=c&&b<=c?"Yes":"No")
end

main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	println((c-a-b)^2>4*a*b?"Yes":"No")
end

main()


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

function main()
	a,b,c = readline() |> split |> parseMap
	println(sqrt(a)+sqrt(b)<sqrt(c)?"Yes":"No")
end

main()


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

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

    hante = sqrt(c) - ((sqrt(a) * sqrt(b)))

    if hante > 0.000000000000000000000000000000000
        ss = "Yes"
    elseif hante < 0.000000000000000000000000000000000
        ss = "No"
    end

    return (print(ss))

end

main()


function main()

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

    hante = sqrt(c) - (a + b + 2 * (sqrt(a) * sqrt(b)))

    if hante > 0.000000000000000000000000000000000
        print("Yes")
    else
        print("No")
    end

end

main()


function main()

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

    hante = sqrt(c) - (sqrt(a) + sqrt(b))

    if hante > 0.000000000000000000000000000000000
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

    hann = 0.000

    hante = c - (a + 2 * sqrt(a) * sqrt(b) + b)

    if hann < hante
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

hante :: Float64
hann::Float64
hann = 0.000

    hante = c -(a+2*sqrt(a)*sqrt(b)+b)

    if hante > hann
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

hante :: Float64
hann::Float64
hann = 0
    hante = c -(a+(2*(sqrt(a))*(sqrt(b)))+b)

    if hante > hann
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

    hante = c -(a+(2*(sqrt(a))*(sqrt(b)))+b)

    if hante > 0
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

    hante::Float64

    hante = c - (a + 2 * sqrt(a) * sqrt(b) + b)

    if hante > 0.00
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


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

d=gcd(A,B,C)

A=div(A,d)
B=div(B,d)
C=div(C,d)

a = sqrt(big(A))
if (Int(ceil(a))^2==A )
  (a = Int(ceil(a)))
elseif (Int(floor(a))^2==A )
  (a  =Int(floor(a)))
end
b = sqrt(big(B))
if (Int(ceil(b))^2==B )
  (b = Int(ceil(b)))
elseif (Int(floor(b))^2==B )
  (b  =Int(floor(b)))
end
c = sqrt(big(C))
if (Int(ceil(c))^2==C )
  (c = Int(ceil(c)))
elseif (Int(floor(c))^2==C )
  (c  =Int(floor(c)))
end

an = (a+b < c ) ? "Yes" : "No"
print(an)


function main()

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

    hante = sqrt(c) - (sqrt(a) +sqrt(b))

    if hante > 0.00
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

    hante = c - (a + b)

    if hante > 0
        return (print("Yes"))
    else
        return (print("No"))
    end

end

main()


function main()

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

hante = sqrt(c)-(sqrt(a)+sqrt(b))

    if hante > 0
        return(print("Yes"))
    else
        return(print("No"))
    end

end

main()


function main()

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

    if (sqrt(a)+sqrt(b)) < sqrt(c)
        return(print("Yes"))
    else
        return(print("No"))
    end

end

main()


function main()

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

    if (root(a)+root(b)) >= root(c)
        return(print("No"))
    else
        return(print("Yes"))
    end

end

main()


function main()

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

    if root(a)+root(b) < root(c)
        return(print("Yes"))
    else
        return(print("No"))
    end

end

main()


function main()

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

    x = sqrt(a) + sqrt(b)
    y = sqrt(c)

    if x < y
        return(print("Yes"))
    else
        return(print("No"))
    end

end

main()


function main()

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

    x = sqrt(a) + sqrt(b)
    y = sqrt(c)

    if x < y
        return(print("Yes"))
    elseif x > y
        return(print("No"))
    end

end

main()


function main()

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

    x = sqrt(a) + sqrt(b)
    y = sqrt(c)

    if x < y
        return(println("Yes"))
    elseif x > y
        return(println("No"))
    end

end

main()


function main()

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

    x = sqrt(a) + sqrt(b)
    y = sqrt(c)

    if x < y
        println("Yes")
    elseif x>y
        println("No")
    end

end

main()


A,B,C=map(x->parse(Int,x),split(readline()," "))
a = (sqrt(A)+sqrt(B) < sqrt(C) ) ? "Yes" : "No"
print(a)


a,b,c = parse.(split(readline()))

uhen  = c - a - b
sahen = 4 * a * b
if uhen < 0
    println("No")
else
    if sahen < uhen ^ 2
        println("Yes")
    else
        println("No")
    end
end


a,b,c = parse.(split(readline()))

sahen = a + b + 2 * sqrt(a*b)

if sahen < c
    println("Yes")
else
    println("No")
end


function f(n::Int,i::Int,ans::Int)
    a=string(i)
    return parse(Int,a[n])==ans
end
function main()
    n,m=parse.(split(readline()))
    a=[parse.(split(readline())) for i=1:m]
    for i=10^(n-1)-(n==1):10^n-1
        flag=true
        for j in a
            flag = flag==true ? f(j[1],i,j[2]) : flag
        end
        if Bool(flag)
            print(i)
            return 0
        end
    end
    print(-1)
end
main()

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


function f(n::Int,i::Int,ans::Int)
    a=string(i)
    return parse(Int,a[n])==ans
end
function main()
    n,m=parse.(split(readline()))
    a=[parse.(split(readline())) for i=1:m]
    for i=10^(n-1)-1:10^n-1
        flag=true
        for j in a
            flag = flag==true ? f(j[1],i,j[2]) : flag
        end
        if Bool(flag)
            print(i)
            return 0
        end
    end
    print(-1)
end
main()


function f(a,b)
    if a==1
        return fld(b,100)
    elseif a==2
        return fld(b,10)%10
    else
        return b%10
    end
end
function main()
    n,m=parse.(split(readline()))
    a=[parse.(split(readline())) for i=1:m]
    for i=0:10^(n+1)-1
        flag=true
        for j in a
            if f(j[1],i)!=j[2] || (n!=1&&f(4-n,i)==0)
                flag=false
            end
        end
        if Bool(flag)
            print(i)
            return 0
        end
    end
    print(-1)
end
main()


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

function main()
    N, M = parseMap(split(readline()))
    x = zeros(Int, N)
    y = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
            y[s] = 1
        end
    end
    if sum(x) == 0 && N != 1 && y[1] == 1
        println(-1)
        return
    end
    if x[1] == 0 && N != 1
        x[1] = 1
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


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

function main()
    N, M = parseMap(split(readline()))

    x = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
        end
    end
    if sum(x) == 0 && N != 1
        println(-1)
        return
    end
    if x[1] == 0 && N != 1
        x[1] = 1
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


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

function main()
    N, M = parseMap(split(readline()))

    x = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
        end
    end
    if x[1] == 0 && N != 1
        x[1] = 1
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


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

function main()
    N, M = parseMap(split(readline()))

    x = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
        end
    end
    if x[1] == 0
        x[1] = 1
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


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

function main()
    N, M = parseMap(split(readline()))

    x = zeros(Int, N)
    flg = 0
    for ii = 1:M
        s, c = parseMap(split(readline()))
        if x[s] != 0 && x[s] != c
            println(-1)
            return
        else
            x[s] = c
        end
    end
    for ii = 1:N
        print(x[ii])
    end

end

main()


function main()
x = 0.0
for i in 1:40000000
  x += 0.1
end
end
main()


function main()

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

  s = zeros(Int,M)
  c = zeros(Int,M)
  ans = ["" for i in 1:N]

  for i in 1:M
    (s,c) = split(chomp(readline())," ")
    s = parse(Int,s)
    if ans[s] == "" || ans[s] == c
      ans[s] = c
    else
      ans[1] = "-1"
      break
    end
  end

  if N == 1
    if M > 0
      println(ans[1])
    else
      println(0)
    end
  elseif ans[1] == "0" || ans[1] == "-1"
    println(-1)
  else
    for i in 1:N
      if ans[1] == "" && i == 1
        print("1")
      elseif ans[i] == "" && i != 1
        print("0")
      else
        print(ans[i])
      end
    end
    println()
  end

end

main()


function main()

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

  s = zeros(Int,M)
  c = zeros(Int,M)
  ans = ["" for i in 1:N]

  for i in 1:M
    (s,c) = split(chomp(readline())," ")
    s = parse(Int,s)
    if ans[s] == "" || ans[s] == c
      ans[s] = c
    else
      ans[1] = "0"
      break
    end
  end

  if ans[1] == "0"
    println(-1)
  else
    for i in 1:N
      if ans[1] == "" && i == 1
        print("1")
      elseif ans[i] == "" && i != 1
        print("0")
      else
        print(ans[i])
      end
    end
    println()
  end

end

main()


function main()

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

  s = zeros(Int,M)
  c = zeros(Int,M)
  ans = ["" for i in 1:N]

  for i in 1:M
    (s,c) = split(chomp(readline())," ")
    s = parse(Int,s)
    if ans[s] == "" || ans[s] == c
      ans[s] = c
    else
      ans[1] = "0"
      break
    end
  end

  if ans[1] == "0"
    println(-1)
  else
    for i in 1:N
      if ans[1] == ""
        print("1")
      elseif ans[i] == ""
        print("0")
      else
        print(ans[i])
      end
    end
    println()
  end

end

main()


N,M=map(x->parse(Int64,x),split(readline()))
s=zeros(Int,M)
c=zeros(Int,M)
for i in 1:M
    s[i],c[i]=map(x->parse(Int64,x),split(readline()))
end
res=-1
st = (N!=1) ? (10^N-1) : 0
for i in st:(10^N-1)
    snum=string(i)
    flag=true
    for j in 1:M
        if snum[s[j]]!=string(c[j])[1]
            flag=false
            break
        end
    end
    if flag
        res=i
        break
    end
end
print(res)


N,M=map(x->parse(Int64,x),split(readline()))
s=zeros(Int,M)
c=zeros(Int,M)
for i in 1:M
    s[i],c[i]=map(x->parse(Int64,x),split(readline()))
end
res=-1
for i in 10^(N-1):(10^N-1)
    snum=string(i)
    flag=true
    for j in 1:M
        if snum[s[j]]!=string(c[j])[1]
            flag=false
            break
        end
    end
    if flag
        res=i
        break
    end
end
print(res)


parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    sc=[parseMap(split(readline())) for i in 1:m]
    ans=-1
    for i in ifelse(n==1,0,10^(n-1)):10^n-1
        t=string(i)
        flg=true
        for (s,c) in sc
            if parseInt(t[s])!=c
                flg=false
            end
        end
        if flg==true
            ans=i
            break
        end
    end
    println(ans)
end
main()


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

sc = {}

def main():
    for i in range(M):
        s,c = input().split()
        s = int(s)
        if s not in sc:
            sc[s] = c
        else:
            if sc[s] != c:
                return -1
                break

    ans = ["0"] * N

    for k,n in sc.items():
        ans[k-1] = n

    result = ''.join(ans)
    if result[0] != '0' or result == '0':
        return result
    else:
        result[0] = '1'
        return int(result)

FUCK = main()
print(FUCK)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
else
    ans = ""
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)

end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
else
    i = fill("0",N)
    ans = ""
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)

end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
elseif Set(values(sc)) == Set([0]) || values(sc) == []
    i = fill("0",N)
    ans = ""
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)

end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
elseif Set(values(sc)) == Set([0])
    i = fill("0",N)
    ans = ""
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)

end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end
if Set(values(sc)) == Set([0])
    i = fill("0",N)
    ans = ""
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end
if Set(values(sc)) == Set([0])
    i = fill("0",N)
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

i = fill("0",N)
#println(i)
for (keta,num) in sc
    i[keta] = string(num)
end
#println(i)
ans = ""
if i[1] != "0" || i == ["0"]
    for j in i
        ans *= j
    end
    return parse(Int,ans)
elseif i == fill("0",N)
    i[1] = "1"
    for j in i
        ans *= j
    end
    return parse(Int,ans)
end
return -1
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

#=for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if  (ok == length(sc)) && (i[1] != '0' || i == "0")
        return parse(i)
    end
end
return -1
end=#
i = fill("0",N)
for (keta,num) in sc
    i[keta] = string(num)
end
ans = ""
    if i[1] != '0'
        for j in i
            ans *= j
        end
    end
    return parse(Int,ans)
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

#=for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if  (ok == length(sc)) && (i[1] != '0' || i == "0")
        return parse(i)
    end
end
return -1
end=#
i = fill("0",N)
for (keta,num) in sc
    i[keta] = string(num)
end
ans = ""
    if i[1] != "0" || i == ["0"]
        for j in i
            ans *= j
        end
    end
    return parse(Int,ans)
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

#=for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if  (ok == length(sc)) && (i[1] != '0' || i == "0")
        return parse(i)
    end
end
return -1
end=#
i = fill("0",N)
for (keta,num) in sc
    i[keta] = string(num)
end
ans = ""
    if i[1] != "0" || i == "0"
        for j in i
            ans *= j
        end
    end
    return parse(Int,ans)
end
ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    s = parse(s)
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

#=for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if  (ok == length(sc)) && (i[1] != '0' || i == "0")
        return parse(i)
    end
end
return -1
end=#
i = fill("0",N)
for (keta,num) in sc
    i[keta] = string(num)
end
ans = ""
    if i[1] != '0' || i == "0"
        for j in i
            ans *= j
        end
    end
    return parse(Int,ans)
end
ans = main()
println(ans)


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

function main()
	n,m = readline() |> split |> parseMap
	a = -ones(Int,n)
	f = 0
	if m==0&&n==1
		println(0)
	else
	for i in 1:m
		s,c = readline() |> split |> parseMap
		if a[s]==-1
			a[s] = c
		elseif a[s]!=c
			f = 1
		end
	end
	if f == 1 || (n>1&&a[1]==0)
		println(-1)
	else
		if a[1]==-1
			print(1)
		else
			print(a[1])
		end
		for i in 2:n
			if a[i]==-1
				print(0)
			else
				print(a[i])
			end
		end
		println("")
	end
end
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if  (ok == length(sc)) && (i[1] != '0' || i == "0" || i == "00" || i =="000")
        return parse(i)
    end
end
return -1
end

ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 1:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if ok == length(sc)
        return parse(i)
    end
end
return -1
end

ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 0:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if ok == length(sc) && i[1] != '0'
        return parse(i)
    end
end
return -1
end

ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            return -1
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 1:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if ok == length(sc) && i[1] != '0'
        return parse(i)
    end
end
return -1
end

ans = main()
println(ans)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
N,M = parseMap(split(readline()))
sc = Dict()
for i in 1:M
    s,c = split(readline())
    if !(s in keys(sc))
        push!(sc,s=>c)
    else
        if sc[s] != c
            println(-1)
            break
        end
    end
end

#println(sc)
#println("=====")
if N == 1
    n = 9
elseif N == 2
    n = 99
elseif N == 3
    n = 999
end

for i in 1:n
    i = string(i)
    i = "0" ^(N - length(i)) * i
    #println(i)
    ok = 0
    for (keta,num) in sc
        #println(i[1])
        #println("$keta -> $num")
        if string(i[parse(keta)]) == num
            ok +=1
        end
    end

    if ok == length(sc)
        return parse(i)
    end
end
return -1
end

ans = main()
println(ans)


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

function main()
	n,m = readline() |> split |> parseMap
	a = -ones(Int,n)
	f = 0
	for i in 1:m
		s,c = readline() |> split |> parseMap
		if a[s]==-1
			a[s] = c
		elseif a[s]!=c
			f = 1
		end
	end
	if f == 1 || (n>1&&a[1]==0)
		println(-1)
	else
		if a[1]==-1
			print(1)
		else
			print(a[1])
		end
		for i in 2:n
			if a[i]==-1
				print(0)
			else
				print(a[i])
			end
		end
		println("")
	end
end

main()


readInt() = parse.(Int,split(readline()))
comb2(x) = div((x-1)x,2)

function f(x,neg,pos)
    ret = 0
    n=length(neg); p=length(pos)
    j=1
    for i in 1:n
        while j<=p && neg[i]*pos[j]>x
            j+=1
        end

        ret+=p-j+1
    end
    return ret
end

g(x,neg,pos) = h(x,neg)+h(x,pos)

function h(x,a)
    ret = 0
    sz=length(a)
    j=sz
    for i in 1:sz
        while j>i && a[i]*a[j]>x
            j-=1
        end
        j<=i && break
        ret+=j-i
    end
    return ret
end

function answer(K,neg,pos,fc)
    lo=-10^18; hi=10^18
    while hi-lo>1
        c = div(lo+hi,2)
        K <= fc(c,neg,pos) ? (hi=c) : (lo=c)
    end
    println(hi)
end

function solve()
    N,K = readInt()
    A = readInt()
    sort!(A)
    zero=0
    neg=Int[]; pos=Int[]
    for i in 1:N
        if A[i]==0
            zero+=1
            continue
        end
        push!((A[i]<0 ? neg : pos), A[i])
    end
    n=length(neg); p=length(pos)
    α = n*p
    γ = comb2(n)+comb2(p)
    β = comb2(N)-α-γ
    if K<=α
        answer(K,neg,pos,f)
    elseif K<=α+β
        println(0)
    else
        reverse!(neg); neg*=-1
        answer(K-α-β,neg,pos,g)
    end
end
solve()

Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

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

1 \leq K \leq \frac{N(N-1)}{2}

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064


#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_d, alphabet: D

function cnt(x, P, M)
  ans = 0
  ei = length(M)
  for p in reverse(P)
    n = searchsortedlast(@view(M[1:ei]) .* p, x)
    n == 0 && break
    ans += n
    ei = n
  end
  x < 0 && return ans

  ei = length(P)
  for (pi, p) in enumerate(P)
    n = searchsortedlast(@view(P[pi+1:ei]) .* p, x)
    n == 0 && break
    ans += n
    ei = (pi+1:ei)[n]
  end

  revM = reverse(M)
  ei = length(revM)
  for (mi, m) in enumerate(revM)
    n = searchsortedlast(@view(revM[mi+1:ei]) .* m, x)
    n == 0 && break
    ans += n
    ei = (mi+1:ei)[n]
  end
  ans
end

function solve(N::Int, K::Int, A::Vector{Int})
  P = [x for x in A if x >= 0]
  M = [x for x in A if x < 0]
  sort!(P)
  sort!(M)

  bottom = -10^18 - 100
  top = 10^18 + 100
  while bottom < top
    mid = div(top + bottom, 2)
    cmid = cnt(mid, P, M)
    if bottom == top - 1
      println(top)
      return
    elseif cmid < K
      bottom = mid
    else
      top = mid
    end
  end
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  N = parse(Int, take!(tokens))
  K = parse(Int, take!(tokens))
  A = similar(Vector{Int}, N)
  for i in 1:N
    A[i] = parse(Int, take!(tokens))
  end
  solve(N, K, A)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("4 3\n3 3 -4 -2", "-6"), ("10 40\n5 4 3 2 -1 0 0 0 0 0", "6"), ("30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0", "448283280358331064")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_d, alphabet: D

function cnt(x, P, M)
  ans = 0
  for p in reverse(P)
    ans += searchsortedlast(M .* p, x)
  end
  x < 0 && return ans

  for (pi, p) in enumerate(P)
    ans += searchsortedlast(@view(P[pi+1:end]) .* p, x)
  end
  revM = reverse(M)
  for (mi, m) in enumerate(revM)
    ans += searchsortedlast(@view(revM[mi+1:end]) .* m, x)
  end
  ans
end

function solve(N::Int, K::Int, A::Vector{Int})
  P = [x for x in A if x >= 0]
  M = [x for x in A if x < 0]
  sort!(P)
  sort!(M)

  bottom = -10^18 - 100
  top = 10^18 + 100
  while bottom < top
    mid = div(top + bottom, 2)
    cmid = cnt(mid, P, M)
    if bottom == top - 1
      println(top)
      return
    elseif cmid < K
      bottom = mid
    else
      top = mid
    end
  end
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  N = parse(Int, take!(tokens))
  K = parse(Int, take!(tokens))
  A = similar(Vector{Int}, N)
  for i in 1:N
    A[i] = parse(Int, take!(tokens))
  end
  solve(N, K, A)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("4 3\n3 3 -4 -2", "-6"), ("10 40\n5 4 3 2 -1 0 0 0 0 0", "6"), ("30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0", "448283280358331064")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_d, alphabet: D

function cnt(x, P, M)
  ans = 0
  for p in reverse(P)
    ans += searchsortedlast(M .* p, x)
  end
  x < 0 && return ans

  for (pi, p) in enumerate(P)
    ans += searchsortedlast(P[pi+1:end] .* p, x)
  end
  revM = reverse(M)
  for (mi, m) in enumerate(revM)
    ans += searchsortedlast(revM[mi+1:end] .* m, x)
  end
  ans
end

function solve(N::Int, K::Int, A::Vector{Int})
  P = [x for x in A if x >= 0]
  M = [x for x in A if x < 0]
  sort!(P)
  sort!(M)

  bottom = -10^18 - 100
  top = 10^18 + 100
  while bottom < top
    mid = div(top + bottom, 2)
    cmid = cnt(mid, P, M)
    if bottom == top - 1
      println(top)
      return
    elseif cmid < K
      bottom = mid
    else
      top = mid
    end
  end
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  N = parse(Int, take!(tokens))
  K = parse(Int, take!(tokens))
  A = similar(Vector{Int}, N)
  for i in 1:N
    A[i] = parse(Int, take!(tokens))
  end
  solve(N, K, A)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("4 3\n3 3 -4 -2", "-6"), ("10 40\n5 4 3 2 -1 0 0 0 0 0", "6"), ("30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0", "448283280358331064")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;l;end
cldd(x,y)=y==0?10^18:fld(x,y)+1

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap |> sort
	nc = bsearch(a,0)
	b = Int[]
	for i in 1:nc
		push!(b,a[i])
	end
	c = Int[]
	for i in nc+1:n
		push!(c,a[i])
	end
	if nc*(n-nc)>=k
		l = b[1]*c[n-nc]-1
		r = 1
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				s += n-nc-bsearch(c,cld(-m,-b[i]))
			end
			if s>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	else
		l = -1
		r = max(a[n]*a[n-1],a[1]*a[2])+1
		b = sort(Int[-b[i] for i in 1:nc])
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				t = bsearch(b,cldd(m,b[i]))
				s += min(t,i-1)
			end
			for i in 1:n-nc
				t = bsearch(c,cldd(m,c[i]))
				s += min(t,i-1)
			end
			if s+nc*(n-nc)>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	end
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;l;end
cldd(x,y)=y==0?10^18:fld(x,y)+1

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap |> sort
	nc = bsearch(a,0)
	b = Int[]
	for i in 1:nc
		push!(b,a[i])
	end
	c = Int[]
	for i in nc+1:n
		push!(c,a[i])
	end
	if nc*(n-nc)>=k
		l = b[1]*c[n-nc]
		r = b[nc]*c[1]
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				s += bsearch(c,cldd(m,b[i]))
			end
			if s>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	else
		l = -1
		r = max(a[n]*a[n-1],a[1]*a[2])
		b = sort(Int[-b[i] for i in 1:nc])
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				t = bsearch(b,cldd(m,b[i]))
				s += min(t,i-1)
			end
			for i in 1:n-nc
				t = bsearch(c,cldd(m,c[i]))
				s += min(t,i-1)
			end
			if s+nc*(n-nc)>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	end
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;l;end
cldd(x,y)=y==0?10^18:fld(x,y)+1

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap |> sort
	nc = bsearch(a,0)
	b = 1<=nc<=n?a[1:nc]:[]
	c = 0<=nc<n?a[nc+1:n]:[]
	if nc*(n-nc)>=k
		l = b[1]*c[n-nc]
		r = b[nc]*c[1]
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				s += bsearch(c,cldd(m,b[i]))
			end
			if s>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	else
		l = -1
		r = max(a[n]*a[n-1],a[1]*a[2])
		b = sort([-b[i] for i in 1:nc])
		while r-l>1
			m = (l+r)>>1
			s = 0
			for i in 1:nc
				t = bsearch(b,cldd(m,b[i]))
				s += min(t,i-1)
			end
			for i in 1:n-nc
				t = bsearch(c,cldd(m,c[i]))
				s += min(t,i-1)
			end
			if s+nc*(n-nc)>=k
				r = m
			else
				l = m
			end
		end
		println(r)
	end
end

main()


Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

1 \leq A \leq 20

1 \leq B \leq 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.

Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.

Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

Sample Input 3

9 9

Sample Output 3

81


a,b=map(x->parse(Int,x),split(readline()))
println(a>9||b>9 ? -1 : a*b)


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

function main()
  a,b = readline() |> split |> parseArray

  ans=a<10&&b<10
  println(ans ? a*b : -1)
end

main()


A,B = parse.(split(readline()))
if A<10 && B<10
  println(A*B)
else
  println("-1")
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()
    s=chomp(readline())
    n=length(s)
    k=parseInt(readline())
    res=1
    cnt=[]
    for i in 2:n+1
        if i==n+1 || s[i]!=s[i-1]
            push!(cnt,res)
            res=1
        else
            res+=1
        end
    end
    ans=sum(map(x->x÷2,cnt))*k
    if s[1]==s[end]
        if length(cnt)==1
            ans=sum(map(x->x,cnt))*k÷2
        else
            ans=sum(map(x->x÷2,cnt))*k
            ans-=(cnt[1]÷2+cnt[end]÷2-(cnt[1]+cnt[end])÷2)*(k-1)
        end
    end
    println(ans)
end
main()

Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997


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())
    n=length(s)
    k=parseInt(readline())
    cnt1=BigInt(0)
    for i in 2:n
        if s[i-1]==s[i]
            cnt1+=1
            s=s[1:i-1]*"?"*s[i+1:end]
        end
    end
    ans=cnt1*k
    if k>=2 && s[1]==s[end]
        ans+=k-1
    end
    println(ans)
end
main()


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

function main()
	s = readline() |> chomp
	k = readline() |> parseInt
	l = length(s)
	fx = 0
	for i in 2:l
		if s[i]!=s[i-1]
			fx = 1
		end
	end
	if l==1
		println(k>>1)
	elseif fx == 0
		println((l*k)>>1)
	else
	h = 0
	b = 0
	x = 0
	f = 0
	tmp = 1
	for i in 2:l
		if s[i]!=s[i-1]
			if f==0
				f = 1
				h = i-1
			else
				x += tmp>>1
			end
			tmp = 1
		else
			tmp += 1
		end
	end
	b = tmp
	if s[1]!=s[l]
		x += h>>1
		x += b>>1
		println(x*k)
	else
		x=x*k
		x += ((h+b)>>1)*(k-1)
		x += h>>1
		x += b>>1
		println(x)
	end
end
end
main()


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

function main()
	s = readline() |> chomp
	k = readline() |> parseInt
	l = length(s)
	h = 0
	b = 0
	x = 0
	f = 0
	tmp = 1
	for i in 2:l
		if s[i]!=s[i-1]
			if f==0
				f = 1
				h = i-1
			else
				x += tmp>>1
			end
			tmp = 1
		else
			tmp += 1
		end
	end
	b = tmp
	if s[1]!=s[l]
		x += h>>1
		x += b>>1
		println(x*k)
	else
		x=x*k
		x += ((h+b)>>1)*(k-1)
		x += h>>1
		x += b>>1
		println(x)
	end

end
main()


S=chomp(readline())
K=parse(Int,readline())
A=Int[1]
for i=2:length(S)
	if S[i-1]==S[i]
		A[end]+=1
	else
		push!(A,1)
	end
end
if length(A)==1
	println(div(A[1]*K,2))
else
	ans=div(A[1],2)+div(A[end],2)
	T=0
	for i=2:length(A)-1
		T+=div(A[i],2)
	end
	ans+=T*K
	if S[1]==S[end]
		ans+=(K-1)*div(A[1]+A[end],2)
	else
		ans+=(K-1)*(div(A[1],2)+div(A[end],2))
	end
	println(ans)
end


S=chomp(readline())
K=parse(Int,readline())
A=Int[1]
for i=2:length(S)
	if S[i-1]==S[i]
		A[end]+=1
	else
		push!(A,1)
	end
end
if length(A)==1
	println(div(N*K,2))
else
	ans=div(A[1],2)+div(A[end],2)
	T=0
	for i=2:length(A)-1
		T+=div(A[i],2)
	end
	ans+=T*K
	if S[1]==S[end]
		ans+=(K-1)*div(A[1]+A[end],2)
	else
		ans+=(K-1)*(div(A[1],2)+div(A[end],2))
	end
	println(ans)
end


c = strip(readline())
l = parse(Int, strip(readline()))
if c[1] != c[end]
  c = c * "#"
  dl = 1
  res = 0
  for i in 2:length(c)
    if c[i] != c[i-1]
      res += div(dl, 2) * l
      dl = 1
    else
      dl += 1
    end
  end
  println(res)
elseif length(Set(collect(c))) == 1
  println(div(len(c) * l, 2))
else
  dlus = Int64[]
  c = c * "#"
  dl = 1
  res = 0
  for i in 2:length(c)
    if c[i] != c[i-1]
      push!(dlus, dl)
      dl = 1
    else
      dl += 1
    end
  end
  for i in dlus[2:end-1]
    res += div(i, 2) * l
  end
  res += div(dlus[1], 2)
  res += div(dlus[end], 2)
  res += div(dlus[1] + dlus[end], 2) * (l-1)
  println(res)
end