code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
import sys from collections import namedtuple, defaultdict from math import gcd input = sys.stdin.readline class Point: def __init__(self, x, y): g = gcd(abs(x), abs(y)) x //= g y //= g if x < 0: x *= -1 y *= -1 elif x == 0 and y < 0: y *= -1 self.x = x self.y = y def __eq__(self, other): return self.x == other.x and self.y == other.y def __hash__(self): return hash((self.x, self.y)) def __repr__(self): return f'({self.x}, {self.y})' def main(): n = int(input()) p = [] d = defaultdict(lambda: 0) zeros = 0 for _ in range(n): x, y = map(int, input().split()) if x == 0 and y == 0: n -= 1 zeros += 1 continue p.append(Point(x, y)) d[p[-1]] += 1 MOD = 10 ** 9 + 7 pw = [ pow(2, i, MOD) for i in range(n + 1) ] ans = 1 tot = 0 for x in d.keys(): if x.x > 0 and x.y >= 0 and Point(-x.y, x.x) in d: s = d[x] t = d[Point(-x.y, x.x)] tot += s + t value = (pw[s] + pw[t] - 1 + MOD) % MOD ans = ans * value % MOD ans = ans * pw[n - tot] % MOD ans = (ans - 1 + MOD + zeros) % MOD print(ans) main()
while True: H, W = map(int, input().split()) if H == 0 and W == 0: break for i in range(H): if i == 0 or i == H-1: print("#" * W) else: print("#" + "." * (W-2) + "#") print()
0
null
10,975,592,766,782
146
50
x, y, z = map(int, input().split()) y, x = x, y z, x = x, z print(x, y, z)
X, Y, Z = map(int, input().split()) print('{} {} {}'.format(Z, X, Y))
1
37,884,850,188,362
null
178
178
n = int(input()) c = list(input()) r = c.count('R') w = c.count('W') ans = 0 for i in range(r): if c[i] == 'R': pass elif c[i] == 'W': ans += 1 print(ans)
import bisect N = int(input()) c = list(input()) c_sorted = sorted(c) R_count = bisect.bisect_right(c_sorted, 'R') ans = 0 for i in range(R_count): if c[i] != 'R': ans += 1 print(ans)
1
6,296,170,261,120
null
98
98
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy # from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # # input = sys.stdin.readline # sys.setrecursionlimit(10**8) # mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) s = input() l = [ 'SUN','MON','TUE','WED','THU','FRI','SAT'] print(7 - l.index(s))
#!/usr/bin/env python3 import math n = int(input()) mod = 10**9+7 data = {} zero_zero = 0 for i in range(n): a, b = list(map(int, input().split())) # # print(a, b) if a == 0 and b == 0: zero_zero += 1 continue gcd = math.gcd(a, b) a, b = a//gcd, b//gcd if a < 0: a, b = -a, -b if a == 0: # (0, 1) a, b = 0, 1 elif b == 0: # (1, 0) a, b = 1, 0 # print(a, b) # print() if b <= 0: # (+, -) or (1, 0) if (-b, a) in data: data[(-b, a)][1] += 1 else: data[(-b, a)] = [0, 1] elif b > 0: # (+, +) or (1, 0) if (a, b) in data: data[(a, b)][0] += 1 else: data[(a, b)] = [1, 0] # print(data) # print(zero_zero) power_2 = [1] for i in range(1, 2*10**5+100): power_2.append(power_2[i-1]*2 % mod) ans = 1 # print(ans) # print() for (a, b), (l, m) in data.items(): ans *= (power_2[l]+power_2[m]-1) % mod # print(power_2[l]+power_2[m]-1) # print(ans) # print() ans = ans - 1 # removed not selected ans += zero_zero print(ans % mod) # count_pp = 0 # count_pm = 0 # ans = 0 # while(1): # pp_tmp = plus_plus[count_pp] # pm_tmp = plus_minus[count_pm] # print("pp_tmp", pp_tmp) # print("pm_tmp", pm_tmp) # if pp_tmp[0]*pm_tmp[0] + pp_tmp[1]*pm_tmp[1] == 0: # pp_mag, pm_mag = 1, 1 # magnitude # while(1): # if count_pp < len(plus_plus)-1: # if plus_plus[count_pp] == plus_plus[count_pp+1]: # pp_mag += 1 # count_pp += 1 # else: # break # else: # break # while(1): # if count_pm < len(plus_minus)-1: # if plus_minus[count_pm] == plus_minus[count_pm+1]: # pm_mag += 1 # count_pm += 1 # else: # break # else: # break # ans += pp_mag*pm_mag # elif pp_tmp[2]*pm_tmp[2] > -1: # count_pp += 1 # elif pp_tmp[2]*pm_tmp[2] < -1: # count_pm += 1 # if count_pp == len(plus_plus)-1: # break # if count_pm == len(plus_minus)-1: # break # print(1) # ans += zero_zero # n = n - zero_zero # count = ((n % mod) * ((n-1) % mod))//2 # count -= (negative) % mod # print(count % mod)
0
null
77,208,517,778,720
270
146
class UF(): def __init__(self, N): self._parent=[n for n in range(0, N)] self._size=[1] * N def find_root(self, x): if self._parent[x]==x:return x self._parent[x]=self.find_root(self._parent[x]) return self._parent[x] def unite(self, x, y): gx=self.find_root(x) gy=self.find_root(y) if gx==gy:return if self._size[gx]<self._size[gy]: self._parent[gx]=gy self._size[gy]+=self._size[gx] else: self._parent[gy]=gx self._size[gx]+=self._size[gy] def size(self, x): return self._size[self.find_root(x)] def samegroup(self, x, y): return self.find_root(x)==self.find_root(y) def groupnum(self): N=len(self._parent) ans=0 for i in range(N): if self.find_root(i)==i: ans+=1 return ans n,m=map(int,input().split()) UFa=UF(n) for i in range(m): x,y=map(int,input().split()) UFa.unite(x-1,y-1) ans=[] for i in range(n): ans.append(UFa.size(i)) print(max(ans))
import sys sys.setrecursionlimit(10**7) 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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし class UnionFind: def __init__(self,n): self.par = [i for i in range(n+1)] # 親のノード番号 self.rank = [0]*(n+1) self.X = [1]*(n+1) def find(self,x): # xの根のノード番号 if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self,x,y): # x,yが同じグループか否か return self.find(x) == self.find(y) def unite(self,x,y): # x,yの属するグループの併合 x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: x,y = y,x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.X[x] += self.X[y] N,M = MI() UF = UnionFind(N) for i in range(M): a,b = MI() if not UF.same_check(a, b): UF.unite(a,b) print(max(UF.X))
1
3,971,434,697,642
null
84
84
from collections import defaultdict def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,a,b = readInts() if (b-a)%2==0: print((b-a)//2) else: print(min(b-1,n-a,a+(b-a-1)//2,n-(a+b-1)//2))
def cal(S): tmp, a, cnt = S[0], 1, 0 flag = True for s in S[1:]: if S[0]!=s: flag=False if flag: a+=1 if tmp[-1]==s: s = '*' cnt += 1 tmp += s return a, cnt S = input().replace('\n', '') k = int(input()) ans = 0 if len(list(set(S)))==1: ans = len(S)*k//2 else: a, cnt = cal(S) b, _ = cal(S[::-1]) ans = cnt*k if S[0]==S[-1]: ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1) print(ans)
0
null
142,350,867,434,268
253
296
from collections import deque n = int(raw_input()) d = [0] * n f = [0] * n M = [[0]*n for _ in xrange(n)] color = [0] * n tt = 0 WHITE = 0 GRAY = 1 BLACK = 2 nt = [0] * n def next(u): for v in xrange(nt[u],n): nt[u] = v + 1 if M[u][v] == 1: return v return -1 def dfs_visit(r): global tt S = deque([]) S.append(r) color[r] = GRAY tt += 1 d[r] = tt while len(S) > 0: u = S[len(S)-1] v = next(u) if v != -1: if color[v] == WHITE: color[v] = GRAY tt += 1 d[v] = tt S.append(v) else: S.pop() color[u] = BLACK tt += 1 f[u] = tt return 0 def dfs(): for u in xrange(n): if color[u] == WHITE: dfs_visit(u) for u in xrange(n): print "{} {} {}".format(u+1, d[u], f[u]) return 0 def main(): for i in xrange(n): a = map(int, raw_input().split()) u = a[0]-1 k = a[1] for j in xrange(k): v = a[j+2] - 1 M[u][v] = 1 dfs() return 0 main()
a=int(input());print(a+a*a+a*a*a)
0
null
5,107,546,439,618
8
115
n = int(input()) sum = 0 for i in range(n) : if (i+1)%3 != 0 and (i+1)%5 != 0 : sum += i+1 print(sum)
x = int(input()) xd = x//100 if xd*100 <= x <= xd*105: print(1) else: print(0)
0
null
80,936,127,167,218
173
266
import sys while(1): H,W = map(int, raw_input().split()) if H==0 and W==0: break for i in range(H): for j in range(W): sys.stdout.write("#") print "" print ""
H,W,K = map(int,input().split()) HW = [list(input()) for _ in range(H)] ans = [[0 for _ in range(W)] for _ in range(H)] cnt = 0 mm = [] for h in range(H): if not("#" in HW[h]): continue mm.append(h) cnt += 1 flg = 1 for w in range(W): if HW[h][w]=="#" and not(flg): cnt += 1 ans[h][w]=cnt if flg and HW[h][w]=="#": flg = 0 continue j = 0 for h in range(H): if j<len(mm)-1 and h==mm[j]: j += 1 continue else: ans[h] = ans[mm[j]] for h in range(H): print(*ans[h])
0
null
72,021,179,587,070
49
277
def main(): k = int(input()) s = str(input()) output = '' if len(s) > k: for i in range(k): output += s[i] output += '...' else: output = s print(output) if __name__ == '__main__': main()
integer = int(input()) string = input() if len(string) > integer: print(string[:integer] + '...') else: print(string)
1
19,646,070,332,770
null
143
143
WA = { int(input()), int(input())} ans = {1, 2, 3} - WA print(ans.pop())
import math as mt a, b, c = map(int, input().split()) d = c - a - b if d>0 and d**2 > 4*a*b: print("Yes") else: print("No")
0
null
81,005,276,766,778
254
197
# encoding:utf-8 input = map(int, raw_input().split()) a, b = input if a == b: print("a == b") elif a > b: print("a > b") else: print("a < b")
values = input() a, b = [int(x) for x in values.split()] if a == b: print('a == b') elif a > b: print('a > b') else: print('a < b')
1
364,088,429,210
null
38
38
n,m,l=map(int,input().split()) a = [[0 for i in range(m)] for j in range(n)] #print(a) b = [[0 for i in range(1)] for j in range(m)] #print(b) A=[] B=[] for j in range (n): a = [int(x) for x in input().split()] A.append(a) #print(A) for i in range(m): b = [int(y) for y in input().split()] B.append(b) #print(B) #print(A[1][1]) for j in range (0,n): F=[] #print(j) for k in range (0,l): S=0 for i in range (0,m): B1=B[i][k] A1=A[j][i] #print(A1) #print(A1,B1,sep=" ") S=S+int(A1)*int(B1) F.append(S) #print(S,end='') #rint('@',end='') print(*F)
import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) 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 S(): return input() def LS(): return input().split() def satisfaction(d, last, c): res = 0 for i in range(26): res += c[i] * (d - last[i]) return res def main(): d = I() c = LI() s = LIR(d) t = IR(d) last = [0] * 26 satis = 0 for day in range(d): j = t[day] - 1 last[j] = day + 1 satis += s[day][j] satis -= satisfaction(day + 1, last, c) print(satis) main()
0
null
5,651,473,919,108
60
114
def insertion_sort(array, g, result): for i in range(g, len(array)): v = array[i] j = i - g while j >= 0 and array[j] > v: array[j + g] = array[j] j -= g result['count'] += 1 A[j + g] = v def g_gene(n): yield 1 for i in range(2, n): x = int((3 ** i - 1) / 2) if x < n: yield x else: raise StopIteration() def shell_sort(array, result): result['count'] = 0 G = list(reversed(list(g_gene(len(array))))) m = len(G) result['G'] = G result['m'] = m for i in range(m): insertion_sort(array, G[i], result) if __name__ == '__main__': import sys n = int(sys.stdin.readline()) A = [] for _ in range(n): A.append(int(sys.stdin.readline())) result = {} shell_sort(A, result) print(result['m']) print(' '.join(map(str, result['G']))) print(result['count']) for a in A: print(a)
N,K,S=map(int,input().split()) ans=[S]*K if S==10**9: ans.extend([S-1]*(N-K)) else: ans.extend([S+1]*(N-K)) print(*ans)
0
null
45,714,906,684,642
17
238
import sys def dfs(u): global time color[u] = "GRAY" time += 1 d[u] = time for v in range(n): if M[u][v] and color[v] == "WHITE": dfs(v) color[u] = "BLACK" time += 1 f[u] = time if __name__ == "__main__": n = int(sys.stdin.readline()) color = ["WHITE"] * n time = 0 d = [-1] * n f = [-1] * n M = [[0] * n for i in range(n)] for inp in sys.stdin.readlines(): inp = list(map(int, inp.split())) for i in inp[2:]: M[inp[0]-1][i-1] = 1 for i in range(n): if d[i] == -1: dfs(i) for i in range(n): print(i+1, d[i], f[i])
n = int(raw_input()) def dfs(u,t): global graph global found global timestamp if u in found: return t found.add(u) timestamp[u] = [-1,-1] timestamp[u][0] = t t += 1 for v in graph[u]: t = dfs(v,t) timestamp[u][1] = t t += 1 return t graph = [[] for i in range(n)] found = set() timestamp = {} for i in range(n): entry = map(int,raw_input().strip().split(' ')) u = entry[0] u -= 1 for v in entry[2:]: v -= 1 graph[u].append(v) t = 1 for i in range(n): t = dfs(i,t) for i in timestamp: print i+1,timestamp[i][0],timestamp[i][1]
1
2,656,046,628
null
8
8
n = int(input()) s = input() if n % 2 != 0: print('No') elif s[:n//2] == s[n//2:]: print("Yes") else: print("No")
import sys n=int(input()) s=input() if n%2==1: print("No") sys.exit() else: s1=s[:n//2] s2=s[n//2:] # print(s1,s2) if s1==s2: print("Yes") else: print("No")
1
146,216,082,409,452
null
279
279
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, X, M = map(int, readline().split()) n = 1 P = 1 while n < N: n *= 2 P += 1 pos = [[0] * M for _ in range(P)] value = [[0] * M for _ in range(P)] for r in range(M): pos[0][r] = r * r % M value[0][r] = r for p in range(P - 1): for r in range(M): pos[p + 1][r] = pos[p][pos[p][r]] value[p + 1][r] = value[p][r] + value[p][pos[p][r]] ans = 0 cur = X % M for p in range(P): if N & (1 << p): ans += value[p][cur] cur = pos[p][cur] print(ans) return if __name__ == '__main__': main()
A, B = map(str, input().split()) if len(A) == 1 and len(B) == 1: print(int(A)*int(B)) else: print(-1)
0
null
80,626,216,813,152
75
286
n,a,b=map(int,input().split()) p=a+b c=n%p d=n//p if c<a: print(d*a+c) else: print((d+1)*a)
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) H, W = map(int, readline().split()) import math if H == 1 or W == 1: print(1) exit() total = H * W ans = (total + 2 - 1) // 2 print(ans)
0
null
53,016,542,696,480
202
196
# 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())) inf = 1 sup = max(a) while inf < sup: x = (inf + sup) // 2 cut = 0 for a_i in a: cut += (a_i - 1) // x if cut <= k: sup = x else: inf = x + 1 print(sup)
1
6,524,055,534,678
null
99
99
########関数部分############## def Base_10_to_n(X, n): if (int(X/n)): return Base_10_to_n(int(X/n), n)+str(X%n) return str(X%n) ############################ #####関数をつかってみる.##### ######今回は二進数に変換###### n, k = map(int, input().split()) x10 = n x2 = Base_10_to_n(x10, k) ans = str(x2) print(len(ans))
N,P = map(int,input().split()) S = input() def solve(S,N,P): if P == 2: ans = 0 for i in range(N): if int(S[i])%P == 0: ans += i+1 return ans if P == 5: ans = 0 for i in range(N): if int(S[i])%P == 0: ans += i+1 return ans S = S[::-1] mod_list = [0]*P mod_list[0] = 1 mod = P tmp = 0 for i in range(N): tmp = (tmp + int(S[i])*pow(10,i,mod))%mod mod_list[tmp] += 1 ans = 0 for i in mod_list: ans += i*(i-1)//2 return ans print(solve(S,N,P))
0
null
61,402,505,322,170
212
205
N = int(input()) P = list(map(int,input().split())) mini = N+1 cnt = 0 for i in P: if mini > i: cnt += 1 mini = i print(cnt)
def abc152c_low_elements(): n = int(input()) p = list(map(int, input().split())) cnt = 1 min_val = p[0] for i in range(1, n): if min_val > p[i]: cnt += 1 min_val = min(min_val, p[i]) print(cnt) abc152c_low_elements()
1
85,225,548,382,840
null
233
233
# https://atcoder.jp/contests/abc152/tasks/abc152_e # 1 <= i < j <= N (i < j)について AiBi = AjBjが成り立つBの和の最小値 # LCM/Ai from collections import defaultdict from math import gcd MOD = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) lcm = A[0] for a in A: lcm = (lcm * a) // gcd(lcm, a) lcm %= MOD # フェルマーの小定理 a^{P-1} = 1 (mod P) ans = 0 for a in A: ans += lcm * pow(a, MOD - 2, MOD) % MOD ans %= MOD print(ans)
n = int(input()) playList = [] sumTerm = 0 for i in range(n) : song = input().split() song[1] = int(song[1]) playList.append(song) sumTerm += song[1] x = input() tmpSumTerm = 0 for i in range(n) : tmpSumTerm += playList[i][1] if playList[i][0] == x : print(sumTerm - tmpSumTerm) break
0
null
92,667,654,050,356
235
243
n,a,b = map(int,input().split()) if (a - b) % 2 == 0: print(min(abs(a-b) // 2, max(a-1, b-1), max(n-a, n-b))) else: print(min(max(a-1, b-1), max(n-a, n-b), (a+b-1)//2, (2 * n - a - b + 1)//2))
import sys sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inl = lambda: [int(x) for x in sys.stdin.readline().split()] ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) def solve(): n, a, b = inl() if (b - a) % 2 == 0: return (b - a) // 2 k = min(a - 1, n - b) return k + 1 + (b - a) // 2 print(solve())
1
109,065,428,052,102
null
253
253
while True: (H,W) = [int(x) for x in input().split()] if H == W == 0: break for hc in range(H): if hc == 0 or hc == H - 1: print('#'* W) else: print('#' + '.' * (W - 2) + '#') print()
import sys def euc(n,m): if max(n,m)%min(n,m) == 0: return min(n,m) else: return euc(min(n,m), max(n,m)%min(n,m)) for line in sys.stdin: a,b = [int(i) for i in line.split()] print(euc(a,b),int(a*b/euc(a,b)))
0
null
409,020,841,114
50
5
N, A, B = map(int, input().split()) if (B-A) % 2 == 0: print((B-A)//2) else: print(min((A-1+B-1+1)//2, (N-A+N-B+1)//2))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, A, B = MAP() if abs(A-B)%2 == 0: print(abs(A-B)//2) else: A, B = min(A, B), max(A, B) print(min((N-B)-(-(B-A)//2), A-1-(-(B-A)//2)))
1
109,618,482,056,188
null
253
253
s=input() print("YNeos"[s == len(s) * s[0]::2])
s = str(input()) ans = "No" for i in range(2): if(s[i]!=s[i+1]): ans = "Yes" print(ans)
1
54,566,323,304,560
null
201
201
n = int(input()) list_a = [i for i in range(1,n+1) if i % 3 ==0] list_b = [] for i in range (1,n+1): j = i while True: if j == 0: break elif j % 10 == 3: list_b.append(i) break j = j // 10 a = set(list_a) b = set(list_b) c =list(a | b) c.sort() print(" " + " ".join(map(str,c)))
N = int(input()) A = list(map(int,input().split())) mod = 10**9+7 a,s = 0,0 for i in range(N): a += s*A[i] s += A[i] a %= mod print(a)
0
null
2,380,917,324,912
52
83
import sys import math from functools import reduce N = str(input()) A = list(map(int, input().split())) M = 10 ** 6 sieve = [0] * (M+1) for a in A: sieve[a] += 1 def gcd(*numbers): return reduce(math.gcd, numbers) d = 0 for i in range(2, M+1): tmp = 0 for j in range(i,M+1,i): tmp += sieve[j] if tmp > 1: d = 1 break if d == 0: print('pairwise coprime') exit() if gcd(*A) == 1: print('setwise coprime') exit() print('not coprime')
# -*- coding: utf-8 -*- import math def g(nx, ny, nz): return nx ** 2 + ny ** 2 + nz ** 2 + nx * ny + ny * nz + nz * nx def solve(n): # min_z = max(1, int(math.sqrt(n) / 3)) max_z = max(1, int(math.sqrt(n - 2) - 1) if n > 2 else 1) # max_x = max(1, int(math.sqrt(n / 3) + 1)) counter = [0 for _ in range(n + 1)] for z in range(1, max_z + 1): for y in range(1, max_z + 1): for x in range(1, max_z + 1): gn = g(x, y, z) if gn <= n: counter[gn] += 1 for i in range(1, n + 1): print(counter[i]) N = int(input()) solve(N)
0
null
6,110,809,323,310
85
106
a = [1, 2, 3, 4, 5, 6, 7, 8, 9] b = [1, 2, 3, 4, 5, 6, 7, 8, 9] for x in a: for y in a: ans = x * y print(str(x)+'x'+str(y)+'='+str(ans))
N, M = map(int, input().split()) res = 0 if N >= 2: res += N * (N - 1) / 2 if M >= 2: res += M * (M - 1) / 2 print(int(res))
0
null
22,674,802,374,866
1
189
n = int(input()) s = input() t = s[:int(n / 2)] if s == t + t: print('Yes') else: print('No')
for i in range(1,10): for k in range(1,10): print("{0}x{1}={2}".format(i,k,i*k))
0
null
73,697,081,612,770
279
1
N = int(input()) K = int(input()) def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def contain_one(n): a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break return 9*a+(n//max_num) def contain_two(n): if n <=10: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10^a位まで for i in range(1, a): cnt += 9*9*i #10^a位 tmp = n // max_num cnt += 9*a*(tmp-1) #nの10^a桁より小さい数 tmp = n % max_num #怪しい if tmp != 0: cnt += contain_one(tmp) return cnt def contain_three(n): if n <=100: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10000以上の時ここがダメ for i in range(2, a): if i == 2: cnt += 9**2 * 9 else: #3H(a-2) = aCa-2 cnt += 9**2 * 9 * cmb(i, i-2) #aH2 #cnt += 9**2 * 9 * (i*(i+1)//2) # tmp = tmp * 3 # cnt += tmp tmp = n // max_num if a == 2: cnt += 9**2 * (tmp-1) else: cnt += 9**2 * (tmp-1) * cmb(a, a-2) tmp = n % max_num if tmp != 0: cnt += contain_two(tmp) return cnt if K == 1: print(contain_one(N)) elif K == 2: print(contain_two(N)) else: print(contain_three(N))
import sys sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inm = lambda: map(int, sys.stdin.readline().split()) inl = lambda: list(inm()) ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) ss, st = ins().split() a, b = inm() su = ins() def solve(): if su == ss: return (a - 1), b else: return a, (b - 1) print(*solve())
0
null
73,962,958,053,630
224
220
n = int(input()) x = list(map(int, input().split())) print(sum((xi - round(sum(x)/n))**2 for xi in x))
N,M,L=map(int, input().split()) def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(N): for i in range(N): for j in range(N): d[i][j]=min(d[i][j],d[i][k] + d[k][j]) return d d=[[float("inf")]*N for i in range(N)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(M): x,y,z=map(int,input().split()) d[x-1][y-1]=z d[y-1][x-1]=z for i in range(N): d[i][i]=0 #自身のところに行くコストは0 D=warshall_floyd(d) E=[[float("inf")]*N for i in range(N)] for i in range(N): for j in range(N): if D[i][j]==0: E[i][j]=0 elif D[i][j]<=L: E[i][j]=1 F=warshall_floyd(E) N=int(input()) for i in range(N): x,y=map(int,input().split()) if F[x-1][y-1]==float("inf"): print(-1) else: print(F[x-1][y-1]-1)
0
null
119,805,185,349,560
213
295
s = input() p = input() p_len = len(p) if p in s: print("Yes") else: for i in range(p_len): if (p[:i] == s[-i:]) and (p[i:] == s[:p_len - i]): print("Yes") break else: print("No")
n,k,s = map(int,input().split()) ans=[] cnt=n-k for i in range(k): ans.append(s) for j in range(cnt): if s==1: ans.append(2) elif s==10**9: ans.append((10**9)-1) else: ans.append(s+1) print(*ans)
0
null
46,674,540,974,698
64
238
N, K = map(int, input().split()) H = list(map(int, input().split())) H = sorted(H) hp = 0 for i in range(N-K): hp += H[i] print(hp)
N, K = map(int, input().split()) H = sorted(list(map(int, input().split()))) print(sum(H[:N - K]) if not N <= K else 0)
1
79,108,700,779,840
null
227
227
N, X, T = map(int, input().split()) ans = 0 if N % X == 0: ans = N//X * T else: ans = (N//X + 1) * T print(ans)
S = 0 N,X,T = map(int,input().split()) if N % X ==0: print((N // X)*T) else: print((N + X - 1)// X *T)
1
4,286,040,303,690
null
86
86
N=int(input()) print(int((N-1-(N+1)%2)/2))
def solve(n): if n % 2 == 0: return n // 2 - 1 else: return (n - 1) // 2 def main(): n = int(input()) res = solve(n) print(res) def test(): assert solve(4) == 1 assert solve(999999) == 499999 if __name__ == "__main__": test() main()
1
153,098,178,592,480
null
283
283
from collections import deque k = int(input()) count = 0 que = deque([1,2,3,4,5,6,7,8,9]) while que: q = que.popleft() count +=1 if count == k: print(q) exit() tmp = q%10 if tmp == 0: for i in range(0,2): nq = q*10+i que.append(nq) elif tmp == 9: for i in range(8,10): nq = q*10+i que.append(nq) else: for i in range(tmp-1, tmp+2): nq = q * 10 + i que.append(nq)
x = list(input().split()) y = list(map(int, input().split())) z = input() y[x.index(z)] -= 1 print("{0} {1}".format(y[0], y[1]))
0
null
55,984,767,285,112
181
220
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 998244353 def resolve(): n = int(input()) D = list(map(int, input().split())) MAX_L = max(D) + 1 cnt = [0] * MAX_L for d in D: cnt[d] += 1 if cnt[0] != 1 or D[0] != 0: print(0) exit() res = 1 for i in range(1, MAX_L): if cnt[i] == 0: print(0) break res *= pow(cnt[i - 1], cnt[i], mod) res %= mod else: print(res) if __name__ == '__main__': resolve()
a=int(input());print(a+a*a+a*a*a)
0
null
82,682,071,793,318
284
115
a, b, c, k = map(int, input().split()) ans = 0 if k <= a: ans = k elif k <= a+b: ans = a else: ans = 2*a +b - k print(ans)
A, B, C, K = map( int, input().split()) ret = min( A, K ) if A < K: ret -= max( 0, K - A - B ) print( ret )
1
21,911,769,850,180
null
148
148
print("YNeos"[2!=len(set(map(int,input().split())))::2])
li=list(map(int,input().split())) for i in li: if li.count(i)==2: print("Yes") break else: print("No")
1
68,090,702,826,630
null
216
216
import math x=int(input()) print(math.ceil((2000-x)/200))
r,c=map(int,input().split()) a = [] for i in range(r): a.append(list(map(int, input().split()))) a[i]+=[sum(a[i])] print(*a[i]) a=list(zip(*a[::-1])) for i in range(c):print(sum(a[i]),end=' ') print(sum(a[c]))
0
null
4,080,741,861,238
100
59
#import sys #sys.setrecursionlimit(10**9) H, N = map(int, input().split()) magic = [_ for _ in range(N)] for k in range(N): magic[k] = list(map(int, input().split())) magic[k].append(magic[k][0]/magic[k][1]) magic.sort(key = lambda x: x[2], reverse=True) ans = [0 for _ in range(H+1)] visited = [0] anskouho = [float('inf')] ans2 = float('inf') """ def solve(start, power, point, maryoku): if start == H: print(min(point, min(anskouho))) exit() elif start > H: anskouho.append(point) return 0 elif ans[start] != 0: return 0 else: visited.append(start) ans[start] = point solve(start+power, power, point+maryoku, maryoku) """ for k in range(N): for item in visited: #solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1]) start = item+magic[k][0] power = magic[k][0] point = ans[item]+ magic[k][1] maryoku = magic[k][1] for _ in range(10**5): if start == H: print(min(point, ans2)) exit() elif start > H: ans2 = min(ans2, point) break elif ans[start]!=0: break else: visited.append(start) ans[start] = point start += power point += maryoku print(ans2)
import sys def input(): return sys.stdin.readline().rstrip() def main(): h,n=map(int, input().split()) ab=[list(map(int, input().split())) for i in range(n)] ans=[0]*(4*10**4) for i in range(1,h+1): li = [ans[i-j[0]]+j[1] for j in ab] ans[i]=min(li) print(ans[h]) if __name__=='__main__': main()
1
81,241,996,422,078
null
229
229
from sys import stdin from collections import defaultdict from math import gcd def main(): MOD = 1000000007 N, *AB = map(int, stdin.buffer.read().split()) d = defaultdict(int) n_zeros = 0 for a, b in zip(AB[::2], AB[1::2]): if a == 0 and b == 0: n_zeros += 1 continue g = gcd(a, b) a, b = a // g, b // g if a * b > 0 or b == 0: c = (abs(a), abs(b)) else: c = (-abs(a), -abs(b)) d[c] += 1 ans = 1 n_not_paired = 0 for ab, n in d.items(): ab_pair = (-ab[1], -ab[0]) if ab_pair in d: if ab[0] > 0: m = d[ab_pair] ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD else: n_not_paired += n ans = (ans * pow(2, n_not_paired, MOD) + n_zeros - 1) % MOD print(ans) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(300000) from fractions import gcd from collections import defaultdict def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') N = I() d = defaultdict(int) zero = 0 for i in range(N): a, b = MI() if a == 0 and b == 0: zero += 1 continue g = gcd(a, b) a, b = a // g, b // g minus = (-1) ** ((a < 0) + (b < 0)) d[(minus * abs(a), abs(b))] += 1 ans = 1 seen = set() for a, b in d: if (a, b) not in seen: if (a, b) in [(1, 0), (0, 1)]: ainv, binv = b, a else: ainv, binv = b * (1 if a < 0 else -1), abs(a) lans = (2 ** d[(a, b)] - 1) lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0 lans += 1 ans = ans * lans % MOD seen.add((a, b)) seen.add((ainv, binv)) ans = (ans + zero) % MOD print((ans + MOD - 1) % MOD)
1
20,896,326,755,102
null
146
146
N = int(input()) S = input() if N % 2 !=0: print('No') else: n = int(N/2) s1 = S[:n] s2 = S[n:] if s1 == s2: print('Yes') else: print('No')
N = int(input()) S = input() print("Yes" if S[:N//2] == S[N//2:] else "No")
1
146,757,051,740,378
null
279
279
s = input() k = int(input()) ans = 0 soui = 0 moji = s[0] for i in range(1,len(s)): if s[i] == s[i-1] and soui == 0: ans += 1 soui = 1 elif soui == 1: soui = 0 flag = 0 a = 0 b = 0 while s[0] == s[a] and a != len(s)-1: a += 1 while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1: b += 1 if s[0] == s[len(s)-1]: flag = 1 for i in range(len(s)): if moji != s[i]: break elif i == len(s)-1: flag = 2 if flag == 1: print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2)))) elif flag == 2: print((k*len(s))//2) else: print(k*ans)
import math def getDistance( x, y, n, p ): dxy = 0 for i in range( n ): dxy += abs( x[i] - y[i] )**p return dxy**(1/float( p ) ) n = int( raw_input() ) x = [ float( i ) for i in raw_input( ).split( " " ) ] y = [ float( i ) for i in raw_input( ).split( " " ) ] print( getDistance( x, y, n, 1 ) ) print( getDistance( x, y, n, 2 ) ) print( getDistance( x, y, n, 3 ) ) dxy = [ 0 ]*(n+1) for i in range( n ): dxy[i] = abs( x[i] - y[i] ) print( max( dxy ) )
0
null
87,526,394,332,888
296
32
S = 0 N,D = input().split() N = int(N) D = int(D) X = [0]*N Y = [0]*N for i in range(N): X[i],Y[i] = map(int, input().split()) if ((X[i])**2 + (Y[i])**2) <= (D)**2: S = S + 1 print(S)
def main(): n,m = map(int,input().split()) print(n * (n - 1) // 2 + m * (m - 1) // 2) main()
0
null
25,710,747,284,400
96
189
N,M = map(int,input().split()) a_list = list(map(int,input().split())) list_n = [0]*(N+1) for i in range(M): a,b = map(int,input().split()) a_n = a_list[a-1] b_n = a_list[b-1] if a_n == b_n: list_n[a]-=10000 list_n[b]-=10000 elif a_n>b_n: list_n[a] +=1 list_n[b] -= 10000 elif a_n<b_n: list_n[b] +=1 list_n[a] -= 10000 count =0 for i in range(1,N+1): if list_n[i]>=0: count+=1 print(count)
""" UnionFindにはいろいろな実装があるが, 本問ではparents配列にノード数を保持する実装だと非常に簡単に解ける. 以下のようにしてノード数を保持する. 自身が子のとき, 親ノード番号を格納する. 自身が根のとき, ノード数を負の数で格納する. つまり, 負の数のときは自身が根であり, その絶対値がその木のノード数を表す. 初期化時は、すべてのノードを−1で初期化する. """ N,M = map(int,input().split()) #UnionFind木の実装 #-1で初期化し、併合のたびに-1していく par = [-1] * N #親 rank = [0] * N #木の深さ #木の根を求める def find(x): #par[x]が負のとき(自分が代表のとき)、自身を返す if par[x] < 0: return x else: return find(par[x]) #xとyの属する集合を併合 def unite(x,y): x = find(x) y = find(y) #もとから同じ集合のときは何もしない if (x == y): return #x側を常に小さくする if par[x] > par[y]: x, y = y, x #x側に併合する、その際xの代表にノード数を加算する par[x] += par[y] par[y] = x #xとyが同じ集合に属するかどうか def same(x,y): return find(x) == find(y) for i in range(M): x,y = map(int,input().split()) x -= 1; y -= 1 unite(x,y) ans = min(par) print(abs(ans))
0
null
14,413,543,390,400
155
84
def main(): n = int(input()) + 1 a = [int(x) for x in input().split()] q = [0] * n for i in range(n): q[i] = (q[i - 1] - a[i - 1]) * 2 if i != 0 else 1 # print(q[i]) if q[i] <= 0: print(-1) return if q[n - 1] < a[n - 1]: print(-1) return q[n - 1] = a[n - 1] s = q[n - 1] # print('--') # print(q[n - 1]) for i in range(n - 2, -1, -1): q[i] = min(q[i], q[i + 1] + a[i]) if q[i] == 0: print(-1) return # print(q[i]) s += q[i] print(s) main()
import sys import math sys.setrecursionlimit(10**9) def main(): N = int(input()) A = list(map(int,input().split())) dic = [{},{}] counted = [set(),set()] def count(x,type): type = type - 1 if x <= 0: return if not x in counted[type]: dic[type][x] = 1 counted[type].add(x) else: dic[type][x] += 1 for i in range(N): type1 = (i+1)-A[i] type2 = (i+1)+A[i] count(type1,1) count(type2,2) ans = 0 # print(dic,counted) for index,cnt in dic[0].items(): if index in counted[1]: ans += cnt * dic[1][index] print(ans) if __name__ == "__main__": main()
0
null
22,614,552,919,232
141
157
n = int(input()) li = list(map(int, input().split())) cnt = 0 flag = True while flag: flag = False for i in range(n-1,0,-1): if li[i] < li[i-1]: li[i], li[i-1] = li[i-1], li[i] flag = True cnt +=1 print(*li) print(cnt)
n = int(input()) a = 0 l = list(map(int, input().split())) for i in range(n): if i % 2 == 0: if l[i] % 2 != 0: a = a + 1 print(a)
0
null
3,936,201,992,800
14
105
while True: n,x=[int(i) for i in input().split()] if n==x==0: break c = 0 for i in range(1,n+1): for j in range(i+1,n+1): if (i+j+n >= x): for k in range(j+1,n+1): if(i+j+k == x): c+=1 break print(c)
moji = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' memo = {} for i in range(len(moji)): memo.setdefault(moji[i],i) #print(memo) n = int(input()) s = str(input()) ans = '' for i in range(len(s)): ans += moji[(memo[s[i]]+n)%26] print(ans)
0
null
67,868,312,138,510
58
271
while(True): a = input() if '?' in a: break print(int(eval(a)))
while True: a,op,b = input().split() a = int(a) b = int(b) if op =='?': break elif op =='+': print('%d'%(a+b)) elif op =='-': print('%d'%(a-b)) elif op =='*': print('%d'%(a*b)) elif op =='/': print('%d'%(a/b))
1
671,412,937,100
null
47
47
MOD = 10 **9 + 7 INF = 10 ** 10 import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main(): n,m,l = map(int,input().split()) dist = [[INF] * n for _ in range(n)] for _ in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 dist[a][b] = c dist[b][a] = c csr = csr_matrix(dist) dist1 = floyd_warshall(csr) dist1 = np.where(dist1 <= l,1,INF) cnt = floyd_warshall(dist1) q = int(input()) for _ in range(q): s,t = map(int,input().split()) s -= 1 t -= 1 print(-1 if cnt[s][t] == INF else int(cnt[s][t]) - 1) if __name__ == '__main__': main()
import sys input = sys.stdin.readline N,M,L = map(int, input().split()) INF = float("inf") dist1 = [[INF]*N for i in range(N)] dist2 = [[INF]*N for i in range(N)] for i in range(M): A,B,C = map(int, input().split()) A -= 1 B -= 1 dist1[A][B] = C dist1[B][A] = C for i in range(N): dist1[i][i] = 0 dist2[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): d = dist1[i][k]+dist1[k][j] if dist1[i][j] <= d: continue dist1[i][j] = d for i in range(N): for j in range(N): if dist1[i][j] > L or i==j: continue dist2[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): d = dist2[i][k]+dist2[k][j] if dist2[i][j] <= d: continue dist2[i][j] = d Q = int(input()) for i in range(Q): s,t = map(int, input().split()) print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1)
1
173,753,854,819,652
null
295
295
k = int(input()) s = str(input()) if len(s) > k: print(s[:k], end='') print("...") else: print(s)
# S の長さが K 以下であれば、S をそのまま出力してください。 # S の長さが K を上回っているならば、 # 先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。 # K は 1 以上 100 以下の整数 # S は英小文字からなる文字列 # S の長さは 1 以上 100 以下 K = int(input()) S = str(input()) if K >= len(S): print(S) else: print((S[0:K] + '...'))
1
19,661,449,767,692
null
143
143
def calc_matrix(A, B, size): n, m, l = size # print(n, m, l) results = [] for i in range(n): row_data = [] for j in range(l): products = [] for k in range(m): products.append(A[i][k] * B[k][j]) # print('C[{0}][{1}] = {2}'.format(i, j, sum(products))) row_data.append(sum(products)) results.append(row_data) return results if __name__ == '__main__': # ??????????????\??? A = [] B = [] # A.append([1, 2]) # A.append([0, 3]) # A.append([4, 5]) # B.append([1, 2, 1]) # B.append([0, 3, 2]) n, m, l = [int(x) for x in input().split(' ')] for i in range(n): A.append([int(x) for x in input().split(' ')]) for i in range(m): B.append([int(x) for x in input().split(' ')]) # ??????????????? results = calc_matrix(A, B, (n, m, l)) # ??????????????? for row in results: print(' '.join(map(str, row)))
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" def main(): h,n = map(int,ipt().split()) atks = [tuple(map(int,ipt().split())) for i in range(n)] dam = [10**18]*(h+1) dam[0] = 0 for i in range(1,h+1): for aj,bj in atks: if aj > i: if dam[i] > bj: dam[i] = bj elif dam[i] > dam[i-aj]+bj: dam[i] = dam[i-aj]+bj print(dam[h]) return None if __name__ == '__main__': main()
0
null
41,154,030,078,380
60
229
import sys def input(): return sys.stdin.readline().strip() def resolve(): x,y=map(int, input().split()) ans=0 if x==3: ans+=100000 elif x==2: ans+=200000 elif x==1: ans+=300000 if y==3: ans+=100000 elif y==2: ans+=200000 elif y==1: ans+=300000 if x==1 and y==1: ans+=400000 print(ans) resolve()
X,Y = map(int,input().split()) money = [300000,200000,100000] ans = 0 if X - 1 < 3: ans += money[X - 1] if Y - 1 < 3: ans += money[Y - 1] if X == 1 and Y == 1: ans += 400000 print(ans)
1
140,369,315,939,996
null
275
275
dts_s = input().split() dts_i = [int(n) for n in dts_s] if dts_i[0]/dts_i[1] > dts_i[2]: print("No") else: print("Yes")
D, T, S = [int(i) for i in input().split()] out = 'Yes' if D <= T * S else 'No' print(out)
1
3,559,027,710,688
null
81
81
# coding:UTF-8 import sys from math import factorial MOD = 10 ** 9 + 7 INF = 10000000000 def main(): # ------ 入力 ------# n = int(input()) # 数字 # 定数行入力 x = n dList = [list(map(int, input().split())) for _ in range(x)] # スペース区切り連続数字(行列) # ------ 処理 ------# flg = 1 for i in range(n-2): if dList[i][0] == dList[i][1]: if dList[i+1][0] == dList[i+1][1]: if dList[i+2][0] == dList[i+2][1]: flg = 0 # ------ 出力 ------# if flg == 0: print("Yes") else: print("No") if __name__ == '__main__': main()
N=int(input()) cnt=0 ans="No" for i in range(N): x,y=input().split() if x==y: cnt=cnt+1 else: cnt=0 if cnt>=3: ans="Yes" print(ans)
1
2,506,173,792,290
null
72
72
while 1: numbers = [i for i in raw_input()] if numbers[0] == '0': break print sum(map(int,numbers))
A = [input().split() for _ in range(3)] N = int(input()) c = [[False]*3 for _ in range(3)] for _ in range(N): B = input() for i in range(3): if B in A[i]: c[i][A[i].index(B)] = True def solve(c): y = "Yes" n = "No" for i in range(3): if c[i][0] and c[i][1] and c[i][2]: return y if c[0][i] and c[1][i] and c[2][i]: return y if c[0][0] and c[1][1] and c[2][2]: return y if c[0][2] and c[1][1] and c[2][0]: return y return n print(solve(c))
0
null
30,899,096,538,122
62
207
n,k = map(int,input().split()) a = list(map(int,input().split())) ML = 50 r = min(ML,k) for l in range(r): imos = [0]*(n+1) for i in range(n): left = max(0,i-a[i]) right = min(n,i+a[i]+1) imos[left] += 1 imos[right] -= 1 c = 0 for i in range(n): c += imos[i] a[i] = c print(*a)
from collections import deque N = int(input()) # 頂点数 conj = [[] for _ in range(N)] for i in range(N): # 各頂点での進める先の候補の集合 L = list(map(int, input().split())) for a in L[2:]: conj[i].append(a-1) # 頂点番号をデクリメント start = 0 visit = [False]*N # 訪れたかどうかをメモ second_visit = [False]*N # 二度目に訪れた事をメモ next_set = deque() # 次に進む候補を列挙する。スタック(右から取り出す = pop)だと深さ優先になり、キュー(左から取り出す = popleft)だと幅優先になる next_set.append((start, 0)) # スタート地点を決める。第二成分は時刻を表す。 visit[start] = True # スタート地点は最初から踏んでいる。 res = [-1 for _ in range(N)] res[0] = 0 while next_set: # p = [] になったら止める p, t = next_set.popleft() # 要素を消去して、消去した要素を出力 for q in conj[p]: # 頂点 p から進める経路の候補から一つ選ぶ if not visit[q]: # 訪れた事がない場所のみ進む。壁などの条件がある場合は、ここに " grid[p] != 壁 " 等を追加する visit[q] = True # 頂点 q に一度訪れた事をメモ (for の前に書くと、ここで選ばれた q が最短であるはずなのに、違う経路でvisit = Trueを踏んでしまう可能性がある) res[q] = t + 1 next_set.append((q, t + 1)) # p から q へと移動。時刻を 1 進める for i in range(N): print(i+1, res[i])
0
null
7,669,727,738,108
132
9
n = int(input()) mod = 10 ** 9 + 7 s = 10 ** n s0 = 9 ** n s9 = 9 ** n sb = 8 ** n ans = s - s0 - s9 + sb print(ans % mod)
n = int(input()) mod = 1000000007 def _mod(x, y): res = 1 for i in range(y): res = (res * x) % mod return res ans = _mod(10, n) - _mod(9, n) - _mod(9, n) + _mod(8, n) ans %= mod print(ans)
1
3,175,066,514,928
null
78
78
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 10**9 + 7 # 998244353 input = lambda:sys.stdin.readline().rstrip() class modfact(object): def __init__(self, n): fact, invfact = [1] * (n + 1), [1] * (n + 1) for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD invfact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD self._fact, self._invfact = fact, invfact def inv(self, n): return self._fact[n - 1] * self._invfact[n] % MOD def fact(self, n): return self._fact[n] def invfact(self, n): return self._invfact[n] def comb(self, n, k): if k < 0 or n < k: return 0 return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD def perm(self, n, k): if k < 0 or n < k: return 0 return self._fact[n] * self._invfact[n - k] % MOD def resolve(): n, k = map(int, input().split()) mf = modfact(n) res = 0 for i in range(min(k + 1, n)): res += mf.comb(n, i) * mf.comb(n - 1, i) % MOD res %= MOD print(res) resolve()
S = int(input()) h = S // 3600 m = S % 3600 // 60 s = (S % 3600) - (m * 60) print(h,m,s,sep=':')
0
null
33,857,640,443,648
215
37
import sys import math import fractions input = lambda: sys.stdin.readline().rstrip() mod = 10**9 + 7 def factorize(n): b = 2 fct = dict() while b * b <= n: while n % b == 0: n //= b if b in fct: fct[b] += 1 else: fct[b] = 1 b = b + 1 if n > 1: if b in fct: fct[n] += 1 else: fct[n] = 1 return fct def divmod(x, mod=10**9 + 7): return pow(x, mod - 2, mod) def solve(): N = int(input()) A = list(map(int, input().split())) B = [[1] for _ in range(N)] fac_list = dict() for i in range(N): d = factorize(A[i]) for k, v in d.items(): fac_list[k] = max(fac_list.get(k, 0), v) lcm = 1 for k, v in fac_list.items(): lcm *= (k**v) lcm %= mod ans = 0 for i in range(N): ans += divmod(A[i]) ans %= mod ans *= lcm ans %= mod print(ans) if __name__ == '__main__': solve()
from math import gcd from functools import reduce N = int(input()) A = [int(i) for i in input().split()] mod = 10**9 + 7 def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) num = lcm_list(A)%mod ans = 0 for a in A: ans += (num * pow(a, mod-2, mod))%mod ans %= mod print(ans)
1
87,310,330,027,998
null
235
235
h, w, n = (int(input()) for i in range(3)) print(-(-n // max(h, w)))
h = int(input()) w = int(input()) n = int(input()) cnt = 0 ans = 0 while ans < n: if h < w: ans += w h -= 1 else: ans += h w -= 1 cnt += 1 print(cnt)
1
89,092,715,174,746
null
236
236
n,m,x=map(int,input().split()) ca=[] ans=10**9 for i in range(n): tmp=list(map(int,input().split())) ca.append(tmp) for p in range(2**n): i_bin = (bin(p)[2:]).zfill(n) fl=1 for i in range(1,m+1): ttl=sum([int(i_bin[k])*ca[k][i] for k in range(n)]) if ttl<x: fl=0 ansc=sum([int(i_bin[k])*ca[k][0] for k in range(n)]) if fl and ansc<ans: ans=ansc if ans==10**9: print(-1) else: print(ans)
N = int(input()) a = N // 100 if 0 <= N - 100 * a <= 5 * a: print(1) else: print(0)
0
null
74,411,261,484,704
149
266
import sys sys.setrecursionlimit(10**9) def main(): n, x, t = map(int, input().split()) if n % x == 0: print((n//x)*t) else: print((n//x+1)*t) return if __name__ == "__main__": main()
n, x, t = map(int, input().split()) ans = t *(n // x) if n%x == 0: print(ans) else: print(ans + t)
1
4,213,511,003,768
null
86
86
board = [list(map(int,input().split())) for i in range(3)] num = int(input()) for n in range(num): bi = int(input()) for i in range(3): for j in range(3): if board[i][j] == bi: board[i][j] = 0 #横 for i in range(3): if board[i][0] == board[i][1] == board[i][2] == 0: print("Yes") exit() #縦 for i in range(3): if board[0][i] == board[1][i] == board[2][i] == 0: print("Yes") exit() if board[0][0] == board[1][1] == board[2][2] == 0: print("Yes") exit() if board[0][2] == board[1][1] == board[2][0] == 0: print("Yes") exit() print("No")
target = input() now_height = [] now_area = [0] answer = [] continued = 0 depth = 0 depth_list = [] for t in target: # print(now_height,depth_list,now_area,answer,continued) if t == '\\': now_height.append(continued) depth_list.append(depth) now_area.append(0) depth -= 1 elif t == '_': pass elif t == '/' and len(now_height) > 0: depth += 1 started = now_height.pop() temp_area = continued - started # print(depth_list[-1],depth) now_area[-1] += temp_area if depth > depth_list[-1]: while depth > depth_list[-1]: temp = now_area.pop() now_area[-1] += temp depth_list.pop() continued += 1 now_area = list(filter(lambda x:x != 0,now_area)) answer.extend(now_area) print(sum(answer)) print(len(answer),*answer)
0
null
30,021,122,689,348
207
21
def main(): N = int(input()) a = [] for _ in range(N): a.append(list(map(int, input().split()))) for x in range(N): a[x].sort(reverse = True) if a[x][0] ** 2 == a[x][1] ** 2 + a[x][2] ** 2: print("YES") else: print("NO") if __name__ == "__main__": main()
import sys n = int(input()) for i in range(n): ns = [x * x for x in map(int, input().split())] if ns[0] + ns[1] == ns[2] or ns[0] + ns[2] == ns[1] or ns[1] + ns[2] == ns[0]: print("YES") else: print("NO")
1
311,559,028
null
4
4
from string import ascii_lowercase, ascii_uppercase s = open(0).read() ans = [0]*26 for c in s: i = ascii_lowercase.find(c) if i > -1: ans[i] += 1 i = ascii_uppercase.find(c) if i > -1: ans[i] += 1 for c, t in zip(ascii_lowercase, ans): print("%s : %d" % (c, t))
import sys def input(): return sys.stdin.readline().rstrip() def main(): a,b,n=map(int, input().split()) if b<=n: n=b-1 print(((a*n)//b) - (a*(n//b))) if __name__ == '__main__': main()
0
null
14,977,582,760,140
63
161
n = int(input()) s = input() ans = '' for c in s: nc_ord = ord(c) + n while nc_ord > ord('Z'): nc_ord -= 26 ans += chr(nc_ord) print(ans)
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" N = int(input()) S = input() ans = [] for c in S: print(abc[(abc.index(c) + N) % len(abc)], end = "")
1
134,104,258,927,908
null
271
271
a, b = map(int, input().split()) print("{} {} {:.12f}".format(a // b, a % b, a * 1.0 / b))
val = map(int, raw_input().split()) ans1 = val[0] / val[1] ans2 = val[0] % val[1] ans3 = format(val[0] / float(val[1]), '.5f') print("{} {} {}".format(ans1, ans2, ans3))
1
599,777,091,650
null
45
45
class Bit: """ used for only int(>=0) 1-indexed (ignore 0-index) """ def __init__(self, n): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ def get_less_than_x_cnt(self, x): """ 累積和がx未満 の個数 """ lb_pos, lb_sum = self.lower_bound(x) return lb_pos-1 def get_less_than_and_x_cnt(self, x): """ 累積和がx以下 の個数 """ lb_pos, lb_sum = self.lower_bound(x+1) return lb_pos-1 def get_more_than_x_cnt(self, x): """ 累積和がxより大きい 個数 """ return self.size - self.get_less_than_and_x_cnt(x) def main(): n = int(input()) s = list(input()) q = int(input()) ql = [] for _ in range(q): num,a,b = map(str, input().split()) ql.append((num,a,b)) alp_d = {chr(ord('a') + i): Bit(n) for i in range(26)} for i, si in enumerate(s): alp_d[si].add(i+1,1) for query in ql: a,b,c = query if a == '1': b = int(b) before = s[b-1] alp_d[before].add(b, -1) alp_d[c].add(b,1) s[b-1] = c else: l,r = int(b),int(c) cnt = 0 for v in alp_d.values(): if v.sum(r)-v.sum(l-1) > 0: cnt += 1 print(cnt) if __name__ == "__main__": main()
import sys import itertools # import numpy as np import time import math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque from itertools import permutations sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) N = int(input()) S = list(input()) Q = int(input()) q_list = [list(input().split()) for _ in range(Q)] bit_tree = [[0] * (N+1) for _ in range(26)] def BIT_add(i, tree): while i <= N: tree[i] += 1 i += i&(-i) def BIT_sub(i, tree): while i <= N: tree[i] -= 1 i += i&(-i) def BIT_sum(i, tree): s = 0 while i: s += tree[i] i -= i&(-i) return s for i in range(N): x = ord(S[i]) - ord('a') BIT_add(i + 1, bit_tree[x]) for q in range(Q): line = q_list[q] if line[0] == '1': i, c = line[1:] i = int(i) - 1 old_c = ord(S[i]) - ord('a') new_c = ord(c) - ord('a') BIT_sub(i + 1, bit_tree[old_c]) BIT_add(i + 1, bit_tree[new_c]) S[i] = c else: l, r = map(int, line[1:]) now = 0 for i in range(26): cnt = BIT_sum(r, bit_tree[i]) - BIT_sum(l - 1, bit_tree[i]) if cnt > 0: now += 1 print(now)
1
62,408,030,121,710
null
210
210
n = int(input()) def binary_search(l, target): left = 0 right = len(l) while left<right: mid = (left+right)//2 if target == l[mid]: return True elif target < l[mid]: right = mid else: left = mid+1 return False seki = [i*j for i in range(1, 10) for j in range(1, 10)] seki.sort() if binary_search(seki, n): print('Yes') else: print('No')
N = int(input()) for i in range(1,10): for j in range(1,10): temp = i*j if N == temp: print("Yes") exit() print("No")
1
160,533,161,993,050
null
287
287
while True: inVal = input().split() if inVal[1] == "?": break if inVal[1] == "+": print(int(inVal[0]) + int(inVal[2])) elif inVal[1] == "-": print(int(inVal[0]) - int(inVal[2])) elif inVal[1] == "*": print(int(inVal[0]) * int(inVal[2])) elif inVal[1] == "/": print(int(inVal[0]) // int(inVal[2]))
#import sys #input = sys.stdin.readline def main(): a, b ,c, d = map( int, input().split()) A = [a*c, a*d, b*c, b*d] if a < b: A.append((a+1)*c) A.append((b-1)*c) A.append((a+1)*d) A.append((b-1)*d) if c < d: A.append(a*(c+1)) A.append(a*(d-1)) A.append(b*(c+1)) A.append(b*(d-1)) if a < b and c < d: A.append((a+1)*(c+1)) A.append((a+1)*(d-1)) A.append((b-1)*(c+1)) A.append((b-1)*(d-1)) print(max(A)) if __name__ == '__main__': main()
0
null
1,867,394,563,408
47
77
N = int(input()) print(N+N*N+N*N*N)
f=input n,s,q=int(f()),list(f()),int(f()) d={chr(97+i):[] for i in range(26)} for i in range(n): d[s[i]]+=[i] from bisect import * for i in range(q): a,b,c=f().split() b=int(b)-1 if a=='1': if s[b]==c: continue d[s[b]].pop(bisect(d[s[b]],b)-1) s[b]=c insort(d[c],b) else: t=0 for l in d.values(): m=bisect(l,b-1) if m<len(l) and l[m]<int(c): t+=1 print(t)
0
null
36,417,116,246,020
115
210
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n, m, k = map(int, input().split()) a = np.array(readline().split(), np.int64) b = np.array(readline().split(), np.int64) aa = a.cumsum() ba = b.cumsum() r = np.searchsorted(ba, k, side='right') for i1, aae in enumerate(aa): if k < aae: break r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1) print(r) if __name__ == '__main__': main()
n, m, k = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) asum = [0] bsum = [0] for i in range(len(aa)): asum.append(asum[i]+aa[i]) for i in range(len(bb)): bsum.append(bsum[i]+bb[i]) j = len(bsum)-1 ans = 0 for i in range(len(asum)): while j >= 0: if k >= asum[i] + bsum[j]: ans = max(ans, i+j) break else: j -= 1 print(ans)
1
10,696,745,475,712
null
117
117
N = int(input()) if N <= 9: print(N) exit() A = [[] for _ in range(11)] A[0] = [1,2,3,4,5,6,7,8,9] now = 9 keta = 1 while True: for x in A[keta-1]: x = str(x) last = int(x[-1]) if last - 1 >= 0: temp = x+str(last-1) A[keta].append(int(temp)) now += 1 if now == N: print(temp) exit() temp = x+str(last) A[keta].append(int(temp)) now += 1 if now == N: print(temp) exit() if last+1 <= 9: temp = x+str(last+1) A[keta].append(int(temp)) now += 1 if now == N: print(temp) exit() keta += 1
# Can't Wait for Holiday S = input() if S == 'SUN': a = 0 elif S == 'MON': a = 1 elif S == 'TUE': a = 2 elif S == 'WED': a = 3 elif S == 'THU': a = 4 elif S == 'FRI': a = 5 elif S == 'SAT': a = 6 answer = 7 - a print(answer)
0
null
86,519,552,764,710
181
270
X,Y=map(int,input().split()) M=[0]*206 M[0],M[1],M[2]=300000,200000,100000 if X+Y==2: print(1000000) else: print(M[X-1]+M[Y-1])
N = int(input()) s = list(input()) for i in range(len(s)): if ord(s[i])+N-ord('A') < 26: s[i] = chr(ord(s[i])+N) else: s[i] = chr(ord(s[i])+N-26) print(''.join(s))
0
null
137,370,989,521,866
275
271
import sys class Card: def __init__(self, card): self.card = card self.mark = card[0] self.value = card[1] def equals(self, other): if self.mark != other.mark: return False if self.value != other.value: return False return True def __str__(self): return self.card def print_cards(cards, cards_): n = len(cards) same = True for i in range(n): if cards_ != None and cards[i].equals(cards_[i]) == False: same = False sys.stdout.write(str(cards[i])) if i != n - 1: sys.stdout.write(' ') print() return same def swap(cards, i, j): temp = cards[i] cards[i] = cards[j] cards[j] = temp def bubble_sort(cards): n = len(cards) for i in range(n): for j in range(n - 1, i, -1): if cards[j].value < cards[j - 1].value: swap(cards, j, j - 1) def selection_sort(cards): n = len(cards) for i in range(n): mini = i for j in range(i, n): if cards[j].value < cards[mini].value: mini = j if mini != i: swap(cards, i, mini) n = int(input()) input_list = list(map(str, input().split())) cards1 = [None] * n cards2 = [None] * n for i in range(n): cards1[i] = Card(input_list[i]) cards2[i] = Card(input_list[i]) bubble_sort(cards1) selection_sort(cards2) print_cards(cards1, None) print('Stable') stable = print_cards(cards2, cards1) if stable == True: print('Stable') else: print('Not stable')
#coding:utf-8 ''' a ÷ b : d (整数) a ÷ b の余り : r (整数) a ÷ b : f (浮動小数点数) ''' a, b = map(int, input().split()) d = a // b r = a % b f = a / b print('%d %d %.8f' % (d, r, f))
0
null
311,425,065,898
16
45
from collections import defaultdict from math import gcd mod = 10 ** 9 + 7 n = int(input()) fishes = defaultdict(int) zero_zero = 0 zero = 0 inf = 0 for _ in range(n): a, b = map(int, input().split()) if a == 0 and b == 0: zero_zero += 1 elif a == 0: zero += 1 elif b == 0: inf += 1 else: div = gcd(a, b) a //= div b //= div if b < 0: a *= -1 b *= -1 key = (a, b) fishes[key] += 1 def get_bad_pair(fish): a, b = fish if a < 0: a *= -1 b *= -1 return (-b, a) ans = 1 counted_key = set() for fish_key, count in fishes.items(): if fish_key in counted_key: continue bad_pair = get_bad_pair(fish_key) if bad_pair in fishes: pair_count = fishes[bad_pair] pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1 counted_key.add(bad_pair) else: pattern = pow(2, count, mod) ans = ans * pattern % mod ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1 if zero_zero: ans += zero_zero ans -= 1 print(ans % mod)
N = input() K = int(input()) m = len(N) dp = [[[0] * (K+1) for _ in range(2)] for _ in range(m+1)] dp[0][0][0] = 1 for i in range(1,m+1): l = int(N[i-1]) for k in range(K+1): if k-1>=0: if l!=0: dp[i][0][k]=dp[i-1][0][k-1] dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1]+dp[i-1][0][k] + (l-1) * dp[i-1][0][k-1] else: dp[i][0][k] = dp[i-1][0][k] dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1] else: dp[i][0][k] = 0 dp[i][1][k] = 1 print(dp[m][0][K] + dp[m][1][K])
0
null
48,228,363,069,958
146
224
a,b = input().split() a = int(a) b = int(b) d = a // b r = a % b f = a / b f = "{0:.8f}".format(f) fmt = "{v} {c} {n}" s = fmt.format(v = d,c = r,n = f) print(s)
n, a, b = map(int, input().split()) ans = pow(2,n,10**9+7) bunshi = 1 bunbo = 1 for i in range(a): bunshi = (bunshi * (n-i)) % (10**9+7) bunbo = (bunbo * (i+1)) % (10**9+7) ans = (ans - bunshi*pow(bunbo,-1,10**9+7) - 1) % (10**9+7) for i in range(a,b): bunshi = (bunshi * (n-i)) % (10**9+7) bunbo = (bunbo * (i+1)) % (10**9+7) ans = (ans - bunshi*pow(bunbo,-1,10**9+7)) % (10**9+7) print(ans)
0
null
33,584,873,231,260
45
214
n, p = map(int, input().split()) if p in (2, 5): c = 0 for i, x in enumerate(map(int, input()[::-1])): if x % p == 0: c += n-i print(c) else: c = [0] * p y = 0 t = 1 for x in map(int, input()[::-1]): y = (y + t*x) % p c[y] += 1 t = (10 * t) % p print(sum(i * (i-1) // 2 for i in c) + c[0])
class BIT: from operator import add, sub, mul, floordiv X_unit = 0 X_f = add X_f_rev = sub def __init__(self, seq): N = len(seq) self.N = N self.X = seq[:] for i in range(self.N): j = i + ((i+1) & -(i+1)) if j < self.N: self.X[j] = self.X_f(self.X[i], self.X[j]) def set_val(self, i, x): while(i < self.N): self.X[i] = self.X_f(self.X[i], x) i += (i+1) & -(i+1) def cum_val(self, i): res = self.X_unit while(i > -1): res = self.X_f(res, self.X[i]) i -= (i+1) & -(i+1) return res #区間[L, R) def fold(self, L, R): return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1)) def bisect_left(self, w): if w > self.cum_val(self.N - 1): return self.N elif self.N == 2: return 1 n = 2**((self.N - 1).bit_length() - 1) res = 0 while(n): if res + n - 1 > self.N - 1: n //= 2 continue if w <= self.X[res + n - 1]: n //= 2 else: w -= self.X[res + n - 1] res += n n //= 2 return res def bisect_right(self, w): if w >= self.cum_val(self.N - 1): return self.N elif self.N == 2: return 1 n = 2**((self.N - 1).bit_length() - 1) res = 0 while(n): if res + n - 1 > self.N - 1: n //= 2 continue if w < self.X[res + n - 1]: n //= 2 else: w -= self.X[res + n - 1] res += n n //= 2 return res def lower_bound(self, w): ans = self.bisect_right(self.cum_val(w)) if ans == self.N: return -1 else: return ans def upper_bound(self, w): ans = self.bisect_left(self.cum_val(w-1)) return ans N = int(input()) S = list(input()) L = [BIT([0]*N) for _ in range(26)] for i in range(N): L[ord(S[i])-97].set_val(i, 1) Q = int(input()) for _ in range(Q): q, a, b = input().split() if q == "1": a = int(a) L[ord(S[a-1])-97].set_val(a-1, -1) L[ord(b)-97].set_val(a-1, 1) S[a-1] = b else: a, b = int(a), int(b) ans = 0 for i in range(26): if L[i].fold(a-1, b) >= 1: ans += 1 print(ans)
0
null
60,287,880,824,810
205
210
N = int(input()) alist = list(map(int, input().split())) k = 1 if 0 in alist: print(0) else: for i in range(0,N): k = k*alist[i] if k > 1000000000000000000: k= -1 break print(k)
import sys input = sys.stdin.readline from collections import * def bfs(): q = deque([(0, -1)]) visited = [False]*N visited[0] = True ans = [-1]*(N-1) while q: v, prev = q.popleft() now = 0 for nv in G[v]: if not visited[nv]: if now==prev: now += 1 visited[nv] = True ans[idx[(min(v, nv), max(v, nv))]] = now q.append((nv, now)) now += 1 return ans N = int(input()) G = [[] for _ in range(N)] idx = defaultdict(int) for i in range(N-1): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) idx[(min(a-1, b-1), max(a-1, b-1))] = i ans = bfs() print(max(ans)+1) for ans_i in ans: print(ans_i+1)
0
null
76,001,135,393,820
134
272
X, Y, A, B, C = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) r.sort() R = p[:X] G = q[:Y] i = X - 1 j = Y - 1 con = True while con and len(r) > 0: rr = r.pop() if R[i] < G[j]: if R[i] < rr: R[i] = rr i -= 1 continue else: con = False else: if G[j] < rr: G[j] = rr j -= 1 continue else: con = False print(sum(R) + sum(G))
X, Y, A, B, C = map(int, input().split()) ps = list(map(int, input().split())) qs = list(map(int, input().split())) rs = list(map(int, input().split())) ps = sorted(ps, reverse=True)[:X] qs = sorted(qs, reverse=True)[:Y] rs = sorted(ps+qs+rs, reverse=True)[:X+Y] r = sum(rs) print(r)
1
44,913,766,716,292
null
188
188
import math import sys n = int(input()) a = list(map(int, input().split())) ga = a[0] for i in range(n): ga = math.gcd(ga, a[i]) if ga != 1: print("not coprime") sys.exit() m = 1000000 b = [0]*(m+1) #高速素因数分解 for i in range(2, m): if b[i] != 0: continue j = 1 while True: t = i * j if t > m: break if b[t] == 0: b[t] = i j += 1 d = {} for i in a: p = i #pが1になるまで重複素因子があるかを調べる while p != 1: if p in d: print("setwise coprime") sys.exit() d[p] = 1 p = int(p/b[p]) #pairwise coprimeではない print("pairwise coprime")
import numpy as np A,B,H,M = map(int,input().split()) pi = np.pi h_angle = (H + M/60) * 2*pi / 12 m_angle = M * 2 * pi / 60 h_x = A * np.cos(h_angle) h_y = A * np.sin(h_angle) m_x = B * np.cos(m_angle) m_y = B*np.sin(m_angle) print(np.sqrt((h_x - m_x) ** 2 + (h_y - m_y) ** 2))
0
null
11,997,470,813,262
85
144
a,b=map(int,input().split());print("a "+("<"if a<b else">"if a>b else"==")+" b")
H1,M1,H2,M2,K = map(int,input().split()) print((H2-H1)*60+(M2-M1)-K if (M2-M1) >= 0 else (H2-H1)*60+(M2-M1)-K)
0
null
9,211,081,471,260
38
139
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline a,b = map(int, input().split()) e = 0.08 t = 0.1 for i in range(1, 1000+1): if int(i * e) == a and int(i * t) == b: print(i) exit() print(-1)
A, B = list(map(int, input().split())) ans = -1 for i in range(1, 1009): if int(i*0.08) == A and int(i*0.10) == B: ans = i break print(ans)
1
56,561,261,421,278
null
203
203
while True: W = input().rstrip() if W == "-": break m = int(input().rstrip()) l = list(W) for i in range(m): h = int(input().rstrip()) w = l[:h] del l[:h] l += w ans = "".join([str(i) for i in l]) print(ans)
def main(): S, W = map(int, input().split(' ')) if S > W: print('safe') else: print('unsafe') main()
0
null
15,438,365,581,898
66
163
n,m,x = map(int,input().split()) ac = [list(map(int,input().split())) for _ in range(n)] ttlmmin = 10**8 for i in range(1<<n): ttlm = 0 skl = [0]*m for k in range(n): if i & (1<<k): for l in range(m): skl[l] += ac[k][l+1] ttlm += ac[k][0] flag = True for l in range(m): if skl[l] < x: flag = False break if flag: ttlmmin = min(ttlmmin,ttlm) if ttlmmin == 10**8: print(-1) else: print(ttlmmin)
# coding: utf-8 # Here your code ! S = int(input()) N = list(map(int,input().split())) count=0 def bubblesort(n,s): global count flag = 1 while flag: flag = 0 for i in range(s-1,0,-1): key = n[i] if n[i]<n[i-1]: n[i]=n[i-1] n[i-1]=key count+=1 flag=1 print(" ".join(list(map(str,n)))) print(count) bubblesort(N,S)
0
null
11,092,819,178,180
149
14
def bubbleSort( nums ): cnt = 0 for i in range( 0, len( nums ) ): for j in range( len( nums )-1 , i, -1 ): if nums[j] < nums[ j-1 ]: nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j] cnt += 1 print( " ".join( map( str, nums) ) ) print( cnt ) n = int( raw_input( ) ) nums = [ int( val ) for val in raw_input( ).split( " " ) ] bubbleSort( nums )
n, m, l = map(int, input().split()) a = [] for i in range(0, n): e = list(map(int, input().split())) a.append(e) b = [] for i in range(0, m): e = list(map(int, input().split())) b.append(e) for i in range(0, n): e = [] for j in range(0, l): ab = 0 for k in range(0, m): ab += a[i][k] * b[k][j] e.append(ab) print(' '.join(map(str, e)))
0
null
719,715,821,902
14
60
inList = input().split() stack = [] for i in inList: if i in ['+', '-', '*']: b, a = stack.pop(), stack.pop() if i == '+': stack.append(b + a) if i == '-': stack.append(a - b) if i == '*': stack.append(b * a) else: stack.append(int(i)) print(stack.pop())
# coding: UTF-8 from collections import deque operators = {'+','*','-'} def operate(L,R,C): if C == '+': return L + R elif C == '*': return L * R else: #<=>if C == '-' return L - R raw = input().split() stack = deque() for C in raw: if C in operators: R = stack.pop() L = stack.pop() stack.append(operate(L,R,C)) else: stack.append(int(C)) print(stack.pop())
1
35,991,791,832
null
18
18
from math import * def distance (p,n,x,y): dis = 0.0 if p == "inf": for i in range(0,n) : if dis < abs(x[i]-y[i]): dis = abs(x[i]-y[i]) else : for i in range(0,n) : dis += abs(x[i]-y[i])**p dis = dis ** (1.0/p) return dis if __name__ == '__main__' : n = int(input()) x = map(int,raw_input().split()) y = map(int,raw_input().split()) print distance(1,n,x,y) print distance(2,n,x,y) print distance(3,n,x,y) v = distance('inf',n,x,y) print "%.6f" % v
import math n = int(input()) x_lst = map(int, input().split()) y_lst = map(int, input().split()) xy_lst = list(zip(x_lst, y_lst)) p1 = 0 p2 = 0 p3 = 0 p4 = [] for x, y in xy_lst: # マンハッタン距離 p1 += abs(x - y) # ユークリッド距離 p2 += (abs(x - y)) ** 2 p3 += (abs(x - y)) ** 3 # チェビシェフ距離 p4.append(abs(x - y)) print(p1) print(math.sqrt(p2)) print(math.pow(p3, 1 / 3)) print(max(p4))
1
212,413,239,192
null
32
32
K = int(input()) S = input() if len(S) <= K: print(S) else: print(S[0:K] + '...')
import sys input = sys.stdin.readline N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -10**18 for i in range(N): now = i visit = [False]*N visit[now] = True l = [] while True: nex = P[now]-1 l.append(C[nex]) if visit[nex]: break visit[nex] = True now = nex s = sum(l) acc = 0 for j in range(min(K, len(l))): acc += l[j] ans = max(ans, acc+max(0, (K-j-1)//len(l)*s)) print(ans)
0
null
12,570,711,080,090
143
93
# coding: utf-8 import codecs import sys sys.stdout = codecs.getwriter("shift_jis")(sys.stdout) # ?????? sys.stdin = codecs.getreader("shift_jis")(sys.stdin) # ??\??? # ??\??¬?????????print??????????????´?????? print(u'?????????') ??¨?????? # ??\??¬?????????input??? input(u'?????????') ??§OK # ??°?¢???????????????????????????´??????6,7???????????????????????¢?????? """ DEBUG = 0 if DEBUG == 0: a = [] for i in range(200): deglist=[int(x) for x in input().split(" ")] a.append(deglist) else: a = [[5,7],[1,99],[1000,999]] for i in range(len(a)): wa = a[i][0] + a[i][1] print len(str(wa)) """ while True: try: a,b = map(int, raw_input().split()) print len(str(a+b)) except EOFError: break
numbers = input().split(" ") num = numbers.index("0") print(num + 1)
0
null
6,710,688,675,652
3
126
N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) T = [] for i in range(N): T.append(A[i]*F[i]) s = -1 l = 10**12 while(l-s > 1): mid = (l-s)//2 + s c = 0 for i in range(N): if T[i] > mid: if (T[i] - mid) % F[i] == 0: c += (T[i] - mid) // F[i] else: c += (T[i] - mid) // F[i] + 1 if c > K: s = mid else: l = mid print(l)
n,k=map(int,input().split()) a=list(map(int,input().split())) f=list(map(int,input().split())) a.sort() f.sort(reverse=True) hi=10**12 lo=0 def c(mi): tmp=0 for i,j in zip(a,f): if mi//j<i: tmp+=i-mi//j if tmp<=k: return True return False while hi>=lo: mi=(hi+lo)//2 if c(mi): hi=mi-1 else: lo=mi+1 print(lo)
1
164,268,402,506,088
null
290
290
import sys import heapq from decimal import Decimal input = sys.stdin.readline n = int(input()) alpha_list = [chr(i) for i in range(97, 97+26)] def dfs(s,used_count): if len(s) == n: print(s) return for i in range(used_count+1): if i == used_count: dfs(s+alpha_list[i],used_count+1) else: dfs(s+alpha_list[i],used_count) dfs("a",1)
a, b = map(int, input().split()) print("{:d} {:d} {:f}".format(a//b, a%b, a/b))
0
null
26,566,999,906,786
198
45
import bisect n=int(input()) l=sorted(list(map(int,input().split()))) ans=0 for i in range(n-1): for j in range(i+1,n): index=bisect.bisect_left(l,l[i]+l[j]) if j<index: ans+=index-j-1 print(ans)
import bisect import sys from bisect import bisect_left from operator import itemgetter sys.setrecursionlimit(10**9) input = sys.stdin.readline def ii(): return int(input()) def mi(): return map(int, input().split()) def lmi(): return list(map(int, input().split())) def lmif(n): return [list(map(int, input().split())) for _ in range(n)] def main(): N = ii() L = lmi() L.sort() # print(L) # 2辺を固定して、2辺の和より長い辺の数を数える count = 0 for i in range(N): for j in range(i+1, N): limit = L[i] + L[j] longer = bisect_left(L, limit) tmp = longer - (j + 1) # print(limit, longer, tmp) count += longer - (j + 1) print(count) return main()
1
172,017,127,846,642
null
294
294
X, Y = map(int,input().split()) multiple = X * Y print(multiple)
A, B = map(int, input().split()) R = A * B print(R)
1
15,743,434,464,130
null
133
133
N = int(input()) A = list(map(int, input().split())) fumidai_list, A_after = [], 0 for count_a in range(len(A)): fumidai = 0 if(A[count_a] >= A_after): A_after = A[count_a] fumidai_list.append(fumidai) elif(A[count_a] < A_after): fumidai = A_after - A[count_a] fumidai_list.append(fumidai) print(sum(fumidai_list))
N = int(input()) As = list(map(int, input().split())) h = 0 ans = 0 for i in range(N): h = max(h, As[i]) ans += h - As[i] print(ans)
1
4,566,131,476,040
null
88
88
from math import tan,radians a,b,w=map(int,input().split()) V=a**2*b def taiseki(x,a,b): x=90-x if tan(radians(x))>a/b: x=90-x return V-(a**3*tan(radians(x)))/2 else: return a*b**2*tan(radians(x))/2 if V==w: print(0) exit() ok,ng=0,90 while ng-ok>0.00000001: mid=(ok+ng)/2 if taiseki(mid,a,b)>=w: ok=mid else: ng=mid print(ng)
n, m = map(int, input().split()) a = 1 b = m + 1 while a < b: print(a, b) a += 1 b -= 1 a = m + 2 b = 2 * m + 1 while a < b: print(a, b) a += 1 b -= 1
0
null
95,511,391,398,658
289
162
s = input() a = [str(c) for c in s] t = input() b = [str(c) for c in t] c = 0 n = len(a) for i in range(n): if a[i] == b[i]: c +=1 print(n-c)
n=0 s=list(str(input())) t=list(str(input())) for i in range(len(s)): if s[i] != t[i]: n+=1 print(n)
1
10,576,083,394,012
null
116
116