code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
N = int(input()) A = list(map(int, input().split())) dicA = {} for i in range(1, N+1): dicA[i] = A[i-1] sort_dicA = sorted(dicA.items(), key=lambda x:x[1]) for i in range(N): print(sort_dicA[i][0], end=' ')
n = int(input()) a = list(map(int,input().split())) tl = [0 for i in range(n)] for i in range(n): tl[a[i] -1] = str(i+1) print(' '.join(tl))
1
180,192,325,810,240
null
299
299
S = ["ABC","ARC"] print(S[S.index(input())-1])
import numpy as np n, k = map(int, input().split()) fruits = np.array(input().split(),dtype=np.int64) fruits.sort() ans = 0 cnt = 0 for i in fruits: if(cnt < k): ans += i cnt += 1 print(ans)
0
null
17,860,753,329,408
153
120
N = int(input()) A = [[[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10], [[0] * 10, [0] * 10, [0] * 10]] for i in range(N): b, f, r, v = [int(j) for j in input().split()] A[b-1][f-1][r-1] += v for a, b in enumerate(A): for f in b: print(' ' + ' '.join([str(i) for i in f])) else: if a != len(A) - 1: print('#' * 20)
n= int(input()) table=[[[0]*10 for i in range(0,3)]for j in range(0,4)] for k in range(n): b,f,r,v = map(int,input().split()) table[b-1][f-1][r-1] +=v x=0 for i in range(4): if x !=0: print("#"*20) x =x+1 for a in range(3): for b in range(10): print(" %d"%(table[i][a][b]),end="") print()
1
1,079,501,663,712
null
55
55
h1, m1, h2, m2, k = map(int, input().split()) H = h2 - h1 if m1 <= m2: M = m2 - m1 else: M = 60 - m1 + m2 H -= 1 print(H*60 + M - k)
H1, M1, H2, M2, K = map(int, input().split()) x = H1*60+M1 y = H2*60+M2 print(y-x-K)
1
18,038,205,733,992
null
139
139
N = int(input()) S = input() third = [[[False]*10 for _ in range(10)] for __ in range(10)] second = [[False]*10 for _ in range(10)] first = [False]*10 for s in S: s = int(s) for i in range(10): if first[i]: for j in range(10): if second[i][j]: third[i][j][s] = True second[i][s] = True first[s] = True res = 0 for i in range(10): for j in range(10): for k in range(10): if third[i][j][k]: # print(i, j, k) res += 1 print(res)
from collections import Counter N = int(input()) S = input() ans = 0 for x in range(10): for y in range(10): hantei = [] for i in range(N): if x != int(S[i]): continue for j in range(i+1, N): if y != int(S[j]): continue for k in range(j+1, N): hantei.append(S[k]) ans += len(Counter(hantei)) break break print(ans)
1
128,086,460,090,602
null
267
267
n, m = map(int, input().split()) ac = [0] * n wa = [0] * n for _ in range(m): p, s = input().split() if s == 'AC': ac[int(p) - 1] = 1 elif ac[int(p) - 1] == 0: wa[int(p) - 1] += 1 for i in range(n): if ac[i] == 0: wa[i] = 0 print(sum(ac), sum(wa))
import copy n = int(input()) A = list(map(str,input().split())) B = copy.copy(A) def BubbleSort(A,n): for i in range(n): for j in range(n-1,i,-1): if int(A[j][1:2])<int(A[j-1][1:2]): v = A[j] A[j] = A[j-1] A[j-1] = v return A def SelectionSort(A,n): for i in range(n): minj = i for j in range(i,n): if int(A[j][1:2])<int(A[minj][1:2]): minj = j v = A[i] A[i] = A[minj] A[minj] = v return A print(' '.join(BubbleSort(A,n))) print('Stable') print(' '.join(SelectionSort(B,n))) if BubbleSort(A,n) == SelectionSort(B,n): print('Stable') else: print('Not stable')
0
null
46,804,812,921,020
240
16
n,m=map(int,input().split()) h=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(m)] from math import gcd ans=[1 for _ in range(n)] for ab in AB: if h[ab[0]-1]>h[ab[1]-1]: ans[ab[1]-1]=0 elif h[ab[0]-1]<h[ab[1]-1]: ans[ab[0]-1]=0 else: ans[ab[0]-1]=0 ans[ab[1]-1]=0 print(sum(ans))
n, m = map(int, input().split()) arr = [0] + list(map(int, input().split())) g = [[] for _ in range(n + 1)] for _ in range(m): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) ans = 0 for i in range(1, n + 1): for j in g[i]: if arr[j] >= arr[i]: break else: ans += 1 print(ans)
1
25,070,170,642,832
null
155
155
n = int(input()) print(len([i for i, j in enumerate(input().split()) if int(j)%2 == 1 and i%2 == 0]))
N = int(input()) a = list(map(int, input().split())) answer = 0 for i, e in enumerate(a): i += 1 if i % 2 != 0 and e % 2 != 0: answer += 1 print(answer)
1
7,761,251,062,370
null
105
105
import math x_1, y_1, x_2, y_2 = map(float, input().split()) l = math.sqrt((x_1 - x_2)**2 + (y_1 - y_2)**2) print(l)
# 1 <= N <= 1000000 N = int(input()) total = [] # N項目までに含まれる->N項目は含まない。だからN項目は+1で外す。 for x in range(1, N+1): if x % 15 == 0: "FizzBuzz" elif x % 5 == 0: "Buzz" elif x % 3 == 0: "Fizz" else: total.append(x) #リストに加える print(sum(total))
0
null
17,574,456,309,158
29
173
n, q = (int(x) for x in input().split()) process = [input().split() for _ in range(n)] time = 0 while process: p = process.pop(0) if int(p[1]) <= q: time += int(p[1]) print(p[0], time) else: time += q process.append([p[0], int(p[1]) - q])
import sys import collections s=sys.stdin.readlines() n,q=map(int,s[0].split()) d=collections.deque(e.split()for e in s[1:]) t=0 while d: k,v=d.popleft() v=int(v) if v>q: v-=q t+=q d.append([k,v]) else: t+=v print(k,t)
1
43,910,829,380
null
19
19
a=int(input()) b=int(input()) ans = set() ans.add(a) ans.add(b) all = {1,2,3} print((all-ans).pop())
a=int(input()) b=int(input()) v=[1,2,3] for i in v: if a!=i and b!=i: print(i) break
1
110,521,771,483,620
null
254
254
N = int(input()) dic = {} for _ in range(N): s = input() if s in dic: dic[s] += 1 else: dic[s] = 1 num = 0 for key in dic: num = max(num, dic[key]) ans = [] for key in dic: if dic[key] == num: ans.append(key) ans.sort() for a in ans: print(a)
import sys import collections S = int(next(sys.stdin)) _A = (s.strip() for s in sys.stdin) A = collections.Counter(_A) # print(A) # print(max(A.values())) m = max(A.values()) keys = [k for k, v in A.items() if v == m] keys.sort() for s in keys: print(s)
1
70,208,089,503,652
null
218
218
v = int(input()) n = list(map(int, input().split(' '))) c = 0 for i in range(0, v, 2): if n[i] %2 == 1: #print(n[i]) c += 1 print(c)
a=0 while True: z=str(input()) if z == '0' : break for i in z: k=int(i) a+=k print(a) a=0
0
null
4,610,509,750,242
105
62
t = int(input()) print(t+t**2+t**3)
import sys def input() : return sys.stdin.readline().strip() def main(): N = int(input()) A = tuple(map(int, input().split())) left_sum = [0] * N # [0, i] right_sum = [0] * N # [i, N-1] left_sum[0] = A[0] right_sum[-1] = A[-1] for i in range(1, N): left_sum[i] = left_sum[i-1] + A[i] right_sum[(N-1)-i] = right_sum[(N-1)-(i-1)] + A[(N-1)-i] ans = 10 ** 18 for i in range(N-1): diff = abs(left_sum[i] - right_sum[i+1]) ans = min(ans, diff) print(ans) if __name__ == "__main__": main()
0
null
76,193,317,095,892
115
276
N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort(reverse=True) F.sort() C = [None] * N for i, (a, f) in enumerate(zip(A, F)): C[i] = (a * f, f) def solve(x): global K, N t = 0 for c, f in C: temp = ((c - x) + f - 1) // f t += max(0, temp) if t > K: result = False break else: result = True return result ok = A[0] * F[N - 1] ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid): ok = mid else: ng = mid print(ok)
n,k = map(int, input().split()) al = list(map(int, input().split())) fl = list(map(int, input().split())) al.sort() fl.sort(reverse=True) afl = [] for a,f in zip(al,fl): afl.append((a,f)) ok, ng = 10**12, -1 while abs(ok-ng) > 1: mid = (ok+ng) // 2 cnt = 0 for a,f in afl: val = a*f train_cnt = (val-mid-1)//f + 1 cnt += max(train_cnt, 0) if cnt <= k: ok = mid else: ng = mid print(ok)
1
165,017,999,562,258
null
290
290
L = int(input()) a = L/3 ans = a**3 print(ans)
X, Y, Z = [int(x) for x in input().split()] print('{} {} {}'.format(Z, X, Y))
0
null
42,432,678,431,110
191
178
n = int(input()) a = list(map(int,input().split())) c = [0,0,0] count = 1 for i in range(n): match = (a[i]==c[0])+(a[i]==c[1])+(a[i]==c[2]) if match==0: count = 0 break elif match==1 or a[i]==0: c[c.index(a[i])] += 1 else: c[c.index(a[i])] += 1 count = (count*match)%(1e+9+7) if count != 0: c = sorted(c,reverse=True) while 0 in c: c.pop() memory = set() kinds = 0 for x in c: if not x in memory: kinds += 1 for i in range(3,3-kinds,-1): count = (count*i)%(1e+9+7) print(int(count))
class Dice(object): def __init__(self, nums): from collections import deque self.ns = deque([nums[4], nums[0], nums[1]]) self.we = deque([nums[3], nums[0], nums[2]]) self.bk = deque([nums[5]]) def __str__(self): return str({"ns": self.ns, "we": self.we, "bk": self.bk}) def operation(self, o): if o == "N": self.n() elif o == "S": self.s() elif o == "W": self.w() elif o == "E": self.e() else: raise BaseException("invalid", o) def n(self): self.ns.append(self.bk.popleft()) self.bk.append(self.ns.popleft()) self.we[1] = self.ns[1] def s(self): self.ns.appendleft(self.bk.pop()) self.bk.appendleft(self.ns.pop()) self.we[1] = self.ns[1] def w(self): self.we.append(self.bk.popleft()) self.bk.append(self.we.popleft()) self.ns[1] = self.we[1] def e(self): self.we.appendleft(self.bk.pop()) self.bk.appendleft(self.we.pop()) self.ns[1] = self.we[1] def rotate_right(self): tmp = self.ns tmp.reverse() self.ns = self.we self.we = tmp def fit_top_s(self, top, s): while self.get_top() != top: if top in self.ns: self.n() elif top in self.we: self.w() else: self.n() self.n() while self.get_s() != s: self.rotate_right() def get_top(self): return self.ns[1] def get_s(self): return self.ns[2] def get_e(self): return self.we[2] def resolve(): nums = [int(i) for i in input().split()] dc = Dice(nums) q = int(input()) for _ in range(q): top, s = [int(i) for i in input().split()] dc.fit_top_s(top, s) print(dc.get_e()) resolve()
0
null
65,353,011,295,076
268
34
import math K = int(input()) ans = 0 for a in range(K): for b in range(K): for c in range (K): ans += math.gcd(math.gcd(a+1, b+1), c+1) print(ans)
a = [list(map(int, input().split())) for _ in range(3)] n = int(input()) b = [int(input()) for _ in range(n)] mark = [[False, False, False] for _ in range(3)] for i in range(3): for j in range(3): if a[i][j] in b:mark[i][j] = True ans = 'No' for i in range(3): if all(mark[i]): ans = 'Yes' break for j in range(3): if mark[0][j] and mark[1][j] and mark[2][j]: ans = 'Yes' break if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[0][2] and mark[1][1] and mark[2][0]): ans = 'Yes' print(ans)
0
null
47,556,292,293,078
174
207
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n,a,b = readInts() ab = abs(b-a) if ab%2 == 0: print(ab//2) else: print(min(a-1, n-b) + 1 + (b-a-1)//2)
def main(): n, a, b = map(int, input().split()) if (b - a) % 2 == 0: ans = (b - a) // 2 else: if b - 1 < n - a: g = (b - a + 1) // 2 ans = a + g - 1 else: g = (2 * n + a - b + 1) // 2 ans = 2 * n - b - g + 1 print(ans) if __name__ == "__main__": main()
1
108,991,960,130,468
null
253
253
from collections import deque n,m = map(int,input().split()) to = [[] for _ in range(n)] for i in range(m): x, y = map(int,input().split()) to[x-1].append(y-1) to[y-1].append(x-1) INF = float('inf') dist = [INF]*n dist[0] = 0 pre = [-1]*n que = deque([]) que.append(0) while que: v = que.popleft() for u in to[v]: if dist[u] != INF:continue dist[u] = v + 1 pre[u] = v que.append(u) print("Yes") for i in range(1,n): print(dist[i])
h,w,k=[int(j) for j in input().split()] s=[list(map(int,list(input()))) for i in range(h)] import itertools s=tuple(itertools.chain(*zip(*s))) ans=10**18 for i in range(1<<(h-1)): dp=list(s) for j in range(h-1): if i&(1<<j): for n in range(0,h*w,h): dp[n+j+1]+=dp[n+j] tmp=h-1-bin(i).count("1") b=False for n in range(0,h*w,h): if any(dp[n+j]>k for j in range(h)): tmp=10**18 break if n+h==h*w: ans=min(ans,tmp) tmp=10**18 break if any(dp[n+j]+dp[n+j+h]>k for j in range(h)): tmp+=1 continue for j in range(h): dp[n+j+h]+=dp[n+j] ans=min(ans,tmp) print(ans)
0
null
34,439,058,888,620
145
193
ans = list(map(int,input().split())) print(ans[2],ans[0],ans[1])
from collections import defaultdict from math import gcd MOD=10**9+7 n=int(input()) L=[] for i in range(n): l=list(map(int,input().split())) L.append(l) def kikaku(a,b): g=gcd(a,b) a//=g b//=g if a<0: return -a,-b return a,b #aもbも正の場合Dposでカウント。 Dpos=defaultdict(int) #aが正bが負の場合Dnegでカウント。 Dneg=defaultdict(int) zerozero=0 azero=0 bzero=0 for l in L: a=l[0] b=l[1] if a==b==0: zerozero+=1 continue if a==0: azero+=1 continue if b==0: bzero+=1 continue a,b=kikaku(a,b) if b>0: Dpos[(a,b)]+=1 else: Dneg[(a,-b)]+=1 Dpos[(-b,a)]+=0 r=1 for k,v in Dpos.items(): a,b=k j=Dneg[(b,a)] r*=pow(2,v,MOD)+pow(2,j,MOD)-1 #print(a,b,v,j,r) r%=MOD r*=pow(2,azero,MOD)+pow(2,bzero,MOD)-1 r%=MOD r-=1 r%=MOD ans=r+zerozero ans%=MOD print(ans) #print(Dpos) #print(Dneg)
0
null
29,273,538,830,634
178
146
T1, T2 = map(int,input().split()) A1, A2 = map(int,input().split()) B1, B2 = map(int,input().split()) T = T1*A1+T2*A2 A = T1*B1+T2*B2 if T == A: print("infinity") exit() if T > A: if A1 > B1: print(0) exit() else: tdif = T-A #7-5 pdif = T1*(B1-A1) #5 if pdif%tdif == 0: ans = 2*(pdif//tdif)+1 else: ans = 2*(1+pdif//tdif) ans -=1 #原点の分を引く else: if B1 > A1: print(0) exit() else: tdif = A-T #7-5 pdif = T1*(A1-B1) #5 if pdif%tdif == 0: ans = 2*(pdif//tdif)+1 else: ans = 2*(1+pdif//tdif) ans -=1 #原点の分を引く print(ans)
t1,t2=map(int,input().split()) a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) p=a1-b1 q=a2-b2 if p*t1+q*t2==0:print('infinity');exit() elif p<0:p,q=-p,-q #p>0 if p*t1+q*t2>0:print(0) else: a=p*t1 d=-(a+q*t2) print(2*(a//d)+int(not(not a%d)))
1
131,248,306,875,488
null
269
269
N = int(input()) z = [] w = [] for i in range(N): x,y = map(int,input().split()) z.append(x+y) w.append(x-y) z_max = max(z) z_min = min(z) w_max = max(w) w_min = min(w) print(max(z_max-z_min,w_max-w_min))
N,K = map(int,input().split()) M = list(map(int,input().split())) M =sorted(M,reverse=True) print(sum(M[K:]))
0
null
41,187,194,984,000
80
227
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil, atan, pi # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline().strip() # warning bytes # def input(): return sys.stdin.buffer.readline().decode('utf-8') import string # string.ascii_lowercase from bisect import bisect_left MOD = int(1e9)+7 INF = float('inf') g = defaultdict(list) n = 0 ans = defaultdict(int) def bfs(x): q = deque([(x, 0)]) w = set([x]) while q: v, dis = q.popleft() if v > x: ans[dis] += 1 for to in g[v]: if to not in w: w.add(to) q.append((to, dis + 1)) def solve(): # n, m = [int(x) for x in input().split()] n, X, Y = [int(x) for x in input().split()] X -= 1 Y -= 1 g[X].append(Y) g[Y].append(X) for i in range(1, n): g[i].append(i-1) g[i-1].append(i) for i in range(n-1): bfs(i) for i in range(1, n): print(ans[i]) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
N = int(input()) S = [input() for _ in range(N)] # ABC-081-Cの類題! # 方針:各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する # 各単語の出現回数を数える(辞書型を用いる!!) dic = {} for i in range(N): s = S[i] if s not in dic: dic[s] = 1 else: dic[s] += 1 max_count = max(dic.values()) # 最大の出現回数 # 出現回数が最も多い単語を集計する l = [key for key in dic.keys() if dic[key] == max_count] # 昇順にソートして出力 for i in sorted(l): print(i)
0
null
57,021,878,063,420
187
218
t = input() if(len(t) == 1): if (t[0] == '?'): t = "D" if(t[0] == '?'): if (t[1] == 'D'): t = "".join(['P' , t[1:]]) elif(t[1] == '?'): t = "".join(['PD', t[2:]]) else: t = "".join(['D' , t[1:]]) if(t[-1] == '?'): t = "".join([t[:-1], 'D']) for i in range(len(t)-1): if(t[i] == '?'): if(t[i-1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]]) elif(t[i+1] == 'D'): t = "".join([t[:i], 'P' , t[i+1:]]) elif(t[i+1] == 'P'): t = "".join([t[:i], 'D' , t[i+1:]]) elif(t[i+1] == '?'): t = "".join([t[:i], 'PD', t[i+2:]]) print(t)
T = list(map(str, input())) count = 0 ans = [] for i in range(0, len(T)): if T[i] == '?': ans.append('D') else: ans.append(T[i]) ans_ans = ''.join(ans); print(ans_ans)
1
18,530,093,548,110
null
140
140
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if not V > W: print("NO") elif (V-W)*T >= abs(B-A): print("YES") else: print("NO")
n=int(input()) r=list(map(int,input().split())) t=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if r[i]==r[j] or r[j]==r[k] or r[i]==r[k]:continue s=[r[i],r[j],r[k]] s.sort() if s[0]+s[1]>s[2]: t+=1 print(t)
0
null
10,047,160,592,760
131
91
def warshall_floid(d): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): d[i][j] = min(d[i][j],d[i][k]+d[k][j]) return d n,m,l = map(int,input().split()) d = [[10**13]*(n+1) for i in range(n+1)] for i in range(m): a,b,c = map(int,input().split()) d[a][b] = c d[b][a] = c for i in range(1,n+1): d[i][i] = 0 d = warshall_floid(d) for i in range(1,n+1): for j in range(1,n+1): if d[i][j] <= l: d[i][j] = 1 else: d[i][j] = 10**13 d = warshall_floid(d) q = int(input()) for i in range(q): s,t = map(int,input().split()) if d[s][t] >= 10**13: print(-1) else: print(d[s][t]-1)
def LI(): return list(map(int, input().split())) X, Y, A, B, C = LI() red = LI() green = LI() mu = LI() red.sort(reverse=True) green.sort(reverse=True) ans = red[:X]+green[:Y]+mu ans.sort(reverse=True) total = 0 for i in range(X+Y): total += ans[i] print(total)
0
null
109,011,649,471,140
295
188
N = int(input()) D = [list(map(int, input().split())) for _ in range(N)] for i in range(N-2): if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]: print('Yes') exit() print('No')
n, x, y = map(int,input().split()) cnt = [0] * (n - 1) for i in range(1, n): for j in range(i + 1, n + 1): temp1 = j - i temp2 = abs(i - x) + abs(j - y) + 1 dis = min(temp1, temp2) cnt[dis - 1] += 1 print(*cnt, sep='\n')
0
null
23,259,722,398,080
72
187
import math from numpy.compat.py3k import asstr a, b = map(int, input().split()) ans = int(a * b / math.gcd(a, b)) print(str(ans))
n=int(input()) lst={} for i in range(n): lst[input()]=1 print(len(lst))
0
null
71,601,407,830,000
256
165
def main(): a = int(input()) b = int(input()) print(6 - a - b) if __name__ == "__main__": main()
n=int(input()) s=input() ans="" for i in range(len(s)): a=(ord(s[i])+n-65)%26 ans=ans+chr(a+65) print(ans)
0
null
122,966,154,237,258
254
271
n, d, a = map(int, input().split()) xh = [] for _ in range(n): x, h = map(int, input().split()) xh.append((x, h)) xh.sort(key=lambda x:x[0]) def bisect(x): ok = n ng = -1 while abs(ok-ng)>1: mid = (ok+ng)//2 if xh[mid][0]>x: ok = mid else: ng = mid return ok out = [0]*(n+1) ans = 0 accu = 0 for ind, (x, h) in enumerate(xh): accu -= out[ind] h -= accu if h<=0: continue ans += (h+a-1)//a accu += ((h+a-1)//a)*a out[bisect(x+2*d)] += ((h+a-1)//a)*a print(ans)
n, k = map(int, input().split()) mod = 1000000007 b = mod-2 blis = [] c = 0 while b >0: if b & 1 == 1: blis.append(c) c += 1 b >>= 1 def modinv(a): if a == 1: return 1 else: res = 1 li = [] for _ in range(c): li.append(a%mod) a = a*a%mod for item in blis: res = res *li[item] %mod return res if k >=n: L = 2*n-1 ansbunsi =1 for j in range(n-1): ansbunsi = ansbunsi*L%mod L -= 1 ansbunbo = 1 L = n - 1 for j in range(n-1): ansbunbo = ansbunbo*L%mod L -= 1 ansbunbo = modinv(ansbunbo) print(ansbunsi*ansbunbo%mod) else: kaijou = [1, 1] for j in range(2, n): kaijou.append(kaijou[-1]*j%mod) ans = 0 for m in range(k+1): ansbunsi = (kaijou[n-1]**2)*n%mod ansbunbo = kaijou[n-m-1]*kaijou[m]%mod ansbunbo = ansbunbo*ansbunbo%mod*(n-m)%mod ansbunbo = modinv(ansbunbo) ans += ansbunbo*ansbunsi%mod ans %= mod print(ans)
0
null
74,786,661,429,060
230
215
X,K,D=map(int, input().split()) if 0<abs(X)<K*D: a=X//D K-=a if K%2==0: ans=X-D*a else: ans=X-D*(a+1) else: ans=abs(X)-K*D print(abs(ans))
x, k, d = map(int, input().split()) x = abs(x) if x - k * d > 0: ans = x - k * d else: if (k - x // d) % 2 == 0: ans = x - d * (x // d) else: ans = abs(x - d * (x // d) - d) print(ans)
1
5,245,299,914,458
null
92
92
import sys from bisect import bisect_left, bisect_right, insort sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() S = list('-' + sr()) d = [[] for _ in range(26)] for i in range(1, N+1): s = S[i] o = ord(s) - ord('a') d[o].append(i) Q = ir() for _ in range(Q): q, a, b = sr().split() if q == '1': a = int(a) if S[a] == b: continue prev = ord(S[a]) - ord('a') d[prev].pop(bisect_left(d[prev], a)) next = ord(b) - ord('a') insort(d[next], a) S[a] = b else: left = int(a); right = int(b) ans = 0 for alpha in range(26): index = bisect_left(d[alpha], left) if index < len(d[alpha]) and d[alpha][index] <= right: ans += 1 print(ans)
# -*- coding:utf-8 -*- def solve(): import math N, K = list(map(int, input().split())) As = list(map(int, input().split())) left, right = 1, 10**9 while left != right: mid = (left+right)//2 cut = 0 for a in As: if a/mid > 1: cut += math.ceil(a/mid) - 1 if cut <= K: # 切って良い回数を満たしている if left+1 == right: print(left) return right = mid else: # 切って良い回数を満たしていない if left+1 == right: print(right) return left = mid if __name__ == "__main__": solve()
0
null
34,477,419,456,170
210
99
N=int(input()) A=[] B=[] for _ in range(N): x,y=map(int, input().split()) A.append(x+y) B.append(x-y) A=sorted(A) B=sorted(B) print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))
a,b =map(str, input().split()) print(str(b+a))
0
null
53,388,435,395,998
80
248
ri = lambda S: [int(v) for v in S.split()] N, M = ri(input()) c = 0 c += (M * (M-1)) / 2 c += (N * (N-1)) / 2 print(int(c))
''' def main(): S = input() cnt = 0 ans = 0 f = 1 for i in range(3): if S[i] == 'R': cnt += 1 else: cnt = 0 ans = max(ans, cnt) print(ans) ''' def main(): S = input() p = S[0] == 'R' q = S[1] == 'R' r = S[2] == 'R' if p and q and r : print(3) elif (p and q) or (q and r): print(2) elif p or q or r: print(1) else: print(0) if __name__ == "__main__": main()
0
null
25,212,667,834,420
189
90
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys INF = 10**10 def main(N, K, P, C): ans = max(C) for i in range(N): used = [False] * N now = 0 mx = -INF cnt = 0 while True: if used[i] or cnt >= K: break used[i] = True i = P[i] - 1 now += C[i] mx = max(mx, now) cnt += 1 tmp = max(mx, now) if now > 0: cycle, mod = divmod(K, cnt) if cycle > 1: tmp = max(tmp, now * (cycle - 1) + mx) t = now * cycle tmp = max(tmp, t) for j in range(mod): i = P[i] - 1 t += C[i] tmp = max(tmp, t) ans = max(ans, tmp) print(ans) if __name__ == '__main__': input = sys.stdin.readline N, K = map(int, input().split()) *P, = map(int, input().split()) *C, = map(int, input().split()) main(N, K, P, C)
n, s = map(int, input().split()) a = list(map(int, input().split())) dp = [[0]*(s+1) for _ in range(n+1)] dp[0][0] = 1 mod = 998244353 for i in range(n): for j in range(s+1): dp[i+1][j] = dp[i][j]*2 if a[i]<=j: dp[i+1][j] += dp[i][j-a[i]] dp[i+1][j] %= mod print(dp[n][s])
0
null
11,522,104,988,240
93
138
def modpow(a,n,m): res=1 while n>0: if n&1:res=res*a%m a=a*a%m n//=2 return res class mod_comb_k(): def __init__(self, MAX_N = 10**6, mod = 10**9+7): self.fact = [1] self.fact_inv = [0] * (MAX_N + 4) self.mod = mod #if MAX_N > mod:print('MAX_N > mod !') for i in range(MAX_N + 3): self.fact.append(self.fact[-1] * (i + 1) % self.mod) self.fact_inv[-1] = pow(self.fact[-1], self.mod - 2, self.mod) for i in range(MAX_N + 2, -1, -1): self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod def comb(self, n, k): if n < k: #print('n < k !') return 0 else:return self.fact[n] * self.fact_inv[k] % self.mod * self.fact_inv[n - k] % self.mod mod=998244353 c=mod_comb_k(mod=mod) n,m,k=map(int,input().split()) ans=0 for i in range(k+1): ans+=modpow(m-1,n-i-1,mod)*c.comb(n-1,i)*m%mod ans%=mod print(ans)
n, m, k = list(map(int, input().split())) mod = 998244353 m_ = m - 1 n_ = n - 1 m_p = {0: 1} ans = 0 fac = {0: 1, 1: 1} finv = {0: 1, 1: 1} inv = {1: 1} def comb_init(): for i in range(2, n + 1): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod def comb(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % mod) % mod def pow_init(m): for i in range(1, m): m_p[i] = m_p[i - 1] * m_ m_p[i] %= mod comb_init() pow_init(n_ - k) for i in range(k, -1, -1): if n_ - i not in m_p: m_p[n_ - i] = m_p[n_ - i - 1] * m_ % mod d = m * comb(n_, i) % mod d *= m_p[n_ - i] ans += d % mod ans %= mod print(ans)
1
23,097,089,465,010
null
151
151
N = int(input()) S = int(N**(1/2)) for i in range(S,0,-1): if N%i == 0: A = N//i B = i break print(A+B-2)
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True n = int(input()) if is_prime(n): print(n -1) exit() ans = n for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: temp_1 = n/k temp_2 = k ans = min(ans,temp_1 + temp_2) print(int(ans-2))
1
161,736,974,088,056
null
288
288
d = int(input()) *C, = map(int, input().split()) S = [list(map(int, input().split())) for i in range(d)] X = [int(input()) - 1 for i in range(d)] L = [-1 for j in range(26)] score = 0 for i in range(d): L[X[i]] = i score += S[i][X[i]] score -= sum([C[j] * (i - L[j]) for j in range(26)]) print(score)
D=int(input()) c=[] c=list(map(int,input().split())) s=[] for i in range(D): s.append(list(map(int,input().split()))) t=[0 for i in range(D)] for i in range(D): t[i]=int(input()) wa=0 last=[0 for i in range(26)] for i in range(D): wa=s[i][t[i]-1]+wa last[t[i]-1]=i+1 for j in range(26): wa=wa-c[j]*((i+1)-last[j]) print(wa)
1
10,032,914,902,850
null
114
114
n,m = map(int,input().split()) par = [i for i in range(n+1)] root = [i for i in range(n+1)] par[0] = 1 def find(x): if par[x] == x: return x else: par[x] = find(par[x]) #経路圧縮 return par[x] def same(x,y): return find(x) == find(y) def unite(x,y): x = find(x) y = find(y) if x == y: return 0 par[x] = y for i in range(m): a,b = map(int,input().split()) unite(a,b) for i in range(n+1): root[i] = find(i) print(len(set(root))-1)
N=int(input()) DMY=10**9 mmax=None mmin=None dmax=None dmin=None for i in range(N): x,y = map(int, input().split()) if not mmax: mmax=(x,y,x+y) mmin=(x,y,x+y) dmax=(x,y,x+DMY-y) dmin=(x,y,x+DMY-y) continue if x+y > mmax[2]: mmax=(x,y,x+y) elif x+y < mmin[2]: mmin=(x,y,x+y) if x+DMY-y > dmax[2]: dmax=(x,y,x+DMY-y) elif x+DMY-y < dmin[2]: dmin=(x,y,x+DMY-y) print(max(mmax[2]-mmin[2],dmax[2]-dmin[2]))
0
null
2,847,916,676,572
70
80
N, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) mod = 10**9 + 7 fac = [0] * (N+1) facinv = [0] * (N+1) fac[0] = 1 facinv[0] = 1 for i in range(N): fac[i+1] = (fac[i] * (i + 1)) % mod facinv[i+1] = (facinv[i] * pow(i+1, -1, mod)) % mod def nCk(n, k): return (fac[n] * facinv[k] * facinv[n-k]) % mod p = 0 m = 0 for i in range(K-1, N): p = (p + A[i] * nCk(i, K-1)) % mod m = (m + A[N-i-1] * nCk(i, K-1)) % mod #print(A[i-K+1] , nCk(N-i+1, K-1)) print((p - m) % mod)
n = int(input()) hon = [2, 4, 5, 7, 9] bon = [3] pon = [1, 6, 0] if int(str(n)[-1]) in hon: print("hon") elif int(str(n)[-1]) in bon: print("bon") else: print("pon")
0
null
57,557,626,477,802
242
142
n, k = map(int, input().split()) a = list(map(int, input().split())) mod = pow(10, 9) + 7 neg = 0 zero = 0 for i in range(n): if a[i] >= 0: if a[i] == 0: zero += 1 a[i] = [a[i], 1] else: a[i] = [-a[i], 0] neg += 1 a.sort(reverse = True) ans = 1 if n == k: for i in range(n): ans *= a[i][0] ans %= mod if not a[i][1]: ans *= -1 ans %= mod elif k % 2 == 1 and (neg == n or neg + zero == n): for i in range(1, k + 1): ans *= -a[-i][0] ans %= mod else: pos, neg = 0, 0 lastpos, lastneg = mod, mod for i in range(k): ans *= a[i][0] ans %= mod if a[i][1]: pos += 1 lastpos = a[i][0] else: neg += 1 lastneg = a[i][0] if neg % 2 == 1: firstpos, firstneg = mod, mod for i in range(k, n): if not firstpos == mod and not firstneg == mod: break if firstpos == mod and a[i][1]: firstpos = a[i][0] elif firstneg == mod and not a[i][1]: firstneg = a[i][0] if not mod in [lastpos, lastneg, firstpos, firstneg]: if firstpos * lastpos >= firstneg * lastneg: ans = ans * pow(lastneg, mod - 2, mod) * firstpos % mod else: ans = ans * pow(lastpos, mod - 2, mod) * firstneg % mod elif not mod in [lastpos, firstneg]: ans = ans * pow(lastpos, mod - 2, mod) * firstneg % mod elif not mod in [lastneg, firstpos]: ans = ans * pow(lastneg, mod - 2, mod) * firstpos % mod print(ans)
S = input() ans = [0] * (len(S) + 1) for i in range(len(S)): if S[i] == '<': ans[i + 1] = ans[i] + 1 for i in range(len(S) - 1, -1, -1): if S[i] == '>': ans[i] = max(ans[i], ans[i + 1] + 1) print(sum(ans))
0
null
83,394,107,346,550
112
285
s,t=map(str,input().split()) print(t,s,sep="")
import math a, b, n = map(int, input().split()) k = min(n, b-1) print(math.floor(a/b*k))
0
null
65,823,086,622,242
248
161
n = int(input()) a = list(map(int, input().split())) for n in a: if n % 2 == 0: if not n % 3 == 0 and not n % 5 == 0: print("DENIED") break else: print("APPROVED")
n = int(input()) a = input() s=list(map(int,a.split())) q = int(input()) a = input() t=list(map(int,a.split())) i = 0 for it in t: if it in s: i = i+1 print(i)
0
null
34,595,966,132,000
217
22
N = int(input()) P = list(map(int, input().split())) c = 10 ** 20 con = 0 for i in range(N): if c > P[i]: con += 1 c = P[i] print(con)
def depth_search(i, adj, d, f, t): if d[i - 1]: return t d[i - 1] = t t += 1 for v in adj[i - 1]: t = depth_search(v, adj, d, f, t) f[i - 1] = t t += 1 return t n = int(input()) adj = [list(map(int, input().split()))[2:] for _ in range(n)] d = [0] * n f = [0] * n t = 1 for i in range(n): if d[i] == 0: t = depth_search(i + 1, adj, d, f, t) for i, df in enumerate(zip(d, f)): print(i + 1, *df)
0
null
42,909,636,378,208
233
8
def main(): _ = int(input()) *A, = map(int, input().split()) A += [0] money = 1000 stock = 0 for a, b in zip(A, A[1:]): money += stock * a stock = 0 if a < b: buy, rest = divmod(money, a) stock = buy money = rest print(money) if __name__ == '__main__': main()
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys while True: s = sys.stdin.readline().strip() if s == '0': break total = 0 for c in s: total += int(c) print(total)
0
null
4,483,570,057,988
103
62
i = input() print"", for n in range(1,i+1): if n%3==0 or "3" in str(n): print n,
from math import gcd from sys import setrecursionlimit setrecursionlimit(4100000) mod = 10 ** 9 + 7 n = int(input()) zeros = 0 d = {} for i in range(n): x, y = map(int, input().split()) if x == 0 and y == 0: zeros += 1 else: g = gcd(x, y) x, y = x // g, y // g if (y < 0) or (y == 0 and x < 0): x, y = -x, -y else: pass if x <= 0: sq = True #second quadrant x, y = y, -x else: sq = False if sq == True: if (x, y) in d: d[(x, y)][1] += 1 else: d[(x, y)] = [0, 1] else: if (x, y) in d: d[(x, y)][0] += 1 else: d[(x, y)] =[1, 0] #繰り返し2乗法 def mod_pow(a:int, b:int, mod:int)->int: if b == 0: return 1 % mod elif b % 2 == 0: return (mod_pow(a, b//2, mod) ** 2) % mod elif b == 1: return a % mod else: return ((mod_pow(a, b//2, mod) ** 2) * a) % mod #print(d) ans = 1 for (a, b), (k, l) in d.items(): now = 1 now = (now + mod_pow(2, k, mod) - 1) % mod now = (now + mod_pow(2, l, mod) - 1) % mod ans = (ans * now) % mod ans -= 1 zeros = zeros % mod ans = (ans + zeros) % mod print(ans)
0
null
11,012,276,840,152
52
146
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] n = I() a = LI() mx = max(a) table = [0] * (mx + 1) # num of factors for x in a: table[x] += 1 g = 0 # check for x in a: g = gcd(g, x) for i in range(2, mx + 1): c = 0 # 因数iの倍数がaにいくつ含まれるか(c) for j in range(i, mx + 1, i): c += table[j] # cが2以上=iの倍数となるaが複数存在する if c > 1: if g == 1: print("setwise coprime") else: print("not coprime") exit(0) print("pairwise coprime")
from functools import reduce N = int(input()) A = [int(n) for n in input().split()] X = reduce(int.__xor__, A) ans = [X^a for a in A] print(*ans)
0
null
8,300,269,198,610
85
123
S = str(input()) if S[len(S)-1] == "s": S += "es" else: S += "s" print(S)
word = input() if word[-1] == 's': word += "e" print(word + "s")
1
2,376,676,429,568
null
71
71
#!/usr/bin/env python3 def main(): N = int(input()) print('YES' if len(set(input().split())) == N else 'NO') if __name__ == '__main__': main()
s = input() if s.islower(): print("a") else: print("A")
0
null
42,707,119,829,340
222
119
s = input() t = input() n = len(s) ans = n for i in range(n): if s[i] == t[i]: ans -= 1 print(ans)
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,591,553,453,342
null
116
116
s="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" s=s.split(", ") k=int(input()) print(int(s[k-1]))
import sys list1=[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] for line in sys.stdin: print(list1[int(line)-1])
1
50,299,820,082,050
null
195
195
n = int(input()) a = list(map(int,input().split())) a_cumsum = [0]*(n+1) for i in range(n): a_cumsum[i+1] = a_cumsum[i] + a[i] ans = 10**18 for i in range(n): ans = min(ans, abs(a_cumsum[-1] - a_cumsum[i]*2)) print(ans)
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) total = sum(A) total *= 2 mindif = 1e12 sub = 0 for i in range(N): sub += 2 * A[i] dif = abs(total//2-sub) if dif < mindif: mindif = dif print(mindif)
1
141,988,435,383,478
null
276
276
from math import ceil def is_ok(arg): # 条件を満たすかどうか?問題ごとに定義 ret = 0 for i in range(n): ret += ceil(A[i]/arg)-1 return bool(ret<=k) def meguru_bisect(ng, ok): ''' 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義すべし ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す ''' while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok n,k = map(int,input().split()) A = list(map(int,input().split())) print(meguru_bisect(0,max(A)+1))
print(' ' + ' '.join(str(i) for i in range(1, int(input()) + 1) if not i % 3 or '3' in str(i)))
0
null
3,733,388,944,242
99
52
def matprod(A,B): C = [] for i in range(len(A)): tmpList = [] for k in range(len(B[0])): tmpVal = 0 for j in range(len(A[0])): tmpVal += A[i][j] * B[j][k] tmpList.append(tmpVal) C.append(tmpList) return C n,m,l = map(int, input().split()) A = [] for i in range(n): A.append(list(map(int, input().split()))) B = [] for i in range(m): B.append(list(map(int, input().split()))) for cr in matprod(A,B): print(' '.join(map(str, cr)))
if __name__ == '__main__': N = int(input()) l = input().split() num = [int(i) for i in l] print(min(num), max(num), sum(num))
0
null
1,070,095,034,320
60
48
N,M=map(int,input().split()) A=[int(x) for x in input().split()] print(max(-1,(N-sum(A))))
n, m = map(int,input().split()) lst = list(map(int,input().split())) x = 0 for i in range(m): x = x + lst[i] if (x > n): print("-1") else: print(n - x)
1
31,825,461,167,690
null
168
168
def main(): n = int(input()) P = [int(x) for x in input().split()] minv = 2 * 10 ** 5 + 1 cnt = 0 for i in range(n): if minv > P[i]: minv = P[i] cnt += 1 print(cnt) if __name__ == '__main__': main()
N = int(input()) P = list(map(int, input().split())) mn = N + 1 ans = 0 for p in P: if p < mn: ans += 1 mn = min(mn, p) print(ans)
1
85,229,318,828,682
null
233
233
N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) import itertools nums = list(itertools.permutations(range(1,N+1))) print(abs(nums.index(P)-nums.index(Q)))
n = int(input()) p = list(map(int,input().split())) q = list(map(int,input().split())) def factorial(n) : if n == 1: return 1 else : return n*factorial(n-1) num_p = 0 num_q = 0 for i in range(n-1) : sort_p = sorted(p[i:],reverse=True) index_p = sort_p.index(p[i]) mp = n - (index_p + 1) num_p += mp * factorial(n-(i+1)) sort_q = sorted(q[i:],reverse = True) index_q = sort_q.index(q[i]) mq = n - (index_q + 1) num_q += mq * factorial(n-(i+1)) print(abs(num_p - num_q))
1
100,152,271,424,302
null
246
246
import fractions as math input_line = list(map(int,input().split(' '))) ans = input_line[0] * input_line[1] // math.gcd(input_line[0], input_line[1]) print(ans)
def main(): N = int(input()) A = list(map(int, input().split())) if 1 not in A: print(-1) exit() next = 1 for a in A: if a == next: next += 1 print(N - next + 1) if __name__ == '__main__': main()
0
null
113,535,522,375,160
256
257
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,k = readInts() a = readInts() a.sort(reverse=True) if n==1: print(math.ceil(a[0]/(k+1))) exit() def get(left, right): l = (right-left)//2+left ans = 0 for i in a: ans+=math.ceil(i/l)-1 #print(l, ans, left, right) return ans,l def nibu(left,right): ans,l = get(left, right) if left<right: if ans<=k: return nibu(left,l) else: return nibu(l+1, right) else: return right print(nibu(1,a[0]))
n,k = map(int,input().split()) L = list(map(int,input().split())) ok = 0 ng = 10**9 while abs(ok-ng) > 1: mid = (ok+ng)//2 cur = 0 for i in range(n): cur += L[i]//mid if cur > k: ok = mid elif cur <= k: ng = mid K = [mid-1, mid, mid+1] P = [] for i in range(3): res = 0 if K[i] > 0: for j in range(n): res += (L[j]-1)//K[i] if res <= k: P.append(K[i]) print(min(P))
1
6,534,391,486,838
null
99
99
import math A,B=map(int, input().split()) for i in range(1,1001): if math.floor(i*0.08)==A and math.floor(i*0.1)==B: print(i) break if i==1000: print(-1)
import sys x = int(input()) for a in range(-(10 ** 3), 10 ** 3): for b in range(-(10 ** 3), 10 ** 3): if a ** 5 - b ** 5 == x: print(a, b) sys.exit()
0
null
41,215,981,146,780
203
156
N,M,K=map(int,input().split()) MOD=998244353 def inv(a): return pow(a,MOD-2,MOD) fact=[0,1] for i in range(2,N+1): fact.append((fact[-1]*i)%MOD) def choose(n,r): if r==0 or r==n: return 1 else: return fact[n]*inv(fact[r])*inv(fact[n-r])%MOD exp=[1] def pow_k(x,n): if n==0: return 1 K=1 while n>1: if n%2!=0: K=K*x%MOD x=x**2%MOD n=(n-1)//2 else: x=x**2%MOD n=n//2 return K*x%MOD ans=0 for i in range(K+1): ans+=(M*choose(N-1,i)*pow_k(M-1,N-1-i)%MOD) ans%=MOD print(ans)
import math K = int(input()) S = 0 for a in range(1, K+1): for b in range(1, K+1): T = math.gcd(a, b) for c in range(1, K+1): S += math.gcd(T, c) print(S)
0
null
29,298,801,655,100
151
174
n = int(input()) lr = [] # 各アームの左端と右端の位置のペア for _ in range(n): x, l = list(map(int, input().split())) lr.append((x-l, x+l)) # 右端位置でソート lr.sort(key=lambda x:x[1]) ans = 0 right = -10**9 for l,r in lr: # 重なってないなら残す if l >= right: ans += 1 right = r print(ans)
import heapq n=int(input()) rb = [] heapq.heapify(rb) for i in range(n): x,l= map(int,input().split()) heapq.heappush(rb,(x+l,x-l)) ans=0 mostr=-1 while len(rb)>0: c=heapq.heappop(rb) if ans==0: ans+=1 mostr=c[0] else: if mostr<=c[1]: ans+=1 mostr=c[0] print(ans)
1
90,020,009,915,852
null
237
237
data = int(input()) ans = abs(data-1) print(ans)
print(0 if input() == '1' else 1)
1
2,929,216,697,248
null
76
76
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): N = int(input()) A = list(map(int, input().split())) ans = 0 d = defaultdict(int) for a in A: d[a] += 1 ans += a Q = int(input()) for i in range(Q): B, C = map(int, input().split()) if d[B] != 0: ans -= B * d[B] ans += C * d[B] d[C] += d[B] d[B] = 0 print(ans) def main(): solve() if __name__ == '__main__': main()
def main(): n = int(input()) a = list(map(int,input().split())) dic = {} for i in range(n): if not a[i] in dic.keys(): dic[a[i]] = 1 else: dic[a[i]] += 1 s = 0 for k in dic.keys(): s += dic[k] * k q = int(input()) for i in range(q): b,c = map(int,input().split()) if b in dic.keys(): cnt = dic[b] else: cnt = 0 dic[b] = 0 if c in dic.keys(): dic[c] += cnt else: dic[c] = cnt s = s + cnt * (c-b) print(s) if __name__ == "__main__": main()
1
12,160,781,212,320
null
122
122
s=input() t=input() count=0 for i in range(0,len(s)): if(s[i]==t[i]): continue else: count+=1 print(count)
A = str(input()) B = str(input()) sum=0 for i in range(len(A)): if A[i]!=B[i]: sum+=1 print(sum)
1
10,425,629,638,340
null
116
116
a=int(input()) b=int(input()) c=[1,2,3] c.remove(a) c.remove(b) if c==[1]: print(1) elif c==[2]: print(2) else: print(3)
n,m=map(int,input().split()) data=[0]*n s=set() sum_wa=0 for i in range(m): p,a=input().split() p=int(p)-1 if p in s: continue else: if a=='WA': data[p]+=1 else: sum_wa+=data[p] s.add(p) print(len(s),sum_wa)
0
null
102,175,871,538,728
254
240
n = int(input()) l = [] for i in range(1,n+1) : if i%3 != 0 and i%5 != 0 : l.append(i) print(sum(l))
N = int(input()) ans = [0] * (N+1) for i in range(N+1): if i % 3 != 0 and i % 5 != 0 and i % 15 != 0: ans[i] = ans[i-1] + i else: ans[i] = ans[i-1] print(ans[-1])
1
34,796,305,027,648
null
173
173
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 from fractions import gcd 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)]) import networkx as nx n,x,y = inpm() x -= 1 y -= 1 if x > y: x,y = y,x d = np.zeros((n,n),int) ans = np.zeros(n,int) for i in range(n): for j in range(i+1,n): a = j - i b = abs(x - i) + abs(j - y) + 1 ans[min(a,b)] += 1 for i in range(1,n): print(ans[i])
def mlt(): return map(int, input().split()) x, a, b = mlt() dp = [0 for n in range(x)] for n in range(1, x+1): for k in range(n+1, x+1): d1 = k-n d2 = abs(a-n)+1+abs(b-k) ds = min(d1, d2) dp[ds] += 1 print(*dp[1:], sep='\n')
1
44,189,419,600,482
null
187
187
s=input() if s=="RSR": print("1") else: ans=s.count("R") print(ans)
def main(): s = input() cnt = 0 cnt2 = 0 for i in s: if i == "R": cnt2 += 1 else: cnt = max(cnt, cnt2) cnt2 = 0 print(max(cnt, cnt2)) main()
1
4,927,386,875,844
null
90
90
i = raw_input() N, A, B = i.split() N = int(N) A = int(A) B = int(B) if abs(A-B)%2 == 0: print int(abs(A-B)/2) else: e = int(min(A-1, N-B)) d = (B-A+1) // 2 print e + d
# author: Taichicchi # created: 19.09.2020 00:14:21 import sys N = int(input()) S = input() ans = S.count("R") * S.count("G") * S.count("B") for i in range(N - 2): for j in range(i + 1, N - 1): try: k = 2 * j - i if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]): ans -= 1 except: continue print(ans)
0
null
72,845,369,479,200
253
175
import math a,b, C = map(int, input().split()) C = math.radians(C) S = (a * b * math.sin(C))/2 l = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C)) h = b * math.sin(C) print(S) print(l) print(h)
import sys from collections import deque, defaultdict, Counter from itertools import accumulate, product, permutations, combinations from operator import itemgetter from bisect import bisect_left, bisect_right from heapq import heappop, heappush from math import ceil, floor, sqrt, gcd, inf from copy import deepcopy import numpy as np import scipy as sp INF = inf MOD = 1000000007 k = int(input()) s = input() tmp = 0 res = 0 if len(s) <= k: res = s else: res = s[:k] + "..." print(res)
0
null
9,950,416,666,300
30
143
#!/usr/bin/python ar = [] while True: tmp = [int(i) for i in input().split()] if tmp == [0,0]: break else: ar.append(tmp) for i in range(len(ar)): for j in range(ar[i][0]): for k in range(ar[i][1]): if j == 0 or j == ar[i][0] - 1 or k == 0 or k == ar[i][1] - 1: print('#' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n') else: print('.' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
def draw(h,w): s = "#" * w k = "#" + "." * (w-2) + "#" print s for i in range(0,h-2): print k print s print if __name__ == "__main__": while True: h,w = map(int, raw_input().split()) if h==0 and w==0: break else: draw(h,w)
1
816,718,092,540
null
50
50
# 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] + '...'))
nb = int(input()) sentence = input() if len(sentence) > nb: print(sentence[0:nb] + '...') else: print(sentence)
1
19,819,970,975,812
null
143
143
N = int(input()) Alist = list(map(int,input().split())) XorPro = 0 for i in Alist: XorPro = XorPro^i Answer = [] for i in Alist: Answer.append(XorPro^i) print(*Answer)
import time start = time.time() n = int(input()) a = list(map(int,input().split())) b = [] m = 0 for i in range(1,n): m = m ^ a[i] b.append(m) for j in range(1,n): m = m ^ a[j-1] m = m ^ a[j] b.append(m) b = map(str,b) print(' '.join(b))
1
12,409,313,920,718
null
123
123
n = int(input()) d = [[0]*9 for _ in range(9)] ans = 0 for num in range(1, n+1): s = str(num) x, y = int(s[0]), int(s[-1]) if x != 0 and y != 0: d[x-1][y-1] += 1 for i in range(9): k = -1 for j in range(9): if i == j: ans += pow(d[i][j], 2) k = 1 elif k == 1: ans += 2*d[i][j]*d[j][i] print(ans)
import collections n = int(raw_input()) def g( a, b , n): count = 0 ## CASE 1 if a == b and a <=n : count +=1 ## CASE 2 if a *10 + b <= n: count +=1 if len(str(n)) <=2: return count ## CASE 3 s = str(n) if len(s) - 3 >= 1: count += 10 ** (len(s) - 3) ## CASE 4 s = str(n) if a == int(s[0]): m = s[1:-1] if m != '': #0,m-1 count += int(m) if b <= int(s[-1]): count +=1 elif a < int(s[0]): count += 10 ** (len(s) - 2) return count h = collections.Counter() for k in range(1, n+1): ks = str(k) a,b = int(ks[0]), int(ks[-1]) h[(a,b)] +=1 s= 0 for a in range(1,10): for b in range(1,10): s += h[(a,b)] * h[(b,a)] print s
1
86,572,404,110,722
null
234
234
N,M,X=map(int,input().split()) C=[list(map(int,input().split())) for _ in range(N)] ans=inf=float('inf') def dfs(idx,tt,l): global ans for i in range(idx,N): ntt=tt+C[i][0] nl=[l[j]+C[i][j+1] for j in range(M)] ok=True for x in nl: if x<X: ok=False break if ok: ans=min(ans,ntt) else: dfs(i+1,ntt,nl) dfs(0,0,[0]*M) print(ans if ans<inf else -1)
import sys n=int(input()) s=[list(input()) for i in range(n)] L1=[] L2=[] for i in range(n): ct3=0 l=[0] for j in s[i]: if j=='(': ct3+=1 l.append(ct3) else: ct3-=1 l.append(ct3) if l[-1]>=0: L1.append((min(l),l[-1])) else: L2.append((min(l)-l[-1],-l[-1])) L1.sort() L1.reverse() ct4=0 for i in L1: if ct4+i[0]<0: print('No') sys.exit() ct4+=i[1] L2.sort() L2.reverse() ct5=0 for i in L2: if ct5+i[0]<0: print('No') sys.exit() ct5+=i[1] if ct4!=ct5: print('No') sys.exit() print('Yes')
0
null
23,013,365,346,322
149
152
s = input() n = len(s) n1 = (n-1)//2 n2 = (n+1)//2 if s == s[::-1]: if s[:n1] == s[n2:]: print("Yes") else: print("No") else: print("No")
s = input() n = len(s) flag = 1 for i in range(int(n/2)): if s[i] != s[n-i-1]: flag = 0 break n2 = int((n-1)/2) if flag == 1: for i in range(int(n2/2)): if s[i] != s[n2-i-1]: flag = 0 break if flag == 1: print("Yes") else: print("No")
1
46,451,944,673,706
null
190
190
n=int(input()) S=[] for i in range(n): S.append(input()) print('AC', 'x', S.count('AC')) print('WA', 'x', S.count('WA')) print('TLE', 'x', S.count('TLE')) print('RE', 'x', S.count('RE'))
# -*- coding: utf-8 -*- N = int(input()) ans ='No' for x in range(1, 10, 1): if (N % x) == 0: for y in range(x, 10, 1): if x * y == N: ans = 'Yes' break if ans == 'Yes': break print(ans)
0
null
84,156,737,015,680
109
287
N = int(input()) ans = [0] * N for i in range(1, 101): for j in range(1, 101): for k in range(1, 101): tmp = i**2+j**2+k**2+i*j+j*k+k*i if tmp <= N: ans[tmp-1] += 1 print(*ans, sep='\n')
from collections import deque def main(): k = int(input()) l = list(range(1, 10)) Q = deque(l) for _ in range(k): q = Q.popleft() # 基準-1 if q % 10 != 0: Q.append(10*q+q%10-1) # 基準 Q.append(10*q+q%10) # 基準 + 1 if q % 10 != 9: Q.append(10*q+q%10+1) print(q) if __name__ == '__main__': main()
0
null
23,986,288,837,832
106
181
def resolve(): X, Y, A, B, C = list(map(int, input().split())) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split())), reverse=True) eatreds = P[:X] eatgreens = Q[:Y] import heapq heapq.heapify(eatreds) heapq.heapify(eatgreens) for r in R: smallred = heapq.heappop(eatreds) smallgreen = heapq.heappop(eatgreens) reddiff = r-smallred greendiff = r-smallgreen if reddiff < 0 and greendiff < 0: heapq.heappush(eatreds, smallred) heapq.heappush(eatgreens, smallgreen) break if reddiff > greendiff: heapq.heappush(eatreds, r) heapq.heappush(eatgreens, smallgreen) else: heapq.heappush(eatreds, smallred) heapq.heappush(eatgreens, r) print(sum(eatreds)+sum(eatgreens)) if __name__ == "__main__": resolve()
n, a, b = map(int, input().split()) if (a%2 and b%2) or (a%2==0 and b%2==0): print((b-a)//2) else: print(min(a-1, n-b)+1+(b-a-1)//2)
0
null
76,868,700,914,622
188
253
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[city - 1] != -1: loop = i - visited_list[city - 1] non_loop = visited_list[city - 1] - 1 break else: visited_list[city - 1] = i city = 1 if k <= non_loop: for _ in range(k): city = a_list[city - 1] else: for _ in range(non_loop + (k - non_loop) % loop + loop): city = a_list[city - 1] print(city) if __name__ == "__main__": main()
from collections import defaultdict n = int(input()) d = defaultdict(int) i = 2 while i * i <= n: while n % i == 0: d[i] += 1 n /= i i += 1 if n != 1: d[n] += 1 ans = 0 for v in d.values(): # x * (x + 1) // 2 <= vとなる最大のx x = 0 while (x + 1) * (x + 2) // 2 <= v: x += 1 ans += x print(ans)
0
null
19,789,591,991,740
150
136
# 163 B N,M = list(map(int, input().split())) A = list(map(int, input().split())) print(N-sum(A)) if sum(A) <= N else print(-1)
days_summer_vacation, amount_homework = map(int, input().split()) a = map(int, input().split()) schedule_hw = list(a) need_days_hw = 0 for i in schedule_hw: need_days_hw += i if days_summer_vacation > need_days_hw: print(days_summer_vacation - need_days_hw) elif days_summer_vacation == need_days_hw: print(0) else: print(-1)
1
32,112,855,412,960
null
168
168
from collections import deque n,m=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 g[a].append(b) g[b].append(a) def bfs(u): queue = deque([u]) d = [None]*n d[u] = 0 while queue: v=queue.popleft() for i in g[v]: if d[i] is None: d[i] = d[v]+1 queue.append(i) return d d = bfs(0) print('Yes') for i in range(1,n): for j in g[i]: if d[j]<d[i]: print(j+1) break
from collections import deque n, m = map(int, input().split()) to = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([1]) dist = [-1] * (n + 1) # print(to) while q: v = q.popleft() for u in to[v]: if dist[u] != -1: continue q.append(u) dist[u] = v print("Yes") # print(dist) for i in range(2, n + 1): print(dist[i])
1
20,522,943,851,058
null
145
145
def solve(): A,B, M = map(int, input().split()) a_kind = list(map(int, input().split())) b_kind = list(map(int, input().split())) Coupon = [list(map(int, input().split())) for _ in range(M)] ans = min(a_kind) + min(b_kind) for x,y,disc in Coupon: ans = min(ans, a_kind[x-1] + b_kind[y-1] - disc) print(ans) if __name__ == '__main__': solve()
import sys #a,b=map(int,input().split()) a,b,c=map(int,input().split()) if a<b: if b<c: print("Yes") sys.exit() print("No")
0
null
27,366,513,951,282
200
39
# C - Subarray Sum def main(): N, K, S = map(int, input().split()) res = [str(S)] * K + ["1" if S == 10 ** 9 else str(S + 1)] * (N - K) print(" ".join(res)) if __name__ == "__main__": main()
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): # floor(x/b)がギリギリ割り切れない辺りが一番大きくなりそう # -> 実験してみるとmath.floor(a*x/b)-a*math.floor(x/b)はループしてそう # -> 答えはfloor(x/b)がギリギリ割り切れないときの値に決め打つぜ! a,b,n=LI() x=min(n,b-1) return math.floor(a*x/b)-a*math.floor(x/b) # main() print(main())
0
null
59,792,399,411,848
238
161
import math a, b, c = map(float,input().split()) c = math.radians(c) S = (1/2) * a * b * math.sin(c) d = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(c))) L = a + b + d H = (2 * S) / a print(S,L,H)
import math a,b,C = map(int, input().split()) r = C*math.pi/180 h = b*math.sin(r) print('{0:f}'.format(a*h/2)) print('{0:f}'.format(a+b+(math.sqrt(a**2+b**2-2*a*b*math.cos(r))))) print('{0:f}'.format(h))
1
170,568,512,540
null
30
30
n=int(input()) x = [int(x) for x in input().split()] heikin=(sum(x)/n) if abs(int(heikin)-heikin)<abs(int(heikin+1)-heikin): kaisai=int(heikin) else: kaisai=int(heikin+1) ans=0 for i in x: ans+=(i-kaisai)**2 print(ans)
n = int(input()) s = input() if n%2 != 0: ans = 'No' else: ans = 'Yes' for i in range(n//2): if s[i] != s[i+n//2]: ans = 'No' print(ans)
0
null
105,896,012,395,044
213
279
n = int(input()) if n>=30: print("Yes") else: print("No")
from collections import Counter N, P = map(int, input().split()) S = input() def check(n): ans = 0 for i in range(1, N+1): v = int(S[-i]) if v%n==0: ans += N-(i-1) return ans ans = 0 if P==2: ans = check(2) elif P==5: ans = check(5) else: ac = [0]*(N+1) for i in range(1, N+1): ac[i] = (ac[i-1]+int(S[-i])*pow(10, i-1, P))%P c = Counter(ac) for i in c.values(): ans += i*(i-1)//2 print(ans)
0
null
31,849,046,353,458
95
205
n, m = map(int, input().split()) a = list(map(int, input().split())) ans = n - sum(a) print(-1 if ans < 0 else ans)
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import itertools import math import sys INF = float('inf') def solve(K: int, S: str): return S[:K] + ['...', ''][len(S) <= K] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() K = int(next(tokens)) # type: int S = next(tokens) # type: str print(solve(K, S)) if __name__ == '__main__': main()
0
null
25,829,255,393,060
168
143
def resolve(): a = int(input()) ans = a * (1 + a * (1 + a)) print(ans) if __name__ == "__main__": resolve()
num = int(input()) answer = num + num * num + num * num * num print(answer)
1
10,185,900,271,410
null
115
115
import math pi=math.pi a,b,si=map(float,input().split()) S=(1/2)*a*b*math.sin(math.radians(si)) c2=a*a+b*b-2*a*b*math.cos(math.radians(si)) L=a+b+math.sqrt(c2) h=(2*S)/a print(S) print(L) print(h)
import math def float_print(v): print('{:.5f}'.format(v)) a, b, C = map(float, input().split()) C = math.radians(C) float_print(a * b * math.sin(C) / 2) float_print(a + b + math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(C))) float_print(b * math.sin(C))
1
175,423,343,140
null
30
30
import sys az = [0 for i in range(26)] s = sys.stdin.read().lower() l = [ord(i) for i in s] for i in range(len(l)): c = l[i] - 97 if(c >= 0 and c <= 26): az[c] += 1 for i in range(26): print('{} : {}'.format(chr(i + 97),az[i]))
import sys def main(): cnt = {} for i in range(97,123): cnt[chr(i)] = 0 # print(cnt) for passages in sys.stdin: for psg in passages: psglower = psg.lower() for s in psglower: if s.isalpha(): cnt[s] += 1 for i in range(97,123): s = chr(i) print(s, ':', cnt[s]) if __name__ == '__main__': main()
1
1,647,164,548,998
null
63
63
N, M = [int(n) for n in input().split()] solved = {} result = {} for i in range(M): p, S = input().split() status = result.setdefault(p, []) if len(status)==0: result[p] = [] solved[p] = False if S == 'AC': solved[p] = True result[p].append(S) ans = 0 wa = 0 for k, v in solved.items(): if v: ans += 1 wa += result[k].index('AC') print(ans , wa)
n,m=map(int,input().split()) ac=[0]*(n+1) wa=0 for i in range(m): p,c=input().split() if c=='WA' and ac[int(p)]!=1: ac[int(p)]-=1 elif c=='AC' and ac[int(p)]!=1: wa+=abs(ac[int(p)]) ac[int(p)]=1 print(ac.count(1),wa)
1
93,429,601,659,030
null
240
240
def main(): N, M = map(int, input().split()) if N == M: print("Yes") exit(0) print("No") if __name__ == "__main__": main()
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] if N == M: print("Yes") else: print("No")
1
83,715,656,577,380
null
231
231
import sys input() rl = sys.stdin.readlines() d = {} for i in rl: c, s = i.split() #if i[0] == 'i': if c[0] == 'i': #d[i[7:]] = 0 d[s] = 0 else: #if i[5:] in d: if s in d: print('yes') else: print('no')
f=lambda:[*map(int,input().split())] k,n=f() l=f() l+=[l[0]+k] a=0 for i in range(n): a=max(a,l[i+1]-l[i]) print(k-a)
0
null
21,827,737,897,408
23
186
N, M = map(int, input().split()) arr = [10] * N for _ in range(M): idx, num = map(int, input().split()) if arr[idx - 1] == 10: arr[idx - 1] = num else: if arr[idx - 1 ] != num: print(-1) exit() if arr[0] == 0: if N == 1: print(0) exit() else: print(-1) exit() elif arr[0] == 10: if N == 1: print(0) exit() else: arr[0] = 1 for i in range(N): if arr[i] == 10: arr[i] = 0 for i in arr: print(i,end="")
N, M = map(int, input().split()) C = [-1] * 3 for i in range(M): s, c = map(int, input().split()) if C[s - 1] == -1: C[s - 1] = c else: if C[s - 1] != c: print(-1) exit() if N == 1 and (M == 0 or (M == 1 and C[0] == 0)): print(0) exit() for i in range(10 ** (N - 1), 10 ** N): si = str(i) flg = True for j in range(N): if C[j] != -1 and si[j] != str(C[j]): flg = False break if flg: print(i) exit() print(-1)
1
60,681,512,834,838
null
208
208
S = input() Q = int(input()) rev = False l, r = "", "" for _ in range(Q): query = input() if query[0] == "1": rev = not rev else: T, F, C = query.split() if F == "1": if rev: r += C else: l = C + l else: if rev: l = C + l else: r += C res = l + S + r if rev: res = res[::-1] print(res)
def main(): S = input() Q = int(input()) order = [list(input().split()) for _ in range(Q)] left_flag = 0 right_flag = 0 cnt = 0 for i in range(Q): if order[i][0] == '1': cnt += 1 else: if cnt%2 == 0: if order[i][1] == '1': if left_flag == 1: left = order[i][2] + left else: left = order[i][2] left_flag = 1 else: if right_flag == 1: right = right + order[i][2] else: right = order[i][2] right_flag = 1 else: if order[i][1] == '2': if left_flag == 1: left = order[i][2] + left else: left = order[i][2] left_flag = 1 else: if right_flag == 1: right = right + order[i][2] else: right = order[i][2] right_flag = 1 if left_flag == 1 and right_flag == 1: S = left + S + right elif left_flag == 1 and right_flag == 0: S = left + S elif left_flag == 0 and right_flag == 1: S = S + right else: S = S if cnt%2 == 0: return(S) else: S2 = S[-1] for i in range(len(S)-2,-1,-1): S2 = S2 + S[i] return S2 print(main())
1
57,420,525,655,822
null
204
204
N = int(input()) total = 0 for num in range(1, N+1): if num % 15 == 0: continue if num % 3 == 0 or num % 5 == 0: continue total += num print(total)
if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) D = [0]*(N) for i, a in enumerate(A): D[a-1] = i+1 print(*D)
0
null
108,133,282,174,240
173
299
def main(): s = input() if s[2]==s[3] and s[4]==s[5]: print("Yes") else: print("No") if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) S = list(input()) lis = [] for s in S: idx = ord(s) if idx+N>90: idx -= 26 lis.append(chr(idx+N)) print(''.join(lis))
0
null
87,989,835,625,218
184
271