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 |
|---|---|---|---|---|---|---|---|
p03998
|
a,b,c = gets.chomp.split(""),gets.chomp.split(""),gets.chomp.split("");second = "a"
loop{
if (eval("#{second}.size") == 1) then
puts second
break
else
old_next = second
eval("second = #{old_next}[0]")
eval("#{old_next}.delete_at(0)")
end
}
|
a,b,c = gets.chomp.split(""),gets.chomp.split(""),gets.chomp.split("");second = "a"
loop{
if (eval("#{second}.size") == 0) then
puts second.upcase
break
else
old_next = second
eval("second = #{old_next}[0]")
eval("#{old_next}.delete_at(0)")
end
}
|
[
"literal.number.integer.change",
"control_flow.branch.if.condition.change",
"call.add"
] | 1,501,779
| 1,501,778
|
u970198083
|
ruby
|
p03999
|
s=gets.chomp
puts ['','+'].repeated_permutation(s.size-1).map{|x| eval(s.chars.zip(x)*'' + x[-1])}.inject(&:+)
|
s=gets.chomp
puts ['','+'].repeated_permutation(s.size-1).map{|x| eval(s.chars.zip(x)*'')}.inject(&:+)
|
[
"expression.operation.binary.remove"
] | 1,501,954
| 1,501,955
|
u056944756
|
ruby
|
p03999
|
s = gets.chomp.chars
l = s.length
sum = 0
if l == 1
sum = str.join.to_i
else
["", "+"].repeated_permutation(l - 1) do |plus|
plus << ""
tmp = s.zip(plus).flatten.join
sum += eval(tmp)
end
end
puts sum
|
s = gets.chomp.chars
l = s.length
sum = 0
if l == 1
sum = s.join.to_i
else
["", "+"].repeated_permutation(l - 1) do |plus|
plus << ""
tmp = s.zip(plus).flatten.join
sum += eval(tmp)
end
end
puts sum
|
[
"assignment.value.change",
"identifier.change"
] | 1,502,025
| 1,502,026
|
u297507288
|
ruby
|
p03999
|
s = gets.chomp.chars
l = s.length
sum = 0
if l == 1
sum = str.to_i
else
["", "+"].repeated_permutation(l - 1) do |plus|
plus << ""
tmp = s.zip(plus).flatten.join
sum += eval(tmp)
end
end
puts sum
|
s = gets.chomp.chars
l = s.length
sum = 0
if l == 1
sum = s.join.to_i
else
["", "+"].repeated_permutation(l - 1) do |plus|
plus << ""
tmp = s.zip(plus).flatten.join
sum += eval(tmp)
end
end
puts sum
|
[
"assignment.value.change",
"identifier.change",
"call.add"
] | 1,502,027
| 1,502,026
|
u297507288
|
ruby
|
p03999
|
def calc(i, a, b)
return a + b*10 + $s[i] if i == $n
calc(i+1, a + b*10 + $s[i], 0) + calc(i+1, a, b*10 + $s[i])
end
$s = gets.chomp.chars.map(&:to_i)
$n = $a.size - 1
puts calc(0, 0, 0)
|
def calc(i, a, b)
return a + b*10 + $s[i] if i == $n
calc(i+1, a + b*10 + $s[i], 0) + calc(i+1, a, b*10 + $s[i])
end
$s = gets.chomp.chars.map(&:to_i)
$n = $s.size - 1
puts calc(0, 0, 0)
|
[
"assignment.value.change",
"expression.operation.binary.change"
] | 1,502,030
| 1,502,031
|
u692254521
|
ruby
|
p03999
|
p gets.chars.tap{|a| break (0..2**(a.size - 1)-1).map{|i| eval(a.zip(i.to_s(2).rjust(a.size-1, "0").chars.map{|c| ["", "+"][c.to_i]}).flatten.compact.join)}.inject(:+)}
|
p gets.chomp.chars.tap{|a| break (0..2**(a.size - 1)-1).map{|i| eval(a.zip(i.to_s(2).rjust(a.size-1, "0").chars.map{|c| ["", "+"][c.to_i]}).flatten.compact.join)}.inject(:+)}
|
[
"call.add"
] | 1,502,066
| 1,502,067
|
u655122274
|
ruby
|
p03999
|
$s = gets.chomp.split("").map(&:to_i)
array = [$s.shift]
$answers = []
def dfs(array, digit)
if digit == $s.size + 1
$answers << array
return
end
p array
dfs([*array, $s[digit - 1]], digit + 1)
dfs([*array[0..-2], array[-1] * 10 + $s[digit - 1]], digit + 1)
end
dfs(array, 1)
puts $answers.flatten.inject(:+)
|
$s = gets.chomp.split("").map(&:to_i)
array = [$s.shift]
$answers = []
def dfs(array, digit)
if digit == $s.size + 1
$answers << array
return
end
dfs([*array, $s[digit - 1]], digit + 1)
dfs([*array[0..-2], array[-1] * 10 + $s[digit - 1]], digit + 1)
end
dfs(array, 1)
puts $answers.flatten.inject(:+)
|
[
"call.remove"
] | 1,502,093
| 1,502,094
|
u653737129
|
ruby
|
p03999
|
s = gets.chomp.split("")
l = s.length - 1
ans = 0
for i in 0..(2**l-1)
ss = s.clone
exp = []
while ss.size > 0
exp << ss.shift
exp << "+" if i % 2 == 1
i = i >> 1
end
ans += eval exp.join
end
|
s = gets.chomp.split("")
l = s.length - 1
ans = 0
for i in 0..(2**l-1)
ss = s.clone
exp = []
while ss.size > 0
exp << ss.shift
exp << "+" if i % 2 == 1
i = i >> 1
end
ans += eval exp.join
end
puts ans
|
[
"call.add"
] | 1,502,176
| 1,502,177
|
u868089307
|
ruby
|
p03999
|
igits = gets.chomp.split('').map(&:to_i)
if digits.length == 1 then
puts digits[0]
exit
end
length =digits.length - 1
max = (2**length) - 1
sum = (0..max).map {|n|
sprintf('%0'+length.to_s+'b', n).split('')
}.map {|p|
f = []
(0..length + 1).each {|i|
f.push digits[i]
if i < length + 1 then
f.push (p[i] == '1') ? '+' : '';
end
}
acc = f.reduce{|acc, c| acc.to_s + c.to_s}
eval(acc)
}.reduce(&:+)
puts sum
|
digits = gets.chomp.split('').map(&:to_i)
if digits.length == 1 then
puts digits[0]
exit
end
length =digits.length - 1
max = (2**length) - 1
sum = (0..max).map {|n|
sprintf('%0'+length.to_s+'b', n).split('')
}.map {|p|
f = []
(0..length + 1).each {|i|
f.push digits[i]
if i < length + 1 then
f.push (p[i] == '1') ? '+' : '';
end
}
fomula = f.reduce{|acc, c| acc.to_s + c.to_s}
eval(fomula)
}.reduce(&:+)
puts sum
|
[
"assignment.variable.change",
"identifier.change",
"io.output.change",
"assignment.value.change",
"call.arguments.change"
] | 1,502,268
| 1,502,269
|
u493535287
|
ruby
|
p03999
|
a=gets.chomp.reverse
w=[1,11,112,1124,11248,112496,1124992,11249984,112499968,1124999946]
s=(0...a.size).map{|v|w[v]*(a[v].ord-48)*2**(a.size-v-1)}.reduce :+
p s
|
a=gets.chomp.reverse
w=[1,11,112,1124,11248,112496,1124992,11249984,112499968,1124999936]
s=(0...a.size).map{|v|w[v]*(a[v].ord-48)*2**(a.size-v-1)}.reduce :+
p s
|
[
"literal.number.integer.change",
"assignment.value.change"
] | 1,502,270
| 1,502,271
|
u459746049
|
ruby
|
p04000
|
# ABC045 D
h, w, n = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
a -= 1
b -= 1
(a-2).upto(a) do |i|
(b-2).upto(b) do |j|
if i >= 0 && i + 2 < h && j >= 0 && j + 2 < w
x = [i, j]
hash[x] += 1
end
end
end
end
ans = Array.new(10, 0)
s = 0
hash.each do |k, v|
ans[v] += 1
s += 1
end
puts (h - 2) * (w - 2) - s
ans.each{|x| puts x}
|
# ABC045 D
h, w, n = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
a -= 1
b -= 1
(a-2).upto(a) do |i|
(b-2).upto(b) do |j|
if i >= 0 && i + 2 < h && j >= 0 && j + 2 < w
x = [i, j]
hash[x] += 1
end
end
end
end
ans = Array.new(10, 0)
s = 0
hash.each do |k, v|
ans[v] += 1
s += 1
end
ans[0] = (h - 2) * (w - 2) - s
ans.each{|x| puts x}
|
[
"assignment.variable.change"
] | 1,502,387
| 1,502,388
|
u910756197
|
ruby
|
p04000
|
H, W, N = gets.split.map(&:to_i)
#H, W, N = 10**5, 10**5, 10**5
points = {}
memo = Hash.new(0)
ans = Array.new(10, 0)
ans[0] = (W - 2) * (H - 2)
N.times do |i|
a, b = gets.split.map(&:to_i)
#a, b = i, i
(a-1..a+1).each do |ap|
next if ap < 2 || ap > H - 1
(b-1..b+1).each do |bp|
next if bp < 2 || bp > W - 1
code = ap*H+bp
ans[memo[code]] -= 1
memo[code] += 1
ans[memo[code]] += 1
end
end
end
(0..9).each do |i|
puts ans[i]
end
|
H, W, N = gets.split.map(&:to_i)
#H, W, N = 10**5, 10**5, 10**5
points = {}
memo = Hash.new(0)
ans = Array.new(10, 0)
ans[0] = (W - 2) * (H - 2)
N.times do |i|
a, b = gets.split.map(&:to_i)
#a, b = i, i
(a-1..a+1).each do |ap|
next if ap < 2 || ap > H - 1
(b-1..b+1).each do |bp|
next if bp < 2 || bp > W - 1
code = ap*W+bp
ans[memo[code]] -= 1
memo[code] += 1
ans[memo[code]] += 1
end
end
end
(0..9).each do |i|
puts ans[i]
end
|
[
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,502,407
| 1,502,408
|
u314396879
|
ruby
|
p04000
|
io = STDIN
$h,$w,$n=io.gets.chomp.split.map(&:to_i)
masu=Hash.new{|h,k|h[k]=0}
$n.times do
i,j = io.gets.chomp.split.map{|s|s.to_i.pred}
[-1,0,1].product([-1,0,1]) do |x,y|
xx,yy=i+x,j+y
next if xx<=0 || yy<=0
next if xx>=$h-1 || yy>=$w-1
masu[xx*$h+yy]+=1
end
end
ans={}
1.upto(9) do |ct|
ans[ct]=0
end
cnts=masu.values
cnts.each do |ct|
ans[ct]+=1
end
puts ($w-2)*($h-2)-cnts.size
puts ans.values
|
io = STDIN
$h,$w,$n=io.gets.chomp.split.map(&:to_i)
masu=Hash.new{|h,k|h[k]=0}
$n.times do
i,j = io.gets.chomp.split.map{|s|s.to_i.pred}
[-1,0,1].product([-1,0,1]) do |x,y|
xx,yy=i+x,j+y
next if xx<=0 || yy<=0
next if xx>=$h-1 || yy>=$w-1
masu[xx*$w+yy]+=1
end
end
ans={}
1.upto(9) do |ct|
ans[ct]=0
end
cnts=masu.values
cnts.each do |ct|
ans[ct]+=1
end
puts ($w-2)*($h-2)-cnts.size
puts ans.values
|
[
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,502,444
| 1,502,445
|
u132360211
|
ruby
|
p04001
|
$s = gets
$result = 0
def calc(idxs)
sum = 0
start = 0
idxs.each do |idx|
sum += $s[start..(idx-1)].to_i
start = idx
end
return sum + $s[start..($s.size-1)].to_i
end
def explore(idx=0, idxs=[])
if idx == $s.size-1 then
$result += calc(idxs)
else
explore(idx+1, idxs)
explore(idx+1, idxs + [idx+1])
end
end
explore()
puts $result
|
$s = gets.chomp
$result = 0
def calc(idxs)
sum = 0
start = 0
idxs.each do |idx|
sum += $s[start..(idx-1)].to_i
start = idx
end
return sum + $s[start..($s.size-1)].to_i
end
def explore(idx=0, idxs=[])
if idx == $s.size-1 then
$result += calc(idxs)
else
explore(idx+1, idxs)
explore(idx+1, idxs + [idx+1])
end
end
explore()
puts $result
|
[
"call.add"
] | 1,502,491
| 1,502,492
|
u568117695
|
ruby
|
p04001
|
s = gets.chomp
t = s.to_s.size - 1
(2 ** t).tims do |i|
temp = s.dup
t.times do |j|
k = s.size - temp.size
if i[j] == 1
sum += temp.slice!(0, j - k + 1).to_i
end
end
sum += temp.to_i
end
puts sum
|
s = gets.chomp
t = s.to_s.size - 1
sum = 0
(2 ** t).times do |i|
temp = s.dup
t.times do |j|
k = s.size - temp.size
if i[j] == 1
sum += temp.slice!(0, j - k + 1).to_i
end
end
sum += temp.to_i
end
puts sum
|
[
"identifier.change"
] | 1,502,710
| 1,502,711
|
u848201575
|
ruby
|
p04001
|
s = gets.split('').map(&:to_i)
n = s.size
sum = 0
['-','+'].repeated_permutation(n-1) do |a|
k = 1
(n-1).downto(0) do |d|
sum += s[d]*k
next if d == 0
if a[d-1] == '+'
k = 1
else
k *= 10
end
end
end
print sum.to_s
|
s = gets.chomp.split('').map(&:to_i)
n = s.size
sum = 0
['-','+'].repeated_permutation(n-1) do |a|
k = 1
(n-1).downto(0) do |d|
sum += s[d]*k
next if d == 0
if a[d-1] == '+'
k = 1
else
k *= 10
end
end
end
print sum.to_s
|
[
"call.add"
] | 1,502,916
| 1,502,917
|
u195257137
|
ruby
|
p04001
|
s = gets.split('').map(&:to_i)
n = s.size
sum = 0
['-','+'].repeated_permutation(n-1) do |a|
k = 1
(n-1).downto(0) do |d|
sum += s[d]*k
next if d == 0
if a[d-1] == '+'
k = 1
else
k *= 10
end
end
end
print sum
|
s = gets.chomp.split('').map(&:to_i)
n = s.size
sum = 0
['-','+'].repeated_permutation(n-1) do |a|
k = 1
(n-1).downto(0) do |d|
sum += s[d]*k
next if d == 0
if a[d-1] == '+'
k = 1
else
k *= 10
end
end
end
print sum.to_s
|
[
"call.add"
] | 1,502,918
| 1,502,917
|
u195257137
|
ruby
|
p04001
|
nums = gets.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
puts(total)
|
nums = gets.chomp.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
puts total
|
[
"call.add",
"call.arguments.change"
] | 1,502,976
| 1,502,977
|
u429775245
|
ruby
|
p04001
|
nums = gets.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
print(total)
|
nums = gets.chomp.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
puts total
|
[
"call.add",
"identifier.change",
"call.arguments.change"
] | 1,502,978
| 1,502,977
|
u429775245
|
ruby
|
p04001
|
nums = gets.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
p(total)
|
nums = gets.chomp.split('')
total = 0
[0 , 1].repeated_permutation(nums.length-1) do |bits|
arr = [nums[0]]
arr_i = 0
0.upto(nums.length-2) do |i|
if bits[i] == 0
arr[arr_i] += nums[i+1]
else
arr_i += 1
arr[arr_i] = nums[i+1]
end
end
total += arr.map(&:to_i).inject(:+)
end
puts total
|
[
"call.add",
"call.function.change",
"io.output.change",
"call.arguments.change"
] | 1,502,979
| 1,502,977
|
u429775245
|
ruby
|
p04001
|
#!/usr/bin/env ruby
def solve
str = gets.chomp
ans = str.to_i
pos = Array.new(str.length - 1){|i| i+1}
(str.length - 1).times do |i|
pos.combination(i+1).each do |plus_positions|
formula = str.dup
plus_positions.reverse.each do |plus_pos|
formula.insert(plus_pos, '+')
end
puts formula
ans += eval(formula)
end
end
puts ans
end
if $0 == __FILE__
solve()
end
|
#!/usr/bin/env ruby
def solve
str = gets.chomp
ans = str.to_i
pos = Array.new(str.length - 1){|i| i+1}
(str.length - 1).times do |i|
pos.combination(i+1).each do |plus_positions|
formula = str.dup
plus_positions.reverse.each do |plus_pos|
formula.insert(plus_pos, '+')
end
ans += eval(formula)
end
end
puts ans
end
if $0 == __FILE__
solve()
end
|
[
"call.remove"
] | 1,503,159
| 1,503,160
|
u041550672
|
ruby
|
p04001
|
def f s;if s.empty? then [1,0] else (1..s.size).map{|i|l=s[0...i].to_i;b,r=f(s[i..-1]);[b, b*l+r]}.reduce([0,0]){|(x,y),(a,b)|[x+a, y+b]}end end
puts (f gets)[1]
|
def f s;if s.empty? then [1,0] else (1..s.size).map{|i|l=s[0...i].to_i;b,r=f(s[i..-1]);[b, b*l+r]}.reduce([0,0]){|(x,y),(a,b)|[x+a, y+b]}end end
puts (f gets.chomp)[1]
|
[
"call.add"
] | 1,503,222
| 1,503,223
|
u735923683
|
ruby
|
p04001
|
def f s;if s.empty? then [1,0] else (1..s.size).map{|i|l=s[0...i].to_i;b,r=f(s[i..-1]);[b, b*l+r]}.reduce([0,0]){|(x,y),(a,b)|[x+a, y+b]}end end
puts (f gets.to_i)[1]
|
def f s;if s.empty? then [1,0] else (1..s.size).map{|i|l=s[0...i].to_i;b,r=f(s[i..-1]);[b, b*l+r]}.reduce([0,0]){|(x,y),(a,b)|[x+a, y+b]}end end
puts (f gets.chomp)[1]
|
[
"identifier.change",
"call.arguments.change"
] | 1,503,224
| 1,503,223
|
u735923683
|
ruby
|
p04001
|
s=gets.chomp
p ['','+'].repeated_permutation(s.size-1).inject(0){|a,x|a+=(['']+x).zip(s.chars).join.to_i}
|
s=gets.chomp
p ['','+'].repeated_permutation(s.size-1).inject(0){|a,x|a+=eval((['']+x).zip(s.chars).join)}
|
[
"call.add",
"call.arguments.change"
] | 1,503,298
| 1,503,299
|
u210718367
|
ruby
|
p03994
|
s = gets.chomp.codepoints
k = gets.to_i
z = "a".ord
z = "z".ord
s.size.times{|i|
break if k.zero?
if s[i] != a
t = (z - s[i]).succ
if t <= k
k -= t
s[i] = 97
end
end
}
k = k % 26
s[-1] = s[-1] + k
puts s.map(&:chr).join
|
s = gets.chomp.codepoints
k = gets.to_i
a = "a".ord
z = "z".ord
s.size.times{|i|
break if k.zero?
if s[i] != a
t = (z - s[i]).succ
if t <= k
k -= t
s[i] = 97
end
end
}
k = k % 26
s[-1] = s[-1] + k
puts s.map(&:chr).join
|
[
"assignment.variable.change",
"identifier.change"
] | 1,504,148
| 1,504,149
|
u964208493
|
ruby
|
p03994
|
s=gets;k=gets.to_i;r=s.chop.bytes.map{|e|x=123-e;e<97||k<x ?e:(k-=x;97)};r[-1]+=k%26;puts r.map(&:chr)*''
|
s=gets;k=gets.to_i;r=s.bytes.map{|e|x=123-e;e<98||k<x ?e:(k-=x;97)};r[-2]+=k%26;puts r.map(&:chr)*''
|
[
"call.remove",
"literal.number.integer.change",
"assignment.value.change",
"control_flow.branch.if.condition.change",
"variable_access.subscript.index.change"
] | 1,504,156
| 1,504,157
|
u503549962
|
ruby
|
p03994
|
s=gets;k=gets.to_i;r=s.chop.bytes.map{|e|x=123-e;e<97||k<x ?e:(k-=x;97)};r[-1]+=k%26;puts r.map(&:chr)*''
|
s=gets;k=gets.to_i;r=s.chop.bytes.map{|e|x=123-e;e<98||k<x ?e:(k-=x;97)};r[-1]+=k%26;puts r.map(&:chr)*''
|
[
"literal.number.integer.change",
"assignment.value.change",
"control_flow.branch.if.condition.change"
] | 1,504,156
| 1,504,158
|
u503549962
|
ruby
|
p03994
|
s=gets.chomp.bytes.map{|b|b-97}
n=gets.to_i
s.size.times{|i|n>=m=(26-s[i])%26&&n-=m-s[i]=0}
s[-1]=(s[-1]+n)%26
puts s.map{|e|(e+97).chr}*''
|
s=gets.chomp.bytes.map{|b|b-97};n=gets.to_i;s.size.times{|i|n>=(m=(26-s[i])%26)&&n-=m-s[i]=0};s[-1]=(s[-1]+n)%26;puts s.map{|e|(e+97).chr}*''
|
[] | 1,504,168
| 1,504,169
|
u280667879
|
ruby
|
p03994
|
s=gets.chomp.bytes.map{|b|b-97}
n=gets.to_i
s.size.times{|i|n>=m=(26-s[i])%26&&n-=m-s[i]=0}
s[-1]=(s[-1]+n)%26
puts s.map{|e|(e+97).chr}*''
|
s=gets.chomp.bytes.map{|b|b-97}
n=gets.to_i
s.size.times{|i|n>=(m=(26-s[i])%26)&&n-=m-s[i]=0}
s[-1]=(s[-1]+n)%26
puts s.map{|e|(e+97).chr}*''
|
[] | 1,504,168
| 1,504,170
|
u280667879
|
ruby
|
p03994
|
WORD = gets.chomp
N = gets.chomp.to_i
def next_char(char, n = 1)
(n % 26).times do
case char
when 'a'..'y'
char = char.next
when 'z'
char = 'a'
end
end
char
end
def solve(word, n)
tmp_word = word
tmp_word.each_char.with_index do |char, i|
# a に変換するために消費する N (z.ord = 122)
required_n = 122 - tmp_word[i].ord + 1
if n >= required_n
word[i] = 'a'
n -= required_n
else
next
end
end
# それでも余れば最後の文字に足す
if (n >= 0)
word[-1] = next_char(word[-1], n)
end
return word
end
puts solve(WORD, N)
|
WORD = gets.chomp
N = gets.chomp.to_i
def next_char(char, n = 1)
(n % 26).times do
case char
when 'a'..'y'
char = char.next
when 'z'
char = 'a'
end
end
char
end
def solve(word, n)
tmp_word = word
tmp_word.each_char.with_index do |char, i|
# a に変換するために消費する N (z.ord = 122)
required_n = (122 - tmp_word[i].ord + 1) % 26
if n >= required_n
word[i] = 'a'
n -= required_n
else
next
end
end
# それでも余れば最後の文字に足す
if (n >= 0)
word[-1] = next_char(word[-1], n)
end
return word
end
puts solve(WORD, N)
|
[
"assignment.change"
] | 1,504,188
| 1,504,189
|
u345626364
|
ruby
|
p03994
|
s = STDIN.gets.strip
c = STDIN.gets.to_i
a = 'a'.codepoints.first
r = s.codepoints.inject([]) do |rs, char|
d = char - a - 26
if char == a
rs << char
elsif (c + d) <= 0
rs << char
else
c = c + d
rs << a
end
end
if 0 < c
r[-1] = r.last + (c % 26)
end
puts r.map(&:chr).join
|
s = STDIN.gets.strip
c = STDIN.gets.to_i
a = 'a'.codepoints.first
r = s.codepoints.inject([]) do |rs, char|
d = char - a - 26
if char == a
rs << char
elsif (c + d) < 0
rs << char
else
c = c + d
rs << a
end
end
if 0 < c
r[-1] = r.last + (c % 26)
end
puts r.map(&:chr).join
|
[
"expression.operator.compare.change",
"assignment.value.change",
"control_flow.branch.if.condition.change"
] | 1,504,254
| 1,504,255
|
u039293076
|
ruby
|
p04005
|
a, b, c = gets.split.map(&:to_i)
if a * b * c == 0
puts 0
else
puts [a * b, b * c, c * a].min
end
|
a, b, c = gets.split.map(&:to_i)
if a * b * c % 2 == 0
puts 0
else
puts [a * b, b * c, c * a].min
end
|
[
"control_flow.branch.if.condition.change"
] | 1,504,407
| 1,504,408
|
u889326464
|
ruby
|
p04005
|
a, b, c = gets.split.map(&:to_i)
if [a, b, c].all?(&:even?)
puts 0
else
puts [a * b, b * c, c * a].min
end
|
a, b, c = gets.split.map(&:to_i)
if [a, b, c].any?(&:even?)
puts 0
else
puts [a * b, b * c, c * a].min
end
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 1,504,409
| 1,504,410
|
u889326464
|
ruby
|
p04011
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if(k <= n)
puts x * k + y * (n - k)
else
puts x * k
end
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if(k <= n)
puts x * k + y * (n - k)
else
puts x * n
end
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,508,125
| 1,508,126
|
u458429268
|
ruby
|
p04011
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if n <= k
p n*x
else
p k*x + (k+1)*y
end
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if n <= k
p n*x
else
p k*x + (n-k)*y
end
|
[
"expression.operation.binary.remove"
] | 1,508,177
| 1,508,178
|
u390727364
|
ruby
|
p04011
|
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
puts a > b ? b*c+(a-b)*d : a*d
|
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
puts a > b ? b*c+(a-b)*d : a*c
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,508,313
| 1,508,314
|
u585819925
|
ruby
|
p04011
|
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
puts a > b ? a*c+(a-b)*d : a*d
|
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
puts a > b ? b*c+(a-b)*d : a*c
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,508,315
| 1,508,314
|
u585819925
|
ruby
|
p04011
|
n, k, x, y = 4.times.map(&:to_i)
puts n * x - [n - k, 0].max * (x - y)
|
n,k,x,y = 4.times.map{gets.to_i}
puts n*x - [n-k, 0].max * (x-y)
|
[] | 1,508,396
| 1,508,397
|
u984479733
|
ruby
|
p04011
|
N = gets.to_i
K = gets.to_i
X = gets.to_i
Y = gets.to_i
puts N>K ? (K*X) + (N-K)*Y : K*X
|
N = gets.to_i
K = gets.to_i
X = gets.to_i
Y = gets.to_i
puts N>K ? (K*X) + (N-K)*Y : N*X
|
[
"call.arguments.change",
"expression.operation.binary.change"
] | 1,508,887
| 1,508,888
|
u814807759
|
ruby
|
p04011
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if n > k
puts (k*x) + ((n-k)*y)
else
puts k*x
end
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if n > k
puts (k*x) + ((n-k)*y)
else
puts n*x
end
|
[
"identifier.change",
"call.arguments.change",
"io.output.change"
] | 1,508,906
| 1,508,907
|
u471368568
|
ruby
|
p04011
|
require 'prime'
include Math
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a end
def gif; gets.to_i end
def gff; gets.to_f end
def gsf; gets.chomp end
def gi; gets.split.map(&:to_i) end
def gf; gets.split.map(&:to_f) end
def gs; gets.chomp.split.map(&:to_s) end
def gc; gets.chomp.split('') end
def pr(num); num.prime_division end
def digit(num); num.to_s.length end
def array(s,ini=nil); Array.new(s){ini} end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}} end
def rep(num); num.times{|i|yield(i)} end
def repl(st,en,n=1); st.step(en,n){|i|yield(i)} end
n = gif
k = gif
x = gif
y = gif
if n > k
puts y*(n-k)+x*k
else
puts x*k
end
|
require 'prime'
include Math
def max(a,b); a > b ? a : b end
def min(a,b); a < b ? a : b end
def swap(a,b); a, b = b, a end
def gif; gets.to_i end
def gff; gets.to_f end
def gsf; gets.chomp end
def gi; gets.split.map(&:to_i) end
def gf; gets.split.map(&:to_f) end
def gs; gets.chomp.split.map(&:to_s) end
def gc; gets.chomp.split('') end
def pr(num); num.prime_division end
def digit(num); num.to_s.length end
def array(s,ini=nil); Array.new(s){ini} end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}} end
def rep(num); num.times{|i|yield(i)} end
def repl(st,en,n=1); st.step(en,n){|i|yield(i)} end
n = gif
k = gif
x = gif
y = gif
if n > k
puts y*(n-k)+x*k
else
puts x*n
end
|
[
"identifier.change",
"call.arguments.change",
"io.output.change"
] | 1,508,954
| 1,508,955
|
u988228861
|
ruby
|
p04011
|
table = []
4.times do |t|
table.push = gets.chomp
end
N = table[0]
K = table[1]
X = table[2]
Y = table[3]
if N <= K
puts N*X
else
puts K*X + (N-K)*Y
end
|
table = []
4.times do |t|
table.push(gets.chomp.to_i)
end
N = table[0]
K = table[1]
X = table[2]
Y = table[3]
if N <= K
puts N*X
else
puts K*X + (N-K)*Y
end
|
[
"call.arguments.add"
] | 1,509,024
| 1,509,025
|
u451787864
|
ruby
|
p04011
|
n,k,x,y = 4.times.map { gets.to_i }
if n > k
puts (n - k) * y + k * x
else
puts k * x
end
|
n,k,x,y = 4.times.map { gets.to_i }
if n > k
puts (n - k) * y + k * x
else
puts n * x
end
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,509,030
| 1,509,031
|
u627981707
|
ruby
|
p04011
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
puts n
if n < k then
puts x*n
else
puts x*k + y*(n-k)
end
|
n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
if n < k then
puts x*n
else
puts x*k + y*(n-k)
end
|
[
"call.remove"
] | 1,509,053
| 1,509,054
|
u162612857
|
ruby
|
p04012
|
w = gets.chomp.chars.sort!
if w.size % 2 != 0
puts "No"
else
i = 0
while i < w.size
if w[i] != w[i+1]
break
end
i += 2
end
puts w
if i == w.size
puts "Yes"
else
puts "No"
end
end
|
w = gets.chomp.chars.sort!
if w.size % 2 != 0
puts "No"
else
i = 0
while i < w.size
if w[i] != w[i+1]
break
end
i += 2
end
if i == w.size
puts "Yes"
else
puts "No"
end
end
|
[
"call.remove"
] | 1,509,211
| 1,509,212
|
u059126963
|
ruby
|
p04012
|
line = gets.split('')
kind = line.sort.uniq
range = kind.size - 1
for i in 0..range do
count = line.count(kind[i])
if count % 2 != 0 then
puts "No"
break
end
if i == range then
puts "Yes"
end
end
|
line = gets.chomp.split('')
kind = line.sort.uniq
range = kind.size - 1
for i in 0..range do
count = line.count(kind[i])
if count % 2 != 0 then
puts "No"
break
end
if i == range then
puts "Yes"
end
end
|
[
"call.add"
] | 1,509,580
| 1,509,581
|
u308894173
|
ruby
|
p04012
|
moji=gets.chomp.chars
flag=0
moji.uniq.each do |n|
if moji.select{|b| b==n}.size.even?
flag=1
else
flag=0
break
end
end
flag==1 ? "Yes" : "No"
|
moji=gets.chomp.chars
flag=0
moji.uniq.each do |n|
if moji.select{|b| b==n}.size.even?
flag=1
else
flag=0
break
end
end
puts flag==1 ? "Yes" : "No"
|
[
"io.output.change",
"call.add"
] | 1,509,669
| 1,509,670
|
u085647568
|
ruby
|
p04012
|
moji=gets.chomp.chars
flag=0
moji.uniq.each do |n|
if moji.select{|b| b=n}.size.even?
flag=1
else
flag=0
break
end
end
if flag=1
puts "Yes"
else
puts "No"
end
|
moji=gets.chomp.chars
flag=0
moji.uniq.each do |n|
if moji.select{|b| b==n}.size.even?
flag=1
else
flag=0
break
end
end
if flag==1
puts "Yes"
else
puts "No"
end
|
[
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 1,509,671
| 1,509,672
|
u085647568
|
ruby
|
p04012
|
moji=gets.chomp.chars
flag=0
moji.each do |n|
if moji.select{|b| b=n}.size.even?
flag=1
else
flag=0
break
end
end
if flag=1
puts "Yes"
else
puts "No"
end
|
moji=gets.chomp.chars
flag=0
moji.uniq.each do |n|
if moji.select{|b| b==n}.size.even?
flag=1
else
flag=0
break
end
end
if flag==1
puts "Yes"
else
puts "No"
end
|
[
"call.add",
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 1,509,673
| 1,509,672
|
u085647568
|
ruby
|
p04012
|
w = gets.chomp
variation = w.split('').uniq
flag = true
variation.each do |str|
if w.count(str) % 2 != 0
puts 'No'
flag = false
end
end
if flag
puts 'Yes'
end
|
w = gets.chomp
variation = w.split('').uniq
flag = true
variation.each do |str|
if w.count(str) % 2 != 0
puts 'No'
flag = false
break
end
end
if flag
puts 'Yes'
end
|
[
"control_flow.break.add"
] | 1,509,719
| 1,509,720
|
u866325115
|
ruby
|
p04012
|
a=gets.chomp
b=a.split("").uniq
for i in 0..(b.length-1)
if a.count(b[0]) % 2 != 0
puts "No"
exit
end
end
puts "Yes"
|
a=gets.chomp
b=a.split("").uniq
for i in 0..(b.length-1)
if a.count(b[i]) % 2 != 0
puts "No"
exit
end
end
puts "Yes"
|
[
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 1,509,921
| 1,509,922
|
u585819925
|
ruby
|
p04012
|
w = gets.chomp.chars
puts w.all? {|e| w.count(e) % 2 == 0} ? "YES" : "NO"
|
w = gets.chomp.chars
puts w.all? {|e| w.count(e) % 2 == 0} ? "Yes" : "No"
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 1,509,981
| 1,509,982
|
u819939299
|
ruby
|
p04012
|
w = gets.split('')
h = Hash.new
w.each do |c|
h.key?(c) ? h[c] += 1 : h[c] = 1
end
puts h.values.select{|v| v.odd?}.empty? ? "Yes" : "No"
|
s = gets.chomp.split('')
h = Hash.new
s.each do |c|
h.key?(c) ? h[c] += 1 : h[c] = 1
end
puts h.values.select{|v| v.odd?}.empty? ? "Yes" : "No"
|
[
"assignment.variable.change",
"identifier.change",
"call.add"
] | 1,510,069
| 1,510,070
|
u502306384
|
ruby
|
p04012
|
s = gets.split('')
h = Hash.new
s.each do |c|
h.key?(c) ? h[c] += 1 : h[c] = 1
end
puts h.values.select{|v| v.odd?}.empty? ? "Yes" : "No"
|
s = gets.chomp.split('')
h = Hash.new
s.each do |c|
h.key?(c) ? h[c] += 1 : h[c] = 1
end
puts h.values.select{|v| v.odd?}.empty? ? "Yes" : "No"
|
[
"call.add"
] | 1,510,071
| 1,510,070
|
u502306384
|
ruby
|
p04012
|
w = gets.split('')
h = Hash.new(0)
w.each do |c|
h[c] += 1
end
puts h.select{|k, v| v%2 == 1}.size == 0 ? "Yes" : "No"
|
w = gets.chomp.split('')
h = Hash.new(0)
w.each do |c|
h[c] += 1
end
puts h.select{|k, v| v%2 == 1}.size == 0 ? "Yes" : "No"
|
[
"call.add"
] | 1,510,072
| 1,510,073
|
u502306384
|
ruby
|
p04012
|
w = gets.strip
count = {}
w.size.times{|i|
count[w[i]] ||= 0
count[w[i]] += 1
}
if count.map { |k,v|
v % 2 == 0
}.all?
puts "YES"
else
puts "NO"
end
|
w = gets.strip
count = {}
w.size.times{|i|
count[w[i]] ||= 0
count[w[i]] += 1
}
if count.map { |k,v|
v % 2 == 0
}.all?
puts "Yes"
else
puts "No"
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 1,510,159
| 1,510,160
|
u692439758
|
ruby
|
p04012
|
a = gets.split("").chomp
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add",
"call.remove"
] | 1,510,279
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add"
] | 1,510,281
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add"
] | 1,510,282
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
puts b
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add",
"call.remove"
] | 1,510,283
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add"
] | 1,510,284
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
puts "Yes"
|
a = gets.chomp.split("")
b = []
for i in 0..a.length-1
b.push(a.count(a[i]))
end
#puts b
for j in 0..b.length-1
if b[j] % 2 == 1
puts "No"
exit
end
end
#puts b
puts "Yes"
|
[
"call.add"
] | 1,510,285
| 1,510,280
|
u614043796
|
ruby
|
p04012
|
a = gets.chomp.split("")
b = []
c = 0
d = a.uniq
d.length.times do
if a.count(d[c]) % 2 == 0
c += 1
b.push("YES")
else
c += 1
b.push("NO")
end
end
if b.include?("NO")
puts "NO"
else
puts "YES"
end
|
a = gets.chomp.split("")
b = []
c = 0
d = a.uniq
d.length.times do
if a.count(d[c]) % 2 == 0
c += 1
b.push("YES")
else
c += 1
b.push("NO")
end
end
if b.include?("NO")
puts "No"
else
puts "Yes"
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 1,510,412
| 1,510,413
|
u271583170
|
ruby
|
p04012
|
dic = {}
gets.chomp.split("").map do |c|
dic[c] ||= 0
dic[c] += 1
end
beautiful = true
p dic
dic.values.each do |count|
if count.odd?
beautiful = false
break
end
end
puts beautiful ? 'Yes' : 'No'
|
dic = {}
gets.chomp.split("").map do |c|
dic[c] ||= 0
dic[c] += 1
end
beautiful = true
dic.values.each do |count|
if count.odd?
beautiful = false
break
end
end
puts beautiful ? 'Yes' : 'No'
|
[
"call.remove"
] | 1,510,452
| 1,510,453
|
u605918955
|
ruby
|
p04012
|
dic = {}
gets.split("").map do |c|
dic[c] ||= 0
dic[c] += 1
end
beautiful = true
dic.values.each do |count|
if count.odd?
beautiful = false
break
end
end
puts beautiful ? "Yes" : "No"
|
dic = {}
gets.chomp.split("").map do |c|
dic[c] ||= 0
dic[c] += 1
end
beautiful = true
dic.values.each do |count|
if count.odd?
beautiful = false
break
end
end
puts beautiful ? 'Yes' : 'No'
|
[
"call.add",
"literal.string.change",
"call.arguments.change"
] | 1,510,455
| 1,510,453
|
u605918955
|
ruby
|
p04012
|
w = gets.chomp.split("")
uniq_w = w.uniq
ans = "YES"
uniq_w.each do |a|
ans = "NO" if w.count(a) % 2 != 0
end
puts ans
|
w = gets.chomp.split("")
uniq_w = w.uniq
ans = "Yes"
uniq_w.each do |a|
ans = "No" if w.count(a) % 2 != 0
end
puts ans
|
[
"literal.string.change",
"literal.string.case.change",
"assignment.value.change"
] | 1,510,462
| 1,510,463
|
u379601169
|
ruby
|
p04012
|
w = gets.split('').map(&:to_s)
def f(str, arr)
len = arr.reduce(1) do |memo, item|
item == str ? memo + 1 : memo
end
if(len%2 == 0)
arr = arr.select do |item|
item != str
end
return arr.length == 0 ? true : f(arr.shift, arr)
else
return false
end
end
puts f(w.shift, w) ? "Yes" : "No"
|
w = gets.chomp.split('').map(&:to_s)
def f(str, arr)
len = arr.reduce(1) do |memo, item|
item == str ? memo + 1 : memo
end
if(len%2 == 0)
arr = arr.select do |item|
item != str
end
return arr.length == 0 ? true : f(arr.shift, arr)
else
return false
end
end
puts f(w.shift, w) ? "Yes" : "No"
|
[
"call.add"
] | 1,510,466
| 1,510,467
|
u860891996
|
ruby
|
p04013
|
N, A = gets.split.map(&:to_i)
x = [0] + gets.split.map(&:to_i)
X = (x + [A]).max
dp = Array.new(N + 1) do
Array.new(N + 1) do
Array.new(A * X + 1, 0)
end
end
dp[0][0][0] = 1
(1..N).each do |j|
(0..j).each do |k|
(0..(N*X)).each do |s|
dp[j][k][s] = case
when k == 0 && s == 0
1
when k == 0 || s == 0
0
when s < x[j]
dp[j-1][k][s]
when k >= 1 && s >= x[j]
dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]
end
end
end
end
p (1..N).map { |k| dp[N][k][k*A] }.inject(:+)
|
N, A = gets.split.map(&:to_i)
x = [0] + gets.split.map(&:to_i)
X = (x + [A]).max
dp = Array.new(N + 1) do
Array.new(N + 1) do
Array.new(N * 50 + 1, 0)
end
end
dp[0][0][0] = 1
(1..N).each do |j|
(0..j).each do |k|
(0..(N*X)).each do |s|
dp[j][k][s] = case
when k == 0 && s == 0
1
when k == 0 || s == 0
0
when s < x[j]
dp[j-1][k][s]
when k >= 1 && s >= x[j]
dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]
end
end
end
end
p (1..N).map { |k| dp[N][k][k*A] }.inject(:+)
|
[
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,511,549
| 1,511,548
|
u736611421
|
ruby
|
p04019
|
s = gets.chomp
if s.count("S") > 0 && s.count("N") == 0
puts :No
elsif s.count("N") > 0 && s.count("S") == 0
puts :No
elsif s.count("W") > 0 && s.count("E") == 0
puts :No
elsif s.count("E") > 0 && s.count("W") == 0
puts :No
end
puts :Yes
|
s = gets.chomp
if s.count("S") > 0 && s.count("N") == 0
puts :No
elsif s.count("N") > 0 && s.count("S") == 0
puts :No
elsif s.count("W") > 0 && s.count("E") == 0
puts :No
elsif s.count("E") > 0 && s.count("W") == 0
puts :No
else
puts :Yes
end
|
[] | 1,513,758
| 1,513,759
|
u489339677
|
ruby
|
p04019
|
# n = gets.split.map(&:to_i)
# array = readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
str = gets.chomp
n = 1
s = 1
w = 1
e = 1
str.length.times do |i|
if str[i] == 'S'
s = 0
elsif str[i] == 'N'
n = 0
elsif str[i] == 'W'
w = 0
elsif str[i] == 'E'
e = 0
end
end
if (s ^ n | w ^ e) == 0
puts "Yes"
else
puts "No"
end
|
# n = gets.split.map(&:to_i)
# array = readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
str = gets.chomp
n = 1
s = 1
w = 1
e = 1
str.length.times do |i|
if str[i] == 'S'
s = 0
elsif str[i] == 'N'
n = 0
elsif str[i] == 'W'
w = 0
elsif str[i] == 'E'
e = 0
end
end
if ((s ^ n) | (w ^ e)) == 0
puts "Yes"
else
puts "No"
end
|
[
"control_flow.branch.if.condition.change"
] | 1,513,816
| 1,513,817
|
u219902564
|
ruby
|
p04019
|
h = gets.chomp.chars.inject(Set.new) {|r, i| r << i }
if h.size == 4 || (h.size == 2 && ((h.include?('N') && h.include?('S')) || (h.include?('W') && h.include?('E'))))
puts 'Yes'
else
puts 'No'
end
|
require 'set'
h = gets.chomp.chars.inject(Set.new) {|r, i| r << i }
if h.size == 4 || (h.size == 2 && ((h.include?('N') && h.include?('S')) || (h.include?('W') && h.include?('E'))))
puts 'Yes'
else
puts 'No'
end
|
[
"call.add"
] | 1,513,921
| 1,513,922
|
u457499130
|
ruby
|
p04020
|
n = gets.to_i
a = Array.new(n){gets.to_i}
b = 0
cnt = 0
n.times do |i|
c = a[i]
d = b + c
cnt += d / 2
if d % 2 > 0
b = c > 0 ? 1 : 0
end
end
puts cnt
|
n = gets.to_i
a = Array.new(n){gets.to_i}
b = 0
cnt = 0
n.times do |i|
c = a[i]
d = b + c
cnt += d / 2
if d % 2 > 0
b = c > 0 ? 1 : 0
else
b = 0
end
end
puts cnt
|
[
"assignment.add"
] | 1,514,425
| 1,514,426
|
u979552932
|
ruby
|
p04020
|
n = gets.to_i
as = n.times.map { gets.to_i }
if as.count(0) == 0
p as.inject(&:+) / 2
else
l = 0
ans = 0
as.each_with_index do |ai, i|
if ai == 0
if i == 0
l = 1
else
ans += as[l..i].inject(&:+) / 2 if !as[l..i].empty?
# p as[l..i]
l = i+1
end
end
end
ans += as[l...n].inject(&:+) / 2 if !as[l..i].empty?
p ans
end
|
n = gets.to_i
as = n.times.map { gets.to_i }
if as.count(0) == 0
p as.inject(&:+) / 2
else
l = 0
ans = 0
as.each_with_index do |ai, i|
if ai == 0
if i == 0
l = 1
else
ans += as[l..i].inject(&:+) / 2 if !(as[l..i].empty?)
# p as[l..i]
l = i+1
end
end
end
ans += as[l...n].inject(&:+) / 2 if !(as[l...n].empty?)
p ans
end
|
[
"control_flow.branch.if.condition.change",
"variable_access.subscript.index.change"
] | 1,514,539
| 1,514,540
|
u706695185
|
ruby
|
p04020
|
N = gets.to_i
as = N.times.map{gets.to_i}
ans = 0
(N-1).times do |i|
ans += as[i] / 2
as[i] %= 2
if i < N-1 && as[i] > 0 && as[i+1] > 0
ans += 1
as[i+1] -= 1
end
end
puts ans
|
N = gets.to_i
as = N.times.map{gets.to_i}
ans = 0
N.times do |i|
ans += as[i] / 2
as[i] %= 2
if i < N-1 && as[i] > 0 && as[i+1] > 0
ans += 1
as[i+1] -= 1
end
end
puts ans
|
[] | 1,514,963
| 1,514,964
|
u314396879
|
ruby
|
p04020
|
N = gets.to_i
as = N.times.map{gets.to_i}
ans = 0
N.times do |i|
ans += as[i] / 2
as[i] %= 1
if i < N-1 && as[i] == 1 && as[i+1] > 0
ans += 1
as[i] -= 1
as[i+1] -= 1
end
end
puts ans
|
N = gets.to_i
as = N.times.map{gets.to_i}
ans = 0
N.times do |i|
ans += as[i] / 2
as[i] %= 2
if i < N-1 && as[i] == 1 && as[i+1] > 0
ans += 1
as[i] -= 1
as[i+1] -= 1
end
end
puts ans
|
[
"literal.number.integer.change"
] | 1,514,965
| 1,514,966
|
u314396879
|
ruby
|
p04026
|
S = " "+gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(0), m.end(0)] * " "; exit
end
puts "-1 -1"
|
S = gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(0)+1, m.end(0)] * " "; exit
end
puts "-1 -1"
|
[
"expression.operation.binary.remove"
] | 1,517,476
| 1,517,477
|
u670503797
|
ruby
|
p04026
|
S = gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(0), m.end(0)] * " "; exit
end
puts "-1 -1"
|
S = gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(0)+1, m.end(0)] * " "; exit
end
puts "-1 -1"
|
[
"expression.operation.binary.add"
] | 1,517,478
| 1,517,477
|
u670503797
|
ruby
|
p04026
|
S = gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(1), m.end(1)] * " "; exit
end
puts "-1 -1"
|
S = gets.chomp
m = S.match(/(.).?\1/)
if m
puts [m.begin(0)+1, m.end(0)] * " "; exit
end
puts "-1 -1"
|
[
"literal.number.integer.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 1,517,479
| 1,517,477
|
u670503797
|
ruby
|
p04029
|
a = gets.to_i
puts a*(a+1)/2
|
a = gets.to_i
puts a*(a+1)/2
|
[
"call.arguments.change"
] | 1,518,789
| 1,518,790
|
u875730451
|
ruby
|
p04029
|
n = gets.to_i
ans = 0
n.times do |i|
ans += (i+1)
end
p
|
n = gets.to_i
ans = 0
n.times do |i|
ans += (i+1)
end
puts ans
|
[
"call.function.change",
"io.output.change",
"call.arguments.change"
] | 1,519,053
| 1,519,054
|
u271044469
|
ruby
|
p04029
|
a=gets.chomp.to_i
puts (a(1+a))/2
|
a=gets.chomp.to_i
puts (a*(1+a))/2
|
[
"call.arguments.change"
] | 1,519,425
| 1,519,426
|
u585819925
|
ruby
|
p04029
|
N = readline.to_i
puts(N*(N-1)/2)
|
N = readline.to_i
puts(N*(N+1)/2)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 1,519,464
| 1,519,465
|
u565487528
|
ruby
|
p04029
|
n = gets.to_i
x = 0
1.upto(n) do |i|
x += i
end
x
|
n = gets.to_i
x = 0
1.upto(n) do |i|
x += i
end
puts x
|
[
"io.output.change",
"call.add"
] | 1,519,591
| 1,519,592
|
u703532536
|
ruby
|
p04030
|
input = gets.chomp.chars
output = []
input.each { |i|
if i == 'B' && output.size != 0
output.pop
elsif i == 'B' && output.size == 0
next
else
output << i
end
}
|
input = gets.chomp.chars
output = []
input.each { |i|
if i == 'B' && output.size != 0
output.pop
elsif i == 'B' && output.size == 0
next
else
output << i
end
}
puts output.join
|
[
"call.add"
] | 1,519,994
| 1,519,995
|
u443397222
|
ruby
|
p04030
|
s = gets.chomp.split(' ')
ans = s.inject([]) do |acc, s|
case s
when 'B'
acc.pop
else
acc << s.to_i
end
acc
end
puts ans.join
|
s = gets.chomp.split("")
ans = s.inject([]) do |acc, s|
case s
when 'B'
acc.pop
else
acc << s.to_i
end
acc
end
puts ans.join
|
[] | 1,520,066
| 1,520,067
|
u433171793
|
ruby
|
p04030
|
s = gets.split("")
arr = []
s.each do |v|
if v == "B"
arr.delete_at(-1)
else
arr << v
end
p arr
end
puts arr.join
|
s = gets.split("")
arr = []
s.each do |v|
if v == "B"
arr.delete_at(-1)
else
arr << v
end
end
puts arr.join
|
[
"call.remove"
] | 1,520,195
| 1,520,196
|
u012110567
|
ruby
|
p04030
|
a=gets.split(" ")
answer=[]
a.each do |n|
if n=="B"
answer.pop
else
answer << n
end
end
puts answer.join
|
a=gets.split("")
answer=[]
a.each do |n|
if n=="B"
answer.pop
else
answer << n
end
end
puts answer.join
|
[
"literal.string.change",
"assignment.value.change",
"call.arguments.change"
] | 1,520,235
| 1,520,236
|
u085647568
|
ruby
|
p04030
|
input = STDIN.gets.chomp.split('')
result = []
input.each do |n|
if n == '0'
result << '0'
end
if n == '1'
result << '1'
end
if n == 'B'
if result.length != 0
result.pop
end
end
end
p result.join("")
|
input = STDIN.gets.chomp.split('')
result = []
input.each do |n|
if n == '0'
result << '0'
end
if n == '1'
result << '1'
end
if n == 'B'
if result.length != 0
result.pop
end
end
end
puts result.join("")
|
[
"call.function.change",
"io.output.change"
] | 1,520,272
| 1,520,273
|
u853554960
|
ruby
|
p04030
|
out = ''
gets.chomp.chars.each do |c|
case c
when '0'
out += '0'
when '1'
out += '0'
when 'B'
out = out.chars[0..-2].join
end
end
puts out
|
out = ''
gets.chomp.chars.each do |c|
case c
when '0'
out += '0'
when '1'
out += '1'
when 'B'
out = out.chars[0..-2].join
end
end
puts out
|
[
"literal.string.change"
] | 1,520,274
| 1,520,275
|
u395702176
|
ruby
|
p04030
|
operations = gets.strip.split('')
line = ''
operations.each do |d|
case d
when 'b'
line = line[0..-2] if line != ''
when '1', '0'
line += d
end
end
puts line
|
operations = gets.strip.split('')
line = ''
operations.each do |d|
case d
when 'B'
line = line[0..-2] if line != ''
when '1', '0'
line += d
end
end
puts line
|
[
"literal.string.change",
"literal.string.case.change"
] | 1,520,597
| 1,520,598
|
u707614029
|
ruby
|
p04030
|
s = gets.chomp.chars
ans =[]
s.each do |i|
if i == "0"
ans.push("0")
elsif i == "1"
ans.push("1")
else i == "B"
ans.pop
end
end
p ans.join
|
s = gets.chomp.chars
ans =[]
s.each do |i|
if i == "0"
ans.push("0")
elsif i == "1"
ans.push("1")
else i == "B"
ans.pop
end
end
puts ans.join
|
[
"call.function.change",
"io.output.change"
] | 1,520,622
| 1,520,623
|
u191196346
|
ruby
|
p04030
|
gets.chop.chars.each do |c|
s.chop! if c==?B
s<<c unless c==?B
end
puts s
|
s=""
gets.chop.chars.each do |c|
s.chop! if c==?B
s<<c unless c==?B
end
puts s
|
[
"assignment.add"
] | 1,520,832
| 1,520,833
|
u647875062
|
ruby
|
p04030
|
w = []
gets.chomp.chars.each {|c| c=='B' ? w.pop : w<<c}
puts w
|
w = []
gets.chomp.chars.each {|c| c=='B' ? w.pop : w<<c}
puts w.join
|
[
"call.add"
] | 1,520,883
| 1,520,884
|
u056944756
|
ruby
|
p04031
|
# N 個の整数 a1,a2,..,aN が与えられます。えび君はこれらを書き換えて全て同じ整数にしようとしています。
# 各ai(1≦i≦N)は高々一回しか書き換えられません(書き換えなくても良い)。
# 整数xを整数yに書き換えるとき、コストが(x−y)2かかります。
# 仮にai=aj(i≠j)だとしても、ひとつ分のコストで同時に書き換えることは出来ません(入出力例2 を参照)。
# えび君が目的を達成するのに必要なコストの総和の最小値を求めてください。
n = gets.to_i
a = gets.chomp.split
n.times do |i|
a[i] = a[i].to_i
end
a_each_kinds = []
a.each do |num|
if !a_each_kinds.include?(num)
a_each_kinds << num
end
end
if a_each_kinds.length == 1
puts 0
else
costs = []
(0..100).each do |num|
cost = 0
n.times do |i|
cost += (a[i] - num) ** 2
end
costs << cost
end
puts costs.min
end
|
# N 個の整数 a1,a2,..,aN が与えられます。えび君はこれらを書き換えて全て同じ整数にしようとしています。
# 各ai(1≦i≦N)は高々一回しか書き換えられません(書き換えなくても良い)。
# 整数xを整数yに書き換えるとき、コストが(x−y)2かかります。
# 仮にai=aj(i≠j)だとしても、ひとつ分のコストで同時に書き換えることは出来ません(入出力例2 を参照)。
# えび君が目的を達成するのに必要なコストの総和の最小値を求めてください。
n = gets.to_i
a = gets.chomp.split
n.times do |i|
a[i] = a[i].to_i
end
a_each_kinds = []
a.each do |num|
if !a_each_kinds.include?(num)
a_each_kinds << num
end
end
if a_each_kinds.length == 1
puts 0
else
costs = []
(-100..100).each do |num|
cost = 0
n.times do |i|
cost += (a[i] - num) ** 2
end
costs << cost
end
puts costs.min
end
|
[
"expression.operation.unary.add"
] | 1,521,101
| 1,521,102
|
u139850627
|
ruby
|
p04031
|
N=gets.to_i
A=gets.split_map(&:to_i)
ans=10**9
cnt=0
for i in 0..200 do
cnt=0
for j in 0...N do
cnt+=(i-100-A[j])**2
end
ans=[ans,cnt].min
end
puts ans
|
N=gets.to_i
A=gets.split.map(&:to_i)
ans=10**9
cnt=0
for i in 0..200 do
cnt=0
for j in 0...N do
cnt+=(i-100-A[j])**2
end
ans=[ans,cnt].min
end
puts ans
|
[
"assignment.value.change",
"identifier.change",
"call.add"
] | 1,521,119
| 1,521,120
|
u041282550
|
ruby
|
p04031
|
N = gets.to_f
A = gets.split.map(&:to_i)
n = (A.inject(:+) / N).ceil
puts A.inject(0) {|r,a| r + (a - n).abs ** 2 }
|
N = gets.to_f
A = gets.split.map(&:to_i)
n = (A.inject(:+) / N).round
puts A.inject(0) {|r,a| r + (a - n) ** 2 }
|
[
"assignment.value.change",
"identifier.change",
"call.remove"
] | 1,521,459
| 1,521,460
|
u064100484
|
ruby
|
p04031
|
n = gets.to_i
a = gets.split.map(&:to_i).sort
ans = 100 * 200
(a.min..a.max).each do |y|
sum = 0
a.each do |x|
sum += (x - y) ** 2
end
ans = sum if sum < ans
end
puts ans
|
n = gets.to_i
a = gets.split.map(&:to_i).sort
ans = 10 ** 9
(a.min..a.max).each do |y|
sum = 0
a.each do |x|
sum += (x - y) ** 2
end
ans = sum if sum < ans
end
puts ans
|
[] | 1,521,465
| 1,521,466
|
u457499130
|
ruby
|
p04031
|
N = gets.to_i
num = 0
ary = gets.chop.split(" ").map(&:to_i)
y = ary.inject(0.0) { |sum, n| sum += n } / N
ary.each { |x| num += (x - y.ceil) ** 2 unless x == y }
puts num
|
N = gets.to_i
num = 0
ary = gets.chop.split(" ").map(&:to_i)
y = ary.inject(0.0) { |sum, n| sum += n } / N
ary.each { |x| num += (x - y.round) ** 2 unless x == y }
puts num
|
[
"identifier.change",
"expression.operation.binary.change"
] | 1,521,794
| 1,521,795
|
u814807759
|
ruby
|
p04030
|
s = gets
t = ""
s.each do |c|
if c == ?B
t.chop!
else
t += c
end
end
puts t
|
s = gets.chomp
t = ""
s.each_char do |c|
if c == ?B
t.chop!
else
t += c
end
end
puts t
|
[
"call.add",
"identifier.change"
] | 1,521,986
| 1,521,987
|
u608234874
|
ruby
|
p04030
|
command = gets.chomp.split("")
p command
string = ""
command.size.times do |i|
case command[i]
when "0" then
string << "0"
when "1" then
string << "1"
when "B" then
string.chop!
else
end
end
puts string
|
command = gets.chomp.split("")
string = ""
command.size.times do |i|
case command[i]
when "0" then
string << "0"
when "1" then
string << "1"
when "B" then
string.chop!
else
end
end
puts string
|
[
"call.remove"
] | 1,522,062
| 1,522,063
|
u743652948
|
ruby
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.