parseInt(x) = parse(Int, x)
n,k = parseInt.(split(readline()))
println(length(string(n, base = k)))

Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

Print the count modulo (10^9 + 7).


const lines=readlines()
const k,q=map(x->parse(Int,x),split(shift!(lines)))
const d=map(x->parse(Int,x),split(shift!(lines)))
for s=lines
  const n,x,m=map(x->parse(Int,x),split(s))
  s=Int[0]
  pre=0
  for i=1:k
    pre+=mod1(d[i],m)
    push!(s,pre)
  end
  println(n-1-div(x%m+div(n-1,k)*pre+s[mod1(n,k)],m))
end

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

Score : 600 points

Problem Statement

We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}.

Process the following q queries in order:

The i-th query contains three integers n_i, x_i, and m_i.
Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray}
Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i).

Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).

Constraints

All values in input are integers.

1 \leq k, q \leq 5000

0 \leq d_i \leq 10^9

2 \leq n_i \leq 10^9

0 \leq x_i \leq 10^9

2 \leq m_i \leq 10^9

Input

Input is given from Standard Input in the following format:

k q
d_0 d_1 ... d_{k - 1}
n_1 x_1 m_1
n_2 x_2 m_2
:
n_q x_q m_q

Output

Print q lines.

The i-th line should contain the response to the i-th query.

Sample Input 1

3 1
3 1 4
5 3 2

Sample Output 1

1

For the first query, the sequence {a_j} will be 3,6,7,11,14.

(a_0~\textrm{mod}~2) > (a_1~\textrm{mod}~2)

(a_1~\textrm{mod}~2) < (a_2~\textrm{mod}~2)

(a_2~\textrm{mod}~2) = (a_3~\textrm{mod}~2)

(a_3~\textrm{mod}~2) > (a_4~\textrm{mod}~2)

Thus, the response to this query should be 1.

Sample Input 2

7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12

Sample Output 2

224489796
214285714
559523809

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.


#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_a, alphabet: A
const YES = "Yes"
macro Y() :( println(YES); return ) end
const NO = "No"
macro N() :( println(NO); return ) end

function solve(A::Int, B::Int, C::Int)
  length(unique([A, B, C]))==2 && @Y
  @N
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
  A = parse(Int, take!(tokens))
  B = parse(Int, take!(tokens))
  C = parse(Int, take!(tokens))
  solve(A, B, C)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("5 7 5", "Yes"), ("4 4 4", "No"), ("4 9 6", "No"), ("3 3 4", "Yes")]
    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

Score: 100 points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

Constraints

A, B, and C are all integers between 1 and 9 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

A and C are equal, but B is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

A, B, and C are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


A,B,C=split(readline()," ")
if (A==B && A!=C) || (A==C && B!=C) || (B==C && A!=C)
  print("Yes")
else
  print("No")
end


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    s=[chomp(readline()) for _ in 1:n]
    cnt=Dict{String,Int}()
    for i in s
        if haskey(cnt,i)
            cnt[i]+=1
        else
            cnt[i]=1
        end
    end
    M=maximum(values(cnt))
    st=sort(collect(Set(s)))
    for i in st
        if cnt[i]==M
            println(i)
        end
    end
end
main()

Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

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

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


S, T = split(readline())
A, B = parse.(Int, split(readline()))
U = readline()
D = Dict(S => A, T => B)
D[U] -= 1
print(D[S], " ", D[T])

Score : 100 points

Problem Statement

We have A balls with the string S written on each of them and B balls with the string T written on each of them.

From these balls, Takahashi chooses one with the string U written on it and throws it away.

Find the number of balls with the string S and balls with the string T that we have now.

Constraints

S, T, and U are strings consisting of lowercase English letters.

The lengths of S and T are each between 1 and 10 (inclusive).

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

Takahashi chose a ball with red written on it and threw it away.
Now we have two balls with the string S and four balls with the string T.

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

Takahashi chose a ball with blue written on it and threw it away.
Now we have five balls with the string S and four balls with the string T.


for i=1:length(chomp(readline()))
  print("x")
end
println()

Score : 200 points

Problem Statement

Given is a string S. Replace every character in S with x and print the result.

Constraints

S is a string consisting of lowercase English letters.

The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

Replace every character in S with x and print the result.

Sample Input 1

sardine

Sample Output 1

xxxxxxx

Replacing every character in S with x results in xxxxxxx.

Sample Input 2

xxxx

Sample Output 2

xxxx

Sample Input 3

gone

Sample Output 3

xxxx


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

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap |> sort
	f = 0
	for i in 2:n
		if a[i]==a[i-1]
			f = 1
		end
	end
	println(f==0?"YES":"NO")
end

main()

Score : 300 points

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N, K = parseMap(split(readline()))
P = parseMap(split(readline()))
function get_k(num)
    return (num+1)/2
end
P = get_k.(P)
ans = 0
for i in 1:N-K+1
    kari_ans = sum(P[i:i+K-1])
    if kari_ans > ans
        ans = kari_ans
    end
end
println(ans)

#=if N > 7
left = P[1]
mid = P[2]
rigth = P[3]
ans = left + mid + rigth
for i in 4:N - 2
    println(i)
    left = mid
    mid = rigth
    rigth = P[i]
    kari_ans = left + mid + rigth
    if kari_ans > ans
        ans = kari_ans
    end
end
else
    ans = 0
    for i in 1:N - 2
        kari_ans = P[i] + P[i+1] + P[i+2]
        if kari_ans > ans
            ans = kari_ans
        end
    end
end=#

Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000


parseInt(x) = parse(Int, x)
h, n = parseInt.(split(readline()))
A = parseInt.(split(readline()))
if sum(A) >= h
    println("Yes")
else
    println("No")
end

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.

Raccoon wins when the monster's health becomes 0 or below.

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

The monster's health will become 0 or below after, for example, using the second and third moves.

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


function main()

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

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

  sum = 0

  for i in 1:N
    sum += A[i]
  end

  if sum >= H
    println("Yes")
  else
    println("No")
  end

end

main()


function main()
	N,D,A=map(x->parse(Int,x),split(readline()))
	H=Pair{Int,Int}[]
	for i=1:N
		x,h=map(x->parse(Int,x),split(readline()))
		push!(H,x=>h)
	end
	sort!(H)
	P=Pair{Int,Int}[]
	cnt=ans=0
	for (x,h)=H
		while !isempty(P)&&P[1].first<x
			cnt-=P[1].second
			shift!(P)
		end
		h-=cnt*A
		if h>0
			t=div(h+A-1,A)
			ans+=t
			cnt+=t
			push!(P,x+D*2=>t)
		end
	end
	println(ans)
end
main()

Score : 600 points

Problem Statement

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A.
There is no way other than bombs to decrease the monster's health.

Silver Fox wins when all the monsters' healths become 0 or below.

Find the minimum number of bombs needed to win.

Constraints

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

0 \leq D \leq 10^9

1 \leq A \leq 10^9

0 \leq X_i \leq 10^9

1 \leq H_i \leq 10^9

X_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D A
X_1 H_1
:
X_N H_N

Output

Print the minimum number of bombs needed to win.

Sample Input 1

3 3 2
1 2
5 4
9 2

Sample Output 1

2

First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.

Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.

Now, all the monsters' healths are 0.
We cannot make all the monsters' health drop to 0 or below with just one bomb.

Sample Input 2

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

Sample Output 2

5

We should use five bombs at the coordinate 5.

Sample Input 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


#=
E:
- Julia version:0.5.2
- Author: abap
- Date: 2020-01-12
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N = parseInt(readline())
A = parseMap(split(readline()))
x = lcm(A)
ans = 0
for i in A
	ans += x ÷ i
end
anser = ans % (10^9 + 7)
println(Int64(anser))

Score : 100 points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has N test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed M cases out of the N test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


n,m=map(x->parse(Int,x),split(readline()))
println(n==m ? "Yes" : "No")


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    p=parseMap(split(readline()))
    MINs=[p[1] for i in 1:n]
    for i in 2:n
        MINs[i]=min(MINs[i-1],p[i])
    end
    ans=0
    for i in 1:n
        if p[i]<=MINs[i]
            ans+=1
        end
    end
    println(ans)
