code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
H, W = map(int, input().split()) dp = [[H*W for __ in range(W)] for _ in range(H)] dh = [1, 0] dw = [0, 1] S = [] for i in range(H): s = input() S.append(s) if (S[0][0] == '#'): dp[0][0] = 1 else: dp[0][0] = 0 for i in range(H): for j in range(W): for k in range(2): nh = i + dh[k] nw = j + dw[k] if nh >= H or nw >= W: continue add = 0 if (S[nh][nw] == "#" and S[i][j] == "."): add = 1 dp[nh][nw] = min(dp[nh][nw], dp[i][j] + add) print(dp[H-1][W-1])
INF = int(1e18) def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = [A[left + i] for i in range(n1)] R = [A[mid + i] for i in range(n2)] L.append(INF) R.append(INF) i, j = 0, 0 count = 0 for k in range(left, right): count += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return count def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 c1 = merge_sort(A, left, mid) c2 = merge_sort(A, mid, right) c = merge(A, left, mid, right) return c + c1 + c2 else: return 0 if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) c = merge_sort(A, 0, n) print(" ".join(map(str, A))) print(c)
0
null
24,876,820,872,734
194
26
def main(): s = input() dp = [0, 1] for c in s: x = int(c) a = dp[0] + x if a > dp[1] + 10 - x: a = dp[1] + 10 - x b = dp[0] + x + 1 if b > dp[1] + 10 - x - 1: b = dp[1] + 10 - x - 1 dp[0] = a dp[1] = b dp[1] += 1 print(min(dp)) if __name__ == "__main__": main()
import sys buildings = [[[0 for i in xrange(10)] for j in xrange(3)] for k in xrange(4)] n = input() for i in xrange(n): b, f, r, v = map(int, raw_input().split()) buildings[b-1][f-1][r-1] += v for i in xrange(4): if i != 0: print "####################" for j in xrange(3): for k in xrange(10): sys.stdout.write(" "+str(buildings[i][j][k])) print
0
null
36,070,792,251,324
219
55
mod = 10 ** 9 + 7 N, K = map(int, input().split()) A = [0] + [pow(K // x, N, mod) for x in range(1, K + 1)] for x in reversed(range(1, K + 1)): for i in range(2, K // x + 1): A[x] -= A[i * x] print(sum(i * a for i, a in enumerate(A)) % mod)
def main(): n, k = map(int, input().split()) MOD = 10 ** 9 + 7 ans = 0 cnt = [0] * (k + 1) for i in range(1, k + 1): cnt[i] = pow(k // i, n, MOD) for i in range(k, 0, -1): for j in range(2, k // i + 1): cnt[i] -= cnt[i * j] ans = 0 for i, c in enumerate(cnt): ans += i * c ans %= MOD print(ans) if __name__ == '__main__': main()
1
36,810,178,253,470
null
176
176
import math ans = 0 N,D = map(int,input().split()) for i in range(N): x,y = map(int,input().split()) if math.sqrt(abs(x)**2 + abs(y)**2) <= D: ans += 1 print(ans)
S=list(input()) n=len(S) for i in range(n): S[i]=int(S[i]) k=int(input()) dp0=[[0]*(n+1) for i in range(k+1)] dp0[0][0]=1 s=0 for i in range(n): if S[i]!=0: s=s+1 if s==k+1: break dp0[s][i+1]=1 else: dp0[s][i+1]=1 dp1=[[0]*(n+1) for i in range(k+1)] for i in range(1,n+1): if dp0[0][i]==0: dp1[0][i]=1 for i in range(1,k+1): for j in range(1,n+1): if S[j-1]==0: dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1] else: dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1] print(dp0[-1][-1]+dp1[-1][-1])
0
null
40,964,234,880,150
96
224
N = int(input()) number1 = [2,4,5,7,9] number2 = [3] number3 = [0,1,6,8] if N % 10 in number1: print('hon') elif N % 10 in number2: print('bon') elif N % 10 in number3: print('pon')
word = input() print(word + "es" if word[-1] == "s" else word + "s" )
0
null
10,923,083,383,652
142
71
n = int(input()) a = [] for i in range(n): s = str(input()) a.append(s) b = set(a) print(len(b))
A,B = map(int,input().split()) print(max(A-B-B,0))
0
null
98,018,345,793,280
165
291
from string import ascii_lowercase, ascii_uppercase l = ascii_lowercase u = ascii_uppercase def conv(c): if c in l: return u[l.index(c)] if c in u: return l[u.index(c)] return c open(1, 'w').write("".join(map(conv, open(0).readline())))
# coding: utf-8 # Your code here! n = input() t = "" for i in range(len(n)): m = str(n[i]) if (n[i].islower()): m = n[i].upper() else: m = n[i].lower() t += m print(t)
1
1,527,138,181,280
null
61
61
heap = [] while True: try: n = int(raw_input()) if len(heap) == 0: heap.append(n) elif len(heap) == 1: if n <= heap[0]: heap.append(n) else: heap.insert(0, n) elif len(heap) == 2: if n > heap[0]: heap.insert(0, n) elif n <= heap[1]: heap.append(n) else: heap.insert(1, n) elif n > heap[2]: if n >= heap[0]: heap.insert(0, n) elif n >= heap[1]: heap.insert(1, n) else: heap.insert(2, n) heap.pop() except (EOFError): break for num in heap: print num
n,k=map(int,input().split()) a=list(map(int,input().split())) if n<=k: print(0) else: a=sorted(a) b=n-k ans=0 for x in range(n-k): ans+=a[x] print(ans)
0
null
39,439,415,600,988
2
227
def main(): inside_rate, outside_rate = map(int, input().split()) correction = 0 if inside_rate < 10: correction = 100 * (10 - inside_rate) print(outside_rate + correction) main()
n, r = [int(_) for _ in input().split()] print(r if n >= 10 else r + 100 * (10 - n))
1
63,691,942,798,052
null
211
211
notice = int(input()) record = [[[0] * 10 for i in range(3)] for j in range(4)] for _ in range(notice): b, f, r, v = map(int, input().split()) record[b-1][f-1][r-1] += v ans = ('\n' + '#' * 20 + '\n').join([ '\n'.join([' ' + ' '.join(map(str, floor)) for floor in building]) for building in record]) print(ans)
N,D=map(int,input().split()) X=[] for i in range(N): X.append(list(map(int,input().split()))) count=0 for i in range(N): if pow(X[i][0]*X[i][0]+X[i][1]*X[i][1],1/2)<=D:count+=1 print(count)
0
null
3,520,599,678,332
55
96
d = set() n = int(input()) for i in range(n): raw=input().split() if raw[0] == 'insert': d.add(raw[1]) else: if raw[1] in d: print('yes') else: print('no')
N = int(input()) dic = {} for i in range(N): com, s = input().split() if com == 'insert': dic[s] = True elif com == 'find': print('yes' if s in dic else 'no')
1
77,164,986,286
null
23
23
N, M = map(int, input().split()) odd_head, odd_tail = 1, 0 even_head, even_tail = 0, 0 if M & 1: odd_tail = M + 1 even_head = M + 2 even_tail = M + 2 + M - 1 else: odd_tail = 1 + (M - 1) even_head = M + 1 even_tail = M + 1 + M while odd_tail - odd_head > 0: print(odd_head, odd_tail) odd_head += 1 odd_tail -= 1 while even_tail - even_head > 0: print(even_head, even_tail) even_head += 1 even_tail -= 1
N, M = map(int, input().split()) cnt = 0 l = 0 k = M while cnt < M and k > 0: print(l + 1, l + k + 1) cnt += 1 l += 1 k -= 2 l = M + 1 k = M - 1 while cnt < M: print(l + 1, l + k + 1) cnt += 1 l += 1 k -= 2
1
28,868,212,627,872
null
162
162
n = int(input()) from decimal import Decimal def calc(n): for i in range(60000): if int(Decimal(i) * Decimal('1.08')) == n: return i return ':(' print(calc(n))
import sys n = int(input()) ans = n*100/108 for i in [int(ans), int(ans)+1]: if int(i*1.08) == n: print(i) sys.exit() print(":(")
1
125,757,256,993,170
null
265
265
N = int(input()) A = list(map(int, input().split())) D = {} for i in range(N): i+=1 D.update([(A[i-1], i)]) ans = [] for i in range(1, N+1): ans.append(D[i]) str_ans = list(map(str, ans)) print(' '.join(str_ans))
n = int(input()) a = list(map(int, input().split())) ans_list = [None for _ in range(n)] for i in range(0, n): ans_list[a[i] - 1] = str(i + 1) print(" ".join(ans_list))
1
180,862,848,301,630
null
299
299
k=int(input()) s=input() l=len(s) if l<=k: print(s) else: s=list(s) t=[] for i in range(k): t.append(s[i]) t.append('...') print(''.join(t))
k=int(input()) n=input() x=len(n) if(x>k): print(n[0:k]+"...") else: print(n)
1
19,628,184,779,360
null
143
143
A = int(input()) B = int(input()) if A == 1 and B == 2: print('3') elif A == 1 and B == 3: print('2') elif A == 2 and B == 1: print('3') elif A == 2 and B == 3: print('1') elif A == 3 and B == 1: print('2') elif A == 3 and B == 2: print('1')
A = input() B = input() answer = [str(i) for i in range(1, 4)] answer.remove(A) answer.remove(B) print(''.join(answer))
1
111,236,592,673,060
null
254
254
def gcd(x, y): if x == 0: return y return gcd(y % x, x) def lcm(x, y): return x // gcd(x, y) * y n, m = map(int, input().split()) a = list(map(int, input().split())) aa = [e // 2 for e in a] for i, e in enumerate(aa): if i == 0: base = 0 while e % 2 == 0: e //= 2 base += 1 else: cnt = 0 while e % 2 == 0: e //= 2 cnt += 1 if cnt != base: print(0) exit() c = 1 for e in aa: c = lcm(c, e) if c > m: print(0) exit() ans = (m - c) // (2 * c) + 1 print(ans)
import math import numpy as np N,M=map(int,input().split()) A=list(map(int,input().split())) c=1 test=A[0] l=0 while test%2 == 0: test=test//2 c*=2 def lcm_base(x, y): return (x * y) // math.gcd(x, y) for i in np.arange(N-1): if A[i+1]%c!=0: print(0) l=1 break elif A[i+1]%(c*2)==0: print(0) l=1 break else: k=A[i+1]//c test=lcm_base(test, k) if l==0: k=test*c//2 print(M//k//2 + M//k%2)
1
101,824,367,250,268
null
247
247
from itertools import permutations n=int(input()) p=list(map(int,input().split())) q=list(map(int,input().split())) c=sorted(list(permutations(range(1,n+1)))) a,b,=0,0 for i,c in enumerate(c): if p==list(c): a=i if q==list(c): b=i print(abs(a-b))
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") s,t = input().split() a,b = map(int, input().split()) u = input() if s==u: a -= 1 else: b -= 1 print(" ".join(map(str, (a,b))))
0
null
86,312,809,964,400
246
220
d,t,s=[int(i) for i in input().split()] if d<=t*s: print("Yes") else: print("No")
N = int(input()) A = list(map(int, input().split())) SUM = 0; for X in range(len(A)-1): if A[X] > A[X+1]: SUM += A[X]-A[X+1] A[X+1] = A[X] print(SUM)
0
null
4,052,201,595,200
81
88
h,w,m=map(int,input().split()) HW=[list(map(int,input().split())) for _ in range(m)] H,W=[0 for _ in range(h)],[0 for _ in range(w)] for i,j in HW: i,j=i-1,j-1 H[i] +=1 W[j] +=1 max_h,max_w=max(H),max(W) ans=max_h+max_w cnt=H.count(max_h)*W.count(max_w) for i,j in HW: if H[i-1]==max_h and W[j-1]==max_w: cnt -=1 print(ans if cnt!=0 else ans-1)
H,W,M = map(int, input().split()) L = [[int(l) for l in input().split()] for _ in range(M)] hlist = [0]*(H+1) wlist = [0]*(W+1) for l in L: hlist[l[0]] += 1 wlist[l[1]] += 1 hmax = max(hlist) wmax = max(wlist) h = hlist.count(hmax) w = wlist.count(wmax) ans = hmax+wmax-1 cnt = 0 for l in L: if hlist[l[0]] == hmax and wlist[l[1]] == wmax: cnt += 1 if cnt < h*w: ans += 1 print(ans)
1
4,648,721,411,400
null
89
89
a = [int(i) for i in input().split()] if a[0]+a[1]<=a[2]: print(0,0) elif a[0]>=a[2]: print(a[0]-a[2],a[1]) elif a[0]<a[2]: b = a[2]-a[0] print(0,a[1]-b)
a,b,k = map(int, input().split(" ")) if a < k: k -= a a = 0 if b < k: b = 0 else: b -= k else: a -= k print(a,b)
1
104,623,128,650,772
null
249
249
s = int(input()); print str(s/3600) + ':' + str((s%3600)/60) + ':' + str((s%3600)%60)
n,m = map(int, input().split()) A = list(map(int, input().split())) rank = sum(A) / (4*m) cnt =0 for a in A: cnt += rank <= a if cnt >= m: print('Yes') else: print('No')
0
null
19,564,904,724,220
37
179
N = int(input()) A = list(map(int, input().split())) flag = True for i in range(N): if A[i]%2 == 0: if A[i]%3!=0 and A[i]%5!=0: flag = False if flag: print("APPROVED") else: print("DENIED")
N = int(input()) A = list(map(int, input().split())) for a in A: if a%2==0 and not (a%3==0 or a%5==0): print("DENIED") exit() print("APPROVED")
1
69,104,017,672,012
null
217
217
n = int(input()) a_ = [int(i) for i in input().split()] a = [[a_[i], i+1] for i in range(n)] a.sort(reverse=True) dp = [[0 for i in range(n+1)] for j in range(n+1)] x_plus_y = 0 ans = 0 for i in range(n): if x_plus_y == 0: dp[0][1] = a[i][0] * abs((n - a[i][1])) dp[1][0] = a[i][0] * abs((a[i][1] - 1)) else: for x in range(x_plus_y + 1): y = x_plus_y - x dp[x][y+1] = max(dp[x][y+1], a[i][0] * abs((n - y) - a[i][1]) + dp[x][y]) dp[x+1][y] = max(dp[x+1][y] , a[i][0] * abs((a[i][1] - (1+x))) + dp[x][y]) if x_plus_y == n-1: ans = max(ans, dp[x][y+1], dp[x+1][y]) x_plus_y += 1 print(ans)
def main(): from operator import itemgetter N = int(input()) a = map(int, input().split()) *ea, = enumerate(a, 1) ea.sort(key=itemgetter(1), reverse=True) dp = [[0] * (N + 1) for _ in range(N + 1)] # dp[left][right]:=活発な幼児から順に左端からleft,右端からright並べた際の最大うれしさ for i, (p, x) in enumerate(ea, 1): for left in range(i + 1): right = i - left if left > 0: dp[left][right] = max( dp[left][right], dp[left - 1][right] + x * (p - left) ) if right > 0: dp[left][right] = max( dp[left][right], dp[left][right - 1] + x * (N - right + 1 - p) ) ans = max(dp[i][N - i] for i in range(N + 1)) print(ans) if __name__ == '__main__': main()
1
33,578,178,185,440
null
171
171
n,m = map(int,input().split()) if n % 2 == 1: ans = [[1+i,n-i] for i in range(n//2)] else: ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)] for i in range(m): print(ans[i][0],ans[i][1])
n = int(input()) L = [int(x) for x in input().split()] L.sort() ans = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if L[i] != L[j] != L[k]: if L[i] + L[j] > L[k]: ans += 1 print(ans)
0
null
16,980,370,084,000
162
91
import sys from math import gcd from functools import reduce import numpy as np read = sys.stdin.read readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def lcm_base(a, b): return (a * b) // gcd(a, b) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) def main(): n, m = map(int, readline().split()) a = np.array(input().split(), np.int64) a //= 2 b = np.copy(a) while True: c = b % 2 if c.sum() == 0: b //= 2 elif c.sum() == n: break else: print(0) sys.exit() d = lcm_list(a) if d > 10 ** 9: ans = 0 else: ans = (m // d) - (m // (d + d)) print(ans) if __name__ == '__main__': main()
from sys import setrecursionlimit, exit setrecursionlimit(1000000000) from heapq import heapify, heappush, heappop, heappushpop, heapreplace from bisect import bisect_left, bisect_right from math import atan, degrees n, m = map(int, input().split()) a = [int(x) // 2 for x in input().split()] t = 0 while a[0] % 2 == 0: a[0] //= 2 t += 1 for i in range(1, n): t2 = 0 while a[i] % 2 == 0: a[i] //= 2 t2 += 1 if t2 != t: print(0) exit() def gcd(x, y): return gcd(y, x%y) if y else x def lcm(x, y): return x // gcd(x, y) * y m >>= t l = 1 for i in a: l = lcm(l, i) if l > m: print(0) exit() print((m // l + 1) // 2)
1
102,113,143,661,952
null
247
247
s = list(input()) for i in range(int(input())): cmd, a, b, *c = input().split() a = int(a); b = int(b) if cmd == "print": print(*s[a:b+1], sep='') elif cmd == "reverse": s[a:b+1] = reversed(s[a:b+1]) else: s[a:b+1] = c[0]
if __name__ == '__main__': s = input() q = int(input()) for i in range(q): code = input().split() op, a, b = code[0], int(code[1]), int(code[2]) if op == 'print': print(s[a:b+1]) elif op == 'reverse': s = s[:a] + s[a:b+1][::-1] + s[b+1:] elif op == 'replace': s = s[:a] + code[3] + s[b+1:]
1
2,082,734,515,568
null
68
68
h, w = list(map(int, input().split())) masu = h * w if h == 1: print(1) elif w == 1: print(1) elif h * w % 2 == 0: print(int(masu / 2)) else: print(int(masu / 2) + 1)
H, W = map(int, input().split()) if H == 1 or W == 1: print(1) elif H % 2 == 0: print(H*W//2) else: if W % 2 == 0: print(H*W//2) else: print((H//2)*(W//2) + (H//2+1)*(W//2+1))
1
50,768,063,904,580
null
196
196
# D - Triangles import bisect N=int(input()) Li=list(map(int,input().split())) Li.sort() ans=0 for i in range(N): for j in range (i+1,N): a=Li[i]+Li[j] t=bisect.bisect_left(Li,a) ans+=t-(j+1) print(ans)
from bisect import * N = int(input()) L = sorted(map(int,input().split())) a = 0 for i in range(N): for j in range(i+1,N): a+=bisect_left(L,L[i]+L[j])-(j+1) print(a)
1
171,485,952,929,408
null
294
294
''' いちばん簡単なのは建物とフロアごとにリスト作って、足し引き ''' #部屋、フロア、建物をクラスで定義。まあ、クラスにしなくてもいいんだけど a = int(input()) n = 10 m = 3 o = 4 h = [ [ [0 for i in range(n)] for j in range(m)] for k in range(o)] #w, x, y, z = 3, 1, 8, 4 for i in range(a): w,x,y,z = map(int, input().split()) h[w-1][x-1][y-1] += z #print(h[1][1]) #建物と建物仕切り def makeFence(): fence = '#' * 20 print(fence) #部屋を表示する関数 def showRoom(f): for k in range(len(f)-1): print(' ' + str(f[k]), end='') print(' ' + str(f[len(f)-1])) #フロアを表示する関数 def showFloor(b): j = 0 while j < len(b): f = b[j] showRoom(f) j += 1 def statusShow(h): for i in range(len(h)-1): b = h[i] showFloor(b) makeFence() showFloor(h[len(h)-1]) statusShow(h) #b = statusShow(h) #makeFence() #print(b)
x, y = map(int, input().split()) result = x * y print(result)
0
null
8,426,887,564,762
55
133
def main(): T = input() T = T.replace("?", "D") print(T) if __name__ == '__main__': main()
(W, H, x, y, r) = [int(i) for i in input().rstrip().split()] if x + r <= W and x - r >= 0 and y + r <= H and y - r >= 0: print('Yes') else: print('No')
0
null
9,555,394,984,432
140
41
n = int(input()) a = [int(i) for i in input().split()] color = [0, 0, 0] ans = 1 mod = 10 ** 9 + 7 for i in a: cnt = color.count(i) ans *= cnt ans = ans % mod if ans > 0: color[color.index(i)] += 1 else: break print(ans)
import sys H = int(next(sys.stdin.buffer)) ans = 0 i = 1 while H > 0: H //= 2 ans += i i *= 2 print(ans)
0
null
104,659,247,862,816
268
228
N = int(input()) S = list(input()) cn = 1 for i in range(N-1): if S[i] == S[i+1]: continue else: cn = cn + 1 print(cn)
n = int(input()) s = input() prev = "" ans = "" for i in range(n): if s[i] == prev: continue prev = s[i] ans += s[i] print(len(ans))
1
169,544,595,250,332
null
293
293
from collections import Counter n = int(input()) s = Counter([input() for _ in range(n)]) before = 0 ans = [] s = s.most_common() for i in range(len(s)): if before == 0: before = s[i][1] elif before != s[i][1]: break ans.append(s[i][0]) for i in sorted(ans): print(i)
sec=int(input()) print(":".join(map(str, [int(sec/3600), int(sec/60)%60, sec%60])))
0
null
34,995,134,432,622
218
37
print(eval(input().replace(' ','*')))
x, y, z = map(int, input().split()) print("{0} {1} {2}".format(z, x, y))
0
null
26,896,929,054,140
133
178
n = int(input()) l = [] for i in range(1,n+1) : if i%3 != 0 and i%5 != 0 : l.append(i) print(sum(l))
n = int(input()) a = sorted(map(int,input().split()))[::-1] ans = 2 * sum(a[:(n-1)//2+1]) - a[0] if n % 2 == 1: ans -= a[(n-1)//2] print(ans)
0
null
21,937,175,234,656
173
111
n=int(input()) a=list(map(int,input().split())) s=sum(a) res=0 m=1 for i in a: b=m-i if b<0: print(-1) exit(0) res+=i res+=b s-=i m=min(b*2,s) print(res)
n=int(input()) even=n//2 a=(n-even)/n print(a)
0
null
97,626,520,727,372
141
297
n=int(input()) cnt=0 a=1 while(a*a<n): cnt+=1 cnt+=max((n-1)//a-a,0)*2 a+=1 print(cnt)
import sys, os.path import math from collections import Counter if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") MAX = 1000001 factor = [0]*(MAX + 1) def generatePrimeFactors(): factor[1] = 1 for i in range(2,MAX): factor[i] = i for i in range(4,MAX,2): factor[i] = 2 i = 3 while(i * i < MAX): if (factor[i] == i): j = i * i while(j < MAX): if (factor[j] == j): factor[j] = i j += i i+=1 def calculateNoOFactors(n): if (n == 1): return 1 ans = 1 dup = factor[n] c = 1 j = int(n / factor[n]) while (j > 1): if (factor[j] == dup): c += 1 else: dup = factor[j] ans = ans * (c + 1) c = 1 j = int(j / factor[j]) ans = ans * (c + 1) return ans generatePrimeFactors() n = int(input()) temp = n c = 1 count = 0 while(temp-c > 0): w = temp-c count += calculateNoOFactors(w) c += 1 print(count)
1
2,589,656,568,030
null
73
73
n = input() lst = list(map(int, input().split())) print(min(lst), max(lst), sum(lst))
# import string import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): h=int(input()) w=int(input()) n=int(input()) v=max(h,w) cnt=0 while n>0: n-=v cnt+=1 print(cnt) resolve()
0
null
44,919,174,738,528
48
236
import numpy as np n,m,x = map(int, input().split()) li = [] for i in range(n): c_A = list(map(int, input().split())) li.append(c_A) li = np.array(li) cost = 10**7 for i in range(2**n): c_s = np.array([0]*(m+1)) for j in range(n): if ((i>>j)&1): c_s += li[j] if np.all(c_s[1:]>=x): cost = min(cost,c_s[0]) if cost==10**7: print(-1) else: print(cost)
N = int(input()) #U:0~9の整数でN桁の数列 = 10**N #A:0を含まないN桁の数列 = 9**N #B:9を含まないN桁の数列 = 9**N #ans = |U-(A∪B)| = |U|-|A|-|B|+|A∩B| MOD = 10**9 + 7 ans = pow(10, N, MOD) - pow(9, N, MOD) - pow(9, N, MOD) + pow(8, N, MOD) ans %= MOD print(ans)
0
null
12,768,676,699,494
149
78
s, t = input().split() a, b = map(int,input().split()) u = input() if s == u: print(a - 1, b) elif t == u: print(a, b - 1)
import math N, D = map(int, input().split()) p = [list(map(int, input().split())) for _ in range(N)] cnt = 0 for x, y in p: if D >= math.sqrt(x**2 + y**2): cnt += 1 print(cnt)
0
null
38,712,891,040,992
220
96
n = int(input()) s = int(n*(n+1)/2) for l in range(2,n+1): i = 1 while l*i <= n: s += l*i i += 1 print(s)
#!/usr/bin/env python3 import sys input = sys.stdin.buffer.readline N = int(input()) A = list(map(int,input().split())) XY = list() for i in range(N): XY.append((A[i], i+1)) XY.sort() Ans = list() for x,y in XY: Ans.append(y) print(*Ans)
0
null
95,695,260,211,380
118
299
#!/usr/bin/env python import sys sys.setrecursionlimit(10**9) from collections import deque,defaultdict import heapq from itertools import combinations import bisect mod=998244353 pp=pow(2,mod-2,mod) n,s=map(int,input().split()) l=list(map(int,input().split())) dp=[[0 for j in range(s+1)] for i in range(n+1)] dp[0][0]=pow(2,n,mod) for i in range(n): for j in range(s+1): if dp[i][j]>=1: if j+l[i]<=s: dp[i+1][j+l[i]]+=dp[i][j]*pp# +pow(2,n-1,mod) dp[i+1][j+l[i]]%=mod dp[i+1][j]+=dp[i][j] dp[i+1][j]%=mod print(dp[-1][-1]%mod)
import sys readline = sys.stdin.readline DIV = 998244353 N,S = map(int,readline().split()) A = list(map(int,readline().split())) # ある数の取り得る状態は以下 # (1)部分集合Pに含まれない # (2)部分集合Pに含まれ、和に使われている # (3)部分集合Pに含まれ、和に使われていない # dp[k] = 総和がkになっている場合の数 dp = [0] * (S + 1) dp[0] = 1 for i in range(N): nextline = [0] * (S + 1) for k in range(S, -1, -1): # (1)部分集合Pに含まれない # (3)部分集合Pに含まれ、和に使われていない nextline[k] += dp[k] * 2 nextline[k] %= DIV # (2)部分集合Pに含まれ、和に使われている if k + A[i] <= S: nextline[k + A[i]] += dp[k] nextline[k + A[i]] %= DIV dp = nextline print(dp[-1])
1
17,790,982,509,440
null
138
138
from math import factorial def comb(a,b): return factorial(a)//(factorial(b)*factorial(a-b)) n = int(input()) ans=0 for i in range(1,n//3+1): ans+=comb(n-3*i+(i-1),i-1) print(ans%(10**9+7))
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() R = 2**(N.bit_length()) st = [0] * (R*2) def update(i,s): x = 2 ** (ord(s) - ord('a')) i += R-1 st[i] = x while i > 0: i = (i-1) // 2 st[i] = st[i*2+1] | st[i*2+2] def query(a,b,n,l,r): ret = 0 if a <= l and r <= b: return st[n] if a < r and b > l: vl = query(a,b,n*2+1,l,(l+r)//2) vr = query(a,b,n*2+2,(l+r)//2,r) ret = vl | vr return ret for i,s in enumerate(sys.stdin.readline().rstrip()): update(i+1,s) Q = NI() for _ in range(Q): c,a,b = sys.stdin.readline().split() if c == '1': update(int(a),b) else: ret = query(int(a),int(b)+1,0,0,R) cnt = 0 b = 1 for i in range(26): cnt += (b & ret) > 0 b <<= 1 print(cnt) if __name__ == '__main__': main()
0
null
32,910,904,996,278
79
210
A, B = map(int, input().split()) print("{}".format(A*B if (A < 10 and B < 10) else -1))
m1,d1 = map(int,input().split()) m2,d2 = map(int,input().split()) print(1 if m1!=m2 else 0)
0
null
141,297,846,490,022
286
264
n = int(input()) result = [input() for i in range(n)] print('AC x ' + str(result.count("AC"))) print('WA x ' + str(result.count("WA"))) print('TLE x ' + str(result.count("TLE"))) print('RE x ' + str(result.count("RE")))
#Union-Find木の実装 from collections import Counter N,M=map(int,input().split()) #初期化 par=[i for i in range(N)]#親の要素(par[x]=xのときxは木の根) rank=[0]*N#木の深さ #木の根を求める def find(x): #xが根だった場合xをそのまま返す if par[x] == x: return x else: #根が出るまで再帰する par[x] = find(par[x]) return par[x] #xとyの属する集合を併合 def unite(x,y): x=find(x)#xの根 y=find(y)#yの根 #根が同じなら何もしない if x == y: return #もし根の深さがyの方が深いなら if rank[x] < rank[y]: par[x] = y#yを根にする else: par[y] = x#xを根にする if rank[x] == rank[y]: rank[x]+=1 #xとyが同じ集合に属するか否か #def same(x,y): #return find(x)==find(y) for _ in range(M): a,b = map(int,input().split()) a,b = a-1, b-1 unite(a,b) for i in range(N): find(i) c=Counter(par) print(len(c)-1)
0
null
5,461,025,761,818
109
70
def insetionSort(A,n,g): global cnt for i in range(g,n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g cnt += 1 A[j+g] = v return A def shellSort(b,p): global cnt t = 1 G = [1] while t*3+1 < p: t = t*3 +1 G.append(t) G.reverse() m = len(G) for i in range(0,m): b = insetionSort(b,p,G[i]) print(m) print(" ".join(map(str,G))) print(cnt) for t in b: print(t) num = int(input()) lister = [int(input()) for s in range(num)] cnt = 0 shellSort(lister,num)
import math def insertionSort(A,n,g): cnt = 0 for i in range(g,n): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g], A[j] = A[j],A[j+g] j -= g cnt += 1 A[j+g] = v return cnt def shellSort(A,n): cnt = 0 m = round(math.log(len(A),2))+1 # 事前処理をやる回数 print(m) G = [round(len(A)*((1/2)**(a+1))) for a in range(m)] # 事前処理時の、各回の間隔 print(*G) for i in range(0,m): cnt += insertionSort(A,n,G[i]) return cnt n = int(input()) A = [int(input()) for a in range(n)] print(shellSort(A,n)) for a in A: print(a)
1
30,047,477,880
null
17
17
H,W=map(int,input().split()) import math A=[0,math.ceil(W/2)] if (H-1)*(W-1)!=0: c=W*math.floor(H/2)+A[H%2] else: c=1 print(c)
A, B=(input().split()) A=int(A) C=int(B[0])*100+int(B[2])*10+int(B[3]) print(int(A*C//100))
0
null
33,607,400,982,890
196
135
import math x1, y1, x2, y2 = [ float( i ) for i in raw_input( ).split( " " ) ] print( math.sqrt( ( x1 - x2 )**2 + ( y1 - y2 )**2 ) )
n, x, m = map(int, input().split()) tmp = [] while True: tmp.append(x) x = pow(x, 2, m) if x in tmp: break k = 0 while True: if tmp[k] == x: break k += 1 if k > n: print(sum(tmp[:n])) else: t = k a = (n - k) // (len(tmp) - k) s = (n - k) % (len(tmp) - k) print(sum(tmp[:k]) + sum(tmp[k:]) * a + sum(tmp[k: k + s]))
0
null
1,476,265,129,430
29
75
def main(): S = input() def an_area(S): ans = 0 stack_in = [] stack_out = [] for i,ch in enumerate(S): if ch == '\\': stack_in.append(i) elif stack_in and ch == '/': j = stack_in.pop() cur = i - j stack_out.append((j,i,cur)) ans += cur return ans,stack_out ans, l = an_area(S) if ans == 0: print(ans) print(len(l)) return l.sort() pre_le, pre_ri = l[0][0], l[0][1] pre_ar = 0 areas = [] for le,ri,ar in l: if pre_le <= ri <= pre_ri: pre_ar += ar else: areas.append(pre_ar) pre_ar = ar pre_le, pre_ri = le, ri else: areas.append(pre_ar) print(ans) print(len(areas),*areas) if __name__ == '__main__': main()
total_stack = [] single_stack = [] def main(): input_line = input() total = 0 for i,s in enumerate(input_line): if s == "\\": total_stack.append(i) elif s == "/" and len(total_stack) != 0: a = total_stack.pop() total += i - a area = 0 while len(single_stack) != 0 and a < single_stack[-1][0]: area += single_stack.pop()[1] single_stack.append([a, area + i - a]) print(total) print(' '.join([str(len(single_stack))] + [str(i[1]) for i in single_stack])) if __name__ == '__main__': main()
1
55,614,288,610
null
21
21
from itertools import chain import sys def main(): N = int(input()) # TLEs were caused mostly by slow input (1s+) # S = list(input() for _ in range(N)) S = sys.stdin.read().split('\n') print(solve(S)) def get_count(args): s, result = args # messy input to work with map. cum_sum = 0 for c in s: if c == ')': cum_sum -= 1 else: cum_sum += 1 result[0] = max(result[0], -cum_sum) result[1] = result[0] + cum_sum return result # Made-up name, don't remember what to call this. Radix-ish def silly_sort(array, value_min, value_max, get_value): if len(array) == 0: return cache = [None for _ in range(value_max - value_min + 1)] for elem in array: # Assume elem[0] is the value value = get_value(elem) - value_min if cache[value] is None: cache[value] = [] cache[value].append(elem) for values in cache: if values is None: continue for value in values: yield value def solve(S): counts = [[0,0] for _ in range(len(S))] counts = list(map(get_count, zip(S,counts))) first_group = [] second_group = [] min_first_group = float('inf') max_first_group = 0 min_second_group = float('inf') max_second_group = 0 for c in counts: if c[0] - c[1] <= 0: first_group.append(c) max_first_group = max(max_first_group, c[0]) min_first_group = min(min_first_group, c[0]) else: second_group.append(c) max_second_group = max(max_second_group, c[1]) min_second_group = min(min_first_group, c[1]) first_group = silly_sort(first_group, min_first_group, max_first_group, lambda c: c[0]) second_group = reversed(list(silly_sort(second_group, min_second_group, max_second_group, lambda c: c[1]))) order = chain(first_group, second_group) cum_sum = 0 for c in order: cum_sum -= c[0] if cum_sum < 0: return 'No' cum_sum += c[1] if cum_sum == 0: return 'Yes' return 'No' if __name__ == '__main__': main()
numbers = [] while True: x=int(input()) if x==0: break numbers.append(x) for i in range(len(numbers)): print("Case ",i+1,": ",numbers[i],sep="")
0
null
12,178,491,091,120
152
42
a,b,c=map(int,input().split()) k=int(input()) while a>=b: k-=1 b*=2 if k>=0: print('Yes' if c*(2**k)>b else 'No') else: print('No')
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N = int(readline()) print(int(N**2))
0
null
76,463,911,523,200
101
278
n,k=map(int,input().split()) li=list(map(int,input().split())) kai=[0] for i in range(1,1001): kai.append(kai[i-1]+i) ka=[0]+[kai[i]/i for i in range(1,len(kai))] lis=[ka[i] for i in li] ans=sum(lis[:k]) mx=ans for i in range(len(li)-k): ans-=lis[i] ans+=lis[i+k] mx=max(ans,mx) print(mx)
N, K = map(int, input().split()) p = list(map(int, input().split())) def calc(x): return (x+1)/2 pe = [] for i in range(N): pe.append(calc(p[i])) cs = [pe[0]] + [0]*(N-1) for i in range(1, N): cs[i] = pe[i] + cs[i-1] ans = cs[K-1] for i in range(K, N): wa = cs[i] - cs[i-K] ans = max(ans, wa) print(ans)
1
74,754,258,468,030
null
223
223
n,k = map(int,input().split()) h = [0 for _ in range(n)] h = [int(s) for s in input().split()] h.sort() #print(h) if(n-k <= 0): ans = 0 else: h_new = h[:n-k] #print(h_new) ans = sum(h_new) print(ans)
n=int(input()) a=map(int,input().split()) pulasu_i=dict() mainasu_i=dict() for i,num in enumerate(a): x=i+1 if num+x not in pulasu_i: pulasu_i[num+x]=1 else: pulasu_i[num+x]+=1 if num-x not in mainasu_i: mainasu_i[num-x]=1 else: mainasu_i[num-x]+=1 #print(pulasu_i,mainasu_i) ans=0 for num,cnt in pulasu_i.items(): if -num not in mainasu_i: continue else: ans+=cnt*mainasu_i[-num] print(ans)
0
null
52,455,218,000,240
227
157
n, m = map(int, input().split()) a = [] b = [] c = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(int(input())) for i in range(n): elm = 0 for k in range(m): elm += a[i][k] * b[k] c.append(elm) for i in c: print(i)
n,m = map(int,input().split()) tbl=[[] for i in range(n)] for i in range(n): tbl[i] = list(map(int,input().split())) tbl2=[[]*1 for i in range(m)] for i in range(m): tbl2[i] = int(input()) for k in range(n): x=0 for l in range(m): x +=tbl[k][l]*tbl2[l] print("%d"%(x))
1
1,163,542,119,608
null
56
56
print('win' if sum(list(map(int, input().split(' ')))) <= 21 else 'bust')
a, b, c = [int(x) for x in input().split()] if a + b + c >= 22: print("bust") else: print("win")
1
118,770,402,090,718
null
260
260
s = list(input()) s1 = s[:len(s)//2] s2 = s[-(-len(s)//2):][::-1] cnt = 0 while True: if s1 == s2: break for i in range(len(s1)): if s1[i] != s2[i]: s1[i] = s2[i] cnt += 1 print(cnt)
import sys (a, b, c) = [int(i) for i in sys.stdin.readline().split()] count = 0 for i in range(a, b + 1): if c % i == 0: count += 1 print(count)
0
null
60,663,139,259,592
261
44
import math n, d = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(n)] count = 0 for i in range(n): count = count + 1 if math.sqrt(xy[i][0]**2 + xy[i][1]**2) <= d else count print(count)
h = int(input()) w = int(input()) n = int(input()) x = max(h, w) ans = (n + x - 1) // x print(ans)
0
null
47,212,163,203,556
96
236
import time as ti class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 50010 self.queue = [0] * self.length # counter = 0 # while counter < self.length: # self.queue.append(Process()) # counter += 1 self.head = 0 self.tail = 0 # def enqueue(self, name, time): def enqueue(self, process): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ self.queue[self.tail] = process # self.queue[self.tail].name = name # self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ # self.queue[self.head].name = "" # self.queue[self.head].time = 0 self.queue[self.head] = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time,): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval # name, time = my_queue.queue[my_queue.head].name, \ # my_queue.queue[my_queue.head].time my_queue.enqueue(my_queue.queue[my_queue.head]) my_queue.dequeue() return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(Process(name, int(time))) counter += 1 # end_time_list = [] current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
import collections import sys n,q = map(int,input().split()) data = [[i for i in input().split()]for i in range(n)] time = 0 while data: task = data[0] del data[0] if int(task[1]) <= q: time += int(task[1]) print(task[0],time) else: time += q task[1] = str(int(task[1]) - q) data.append(task)
1
44,715,311,460
null
19
19
#input() ans=1 for i in map(int,input().split()):ans*=i print(int(ans))
# -*- coding: utf-8 -*- import sys from collections import defaultdict H,W,K=map(int, sys.stdin.readline().split()) S=[ sys.stdin.readline().strip() for _ in range(H) ] #print H,W,K #print S ans=float("inf") for bit in range(2**H): cnt=0 group_num=0 GROUP={} for i,s in enumerate(S): if i==0: GROUP[i]=group_num else: if bit>>i-1&1==1: cnt+=1 #境目のカウントに+1 group_num+=1 GROUP[i]=group_num #print "GROUP :: ",GROUP ok=None VALUE=defaultdict(lambda: 0) w=0 for w in range(W): for h in range(H): VALUE[GROUP[h]]+=int(S[h][w]) #現在の値がKを超えていないか for v in VALUE.values(): if v<=K: pass else: #print "NG!",w if ok is None: #okに値がない場合は、このパターンは成り立たない #print "IMPOSSIBLE!" cnt=float("inf") #不可能なパターンなのでカウントに無限大を代入 else: #以前の列で成り立たっていた場合 cnt+=1 #境目のカウントに+1 VALUE=defaultdict(lambda: 0) #NGの場合は値を初期化して入れなおし for h in range(H): VALUE[GROUP[h]]+=int(S[h][w]) break else: ok=w #print "w,ok,cnt,VALUE :: ",w,ok,cnt,VALUE ans=min(ans,cnt) print ans
0
null
32,225,472,470,544
133
193
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): tmp = [] if n % i == 0: tmp.append(i) tmp.append(n//i) if(len(tmp)>0): divisors.append(sum(tmp)) return divisors def main5(): n = int(input()) k = make_divisors(n) print(min(k)-2) if __name__ == '__main__': main5()
a,b=map(str,input().split()) c,d=map(int,input().split()) k=input() if k==a: c-=1 else: d-=1 print(c,d)
0
null
116,309,271,245,020
288
220
T1,T2 = map(int,input().split()) A1,A2 = map(int,input().split()) B1,B2 = map(int,input().split()) ans = 0 if T1*A1+T2*A2 == T1*B1+T2*B2: print("infinity") exit() if A1>B1: jtA = True else: jtA = False if jtA: if T1*A1+T2*A2 > T1*B1+T2*B2: print(0) exit() else: jA = False x = abs(T1*B1+T2*B2 - T1*A1-T2*A2) else: if T1*A1+T2*A2 < T1*B1+T2*B2: print(0) exit() else: jA = True x = abs(T1*A1+T2*A2 - T1*B1-T2*B2) if (abs(A1-B1)*T1)%x == 0: ans += ((abs(A1-B1)*T1)//x)*2 else: ans += ((abs(A1-B1)*T1)//x)*2+1 print(ans)
S = input() K = int(input()) length = len(S) num_fixed = 0 pre_char = '' count = 0 for i in range(length): now_char = S[i] if pre_char != now_char: num_fixed += count//2 count = 0 count += 1 pre_char = now_char # print("pre_char:{}, now_char:{}, count:{}".format(pre_char, now_char, count)) num_fixed += count//2 # print(num_fixed) if S[0] == S[length - 1]: head_length = 1 head_char = S[0] for i in range(1, length): now_char = S[i] if now_char != head_char: break head_length += 1 tail_length = 1 tail_char = S[length - 1] for i in range(1, length): now_char = S[length - 1 - i] if now_char != tail_char: break tail_length += 1 if length == head_length == tail_length: ans = length * K // 2 else: ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) else: ans = num_fixed * K print(ans)
0
null
153,794,432,677,760
269
296
# -*- coding: utf-8 -*- S = int(raw_input()) h = S / 3600 S %= 3600 m = S / 60 S %= 60 s = S print "%d:%d:%d" %(h, m, s)
time = input() h = time/3600 m = time/60%60 s = time%60 print "%d:%d:%d"% (h, m, s)
1
338,425,839,038
null
37
37
from collections import deque d=deque() N=int(input()) for n in range(N): a=input() if a=="deleteFirst": d.popleft() elif a=="deleteLast": d.pop() else: a,b=a.split() if a=="insert": d.appendleft(b) elif a=="delete": if d.count(b): d.remove(b) print(' '.join(list(d)))
x = int(input()) ans = 8 if x < 600: ans=8 elif x < 800: ans=7 elif x < 1000: ans=6 elif x < 1200: ans=5 elif x < 1400: ans=4 elif x < 1600: ans=3 elif x < 1800: ans=2 else: ans=1 print(ans)
0
null
3,422,270,701,810
20
100
n = int(input()) s = [] t = [] for i in range(n): a,b = input().split() s.append(a) t.append(int(b)) x = s.index(input()) ans = 0 for i in range(x+1,n): ans += t[i] print(ans)
N = int(input()) s = [""] * N t = [0] * N for i in range(N): a, b = map(str, input().split()) s[i] = a t[i] = int(b) X = input() sleep_index = s.index(X) ans = 0 for i in range(sleep_index+1, N): ans += t[i] print(ans)
1
96,891,011,322,660
null
243
243
seed = [i for i in range(1,14)] deck = {} for s in ['S','H','C','D']: deck[s] = seed[:] n = int(input()) for i in range(n): s,v = input().split() deck[s][int(v)-1] = 0 for s in ['S','H','C','D']: for i in deck[s]: if i != 0: print(s,i)
n = int(input()) full_set=set([x for x in range(1,14)]) cards={"S":[],"H":[],"C":[],"D":[]} for i in range(n): suit,num = input().split() cards[suit].append(int(num)) for suit in ["S","H","C","D"]: suit_set = set(cards[suit]) for num in sorted(list(full_set - suit_set)): print(suit,num)
1
1,051,165,484,220
null
54
54
n = int(input()) q = list(map(int,input().split())) ans = 0 count = 0 for i in q: if i%2 == 0: alm = i count += 1 if alm%3 == 0 or alm%5 == 0: ans += 1 if ans == count: print("APPROVED") else: print("DENIED")
n = input() l = list( map(int, input().split())) odd = [ c for c in l if (c % 2 == 0 ) and (( c % 3 != 0) and ( c % 5 !=0 ))] if len( odd ) == 0: print( "APPROVED" ) else: print( "DENIED" )
1
69,120,080,721,572
null
217
217
h, w = map(int, input().split()) s = [list(map(str, input().rstrip())) for _ in range(h)] dp = [[10001] * w for _ in range(h)] if s[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 moves = [[1, 0], [0, 1]] for y in range(h): for x in range(w): for m in moves: ny, nx = y + m[0], x + m[1] if ny >= h or nx >= w: continue add = 0 # .から#に突入する時だけカウントが増える if s[y][x] == "." and s[ny][nx] == "#": add = 1 dp[ny][nx] = min(dp[ny][nx], dp[y][x] + add) print(dp[-1][-1])
h,w=map(int,input().split()) s=['*'+'.'+'*'*w]+['*'+input()+'*' for i in range(h)]+['*'*(w+2)] b=10**9 d=[[b]*(w+2)]+[[b]+[0]*w+[b] for _ in range(h)]+[[b]*(w+2)] d[0][1]=0 for i in range(1,h+1): for j in range(1,w+1): d[i][j]=min(d[i-1][j]+(s[i][j]=='#')*(s[i-1][j]=='.'),d[i][j-1]+(s[i][j]=='#')*(s[i][j-1]=='.')) print(d[h][w])
1
49,172,899,555,052
null
194
194
from collections import deque INF = 1000000 N,T,A=map(int,input().split()) T -= 1 A -= 1 G = [ [] for i in range(N) ] DT = [ INF for _ in range(N) ] DA = [ INF for _ in range(N) ] for i in range(N-1): h1,h2=map(int,input().split()) h1 -= 1 h2 -= 1 G[h1].append(h2); G[h2].append(h1); DT[T] = 0 DA[A] = 0 q = deque() # BFS q.append(T) while len(q) > 0: v = q.popleft() for nv in G[v]: if DT[nv] == INF: DT[nv] = DT[v] + 1 q.append(nv) q.clear() q.append(A) while len(q) > 0: v = q.popleft() for nv in G[v]: if DA[nv] == INF: DA[nv] = DA[v] + 1 q.append(nv) max_da = 0 for i in range(N): #print(i, " T:", DT[i], " A:", DA[i]) if DA[i] - DT[i] >= 1 : max_da = max(DA[i], max_da) print(max_da-1)
for n in range(1, 10): for m in range(1, 10): print(str(n) + "x" + str(m) + "=" + str(n*m))
0
null
58,673,410,385,550
259
1
n = int(input()) ans = [] while n > 0: n -= 1 k = n % 26 n = n // 26 ans.append(chr(ord('a') + k)) for j in reversed(range(len(ans))): print(ans[j], end = '')
def numtoalpha(n): if n <= 26: return chr(96+n) elif n % 26 == 0: return numtoalpha(n//26-1) + chr(96+26) else : return numtoalpha(n//26) + chr(96+(n%26)) if __name__ == '__main__': n = int(input()) print(numtoalpha(n))
1
11,846,798,012,660
null
121
121
x = int(input()) t = x // 500 print(1000 * t + 5 * ((x - 500 * t) // 5))
def main(): a, b = map(int, input().split()) if a < 10 and b < 10: print(a*b) else: print(-1) main()
0
null
100,505,113,000,240
185
286
t1,t2 = map(int,input().split()) a1,a2 = map(int,input().split()) b1,b2 = map(int,input().split()) a1 -= b1 a2 -= b2 if a1 < 0: a1 *= -1 a2 *= -1 d = a1 * t1 + a2 * t2 if d > 0: print(0) elif d == 0: print('infinity') else: d *= -1 l = a1 * t1 if l % d != 0: print(l//d*2+1) else: print(l//d*2) #print(a1,a2) #print(d,l)
import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n,u,v=map(int,input().split()) node=[[]for _ in range(n)] for _ in range(n-1): a,b=map(int,input().split()) node[a-1].append(b-1) node[b-1].append(a-1) def dfs(i): visited[i]=1 for x in node[i]: if visited[x]==0: dis[x]=dis[i]+1 dfs(x) inf=10**9 dis=[inf]*n;dis[u-1]=0;visited=[0]*n dfs(u-1) dis2=[] from copy import copy dis_dash=copy(dis) dis2.append(dis_dash) dis[v-1]=0;visited=[0]*n dfs(v-1) dis2.append(dis) cnt=0 for i in range(n): if dis2[0][i]<dis2[1][i]: cnt=max(cnt,dis2[1][i]) print(cnt-1)
0
null
124,752,294,612,440
269
259
def main(): n = int(input()) even = n // 2 print(1 - even / n) if __name__ == "__main__": main()
def main(): n = int(input()) for _ in range(n): len_list = map(int, input().split()) check_tri(len_list) def check_tri(len_list): import itertools import math flag = False for tmp in list(itertools.permutations(len_list)): if (pow(tmp[0], 2) + pow(tmp[1], 2)) == pow(tmp[2], 2): flag = True break if flag == True: print('YES') else: print('NO') if __name__ == '__main__': main()
0
null
88,776,404,588,300
297
4
n = int(raw_input()) d = [0 for i in range(n)] f = [0 for i in range(n)] G = [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] col = [0 for i in range(n)] t = [0] def DFS_visit(u): col[u] = 1 t[0] += 1 d[u] = t[0] for v in range(n): if M[u][v] == 1 and col[v] == 0: DFS_visit(v) col[u] = 2 t[0] += 1 f[u] = t[0] def DFS(): for u in range(n): if col[u] == 0: DFS_visit(u) for u in range(n): print'{0} {1} {2}'.format(u+1, d[u], f[u]) for i in range(n): X = map(int, raw_input().split()) for j in range(X[1]): M[X[0]-1][X[2+j]-1] = 1 DFS()
N = int(input()) a = 0 k = 2*(N-2)+1 for i in range(2,N): for j in range(i,N): if (i*j<N)and(i!=j): a+=2 elif(i*j<N)and(i==j): a+=1 else: break print(a+k)
0
null
1,289,874,363,104
8
73
x = int(input()) j = 8 for low in range(400, 2000, 200): if low <= x < low + 200: print(j) break j -= 1
def main(): x = int(input()) grade = 0 for i in range(8): if (400 + 200 * i) <= x < (400 + 200 * (i + 1)): grade = 8 - i print(grade) if __name__ == "__main__": main()
1
6,707,163,793,600
null
100
100
S = input() if(S[len(S)-1] == 's'):print(S + 'es') else :print(S + 's')
n = int(input()) if n % 2 == 0: ans = n / 2 - 1 else: ans = n / 2 print(int(ans))
0
null
78,071,874,891,230
71
283
def resolve(): N = int(input()) S = list(input()) ans = [chr(((ord(s)-65+N)%26)+65) for s in S] print("".join(ans)) if '__main__' == __name__: resolve()
a = int(input()) b = input() for i in range(0, len(b)): c = ord(b[i]) d = int(c+a) if d>90: d -= 26 e = chr(d) print(e, end="")
1
134,446,519,499,280
null
271
271
x=int(input()) n=100 ans=0 while True: ans+=1 n+=n//100 if n>=x: print(ans) break
if __name__ == '__main__': try: n = int(raw_input()) except: print 'the first input must be integer value!' exit() genoms = set([]) answers = [] for _ in range(n): values = raw_input().split() order = values[0] genom = values[1] if order == "insert": genoms.add(genom) else: # TODO: fasten here! answers.append('yes' if genom in genoms else 'no' ) # print(genoms) # print(answers) for answer in answers: print answer
0
null
13,689,078,420,990
159
23
# -*- coding: utf-8 -*- class dice_class: def __init__(self, list): self.num = list def roll(self, s): for i in s: if i == 'E': self.rollE() elif i == 'N': self.rollN() elif i == 'S': self.rollS() elif i == 'W': self.rollW() def rollE(self): self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]] def rollN(self): self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]] def rollS(self): self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]] def rollW(self): self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]] if __name__ == "__main__": dice = dice_class(map(int, raw_input().split())) s = str(raw_input()) dice.roll(s) print dice.num[0]
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) N, M = map(int, input().split()) uf = UnionFind(N) import sys input = sys.stdin.readline import collections for i in range(M): A, B = map(int, input().rstrip().split()) uf.union(A-1, B-1) doku = uf.parents.count(-1) all = uf.group_count() - doku ans = all + doku -1 print(ans)
0
null
1,277,005,015,618
33
70
def main(): k = int(input()) s = str(input()) output = '' if len(s) > k: for i in range(k): output += s[i] output += '...' else: output = s print(output) if __name__ == '__main__': main()
#template def inputlist(): return [int(j) for j in input().split()] #template li = inputlist() for i in range(5): if li[i] == 0: print(i+1)
0
null
16,579,768,788,932
143
126
def selection_sort(A): count = 0 for i in range(len(A)): min_value = A[i] min_value_index = i # print('- i:', i, 'A[i]', A[i], '-') for j in range(i, len(A)): # print('j:', j, 'A[j]:', A[j]) if A[j] < min_value: min_value = A[j] min_value_index = j # print('min_value', min_value, 'min_value_index', min_value_index) if i != min_value_index: count += 1 A[i], A[min_value_index] = A[min_value_index], A[i] # print('swap!', A) return count n = int(input()) A = list(map(int, input().split())) count = selection_sort(A) print(*A) print(count)
N, A, cou = int(input()), [int(temp) for temp in input().split()], 0 for i in range(N) : minj = i for j in range(i, N) : if A[j] < A[minj] : minj = int(j) if A[i] != A[minj] : A[i], A[minj] = int(A[minj]), int(A[i]) cou = cou + 1 print(*A) print(cou)
1
19,619,317,842
null
15
15
def main(): a,b,c=map(int,input().split()) k = int(input()) for i in range(k): if a < b < c: break elif a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') main()
a = map(int, raw_input().split()) a.sort() for i in range(len(a)): print a[i],
0
null
3,680,611,818,248
101
40
d,t,s = [int(x) for x in input().split()] if d/s <= t: print("Yes") else: print("No")
n,k=map(int,input().split()) h=list(map(int,input().split())) sum=0 for l in h: if l>=k: sum+=1 print(sum)
0
null
90,981,581,177,604
81
298
import statistics while True: n = int(input()) if n == 0: break scores = list((int(x) for x in input().split())) std = statistics.pstdev(scores) print("{0:.8f}" . format(round(std,8)))
while True: n = int(input()) if n == 0: break else: score = [int(x) for x in input().split()] a = 0 m = sum(score)/n for s in score: a += (s-m)**2 a = (a/n)**0.5 print('{:.8f}'.format(a))
1
199,342,923,582
null
31
31
k=int(input()) a,b = map(int, input().split()) if a%k==0: print("OK") exit() if a+k-a%k<=b: print("OK") else: print("NG")
K = int(input()) A, B = map(int, input().split()) exist = False for i in range(A, B+1): if i % K == 0: exist = True print('OK' if exist else 'NG')
1
26,469,412,240,736
null
158
158
length = int(input()) nums = input().split() print(" ".join(nums[::-1]))
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() S = input() tmp = string.ascii_uppercase ans = [] for s in S: i = string.ascii_uppercase.index(s) if i+n > 25: ans.append(tmp[i+n-26]) else: ans.append(tmp[i+n]) print(''.join(ans))
0
null
68,102,593,744,458
53
271
n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) d= [abs(x[i] - y[i]) for i in range(n)] for i in range(1, 4): a = 0 for j in d: a += j**i print("{:.6f}".format(a**(1/i))) print("{:.6f}".format(max(d)))
n = int(input()) X = list(map(int, input().split())) Y = list(map(int, input().split())) diff = [] total1 = 0 total2 = 0 total3 = 0 for i in range(n): diff.append(abs(X[i] - Y[i])) total1 += diff[i] total2 += diff[i] ** 2 total3 += diff[i] ** 3 print("{0:.6f}" . format(total1)) print("{0:.6f}" . format(total2 ** 0.5)) print("{0:.6f}" . format(total3 ** (1 / 3))) print("{0:.6f}" . format(max(diff)))
1
213,940,739,140
null
32
32
W = input().lower() count = 0 while True: line = input() if line == 'END_OF_TEXT': break for s in line.lower().split(): if s == W: count += 1 print(count)
h,w,n=[int(input()) for _ in range(3)] m=max(h,w) print(0--n//m)
0
null
45,080,453,340,510
65
236
from collections import Counter a = int(input()) num_list = list(map(int, input().split())) D = Counter(num_list) for i in range(a): print(D[i+1])
N = int(input()) A = list(input().split()) boss = [0] for i in range(N-1): boss.append(0) boss[int(A[i])-1] += 1 for i in range(N): print(str(boss[i]))
1
32,600,703,471,710
null
169
169
from collections import * n=int(input()) l=[] for i in range(n): l.append(input()) c=Counter(l) m=max(c.values()) d=[] for i in c: if(c[i]==m): d.append(i) d.sort() for i in d: print(i)
cnt = int(input()) string = input() if len(string) <= cnt: print(string) else: print(string[:cnt] + "...")
0
null
44,617,422,435,924
218
143
n = int(input()) a = list(map(int, input().split())) h = 0 for i in range(1, len(a)): if a[i-1] > a[i]: h += a[i-1] - a[i] a[i] += a[i - 1] - a[i] print(h)
def main() : N = int(input()) A = list(map(int, input().split())) sum = 0 t = A[0] for i in range(1, N): if A[i] <= t: sum += t - A[i] else: t = A[i] print(sum) if __name__ == "__main__": main()
1
4,598,436,960,558
null
88
88
N=int(input()) S=[input() for i in range(N)] L=dict() for i in range(N): if S[i] in L: L[S[i]]+=1 else: L[S[i]]=1 M=max(L.values()) ans=list() for X in L: if L[X]==M: ans.append(X) ans.sort() for X in ans: print(X)
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): a[i] = a[i] % k if k == 1: print(0) exit() ruiseki = [0] for i in range(n): ruiseki.append((a[i]+ruiseki[-1])%k) mini = 0 dic = {} ans = 0 for j in range(1, n+1): if j-k+1 > mini: dic[(ruiseki[mini]-mini)%k] -= 1 mini += 1 if (ruiseki[j-1]-(j-1))%k in dic: dic[(ruiseki[j-1]-(j-1))%k] += 1 else: dic[(ruiseki[j-1]-(j-1))%k] = 1 if (ruiseki[j]-j)%k in dic: ans += dic[(ruiseki[j]-j)%k] print(ans)
0
null
103,401,153,663,548
218
273
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) P = list(map(int, readline().split())) cur = N + 1 ans = 0 for x in P: if cur > x: ans += 1 cur = x print(ans) if __name__ == '__main__': main()
A,B = map(str,input().split()) A = int(A) B = int(B[0])*100+int(B[2])*10+int(B[3]) print(int(A*B//100))
0
null
50,820,509,437,448
233
135
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp sample_input = list(range(3)) sample_input[0] = '''6 5 6 4 2 1 3''' sample_input[1] = '''6 5 2 4 6 1 3''' sample_input[2] = '''''' give_sample_input = None if give_sample_input is not None: sample_input_list = sample_input[give_sample_input].split('\n') def input(): return sample_input_list.pop(0) # main def swap_list_item(lst, i, j): tmp = lst[i] lst[i] = lst[j] lst[j] = tmp num_of_data = int(input()) data_list = list(map(int, input().split())) swap_count = 0 for i in range(num_of_data): minj = i for j in range(i, num_of_data): if data_list[minj] > data_list[j]: minj = j if not minj == i: swap_list_item(data_list, i, minj) swap_count += 1 result = '' for number in data_list: result += str(number) + ' ' print(result.strip()) print(swap_count)
a, b =map(int, input().split()) m = a*b lst = [] for i in range(1, b+1): if m < a*i: break lst.append(a*i) for j in lst: if j%b == 0: print(j) break
0
null
56,501,616,724,770
15
256
A,B,C,K = map(int,input().split()) koa = 0 if A<K: koa = A else : koa = K kob = 0 if B<K-koa: kob = B else : kob = K-koa #print (koa) #print (kob) sum = koa+0*kob+(K-(koa+kob))*-1 print (sum)
A,B,C,K = map(int,input().split()) if K-A > 0: if K-A-B > 0: print(A-(K-A-B)) else: print(A) else: print(K)
1
21,665,474,016,120
null
148
148
A,B,C,K = map(int,input().split()) if K-A > 0: if K-A-B > 0: print(A-(K-A-B)) else: print(A) else: print(K)
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): a, b, c, k = map(int, input().split()) r = min(k, a) k -= a if k > 0: k -= b if k > 0: r -= k print(r) if __name__ == '__main__': main()
1
21,857,474,429,660
null
148
148
a,b = map(int,input().split()) print("{0} {1} {2:.5f}".format((a//b),(a%b),(a/b)))
a,b = [float(i) for i in input().split()] d = int(a/b) r = int(a) % int(b) f = a/b f = "{:.9f}".format(f) print(d,r,f)
1
599,433,456,312
null
45
45
a, b, c, d = map(int, input().split()) while a > 0 and c > 0: a = a - d c = c - b if c <= 0: print('Yes') else: print('No')
from collections import Counter n, m = map(int, input().split()) group = [None for _ in range(n)] connected = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 connected[a].append(b) connected[b].append(a) # print(connected) for i in range(n): if group[i] is not None: continue newly_visited = [i] group[i] = i while len(newly_visited) > 0: new = newly_visited.pop() for j in connected[new]: if group[j] is not None: continue group[j] = i newly_visited.append(j) # print(Counter(group)) print(len(Counter(group)) - 1)
0
null
16,074,978,715,104
164
70
S = input() l = len(S) x = [0]*(l+1) y = [0]*(l+1) for i in range(l): if S[i] == "<": x[i+1] = x[i]+1 for i in range(l): if S[l-i-1] == ">": y[l-i-1] = y[l-i]+1 res = 0 for a, b in zip(x, y): res += max(a, b) print(res)
string = input() lt = True ans = 0 l_cnt = 0 m_cnt = 0 if string[0] == ">": lt = False for s in string: if s == "<": if not lt: a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt) ans += a * (a + 1) // 2 + b * (b - 1) // 2 l_cnt = m_cnt = 0 l_cnt += 1 lt = True else: m_cnt += 1 lt = False a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt) ans += a * (a + 1) // 2 + b * (b - 1) // 2 print(ans)
1
156,673,822,129,448
null
285
285
import math A, B = input().split() A = int(A) B = int(B.replace(".", "")) ans = (A * B) // 100 print(ans)
n = int(input()) s = input() total = 1 for c in 'RGB': total *= s.count(c) for i in range(1, n - 1): for j in range(1, min(i + 1, n - i)): if s[i] != s[i - j] and s[i - j] != s[i + j] and s[i] != s[i + j]: total -= 1 print(total)
0
null
26,395,261,938,764
135
175