code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
n=int(input()) cards = [[s+" "+str(n) for n in range(1,14)] for s in ["S","H","C","D"]] for _ in range(n): suit,num =input().split() if suit=="S": cards[0][int(num)-1]=0 elif suit=="H": cards[1][int(num)-1]=0 elif suit=="C": cards[2][int(num)-1]=0 elif suit=="D": cards[3][int(num)-1]=0 for s in cards: for n in s: if n!=0: print(n)
n = int(raw_input()) C = {'S':range(13), 'H':range(13), 'C':range(13), 'D':range(13)} for i in range(n): suit, num = raw_input().split() num = int(num) C[suit][num-1] = 14 for i in ['S', 'H', 'C', 'D']: for j in range(13): if C[i][j] != 14: print "%s %d" %(i, j+1)
1
1,047,994,214,080
null
54
54
n, m, l = map(int, input().split()) A = [] B = [] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): B.append([int(j) for j in input().split()]) # ??????????????????????????????B?????¢??????????????¨??????????????? B_T = list(map(list, zip(*B))) C = [[0 for j in range(l)] for i in range(n)] for i in range(n): for j in range(l): C[i][j] = sum([a * b for (a, b) in zip(A[i], B_T[j])]) for i in range(n): print(*C[i])
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces a,b = na() ans = -1 for i in range(1, 1001): if a == math.floor(i * 0.08) and b == math.floor(i * 0.10): ans = i break print(ans)
0
null
28,960,218,891,642
60
203
s = input() if s=='hi' or s=='hihi' or s=='hihihi' or s=='hihihihi' or s=='hihihihihi' : print("Yes") else: print("No")
s = input() if len(s) %2 !=0: print("No") else: c =0 for i in range(len(s)//2): hi = s[2*i:2*i+2] if hi == "hi": pass else: c = 1 break if c ==0: print("Yes") else: print("No")
1
53,108,745,926,432
null
199
199
x_low,x_up,y_low,y_up=map(int,input().split()) a1=x_low*y_low a2=x_low*y_up a3=x_up*y_low a4=x_up*y_up ans=max(a1,a2,a3,a4) print(ans)
import sys, math for line in sys.stdin.readlines(): line = line.strip() n = int(line) value = 100000.0 for week in xrange(n): value = value * 1.05 value = math.ceil(value / 1000) * 1000 print int(value)
0
null
1,517,164,397,420
77
6
N, X, M = map(int, input().split()) I = [-1] * M A = [] total = 0 while (I[X] == -1): A.append(X) I[X] = len(A) total += X X = (X * X) % M # print(f'{A=}') # print(f'{I[:20]=}') # print(f'{total=}') # print(f'{X=}, {I[X]=}') c = len(A) - I[X] + 1 s = sum(A[I[X] - 1:]) # print(f'{c=}, {s=}') ans = 0 if N < len(A): ans += sum(A[:N]) else: ans += total N -= len(A) ans += s * (N // c) N %= c ans += sum(A[I[X] - 1:I[X] - 1 + N]) print(ans)
N, X, M = map(int, input().split()) ans = 0 C = [0] Xd = [-1] * (M+1) for i in range(N): x = X if i==0 else x**2 % M if Xd[x] > -1: break Xd[x] = i ans += x C.append(ans) loop_len = i - Xd[x] if loop_len > 0: S = C[i] - C[Xd[x]] loop_num = (N - i) // loop_len ans += loop_num * S m = N - loop_num * loop_len - i ans += C[Xd[x]+m] - C[Xd[x]] print(ans)
1
2,805,889,827,498
null
75
75
n, k = map(int, input().split()) a = [int(s) for s in input().split()] for i in range(k, n): if a[i] > a[i - k]: print('Yes') else: print('No')
n = int(input()) mod = 10 ** 9 + 7 s = 10 ** n s0 = 9 ** n s9 = 9 ** n sb = 8 ** n ans = s - s0 - s9 + sb print(ans % mod)
0
null
5,092,069,876,960
102
78
n = input() A=[int(j) for j in input().split()] nums = [0,0,0] ans = 1 for a in A: ans = (ans*nums.count(a))%(10**9 +7) for i in range(len(nums)): if nums[i] == a: nums[i] = a+1 break print(ans)
N = int(input()) a_list = list(map(int, input().split())) MOD = 10**9 + 7 cnts = [0,0,0] sames = 0 ind = -1 res = 1 for a in a_list: for i, cnt in enumerate(cnts): if cnt == a: sames += 1 ind = i res *= sames res %= MOD cnts[ind] += 1 sames = 0 print(res)
1
130,522,046,520,580
null
268
268
N = int(input()) % 10 print('hon' if N in [2, 4, 5, 7, 9] else 'pon' if N in [0, 1, 6, 8] else 'bon')
from collections import defaultdict,Counter h,w,m = map(int,input().split()) w_list = [] h_list = [] se = set() for _ in range(m): nh,nw = map(int,input().split()) se.add((nh,nw)) w_list.append(nw) h_list.append(nh) w_count = Counter(w_list) h_count = Counter(h_list) max_w = 0 max_h = 0 ch = [] cw = [] for i in w_count.values(): max_w = max(max_w,i) cw.append(i) for i in h_count.values(): max_h = max(max_h,i) ch.append(i) ma = ch.count(max_h)*cw.count(max_w) result = max_h+max_w point = 0 for i,j in se: if w_count[j] == max_w and h_count[i] == max_h: point += 1 if point == ma: print(result-1) else: print(result)
0
null
11,951,020,689,022
142
89
# 改善1:sys入力 # 改善2:ifで分岐させるより、あとから個別対応した方が分岐を毎回やらないですむ? import sys input=sys.stdin.readline def main(): k,n = map(int, input().split()) s = list(map(int, input().split())) l = [] for i in range(1,n): a = s[i] - s[i-1] l.append(a) l.append(k - (s[-1] - s[0])) print(k - max(l)) if __name__ == '__main__': main()
k, n = map(int, input().split()) A = list(map(int, input().split())) diff = [] for i in range(n-1): diff.append(A[i+1] - A[i]) diff.append(A[0]+k-A[-1]) print(sum(diff)-max(diff))
1
43,603,803,298,368
null
186
186
ret = [] while True: m, f, r = map(int, raw_input().split()) if (m,f,r) == (-1, -1, -1): break if m == -1 or f == -1: ret += 'F' elif 80 <= m + f: ret += ['A'] elif 65 <= m + f < 80: ret += ['B'] elif 50 <= m + f < 65: ret += ['C'] elif 30 <= m + f < 50 and 50 <= r: ret += ['C'] elif 30 <= m + f < 50 and r < 50: ret += ['D'] elif m + f < 30: ret += ['F'] for i in ret: print i
import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9+7 Max = sys.maxsize def l(): #intのlist return list(map(int,input().split())) def m(): #複数文字 return map(int,input().split()) def onem(): #Nとかの取得 return int(input()) def s(x): #圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x)-1): if aa != x[i+1]: a.append([aa,su]) aa = x[i+1] su = 1 else: su += 1 a.append([aa,su]) return a def jo(x): #listをスペースごとに分ける return " ".join(map(str,x)) def max2(x): #他のときもどうように作成可能 return max(map(max,x)) def In(x,a): #aがリスト(sorted) k = bs.bisect_left(a,x) if k != len(a) and a[k] == x: return True else: return False """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ h,w,k = m() s = [] for i in range(h): s.append(list(map(int,input()[:-1]))) st = [0 for i in range(h)] dp = [[0,0] for i in range(h)] ans = mod for po in range(2 << h): de = 0 tm = 0 for j in range(h): dp[j][0] = 0 dp[j][1] = 0 for j in range(h): if j == 0: st[0] = 0 else: a = (po>>j)&1 b = (po>>(j-1))&1 if a != b: de += 1 st[j] = de tm += de for kp in range(w): fl = 0 for kk in range(h): if s[kk][kp] == 1: dp[st[kk]][1] += 1 if all(dp[x][0] + dp[x][1] <= k for x in range(h)): for kk in range(h): dp[kk][0] += dp[kk][1] dp[kk][1] = 0 else: tm += 1 for kk in range(h): if dp[kk][0] > k: fl = 1 break dp[kk][0] = dp[kk][1] dp[kk][1] = 0 if fl: break else: ans = min(tm,ans) print(ans)
0
null
25,007,840,424,700
57
193
n = int(input()) sum = (1 + n) * n // 2 sho_3 = n // 3 sho_5 = n // 5 sho_15 = n // 15 s_3 = (sho_3 * 3 + 3) * sho_3 // 2 s_5 = (sho_5 * 5 + 5) * sho_5 // 2 s_15 = (sho_15 * 15 + 15) * sho_15 // 2 print(sum - s_3 - s_5 + s_15)
from collections import deque def matrix(n): for _ in range(n): adj = list(map(int, input().split())) i = adj[0] v = adj[2:] for j in v: mat[i - 1][j - 1] = 1 def bfs(v): d[v] = 1 dist[v] = 0 dq.append(v) while dq: v = dq.popleft() for n, i in enumerate(mat[v]): if i == 1 and not d[n]: d[n] = 1 dist[n] = dist[v] + 1 dq.append(n) n = int(input()) mat = [[0] * n for _ in range(n)] d, dist = [0] * n, [-1] * n dq = deque() matrix(n) bfs(0) for i, v in enumerate(dist): print(i + 1, v)
0
null
17,573,778,106,638
173
9
n, m, l = map(int, input().split()) A = [] B = [] for line in range(n): A.append(list(map(int, input().split()))) for line in range(m): B.append(list(map(int, input().split()))) C = [] for lines in range(n): C.append([sum([A[lines][i] * B[i][j] for i in range(m)]) for j in range(l)]) print(" ".join(map(str, C[lines])))
n, k = map(int, input().split(" ")) MOD = (10**9) + 7 def dSum(s, e): s -= 1 _s = s * (s + 1) // 2 _e = e * (e + 1) // 2 return _e - _s ans = 0 for i in range(k, n + 1): # _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1 ans += dSum(i, n) - dSum(0, n - i) + 1 print((ans + 1) % MOD)
0
null
17,307,688,174,714
60
170
def solve(): n = int(input()) if n % 2 == 0: print(0.5) else: print(((n+1)//2) / n) if __name__ == '__main__': solve()
N = int(input()) print((N+1)//2/N)
1
176,509,791,758,080
null
297
297
import sys input = sys.stdin.readline A = list(map(int, input().split())) if sum(A) >= 22: print('bust') else: print('win')
N=int(input()) A=list(map(int,input().split())) B=[0]*N for x in range(N-1): B[A[x]-1] += 1 for y in range(N): print(B[y])
0
null
75,551,591,341,740
260
169
i = input() if(i=='ABC'): print('ARC') else: print('ABC')
S=input() if S=="ABC": print("ARC") else:print("ABC")
1
24,178,973,838,454
null
153
153
def main(): X = int(input()) cnt = 0 money = 100 while money < X: cnt += 1 money = money * 101 money //= 100 #print(money) return cnt print(main())
N=int(input()) S,T=input().split() for i in range(N): print(S[i],T[i],sep='',end='') print()
0
null
69,739,057,310,732
159
255
X, K, D = map(int, input().split()) X = abs(X) q, m = divmod(X, D) if q >= K: print(X-K*D) elif (q+K)%2==0: print(m) else: print(-(m-D))
n=int(input()) list=list(map(int,input().split(" "))) list.reverse() for i in range(n-1): print(str(list[i])+" ",end="") print(str(list[n-1]))
0
null
3,089,419,120,072
92
53
X = int(input()) rank = -1 if X <= 599: rank = 8 elif X <= 799: rank = 7 elif X <= 999: rank = 6 elif X <= 1199: rank = 5 elif X <= 1399: rank = 4 elif X <= 1599: rank = 3 elif X <= 1799: rank = 2 else: rank = 1 print(rank)
import sys H, N = map(int, input().split()) data = [int(i) for i in input().split()] DATA = sorted(data, reverse=True) count = 0 for i in range(N): H = H - DATA[i] if H <= 0: print("Yes") sys.exit() else: print("No")
0
null
42,366,593,428,480
100
226
# -*- coding: utf-8 -*- """ コッホ曲線 参考:https://www.mynote-jp.com/entry/2016/04/30/201249    https://atarimae.biz/archives/23930 ・回転行列を使うと、向きの変わった座標が出せる。 ・そのために行列の計算方法も確認。  →m行n列成分は、「左の行列のm行目」と「右の行列のn列目」の内積 """ from math import sin, cos, radians N = int(input()) def dfs(p1x, p1y, p2x, p2y, depth): if depth == N: return sx = p1x + (p2x-p1x)/3 tx = p1x + (p2x-p1x)/3*2 sy = p1y + (p2y-p1y)/3 ty = p1y + (p2y-p1y)/3*2 # s,tを基準の位置として左回りに60度回転させる ux = sx + (tx-sx) * cos(radians(60)) - (ty-sy) * sin(radians(60)) uy = sy + (tx-sx) * sin(radians(60)) + (ty-sy) * cos(radians(60)) # 再帰が終了した場所から出力していけば、線分上の各頂点の順番になる dfs(p1x, p1y, sx, sy, depth+1) print(sx, sy) dfs(sx, sy, ux, uy, depth+1) print(ux, uy) dfs(ux, uy, tx, ty, depth+1) print(tx, ty) dfs(tx, ty, p2x, p2y, depth+1) print(0, 0) dfs(0, 0, 100, 0, 0) print(100, 0)
# (+1,+2)をn回,(+2,+1)をm回とすると # n + 2m = X # 2n + m = Y でn,mが求まる. # このとき答えは(n+m)Cn通り def combination(n,r): """ 高速な組み合わせの計算. nCrは必ず整数になるため分母を全部約分で1にしてから残った分子の積を求める. [参考]https://kadzus.hatenadiary.org/entry/20081211/1229023326 """ if n-r < r: r = n-r if r == 0: return 1 if r == 1: return int(n) numerator = [i+1 for i in range(n-r, n)] denominator = [i+1 for i in range(r)] for p in range(2,r+1): pivot = denominator[p-1] if pivot > 1: offset = (n-r)%p for k in range(p-1, r, p): numerator[k-offset] /= pivot denominator[k] /= pivot ans = 1 for i in range(r): if numerator[i] > 1: ans *= numerator[i] if ans >= 1e9+7: ans %= 1e9+7 return int(ans) X,Y = map(int, input().split()) if (X+Y)%3 != 0: ans = 0 else: n = int((2*Y-X)/3) m = int(Y-2*n) if n<0 or m<0: ans = 0 else: ans = combination(n+m, n) print(ans)
0
null
75,076,676,102,200
27
281
import math N = int(input()) s = 0 for a in range(1, N+1): s += (N-1)//a print(s)
n = int(input()) ans = 0 for i in range(1, n): for j in range(1, n): if i*j>=n: break ans += 1 print(ans)
1
2,602,929,634,912
null
73
73
S = input() Sr = S[ : : -1] hug = 0 for i in range(len(S)): if S[i] != Sr[i]: hug += 1 print((hug + 1) // 2)
N = int(input()) if N%1000==0: q = N//1000-1 else: q = N//1000 ans = 1000*(q+1)-N print(ans)
0
null
64,246,160,443,108
261
108
nm = input() print(nm[:3])
X, Y = map(int, input().split()) ans = 'No' for a in range(X + 1): b = X - a if Y == 2 * a + 4 * b: ans = 'Yes' break print(ans)
0
null
14,266,975,711,652
130
127
n = int(input()) % 10 if n == 3: print('bon') elif n == 0 or n == 1 or n == 6 or n == 8: print('pon') else: print('hon')
n = str(input()) if n[-1] in ['2', '4', '5', '7', '9']: how_to_read = 'hon' elif n[-1] in ['0', '1', '6', '8']: how_to_read = 'pon' else: how_to_read = 'bon' print(how_to_read)
1
19,242,087,939,030
null
142
142
from math import sqrt x1, y1, x2, y2 = map(float, input().split()) X = abs(x1 - x2) Y = abs(y1 - y2) print(sqrt(X**2 + Y**2))
import sys for line in sys.stdin: if len(line)>1: x1, y1, x2, y2 = line.strip('\n').split() x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2) print ((x1-x2)**2+(y1-y2)**2)**0.5
1
159,463,243,040
null
29
29
ans = [1,2,3] for i in [0,1]: y = int(input()) ans.remove(y) print(ans[0])
A=int(input()) B=int(input()) list1=[] list1.append(A) list1.append(B) if 1 not in list1: print(1) elif 2 not in list1: print(2) elif 3 not in list1: print(3)
1
110,564,912,087,132
null
254
254
import math a,b,c=map(int, input().split()) c=math.radians(c) print(0.5*a*b*math.sin(c)) print(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(c))) print(b*math.sin(c))
#coding = utf-8 import math a, b, c = map(float, raw_input().split()) h = b * math.sin(math.pi*c/180) s = a * h / 2 x = math.sqrt(h**2 + (a-b*math.sin(math.pi*(90-c)/180))**2) l = a + b + x #print "%.8f, %.8f, %.8f" % (s, l, h) print "\n".join([str(s), str(l), str(h)]) #print "%.1f, %.1f, %.1f" % (s, l, h)
1
179,365,002,360
null
30
30
s = input() if len(s) % 2 == 1: print('No') else: ans = "Yes" for i in range(len(s)): if i % 2 == 0 and s[i] != 'h': ans = "No" break if i % 2 == 1 and s[i] != 'i': ans = "No" break print(ans)
n = int(input()) print("".join(["ACL" for i in range(n)]))
0
null
27,859,251,125,564
199
69
def A(): n = int(input()) print(-(-n//2)) A()
N = int(input()) print(N//2 if N/2 == N//2 else N//2 + 1)
1
59,391,924,729,862
null
206
206
a=list(map(int,input().split())) print(*[a[2],a[0],a[1]],sep=' ')
for i in range(1,10): for j in range(1,10): print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))
0
null
19,046,997,994,562
178
1
n = int(input()) s = input() table = {x: 2**i for i, x in enumerate(map(chr, range(97, 123)))} SEG_LEN = n SEG = [0]*(SEG_LEN*2) def update(i, x): i += SEG_LEN SEG[i] = table[x] while i > 0: i //= 2 SEG[i] = SEG[i*2] | SEG[i*2+1] def find(left, right): left += SEG_LEN right += SEG_LEN ans = 0 while left < right: if left % 2 == 1: ans = SEG[left] | ans left += 1 left //= 2 if right % 2 == 1: ans = SEG[right-1] | ans right -= 1 right //= 2 return format(ans, 'b').count('1') for i, c in enumerate(s): update(i, c) q = int(input()) for _ in range(q): com, *query = input().split() if com == '1': idx, x = query update(int(idx)-1, x) else: L, R = map(int, query) print(find(L-1, R))
n = int(input()) xpy = [] xmy = [] for i in range(n): x,y = map(int,input().split()) xpy.append(x+y) xmy.append(x-y) xpy.sort() xmy.sort() print(max(abs(xpy[0]-xpy[-1]),abs(xmy[0]-xmy[-1])))
0
null
33,045,347,501,042
210
80
h, n = map(int, input().split()) a = [int(s) for s in input().split()] a.sort(reverse=True) ans = 'No' for s in a: h -= s if h <= 0: ans = 'Yes' print(ans)
H,N= map(int, input().split()) list = list(map(int, input().split())) #Aiを入力 for i in list: H=H-i if H<=0: print('Yes') else: print('No')
1
78,089,168,390,050
null
226
226
W,H,x,y,r = map(int,input().split()) if x >= r and x <= W-r and y >= r and y <= H-r: print('Yes') else: print('No')
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) 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) INF = 10**9 mod = 10**9+7 N,M = I() a = l() num1 = format(a[0],'b')[::-1].find('1') num2 = 1 for i in range(N): num2 = lcm(num2,a[i]) if num1 != format(a[i],'b')[::-1].find('1'): print(0) exit() num2 = num2//2 print(math.ceil(M//num2/2))
0
null
50,995,898,215,838
41
247
n = int(input()) l = sorted(list(map(int,input().split()))) ans = 0 for ai in range(n): for bi in range(ai+1,n): ok,ng = bi,n while ng-ok>1: mid = (ng+ok)//2 if l[mid]<l[ai]+l[bi]: ok = mid else: ng = mid ans += ok-bi print(ans)
a,b,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=10**6 for i in range(m): x,y,c=map(int,input().split()) ans=min(ans,a[x-1]+b[y-1]-c) print(min(ans,min(a)+min(b)))
0
null
112,642,111,416,718
294
200
N, = map(int, input().split()) print(1-N)
n=int(input()) a=list(map(int,input().split())) count=1 chk=False for i in range(1,n+1): if a[i-1]==count: chk=True count+=1 print(n-count+1 if chk else -1)
0
null
58,735,877,336,046
76
257
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): N = int(input()) A = list(map(int, input().split())) S = 0 for a in A: S = S ^ a answer = [] for a in A: answer.append(S ^ a) print(*answer) if __name__ == "__main__": main()
N=int(input()) A=list(map(int,input().split())) mlt=0 for a in A: mlt^=a for i in range(N): print(mlt^A[i],end=" ")
1
12,522,385,375,388
null
123
123
S = str(input()) le = len(S) s = [] for i in range(le): s.append(S[i]) r = s.count("R") if r == 0: print(0) elif r == 1: print(1) elif r == 2: if s[1] == "S": print(1) else: print(2) elif r == 3: print(3)
MAX = 5 * 10**5 SENTINEL = 2 * 10**9 cnt = 0 def merge(A, left, mid, right): n1 = mid - left; n2 = right - mid; L = A[left:left+n1] R = A[mid:mid+n2] global cnt L.append(SENTINEL) R.append(SENTINEL) 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 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) n = int(input()) s = list(map(int, input().split())) mergeSort(s, 0, len(s)) ans = [] for item in s: ans.append(str(item)) print(' '.join(ans)) print(cnt)
0
null
2,460,567,204,332
90
26
def draft(A, K, N): for _ in range(1, K+1):# 2 * 10**5 tmp = [0]*(N+1) for i in range(N):# 2 * 10**5 L = max(0, i - A[i]) R = min(N, i + A[i]+1) tmp[L] += 1 tmp[R] -= 1 f = True for i in range(N): tmp[i+1] += tmp[i] A[i] = tmp[i] if A[i] != N: f = False if f: break for i in range(N): print(A[i], end=" ") def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) draft(A, K, N) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- n, k = map(int, input().split()) a = list(map(int, input().split())) for j in range(k): b = [0] * (n + 1) for i in range(n): left_edge = max(0, i-a[i]) right_edge = min(i + a[i] + 1, n) b[left_edge] += 1 b[right_edge] -= 1 for i in range(1, n+1): b[i] = b[i] + b[i-1] b.pop(n) if a == b: break a = b.copy() print(' '.join(str(b[i]) for i in range(n)))
1
15,442,781,459,170
null
132
132
#!/usr/bin/env python3 while(True): try: a,b=map(int, input().split()) except EOFError: break #euclidian algorithm r=a%b x,y=a,b while(r>0): x=y y=r r=x%y gcd=y lcm=int(a*b/gcd) print("{0} {1}".format(gcd, lcm))
class Combination(): # nCr(mod p) #n<=10**6 def __init__(self, N, MOD): # cmbの前処理 self.mod = MOD self.FACT = [1, 1] # 階乗 self.INV = [0, 1] # 各iの逆元 self.FACTINV = [1, 1] # 階乗の逆元 for i in range(2, N + 1): self.FACT.append((self.FACT[-1] * i) % self.mod) self.INV.append(pow(i, self.mod - 2, self.mod)) self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod) def count(self, N, R): # nCr(mod p) #前処理必要 if (R < 0) or (N < R): return 0 R = min(R, N - R) return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mod = 10 ** 9 + 7 ans = 0 cmb = Combination(n, mod) for i in range(n): cnt = cmb.count(i, k - 1) - cmb.count(n - i - 1, k - 1) ans += a[i] * cnt % mod print(ans % mod)
0
null
48,050,229,731,308
5
242
def main(): number = int(input()) queue = ["a"] for i in range(number - 1): now_queue = [] for now in queue: limit = ord(max(now)) + 2 for j in range(ord("a"), limit): now_queue.append(now + chr(j)) queue = now_queue for q in queue: print(q) if __name__ == '__main__': main()
class Dice: dice = {'N':2, 'E':4, 'S':5, 'W':3} currTop = 1 def top(self): return self.currTop def rot(self, direction): newTop = self.dice[direction] currTop = self.currTop self.currTop = newTop if direction == 'N': self.dice['N'] = 7 - currTop self.dice['S'] = currTop elif direction == 'S': self.dice['N'] = currTop self.dice['S'] = 7 - currTop elif direction == 'E': self.dice['E'] = 7 - currTop self.dice['W'] = currTop elif direction == 'W': self.dice['E'] = currTop self.dice['W'] = 7 - currTop faces = list(map(int, input().split())) cmd = input() d = Dice() for c in cmd: d.rot(c) print(faces[d.top()-1])
0
null
26,432,835,428,078
198
33
H,W,s=list(map(int,input().split())) l=[list(input()) for i in range(H)] l_h=[0]*H for i in range(H): if "#" in set(l[i]): l_h[i]=1 cnt=0 bor=sum(l_h)-1 for i in range(H): if cnt==bor: break if l_h[i]==1: l_h[i]=-1 cnt+=1 cnt=1 import numpy as np tmp=[] st=0 ans=np.zeros((H,W)) for i in range(H): tmp.append(l[i]) if l_h[i]==-1: n_tmp=np.array(tmp) s_count=np.count_nonzero(n_tmp=="#")-1 for j in range(W): ans[st:i+1,j]=cnt if "#" in n_tmp[:,j] and s_count>0: cnt+=1 s_count-=1 st=i+1 cnt+=1 tmp=[] n_tmp=np.array(tmp) s_count=np.count_nonzero(n_tmp=="#")-1 for j in range(W): ans[st:i+1,j]=cnt if "#" in n_tmp[:,j] and s_count>0: cnt+=1 s_count-=1 for i in ans: print(*list(map(int,i)))
N = int(input()) A = list(map(int, input().split())) min = 1 check = True count = 0 for i in range(N): if A[i] != min: A[i] = 0 count += 1 elif A[i] == min: min += 1 if A == [0] * N: print(-1) else: print(count)
0
null
129,435,897,178,848
277
257
N = int(input()) ct = [] for i in range(N): ct.append([int(i) for i in input().split()]) dist = 0 for a in ct: for b in ct: dist += (abs(a[0] - b[0])**2 +abs(a[1] - b[1])**2)**0.5 print(dist/N)
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N, K = map(int, readline().split()) A = list(map(int, readline().split())) A.sort() lenA = len(A) ans = 0 if K == 1: print(0) sys.exit() def com(n, r, mod): r = min(r, n - r) if r == 0: return 1 res = ilist[n] * iinvlist[n - r] * iinvlist[r] % mod return res def modinv(a, mod=10 ** 9 + 7): return pow(a, mod - 2, mod) ilist = [0] iinvlist = [1] tmp = 1 for i in range(1, N + 1): tmp *= i tmp %= mod ilist.append(tmp) iinvlist.append(modinv(tmp, mod)) sum_of_com = [] now = 0 for i in range(K-2, N+1): now += com(i, K-2, mod) sum_of_com.append(now) ans = 0 for first in range(lenA-K+1): ans -= A[first] * sum_of_com[lenA-first-K] for last in range(K-1, lenA): ans += A[last] * sum_of_com[last-K+1] ans %= mod print(ans) if __name__ == '__main__': solve()
0
null
121,672,359,436,714
280
242
N=int(input()) print(sum((N-1)//a for a in range(1,N+1)))
#!/usr/bin/env python3 import sys import numpy as np import numba from numba import njit, b1, i4, i8, f8 input = sys.stdin.readline def I(): return int(input()) @njit((i8,), cache=True) def main(n): table = np.zeros(n, np.int64) for i in range(1, n): table[::i] += 1 ans = 0 for n in table[1:]: q, r = divmod(n, 2) ans += q * 2 + 1 * r return ans N = I() print(int(main(N)))
1
2,590,842,174,338
null
73
73
H, W, M = map(int, input().split()) HW = [] for _ in range(M): HW.append(list(map(int, input().split()))) A = [0] * (H + 1) B = [0] * (W + 1) for h, w in HW: A[h] += 1 B[w] += 1 a = max(A) b = max(B) cnt = A.count(a) * B.count(b) - len([0 for h, w in HW if A[h] == a and B[w] == b]) print(a + b - (cnt == 0))
n = int(input()) s = ["" for i in range(n)] t = [0 for i in range(n)] for i in range(n): a, b = input().split() s[i], t[i] = a, int(b) x = input() ans = 0 flag = False for i in range(n): if s[i] == x: flag = True elif flag: ans += t[i] print(ans)
0
null
50,536,963,265,448
89
243
N, M = map(int, input().split()) A_list = list(map(int, input().split())) for i in range(M): N -= A_list[i] if N < 0: print(-1) break if i == M-1: print(N)
from collections import deque n,m=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 g[a].append(b) g[b].append(a) def bfs(u): queue = deque([u]) d = [None]*n d[u] = 0 while queue: v=queue.popleft() for i in g[v]: if d[i] is None: d[i] = d[v]+1 queue.append(i) return d d = bfs(0) print('Yes') for i in range(1,n): for j in g[i]: if d[j]<d[i]: print(j+1) break
0
null
26,317,859,037,040
168
145
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) a = LI() s = sum(a) if s >= 22: print('bust') else: print('win')
out = 0 inp = list(map(int, input().split())) while 0<len(inp): out += inp.pop(0) if out <= 21: print('win') else: print('bust')
1
118,994,270,344,950
null
260
260
import sys import math def main(): r = float(sys.stdin.readline()) print(math.pi * r**2, 2 * math.pi * r) return if __name__ == '__main__': main()
import math r = input() print "%.6f %.6f" % (math.pi * r * r, math.pi * 2 * r)
1
638,226,757,802
null
46
46
i=1 while True: x = int(input()) if x==0: break print('Case ',i,': ',x,sep='') i=i+1;
i = 1 while True: x = int(raw_input()) if x == 0: break else: print "Case %d: %d" % (i, x) i += 1
1
488,843,942,520
null
42
42
def main(): _ = int(input()) num_tuple = tuple(map(int, input().split())) count = 0 for i, num in enumerate(num_tuple): if ((i+1)*num) % 2 == 1: count += 1 print(count) if __name__ == '__main__': main()
import re s = input() if s == "hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s== "hihihihihi": print("Yes") else: print("No")
0
null
30,548,106,176,768
105
199
n,m = list(map(int, input().split())) parent = list(range(n)) def root(x): if parent[x] == x: return x rt = root(parent[x]) parent[x] = rt return rt def unite(x,y): x = root(x) y = root(y) if x == y: return parent[y] = x for _ in range(m): a,b = list(map(lambda x: int(x)-1, input().split())) unite(a,b) for i in range(n): root(i) cnt = len(set(parent)) - 1 print(cnt)
from collections import defaultdict def bfs(s): q = [s] while q != []: p = q[0] del q[0] for node in adj[p]: if not visited[node]: visited[node] = True q.append(node) n,m = map(int,input().split()) adj = defaultdict(list) visited = [False]*(n+1) comp = 0 for _ in range(m): a,b = map(int,input().split()) adj[a].append(b) adj[b].append(a) for i in range(1,n+1): if not visited[i]: comp+=1 bfs(i) print(comp-1)
1
2,329,833,597,472
null
70
70
K, N = map(int, input().split()) A = list(map(int, input().split())) import numpy as np a = np.array(A) D = np.diff(a) D = np.append(D, a[0] + K - a[-1]) print(K - max(D))
k, n = map(int,input().split()) a = list(map(int,input().split())) new_a = sorted(a) num = len(new_a) - 1 s_a = [] b = (k - new_a[num]) + new_a[0] s_a.append(b) cun = 0 for i in new_a[1::]: s = i - new_a[cun] s_a.append(s) cun += 1 max_num = max(s_a) print(sum(s_a) - max_num)
1
43,304,644,567,808
null
186
186
n = int(input()) s = [input() for i in range(n)] c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(len(s)): if s[i] == "AC": c0 += 1 elif s[i] == "WA": c1 += 1 elif s[i] == "TLE": c2 += 1 else: c3 += 1 print("AC x ", str(c0)) print("WA x ", str(c1)) print("TLE x ", str(c2)) print("RE x ", str(c3))
n=int(input()) a=[input() for i in range(n)] b=a.count("AC") c=a.count("TLE") d=a.count("WA") e=a.count("RE") print(f"AC x {b}") print(f"WA x {d}") print(f"TLE x {c}") print(f"RE x {e}")
1
8,709,441,677,440
null
109
109
print(-(-int(input()) // 2))
import math h,w = map(int,input().split()) if h == 1 or w == 1: print(1) else: print(math.ceil(h/2*w))
0
null
54,982,572,476,872
206
196
from math import ceil h,w=map(int,input().split()) ans=0 if h==1 or w==1: ans=1 elif (h*w)%2==0: ans=int(h*w//2) else: ans=ceil(h*w/2) print(ans)
import sys input = sys.stdin.readline N, P = map(int, input().split()) S = list(input().rstrip()) if P in {2, 5}: ans = 0 for i, s in enumerate(S): if int(s) % P == 0: ans += i+1 else: ans = 0 T = [0]*P T[0] = 1 tmp = 0 k = 1 for s in reversed(S): tmp = (tmp + k * int(s)) % P k = k * 10 % P ans += T[tmp] T[tmp] += 1 print(ans)
0
null
54,471,187,239,300
196
205
import math n, m = map(int, input().split()) r = 2 if (n > 1): cn = math.factorial(n) / (2 * math.factorial(n - r)) else: cn = 0 if (m > 1): cm = math.factorial(m) / (2 * math.factorial(m - r)) else : cm = 0 print(int(cn+cm))
n,m = map(int,input().split()) ans = 0 if n > 1: ans += n * (n -1) / 2 if m > 1: ans += m *(m - 1) / 2 print(int(ans))
1
45,576,217,637,020
null
189
189
nums = list(map(int, input().split())) nums.sort() print(nums[0], nums[1], nums[2])
# -*- coding: utf-8 -*- S = int(raw_input()) h = S / 3600 S %= 3600 m = S / 60 S %= 60 s = S print "%d:%d:%d" %(h, m, s)
0
null
369,467,459,202
40
37
from sys import stdin from collections import deque n = int(stdin.readline()) g = [None] * n for _ in range(n): u, _, *cs = [int(s) for s in stdin.readline().split()] g[u-1] = [c - 1 for c in cs] ds = [-1] * n v = [False] * n v[0] = True q = deque([(0, 0)]) while len(q): u, d = q.popleft() ds[u] = d for c in g[u]: if not v[c]: v[c] = True q.append((c, d + 1)) for u, d in enumerate(ds): print(u + 1, d)
from math import gcd from collections import defaultdict MOD = 10**9+7 n = int(input()) cnt = defaultdict(lambda: [0, 0]) zeros = 0 for _ in range(n): a, b = map(int, input().split()) if a == b == 0: zeros += 1 continue if a < 0: a *= -1 b *= -1 g = gcd(a, b) a //= g b //= g if b > 0: cnt[(a, b)][0] += 1 else: if a == 0 and b < 0: cnt[(a, -b)][0] += 1 else: cnt[(-b, a)][1] += 1 ans = 1 for v, v2 in cnt.values(): ans *= 1+pow(2, v, MOD)-1+pow(2, v2, MOD)-1 ans %= MOD ans = (ans+zeros-1) % MOD print(ans)
0
null
10,482,661,713,898
9
146
#!/usr/bin/env python3 from collections import Counter def main(): S = input() N = len(S) T = [0] * (N+1) for i in range(N-1,-1,-1): T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019 l = Counter(T) ans = 0 for v in l.values(): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
# Forbidden List X, N = [int(i) for i in input().split()] pi = [int(i) for i in input().split()] pl = [] pu = [] for i in pi: if i <= X: pl.append(i) if X <= X: pu.append(i) pl.sort(reverse=True) pu.sort() nl = X for i in pl: if i == nl: nl -= 1 nu = X for i in pu: if i == nu: nu += 1 if X - nl <= nu - X: print(nl) else: print(nu)
0
null
22,379,043,083,712
166
128
s = input() l = s.split(" ") a,b = int(l[0]), int(l[1]) print(a*b)
import math L,R,d = map(int, input().strip().split()) x=math.ceil(L/d) y=math.floor(R/d) print(y-x+1)
0
null
11,688,348,723,998
133
104
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, K = map(int, readline().split()) point = list(map(int, readline().split())) T = readline().strip() T = T.translate(str.maketrans('rsp', '012')) T = list(map(int, T)) ans = 0 for i in range(K): vec = T[i::K] M = len(vec) dp = [[0] * 3 for _ in range(M + 1)] for j in range(M): for k in range(3): dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3]) if (k + 1) % 3 == vec[j]: dp[j + 1][k] += point[k] ans += max(dp[M]) print(ans) return if __name__ == '__main__': main()
S = input() if S[-1] != 's': S = S + 's' elif S[-1] == 's': S = S + 'es' print(S)
0
null
54,669,408,974,432
251
71
# B - Bishop H,W = map(int,input().split()) if H>1 and W>1: print((H*W+1)//2) else: print(1)
x,y=list(map(int,raw_input().split())) w=x h=y if x==1 or y==1: print("1") exit(0) ans=x//2 * (h//2 + (h+1)//2) if x%2==1: ans+=(h+1)//2 print(ans)
1
50,599,103,771,022
null
196
196
n = int(input()) dic = {} for i in range(1,50000): dic[int(i * 1.08)] = i if n in dic: print(dic[n]) else: print(':(')
h1, m1, h2, m2, k = [int(_) for _ in input().split()] print((h2 - h1) * 60 + m2 - m1 - k)
0
null
71,888,061,570,068
265
139
s = input() print('No' if s.count('A') > 2 or s.count('B') > 2 else 'Yes')
# A - Station and Bus # https://atcoder.jp/contests/abc158/tasks/abc158_a s = input() if len(set(s)) == 2: print('Yes') else: print('No')
1
54,975,144,273,712
null
201
201
n=int(input()) A=list(map(int,input().split())) r = [-1]*n for i,a in enumerate(A): r[a-1]=i+1 for r2 in r: print(r2)
N = int(input()) A = list(map(int,input().split())) Adict = {} for i in range(N): Adict[A[i]] = (i+1) ans = [] for i in range(1,N+1): ans.append(str(Adict[i])) print(" ".join(ans))
1
181,062,202,727,692
null
299
299
n,m = map(int, input().split()) #a = list(map(int, input().split())) class UnionFind: def __init__(self,n): self.par=[i for i in range(n)] self.siz=[1]*n def root(self,x): while self.par[x]!=x: self.par[x]=self.par[self.par[x]] x=self.par[x] return x def unite(self,x,y): x=self.root(x) y=self.root(y) if x==y: return False if self.siz[x]<self.siz[y]: x,y=y,x self.siz[x]+=self.siz[y] self.par[y]=x return True def is_same(self,x,y): return self.root(x)==self.root(y) def size(self,x): return self.siz[self.root(x)] uni = UnionFind(n) for i in range(m): a,b = map(int, input().split()) uni.unite(a-1, b-1) cnt = [0]*(n) for i in range(n): cnt[uni.root(i)] = 1 print(sum(cnt)-1)
import math a, b, C = map(int, input().split()) C = math.radians(C) S = a * b * math.sin(C) * 0.5 c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(C)) L = a + b + c h = 2 * S / a print(S, L, h)
0
null
1,241,829,301,152
70
30
import math pai = math.pi r = float(input()) print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
import math n = int(input()) xy = [] for i in range(n): XY = list(map(int,input().split())) xy.append(XY) total = 0 for i in range(n - 1): for j in range(i + 1,n): total += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) print(total * 2 / n)
0
null
74,351,331,457,600
46
280
while True: a, b, c = map(int, raw_input().split()) if (a == -1) and (b == -1) and (c == -1): break if (a == -1) or (b == -1): print "F" elif (a + b) >= 80: print "A" elif (a + b) >= 65: print "B" elif (a + b) >= 50: print "C" elif (a + b) < 30: print "F" elif c >= 50: print "C" else: print "D"
while True : a, b, c = [int(temp) for temp in input().split()] if a == b == c == -1 : break if (a == -1) or (b == -1) or (a + b < 30) : print('F') elif (80 <= a + b) : print('A') elif (65 <= a + b) : print('B') elif (50 <= a + b) or ((30 <= a + b) and (50 <= c)) : print('C') else : print('D')
1
1,233,255,918,350
null
57
57
import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 a, b, x = rm() x /= a if a*b / 2 >= x: a = 2*x / b print(90 - math.degrees(math.atan(a/b))) else: x = a*b - x b = 2*x / a print(math.degrees(math.atan(b/a)))
N=int(input()) count=0 for i in range(1,N): for j in range(1,(N-1)//i+1): count+=1 print(count)
0
null
82,528,247,391,700
289
73
import math; in_put = input(""); cube=math.pow(float(in_put),3); print(int(cube));
a=input() print a ** 3
1
289,737,420,128
null
35
35
S = ['0'] + list(input()) + ['0'] N = len(S) flag = False ans = 0 for i in range(N - 1, 0, -1): j = int(S[i]) if flag: j += 1 S[i] = j if j <= 5: if j == 5 and int(S[i - 1]) >= 5: ans += j flag = True else: ans += j flag = False else: ans += 10 - j flag = True if flag: ans += 1 # print (ans) count = 0 for s in S: if s == 5: count += 1 else: ans -= max(0, count - 2) count = 0 print (ans)
s = input() s = "".join([ i for i in reversed(s)]) + "0" INF = 10 ** 32 n = len(s) dp = [ [INF]*2 for _ in range(n)] dp[0][0] = 0 for i in range(n-1): x = int(s[i]) dp[i+1][0] = min( dp[i][0]+x, dp[i][1]+x ) dp[i+1][1] = min( dp[i][0]+1+(10-x), dp[i][1]+(9-x) ) print(min(dp[n-1][0], dp[n-1][1]))
1
71,047,990,049,348
null
219
219
from sys import stdin rs = stdin.readline ri = lambda : int(rs()) ril = lambda : list(map(int, rs().split())) def main(): N = ri() c = rs() x = 0 y = c.count('R') for e in c: if x == y: break elif e == 'W': x += 1 else: y -= 1 print(y) if __name__ == '__main__': main()
n = int(input()) lis =[] for i in range(1,n+1): lis.append(i) odd =[] for j in lis: if j % 2 != 0: odd.append(j) print(len(odd)/len(lis))
0
null
91,555,630,503,162
98
297
n, m = map(int, input().split()) ans = 0 if n >= 2: ans += n * (n - 1) / 2 if m >= 2: ans += m * (m - 1) / 2 print(int(ans))
N,M=map(int,input().split()) n=N*(N-1) m=M*(M-1) result=int((n+m)/2) print(result)
1
45,400,122,911,918
null
189
189
import copy N, M = map(int, input().split()) res = [[] for i in range(N+5)] for i in range(M) : a,b = map(int, input().split()) a -= 1 b -= 1 res[a].append(b) res[b].append(a) pre = [-1] * N dist = [-1] * N d = 1 dl = [] pre[0] = 0 dist[0] = 0 dl.append(0) while(len(dl) != 0) : a = dl[0] dl.pop(0) for i in res[a] : if(dist[i] != -1): continue dist[i] = dist[a] + 1 pre[i] = a dl.append(i) for i in range(N) : if(i == 0) : print("Yes") continue print(pre[i] + 1)
def gcd(a, b): if a > b: a, b = b, a if a == 0: return b else: return gcd(b % a, a) try: while 1: a,b = list(map(int,input().split())) c = gcd(a, b) print('{} {}'.format(c,int(c * (a/c) * (b/c)))) except Exception: pass
0
null
10,325,017,302,368
145
5
X, Y = list(map(int, input().split())) judge = 0 for a in range(X + 1): if (Y - a*2 - (X-a)*4 ) == 0: print("Yes") judge = 1 break if judge == 0: print("No")
from string import ascii_lowercase N = int(input()) k = [0, 26] for i in range(1, 13): k.append(26 * (k[i] + 1)) for i in range(13): if k[i] + 1 <= N <= k[i+1]: n = N - (k[i] + 1) for j in range(i, -1, -1): print(ascii_lowercase[(n//26**j) % 26], end="")
0
null
12,751,762,018,438
127
121
def matprod(A,B): C = [] for i in range(len(A)): tmpList = [] for k in range(len(B[0])): tmpVal = 0 for j in range(len(A[0])): tmpVal += A[i][j] * B[j][k] tmpList.append(tmpVal) C.append(tmpList) return C n,m,l = map(int, input().split()) A = [] for i in range(n): A.append(list(map(int, input().split()))) B = [] for i in range(m): B.append(list(map(int, input().split()))) for cr in matprod(A,B): print(' '.join(map(str, cr)))
h,w = [],[] while True: (h,w) = [int(x) for x in input().split()] if h == w == 0: break for x in range(h): for y in range(w): if (x + y) % 2 == 0: print('#', end='') else: print('.', end='') print() print()
0
null
1,148,116,703,692
60
51
a, b, x = map(int, input().split()) if x > (a**2)*b/2: t = 2*((a**2)*b-x)/(a**3) else: t = a*(b**2)/(2*x) import math ans = math.degrees(math.atan(t)) print(ans)
import math a, b, x = map(int, input().split()) if x == a**2*b: print(0) elif x >= a**2*b/2: print(90 - math.degrees(math.atan(a**3/(2*a**2*b-2*x)))) else: print((90 - math.degrees(math.atan(2*x/(a*b**2)))))
1
163,120,580,892,260
null
289
289
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): S = set(map(int, readline().split())) if len(S) == 2: print("Yes") else: print("No") if __name__ == '__main__': main()
#!/usr/bin/env python3 a = list(map(int, input().split())) if len(a) - len(set(a)) == 1: print('Yes') else: print('No')
1
68,280,193,966,248
null
216
216
def main(): H, W, K = [int(k) for k in input().split(" ")] C = [] black_in_row = [] black_in_col = [0] * W for i in range(H): C.append(list(input())) black_in_row.append(C[i].count("#")) for j in range(W): if C[i][j] == "#": black_in_col[j] += 1 black = sum(black_in_row) if black < K: print(0) return 0 cnt = 0 for i in range(2 ** H): row_bit = [f for f, b in enumerate(list(pad_zero(format(i, 'b'), H))) if b == "1"] r = sum([black_in_row[y] for y in row_bit]) for j in range(2 ** W): col_bit = [f for f, b in enumerate(list(pad_zero(format(j, 'b'), W))) if b == "1"] c = sum([black_in_col[x] for x in col_bit]) bl = black - r - c + sum([1 for p in row_bit for q in col_bit if C[p][q] == "#"]) if bl == K: cnt += 1 print(cnt) def pad_zero(s, n): s = str(s) return ("0" * n + s)[-n:] main()
H, W, K = map(int,input().split()) grid = [list(input()) for i in range(H)] total = 0 for mask1 in range(1<<H): for mask2 in range(1<<W): ct = 0 for i in range(H): for j in range(W): if grid[i][j]=='#' and not (1<<i)&mask1 and not (1<<j)&mask2: ct += 1 if ct==K: total += 1 print(total)
1
9,011,263,661,400
null
110
110
R = int(input()) print(2 * R * 3.14159265359)
MOD = 10**9+7 k = int(input()) s = input() n = len(s) U = n+k fact = [0]*(U+1) fact[0] = 1 for i in range(1, U+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(U+1) invfact[U] = pow(fact[U], MOD-2, MOD) for i in reversed(range(U)): invfact[i] = invfact[i+1]*(i+1) % MOD def nCr(n, r): if r < 0 or n < r: return 0 return fact[n]*invfact[r]*invfact[n-r] ans = 0 for x in range(k+1): ans += pow(26, x, MOD)*nCr(n+k-x-1, n-1)*pow(25, k-x, MOD) ans %= MOD print(ans)
0
null
22,110,006,451,338
167
124
n, m = map(int, input().split()) mat = [map(int,input().split()) for i in range(n)] vec = [int(input()) for i in range(m)] for row in mat: print(sum([a*b for (a,b) in zip(row, vec)]))
N=int(input()) S=set() for i in range(1,N): x=i y=N-i if x<y: S.add(x) print(len(S))
0
null
76,983,667,502,600
56
283
N = int(input()) NN = [[0]*10 for _ in range(11)] for i in range(11,100): As = str(i)[0] Ae = str(i)[-1] cnt = 0 for j in range(1,N+1): if str(j)[-1]== As and str(j)[0] == Ae: cnt +=1 NN[int(As)][int(Ae)] = cnt ans = 0 for i in range(1,N+1): ans += NN[int(str(i)[0])][int(str(i)[-1])] print(ans)
import sys import collections import bisect def main(): n = int(input()) ac, bc = collections.Counter([str(i + 1)[0] + str(i + 1)[-1] for i in range( n)]), collections.Counter([str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]) print(sum(ac[i] * bc[i] for i in ac.keys())) if __name__ == '__main__': main()
1
86,494,920,817,954
null
234
234
import sys lines = sys.stdin.readlines() N = lines[0] A = lines[1].strip().split(" ") count = 0 for i in range(len(A)): minj = i for j in range(i, len(A)): if int(A[j]) < int(A[minj]): minj = j if i != minj: a = A[i] b = A[minj] A[i] = b A[minj] = a count += 1 print " ".join(A) print count
import sys def selectionSort(x_list, y): a = 0 for i in range(y): minj = i for j in range(i, y): if x_list[j] < x_list[minj]: minj = j x_list[i], x_list[minj] = x_list[minj], x_list[i] if x_list[i] != x_list[minj]: a += 1 return a y = sys.stdin.readline() y = int(y) x = sys.stdin.readline() x_list = x.split(" ") for i in range(y): x_list[i] = int(x_list[i]) a = selectionSort(x_list, y) for k in range(0, y): print x_list[k], print print a
1
22,750,906,490
null
15
15
def inpl(): return list(map(int, input().split())) X = [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] print(X[int(input())-1])
import sys from collections import deque import numpy as np import math sys.setrecursionlimit(10**6) def S(): return sys.stdin.readline().rstrip() def SL(): return map(str,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def Main(): a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = I() print(a[k-1]) return if __name__=='__main__': Main()
1
49,886,347,581,952
null
195
195
H1,M1,H2,M2,K=map(int,input().split()) t1=60*H1 + M1 t2=60*H2 + M2 t=t2 - K ans=t-t1 print(max(0,ans))
a=list(map(int, input().split(' '))) # 起きてる時間(分)の計算 h=a[2]-a[0] m=a[3]-a[1] mt=h*60+m # 時間の表示 print(mt-a[4])
1
18,089,266,567,230
null
139
139
import sys sys.setrecursionlimit(10**7) def dfs(f): if vis[f] == 1: return vis[f] = 1 for t in V[f]: dfs(t) n, m = map(int, input().split()) E = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)] V = [[] for _ in range(n)] for a, b in E: V[a].append(b); V[b].append(a) ans = 0 vis = [0]*n for a in range(n): if vis[a]==1: continue ans+=1 dfs(a) print(ans-1)
code = """ # distutils: language=c++ # distutils: include_dirs=[/home/USERNAME/.local/lib/python3.8/site-packages/numpy/core/include, /opt/ac-library] # cython: boundscheck=False # cython: wraparound=False from libcpp cimport bool from libc.stdio cimport getchar, printf from libcpp.string cimport string from libcpp.vector cimport vector cdef extern from "<atcoder/dsu>" namespace "atcoder": cdef cppclass dsu: dsu(int n) int merge(int a, int b) bool same(int a, int b) int leader(int a) int size(int a) vector[vector[int]] groups() cdef class Dsu: cdef dsu *_thisptr def __cinit__(self, int n): self._thisptr = new dsu(n) cpdef int merge(self, int a, int b): return self._thisptr.merge(a, b) cpdef bool same(self, int a, int b): return self._thisptr.same(a, b) cpdef int leader(self, int a): return self._thisptr.leader(a) cpdef int size(self, int a): return self._thisptr.size(a) cpdef vector[vector[int]] groups(self): return self._thisptr.groups() cpdef inline vector[int] ReadInt(int n): cdef int b, c cdef vector[int] *v = new vector[int]() for i in range(n): c = 0 while 1: b = getchar() - 48 if b < 0: break c = c * 10 + b v.push_back(c) return v[0] cpdef inline vector[string] Read(int n): cdef char c cdef vector[string] *vs = new vector[string]() cdef string *s for i in range(n): s = new string() while 1: c = getchar() if c<=32: break s.push_back(c) vs.push_back(s[0]) return vs[0] cpdef inline void PrintLongN(vector[long] l): cdef int n = l.size() for i in range(n): printf("%ld\\n", l[i]) cpdef inline void PrintLong(vector[long] l): cdef int n = l.size() for i in range(n): printf("%ld ", l[i]) """ import os, sys, getpass if sys.argv[-1] == 'ONLINE_JUDGE': code = code.replace("USERNAME", getpass.getuser()) open('atcoder.pyx','w').write(code) os.system('cythonize -i -3 -b atcoder.pyx') sys.exit(0) from atcoder import Dsu, ReadInt def main(): N,M = ReadInt(2) dsu = Dsu(N) for i in range(M): a,b = ReadInt(2) dsu.merge(a-1,b-1) print(len(dsu.groups())-1) if __name__ == "__main__": main()
1
2,287,397,503,060
null
70
70
# Binary Indexed Tree (Fenwick Tree) class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.bit[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i-1) def lower_bound(self,x): w = i = 0 k = 1<<((self.n).bit_length()) while k: if i+k <= self.n and w + self.bit[i+k] < x: w += self.bit[i+k] i += k k >>= 1 return i+1 def alph_to_num(s): return ord(s)-ord('a') def solve(): N = int(input()) S = list(map(alph_to_num,list(input()))) Q = int(input()) bits = [BIT(N) for _ in range(26)] for i in range(N): bits[S[i]].add(i+1,1) ans = [] for _ in range(Q): x,y,z = input().split() y = int(y) if x=='1': z = alph_to_num(z) bits[S[y-1]].add(y,-1) S[y-1] = z bits[z].add(y,1) if x=='2': z = int(z) ans.append(sum([bits[i].get(y,z)>0 for i in range(26)])) return ans print(*solve(),sep='\n')
class SegmentTree(): def segfunc(self, x, y): return x|y #関数 def __init__(self, a): #a:リスト n = len(a) self.ide_ele = 0 #単位元 self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗 self.seg = [self.ide_ele]*2*self.num #set_val for i in range(n): self.seg[i+self.num-1] = a[i] #built for i in range(self.num-2,-1,-1): self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2]) def update(self, k, s): x = 1<<(ord(s)-97) k += self.num-1 self.seg[k] = x while k: k = (k-1)//2 self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2]) def query(self, p, q): if q <= p: return self.ide_ele p += self.num-1 q += self.num-2 res = self.ide_ele while q - p > 1: if p&1 == 0: res = self.segfunc(res, self.seg[p]) if q&1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = self.segfunc(res,self.seg[p]) else: res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q]) return res def popcount(x): '''xの立っているビット数をカウントする関数 (xは64bit整数)''' # 2bitごとの組に分け、立っているビット数を2bitで表現する x = x - ((x >> 1) & 0x5555555555555555) # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと x = x + (x >> 8) # 16bitごと x = x + (x >> 16) # 32bitごと x = x + (x >> 32) # 64bitごと = 全部の合計 return x & 0x0000007f N = int(input()) S = list(input()) for i in range(N): S[i] = 1<<(ord(S[i])-97) Seg = SegmentTree(S) Q = int(input()) for i in range(Q): x, y, z = input().split() if int(x) == 1: Seg.update(int(y)-1, z) else: print(popcount(Seg.query(int(y)-1, int(z))))
1
62,613,173,228,642
null
210
210
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, t = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort() res = 0 dp = [[0] * (t + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = AB[i - 1] for j in range(1, t + 1): if j - a >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b) else: dp[i][j] = dp[i - 1][j] for k in range(i, n): _, b = AB[k] res = max(res, dp[i][j - 1] + b) print(res) if __name__ == '__main__': resolve()
from collections import Counter class UnionFind: def __init__(self,num:int): self.r = [-1 for i in range(num)] def root(self,x:int): if(self.r[x] < 0): return x self.r[x] = self.root(self.r[x]) return self.r[x] def unite(self,x:int,y:int): rx = self.root(x) ry = self.root(y) if(rx == ry): return False if(self.r[rx] > self.r[ry]): rx,ry = ry,rx self.r[rx] += self.r[ry] self.r[ry] = rx return True def size(self,x:int): return -self.r[self.root(x)] N,M = map(int,input().split()) group = UnionFind(N) for i in range(M): A,B = map(int,input().split()) group.unite(A-1,B-1) ans = 0 for i in range(N): ans = max(ans,group.size(i)) print(ans)
0
null
77,792,846,707,652
282
84
# -*- coding: utf-8 -*- def resolve(T,v): lv = v while lv != T[lv]: lv = T[lv] T[v] = lv return lv def solve(): N, M = map(int, input().split()) T = list(range(N+1)) for i in range(M): u, v = map(int, input().split()) lu = resolve(T,u) lv = resolve(T,v) if lv == lu: continue T[lv] = lu #print(f'===round{i}===') #print(T) #print([resolve(T,v) for v in range(N+1)]) return len(set(resolve(T,v) for v in range(1,N+1)))-1 if __name__ == '__main__': print(solve())
c = input() alphabet = 'abcdefghijklmnopqrstuvwxyz' list_a = list(alphabet) num_c = list_a.index(c) print(list_a[num_c + 1])
0
null
47,110,242,035,760
70
239
import sys X = int(input()) for i in range(1,180): if int(360*i/X) == 360*i/X: print(int(360*i/X)) sys.exit()
import numpy as np from numba import njit, i8 import sys read = sys.stdin.readline mod = 10 ** 9 + 7 @njit((i8, i8[:]), cache=True) def main(n, a): s = np.zeros(n + 1, dtype=np.int64) for i in range(n): s[i + 1] = (a[i] + s[i]) % mod ans = 0 for i in range(1, n): ans = (ans + a[i] * s[i] % mod) % mod print(ans) n = int(read()) a = np.fromstring(read(), dtype=np.int64, sep=' ') main(n, a)
0
null
8,517,567,657,060
125
83
N = int(input()) ans = 0 c = input() redNum = c.count("R") leftWhite = c.count("W", 0,redNum) rightRed = c.count("R", redNum,N) ans += min(leftWhite, rightRed) if leftWhite > rightRed: ans += (leftWhite - rightRed) print(ans)
import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9+7 Max = sys.maxsize def l(): #intのlist return list(map(int,input().split())) def m(): #複数文字 return map(int,input().split()) def onem(): #Nとかの取得 return int(input()) def s(x): #圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x)-1): if aa != x[i+1]: a.append([aa,su]) aa = x[i+1] su = 1 else: su += 1 a.append([aa,su]) return a def jo(x): #listをスペースごとに分ける return " ".join(map(str,x)) def max2(x): #他のときもどうように作成可能 return max(map(max,x)) def In(x,a): #aがリスト(sorted) k = bs.bisect_left(a,x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans """ def nibu(x,n,r): ll = 0 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if (ここに評価入れる): rr = mid else: ll = mid+1 """ n = onem() S = input()[:-1] po = [0 for i in range(n)] for i in range(n-1,-1,-1): if i == n-1: if S[i] == "R": po[i] += 1 else: if S[i] == "R": po[i] += po[i+1]+1 else: po[i] += po[i+1] co = 0 for i in range(n): if po[i] - co > 0 and S[i] != "R": co += 1 print(co)
1
6,318,251,699,658
null
98
98
#A x = input() if x.isupper() ==True: print('A') else: print('a')
print("A") if input().isupper() else print("a")
1
11,320,568,239,980
null
119
119
from collections import Counter from math import gcd N=int(input()) def factorize(x): i=2 ret=[] while i*i<=x: while x%i==0: ret.append(i) x//=i i+=1 if x>1: ret.append(x) return Counter(ret) ans=1 for v in factorize(N-1).values(): ans*=v+1 ans-=1 cnt=1 for v in factorize(gcd(N,N-1)).values(): cnt*=v+1 cnt-=1 ans-=cnt k=2 while k*k<=N: if N%k==0: n=N//k while n%k==0: n//=k if n%k==1: ans+=1 k+=1 ans+=1 print(ans)
len_s = int(input()) s = [int(i) for i in input().split()] len_t = int(input()) t = [int(i) for i in input().split()] cnt = 0 for f in t: i = 0 while i < len(s) and s[i] != f: i += 1 if i < len(s): cnt +=1 print(cnt)
0
null
20,676,119,220,340
183
22
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) h, n = inm() a = sorted(inl(), reverse=True) for i in a: h -= i if h <= 0: break print("Yes" if h <= 0 else "No")
H, N = map(int, input().split()) A = map(int, input().split()) print('Yes' if H <= sum(A) else 'No')
1
77,720,115,200,130
null
226
226
i=0 while True: i=i+1 x=int(input()) if x==0: break print("Case "+str(i)+": "+str(x))
import sys stdin = sys.stdin def ns(): return stdin.readline().rstrip() def ni(): return int(stdin.readline().rstrip()) def nm(): return map(int, stdin.readline().split()) def nl(): return list(map(int, stdin.readline().split())) def main(): n = ni() A = nl() mod = 10 ** 9 + 7 s = sum(A) q = sum([a ** 2 for a in A]) ans = (((s * s) - q)) // 2 print(int(ans % mod)) if __name__ == '__main__': main()
0
null
2,134,217,209,828
42
83
def build_combinations_counter(N=10**5, p=10**9+7): fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # mod p におけるnの逆元 n^(-1) for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) def cmb(n, r, p, fact, factinv): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p import functools return functools.partial(cmb, p=p, fact=fact, factinv=factinv) def resolve(): n, k = list(map(int, input().split())) MOD = 10**9+7 counter = build_combinations_counter(2*10**5, 10**9+7) ans = 0 for i in range(min(n, k+1)): ans += counter(n, i) * counter(n-1, n-i-1) ans %= MOD print(ans) if __name__ == "__main__": resolve()
mod = int(10 ** 9) + 7 def modinv(x, m = mod): b = m u = 1 v = 0 while b: t = x // b x -= t * b x, b = b, x u -= t * v u, v = v, u u %= m if u < 0: u += m return u def main(): n, k = map(int, input().split()) if k > n-1: k = n-1 factorial = [None for _ in range(200001)] factorial[0] = 1 factorial[1] = 1 for i in range(2, 200001): factorial[i] = (factorial[i-1] * i) % mod posCount = [None for _ in range(n+1)] for i in range(n+1): posCount[i] = (factorial[n] * modinv((factorial[i] * factorial[n-i]) % mod)) % mod placeCount = [None for _ in range(n+1)] placeCount[0] = 0 for i in range(1, n+1): placeCount[i] = (factorial[n-1] * modinv((factorial[i-1] * factorial[(n-1)-(i-1)]) % mod)) % mod ans = 0 for i in range(-1, -k-2, -1): ans = (ans + (posCount[i] * placeCount[i])) % mod if k == 1: ans -= 1 if ans < 0: ans += mod print(ans) if __name__ == '__main__': main()
1
66,959,357,085,280
null
215
215
import sys from bisect import bisect_left, bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *L = map(int, read().split()) L.sort() ans = 0 for i in range(N): a = L[i] for j in range(i + 1, N): b = L[j] left = bisect_left(L, b, lo=j + 1) right = bisect_left(L, a + b, lo=j + 1) ans += right - left print(ans) return if __name__ == '__main__': main()
m, n = map(int, input().split()) l = list(map(int, input().split())) for i in range(m-n): if l[i] < l[i+n]: print('Yes') else: print('No')
0
null
89,253,582,045,780
294
102
[w,h,x,y,r] = map(int, input().split()) print("Yes" if r <= x and x <= w - r and r <= y and y <= h - r else "No")
whxyr = input().split() [w, h, x, y, r] = [int(x) for x in whxyr] if 0 <= x - r and x + r <= w and 0 <= y - r and y + r <= h: print("Yes") else: print("No")
1
450,114,780,660
null
41
41
s,w = map(int,input().split()) print("unsafe" if w>=s else "safe")
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# S = str(input()) if S[-1] == 's': print(S+'es') else: print(S+'s')
0
null
15,722,583,500,800
163
71
from sys import stdin input = stdin.readline def solve(): n = int(input()) r = n % 1000 res = 0 if r == 0 else 1000 - r print(res) if __name__ == '__main__': solve()
s = input() rd = 0 max_rd = 0 for i in range(len(s)): if s[i] == 'R': rd += 1 if max_rd < rd: max_rd = rd else: rd = 0 print(max_rd)
0
null
6,671,980,041,150
108
90
import sys import math def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,X,M = MI() if M == 1: print(0) exit() flag = [-1]*M Z = [X] flag[X] = 1 r = X for i in range(2,M+2): r = r ** 2 r %= M if flag[r] != -1: a,b = flag[r],i # [a,b) = 循環節 break else: flag[r] = i Z.append(r) z = len(Z) ans = 0 for i in range(a-1): ans += Z[i] n = N-a+1 q = n//(b-a) r = n % (b-a) for i in range(a-1,a+r-1): ans += (q+1)*Z[i] for i in range(a+r-1,b-1): ans += q*Z[i] print(ans)
from collections import defaultdict import sys def input():return sys.stdin.readline().strip() def main(): N, P = map(int, input().split()) S = input() ans = 0 if P in [2, 5]: for i, c in enumerate(S[::-1]): if int(c) % P == 0: ans += N-i else: d = defaultdict(int) d[0] = 1 num = 0 ten = 1 for c in S[::-1]: num += int(c) * ten num %= P d[num] += 1 ten *= 10 ten %= P ans = sum([d[i]*(d[i]-1)//2 for i in range(P)]) print(ans) if __name__ == "__main__": main()
0
null
30,578,284,877,808
75
205
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) n, m = map(int, input().split()) graph = [0] + [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) from collections import deque def bfs(graph, queue, dist, prev): while queue: current = queue.popleft() for _next in graph[current]: if dist[_next] != -1: continue else: dist[_next] = dist[current] + 1 prev[_next] = current queue.append(_next) queue = deque([1]) dist = [0] + [-1] * n prev = [0] + [-1] * n dist[1] = 0 bfs(graph, queue, dist, prev) if -1 in dist: print('No') else: print('Yes') for v in prev[2:]: print(v)
from collections import defaultdict, deque n, m=map(int, input().split()) deq=deque() dic=defaultdict(list) for i in range(m): a, b = map(int, input().split()) dic[a].append(b) dic[b].append(a) sign=[-1]*(n+1) sign[1]=0 for i in dic[1]: deq.append(i) sign[i]=1 while deq: p = deq.popleft() for i in dic[p]: if sign[i]!=-1: continue else: sign[i]=p deq.append(i) bl = True for i in range(2, n+1): if sign[i]<0: bl = False if bl: print("Yes") for i in range(2, n+1): print(sign[i]) else: print("No")
1
20,449,408,637,560
null
145
145