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 |
|---|---|---|---|---|---|---|---|
p03338
|
n = gets.chomp.to_i
s = gets.chomp.split('')
max = 0
1.upto(n-2) do |i|
a = s[1..i].uniq
b = s[i+1..-1].uniq
num = (a & b).size
max = num if num > max
end
puts max
|
n = gets.chomp.to_i
s = gets.chomp.split('')
max = 0
0.upto(n-2) do |i|
a = s[0..i].uniq
b = s[i+1..-1].uniq
num = (a & b).size
max = num if num > max
end
puts max
|
[
"literal.number.integer.change",
"assignment.value.change",
"variable_access.subscript.index.change"
] | 1,112,276
| 1,112,277
|
u434509016
|
ruby
|
p03338
|
a = gets.to_i
b = gets.to_s
count_max = 0
for i in (0..a)
count = 0
s1 = b[0..i]
s2 = b[i..a]
uniq_s1 = s1.split("").uniq
uniq_s1.each do |s|
count = count + 1 if s2.include?(s)
end
count_max = count if count_max < count
end
puts count_max
|
a = gets.to_i
b = gets.to_s
count_max = 0
for i in (0..a)
count = 0
s1 = b[0..i]
s2 = b[i+1..a]
uniq_s1 = s1.split("").uniq
uniq_s1.each do |s|
count = count + 1 if s2.include?(s)
end
count_max = count if count_max < count
end
puts count_max
|
[
"assignment.change"
] | 1,112,326
| 1,112,327
|
u610761300
|
ruby
|
p03338
|
n = gets.to_i
s = gets.chomp.split("")
ans = 1
for i in 1..n-1 do
s1 = s[0,i].uniq
s2 = s[i,n-i].uniq
ans1 = 0
for j in 0..s1.length-1 do
if s2.include?(s1[j])
ans1 = ans1 + 1
end
end
if ans1 >= ans
ans = ans1
end
end
puts ans
|
n = gets.to_i
s = gets.chomp.split("")
ans = 0
for i in 1..n-1 do
s1 = s[0,i].uniq
s2 = s[i,n-i].uniq
ans1 = 0
for j in 0..s1.length-1 do
if s2.include?(s1[j])
ans1 = ans1 + 1
end
end
if ans1 >= ans
ans = ans1
end
end
puts ans
|
[
"literal.number.integer.change",
"assignment.value.change"
] | 1,112,408
| 1,112,409
|
u094826590
|
ruby
|
p03338
|
n=gets.to_i;a=gets.chars;p (1...n).max_by{|i|(a[0,i]&a[i,n]).size}
|
n=gets.to_i;a=gets.chars;p (1..n).map{|i|(a[0,i]&a[i,n]).size}.max
|
[
"call.arguments.change",
"identifier.change",
"call.add"
] | 1,112,646
| 1,112,647
|
u657913472
|
ruby
|
p03338
|
n=gets.to_i;a=gets.chars;p (1...n).max{|i|(a[0,i]&a[i,n]).size}
|
n=gets.to_i;a=gets.chars;p (1..n).map{|i|(a[0,i]&a[i,n]).size}.max
|
[
"call.arguments.change",
"identifier.change",
"call.add"
] | 1,112,648
| 1,112,647
|
u657913472
|
ruby
|
p03338
|
n = STDIN.gets.chomp.to_i
s = STDIN.gets.chomp
cs = s.chars.uniq
puts rs = cs.map {|c|
if s.index(c) == s.rindex(c)
nil
else
(s.index(c)..s.rindex(c))
end
}.compact
puts n.times.map {|i|
rs.select {|r| r.include?(i+1) }.count
}.max
|
n = STDIN.gets.chomp.to_i
s = STDIN.gets.chomp
cs = s.chars.uniq
rs = cs.map {|c|
if s.index(c) == s.rindex(c)
nil
else
(s.index(c)..s.rindex(c))
end
}.compact
puts n.times.map {|i|
rs.select {|r| r.include?(i+1) }.count
}.max
|
[
"io.output.change",
"call.remove"
] | 1,112,658
| 1,112,659
|
u039293076
|
ruby
|
p03338
|
gets
S = gets.chomp
ans = 0
for i in 1..(S.length-1)
s1 = S[0, i]
s2 = S[(i+1)..-1]
c1 = s1.chars.uniq
c2 = s2.chars.uniq
ans = [ans, (c1 & c2).length].max
end
p ans
|
gets
S = gets.chomp
ans = 0
for i in 1..(S.length-1)
s1 = S[0, i]
s2 = S[i..-1]
#p i: i, s1: s1, s2: s2
c1 = s1.chars.uniq
c2 = s2.chars.uniq
ans = [ans, (c1 & c2).length].max
end
p ans
|
[] | 1,112,682
| 1,112,683
|
u437302815
|
ruby
|
p03339
|
n = gets.to_i
s = gets.chomp
tmp = 0
cum = [0]
min = 3 * 10**5 - 1
s.each_char do |c|
tmp += 1 if c == 'W'
cum << tmp
end
1.upto(n - 1) do |i|
tmp = cum[i - 1] + n - i - (cum[-1] - cum[i])
min = tmp if min > tmp
end
puts min
|
n = gets.to_i
s = gets.chomp
tmp = 0
cum = [0]
min = 3 * 10**5 - 1
s.each_char do |c|
tmp += 1 if c == 'W'
cum << tmp
end
1.upto(n) do |i|
tmp = cum[i - 1] + n - i - (cum[-1] - cum[i])
min = tmp if min > tmp
end
puts min
|
[
"expression.operation.binary.remove"
] | 1,112,838
| 1,112,839
|
u104886851
|
ruby
|
p03339
|
n=gets.to_i
s=gets.chomp
c=[0]
cc=0
0.upto(n-2) do |i|
if s[i]=="W"
cc+=1
end
c[i+1]=cc
end
cc=0
(n-1).downpto(1) do |i|
if s[i]=="E"
cc+=1
end
c[i-1]+=cc
end
puts c.min
|
n=gets.to_i
s=gets.chomp
c=[0]
cc=0
0.upto(n-2) do |i|
if s[i]=="W"
cc+=1
end
c[i+1]=cc
end
cc=0
(n-1).downto(1) do |i|
if s[i]=="E"
cc+=1
end
c[i-1]+=cc
end
puts c.min
|
[
"identifier.change"
] | 1,113,022
| 1,113,023
|
u744908753
|
ruby
|
p03339
|
n = gets.to_i
s = gets.split('')
e_sum = []
num = 0
n.times do |i|
num += 1 if s[i] == 'E'
e_sum << num
end
counts = []
n.times do |i|
if i == 0
counts << e_sum[n-1] - e_sum[i]
elsif i == n-1
counts << (n-1-(e_sum[n-1]))
else
counts << (i-e_sum[i-1] + (e_sum[n-1] - e_sum[i+1]))
end
end
puts counts.min
|
n = gets.to_i
s = gets.split('')
e_sum = []
num = 0
n.times do |i|
num += 1 if s[i] == 'E'
e_sum << num
end
counts = []
n.times do |i|
if i == 0
counts << e_sum[n-1] - e_sum[i]
elsif i == n-1
counts << (n-1-(e_sum[n-2]))
else
counts << (i-e_sum[i-1] + (e_sum[n-1] - e_sum[i]))
end
end
puts counts.min
|
[
"literal.number.integer.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 1,113,213
| 1,113,214
|
u195257137
|
ruby
|
p03339
|
n = gets.to_i
s = gets.split('')
e_sum = []
num = 0
n.times do |i|
num += 1 if s[i] == 'E'
e_sum << num
end
counts = []
n.times do |i|
if i == 0
counts << e_sum[n-1] - e_sum[i]
elsif i == n-1
counts << (n-1-(e_sum[n-2]))
else
counts << (i-e_sum[i-1] + (e_sum[n-1] - e_sum[i+1]))
end
end
puts counts.min
|
n = gets.to_i
s = gets.split('')
e_sum = []
num = 0
n.times do |i|
num += 1 if s[i] == 'E'
e_sum << num
end
counts = []
n.times do |i|
if i == 0
counts << e_sum[n-1] - e_sum[i]
elsif i == n-1
counts << (n-1-(e_sum[n-2]))
else
counts << (i-e_sum[i-1] + (e_sum[n-1] - e_sum[i]))
end
end
puts counts.min
|
[
"expression.operation.binary.remove"
] | 1,113,215
| 1,113,214
|
u195257137
|
ruby
|
p03339
|
module Enumerable
def cum_sum
inject([0]) { |a, n| a << (a.last + n) }
end
end
n = gets.to_i
s = gets.chomp.chars
ws = s.map { |c| c.count 'W' }.cum_sum
es = s.map { |c| c.count 'E' }.cum_sum
p Array.new(n) { |i| ws[i] + es.last - es[i] }.min
|
module Enumerable
def cum_sum
inject([0]) { |a, n| a << (a.last + n) }
end
end
n = gets.to_i
s = gets.chomp.chars
ws = s.map { |c| c.count 'W' }.cum_sum
es = s.map { |c| c.count 'E' }.cum_sum
p Array.new(n) { |i| ws[i] + es.last - es[i + 1] }.min
|
[
"expression.operation.binary.add"
] | 1,113,341
| 1,113,342
|
u702547798
|
ruby
|
p03339
|
a = gets.chomp.to_i
b = []
b = gets.chomp.split("")
#puts a
#puts b.join("")
s = 0
t = 0
cnt = 3 * 10**5
for i in 0..a-1 #1文字目
if b[i] != "W"
t = t+1
end
end
if (s + t) <= cnt
cnt = (s + t)
end
#puts t
for i in 1..a-2
if b[i] != "W"
t = t -1
end
if b[i-1] != "E"
s = s + 1
end
#puts s + t
if (s + t) <= cnt
cnt = (s + t)
end
end
puts cnt
|
a = gets.chomp.to_i
b = []
b = gets.chomp.split("")
#puts a
#puts b.join("")
s = 0
t = 0
cnt = 3 * 10**5
for i in 1..a-1 #1文字目
if b[i] != "W"
t = t+1
end
end
if (s + t) <= cnt
cnt = (s + t)
end
#puts t
for i in 1..a-1 #2文字目から
if b[i] != "W"
t = t -1
end
if b[i-1] != "E"
s = s + 1
end
#puts s + t
if (s + t) <= cnt
cnt = (s + t)
end
end
puts cnt
|
[
"literal.number.integer.change",
"expression.operation.binary.change"
] | 1,113,660
| 1,113,661
|
u614043796
|
ruby
|
p03341
|
n,s=`dd`.split
n=n.to_i
f=->c{ a=0; [0]+s.chars.map{|x|a+=x==c ? 1 : 0} }
w=f[?W]
e=f[?E]
puts (1...n).map{|i|w[i-1]+(e[n]-e[i+1])}.min
|
n,s=`dd`.split
n=n.to_i
f=->c{ a=0; [0]+s.chars.map{|x|a+=x==c ? 1 : 0} }
w=f[?W]
e=f[?E]
puts (1..n).map{|i|w[i-1]+(e[n]-e[i])}.min
|
[
"call.arguments.change",
"expression.operation.binary.remove"
] | 1,114,508
| 1,114,509
|
u503549962
|
ruby
|
p03341
|
a = gets.to_i
#b,c=gets.chomp.split(" ").map(&:to_i);
s = gets.chomp
w_counts = []
e_counts = []
w_sum = e_sum = 0
s.each_char do |c|
if c == "W"
w_sum += 1
else
e_sum += 1
end
w_counts << w_sum
e_counts << e_sum
end
#pp w_counts
#pp e_counts
min = e_sum - (s[0] == "E"? 1 : 0)
tmp = w_counts[a.size - 1 -1]
#puts "tmp:#{min}"
a.times do |i|
i= i -1
next if (i == 0 || a.size - 1 == i)
count = w_counts[i-1] + (e_sum - e_counts[i+1])
min = count if count < min
end
puts min
|
#require 'pp'
a = gets.to_i
#b,c=gets.chomp.split(" ").map(&:to_i);
s = gets.chomp
w_counts = []
e_counts = []
w_sum = e_sum = 0
s.each_char do |c|
if c == "W"
w_sum += 1
else
e_sum += 1
end
w_counts << w_sum
e_counts << e_sum
end
#pp w_counts
#pp e_counts
min = e_sum - (s[0] == "E"? 1 : 0)
tmp = w_counts[a.size - 1 -1]
a.times do |i|
i= i -1
next if (i == 0 || a.size - 1 == i)
count = w_counts[i-1] + (e_sum - e_counts[i])
min = count if count < min
# puts min
end
puts min
|
[
"expression.operation.binary.remove"
] | 1,114,552
| 1,114,553
|
u650620788
|
ruby
|
p03341
|
gets
b = gets.chomp.split("")
a = b.map { |x| x == 'W' ? -1 : 1}
s = Array.new(a.length)
sum = 0
a.length.times do |i|
sum += a[i]
s[i] = sum
end
max_i = s.index(s.max)
l = max_i == 0 ? 0 : a[0..max_i-1].count(1)
r = max_i == a.length ? 0: a[max_i+1..-1].count(-1)
puts l+r
|
gets
b = gets.chomp.split("")
a = b.map { |x| x == 'W' ? -1 : 1}
s = Array.new(a.length)
sum = 0
a.length.times do |i|
sum += a[i]
s[i] = sum
end
max_i = s.index(s.max)
l = max_i == 0 ? 0 : a[0..max_i-1].count(-1)
r = max_i == a.length ? 0: a[max_i+1..-1].count(1)
puts l+r
|
[
"expression.operation.unary.add",
"call.arguments.change",
"expression.operation.unary.arithmetic.remove"
] | 1,114,658
| 1,114,659
|
u631383869
|
ruby
|
p03341
|
N = gets.to_i
dirs = gets.each_char.to_a
ww = Array.new(N,0)
ee = Array.new(N,0)
N.times do |i|
pos = i+1
ww[pos] = ww[i] + (dirs[i] == 'W' ? 1 : 0)
ee[N-pos-1] = ee[-pos] + (dirs[-pos] == 'E' ? 1 : 0)
end
# pp ww, ee
ret = N
N.times do |i|
if ret > (ww[i] + ee[i])
ret = (ww[i] + ee[i])
end
end
puts ret
|
N = gets.to_i
dirs = gets.each_char.to_a
ww = Array.new(N,0)
ee = Array.new(N,0)
(N-1).times do |i|
pos = i+1
ww[pos] = ww[i] + (dirs[i] == 'W' ? 1 : 0)
ee[N-pos-1] = ee[N-pos] + (dirs[N-pos] == 'E' ? 1 : 0)
end
# pp ww, ee
ret = N
N.times do |i|
if ret > (ww[i] + ee[i])
ret = (ww[i] + ee[i])
end
end
puts ret
|
[
"control_flow.branch.if.condition.change"
] | 1,114,719
| 1,114,720
|
u714878632
|
ruby
|
p03339
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n+1) do |i|
cusum << [cusum[i-1][0] + (lines[i-1]=="W"?1:0), cusum[i-1][1]-(lines[i-1]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n-1) do |i|
cusum << [cusum[i-1][0] + (lines[i-1]=="W"?1:0), cusum[i-1][1]-(lines[i]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 1,115,247
| 1,115,248
|
u872636244
|
ruby
|
p03339
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n+1) do |i|
cusum << [cusum[i-1][0] + (lines[i]=="W"?1:0), cusum[i-1][1]-(lines[i-1]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n-1) do |i|
cusum << [cusum[i-1][0] + (lines[i-1]=="W"?1:0), cusum[i-1][1]-(lines[i]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 1,115,249
| 1,115,248
|
u872636244
|
ruby
|
p03339
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n) do |i|
cusum << [cusum[i-1][0] + (lines[i]=="W"?1:0), cusum[i-1][1]-(lines[i-1]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
n = gets.to_i
lines = gets.chomp.split("")
cusum = [[0,lines[1..n].count("E")]]
1.upto(n-1) do |i|
cusum << [cusum[i-1][0] + (lines[i-1]=="W"?1:0), cusum[i-1][1]-(lines[i]=="E"?1:0)]
end
puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)
|
[
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 1,115,250
| 1,115,248
|
u872636244
|
ruby
|
p03345
|
a,b,c,k=gets.split.map(&:to_i)
if k==0
ans=a-b
else
ans=b-a
end
if ans.abs>10**18
puts "Unfair"
else
puts ans
end
|
a,b,c,k=gets.split.map(&:to_i)
if k%2==0
ans=a-b
else
ans=b-a
end
if ans.abs>10**18
puts "Unfair"
else
puts ans
end
|
[
"control_flow.branch.if.condition.change"
] | 1,115,914
| 1,115,915
|
u556046719
|
ruby
|
p03345
|
a,b,c,k=gets.split.map(&:to_i)
if k==0
ans=a-b
else
ans=b-a
end
if ans.abs>10*18
puts "Unfair"
else
puts ans
end
|
a,b,c,k=gets.split.map(&:to_i)
if k%2==0
ans=a-b
else
ans=b-a
end
if ans.abs>10**18
puts "Unfair"
else
puts ans
end
|
[
"control_flow.branch.if.condition.change"
] | 1,115,916
| 1,115,915
|
u556046719
|
ruby
|
p03345
|
m=gets.split
a=m[0].to_i
b=m[1].to_i
k=m[3].to_i
if k.even?
g=b-a
else
g=a-b
end
puts g
|
m=gets.split
a=m[0].to_i
b=m[1].to_i
k=m[3].to_i
if k.odd?
g=b-a
else
g=a-b
end
puts g
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 1,116,611
| 1,116,612
|
u671239754
|
ruby
|
p03345
|
ary = gets.chomp.split().map(&:to_i)
num = ary[0] - ary[1]
if num.abs>10^18
puts("Unfair")
else
puts(num*((-1)**ary[3]))
end
|
ary = gets.chomp.split().map(&:to_i)
num = ary[0] - ary[1]
if num.abs>10**18
puts("Unfair")
else
puts(num*((-1)**ary[3]))
end
|
[
"control_flow.branch.if.condition.change"
] | 1,116,814
| 1,116,815
|
u706730549
|
ruby
|
p03345
|
a, b, c, K = gets.split.map(&:to_i)
if a == b && b == c
puts 0
exit
end
diff = if K.even?
a - b
else
b - a
end
if diff.abs > 10**8
puts 'Unfair'
else
puts diff
end
|
a, b, c, K = gets.split.map(&:to_i)
if a == b && b == c
puts 0
exit
end
diff = if K.even?
a - b
else
b - a
end
if diff.abs > 10**18
puts 'Unfair'
else
puts diff
end
|
[
"literal.number.integer.change",
"control_flow.branch.if.condition.change"
] | 1,116,835
| 1,116,836
|
u764026162
|
ruby
|
p03346
|
N,*P=$<.map &:to_i
s=[0]*(N+2)
P.map{|p|s[p]=s[p-1]+1}
p s
p N-s.max
|
N,*P=$<.map &:to_i
s=[0]*(N+2)
P.map{|p|s[p]=s[p-1]+1}
p N-s.max
|
[
"call.remove"
] | 1,117,187
| 1,117,188
|
u019489252
|
ruby
|
p03346
|
n = gets.to_i
a = [0] * (n + 1)
n.times do
i << gets.to_i
a[i] = a[i - 1] + 1
end
puts n - a.max
|
n = gets.to_i
a = [0] * (n + 1)
n.times do
i = gets.to_i
a[i] = a[i - 1] + 1
end
puts n - a.max
|
[
"expression.operation.binary.change"
] | 1,117,275
| 1,117,276
|
u433600270
|
ruby
|
p03346
|
n = gets.to_i
input = n.times.map { gets.to_i }
arr = Array.new(n + 1, 0)
input.each do |i|
arr[i] = arr[i - 1] + 1
end
puts arr.max
|
n = gets.to_i
input = n.times.map { gets.to_i }
arr = Array.new(n + 1, 0)
input.each do |i|
arr[i] = arr[i - 1] + 1
end
p n - arr.max
|
[
"identifier.change"
] | 1,117,588
| 1,117,589
|
u214983738
|
ruby
|
p03347
|
n = gets.to_i
a = n.times.map{gets.to_i}
sum = a.last
now_v = a.last
(n-2).downto(0) do |i|
if a[i] == a[i+1] - 1
now_v = a[i]
elsif a[i] >= a[i+1]
sum += a[i]
now_v = a[i]
else
pust -1
exit
end
end
unless now_v == 0
puts -1
exit
end
puts sum
|
n = gets.to_i
a = n.times.map{gets.to_i}
sum = a.last
now_v = a.last
(n-2).downto(0) do |i|
if a[i] == a[i+1] - 1
now_v = a[i]
elsif a[i] >= a[i+1]
sum += a[i]
now_v = a[i]
else
puts -1
exit
end
end
unless now_v == 0
puts -1
exit
end
puts sum
|
[
"identifier.change"
] | 1,117,685
| 1,117,686
|
u392423112
|
ruby
|
p03347
|
N,*A=$<.map &:to_i
r=b=0
A.map{|e|
A[0]>0||b+1<e&&(p -1;exit)
b>=e&&r+=b
b=e
}
p r+b
|
N,*A=$<.map &:to_i
r=b=0
A.map{|e|
(A[0]>0||b+1<e)&&(p -1;exit)
b>=e&&r+=b
b=e
}
p r+b
|
[] | 1,118,563
| 1,118,564
|
u280667879
|
ruby
|
p03347
|
N,*A=$<.map &:to_i
r=b=0
A.map{|e|
(p -1;exit)if A[0]>0||b+1<t
r+=b if b>=t
b=t
}
p r+b
|
N,*A=$<.map &:to_i
r=b=0
A.map{|e|
(p -1;exit)if A[0]>0||b+1<e
r+=b if b>=e
b=e
}
p r+b
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"assignment.value.change"
] | 1,118,565
| 1,118,566
|
u280667879
|
ruby
|
p03346
|
N = gets.to_i
ps = []
N.times{
ps << gets.to_i
}
ps << -1
list = [0] * (N + 1)
ps.each_with_index{|value, i|
list[value] = list[value - 1] + 1
}
puts N - list.max
|
N = gets.to_i
ps = []
N.times{
ps << gets.to_i
}
list = [0] * (N + 1)
ps.each_with_index{|value, i|
list[value] = list[value - 1] + 1
}
puts N - list.max
|
[
"expression.operation.binary.remove"
] | 1,118,859
| 1,118,860
|
u751724075
|
ruby
|
p03351
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - b).abs && (b - c).abs < d ## 入力例 3 で気づかないとダメ
puts "Yes"
elsif (a - c).abs < d ## a - c の絶対値も d 以下ならば
puts "Yes"
else
puts "No" ## それ以外
end
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - b).abs <= d && (b - c).abs <= d
puts "Yes"
elsif (a - c).abs <= d
puts "Yes"
else
puts "No"
end
|
[
"control_flow.branch.if.condition.change",
"expression.operator.compare.change"
] | 1,119,585
| 1,119,586
|
u552761221
|
ruby
|
p03351
|
ary = gets.split(" ").map(&:to_i)
a = ary[0]
b = ary[1]
c = ary[2]
d = ary.last
if d >= (a-c).abs
puts "Yes"
elsif d >= (a-b).abs and d >= (a-c).abs
puts "Yes"
else
puts "No"
end
|
ary = gets.split(" ").map(&:to_i)
a = ary[0]
b = ary[1]
c = ary[2]
d = ary.last
if d >= (a-c).abs
puts "Yes"
elsif d >= (a-b).abs and d >= (b-c).abs
puts "Yes"
else
puts "No"
end
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 1,119,664
| 1,119,665
|
u944733909
|
ruby
|
p03351
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - c).abs <= d || (a - b).abs <= d and (b - c).abs <= d
puts "Yes"
else
puts "No"
end
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - c).abs <= d || ((a - b).abs <= d && (b - c).abs <= d)
puts "Yes"
else
puts "No"
end
|
[
"control_flow.branch.if.condition.change"
] | 1,119,882
| 1,119,883
|
u968699140
|
ruby
|
p03351
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - c).abs <= d || (a - b).abs <= d and (a - c).abs <= d
puts "Yes"
else
puts "No"
end
|
a, b, c, d = gets.chomp.split.map(&:to_i)
if (a - c).abs <= d || ((a - b).abs <= d && (b - c).abs <= d)
puts "Yes"
else
puts "No"
end
|
[
"control_flow.branch.if.condition.change",
"identifier.change"
] | 1,119,884
| 1,119,883
|
u968699140
|
ruby
|
p03351
|
a,b,c,d = gets.split.map(&:to_i).sort
puts (a-c).abs <= d || ((a-b).abs <= d && (b-c).abs <= d) ? "Yes" : "No"
|
a,b,c,d = gets.split.map(&:to_i)
puts (a-c).abs <= d || ((a-b).abs <= d && (b-c).abs <= d) ? "Yes" : "No"
|
[
"call.remove"
] | 1,120,019
| 1,120,020
|
u670503797
|
ruby
|
p03351
|
a,b,c,d = gets.split.map(&:to_i)
if d >= (b-a).asb && d >= (c-b).asb || d >= (c-a).asb
puts "Yes"
else
puts "No"
end
|
a,b,c,d = gets.split.map(&:to_i)
if d >= (b-a).abs && d >= (c-b).abs || d >= (c-a).abs
puts "Yes"
else
puts "No"
end
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 1,120,394
| 1,120,395
|
u990788654
|
ruby
|
p03351
|
a,b,c,d=gets.split(" ").map(&:to_i)
if (a-c).abs <=3 || ((a-b).abs <=3 && (b-c).abs <=3)
puts "Yes"
else
puts "No"
end
|
a,b,c,d=gets.split(" ").map(&:to_i)
if (a-c).abs <=d || ((a-b).abs <=d && (b-c).abs <=d)
puts "Yes"
else
puts "No"
end
|
[
"identifier.replace.add",
"literal.replace.remove",
"control_flow.branch.if.condition.change"
] | 1,120,699
| 1,120,700
|
u887087974
|
ruby
|
p03351
|
a, b, c, d = gets.chop.split.map(&:to_i)
if (a-c).abs <= d
puts "Yes"
else
if (a-b).abs && (b-c).abs
puts "Yes"
else
puts "No"
end
end
|
a, b, c, d = gets.chop.split.map(&:to_i)
if (a-c).abs <= d
puts "Yes"
else
if (a-b).abs <= d && (b-c).abs <= d
puts "Yes"
else
puts "No"
end
end
|
[
"control_flow.branch.if.condition.change"
] | 1,120,701
| 1,120,702
|
u709879360
|
ruby
|
p03351
|
def main()
a,b,c,d = gets.chomp.split(' ').map(&:to_i)
ans = "No"
ans = "Yes" if (((a-b).abs <= d) and ((b-c).abs <= d)) or ((a-c) <= d)
puts ans
end
main()
|
def main()
a,b,c,d = gets.chomp.split(' ').map(&:to_i)
ans = "No"
ans = "Yes" if (((a-b).abs <= d) and ((b-c).abs <= d)) or ((a-c).abs <= d)
puts ans
end
main()
|
[
"control_flow.branch.if.condition.change",
"call.add"
] | 1,120,723
| 1,120,724
|
u947517859
|
ruby
|
p03348
|
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
if(IS_DEBUG)
puts str
end
end
def dpp str
if(IS_DEBUG)
pp str
end
end
require 'pp'
# from s(s) to t with limited depth d of graph e
# s is assumed to be an array [s1] or [s1,s2]
def count(g,s,d)
arrsize = (d+2)/2
maxarr = Array.new(arrsize){0}
def makearr(g,s,nott,maxarr)
stack = [] # stack
f = Array.new(g.size){false} # is searched flag
# tr = Array.new(g.size){nil}
# init
dmax = 0
emax = s # e of dmax
f[s]=true
enext = E[s].reject{|e| e == nott}
# evaluation
if(enext.size > maxarr[0])
maxarr[0] = enext.size
end
# next edge push
enext.each{|v|
# tr[v]=s
stack.push([v,1]) #v,d to v
}
while(!stack.empty?)
curv,curd = stack.pop
dputs "(curv,curd) = (#{curv},#{curd})"
f[curv]=true
enext = E[curv].reject{|e| f[e]}
# evaluation
if(enext.size > maxarr[curd])
maxarr[curd] = enext.size
end
# next edge push
enext.each{|v|
# tr[v]=curv
stack.push([v,curd+1])
}
end
end
case s.size
when 1
makearr(g,s[0],s[0],maxarr)
when 2
dputs "first makearr"
makearr(g,s[0],s[1],maxarr)
dputs "second makearr"
makearr(g,s[1],s[0],maxarr)
end
maxarr[-1]=1
dpp maxarr
return s.size*maxarr.inject(1){|prod,n| prod*n}
end
# returns diameter and central edge(s)
def diameter(g)
def farthest(g,s)
stack = [] # stack
f = Array.new(g.size){false} # is searched flag
tr = Array.new(g.size){nil}
# init
dmax = 0
emax = s # e of dmax
tr[s]=s
f[s]=true
E[s].each{|v|
tr[v]=s
stack.push([v,1]) #v,d to v
}
while(!stack.empty?)
curv,curd = stack.pop
f[curv]=true
if(dmax < curd)
dmax = curd
emax = curv
end
dputs "(curv,curd) = (#{curv},#{curd})"
E[curv].each{|v|
if !f[v]
tr[v]=curv
stack.push([v,curd+1])
end
}
end
return [dmax,emax,tr]
end
# diameter by two execute
d,e,tr = farthest(g,0)
dputs "d = #{d}"
dputs "e = #{e}"
dpp tr
d,e,tr = farthest(g,e)
dputs "d = #{d}"
dputs "e = #{e}"
dpp tr
# trace
etr = e
len = 0
centd = d/2
offs = d%2
cente = []
while(true)
etr = tr[etr]
len += 1
if(len == centd)
cente << etr
elsif(len == centd+offs)
cente << etr
break
elsif(len > centd+offs)
break
end
end
return [d, cente]
end
N,_=gets.chomp.split(' ').map{|n| n.to_i}
if(N==2)
puts "1 2"
exit(0)
end
E = Array.new(N){[]}
1.upto(N-1){
p=gets.chomp.split(' ').map{|n| n.to_i}
p[0]-=1
p[1]-=1
E[p[0]].push(p[1])
E[p[1]].push(p[0])
}
d,s = diameter(E)
dpp s
mind = count(E,s,d)
if s.size == 1
# center of the generated tree is the center or the center + neibor
E[s[0]].each{|sn|
tmp = count(E,[s[0],sn],d)
dputs "count #{s[0]},#{sn} is #{tmp}"
mind = tmp if tmp < mind
}
end
puts "#{(d+2)/2} #{mind}"
|
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
if(IS_DEBUG)
puts str
end
end
def dpp str
if(IS_DEBUG)
pp str
end
end
require 'pp'
# from s(s) to t with limited depth d of graph e
# s is assumed to be an array [s1] or [s1,s2]
def count(g,s,d)
arrsize = (d+2)/2
maxarr = Array.new(arrsize){0}
def makearr(g,s,nott,maxarr)
stack = [] # stack
f = Array.new(g.size){false} # is searched flag
# tr = Array.new(g.size){nil}
# init
dmax = 0
emax = s # e of dmax
f[s]=true
enext = E[s].reject{|e| e == nott}
# evaluation
if(enext.size > maxarr[0])
maxarr[0] = enext.size
end
# next edge push
enext.each{|v|
# tr[v]=s
stack.push([v,1]) #v,d to v
}
while(!stack.empty?)
curv,curd = stack.pop
dputs "(curv,curd) = (#{curv},#{curd})"
f[curv]=true
enext = E[curv].reject{|e| f[e]}
# evaluation
if(enext.size > maxarr[curd])
maxarr[curd] = enext.size
end
# next edge push
enext.each{|v|
# tr[v]=curv
stack.push([v,curd+1])
}
end
end
case s.size
when 1
makearr(g,s[0],s[0],maxarr)
when 2
dputs "first makearr"
makearr(g,s[0],s[1],maxarr)
dputs "second makearr"
makearr(g,s[1],s[0],maxarr)
end
maxarr[-1]=1
dpp maxarr
return s.size*maxarr.inject(1){|prod,n| prod*n}
end
# returns diameter and central edge(s)
def diameter(g)
def farthest(g,s)
stack = [] # stack
f = Array.new(g.size){false} # is searched flag
tr = Array.new(g.size){nil}
# init
dmax = 0
emax = s # e of dmax
tr[s]=s
f[s]=true
E[s].each{|v|
tr[v]=s
stack.push([v,1]) #v,d to v
}
while(!stack.empty?)
curv,curd = stack.pop
f[curv]=true
if(dmax < curd)
dmax = curd
emax = curv
end
dputs "(curv,curd) = (#{curv},#{curd})"
E[curv].each{|v|
if !f[v]
tr[v]=curv
stack.push([v,curd+1])
end
}
end
return [dmax,emax,tr]
end
# diameter by two execute
d,e,tr = farthest(g,0)
dputs "d = #{d}"
dputs "e = #{e}"
dpp tr
d,e,tr = farthest(g,e)
dputs "d = #{d}"
dputs "e = #{e}"
dpp tr
# trace
etr = e
len = 0
centd = d/2
offs = d%2
cente = []
while(true)
etr = tr[etr]
len += 1
if(len == centd)
cente << etr
elsif(len == centd+offs)
cente << etr
break
elsif(len > centd+offs)
break
end
end
return [d, cente]
end
N,_=gets.chomp.split(' ').map{|n| n.to_i}
if(N==2)
puts "1 2"
exit(0)
end
E = Array.new(N){[]}
1.upto(N-1){
p=gets.chomp.split(' ').map{|n| n.to_i}
p[0]-=1
p[1]-=1
E[p[0]].push(p[1])
E[p[1]].push(p[0])
}
d,s = diameter(E)
dpp s
mind = count(E,s,d)
if s.size == 1
# center of the generated tree is the center or the center + neibor
E[s[0]].each{|sn|
tmp = count(E,[s[0],sn],d)
dputs "count #{s[0]},#{sn} is #{tmp}"
mind = tmp if tmp < mind
}
end
puts "#{(d+2)/2} #{mind}"
|
[
"misc.opposites",
"assignment.value.change"
] | 1,120,801
| 1,120,802
|
u415591191
|
ruby
|
p03329
|
N = gets.to_i
dp = []
for i in 0..N
if i == 0
dp[i] = 0
elsif i < 6
dp[i] = dp[i-1] + 1
elsif 6 <= i && i < 9
dp[i] = [dp[i-1]+1,dp[i-6]+1].min
elsif 9 <= i && i < 36
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1].min
elsif 36 <= i && i < 81
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1].min
elsif 81 <= i && i < 216
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1].min
elsif 216 <= i && i < 729
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1].min
elsif 729 <= i && i < 1296
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1].min
elsif 1296 <= i && i < 6561
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1].min
elsif 6561 <= i && i < 7776
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1].min
elsif 7776 <= i && i < 46656
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1].min
elsif 46656 <= i && i < 59049
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1,dp[46656]+1].min
else
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1,dp[i-46656]+1,dp[i-59049]+1].min
end
end
puts dp[N]
|
N = gets.to_i
dp = []
for i in 0..N
if i == 0
dp[i] = 0
elsif i < 6
dp[i] = dp[i-1] + 1
elsif 6 <= i && i < 9
dp[i] = [dp[i-1]+1,dp[i-6]+1].min
elsif 9 <= i && i < 36
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1].min
elsif 36 <= i && i < 81
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1].min
elsif 81 <= i && i < 216
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1].min
elsif 216 <= i && i < 729
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1].min
elsif 729 <= i && i < 1296
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1].min
elsif 1296 <= i && i < 6561
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1].min
elsif 6561 <= i && i < 7776
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1].min
elsif 7776 <= i && i < 46656
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1].min
elsif 46656 <= i && i < 59049
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1,dp[i-46656]+1].min
else
dp[i] = [dp[i-1]+1,dp[i-6]+1,dp[i-9]+1,dp[i-36]+1,dp[i-81]+1,dp[i-216]+1,dp[i-729]+1,dp[i-1296]+1,dp[i-6561]+1,dp[i-7776]+1,dp[i-46656]+1,dp[i-59049]+1].min
end
end
puts dp[N]
|
[
"expression.operation.binary.add"
] | 1,121,217
| 1,121,218
|
u162758522
|
ruby
|
p03352
|
# util functions
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
# body
if $debugFlag
end
ans = 1
for i in 2..nn
tmp = i*i
while tmp < nn
ans = tmp if tmp > ans
tmp *= i
end
end
puts ans
|
# util functions
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
# body
if $debugFlag
end
ans = 1
for i in 2..nn
tmp = i*i
while tmp <= nn
ans = tmp if tmp > ans
tmp *= i
end
end
puts ans
|
[
"expression.operator.compare.change",
"expression.operation.binary.change"
] | 1,122,370
| 1,122,371
|
u714724786
|
ruby
|
p03352
|
# util functions
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
# body
if $debugFlag
end
ans = 4
for i in 2..nn
tmp = i*i
while tmp < nn
ans = tmp if tmp > ans
tmp *= i
end
end
puts ans
|
# util functions
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
# body
if $debugFlag
end
ans = 1
for i in 2..nn
tmp = i*i
while tmp <= nn
ans = tmp if tmp > ans
tmp *= i
end
end
puts ans
|
[
"literal.number.integer.change",
"assignment.value.change",
"expression.operator.compare.change",
"expression.operation.binary.change"
] | 1,122,372
| 1,122,371
|
u714724786
|
ruby
|
p03352
|
X=gets.to_i
max = 0
1.upto(X){|b|
2.upto(X){|p|
bp = b**p
max = bp if bp <= X and bp > max
break if bp > X
}
}
p max
|
X=gets.to_i
max = 1
1.upto(X){|b|
2.upto(X){|p|
bp = b**p
max = bp if bp <= X and bp > max
break if bp > X
}
}
p max
|
[
"literal.number.integer.change",
"assignment.value.change"
] | 1,122,429
| 1,122,430
|
u502306384
|
ruby
|
p03352
|
X=gets.to_i
max = 0
1.upto(X){|b|
2.upto(X){|p|
bp = b**p
max = bp if bp < X and bp > max
break if bp > X
}
}
p max
|
X=gets.to_i
max = 1
1.upto(X){|b|
2.upto(X){|p|
bp = b**p
max = bp if bp <= X and bp > max
break if bp > X
}
}
p max
|
[
"literal.number.integer.change",
"assignment.value.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,122,431
| 1,122,430
|
u502306384
|
ruby
|
p03352
|
x = gets.to_i
p (2..x).map{|i| (2..10).map{|a| i**a}.select{|s| s <= x} }.flatten.max
|
x = gets.to_i
p (1..x).map{|i| (2..10).map{|a| i**a}.select{|s| s <= x} }.flatten.max
|
[
"literal.number.integer.change",
"call.arguments.change"
] | 1,122,432
| 1,122,433
|
u069429049
|
ruby
|
p03352
|
#!/usr/bin/ruby
#encoding: utf-8
x = gets.to_i
max = 0
(1..x).each do |i|
(2..10).each do |j|
a = i ** j
if a < x
max = [max,a].max
end
end
end
puts max
|
#!/usr/bin/ruby
#encoding: utf-8
x = gets.to_i
max = 0
(1..x).each do |i|
(2..10).each do |j|
a = i ** j
if a <= x
max = [max,a].max
end
end
end
puts max
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,122,489
| 1,122,490
|
u998741086
|
ruby
|
p03352
|
X = gets.to_i
n = 1
a = []
(2..10).each do |i|
while n**i <= X
a << n ** i
n += 1
end
end
puts a.max
|
X = gets.to_i
a = []
(2..10).each do |i|
n = 1
while n**i <= X
a << n ** i
n += 1
end
end
puts a.max
|
[
"assignment.remove",
"assignment.add"
] | 1,122,715
| 1,122,716
|
u627764960
|
ruby
|
p03352
|
x = gets.chomp.to_i
res = []
for i in 1..35 do
for j in 2..10 do
n = i ** j
res << n if n < x
end
end
ans = -1
res.sort.reverse.each do |r|
if r <= x
ans = r
break
end
end
puts ans
|
x = gets.chomp.to_i
res = []
for i in 1..35 do
for j in 2..10 do
n = i ** j
res << n if n <= x
end
end
ans = -1
res.sort.reverse.each do |r|
if r <= x
ans = r
break
end
end
puts ans
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,122,861
| 1,122,862
|
u729246375
|
ruby
|
p03351
|
def d(n)
if n < 0
return -1 * n
else
return n
end
end
inp = gets.split(" ")
a = inp[0].to_i
b = inp[1].to_i
c = inp[2].to_i
d = inp[3].to_i
if d(c-a) <= d
print("YES")
print("\n")
elsif d(b-a) <= d && d(c-b) <= d
print("YES")
print("\n")
else
print("NO")
print("\n")
end
|
def d(n)
if n < 0
return -1 * n
else
return n
end
end
inp = gets.split(" ")
a = inp[0].to_i
b = inp[1].to_i
c = inp[2].to_i
d = inp[3].to_i
if d(c-a) <= d
print("Yes")
print("\n")
elsif d(b-a) <= d && d(c-b) <= d
print("Yes")
print("\n")
else
print("No")
print("\n")
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 1,122,952
| 1,122,953
|
u855781168
|
ruby
|
p03351
|
def d(n)
if n < 0
return -1 * n
else
return n
end
end
inp = gets.split(" ")
a = inp[0].to_i
b = inp[1].to_i
c = inp[2].to_i
d = inp[3].to_i
if d(c-a) < d
print("YES")
print("\n")
elsif d(b-a) <= d && d(c-b) <= d
print("YES")
print("\n")
else
print("NO")
print("\n")
end
|
def d(n)
if n < 0
return -1 * n
else
return n
end
end
inp = gets.split(" ")
a = inp[0].to_i
b = inp[1].to_i
c = inp[2].to_i
d = inp[3].to_i
if d(c-a) <= d
print("Yes")
print("\n")
elsif d(b-a) <= d && d(c-b) <= d
print("Yes")
print("\n")
else
print("No")
print("\n")
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 1,122,954
| 1,122,953
|
u855781168
|
ruby
|
p03351
|
a,b,c,d=gets.split.map &:to_i
if ((a-b).abs<d && (b-c).abs<d) || (a-c).abs<d
print("Yes\n")
else
print("No\n")
end
|
a,b,c,d=gets.split.map &:to_i
if ((a-b).abs<=d && (b-c).abs<=d) || (a-c).abs<=d
print("Yes\n")
else
print("No\n")
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,123,003
| 1,123,004
|
u610697662
|
ruby
|
p03352
|
x = gets.to_i
a = Array.new
(2..9).each do |i|
(2..31).each do |j|
if j ** i <= x
a.push(j ** i)
end
end
end
p a.max
|
x = gets.to_i
a = Array.new
(2..9).each do |i|
(2..31).each do |j|
if j ** i <= x
a.push(j ** i)
end
end
end
a.push(1)
p a.max
|
[
"call.add"
] | 1,123,125
| 1,123,126
|
u757568397
|
ruby
|
p03352
|
x = gets.to_i
list = []
for i in 1..x+1 do
a = 0
for j in 2..x+2 do
a = i ** j
if a <= x
list.push(a)
else
break
end
end
end
p list[-1]
|
x = gets.to_i
list = []
for i in 1..x+1 do
a = 0
for j in 2..x+2 do
a = i ** j
if a <= x
list.push(a)
else
break
end
end
end
p list.max
|
[] | 1,123,133
| 1,123,134
|
u827568390
|
ruby
|
p03352
|
a=gets.to_i
puts (1..1000).map{|x| x**((2..10).reverse.find{|y| x**y <= a}||0)}.max
|
a=gets.to_i
puts (1..1000).map{|x| x**([*2..10].reverse.find{|y| x**y <= a}||0)}.max
|
[
"call.arguments.change",
"expression.operation.binary.change"
] | 1,123,174
| 1,123,175
|
u056944756
|
ruby
|
p03352
|
a=gets.to_i
puts (1..1000).map{|x| x**(2..10).reverse.find{|y| x**y <= a}||0}.max
|
a=gets.to_i
puts (1..1000).map{|x| x**([*2..10].reverse.find{|y| x**y <= a}||0)}.max
|
[
"literal.array.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,123,176
| 1,123,175
|
u056944756
|
ruby
|
p03352
|
x = gets.chomp.to_i
y = Math.sqrt(x).to_i + 1
if x == 1 then
puts 1
exit
end
ans = 1
2.upto(y) do |i|
a = i
10.times do |j|
a *= a
if a > x then
break
elsif a > ans then
ans = a
end
end
end
puts ans
|
x = gets.chomp.to_i
y = Math.sqrt(x).to_i + 1
if x == 1 then
puts 1
exit
end
ans = 1
2.upto(y) do |i|
a = i
10.times do |j|
a *= i
if a > x then
break
elsif a > ans then
ans = a
end
end
end
puts ans
|
[
"identifier.change"
] | 1,123,333
| 1,123,334
|
u910756197
|
ruby
|
p03352
|
x = gets.chomp!.to_i
max = 0
(1..x).each do |i|
(2..x).each do |j|
num = i ** j
if num <= x
max = [max, num].max
elsif num > x
break
end
end
end
puts max
|
x = gets.chomp!.to_i
max = 1
(1..x).each do |i|
(2..x).each do |j|
num = i ** j
if num <= x
max = [max, num].max
elsif num > x
break
end
end
end
puts max
|
[
"literal.number.integer.change",
"assignment.value.change"
] | 1,123,392
| 1,123,393
|
u064386052
|
ruby
|
p03352
|
x=gets.to_i
max = 0
if x < 4
puts 1
else
for i in 2..(Math.sqrt(x))
beki = 0
j = 0
while beki < x
beki = i**j
j += 1
end
beki = i**(j-2)
if max < beki
max = beki
end
end
puts max
end
|
x=gets.to_i
max = 0
if x < 4
puts 1
else
for i in 2..(Math.sqrt(x))
beki = 0
j = 0
while beki <= x
beki = i**j
j += 1
end
beki = i**(j-2)
if max < beki
max = beki
end
end
puts max
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,123,425
| 1,123,426
|
u887087974
|
ruby
|
p03352
|
x=gets.to_i
max = 0
if x == 1
puts 1
else
for i in 2..(Math.sqrt(x))
beki = 0
j = 0
while beki < x
beki = i**j
j += 1
end
beki = i**(j-2)
if max < beki
max = beki
end
end
puts max
end
|
x=gets.to_i
max = 0
if x < 4
puts 1
else
for i in 2..(Math.sqrt(x))
beki = 0
j = 0
while beki <= x
beki = i**j
j += 1
end
beki = i**(j-2)
if max < beki
max = beki
end
end
puts max
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,123,427
| 1,123,426
|
u887087974
|
ruby
|
p03352
|
x = gets.chomp.to_i
i = 2
arr = [1]
while x >= i*i do
j = i*i
while x >= j do
arr.push(j)
j *= i
p j
end
i += 1
end
printf("%d\n",arr.sort[-1])
|
x = gets.chomp.to_i
i = 2
arr = [1]
while x >= i*i do
j = i*i
while x >= j do
arr.push(j)
j *= i
end
i += 1
end
printf("%d\n",arr.sort[-1])
|
[
"call.remove"
] | 1,123,477
| 1,123,478
|
u913444337
|
ruby
|
p03352
|
x = gets.to_i
ans = 1
for i in 2...x
t = i
next if t*t>x
while t*t<=x
t *= t
end
ans = t if ans<t
end
p ans
|
x = gets.to_i
ans = 1
for i in 2...x
t = i
next if t*t>x
while t*i<=x
t *= i
end
ans = t if ans<t
end
p ans
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,123,512
| 1,123,513
|
u397763977
|
ruby
|
p03352
|
x = gets.to_i
x.downto(1) do |i|
2.upto(i) do |j|
if i % j == 0
y = i
cnt = 0
while y % j == 0
y /= j
cnt += 1
end
if y == 1 && cnt > 1
puts i
exit
end
end
end
end
|
x = gets.to_i
x.downto(1) do |i|
2.upto(i) do |j|
if i % j == 0
y = i
cnt = 0
while y % j == 0
y /= j
cnt += 1
end
if y == 1 && cnt > 1
puts i
exit
end
end
end
end
p 1
|
[
"call.add"
] | 1,123,546
| 1,123,547
|
u553623615
|
ruby
|
p03352
|
p gets.to_i.downto(1).find{|n|(2..36).any?{|i|n.to_s(i)[/^100+$/]}}
|
p gets.to_i.downto(1).find{|n|(2..36).any?{|i|n.to_s(i)[/^100+$/]}}||1
|
[
"expression.operation.binary.add"
] | 1,123,557
| 1,123,558
|
u711705317
|
ruby
|
p03352
|
def main()
a = gets.chomp.to_i
ans = 0
for i in 1..a do
for j in 2..(a+1) do
tmp = i ** j
if tmp > a
break
elsif tmp <= a
ans = tmp
end
end
end
puts ans
end
main()
|
def main()
a = gets.chomp.to_i
ans = 0
for i in 1..a do
for j in 2..(a+1) do
tmp = i ** j
if tmp > a
break
elsif tmp <= a
ans = [tmp,ans].max
end
end
end
puts ans
end
main()
|
[
"call.add"
] | 1,123,686
| 1,123,687
|
u947517859
|
ruby
|
p03352
|
x = gets.to_i
ans = 0
((x**0.5).to_i**2).downto(2) do |n|
tmp = 1
tmp *= n while tmp < x
tmp /= n if tmp > x
ans = tmp if tmp > ans
end
p ans
|
x = gets.to_i
ans = 1
((x**0.5).to_i**2).downto(2) do |n|
tmp = 1
tmp *= n while tmp < x
tmp /= n if tmp > x
ans = tmp if tmp > ans
end
p ans
|
[
"literal.number.integer.change",
"assignment.value.change"
] | 1,123,953
| 1,123,952
|
u987869509
|
ruby
|
p03353
|
s = gets.chop
k = gets.chop.to_i
order = s.split('').sort.uniq
result = []
order.each do |e|
(0..s.length-1).each do |i|
next if s[i] != e
result << s[i]
(i..s.length-1).each do |j|
result << s.slice(i..j)
end
end
result.uniq!
break if result.size > k
end
puts result.sort[k-1]
|
s = gets.chop
k = gets.chop.to_i
order = s.split('').sort.uniq
result = []
order.each do |e|
(0..s.length-1).each do |i|
next if s[i] != e
result << s[i]
(i..i+4).each do |j|
result << s.slice(i..j)
end
end
result.uniq!
break if result.size > k
end
puts result.sort[k-1]
|
[
"expression.operation.binary.remove"
] | 1,124,774
| 1,124,776
|
u709879360
|
ruby
|
p03353
|
s = gets.chomp.split("")
k = gets.chomp.to_i
a1 = s.clone
s.each_cons(2) {|ary| a1 << ary.join}
s.each_cons(3) {|ary| a1 << ary.join}
s.each_cons(4) {|ary| a1 << ary.join}
s.each_cons(5) {|ary| a1 << ary.join}
puts a1.sort.uniq[4]
|
s = gets.chomp.split("")
k = gets.chomp.to_i
a1 = s.clone
s.each_cons(2) {|ary| a1 << ary.join}
s.each_cons(3) {|ary| a1 << ary.join}
s.each_cons(4) {|ary| a1 << ary.join}
s.each_cons(5) {|ary| a1 << ary.join}
puts a1.sort.uniq[k-1]
|
[
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 1,124,898
| 1,124,900
|
u868089307
|
ruby
|
p03353
|
a = gets.chomp
b = gets.to_i
c = []
for i in 1..(b - 1)
for j in 0..(a.length - 1)
c.push(a[j, i])
end
end
c = c.uniq
c.sort!
#c.sort_by {|array| array.size}
#puts c
#puts "end"
puts c[b - 1]
#p a
#p b
|
a = gets.chomp
b = gets.to_i
c = []
for i in 1..b
for j in 0..(a.length - 1)
c.push(a[j, i])
end
end
c = c.uniq
c.sort!
#c.sort_by {|array| array.size}
#puts c
#puts "end"
puts c[b - 1]
#p a
#p b
|
[] | 1,125,033
| 1,125,035
|
u614043796
|
ruby
|
p03354
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if lused[ps[n]]
end
end
1.upto(ps.length-1) do |i|
ret += 1 if !used[i] && ps[i] == 1
end
p ret
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if lused[ps[n]]
end
end
1.upto(ps.length-1) do |i|
ret += 1 if !used[i] && ps[i] == i
end
p ret
|
[
"identifier.replace.add",
"literal.replace.remove",
"control_flow.branch.if.condition.change"
] | 1,125,335
| 1,125,336
|
u852974293
|
ruby
|
p03354
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if h[ps[n]]
end
end
# p h
# p used
1.upto(ps.length-1) do |i|
ret += 1 if !used[i] && ps[i] == 1
end
p ret
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if lused[ps[n]]
end
end
1.upto(ps.length-1) do |i|
ret += 1 if !used[i] && ps[i] == i
end
p ret
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"identifier.replace.add",
"literal.replace.remove"
] | 1,125,337
| 1,125,336
|
u852974293
|
ruby
|
p03354
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if h[ps[n]]
end
end
# p h
# p as
# p rest
1.upto(ps.length-1) do |i|
ret += 1 if !used[1] && ps[i] == 1
end
p ret
|
gets
ps = [0] + gets.split.map(&:to_i)
xys = $stdin.read.split
h = {}
xys.each_slice(2) do |xs,ys|
x = xs.to_i
y = ys.to_i
h[x] ||= []
h[x] << y
h[y] ||= []
h[y] << x
end
used = {}
ret = 0
h.each do |k,v|
next if used[k]
b = v
lused = {}
lused[k] = 1
until b.empty?
b.each do |n|
lused[n] = 1
end
b = b.flat_map {|n| h[n] || []}.uniq.reject {|n| lused[n]}
end
used.merge!(lused)
lused.each_key do |n|
ret += 1 if lused[ps[n]]
end
end
1.upto(ps.length-1) do |i|
ret += 1 if !used[i] && ps[i] == i
end
p ret
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change"
] | 1,125,338
| 1,125,336
|
u852974293
|
ruby
|
p03354
|
# util functions
class UnionFind
def initialize(n) # n: number of elements in the forest
@par = []
@rank = []
@vs = []
n.times do |i|
@par[i] = i
@rank[i] = 0
@vs[i] = 1
end
end
attr_accessor :par, :rank, :vs
def find(x)
raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
if @par[x] == x
return x
else
return find( @par[x] )
end
end
def unite( x, y )
xrt = find(x)
yrt = find(y)
return if xrt == yrt
if @rank[xrt] > @rank[yrt]
@par[yrt] = xrt
@vs[xrt] += @vs[yrt]
else
@par[xrt] = yrt
@vs[yrt] += @vs[xrt]
@rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
end
end
def same( x, y ) # returns true/false
return find( x ) == find( y )
end
end # UnionFind
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
$lst = inputs[1]
# body
if $debugFlag
end
uf = UnionFind.new(nn)
for i in 2..inputs.size-1
uf.unite($lst[inputs[i][0]-1]-1, $lst[inputs[i][1]-1]-1);
end
ans = 0;
for j in 0..nn-1
ans += 1 if uf.same(j, $lst[j] - 1) or j-1 == $lst[j-1]-1
end
puts ans
|
# util functions
class UnionFind
def initialize(n) # n: number of elements in the forest
@par = []
@rank = []
@vs = []
n.times do |i|
@par[i] = i
@rank[i] = 0
@vs[i] = 1
end
end
attr_accessor :par, :rank, :vs
def find(x)
raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
if @par[x] == x
return x
else
return find( @par[x] )
end
end
def unite( x, y )
xrt = find(x)
yrt = find(y)
return if xrt == yrt
if @rank[xrt] > @rank[yrt]
@par[yrt] = xrt
@vs[xrt] += @vs[yrt]
else
@par[xrt] = yrt
@vs[yrt] += @vs[xrt]
@rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
end
end
def same( x, y ) # returns true/false
return find( x ) == find( y )
end
end # UnionFind
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
$lst = inputs[1]
# body
if $debugFlag
end
uf = UnionFind.new(nn)
for i in 2..inputs.size-1
uf.unite($lst[inputs[i][0]-1]-1, $lst[inputs[i][1]-1]-1);
end
ans = 0;
for j in 0..nn-1
ans += 1 if uf.same(j, $lst[j] - 1) or j == $lst[j]-1
end
puts ans
|
[
"expression.operation.binary.remove"
] | 1,125,509
| 1,125,510
|
u714724786
|
ruby
|
p03354
|
# util functions
class UnionFind
def initialize(n) # n: number of elements in the forest
@par = []
@rank = []
@vs = []
n.times do |i|
@par[i] = i
@rank[i] = 0
@vs[i] = 1
end
end
attr_accessor :par, :rank, :vs
def find(x)
raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
if @par[x] == x
return x
else
return find( @par[x] )
end
end
def unite( x, y )
xrt = find(x)
yrt = find(y)
return if xrt == yrt
if @rank[xrt] > @rank[yrt]
@par[yrt] = xrt
@vs[xrt] += @vs[yrt]
else
@par[xrt] = yrt
@vs[yrt] += @vs[xrt]
@rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
end
end
def same( x, y ) # returns true/false
return find( x ) == find( y )
end
end # UnionFind
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
$lst = inputs[1]
# body
if $debugFlag
end
uf = UnionFind.new(nn)
for i in 2..inputs.size-1
uf.unite($lst[inputs[i][0]-1]-1, $lst[inputs[i][1]-1]-1);
end
ans = 0;
for j in 0..nn-1
ans += 1 if uf.same(j - 1, $lst[j] - 1) or j-1 == $lst[j-1]-1
end
puts ans
|
# util functions
class UnionFind
def initialize(n) # n: number of elements in the forest
@par = []
@rank = []
@vs = []
n.times do |i|
@par[i] = i
@rank[i] = 0
@vs[i] = 1
end
end
attr_accessor :par, :rank, :vs
def find(x)
raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
if @par[x] == x
return x
else
return find( @par[x] )
end
end
def unite( x, y )
xrt = find(x)
yrt = find(y)
return if xrt == yrt
if @rank[xrt] > @rank[yrt]
@par[yrt] = xrt
@vs[xrt] += @vs[yrt]
else
@par[xrt] = yrt
@vs[yrt] += @vs[xrt]
@rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
end
end
def same( x, y ) # returns true/false
return find( x ) == find( y )
end
end # UnionFind
# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag
def pd(str)
p str if $debugFlag
end
def printd(str)
print str if $debugFlag
end
# input
inputs = []
lc = 0
while l = $stdin.gets do
if false
inputs << l.chomp.split(" ").map(&:to_s)
else
inputs << l.chomp.split(" ").map(&:to_i)
end
lc += 1
end
# input check
if $debugFlag
p "--- INPUT (begin) ---"
inputs.each do |l_i|
p l_i
end
p "--- INPUT (end) ---"
print "\n"
end
nn = inputs[0][0]
$lst = inputs[1]
# body
if $debugFlag
end
uf = UnionFind.new(nn)
for i in 2..inputs.size-1
uf.unite($lst[inputs[i][0]-1]-1, $lst[inputs[i][1]-1]-1);
end
ans = 0;
for j in 0..nn-1
ans += 1 if uf.same(j, $lst[j] - 1) or j == $lst[j]-1
end
puts ans
|
[
"expression.operation.binary.remove"
] | 1,125,511
| 1,125,510
|
u714724786
|
ruby
|
p03356
|
require "optparse"
require "pp"
params = ARGV.getopts("")
def root_of x, parent
ret = parent[x]
unless ret == parent[ret]
ret = root_of(ret, parent)
parent[x] = ret
end
return ret
end
N, M = gets.split.map(&:to_i)
ps = [0] + gets.split.map(&:to_i)
parent = Array.new(N+1){ |i| i }
rank = Array.new(N+1,0)
M.times do |i|
x, y = gets.split.map(&:to_i)
# unless parent.has_key? x
# parent[x] = x
# rank[x] = 0
# end
# unless parent.has_key? y
# parent[y] = y
# rank[y] = 0
# end
xrt = root_of(x, parent)
yrt = root_of(y, parent)
rt, lf = xrt, yrt
rt, lf = lf, rt if rank[xrt] < rank[yrt]
parent[lf] = rt
rank[rt] += rank[lf]
# nx = ps[x-1]
# ny = ps[y-1]
# gx = gp[nx]
# gx = gp[gx] while gx != gp[gx]
# gy = gp[ny]
# gy = gp[gy] while gy != gp[gy]
# if gx != gy
# marged = [gx,gy].min
# ue = gp[nx]
# gp[nx] = marged
# ue, gp[ue] = gp[ue], marged while ue != marged
# ue = gp[ny]
# gp[ny] = marged
# ue, gp[ue] = gp[ue], marged while ue != marged
# # if gx < gy
# # gp[gy] = gx
# # gp[ny] = gx
# # else
# # gp[gx] = gy
# # gp[nx] = gy
# # end
# end
# # pp [x,y].join(" ")
# # x, y = y, x if gp[ps[x-1]] > gp[ps[y-1]]
# # gp[ps[y-1]] = gp[ps[x-1]]
# # pp gp
end
ret = 0
N.times do |i|
n = i+1
m = ps[n]
if root_of(n, parent) == root_of(m, parent)
ret += 1
end
# n_ue = gp[n]
# while n_ue != gp[n_ue]
# n_ue = gp[n_ue]
# end
# m_ue = gp[m]
# while m_ue != gp[m_ue]
# m_ue = gp[m_ue]
# end
# if n_ue == m_ue
# ret += 1
# end
end
# N.times do |i|
# ue = gp[i+1]
# while gp[ue] != ue
# gp[i+1] = gp[ue]
# ue = gp[i+1]
# end
# end
#pp gp
# ps.each_with_index do |p,i|
# ret += 1 if gp[ps[p-1]] == gp[p]
# end
pp parent
pp rank
puts ret
|
require "optparse"
require "pp"
params = ARGV.getopts("")
def root_of x, parent
ret = parent[x]
unless ret == parent[ret]
ret = root_of(ret, parent)
parent[x] = ret
end
return ret
end
N, M = gets.split.map(&:to_i)
ps = [0] + gets.split.map(&:to_i)
parent = Array.new(N+1){ |i| i }
rank = Array.new(N+1,0)
M.times do |i|
x, y = gets.split.map(&:to_i)
# unless parent.has_key? x
# parent[x] = x
# rank[x] = 0
# end
# unless parent.has_key? y
# parent[y] = y
# rank[y] = 0
# end
xrt = root_of(x, parent)
yrt = root_of(y, parent)
rt, lf = xrt, yrt
rt, lf = lf, rt if rank[xrt] < rank[yrt]
parent[lf] = rt
rank[rt] += rank[lf]
# nx = ps[x-1]
# ny = ps[y-1]
# gx = gp[nx]
# gx = gp[gx] while gx != gp[gx]
# gy = gp[ny]
# gy = gp[gy] while gy != gp[gy]
# if gx != gy
# marged = [gx,gy].min
# ue = gp[nx]
# gp[nx] = marged
# ue, gp[ue] = gp[ue], marged while ue != marged
# ue = gp[ny]
# gp[ny] = marged
# ue, gp[ue] = gp[ue], marged while ue != marged
# # if gx < gy
# # gp[gy] = gx
# # gp[ny] = gx
# # else
# # gp[gx] = gy
# # gp[nx] = gy
# # end
# end
# # pp [x,y].join(" ")
# # x, y = y, x if gp[ps[x-1]] > gp[ps[y-1]]
# # gp[ps[y-1]] = gp[ps[x-1]]
# # pp gp
end
ret = 0
N.times do |i|
n = i+1
m = ps[n]
if root_of(n, parent) == root_of(m, parent)
ret += 1
end
# n_ue = gp[n]
# while n_ue != gp[n_ue]
# n_ue = gp[n_ue]
# end
# m_ue = gp[m]
# while m_ue != gp[m_ue]
# m_ue = gp[m_ue]
# end
# if n_ue == m_ue
# ret += 1
# end
end
# N.times do |i|
# ue = gp[i+1]
# while gp[ue] != ue
# gp[i+1] = gp[ue]
# ue = gp[i+1]
# end
# end
#pp gp
# ps.each_with_index do |p,i|
# ret += 1 if gp[ps[p-1]] == gp[p]
# end
# pp parent
# pp rank
puts ret
|
[
"call.remove"
] | 1,126,265
| 1,126,266
|
u714878632
|
ruby
|
p03359
|
a,b=gets.split.map(&:to_i)
p a<b ? a : b
|
a,b=gets.split.map(&:to_i)
p a<=b ? a : a - 1
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 1,126,773
| 1,126,774
|
u803684095
|
ruby
|
p03359
|
m,d = gets.split.map(&:to_i)
if m < d
puts m - 1
else
puts m
end
|
m,d = gets.split.map(&:to_i)
if m > d
puts m - 1
else
puts m
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,126,831
| 1,126,832
|
u437368899
|
ruby
|
p03359
|
a, b = gets.chomp.split.map(&:to_i)
if a == b
puts a
elsif a != b
puts a - 1
end
|
a, b = gets.chomp.split.map(&:to_i)
if a <= b
puts a
elsif
puts a - 1
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 1,126,904
| 1,126,905
|
u552761221
|
ruby
|
p03359
|
a, b = gets.chomp.split.map(&:to_i)
if a == b
puts b
elsif a != b
puts a - 1
end
|
a, b = gets.chomp.split.map(&:to_i)
if a <= b
puts a
elsif
puts a - 1
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 1,126,906
| 1,126,905
|
u552761221
|
ruby
|
p03359
|
a,b = gets.split.map(&:to_i)
if a >= b
puts a
else
puts a-1
end
|
a,b = gets.split.map(&:to_i)
if a <= b
puts a
else
puts a-1
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,256
| 1,127,257
|
u945412921
|
ruby
|
p03359
|
a, b = gets.split(' ').map(&:to_i)
count = 1 # 1/1
puts count if a == 1
count += (a - 1)
count -= 1 if a > b
puts count
|
a, b = gets.split(' ').map(&:to_i)
count = 1 # 1/1
if a != 1
count += (a - 1)
count -= 1 if a > b
end
puts count
|
[
"call.remove",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,281
| 1,127,282
|
u315984289
|
ruby
|
p03359
|
a,b = gets.split.map(&:to_i)
if b <= a
puts a
else
puts a - 1
end
|
a,b = gets.split.map(&:to_i)
if b >= a
puts a
else
puts a - 1
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,313
| 1,127,314
|
u962609087
|
ruby
|
p03359
|
a,b = gets.chomp.split(" ").map(&:to_i)
ans = a - 1
if a >= b
ans += 1
end
print(ans)
|
a,b = gets.chomp.split(" ").map(&:to_i)
ans = a - 1
if a <= b
ans += 1
end
print(ans)
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,362
| 1,127,363
|
u691896522
|
ruby
|
p03359
|
a, b = gets.chomp.split.map(&:to_i)
if b > a
puts a
exit
end
puts a - 1
|
a, b = gets.chomp.split.map(&:to_i)
if b >= a
puts a
exit
end
puts a - 1
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,678
| 1,127,679
|
u411903982
|
ruby
|
p03359
|
a,b = gets.split.map(&:to_i)
if b > a
puts a
else
puts a - 1
end
|
a,b = gets.split.map(&:to_i)
if b >= a
puts a
else
puts a - 1
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,737
| 1,127,738
|
u990788654
|
ruby
|
p03359
|
a, b = gets.chomp.split.map(&:to_i)
puts a < b ? a : a-1
|
a, b = gets.chomp.split.map(&:to_i)
puts a <= b ? a : a-1
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,741
| 1,127,742
|
u427155858
|
ruby
|
p03359
|
a, b = gets.chomp.split.map(&:to_i)
puts a < b ? a : b
|
a, b = gets.chomp.split.map(&:to_i)
puts a <= b ? a : a-1
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 1,127,743
| 1,127,742
|
u427155858
|
ruby
|
p03359
|
a,b=gets.chomp.split(" ").map { |e| e.to_i }
if b <= a
puts a
else
puts a-1
end
|
a,b=gets.chomp.split(" ").map { |e| e.to_i }
if b >= a
puts a
else
puts a-1
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,778
| 1,127,779
|
u267552846
|
ruby
|
p03359
|
a,b=gets.split.map(&:to_i)
puts a>=b ? a : a-1
|
a,b=gets.split.map(&:to_i)
puts a>b ? a-1 : a
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,815
| 1,127,816
|
u394482932
|
ruby
|
p03359
|
a,b=gets.split.map &:to_i
puts a<=b ? a : b
|
a,b=gets.split.map &:to_i
puts a<=b ? a : a-1
|
[
"call.arguments.change"
] | 1,127,894
| 1,127,895
|
u785521224
|
ruby
|
p03359
|
a,b=gets.split(" ").map(&:to_i)
if a>=b
puts a-1
else
puts a
end
|
a,b=gets.split(" ").map(&:to_i)
if a>b
puts a-1
else
puts a
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,127,997
| 1,127,998
|
u887087974
|
ruby
|
p03359
|
a,b=gets.split(" ").map(&:to_i)
if a>=b
puts b
else
puts a
end
|
a,b=gets.split(" ").map(&:to_i)
if a>b
puts a-1
else
puts a
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"call.arguments.change"
] | 1,127,999
| 1,127,998
|
u887087974
|
ruby
|
p03359
|
a,b=gets.split(" ").map(&:to_i)
if a>=b
puts a
else
puts b
end
|
a,b=gets.split(" ").map(&:to_i)
if a>b
puts a-1
else
puts a
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"identifier.change",
"call.arguments.change"
] | 1,128,000
| 1,127,998
|
u887087974
|
ruby
|
p03359
|
input = gets
a = input.split(' ')[0].to_i
b = input.split(' ')[1].to_i
if a < b
p a - 1
else
p a
end
|
input = gets
a = input.split(' ')[0].to_i
b = input.split(' ')[1].to_i
if a > b
p a - 1
else
p a
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 1,128,191
| 1,128,192
|
u601265472
|
ruby
|
p03359
|
input = gets
a = input.split(' ')[0].to_i
b = input.split(' ')[1].to_i
if a < b
p a - 1
elsif a >= b
p a
end
|
input = gets
a = input.split(' ')[0].to_i
b = input.split(' ')[1].to_i
if a > b
p a - 1
else
p a
end
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 1,128,193
| 1,128,192
|
u601265472
|
ruby
|
p03359
|
eval"a=%d;p a>%d?〜-a:a"%gets.split
|
eval"a=%d;p a>%d?~-a:a"%gets.split
|
[
"literal.string.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 1,128,415
| 1,128,416
|
u711705317
|
ruby
|
p03359
|
a,b = gets.split.map(&:to_i)
if a <= b
puts a
else
puts b
end
|
a,b = gets.split.map(&:to_i)
if a <= b
puts a
else
puts a-1
end
|
[
"call.arguments.change"
] | 1,128,458
| 1,128,457
|
u030898887
|
ruby
|
p03360
|
def solver
arr = gets.split.map(&:to_i).sort.reverse
k = gets.to_i
k.times do
arr[0] *= 2
end
print arr.reduce(&:+)
end
|
arr = gets.split.map(&:to_i).sort.reverse
k = gets.to_i
k.times do
arr[0] *= 2
end
print arr.reduce(&:+)
|
[] | 1,129,233
| 1,129,234
|
u644856766
|
ruby
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.