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
p = int(input()) while True: q = int(p**0.5) for i in range(2, q+1): if p%i == 0: p += 1 break else: print(p) break
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 ** 19 MOD = 998244353 N, K = MAP() A = LIST() dp = list2d(N+1, K+1, 0) dp[0][0] = 1 for i, a in enumerate(A): for j in range(K+1): dp[i+1][j] += dp[i][j] * 2 dp[i+1][j] %= MOD if j+a <= K: dp[i+1][j+a] += dp[i][j] dp[i+1][j+a] %= MOD ans = dp[N][K] print(ans)
0
null
61,766,578,690,740
250
138
from collections import deque [N,M] = list(map(int,input().split())) AB = [] for i in range(M): AB.append(list(map(int,input().split()))) #そこから直で行けるところをまとめる ikeru = [[] for i in range(N)] for i in range(M): ikeru[AB[i][0]-1].append(AB[i][1]-1) ikeru[AB[i][1]-1].append(AB[i][0]-1) # print('ikeru:',ikeru) que = deque([]) que.append(0) # print('que ini:',que) out=[10**6]*N out[0]=0 while que: p = que.popleft() # print('p,que:',p,que) for next in ikeru[p]: # print('next,out:',next,out) if out[next]==10**6: que.append(next) out[next]=p+1 # print(out) print('Yes') for i in range(1,N): print(out[i])
class card: def __init__(self,cv): c = cv[0:1] v = int(cv[1:2]) self.c = c self.v = v def self_str(self): q = str(str(self.c) + str(self.v)) return q n = int(input()) a = list(map(card, input().split())) b = a[:] c = a[:] for i in range(n): for j in range(n-1, i, -1): if b[j].v < b[j-1].v: b[j], b[j-1] = b[j-1],b[j] print(" ".join(x.self_str() for x in b)) coua = ["" for i in range(10)] coub = ["" for i in range(10)] conb = "" for i in range(n): for j in range(n): if i != j: if a[i].v == a[j].v: coua[a[i].v] += a[i].c if b[i].v == b[j].v: coub[b[i].v] += b[i].c if coua == coub: conb = "Stable" else: conb = "Not stable" print(conb) for i in range(n): mini = i for j in range(i, n): if c[j].v < c[mini].v: mini = j c[mini], c[i] = c[i], c[mini] print(" ".join(x.self_str() for x in c)) couc = ["" for i in range(10)] conc = "" for i in range(n): for j in range(n): if i != j: if c[i].v == c[j].v: couc[c[i].v] += c[i].c if coua == couc: conc = "Stable" else: conc = "Not stable" print(conc)
0
null
10,203,084,993,632
145
16
n, m, l = map(int, input().split()) a = [] b = [] ans = [[0 for _ in range(l)] for _ in range(n)] for _ in range(n): a.append(list(map(int, input().split()))) for _ in range(m): b.append(list(map(int, input().split()))) for i in range(n): for j in range(l): for k in range(m): ans[i][j] = ans[i][j] + a[i][k] * b[k][j] for ans_row in ans: print(*ans_row)
n = int(input()) s = 0 a = 1 b = 1 while a*b < n: while a*b < n and b <= a: if a == b: s += 1 else: s += 2 b += 1 a += 1 b = 1 print(s)
0
null
2,036,965,460,420
60
73
N=input() A=list(map(int,input().split())) m=1000 tmp = A[0] stock=0 for i,ai in enumerate(A): if tmp>=ai: m+=tmp*stock stock=0 if ai < max(A[i:]): stock=m//ai m-=ai*stock tmp = ai print(m+stock*A[-1])
import sys from itertools import combinations_with_replacement input = sys.stdin.readline def main(): N, M, Q = map(int, input().split()) abcd = [None] * Q for i in range(Q): abcd[i] = list(map(int, input().split())) abcd[i][0] -= 1 abcd[i][1] -= 1 ans = 0 for A in combinations_with_replacement(range(1, M + 1), N): score = 0 for a, b, c, d in abcd: if A[b] - A[a] == c: score += d if score > ans: ans = score print(ans) if __name__ == "__main__": main()
0
null
17,606,233,774,570
103
160
n = int(input()) lx = list(map(int,input().split())) lc=[] for i in range(1,101): c = 0 for x in lx: c += (i-x)**2 lc.append(c) print(min(lc))
#!/usr/bin/env python3 # from numba import njit # from collections import Counter # from itertools import accumulate # import numpy as np # from heapq import heappop,heappush # from bisect import bisect_left INF = pow(10,6) # @njit def solve(n,a): res = INF for i in range(1,101): res = min(res,sum(pow(i-x,2) for x in a)) return res def main(): N = int(input()) # N,M = map(int,input().split()) a = list(map(int,input().split())) print(solve(N,a)) return if __name__ == '__main__': main()
1
65,030,570,566,460
null
213
213
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) def inp():return stdin.readline() def out(x):return stdout.write(x) import math import random J=10**19 ###############################################################################\n=17 d,t,s=INPUT() if d/s<=t: print("Yes") else: print("No")
def resolve(): num = list(map(int, input().split())) time = num[0] / num[2] if time <= num[1]: print("Yes") else: print("No") resolve()
1
3,567,385,718,820
null
81
81
N, K = map(int,input().split()) P = list(map(int,input().split())) C = list(map(int,input().split())) S = [] R = -1000000001 #それぞれについての累積和の計算 for i in range(N):#このループはN個の初期マスの時のループ t = i # tは現在の位置 cnt = 0 # 累積和 sum = [] # 累積和のリスト res = 0 while True:#このループは一つの初期マスの累積和。最初のコマに戻るまで t = P[t]-1 cnt += C[t] sum.append(cnt) if t == i: break #S.append(sum) if len(sum) >= K: res = max(sum[:K]) else: if sum[-1] <= 0: res = max(sum) else: score1 = sum[-1] * (K // len(sum) - 1) + max(sum) score2 = sum[-1] * (K // len(sum)) r = K % len(sum) if r != 0: score2 += max(0, max(sum[:r])) res = max(score1,score2) R = max(R,res) print(R)
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 ans = collections.deque(ns()) q = ni() now = 0 for i in range(q): query = ns().split(' ') if query[0] == '1': now = 1 - now else: f, c = query[1], query[2] if f == '1': if now == 1: ans.append(c) else: ans.appendleft(c) else: if now != 1: ans.append(c) else: ans.appendleft(c) if now == 1: for i in range(len(ans)): print(ans[-(i+1)], end="") else: for i in range(len(ans)): print(ans[i], end="") print()
0
null
31,171,106,029,770
93
204
n=int(input()) E=[0]*n for _ in range(n): u,k,*V=map(int,input().split()) E[u-1]=sorted(V)[::-1] todo=[1] seen=[0]*n d=[0]*n f=[0]*n t=0 while 0 in f: if not todo: todo.append(seen.index(0)+1) if seen[todo[-1]-1]==0: seen[todo[-1]-1]=1 t+=1 d[todo[-1]-1]=t for v in E[todo[-1]-1]: if d[v-1]==0: todo.append(v) elif f[todo[-1]-1]==0: t+=1 f[todo.pop()-1]=t else: todo.pop() for i in range(n): print(i+1,d[i],f[i])
N = input() color = [0] * N d = [0] * N f = [0] * N nt = [0] * N m = [[0] * N for i in range(N)] S = [] tt = 0 def next(u): global nt w = nt[u] for v in range(w, N): nt[u] = v + 1 if( m[u][v] ): return v return -1 def dfs_visit(r): global tt S.append(r) color[r] = 1 tt += 1 d[r] = tt while( len(S) != 0 ): u = S[-1] v = next(u) if ( v != -1 ): if ( color[v] == 0 ): color[v] = 1 tt += 1 d[v] = tt S.append(v) else: S.pop() color[u] = 2 tt += 1 f[u] = tt def dfs(): global color for u in range(N): if( color[u] == 0 ): dfs_visit(u) if __name__ == '__main__': for i in range(N): v = map(int, raw_input().split()) for j in v[2:]: m[i][j-1] = 1 dfs() for i in range(N): print (i+1), d[i], f[i]
1
2,827,368,192
null
8
8
ass, bss, css = input().split(" ") a = int(ass) b = int(bss) c = int(css) if a < b: if b < c: print(a,b,c) else: if a < c: print(a,c,b) else: print(c,a,b) else: if a < c: print(b,a,c) else: if b < c: print(b,c,a) else: print(c,b,a)
def main(): n = int(input()) s = input() ans = 0 for i in range(n-2): if s[i]+s[i+1]+s[i+2] == "ABC": ans += 1 print(ans) main()
0
null
49,910,080,057,892
40
245
t = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [t[0]*a[0],t[1]*a[1]] d = [t[0]*b[0],t[1]*b[1]] if sum(c)==sum(d): print('infinity') exit() elif c[0]==d[0]: print('infinity') exit() if sum(d)>sum(c) and d[0]>c[0]: print(0) exit() elif sum(c)>sum(d) and c[0]>d[0]: print(0) exit() else: n = (c[0]-d[0])/(sum(d)-sum(c)) if n==int(n): print(2*int(n)) else: print(2*int(n)+1)
t1,t2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) hosei = 0 if t1*c1>t1*d1: a1=c1 a2=c2 b1=d1 b2=d2 else: a1,a2,b1,b2=d1,d2,c1,c2 if t1*a1+t2*a2 > t1*b1+t2*b2: print(0) exit() elif t1*a1+t2*a2 == t1*b1+t2*b2: print("infinity") else: # print((t1*(a1-b1))//(t2*(b2-a2)) + 1,t1*(a1-b1),t2*(b2-a2)) if t2*(b2-a2) % (t2*(b2-a2)-t1*(a1-b1)) == 0: hosei = 1 print((t2*(b2-a2)) // (t2*(b2-a2)-t1*(a1-b1))*2-1-hosei) # print((t2*(a2-b2)))
1
131,629,077,166,862
null
269
269
N, K, C = list(map(int,input().split())) s = list(str(input())) L = [] # i+1日目に働くのはL[i]日目以降 R = [] # i+1日目に働くのはL[i]日目以前 for i in range(N): if len(L) >= K: break if s[i] == 'o' and (L == [] or (i + 1) - L[-1] > C): # 出勤可能('o') 且 (Lが空又はi日目時点の最終出勤からc日経過) # ならばLにi+1を追加 L.append(i + 1) for i in range(N - 1, -1, -1): if len(R) >= K: break if s[i] == 'o' and (R == [] or R[-1] - (i + 1) > C): R.append(i + 1) R.reverse() ans = [] for i in range(K): if L[i] == R[i]: print(L[i])
N,K,C=map(int, input().split()) S=input() L=[0]*N R=[0]*N c=1 last=-C-1 for i in range(N): if i-last>C and S[i]!='x' and c<=K: L[i]=c c+=1 last=i c=K last=N+C for i in range(N-1,-1,-1): if last-i>C and S[i]!='x' and c>=1: R[i]=c c-=1 last=i for i in range(N): if 0<L[i]==R[i]: print(i+1)
1
40,434,082,773,632
null
182
182
line = input() for ch in line: n = ord(ch) if ord('a') <= n <= ord('z'): n -= 32 elif ord('A') <= n <= ord('Z'): n += 32 print(chr(n), end='') print()
import itertools lst = list(map(int, input().split())) k = int(input()) ans = 'No' for tup in itertools.combinations_with_replacement([0, 1, 2], k): temp = lst[:] for i in tup: temp[i] *= 2 if temp[0] < temp[1] and temp[1] < temp[2]: ans = 'Yes' print(ans)
0
null
4,168,381,872,468
61
101
import numpy as np n,s = map(int,input().split()) a = list(map(int,input().split())) dp = np.zeros(s+1, dtype=np.int64) """ dp[i][j] := i番目までを選んで、和がちょうどjのときの場合の数 遷移 → 1増えると全体集合に選ぶ, Aには選ばない, Aに選ぶの3種類. """ mod = 998244353 dp[0] = 1 for i in range(n): p = (dp * 2) % mod p[a[i]:] += dp[:-a[i]] dp = p % mod print(dp[s])
import numpy as np mod = 998244353 n, s = map(int, input().split()) A = list(map(int, input().split())) DP = np.zeros(3005, dtype=np.int64) for num, a in enumerate(A): double = DP * 2 shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64) DP = double + shift DP[a] += pow(2, num, mod) DP %= mod print(DP[s])
1
17,680,485,727,618
null
138
138
from itertools import accumulate n = int(input()) a = list(map(int, input().split())) a_acc = list(accumulate(a)) ans = 2020202020 for i in range(n): ans = min(abs(a_acc[-1] - a_acc[i] - a_acc[i]), ans) print(ans)
N, K = [int(x) for x in input().split()] P = [0] + [int(x) for x in input().split()] C = [0] + [int(x) for x in input().split()] max_score = max(C[1:]) for init in range(1, N + 1): # 初めの場所をinitとする score = [0] # k回移動後のスコア i = init for k in range(1, K + 1): i = P[i] # k回移動後に着くところ score.append(score[-1] + C[i]) max_score = max(max_score, score[k]) if i == init: # ループ検出 loop_score = score[-1] loop_len = k if loop_score < 0: max_score = max(max_score, max(score[1:])) else: max_score = max(max_score, max(score[j] + loop_score * ((K - j) // loop_len) for j in range(1, loop_len + 1))) break print(max_score)
0
null
73,843,859,494,392
276
93
n=int(input()) A=set() for i in range(n): x,y=input().split() if x == 'insert': A.add(y) else: print('yes'*(y in A)or'no')
N, K = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(K)] mod = 998244353 dp = [0] * N dp[0] = 1 now = 0 for i in range(1, N): for l, r in LR: if i - l >= 0: now += dp[i - l] now %= mod if i - r - 1 >= 0: now -= dp[i - r - 1] now %= mod dp[i] = now #print(dp) print(dp[-1])
0
null
1,388,050,998,562
23
74
from collections import defaultdict N=int(input()) *A,=map(int,input().split()) mod = 10**9+7 count = defaultdict(int) count[0] = 3 ans = 1 for i in range(N): ans *= count[A[i]] ans %= mod count[A[i]] -= 1 count[A[i]+1] += 1 print(ans)
import sys # sys.setrecursionlimit(100000) def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return [int(i) for i in input().split()] def main(): n = input_int() A = input_int_list() MOD = 10**9 + 7 cnt = 1 x, y, z = 0, 0, 0 for a in A: tmp = 0 is_used = False # x,y,zのどこかに配った。 if a == x: tmp += 1 if not is_used: x += 1 is_used = True if a == y: tmp += 1 if not is_used: y += 1 is_used = True if a == z: tmp += 1 if not is_used: z += 1 is_used = True cnt *= tmp cnt = cnt % MOD print(cnt) return if __name__ == "__main__": main()
1
130,279,360,602,720
null
268
268
import random class Dice: def __init__(self, labels): self.labels = labels def north(self): self.change([2, 6, 3, 4, 1, 5]) def south(self): self.change([5, 1, 3, 4, 6, 2]) def east(self): self.change([4, 2, 1, 6, 5, 3]) def west(self): self.change([3, 2, 6, 1, 5, 4]) def change(self, convert): result = [] for i in range(6): result.append(self.labels[convert[i] - 1]) self.labels = result dice = Dice(list(map(int, input().split()))) for i in range(int(input())): up, front = map(int, input().split()) while(True): direction = random.randint(0, 3) if direction == 0: dice.north() if direction == 1: dice.south() if direction == 2: dice.east() if direction == 3: dice.west() if dice.labels[0] == up and dice.labels[1] == front: print(dice.labels[2]) break
class Dice: def __init__(self): self.dice=[1,2,3,4,5,6] # up,front,right,left,back,front def set(self,l): self.dice=l def roll(self, s): import copy mat=((1,4,3,2),(5,0,1,1),(2,2,0,5),(3,3,5,0),(0,5,4,4),(4,1,2,3)) l=copy.deepcopy(self.dice) if s == 'N': c = 0 if s == 'S': c = 1 if s == 'E': c = 2 if s == 'W': c = 3 for i in range(6): self.dice[i]=l[mat[i][c]] def get(self): return self.dice import random d=Dice() d.set(list(map(int,input().split()))) for i in range(int(input())): u,f=map(int,input().split()) while True: d.roll('NSEW'[random.randrange(4)]) if d.get()[0]==u and d.get()[1]==f: print(d.get()[2]) break
1
257,576,350,900
null
34
34
A = [list(map(int, input().split())) for i in range(3)] N = int(input()) for k in range(N): B = int(input()) for l in range(3): for m in range(3): if A[l][m] == B: A[l][m] = 0 if (A[0][0] == A[0][1] == A[0][2] == 0) or (A[1][0] == A[1][1] == A[1][2] == 0) or (A[2][0] == A[2][1] == A[2][2] == 0): print ("Yes") elif (A[0][0] == A[1][0] == A[2][0] == 0) or (A[0][1] == A[1][1] == A[2][1] == 0) or (A[0][2] == A[1][2] == A[2][2] == 0): print ("Yes") elif (A[0][0] == A[1][1] == A[2][2] == 0) or (A[0][2] == A[1][1] == A[2][0] == 0): print ("Yes") else: print ("No")
A=[list(map(int,input().split())) for i in range(3)] n=int(input()) b=[int(input()) for i in range(n)] for i in range(3): for j in range(3): for k in range(n): if A[i][j]==b[k]: A[i][j]=-1 if A[0][0]==-1 and A[1][1]==-1 and A[2][2]==-1: print("Yes") exit() elif A[0][2]==-1 and A[1][1]==-1 and A[2][0]==-1: print("Yes") exit() for i in range(3): total=0 if A[i].count(-1)==3: print("Yes") exit() for j in range(3): if A[j][i]==-1: total+=1 if total==3: print("Yes") exit() print("No")
1
59,784,205,586,820
null
207
207
A, V = map(int,input().split()) B, W = map(int,input().split()) T = int(input()) if (V <= W): print("NO") elif(T < abs(A - B)/(V-W)): print("NO") else: print("YES")
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if V == W: print("NO") exit() if A > B: t1 = A A = B B = t1 if V < W: # print("A") print("NO") exit() if (A + V*T) - (B + W*T) >= 0: print("YES") exit() else: print("NO") exit()
1
15,163,107,230,290
null
131
131
def solve(string): x, k, d = map(int, string.split()) if k % 2: x = min(x - d, x + d, key=abs) k -= 1 x, k, d = abs(x), k // 2, d * 2 return str(min(x % d, abs((x % d) - d))) if x < k * d else str(x - k * d) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
import math X,K,D = map(int,input().split()) X = abs(X) if X > K*D: print(X-K*D) else: c=math.floor(X/D) print( abs(X-D*c-((K-c)%2)*D) )
1
5,221,372,974,658
null
92
92
s=raw_input() t=[] for x in s: if x=='?': t.append('D') else: t.append(x) print "".join(t)
import bisect def binary_search(items, a, b, i, j): def c_is_x(c): is1 = c > max(a - b, b - a) is2 = c < a + b if is1 and is2: return 0 elif is1: return 1 else: return 2 low = j+1 high = len(items) - 1 while low <= high: mid = (low + high) // 2 ans = items[mid] c_type = c_is_x(ans) if c_type == 0 and mid != i and mid != j: return mid elif c_type == 1: low = mid + 1 else: high = mid - 1 return None N = int(input()) L = list(map(int, input().split())) L.sort() # print(L) count = 0 for i in range(N): for j in range(i+1, N): # i = N - i - 1 # j = N - j - 1 a = L[i] b = L[j] k = bisect.bisect_left(L, a+b, lo=j) - 1 if k < N: c = L[k] # print(a, b, c, a+b) # print(i, j, k) count += max(k - j, 0) print(count)
0
null
95,132,663,436,508
140
294
N = int(input()) def is_prime(x): if x<=1:return False for i in range(2,x): if x%i==0 : return False return True while not is_prime(N):N+=1 print(N)
def readinput(): n=int(input()) return n def main(n): if n==2: return 2 nmax=2*10**5 isprime=[1]*(nmax) isprime[0]=0 isprime[1]=0 m=4 while(m<nmax): isprime[m]=0 m+=2 for i in range(3,nmax,2): if isprime[i]==0: continue else: if i>=n: return i m=2*i while(m<nmax): isprime[m]=0 m+=i return -1 if __name__=='__main__': n=readinput() ans=main(n) print(ans)
1
105,469,455,675,000
null
250
250
N=int(input()) for i in range(1,10): for j in range(1,10): if i*j==N: print("Yes") break else: continue break else: print("No")
def main(): N = int(input()) ctr = [[0] * 10 for _ in range(10)] for x in range(1, N + 1): s = str(x) ctr[int(s[0])][int(s[-1])] += 1 ans = 0 for i in range(10): for j in range(10): ans += ctr[i][j] * ctr[j][i] print(ans) if __name__ == '__main__': main()
0
null
123,593,909,649,340
287
234
N=int(input()) A=map(int, input().split()) P=1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(N + 1)] for a in A: ans=ans*cnt[a]%P if ans==0: break cnt[a]-=1 cnt[a+1]+=1 print(ans)
import sys import math def gcd(x, y): if y == 0: return x return gcd(y, x%y) x, y = map(int, raw_input().split()) print gcd(min(x, y), max(x, y))
0
null
64,969,106,984,202
268
11
N, K = map(int, input().split()) h = list(map(int, input().split())) cn = 0 for i in range(N): if h[i] >= K: cn = cn + 1 print(cn)
S=input() T=input() yes=True l=len(S) for i in range(0,l): if S[i]!=T[i]: yes=False break if yes: print("Yes") else: print("No")
0
null
100,384,620,851,410
298
147
s = [] for t in input().split(): try: v = int(t) except ValueError: a = s.pop() b = s.pop() if t == '+': v = b + a elif t == '-': v = b - a elif t == '*': v = b * a s.append(v) print(s.pop())
# A - A?C # 'ABC'には'ARC'を、'ARC'には'ABC'を返す S = str(input()) if S == 'ABC': print('ARC') elif S == 'ARC': print('ABC')
0
null
12,005,001,679,242
18
153
S=input() print("{}{}{}".format(S[0],'B' if S[1]!='B' else 'R',S[-1]))
S = input() if S.upper() == "ABC": print("ARC") else: print("ABC")
1
24,280,175,137,188
null
153
153
n = int(input()) A = list(map(int,input().split())) val1 = sum(A)//n val2 = val1+1 ans1 = 0 ans2 = 0 for a in A: ans1 += (a-val1)**2 ans2 += (a-val2)**2 print(min(ans1,ans2))
N=int(input()) X=list(map(int, input().split())) power_min = 1e8 for P in range(1,101): power = 0 for i in range(N): power += (X[i]-P)**2 if power < power_min: power_min = power print(power_min)
1
65,336,667,847,810
null
213
213
import math a, b, n = list(map(int, input().split())) x = min(n, b - 1) ans = math.floor((a * x) / b) - a * math.floor(x / b) print(ans)
from math import floor A, B, N = map(int, input().split()) i = min(B - 1, N) f_i = floor(A * i / B) - A * floor(i / B) print(f_i)
1
27,911,506,149,280
null
161
161
s=1 while True: i=input() if i=='0': break print('Case '+str(s)+':', i) s+=1
list = [] x = 1 while x > 0: x = input() if x > 0: list.append(x) for i,j in enumerate(list): print "Case " + str(i+1) + ": " + str(j)
1
487,579,824,292
null
42
42
from math import floor X = int(input()) deposit, year = 100, 0 while deposit < X: deposit += deposit // 100 year += 1 print(year)
X = int(input()) s = 100 c = 0 while s < X: s = s + s // 100 c = c + 1 print(c)
1
27,107,785,403,490
null
159
159
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): r = int(input()) print(r**2) if __name__ == '__main__': main()
# coding: utf-8 # Your code here! import sys n=int(input()) s=list(input()) if n%2==1: print("No") sys.exit() else: for i in range(n//2): if s[i]==s[n//2+i]: continue print("No") sys.exit() print("Yes")
0
null
146,079,042,955,272
278
279
N, M = map(int, input().split()) A = map(int, input().split()) A_sum = sum(A) if (N - A_sum) >= 0: print(N - A_sum) else: print(-1)
N,M=map(int,input().split()) A=input() List_A=A.split() day=0 for i in range(0,M): day=day+int(List_A[i]) if N>=day: print(N-day) else: print(-1)
1
32,017,796,537,532
null
168
168
import itertools import math n = int(input()) xy = [list(map(int,input().split())) for i in range(n)] q = list(itertools.permutations(range(n))) m = len(q) k_sum = 0 for i in range(m): for j in range(n-1): a = xy[q[i][j]][0] - xy[q[i][j+1]][0] x = a**2 b = xy[q[i][j]][1] - xy[q[i][j+1]][1] y = b**2 k_sum += math.sqrt(x+y) print(k_sum/m)
import math import itertools n = int(input()) data = [] for i in range(n): x, y = map(int,input().split()) data.append((x, y)) cnt = 0 for a in itertools.permutations(range(n)): for j in range(n-1): cnt += ((data[a[j+1]][0]-data[a[j]][0])**2 + (data[a[j+1]][1]-data[a[j]][1])**2)**0.5 print(cnt / math.factorial(n))
1
148,822,837,056,658
null
280
280
import sys s = input() k = int(input()) n = len(s) if n==1: print(k//2) sys.exit() if n==2: print(k if s[0]==s[1] else 0) sys.exit() i = 1 change = [0, 0] same = True while i<n: if s[i-1]==s[i]: if i==n-1: same = False change[0] += 1 i += 1 i += 1 if s[0]!=s[-1]: same = False if not same: print(change[0]*k) sys.exit() i = 2 change[1] = 1 same = True while i<n: if s[i-1]==s[i]: if i==n-1: same = False change[1] += 1 i += 1 i += 1 if same: print(change[0]+change[1]*(k-1)) else: print(change[0]*((k+1)//2)+change[1]*(k//2))
n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) mod = 10**9+7 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, 10**5+5 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans = 0 for i in range(0, n-k+1): ans += a[i]*cmb(n-i-1, k-1, mod) ans %= mod a.sort() for i in range(0, n-k+1): ans -= a[i]*cmb(n-i-1, k-1, mod) ans %= mod print(ans)
0
null
135,212,808,193,920
296
242
def main(): k = int(input()) s = str(input()) output = '' if len(s) > k: for i in range(k): output += s[i] output += '...' else: output = s print(output) if __name__ == '__main__': main()
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, M, S): ans = [] i = N while i > 0: for j in range(max(0, i - M), i): if S[j] == '0': ans.append(i - j) i = j break else: print(-1) return print(*list(reversed(ans))) if __name__ == '__main__': input = sys.stdin.readline N, M = map(int, input().split()) S = input().rstrip() main(N, M, S)
0
null
79,187,206,240,810
143
274
while True: c=0 x, y = map(int, input().split()) if x == 0 and y== 0: break for i in range(1, x+1): for j in range(i+1, x+1): for k in range(j+1, x+1): if i+j+k == y: c += 1 print (c)
N = list(input()) if "7" in N: print("Yes") else: print("No")
0
null
17,785,960,747,930
58
172
import math c = math.cos(math.radians(60)) s = math.sin(math.radians(60)) def koch(d,p1,p2): if d == 0: return sx = (2 * p1[0] + p2[0]) / 3 sy = (2 * p1[1] + p2[1]) / 3 tx = (p1[0] + p2[0] * 2) / 3 ty = (p1[1] + p2[1] * 2) / 3 dx = tx - sx dy = ty - sy ux = dx * c - dy * s + sx uy = dx * s + dy * c + sy koch(d-1,p1,(sx,sy)) print("{0:.8f} {1:.8f}".format(sx,sy)) koch(d-1,(sx,sy),(ux,uy)) print("{0:.8f} {1:.8f}".format(ux,uy)) koch(d-1,(ux,uy),(tx,ty)) print("{0:.8f} {1:.8f}".format(tx,ty)) koch(d-1,(tx,ty),p2) n = int(input()) print("{0:.8f} {1:.8f}".format(0,0)) koch(n,(0,0),(100,0)) print("{0:.8f} {1:.8f}".format(100,0))
import math def koch(n, ax, ay, bx, by): if n == 0: return ; sin = math.sin(math.radians(60)) cos = math.cos(math.radians(60)) sx = (2.0 * ax + 1.0 * bx) / 3.0 sy = (2.0 * ay + 1.0 * by) / 3.0 tx = (1.0 * ax + 2.0 * bx) / 3.0 ty = (1.0 * ay + 2.0 * by) / 3.0 ux = (tx - sx) * cos - (ty - sy) * sin + sx uy = (tx - sx) * sin + (ty - sy) * cos + sy koch(n-1, ax, ay, sx, sy) print(str(sx)+ " " + str(sy)) koch(n-1, sx, sy, ux, uy) print(str(ux)+ " " + str(uy)) koch(n-1, ux, uy, tx, ty) print(str(tx)+ " " + str(ty)) koch(n-1, tx, ty, bx, by) if __name__ == '__main__': n = int(input()) ax = 0.00000000 ay = 0.00000000 bx = 100.00000000 by = 0.00000000 print(str(ax) + " " + str(ay)) koch(n, ax, ay, bx, by) print(str(bx)+ " " + str(by))
1
125,735,857,742
null
27
27
MOD = 10 ** 9 + 7 n, k = map(int, input().split()) ans = 0 for x in range(k, n + 2): p = x * (x - 1) // 2 q = x * (x - 1) // 2 + (n - x + 1) * x ans += q - p + 1 print(ans % MOD)
N, K = list(map(int, input().split())) ans = 0 all_sum = N*(N+1)/2 mod = 10**9+7 for i in range(K,N+2): min_val = i*(i-1)/2 max_val = N*(N+1)/2 - (N-i+1)*(N-i)/2 ans += (int(max_val) - int(min_val) + 1) % mod # print(i, min_val, max_val) print(ans%mod)
1
33,028,568,722,332
null
170
170
s = input() t = input() i = 0 for key, val in enumerate(s): if (val != t[key]): i+=1 print(i)
a=list(input()) ans=0 for i in range(len(a)): ans+=int(a[i]) if ans%9==0: print("Yes") else: print("No")
0
null
7,458,027,852,308
116
87
def main(listseq): x = y = 0 for strings in listseq: a, b = strings.split(" ") if a < b: y += 3 elif a > b: x += 3 elif a == b: x += 1; y += 1 return x, y times = int(input()) words = [input() for _ in range(times)] a, b = main(words) print(f"{a} {b}")
def solve(): n, m = map(int, input().split()) print('YNeos'[n!=m::2]) if __name__ == '__main__': solve()
0
null
42,623,325,562,970
67
231
def solve(): N, K = map(int, input().split()) mod = 10**9+7 ans = 0 for k in range(K,N+2): ans += (N+N-k+1)*k//2-k*(k-1)//2+1 ans %= mod return ans print(solve())
N, K = map(int, input().split()) A = [0]*(N+2) for i in range(N+1): A[i+1] += A[i] + i ans = 0 for i in range(K, N+2): minv = A[i] maxv = A[N+1]-A[N-i+1] ans += maxv-minv+1 ans %= 10**9+7 print(ans)
1
33,141,585,880,712
null
170
170
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline from numba import njit def getInputs(): D = int(readline()) CS = np.array(read().split(), np.int32) C = CS[:26] S = CS[26:].reshape((-1, 26)) return D, C, S @njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True) def _compute_score1(D, C, S, out): score = 0 last = np.zeros(26, np.int32) for d in range(len(out)): i = out[d] score += S[d, i] last[i] = d + 1 score -= np.sum(C * (d + 1 - last)) return last, score def step1(D, C, S): #out = np.zeros(D, np.int32) out = [] LAST = 0 for d in range(D): max_score = -10000000 best_i = 0 for i in range(26): #out[d] = i out.append(i) last, score = _compute_score1(D, C, S, np.array(out, np.int32)) if max_score < score: max_score = score LAST = last best_i = i out.pop() #out[d] = best_i out.append(best_i) return np.array(out), LAST, max_score def output(out): out += 1 print('\n'.join(out.astype(str).tolist())) D, C, S = getInputs() out, _, score = step1(D, C, S) output(out)
print(int(input()=="0"))
0
null
6,236,507,059,008
113
76
while True: n,x = map(int,input().split(" ")) if n == 0 and x == 0: break #データリスト作成 data = [m for m in range(1,n+1)] data_list = [] cnt = 0 #n種類の数字があって、xになる組み合わせは? for i in range(1,n+1): for j in range(1+i,n+1): for k in range(1+j,n+1): if i+j+k == x: cnt += 1 print(cnt)
rs = [(x - l, x + l) for x, l in (map(int, input().split()) for _ in range(int(input())))] rs.sort(key=lambda x: x[1]) last = - 10 ** 9 ans = 0 for l, r in rs: if last <= l: ans += 1 last = r print(ans)
0
null
45,403,236,683,406
58
237
N = int(input()) a = list(map(int, input().split())) S = 0 for aa in a: S ^= aa ans = "" for ai in a: ans += f'{str(S ^ ai)} ' print(ans.rstrip())
import numpy as np from numba import njit @njit('i8(i8)', cache=True) def solve(x): count = np.zeros(x + 1, dtype=np.int64) for i in range(1, x + 1): for j in range(i, x + 1, i): count[j] += j return count.sum() if __name__ == "__main__": x = int(input()) print(solve(x))
0
null
11,725,207,184,912
123
118
n=int(input()) p=round(n**0.5)+1 ans=[0]*n for x in range(1,p): for y in range(1,p): for z in range(1,p): k=x**2+y**2+z**2+x*y+y*z+z*x k-=1 if 0<=k<=n-1: ans[k]+=1 for i in ans: print(i)
import numpy as np from itertools import permutations N = int(input()) counter = np.zeros(N, dtype=int) for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): res = x**2 + y**2 + z**2 + x * y + x * z + y * z if res <= N: counter[res - 1] += 1 for c in counter: print(c)
1
8,032,596,109,752
null
106
106
#!/usr/bin/env python3 def next_line(): return input() def next_int(): return int(input()) def int_ar(): return list(map(int, input().split())) def strs(): return input().split() def ints(): return map(int, input().split()) def int_ar_mul(size): return [int(input()) for _ in range(size)] def str_ar(size): return [input() for _ in range(size)] def main(): n, k = ints() p = sorted(int_ar()) res = 0 for i in range(k): res += p[i] print(res) if __name__ == '__main__': main()
#!usr/bin/env pypy3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate, combinations_with_replacement, compress import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) def main(): N, M, Q = LI() abcd = [LI() for _ in range(Q)] ans = 0 for A in combinations_with_replacement(range(1, M + 1), N): tmp = 0 for (a, b, c, d) in abcd: tmp += d if (A[b-1] - A[a-1] == c) else 0 ans = max(ans, tmp) print(ans) main()
0
null
19,573,083,731,388
120
160
import sys BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 buf = str(input()) print(buf.swapcase())
a=input() b=a.swapcase() print(b)
1
1,510,624,681,412
null
61
61
from math import gcd from functools import reduce def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def evencount(n): cnt=0 while n%2==0: cnt+=1 n//=2 return cnt n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]//=2 if all(evencount(i) == evencount(a[0]) for i in a): d=lcm(*a) print((m+d)//2//d) else:print(0)
from functools import reduce def gcd_base(x, y): if x % y: return gcd_base(y, x%y) return y def gcd(numbers): return reduce(gcd_base, numbers) def lcm_base(x, y): res = (x * y) // gcd_base(x, y) return res if res <= 1000000007 else 0 def lcm(numbers): return reduce(lcm_base, numbers, 1) n, m = map(int, input().split()) a = [int(i) for i in input().split()] k = [0] * n for i in range(n): j = a[i] while(j%2==0): j //= 2 k[i] += 1 if any([k[i]!=k[i+1] for i in range(n-1)]): print(0) else: l = [i//2 for i in a] x = lcm(l) if x==0: print(0) else: print((m//x+1)//2)
1
101,660,213,696,732
null
247
247
import itertools n = int(input()) d = list(map(int, input().split())) lst = list(itertools.combinations(d, 2)) ans = 0 for i in lst: a = i[0] * i[1] ans += a print(ans)
from itertools import combinations import numpy as np N = int(input()) D = list(map(int, input().split())) List = np.array(list(combinations(D,2))) print(sum(np.product(List, axis = 1)))
1
167,601,094,811,248
null
292
292
a, b = input().split() s1 = a*int(b) s2 = b*int(a) print(s1 if s1 < s2 else s2)
a,b = map(int,input().split()) n = min(a,b) m = max(a,b) ans = '' for i in range(m): ans = ans + str(n) print(ans)
1
84,750,696,817,304
null
232
232
import sys input = sys.stdin.readline def main(): a,b,n = map(int,input().split()) if n < b: print((a*n)//b) exit() num = n//b ans = (a*(b-1))//b print(max(ans,(a*n)//b - a * (n//b))) if __name__ == '__main__': main()
a, b, c = list(map(int, input().split())) frag1 = ((a+b-c)**2 -4*a*b) > 0 frag2 = a+b-c < 0 if frag1 and frag2: print("Yes") else: print("No")
0
null
39,867,465,855,100
161
197
import sys from collections import defaultdict from math import gcd def input(): return sys.stdin.readline().strip() mod = 1000000007 def main(): N = int(input()) fish = defaultdict(int) """ b / aで値を管理するのは浮動小数点誤差が怖いので、 g = gcd(a, b) として(a//g, b//g)のタプルで管理するのが良い。 """ zero = 0 for _ in range(N): a, b = map(int, input().split()) if a == 0 and b == 0: zero += 1 elif a == 0: fish[(0, 1)] += 1 elif b == 0: fish[(1, 0)] += 1 else: g = gcd(a, b) if a < 0: a, b = -a, -b fish[(a // g, b // g)] += 1 #print(fish) """ 仲の悪い組を(S1, T1), (S2, T2),...とすれば(Si, Ti)からの魚の選び方と (Sj, Tj)からの魚の選び方は独立じゃん。 なぜ気づかなかったのか。。。 """ ans = 1 finished = set([]) for a, b in fish: if (a, b) in finished: continue finished.add((a, b)) s = fish[(a, b)] if b > 0: t = fish[(b, -a)] if (b, -a) in fish else 0 finished.add((b, -a)) else: t = fish[(-b, a)] if (-b, a) in fish else 0 finished.add((-b, a)) ans *= pow(2, s, mod) + pow(2, t, mod) - 1 ans %= mod #print("(a, b)=({}, {}) -> s={}, t={}, val={}".format(a, b, s, t, pow(2, s, mod) + pow(2, t, mod) - 1)) print((ans + zero - 1) % mod) if __name__ == "__main__": main()
if __name__ == "__main__": n = int(input()) taro, hanako = 0, 0 for _ in range(n): tw, hw = input().split() if tw > hw: taro += 3 elif tw < hw: hanako += 3 else: taro += 1 hanako += 1 print(taro, hanako)
0
null
11,463,107,206,980
146
67
# Aizu Problem ALDS_1_4_A: Linear Search # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input2.txt", "rt") _ = input() S = set([int(_) for _ in input().split()]) _ = input() T = set([int(_) for _ in input().split()]) print(len(S.intersection(T)))
N, M = map(int,input().split()) li = [] for _ in range(M): p, S = input().split() li.append([int(p), S]) ac = [0] * N wa = [0] * N c1 = 0 c2 = 0 for i in range(M): j = li[i][0] - 1 if li[i][1] == "WA": wa[j] += 1 if ac[j] == 0 and li[i][1] == "AC": ac[j] = 1 c1 += 1 c2 += wa[j] print(c1, c2)
0
null
46,861,104,829,366
22
240
def inp(): return input() def iinp(): return int(input()) def inps(): return input().split() def miinps(): return map(int,input().split()) def linps(): return list(input().split()) def lmiinps(): return list(map(int,input().split())) def lmiinpsf(n): return [list(map(int,input().split()))for _ in range(n)] n = iinp() l = lmiinps() ans = 0 if n < 3: print(0) exit() for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if l[i] == l[j] or l[j] == l[k] or l[i] == l[k]: continue if l[i]+l[j] > l[k] and l[j]+l[k] > l[i] and l[k]+l[i] > l[j]: ans += 1 print(ans)
import sys class Card: def __init__(self, kind, num): self.kind = kind self.num = num def __eq__(self, other): return (self.kind == other.kind) and (self.num == other.num) def __ne__(self, other): return not ((self.kind == other.kind) and (self.num == other.num)) def __str__(self): return self.kind + self.num def list_to_string(array): s = "" for n in array: s += str(n) + " " return s.strip() def swap(array, i, j): tmp = array[i] array[i] = array[j] array[j] = tmp def is_stable(array1, array2): if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))): return "Stable" else: return "Not stable" def bubble_sort(array): for i in range(0, len(array)): for j in reversed(range(i+1, len(array))): if array[j].num < array[j-1].num: swap(array, j, j-1) return array def selection_sort(array): for i in range(0, len(array)): min_index = i for j in range(i, len(array)): if array[min_index].num > array[j].num: min_index = j swap(array, i, min_index) return array def main(): num = int(sys.stdin.readline().strip()) array = map(lambda x: Card(x[0], x[1]), sys.stdin.readline().strip().split(" ")) a = list(array) b = list(array) print list_to_string(bubble_sort(a)) print "Stable" print list_to_string(selection_sort(b)) print is_stable(a, b) if __name__ == "__main__": main()
0
null
2,538,657,766,290
91
16
n = int(raw_input()) x = map(int,raw_input().split()) i = n-1 while i != -1: print "%d" %x[i] , i = i-1
def reverse(l): """ l: a list returns a reversed list >>> reverse([1,2,3,4,5]) [5, 4, 3, 2, 1] >>> reverse([3,3,4,4,5,8,7,9]) [9, 7, 8, 5, 4, 4, 3, 3] >>> reverse([]) [] """ length = len(l) result = [] for i in range(length): result.append(l[length-i-1]) return result if __name__ == '__main__': #import doctest #doctest.testmod() num = int(input()) ilist = [int(i) for i in input().split(' ')] print(' '.join([str(i) for i in reverse(ilist)]))
1
985,896,023,168
null
53
53
def resolve(): N = int(input()) Z = [] W = [] for i in range(N): x, y = map(int, input().split()) Z.append(x + y) W.append(x - y) a = max(Z) - min(Z) b = max(W) - min(W) print(max(a, b)) if __name__ == "__main__": resolve()
while True: x = list(input()) if x[0] == "0": break sum = 0 for i in range(len(x)): sum += int(x[i]) print(sum) #print(x)
0
null
2,498,527,849,760
80
62
h, a = map(int, input().split()) if h % a > 0: number_of_times = h // a + 1 print(number_of_times) else: print(h // a)
def resolve(): N = int(input()) S = list(input()) ans = [chr(((ord(s)-65+N)%26)+65) for s in S] print("".join(ans)) if '__main__' == __name__: resolve()
0
null
105,336,348,784,240
225
271
pd = list(input()) for i in range(len(pd)): if '?' in pd[i]: pd[i] = 'D' print(pd[i], end = '')
t = input() n = len(t) t += "a" ans = "" for i in range(n): if t[i] == "?": ans += "D" else: ans += t[i] print(ans)
1
18,597,533,146,074
null
140
140
n=int(input())+1 data=[0]*n*2 def update(i,x): i+=n data[i]=x i//=2 while i: data[i]=data[i*2]|data[i*2+1] i//=2 def query(l,r): l+=n r+=n s=0 while l<r: if l&1: s|=data[l] l+=1 if r&1: r-=1 s|=data[r] l//=2 r//=2 return sum(map(int,bin(s)[2:])) s=input() for i,c in enumerate(s,n): data[i]=1<<(ord(c)-97) for i in range(n-1,0,-1): data[i]=data[2*i]|data[2*i+1] for _ in range(int(input())): q,a,b=input().split() if q=="2": print(query(int(a)-1,int(b))) else: update(int(a)-1,1<<(ord(b)-97))
import sys k = int(input()) ans = [0]*(k+1) ans[0] = 7 % k if ans[0] == 0: print(1) else: for i in range(k): ans[i+1] = (ans[i]*10 + 7) % k if ans[i+1] == 0: print(i+2) sys.exit() print(-1)
0
null
34,373,365,330,792
210
97
N=int(input()) #m1,d1=map(int,input().split()) #hl=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] S=list(input()) d=list('0123456789') ans=0 for d1 in d: for d2 in d: for d3 in d: v=d1+d2+d3 i=0 p=0 while i < N : if v[p]==S[i]: p+=1 if p == 3: break i+=1 if p==3 : ans+=1 print(ans)
N = int(input()) S = str(input()) R = S[::-1] ans = 0 for i in range(1000): z = str(i).zfill(3) right = -1 left = -1 if z[2] in R: r = R.index(z[2]) + 1 right = N-r else: continue if z[0] in S: left = S.index(z[0]) + 1 else: continue if z[1] in S[left:right]: ans += 1 print(ans)
1
128,403,885,222,688
null
267
267
while True: n=int(input()) if n==0:break s=list(map(float,input().split())) print((sum(map(lambda x: x*x,s))/n-(sum(s)/n)**2)**.5)
N = int(input()) S = input() if N % 2 != 0: print('No') exit() print('Yes') if S[:N//2] == S[N//2:] else print('No')
0
null
73,393,671,059,908
31
279
import sys # from math import sqrt, gcd, ceil, log # from bisect import bisect from collections import defaultdict, Counter inp = sys.stdin.readline read = lambda: list(map(int, inp().strip().split())) # sys.setrecursionlimit(10**6) def solve(): n = int(input()); arr = read() ans= 0 for i in range(n): for j in range(i+1, n): ans += arr[i]*arr[j] print(ans) if __name__ == "__main__": solve()
import math x1,y1,x2,y2=[float(x) for x in input().split(' ')] dis=math.sqrt((y2 - y1)**2 + (x2-x1)**2) print("{:.4f}".format(dis))
0
null
84,415,442,915,232
292
29
#!/usr/bin/python n = input() a = input().split() a.reverse() for (i, item) in enumerate(a): print(str(item), end = ' ' if i != len(a)-1 else '\n')
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] answer = 0 for h in range(2**H): for w in range(2**W): b_cnt = 0 for i in range(H): for j in range(W): if not (h>>i&1 or w>>j&1) and tiles[i][j] == '#': b_cnt += 1 if b_cnt == K: answer += 1 print(answer)
0
null
4,905,505,118,052
53
110
count = 0 n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(n): if a[i] >= sum(a)/4/m: count += 1 if count >= m: print("Yes") else: print("No")
N, M = map(int, input().split()) A = list(map(int, input().split())) D = sum(A) cnt = 0 for i in range(N): if A[i] * 4 * M >= D: cnt += 1 if cnt >= M: print('Yes') else: print('No')
1
38,624,937,390,758
null
179
179
from sys import stdin, setrecursionlimit input = stdin.buffer.readline N = int(input()) A = list(map(int, input().split())) max_A = max(A) if max_A == 1: print("pairwise coprime") exit() class Prime: def __init__(self, n): self.prime_factor = [i for i in range(n + 1)] self.prime = [] for i in range(2, n + 1): if self.prime_factor[i] == i: for j in range(2, n // i + 1): self.prime_factor[i * j] = i self.prime.append(i) #print(self.prime_factor) #print(self.prime) def factorize(self, m): ret = [] while m != 1: if not ret: ret = [[self.prime_factor[m], 1]] elif self.prime_factor[m] == ret[-1][0]: ret[-1][1] += 1 else: ret.append([self.prime_factor[m], 1]) m //= self.prime_factor[m] return ret def divisors(self, m): ret = [] for i in range(1, int(m ** 0.5) + 1): if m % i == 0: ret.append(i) if i != m // i: ret.append(m // i) #self.divisors.sort() return ret pm = Prime(max_A) def is_pairwise_coprime(arr): cnt = [0] * (max_A + 1) for a in arr: for b, c in pm.factorize(a): cnt[b] += 1 if max(cnt[2:]) <= 1: return 1 else: return 0 def gcd(a, b): while b: a, b = b, a % b return a def is_setwise_coprime(A): gcd_a = 0 for a in A: gcd_a = gcd(gcd_a, a) if gcd_a == 1: return 1 else: return 0 if is_pairwise_coprime(A): print("pairwise coprime") elif is_setwise_coprime(A): print("setwise coprime") else: print("not coprime")
from sys import stdin from collections import defaultdict # from bisect import * # from heapq import * # import math # mod = 10**9+7 N = input() A = list(map(int, input().split())) M = 10**6+1 spf = [i for i in range(M)] for i in range(2, M): if spf[i] == i: for j in range(i+i, M, i): spf[j] = i cnt = defaultdict(int) for a in A: ps = set() while a != 1: ps.add(spf[a]) a = a // spf[a] for p in ps: cnt[p] += 1 if all([x < 2 for x in cnt.values()]): print("pairwise coprime") exit() gcd = lambda x, y : x if y == 0 else gcd(y, x % y) x = A[0] for a in A[1:]: x = gcd(x, a) if x == 1: print("setwise coprime") else: print("not coprime")
1
4,084,704,491,000
null
85
85
n, q = map(int, input().split()) s = list() process = 0 t = list() for i in range(n): name, time = map(str, input().split()) s.append([name, int(time)]) flag = True while s: diff = s[0][1] - q if diff <= 0: process += s[0][1] t.append([s[0][0], process]) s.pop(0) else: process += q s.append([s[0][0], diff]) s.pop(0) for i in t: print(i[0], i[1])
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline from numba import njit def getInputs(): D = int(readline()) CS = np.array(read().split(), np.int32) C = CS[:26] S = CS[26:].reshape((-1, 26)) return D, C, S @njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True) def _compute_score1(D, C, S, out): score = 0 last = np.zeros((D, 26), np.int32) for d in range(len(out)): if d: last[d, :] = last[d - 1, :] i = out[d] score += S[d, i] last[d, i] = d + 1 score -= np.sum(C * (d + 1 - last[d, :])) return last, score def _update_score(): pass @njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True) def _random_update(D, C, S, out, score): d = np.random.randint(0, D) q = np.random.randint(0, 26) p = out[d] out[d] = q if p == q: return out, score last, new_score = _compute_score1(D, C, S, out) if score < new_score: score = new_score else: out[d] = p return out, score def _random_swap(): pass def step1(D, C, S): out = [] LAST = 0 for d in range(D): max_score = -10000000 best_i = 0 for i in range(26): out.append(i) last, score = _compute_score1(D, C, S, np.array(out, np.int32)) if max_score < score: max_score = score LAST = last best_i = i out.pop() out.append(best_i) return np.array(out), LAST, max_score def step2(D, C, S, out, score): for i in range(10 ** 4): out = out.astype(np.int32) out, score = _random_update(D, C, S, out, score) return out, score def output(out): out += 1 print('\n'.join(out.astype(str).tolist())) D, C, S = getInputs() out, _, score = step1(D, C, S) #print(score) out, score = step2(D, C, S, out, score) output(out) #print(score)
0
null
4,802,939,121,198
19
113
import math a,b,C = map(int,input().split()) C = math.radians(C) c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C)) S = 1/2*a*b*math.sin(C) L = a+b+c h = b * math.sin(C) print('{0:.5f}\n{1:.5f}\n{2:.5f}'.format(S,L,h))
import math a,b,x=map(float, input().split()) h=b*math.sin(math.pi*x/180) c=(a**2+b**2-2*a*b*math.cos(math.pi*x/180))**0.5 print(a*h*0.5) print(a+b+c) print(h)
1
169,915,422,880
null
30
30
A, B, K = map(int, input().split()) if A-K >= 0: print(A-K, B) else: if B-(K-A)<0: print(0, 0) quit() print(0, B-(K-A))
#submit 16999743 a, b = input().split() a = int(a) b1, b2 = b.split('.') ans = a * (int(b1) * 100 + int(b2)) // 100 print(ans)
0
null
60,491,187,040,912
249
135
n = int(input()) S = input() l = len(S) S += 'eeee' cnt = 0 for i in range(10): for j in range(10): for k in range(10): # tmp = str(i)+str(j)+str(k) m = 0 while S[m] != str(i): m += 1 if m >= l: break m += 1 while S[m] != str(j): m += 1 if m >= l: break m += 1 while S[m] != str(k): m += 1 if m >= l: break if m < l: cnt += 1 print(cnt)
import itertools N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) R = [i+1 for i in range(N)] RPS = sorted(list(itertools.permutations(R))) print(abs(RPS.index(P)-RPS.index(Q)))
0
null
114,594,080,331,960
267
246
def main(): a, b, c, d = map(int, input().split()) if c % b == 0: e = c // b else: e = c // b + 1 if a % d == 0: f = a // d else: f = a // d + 1 if e > f: ans = "No" else: ans = "Yes" print(ans) if __name__ == "__main__": main()
import math a,b,c,d = (int(x) for x in input().split()) if math.ceil (a/d) < math.ceil (c/b): print ('No') else: print ('Yes')
1
29,924,812,160,386
null
164
164
import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N, M, L = map(int, input().split()) dist = [[INF] * N for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) if c > L: continue a -= 1 b -= 1 dist[a][b] = c dist[b][a] = c Q = int(input()) for k in range(N): for i in range(N): for j in range(N): if dist[i][j] > dist[i][k] + dist[k][j]: dist[i][j] = dist[i][k] + dist[k][j] fuel = [[INF] * N for _ in range(N)] for i in range(N): for j in range(N): fuel[i][j] = 1 if dist[i][j] <= L else INF for k in range(N): for i in range(N): for j in range(N): if fuel[i][j] > fuel[i][k] + fuel[k][j]: fuel[i][j] = fuel[i][k] + fuel[k][j] for i in range(Q): s,t = map(int, input().split()) if fuel[s - 1][t - 1] != INF: print(fuel[s - 1][t - 1] - 1) else: print(-1)
import sys input = sys.stdin.readline def main(): N, M, L = map(int, input().split()) dist = [[float('inf')] * N for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) if C > L: continue A -= 1 B -= 1 dist[A][B] = C dist[B][A] = C for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) e = [[float('inf')] * N for _ in range(N)] for i in range(N): for j in range(N): if dist[i][j] <= L: e[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): e[i][j] = min(e[i][j], e[i][k] + e[k][j]) Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) s -= 1 t -= 1 if e[s][t] == float('inf'): print(-1) continue ans = e[s][t] print(ans-1) if __name__ == "__main__": main()
1
173,982,686,911,682
null
295
295
n = int(input()) def divGame(N=n): if N == 1: return 0 if N == 2: return 1 factors = [] for i in range(2, int(N**0.5 + 1)): count = 0 while N % i == 0: N /= i count += 1 if count != 0: factors.append(count) if N != 1: factors.append(1) factors.sort() answer = 0 accum = 1 count = 1 for i in range(len(factors)): while factors[i] >= accum: count += 1 accum += count answer += count - 1 return answer print(divGame())
n = int(input()) x = n%10 if (x == 2 or x == 4 or x == 5 or x == 7 or x == 9): print("hon") elif (x == 0 or x == 1 or x == 6 or x == 8): print("pon") else: print("bon")
0
null
18,006,752,707,310
136
142
#!/usr/bin/env python3 def main(): print(int(input()) ** 3 / 27) if __name__ == '__main__': main()
N,M = map(int,input().split()) H = list(map(int,input().split())) H.insert(0,0) S = set() for m in range(M): A,B = map(int,input().split()) if H[A]<=H[B]: S.add(A) if H[A]>=H[B]: S.add(B) print(N-len(S))
0
null
36,192,165,054,308
191
155
D, T, S = list(map(int, input().split())) if D <= S * T: print("Yes") else: print("No")
D, T, S = input().split() D = int(D) T = int(T) S = int(S) if D <= (T*S): print("Yes") else: print("No")
1
3,535,817,227,380
null
81
81
line = raw_input() lis = line.split() a = int(lis[0]) b = int(lis[1]) s = a * b len = 2 * (a + b) print str(s) + " " + str(len)
def check(i, j): if s[i][j] == '.': return 1 else: return 0 H, W = map(int, input().split()) s = [input() for i in range(H)] dp = [[0]*W for i in range(H)] dp[0][0] = int(s[0][0] == '#') for i in range(H): for j in range(W): if s[i][j] == '.': if i > 0 and j > 0: dp[i][j] = min(dp[i-1][j], dp[i][j-1]) elif i > 0: dp[i][j] = dp[i-1][j] elif j > 0: dp[i][j] = dp[i][j-1] else: if i > 0 and j > 0: dp[i][j] = min(dp[i-1][j]+check(i-1, j), dp[i][j-1]+check(i, j-1)) elif i > 0: dp[i][j] = dp[i-1][j]+check(i-1, j) elif j > 0: dp[i][j] = dp[i][j-1]+check(i, j-1) print(dp[H-1][W-1])
0
null
24,947,907,771,368
36
194
#coding:utf-8 #1_8_C 2015.4.8 sentence = '' while True: try: sentence += input().lower() except: break for i in range(ord('a') , ord('z') + 1): print('{} : {}'.format(chr(i),sentence.count(chr(i))))
import collections import sys S = "".join([line for line in sys.stdin]) count = collections.Counter(S.lower()) for char in "abcdefghijklmnopqrstuvwxyz": print("{0:s} : {1:d}".format(char, count[char]))
1
1,671,019,043,148
null
63
63
import math n = (int)(input()) 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] ret = x[n-1] print("{}".format(ret))
import sys texts=sys.stdin.read() texts=texts.lower() cnt=[0]*26 letters=list('abcdefghijklmnopqrstuvwxyz') for x in texts: i=0 for y in letters: if x==y: cnt[i]+=1 i+=1 for i in range(26): print(letters[i]+" : "+str(cnt[i]))
0
null
26,005,134,879,488
195
63
import numpy as np n,k = map(int,input().split()) m = 10**9 + 7 gcds = np.zeros(k+1, int) ans = 0 for i in range(k,0,-1): tmp = pow(k//i,n, m) for j in range(i*2,k+1,i): tmp -= gcds[j] ans = (ans + tmp*i)%m gcds[i] = tmp print(ans)
mod=10**9+7 n,k=map(int,input().split()) l=[0]*(k+1) for i in range(k): num=(k-i) if k//num==1: l[num]=1 else: ret=pow(k//num,n,mod) for j in range(2,k//num+1): ret-=l[num*j] ret%=mod l[num]=(ret)%mod ans=0 for i in range(k+1): ans+=(l[i]*i)%mod print(ans%mod)
1
36,954,470,731,012
null
176
176
N = int(input()) S = [x for x in input()] Q = int(input()) #A1 ... AnのBIT(1-indexed) BIT = [[0] * (N + 1) for _ in range(26)] #A1 ~ Aiまでの和 O(logN) def BIT_query(input_BIT, idx): res_sum = 0 while idx > 0: res_sum += input_BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def BIT_update(input_BIT,idx,x): while idx <= N: input_BIT[idx] += x idx += (idx&(-idx)) return for i, c in enumerate(S): BIT_update(BIT[ord(c)-ord('a')], i+1, 1) for _ in range(Q): a, b, c = input().rstrip().split() if int(a) == 1: BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1) BIT_update(BIT[ord(c)-ord('a')], int(b), 1) S[int(b)-1] = c else: count = 0 for i in range(26): if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)): count += 1 print(count)
import numpy as np N = int(input()) A = np.array(list(map(int, input().split()))) A_cs = A.cumsum() A_cs = A_cs - A_cs[-1]/2 div = np.abs(A_cs).argmin() print(abs(A[:div+1].sum() - A[div+1:].sum()))
0
null
102,343,773,148,324
210
276
def main(): n = int(input()) if n % 10 == 3: print("bon") return elif n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8: print("pon") return else: print("hon") return main()
S = int(input()) mod = 10**9+7 dp = [1]+[0]*S for i in range(1, S+1): for j in range(0, i-2): dp[i] += dp[j] print(dp[S]%mod)
0
null
11,198,156,166,232
142
79
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) total = sum(A) total *= 2 mindif = 1e12 sub = 0 for i in range(N): sub += 2 * A[i] dif = abs(total//2-sub) if dif < mindif: mindif = dif print(mindif)
n = int(input()) A = list(map(int, input().split())) ans = 10**18 total = sum(A) acc = 0 for a in A: acc += a ans = min(ans, abs(total - acc * 2)) print(ans)
1
142,580,251,974,468
null
276
276
n = int(input()) a = sorted([int(i) for i in input().split()]) cnt = 1 for ai in a: cnt *= ai if cnt > 10 ** 18: print(-1) exit() print(cnt)
input();a=1 for i in input().split():a*=int(i);a=[-1,a][0<=a<=10**18] print(a)
1
16,306,792,873,062
null
134
134
import math from math import gcd,pi,sqrt INF = float("inf") import sys sys.setrecursionlimit(10**6) import itertools from collections import Counter,deque def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def main(): n, x, y = i_map() ans = [0] * n for fr in range(1, n+1): for to in range(fr+1, n+1): cost = min(to - fr, abs(x-fr) + abs(to - y) + 1) ans[cost] += 1 print(*ans[1:], sep="\n") if __name__=="__main__": main()
n,x,y=map(int,input().split()) x-=1;y-=1 fl=[0 for i in range(n-1)] for i in range(n): for j in range(i+1,n): fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1 print(*fl[1:],sep="\n") print(0)
1
44,130,187,595,392
null
187
187
from collections import deque def main(): H, W = map(int, input().split()) field = "#"*(W+2) field += "#" + "##".join([input() for _ in range(H)]) + "#" field += "#"*(W+2) INF = 10**9 cost = [INF]*len(field) move = [-1, 1, -(W+2), W+2] def bfs(s, g): q = deque() dequeue = q.popleft enqueue = q.append cost[s] = 0 enqueue(s) while q: now = dequeue() now_cost = cost[now] for dx in move: nv = now + dx if nv == g: cost[g] = now_cost + 1 return if field[nv] == "#" or cost[nv] < INF: continue else: cost[nv] = now_cost + 1 q.append(nv) ans = 0 for si in range(H): for sj in range(W): for gi in range(H): for gj in range(W): start = (si+1)*(W+2)+sj+1 goal = (gi+1)*(W+2)+gj+1 if field[start] == "#" or field[goal] == "#" or start == goal: continue cost = [INF] * len(field) bfs(start, goal) ans = max(ans, cost[goal]) print(ans) if __name__ == "__main__": main()
import math a,b,x=map(float, input().split()) h=b*math.sin(math.pi*x/180) c=(a**2+b**2-2*a*b*math.cos(math.pi*x/180))**0.5 print(a*h*0.5) print(a+b+c) print(h)
0
null
47,319,968,094,070
241
30
import sys n = int(raw_input()) R = [int(raw_input()) for i in xrange(n)] minimum = sys.maxint maximum = -sys.maxint - 1 for x in R: p = x - minimum if maximum < p: maximum = p if minimum > x: minimum = x print maximum
n = int(input()) r = [] for i in range(n): r.append(int(input())) min = r[0] max = -10 ** 12 for j in r[1:]: if j - min > max: max = j - min if min > j: min = j print(max)
1
13,121,136,288
null
13
13
a = raw_input() while a!='0': s = 0 for i in range(len(a)): s += int(a[i]) print s a = raw_input()
N = int(input()) s = 0 for i in range(1,N+1): if i%2 != 0: s += 1 print(s/N)
0
null
89,150,739,706,542
62
297
def W(d): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d ############################## n,w,l= map(int,input().split()) #n:頂点数 w:辺の数 d = [[10**14]*n for i in range(n)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(w): x,y,z = map(int,input().split()) if z>l: continue x=x-1 y=y-1 d[x][y] = z d[y][x] = z for i in range(n): d[i][i] = 0 #自身のところに行くコストは0 D=W(d) G=[[10**4]*n for i in range(n)] for i in range(n): for j in range(n): if D[i][j]>l: continue G[i][j]=1 WW=W(G) for i in range(int(input())): a,b=map(int,input().split()) a=a-1 b=b-1 if WW[a][b]>=10**4: print(-1) else: print(WW[a][b]-1)
def resolve(): from scipy.sparse.csgraph import floyd_warshall import numpy as np import sys input = sys.stdin.readline n, m, l = map(int, input().split()) inf = 10 ** 20 ar = [[0] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) ar[a - 1][b - 1] = c ar[b - 1][a - 1] = c x = floyd_warshall(ar) br = [[0] * n for _ in range(n)] for i in range(n): for j in range(i + 1, n): if x[i, j] <= l: br[i][j] = 1 br[j][i] = 1 y = floyd_warshall(br) q = int(input()) for _ in range(q): s, t = map(int, input().split()) p = y[s - 1, t - 1] print(int(p) - 1 if p < inf else -1) if __name__ == "__main__": resolve()
1
173,230,220,852,740
null
295
295
N=list(input()) n=[int(s) for s in N] if n[-1]==2 or n[-1]== 4 or n[-1]== 5 or n[-1]== 7 or n[-1]== 9: print('hon') elif n[-1]==0 or n[-1]==1 or n[-1]== 6 or n[-1]== 8: print('pon') else : print('bon')
N = int(input()) X = (N%100)%10 if X == 3: print('bon') elif X == 0 or X == 1 or X == 6 or X == 8: print('pon') else: print('hon')
1
19,104,839,969,600
null
142
142
import itertools n = int(input()) a = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) able = [0] * (max(n * max(a) + 1, 2001)) for item in itertools.product([0, 1], repeat=n): total = sum([i * j for i, j in zip(a, item)]) able[total] = 1 for m in M: print('yes' if able[m] else 'no')
alphabet = 'abcdefghijklmnopqrstuvwxyz' from collections import defaultdict import sys adict = defaultdict(int) for l in sys.stdin: for c in l.lower(): adict[c] += 1 for k in alphabet: print('%s : %i' %(k, adict[k]))
0
null
893,727,847,848
25
63
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): S = input() cnt = 0 mx = 0 for i in range(len(S)): if (S[i] == 'R'): cnt += 1 else: cnt = 0 mx = max(mx, cnt) print(mx) if __name__ == '__main__': main()
import math N = float(input()) if(N%2==0): print(1/2) else: print((math.floor(N/2)+1)/N)
0
null
91,232,215,139,520
90
297
X=int(input()) number1=X//500 number2=(X-(X//500)*500)//5 print(number1*1000+number2*5)
x = int(input());print((x//500)*1000 + ((x%500)//5)*5)
1
42,997,742,978,348
null
185
185
import math N = int(input()) print (math.ceil(N/2))
def A(): n = int(input()) print(-(-n//2)) A()
1
59,113,723,996,844
null
206
206
#coing:utf-8 def distance(a,b): dst = pow(a,2) + pow(b,2) return dst def isTriangle(lines): idxList = [[0,1,2],[1,0,2],[2,0,1]] flag = False for i in idxList: if not flag and pow(lines[i[0]],2) == distance(lines[i[1]], lines[i[2]]): flag = True return flag if __name__ == '__main__': num = int(input()) results = [] for i in range(num): lines = [int(item) for item in input().split(" ")] results.append(isTriangle(lines)) for r in results: if r: print("YES") else : print("NO")
N, K = map(int, input().split()) A = list(map(lambda x: int(x)-1, input().split())) sa = [0] for a in A: sa.append((sa[-1] + a) % K) d = {0: 1} ans = 0 for i in range(1, N+1): if i >= K: d[sa[i-K]] -= 1 v = d.get(sa[i], 0) ans += v d[sa[i]] = v + 1 print(ans)
0
null
68,729,690,796,570
4
273
n = int(input()) for i in range(n): a = list(map(int, input().split())) m = max(a) b = sum([i**2 for i in a if i != m]) if (m**2 == b): print("YES") else: print("NO")
h = int(input()) num = 0 t = 0 while h != 1: h = h//2 num += 2**t t += 1 num += 2**t print(num)
0
null
40,184,529,990,350
4
228
N=int(input()) d=list(map(int, input().split())) sum=0 for i in range(0,N-1): for j in range(i+1,N): sum=sum+d[i]*d[j] print(sum)
N, P = map(int, input().split()) S = input() if 10 % P == 0: ans = 0 for r in range(N): if int(S[r]) % P == 0: ans += r + 1 print(ans) exit() d = [0] * (N + 1) ten = 1 for i in range(N - 1, -1, -1): a = int(S[i]) * ten % P d[i] = (d[i + 1] + a) % P ten *= 10 ten %= P cnt = [0] * P ans = 0 for i in range(N, -1, -1): ans += cnt[d[i]] cnt[d[i]] += 1 print(ans)
0
null
113,275,648,575,590
292
205
n = int(input()) s = input().split() arr = [int(s[i]) for i in range(n)] arr.sort() sum = 0 for i in range(len(arr)): sum += arr[i] print(arr[0], arr[len(arr)-1], sum)
n = input() l = [int(i) for i in input().split()] print(' '.join([str(min(l)),str(max(l)),str(sum(l))]))
1
741,376,479,378
null
48
48
n = int(input()) p = list(map(int,input().split())) for x in p: if x % 2 == 0: if x % 3 != 0 and x % 5 != 0: print("DENIED") break else : print("APPROVED")
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) ans = "APPROVED" for a in A: if a % 2 == 0: if a % 3 == 0 or a % 5 == 0: pass else: ans = "DENIED" break print(ans)
1
69,333,507,012,106
null
217
217
str1 = str(input()) if len(str1) != 6 : print('No') if str1[2] == str1[3] and str1[4] == str1[5] : print('Yes') else : print('No')
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): if S[2] == S[3] and S[4] == S[5]: print(YES) else: print(NO) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == '__main__': main()
1
42,017,172,208,988
null
184
184
import math s = input().split(" ") n = list(map(float,s)) d = math.sqrt((n[0]-n[2])**2 + (n[1]-n[3])**2) print(d)
x1, y1, x2, y2 = (float(x) for x in input().split()) print("{:.7f}".format(((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5))
1
153,481,724,202
null
29
29