end
main()

Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

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

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


#=
B:
- Julia version:0.5.2
- Author: abap
- Date: 2020-01-12
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N = parseInt(readline())
P = parseMap(split(readline()))
#P = []
#=for i in 1:N
	push!(P,(i,p[i]))
end
sort!(P,by=x->x[2])
count = 0
for (key,value) in P
		println(key," ",value)
		count += 1
end=#

#println(count)
not = 0
min = P[1]
for i in 1:N
	p = P[i]
	if p > min
		not += 1
	else
		min = p
	end
end
println(N - not)


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())
    arr=[[[] for i in 1:9] for j in 0:9]
    for i in 1:n
        if i%10==0
            continue
        end
        s=string(i)
        push!(arr[s[1]-'0'][s[end]-'0'],i)
    end
    ans=0
    for i in 1:n
        if i%10==0
            continue
        end
        s=string(i)
        ans+=length(arr[s[end]-'0'][s[1]-'0'])
    end
    println(ans)
end
main()

Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008


N = parse(Int, readline())
arr = string.(collect(1:N))
total = 0
dict = Dict((string(a)[1], string(b)[1]) => 0 for a in 0:9 for b in 0:9)
for i in arr
    a = i[1]
    b = i[end]
    global dict[(a, b)] += 1
end
count = 0
for i in arr
    a = i[end]
    b = i[1]
    global count += dict[(a, b)]
end
println(count)


#=
A:
- Julia version:
- Author: abap
- Date: 2020-01-18
=#
H = parse(readline())
W = parse(readline())
N = parse(readline())
white = H * W
black  = 0
h = 0
w = 0
count = 0
for i in 1:100000
	count += 1
	if W - h > H - w
		w += 1
		black += W - h
	else
		h += 1
		black += H - w
	end
	if black >= N
		println(count)
		break
	end
end

Score : 100 points

Problem Statement

We have a grid with H rows and W columns, where all the squares are initially white.

You will perform some number of painting operations on the grid.
In one operation, you can do one of the following two actions:

Choose one row, then paint all the squares in that row black.

Choose one column, then paint all the squares in that column black.

At least how many operations do you need in order to have N or more black squares in the grid?
It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Constraints

1 \leq H \leq 100

1 \leq W \leq 100

1 \leq N \leq H \times W

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H
W
N

Output

Print the minimum number of operations needed.

Sample Input 1

3
7
10

Sample Output 1

2

You can have 14 black squares in the grid by performing the "row" operation twice, on different rows.

Sample Input 2

14
12
112

Sample Output 2

8

Sample Input 3

2
100
200

Sample Output 3

2


function main()
	N=parse(Int,readline())
	X=Pair{Int,Int}[]
	for i=1:N
		x,l=map(x->parse(Int,x),split(readline()))
		push!(X,x+l=>x-l)
	end
	sort!(X)
	p=-10^9
	ans=0
	for (l,r)=X
		if p<=r
			ans+=1
			p=l
		end
	end
	println(ans)
end
main()

Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

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

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

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5


function main()

  N = parse(Int,readline())
  R = [(0,0) for i in 1:N]

  for i in 1:N

    (a,b) = map(x -> parse(Int,x), split(readline()))
    R[i] = (a-b,a+b)

  end

  sort!(R, by = R -> R[1])

  check = R[1]
  count = 0

  for i in 2:N

    if check[2] <= R[i][1]
      count += 1
      check = R[i]
    end

  end

  println(count+1)

end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N, M = parseMap(split(readline()))
d = Dict()
ac,wa = 0, 0
for i in 1:M
  p,S = split(readline())
  p = parseInt(p)
  if !(p in keys(d))
    push!(d, p=>"WJ") #デバッグしやすいので...
  end
  if d[p] == "WJ" || d[p] == "WA"
    	if S == "AC"
            d[p] = "FIN"
      		ac += 1
    	else
        	wa += 1
    	end
  end
end
println("$ac $wa")

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


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

function main()
	n,m = readline() |> split |> parseMap
	a = Tuple{Int,Int}[(0,0) for i in 1:n]
	ac = zeros(Int,n)
	wa = 0
	for i in 1:m
		p,x = readline() |> chomp |> split
		p = parseInt(p)
		if x=="AC"
			ac[p]=1
		elseif ac[p]==0
			wa += 1
		end
	end
	println(sum(ac)," ",wa)
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)

h,w=parseMap(split(readline()))
s=[chomp(readline()) for i in 1:h]
function dfs(x,y,dis)
    if !(0<x<w+1 && 0<y<h+1 && s[y][x]!='#')
        return 0
    end
    for (i,j) in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
        if 0<i<w+1 && 0<j<h+1 && s[j][i]!='#' && dis[y,x]+1<dis[j,i]
            dis[j,i]=dis[y,x]+1
            dfs(i,j,dis)
        end
    end
    return dis
end
function main()
    ans=0
    for i in 1:h
        for j in 1:w
            dis=fill(10^9,(h,w))
            dis[i,j]=0
            dfs(j,i,dis)
            res=0
            for k in 1:h,l in 1:w
                if dis[k,l]<10^9
                    res=max(res,dis[k,l])
                end
            end
            ans=max(ans,res)
        end
    end
    println(ans)
end
main()

Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

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

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.


f()=(x->parse(Int,x)).(split(readline()))
N,K=f()
A=sort(f())
S=0
C=1
M=10^9+7
for k=K:N
	S+=C*(A[k]-A[N+1-k])%M
	C=C*k%M*invmod(k-K+1,M)%M
end
show(S%M)

Score : 500 points

Problem Statement

For a finite set of integers X, let f(X)=\max X - \min X.

Given are N integers A_1,...,A_N.

We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways.

Since the answer can be enormous, print it \bmod (10^9+7).

Constraints

1 \leq N \leq 10^5

1 \leq K \leq N

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 ... A_N

Output

Print the answer \bmod (10^9+7).

Sample Input 1

4 2
1 1 3 4

Sample Output 1

11

There are six ways to choose S: \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1s). The value of f(S) for these choices are 0,2,3,2,3,1, respectively, for the total of 11.

Sample Input 2

6 3
10 10 10 -10 -10 -10

Sample Output 2

360

There are 20 ways to choose S. In 18 of them, f(S)=20, and in 2 of them, f(S)=0.

Sample Input 3

3 1
1 1 1

Sample Output 3

0

Sample Input 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

Sample Output 4

999998537

Print the sum \bmod (10^9+7).


Score : 600 points

Problem Statement

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

2 \leq N \leq 50

0 \leq x_i \leq 1000

0 \leq y_i \leq 1000

The given N points are all different.

The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum radius of a circle such that all the N points are inside or on it.

Your output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

Both points are contained in the circle centered at (0.5,0) with a radius of 0.5.

Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Sample Output 3

6.726812023536805158

If the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.


function main()
	N=parse(Int,readline())
	X=Pair{String,Int}[]
	for _=1:N
		s,t=split(readline())
		push!(X,String(s)=>parse(Int,t))
	end
	reverse!(X)
	x=chomp(readline())
	sum=0
	for (s,t)=X
		if s==x
			break
		end
		sum+=t
	end
	println(sum)
end
main()

Score : 200 points

Problem Statement

Niwango created a playlist of N songs.
The title and the duration of the i-th song are s_i and t_i seconds, respectively.
It is guaranteed that s_1,\ldots,s_N are all distinct.

Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)
However, he fell asleep during his work, and he woke up after all the songs were played.
According to his record, it turned out that he fell asleep at the very end of the song titled X.

Find the duration of time when some song was played while Niwango was asleep.

Constraints

1 \leq N \leq 50

s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.

s_1,\ldots,s_N are distinct.

There exists an integer i such that s_i = X.

1 \leq t_i \leq 1000

t_i is an integer.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
\vdots
s_{N} t_N
X

Output

