code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
from itertools import islice def make_seq(): n, m, l = list(map(int, input().split())) m1 = [list(map(int, input().split())) for _ in range(n)] m2 = [list(map(int, input().split())) for _ in range(m)] def g(): for r1 in m1: for r2 in zip(*m2): yield str(sum(i*j for i, j in zip(r1, r2))) return (n, l, list(g())) n, l, lst = make_seq() for i in range(n): print(" ".join(islice(lst, i*l, (i+1)*l)))
import numpy D = int(input()) c_list = list(map(int, input().split())) s_list = [] for i in range(D): s_list.append(list(map(int, input().split()))) t_list = [] score = 0 past_list = [0] * 26 for i in range(D): t_list.append(int(input()) - 1) for i in range(D): for j in range(26): if(t_list[i] == j): score += s_list[i][j] past_list[j] = i + 1 else: score -= c_list[j] * (i + 1 - past_list[j]) print(score)
0
null
5,660,896,311,382
60
114
a, b = map(int, input().split()) s = str(a) * b t = str(b) * a if s > t: print(t) else: print(s)
def solve(): a,b = [int(i) for i in input().split()] smaller = min(a, b) bigger = max(a, b) print(''.join([str(smaller)]*bigger)) if __name__ == "__main__": solve()
1
84,183,538,392,380
null
232
232
m1, _ = [int(i) for i in input().split()] m2, _ = [int(i) for i in input().split()] if m1 == m2: print(0) else: print(1)
a, b = map(int, input().split()) c = list(map(int, input().split())) if a >= sum(c): print(a - sum(c)) else: print('-1')
0
null
78,209,735,529,990
264
168
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a // gcd(a, b) * b n = int(input()) a = list(map(int, input().split())) l = 1 for i in a: l = lcm(l, i) ans = 0 for i in a: ans += l // i print(ans % 1000000007)
word = input() if word.endswith('s'): print(word+"es") else: print(word+"s")
0
null
44,935,694,501,600
235
71
#!/usr/bin/env python3 from collections import Counter def main(): S = input() N = len(S) T = [0] * (N+1) for i in range(N-1,-1,-1): T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019 l = Counter(T) ans = 0 for v in l.values(): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
s = list(map(int,input())) s.reverse() t = len(s) mod = 2019 arr = [0] * (t+1) arr[-2] = s[0] for i in range(1,t): arr[t-i-1] = (arr[t-i] + s[i]*pow(10,i,mod)) % mod from collections import Counter arr = Counter(arr) ans = 0 for i in arr: ans += (arr[i] - 1) * arr[i] // 2 print(ans)
1
30,759,577,180,194
null
166
166
n = int(input()) s, t = input().split() ret = '' for i, j in zip(s, t): ret += i ret += j print(ret)
N = int(input()) A = {int(x): key for key, x in enumerate(input().split(), 1)} sort_a = sorted(A.items(), key=lambda x: x[0]) print(' '.join([str(key) for x, key in sort_a]))
0
null
145,871,945,351,920
255
299
N = int(input()) L = [] for i in range(N): L.append(list(input().split())) S = input() ans = 0 f = 0 for i in range(N): if f == 1: ans += int(L[i][1]) if L[i][0] == S: f = 1 print(ans)
N=int(input()) st=[] for i in range(N): s,t=input().split() st.append((s,int(t))) X=input() time=0 s=False for i in range(N): if s: time+=st[i][1] if st[i][0]==X: s=True print(time)
1
96,795,861,842,640
null
243
243
a = input() b = input() if '1' not in [a, b]: print('1') if '2' not in [a, b]: print('2') if '3' not in [a, b]: print('3')
f = list(map(str, [1, 2, 3])) f.remove(input()) f.remove(input()) print(f[0])
1
110,892,152,484,968
null
254
254
import math H,W=map(int,input().split()) if W==1: print(1) elif H==1: print(1) else: A=math.ceil(H*W/2) print(A)
def resolve(): h, w = map(int, input().split()) import math if w == 1 or h == 1: print(1) else: print(math.ceil(h * w / 2)) if __name__ == '__main__': resolve()
1
50,837,858,557,990
null
196
196
import string import sys def main(): str1 = sys.stdin.read() dict1 = {} for char in str1.lower(): if not char.isalpha(): continue elif dict1.__contains__(char): dict1[char] += 1 else: dict1[char] = 1 for char in string.ascii_lowercase: print(char + ' : ' + (str(dict1[char]) if dict1.__contains__(char) else '0')) if __name__ == '__main__': main()
import sys from collections import Counter S = "" for s in sys.stdin: s = s.strip().lower() if not s: break S += s for i in 'abcdefghijklmnopqrstuvwxyz': print(i, ":", S.count(i))
1
1,661,588,573,670
null
63
63
N = int(input()) A = list(map(int, input().split())) # ex. 24 11 8 3 16 A.sort() # ex. 3 8 11 16 24 cnt = 0 # Aの最大値が24なら25個用意する感じ # indexと考える値を一致させて分かりやすくしている # Trueで初期化 # 最後のインデックスはA[-1] dp = [True] * (A[-1] + 1) # エラトステネスの篩っぽいやつ for i in range(N): if dp[A[i]] == True: # dp[A[i]], dp[2*A[i]], dp[3*A[i]],...をFalseにする for j in range(A[i], A[-1] + 1, A[i]): dp[j] = False if i < N - 1: # 次も同じ数字が存在するなら数えない、なぜならお互いに割れてしまって題意を満たさないから # 次以降に出てくる同じ数字は既にFalseになっているのでもう走査する事はない if A[i] != A[i + 1]: cnt += 1 # i=N-1の時は次がないので無条件でcntを増やす # elseの方が良さそうだが明示的にするためにelifを使った elif i == N - 1: cnt += 1 print(cnt)
input() print('APPROVED' if all(map(lambda x: x % 3 == 0 or x % 5 == 0, filter(lambda x: x % 2 == 0, map(int, input().split())))) else 'DENIED')
0
null
41,907,831,797,890
129
217
#-*-coding:utf-8-*- import sys input=sys.stdin.readline import itertools def main(): n = int(input()) P=tuple(map(int,input().split())) Q=tuple(map(int,input().split())) permutations = list(itertools.permutations(range(1,n+1))) a = permutations.index(P) b = permutations.index(Q) print(abs(a-b)) if __name__=="__main__": main()
N,M=map(int,input().split()) A_M=list(map(int,input().split())) if N >= sum(A_M): print(N-sum(A_M)) else: print(-1)
0
null
66,063,018,900,392
246
168
def solve(): N, X, M = map(int,input().split()) past_a = {X} A = [X] ans = prev = X for i in range(1, min(M,N)): next_a = prev ** 2 % M if next_a in past_a: loop_start = A.index(next_a) loop_end = i loop_size = loop_end - loop_start loop_elem = A[loop_start:loop_end] rest_n = N-i ans += rest_n // loop_size * sum(loop_elem) ans += sum(loop_elem[:rest_n%loop_size]) break ans += next_a past_a.add(next_a) A.append(next_a) prev = next_a print(ans) if __name__ == '__main__': solve()
string = str(input()) print(string.swapcase())
0
null
2,187,847,673,378
75
61
s = input() rs = s[::-1] ans = 0 for i in range(len(s)//2): ans += (s[i] != rs[i]) print(ans)
#!/usr/bin/env python3 N = int(input().split()[0]) a_list = list(map(int, input().split())) before_a = 0 total = 0 for i, a in enumerate(a_list): if i == 0: before_a = a continue total += max(before_a - a, 0) before_a = a + max(before_a - a, 0) ans = total print(ans)
0
null
62,487,538,253,338
261
88
n=int(input()) data=list(map(int,input().split())) data=sorted(data) flag=0 for i in range(len(data)-1): if data[i]==data[i+1]: flag=1 break if flag==1: print("NO") else: print("YES")
# -*- coding: utf-8 -*- import io import sys import math def solve(a,b): # implement process s = str(min(a,b)) n = max(a,b) return s * n def main(): # input a,b = map(int, input().split()) # process ans = str( solve(a,b) ) # output print(ans) return ans ### DEBUG I/O ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 7 7 """ _EXPECTED = """\ 7777777 """ def logd(str): """usage: if _DEB: logd(f"{str}") """ if _DEB: print(f"[deb] {str}") ### MAIN ### if __name__ == "__main__": if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") ans = main() if _DEB: print() if _EXPECTED.strip() == ans.strip(): print("!! Success !!") else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
0
null
79,291,667,639,760
222
232
import warnings import sys x = 0 while (x == 0): args = map(int, raw_input().split()) h = args[0] w = args[1] if (h == 0 and w == 0): break for i in range(h): for j in range(w): sys.stdout.write("#") print "" print ""
n = int(input()) for i in range(2, n + 1): if i % 3 == 0 or '3' in str(i): print('', i, end = '') print()
0
null
866,302,974,500
49
52
import math h,w=map(int,input().split()) if h==1 or w==1: print(1) elif (h*w)%2==0: print(int((h*w)/2)) else: print(math.ceil((h*w)/2))
x = list(map(int,input().split())) H = x[0] W = x[1] if H == 1 or W == 1: print(1) else: if W % 2 == 0: print(int(H*W/2)) else: if H % 2 == 0: print(int(H*(W-1)/2 + H/2)) else: print(int(H*(W-1)/2 + (H+1)/2))
1
50,850,762,163,490
null
196
196
import statistics while True: n = input() if n == '0': break print(statistics.pstdev(map(int, input().split())))
N=int(input()) if(N%1000==0): print(0) else: print(-(-N//1000)*1000-N)
0
null
4,322,651,198,410
31
108
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) T1, T2 = mapint() A1, A2 = mapint() B1, B2 = mapint() if not (A1-B1)*(A2-B2)<0: print(0) else: if A1<B1: A1, B1 = B1, A1 A2, B2 = B2, A2 if A1*T1+A2*T2==B1*T1+B2*T2: print('infinity') exit(0) rest = (A1-B1)*T1 come = (B2-A2)*T2 if come<rest: print(0) else: ans = come//(come-rest) last = 1 if come%(come-rest)==0 else 0 print(ans*2-1-last)
def g(A,l,m,r): global c L=A[l:m]+[1e10] R=A[m:r]+[1e10] i=j=0 for k in range(l,r): if L[i]<R[j]:A[k]=L[i];i+=1 else:A[k]=R[j];j+=1 c+=1 def s(A,l,r): if l+1<r: m=(l+r)//2 s(A,l,m) s(A,m,r) g(A,l,m,r) c=0 n=int(input()) A=list(map(int,input().split())) s(A,0,n) print(*A) print(c)
0
null
65,824,835,906,918
269
26
def answer(k: int, s: str) -> str: return s if len(s) <= k else s[:k] + '...' def main(): k = int(input()) s = input() print(answer(k, s)) if __name__ == '__main__': main()
def main(): N,T = map(int, input().split()) AB = [[int(i) for i in input().split()] for _ in range(N)] AB.sort() # dp[i][j]: 満足度の最大値 # i: i品目まで # j: 制限時間(< T) dp = [[0] * 3100 for _ in range(3100)] dp[0][0] = 0 # 貰うDP ans = 0 for i in range(1, N + 1): for j in range(T): dp[i][j] = dp[i - 1][j] # ラストオーダーはAB[i - 1] ans = max(ans, dp[i][j] + AB[i - 1][1]) if j - AB[i - 1][0] >= 0: dp[i][j] = max(dp[i][j], dp[i - 1][j - AB[i - 1][0]] + AB[i - 1][1]) print(ans) if __name__ == "__main__": main()
0
null
85,756,046,693,308
143
282
X = int(input()) print(1000 * (X // 500) + 5 * ((X - 500 * (X // 500)) // 5))
x=int(input()) a=x//500 rem=x%500 b=rem//5 ans=a*1000+b*5 print(ans)
1
42,542,466,669,670
null
185
185
x, k, d = [int(s) for s in input().split()] x = abs(x) q, m = divmod(x, d) if q >= k: x -= k * d else: x = m if (k - q) & 1: x = d - x print(x)
X, K, D = (int(x) for x in input().split()) if X > 0: div, mod = divmod(X, D) if div >= K: answer = X - K*D else: if (K - div)%2 == 0: answer = X - div*D else: answer = abs(X - (div+1)*D) elif X < 0: div, mod = divmod(-X, D) if div >= K: answer = abs(X + K*D) else: if (K - div)%2 == 0: answer = abs(X + div*D) else: answer = X + (div+1)*D else: if K%2 == 0: answer = 0 else: answer = D print(answer)
1
5,153,434,172,152
null
92
92
n = int(input()) ai = [int(i) for i in input().split()] ai_li = [] for i in range(n): ai_li.append([ai[i],i+1]) ai_li.sort(reverse=True) dp = [[0 for i in range(n+1)] for j in range(n+1)] for i in range(1,n+1): #print(i) for j in range(0,i+1): if i == 1: if j == 1: dp[i][j] = ai_li[i-1][0]*abs(ai_li[i-1][1]-1) else: dp[i][j] = ai_li[i-1][0]*abs(n-ai_li[i-1][1]) else: if j == 0: #print(dp[i][j]) dp[i][j] = dp[i-1][0] + ai_li[i-1][0]*abs(n-ai_li[i-1][1]-i+1) else: #if i == 2: # print(i-1,j-1) dp[i][j] = max(dp[i-1][j-1]+ai_li[i-1][0]*abs(ai_li[i-1][1]-j),dp[i-1][j]+ai_li[i-1][0]*abs(n-ai_li[i-1][1]-(i-1-j))) #dp[i][j] = max(dp[i-1][j-1]+ai_li[i][0]*abs(ai_li[i][1]-1+i-1),dp[i-1][j]+ai_li[i][0]*abs(n-i+1-ai_li[i][1])) #print(dp) print(max(dp[n]))
n = int(input()) xs = list(enumerate(map(int, input().split()))) xs.sort(key=lambda x: x[1]) xs.reverse() dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)] for i in range(1, n + 1): (j, a) = xs[i - 1] for x in range(0, i + 1): y = i - x if x == 0: dp[x][y] = dp[x][y - 1] + a * (n - y - j) elif y == 0: dp[x][y] = dp[x - 1][y] + a * (j - x + 1) else: dp[x][y] = max(dp[x][y - 1] + a * (n - y - j), dp[x - 1][y] + a * (j - x + 1)) print(max([dp[i][n - i] for i in range(n + 1)]))
1
33,652,928,176,250
null
171
171
n = int(raw_input()) S = map(int, raw_input().split()) q = int(raw_input()) T = map(int, raw_input().split()) ans = 0 for i in T: if i in S: ans += 1 print ans
n = int(input()) sum = (1 + n) * n // 2 sho_3 = n // 3 sho_5 = n // 5 sho_15 = n // 15 s_3 = (sho_3 * 3 + 3) * sho_3 // 2 s_5 = (sho_5 * 5 + 5) * sho_5 // 2 s_15 = (sho_15 * 15 + 15) * sho_15 // 2 print(sum - s_3 - s_5 + s_15)
0
null
17,608,012,179,758
22
173
N,K,S=map(int, input().split()) MAX = 10**9 if S != MAX: ans = [S]*K + [S+1]*(N-K) print(*ans) else: ans = [S]*K + [S-1]*(N-K) print(*ans)
int(input()) x=map(int,raw_input().split()) print min(x),max(x),sum(x)
0
null
46,164,635,706,140
238
48
def main(): from sys import stdin def input(): return stdin.readline().strip() r, c, k = map(int, input().split()) v = [[0] * c for _ in range(r)] for _ in range(k): i, j, k = map(int, input().split()) v[i-1][j-1] = k # dp[j][n] = j列にいて、n個itemを拾った時のアイテムの価値の合計の最大値 # 1行ずつdpを更新する # 0行目 value = v[0][0] if value == 0: dp = [[0] * 4] else: dp = [[0, value, value, value]] for j in range(1, c): value = v[0][j] if value == 0: dp.append(dp[j-1]) continue a = dp[j-1].copy() b = [0, a[0]+value, a[1]+value, a[2]+value] for k in range(1, 4): if a[k] < b[k]: a[k] = b[k] dp.append(a) # i行目 for i in range(1, r): pre = dp[0][3] value = v[i][0] if value == 0: new_dp = [[pre] * 4] else: new_dp = [[pre, pre+value, pre+value, pre+value]] for j in range(1, c): value = v[i][j] if value == 0: a = new_dp[j-1].copy() b = [dp[j][3]] * 4 for k in range(4): if a[k] < b[k]: a[k] = b[k] new_dp.append(a) else: a = new_dp[j-1].copy() pre = dp[j][3] b = [pre, pre+value, pre+value, pre+value] d = [a[0], a[0]+value, a[1]+value, a[2]+value] for k in range(4): if a[k] < b[k]: a[k] = b[k] if a[k] < d[k]: a[k] = d[k] new_dp.append(a) dp = new_dp print(dp[c-1][3]) main()
import numpy as np import sys input = sys.stdin.readline def main(): h, w, k = map(int, input().split()) values = np.zeros((h, w), dtype=np.int64) items = np.array([list(map(int, input().split())) for _ in range(k)]) ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2] values[ys, xs] = vs DP = np.zeros(w + 1, dtype=np.int64) for line in values: DP[1:] += line DP = np.maximum.accumulate(DP) for _ in range(2): DP[1:] = np.maximum(DP[:-1] + line, DP[1:]) DP = np.maximum.accumulate(DP) print(DP[-1]) if __name__ == "__main__": main()
1
5,565,060,124,420
null
94
94
def main(): N, K = map(int,input().split()) mod = 998244353 S = [] for _ in range (K): S.append(list(map(int,input().split()))) S.sort() #print(S) ans = [0]*N acc = [0]*N ans[0] = 1 acc[0] = 1 for i in range (1,N): for l,r in S: if i-l < 0: break else: ans[i] += acc[i-l] if i-r -1 < 0: break else: ans[i] -= acc[i-r-1] ans[i] %= mod acc[i] = (acc[i-1]+ans[i])%mod print(ans[N-1]) main()
N,M,Q=map(int,input().split()) abcd=[] for i in range(Q): abcd.append(list(map(int,input().split()))) abcd[i][0]-=1 abcd[i][1]-=1 def calcScore(target): score=0 for i in range(Q): if target[abcd[i][1]]-target[abcd[i][0]]==abcd[i][2]: score+=abcd[i][3] return score def makeTarget(): list=[1]*N list[-1]=0 while True: list[-1]+=1 for i in range(len(list)): if list[-i-1]>M: if len(list)==i+1:return list[-i-2]+=1 list[-i-1]=0 for i in range(len(list)-1): if list[i]>list[i+1]:list[i+1]=list[i] yield list.copy() ans=0 for i in makeTarget(): ans=max(ans,calcScore(i)) print(ans)
0
null
15,237,366,385,122
74
160
a = int(input()) b = int(input()) ans = [1,2,3] ans.remove(a) ans.remove(b) print(ans[0])
a=int(input()) b=int(input()) if (a==1 and b==2) or (a==2 and b==1): print('3') if (a==1 and b==3) or (a==3 and b==1): print('2') if (a==2 and b==3) or (a==3 and b==2): print('1')
1
110,979,034,227,360
null
254
254
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, t = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(n)] AB.sort() res = 0 dp = [[0] * (t + 1) for _ in range(n + 1)] for i in range(1, n + 1): a, b = AB[i - 1] for j in range(1, t + 1): if j - a >= 0: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b) else: dp[i][j] = dp[i - 1][j] for k in range(i, n): _, b = AB[k] res = max(res, dp[i][j - 1] + b) print(res) if __name__ == '__main__': resolve()
def main(): N, T = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] dp = [-1] * (T + 3000) dp[0] = 0 c = 0 for a, b in sorted(AB): for j in range(c, -1, -1): if dp[j] == -1: continue t = dp[j] + b if dp[j + a] < t: dp[j + a] = t c = min(c + a, T - 1) print(max(dp)) main()
1
151,642,492,589,650
null
282
282
from math import* print(2**ceil(log2(int(input())+1))-1)
import math h = int(input()) num = math.log(h,2) num = int(num) ans = 0 for i in range(num+1): ans += 2**i print(ans)
1
79,968,502,092,220
null
228
228
class UnionFind(): def __init__(self, n): self.n = n #親の添字、親自身は木の要素数*-1をもつ self.root = [-1]*(n) #枝の最大長さ self.rank = [0]*(n) def find_root(self, x): if(self.root[x] < 0): return x else: self.root[x] = self.find_root(self.root[x]) return self.root[x] #高さによる合併 def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rank[x] > self.rank[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if(self.rank[x] == self.rank[y]): self.rank[y] += 1 def same(self, x, y): return self.find_root(x) == self.find_root(y) def count(self, x): return -self.root[self.find_root(x)] def members(self, x): root = self.find_root(x) return [i for i in range(self.n) if self.find_root(i) == root] def roots(self): return [i for i, x in enumerate(self.root) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} N, M, K = map(int,input().rstrip().split()) AB=[list(map(int,input().rstrip().split()))for _ in range(M)] CD=[list(map(int,input().rstrip().split()))for _ in range(K)] u = UnionFind(N) for a,b in AB: u.unite(a-1,b-1) ans=[u.count(i)-1 for i in range(N)] #木の要素数から自分を引く ans for a,b in AB: if u.same(a-1,b-1): ans[a-1]-=1 ans[b-1]-=1 for c,d in CD: if u.same(c-1,d-1): ans[c-1]-=1 ans[d-1]-=1 print(*ans)
#coding:utf-8 #1_5_B def merge_sort(array): if len(array) > 1: L, countL = merge_sort(array[0:len(array)//2]) R, countR = merge_sort(array[len(array)//2:]) return merge(L, R, countL+countR) if len(array) == 1: return [array, 0] def merge(L, R, count=0): L.append(10**9+1) R.append(10**9+1) response = [] i = 0 j = 0 for k in range(len(L)-1 + len(R)-1): if L[i] <= R[j]: response.append(L[i]) i += 1 count += 1 else: response.append(R[j]) j += 1 count += 1 return [response, count] n = int(input()) S = list(map(int, input().split())) numbers, count = merge_sort(S) print(*numbers) print(count)
0
null
31,000,993,347,700
209
26
n,k = map(int, input().split()) l = list(map(int, input().split())) l.sort() c = 0 i = 0 while i < k: c += l[i] i += 1 print(c)
N, K = map(int, input().split()) p = list(map(int, input().split())) p.sort() print(sum(p[:K]))
1
11,540,991,248,920
null
120
120
x=input() lst=x.split(" ") print(int(lst[0])*int(lst[1]))
n = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) A2 = [A[0]] for a in A[1:]: A2.extend([a, a]) ans = 0 for a in A2[:n-1]: ans += a print(ans)
0
null
12,482,587,914,202
133
111
n = int(input()) num_list = input().split() def bubbleSort(num_list, n): flag = 1 count = 0 while flag: flag = 0 for j in range(n-1, 0, -1): if int(num_list[j]) < int(num_list[j-1]): a = num_list[j] b = num_list[j-1] num_list[j] = b num_list[j-1] = a flag = 1 count += 1 result = ' '.join(num_list) print(result) print(count) bubbleSort(num_list, n)
import sys def swap(a, i, j): tmp = a[j] a[j] = a[i] a[i] = tmp return a def list_to_string(a): s = "" for n in a: s += str(n) + " " return s.strip() num = int(sys.stdin.readline().strip()) array = map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) flag = True swap_num = 0 while flag: flag = False for i in reversed(range(1, len(array))): if array[i] < array[i - 1]: swap(array, i, i-1) flag = True swap_num += 1 print list_to_string(array) print str(swap_num)
1
16,830,552,672
null
14
14
n, x, m = map(int,input().split()) amari = [0]*m v = [x] cnt = 0 while True: xn_1 = x**2%m cnt += 1 if x == 0: break amari[x] = xn_1 if amari[xn_1]: break v.append(xn_1) x = xn_1 #print(v) if 0 in v: ans = sum(v) else: ind = v.index(xn_1) rooplen = len(v) - ind ans = sum(v[0:ind]) l = n-ind if rooplen: ans += (l//rooplen)*sum(v[ind:]) nokori = l - rooplen*(l//rooplen) ans += sum(v[ind:ind+nokori]) #print(v) print(ans)
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N, X, M = LI() A = [] seen = set() tmp = X head_idx = -1 while True: A.append(tmp) seen.add(tmp) tmp = pow(tmp, 2, M) if tmp in seen: head_idx = A.index(tmp) break # print(A, head_idx) cnt = [0] * len(A) for i in range(len(A)): if i < head_idx: if i <= N: cnt[i] = 1 else: l = len(A) - head_idx cnt[i] = (N - head_idx) // l for i in range(head_idx, head_idx + (N - head_idx) % l): cnt[i] += 1 # print(cnt) ans = sum([a * c for a, c in zip(A, cnt)]) print(ans) if __name__ == '__main__': resolve()
1
2,791,589,431,442
null
75
75
A, B, K = [int(x) for x in input().split()] if A >= K: print("{} {}".format(A-K, B)) exit() K -= A A = 0 if B >= K: print("{} {}".format(A, B-K)) exit() print("{} {}".format(0, 0))
A, B, K = map(int, input().split()) if A-K <= 0: K2 = K-A A_ans = 0 if B-K2 <= 0: B_ans = 0 else: B_ans = B-K2 else: A_ans = A-K B_ans = B print(A_ans, B_ans)
1
104,137,514,704,622
null
249
249
n,d,a=[int(j) for j in input().split()] xh=[[int(j) for j in input().split()] for i in range(n)] xh.sort() from collections import deque q=deque() ans=0 dmg=0 for x,h in xh: while q and q[0][0]<x: i,j=q.popleft() dmg-=j r=h-dmg if r<=0: continue p=-(-r//a) dmg+=p*a ans+=p q.append((x+2*d,p*a)) print(ans)
n,m = map(int, input().split()) pena=[0]*(n+1) seitou=[0]*(n+1) for i in range(m): p,s = map(str,input().split()) p=int(p) if s=="WA" and seitou[p]==0: pena[p]+=1 if s=="AC": seitou[p]=1 pena_kazu=0 for i in range(1,n+1): if seitou[i]==1: pena_kazu+=pena[i] seitou_kazu=sum(seitou) print(str(seitou_kazu)+" "+str(pena_kazu))
0
null
87,723,094,060,448
230
240
import sys l = "" for i in sys.stdin.readlines(): l += i.lower().rstrip() word = "abcdefghijklmnopqrstuvwxyz" for i in word: n = l.count(i) print("{} : {}".format(i,n))
import sys alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] cnt = 26 * [0] Input = "" loop = True #while loop: # I = input() # if not I: # loop = False # Input += I for I in sys.stdin: Input += I for i1 in range(len(alphabet)): for i2 in range(len(Input)): if 'A' <= Input[i2] <= 'Z': w = Input[i2].lower() else: w = Input[i2] if alphabet[i1] == w: cnt[i1] += 1 print(alphabet[i1] + " : " + str(cnt[i1]))
1
1,664,100,969,128
null
63
63
n = str(input()) n_list = list(reversed(n)) n_list.append('0') sum = 0 kuriagari = False for i in range(len(n_list)): num = int(n_list[i]) if(kuriagari): num+=1 kuriagari=False if(num==10): num=0 kuriagari=True if(num<5): sum+=num else: if(num>5): sum+=10-num kuriagari=True else: sum+=5 if(int(n_list[i+1])>=5): kuriagari=True print(sum)
k = int(input()) text = "ACL" * k print(text)
0
null
36,645,763,825,340
219
69
X = int(input()) year = 1 yokin = 100 while True: yokin += yokin//100 if yokin >= X: print(year) break year += 1
N = int(input()) A1 = list(map(str,input().split())) A2 = A1[:] def bubbleSort(A, N): flag = 0 i = 0 while flag == 0: flag = 1 for j in range(N-1, i, -1): if A[j][1] < A[j-1][1]: A[j], A[j-1] = A[j-1], A[j] flag = 0 i += 1 return A def selectSort(A, N): for i in range(N): minj = i for j in range(i, N): if A[j][1] < A[minj][1]: minj = j if A[i][1] != A[minj][1]: A[i], A[minj] = A[minj], A[i] return A def stable(Ab, As, N): for i in range(N): if Ab[i] != As[i]: return False return True bubbleSort(A1, N) selectSort(A2, N) print(" ".join(map(str, A1))) print("Stable") print(" ".join(map(str, A2))) if stable(A1, A2, N): print("Stable") else: print("Not stable")
0
null
13,465,069,846,492
159
16
def first_three(str): return str[:3] if len(str) > 3 else str val = input() print(first_three(val))
a = input() b = a[:3] print(b)
1
14,652,541,674,108
null
130
130
n = int(input()) a = [] b = [] for i in range(n): a_1, b_1 = input().split() a.append(int(a_1)) b.append(int(b_1)) a.sort() b.sort() is_odds = n % 2 == 0 if n % 2 == 0: print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1) else: print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)
#!/usr/bin/env python3 from sys import stdin, stdout def solve(): n = int(stdin.readline().strip()) seqA = [] seqB = [] for i in range(n): a,b = map(int, stdin.readline().split()) seqA.append(a) seqB.append(b) seqA = sorted(seqA) seqB = sorted(seqB) mA = seqA[n//2] mB = seqB[n//2] if n%2==0: mA += seqA[n//2-1] mB += seqB[n//2-1] print(mB-mA+1) solve()
1
17,269,535,948,760
null
137
137
n, t = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() dp = [[0] * t for _ in range(n + 1)] ans = 0 for i, (a, b) in enumerate(ab): for j in range(t): dp[i+1][j] = max(dp[i+1][j], dp[i][j]) if j + a <= t - 1: dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b) else: ans = max(ans, dp[i][j] + b) print(ans)
import sys readline = sys.stdin.readline import math # 最短距離をワーシャルフロイドで求める # 最短距離がL以下の街には燃料1で行けるので、辺を貼り直してワーシャルフロイド N,M,L = map(int,readline().split()) import numpy as np from scipy.sparse.csgraph import shortest_path from scipy.sparse.csgraph import floyd_warshall from scipy.sparse.csgraph import csgraph_from_dense INF = 10 ** 9 + 1 G = [[INF for i in range(N)] for j in range(N)] for i in range(M): a,b,c = map(int,readline().split()) G[a - 1][b - 1] = c G[b - 1][a - 1] = c G = csgraph_from_dense(G, null_value=INF) d = floyd_warshall(G) EG = [[INF for i in range(N)] for j in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: EG[i][j] = 1 EG = csgraph_from_dense(EG, null_value=INF) d = floyd_warshall(EG) Q = int(readline()) for i in range(Q): s,t = map(int,readline().split()) if d[s - 1][t - 1] != math.inf: print(int(d[s - 1][t - 1] - 1)) else: print(-1)
0
null
163,082,583,488,032
282
295
N = int(input()) x = int(N/1.08) for i in range(x, x+2): if N == int(i*1.08): print(i) break else: print(":(")
n = int(input()) from decimal import Decimal def calc(n): for i in range(60000): if int(Decimal(i) * Decimal('1.08')) == n: return i return ':(' print(calc(n))
1
125,614,972,645,500
null
265
265
n,m=map(int,input().split()) for i in range(m): print(i+1,2*m-i+(n%2==0 and 2*(m-i)-1>=n//2))
import math n, m = map(int, input().split()) c = 0 f = [math.floor(n/2), math.floor(n/2) + 1] if n % 2 == 0: while c < m: c += 1 if c == math.floor(n/4) + 1: if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n else: while c < m: c += 1 print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n
1
28,782,986,994,696
null
162
162
while True: h, w = map(int, input().split()) if h == 0 and w == 0: break for i in range(h): print('#'*w) print()
H, W, K = map(int, input().split()) m = [] for h in range(H): m.append(list(map(int, list(input())))) ans = float('inf') for hb in range(2**(H-1)): hl = [] for i in range(H-1): if hb & (1 << i) > 0: hl.append(i+1) t = len(hl) hl = [0]+hl+[H] w, pw = 0, 0 wl = [0]*len(hl) while w < W: ok = True for i in range(len(hl)-1): sh, eh = hl[i], hl[i+1] for h in range(sh, eh): wl[i] += m[h][w] if wl[i] > K: ok = False break if not ok: break if not ok: if pw == w: t = float('inf') break pw, w = w, w t += 1 wl = [0]*len(hl) else: w += 1 ans = min(t, ans) print(ans)
0
null
24,667,514,445,028
49
193
import sys input = sys.stdin.readline N=int(input()) L=list(map(int,input().split())) Q=int(input()) R=[0]*(10**5) for i in L: R[i-1]+=1 ans=sum(L) for i in range(Q): a,b=map(int,input().split()) R[b-1]+=R[a-1] ans+=(b-a)*R[a-1] R[a-1]=0 print(ans)
n = int(input()) a = list(map(int, input().split())) q = int(input()) sums = sum(a) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 for i in range(q): b,c = map(int, input().split()) if b in d: sums += d[b]*(c-b) if c in d: d[c] += d[b] else: d[c] = d[b] d[b] = 0 print(sums)
1
12,269,034,139,680
null
122
122
n = int(input()) p = list(map(int,input().split())) mini = 10**9 ans =0 for i in range(n): if p[i] <= mini: mini = p[i] ans += 1 print(ans)
def first_three(str): return str[:3] if len(str) > 3 else str val = input() print(first_three(val))
0
null
50,239,728,189,780
233
130
#https://atcoder.jp/contests/abc164/tasks/abc164_b A,B,C,D = map(int,input().split()) Senkou_N,Senkou_Amari = divmod(C,B) if Senkou_Amari != 0: Senkou_N += 1 Koukou_N,Koukou_Amari = divmod(A,D) if Koukou_Amari != 0: Koukou_N += 1 if Senkou_N <= Koukou_N: print("Yes") else: print("No")
a,b,c,d=map(int,input().split()) while 1: c-=b if c<=0: print('Yes'); exit() a-=d if a<=0: print('No'); exit()
1
29,645,334,319,928
null
164
164
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys a, b, c = map(int, sys.stdin.readline().split()) num_div = 0 for x in range(a, b+1): if c % x == 0: num_div += 1 print(num_div)
R, C, K = map(int, input().split()) items = [[0]*C for _ in range(R)] for i in range(K): r, c, v = map(int, input().split()) items[r-1][c-1] = v dp = [[0]*4 for _ in range(C)] for x in range(1, 4): dp[0][x] = items[0][0] for j in range(1, C): dp[j][x] = max(dp[j-1][x-1] + items[0][j], dp[j-1][x]) #print(items) #print(dp) for i in range(1, R): for j in range(C): for x in range(4): dp[j][x] = dp[j][3] for x in range(1, 4): dp[0][x] += items[i][0] for j in range(1, C): dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j]) #print(dp) print(dp[-1][-1])
0
null
3,050,487,979,072
44
94
import math import itertools n=int(input()) k=int(input()) def comb(n,k): return len(list(itertools.combinations(range(n), k))) x=str(n) m=len(x) ans=0 for i in range(1,m): ans+=(comb(i-1,k-1)*(9**k)) if k==1: for i in range(1,10): if i*(10**(m-1))<=n: ans+=1 elif k==2: for i in range(1,10): if i*(10**(m-1))<=n: for j in range(m-1): for a in range(1,10): if i*(10**(m-1))+a*(10**(j))<=n: ans+=1 else: break else: break else: po=[10**i for i in range(m)] for i in range(1,10): if i*po[m-1]<=n: for j in range(m-1): for a in range(1,10): if i*po[m-1]+a*po[j]<=n: for b in range(j): for c in range(1,10): ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n) else: break else: break print(ans)
#!/usr/bin/env python3 #%% for atcoder uniittest use import sys input= lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int):return map(type,input().split()) def tupin(t=int):return tuple(pin(t)) def lispin(t=int):return list(pin(t)) #%%code def resolve(): N=input() K,=pin() #degit DP #dp_table["index"][smaller][cond]=cond:=ちょうどK個の数がある を満たす総数 rb=(0,1) dp_table=[[[0 for cnd in range(K+1)]for sml in rb]for ind in range(len(N)+1)] dp_table[0][0][0]=1 #print(dp_table) #print("degit,sml,k,prove,l,x<n,dp_table[degit-1][sml][k]")# for degit in range(len(N)+1): n=int(N[degit-1]) for sml in rb: t=10 if sml else int(N[degit-1])+1 for k in range(K+1): for prove in range(t): x=prove try:#Indexerror #print(degit,sml,k,prove,"l",x<n,dp_table[degit-1][sml][k]) #if sml==False and x==n:print(n,":") dp_table[degit][sml or x<n][k+(x!=0)]+=dp_table[degit-1][sml][k] except :pass print(dp_table[-1][0][K]+dp_table[-1][1][K]) #print(dp_table) #%%submit! resolve()
1
76,120,496,489,700
null
224
224
n,p = map(int, input().split()) s = list(map(int, input().strip())) count = 0 if(p == 2 or p == 5): #10と互いに素ではない場合 co = 0 for i in range(n): #1の位から順に数を追加していく ne = int(s[n-i-1]) % p if(ne == 0): co += 1 count += co print(count) else: sta = [0]*p sta[0] += 1 d = 1 co = 0 for i in range(n): ne = int(s[n-i-1]) * d % p co += ne co %= p sta[co] += 1 d *= 10 d %= p for i in range(p): count += sta[i] * (sta[i]-1) // 2 print(count)
N = int(input()) S = set([]) for i in range(N): temp = str(input()) S.add(temp) ans = len(S) print(ans)
0
null
44,077,910,774,610
205
165
n,m = map(int,input().split()) #行列a、ベクトルb、行列積cの初期化 a = [0 for i in range(n)] b = [0 for j in range(m)] c = [] #a,bの読み込み for i in range(n): a[i] = input().split() a[i] = [int(x) for x in a[i]] for j in range(m): b[j] = int(input()) #行列積計算 temp = 0 for i in range(n): for j in range(m): temp += a[i][j]*b[j] c.append(temp) temp = 0 #結果の表示 for num in c:print(num)
n,m = (int(i) for i in input().split()) array = [[int(i) for i in input().split()] for i in range(n)] b = [int(input()) for i in range(m)] for i in range(n): ans = 0 for i2 in range(m): ans += array[i][i2]*b[i2] print(ans)
1
1,178,492,739,480
null
56
56
import sys mapin = lambda: map(int, sys.stdin.readline().split()) listin = lambda: list(map(int, sys.stdin.readline().split())) inp = lambda: sys.stdin.readline() N = int(inp()) mp = {} for i in range(N): S = inp() S = S[:-1] if S in mp: mp[S] += 1 else: mp[S] = 1 ans = 0 vec = [] for i in mp.values(): if ans < i: ans = i for i in mp.keys(): if mp[i] == ans: vec.append(i) vec.sort() for i in vec: print(i)
n = int(input()) dic = {} for _ in range(n): s = input() if s in dic: dic[s] += 1 else: dic[s] = 1 mv = max(dic.values()) for s, v in sorted(dic.items()): if v == mv: print(s)
1
69,989,367,776,226
null
218
218
X,Y = map(int,input().split()) turtle_leg = 4 crane_leg = 2 for i in range(X+1): if Y == turtle_leg*i+crane_leg*(X-i): print ("Yes") break if i==X: print ("No") break
r, c = map(int, input().split()) sum_row = [] for i in range(c + 1): sum_row.append(0) for i in range(r): tmp_row = tuple(map(int, input().split())) tmp_row_sum = sum(tmp_row) tmp_row += tmp_row_sum, print(" ".join(map(str, tmp_row))) for j in range(c + 1): sum_row[j] += tmp_row[j] print(" ".join(map(str, sum_row)))
0
null
7,560,993,895,690
127
59
import sys sys.setrecursionlimit(10000000) input=sys.stdin.readline n = int(input()) a = list(map(int,input().split())) def gcd(a, b): return a if b == 0 else gcd(b, a%b) def lcm(a, b): return a // gcd(a, b) * b mod = 10**9+7 x=a[0] for i in a[1:]: x=lcm(x,i) ans=0 for i in range(n): ans+= x//a[i] print(ans%mod)
n=int(input()) A=list(map(int,input().split())) mod=10**9+7 def lcm(X,Y): x=X y=Y if y>x: x,y=y,x while x%y!=0: x,y=y,x%y return X*Y//y cnt=0 ans=0 LCM=1 for i in range(n): Q=lcm(LCM,A[i]) cnt*=Q//LCM LCM=Q cnt+=Q//A[i] print(cnt%mod)
1
87,738,659,557,808
null
235
235
S = input() Q = int(input()) lS = '' for _ in range(Q): query = input().split() if query[0] == '1': lS, S = S, lS else: if query[1] == '1': lS += query[2] else: S += query[2] print(lS[::-1] + S)
n, m = list(map(int, input().split())) A = [] V = [] B = [] for i in range(n): A.append(list(map(int, input().split()))) for j in range(m): V.append([int(input())]) for i in range(n): B.append([0]) for j in range(m): B[i][0] += A[i][j] * V[j][0] for i in range(n): print(B[i][0])
0
null
29,366,741,618,070
204
56
s=input() if s=="RSR": print("1") else: ans=s.count("R") print(ans)
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)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def main(): N, M = list(map(int, input().split())) paths = [list(map(int, input().split())) for _ in range(M)] result = solve(N, paths) print(result) def solve(N, paths) -> int: uf = UnionFind(N) for x, y in paths: uf.union(x - 1, y - 1) return uf.group_count() - 1 if __name__ == '__main__': main()
0
null
3,577,665,519,782
90
70
print("No" if input() in ["AAA","BBB"] else "Yes")
n, m ,l = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] b = [list(map(int, input().split())) for j in range(m)] c = [[sum(ak*bk for ak, bk in zip(ai, bj)) for bj in zip(*b)] for ai in a] for ci in c: print(*ci)
0
null
28,225,749,513,668
201
60
s=input() if s.count('A') and s.count('B'): print('Yes') else: print('No')
l=list(input()) if(l[0]==l[1]==l[2]): print("No") else: print("Yes")
1
55,098,161,446,432
null
201
201
def insertion_sort(array, size, gap=1): """ AOJ??¬??¶?????¬??? http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_A :param array: ?????????????±?????????? :return: ????????????????????? """ global Count for i in range(gap, len(array)): # i????¬?????????????????????????????????? v = array[i] # ?????¨?????\???????????¨????????????????????????????????´??? j = i - gap while j >= 0 and array[j] > v: array[j + gap] = array[j] j = j - gap Count += 1 array[j + gap] = v return array def shell_sort(array, n): Count = 0 G = calc_gap(n) m = len(G) print(m) print(' '.join(map(str, G))) for i in range(0, m): insertion_sort(array, n, G[i]) def calc_gap(n): results = [1] while results[-1] < n: results.append(3 * results[-1] + 1) if len(results) > 1: results = results[:-1] results.sort(reverse=True) return results Count = 0 if __name__ == '__main__': # ??????????????\??? # data = [5, 1, 4, 3, 2] data = [] num = int(input()) for i in range(num): data.append(int(input())) # ??????????????? shell_sort(data, len(data)) # ???????????¨??? print(Count) for i in data: print(i)
def insertionSort(A, n, g): cnt = 0 for i in xrange(g, n): v = A[i] j = i - g while (j >= 0) and (A[j] > v): A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v return cnt def shellSort(A, n): # variables cnt, m, t = 0, 1, n # getting m while (t-1)/3 > 0: t, m = (t-1)/3, m+1 print m # creating and printing G G = [1] for i in xrange(1,m): G.append(1+G[i-1]*3) G = list(reversed(G)) print " ".join( map(str, G) ) # sorting for i in xrange(0, m): cnt += insertionSort(A, n, G[i]) return cnt # MAIN n = input() A = [input() for i in xrange(n)] cnt = shellSort(A, n) print cnt for i in xrange(n): print A[i]
1
31,800,086,918
null
17
17
H=int(input()) if H==1: print(1) else: i=1 count=1 while H//2!=1: i*=2 count+=i H=H//2 i*=2 count+=i print(count)
H = int(input()) for i in range(0, 10**20 + 1): if 2**i <= H < 2 ** (i + 1): break print(2 ** (i + 1) - 1)
1
80,066,560,640,220
null
228
228
while 1: a, b = [int(x) for x in input().split()] if a == 0 and b == 0: break if a > b: a, b = b, a print(a, b)
x=[] y=[] while True: i,j=map(int,raw_input().split()) if (i,j)==(0,0): break; x.append(i) y.append(j) X=iter(x) Y=iter(y) for a in X: b=Y.next() if a<b: print('%d %d'%(a,b)) else: print('%d %d'%(b,a))
1
537,421,494,978
null
43
43
import math N=int(input()) if (N/1.08).is_integer()==True: S=int(N/1.08) else: S=math.ceil(N/1.08) if (S*1.08)//1==N: print(S) else: print(':(')
import math N = int(input()) for i in range(1,46298): if math.floor(i*1.08) == N: print(i) exit() print(":(")
1
126,008,846,866,210
null
265
265
n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n-1): if a[i]==a[i+1]: print("NO") exit() print("YES")
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
37,198,736,940,092
222
22
X, K, D = map(int, input().split()) X = abs(X) point = X % D q = X // D ans = 0 if q >= K: ans = abs(X-D*K) elif (K - q) % 2 == 0: ans = point else: ans = D-point print(ans)
import math X,K,D=map(int,input().split()) count=0 #Xが初期値 #Dが移動量(+or-) #K回移動後の最小の座標 #X/D>Kの場合、K*D+Xが答え Y = 0 #X>0 D>0 の場合 if X / D > K and X / D > 0: Y = abs(X - D * K) elif abs(X / D) > K and X / D < 0: Y = abs(X + D * K) else: #X/D<Kの場合、X mod D L = abs(X) % D M = math.floor(abs(X) / D) if (K - M) % 2 == 0: Y = L else: Y=abs(L-D) print(Y)
1
5,213,433,840,600
null
92
92
n,k =map(int, input().split()) h = list(map(int, input().split())) # n = int(input()) # s = [map(int, input()) for i in range(3)] count = 0 for i in range (0,n): if h[i] < k: count+=1 print(n-count)
K = int(input()) Ans = 'ACL' for i in range(K-1): Ans += 'ACL' print(Ans)
0
null
90,892,850,641,592
298
69
def InsertionSort(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) N = int(input()) A = [int(a) for a in input().split()] InsertionSort(A, N)
class SwappingTwoNumbers: def output(self, n): n.sort() print "%d %d" % (n[0], n[1]) if __name__ == "__main__": stn = SwappingTwoNumbers(); while True: n = map(int, raw_input().split()) if n[0] == 0 and n[1] == 0: break stn.output(n)
0
null
263,235,429,380
10
43
n,m=map(int,input().split());print('YNeos'[n!=m::2])
inputted = list(map(int, input().split())) N = inputted[0] M = inputted[1] answer = 'Yes' if N == M else 'No'; print(answer);
1
82,983,706,037,038
null
231
231
from collections import deque def breadth_first_search(adj_matrix, n): distance = [0] + [-1] * (n - 1) searching = deque([0]) while len(searching) > 0: start = searching.popleft() for end in range(n): if adj_matrix[start][end] and distance[end] == -1: searching.append(end) distance[end] = distance[start] + 1 return distance def main(): n = int(input()) adj = [[False for _ in range(n)] for _ in range(n)] for _ in range(n): ukv = input().split() id = int(ukv[0]) dim = int(ukv[1]) if dim > 0: nodes = map(int, ukv[2:]) for node in nodes: adj[id - 1][node - 1] = True distance = breadth_first_search(adj, n) for i in range(n): print("{} {}".format(i + 1, distance[i])) if __name__ == "__main__": main()
def BFS(s = 0): Q.pop(0) color[s] = 2 for j in range(len(color)): if A[s][j] == 1 and color[j] == 0: Q.append(j) color[j] = 1 d[j] = d[s] + 1 if len(Q) != 0: BFS(Q[0]) n = int(raw_input()) A = [0] * n for i in range(n): A[i] = [0] * n for i in range(n): value = map(int, raw_input().split()) u = value[0] - 1 k = value[1] nodes = value[2:] for j in range(k): v = nodes[j] - 1 A[u][v] = 1 color = [0] * n Q = [0] d = [-1] * n d[0] = 0 BFS(0) for i in range(n): print(str(i + 1) + " " + str(d[i]))
1
3,749,508,612
null
9
9
K=int(input()) S=input() N=len(S) if N<=K: print(S) else: ans=[] for i in range(K): ans.append(S[i]) print(''.join(ans)+'...')
def main(): K = int(input()) S = input() if len(S) <= K: return S return S[:K] + '...' if __name__ == '__main__': print(main())
1
19,639,249,822,752
null
143
143
s = input() ret = s[:3] print("{}".format(ret))
name = input() str_name = str(name) print(str_name[:3])
1
14,650,260,442,658
null
130
130
X, Y = map(int, input().split()) ans = '' for i in range(X+1): if (i*2 + (X-i)*4) == Y: ans = 'Yes' break else: ans = 'No' print(ans)
X,Y = map(int, input().split()) if X * 2 > Y: print('No') elif X * 4 < Y: print('No') else: for i in range(0,X+1): if Y == (X * 2) + (i * 2): print('Yes') break else: print('No')
1
13,874,560,238,848
null
127
127
s = input() s = s.split() n = [] for i in s: n.append(int(i)) a = n[0] b = n[1] print("a",end = " ") if a > b: print(">",end = " ") elif a < b: print("<",end = " ") else: print("==",end = " ") print("b")
height = [int(input()) for i in range(10)] sort = sorted(height, reverse=True) for i in range(3): print(sort[i])
0
null
186,095,759,396
38
2
import sys input = lambda: sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) nums = [i for i in range(n+1)] sums = [0] ans = 0 x = 10**9 + 7 for i in range(n): sums.append(nums[i+1]+sums[i]) for j in range(k, len(nums)+1): if j == len(nums): ans += 1 else: ans += sums[-1] - sums[-(1+j)] - sums[j-1] + 1 print(ans%x) if __name__ == '__main__': main()
def main(): N,K=map(int,input().split()) res=0 MOD=10**9+7 for i in range(K,N+2): MAX=(N+(N-i+1))*i//2 MIN=(i-1)*i//2 res+=MAX-MIN+1 res%=MOD print(res%MOD) if __name__=="__main__": main()
1
33,020,851,582,498
null
170
170
a, b, c = map(int, input().split()) if 4 * a * b < (c - a - b) ** 2 and a + b < c: print('Yes') else: print('No')
import math x = int(input()) for i in range(1, 121): for j in range(-120, 121): if i**5 - j**5 == x: print(i, j) quit(0)
0
null
38,762,684,065,698
197
156
n = int(input()) - 1 a = list(map(int, input().split())) count = 0 flag = 1 while flag: flag = 0 j = 0 for i in range( n, j, -1 ): if a[i] < a[i-1]: t = a[i] a[i] = a[i-1] a[i-1] = t count += 1 flag = 1 j += 1 print(*a) print(count)
n = int(input()) line = input() arr= line.split(" ") nums = [] for c in range(n): nums.append(int(arr[c])) flag = "true" convert_n = 0 while flag == "true": flag = "false" for i in range(len(nums)-1, 0, -1): if nums[i] < nums[i-1]: tmp = nums[i] nums[i] = nums[i-1] nums[i-1] = tmp flag = "true" convert_n += 1 n_list_str = "" for num in nums: n_list_str += str(num) n_list_str += " " print(n_list_str.rstrip(" ")) print(convert_n)
1
17,446,166,264
null
14
14
# -*- coding: utf-8 -*- import numpy as np import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect sys.setrecursionlimit(10**6) def zz(): return list(map(int, sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline() def C(line): return [sys.stdin.readline() for _ in range(line)] N = z() A = [0]*N X = {} Y = {} for i in range(N): A[i] = z() X[i] = [0]*A[i] Y[i] = [0]*A[i] for j in range(A[i]): x, y = zz() X[i][j] = x-1 Y[i][j] = y ans = 0 for bits in itertools.product([0, 1], repeat=N): # print("================") # print(bits) false_flg = False for i, b in enumerate(bits): if (b == 1): # print('i=', i) for x, y in zip(X[i], Y[i]): # print(x, y) if (bits[x] != y): # print(False) false_flg = True if false_flg: break if false_flg: break if false_flg: continue else: ans = max(ans, sum(bits)) print(ans)
# -*- coding: utf-8 -*- N = int(input()) A = [] data = [] for i in range(N): a = int(input()) A.append(a) x = [list(map(int, input().split())) for _ in range(a)] data.append(x) ans = 0 for i in range(1<<N): bit = [0] * N cnt = 0 for j in range(N): div = 1 << j bit[j] = (i // div) % 2 if bit[j] == 1: cnt += 1 flag = True for j in range(N): if bit[j] == 0: continue for a in range(A[j]): x = data[j][a] if bit[x[0]-1] != x[1]: flag = False break if not flag: break if flag: ans = max(ans, cnt) print(ans)
1
121,374,079,774,970
null
262
262
N, M = map(int, input().split()) ac = 0 pena = 0 count = [0 for _ in range(N+1)] for _ in range(M): p, S = input().split() p = int(p) if S == 'AC': if count[p] > -1: pena += count[p] ac += 1 count[p] = -10**5-1 else: count[p] += 1 print(ac, pena)
row = int(input()) colmun = int(input()) top = int(input()) low, high = 0,0 if row <= colmun: low, high = row, colmun else: low, high = colmun, row for n in range(low): if (n + 1) * high >= top: print(n + 1) break
0
null
91,181,683,123,022
240
236
X,Y = map(int,input().split()) price = [3*10**5, 2*10**5, 1*10**5] ans = 0 if X == 1 and Y == 1: ans += 4*10**5 X -= 1 Y -= 1 if X < 3: ans += price[X] if Y < 3: ans += price[Y] print(ans)
s = int(input()) n = (s/3) print(n*n*n)
0
null
93,973,309,143,812
275
191
N=input() N=list(N) N=map(lambda x: int(x),N) if sum(N)%9==0: print("Yes") else: print("No")
N = int(input()) digits = list(map(int,str(N))) if sum(digits) % 9 == 0: print('Yes') else: print('No')
1
4,364,679,498,620
null
87
87
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # map(int, input().split()) def my_pow(base, n, mod): if n == 0: return 1 x = base y = 1 while n > 1: if n % 2 == 0: x *= x n //= 2 else: y *= x n -= 1 x %= mod y %= mod return x * y % mod N, P = map(int, input().split()) S = input() if P == 2 or P == 5: ans = 0 for i, c in enumerate(S[::-1]): if int(c) % P == 0: ans += N - i print(ans) exit() cnt = [0] * P base = 1 cur = 0 for c in S[::-1]: cur += (base * int(c)) % P cnt[cur % P] += 1 base *= 10 base %= P ans = 0 for i in cnt: if i == 0: continue ans += i * (i - 1) // 2 print(ans + cnt[0])
n,p=map(int,input().split()) s=list(map(int,list(input()[::-1]))) if p in [2,5]: ans=0 for i in range(n): if s[-i-1]%p==0:ans+=i+1 print(ans) exit() from collections import defaultdict d=defaultdict(int) t=0 d[t]+=1 m=1 for i in range(n): t+=m*s[i] t%=p d[t]+=1 m*=10 m%=p print(sum(d[i]*(d[i]-1)//2 for i in range(p)))
1
58,167,248,259,130
null
205
205
import collections hoge = collections.defaultdict(lambda: 'no') num = int(input()) for _ in range(num): command, key = input().split() if command == 'insert': hoge[key] = 'yes' else: print(hoge[key])
def main(): N = int(input()) A = list(map(int, input().split())) L = [0] * (10**6+1) for a in A: L[a] += 1 ans = 0 Ng = [False] * (10**6+1) for a, cnt in enumerate(L): if cnt: for i in range(a*2, 10**6+1, a): Ng[i] = True for a, (cnt, ng) in enumerate(zip(L, Ng)): if cnt == 1 and not ng: ans += 1 print(ans) main()
0
null
7,328,136,626,790
23
129
H = int(input()) ans = 0 cnt = 0 while True: ans += 2 ** cnt if H == 1: break H = H//2 cnt += 1 print(ans)
n=int(input()) cnt=0 ans=0 while(n>=1): ans+=2**cnt n//=2 cnt+=1 print(ans)
1
80,566,118,395,280
null
228
228
S = input() print(S[0:3:1])
S = input() ans = [] for i in range(len(S)+1): if i <= 2 : ans += S[i] else: print(''.join(ans)) exit()
1
14,733,272,080,060
null
130
130
N,K,C = map(int,input().split()) S = input() left, right = [], [] d = 0 while d < N and len(left) < K: if S[d] == 'o': left.append(d) d += C + 1 else: d += 1 d = N - 1 while d >= 0 and len(right) < K: if S[d] == 'o': right.append(d) d -= C + 1 else: d -= 1 right.sort() ans = [] for i in range(K): if left[i] == right[i]: ans.append(left[i]) for c in ans: print(c+1)
a = int(input()) b = int(input()) if a == 1 and b == 2: print(3) elif a == 1 and b == 3: print(2) elif a == 2 and b == 1: print(3) elif a == 2 and b == 3: print(1) elif a == 3 and b == 1: print(2) elif a == 3 and b == 2: print(1)
0
null
76,015,840,403,260
182
254
a, b = input().split() c = a a = a*int(b) b = b*int(c) for i in range(len(a)): if a[i]<b[i]: print(a) break elif a==b: print(a) break else: print(b) break
# -*- coding: utf-8 -*- a, b = input().split() if a > b: print(b*int(a)) else: print(a*int(b))
1
84,368,819,204,348
null
232
232
# -*- coding: utf-8 -*- import sys def main(): N,K = list(map(int, sys.stdin.readline().split())) A_list = list(map(int, sys.stdin.readline().split())) for i in range(K, len(A_list)): if A_list[i] > A_list[i-K]: print("Yes") else: print("No") if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def BFS(adj, start): n = len(adj) d = [n] * n flag = [0] * n Q = [] Q.append(start) d[start] = 0 while len(Q) != 0: u = Q.pop(0) v = [i for i, x in enumerate(adj[u]) if (x == 1) and (flag[i] == 0)] # v <= ??£??\???????????????????????¢?´¢?????????????????? for i in v: Q.append(i) d[i] = min(d[u] + 1, d[i]) flag[u] = 1 for i in range(n): if d[i] == n: d[i] = -1 return d def main(): n = int(input()) adj = [[0 for i in range(n)] for j in range(n)] for i in range(n): tmp = list(map(int, input().split())) u = tmp[0] u = u -1 k = tmp[1] v = tmp[2:] for j in range(k): adj[u][v[j]-1] = 1 d = BFS(adj, 0) for i in range(n): print(i+1, d[i]) if __name__ == "__main__": main()
0
null
3,530,848,446,358
102
9
from heapq import heappush, heappop n = int(input()) A = list(map(int, input().split())) f_inf = float('inf') dp = [[0 for _ in range(n+1)] for _ in range(n+1)] dp[0][0] = 0 hq = [] for i in range(n): heappush(hq, (-A[i], i)) ans = 0 for i in range(n): x, pi = heappop(hq) for l in range(i+1): r = i-l dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + (pi-l)*A[pi]) dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ((n-r-1)-pi)*A[pi]) ans = 0 for i in range(n+1): ans = max(ans, dp[n][i]) print(ans)
import heapq import sys input = sys.stdin.readline n = int(input()) s = [input() for _ in range(n)] t = [] p = [] for i in range(n): k = 0 m = 0 for c in s[i]: if c == '(': k += 1 elif c == ')': k -= 1 m = min(k, m) if k >= 0: t.append((-m, k)) else: k = 0 m = 0 for c in s[i][::-1]: if c == ')': k += 1 elif c == '(': k -= 1 m = min(k, m) p.append((-m, k)) t.sort() p.sort() hq = [] hq1 = [] d = 0 idx = 0 for i in range(len(t)): while idx < len(t) and d >= t[idx][0]: m, k = t[idx] heapq.heappush(hq, (-k, m)) idx += 1 if hq: k, m = heapq.heappop(hq) else: print('No') break d -= k else: d1 = 0 idx = 0 for i in range(len(p)): while idx < len(p) and d1 >= p[idx][0]: m, k = p[idx] heapq.heappush(hq1, (-k, m)) idx += 1 if hq1: k, m = heapq.heappop(hq1) else: print('No') break d1 -= k else: if d == d1: print('Yes') else: print('No')
0
null
28,570,912,410,012
171
152
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D #?????§?????? #??????????????????????????°???????????????????????¢?????´????????????????????? def get_maximum_profit(value_list, n_list): minv = pow(10,10) + 1 profit = -minv for v in value_list: profit = max(profit, v - minv) minv = min(minv, v) return profit def main(): n_list = int(input()) target_list = [int(input()) for i in range(n_list)] print(get_maximum_profit(target_list, n_list)) if __name__ == "__main__": main()
import sys n = int(input()) r0 = int(input()) r1 = int(input()) mx = r1-r0 mn = min(r1,r0) for i in map(int,sys.stdin.readlines()): if mx < i - mn: mx = i - mn if 0 > i-mn: mn = i elif mn > i: mn = i print(mx)
1
13,729,318,428
null
13
13
from math import ceil H=int(input()) W=int(input()) N=int(input()) print(min(ceil(N/H),ceil(N/W)))
H = int(input()) W = int(input()) N = int(input()) HW =H*W ans =H+W for h in range(0,H+1): for w in range(0,W+1): cntB = HW - (H-h)*(W-w) if cntB>=N: ans = min(ans, h+w) print(ans)
1
88,678,632,362,592
null
236
236
for _ in range(int(input())): e = list(map(int, input().split())) print("YES" if max(e) ** 2 * 2 == sum(i ** 2 for i in e) else "NO")
N = input() a = [] for i in range(N): a = map(int, raw_input().split()) b = [0] for i in a: j = 0 while j < 3: if i > b[j]: b.insert(j, i) break j += 1 if b[0]**2 == b[1]**2 + b[2]**2: print "YES" else: print "NO"
1
250,694,230
null
4
4
n, m, q = map(int, input().split()) abcd = [list(map(int, input().split())) for _ in range(q)] a,b,c,d = [],[],[],[] for i in range(q): a.append(abcd[i][0]) b.append(abcd[i][1]) c.append(abcd[i][2]) d.append(abcd[i][3]) def score(A): tmp = 0 for ai, bi, ci, di in zip(a, b, c, d): if A[bi] - A[ai] == ci: tmp += di return tmp def dfs(A): if len(A)==n+1: return score(A) ans = 0 for i in range(A[-1],m): A.append(i) ans = max(ans,dfs(A)) A.pop() return ans print(dfs([0]))
#!/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())) def calc(lst): ret = 0 for a, b, c, d in abcd: if lst[b-1] - lst[a-1] == c: ret += d return ret def dfs(lst): if len(lst) == n: return calc(lst) x = lst[-1] ret = 0 for i in range(x, m+1): ret = max(ret, dfs(lst + [i])) return ret n, m, q = LI() abcd = [LI() for _ in range(q)] ans = dfs([1]) print(ans)
1
27,591,577,356,264
null
160
160
from collections import Counter n = int(input()) S = [input() for i in range(n)] counter = Counter(S) print(len(counter.keys()))
x = raw_input().split() if float(x[0]) < float(x[1]): print "a < b" elif float(x[0]) > float(x[1]): print "a > b" else: print "a == b"
0
null
15,402,704,506,798
165
38
import math def main(): n = int(input()) _debt = 100000 for i in range(n): _debt += math.ceil(_debt*0.05*0.001)*1000 print(_debt) if __name__ == '__main__': main()
N = input() K = int(input()) # K = 1の時の組み合わせを求める関数 def func_1(N): Nm = int(N[0]) return Nm + 9 * (len(N) - 1) # K = 2の時の組み合わせを求める関数 def func_2(N): #NはStringなので #print(N[0]) Nm = int(N[0]) m = len(N) #if m == 1: # print("0") #print((Nm-1)*(m-1)*9) #print((m - 1) * (m - 2) * 9 * 9 / 2) x = int(N) - Nm * pow(10, m-1) #print(x) #print(1) #print(func_1(str(x))) return int((Nm-1)*(m-1)*9+(m-1)*(m-2)*9*9/2+func_1(str(x))) def func_3(N): #print("OK") Nm = int(N[0]) m = len(N) # if m == 1 or m == 2: # print("0") return int(pow(9,3)*(m-1)*(m-2)*(m-3)/6+(Nm-1)*(m-1)*(m-2)*9*9/2+func_2(str(int(N)-Nm*(10**(m-1))))) if K == 1: print(func_1(N)) elif K == 2: print(func_2(N)) elif K == 3: print(func_3(N))
0
null
38,201,829,234,056
6
224
s,t=input().split() x=t+s print(x)
s,t=input().split() print(t+s,end='')
1
103,352,614,453,360
null
248
248
s=input() print("".join(["x"]*len(s)))
n=int(input()) a=list(map(int,input().split())) col=[0,0,0] res=1 for ai in a: cnt=0 for i in range(3): if col[i]==ai: if cnt==0: col[i]=col[i]+1 cnt+=1 res=(res*cnt)%1000000007 print(res)
0
null
101,334,418,207,370
221
268
n = list(map(int,input().split())) a = list(map(int,input().split())) for i in range(n[1],n[0]): if a[i-n[1]] < a[i]: print("Yes") else: print("No")
import sys read = sys.stdin.readline import time import math import itertools as it def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N, K = inpl() A = inpl() for i in range(K, N): if A[i] > A[i-K]: print('Yes') else: print('No') # ----------------------------- ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
1
7,035,422,291,340
null
102
102
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 #mod = 998244353 INF = 10**18 eps = 10**-7 N = int(input()) 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) divisors.sort() m=len(divisors) if m%2==0: print(divisors[m//2]+divisors[m//2-1]-2) else: print(divisors[m//2]*2-2)
def solve(n): l = [] for i in range(int(n**(1/2))): if n % (i+1) == 0: a = i + 1 b = n // a l.append(a+b-2) return min(l) print(solve(int(input())))
1
161,568,362,340,722
null
288
288
num=[] num=list(map(int,input().split())) for i in range(5): if num[i]==0: print(i+1) break else: continue
import math N=int(input()) lim=int(math.sqrt(N)) ans=10**13 for i in range(1,lim+1): if N%i==0: if ans>(i+(N//i)-2): ans=(i+(N//i)-2) print(ans)
0
null
87,212,537,595,228
126
288