Datasets:

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
8 values
p02603
n = gets.to_i a = gets.split.map(&:to_i) cash = 1000 stock = 0 0.upto(n-2){|i| if a[i] < a[i+1] stock = cash/a[i] cash -= stock*a[i] end if a[i] > a[i+1] cash += stock*a[i] stock = 0 end } if stock!=0 cash += stock*a[n-1] stock = 0 end p cash
n = gets.to_i a = gets.split.map(&:to_i) cash = 1000 stock = 0 0.upto(n-2){|i| if a[i] < a[i+1] && stock == 0 stock = cash/a[i] cash -= stock*a[i] end if a[i] > a[i+1] cash += stock*a[i] stock = 0 end } if stock!=0 cash += stock*a[n-1] stock = 0 end p cash
[ "control_flow.branch.if.condition.change" ]
308,703
308,704
u679291177
ruby
p02603
n = gets.to_i a = gets.split.map(&:to_i) money = 1000 stock = 0 n.times do |idx| current = a[idx] if idx.zero? if a[idx+1] > current stock, money = money.divmod(current) end elsif idx == n - 1 money += stock * current stock = 0 else if a[idx+1] < current money += stock * current stock = 0 elsif a[idx+1] > current stock, money = money.divmod(current) end end end puts money
n = gets.to_i a = gets.split.map(&:to_i) money = 1000 stock = 0 n.times do |idx| current = a[idx] if idx.zero? if a[idx+1] > current stock, money = money.divmod(current) end elsif idx == n - 1 money += stock * current stock = 0 else if a[idx+1] < current money += stock * current stock = 0 elsif a[idx+1] > current && money >= current stock, money = money.divmod(current) end end end puts money
[ "control_flow.branch.if.condition.change" ]
309,213
309,214
u604352408
ruby
p02603
n = gets.to_i a = gets.split.map(&:to_i) money = 1000 stock = 0 n.times do |idx| current = a[idx] if idx.zero? if a[idx+1] > current stock, money = money.divmod(current) end elsif idx == n - 1 money += stock * current stock = 0 else if a[idx-1] <= current && a[idx+1] < current money += stock * current stock = 0 elsif a[idx-1] >= current && a[idx+1] > current stock, money = money.divmod(current) end end end puts money
n = gets.to_i a = gets.split.map(&:to_i) money = 1000 stock = 0 n.times do |idx| current = a[idx] if idx.zero? if a[idx+1] > current stock, money = money.divmod(current) end elsif idx == n - 1 money += stock * current stock = 0 else if a[idx-1] <= current && a[idx+1] < current money += stock * current stock = 0 elsif a[idx-1] >= current && a[idx+1] > current && money >= current stock, money = money.divmod(current) end end end puts money
[ "control_flow.branch.if.condition.change" ]
309,215
309,216
u604352408
ruby
p02606
L, R, d = gets.split.map(&:to_i) puts d==1 ? R/d - L/d + 1 : R/d - L/d
L, R, d = gets.split.map(&:to_i) puts L%d==0 ? R/d - L/d + 1 : R/d - L/d
[ "control_flow.branch.if.condition.change", "literal.number.integer.change" ]
309,613
309,614
u635857549
ruby
p02606
l, r, d = gets.chomp.split(' ').map(&:to_i) count = 0 (l..r).each { |i| count + i % d == 0 ? 1 : 0 } puts count
l, r, d = gets.chomp.split(' ').map(&:to_i) count = 0 (l..r).each { |i| count += i % d == 0 ? 1 : 0 } puts count
[ "assignment.compound.arithmetic.replace.add", "expression.operator.arithmetic.replace.remove", "control_flow.branch.if.condition.change" ]
309,615
309,616
u857510905
ruby
p02606
l,r,d = gets.split.map(&:to_i) puts (r / d) - (l / d)
l,r,d = gets.split.map(&:to_i) puts (r / d) - ((l - 1) / d)
[ "call.arguments.change" ]
309,894
309,895
u392423112
ruby
p02606
l, r, d = gets.split.map(&:to_i) ans = 0 (l..r).each do |i| ans += 1 if i % 2 == 0 end p ans
l, r, d = gets.split.map(&:to_i) ans = 0 (l..r).each do |i| ans += 1 if i % d == 0 end p ans
[ "identifier.replace.add", "literal.replace.remove", "control_flow.branch.if.condition.change" ]
310,410
310,411
u011809316
ruby
p02606
l, r, d = gets.chomp.split.map(&:to_i) puts(r / d - l / d)
l, r, d = gets.chomp.split.map(&:to_i) puts(r / d - (l-1) / d)
[ "call.arguments.change" ]
310,464
310,465
u630185395
ruby
p02607
n=gets.to_i array = gets.split.map(&:to_i) c=0 (0..n-1).each do |i| if i.odd? && array[i].odd? c += 1 end end puts c
n=gets.to_i array = gets.split.map(&:to_i) c=0 (0..n-1).each do |i| if (i+1).odd? && array[i].odd? c += 1 end end puts c
[ "control_flow.branch.if.condition.change" ]
310,811
310,812
u575740023
ruby
p02607
n = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each.with_index(1) do |i, k| count+=1 if k.odd? && i.odd? puts k end puts count
n = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each.with_index(1) do |i, k| count+=1 if k.odd? && i.odd? end puts count
[ "call.remove" ]
311,103
311,104
u514143079
ruby
p02607
n = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each_with_index do |i, k| count+=1 if k.odd? && i.odd? end puts count
n = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each.with_index(1) do |i, k| count+=1 if k.odd? && i.odd? end puts count
[ "identifier.change", "call.add" ]
311,105
311,104
u514143079
ruby
p02607
N = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each_with_index do |k, i| if i.odd? && k.odd? count += 1 end end puts count
N = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each_with_index do |k, i| if (i+1).odd? && k.odd? count += 1 end end puts count
[ "control_flow.branch.if.condition.change" ]
311,660
311,661
u684458716
ruby
p02607
gets arr = gets.chomp.split.map!(&:to_i) arr = arr.select.with_index{|v, i| (i % 2 == 1) && (v % 2 == 0)} puts arr.size
gets arr = gets.chomp.split.map!(&:to_i) arr = arr.select.with_index{|v, i| (i % 2 == 0) && (v % 2 == 1)} puts arr.size
[ "literal.number.integer.change", "assignment.value.change", "expression.operation.binary.change" ]
311,721
311,722
u308800285
ruby
p02607
gets arr = gets.chomp.split.map!(&:to_i) arr = arr.select.with_index{|v, i| (i % 2 == 1) && (v % 2 == 1)} puts arr.size
gets arr = gets.chomp.split.map!(&:to_i) arr = arr.select.with_index{|v, i| (i % 2 == 0) && (v % 2 == 1)} puts arr.size
[ "literal.number.integer.change", "assignment.value.change", "expression.operation.binary.change" ]
311,723
311,722
u308800285
ruby
p02607
n = gets.chomp.to_i a = gets.chomp.split(' ').map(&:to_i) arr = [] i = 1 while i <= n arr << [i,a[i-1]] i += 1 end # p arr # count c = 0 i = 0 while i < n if (a[i]%2 != 0) && (a[i][1]%2 !=0) c += 1 end i += 1 end puts c
n = gets.chomp.to_i a = gets.chomp.split(' ').map(&:to_i) arr = [] i = 1 while i <= n arr << [i,a[i-1]] i += 1 end # p arr # count c = 0 i = 0 while i < n if (arr[i][0]%2 != 0) && (arr[i][1]%2 !=0) # p "a[][]:#{a[i]}" c += 1 end i += 1 end puts c
[ "identifier.change", "control_flow.branch.if.condition.change" ]
311,976
311,977
u847977106
ruby
p02607
N = gets.to_i p gets.split.map(&:to_i).map.with_index.count{|i,idx| (idx+1)%3==1 && i%2==1}
N = gets.to_i p gets.split.map(&:to_i).map.with_index.count{|i,idx| (idx+1)%2==1 && i%2==1}
[ "literal.number.integer.change", "call.arguments.change", "expression.operation.binary.change" ]
312,187
312,188
u009976559
ruby
p02607
N = gets.to_i p gets.split.map(&:to_i).map.with_index.count{|i,idx| idx%2==1 && i%2==1}
N = gets.to_i p gets.split.map(&:to_i).map.with_index.count{|i,idx| (idx+1)%2==1 && i%2==1}
[ "call.arguments.change" ]
312,189
312,188
u009976559
ruby
p02607
n = gets.to_i nums = gets.split(' ').map(&:to_i) count = 0 i = 1 nums.each do |num| i += 1 count += 1 if i.odd? && num.odd? end p count
n = gets.to_i nums = gets.split(' ').map(&:to_i) count = 0 i = 0 nums.each do |num| i += 1 count += 1 if i.odd? && num.odd? end p count
[ "literal.number.integer.change", "assignment.value.change" ]
312,363
312,364
u046160726
ruby
p02607
### 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 a = gets.split.map(&:to_i) count = 0 a.each_with_index do |data,i| if data % 2 == 1 && i % 2 == 1 count += 1 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 n = gets.to_i a = gets.split.map(&:to_i) count = 0 a.each_with_index do |data,i| if data % 2 == 1 && (i+1) % 2 == 1 count += 1 end end puts count
[ "control_flow.branch.if.condition.change" ]
312,656
312,657
u219902564
ruby
p02607
n,*A=$<.read.split.map &:to_i p n.times.count{|i|i%2==1&&A[i]%2==1}
n,*A=$<.read.split.map &:to_i p n.times.count{|i|i%2==0&&A[i]%2==1}
[ "literal.number.integer.change", "call.arguments.change", "expression.operation.binary.change" ]
313,030
313,031
u019489252
ruby
p02608
N = gets.to_i count = Array.new(N+1, 0) #puts count (1..32).each { |x| (1..32).each { |y| (1..32).each { |z| sum = x*x + y*y + z*z + x*y + y*z + z*x break if sum > N count[sum] += 1 } } } puts count[1,N]
N = gets.to_i count = Array.new(N+1, 0) #puts count (1..100).each { |x| (1..100).each { |y| (1..100).each { |z| sum = x*x + y*y + z*z + x*y + y*z + z*x break if sum > N count[sum] += 1 } } } puts count[1,N]
[ "literal.number.integer.change" ]
313,707
313,708
u635857549
ruby
p02608
N = gets.to_i count = Array.new(N, 0) #puts count (1..32).each { |x| (1..32).each { |y| (1..32).each { |z| sum = x*x + y*y + z*z + x*y + y*z + z*x break if sum > N count[sum] += 1 } } } puts count[1,N]
N = gets.to_i count = Array.new(N+1, 0) #puts count (1..100).each { |x| (1..100).each { |y| (1..100).each { |z| sum = x*x + y*y + z*z + x*y + y*z + z*x break if sum > N count[sum] += 1 } } } puts count[1,N]
[ "literal.number.integer.change" ]
313,709
313,708
u635857549
ruby
p02608
N = gets.chomp.to_i ans = Array.new(10_000, 0) n = Math.sqrt(1000) (1..n).each do |x| (1..n).each do |y| (1..n).each do |z| v = x**2 + y**2 + z**2 + x * y + y * z + x * z ans[v] += 1 if v < 10_000 end end end (1..N).each do |i| puts ans[i] end
N = gets.chomp.to_i ans = Array.new(10_050, 0) n = Math.sqrt(10_050) (1..n).each do |x| (1..n).each do |y| (1..n).each do |z| v = x**2 + y**2 + z**2 + x * y + y * z + x * z ans[v] += 1 if v < 10_050 end end end (1..N).each do |i| puts ans[i] end
[ "literal.number.integer.change", "assignment.value.change", "call.arguments.change", "control_flow.branch.if.condition.change" ]
313,758
313,757
u526771595
ruby
p02608
n = gets.to_i ans = Array.new(10**4 + 1, 0) ## x <= y <= zとする。 max_x = Math.sqrt(n/6).to_i max_y = Math.sqrt(n/3).to_i max_z = Math.sqrt(n).to_i (1..max_x).each do |x| (x..max_y).each do |y| (y..max_z).each do |z| result = x**2 + y**2 + z**2 + x*y + y*z + z*x break if result > n if x != y && y != z plus_cnt = 6 elsif x != z && (x == y || y == z) plus_cnt = 3 else x == z plus_cnt = 6 end ans[result] += plus_cnt if result <= n end end end (1..n).each do |i| puts ans[i] end
n = gets.to_i ans = Array.new(10**4 + 1, 0) ## x <= y <= zとする。 max_x = Math.sqrt(n/6).to_i max_y = Math.sqrt(n/3).to_i max_z = Math.sqrt(n).to_i (1..max_x).each do |x| (x..max_y).each do |y| (y..max_z).each do |z| result = x**2 + y**2 + z**2 + x*y + y*z + z*x break if result > n if x != y && y != z plus_cnt = 6 elsif x != z && (x == y || y == z) plus_cnt = 3 else x == z plus_cnt = 1 end ans[result] += plus_cnt if result <= n end end end (1..n).each do |i| puts ans[i] end
[ "literal.number.integer.change", "assignment.value.change" ]
313,869
313,870
u001859537
ruby
p02608
n = gets.to_i ans = Array.new(n+1, 0) ## x <= y <= zとする。 max_x = Math.sqrt(n/6).to_i + 1 max_y = Math.sqrt(n/3).to_i + 1 max_z = Math.sqrt(n).to_i + 1 (1..max_x).each do |x| (x..max_y).each do |y| (y..max_z).each do |z| result = x**2 + y**2 + z**2 + x*y + y*z + z*x if x == y && x == z plus_cnt = 1 elsif x == y || y == z || z == x plus_cnt = 3 else plus_cnt = 6 end ans[result] += plus_cnt end end end (1..n).each do |i| puts ans[i] end
n = gets.to_i ans = Array.new(10**5, 0) ## x <= y <= zとする。 max_x = Math.sqrt(n/6).to_i + 1 max_y = Math.sqrt(n/3).to_i + 1 max_z = Math.sqrt(n).to_i + 1 (1..max_x).each do |x| (x..max_y).each do |y| (y..max_z).each do |z| result = x**2 + y**2 + z**2 + x*y + y*z + z*x if x == y && x == z plus_cnt = 1 elsif x == y || y == z || z == x plus_cnt = 3 else plus_cnt = 6 end ans[result] += plus_cnt end end end (1..n).each do |i| puts ans[i] end
[]
313,871
313,872
u001859537
ruby
p02608
num = gets.to_i # (x,y,z) = (99,1,1) loop_count = 99 ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result] += 1 end end end end ans.each do |a| puts a end
num = gets.to_i loop_count = 99 # (x,y,z) = (99,1,1) ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result-1] += 1 end end end end ans.each do |a| puts a end
[ "expression.operation.binary.add" ]
314,424
314,425
u046160726
ruby
p02608
num = gets.to_i # 6*(x*x)>10000 になるxの最小値が41 loop_count = 41 ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result] += 1 end end end end ans.each do |a| puts a end
num = gets.to_i loop_count = 99 # (x,y,z) = (99,1,1) ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result-1] += 1 end end end end ans.each do |a| puts a end
[ "literal.number.integer.change", "assignment.value.change" ]
314,426
314,425
u046160726
ruby
p02608
num = gets.to_i # 6*(x*x)>10000 になるxの最小値が41 loop_count = 41 ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result] += 1 end end end end ans.each do |a| p a end
num = gets.to_i loop_count = 99 # (x,y,z) = (99,1,1) ans = Array.new(num, 0) for x in 1..loop_count do for y in 1..loop_count do for z in 1..loop_count do result = (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (z*x) if result <= num ans[result-1] += 1 end end end end ans.each do |a| puts a end
[ "literal.number.integer.change", "assignment.value.change", "call.function.change", "io.output.change" ]
314,427
314,425
u046160726
ruby
p02608
def f(xyz) xyz[0]*xyz[0] + xyz[1]*xyz[1] + xyz[2]*xyz[2] + xyz[0]*xyz[1] + xyz[1]*xyz[2] + xyz[2]*xyz[0] end def countCombination(xyz) c = xyz.uniq.size if c == 1 then return 1 elsif c == 2 then return 3 else return 6 end end n = gets.chomp.to_i MAX = 1000000 ans = Array.new(MAX, 0) [*1..50].repeated_combination(3) do |xyz| ans[f(xyz)] += countCombination(xyz) end (1..n).each do |i| puts ans[i] end
def f(xyz) xyz[0]*xyz[0] + xyz[1]*xyz[1] + xyz[2]*xyz[2] + xyz[0]*xyz[1] + xyz[1]*xyz[2] + xyz[2]*xyz[0] end def countCombination(xyz) c = xyz.uniq.size if c == 1 then return 1 elsif c == 2 then return 3 else return 6 end end n = gets.chomp.to_i MAX = 1000000 ans = Array.new(MAX, 0) [*1..300].repeated_combination(3) do |xyz| ans[f(xyz)] += countCombination(xyz) end (1..n).each do |i| puts ans[i] end
[ "literal.number.integer.change" ]
314,554
314,555
u466332671
ruby
p02608
n = gets.to_i ary = [] n.times{ ary << 0 } (1..45).each do |i| (1..45).each do |j| (1..45).each do |k| check = i*i + j*j + k*k + i*j + j*k + i*k next if check > n ary[check-1] += 1 end end end puts ary
n = gets.to_i ary = [] n.times{ ary << 0 } (1..100).each do |i| (1..100).each do |j| (1..100).each do |k| check = i*i + j*j + k*k + i*j + j*k + i*k next if check > n ary[check-1] += 1 end end end puts ary
[ "literal.number.integer.change" ]
314,778
314,779
u011809316
ruby
p02608
N = gets.to_i a = [] (1..57).each{ |x| (1..57).each{ |y| (1..57).each{ |z| n = x**2 + y**2 + z**2 + x*y + y*z + z*x a.push n } } } a2 = a.group_by{|n| n} (1..N).each{ |n| puts a2.fetch(n, []).size }
N = gets.to_i #max = 57 max = 100 a = [] (1..max).each{ |x| (1..max).each{ |y| (1..max).each{ |z| n = x**2 + y**2 + z**2 + x*y + y*z + z*x a.push n } } } a2 = a.group_by{|n| n} (1..N).each{ |n| puts a2.fetch(n, []).size }
[ "identifier.replace.add", "literal.replace.remove" ]
315,131
315,132
u810064020
ruby
p02608
n = gets.chomp.to_i hash = {} (1..31).each do |x| (1..31).each do |y| (1..31).each do |z| count = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x hash[count] ||= 0 hash[count] += 1 end end end (1..n).each do |i| puts hash[i].to_i end
n = gets.chomp.to_i hash = {} (1..100).each do |x| (1..100).each do |y| (1..100).each do |z| count = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x hash[count] ||= 0 hash[count] += 1 end end end (1..n).each do |i| puts hash[i].to_i end
[ "literal.number.integer.change" ]
315,211
315,212
u257668305
ruby
p02608
n = gets.to_i ans = Array.new(n,0) for i in 1..100 for j in 1..100 for k in 1..100 x = i**2 + j**2 + k**2 + i*j + j*k + k*i if x >= 1 && x <= n ans[x] += 1 end end end end puts ans
n = gets.to_i ans = Array.new(n,0) for i in 1..100 for j in 1..100 for k in 1..100 x = i**2 + j**2 + k**2 + i*j + j*k + k*i if x >= 1 && x <= n ans[x-1] += 1 end end end end puts ans
[ "expression.operation.binary.add" ]
315,671
315,672
u911373146
ruby
p02609
gets; k = gets.strip c = k.count('1') ki = k.to_i(2) kr = k.reverse df1, df2 = ki % (c+1), (c == 1 ? 0 : ki % (c-1)) t1, t2 = 1, -1 def calc(x) ret = 1 while x != 0 ret += 1 x %= x.to_s(2).count('1') end return ret end kr.chars.map{|i| ans = 0 if i == '0' ans = calc((df1+t1+c+1) % (c+1)) elsif c == 1 ans = 1 else ans = calc((df2+t2+c-1) % (c-1)) end t1 = t1 * 2 % (c+1) t2 = t2 * 2 % (c-1) if c != 1 ans }.reverse.each{|x|p x}
gets; k = gets.strip c = k.count('1') ki = k.to_i(2) kr = k.reverse df1, df2 = ki % (c+1), (c == 1 ? 0 : ki % (c-1)) t1, t2 = 1, -1 def calc(x) ret = 1 while x != 0 ret += 1 x %= x.to_s(2).count('1') end return ret end kr.chars.map{|i| ans = 0 if i == '0' ans = calc((df1+t1+c+1) % (c+1)) elsif c == 1 ans = 0 else ans = calc((df2+t2+c-1) % (c-1)) end t1 = t1 * 2 % (c+1) t2 = t2 * 2 % (c-1) if c != 1 ans }.reverse.each{|x|p x}
[ "literal.number.integer.change", "assignment.value.change" ]
315,768
315,769
u309985845
ruby
p02609
gets; k = gets c = k.count('1') ki = k.to_i(2) kr = k.reverse df1, df2 = ki % (c+1), (c == 1 ? 0 : ki % (c-1)) t1, t2 = 1, -1 def calc(x) ret = 1 while x != 0 ret += 1 x %= x.to_s(2).count('1') end return ret end kr.chars.map{|i| ans = 0 if i == '0' ans = calc((df1+t1+c+1) % (c+1)) elsif c == 1 ans = 1 else ans = calc((df2+t2+c-1) % (c-1)) end t1 = t1 * 2 % (c+1) t2 = t2 * 2 % (c-1) if c != 1 ans }.reverse.each{|x|p x}
gets; k = gets.strip c = k.count('1') ki = k.to_i(2) kr = k.reverse df1, df2 = ki % (c+1), (c == 1 ? 0 : ki % (c-1)) t1, t2 = 1, -1 def calc(x) ret = 1 while x != 0 ret += 1 x %= x.to_s(2).count('1') end return ret end kr.chars.map{|i| ans = 0 if i == '0' ans = calc((df1+t1+c+1) % (c+1)) elsif c == 1 ans = 0 else ans = calc((df2+t2+c-1) % (c-1)) end t1 = t1 * 2 % (c+1) t2 = t2 * 2 % (c-1) if c != 1 ans }.reverse.each{|x|p x}
[ "call.add", "literal.number.integer.change", "assignment.value.change" ]
315,770
315,769
u309985845
ruby
p02609
N = gets.to_i X = gets.chomp # N = 2 * 10**5 # X = "1"*(N-1) + "0" xcnt = X.count('1') @fmap = { 0 => 0, 1 => 1 } def popcount(x) m1 = 0x55555555 m2 = 0x33333333 m4 = 0x0f0f0f0f x -= (x >> 1) & m1 x = (x & m2) + ((x >> 2) & m2) x = (x + (x >> 4)) & m4 x += x >> 8 return (x + (x >> 16)) & 0x3f end def f x return @fmap[x] if @fmap[x] != nil pc = popcount(x) if pc == 0 return @fmap[x] = 0 end m = x % pc unless @fmap[m] @fmap[m] = f(m) end @fmap[x] = @fmap[m] + 1 end pdiff = 1 mdiff = 1 intx = X.to_i(2) xar = X.split('').reverse pl_mod = intx % (xcnt + 1) mi_mod = false if xcnt > 1 mi_mod = intx % (xcnt - 1) end results = xar.map do |i| mo = nil if i == "0" mo = (pl_mod + pdiff) % (xcnt + 1) elsif !mi_mod next 0 else mo = (mi_mod - mdiff) % (xcnt - 1) end next f(mo) + 1 ensure pdiff = (pdiff * 2) % (xcnt + 1) mdiff = (mdiff * 2) % (xcnt - 1) end puts results.reverse.join("\n")
N = gets.to_i X = gets.chomp # N = 2 * 10**5 # X = "1"*(N-1) + "0" xcnt = X.count('1') @fmap = { 0 => 0, 1 => 1 } def popcount(x) m1 = 0x55555555 m2 = 0x33333333 m4 = 0x0f0f0f0f x -= (x >> 1) & m1 x = (x & m2) + ((x >> 2) & m2) x = (x + (x >> 4)) & m4 x += x >> 8 return (x + (x >> 16)) & 0x3f end def f x return @fmap[x] if @fmap[x] != nil pc = popcount(x) if pc == 0 return @fmap[x] = 0 end m = x % pc unless @fmap[m] @fmap[m] = f(m) end @fmap[x] = @fmap[m] + 1 end pdiff = 1 mdiff = 1 intx = X.to_i(2) xar = X.split('').reverse pl_mod = intx % (xcnt + 1) mi_mod = false if xcnt > 1 mi_mod = intx % (xcnt - 1) end results = xar.map do |i| mo = nil if i == "0" mo = (pl_mod + pdiff) % (xcnt + 1) elsif !mi_mod next 0 else mo = (mi_mod - mdiff) % (xcnt - 1) end next f(mo) + 1 ensure pdiff = (pdiff * 2) % (xcnt + 1) mdiff = (mdiff * 2) % (xcnt - 1) if mi_mod end puts results.reverse.join("\n")
[]
315,926
315,927
u299761130
ruby
p02609
n = gets.to_i x = gets.chomp.chars pc = x.count("1") ur = [] lr = [] ut = 1 lt = -1 n.times do ut %= pc + 1 ur.unshift(ut) ut <<= 1 if pc - 1 > 0 lt %= pc - 1 lr.unshift(lt) lt <<= 1 end end rl = x[0].to_i ru = x[0].to_i 1.step(n - 1) do |i| t = x[i] if pc - 1 > 0 rl <<= 1 rl += t.to_i rl %= pc - 1 end ru <<= 1 ru += t.to_i ru %= pc + 1 end n.times do |i| res = 1 if x[i] == "0" t = (ur[i] + ru) % (pc + 1) elsif pc - 1 == 0 puts "0" else t = (lr[i] + rl) % (pc - 1) end while t > 0 t %= ("%b" % [t]).count("1") res += 1 end puts res end
n = gets.to_i x = gets.chomp.chars pc = x.count("1") ur = [] lr = [] ut = 1 lt = -1 n.times do ut %= pc + 1 ur.unshift(ut) ut <<= 1 if pc - 1 > 0 lt %= pc - 1 lr.unshift(lt) lt <<= 1 end end rl = x[0].to_i ru = x[0].to_i 1.step(n - 1) do |i| t = x[i] if pc - 1 > 0 rl <<= 1 rl += t.to_i rl %= pc - 1 end ru <<= 1 ru += t.to_i ru %= pc + 1 end n.times do |i| res = 1 if x[i] == "0" t = (ur[i] + ru) % (pc + 1) elsif pc - 1 == 0 puts "0" next else t = (lr[i] + rl) % (pc - 1) end while t > 0 t %= ("%b" % [t]).count("1") res += 1 end puts res end
[]
315,943
315,944
u482840940
ruby
p02609
class Integer def popcount to_s(2).count('1') end end def f(n) c = 0 while n > 0 n %= n.popcount c += 1 end c end def modpow(base, n, mod) result = 1 while n > 0 if n.odd? result = result * base % mod end base = (base * base) % mod n /= 2 end result % mod end n = gets.to_i x = gets.chomp x_int = x.to_i(2) base_popcount = x.count('1') mod_zero = x_int % (base_popcount + 1) mod_one = x_int % (base_popcount - 1) unless base_popcount == 0 0.upto(n - 1) do |index| if x[index] == '1' && base_popcount == 1 puts 0 next end shift = n - index - 1 mod = if x[index] == '0' popcount = base_popcount + 1 (mod_zero + modpow(2, shift, popcount)) % popcount else popcount = base_popcount - 1 (mod_one - modpow(2, shift, popcount)) % popcount end puts f(mod) + 1 end
class Integer def popcount to_s(2).count('1') end end def f(n) c = 0 while n > 0 n %= n.popcount c += 1 end c end def modpow(base, n, mod) result = 1 while n > 0 if n.odd? result = result * base % mod end base = (base * base) % mod n /= 2 end result % mod end n = gets.to_i x = gets.chomp x_int = x.to_i(2) base_popcount = x.count('1') mod_zero = x_int % (base_popcount + 1) mod_one = x_int % (base_popcount - 1) unless base_popcount == 1 0.upto(n - 1) do |index| if x[index] == '1' && base_popcount == 1 puts 0 next end shift = n - index - 1 mod = if x[index] == '0' popcount = base_popcount + 1 (mod_zero + modpow(2, shift, popcount)) % popcount else popcount = base_popcount - 1 (mod_one - modpow(2, shift, popcount)) % popcount end puts f(mod) + 1 end
[ "literal.number.integer.change", "expression.operation.binary.change" ]
316,163
316,164
u158406393
ruby
p02609
END { load __FILE__ unless $stdin.eof? } n = gets.to_i x = gets.chomp.chars.map!(&:to_i) c = x.count(1) c0 = c + 1 m0 = x.inject(0) { |result, bit| (result * 2 + bit) % c0 } c1 = c - 1 m1 = x.inject(0) { |result, bit| (result * 2 + bit) % c1 } if c1 > 0 y0 = 1 y1 = 1 x = x.reverse!.map! do |xi| xi = ( if xi == 0 (m0 + y0) % c0 else (m1 - y1) % c1 if c1 > 0 end ) y0 = y0 * 2 % c0 y1 = y1 * 2 % c1 xi end.reverse! $table = [0] def f(num) $table[num] ||= f(num % num.digits(2).count(1)) + 1 end x.each { |xi| puts xi ? f(xi) + 1 : 0 }
END { load __FILE__ unless $stdin.eof? } n = gets.to_i x = gets.chomp.chars.map!(&:to_i) c = x.count(1) c0 = c + 1 m0 = x.inject(0) { |result, bit| (result * 2 + bit) % c0 } c1 = c - 1 m1 = x.inject(0) { |result, bit| (result * 2 + bit) % c1 } if c1 > 0 y0 = 1 y1 = 1 x = x.reverse!.map! do |xi| xi = ( if xi == 0 (m0 + y0) % c0 else (m1 - y1) % c1 if c1 > 0 end ) y0 = y0 * 2 % c0 y1 = y1 * 2 % c1 if c1 > 0 xi end.reverse! $table = [0] def f(num) $table[num] ||= f(num % num.digits(2).count(1)) + 1 end x.each { |xi| puts xi ? f(xi) + 1 : 0 }
[]
316,533
316,534
u960319975
ruby
p02612
n = gets.chomp.to_i #p n ans = n % 1000 ans == 0 ? 0 : 1000 - ans p ans
n = gets.chomp.to_i #p n ans = n % 1000 ans = ans == 0 ? 0 : 1000 - ans p ans
[ "assignment.add" ]
316,922
316,923
u341702138
ruby
p02612
rest = gets.to_i % 1000 p rest == 0 ? 0 : rest
rest = gets.to_i % 1000 p rest == 0 ? 0 : 1000-rest
[ "expression.operation.binary.add" ]
316,949
316,950
u458429268
ruby
p02612
rest = gets.to_i % 1000 p rest == 0 ? 0 : rest
rest = gets.to_i % 1000 p rest == 0 ? 0 : 1000-rest
[ "expression.operation.binary.add" ]
316,951
316,950
u458429268
ruby
p02612
n = gets.chomp.to_i puts 1000*(n/1000).ceil - n
n = gets.chomp.to_i puts 1000*(n/1000.0).ceil - n
[ "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
317,199
317,200
u358554431
ruby
p02608
N = gets.to_i $counts = [0] * (N + 1) def add(x, y, z) n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if n <= N + 1 # puts "n=#{n}, #{x}, #{y}, #{z}" $counts[n] += 1 false else # puts "over, n=#{n}, #{x}, #{y}, #{z}" true end end max = 100 (1..max).each do |x| (1..max).each do |y| (1..max).each do |z| add(x, y, z) end end end puts $counts[1..-1]
N = gets.to_i $counts = [0] * (N + 1) def add(x, y, z) n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if n <= N # puts "n=#{n}, #{x}, #{y}, #{z}" $counts[n] += 1 false else # puts "over, n=#{n}, #{x}, #{y}, #{z}" true end end max = 100 (1..max).each do |x| (1..max).each do |y| (1..max).each do |z| add(x, y, z) end end end puts $counts[1..-1]
[ "expression.operation.binary.remove" ]
318,180
318,181
u447268473
ruby
p02612
n = gets.to_i realn = n % 1000 ans = 1000 - realn if ans == 1000 puts n else puts ans end
n = gets.to_i realn = n % 1000 ans = 1000 - realn if ans == 1000 p 0 else p ans end
[ "identifier.change" ]
318,535
318,536
u945412921
ruby
p02612
n=gets.to_i p 1000-n%1000
n=gets.to_i p (1000-n%1000)%1000
[ "call.arguments.change" ]
318,539
318,540
u771630380
ruby
p02612
n=gets.to_i p n%1000
n=gets.to_i p (1000-n%1000)%1000
[ "expression.operation.binary.add" ]
318,541
318,540
u771630380
ruby
p02612
i=gets.to_i;puts i%1000?(1000-i%1000):0
i=gets.to_i;puts i%1000!=0?(1000-i%1000):0
[ "control_flow.branch.if.condition.change" ]
318,695
318,696
u926080943
ruby
p02612
N = gets.to_i unless N%1000 == 0 puts (N % 1000) - 1000 else puts 0 end
N = gets.to_i if N%1000 != 0 puts ((N % 1000) - 1000).abs else puts 0 end
[ "misc.opposites", "expression.operator.compare.change", "expression.operation.binary.change", "call.arguments.change", "call.add" ]
318,833
318,834
u802039083
ruby
p02612
N = gets.to_i if (N % 1000) != 0 puts (N % 1000) - 1000 else puts 0 end
N = gets.to_i if N%1000 != 0 puts ((N % 1000) - 1000).abs else puts 0 end
[ "control_flow.branch.if.condition.change", "call.arguments.change", "call.add" ]
318,835
318,834
u802039083
ruby
p02612
a = gets.to_i while a >= 1000 do a = a-1000 end p a
a = gets.to_i while a > 0 do a = a-1000 end p a.abs
[ "call.add" ]
319,479
319,480
u599631096
ruby
p02612
n = gets.to_i return 0 if n % 1000 == 0 return 1000 - ((n + 1000) % 1000)
n = gets.to_i return puts(0) if n % 1000 == 0 return puts(1000 - ((n + 1000) % 1000))
[ "call.add", "call.arguments.change", "function.return_value.change" ]
319,590
319,589
u866614353
ruby
p02612
syouhin = gets.chomp.to_i if syouhin%1000 puts 0 exit else puts 1000-(syouhin%1000) end
syouhin = gets.chomp.to_i if syouhin%1000 == 0 puts 0 exit else puts 1000-(syouhin%1000) end
[ "control_flow.branch.if.condition.change" ]
319,807
319,808
u320123708
ruby
p02612
p gets.to_i%1000
p (100000-gets.to_i)%1000
[ "call.arguments.change" ]
320,113
320,114
u079330987
ruby
p02612
s=gets.to_i print 1000-s%1000
s=gets.to_i print (1000-s%1000)%1000
[ "call.arguments.change" ]
320,344
320,345
u702482655
ruby
p02613
patarn = ['AC', 'WA', 'TLE', 'RE'] input = [] n = gets.chomp.to_i n.times{input << gets.chomp} patarn.each do |judge| puts "#{judge} × #{input.count(judge)}" end
patarn = ['AC', 'WA', 'TLE', 'RE'] input = [] n = gets.chomp.to_i n.times{input << gets.chomp} patarn.each do |judge| puts "#{judge} x #{input.count(judge)}" end
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
320,566
320,567
u718435392
ruby
p02613
n = gets.chomp.to_i #p n s = readlines.map(&:chomp) #p s ac = 0 wa = 0 tle = 0 re = 0 n.times{ |i| if s[i] == 'AC' ac += 1 elsif s[i] == 'WA' wa +=1 elsif s[i] == 'TLE' tle += 1 elsif s[i] == 'RE' re += 1 end } p "AC x #{ac}" p "WA x #{wa}" p "TLE x #{tle}" p "RE x #{re}"
n = gets.chomp.to_i #p n s = readlines.map(&:chomp) #p s ac = 0 wa = 0 tle = 0 re = 0 n.times{ |i| if s[i] == 'AC' ac += 1 elsif s[i] == 'WA' wa +=1 elsif s[i] == 'TLE' tle += 1 elsif s[i] == 'RE' re += 1 end } puts "AC x #{ac}" puts "WA x #{wa}" puts "TLE x #{tle}" puts "RE x #{re}"
[ "call.function.change", "io.output.change" ]
320,932
320,933
u341702138
ruby
p02613
ac = 0 wa = 0 tle = 0 re = 0 input_list = Array.new while line = gets input_list << line.chomp! # 改行を削除 end input_list.each do |input| case input when "AC" ac +=1 when "WA" wa +=1 when "TLE" tle +=1 when "RE" re +=1 else end end p "AC x #{ac}" p "WA x #{wa}" p "TLE x #{tle}" p "RE x #{re}"
ac = 0 wa = 0 tle = 0 re = 0 input_list = Array.new while line = gets input_list << line.chomp! # 改行を削除 end input_list.each do |input| case input when "AC" ac +=1 when "WA" wa +=1 when "TLE" tle +=1 when "RE" re +=1 else end end puts "AC x #{ac}" puts "WA x #{wa}" puts "TLE x #{tle}" puts "RE x #{re}"
[ "call.function.change", "io.output.change" ]
320,824
320,825
u589257616
ruby
p02613
gets s = readlines.map(&:chomp).tally ["AC", "WA", "TLE", "RE"].each do |w| puts "#{w} × #{s[w] || 0}" end
gets s = readlines.map(&:chomp).tally ["AC", "WA", "TLE", "RE"].each do |w| puts "#{w} x #{s[w] || 0}" end
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
321,346
321,347
u658910570
ruby
p02613
gets s = readlines.map(&:chomp).tally ["AC", "TLE", "WA", "RE"].each do |w| puts "#{w} × #{s[w] || 0}" end
gets s = readlines.map(&:chomp).tally ["AC", "WA", "TLE", "RE"].each do |w| puts "#{w} x #{s[w] || 0}" end
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
321,348
321,347
u658910570
ruby
p02613
dic = {'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 } N = gets.to_i 1.times do s = gets.chomp dic[s] += 1 end dic.each_pair do |key, val| puts "#{key} x #{val}" end
dic = {'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 } N = gets.to_i N.times do s = gets.chomp dic[s] += 1 end dic.each_pair do |key, val| puts "#{key} x #{val}" end
[]
321,501
321,502
u797982941
ruby
p02613
n = gets.chomp.to_i ac = 0 wa = 0 tel = 0 re = 0 n.times do s = gets.chomp if s == "AC" ac += 1 end if s == "WA" wa += 1 end if s == "TEL" tel += 1 end if s == "RE" re += 1 end end print "AC" print " " print "x" print " " print ac print "\n" print "WA" print " " print "x" print " " print wa print "\n" print "TEL" print " " print "x" print " " print tel print "\n" print "RE" print " " print "x" print " " print re print "\n"
n = gets.chomp.to_i ac = 0 wa = 0 tle = 0 re = 0 n.times do s = gets.chomp if s == "AC" ac += 1 end if s == "WA" wa += 1 end if s == "TLE" tle += 1 end if s == "RE" re += 1 end end print "AC" print " " print "x" print " " print ac print "\n" print "WA" print " " print "x" print " " print wa print "\n" print "TLE" print " " print "x" print " " print tle print "\n" print "RE" print " " print "x" print " " print re print "\n"
[ "assignment.variable.change", "identifier.change", "literal.string.change", "control_flow.branch.if.condition.change", "call.arguments.change" ]
321,728
321,729
u412789323
ruby
p02613
N,*S = $<.read.split.tally %w(AC WA TLE RE).each {|c| puts "#{c} x #{S[c]||0}"}
gets S = $<.read.split.tally %w(AC WA TLE RE).each {|c| puts "#{c} x #{S[c]||0}"}
[]
322,106
322,107
u720281401
ruby
p02613
N = gets.to_i ac = wa = tle = re = 0 s = [] N.times do |i| s << gets.to_s.chomp end for i in s if i == "AC" ac +=1 elsif i == "WA" wa += 1 elsif i == "TLE" tle += 1 elsif i == "RE" re += 1 end end puts "AC x #{ac}" puts "WA x #{wa}" puts "TLE × #{tle}" puts "RE × #{re}"
N = gets.to_i ac = wa = tle = re = 0 s = [] N.times do |i| s << gets.to_s.chomp end for i in s if i == "AC" ac +=1 elsif i == "WA" wa += 1 elsif i == "TLE" tle += 1 elsif i == "RE" re += 1 end end puts "AC x #{ac}" puts "WA x #{wa}" puts "TLE x #{tle}" puts "RE x #{re}"
[ "literal.string.change", "call.arguments.change" ]
322,234
322,235
u966810027
ruby
p02613
n = gets.to_i s = [] n.times do s.push gets.chomp end p s c = s.tally p c puts "AC x " + (c["AC"] || 0).to_s puts "WA x " + (c["WA"] || 0).to_s puts "TLE x " + (c["TLE"] || 0).to_s puts "RE x " + (c["RE"] || 0).to_s
n = gets.to_i s = [] n.times do s.push gets.chomp end c = s.tally puts "AC x " + (c["AC"] || 0).to_s puts "WA x " + (c["WA"] || 0).to_s puts "TLE x " + (c["TLE"] || 0).to_s puts "RE x " + (c["RE"] || 0).to_s
[ "call.remove" ]
322,466
322,467
u810064020
ruby
p02613
n = gets.to_i ac = "AC" wa = "WA" tle = "TLE" re = "RE" c = [0, 0, 0, 0] n.times do |i| case gets.chomp when ac c[0] += 1 when wa c[1] += 1 when tle c[2] += 1 when re c[2] += 1 end end puts ac + " x " + c[0].to_s puts wa + " x " + c[1].to_s puts tle + " x " + c[2].to_s puts re + " x " + c[3].to_s
n = gets.to_i ac = "AC" wa = "WA" tle = "TLE" re = "RE" c = [0, 0, 0, 0] n.times do |i| case gets.chomp when ac c[0] += 1 when wa c[1] += 1 when tle c[2] += 1 when re c[3] += 1 end end puts ac + " x " + c[0].to_s puts wa + " x " + c[1].to_s puts tle + " x " + c[2].to_s puts re + " x " + c[3].to_s
[ "literal.number.integer.change", "variable_access.subscript.index.change" ]
322,958
322,959
u016444909
ruby
p02615
class PriorityQueue def initialize(array = []) @data = [] array.each{|a| add(a)} end def add(element) @data.push(element) bottom_up end def peek @data[0] end def poll if size == 0 return nil elsif size == 1 return @data.pop else min = @data[0] @data[0] = @data.pop top_down return min end end def size @data.size end private def swap(i, j) @data[i], @data[j] = @data[j], @data[i] end def bottom_up idx = size - 1 while(has_parent?(idx)) parent_idx = parent_idx(idx) if @data[parent_idx][:key] > @data[idx][:key] swap(parent_idx, idx) idx = parent_idx else return end end end def top_down idx = 0 while (has_child?(idx)) a = left_child_idx(idx) b = right_child_idx(idx) if @data[b].nil? c = a else c = @data[a][:key] <= @data[b][:key] ? a : b end if @data[idx][:key] > @data[c][:key] swap(idx, c) idx = c else return end end end def parent_idx(idx) (idx - (idx.even? ? 2 : 1)) / 2 end def left_child_idx(idx) (idx * 2) + 1 end def right_child_idx(idx) (idx * 2) + 2 end def has_child?(idx) ((idx * 2) + 1) < @data.size end def has_parent?(idx) idx > 0 end end N = gets.to_i A = gets.split.map(&:to_i) sorted = A.sort_by{ |v| -v } comb = PriorityQueue.new([{ key: sorted[1], value: [sorted[0],sorted[1]]}] * 2) ans = sorted[0] sorted[2..-1].each do |v| tmp = comb.poll ans += tmp[:key] comb.add({ key: v, value: [v, tmp[0]] }) comb.add({ key: v, value: [v, tmp[1]] }) end puts ans
class PriorityQueue def initialize(array = []) @data = [] array.each{|a| add(a)} end def add(element) @data.push(element) bottom_up end def peek @data[0] end def poll if size == 0 return nil elsif size == 1 return @data.pop else min = @data[0] @data[0] = @data.pop top_down return min end end def size @data.size end private def swap(i, j) @data[i], @data[j] = @data[j], @data[i] end def bottom_up idx = size - 1 while(has_parent?(idx)) parent_idx = parent_idx(idx) if @data[parent_idx][:key] > @data[idx][:key] swap(parent_idx, idx) idx = parent_idx else return end end end def top_down idx = 0 while (has_child?(idx)) a = left_child_idx(idx) b = right_child_idx(idx) if @data[b].nil? c = a else c = @data[a][:key] <= @data[b][:key] ? a : b end if @data[idx][:key] > @data[c][:key] swap(idx, c) idx = c else return end end end def parent_idx(idx) (idx - (idx.even? ? 2 : 1)) / 2 end def left_child_idx(idx) (idx * 2) + 1 end def right_child_idx(idx) (idx * 2) + 2 end def has_child?(idx) ((idx * 2) + 1) < @data.size end def has_parent?(idx) idx > 0 end end N = gets.to_i A = gets.split.map(&:to_i) sorted = A.sort_by{ |v| -v } comb = PriorityQueue.new([{ key: -sorted[1], value: [sorted[0],sorted[1]]}] * 2) ans = sorted[0] sorted[2..-1].each do |v| tmp = comb.poll ans += -tmp[:key] comb.add({ key: -v, value: [v, tmp[0]] }) comb.add({ key: -v, value: [v, tmp[1]] }) end puts ans
[ "expression.operation.unary.add", "call.arguments.change" ]
323,963
323,964
u990758634
ruby
p02615
N = gets.to_i A = gets.chomp.split.map(&:to_i).sort.reverse ans = A[0] (1..(N-2)/2).each do |i| ans += A[i]*2 if (N-2)%2 == 1 ans += A[(N-2)/2+1] end end puts ans
N = gets.to_i A = gets.chomp.split.map(&:to_i).sort.reverse ans = A[0] (1..(N-2)/2).each do |i| ans += A[i]*2 end if (N-2)%2 == 1 ans += A[(N-2)/2+1] end puts ans
[]
324,811
324,812
u032624914
ruby
p02615
N = gets.strip.to_i A = gets.strip.split(' ').map(&:to_i).sort sum = A[-1] b = 0 puts N-2 (N-2).times do |i| sum += A[A.size-(b/2)-2] b+=1 end puts sum
N = gets.strip.to_i A = gets.strip.split(' ').map(&:to_i).sort sum = A[-1] b = 0 (N-2).times do |i| sum += A[A.size-(b/2)-2] b+=1 end puts sum
[ "call.remove" ]
324,968
324,969
u262392777
ruby
p02615
N,*A = $<.read.split.map(&:to_i) A.sort! n,s = 1,0 while n<N s += A[-1] n += 1 A.pop if n&n-1==0 end p s
N,*A = $<.read.split.map(&:to_i) A.sort! n,s = 1,0 while n<N s += A[-1] n += 1 A.pop if n&1==0 end p s
[ "expression.operation.binary.remove" ]
325,118
325,119
u977697682
ruby
p02615
N = gets.to_i A = gets.chomp.split(" ").map(&:to_i).sort.reverse ans = A[0] A.shift (1..(N-2)).reverse_each{|i| ans += A[(i-1)/2] }
N = gets.to_i A = gets.chomp.split(" ").map(&:to_i).sort.reverse ans = A[0] A.shift (1..(N-2)).reverse_each{|i| ans += A[(i-1)/2] } puts ans
[ "call.add" ]
325,277
325,278
u276517671
ruby
p02615
n = gets.to_i a = gets.split.map(&:to_i) a.sort! a.reverse! if n.even? puts a.slice(1..((n-2)/2)).sum*2+a[0] else puts a.slice(1..((n-3)/2)).sum*2+a[0]+a[(n+1)/2] end
n = gets.to_i a = gets.split.map(&:to_i) a.sort! a.reverse! if n.even? puts a.slice(1..((n-2)/2)).sum*2+a[0] else puts a.slice(1..((n-3)/2)).sum*2+a[0]+a[n/2] end
[ "call.arguments.change" ]
325,401
325,402
u911373146
ruby
p02616
n, k = gets.chomp.split(' ').map(&:to_i) a = gets.chomp.split(' ').map(&:to_i).sort M = (1e9+7).to_i if a.any? { |i| i > 0 } || k % 2 == 0 b = [] (0...(k / 2)).each do |m| if a[0] * a[1] >= a[-2] * a[-1] b.append(a.shift(2)) else b.append(a.pop(2)) end end if k % 2 == 1 b.append(a.pop) end answer = 1 b.each do |i| answer *= i answer %= M end puts answer else answer = 1 a[(n - k)...n].each do |i| answer *= i answer %= M end puts answer end
n, k = gets.chomp.split(' ').map(&:to_i) a = gets.chomp.split(' ').map(&:to_i).sort M = (1e9+7).to_i if a.any? { |i| i > 0 } || k % 2 == 0 b = [] (0...(k / 2)).each do |m| if a[0] * a[1] >= a[-2] * a[-1] b.append(a.shift(2)) else b.append(a.pop(2)) end end if k % 2 == 1 b.append(a.pop) end b.flatten! answer = 1 b.each do |i| answer *= i answer %= M end puts answer else answer = 1 a[(n - k)...n].each do |i| answer *= i answer %= M end puts answer end
[ "call.add" ]
326,479
326,480
u253759478
ruby
p02616
require 'pp' def puts_answer(ans) o = 1 ans.each do |t| o = (o * t) % MOD end o end MOD = 10 ** 9 + 7 n, k = gets.split.map(&:to_i) a_n = gets.split.map(&:to_i) # 全選択するしかない if a_n.length == k ans = a_n puts puts_answer(ans) exit 0 end # 0 を除く len = a_n.length a_n.delete_if {|a| a == 0} is_zero = (len != a_n.length) # pp is_zero # 0を答えに含むしかないので答えは0 if a_n.length < k puts 0 exit 0 end minus = [] plus = [] a_n.each do |a| if a > 0 plus << a else minus << a end end plus.sort!.reverse! minus.sort! ans = [] if k % 2 != 0 # 選択する個数が奇数 # 最初の一つは必ず正の一番でかい数をとる # ただし正の数をとれない場合は負数しかないので,答えは負なので絶対値が一番小さくなるようにする x = plus.shift if x == nil if is_zero puts 0 exit 0 else ans = minus.reverse![0, k] puts puts_answer(ans) exit 0 end end ans << x k = k - 1 end # これで残りはkが偶数 pp plus pp minus z = false while k != 0 x, b = if plus.length == 1 && minus.length == 1 [minus[0] * plus[0], :xxx] elsif plus[0] == nil || plus[1] == nil [minus[0] * minus[1], :minus] elsif minus[0] == nil || minus[1] == nil [plus[0] * plus[1], :plus] else p1 = plus[0] * plus[1] m1 = minus[0] * minus[1] if p1 >= m1 [p1, :plus] else [m1, :minus] end end if b == :plus ans << plus.shift ans << plus.shift elsif b == :minus ans << minus.shift ans << minus.shift else ans << minus.shift ans << plus.shift z = true end k -= 2 end if z && is_zero puts 0 else puts puts_answer(ans) end
require 'pp' def puts_answer(ans) o = 1 ans.each do |t| o = (o * t) % MOD end o end MOD = 10 ** 9 + 7 n, k = gets.split.map(&:to_i) a_n = gets.split.map(&:to_i) # 全選択するしかない if a_n.length == k ans = a_n puts puts_answer(ans) exit 0 end # 0 を除く len = a_n.length a_n.delete_if {|a| a == 0} is_zero = (len != a_n.length) # pp is_zero # 0を答えに含むしかないので答えは0 if a_n.length < k puts 0 exit 0 end minus = [] plus = [] a_n.each do |a| if a > 0 plus << a else minus << a end end plus.sort!.reverse! minus.sort! ans = [] if k % 2 != 0 # 選択する個数が奇数 # 最初の一つは必ず正の一番でかい数をとる # ただし正の数をとれない場合は負数しかないので,答えは負なので絶対値が一番小さくなるようにする x = plus.shift if x == nil if is_zero puts 0 exit 0 else ans = minus.reverse![0, k] puts puts_answer(ans) exit 0 end end ans << x k = k - 1 end # これで残りはkが偶数 #pp plus #pp minus z = false while k != 0 x, b = if plus.length == 1 && minus.length == 1 [minus[0] * plus[0], :xxx] elsif plus[0] == nil || plus[1] == nil [minus[0] * minus[1], :minus] elsif minus[0] == nil || minus[1] == nil [plus[0] * plus[1], :plus] else p1 = plus[0] * plus[1] m1 = minus[0] * minus[1] if p1 >= m1 [p1, :plus] else [m1, :minus] end end if b == :plus ans << plus.shift ans << plus.shift elsif b == :minus ans << minus.shift ans << minus.shift else ans << minus.shift ans << plus.shift z = true end k -= 2 end if z && is_zero puts 0 else puts puts_answer(ans) end
[ "call.remove" ]
326,508
326,509
u754375546
ruby
p02616
(N, K), As = readlines.map{_1.split.map(&:to_i)} M = 10**9 + 7 as = As.sort if as.last < 0 puts as.last(K).inject(1){|r, a| r*a % M} else ans, c, l, r = 1, 0, 0, -1 while c < K - 1 ls, rs = as[l]*as[l + 1], as[r]*as[r - 1] if ls > rs ans = ans*ls % M l += 2 c += 2 else ans = ans*as[r] % M r -= 1 c += 1 end end ans = ans*as[r] % M if c == K - 1 puts ans end
(N, K), As = readlines.map{_1.split.map(&:to_i)} M = 10**9 + 7 as = As.sort if as.last < 0 && K.odd? puts as.last(K).inject(1){|r, a| r*a % M} else ans, c, l, r = 1, 0, 0, -1 while c < K - 1 ls, rs = as[l]*as[l + 1], as[r]*as[r - 1] if ls > rs ans = ans*ls % M l += 2 c += 2 else ans = ans*as[r] % M r -= 1 c += 1 end end ans = ans*as[r] % M if c == K - 1 puts ans end
[ "control_flow.branch.if.condition.change" ]
326,773
326,774
u304198114
ruby
p02619
lines = [] while line = gets lines << line.chomp.split(' ').map(&:to_i) end D = lines[0][0] class Array def max_id max = - 10000000000 tmp = -1 for i in 1..self.length do if self[i-1] > max then tmp = i-1 max = self[i-1] end end return tmp end end last_date = [] for i in 1..26 do last_date.push(0) end satis = 0 for i in 1..D do contest = lines[D+i][0] satis += lines[i][contest-1] last_date[contest-1] = i for j in 1..26 do satis -= (i - last_date[j-1]) * lines[1][j-1] end puts satis end
lines = [] while line = gets lines << line.chomp.split(' ').map(&:to_i) end D = lines[0][0] class Array def max_id max = - 10000000000 tmp = -1 for i in 1..self.length do if self[i-1] > max then tmp = i-1 max = self[i-1] end end return tmp end end last_date = [] for i in 1..26 do last_date.push(0) end satis = 0 for i in 1..D do contest = lines[D+i+1][0] satis += lines[i+1][contest-1] last_date[contest-1] = i for j in 1..26 do satis -= (i - last_date[j-1]) * lines[1][j-1] end puts satis end
[ "assignment.change", "expression.operation.binary.add" ]
328,258
328,259
u569559028
ruby
p02621
a=gets.to_i p a+a+a*a+a*a*a
a=gets.to_i p a+a*a+a*a*a
[ "expression.operation.binary.remove" ]
329,010
329,011
u492991702
ruby
p02621
a = gets puts a + a*a + a*a*a
a = gets.to_i puts a + a*a + a*a*a
[ "call.add" ]
329,136
329,137
u944470046
ruby
p02621
a = gets.to_i p (a + a ** 2 + a ** 32).to_i
a = gets.to_i p (a + a ** 2 + a ** 3).to_i
[ "literal.number.integer.change", "call.arguments.change", "expression.operation.binary.change" ]
329,155
329,156
u452697734
ruby
p02621
n = gets.to_i a = n + n**2 + n*3 puts a
n = gets.to_i a = n + n**2 + n**3 puts a
[ "assignment.value.change", "expression.operation.binary.change" ]
329,498
329,499
u652514744
ruby
p02621
input = gets.to_i puts input + input * 2 + input * 3
input = gets.to_i puts input + input ** 2 + input ** 3
[ "call.arguments.change", "expression.operation.binary.change" ]
329,604
329,605
u577617750
ruby
p02622
s = gets.chomp.chars t = gets.chomp.chars num = 0 for i in 1..s.length num = num + 1 if s[i] != t[i] end puts num
s = gets.chomp!.chars t = gets.chomp!.chars num = 0 for i in 0..s.length-1 num = num + 1 if s[i] != t[i] end puts num
[ "assignment.value.change", "identifier.change", "literal.number.integer.change" ]
329,897
329,898
u319056721
ruby
p02622
S=gets.chomp T=gets.chomp kekka=0 (0..S.size-1).each do |n| p S[n] kekka+=1 if S[n]!=T[n] end puts kekka
S=gets.chomp T=gets.chomp kekka=0 (0..S.size-1).each do |n| kekka+=1 if S[n]!=T[n] end puts kekka
[ "call.remove" ]
330,196
330,197
u085647568
ruby
p02622
S=gets T=gets kekka=0 (0..S.size-1).each do |n| kekka+=1 if S[n]==T[n] end puts kekka
S=gets.chomp T=gets.chomp kekka=0 (0..S.size-1).each do |n| kekka+=1 if S[n]!=T[n] end puts kekka
[ "call.add", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
330,198
330,197
u085647568
ruby
p02622
s = gets.chomp t = gets.chomp ans = 0 for a in 0..(s.length - 1) do if s[a] == t[a] break else ans += 1 end end puts ans
s = gets.chomp t = gets.chomp ans = 0 for a in 0..(s.length - 1) do if s[a] != t[a] ans += 1 end end puts ans
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.break.remove" ]
330,223
330,224
u641383521
ruby
p02622
a = gets.chomp b = gets.chomp u = 0 a.each_with_index do |c, i| u += 1 if c != b[i] end puts u
a = gets.chomp b = gets.chomp u = 0 a.chars.each_with_index do |c, i| u += 1 if c != b[i] end puts u
[ "call.add" ]
330,251
330,252
u365782862
ruby
p02622
S = gets.chomp.split(" ") T = gets.chomp.split(" ") ans = 0 S.size.times do |i| ans += 1 if S[i] != T[i] end puts ans
S = gets.chomp.split("") T = gets.chomp.split("") ans = 0 S.size.times do |i| ans += 1 if S[i] != T[i] end puts ans
[ "literal.string.change", "assignment.value.change", "call.arguments.change" ]
330,420
330,421
u729911058
ruby
p02622
str_a,str_b = gets.split str_length = str_a.length same_character_num = 0 str_length.times do |i| if str_a[i] == str_b[i] same_character_num += 1 end end result = str_length - same_character_num puts result
str_a = gets str_b = gets str_length = str_a.length same_character_num = 0 str_length.times do |i| if str_a[i] == str_b[i] same_character_num += 1 end end result = str_length - same_character_num puts result
[ "call.remove" ]
330,506
330,507
u090346198
ruby
p02622
n = gets.chars m = gets.chars cnt = 0 n.each_with_index do |i, index| cnt += 1 if i != m[index] end puts cnt -1
n = gets.chomp.chars m = gets.chomp.chars cnt = 0 n.each_with_index do |i, index| cnt += 1 if i != m[index] end puts cnt
[ "call.add" ]
330,640
330,641
u652514744
ruby
p02623
n, m, k = gets.split.map(&:to_i) a_arr = gets.split.map(&:to_i) b_arr = gets.split.map(&:to_i) sum = 0 sum_a_arr = [[0, 0]] a_arr.each_with_index do |num, i| sum += num sum_a_arr << [sum, i + 1] end sum = 0 sum_b_arr = [[0, 0]] b_arr.each_with_index do |num, i| sum += num sum_b_arr << [sum, i + 1] end max = 0 ind = 0 sum_a_arr.reverse_each do |num, count| next if num > k c = count while ind < b_arr.length num2, count2 = sum_b_arr[ind] break if num + num2 > k ind += 1 c = count + count2 end max = c if max < c end p max
n, m, k = gets.split.map(&:to_i) a_arr = gets.split.map(&:to_i) b_arr = gets.split.map(&:to_i) sum = 0 sum_a_arr = [[0, 0]] a_arr.each_with_index do |num, i| sum += num sum_a_arr << [sum, i + 1] end sum = 0 sum_b_arr = [[0, 0]] b_arr.each_with_index do |num, i| sum += num sum_b_arr << [sum, i + 1] end max = 0 ind = 0 sum_a_arr.reverse_each do |num, count| next if num > k c = count while ind < b_arr.length + 1 num2, count2 = sum_b_arr[ind] break if num + num2 > k ind += 1 c = count + count2 end max = c if max < c end p max
[ "expression.operation.binary.add" ]
331,153
331,154
u771770008
ruby
p02623
N, M, K = gets.split(" ").map(&:to_i) a = gets.split(" ").map(&:to_i) b = gets.split(" ").map(&:to_i) aa = [0] bb = [0] N.times do |i| aa << a[i] + aa.last end M.times do |i| bb << b[i] + bb.last end ans, j = 0, M N.times do |i| break if aa[i] > K while bb[j] > K - aa[i] j -= 1 end ans = i + j if i + j > ans end puts ans
N, M, K = gets.split(" ").map(&:to_i) a = gets.split(" ").map(&:to_i) b = gets.split(" ").map(&:to_i) aa = [0] bb = [0] N.times do |i| aa << a[i] + aa.last end M.times do |i| bb << b[i] + bb.last end ans, j = 0, M (N + 1).times do |i| break if aa[i] > K while bb[j] > K - aa[i] j -= 1 end ans = i + j if i + j > ans end puts ans
[]
332,754
332,755
u729911058
ruby
p02623
N, M, K = gets.split(" ").map(&:to_i) a = gets.split(" ").map(&:to_i) b = gets.split(" ").map(&:to_i) aa = [0] bb = [0] M.times do |i| aa << a[i] + aa.last end N.times do |i| bb << b[i] + bb.last end ans, j = 0, M N.times do |i| break if aa[i] > K while bb[j] > K - aa[i] j -= 1 end ans = i + j if i + j > ans end puts ans
N, M, K = gets.split(" ").map(&:to_i) a = gets.split(" ").map(&:to_i) b = gets.split(" ").map(&:to_i) aa = [0] bb = [0] N.times do |i| aa << a[i] + aa.last end M.times do |i| bb << b[i] + bb.last end ans, j = 0, M (N + 1).times do |i| break if aa[i] > K while bb[j] > K - aa[i] j -= 1 end ans = i + j if i + j > ans end puts ans
[]
332,756
332,755
u729911058
ruby
p02623
n, m, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) aa = [0] bb = [0] a.size.times{|i| aa << a[i] + aa.last } b.size.times{|i| bb << b[i] + bb.last } i = 0 j = b.size while i < aa.size && j >= 0 if aa[i] + bb[j] <= k mx = i+j if mx < i+j i += 1 else j -= 1 end end p mx
n, m, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) aa = [0] bb = [0] a.size.times{|i| aa << a[i] + aa.last } b.size.times{|i| bb << b[i] + bb.last } i = 0 j = b.size mx = 0 while i < aa.size && j >= 0 if aa[i] + bb[j] <= k mx = i+j if mx < i+j i += 1 else j -= 1 end end p mx
[ "assignment.add" ]
332,978
332,979
u207607938
ruby
p02623
n, m, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) aa = [0] bb = [0] a.size.times{|i| aa << a[i] + aa.last } b.size.times{|i| bb << b[i] + bb.last } i = 0 j = b.size while i < aa.size && j >= 0 if aa[i] + bb[j] <= k mx = i+j if mx < i+j i += 1 else j -= 1 end end p mx
n, m, k = gets.split.map(&:to_i) a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) aa = [0] bb = [0] a.size.times{|i| aa << a[i] + aa.last } b.size.times{|i| bb << b[i] + bb.last } i = 0 j = b.size mx = 0 while i < aa.size && j >= 0 if aa[i] + bb[j] <= k mx = i+j if mx < i+j i += 1 else j -= 1 end end p mx
[ "assignment.add" ]
332,978
332,980
u207607938
ruby
p02623
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M (N+1).times do |i| break if a[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M (N+1).times do |i| break if sa[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
[ "identifier.change", "control_flow.branch.if.condition.change" ]
333,675
333,676
u326288614
ruby
p02623
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M (N+1).times do |i| break if a[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M (N+1).times do |i| break if sa[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
[ "identifier.change", "control_flow.branch.if.condition.change" ]
333,677
333,676
u326288614
ruby
p02623
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) # 累積和の計算 sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M # iがAから読む数,jがBから読む数 (N+1).times do |i| break if a[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
N, M, K = gets.split.map(&:to_i) a = [] b = [] a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) sa = [] sa[0] = 0 sb = [] sb[0] = 0 N.times do |i| sa[i+1] = sa[i] + a[i] end M.times do |i| sb[i+1] = sb[i] + b[i] end ans = 0 j = M (N+1).times do |i| break if sa[i] > K while sb[j] > K - sa[i] j -= 1 end ans = [ans, i+j].max end puts ans
[ "identifier.change", "control_flow.branch.if.condition.change" ]
333,678
333,676
u326288614
ruby
p02623
N,M,K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) max = 0 a = [0] b = [0] A.each_with_index do |n,i| a << a[i] + n end B.each_with_index do |n,i| b << b[i] + n end ans = 0 j = M 1.upto(N+1) do |i| if a[i] > K break end while b[j] > K - a[i] do j -= 1 end c = i + j ans = c if c > ans end puts ans
N,M,K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) a = [0] b = [0] A.each_with_index do |n,i| a << a[i] + n end B.each_with_index do |n,i| b << b[i] + n end ans = 0 j = M 0.upto(N) do |i| if a[i] > K break end while b[j] > K - a[i] do j -= 1 end c = i + j ans = c if c > ans end puts ans
[ "literal.number.integer.change", "expression.operation.binary.remove" ]
333,771
333,772
u173515518
ruby
p02623
N,M,K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) max = 0 a = [0] b = [0] A.each_with_index do |n,i| a << a[i] + n end B.each_with_index do |n,i| b << b[i] + n end ans = 0 j = M 1.upto(N+1) do |i| if a[i] > K break end while b[j] > K - a[i] do j -= 1 end c = i + j ans = c if c > ans end puts ans
N,M,K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) max = 0 a = [0] b = [0] A.each_with_index do |n,i| a << a[i] + n end B.each_with_index do |n,i| b << b[i] + n end ans = 0 j = M 0.upto(N) do |i| if a[i] > K break end while b[j] > K - a[i] do j -= 1 end c = i + j ans = c if c > ans end puts ans
[ "literal.number.integer.change", "expression.operation.binary.remove" ]
333,771
333,773
u173515518
ruby
p02623
def search(tim, d) i = 0 j = d.size - 1 if d[0] > tim return 0 end while true if tim < d[i] return i end if i >= j if i > d.size - 1 return i end if tim >= d[i] return i + 1 else return i end end k = (i + j).div(2) val = d[k] if tim == val return k + 1 elsif tim > d[k] i = k + 1 else j = k - 1 end end end (N, M, K) = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } a = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } b = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } c = [] d = [] tim = 0 for i in a do tim += i c.push(tim) end tim = 0 for i in b do tim += i d.push(tim) end ans = 0 c.each_with_index do |e, i| rest = K - e if rest < 0 break end z = search(rest, d) if ans < i + 1 + z ans = i + 1 + z end end puts ans
def search(tim, d) i = 0 j = d.size - 1 if d[0] > tim return 0 end while true if tim < d[i] return i end if i >= j if i > d.size - 1 return i end if tim >= d[i] return i + 1 else return i end end k = (i + j).div(2) val = d[k] if tim == val return k + 1 elsif tim > d[k] i = k + 1 else j = k - 1 end end end (N, M, K) = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } a = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } b = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i } c = [] d = [] tim = 0 for i in a do tim += i c.push(tim) end tim = 0 for i in b do tim += i d.push(tim) end ans = search(K, d) c.each_with_index do |e, i| rest = K - e if rest < 0 break end z = search(rest, d) if ans < i + 1 + z ans = i + 1 + z end end puts ans
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "call.arguments.add" ]
334,088
334,089
u250545805
ruby