Print the answer.

Sample Input 1

3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1

30

While Niwango was asleep, two songs were played: sixth and prelims.

The answer is the total duration of these songs, 30.

Sample Input 2

1
abcde 1000
abcde

Sample Output 2

0

No songs were played while Niwango was asleep.

In such a case, the total duration of songs is 0.

Sample Input 3

15
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu

Sample Output 3

6348


n=parse(Int,readline())
s=chomp(readline())
print(count(x->x=="ABC",[s[i:i+2] for i in 1:n-2]))

Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function permutation(a,n)
	ans = Array{Int,1}[copy(a)]
	c = ones(Int,n)
	i = 1
	while i<=n
		if c[i]<i
			if i%2==1
				tmp = a[1]
				a[1] = a[i]
				a[i] = tmp
			else
				tmp = a[c[i]]
				a[c[i]] = a[i]
				a[i] = tmp
			end
			c[i] += 1
			i = 1
			push!(ans,copy(a))
		else
			c[i] = 1
			i += 1
		end
	end
	ans
end

function calc(a::Array{Int,1})
	l = length(a)
	x = 0
	for i in 1:l
		x += a[i]*10^(l-i)
	end
	x
end

function main()
	n = readline() |> parseInt
	p = readline() |> split |> parseMap
	q = readline() |> split |> parseMap
	perm = permutation([i for i in 1:n],n)
	pb = [calc(perm[i]) for i in 1:length(perm)]
	pb = sort(pb)
	px = calc(p)
	qx = calc(q)
	a = 0
	b = 0
	for i in 1:length(perm)
		if pb[i]==px
			a = i
		end
		if pb[i]==qx
			b = i
		end
	end
	println(abs(a-b))
end

main()

Score : 300 points

Problem Statement

We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).

There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Notes

For two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \leq i < k) and X_k < Y_k.

Constraints

2 \leq N \leq 8

P and Q are permutations of size N.

Input

Input is given from Standard Input in the following format:

N
P_1 P_2 ... P_N
Q_1 Q_2 ... Q_N

Output

Print |a - b|.

Sample Input 1

3
1 3 2
3 1 2

Sample Output 1

3

There are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.

Sample Input 2

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

Sample Output 2

17517

Sample Input 3

3
1 2 3
1 2 3

Sample Output 3

0


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
	x = 0
	tmp = a[1]
	while tmp%2==0
		x+=1
		tmp>>=1
	end
	f = 0
	for i in 2:n
		y = 0
		tmp = a[i]
		while tmp%2==0
			y+=1
			tmp>>=1
		end
		if y!=x
			f = 1
			break
		end
	end
	b = Int[a[i]>>1 for i in 1:n]
	k = lcm(b)
	println(f==1?0:max(div(m+k,2*k),0))
end

main()

Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6 \times 2.5

15 = 10 \times 1.5

45 = 6 \times 7.5

45 = 10 \times 4.5

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667


function main()
	N,M=map(x->parse(Int,x),split(readline()))
	g=0
	c=-1
	for a=map(x->parse(Int,x),split(readline()))
		a>>=1
		g=lcm(g,a)
		t=0
		while a%2==0
			a>>=1
			t+=1
		end
		if c<0
			c=t
		elseif c!=t
			println(0)
			exit()
		end
	end
	if g>M
		println(0)
	else
		t=div(M,g)
		println(div(t+1,2))
	end
end
main()


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

function main()
	p = 10^9+7
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	c = zeros(Int,n)
	d = zeros(Int,n)
	for i in 1:n-1
		c[i]=a[i]$a[i+1]
		d[i]=b[i]$b[i+1]
	end
	c[n]=a[1]$a[n]
	d[n]=b[1]$b[n]
	z = 103
	za = zeros(Int,n+1)
	za[1]=1
	for i in 2:n+1
		za[i]=za[i-1]*z%p
	end
	rhc=c[1]*za[n]%p
	rhd=d[1]*za[n]%p
	for i in 2:n
		rhc=(rhc+(c[i]*za[n-i+1])%p)%p
		rhd=(rhd+(d[i]*za[n-i+1])%p)%p
	end
	hash = rhc
	if hash==rhd
		f = 0
		for i in 1:n
			if c[i]!=d[i]
				f = 1
				break
			end
		end
		if f == 0
			println("0"," ",a[1]$b[1])
		end
	end
	for i in 1:n-1
		hash = (mod(hash-za[n]*c[i],p)*z%p+c[i])%p
		if hash==rhd
			f = 0
			for j in 0:n-1
				if c[(i+j)%n+1]!=d[j+1]
					f = 1
					break
				end
			end
			if f == 0
				println(i," ",a[i%n+1]$b[1])
			end
		end
	end
end

main()

Score : 600 points

Problem Statement

Given are two sequences a=\{a_0,\ldots,a_{N-1}\} and b=\{b_0,\ldots,b_{N-1}\} of N non-negative integers each.

Snuke will choose an integer k such that 0 \leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\{a_0',\ldots,a_{N-1}'\}, as follows:

a_i'= a_{i+k \mod N}\ XOR \ x

Find all pairs (k,x) such that a' will be equal to b.

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

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

0 \leq a_i,b_i < 2^{30}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1}

Output

Print all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).

If there are no such pairs, the output should be empty.

Sample Input 1

3
0 2 1
1 2 3

Sample Output 1

1 3

If (k,x)=(1,3),

a_0'=(a_1\ XOR \ 3)=1

a_1'=(a_2\ XOR \ 3)=2

a_2'=(a_0\ XOR \ 3)=3

and we have a' = b.

Sample Input 2

5
0 0 0 0 0
2 2 2 2 2

Sample Output 2

0 2
1 2
2 2
3 2
4 2

Sample Input 3

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

Sample Output 3

2 2
5 5

Sample Input 4

2
1 2
0 0

Sample Output 4

No pairs may satisfy the condition.


Score : 100 points

Problem Statement

Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.

Constraints

S and T are strings consisting of lowercase English letters.

The lengths of S and T are between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S T

Output

Print the resulting string.

Sample Input 1

oder atc

Sample Output 1

atcoder

When S = oder and T = atc, concatenating T and S in this order results in atcoder.

Sample Input 2

humu humu

Sample Output 2

humuhumu


a,b,k=[parse(Int,i) for i in split(readline())]
for i=1:k
  a==0 ? b-=1 : a-=1
end
print("$a $(max(0,b))")

Score : 200 points

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:

If Takahashi has one or more cookies, eat one of his cookies.

Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.

If they both have no cookies, do nothing.

In the end, how many cookies will Takahashi and Aoki have, respectively?

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

He has two cookies, so he eats one of them.

Now he has one cookie left, and he eats it.

Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


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

function main()
	a,b,k = readline() |> split |> parseMap
	if a+b<k
		println("0 0")
	elseif a<k
		println("0 ",a+k-b)
	else
		println(k-a," ",b)
	end
end

main()


a,b,k=parse.(split(readline()))
a-=k
if a<0
  b+=a
  a=0
  if b<0
    b=0
  end
end
println("$a $b")


function isprime(n)
    if n <= 1 return false end
    if n == 2 return true end

    for i = 3:2:(n÷2)
        if n % i == 0 return false end
    end

    return true
end

function solve()
    X = parse(Int, readline())

    i = X
    while true
        if isprime(i)
            println(i)
            break
        end
        i+=1
    end
end

solve()

Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

2 \le X \le 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003


function isprime(x)
    if x<=1
        return false
    end
    rootx = ceil(sqrt(x))
    for i =2:rootx
        if x%i==0
            return false
        end
    end
    return true
end

x1 = parse(Int64, readline())
# println(x1)
p = x1
# println(p)

while (!isprime(p))
    global p += 1
end
println(p)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    x=parseInt(readline())
    for i in x:10^5+3
        flg=true
        for j in 2:sqrt(i)+1
            if i%j==0 && x>2
                flg=false
                break
            end
        end
        if flg
            println(i)
            break
        end
    end
end
main()


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

