code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
import numpy as np raw = input() rawl = raw.split() A = int(rawl[0]) B = int(rawl[1]) H = int(rawl[2]) M = int(rawl[3]) theta = 2*np.pi*(H/12+M/720-M/60) print((A*A+B*B-2*A*B*np.cos(theta))**(0.5))
import math A,B,H,M=map(int,input().split()) C2=A**2+B**2-2*A*B*math.cos((30*H-11*M/2)/180*math.pi) print(C2**(1/2))
1
20,020,025,496,466
null
144
144
def ra(a): #圧縮された要素を非保持 ll,l=[],1 for i in range(len(a)-1): if a[i]==a[i+1]: l+=1 else: ll.append(l) l=1 ll.append(l) return ll n=input() print(len(ra(input())))
a,b,c=map(int,input().split()) K=int(input()) # B > A # C > B import sys for i in range(K+1): A=a B=b*(2**i) C=c*(2**(K-i)) #print(i,K-i,A,B,C) if B>A and C>B: print('Yes') sys.exit() else: print('No')
0
null
88,305,001,316,490
293
101
H, N = map(int, input().split()) l = [] for i in range(N): l.append(list(map(int, input().split()))) dp = [0] * 20000 for i in range(1, 20001): dp[i] = min(dp[i-a]+b for a, b in l) if i == H: break print(dp[H])
r = input() p = 3.141592653589 print "%.6f %.6f" % (p*r*r,2*p*r)
0
null
40,688,942,207,312
229
46
#!/usr/bin/env python3 import math def solver(visited, coord, depth = 0): dists = [] if len(visited) == depth: for i in range(1, len(visited)): x1, y1 = coord[visited[i - 1]][0], coord[visited[i - 1]][1] x2, y2 = coord[visited[i]][0], coord[visited[i]][1] dists.append(math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))) return sum(dists) for i in range(0, len(visited)): if visited[i] != -1: continue visited[i] = depth dists.append(solver(visited, coord, depth + 1)) visited[i] = -1; return sum(dists) def main(): n = int(input()) coord = [] for i in range(0, n): coord.append([int(c) for c in input().split()]) print(solver([-1 for i in range(0, n)], coord) / math.factorial(n)) if __name__ == "__main__": main()
import itertools import math N=int(input()) z=[] for _ in range(N): z.append(list(map(int,input().split()))) sum=0 for per in itertools.permutations(list(range(N))): for i in range(N-1): sum+=math.sqrt((z[per[i]][0]-z[per[i+1]][0])**2+(z[per[i]][1]-z[per[i+1]][1])**2) ans=sum/math.factorial(N) print(ans)
1
148,880,969,315,120
null
280
280
n, k = map(int, (input().split())) n %= k print(min(n, abs(n-k)))
import copy N = int(input()) testimony = [] for n in range(N): A = int(input()) testimony.append({}) for a in range(A): x, y = map(int, input().split()) testimony[n][x - 1] = y def judge(truthy): answer = True for i in range(len(truthy)): if truthy[i] == 1: for t in testimony[i].keys(): if truthy[t] != testimony[i][t]: answer = False break if not answer: break # print(answer, truthy) return 0 if not answer else truthy.count(1) def dfs(truthy, depth): if N == depth: return judge(truthy) truth = copy.copy(truthy) truth.append(1) t = dfs(truth, depth + 1) false = copy.copy(truthy) false.append(0) f = dfs(false, depth + 1) return max(t, f) print(dfs([], 0))
0
null
80,366,152,034,950
180
262
import math x=int(input()) if x==2: print(2) exit() x=x//2*2+1 i=x while 1: flag=True for j in range(2,int(i**0.5)+1): if i%j==0: flag=False break if flag: break i+=1 print(i)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): X = int(readline()) def enum_primes(n): flag_num = (n + 1) // 2 prime_flag = [True] * flag_num for num in range(3, int(n ** 0.5) + 1, 2): idx = (num - 1) // 2 - 1 if prime_flag[idx]: for j in range(idx + num, flag_num, num): prime_flag[j] = False primes = [2] temp = [(i + 1) * 2 + 1 for i in range(flag_num) if prime_flag[i]] primes.extend(temp) return primes primes = enum_primes(10 ** 6) for prime in primes: if prime >= X: return print(prime) if __name__ == '__main__': main()
1
106,026,613,864,380
null
250
250
X = int(input()) SUM = 0 (X * 1000 / 500) Z = X // 500 A = X % 500 SUM = SUM + (Z * 1000) B = A // 5 SUM = SUM + (B * 5) print(int(SUM))
x=int(input()) c=x//500 d=x%500 e=d//5 print(1000*c+e*5)
1
42,688,411,946,542
null
185
185
import unittest def print_str(S,T): return T+S S, T = input().split(' ') print(print_str(S,T)) class TestPrint_str(unittest.TestCase): def test_print_str(selt): self.assertEqual(T+S, print_str(T,S))
s, t = input().split() print('{}{}'.format(t, s))
1
102,742,182,227,680
null
248
248
n = sum(map(int, list(input()))) if n%9==0: print('Yes') else: print('No')
n = int(input()) a = list(map(int, input().split())) # 横入力 x = [0] aaa = 0 for i in range(n): aaa += a[i] x.append(aaa) aa = sum(a) y = [aa] for i in range(n): aa -= a[i] y.append(aa) ans = 202020202020 for i in range(n+1): ans = min(ans, abs(x[i] - y[i])) print(ans)
0
null
73,353,874,484,000
87
276
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 mod = 10**9+7 nums = 10**6 # 制約に合わせよう g1, g2, inverse = [1, 1] , [1, 1], [0, 1] for num in range(2, nums + 1): g1.append((g1[-1] * num) % mod) inverse.append((-inverse[mod % num] * (mod//num)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) x, y = map(int, input().split()) if (x+y)%3 or 2*x<y or 2*y<x: print(0) else: print(cmb((x+y)//3,(2*x-y)//3, mod))
from math import factorial as fac x,y=map(int,input().split()) a=2*y-x b=2*x-y mod=10**9+7 if a>=0 and b>=0 and a%3==0 and b%3==0: a=a//3 b=b//3 a1=1 a2=1 n3=10**9+7 for i in range(a): a1*=a+b-i a2*=i+1 a1%=n3 a2%=n3 a2=pow(a2,n3-2,n3) print((a1*a2)%n3) else: print(0)
1
150,457,988,849,688
null
281
281
n = int(input()) # ns = list(map(int, input().split())) ns.reverse() print(*ns)
_ = input() l = reversed(input().split()) print(' '.join(l))
1
978,532,695,702
null
53
53
N,X,Y = map(int,input().split()) from collections import deque INF = 1000000000 ans = [0]*(N-1) def rep(sv,dist): que = deque() def push(v,d): if (dist[v] != INF): return dist[v] = d que.append(v) push(sv,0) while(que): v = que.popleft() d = dist[v] if v-1 >= 0: push(v-1, d+1) if v+1 < N: push(v+1, d+1) if v == X-1: push(Y-1, d+1) #逆に気を付ける if v == Y-1: push(X-1, d+1) for i in range(N): dist = [INF]*N rep(i,dist) # print(dist) for d in dist: if d-1 == -1:continue ans[d-1] += 1 for an in ans: print(an//2) # print(ans)
# -*- coding: utf-8 -*- """ Created on Mon Sep 7 15:49:02 2020 @author: liang """ N, X, Y = map(int, input().split()) ans = [0]*(N-1) for i in range(1,N+1): for j in range(i+1, N+1): #print(i,j) res = min(abs(i-j), abs(X-i) + 1 + abs(Y-j)) #print(i, j, res) ans[res-1] += 1 for i in ans: print(i)
1
44,175,042,998,910
null
187
187
lakes = [] # [(左岸位置, 断面積)] lefts = [] # lefts[i]: まだ対になっていない上から i 番目の左岸位置 for i, c in enumerate(input()): if c == '\\': lefts.append(i) elif c == '/': if lefts: left = lefts.pop() area = i - left while lakes: sub_left, sub_area = lakes[-1] if left < sub_left: area += sub_area lakes.pop() else: break lakes.append((left, area)) L = [lake[1] for lake in lakes] print(sum(L)) print(len(L), *L)
class Flood: """ begin : int 水たまりの始まる場所 area : int 水たまりの面積 """ def __init__(self, begin, area): self.begin = begin self.area = area down_index_stack = [] # \の場所 flood_stack = [] # (水たまりの始まる場所, 面積) for i, c in enumerate(input()): if c == '\\': down_index_stack.append(i) if c == '/': if len(down_index_stack) >= 1: # 現在の/に対応する\が存在したら l = down_index_stack.pop() # 現在の水たまりの始まる場所 area = i - l # 現在の水たまりの現在の高さの部分の面積はi-l # 現在の水たまりが最後の水たまりを内包している間は # (現在の水たまりの始まる場所が最後の水たまりの始まる場所より前にある間は) while len(flood_stack) >= 1 and l < flood_stack[-1].begin: # 最後の水たまりを現在の水たまりに取り込む last_flood = flood_stack.pop() area += last_flood.area flood_stack.append(Flood(l, area)) # 現在の水たまりを最後の水たまりにして終了 area_list = [flood.area for flood in flood_stack] print(sum(area_list)) print(' '.join(list(map(str, [len(area_list)] + area_list))))
1
59,455,261,110
null
21
21
while True: H, W = [int(i) for i in input().split()] if H == 0 and W == 0: break for i in range(H): for j in range(W): if (i + j) % 2 == 0: print('#', end='') else: print('.', end='') print('') print('')
import math def main(): a, b = [int(i) for i in input().split()] lo = max(1000 * a, 800 * b) hi = min(1000 * (a + 1), 800 * (b + 1)) if lo < hi: print(math.ceil(lo / 80)) else: print(-1) main()
0
null
28,641,998,989,440
51
203
x1, y1, x2, y2 = map(float,input().split()) r = ((x1-x2)**2+(y1-y2)**2)**.5 print("{:.8f}".format(r))
from collections import defaultdict N, M = map(int, input().split()) H = list(map(int, input().split())) edges = defaultdict(list) for _ in range(M): a, b = map(lambda x:int(x)-1, input().split()) edges[a].append(b) edges[b].append(a) ans = 0 for i in range(N): ok = True for adj in edges[i]: if H[adj] >= H[i]: ok = False break if ok: ans += 1 print(ans)
0
null
12,551,613,919,998
29
155
class UnionFind: def __init__(self, num): self.parent = [-1] * num def find(self, node): if self.parent[node] < 0: return node self.parent[node] = self.find(self.parent[node]) return self.parent[node] def union(self, node1, node2): node1 = self.find(node1) node2 = self.find(node2) if node1 == node2: return if self.parent[node1] > self.parent[node2]: node1, node2 = node2, node1 self.parent[node1] += self.parent[node2] self.parent[node2] = node1 return def same(self, node1, node2): return self.find(node1) == self.find(node2) def size(self, x): return -self.parent[self.find(x)] def roots(self): return [i for i, x in enumerate(self.parent) if x < 0] def group_count(self): return len(self.roots()) n, m = map(int, input().split()) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 uf.union(a, b) print(uf.group_count() - 1)
suuretu=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K=int(input()) ans=suuretu[K-1] print(ans)
0
null
26,273,225,444,060
70
195
N = int(input()) XL = [list(map(int, input().split())) for x in range(N)] XL = sorted(XL, key=lambda x: x[0]+x[1]) cnt = 0 prev_right = -10**9+10 for x, l in XL: left = x - l right = x + l if left >= prev_right: cnt += 1 prev_right = right print(cnt)
n = int(input()) xl = [] for _ in range(n): x, l = map(int,input().split()) xl.append((x-l, x+l, x, l)) xl.sort() count = n flag = 0 for i in range(n-1): if flag == 1: # this machine was removed. flag = 0 else: left, right, x, l = xl[i] if xl[i+1][0] < right: # overlap if xl[i+1][1] <= right: # i includes i+1 count -= 1 # remove i else: flag = 1 count -= 1 # remove i+1 print(count)
1
90,160,204,015,180
null
237
237
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if b<=a: b*=2 else: c*=2 if b>a and c>b: print('Yes') else: print('No')
H, N = list(map(int, input().split())) A = list(map(int, input().split())) print('Yes' if sum(A) >= H else 'No')
0
null
42,570,854,754,972
101
226
import sys def main(): n, x, y = map(int, sys.stdin.buffer.readline().split()) L = [0] * n for i in range(1, n): for j in range(i + 1, n + 1): d = j - i if i <= x and y <= j: d -= y - x - 1 elif i <= x and x < j < y: d = min(d, x - i + y - j + 1) elif x < i < y and y <= j: d = min(d, i - x + j - y + 1) elif x < i and j < y: d = min(d, i - x + y - j + 1) L[d] += 1 for a in L[1:]: print(a) main()
H, M = map(int, input().split()) A = list(map(int, input().split())) for i in A: H -= i if H < 0: print("-1") else: print(H)
0
null
37,849,573,329,700
187
168
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) SA =[0] SB =[0] for i in range(len(A)): SA.append(SA[i] + A[i]) for j in range(len(B)): SB.append(SB[j] + B[j]) l = M ans = 0 for k in range(N+1): if SA[k] > K: break while SA[k] + SB[l] > K: l -= 1 ans = max(ans, k + l) print(ans)
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) tmp_time = 0 last_i = -1 for i in range(N): if tmp_time + A[i] <= K: tmp_time += A[i] last_i = i else: break last_j = -1 for j in range(M): if tmp_time + B[j] <= K: tmp_time += B[j] last_j = j else: break ans = last_i + last_j + 2 now = ans while last_i >= 0: tmp_time -= A[last_i] now -= 1 last_i -= 1 while last_j + 1 < M and tmp_time + B[last_j + 1] <= K: tmp_time += B[last_j + 1] last_j += 1 now += 1 ans = max(ans, now) print(ans) def main(): solve() if __name__ == '__main__': main()
1
10,799,808,643,392
null
117
117
# -*- coding: utf-8 -*- from collections import deque if __name__ == '__main__': n = int(input()) L = deque() for _ in range(n): command = input().split(" ") if command[0] == "insert": L.appendleft(command[1]) elif command[0] == "delete": try: L.remove(command[1]) except: pass elif command[0] == "deleteFirst": L.popleft() elif command[0] == "deleteLast": L.pop() print(" ".join(L))
import sys import math import itertools as it def I():return int(sys.stdin.readline().replace("\n","")) def I2():return map(int,sys.stdin.readline().replace("\n","").split()) def S():return str(sys.stdin.readline().replace("\n","")) def L():return list(sys.stdin.readline().replace("\n","")) def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()] def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split())) if __name__ == "__main__": n = I() a = Intl() for i in range(n): if a[i]%2 == 0: if a[i]%3 == 0 or a[i]%5 == 0:pass else: print("DENIED") exit() print("APPROVED")
0
null
34,351,789,657,682
20
217
def main(): S = input() if S[-1] == "s": print(S+"es") else: print(S+"s") if __name__ == "__main__": main()
n = int(input()) d1 = [0] * n d2 = [0] * n for i in range(n): d1[i], d2[i] = (map(int, input().split())) cnt = 0 for i in range(n): if d1[i] == d2[i]: cnt += 1 else: cnt = 0 if cnt >= 3: break if cnt >= 3: print("Yes") else: print("No")
0
null
2,459,555,162,950
71
72
x = [int(x) for x in input().split()] if (sum(x)>21): print('bust') else: print('win')
A=list(map(int,input().split())) if A[0]+A[1]+A[2]<=21: print("win") else: print("bust")
1
118,752,301,771,850
null
260
260
n = int(input()) a = [int(x) for x in input().split()] q = int(input()) bc=[] for i in range(q): bc.append([int(x) for x in input().split()]) a_cnt=[0]*(10**5+1) for i in range(len(a)): a_cnt[a[i]]+=1 a_goukei=sum(a) for gyou in range(q): a_goukei+=(bc[gyou][1]-bc[gyou][0])*a_cnt[bc[gyou][0]] print(a_goukei) a_cnt[bc[gyou][1]]+=a_cnt[bc[gyou][0]] a_cnt[bc[gyou][0]]=0
N=int(input()) A=list(map(int, input().split())) q=int(input()) Q=[list(map(int, input().split())) for _ in range(q)] L=[0]*(10**5+1) S=0 for i in range(N): L[A[i]]+=1 S+=A[i] for i in range(q): S+=L[Q[i][0]]*(Q[i][1]-Q[i][0]) L[Q[i][1]]+=L[Q[i][0]] L[Q[i][0]]=0 # print(L) print(S)
1
12,072,062,427,410
null
122
122
import collections n = int(raw_input()) adj = collections.defaultdict(list) edges = [] for _ in range(n - 1): u,v = map(int, raw_input().split(' ')) edges.append((u,v)) adj[u].append(v) adj[v].append(u) root = 1 q = collections.deque([root]) h = {} while(q): u = q.popleft() c = 1 used = set([h[tuple(sorted([u,v]))] for v in adj[u] if tuple(sorted([u,v])) in h]) for v in adj[u]: t = tuple(sorted([u,v])) if t not in h: while(c in used): c+=1 h[t] = c c+=1 q.append(v) print max(h.values()) for u,v in edges: print h[(u,v)]
import collections N = int(input()) edges = [[] for _ in range(N)] for i in range(N-1): a, b = map(int, input().split()) edges[a-1].append([b-1,i]) edges[b-1].append([a-1,i]) q = collections.deque() q.append([0,-1,-1]) colors = [0]*(N-1) while len(q) != 0: v, color, num = q.popleft() if colors[num] == 0 and color != -1: colors[num] = color next_color = 0 for w in edges[v]: if colors[w[1]] != 0: continue next_color += 1 if next_color == colors[num]: next_color += 1 q.append([w[0],next_color,w[1]]) print(len(set(colors))) for i in colors: print(i)
1
135,900,481,427,270
null
272
272
class HashTable: def __init__(self, size = 1000003): self.size = size self.hash_table = [None] * size def _gen_key(self, val): raw_hash_val = hash(val) h1 = raw_hash_val % self.size h2 = 1 + (raw_hash_val % (self.size - 1)) for i in range(self.size): candidate_key = (h1 + i * h2) % self.size if not self.hash_table[candidate_key] or self.hash_table[candidate_key] == val: return candidate_key def insert(self, val): key = self._gen_key(val) self.hash_table[key] = val def search(self, val): key = self._gen_key(val) if self.hash_table[key]: print('yes') else: print('no') import sys n = int(sys.stdin.readline()) simple_dict = HashTable() ans = '' for i in range(n): operation = sys.stdin.readline() if operation[0] == 'i': simple_dict.insert(operation[7:]) else: simple_dict.search(operation[5:])
n = int(input()) my_dict = {} for i in range(n): order, key = input().split(' ') if order == 'insert': my_dict[key] = True elif order== 'find': if key in my_dict.keys(): print('yes') else: print('no')
1
74,285,437,520
null
23
23
string = input('') if string.endswith('s'): print(string + 'es') else: print(string + 's')
n = int(input()) plus,minus = [],[] for i in range(n): a,b = map(int,input().split()) plus.append(a+b) minus.append(a-b) plus.sort() minus.sort() print(max(plus[-1]-plus[0],minus[-1]-minus[0]))
0
null
2,953,277,958,026
71
80
import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return -self.parents[self.find(x)] if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return -self.parents[self.find(x)] def main(): N, M = map(int, input().split()) uf = UnionFind(N+1) ans = 1 if M == 0: print(ans) return for i in range(M): x, y = map(int, input().split()) ans = max(uf.union(x,y), ans) print(ans) if __name__ == '__main__': main()
''' We can show that if u and v belong to the same connected component, then they are friends w/ each other So everyone in a given connected component is friends with one another So everyone in a given connected component must be separated into different groups If we have a CC of with sz nodes in it, then we need at least sz different groups So, the minimum number of groups needed is max sz(CC) ''' n, m = map(int,input().split()) adj = [[] for u in range(n+1)] for i in range(m): u, v = map(int,input().split()) adj[u].append(v) adj[v].append(u) vis = [False for u in range(n+1)] def bfs(s): sz = 0 queue = [s] ptr = 0 while ptr < len(queue): u = queue[ptr] if not vis[u]: vis[u] = True sz += 1 for v in adj[u]: queue.append(v) ptr += 1 return sz CCs = [] for u in range(1,n+1): if not vis[u]: CCs.append(bfs(u)) print(max(CCs))
1
3,925,501,231,278
null
84
84
n = int(input()) print(sum(i for i in range(1, n + 1) if i % 3 and i % 5))
H, A = map(int, input().split()) print(abs(-1*H//A))
0
null
55,988,451,546,148
173
225
import sys def input(): return sys.stdin.readline().rstrip() def main(): h,w,k=map(int,input().split()) S=[input() for _ in range(h)] ANS=[[0]*w for _ in range(h)] cunt=0 for i,s in enumerate(S): for j,ss in enumerate(s): if ss=='#': cunt+=1 ANS[i][j]=cunt elif j>=1 and ANS[i][j-1]>0: ANS[i][j]=ANS[i][j-1] if ANS[i][-1]!=0: for j in range(w-2,-1,-1): if ANS[i][j]==0: ANS[i][j]=ANS[i][j+1] for i in range(h-2,-1,-1): if ANS[i][0]==0: for j,ans in enumerate(ANS[i+1]): ANS[i][j]=ans for i in range(h): if ANS[i][0]==0: for j,ans in enumerate(ANS[i-1]): ANS[i][j]=ans for ans in ANS: print(*ans) if __name__=='__main__': main()
import bisect H,W,K=map(int,input().split()) s=[""]*H ans=[[0]*W for _ in range(H)] St=[0]*H#i行目にイチゴがあるか? St2=[] for i in range(H): s[i]=input() if "#" in s[i]: St[i]=1 St2.append(i) a=1 #i行目,aからスタートして埋める for i in range(H): if St[i]==1: flag=0 for j in range(W): if s[i][j]=="#": if flag==0: flag=1 else: a+=1 ans[i][j]=a a+=1 for i in range(H): k=bisect.bisect_left(St2,i) #近いところを参照したいけど参照したいけど,端での処理が面倒 if k!=0: k-=1 if St[i]==0: ans[i]=ans[St2[k]] for i in range(H): print(" ".join(map(str, ans[i])))
1
143,541,753,024,060
null
277
277
N = int(input()) nums = map(int, input().split(" ")) for n in nums: if n % 2 != 0: continue if n % 3 == 0 or n % 5 == 0: continue else: print("DENIED") exit(0) print("APPROVED")
N = int(input()) A = list(map(int,input().split())) B = len([i for i in A if i % 2==0]) count = 0 for i in A: if i % 2 !=0: continue elif i % 3 ==0 or i % 5==0: count +=1 if count == B: print('APPROVED') else: print('DENIED')
1
68,929,554,604,022
null
217
217
import math def calc_debt(week=0): debt = 100000 for i in range(week): debt = int(math.ceil(debt * 1.05 / 1000))*1000 return debt print(calc_debt(int(input())))
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(M)] buy = [min(a)+min(b)] for i in range(M): C = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2] buy.append(C) print(min(buy))
0
null
27,060,134,408,658
6
200
s = input() t = input() if s == t[:len(t) - 1]: print('Yes') else: print('No')
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True X = int(input()) i = X while 1: if not is_prime(i): i += 1 else: ans = i print(i) break
0
null
63,438,423,275,260
147
250
N = int(input()) X = list(map(int,input().split())) ans = float("inf") for loc in range(-100,101): temp = 0 for x in X: temp += (loc-x)**2 ans = min(temp,ans) print(ans)
from sys import stdin input = stdin.readline def solve(): n,m = map(int,input().split()) p = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()] father = [-1] * n count = n def getfather(x): if father[x] < 0: return x father[x] = getfather(father[x]) return father[x] def union(x, y): x = getfather(x) y = getfather(y) nonlocal count if x != y: count -= 1 if father[x] > father[y]: x,y = y,x father[x] += father[y] father[y] = x for a,b in p: union(a-1,b-1) print(count - 1) if __name__ == '__main__': solve()
0
null
33,755,595,604,742
213
70
n = int(input()) A, B = map(list,zip(*[map(int,input().split()) for i in range(n)])) A.sort() B.sort() if n&1: print(B[n//2]-A[n//2]+1) else: print(B[n//2]+B[n//2-1]-(A[n//2]+A[n//2-1])+1)
import math from math import gcd,pi,sqrt INF = float("inf") MOD = 10**9 + 7 import sys sys.setrecursionlimit(10**6) import itertools import bisect 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 = i_input() a = i_list() cnt = 1 for i in a: if i == cnt: cnt += 1 if cnt == 1: print(-1) else: print(n - cnt + 1) if __name__=="__main__": main()
0
null
65,703,470,641,678
137
257
n=int(input()) a=[] l=[] for i in range(n): A=int(input()) L=[list(map(int,input().split())) for _ in range(A)] a.append(A) l.append(L) ans=0 for i in range(2**n): b=[0]*n for j in range(n): if (i>>j)&1: b[j]=1 for k in range(n): for h in range(a[k]): hito=l[k][h][0]-1 singi=l[k][h][1] if b[k]==1 and b[hito]!=singi: break else: continue break else: ans=max(ans,sum(b)) print(ans)
from collections import* n=input() a=list(map(int,input().split())) d=dict(Counter(a)) mod=998244353 ans=a[0]==0 and d[0]==1 for i in d: if i==0:continue ans*=pow(d.get(i-1,0),d[i],mod) ans%=mod print(ans)
0
null
138,029,676,899,922
262
284
def main(): n, a, b = map(int, input().split(" ")) one_round = a+b x = n // one_round n = n % one_round ans = x * a ans += min(n,a) print(ans) if __name__ == "__main__": main()
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, copy, time from fractions import gcd import numpy as np sys.setrecursionlimit(10**8) INF = float('inf') MOD = 10**9+7 EPS = 10**-7 n, a, b = map(int, input().split()) ans = n//(a+b)*a + min(n%(a+b), a) print(ans)
1
55,441,098,835,808
null
202
202
def resolve(): n = int(input()) a = tuple(map(int,input().split())) attend = [0]*n for i,j in enumerate(a): attend[j-1] = i+1 print(*attend) resolve()
n = int(input()) a = list(map(int, input().split())) # a = np.array(a) # ans = [] # while a.min() != 9999999: # min_index = a.argmin() # ans.append(min_index+1) # a[min_index] = 9999999 # print(' '.join([str(_) for _ in ans])) l = [] for i in range(n): l.append([i+1, a[i]]) sl = sorted(l, key=lambda x: x[1]) sl0 = [r[0] for r in sl] print(' '.join([str(_) for _ in sl0]))
1
180,977,535,916,260
null
299
299
def resolve(): # 十進数表記で1~9までの数字がK個入るN桁の数字の数を答える問題 S = input() K = int(input()) n = len(S) # dp[i][k][smaller]: # i:桁数 # K:0以外の数字を使った回数 # smaller:iまでの桁で値以上になっていないかのフラグ dp = [[[0] * 2 for _ in range(4)] for _ in range(105)] dp[0][0][0] = 1 for i in range(n): for j in range(4): for k in range(2): nd = int(S[i]) for d in range(10): ni = i+1 nj = j nk = k if d != 0: nj += 1 if nj > K: continue if k == 0: if d > nd: # 値を超えている continue if d < nd: nk += 1 dp[ni][nj][nk] += dp[i][j][k] ans = dp[n][K][0] + dp[n][K][1] print(ans) if __name__ == "__main__": resolve()
N=int(input()) if N%10==2 or N%10==4 or N%10==5 or N%10==7 or N%10==9: print("hon") elif N%10==0 or N%10==1 or N%10==6 or N%10==8: print("pon") else: print("bon")
0
null
47,758,147,407,388
224
142
i = input() i_l = i.split() count = 0 for each in range(int(i_l[0]),int(i_l[1])+1): if int(i_l[2]) % each == 0: count += 1 else: print(count)
import sys a,b,c = map(int,sys.stdin.readline().split()) num = 0 for i in range(a,b+1): if c % i == 0: num += 1 print(num)
1
554,792,352,520
null
44
44
import math N = int(input()) P = math.ceil(N/2) print(P)
N = int(input()) if N%2 == 0: n = N/2 else: n = (N+1)/2 print(round(n))
1
58,981,816,775,940
null
206
206
n,m=map(int,input().split()) s=input() ans=[] cursor=n actualfail=0 while cursor!=0: if cursor<=m: ans.append(cursor) break failflag=1 for i in range(m): if s[cursor-m+i]=='0': failflag=0 ans.append(m-i) cursor-=m-i break if failflag==1: actualfail=1 break if actualfail==1: print(-1) else: ans.reverse() for i in ans: print(i)
n,m = map(int,input().split()) s = input() s = s[::-1] tmp = 0 sum1 = 0 ans = [] while tmp < n: for i in range(m, 0, -1): flag = False if tmp + i <= n: if s[tmp+i] == '0': tmp += i flag = True sum1 += 1 ans.append(i) break if not flag: print(-1) exit() for i in ans[::-1]: print(i, end = ' ')
1
139,096,687,512,480
null
274
274
import sys a_b_c = list(map(int, input().split())) r = a_b_c[0] g = a_b_c[1] b = a_b_c[2] k = int(input()) while (g <= r and k >= 0): g *= 2 k -= 1 while (b <= g and k >= 0): b *= 2 k -= 1 if (k < 0): print("No") else: print("Yes")
import sys r,g,b=map(int,input().split()) k=int(input()) for i in range(k+1): if r<g<b: print("Yes") sys.exit() else: if r<=b<=g: b*=2 elif b<=r<=g: b*=2 elif b<=g<=r: b*=2 elif g<=r<=b: g*=2 elif g<=b<=r: b*=2 print("No")
1
6,965,565,683,648
null
101
101
import sys from math import pi read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): R = int(readline()) print(2 * R * pi) return if __name__ == '__main__': main()
from math import pi print(2 * pi * int(input()), end='\n')
1
31,505,698,039,200
null
167
167
n,m,k = map(int,input().split()) ans = 0 mod = 998244353 p = [0 for i in range(n)] p[0] = 1 for i in range(n-1): p[i+1] = p[i]*(i+2)%mod p.append(1) for i in range(k+1): u = pow(m-1,n-1-i,mod) s = p[n-2]*pow(p[i-1],mod-2,mod)*pow(p[n-i-2],mod-2,mod) ans = (ans + m*u*s)%mod print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) A = sorted(A) B = A[:][::-1] fac = [1, 1] finv = [1, 1] inv = [0, 1] Mod = 10**9+7 def COMinit(): #N_C_kのN for i in range(2, 10**5+10): fac.append(fac[-1]*i%Mod) inv.append((-inv[Mod%i] * (Mod//i)) % Mod) finv.append(finv[-1] * inv[-1] % Mod) def COM(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod COMinit() comb = {} for i in range(K-1, N): comb[(i, K-1)] = COM(i, K-1) ans = 0 for i in range(K-1, N): ans += A[i] * comb[(i, K-1)] ans %= Mod for i in range(K-1, N): ans -= B[i] * comb[(i, K-1)] ans %= Mod print(ans)
0
null
59,628,864,575,648
151
242
S=input() if S == "ABC":print("ARC") else : print("ABC")
S = str(input()) W = ['B', 'R'] if S == 'ABC': p = 1 else: p = 0 print('A'+W[p]+'C')
1
24,152,235,908,430
null
153
153
import sys stdin = sys.stdin def ni(): return int(ns()) def na(): return list(map(int, stdin.readline().split())) def naa(N): return [na() for _ in range(N)] def ns(): return stdin.readline().rstrip() # ignore trailing spaces A, B = na() print(A * B)
import math a, b, h, m = map(int, input().split()) st = (60*h+m)/360*math.pi lt = m/30*math.pi sx = a*math.sin(st) sy = a*math.cos(st) lx = b*math.sin(lt) ly = b*math.cos(lt) print(math.sqrt((lx-sx)**2+(ly-sy)**2))
0
null
18,006,691,695,540
133
144
K = int(input()) ai_1 = 0 for i in range(K): ai = (10*ai_1 + 7)%K if ai==0: print(i+1) exit() ai_1 = ai print("-1")
k = int(input()) s = 7 num = 1 res = True if k == 2: print(-1) else: for i in range(k): s %= k if s == 0: res = False print(num) break num += 1 s *= 10 s += 7 if res: print(-1)
1
6,177,710,288,820
null
97
97
import numpy as np a1 = [int(x.strip()) for x in input().split()] a2 = [int(x.strip()) for x in input().split()] a3 = [int(x.strip()) for x in input().split()] a = np.array([a1,a2,a3]) n = int(input()) bingo = 0 for i in range(n): b = int(input()) if b in a: ch = np.argwhere(a==b) a[ch[0][0]][ch[0][1]] = 0 #該当する文字をゼロでパンチング sum_col = np.sum(a, axis=0) sum_row = np.sum(a, axis=1) bingo = np.count_nonzero(sum_col==0) + np.count_nonzero(sum_row==0) if a[0,0]==0 and a[1,1]==0 and a[2,2]==0: bingo += 1 if a[2,0]==0 and a[1,1]==0 and a[0,2]==0: bingo += 1 if bingo > 0: ans = 'Yes' else: ans = 'No' print(ans)
# -*- coding: utf-8 -*- A = [0] * 3 for i in range(3): A[i] = list(map(int, input().split())) N = int(input()) b = [] for i in range(N): b.append(int(input())) for b_i in b: for i in range(3): for j in range(3): if A[i][j] == b_i: A[i][j] = 0 if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0: print('Yes') elif A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0: print('Yes') elif A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0: print('Yes') elif A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0: print('Yes') elif A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0: print('Yes') elif A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0: print('Yes') elif A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0: print('Yes') elif A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0: print('Yes') else: print('No')
1
59,868,624,247,252
null
207
207
n = int(input()) arrey = [int(i) for i in input().split()] count = 0 for i in range(len(arrey)): minj = i change = False for j in range(i+1, len(arrey)): if arrey[minj] > arrey[j]: minj = j change = True if change: arrey[i], arrey[minj] = arrey[minj], arrey[i] count += 1 for i in range(len(arrey)): print(str(arrey[i])+' ',end='') if i != len(arrey)-1 else print(arrey[i]) print(count)
def main() : n = int(input()) nums = [int(i) for i in input().split()] exchange_count = 0 for i in range(n) : minj = i for j in range(i, n) : if nums[j] < nums[minj] : minj = j if minj != i : exchange_count += 1 nums[i], nums[minj] = nums[minj], nums[i] print(" ".join(map(str, nums))) print(exchange_count) if __name__ == '__main__' : main()
1
19,588,962,470
null
15
15
ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(map(int, input().split())) d, t, s = mi() print("Yes" if d <= t*s else "No")
if __name__ == "__main__": N = int(input()) hash = {} for i in range(N): hash[input()] = "" print(len(hash.keys()))
0
null
16,957,869,691,360
81
165
n = input() a = [raw_input() for _ in range(n)] b = [] for i in ['S ','H ','C ','D ']: for j in range(1,14): b.append(i+str(j)) for i in a: b.remove(i) for i in b: print i
a = {} for s in ["S", "H", "C", "D"]: a.update({f'{s} {i}': 0 for i in range(1, 14)}) n = int(input()) for _ in range(n): s = input() del a[s] a = list(a) for i in range(len(a)): print(a[i])
1
1,065,246,942,144
null
54
54
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def SS(): return map(str,sys.stdin.readline().rstrip().split()) def II(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) A,B,M = II() a = LI() b = LI() ticket = [LI() for _ in range(M)] cost = min(a) + min(b) costl = [a[t[0]-1] + b[t[1]-1] - t[2] for t in ticket] print(min(cost,min(costl)))
n = int(input()) ans = 0 for a in range(1,n): b = n//a if b*a == n: b -= 1 ans += b print(ans)
0
null
28,202,620,312,352
200
73
n = int(input()) a = list(map(int, input().split())) hoge = [0] * n cnt = 0 for i in range(n): #hoge[i + 1] = hoge[i] + a[i] cnt += a[i] hoge[i] = cnt hoge_ = [0] * n cnt = 0 for i in range(n - 1, -1, -1): cnt += a[i] hoge_[i] = cnt ans = float('Inf') for i in range(n - 1): ans = min(ans, abs(hoge[i] - hoge_[i + 1])) print(ans)
import math X = int(input()) i = 1 while True: net = (i * X)/360 if math.floor(net) == math.ceil(net): break else: i+=1 print(i)
0
null
77,489,900,653,620
276
125
import sys read=sys.stdin.read h,w,n=map(int, read().split()) m=max(h,w) print(n//m+(n%m!=0))
r, c = list(map(int, input().split(' '))) matrix = [] for i in range(r): matrix.append(input()) ans = 0 cost = {} # cost[(i, j), (p, q)] -> (i,j) -> (p,q) の minコスト (20 * 20 * 20 * 20 = 1.6 * 1e4) for i in range(r): for j in range(c): if matrix[i][j] == '#': # !!! continue start = (i, j) cost[(i,j), (i,j)] = 0 q = [start] while q: ti, tj = q.pop(0) for ni, nj in [(ti-1, tj), (ti, tj-1), (ti+1, tj), (ti, tj+1)]: if ni < 0 or nj < 0 or ni >= r or nj >= c or matrix[ni][nj] == '#': continue if cost.get(((i,j), (ni, nj)), 99999999999999999) > cost[(i,j), (ti, tj)] + 1: cost[(i,j), (ni, nj)] = cost[(i,j), (ti, tj)] + 1 ans = max(ans, cost[(i,j), (ni, nj)]) #print('i,j = ', (i,j), 'ni,nj = ', (ni,nj), 'ans = ', cost[(i,j), (ni, nj)]) q.append((ni, nj)) print(ans)
0
null
91,470,020,505,868
236
241
s = input() a = "x"*len(s) print(a)
import math import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def main(): X = ii() print(360//math.gcd(X,360)) if __name__ == "__main__": main()
0
null
43,021,235,662,770
221
125
n,a,b = map(int,input().split()) t = n // (a+b) ans = t*a s = n % (a+b) if s <= a: ans += s else: ans += a print(ans)
N,A,B=map(int,input().split()) if A==0: print("0") elif B==0: print(N) elif N%(A+B)>A: print(A*int(N/(A+B))+A) else: print(A*int(N/(A+B))+N%(A+B))
1
55,760,789,728,020
null
202
202
while True: s = list(input()) if s == ['-']: break for _ in range(int(input())): h = int(input()) s = s[h:] + s[:h] for c in s: print(c, end='') print('')
#!/usr/bin/env python3 n, a, b = map(int, input().split()) ans = 0 if (b-a)%2 == 0: ans = (b-a)//2 else: if a-1 >= n-b: ans = n + (1-a-b)//2 else: ans = (a+b)//2 print(int(ans))
0
null
55,698,621,694,448
66
253
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, cos, radians, pi, sin from operator import mul from functools import reduce from operator import mul sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') 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)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] n = I() A = [] B = [] for _ in range(n): s = S() ret = 0 ret2 = 0 for i in s: if ret and i == ')': ret -= 1 elif i == '(': ret += 1 else: ret2 += 1 if ret2 > ret: A += [(ret, ret2)] else: B += [(ret, ret2)] A.sort() B.sort(key=lambda x:x[1], reverse=True) L = A + B now = 0 for x, y in L: if x > now: print('No') exit() now = now - x + y if now: print('No') else: print('Yes')
n = int(input()) S = set(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) sum = 0 for i in T: if i in S: sum +=1 print(sum)
0
null
11,911,795,318,620
152
22
from collections import Counter N = input() D_list = list(map(int, input().split())) max_D = max(D_list) cnt_dic = dict(Counter(D_list)) if (D_list[0] == 0) & (cnt_dic.get(0) == 1): ans = 1 for n in range(1, max_D + 1): ans *= cnt_dic.get(n - 1, 0) ** cnt_dic.get(n, 1) print(ans % 998244353) else: print(0)
from collections import Counter N,*D = map(int, open(0).read().split()) m = 998244353 if D[0] > 0: print(0) else: dc = Counter(D) dci = [x for x in dc.items()] ans = 1 if dc[0] > 1: print(0) else: for i in range(1,max(dci)[0]+1): if dc[i] == 0: print(0) break else: ans = (ans*pow(dc[i-1],dc[i],m)) % m else: print(ans)
1
154,868,455,638,428
null
284
284
def is_good(mid, key): S = list(map(int, str(mid))) N = len(S) dp = [[[0] * 11 for _ in range(2)] for _ in range(N + 1)] dp[1][1][10] = 1 for k in range(1, S[0]): dp[1][1][k] = 1 dp[1][0][S[0]] = 1 for i in range(1, N): for k in range(1, 11): dp[i + 1][1][k] += dp[i][0][10] + dp[i][1][10] for is_less in range(2): for k in range(10): for l in range(k - 1, k + 2): if not 0 <= l <= 9 or (not is_less and l > S[i]): continue dp[i + 1][is_less or l < S[i]][l] += dp[i][is_less][k] return sum(dp[N][0][k] + dp[N][1][k] for k in range(10)) >= key def binary_search(bad, good, key): while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good K = int(input()) print(binary_search(0, 3234566667, K))
from collections import deque K = int(input()) if K <= 10: print(K) else: cnt = 9 l = deque(list(range(1,10))) while True: a = l.popleft() a1 = a% 10 if a1 != 0: a2 = a*10 + a1 - 1 cnt += 1 if cnt == K: print(a2) break l.append(a2) a2 = a*10 + a1 cnt += 1 if cnt == K: print(a2) break l.append(a2) if a1 != 9: a2 = a*10 + a1 + 1 cnt += 1 if cnt == K: print(a2) break l.append(a2)
1
39,961,665,548,630
null
181
181
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect import math, fractions import sys, copy def L(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline().rstrip()) def S(): return list(sys.stdin.readline().rstrip()) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def LR(n): return [L() for _ in range(n)] def perm(n, r): return math.factorial(n) // math.factorial(r) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) alphabets = "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 INF = float("inf") class Eratosthenes: # https://cp-algorithms.com/algebra/prime-sieve-linear.html def __init__(self, n): primes = [] lp = [0] * (n + 1) for i in range(2, n + 1): if lp[i] == 0: primes.append(i) lp[i] = i for pj in primes: if pj > lp[i] or i * pj > n: break lp[i * pj] = pj self.primes = primes self.lp = lp def is_prime(self, x): return self.lp[x] == x def factrization(self, x): ret = [] while x > 1: ret.append(self.lp[x]) x //= self.lp[x] return ret def main(): N, K = LI() era = Eratosthenes(K) count = [0] * (K + 1) for i in range(1, K + 1): count[i] = pow((K // i), N, MOD) for i in range(1, K + 1)[::-1]: divs = era.factrization(i) candedates = [l for l in set(reduce(lambda x, y:x * y, ll, 1) for r in range(1, len(divs) + 1) for ll in itertools.combinations(divs, r))] for v in candedates: count[i // v] -= count[i] ans = 0 for i in range(1, K + 1): ans = (ans + i * count[i]) % MOD print(ans % MOD) if __name__ == '__main__': main()
N,K=map(int,input().split()) MOD=int(1e9)+7 dp=[0]*(K+1) for i in range(K): j=K-i dp[j]+=pow(K//j, N, MOD) k=2*j while k<=K: dp[j]=(dp[j]-dp[k]+MOD) % MOD k+=j ans=0 for i in range(1,K+1): ans+=dp[i]*i ans%=MOD print(ans)
1
36,872,874,650,140
null
176
176
import math a = float(input()) area = a * a * math.pi cir = (a * 2) * math.pi print(area,cir)
h, n = map(int,input().split()) a = list(map(int, input().split())) a.sort(reverse=True) for v in a: h -= v if h <= 0: print('Yes') break else: print('No')
0
null
39,460,088,143,380
46
226
# -*- coding: utf-8 -*- N = int(input()) g = N // 2 k = ( N + 1 ) // 2 if N % 2 == 0: print(g) else: print(k)
A,B,C=map(int, input().split()) D=A+B+C if D>=22: print('bust') else : print('win')
0
null
89,201,061,414,220
206
260
import sys input = sys.stdin.readline N, M, L = map(int, input().split()) INF = float('inf') VD = [[INF] * N for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 VD[a][b] = c VD[b][a] = c for i in range(N): VD[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): if VD[i][j] > VD[i][k] + VD[k][j]: VD[i][j] = VD[i][k] + VD[k][j] WD = [[INF] * N for _ in range(N)] for i in range(N): WD[i][i] = 0 for j in range(i+1,N): d = VD[i][j] if d <= L: WD[i][j] = 1 WD[j][i] = 1 for k in range(N): for i in range(N): for j in range(N): if WD[i][j] > WD[i][k] + WD[k][j]: WD[i][j] = WD[i][k] + WD[k][j] Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1)
import numpy as np from scipy.sparse.csgraph import floyd_warshall def main(): N, M, L = map(int, input().split()) graph = [[0] * N for _ in range(N)] for _ in range(M): s, t, w = map(int, input().split()) if w <= L: graph[s-1][t-1] = graph[t-1][s-1] = w graph = floyd_warshall(graph, directed=False) graph = floyd_warshall(graph <= L, directed=False) graph[np.isinf(graph)] = 0 Q = int(input()) ans = [] for _ in range(Q): s, t = map(int, input().split()) ans.append(int(graph[s-1][t-1]) - 1) print(*ans, sep='\n') if __name__ == '__main__': main()
1
173,470,841,618,588
null
295
295
k, n = map(int, input().split()) A = list(map(int, input().split())) A.append(A[0]+k) l = 0 for i in range(n): l = max(l, A[i+1]-A[i]) ans = k - l print(ans)
k,n,*a=map(int,open(0).read().split()) l=k-a[n-1]+a[0] for i in range(n-1): l=max(l,a[i+1]-a[i]) print(k-l)
1
43,613,010,949,088
null
186
186
import math N = int(input()) total = N/2*(N+1) f = math.floor(N/3) f = (3*f+3)*f/2 b = math.floor(N/5) b = (5*b+5)*b/2 fb = math.floor(N/15) fb = (15*fb+15)*fb/2 print(int(total-f-b+fb))
#162B #FizzBuzz Sum n=int(input()) print(sum(x for x in range(1,n+1) if x%3!=0 and x%5!=0))
1
34,879,462,696,760
null
173
173
a,b=list(map(int,input().split())) from fractions import gcd res=a*b/gcd(a,b) print(int(res))
from collections import defaultdict def main(): n = int(input()) d = defaultdict(int) for i in range(1, n+1): s = str(i) a = s[0] b = s[-1] d[a, b] += 1 ans = 0 d_items = list(d.items()) for (a, b), v in d_items: ans += v * d[b,a] print(ans) if __name__ == '__main__': main()
0
null
99,796,441,400,480
256
234
import os, sys, re, math N = int(input()) S = [] for i in range(N): S.append(input()) d = {} for s in S: if not s in d: d[s] = 0 d[s] += 1 d = sorted(d.items(), key=lambda x:x[1], reverse=True) names = [v[0] for v in d if v[1] == d[0][1]] for name in sorted(names): print(name)
# coding:UTF-8 import sys from math import factorial MOD = 10 ** 9 + 7 INF = float('inf') N = int(input()) # 数字 A = list(map(int, input().split())) # スペース区切り連続数字 m = max(A) num = [0] * (m + 1) for a in A: num[a] += 1 for a in A: if num[a] > 1: num[a] = 0 i = 2 while a * i <= m: num[a * i] = 0 i += 1 res = 0 for n in num: if n != 0: res += 1 print("{}".format(res))
0
null
42,178,629,004,540
218
129
import sys input = sys.stdin.readline def main(): text = input().rstrip() n = int(input().rstrip()) for i in range(n): s = input().split() if s[0] == "print": print(text[int(s[1]):int(s[2])+1]) elif s[0] == "replace": new_text = "" new_text += text[:int(s[1])] new_text += s[3] new_text += text[int(s[2])+1:] text = new_text elif s[0] == "reverse": new_text = "" new_text += text[:int(s[1])] for i in range(int(s[2])-int(s[1]) + 1): new_text += text[int(s[2]) - i] new_text += text[int(s[2])+1:] text = new_text if __name__ == "__main__": main()
from collections import deque que = deque() n = int(input()) for _ in range(n): command = input() if command == 'deleteFirst': que.popleft() elif command == 'deleteLast': que.pop() else: x, y = command.split() if x == 'insert': que.appendleft(int(y)) elif int(y) in que: que.remove(int(y)) print(' '.join(map(str, que)))
0
null
1,082,932,151,388
68
20
X, Y = map(int, input().split()) prize = [300000, 200000, 100000] ans = 0 if X <= 3: X -= 1 ans += prize[X] if Y <= 3: Y -= 1 ans += prize[Y] if ans == 600000: ans += 400000 print(ans)
H,N = (int(x) for x in input().split()) A = [int(x) for x in input().split()] if sum(A)>=H: print('Yes') else: print('No')
0
null
109,655,466,808,242
275
226
S=input() N=len(S) A=S[:(N-1)//2] B=S[(N+3)//2-1:] if S!=S[::-1] or A!=A[::-1] or B!=B[::-1]: print("No") else: print("Yes")
S = input() N = len(S) count1,count2,count3 = 0,0,0 flg1,flg2,flg3 = False,False,False for i in range(N): #print(S[i],S[-1-i]) if S[i] == S[-1-i]: count1 += 1 if count1 == N: flg1 = True #print(count1,flg1) a = int((N-1)/2) for i in range(a): #print(S[i],S[a-1-i]) if S[i] == S[a-1-i]: count2 += 1 if count2 == int((N-1)/2): flg2 = True #print(count2,flg2,a) b = int((N+3)/2) #print(b) for i in range(N-b+1): #print(S[b+i-1],S[N-1-i]) if S[b+i-1] == S[N-i-1]: count3 += 1 if count3 == N-b+1 : flg3 = True if flg1 == True and flg2 == True and flg3 == True: print("Yes") else: print("No")
1
46,064,724,184,608
null
190
190
print '1' if int(raw_input().split(' ')[1]) > int(raw_input().split(' ')[1]) else '0'
ary = list(map(int, input().split())) print('Yes' if len(set(ary)) == 2 else 'No')
0
null
95,988,671,133,880
264
216
# coding: utf-8 N = int(input()) x_ = N//1.08 ans = ':(' for i in range(1,100000): x = x_+i if int(1.08*x) == N: ans = int(x) break print(ans)
def n_cand(x): return int(x*1.08) n = int(input()) x = round(n / 1.08) n_dash = n_cand(x) n_dash_m = n_cand(x-1) n_dash_p = n_cand(x+1) if n_dash == n: print(x) elif n_dash_m == n: print(x-1) elif n_dash_p == n: print(x+1) else: print(':(')
1
125,221,993,972,868
null
265
265
from collections import defaultdict import bisect def f(): return [] d=defaultdict(f) n=int(input()) a=list(map(int,input().split())) x=[i+1+a[i] for i in range(n)] y=[i+1-a[i] for i in range(n)] for i in range(n): d[y[i]].append(i) ans=0 for i in range(n): ans+=len(d[x[i]]) print(ans)
import sys [a, b, c] = [int(x) for x in sys.stdin.readline().split()] counter = 0 for value in range(a, b + 1): if c % value == 0: counter += 1 print(counter)
0
null
13,320,279,504,882
157
44
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(read()) lim = int(n ** 0.5) fact = [1] for i in range(2, lim + 1): if (n % i == 0): fact.append(i) else: pass if (len(fact) == 1): ans = n - 1 else: tar = fact[-1] ans = tar + int(n // tar) - 2 print(ans)
H, A = [int(x) for x in input().split()] if H % A == 0: print(H//A) else: print(H//A + 1)
0
null
119,034,465,328,252
288
225
def isKaibun(ss): return ss==ss[::-1] s = input() ans=True n=len(s) if not isKaibun(s): ans=False if not isKaibun(s[:((n-1)//2)]): ans=False if ans: print("Yes") else: print("No")
a=input() c=len(a) b=a[:(c-1)//2] d=a[(c+3)//2-1:] if a==a[::-1] and b==b[::-1] and d==d[::-1]: print("Yes") else: print("No")
1
46,191,325,112,960
null
190
190
from itertools import accumulate N, K = map(int, input().split()) P = list(map(int, input().split())) P = [((x+1) * x / 2) / x for x in P] A = list(accumulate(P)) ans = A[K-1] for i in range(K, N): ans = max(ans, A[i] - A[i-K]) print(ans)
ret = [] while True: m, f, r = map(int, raw_input().split()) if (m,f,r) == (-1, -1, -1): break if m == -1 or f == -1: ret += 'F' elif 80 <= m + f: ret += ['A'] elif 65 <= m + f < 80: ret += ['B'] elif 50 <= m + f < 65: ret += ['C'] elif 30 <= m + f < 50 and 50 <= r: ret += ['C'] elif 30 <= m + f < 50 and r < 50: ret += ['D'] elif m + f < 30: ret += ['F'] for i in ret: print i
0
null
37,898,529,451,120
223
57
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A x = int(input()) y = list(map(int,input().split())) z = 0 flag = 1 while flag: flag = 0 i = x - 1 while i > 0: if y[i] < y[i - 1]: y[i], y[i - 1] = y[i - 1], y[i] flag = 1 z += 1 i -= 1 print(" ".join(list(map(str,y)))) print(z)
while True: m, f, r = map(int, raw_input().split()) if m == -1 and f == -1 and r == -1: break elif m == -1 or f == -1: print "F" elif m + f >= 80: print "A" elif m + f >= 65: print "B" elif m + f >= 50: print "C" elif m + f >= 30 and r >= 50: print "C" elif m + f >= 30: print "D" else: print "F"
0
null
620,487,233,040
14
57
# ng, ok = 0, 10**9+1 n,k = map(int, input().split()) al = list(map(int, input().split())) ng, ok = 0, 10**9+1 while abs(ok-ng) > 1: mid = (ok+ng)//2 ok_flag = True # ... cnt = 0 for a in al: cnt += (a-1)//mid if cnt <= k: ok = mid else: ng = mid print(ok)
N, K = map(int, input().split()) A = list(map(int, input().split())) left, right = 0, max(A) while right - left != 1: mid = (left + right) // 2 tmp = 0 for i in A: tmp += i // mid - 1 if i % mid == 0 else i // mid if tmp > K: left = mid else: right = mid print(right)
1
6,479,038,566,902
null
99
99
s = input() ans = 0 if 'RRR' in s: ans = 3 elif 'RR' in s: ans = 2 elif 'R' in s: ans = 1 print(ans)
S=input() if "RRR" in S: print(3) elif "RR" in S: print(2) elif "R" in S: print(1) else: print(0)
1
4,919,117,268,678
null
90
90
from itertools import accumulate MAX = 2 * 10 ** 5 + 5 N, M, *A = map(int, open(0).read().split()) B = [0] * MAX for a in A: B[a] += 1 C = list(accumulate(reversed(B)))[::-1] ng, ok = 1, MAX while abs(ok - ng) > 1: m = (ok + ng) // 2 if sum(C[max(0, m - a)] for a in A) >= M: ng = m else: ok = m D = list(accumulate(reversed(list(i * b for i, b in enumerate(B)))))[::-1] print(sum(D[max(0, ng - a)] - (ng - a) * C[max(0, ng - a)] for a in A) + ng * M)
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) """ どのパワー以上の組み合わせまで握手するのか二分探索で調べる 同じパワーとなる組み合わせに注意 """ N, M = lr() A = np.array(lr()) A.sort() def check(x): # x以上の幸福度で握手した時、M回以下だとTrueを返す Y = np.searchsorted(A, x - A) return N*N - Y.sum() <= M ok = 10 ** 6; ng = 0 while abs(ng-ok) > 1: mid = (ok+ng) // 2 if check(mid): ok = mid else: ng = mid Acum = np.zeros(N+1, np.int64) Acum[1:] = A.cumsum() Y = np.searchsorted(A, ok-A) answer = (Acum[-1] - Acum[Y]).sum() + (A * (N-Y)).sum() answer += ng * (M - (N-Y).sum()) print(answer) # 24
1
108,226,899,396,480
null
252
252
X = int(input()) if ((2000-X)%200) == 0: print((2000-X)//200) else: print((2000-X)//200+1)
a=int(input()) print(max(8-(a-400)//200,1))
1
6,716,980,123,738
null
100
100
K = int(input()) L = [i for i in range(1, 10)] cnt = 9 i = 0 while K > cnt: x = L[i] r = x % 10 if r != 0: L.append(10*x + r - 1) cnt += 1 L.append(10*x + r) cnt += 1 if r != 9: L.append(10*x + r + 1) cnt += 1 i += 1 print(L[K-1])
from collections import deque k = int(input()) q = deque([]) for i in range(1, 10): q.append(i) cnt = 0 while cnt < k: s = q.popleft() cnt += 1 t = s % 10 if t != 0: q.append(10 * s + (t - 1)) q.append(10 * s + t) if t != 9: q.append(10 * s + (t + 1)) print(s)
1
40,036,821,430,570
null
181
181
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) 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()) H, W, M = MI() h = [0] * H w = [0] * W item_list = [[0, 0] for _ in range(M)] for i in range(M): item_h, item_w = MI() item_h -= 1 item_w -= 1 h[item_h] += 1 w[item_w] += 1 item_list[i][0] = item_h item_list[i][1] = item_w h_max = max(h) w_max = max(w) h_cnt = h.count(h_max) w_cnt = w.count(w_max) ans = h_max + w_max cnt = 0 for item in item_list: if h[item[0]] == h_max and w[item[1]] == w_max: cnt += 1 x = h_cnt * w_cnt if cnt == x: ans -= 1 print(ans)
H,V,M=map(int,input().split()) h=[0 for i in range(M)] w=[0 for i in range(M)] for i in range(M): h[i],w[i]=map(int,input().split()) Dh=dict() Dw=dict() for i in range(M): if h[i] in Dh: Dh[h[i]]+=1 else: Dh[h[i]]=1 if w[i] in Dw: Dw[w[i]]+=1 else: Dw[w[i]]=1 Hmax=0 Wmax=0 for i in Dh: if Dh[i]>Hmax: Hmax=Dh[i] for i in Dw: if Dw[i]>Wmax: Wmax=Dw[i] A=0 B=0 for i in Dh: if Dh[i]==Hmax: A+=1 for i in Dw: if Dw[i]==Wmax: B+=1 tmp=0 for i in range(M): if Dh[h[i]]==Hmax and Dw[w[i]]==Wmax: tmp+=1 if A*B>tmp: print(Hmax+Wmax) else: print(Hmax+Wmax-1)
1
4,683,074,919,460
null
89
89
s = input() w = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'] print(w.index(s)+1)
S = input() days = ['SUN','MON','TUE','WED','THU','FRI','SAT'] i = days.index(S) print (7-i)
1
133,461,521,282,788
null
270
270
def resolve(): H, W = map(int, input().split(" ")) s = [] dp = [[0] * W for i in range(H)] for _ in range(H): s.append([x == "." for x in list(input())]) for h in range(H): for w in range(W): if h == 0 and w == 0: if not s[0][0]: dp[0][0] = 1 elif h == 0: dp[0][w] = dp[0][w-1] if s[0][w-1] and not s[0][w]: dp[0][w] += 1 elif w == 0: dp[h][0] = dp[h-1][0] if s[h-1][0] and not s[h][0]: dp[h][0] += 1 else: # 左側と上側を見て、操作回数が最小になるようにする。 # 上だけをみる temp_up = dp[h-1][w] if s[h-1][w] and not s[h][w]: temp_up += 1 # 左だけを見る temp_left = dp[h][w-1] if s[h][w-1] and not s[h][w]: temp_left += 1 dp[h][w] = min(temp_up, temp_left) print(dp[H-1][W-1]) if __name__ == "__main__": resolve()
import numpy as np h,w=map(int,input().split()) s=[input() for _ in range(h)] dp=np.zeros((h,w),np.int64) if s[0][0]=='#': dp[0,0]=1 for i in range(h): for j in range(w): if (i,j)==(0,0): continue elif i==0: if s[i][j-1]=='.' and s[i][j]=='#': dp[i,j]=dp[i,j-1]+1 else: dp[i,j]=dp[i,j-1] elif j==0: if s[i-1][j]=='.' and s[i][j]=='#': dp[i,j]=dp[i-1,j]+1 else: dp[i,j]=dp[i-1,j] else: dp[i,j]=min(dp[i,j-1]+1 if s[i][j-1]=='.' and s[i][j]=='#' else dp[i,j-1],dp[i-1,j]+1 if s[i-1][j]=='.' and s[i][j]=='#' else dp[i-1,j]) print(dp[-1,-1]) #print(dp)
1
49,447,111,230,872
null
194
194
from collections import defaultdict N, M = map(int, input().split()) H = list(map(int, input().split())) edges = defaultdict(list) for _ in range(M): a, b = map(lambda x:int(x)-1, input().split()) edges[a].append(b) edges[b].append(a) ans = 0 for i in range(N): ok = True for adj in edges[i]: if H[adj] >= H[i]: ok = False break if ok: ans += 1 print(ans)
n , m = map(int,input().split()) h = list(map(int,input().split())) ma = [0] * (n) for i in range(m): a , b = map(int,input().split()) a , b = a - 1 , b - 1 ma[a] = max(ma[a] , h[b]) ma[b] = max(ma[b] , h[a]) ans = 0 for i in range(n): ans += h[i] > ma[i] print(ans)
1
25,122,009,166,368
null
155
155
N = int(input()) S, T = input().split() i = '' for j in zip(S, T): for k in j: i += k print(i)
n = int(input()) s,t = list(map(str,input().split())) string = [] for i in range(len(s)): string.append(s[i]) string.append(t[i]) print(''.join(string))
1
111,995,008,739,108
null
255
255
a = int(input()) S ="" l =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] num = a % 26 while a >0: if a%26 !=0: S =l[(a%26)-1] + S a = (a-a%26)//26 else: S = l[(a%26)-1] + S a = (a-26)//26 print(S)
n, a, b = map(int, input().split()) x = int(n / (a + b)) y = n - ((a + b) * x) if y >= a: z = a else: z = y print(int((a * x) + z))
0
null
33,911,042,216,350
121
202
H,N=map(int,input().split()) A=list(map(int,input().split())) sum=0 for i in range(len(A)): sum+=A[i] if H<=sum : print("Yes") else: print("No")
H,N = (int(x) for x in input().split()) A = [int(x) for x in input().split()] if sum(A)>=H: print('Yes') else: print('No')
1
78,106,226,288,270
null
226
226
string = [] while 1: s = input() if s == "-": break try: n = int(s) for i in range(n): m = int(input()) string = string[m:] + string[:m] output = "".join(string) print(output) except ValueError: string = list(s) continue
import sys from collections import deque import bisect import copy import heapq import itertools import math import random input = sys.stdin.readline sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 def read_values(): return map(int, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for n in range(N)] N, K = read_values() def main(): A = read_list() # A = [random.randint(-10 ** 9, 10 ** 9) for _ in range(N)] A.sort(reverse=True) if N == K or (A[0] < 0 and K % 2 == 1): res = 1 for a in A[:K]: res *= a res %= mod print(res) return A.sort(key=lambda a: abs(a), reverse=True) P1 = list(filter(lambda a: a >= 0, A[:K])) P2 = list(filter(lambda a: a >= 0, A[K:])) N1 = list(filter(lambda a: a < 0, A[:K])) N2 = list(filter(lambda a: a < 0, A[K:])) if len(N1) % 2 == 1: # if N1[-1] * N2[0] : P1[-1] * P2[0] if len(P1) == 0 or len(N2) == 0: N1[-1] = P2[0] elif len(P2) == 0: P1[-1] = N2[0] else: if P1[-1] * P2[0] >= N1[-1] * N2[0]: N1[-1] = P2[0] else: P1[-1] = N2[0] res = 1 for p in P1: res *= p res %= mod for n in N1: res *= n res %= mod print(res % mod) if __name__ == "__main__": main()
0
null
5,693,829,006,728
66
112
n = int(input()) if n % 2 != 0: print((int(n/2) + 1)/n) else: print((n/2)/n)
n = int(input()) if n%2 == 0: print(float((n//2)/n)) elif n == 1: print(float(1)) else: print(float((n//2 + 1)/n))
1
177,439,376,882,782
null
297
297
def isprime(n): if n == 2: return True if n % 2 == 0: return False i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True result = 0 for i in range(int(input())): result += isprime(int(input())) print(result)
import math def isprime(n): for i in range(2, int(math.sqrt(n))+1): if n % i == 0: return False return True if __name__ == '__main__': n = int(input()) nums = [] for _ in range(n): nums.append(int(input())) count = 0 for n in nums: if isprime(n): count += 1 print(count)
1
9,946,788,644
null
12
12
n = int(input()) cnt = [[0] * 10 for _ in range(10)] for i in range(1, n+1): cnt[int(str(i)[0])][int(str(i)[-1])] += 1 res = 0 for i in range(1, 10): for j in range(1, 10): res += cnt[i][j] * cnt[j][i] print(res)
##以下ググった(https://at274.hatenablog.com/entry/2020/01/24/060000) n = int( input() ) cnt = [ [ 0 for i in range( 10 ) ] for j in range( 10 ) ] # cnt[ i ][ j ] = 先頭がi,末尾がjである,n以下の整数の個数 for k in range( n + 1 ): head = int( str( k )[ 0 ] ) foot = int( str( k )[ -1 ] ) cnt[ head ][ foot ] += 1 ans = 0 for i in range( 1, 10 ): for j in range( 1, 10 ): ans += cnt[ i ][ j ] * cnt[ j ][ i ] print( ans )
1
86,768,325,649,220
null
234
234
N=int(input()) A=list(map(int,input().split())) total=sum(A) cost=total cumulative=0 for i in range(N): cumulative+=A[i] cost=min(cost,abs(cumulative-(total-cumulative))) print(cost)
import itertools,sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N = I() A = LI() ans = float('INF') sum_A = sum(A) accumulate_A = list(itertools.accumulate(A)) for i in range(N-1): ans = min(ans,abs(sum_A-accumulate_A[i]*2)) print(ans)
1
141,540,929,243,650
null
276
276
N = int(input()) c = list(str(input())) r = c.count('R') w = 0 for i in range(r): if c[i] == 'W': w += 1 print(w)
data = [None] * 4 for i in xrange(4): data[i] = [None] * 3 for j in xrange(3): data[i][j] = [0] * 10 n = input() for i in xrange(n): line = map(int, raw_input().split()) data[line[0] - 1][line[1] - 1][line[2] - 1] += line[3] for i in xrange(4): for j in xrange(3): s = "" for k in xrange(10): s += ' ' s += str(data[i][j][k]) print s if i < 3: print '#' * 20
0
null
3,673,803,388,640
98
55
while(1): char_list = list(input()) int_list = [0 for i in range(len(char_list))] if char_list[0] == '0': break for i in range(len(char_list)): int_list[i] = int(char_list[i]) print(sum(int_list))
def main(): n, x, y = map(int,input().split()) cnt = 0 ans=[0]*n for i in range(1,n+1): for j in range(i+1,n+1): d = min(j-i,abs(x-i)+abs(y-j)+1) ans[d] += 1 for i in range(1,n): print(ans[i]) if __name__ == "__main__": main()
0
null
22,812,575,031,610
62
187
class SegTree: """ segment tree with point modification and range product. """ # # https://yukicoder.me/submissions/452850 def __init__(self, N, data_f = min, data_unit=1<<30): self.N = N self.data_f = data_f self.data_unit = data_unit self.data = [self.data_unit] * (N + N) def build(self, raw_data): data = self.data f = self.data_f N = self.N data[N:] = raw_data[:] for i in range(N - 1, 0, -1): data[i] = f(data[i << 1], data[i << 1 | 1]) def set_val(self, i, x): data = self.data f = self.data_f i += self.N data[i] = x while i > 1: data[i >> 1] = f(data[i], data[i ^ 1]) i >>= 1 def fold(self, L, R): """ compute for [L, R) """ vL = vR = self.data_unit data = self.data f = self.data_f L += self.N R += self.N while L < R: if L & 1: vL = f(vL, data[L]) L += 1 if R & 1: R -= 1 vR = f(data[R], vR) L >>= 1 R >>= 1 return f(vL, vR) N=int(input()) S=input() data = [[0]*N for _ in range(26)] di = {} for i in range(N): data[ord(S[i])-97][i] = 1 di[i] = S[i] seg = [SegTree(N,max,0) for _ in range(26)] for i in range(26): seg[i].build(data[i]) Q=int(input()) for i in range(Q): *q, = input().split() if q[0] == '1': i, c = q[1:] i = int(i)-1 c_old = di[i] di[i] = c seg[ord(c_old)-97].set_val(i,0) seg[ord(c)-97].set_val(i,1) else: l,r = map(int,q[1:]) ans=0 for i in range(26): ans += seg[i].fold(l-1,r) print(ans)
class BalancingTree: """平衡二分木のクラス Pivotを使った実装. 0以上2^n - 2以下の整数を扱う """ def __init__(self, n): """ 2の指数nで初期化 """ self.N = n self.root = self.node(1<<n, 1<<n) def debug(self): """デバッグ用の関数""" def debug_info(nd_): return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1) def debug_node(nd): re = [] if nd.left: re += debug_node(nd.left) if nd.value: re.append(debug_info(nd)) if nd.right: re += debug_node(nd.right) return re print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50]) def append(self, v): """ v を追加(その時点で v はない前提) """ v += 1 nd = self.root while True: if v == nd.value: # v がすでに存在する場合に何か処理が必要ならここに書く return 0 else: mi, ma = min(v, nd.value), max(v, nd.value) if mi < nd.pivot: nd.value = ma if nd.left: nd = nd.left v = mi else: p = nd.pivot nd.left = self.node(mi, p - (p&-p)//2) break else: nd.value = mi if nd.right: nd = nd.right v = ma else: p = nd.pivot nd.right = self.node(ma, p + (p&-p)//2) break def leftmost(self, nd): if nd.left: return self.leftmost(nd.left) return nd def rightmost(self, nd): if nd.right: return self.rightmost(nd.right) return nd def find_l(self, v): """ vより真に小さいやつの中での最大値(なければ-1) """ v += 1 nd = self.root prev = 0 if nd.value < v: prev = nd.value while True: if v <= nd.value: if nd.left: nd = nd.left else: return prev - 1 else: prev = nd.value if nd.right: nd = nd.right else: return prev - 1 def find_r(self, v): """ vより真に大きいやつの中での最小値(なければRoot) """ v += 1 nd = self.root prev = 0 if nd.value > v: prev = nd.value while True: if v < nd.value: prev = nd.value if nd.left: nd = nd.left else: return prev - 1 else: if nd.right: nd = nd.right else: return prev - 1 @property def max(self): """最大値の属性""" return self.find_l((1<<self.N)-1) @property def min(self): """最小値の属性""" return self.find_r(-1) def delete(self, v, nd = None, prev = None): """ 値がvのノードがあれば削除(なければ何もしない) """ v += 1 if not nd: nd = self.root if not prev: prev = nd while v != nd.value: prev = nd if v <= nd.value: if nd.left: nd = nd.left else: return else: if nd.right: nd = nd.right else: return if (not nd.left) and (not nd.right): if nd.value < prev.value: prev.left = None else: prev.right = None elif not nd.left: if nd.value < prev.value: prev.left = nd.right else: prev.right = nd.right elif not nd.right: if nd.value < prev.value: prev.left = nd.left else: prev.right = nd.left else: nd.value = self.leftmost(nd.right).value self.delete(nd.value - 1, nd.right, nd) def __contains__(self, v: int) -> bool: return self.find_r(v - 1) == v class node: """ノードをあらわすクラス v: 値 p: ピボット値 で初期化 """ def __init__(self, v, p): self.value = v self.pivot = p self.left = None self.right = None Trees = [BalancingTree(50) for _ in range(26)] N = int(input()) S = input() Q = int(input()) alphabets = list("abcdefghijklmnopqrstuvwxyz") c2n = {c: i for i, c in enumerate(alphabets)} for i in range(N): Trees[c2n[S[i]]].append(i+1) S = list(S) for _ in range(Q): tmp = list(input().split()) if tmp[0] == "1": _, i, c = tmp i = int(i) bef = S[i-1] if bef == c: continue Trees[c2n[bef]].delete(i) Trees[c2n[c]].append(i) S[i-1] = c else: _, l, r = tmp l = int(l) r = int(r) ans = 0 for char in range(26): res = Trees[char].find_r(l-1) if l <= res <= r: ans += 1 print(ans)
1
62,839,764,810,190
null
210
210
print('NYoe s'[len(set(map(int,input().split())))==2::2])
import sys def main(): for line in sys.stdin: A = list(map(int,line.split())) C = A[0]+A[1] count = 0 while True: C/=10 if C < 1: break count += 1 print(count+1) if __name__ == '__main__': main()
0
null
33,914,753,732,178
216
3