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
while True: (n, x) = [int(i) for i in input().split()] if n == x == 0: break count = 0 start = n if n < x else x for a in range(start, 0, -1): if a >= x: continue for b in range(a - 1, 0, -1): if a + b >= x: continue for c in range(b - 1, 0, -1): if a + b + c == x: count += 1 print(count)
BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 while True: N,X = map(int,input().split()) if N == 0 and X == 0: break ans = 0 for a in range(1,N+1): for b in range(1,N+1): if b <= a: continue c = X-(a+b) if c > b and c <= N: ans += 1 print("%d"%(ans))
1
1,285,036,150,786
null
58
58
import math import re import copy t = input() ans = t.replace("?","D") print(ans)
import math a, b, h, m = map(int,input().split()) m_rad = m/60 * 360 h_rad = (h/12 * 360) + (m/60 * 360/12) rad = abs(m_rad - h_rad) ans = (a**2 + b**2) - (2 * a * b * math.cos(math.radians(rad))) print(math.sqrt(ans))
0
null
19,393,047,786,320
140
144
import sys BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 NUM = 20005 table = [""]*NUM while True: T = str(input()) if T == '-': break left = 0 right = 0 #長い配列にパターン文字列を転記 for i in range(len(T)): # print(T[right]) table[left+right] = T[right] right += 1 num_suffle = int(input()) for loop in range(num_suffle): pick_num = int(input()) #先頭からpick_num文字を末尾に転記し、論理削除 for i in range(pick_num): table[right+i] = table[left+i] left += pick_num right += pick_num for i in range(left,right): print("%s"%(table[i]),end = "") print()
while 1: s = input() if s[0] == "-": break m = int(input()) for i in range(m): h = int(input()) s = s[h:] + s[:h] print(s)
1
1,906,947,201,572
null
66
66
# D - Maze Master # https://atcoder.jp/contests/abc151/tasks/abc151_d from collections import deque def main(): height, width = [int(num) for num in input().split()] maze = [input() for _ in range(height)] ans = 0 next_to = ((0, 1), (1, 0), (0, -1), (-1, 0)) for start_x in range(height): for start_y in range(width): if maze[start_x][start_y] == '#': continue queue = deque() queue.append((start_x, start_y)) reached = [[-1] * width for _ in range(height)] reached[start_x][start_y] = 0 while queue: now_x, now_y = queue.popleft() for move_x, move_y in next_to: adj_x, adj_y = now_x + move_x, now_y + move_y # Python は index = -1 が通ってしまうことに注意。 # except IndexError では回避できない。 if (not 0 <= adj_x < height or not 0 <= adj_y < width or maze[adj_x][adj_y] == '#' or reached[adj_x][adj_y] != -1): continue queue.append((adj_x, adj_y)) reached[adj_x][adj_y] = reached[now_x][now_y] + 1 most_distant = max(max(row) for row in reached) ans = max(most_distant, ans) print(ans) if __name__ == '__main__': main()
import sys from collections import deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = map(int, input().split()) grid = [input() for _ in range(H)] res = [] for sh in range(H): for sw in range(W): if grid[sh][sw] == "#": continue maze = [[f_inf] * W for _ in range(H)] maze[sh][sw] = 0 que = deque([[sh, sw]]) while que: h, w = que.popleft() for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)): next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W or grid[next_h][ next_w] == "#": continue if maze[next_h][next_w] > maze[h][w] + 1: maze[next_h][next_w] = maze[h][w] + 1 que.append([next_h, next_w]) res.append(maze[next_h][next_w]) print(max(res)) if __name__ == '__main__': resolve()
1
94,958,504,277,830
null
241
241
# coding: utf-8 # Your code here! n=int(input()) sum=0 min=1000001 max=-1000001 table=list(map(int,input().split(" "))) for i in table: sum+=i if max<i: max=i if min>i: min=i print(str(min)+" "+str(max)+" "+str(sum))
input() n = list(map(int, input().split())) n.sort() print('{} {} {}'.format(n[0], n[-1], sum(n)))
1
709,038,727,820
null
48
48
x, y, z = input().split() x, y = y, x x, z = z, x print(x, y, z)
while True: H, W = [int(x) for x in input().split()] if H == W == 0: break for i in range(H): cnt = i % 2 for j in range(W): if (cnt % 2) == 0: print('#', end="") else: print('.', end="") cnt += 1 print() print()
0
null
19,554,141,078,308
178
51
n,q = map(int,input().split()) queue = [] for i in range(n): name,time = input().split() queue.append((name, int(time))) t = 0 while queue: name,time = queue.pop(0) t += min(q, time) if time > q: queue.append((name, time-q)) else: print(name,t)
S = str(input()) count = 0 result = 0 for i in S: if i == 'R': count+=1 if count>result: result = count else: count=0 print(result)
0
null
2,428,434,490,712
19
90
import sys def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = [] R = [] for i in range(n1): L.append(A[left+i]) for i in range(n2): R.append(A[mid+i]) L.append("INFTY") R.append("INFTY") i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 global c c += 1 def mergeSort(A, left, right): if left+1 < right: mid = (left + right) / 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) if __name__ == "__main__": lines = sys.stdin.readlines() N = int(lines[0]) nums = [int(n) for n in lines[1].split(" ")] c = 0 mergeSort(nums, 0, N) print " ".join(map(str, nums)) print c
N = int(input()) XY = [] points = [] for i in range(N): points.append(i) x, y = list(map(int, input().split())) XY.append((x, y)) import math import itertools count = math.factorial(N) line = 0 for pp in itertools.permutations(points, N): i = 0 while i < N - 1: i1, i2 = pp[i], pp[i + 1] t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5 line += t i += 1 ans = line / count print(ans)
0
null
73,947,980,228,640
26
280
n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n): x=a[i] b[x-1]=i+1 print(*b)
# Aizu Problem ALDS_1_4_C: Dictionary import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") D = set() N = int(input()) for _ in range(N): cmd, string = input().split() if cmd == "insert": D.add(string) elif cmd == "find": print("yes" if string in D else "no")
0
null
90,098,419,715,798
299
23
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] N,M = LI() A = LI() a = sorted(A,reverse=True) high = a[0] * 2 + 1 low = 0 while high > low + 1: mid = (high + low) // 2 cnt = 0 j = N - 1 for i in range(N): while a[i] + a[j] < mid: j -= 1 if j < 0: break else: cnt += (j+1) continue break if cnt <= M: high = mid else: low = mid s = [a[0]] for i in range(1,N): s.append(s[-1]+a[i]) ans = 0 cnt = 0 m = a[0] * 2 j = N - 1 for i in range(N): while a[i] + a[j] < low: j -= 1 if j < 0: break else: ans += a[i] * (j+1) + s[j] cnt += j + 1 m = min(m,a[i] + a[j]) continue break print(ans - (cnt-M) * low) if __name__ == '__main__': main()
import sys import math import fractions from collections import defaultdict import bisect 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,M=nm() A=nl() A.sort() S=[0] S[0]=A[0] for i in range(1,N): S.append(S[i-1]+A[i]) def clc_shake(x):#x以上の和 tot=0 for i in range(N): th=x-A[i] inds=bisect.bisect_left(A,th) tot+=(N-inds) return tot l=0 r=2*(10**6) c=0 while (l+1<r): c=(l+r)//2 if(clc_shake(c)<M): r=c else: l=c ans=0 for i in range(N): th=r-A[i] inds=bisect.bisect_left(A,th) if(inds!=0): ans+=((N-inds)*A[i]+(S[N-1]-S[inds-1])) else: ans+=((N-inds)*A[i]+(S[N-1])) M2=M-clc_shake(r) ans+=M2*(l) print(ans)
1
108,166,511,565,788
null
252
252
import sys input = sys.stdin.readline N, D = map(int, input().split()) count = 0 for i in range(N): a, b = map(int, input().split()) if (a*a + b*b) <= D*D: count += 1 print(count)
N,D = map(int,input().split()) ans = 0 for i in range(N): X1,Y1 = map(int,input().split()) if X1*X1+Y1*Y1 <= D*D: ans += 1 print(ans)
1
5,939,683,759,612
null
96
96
dataList = [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] input_k = input('') k_index = int(input_k) print(dataList[k_index - 1])
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): l = list(map(int, '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'.replace(',', '').split())) K = int(input()) - 1 print(l[K]) if __name__ == '__main__': main()
1
50,060,680,078,952
null
195
195
import sys input = sys.stdin.readline from collections import defaultdict def prime(n: int) -> defaultdict: f, i = defaultdict(int), 2 while i * i <= n: while n % i == 0: f[i] += 1; n //= i i += 1 if n != 1: f[n] = 1 return f def solve(n: int) -> int: if n == 1: return 1 r, l = n, 0 while (r - l) > 1: m = (l + r) // 2 if m * (m + 1) // 2 <= n: l = m else: r = m return l n, res = int(input()), 0 for k, v in prime(n).items(): res += solve(v) print(res)
N = int(input()) def factorization(num): res = [] n = num div_max = int(num ** 0.5) for i in range(2, div_max+1): if n % i == 0: count = 0 while n % i == 0: count += 1 n //= i res.append([i, count]) if n != 1: res.append([n, 1]) if len(res) == 0: res.append([num, 1]) return res res = factorization(N) ans = 0 for i in range(len(res)): p, n = res[i] if p != 1: j = 1 while n - j >= 0: ans += 1 n -= j j += 1 print(ans)
1
16,939,924,741,376
null
136
136
n,k = map(int,input().split()) A = [0] A.extend(list(map(int,input().split()))) town = 1 once = [0]*(n+1) for i in range(n): if once[town]==0: once[town] = 1 else: break town = A[town] rt = A[town] roop = 1 while rt != town: rt = A[rt] roop += 1 rt = 1 bf = 0 while rt != town: rt = A[rt] bf += 1 if bf<k: K = (k-bf)%roop + bf else: K = k town = 1 for _ in range(K): town = A[town] print(town)
nums = [] while True: num = [int(e) for e in input().split()] if num[0]==0 and num[1]==0: break nums.append(num) for i in range(len(nums)): for j in range(len(nums[i])): for k in range(j): if nums[i][k] > nums[i][j]: a = nums[i][k] nums[i][k] = nums[i][j] nums[i][j] = a for i in range(len(nums)): print(" ".join(map(str, nums[i])))
0
null
11,525,793,771,386
150
43
i = 1 while True: a = int(input()) if (a == 0): break else: print("Case " + str(i) + ": " + str(a)) i += 1
class itp1_3b: def out(self,i,x): print "Case "+str(i)+": "+str(x) if __name__=="__main__": run=itp1_3b() i=1 while(True): x=input() if x==0: break run.out(i,x) i+=1
1
491,499,525,778
null
42
42
# coding: utf-8 from collections import defaultdict def main(): N = int(input()) dic = defaultdict(int) max_p = 0 for i in range(N): dic[input()] += 1 d = dict(dic) l = [] for key, value in d.items(): l.append([key, value]) if max_p < value: max_p = value l.sort(key=lambda x: (-x[1], x[0]), reverse=False) for i, j in l: if j == max_p: print(i) else: break if __name__ == "__main__": main()
n = int(input()) # 入力データ受取り時に、辞書に追加していくやり方 s_dict = {} for i in range(n): s = input() if s not in s_dict: s_dict[s] = 1 s_dict[s] += 1 max_value = max(s_dict.values()) ans = [] for key, value in s_dict.items(): if value == max_value: ans.append(key) ans.sort() for i in ans: print(i)
1
70,162,941,064,128
null
218
218
a = int(input()) print((1+a)*a//2-((3 + a//3*3)*(a//3)//2 + (5 + a//5*5)*(a//5)//2 - (15 + a//15*15)*(a//15)//2))
n=int(input()) a=n//3 b=n//5 c=n//15 suma=(0+a*3)*(a+1)//2 sumb=(0+b*5)*(b+1)//2 sumc=(0+c*15)*(c+1)//2 print((n+1)*n//2-suma-sumb+sumc)
1
35,028,439,022,952
null
173
173
from collections import deque k = int(input()) q = deque([]) for i in range(1, 10): q.append(i) cnt = 0 while cnt < k: s = q.popleft() cnt += 1 t = s % 10 if t != 0: q.append(10 * s + (t - 1)) q.append(10 * s + t) if t != 9: q.append(10 * s + (t + 1)) print(s)
import sys input = sys.stdin.readline n = int(input()) A = tuple(int(x) for x in input().split()) _ = int(input()) M = tuple(int(x) for x in input().split()) S = set() def Check(i, s): if i == n: S.add(s) return Check(i + 1, s + A[i]) Check(i + 1, s) Check(0, 0) for m in M: if m in S: print('yes') else: print('no')
0
null
20,090,241,044,292
181
25
h,n = map(str,input().split()) #li = [int(x) for x in input().split()] print(n+h)
s,t=input().split() x=t+s print(x)
1
103,161,295,264,652
null
248
248
from collections import defaultdict n,*L=map(int,open(0).read().split()) mod=10**9+7 d=defaultdict(lambda:[0,0]) gcd=lambda x,y:x if y==0 else gcd(y,x%y) two=[1]*(n+1) for i in range(n): two[i+1]=(two[i]*2)%mod zero=0 for a,b in zip(*[iter(L)]*2): if a==b==0: zero+=1 continue if a==0: d[(0,1)][0]+=1 elif b==0: d[(0,1)][1]+=1 else: g=gcd(a,b) a//=g b//=g if a*b>0: d[(a,b)][0]+=1 else: d[(abs(b),abs(a))][1]+=1 ans=1 for (_,_),(x,y) in d.items(): ans*=(two[x]+two[y]-1)%mod ans%=mod print((ans+zero+mod-1)%mod)
a,v = map(int,input().split()) b,w = map(int,input().split()) t = int(input()) if a > b: oni = a + (-1*v) * t nige = b + (-1*w) * t if oni <= nige: print("YES") else: print("NO") else: oni = a + v*t nige = b + w * t if oni >= nige: print("YES") else: print("NO")
0
null
17,987,400,639,520
146
131
n, x, t = input().split() z = ((int(n)+int(x))-1)//int(x) ans = z * int(t) print(ans)
n,x,t = map(int,input().split()) if n % x ==0: print(int(n/x*t)) else: print(int((n//x+1)*t))
1
4,186,447,382,832
null
86
86
s = input() l = [0] m = [0] a = 0 b = 0 arr = [] for i in range(len(s)): if s[i] == '<': a += 1 else: a = 0 l.append(a) if s[len(s) - i - 1] == '>': b += 1 else: b = 0 m.append(b) m = m[::-1] for i in range(len(l)): arr.append(max(l[i], m[i])) ans = sum(arr) print(ans)
s = input() cut = [0] for i in range(len(s)-1): if(s[i:i+2] == '><'): cut.append(i+1) cut.append(len(s)+1) ans = 0 for i in range(len(cut)-1): ss = s[cut[i]:cut[i+1]] left = ss.count('<') right = ss.count('>') ans += left*(left+1)//2 + right*(right+1)//2 - min(left,right) print(ans)
1
156,470,821,635,378
null
285
285
n=int(input()) l=[int(i) for i in input().split()] l.sort() def func(one,two,three): if len({one,two,three})==3 and one+two>three: return True return False ans=0 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): one=l[i] two=l[j] three=l[k] if func(one,two,three): ans+=1 print(ans)
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = map(int, read().split()) M = 61 C = [0] * M for a in A: a = str(format(a, 'b')) for i, d in enumerate(reversed(a)): if d == '1': C[i] += 1 ans = 0 p = 1 for c in C: ans = (ans + c * (N - c) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
0
null
63,683,954,128,252
91
263
n = int(input()) l = [0 for _ in range(10**4)] def fib(n): if n==0: l[0]=1 return 1 if n==1: l[1]=1 return 1 if l[n]!=0: return l[n] else: l[n]=fib(n-1)+fib(n-2) return fib(n-1)+fib(n-2) print(fib(n))
n = int(input()) a0 = 1 a1 = 1 #print(a0, a1, end='') if n == 0 or n == 1: a2 = 1 else: for i in range(n-1): a2 = a0 + a1 a0 = a1 a1 = a2 #print('',a2,end='') print(a2)
1
1,680,203,670
null
7
7
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)
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil #from operator import itemgetter #inf = 10**17 #mod = 10**9 + 7 n = int(input()) a =[0]+list(map(int, input().split())) b = list(accumulate(a)) c = sum(a) res = 10000000000000000 for i in range(1, n): s = b[i] t = c-s res = min(res, abs(s-t)) print(res) if __name__ == '__main__': main()
0
null
155,864,554,612,030
293
276
import math r = float(input()) #r = (float(x) for x in input().split()) d = r * r * math.pi R = 2 * r * math.pi print ("{0:.6f} {1:.6f}".format(d,R))
import math r=float(input()) string=str(r**2*math.pi)+" "+str(2*math.pi*r) print(string)
1
650,333,297,450
null
46
46
def solve(string): n, c = string.split() n, c = int(n), list(c) wi, ri = 0, n - 1 while wi < n and c[wi] == "R": wi += 1 while ri >= 0 and c[ri] == "W": ri -= 1 ans = 0 while wi < n and ri >= 0 and wi < ri: c[wi], c[ri], ans = c[ri], c[wi], ans + 1 wi, ri = wi + 1, ri - 1 while wi < n and c[wi] == "R": wi += 1 while ri >= 0 and c[ri] == "W": ri -= 1 return str(ans) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
n = int(input()) k = input() a = k.count("R") b = k[:a].count("W") print(b)
1
6,308,486,841,960
null
98
98
X, N = map(int, input().split()) P = list(map(int, input().split())) st = set(P) for i in range(111): if not X - i in st: print(X - i) exit(0) if not X + i in st: print(X + i) exit(0)
X, N = map(int, input().split()) p = list(map(int, input().split())) for i in range(X + 1): for j in [-1, +1]: ans = X + i * j if p.count(ans) == 0: print(ans) break else: continue break
1
14,205,605,654,130
null
128
128
from collections import Counter def cal(D,M): C = Counter(D) MC = C.most_common() MC.sort(key = lambda x:x[0]) n = len(MC) #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで #頂点1を根にできる. #従ってD[i-1]は頂点iの深さと見なせる for i in range(n): if MC[i][0] != i: #深さiと深さi-1又は深さiと深さi+1を繋げない return 0 if MC[0][1] != 1 or D[0] != 0: #1以外の根がある又は1が根になってない return 0 output = 1 for i in range(n-1): output *= pow(MC[i][1],MC[i+1][1],M) output %= M return output def main(): N = int(input()) D = list(map(int,input().split())) M = 998244353 ans = cal(D,M) print(ans) if __name__ == "__main__": main()
from collections import defaultdict N = int(input()) D = list(map(int, input().split())) depth = defaultdict(int) for d in D: depth[d] += 1 # つながらない if D[0] != 0 or depth[0] != 1: print(0) exit() mod = 998244353 ans = 1 for d in range(1, max(D) + 1): ans *= pow(depth[d - 1], depth[d], mod) ans %= mod print(ans)
1
155,053,733,829,280
null
284
284
a,b,k = map(int,input().split()) if a == k : print(0,b) elif a > k : print(a-k,b) elif a < k : c = b - (k-a) if c >= 0 : print(0,c) else : print(0,0)
import sys n = input() for _ in range(int(n)): a, b, c = sorted(map(int, sys.stdin.readline().split())) if a * a + b*b == c* c: print("YES") else: print("NO")
0
null
51,949,530,478,850
249
4
X, N = map(int, input().split()) P = list(map(int, input().split())) st = set(P) ans = 111 for i in range(111): if i in st: continue if abs(ans - X) > abs(i - X): ans = i print(ans)
s = input() t = input() cnt = 0 word = list(s) answer = list(t) for i in range(len(s)): if word[i] != answer[i]: cnt+=1 print(cnt)
0
null
12,424,002,041,792
128
116
#nは問題数 mは提出した回数  n,m = map(int,input().split()) submit = [] check = [0] * n for x in range(m): a,b = input().split() a = int(a) x = [a,b] submit.append(x) o = 0 x = 0 for y in submit: if check[y[0]-1] == 0: if y[1] == "AC": o += 1 check[y[0]-1] = 1 elif y[1] == "WA": x += 1 for z in submit: if check[z[0]-1] == 0: if z[1] == "WA": x -= 1 print(o,x)
import itertools Row = int(input()) List = [] l=[] for i in range (Row): l.append(i+1) List.append(list(map(int, input().split()))) x = 0 y = 0 mid = 0 p_list = list(itertools.permutations(l, Row)) for v in p_list: for i in range(1,Row): x = List[v[i]-1][0]-List[v[i-1]-1][0] y = List[v[i]-1][1]-List[v[i-1]-1][1] k = x*x+y*y mid += k**0.5 res = mid / len(p_list) print(res)
0
null
120,276,035,886,060
240
280
N = int(input()) S = input() ans = 0 for i in range(10): for j in range(10): for k in range(10): s = ["0", "0", "0"] s[0] = str(i) s[1] = str(j) s[2] = str(k) ind = 0 cnt = 0 while cnt < 3 and ind < N: if S[ind] == s[cnt]: cnt += 1 ind += 1 if cnt == 3: ans += 1 print(ans)
#coding:utf-8 #?????¬??????????????? def draw_topbottom(n): a = "" for i in range(n): a += "#" print a def draw_middle(n): a = "#" for i in range(n-2): a += "." a += "#" print a while 1: HW = raw_input().split() H = int(HW[0]) W = int(HW[1]) if H == 0 and W == 0: break draw_topbottom(W) for i in range(H-2): draw_middle(W) draw_topbottom(W) print ""
0
null
64,907,598,352,080
267
50
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): L = int(input()) print((L/3)**3) if __name__ == '__main__': main()
n = int(raw_input()) points = [0, 0] for i in xrange(n): card_list = raw_input().split(" ") if card_list[0] > card_list[1]: points[0] += 3 elif card_list[0] < card_list[1]: points[1] += 3 else: points[0] += 1 points[1] += 1 print str(points[0]) + " " + str(points[1])
0
null
24,402,006,787,018
191
67
import sys a,b,c = map(int, sys.stdin.readline().rstrip().split(' ')) print('Yes' if (a<b<c) else 'No')
import sys M = 1044697 H = [None] * M table = str.maketrans({"A":"1","C":"2","G":"3","T":"4"}) def getChar(ch): if ch == "A": return 1 elif ch == "C": return 2 elif ch == "G": return 3 elif ch == "T": return 4 else: return 0 def getKey(string): sum = 0 p = 1 for i in range(len(string)): sum += p*(getChar(string[i])) p *= 5 return sum #print(getKey(string)) def h1(key): return key % M def h2(key): return 1 + (key % (M-1)) # 関数の中のwhile文はreturnで抜け出せる def find(string): i = 0 key = getKey(string) while True: h = (h1(key) + i * h2(key)) % M if H[h] == string: return 1 elif H[h] is None: return 0 else: i += 1 def insert(string): i = 0 key = getKey(string) while True: h = (h1(key) + i * h2(key)) % M if H[h] is None: H[h] = string break else: i += 1 input = sys.stdin.readline n = int(input()) for _ in range(n): com,string = input().split() if com == "insert": insert(string) elif com == "find": if find(string): print("yes") else: print("no")
0
null
227,372,734,820
39
23
n = int(input()) r = -10000000000 y = int(input()) m = y x = y for i in range(1, n): x = int(input()) if r < (x - m): r = (x - m) if x < m: m = x print(r)
a = int(input()) x = input() y = x.split(' ') c =[] for i in range(a): c.append(y[(a-1)-i]) b = ' '.join(c) print(b)
0
null
491,591,315,530
13
53
x=input() y=input() lst1=[] lst1=list(x) lst2=[] lst2=list(y) b=0 ans=0 while(b<len(x)): if(not lst1[b]==lst2[b]): ans=ans+1 b+=1 print(ans)
def solve(x): return sum([int(i) for i in str(x)]) if __name__ == '__main__': while True: x = int(input()) if x == 0: break print(solve(x))
0
null
6,000,081,659,840
116
62
N = int(input()) S,T = input().split() print(''.join([X+Y for (X,Y) in zip(S,T)]))
n = int(input()) s, t = input().split() for i in range(n): print(s[i], t[i], sep="", end="") print("")
1
112,091,285,572,420
null
255
255
import math import numpy as np import numba from numba import njit, b1, i4, i8, f8 from numba import jit import collections import bisect from collections import deque from copy import copy, deepcopy import time def main(): N,X,T = map(int,input().split()) print(math.ceil(N/X) * T) if __name__ == '__main__': main()
import math n, x, t = [int(x) for x in input().split()] print(math.ceil(n/x)*t)
1
4,317,892,387,382
null
86
86
n = int(input()) ans = n // 2 ans += 1 if n % 2 != 0 else 0 print(ans)
import math a = int(input()) print(math.ceil(a/2))
1
59,213,804,400,960
null
206
206
a, b = map(int, input().split()) al = [] b_lis = [] for _ in range(a): g = list(map(int, input().split())) g.append(sum(g)) al.append(g) for i in range(b+1): p = 0 for j in range(a): p += al[j][i] b_lis.append(p) al.append((b_lis)) for i in al: print(' '.join([str(v) for v in i]))
r, c = map(int, input().split()) hyou = [] tate_sum = [0] * (c + 1) for i in range(r): line = list(map(int, input().split())) line.append(sum(line)) tate_sum = [tate_sum[j] + line[j] for j in range(len(line))] line = map(str, line) hyou.append(" ".join(line)) tate_sum = map(str, tate_sum) hyou.append(" ".join(tate_sum)) print("\n".join(hyou))
1
1,369,459,543,452
null
59
59
r, c = map(int, input().split()) x = []; for i in range(r): x.append(list(map(int, input().split()))) rsum = [0 for i in range(r)] csum = [0 for i in range(c)] total = 0 for i in range(r): for j in range(c): rsum[i] += x[i][j] csum[j] += x[i][j] total += x[i][j] for i in range(r): for j in range(c): print(str(x[i][j]) + " ", end="") print(rsum[i]) for j in range(c): print(str(csum[j]) + " ", end="") print(total)
r, c = map(int, input().split()) tbl = [[] for _ in range(r)] cSum = [0 for _ in range(c+1)] for i in range(r): tblS = input() tbl[i] = list(map(int, tblS.split())) print(tblS, end = '') print(' ', sum(tbl[i]), sep = '') for j in range(c): cSum[j] += tbl[i][j] cSum[c] += sum(tbl[i]) print(' '.join(map(str, cSum)))
1
1,385,613,160,500
null
59
59
n,k=map(int,input().split()) k_list=[] for i in range(k): l,r=map(int,input().split()) k_list.append([l,r]) dp=[0]*(n+1) dp[1]=1 dpsum=[0]*(n+1) dpsum[1]=1 for i in range(1,n): dpsum[i]=dp[i]+dpsum[i-1] for j in range(k): l,r=k_list[j] li=i+l ri=i+r+1 if li<=n: dp[li]+=dpsum[i] dp[li]=dp[li]%998244353 if ri<=n: dp[ri]-=dpsum[i] dp[ri]=dp[ri]%998244353 print(dp[n])
r = int(input()) pi = 3.14159265358979323846 print(2*pi*r)
0
null
17,157,972,305,450
74
167
''' ITP-1_3-D ?´???°?????° ???????????´??° aa???bb???cc ??????????????????aa ?????? bb ?????§?????´??°????????????cc ????´???°?????????????????????????±??????? ????????°???????????????????????????????????? ???Input aa ???bb???cc ?????????????????????????????§?????????????????????????????? ???Output ?´???°?????°??????????????????????????????????????? ''' # import import sys # ?´???°???????????? cnt = 0 # ?????°?????????????????? aa, bb, cc = map(int,input().split()) # input??????????????? for dd in range(aa, bb+1): if cc%dd == 0: # ?´???°????????????????????? cnt += 1 print( cnt )
x = raw_input() a, b, c = x.split() a = int(a) b = int(b) c = int(c) kai = 0 d = b + 1 for i in range(a, d): if c % i == 0: kai += 1 print kai
1
563,155,333,760
null
44
44
n = int(input()) tarou = 0 hanako = 0 for i in range(n): w1, w2 = input().split() if w1 == w2: tarou += 1 hanako += 1 elif w1 > w2: tarou += 3 else: hanako += 3 print(tarou, hanako)
n,d = map(int,input().split()) ans = 0 for i in range(n): x1,y1 = map(int,input().split()) if(d*d >= x1*x1+y1*y1): ans += 1 print(ans)
0
null
3,987,292,676,250
67
96
N = int(input()) hen = [] hen = list(int(x) for x in input().split()) hen.sort() #print(hen) #hen_u = set(hen) #print(hen_u) tri = 0 for a in hen: for b in hen: if(a == b)or (a > b): continue for c in hen: if(a == c)or(b == c) or (a > c) or (b > c): continue if(a+b >c)and(b+c >a)and(c+a >b): tri += 1 print(tri)
num = list(map(int, input().split())) class Dice: def __init__(self, num): self.state = {} for i in range(1,6+1): self.state[i] = num[i-1] self.reversed_state = {} for key,val in zip(self.state.keys(), self.state.values()): self.reversed_state[val] = key def search_side(self, x,y): a = self.reversed_state[x] b = self.reversed_state[y] if str(a)+str(b) in '12651': side = self.state[3] elif str(b)+str(a) in '12651': side = self.state[4] elif str(a)+str(b) in '13641': side = self.state[5] elif str(b)+str(a) in '13641': side = self.state[2] elif str(a)+str(b) in '23542': side = self.state[1] elif str(b)+str(a) in '23542': side = self.state[6] return side dice = Dice(num) q = int(input()) for _ in range(q): x,y = map(int, input().split()) ans = dice.search_side(x,y) print(ans)
0
null
2,631,609,770,340
91
34
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall import sys def input(): return sys.stdin.readline()[:-1] n, m, l = map(int, input().split()) dist = [[0 for _ in range(n)] for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) dist[a-1][b-1] = c dist[b-1][a-1] = c fw = floyd_warshall(csr_matrix(dist)) num = [[0 for _ in range(n)] for _ in range(n)] for i in range(n): for j in range(n): if fw[i][j] <= l: num[i][j] = 1 ans = floyd_warshall(csr_matrix(num)) q = int(input()) for _ in range(q): s, t = map(int, input().split()) if ans[s-1][t-1] > n: print(-1) else: print(int(ans[s-1][t-1])-1)
import sys k, s = sys.stdin.readlines() k = int(k) s = s.strip() if len(s) <= k: print(s) else: print('{}...'.format(s[:k]))
0
null
97,023,974,374,688
295
143
# ITP1_10_B import math a, b, c = map(float, input().split()) s = a * b * math.sin(math.radians(c)) / 2 l = a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(c))) h = b * math.sin(math.radians(c)) print(s) print(l) print(h)
t1, t2 = (int(x) for x in input().split()) a1, a2 = (int(x) for x in input().split()) b1, b2 = (int(x) for x in input().split()) if a1 < b1: a1, b1 = b1, a1 a2, b2 = b2, a2 if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2: print(0) exit() elif a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2: print("infinity") exit() d1 = (a1 - b1) * t1 d2 = (b2 - a2) * t2 k = d1 // (d2 - d1) if d1 % (d2 - d1) == 0: print(2 * k) else: print(2 * k + 1)
0
null
65,603,082,669,920
30
269
a, b = list(map(int, input().split(' '))) print('Yes' if a * 500 >= b else 'No')
from sys import stdin line = stdin.readline() input = [int(x) for x in line.rstrip().split()] if input[0] * 500 >= input[1]: print('Yes') else: print('No')
1
97,690,586,603,962
null
244
244
a,b,c,d=map(int, raw_input().split()) print max(a*c,a*d,b*c,b*d)
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) def lcm(a, b): return a*b/gcd(a, b) try : while True : (a,b) = map(int, raw_input().split()) print gcd(a,b), lcm(a,b) except EOFError : pass
0
null
1,515,950,071,400
77
5
n = int(input()) l = list(map(int,input().split())) p=l[0] s=0 for i in l[1:]: s+= max(0,p-i) p=max(p,i) print(s)
N = int(input()) A = list(map(int,input().split())) num_b = 0 cnt = 0 for i in A: if num_b > i: cnt += num_b - i else: num_b = i print(cnt)
1
4,529,325,473,848
null
88
88
n, k, s = map(int,input().split()) x = s + 1 if s < 10 ** 9 else 1 a = [x] * n for i in range(k): a[i] = s print(*a, sep=' ')
N, K, S = map(int, input().split()) A = [] for i in range(K): A.append(S) if S != 10 ** 9: res = S + 1 else: res = 1 for j in range(N - K): A.append(res) print(*A)
1
90,788,669,544,730
null
238
238
h, w = map(int, input().split()) s = [] score = [[0] * w for i in range(h)] for i in range(h): s.append(list(input())) for j in range(w): if i == 0: if j == 0: score[0][0] = 1 if s[0][0] == '#' else 0 else: score[0][j] = score[0][j-1] if s[0][j] == '#' and s[0][j-1] != '#': score[0][j] += 1 else: if j == 0: score[i][0] = score[i-1][0] if s[i][0] == '#' and s[i-1][0] != '#': score[i][0] += 1 else: r = score[i][j-1] if s[i][j] == '#' and s[i][j-1] != '#': r += 1 d = score[i-1][j] if s[i][j] == '#' and s[i-1][j] != '#': d += 1 score[i][j] += min(r, d) print(score[-1][-1])
mod = 10 ** 9 + 7 n, k = map(int, input().split()) a = sorted(map(int, input().split())) fact = [1] * n inv = [1] * n inv_fact = [1] * n for i in range(2, n): fact[i] = fact[i-1] * i % mod inv[i] = -inv[mod % i] * (mod // i) % mod inv_fact[i] = inv_fact[i-1] * inv[i] % mod max_sum = 0 for i in range(k-1, n): max_sum = (max_sum + a[i] * fact[i] * inv_fact[i-k+1]) % mod max_sum = (max_sum * inv_fact[k-1]) % mod min_sum = 0 for i in range(n-k+1): min_sum = (min_sum + a[i] * fact[n-i-1] * inv_fact[n-k-i]) % mod min_sum = (min_sum * inv_fact[k-1]) % mod print((max_sum - min_sum) % mod)
0
null
72,682,924,562,010
194
242
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 idx = 1 def resolve(): def dfs(v): global idx begin[v] = idx idx += 1 for u in edge[v]: if begin[u] != 0: continue else: dfs(u) end[v] = idx idx += 1 n = int(input()) edge = [[] for _ in range(n)] for _ in range(n): u, k, *V = map(int, input().split()) for v in V: edge[u - 1].append(v - 1) begin = [0] * n end = [0] * n for i in range(n): if begin[i] == 0: dfs(i) for i in range(n): print(i + 1, begin[i], end[i]) if __name__ == '__main__': resolve()
def main(): x = int(input()) a, b = 1, 0 while True: for b in reversed(range(-a + 1, a)): # print(a, b) q = a**5 - b**5 if q == x: print(f'{a} {b}') return a += 1 main()
0
null
12,714,526,468,000
8
156
from itertools import combinations_with_replacement n, m, q = map(int, input().split()) abcd = [list(map(int, input().split())) for i in range(q)] ans = 0 for i in combinations_with_replacement(range(1, m + 1), n): cnt = 0 for a, b, c, d in abcd: if i[b - 1] - i[a - 1] == c: cnt += d ans = max(ans, cnt) print(ans)
from itertools import combinations_with_replacement N, M, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for i in combinations_with_replacement(range(1, M+1), N): tmp = 0 for a, b, c, d in A: if i[b-1] - i[a-1] == c: tmp += d ans = max(ans, tmp) print(ans)
1
27,629,035,598,672
null
160
160
S = input() T = input() if T[:len(S)] == S: print('Yes') else: print('No')
S=list(input()) T=list(input()) T.pop(len(T)-1) if S == T: print("Yes") else: print("No")
1
21,384,745,156,392
null
147
147
H, W = map(int,input().split()) grid = [input() for _ in range(H)] dp = [[float('inf')]*(W) for _ in range(H)] dp[0][0] = 0 if grid[0][0] == '.' else 1 for i in range(H): for k in range(W): if i+1 < H: if grid[i][k] == '.' and grid[i+1][k] == '#': dp[i+1][k] = min(dp[i][k]+1,dp[i+1][k]) else: dp[i+1][k] = min(dp[i][k],dp[i+1][k]) if k+1 < W: if grid[i][k] == '.' and grid[i][k+1] == '#': dp[i][k+1] = min(dp[i][k]+1,dp[i][k+1]) else: dp[i][k+1] = min(dp[i][k],dp[i][k+1]) print(dp[-1][-1])
H,W = map(int,input().split()) s = [] for i in range(H): S = list(input()) s.append(S) dis = [[float("inf")] * W for i in range(H)] if s[0][0] == "#": dis[0][0] = 1 else: dis[0][0] = 0 for i in range(H): for j in range(W): if i != H-1: if s[i][j] == "." and s[i+1][j] == "#": dis[i+1][j] = min(dis[i][j] + 1,dis[i+1][j]) else: dis[i+1][j] = min(dis[i][j],dis[i+1][j]) if j != W-1: if s[i][j] == "." and s[i][j+1] == "#": dis[i][j+1] = min(dis[i][j] + 1,dis[i][j+1]) else: dis[i][j+1] = min(dis[i][j],dis[i][j+1]) print (dis[-1][-1])
1
49,419,180,940,792
null
194
194
AA1 = input().split() AA2 = input().split() AA3 = input().split() AA4 = [AA1[0],AA2[0],AA3[0]] AA5 = [AA1[1],AA2[1],AA3[1]] AA6 = [AA1[2],AA2[2],AA3[2]] AA7 = [AA1[0],AA2[1],AA3[2]] AA8 = [AA1[2],AA2[1],AA3[0]] N = int(input()) list1 = [] for i in range(N): b = input() list1.append(b) count = 0 bingo =0 for i in list1: if i in AA1: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA2: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA3: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA4: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA5: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA6: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA7: count +=1 if count ==3 : bingo =1 else: count =0 for i in list1: if i in AA8: count +=1 if count ==3 : bingo =1 else: count =0 if bingo ==1: print('Yes') else: print('No')
a = [] for i in range(3): l,m,n = map(int,input().split()) a.append([l,m,n]) n = int(input()) b = [] for i in range(n): b.append(int(input())) #print(a) #print(b) for i in range(3): for j in range(3): for k in range(n): if a[i][j] == b[k]: a[i][j] = 0 tmp = 0 for i in range(3): if a[i][0]+a[i][1]+a[i][2] == 0: tmp = 1 elif a[0][i]+a[1][i]+a[2][i] == 0: tmp = 1 if a[0][0]+a[1][1]+a[2][2] ==0: tmp = 1 elif a[0][2]+a[1][1]+a[2][0] ==0: tmp = 1 if tmp == 1: print('Yes') else: print('No')
1
60,021,604,708,640
null
207
207
nums = [int(i) for i in input().split()] nums.sort() print("{} {} {}".format(nums[0], nums[1], nums[2]))
M = 10**9 + 7 n,a,b = map(int, input().split()) def modinv(n): return pow(n, M-2, M) def comb(n, r): num = 1 for i in range(n,n-r,-1): cur = i while cur%M == 0: cur //= M num = (num*cur)%M denom = 1 for i in range(1,r+1): cur = i while cur%M == 0: cur //= M denom = (denom*cur)%M return num * modinv(denom) % M print((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M)
0
null
33,370,936,684,360
40
214
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())
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)
0
null
31,584,145,401,500
151
181
import sys def I(): return int(sys.stdin.readline().rstrip()) def Main(): x = I() for a in range(-118,120): for b in range(-118,120): if a**5-b**5 == x: print(a,b) exit() return if __name__=='__main__': Main()
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): x = ri() fifths = {i**5: i for i in range(10000)} a = 0 while 1: if x - a**5 in fifths: print (a, -fifths[x - a**5]) return elif a**5 - x in fifths: print (a, fifths[a**5 - x]) return a += 1 mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
1
25,529,253,557,558
null
156
156
print("".join([_.upper() if _.islower() else _.lower() for _ in input()]))
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) a,b,c = inpm() k = inp() for i in range(k): if b <= a: b *= 2 elif c <= b: c *= 2 if a < b < c: ans = 'Yes' else: ans = 'No' print(ans)
0
null
4,228,466,662,772
61
101
A, B = map(int, input().split()) ans = -1 for i in range(10000): if int((i/100)*8) == A and int((i/100)*10) == B: ans = i break print(ans)
A,B=map(int,input().split()) for money in range(1,1001): if int(money*0.08)==A and int(money*0.1)==B: print(money) break else: print(-1)
1
56,447,406,670,480
null
203
203
H, M = map(int, input().split()) A = list(map(int, input().split())) a = (sum(A)) if a >= H: ans = "Yes" else: ans = "No" print(ans)
h, n = map(int,input().split()) a = list(map(int,input().split())) hitpoint=h atack = a[:] for e in atack: hitpoint -= e if hitpoint <= 0: break if hitpoint <= 0: print("Yes") else: print("No")
1
78,054,996,331,520
null
226
226
x = list(map(int, input().split())) if len(set(x))==2: kotae='Yes' else: kotae='No' print(kotae)
import math def average(l): return sum(l) / len(l) def var(l): a = average(l) return sum(map(lambda x: (x-a)**2, l)) / len(l) def std(l): return math.sqrt(var(l)) if __name__ == '__main__': while True: n = int(input()) if n == 0: break l = [int(i) for i in input().split()] print("{0:.5f}".format(std(l)))
0
null
34,231,618,651,350
216
31
number = list(map(int,input().split())) score = list(map(int,input().split())) waza = 0 for i in range(number[1]): waza += score[i] if number[0] <= waza: print('Yes') else: print('No')
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 class SegTree: """ セグメント木 1.update: i番目の値をxに更新する 2.query: 区間[l, r)の値を得る """ def __init__(self, n, func, intv, A=[]): """ :param n: 要素数(0-indexed) :param func: 値の操作に使う関数(min, max, add, gcdなど) :param intv: 要素の初期値(単位元) :param A: 初期化に使うリスト(オプション) """ self.n = n self.func = func self.intv = intv # nより大きい2の冪数 n2 = 1 while n2 < n: n2 <<= 1 self.n2 = n2 self.tree = [self.intv] * (n2 << 1) # 初期化の値が決まっている場合 if A: # 1段目(最下段)の初期化 for i in range(n): self.tree[n2+i] = A[i] # 2段目以降の初期化 for i in range(n2-1, -1, -1): self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1]) def update(self, i, x): """ i番目の値をxに更新 :param i: index(0-indexed) :param x: update value """ i += self.n2 self.tree[i] = x while i > 0: i >>= 1 self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1]) def query(self, a, b): """ [a, b)の値を得る :param a: index(0-indexed) :param b: index(0-indexed) """ l = a + self.n2 r = b + self.n2 s = self.intv while l < r: if r & 1: r -= 1 s = self.func(s, self.tree[r]) if l & 1: s = self.func(s, self.tree[l]) l += 1 l >>= 1 r >>= 1 return s def get(self, i): """ 一点取得 """ return self.tree[i+self.n2] def all(self): """ 全区間[0, n)の取得 """ return self.tree[1] N, M = MAP() S = input() dp = SegTree(N+1, min, INF) dp.update(N, 0) for i in range(N-1, -1, -1): # ゲームオーバーマスには遷移できない if S[i] == '1': continue mn = dp.query(i+1, min(N+1, i+M+1)) if mn != INF: dp.update(i, mn+1) # 辿り着けない if dp.get(0) == INF: print(-1) exit() cnt = dp.get(0) cur = 0 prev = -1 ans = [] for i in range(1, N+1): if dp.get(i) == INF: continue # 手数が変わる場所でなるべく手前に飛ぶ if dp.get(i) != cnt: prev = cur cur = i ans.append(cur-prev) cnt = dp.get(i) print(*ans)
0
null
108,254,452,968,860
226
274
a, b, k = list(map(int, input().split(' '))) print(max(0, a-k), max(0, b-max(0, k-a)))
def main(): A, B, K= map(int, input().split()) if A >= K: print(A - K, B) elif A + B >= K: print(0, A + B - K) else: print(0, 0) main()
1
104,627,248,972,400
null
249
249
import queue n, quantum = map(int, input().split()) q = queue.Queue() for _ in range(n): name, time = input().split() q.put([name, int(time)]) spend_time = 0 while q.qsize() > 0: name, time = q.get() tmp = min(quantum, time) spend_time += tmp time -= tmp if time == 0: print('{} {}'.format(name, spend_time)) else: q.put([name, time])
from collections import OrderedDict n, q = map(int, input().split()) od = OrderedDict() for i in range(n): name, time = input().split() od.update({name: int(time)}) total = 0 while len(od) > 0: name, time = od.popitem(False) if time <= q: total += time print("{} {}".format(name, total)) else: total += q time -= q od.update({name: time})
1
45,121,607,512
null
19
19
X, K, D = map(int, input().split()) X = abs(X) if X >= K * D: ans = X - K * D else: n, d = divmod(X, D) ans = d if (K - n) % 2: ans = D - d print(ans)
X,K,D=map(int,input().split()) import math X=abs(X) U=min(math.floor(X/D),K) K=K-U A=X-U*D if K%2==0: print(A) else: print(abs(A-D))
1
5,186,829,851,390
null
92
92
M1,D1 = list(map(int,input().split())) M2,D2 = list(map(int,input().split())) if (M1 != M2 and M2>M1) or M2 == 1 and M2<M1: print(1) else: print(0)
a, b = map(int, input().split()) c = a - (2 * b) print(c if c >= 0 else 0)
0
null
145,588,767,261,546
264
291
D=int(input()) c=list(map(int,input().split())) c_memo=[0]*26 s=[] for i in range(D): ss=list(map(int,input().split())) s.append(ss) ans_b=[] for i in range(D): t=int(input()) c_down=0 for j in range(26): if j==t-1: c_memo[t-1]=i+1 continue else: c_down+=(i+1-c_memo[j])*c[j] ans=s[i][t-1]-c_down ans_b.append(ans) ans=0 for x in ans_b: ans+=x print(ans)
#!/usr/bin/env python3 import sys from typing import NamedTuple, List class Game(NamedTuple): c: List[int] s: List[List[int]] def solve(D: int, c: "List[int]", s: "List[List[int]]", t: "List[int]"): from functools import reduce ans = [0] lasts = [0] * 26 adjust = 0 sum_c = sum(c) daily_loss = sum_c for day, tt in enumerate(t, 1): a = s[day-1][tt-1] adjust += day * c[tt-1] - lasts[tt-1] * c[tt-1] lasts[tt-1] = day a -= daily_loss a += adjust ans.append(ans[-1]+a) daily_loss += sum_c return ans[1:] # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() D = int(next(tokens)) # type: int c = [int(next(tokens)) for _ in range(26)] # type: "List[int]" s = [[int(next(tokens)) for _ in range(26)] for _ in range(D)] # type: "List[List[int]]" t = [int(next(tokens)) for _ in range(D)] # type: "List[int]" print(*solve(D, c, s, t), sep="\n") def test(): import doctest doctest.testmod() if __name__ == '__main__': #test() main()
1
9,925,210,739,300
null
114
114
N = int(input()) A = input().split() ans = 1 zero_count = A.count("0") if zero_count != 0: print(0) else: for i in range(N): ans *= int(A[i]) if ans > 10**18: ans = -1 break print(ans)
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def nPr(n: int, r: int) -> int: return math.factorial(n) // math.factorial(n - r) def nCr(n: int, r: int) -> int: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def solve(N: int, M: int): return (nCr(N, 2)if N > 1 else 0) + (nCr(M, 2) if M > 1 else 0) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int print(f'{solve(N, M)}') if __name__ == '__main__': main()
0
null
30,937,424,985,650
134
189
a = list(map(int, input().split())) sum_a = sum(a) if sum_a >= 22: print('bust') else: print('win')
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a = map(int, input().split()) if sum(a) >= 22: print('bust') else: print('win') if __name__ == "__main__": setrecursionlimit(10000) main()
1
118,428,240,806,788
null
260
260
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N = I() X = SS() # 一回の操作でnはN以下になる # 2回目以降の操作はメモ化再帰 # 初回popcountは2種類しかない Xのpopcountから足し引きすればよい pc_X = X.count('1') if pc_X == 0: for i in range(N): print(1) elif pc_X == 1: for i in range(N): if i == X.index('1'): print(0) else: # 1が2つある場合、最後の位が1の場合、奇数 if i == N - 1 or X.index('1') == N - 1: print(2) else: print(1) else: next_X_m1 = 0 next_X_p1 = 0 pc_m1 = pc_X - 1 pc_p1 = pc_X + 1 for i in range(N): if X[i] == '1': next_X_m1 += pow(2, N - 1 - i, pc_m1) next_X_p1 += pow(2, N - 1 - i, pc_p1) dp = [-1] * N dp[0] = 0 def dfs(n): if dp[n] == -1: dp[n] = 1 + dfs(n % bin(n).count('1')) return dp[n] for i in range(N): next = 0 if X[i] == '0': next = (next_X_p1 + pow(2, N - 1 - i, pc_p1)) % pc_p1 else: next = (next_X_m1 - pow(2, N - 1 - i, pc_m1)) % pc_m1 ans = dfs(next) + 1 print(ans) # print(dp) if __name__ == '__main__': resolve()
s=str(input()) s=list(s) temp=[] cnt=0 ans=0 for i in range(len(s)): if s[i]=="<": if i!=0 and s[i-1]==">": temp.append(cnt) cnt=0 cnt=cnt+1 else: if i!=0 and s[i-1]=="<": temp.append(cnt) cnt=0 cnt=cnt+1 temp.append(cnt) if s[0]=="<": for i in range(0,len(temp)-1,2): tempmin=min(temp[i],temp[i+1])-1 tempmax=max(temp[i],temp[i+1]) temp[i]=tempmin temp[i+1]=tempmax else: for i in range(1,len(temp)-1,2): tempmin=min(temp[i],temp[i+1])-1 tempmax=max(temp[i],temp[i+1]) temp[i]=tempmin temp[i+1]=tempmax for i in range(len(temp)): ans=ans+temp[i]*(temp[i]+1)//2 print(ans)
0
null
82,567,484,971,858
107
285
n = input() for i in xrange(n): a, b, c = sorted(map(int, raw_input().split())) print 'YES' if a*a+b*b==c*c else 'NO'
import sys A,B,C,K=map(int, sys.stdin.readline().split()) ans=0 a_cards=min(K,A) K-=a_cards ans+=a_cards*1 b_cards=min(K,B) K-=b_cards ans+=b_cards*0 c_cards=min(K,C) K-=c_cards ans+=c_cards*-1 print ans
0
null
10,867,382,593,980
4
148
n = int(input()) ans = 0 for a in range(1,n): b = n//a if b*a == n: b -= 1 ans += b print(ans)
from math import sqrt N = int(input()) ans = 0 for a in range(1, N+1): ans += (N-1)//a print(ans)
1
2,601,143,128,860
null
73
73
def FizzBuzz_sum(): # 入力 N = int(input()) # 初期処理 N = [i for i in range(1,N+1)] sum = 0 # 比較処理 for i in N: if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: sum += i return sum result = FizzBuzz_sum() print(result)
n=int(input()) a=n//3 b=n//5 c=n//15 suma=(0+a*3)*(a+1)//2 sumb=(0+b*5)*(b+1)//2 sumc=(0+c*15)*(c+1)//2 print((n+1)*n//2-suma-sumb+sumc)
1
34,869,131,433,280
null
173
173
# coding: utf-8 # Your code here! N=int(input()) count=-1 for i in range(N//2+1): count+=1 if N%2==0: print(count-1) else: print(count)
n = int(input()) iteration = n ex = 0 count = 0 for i in range(1,n): ex = iteration-i #print(ex) if ex <=i: break else: count += 1 print(count)
1
153,249,833,211,072
null
283
283
import math N = int(input()) S = input() lst0 = [0]*N lst1 = [0]*N lst0[0] = 1 lst1[0] = 1 c = S.count('1') m0 = int(S[-1]) m1 = int(S[-1]) for i in range(1, N): lst0[i] += (lst0[i-1]*2)%(c+1) if c == 1:lst1[i] = 0 else: lst1[i] += (lst1[i-1]*2)%(c-1) m0 += lst0[i] * int(S[N - 1- i]) m0 %= c+1 m1 += (lst1[i] * int(S[N - 1 - i])) if c == 1: m1 = 0 else: m1 %= c-1 memo = [0]*(N+1) def calc(a): global ans, memo if a == 0: return ans ans += 1 if memo[a] != 0: b = memo[a] else: b = bin(a).count('1') memo[a] = b return calc(a%b) for i in range(N): if S[i] == '1': b = c - 1 if b == 0: a = 0 else: a = max((m1 - lst1[N - 1 - i])%b, (m1 - lst1[N - 1 - i]+ b)%b) else: b = c + 1 a = (m0 + lst0[N - 1 - i])%b if b == 0: print(0) elif a == 0:print(1) else: ans = 1 print(calc(a))
N,K,S=map(int,input().split()) if S==10**9: for i in range(K): print(S,"",end="") for i in range(K,N): print(1,"",end="") print() else: for i in range(K): print(S,"",end="") for i in range(K,N): print(S+1,"",end="") print()
0
null
49,868,915,838,198
107
238
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, k, s = map(int, input().split()) if s != 10**9: ans = [s]*k + [10**9]*(n-k) else: ans = [s]*k + [1]*(n-k) print(*ans)
0
null
106,301,857,615,840
262
238
from collections import deque import sys input = sys.stdin.readline def main(): N,X,Y = map(int,input().split()) edge = [[] for _ in range(N)] for i in range(N): if i == 0: edge[i].append(i+1) elif i == N-1: edge[i].append(i-1) else: edge[i].append(i-1) edge[i].append(i+1) edge[X-1].append(Y-1) edge[Y-1].append(X-1) ans = [0]*(N-1) for i in range(N): visited = [0]*N dist = [0]*N q = deque([i])#i番目のノードを根とする探索 visited[i] = 1 while q: now = q.popleft() for connection in edge[now]: if visited[connection]: dist[connection] = min(dist[connection],dist[now]+1) else: visited[connection] = 1 dist[connection] = dist[now] + 1 q.append(connection) for d in dist: if d == 0: continue ans[d-1] += 1 ans = list(map(lambda x: x//2,ans)) print(*ans,sep="\n") if __name__ == '__main__': main()
n,x,y=map(int,input().split()) a=[0]*n for i in range(1,n+1): for j in range(i,n+1): b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i)) a[b]+=1 print(*a[1:],sep="\n")
1
44,035,868,028,152
null
187
187
def prime_factors(n): i = 2 factors = [] while i**2 <= n: if n % i != 0: i += 1 else: factors.append(i) n = n // i if n > 1: factors.append(n) return factors def resolve(): N = int(input()) import collections factors = collections.Counter(prime_factors(N)) numbers = [0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9] cnt = 0 for k, v in factors.items(): cnt += numbers[v] print(cnt) if '__main__' == __name__: resolve()
n=int(input()) ans =0 for i in range(2,int(n**0.5)+5): cnt = 0 while n%i==0: n//=i cnt += 1 s=1 while cnt-s>=0: cnt -= s s +=1 ans += 1 if n!=1:ans+=1 print(ans)
1
16,963,240,291,270
null
136
136
from math import factorial def modpow(a, n, p): if n == 0: return 1 elif n == 1: return a % p if n % 2 == 1: return (a * modpow(a, n-1, p)) % p tmp = modpow(a, n//2, p) return (tmp * tmp) % p def main(): mod = 10 ** 9 + 7 n, a, b = map(int, input().split()) # まずは繰り返し2乗法によって全部の組み合わせを求める # すべての組み合わせは、花を選ぶ/選ばないで組み合わせを決めれる ans = (modpow(2, n, mod) - 1) % mod # a本選んだときの数を引く c_a = 1 for i in range(n, n-a, -1): c_a *= i c_a %= mod c_a *= modpow(factorial(a), mod-2, mod) ans -= c_a ans %= mod # b本選んだときの数を引く c_b = 1 for i in range(n, n-b, -1): c_b *= i c_b %= mod c_b *= modpow(factorial(b), mod-2, mod) ans -= c_b ans %= mod print(ans) if __name__ == "__main__": main()
n=input() if 65<=ord(n)<=90: print("A") else: print("a")
0
null
38,595,269,906,490
214
119
n = int(input()) t = 0 h = 0 for _ in range(n): a_lst = input().rstrip().split(" ") #print(a_lst) b_lst = sorted(a_lst) #print(b_lst) if a_lst[0] == a_lst[1]: t += 1 h += 1 elif a_lst == b_lst: h += 3 else: t += 3 print(t, h)
T,H = 0,0 n = int(input()) for i in range(n): S1,S2 = input().split() if S1 < S2: H += 3 elif S1 > S2: T += 3 else: T += 1 H += 1 print(T,H)
1
2,000,963,539,516
null
67
67
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) R, C, K = mapint() dp = [[[0]*C for _ in range(R)] for _ in range(4)] from collections import defaultdict dic = [[0]*C for _ in range(R)] for _ in range(K): r, c, v = mapint() dic[r-1][c-1] = v for r in range(R): for c in range(C): v = dic[r][c] for i in range(4): if c!=0: dp[i][r][c] = dp[i][r][c-1] if r!=0: dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c]) for i in range(2, -1, -1): dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) ans = 0 for i in range(4): ans = max(ans, dp[i][R-1][C-1]) print(ans)
k,n = map(int,input().split()) a = list(map(int,input().split())) ans = 10 ** 8 for i in range(n-1): a.append(a[i]+k) for i in range(n): ans = min(ans,a[i+n-1] - a[i]) print(ans)
0
null
24,383,393,379,310
94
186
n,k = map(int,input().split()) mod = 10**9+7 num_gcd = [0]*(k+1) for i in range(1,k+1)[::-1]: num = pow(k//i,n,mod) for j in range(2,k//i+1): num -= num_gcd[i*j] if num < 0: num += mod num_gcd[i] = num ans = 0 for i in range(1,k+1): ans += i*num_gcd[i] ans %= mod print(ans)
MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from bisect import bisect_left,bisect_right from collections import deque def main(): n,k = map(int,input().split()) ans = 0 G = [0] * (1 + k) for g in range(k,0,-1): ret = pow((k//g),n,MOD) for j in range(2 * g,k + 1,g): ret -= G[j] G[g] = ret ans += ret * g ans %= MOD print(ans) if __name__ =='__main__': main()
1
36,855,995,448,804
null
176
176
class Node: def __init__(self,key): self.key = key self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.nil = Node(None) self.nil.prev = self.nil self.nil.next = self.nil def insert(self,key): new = Node(key) new.next = self.nil.next self.nil.next.prev = new self.nil.next = new new.prev = self.nil def listSearch(self,key): cur = self.nil.next while cur != self.nil and cur.key != key: cur = cur.next return cur def deleteNode(self, t): if t == self.nil: return t.prev.next = t.next t.next.prev = t.prev def deleteFirst(self): self.deleteNode(self.nil.next) def deleteLast(self): self.deleteNode(self.nil.prev) def deleteKey(self, key): self.deleteNode(self.listSearch(key)) if __name__ == '__main__': import sys input = sys.stdin.readline n = int(input()) d = DoublyLinkedList() for _ in range(n): c = input().rstrip() if c[0] == "i": d.insert(c[7:]) elif c[6] == "F": d.deleteFirst() elif c[6] =="L": d.deleteLast() else: d.deleteKey(c[7:]) ans = [] cur = d.nil.next while cur != d.nil: ans.append(cur.key) cur = cur.next print(" ".join(ans))
from collections import deque n = int(input()) dll = deque([]) for _ in range(n): p = input().split() if p[0] == "insert": dll.appendleft(p[1]) elif p[0] == "delete": try: dll.remove(p[1]) except: pass elif p[0] == "deleteFirst": dll.popleft() else: dll.pop() print(" ".join(dll))
1
51,500,315,780
null
20
20
line = input() q = int(input()) for _ in range(q): cmd = input().split() a = int(cmd[1]) b = int(cmd[2]) if cmd[0] == "print": print(line[a:b + 1]) elif cmd[0] == "replace": line = line[:a] + cmd[3] + line[b + 1:] else: line = line[:a] + line[a:b + 1][::-1] + line[b + 1:]
s = input() n = int(input()) for i in range(n): c = input().split() a = int(c[1]) b = int(c[2]) if "replace" in c: s = s[:a] + c[3] + s[b+1:] if "reverse" in c: u = s[a:b+1] s = s[:a] + u[:: -1] +s[b + 1:] if "print" in c: print(s[a:b+1], sep = '')
1
2,094,320,579,638
null
68
68
from sys import stdin def ip(): return stdin.readline().rstrip() d,t,s=map(int,ip().split()) if d<=t*s: print('Yes') else: print('No')
def main(): d, t, s = map(int, input().split()) print('Yes' if t*s >= d else 'No') if __name__ == '__main__': main()
1
3,540,305,251,262
null
81
81
s = str(input()) MOD = 2019 m = 0 digit = 1 mods = [1] + [0] * 2018 for a in s[::-1]: m = (m + digit * int(a)) % MOD mods[m] += 1 digit = digit * 10 % MOD ans = 0 for x in mods: ans += x * (x - 1) // 2 print(ans)
N = int(input()) jage = "No" for l in range(1, 10): for r in range(1,10): if N == r * l: jage = "Yes" print(jage)
0
null
95,276,959,400,198
166
287
def solve(a, b): if a % b == 0: return b else: return solve(b, a % b) while True: try: a, b = map(int, input().split()) lcm = solve(a,b) print(lcm, a * b // lcm) except: break
A, B, N = map(int,input().split()) x = min(B-1, N) print((A * x) // B - A * int(x // B))
0
null
14,130,595,224,110
5
161
import math a, b, c = map(float, input().split()) r = math.radians(c) S = (a * b * math.sin(r)) / 2 print(S) d = (a**2 + b**2 - 2 * a * b * math.cos(r)) d = math.sqrt(d) L = a + b + d print(L) h = 2 * S / a print(h)
import math a,b,C=map(float,input().split()) S=(a*b*math.sin(math.radians(C)))/2 c=a**2+b**2-2*a*b*math.cos(math.radians(C)) L=a+b+c**(1/2) if C==90: h=b else: h=(2*S)/a print(f'{S:10.8f}') print(f'{L:10.8f}') print(f'{h:10.8f}')
1
179,083,008,848
null
30
30
import math a,b,c=map(float,input().split()) h=b*math.sin(c/180.0*math.pi) ad=a-b*math.cos(c/180.0*math.pi) d=(h*h+ad*ad)**0.5 l = a + b + d s = a * h / 2.0 print('{0:.6f}'.format(s)) print('{0:.6f}'.format(l)) print('{0:.6f}'.format(h))
import math a, b, c = map(float,input().split()) e = b*math.sin(math.radians(c)) print(a*e/2) print(((a-b*math.cos(math.radians(c)))**2+e**2)**0.5+a+b) print(e)
1
177,704,682,880
null
30
30
A=[] for i in range(3): A.append(list(map(int,input().split()))) N=int(input()) for i in range(N): x=int(input()) for row in A: for num in range(len(row)): if x==row[num]: row[num]=0 for i in A: if i==[0,0,0]: print("Yes") exit(0) for i in range(3): if A[0][i]==0 and A[1][i]==0 and A[2][i]==0: print("Yes") exit(0) if A[0][0]==0 and A[1][1]==0 and A[2][2]==0: print("Yes") exit(0) if A[2][0]==0 and A[1][1]==0 and A[0][2]==0: print("Yes") exit(0) print("No")
import numpy as np MOD = 998244353 N,S = map(int,input().split()) A = list(map(int,input().split())) coefs = np.array([0]*(S+1)) coefs[0] = 1 for i in range(N): tmp = coefs[:] coefs = coefs*2 coefs[A[i]:] += tmp[:-A[i]] coefs%=MOD print(coefs[-1])
0
null
38,680,673,407,428
207
138
import math N = int(input()) ans = math.ceil(N / 2.0) print(ans)
if __name__ == "__main__": S = input() list_s = [s for s in S] ans = 0 if list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'S': ans = 0 elif list_s[0] == 'S' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'R': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'R': ans = 3 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'R': ans = 1 elif list_s[0] == 'R' and list_s[1] == 'R' and list_s[2] == 'S': ans = 2 elif list_s[0] == 'R' and list_s[1] == 'S' and list_s[2] == 'S': ans = 1 elif list_s[0] == 'S' and list_s[1] == 'R' and list_s[2] == 'S': ans = 1 print(ans)
0
null
31,854,034,125,140
206
90
n = int(input()) nums = [int(i) for i in input().split(" ")] count = 0 def merge(nums, left, mid, right): i = 0 j = 0 nums_l = nums[left:mid] nums_r = nums[mid:right] nums_l.append(10 ** 9 + 1) nums_r.append(10 ** 9 + 1) for x in range(0, right - left): global count count = count + 1 if nums_l[i] <= nums_r[j]: nums[left + x] = nums_l[i] i = i + 1 else: nums[left + x] = nums_r[j] j = j + 1 def merge_sort(nums, left, right): if left + 1 < right: mid = int((left + right) / 2) merge_sort(nums, left, mid) merge_sort(nums, mid, right) merge(nums, left, mid, right) merge_sort(nums, 0, n) result = "" for i in nums: result += str(i) + " " print(result.rstrip()) print(count)
import sys input = sys.stdin.readline def marge(A, left, right, mid): cnt = 0 n1 = mid - left n2 = right - mid L = [0] * (n1 + 1) R = [0] * (n2 + 1) for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = 10 ** 9 + 1 R[n2] = 10 ** 9 + 1 i = 0 j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return cnt def margesort(A, left, right): if left + 1 < right: mid = (left + right) // 2 cnt1 = margesort(A, left, mid) cnt2 = margesort(A, mid, right) return cnt1 + cnt2 + marge(A, left, right, mid) return 0 def main(): n = int(input()) A = list(map(int, input().split())) cnt = margesort(A, 0, n) print(' '.join(list(map(str, A)))) print(cnt) if __name__ == '__main__': main()
1
111,904,640,530
null
26
26
import math import itertools n = int(input()) l = [] for _ in range(n): a = list(map(int,input().split())) l.append(a) dis = 0 for case in itertools.permutations(l): for i in range(n-1): dis += math.sqrt((case[i][0]-case[i+1][0])**2+(case[i][1]-case[i+1][1])**2) result = dis/math.factorial(n) print(result)
class Dice: arr = [] tmpArr = [] def __init__(self, arr): self.arr = arr def move(self, pos): if pos == 'E': self.eastMove() elif pos == 'N': self.northMove() elif pos == 'S': self.sorthMove() elif pos == 'W': self.westMove() def out(self): return self.arr[0] def eastMove(self): self.changeArr(3, 6) self.changeArr(3, 4) self.changeArr(3, 1) def northMove(self): self.changeArr(5, 6) self.changeArr(5, 2) self.changeArr(5, 1) def sorthMove(self): self.changeArr(2, 6) self.changeArr(2, 5) self.changeArr(2, 1) def westMove(self): self.changeArr(4, 6) self.changeArr(4, 3) self.changeArr(4, 1) def changeArr(self, f, t): tmp = self.arr[f - 1] self.arr[f - 1] = self.arr[t - 1] self.arr[t - 1] = tmp diceNum = list(map(int, input().split(' '))) dice = Dice(diceNum) posAction = input() for pos in posAction: dice.move(pos) print(dice.out())
0
null
74,424,711,703,190
280
33
k=int(input()) if k==4 or k==6 or k==9 or k==10 or k==14 or k==21 or k==22 or k==25 or k==26: print(2) elif k==8 or k==12 or k==18 or k==20 or k==27: print(5) elif k==16: print(14) elif k==24: print(15) elif k==32: print(51) elif k==28 or k==30: print(4) else: print(1)
import sys lst=[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] pos = input() print(lst[int(pos)-1])
1
49,993,964,802,166
null
195
195
import math k = int(input()) sum = 0 for a in range(1,k+1): for b in range(1,k+1): x = math.gcd(a, b) for c in range(1,k+1): sum += math.gcd(x, c) print(sum)
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, u, v = map(int, input().split()) edge = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, input().split()) edge[a].append(b) edge[b].append(a) def calc_dist(s): dist = [-1] * (N + 1) dist[s] = 0 node = [s] while node: s = node.pop() d = dist[s] for t in edge[s]: if dist[t] != -1: continue dist[t] = d + 1 node.append(t) return dist[1:] taka = calc_dist(u) aoki = calc_dist(v) ans = 0 for x, y in zip(taka, aoki): if x <= y: ans = max(ans, y - 1) print(ans)
0
null
76,625,092,252,604
174
259
a,b,c = input().split() ti = [a,b,c] ti.sort() print(ti[0],ti[1],ti[2])
a = input().split() v = 2 while int(v) >= 1: if int(a[int(v)-1]) < int(a[int(v)]): pass else: b = int(a[int(v)-1]) a[int(v)-1] = int(a[int(v)]) a[int(v)] = int(b) v = int(v) - 1 if int(a[1]) < int(a[2]): pass else: b = int(a[1]) a[1] = int(a[2]) a[2] = int(b) print('%d %d %d' % (int(a[0]),int(a[1]),int(a[2])))
1
415,818,936,392
null
40
40