code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
Flag = True data = [] while Flag: H, W = map(int, input().split()) if H == 0 and W == 0: Flag = False else: data.append((H, W)) #print(type(W)) for (H, W) in data: for i in range(H): if i == 0 or i == H-1: print('#' * W) else: print('#' + '.' * (W-2) + '#') print('\n', end="")
class dice(): top = 1 flont = 2 right = 3 def do_N(self): temp = self.flont self.flont = 7-self.top self.top = temp def do_S(self): temp = 7-self.flont self.flont = self.top self.top = temp def do_E(self): temp = self.top self.top = 7-self.right self.right = temp def do_W(self): temp = 7-self.top self.top = self.right self.right = temp num1 = list(map(int, input().split())) q = int(input()) dice1 = dice() for i in range(q): top, flont = map(int, input().split()) if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] for j in range(4): for k in range(4): dice1.do_E() if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] dice1.do_N() if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] dice1.do_S() dice1.do_E() if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] for j in range(4): for k in range(4): dice1.do_E() if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] dice1.do_N() if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top: ans = num1[dice1.right-1] print(str(ans))
0
null
545,545,846,328
50
34
def main(): A1, A2, A3 = map(int, input().split()) if A1 + A2 + A3 >= 22: ans = "bust" else: ans = "win" print(ans) if __name__ == "__main__": main()
#!/usr/bin/python3 import sys def input(): return sys.stdin.readline().rstrip('\n') #S = input() A1,A2,A3 = list(map(int,input().split())) if A1+A2+A3 < 22: print('win') else: print('bust')
1
118,359,900,478,018
null
260
260
from collections import deque import math import sys x,y,a,b,c = list(map(int,sys.stdin.readline().split())) p = sorted(list(map(int,sys.stdin.readline().split())), reverse=True) q = sorted(list(map(int,sys.stdin.readline().split())), reverse=True) r = sorted(list(map(int,sys.stdin.readline().split())), reverse=True) eat=[] if x<len(p): [eat.append(red) for red in p[:x]] else: [eat.append(red) for red in p] if y<len(q): [eat.append(green) for green in q[:y]] else: [eat.append(green) for green in q] [eat.append(apple) for apple in r] eat = sorted(eat, reverse=True) #print(sum(eat[:x + y])) ans = 0 for taste in eat[:x + y]: ans += taste print(ans)
def LI(): return list(map(int, input().split())) X, Y, A, B, C = LI() red = LI() green = LI() mu = LI() red.sort(reverse=True) green.sort(reverse=True) ans = red[:X]+green[:Y]+mu ans.sort(reverse=True) total = 0 for i in range(X+Y): total += ans[i] print(total)
1
44,954,240,930,312
null
188
188
import sys from math import gcd from collections import Counter MOD = 10**9 + 7 def main(): input = sys.stdin.readline N = int(input()) V = [] z = 0 for _ in range(N): A, B = map(int, input().split()) g = gcd(A, B) if g == 0: z += 1 continue A, B = A // g, B // g if A == 0: V.append((0, 1)) elif A < 0: V.append((-A, -B)) else: V.append((A, B)) C = Counter(V) ans = Mint(1) used = set() for k, V in C.items(): if k in used: continue a, b = k v = (0, 1) if b == 0 else (b, -a) if b > 0 else (-b, a) t = Mint(1) t += pow(2, V, MOD) - 1 t += pow(2, C[v], MOD) - 1 ans *= t used.add(v) print(ans - 1 + z) class Mint: def __init__(self, value=0): self.value = value % MOD if self.value < 0: self.value += MOD @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, MOD u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v if u < 0: u += MOD return u def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % MOD return self def __add__(self, other): new_obj = Mint(self.value) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other)) % MOD if self.value < 0: self.value += MOD return self def __sub__(self, other): new_obj = Mint(self.value) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % MOD return self def __mul__(self, other): new_obj = Mint(self.value) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other) self *= other.inverse() return self def __floordiv__(self, other): new_obj = Mint(self.value) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj //= self return new_obj if __name__ == '__main__': main()
s=input() p=input() result="No" for i in range(len(s)): r=s[i:]+s[:i] if r[0:len(p)]==p: result="Yes" break print(result)
0
null
11,323,502,490,794
146
64
import sys input = sys.stdin.readline from math import sqrt def main(): N = int(input()) A = [0]*(N+1) n = int(sqrt(N)) + 1 for x in range(1, n): for y in range(1, n): for z in range(1, n): tmp = x*x + y*y + z*z + x*y + y*z + z*x if tmp <= N: A[tmp] += 1 for i in range(1,N+1): print(A[i]) if __name__ == '__main__': main()
N = int(input()) l = [0] * 10 ** 5 for x in range(1,100): for y in range(1,100): for z in range(1,100): n = (pow(x + y,2) + pow(y + z,2) + pow(z + x,2)) // 2 l[n] += 1 for n in range(1,N + 1): print(l[n])
1
8,013,623,368,828
null
106
106
N = int(input()) S = [input() for i in range(N)] ac = 0 wa = 0 tle = 0 re = 0 for s in S: if s == 'AC': ac += 1 elif s == 'WA': wa += 1 elif s == 'TLE': tle += 1 elif s == 'RE': re += 1 print('AC x ' + str(ac)) print('WA x ' + str(wa)) print('TLE x ' + str(tle)) print('RE x ' + str(re))
from collections import defaultdict def main(): N = int(input()) d = defaultdict(int) results = ["AC", "WA", "TLE", "RE"] for _ in range(N): d[input()] += 1 for r in results: print(f"{r} x {d[r]}") if __name__ == '__main__': main()
1
8,706,571,210,688
null
109
109
n = int(input()) sum = 0 for i in range(n) : if (i+1)%3 != 0 and (i+1)%5 != 0 : sum += i+1 print(sum)
K = int(input()) a = [0] * K a[0] = 7 % K for i in range(1, K): a[i] = (a[i-1] * 10 + 7) % K ans = -1 for i in range(K): if a[i] == 0: ans = i + 1 break print(ans)
0
null
20,486,141,008,788
173
97
A,B,C = map(int,input().split()) ans = "No" if A == B and A != C: ans = "Yes" elif B == C and B != A: ans = "Yes" elif C == A and C != B: ans = "Yes" print(ans)
a, b, c = map(int, input().split()) ret = "No" if (a == b and a != c) or (b == c and c != a) or (c == a and a != b): ret = "Yes" print("{}".format(ret))
1
68,138,244,787,392
null
216
216
def printComparison(a, b): """ a: int b: int outputs the comparison result of a and b >>> printComparison(1, 2) a < b >>> printComparison(4, 3) a > b >>> printComparison(5, 5) a == b >>> printComparison(-20, -10) a < b """ operator = '' if a > b: operator = '>' elif a < b: operator = '<' else: operator = '==' print('a', operator, 'b') if __name__ == '__main__': ival = input().split(' ') printComparison(int(ival[0]), int(ival[1]))
N,M=map(int,input().split()) n=['0']*N a=0 for i in range(M): s,c=map(str,input().split()) if n[int(s)-1]!='0' and n[int(s)-1]!=c: a=1 if s=='1' and c=='0' and N!=1: a=1 n[int(s)-1]=c if n[0]=='0' and N!=1: n[0]='1' if a==0: print(''.join(n)) else: print(-1)
0
null
30,766,118,907,482
38
208
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import collections class Process(object): def __init__(self, name, time): self.name = name self.time = int(time) def schedule(processes, quantum): queue = collections.deque(processes) time = 0 while len(queue) > 0: p = queue.popleft() rest_time = p.time - quantum if rest_time > 0: time += quantum queue.append(Process(p.name, rest_time)) else: time += p.time print("{name} {time:d}".format(name=p.name, time=time)) def main(): [n, q] = list(map(int, input().split())) processes = [Process(*input().split()) for i in range(n)] schedule(processes, q) if __name__ == "__main__": main()
# coding: utf-8 import sys import collections def main(): n, quantum = map(int, raw_input().split()) processes = [x.split() for x in sys.stdin.readlines()] for p in processes: p[1] = int(p[1]) queue = collections.deque(processes) elapsed = 0 while queue: # print elapsed, queue head = queue.popleft() if head[1] > quantum: head[1] -= quantum queue.append(head) elapsed += quantum else: elapsed += head[1] print head[0], elapsed if __name__ == '__main__': main()
1
41,766,189,400
null
19
19
n=int(input()) a=list(map(int,input().split())) #R,B,Gの順に埋めていく #R,B,Gの現在の数を保存する cnt={'R':0,'B':0,'G':0} ans=1 for i in range(n): count=0 edi=0 for j in 'RBG': if cnt[j]==a[i]: count+=1 if edi==0: cnt[j]+=1 edi=1 ans*=count print(ans%(10**9+7))
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right def main(): N = int(input()) A = list(map(int, input().split())) p = 10**9+7 # check[i]:= Aの中のiが出てきた順番 check = [[] for _ in range(N)] for i in range(N): check[A[i]].append(i) # print(check) ans = 1 for i in range(len(check[0])): ans *= (3-i) for i in range(1,N): if len(check[i-1]) < len(check[i]): exit(print(0)) # check[i]がcheck[i-1]のなかで何番目か調べる for j in range(len(check[i])): d = bisect_right(check[i-1],check[i][j]) if d < j: exit(print(0)) ans *= d-j ans %= p # print(ans) print(ans) if __name__ == "__main__": main()
1
130,526,865,037,800
null
268
268
#!/usr/bin/env python3 def main(): N, K = map(int, input().split()) H = sorted([int(x) for x in input().split()]) if K == 0: print(sum(H)) elif N > K: print(sum(H[:-K])) else: print(0) if __name__ == '__main__': main()
n, k = map(int, input().split()) h = list(map(int,input().split())) ans = 0 h = sorted(h,reverse=True) for i in range(k,n): ans += h[i] print(ans)
1
78,987,139,407,798
null
227
227
a, b, c, d = map(int, input().split()) for i in range(max(a, b, c, d)): if b >= c: print('Yes') exit() else: c -= b if a <= d: print('No') exit() else: a -= d continue
N = int(input()) d_s = list(map(int, input().split())) answer = 0 for i in range(N-1): for j in range(i+1, N): answer += d_s[i] * d_s[j] print(answer)
0
null
98,858,004,609,472
164
292
n = int(input()) cnt = 0 for i in range(1, n+1): cnt += i * (n // i) * (n // i + 1) // 2 print(cnt)
N = int(input()) ans = 0 for i in range(1, N + 1): res = N // i ans += res*(res+1)//2*i print(ans)
1
11,106,505,289,164
null
118
118
l = map(int, raw_input().split()) print l[0] * l[1], print l[0] *2 + l[1] * 2
a, b=map(int, input().split()) r=a*b l=2*(a+b) print(r,l)
1
307,493,407,100
null
36
36
class SegmentTree(): """A segment Tree. This is a segment tree without recursions. This can support queries as follows: - update a single value in O(logN). - get the folded value of values in a segment [l, r) in O(logN) N is the length of the given iterable value. Parameters ---------- iterable : Iterable[_T] An iterable value which will be converted into a segment tree func : Callable[[_T, _T], _T] A binary function which returns the same type as given two. This has to satisfy the associative law: func(a, func(b, c)) = func(func(a, b), c) e : _T The identity element of the given func. In other words, this satisfies: func(x, e) = func(e, x) = x """ def __init__(self, iterable, func, e): self.func = func self.e = e ls = list(iterable) self.n = 1 << len(ls).bit_length() ls.extend( [self.e] * (self.n - len(ls)) ) self.data = [self.e] * self.n + ls for i in range(self.n-1, 0, -1): self.data[i] = self.func(self.data[2*i], self.data[2*i+1]) def replace(self, index, value): """replace the old value of the given index with the given new value. This replaces the old value of the given index with the given new value in O(logN). This is like "list[index] = value". Parameters ---------- index : int The index of the value which will be replaced. value : _T The new value with which the old value will be replaced. """ index += self.n self.data[index] = value index //= 2 while index > 0: self.data[index] = self.func(self.data[2*index], self.data[2*index+1]) index //= 2 def folded(self, l, r): """get the folded value of values in a segment [l, r). This get the folded value of values in a segment [l, r) in O(logN). If func is add, it returns the sum of values in [l, r). In other words, this is eqivalent to "sum(list[l:r])". If func is other functions, then this is equivalent to "accumulate(list[l:r], func)". Parameters ---------- l : int The left edge. r : int The right edge. Returns ------- _T(the same type as the type of the element of the given iterable) This is equivalent to func(list[l], func(list[l+1], ... ) ). If func is represented as '*', then it's: list[l] * list[l+1] * ... * list[r-1] """ left_folded = self.e right_folded = self.e l += self.n r += self.n while l < r: if l % 2: left_folded = self.func(left_folded, self.data[l]) l += 1 if r % 2: r -= 1 right_folded = self.func(self.data[r], right_folded) l //= 2 r //= 2 return self.func(left_folded, right_folded) from operator import or_ N = int(input()) S = input() ls = [1 << (ord(c) - ord('a')) for c in S] segtree = SegmentTree(ls, or_, 0) Q = int(input()) for _ in range(Q): s = input() if s[0] == '1': i, c = s[2:].split() segtree.replace(int(i)-1, 1 << (ord(c) - ord('a'))) else: l, r = map(int, s[2:].split()) value = segtree.folded(l-1, r) print(format(value, 'b').count('1'))
n = int(input()) s = input() s = list(s) count = 0 while len(s) > 2: if s[0] == "A" and s[1] =="B" and s[2] == "C": count += 1 del s[0:2] else: del s[0] print(count)
0
null
80,462,966,379,922
210
245
N = int(input()) L = [i for i in range(N+1)] odd = [] for j in range(N+1): if L[j] % 2 == 0: pass else: odd.append(L[j]) j+=1 print(len(odd)/(len(L)-1))
import math N = float(input()) if(N%2==0): print(1/2) else: print((math.floor(N/2)+1)/N)
1
177,052,069,372,608
null
297
297
n,m = map(int,input().split()) a = list(map(int,input().split())) for v in a: n = n - v if n < 0: n = -1 break print(n)
n, m = map(int, input().split()) a = list(map(int, input().split())) for time in a: n -= time if n<0: n = -1 break print(n)
1
32,027,476,958,650
null
168
168
s = input() k = int(input()) if len(set(s)) == 1: print((len(s)*k)//2) exit() ss = s + s shoko = 0 prev = '' cnt = 0 for i in range(len(s)): if s[i] == prev: cnt += 1 else: shoko += cnt // 2 cnt = 1 prev = s[i] shoko += cnt // 2 kosa = 0 prev = '' cnt = 0 for i in range(len(ss)): if ss[i] == prev: cnt += 1 else: kosa += cnt // 2 cnt = 1 prev = ss[i] kosa += cnt // 2 kosa -= shoko print(shoko + (k-1)*kosa)
n = int(input()) ans = list() for i in range(n): line = input().split(" ") a = float(line[0]) b = float(line[1]) c = float(line[2]) if ((a**2 + b**2) == c**2) or ((b**2 + c**2) == a**2) or ((c**2 + a**2) == b**2): ans.append("YES") else: ans.append("NO") for j in range(n): print(ans[j])
0
null
87,540,307,556,482
296
4
n = int(input()) s = "" for i in range(n): l = list(map(lambda x:x*x,map(int, input().split()))) l.sort() if l[0] + l[1] == l[2]: s += "YES\n" else: s += "NO\n" print(s,end="")
import math n = int(input()) values = list(map(int, input().split(' '))) values.sort(reverse=True) sum = 0 for i in range(1, n): sum += values[math.floor(i/2)] print(sum)
0
null
4,620,105,331,582
4
111
from math import sqrt N = int(input()) result = [0] * N n = int(sqrt(N)) for x in range(1, n+1): for y in range(1, n+1): for z in range(1, n+1): check = x**2 + y**2 + z**2 + x * y + y * z + z * x if check <= N: result[check-1] += 1 for i in result: print(i)
n=int(input()) Ans=[0]*n for x in range(1,100): for y in range(1,100): for z in range(1,100): num=x**2+y**2+z**2+x*y+y*z+z*x if num<=n: Ans[num-1]+=1 print(*Ans,sep='\n')
1
7,994,139,523,260
null
106
106
n,k=map(int,input().split()) a=list(map(lambda x:(int(x)-1)%k,input().split())) s=[0] for i in a: s.append((s[-1]+i)%k) mp={} ans=0 for i in range(len(s)): if i-k>=0: mp[s[i-k]]-=1 if s[i] in mp: ans+=mp[s[i]] mp[s[i]]+=1 else: mp[s[i]]=1 print(ans)
# # # author : samars_diary # # 13-09-2020 │ 11:26:57 # # # import sys, os.path #if(os.path.exists('input.txt')): #sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) 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(): d,t,s=mii() if d/s<=t: print('Yes') else: print('No') solve()
0
null
70,561,982,640,760
273
81
N, R = map(int, input().split()) if N < 10: ans = R + (100 * (10 - N)) else: ans = R print(ans)
n,r=map(int,input().split()) print(r if n>9 else r+(100*(10-n)))
1
63,301,080,612,000
null
211
211
h, n = map(int,input().split()) a = list(map(int, input().split())) a.sort(reverse=True) for v in a: h -= v if h <= 0: print('Yes') break else: print('No')
import sys def input(): return sys.stdin.readline().strip() def STR(): return input() def MAP(): return map(int, input().split()) inf = sys.maxsize h, w, k = MAP() s = [[int(i) for i in STR()] for _ in range(h)] ans = inf for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500) hdiv = [1 for _ in range(h)] for j in range(h - 1): tmp = 2 ** j hdiv[j] = 1 if i & tmp else 0 sh = sum(hdiv) tmpans = sh - 1 wdiv = [0 for _ in range(w - 1)] partsum = [0 for _ in range(sh + 1)] j = 0 cnt = 0 while j < w: #O(2 * 10 ** 4) tmp = 0 idx = 0 for kk in range(h): #O(10) tmp += s[kk][j] if hdiv[kk]: partsum[idx] += tmp tmp = 0 idx += 1 flag = True for kk in range(sh + 1): if partsum[kk] > k: tmpans += 1 partsum = [0 for _ in range(sh + 1)] flag = False if flag: j += 1 cnt = 0 else: cnt += 1 if cnt > 2: tmpans = inf break ans = min(ans, tmpans) print(ans)
0
null
63,381,054,711,440
226
193
import itertools n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) d = list(itertools.permutations(range(1, n + 1))) d.sort() a = -1 b = -1 for i in range(len(d)): if d[i] == p: a = i if d[i] == q: b = i print(abs(a - b))
n,m = map(int,input().split()) ans = ["num"]*n for i in range(m): s,c = map(int,input().split()) if ans[s-1] == "num" or ans[s-1] == c: ans[s-1] = c else: print("-1") exit() if ans[0] == 0 and n >= 2: print("-1") exit() elif ans[0] == 0 and n == 1: print("0") exit() elif ans[0] == "num" and n == 1: print("0") exit() elif ans[0] == "num": ans[0] = 1 for j in range(n): if ans[j] == "num": ans[j] = 0 [print(ans[k],end ="") for k in range(n)]
0
null
80,886,783,064,710
246
208
from itertools import permutations import math N = int(input()) l = [list(map(int, input().split())) for i in range(N)] waru = 1 for i in range(N): waru*= i+1 a = [i+1 for i in range(N)] c = 0 su = 0 for i in permutations(a,N): li = list(i) for j in range(len(li)-1): start = l[li[j]-1] g = l[li[j+1]-1] su += math.sqrt((start[0]-g[0]) ** 2 + (start[1]-g[1]) ** 2) print(su/waru)
import itertools import math N = int(input()) p = [] for i in range(N): x, y = [int(n) for n in input().split()] p.append([x, y]) total_length = 0 k = 0 for pattern in itertools.permutations(p): k += 1 length = 0 for i in range(N-1): length += math.sqrt((pattern[i+1][0] - pattern[i][0])**2 + (pattern[i+1][1] - pattern[i][1])**2) total_length += length print(total_length/k)
1
148,817,360,965,562
null
280
280
A,B,K=map(int,input().split()) if K<A: ans1=A-K ans2=B else: ans1=0 ans2=max(A+B-K,0) print(ans1,ans2)
s = raw_input() p = raw_input() s3 = s + s + s if p in s3: print 'Yes' else: print 'No'
0
null
53,104,158,064,490
249
64
base = input().split() print(base[1],end="") print(base[0])
import math a,b,h,m = map(int,input().split()) h_s = 360*h/12+30*m/60 m_s = 360*m/60 s = abs(h_s - m_s) print(abs(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(s)))))
0
null
61,683,367,244,580
248
144
import sys n,k=map(int,input().split()) w=list(map(int,sys.stdin.readlines())) def f(): i=0 for _ in[0]*k: s=0 while s+w[i]<=m: s+=w[i];i+=1 if i==n:return n return i l,r=max(w),sum(w) while l<r: m=(l+r)//2 if f()>=n:r=m else:l=m+1 print(r)
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) x=int(input()) a,b=divmod(x,100) if a*5>=b: print(1) else: print(0)
0
null
63,981,831,975,982
24
266
n, k = map(int, input().split()) xs = [i for i in range(1, k + 1)] xs.reverse() dict_x = {} mod = 10 ** 9 + 7 def pow(x, y): global mod a = 1 b = x c = y while c > 0: if c & 1: a = (a * b) % mod b = (b * b) % mod c = c >> 1 return a answer = 0 for x in xs: num = k // x a = pow(num, n) # print(a) s = 2 while x * s <= k: a -= dict_x[x * s] s += 1 dict_x[x] = a answer = (answer + a * x) % mod print(answer)
n, k = map(int, input().split()) mod = 10 ** 9 + 7 dp = [0] * (k + 1) ans = 0 for i in range(k, 0, -1): num = k // i dp[i] += pow(num, n, mod) for j in range(1, num): dp[i] -= dp[(j + 1) * i] ans += i * dp[i] ans %= mod print(ans)
1
36,697,297,137,670
null
176
176
from math import gcd def main(): a, b = map(int, input().split()) r = (a * b) // gcd(a, b) print(r) if __name__ == '__main__': main()
import numpy as np from numba import njit def main(): R, C, K = map(int, input().split()) field = np.full((R+1,C+1), 0, dtype='int64') dpt = np.full((R+1,C+1,4), 0, dtype='int64') for i in range(K): r, c, v = map(int, input().split()) field[r][c] = v dp(R, C, field, dpt) print(max(dpt[-1][-1])) @njit('i4(i4,i4,i8[:,:],i8[:,:,:])', cache=True) def dp(R, C, field, dpt): for r in range(1, R+1): for c in range(1, C+1): for taken in range(4): max_v = 0 if taken == 0: max_v = max(dpt[r-1][c]) max_v = max(dpt[r][c-1][0], max_v) elif taken == 1: max_v = max(dpt[r][c-1][taken-1] + field[r][c], dpt[r][c-1][taken], max(dpt[r-1][c]) + field[r][c]) else: max_v = max(dpt[r][c-1][taken-1] + field[r][c], dpt[r][c-1][taken]) dpt[r][c][taken] = max_v return 1 if __name__ == '__main__': main()
0
null
59,488,683,628,092
256
94
S = input() flag = 0 for i in range(0,len(S)//2): if S[i] == S[-1-i]: continue else: flag = 1 print("No") break if flag == 0: S = S[:((len(S)-1)//2)] for i in range(0,len(S)//2): if S[i] == S[-1-i]: continue else: flag = 1 print("No") break if flag == 0: print("Yes")
i = 1 while True: x = int(raw_input()) if x == 0: break else: print "Case %d: %d" % (i, x) i += 1
0
null
23,497,017,114,450
190
42
a, b, c, d = map(int, input().split()) if d <= a: print(d) elif d <= a + b: print(a) else: print(a-(d-(a+b)))
a, b, c, k = map(int, input().split()) ans = 0 if a >= k: ans += k k = 0 else: ans += a k -= a if b >= k: k = 0 else: k -= b if c >= k: ans -= k print(ans)
1
21,899,896,374,444
null
148
148
a,b = map(int,input().split()) A = [str(a)*b,str(b)*a] B = sorted(A) print(B[0])
# -*- coding: utf-8 -*- import sys import os def gcd(a, b): # big - small while a != b: if a > b: a, b = b, a a, b = b - a, a return a def lcm(a, b): return a * b // gcd(a, b) lst = sys.stdin.readlines() for s in lst: a, b = map(int, s.split()) G = gcd(a, b) L = lcm(a, b) print(G, L)
0
null
42,297,297,250,592
232
5
#!/usr/bin/env python3 n = int(input()) a = [] for _ in range(n): a.append([[*map(int, input().split())] for _ in range(int(input()))]) ans = 0 for i in range(2**n): hone = set() unki = set() for j in range(n): if i >> j & 1: hone |= {j + 1} for k in a[j]: if k[1] == 1: hone |= {k[0]} else: unki |= {k[0]} else: unki |= {j + 1} if hone & unki == set(): ans = max(ans, len(hone)) print(ans)
# 解説見た n,k = map(int,input().split()) lr = [list(map(int,input().split())) for _ in range(k)] dp = [0]*(n+1) sdp = [0]*(n+1) dp[1],sdp[1] = 1,1 mod = 998244353 for i in range(1,n+1): for l,r in lr: if i-l<0: continue else: dp[i] += sdp[i-l] - sdp[max(0,i-r-1)] sdp[i] = sdp[i-1] + dp[i] dp[i] %= mod sdp[i] %= mod print(dp[-1])
0
null
62,201,282,014,620
262
74
h,n=map(int,input().split()) c=[list(map(int,input().split()))for _ in range(n)] d=[0]+[0]*20001 for i in range(h): d[i]=min(d[i-a]+b for a,b in c) print(d[h-1])
import sys sys.setrecursionlimit(10**5) input = sys.stdin.readline N, u, v = map(int, input().split()) u -= 1 v -= 1 Tree = [[] for _ in range(N)] for _ in range(N-1): A, B = map(lambda x:int(x)-1, input().split()) Tree[A].append(B) Tree[B].append(A) #u-v間の単純pathを用意する path = [] def connected(v, tv, p=-1): if v == tv: return True for w in Tree[v]: if w == p: continue elif connected(w, tv, v): path.append(w) return True return False connected(v, u) path.append(v) #u-v間の点からvとは逆方向にdfs #u-vの中点から調べれば十分(中点よりvに寄ると、青木君は捕まってしまう) def dfs(v, p): d = -1 for w in Tree[v]: if w == p: continue else: d = max(d, dfs(w, v)) return d + 1 dist = len(path) mid = path[dist//2 - 1] par = path[dist//2] ans = dfs(mid, par) print(ans + (dist-1)//2)
0
null
99,144,813,394,302
229
259
(a,b,c,d,e)=map(int,input().split()) if a==c: t=d-b if e<=t: print(t-e) else: print(0) if c>a: if b>d: t=60*(c-a)-b+d if e<=t: print(t-e) else: print(0) if b<=d: t=(c-a)*60+d-b if e<=t: print(t-e) else: print(0)
S = input() s = S[::-1] cnt = [0]*2019 cnt[0] = 1 number = 0 d = 1 for i in s: number += int(i)*d cnt[number % 2019] += 1 d *= 10 d = d % 2019 ans = 0 for i in cnt: ans += i*(i-1) // 2 print(ans)
0
null
24,394,715,156,220
139
166
import sys sys.setrecursionlimit(10 ** 9) n,m = map(int, input().split()) ab = [] c = [set() for i in range(n)] for i in range(m): a = list(map(int, input().split())) a.sort() x,y = a[0]-1,a[1]-1 c[x].add(y) c[y].add(x) def dfs(s): if vis[s] == False: ary.append(s) vis[s] = True for j in c[s]: dfs(j) vis = [False for i in range(n)] ans= [] for i in range(n): ary = [] dfs(i) if len(ary) == 0: continue ans.append(len(ary)) print (len(ans)-1)
#Union Find #xの根を求める def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return True #xとyが同じ集合に属するかの判定 def same(x,y): return find(x) == find(y) #xが属する集合の個数 def size(x): return -par[find(x)] #初期化 #根なら-size,子なら親の頂点 n,m = map(int,input().split()) par = [-1]*n for i in range(m): a,b = map(int,input().split()) unite(a-1,b-1) ans = 0 for i in range(n): if par[i] < 0: ans += 1 print(ans-1)
1
2,293,492,133,358
null
70
70
N = int(input()) a = list(map(int,input().split())) flag = True for a_i in a: if a_i%2==0: if not (a_i%3==0 or a_i%5==0): flag=False print("APPROVED" if flag else "DENIED")
n=int(input()) a=list(map(int,input().split())) for i in a: if i%2==0: if i%3!=0 and i%5!=0: print('DENIED') exit() print('APPROVED')
1
68,922,813,124,960
null
217
217
from sys import stdin input = stdin.readline().rstrip #x = input().rstrip() #n = int(input()) #a,b,c = input().split() #a,b,c = map(int, input().split()) D,T,S = map(int, input().split(" ")) if(T * S >= D): print("Yes") else: print("No")
D,T,S = map(int, open(0).read().split()) if T * S >= D: print('Yes') else: print('No')
1
3,520,369,429,472
null
81
81
import sys input = sys.stdin.buffer.readline def main(): N = int(input()) d = list(map(int,input().split())) if d[0] != 0: print(0) else: MOD = 998244353 use = [0 for _ in range(max(d)+1)] for num in d: use[num] += 1 if use[0] != 1: print(0) else: ans,pa = 1,1 for num in use: ans *= pow(pa,num,MOD) ans %= MOD pa = num print(ans) if __name__ == "__main__": main()
v, e = map(int,input().split()) par = [i for i in range(v+1)] def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] def unite(x, y): x = find(x) y = find(y) if x == y: return 0 par[x] = y for i in range(e): a, b = map(int, input().split()) unite(a, b) cnt = 0 for i in range(v+1): if i == par[i]: cnt += 1 print(cnt-2)
0
null
78,564,700,910,850
284
70
n, m = list(map(int, input().split())) print(int((n * (n-1) + m * (m-1)) / 2))
import math N,M=map(int,input().split()) def comb(num,k): if num<2: return 0 return math.factorial(num)/(math.factorial(k)*math.factorial(num-k)) ans=int(comb(N,2)+comb(M,2)) print(ans)
1
45,592,810,631,928
null
189
189
from numba import jit import numpy as np @jit def main(): R,C,K=map(int,input().split()) scores=np.zeros((R,C),np.int64) for _ in range(K): #各マスにアイテム配置 r,c,v=map(int,input().split()) scores[r-1][c-1]=v dp=np.zeros((R+1,C+1,4),np.int64) #後のために余分に作っておく、scoresの配列は別なのでindexに注意 for i in range(1,R+1): for j in range(1,C+1): for k in range(4): dp[i][j][k]=max(dp[i][j-1][k],dp[i-1][j][3]) #同じ行ですでに3つ拾ってから次の行にくるのかただ隣のマスに進むか for k in range(3,0,-1): dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+scores[i-1][j-1]) #そのマスでアイテムを拾うかどうか return dp[R][C][3] print(main())
def max2(x,y): return x if x > y else y R, C, K = map(int, input().split()) V = [[0]*R for _ in range(C)] for _ in range(K): r, c, v = map(int, input().split()) V[c-1][r-1] = v dp = [[0]*4 for _ in range(R)] for j in range(R): if V[0][j] != 0: dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j] if j != 0: dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0]) for i in range(1,C): for j in range(R): v = V[i][j] if v != 0: if dp[j][2] != 0: dp[j][3] = max2(dp[j][2] + v, dp[j][3]) if dp[j][1] != 0: dp[j][2] = max2(dp[j][1] + v, dp[j][2]) dp[j][1] = max2(v, dp[j][1]) if j != 0: if v != 0: dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1]) dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) print(max(dp[-1]))
1
5,497,421,809,840
null
94
94
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if(a >= b): b*=2 continue if(b >= c): c*=2 continue if(a<b and b<c): print("Yes") exit() else: print("No")
a=list(map(int,input().split())) k=int(input()) while a[0]>=a[1]: k-=1 a[1]*=2 while a[1]>=a[2]: k-=1 a[2]*=2 if k>=0: print("Yes") else: print("No")
1
6,924,990,088,810
null
101
101
N = int(input()) a = list(map(int, input().split())) count = 1 if 0 in a: print(0) else: for i in range(N): count *= a[i] if count > 10 ** 18: print(-1) break else: print(count)
n = int(input()) A = sorted(list(map(int, input().split())))[::-1] if 0 in A: print(0) exit() ans = 1 for a in A: ans *= a if ans > 10 **18: print(-1) exit() print(ans)
1
16,156,522,156,570
null
134
134
def check(i,N,Ls): count=0 for j in range(N): if (i>>j)%2==1: for k in Ls[j]: if ((i>>(k[0]-1))%2)!=k[1]: return 0 count+=1 return count N=int(input()) A_ls=[] Ls=[] for i in range(N): A=int(input()) A_ls.append(A) ls=[] for j in range(A): x,y=map(int,input().split()) ls.append((x,y)) Ls.append(ls) ans=0 for i in range(2**N): num=check(i,N,Ls) if num>ans: ans=num print(ans)
from itertools import product def max2(x,y): return x if x > y else y N = int(input()) data = [[] for _ in range(N)] res = 0 for i in range(N): for _ in range(int(input())): data[i].append(tuple(map(int, input().split()))) for a in product((0,1), repeat=N): flg = False for i in range(N): for x, y in data[i]: x -= 1 if a[i] == 1: if a[x] != y: flg = True break if flg: break if i == N-1: res = max2(res, sum(a)) print(res)
1
121,448,356,390,192
null
262
262
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64) import base64 import subprocess import zlib exe_bin = "c$~#qeQaCR6~DIQ#Ay@9ZBv@IKs}bC7RYN%K1fz&#EzXlgA+<Vy3)11IJVO~aO~*$8It}1VWFs|O&6vK@y9lG+Wy!kZK6^&P2HrWO9x|OTA9Swt=rTgJ{+K;6{G4l8t>fq?tOmm`n|z4q}?b!@BH35=bn4+_jyl7V*O5s1F_;lUqpmktkw8liqCG=MF8tUweWijx*1giUuBTv>2-&hdh~iUy)LK5^Ymt9rVayjBl}XUGgE~8x*qX$s$N5<>is5qlGf{UoAsPj?<mzfO63_vRF6^CzAE}ZLUEpkk(pLey8A69NuKww)_9)U={*Q~)#%d~AEiUIKD)RqP=6U^{jeh~jdix~NGDs;QYJs$GTqhL(%CNLvclb}Pd+NUYj9MRC;iPrMcy}3jJ!WJaPhMDN4JLZ?=%j@!lw)3U8nv^Wb0A6-@u~N0h-iJ)c8VOU+(!DX0oC@1^;U;@SR}rHVb^zMqY4O<G0x0-?6cC)dt^!*hn*%`)us{Y~**^;F3+fwP1e@YC^p}P0L3+_F<&q53kYiCf4E5-#I0jxbsfZ$DIh{LzCGI&M9$O!5HD_$N)~J<kTT4r=;YOfxdJ$lNyPSrBm8F>o@xbhb1`|8Is^}SZPa085L8yq-+k4#dE3lXhu@PfyiSV9_Yx;WD@vsNtpm2l2SG@rkV(JVw}w>aw<NFrA#g*E71g?fy6{y#)=%5lw33si3|bO26m(bla7wykyacT?!>$AA8x~GD?j=)KZcd|L^iLGh$L7rAP$K~abn_8JRX-o87HRWIIg6oC51BMQYN034nw0cQKXTZj6;)m#iF4;e7Df9Kiw^KXwQ51;x?gO=r(eQ%p{lkUj=I+nF21gi=678RvhrO&Y_K$R`_p}q<S**_ERjsNvb7!<Bqbt1C`f>!js#bWTlm<yt4gk9#X?Bm1pY%TkjTEX>^*y7wA4R%i*(B-s3alj6dI?(P~s)H%Pf)z&!^1k^!$Z;6($z%79-n;HwSzbpu{!z}Y+@+e5tpXY+*MUITuT+NnY1HItO@8E}^Yf6;(f8StMNaO1wWXuyr@{;v#pjR6<u-uH;d+#l8Wk$7ZLahA@DbLTuusMPT+K&7q6;kRK+FFX-`f~YKCDnZ%$6~dDyET32T!-OYYvb?DBGT}*6mS0r)M+i@vuzXVG#|TecUtUo8eZY?|Fu#I(f}?>_aAb5CJoG2UV^v$X5qAsW=BB`6aS}Add8N5dobNg10pDMCpQzPZ7@JQvHx~DUz_D<1-I2v7l7WkX%P|o4sjp)5El+~Rd%lJ(uvrE!&n-E+_czx)(Gx3Nixoa7-Ugbn!rNlu<>Cg-NMm=n*_VHP?w5|a8?O9s&yYrm^Bt|w*!R{oY?(zGe+%$uoa%GWjcPwCdQ>NSuEO&f5-70x5?EVR{9vV23M`7pV$DrSv8_&RS-u_u@Bi|F;Qru&;K8NhPeEp3Txi(xwAN4aJ#Ub9LU$Dx;gxu-=RvS5&adC6l8$rg+jE{}8QzXB1TIGluN@Q%Z-{emUfDeon|D9rAXe%>)Qo)tq)O|rx&7$xY8(LC2!=+*dG{J(u=~1LcuUy`L*v(OZD`aVC|xT1b6|;#3X^|-bgPd1&P~j0Ujcpb?21b)ToKO}?-d;{iLb3FO<?djYOszNw6izca}~w|%I^^8dhP`UFbV$DL9-tLuK1f9rBYFZCcNZ+1>_t=UG0Ytm&Voh5b*=c;~=5&!7l~(L<@fijs_tXTTeLErnWo}bU0YJ5rwYb{+2oy&fahp-}x8<eB`p?4_sva#0vj}@ewY35G*zRS%fhocK;>+E(tj6vLIeE^w)<=bZ)7$Nn1w;v*@8z4xTr=cJ|VF_+6;#IM7CD&}pE}Kwkyg4*f&+-Xzfdz$?&_yMTWasN&GhNu)Rq4<X02&#}3##<Sq4@ey1-8-w1RhIwu+5A{)bANVmv1iZd}Z_|AZs~`8wqI);(yrZr8Hl|O`mU}_YxW1Bh5dU@q?k0mg<n^6!hP+MluCUjCyejD3_KZ8|ZJnzQdv`mRS9x0j33~k?0g@rFC%76;6|gQ6KcMXbF?zq(chIZVLhAe(sR!DVLYn=r68k4y5wCx~D&*aE+%0-rpQ#qTU2`=9-d@?;6;x{p8ER4Ysw(hr0_@lx4*!pZ?UVYxNO|M^#z@!E2eua#>7vf|pfKIMHd3DL%j~+w_VZ1YvVEA{t5_d@v{K3v`T`9a+iSMb&4}$Wi}XF)OOI3k*dE$M>3U=?Y_B^?_b1jjY$IUfmhD*^DBW9Q#=EM`e*0<tY|m%)--^s~|0-$ib5Ll7@)u}BOO$7RU7`GG`u-o3H}1`!Wzp}GT)Bxh;C4zoDeb3p52fQC^gk7L?%LJY_XYp9(Xo6+$@}jSI)v7iw!F#(o(Oaat?k=2^wZdMLA1LpCLuYyj#%O@q*&rr`nWXXZhbtO@oIhCn(-RFKh3yD9|vZ<Rv&L>e3d>f&G>44ewy(*^I=uT>(P`Y?nSefc!NIQ&A1Qkw#3)yc>^=P7M--j*Xiqr8E@3r4Ku#pa@@MmP5L}H<1njzR(SayYQ{HKU}U;ip{pexCwE*Y#Eq@10>y7vb(+x3TEDJON{5Y|UTWt`tr-tdymgfsAEo##hd)Z|o#yI2tUg!9^V`(UB4_7^s(fX?*!lmeD!&%JS;xPzmj9FbTRBcHt9B~;_nP{<uEPHshlcZhZgLPimE)mRy;p8PKCa(0PLju{94Ggv`HJ#5XVbgiCQp*L$@6>;5&81`a?_4^j@Wl@(APm$zGY+ol9S+-^YO<v^0HH_m*rL2neDud{ApFbay@yU`pL)bx{aMtr*)nu?bPDW$Jwd&OB0%1YsP1s8qU{y#A#jc4`_SO)A5|5_!*~lp6d5hzL&<6E$eSPt@BYI+tj<+Wo`cs8$9f?wu3@=R~9Q-d|zBj3yG;Igm=Xr2nAyp=kjAXs%36SGAP!Cv6PiEl7bSll2h{I<3a+Jb75GS#0iq~${~!CS$rs+9gC-NQpw6W9M4aqM0Rp2ol;Us;hxU!E^8r@K9X=;mg6%xl~LpwG%m*{Q#hHQoSXp_1BZz#CQ*$0hk^qU92pFgR2|+mIEo`81;y|X!r_Mog9Fh%cxO^hngKOsrN`lc{{G>}2p$QBViB;KO2(Bq!qErRd|U?SbE)JfC+&KBjfpLDri{L$=`aXOE{iAPnWQOkXk|dlyYcGg6kYi((Ha@(W6}96lZYnggzj?gkoTIzj)fPG<#O!VItR&XtNFx4F0c00e@?}gWyyfjv#ypF%Na^Ol$EJp+w`tQD%V^Y5^^(>N_-5cB5QPlJxLibIfaBwR!IrLP_#vfAEMl$OkNnvOX*~bltd~w5zkE^Avu!)dm2?_?agB;IVWW^CI-VhIhBqRLHab6R!Ef)Lh>ja%EAMTB=}WhCCFKIhzqF+I^8Cca+%XqwV9%6uxF?tJ}D*OK~;zDMFPzENtm2g3(tR7$UToNiEO>J`;NwngX2Gsw7V74=f6|=IeGqA9pLoY`JK_`PtYg#{%dfzV*2cy&*(Oav*S5`EFMJK-IM9F`v9X8w87*U?=a}Id*U8s{x-$#4U8V=0>;PhAkyxROrPB^7-jcR=0EqjP(3HE81&gagwcml*?%XhY(F_qRvGNE`wFA%e$2;@wf||VAEG?F*D%WN=S2S|3;h$w_>HcdpJ0^T<5}VRzrg92KLluGij((o^y{2HyH7F7$BQ$MzRBscb0MR@;O>_`Gpl~@GwQSRAfwzhqN4rZN9Os<&bN&6*EC-L6sK?Zz1U9w=bS#f7cwex1D=oPD@gn9!SXxh@5dU?$BU2u>+s)T&}a9G*?Q~xc>TX2E%thTN&h}i0ot%?PLKKZ0@B*g=ckS~X#Dgi)c-E0ub-!V=6ZO2R<2Nt>Feios@Thozg|xNBU(S7kYW1UIovAGXq6}JrTQ0W;K)AHf-2{Kt-*I=X`&Nf;$HIW=NcRRr)a`*g~NIMe*+LGoE`" open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod +x ./kyomu"], shell=True) subprocess.run(["./kyomu"], shell=True)
n = int(input()) s = 0 b = False for _ in range(n): w = input().split() if w[0] == w[1]: s += 1 if s == 3: b = True break else: s = 0 print('Yes' if b else 'No')
1
2,485,559,748,854
null
72
72
n = int(input()) s = [None] * n for i in range(n): s[i] = input() print(len(list(set(s))))
N = int(input()) ga = [] for _ in range(N): ga.append(input()) ga = set(ga) print(len(ga))
1
30,050,682,126,304
null
165
165
class Dice: def __init__(self, state): self.state = state def vertical(self, direction): s = self.state state = [s[1], s[5], s[0], s[4]] if direction < 0: s[0], s[1], s[4], s[5] = state elif 0 < direction: s[0], s[1], s[4], s[5] = reversed(state) return self def lateral(self, direction): s = self.state state = [s[2], s[5], s[0], s[3]] if direction < 0: s[0], s[2], s[3], s[5] = state elif 0 < direction: s[0], s[2], s[3], s[5] = reversed(state) return self def north(self): self.vertical(-1) return self def south(self): self.vertical(1) return self def east(self): self.lateral(1) return self def west(self): self.lateral(-1) return self init_state = input().split() for i in range(int(input())): dice = Dice(init_state) up, front = input().split() if up == dice.state[0] \ and front == dice.state[1]: print(dice.state[2]) else: for c in list('NNNNWNNNWNNNENNNENNNWNNN'): if c == 'N': dice.north() elif c == 'S': dice.south() elif c == 'W': dice.west() elif c == 'E': dice.east() if up == dice.state[0] \ and front == dice.state[1]: print(dice.state[2]) break
#!/usr/bin/env python # -*- coding: utf-8 -*- POSITIONS = ["top", "south", "east", "west", "north", "bottom"] class Dice(object): def __init__(self, initial_faces): self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)} self.store_previous_faces() def store_previous_faces(self): self.previous_faces = self.faces.copy() def change_face(self, after, before): self.faces[after] = self.previous_faces[before] def change_faces(self, rotation): self.change_face(rotation[0], rotation[1]) self.change_face(rotation[1], rotation[2]) self.change_face(rotation[2], rotation[3]) self.change_face(rotation[3], rotation[0]) def roll(self, direction): self.store_previous_faces() if direction == "E": self.change_faces(["top", "west", "bottom", "east"]) elif direction == "N": self.change_faces(["top", "south", "bottom", "north"]) elif direction == "S": self.change_faces(["top", "north", "bottom", "south"]) elif direction == "W": self.change_faces(["top", "east", "bottom", "west"]) def rolls(self, directions): for d in directions: self.roll(d) def main(): dice = Dice(input().split()) q = int(input()) for x in range(q): [qtop, qsouth] = input().split() if qsouth == dice.faces["west"]: dice.roll("E") elif qsouth == dice.faces["east"]: dice.roll("W") while qsouth != dice.faces["south"]: dice.roll("N") while qtop != dice.faces["top"]: dice.roll("W") print(dice.faces["east"]) if __name__ == "__main__": main()
1
264,522,964,060
null
34
34
N,K=map(int,input().split()) H=list(map(int,input().split())) ans=0 for h in H: if K<=h: ans=ans+1 print(ans)
import sys import math import fractions from collections import defaultdict stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) N,K=nm() A=nl() imos_l=[0]*(N+1) for i in range(K): imos_l=[0]*(N+1) for j in range(len(A)): imos_l[max(j-A[j],0)]+=1 imos_l[min(j+A[j]+1,N)]-=1 for j in range(len(imos_l)-1): imos_l[j+1]=imos_l[j]+imos_l[j+1] for j in range(len(A)): A[j]=imos_l[j] flag=True for j in range(len(A)): if(A[j]<N): flag=False if(flag): print(*A) sys.exit(0) print(*A)
0
null
97,071,894,034,412
298
132
# Pythonのスライスは最後が開区間だから癖がある t = input() for i in range(int(input())): cmd = list(input().split()) cmd[1] = int(cmd[1]) cmd[2] = int(cmd[2]) if cmd[0] == "print": print(t[cmd[1] : cmd[2]] + t[cmd[2]]) elif cmd[0] == "reverse": tmp = t[cmd[1] : cmd[2]] + t[cmd[2]] tmp = tmp[::-1] t = t[:cmd[1]] + tmp + t[cmd[2]+1:] elif cmd[0] == "replace": t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]
a, b = map(int, input().split()) s1 = str(a)*b s2 = str(b)*a if s1<s2 : print(s1) else: print(s2)
0
null
43,453,928,413,240
68
232
N = int(input()) s = list(input()) cnt = 0 for i in range(N-2): if s[i] == 'A': if s[i+1] == 'B': if s[i+2] == 'C': cnt += 1 print(cnt)
N = int(input()) S = input() cnt = 0 for i in range(N): if S[i:i+3] == "ABC": cnt += 1 print(cnt)
1
99,672,064,294,400
null
245
245
import sys import math n=int(input()) A=[] xy=[[]]*n for i in range(n): a=int(input()) A.append(a) xy[i]=[list(map(int,input().split())) for _ in range(a)] ans=0 for bit in range(1<<n): tmp=0 for i in range(n): if bit>>i & 1: cnt=0 for elem in xy[i]: if elem[1]==1: if bit>>(elem[0]-1) & 1: cnt+=1 else: if not (bit>>(elem[0]-1) & 1): cnt+=1 if cnt==A[i]: tmp+=1 else: continue if tmp==bin(bit).count("1"): ans=max(bin(bit).count("1"),ans) print(ans)
n = int(input()) graph = [[-1 for _ in range(n)] for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x, y = map(int, input().split()) graph[i][x-1] = y ans = 0 for p in range(2**n): q = p c = 0 t = [] l = 0 while q: if q&1: t.append(graph[c]) l += 1 q >>= 1 c += 1 flag = True for c in range(n): if p&1: for s in t: if s[c] == 0: flag = False else: for s in t: if s[c] == 1: flag = False p >>= 1 if flag: ans = max(ans, l) print(ans)
1
121,643,231,774,962
null
262
262
H,W,k = map(int, input().split()) cell = [input() for i in range(H)] cnt = 0 for h in range(1 << H): for w in range(1 << W): black = 0 for i in range(H): if (h >> i) % 2 == 1: continue for j in range(W): if (w >> j) % 2 == 1: continue black += cell[i][j] == '#' cnt += black == k print(cnt)
from itertools import combinations n,m,k = map(int,input().split()) mat = [] for _ in range(n): mat.append(list(input())) def black(row,col): new = [mat[i] for i in range(n) if i not in row] if not new:return 0 new = list(zip(*new)) new = [new[i] for i in range(m) if i not in col] if not new:return 0 return sum([i.count("#") for i in new]) ans = 0 rows = [] cols = [] for i in range(0,n+1): rows += list(combinations([i for i in range(n)],i)) for i in range(0,m+1): cols += list(combinations([i for i in range(m)],i)) #print(rows,cols) for row in rows: for col in cols: if black(set(row),set(col))==k: #print(row,col) ans+=1 print(ans)
1
8,933,984,180,882
null
110
110
h, w, k = map(int, input().split()) S = [list(input()) for _ in range(h)] ans = S.copy() index = 1 for i in range(h): for j in range(w): if S[i][j] == "#": ans[i][j] = str(index) index += 1 for i in range(h): for j in range(w-1): if ans[i][j] != "." and ans[i][j+1] == ".": ans[i][j+1] = ans[i][j] for i in range(h): for j in range(w-1, 0, -1): if ans[i][j] != "." and ans[i][j-1] == ".": ans[i][j-1] = ans[i][j] for j in range(w): for i in range(h-1): if ans[i][j] != "." and ans[i+1][j] == ".": ans[i+1][j] = ans[i][j] for j in range(w): for i in range(h-1, 0, -1): if ans[i][j] != "." and ans[i-1][j] == ".": ans[i-1][j] = ans[i][j] for l in ans: print(" ".join(l))
import sys from collections import deque input = sys.stdin.readline def main(): h, w, k = map(int, input().split()) board = [input().strip() for i in range(h)] group = [[0 for i in range(w)] for j in range(h)] state = 0 # 0:not found, 1:one strawberry num = 1 stock = 1 pre = -1 for i in range(h): if "#" not in board[i]: stock += 1 continue for j in range(w): if board[i][j] == "#": if state == 0: state = 1 else: num += 1 group[i][j] = num else: group[i][j] = num for k in range(stock): for j in range(w): print(group[i][j], end=" ") print() num += 1 state = 0 stock = 1 pre = i for k in range(h-pre-1): for j in range(w): print(group[pre][j], end=" ") print() if __name__ == "__main__": main()
1
143,967,050,613,200
null
277
277
l=input().split() n=int(l[0]) m=int(l[1]) #receive vecter a(n*m) i=0 A=[] while i<n: a=input().split() for p in a: A.append(int(p)) i+=1 #receive vecter b(m*1) I=0 B=[] while I<m: b=int(input()) B.append(b) I+=1 #Ci=ai1b1+ai2b2+...+aimbm #C[i]=a[m*(i)+1]*b[1]+a[m*(i)+2]*b[2]+...a[m*(i)+m]*b[m] q=0 C=[] while q<n: Q=0 cq=0 while Q<m: cq+=A[m*q+Q]*B[Q] Q+=1 C.append(cq) q+=1 for x in C: print(x)
n=int(input()) s=str(input()) ans="Yes" if len(s)%2==1: ans="No" for i in range(len(s)//2): if s[i]!=s[len(s)//2+i]: ans="No" break print(ans)
0
null
74,288,724,983,408
56
279
#!/usr/bin python3 # -*- coding: utf-8 -*- t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) s1 = a1 - b1 s2 = a2 - b2 # a1 が先行にする if s1<0: s1*=-1 s2*=-1 d = s1*t1 + s2*t2 mxd = s1*t1 if d>0: print(0) elif d==0: print('infinity') else: if mxd%abs(d)==0: print(mxd//abs(d)*2) else: print(mxd//abs(d)*2+1)
n, m = [int(s) for s in input().split()] ans = "Yes" if m == n else "No" print(ans)
0
null
107,682,621,985,630
269
231
N=int(input()) A = list(map(int, input().split())) c=0 for i in range(0,len(A),2): if A[i]%2==1: c+=1 print(c)
n = int(input()) a = [int(x) for x in input().split()] cnt = 0 for a0 in a[::2]: if a0%2 == 1: cnt += 1 print(cnt)
1
7,779,908,415,772
null
105
105
D,T,S=map(int,input().split()) print("Yes" if D<=T*S else "No")
import math n=int(input()) ans=n-1 for i in range(2,int(math.sqrt(n))+1): if n%i==0: ans=min(ans,(i-1)+(n//i)-1) print(ans)
0
null
82,472,854,556,388
81
288
import math a, b, C = map(float, input().split()) h = b * math.sin(math.radians(C)) S = a * h / 2 a1 = b * math.cos(math.radians(C)) cc = math.sqrt(h * h + (a - a1) * (a - a1)) print("{a:5f}".format(a=S)) print("{a:5f}".format(a=a + b + cc)) print("{a:5f}".format(a=h))
from math import sqrt, radians, sin, cos class Triangle (object): def __init__(self, a, b, C): self.a = a self.b = b self.C = radians(C) def getArea(self): return self.a * self.getHeight() / 2 def getPerimeter(self): return self.a + self.b + sqrt(self.a ** 2 - 2 * self.a * self.b * cos(self.C) + self.b ** 2) def getHeight(self): return self.b * sin(self.C) tri = Triangle(*[int(e) for e in input().split()]) print(tri.getArea()) print(tri.getPerimeter()) print(tri.getHeight())
1
174,818,137,212
null
30
30
import sys input = sys.stdin.readline INF = 99999#1001001001 from collections import deque def linput(ty=int, cvt=list): return cvt(map(ty,input().split())) def pad(mxy, wall="#"): w = len(mxy[0]) gp = wall*(w+2) re = [gp,] re_app = re.append for vx in mxy: re_app(wall+vx+wall) re_app(gp) return re vD = [(0,1),(1,0)] vQ = deque([]) vQ_app, vQ_popl = vQ.append, vQ.popleft def main(): H,W = linput() mM = [input().rstrip() for _ in [0,]*H] mM = pad(mM, "$") res = 0 cnt = 0 for sr in range(1,1+1): for sc in range(1,1+1): if mM[sr][sc]=="#": res += 1 mV = [[INF,]*(W+2) for _ in [INF,]*(H+2)] mV[sr][sc] = res vQ_app((sr,sc)) while vQ: r,c = vQ_popl() now_cost = mV[r][c] now_s = mM[r][c] for dr,dc in vD: nr,nc = r+dr, c+dc if mM[nr][nc]=="$": continue next = now_s=="."!=mM[nr][nc] new_cost = now_cost + next if new_cost < mV[nr][nc]: vQ_app((nr,nc)) mV[nr][nc] = new_cost cnt += 1 #print(res,cnt,X,Y,H) if cnt>999999: break #print(*mV,sep="\n")### res = mV[H][W] print(res) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(H: int, W: int, s: "List[str]"): dp = [[0 for w in range(W)] for h in range(H)] # dp[h][w]はh,wに達するための回数 if s[0][0] == '#': dp[0][0] = 1 for w in range(W-1): # 0行目について if s[0][w+1] == '.': # 移動先が白だったら特に変わりなし dp[0][w+1] = dp[0][w] elif s[0][w] == '.' and s[0][w+1] == '#': # 移動元が白で先が黒ならば、新しく施行1回追加 dp[0][w+1] = dp[0][w] + 1 elif s[0][w] == '#' and s[0][w+1] == '#': # 移動元も先も黒だったとしたら、試行回数は変わらない dp[0][w+1] = dp[0][w] for h in range(H-1): # 1列目について if s[h+1][0] == '.': dp[h+1][0] = dp[h][0] elif s[h][0] == '.' and s[h+1][0] == '#': dp[h+1][0] = dp[h][0] + 1 elif s[h][0] == '#' and s[h+1][0] == '#': dp[h+1][0] = dp[h][0] for h in range(1, H): for w in range(W-1): if s[h][w+1] == '.': dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]) elif s[h][w] == '.' and s[h][w+1] == '#': if s[h-1][w+1] == '.': dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1]+1) elif s[h-1][w+1] == '#': dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1]) elif s[h][w] == '#' and s[h][w+1] == '#': if s[h-1][w+1] == '.': dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]+1) elif s[h-1][w+1] == '#': dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]) print(dp[H-1][W-1]) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() H = int(next(tokens)) # type: int W = int(next(tokens)) # type: int s = [next(tokens) for _ in range(H)] # type: "List[str]" solve(H, W, s) if __name__ == '__main__': main()
1
49,365,737,125,528
null
194
194
input_num = int(input()) input_str = input() if len(input_str) <= input_num: print(input_str) else: print(input_str[:input_num]+"...")
import sys s = sys.stdin cnt = 1 for i in s: if int(i)== 0: break print("Case {0}: {1}".format(cnt,i),end="") cnt += 1
0
null
10,124,104,342,982
143
42
h,n,a=map(int,input().split()) if h+n+a<=21: print("win") else: print("bust")
a = input() b = input() if '1' not in [a, b]: print('1') if '2' not in [a, b]: print('2') if '3' not in [a, b]: print('3')
0
null
114,387,022,176,098
260
254
M=998244353 n,m,k=map(int,input().split()) p,c=[m]*n,[1]*n for i in range(1,n): p[i]=p[i-1]*(m-1)%M c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)
N = int(input()) C = input().split() B = C[:] S = C[:] # bubble sort flag = 1 while(flag): flag = 0 for x in range(1, N): if B[x][1:] < B[x-1][1:]: B[x], B[x-1] = B[x-1], B[x] flag = 1 # sectionSot for x in range(0,N): minj = x for j in range(x,N): if S[j][1:] < S[minj][1:]: minj = j if minj != x: S[x], S[minj] = S[minj], S[x] print(" ".join(b for b in B)) print("Stable") if(B == S): print(" ".join(b for b in S)) print("Stable") else: print(" ".join(b for b in S)) print("Not stable")
0
null
11,708,832,432,576
151
16
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = inpl() if 0 in set(a): print(0) quit() res = 1 for x in a: res *= x if res > 10**18: print(-1) quit() print(res)
N = int(input()) A = list(map(int, input().split())) A.sort() result = 1 for i in range(N): result *= A[i] if result > 10**18: result = -1 break print(result)
1
16,191,561,914,738
null
134
134
(N,) = [int(x) for x in input().split()] brackets = [input() for i in range(N)] delta = [] minDelta = [] for s in brackets: balance = 0 mn = 0 for c in s: if c == "(": balance += 1 else: balance -= 1 mn = min(mn, balance) delta.append(balance) minDelta.append(mn) if sum(delta) == 0: # Want to get balance as high as possible # Take any positive as long there's enough balance to absorb their minDelta # Can sort since anything that works will only increase balance and the ones with worse minDelta comes later posIndices = [i for i in range(N) if delta[i] > 0] posIndices.sort(key=lambda i: minDelta[i], reverse=True) # At the top can take all with zero delta, just need to absorb minDelta eqIndices = [i for i in range(N) if delta[i] == 0] # When going back down, want to preserve existing balance as much as possible but take a hit for stuff that does need to use the balance to absorb minDelta negIndices = [i for i in range(N) if delta[i] < 0] negIndices.sort(key=lambda i: delta[i] - minDelta[i], reverse=True) balance = 0 for i in posIndices + eqIndices + negIndices: if balance + minDelta[i] < 0 or balance + delta[i] < 0: print("No") exit() balance += delta[i] assert balance == 0 print("Yes") else: print("No")
import math while True: try: a,b=map(int,input().split()) print(*[math.gcd(a,b),a*b//math.gcd(a,b)]) except:break
0
null
11,915,118,221,942
152
5
N=int(input()) *A,=map(int,input().split()) total=0 for i in range(N): total ^= A[i] print(*[total^A[i] for i in range(N)])
import itertools while True: n, x = map(int, input().split()) if n == x == 0: break result = 0 for i in itertools.combinations(range(1, n + 1), 3): if sum(i) == x: result += 1 print(result)
0
null
6,980,320,320,600
123
58
n = int(input()) s = input() count = 0 for i in range(len(list(s))-2): if s[i] == "A" and s[i+1] == "B" and s[i+2] =="C": count += 1 print(count)
def solve(n,s): cnt = 0 for i in range(len(s)-2): if "ABC" == s[i:i+3]: cnt+=1 return cnt n = int(input()) s = input() ans = solve(n,s) print(ans)
1
99,375,795,514,050
null
245
245
se = set([]) n = int(raw_input()) for i in range(n): s = raw_input().split() if s[0] == 'insert': se.add(s[1]) elif s[0] == 'find': if s[1] in se: print 'yes' else: print 'no'
h = int(input()) p = 1 i = 1 while h > 1: h = h // 2 p += 2 ** i i += 1 print(p)
0
null
40,150,805,368,948
23
228
n, k, s = map(int,input().split()) if s == 10**9: ans = [1 for i in range(n)] for i in range(k): ans[i] = 10**9 else: ans = [10**9 for i in range(n)] for i in range(k): ans[i] = s print(" ".join(map(str,ans)))
X = int(input()) while True: flag = True for i in range(2, X): if X % i == 0: flag = False if flag: break X += 1 print(X)
0
null
97,773,350,087,740
238
250
while True: a,op,b=input().split() a,b=int(a),int(b) if op=="+": print(a+b) elif op=="-": print(a-b) elif op=="*": print(a*b) elif op=="/": print(a//b) else: break
ans = [] while True: arr = map(str, raw_input().split()) if arr[1] is '?': break val = eval(arr[0] + arr[1] + arr[2]) ans.append(val) print("\n".join(map(str, ans)))
1
695,306,558,632
null
47
47
x, y, p, q = map(float, input().split()) ans = ((p-x)**2 + (q-y)**2)**0.5 print(f"{ans:.8f}")
import math x1,y1,x2,y2=map(float,input().split()) a=(x2-x1)**2+(y2-y1)**2 l=math.sqrt(a) print(f'{l:.8f}')
1
156,709,209,382
null
29
29
a=[int(input()) for i in range(10)] a.sort(reverse=True) for i, iv in enumerate(a): print(iv) if i >= 2: break
# coding: utf-8 # Here your code ! import sys n = [int(input()) for i in range (1,11)] #t = [int(input()) for i in range(n)] n.sort() n.reverse() for j in range (0,3): print(n[j])
1
42,328,832
null
2
2
N = int(input()) S = input() #print(ord("A")) #print(ord("B")) #print(ord("Z")) for i in range(len(S)): ascii = ord(S[i]) + N #Sのi文字目のアスキーコードを計算してしれにNを足してづらす if ascii > ord("Z"): #アスキーコードがよりも大きくなった時はA初まりにづらす ascii = ascii - (ord("Z") - ord("A") + 1) print(chr(ascii),end = "") #,end = "" は1行ごとに改行しないでプリントする仕組み
n = int(input()) s = input() cnt = 0 for i in range(len(s)): if s[i] == "A" and i+2 <= len(s)-1: if s[i+1] == "B": if s[i+2] == "C": cnt += 1 print(cnt)
0
null
117,129,295,955,000
271
245
import math X = int(input()) print(X * 2 * math.pi)
R,C,K = map(int, input().split()) a = [[0] * (C+1) for i in range(R+1)] dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)] for i in range(K): r,c,v = map(int, input().split()) r -= 1 c -= 1 a[r][c] = v for i in range(R): for j in range(C): for k in range(2,-1,-1): dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + a[i][j]) for k in range(4): dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j]) dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j]) ans = 0 for k in range(4): ans = max(ans, dp[k][R-1][C-1]) print(ans)
0
null
18,625,371,387,940
167
94
h, w = map(int,input().split()) maze = [] for i in range(h): t = list(input()) maze.append(t) dx = [1, 0] dy = [0, 1] dp = [[10000]*w for i in range(h)] if maze[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for x in range(w): for y in range(h): for dxi, dyi in zip(dx, dy): if not (0<=x+dxi<w and 0<=y+dyi<h): continue dp[y+dyi][x+dxi] = min(dp[y+dyi][x+dxi], dp[y][x]+(maze[y][x]=="." and maze[y+dyi][x+dxi]=="#")) #print(*dp) print(dp[h-1][w-1])
import sys readline = sys.stdin.readline inf = float('inf') def main(): H, W = map(int, readline().split()) grid = [] grid.append(['*'] * (W+2)) for _ in range(H): grid.append(['*'] + list(readline()[:-1]) + ['*']) grid.append(['*']*(W+2)) DP = [[inf] * (W+2) for _ in range(H+2)] DP[1][1] = (grid[1][1] == '#')*1 for i in range(1, H+1): for j in range(1, W+1): if i == 1 and j == 1: continue k = i gridkj = grid[k][j] if gridkj == '.': DP[k][j] = min(DP[k][j-1], DP[k-1][j]) if gridkj == '#': DP[k][j] = min(DP[k][j-1]+(grid[k][j-1] in ['.', '*']), DP[k-1][j] + (grid[k-1][j] in ['.', '*'])) ans = DP[H][W] print(ans) if __name__ == "__main__": main()
1
49,498,123,430,592
null
194
194
n = int(input()) t_p = 0 h_p = 0 for i in range(n): taro, hana = [i for i in input().split()] if taro > hana: t_p += 3 elif taro == hana: t_p += 1 h_p += 1 else: h_p += 3 print(f'{t_p} {h_p}')
import sys lines = [line.split() for line in sys.stdin] T = H = 0 n = int(lines[0][0]) for w1,w2 in lines[1:]: if w1 > w2: T += 3 elif w1 < w2: H += 3 else: T += 1 H += 1 print (str(T) + " " + str(H))
1
2,002,350,457,458
null
67
67
n, m = map(int, input().split()) h = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] ans = [1]*n for i in range(m): if h[ab[i][0]-1] == h[ab[i][1]-1]: ans[ab[i][0]-1] = 0 ans[ab[i][1]-1] = 0 elif h[ab[i][0]-1] > h[ab[i][1]-1]: ans[ab[i][1]-1] = 0 else: ans[ab[i][0]-1] = 0 print(sum(ans))
# -*- coding: utf-8 -*- mat1 = {} mat2 = {} n, m, l = map(int, raw_input().split()) for i in range(1, n+1): list = map(int, raw_input().split()) for j in range(1, m+1): mat1[(i, j)] = list[j-1] for j in range(1, m+1): list = map(int, raw_input().split()) for k in range(1, l+1): mat2[(j, k)] = list[k-1] for i in range(1, n+1): buf = "" for k in range(1, l+1): res = 0 for j in range(1, m+1): res += mat1[(i, j)]*mat2[(j, k)] buf += str(res) +" " buf = buf.rstrip() print buf
0
null
13,222,817,409,760
155
60
def main(): n = int(input()) print(b(n)) def b(n: int) -> int: m = 100 i = 0 while True: m = m * 101 // 100 i += 1 if m >= n: break return i if __name__ == '__main__': main()
import sys read = sys.stdin.readline import time import math import itertools as it def inp(): return int(input()) def inpl(): return list(map(int, input().split())) start_time = time.perf_counter() # ------------------------------ X = inp() yen = 100 for i in range(10**4): yen += (yen // 100) if yen >= X: print(i+1) break # ----------------------------- end_time = time.perf_counter() print('time:', end_time-start_time, file=sys.stderr)
1
27,102,335,030,748
null
159
159
d,t,s=map(int, input().split()) if d/s<=t: print("Yes") else: print("No")
import sys import math def str_input(): S = raw_input() if S[len(S)-1] == "\r": return S[:len(S)-1] return S def float_to_str(num): return str("{:.10f}".format(num)) def list_input(tp): return map(tp, str_input().split()) # # # # # # # # # # # # # # # # # # # # # # # # # class Dice: pip = [0 for i in xrange(6)] def __init__(self, arg): self.pip = arg def rollDir(self, dr): nextPip = [0 for i in xrange(6)] if dr == "N": nextPip[0] = self.pip[1] nextPip[1] = self.pip[5] nextPip[2] = self.pip[2] nextPip[3] = self.pip[3] nextPip[4] = self.pip[0] nextPip[5] = self.pip[4] elif dr == "E": nextPip[0] = self.pip[3] nextPip[1] = self.pip[1] nextPip[2] = self.pip[0] nextPip[3] = self.pip[5] nextPip[4] = self.pip[4] nextPip[5] = self.pip[2] self.pip = nextPip def roll(self, dr): if dr == "N" or dr == "E": self.rollDir(dr) elif dr == "S": self.rollDir("N") self.rollDir("N") self.rollDir("N") elif dr == "W": self.rollDir("E") self.rollDir("E") self.rollDir("E") dice = Dice(list_input(int)) for i in xrange(input()): a, b = list_input(int) while dice.pip[0] != a: if dice.pip[2] != a and dice.pip[3] != a: dice.roll("N") else: dice.roll("N") dice.roll("W") dice.roll("S") while dice.pip[1] != b: dice.roll("N") dice.roll("W") dice.roll("S") print dice.pip[2]
0
null
1,891,677,106,368
81
34
n,x, m = map(int, input().split()) mod = [None for _ in range(m)] count = x loop = [] rem = [x] for i in range(1, n): value = (x * x) % m rem.append(value) x = (x * x) % m if mod[value] != None: # print(mod) s_index = mod[value] loop = rem[s_index : -1] num = (n - s_index) // len(loop) amari = (n - s_index) % len(loop) if amari == 0: print(sum(rem[:s_index]) + sum(loop) * num) else: print(sum(rem[:s_index]) + sum(loop) * num + sum(loop[:amari])) exit() else: mod[value] = i count += value print(count)
n, x, m = map(int, input().split()) ans = [] c = [0]*m flag = False for i in range(n): if c[x] == 1: flag = True break ans.append(x) c[x] = 1 x = x**2 % m if flag: p = ans.index(x) l = len(ans) - p d, e = divmod(n-p, l) print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e])) else: print(sum(ans))
1
2,830,356,743,452
null
75
75
# 動的計画法で求める s = int(input()) mod = 10 ** 9 + 7 A = [0, 0, 0, 1, 1, 1, 2, 3] for i in range(8, 2000 + 1): ans = (sum(A[:i - 3 + 1]) + 1) % mod #Aの先頭からi-3+1までを取得 A.append(ans)#配列に結果を加える print(A[s])
max_n=10**5 mod=10**9+7 frac=[1] for i in range(1,max_n+1): frac.append((frac[-1]*i)%mod) inv=[1,1] inv_frac=[1,1] for i in range(2,max_n): inv.append((mod-inv[mod%i]*(mod//i))%mod) inv_frac.append((inv_frac[-1]*inv[-1])%mod) def perm(m,n): if m<n: return 0 if m==1: return 1 return (frac[m]*inv_frac[m-n])%mod def comb(m,n): if m<n: return 0 if m==1: return 1 return (frac[m]*inv_frac[n]*inv_frac[m-n])%mod s=int(input()) c=0 for i in range(1,s//3+1): ss=s-i*3 c=(c+comb(ss+i-1,i-1))%mod print(c)
1
3,305,419,055,652
null
79
79
S = input() mod2019 = [0]*len(S) mod2019[-1] = int(S[-1]) keta_mod = 1 for i in range(len(S)-2,-1,-1): keta_mod = (keta_mod*10)%2019 mod2019[i] = (mod2019[i+1] + int(S[i])*keta_mod)%2019 mod2019.extend([0]) answer = 0 count = [0 for _ in range(2020)] for i in range(len(S)+1): answer += count[mod2019[i]] count[mod2019[i]] += 1 print(answer)
h , w , k = map(int,input().split()) cho = [list(input()) for i in range(h)] ans = 10**9 for i in range(2**(h-1)): cut = [0 for i in range(h)] for j in range(h-1): if i >> j & 1 == 1: cut[j+1] = cut[j]+1 else: cut[j+1] = cut[j] maxcut = max(cut)+1 cou = [0 for i in range(maxcut)] ccho = [[0 for i in range(w)] for j in range(maxcut)] for j in range(h): for l in range(w): ccho[cut[j]][l] += int(cho[j][l]) tyu = maxcut - 1 hukanou = False for j in range(w): flag = True for l in range(maxcut): if cou[l] + ccho[l][j] > k: flag = False break if flag: for l in range(maxcut): cou[l] += ccho[l][j] elif not flag: tyu += 1 for l in range(maxcut): if ccho[l][j] > k: hukanou = True break cou[l] = ccho[l][j] if hukanou: break if hukanou: continue ans = min(ans,tyu) print(ans)
0
null
39,514,616,827,740
166
193
n = input() a = list(map(int, input().split())) max = 0 step = 0 for i in a: if max > i: step += max - i else: max = i print(step)
x=int(input()) a=0 while True: for b in range(10**3): if a**5-b**5==x: print(a,b) exit() elif a**5+b**5==x: print(a,-b) exit() elif -a**5+b**5==x: print(-a,-b) exit() a+=1
0
null
15,089,256,770,940
88
156
N, M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) As = [0]*(N+1) for i in range(N): As[i+1] = As[i] + A[i] A.reverse() import bisect def flag(x): ans = 0 for i in range(N): a = x - A[i] res = bisect.bisect_left(A, a) ans += (N-res) return bool(ans >= M) def an(x): ans = 0 m = 0 for i in range(N): a = x - A[i] res = bisect.bisect_left(A, a) m += (N-res) ans += As[N-res] ans += A[i] * (N-res) ans -= (m - M) * x return ans low = 0 high = 10**6 while low <= high: mid = (low + high) // 2 if flag(mid): if not flag(mid+1): ans = mid break else: low = mid + 1 else: high = mid - 1 print(an(ans))
if __name__ == '__main__': current_no = 1 while True: input_num = int(input()) if input_num != 0: print('Case {0}: {1}'.format(current_no, input_num)) current_no += 1 else: break
0
null
54,272,821,560,320
252
42
import sys printf = sys.stdout.write ans = [] while True: word = list(raw_input()) if word[0] == "-": break x = input() suff = [] for i in range(x): suff.append(input()) for i in range(len(suff)): for j in range(suff[i]): word.insert(int(len(word)), word[0]) del word[0] ans.append(word) word = 0 for i in range(len(ans)): for j in range(len(ans[i])): printf(ans[i][j]) print ""
k,n = map(int,input().split()) lst = list(map(int,input().split())) m = 0 for i in range(n-1): m = max(lst[i+1]-lst[i],m) m = max(m,k+lst[0]-lst[n-1]) print(k-m)
0
null
22,827,506,011,332
66
186
import sys import collections import bisect readline = sys.stdin.readline def main(): n = int(readline().rstrip()) aList = sorted(list(map(int, readline().rstrip().split()))) z = [0] * n for a in aList: z[a-1] += 1 for i in range(n): print(z[i]) if __name__ == '__main__': main()
n = int(input()) arr = [0] * n for i in input().split(): i = int(i) arr[i - 1] += 1 for i in range(n): print(arr[i])
1
32,505,834,867,012
null
169
169
HM = list(map(int, input().split())) hours = HM[2]-HM[0] minutes = HM[3]-HM[1] K = HM[4] totalTimes = hours*60+minutes print(totalTimes-K)
s = raw_input() p = raw_input() idx = [] for i in range(0,len(s)): if s[i] == p[0]: idx.append(i) for i in idx: for j in range(0,len(p)): if p[j] == s[(i+j)%len(s)]: continue else: break else: print 'Yes' break else: print 'No'
0
null
9,943,677,428,798
139
64
import itertools from collections import deque from sys import stdin input = stdin.readline def main(): H, W = list(map(int, input().split())) M = [input()[:-1] for _ in range(H)] def bfs(start): dist = [[float('inf')]*W for _ in range(H)] dist[start[0]][start[1]] = 0 is_visited = [[0]*W for _ in range(H)] is_visited[start[0]][start[1]] = 1 q = deque([start]) max_ = 0 while len(q): now_h, now_w = q.popleft() if M[now_h][now_w] == '#': return for next_h, next_w in ((now_h+1, now_w), (now_h-1, now_w), (now_h, now_w-1), (now_h, now_w+1)): if not(0 <= next_h < H) or not(0 <= next_w < W) or \ (is_visited[next_h][next_w] == 1) or \ M[next_h][next_w] == '#': # (dist[next_h][next_w] != float('inf')) or \ continue dist[next_h][next_w] = dist[now_h][now_w] + 1 is_visited[next_h][next_w] = 1 max_ = max(max_, dist[next_h][next_w]) q.append((next_h, next_w)) return max_ max_ = 0 for h in range(H): for w in range(W): if M[h][w] == '.': max_ = max(bfs((h, w)), max_) print(max_) if(__name__ == '__main__'): main()
H,W=map(int,input().split()) S=[list(input())for _ in range(H)] from collections import deque def bfs(h,w,sy,sx,S): maze=[[10**9]*(W)for _ in range(H)] maze[sy-1][sx-1]=0 que=deque([[sy-1,sx-1]]) count=0 while que: y,x=que.popleft() for i,j in [(1,0),(0,1),(-1,0),(0,-1)]: nexty,nextx=y+i,x+j if 0<=nexty<h and 0<=nextx<w: dist1=S[nexty][nextx] dist2=maze[nexty][nextx] else: continue if dist1!='#': if dist2>maze[y][x]+1: maze[nexty][nextx]=maze[y][x]+1 count=max(count,maze[nexty][nextx]) que.append([nexty,nextx]) return count ans=0 for sy in range(H): for sx in range(W): if S[sy][sx]=='.': now=bfs(H,W,sy+1,sx+1,S) ans=max(ans,now) print(ans)
1
94,570,432,047,620
null
241
241
from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) d = defaultdict(int) sa = [0] * (n + 1) d[0] = 1 if k == 1: print(0) exit() for i in range(n): sa[i + 1] = sa[i] + a[i] sa[i + 1] %= k ans = 0 for i in range(1, n + 1): v = sa[i] - i v %= k ans += d[v] d[v] += 1 if 0 <= i - k + 1: vv = sa[i - k + 1] - (i - k + 1) vv %= k d[vv] -= 1 print(ans)
import sys input = sys.stdin.readline n, s = map(int,input().split()) A = list(map(int,input().split())) mod = 998244353 l = 3050 M = [1] # i!のmod m = 1 for i in range(1, l): m = (m * i) % mod M.append(m) def pow(x, y, mod): # x**y の mod を返す関数 ans = 1 while y > 0: if y % 2 == 1: ans = (ans * x) % mod x = (x**2) % mod y //= 2 return ans def inv(x, mod): # x の mod での逆元を返す関数 return pow(x, mod-2, mod) D = [0] * 3050 M2 = [1] M2I = [0] * l for i in range(l-1): M2.append((M2[-1] * 2) % mod) for i in range(l): M2I[i] = inv(M2[i], mod) i2 = inv(2,mod) D[0] = M2[n] for i in range(n): for j in range(l-1,-1,-1): if j - A[i] >= 0: D[j] = (D[j] + D[j-A[i]] * i2) % mod # print(D[:10]) print(D[s])
0
null
77,603,842,085,082
273
138
n,m = map(int,input().split()) print('Yes' if n<=m else 'No')
N, M = (int(x) for x in input().split()) if N==M: print("Yes") else: print("No")
1
83,448,311,922,976
null
231
231
n = int(input()) li = ["#"*20 if i%4==0 else "0"*10 for i in range(1, 16)] for _ in range(n): b, f, r, v = map(int, input().split()) h = 4*b-(4-f)-1 li[h] = li[h].replace(li[h], ''.join([str(int(list(li[h])[r-1])+v) if i == r-1 else list(li[h])[i] for i in range(10)])) li = [' '+' '.join(li[i]) if (i+1)%4!=0 else li[i] for i in range(len(li))] print('\n'.join(li))
house1 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]] house2 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]] house3 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]] house4 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]] houses = [house1, house2, house3, house4] n = int(input()) for i in range(n): b, f, r, v = [int(x) for x in input().split()] houses[b - 1][f - 1][r - 1] += v cnt = 0 for house in houses: for floor in house: floor = [str(x) for x in floor] print(' ' + ' '.join(floor)) if cnt != 3: print('#' * 20) cnt += 1
1
1,102,170,354,380
null
55
55
from collections import defaultdict d = defaultdict(int) n = int(input()) for _ in range(n): d[input()] += 1 s = sorted(d.items(), key=lambda x: (-x[1], x[0])) nmax = s[0][1] for i in s: if i[1] != nmax: break print(i[0])
N = int(input()) word = [str(input()) for i in range(N)] dic = {} for i in word: if i in dic: dic[i] += 1 else: dic[i] = 1 max_num = max(dic.values()) can_word = [] for i,j in dic.items(): if j == max_num: can_word.append(i) can_word.sort() for i in can_word: print(i)
1
69,848,227,743,398
null
218
218
from collections import Counter S = input() MOD = 2019 div10 = 202 # modInverse(10, MOD). Note MOD is not prime so can't use FLT! def solve1(S): # Naive implementation counts = [0 for i in range(MOD)] total = 0 for d in S: d = int(d) nextCounts = [0 for i in range(MOD)] nextCounts[d] += 1 for k, v in enumerate(counts): nextCounts[(10 * k + d) % MOD] += v counts = nextCounts total += counts[0] return total def solve2(S): # Instead of shuffling the entire counts, update how we index into counts instead # The cumulative shuffle function forward is something like a * index + b for some calculable a, b # Then indexing into counts[t][x] is same as indexing into counts[0][(x - b) / a] negPowTen = 1 # our a prefix = 0 # our b counts = [0 for i in range(MOD)] total = 0 for d in S: d = int(d) prefix = (10 * prefix + d) % MOD negPowTen = (negPowTen * div10) % MOD counts[((d - prefix) * negPowTen) % MOD] += 1 total += counts[((0 - prefix) * negPowTen) % MOD] return total def solve3(S): # Alternative solution, precompute prefixes, p[i+1] == (10 * p[i] + S[i]) % MOD # Then you have for S = '1817181712114' # p[1] = 1 # p[2] = 18 # p[3] = 181 # p[4] = 1817 # etc # Then want to count all i j such that: # (p[j] - p[i] * pow(10, j - i)) % M == 0 # Which is equivalent to # (p[j] * pow(10, -j) - p[i] * pow(10, -i) % M == 0 negPowTen = 1 total = 0 prefix = 0 counts = [0 for i in range(MOD)] counts[0] = 1 for d in S: prefix = (prefix * 10 + int(d)) % MOD key = (prefix * negPowTen) % MOD total += counts[key] counts[key] += 1 negPowTen = (negPowTen * div10) % MOD return total def solve4(S): # Compute all suffixes instead # S = '1817181712114' # suf[1] = 4 # suf[2] = 14 # suf[3] = 114 # suf[4] = 2114 # # Difference of suffixes is almost correct but has extra 10s. # For example 2114 to 114 is the string 2 but our difference returns 2000. # Luckily 2 and 5 aren't divisible by 2019 so the extra 10s don't matter when counting. N = len(S) suf = 0 powTen = 1 counts = [0 for i in range(MOD)] total = 0 counts[0] = 1 for i in range(N): d = int(S[N - 1 - i]) suf = (powTen * d + suf) % MOD total += counts[suf] counts[suf] += 1 powTen = (powTen * 10) % MOD return total #assert solve1(S) == solve2(S) == solve3(S) == solve4(S) ans = solve4(S) print(ans)
from collections import defaultdict S = input() kTarget = 2019 mod2cnt = defaultdict(int) mod2cnt[0] += 1 ord_z = ord('0') res = 0 for i in range(len(S)-1, -1, -1): d = ord(S[i]) - ord_z res = (res+d*pow(10, len(S)-1-i, kTarget))%kTarget mod2cnt[res] += 1 ans = 0 for cnt in mod2cnt.values(): ans += cnt*(cnt-1) print(ans//2)
1
30,618,676,672,648
null
166
166
import sys def input(): return sys.stdin.readline()[:-1] n = int(input()) plus, minus = [], [] for _ in range(n): s = input() mi, cur = 0, 0 for i in range(len(s)): if s[i] == "(": cur += 1 else: cur -= 1 mi = min(mi, cur) if cur >= 0: plus.append((mi, cur)) else: minus.append((mi, cur)) plus.sort(key=lambda x: -x[0]) minus.sort(key=lambda x: x[0] - x[1]) res = plus + minus cur = 0 for m, t in res: if cur + m < 0: print("No") exit() cur += t if cur != 0: print("No") exit() print("Yes")
a = list(map(int,input().split())) if sum(a)<= 21: print("win") else: print("bust")
0
null
70,996,083,071,852
152
260
N = int(input()) P = list(map(int,input().split())) num = 1 min_P = P[0] for i in range(1,N): if P[i] < min_P: min_P = P[i] num += 1 print(num)
n = int(input()) P = list(map(int, input().split())) cnt = 0 m = P[0] for p in P: if m >= p: cnt += 1 m = p print(cnt)
1
85,522,795,786,780
null
233
233
x, n = map(int, input().split()) p = list(map(int, input().split())) i = 0 while True: if x-i not in p: print(x-i) break if x+i not in p: print(x+i) break i += 1
def run(): X, N = [int(v) for v in input().rstrip().split()] p = [] if N > 0: p = [int(v) for v in input().rstrip().split()] i = -1 try: i = p.index(X) except ValueError: pass if i == -1: # not contained return X d1 = {} for k in range(0, 102): d1[k] = k for v in p: del d1[v] l2 = sorted(list(d1.keys())) l2.append(X) l2.sort() i = l2.index(X) r = 0 if i == 0: r = l2[1] elif (i + 1) == len(l2): r = l2[-2] else: v1 = l2[i + 1] - X v2 = X - l2[i - 1] if v1 < v2 : r = l2[i + 1] elif v1 > v2 : r = l2[i - 1] else: # v1 == v2 r = l2[i - 1] return r r = run() print(r)
1
13,975,178,775,008
null
128
128
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 ** 9) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") a,b = I() for i in range(1,2000): if int(i*0.08)==a and int(i*0.1)==b: print(i) sys.exit() print(-1)
t = [] w = input().lower() while True: s = input() if s == "END_OF_TEXT": break t.extend(s.lower().split()) print(t.count(w))
0
null
29,062,204,883,286
203
65
import math y = int(input()) print(360//math.gcd(y,360))
import math x = int(input()) def lcm(x, y): return (x * y) // math.gcd(x, y) print(lcm(x, 360)//x)
1
13,083,725,056,490
null
125
125
N = int(input()) R = [int(input()) for i in range(N)] maxv = -20000000000 minv = R[0] for i in range(1, N): maxv = max(R[i] - minv, maxv) minv = min(R[i], minv) print(maxv)
#ALDS1_1_D Maximum Profit n=int(input()) A=[] max_dif=-1*10**9 for i in range(n): A.append(int(input())) min=A[0] for i in range(n-1): if(A[i+1]-min>max_dif): max_dif=A[i+1]-min if(min>A[i+1]): min=A[i+1] print(max_dif)
1
13,112,350,240
null
13
13