code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
H = int(input()) def attack(h): if h == 1: return 0 r = 2 h //= 2 ans = 2 while h > 1: h //= 2 r *= 2 ans += r return ans print(1 + attack(H))
print(2**(len(bin(int(input())))-2)-1)
1
79,772,069,984,838
null
228
228
n,k=map(int,input().split()) A=list(map(int,input().split())) mod=10**9+7 count=k B,C=[],[] for i in A: if i<=0:B.append(i) else:C.append(i) B.sort(key=lambda x:abs(x)) C.sort() ans,flag=1,1 while k!=0: if k>=2: if len(B)>=2 and len(C)>=2: if B[-1]*B[-2]>C[-1]*C[-2]: ans *=B.pop()*B.pop() k -=2 else: ans *=C.pop() k -=1 elif len(B)>=2: ans *=B.pop()*B.pop() k -=2 elif len(C)>=2: ans *=C.pop()*C.pop() k -=2 else:flag=0;break else: if len(C)>0: ans *=C.pop() k -=1 else:flag=0;break ans %=mod if flag:print(ans) else: ans=1 A.sort(reverse=True) for i in range(count): ans *=A[i] ans %=mod print(ans)
def gcd(a, b): c = max([a, b]) d = min([a, b]) if c % d == 0: return d else: return gcd(d, c % d) nums = input().split() print(gcd(int(nums[0]), int(nums[1])))
0
null
4,717,802,827,900
112
11
n, d = list(map(int, input().split(' '))) res = 0 for _ in range(n): x, y = list(map(int, input().split(' '))) if d ** 2 >= (x ** 2) + (y ** 2): res += 1 print(res)
N, D = map(int, input().split()) result = 0 for i in range(N): a, b = map(int, input().split()) if a**2 + b**2 <= D**2: result += 1 print(result)
1
5,938,501,522,482
null
96
96
k = int(input()) hp = [i for i in range(k+4)] r, w = 1, 10 while w <= k: n = hp[r] r += 1 nm = n % 10 val = n * 10 + nm if nm != 0: hp[w] = val - 1 w += 1 hp[w] = val w += 1 if nm != 9: hp[w] = val + 1 w += 1 print(hp[k])
from collections import deque k = int(input()) num_deq = deque([i for i in range(1, 10)]) for i in range(k-1): x = num_deq.popleft() if x % 10 != 0: num_deq.append(10 * x + x % 10 - 1) num_deq.append(10 * x + x % 10) if x % 10 != 9: num_deq.append(10 * x + x % 10 + 1) x = num_deq.popleft() print(x)
1
39,997,378,363,894
null
181
181
N,K=map(int,input().split()) A = list(map(int,input().split())) count = 0 now = 1 city = [1] city2 = {1} while count < K: count += 1 now = A[now-1] if now in city2: break else: city.append(now) city2.add(now) if count == K: print(now) else: n = city.index(now) K -= n count -= n K %= count print(city[n+K])
import sys for i in sys.stdin: lst = i.split(' ') lst = map(int, lst) lst.sort() n = 1 maxn = 1 while n*n <= lst[0]: if lst[0]%n == 0 and lst[1]%(lst[0]/n) == 0: print lst[0]/n break elif lst[0]%n == 0 and lst[1]%n == 0: maxn = n n = n+1 else: print maxn sys.exit(0)
0
null
11,437,646,264,108
150
11
#!/usr/bin/python3 # main n = int(input()) - 1 fib = [1, 2] for i in range(2, n + 1): fib.append(fib[i - 1] + fib[i - 2]) print(fib[n])
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin def fibo(n): a, b = 1, 1 while n: a, b = b, a + b n -= 1 return a print(fibo(int(stdin.readline())))
1
1,906,061,222
null
7
7
import math A, B, C, D = map(int, input().split()) #何ターンで倒せるかを比較、ターン数が小さい方が強い。ターン数が同じなら高橋が勝ち。 if math.ceil(C / B) <= math.ceil(A / D): print("Yes") else: print("No")
A, B, C, D = map(int, input().split()) while True: C -= B if C < 1: print('Yes') quit() A -= D if A < 1: print('No') quit()
1
29,645,227,022,192
null
164
164
a = list(map(str, input().strip())) for i in range(0, len(a)): if a[i] == '?': a[i] = 'D' print(''.join(a))
word = input() start = 0 end = len(word) while(True): i = word.find('?', start, end) if (i == -1): break elif (i == (end-1)): word = word.replace('?', "D", 1) elif (word[i-1] == 'P'): word = word.replace('?', "D", 1) elif ((word[i+1] == "?") or (word[i+1] == "D")): word = word.replace('?', "P", 1) else: word = word.replace('?', "D", 1) start = i + 1 print(word)
1
18,432,280,243,388
null
140
140
n = int(input()) x = list(map(int,input().split())) x.sort() xmin = x[0] xmax = x[-1] ans = 10**9 for i in range(xmin, xmax+1): d = 0 for j in x: d += (j - i)**2 ans = min(ans, d) print(ans)
n = int(input()) A = list(map(int,input().split())) val1 = sum(A)//n val2 = val1+1 ans1 = 0 ans2 = 0 for a in A: ans1 += (a-val1)**2 ans2 += (a-val2)**2 print(min(ans1,ans2))
1
65,091,598,433,730
null
213
213
arr = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for i in range(int(input())): b,f,r,v = map(int, input().split()) arr[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): if k == 0: print ("", end=" ") if k == 9: print(arr[i][j][k]) else: print(arr[i][j][k], end=" ") if i != 3: print("#"*20)
H = int(input()) cnt = 0 while True: H //= 2 cnt += 1 if H == 0: break print(2**cnt-1)
0
null
40,505,830,732,512
55
228
from collections import OrderedDict import sys cnt = OrderedDict() for i in range(ord('a'), ord('z') + 1): cnt[chr(i)] = 0 S = sys.stdin.readlines() for s in S: s = s.lower() for i in s: if i in cnt: cnt[i] += 1 for k, v in cnt.items(): print('{} : {}'.format(k, v))
import sys import string s = sys.stdin.read().lower() for c in string.ascii_lowercase: print(c, ":", s.count(c))
1
1,637,193,308,552
null
63
63
f=lambda:map(int,input().split()) n,st,sa=f() g=[set() for _ in range(n)] for _ in range(n-1): a,b=f() g[a-1].add(b-1) g[b-1].add(a-1) def bfs(s): l=[-1]*n; l[s]=0; q=[s] while q: v=q.pop(); d=l[v]+1 for c in g[v]: if l[c]<0: l[c]=d; q+=[c] return l lt=bfs(st-1) la=bfs(sa-1) print(max(la[i] for i in range(n) if lt[i]<la[i])-1)
import math def main(): A, B, H, M = map(int, input().split()) h_angle = 30 * H + 0.5 * M if h_angle <= 90: h_angle = math.radians(90 - h_angle) else: h_angle = math.radians(360 - (h_angle - 90)) m_angle = 6 * M if m_angle <= 90: m_angle = math.radians(90 - m_angle) else: m_angle = math.radians(360 - (m_angle - 90)) h_x = A * math.cos(h_angle) h_y = A * math.sin(h_angle) m_x = B * math.cos(m_angle) m_y = B * math.sin(m_angle) print(math.sqrt(abs(h_x - m_x)**2 + abs(h_y - m_y)**2)) if __name__ == '__main__': main()
0
null
69,134,039,559,432
259
144
x1,y1,x2,y2 = map(float,input().split()) an = (x1 - x2)**2 + (y1 - y2)**2 dis = an/2 v = an/4 while abs(dis**2 - an) > 0.0001: if dis**2 > an: dis -= v else: dis += v v = v/2 print(dis)
import numpy as np H = int(input()) W = int(input()) N = int(input()) print(int(np.ceil(N/max(H,W))))
0
null
44,516,104,941,882
29
236
n = int(input()) L = list(map(int,input().split(' '))) L.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if L[i]==L[j]: continue if L[j]==L[k]: continue if L[i]+L[j] <= L[k]: continue ans+=1 print(ans)
def ifTriangle(v): largest = max(v) smallers_sum = 0 for x in v: if not x == largest: smallers_sum += x if smallers_sum > largest: return True return False N = int(input()) L = [int(x) for x in input().split()] L.sort() L.reverse() count = 0 before_i = -1 before_j = -1 before_k = -1 for i in range(N-2): for j in range(i+1, N-1): if L[j] == L[i]: continue if L[i]/2 >= L[j]: break for k in range(j+1, N): if L[k] == L[j]: continue if ifTriangle([L[i], L[j], L[k]]): count += 1 print(count)
1
5,041,162,545,220
null
91
91
n = int(input()) l = list(map(int, input().split())) l.sort() cnt = 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] and l[j]!=l[k] and l[k]!=l[i] and l[k]-l[j]<l[i]: cnt +=1 print(cnt)
import sys A, B, M = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] t = sys.maxsize for _ in range(M): x, y, c = [int(i) for i in input().split()] t = min(t, a[x - 1] + b[y - 1] - c) print(min(t, sorted(a)[0] + sorted(b)[0]))
0
null
29,314,705,674,968
91
200
from collections import deque H, W = list(map(int,input().split())) s = [] for i in range(H): s.append(input()) dx = [0, 1, -1, 0] dy = [1, 0, 0, -1] def bfs(sx, sy): q = deque([]) d = [[-1 for _ in range(W)] for _ in range(H)] q.append([sx, sy]) d[sx][sy] = 0 while(q): pop = q.popleft() x, y = pop[0], pop[1] for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx and nx < H and ny >= 0 and ny < W: if s[nx][ny] != "#" and d[nx][ny] == -1: q.append([nx, ny]) d[nx][ny] = d[x][y] + 1 return d def max_dim2(d): ret = 0 for i in range(len(d)): for j in d[i]: ret = max(ret, j) return ret ans = 0 for i in range(H): for j in range(W): if s[i][j] == ".": ret = bfs(i, j) temp = max_dim2(ret) ans = max(ans, temp) print(ans)
from collections import deque import copy H, W = map(int, input().split()) route = [] for _ in range(H): route.append(input()) wall = set() start = set() for y, r in enumerate(route): for x, w in enumerate(r): if w == '.': start.add((x, y)) score = -1 ssize = [(-1,0),(0,-1),(1,0),(0,1)] for xy in start: d = deque() d.append((xy+(0,))) step = 0 can = copy.deepcopy(start) can.remove(xy) while len(d) > 0: now = d.popleft() step = now[2] for xs, ys in ssize: nxt = (now[0]+xs, now[1]+ys) if nxt in can: d.append(nxt+(step+1,)) can.remove(nxt) score = max(step, score) print(score)
1
94,373,598,899,008
null
241
241
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=1000000007 #+++++ def modinv(a,m): b=m u=1 v=0 while b > 0: t = a //b a = a - (t * b) a,b = b,a u = u - (t * v) u,v=v,u u = u % m if u < 0: u+=m return u size_l=(10**5)+5 kaijoy=[1]*(size_l) inv = [0]*(size_l) pre=1 for i,v in enumerate(kaijoy[1:], 1): pre *= i pre %= mod kaijoy[i]=pre inv[-1] = modinv(kaijoy[-1], mod) pre = inv[-1] #print(pre*24) for i, v in enumerate(inv[1:],1): pre *= (size_l-i) pre %= mod inv[-i-1]=pre #print(kaijoy) #print(inv) #print([(v*s)%mod for v, s in zip(kaijoy, inv)]) def conv(n, k): if n < k: return 0 global kaijoy global inv ret = kaijoy[n] ret *= inv[n-k] ret *= inv[k] return ret def main(): # = int(input()) n, k = tin() #s = input() al = lin() al.sort() ret = 0 for i in range(n-k+1): d= (al[-i-1] - al[i])*conv(n-i-1, k-1) #pa((d,kaijoy[max(0,n-i-1)],inv[k-1])) ret += d ret %= mod return ret #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
def main(): n, x, t = map(int, input().split()) print(((n-1)//x+1)*t) main()
0
null
50,071,222,730,620
242
86
n = int(input()) A = list() for i in range(0, n): A.append(int(input())) G = [1] # G[0]????????¨????????? cnt = 0 # G[i] = 3*Gi-1 + 1 for i in range(1, 100): h = 4**i + 3*2**(i-1) + 1 if(h > n): # h???n?¶???????????????§?????????4n+3*2n-1+1 m = i break else: G.append(h) for g in reversed(G): 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 = j - g cnt += 1 A[j+g] = v print(m) print(" ".join(str(x) for x in reversed(G))) print(cnt) print("\n".join(str(x) for x in A))
n = int(input()) d = {} for i in range(n): s = str(input()) if s in d.keys(): d[s] += 1 else: d[s] = 1 max_count = max(d.values()) for i in sorted(d.keys()): if d[i] == max_count: print(i)
0
null
34,883,597,899,390
17
218
from sys import stdin for line in stdin: print(len(str(sum(map(int, line.split())))))
import sys from math import log10 for line in sys.stdin: a, b = map(int, line.split()) digitNumber = int(log10((a + b))) + 1 print(digitNumber)
1
108,137,140
null
3
3
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def inv(x): return pow(x, mod2 - 2, mod2) cms = 10**6 cm = [0] * cms def comb_init(): cm[0] = 1 for i in range(1, cms): cm[i] = cm[i-1] * i % mod2 def comb(a, b): return (cm[a] * inv(cm[a-b]) % mod2) * inv(cm[b]) % mod2 def main(): n,m,k = LI() comb_init() a = [0] * n a[0] = m for i in range(1,n): a[i] = a[i-1] * (m-1) % mod2 r = 0 for i in range(k+1): r += a[n-i-1] * comb(n-1, i) r %= mod2 return r print(main())
S = input() S_len = len(S) print("x" * S_len)
0
null
47,903,154,216,378
151
221
while True: l = input().split() h = int(l[0]) w = int(l[1]) if h == 0 and w ==0: break flag = 0 for i in range(h*(w+1)): if (i+1) % (w+1) == 0: print("") if w % 2 == 0: flag += 1 if i == h*(w+1)-1: print("") else: if flag % 2 == 0: print("#", end="") flag += 1 else: print(".", end="") flag += 1
N=int(input()) ans=[] while(1): if N==0: break tmp=N%26 if tmp==0: ans.append(26) N=N//26-1 else: N//=26 ans.append(tmp) new_ans = list(reversed(ans)) ANS="" for i in new_ans: ANS+=chr(96+int(i)) print(ANS)
0
null
6,436,726,239,148
51
121
class BiCoeff(object): def __init__(self, MAX, m): super(BiCoeff, self).__init__() fac = [0]*MAX finv = [0]*MAX inv = [0]*MAX fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2,MAX): fac[i] = (fac[i-1]*i)%m inv[i] = m - (inv[m%i] * (m//i))%m finv[i] = (finv[i-1] * inv[i])%m self.MAX = MAX self.m = m self.fac = fac self.finv = finv self.inv = inv def calc(self,n,k): if n<k: return 0 if n<0 or k<0: return 0 return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m mod = 10**9 + 7 k = int(input()) s = input() n = len(s) b = BiCoeff(n+k+10, mod) res = 0 for t in range(k+1): res += b.calc(n+k - (t+1), k-t)*pow(25,k-t,mod)*pow(26,t,mod) res %= mod print(res)
def main(): n,m,x = map(int,input().split()) c = [] a = [] for _ in range(n): ca = [int(v) for v in input().split()] c.append(ca[0]) a.append(ca[1:]) INTHIGH = 1<<32 pricemin = INTHIGH for i in range(1<<n): sm = [0]*m sc = 0 for j in range(n): if i & 1<<j: sc += c[j] for k in range(m): sm[k] += a[j][k] if min(sm)>=x: pricemin = min(pricemin, sc) break print(pricemin if pricemin<INTHIGH else -1) main()
0
null
17,618,934,946,168
124
149
N,K=map(int,input().split()) R,S,P=map(int,input().split()) L=input() T=[] for i in range(N): T.append(L[i]) for i in range(K,N): if T[i]==T[i-K]: T[i]="0" p=0 for i in T: if i=="r": p+=P elif i=="s": p+=R elif i=="p": p+=S print(p)
N,K = map(int,input().split()) R,S,P = map(int,input().split()) T = list(input()) for n in range(N-K): if T[n+K]==T[n]: T[n+K]="" print(P*T.count("r")+R*T.count("s")+S*T.count("p"))
1
107,323,168,308,220
null
251
251
import math from itertools import permutations N=int(input()) XYlist=[] indexlist=[i for i in range(N)] for _ in range(N): XYlist.append(tuple(map(int,input().split()))) ans=0 num=0 for indexes in permutations(indexlist,N): for i in range(N-1): ans+=math.sqrt((XYlist[indexes[i]][0]-XYlist[indexes[i+1]][0])**2+ (XYlist[indexes[i]][1]-XYlist[indexes[i+1]][1])**2) num+=1 print(ans/num)
# # # author : samars_diary # # 17-09-2020 │ 16:08:30 # # # import sys, os.path, math #if(os.path.exists('input.txt')): #sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def mod(): return 10**9+7 def i(): return sys.stdin.readline().strip() def ii(): return int(sys.stdin.readline()) def li(): return list(sys.stdin.readline().strip()) def mii(): return map(int, sys.stdin.readline().split()) def lii(): return list(map(int, sys.stdin.readline().strip().split())) #print=sys.stdout.write def solve(): n,d=mii();c=0 for _ in range(n): a,b=mii() if math.sqrt((a**2)+(b**2))<=d: c+=1 print(c) for _ in range(1): solve()
0
null
77,196,694,172,080
280
96
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)
def main(): n = int(input()) ans = 0 for i in range(1, n+1): tmp = n//i ans += i*tmp*(tmp+1)//2 print(ans) return if __name__ == "__main__": main()
0
null
5,600,668,966,740
17
118
N,K=map(int,input().split()) if N%K != 0: if abs(K-N%K)<N: print(K-N%K) else: print(N) else: print(0)
N = int(input()) S = input() ans = 0 for n in range(N-2): if S[n:n+3] == "ABC": ans += 1 print(ans)
0
null
69,142,846,577,518
180
245
N = int(input()) S = str(input()) s=list(S) num=0 for i in range(N-2): if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C': num+=1 print(num)
N = int(input()) print(input().count("ABC"))
1
99,441,347,924,522
null
245
245
n = int(input()) input_line = input().split() member = [int(input_line[i]) for i in range(n)] stands = 0 for i in range(1,n): stand = member[i-1] - member[i] if stand > 0: stands += stand member[i] += stand print(stands)
import sys n=int(input()) li=[int(x) for x in input().split()] h=0 k=0 for i in range(n): if h<=li[i]: h=max(h,li[i]) else: k=k+(h-li[i]) h=max(h,li[i]) print(k)
1
4,519,429,049,870
null
88
88
a,b,c = sorted(map(int,raw_input().split())) print a,b,c
N = int(input()) S = input() ans = [S[0]] for i in range(1, N): if S[i]==ans[-1]: continue else: ans.append(S[i]) print(len(ans))
0
null
85,085,889,955,962
40
293
def main(): n = int(input()) s = input() ans = 0 for i in range(n): if i == 0: ans += 1 mae = s[i] else: if s[i] != mae: ans += 1 mae = s[i] print(ans) if __name__ == "__main__": main()
import sys, math import bisect sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def isPrime(n): if n < 2: return False i = 2 while i*i <= n: if n%i==0: return False i += 1 return True def main(): l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = ii() print(l[K-1]) if __name__ == '__main__': main()
0
null
109,984,601,468,830
293
195
n, k, c = map(int, input().split()) s = input() s2 = s[::-1] dp1 = [0] * (n + 2) dp2 = [0] * (n + 2) for (dp, ss) in zip([dp1, dp2], [s, s2]): for i in range(n): if ss[i] == 'x': dp[i+1] = dp[i] elif i <= c: dp[i+1] = min(1, dp[i] + 1) else: dp[i+1] = max(dp[i-c] + 1, dp[i]) dp2 = dp2[::-1] for i in range(1, n+1): if s[i-1] == 'o' and dp1[i-1] + dp2[i+1] < k: print(i)
N, M = map(int, input().split()) for i in range((M + 1) // 2): print(i + 1, i + (M - 2 * i) + 1) for i in range(M - (M + 1) // 2): print(M + 1 + i + 1, M + 1 + i + (M - 1 - 2 * i) + 1)
0
null
34,773,069,950,460
182
162
s=input() count=0 list_s=list(s) if(list_s[2]==list_s[3] and list_s[4]==list_s[5]): print("Yes") else: print("No")
string = input() if string[2] == string[3] and string[4] == string[5]: print("Yes") else: print("No")
1
42,140,642,934,560
null
184
184
k=int(input()) q=["1","2","3","4","5","6","7","8","9"] x=9 for i in q: if x>100000: break x+=1 a=i[-1] for j in ([-1,0,1]): bb=int(a)+j if bb<10 and bb>=0: q.append(i+str(bb)) print(q[k-1])
from collections import deque k=int(input()) d=deque() for i in range(1,10): d.append(i) for i in range(k-1): x=d.popleft() if x%10!=0: d.append(10*x+(x%10)-1) d.append(10*x+(x%10)) if x%10!=9: d.append(10*x+(x%10)+1) print(d.popleft())
1
39,988,331,912,000
null
181
181
def solve(): N, K = list(map(int, input().split())) if(N >= K): tmp = N - ((N // K) * K) ans = min(tmp, abs(abs(tmp) - K)) elif(N < K): if(K <= 2*N): ans = abs(N - K) else: ans = abs(N) print(ans) if __name__ == "__main__": solve()
n,m=map(int,input().split()) C=list(map(int,input().split())) dp=[[float('inf')]*(n+1) for i in range(m+1)] for i in range(m+1): dp[i][0]=0 for i in range(1,m+1): c=C[i-1] for j in range(1,n+1): dp[i][j]=dp[i-1][j] if j>=c: dp[i][j]=min(dp[i][j],dp[i-1][j-c]+1,dp[i][j-c]+1) print(dp[m][n])
0
null
19,631,743,531,500
180
28
import math x1,y1,x2,y2=(float(x) for x in input().split()) print('{:.05f}'.format(math.sqrt((x2-x1)**2+(y2-y1)**2)))
while True: n,x=map(int,input().split()) a=0 if n==0 and x==0:break for i in range(1,n+1): for j in range(1,i): for k in range(1,j): if i+j+k==x:a+=1 print(a)
0
null
720,793,392,032
29
58
results = [] while True: cards = input() if cards == '-': break for i in range(int(input())): n = int(input()) cards = cards[n:] + cards[:n] results.append(cards) for line in results: print(line)
import math a,b,x=map(int,input().split()) v = a * b x = x / a if x < v/2: c = x * 2 / b d = math.sqrt(b * b + c * c) print(math.degrees(math.asin(b/d))) else: rest = v - x c = rest * 2 / a d = math.sqrt(a * a + c * c) print(math.degrees(math.acos(a/d)))
0
null
82,631,960,930,332
66
289
day = ["SUN","MON","TUE","WED","THU","FRI","SAT" ] s = input() pos = day.index(s) print(7-pos)
s=input() dict1={7:'SUN',6:'MON',5:'TUE',4:'WED',3:'THU',2:'FRI',1:'SAT'} keys = [k for k, v in dict1.items() if v == s] print(keys[0])
1
133,146,139,101,980
null
270
270
import string s = raw_input() print string.swapcase(s)
n=raw_input() a='' for i in n: if i.islower():a+=i.upper() else:a+=i.lower() print a
1
1,518,851,486,234
null
61
61
# coding: utf-8 def main(): N = int(input()) tmp = 200001 ans = 0 A = list(map(int, input().split())) for a in A: if a < tmp: ans += 1 tmp = a print(ans) if __name__ == "__main__": main()
n = int(input()) t = list(map(int,input().split())) a = min(t) b = max(t) c = sum(t) print(str(a),str(b),str(c))
0
null
42,982,412,689,152
233
48
val = input() print(val*val)
def resolve(): N, K = list(map(int, input().split())) A = list(map(lambda x: int(x)-1, input().split())) routes = [0] current = 0 visited = [False for _ in range(N)] visited[0] = True while visited[A[current]] is False: current = A[current] routes.append(current) visited[current] = True leftlen = routes.index(A[current]) repeat = routes[leftlen:] # print(leftlen) # print(routes) # print(repeat) print(repeat[(K-leftlen)%len(repeat)]+1 if K > leftlen else routes[K]+1) if '__main__' == __name__: resolve()
0
null
84,072,624,999,468
278
150
N, K = map(int, input().split()) P = tuple(map(int, input().split())) PMAX = 1000 s = [0] * (PMAX + 1) for i in range(PMAX): s[i+1] = s[i] + (i + 1) e = [0] * (N + 1) for i, p in enumerate(P): e[i+1] = e[i] + (s[p] / p) ans = 0 for i in range(N - K + 1): ans = max(ans, e[i+K] - e[i]) print(ans)
n,k=[int(i) for i in input().split()] p=[(int(i)+1)/2 for i in input().split()] ans=0 sum_num=sum(p[:k]) for i in range(n-k+1): if i==0: sum_num = sum(p[:k]) else: sum_num+=p[i+k-1]-p[i-1] ans=max(ans,sum_num) print(ans)
1
75,100,137,652,472
null
223
223
from random import choice class dice: def __init__(self, X): self.x = [0] * 6 self.x[0] = X[0] self.x[1] = X[1] self.x[2] = X[2] self.x[3] = X[3] self.x[4] = X[4] self.x[5] = X[5] def roll(self, d): if d == 'S': self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \ self.x[4], self.x[0], self.x[2], self.x[3], self.x[5], self.x[1] elif d == 'E': self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \ self.x[3], self.x[1], self.x[0], self.x[5], self.x[4], self.x[2] elif d == 'W': self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \ self.x[2], self.x[1], self.x[5], self.x[0], self.x[4], self.x[3] elif d == 'N': self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \ self.x[1], self.x[5], self.x[2], self.x[3], self.x[0], self.x[4] X = list(map(int, input().split())) n = int(input()) dice1 = dice(X) distances = ['S', 'E', 'W', 'N'] for i in range(n): x1, x2 = map(int, input().split()) while True: d = choice(distances) dice1.roll(d) if dice1.x[0] == x1 and dice1.x[1] == x2: print(dice1.x[2]) break
import sys def input(): return sys.stdin.readline().strip() def resolve(): n,a,b=map(int, input().split()) if (abs(a-b))%2==0: print((abs(a-b))//2) else: ue=max(a,b)-1 sita=n-min(a,b) hokasita=((n-max(a,b))*2+1+abs(b-a))//2 hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2 print(min(ue,sita,hokasita,hokaue)) resolve()
0
null
54,957,048,809,052
34
253
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k = list(map(int, input().split())) a = list(map(int, input().split())) def cumsum(a): """※ aを破壊する l[i] = sum(a[:i]) なるlを返す sum(a[i:j]) == l[j+1] - l[i] """ c = 0 n = len(a) a.insert(0, 0) for i in range(1, n+1): a[i] = a[i-1]+a[i] return a a = cumsum(a) aa = [((item - i)%k) for i,item in enumerate(a)] ans = 0 from collections import defaultdict c = defaultdict(int) for i in range(min(k, len(aa))): c[aa[i]] += 1 for i,item in enumerate(aa): c[item] -= 1 # print(c, item) ans += c[item] if i+k<n+1: c[aa[i+k]] += 1 print(ans)
from collections import defaultdict N, K, *A = map(int, open(0).read().split()) x = [0] * (N + 1) for i in range(N): x[i + 1] = x[i] + A[i] y = [(x[i] - i) % K for i in range(N + 1)] ctr = defaultdict(int) ans = 0 for j in range(N + 1): ans += ctr[y[j]] ctr[y[j]] += 1 if j - K + 1 >= 0: ctr[y[j - K + 1]] -= 1 print(ans)
1
137,137,214,511,040
null
273
273
import copy def inputInline(): N = int(input()) cards = input().split(" ") return cards def selectionSort(list): cards=copy.deepcopy(list) n = len(cards) count = 0 for i in range(n): min_j = i for j in range(i + 1, n): if int(cards[j][1]) < int(cards[min_j][1]): min_j = j if min_j != i: temp = cards[i] cards[i] = cards[min_j] cards[min_j] = temp count += 1 return (" ".join(cards), count) def bubbleSort(list): cards=copy.deepcopy(list) N = len(cards) count = 0 flag = True while flag: flag = False for i in range(N - 1): if int(cards[i][1]) > int(cards[i + 1][1]): temp = cards[i] cards[i] = cards[i + 1] cards[i + 1] = temp flag = True count += 1 return (" ".join(cards), count) cards=inputInline() sortedbubble=bubbleSort(cards)[0] sortedselection=selectionSort(cards)[0] print(sortedbubble) print("Stable") print(sortedselection) if sortedbubble==sortedselection: print("Stable") else: print("Not stable")
def main(): INF = 10 ** 18 N = int(input()) A = list(map(int, input().split(' '))) K = 1 + N % 2 # 余分な×を入れられる個数 # dp[i][j]: i個目までの要素で余分な×をj個使った際の最大値 dp = [[- INF for _ in range(K + 1)] for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): for j in range(K + 1): if j < K: # 余分な×を使う場合 dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]) # 余分な×を使わない場合 now = dp[i][j] if (i + j) % 2 == 0: # 基本はi % 2 == 0の時にA[i]を足していく # ただ、余分な×がj個入っていると、その分ずれる now += A[i] dp[i + 1][j] = max(dp[i + 1][j], now) print(dp[N][K]) if __name__ == '__main__': main()
0
null
18,850,634,444,868
16
177
a, b, k = map(int, input().split()) print(min(a, max(a-k, 0)), min(b, max(b-k+a, 0)))
input_line = list(map(int,input().split(' '))) if(input_line[0]>=input_line[2]): input_line[0] -= input_line[2] elif((input_line[0]+input_line[1])>=input_line[2]): input_line[1] -= (input_line[2]-input_line[0]) input_line[0] = 0 else: input_line[0] = 0 input_line[1] = 0 print(input_line[0],input_line[1])
1
104,317,274,586,862
null
249
249
N=int(input()) A=list(map(int,input().split())) for i in range(N): A[i]=[A[i],i] A.sort() for i in range(N): print(A[i][1]+1,end=' ') print()
import numpy as np import sys i4 = np.int32 i8 = np.int64 u4 = np.uint32 if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC from numba import njit from numba.types import int64, Array, uint32 cc = CC('my_module') @cc.export('factorization', (uint32, )) @njit def factorization(N): p = np.zeros(N + 1, u4) n_max = int(np.sqrt(N)) + 1 p[0] = 1 p[1] = 1 for i in range(2, n_max): if p[i] == 0: j = i while j <= N: p[j] = i j += i for i in range(n_max, N + 1): if p[i] == 0: p[i] = i return p @cc.export('solve', (Array(uint32, 1, 'C'),)) def solve(A): a = np.sort(A) p_max = a[-1] p = factorization(p_max) primes_num = 0 for i in range(p.shape[0]): if i == p[i]: primes_num += 1 a_start = 0 while a[a_start] == 1: a_start += 1 if a_start == a.shape[0]: return 0 a = a[a_start:] if len(a) > primes_num: return 1 check = np.zeros(p_max + 1, u4) stack = np.empty(20, u4) p_stack = 0 for d in a: while d > 1: x = p[d] for i in range(p_stack): if stack[i] == x: break else: stack[p_stack] = x p_stack += 1 d //= x while p_stack > 0: p_stack -= 1 check[stack[p_stack]] += 1 if check.max() > 1: return 1 else: return 0 cc.compile() from my_module import solve, factorization exit() from my_module import solve, factorization def main(in_file): stdin = open(in_file) stdin.readline() A = np.fromstring(stdin.readline(), u4, sep=' ') ans = solve(A) if ans: g = np.gcd.reduce(A) if g > 1: ans = 2 else: ans = 1 p = ['pairwise coprime', 'setwise coprime', 'not coprime'] print(p[ans]) if __name__ == '__main__': main('/dev/stdin')
0
null
92,063,329,391,868
299
85
n = int(input()) i, j = int(input()), 0 nmin = i a = -2 * 10 ** 9 for h in range(n - 1): j = int(input()) a = max(a, j - nmin) if j < nmin: nmin = j print(a)
L = int(input()) r = (L/3)**3 print(r)
0
null
23,441,978,047,228
13
191
ABC = list(map(int, input().split())) if len(set(ABC)) == 2: print('Yes') else: print('No')
score = list(map(int,input().split())) if score[0] == score[1] and score[0] != score[2]: print('Yes') elif score[1] == score[2] and score[0] != score[2]: print('Yes') elif score[2] == score[0] and score[1] != score[2]: print('Yes') else: print('No')
1
67,794,809,565,418
null
216
216
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 6) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") al = "abcdefghijklmnopqrstuvwxyz" AL = al.upper() n, k=I() h = l() h.sort(reverse=True) print(sum(h[k:]))
# -*- config: utf-8 -*- if __name__ == '__main__': for i in range(int(raw_input())): nums = map(lambda x:x**2,map(int,raw_input().split())) nums.sort() if nums[0]+nums[1] == nums[2]: print "YES" else : print "NO"
0
null
39,488,189,954,240
227
4
def sell(rate, kabu): return rate * kabu def buy(rate, money): kabu = money//rate otsuri = money % rate return kabu, otsuri N,*A = map(int, open(0).read().split()) money = 1000 have_kabu = 0 for i in range(N): #売る money += sell(A[i], have_kabu) have_kabu = 0 #買う if i != N-1 and A[i] < A[i+1]: have_kabu, money = buy(A[i], money) print(money)
n = int(input()) arr = list(map(int,input().split())) cur=1000 for i in range(n-1): p=0 if arr[i] < arr[i+1]: p=cur // arr[i] cur += (arr[i+1] - arr[i])*p print(cur)
1
7,240,697,328,430
null
103
103
s,t = input().split() a,b = (int(x) for x in input().split()) u = input() if u == s: print(a - 1,b) else: print(a,b - 1)
S, T = input().split() A, B = map(int, input().split()) U = input() ans = {S: A, T: B} ans[U] -= 1 print(ans[S], ans[T])
1
71,818,511,446,460
null
220
220
x,y = map(int,input().split()) def solve(x,y): legs = x * 2 while(legs <= x * 4): if legs == y: print('Yes') return legs += 2 print('No') return solve(x,y)
N = int(input()) if N%2==1: ans = 0 else: n = N//10 ans = n k = 1 while 5**k<=n: ans += n//(5**k) k += 1 print(ans)
0
null
64,860,417,517,620
127
258
def main(): MOD = 998244353 N, S = list(map(int, input().split())) A = list(map(int, input().split())) dp = [[0] * (S + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, a in enumerate(A): n = i + 1 for s in range(S + 1): dp[n][s] += 2 * dp[n - 1][s] if s - a >= 0: dp[n][s] += dp[n - 1][s - a] dp[n][s] %= MOD print(dp[N][S]) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=998244353 N,S=MI() A=LI() dp=[[0]*(S+1) for _ in range(N+1)] #dp[i][j]はi番目までで,和がjになるのが何個作れるか. #ただし,その数を使わない場合,選択するかしないか選べるのでダブルでカウント dp[0][0]=1 for i in range(N): #dp[i][0]+=1 for j in range(S+1): dp[i+1][j]+=dp[i][j]*2 dp[i+1][j]%=mod if j+A[i]<=S: dp[i+1][j+A[i]]+=dp[i][j] dp[i+1][j+A[i]]%=mod print(dp[-1][-1]) main()
1
17,783,237,993,522
null
138
138
S = input() Q = int(input()) q = [] for i in range(Q): a = input().split(" ") if len(a) == 1: q.append([int(a[0])]) else: q.append([int(a[0]), int(a[1]), a[2]]) #print(S) #print(q) def switch(s): d = "" for i in range(len(s)): d += s[len(s) - i - 1] return d H = "" B = "" direction = 1 #通常の向き -1:反対方向 for t in range(len(q)): T = q[t] if T[0] == 1: direction *= -1 else: F = T[1] C = T[2] if F == 1: if direction == 1: H += C else: B += C else: if direction == 1: B += C else: H += C if direction == 1: print(switch(H) + S + B) else: print(switch(B) + switch(S) + H)
print('NYoe s'['7'in [*input()]::2])
0
null
45,676,693,905,382
204
172
from sys import stdin import math inp = lambda : stdin.readline().strip() s = inp() if s[2] == s[3] and s[4] == s[5]: print("Yes") else: print("No")
# ABC160 # A Coffee s = input() if s[2] == s[3]: if s[4] == s[5]: print('Yes') exit() print("No")
1
42,081,160,053,412
null
184
184
import copy def bit_list(x: int, n: int) -> list: ''' xのn乗のbit配列を返す ''' ans = [] for i in range(x ** n): num = i j = 0 table = [0 for _ in range(n)] while num: table[j] = num % x num = num // x j += 1 ans.append(table) return ans H, W, K = map(int, input().split()) M = [list(input()) for _ in range(H)] ans = 0 bits = bit_list(2, H + W) for bit in bits: tmp_M = copy.deepcopy(M) for i in range(H + W): if i < H and bit[i] == 1: for j in range(W): tmp_M[i][j] = "R" if i >= H and bit[i] == 1: for j in range(H): tmp_M[j][i - H] = "R" count = 0 for i in range(H): for j in range(W): if tmp_M[i][j] == '#': count += 1 if count == K: ans += 1 print(ans)
from sys import stdin input = stdin.readline def solve(): Y, X, K = map(int, input().split()) c = [inp for inp in stdin.read().splitlines()] res = 0 for ymask in range((1<<Y) - 1): for xmask in range((1<<X) - 1): cnt = 0 for y in range(Y): for x in range(X): if ymask & (1<<y) == 0 and xmask & (1<<x) == 0 and c[y][x] == '#': cnt += 1 if cnt == K: res +=1 print(res) if __name__ == '__main__': solve()
1
8,890,650,746,080
null
110
110
n = int(input()) x = list(map(int, input().split())) sum= 1000000000000000 for p in range(1,101): tmp=0 # print("p",p) for i in range(len(x)): tmp += (x[i] - p)**2 # print("tmp",tmp) sum = min(sum,tmp) # print("su",sum) print(sum)
S=input() T=input() total=0 for i in range(0,len(S)): if S[i]!=T[i]: total+=1 print(int(total))
0
null
37,691,386,731,840
213
116
N=int(input()) P=list(map(int,input().split())) x=N+1 cnt=0 for i in range(N): if P[i]<x: cnt+=1 x=P[i] print(cnt)
n=int(input()) a=list(map(int, input().split())) mi = n+2 ans = 0 for i in a: if mi > i: ans+=1 mi=min(i,mi) print(ans)
1
85,156,283,471,606
null
233
233
import sys input = sys.stdin.readline import bisect import math # 持っているビスケットを叩き、1枚増やす # ビスケット A枚を 1円に交換する # 1円をビスケット B枚に交換する def main(): a, b, n = input_list() x = min(b-1, n) aa = math.floor((a*x)/b) - (a * math.floor(x/b)) print(aa) def bi(num, a, b, x): print((a * num) + (b * len(str(b)))) if (a * num) + (b * len(str(b))) <= x: return False return True def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
nn = [0] + list(map(int, list(input()))) dp0, dp1 = 0, 0 for i in range(len(nn)): dp0, dp1 = nn[i] + min(dp1, dp0), 9 - nn[i] + min(dp1, dp0 + 2) print(min(dp0, dp1))
0
null
49,303,170,613,632
161
219
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect import functools @functools.lru_cache(None) def dfs(i,sum_v,val): if i == n: return sum_v == val if dfs(i+1,sum_v,val): return True if dfs(i+1,sum_v + A[i],val): return True return False n = int(input()) A = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) for i in range(q): if dfs(0,0,m[i]): print("yes") else: print("no")
from collections import defaultdict N, *A = map(int, open(0).read().split()) ctr1 = defaultdict(int) ctr2 = defaultdict(int) for i in range(N): ctr2[i + A[i]] += 1 if i - A[i] > 0: ctr1[i - A[i]] += 1 ans = 0 for v in ctr1: ans += ctr1[v] * ctr2[v] print(ans)
0
null
13,106,899,363,700
25
157
def main(): k,n = map(int, input().split()) s = list(map(int, input().split())) l = [] for i in range(n): if i == 0: l.append(k - (s[-1] - s[0])) else: a = s[i] - s[i-1] l.append(a) print(k - max(l)) if __name__ == '__main__': main()
N = int(input()) A = list(map(int, input().split())) m = 1000000007 result = 1 t = [0, 0, 0] for i in range(N): a = A[i] f = -1 k = 0 for j in range(3): if t[j] == a: k += 1 if f == -1: t[j] += 1 f = j result *= k result %= m print(result)
0
null
86,675,496,548,562
186
268
T = input() T_l = [t for t in T] for i in range(len(T_l)): if T[i] =="?": T_l[i] = "D" print("".join(T_l))
l,r,f = map(int,input().split()) count = 0 for i in range(l,r+1): if i % f == 0 : count = count + 1 print(count)
0
null
13,029,180,601,490
140
104
S = input() count = 0 if S[2] == S[3]: count+=1 if S[4] == S[5]: count+=1 if count == 2: print('Yes') else: print('No')
INF = 1 << 60 n = int(input()) x = [0 for i in range(n)] l = [0 for i in range(n)] for i in range(n): x[i], l[i] = map(int, input().split()) itv = [[x[i] - l[i], x[i] + l[i]] for i in range(n)] itv.sort(key=lambda x:x[1]) # print("itv =", itv) ans = 0 t = -INF for i in range(n): if t <= itv[i][0]: ans += 1 t = itv[i][1] print(ans)
0
null
65,686,410,311,808
184
237
N = int(input()) x = [] for _ in range(N): s = input() x.append(s) print('AC'+ ' '+ 'x'+ ' '+str(x.count('AC'))) print('WA'+ ' '+ 'x'+ ' '+str(x.count('WA'))) print('TLE'+ ' '+ 'x'+ ' '+str(x.count('TLE'))) print('RE'+ ' '+ 'x'+ ' '+str(x.count('RE')))
MAXN = 45 fibs = [-1] * MAXN def fib(n): """Returns n-th fibonacci number >>> fib(3) 3 >>> fib(10) 89 >>> fib(20) 10946 """ if n == 0: return 1 elif n == 1: return 1 elif fibs[n] == -1: fibs[n] = fib(n-1) + fib(n-2) return fibs[n] def run(): n = int(input()) print(fib(n)) if __name__ == '__main__': run()
0
null
4,386,843,511,908
109
7
word = input().lower() text = [] c = 0 while True: read = input().split() if read[0] == 'END_OF_TEXT': break else: text.append(read) for i in text: for n in i: if word == n.lower(): c += 1 print(c)
while True: numbers = list(map(int,input())) if numbers[0] == 0: break print(sum(numbers))
0
null
1,694,886,498,892
65
62
S = int(input()) dp = [0 for _ in range(S+1)] dp[0] = 1 MOD = 10**9+7 for i in range(3,S+1): dp[i] = dp[i-1]+dp[i-3] print(dp[S]%MOD)
mod=1000000007 dp=[1]*2001 for i in range(3,2001): for j in range(i+3,2001): dp[j]=(dp[j]+dp[i])%mod n=int(input()) if n<3:print(0) else:print(dp[n])
1
3,257,804,366,124
null
79
79
nm = raw_input().split() n = int(nm[0]) m = int(nm[1]) d = raw_input().split() c = [0] * 100000 c[0] = 0 for i in range(n): min = 100000 for j in range(m): if int(d[j]) < i + 2: x = c[i + 1 - int(d[j])] if x < min: min = x c[i + 1] = min + 1 print c[n]
n,m=map(int,input().split()) c=list(map(int,input().split())) dp=[[10001]*m for i in range(n)] #dp[value][i_coin] dp.insert(0,[0]*m) for i in range(m): for v in range(1,n+1): if i==0: dp[v][i]=v//c[i] if v%c[i]==0 else 10001 continue if v<c[i]: dp[v][i]=dp[v][i-1] else: dp[v][i]=min(dp[v][i-1],dp[v-c[i]][i]+1) print(dp[n][m-1])
1
141,269,248,020
null
28
28
i=1 while i<=9: j=1 while j<=9: print '%d%s%d%s%d'%(i,"x",j,"=",i*j) j=j+1 i=i+1
import itertools def actual(n, D): """ combinations でゴリ押し """ comb = itertools.combinations(D, 2) # return sum([x * y for x, y in comb]) """ 「順番を考慮しない2要素の選び方」を全探索する際のポイント 内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。 これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、 同じ選び方を 2 回見てしまうことを回避できます。 """ # s = 0 # for i in range(len(D)): # for j in range(i + 1, len(D)): # s += D[i] * D[j] # # return s """ O(N)で解くパターン ex: a, b, c, d a*b + a*c + a*d = a * (b + c +d) b*c + b*d = b * ( c +d) c*d = c * ( d) """ s = 0 for i in range(len(D) - 1): s += D[i] * sum(D[i + 1:]) return s n = int(input()) D = list(map(int, input().split())) print(actual(n, D))
0
null
84,171,637,184,970
1
292
n = int(input()) string = input() ans = 0 for i in range(0, n-2): if string[i] == "A" and string[i+1] == "B" and string[i+2] == "C": ans += 1 print(ans)
import math R = float(input()) print(float(2*R*math.pi))
0
null
65,147,989,886,288
245
167
x = int(input()) if x < 30: print('No') else: print('Yes')
x=input() x=int(x) if x>=30: print('Yes') else: print("No")
1
5,777,005,629,122
null
95
95
import random import time def search(day, schedule, c, s, satisfy): score = 0 date = [0] * 26 for d in range(day): tmp = 0 contest = 0 nmax = -float('inf') for i in range(26): tmp += c[i] * (d + 1 - date[i]) for i in range(26): tmp2 = s[d][i] - tmp + c[i] * (d + 1 - date[i]) if nmax < tmp2: nmax = tmp2 contest = i date[contest] = d + 1 satisfy.append(tmp - c[contest] * (d + 1 - date[contest])) schedule.append(contest) score += s[d][contest] - satisfy[d] return score # def decrease(day, schedule, c, s, satisfy): # ret = 0 # date = [0] * 26 # for d in range(day): # now = schedule[d] + 1 # date[now - 1] = d + 1 # tmp = 0 # for i in range(26): # tmp += c[i] * (d+1 - date[i]) # ret += tmp # satisfy.append(tmp) # return ret def change(_from, _to, schedule, c, s, satisfy): ret = 0 date = [0] * 26 for d in range(_to): if d < _from-1: ret += satisfy[d] continue now = schedule[d] + 1 date[now - 1] = d + 1 tmp = 0 for i in range(26): tmp += c[i] * (d+1 - date[i]) ret += tmp satisfy[d] = tmp return ret def Main(): D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] dissatisfy=[] schedule = [] score = 0 start = time.time() #最大値を足すだけ # for i in range(D): # schedule.append(np.argmax(s[i])) # score += np.max(s[i]) ans = search(D, schedule, c, s, dissatisfy) for i in range(D): score+=s[i][schedule[i]] while time.time() - start < 1.8: contest = random.randint(0, 25) day = random.randint(0, D - 1) if schedule[day] == contest: continue save = dissatisfy.copy() dec2 = change(day + 1, D, schedule, c, s, dissatisfy) score2 = score - s[day][schedule[day]] + s[day][contest] if ans < score2 - dec2: ans = score2 - dec2 score = score2 schedule[day] = contest else: dissatisfy = save for i in range(D): print(schedule[i] + 1) if __name__ == "__main__": Main()
n=raw_input() k=n.split() k.sort() print k[0], print k[1], print k[2]
0
null
5,049,660,684,640
113
40
N = int(input()) S = list(input()) check = S[0] count =1 for i in range(1,N): if(check!=S[i]): check=S[i] count +=1 print(count)
n = int(input()) s = list(input()) cnt = 1 for i in range(n-1): if s[i]!=s[i+1]: cnt += 1 print(cnt)
1
170,310,012,214,020
null
293
293
from math import gcd mod = 1000000007 n = int(input()) zero = 0 bad = {} for i in range(n): x, y = map(int, input().split()) if x == 0 and y == 0: zero += 1 continue g = gcd(x, y) x //= g y //= g if y < 0: x, y = -x, -y if y==0 and x<0: x, y = -x, -y is_rotate90 = (x <= 0) if is_rotate90: x, y = y, x y = -y if not (x, y) in bad: bad[x, y] = [0, 0] if is_rotate90: bad[x, y][0] += 1 else: bad[x, y][1] += 1 # print(bad) cnt = 1 for x, y in bad: c1, c2 = bad[x, y] c3 = 1 c3 += pow(2, c1, mod) - 1 c3 += pow(2, c2, mod) - 1 cnt = cnt * c3 % mod ans = (cnt + zero - 1) % mod # print('cnt',cnt) # print('zero',zero) # print('ans',ans) print((ans+mod) % mod)
import math def main(): mod = 1000000007 N = int(input()) A = [0] B = [0] for n in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) calc = dict() non_count = 0 for i in range(1, N + 1): if A[i] == 0 and B[i] == 0: non_count += 1 elif A[i] == 0: k = (0, 1) if calc.get(k): calc[k][0] += 1 else: calc[k] = [1, 0] elif B[i] == 0: k = (0, 1) if calc.get(k): calc[k][1] += 1 else: calc[k] = [0, 1] else: r = math.gcd(A[i], B[i]) m = 1 if A[i] * B[i] < 0: m = -1 k1 = (m * abs(A[i] // r), abs(B[i] // r)) k2 = (-m * abs(B[i] // r), abs(A[i] // r)) if calc.get(k1): calc[k1][0] += 1 elif not calc.get(k2): calc[k1] = [1, 0] else: calc[k2][1] += 1 N = N - non_count count = 0 for k, v in calc.items(): if not v[0] * v[1] == 0: count += v[0] + v[1] ans = pow(2, N - count, mod) for k, v in calc.items(): if not v[0] * v[1] == 0: comb = (pow(2, v[0]) + pow(2, v[1]) - 1) ans = (ans * comb) % mod print((ans - 1 + non_count) % mod) if __name__ == '__main__': main()
1
20,966,732,190,700
null
146
146
N,K,S = map(int,input().split()) A = [10**9]*N if S != 10**9: for i in range(K): A[i] = S else: for i in range(N-K): A[i] = 10**9-1 print(*A)
s=input() q=int(input()) flag=0 t=['' for _ in range(2)] cnt=0 for _ in range(q): a=list(input().split()) if a[0]=='1': flag=1-flag cnt+=1 else: if a[1]=='1':t[flag]+=a[2] else:t[1-flag]+=a[2] ans=t[0][::-1]+s+t[1] if cnt%2:ans=ans[::-1] print(ans)
0
null
74,139,361,471,058
238
204
S=input() S=str(S) print(S[0]+S[1]+S[2])
from collections import defaultdict facts = defaultdict(int) mod=10**9+7 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n=int(input()) a=[int(i) for i in input().split()] for i in range(n): for b,p in factorization(a[i]): if facts[b]<p: facts[b]=p ans=0 f=1 for k,v in facts.items(): f*=pow(k,v,mod) f%=mod for i in range(n): ans+=f*pow(a[i],mod-2,mod) ans%=mod print(ans)
0
null
51,178,588,768,570
130
235
S = input() youbi = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'] print(youbi.index(S) + 1)
k=int(input()) a="1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" list=a.split(',') print(list[k-1])
0
null
91,291,554,382,390
270
195
billdings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)] def printstate(billdings): """ for billnum, billding in enumerate(billdings): for flooor in billding: for room in flooor: print(" {}".format(room), end="") print() print("#"*20 if billnum != len(billdings)-1 else "") """ for i in range(len(billdings)): for j in range(len(billdings[0])): for k in range(len(billdings[0][0])): print(" "+str(billdings[i][j][k]), end="") print() if i != len(billdings)-1: print("#"*20) n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) b, f, r = b-1, f-1, r-1 billdings[b][f][r] += v printstate(billdings)
n = int(input()) for i in range(1,n+1): if i % 3 == 0 or i % 10 == 3: print(" {}".format(i), end='') else: x = i while True: x = x // 10 if x == 0: break elif x % 10 == 3: print(" {}".format(i), end='') break print("")
0
null
1,031,068,075,918
55
52
import sys sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inm = lambda: map(int, sys.stdin.readline().split()) inl = lambda: list(inm()) ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) n, m = inm() sc = [tuple(inm()) for i in range(m)] def digits(x): if x < 10: return 1 if x < 100: return 2 return 3 def solve(): for x in range(1000): if digits(x) != n: continue sx = str(x) ok = True for i in range(m): s, c = sc[i] if sx[s - 1] != str(c): ok = False break if ok: return x return -1 print(solve())
N, M = map(int, input().split()) s = [] c = [] for i in range(M): x,y = map(int,input().split()) s.append(x) c.append(y) ans_list = [-1 for i in range(N)] for i in range(M): if ans_list[s[i]-1] != -1 and ans_list[s[i]-1] != c[i]: print(-1) exit() else: ans_list[s[i]-1] = c[i] #print(ans_list) if ans_list[0] == 0 and N>=2: print(-1) exit() ans = 0 for i in range(N): if ans_list[i] == -1 and i != 0: ans_list[i] = 0 if ans_list[i] == -1 and i == 0 and N >= 2: ans_list[i] = 1 if ans_list[i] == -1 and i == 0 and N == 1: ans_list[i] = 0 ans += ans_list[i] * (10**(N-i-1)) print(ans)
1
60,748,767,215,068
null
208
208
from heapq import * import sys from collections import * from itertools import * from decimal import * import copy from bisect import * import time import math def gcd(a,b): if(a%b==0):return(b) return (gcd(b,a%b)) N=int(input()) A=list(map(int,input().split())) A=[[A[i],i] for i in range(N)] A.sort(reverse=True) dp=[[0 for i in range(N+1)] for _ in range(N+1)] for n in range(N): a,p=A[n] for x in range(1,n+2): y=n+1-x dp[x][y]=max(dp[x][y],dp[x-1][y]+round(abs(x-1 - p))*a) for y in range(1,n+2): x=n+1-y dp[x][y]=max(dp[x][y],dp[x][y-1]+round(abs(N-y - p))*a) #print(dp) print(max([dp[x][y] for x in range(N+1) for y in range(N+1) if x+y==N]))
#!/usr/bin/env python3 import sys import itertools sys.setrecursionlimit(10**8) INF = float("inf") MOD = 10**9+7 N = int(input()) A = list(map(int, input().split())) AA = [(a, i) for i, a in enumerate(A, start=1)] AA.sort(reverse=True) # print(AA) DP = [[0]*(N+1) for _ in range(N+1)] for wa in range(1, N+1): # AA[:wa]までを考える for x in range(wa+1): y = wa - x a, i = AA[wa-1] if x - 1 >= 0: DP[x][y] = max(DP[x][y], DP[x-1][y]+a*(i-x)) if y - 1 >= 0: DP[x][y] = max(DP[x][y], DP[x][y-1]+a*(N-y-i+1)) # print(wa, (x, y), (a, i), DP[x][y]) M = -INF for x in range(N): y = N-x M = max(DP[x][y], M) print(M)
1
33,721,827,406,410
null
171
171
s = int(input()) mod = 10**9 + 7 dp = [0 for i in range(s+1)] dp[0] = 1 for cp in range(1, s+1): dp[cp] = sum(dp[0:max(cp-2, 0)]) % mod print(dp[s])
import sys input = sys.stdin.readline def main(): S = int(input()) dp = [0]*(S+1) dp[0] = 1 M = 10**9 + 7 for i in range(1, S+1): for j in range(0,i-2): dp[i] += dp[j] dp[i] %= M print(dp[S]) if __name__ == '__main__': main()
1
3,313,830,064,378
null
79
79
x=int(input()) print(int(x*x*x))
#coding: UTF-8 input_number = int(input()) print input_number ** 3
1
282,062,000,130
null
35
35
a,v,b,w,t=map(int,open(0).read().split()) print('YNEOS'[v-w<abs(a-b)/t::2])
#!/usr/bin/env python3 import sys from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) a, v = mi() b, w = mi() t = ii() if v <= w: print('NO') else: dist = abs(a - b) print('YES') if dist <= t * (v - w) else print('NO') if __name__ == "__main__": main()
1
15,203,674,750,550
null
131
131
import math import collections import fractions import itertools import functools import operator import numpy as np def solve(): h, w = map(int, input().split()) maze = [input() for _ in range(h)] ans = 0 can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]] for x in range(h): for y in range(w): if maze[x][y] == "#": continue dist = [[0]*w for _ in range(h)] stack = collections.deque() stack.append([x,y]) while stack: h2, w2 = stack.popleft() for i, j in can_move: newh, neww = h2+i, w2+j if newh < 0 or neww < 0 or newh >= h or neww >= w: continue elif maze[newh][neww] != "#" and dist[newh][neww] == 0: dist[newh][neww] = dist[h2][w2]+1 stack.append([newh, neww]) dist[x][y] = 0 ans = max(ans, np.max(dist)) print(ans) return 0 if __name__ == "__main__": solve()
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 H, W = list(map(int, input().split())) S = [] for i in range(H): S.append(input()) def bfs(u): stack = deque([u]) visited = set() seen = set() p = [[INF for j in range(W)] for i in range(H)] p[u[0]][u[1]] = 0 for i in range(H): for j in range(W): if S[i][j] == "#": p[i][j] = -1 while len(stack) > 0: v = stack.popleft() ### visited.add(v) ### a = (v[0] + 1, v[1]) b = (v[0] , v[1] + 1) c = (v[0] - 1, v[1]) d = (v[0] , v[1] - 1) e = [a, b, c, d] for ee in e: if ee[0] >= 0 and ee[0] <= H-1 and ee[1] >= 0 and ee[1] <= W-1: if S[ee[0]][ee[1]] == ".": if ee not in visited: p[ee[0]][ee[1]] = min(p[ee[0]][ee[1]], p[v[0]][v[1]] + 1) if ee not in seen: stack.append(ee) seen.add(ee) ans = 0 for i in range(H): ans = max(ans, max(p[i])) return ans sol = 0 for i in range(H): for j in range(W): if S[i][j] == ".": sol = max(sol, bfs((i,j))) print(sol)
1
94,546,044,849,152
null
241
241
n,k = map(int,input().split()) h = sorted(map(int,input().split()),reverse=True) print(sum(h[k:]))
n, k = list(map(int, input().split())) h = list(map(int, input().split())) h.sort() if k > 0: h = h[:-k] print(sum(h))
1
78,632,296,979,988
null
227
227
w,h,x,y,r = input().split() w = int(w) h = int(h) x = int(x) y = int(y) r = int(r) if x - r >= 0 and y - r >= 0 and x + r <= w and y + r <= h: print("Yes") else: print("No")
values = input() W, H, x, y, r = [int(x) for x in values.split()] flag = True if x - r < 0 or x + r > W: flag = False if y - r < 0 or y + r > H: flag = False if flag: print('Yes') else: print('No')
1
441,796,032,210
null
41
41
x = int(input()) k = [] for i in range(1, x + 1): y = i if i % 3 == 0: k.append(i) else: while True: if y % 10 == 3: k.append(i) break else: if y <= 10: break else: y //= 10 print(' '+ ' '.join([str(x) for x in k]))
import math N , M = map(int,input().split())#N:展望台の数、M:道の数 H = list(map(int,input().split()))#H:高さの配列 AB = [map(int, input().split()) for _ in range(M)] A , B = [list(i) for i in zip(*AB)] G = [1] * N #展望台の数 for i in range (M): if H[ A[i] -1 ] > H[B[i] -1 ]: G[ B[i] -1 ] = 0 elif H[ A[i] -1] == H[ B[i] -1 ]: G[ A[i] -1 ] = 0 G[ B[i] -1 ] = 0 else: G[A[i] -1 ] = 0 print( G.count(1) )
0
null
13,031,464,304,352
52
155
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] answer = 0 for h in range(2**H): for w in range(2**W): b_cnt = 0 for i in range(H): for j in range(W): if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#': b_cnt += 1 if b_cnt == K: answer += 1 print(answer)
def solve(): N, K = map(int, input().split()) H = list(map(int, input().split())) if K>=N: return 0 H.sort() ans = sum(H[:N-K]) return ans print(solve())
0
null
44,095,239,384,280
110
227
n=int(input()) s=input() ans='' for i in range(n-1): if s[i]==s[i+1]: pass else: ans+=s[i] ans+=s[-1] print(len(ans))
n = int(input()) ls = [] rs = [] for _ in range(n): x, y = map(int, input().split()) ls.append(x) rs.append(y) ls = sorted(ls) rs = sorted(rs) if n % 2 == 1: print(rs[len(rs)//2] - ls[len(ls)//2] + 1) else: a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2 b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2 print((a - b) // 5 + 1)
0
null
93,556,934,135,940
293
137
import sys, re from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from collections import deque, defaultdict, Counter from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop, heapify from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 class UnionFind(): def __init__(self, n): self.n = n # parents[i]: 要素iの親要素の番号 # 要素iが根の場合、parents[i] = -(そのグループの要素数) self.parents = [-1] * n def find(self, x): if 0 > self.parents[x]: 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 # 要素xが属するグループの要素数を返す def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) # 要素xが属するグループに属する要素をリストで返す 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 0 > x] # グループの数を返す def group_count(self): return len(self.roots()) # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す def all_group_members(self): return {r: self.members(r) for r in self.roots()} # print()での表示用 # all_group_members()をprintする def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) N, M, K = MAP() tree = UnionFind(N) friends = [[] for _ in range(N)] for _ in range(M): A, B = MAP() tree.union(A-1, B-1) friends[A-1].append(B-1) friends[B-1].append(A-1) blocks = [[] for _ in range(N)] for _ in range(K): C, D = MAP() blocks[C-1].append(D-1) blocks[D-1].append(C-1) for i in range(N): blocks_cnt = sum([tree.same(i, j) for j in blocks[i]]) print(tree.size(i) - len(friends[i]) - 1 - blocks_cnt, end=" ") print()
def cut(S,H,W,K): cnt,h = 0,0 OP = [[0 for _ in range(W)] for _ in range(H)] while "#" not in S[h]: h += 1 burst = False for i in range(h,H): if "#" not in S[i]: OP[i] = [OP[i-1][j] for j in range(W)] burst = False else: cnt += 1 cnt_h = 1 for j in range(W): OP[i][j] = cnt if S[i][j] == "#" and cnt_h < S[i].count("#"): cnt += 1 cnt_h += 1 for i in reversed(range(h)): for j in range(W): OP[i][j] = OP[i+1][j] for i in range(H): OP[i] = " ".join(map(str,OP[i])) return OP def main(): H,W,K = map(int,input().split()) S = [input() for _ in range(H)] ans = cut(S,H,W,K) for i in range(H): print(ans[i]) if __name__ == "__main__": main()
0
null
102,302,022,422,680
209
277
n,s = map(int, input().split()) a = list(map(int, input().split())) a.sort() mod = 998244353 dp = [[0 for i in range(s+1)] for j in range(n+1)] dp[0][0] = 1 for i in range(n): for x in range(s+1): dp[i+1][x] = 2*dp[i][x] if x-a[i] >= 0: dp[i+1][x] += dp[i][x-a[i]] dp[i+1][x] %= mod print(dp[n][s])
N, K, S = map(int, input().split()) d = S if S == int(1e9): d -= 1 else: d += 1 ans = [1 for _ in range(N)] for i in range(N): if K > 0: ans[i] = S K -= 1 else: ans[i] = d print(*ans)
0
null
54,300,785,767,662
138
238
n, k = map(int, input().split()) a = sorted(map(int, input().split())) d = [a[i + 1] - a[i] for i in range(n - 1)] mod = 1000000007 def pow(x, n): ret = 1 while n > 0: if (n & 1) == 1: ret = (ret * x) % mod x = (x * x) % mod n //= 2 return ret fac = [1] inv = [1] for i in range(1, n + 1): fac.append((fac[-1] * i) % mod) inv.append(pow(fac[i], mod - 2)) def cmb(n, k): if k < 0 or k > n: return 0 return ((fac[n] * inv[k]) % mod * inv[n - k]) % mod ret = 0 for i in range(n - 1): num = (cmb(n, k) - cmb(i + 1, k) - cmb(n - i - 1, k)) % mod ret = (ret + d[i] * num) % mod print(ret)
from functools import reduce n, *s = open(0).read().split() u = [] for t in s: close_cnt = 0 tmp = 0 for c in t: tmp += (1 if c == '(' else -1) close_cnt = min(close_cnt, tmp) u.append((close_cnt, tmp - close_cnt)) M = 10**6 + 1 acc = 0 for a, b in sorted(u, key=lambda z: (- M - z[0] if sum(z)>= 0 else M - z[1])): if acc + a < 0: print("No") exit(0) else: acc += a + b print(("No" if acc else "Yes"))
0
null
59,835,131,811,820
242
152
def resolve(): H, W = list(map(int, input().split())) S = [list(input()) for _ in range(H)] import collections maxdist = 0 for startx in range(H): for starty in range(W): if S[startx][starty] == "#": continue visited = [[-1 for _ in range(W)] for __ in range(H)] visited[startx][starty] = 0 q = collections.deque([(startx, starty)]) while q: x, y = q.pop() for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx = x + dx ny = y + dy if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and visited[nx][ny] == -1: visited[nx][ny] = visited[x][y] + 1 q.appendleft((nx, ny)) maxdist = max(maxdist,max(sum(visited, []))) print(maxdist) if '__main__' == __name__: resolve()
from collections import deque import sys sys.setrecursionlimit(20000000) N = int(input()) ab = [list(map(int, input().split())) for _ in range(N-1)] routes = [[] for _ in range(N)] for i in range(len(ab)): routes[ab[i][0]-1].append([ab[i][1]-1, i]) routes[ab[i][1]-1].append([ab[i][0]-1, i]) route_color = [-10e+10 for _ in range(len(ab))] route_num = [0]*N max_route = 0 for i in range(N): num = len(routes[i]) route_num[i] = num if max_route < num: max_route = num seen = [False for _ in range(N)] def function(num,pre_color): color_num = -1 for route in routes[num]: color_num += 1 if color_num == pre_color: color_num+=1 if route_color[route[1]] != -10e+10: color_num-=1 pass else: route_color[route[1]] = color_num if seen[route[0]] == False: seen[route[0]] = True function(route[0],route_color[route[1]]) return function(0,-1) print(max_route) for color in route_color: print(color+1)
0
null
115,283,603,637,000
241
272
if sum(list(map(int,input().split())))>21: print("bust") else: print("win")
A1, A2, A3 = map(int, input().split()) print('win') if A1 + A2 + A3 <= 21 else print('bust')
1
118,214,147,369,190
null
260
260
import numpy as np n, k = map(int, input().split()) aa = list(map(np.int64, input().split())) aa = np.array(aa) def mul(dd): mod = 10**9+7 ret = 1 for d in dd: ret = (ret*d)%mod return ret def sol(aa, n, k): mod = 10**9+7 aap = aa[aa>0] aam = aa[aa<0] if n == k: return mul(aa) if len(aap) + 2*(len(aam)//2) < k: return 0 # マイナスのみ if len(aam) == n: aam.sort() if k%2==1: return mul(aam[-k:]) else: return mul(aam[:k]) aap = aa[aa>=0] aap.sort() aap = aap[::-1] aam.sort() ret=1 if k%2 >0: k = k-1 ret *= aap[0] aap = aap[1:] aap2 = [aap[2*i]*aap[2*i+1] for i in range(len(aap)//2)] aam2 = [aam[2*i]*aam[2*i+1] for i in range(len(aam)//2)] aap2.extend(aam2) aap2.sort(reverse=True) aap2 = [i%mod for i in aap2] return (ret*mul(aap2[:k//2]))%mod print(sol(aa, n, k))
N,K=map(int,input().split()) A=list(map(int,input().split())) point=[1]*N for i in range(N-K): if(A[K+i]>A[i]): print("Yes") else: print("No")
0
null
8,203,486,760,550
112
102
n,m = map(int, input().split()) neighbors = {key:[] for key in range(1, n+1)} answers = {key:0 for key in range(1, n+1)} answers[1] = 1 for i in range(m): a,b = map(int, input().split()) neighbors[a].append(b) neighbors[b].append(a) def register(hs): newhs = [] for h in hs: for i in neighbors[h]: if answers[i] == 0: answers[i] = h newhs.append(i) return newhs hosts = [1] while True: hosts = register(hosts) if len(hosts) == 0: break flag = 0 for key, item in answers.items(): if item == 0: flag = 1 if flag == 0: print("Yes") for key, item in answers.items(): if key != 1: print(item) else: print("No")
n, m = map(int, input().split()) err = False ans = list('*' * n) for _ in range(m): si, ci = map(int, input().split()) if ans[si - 1] == '*' or ans[si - 1] == str(ci): ans[si - 1] = str(ci) else: err = True if ans[0] == '0' and n != 1: err = True if ans[0] == '*': if n == 1: ans[0] = '0' else: ans[0] = '1' if err: print(-1) else: print(''.join(ai if ai != '*' else '0' for ai in ans))
0
null
40,755,204,237,308
145
208
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors n,m = inm() h = inl() p = [True] * n for i in range(m): a,b = inm() a -= 1 b -= 1 if h[a] >= h[b]: p[b] = False if h[b] >= h[a]: p[a] = False ans = sum(p) print(ans)
n,m = map(int,input().split()) *hl, = map(int,input().split()) ansl = [1]*n for _ in [0]*m: a,b = map(int,input().split()) if hl[a-1] > hl[b-1]: ansl[b-1] = 0 elif hl[a-1] < hl[b-1]: ansl[a-1] = 0 else: ansl[a-1] = 0 ansl[b-1] = 0 print(sum(ansl))
1
25,018,176,173,728
null
155
155
K=int(input()) A,B=map(int,input().split()) print("OK" if B//K*K >= A else "NG")
import math T_1, T_2 = map(int, input().split()) A_1, A_2 = map(int, input().split()) B_1, B_2 = map(int, input().split()) ans = 0 if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2: print("infinity") else: # 速いほうをAと仮定 if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2: A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2 if A_1 < B_1: sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2) # 1サイクルでできる差 sa_1 = -T_1 * A_1 + T_1 * B_1 # T_1でできる差 if sa_1 % sa_12 == 0: ans = int((sa_1 / sa_12)*2) else: kari = math.ceil(sa_1 / sa_12) ans = (kari-1)*2+1 print(ans)
0
null
78,766,702,265,060
158
269
a,b=map(int,input().split());print(a*b)
n = input().split(" ") print(int(n[0]) * int(n[1]))
1
15,832,597,039,840
null
133
133
n, m = map(int,input().split()) h = list(map(int, input().split())) e = [[] for _ in range(n)] for i in range(m): u, v = map(int,input().split()) u -= 1 v -= 1 e[u].append(h[u]- h[v]) e[v].append(h[v]- h[u]) cnt = 0 for i in range(n): if not e[i]: cnt += 1 elif min(e[i]) > 0: cnt += 1 print(cnt)
N,M = map(int,input().split()) H = list(map(int,input().split())) bad = [] for i in range(M): A,B = map(int,input().split()) if H[A-1] > H[B-1]: bad.append(B-1) elif H[A-1] < H[B-1]: bad.append(A-1) else: bad.append(A-1) bad.append(B-1) print(N-len(set(bad)))
1
25,084,301,485,376
null
155
155
a,b,c,d = map(int, input().split()) for i in range(100): # 繰り返し処理したい、とりあえず100回以上の繰り返しはないから100回繰り返す c -= b # 青木くんの体力cから高橋くんの攻撃力bぶん引く # print('青木体力', c) # 残り体力を確認する時は先頭の#を外す if c <= 0: # 青木くん体力が0以下になったら print('Yes') # 高橋くんの勝ちなのでYes break # 体力が0になったら繰り返しも終了 a -= d # 次に高橋くんの体力aから青木くんの攻撃力dを引く # print('高橋体力',a) # 残り体力を確認する時は先頭の#を外す if a <= 0: # 高橋くん体力が0以下になったら print('No') # 青木くん勝利でNo break # 体力が0になったら繰り返しも終了 # どちらの体力も残ってたら次の繰り返し
A, B, C, D = map(int, input().split()) while True: C -= B if C < 1: print('Yes') quit() A -= D if A < 1: print('No') quit()
1
29,714,002,306,164
null
164
164