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
import sys SUITS = ['S', 'H', 'C', 'D'] exist_cards = {suit:[] for suit in SUITS} n = input() for line in sys.stdin: suit, number = line.split() exist_cards[suit].append(int(number)) for suit in SUITS: for i in range(1, 14): if i not in exist_cards[suit]: print(suit, i)
from bisect import bisect_left N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() def doesOver(k): cnt = 0 for a in A: cnt += N - bisect_left(A, k - a) return cnt >= M overEq = 0 less = A[-1] * 2 + 100 while less - overEq > 1: mid = (less + overEq) // 2 if doesOver(mid): overEq = mid else: less = mid accA = [0] * (N + 1) for i in range(1, N + 1): accA[i] = accA[i - 1] + A[i - 1] ans = 0 cnt = 0 for a in A: left = bisect_left(A, overEq - a) ans += accA[N] - accA[left] ans += (N - left) * a cnt += N - left ans -= (cnt - M) * overEq print(ans)
0
null
54,591,798,594,400
54
252
n = input() n = n.split() m = int(n[1]) n = int(n[0]) a = input() a = a.split() c = int(a[0]) for b in range(n-1): c = c + int(a[b+1]) c = c / (4 * m) e = 0 for d in range(n): if int(a[d]) >= c : e = e + 1 if e >= m: print("Yes") else: print("No")
import numpy as np S=input() N=len(S) mod=[0 for i in range(2019)] mod2=0 ten=1 for i in range(N-1,-1,-1): s=int(S[i])*ten mod2+=np.mod(s,2019) mod2=np.mod(mod2,2019) mod[mod2]+=1 ten=(ten*10)%2019 ans=0 for i in range(2019): k=mod[i] if i==0: if k>=2: ans+=k*(k-1)//2+k else: ans+=k else: if k>=2: ans+=k*(k-1)//2 print(ans)
0
null
34,629,491,878,578
179
166
n = list(map(int, list(input()))) k = int(input()) dp0 = [[0]*3]*len(n) dp1 = [[0]*3]*len(n) dp0[0][0] = 1 dp1[0][0] = max(0, n[0]-1) for i in range(1, len(n)): if n[i]==0: dp0[i] = dp0[i-1] else: dp0[i] = [0]+dp0[i-1][:2] dp1[i] = [ dp1[i-1][0]+dp0[i-1][0]*(n[i]!=0)+9, dp1[i-1][1]+dp0[i-1][1]*(n[i]!=0)+dp0[i-1][0]*max(0, n[i]-1)+dp1[i-1][0]*9, dp1[i-1][2]+dp0[i-1][2]*(n[i]!=0)+dp0[i-1][1]*max(0, n[i]-1)+dp1[i-1][1]*9, ] print(dp0[-1][k-1]+dp1[-1][k-1])
S=list(input()) n=len(S) for i in range(n): S[i]=int(S[i]) k=int(input()) dp0=[[0]*(n+1) for i in range(k+1)] dp0[0][0]=1 s=0 for i in range(n): if S[i]!=0: s=s+1 if s==k+1: break dp0[s][i+1]=1 else: dp0[s][i+1]=1 dp1=[[0]*(n+1) for i in range(k+1)] for i in range(1,n+1): if dp0[0][i]==0: dp1[0][i]=1 for i in range(1,k+1): for j in range(1,n+1): if S[j-1]==0: dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1] else: dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1] print(dp0[-1][-1]+dp1[-1][-1])
1
75,849,432,974,660
null
224
224
N,M = map(int,input().split()) A = list(map(int,input().split())) A = sorted(A, reverse=True) if A[M-1]<(sum(A)/(4*M)): print("No") else: print("Yes")
dice = list(map(int, input().split())) command = str(input()) for c in command: if (c == 'S'): ##2651 --> 1265 dice[1],dice[5],dice[4],dice[0] = dice[0],dice[1],dice[5],dice[4] elif(c == 'N'): dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0] elif (c == 'W'): ##4631 -- > 1463 dice[3], dice[5], dice[2],dice[0] = dice[0], dice[3], dice[5], dice[2] else: dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2],dice[0] print(dice[0])
0
null
19,569,736,644,590
179
33
N, M = map(int, input().split()) if N - M == 0 : print('Yes') else : print('No')
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M = map(int, readline().split()) if N == M: print('Yes') else: print('No') return if __name__ == '__main__': main()
1
83,484,406,522,266
null
231
231
from fractions import gcd from functools import reduce def l(a,b):return a*b//gcd(a,b) def L(N):return reduce(l,N) n,m=map(int,input().split()) A=list(map(lambda x:int(x)//2,input().split())) a=A[0] c=0 while(a%2==0): a//=2 c+=1 if any([(a%(2**c)==0 and a//(2**c))%2==0 for a in A]): print(0) exit() a=L(A) print((m+a)//(2*a))
N = int(input()) S = list(''.join(input())) t = 1 for i in range(N-1): if S[i]!=S[i+1]: t += 1 print(t)
0
null
135,633,972,818,188
247
293
s,t = input().split() a,b = map(int, input().split()) u = input() if(u == s): a = a-1 else: b = b-1 print(str(a) + " " + str(b))
s, t = input().split() a, b = map(int, input().split()) u = input() print(a - (s == u), b - (t == u))
1
72,230,697,498,758
null
220
220
def main(): N, M = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) def helper(x): p = len(A) - 1 t = 0 for a in A: while p >= 0 and A[p] + a < x: p -= 1 t += p + 1 return t l, r = 0, A[0] * 2 + 1 while r - l > 1: m = (l + r) // 2 if helper(m) > M: l = m else: r = m k = sum(A) p = len(A) - 1 t = (M - helper(l)) * l for a in A: while p >= 0 and A[p] + a < l: k -= A[p] p -= 1 t += a * (p + 1) + k print(t) main()
n, m = map(int, input().split()) l = list(map(int, input().split())) l.sort() import bisect def func(x): C = 0 for p in l: q = x -p j = bisect.bisect_left(l, q) C += n-j if C >= m: return True else: return False l_ = 0 r_ = 2*10**5 +1 while l_+1 < r_: c_ = (l_+r_)//2 if func(c_): l_ = c_ else: r_ = c_ ans = 0 cnt = 0 lr = sorted(l, reverse=True) from itertools import accumulate cum = [0] + list(accumulate(lr)) for i in lr: j = bisect.bisect_left(l, l_-i) ans += i*(n-j) + cum[n-j] cnt += n -j ans -= (cnt-m)*l_ print(ans)
1
108,277,750,520,160
null
252
252
n, k = map(int, input().split()) A = [*map(int, input().split())] for i in range(n-k): print('Yes' if A[i] < A[i+k] else 'No')
[N, K] = [int(i) for i in input().split()] point_list = [int(i) for i in input().split()] for i in range(N): if i >= K: if point_list[i-K] < point_list[i]: print("Yes") else: print("No")
1
7,084,788,787,480
null
102
102
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 998244353 N, S = lr() A = lr() dp = np.zeros(S+1, np.int64) dp[0] = 1 for a in A: prev = dp.copy() dp[a:] += dp[:-a] dp += prev dp %= MOD answer = dp[S] print(answer%MOD)
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=998244353 N,S=MI() A=LI() dp=[[0]*(S+1) for _ in range(N+1)] #dp[i][j]はi番目までで,和がjになるのが何個作れるか. #ただし,その数を使わない場合,選択するかしないか選べるのでダブルでカウント dp[0][0]=1 for i in range(N): #dp[i][0]+=1 for j in range(S+1): dp[i+1][j]+=dp[i][j]*2 dp[i+1][j]%=mod if j+A[i]<=S: dp[i+1][j+A[i]]+=dp[i][j] dp[i+1][j+A[i]]%=mod print(dp[-1][-1]) main()
1
17,659,034,617,644
null
138
138
n=int(input()) A=[] for i in range(n): for _ in range(int(input())): x,y=map(int,input().split()) A+=[(i,x-1,y)] a=0 for i in range(2**n): if all(i>>j&1<1 or i>>x&1==y for j,x,y in A): a=max(a,sum(map(int,bin(i)[2:]))) print(a)
n = list(map(int, list(input()))) n_sum = sum(n) print("Yes" if n_sum % 9 == 0 else "No")
0
null
62,712,465,026,232
262
87
operators = ['+', '-', '*', '/'] stack = list(input().split()) # stack = list(open('input.txt').readline().split()) def calc(ope): c = stack.pop() a = c if c not in operators else calc(c) c = stack.pop() b = c if c not in operators else calc(c) return str(eval(b+ope+a)) print(calc(stack.pop()))
n,m = map(int,input().split()) l=1 if n%2==1: r=n for i in range(m): d=min(abs(l-r),n-abs(l-r)) print(l,r) l+=1 r-=1 else: if n%4==0: r=n-1 else: r=n rev=False for i in range(m): d=min(abs(l-r),n-abs(l-r)) if d == n//2: rev=True l+=1 print(l,r) else: print(l,r) l+=1 r-=1
0
null
14,283,014,392,890
18
162
n,p=map(int,input().split()) s=input() ans=0 if p==2: for i in range(n): if int(s[i])%2==0: ans+=i+1 print(ans) elif p==5: for i in range(n): if int(s[i])%5==0: ans+=i+1 print(ans) else: s=s[::-1] accum=[0]*n d=dict() for i in range(n): accum[i]=int(s[i])*pow(10,i,p)%p for i in range(n-1): accum[i+1]+=accum[i] accum[i+1]%=p accum[-1]%=p #print(accum) for i in range(n): if accum[i] not in d: if accum[i]==0: ans+=1 d[accum[i]]=1 else: if accum[i]==0: ans+=1 ans+=d[accum[i]] d[accum[i]]+=1 #print(d) print(ans)
from collections import Counter import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, P = map(int, readline().split()) S = [int(i) for i in readline().strip()[::-1]] ans = 0 if P == 2 or P == 5: for i, s in enumerate(S): if s % P == 0: ans += N - i print(ans) exit() a = [0] s = 0 for i in range(N): s += S[i] * pow(10, i, P) a.append(s % P) t = Counter(a) ans = 0 for v in t.values(): ans += v * (v-1) // 2 print(ans) if __name__ == "__main__": main()
1
58,095,400,826,720
null
205
205
N, K = [int(i) for i in input().split()] R, S, P = [int(i) for i in input().split()] T = input() def addScore(hand): if hand == 'r': return P elif hand == 's': return R else : return S score = 0 score_flag = [0 for i in range(N)] for l in range(len(T)): if l < K: score += addScore(T[l]) score_flag[l] = 1 else : if T[l] == T[l-K] and score_flag[l-K] == 1: continue else : score += addScore(T[l]) score_flag[l] = 1 print(score)
n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input() me = "" ans = 0 for i in range(n): if t[i] == "r": if i < k: me += "p" ans += p elif me[i-k] != "p": me += "p" ans += p else: if t[i-k] == "p": me += "p" ans += p else: me += "r" elif t[i] == "s": if i < k: me += "r" ans += r elif me[i-k] != "r": me += "r" ans += r else: if t[i-k] == "r": me += "r" ans += r else: me += "s" else: if i < k: me += "s" ans += s elif me[i-k] != "s": me += "s" ans += s else: if t[i-k] == "s": me += "s" ans += s else: me += "p" print(ans)
1
106,867,073,088,540
null
251
251
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import functools import collections, heapq, itertools, bisect import math, fractions import sys, copy def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): N = I() A = LI() C0, C1 = [0] * 60, [0] * 60 for d in range(60): for ai in A: C0[d] += (ai >> d & 1) == 0 C1[d] += (ai >> d & 1) == 1 ans = 0 for (d, (a, b)) in enumerate(zip(C0, C1)): ans = (ans + a * b * (1 << d % MOD)) % MOD print(ans % MOD) if __name__ == '__main__': main()
from sys import stdin input = stdin.readline N, M = map(int, input().split()) friends = [tuple(map(int, inp.strip().split())) for inp in stdin.read().splitlines()] father = [-1] * N def getfather(x): if father[x] < 0: return x father[x] = getfather(father[x]) return father[x] def union(x, y): x = getfather(x) y = getfather(y) if x != y: if father[x] > father[y]: x,y = y,x father[x] += father[y] father[y] = x; for a, b in friends: union(a - 1, b - 1) # print(max(Counter([getfather(i) for i in range(N)]).values())) print(max([-father[getfather(i)] for i in range(N)] or [0]) )
0
null
63,180,687,102,390
263
84
import numpy as np N = int(input()) A = np.array([int(i) for i in input().split()]) A_sort = np.sort(A) #print(A_sort) score = 0 score += A_sort[-1] for i in range(0, (N-2)//2): score += A_sort[-2-i] * 2 if (N-2) % 2 == 1: score += A_sort[-3-i] print(score)
def main(): n = int(input()) A = list(map(int,input().split())) A.sort(reverse=True) k = n//2 if n%2==0: print(A[0]+2*sum(A[1:k])) else: print(A[0]+2*sum(A[1:k])+A[k]) main()
1
9,169,676,514,150
null
111
111
s = input().split("hi") f = 0 for i in s: if i != "": f = 1 break if f == 0: print("Yes") else: print("No")
N = int(input()) ans = '' while N: N -= 1 N, mod = divmod(N, 26) ans += chr(ord('a') + mod) print(ans[::-1])
0
null
32,645,363,449,332
199
121
# https://atcoder.jp/contests/abc154/tasks/abc154_e def digit(N, M): """ :param N: 0 <= n <= N の整数 (※ 下限が 1 の場合は返り値を -= 1 等する) :param M: 状態数(例: 0<= (0の個数) <= M) dp[0][i][*]: 上からi桁目までが N と一致 dp[1][i][*]: 上からi桁目までで N である事が確定 dp[*][*][j]: 状態 j の個数(今回は j = (0 の個数) ) """ def f(j,k): """状態 j からの繊維。 i+1 桁目の数( = j)に依存""" return min2(j + (k != 0), M - 1) L = len(N) dp = [[[0] * M for i in range(L + 1)] for j in range(2)] dp[0][0][0] = 1 for i in range(L): for j in range(M): for k in range(10): if k < N[i]: dp[1][i+1][f(j, k)] += dp[0][i][j] + dp[1][i][j] elif k == N[i]: dp[0][i+1][f(j, k)] += dp[0][i][j] dp[1][i+1][f(j, k)] += dp[1][i][j] else: dp[1][i+1][f(j, k)] += dp[1][i][j] return dp[0][L][K] + dp[1][L][K] ########################################################################################## N = list(map(int, input().strip())) # 整数を桁毎のリストとして読み込む K = int(input()) M = K + 2 # 状態数 def min2(x,y): return x if x < y else y print(digit(N, M))
import math import itertools n = int(input()) k = int(input()) f = len(str(n)) if f < k: print(0) else: #f-1桁以内に収まる数 en = 1 for i in range(k): en *= f-1-i de = math.factorial(k) s = en // de * pow(9, k) #f桁目によって絞る kami = int(str(n)[0]) en = 1 for i in range(k-1): en *= f-1-i de = math.factorial(k-1) s += (en // de * pow(9, k-1)) * (kami-1) #以下上1桁は同じ数字 keta = list(range(f-1)) num = list(range(1,10)) b = kami * pow(10, f-1) m = 0 if k == 1: m = b if m <= n: s += 1 else: for d in itertools.product(num, repeat=k-1): for c in itertools.combinations(keta, k-1): m = b for i in range(k-1): m += d[i] * pow(10, c[i]) if m <= n: s += 1 print(s)
1
75,784,857,787,872
null
224
224
n,k = map(int,input().split()) a = list(map(lambda x: (int(x)-1)%k ,input().split())) sum_a = sum(a)%k left = [0] * (n+1) right = [0] * (n+1) for i,num in enumerate(a,1): left[i] = (left[i-1] + num)%k for i,num in enumerate(a[::-1],1): right[-i-1] = (right[-i] + num)%k from collections import defaultdict right_d = defaultdict(int) right_d_over = defaultdict(int) ans = 0 for i in range(n,-1,-1): ans += right_d[(sum_a - left[i])%k] - right_d_over[(sum_a - left[i])%k] right_d[right[i]] += 1 if( (n-i+1) >= k ): right_d_over[right[i+k-1]] += 1 print(ans)
def main(): N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] v = {0: 1} n = [0] r = 0 t = 0 for i, a in enumerate(A, 1): if i >= K: v[n[i - K]] -= 1 t += a j = (t - i) % K r += v.get(j, 0) v[j] = v.get(j, 0) + 1 n.append(j) return r print(main())
1
137,006,561,769,810
null
273
273
n,m=map(int,input().split()) if(n>m): print("safe") else: print("unsafe")
S=list(input()) s=0 f=0 g=0 h=0 for i in range(len(S)): if S[i]==">": g=0 f+=1 if h>=f: s+=f-1 else: s+=f else: f=0 g+=1 s+=g h=g print(s)
0
null
92,726,430,748,722
163
285
H,W,N=[int(input()) for i in range(3)] print((N+max(H,W)-1)//max(H,W))
H = int(input()) W = int(input()) N = int(input()) cnt=wcnt=hcnt=0 while N>0: a = max(H-hcnt, W-wcnt) N -= a cnt+=1 if a==W: H-=1 hcnt+=1 elif a==H: W-=1 wcnt+=1 print(cnt)
1
88,344,590,056,052
null
236
236
a=input() b=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=="3" and b=="2")or(a=="2" and b=="3"): print("1")
l = input().split() print(int(l.index('0'))+1)
0
null
62,339,550,261,380
254
126
N = int(input()) ans = 10**N -9**N *2 + 8**N ans %= (10**9+7) print(ans)
import math n = int(input()) mod = 1000000007 all = pow(10, n, mod) s1 = 2 * pow(9, n, mod) % mod s2 = pow(8, n, mod) % mod ans = int(all - s1 + s2)%mod if ans < 0: ans += mod print(ans%mod)
1
3,188,909,546,990
null
78
78
import collections import sys import math sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) def NIJIGEN(H): return [list(input()) for i in range(H)] K=int(input()) if K%2==0 or K%5==0: print(-1) ans=7%K for i in range(K): if ans==0: print(i+1) exit() ans=((ans*10)+7)%K
k = int(input()) svn = 7 cnt = 1 for i in range(10**7): svn %= k if svn == 0: print(cnt) exit() svn *= 10 svn += 7 cnt += 1 print(-1)
1
6,159,398,703,932
null
97
97
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()
n = input() sum = 0; for i in n: sum += int(i) if sum % 9 == 0: print('Yes') else: print('No')
0
null
15,085,891,746,300
156
87
import sys read = sys.stdin.read readlines = sys.stdin.readlines from itertools import accumulate from bisect import bisect def main(): n, m, k = map(int, input().split()) a = tuple(map(int, input().split())) b = tuple(map(int, input().split())) aa = [0] + list(accumulate(a)) ba = [0] + list(accumulate(b)) r = 0 for i1, aae in enumerate(aa): if aae > k: break else: time_remain = k - aae b_num = bisect(ba, time_remain) r = max(r, i1 + b_num - 1) print(r) if __name__ == '__main__': main()
import math k, x = map(int, input().split(" ")) if 500 * k >= x: print("Yes") else: print("No")
0
null
54,578,909,503,780
117
244
m_one = list(map(int, input().split())) m_two = list(map(int,input().split())) print(1 if m_one[1] > m_two[1] else 0)
a=input().split() b=input().split() if a[0] != b[0]: print("1") else: print("0")
1
124,367,825,403,972
null
264
264
def main(): N = int(input()) l = list(map(int, input().split())) ans = 0 m = 10**9 + 7 for i in range(60): x = 0 for j in l: x += 1 & j >> i tmp = x * (N - x) % m tmp *= 2 ** i % m ans += tmp ans %= m print(ans) if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = map(int, read().split()) ans = 0 p = 1 for _ in range(60): n = 0 for i in range(N): A[i], d = A[i] // 2, A[i] % 2 n += d ans = (ans + n * (N - n) * p) % MOD p = p * 2 % MOD print(ans) return if __name__ == '__main__': main()
1
122,834,607,669,312
null
263
263
import sys input = lambda: sys.stdin.readline().rstrip() def main(): print(10 - int(input()) // 200) if __name__ == '__main__': main()
import sys readline = sys.stdin.readline X = int(readline()) limit = 600 rank = 8 for i in range(8): if X < limit: print(rank) break limit += 200 rank -= 1
1
6,724,581,064,418
null
100
100
def insertionSort(lst, n): for i in range(1, n): v = lst[i] j = i - 1 while j >= 0 and lst[j] > v: lst[j+1] = lst[j] j = j - 1 lst[j+1] = v print(" ".join([str(n) for n in lst])) if __name__ == "__main__": n = int(input()) lst = [int(n) for n in input().split()] print(" ".join([str(n) for n in lst])) insertionSort(lst, n)
n,p = map(int,input().split()) s = input() ans = 0 if p == 2 or p == 5: for i,c in enumerate(s,1): if int(c)%p == 0: ans += i else: cnt = [0]*p cnt[0] = 1 x = 0 d = 1 for c in s[::-1]: x += d*int(c) x %= p cnt[x%p] += 1 d *= 10 d %= p # print(cnt) for v in cnt: ans += v*(v-1)//2 print(ans)
0
null
28,948,678,592,798
10
205
(a, b) = tuple([int(i) for i in input().split(' ')]) d = int(a / b) r = a % b f = a / b print('{0} {1} {2:.8f}'.format(d, r, f))
a, b = map(int, raw_input().split()) d = a / b r = a % b f = a * 1.0 / b print '%d %d %f' % (d,r,f)
1
590,843,618,280
null
45
45
import sys sys.setrecursionlimit(10**9) INF = 10**20 def main(): H,N = map(int,input().split()) A,B = [],[] for _ in range(N): a,b = map(int,input().split()) A.append(a) B.append(b) tp = 3 * 10**4 dp = [INF] * tp dp[0] = 0 ans = INF for h in range(tp): minim = INF for i in range(N): dp_i = h-A[i] if dp_i >= 0 and dp[dp_i] != INF: minim = min(minim,dp[dp_i]+B[i]) # print(dp[h-A[i]]+B[i]) if minim != INF: dp[h] = minim if h >= H: ans = min(ans,dp[h]) print(ans) if __name__ == "__main__": main()
HP, n = map(int, input().split()) AB = [list(map(int,input().split())) for _ in range(n)] # DP ## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト ## DPの初期化 DP = [float('inf')] * (HP+1); DP[0] = 0 ## HP分だけDPを回す. for now_hp in range(HP): ## 全ての魔法について以下を試す. for damage, cost in AB: ### 与えるダメージは、現在のダメージ量+魔法のダメージか体力の小さい方 next_hp = min(now_hp+damage, HP) ### 今の魔法で与えるダメージ量に必要な最小コストは、-> ####->現在わかっている値か今のHPまでの最小コスト+今の魔法コストの小さい方 DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost) print(DP[-1])
1
81,181,385,242,148
null
229
229
N = int(input()) L = list(map(int, input().split())) count = 0 L_sort = sorted(L) length = len(L_sort) # 最長辺以外の辺の長さの和 > 最長辺の辺の長さ のとき三角形が成り立つ for i in range(0, length-2): for j in range(i+1, length-1): if L_sort[i] == L_sort[j]: continue for k in range(j+1, length): if L_sort[j] == L_sort[k]: continue if L_sort[i] + L_sort[j] > L_sort[k]: count += 1 print(count)
# string # a, b, c = input().split() # str_list = list(input().split()) # number # a, b, c = map(int, input().split()) # num_list = list(map(int, input().split())) # lows # str_list = [input() for _ in range(n)] # many inputs # num_list = [] # for i in range(n): num_list.append(list(map(int, input().split()))) n = int(input()) l = list(map(int, input().split())) l.sort(reverse = True) ctr = 0 for i in range(n-2): for j in range(i+1, n-1): if l[i] == l[j]: continue for k in range(j+1, n): if l[j] == l[k]: continue if l[i] < l[j] + l[k]: ctr += 1 print(ctr)
1
5,038,256,292,612
null
91
91
a,b,c,d = map(int,input().split()) while a > 0 and c > 0 : c -= b a -= d if c <= 0 : print('Yes') else : print('No')
a, b, c, d = map(int, input().split()) for i in range(101): x = c - b*i y = a - d*i if x <= 0: print("Yes") break elif y <= 0: print("No") break
1
29,696,488,133,608
null
164
164
s, t = input().split() a, b = map(int,input().split()) u = input() if s == u: print(a - 1, b) elif t == u: print(a, b - 1)
import os, sys, re, math (S, T) = [n for n in input().split()] (A, B) = [int(n) for n in input().split()] U = input() if U == S: A -= 1 else: B -= 1 print('%s %s' % (A, B))
1
71,763,295,914,940
null
220
220
A, B, K = map(int, input().split()) if K >= A+B: print("0 0") elif K <= A: print("{} {}".format(A-K, B)) elif K > A: print("0 {}".format(B-(K-A)))
import sys import re def judge(a, b, c): if a ** 2 + b ** 2 == c ** 2: return "YES" else: return "NO" #file = sys.argv[1] #lis = open(file, "r").readlines() lis = sys.stdin.readlines() lis.pop(0) for line in lis: edges = map((lambda x: int(x)), re.split(" +", line)) edges.sort() r = judge(edges[0], edges[1], edges[2]) print r
0
null
52,033,076,540,178
249
4
def answer(a: int, b: int) -> str: return min(str(a) * b, str(b) * a) def main(): a, b = map(int, input().split()) print(answer(a, b)) if __name__ == '__main__': main()
# C - Slimes def main(): n = int(input()) s = input() p = '' ans = '' for v in s: if v != p: ans += v p = v else: continue print(len(ans)) if __name__ == "__main__": main()
0
null
126,915,439,716,188
232
293
n = int(input()) a = list(map(int, input().split())) s, mod = sum(a)-a[0], 1000000007 ans = a[0]*s for i in range(1, n): s -= a[i] ans = (ans % mod + ((s % mod) * a[i]) % mod) % mod print(ans % mod)
N=int(input()) K=[int(n) for n in input().split()] S=sum(K) total=0 for i in range(N): S-=K[i] total+=K[i]*S print(total %(10**9+7))
1
3,876,329,452,488
null
83
83
n,k = list(map(int, input().split())) mod = int(1e9+7) def init_cmb(Nmax): #mod = 10**9+7 #出力の制限 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range(2, Nmax + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) return g1, g2 g1,g2 = init_cmb(n+10) def cmb(n, r, modn=mod): if (r < 0 or r > n): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % modn # ci = 0 である個数が m となるような数列の数は、 nCm ×n−m Hm = nCm * n-1Cn-m-1 # 0 <= m < n で足算する ans = 0 for i in range(min(k+1,n)): wk = cmb(n,i) * cmb(n-1, n-i-1) % mod ans = (ans + wk ) % mod print(ans)
def main(): N = int(input()) A = list(map(int, input().split())) for i in A: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: return ("DENIED") return ("APPROVED") print(main())
0
null
67,857,367,124,710
215
217
n,k=map(int,input().split()) a=list(map(int,input().split())) if n<=k: print(0) else: a=sorted(a) b=n-k ans=0 for x in range(n-k): ans+=a[x] print(ans)
def solve(N, X, M): x = X table = [-1] * M a = [] length = 0 # ループするまで配列に値を入れていく while table[x] == -1: a.append(x) table[x] = length length += 1 x = x**2 % M # ループの開始位置とループの合計値を求める start = table[x] loop_total = 0 for i in range(table[x], length): loop_total += a[i] # 答えの計算 ans = 0 if N <= length: for i in range(N): ans += a[i] else: # フルで何周するかを計算 count = N - start count //= (length-start) ans += count * loop_total count *= (length-start) count = N - count for i in range(count): ans += a[i] return ans if __name__ == "__main__": N, X, M = map(int, input().split()) print(solve(N, X, M))
0
null
40,844,335,246,558
227
75
#coding:utf-8 n,m=list(map(int,input().split())) A,b=[],[] for i in range(n): A.append(list(map(int,input().split()))) for j in range(m): b.append(int(input())) ans=[0 for i in range(n)] for i in range(n): for j in range(m): ans[i]+=A[i][j]*b[j] for i in ans: print(i)
n, m = map(int, raw_input().split()) a, b = [], [] c = [0 for _ in range (n)] for _ in range(n): a.append(map(int, raw_input().split())) for _ in range(m): b.append(int(raw_input())) for i in range(n): c[i] = 0 for j in range(m): c[i] += a[i][j]*b[j] print c[i]
1
1,175,943,207,570
null
56
56
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) R, C, K = mapint() dp = [[[0]*C for _ in range(R)] for _ in range(4)] from collections import defaultdict dic = [[0]*C for _ in range(R)] for _ in range(K): r, c, v = mapint() dic[r-1][c-1] = v for r in range(R): for c in range(C): v = dic[r][c] for i in range(4): if c!=0: dp[i][r][c] = dp[i][r][c-1] if r!=0: dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c]) for i in range(2, -1, -1): dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) ans = 0 for i in range(4): ans = max(ans, dp[i][R-1][C-1]) print(ans)
n=int(input()) arr=list(map(int,input().split())) if n%2==0: ans=-10**18 dp=[[0]*2 for _ in range(n+10)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) ans=max(ans,dp[n-1][0],dp[n][1]) dp=[[0]*2 for _ in range(n+10)] for i in range(1,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) ans=max(ans,dp[n][0]) print(ans) else: ans=-10**18 dp=[[0]*3 for _ in range(n+10)] for i in range(n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n-2][0],dp[n-1][1],dp[n][2]) dp=[[0]*3 for _ in range(n+10)] for i in range(1,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n-1][0],dp[n][1]) dp=[[0]*3 for _ in range(n+10)] for i in range(2,n): dp[i+1][0]=dp[i-1][0]+arr[i] dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i]) dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i]) ans=max(ans,dp[n][0]) print(ans)
0
null
21,397,813,421,380
94
177
line = list(map(int, input().split())) kyori = line[0] lim = line[1] speed = line[2] ans = kyori/speed if ans <= lim: print("Yes") else: print("No")
D, T, S = input().split() D = int(D) T = int(T) S = int(S) if D <= (T*S): print("Yes") else: print("No")
1
3,546,720,979,280
null
81
81
N, K = map(int, input().split()) MOD = 10**9 + 7 cnt = [0] * (K + 1) def calc(x): M = K // x c = pow(M, N, MOD) for i in range(x + x, K + 1, x): c -= cnt[i] cnt[x] = c return c * x ans = 0 for x in range(1, K + 1)[::-1]: ans = (ans + calc(x)) % MOD print(ans)
import sys n = int(raw_input()) #n = 30 for i in range(1, n+1): if i % 3 == 0: sys.stdout.write(" {:}".format(i)) elif str(i).find('3') > -1: sys.stdout.write(" {:}".format(i)) print("")
0
null
18,931,871,113,120
176
52
# -*- coding:utf-8 -*- n = int(input()) s='' for i in range(1,n+1): if i%3==0 or i%10==3: s = s + " " + str(i) continue else: x = i while x >0: x //= 10 if x%10==3: s = s + " " + str(i) break print(s)
import itertools def LI(): return tuple(map(int, input().split())) N = int(input()) P = LI() Q = LI() Nlist = list(range(1, N+1)) count = 1 for v in itertools.permutations(Nlist, N): if P == v: p = count if Q == v: q = count count += 1 print(abs(p-q))
0
null
50,959,201,313,460
52
246
import heapq n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() f = list(map(int, input().split())) f.sort(reverse=True) asum = sum(a) def test(x): t = [min(a[i], x//f[i]) for i in range(n)] return asum - sum(t) ng = -1 ok = 10**13 while abs(ok-ng)>1: mid = (ok+ng)//2 if test(mid) <= k: ok = mid else: ng = mid print(ok)
def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr N = int(input()) fac = factorization(N) result = 0 for div in fac: if div[0] == 1: continue i = 1 count = 1 while i <= div[1]: result += 1 count += 1 i += count print(result)
0
null
91,235,356,721,220
290
136
n = int(input()) print(int(n/2)+n%2)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(read()) print((N + 1) // 2)
1
59,354,533,563,128
null
206
206
N,M = map(int,input().split()) C = list(map(int,input().split())) INF = float('inf') dp = [INF] * (N+1) dp[0] = 0 for i in range(M): c = C[i] for j in range(N+1): if j >= c: dp[j] = min(dp[j], dp[j-c]+1) print(dp[N])
import os from functools import lru_cache import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = list(map(int, sys.stdin.readline().split())) C = list(map(int, sys.stdin.readline().split())) @lru_cache(maxsize=None) def solve(n): if n == 0: return 0 if n < 0: return IINF ret = IINF for c in C: ret = min(ret, solve(n - c) + 1) return ret print(solve(N))
1
139,532,966,330
null
28
28
import sys input = sys.stdin.readline def main(): N, K = map(int, input().split()) H = list(map(int, input().split())) H.sort(reverse=True) if K >= N: print(0) else: ans = sum(H[K:]) print(ans) if __name__ == '__main__': main()
n,k = map(int,input().split()) h = [0 for _ in range(n)] h = [int(s) for s in input().split()] h.sort() #print(h) if(n-k <= 0): ans = 0 else: h_new = h[:n-k] #print(h_new) ans = sum(h_new) print(ans)
1
78,896,251,156,820
null
227
227
# -*- config: utf-8 -*- if __name__ == '__main__': hills = [] for i in range(10): tmp = raw_input() hills.append(int(tmp)) hills.sort(reverse=True) for i in range(3): print hills[i]
print("\n".join(map(str,sorted([int(input())for _ in[0]*10])[:-4:-1])))
1
20,607,772
null
2
2
A,B = list(map(int, input().split())) list_A = [] list_B = [] for i in range(A): a = list(map(int, input().split())) list_A.append(a) for i in range(B): b = int(input()) list_B.append(b) for i in list_A: output = [] for (y,z) in zip(i,list_B): op = y*z output.append(op) sum_op = sum(output) print(sum_op)
# -*- coding: utf-8 -*- import sys import os def input_to_list(): return list(map(int, input().split())) H, W = input_to_list() M = [] for i in range(H): M.append(input_to_list()) v = [] for i in range(W): v.append(int(input())) # M x v for i in range(H): all = 0 for j in range(W): all += M[i][j] * v[j] print(all)
1
1,175,553,821,750
null
56
56
S = input() T = input() ans = 1001 for i in range(len(S)-len(T)+1): ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T)))) print(ans)
#!/usr/bin/env python3 import sys def solve(S: str, T: str): min_change = 100000000 S = [s for s in S] T = [t for t in T] for i, s in enumerate(S): for j, t in enumerate(T): if j == 0: c = 0 if len(S) <= i + j: break if S[i+j] != t: c += 1 if len(T) == j + 1: min_change = min(min_change, c) print(min_change) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str T = next(tokens) # type: str solve(S, T) if __name__ == '__main__': main()
1
3,697,949,435,558
null
82
82
# coding: utf-8 import sys from collections import deque sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def main(): # 左からgreedyに N, D, A = lr() monsters = [] for _ in range(N): x, h = lr() monsters.append((x, h)) monsters.sort() bomb = deque() answer = 0 attack = 0 for x, h in monsters: while bomb: if bomb[0][0] + D < x: attack -= bomb[0][1] bomb.popleft() else: break h -= attack if h > 0: t = -(-h//A) answer += t bomb.append((x + D, A * t)) attack += A * t print(answer) if __name__ == '__main__': main()
n,m = map(int,input().split()) memo2 = [False for i in range(n)] memo = [0 for i in range(n)] count1,count2 = 0,0 for i in range(m): p,l = input().split() p = int(p)-1 if memo2[p]: continue else: if l == 'WA': memo[p]+=1 else: memo2[p] = True count2 += 1 count1+=memo[p] print(count2,count1)
0
null
88,150,618,529,206
230
240
H,W = map(int,input().split()) if H==1 or W==1: print(1) elif H%2==0 and W%2==0 or H%2==0 and W%2==1 or H%2==1 and W%2==0: print((H*W)//2) else: print(((H*W)+1)//2)
st = input() if st[-1] == "s": st += "es" else: st += "s" print(st)
0
null
26,424,310,242,792
196
71
N = int(input()) S = list() for i in range(N): S.append(input()) judge = ['AC', 'WA', 'TLE', 'RE'] count = [0] * 4 for i in range(N): letter = S[i] ind = judge.index(letter) count[ind] += 1 for i in range(len(judge)): print(judge[i], "x", str(count[i]))
result = [] while True: (m, f, r) = [int(i) for i in input().split()] sum = m + f if m == f == r == -1: break if m == -1 or f == -1: result.append('F') elif sum >= 80: result.append('A') elif sum >= 65: result.append('B') elif sum >= 50: result.append('C') elif sum >= 30: if r >= 50: result.append('C') else: result.append('D') else: result.append('F') [print(result[i]) for i in range(len(result))]
0
null
4,999,911,721,000
109
57
#Is it Right Triangre? n = int(input()) for i in range(n): set = input(). split() set = [int(a) for a in set] #int????????? set.sort() if set[0] ** 2 + set[1] ** 2 == set[2] ** 2: print("YES") else: print("NO")
N = int(input()) A = 0 for i in range(1, N+1): if i%3 > 0 and i%5 > 0: A += i print(A)
0
null
17,551,797,280,692
4
173
ans = -1 a = 0 K = int(input()) if K % 2 == 0: ans = -1 elif K % 5 == 0: ans = -1 else: for i in range(0, K): a = (10 * a + 7) % K if a == 0: ans = i + 1 break print(ans)
n = int(input()) minv = int(input()) maxv = -2*10**9 for i in range(n-1): r = int(input()) maxv = max(maxv,r-minv) minv = min(minv,r) print(maxv)
0
null
3,049,050,185,372
97
13
n, m = [int(el) for el in input().split(' ')] c = [int(el) for el in input().split(' ')] t = [0] + [float('inf') for _ in range(n)] for i in range(m): for j in range(c[i], n+1): t[j] = min(t[j], t[j-c[i]] + 1) print(t[n])
inf=10**9 n,m=map(int,input().split()) C=list(map(int,input().split())) DP=[inf]*(n+1) DP[0]=0 for i in range(n+1): for c in C: if 0<=i+c<=n: DP[i+c]=min(DP[i+c],DP[i]+1) print(DP[n])
1
144,620,898,620
null
28
28
numbers = [int(x) for x in input().split(" ")] a, b = numbers[0], numbers[1] print("{} {} {:.5f}".format((a//b), (a%b), (a/b)))
from math import gcd N = int(input()) A = list(map(int,input().split())) g = A[0] for i in range(1,N): g = gcd(g,A[i]) if g>1: print("not coprime") exit() MAXN = 10**6 + 9 D = [i for i in range(MAXN+1)] p = 2 while(p*p <=MAXN): if D[p]==p: for q in range(2*p,MAXN+1,p): if D[q]==q: D[q]=p p+=1 st = set() for a in A: tmp = set() while(a>1): tmp.add(D[a]) a //=D[a] for p in tmp: if p in st: print("setwise coprime") exit() st.add(p) print("pairwise coprime")
0
null
2,369,554,666,948
45
85
H = int(input()) W = int(input()) N = int(input()) a = max(H, W) print((N+a-1)//a)
N,X,T = map(int, input().split()) if X >= N: print(T) elif N % X == 0: print(N//X*T) else: print((N//X+1)*T)
0
null
46,397,883,998,478
236
86
S = input() T = input() ans = float('inf') for i in range(len(S) - len(T) + 1): s = list(S[i:i + len(T)]) t = list(T) count = 0 for j in range(len(T)): if s[j] != t[j]: count += 1 ans = min(ans, count) print(ans)
num = input() streaks = [] streak = 0 for letter in num: if letter == "R": streak += 1 elif letter != "R": streaks.append(streak) streak = 0 else: streaks.append(streak) print(max(streaks))
0
null
4,348,233,236,392
82
90
def solve(n,s): if "ABC" not in s: return 0 cnt = 0 for i in range(len(s)-2): if "ABC" == s[i:i+3]: cnt+=1 return cnt n = int(input()) s = input() ans = solve(n,s) print(ans)
n = int(input()) s = input() cnt = s.count('ABC') print(cnt)
1
99,473,176,311,222
null
245
245
N = int(input()) A = list(map(int, input().split())) x = 0 for a in A: x ^= a out = [] for a in A: out.append(str(x ^ a)) print(' '.join(out))
N = int(input()) A = list(map(int, input().split())) numbers = [] s = A[0] for i in range(1, N): s = s ^ A[i] for i in range(N): numbers.append(s ^ A[i]) print(*numbers)
1
12,372,875,181,590
null
123
123
N,K=map(int,input().split()) p,c=1,1 while p<=N: p*=K c+=1 print(c-1)
import random def name(x): if len(x) > 20: return name() if len(x) < 3: return name() if x.isupper() == True: return name() if x.isalpha() == False: return name() else: l = list(x) w = random.randint(0, len(x) - 3) y = l[w] z = l.index(y) print(y + l[z+1] + l[z+2]) S=input() name(S)
0
null
39,349,607,371,760
212
130
a = [] while True: num = int(input()) if num == 0: break a.append(num) i=1 for x in a: print('Case {}: {}'.format(i,x)) i += 1
n,t = map(int,input().split()) ab = [list(map(int,input().split())) for _ in range(n)] ab.sort() # 食べるのが早い順にソート # ナップザック問題に落とし込む dp = [[0 for i in range(t+1)]for j in range(n+1)] for i in range(n): ti,vi = ab[i] for j in range(t+1): # 食べたほうがよい(t秒以内かつ満足度が上がるならば) if j + ti <= t: dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi) # 食べなかった場合の最高値を更新 dp[i+1][j] = max(dp[i][j],dp[i+1][j]) ma = 0 for i in range(n): # 最後にi番目の皿を食べることができる ma = max(ma,dp[i][t-1]+ab[i][1]) print(ma)
0
null
75,818,387,439,900
42
282
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()
K = int(input())#asking lenght of string wanted to be shorted S = input()#asking string if len(S)>K:##set that S must be greater than K print (S[:K], "...",sep="")# to print only the K number of the string else: print (S)
1
19,748,075,213,558
null
143
143
n, m, l = [int(x) for x in input().split(" ")] first = [] second = [] for _ in range(n): first.append([int(x) for x in input().split(" ")]) for _ in range(m): second.append([int(x) for x in input().split(" ")]) res = [] for i in range(n): res.append([]) for j in range(l): a = 0 for k in range(m): a +=(first[i][k] * second[k][j]) res[i].append(a) for r in res: print(*r)
buf = str(input()) print(buf.swapcase())
0
null
1,455,176,675,040
60
61
r, c = map(int, input().split()) a = [list(map(int, input().split())) for i in range(r)] newr = [] for i in range(r): a[i].append(sum(a[i])) for j in range(c + 1): sumc = 0 for i in range(r): sumc += a[i][j] newr.append(sumc) a.append(newr) for i in range(r+1): print(" ".join(str(t) for t in a[i]))
l=input().split() r=int(l[0]) c=int(l[1]) # for yoko i=0 b=[] while i<r: a=input().split() q=0 su=0 while q<c: b.append(int(a[q])) su+=int(a[q]) q=q+1 b.append(su) i=i+1 # for tate #x=0 #d=b[0]+b[c+1]+b[2*(c+1)]+b[3*(c+1)] #x<c+1 x=0 while x<c+1: d=0 z=0 while z<r: d+=b[x+z*(c+1)] z+=1 b.append(d) x=x+1 # for output # C=[] # y=0 (for gyou) # z=0 (for yoko) C=[] y=0 while y<r+1: z=0 Ans=str(b[y*(c+1)+z]) while z<c: z+=1 Ans=Ans+" "+str(b[y*(c+1)+z]) C.append(Ans) y+=1 for k in C: print(k)
1
1,347,528,345,770
null
59
59
a=input() b=a.split(" ") c=list(map(int,b)) w=c[0] h=c[1] x=c[2] y=c[3] r=c[4] if((x-r)<0 or (x+r)>w or (y-r)<0 or (y+r)>h): str="No" else : str="Yes" print(str)
W, H, x, y, r = map(int, input().split()) flg = False for X in [x - r, x + r]: for Y in [y - r, y + r]: if not 0 <= X <= W: flg = True if not 0 <= Y <= H: flg = True print(["Yes", "No"][flg])
1
448,024,910,812
null
41
41
import numpy as np import sys N,K = map(int, input().split()) A = np.array(sys.stdin.readline().split(), np.int64) maxa = np.max(A) mina = maxa // (K+1) while maxa > mina + 1: mid = (maxa + mina)// 2 div = np.sum(np.ceil(A/mid-1)) if div > K: mina = mid else: maxa = mid print(maxa)
from collections import Counter n = int(input()) s = [input() for _ in range(n)] data = Counter(s) print(len(data.keys()))
0
null
18,533,567,368,074
99
165
# 最小公倍数(mathは3.5以降) fractions from functools import reduce import fractions #(2020-0405 fractions→math) def lcm_base(x, y): return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする def lcm(*numbers): return reduce(lcm_base, numbers, 1) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) N,M = (int(x) for x in input().split()) A = list(map(int, input().split())) lcm =lcm_list(A) han_lcm =lcm//2 han_lcm_num =M//han_lcm han_lcm_num =(han_lcm_num +1)//2 #偶数を除く #半公倍数がA自身の中にある時は✖ if han_lcm in A: han_lcm_num =0 #半公倍数がaiで割り切れるときは✖ for a in A: if han_lcm % a ==0: han_lcm_num =0 print(han_lcm_num)
import sys input=sys.stdin.readline n,k=map(int,input().split()) INF=10**9+7 l=[0]*k ans=0 for i in range(k-1,-1,-1): x=i+1 temp=pow(k//x,n,INF) for j in range(2,k//x+1): temp=(temp-l[j*x-1])%INF l[i]=temp ans=(ans+x*temp)%INF print(ans)
0
null
69,353,761,595,832
247
176
import sys input = sys.stdin.readline def main(): N, M, L = map(int, input().split()) dist = [[float('inf')] * N for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) if C > L: continue A -= 1 B -= 1 dist[A][B] = C dist[B][A] = C for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) e = [[float('inf')] * N for _ in range(N)] for i in range(N): for j in range(N): if dist[i][j] <= L: e[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): e[i][j] = min(e[i][j], e[i][k] + e[k][j]) Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) s -= 1 t -= 1 if e[s][t] == float('inf'): print(-1) continue ans = e[s][t] print(ans-1) if __name__ == "__main__": main()
# ABC159C # 縦,横,高さの合計が len である直方体のうち,体積が最大のものの体積はいくつか def f(len): print((len / 3) ** 3) f(int(input()))
0
null
110,487,581,116,704
295
191
N=int(input()) print(1000*(N%1000!=0)-N%1000)
print(-int(input())%1000)
1
8,362,143,239,580
null
108
108
s = input() a = [-1] * (len(s) + 1) if s[0] == "<": a[0] = 0 if s[-1] == ">": a[-1] = 0 for i in range(len(s) - 1): if s[i] == ">" and s[i + 1] == "<": a[i + 1] = 0 for i in range(len(a)): if a[i] == 0: l = i - 1 while 0 <= l - 1: if s[l] == ">" and s[l - 1] == ">": a[l] = a[l + 1] + 1 else: break l -= 1 r = i + 1 while r + 1< len(a): if s[r - 1] == "<" and s[r] == "<": a[r] = a[r - 1] + 1 else: break r += 1 for i in range(len(a)): if a[i] == -1: if i == 0: a[i] = a[i + 1] + 1 elif i == len(a) - 1: a[i] = a[i - 1] + 1 else: a[i] = max(a[i - 1], a[i + 1]) + 1 ans = sum(a) print(ans)
def rle(t): tmp2, count_, ans_ = t[0], 1, [] for i_ in range(1, len(t)): if tmp2 == t[i_]: count_ += 1 else: ans_.append([tmp2, count_]) tmp2 = t[i_] count_ = 1 ans_.append([tmp2, count_]) return ans_ S = list(input()) l = rle(S) ans = [0] * (len(S) + 1) count = 0 for i in range(len(l)): if l[i][0] == '<': for j in range(l[i][1] + 1): ans[count + j] = max(ans[count + j], j) elif l[i][0] == '>': for k in range(l[i][1] + 1): ans[count + k] = max(ans[count + k], l[i][1] - k) count += l[i][1] print(sum(ans))
1
155,977,310,218,548
null
285
285
from bisect import bisect_left, bisect_right n = int(input()) stick = list(map(int, input().split())) stick.sort() count = 0 for i in range(n): for j in range(i + 1, n): l = bisect_right(stick, stick[j] - stick[i]) r = bisect_left(stick, stick[i] + stick[j]) # [l, r) が範囲 if j + 1 >= r: continue count += r - max(l, j + 1) print(count)
import bisect N=int(input()) L=list(map(int,input().split())) L=sorted(L) ans=0 for i in range(N-1): for k in range(i+1,N-1): a=L[i]+L[k] b=bisect.bisect_left(L,a) ans=ans+(b-k-1) print(ans)
1
171,900,164,414,160
null
294
294
from sys import stdin from math import pi r = float(stdin.readline().rstrip()) area = pi*r*r circumference = 2*pi*r print("%lf %lf" % (area, circumference))
h,w,k = map(int, input().split()) item = [[0 for _ in range(w)] for _ in range(h)] for i in range(k): y,x,v = list(map(int,input().split())) item[y-1][x-1]=v dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)] for y in range(h): for x in range(w): for i in range(4): if y<h-1: dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x]) if x<w-1: dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x]) if item[y][x]>0: for i in range(3): if y<h-1: dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x]) if x<w-1: dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) ans=[dp[0][-1][-1] + item[-1][-1], dp[1][-1][-1] + item[-1][-1], dp[2][-1][-1] + item[-1][-1], dp[3][-1][-1]] print(max(ans))
0
null
3,078,290,108,010
46
94
string = list(map(str, input())) ans =[] for char in string: if char.islower(): ans.append(char.upper()) elif char.isupper(): ans.append(char.lower()) else: ans.append(char) print(ans[-1], end="") print()
s = input() b = s.swapcase() print(b)
1
1,483,460,895,928
null
61
61
s = input() k = int(input()) m = 0 j = 0 if len(set(list(s))) == 1: print((len(s) * k) // 2) exit() for i in range(len(s)): if len(s) <= j + 1: a = m * k if s[0] == s[-1] == s[len(s) // 3]: print(a + k - 1) else: print(a) break if s[j] == s[j + 1]: m += 1 j += 1 j += 1
S = input() K = int(input()) INNER = 0 if len(set(list(S))) == 1: print(K*len(S)//2) else: i = 0 while i < len(S)-1: if S[i] == S[i+1]: INNER += 1 i += 1 i += 1 if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、 print(INNER*K) else: same_from_start = 0 same_from_end = 0 count_from_start = 0 count_from_end = 0 flag_same_from_start = 0 flag_same_from_end = 0 while flag_same_from_start == 0: if S[count_from_start] == S[count_from_start+1]: count_from_start += 1 else: count_from_start += 1 flag_same_from_start = 1 while flag_same_from_end == 0: if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]: count_from_end += 1 else: count_from_end += 1 flag_same_from_end = 1 print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\ count_from_start//2- count_from_end//2))
1
175,417,789,839,500
null
296
296
A1,A2,A3 = map(int,input().split()) if (A1+A2+A3) >= 22 : print("bust") else : print("win")
a1, a2, a3 = map(int, input().split()) x = a1 + a2 + a3 print('win' if x <= 21 else 'bust')
1
118,355,322,633,380
null
260
260
n = int(raw_input()) a = [] input_line = raw_input().split() for i in input_line: a.append(i) for i in reversed(a): print i,
cnt = int(input()) li = list(map(int,input().split())) re_li = li[::-1] print(' '.join(map(str,re_li)))
1
1,003,222,952,538
null
53
53
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func,M): ok = 0 # exist ng = 4*(10**5) # not exist while abs(ok-ng) > 1: cnt = (ok + ng) // 2 if func(cnt,reva,M): ok = cnt else: ng = cnt return ok def solve1(tgt,reva,M): res=0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva,tgt-reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False N,M = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = (bs.bisect_max(reva,solve1,M)) r=[0] for i in range(N): r.append(r[i]+a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1]) tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1]) if tmp!=tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp*a[i]+r[tmp] if t==1: res -= (cnt-M)*Kmax print(res)
n, x, t = map(int, input().split()) answer = -(-n // x) * t print(answer)
0
null
56,207,189,429,832
252
86
n, k = map(int, input().split()) p = sorted(map(int, input().split())) ans = sum(p[:k]) print(ans)
N = int(input()) A = sorted(list(map(int, input().split()))) #篩 M = 10**6+ 10 c = [0] * M for i in range(N): if c[A[i]-1] >= 1: c[A[i]-1] = c[A[i]-1] + 1 else: for j in range(1, M//A[i] + 1): c[A[i]*j-1] += 1 #チェック ans = 0 for i in range(N): if c[A[i]-1] <= 1: ans += 1 print(ans)
0
null
13,088,466,434,240
120
129
input_data = input().split(" ") items = [int(cont) for cont in input_data] keys = ['T', 'S', 'E', 'W', 'N', 'B'] dice = dict(zip(keys, items)) def q1(): def rot_func_list(rot, dice): if rot == "N": keys = ['T', 'S', 'B', 'N'] items = dice['S'], dice['B'], dice['N'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "S": keys = ['T', 'S', 'B', 'N'] items = dice['N'], dice['T'], dice['S'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "E": keys = ['T', 'E', 'B', 'W'] items = dice['W'], dice['T'], dice['E'], dice['B'] new_dice = dict(zip(keys, items)) dice.update(new_dice) if rot == "W": keys = ['T', 'E', 'B', 'W'] items = dice['E'], dice['B'], dice['W'], dice['T'] new_dice = dict(zip(keys, items)) dice.update(new_dice) controls = list(input()) for i in controls: rot_func_list(i, dice) print(dice["T"]) def q2(): def search_surf(conds, dice): a,b=conds a_key = [k for k, v in dice.items() if v == a ] b_key = [k for k, v in dice.items() if v == b ] key_list = a_key + b_key part_st = ''.join(key_list) def search(part_st): if part_st in "TNBST": return "W" if part_st in "TSBNT": return "E" if part_st in "TEBWT": return "N" if part_st in "TWBET": return "S" if part_st in "NESWN": return "B" if part_st in "NWSEN": return "T" target_key = search(part_st) print(dice[target_key]) a = input() repeater = int(a) for neee in range(repeater): control_input = input().split(" ") conds = [int(i) for i in control_input] search_surf(conds, dice) q2()
class Dice: def __init__(self,u,w,r,s,t,y): self.s1 = u self.s2= w self.s3= r self.s4= s self.s5 = t self.s6= y def right_s3(self): prev_s3 = self.s3 self.s3 = prev_s3 def right_s4(self): prev_s4 = self.s4 self.s3 = prev_s4 def right_s5(self): prev_s5 = self.s5 self.s3 = prev_s5 def right_s6(self): prev_s6 = self.s6 self.s3 = prev_s6 def right_s1(self): prev_s1 = self.s1 self.s3 = prev_s1 def right_s2(self): prev_s2 = self.s2 self.s3 = prev_s2 def top(self): return self.s3 s1,s2,s3,s4,s5,s6 = map(int,input().split()) order = int(input()) for c in range(order): dice = Dice(s1,s2,s3,s4,s5,s6) new_s1 , new_s2 = map(int,input().split()) if (new_s1 == s1 and new_s2 == s2) or (new_s1 ==s2 and new_s2 == s6) or (new_s1 == s6 and new_s2 ==s5) or (new_s1==s5 and new_s2 == s1): dice.right_s3() elif (new_s1 == s1 and new_s2 == s5) or (new_s1 ==s5 and new_s2 == s6) or (new_s1 == s6 and new_s2 ==s2) or (new_s1==s2 and new_s2 == s1): dice.right_s4() elif (new_s1 == s1 and new_s2 == s3) or (new_s1 ==s3 and new_s2 == s6) or (new_s1 == s6 and new_s2 ==s4) or (new_s1==s4 and new_s2 == s1): dice.right_s5() elif (new_s1 == s2 and new_s2 == s4) or (new_s1 ==s4 and new_s2 == s5) or (new_s1 == s5 and new_s2 ==s3) or (new_s1==s3 and new_s2 == s2): dice.right_s6() elif (new_s1 == s2 and new_s2 == s3) or (new_s1 ==s3 and new_s2 == s5) or (new_s1 == s5 and new_s2 ==s4) or (new_s1==s4 and new_s2 == s2): dice.right_s1() elif (new_s1 == s1 and new_s2 == s4) or (new_s1 ==s4 and new_s2 == s6) or (new_s1 == s6 and new_s2 ==s3) or (new_s1==s3 and new_s2 == s1): dice.right_s2() print(dice.top())
1
250,456,163,588
null
34
34
l = input().split() print(l.index('0')+1)
import sys X=map(int, sys.stdin.readline().split()) print X.index(0)+1
1
13,408,482,932,560
null
126
126
class UnionFind: def __init__(self, n): self.n = n self.par = [i for i in range(n+1)] # �?要�?の親要�?の番号を�?�納するリス�? self.rank = [0] * (n+1) self.size = [1] * (n+1) # 根?��ルート)�?�場合、そのグループ�?�要�?数を�?�納するリス�? # 要�? x が属するグループ�?�根を返す def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 要�? x が属するグループと要�? y が属するグループとを併合す�? def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 要�? x, y が同じグループに属するかど�?かを返す def same_check(self, x, y): return self.find(x) == self.find(y) # 要�? x が属するグループに属する要�?をリストで返す def members(self, x): root = self.find(x) return [i for i in range(1,self.n+1) if self.find(i) == root] # 要�? x が属するグループ�?�サイズ?��要�?数?��を返す def get_size(self, x): return self.size[self.find(x)] # すべての根の要�?をリストで返す def roots(self): return [i for i, x in enumerate(self.par) if x == i and i != 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 = map(int,input().split()) uf = UnionFind(n) for i in range(m): a,b = map(int,input().split()) uf.union(a,b) print(len(uf.roots())-1)
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N, M = MI() routes = [] cities = [[] for i in range(N)] for i in range(M): a, b = MI() cities[a-1].append(b-1) cities[b-1].append(a-1) groups = [-1] * N group = 0 for i in range(N): if groups[i] != -1: continue deque = cl.deque([i]) groups[i] = group while len(deque) > 0: city = deque.popleft() next_cities = cities[city] for next_city in next_cities: if groups[next_city] != -1: continue groups[next_city] = group deque.append(next_city) group += 1 print(group - 1) main()
1
2,275,335,987,782
null
70
70
# coding: utf-8 def gcd(a, b): if a < b: a, b = b, a while b: a, b = b, a % b return a def main(): a, b = map(int, raw_input().split()) print gcd(a, b) if __name__ == '__main__': main()
n, m = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for y in range(n)] b = [int(input()) for x in range(m)] c = [] for i in range(n): c.append(sum([a[i][x] * b[x] for x in range(m)])) for i in c: print(i)
0
null
589,677,925,298
11
56
x = int(input()) print('Yes') if x >= 30 else print('No')
X=input() X=int(X) if X >= 30: print('Yes') else: print('No')
1
5,716,300,267,122
null
95
95
from math import atan,pi A,B,X=map(int,input().split()) if 2*X>=A*A*B: P=atan(2*(A*A*B-X)/(A*A*A))*180/pi print(P) else: Q=atan((A*B*B)/(2*X))*180/pi print(Q)
N, X, T = (int(x) for x in input().split()) if N % X == 0: ans = N / X else: ans = N // X + 1 ans = T * ans print("%d" % ans)
0
null
83,907,328,219,140
289
86
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): R, C, K = NMI() grid = make_grid_int(R, C, 0) for i in range(K): r, c, v = NMI() grid[r-1][c-1] = v dp = [[[0 for _ in range(C+2)] for _ in range(R+2)] for _ in range(4)] for r in range(R+1): for c in range(C+1): for i in range(4): now = dp[i][r][c] try: val = grid[r][c] except: val = 0 if i == 3: # 取らずに下 dp[0][r + 1][c] = max(now, dp[0][r + 1][c]) continue # 取って下 dp[0][r+1][c] = max(now + val, dp[0][r+1][c]) # 取らずに下 dp[0][r+1][c] = max(now, dp[0][r+1][c]) # 取って横 dp[i+1][r][c+1] = max(now + val, dp[i+1][r][c+1]) # 取らずに横 dp[i][r][c+1] = max(now, dp[i][r][c+1]) print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) if __name__ == "__main__": main()
def resolve(): R, C, K = map(int, input().split()) G = [[0] * (C+1) for _ in range(R+1)] for _ in range(K): r, c, v = map(int, input().split()) G[r][c] = v DP1 = [0 for _ in range(C + 1)] # c列目までとったとき、最新の行で1個以下とったという条件のもとの最大 DP2 = [0 for _ in range(C + 1)] # c列目までとったとき、最新の行で2個以下とったという条件のもとの最大 DP3 = [0 for _ in range(C + 1)] # c列目までとったとき、最新の行で3個以下とったという条件のもとの最大 for r in range(1, R+1): for c in range(1, C+1): # 更新の順番に注意 # mid = max(DP1[c], DP2[c], DP3[c]) + I[r][c] mid = DP3[c] + G[r][c] DP3[c] = max(DP3[c - 1], mid, DP2[c - 1] + G[r][c]) # 3個 DP2[c] = max(DP2[c - 1], mid, DP1[c - 1] + G[r][c]) # 2個 DP1[c] = max(DP1[c - 1], mid) # 1個 print(DP3[C]) if __name__ == "__main__": resolve()
1
5,604,078,301,108
null
94
94
n = int(input()) print(pow(n, 2))
r=int(input()) print(int(r**2))
1
145,363,660,436,770
null
278
278
# Union-Find class UnionFind(): def __init__(self, n): self.n = n self.parents = [i for i in range(n + 1)] def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return 0 elif x < y: self.parents[y] = x else: self.parents[x] = y return 1 from collections import Counter n, m = map(int, input().split()) uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.unite(a, b) roots = [] for num in uf.parents: roots.append(uf.find(num)) count_roots = Counter(roots) print(len(count_roots)-2)
N = int(input()) S = input() total = S.count("R") * S.count("G") * S.count("B") sub = 0 for i in range(N): for j in range(i + 1, N): if S[i] == S[j]: continue h = j + j - i if h > N - 1 or S[j] == S[h] or S[h] == S[i]: continue sub += 1 print(total - sub)
0
null
19,337,718,712,520
70
175
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 ans=0 N=I() for a in range(1,N): for b in range(1,N): if a*b>=N: break ans+=1 print(ans) main()
def insertion_sort(data, g): global cnt for i in range(g, len(data)): v, j = data[i], i - g while j >= 0 and data[j] > v: data[j + g] = data[j] j = j - g cnt += 1 data[j + g] = v def shell_sort(data): global G for i in range(1, 100): tmp = (3 ** i - 1) // 2 if tmp > len(data): break G.append(tmp) for g in list(reversed(G)): insertion_sort(data, g) G, cnt = [], 0 n = int(input()) data = list(int(input()) for _ in range(n)) shell_sort(data) print(len(G)) print(' '.join(map(str, list(reversed(G))))) print(cnt) print('\n'.join(map(str, data)))
0
null
1,288,738,611,930
73
17
S = input() l_s = len(S) cnt = 0 for i in range(0,l_s//2): if S[i] != S[-i-1]: cnt += 1 print(cnt)
X, N = map(int, input().split()) P = list(map(int, input().split())) st = set(P) for i in range(111): if not X - i in st: print(X - i) exit(0) if not X + i in st: print(X + i) exit(0)
0
null
66,945,481,440,924
261
128
n = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(n): s = input() if s == "AC": c0 += 1 elif s == "WA": c1 += 1 elif s == "TLE": c2 += 1 elif s == "RE": c3 += 1 else: exit() print(f"AC x {c0}") print(f"WA x {c1}") print(f"TLE x {c2}") print(f"RE x {c3}")
N = int(input()) S = [""]*N Dict={} ac=0 wa =0 tle =0 re=0 for i in range(N): S[i] = str(input()) for j in S: if j in Dict: temp = Dict[j] Dict[j] = temp + 1 else: Dict[j] = 1 if "AC" in Dict: ac = Dict["AC"] if "WA" in Dict: wa = Dict["WA"] if "TLE" in Dict: tle = Dict["TLE"] if "RE" in Dict: re = Dict["RE"] print("AC x " , ac) print("WA x " , wa) print("TLE x " , tle) print("RE x " , re)
1
8,669,471,971,530
null
109
109
a = input() if(a[0]=='7' or a[1]=='7' or a[2]=='7'): print("Yes") else: print("No")
# local search is all you need # 「日付 d とコンテストタイプ q をランダムに選び、d 日目に開催するコンテストをタイプ q に変更する」 # このデメリット→変化させる量が小さすぎるとすぐに行き止まり (局所最適解) に陥ってしまい、逆に、変化させる量が 大きすぎると闇雲に探す状態に近くなって、改善できる確率が低くなってしまう。 # 今回ならば、開催日が全体的に遠すぎず近すぎない感じのlocal minimumに収束する∵d日目のコンテストをi→jに変更したとする。iの開催期間はすごく伸びると2乗でスコアが下がるため、iの開催期間が比較的近いところのiしか選ばれない # →じゃ2点スワップを導入して改善してみよう # あといっぱい回すためにinitやscoreも若干高速化 from time import time t0 = time() import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(read()) def ints(): return list(map(int, read().split())) def read_col(H): '''H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合''' ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from random import randint, random def score(D, C, S, T): '''2~3*D回のループでスコアを計算する''' # last = [-1] * 26 date_by_contest = [[-1] for _ in range(26)] for d, t in enumerate(T): date_by_contest[t].append(d) for i in range(26): date_by_contest[i].append(D) # 番兵 # print(*date_by_contest, sep='\n') score = 0 for d in range(D): score += S[d][T[d]] for c, dates in enu(date_by_contest): for i in range(len(dates) - 1): dd = (dates[i + 1] - dates[i]) # for ddd in range(dd): # score -= C[c] * (ddd) score -= C[c] * (dd - 1) * dd // 2 return score D = a_int() C = ints() S = read_tuple(D) def maximizer(newT, bestT, bestscore): tmpscore = score(D, C, S, newT) if tmpscore > bestscore: return newT, tmpscore else: return bestT, bestscore def ret_init_T(): '''greedyで作ったTを初期値とする。 return ---------- T, score ... 初期のTとそのTで得られるscore ''' def _make_T(n_days): # editorialよりd日目の改善は、改善せずにd+n_days経過したときの関数にしたほうが # 最終的なスコアと相関があるんじゃない? T = [] last = [-1] * 26 for d in range(D): ma = -INF for i in range(26): tmp = S[d][i] dd = d - last[i] tmp += C[i] * (((dd + n_days + dd) * (n_days) // 2)) if tmp > ma: t = i ma = tmp last[t] = d # Tを選んだあとで決める T.append(t) return T T = _make_T(2) sco = score(D, C, S, T) for i in range(3, 16): T, sco = maximizer(_make_T(i), T, sco) return T, sco bestT, bestscore = ret_init_T() def add_noise(T, thre_p, days_near): '''確率的にどちらかの操作を行う 1.日付dとコンテストqをランダムに選びd日目に開催するコンテストのタイプをqに変更する 2.10日以内の点でコンテストを入れ替える thre_pはどちらの行動を行うかを調節、days_nearは近さのパラメータ''' ret = T.copy() if random() < thre_p: d = randint(0, D - 1) q = randint(0, 25) ret[d] = q return ret else: i = randint(0, D - 2) j = randint(i - days_near, i + days_near) j = max(j, 0) j = min(j, D - 1) if i == j: j += 1 ret[i], ret[j] = ret[j], ret[i] return ret while time() - t0 < 1.92: bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) bestT, bestscore = maximizer(add_noise(bestT, 0.8, 8), bestT, bestscore) # print(bestscore) # print(score(D, C, S, T)) print(*mina(*bestT, sub=-1), sep='\n')
0
null
21,962,957,767,708
172
113
h,w,k=map(int,input().split()) board=[list(input()) for _ in range(h)] acum=[[0]*w for _ in range(h)] def count(x1,y1,x2,y2): #事前に求めた2次元累積和を用いて左上の点が(x1,y1)、右下の点(x2,y2)の長方形に含まれる1の個数を数える ret=acum[y2][x2] if x1!=0: ret-=acum[y2][x1-1] if y1!=0: ret-=acum[y1-1][x2] if x1!=0 and y1!=0: ret+=acum[y1-1][x1-1] return ret for i in range(h): #2次元累積和により左上の点が(0,0)、右下の点が(j,i)の長方形に含まれる1の個数を数える for j in range(w): if board[i][j] == '1': acum[i][j]+=1 if i!=0: acum[i][j]+=acum[i-1][j] if j!=0: acum[i][j]+=acum[i][j-1] if i!=0 and j!=0: acum[i][j]-=acum[i-1][j-1] ans = 10**18 for i in range(2**(h-1)): cnt = 0 list = [] flag = format(i,'b')[::-1] # '1'と'10'と'100'の区別のために必要 #print(flag) for j in range(len(flag)): if flag[j] == '1': # ''をつける! cnt += 1 list.append(j) list.append(h-1) #print(list) x1 = 0 for x2 in range(w-1): #x1(最初は0)とx1+1の間からx=w-1とx=wの間までの区切り方をそれぞれ確かめる y1 = 0 for y2 in list: #長方形のブロックの右下の点のy座標の候補をすべて試す if count(x1,y1,x2,y2) > k: #ある横の区切り方の下で、どのように縦を区切ってもブロックに含まれる1の個数がKより大きくなるとき、条件を満たす切り分け方は存在しない cnt += 10**18 if count(x1,y1,x2,y2) <= k and count(x1,y1,x2+1,y2) > k: #ある位置でブロックを区切ると1の個数がK以下になるが、区切る位置を1つ進めると1の個数がKより大きくなるとき、その位置で区切る必要がある cnt += 1 x1 = x2+1 #ある位置x2で区切ったとき、次からはx2+1を長方形のブロックの左上の点のx座標として見ればよい break y1 = y2+1 #(いま見ているブロックの右下の点のy座標)+1が次に見るブロックの左上の点のy座標に等しくなる y1 = 0 for y2 in list: if count(x1,y1,w-1,y2) > k: #最後に縦で区切った位置以降で、あるブロックに含まれる1の個数がKより大きくなるとき、条件を満たすような区切り方は存在しない cnt += 10**18 break y1 = y2+1 ans = min(ans,cnt) print(ans)
N = int(input()) lists= [] for i in range(N): a,b = [x for x in input().split()] lists.append([a,int(b)]) X = input() add_time = False add = 0 for i in range(N): if add_time == True: add += lists[i][1] if X == lists[i][0]: add_time = True print(add)
0
null
72,435,737,462,692
193
243
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, T = lr() AB = [lr() for _ in range(N)] AB.sort() # 時間のかかる物は後ろへ dp = np.zeros(T, np.int64) answer = 0 for a, b in AB: answer = max(answer, dp.max() + b) prev = dp dp[a:] = np.maximum(prev[a:], prev[:-a] + b) print(answer)
def gcd(x, y): if y == 0: return x else: return gcd(y, x % y) def main(): l, r = tuple(map(int, input().split(' '))) print(gcd(l, r)) main()
0
null
75,578,043,266,848
282
11
def solve(string): _, c = string.split() r = c.count("R") return str(c[:r].count("W")) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
n = int(input()) c = list(input()) r = 0 w = 0 for i in range(len(c)): if(c[i]=="R"): r += 1 ans = max(r,w) for i in range(len(c)): if(c[i]=="R"): r -= 1 else: w += 1 now = max(r,w) ans = min(ans,now) print(ans)
1
6,298,284,305,170
null
98
98
xyz = list(map(int,input().split())) xyz[0] ,xyz[1] = xyz[1],xyz[0] xyz[0], xyz[2] = xyz[2], xyz[0] print(*xyz)
X,Y,Z = map(int,input().split()) X,Y = Y,X X,Z = Z,X print(X,Y,Z,sep=" ")
1
38,126,148,430,854
null
178
178
# coding: utf-8 import sys from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np #import queue# queue,get(), queue.put() def run(): N = int(input()) current = 0 ways = [] dic = {'(': 1, ')': -1} SS = read().split() for S in SS: path = [0] for s in S: path.append(path[-1]+ dic[s]) ways.append((path[-1], min(path))) ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:x[0], reverse=True) ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[0] - x[1]), reverse=True) tmp = [] for go, max_depth in ways_pos: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None tmp =[] for go, max_depth in ways_neg: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None if current == 0: print('Yes') else: print('No') if __name__ == "__main__": run()
#coding:utf-8 H,W=map(int,input().split()) while not(H==0 and W==0): for i in range(0,H): for j in range(0,W): print("#",end="") print("") print("") H,W=map(int,input().split())
0
null
12,233,768,793,802
152
49