function isPrime(x)
	if x <= 1
		false
	elseif x == 2
		true
	elseif x%2 == 0
		false
	else
		i = 3
		f = 0
		while i <= sqrt(x)
			if x%i == 0
				f = 1
				break
			else
				i += 2
			end
		end
		f==0?true:false
	end
end

function main()
	x = readline() |> parseInt
	while !isPrime(x)
		x += 1
	end
	println(x)
end

main()


parseline(str=readline()) = parse.(Int, split(str))
function PredictionAndRestriction()
    N, K = parseline()
    R, S, P = parseline()
    score = zeros(Int, N)
    T = readline()
    for n in 1:N
        if T[n]=='r'
            score[n] = P
        elseif T[n]=='s'
            score[n] = R
        else
            score[n] = S
        end
    end
    for k in 1:K
        now = k + K
        while now ≤ N
            score[now-K] == score[now] && (score[now]=0)
            now += K
        end
    end
    println(sum(score))
end
PredictionAndRestriction()

Score : 400 points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996


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

function main()
	n = readline() |> parseInt
	if n==2
		println(-1)
	elseif n==3
		println("aa.")
		println("..a")
		println("..a")
	else
		x = n%4+4
		for ii in 1:div(n-4,4)*4
			for jj in 1:n
				if div(jj-1,4)==div(ii-1,4)
					i = ii%4
					j = jj%4
					if (i,j)==(1,1)||(i,j)==(1,2)||(i,j)==(3,3)||(i,j)==(3,0)
						print("a")
					elseif (i,j)==(1,3)||(i,j)==(2,3)||(i,j)==(3,1)||(i,j)==(0,1)
						print("b")
					elseif (i,j)==(1,0)||(i,j)==(2,0)||(i,j)==(3,2)||(i,j)==(0,2)
						print("c")
					else
						print("d")
					end
				else
					print(".")
				end
			end
			println("")
		end
		for i in 1:x
			for j in 1:div(n-4,4)*4
				print(".")
			end
			if x==4
				if i==1
					print("aabc")
				elseif i==2
					print("ddbc")
				elseif i==3
					print("bcaa")
				else
					print("bcdd")
				end
			elseif x==5
				if i==1
					print("aabba")
				elseif i==2
					print("bcc.a")
				elseif i==3
					print("b..cb")
				elseif i==4
					print("a..cb")
				else
					print("abbaa")
				end
			elseif x==6
				if i==1
					print("aabc..")
				elseif i==2
					print("ddbc..")
				elseif i==3
					print("..aabc")
				elseif i==4
					print("..ddbc")
				elseif i==5
					print("bc..aa")
				else
					print("bc..dd")
				end
			elseif x==7
				if i==1
					print("aabbcc.")
				elseif i==2
					print("dd.dd.a")
				elseif i==3
					print("..d..da")
				elseif i==4
					print("..d..db")
				elseif i==5
					print("dd.dd.b")
				elseif i==6
					print("..d..dc")
				else
					print("..d..dc")
				end
			end
			println("")
		end
	end
end

main()

Score : 900 points

Problem Statement

Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.
Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.

For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.
We define the quality of each column similarly.

Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,
or determine that such a placement doesn't exist.

Constraints

2 \le N \le 1000

Input

Input is given from Standard Input in the following format:

N

Output

If the required domino placement doesn't exist, print a single integer -1.

Otherwise, output your placement as N strings of N characters each.
If a square is not covered, the corresponding character must be . (a dot).
Otherwise, it must contain a lowercase English letter.
Squares covered by the same domino piece must contain the same letter.
If two squares have a common side but belong to different pieces, they must contain different letters.

Sample Input 1

6

Sample Output 1

aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b

The quality of every row and every column is 2.

Sample Input 2

2

Sample Output 2

-1


Score: 100 points

Problem Statement

Takahashi is solving quizzes. He has easily solved all but the last one.

The last quiz has three choices: 1, 2, and 3.

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

Print the correct choice for this problem.

Constraints

Each of the numbers A and B is 1, 2, or 3.

A and B are different.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the correct choice.

Sample Input 1

3
1

Sample Output 1

2

When we know 3 and 1 are both wrong, the correct choice is 2.

Sample Input 2

1
2

Sample Output 2

3


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

function main()
	n = readline() |> parseInt
	s,t = split(chomp(readline()))
	for i in 1:n
		print(s[i],t[i])
	end
	println("")
end

main()

Score : 200 points

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints

1 \leq N \leq 100

|S| = |T| = N

S and T are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S T

Output

Print the string formed.

Sample Input 1

2
ip cc

Sample Output 1

icpc

Sample Input 2

8
hmhmnknk uuuuuuuu

Sample Output 2

humuhumunukunuku

Sample Input 3

5
aaaaa aaaaa

Sample Output 3

aaaaaaaaaa


#=
B:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-12-22
=#
N = parse(readline())
A,B = split(readline())
ans = []
for (i,j) in zip(A,B)
	push!(ans,i)
	push!(ans,j)

end

for k in ans
	print(k)
end


#=
C:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-12-22
=#
A,B = parse.(split(readline()))

println(lcm(A,B))

Score : 300 points

Problem Statement

Takahashi is organizing a party.

At the party, each guest will receive one or more snack pieces.

Takahashi predicts that the number of guests at this party will be A or B.

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

We assume that a piece cannot be divided and distributed to multiple guests.

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

Sample Input 1

2 3

Sample Output 1

6

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000


a =  split(readline())
println(sum(parse.(Int, a)) > 21 ? "bust" : "win")

Score : 100 points

Problem Statement

Given are three integers A_1, A_2, and A_3.

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Constraints

1 \leq A_i \leq 13 \ \ (i=1,2,3)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Sample Input 1

5 7 9

Sample Output 1

win

5+7+9=21, so print win.

Sample Input 2

13 7 2

Sample Output 2

bust

13+7+2=22, so print bust.


#=
C:
- Julia version:
- Author: abap
- Date: 2019-12-21
=#

function return_all_pettern(x)  #bit全探索
    count_pettern = x ^ 2
    b = []
    for i in 0:count_pettern - 1
        bit = bin(i, x)
        bits = []
        for j in 1:x
            push!(bits, bit[j])
        end
        bits = [bits .== '1']
        push!(b, bits)
    end
    #println(length(b))
    return  b
end

function main()
XY = Dict{Int64, Array{Any,1}}() # xıとyıの格納先
N = parse(Int,readline())
for i in 1:N
    A = parse(Int,readline())
    for j in  1:A
       xy = parse.(split(readline()))
       xy[2] = xy[2] == 1
       push!(XY,i=>xy)       # i = 発言者 xy = 主張
    end
end
petterns = return_all_pettern(length(keys(XY)))  # 全ての部分集合を取得
res_said = []
for i in 1:length(petterns)               # それぞれの部分集合についての結果の格納先
    push!(res_said,[])
end
for jj in 1:length(petterns)        # 特定の格納先に入れるためにインデックスを回す
    pettern = petterns[jj]
    honest_list = collect(1:N)[sum(pettern)]
    for k in honest_list
        push!(res_said[jj],[k,1])      # 発言している人は本物
        push!(res_said[jj], [XY[k][1],Bool(XY[k][2]) ]  ) # 本物の言っている人も本物
    end
end
global kari_ans = []
for i in 1:length(petterns)               # それぞれの仮の答えについての結果の格納先
    push!(kari_ans,[])
end

for kk in 1:length(petterns)        # 特定の格納先に入れるためにインデックスを回す
    res = res_said[kk]
    if res == []
        ans = 0
    else
        for ik in res
            push!(kari_ans[kk],[ik[1],ik[2]])
        end
    end
end
ans_list  = []
for kari in kari_ans
    #println(kari)
    honest_count = 0
    for i in kari  # それぞれの結果について検証する
        #println(i)
        if i[2] == 0
            another_ans = [i[1],1]  # 違う答えがないかチェック
        else
            another_ans = [i[1],0]
            count = 0
            for jj in kari
                if jj == i
                    count += 1
                end
            end
            if count == 1
                honest_count += 1 # 同じ答えが何回もあるときはカウントしない
            end
        end
        if another_ans in kari
            honest_count = 0
            break
        end
    end
    push!(ans_list,honest_count)
