problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p00193
def g;gets.split.map &:to_i;end while(m,n=g)[0]>0 a=(1..g[0]).map{|i|g<<i} p (1..g[0]).map{d=a+[c=g<<11] (0..m*n).count{|k|i=k/n+1;j=k%n+1 d.min_by{|x,y,t|z=(y-j).abs [z+[(x-i).abs-(z+(i<x ?1-j%2:j%2))/2,0].max,t]}==c}}.max end
def g;gets.split.map &:to_i;end while(m,n=g)[0]>0 a=(1..g[0]).map{|i|g<<i} p (1..g[0]).map{d=a+[c=g<<11] (0..m*n-1).count{|k|i=k/n+1;j=k%n+1 d.min_by{|x,y,t|z=(y-j).abs [z+[(x-i).abs-(z+(i<x ?1-j%2:j%2))/2,0].max,t]}==c}}.max end
[]
41,788
41,789
u198069342
ruby
p00206
class NextTrip def solve while true target_price = gets.to_i break if target_price <= 0 calc(target_price) end end private def calc(target_price) answer = 'NA' 1.upto(12) do |month| m, n = gets.split.map(&:to_i) target_price -= (m - n) if target_price <= 0 && answer == 'NA' answer = month end end p answer end end next_trip = NextTrip.new next_trip.solve
class NextTrip def solve while true target_price = gets.to_i break if target_price <= 0 calc(target_price) end end private def calc(target_price) answer = 'NA' 1.upto(12) do |month| m, n = gets.split.map(&:to_i) target_price -= (m - n) if target_price <= 0 && answer == 'NA' answer = month end end puts answer end end next_trip = NextTrip.new next_trip.solve
[ "call.function.change", "io.output.change" ]
41,890
41,891
u728532181
ruby
p00205
puts readlines[0..-2].map(&:to_i).each_slice(5).map{|a|b=a.uniq.sort;b==[1,2]?a:b==[1,3]?a.map{|i|i==3?1:2}:a==[2,3]?a.map{|i|i==2?1:2}:[3]*5}
puts readlines[0..-2].map(&:to_i).each_slice(5).map{|a|b=a.uniq.sort;b==[1,2]?a:b==[1,3]?a.map{|i|i==3?1:2}:b==[2,3]?a.map{|i|i==2?1:2}:[3]*5}
[ "call.arguments.change", "io.output.change" ]
42,181
42,182
u780205791
ruby
p00227
class ProblemB def solve while true total = 0 n, m = gets.split.map(&:to_i) return total if n <= 0 pn = gets.split.map(&:to_i).sort {|a, b| b <=> a } while pn.count > 0 t = [] m.times do |i| t.push pn.shift break if pn.count <= 0 end t.pop if t.count == m t.each { |price| total += price } end total end end end thanksgiving = ProblemB.new thanksgiving.solve
class ProblemB def solve while true total = 0 n, m = gets.split.map(&:to_i) break if n <= 0 pn = gets.split.map(&:to_i).sort {|a, b| b <=> a } while pn.count > 0 t = [] m.times do t.push pn.shift break if pn.count <= 0 end t.pop if t.count == m t.each { |price| total += price } end p total end end end thanksgiving = ProblemB.new thanksgiving.solve
[ "control_flow.return.remove", "control_flow.break.add", "call.arguments.change", "io.output.change", "call.add" ]
43,278
43,277
u728532181
ruby
p00251
p 10.map{gets.to_i}.reduce(:+)
p ARGF.map(&:to_i).reduce(:+)
[ "call.arguments.change" ]
44,170
44,171
u300645821
ruby
p00251
p 10.map{gets.to_i}.reduce(:+)
p$<.map(&:to_i).reduce(:+)
[ "call.arguments.change", "call.add" ]
44,170
44,172
u300645821
ruby
p00242
### main while true n = gets.strip.to_i break if n == 0 words = [] hists = {} n.times do ws = gets.strip.split(' ') for w in ws if hists[w].nil? words << w hists[w] = 1 else hists[w] += 1 end end end #p words #p hists k = gets.strip kwords = words.select{|w| w[0] == k}.sort{|a, b| (cmp = hists[b] <=> hists[b]) != 0 ? cmp : a <=> b }[0, 5] #p kwords puts(kwords.empty? ? 'NA' : kwords.join(' ')) end
### main while true n = gets.strip.to_i break if n == 0 words = [] hists = {} n.times do ws = gets.strip.split(' ') for w in ws if hists[w].nil? words << w hists[w] = 1 else hists[w] += 1 end end end #p words #p hists k = gets.strip kwords = words.select{|w| w[0] == k}.sort{|a, b| (cmp = hists[b] <=> hists[a]) != 0 ? cmp : a <=> b }[0, 5] #p kwords puts(kwords.empty? ? 'NA' : kwords.join(' ')) end
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
44,691
44,692
u137027976
ruby
p00263
gets$<.map{|l|n=0.0;b=l.hex;(0..30).map{|i|n+=(i<7?0.5**(7-i):2**(i-7))*b[i]};p n*(-1)**b[31]}
gets $<.map{|l|n=0.0;b=l.hex;31.times{|i|n+=(i<7?0.5**(7-i):2**(i-7))*b[i]};p n*(-1)**b[31]}
[ "call.arguments.change", "identifier.change" ]
45,844
45,845
u879497299
ruby
p00263
gets $<.map{|l|n=0.0;b=l.hex;30.times{|i|n+=(i<7?0.5**(7-i):2**(i-7))*b[i]};p n*(-1)**b[31]}
gets $<.map{|l|n=0.0;b=l.hex;31.times{|i|n+=(i<7?0.5**(7-i):2**(i-7))*b[i]};p n*(-1)**b[31]}
[ "literal.number.integer.change" ]
45,846
45,845
u879497299
ruby
p00311
h1, h2 = gets.split.map(&:to_i) k1, k2 = gets.split.map(&:to_i) a, b, c, d, = gets.split.map(&:to_i) f = -> i, y { a * i + b * y + c * (i / 10) + d * (y / 20) } h = f[h1, h2] k = f[k1, k2] puts h > k ? 'hiroshi' : h < k ? 'kenjiro' : 'draw'
h1, h2 = gets.split.map(&:to_i) k1, k2 = gets.split.map(&:to_i) a, b, c, d, = gets.split.map(&:to_i) f = -> i, y { a * i + b * y + c * (i / 10) + d * (y / 20) } h = f[h1, h2] k = f[k1, k2] puts h > k ? 'hiroshi' : h < k ? 'kenjiro' : 'even'
[ "literal.string.change", "call.arguments.change" ]
47,276
47,277
u797180951
ruby
p00423
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?b+=i+j :a+=i&&b+=j} puts"#{a} #{b}" end
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?(b+=i+j):(a+=i)&&(b+=j)} puts"#{a} #{b}" end
[]
49,438
49,439
u198069342
ruby
p00423
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?b+=i+j :a+=i&&b+=j} puts"#{a} #{b}" end
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?b+=i+j :(a+=i)&&(b+=j)} puts"#{a} #{b}" end
[]
49,438
49,440
u198069342
ruby
p00423
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?b+=i+j :a+=i&&b+=j} puts"#{a} #{b}" end
while(n=gets.to_i)>0 a=b=0 n.times{i,j=gets.split.map &:to_i;i>j ?a+=i+j :i<j ?b+=i+j :(a+=i)&&b+=j} puts"#{a} #{b}" end
[]
49,438
49,441
u198069342
ruby
p00423
while str = gets do num = str.chomp.to_i a = 0 b = 0 num.times do |n| x, y = gets.chomp.split(" ").map(&:to_i) if x > y a += x + y elsif x < y b += x + y else a += x b += y end end puts [a, b].join(" ") end
while str = gets do num = str.chomp.to_i break if num == 0 a = 0 b = 0 num.times do |n| x, y = gets.chomp.split(" ").map(&:to_i) if x > y a += x + y elsif x < y b += x + y else a += x b += y end end puts [a, b].join(" ") end
[]
49,448
49,449
u720435069
ruby
p00425
while n=gets.to_i exit if n==0 sum=1 num=[1,2,3,4,5,6] n.times do dire=gets.chomp("") case dire when "North" then a=num[0] num[0]=num[1] num[1]=num[5] num[5]=num[4] num[4]=a when "East" then a=num[0] num[0]=num[3] num[3]=num[5] num[5]=num[2] num[2]=a when "West" then a=num[0] num[0]=num[2] num[2]=num[5] num[5]=num[3] num[3]=a when "South" then a=num[0] num[0]=num[4] num[4]=num[5] num[5]=num[1] num[1]=a when "Right" then a=num[1] num[1]=num[2] num[2]=num[4] num[4]=num[3] num[3]=a when "Left" then a=num[1] num[1]=num[3] num[3]=num[4] num[4]=num[2] num[2]=a end p num[0] sum+=num[0] end puts sum end
while n=gets.to_i exit if n==0 sum=1 num=[1,2,3,4,5,6] n.times do dire=gets.chomp("") case dire when "North" then a=num[0] num[0]=num[1] num[1]=num[5] num[5]=num[4] num[4]=a when "East" then a=num[0] num[0]=num[3] num[3]=num[5] num[5]=num[2] num[2]=a when "West" then a=num[0] num[0]=num[2] num[2]=num[5] num[5]=num[3] num[3]=a when "South" then a=num[0] num[0]=num[4] num[4]=num[5] num[5]=num[1] num[1]=a when "Right" then a=num[1] num[1]=num[2] num[2]=num[4] num[4]=num[3] num[3]=a when "Left" then a=num[1] num[1]=num[3] num[3]=num[4] num[4]=num[2] num[2]=a end sum+=num[0] end puts sum end
[ "call.remove" ]
50,861
50,862
u207440174
ruby
p00435
arr = [*"a".."z"] puts str.tr(arr.join(""), arr.rotate(-3).join(""))
arr = [*"A".."Z"] puts gets.chomp.tr(arr.join(""), arr.rotate(-3).join(""))
[ "literal.string.change", "literal.string.case.change", "assignment.value.change", "identifier.change", "call.arguments.change", "io.output.change", "call.add" ]
51,288
51,289
u814658648
ruby
p00435
arr = [*"a".."z"] puts gets.chomp.tr(arr.join(""), arr.rotate(-3).join(""))
arr = [*"A".."Z"] puts gets.chomp.tr(arr.join(""), arr.rotate(-3).join(""))
[ "literal.string.change", "literal.string.case.change", "assignment.value.change" ]
51,290
51,289
u814658648
ruby
p00446
#!/usr/bin/ruby M=999 while(n=gets.to_i)>0 do a=(1..(2*n)).map.to_a b=[];n.times{b.push(gets.to_i)} h=[b,a-b];f=0;m=0 while true do x=h[f].map{|e|e>m ?e: M}.min if x<M then h[f]-=[x];m=x else m=0 end if h[f].size==0 then p h[1].size,h[0].size;exit end f^=1 end end
#!/usr/bin/ruby M=999 while(n=gets.to_i)>0 do a=(1..(2*n)).map.to_a b=[];n.times{b.push(gets.to_i)} h=[b,a-b];f=0;m=0 while true do x=h[f].map{|e|e>m ?e: M}.min if x<M then h[f]-=[x];m=x else m=0 end if h[f].size==0 then p h[1].size,h[0].size;break end f^=1 end end
[ "control_flow.exit.remove", "control_flow.break.add" ]
52,517
52,518
u300645821
ruby
p00478
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets.strip.to_s if str.index(target_str) count += 1 end end p count
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets.strip.to_s if (str+str).index(target_str) count += 1 end end p count
[ "control_flow.branch.if.condition.change" ]
54,710
54,711
u476528774
ruby
p00478
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets.to_s if str.index(target_str) count += 1 end end p count
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets.strip.to_s if (str+str).index(target_str) count += 1 end end p count
[ "call.add", "control_flow.branch.if.condition.change" ]
54,713
54,711
u476528774
ruby
p00478
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets..strip.to_s if (str+str).index(target_str) count += 1 end end p count
target_str = gets.strip.to_s N = gets.to_i count = 0 N.times do |i| str = gets.strip.to_s if (str+str).index(target_str) count += 1 end end p count
[]
54,715
54,711
u476528774
ruby
p00484
### constant MAXGE = 10 ### main n, k = gets.strip.split(' ').map{|s| s.to_i} books = MAXGE.times.map{[]} nge = 0 n.times do ci, gi = gets.strip.split(' ').map{|s| s.to_i} books[gi - 1] << ci nge = gi if nge < gi end for g in (1...nge) books[g].sort!{|a, b| b <=> a} end #p nge #p books costs = [0] for g in (0...nge) bs = books[g] bslen = bs.length costs0 = costs.clone clen = costs.length csum = 0 for nbk in (0...bslen) csum += bs[nbk] csum0 = csum + nbk * (nbk + 1) for i in (0...clen) j = i + nbk + 1 break if j > k nc = costs[i] + csum0 if costs0[j].nil? || costs0[j] < nc costs0[j] = nc end end end costs = costs0 end #p costs puts costs[k]
### constant MAXGE = 10 ### main n, k = gets.strip.split(' ').map{|s| s.to_i} books = MAXGE.times.map{[]} nge = 0 n.times do ci, gi = gets.strip.split(' ').map{|s| s.to_i} books[gi - 1] << ci nge = gi if nge < gi end for g in (0...nge) books[g].sort!{|a, b| b <=> a} end #p nge #p books costs = [0] for g in (0...nge) bs = books[g] bslen = bs.length costs0 = costs.clone clen = costs.length csum = 0 for nbk in (0...bslen) csum += bs[nbk] csum0 = csum + nbk * (nbk + 1) for i in (0...clen) j = i + nbk + 1 break if j > k nc = costs[i] + csum0 if costs0[j].nil? || costs0[j] < nc costs0[j] = nc end end end costs = costs0 #p [g, costs] end puts costs[k]
[ "literal.number.integer.change" ]
55,959
55,960
u137027976
ruby
p00511
a=$<.map(&:strip) r=a[0] c=1 while 2*c<a.size r=eval(r+a[2*c-1]+a[2*c]).to_s c+=1 end p r
a=$<.map(&:strip) r=a[0] c=1 while 2*c<a.size r=eval(r+a[2*c-1]+a[2*c]).to_s c+=1 end puts r
[ "call.function.change", "io.output.change" ]
58,015
58,016
u505648358
ruby
p00507
n=gets.to_i a=[] n.times{a.push(gets.to_i)} res=[] a=a.sort[0..3] a.permutation(2){|num|res.push(num.join.to_i)} p res,res.sort[2]
n=gets.to_i a=[] n.times{a.push(gets.to_i)} res=[] a=a.sort[0..3] a.permutation(2){|num|res.push(num.join.to_i)} p res.sort[2]
[ "call.arguments.change" ]
58,549
58,550
u067629267
ruby
p00534
n, m = gets.split.map(&:to_i) d = [] h = [] n.times{ d << gets.to_i } m.times{ h << gets.to_i } dp = Array.new(2){ Array.new(m, 1<<31) } table = Array.new(n){ Array.new(m) } n.times do |i| m.times do |j| table[i][j] = d[i] * h[j] end end m.times{ |i| dp[0][i] = table[0][i] } (0...n-1).each do |j| (j+1..m-n+j+1).each do |k| (k+1..m-n+j+1).each do |i| dp[j%2^1][i] = [dp[j%2^1][i], dp[j%2][k] + table[j+1][i]].min end end dp[j%2].fill(1<<31) end p dp[n%2^1][n-1..-1].min
n, m = gets.split.map(&:to_i) d = [] h = [] n.times{ d << gets.to_i } m.times{ h << gets.to_i } dp = Array.new(2){ Array.new(m, 1<<31) } table = Array.new(n){ Array.new(m) } n.times do |i| m.times do |j| table[i][j] = d[i] * h[j] end end m.times{ |i| dp[0][i] = table[0][i] } (0...n-1).each do |j| (j..m-n+j+1).each do |k| (k+1..m-n+j+1).each do |i| dp[j%2^1][i] = [dp[j%2^1][i], dp[j%2][k] + table[j+1][i]].min end end dp[j%2].fill(1<<31) end p dp[n%2^1][n-1..-1].min
[ "expression.operation.binary.remove" ]
59,633
59,634
u811434779
ruby
p00593
class Map def initialize(x,y,number,move) @x = x @y = y @move = move @number = number end attr_accessor :x,:y,:move,:number def +(map) x = self.x + map.x y = self.y + map.y m = self.move n = self.number + 1 tmp = Map.new(x,y,n,m) end end @b = [] @b << Map.new(1,0, 1,0) #sita @b << Map.new(0,1, 1,1) #migi @b << Map.new(1,-1,1,2) #hidarisita @b << Map.new(-1,1,1,3) #migiue def work(map,m) n=m-1 if map.move==3 && map.x!=0 && map.y!=n then return map+@b[3] elsif map.move==2 && map.y!=0 && map.x!=n then return map+@b[2] elsif (map.move==3&&map.x==0)||(map.move==2&&map.x==n) then if map.move==3 then move = 2 else move = 3 end temp = map + @b[1] temp.move = move if map.y==n then temp.move = 2 temp.x = 1 temp.y = n return temp else return temp end else if map.move==3 then move = 2 else move = 3 end temp = map + @b[0] temp.move = move return temp end end $m = Map.new(0,0,1,2) $n = 3 def w(m,n) return work( m, n ) end $COU = 0 def printmap(n) $COU = $COU + 1 puts "Case %d" % $COU c=[$m] i=1 while i<n*n c << w(c[i-1],n) i = i+1 end i=0 while i < n for mapp in c do if mapp.y==i then print "%3d" % mapp.number end end puts i=i+1 end end while true a = gets.to_i if a==0 then break end printmap(a) end
class Map def initialize(x,y,number,move) @x = x @y = y @move = move @number = number end attr_accessor :x,:y,:move,:number def +(map) x = self.x + map.x y = self.y + map.y m = self.move n = self.number + 1 tmp = Map.new(x,y,n,m) end end @b = [] @b << Map.new(1,0, 1,0) #sita @b << Map.new(0,1, 1,1) #migi @b << Map.new(1,-1,1,2) #hidarisita @b << Map.new(-1,1,1,3) #migiue def work(map,m) n=m-1 if map.move==3 && map.x!=0 && map.y!=n then return map+@b[3] elsif map.move==2 && map.y!=0 && map.x!=n then return map+@b[2] elsif (map.move==3&&map.x==0)||(map.move==2&&map.x==n) then if map.move==3 then move = 2 else move = 3 end temp = map + @b[1] temp.move = move if map.y==n then temp.move = 2 temp.x = 1 temp.y = n return temp else return temp end else if map.move==3 then move = 2 else move = 3 end temp = map + @b[0] temp.move = move return temp end end $m = Map.new(0,0,1,2) $n = 3 def w(m,n) return work( m, n ) end $COU = 0 def printmap(n) $COU = $COU + 1 puts "Case %d:" % $COU c=[$m] i=1 while i<n*n c << w(c[i-1],n) i = i+1 end i=0 while i < n for mapp in c do if mapp.y==i then print "%3d" % mapp.number end end puts i=i+1 end end while true a = gets.to_i if a==0 then break end printmap(a) end
[ "literal.string.change", "call.arguments.change", "expression.operation.binary.change" ]
61,417
61,418
u399045574
ruby
p00605
loop do n, k = gets.split.map(&:to_i) break if n == 0 s, ans = gets.split.map(&:to_i), "Yes" n.times do b = gets.split.map(&:to_i) k.times do |i| s[i] -= b[i] ans = "No" if s[i] < 0 end end p ans end
loop do n, k = gets.split.map(&:to_i) break if n == 0 s, ans = gets.split.map(&:to_i), "Yes" n.times do b = gets.split.map(&:to_i) k.times do |i| s[i] -= b[i] ans = "No" if s[i] < 0 end end puts ans end
[ "call.function.change", "io.output.change" ]
61,712
61,713
u814658648
ruby
p00605
loop{ n,k = gets.split.map(&:to_i) if n == 0 and k == 0 then break end s = gets.split.map(&:to_i) n.times do s = gets.split.each_with_index.map{|b,i| (s[i] - b.to_i())} end print s.all?{|a| a >= 0} ? "YES" : "NO" print "\n" }
loop{ n,k = gets.split.map(&:to_i) if n == 0 and k == 0 then break end s = gets.split.map(&:to_i) n.times do s = gets.split.each_with_index.map{|b,i| (s[i] - b.to_i())} end print s.all?{|a| a >= 0} ? "Yes" : "No" print "\n" }
[ "literal.string.change", "literal.string.case.change", "call.arguments.change", "io.output.change" ]
61,718
61,719
u533425205
ruby
p00595
def gcd(a, b) gcd(b, a) if b > a return b if (r = a % b).zero? gcd(b, r) end while str = gets do a, b = str.chomp.split(" ").to_i puts gcd(a, b) end
def gcd(a, b) gcd(b, a) if b > a return b if (r = a % b).zero? gcd(b, r) end while str = gets do a, b = str.chomp.split(" ").map(&:to_i) puts gcd(a, b) end
[ "assignment.value.change", "identifier.change", "call.arguments.add" ]
61,980
61,981
u720435069
ruby
p00627
class Q1041 def doIt n = gets.to_i / 4 while n > 1 calc n n = gets.to_i / 4 end end def calc(n) sum = 0 for i in 1..n sum += gets.to_i end puts sum end end Q1041.new.doIt
class Q1041 def doIt n = gets.to_i / 4 while n > 0 calc n n = gets.to_i / 4 end end def calc(n) sum = 0 for i in 1..n sum += gets.to_i end puts sum end end Q1041.new.doIt
[ "literal.number.integer.change", "expression.operation.binary.change" ]
62,076
62,077
u529386853
ruby
p00627
class Main def doIt n = gets.to_i / 4 while n > 1 calc n n = gets.to_i / 4 end end def calc(n) sum = 0 for i in 1..n sum += gets.to_i end puts sum end end Main.new.doIt
class Q1041 def doIt n = gets.to_i / 4 while n > 0 calc n n = gets.to_i / 4 end end def calc(n) sum = 0 for i in 1..n sum += gets.to_i end puts sum end end Q1041.new.doIt
[ "literal.number.integer.change", "expression.operation.binary.change" ]
62,078
62,077
u529386853
ruby
p00628
puts $_.chomp.split.map{ |i| i.length }.join(" ") until gets == "END OF INPUT\n"
puts $_.chomp.split(/ /).map{ |i| i.length }.join("") until gets == "END OF INPUT\n"
[ "call.arguments.add", "literal.string.change", "call.arguments.change", "io.output.change" ]
62,231
62,232
u814658648
ruby
p00628
puts $_.chomp.split.map{ |i| i.length }.join(" ") until gets == "END OF INPUT"
puts $_.chomp.split(/ /).map{ |i| i.length }.join("") until gets == "END OF INPUT\n"
[ "call.arguments.add", "literal.string.change", "call.arguments.change", "io.output.change", "expression.operation.binary.change" ]
62,233
62,232
u814658648
ruby
p00630
loop do name,type = gets.split break if type =='X' if name.include?('_') words = name.split('_') else name.gsub!(/(.)([A-Z])/,'\1 \2') words = name.split end case type when 'U' puts words.map(&:capitalize).join when 'L' words.map!(&:capitalize) words[0].downcase! puts words.join when 'D' words.map!(&:downcase) puts words.join('_') end end
loop do name,type = gets.split break if type =='X' if name.include?('_') words = name.split('_') else name.gsub!(/([A-Z])/,' \1') words = name.split end case type when 'U' puts words.map(&:capitalize).join when 'L' words.map!(&:capitalize) words[0].downcase! puts words.join when 'D' words.map!(&:downcase) puts words.join('_') end end
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
62,510
62,511
u907626292
ruby
p00630
def main loop do str,pattern = gets.chomp.split(' ') break if pattern.eql?('X') answers << case pattern when 'U' puts conversion_to_upper_camel_case(str) when 'L' puts conversion_to_lower_camel_case(str) when 'D' puts conversion_to_snake_case(str) end end end def split_word str words = [] word = '' str.length.times do |i| if str[i].match(/_/) words << word word = '' elsif str[i].match(/[A-Z]/) words << word unless i == 0 word = str[i] else word << str[i] end end words << word words end def conversion_to_upper_camel_case str words = split_word(str) words.map{|word|word.capitalize}.join end def conversion_to_lower_camel_case str conversion_word = '' words = split_word(str) words.each_with_index do |word, i| if i == 0 conversion_word << word.downcase else conversion_word << word.capitalize end end conversion_word end def conversion_to_snake_case str words = split_word(str) words.each.map{|word|word.downcase}.join('_') end main
def main loop do str,pattern = gets.chomp.split(' ') break if pattern.eql?('X') case pattern when 'U' puts conversion_to_upper_camel_case(str) when 'L' puts conversion_to_lower_camel_case(str) when 'D' puts conversion_to_snake_case(str) end end end def split_word str words = [] word = '' str.length.times do |i| if str[i].match(/_/) words << word word = '' elsif str[i].match(/[A-Z]/) words << word unless i == 0 word = str[i] else word << str[i] end end words << word words end def conversion_to_upper_camel_case str words = split_word(str) words.map{|word|word.capitalize}.join end def conversion_to_lower_camel_case str conversion_word = '' words = split_word(str) words.each_with_index do |word, i| if i == 0 conversion_word << word.downcase else conversion_word << word.capitalize end end conversion_word end def conversion_to_snake_case str words = split_word(str) words.each.map{|word|word.downcase}.join('_') end main
[ "expression.operation.binary.remove" ]
62,512
62,513
u913452775
ruby
p00717
def round(points) 3.times.each_with_object([points]){ |_, obj| obj << obj[-1].map{ |p| [-p[1], p[0]] } } end def same(a, b) a.size == b.size && a.zip(b).map { |(xa, ya), (xb, yb)| [xb - xa, yb - ya] }.uniq.size == 1 end while (n = gets.to_i) != 0 target = gets.to_i.times.map{ gets.split.map(&:to_i) } cand = n.times.map{ gets.to_i.times.map{ gets.split.map(&:to_i) } } (1..n).each do |i| [target, target.reverse].flat_map{ |t| round(t) }.each do |t| if same(t, cand[i]) puts i break end end end puts '+++++' end
def round(points) 3.times.each_with_object([points]){ |_, obj| obj << obj[-1].map{ |p| [-p[1], p[0]] } } end def same(a, b) a.size == b.size && a.zip(b).map { |(xa, ya), (xb, yb)| [xb - xa, yb - ya] }.uniq.size == 1 end while (n = gets.to_i) != 0 target = gets.to_i.times.map{ gets.split.map(&:to_i) } cand = n.times.map{ gets.to_i.times.map{ gets.split.map(&:to_i) } } (1..n).each do |i| [target, target.reverse].flat_map{ |t| round(t) }.each do |t| if same(t, cand[i - 1]) puts i break end end end puts '+++++' end
[ "control_flow.branch.if.condition.change" ]
65,404
65,405
u811434779
ruby
p00728
while true do n = gets.to_i if n == 0 break end max = 0 min = 10000 sum = 0 n.times do i = gets.to_i if i > max max = i elsif i < min min = i end sum += i end p (sum - min - max) / (n-2) end
while true do n = gets.to_i if n == 0 break end max = 0 min = 1000 sum = 0 n.times do i = gets.to_i if i > max max = i end if i < min min = i end sum += i end p (sum - min - max) / (n-2) end
[ "literal.number.integer.change", "assignment.value.change" ]
66,065
66,066
u430800998
ruby
p00728
result = [] loop do input = gets.chomp!.to_i ary = [] break unless input != 0 input.times do ary << gets.chomp!.to_i end ary.sort_by!{|a, b| a<=>b} ary.delete_at(0) ary.delete_at(ary.length-1) sum = 0 ary.each do |i| sum += i end result << sum / ary.length end result.each do |r| p r end
result = [] loop do input = gets.chomp!.to_i ary = [] break unless input != 0 input.times do ary << gets.chomp!.to_i end ary.sort!{|a, b| a<=>b} ary.delete_at(0) ary.delete_at(ary.length-1) sum = 0 ary.each do |i| sum += i end result << sum / ary.length end result.each do |r| p r end
[ "identifier.change" ]
66,067
66,068
u305943158
ruby
p00728
# coding: utf-8 loop do judge_num = gets.to_i if judge_num == 0 break end max_val = 0 min_val = 1001 sum = 0 judge_num.times do |i| value = gets.to_i if value > max_val max_val = value end if value < min_val min_val = value end sum += value end sum -= (min_val + max_val) p sum puts (sum / (judge_num - 2)).floor end
loop do judge_num = gets.chomp.to_i if judge_num == 0 break end max_val = 0 min_val = 1001 sum = 0 judge_num.times do |i| value = gets.chomp.to_i if value > max_val max_val = value end if value < min_val min_val = value end sum += value end sum -= (min_val + max_val) puts (sum / (judge_num - 2)).floor end
[ "call.add", "call.remove" ]
66,070
66,071
u214570992
ruby
p00728
while(n=gets.to_i)>0 p n.times.map{gets.to_i}.sort[1..-1].reduce(:+)/(n-2)end
while(n=gets.to_i)>0 p n.times.map{gets.to_i}.sort[1..-2].reduce(:+)/(n-2)end
[ "literal.number.integer.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
66,076
66,077
u300645821
ruby
p00740
answers = [] def get_answer(n, p, answers) owan = p index = 0 temoto = [] n.times do temoto << 0 end while true if owan == 0 owan += temoto[index] temoto[index] = 0 else if owan == 1 && temoto[index] == p -1 answers << index return answers end owan -= 1 temoto[index] += 1 end index += 1 index = 0 if index == n end end while true array = gets.chomp.split(" ").map(&:to_i) n = array[0].to_i p = array[1].to_i exit if n == 0 && p == 0 answers = get_answer(n,p, answers) p answers end answers.each do |ans| puts ans end
answers = [] def get_answer(n, p, answers) owan = p index = 0 temoto = [] n.times do temoto << 0 end while true if owan == 0 owan += temoto[index] temoto[index] = 0 else if owan == 1 && temoto[index] == p -1 answers << index return answers end owan -= 1 temoto[index] += 1 end index += 1 index = 0 if index == n end end while true array = gets.chomp.split(" ").map(&:to_i) n = array[0].to_i p = array[1].to_i break if n == 0 && p == 0 answers = get_answer(n,p, answers) end answers.each do |ans| puts ans end
[ "control_flow.exit.remove", "control_flow.break.add", "call.remove" ]
67,316
67,317
u864527629
ruby
p00740
answers = [] def get_answer(n, p, answers) owan = p index = 0 temoto = [] n.times do temoto << 0 end while true if owan == 0 owan += temoto[index] temoto[index] = 0 else if owan == 1 && temoto[index] == p -1 answers << index return answers end owan -= 1 temoto[index] += 1 end index += 1 index = 0 if index == n end end while true array = gets.chomp.split(" ").map(&:to_i) n = array[0].to_i p = array[1].to_i exit if n == 0 && p == 0 answers = get_answer(n,p, answers) end answers.each do |ans| puts ans end
answers = [] def get_answer(n, p, answers) owan = p index = 0 temoto = [] n.times do temoto << 0 end while true if owan == 0 owan += temoto[index] temoto[index] = 0 else if owan == 1 && temoto[index] == p -1 answers << index return answers end owan -= 1 temoto[index] += 1 end index += 1 index = 0 if index == n end end while true array = gets.chomp.split(" ").map(&:to_i) n = array[0].to_i p = array[1].to_i break if n == 0 && p == 0 answers = get_answer(n,p, answers) end answers.each do |ans| puts ans end
[ "control_flow.exit.remove", "control_flow.break.add" ]
67,318
67,317
u864527629
ruby
p00773
while true rateA,rateB,s = gets.split(" ").map(&:to_i) break if rateA ==0 && rateB == 0 && s == 0 a=[] $roop = 1 for i in 1..s/2 sa = i*(100+rateA)/100 (s/2..s).to_a.reverse.each do |j| sb = j*(100+rateA)/100 if sa + sb < s break end if sa + sb == s a.push([i,j]) break end end break if $roop == 0 end maximum = 0 for i in 0..a.length-1 b = [maximum, a[i][0]*(100+rateB)/100 + a[i][1]*(100+rateB)/100] maximum = b.max end puts(maximum) end
while true rateA,rateB,s = gets.split(" ").map(&:to_i) break if rateA ==0 && rateB == 0 && s == 0 a=[] $roop = 1 for i in 1..s/2 sa = i*(100+rateA)/100 (1..s-sa).to_a.reverse.each do |j| sb = j*(100+rateA)/100 if sa + sb < s break end if sa + sb == s a.push([i,j]) break end end break if $roop == 0 end maximum = 0 for i in 0..a.length-1 b = [maximum, a[i][0]*(100+rateB)/100 + a[i][1]*(100+rateB)/100] maximum = b.max end puts(maximum) end
[ "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove" ]
69,967
69,968
u557813454
ruby
p00990
n = gets.to_i s = gets.chomp gets candidates = gets.split.map(&:to_i) dp = [1] + [0] * 9 (0..s.size-1).each do |i| new_dp = [0] * 10 (s[i] == ?* ? candidates : [s[i].to_i]).each do |c| if (s.size - i).even? c = (c * 2).to_s.split("").map(&:to_i).inject(:+) end (0..9).each do |j| new_dp[(j + c) % 10] += dp[j] end end p dp = new_dp end p dp[0]
n = gets.to_i s = gets.chomp gets candidates = gets.split.map(&:to_i) dp = [1] + [0] * 9 (0..s.size-1).each do |i| new_dp = [0] * 10 (s[i] == ?* ? candidates : [s[i].to_i]).each do |c| if (s.size - i).even? c = (c * 2).to_s.split("").map(&:to_i).inject(:+) end (0..9).each do |j| new_dp[(j + c) % 10] += dp[j] end end dp = new_dp end p dp[0]
[ "io.output.change", "call.remove" ]
72,904
72,905
u797180951
ruby
p01048
require "prime" def num(x) Prime.prime_division(x).inject(1) { |s, x| s * (x[1] + 1) } end n = gets.to_i puts (1..1000).find { |x| num(x) == n }
require "prime" def num(x) Prime.prime_division(x).inject(1) { |s, x| s * (x[1] + 1) } end n = gets.to_i puts (1..10000).find { |x| num(x) == n }
[ "literal.number.integer.change", "call.arguments.change", "io.output.change" ]
73,200
73,201
u615727692
ruby
p01125
n = gets.to_i while n != 0 tmp = [] n.times do tmp.push(gets.split.map(&:to_i)) end m = gets.to_i ans = [] xy_first = [10,10] m.times do dir,val = gets.split(" ") val = val.to_i val.times do flag = 0 if dir == "N" xy_first[1] += 1 elsif dir == "E" xy_first[0] += 1 elsif dir == "S" xy_first[1] -= 1 elsif dir == "W" xy_first[0] -= 1 end #p "x = ",xy_first[0] , "y = " , xy_first[1] tmp.each do |xy| if xy == xy_first flag = 1 else flag = 0 end ans.push(flag) if flag == 1 end end end if n == ans.length puts "yes" else puts "no" end n = gets.to_i end
n = gets.to_i while n != 0 tmp = [] n.times do tmp.push(gets.split.map(&:to_i)) end m = gets.to_i ans = [] xy_first = [10,10] m.times do dir,val = gets.split(" ") val = val.to_i val.times do flag = 0 if dir == "N" xy_first[1] += 1 elsif dir == "E" xy_first[0] += 1 elsif dir == "S" xy_first[1] -= 1 elsif dir == "W" xy_first[0] -= 1 end tmp.each do |xy| if xy == xy_first flag = 1 xy.shift else flag = 0 end ans.push(flag) if flag == 1 end end end if n == ans.length puts "Yes" else puts "No" end n = gets.to_i end
[ "call.add", "literal.string.change", "literal.string.case.change", "call.arguments.change" ]
74,889
74,890
u876093185
ruby
p01125
n = gets.to_i while n != 0 tmp = [] n.times do tmp.push(gets.split.map(&:to_i)) end m = gets.to_i ans = [] xy_first = [10,10] m.times do dir,val = gets.split(" ") val = val.to_i val.times do flag = 0 if dir == "N" xy_first[1] += 1 elsif dir == "E" xy_first[0] += 1 elsif dir == "S" xy_first[1] -= 1 elsif dir == "W" xy_first[0] -= 1 end #p "x = ",xy_first[0] , "y = " , xy_first[1] tmp.each do |xy| if xy == xy_first flag = 1 else flag = 0 end ans.push(flag) if flag == 1 end end end if n == ans.length puts "Yes" else puts "No" end n = gets.to_i end
n = gets.to_i while n != 0 tmp = [] n.times do tmp.push(gets.split.map(&:to_i)) end m = gets.to_i ans = [] xy_first = [10,10] m.times do dir,val = gets.split(" ") val = val.to_i val.times do flag = 0 if dir == "N" xy_first[1] += 1 elsif dir == "E" xy_first[0] += 1 elsif dir == "S" xy_first[1] -= 1 elsif dir == "W" xy_first[0] -= 1 end tmp.each do |xy| if xy == xy_first flag = 1 xy.shift else flag = 0 end ans.push(flag) if flag == 1 end end end if n == ans.length puts "Yes" else puts "No" end n = gets.to_i end
[ "call.add" ]
74,891
74,890
u876093185
ruby
p01126
loop do n, m, a = gets.split.map(&:to_i) break if n == 0 && m == 0 && a == 0 d = m.times.map{gets.split.map(&:to_i)} d.sort! { |a, b| b[0] <=> a[0]} pos = 1 d.each do |dd| if dd[1] == pos pos = dd[2] elsif dd[2] == pos pos = dd[1] end end puts pos end
loop do n, m, a = gets.split.map(&:to_i) break if n == 0 && m == 0 && a == 0 d = m.times.map{gets.split.map(&:to_i)} d.sort! { |a, b| b[0] <=> a[0]} pos = a d.each do |dd| if dd[1] == pos pos = dd[2] elsif dd[2] == pos pos = dd[1] end end puts pos end
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
75,135
75,136
u672005134
ruby
p01132
def f(x) k = 0 k += x / 500 x %= 500 k += x / 100 x %= 100 k += x / 50 x %= 50 k + x / 10 end ans = [] loop { price = gets.to_i break if price == 0 a, b, c, d = gets.split.map &:to_i min = Float::INFINITY min_by = nil (0..a).each{|x| (0..b).each{|y| (0..c).each{|z| (0..d).each{|w| total = 10*x+50*y+100*z+500*w next if total < price net = f(total - price) - (x + y + z + w) if net < min min = net min_by = [x, y, z, w] end } } } } tmp = %w(10 50 100 500) ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact } puts ans.join("\n")
def f(x) k = 0 k += x / 500 x %= 500 k += x / 100 x %= 100 k += x / 50 x %= 50 k + x / 10 end ans = [] loop { price = gets.to_i break if price == 0 a, b, c, d = gets.split.map &:to_i min = Float::INFINITY min_by = nil (0..a).each{|x| (0..b).each{|y| (0..c).each{|z| (0..d).each{|w| total = 10*x+50*y+100*z+500*w next if total < price net = f(total - price) - (x + y + z + w) if net < min min = net min_by = [x, y, z, w] end } } } } tmp = %w(10 50 100 500) ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact.join } puts ans.join("\n")
[ "call.add" ]
76,210
76,211
u797180951
ruby
p01132
def calc(s,c) num=Array.new(4) num[3]=s/500 s=s-500*num[3] num[2]=s/100 s=s-100*num[2] num[1]=s/50 s=s-50*num[1] num[0]=s/10 return num end nf=false while(money=gets.to_i) if money==0 break end if nf print "\n" end c=gets.chomp.split(/ /).map{|i| i.to_i} m=[10,50,100,500] sum=0 for i in 0..3 sum+=c[i]*m[i] end t=calc(sum-money,c) for i in 0..3 if c[i]-t[i]>0 print m[i]," ",c[i]-t[i],"\n" end end end
def calc(s,c) num=Array.new(4) num[3]=s/500 s=s-500*num[3] num[2]=s/100 s=s-100*num[2] num[1]=s/50 s=s-50*num[1] num[0]=s/10 return num end nf=false while(money=gets.to_i) if money==0 break end if nf print "\n" end nf=true c=gets.chomp.split(/ /).map{|i| i.to_i} m=[10,50,100,500] sum=0 for i in 0..3 sum+=c[i]*m[i] end t=calc(sum-money,c) for i in 0..3 if c[i]-t[i]>0 print m[i]," ",c[i]-t[i],"\n" end end end
[ "assignment.add" ]
76,217
76,218
u815659735
ruby
p01140
loop { n, m = gets.split.map &:to_i break if n == 0 hs = (1..n).map { gets.to_i } ws = (1..m).map { gets.to_i } h_hash = Hash.new(0) (0..hs.size-1).each{|i| s = 0 (i..hs.size-1).each{|j| s += hs[j] h_hash[s] += 1 } } w_hash = Hash.new(0) (0..ws.size-1).each{|i| s = 0 (i..ws.size-1).each{|j| s += ws[j] w_hash[s] += 1 } } hs = h_hash.to_a.sort_by(&:first) ws = w_hash.to_a.sort_by(&:first) i = 0 j = 0 count = 0 while i < hs.size && j < ws.size if hs[i][0] == ws[j][0] count += hs[i][1] * ws[i][1] i += 1 j += 1 elsif hs[i][0] < ws[j][0] i += 1 else j += 1 end end p count }
loop { n, m = gets.split.map &:to_i break if n == 0 hs = (1..n).map { gets.to_i } ws = (1..m).map { gets.to_i } h_hash = Hash.new(0) (0..hs.size-1).each{|i| s = 0 (i..hs.size-1).each{|j| s += hs[j] h_hash[s] += 1 } } w_hash = Hash.new(0) (0..ws.size-1).each{|i| s = 0 (i..ws.size-1).each{|j| s += ws[j] w_hash[s] += 1 } } hs = h_hash.to_a.sort_by(&:first) ws = w_hash.to_a.sort_by(&:first) i = 0 j = 0 count = 0 while i < hs.size && j < ws.size if hs[i][0] == ws[j][0] count += hs[i][1] * ws[j][1] i += 1 j += 1 elsif hs[i][0] < ws[j][0] i += 1 else j += 1 end end p count }
[ "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
76,382
76,383
u797180951
ruby
p01314
s = Array.new(1001, 0) 1000.times do |i| sum = i (i+1).upto(1000) do |j| sum += j break if sum > 1000 s[sum] += 1 end end loop do n = gets.to_i break if n == 0 puts s[n] end
s = Array.new(1001, 0) 1.upto(999) do |i| sum = i (i+1).upto(1000) do |j| sum += j break if sum > 1000 s[sum] += 1 end end loop do n = gets.to_i break if n == 0 puts s[n] end
[ "literal.number.integer.change", "identifier.change", "call.arguments.add" ]
79,656
79,657
u672005134
ruby
p01314
s = Array.new(1001, 0) 1000.times do |i| sum = i (i+1).upto(1000) do |j| sum += j break if sum > 1000 s[sum] += 1 end end loop do n = gets.to_i break if n == 0 puts s[n] end
s = Array.new(1001, 0) 1.upto(500) do |i| sum = i (i+1).upto(500) do |j| sum += j break if sum > 1000 s[sum] += 1 end end loop do n = gets.to_i break if n == 0 puts s[n] end
[ "literal.number.integer.change", "identifier.change", "call.arguments.add", "call.arguments.change" ]
79,656
79,658
u672005134
ruby
p01314
counter = [0] * 1001 (1..499).each do |i| counter[i + (i + 1)] += 1 end (3..50).each do |i| (1..1000/i).each do |s| k = s num = 0 i.times{ num += k; k += 1} break if num > 1000 counter[j] += 1 end end while n = gets.to_i break if n == 0 p counter[n] end
counter = [0] * 1001 (1..499).each do |i| counter[i + (i + 1)] += 1 end (3..50).each do |i| (1..1000/i).each do |s| k = s num = 0 i.times{ num += k; k += 1} break if num > 1000 counter[num] += 1 end end while n = gets.to_i break if n == 0 p counter[n] end
[ "identifier.change", "variable_access.subscript.index.change" ]
79,659
79,660
u811434779
ruby
p01314
while true n = gets.to_i break if n==0 s = 2*n x = 2 ptn = 0 while x<sqrt(s) if s%x == 0 k2 = s/x-x+1 ptn += 1 if k2>0 && k2%2==0 end x += 1 end puts ptn end
include Math while true n = gets.to_i break if n==0 s = 2*n x = 2 ptn = 0 while x<sqrt(s) if s%x == 0 k2 = s/x-x+1 ptn += 1 if k2>0 && k2%2==0 end x += 1 end puts ptn end
[ "call.add" ]
79,661
79,662
u217294278
ruby
p01314
loop do n = gets.chomp.to_i break if n==0 ans = 0 for i in 1...n for j in (i+1)...n if (j*(j+1) - i*(i+1))/2==n ans+=1 end end end puts ans end
loop do n = gets.chomp.to_i break if n==0 ans = 0 for i in 0...n for j in (i+1)...n t = (j*(j+1) - i*(i+1))/2 if t==n ans+=1 end end end puts ans end
[ "literal.number.integer.change", "assignment.variable.change" ]
79,667
79,668
u553881259
ruby
p01448
s=Array.new(100001,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}
s=Array.new(100002,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}
[ "literal.number.integer.change", "assignment.value.change", "call.arguments.change" ]
83,786
83,787
u300645821
ruby
p01448
s=Array.new(100001,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}
#!/usr/bin/ruby s=Array.new(100002,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}
[ "literal.number.integer.change", "assignment.value.change", "call.arguments.change" ]
83,786
83,788
u300645821
ruby
p01448
s=Array.new(100001,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}
s=Array.new(100002,0) gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1} t=0;p 1.step(100000).reduce(0){|a,i|(t+=s[i])<i ? a : i}
[ "literal.number.integer.change", "assignment.value.change", "call.arguments.change" ]
83,786
83,789
u300645821
ruby
p01634
p=gets.chop puts p.size>5&&p.match(/[A-Z]/)&p.match(/[a-z]/)&p.match(/[0-9]/)?"VALID":"INVALID"
p=gets.chomp puts p.size>5&&p.match(/[A-Z]/)&&p.match(/[a-z]/)&&p.match(/[0-9]/) ? "VALID" : "INVALID"
[ "assignment.value.change", "identifier.change", "control_flow.branch.if.condition.change" ]
87,067
87,068
u392015442
ruby
p01634
p=gets.chop puts p.size>5&&p.match(/[A-Z]/)&p.match(/[a-z]/)&p.match(/[0-9]/) ? "VALID" : "INVALID"
p=gets.chomp puts p.size>5&&p.match(/[A-Z]/)&&p.match(/[a-z]/)&&p.match(/[0-9]/) ? "VALID" : "INVALID"
[ "assignment.value.change", "identifier.change", "control_flow.branch.if.condition.change" ]
87,069
87,068
u392015442
ruby
p01634
p=gets.chop puts p.size>5&&p.match(/[A-Z]/)&p.match(/[a-z]/)&p.match(/[0-9]/) ? "VALID" : "INVALID"
p=gets.chop puts p.size>5&&p.match(/[A-Z]/)&&p.match(/[a-z]/)&&p.match(/[0-9]/)?"VALID":"INVALID"
[ "control_flow.branch.if.condition.change" ]
87,069
87,070
u392015442
ruby
p02233
$fiba = [1,1] def fib(n) while $fiba.size<=n $fiba << $fiba[n-1] + $fiba[n-2] end return $fiba[n] end while gets puts fib($_.to_i) end
$fiba = [1,1] def fib(n) while $fiba.size<=n $fiba << $fiba[-1] + $fiba[-2] end return $fiba[n] end while gets puts fib($_.to_i) end
[]
92,620
92,621
u881491942
ruby
p02233
def f(n) if n == 1 return 1, 1 elsif n % 2 == 0 a, b = f(n / 2) return 2 * a * b - a ** 2, a ** 2 + b ** 2 else a, b = f(n / 2) return a ** 2 + b ** 2, 2 * a * b + b ** 2 end end puts f(gets.to_i)
def f(n) if n == 1 return 1, 1 elsif n % 2 == 0 a, b = f(n / 2) return 2 * a * b - a ** 2, a ** 2 + b ** 2 else a, b = f(n / 2) return a ** 2 + b ** 2, 2 * a * b + b ** 2 end end puts f(gets.to_i + 1)[0]
[ "expression.operation.binary.add" ]
92,622
92,623
u514597327
ruby
p02233
# coding: utf-8 #lines = <<'EOS' #4 #1 2 2 4 #2 1 4 #3 0 #4 1 3 #EOS def fib(n) if n == 1 or n == 2 1 else n_1 = 1 n_2 = 1 tmp = 0 for x in 3..n tmp = n_1 + n_2 n_2 = n_1 n_1 = tmp end tmp end end lines = $stdin.read array = lines.split("\n") N = array[0].to_i puts fib(N)
# coding: utf-8 #lines = <<'EOS' #4 #1 2 2 4 #2 1 4 #3 0 #4 1 3 #EOS def fib(n) if n == 1 or n == 2 1 else n_1 = 1 n_2 = 1 tmp = 0 for x in 3..n tmp = n_1 + n_2 n_2 = n_1 n_1 = tmp end tmp end end lines = $stdin.read array = lines.split("\n") N = array[0].to_i puts fib(N+1)
[ "expression.operation.binary.add" ]
92,628
92,629
u397596432
ruby
p02237
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A n = gets.chop.to_i a = [] n.times do u, k, *v = gets.chop.split.map(&:to_i) a << Array.new(n) { |i| (v.include?(i + 1)) ? 1 : 0 } end a.each { |i| i.join(' ') }
n = gets.chop.to_i a = [] n.times do u, k, *v = gets.chop.split.map(&:to_i) a << Array.new(n) { |i| (v.include?(i + 1)) ? 1 : 0 } end a.each { |i| puts i.join(' ') }
[ "io.output.change", "call.add" ]
93,723
93,724
u024281398
ruby
p02237
n = gets.to_i g = (1..n).map{ Array.new(N, 0) } n.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| g[u][vi] = 1 end end g.each do |r| puts r.join(" ") end
n = gets.to_i g = (1..n).map{ Array.new(n, 0) } n.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| g[u - 1][vi - 1] = 1 end end # p g g.each do |r| puts r.join(" ") end
[ "assignment.value.change", "call.arguments.change" ]
93,726
93,727
u864527629
ruby
p02237
n = gets.to_i g = (1..n).map{ Array.new(n, 0) } n.times do u, k, *v = gets.split(' ').map(&:to_i) p v v.each do |vi| g[u - 1][vi - 1] = 1 end end # p g g.each do |r| puts r.join(" ") end
n = gets.to_i g = (1..n).map{ Array.new(n, 0) } n.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| g[u - 1][vi - 1] = 1 end end # p g g.each do |r| puts r.join(" ") end
[ "call.remove" ]
93,728
93,727
u864527629
ruby
p02239
n = gets.to_i line = [] (1..n).each{ |i| line[i] = gets.split.map(&:to_i)[2..-1] } h = 0 visited = Array.new(n+1, -1) visited[1] = 0 while true f = false (1..n).each do |i| if visited[i] == h f = true line[i].each{ |j| visited[j] = h+1 if visited[i] == -1 } end end break unless f h += 1 end (1..n).each{ |i| puts "#{i} #{visited[i]}" }
n = gets.to_i line = [] (1..n).each{ |i| line[i] = gets.split.map(&:to_i)[2..-1] } h = 0 visited = Array.new(n+1, -1) visited[1] = 0 while true f = false (1..n).each do |i| if visited[i] == h f = true line[i].each{ |j| visited[j] = h+1 if visited[j] == -1 } end end break unless f h += 1 end (1..n).each{ |i| puts "#{i} #{visited[i]}" }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
94,724
94,725
u811434779
ruby
p02239
N = gets.to_i G = (1..N).map{ Array.new(N, 0) } N.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| G[u - 1][vi - 1] = 1 end end Q = [0] #?§????0?????\??£????????\??? D = Array.new(N, -1) D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨???????????? while Q.size > 0 cur = Q.shift (0..N-1).each do |dst| if G[cur][dst] == 1 && D[dst] == -1 D[dst] = D[cur] + 1 Q < dst end end end (0..N-1).each do |id| puts "#{id + 1} #{D[id]}" end # g.each do |r| # puts r.join(" ") # end
N = gets.to_i G = (1..N).map{ Array.new(N, 0) } N.times do u, k, *v = gets.split(' ').map(&:to_i) v.each do |vi| G[u - 1][vi - 1] = 1 end end Q = [0] #?§????0?????\??£????????\??? D = Array.new(N, -1) D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨???????????? while Q.size > 0 cur = Q.shift (0..N-1).each do |dst| if G[cur][dst] == 1 && D[dst] == -1 D[dst] = D[cur] + 1 Q << dst end end end (0..N-1).each do |id| puts "#{id + 1} #{D[id]}" end # g.each do |r| # puts r.join(" ") # end
[ "expression.operation.binary.change" ]
94,728
94,729
u864527629
ruby
p02239
#encoding: utf-8 $map = [] $vis = [false] * 100 $depth = [0] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end end def bfs(x) $depth[x] = 0 que = [x] $vis[x] = true while not que.empty? u, que = que.first, que.drop(1) $map[u].each_with_index do |node, idx| if node == 1 and not $vis[idx] $depth[idx] = $depth[u] + 1 $vis[idx] = true que << idx end end end end def solve build_map bfs(0) end solve (0..$n - 1).each do |node| puts "#{node + 1} #{$depth[node]}" end
#encoding: utf-8 $map = [] $depth = [-1] * 100 $vis = [false] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end end def bfs(x) $depth[x] = 0 que = [x] $vis[x] = true while not que.empty? u, que = que.first, que.drop(1) $map[u].each_with_index do |node, idx| if node == 1 and not $vis[idx] $depth[idx] = $depth[u] + 1 $vis[idx] = true que << idx end end end end def solve build_map bfs(0) end solve (0..$n - 1).each do |node| puts "#{node + 1} #{$depth[node]}" end
[ "assignment.add", "assignment.remove" ]
94,733
94,734
u284474275
ruby
p02239
#encoding: utf-8 $map = [] $depth = [0] * 100 $vis = [false] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end end def bfs(x) $depth[x] = 0 que = [x] $vis[x] = true while not que.empty? u, que = que.first, que.drop(1) $map[u].each_with_index do |node, idx| if node == 1 and not $vis[idx] $depth[idx] = $depth[u] + 1 $vis[idx] = true que << idx end end end end def solve build_map bfs(0) end solve (0..$n - 1).each do |node| puts "#{node + 1} #{$depth[node]}" end
#encoding: utf-8 $map = [] $depth = [-1] * 100 $vis = [false] * 100 def build_map $n = gets.rstrip.to_i $map = [] $n.times { $map << [0] * $n} (1..$n).each do |node| arr = gets.rstrip.split(/\s/).map(&:to_i) u, k = arr[0], arr[1] node = arr[2..-1] node.each { |v| $map[u - 1][v - 1] = 1} end end def bfs(x) $depth[x] = 0 que = [x] $vis[x] = true while not que.empty? u, que = que.first, que.drop(1) $map[u].each_with_index do |node, idx| if node == 1 and not $vis[idx] $depth[idx] = $depth[u] + 1 $vis[idx] = true que << idx end end end end def solve build_map bfs(0) end solve (0..$n - 1).each do |node| puts "#{node + 1} #{$depth[node]}" end
[ "assignment.value.change", "expression.operation.binary.change", "expression.operation.unary.add" ]
94,736
94,734
u284474275
ruby
p02241
# encoding: utf-8 class UFSet def initialize(sz) @sz = sz @par = [0] * sz (0..sz - 1).each { |idx| @par[idx] = idx} end def find(x) if @par[x] == x x else @par[x] = find(@par[x]) end end def same(x, y) find(x) == find(y) end def unite(x, y) fx = find(x) fy = find(y) @par[fx] = fy if fx != fy end end class Graph def initialize(v) @v = v @edge = [] end def add_edge(u, v, w) @edge << { from: u, to: v, weight: w} end def mst ans = 0 @edge = @edge.sort_by { |x| x[:weight]} ufset = UFSet.new(@v) @edge.each do |ee| u, v, c = ee[:from], ee[:to], ee[:weight] if not ufset.same(u, v) ans += c ufset.unite(u, v) else next end end ans end end def main n = gets.rstrip.to_i g = Graph.new(n) (0..n - 1).each do |row| r = gets.lstrip.rstrip.split(/\s/).map(&:to_i) r.each_with_index do |node, idx| g.add_edge(row, idx, node) if node > 0 end end puts g.mst end main
# encoding: utf-8 class UFSet def initialize(sz) @sz = sz @par = [0] * sz (0..sz - 1).each { |idx| @par[idx] = idx} end def find(x) if @par[x] == x x else @par[x] = find(@par[x]) end end def same(x, y) find(x) == find(y) end def unite(x, y) fx = find(x) fy = find(y) @par[fx] = fy if fx != fy end end class Graph def initialize(v) @v = v @edge = [] end def add_edge(u, v, w) @edge << { from: u, to: v, weight: w} end def mst_kruskal ans = 0 @edge = @edge.sort_by { |x| x[:weight]} ufset = UFSet.new(@v) @edge.each do |ee| u, v, c = ee[:from], ee[:to], ee[:weight] if not ufset.same(u, v) ans += c ufset.unite(u, v) else next end end ans end end def main n = gets.rstrip.to_i g = Graph.new(n) (0..n - 1).each do |row| r = gets.lstrip.rstrip.split(/\s/).map(&:to_i) r.each_with_index do |node, idx| g.add_edge(row, idx, node) if node >= 0 end end puts g.mst_kruskal end main
[ "identifier.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "call.arguments.change", "io.output.change" ]
95,269
95,270
u284474275
ruby
p02242
class Node attr_reader :id, :siblings attr_accessor :state def initialize(id) @id = id @siblings = [] @distances = {} @state = :white end def add(sibling, distance) @siblings << sibling @distances[sibling.id] = distance end def distance_from(other) @distances[other.id] end end if $PROGRAM_NAME == __FILE__ n = gets.to_i nodes = [] n.times do id, _, *rest = gets.chomp.split.map(&:to_i) nodes[id] ||= Node.new(id) node = nodes[id] rest.each_slice(2) do |sibling_id, distance| nodes[sibling_id] ||= Node.new(sibling_id) sibling = nodes[sibling_id] node.add(sibling, distance) end end distances = Array.new(n, Float::INFINITY) distances[0] = 0 nodes[0].state = :gray loop do current = nil min = Float::INFINITY nodes.each do |node| next if node.state == :black distance = distances[node.id] if distance < min min = distance current = node end end break unless current current.state = :black current_distance = distances[current.id] current.siblings.each do |sibling| next if sibling.state == :black distance = current_distance + sibling.distance_from(current) if distance < distances[sibling.id] distances[sibling.id] = distance sibling.state = :gray end end end puts distances.map.with_index {|distance, id| [id, distance].join(' ') }.join("\n") end
class Node attr_reader :id, :siblings attr_accessor :state def initialize(id) @id = id @siblings = [] @distances = {} @state = :white end def add(sibling, distance) @siblings << sibling @distances[sibling.id] = distance end def distance_from(other) @distances[other.id] end end if $PROGRAM_NAME == __FILE__ n = gets.to_i nodes = [] n.times do id, _, *rest = gets.chomp.split.map(&:to_i) nodes[id] ||= Node.new(id) node = nodes[id] rest.each_slice(2) do |sibling_id, distance| nodes[sibling_id] ||= Node.new(sibling_id) sibling = nodes[sibling_id] node.add(sibling, distance) end end distances = Array.new(n, Float::INFINITY) distances[0] = 0 nodes[0].state = :gray loop do current = nil min = Float::INFINITY nodes.each do |node| next if node.state == :black distance = distances[node.id] if distance < min min = distance current = node end end break unless current current.state = :black current_distance = distances[current.id] current.siblings.each do |sibling| next if sibling.state == :black distance = current_distance + current.distance_from(sibling) if distance < distances[sibling.id] distances[sibling.id] = distance sibling.state = :gray end end end puts distances.map.with_index {|distance, id| [id, distance].join(' ') }.join("\n") end
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change", "call.arguments.change" ]
95,489
95,490
u069176427
ruby
p02256
def geta(n=0) return $stdin.gets.to_i if n==0 ar = [] n.times do ar << $stdin.gets.chomp.split end return ar.flatten(1) if n<=1 return ar end @ar = geta(1).map(&:to_i) y,x = @ar.sort rems = [] while (rem=x%y)>0 rems << rem x = y y = rem end p rems.min
def geta(n=0) return $stdin.gets.to_i if n==0 ar = [] n.times do ar << $stdin.gets.chomp.split end return ar.flatten(1) if n<=1 return ar end @ar = geta(1).map(&:to_i) y,x = @ar.sort rems = [y] while (rem=x%y)>0 rems << rem x = y y = rem end p rems.min
[]
98,977
98,978
u232214601
ruby
p02256
def gcd(x, y) return x if y.zero? gcd(y, x % y) if x >= y end x, y = gets.split.map(&:to_i) puts gcd(x, y)
def gcd(x, y) return x if y.zero? gcd(y, x % y) if x >= y end x, y = gets.split.map(&:to_i).minmax.reverse puts gcd(x, y)
[ "call.add" ]
98,979
98,980
u139670451
ruby
p02256
def gcd(x, y) return x if y < 2; x, y = y, x if( y > x ) return gcd(y, x%y) end x, y = gets.split.map(&:to_i) printf "%d\n", gcd(x, y)
def gcd(x, y) return x if y < 1; x, y = y, x if( y > x ) return gcd(y, x%y) end x, y = gets.split.map(&:to_i) printf "%d\n", gcd(x, y)
[ "literal.number.integer.change", "control_flow.branch.if.condition.change" ]
98,985
98,986
u960312159
ruby
p02256
array = gets.chomp.split(" ").map(&:to_i) max = array.max min = array.min gcf = min while true do sur = max % min if sur == 0 return else max = min min = sur end end puts min.to_s
array = gets.chomp.split(" ").map(&:to_i) max = array.max min = array.min gcf = min while true do sur = max % min if sur == 0 break else max = min min = sur end end puts min.to_s
[ "control_flow.return.remove", "control_flow.break.add" ]
98,988
98,989
u720435069
ruby
p02255
def geta(n=0) return $stdin.gets.to_i if n==0 ar = [] n.times do ar << $stdin.gets.chomp.split end return ar.flatten(1) if n<=1 return ar end def insert(idx) return if idx-1<0 0.step(idx-1) do |i| if @ar[i] > @ar[idx] n = @ar.delete_at(idx) @ar.insert( i, n) return end end end n = geta(0) @ar = geta(1).to_i n.times do |i| insert(i) puts @ar.join(" ") end
def geta(n=0) return $stdin.gets.to_i if n==0 ar = [] n.times do ar << $stdin.gets.chomp.split end return ar.flatten(1) if n<=1 return ar end def insert(idx) return if idx-1<0 0.step(idx-1) do |i| if @ar[i] > @ar[idx] n = @ar.delete_at(idx) @ar.insert( i, n) return end end end n = geta(0) @ar = geta(1).map(&:to_i) n.times do |i| insert(i) puts @ar.join(" ") end
[ "assignment.value.change", "identifier.change", "call.arguments.add" ]
99,018
99,019
u232214601
ruby
p02255
n = gets.toi a = gets.split.map(&:to_i) puts a * ' ' (1..n-1).each do |i| j = i while j>=1 && a[j]<a[j-1] a[j-1], a[j] = a[j], a[j-1] j -= 1 end puts a * ' ' end
n = gets.to_i a = gets.split.map(&:to_i) puts a * ' ' (1..n-1).each do |i| j = i while j>=1 && a[j]<a[j-1] a[j-1], a[j] = a[j], a[j-1] j -= 1 end puts a * ' ' end
[ "assignment.value.change", "identifier.change" ]
99,022
99,023
u352522848
ruby
p02255
counts = 1 size = 0 array = [] def print_array(array) str = "" array.each{|s| str = str + "\s" + s.to_s } puts str.strip! end loop{ if counts == 1 then size = gets.to_i else array = gets.split("\s") end counts = counts + 1 if counts > 2 then break end } for i in 1..size - 1 do print_array(array) v = array[i].to_i j = i - 1 while (j >= 0 && array[j] > v ) do array[j+1] = array[j] j = j - 1 end array[j+1] = v end print_array(array)
counts = 1 size = 0 array = [] def print_array(array) str = "" array.each{|s| str = str + "\s" + s.to_s } puts str.strip! end loop{ if counts == 1 then size = gets.to_i else array = gets.split("\s") end counts = counts + 1 if counts > 2 then break end } for i in 1..size - 1 do print_array(array) v = array[i].to_i j = i - 1 while (j >= 0 && array[j].to_i > v ) do array[j+1] = array[j] j = j - 1 end array[j+1] = v end print_array(array)
[ "call.add" ]
99,026
99,027
u761810722
ruby
p02255
n = gets.to_i array = gets.chomp.split(' ').map(&:to_i) p array.join(' ') for i in 1..(n-1) do v = array[i] j = i - 1 while j >= 0 && array[j] > v array[j+1] = array[j] j -= 1 array[j+1] = v end p array.join(' ') end
n = gets.to_i array = gets.chomp.split(' ').map(&:to_i) puts array.join(' ') for i in 1..(n-1) do v = array[i] j = i - 1 while j >= 0 && array[j] > v array[j+1] = array[j] j -= 1 array[j+1] = v end puts array.join(' ') end
[ "call.function.change", "io.output.change" ]
99,033
99,034
u878851603
ruby
p02255
n = gets.to_i array = gets.chomp.split(' ').map(&:to_i) p array.join(' ') for i in 1..(n-1) do v = array[i] j = i - 1 while j >= 0 && array[j] > v array[j+1] = array[j] j -= 1 array[j+1] = v end p array.join(' ') end
n = gets.to_i array = gets.chomp.split(' ').map(&:to_i) puts array.join(' ') for i in 1..(n-1) do v = array[i] j = i - 1 while j >= 0 && array[j] > v array[j+1] = array[j] j -= 1 end array[j+1] = v puts array.join(' ') end
[ "call.function.change", "io.output.change", "call.remove" ]
99,033
99,036
u878851603
ruby
p02255
n = get.strip.to_i array = gets.split.map(&:to_i) puts array join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0&& array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
n = gets.strip.to_i array = gets.split.map(&:to_i) puts array.join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0 && array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
[ "assignment.value.change", "identifier.change", "call.add", "call.arguments.change" ]
99,037
99,038
u407138207
ruby
p02255
n = get.strip.to_i array = gets.split.map(&:to_i) puts array.join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0&& array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
n = gets.strip.to_i array = gets.split.map(&:to_i) puts array.join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0 && array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
[ "assignment.value.change", "identifier.change" ]
99,039
99,038
u407138207
ruby
p02255
n = get.strip.to_i array = gets.split.map(&:to_i) puts array.join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0 && array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
n = gets.strip.to_i array = gets.split.map(&:to_i) puts array.join(' ') for i in 1..n-1 do key = array[i] j = i while j > 0 && array[j-1] > key do array[j] = array[j-1] j -= 1 end array[j] = key puts array.join(' ') end
[ "assignment.value.change", "identifier.change" ]
99,040
99,038
u407138207
ruby
p02255
n = gets.to_i arr = gets.chomp.split.map(&:to_i) def puts_arr(arr) puts arr.join(' ') end def insertionSort(arr, n) 1.upto(n-1) do |i| v = arr[i] j = i-1 while j>=0 && arr[j] > v arr[j+1] = arr[j] j -= 1 end arr[j+1] = v puts_arr(arr) end end insertionSort(arr, n)
n = gets.to_i arr = gets.chomp.split.map(&:to_i) def puts_arr(arr) puts arr.join(' ') end def insertionSort(arr, n) 1.upto(n-1) do |i| v = arr[i] j = i-1 while j>=0 && arr[j] > v arr[j+1] = arr[j] j -= 1 end arr[j+1] = v puts_arr(arr) end end puts_arr(arr) insertionSort(arr, n)
[ "call.add" ]
99,041
99,042
u375068279
ruby
p02255
n = gets.to_i a = gets.split.map(&:to_i) def insertionSort(a,n) for k in 0..n-2 print "#{a[k]} " end print a[n-1] for i in 1..n-1 v = a[i] j = i-1 while j >= 0 && a[j] > v a[j+1] = a[j] j -= 1 a[j+1] = v end for k in 0..n-2 print "#{a[k]} " end print a[n-1] end end insertionSort(a,n)
n = gets.to_i a = gets.split.map(&:to_i) def insertionSort(a,n) for k in 0..n-2 print "#{a[k]} " end puts a[n-1] for i in 1..n-1 v = a[i] j = i-1 while j >= 0 && a[j] > v a[j+1] = a[j] j -= 1 a[j+1] = v end for k in 0..n-2 print "#{a[k]} " end puts a[n-1] end end insertionSort(a,n)
[ "identifier.change" ]
99,044
99,045
u536840698
ruby
p02255
input = [] while (n = gets.to_i) != 0 do input = gets.split.map(&:to_i) end for i in 1..input.size - 1 do v = input[i] j = i - 1 while j >= 0 && input[j] > v do input[j+1] = input[j] j -= 1 input[j+1] = v end puts input*" " end
input = [] while (n = gets.to_i) != 0 do input = gets.split.map(&:to_i) end puts input*" " for i in 1..input.size - 1 do v = input[i] j = i - 1 while j >= 0 && input[j] > v do input[j+1] = input[j] j -= 1 input[j+1] = v end puts input*" " end
[ "call.add" ]
99,060
99,061
u854817684
ruby
p02255
def intersection_sort(arr, n) for i in 1..(n-1) v = arr[i] j = i-1 while j >= 0 and arr[j] > v arr[j+1] = arr[j] j = j - 1 end arr[j+1] = v p arr.join(' ') end end n = gets.chomp.to_i arr = gets.chomp.split(' ').map(&:to_i).shift(n) p arr.join(' ') intersection_sort(arr, n)
def intersection_sort(arr, n) for i in 1..(n-1) v = arr[i] j = i-1 while j >= 0 and arr[j] > v arr[j+1] = arr[j] j = j - 1 end arr[j+1] = v puts arr.join(' ') end end n = gets.chomp.to_i arr = gets.chomp.split(' ').map(&:to_i).shift(n) puts arr.join(' ') intersection_sort(arr, n)
[ "call.function.change", "io.output.change" ]
99,065
99,063
u571712009
ruby
p02255
gets ar = gets.split.map(&:to_i) n = ar.size putout = ->{puts ar.join(" ")} putout.(ar) 1.upto(n - 1) do |i| v = ar[i] j = i - 1 while j >= 0 and ar[j] > v ar[j + 1] = ar[j] j -= 1 end ar[j + 1] = v putout.(ar) end
gets ar = gets.split.map(&:to_i) n = ar.size putout = ->{puts ar.join(" ")} putout.() 1.upto(n - 1) do |i| v = ar[i] j = i - 1 while j >= 0 and ar[j] > v ar[j + 1] = ar[j] j -= 1 end ar[j + 1] = v putout.() end
[ "call.arguments.change" ]
99,066
99,067
u864617427
ruby
p02257
include Math ans = 0 num, *ary = $<.map &:to_i ary.each do|i| for j in 2..sqrt(i).floor if i % j == 0 ans -= 1 break end ans += 1 end end puts ans
include Math ans = 0 num, *ary = $<.map &:to_i ary.each do|i| for j in 2..sqrt(i).floor if i % j == 0 ans -= 1 break end end ans += 1 end puts ans
[]
100,913
100,914
u699389099
ruby
p02257
n = gets.to_i ans = 0 n.times do if gets.to_i.prime? ans += 1 end end puts ans
require 'prime' n = gets.to_i ans = 0 n.times do if gets.to_i.prime? ans += 1 end end puts ans
[ "call.add" ]
100,915
100,916
u036194084
ruby
p02257
n = 0 gets.to_i.times do n+=1 if gets.to_i.prime? end puts n
require 'prime' n = 0 gets.to_i.times do n+=1 if gets.to_i.prime? end puts n
[ "call.add" ]
100,919
100,920
u873778695
ruby
p02257
Fixnum.class_eval { def is_prime? return true if self == 2 return false if self < 2 or self % 2 == 0 3.step(Math.sqrt(self).ceil, 2) { |i| return false if self % i == 0 } true end } STDIN.read.split("\s")[1..-1].map(&:to_i).map(&:is_prime?).select { |x| x }.size
Fixnum.class_eval { def is_prime? return true if self == 2 return false if self < 2 or self % 2 == 0 3.step(Math.sqrt(self).ceil, 2) { |i| return false if self % i == 0 } true end } puts STDIN.read.split("\s")[1..-1].map(&:to_i).map(&:is_prime?).select { |x| x }.size
[ "io.output.change", "call.add" ]
100,926
100,927
u275152649
ruby
p02257
require 'prime' n = gets.chomp.to_i data = Array.new n.times { |i| data[i] = gets.chomp.to_i } data.sort! prime = Prime.each(10000).to_a cnt=0 n.times { |i| limit = Math::sqrt(data[i]) j = 0 flg = 1 while j<prime.length && limit<prime[j] if data[i]%prime[j]==0 flg = 0 end j += 1 end if flg == 1 cnt += 1 end } puts cnt
require 'prime' n = gets.chomp.to_i data = Array.new n.times { |i| data[i] = gets.chomp.to_i } data.sort! prime = Prime.each(10000).to_a cnt=0 n.times { |i| limit = Math::sqrt(data[i]) j = 0 flg = 1 while j<prime.length && limit>=prime[j] if data[i]%prime[j]==0 flg = 0 break end j += 1 end if flg == 1 cnt += 1 end } puts cnt
[ "expression.operator.compare.change", "expression.operation.binary.change", "control_flow.break.add" ]
100,928
100,929
u843848664
ruby
p02257
require 'prime' primes = [] Prime.each(10000){|i| primes.push(i) } n = gets.to_i nums =[] n.times{ nums.push(get.to.i) } cnt = n nums.each{|val| primes.each{|i| break if val == i if val%i == 0 cnt -=1 break end } } puts(cnt)
require 'prime' primes =[] Prime.each(10000){|i| primes.push(i) } n = gets.to_i nums = [] n.times{ nums.push(gets.to_i) } cnt = n nums.each{|val| primes.each{|i| break if val == i if val%i == 0 cnt -=1 break end } } puts (cnt)
[ "identifier.change", "call.arguments.change", "call.remove" ]
100,932
100,931
u456179450
ruby
p02257
include Math require 'prime' n = gets.to_i root_prime = Prime.each(10000).to_a c = 0 n.times { catch(:next) do x = gets.to_i if (x <= 10000) c += 1 if (root_prime.bsearch{|i| x == i}) throw :next end xs = sqrt(x).floor root_prime.each{ |rp| break if (rp > xs) throw :next if (x % rp == 0) } c += 1 end } puts c
include Math require 'prime' n = gets.to_i root_prime = Prime.each(10000).to_a c = 0 n.times { catch(:next) do x = gets.to_i if (x <= 10000) c += 1 if (x == root_prime.bsearch{|i| x <= i}) throw :next end xs = sqrt(x).floor root_prime.each{ |rp| break if (rp > xs) throw :next if (x % rp == 0) } c += 1 end } puts c
[ "control_flow.branch.if.condition.change", "expression.operator.compare.change" ]
100,938
100,939
u213421924
ruby
p02257
require 'prime' N = gets.to_i count = 0 #AS=[] N.times{ AS << gets.to_i } puts AS.count{ | x | Prime.prime?(x) }
require 'prime' N = gets.to_i count = 0 AS=[] N.times{ AS << gets.to_i } puts AS.count{ | x | Prime.prime?(x) }
[ "assignment.add" ]
100,943
100,944
u265772813
ruby
p02257
#!/usr/bin/ruby require 'prime' h={} Prime.each(10**4+10){|e|h[e]=1} p gets.to_i.times.count{e=gets.to_i;h[e]||h.keys.any?{|f|e%f==0}}
#!/usr/bin/ruby require 'prime' h={} Prime.each(10**4+10){|e|h[e]=1} p gets.to_i.times.count{e=gets.to_i;h[e]||h.keys.none?{|f|e%f==0}}
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
100,949
100,950
u300645821
ruby