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 |
|---|---|---|---|---|---|---|---|
p02421
|
scoret, scoreh = 0, 0
gets.to_i.times do
taro, hanako = gets.split(" ")
if taro == hanako
scoret += 1
scoreh += 1
else
if taro > hanako
socoret += 3
else
scoreh += 3
end
end
end
puts [scoret, scoreh].join(" ")
|
scoret, scoreh = 0, 0
gets.to_i.times do
taro, hanako = gets.split(" ")
if taro == hanako
scoret += 1
scoreh += 1
else
if taro > hanako
scoret += 3
else
scoreh += 3
end
end
end
puts [scoret, scoreh].join(" ")
| null | 223,373
| 223,374
|
u514597327
|
ruby
|
p02467
|
def is_prime?(num)
$primes = []
return true if num == 2
return false if num % 2 == 0
$primes.each do |n|
return false if num % n == 0
end
$primes << num
return true
end
n = gets.chomp.to_i
nn = n
sub_n = 2
prime_factors = []
while n > 1
if n % sub_n == 0
n /= sub_n
prime_factors << sub_n
next
else
break if sub_n * sub_n > n
if sub_n == 2
sub_n += 1
else
sub_n += 2
while !is_prime?(sub_n)
sub_n += 2
end
end
end
end
str = "#{nn}:"
prime_factors.each do |k|
str += " #{k}"
end
if n == nn
str << " #{nn}"
end
puts str
|
def is_prime?(num)
$primes = []
return true if num == 2
return false if num % 2 == 0
$primes.each do |n|
return false if num % n == 0
end
$primes << num
return true
end
n = gets.chomp.to_i
nn = n
sub_n = 2
prime_factors = []
while n > 1
if n % sub_n == 0
n /= sub_n
prime_factors << sub_n
next
else
break if sub_n * sub_n > n
if sub_n == 2
sub_n += 1
else
sub_n += 2
while !is_prime?(sub_n)
sub_n += 2
end
end
end
end
str = "#{nn}:"
prime_factors.each do |k|
str += " #{k}"
end
if n > 1
str << " #{n}"
end
puts str
| null | 225,224
| 225,225
|
u720435069
|
ruby
|
p02468
|
M = 1000000007
def pow(x,n)
return 1 if n == 0
res = pow(x*x%M,n/2)
res *= x if n.odd?
res
end
m,n = gets.split.map {|e|e.to_i}
puts pow(m,n)
|
M = 1000000007
def pow(x,n)
return 1 if n == 0
res = pow(x*x%M,n/2)
res *= x if n.odd?
res%M
end
m,n = gets.split.map {|e|e.to_i}
puts pow(m,n)
| null | 225,264
| 225,265
|
u728700495
|
ruby
|
p02479
|
r=gets.to_i;P=3.1415926;puts [r*r*P,2*r*P]*" "
|
r=gets.to_f;P=Math::PI;puts [r*r*P,2*r*P]*" "
| null | 227,993
| 227,994
|
u890794282
|
ruby
|
p02479
|
r=gets.to_i;P=Math::PI;puts [r*r*P,2*r*P]*" "
|
r=gets.to_f;P=Math::PI;puts [r*r*P,2*r*P]*" "
| null | 227,995
| 227,994
|
u890794282
|
ruby
|
p02415
|
input_strings = gets.chomp.chars
length = input_strings.length
for i in 0..(length-1)
if input_strings[i] != input_strings[i].upcase
input_strings[i].upcase!
else input_strings[i] != input_strings[i].downcase
input_strings[i].downcase!
end
end
p input_strings.join
|
input_strings = gets.chomp.chars
length = input_strings.length
for i in 0..(length-1)
if input_strings[i] != input_strings[i].upcase
input_strings[i].upcase!
else input_strings[i] != input_strings[i].downcase
input_strings[i].downcase!
end
end
puts input_strings.join
| null | 218,452
| 218,453
|
u723368439
|
ruby
|
p02415
|
puts line = gets.chomp.capitalize
|
puts line = gets.chomp.swapcase
| null | 218,458
| 218,459
|
u251341266
|
ruby
|
p02416
|
loop{p(v=gets.chars.map(&:to_i).sum);v==0&&break}
|
loop{(v=gets.chars.map(&:to_i).sum)==0&&break;p v}
| null | 221,790
| 221,791
|
u526776155
|
ruby
|
p02416
|
ARGF.each{ |line|
break if line == "0"
a = line.split("").map(&:to_i)
puts a.inject(:+)
}
|
ARGF.each{ |line|
break if line.to_i == 0
a = line.split("").map(&:to_i)
puts a.inject(:+)
}
| null | 221,816
| 221,817
|
u330842660
|
ruby
|
p02416
|
while s=gets.strip
c=0
(0..s.size-1).each{|i| c+=s[i].to_i}
puts c
end
|
while (s=gets.strip)!=?0
c=0
(0..s.size-1).each{|i| c+=s[i].to_i}
puts c
end
| null | 221,821
| 221,822
|
u352522848
|
ruby
|
p02416
|
loop do
g=gets.chomp
break if g=='0'
puts g.chars.to_a.inject(0){|x,s| s + x.to_i}
end
|
loop do
g=gets.chomp
break if g=='0'
puts g.chars.to_a.inject(0){|s,x| s + x.to_i}
end
| null | 221,823
| 221,824
|
u714639016
|
ruby
|
p02417
|
h = gets(nil).chars.map(&:downcase).inject({}) { |h, c| h[c] ||= 0; h[c] += 1; h }
('a'..'z').each do |c|
puts [c, h[c] || 0].join(": ")
end
|
h = gets(nil).chars.map(&:downcase).inject({}) { |h, c| h[c] ||= 0; h[c] += 1; h }
('a'..'z').each do |c|
puts [c, h[c] || 0].join(" : ")
end
| null | 224,217
| 224,218
|
u390149337
|
ruby
|
p02417
|
h = Hash.new { 0 }
STDIN.read.each_char do |char|
h[char] += 1 if char =~ /[a-zA-Z]/
end
('a'..'z').each do |char|
puts "#{char} : #{h[char]}"
end
|
h = Hash.new { 0 }
STDIN.read.each_char do |char|
h[char.downcase] += 1 if char =~ /[a-zA-Z]/
end
('a'..'z').each do |char|
puts "#{char} : #{h[char]}"
end
| null | 224,259
| 224,260
|
u670581076
|
ruby
|
p02417
|
str = ""
while add = gets.chomp
str += add
end
for i in 97..122
puts "#{i.chr} : #{str.scan(/[#{i.chr}#{(i-32).chr}]/).size}"
end
|
str = ""
while add = gets
str += add
end
for i in 97..122
puts "#{i.chr} : #{str.scan(/[#{i.chr}#{(i-32).chr}]/).size}"
end
| null | 224,282
| 224,283
|
u350127362
|
ruby
|
p02417
|
# 標準入力,小文字にしてアルファベットだけ取り出す
str = gets(chomp:true).downcase.scan(/[a-z]/)
# a~zのハッシュ作成
alp = {}
("a".."z").each do | a |
alp[a] = 0
end
# a~zのハッシュに標準入力の文字数を加算
str.each do | a |
alp[a] += 1
end
# 出力
alp.each do |key,value|
puts "#{key} : #{value}"
end
|
str = $stdin.read.downcase.scan(/[a-z]/)
# a~zのハッシュ作成
alp = {}
("a".."z").each do | a |
alp[a] = 0
end
# a~zのハッシュに標準入力の文字数を加算
str.each do | a |
alp[a] += 1
end
# 出力
alp.each do |key,value|
puts "#{key} : #{value}"
end
| null | 224,289
| 224,290
|
u958508535
|
ruby
|
p02417
|
str = read.downcase.scan(/[a-z]/)
# a~zのハッシュ作成
alp = {}
("a".."z").each do | a |
alp[a] = 0
end
# a~zのハッシュに標準入力の文字数を加算
str.each do | a |
alp[a] += 1
end
# 出力
alp.each do |key,value|
puts "#{key} : #{value}"
end
|
str = $stdin.read.downcase.scan(/[a-z]/)
# a~zのハッシュ作成
alp = {}
("a".."z").each do | a |
alp[a] = 0
end
# a~zのハッシュに標準入力の文字数を加算
str.each do | a |
alp[a] += 1
end
# 出力
alp.each do |key,value|
puts "#{key} : #{value}"
end
| null | 224,291
| 224,290
|
u958508535
|
ruby
|
p02417
|
obj = {}
("a".."z").each do |s|
obj[s] = 0
end
while (ln = gets) do
ln.downcase.gsub(/[^a-z]/, '').chars do |key|
obj[key] += 1
end
end
obj.each do |key, val|
puts "#{key}:#{val}"
end
|
obj = {}
("a".."z").each do |s|
obj[s] = 0
end
while (ln = gets) do
ln.downcase.gsub(/[^a-z]/, '').chars do |key|
obj[key] += 1
end
end
obj.each do |key, val|
puts "#{key} : #{val}"
end
| null | 224,298
| 224,299
|
u252204578
|
ruby
|
p02489
|
1.upto(10){|i|puts"Case #{i}: #{("0\n"==g=gets)?break: g}"}
|
1.upto(1e5){|i|puts"Case #{i}: #{("0\n"==g=gets)?break: g}"}
| null | 234,165
| 234,166
|
u890794282
|
ruby
|
p02489
|
n=0
i=[0]
while true do
input = gets.to_i
i[n] = input
if i[n]==0 then
break
end
n+=1
end
n=0
while true do
if i[n]==0 then
break
end
puts "Case #{n}: #{i[n]}"
n=n+1
end
|
n=1
i=[0]
while true do
input = gets.to_i
i[n] = input
if i[n]==0 then
break
end
n+=1
end
n=1
while true do
if i[n]==0 then
break
end
puts "Case #{n}: #{i[n]}"
n=n+1
end
| null | 234,204
| 234,205
|
u909973908
|
ruby
|
p02489
|
inputList = Array.new()
begin
inputLine = STDIN.gets
inputList.push(inputLine.to_i)
end until inputLine.to_i == 0
i = 1
while i < inputList.length
print "case ", i, ": ", inputList[i-1], "\n"
i += 1
end
|
inputList = Array.new()
begin
inputLine = STDIN.gets
inputList.push(inputLine.to_i)
end until inputLine.to_i == 0
i = 1
while i < inputList.length
print "Case ", i, ": ", inputList[i-1], "\n"
i += 1
end
| null | 234,206
| 234,207
|
u975936028
|
ruby
|
p02546
|
S = gets.split('')
if S.last != "s"
S << "s"
puts S.join
else
S << "es"
puts S.join
end
|
S = gets.chomp.split('')
if S.last != "s"
S << "s"
puts S.join
else
S << "es"
puts S.join
end
| null | 243,313
| 243,314
|
u978576991
|
ruby
|
p02536
|
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
#====UnionFindTree====
class UnionFindTree
attr_accessor:parent,:size,:rank,:group
def initialize(n)
@parent=Array.new(n){|idx| idx}
@rank=Array.new(n,0)
@size=Array.new(n,1)
end
def find(x)
return x if @parent[x]==x
@parent[x]=find(@parent[x])
return @parent[x]
end
def union(x,y)
par_x=find(x)
par_y=find(y)
return if par_x==par_y
if @rank[par_x]<@rank[par_y]
@parent[par_x]=par_y
@size[par_y]+=@size[par_x]
else
@parent[par_y]=par_x
@size[par_x]+=@size[par_y]
@rank[par_x]+=1 if @rank[par_x]==@rank[par_y]
end
end
def same?(x,y)
return find(x)==find(y)
end
def get_size(x)
return @size[find(x)]
end
def make_groups()
n=@parent.size
@group=Array.new(n){ Array.new }
@parent.each_with_index do|par,i|
@group[find(par)]<< i
end
end
end
N,M=get_i
uft=UnionFindTree.new(N)
M.times do|i|
a,b=get_i.map{|x| x-=1}
uft.union(a,b)
end
uft.make_groups
ans=N
N.times do|i|
ans-=1 unless uft.group[i]==[]
end
puts ans
|
def get_i()
return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
return bool ? y : n
end
#create of array
def array(size1,init=nil,size2=-1)
if size2==-1
return Array.new(size1){init}
else
return Array.new(size2){Array.new(size1){init}}
end
end
def max(a,b)
return a>b ? a : b
end
def min(a,b)
return a>b ? b : a
end
INF=Float::INFINITY
#====UnionFindTree====
class UnionFindTree
attr_accessor:parent,:size,:rank,:group
def initialize(n)
@parent=Array.new(n){|idx| idx}
@rank=Array.new(n,0)
@size=Array.new(n,1)
end
def find(x)
return x if @parent[x]==x
@parent[x]=find(@parent[x])
return @parent[x]
end
def union(x,y)
par_x=find(x)
par_y=find(y)
return if par_x==par_y
if @rank[par_x]<@rank[par_y]
@parent[par_x]=par_y
@size[par_y]+=@size[par_x]
else
@parent[par_y]=par_x
@size[par_x]+=@size[par_y]
@rank[par_x]+=1 if @rank[par_x]==@rank[par_y]
end
end
def same?(x,y)
return find(x)==find(y)
end
def get_size(x)
return @size[find(x)]
end
def make_groups()
n=@parent.size
@group=Array.new(n){ Array.new }
@parent.each_with_index do|par,i|
@group[find(par)]<< i
end
end
end
N,M=get_i
uft=UnionFindTree.new(N)
M.times do|i|
a,b=get_i.map{|x| x-=1}
uft.union(a,b)
end
uft.make_groups
ans=0
N.times do|i|
ans+=1 unless uft.group[i]==[]
end
puts ans-1
| null | 241,286
| 241,287
|
u415400221
|
ruby
|
p02547
|
n = gets.to_i
a = Array.new(n) { b = gets.split.map(&:to_i); b[0] == b[1] }
flag = false
(2...(a.size)).each do |i|
if a[i] && a[i-1] && a[i-1]
flag = true
break
end
end
puts flag ? "Yes" : "No"
|
n = gets.to_i
a = Array.new(n) { b = gets.split.map(&:to_i); b[0] == b[1] }
flag = false
(2...(a.size)).each do |i|
if a[i] && a[i-1] && a[i-2]
flag = true
break
end
end
puts flag ? "Yes" : "No"
| null | 245,046
| 245,047
|
u016444909
|
ruby
|
p02552
|
p gets.toi^1
|
p gets.to_i^1
| null | 247,602
| 247,603
|
u244203620
|
ruby
|
p02552
|
x = gets.to_i
if x == 1
puts x
else
puts x
end
|
x = gets.to_i
if x == 0
puts 1
else
puts 0
end
| null | 247,598
| 247,599
|
u231155602
|
ruby
|
p02553
|
a,b,c,d = gets.split.map(&:to_i)
puts [a*c,a*d,b*c,d*d].max
|
a,b,c,d = gets.split.map(&:to_i)
puts [a*c,a*d,b*c,b*d].max
| null | 248,443
| 248,444
|
u244087909
|
ruby
|
p02570
|
a,b,c=gets.split.map &:to_i
p a>b*c ? :No : :Yes
|
a,b,c=gets.split.map &:to_i
puts a>b*c ? :No : :Yes
| null | 255,233
| 255,234
|
u657913472
|
ruby
|
p02570
|
d,t,s=gets.chomp.split(" ").map(&:to_i);
if t*s>=1000
print "Yes"
else
print "No"
end
|
d,t,s=gets.chomp.split(" ").map(&:to_i);
if t*s>=d
print "Yes"
else
print "No"
end
| null | 255,648
| 255,649
|
u492991702
|
ruby
|
p02570
|
d, t, s = gets.split.map(&:to_i)
min = 0
if d % s >= 0
min = (d / s) + 1
else
min = d / s
end
if min <= t
puts "Yes"
else
puts "No"
end
|
d, t, s = gets.split.map(&:to_i)
min = 0
if d % s > 0
min = (d / s) + 1
else
min = d / s
end
if min <= t
puts "Yes"
else
puts "No"
end
| null | 257,528
| 257,529
|
u212791500
|
ruby
|
p02554
|
n = gets.to_i
t1 = 1 #0-9
t2 = 1 #1-8
t3 = 1 #1-9 or 0-8
mod = 10**9 + 7
for i in 0...n
t1 *= 10
t2 *= 8
t3 *= 9
t1 %= mod
t2 %= mod
t3 %= mod
end
ans = t1 - t2 - (t3-t2) * 2
if ans < 0
ans += mod
end
puts ans
|
n = gets.to_i
t1 = 1 #0-9
t2 = 1 #1-8
t3 = 1 #1-9 or 0-8
mod = 10**9 + 7
for i in 0...n
t1 *= 10
t2 *= 8
t3 *= 9
t1 %= mod
t2 %= mod
t3 %= mod
end
ans = t1 - t2 - (t3-t2) * 2
ans %= mod
puts ans
| null | 251,269
| 251,270
|
u054798759
|
ruby
|
p02554
|
N = gets.to_i
Mod = 10 ** 9 + 7
def modpow(x,p) #x^p
result = 1
for i in 1..p do
result = (result * x) % Mod
end
return result
end
if N == 1 then
puts 0
else
puts modpow(10,N) - 2 * modpow(9,N) + modpow(8,N)
end
|
N = gets.to_i
Mod = 10 ** 9 + 7
def modpow(x,p) #x^p
result = 1
for i in 1..p do
result = (result * x) % Mod
end
return result
end
if N == 1 then
puts 0
else
puts (modpow(10,N) - 2 * modpow(9,N) + modpow(8,N)) % Mod
end
| null | 252,362
| 252,363
|
u569559028
|
ruby
|
p02582
|
s = gets.split("")
p s
#ans = 0
s.length.times{ |i|
if s[i]== 'R'
ans += 1
end
}
if s[1] == 'S' and ans == 2
ans = 1
end
puts ans
|
s = gets.split("")
#p s
ans = 0
s.length.times{ |i|
if s[i]== 'R'
ans += 1
end
}
if s[1] == 'S' and ans == 2
ans = 1
end
puts ans
| null | 281,171
| 281,172
|
u341702138
|
ruby
|
p02582
|
str = gets.champ
puts str.scan(/R+/).map(&:size).max.to_i
|
str = gets.chomp
puts str.scan(/R+/).map(&:size).max.to_i
| null | 281,439
| 281,440
|
u295003004
|
ruby
|
p02583
|
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans = 0
arr.sort!
if arr.length < 3
puts "0"
end
0.step(arr.length-1) do |a|
a.step(arr.length-1) do |b|
b.step(arr.length-1)do |c|
if arr[a] != arr[b] && arr[b] != arr[c] && arr[c] != arr[a]
if arr[a] < arr[b]+arr[c] && (arr[b]-arr[c]).abs < arr[a]
ans += 1
end
end
end
end
end
puts ans
|
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans = 0
arr.sort!
if arr.length <= 2
puts "0"
exit
end
0.step(arr.length-1) do |a|
a.step(arr.length-1) do |b|
b.step(arr.length-1)do |c|
if arr[a] != arr[b] && arr[b] != arr[c] && arr[c] != arr[a]
if arr[a] < arr[b]+arr[c] && (arr[b]-arr[c]).abs < arr[a]
ans += 1
end
end
end
end
end
puts ans
| null | 284,031
| 284,032
|
u688809543
|
ruby
|
p02584
|
x, k, d = gets.chomp.split.map(&:to_i)
abs_x = x.abs
a, b = abs_x.divmod(d)
if k < a
puts x + (-1 * d * k)
else
if (k - a).odd?
puts (d - b).abs
else
puts b
end
end
|
x, k, d = gets.chomp.split.map(&:to_i)
abs_x = x.abs
a, b = abs_x.divmod(d)
if k < a
puts abs_x + (-1 * d * k)
else
if (k - a).odd?
puts (d - b).abs
else
puts b
end
end
| null | 285,479
| 285,480
|
u639006399
|
ruby
|
p02577
|
# your code goes here
a = gets.chomp.to_i
puts((a%9==0) ? "YES" : "NO")
|
# your code goes here
a = gets.chomp.to_i
puts((a%9==0) ? "Yes" : "No")
| null | 275,606
| 275,607
|
u624520031
|
ruby
|
p02571
|
s = gets.chomp.split("")
t = gets.chomp.split("")
max = 0
s.size.times do |i|
count = 0
t.size.times do |j|
if s[i+j].nil?
break
end
if s[i+j]==t[j]
count += 1
end
end
if max < count
max = count
end
end
puts("#{t.size-max}")
|
s = gets.chomp.split("")
t = gets.chomp.split("")
max = 0
s.size.times do |i|
count = 0
t.size.times do |j|
if s[i+j].nil?
count = 0
break
end
if s[i+j]==t[j]
count += 1
end
end
if max < count
max = count
end
end
puts("#{t.size-max}")
| null | 263,730
| 263,731
|
u879573689
|
ruby
|
p02572
|
# n = gets.chomp.to_i
# a = gets.chomp.split(" ").map(&:to_i)
# ans = 0
mod = 10 ** 9 + 7
# i = 0
# while true
# t = i + 1
# kake = 0
# until t == n
# kake += (a[t] % mod)
# t += 1
# end
# ans = ans + (a[i] * kake) % mod
# ans %= mod
# if i == n - 2
# break
# end
# i += 1
# end
# puts ans
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = 0
hiku = 0
a.each do |i|
ans += i
hiku += i * i
end
puts ((ans * ans - hiku) % mod) / 2
|
# n = gets.chomp.to_i
# a = gets.chomp.split(" ").map(&:to_i)
# ans = 0
mod = 10 ** 9 + 7
# i = 0
# while true
# t = i + 1
# kake = 0
# until t == n
# kake += (a[t] % mod)
# t += 1
# end
# ans = ans + (a[i] * kake) % mod
# ans %= mod
# if i == n - 2
# break
# end
# i += 1
# end
# puts ans
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = 0
hiku = 0
a.each do |i|
ans += i
hiku += i * i
end
puts ((ans * ans - hiku)/ 2) % mod
| null | 267,625
| 267,626
|
u412789323
|
ruby
|
p02573
|
n,m = gets.split.map(&:to_i)
class UnionFind
def initialize(size)
@rank = Array.new(size,0)
@parent = Array.new(size,&:itself)
end
def getRoot(x)
@parent[x] == x ? x : (@parent[x] = getRoot(@parent[x]))
end
def unite(x,y)
xp = getRoot(x)
yp = getRoot(y)
if xp == yp
return
elsif @rank[xp] > @rank[yp]
@parent[yp] = xp
else
@parent[xp] = yp
@rank[yp] += 1 if @rank[xp] = @rank[yp]
end
end
def same?(x,y)
getRoot(x) == getRoot(y)
end
def size
@parent.map{|x| getRoot(x)}.uniq.size
end
def sizeOfTree
data = Array.new(@parent.size,0)
for i in 0..(@parent.size-1)
data[getRoot(i)] += 1
end
data
end
end
friends = UnionFind.new(n)
m.times do
a,b = gets.split.map(&:to_i)
friends.unite(a-1,b-1)
end
p friends.sizeOfTree.max
p friends.sizeOfTree
|
n,m = gets.split.map(&:to_i)
class UnionFind
def initialize(size)
@rank = Array.new(size,0)
@parent = Array.new(size,&:itself)
end
def getRoot(x)
@parent[x] == x ? x : (@parent[x] = getRoot(@parent[x]))
end
def unite(x,y)
xp = getRoot(x)
yp = getRoot(y)
if xp == yp
return
elsif @rank[xp] > @rank[yp]
@parent[yp] = xp
else
@parent[xp] = yp
@rank[yp] += 1 if @rank[xp] = @rank[yp]
end
end
def same?(x,y)
getRoot(x) == getRoot(y)
end
def size
@parent.map{|x| getRoot(x)}.uniq.size
end
def sizeOfTree
data = Array.new(@parent.size,0)
for i in 0..(@parent.size-1)
data[getRoot(i)] += 1
end
data
end
end
friends = UnionFind.new(n)
m.times do
a,b = gets.split.map(&:to_i)
friends.unite(a-1,b-1)
end
p friends.sizeOfTree.max
| null | 269,737
| 269,738
|
u911373146
|
ruby
|
p02574
|
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
mx = A.max
sieve = Array.new(mx+1).map{[]}
(2..mx/2).each{|i|
next if not sieve[i].empty?
j=2*i
while j <= mx do
sieve[j] << i
j += i
end
}
prm = Hash.new{|h, k| h[k] = 0}
A.each{|a|
sieve[a].empty? ? prm[a] += 1 : sieve[a].each{|i| prm[i] += 1}
}
if prm.all?{|k, v| v == 1} then
puts 'pairwise coprime'
elsif prm.any?{|k, v| v == N} then
puts 'not coprime'
else
puts 'setwise coprime'
end
|
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
mx = A.max
sieve = Array.new(mx+1).map{[]}
(2..mx/2).each{|i|
next if not sieve[i].empty?
j=2*i
while j <= mx do
sieve[j] << i
j += i
end
}
prm = Hash.new{|h, k| h[k] = 0}
A.each{|a|
next if a == 1
sieve[a].empty? ? prm[a] += 1 : sieve[a].each{|i| prm[i] += 1}
}
if prm.all?{|k, v| v == 1} then
puts 'pairwise coprime'
elsif prm.any?{|k, v| v == N} then
puts 'not coprime'
else
puts 'setwise coprime'
end
| null | 270,131
| 270,132
|
u276517671
|
ruby
|
p02574
|
require 'prime'
n=gets.to_i
a=gets.split.map(&:to_i)
l=[0]*1000001
a.each do |aa|
l[aa]+=1
end
s=0
Prime.each(1000000).to_a do |i|
x=i
c=0
while x<=1000000
if l[x]>0
c+=l[x]
end
x+=i
end
s=c if s<c
end
#s=l.max
if s<=1
puts "pairwise coprime"
elsif s==n
puts "not coprime"
else
puts "setwise coprime"
end
|
require 'prime'
n=gets.to_i
a=gets.split.map(&:to_i)
l=[0]*1000001
a.each do |aa|
l[aa]+=1
end
s=0
Prime.each(1000000).to_a.each do |i|
x=i
c=0
while x<=1000000
if l[x]>0
c+=l[x]
end
x+=i
end
s=c if s<c
end
#s=l.max
if s<=1
puts "pairwise coprime"
elsif s==n
puts "not coprime"
else
puts "setwise coprime"
end
| null | 270,212
| 270,213
|
u744908753
|
ruby
|
p02594
|
x = get.to_i
if x >= 30
puts "Yes"
else
puts "No"
end
|
x = gets.to_i
if x >= 30
puts "Yes"
else
puts "No"
end
| null | 298,216
| 298,217
|
u067532505
|
ruby
|
p02594
|
pruts (gets.to_i>=30 ? "Yes" : "No")
|
puts (gets.to_i>=30 ? "Yes" : "No")
| null | 291,750
| 291,751
|
u054798759
|
ruby
|
p02598
|
#!/usr/bin/env ruby
require 'set'
class Hash
def push(key, value)
self[key] = [] if self[key] == nil
self[key].push(value)
end
end
class Array
def lower_bound(value)
left = -1;
right = self.length;
while left + 1 < right
mid = left + (right - left) / 2;
if self[mid] >= value
right = mid
else
left = mid
end
end
right
end
def unique
res = [self.first]
each_cons(2) do |a, b|
if a != b
res.push(b)
end
end
res
end
end
def get_ints
gets.chomp.split.map(&:to_i)
end
def get_ints_minus_one
get_ints.map { |x| x - 1 }
end
def get_int
gets.chomp.to_i
end
require 'bigdecimal'
N, K = get_ints
A = get_ints
# ax = A.sort.map { |a| [BigDecimal(a), 1, BigDecimal(a)] }
# count = 0
# while count < K
# value, divided, first = ax.pop
# value = first / (divided + 1)
# next_value = [value, divided + 1, first]
# index = ax.bsearch_index { |a| a[0] >= value }
# if index.nil?
# ax.push(next_value)
# else
# ax.insert(index, next_value)
# end
# count += 1
# # p ax.map { |a| {value: a[:value].to_f, divided: a[:divided], first: a[:first].to_f} }
# end
#
# puts ax.last[0].ceil
ax = A.sort.map { |a| a.to_f }
high = ax.last.to_i
low = 1
while high - low > 1
mid = low + (high - low) / 2
index = ax.bsearch_index { |a| a > mid }
count = 0
ax[index..].each do |a|
count += (a / mid).ceil - 1
end
if count <= K
high = mid
else
low = mid
end
end
puts high
|
#!/usr/bin/env ruby
require 'set'
class Hash
def push(key, value)
self[key] = [] if self[key] == nil
self[key].push(value)
end
end
class Array
def lower_bound(value)
left = -1;
right = self.length;
while left + 1 < right
mid = left + (right - left) / 2;
if self[mid] >= value
right = mid
else
left = mid
end
end
right
end
def unique
res = [self.first]
each_cons(2) do |a, b|
if a != b
res.push(b)
end
end
res
end
end
def get_ints
gets.chomp.split.map(&:to_i)
end
def get_ints_minus_one
get_ints.map { |x| x - 1 }
end
def get_int
gets.chomp.to_i
end
require 'bigdecimal'
N, K = get_ints
A = get_ints
# ax = A.sort.map { |a| [BigDecimal(a), 1, BigDecimal(a)] }
# count = 0
# while count < K
# value, divided, first = ax.pop
# value = first / (divided + 1)
# next_value = [value, divided + 1, first]
# index = ax.bsearch_index { |a| a[0] >= value }
# if index.nil?
# ax.push(next_value)
# else
# ax.insert(index, next_value)
# end
# count += 1
# # p ax.map { |a| {value: a[:value].to_f, divided: a[:divided], first: a[:first].to_f} }
# end
#
# puts ax.last[0].ceil
ax = A.sort.map { |a| a.to_f }
high = ax.last.to_i
low = 0
while high - low > 1
mid = (high + low) / 2
index = ax.bsearch_index { |a| a > mid }
count = 0
ax[index..].each do |a|
count += (a / mid).ceil - 1
end
if count <= K
high = mid
else
low = mid
end
end
puts high
| null | 306,880
| 306,881
|
u305883349
|
ruby
|
p02600
|
x = gets.to_i
if 400 <= x && x <= 599
puts 8
elsif 600 <= x && x <= 799
puts 7
elsif 800 <= x && 999
puts 6
elsif 1000 <= x && x <= 1199
puts 5
elsif 1200 <= x && x <= 1399
puts 4
elsif 1400 <= x && x <= 1599
puts 3
elsif 1600 <= x && x <= 1799
puts 2
elsif 1800 <= x && x <= 1999
puts 1
end
|
x = gets.to_i
if 400 <= x && x <= 599
puts 8
elsif 600 <= x && x <= 799
puts 7
elsif 800 <= x && x <= 999
puts 6
elsif 1000 <= x && x <= 1199
puts 5
elsif 1200 <= x && x <= 1399
puts 4
elsif 1400 <= x && x <= 1599
puts 3
elsif 1600 <= x && x <= 1799
puts 2
elsif 1800 <= x && x <= 1999
puts 1
end
| null | 303,290
| 303,291
|
u392423112
|
ruby
|
p02600
|
x = gets.to_i
for i in 0..7
if x >= 400 + i * 200 && x <= 400 + (i+1) * 200
puts 8 - i
end
end
|
x = gets.to_i
for i in 0..7
if x >= 400 + i * 200 && x < 400 + (i+1) * 200
puts 8 - i
exit
end
end
| null | 303,311
| 303,312
|
u265679940
|
ruby
|
p02601
|
r, g, b = gets.split.map &:to_i
k = gets.to_i
k.times do
if g <= r
g *=2
elsif b <= g
b *= 2
end
if b > g && g > r
puts "Yes"
exit
end
end
|
r, g, b = gets.split.map &:to_i
k = gets.to_i
k.times do
if g <= r
g *=2
elsif b <= g
b *= 2
end
if b > g && g > r
puts "Yes"
exit
end
end
puts "No"
| null | 305,337
| 305,338
|
u953495504
|
ruby
|
p02603
|
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
mon = 1000;kab = 0
(n-2).times do |k|
if arr[k] < arr[k+1] && kab == 0
kab += mon / arr[k]
mon -= arr[k] * kab
end
if arr[k] > arr[k+1]
mon += arr[k] * kab
kab = 0
end
end
if kab != 0
mon += arr[n-1] * kab
kab = 0
end
puts mon
|
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
mon = 1000;kab = 0
(n-1).times do |k|
if arr[k] < arr[k+1] && kab == 0
kab += mon / arr[k]
mon -= arr[k] * kab
end
if arr[k] > arr[k+1]
mon += arr[k] * kab
kab = 0
end
end
if kab != 0
mon += arr[n-1] * kab
kab = 0
end
puts mon
| null | 309,266
| 309,267
|
u688809543
|
ruby
|
p02607
|
N = gets.to_i
A = gets.split.map(&:to_i)
puts A.select.with_index { |a, i| a.odd? && i.odd? }.size
|
N = gets.to_i
A = gets.split.map(&:to_i)
puts A.select.with_index(1) { |a, i| a.odd? && i.odd? }.size
| null | 310,663
| 310,664
|
u740836226
|
ruby
|
p02607
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
cnt = 0
i = 1
while i < n
cnt += 1 if !arr[i].even?
i += 2
end
puts cnt
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
cnt = 0
i = 0
while i < n
cnt += 1 if !arr[i].even?
i += 2
end
puts cnt
| null | 310,690
| 310,691
|
u409390792
|
ruby
|
p02607
|
# frozen_string_literal: true
N = gets.chomp.to_i
ar = gets.chomp.split.map(&:to_i)
ans = 0
ar.each_with_index do |value, index|
ans += 1 if index.odd? && value.odd?
end
puts ans
|
# frozen_string_literal: true
N = gets.chomp.to_i
ar = gets.chomp.split.map(&:to_i)
ans = 0
ar.each_with_index do |value, index|
ans += 1 if (index + 1).odd? && value.odd?
end
puts ans
| null | 311,046
| 311,047
|
u727437745
|
ruby
|
p02613
|
n = gets.to_i
s = []
n.times do
s << gets.chomp
end
["AC", "WA", "TLE", "RE"].each do |str|
puts str + " × " + s.count(str).to_s
end
|
n = gets.to_i
s = []
n.times do
s << gets.chomp
end
["AC", "WA", "TLE", "RE"].each do |str|
puts str + " x " + s.count(str).to_s
end
| null | 320,593
| 320,594
|
u139850627
|
ruby
|
p02613
|
ans = { AC: 0, WA: 0, TLE: 0, RE: 0 }
puts ans.inspect
gets.to_i.times do
s = gets.chomp
ans[s.to_sym] += 1
end
ans.each do |k, v|
puts "#{k} x #{v}"
end
|
ans = { AC: 0, WA: 0, TLE: 0, RE: 0 }
gets.to_i.times do
s = gets.chomp
ans[s.to_sym] += 1
end
ans.each do |k, v|
puts "#{k} x #{v}"
end
| null | 321,615
| 321,616
|
u729246375
|
ruby
|
p02613
|
i = gets.to_i
arr = []
i.times do |i|
arr.push(gets.chomp)
end
puts ('AC x ' + arr.count('AC').to_s)
puts ('WA x ' + arr.count('WA').to_s)
puts ('TLE x ' + arr.count('TLE').to_s)
puts ('RE x ' + arr.count('Re').to_s)
|
i = gets.to_i
arr = []
i.times do |i|
arr.push(gets.chomp)
end
puts ('AC x ' + arr.count('AC').to_s)
puts ('WA x ' + arr.count('WA').to_s)
puts ('TLE x ' + arr.count('TLE').to_s)
puts ('RE x ' + arr.count('RE').to_s)
| null | 322,067
| 322,068
|
u866614353
|
ruby
|
p02623
|
n,m,k = gets.to_s.split.map{ |v| v.to_i }
a = gets.to_s.split.map{ |v| v.to_i }
b = gets.to_s.split.map{ |v| v.to_i }
csa = a.each_with_object([0]) { |v, h| h << h[-1] + v }
csb = b.each_with_object([0]) { |v, h| h << h[-1] + v }
ans = 0
1.upto(n) do |i|
next if csa[i] > k
r = k - csa[i] # 残っている時間
j = csb.bsearch_index {|v| r < v } || m + 1
ans = i + j - 1 if ans < i + j - 1
end
puts ans
|
n,m,k = gets.to_s.split.map{ |v| v.to_i }
a = gets.to_s.split.map{ |v| v.to_i }
b = gets.to_s.split.map{ |v| v.to_i }
csa = a.each_with_object([0]) { |v, h| h << h[-1] + v }
csb = b.each_with_object([0]) { |v, h| h << h[-1] + v }
ans = 0
# aを読まない選択肢
0.upto(n) do |i|
next if csa[i] > k
r = k - csa[i] # 残っている時間
j = csb.bsearch_index {|v| r < v } || m + 1
ans = i + j - 1 if ans < i + j - 1
end
puts ans
| null | 334,456
| 334,457
|
u106964380
|
ruby
|
p02628
|
n, k = gets.map(&:to_i)
p gets.map(&:to_i).sort.first(k).sum
|
n, k = gets.split.map(&:to_i)
p gets.split.map(&:to_i).sort.first(k).sum
| null | 338,940
| 338,941
|
u306155637
|
ruby
|
p02639
|
x = gets.chomp.splite(" ").map(&:to_i)
x.each_with_index do |n, i|
if n == 0
print i
end
end
|
x = gets.chomp.split(" ").map(&:to_i)
x.each_with_index do |n, i|
if n == 0
print i+1
end
end
| null | 349,591
| 349,592
|
u731036814
|
ruby
|
p02639
|
a = gets.split(' ')
for i in 0..a.length - 1
puts i if a[i].to_i == 0
end
|
a = gets.split(' ')
for i in 0..a.length - 1
puts i+1 if a[i].to_i == 0
end
| null | 350,024
| 350,025
|
u341534571
|
ruby
|
p02639
|
x = gets.split(" ").map(&:to_i)
x.each with index do |val, i|
if val == 0
puts i+1
exit
end
end
|
x = gets.split(" ").map(&:to_i)
x.each_with_index do |val, i|
if val == 0
puts i+1
exit
end
end
| null | 350,172
| 350,173
|
u742129941
|
ruby
|
p02639
|
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
def r_up(a, b) (a+b-1)/b end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
x = inp
p x.index(0)
|
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
def r_up(a, b) (a+b-1)/b end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
x = inp
p x.index(0)+1
| null | 350,301
| 350,302
|
u145123922
|
ruby
|
p02640
|
x, y = gets.split(" ").map(&:to_i)
ans = "No"
i = 0
while (x -i) > 0
if (2*i + 4*(x-i)) == y
ans = "Yes"
break
end
i+=1
end
puts ans
|
x, y = gets.split(" ").map(&:to_i)
ans = "No"
i = 0
while (x -i) >= 0
if (2*i + 4*(x-i)) == y
ans = "Yes"
break
end
i+=1
end
puts ans
| null | 350,364
| 350,365
|
u341702138
|
ruby
|
p02641
|
x, n = gets.chomp.split(' ').map{|i| i.to_i }
if n == 0
puts x
exit
end
pset = {}
pp = gets.chomp.split(' ').map{|i|
ii = i.to_i
pset[ii] = true
}
if pset[x].nil?
puts x
else
cursordiff = 1
cursormax = x + cursordiff
cursormin = x - cursordiff
while pset[cursormax] && pset[cursormin]
cursordiff += 1
cursormax = x + cursordiff
cursormin = x - cursordiff
end
if pset[cursormax].nil?
puts cursormax
else
puts cursormin
end
end
|
x, n = gets.chomp.split(' ').map{|i| i.to_i }
if n == 0
puts x
exit
end
pset = {}
pp = gets.chomp.split(' ').map{|i|
ii = i.to_i
pset[ii] = true
}
if pset[x].nil?
puts x
else
cursordiff = 1
cursormax = x + cursordiff
cursormin = x - cursordiff
while pset[cursormax] && pset[cursormin]
cursordiff += 1
cursormax = x + cursordiff
cursormin = x - cursordiff
end
if pset[cursormin].nil?
puts cursormin
else
puts cursormax
end
end
| null | 360,836
| 360,837
|
u208362438
|
ruby
|
p02659
|
line = gets
first, second = line.split(' ')
result = BigDecimal(first) * BigDecimal(second)
put result.to_i
|
require 'bigdecimal'
line = gets
first, second = line.split(' ')
result = BigDecimal(first) * BigDecimal(second)
puts result.to_i
| null | 378,062
| 378,063
|
u305883349
|
ruby
|
p02659
|
array = gets.chomp.split
A = array[0].to_i
B = (array[1].to_f * 100).to_i
ans = A * B / 100
puts ans
|
array = gets.chomp.split
A = array[0].to_i
B = (array[1].to_f * 100 + 0.5).to_i
ans = (A * B) / 100
puts ans
| null | 378,909
| 378,910
|
u854388580
|
ruby
|
p02659
|
a, b = gets.split
puts a.to_i * (b.to_f * 100).floor / 100
|
a, b = gets.split
puts a.to_i * (b.to_f * 100 + 0.1).floor / 100
| null | 379,874
| 379,875
|
u389410817
|
ruby
|
p02659
|
A,B = gets.chomp.split.map(&:to_f)
if A.zero? || B.zero?
puts 0
exit
end
a = A.to_i
b = (B * 100).to_i
puts (a * b)/100
|
A,B = gets.chomp.split.map(&:to_f)
if A.zero? || B.zero?
puts 0
exit
end
a = A.to_i
b = (B * 1000).to_i
puts (a * b)/1000
| null | 378,905
| 378,906
|
u157887852
|
ruby
|
p02675
|
n=gets.chars[-1].to_i
if [2,4,5,7,9].include?(n)
print "hon"
elsif n == 3
print "bon"
else
print "pon"
end
|
n=gets.chomp.chars[-1].to_i
if [2,4,5,7,9].include?(n)
print "hon"
elsif n == 3
print "bon"
else
print "pon"
end
| null | 392,716
| 392,717
|
u702482655
|
ruby
|
p02658
|
io = STDIN
N=io.gets.to_i
a=io.gets.split.map(&:to_i)
def calc(a)
lim=10**18
return 0 if a.include?(0)
a.inject(1) do |s,i|
p [s,i]
s=s*i
return -1 if s>lim
s
end
end
puts calc(a)
|
io = STDIN
N=io.gets.to_i
a=io.gets.split.map(&:to_i)
def calc(a)
lim=10**18
return 0 if a.include?(0)
a.inject(1) do |s,i|
s=s*i
return -1 if s>lim
s
end
end
puts calc(a)
| null | 375,551
| 375,552
|
u132360211
|
ruby
|
p02659
|
# ruby 少数 誤差 対応
# 705513400978450 8.28 誤差の出るやつ
# bのパターン 1.10 1.01 1.00 #必ず小数第二位まであるらしい
a,b=gets.split(" ")
a_int=a.to_i
b_int=b[0].to_i*10+b[2].to_i*100+b[3].to_i
print a_int*b_int/100
|
# ruby 少数 誤差 対応
# 705513400978450 8.28 誤差の出るやつ
# bのパターン 1.10 1.01 1.00 #必ず小数第二位まであるらしい
a,b=gets.split(" ")
a_int=a.to_i
b_int=b[0].to_i*100+b[2].to_i*10+b[3].to_i
print a_int*b_int/100
| null | 377,291
| 377,292
|
u103662738
|
ruby
|
p02642
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
count = 0
puts a.slect {|i| arr[i] == 1}.size
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
puts a.select {|o| arr[o] == 1}.size
| null | 363,423
| 363,424
|
u412789323
|
ruby
|
p02642
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
count = 0
puts a.slect{|o| arr[o] == 1}.size
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
puts a.select {|o| arr[o] == 1}.size
| null | 363,425
| 363,424
|
u412789323
|
ruby
|
p02642
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
count = 0
puts a.slect{|o| b[o] == 1}.size
# a.each do |i|
# count += 1 if arr[i] == 1
# end
# puts count
|
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
INF = (10 ** 6)
arr = Array.new(INF+1,0)
a.each do |i|
next if arr[i] == 2
i.step(INF, i) do |j|
arr[j] += 1
end
end
puts a.select {|o| arr[o] == 1}.size
| null | 363,426
| 363,424
|
u412789323
|
ruby
|
p02642
|
N = 10**6
a = (N+1).times.map{0}
gets
gets.split do |s|
a[s.to_i] += 1
end
ans = 0
(2..N).each do |i|
next if a[i] == 0
ans += 1 if a[i]==1
j = i*2
while j <= N
a[j] = 0
j += i
end
end
p ans
|
N = 10**6
a = (N+1).times.map{0}
gets
gets.split do |s|
a[s.to_i] += 1
end
ans = 0
(1..N).each do |i|
next if a[i] == 0
ans += 1 if a[i]==1
j = i*2
while j <= N
a[j] = 0
j += i
end
end
p ans
| null | 363,690
| 363,691
|
u976045235
|
ruby
|
p02642
|
N = 10**6
a = (N+1).times.map 0
gets
gets.split do |s|
a[s.to_i] += 1
end
ans = 0
(2..N).each do |i|
next if a[i] == 0
ans += 1 if a[i]==1
j = i*2
while j <= N
a[j] = 0
j += i
end
end
p ans
|
N = 10**6
a = (N+1).times.map{0}
gets
gets.split do |s|
a[s.to_i] += 1
end
ans = 0
(1..N).each do |i|
next if a[i] == 0
ans += 1 if a[i]==1
j = i*2
while j <= N
a[j] = 0
j += i
end
end
p ans
| null | 363,692
| 363,691
|
u976045235
|
ruby
|
p02646
|
a,v = gets.split(' ').map(&:to_i)
b,w = gets.split(' ').map(&:to_i)
t = gets.to_i
#ans = false
dist = (b-a).abs
if v == w
puts 'NO'
elsif v < w
puts 'NO'
else
if dist < (v-w)*t
puts 'YES'
else
puts 'NO'
end
end
|
a,v = gets.split(' ').map(&:to_i)
b,w = gets.split(' ').map(&:to_i)
t = gets.to_i
#ans = false
dist = (b-a).abs
if v == w
puts 'NO'
elsif v < w
puts 'NO'
else
if dist <= (v-w)*t
puts 'YES'
else
puts 'NO'
end
end
| null | 366,767
| 366,768
|
u932417742
|
ruby
|
p02646
|
a = gets.split(' ')
a_zahyou = a[0].to_i
a_kyori = a[1].to_i
b = gets.split(' ')
b_zahyou = b[0].to_i
b_kyori = b[1].to_i
time = gets.to_i
a_plus = a_zahyou + a_kyori * time
a_minus = a_zahyou - a_kyori * time
b_plus = b_zahyou + b_kyori * time
b_minus = b_zahyou - b_kyori * time
if a_plus >= b_plus || a_minus <= b_minus
puts 'YES'
else
puts 'NO'
end
|
a = gets.split(' ')
a_zahyou = a[0].to_i
a_kyori = a[1].to_i
b = gets.split(' ')
b_zahyou = b[0].to_i
b_kyori = b[1].to_i
time = gets.to_i
a_plus = a_zahyou + a_kyori * time
a_minus = a_zahyou - a_kyori * time
b_plus = b_zahyou + b_kyori * time
b_minus = b_zahyou - b_kyori * time
if a_plus >= b_plus && a_minus <= b_minus
puts 'YES'
else
puts 'NO'
end
| null | 366,797
| 366,798
|
u341534571
|
ruby
|
p02646
|
A,V = gets.split(" ").map(&:to_i)
B,W = gets.split(" ").map(&:to_i)
T = gets.to_i
dis = (B - A).abs
sp = V - W
if dis - sp * T > 0
puts "No"
else
puts "Yes"
end
|
A,V = gets.split(" ").map(&:to_i)
B,W = gets.split(" ").map(&:to_i)
T = gets.to_i
dis = (B - A).abs
sp = V - W
if dis - sp * T > 0
puts "NO"
else
puts "YES"
end
| null | 367,832
| 367,833
|
u039504682
|
ruby
|
p02676
|
attrs = Array.new
while line = $stdin.gets
attrs << line.chomp.split
end
K = attrs[0][0].to_i
S = attrs[1][0]
if S.length <= K then
puts S
else
puts "#{S[0, 7]}..."
end
|
attrs = Array.new
while line = $stdin.gets
attrs << line.chomp.split
end
K = attrs[0][0].to_i
S = attrs[1][0]
if S.length <= K then
puts S
else
puts "#{S[0, K]}..."
end
| null | 396,667
| 396,668
|
u244257825
|
ruby
|
p02682
|
a, b, c, k = gets.split.map(&:to_i)
if a >= k
puts a
elsif a + b >= k
puts a
else
ans = a
minus = k - a - b
ans -= minus
puts ans
end
|
a, b, c, k = gets.split.map(&:to_i)
if a >= k
puts k
elsif a + b >= k
puts a
else
ans = a
minus = k - a - b
ans -= minus
puts ans
end
| null | 408,772
| 408,773
|
u653737129
|
ruby
|
p02705
|
r = gets.chomp!.to_i
puts r * r * 3.14159265358979
|
r = gets.chomp!.to_i
puts 2 * r * 3.14159265358979
| null | 458,178
| 458,179
|
u081708706
|
ruby
|
p02687
|
s = gets.to_s
if s == 'ABC'
puts 'ARC'
elsif s == 'ARC'
puts 'ABC'
else
puts 'Error'
end
|
s = gets.chomp
if s == 'ABC'
puts 'ARC'
elsif s == 'ARC'
puts 'ABC'
else
puts 'Error'
end
| null | 419,282
| 419,283
|
u753851577
|
ruby
|
p02687
|
s = gets.chomp
puts "ABC" if s = "ARC"
puts "ARC" if s = "ABC"
|
s = gets.chomp
puts "ABC" if s == "ARC"
puts "ARC" if s == "ABC"
| null | 419,716
| 419,717
|
u979552932
|
ruby
|
p02693
|
K = gets.to_i
A,B = gets.split.map(&:to_i)
puts ((A - 1) / K) < (B / K) ? 'YES' : 'NO'
|
K = gets.to_i
A,B = gets.split.map(&:to_i)
puts ((A - 1) / K) < (B / K) ? 'OK' : 'NG'
| null | 436,297
| 436,298
|
u627981707
|
ruby
|
p02718
|
n, m = gets.split.map(&:to_i)
numbers = gets.split.map(&:to_i)
t = numbers.inject(&:+) / 4.0 * m
c = numbers.select { |n| n >= t }.count
if c >= m
print "Yes"
else
print "No"
end
|
n, m = gets.split.map(&:to_i)
numbers = gets.split.map(&:to_i)
t = numbers.inject(&:+) / (4.0 * m)
c = numbers.select { |n| n >= t }.count
if c >= m
print "Yes"
else
print "No"
end
| null | 486,172
| 486,173
|
u771131483
|
ruby
|
p02718
|
n,m=gets.split.map(&:to_i)
arr=gets.split.map(&:to_i).sort.reverse
sum=arr.inject(:+)
puts arr[0..m-1].each.all?{|a|a>=sum/(4*m)} ? 'Yes' : 'No'
|
n,m=gets.split.map(&:to_f)
arr=gets.split.map(&:to_f).sort.reverse
sum=arr.inject(:+)
puts arr[0..m-1].each.all?{|a|a>=sum/(4*m)} ? 'Yes' : 'No'
| null | 490,077
| 490,078
|
u124214522
|
ruby
|
p02722
|
f=->m{(1..Math.sqrt(m)).flat_map{|i|m%i<1?[i,m/i]:[]}-[1]}
p f[N=gets.to_i].count{|x|m=N;m/=x while m%x<1;m%x<2}+f[N-1].size
|
f=->m{(1..Math.sqrt(m)).flat_map{|i|m%i<1?[i,m/i]:[]}-[1]|[]}
p f[N=gets.to_i].count{|x|m=N;m/=x while m%x<1;m%x<2}+f[N-1].size
| null | 494,694
| 494,695
|
u049095189
|
ruby
|
p02754
|
n, a, b = gets.chomp.split().map(&:to_i)
quotient = n % (a + b) * a
amari = n % (a + b)
if amari >= a
quotient += a
else
quotient += amari
end
puts quotient
|
n, a, b = gets.chomp.split().map(&:to_i)
quotient = n / (a + b) * a
amari = n % (a + b)
if amari >= a
quotient += a
else
quotient += amari
end
puts quotient
| null | 532,256
| 532,257
|
u641383521
|
ruby
|
p02765
|
line = gets.split(' ').map(&:to_i)
N = line[0]
R = line[1]
if N < 10 then
print R + 100 * (10 - K)
else
print R
end
|
line = gets.split(' ').map(&:to_i)
N = line[0]
R = line[1]
if N < 10 then
print R + 100 * (10 - N)
else
print R
end
| null | 556,042
| 556,043
|
u569559028
|
ruby
|
p02767
|
#!/usr/bin/env ruby
# 156-c
n = gets().to_i
x = gets().chomp.split(" ").map(&:to_i)
a = 0
(x.min..(x.max+1)).each {|i|
c = 0
x.each {|j|
c = c + (i-j)*(i-j)
}
if a == 0 then
a = c
elsif a > c then
a = c
end
}
puts a
|
#!/usr/bin/env ruby
# 156-c
n = gets().to_i
x = gets().chomp.split(" ").map(&:to_i)
a = 0
(x.min..x.max).each {|i|
c = 0
x.each {|j|
c = c + (i-j)*(i-j)
}
if a == 0 then
a = c
elsif a > c then
a = c
end
}
puts a
| null | 562,494
| 562,495
|
u745802292
|
ruby
|
p02771
|
a = gets.split.map(&:to_i)
puts a.uniq.length
puts a.uniq.length == 2 ? "Yes" : "No"
|
a = gets.split.map(&:to_i)
puts a.uniq.length == 2 ? "Yes" : "No"
| null | 566,420
| 566,421
|
u514143079
|
ruby
|
p02771
|
arr = gets.strip.split(' ').map(&:to_i)
result = (arr[0] == arr[1] && arr[0] != arr[2]) ||
(arr[1] == arr[2] && arr[1] != arr[0]) ||
(arr[2] == arr[0] && arr[2] != arr[1]) ||
msg = 'No'
msg = 'Yes' if result
puts msg
|
arr = gets.strip.split(' ').map(&:to_i)
result = (arr[0] == arr[1] && arr[0] != arr[2]) ||
(arr[1] == arr[2] && arr[1] != arr[0]) ||
(arr[2] == arr[0] && arr[2] != arr[1])
msg = 'No'
msg = 'Yes' if result
puts msg
| null | 567,177
| 567,178
|
u259578064
|
ruby
|
p02772
|
N = gets.to_i
A = gets.chomp.split.map(&:to_i)
ans = false
A.each do |i|
if i.odd? # 奇数か?
if !(i % 3 == 0 && i % 5 == 0)
ans = true
end
end
end
puts ans ? "APPROVED" : "DENIED"
|
N = gets.to_i
A = gets.chomp.split.map(&:to_i)
ans = true
A.each do |i|
if i.even? # 偶数か?
if !(i % 3 == 0 || i % 5 == 0)
ans = false
end
end
end
puts ans ? "APPROVED" : "DENIED"
| null | 568,491
| 568,492
|
u552761221
|
ruby
|
p02779
|
N = gets.to_i
ary = gets.chomp.split(" ")
aryuniq = ary.uniq
if ary == aryuniq
puts "Yes"
else
puts "No"
end
|
N = gets.to_i
ary = gets.chomp.split(" ")
aryuniq = ary.uniq
if ary == aryuniq
puts "YES"
else
puts "NO"
end
| null | 577,267
| 577,268
|
u729911058
|
ruby
|
p02779
|
N = gets.to_i
A = gets.split.map(&:to_i)
puts A.uniq.size == N ? "Yes" : "No"
|
N = gets.to_i
A = gets.split.map(&:to_i)
puts A.uniq.size == N ? "YES" : "NO"
| null | 578,378
| 578,379
|
u199924561
|
ruby
|
p02801
|
alphabet = (a..z).to_a
puts alphabet[alphabet.index(gets.chomp) + 1]
|
alphabet = ("a".."z").to_a
puts alphabet[alphabet.index(gets.chomp) + 1]
| null | 604,988
| 604,989
|
u199924561
|
ruby
|
p02811
|
K,X = gets.chomp.split(" ").map(&:to_i)
if K * 500 > X
print "Yes"
else
print "No"
end
|
K,X = gets.chomp.split(" ").map(&:to_i)
if K * 500 >= X
print "Yes"
else
print "No"
end
| null | 610,999
| 611,000
|
u886100669
|
ruby
|
p02812
|
N=gets.to_i
S=gets
puts S.count("ABC")
|
N=gets.to_i
S=gets
puts S.scan("ABC").length
| null | 616,137
| 616,138
|
u041282550
|
ruby
|
p02813
|
n=gets.to_i
s1=gets.split.map(&:to_i)
s2=gets.split.map(&:to_i)
a,b=0,0
[*1..n].permutation.to_a.each_with_index do |p,i|
a=i if p==s1
b=i if p==s2
end
p b-a
|
n=gets.to_i
s1=gets.split.map(&:to_i)
s2=gets.split.map(&:to_i)
a,b=0,0
[*1..n].permutation.to_a.each_with_index do |p,i|
a=i if p==s1
b=i if p==s2
end
p (b-a).abs
| null | 615,423
| 615,424
|
u966810027
|
ruby
|
p02755
|
a,b=gets.split.map(&:to_i)
1.upto(100) do |i|
if i*8/100==a && i*10/100==b
puts i
exit
end
end
puts "-1"
|
a,b=gets.split.map(&:to_i)
1.upto(80000) do |i|
if i*8/100==a && i*10/100==b
puts i
exit
end
end
puts "-1"
| null | 541,395
| 541,396
|
u744908753
|
ruby
|
p02756
|
# frozen_string_literal: false
s = gets.chomp
q = gets.to_i
queries = q.times.map { gets.split }
f1s = ''
f2s = s
reversed = false
queries.each do |t, f, c|
if t.to_i == 1
reversed = !reversed
next
end
if f.to_i == 1
if !reversed
f1s << c
else
f2s << c
end
elsif f.to_i == 2
if !reversed
f2s << c
else
f1s << c
end
end
end
if reversed
puts f2s << f1s
else
puts f1s.reverse! << f2s
end
|
# frozen_string_literal: false
s = gets.chomp
q = gets.to_i
queries = q.times.map { gets.split }
f1s = ''
f2s = s
reversed = false
queries.each do |t, f, c|
if t.to_i == 1
reversed = !reversed
next
end
if f.to_i == 1
if !reversed
f1s << c
else
f2s << c
end
elsif f.to_i == 2
if !reversed
f2s << c
else
f1s << c
end
end
end
if reversed
puts f2s.reverse! << f1s
else
puts f1s.reverse! << f2s
end
| null | 542,226
| 542,227
|
u889326464
|
ruby
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.