end
println(maximum(ans_list))
end

main()

Score : 300 points

Problem Statement

There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.

Person i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.

How many honest persons can be among those N people at most?

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

N
A_1
x_{11} y_{11}
x_{12} y_{12}
:
x_{1A_1} y_{1A_1}
A_2
x_{21} y_{21}
x_{22} y_{22}
:
x_{2A_2} y_{2A_2}
:
A_N
x_{N1} y_{N1}
x_{N2} y_{N2}
:
x_{NA_N} y_{NA_N}

Output

Print the maximum possible number of honest persons among the N people.

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.

Sample Input 2

3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0

Sample Output 2

0

Assuming that one or more of them are honest immediately leads to a contradiction.

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1


function  parse_int(x)
    parse(Int, x)
end
function  MAP()
    map(parse_int, split(readline(), " "))
end
function intinput()
    parse(Int, readline())
end
function solve()
    H, W = MAP()
    a = MAP()
    a = reshape(a, 1, W)
    A = copy(a)
    for i = 1:H-1
        a = MAP()
        a = reshape(a, 1, W)
        A = [A; a]
    end
    b = MAP()
    b = reshape(b, 1, W)
    B = copy(b)
    for i = 1:H-1
        b = MAP()
        b = reshape(b, 1, W)
        B = [B; b]
    end
    dp = falses(H, W, 12601)
    dp[1, 1, abs(A[1, 1] - B[1, 1]) + 1] = true
    for i = 2:H
        for k = 1:12601
            difference = abs(A[i, 1] - B[i, 1])
            if dp[i - 1, 1, k]
                dp[i, 1, k + difference] = true
                dp[i, 1, abs(k - 1 - difference) + 1] = true
            end
        end
    end
    for j = 2:W
        for k = 1:12601
            difference = abs(A[1, j] - B[1, j])
            if dp[1, j - 1, k]
                dp[1, j, k + difference] = true
                dp[1, j, abs(k - 1 - difference) + 1] = true
            end
        end
    end
    for i = 2:H, j = 2:W
        difference = abs(A[i, j] - B[i, j])
        for k = 1:12601
            if dp[i - 1, j, k] || dp[i, j - 1, k]
                dp[i, j, k + difference] = true
                dp[i, j, abs(k - 1 - difference) + 1] = true
            end
        end
    end
    ans = 0
    for i = 1:12601
        if dp[H, W, i]
            ans = i
            break
        end
    end
    println("$(ans - 1)")
end
solve()

Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.

The square (i, j) has two numbers A_{ij} and B_{ij} written on it.

First, for each square, Takahashi paints one of the written numbers red and the other blue.

Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.

Let the unbalancedness be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).

Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.

Find the minimum unbalancedness possible.

Constraints

2 \leq H \leq 80

2 \leq W \leq 80

0 \leq A_{ij} \leq 80

0 \leq B_{ij} \leq 80

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W
A_{11} A_{12} \ldots A_{1W}
:
A_{H1} A_{H2} \ldots A_{HW}
B_{11} B_{12} \ldots B_{1W}
:
B_{H1} B_{H2} \ldots B_{HW}

Output

Print the minimum unbalancedness possible.

Sample Input 1

2 2
1 2
3 4
3 4
2 1

Sample Output 1

0

By painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are 3+3+1=7 and 1+2+4=7, respectively, for the unbalancedness of 0.

Sample Input 2

2 3
1 10 80
80 10 1
1 2 3
4 5 6

Sample Output 2

2


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

