Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p02761
# frozen_string_literal: true n, m = gets.split.map(&:to_i) sc = m.times.map { gets.split.map(&:to_i) } l = 0 r = 9 if n == 2 l = 10 r = 99 else l = 100 r = 999 end l.upto(r) do |x| flag = true sc.each do |e| s = e[0] c = e[1].to_s xx = x.to_s if xx[s - 1] != c flag = false break end end if flag puts x exit end end puts '-1'
# frozen_string_literal: true n, m = gets.split.map(&:to_i) sc = m.times.map { gets.split.map(&:to_i) } l = 0 r = 9 if n == 2 l = 10 r = 99 elsif n == 3 l = 100 r = 999 end l.upto(r) do |x| flag = true sc.each do |e| s = e[0] c = e[1].to_s xx = x.to_s if xx[s - 1] != c flag = false break end end if flag puts x exit end end puts '-1'
null
552,574
552,575
u434509016
ruby
p02830
a = gets.to_i b, c = gets.split d = [] a.each do |i| d << b[i] d << c[i] end puts d.join
a = gets.to_i b, c = gets.split d = [] a.times do |i| d << b[i] d << c[i] end puts d.join
null
630,548
630,549
u684458716
ruby
p02830
N = gets.to_i S = gets T = gets N.times do |i| putc S[i] putc T[i] end
N = gets.to_i S ,T = gets.split N.times do |i| putc S[i] putc T[i] end
null
630,563
630,564
u803684095
ruby
p02830
n = gets.to_i s, t = gets.chomp.split.map(&:to_s) ans = "" n.times do |i| ans << s[i] ans << t[i] end p ans
n = gets.to_i s, t = gets.chomp.split.map(&:to_s) ans = "" n.times do |i| ans << s[i] ans << t[i] end puts ans
null
631,241
631,242
u610761300
ruby
p02835
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] 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 a = inp puts (sum(s) <= 21)? "win" : "bust"
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] 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 a = inp puts (sum(a) <= 21)? "win" : "bust"
null
638,045
638,046
u145123922
ruby
p02933
a = gets.to_i s = gets.chomp p a >= 3200 ? s : 'red'
a = gets.to_i s = gets.chomp print a >= 3200 ? s : 'red'
null
735,021
735,022
u631543593
ruby
p02860
n = gets.to_i s = gets if s.slice(0,n/2) == s.slice(n/2..n) puts "Yes" else puts "No" end
n = gets.to_i s = gets if s.slice(0..n/2-1) == s.slice(n/2..n-1) puts "Yes" else puts "No" end
null
663,415
663,416
u469030089
ruby
p02860
N = gets.to_i S = gets.to_s if N % 2 != 0 puts "No" else tn = N / 2 t = S.slice(0, tn) s = t + t if s.eql?(S) puts "Yes" else puts "No" end end
N = gets.to_i S = gets.to_s.chomp if N % 2 != 0 puts "No" else tn = N / 2 t = S.slice(0, tn) s = t << t if s.eql?(S) puts "Yes" else puts "No" end end
null
664,928
664,929
u532764966
ruby
p02865
n = gets.chomp.to_i if(n % 2 == 0) print(n / 2 - 1) elsif(n % 2 == 1) print(n - 1) / 2 end
n = gets.chomp.to_i if(n % 2 == 0) print(n / 2 - 1) elsif(n % 2 == 1) print((n - 1) / 2) end
null
668,324
668,325
u953495504
ruby
p02873
def sums(n) return n*(n+1)/2 end s = gets.chomp.split("") cmps = Array.new(0) mark = Array.new(0) cnt = 1 pre = s[0] for i in 1..(s.length-1) if s[i] == pre cnt += 1 else cmps.push(cnt) mark.push(pre) cnt = 1 end pre = s[i] end cmps.push(cnt) mark.push(pre) ans = 0 if mark[0] == ">" ans += sums(cmps[0]) end for i in 0..(cmps.length-2) if mark[i] == "<" ans += [cmps[i],cmps[i+1]].max end end if mark[cmps.length-1] == "<" ans += sums(cmps[cmps.length-1]) end for i in 0..(cmps.length-1) ans += sums(cmps[i]-1) end puts ans
def sums(n) return n*(n+1)/2 end s = gets.chomp.split("") cmps = Array.new(0) mark = Array.new(0) cnt = 1 pre = s[0] for i in 1..(s.length-1) if s[i] == pre cnt += 1 else cmps.push(cnt) mark.push(pre) cnt = 1 end pre = s[i] end cmps.push(cnt) mark.push(pre) ans = 0 if mark[0] == ">" ans += cmps[0] end for i in 0..(cmps.length-2) if mark[i] == "<" ans += [cmps[i],cmps[i+1]].max end end if mark[cmps.length-1] == "<" ans += cmps[cmps.length-1] end for i in 0..(cmps.length-1) ans += sums(cmps[i]-1) end puts ans
null
671,957
671,958
u326891688
ruby
p02901
n, m = gets.to_s.split.map{|i| i.to_i } bits = Array.new(n){|i| 2**i } # p bits = Array.new(12){|i| 2**i } #=> [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] shops = Array.new(m) do a = gets.to_s.to_i c = gets.to_s.split.map{|i| i.to_i - 1 } bit = c.reduce(0){|s,t|bits[t]} [bit, a] end.sort_by{|(bit, _)| bit } inf = 10 ** 12 state_size = 2 ** n d = Array.new(state_size, inf) d[0] = 0 state_max = 0 shops.each do |(bit, a)| state_max |= bit state_max.times do |k| new = k | bit d[new] = d[k] + a if d[new] > d[k] + a end end puts d[-1] == inf ? -1 : d[-1]
n, m = gets.to_s.split.map{|i| i.to_i } bits = Array.new(n){|i| 2**i } # p bits = Array.new(12){|i| 2**i } #=> [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048] shops = Array.new(m) do a = gets.to_s.to_i c = gets.to_s.split.map{|i| i.to_i - 1 } [c.reduce(0){|s,t| s + bits[t] }, a] end.sort_by{|(bit, _)| bit } inf = 10 ** 12 state_size = 2 ** n d = Array.new(state_size, inf) d[0] = 0 state_max = 0 shops.each do |(bit, a)| state_max |= bit state_max.times do |k| new = k | bit d[new] = d[k] + a if d[new] > d[k] + a end end puts d[-1] == inf ? -1 : d[-1]
null
700,886
700,887
u693378622
ruby
p02952
(1..gets.to_i).to_a.map(&:to_s).map(&:size).select(&:odd?).size
p (1..gets.to_i).to_a.map(&:to_s).map(&:size).select(&:odd?).size
null
754,528
754,529
u315597999
ruby
p02952
n = gets.to_i kotae = 0 (1..n+1).each do |i| kotae += 1 if i.to_s.length % 2 == 1 end puts kotae
n = gets.to_i kotae = 0 (1..n).each do |i| kotae += 1 if i.to_s.length % 2 == 1 end puts kotae
null
755,025
755,026
u635412457
ruby
p02970
_=$<.read.split.map(&:to_i) p (_[0]/(2.0*_[1])).ceil
_=$<.read.split.map(&:to_i) p (_[0]/(2.0*_[1]+1)).ceil
null
773,840
773,841
u264508862
ruby
p02954
#E A, B, C = gets.chomp.split.map(&:to_i) S = gets.chomp.chars n = S.size res = Array.new(n, 0) # Set cnts from R cnt = 0 # count of R 0.upto(n-1).each do |i| if S[i] == 'R' cnt += 1 next end # L is Found. index is i res[i] += cnt / 2 # RRRL -> 1 (3/2) res[i-1] += (cnt + 1) / 2 # RRRL -> 2 ((3+1)/2) cnt = 0 end # Set cnts from L cnt = 0 # count of L (n-1).downto(0).each do |i| if S[i] == 'L' cnt += 1 next end # R is found. index is i res[i] += cnt / 2 # RLLL -> 1 (3/2) res[i+1] += (cnt + 1) / 2 # RLLL -> 2 ((3+1)/2) cnt = 0 end p res.join(" ")
#E A, B, C = gets.chomp.split.map(&:to_i) S = gets.chomp.chars n = S.size res = Array.new(n, 0) # Set cnts from R cnt = 0 # count of R 0.upto(n-1).each do |i| if S[i] == 'R' cnt += 1 next end # L is Found. index is i res[i] += cnt / 2 # RRRL -> 1 (3/2) res[i-1] += (cnt + 1) / 2 # RRRL -> 2 ((3+1)/2) cnt = 0 end # Set cnts from L cnt = 0 # count of L (n-1).downto(0).each do |i| if S[i] == 'L' cnt += 1 next end # R is found. index is i res[i] += cnt / 2 # RLLL -> 1 (3/2) res[i+1] += (cnt + 1) / 2 # RLLL -> 2 ((3+1)/2) cnt = 0 end print res.join(" ")
null
758,637
758,638
u328294851
ruby
p02971
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] 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 r_sort(a) a.sort{|a,b|b<=>a} end n =gets t = ARGF.map(&:to_i) max = t.max m_i = t.index(max) t.delete_at(m_i) max2 = t.max n.timest.each do |i| puts (i==m_i)? max2:max end
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE'] 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 r_sort(a) a.sort{|a,b|b<=>a} end n =gets.to_i t = ARGF.map(&:to_i) max = t.max m_i = t.index(max) t.delete_at(m_i) max2 = t.max n.times.each do |i| puts (i==m_i)? max2:max end
null
775,762
775,763
u145123922
ruby
p02982
n,d = gets.split.map(&:to_i) s = n.times.map{gets.split.map(&:to_i)} cnt = 0 s.combination(2) do |a,b| r2 = a.zip(b).map{|x,y| (x-y)**2 }.inject(:+) cnt +=1 if Math.sqrt(r2)**2 == r2 end p cnt
n,d = gets.split.map(&:to_i) s = n.times.map{gets.split.map(&:to_i)} cnt = 0 s.combination(2) do |a,b| r2 = a.zip(b).map{|x,y| (x-y)**2 }.inject(:+) cnt +=1 if Math.sqrt(r2).to_i**2 == r2 end p cnt
null
786,544
786,545
u562082015
ruby
p02958
n = gets.to_i array_p = gets.split(" ").map!{|i | i.to_i} swap = 0 array_p.each_with_index do |num, index| unless num == (index + 1) swap = swap + 1 end end (swap == 0 || swap == 2) ? result = "YES" : result = "NO" p result
n = gets.to_i array_p = gets.split(" ").map!{|i | i.to_i} swap = 0 array_p.each_with_index do |num, index| unless num == (index + 1) swap = swap + 1 end end (swap == 0 || swap == 2) ? result = "YES" : result = "NO" puts result
null
765,037
765,038
u176517109
ruby
p02960
S = '?'*100000#gets.chomp ks, l = [12,3,4,1,10,9], [] ks.each{|k| l[k] = a = Array.new(13){ [] } js = [*0..12] 9.times{ js.rotate! k js.each_with_index{|j,i| a[i] << j } } } ks = ks.cycle m = [1]+[0]*12 S.each_char.reverse_each.with_index{|c,i| k = ks.next if c != ?? m.rotate! (c.ord-?0.ord)*k else m = l[k].map.with_index{|a,i| m.values_at(*a).inject(m[i],:+) % 1000000007 } end } p m[5]
S = gets.chomp ks, l = [12,3,4,1,10,9], [] ks.each{|k| l[k] = a = Array.new(13){ [] } js = [*0..12] 9.times{ js.rotate! k js.each_with_index{|j,i| a[i] << j } } } ks = ks.cycle m = [1]+[0]*12 S.each_char.reverse_each.with_index{|c,i| k = ks.next if c != ?? m.rotate! (c.ord-?0.ord)*k else m = l[k].map.with_index{|a,i| m.values_at(*a).inject(m[i],:+) % 1000000007 } end } p m[5]
null
770,209
770,210
u977697682
ruby
p03035
a,b = gets.split(" ").map(&:to_i) if a >= 13 puts b elsif 12 >= a ; a >= 6 puts b/2 else puts 0 end
a,b = gets.split(" ").map(&:to_i) if a >= 13 puts b elsif 12 >= a and a >= 6 puts b/2 else puts 0 end
null
846,123
846,124
u944733909
ruby
p03041
n, k = gets.split.map(&:to_i) s = gets.chomp.split("") s[k] = s[k].downcase puts s.join("")
n, k = gets.split.map(&:to_i) s = gets.chomp.split("") s[k-1] = s[k-1].downcase puts s.join("")
null
856,260
856,261
u757568397
ruby
p03001
w, h, x, y = gets.chomp.split(' ').map(&:to_i) if x == w && y == h print("#{ (w * h)/2.to_f } 1") else print("#{ (w * h)/2.to_f } 0") end
w, h, x, y = gets.chomp.split(' ').map(&:to_i) if x * 2 == w && y * 2 == h print("#{ (w * h)/2.to_f } 1") else print("#{ (w * h)/2.to_f } 0") end
null
816,079
816,080
u429775245
ruby
p02987
a = gets.chomp.split("") puts (a.group_by{|c|c}.all?{|a|a.length==2})? "Yes" : "No"
a = gets.chomp.split("") puts (a.group_by{|c|c}.all?{|_c,a|a.length==2})? "Yes" : "No"
null
795,968
795,969
u731646494
ruby
p02987
s = gets.chomp.split('') first = s[0] if s.count(first) == 2 s.delete(first) if s.count(s[0]) == 2 puts 'Yes' end else puts 'No' end
s = gets.chomp.split('') first = s[0] if s.count(first) == 2 s.delete(first) if s.count(s[0]) == 2 puts 'Yes' else puts 'No' end else puts 'No' end
null
795,336
795,337
u262994359
ruby
p02994
n,l = gets.strip.split.map(&:to_i) ary = Array.new(n,0) for i in 1..n ary[i] = (l-1+i).abs end puts (n-1)*(l-1)+n*(n+1)/2-(ary.index(ary.min))-1
n,l = gets.strip.split.map(&:to_i) ary = Array.new(n,0) for i in 1..n ary[i-1] = (l-1+i).abs end puts (n-1)*(l-1)+n*(n+1)/2-(ary.index(ary.min))-1
null
802,387
802,388
u313103408
ruby
p02995
a,b,c,d=gets.split.map &:to_i a_c = a/c a_d = a/d a_cd = a/(c.lcm(d)) b_c = b/c b_d = b/d b_cd = b/(c.lcm(d)) sum = (b_c + b_d - b_cd) - (a_c + a_d - a_cd) sum += 1 if a % c == 0 sum += 1 if a % d == 0 sums = b-a+1 puts sums-sum
a,b,c,d=gets.split.map &:to_i a_c = a/c a_d = a/d a_cd = a/(c.lcm(d)) b_c = b/c b_d = b/d b_cd = b/(c.lcm(d)) sum = (b_c + b_d - b_cd) - (a_c + a_d - a_cd) sum += 1 if a % c == 0 || a % d == 0 sums = b-a+1 puts sums-sum
null
806,194
806,193
u634482428
ruby
p03126
n,m=gets.chomp.split(" ").map{|s| s.to_i} ans=(1..m).to_a p ans for i in 0..n-1 a=gets.chomp.split(" ").map{|s| s.to_i} a.shift ans=ans&a end p ans.size
n,m=gets.chomp.split(" ").map{|s| s.to_i} ans=(1..m).to_a for i in 0..n-1 a=gets.chomp.split(" ").map{|s| s.to_i} a.shift ans=ans&a end p ans.size
null
927,564
927,565
u087165202
ruby
p03126
line = gets.split(' ') N = line[0].to_i M = line[1].to_i array = Array.new(40, 0) for i in 1..N do line = gets.split(' ') k = line[0].to_i puts k for j in 1..k do array[line[j].to_i] += 1 end end ret = 0 for i in 1..M do if array[i] == N then ret += 1 end end puts ret
line = gets.split(' ') N = line[0].to_i M = line[1].to_i array = Array.new(40, 0) for i in 1..N do line = gets.split(' ') k = line[0].to_i for j in 1..k do array[line[j].to_i] += 1 end end ret = 0 for i in 1..M do if array[i] == N then ret += 1 end end puts ret
null
927,595
927,596
u370768058
ruby
p03126
n, m = gets.split(" ").map(&:to_i) res = [] n.times do |i| a = gets.split(" ").map(&:to_i) a.shift p a if i == 0 res = a else res &= a end end puts res.count
n, m = gets.split(" ").map(&:to_i) res = [] n.times do |i| a = gets.split(" ").map(&:to_i) a.shift if i == 0 res = a else res &= a end end puts res.count
null
928,023
928,024
u895795263
ruby
p03089
_=gets() a=gets.split.map(&:to_i) def rec(x) if x.size ==0 return true end (0...x.size).to_a.reverse.each{|i| if x[i] <(i+1) return false end if x[i]==(i+1) r=rec(x.values_at(0...i,(i+1)...x.size)) if r p (i+1) return true end end } return false end r=rec(a) p -1 if !r
_=gets() a=gets.split.map(&:to_i) def rec(x) if x.size ==0 return true end (0...x.size).to_a.reverse.each{|i| if x[i] >(i+1) return false end if x[i]==(i+1) r=rec(x.values_at(0...i,(i+1)...x.size)) if r p (i+1) return true end end } return false end r=rec(a) p -1 if !r
null
904,384
904,385
u702482655
ruby
p03103
n, m = gets.split.map(&:to_i) shop = [] ans = 0 n.times do shop << gets.split.map(&:to_i) end shop.sort! while m > 0 if m >= shop[0][1] ans += shop[0][0] * shop[0][1] m -= shop[0][1] shop.shift else ans += shop[0][0] * m puts ans exit end end
n, m = gets.split.map(&:to_i) shop = [] ans = 0 n.times do shop << gets.split.map(&:to_i) end shop.sort! while m > 0 if m >= shop[0][1] ans += shop[0][0] * shop[0][1] m -= shop[0][1] shop.shift else ans += shop[0][0] * m break end end puts ans
null
911,315
911,316
u785521224
ruby
p03149
array = gets.chomp.split(' ').map(&:to_i) a,b,c,d = false,false,false,false array.each do |i| if i == 1 a = true end if i == 9 b = true end if i == 7 c == true end if i == 4 d ==true end end if a && b && c && d return "YES" else return "NO" end
array = gets.chomp.split(' ').map(&:to_i) a,b,c,d = false,false,false,false array.each do |i| if i == 1 a = true end if i == 9 b = true end if i == 7 c =true end if i == 4 d =true end end if a && b && c && d puts "YES" else puts "NO" end
null
947,280
947,281
u925626028
ruby
p03212
n = gets.to_i ans = 0 i = 3 while i < 10 [3,5,7].repeated_permutation(i).each do |perm| if perm.uniq.size == 3 && perm.join.to_i < n ans += 1 end end i += 1 end puts ans
n = gets.to_i ans = 0 i = 3 while i < 10 [3,5,7].repeated_permutation(i).each do |perm| if perm.uniq.size == 3 && perm.join.to_i <= n ans += 1 end end i += 1 end puts ans
null
1,007,396
1,007,397
u059126963
ruby
p03214
N = gets.to_i A = gets.split(' ').map(&:to_i) average = A.inject(0){|s, a| s + a } / N diff_list = A.map{|a| { value: a, diff: (a-average).abs}}.sort_by{|a| a[:diff] } warn diff_list targets = diff_list.find_all{|a| a[:diff] == diff_list[0][:diff ]}.map{|a| a[:value]} warn targets puts A.find_index{|a| targets.include?(a)}
N = gets.to_i A = gets.split(' ').map(&:to_i) average = A.inject(0){|s, a| s + a }.to_f / N diff_list = A.map{|a| { value: a, diff: (a-average).abs}}.sort_by{|a| a[:diff] } warn diff_list targets = diff_list.find_all{|a| a[:diff] == diff_list[0][:diff ]}.map{|a| a[:value]} warn targets puts A.find_index{|a| targets.include?(a)}
null
1,009,488
1,009,489
u299761130
ruby
p03220
num = gets.to_i t,a = gets.split.map(&:to_f) talls = gets.split.map(&:to_f) ave_temp = talls.map{|n| t - n * 0.006} diff = ave_temp.map{|i| (a.abs - i.abs).abs} puts diff.index(diff.min) + 1
num = gets.to_i t,a = gets.split.map(&:to_f) talls = gets.split.map(&:to_f) ave_temp = talls.map{|n| t - n * 0.006} diff = ave_temp.map{|i| (a - i).abs} puts diff.index(diff.min) + 1
null
1,015,122
1,015,123
u296101474
ruby
p03208
require "bigdecimal" require "bigdecimal/util" def gi() gets.to_i end def gs() gets.chomp end def gmi() gets.split.map(&:to_i) end def gms() gets.split.map(&:chomp) end def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end def comb(n,k) return nil if k > n result = 1 1.upto() do |d| result *= n result /= d n -= 1 end result end def perm(n,k) return nil if k > n result = 1 k.times do result *= n n -= 1 end result end def kaibun(str) str == str.reverse end ##### n,k = gmi trees = [] n.times do trees.push(gi) end trees.sort! print trees min = 1000000000 (n-k+1).times do |i| #puts i #puts trees[i+k-1] - trees[i] min = [min,trees[i+k-1] - trees[i]].min end puts min
require "bigdecimal" require "bigdecimal/util" def gi() gets.to_i end def gs() gets.chomp end def gmi() gets.split.map(&:to_i) end def gms() gets.split.map(&:chomp) end def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end def comb(n,k) return nil if k > n result = 1 1.upto() do |d| result *= n result /= d n -= 1 end result end def perm(n,k) return nil if k > n result = 1 k.times do result *= n n -= 1 end result end def kaibun(str) str == str.reverse end ##### n,k = gmi trees = [] n.times do trees.push(gi) end trees.sort! #print trees min = 1000000000 (n-k+1).times do |i| #puts i #puts trees[i+k-1] - trees[i] min = [min,trees[i+k-1] - trees[i]].min end puts min
null
1,000,104
1,000,105
u105001881
ruby
p03244
class Counter < Hash def initialize(a=[]) super self.default=0 a.each{|e|self[e]+=1} end def most_common(n=nil) a=self.sort_by{|k,v|v}.reverse a=a[0,n] if n a end def self.[](*a) new(a) end end def Counter(a=[]) Counter.new(a) end n,*v=`dd`.split.map &:to_i v=v.each_slice(2).to_a a,b=v.shift.zip(*v).map(&:compact).map{|e|Counter[e].most_common<<[0,0]} if a[0][0] != b[0][0] p n - (a[0][1] + b[0][1]) else p [n-(a[1][1]+b[0][1]), n-(a[0][1]+b[1][1])].min end
class Counter < Hash def initialize(a=[]) super self.default=0 a.each{|e|self[e]+=1} end def most_common(n=nil) a=self.sort_by{|k,v|v}.reverse a=a[0,n] if n a end def self.[](*a) new(a) end end def Counter(a=[]) Counter.new(a) end n,*v=`dd`.split.map &:to_i v=v.each_slice(2).to_a a,b=v.shift.zip(*v).map(&:compact).map{|e|Counter(e).most_common<<[0,0]} if a[0][0] != b[0][0] p n - (a[0][1] + b[0][1]) else p [n-(a[1][1]+b[0][1]), n-(a[0][1]+b[1][1])].min end
null
1,034,860
1,034,861
u280667879
ruby
p03250
a, b, c = gets.chomp.split.map(&:to_i) puts [a * 10 + b + c, 1 + b * 10 + c, a + b + c * 10].max
a, b, c = gets.chomp.split.map(&:to_i) puts [a * 10 + b + c, a + b * 10 + c, a + b + c * 10].max
null
1,037,424
1,037,425
u527280956
ruby
p03282
s = gets.chomp k = gets.to_i puts s[0...k].match(/1{#{[k, s.length].min}}/) ? s[0] : s[k-1]
s = gets.chomp k = gets.to_i puts s[0...k] =~ /1{#{[k, s.length].min}}/ ? "1" : s.match(/[^1]/)
null
1,065,840
1,065,841
u358554431
ruby
p03289
s=gets.chomp.chars dame=0 dame=1 if s[0]!="A" || s[1]=="C" || s[-1]=="C" c=0 for i in 2...s.size dame=1 if s[i]=="A" c+=1 if s[i]=="C" end dame=1 if c>1 || c=0 for i in 1...s.size next if s[i]=="A" || s[i]=="C" dame=1 if s[i]!=s[i].downcase end puts dame==1 ? "WA":"AC"
s=gets.chomp.chars dame=0 dame=1 if s[0]!="A" || s[1]=="C" || s[-1]=="C" c=0 for i in 2...s.size dame=1 if s[i]=="A" c+=1 if s[i]=="C" end dame=1 if c>1 || c==0 for i in 1...s.size next if s[i]=="A" || s[i]=="C" dame=1 if s[i]!=s[i].downcase end puts dame==1 ? "WA":"AC"
null
1,075,144
1,075,145
u977506075
ruby
p03289
a=gets.chomp puts a[0]=="A" && a[2..-1].count("C")==1 && a.delete("A-Z").size == a.size-2 ?"AC": "WA"
a=gets.chomp puts a[0]=="A" && a[2..-2].count("C")==1 && a.delete("A-Z").size == a.size-2 ?"AC": "WA"
null
1,077,776
1,077,777
u510556034
ruby
p03262
n, here = gets.split.map(&:to_i) x = gets.split.map{|i| i.to_i - here } d = x.inject{|a,b| a.gcd(b)} puts d
n, here = gets.split.map(&:to_i) x = gets.split.map{|i| (i.to_i - here).abs } d = x.inject{|a,b| a.gcd(b)} puts d
null
1,051,428
1,051,429
u464713696
ruby
p03262
N, X = gets.split.map(&:to_i) towns = gets.split.map(&:to_i).sort first_point = nil diff_array = [] diff = 123456789 towns.each_with_index{|i, idx| if X > i if diff > (X - i) first_point = i diff = (X - i) end else if diff > (i - X) first_point = i diff = (i - X) end end unless idx == 0 diff_array << (towns[idx]-towns[idx-1]) end } diff_array << diff if diff_array.length == 1 diff_array << diff end diff_array.delete(0) diff_array.sort! def gcd(x, y) if y == 0 return y end if y > x gcd(y, x) end r = x % y if r.zero? return y end gcd(y, r) end result = diff_array.reduce{|memo, item| gcd(memo, item) } puts result
N, X = gets.split.map(&:to_i) towns = gets.split.map(&:to_i).sort first_point = nil diff_array = [] diff = 123456789000 towns.each_with_index{|i, idx| if X > i if diff > (X - i) first_point = i diff = (X - i) end else if diff > (i - X) first_point = i diff = (i - X) end end unless idx == 0 diff_array << (towns[idx]-towns[idx-1]) end } diff_array << diff if diff_array.length == 1 diff_array << diff end diff_array.delete(0) diff_array.sort! def gcd(x, y) if y == 0 return y end if y > x gcd(y, x) end r = x % y if r.zero? return y end gcd(y, r) end result = diff_array.reduce{|memo, item| gcd(memo, item) } puts result
null
1,051,461
1,051,462
u728732647
ruby
p03272
a = STDIN.gets.split(" ").map(:to_i) puts a[0] - a[1] + 1
a = gets.split(" ").map(&:to_i) puts a[0] - a[1] + 1
null
1,056,335
1,056,391
u517379236
ruby
p03272
a = gets.split(" ").map(:to_i) puts a[0] - a[1] + 1
a = gets.split(" ").map(&:to_i) puts a[0] - a[1] + 1
null
1,056,392
1,056,391
u517379236
ruby
p03274
#!/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 N, K = get_ints X = get_ints minus = [] plus = [] zero = nil X.each do |x| if x < 0 minus << -x elsif x > 0 plus << x else zero = true end end k = zero ? K - 1 : K if k == 0 puts 0 else minus.reverse! min = 10 ** 32 plus.each.with_index do |x, i| num = i + 1 break if num >= k if minus.length >= k - num stock = x * 2 + minus[k-num-1] min = stock if stock < min end end if plus.length >= k min = plus[k-1] if plus[k-1] < min end minus.each.with_index do |x, i| num = i + 1 break if num >= k if plus.length >= num stock = x * 2 + plus[k-num-1] min = stock if stock < min end end if minus.length >= k min = minus[k-1] if minus[k-1] < min end puts min end
#!/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 N, K = get_ints X = get_ints minus = [] plus = [] zero = nil X.each do |x| if x < 0 minus << -x elsif x > 0 plus << x else zero = true end end k = zero ? K - 1 : K if k == 0 puts 0 else minus.reverse! min = 10 ** 32 plus.each.with_index do |x, i| num = i + 1 break if num >= k if minus.length >= k - num stock = x * 2 + minus[k-num-1] min = stock if stock < min end end if plus.length >= k min = plus[k-1] if plus[k-1] < min end minus.each.with_index do |x, i| num = i + 1 break if num >= k if plus.length >= k-num stock = x * 2 + plus[k-num-1] min = stock if stock < min end end if minus.length >= k min = minus[k-1] if minus[k-1] < min end puts min end
null
1,057,873
1,057,874
u305883349
ruby
p03274
N, K = gets.chomp.split(" ").map(&:to_i) X = gets.chomp.split(" ").map(&:to_i) Xp = X.select{|x| x >= 0} Xm = X.select{|x| x < 0}.reverse.map{|x| -x} ans = 10 ** 9 ans = Kp[K-1] if Xp.size >= K (1...K).each{|i| next if Xp.size < i next if Xm.size < K - i wk = Xp[i-1] + 2 * Xm[K-i-1] ans = wk if ans > wk } (1...K).each{|i| next if Xm.size < i next if Xp.size < K - i wk = Xm[i-1] + 2 * Xp[K-i-1] ans = wk if ans > wk } ans = Xm[K-1] if Xm.size >= K && ans > Xm[K-1] puts ans
N, K = gets.chomp.split(" ").map(&:to_i) X = gets.chomp.split(" ").map(&:to_i) Xp = X.select{|x| x >= 0} Xm = X.select{|x| x < 0}.reverse.map{|x| -x} ans = 10 ** 9 ans = Xp[K-1] if Xp.size >= K (1...K).each{|i| next if Xp.size < i next if Xm.size < K - i wk = Xp[i-1] + 2 * Xm[K-i-1] ans = wk if ans > wk } (1...K).each{|i| next if Xm.size < i next if Xp.size < K - i wk = Xm[i-1] + 2 * Xp[K-i-1] ans = wk if ans > wk } ans = Xm[K-1] if Xm.size >= K && ans > Xm[K-1] puts ans
null
1,058,187
1,058,188
u276517671
ruby
p03274
n,k = gets.split.map(&:to_i) xs = gets.split.map(&:to_i) ans = Float::INFINITY n.times do |i| tmp = xs[i, k] break if tmp.size < k a = tmp[0] b = tmp[-1] base = (a - b).abs if a < 0 && b > 0 extra = [a.abs, b.abs].min elsif a < 0 && b < 0 extra = b.abs elsif a > 0 extra = a.abs end ans = [ans, base + extra].min end puts ans
n,k = gets.split.map(&:to_i) xs = gets.split.map(&:to_i) ans = Float::INFINITY n.times do |i| tmp = xs[i, k] break if tmp.size < k a = tmp[0] b = tmp[-1] base = (a - b).abs if a < 0 && b > 0 extra = [a.abs, b.abs].min elsif a < 0 && b < 0 extra = b.abs elsif a > 0 extra = a.abs else extra = 0 end ans = [ans, base + extra].min end puts ans
null
1,058,697
1,058,698
u298628832
ruby
p03274
n, k = gets.split.map(&:to_i) xs = gets.split.map(&:to_i) p (0..n-k).map{|l| [xs[l], xs[l+k-1]].min.abs + xs[l+k-1] - xs[l]}.min
n, k = gets.split.map(&:to_i) xs = gets.split.map(&:to_i) p (0..n-k).map{|l| [xs[l].abs, xs[l+k-1].abs].min + xs[l+k-1] - xs[l]}.min
null
1,060,233
1,060,234
u467508794
ruby
p03274
n, k = gets.chomp.split(' ').map(&:to_i) list = gets.chomp.split(' ').map(&:to_i) N_MAX = 100_000 time = N_MAX * 3 0.upto(n - k).each do |i| l = i r = i + k - 1 time_1 = list[l].abs + (list[r] - list[l]).abs time_2 = list[r].abs + (list[r] - list[l]).abs time = [time, time_1, time_2].min end puts time
n, k = gets.chomp.split(' ').map(&:to_i) list = gets.chomp.split(' ').map(&:to_i) N_MAX = 100_000_000 time = N_MAX * 3 0.upto(n - k).each do |i| l = i r = i + k - 1 time_1 = list[l].abs + (list[r] - list[l]).abs time_2 = list[r].abs + (list[r] - list[l]).abs time = [time, time_1, time_2].min end puts time
null
1,060,237
1,060,238
u823451365
ruby
p03293
s=gets.chomp t=gets.chomp s.length.times do if s == t puts 'YES' exit 0 end s = s[1..-1] + s[0] end puts 'NO'
s=gets.chomp t=gets.chomp s.length.times do if s == t puts 'Yes' exit 0 end s = s[1..-1] + s[0] end puts 'No'
null
1,082,198
1,082,199
u852974293
ruby
p03296
n = gets.to_i slimes = gets.split.map{|s|s.to_i} ans = 0 (n-1).times do |i| if slimes[i] == slimes[i+1] aes += 1 slimes[i+1] = -1 end end puts ans
n = gets.to_i slimes = gets.split.map{|s|s.to_i} ans = 0 (n-1).times do |i| if slimes[i] == slimes[i+1] ans += 1 slimes[i+1] = -1 end end puts ans
null
1,084,188
1,084,189
u320576758
ruby
p03433
n = gets.to_i%500 a = gets.to_i puts n < a ? 'Yes':'No'
n = gets.to_i%500 a = gets.to_i puts n <= a ? 'Yes':'No'
null
1,185,761
1,185,762
u397763977
ruby
p03448
a = gets.chomp.to_i b = gets.chomp.to_i c = gets.chomp.to_i x = gets.chomp.to_i num = 0 total = 0 for i in 0..a do for j in 0..b do for k in 0..c do total = 500*a + 100*b + 50*c num+=1 if total == x end end end print num
a = gets.chomp.to_i b = gets.chomp.to_i c = gets.chomp.to_i x = gets.chomp.to_i num = 0 total = 0 for i in 0..a do for j in 0..b do for k in 0..c do total = 500*i + 100*j + 50*k num+=1 if total == x end end end print num
null
1,195,786
1,195,787
u096860578
ruby
p03323
a, b = gets.chomp!.split.map(&to_s) if a <= 8 && b <= 8 puts 'Yay!' else puts ':(' end
a, b = gets.chomp.split.map(&:to_i) if a <= 8 && b <= 8 puts 'Yay!' else puts ':(' end
null
1,099,515
1,099,516
u304013285
ruby
p03373
a, b, c, x, y = STDIN.gets.split(' ').map(&:to_i) max = x < y ? y : x min = 10**9 0.step(max * 2, 2) do |i| num_a = (x - i / 2 < 0) ? 0 : x - i / 2 num_b = (y - i / 2 < 0) ? 0 : y - i / 2 num_c = i price = a*num_a + b*num_b + c*num_c # p "num_a #{num_a}, num_b #{num_b} num_c: #{num_c} price #{price}" if (a*num_a + b*num_b + c*num_c < min) min = price end end
a, b, c, x, y = STDIN.gets.split(' ').map(&:to_i) max = x < y ? y : x min = 10**9 0.step(max * 2, 2) do |i| num_a = (x - i / 2 < 0) ? 0 : x - i / 2 num_b = (y - i / 2 < 0) ? 0 : y - i / 2 num_c = i price = a*num_a + b*num_b + c*num_c # p "num_a #{num_a}, num_b #{num_b} num_c: #{num_c} price #{price}" if (a*num_a + b*num_b + c*num_c < min) min = price end end puts min
null
1,139,481
1,139,482
u237620737
ruby
p03385
puts gets =~ /(.).\1/ ? "No" : "Yes"
puts gets =~ /(.).*\1/ ? "No" : "Yes"
null
1,147,453
1,147,454
u693378622
ruby
p03385
s = gets.chomp abc = %w(a b c) ans = true abc.each do |i| ans = false unless s.include?(i) end if ans p 'Yes' else p 'No' end
s = gets.chomp abc = %w(a b c) ans = true abc.each do |i| ans = false unless s.include?(i) break if false end if ans printf 'Yes' else printf 'No' end
null
1,147,607
1,147,608
u979444096
ruby
p03351
# https://abc097.contest.atcoder.jp/tasks/abc097_a a, b, c, d = gets.chomp.split.map(&:to_i) def a2b2c?(a, b, c, d) (a - b).abs <= d && (b - c).abs <= d end def a2c?(a, c, d) (a - c).abs <= d end if a2b2c?(a, b, c, d) || a2c?(a, c, d) puts "YES" else puts "NO" end
# https://abc097.contest.atcoder.jp/tasks/abc097_a a, b, c, d = gets.chomp.split.map(&:to_i) def a2b2c?(a, b, c, d) (a - b).abs <= d && (b - c).abs <= d end def a2c?(a, c, d) (a - c).abs <= d end if a2b2c?(a, b, c, d) || a2c?(a, c, d) puts "Yes" else puts "No" end
null
1,120,670
1,120,671
u508600593
ruby
p03359
a,b = gets.split.map(&:to_i) p a<b ? a-1 : a
a,b = gets.split.map(&:to_i) p a>b ? a-1 : a
null
1,127,134
1,127,135
u502306384
ruby
p03364
N = gets.to_i ss, sst = [], Array.new(N){Array.new(N)} N.times do |i| ss[i] = gets.chomp N.times {|j| sst[j][i] = ss[i][j]} end sst.map!{|row| row.join} sum = 0 N.times do |i| sum += 1 if N.times.all?{|j|ss[j] == sst[j]} ss.map!{|str| str[-1] + str[0...-1]} sst.rotate!(1) end puts sum*N
N = gets.to_i ss, sst = [], Array.new(N){Array.new(N)} N.times do |i| ss[i] = gets.chomp N.times {|j| sst[j][i] = ss[i][j]} end sst.map!{|row| row.join} sum = 0 N.times do |i| sum += 1 if N.times.all?{|j|ss[j] == sst[j]} ss.map!{|str| str[-1] + str[0...-1]} sst.rotate!(-1) end puts sum*N
null
1,134,811
1,134,812
u314396879
ruby
p03369
s = gets.chomp.split("") sum = 0 s.each do |string| sum += 1 if string = "o" end puts 700 + sum * 100
s = gets.chomp.split("") sum = 0 s.each do |string| sum += 1 if string == "o" end puts 700 + sum * 100
null
1,135,505
1,135,506
u333374716
ruby
p03369
a = gets.chomp puts (count("o"))*100 + 700
a = gets.chomp puts (a.count("o"))*100 + 700
null
1,135,426
1,135,427
u928941036
ruby
p03369
puts 700 + gets.chomp.count('o')
puts 700 + gets.chomp.count('o')*100
null
1,135,918
1,135,919
u374190629
ruby
p03369
puts 700+100*(gets.count("O"))
puts 700+100*(gets.count("o"))
null
1,135,920
1,135,921
u374190629
ruby
p03456
require 'complex' n = gets.split.join('').to_i m = Math.sqrt(n) puts m * m == n ? 'Yes' : 'No'
require 'complex' n = gets.split.join('').to_i m = (Math.sqrt(n)).round puts m * m == n ? 'Yes' : 'No'
null
1,207,110
1,207,111
u811309788
ruby
p03457
#行き先数の入力 n = gets.chomp.to_i #目的地の入力 t, x, y = n.times.map{gets.split.map(&:to_i)}.transpose flag = false (0..n - 1).each do |i| if x[i] + y[i] <= t[i] && (x[i] + y[i]).even? == t[i].even? flag = true else flag = false break end end if flag puts "YES" else puts "NO" end
#行き先数の入力 n = gets.chomp.to_i #目的地の入力 t, x, y = n.times.map{gets.split.map(&:to_i)}.transpose flag = false (0..n - 1).each do |i| if x[i] + y[i] <= t[i] && (x[i] + y[i]).even? == t[i].even? flag = true else flag = false break end end if flag puts "Yes" else puts "No" end
null
1,208,931
1,208,932
u986439180
ruby
p03471
eval"N,Y="+`tr ' ' ,`;$><<([*0..N].product([0,1]).map{|a,b|[a,b,N-a-b]}.find{|a,b,c|c>=0&&a*10+b*5+c==Y/1e3}||[-1]*3)*?\s
eval"N,Y="+`tr ' ' ,`;$><<([*0..N].product([*0..9]).map{|a,b|[a,b,N-a-b]}.find{|a,b,c|c>=0&&a*10+b*5+c==Y/1e3}||[-1]*3)*?\s
null
1,224,325
1,224,326
u032223772
ruby
p03471
$n,$y = gets.chomp.split(" ").map(&:to_i) arr = [] $n.times do |n| ($n - n).times do |n2| arr << [n,n2,($n-n-n2)] end end arr.each do |ar| if ar[0]*10000 + ar[1]*5000 + ar[2]*1000 == $y puts ar.join(" ") exit end end puts "-1 -1 -1"
$n,$y = gets.chomp.split(" ").map(&:to_i) arr = [] ($n+1).times do |n| ($n+1 - n).times do |n2| arr << [n,n2,($n-n-n2)] end end arr.each do |ar| if ar[0]*10000 + ar[1]*5000 + ar[2]*1000 == $y puts ar.join(" ") exit end end puts "-1 -1 -1"
null
1,224,315
1,224,316
u872636244
ruby
p03473
puts 48 - get.to_i
puts (48 - gets.to_i)
null
1,225,066
1,225,067
u627981707
ruby
p03473
p gets.to_i+24
p 48-gets.to_i
null
1,225,143
1,225,144
u503549962
ruby
p03557
n=gets.to_i a=gets.split.map(&:to_i).sort b=gets.split.map(&:to_i) c=gets.split.map(&:to_i).sort answer=0 result=0 for i in 0..b.length-1 key=b[i] ng1=-1 ok1=n #min while (ok1-ng1).abs>1 mid1=(ng1+ok1)/2 if a[mid1]>key ok1=mid1 else ng1=mid1 end end ab=ng1+1 ng2=-1 ok2=n #max while (ok2-ng2).abs>1 mid2=(ng2+ok2)/2 if c[mid2]>key ok2=mid2 else ng2=mid2 end end bc=ok2 result+=(ab*(n-bc)) end p result
n=gets.to_i a=gets.split.map(&:to_i).sort b=gets.split.map(&:to_i) c=gets.split.map(&:to_i).sort answer=0 result=0 for i in 0..b.length-1 key=b[i] ng1=-1 ok1=n #min while (ok1-ng1).abs>1 mid1=(ng1+ok1)/2 if a[mid1]>=key ok1=mid1 else ng1=mid1 end end ab=ng1+1 ng2=-1 ok2=n #max while (ok2-ng2).abs>1 mid2=(ng2+ok2)/2 if c[mid2]>key ok2=mid2 else ng2=mid2 end end bc=ok2 result+=(ab*(n-bc)) end p result
null
1,273,585
1,273,586
u590472228
ruby
p03563
r = gets.to_i g = get.to_i puts 2 * g - r
r = gets.to_i g = gets.to_i puts 2 * g - r
null
1,278,434
1,278,435
u232013343
ruby
p03568
n,*a=`dd`.split.map &:to_i;p 3**n-2**a.count(&:odd?)
n,*a=`dd`.split.map &:to_i;p 3**n-2**a.count(&:even?)
null
1,282,883
1,282,884
u280667879
ruby
p03502
n = gets.to_i a = gets.split.map(&:to_i).inject(:+) puts n % a == 0 ? "Yes": "No"
n = gets.to_i a = n.to_s.chars.map(&:to_i).inject(:+) puts n % a == 0 ? "Yes": "No"
null
1,253,357
1,253,358
u374190629
ruby
p03502
n = gets.to_i a = gets.chars.map(&:to_i).inject(:+) puts n % a == 0 ? "Yes": "No"
n = gets.to_i a = n.to_s.chars.map(&:to_i).inject(:+) puts n % a == 0 ? "Yes": "No"
null
1,253,359
1,253,358
u374190629
ruby
p03502
n = gets.to_i a = gets.chars.map(&:to_i).inject(:+) puts n & a == 0 ? "Yes": "No"
n = gets.to_i a = n.to_s.chars.map(&:to_i).inject(:+) puts n % a == 0 ? "Yes": "No"
null
1,253,360
1,253,358
u374190629
ruby
p03502
x = gets.to_i f = x.to_i.chars.map(&:to_i).inject(0,&:+) puts (x % f == 0 ? 'Yes' : 'No')
x = gets.to_i f = x.to_s.chars.map(&:to_i).inject(0,&:+) puts (x % f == 0 ? 'Yes' : 'No')
null
1,253,828
1,253,829
u627981707
ruby
p03502
n = gets.to_i puts n % n.to_s.split("").map(&:to_i).inject(:+) ? "Yes" : "No"
n = gets.to_i puts n % n.to_s.split("").map(&:to_i).inject(:+) == 0 ? "Yes" : "No"
null
1,253,869
1,253,870
u990788654
ruby
p03502
n = gets.chomp.to_s result = "" keta = n.length fx = 0 keta.times{ |i| fx += n[i].to_i } if( n.to_i % fx == 0 ) result = "yes" else result = "no" end puts result
n = gets.chomp.to_s result = "" keta = n.length fx = 0 keta.times{ |i| fx += n[i].to_i } if( n.to_i % fx == 0 ) result = "Yes" else result = "No" end puts result
null
1,253,902
1,253,903
u285748498
ruby
p03502
n = gets.to_i puts n % n.to_s.split.map(&:to_i).inject(:+) == 0 ? "Yes" : "No"
n = gets.to_i puts n % n.to_s.split('').map(&:to_i).inject(:+) == 0 ? "Yes" : "No"
null
1,254,080
1,254,081
u553623615
ruby
p03524
s = gets.chomp h = {} ("a".."c").each {|c| h[c] = s.count(c)} h = h.values puts h.max - h.min <= 1 ? "Yes" : "No"
s = gets.chomp h = {} ("a".."c").each {|c| h[c] = s.count(c)} h = h.values puts h.max - h.min <= 1 ? "YES" : "NO"
null
1,257,883
1,257,884
u692254521
ruby
p03545
s = gets.chomp def cal(c, a) return a if c.empty? p = c.shift if a.empty? return cal(c, [[p]]) end new_a = [] a.each do |arr| new_a << arr + ['+', p] new_a << arr + ['-', p] end cal(c, new_a) end pattern = cal(s.chars, []) ans = pattern.find { |p| eval(p.join) == 7 } print ans.join
s = gets.chomp def cal(c, a) return a if c.empty? p = c.shift if a.empty? return cal(c, [[p]]) end new_a = [] a.each do |arr| new_a << arr + ['+', p] new_a << arr + ['-', p] end cal(c, new_a) end pattern = cal(s.chars, []) ans = pattern.find { |p| eval(p.join) == 7 } print "#{ans.join}=7"
null
1,264,333
1,264,334
u402631533
ruby
p03545
a, b, c, d = gets.chomp.chars.map(&:to_i) if a + b + c + d == 7 puts "#{a}+#{b}+#{c}+#{d}=7" elsif a + b + c - d == 7 puts "#{a}+#{b}+#{c}-#{d}=7" elsif a + b - c + d == 7 puts "#{a}+#{b}-#{c}+#{d}=7" elsif a - b + c + d == 7 puts "#{a}-#{b}+#{c}+#{d}=7" elsif a - b - c + d == 7 puts "#{a}-#{b}-#{c}+#{d}=7" elsif a + b - c - d == 7 puts "#{a}+#{b}-#{c}-#{d}=7" elsif a + b - c - d == 7 puts "#{a}+#{b}-#{c}-#{d}=7" elsif a - b - c - d == 7 puts "#{a}-#{b}-#{c}-#{d}=7" end
a, b, c, d = gets.chomp.chars.map(&:to_i) if a + b + c + d == 7 puts "#{a}+#{b}+#{c}+#{d}=7" elsif a + b + c - d == 7 puts "#{a}+#{b}+#{c}-#{d}=7" elsif a + b - c + d == 7 puts "#{a}+#{b}-#{c}+#{d}=7" elsif a - b + c + d == 7 puts "#{a}-#{b}+#{c}+#{d}=7" elsif a - b - c + d == 7 puts "#{a}-#{b}-#{c}+#{d}=7" elsif a + b - c - d == 7 puts "#{a}+#{b}-#{c}-#{d}=7" elsif a - b + c - d == 7 puts "#{a}-#{b}+#{c}-#{d}=7" elsif a - b - c - d == 7 puts "#{a}-#{b}-#{c}-#{d}=7" end
null
1,264,697
1,264,698
u866325115
ruby
p03545
OPS = %w[+ -] ds = gets.chomp.chars ops = OPS.product(OPS, OPS) combs = ([ds] * ops.size).zip(ops).map { |(d, o)| d.zip(o).flatten.join } exp = combs.find { |comb| (eval comb) == 7 } p "#{exp}=7"
OPS = %w[+ -] ds = gets.chomp.chars ops = OPS.product(OPS, OPS) combs = ([ds] * ops.size).zip(ops).map { |(d, o)| d.zip(o).flatten.join } exp = combs.find { |comb| (eval comb) == 7 } puts "#{exp}=7"
null
1,265,825
1,265,826
u702547798
ruby
p03610
res = [] gets.chomp.each_with_index{|i,v| res << v if (i+1)%2 == 1} print res.join('')
res = [] gets.chomp.chars.each_with_index{|v,i| res << v if (i + 1)%2 == 1} print res.join('')
null
1,306,547
1,306,548
u978288665
ruby
p03501
g = STDIN.gets s = g.split(' ') s = s.map(&:to_i) if s[0] * s[1] < s[2] puts s[0] * s[1] else puts[2] end
g = STDIN.gets s = g.split(' ') s = s.map(&:to_i) if s[0] * s[1] < s[2] puts s[0] * s[1] else puts s[2] end
null
1,252,234
1,252,235
u152646037
ruby
p03598
n=gets.to_i k=gets.to_i x=gets.split.map(&:to_i) tot=0 for v in x tot+=[x,k-v].min end puts tot*2
n=gets.to_i k=gets.to_i x=gets.split.map(&:to_i) tot=0 for v in x tot+=[v,k-v].min end puts tot*2
null
1,296,870
1,296,871
u459746049
ruby
p03598
n=gets.to_i k=gets.to_i x=gets.split.map(&:to_i) tot=0 for v in x tot+=[x,k-x].min end puts tot
n=gets.to_i k=gets.to_i x=gets.split.map(&:to_i) tot=0 for v in x tot+=[v,k-v].min end puts tot*2
null
1,296,872
1,296,871
u459746049
ruby
p03645
n,m = gets.chomp.split.map(&:to_i) ls = m.times.map{gets.chomp.split.map(&:to_i)} path = Array.new(n){Array.new} flag = false ls.each do |a,b| a -= 1 b -= 1 path[a] << b path[b] << a end stack = path[0] stack.each do |i| if path[i].include?(n-1) flag = true end end puts flag ? "POSSIBLE" : "IMPODDIBLE"
n,m = gets.chomp.split.map(&:to_i) ls = m.times.map{gets.chomp.split.map(&:to_i)} path = Array.new(n){Array.new} flag = false ls.each do |a,b| a -= 1 b -= 1 path[a] << b path[b] << a end stack = path[0] stack.each do |i| if path[i].include?(n-1) flag = true end end puts flag ? "POSSIBLE" : "IMPOSSIBLE"
null
1,333,412
1,333,413
u191196346
ruby
p03645
n, m = gets.split(" ").map(&:to_i) ary = [] m.times do ary << gets.split(" ").map(&:to_i) end ary_one = [] ary_n = [] ary.each do |x| if x[0] == 1 ary_one << x[1] elsif x[1] == n ary_n << x[0] end end if ary_one & ary_n puts "POSSIBLE" else puts "IMPOSSIBLE" end
n, m = gets.split(" ").map(&:to_i) ary = [] m.times do ary << gets.split(" ").map(&:to_i) end ary_one = [] ary_n = [] ary.each do |x| if x[0] == 1 ary_one << x[1] elsif x[1] == n ary_n << x[0] end end if !(ary_one & ary_n).empty? puts "POSSIBLE" else puts "IMPOSSIBLE" end
null
1,333,434
1,333,435
u928941036
ruby
p03719
a,b,c=gets.split.map(&:to_i) puts (a..b).include? c ? "Yes" : "No"
a,b,c=gets.split.map(&:to_i) puts (a..b).include?(c) ? "Yes" : "No"
null
1,382,672
1,382,673
u966810027
ruby
p03719
a, b, c = gets.split.map(&:to_i) puts (c >= a and c >= b) ? "Yes" : "No"
a, b, c = gets.split.map(&:to_i); puts (c >= a and c <= b) ? "Yes" : "No"
null
1,382,770
1,382,771
u714724786
ruby
p03680
n = gets.to_i a = Array.new n.times do a << gets.to_i end t = 0 answer = -1 b = 1 n.times do t = t + 1 b = a[b-1] if b==2 answer = t exit end end puts answer
n = gets.to_i a = Array.new n.times do a << gets.to_i end t = 0 answer = -1 b = 1 n.times do t = t + 1 b = a[b-1] if b==2 answer = t break end end puts answer
null
1,356,628
1,356,629
u775418094
ruby
p03680
N = gets.to_i a = Array.new n.times do a << gets.to_i end t = 0 answer = -1 b = 1 n.times do t = t + 1 b = a[b-1] if b==2 answer = t exit end end puts answer
n = gets.to_i a = Array.new n.times do a << gets.to_i end t = 0 answer = -1 b = 1 n.times do t = t + 1 b = a[b-1] if b==2 answer = t break end end puts answer
null
1,356,630
1,356,629
u775418094
ruby
p03687
s = gets.chomp h = Hash.new {[-1, 0]} s.each_char.with_index do |c, i| h[c] = [i, [h[c][0], i - h[c][1] - 1].max] end puts h.values.map{|x, y| [y, s.size - x - 1].max}.min
s = gets.chomp h = Hash.new {[-1, 0]} s.each_char.with_index do |c, i| h[c] = [i, [h[c][1], i - h[c][0] - 1].max] end puts h.values.map{|x, y| [y, s.size - x - 1].max}.min
null
1,358,942
1,358,943
u692254521
ruby
p03835
k , s = gets.chomp.split(" ").map(&:to_i) count = 0 (0..k).each do |i| (0..k).each do |e| z = s - i - e if z >= 0 && i + e + z == s count += 1 end end end puts count
k , s = gets.chomp.split(" ").map(&:to_i) count = 0 (0..k).each do |i| (0..k).each do |e| z = s - i - e if z >= 0 && i + e + z == s && z <= k count += 1 end end end puts count
null
1,454,462
1,454,463
u412789323
ruby
p03854
s = gets.chomp loop do if s[-5..-1] == 'dream' || s[-5..-1] == 'erase' s.slice!(-5..-1) elsif s[-6..-1] == 'eraser' s.slice!(-6..-1) elsif s[-7..-1] == 'dreamer' s.slice!(-7..-1) else puts 'No' exit end if s.empty? puts 'Yes' exit end end
s = gets.chomp loop do if s[-5..-1] == 'dream' || s[-5..-1] == 'erase' s.slice!(-5..-1) elsif s[-6..-1] == 'eraser' s.slice!(-6..-1) elsif s[-7..-1] == 'dreamer' s.slice!(-7..-1) else puts 'NO' exit end if s.empty? puts 'YES' exit end end
null
1,467,632
1,467,633
u195257137
ruby
p03854
s = gets.chomp.to_s.reverse t = ['dream','dreamer','erase','eraser'] t_r = t.map{|t| t.reverse} 400000.times do t_r.each do |t| if s[0..t.length-1] == t s = s[t.length..-1] break if s.empty? end end end p s.empty? ? "YES" : "NO"
s = gets.chomp.to_s.reverse t = ['dream','dreamer','erase','eraser'] t_r = t.map{|t| t.reverse} 400000.times do t_r.each do |t| if s[0..t.length-1] == t s = s[t.length..-1] break if s.empty? end end end puts s.empty? ? "YES" : "NO"
null
1,468,181
1,468,182
u296101474
ruby
p03828
require 'prime' MOD = (1e+9+7).to_i def array2hash(a) h = {} a.each do |p, e| h[p] = e end return h end def merge(h1, h2) h2.each do |k, v| if h1.key?(k) then h1[k] += h2[k] else h1[k] = h2[k] end end return h1 end def count(h) t = 1 h.each do |p, e| t = (t * (e + 1)) % MOD end return t end def main n = STDIN.gets.chomp.to_i h = {} (1..n).each do |x| merge(h, array2hash(x.prime_division)) end STDOUT.puts count(h).to_i end
require 'prime' MOD = (1e+9+7).to_i def array2hash(a) h = {} a.each do |p, e| h[p] = e end return h end def merge(h1, h2) h2.each do |k, v| if h1.key?(k) then h1[k] += h2[k] else h1[k] = h2[k] end end return h1 end def count(h) t = 1 h.each do |p, e| t = (t * (e + 1)) % MOD end return t end n = STDIN.gets.chomp.to_i h = {} (1..n).each do |x| merge(h, array2hash(x.prime_division)) end STDOUT.puts count(h).to_i
null
1,451,003
1,451,004
u198355306
ruby