code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
N = int(input()) res = 0 for i in range(int(N**0.5)): if(N % (i+1) == 0): res = max(res, i+1) print((res-1) + (N//res-1))
n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = input() point = {"r":(p,"p"), "s":(r,"r"), "p":(s,"s")} ans = 0 hand = "" for i in range(n): if i < k: ans += point[t[i]][0] hand += point[t[i]][1] else: if (t[i-k] != t[i]): ans += point[t[i]][0] hand += point[t[i]][1] else: if hand[i-k] != point[t[i]][1]: ans += point[t[i]][0] hand += point[t[i]][1] else: if (i+k) < n: hand += "rsp".replace(point[t[i+k]][1],"").replace(hand[i-k],"")[0] else: hand += "rsp".replace(hand[i-k],"")[0] print(ans)
0
null
134,830,181,433,782
288
251
import math # 提出用 n = int(input()) x = [int(i) for i in input().split()] y = [int(i) for i in input().split()] # # 動作確認用 # with open('input_itp1_10_d_1.txt', mode='r')as fin: # n = int(next(fin)) # x = [int(i) for i in next(fin).split()] # y = [int(i) for i in next(fin).split()] tmp = 0 for i in range(n): tmp += abs(x[i] - y[i]) print('%f' % (tmp)) tmp = 0 for i in range(n): tmp += (abs(x[i] - y[i]))**2 print('%f' % (math.sqrt(tmp))) tmp = 0 for i in range(n): tmp += (abs(x[i] - y[i]))**3 print('%f' % (pow(tmp, 1 / 3))) tmp = 0 for i in range(n): tmp = abs(x[i] - y[i]) if tmp < abs(x[i] - y[i]) else tmp print('%f' % (tmp))
def main(): H, W, M = map(int, input().split()) h_dic = [0] * H w_dic = [0] * W boms = set() for _ in range(M): h, w = map(int, input().split()) h, w = h-1, w-1 h_dic[h] += 1 w_dic[w] += 1 boms.add((h, w)) hmax = max(h_dic) wmax = max(w_dic) h_maxs = [idx for idx, v in enumerate(h_dic) if v==hmax] w_maxs = [idx for idx, v in enumerate(w_dic) if v==wmax] # 爆弾数はたかだか3*10~5なので、総当りで解ける for h in h_maxs: for w in w_maxs: if (h, w) not in boms: print(hmax + wmax) return print(hmax + wmax - 1) return if __name__ == "__main__": main()
0
null
2,423,246,478,650
32
89
from sys import stdin from collections import Counter N, P = map(int, stdin.readline().split()) S = stdin.readline().strip() ans = 0 if P in (2, 5): for i in range(N): if int(S[i]) % P == 0: ans += i + 1 else: count = Counter() ten = 1 mod = 0 for i in range(N): x = (int(S[N - i - 1])*ten + mod) % P ten = ten*10 % P mod = x count[x] += 1 count[0] += 1 for i in count.values(): ans += i*(i - 1)//2 print (ans)
N, P = map(int, input().split()) S = input() if P == 2: ans = 0 for i, d in enumerate(map(int, S)): if d % 2 == 0: ans += i+1 print(ans) elif P == 5: ans = 0 for i, d in enumerate(map(int, S)): if d % 5 == 0: ans += i+1 print(ans) else: mods = [0] * P mods[0] = 1 cur_mod = 0 for i, digit in enumerate(map(int, S)): cur_mod += pow(10, N-i-1, P) * digit cur_mod %= P mods[cur_mod] += 1 ans = 0 for count in mods: ans += count * (count - 1) // 2 print(ans)
1
58,217,581,710,442
null
205
205
cards=input() new=cards.split() a=int(new[0]) b=int(new[1]) c=int(new[2]) k=int(new[3]) if a>k: print(k) else: if a+b>k: print(a) else: sum=a+(k-(a+b))*(-1) print(sum)
A,B,C,K = map(int,input().split()) Current_Sum = 0 if K <= A : ans = K elif K <= (A + B): ans = A else: K -= (A + B) ans = A - K print(ans)
1
21,802,379,103,228
null
148
148
a,b=map(int,input().split()) c=0 res = 0 if a >=10: print(b) else: c = 100 * (10-a) res = b+c print(res)
from sys import exit N, R = [int(x) for x in input().split()] if N >= 10: print(R) exit() else: print(R + (100 * (10 - N))) exit()
1
63,430,399,903,610
null
211
211
N,M,L = map(int,input().split()) A = [list(map(int,input().split()))for i in range(N)] B = [list(map(int,input().split()))for i in range(M)] ANS = [[0]*L for i in range(N)] for x in range(N): for y in range(L): for z in range(M): ANS[x][y]+=B[z][y]*A[x][z] for row in range(N): print("%d"%ANS[row][0],end="") for col in range(1,L): print(" %d"%(ANS[row][col]),end="") print()
n, m, l =map(int, input().split()) A = [] B = [] C = [] for i in range(n): i = list(map(int, input().split())) A.append(i) for i in range(m): i = list(map(int, input().split())) B.append(i) #積を求める for i in range(n): line = [] for j in range(l): c = 0 for k in range(m): c += A[i][k] * B[k][j] line.append(c) C.append(line) #形式に合わせて出力する for line in C: print(*line)
1
1,408,514,052,890
null
60
60
from collections import defaultdict N, K = map(int, input().split()) A = [(int(c)%K)-1 for c in input().split()] B = [0] for c in A: B += [B[-1]+c] dic = defaultdict(int) ldic = defaultdict(int) for i in range(min(K,N+1)): c = B[i] dic[c%K] += 1 ans = 0 #print(dic) for i in range(1,N+1): x = B[i-1] ldic[x%K] += 1 ans += dic[x%K]-ldic[x%K] if K+i-1<=N: dic[B[K+i-1]%K] += 1 """ print('###############') print(i,x, ans) print(dic) print(ldic) """ print(ans)
n,k=map(int,input().split()) a=list(map(int,input().split())) current=[0] dic={} dic[0]=1 ans=0 for i in range(n): current.append((current[-1]+a[i]-1)%k) if i>=k-1: dic[current[-k-1]]-=1 if current[-1] in dic: ans+=dic[current[-1]] dic[current[-1]]+=1 else: dic[current[-1]]=1 print(ans)
1
137,529,983,641,690
null
273
273
N=int(input()) count=0 for A in range(1,N): count+=(N-1)//A print(count)
n = int(input()) total = 0 for i in range(1, n + 1): j = n // i if n % i == 0: j -= 1 total += j print(total)
1
2,581,199,964,200
null
73
73
n = int(input()) a = [int(x) for x in input().split()] a.sort() ans = 1 for i in a: ans *= i if ans > 10 ** 18: print(-1) break else: print(ans)
n = int(input()) A = sorted(list(map(int, input().split())))[::-1] if 0 in A: print(0) exit() ans = 1 for a in A: ans *= a if ans > 10 **18: print(-1) exit() print(ans)
1
16,175,841,382,122
null
134
134
n,k=input().split();print(sum(sorted(list(map(int,input().split())))[:int(k)]))
def resolve(): n = int(input()) s = input() ans = '' for i in s: ans += chr(ord('A')+(ord(i)-ord('A')+n)%26) print(ans) resolve()
0
null
73,110,367,690,320
120
271
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() s = S() rgb = ["R","G","B"] rgb_st = set(rgb) rgb_acc = [[0]*n for _ in range(3)] index = rgb.index(s[0]) rgb_acc[index][0] += 1 ans = 0 for i in range(1,n): for j in range(3): rgb_acc[j][i] = rgb_acc[j][i-1] index = rgb.index(s[i]) rgb_acc[index][i] += 1 for i in range(n-2): for j in range(i+1,n-1): if s[i] != s[j]: ex = (rgb_st-{s[i],s[j]}).pop() index = rgb.index(ex) cnt = rgb_acc[index][-1] - rgb_acc[index][j] if j<2*j-i<n: if s[2*j-i] == ex: cnt -= 1 ans += cnt print(ans) main()
a = int(input()) l = [] c,f =0, 0 for i in range(a): ta,tb = map(int,input().split()) if ta==tb : c+=1 else: c = 0 if c>=3 : f = 1 if f: print("Yes") else: print("No")
0
null
19,359,658,734,670
175
72
n=input() m = 100000 for _ in xrange(n): m = m + m*0.05 if m % 1000: m = m + 1000 - m % 1000 print int(m)
a=raw_input() debt = 100000 for i in range(int(a)): debt += debt/20 b=debt%1000 if b > 0: debt += 1000-b print debt
1
1,184,324,868
null
6
6
#queue n,q=(int(i) for i in input().split()) nl=[] t=[] et=0 for i in range(n): na,ti=(j for j in input().split()) # print(t) nl.append(na) t.append(int(ti)) i=0 while len(nl)>0: t[i]-=q et+=q # print(t) if t[i]<=0: et+=t[i] print(nl[i]+" "+str(et)) nl.pop(i) t.pop(i) i-=1 i+=1 if i>=len(nl): i=0
from collections import deque process = deque(maxlen=100000) n, q = [int(x) for x in input().split(' ')] for i in range(n): name, time = input().split(' ') process.append([name, int(time)]) total_time = 0 while process: p_q = process.popleft() if p_q[1] > q: total_time += q p_q[1] -= q process.append(p_q) else: total_time += p_q[1] print('{} {}'.format(p_q[0], total_time))
1
41,459,773,262
null
19
19
n,m = map(int,input().split()) dac = {} for i in range(1,n+1): dac[str(i)] = 0 dwa = {} for i in range(1,n+1): dwa[str(i)] = 0 for i in range(m): p,s = input().split() if s == 'AC': dac[p] = 1 if s == 'WA' and dac[p] == 0: dwa[p] += 1 ac = 0 wa = 0 for k,v in dac.items(): ac += v for k,v in dwa.items(): if dac[k] == 1: wa += v print(ac,wa)
# 22-Math_Functions-Distance_II.py # ??????????????????????????¢ # ???????????????????????????????????????????????????????????????????????¢??§??¬??????????????? # ????????????????????°???????????????????§?????????¨????????§???????????????????????? # ????????§??????????????? n ?¬???????????????? # x={x1,x2,...,xn} ??¨ # y={y1,y2,...,yn} # ????????¢????¨???????????????????????????? # ????????????????????????????????¢?????¬???????¨?????????¨?????¨??????????¬??????????????????????????????¢?????\????????????????????? # Dxy=(???{i=1n}|xi???yi|^p)1/p # p=1 ?????¨??? # Dxy=|x1???y1|+|x2???y2|+...+|xn???yn| # ??¨?????????????????????????????????????????¢??¨?????°???????????? # p=2 ?????¨??? # Dxy=(|x1???y1|)2+(|x2???y2|)2+...+(|xn???yn|)2????????????????????????????????????????????????????????????????????????????????????????????????????????? # ??¨???????????????????????¬?????????????????????????????????????????¢?????????????????? # p=??? ?????¨??? # Dxy=maxni=1(|xi???yi|) # ??¨???????????????????????§????????§????????¢??¨?????°???????????? # ????????? n ?¬???????????????????????????????????????§??? # p ??????????????? 1???2???3?????? ?????????????????????????????¢????±???????????????°???????????????????????????????????? # Input # ??????????????´??° n ???????????????????????? # ???????????????????????? x ???????´? {x1,x2,...xn}{x1,x2,...xn}??? # ???????????????????????? y ???????´? {y1,y2,...yn}{y1,y2,...yn} # ????????????????????§???????????????????????\?????????????????´??°?????§?????? # Output # p ??????????????? 1???2???3?????? ??????????????????????????????????????¢?????????????????????????????? # ????????????0.00001 ??\????????????????????£????????????????????¨???????????? # Constraints # 1???n???100 # 0???xi,yi???1000 # Sample Input # 3 # 1 2 3 # 2 0 4 # Sample Output # 4.000000 # 2.449490 # 2.154435 # 2.000000 n = int(input()) x = list( map(int, input().split()) ) y = list( map(int, input().split()) ) pp=[1.0, 2.0, 3.0, 500.0] for p in pp: if p==500.0: print( "{0:.8f}".format( max( [abs(x[i]-y[i]) for i in range(n)] ) )) else: print( "{0:.8f}".format( sum( [abs(x[i]-y[i])**p for i in range(n)] )**(1./p) ))
0
null
46,848,115,887,440
240
32
a, b, c = (int(x) for x in input().split()) cnt = 0 for i in range(a, b+1): if c % i == 0: cnt += 1 print(cnt)
z = input() a = list(map(int, z.split())) cnt = 0 for i in range(a[0], a[1] + 1, 1): if a[2] % i == 0: cnt += 1 print(cnt)
1
553,601,449,828
null
44
44
a,b=map(int,input().split()) print('%d %d %.5f\n'%(a//b,a%b,a/b))
def bubble_sort(A): count = 0 for i in reversed(range(len(A))): for j in range(i): if A[j] > A[j+1]: temp = A[j] A[j] = A[j+1] A[j+1] = temp count += 1 return count N = int(input()) A = list(map(int,input().split())) count = bubble_sort(A) print(" ".join(map(str,A))) print(count)
0
null
302,218,518,578
45
14
n, k = map(int, input().split()) s = "" while(True): if n < k : s += str(n) break else : s += str(n%k) n = n//k print(len(s))
N = int(input()) u = [] v = [] for _ in range(N): x,y = map(int,input().split()) u.append(x+y) v.append(x-y) umax = max(u) umin = min(u) vmax = max(v) vmin = min(v) print(max(umax-umin,vmax-vmin))
0
null
33,963,811,222,540
212
80
def reverse_polish_notation(A): ops = {'+': lambda a, b: b + a, '-': lambda a, b: b - a, '*': lambda a, b: b * a} stack = [] for i in A: if i in ops: stack.append(ops[i](stack.pop(), stack.pop())) else: stack.append(int(i)) return stack[0] if __name__ == '__main__': A = list(input().split()) print(reverse_polish_notation(A))
l=list(input().split()) ##文字も数字も入る stack=[] for x in l: ##リストの長さ文だけ繰り返し if x in ['+','-','*']: ##←知らなかった判定方法 t=str(stack.pop()) ##末尾取り出し r=str(stack.pop()) c=r+x+t stack+=[int(eval(c))] ##eval:入力した式の入力 else: stack+=[int(x)] ##[]の意味?>リストに追加 print(stack.pop())
1
36,361,856,740
null
18
18
import sys sys.setrecursionlimit(10**9) INF = 10**20 def main(): H,N = map(int,input().split()) A,B = [],[] for _ in range(N): a,b = map(int,input().split()) A.append(a) B.append(b) tp = 3 * 10**4 dp = [INF] * tp dp[0] = 0 ans = INF for h in range(tp): minim = INF for i in range(N): dp_i = h-A[i] if dp_i >= 0 and dp[dp_i] != INF: minim = min(minim,dp[dp_i]+B[i]) # print(dp[h-A[i]]+B[i]) if minim != INF: dp[h] = minim if h >= H: ans = min(ans,dp[h]) print(ans) if __name__ == "__main__": main()
def resolve(): INF = 1<<60 H, N = map(int, input().split()) A, B = [], [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) dp = [INF]*(H+1) dp[0] = 0 for h in range(H): for i in range(N): to = min(H, A[i]+h) dp[to] = min(dp[to], dp[h]+B[i]) print(dp[H]) if __name__ == "__main__": resolve()
1
81,216,906,685,408
null
229
229
N = input() USA = 0 n = 0 h = 0 k = 0 for i in range(0,len(N)): n += int(N[i]) if n % 9 == 0: print("Yes") else: print("No") # h += 1 # n += h # # if n == N+1: # if n % 9 == 0:
h,w = map(int, input().split()) if h == 1 or w == 1: print(1) else: if h % 2 == 0: print(int((h / 2) * w)) else: if w % 2 == 0: print(int(((h//2) * w/2) + ((h//2 + 1) * w/2))) else: print(int(((h//2 + 1) * (w//2+1)) + ((h//2) * (w//2))))
0
null
27,605,932,136,832
87
196
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) from math import ceil h,w = readints() s = [readstr() for i in range(h)] dp = [[0]*w for i in range(h)] if s[0][0] == '.': dp[0][0] = 0 else: dp[0][0] = 1 for i in range(1,h): if s[i][0] != s[i-1][0]: dp[i][0] = dp[i-1][0] + 1 else: dp[i][0] = dp[i-1][0] for i in range(1,w): if s[0][i] != s[0][i-1]: dp[0][i] = dp[0][i-1] + 1 else: dp[0][i] = dp[0][i-1] for i in range(1,h): for j in range(1,w): if s[i][j] != s[i-1][j]: dp[i][j] = dp[i-1][j] + 1 else: dp[i][j] = dp[i-1][j] if s[i][j] != s[i][j-1]: dp[i][j] = min(dp[i][j-1] + 1,dp[i][j]) else: dp[i][j] = min(dp[i][j-1],dp[i][j]) print(ceil(dp[-1][-1]/2))
from typing import List, Dict INF = 10**9+1 def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(' '))) def solve() -> int: H, W = read_ints() S: List[str] = [] for _ in range(H): S.append(input().strip()) black_count = [[INF for _ in range(W)] for _ in range(H)] if S[0][0] == '.': black_count[0][0] = 0 else: black_count[0][0] = 1 for i in range(H): for j in range(W): if i == 0 and j == 0: continue if S[i][j] == '.': if i > 0: black_count[i][j] = min(black_count[i][j], black_count[i-1][j]) if j > 0: black_count[i][j] = min(black_count[i][j], black_count[i][j-1]) else: if i > 0: if S[i-1][j] == '.': black_count[i][j] = min(black_count[i][j], black_count[i-1][j]+1) else: black_count[i][j] = min(black_count[i][j], black_count[i-1][j]) if j > 0: if S[i][j-1] == '.': black_count[i][j] = min(black_count[i][j], black_count[i][j-1]+1) else: black_count[i][j] = min(black_count[i][j], black_count[i][j-1]) return black_count[H-1][W-1] if __name__ == '__main__': print(solve())
1
49,139,681,457,450
null
194
194
N = int(input()) s = list(input()) cnt = 0 for i in range(N-2): if s[i] == 'A': if s[i+1] == 'B': if s[i+2] == 'C': cnt += 1 print(cnt)
n = int(input()) s = input().replace('ABC','1') print(s.count('1'))
1
99,798,121,586,398
null
245
245
x1, y1, x2, y2 = (float(x) for x in input().split()) print("{:.7f}".format(((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5))
N = int(input()) # x の y 乗を d で割った余りを求める def powmod(x, y, d): ret = 1 for _ in range(1, y+1): ret = ret * x % d return ret ans = powmod(10, N, 10**9+7) - powmod(9, N, 10**9+7)*2 + powmod(8, N, 10**9+7) print(ans % (10**9+7))
0
null
1,644,431,268,700
29
78
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, m = map(int, readline().split()) if m % 2 == 0: rem = m for i in range(m // 2): print(i + 1, m + 1 - i) rem -= 1 if rem == 0: return for i in range(n): print(m + 2 + i, 2 * m + 1 - i) rem -= 1 if rem == 0: return else: rem = m for i in range((m - 1) // 2): print(i + 1, m - i) rem -= 1 if rem == 0: return for i in range(n): print(m + 1 + i, 2 * m + 1 - i) rem -= 1 if rem == 0: return if __name__ == '__main__': main()
N, M = [int(_) for _ in input().split()] l = 1 r = N ans = [] for _ in range(M - M // 2): ans += [l, r] l += 1 r -= 1 if (r - l) % 2 == (l + N - r) % 2: r -= 1 for _ in range(M // 2): ans += [l, r] l += 1 r -= 1 ans = ans[:2 * M] print('\n'.join(f'{a} {b}' for a, b in zip(ans[::2], ans[1::2])))
1
28,630,657,013,738
null
162
162
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")
n=int(input()) for i in range(n): p=list(map(int,input().split(" "))) p.sort() if pow(p[0],2) + pow(p[1],2) == pow(p[2],2): print('YES') else: print('NO')
1
218,916,352
null
4
4
N = int(input()) A = list(map(int, input().split())) Q = int(input()) M = list(map(int, input().split())) combinations = {} def create_combinations(idx, sum): combinations[sum] = 1 if idx >= N: return create_combinations(idx+1, sum) create_combinations(idx+1, sum+A[idx]) return create_combinations(0, 0) for target in M: if target in combinations.keys(): print("yes") else: print("no")
n = int(input()) A = list(map(int,input().split())) m = int(input()) B = list(input().split()) for i in range(m): B[i] = int(B[i]) def solve(x,y): if x==n: S[y] = 1 else: solve(x+1,y) if y+A[x] < 2001: solve(x+1,y+A[x]) S = [0 for i in range(2001)] solve(0,0) for i in range(m): if S[B[i]] == 1: print("yes") else: print("no")
1
101,967,752,952
null
25
25
N = int(input()) d = list(map(int, input().split())) sumd = sum(d) d_2 = sum([i * i for i in d]) print((sumd*sumd-d_2)//2)
def main(): import sys readline = sys.stdin.buffer.readline n = int(readline()) d = list(map(int, readline().split())) e = sum(d) ans = 0 for i in d: e -= i ans += i*e print(ans) if __name__ == '__main__': main()
1
168,637,307,198,812
null
292
292
a, b = map(int, input().split()) ab = str(a) * b ba = str(b) * a print(sorted([ab, ba])[0])
import numpy as np D = int(input()) c = np.array( list(map(int, input().split())) ) s = [[] for i in range(365+1)] for i in range(D): s[i] = np.array( list(map(int, input().split())) ) # last = np.array( [-1]*26 ) av = np.array( [0]*26 ) id = np.identity(4,dtype=int) v = 0 for d in range(D): av = s[d] - sum( c*(d-last) ) + c*(d-last) t = int(input()) t -= 1 last[t] = d v += av[t] print( v ) #
0
null
47,108,820,325,532
232
114
a,b,c=map(int, input().split()) 0<=a<=100,0<=b<=100,0<=c<=100, if a<b: if b<c: print('Yes') else: print('No') else: print('No')
def selectionSort(A, N): for i in range(N): minj = i for j in range(i, N): if A[j][1:] < A[minj][1:]: minj = j if i != minj: tmp = A[i] A[i] = A[minj] A[minj] = tmp return A def bubbleSort(A, N): for i in range(N): for j in range(N - 1, i, -1): if A[j][1:] < A[j - 1][1:]: tmp = A[j] A[j] = A[j - 1] A[j - 1] = tmp return A if __name__ == '__main__': n = int(input()) R = list(map(str, input().split())) C = R[:] SR = selectionSort(R, n) BR = bubbleSort(C, n) fStable = SR == BR print(" ".join(map(str, BR))) print("Stable") print(" ".join(map(str, SR))) if (fStable == True): print("Stable") else: print("Not stable")
0
null
214,350,199,488
39
16
a,b=input().split() ans=int(a)*round(float(b)*100)//100 print(int(ans))
H,N = map(int,input().split()) A = list(map(int,input().split())) All = sum(A) if H - All > 0: print("No") else: print("Yes")
0
null
46,956,572,313,898
135
226
a = input() b = input() print(b.count('ABC'))
class dice: men = [0] * 7 def __init__(self, li): self.men = [0] + li def move0(self, a, b, c, d): self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a] def move(self, h): if h == "N": self.move0(1, 2, 6, 5) elif h == "S": self.move0(1, 5, 6, 2) elif h == "W": self.move0(1, 3, 6, 4) elif h == "E": self.move0(1, 4, 6, 3) elif h == "O": self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2] elif h == "L": self.move0(2, 3, 5, 4) elif h == "R": self.move0(2, 4, 5, 3) elif h == "B": self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2] def move2(self, a, b): if self.men[1] != a: for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]: if self.men[i] == a: self.move(s) break if self.men[2] != b: if b == self.men[3]: self.move("L") elif b == self.men[4]: self.move("R") else: self.move("B") saikoro = dice(list(map(int, input().split()))) for _ in range(int(input())): saikoro.move2(*map(int, input().split())) print(saikoro.men[3])
0
null
49,919,227,193,768
245
34
N = int(input()) S = input() if len(S) % 2 == 0 : for i in range(len(S)//2) : if S[i] != S[i+len(S)//2] : print("No") exit() print("Yes") exit() print("No")
k=int(input()) a=7%k for i in range(k+1): if a==0: print(i+1) break a=(a*10+7)%k else: print(-1)
0
null
76,708,003,517,532
279
97
n=int(input()) a=[int(i) for i in input().split()] a.sort() prod=1 for i in a: prod*=i if prod>10**18: break if prod>10**18: print(-1) else: print(prod)
input();ans,a=1,[*map(int,input().split())] if 0 in a: print(0) else: for i in a: ans*=i if ans>10**18: print(-1);break else: print(ans)
1
16,189,566,975,088
null
134
134
from collections import deque from sys import stdin input = stdin.readline N, M = map(int, input().split()) graph = [[] for _ in range(N)] seen = [-1] * N for _ in range(M): a, b = map(int, input().split()) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) def bfs(x): q = deque([]) q.append(x) seen[x] = 1 while q: x = q.popleft() for y in graph[x]: if seen[y] != -1: continue seen[y] = 1 q.append(y) ans = 0 for i in range(N): if seen[i] != -1: continue else: ans += 1 bfs(i) print(ans - 1)
#Union Find #xの根を求める def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] #xとyの属する集合の併合 def unite(x,y): x = find(x) y = find(y) if x == y: return False else: #sizeの大きいほうがx if par[x] > par[y]: x,y = y,x par[x] += par[y] par[y] = x return True #xとyが同じ集合に属するかの判定 def same(x,y): return find(x) == find(y) #xが属する集合の個数 def size(x): return -par[find(x)] #初期化 #根なら-size,子なら親の頂点 n,m = map(int,input().split()) par = [-1]*n for i in range(m): a,b = map(int,input().split()) unite(a-1,b-1) ans = 0 for i in range(n): if par[i] < 0: ans += 1 print(ans-1)
1
2,279,110,468,610
null
70
70
H, N = map(int, input().split()) magic = [list(map(int, input().split())) for _ in range(N)] dp = [10**9 for _ in range(H+10**4+1)] dp[0] = 0 for a, b in magic: for j in range(H+1): if dp[j+a] > dp[j] + b: dp[j+a] = dp[j] + b print(min(dp[H:]))
# 雰囲気で書いたら通ってしまったがなんで通ったかわからん # i<jという前提を無視しているのではと感じる N = int(input()) A = list(map(int, input().split())) # i<jとして、条件は j-i = A_i + A_j # i + A_i = j - A_j dict1 = {} for i in range(1, N + 1): tmp = i + A[i - 1] if tmp not in dict1: dict1[tmp] = 1 else: dict1[tmp] += 1 dict2 = {} for i in range(1, N + 1): tmp = i - A[i - 1] if tmp not in dict2: dict2[tmp] = 1 else: dict2[tmp] += 1 # print(dict1, dict2) ans = 0 for k, v in dict1.items(): if k in dict2: ans += v * dict2[k] print(ans)
0
null
53,708,896,687,690
229
157
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input() cnt=[0 for _ in range(N)] score={'r':P,'s':R,'p':S} for i in range(N): if i<K: cnt[i]=score[T[i]] else: if T[i-K]!=T[i]: cnt[i]=score[T[i]] else: if cnt[i-K]==0: cnt[i]=score[T[i]] print(sum(cnt))
import sys n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort(reverse=True) l, r = -1, 10 ** 12 + 1 while r - l > 1: m = (l + r) // 2 cnt = 0 for i in range(n): cnt += max(0, a[i] - (m // f[i])) if cnt <= k: r = m else: l = m print(r)
0
null
135,741,033,391,700
251
290
import sys input = sys.stdin.readline def readstr(): return input().strip() def readint(): return int(input()) def readnums(): return map(int, input().split()) def readstrs(): return input().split() def main(): N = readint() X = readstr() s = sum(tuple(map(int, X))) s1 = s + 1 s2 = s - 1 if s != 1 else 1 m1 = int(X, 2) % s1 m2 = int(X, 2) % s2 t1 = [1] t2 = [1] for i in range(N): t1.append(t1[i] * 2 % s1) t2.append(t2[i] * 2 % s2) for i in range(N): ans = 0 if X[i] == '0': x = (m1 + t1[(N - i - 1)]) % s1 else: if s == 1: print(0) continue else: x = (m2 - t2[(N - i - 1)]) % s2 d = sum(tuple(map(int, bin(x)[2:]))) ans += 1 while x: x %= d d = sum(tuple(map(int, bin(x)[2:]))) ans += 1 print(ans) if __name__ == "__main__": main()
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N = I() X = SS() # 一回の操作でnはN以下になる # 2回目以降の操作はメモ化再帰 # 初回popcountは2種類しかない Xのpopcountから足し引きすればよい pc_X = X.count('1') if pc_X == 0: for i in range(N): print(1) elif pc_X == 1: for i in range(N): if i == X.index('1'): print(0) else: # 1が2つある場合、最後の位が1の場合、奇数 if i == N - 1 or X.index('1') == N - 1: print(2) else: print(1) else: next_X_m1 = 0 next_X_p1 = 0 pc_m1 = pc_X - 1 pc_p1 = pc_X + 1 for i in range(N): if X[i] == '1': next_X_m1 += pow(2, N - 1 - i, pc_m1) next_X_p1 += pow(2, N - 1 - i, pc_p1) dp = [-1] * N dp[0] = 0 def dfs(n): if dp[n] == -1: dp[n] = 1 + dfs(n % bin(n).count('1')) return dp[n] for i in range(N): next = 0 if X[i] == '0': next = (next_X_p1 + pow(2, N - 1 - i, pc_p1)) % pc_p1 else: next = (next_X_m1 - pow(2, N - 1 - i, pc_m1)) % pc_m1 ans = dfs(next) + 1 print(ans) # print(dp) if __name__ == '__main__': resolve()
1
8,250,757,054,848
null
107
107
n = int(input()) dict = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j"} dict2 = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10} #ans = [["a", 1]] #for i in range(n-1): # newans = [] # for lis in ans: # now = lis[0] # count = lis[1] # for j in range(1, count + 2): # newans.append([now + dict[j], max(j, count)]) # ans = newans #for lis in ans: # print(lis[0]) def dfs(s): if len(s) == n: print(s) return m = max(s) count = dict2[m] for i in range(1, count+2): dfs(s+dict[i]) dfs("a")
#!/usr/bin/env python # coding: utf-8 # In[8]: N = int(input()) mylist = [] for _ in range(N): x,l = map(int, input().split()) a = x-l b = x+l mylist.append([a,b]) # In[12]: mylist = sorted(mylist,key=lambda x:x[1]) cnt = 1 p = mylist[0][1] for i in range(1,N): if mylist[i][0] < p: continue else: cnt += 1 p = mylist[i][1] print(cnt) # In[ ]:
0
null
70,869,296,787,040
198
237
N = int(input()) A = list(map(int, input().split())) Q = int(input()) d = {} v = 0 ans = [] for a in A: d[a] = d.get(a, 0) + 1 v += a for i in range(Q): B, C = map(int, input().split()) v += d.get(B, 0) * (C - B) d[C] = d.get(C, 0) + d.get(B, 0) d[B] = 0 ans.append(v) for a in ans: print(a)
def solve(): N = int(input()) A = [int(i) for i in input().split()] counter = {} total = 0 for num in A: total += num counter[num] = counter.get(num, 0) + 1 Q = int(input()) for i in range(Q): B,C = [int(i) for i in input().split()] if B in counter: B_cnt = counter[B] counter[C] = counter.get(C, 0) + B_cnt total += (C-B) * B_cnt counter[B] = 0 print(total) if __name__ == "__main__": solve()
1
12,279,134,011,484
null
122
122
import collections n = int(input()) graph = [tuple(map(int, input().split())) for _ in range(n - 1)] tree = [[] for _ in range(n)] deg = [0] * n color = {} for a, b in graph: a, b = min(a - 1, b - 1), max(a - 1, b - 1) deg[a] += 1 deg[b] += 1 tree[a].append(b) tree[b].append(a) color[(a, b)] = 0 color_max = max(deg) print(color_max) c = [0] * n c[0] = -1 que = collections.deque([0]) while len(que) != 0: i = que.popleft() tmp = 1 for j in tree[i]: if c[j] != 0: continue a, b = min(i, j), max(i, j) if tmp == c[i]: tmp += 1 color[(a, b)] = tmp c[j] = tmp que.append(j) tmp += 1 for a, b in graph: a, b = min(a - 1, b - 1), max(a - 1, b - 1) print(color[(a, b)])
s = input() if s in ['hi','hihi','hihihi','hihihihi','hihihihihi']: print('Yes') else: print('No')
0
null
94,506,550,501,000
272
199
arr = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] n = int(input()) for _ in range(n): b, f, r, v = map(int, input().split()) arr[b-1][f-1][r-1] += v for b in range(4): for f in range(3): print(' '+' '.join(str(x) for x in arr[b][f])) if(b < 3): print('#' * 20)
def main(): N, M = map(int, input().split()) if N == M: return "Yes" return "No" if __name__ == '__main__': print(main())
0
null
42,310,814,124,392
55
231
[r,c] = map(int, input().split()) mat = [list(map(int, input().split())) for i in range(r)] for i in range(r): mat[i].append(sum(mat[i])) r_sum = [] for j in range(c+1): r_sum.append(sum([mat[i][j] for i in range(r)])) for i in range(r): print(" ".join(list(map(str, mat[i])))) print(" ".join(list(map(str, r_sum))))
import sys import math r, c = map(int, raw_input().split()) b = [0 for i in xrange(c+1)] for i in xrange(r): a = map(int, raw_input().split()) for j in xrange(c): b[j] += a[j] sys.stdout.write(str(a[j]) + " ") print sum(a) b[c] += sum(a) for j in xrange(c+1): sys.stdout.write(str(b[j])) if j < c: sys.stdout.write(" ") print
1
1,362,019,224,608
null
59
59
def main(): import sys import math input = sys.stdin.buffer.readline n = int(input()) A = list(map(int, input().split())) ans = 0 node = 1 max_node = sum(A) for i in range(n+1): ans += node max_node -= A[i] node = min(max_node,(node-A[i])*2) if node < 0: print(-1) exit(0) print(ans) if __name__ == '__main__': main()
N,K = map(int,input().split()) R,S,P = map(int,input().split()) T = input() ans = 0 memo = [0 for i in range(N)] for i in range(N): check = T[i] if i >= K and T[i-K] == check and memo[i-K] == 0: memo[i] = 1 continue if check == "r": ans += P elif check == "p": ans += S elif check == "s": ans += R print(ans)
0
null
62,632,232,579,612
141
251
N = int(input()) S = input().split("ABC") print(len(S)-1)
a = int(input()) b = int(input()) l = {1, 2, 3} m = {a, b} ans = list(l ^ m) print(ans[0])
0
null
105,369,285,075,716
245
254
s=input() times=int(input()) for _ in range(times): order=input().split() a=int(order[1]) b=int(order[2]) if order[0]=="print": print(s[a:b+1]) elif order[0]=="reverse": s=s[:a]+s[a:b+1][::-1]+s[b+1:] else : s=s[:a]+order[3]+s[b+1:]
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) K,X=nm() print('Yes' if X<=500*K else 'No')
0
null
49,976,091,668,124
68
244
X,Y,Z=map(int,input().split()) print(str(Z)+' '+str(X)+' '+str(Y))
a=input() a=a.split() a=(a[2],a[0],a[1]) print(*a)
1
38,312,655,935,868
null
178
178
for i in range(int(input())): a,b,c=map(lambda x:int(x)**2,input().split()) if a+b==c or b+c==a or c+a==b: print("YES") else: print("NO")
from sys import stdin #n = int(stdin.readline().rstrip()) #l = list(map(int, stdin.readline().rstrip().split())) a,b,c = map(int, stdin.readline().rstrip().split()) #S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに import math if c-a-b>0 and 4*a*b<(c-a-b)**2: print('Yes') else: print("No")
0
null
25,722,221,880,348
4
197
N, K= map(int, input().strip().split()) p = list(map(int, input().strip().split())) p=sorted(p) q=0 for i in range(K): q=q+p[i] print(q)
def selection_sort(seq): l = len(seq) cnt = 0 for i in range(l): mi = i for j in range(i+1, l): if seq[j] < seq[mi]: mi = j if i is not mi: seq[i], seq[mi] = seq[mi], seq[i] cnt += 1 return seq, cnt n = int(input()) a = list(map(int, input().split())) sorted_a, num_swap = selection_sort(a) print(' '.join(map(str, sorted_a))) print(num_swap)
0
null
5,771,022,241,010
120
15
from collections import defaultdict n, k = map(int, input().split()) a = list(map(int, input().split())) d = defaultdict(int) sa = [0] * (n + 1) d[0] = 1 if k == 1: print(0) exit() for i in range(n): sa[i + 1] = sa[i] + a[i] sa[i + 1] %= k ans = 0 for i in range(1, n + 1): v = sa[i] - i v %= k ans += d[v] d[v] += 1 if 0 <= i - k + 1: vv = sa[i - k + 1] - (i - k + 1) vv %= k d[vv] -= 1 print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) X = [0 for _ in range(N)] D = {0: [-1]} E = {0: 1} X[0] = (A[0] - 1) % K if X[0] in D: D[X[0]].append(0) E[X[0]] += 1 else: D[X[0]] = [0] E[X[0]] = 1 for i in range(1, N): X[i] = (X[i-1] + A[i] - 1) % K if X[i] in D: D[X[i]].append(i) E[X[i]] += 1 else: D[X[i]] = [i] E[X[i]] = 1 S = 0 for i in D: n = E[i] if n > 1: L = D[i][:] m = L[-1] for j in range(n-1): x = L[j] if m - x < K: S += n - 1 - j else: l, r = j, n d = (l + r) // 2 tmp = 2 * n while tmp != 0: if L[d] - x <= K - 1: l = d d = (l + r) // 2 else: r = d d = (l + r) // 2 tmp //= 2 S += d - j print(S)
1
137,408,757,022,642
null
273
273
def main(): N = int(input()) L = [int(l) for l in input().split(" ")] L.sort() m = len(L) cnt = 0 for i in range(m): k = m - 1 for j in range(i + 1, m): while m + i - j < k: if L[m + i - j] + L[i] <= L[k]: k -= 1 else: cnt += k - m - i + j break print(cnt) main()
inp = input().split() A = int(inp[0]) B = int(inp[1].replace('.','')) print(A*B//100)
0
null
94,092,000,629,482
294
135
n,k = map(int,input().split()) P = 10**9+7 ans = 1 nCl = 1 n1Cl = 1 for l in range(1,min(k+1,n)): nCl = nCl*(n+1-l)*pow(l,P-2,P)%P n1Cl = n1Cl*(n-l)*pow(l,P-2,P)%P ans = (ans+nCl*n1Cl)%P print(ans)
N ,K = map(int, input().split()) MOD = 10**9 + 7 ans = 0 S = [0]*(2*10**5+1) S[1] = 1 for i in range(2, 2*10**5+1): S[i] = S[MOD%i]*(MOD-int(MOD/i))%MOD if N-1 <= K: ans = 1 num = 2*N - 1 for i in range(N-1): ans *= (num-i)*S[i+1] ans %= MOD print(ans%MOD) else: S1 = [1]*N S2 = [1]*N for i in range(1, N): S1[i] = (S1[i-1]*(N+1-i)*S[i])%MOD S2[i] = (S2[i-1]*(N-i)*S[i])%MOD ans = 0 for i in range(K+1): ans += S1[i]*S2[N-1-i] ans %= MOD print(ans) # nCm * n-mHm # nCm * n-1Cn-m-1
1
67,140,637,925,262
null
215
215
for i in range(int(input())): a,b,c = map(int, input().split()) if a**2 + b**2 == c**2 or a**2+c**2 == b**2 or b**2+c**2 == a**2: print("YES") else: print("NO")
for i in range(int(input())): temp = [int(x) for x in input().split()] stemp = sorted(temp) if stemp[2]**2 == stemp[1]**2 + stemp[0]**2: print('YES') else: print('NO')
1
304,768,920
null
4
4
from collections import Counter N,MOD=map(int,input().split()) S=input() res=0 if MOD==2 or MOD==5: for i in range(N): if(int(S[N-i-1])%MOD==0): res+=N-i else: Cum=[0]*(N+1) for i in range(N): Cum[i+1]=(Cum[i]+int(S[N-i-1])*pow(10,i,MOD))%MOD c=Counter(Cum).most_common() for a,b in c: res+=b*(b-1)//2 print(res)
# -*- coding: utf-8 -*- import sys from collections import defaultdict N,P=map(int, sys.stdin.readline().split()) S=sys.stdin.readline().strip() if P in (2,5): ans=0 for i,x in enumerate(S): if int(x)%P==0: ans+=i+1 print ans else: L=[int(S)%P] for i,x in enumerate(S): L.append((L[-1]-int(x)*pow(10,N-1-i,P))%P) ans=0 D=defaultdict(lambda: 0) for i in range(N,-1,-1): x=L[i] ans+=D[x] D[x]+=1 print ans
1
58,050,041,863,008
null
205
205
#http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_4_A #?????¢??¢?´¢ #???????????§?¨????????????????????????¨?????§??????????????\???????????????????????????????????? def linear_search(list_1, list_2): count = 0 for a in list_1: i = 0 list_2.append(a) while not a == list_2[i]: i += 1 if not i == len(list_2) - 1: count += 1 list_2 = list_2[:-1] return count def main(): n_listA = int(input()) a = list(set([n for n in input().split()])) n_listB = int(input()) b = list(set([n for n in input().split()])) print(linear_search(a,b)) if __name__ == "__main__": main()
input() s = set(map(int,input().split())) n = int(input()) t = tuple(map(int,input().split())) c = 0 for i in range(n): if t[i] in s: c += 1 print(c)
1
64,745,422,012
null
22
22
from bisect import * n,m,k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) # Aの累積和を保存しておく # 各Aの要素について、Bが何冊読めるか二分探索する。 # 計算量: AlogB A.insert(0, 0) for i in range(1,len(A)): A[i] += A[i-1] for i in range(1, len(B)): B[i] += B[i-1] ans = 0 for i in range(len(A)): rest_time = k - A[i] if rest_time >= 0: numb = bisect_right(B, rest_time) anstmp = i + numb ans = max(ans, anstmp) print(ans)
input_int = input() input_str = input() K = int(input_int) S = str(input_str) if len(S)<=K: print(S) elif len(S)>K: print(S[:K]+'...')
0
null
15,194,108,975,420
117
143
N, K = map(int, input().split()) vec = [0] * N for _ in range(K): d = int(input()) A = list(map(int, input().split())) for i in range(d): vec[A[i]-1] += 1 print(vec.count(0))
import math import numpy as np import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # MOD = 998244353 N,K = LI() s = set() for i in range(K): _ = I() s.update(LI()) print(N-len(s))
1
24,458,075,685,500
null
154
154
x = input() x = int(x) num = 1 while x: print("Case {0}: {1}".format(num, x)) x = input() x = int(x) num += 1
count = 1 while(True): x = int(input()) if x == 0: break print('Case {}: {}'.format(count, x)) count += 1
1
473,206,594,010
null
42
42
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) d = abs(a-b) s = v-w if s <= 0: print("NO"); exit() print("YES" if d <= t * s else "NO")
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce, lru_cache import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) n = INT() k = INT() @lru_cache(None) def F(n, k): # n以下で0でないものがちょうどk個ある数字の個数 if n < 10: if k == 0: return 1 if k == 1: return n return 0 q, r = divmod(n, 10) ret = 0 if k >= 1: ret += F(q, k-1) * r ret += F(q-1, k-1) * (9-r) ret += F(q, k) return ret print(F(n, k))
0
null
45,626,312,350,518
131
224
from collections import Counter, defaultdict # 拡張ユークリッド互除法 # ax + by = gcd(a,b)の最小整数解を返す def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) # mを法とするaの乗法的逆元 def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m # 素因数分解 def prime_factors(n): i = 2 while i * i <= n: if n % i: i += 1 else: n //= i yield i if n > 1: yield n # mを法とするときのa^n def modpow(a,n,m): res = 1 t = a while n: if n%2: res = (res*t)%m t = (t*t)%m n //= 2 return res def lcm_mod(nums, mod): p = defaultdict(int) for n in nums: c = Counter(prime_factors(n)) for v,cnt in c.items(): p[v] = max(p[v],cnt) res = 1 for v,cnt in p.items(): res *= modpow(v,cnt,mod) res %= mod return res MOD = 10**9+7 N = int(input()) A = list(map(int,input().split())) s = sum(modinv(a,MOD) for a in A)%MOD s *= lcm_mod(A, MOD) print(s%MOD)
N = int(input()) A = list(map(int, input().split())) MOD = 10**9+7 def gcd(x, y): while(x % y != 0 and y % x != 0): if(x > y): x = x % y else: y = y % x if(x > y): return y else: return x def lcm(x, y, MOD): return x * y // gcd(x, y) X = 1 ans = 0 for i in range(N): X = lcm(X, A[i], MOD) for i in range(N): ans = (ans + X*pow(A[i], MOD-2, MOD))%MOD print(ans)
1
87,273,031,015,168
null
235
235
n = int(input()) arr = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) result = set() for i in range(2**n): tmp = 0 for j in range(n): if i >> j & 1: tmp += arr[j] result.add(tmp) for x in m: print("yes" if x in result else "no")
n = input() A = map(int, raw_input().split()) q = input() M = map(int, raw_input().split()) def solve(i, m): if m == 0: return True if n <= i or sum(A) < m: return False x = (solve(i+1, m) or solve(i+1, m-A[i])) return x for m in M: if solve(0, m): print "yes" else: print "no"
1
100,211,634,432
null
25
25
#!/usr/bin/env python n, k = map(int, input().split()) mod = 10**9+7 d = [-1 for _ in range(k+1)] d[k] = 1 for i in range(k-1, 0, -1): d[i] = pow(k//i, n, mod) j = 2*i while j <= k: d[i] -= d[j] j += i #print('d =', d) ans = 0 for i in range(1, k+1): ans += (i*d[i])%mod print(ans%mod)
r=int(input()) print(r*6.28318530717958623200)
0
null
34,304,091,611,310
176
167
n = int(input()) sum = 0 for i in range(1, n+1): if((i % 3 * i % 5 * i % 15) != 0): sum += i print(sum)
try: s = '' while True: s = s + input().lower() except EOFError: [print(chr(o)+' : '+str(s.count(chr(o)))) for o in range(ord('a'),ord('z')+1)]
0
null
18,418,034,696,750
173
63
n,k=map(int,input().split()) fact=[1] for i in range(1,2*n): fact.append((fact[i-1]*(i+1))%(10**9+7)) factinv=[] for i in range(n): factinv.append(pow(fact[i],10**9+5,10**9+7)) if k==1: print((n*(n-1))%(10**9+7)) elif k>=n-1: print((fact[2*n-2]*factinv[n-1]*factinv[n-2])%(10**9+7)) else: ans=1 for i in range (k): ans=(ans+fact[n-1]*factinv[i]*factinv[n-i-2]*fact[n-2]*factinv[i]*factinv[n-i-3])%(10**9+7) print(ans)
n, k = map(int, input().split()) mod = 10 ** 9 + 7 class ModInt: def __init__(self, num, mod): self.num = num self.mod = mod def __str__(self): return str(self.num) def __repr__(self): return "ModInt(num: {}, mod: {}".format(self.num, self.mod) def __add__(self, other): ret = self.num + other.num ret %= self.mod return ModInt(ret, self.mod) def __sub__(self, other): ret = self.num - other.num ret %= self.mod return ModInt(ret, self.mod) def __mul__(self, other): ret = self.num * other.num ret %= self.mod return ModInt(ret, self.mod) def pow(self, times): pw = pow(self.num, times, self.mod) return ModInt(pw, self.mod) def inverse(self): return self.pow(self.mod - 2) def __truediv__(self, other): num = self * other.inverse() return ModInt(num, self.mod) class Combination: def __init__(self, n, mod): self.mod = mod self.fact = [ModInt(1, mod)] self.inverse = [ModInt(1, mod)] for i in range(1, n + 1): self.fact.append(self.fact[-1] * ModInt(i, mod)) self.inverse.append(self.inverse[-1] * ModInt(i, mod).inverse()) def comb(self, n, k): if k < 0 or n < k: return ModInt(0, self.mod) return self.fact[n] * self.inverse[k] * self.inverse[n-k] mx = min(k, n - 1) comb = Combination(n, mod) ans = ModInt(0, mod) for i in range(mx + 1): ans += comb.comb(n, i) * comb.comb(n - 1, i) print(ans)
1
67,090,795,123,228
null
215
215
n,k = map(int, input().split()) scores = list(map(int, input().split())) for i in range(k, n): a = scores[i] b = scores[i-k] if a > b: print('Yes') else: print('No')
n, k = map(int, input().split()) *a, = map(int, input().split()) for i, j in zip(a, a[k:]): print('Yes' if i < j else 'No')
1
7,154,059,803,790
null
102
102
import sys for line in sys.stdin: l = line.replace('\n', '') a, b = l.split() a = int(a) b = int(b) print(len(str(a+b)))
def resolve(): s, t = input().split() a, b = list(map(int, input().split())) u = input() if u == s: a -= 1 elif u == t: b -= 1 print(a, b) resolve()
0
null
35,871,730,584,438
3
220
import sys input = sys.stdin.readline import math big = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) num = A[0] for i in range(1, N): num = num * A[i] // math.gcd(num, A[i]) res = 0 for a in A: res += num // a print(res % big)
#!/usr/bin/env python3 from fractions import gcd n = int(input()) a = list(map(int, input().split())) MOD = 10 ** 9 + 7 l = 1 for x in a: l = l * x // gcd(l, x) ans = sum(l // x for x in a) % MOD print(ans)
1
87,694,008,556,700
null
235
235
n = input() l = input().split() for a in l: a = int(a) x = list() for i in (reversed(l)): x.append(i) x = ' '.join(x) print(x)
N,S = map(int,input().split()) A = list(map(int,input().split())) MOD = 998244353 dp = [0 for _ in range(S+1)] #i個目までの和がjの数となるのは何通りあるかdp[i][j] dp[0] = 1 #dp = [0 if i==0 else INF for i in range(S + 1)] for i in range(N): #i個目まで見て。 p = [0 for _ in range(S+1)] p,dp = dp,p for j in range(S+1): dp[j] = (dp[j]+p[j]*2)%MOD if j >= A[i]: #print(j,A[i],p[j-A[i]]) dp[j] += p[j-A[i]] #print(dp) ans = dp[S]%MOD print(ans)
0
null
9,387,299,222,972
53
138
import math r = input() area = r * r * math.pi * 1.0 cir = 2 * r * math.pi * 1.0 print '%f %f' % (area, cir)
r=float(raw_input()) p=float(3.14159265358979323846264338327950288) s=p*r**2.0 l=2.0*p*r print"%.5f %.5f"%(float(s),float(l))
1
650,499,790,018
null
46
46
from itertools import combinations n=int(input()) a=list(map(int,input().split())) q=int(input()) m=list(map(int,input().split())) s=set() for i in range(1,n+1): for j in combinations(a,i): s.add(sum(j)) for i in m: if i in s: print("yes") else: print("no")
def solve_knapsack_problem(A,n,m): a=[[0 for i in range(m+1)]for j in range(n+1)] for i in range(1,n+1): for j in range(1,m+1): if A[i-1]<=j: a[i][j] = max(a[i-1][j-A[i-1]]+A[i-1],a[i-1][j]) else: a[i][j] = a[i-1][j] if a[i][j] == m: return True return False if __name__ == "__main__": n=int(input()) A=list(map(int,input().split())) q=int(input()) m=list(map(int,input().split())) result=[] for i in range(q): if solve_knapsack_problem(A,n,m[i]): print("yes") else: print("no")
1
100,836,662,092
null
25
25
a,b=map(int,input().split()) ans=a-b*2 if a<=b*2: ans=0 print(ans)
import itertools,sys def S(): return sys.stdin.readline().rstrip() def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) H,W = LI() S = [S() for _ in range(H)] dp = [[float('INF')]*W for _ in range(H)] for i,j in itertools.product(range(H),range(W)): if i==0: if j==0: dp[i][j] = 1 if S[i][j]=='#' else 0 else: dp[i][j] = dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0) else: if i==0: dp[i][j] = dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0) else: dp[i][j] = min(dp[i][j],dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0)) dp[i][j] = min(dp[i][j],dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0)) print(dp[-1][-1])
0
null
107,633,718,171,460
291
194
a,b = map(int, input().split()) def gcd(x, y): if y < x: x,y = y,x while x%y != 0: x,y = y,x%y return y def lcm(x, y): return (x*y)//gcd(x,y) print(lcm(a,b))
X,K,D = map(int,input().split()) y = abs(X)//D if K<=y: print(abs(abs(X)-K*D)) else : a = (abs(X)-y*D) b = (abs(X)-(y+1)*D) C = abs(a) D = abs(b) if (K-y)%2==0: print(C) else: print(D) #print(y+1) #print(1000000000000000)
0
null
59,202,539,269,920
256
92
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 998244353 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): N, S = LI() a = LI() dp = [[0 for _ in range(S+1)] for _ in range(N+1)] for i in range(1, N+1): dp[i][0] = dp[i-1][0] * 2 + 1 dp[i][0] %= mod for i in range(N): for j in range(1, S+1): if j - a[i] >= 0: dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod) else: dp[i+1][j] = dp[i][j] * 2 % mod if j == a[i]: dp[i+1][j] += 1 dp[i+1][j] %= mod print(dp[N][S]) main()
import sys def gcd(a, b): return gcd(b, a%b) if b else a def lcm(a, b): return a // gcd(a, b) * b def f(n): res = 0 while not n % 2: n //= 2 res += 1 return res N, M = list(map(int, input().split())) A = list(map(int, input().split())) for i in range(N): A[i] //= 2 t = f(A[0]) A[0] >> t M >> t for i in range(1, N): if f(A[i]) != t: print(0) sys.exit() A[i] >> t l = 1 for a in A: l = lcm(l, a) if l > M: print(0) sys.exit() M /= l print(int((M+1)/2))
0
null
59,786,544,226,752
138
247
#coding:utf-8 m = 0 f = 0 r = 0 while m + f + r >-3: m , f, r =[int(i) for i in input().rstrip().split(" ")] if m+f+r == -3: break if m == -1: print("F") elif f == -1: print("F") elif m+f <30: print("F") elif m+f <50: if r>=50: print("C") else: print("D") elif m+f <65: print("C") elif m+f <80: print("B") else: print("A")
while True: m, t, f = map( int, raw_input().split()) if m == -1 and t == -1 and f == -1: break if m == -1 or t == -1: r = "F" elif (m + t) >= 80: r = "A" elif (m + t) >= 65: r = "B" elif (m + t) >= 50: r = "C" elif (m + t) >= 30: if f >= 50: r = "C" else: r = "D" else: r = "F" print r
1
1,242,834,197,898
null
57
57
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline INF = float('inf') def main(): s = map(int, input()[::-1]) mod = 2019 counts = [0] * mod counts[0] = 1 t = 0 x = 1 for num in s: t = (t + num * x) % mod counts[t] += 1 x = (x * 10) % mod ans = 0 for count in counts: if count > 1: ans += count * (count - 1) // 2 print(ans) if __name__ == '__main__': main()
from collections import Counter s = input() ls = len(s) t = [0] j = 1 for i in range(ls): u = (int(s[ls-1-i])*j + t[-1]) % 2019 t.append(u) j = (j * 10) % 2019 c = Counter(t) k = list(c.keys()) ans = 0 for i in k: ans += c[i]*(c[i]-1)/2 print(int(ans))
1
30,668,664,322,072
null
166
166
x = int(input()) count = 0 for i in range(x+1): if i % 3 != 0 and i % 5 != 0: count += i print(count)
ary = list(filter(lambda x: int(x) % 3 != 0 and int(x) % 5 != 0, list(range(int(input()) + 1)))) print(sum(ary))
1
34,992,185,883,498
null
173
173
n = int(input()) data = [input().split() for i in range(n)] for i in range(n - 2): if int(data[i][0]) == int(data[i][1]) and int(data[i + 1][0]) == int(data[i+1][1]) and int(data[i+2][0]) == int(data[i+2][1]): print('Yes') break else: print('No')
MOD = 10 ** 9 + 7 INF = 10 ** 20 import sys input = sys.stdin.readline sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n = int(input()) a = list(map(int,input().split())) if n%2 == 0: ans1 = 0 ans2 = 0 for i in range(n): if i%2 == 0: ans1 += a[i] else: ans2 += a[i] ans = max(ans1,ans2) cuml = [0] * (n + 1) cumr = [0] * (n + 1) for i in range(n): if i == 0: cuml[i + 1] = a[i] else: cuml[i + 1] = cuml[i - 1] + a[i] for i in range(n - 1,-1,-1): if i == n - 1: cumr[i] = a[i] else: cumr[i] = cumr[i + 2] + a[i] for i in range(1,n - 2,2): ans = max(ans,cuml[i] + cumr[i + 2]) else: cuml = [0] * (n + 1) cumr = [0] * (n + 1) cumr2 = [0] * (n + 1) for i in range(n): if i == 0: cuml[i + 1] = a[i] else: cuml[i + 1] = cuml[i - 1] + a[i] for i in range(n - 1,-1,-1): if i == n - 1: cumr[i] = a[i] cumr2[i] = a[i] else: cumr[i] = cumr[i + 2] + a[i] if i%2 == 1: if i == n - 2: continue if i == n - 4: cumr2[i] = cumr2[i + 3] + a[i] else: cumr2[i] = max(cumr2[i + 2],cumr[i + 3]) + a[i] cumr.append(0) ans = -INF for i in range(n): ans = max(ans,cuml[i] + cumr[i + 2]) if i <= n - 6 and i%2 == 1: ans = max(ans,cuml[i] + cumr2[i + 2]) if i <= n - 4 and i%2 == 1: ans = max(ans,cuml[i] + cumr[i + 3]) print(ans) if __name__ =='__main__': main()
0
null
19,827,230,105,408
72
177
import sys a = list(map(int,input().split())) b = list(map(int,input().split())) t = int(input()) if a[1] <= b[1]: print('NO') sys.exit() elif abs(a[0]-b[0])/abs(a[1]-b[1]) <= t: print('YES') sys.exit() else: print('NO')
a,v,b,w,t=map(int,open(0).read().split()) print('YNEOS'[abs(b-a)>(v-w)*t::2])
1
15,105,811,721,760
null
131
131
# -*- coding: utf-8 -*- X = int(input()) # A**5 - (A-1)**5 = X = 10**9(Xの最大) となるAが # Aの最大値となる(それ以上Aが大きくなると、Xは上限値を超える) # → 最大となるAは120 for A in range(-120, 120 + 1): for B in range(-120, 120): if A**5 - B**5 == X: print("{} {}".format(A, B)) exit()
ans = [] for i, x in enumerate(open(0).readlines()): ans.append("Case %d: %s" % (i+1, x)) open(1,'w').writelines(ans[:-1])
0
null
12,987,043,658,832
156
42
a,b=input().split() a=int(a) b=int(b) if a*500>=b: print("Yes") else: print("No")
K,X = map(int, open(0).read().split()) if 500 * K >= X: print('Yes') else: print('No')
1
98,108,745,334,460
null
244
244
import itertools def main(): N = int(input()) n_x_y = {} for n in range(N): A = int(input()) x_y = {} for _ in range(A): x, y = map(int, input().split()) x_y[x-1] = y n_x_y[n] = x_y ans = 0 for flags in itertools.product([1, 0], repeat=N): sat = True for n, flag in enumerate(flags): if flag == 0: continue for x, y in n_x_y[n].items(): if (y == 1 and flags[x] == 0) or (y == 0 and flags[x] == 1): sat = False break if sat is False: break if sat is True and sum(flags) > ans: ans = sum(flags) print(ans) if __name__ == '__main__': main()
N = int(input()) xyss = [[] for _ in range(N)] for i in range(N): A = int(input()) for _ in range(A): x, y = map(int, input().split()) xyss[i].append((x-1, y)) ans = 0 for ptn in range(1<<N): conflict = False for i in range(N): if (ptn>>i) & 1: for x, y in xyss[i]: if (ptn>>x) & 1 != y: conflict = True break if conflict: break else: num1 = bin(ptn).count('1') if num1 > ans: ans = num1 print(ans)
1
121,629,612,954,850
null
262
262
num = (1,0,0) for _ in range(int(input()) - 2): num = (num[1],num[2],num[0]+num[2]) print(num[2]%(10**9+7))
N = input() A_ls = map(int, input().split(' ')) A_ls = [i for i in A_ls if i % 2 == 0] ls = [i for i in A_ls if i % 3 == 0 or i % 5 == 0] if len(A_ls) == len(ls): print('APPROVED') else: print('DENIED')
0
null
36,320,190,475,010
79
217
def exhaustiveSearch(A:list, m:int) -> str: if m == 0: return True if len(A) == 0 or sum(A) < m: return False return exhaustiveSearch(A[1:], m) or exhaustiveSearch(A[1:], m - A[0]) if __name__ == '__main__': n = int(input()) A = list(map(int, input().rstrip().split())) q = int(input()) M = list(map(int, input().rstrip().split())) for m in M: if exhaustiveSearch(A, m): print('yes') else: print('no')
N = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) k = 2**N totallist = [0]*k for b in range(k): total = 0 for i in range(N): if b >> i & 1 == 1: total += A[i] totallist[b] = total for m in M: print('yes') if m in totallist else print('no')
1
102,512,993,870
null
25
25
n = int(input()) #a, b = map(int, input().split()) #l = list(map(int, input().split())) s = input() ans = 1 last = s[0] for i in range(1,n): if last != s[i]: last = s[i] ans = ans + 1 print(ans)
def main(): sectionalview = input() stack = [] a_surface = 0 surfaces = [] for cindex in range(len(sectionalview)): if sectionalview[cindex] == "\\": stack.append(cindex) elif sectionalview[cindex] == "/" and 0 < len(stack): if 0 < len(stack): left_index = stack.pop() a = cindex - left_index a_surface += a while 0 < len(surfaces): if left_index < surfaces[-1][0]: a += surfaces.pop()[1] else: break surfaces.append((cindex, a)) t = [i[1] for i in surfaces] print(sum(t)) print(" ".join(map(str, [len(t)] + t))) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
0
null
84,703,078,804,070
293
21
#!/usr/bin/env python3 def main(): n = int(input()) s, t = input().split() print(*[s[i] + t[i] for i in range(n)], sep="") if __name__ == "__main__": main()
import sys input = sys.stdin.readline n = int(input()) s, t = list(map(list, input().split())) a = "" for i in range(n): a += s[i] a += t[i] print(a)
1
112,500,291,961,528
null
255
255
import numpy as np def main(A, B, V, W, T): if abs(B-A) <= T*(V-W): return "YES" return "NO" A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) print(main(A, B, V, W, T))
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if a <= b: print("YES" if a + v * t >= b + w * t else "NO") else: print("YES" if b - w * t >= a - v * t else "NO")
1
15,006,182,282,618
null
131
131
import sys read = sys.stdin.buffer.read def main(): N, D, A, *XH = map(int, read().split()) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() X = [x for x, h in monster] S = [0] * (N + 1) idx = 0 ans = 0 for i, (x, h) in enumerate(monster): d = h - S[i] if d > 0: right = x + 2 * D while idx < N and X[idx] <= right: idx += 1 S[i] += d S[idx] -= d ans += d S[i + 1] += S[i] print(ans) return if __name__ == '__main__': main()
import sys input = sys.stdin.readline import bisect import collections from collections import deque n,d,a= map(int, input().split()) x= [list(map(int, input().split())) for i in range(n)] x.sort() y=[] for i in range(n): y.append(x[i][0]) x[i][1]=-(-x[i][1]//a) # どのモンスターまで倒したか管理しながら進める。 # 累積ダメージを管理 qq=deque([]) ans=0 atk=0 for i in range(n): w=x[i][1] # iがダメージの有効期限を超過している場合 while len(qq)>0 and i > qq[0][0]: atk-=qq[0][1] qq.popleft() if w-atk>0: ans+=w-atk q=bisect.bisect_right(y,x[i][0]+2*d)-1 # 有効期限 ダメージ qq.append([q,w-atk]) atk += w - atk print(ans)
1
82,077,274,885,250
null
230
230
if __name__ == "__main__": T = input() ans = T ans = ans.replace("P?", 'PD') ans = ans.replace("??", 'PD') ans = ans.replace("?D", 'PD') ans = ans.replace("?", 'D') print(ans)
import sys def main(): for line in iter(sys.stdin.readline, ""): #print (line) a = line.rstrip("\n") tmp = a.split(" ") a = int(tmp[0]) b = int(tmp[1]) n = int(tmp[2]) cnt = 0 for i in range(1, n+1): if (n % i == 0) and (a <= i and i <= b): cnt = cnt + 1 #print (i) print (cnt) if __name__ == "__main__": main()
0
null
9,529,889,771,890
140
44
li1 = [] li2 = [] for i, s in enumerate(input()): if s == "\\": li1.append(i) elif s == "/" and li1: j = li1.pop() c = i - j while li2 and li2[-1][0] > j: c += li2[-1][1] li2.pop() li2.append((j, c)) if li2: li3 = list(zip(*li2))[1] print(sum(li3)) print(len(li3), *li3) else: print(0, 0, sep="\n")
def main(): n = int(input()) ans = n * (n + 1) - 1 # 1とk 自信 i = 2 while i * i <= n: num = n // i min_i = i * i max_i = i * num ans += (num - i + 1) * (min_i + max_i) # 自分自身 ans -= min_i i += 1 print(ans) if __name__ == "__main__": main()
0
null
5,544,792,785,272
21
118
#!/usr/bin/python3 # -*- coding:utf-8 -*- from math import factorial def main(): s = list(map(int, input().strip())) k = int(input()) dp = [] dp.append([[0]*(len(s)+1) for _ in range(k+1)]) dp.append([[0]*(len(s)+1) for _ in range(k+1)]) dp[0][0][0] = 1 for i, c in enumerate(s): for j in range(k+1): for d in range(10): nj = j if d != 0: nj+=1 if nj > k: continue if d < c: dp[1][nj][i+1] += dp[0][j][i] if d == c: dp[0][nj][i+1] += dp[0][j][i] dp[1][nj][i+1] += dp[1][j][i] print(dp[0][k][len(s)]+dp[1][k][len(s)]) if __name__=='__main__': main()
# from collections import defaultdict import math def comb(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) N = int(input()) K = int(input()) keta = len(str(N)) dp = [[0]*(keta) for i in range(4)] ans = 0 for k in range(1, 4): for i in range(1, keta): if i<k: continue else: dp[k][i] = comb(i-1, i-k)*(9**k) #print(dp) # dp[k][i]: i桁で、k個の0でない数 ans += sum(dp[K]) # (N の桁)-1 までの累積和 count = 0 for j in range(keta): t = int(str(N)[j]) if j==0: count+=1 ans += sum(dp[K-count])*(t-1) if count == K: # K==1 ans+=t break continue elif j==keta-1: if t!=0: count+=1 if count==K: ans+=t break if t !=0: count+=1 if count==K: ans+=sum(dp[K-count+1][:keta-j]) #0のとき ans+=t break ans += sum(dp[K-count][:keta-j])*(t-1) #0より大きいとき ans += sum(dp[K-count+1][:keta-j]) #0のとき print(ans)
1
76,063,027,599,890
null
224
224
from collections import defaultdict from collections import deque from collections import OrderedDict import itertools from sys import stdin input = stdin.readline def main(): N = int(input()) set_ = set() for i in range(N): set_.add(input()[:-1]) print(len(set_)) if(__name__ == '__main__'): main()
N=int(input()) S=[input() for i in range(N)] print(len(set(S)))
1
30,160,419,961,540
null
165
165
r = int(input()) ans = r * r print(ans)
S = input() N = len(S) num = 0 L = [0] R = [0] cnt = 0 for i in range(N): if S[i] == "<": cnt += 1 else: cnt = 0 L.append(cnt) ans = 0 S = S[::-1] cnt = 0 for i in range(N): if S[i] == ">": cnt += 1 else: cnt = 0 R.append(cnt) R = R[::-1] for i in range(N+1): ans += max(L[i], R[i]) print(ans)
0
null
150,811,269,363,972
278
285
import time start = time.time() n = int(input()) a = list(map(int,input().split())) b = [] m = 0 for i in range(1,n): m = m ^ a[i] b.append(m) for j in range(1,n): m = m ^ a[j-1] m = m ^ a[j] b.append(m) b = map(str,b) print(' '.join(b))
N = int(input()) A = list(map(int, input().split())) x = 0 for a in A: x ^= a ans = [] for a in A: ans.append(a ^ x) print(" ".join(map(str, ans)))
1
12,497,779,124,606
null
123
123
n = int(input()) if n%2 == 0: print(1/2) else : print((n//2+1)/n)
n = int(input()) if n%2 == 0: print(1/2) else: n2 = (n//2) + 1 print(n2/n)
1
177,773,548,384,418
null
297
297
#coding:utf-8 import math r=float(input()) print("%.6f"%(math.pi*r**2)+" %.6f"%(2*math.pi*r))
pi = 3.141592653589 r = float(input()) c = pi*r**2 s = 2*pi*r print('%.5f %.5f' % (c,s))
1
651,037,557,732
null
46
46
x='123' for _ in range(2): x=x.replace(input(),'') print(x)
ans = [1,2,3] ans.remove(int(input())) ans.remove(int(input())) print(*ans)
1
111,035,686,663,148
null
254
254
N = int(input()) height = [int(i) for i in input().split()] step = 0 for i, h in enumerate(height): if i == 0: pre = h else: if h < pre: step += (pre - h) pre = pre else: step += 0 pre = h print(step)
n, x, m = map(int, input().split()) def solve(n, x, m): if n == 1: return x arr = [x] for i in range(1, n): x = x*x % m if x in arr: rem = n-i break else: arr.append(x) else: rem = 0 sa = sum(arr) argi = arr.index(x) roop = arr[argi:] nn, r = divmod(rem, len(roop)) return sa + nn*sum(roop) + sum(roop[:r]) print(solve(n, x, m))
0
null
3,707,266,578,204
88
75
#!/usr/bin/env python3 x,y = map(int,input().split()) if x == 1 and y == 1: #if False: print(10**6) else: print((max(0,4-x)+max(0,4-y))*(10**5))
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]
0
null
69,951,291,560,992
275
8
import random name = str(input()) a = len(name) if 3<= a <= 20: b = random.randint(0,a-3) ada_1 = name[b] ada_2 = name[b+1] ada_3 = name[b+2] print(ada_1+ada_2+ada_3) else: None
a = input() s = a[0],a[1],a[2] print("".join(s))
1
14,679,687,578,532
null
130
130
#!usr/bin/env pypy3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate 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(): K = I() ans = 0 for i in range(1, K+1): for j in range(1, K+1): for k in range(1, K+1): ans += math.gcd(math.gcd(i, j), k) print(ans) main()
# coding: UTF-8 n,m,l = map(int,raw_input().split(" ")) a_matrix = [map(int,raw_input().split()) for i in range(n)] b_matrix = [map(int,raw_input().split()) for i in range(m)] tmp3_matrix = [] c_matrix = [] for i in range(n): tmp2_matrix = [] for j in range(l): sum = 0 for k in range(m): sum += a_matrix[i][k] * b_matrix[k][j] tmp2_matrix.append(sum) tmp3_matrix.extend([tmp2_matrix]) c_matrix.extend(tmp3_matrix) for x in range(n): print " ".join(map(str,c_matrix[x]))
0
null
18,425,653,001,468
174
60
def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) upper_divisors.append(n//i) i += 1 return lower_divisors, upper_divisors n = int(input()) low, up = make_divisors(n) if len(low) != 1: # ans = low[0] + up[0] # for i in range(1, len(low)): # tmp = low[i] + up[i] # if tmp < ans: # ans = tmp print(low[-1] + up[-1] - 2) else: print(n - 1)
N=int(input()) check=1 while check**2<=N: if N%check==0: keep=N//check check+=1 print(keep+N//keep-2)
1
161,304,731,467,750
null
288
288