function main()
	h,w = readline() |> split |> parseMap
	a = zeros(Int,h,w)
	b = zeros(Int,h,w)
	ms = 80
	for i in 1:h
		a[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		b[i,:] = readline() |> split |> parseMap
	end
	base = ms*(h+w+1)
	dp = zeros(BigInt,h,w)
	dp[1,1] += BigInt(2)^(base+1+a[1,1]-b[1,1])
	dp[1,1] += BigInt(2)^(base+1-a[1,1]+b[1,1])
	for x in 1:h
		for y in 1:w
			if y<w
				v1 = abs(a[x,y+1]-b[x,y+1])
				dp[x,y+1] = dp[x,y+1]|dp[x,y]>>v1|dp[x,y]<<v1
			end
			if x<h
				v2 = abs(a[x+1,y]-b[x+1,y])
				dp[x+1,y] = dp[x+1,y]|dp[x,y]>>v2|dp[x,y]<<v2
			end
		end
	end
	z = base
	for i in 0:2*base+1
		if (dp[h,w]>>i)%2==1
			z = min(z,abs(base+2-i))
		end
	end
	println(z)
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function spush(s::Set{Int32},x::Int32)
	if !(x in s)
		push!(s,x)
	end
end

function main()
	h,w = readline() |> split |> parseMap
	a = zeros(Int32,h,w)
	b = zeros(Int32,h,w)
	ms = 80
	for i in 1:h
		a[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		b[i,:] = readline() |> split |> parseMap
	end
	base = (h+w)*ms
	dp = [zeros(Bool,2*base+1) for i in 1:h+w-1]
	dp[1][base+1+a[1,1]-b[1,1]]=true
	dp[1][base+1-a[1,1]+b[1,1]]=true
	for p in 1:h+w-2
		cand = Set{Int}()
		for q in max(1,p+1-h):min(p,w)
			x = p-q+1
			y = q
			if y<w
				push!(cand,a[x,y+1]-b[x,y+1])
				push!(cand,-a[x,y+1]+b[x,y+1])
			end
			if x<h
				push!(cand,a[x+1,y]-b[x+1,y])
				push!(cand,-a[x+1,y]+b[x+1,y])
			end
		end
		for i in 1:2*base+1
			if dp[p][i]
				for j in cand
					if 1<=i+j<=2*base+1
						dp[p+1][i+j]=true
					end
				end
			end
		end
	end
	z = base
	for i in 1:2*base+1
		if dp[h+w-1][i]
			z = min(z,abs(base+1-i))
		end
	end
	println(z)
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function spush(s::Set{Int},x::Int)
	if !(x in s)
		push!(s,x)
	end
end

function main()
	h,w = readline() |> split |> parseMap
	a = zeros(Int,h,w)
	b = zeros(Int,h,w)
	ms = 0
	for i in 1:h
		a[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		b[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		for j in 1:w
			ms = max(ms,a[i,j]-b[i,j],b[i,j]-a[i,j])
		end
	end
	base = (h+w)*ms
	dp = [Dict{Int,Bool}() for i in 1:h*w]
	dp[1][a[1,1]-b[1,1]]=true
	dp[1][-a[1,1]+b[1,1]]=true
	for x in 1:h
		for y in 1:w
			if y<w
				v1 = a[x,y+1]-b[x,y+1]
				for i in keys(dp[(x-1)*w+y])
					dp[(x-1)*w+y+1][i-v1]=true
					dp[(x-1)*w+y+1][i+v1]=true
				end
			end
			if x<h
				v2 = a[x+1,y]-b[x+1,y]
				for i in keys(dp[(x-1)*w+y])
					dp[x*w+y][i-v2]=true
					dp[x*w+y][i+v2]=true
				end
			end
		end
	end
	z = base
	for i in keys(dp[h*w])
		z = min(z,abs(i))
	end
	println(z)
end

main()


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
bsor(a::Array{Bool,1},b::Array{Bool,1})=a|b
cshift(a::Array{Bool,1},x::Int) = bsor(circshift(a,x),circshift(a,-x))

function main()
	h,w = readline() |> split |> parseMap
	a = zeros(Int,h,w)
	b = zeros(Int,h,w)
	ms = 0
	for i in 1:h
		a[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		b[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		for j in 1:w
			ms = max(ms,a[i,j]-b[i,j],b[i,j]-a[i,j])
		end
	end
	base = (h+w)*ms
	dp = [zeros(Bool,2*base+1) for i in 1:h*w]
	dp[1][base+1+a[1,1]-b[1,1]] = true
	dp[1][base+1-a[1,1]+b[1,1]] = true
	for x in 1:h
		for y in 1:w
			if y<w
				v1 = a[x,y+1]-b[x,y+1]
				dp[(x-1)*w+y+1] = bsor(dp[(x-1)*w+y+1],cshift(dp[(x-1)*w+y],v1))
			end
			if x<h
				v2 = a[x+1,y]-b[x+1,y]
				dp[x*w+y] = bsor(dp[x*w+y],cshift(dp[(x-1)*w+y],v2))
			end
		end
	end
	z = base
	for i in 1:2*base+1
		if dp[h*w][i]
			z = min(z,abs(base+1-i))
		end
	end
	println(z)
end

main()


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

function main()
	h,w = readline() |> split |> parseMap
	a = zeros(Int,h,w)
	b = zeros(Int,h,w)
	ms = 0
	for i in 1:h
		a[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		b[i,:] = readline() |> split |> parseMap
	end
	for i in 1:h
		for j in 1:w
			ms = max(ms,abs(a[i,j]-b[i,j]))
		end
	end
	ms *= 2
	dp = [Bool[false for x in 1:2*ms+1] for i in 1:h*w]
	dp[1][ms+1+a[1,1]-b[1,1]] = true
	dp[1][ms+1-a[1,1]+b[1,1]] = true
	for x in 1:h
		for y in 1:w
			for i in 1:2*ms+1
				if dp[(x-1)*w+y][i]
					if y<w
						v1 = i+a[x,y+1]-b[x,y+1]
						if 1<=v1&&v1<=2*ms+1
							dp[(x-1)*w+y+1][v1] = true
						end
						v2 = i-a[x,y+1]+b[x,y+1]
						if 1<=v2&&v2<=2*ms+1
							dp[(x-1)*w+y+1][v2] = true
						end
					end
					if x<h
						v1 = i+a[x+1,y]-b[x+1,y]
						if 1<=v1&&v1<=2*ms+1
							dp[x*w+y][v1] = true
						end
						v2 = i-a[x+1,y]+b[x+1,y]
						if 1<=v2&&v2<=2*ms+1
							dp[x*w+y][v2] = true
						end
					end
				end
			end
		end
	end
	z = ms
	for i in 1:2*ms+1
		if dp[h*w][i]
			z = min(z,abs(ms+1-i))
		end
	end
	println(z)
end

main()


function main()
	N,X,D=map(x->parse(Int,x),split(readline()))
	if D==0
		println(X==0 ? 1 : N+1)
		exit()
	end
	if D<0
		D=-D
		X=-X
	end
	S=Pair{Int,Pair{Int,Int}}[]
	for k=0:N
		L=fld(k*X,D)
		U=L+div(k*(k-1),2)=>L+N*k-div(k*(k+1),2)
		push!(S,mod(k*X,D)=>U)
	end
	ans=0
	pm=-1
	pre=0
	for (k,(l,r))=sort(S)
		if k==pm
			ans+=max(0,r-max(pre,l-1))
			pre=max(pre,r)
		else
			pm=k
			ans+=r-l+1
			pre=r
		end
	end
	println(ans)
end
main()

Score : 600 points

Problem Statement

We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds.

Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.

Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?

Constraints

-10^8 \leq X, D \leq 10^8

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X D

Output

Print the number of possible values of S - T.

Sample Input 1

3 4 2

Sample Output 1

8

A is (4, 6, 8).

There are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()).

The values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.

Sample Input 2

2 3 -3

Sample Output 2

2

A is (3, 0). There are two possible values of S - T: -3 and 3.

Sample Input 3

100 14 20

Sample Output 3

49805


function main()
	N,X,D=map(x->parse(Int,x),split(readline()))
	if D==0
		println(X==0 ? 1 : N+1)
		exit()
	end
	if D<0
		D=-D
		X=-X
	end
	S=Dict{Int,Array{Pair{Int,Int}}}()
	for k=0:N
		U=div(k*(k-1),2)=>N*k-div(k*(k+1),2)
		x=get(S,k*X%D,Pair{Int,Int}[])
		push!(x,U)
		S[k*X%D]=x
	end
	ans=0
	for (_,a)=S
		pre=-10^18
		for (l,r)=sort(a)
			ans+=r-max(pre,l)+1
			pre=r+1
		end
	end
	println(ans*2)
end
main()


m1,d1 = parse.(split(readline()," "))
m2,d2 = parse.(split(readline()," "))

if m1==m2
  print(0)
else
  print(1)
end

Score: 100 points

Problem Statement

In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019.

Integers M_1, D_1, M_2, and D_2 will be given as input.

It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1.

Determine whether the date 2019-M_1-D_1 is the last day of a month.

Constraints

Both 2019-M_1-D_1 and 2019-M_2-D_2 are valid dates in the Gregorian calendar.

The date 2019-M_2-D_2 follows 2019-M_1-D_1.

Input

Input is given from Standard Input in the following format:

M_1 D_1
M_2 D_2

Output

If the date 2019-M_1-D_1 is the last day of a month, print 1; otherwise, print 0.

Sample Input 1

11 16
11 17

Sample Output 1

0

November 16 is not the last day of a month.

Sample Input 2

11 30
12 1

Sample Output 2

1

November 30 is the last day of November.


N = parse(readline())
X = cld(N,1.08)
if trunc(X*1.08) == N
  println(convert(Int,X))
else
  println(":(")
end

Score: 200 points

Problem Statement

Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.

The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).

Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.

If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

Constraints

1 \leq N \leq 50000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If there are values that could be X, the price of the apple pie before tax, print any one of them.

If there are multiple such values, printing any one of them will be accepted.

If no value could be X, print :(.

Sample Input 1

432

Sample Output 1

400

If the apple pie is priced at 400 yen before tax, you have to pay 400 \times 1.08 = 432 yen to buy one.

Otherwise, the amount you have to pay will not be 432 yen.

Sample Input 2

1079

Sample Output 2

:(

There is no possible price before tax for which you have to pay 1079 yen with tax.

Sample Input 3

1001

Sample Output 3

927

If the apple pie is priced 927 yen before tax, by rounding down 927 \times 1.08 = 1001.16, you have to pay 1001 yen.


function main()
N = parse(readline())
x = cld(N,1.08)
x = convert(Int,x)
if x * 1.08 == N
    println(x)
else
    println(":(")
end
end
main()


function main()
X = parse(split(readline()))
len = length(X)
num = X[len-1:len]
num = parse(num)
X = parse(X)
ans = false
for i in 1:100
    for j in 1:cld((100-i),2)
      for k in 1:cld((100-i-2j),3)
        for ij in 1:cld((100-i-2j-3k),4)
          for ik in 1:cld((100-i-2j-3k-4ij),5)
            if i + 2j + 3k + 4ij + 5ik == num && 100*(i + j + k +ij + ik) == X-num
              pritnln(1)
              ans = true
              break
            end
          end
        end
      end
    end
  end
end
if ans != true
    pritnln(0)
end
main()

Score: 300 points

Problem Statement

AtCoder Mart sells 1000000 of each of the six items below:

Riceballs, priced at 100 yen (the currency of Japan) each

Sandwiches, priced at 101 yen each

Cookies, priced at 102 yen each

Cakes, priced at 103 yen each

Candies, priced at 104 yen each

Computers, priced at 105 yen each

Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.

(Ignore consumption tax.)

Constraints

1 \leq X \leq 100000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

Sample Input 1

615

Sample Output 1

1

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

Sample Input 2

217

Sample Output 2

0

No set of items costs 217 yen in total.


N=parse(readline())
println(N%100*21<=N ? 1 : 0)


N=parse(Int,readline())
S=chomp(readline())
A=zeros(Int,10)
B=zeros(Int,100)
C=zeros(Int,1000)
for c=S
	x=Int(c)-48
	for i=0:99
		if B[i+1]==1
			C[i*10+x+1]=1
		end
	end
	for i=0:9
		if A[i+1]==1
			B[i*10+x+1]=1
		end
	end
	A[x+1]=1
end
println(sum(C))

Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329


readline()
c=zeros(Int,3)
ans=1
for a=map(x->parse(Int,x),split(readline()))
	id=1
	cnt=0
	for i=1:3
		if c[i]==a
			cnt+=1
			id=i
		end
	end
	ans=ans*cnt%(10^9+7)
	c[id]+=1
end
println(ans)

Score: 500 points

Problem Statement

N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green.

The person numbered i says:

"In front of me, exactly A_i people are wearing hats with the same color as mine."

Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats.

Since the count can be enormous, compute it modulo 1000000007.

Constraints

1 \leq N \leq 100000

0 \leq A_i \leq N-1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print the number of possible combinations of colors of the N people's hats, modulo 1000000007.

Sample Input 1

6
0 1 2 3 4 5

Sample Output 1

3

We have three possible combinations, as follows:

Red, Red, Red, Red, Red, Red

Blue, Blue, Blue, Blue, Blue, Blue

Green, Green, Green, Green, Green, Green

Sample Input 2

3
0 0 0

Sample Output 2

6

Sample Input 3

54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Sample Output 3

115295190


T1,T2=map(x->parse(Int,x),split(readline()))
A1,A2=map(x->parse(Int,x),split(readline()))
B1,B2=map(x->parse(Int,x),split(readline()))
X=T1*A1+T2*A2
Y=T1*B1+T2*B2
if X==Y
	println("infinity")
else
	d=abs(T1*A1-T1*B1)
	D=abs(X-Y)
	if d<0
		println(0)
	elseif d==0
		println(1)
	else
		ans=1
		d-=D
		if d>=0
			ans+=div(d,D)*2+2
			if d%D==0
				ans-=1
			end
		end
		println(ans)
	end
end

Score: 600 points

Problem Statement

Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.

They start simultaneously at the same point and moves as follows towards the east:

Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

Print the number of times Takahashi and Aoki will meet each other.

If they meet infinitely many times, print infinity instead.

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start.

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times.

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

The values in input may not fit into a 32-bit integer type.


Score : 100 points

Problem Statement

Given is a string S representing the day of the week today.

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

After how many days is the next Sunday (tomorrow or later)?

Constraints

S is SUN, MON, TUE, WED, THU, FRI, or SAT.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of days before the next Sunday.

Sample Input 1

SAT

Sample Output 1

1

It is Saturday today, and tomorrow will be Sunday.

Sample Input 2

SUN

Sample Output 2

7

It is Sunday today, and seven days later, it will be Sunday again.


r=chomp(readline())
week=["SUN","MON","TUE","WED","THU","FRI","SAT"]

nextSUN=10
for i in 1:7
  if r==week[i]
    nextSUN=8-i
  end
end

print(nextSUN)


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    day=Dict{String,Int}("MON"=>6,"TUE"=>5,"WED"=>4,"THU"=>3,"FRI"=>2,"SAT"=>1,"SUN"=>7)
    println(day[s])
end
main()


day = strip(readline())

if day == "SUN"
  println(7)
elseif day == "MON"
  println(6)
elseif day == "TUE"
  println(5)
elseif day == "WED"
  println(4)
elseif day == "THU"
  println(3)
elseif day == "FRI"
  println(2)
elseif day == "SAT"
  println(1)
end


day = readline()

if day == "SUN"
  println(7)
elseif day == "MON"
  println(6)
elseif day == "TUE"
  println(5)
elseif day == "WED"
  println(4)
elseif day == "THU"
  println(3)
elseif day == "FRI"
  println(2)
elseif day == "SAT"
  println(1)
end


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

n=length(S)
ss=zeros(UInt8,n)
for i in 1:n
    ss[i]=UInt8(S[i])+N
    ss[i] > 0x5a  && (ss[i]-=26)
end

print.(Char.(ss));

Score : 200 points

Problem Statement

We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.

Shift each character of S by N in alphabetical order (see below), and print the resulting string.

We assume that A follows Z. For example, shifting A by 2 results in C (A \to B \to C), and shifting Y by 3 results in B (Y \to Z \to A \to B).

Constraints

0 \leq N \leq 26

1 \leq |S| \leq 10^4

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the string resulting from shifting each character of S by N in alphabetical order.

Sample Input 1

2
ABCXYZ

Sample Output 1

CDEZAB

Note that A follows Z.

Sample Input 2

0
ABCXYZ

Sample Output 2

ABCXYZ

Sample Input 3

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output 3

NOPQRSTUVWXYZABCDEFGHIJKLM


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    s=chomp(readline())
    for i in s
        if i+n>'Z'
            print('A'+(i+n-1-'Z'))
        else
            print(i+n)
        end
    end
end
main()


n=parse(Int,readline())
l=[parse(Int,i) for i in split(readline())]
g=+(l...)/2
l=[+(l[1:i]...) for i in 1:n]
print(Int(min([abs(g-i)*2 for i in l]...)))

Score: 200 points

Problem Statement

Takahashi, who works at DISCO, is standing before an iron bar.
The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.

Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.
However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:

Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).

Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.

Find the minimum amount of money needed before cutting the bar into two parts with the same length.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 2020202020

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.

Sample Input 1

3
2 4 3

Sample Output 1

3

The initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:

Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].

Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].

Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.

Sample Input 2

12
100 104 102 105 103 103 101 105 104 102 104 101

Sample Output 2

0


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

function main()
    n = readline() |> parseInt
    s = readline() |> chomp
    if n%2==1
        println("No")
    else
        f = 0
        k = n>>1
        for i in 1:k
            if s[i]!=s[i+k]
                f = 1
            end
        end
        println(f==0?"Yes":"No")
    end
end
main()

Score : 200 points

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string T such that S = T + T.

Constraints

1 \leq N \leq 100

S consists of lowercase English letters.

|S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let T = abc, and S = T + T.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No


#=
C:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-11-16
=#
N = parse(readline())
xy = []
for i in 1:N
    push!(xy,parse.(split(readline())))
end

function ky(a,b)
    return sqrt((a[1]-b[1])^2 + (a[2]-b[2])^2)
end
kyori = []
if N!=2
for i in 1:N
    for j in i+1:N
        push!(kyori,ky(xy[i],xy[j]))
    end
end
else
    println(ky(xy[1],xy[2]))
    end

o = factorial(N-1)
oo = o*(N-1)

sums = sum(kyori.*oo)

println(sums/factorial(N))

Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387


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

function main()
    n,t = readline() |> split |> parseMap
    a = zeros(Int,n,2)
    for i in 1:n
        a[i,:] = readline() |> split |> parseMap
    end
    a = sortrows(a,by=x->x[1])
    dp = -ones(Int,n+1,t+1)
    dp[1,1] = 0
    for i in 1:n
        for j in 1:t
            if dp[i,j]>-1
                dp[i+1,j] = max(dp[i+1,j],dp[i,j])
                dp[i+1,min(j+a[i,1],t+1)] = max(dp[i+1,min(j+a[i,1],t+1)], dp[i,j]+a[i,2])
            end
        end
    end
    println(maximum(dp))
end
main()

Score : 500 points

Problem Statement

Takahashi is at an all-you-can-eat restaurant.

The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.

The restaurant has the following rules:

You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.

You cannot order the same kind of dish more than once.

Until you finish eating the dish already served, you cannot order a new dish.

After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.

Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.

What is the maximum possible happiness achieved by making optimal choices?

Constraints

2 \leq N \leq 3000

1 \leq T \leq 3000

1 \leq A_i \leq 3000

1 \leq B_i \leq 3000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N T
A_1 B_1
:
A_N B_N

Output

Print the maximum possible happiness Takahashi can achieve.

Sample Input 1

2 60
10 10
100 100

Sample Output 1

110

By ordering the first and second dishes in this order, Takahashi's happiness will be 110.

Note that, if we manage to order a dish in time, we can spend any amount of time to eat it.

Sample Input 2

3 60
10 10
10 20
10 30

Sample Output 2

60

Takahashi can eat all the dishes within 60 minutes.

Sample Input 3

3 60
30 10
30 20
30 30

Sample Output 3

50

By ordering the second and third dishes in this order, Takahashi's happiness will be 50.

We cannot order three dishes, in whatever order we place them.

Sample Input 4

10 100
15 23
20 18
13 17
24 12
18 29
19 27
23 21
18 20
27 15
22 25

Sample Output 4

145


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

function main()
    n,t = readline() |> split |> parseMap
    a = Tuple{Int,Int}[(0,0) for i in 1:n]
    for i in 1:n
        p,q = readline() |> split |> parseMap
        a[i] = (p,q)
    end
    a = sort(a,by=x->x[1])
    dp = -ones(Int,n+1,t+3000)
    dp[1,1] = 0
    for i in 1:n
        for j in 1:t
            if dp[i,j]>-1
                dp[i+1,j] = max(dp[i+1,j],dp[i,j])
                dp[i+1,j+a[i][1]] = max(dp[i+1,j+a[i][1]], dp[i,j]+a[i][2])
            end
        end
    end
    println(maximum(dp))
end
main()


function main()
  N,T=map(x->parse(Int,x),split(readline()))
  A=Pair{Int,Int}[]
  for s=readlines()
    a,b=map(x->parse(Int,x),split(s))
    push!(A,a=>b)
  end
  sort!(A)
  ans=0
  dp=zeros(Int,T)
  for (a,b)=A
    for j=T:-1:1
      if j+a>T
        ans=max(ans,dp[j]+b)
      else
        dp[j+a]=max(dp[j+a],dp[j]+b)
      end
    end
  end
  println(ans)
end
main()


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

function main()
    n=parseInt(readline())
    ans=n÷2-ifelse(n%2==0,1,0)
    println(ans)
end
main()

Score : 100 points

Problem Statement

How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Constraints

1 \leq N \leq 10^6

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

4

Sample Output 1

1

There is only one way to choose two distinct integers totaling 4: to choose 1 and 3. (Choosing 3 and 1 is not considered different from this.)

Sample Input 2

999999

Sample Output 2

499999


#=
C:
- Julia version:
- Author: abap
- Date: 2019-11-09
=#
parseInt(x::SubString{String}) = parse(Int,x)

function main()
    count::Int64 = 0
    N::Int64 = parse(readline())
    A::Array{Int64} = parseInt.(split(readline()))
    B::Array{Int64} = parseInt.(split(readline()))
    #=sort!(A,alg = QuickSort)
    sort!(B,alg = QuickSort)
    @simd for i in 1:N
        if B[i] < A[N]
            @inbounds A[N], B[i] = B[i], A[N]
            sort!(A,alg = QuickSort)
            count += 1
        end
    end
    if count > N - 2
        println("No")
    else
        println("Yes")
    end=#
    sort!(A)
    for i in B
        if i > A[N]
            count += 1
            end
            end

            if count <= N - 2
                println("Yes")
            else
                println("No")
            end
end

main()


#=
C:
- Julia version:
- Author: abap
- Date: 2019-11-09
=#
N = parse(readline())
A = parse.(split(readline()))
B  = parse.(split(readline()))
sort!(A,alg = QuickSort)
sort!(B,alg = QuickSort)
function main()
    count = 0
    @simd for i in 1:N
        if B[i] < A[N]
            @inbounds A[N], B[i] = B[i], A[N]
            sort!(A,alg = QuickSort)
            count += 1
            #=println("B $i -> $(A[N])")
            print(B)=#
        end
    end
    if count > N -2
        print("No")
    else
        print("Yes")
    end
end

main()

Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

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

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes


#=
C:
- Julia version:
- Author: abap
- Date: 2019-11-09
=#
N = parse(readline())
A = parse.(split(readline()))
B  = parse.(split(readline()))
sort!(A)
sort!(B)
count = 0
for i in 1:N
    if B[i] < A[N]
        a = A[N]
        A[N] = B[i]
        B[i] = a
        sort!(A)
        count += 1
        #=println("B $i -> $(A[N])")
        print(B)=#
        println(A)
    end
end

if count > N-2
    print("No")
else
    print("Yes")
end


function main()
  s=readline()
  n=length(s)+1
  ans=0
  for i=1:n
    l=r=0
    for j=i:n-1
      s[j]=='>' ? r+=1 : break
    end
    for j=i-1:-1:1
      s[j]=='<' ? l+=1 : break
    end
    ans+=max(l,r)
  end
  println(ans)
end
main()

Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

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

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28


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)
    arr=zeros(Int,1,n+1)
    for i in 1:n
        if s[i]=='<' && arr[i]>=arr[i+1]
            arr[i+1]=arr[i]+1
        end
    end
    for i in n:-1:1
        if s[i]=='>' && arr[i]<=arr[i+1]
            arr[i]=arr[i+1]+1
        end
    end
    println(sum(arr))
end
main()


x=[]
for i in 1:9
  for j in 1:9
    push!(x,i*j)
  end
end

N=parse(readline())

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

Score : 200 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

Constraints

1 \leq N \leq 100

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.

Sample Input 1

10

Sample Output 1

Yes

10 can be represented as, for example, 2 \times 5.

Sample Input 2

50

Sample Output 2

No

50 cannot be represented as the product of two integers between 1 and 9.

Sample Input 3

81

Sample Output 3

Yes


function check(n)

  prime = false
  for i in round(Int,sqrt(n)):-1:2

    if n % i == 0
      prime = true
      return i
      break
    end

  end

  if prime == false
    return n
  end

end

function main()

  N = parse(Int,readline())

  a = check(N)
  b = div(N,a)

  println((a-1)+(b-1))

end

main()

Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.


N=parse(readline())
function get_num(N)
  for i in 1:1:sqrt(N)
    if N%i==0
      global a = i
    end
  end
  return a
end

a=get_num(N)
b=div(N,a)
a=Int64(a)
b=Int64(b)
println((a-1)+(b-1))


parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a::Array{Int,1},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;r;end
func(f::Int,a::Int,m::Int)=f*a<m?0:div(f*a-m,f)+min(1,(f*a-m)%f)

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	f = readline() |> split |> parseMap
	a =	sort(a)
	f = sort(f,rev=true)
	b = [a[i]*f[i] for i in 1:n]
	b = sort(b)
	l = -1
	r = b[n]
	while r-l>1
		m = (l+r)>>1
		s = 0
		t = bsearch(b,m)
		for i in t:n
			s += func(f[i],a[i],m)
		end
		if s<=k
			r = m
		else
			l = m
		end

	end
	println(r)
end

main()

Score: 500 points

Problem Statement

Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.

In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:

A team should assign one member to each food, and should not assign the same member to multiple foods.

It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.

The score of a team is the longest time it takes for an individual member to finish the food.

Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.

What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?

Constraints

All values in input are integers.

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

0 \leq K \leq 10^{18}

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

1 \leq F_i \leq 10^6\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N
F_1 F_2 ... F_N

Output

Print the minimum possible score of the team.

Sample Input 1

3 5
4 2 1
2 3 1

Sample Output 1

2

They can achieve the score of 2, as follows:

Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds.

Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second.

Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds.

They cannot achieve a score of less than 2, so the answer is 2.

Sample Input 2

3 8
4 2 1
2 3 1

Sample Output 2

0

They can choose not to do exactly K sets of training.

Sample Input 3

11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2

Sample Output 3

12


function f(A,F,X)
	T=0
	for (a,b)=zip(A,F)
		t=a*b-X
		if t>0
			T+=cld(t,b)
		end
	end
	T
end
function main()
	N,K=map(x->parse(Int,x),split(readline()))
	A=sort(map(x->parse(Int,x),split(readline())))
	F=reverse(sort(map(x->parse(Int,x),split(readline()))))
	L=0
	R=2^40
	while R-L>1
		M=(L+R)>>1
		if f(A,F,M)<=K
			R=M
		else
			L=M
		end
	end
	println(R)
end
main()