problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p02577 | p gets.to_i%9<1?:Yes: :No | puts`dd`.to_i%9<1?:Yes: :No | [
"control_flow.branch.if.condition.change"
] | 274,450 | 274,451 | u032223772 | ruby |
p02577 | p gets.to_i%9<1?:Yes: :No | puts gets.to_i%9<1?:Yes: :No | [
"call.function.change",
"io.output.change"
] | 274,450 | 274,452 | u032223772 | ruby |
p02577 | list = gets.chars.map(&:to_i)
sum = list.sum
if sum % 9 === 0
p 'Yes'
else
p 'No'
end | lists = gets.chars.map(&:to_i)
sum = lists.sum
if sum % 9 == 0
puts 'Yes'
else
puts 'No'
end | [
"assignment.variable.change",
"identifier.change",
"assignment.value.change",
"control_flow.branch.if.condition.change",
"call.function.change",
"io.output.change"
] | 274,608 | 274,609 | u608680352 | ruby |
p02577 | line = gets.split('')
line = line.map { |x| x.to_i }
S = line.sum
if S % 9 == 0
p 'Yes'
else
p 'No'
end | line = gets.split('')
line = line.map { |x| x.to_i }
S = line.sum
if S % 9 == 0
puts "Yes"
else
puts "No"
end | [
"literal.string.change",
"call.arguments.change"
] | 274,773 | 274,774 | u936380681 | ruby |
p02577 | line = gets.split('')
line = line.map { |x| x.to_i }
S = line.sum
if S % 9 == 0
p "Yes"
else
p "No"
end | line = gets.split('')
line = line.map { |x| x.to_i }
S = line.sum
if S % 9 == 0
puts "Yes"
else
puts "No"
end | [
"call.function.change",
"io.output.change"
] | 274,775 | 274,774 | u936380681 | ruby |
p02578 | # frozen_string_literal: true
n = gets.to_i
a = gets.split.map(&:to_i)
if n == 1
puts 0
exit
end
c = 0
(1..(n - 1)).each do |i|
d = [a[i] - a[i - 1], 0].max
a[i] += d
c += d
end
puts c
| # frozen_string_literal: true
n = gets.to_i
a = gets.split.map(&:to_i)
if n == 1
puts 0
exit
end
c = 0
(1..(n - 1)).each do |i|
d = [a[i - 1] - a[i], 0].max
a[i] += d
c += d
end
puts c
| [
"expression.operation.binary.remove"
] | 278,233 | 278,234 | u434509016 | ruby |
p02578 | require 'pp'
n = gets.to_i
a_n = gets.split.map(&:to_i)
i = 1
sum = 0
while i < n
if a_n[i-1] < a_n[i]
diff = a_n[i] - a_n[i-1]
sum += diff
a_n[i] += diff
end
i += 1
end
puts sum
| require 'pp'
n = gets.to_i
a_n = gets.split.map(&:to_i)
i = 1
sum = 0
while i < n
if a_n[i-1] > a_n[i]
diff = a_n[i-1] - a_n[i]
sum += diff
a_n[i] += diff
end
i += 1
end
puts sum
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 278,671 | 278,672 | u754375546 | ruby |
p02580 | io = DATA.eof? ? STDIN : DATA
h,w,m=io.gets.split.map(&:to_i)
rc=m.times.map{io.gets.split.map(&:to_i)}
r,c=rc.transpose
rtally= r.tally
ctally= c.tally
rmax= rtally.values.max
cmax= ctally.values.max
rct=rtally.count{|r,maxct|maxct==rmax}
cct=ctally.count{|c,maxct|maxct==cmax}
if rct*cct>rc.count{|r,c|rtally[r]==rmax && ctally[c]==cmax}
puts rmax+cmax
else
puts rmax+cmax-1
end
| io = DATA.eof? ? STDIN : DATA
h,w,m=io.gets.split.map(&:to_i)
rc=m.times.map{io.gets.split.map(&:to_i)}
r,c=rc.transpose
rtally= r.tally
ctally= c.tally
rmax= rtally.values.max
cmax= ctally.values.max
rct=rtally.count{|r,maxct|maxct==rmax}
cct=ctally.count{|c,maxct|maxct==cmax}
if rct*cct>rc.count{|r,c|rtally[r]==rmax && ctally[c]==cmax}
puts rmax+cmax
else
puts rmax+cmax-1
end
__END__
| [] | 280,195 | 280,196 | u132360211 | ruby |
p02580 | h, w, m = gets.split(" ").map(&:to_i)
grid = {}
h_grid = Array.new(h+1, 0)
w_grid = Array.new(w+1, 0)
hmax = h_grid.max
h_arr = []
wmax = w_grid.max
w_arr = []
m.times do
hi, wi = gets.split(" ").map(&:to_i)
grid[[hi, wi]] = true
h_grid[hi] ||= 0
w_grid[wi] ||= 0
h_grid[hi] += 1
w_grid[wi] += 1
if h_grid[hi] > hmax
hmax = h_grid[hi]
h_arr = [hi]
elsif h_grid[hi] == hmax
h_arr << hi
end
if w_grid[wi] > wmax
wmax = w_grid[wi]
w_arr = [wi]
elsif w_grid[wi] == wmax
w_arr << wi
end
end
bomb = true
h_arr.each do |i|
w_arr.each do |j|
bomb = false unless grid[[i, j]]
break
end
break unless bomb
end
puts hmax + wmax + (bomb ? -1 : 0)
| h, w, m = gets.split(" ").map(&:to_i)
grid = {}
h_grid = Array.new(h+1, 0)
w_grid = Array.new(w+1, 0)
hmax = h_grid.max
h_arr = []
wmax = w_grid.max
w_arr = []
m.times do
hi, wi = gets.split(" ").map(&:to_i)
grid[[hi, wi]] = true
h_grid[hi] ||= 0
w_grid[wi] ||= 0
h_grid[hi] += 1
w_grid[wi] += 1
if h_grid[hi] > hmax
hmax = h_grid[hi]
h_arr = [hi]
elsif h_grid[hi] == hmax
h_arr << hi
end
if w_grid[wi] > wmax
wmax = w_grid[wi]
w_arr = [wi]
elsif w_grid[wi] == wmax
w_arr << wi
end
end
bomb = true
h_arr.each do |i|
w_arr.each do |j|
bomb = false unless grid[[i, j]]
break unless bomb
end
break unless bomb
end
puts hmax + wmax + (bomb ? -1 : 0)
| [] | 280,930 | 280,931 | u771770008 | ruby |
p02582 | s=gets.chomp.split
m=0
t=0
for i in 0...3
if s[i]=='R'
t+=1
else
m=[m,t].max
t=0
end
end
m=[m,t].max
puts m
| s=gets.chomp.chars
m=0
t=0
for i in 0...3
if s[i]=='R'
t+=1
else
m=[m,t].max
t=0
end
end
m=[m,t].max
puts m
| [
"assignment.value.change",
"identifier.change"
] | 281,427 | 281,428 | u054798759 | ruby |
p02582 | puts (gets.split("S").map(&:size).max).to_i | n = gets.chomp.split("S").map(&:size).max
puts n.to_i | [
"call.add",
"call.arguments.change",
"io.output.change"
] | 281,466 | 281,465 | u802371628 | ruby |
p02582 | s = gets
cnt = 0
max = 0
s.times do |a|
if a == 'R'
cnt += 1
else
cnt =0
end
if max <cnt
max = cnt
end
end
p max | s = gets
cnt = 0
max = 0
3.times do |a|
if s[a] == 'R'
cnt += 1
else
cnt =0
end
if max <cnt
max = cnt
end
end
p max | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.branch.if.condition.change"
] | 281,520 | 281,519 | u621527413 | ruby |
p02582 | weathers = gets
if weathers.scan('SSS').length == 1
p 3
elsif weathers.scan('SS').length == 1
p 2
elsif weathers.scan('S').length > 0
p 1
else
p 0
end | weathers = gets
if weathers.scan('RRR').length == 1
p 3
elsif weathers.scan('RR').length == 1
p 2
elsif weathers.scan('R').length > 0
p 1
else
p 0
end | [
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 282,024 | 282,025 | u734028443 | ruby |
p02582 | weathers = gets
p weathers
if weathers.scan('SSS').length == 1
p 3
elsif weathers.scan('SS').length == 1
p 2
elsif weathers.scan('S').length > 0
p 1
else
p 0
end | weathers = gets
if weathers.scan('RRR').length == 1
p 3
elsif weathers.scan('RR').length == 1
p 2
elsif weathers.scan('R').length > 0
p 1
else
p 0
end | [
"call.remove",
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 282,026 | 282,025 | u734028443 | ruby |
p02582 | def input_n
gets.to_i # 単一整数
end
def input_s
gets.chomp # 文字列。chompを付けないと改行文字がついてくる
end
def input_a
gets.split.map(&:to_i) # スペースで区切られた複数の整数
end
def input_o(num)
num.times.map { gets.to_i } # 縦に並んだ複数の整数。たまにある
end
def output_f(num)
puts sprintf("%.12f", num)
end
s = input_s
cnt = 0
max = 0
(s.length).times do |i|
if s[i] == "S"
max = cnt
cnt = 0
end
cnt += 1 if s[i] == "R"
end
max = cnt if cnt > max
puts max
| def input_n
gets.to_i # 単一整数
end
def input_s
gets.chomp # 文字列。chompを付けないと改行文字がついてくる
end
def input_a
gets.split.map(&:to_i) # スペースで区切られた複数の整数
end
def input_o(num)
num.times.map { gets.to_i } # 縦に並んだ複数の整数。たまにある
end
def output_f(num)
puts sprintf("%.12f", num)
end
s = input_s
cnt = 0
max = 0
(s.length).times do |i|
if s[i] == "S"
next if cnt == 0
max = cnt
cnt = 0
end
cnt += 1 if s[i] == "R"
end
max = cnt if cnt > max
puts max
| [] | 282,091 | 282,092 | u876846619 | ruby |
p02582 | line = gets.split('')
count = 0
maxCount = 0
line.each{|var|
if var == ("S")
count +=1
if maxCount < count
maxCount = count
end
elsif var == ("R")
count = 0
end
}
p maxCount | line = gets.split('')
count = 0
maxCount = 0
line.each{|var|
if var == ("R")
count +=1
if maxCount < count
maxCount = count
end
elsif var == ("S")
count = 0
end
}
p maxCount | [
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 282,238 | 282,239 | u720102703 | ruby |
p02582 | puts gets.slice(/R+/).size
| puts gets.slice(/R+/)&.size || 0
| [
"call.add",
"call.arguments.change"
] | 282,427 | 282,428 | u158406393 | ruby |
p02582 | puts gets.slice(/R*/).size
| puts gets.slice(/R+/)&.size || 0
| [
"literal.string.change",
"expression.operator.arithmetic.change",
"call.arguments.change",
"call.add"
] | 282,429 | 282,428 | u158406393 | ruby |
p02582 | S = gets.chomp
result = ''
if S.match('SSS')
result = 3
elsif S.match('SS')
result = 2
elsif S.match('S')
result = 1
else
result = 0
end
p result | S = gets.chomp
result = ''
if S.match('RRR')
result = 3
elsif S.match('RR')
result = 2
elsif S.match('R')
result = 1
else
result = 0
end
p result | [
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 282,843 | 282,844 | u094197486 | ruby |
p02582 | s = gets.chomp
if s == "RRR"
puts 0
elsif s == "SSS"
puts 3
elsif s == "RRS" || s == "SRR"
puts 2
else
puts 1
end | s = gets.chomp
if s == "RRR"
puts 3
elsif s == "SSS"
puts 0
elsif s == "RRS" || s == "SRR"
puts 2
else
puts 1
end | [
"literal.number.integer.change",
"call.arguments.change"
] | 283,027 | 283,028 | u016444909 | ruby |
p02582 | puts gets.scan(/R+/).map!(&:length).max
| puts gets.scan(/R+/).map!(&:length).max || 0
| [
"expression.operation.binary.add"
] | 283,165 | 283,166 | u960319975 | ruby |
p02582 | p gets.scan(/R+/).max.size | p (gets.scan(/R+/).max||"").size | [
"call.arguments.change"
] | 283,173 | 283,174 | u019489252 | ruby |
p02583 | ### SNIPPET
# n = gets.split.map(&:to_i)
# array = n.times.map { gets.split.map(&:to_i) }
# [].all?(&:even?)
# a = [*1..m].repeated_combination(n).to_a
# [1,2,3,4,5].select { |num| num.even? } # => [2, 4]
# ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
# 切り捨て: .floor(2).to_f ,切り上げ: .ceil(2).to_f,四捨五入: round(2)
# 3.upto(6) do |i|, 6.downto(3) do |i|
# 公約数125.gcd(100)、公倍数125.lcm(100)
# PI = Math::PI
# 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
# def chmax(a, b) a > b ? a : b end
# INF = Float::INFINITY
# def chmin(a, b) a < b ? a : b end
n = gets.to_i
l = gets.split.map(&:to_i)
s = Set.new
count = 0
n.times do |i|
n.times do |j|
n.times do |k|
next if l[i]==l[j] || l[j]==l[k] || l[k]==l[i]
if s.add?([i,j,k].sort)
array = [l[i], l[j], l[k]].sort
if array[0] + array[1] > array[2] &&
array[0] < array[1] + array[2] &&
array[0] + array[2] > array[1]
count += 1
end
end
end
end
end
puts count
| ### SNIPPET
# n = gets.split.map(&:to_i)
# array = n.times.map { gets.split.map(&:to_i) }
# [].all?(&:even?)
# a = [*1..m].repeated_combination(n).to_a
# [1,2,3,4,5].select { |num| num.even? } # => [2, 4]
# ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
# 切り捨て: .floor(2).to_f ,切り上げ: .ceil(2).to_f,四捨五入: round(2)
# 3.upto(6) do |i|, 6.downto(3) do |i|
# 公約数125.gcd(100)、公倍数125.lcm(100)
# PI = Math::PI
# 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
# def chmax(a, b) a > b ? a : b end
# INF = Float::INFINITY
# def chmin(a, b) a < b ? a : b end
require 'set'
n = gets.to_i
l = gets.split.map(&:to_i)
s = Set.new
count = 0
n.times do |i|
n.times do |j|
n.times do |k|
next if l[i]==l[j] || l[j]==l[k] || l[k]==l[i]
if s.add?([i,j,k].sort)
array = [l[i], l[j], l[k]].sort
if array[0] + array[1] > array[2] &&
array[0] < array[1] + array[2] &&
array[0] + array[2] > array[1]
count += 1
end
end
end
end
end
puts count
| [
"call.add"
] | 283,392 | 283,393 | u219902564 | ruby |
p02583 |
# 棒の本数
n = gets.to_i
# 棒の長さ
a = gets.split.map(&:to_i).sort
# 答えの変数
sum = 0
# 全探索
(n - 2).times do |i|
((i + 1)..(n - 1)).each do |j|
next if a[i] == a[j]
((j + 1)..n).each do |k|
next if a[i] + a[j] <= a[k] || a[j] == a[k]
sum += 1
end
end
end
puts sum |
# 棒の本数
n = gets.to_i
# 棒の長さ
a = gets.split.map(&:to_i).sort
# 答えの変数
sum = 0
# 全探索
(n - 2).times do |i|
((i + 1)...(n - 1)).each do |j|
next if a[i] == a[j]
((j + 1)...n).each do |k|
next if a[i] + a[j] <= a[k] || a[j] == a[k]
sum += 1
end
end
end
puts sum | [] | 283,616 | 283,617 | u968803854 | ruby |
p02583 |
# 棒の本数
n = gets.to_i
# 棒の長さ
a = gets.chomp.split.map(&:to_i).sort.reverse
# 答えの変数
sum = 0
# 全探索
(n - 2).times do |i|
((i + 1)..(n - 1)).each do |j|
next if a[i] == a[j]
((j + 1)..n).each do |k|
next if a[i] + a[j] <= a[k] || a[j] == a[k]
sum += 1
end
end
end
puts sum |
# 棒の本数
n = gets.to_i
# 棒の長さ
a = gets.split.map(&:to_i).sort
# 答えの変数
sum = 0
# 全探索
(n - 2).times do |i|
((i + 1)...(n - 1)).each do |j|
next if a[i] == a[j]
((j + 1)...n).each do |k|
next if a[i] + a[j] <= a[k] || a[j] == a[k]
sum += 1
end
end
end
puts sum | [
"call.remove"
] | 283,618 | 283,617 | u968803854 | ruby |
p02583 | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 3
i = 1
while i <= line1[0].to_i - 3
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 3
i = 1
while i <= line1[0].to_i - 2
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | [
"literal.number.integer.change",
"expression.operation.binary.change"
] | 283,805 | 283,806 | u936380681 | ruby |
p02583 | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 3
i = 1
while i <= line1[0].to_i - 3
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 2
i = 1
while i <= line1[0].to_i - 2
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | [
"literal.number.integer.change",
"expression.operation.binary.change"
] | 283,805 | 283,807 | u936380681 | ruby |
p02583 | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 3
i = 1
while i <= line1[0].to_i - 3
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | line1 = gets.split(' ')
line2 = gets.split(' ')
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i }
counter = 0
h = 0
while h <= line1[0].to_i - 2
i = 1
while i <= line1[0].to_i - 2
j = 1
while i + j <= line1[0].to_i - 1
if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
else
if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
else
counter += 1
end
end
j += 1
end
i += 1
end
h += 1
end
p counter | [
"literal.number.integer.change",
"expression.operation.binary.change"
] | 283,805 | 283,808 | u936380681 | ruby |
p02584 | x, k, d = gets.split.map(&:to_i)
x = x.abs
result = if x < k * d
if k.even?
n = x / (2 * d)
a = x - n * 2 * d
b = x - 2 * d
[a.abs, b.abs].min
else
a0 = (x - d).abs
if k == 1
a0
else
x -= d
n = x / (2 * d)
a = x - n * 2 * d
b = x - 2 * d
[a.abs, b.abs].min
end
end
else
x - k * d
end
puts result | x, k, d = gets.split.map(&:to_i)
x = x.abs
result = if x < k * d
if k.even?
n = x / (2 * d)
a = x - n * 2 * d
b = a - 2 * d
[a.abs, b.abs].min
else
a0 = (x - d).abs
if x <= d
a0
else
x -= d
n = x / (2 * d)
a = x - n * 2 * d
b = a - 2 * d
[a.abs, b.abs].min
end
end
else
x - k * d
end
puts result | [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 284,179 | 284,178 | u297507288 | ruby |
p02584 | X, K, D = gets.split.map(&:to_i)
x = X.abs
k = K - x / D
if k < 0
puts "a"
exit
end
x = X % D
if k % 2 == 0
puts x
else
puts D - x
end
| X, K, D = gets.split.map(&:to_i)
x = X.abs
k = K - x / D
if k < 0
puts x - K * D
exit
end
x = x % D
if k % 2 == 0
puts x
else
puts D - x
end
| [
"assignment.value.change",
"expression.operation.binary.change"
] | 284,501 | 284,502 | u447268473 | ruby |
p02584 | X, K, D = gets.split.map(&:to_i)
x = X.abs
k = K - x / D
if k < 0
puts x - K * D
exit
end
x = X % D
if k % 2 == 0
puts x
else
puts D - x
end
| X, K, D = gets.split.map(&:to_i)
x = X.abs
k = K - x / D
if k < 0
puts x - K * D
exit
end
x = x % D
if k % 2 == 0
puts x
else
puts D - x
end
| [
"assignment.value.change",
"expression.operation.binary.change"
] | 284,503 | 284,502 | u447268473 | ruby |
p02584 | #input of int(split by space)
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
X,K,D=get_i
if X.abs>K*D
puts X.abs-K*D
exit
end
n=K-X.abs/D
if n.even?
puts X%D
else
puts D-X%D
end | #input of int(split by space)
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
X,K,D=get_i
if X.abs>K*D
puts X.abs-K*D
exit
end
n=K-X.abs/D
if n.even?
puts X.abs%D
else
puts D-X.abs%D
end | [
"call.add"
] | 284,647 | 284,648 | u415400221 | ruby |
p02584 | X, K, D = gets.chomp.split(' ').map(&:to_i)
if X/D > K
ans = X - D * K
elsif (K - X/D) % 2 == 0
ans = X - X/D*D
else
ans = (X - X/D*D - D) * -1
end
puts ans | X, K, D = gets.chomp.split(' ').map(&:to_i)
X = X.abs
if X/D > K
ans = X - D * K
elsif (K - X/D) % 2 == 0
ans = X - X/D*D
else
ans = (X - X/D*D - D) * -1
end
puts ans | [
"assignment.add"
] | 284,715 | 284,716 | u449004312 | ruby |
p02584 | X, K, D = gets.chomp.split(' ').map(&:to_i)
if X/D >= K
ans = X - D * K
elsif (K - X/D) % 2 == 0
ans = X - X/D*D
else
ans = (X - X/D*D - D) * -1
end
puts ans | X, K, D = gets.chomp.split(' ').map(&:to_i)
X = X.abs
if X/D > K
ans = X - D * K
elsif (K - X/D) % 2 == 0
ans = X - X/D*D
else
ans = (X - X/D*D - D) * -1
end
puts ans | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 284,717 | 284,716 | u449004312 | ruby |
p02584 | x,k,d = gets.chomp.split(" ").map(&:to_i)
num = [x / d, k].min
if x >= 0
x -= num * d
else
x += num * d
end
k -= num
if k % 2 == 0
puts x.abs
elsif x >= 0
puts (x - d).abs
else
puts (x + d).abs
end
| x,k,d = gets.chomp.split(" ").map(&:to_i)
num = [(x / d).abs, k].min
if x >= 0
x -= num * d
else
x += num * d
end
k -= num
if k % 2 == 0
puts x.abs
elsif x >= 0
puts (x - d).abs
else
puts (x + d).abs
end
| [
"call.add"
] | 285,408 | 285,409 | u257668305 | ruby |
p02584 | x, k, d = gets.split.map(&:to_i)
t, m = x.divmod(d)
if k <= t
puts (x - k * d).abs
elsif (k - t).even?
puts m
else
puts (m - d).abs
end
| x, k, d = gets.split.map(&:to_i)
x = x.abs
t, m = x.divmod(d)
if k <= t
puts (x - k * d).abs
elsif (k - t).even?
puts m
else
puts (m - d).abs
end
| [
"assignment.add"
] | 285,436 | 285,437 | u180695909 | ruby |
p02584 | x, k ,d = gets.chomp.split(" ").map(&:to_i)
#今いる座標
#kkaisuu
#d idou
x = x.abs
kyori = x - k * d
if x > 0
if kyori > 0
puts kyouri
elsif kyori == 0
puts "0"
elsif kyori < 0
mae = x / d
maekyori = x - d * mae
usiro = x - d * (mae + 1)
kaizuu = k - mae
if maekyori != d
if kaizuu % 2 == 0
puts maekyori.abs
else
puts usiro.abs
end
elsif maekyori == d
if kaizuu % 4 == 1 || kaizuu % 4 == 3
puts "0"
else
puts maekyori.abs
end
end
end
elsif x == 0
if k % 4 == 1 || k % 3 == 3
puts d.abs
else
puts "0"
end
end | x, k ,d = gets.chomp.split(" ").map(&:to_i)
#今いる座標
#kkaisuu
#d idou
x = x.abs
kyori = x - k * d
if x > 0
if kyori > 0
puts kyori
elsif kyori == 0
puts "0"
elsif kyori < 0
mae = x / d
maekyori = x - d * mae
usiro = x - d * (mae + 1)
kaizuu = k - mae
if maekyori != d
if kaizuu % 2 == 0
puts maekyori.abs
else
puts usiro.abs
end
elsif maekyori == d
if kaizuu % 4 == 1 || kaizuu % 4 == 3
puts "0"
else
puts maekyori.abs
end
end
end
elsif x == 0
if k % 4 == 1 || k % 3 == 3
puts d.abs
else
puts "0"
end
end | [
"identifier.change",
"call.arguments.change"
] | 285,453 | 285,454 | u412789323 | ruby |
p02584 | x, k ,d = gets.chomp.split(" ").map(&:to_i)
#今いる座標
#kkaisuu
#d idou
x = x.abs
kyouri = x - k * d
if x > 0
if kyori > 0
puts kyouri
elsif kyori == 0
puts "0"
elsif kyori < 0
mae = x / d
maekyori = x - d * mae
usiro = x - d * (mae + 1)
kaizuu = k - mae
if maekyori != d
if kaizuu % 2 == 0
puts maekyori.abs
else
puts usiro.abs
end
elsif maekyori == d
if kaizuu % 4 == 1 || kaizuu % 4 == 3
puts "0"
else
puts maekyori.abs
end
end
end
elsif x == 0
if k % 4 == 1 || k % 3 == 3
puts d
else
puts "0"
end
end | x, k ,d = gets.chomp.split(" ").map(&:to_i)
#今いる座標
#kkaisuu
#d idou
x = x.abs
kyori = x - k * d
if x > 0
if kyori > 0
puts kyori
elsif kyori == 0
puts "0"
elsif kyori < 0
mae = x / d
maekyori = x - d * mae
usiro = x - d * (mae + 1)
kaizuu = k - mae
if maekyori != d
if kaizuu % 2 == 0
puts maekyori.abs
else
puts usiro.abs
end
elsif maekyori == d
if kaizuu % 4 == 1 || kaizuu % 4 == 3
puts "0"
else
puts maekyori.abs
end
end
end
elsif x == 0
if k % 4 == 1 || k % 3 == 3
puts d.abs
else
puts "0"
end
end | [
"assignment.variable.change",
"identifier.change",
"call.arguments.change",
"call.add"
] | 285,455 | 285,454 | u412789323 | ruby |
p02584 | x,k,d = gets.split(" ").map(&:to_i)
min_steps = x.abs / d
min1 = x - min_steps * d * (x>0 ? 1 : -1)
min2 = min1 + d * (min1>0 ? -1 : 1)
if k < min_steps then
puts x - k * d * (x>0 ? 1 : -1)
elsif k == min_steps then
puts min1.abs
else
puts (k - min_steps) % 2 == 0 ? min1.abs : min2.abs
end
| x,k,d = gets.split(" ").map(&:to_i)
min_steps = x.abs / d
min1 = x - min_steps * d * (x>0 ? 1 : -1)
min2 = min1 + d * (min1>0 ? -1 : 1)
if k < min_steps then
puts (x - k * d * (x>0 ? 1 : -1)).abs
elsif k == min_steps then
puts min1.abs
else
puts (k - min_steps) % 2 == 0 ? min1.abs : min2.abs
end
| [
"call.arguments.change",
"call.add"
] | 286,032 | 286,033 | u217358301 | ruby |
p02584 | x,k,d=gets.split.map(&:to_i)
if x>=k*d
puts x-k*d
else
if (x/d+k).even?
puts x%d
else
puts d-x%d
end
end
| x,k,d=gets.split.map(&:to_i)
x=x.abs
if x>=k*d
puts x-k*d
else
if (x/d+k).even?
puts x%d
else
puts d-x%d
end
end
| [
"assignment.add"
] | 286,211 | 286,212 | u744908753 | ruby |
p02584 | class InputLine
def self.to_s
gets.chomp
end
def self.to_i
InputLine.to_s.to_i
end
def self.to_f
InputLine.to_s.to_f
end
def self.to_sa
InputLine.to_s.split(' ')
end
def self.to_ia
InputLine.to_sa.map(&:to_i)
end
def self.to_fa
InputLine.to_sa.map(&:to_f)
end
end
def f(x, k, d, i)
(x - k * d) + 2 * d * i
end
def main(argv)
(x, k, d) = InputLine.to_ia
hi = k + 1
lo = 0
while hi - lo > 4 do
dist = (hi - lo) / 3
midL = lo + dist
midR = hi - dist
valL = f(x, k, d, midL).abs
valR = f(x, k, d, midR).abs
if valL < valR then
hi = midL
else
lo = midR
end
end
lb = [0, lo - 1000].max
ub = [k, hi + 1000].min
mval = 1e+18.to_i
(lb..ub).each do |i|
mval = [mval, f(x, k, d, i).abs].min
end
puts mval.to_s
end
if self.to_s == 'main' then
main(ARGV)
end | class InputLine
def self.to_s
gets.chomp
end
def self.to_i
InputLine.to_s.to_i
end
def self.to_f
InputLine.to_s.to_f
end
def self.to_sa
InputLine.to_s.split(' ')
end
def self.to_ia
InputLine.to_sa.map(&:to_i)
end
def self.to_fa
InputLine.to_sa.map(&:to_f)
end
end
def f(x, k, d, i)
(x - k * d) + 2 * d * i
end
def main(argv)
(x, k, d) = InputLine.to_ia
hi = k + 1
lo = 0
while hi - lo > 4 do
dist = (hi - lo) / 3
midL = lo + dist
midR = hi - dist
valL = f(x, k, d, midL).abs
valR = f(x, k, d, midR).abs
if valL < valR then
hi = midR
else
lo = midL
end
end
lb = [0, lo - 10].max
ub = [k, hi + 10].min
mval = 1e+18.to_i
(lb..ub).each do |i|
mval = [mval, f(x, k, d, i).abs].min
end
puts mval.to_s
end
if self.to_s == 'main' then
main(ARGV)
end | [
"assignment.value.change",
"identifier.change",
"literal.number.integer.change",
"expression.operation.binary.change"
] | 286,235 | 286,236 | u198355306 | ruby |
p02584 | x,k,d = gets.chomp.split(" ").map(&:to_i)
minus = false
if x < 0
minus = true
x *= -1
end
ans = x
y = x/d
r = x%d
if k < y
ans -= k*d
else
ans = r
if (k-y%2) == 1
ans -= d
end
end
if minus
ans *= -1
end
puts("#{ans.abs}") | x,k,d = gets.chomp.split(" ").map(&:to_i)
minus = false
if x < 0
minus = true
x *= -1
end
ans = x
y = x/d
r = x%d
if k < y
ans -= k*d
else
ans = r
if ((k-y)%2) == 1
ans -= d
end
end
if minus
ans *= -1
end
puts("#{ans.abs}") | [
"control_flow.branch.if.condition.change"
] | 286,278 | 286,279 | u879573689 | ruby |
p02584 | x, k, d = gets.chomp.split.map(&:to_i)
x = x.abs
t = x / d
a = x - t * d
res =
if t <= k
if (k - t) % 2 == 0
a
else
d - a
end
else
(k - t) * d + a
end
puts res.abs | x, k, d = gets.chomp.split.map(&:to_i)
x = x.abs
t = x / d
a = x - t * d
res =
if t <= k
if (k - t) % 2 == 0
a
else
d - a
end
else
(t - k) * d + a
end
puts res | [
"expression.operation.binary.remove",
"call.remove"
] | 286,347 | 286,348 | u946334556 | ruby |
p02584 | x,k,d = gets.split.map(&:to_i)
if x / d < k
if (k - (x / d)) % 2 == 0
puts (x - (x / d) * d).abs
else
puts ((x - (x / d) * d).abs - d).abs
end
else
puts (x - k * d).abs
end
| x,k,d = gets.split.map(&:to_i)
x = x.abs
if x / d < k
if (k - (x / d)) % 2 == 0
puts (x - (x / d) * d).abs
else
puts ((x - (x / d) * d).abs - d).abs
end
else
puts (x - k * d).abs
end
| [
"assignment.add"
] | 286,375 | 286,376 | u966810027 | ruby |
p02584 | X,K,D = gets.split.map(&:to_i)
if (X < 0)
if (X + K*D <= 0)
puts (X + K*D).abs
else
if (K - (-X.to_f/D).ceil).even?
puts (X + (-X.to_f/D).ceil*K).abs
else
puts (X + (-X.to_f/D).ceil*K - K).abs
end
end
else
if (X - K*D > 0)
puts (X - K*D).abs
else
if (K - (X.to_f/D).ceil).even?
puts (X - (X.to_f/D).ceil*K).abs
else
puts (X - (X.to_f/D).ceil*K + K).abs
end
end
end
| X,K,D = gets.split.map(&:to_i)
if (X < 0)
if (X + K*D <= 0)
puts (X + K*D).abs
else
if (K - (-X.to_f/D).ceil).even?
puts (X + (-X.to_f/D).ceil*D).abs
else
puts (X + (-X.to_f/D).ceil*D - D).abs
end
end
else
if (X - K*D > 0)
puts (X - K*D).abs
else
if (K - (X.to_f/D).ceil).even?
puts (X - (X.to_f/D).ceil*D).abs
else
puts (X - (X.to_f/D).ceil*D + D).abs
end
end
end
| [
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 286,618 | 286,619 | u616360029 | ruby |
p02584 | X, K, D = gets.split.map(&:to_i)
pos = X.abs
if K * D < pos then
puts pos - K * D
else
a = pos / D
pos = pos - D * a
i = a % 2
if i == 0
puts pos
else
puts (pos - K).abs
end
end
| X, K, D = gets.split.map(&:to_i)
pos = X.abs
if K * D < pos then
puts pos - K * D
else
a = pos / D
pos = pos - D * a
i = (K - a) % 2
if i == 0
puts pos
else
puts (pos - D).abs
end
end
| [
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 287,287 | 287,288 | u990758634 | ruby |
p02585 | def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end
def extract_cycle(s, used)
cycle = []
u = s
until used[u]
used[u] = true
cycle << u
u = P[u]
end
return cycle
end
N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
C = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
used = Array.new(N + 1)
ans = (1 .. N).inject(-1e20) do |max_score, s|
next max_score if used[s]
# sを始点とする閉路を抽出
cycle = extract_cycle(s, used)
z = cycle.size
# 閉路の各頂点から最大1周分のスコアを計算できるように事前準備
dp = Array.new(3 * z + 1, 0)
(1 .. z * 3).each do |i|
v = cycle[i % z]
dp[i] = dp[i - 1] + C[v]
end
# 閉路上の任意の点 s を始点としたときの最大スコアを計算
# 1周 + 余りの最大スコアを計算する
# 余りのみ計算すると1周が負(sz < 0)かつ, K >= zのときに
# 上手く計算できないので、z + K % zになってる。
sz = max(0, dp[z])
k = min(K, z + K % z)
r = (K - k) / z
cycle_score = (0 ... z).map{|s| r * sz + score[s + 1, k].max - score[s]}.max
max(max_score, cycle_score)
end
puts ans
| def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end
def extract_cycle(s, used)
cycle = []
u = s
until used[u]
used[u] = true
cycle << u
u = P[u]
end
return cycle
end
N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
C = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
used = Array.new(N + 1)
ans = (1 .. N).inject(-1e20) do |max_score, s|
next max_score if used[s]
# sを始点とする閉路を抽出
cycle = extract_cycle(s, used)
z = cycle.size
# 閉路の各頂点から最大1周分のスコアを計算できるように事前準備
dp = Array.new(3 * z + 1, 0)
(1 .. z * 3).each do |i|
v = cycle[i % z]
dp[i] = dp[i - 1] + C[v]
end
# 閉路上の任意の点 s を始点としたときの最大スコアを計算
# 1周 + 余りの最大スコアを計算する
# 余りのみ計算すると1周が負(sz < 0)かつ, K >= zのときに
# 上手く計算できないので、z + K % zになってる。
sz = max(0, dp[z])
k = min(K, z + K % z)
r = (K - k) / z
cycle_score = (0 ... z).map{|s| r * sz + dp[s + 1, k].max - dp[s]}.max
max(max_score, cycle_score)
end
puts ans
| [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 287,968 | 287,969 | u627981707 | ruby |
p02594 | x=gets.to_i
if x>=30
print "YES"
elsif x<30
print "NO"
end | x=gets.to_i
if x>=30
print "Yes"
elsif x<30
print "No"
end | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,354 | 290,355 | u492991702 | ruby |
p02594 | x=gets.to_i
if x>30
print "YES"
elsif x<30
print "NO"
end | x=gets.to_i
if x>=30
print "Yes"
elsif x<30
print "No"
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,356 | 290,355 | u492991702 | ruby |
p02594 | x=gets.to_i
if x>=30
print "YES"
else
print "NO"
end | x=gets.to_i
if x>=30
print "Yes"
else
print "No"
end | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,357 | 290,358 | u678700651 | ruby |
p02594 | x=gets.to_i
if x>30
print "YES"
else
print "NO"
end | x=gets.to_i
if x>=30
print "Yes"
else
print "No"
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,360 | 290,358 | u678700651 | ruby |
p02594 | x=gets.to_i
if x>30
p "Yes"
else
p "No"
end | x=gets.to_i
if x>=30
print "Yes"
else
print "No"
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.function.change",
"io.output.change"
] | 290,361 | 290,358 | u678700651 | ruby |
p02594 | x=gets.to_i
if x>30
p "Yes"
else
p "No"
end
| x=gets.to_i
if x>=30
print "Yes"
else
print "No"
end
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.function.change",
"io.output.change"
] | 290,362 | 290,363 | u341246457 | ruby |
p02594 | X = gets.to_i
if X >= 30
print 'YES'
else
print 'NO'
end | X = gets.to_i
if X >= 30
print 'Yes'
else
print 'No'
end | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,486 | 290,487 | u159942474 | ruby |
p02594 | tem=gets.to_i
if tem>=30
puts "YES"
else
puts "NO"
end | tem=gets.to_i
if tem>=30
puts "Yes"
else
puts "No"
end | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,878 | 290,879 | u338904326 | ruby |
p02594 | ten=gets.to_i
if ten>=30
puts "YES"
else
puts "NO"
end | tem=gets.to_i
if tem>=30
puts "Yes"
else
puts "No"
end | [
"assignment.variable.change",
"identifier.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,880 | 290,879 | u338904326 | ruby |
p02594 | ten = gets.to_i
if ten >= 30
puts "YES"
else
puts "NO"
end | tem=gets.to_i
if tem>=30
puts "Yes"
else
puts "No"
end | [
"assignment.variable.change",
"identifier.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,881 | 290,879 | u338904326 | ruby |
p02594 | X = gets.to_i
if X >= 30
puts "YES"
else
puts "NO"
end | tem=gets.to_i
if tem>=30
puts "Yes"
else
puts "No"
end | [
"assignment.variable.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,882 | 290,879 | u338904326 | ruby |
p02594 | X = gets.to_i
if X >= 30
puts "YES"
else
puts "NO"
end | tem=gets.to_i
if tem>=30
puts "Yes"
else
puts "No"
end | [
"assignment.variable.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 290,883 | 290,879 | u338904326 | ruby |
p02594 | x = gets.strip.to_i
if x < 30
p "No"
else
p "Yes"
end
| x = gets.strip.to_i
if x < 30
puts "No"
else
puts "Yes"
end
| [
"call.function.change",
"io.output.change"
] | 292,128 | 292,129 | u188673878 | ruby |
p02594 | puts gets.to_i<30?"NO":"YES" | puts gets.to_i<30?"No":"Yes" | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 292,386 | 292,387 | u771630380 | ruby |
p02594 | x = gets.to_i
if x >= 30
puts("yes")
else
puts("no")
end | x = gets.to_i
if x >= 30
puts("Yes")
else
puts("No")
end | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 292,603 | 292,604 | u879573689 | ruby |
p02595 | n,d = gets.split.map(&:to_i)
cnt = 0
for i in 0...n
a,b = gets.split.map(&:to_i)
if a*a+b*b<=d
cnt += 1
end
end
puts cnt | n,d = gets.split.map(&:to_i)
cnt = 0
for i in 0...n
a,b = gets.split.map(&:to_i)
if a*a+b*b<=d*d
cnt += 1
end
end
puts cnt
| [
"control_flow.branch.if.condition.change"
] | 294,581 | 294,582 | u054798759 | ruby |
p02595 | n,d = gets.split.map(&:to_i)
cnt = 0
for i in 0...n
a,b = gets.split.map(&:to_i)
if a*a+b*b<=d
cnt += 1
end
end
puts | n,d = gets.split.map(&:to_i)
cnt = 0
for i in 0...n
a,b = gets.split.map(&:to_i)
if a*a+b*b<=d*d
cnt += 1
end
end
puts cnt
| [
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 294,583 | 294,582 | u054798759 | ruby |
p02588 | c=(0..19).map{[0]*20}
p`sed 1d`.split.sum{|a|a=(a.to_r*10**9).to_i
i=j=0
i+=1while a[i]<1&&i<18
(j+=1;a/=5)while a%5<1&&j<18
s=c[~i..].sum{_1[~j..].sum}
c[i][j]+=1;s} | c=(0..18).map{[0]*19}
p`sed 1d`.split.sum{|a|a=(a.to_r*10**9).to_i
i=j=0
i+=1while a[i]<1&&i<18
(j+=1;a/=5)while a%5<1&&j<18
s=c[~i..].sum{_1[~j..].sum}
c[i][j]+=1
s} | [
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change",
"call.arguments.change"
] | 295,330 | 295,331 | u657913472 | ruby |
p02588 | def divisors(n,x)
i = 0
while n % x == 0
n = n / x
i += 1
end
i
end
N = gets.to_i
a = N.times.map{gets.to_f}
arr = Array.new(13){Array.new(4){Hash.new(0)}}
a.each do |xx|
bit = 9
x = ((xx+0.00000000001) * (10 ** 9)).floor
puts x
while x % 10 == 0
bit -= 1
x /= 10
end
if x % 5 == 0
arr[bit%13][2][divisors(x,5)] += 1
elsif x % 2 == 0
arr[bit%13][1][divisors(x,2)] += 1
else
arr[bit%13][0][0] += 1
end
arr[bit%13][3][0] += 1
end
cnt = 0
(-3).upto(9) do |i|
i.upto(9) do |j|
if i + j <= 0
if i == j
cnt += arr[i%13][3][0] * (arr[i%13][3][0]-1) / 2
else
cnt += arr[i%13][3][0] * arr[j%13][3][0]
end
else
if i == j
inum = 0
jnum = 0
arr[i%13][1].each do |k,v|
if k >= i+j
inum += v
end
end
arr[i%13][2].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
else
inum = 0
arr[i%13][1].each do |k,v|
if k >= i+j
inum += v
end
end
jnum = 0
arr[j%13][2].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
inum = 0
arr[i%13][2].each do |k,v|
if k >= i+j
inum += v
end
end
jnum = 0
arr[j%13][1].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
end
end
end
end
puts cnt | def divisors(n,x)
i = 0
while n % x == 0
n = n / x
i += 1
end
i
end
N = gets.to_i
a = N.times.map{gets.to_f}
arr = Array.new(13){Array.new(4){Hash.new(0)}}
a.each do |xx|
bit = 9
x = ((xx+0.00000000001) * (10 ** 9)).floor
while x % 10 == 0
bit -= 1
x /= 10
end
if x % 5 == 0
arr[bit%13][2][divisors(x,5)] += 1
elsif x % 2 == 0
arr[bit%13][1][divisors(x,2)] += 1
else
arr[bit%13][0][0] += 1
end
arr[bit%13][3][0] += 1
end
cnt = 0
(-3).upto(9) do |i|
i.upto(9) do |j|
if i + j <= 0
if i == j
cnt += arr[i%13][3][0] * (arr[i%13][3][0]-1) / 2
else
cnt += arr[i%13][3][0] * arr[j%13][3][0]
end
else
if i == j
inum = 0
jnum = 0
arr[i%13][1].each do |k,v|
if k >= i+j
inum += v
end
end
arr[i%13][2].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
else
inum = 0
arr[i%13][1].each do |k,v|
if k >= i+j
inum += v
end
end
jnum = 0
arr[j%13][2].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
inum = 0
arr[i%13][2].each do |k,v|
if k >= i+j
inum += v
end
end
jnum = 0
arr[j%13][1].each do |k,v|
if k >= i+j
jnum += v
end
end
cnt += inum * jnum
end
end
end
end
puts cnt | [
"call.remove"
] | 295,434 | 295,435 | u265679940 | ruby |
p02595 | n,d = gets.strip.split.map(&:to_i)
ans = 0
n.times do
x,y = gets.strip.split.map(&:to_i)
ans += 1 if d * d <= x * x + y * y
end
p ans
| n,d = gets.strip.split.map(&:to_i)
ans = 0
n.times do
x,y = gets.strip.split.map(&:to_i)
ans += 1 if d * d >= x * x + y * y
end
p ans
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 295,808 | 295,809 | u188673878 | ruby |
p02596 | K=gets.to_i
if K.even?
puts "-1"
exit
end
c=1
n=7
loop do
break if n%K==0
c+=1
n=(n*10+7)%K
if n==7 || c == K
puts "-1"
exit
end
end
puts c
| K=gets.to_i
if K.even?
puts "-1"
exit
end
c=1
n=7
loop do
break if n%K==0
c+=1
n=(n*10+7)%K
if n==7 || c == K+1
puts "-1"
exit
end
end
puts c
| [
"control_flow.branch.if.condition.change"
] | 297,005 | 297,006 | u058568575 | ruby |
p02596 | K = gets.to_i
r = -1
m = 1 % K
K.times{|i|
if m == 0
r = i + 1
break
end
m = m * 10 + 1
m %= K
}
puts r
| K = gets.to_i
r = -1
m = 7 % K
K.times{|i|
if m == 0
r = i + 1
break
end
m = m * 10 + 7
m %= K
}
puts r
| [
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 297,376 | 297,377 | u488526012 | ruby |
p02596 | k = gets.chomp.to_i
if k == 7
p 1
exit
end
ans = 0
x = 7%k
i = 1
s =false
while i <= k
x =(x*10+7)%k
if x == 0
s = true
break
end
i += 1
end
if s
p i+1
else
p -1
end | k = gets.chomp.to_i
if k == 7 || k == 1
p 1
exit
end
ans = 0
x = 7%k
i = 1
s =false
while i <= k
x =(x*10+7)%k
if x == 0
s = true
break
end
i += 1
end
if s
p i+1
else
p -1
end | [
"control_flow.branch.if.condition.change"
] | 297,393 | 297,394 | u847977106 | ruby |
p02596 | K = gets.to_i
if K == 1
puts 1
exit
end
if K.even?
puts -1
exit
end
if K % 5 == 0
puts -1
exit
end
x = 1
result = 1
while x % K != 0 do
while x < K do
x = x * 10 + 1
result += 1
end
x = x % K
end
puts result
| K = gets.to_i
if K == 1
puts 1
exit
end
if K.even?
puts -1
exit
end
if K % 5 == 0
puts -1
exit
end
x = 7
result = 1
while x % K != 0 do
while x < K do
x = x * 10 + 7
result += 1
end
x = x % K
end
puts result
| [
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 298,066 | 298,067 | u299761130 | ruby |
p02596 | k=gets.to_i
tmp=[false]*k
m = 7%k
(1...k).each {|i|
if m == 0
print i
exit
end
if tmp[m]
print -1
exit
end
tmp[m]=true
m = (m*10+7)%k
}
| k=gets.to_i
tmp=[false]*k
m = 7%k
(1..k).each {|i|
if m == 0
print i
exit
end
if tmp[m]
print -1
exit
end
tmp[m]=true
m = (m*10+7)%k
}
| [] | 299,499 | 299,500 | u702482655 | ruby |
p02598 | n,k = gets.chomp.split(" ").map(&:to_i)
a_arr = gets.chomp.split(" ").map(&:to_i)
l = 0
r = a_arr.max
# 二分探索
while true do
len = (r + l) / 2
break if len
tmp_k = 0
a_arr.each do |a|
tmp_k += (a / len.to_f).ceil - 1
end
if tmp_k <= k
r = len
else
l = len
end
if r - l <= 1
break
end
end
puts l + 1
| n,k = gets.chomp.split(" ").map(&:to_i)
a_arr = gets.chomp.split(" ").map(&:to_i)
l = 0
r = a_arr.max
# 二分探索
while true do
len = (r + l) / 2
break if len == 0
tmp_k = 0
a_arr.each do |a|
tmp_k += (a / len.to_f).ceil - 1
end
if tmp_k <= k
r = len
else
l = len
end
if r - l <= 1
break
end
end
puts l + 1
| [
"control_flow.branch.if.condition.change"
] | 299,882 | 299,883 | u257668305 | ruby |
p02598 | # 入力:N本ある丸太を合計K回切ることができる
N, K = gets.chomp.split.map(&:to_i)
# 入力:N本ある丸太それぞれの長さ
A = gets.chomp.split.map(&:to_i)
# 切り終えたとき最大の丸太の長さの候補
range = [1..A.max]
# 長さ候補rangeのそれぞれについて、k回で切れるか二分探索
ans = range.bsearch{|x| A.sum{(_1 - 1) / x} <= K}
# 出力
puts ans | # 入力:N本ある丸太を合計K回切ることができる
N, K = gets.chomp.split.map(&:to_i)
# 入力:N本ある丸太それぞれの長さ
A = gets.chomp.split.map(&:to_i)
# 長さ候補rangeのそれぞれについて、k回で切れるか二分探索
ans = (1 .. A.max).bsearch{|x| A.sum{(_1 - 1) / x} <= K}
# 出力
puts ans | [
"assignment.variable.change",
"identifier.change",
"assignment.value.change"
] | 300,411 | 300,412 | u968803854 | ruby |
p02598 | n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l = 0
r = a.max
while l < r
m = (l + r) / 2
sum = 0
a.each {|e| sum += (e.fdiv(m) - 1).ceil}
sum > k ? l = m + 1 : r = m
end
p l | n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l = 1
r = a.max
while l < r
m = (l + r) / 2
sum = 0
a.each {|e| sum += (e.fdiv(m) - 1).ceil}
sum > k ? l = m + 1 : r = m
end
p l | [
"literal.number.integer.change",
"assignment.value.change"
] | 300,812 | 300,813 | u692254521 | ruby |
p02598 | n, k = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_f)
def check(k, len, arr)
cnt = 0
arr.each do |a|
cnt += (a/len).ceil - 1
end
return cnt <= k
end
prev = -1
l = 0
r = arr.max.to_i + 1
min = 1145148101919
while l < r
len = (l + r) / 2
ok = check(k, len, arr)
#puts "len:#{len} ok:#{ok} l:#{l} r:#{r}"
if len == prev
break
elsif ok
r = len
min = len if min > len
else
l = len
end
prev = len
end
puts min | n, k = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_f)
def check(k, len, arr)
cnt = 0
arr.each do |a|
cnt += (a/len).ceil - 1
end
return cnt <= k
end
prev = -1
l = 0
r = arr.max.to_i + 1
min = 1145148101919
while l < r
len = [(l + r) / 2, 1].max
ok = check(k, len, arr)
#puts "len:#{len} ok:#{ok} l:#{l} r:#{r}"
if len == prev
break
elsif ok
r = len
min = len if min > len
else
l = len
end
prev = len
end
puts min | [
"call.add"
] | 300,922 | 300,923 | u409390792 | ruby |
p02598 | def bsearch_desc(a, b, &proc)
inverse_proc = -> (n) { proc.call(-n) }
value *= -1 if value = (-a..-b).bsearch(&inverse_proc)
end
INF = 10 ** 9
n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
ans = bsearch_desc(INF, 1) { |length|
count = 0
nums.each do |num|
div, mod = num.divmod(length)
div += 1 if mod > 0
count += div - 1
end
count > k
} + 1
puts ans
| def bsearch_desc(a, b, &proc)
inverse_proc = -> (n) { proc.call(-n) }
value *= -1 if value = (-a..-b).bsearch(&inverse_proc)
end
INF = 10 ** 9
n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
ans = bsearch_desc(INF, 1) { |length|
count = 0
nums.each do |num|
div, mod = num.divmod(length)
div += 1 if mod > 0
count += div - 1
end
count > k
}
ans ||= 0
ans += 1
puts ans
| [
"expression.operation.binary.change"
] | 301,359 | 301,360 | u653737129 | ruby |
p02600 | input = gets.chomp.split("")
puts 10 - (input/200).to_i | input = gets.chomp.to_i
puts 10 - (input/200).to_i | [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 303,298 | 303,299 | u330144367 | ruby |
p02600 | input = gets.chomp.to_i
result = 0
8.times do |i|
i += 1 if input > 1800 - i * 200
end
return result | input = gets.chomp.to_i
result = 0
8.times do |i|
result += 1 if input <= 1999 - i * 200
end
print result | [
"identifier.change",
"function.return_value.change"
] | 303,365 | 303,366 | u794447645 | ruby |
p02601 | a, b, c = gets.split.map { |t| t.to_i }
k = gets.to_i
[0, 1].repeated_permutation(k) do |bits|
x, y, z = a, b, c
bits.each do |bit|
if bit.zero?
y **= 2
else
z **= 2
end
end
if x < y && y < z
puts "Yes"
exit
end
end
puts "No" | a, b, c = gets.split.map { |t| t.to_i }
k = gets.to_i
[0, 1].repeated_permutation(k) do |bits|
x, y, z = a, b, c
bits.each do |bit|
if bit.zero?
y *= 2
else
z *= 2
end
end
if x < y && y < z
puts "Yes"
exit
end
end
puts "No" | [
"io.output.change"
] | 303,736 | 303,737 | u693378622 | ruby |
p02601 | a, b, c = gets.split.map(&:to_i)
K = gets.to_i
cnt = 0
while true do
if b < a
b *= 2
cnt += 1
else
break
end
end
while true do
if c < b
c *= 2
cnt += 1
else
break
end
end
puts cnt <= K ? "Yes" : "No" | a, b, c = gets.split.map(&:to_i)
K = gets.to_i
cnt = 0
while true do
if b <= a
b *= 2
cnt += 1
else
break
end
end
while true do
if c <= b
c *= 2
cnt += 1
else
break
end
end
puts cnt <= K ? "Yes" : "No" | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 303,809 | 303,810 | u926099741 | ruby |
p02601 | num = gets.split(" ").map(&:to_i)
k = gets.to_i
magic = false
while k != -1
if (num[0] >= num[1])
num[1] *= 2
elsif (num[1] >= num[2])
num[2] *= 2
else
k = 0
magic = true
end
k = k - 1
end
if (magic)
p 'Yes'
else
p 'No'
end
| num = gets.split(" ").map(&:to_i)
k = gets.to_i
magic = false
while k != -1
if (num[0] >= num[1])
num[1] *= 2
elsif (num[1] >= num[2])
num[2] *= 2
else
k = 0
magic = true
end
k = k - 1
end
if (magic)
print 'Yes'
else
print 'No'
end
| [
"call.function.change",
"io.output.change"
] | 303,881 | 303,882 | u152712578 | ruby |
p02601 | num = gets.split(" ").map(&:to_i)
k = gets.to_i
magic = false
while k != -1
if (num[0] >= num[1])
num[1] *= 2
elsif (num[1] >= num[2])
num[2] *= 2
else
k = 0
magic = true
end
k = k - 1
end
if (magic)
p "Yes"
else
p "No"
end
| num = gets.split(" ").map(&:to_i)
k = gets.to_i
magic = false
while k != -1
if (num[0] >= num[1])
num[1] *= 2
elsif (num[1] >= num[2])
num[2] *= 2
else
k = 0
magic = true
end
k = k - 1
end
if (magic)
print 'Yes'
else
print 'No'
end
| [
"literal.string.change",
"call.arguments.change"
] | 303,883 | 303,882 | u152712578 | ruby |
p02601 | a,b,c = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if a>b
b*=2
else
c*=2
end
end
puts a<b && b<c ? "Yes" : "No" | a,b,c = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if a>=b
b*=2
else
c*=2
end
end
puts a<b && b<c ? "Yes" : "No" | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 304,010 | 304,011 | u514143079 | ruby |
p02601 | a, b, c = gets.chomp.split.map(&:to_i)
k = gets.chomp.to_i
# c > b > a
(k+1).times do
if c > b && b > a
puts "Yes"
exit
end
if a > b
b *= 2
elsif b > c
c *= 2
end
end
puts "No" | a, b, c = gets.chomp.split.map(&:to_i)
k = gets.chomp.to_i
# c > b > a
(k+1).times do
if c > b && b > a
puts "Yes"
exit
end
if a >= b
b *= 2
elsif b >= c
c *= 2
end
end
puts "No" | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 304,025 | 304,026 | u409390792 | ruby |
p02601 | r,g,b = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if r>g
g*=2
elsif g>b
b*=2
end
#p r,g,b
end
puts (r<g and g<b) ? "Yes" : "No" | r,g,b = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if r>=g
g*=2
elsif g>=b
b*=2
end
#p r,g,b
end
puts (r<g and g<b) ? "Yes" : "No" | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 304,199 | 304,200 | u712322283 | ruby |
p02601 | a, b, c = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if a > b
b *= 2
elsif b > c
c *= 2
end
end
if a < b && b < c
puts 'Yes'
else
puts 'No'
end
| a, b, c = gets.split.map(&:to_i)
k = gets.to_i
k.times do
if a >= b
b *= 2
elsif b >= c
c *= 2
end
end
if a < b && b < c
puts 'Yes'
else
puts 'No'
end
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 304,735 | 304,736 | u393913844 | ruby |
p02601 | a, b, c = gets.chomp.split.map(&:to_i)
k = gets.chomp.to_i
k.times do |i|
if a > b
b = b * 2
next
end
if b > c
c = c * 2
next
end
end
if a < b and b < c
puts "Yes"
else
puts "No"
end | a, b, c = gets.chomp.split.map(&:to_i)
k = gets.chomp.to_i
k.times do |i|
if a >= b
b = b * 2
next
end
if b >= c
c = c * 2
next
end
end
if a < b and b < c
puts "Yes"
else
puts "No"
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 304,822 | 304,823 | u644533034 | ruby |
p02601 | a,b,c = gets.chomp.split(' ').map(&:to_i)
k = gets.chomp.to_i
k.times do
if (b < a)
b = b*2
next
end
if (c < b)
c = c*2
next
end
if (a < b && b < c)
puts 'Yes'
exit
end
end
puts (a < b && b < c) ? 'Yes' : 'No' | a,b,c = gets.chomp.split(' ').map(&:to_i)
k = gets.chomp.to_i
k.times do
if (b <= a)
b = b*2
next
end
if (c <= b)
c = c*2
next
end
if (a < b && b < c)
puts 'Yes'
exit
end
end
puts (a < b && b < c) ? 'Yes' : 'No' | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 305,122 | 305,123 | u546441021 | ruby |
p02601 | a,b,c = gets.chomp.split(" ").map(&:to_i)
k = gets.to_i
k.times do
if a > b
b = b * 2
elsif b > c
c = c * 2
end
end
if a < b && b < c
puts "Yes"
else
puts "No"
end | a,b,c = gets.chomp.split(" ").map(&:to_i)
k = gets.to_i
k.times do
if a >= b
b = b * 2
elsif b >= c
c = c * 2
end
end
if a < b && b < c
puts "Yes"
else
puts "No"
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 305,236 | 305,237 | u265679940 | ruby |
p02601 | n = gets.strip.split.map(&:to_i)
k = gets.to_i
k.times do |i|
if n[0] > n[1]
x = n[1]
x = x*2
n[1] = x
elsif n[1] > n[2]
x = n[2]
x = x*2
n[2] = x
end
if n[0] < n[1] && n[1] < n[2]
puts "Yes"
exit
end
end
puts "No"
| n = gets.strip.split.map(&:to_i)
k = gets.to_i
k.times do |i|
if n[0] >= n[1]
x = n[1]
x = x*2
n[1] = x
elsif n[1] >= n[2]
x = n[2]
x = x*2
n[2] = x
end
if n[0] < n[1] && n[1] < n[2]
puts "Yes"
exit
end
end
puts "No"
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 305,735 | 305,736 | u652514744 | ruby |
p02601 | a,b,c = gets.split(" ").map(&:to_i)
k = gets.to_i
k.times do
if a > b then
b = b * 2
elsif b > c then
c = c * 2
end
if a < b && b < c then
break
end
end
puts (a < b && b < c) ? "Yes" : "No"
| a,b,c = gets.split(" ").map(&:to_i)
k = gets.to_i
k.times do
if a >= b then
b = b * 2
elsif b >= c then
c = c * 2
end
if a < b && b < c then
break
end
end
puts (a < b && b < c) ? "Yes" : "No"
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 305,856 | 305,857 | u217358301 | ruby |
p02598 | #input of int(split by space)
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
N,K=get_i
A=get_i.sort!{|x,y| y<=>x}
def fulfil?(x)
res=0
A.each do|a|
break if a<x
res+=a/x
end
return res<=K
end
if K.zero?
puts A[0]
exit
end
head=1
tail=A[0]
while tail-head>1
mid=head+(tail-head)/2
if fulfil?(mid)
tail=mid
else
head=mid
end
end
if fulfil?(head)
puts head
else
puts tail
end | #input of int(split by space)
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
N,K=get_i
A=get_i.sort!{|x,y| y<=>x}
def fulfil?(x)
res=0
A.each do|a|
break if a<=x
res+=a/x
end
return res<=K
end
if K.zero?
puts A[0]
exit
end
head=1
tail=A[0]
while tail-head>1
mid=head+(tail-head)/2
if fulfil?(mid)
tail=mid
else
head=mid
end
end
if fulfil?(head)
puts head
else
puts tail
end | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 306,703 | 306,704 | u415400221 | ruby |
p02603 | n = gets.to_i
a = gets.split(" ").map(&:to_i).slice(0,n)
BUY ="buy"
SELL="sell"
NO = ""
chart =[]
last =0
a.each_index{|d|
action = NO
if d == 0
action = BUY
else
if a[d] > a[d-1]
action=SELL
chart[d-1]=NO if chart[d-1] == SELL
elsif a[d] < a[d-1]
action = BUY
chart[d-1]=NO if chart[d-1]==BUY
end
end
chart.push(action)
}
for i in 0..n-1
d = n-1 - i
if chart[d] == SELL
break
elsif chart[d] == BUY
chart[d] = NO
break
end
end
money = 1000
stock=0
chart.each_index { |d|
action = chart[d]
price = a[d]
case action
when BUY then
count = money / price
money = money - count * price
stock += count
when SELL then
money += stock * price
stock = 0
end
}
puts money < 1000 ? 1000 : money
| n = gets.to_i
a = gets.split(" ").map(&:to_i).slice(0,n)
BUY ="buy"
SELL="sell"
NO = ""
chart =[]
last =0
a.each_index{|d|
action = NO
if d == 0
action = BUY
else
if a[d] >= a[d-1]
action=SELL
chart[d-1]=NO if chart[d-1] == SELL
elsif a[d] < a[d-1]
action = BUY
chart[d-1]=NO if chart[d-1]==BUY
end
end
chart.push(action)
}
for i in 0..n-1
d = n-1 - i
if chart[d] == SELL
break
elsif chart[d] == BUY
chart[d] = NO
break
end
end
money = 1000
stock=0
chart.each_index { |d|
action = chart[d]
price = a[d]
case action
when BUY then
count = money / price
money = money - count * price
stock += count
when SELL then
money += stock * price
stock = 0
end
}
puts money < 1000 ? 1000 : money
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 307,494 | 307,495 | u217358301 | ruby |
p02603 | n = gets.to_i
a = gets.split(" ").map(&:to_i).slice(0,n)
BUY ="buy"
SELL="sell"
NO = ""
chart =[]
last =0
a.each_index{|d|
action = NO
if d == 0
action = BUY
else
if a[d] > a[d-1]
action=SELL
chart[d-1]=NO if chart[d-1] == SELL
elsif a[d] < a[d-1]
action = BUY
chart[d-1]=NO if chart[d-1]=BUY
end
end
chart.push(action)
}
for i in 0..n-1
d = n-1 - i
if chart[d] == SELL
break
elsif chart[d] == BUY
chart[d] = NO
break
end
end
money = 1000
stock=0
chart.each_index { |d|
action = chart[d]
price = a[d]
case action
when BUY then
count = money / price
money = money - count * price
stock += count
when SELL then
money += stock * price
stock = 0
end
}
puts money < 1000 ? 1000 : money
| n = gets.to_i
a = gets.split(" ").map(&:to_i).slice(0,n)
BUY ="buy"
SELL="sell"
NO = ""
chart =[]
last =0
a.each_index{|d|
action = NO
if d == 0
action = BUY
else
if a[d] >= a[d-1]
action=SELL
chart[d-1]=NO if chart[d-1] == SELL
elsif a[d] < a[d-1]
action = BUY
chart[d-1]=NO if chart[d-1]==BUY
end
end
chart.push(action)
}
for i in 0..n-1
d = n-1 - i
if chart[d] == SELL
break
elsif chart[d] == BUY
chart[d] = NO
break
end
end
money = 1000
stock=0
chart.each_index { |d|
action = chart[d]
price = a[d]
case action
when BUY then
count = money / price
money = money - count * price
stock += count
when SELL then
money += stock * price
stock = 0
end
}
puts money < 1000 ? 1000 : money
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 307,496 | 307,495 | u217358301 | ruby |
p02603 | line = gets
prices = gets.split(' ').map(&:to_i)
have_money = 1000
kabu_num = 0
last_sell = false
prices.each_with_index do |price,i|
break if prices[i+1].nil?
if price < prices[i+1]
# puts '買い'
last_sell = true
next if kabu_num != 0 # 株を保持してて買いの時はそのまま保持なので
kabu_num = (have_money / price)
have_money = have_money - (kabu_num * price)
end
if price > prices[i+1]
# puts '売り'
last_sell = false
have_money = have_money + (kabu_num * price)
kabu_num = 0
end
end
# 最後
if last_sell
have_money = have_money + (kabu_num * prices[-1])
end
| line = gets
prices = gets.split(' ').map(&:to_i)
have_money = 1000
kabu_num = 0
last_sell = false
prices.each_with_index do |price,i|
break if prices[i+1].nil?
if price < prices[i+1]
# puts '買い'
last_sell = true
next if kabu_num != 0 # 株を保持してて買いの時はそのまま保持なので
kabu_num = (have_money / price)
have_money = have_money - (kabu_num * price)
end
if price > prices[i+1]
# puts '売り'
last_sell = false
have_money = have_money + (kabu_num * price)
kabu_num = 0
end
end
# 最後
if last_sell
have_money = have_money + (kabu_num * prices[-1])
end
puts have_money
| [
"call.add"
] | 307,849 | 307,850 | u046160726 | ruby |
p02603 | n = gets.to_i
nums = gets.split.map(&:to_i)
rest = 1000
stock = 0
waiting_to_buy = true
previous = nums.first
last_price = previous
nums[1..-1].each do |num|
if waiting_to_buy && num <= previous
previous = num
next
elsif waiting_to_buy
stock, rest = rest.divmod(previous)
previous = num
waiting_to_buy = !waiting_to_buy
last_price = num
elsif !waiting_to_buy && num >= previous
previous = num
next
elsif !waiting_to_buy
rest = previous * stock
stock = 0
previous = num
waiting_to_buy = !waiting_to_buy
end
end
puts rest + [last_price, nums.last].max * stock
| n = gets.to_i
nums = gets.split.map(&:to_i)
rest = 1000
stock = 0
waiting_to_buy = true
previous = nums.first
last_price = previous
nums[1..-1].each do |num|
if waiting_to_buy && num <= previous
previous = num
next
elsif waiting_to_buy
stock, rest = rest.divmod(previous)
previous = num
waiting_to_buy = !waiting_to_buy
last_price = num
elsif !waiting_to_buy && num >= previous
previous = num
next
elsif !waiting_to_buy
rest += previous * stock
stock = 0
previous = num
waiting_to_buy = !waiting_to_buy
end
end
puts rest + [last_price, nums.last].max * stock
| [
"assignment.value.change"
] | 308,275 | 308,276 | u653737129 | ruby |
p02603 | n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
up_trend = a[0] < a[1]
array = []
array << a[0] if (up_trend)
for i in 1...a.size do
if (up_trend)
if (a[i] < a[i-1])
array << a[i-1]
up_trend = false
end
else
if (a[i] > a[i-1])
array << a[i-1]
up_trend = true
end
end
end
if (array[-1] < a[-1])
array << a[-1]
end
okane = 1000
kabu = 0
buy = true
array.each do |price|
if (buy)
kazu = okane / price
kabu += kazu
okane -= price * kazu
buy = !buy
else
okane += kabu * price
kabu = 0
buy = !buy
end
end
puts okane | n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
up_trend = a[0] < a[1]
array = []
array << a[0] if (up_trend)
for i in 1...a.size do
if (up_trend)
if (a[i] < a[i-1])
array << a[i-1]
up_trend = false
end
else
if (a[i] > a[i-1])
array << a[i-1]
up_trend = true
end
end
end
if (array[-1] && array[-1] < a[-1])
array << a[-1]
end
okane = 1000
kabu = 0
buy = true
array.each do |price|
if (buy)
kazu = okane / price
kabu += kazu
okane -= price * kazu
buy = !buy
else
okane += kabu * price
kabu = 0
buy = !buy
end
end
puts okane | [
"control_flow.branch.if.condition.change"
] | 308,451 | 308,452 | u546441021 | ruby |
p02603 | n = gets().chomp().to_i
prices = gets().chomp().split(' ').map(&:to_i)
curr_money = 1000
buy_at, count = -1, 0
while count < n do
if buy_at == -1
buy_at = count
else
if prices[buy_at] < prices[count]
curr_money += (curr_money / prices[buy_at]) * (prices[count] - prices[buy_at])
buy_at = -1
else
buy_at = count
end
end
count += 1
end
puts curr_money | n = gets().chomp().to_i
prices = gets().chomp().split(' ').map(&:to_i)
curr_money = 1000
buy_at, count = -1, 0
while count < n do
if buy_at == -1
buy_at = count
else
if prices[buy_at] < prices[count]
curr_money += (curr_money / prices[buy_at]) * (prices[count] - prices[buy_at])
buy_at = count
else
buy_at = count
end
end
count += 1
end
puts curr_money | [
"assignment.value.change",
"expression.operation.unary.remove"
] | 308,562 | 308,563 | u261436664 | ruby |
p02603 | N = gets.to_i
A = gets.split.map(&:to_i)
stock = 0
ans = 1000
(N-1).times do |i|
if (A[i] < A[i+1])
stock = ans / A[i]
ans %= A[i]
elsif (A[i] > A[i+1])
ans += stock * A[i]
stock = 0
end
end
puts (ans + stock * A.last) | N = gets.to_i
A = gets.split.map(&:to_i)
stock = 0
ans = 1000
(N-1).times do |i|
if (A[i] < A[i+1] && stock == 0)
stock = ans / A[i]
ans %= A[i]
elsif (A[i] > A[i+1])
ans += stock * A[i]
stock = 0
end
end
puts (ans + stock * A.last) | [
"control_flow.branch.if.condition.change"
] | 308,574 | 308,575 | u616360029 | ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.