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
f = lambda: int(input()) d = -float('inf') n = f() l = f() for _ in range(n-1): r = f() d = max(d, r-l) l = min(l, r) print(d)
n = int(raw_input()) _min, dif = 10**10, -10**10 for x in xrange(n): a = int(raw_input()) if a -_min > dif: dif = a - _min if a < _min: _min = a print dif
1
13,370,252,798
null
13
13
import math import itertools # 与えられた数値の桁数と桁値の総和を計算する. def calc_digit_sum(num): digits = sums = 0 while num > 0: digits += 1 sums += num % 10 num //= 10 return digits, sums n = int(input()) distances = [] for _ in range(n): points = list(map(int, input().split())) distances.append(points) total = 0 routes = list(itertools.permutations(range(n), n)) for route in routes: distance = 0 for index in range(len(route)-1): idx1 = route[index] idx2 = route[index+1] distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2) total += distance print(total / len(routes))
import math import itertools n = int(input()) l = [] for _ in range(n): a = list(map(int,input().split())) l.append(a) dis = 0 for case in itertools.permutations(l): for i in range(n-1): dis += math.sqrt((case[i][0]-case[i+1][0])**2+(case[i][1]-case[i+1][1])**2) result = dis/math.factorial(n) print(result)
1
148,276,837,063,940
null
280
280
def main(): P = 2019 S = [int(s) for s in input()] ans = 0 if P == 2: for i, v in enumerate(S, start=1): if v % 2 == 0: ans += i elif P == 5: for i, v in enumerate(S, start=1): if v == 0 or v == 5: ans += i else: cnt = [0]*P d = 1 pre = 0 cnt[pre] += 1 for v in S[::-1]: v *= d v += pre v %= P cnt[v] += 1 d *= 10 d %= P pre = v ans = sum(cnt[i]*(cnt[i]-1)//2 for i in range(P)) print(ans) if __name__ == '__main__': main()
n,x,m=map(int,input().split()) l=[0]*m s=[0]*m t=p=0 while l[x]<1: t+=1 l[x]=t s[x]=s[p]+x p=x x=pow(p,2,m) T=t+1-l[x] S=s[p]+x-s[x] d,m=divmod(n-l[x],T) print(S*d+s[l.index(l[x]+m)])
0
null
16,843,231,635,998
166
75
import sys input = sys.stdin.readline n = int(input()) l=[[]] nn = [] for _ in range(n+1): l.append([]) for i in range(n-1): a,b = map(int,input().split()) l[a].append(b) l[b].append(a) nn.append(b) ml = list(map(len,l)) m = max(ml) co = [] for i in range(n+1): co.append( set(range(1,ml[i]+1) )) col = [0]*(n+1) col[1] = 1 for i in range(1,n+1): for la in l[i]: if col[la] ==0: col[la] = co[i].pop() co[la].discard(col[la]) print(m) for i in range(n-1): print(col[nn[i]])
import sys sys.setrecursionlimit(10 ** 9) # 昔同じ問題を atcoder で見た? n = int(input()) edges = [] paths = {} for i in range(n-1): a, b = list(map(int, input().split(' '))) edges.append((a, b)) paths[a] = paths.get(a, []) + [b] paths[b] = paths.get(b, []) + [a] # print(edges) # print(paths) colors = {} # (a->b) 1 とか current = 1 biggest = 1 def f(current, prev, prev_color): global biggest color = 0 for vertex in paths[current]: if vertex == prev: continue color += 1 if color == prev_color: color += 1 biggest = max(biggest, color) colors[(current, vertex)] = color f(vertex, current, color) f(1, None, None) print(biggest) for a, b in edges: print(colors[(a, b)]) # pypy3
1
136,224,522,546,150
null
272
272
s,t=map(str,input().split()) a,b=map(int,input().split()) u=input() print(str(a-1) + " " + str(b) if s==u else str(a) + " " + str(b-1))
S, T = input().split() A, B = map(int, input().split()) U = input() if U == S: A -= 1 else: B -= 1 print(A, B)
1
72,342,195,262,876
null
220
220
n = '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' nn = n.split(', ') nn = list(map(int, nn)) K = int(input()) print(nn[K-1])
s=input() if s=="SUN":print(7) elif s=="MON":print(6) elif s=="TUE":print(5) elif s=="WED":print(4) elif s=="THU":print(3) elif s=="FRI":print(2) elif s=="SAT":print(1)
0
null
91,736,605,302,748
195
270
import sys input = sys.stdin.readline N = int(input()) S = list(input().rstrip()) ord_a = ord("a") class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) 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 bits = [Bit(N) for _ in range(26)] for i in range(N): s = S[i] bits[ord(s) - ord_a].add(i + 1, 1) Q = int(input()) for _ in range(Q): query = input().rstrip().split() if query[0] == "1": i, c = int(query[1]), query[2] bits[ord(S[i - 1]) - ord_a].add(i, -1) S[i - 1] = c bits[ord(S[i - 1]) - ord_a].add(i, 1) else: l, r = int(query[1]), int(query[2]) res = 0 for bit in bits: if l != 1: res += int(bit.sum(r) - bit.sum(l - 1) > 0) else: res += int(bit.sum(r) > 0) print(res)
def main(): import bisect n = int(input()) s = list(input()) q = int(input()) d = {} for i in range(26): d[chr(ord('a')+i)] = [] for i in range(n): d[s[i]].append(i) #print(d) for i in range(q): t,a,b = input().split() if t == '1': a = int(a)-1 if s[a] == b: continue idx = bisect.bisect_left(d[s[a]],a) d[s[a]].pop(idx) bisect.insort_left(d[b],a) s[a] = b else: a = int(a)-1 b = int(b)-1 c = 0 for i in range(26): idx = bisect.bisect_left(d[chr(ord('a')+i)],a) if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b: c += 1 print(c) main()
1
62,630,900,407,040
null
210
210
N = int(input()) A = list(map(int, input().split())) # N日目の最大の所持金 dp = [1000] + [0] * (N-1) for i in range(1, N): dp[i] = dp[i-1] for j in range(i): # j日に買える最大の株数 max_unit = dp[j] // A[j] # その場合の所持金の変化 money = dp[j] + (A[i]-A[j])*max_unit dp[i] = max(money, dp[i]) print(dp[-1])
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()) def main(): N, K = MI() a = N % K b = K - a print(min(a, b)) if __name__ == "__main__": main()
0
null
23,427,070,033,678
103
180
N = int(input()) c = list(input()) #cを[R,R,R,.....,R,W,W,W,.....,W]の形にする。 div = c.count('R') c_for = c[:div] c_lat = c[div:] ans = 0 replace = min(c_for.count('W'), c_lat.count('R')) change = max(c_for.count('W'), c_lat.count('R')) - replace ans = replace + change #実質 ans = max(c_for.count('W'), c_lat.count('R')) やんけ! print(ans)
n,k = map(int, input().split()) r, s, p = map(int, input().split()) T = list(str(input())) ans = 0 S = [-1]*n for i in range(n): if i <= k-1: if T[i] == 'r': S[i] = 'p' ans += p elif T[i] == 's': S[i] = 'r' ans += r else: S[i] = 's' ans += s else: if T[i] == 'r': if S[i-k] != 'p': S[i] = 'p' ans += p else: if i+k <= n-1: if T[i+k] == 's': S[i] = 's' elif T[i+k] == 'p': S[i] = 'r' else: S[i] = 'r' else: S[i] = 'r' elif T[i] == 's': if S[i-k] != 'r': S[i] = 'r' ans += r else: if i+k <= n-1: if T[i+k] == 'p': S[i] = 'p' elif T[i+k] == 'r': S[i] = 's' else: S[i] = 's' else: S[i] = 's' else: if S[i-k] != 's': S[i] = 's' ans += s else: if i+k <= n-1: if T[i+k] == 's': S[i] = 'p' elif T[i+k] == 'r': S[i] = 'r' else: S[i] = 'p' else: S[i] = 'p' print(ans)
0
null
56,681,639,970,280
98
251
from collections import Counter def solve(): N = int(input()) c = Counter([input() for _ in range(N)]) cnt = -1 ans = [] for i in c.most_common(): if cnt == -1: cnt = i[1] ans.append(i[0]) elif cnt == i[1]: ans.append(i[0]) else: break for a in sorted(ans): print(a) if __name__ == "__main__": solve()
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] #a = [input() for _ in range(n)] n = int(input()) s = [input() for _ in range(n)] h = {} for i in range(n): if (s[i] in h): h[s[i]] += 1 else: h[s[i]] = 1 ans = [] highScore = max(h.values()) for k,v in h.items(): if v== highScore: ans.append(k) ans.sort() for i in range(len(ans)): print(ans[i])
1
70,265,717,120,128
null
218
218
input() s = input() count = 1 for i in range(len(s)-1): if s[i]!=s[i+1]: count+=1 print(count)
def main(): X = int(input()) tmp = 0 cnt = 0 while True: tmp += X cnt += 1 tmp %= 360 if tmp == 0: break return cnt print(main())
0
null
91,717,258,485,730
293
125
list1=list(map(int,input().split())) A=list1[0] B=list1[1] C=list1[2] if list1.count(A)==2 or list1.count(B)==2 or list1.count(C)==2: print("Yes") else: print("No")
import sys a,b,c=map(int,input().split()) if a==b and b!=c: print("Yes") sys.exit() elif c==b and b!=a: print("Yes") sys.exit() elif a==c and b!=c: print("Yes") sys.exit() else: print("No") sys.exit()
1
67,776,047,885,908
null
216
216
# 数字を取得 N = int(input()) # 数値分ループ calc = [] for cnt in range(1, N + 1): # 3もしくは5の倍数であれば、加算しない if cnt % 3 != 0 and cnt % 5 != 0: calc.append(cnt) # 合計を出力 print(sum(calc))
A, B = input().split() print(int(A) * round(float(B) * 100) // 100)
0
null
25,808,906,132,402
173
135
H, W = map(int,input().split()) if H == 1 or W == 1: print(1) else: ans = H*W if ans % 2: print(ans//2+1) else: print(ans//2)
"""Boot-camp-for-Beginners_Easy006_B_Bishop_25-August-2020.py""" H, W = (map(int, input().split())) if(H == 1 or W == 1): print(1) else: if (H*W) % 2 == 0: print(int(H*W/2)) else: print(int(H*W/2)+1)
1
50,668,942,669,620
null
196
196
C = input() n = chr(ord(C)+1) print(n)
#A alpha="abcdefghijklmnopqrstuvwxyz" C=input() for i in range(len(alpha)): if alpha[i]==C: print(alpha[i+1])
1
92,239,220,704,000
null
239
239
n,m = map(int,input().split()) even = n * (n-1) // 2 odd = m * (m-1) // 2 print(even + odd)
n,m = map(int,input().split()) a = list(map(int,input().split())) for i in range(m): n -= a[i] if n < 0: print(-1) else: print(n)
0
null
38,966,568,533,508
189
168
from math import ceil def enum_divisor(n): res = [] for i in range(1, int(n ** 0.5) + 1): if n % i != 0: continue res.append(i) if i * i != n: res.append(n // i) return res ans = 0 n = int(input()) for x in enum_divisor(n): if x == 1: continue tmp = n while tmp % x == 0: tmp //= x if tmp % x == 1: ans += 1 ans += len(enum_divisor(n - 1)) - 1 print(ans)
from sys import stdin def make_divisors(n): mod0 = set() mod1 = set() for i in range(2, int(n**0.5)+1): if n%i==0: mod0.add(i) mod0.add(n/i) if (n-1)%i==0: mod1.add(i) mod1.add((n-1)/i) return mod0,mod1 N=list(map(int,(stdin.readline().strip().split()))) num=N[0] if num==2:print(1) else: K=0 mod0,mod1=(make_divisors(num)) # mod0.remove(1) # mod1.remove(1) for i in mod0: num = N[0] while(num % i == 0): num/=i if num%i==1: K+=1 K+=len(mod1)+2 print(K)
1
41,265,811,113,570
null
183
183
A, B = list(map(int, input().split())) print(A * B)
n=int(input()) change=1000-n%1000 if change==1000: print(0) else: print(change)
0
null
12,080,361,321,840
133
108
import math n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) import itertools t=[i for i in range(1,n+1)] a = list(itertools.permutations(t)) def num(b,t,n): c = 0 for i in range(len(t)): if list(t[i]) != b: c += 1 else: break return(c) x = num(p,a,n) y = num(q,a,n) print(abs(x-y))
from itertools import permutations n = int(input()) x = [i+1 for i in range(n)] x = list(map(str, x)) pt = [''.join(p) for p in permutations(x)] a = pt.index(''.join(input().split())) b = pt.index(''.join(input().split())) print(abs(a-b))
1
100,433,904,437,860
null
246
246
r=input().split() H=int(r[0]) N=int(r[1]) data_pre=input().split() data=[int(s) for s in data_pre] if sum(data)>=H: print("Yes") else: print("No")
H, N = map(int, input().split()) A = map(int, input().split()) print("Yes" if H <= sum(A) else "No")
1
78,209,856,657,440
null
226
226
def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) r = A[-1]*F[0] l = -1 while(r-l > 1): tmp = (l+r)//2 k = 0 for x, y in zip(A, F): if x*y > tmp: k += x - (tmp // y) #k += max(0, x - (tmp // y)) if K >= k: r = tmp else: l = tmp print(r) main()
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) f = sorted(list(map(int, input().split())))[::-1] r = 10**12+1 l = -1 while r - l > 1: s = k mid = (r + l)//2 for i, j in zip(a, f): if mid < i*j: s -= i-mid//j if s < 0: l = mid else: r = mid # print('r:', r, 'l:', l, 'r-l:', r-l) print(r)
1
164,597,447,894,870
null
290
290
h,w,k = map(int,input().split()) S = [input() for _ in range(h)] ans = float('inf') for bit in range(1<<(h-1)): segment = [0]*h seg = 0 for i in range(h-1): if bit & (1<<i): seg += 1 segment[i+1] = seg n = max(segment) + 1 count = n-1 k_cnt = [0]*n for j in range(w): tmp = [0]*n for i in range(h): k_cnt[segment[i]] += int(S[i][j]) tmp[segment[i]] += int(S[i][j]) if k_cnt[segment[i]] > k: count += 1 for i in range(n): k_cnt[i] = tmp[i] ans = min(ans,count) print(ans)
import sys input = sys.stdin.readline H,W,K=map(int,input().split()) CO=[[0 for i in [0]*W] for j in [0]*H] DO=[[0 for i in [0]*W] for j in [0]*H] for i in range(H): C=input() for j in range(W): DO[i][j]=int(C[j]) CO[H-1]=DO[H-1] F=1000000 for s in range(2**(H-1)): D=0 E=0 for k in range(H-1): if ((s >> k) & 1): for i in range(W): CO[H-k-2][i]=DO[H-k-2][i] E+=1 else: for i in range(W): CO[H-k-2][i]=DO[H-k-2][i]+CO[H-k-1][i] lst=[0]*H for h in range(W): c=max(CO[x][h] for x in range(H)) d=max(lst[y]+CO[y][h] for y in range(H)) if c>K: E=1000000 break elif d>K: D+=1 lst=[0]*H for z in range(H): lst[z]+=CO[z][h] F=min(F,D+E) print(F)
1
48,501,822,918,010
null
193
193
import string N = int(input()) alph = string.ascii_lowercase ans = [] A = [0] def search(): if len(A) == N: ans.append(tuple(A)) return mx = max(A) for i in range(mx + 2): A.append(i) search() A.pop() return search() for a in ans: print(''.join(alph[i] for i in a))
from collections import * def dfs(q): if len(q)==N: print(''.join(q)) return M = 'a' for qi in q: M = max(M, qi) for i in range(ord(M)-ord('a')+2): q.append(alpha[i]) dfs(q) q.pop() N = int(input()) alpha = 'abcdefghijklmnopqrstuvwxyz' dfs(deque(['a']))
1
52,542,163,225,970
null
198
198
a, b, c = map(int, input().split(" ")) print("Yes" if len(set({a,b,c})) == 2 else "No")
l = input().split(' ') print('Yes' if len(set(l)) == 2 else 'No')
1
68,085,013,692,368
null
216
216
H,W = [int(i) for i in input().split()] h1 = H//2 h2 = H-h1 w2 = W//2 w1 = W-w2 if H==1 or W==1: print(1) else: print(h2*w1+h1*w2)
H , W = map(int,input().split()) if H == 1 or W ==1: print(1) exit() if H %2 == 0: tate = H/2 ans = tate * W else: tate1 = H // 2 + 1 tate2 = H // 2 if W % 2 == 0: ans = (tate1 + tate2) * W/2 else: ans = tate1*((W//2)+1) + tate2*(W//2) print(int(ans))
1
50,860,976,422,102
null
196
196
from collections import defaultdict from collections import deque from collections import OrderedDict import itertools from sys import stdin input = stdin.readline def main(): N, K = list(map(int, input().split())) P = list(map(int, input().split())) PP = [0]*N for i, p in enumerate(P): PP[i] = p*(p+1)/(2*p) S = [0]*(N+1) for i in range(1, N+1): S[i] = PP[i-1] + S[i-1] max_ = 0 for i in range(0, N-K+1): max_ = max(max_, S[i+K] - S[i]) print(max_) if(__name__ == '__main__'): main()
def abc154d_dice_in_line(): n, k = map(int, input().split()) p = list(map(lambda x: (int(x)+1)*(int(x)/2)/int(x), input().split())) ans = sum(p[0:k]) val = ans for i in range(k, len(p)): val = val - p[i-k] + p[i] ans = max(ans, val) print(ans) abc154d_dice_in_line()
1
74,912,274,209,488
null
223
223
N = int(input()) A = list(map(int, input().split())) ans = float('inf') sum_A = sum(A) CumSum = 0 for i in range(N-1): CumSum = CumSum + A[i] ans = min(ans,(abs((sum_A - CumSum)-(CumSum)))) print(ans)
from itertools import accumulate n = int(input()) a = list(map(int, input().split())) a_acc = list(accumulate(a)) ans = 2020202020 for i in range(n): ans = min(abs(a_acc[-1] - a_acc[i] - a_acc[i]), ans) print(ans)
1
141,936,665,510,912
null
276
276
st = input().split() st.reverse() print(''.join(st))
def main(): x = int(input()) coin_500 = x // 500 coin_5 = x % 500 // 5 ans = coin_500 * 1000 + coin_5 * 5 print(ans) if __name__ == "__main__": main()
0
null
72,785,872,827,822
248
185
change = int(input()) % 1000 print(1000-change if change else change)
N = int(input()) ans = N%1000 if ans == 0: print(0) else: print(1000-ans)
1
8,501,487,710,012
null
108
108
N, M = input().split() N = int(N) M = int(M) A = list(map(int, input().split())) LA = len(A) i = 0 SUM = 0 for i in range(LA): SUM = SUM + A[i] if SUM > N: print('-1') else: print(N - SUM)
N, M = map(int, input().split()) A = list(map(int, input().split())) def answer(N: int, M: int, A: list) -> int: A = sum(A) if N < A: return -1 else: return N - A print(answer(N, M, A))
1
32,187,350,210,080
null
168
168
# coding:utf-8 # ??\??????????????´??°????°??????????????????? i = 1 x = 1 y = 1 while x != 0 or y != 0: xy = raw_input().split() x = int(xy[0]) y = int(xy[1]) if x == 0 and y ==0: break if x < y : print x,y else: print y,x
S = input() length = len(S) print("x"*length)
0
null
36,722,088,147,558
43
221
n = int(input()) s = input() if n % 2 == 1: print('No') exit() n2 = n // 2 for i in range(n2): if s[i] != s[i+n2]: print('No') exit() print('Yes')
nn = input() n = str(input()) if len(n) % 2 == 1: print('No') else: a = n[0 : len(n)//2] b = n[len(n)//2 : len(n)] if a == b: print('Yes') else: print('No')
1
146,662,661,261,480
null
279
279
_str = "" _k = int(input()) for _i in range(_k): _str += "ACL" print(_str)
print(eval("'ACL'*"+input()))
1
2,177,560,639,100
null
69
69
from sys import stdin while True: n, x = [int(x) for x in stdin.readline().rstrip().split()] if n == 0 and x == 0: break else: count = 0 for i in range(1, n-1): for j in range(i+1, n): if j < x-i-j <= n: count += 1 else: print(count)
while True: [n, m] = [int(x) for x in raw_input().split()] if [n, m] == [0, 0]: break data = [] for x in range(n, 2, -1): for y in range(x - 1, 1, -1): for z in range(y - 1, 0, -1): s = x + y + z if s < m: break if s == m: data.append(s) print(len(data))
1
1,302,108,672,510
null
58
58
n = int(input()) a = list(map(int, input().split())) ans = [0]*n for i in range(n): ans[a[i]-1] += i+1 ans[a[i]-1] = str(ans[a[i]-1]) print(" ".join(ans))
n=int(input()) s=set([]) for i in range(n): s_=input() s.add(s_) print(len(s))
0
null
105,016,554,373,732
299
165
def main(): global s,ide_ele,num,seg n = int(input()) s = list(input()) for i in range(n): s[i] = ord(s[i])-97 ide_ele = 0 num = 2**(n-1).bit_length() seg = [[ide_ele for _ in range(2*num)] for _ in range(26)] for i in range(n): seg[s[i]][i+num-1] = 1 for a in range(26): for i in range(num-2,-1,-1) : seg[a][i] = max(seg[a][2*i+1],seg[a][2*i+2]) q = int(input()) for _ in range(q): QUERY = list(input().split()) QUERY[0], QUERY[1] = int(QUERY[0]), int(QUERY[1]) if QUERY[0] == 1: x = ord(QUERY[2])-97 k = QUERY[1]-1 pre = s[k] s[k] = x k += num-1 seg[pre][k] = 0 seg[x][k] = 1 while k: k = (k-1)//2 seg[pre][k] = max(seg[pre][k*2+1],seg[pre][k*2+2]) seg[x][k] = max(seg[x][k*2+1],seg[x][k*2+2]) if QUERY[0] == 2: P, Q = QUERY[1]-1, int(QUERY[2]) if Q <= P: print(ide_ele) break P += num-1 Q += num-2 ans = ide_ele for i in range(26): res = ide_ele p,q = P,Q while q-p > 1: if p&1 == 0: res = max(res,seg[i][p]) if q&1 == 1: res = max(res,seg[i][q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = max(res,seg[i][p]) else: res = max(max(res,seg[i][p]),seg[i][q]) ans += res print(ans) if __name__ == "__main__": main()
N = int(input()) S = [x for x in input()] Q = int(input()) #A1 ... AnのBIT(1-indexed) BIT = [[0] * (N + 1) for _ in range(26)] #A1 ~ Aiまでの和 O(logN) def BIT_query(input_BIT, idx): res_sum = 0 while idx > 0: res_sum += input_BIT[idx] idx -= idx&(-idx) return res_sum #Ai += x O(logN) def BIT_update(input_BIT,idx,x): while idx <= N: input_BIT[idx] += x idx += (idx&(-idx)) return for i, c in enumerate(S): BIT_update(BIT[ord(c)-ord('a')], i+1, 1) for _ in range(Q): a, b, c = input().rstrip().split() if int(a) == 1: BIT_update(BIT[ord(S[int(b)-1])-ord('a')], int(b), -1) BIT_update(BIT[ord(c)-ord('a')], int(b), 1) S[int(b)-1] = c else: count = 0 for i in range(26): if BIT_query(BIT[i], int(b)-1) != BIT_query(BIT[i], int(c)): count += 1 print(count)
1
62,375,206,778,722
null
210
210
N = int(input()) alp = {"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8, "i":9, "j":10} alp2 = "abcdefghij" def solve(N): ans = [] if N == 1: ans.append("a") else: pre = solve(N-1) for i in range(len(pre)): tmp = sorted(pre[i]) num = alp[tmp[len(tmp)-1]] for j in range(num+1): ans.append(pre[i]+alp2[j]) return ans f_ans = solve(N) f_ans.sort() for i in range(len(f_ans)): print(f_ans[i])
N=int(input()) if N==1: print("a") exit() from collections import deque from collections import Counter abc="abcdefghijklmnopqrstuvwxyz" ans=["a"] for i in range(1,N): d=deque(ans) ans=[] while d: temp=d.popleft() temp2=list(temp) cnt=Counter(temp2) L=len(cnt) for j in range(L+1): ans.append(temp+abc[j]) for a in ans: print(a)
1
52,345,888,399,042
null
198
198
import math from decimal import Decimal X = int(input()) now = 100 year = 0 while True: if now >= X: break #now = int(now * Decimal("1.01")) now = int(now * round(Decimal(1.01), 2)) year += 1 print(year)
X=int(input()) a=100 cnt=0 while a<X: a=a+a//100 cnt+=1 print(cnt)
1
27,097,043,328,168
null
159
159
#init N = int(input()) S=[input() for i in range(N)] for word in ['AC', 'WA', 'TLE', 'RE']: print('{0} x {1}'.format(word, S.count(word)))
import copy import sys sys.setrecursionlimit(10**9) def dfs(G, v, p, d, depth): depth[v] = d for nv in G[v]: if nv == p: continue dfs(G, nv, v, d+1, depth) return G, depth n, T, A = map(int,input().split()) T, A = T-1, A-1 g = [[] for _ in range(n)] for i in range(n-1): x, y = map(int,input().split()) x, y = x-1, y-1 g[x].append(y) g[y].append(x) depth = [0]*n GT = copy.deepcopy(g) GT[T].append(-1) GT, dt = dfs(GT, T, -1, 0, depth) depth = [0]*n GA = copy.deepcopy(g) GA[A].append(-1) GA, da = dfs(GA, A, -1, 0, depth) ans = 0 for t, a in zip(dt, da): if t <= a: ans = max(ans, a) print(ans-1)
0
null
63,229,212,218,590
109
259
n=int(input()) k=[1] ans=[] c=26 wa=0 while wa+c<n: k.append(c) wa+=c c=c*26 n=n-1-wa for i in k[::-1]: ans.append(n//i) n=n%i t='' for i in ans: t+=chr(97+i) print(t)
#!/usr/bin/env python3 import sys import string l = [c for c in string.ascii_lowercase] def f(N: int): N -= 1 if N // 26: return f(N//26) + l[N%26] else: return l[N%26] def solve(N): print(f(N)) # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == '__main__': main()
1
11,819,268,754,332
null
121
121
value = int(input()) print(value ** 3)
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 11:23:30 2018 ALDS1-4a most simple implementation using the features of the python @author: maezawa """ n = int(input()) s = map(int, input().split()) q = int(input()) t = map(int, input().split()) s_set = set(s) t_set = set(t) sandt = s_set & t_set print(len(sandt))
0
null
172,898,202,160
35
22
import math N,M,K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.append(math.inf) B.append(math.inf) best = 0 i = j = 0 while K >= A[i]: K -= A[i] i += 1 while True: while K >= B[j]: K -= B[j] j += 1 best = max(best, i+j) if i == 0: break i -= 1 K += A[i] print(best)
import bisect N, M, K = map(int, input().split()) As = list(map(int, input().split())) Bs = list(map(int, input().split())) sAs = [0] sBs = [0] for a in As: sAs.append(sAs[-1]+a) for b in Bs: sBs.append(sBs[-1]+b) rlt = 0 for i in range(N+1): t = K - sAs[i] if t < 0: break j = bisect.bisect_right(sBs, t) rlt = max(rlt, i+j-1) print(rlt)
1
10,796,166,081,568
null
117
117
#!/usr/bin/env python3 import bisect import heapq import itertools import math import numpy as np from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from math import gcd from operator import add, itemgetter, mul, xor def cmb(n,r,mod): bunshi=1 bunbo=1 for i in range(r): bunbo = bunbo*(i+1)%mod bunshi = bunshi*(n-i)%mod return (bunshi*pow(bunbo,mod-2,mod))%mod mod = 10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def MI(): return map(int,input().split()) def LLI(n): return [list(map(int, input().split())) for _ in range(n)] #いまいるところ, #listとnが与えられたときn回テレポートしたところを出力する def now_place(li,n): now = 1 for i in range(n): now = li[now-1] return now #p回のテレポートでたどってきた道筋のルートを返す def root(li,p): ans = [] now = 1 for j in range(p): ans.append(now_place(li,j+1)) return ans n,k = MI() a = LI() #訪れたところのメモがtown town = [] #訪れたかどうかを0と1で管理 visit=[0]*n p = 1 while visit[p-1] == 0: town.append(p) visit[p-1] = 1 p = a[p-1] #香りだかい町がいつでてきたか→周期に入るまでのテレポート回数 #len(town[l:])は周期を表す l = town.index(p) if k <len(town): print(town[k]) else: print(town[l + (k-l)%(len(town[l:]))])
N,A,B = map(int,input().split()) balls = A + B N_surplus = N%balls if N_surplus < A: blues = (N//balls)*A + N_surplus else: blues = (N//balls)*A + A print(blues)
0
null
39,090,388,361,088
150
202
#import numpy as np N = int(input()) a = list(map(int, input().split())) all_xor = 0 for _a in a: all_xor = all_xor ^ _a for _a in a: print(all_xor ^ _a)
S = input() T = input() N = len(S) cnt = 0 for i in range(N): if S[i] != T[i]: cnt += 1 else: cnt += 0 print(cnt)
0
null
11,514,071,565,052
123
116
N = int(input()) arr = [int(n) for n in input().split()] swap_cnt = 0 for i in range(0, N): minj = i for j in range(i + 1, N): if arr[j] < arr[minj]: minj = j if (i != minj): arr[i], arr[minj] = arr[minj], arr[i] swap_cnt += 1 print(' '.join(map(str, arr))) print(swap_cnt)
n=int(input()) a = [0]*n b = [0]*n for i in range(n): a[i], b[i] = map(int, input().split()) a.sort() b.sort() youso = int(n/2) if n % 2 != 0: print(b[youso]-a[youso]+1) else: print((b[youso]+b[youso-1])-(a[youso]+a[youso-1])+1)
0
null
8,575,082,468,010
15
137
n,m=map(int,input().split()) 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 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] uf = UnionFind(n) ans=0 for i in range(m): a, b = map(int,input().split()) a -= 1 b -= 1 uf.union(a, b) for i in range(n): ans = max(ans, uf.size(i)) print(ans)
class unionfind(): def __init__(self,n): #親番号<0なら根 #根の場合、数値の絶対値が要素数 self.par=[-1 for i in range(n)] def root(self,x): par=self.par if par[x]<0: return x else: self.x = self.root(par[x]) return self.x def unite(self,x,y): #高いほうに低いほうをくっつける rx=self.root(x) ry=self.root(y) if rx==ry: return else: if self.par[rx]>self.par[ry]: rx,ry = ry,rx self.par[rx]+=self.par[ry] self.par[ry] = rx def same(self, x,y): return self.root(x) == self.root(y) def par_print(self): print(self.par) def count(self, x): return -self.root(x) n,m = map(int,input().split()) friend = unionfind(n) for i in range(m): a,b = map(int,input().split()) friend.unite(a-1,b-1) # print(friend.par_print()) # print(friend.par_print()) ans = -min(friend.par) print(ans)
1
3,967,988,576,628
null
84
84
n=int(input()) a=list(map(int,input().split())) ans=1 d={} ch=0 mod=10**9+7 for i in range(n): if a[i]==0: if 0 not in d: d[0]=1 ans*=3 else: if d[0]==1: d[0]=2 ans*=2 elif d[0]==2: d[0]=3 else: ch+=1 break else: if a[i] not in d: d[a[i]]=1 if a[i]-1 not in d: ch+=1 break else: ans*=d[a[i]-1] else: if d[a[i]]==1: d[a[i]]=2 if a[i]-1 not in d: ch+=1 break else: if d[a[i]-1]>=2: ans*=d[a[i]-1]-1 else: ch+=1 break elif d[a[i]]==2: d[a[i]]=3 if a[i]-1 not in d: ch+=1 break else: if d[a[i]-1]>=3: ans*=1 else: ch+=1 break else: ch+=1 break ans=(ans%mod) if ch==0: print(ans) else: print(0)
MOD = 10**9+7 n = int(input()) a = list(map(int, input().split())) cnt = [0 for _ in range(n)] ans = 1 for x in a: if x > 0: ans *= cnt[x-1] - cnt[x] else: ans *= 3 - cnt[0] cnt[x] += 1 ans %= MOD print(ans)
1
130,609,555,017,760
null
268
268
def main(): musics = int(input()) title = [] time = [] for _ in range(musics): s, t = input().split() title.append(s) time.append(int(t)) last_song = input() for i in range(musics): if title[i] == last_song: print(sum(time[i + 1:])) break if __name__ == '__main__': main()
n = int(input()) s = [] t = [] for i in range(n): s_, t_ = map(str, input().split()) s.append(s_) t.append(int(t_)) x = input() for i in range(n): if s[i] == x: break ans = 0 for j in range(n-1, i, -1): ans += t[j] print(ans)
1
97,342,242,096,838
null
243
243
import sys, math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial#, gcd from bisect import bisect_left #bisect_left(list, value) sys.setrecursionlimit(10**7) enu = enumerate MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def pri(x): print('\n'.join(map(str, x))) def prime_decomposition(n): i = 2 table = [] while i*i <= n: while n%i == 0: n //= i table.append(i) i += 1 if n > 1: table.append(n) return table def prime_decomposition2(n): i = 2 table = defaultdict(int) while i*i <= n: while n%i == 0: n //= i table[i] += 1 i += 1 if n > 1: table[n] += 1 return table def make_divisor(n): divisors = [] for i in range(1, int(n**0.5)+1): if n%i == 0: divisors.append(i) if i != n//i: divisors.append(n//i) return divisors N = int(input()) list_pd1 = make_divisor(N) list_pd1.sort() dict_pd2 = prime_decomposition2(N-1) #print(N, ':', list_pd1) #print(N-1, ':', dict_pd2) cnt = 1 # -1 nohou for val in dict_pd2.values(): cnt *= (val+1) cnt -= 1 #print(cnt) for k in list_pd1[1:]: #print('k:', k) sN = N while sN >= k: if sN%k==0: sN //= k else: sN %= k if sN == 1: cnt += 1 print(cnt)
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import collections, heapq, itertools, bisect import math, fractions import sys, copy sys.setrecursionlimit(1000000) 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 I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) 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)] 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 def divisors(N): divs = set([1, N]) i = 2 while i ** 2 <= N: if N % i == 0: divs.add(i) divs.add(N//i) i += 1 return sorted(list(divs)) def is_ok(N, K): if K <= 1: return False while N % K == 0: N //= K return N % K == 1 def main(): N = I() ans = 0 for divisor in divisors(N-1): if is_ok(N, divisor): ans += 1 for divisor in divisors(N): if is_ok(N, divisor): ans += 1 print(ans) if __name__ == '__main__': main()
1
41,623,255,769,242
null
183
183
while 1: x, y = map(int, input().split()) if x == 0 and y == 0: break elif x < y: print("%d %d" % (x, y)) else: print("%d %d" % (y, x))
# coding: UTF-8 import sys import numpy as np # f = open("input.txt", "r") # sys.stdin = f a = str(input()) if a.islower(): print("a") else: print("A")
0
null
5,974,687,946,932
43
119
X = input() print("".join(list(X)[0:3]))
N=int(input()) if N==1: print(0) exit() def primeryNum(n): border=int(n**0.5)+1 ary=list(range(int(n**0.5)+2)) ary[1]=0 for a in ary: if a>border: break elif a==0: continue for i in range(a*2,int(n**0.5)+2,a): ary[i]=0 return ary primeryNumL=primeryNum(N) # print(primeryNumL) ans=0 N_=N for x in primeryNumL: if x==0 or N%x!=0: continue n=N cnt=0 while n%x==0: cnt+=1 n/=x N_//=x**cnt buf=cnt-1 res=1 # print(x,cnt) for i in range(2,cnt+1): if buf<i: break buf-=i res+=1 ans+=res if N_>1: ans+=1 print(ans)
0
null
15,901,292,586,328
130
136
data = input().split() W=int(data[0]) H=int(data[1]) x=int(data[2]) y=int(data[3]) r=int(data[4]) if (0 <= x - r <= W) and (0 <= x + r <= W): if (0 <= y - r <= H) and (0 <= y + r <= H): print("Yes") else: print("No") else: print("No")
W, H, x, y, r = map(int, input().split()) if (x-r >= 0 and y-r >= 0 and x+r <= W and y+r <= H): print("Yes") else: print("No")
1
451,622,920,258
null
41
41
S,T=list(input().split()) A,B=list(map(int,input().split())) U=input() D={} D[S]=A D[T]=B D[U]-=1 print(D[S],D[T])
import sys # input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 S, T = map(str, input().split()) A, B = map(int, input().split()) U = str(input()) if S == U: print (A - 1, B) else: print (A, B - 1)
1
71,933,765,040,570
null
220
220
n = int(input()) print(((n + 1) // 2) / n)
import math import sys from collections import deque import heapq import copy import itertools from itertools import permutations from itertools import combinations import bisect def mi() : return map(int,sys.stdin.readline().split()) def ii() : return int(sys.stdin.readline().rstrip()) def i() : return sys.stdin.readline().rstrip() a=ii() if a%2==0: print(1/2) else: print(math.ceil(a/2)/a)
1
176,968,272,488,810
null
297
297
a,b=input().split() c,d=input().split() if a==c: print("0") else: print("1")
M1,D1 = map(int, input().split()) M2,D2 = map(int, input().split()) if M1==12 and M2==1 or M1+1==M2: print(1) else: print(0)
1
124,603,658,622,718
null
264
264
import math a = int(input()) b = a /1000 B = math.ceil(b) print(B * 1000 -a)
N = int(input()) tmp = 1000 while N > tmp: tmp += 1000 print(tmp - N)
1
8,389,472,730,820
null
108
108
# coding: utf-8 # Here your code ! N=int(input()) dict={} for i in range(N): a,b=input().split() if a=="insert": dict[b]=i else: if b in dict: print("yes") else: print("no")
n = int(input()) if n == 2 * int(n / 2): p = 1 / 2 else: p = (n + 1) / (2 * n) print(p)
0
null
88,435,888,752,000
23
297
bit=[0 for i in xrange(200)] n=int(raw_input().strip()) class dig: def __init__(self,val,id): self.val=val self.id=id def __gt__(self,other): return self.val<other.val def sum(i): s=0 i=int(i) while i>0: s+=bit[i] i-=i&(-i) return s def add(i,x): i=int(i) while i<=n: bit[i]+=x i+=i&-i def sort2(lst): lens=len(lst) sm=0 for i in xrange(lens): for j in xrange(i+1,lens): if lst[i]>lst[j]: sm+=1 return sm lst=map(int,raw_input().strip().split()) vals=[] lens=len(lst) for i in xrange(lens): vals.append(dig(lst[i],i+1)) vals.sort() ans=0 for i in vals: #print i.val,i.id ans+=sum(i.id) add(i.id,1) ans=sort2(lst) lst.sort() print " ".join(str(pp) for pp in lst) print ans
N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() MOD = 10**9+7 MAXN = N+5 fac = [1,1] + [0]*MAXN finv = [1,1] + [0]*MAXN inv = [0,1] + [0]*MAXN for i in range(2,MAXN+2): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD // i) % MOD finv[i] = finv[i-1] * inv[i] % MOD def comb(n,r): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD ans = 0 for i in range(N-K+1): c = comb(N-1-i,K-1) ans += (A[-i-1] - A[i]) * c ans %= MOD print(ans)
0
null
47,997,916,201,170
14
242
import sys def solve(h): if h == 1: return 1 else: return 1 + 2 * solve(h // 2) def main(): input = sys.stdin.buffer.readline h = int(input()) print(solve(h)) if __name__ == "__main__": main()
H = int(input()) c=1 h=H while 1: h = h//2 if h==0 : break c+=(1+c) print(c)
1
79,884,329,180,518
null
228
228
H,N=map(int,input().split()) A=input() list_A=A.split() waza=0 for i in range(0,N): waza=waza+int(list_A[i]) if waza>=H: print("Yes") else: print("No")
H,N=map(int, input().split()) A=list(map(int, input().split())) print('Yes' if sum(A) >= H else 'No')
1
78,237,570,037,326
null
226
226
import math def checkPrime(n): for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True if __name__ == "__main__": N = input() cnt = 0 for i in range(N): n = input() if checkPrime(n): cnt += 1 print cnt
n, q = map(int, input().split()) tasks = [(li[0], int(li[1])) for li in [input().split() for _ in range(n)]] elapsed = 0 while len(tasks): name, time = tasks.pop(0) if time > q: elapsed += q tasks.append((name, time - q)) else: elapsed += time print('{0} {1}'.format(name, elapsed))
0
null
24,899,045,920
12
19
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 arr = [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] n = INT() print(arr[n - 1])
l = [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] z = input() n = int(z) - 1 print(l[n])
1
49,983,893,123,138
null
195
195
import collections n = int(input()) A = list(map(int,input().split())) a = collections.Counter(A) sum_ = sum(A) Q = int(input()) B,C = [],[] for i in range(Q): lis = list(map(int,input().split())) B.append(lis[0]) C.append(lis[1]) for j,b in enumerate(B): sum_+=a[b]*(C[j]-b) a[C[j]]+=a[b] a[b]=0 print(sum_)
n = int(input()) lst = [0]*(10**5) l = list(map(int,input().split())) total = sum(l) for x in l: lst[x-1] += 1 m = int(input()) for i in range(m): x,y = map(int,input().split()) lst[y-1] += lst[x-1] total += (y-x) * lst[x-1] lst[x-1] = 0 print(total)
1
12,130,826,274,258
null
122
122
point = int(input()) rank = 1 for val in range(1800, 200, -200): if point >= val: break else: rank += 1 print(rank)
n,k=map(int,input().split()) a=list(map(int,input().split())) cnt=0 for i in range(n-k): if a[cnt]<a[cnt+k]: print("Yes") else: print("No") cnt+=1
0
null
6,978,127,842,308
100
102
c = 0 while 1: c += 1 t = int(input()) if t==0: break print("Case "+str(c)+":",t)
a=1 while True: i=int(input()) if i==0: break else: print("Case {0:d}: {1:d}".format(a,i)) a=a+1
1
478,064,464,544
null
42
42
def cmb(n, r, p): if r < 0 or n < r: return 0 r = min(r, n - r) return fact[n] * fact_inv[r] * fact_inv[n - r] % p n, k = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) p = 10 ** 9 + 7 fact = [1, 1] # fact[n] = (n! mod p) fact_inv = [1, 1] # fact_inv[n] = ((n!)^(-1) mod p) inv = [0, 1] # fact_invの計算用 for i in range(2, n + 1): fact.append(fact[-1] * i % p) inv.append((-inv[p % i] * (p // i)) % p) fact_inv.append(fact_inv[-1] * inv[-1] % p) i = 0 sum_max = 0 sum_min = 0 while n - i - 1 >= k - 1: cnt = cmb(n - i - 1, k - 1, p) sum_max += a[i] * cnt sum_min += a[n - i - 1] * cnt # print(i, a[i] * cnt, a[n - i - 1] * cnt) i += 1 ans = (sum_max - sum_min) % p print(ans)
import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() class Combination: """ O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms) 使用例: comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10 ** 9 + 7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n + 1): fac.append(fac[i - 1] * i % self.mod) facinv.append(facinv[i - 1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n + 1) modinv[1] = 1 for i in range(2, n + 1): modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod return modinv def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() comb = Combination(n_max=10 ** 5) ans = 0 for i in range(N - K + 1): ans -= comb(N - 1 - i, K - 1) * A[i] % MOD ans += comb(N - 1 - i, K - 1) * A[N - i - 1] % MOD ans %= MOD print(ans) if __name__ == "__main__": main()
1
95,660,896,493,848
null
242
242
import sys def input(): return sys.stdin.readline().rstrip() def main(): n = int(input()) if n%1000>0: print(1000-n%1000) else: print(0) if __name__=='__main__': main()
N = int(input()) ans = 0 if N % 1000 == 0: print(ans) else: a = N // 1000 ans = (a+1)*1000 - N print(ans)
1
8,486,533,050,648
null
108
108
import math import collections import fractions import itertools import functools import operator import bisect N = int(input()) def solve(): cnt = 0 for i in range(1, N): cnt += (N-1)//i print(cnt) return 0 if __name__ == "__main__": solve()
N=int(input()) ans=0 for a in range(1,N): q,m=divmod(N,a) ans+=(N//a)-(m==0) print(ans)
1
2,591,209,890,652
null
73
73
# -*- coding:utf-8 -*- x = int(input()) if x == False: print("1") else: print("0")
x = int(input()) if(x==0): print("1") elif(x==1): print("0")
1
2,935,214,310,216
null
76
76
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K = int(readline()) print(A[K-1]) if __name__ == "__main__": main()
import numpy as np S = input() a = [0]*(len(S)+1) for i in range(len(S)): if S[i] == '<': a[i+1] =max(a[i+1], a[i]+1) else: a[i] = max(a[i],a[i+1]+1) for i in range(len(S)-1,-1,-1): if S[i] == '<': a[i+1] =max(a[i+1], a[i]+1) else: a[i] = max(a[i],a[i+1]+1) print(sum(a))
0
null
103,582,664,274,432
195
285
h,w,k=map(int,input().split()) def split(word): return [char for char in word] m=[] for i in range(h): m.append(input()) t=[0]*(h-1) ans=w-1+h-1 for i in range(2**(h-1)): failflag=0 s=split("{0:b}".format(i)) s.reverse() for j in range(h-1-len(s)): s.append('0') s.reverse() a=[] a.append([]) for j in range(w): a[0].append(int(m[0][j])) for j in range(1,h): if s[j-1]=='0': for l in range(w): a[-1][l]+=int(m[j][l]) else: a.append([]) for l in range(w): a[-1].append(int(m[j][l])) n=len(a) tmp=0 p=[0]*n flag=0 for j in range(w): for l in range(n): if a[l][j]>k: failflag=1 if p[l]+a[l][j]>k: flag=1 break if flag==1: tmp+=1 flag=0 for t in range(n): p[t]=0 for l in range(n): p[l]+=a[l][j] if failflag==0 and n-1+tmp<ans: ans=n-1+tmp print(ans)
import numpy as np def main(): H, W, K = map(int, input().split()) S = [] for _ in range(H): S.append(list(map(int, list(input())))) S = np.array(S) if S.sum() <= K: print(0) exit(0) answer = float('INF') for i in range(0, 2 ** (H - 1)): horizons = list(map(int, list(bin(i)[2:].zfill(H - 1)))) result = greedy(W, S, K, horizons, answer) answer = min(answer, result) print(answer) # ex. horizons = [0, 0, 1, 0, 0, 1] def greedy(W, S, K, horizons, current_answer): answer = sum(horizons) # ex. # S = [[1, 1, 1, 0, 0], # [1, 0, 0, 0, 1], # [0, 0, 1, 1, 1]] # horizons = [0, 1]のとき, # S2 = [[2, 1, 1, 0, 0], # [0, 0, 1, 1, 1]] # となる top = 0 bottom = 0 S2 = [] for h in horizons: if h == 1: S2.append(S[:][top:(bottom + 1)].sum(axis=0).tolist()) top = bottom + 1 bottom += 1 S2.append(S[:][top:].sum(axis=0).tolist()) # ブロック毎の累積和を計算する h = len(S2) partial_sums = [0] * h for right in range(W): current = [0] * h for idx in range(h): current[idx] = S2[idx][right] partial_sums[idx] += S2[idx][right] # 1列に含むホワイトチョコの数がkより多い場合 if max(current) > K: return float('INF') # 無理な(ブロックの中のホワイトチョコの数をk以下にできない)場合 if max(partial_sums) > K: answer += 1 if answer >= current_answer: return float('INF') partial_sums = current return answer if __name__ == '__main__': main()
1
48,475,928,709,920
null
193
193
N, K = map(int,input().split()) i = 0 while True: if N/(K**i)<K: break i += 1 print(i+1)
n=int(input()) a=list(map(int,input().split())) dp=[0]*(n+1) for i in range(n-1): dp[a[i]]+=1 for i in range(n): print(dp[i+1])
0
null
48,094,655,182,422
212
169
n,k = map(int,input().split()) l = list(map(int,input().split())) l.sort() x,y=0,10**9 while y>x+1: m = (x+y)//2 c=0 for i in l: c+=(i-1)//m if c<=k: y=m else: x=m print(y)
import math N, K = map(int, input().split()) a = list(map(int, input().split())) def cal(x): s = 0 for aa in a: s += math.ceil(aa / x) - 1 if s <= K: return True else: return False l = 0 r = max(a) while r - l > 1: mid = (l + r) // 2 if cal(mid): r = mid else: l = mid print(r)
1
6,561,480,875,742
null
99
99
from bisect import bisect from itertools import accumulate as acc N = int(input()) d = dict() for i in range(2, int(N**(1/2))+2): if N%i == 0: d[i] = 0 while N%i == 0: d[i] += 1 N //= i if N != 1: d[N] = 1 a = list(acc(range(1, 100))) r = 0 for v in d.values(): r += bisect(a, v) print(r)
import math def factorization(n): arr = [] temp = n for i in range(2, int(math.ceil(n**0.5))): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i,cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr n = int(input()) if n == 1: print(0) exit(0) fact_1i = factorization(n) res = 0 for _, num in fact_1i: temp_num = 1 while temp_num <= num: res += 1 num -= temp_num temp_num += 1 print(res)
1
16,945,674,684,600
null
136
136
import sys from fractions import gcd [print("{} {}".format(gcd(k[0], k[1]), (k[0] * k[1]) // gcd(k[0], k[1]))) for i in sys.stdin for k in [[int(j) for j in i.split()]]]
import sys input = sys.stdin.readline n, res = int(input()), 0 for i in range(1, n + 1): res += 0 if i % 3 == 0 or i % 5 == 0 else i print(res)
0
null
17,517,487,345,094
5
173
#import numpy as np #import math #from decimal import * #from numba import njit #@njit def main(): N = int(input()) s = set() for _ in range(N): s.add(input()) print(len(s)) main()
x = input().split() a = int(x[0]) b = int(x[1]) c = int(x[2]) if a <= b <= c: print(a,b,c) elif a <= c <= b: print(a,c,b) elif b <= a <= c: print(b,a,c) elif b <= c <= a: print(b,c,a) elif c <= a <= b: print( c,a,b) else: print(c,b,a)
0
null
15,302,034,236,320
165
40
def main(): h = int(input()) w = int(input()) n = int(input()) if n % max(h,w) == 0: print(n//max(h,w)) else: print(n//max(h,w) + 1) if __name__=='__main__': main()
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() def resolve(): h, w, n = int(input()), int(input()), int(input()) print(min((n - 1) // h + 1, (n - 1) // w + 1)) resolve()
1
88,716,566,357,510
null
236
236
import math x,k,d = map(int,input().split()) d = abs(d) x = abs(x) if k*d<=x: print(x-k*d) else: e = math.floor(x/d) k -= e x = x-e*d if k%2 == 0: print(x) else: print(abs(x-d))
X, K, D = list(map(int, input().split())) X = abs(X) if(X >= K * D): print(X - K * D) else: q = X // D r = X % D if((K - q) % 2 == 0): print(r) else: print(abs(r - D))
1
5,267,608,622,080
null
92
92
time = int(input()) hour = int(time / 3600) minute = int(time % 3600/60) second = int(time % 60 % 60) print("%d:%d:%d" % (hour, minute, second))
S = int(input()) a = S//(60*60) b = (S-(a*60*60))//60 c = S-(a*60*60 + b*60) print(a, ':', b, ':', c, sep='')
1
334,086,098,012
null
37
37
while True: temp = input() if temp == '-': break else: cards = temp for i in range(int(input())): h = int(input()) cards = cards[h:] + cards[:h] print(cards)
while True: string = str(input()) box = "" if string == "-": break shuffle = int(input()) h = [0]*shuffle for a in range(shuffle): h[a] = int(input()) for b in range(shuffle): box = string[0:h[b]] string = string[h[b]:] string = string+box box = "" print(string)
1
1,938,858,127,140
null
66
66
def main(): import sys def input(): return sys.stdin.readline().rstrip() 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 = p[:x]+q[:y]+r r.sort(reverse=True) print(sum(r[:x+y])) if __name__ == '__main__': main()
X, Y, A, B, C = [int(_) for _ in input().split()] P = [int(_) * 3 for _ in input().split()] Q = [int(_) * 3 + 1 for _ in input().split()] R = [int(_) * 3 + 2 for _ in input().split()] S = sorted(P + Q + R) cnt = [0, 0, 0] ans = [0, 0, 0] limit = [X, Y, 10**10] while S: s = S.pop() q, r = divmod(s, 3) if cnt[r] >= limit[r]: continue cnt[r] += 1 ans[r] += q if sum(cnt) == X + Y: print(sum(ans)) exit()
1
44,885,151,749,350
null
188
188
from collections import deque N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) dic = [] que = deque() for i in range(1, N+1): que.append([i]) while que: seq = que.popleft() if len(seq) == N: dic.append(seq) continue else: for i in range(1, N+1): if i in seq: continue seq_next = seq + [i] que.append(seq_next) for i in range(len(dic)): if P == dic[i]: a = i if Q == dic[i]: b = i print(abs(a-b))
bit=[0]*9 fa=[1]*9 for n in range(1,9):fa[n]=fa[n-1]*n def up(id): while id<9: bit[id]+=1 id+=id&(-id) def qr(id): res=0 while id: res+=bit[id] id-=id&(-id) return res x=int(input()) s=list(map(int,input().split())) z=list(map(int,input().split())) v='' for n in s: a=qr(n) vl=n-1-a v+=str(vl) up(n) v=v[::-1] r1=0 for n in range(len(v)): r1+=int(v[n])*fa[n] r2=0 v='' bit=[0]*9 for n in z: a=qr(n) vl=n-1-a v+=str(vl) up(n) v=v[::-1] for n in range(len(v)): r2+=int(v[n])*fa[n] print(abs(r1-r2))
1
100,936,833,632,380
null
246
246
import sys read=sys.stdin.readline class SEGTree: def __init__(self,n): self.Unit=0 i=1 while(i<n): i*=2 self.SEG=[self.Unit]*(2*i-1) self.d=i def update(self,i,x): i+=self.d-1 self.SEG[i]=1<<x while i>0: i=(i-1)//2 self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2] def find(self,a,b,k,l,r): if r<=a or b<=l: return self.Unit if a<=l and r<=b: return self.SEG[k] else: c1=self.find(a,b,2*k+1,l,(l+r)//2) c2=self.find(a,b,2*k+2,(l+r)//2,r) return c1|c2 def get(self,a,b): return self.find(a,b,0,0,self.d) def bitcnt(x): res=0 while x>0: if x&1: res+=1 x//=2 return res n=int(input()) s=input() q=int(input()) seg=SEGTree(n) for i in range(n): seg.update(i,ord(s[i])-97) for i in range(q): q,x,y=read().rstrip().split() if q=='1': seg.update(int(x)-1,ord(y)-97) else: x,y=int(x)-1,int(y) bit=seg.get(x,y) print(bitcnt(bit))
import sys import bisect N = int(sys.stdin.readline().rstrip()) S = list(sys.stdin.readline().rstrip()) Q = int(sys.stdin.readline().rstrip()) idx = {chr(ord("a") + i): [] for i in range(26)} for i, s in enumerate(S): idx[s].append(i + 1) for _ in range(Q): t, i, c = sys.stdin.readline().rstrip().split() i = int(i) if t == "1": if S[i - 1] != c: idx[S[i - 1]].remove(i) bisect.insort(idx[c], i) S[i - 1] = c else: c = int(c) ans = 0 for a, id in idx.items(): x = bisect.bisect_left(id, i) y = bisect.bisect_right(id, c) if y - x: ans += 1 print(ans)
1
62,220,530,425,340
null
210
210
x, y = (int(x) for x in input().split()) if x == y == 1: print(1000000) else: ans = 0 points = [300000, 200000, 100000] if x <= 3: ans += points[x-1] if y <= 3: ans += points[y-1] print(ans)
X,Y=map(int,input().split()) prize=[0,300000,200000,100000] ans=0 for c in [X,Y]: if c<=3: ans+=prize[c] if X==Y==1: ans+=400000 print(ans)
1
140,287,062,046,650
null
275
275
from numba import jit N, K = map(int, input().split()) A = list(map(int, input().split())) @jit def solve(k,n,a): for _ in range(k): Y = [0]*(n+1) for i, x in enumerate(a): Y[max(0, i-x)] += 1 Y[min(n, i+x+1)] -= 1 for j in range(1, n): Y[j] += Y[j-1] if a == Y[:-1]: break a = Y[:-1] return a ans=solve(K,N,A) print(*ans)
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n, k = ns() a = na() for _ in range(k): imos = [0 for _ in range(n)] for i, ai in enumerate(a): imos[max(0, i - ai)] += 1 if i + ai + 1 < n: imos[i + ai + 1] -= 1 val = 0 for i, im in enumerate(imos): val += im a[i] = min(val, n) if min(a) == n: break print(*a, sep=" ") if __name__ == '__main__': main()
1
15,501,360,079,040
null
132
132
S=str(input()) ls = ["SAT","FRI","THU","WED","TUE","MON","SUN"] for i in range(7): if S == ls[i]: print(i+1)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) s = input() day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] print(7 - day.index(s))
1
132,979,065,865,728
null
270
270
l = input() s = l[-1] c = '' if s == 's': c = l + 'es' else: c = l + 's' print(c)
N=int(input()) m=0 x=[[0]*9 for i in range(9)] for i in range(1,N+1): if i%10==0: continue b=int(str(i)[0]) g=int(i%10) x[b-1][g-1]+=1 ans=0 for i in range(9): for j in range(9): ans+=x[i][j]*x[j][i] #print(i+1,j+1,x[i][j]) print(ans)
0
null
44,485,658,074,448
71
234
N, A, B = map(int, input().split()) if A == 0: print(0) exit() quotient = N // (A + B) * A remainder = N % (A + B) quotient += min((remainder, A)) print(quotient)
import math k = 1 x = float(input()) while x*k%360 != 0: k += 1 print(k)
0
null
34,464,221,987,920
202
125
N,K=map(int,input().split()) A=list(map(int,input().split())) mod=10**9+7 if N==K: #全部 ans=1 for i in range(N): ans*=A[i] ans%=mod print(ans) exit() if max(A)<0 and K%2==1: #答えがマイナス A.sort(reverse=True) ans=1 for i in range(K): ans*=A[i] ans%=mod print(ans) exit() plus=[] minus=[] for i in range(N): if A[i]>=0: plus.append(A[i]) else: minus.append(A[i]) plus.sort(reverse=True) #5,3,1 minus.sort() #-5,-3,-1 plus_k=0 minus_k=0 if K%2==0: ans=1 else: ans=plus[0] plus_k=1 for _ in range(K): if plus_k+minus_k==K: break if plus_k>=len(plus)-1: ans*=minus[minus_k]*minus[minus_k+1]%mod ans%=mod minus_k+=2 continue if minus_k>=len(minus)-1: ans*=plus[plus_k]*plus[plus_k+1]%mod ans%=mod plus_k+=2 continue if plus[plus_k]*plus[plus_k+1]>minus[minus_k]*minus[minus_k+1]: ans*=plus[plus_k]*plus[plus_k+1]%mod ans%=mod plus_k+=2 continue else: ans*=minus[minus_k]*minus[minus_k+1]%mod ans%=mod minus_k+=2 continue print(ans)
def e_multiplication_4(MOD=10**9 + 7): from functools import reduce N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] sign = {-1: 0, 0: 0, 1: 0} # A の各要素の符号 for a in A: if a == 0: sign[0] += 1 continue sign[a // abs(a)] += 1 if sign[1] == 0 and K % 2 == 1: # どうやっても解は負。絶対値の小さなものから掛けていく A.sort(reverse=True) return reduce(lambda x, y: (x * y) % MOD, A[:K]) if sign[1] == 0 and K % 2 == 0: # 先程と違って絶対値の大きなものから掛けても解は正になる A.sort() return reduce(lambda x, y: (x * y) % MOD, A[:K]) A.sort() ans = 1 i, j = 0, N - 1 while K > 0: # 負の絶対値が大きいものから 2 個取るか? 正の絶対値が大きいものから 1 個取るか? # i, j がそれぞれ負の値、非負の値を指さなくなった場合、if 文のどちらかを # 確実に通らなくなるので、i, j についての条件は必要ない if K > 1 and A[i] * A[i + 1] >= A[j] * A[j - 1]: ans *= A[i] * A[i + 1] i += 2 K -= 2 else: ans *= A[j] j -= 1 K -= 1 ans %= MOD return ans print(e_multiplication_4())
1
9,500,257,331,860
null
112
112
A = int(input()) B = int(input()) anss = set([1, 2, 3]) anss.remove(A) anss.remove(B) for i in anss: print(i)
l = [1,2,3] l.remove(int(input())) l.remove(int(input())) print(l[0])
1
110,451,648,100,180
null
254
254
n,m = map(int,input().split()) if n%2: for i in range(1,m+1): print(i,n-i+1) else: for i in range(1,m+1): if n-2*i+1>n//2: print(i,n-i+1) else: print(i,n-i)
n, m = map(int, input().split()) if m%2 == 0: x = m//2 y = m//2 else: x = m//2 y = m//2+1 for i in range(x): print(i+1, 2*x+1-i) for i in range(y): print(i+2*x+2, 2*y+2*x+1-i)
1
28,829,123,557,348
null
162
162
''' Date : 2020-08-09 00:46:52 Author : ssyze Description : ''' n, k = map(int, input().split()) a = list(map(int, input().split())) def check(m): sum = 0 for i in range(len(a)): sum += (a[i] - 1) // m if sum > k: return False else: return True l = 1 r = 10**9 ans = 10**9 while l < r: mid = (l + r) // 2 if check(mid) == 1: r = mid ans = mid else: l = mid + 1 print(ans)
S = input() ans = 'Yes' while S: if S.startswith('hi'): S = S[2:] else: ans = 'No' break print(ans)
0
null
29,837,046,048,940
99
199
n = int(input()) data = list(map(int, input().split())) def insertion_sort(A, N): print(*A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A) insertion_sort(data, n)
N = int(input()) A = [int(x) for x in input().split()] print(*A) for i in range(1, len(A)): key = A[i] j = i-1 while j >= 0 and A[j] > key: A[j+1] = A[j] j += -1 A[j+1] = key print(*A)
1
5,245,134,062
null
10
10
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)
from collections import defaultdict def bfs(s): q = [s] while q != []: p = q[0] del q[0] for node in adj[p]: if not visited[node]: visited[node] = True q.append(node) n,m = map(int,input().split()) adj = defaultdict(list) visited = [False]*(n+1) comp = 0 for _ in range(m): a,b = map(int,input().split()) adj[a].append(b) adj[b].append(a) for i in range(1,n+1): if not visited[i]: comp+=1 bfs(i) print(comp-1)
1
2,297,592,503,580
null
70
70
N, A, B = map(int, input().split()) ans = 0 def odd(): global ans ans += (B - A) // 2 if (B - A) % 2 == 0: odd() else: if (N - B) <= (A - 1): ans += (N - B) + 1 A += (N - B) + 1 B = N else: ans += (A - 1) + 1 B -= (A - 1) + 1 A = 1 odd() print(ans)
print(int(input()) * 2 * __import__("math").pi)
0
null
70,314,000,056,050
253
167
import math import numpy as np import queue from collections import deque import heapq mod = 10**9+7 ans = 1 iw0 = 0 def twoxxn(t,mod): ni = t an = 1 n2 = 2 while ni > 0: if ni%2 == 1: an = (an*n2)%mod n2 = (n2**2)%mod ni >>= 1 return an n = int(input()) d = dict() for i in range(n): a,b = map(int,input().split()) if a == 0 and b == 0: iw0 += 1 continue if a == 0: b = 1 g = 1 elif b == 0: a = 1 g = 1 else: g = math.gcd(abs(a),abs(b)) if a < 0 : a = -a b = -b p1 = a//g, b//g if p1 in d: d[p1] += 1 else: d[p1] = 1 done = [] for (i0,i1), din in d.items(): if d.get((-i1,i0),1) == 0 or d.get((i1,-i0),1) == 0: continue w = d.get((i1,-i0),0) + d.get((-i1,i0),0) aaa = (twoxxn(w,mod)+twoxxn(din,mod)-1)%mod ans = (ans*aaa)%mod d[(i0,i1)] = 0 if len(d.keys()) == 0: print(iw0) exit() ans = (iw0+ans+mod-1)%mod print(ans)
from collections import defaultdict from math import gcd def main(): N = int(input()) MOD = 10 ** 9 + 7 zero = 0 d = defaultdict(lambda: defaultdict(int)) for i in range(N): A, B = map(int, input().split()) if A == 0 and B == 0: zero += 1 continue if B < 0: A = -A B = -B flag = False if A <= 0: A, B = B, -A flag = True g = gcd(A,B) A //= g B //= g if flag: d[(A,B)]['first'] += 1 else: d[(A,B)]['second'] += 1 ans = 1 for i, j in d.items(): now = 1 now += pow(2,j['first'],MOD) - 1 now += pow(2,j['second'],MOD) - 1 ans *= now ans %= MOD ans -= 1 ans += zero ans %= MOD print(ans) if __name__ == "__main__": main()
1
20,958,267,398,212
null
146
146
N = input() A=[] for i in N: A.append(i) hon = ["2","4","5","7","9"] pon = ["0","1","6","8"] bon = ["3"] if A[-1] in hon: print("hon") elif A[-1] in pon: print("pon") else: print("bon")
while True: (H,W) = [int(x) for x in input().split()] if H == W == 0: break for h in range(0, H): for w in range(0, W): print("#", end="") if w == W - 1: print() break print()
0
null
10,025,836,761,090
142
49
a,b,c = map(int, raw_input().split()) value = [a,b,c] value.sort() value_str = map(str, value) print " ".join(value_str)
x = int(input()) x500 = x // 500 y = x - x500*500 y5 = y // 5 z = y - y5*5 print(x500*1000+y5*5)
0
null
21,617,806,888,228
40
185
import sys def input(): return sys.stdin.readline().rstrip() N = int(input()) num = (N + 1000 - 1 )// 1000 print(num * 1000 - N)
def ceil(n): if n%1000: return (1+n//1000)*1000 else: return n def debt(n): if n==0: return 100000 return int(ceil(debt(n-1)*1.05)) print(debt(int(input())))
0
null
4,214,536,986,230
108
6
n = int(input()) xy_sum = [] xy_dif = [] for i in range(n) : x, y = map(int, input().split()) xy_sum.append(x + y) xy_dif.append(x - y) print(max(abs(max(xy_sum) - min(xy_sum)), abs(max(xy_dif) - min(xy_dif))))
N = int(input()) X = [] Y = [] for _ in range(N): x, y = list(map(int, input().split())) X.append(x) Y.append(y) points = [] for x, y in zip(X, Y): points.append(( x + y, x - y )) print(max(max(dim) - min(dim) for dim in zip(*points)))
1
3,416,097,145,188
null
80
80