code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
H,W,M = map(int,input().split()) hlist = [0]*H wlist = [0]*W sets = set() for i in range (M): h,w = map(lambda x: int(x)-1,input().split()) hlist[h]+=1 wlist[w]+=1 sets.add((h,w)) hmax = 0 hind = [] for i in range(H): if hmax < hlist[i]: hmax = hlist[i] hind = [i] elif hmax == hlist[i]: hind.append(i) wmax = 0 wind = [] for i in range(W): if wmax < wlist[i]: wmax = wlist[i] wind = [i] elif wmax == wlist[i]: wind.append(i) flag = False for h in hind: for w in wind: if (h,w) not in sets: flag = True break if flag: break if flag: print(hmax + wmax) else: print(hmax + wmax - 1)
h,w,m = map(int,input().split()) hw = [list(map(int,input().split())) for i in range(m)] hb = [0] * h wb = [0] * w for i in range(m): hb[hw[i][0]-1] += 1 wb[hw[i][1]-1] += 1 max_h = max(hb) max_w = max(wb) ans = max_h + max_w count = hb.count(max_h) * wb.count(max_w) for i in range(m): if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w: count -= 1 if count <= 0: ans -= 1 print(ans)
1
4,646,615,615,200
null
89
89
N, A, B = map(int, input().split()) temp = N // (A+B) temp2 = N % (A + B) temp2 = min(temp2, A) print(temp*A + temp2)
n,a,b = map(int,input().split()) cnt = n//(a+b) rem = n-cnt*(a+b) ans = cnt*a if(rem > a): ans += a else: ans += rem print(ans)
1
55,857,061,609,120
null
202
202
if any(x == '7' for x in input()): print('Yes') else: print('No')
H, A = (int(x) for x in input().split()) dm = divmod(H,A) if dm[1] == 0: print(dm[0]) else: print(dm[0]+1)
0
null
55,558,554,711,660
172
225
N = list(input().split()) A = int(N[0]) b1,b2 = N[1].split('.') B = int(b1+b2) prd = list(str(A*B)) ans = 0 if len(prd) < 3: ans = 0 else: prd.pop() prd.pop() ans = int(''.join(prd)) print(ans)
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, *D = map(int, read().split()) ans = 0 for i in range(N): for j in range(i + 1, N): ans += D[i] * D[j] print(ans) return if __name__ == '__main__': main()
0
null
92,457,922,434,148
135
292
while(1): sen1=input() if sen1=="-": break suff=int(input()) for i in range(suff): h=int(input()) sen1=sen1[h:]+sen1[:h] print(sen1)
n, m, l = map(int, input().split()) A, B = [], [] C = [[0 for _ in range(l)] for _ in range(n)] for _ in range(n): A.append([int(x) for x in input().split()]) for _ in range(m): B.append([int(x) for x in input().split()]) for i in range(n): for j in range(l): C[i][j] = 0 for x in range(m): C[i][j] += A[i][x] * B[x][j] for i in C: print(*i)
0
null
1,660,704,855,888
66
60
import sys alpha = input() text = 'abcdefghijklmnopqrstuvwxyz' for k in range(26): if text[k] == alpha: print('a') sys.exit() else: if k == 25: print('A')
n = int(input()) cnt = [[0] * 10 for i in range(10)] for i in range(n+1): a = int(str(i)[0]) b = int(str(i)[-1]) if a == 0 or b == 0: continue cnt[a][b] += 1 ans = 0 for i in range(n+1): a = int(str(i)[0]) b = int(str(i)[-1]) ans += cnt[b][a] print(ans)
0
null
48,794,689,019,528
119
234
s = input() n = len(s) t = [0]*(n+1) tmp=0 for i in range(n): tmp+=1 if s[i]=="<": t[i]=tmp-1 t[i+1]=tmp else: tmp=0 tmp=0 for j in range(n)[::-1]: tmp+=1 if s[j]==">": t[j+1]=max(tmp-1,t[j+1]) t[j]=max(tmp,t[j]) else: tmp=0 #print(t) print(sum(t))
s=input() a=[0]*(len(s)+1) for i in range(len(s)): if s[i]=="<": a[i+1]=a[i]+1 for i in range(len(s)-1,-1,-1): if s[i]==">": a[i]=max(a[i],a[i+1]+1) print(sum(a))
1
156,158,009,324,028
null
285
285
import base64 exec(base64.b64decode(b'aW1wb3J0IHN1YnByb2Nlc3MKaW1wb3J0IHN5cwoKY29kZSA9IHIiIiIjcHJhZ21hIEdDQyBvcHRpbWl6ZSgidW5yb2xs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zAnOwogICAgICAgIHRtcCAvPSAxMDsKICAgICAgfQogICAgfQogIH0KCiAgaW5saW5lIHZvaWQgZmx1c2goKSB7CiAgICBmd3JpdGUoYnVmLCAxLCBjdXIgLSBidWYsIHN0ZG91dCk7CiAgICBjdXIgPSBidWY7CiAgfQoKICB0ZW1wbGF0ZSA8Y2xhc3MgVCwgc3RkOjplbmFibGVfaWZfdDxzdGQ6OmlzX3NhbWU8VCwgaW50Pjo6dmFsdWUsIGludD4gPSAwPgogIGlubGluZSBpbnQgZ2V0X2RpZ2l0KFQgbikgewogICAgaWYgKG4gPj0gKGludCkxZTUpIHsKICAgICAgaWYgKG4gPj0gKGludCkxZTgpIHJldHVybiA5OwogICAgICBpZiAobiA+PSAoaW50KTFlNykgcmV0dXJuIDg7CiAgICAgIGlmIChuID49IChpbnQpMWU2KSByZXR1cm4gNzsKICAgICAgcmV0dXJuIDY7CiAgICB9IGVsc2UgewogICAgICBpZiAobiA+PSAoaW50KTFlNCkgcmV0dXJuIDU7CiAgICAgIGlmIChuID49IChpbnQpMWUzKSByZXR1cm4gNDsKICAgICAgaWYgKG4gPj0gKGludCkxZTIpIHJldHVybiAzOwogICAgICBpZiAobiA+PSAoaW50KTFlMSkgcmV0dXJuIDI7CiAgICAgIHJldHVybiAxOwogICAgfQogIH0KCiAgdGVtcGxhdGUgPGNsYXNzIFQsIHN0ZDo6ZW5hYmxlX2lmX3Q8c3RkOjppc19zYW1lPFQsIGludDY0Pjo6dmFsdWUsIGludD4gPSAwPgogIGlubGluZSBpbnQgZ2V0X2RpZ2l0KFQgbikgewogICAgaWYgKG4gPj0gKGludDY0KTFlMTApIHsKICAgICAgaWYgKG4gPj0gKGludDY0KTFlMTQpIHsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUxOCkgcmV0dXJuIDE5OwogICAgICAgIGlmIChuID49IChpbnQ2NCkxZTE3KSByZXR1cm4gMTg7CiAgICAgICAgaWYgKG4gPj0gKGludDY0KTFlMTYpIHJldHVybiAxNzsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUxNSkgcmV0dXJuIDE2OwogICAgICAgIHJldHVybiAxNTsKICAgICAgfSBlbHNlIHsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUxNCkgcmV0dXJuIDE1OwogICAgICAgIGlmIChuID49IChpbnQ2NCkxZTEzKSByZXR1cm4gMTQ7CiAgICAgICAgaWYgKG4gPj0gKGludDY0KTFlMTIpIHJldHVybiAxMzsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUxMSkgcmV0dXJuIDEyOwogICAgICAgIHJldHVybiAxMTsKICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgaWYgKG4gPj0gKGludDY0KTFlNSkgewogICAgICAgIGlmIChuID49IChpbnQ2NCkxZTkpIHJldHVybiAxMDsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWU4KSByZXR1cm4gOTsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWU3KSByZXR1cm4gODsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWU2KSByZXR1cm4gNzsKICAgICAgICByZXR1cm4gNjsKICAgICAgfSBlbHNlIHsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWU0KSByZXR1cm4gNTsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUzKSByZXR1cm4gNDsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUyKSByZXR1cm4gMzsKICAgICAgICBpZiAobiA+PSAoaW50NjQpMWUxKSByZXR1cm4gMjsKICAgICAgICByZXR1cm4gMTsKICAgICAgfQogICAgfQogIH0KCiAgdGVtcGxhdGUgPGNsYXNzIFQsIHN0ZDo6ZW5hYmxlX2lmX3Q8c3RkOjppc19zYW1lPFQsIGludD46OnZhbHVlLCBpbnQ+ID0gMD4KICBpbmxpbmUgdm9pZCB3cml0ZShUIG51bSkgewogICAgaWYgKF9fYnVpbHRpbl9leHBlY3QoY3VyICsgaW50ZWdlcl9zaXplID49IGJ1ZiArIGJ1Zl9zaXplLCAwKSkgZmx1c2goKTsKICAgIGlmIChudW0gPT0gMCkgewogICAgICB3cml0ZSgnMCcpOwogICAgICByZXR1cm47CiAgICB9CiAgICBpZiAobnVtIDwgMCkgewogICAgICB3cml0ZSgnLScpOwogICAgICBudW0gPSAtbnVtOwogICAgfQogICAgaW50IGxlbiA9IGdldF9kaWdpdChudW0pOwogICAgaW50IGRpZ2l0cyA9IGxlbjsKICAgIHdoaWxlIChudW0gPj0gMTAwMDApIHsKICAgICAgbWVtY3B5KGN1ciArIGxlbiAtIDQsIHRhYmxlICsgKG51bSAlIDEwMDAwKSAqIDQsIDQpOwogICAgICBudW0gLz0gMTAwMDA7CiAgICAgIGxlbiAtPSA0OwogICAgfQogICAgbWVtY3B5KGN1ciwgdGFibGUgKyBudW0gKiA0ICsgKDQgLSBsZW4pLCBsZW4pOwogICAgY3VyICs9IGRpZ2l0czsKICB9CgogIHRlbXBsYXRlIDxjbGFzcyBULCBzdGQ6OmVuYWJsZV9pZl90PHN0ZDo6aXNfc2FtZTxULCBpbnQ2ND46OnZhbHVlLCBpbnQ+ID0gMD4KICBpbmxpbmUgdm9pZCB3cml0ZShUIG51bSkgewogICAgaWYgKF9fYnVpbHRpbl9leHBlY3QoY3VyICsgaW50ZWdlcl9zaXplID49IGJ1ZiArIGJ1Zl9zaXplLCAwKSkgZmx1c2goKTsKICAgIGlmIChudW0gPT0gMCkgewogICAgICB3cml0ZSgnMCcpOwogICAgICByZXR1cm47CiAgICB9CiAgICBpZiAobnVtIDwgMCkgewogICAgICB3cml0ZSgnLScpOwogICAgICBudW0gPSAtbnVtOwogICAgfQogICAgaW50IGxlbiA9IGdldF9kaWdpdChudW0pOwogICAgaW50IGRpZ2l0cyA9IGxlbjsKICAgIHdoaWxlIChudW0gPj0gMTAwMDApIHsKICAgICAgbWVtY3B5KGN1ciArIGxlbiAtIDQsIHRhYmxlICsgKG51bSAlIDEwMDAwKSAqIDQsIDQpOwogICAgICBudW0gLz0gMTAwMDA7CiAgICAgIGx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gICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKGkgPiAwKSB7CiAgICAgICAgICBmb3IgKGludCBsID0gMDsgbCA8IDQ7ICsrbCkgZHBbaV1bal1bMF0gPSBtYXgoZHBbaV1bal1bMF0sIGRwW2kgLSAxXVtqXVtsXSk7CiAgICAgICAgfQogICAgICAgIGlmIChqID4gMCkgewogICAgICAgICAgZm9yIChpbnQgbCA9IDA7IGwgPCA0OyArK2wpIGRwW2ldW2pdW2xdID0gbWF4KGRwW2ldW2pdW2xdLCBkcFtpXVtqIC0gMV1bbF0pOwogICAgICAgIH0KICAgICAgfQogICAgfQogIH0KCiAgaW50NjQgYW5zID0gMDsKICBmb3IgKGludCBpID0gMDsgaSA8IDQ7ICsraSkgYW5zID0gbWF4KGFucywgZHBbciAtIDFdW2MgLSAxXVtpXSk7CiAgZm91dC5wcmludGxuKGFucyk7CgogIHJldHVybiAwOwp9CiIiIgoKd2l0aCBvcGVuKCdzb2wuY3BwJywgJ3cnKSBhcyBmOgogICAgZi53cml0ZShjb2RlKQoKc3VicHJvY2Vzcy5Qb3BlbihbJ2crKycsICctc3RkPWMrKzE3JywgJy1PMicsICdzb2wuY3BwJ10pLmNvbW11bmljYXRlKCkKc3VicHJvY2Vzcy5Qb3BlbihbJy4vYS5vdXQnXSwgc3RkaW49c3lzLnN0ZGluLCBzdGRvdXQ9c3lzLnN0ZG91dCkuY29tbXVuaWNhdGUoKQ=='))
import sys input=sys.stdin.readline R,C,k=map(int,input().split()) A=[[0]*C for i in range(R)] for i in range(k): r,c,v=map(int,input().split()) A[r-1][c-1]=v dp0=[[0]*(C+1) for i in range(R+1)] dp1=[[0]*(C+1) for i in range(R+1)] dp2=[[0]*(C+1) for i in range(R+1)] dp3=[[0]*(C+1) for i in range(R+1)] for i in range(1,R+1): for j in range(1,C+1): V=A[i-1][j-1] dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1]) dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1]) dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1]) dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1]) print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
1
5,545,967,645,610
null
94
94
import sys def resolve(in_, out): n = int(in_.readline()) b = [0] * (n + 1) for a in map(int, in_.readline().split()): b[a] += 1 out.write('\n'.join(map(str, b[1:]))) def main(): resolve(sys.stdin.buffer, sys.stdout) if __name__ == '__main__': main()
s = list(input()) s = list(set(s)) print('Yes') if len(s) >1 else print('No')
0
null
43,498,399,535,992
169
201
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)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n = int(readline()) st = [readline().rstrip().decode().split() for _ in range(n)] x = readline().rstrip().decode() cnt = 0 flag = False for s, t in st: if flag: cnt += int(t) if x == s: flag = True print(cnt)
1
96,465,059,891,804
null
243
243
a = [int(input()) for i in range(2)] if a[0] == 1: if a[1] == 2: my_result = 3 else: my_result = 2 elif a[0] == 2: if a[1] == 1: my_result = 3 else: my_result = 1 else: if a[1] == 1: my_result = 2 else: my_result = 1 print(my_result)
import math n,k=map(int,input().split()) A=list(map(int,input().split())) low=1 high=max(A) while low!=high: mid=(low+high)//2 s=0 for i in range(n): s+=math.ceil(A[i]/mid)-1 if s>k: low=mid+1 else: high=mid print(low)
0
null
58,473,167,100,502
254
99
import sys import fractions sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) H, W = lr() dp = [[0 for _ in range(W)] for _ in range(H)] masu = [sr() for _ in range(H)] dp[0][0] = 1 if masu[0][0] == "#" else 0 for h, m in enumerate(masu): for w, s in enumerate(m): if w == 0 and h == 0: continue if w == 0: if masu[h-1][w] != s and s == "#": dp[h][w] += dp[h-1][w] + 1 else: dp[h][w] += dp[h-1][w] continue if h == 0: if masu[h][w-1] != s and s == "#": dp[h][w] += dp[h][w-1] + 1 else: dp[h][w] += dp[h][w-1] continue if masu[h-1][w] != s and s == "#": cand1 = dp[h][w] + dp[h-1][w] + 1 else: cand1 = dp[h][w] + dp[h-1][w] if masu[h][w-1] != s and s == "#": cand2 = dp[h][w] + dp[h][w-1] + 1 else: cand2 = dp[h][w] + dp[h][w-1] dp[h][w] = min(cand1, cand2) print(dp[H-1][W-1])
h,w=map(int,input().split()) grid=[[1 if s=='#' else 0 for s in list(input())] for i in range(h)] #print(grid) maxi=10**5 from collections import deque visited=[[maxi]*w for _ in range(h)] def bfs(s): q=deque() q.append(s) visited[s[0]][s[1]]=grid[s[0]][s[1]] for r in range(h): for c in range(w): if r>=1: visited[r][c]=min(visited[r][c],visited[r-1][c]+grid[r][c]) if grid[r-1][c]==1: visited[r][c]=min(visited[r][c],visited[r-1][c]) if c>=1: visited[r][c]=min(visited[r][c],visited[r][c-1]+grid[r][c]) if grid[r][c-1]==1: visited[r][c]=min(visited[r][c],visited[r][c-1]) bfs([0,0]) print(visited[-1][-1])
1
49,340,945,896,838
null
194
194
N,M = map(int, input().split()) S = N+M ans = S*(S-1) / 2 - N * M print(int(ans))
import itertools N, M = map(int, input().split()) print( len([i for i in list(itertools.combinations(([2]*N)+([3]*M), 2)) if sum(i) % 2 == 0]) )
1
45,795,703,435,680
null
189
189
from collections import deque que = deque() l = input() S = 0 S2 = [] for j in range(len(l)): i = l[j] if i == '\\': que.append(j) continue elif i == '/': if len(que) == 0: continue k = que.pop() pond_sum = j-k S += pond_sum while S2 and S2[-1][0] > k: pond_sum += S2[-1][1] S2.pop() S2.append([k,pond_sum]) elif i == '_': continue data = [i for j,i in S2] print(S) print(len(S2),*data)
import sys from collections import deque def input(): return sys.stdin.readline()[:-1] A = input() total = 0 total_each = deque() S1 = deque() S2 = deque() for j,a in enumerate(A): #print('j = {}, S2 = {}'.format(j,S2)) if a == '\\': S1.append(j) elif a=='/': try: i = S1.pop() val_new = j-i total += val_new if len(S2)==0: S2.append((i,val_new)) continue while True: if len(S2)>0: a,val = S2[-1] if a<i: S2.append((i, val_new)) break elif i<a: _ = S2.pop() val_new = val + val_new else: S2.append((i,val_new)) break except: pass print(total) ans = [len(S2)] for _ in range(len(S2)): a,val = S2.popleft() ans.append(val) print(*ans)
1
56,138,772,342
null
21
21
for i in range(10000): x = input().split() h = int(x[0]) w = int(x[1]) if h == 0 and w ==0: break for i in range(w): print("#",end="") print() for i in range(h-2): print("#",end="") for i in range(w-2): print(".",end="") print("#",end="") print() for i in range(w): print("#",end="") print() print()
while True: h, w = [int(i) for i in input().split(' ')] if h ==0 and w ==0: break for i in range(h): row = '' for j in range(w): if i == 0 or i == h - 1: row = row + '#' else: if j == 0 or j == w -1: row = row + '#' else: row = row + '.' print(row) print('')
1
844,427,400,608
null
50
50
n = int(input()) arrey = [int(i) for i in input().split()] for i in range(n): v = arrey[i] j = i - 1 while j >= 0 and arrey[j] > v: arrey[j+1] = arrey[j] j = j - 1 arrey[j+1] = v for k in range(n): print(arrey[k]) if k == n-1 else print(str(arrey[k])+' ',end='')
n=int(input()) a=[int(i) for i in input().split()] aaa=" ".join(map(str,a)) print(aaa) for i in range(1,n): key=a[i] j=i-1 while j >= 0 and a[j] > key: a[j+1]=a[j] j=j-1 a[j+1]=key aaa=" ".join(map(str,a)) print(aaa)
1
5,297,537,714
null
10
10
from numpy import* (n,),*d=[int_(i.split())for i in open(0)] a,b=median(d,0) print(int((b-a)*(2-n%2))+1)
import sys from collections import deque, defaultdict, Counter from itertools import accumulate, product, permutations, combinations from operator import itemgetter from bisect import bisect_left, bisect_right from heapq import heappop, heappush from math import ceil, floor, sqrt, gcd, inf from copy import deepcopy import numpy as np import scipy as sp INF = inf MOD = 1000000007 n = int(input()) A = [[int(i) for i in input().split()]for j in range(n)] # nは行数 tmp = 0 res = 0 x = np.median(np.array(A), axis=0) if n % 2 == 0: res = int((x[1] - x[0]) * 2 + 1) else: res = int(x[1] - x[0] + 1) print(res)
1
17,320,297,918,142
null
137
137
N = int(input()) print((10 ** N - 2 * (9 ** N) + 8 ** N) % (10 ** 9 + 7))
import math n, m = map(int, input().split()) def comb(n, r): if n == 0 or n == 1: return 0 return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) a = comb(n, 2) b = comb(m, 2) print(a+b)
0
null
24,478,694,917,520
78
189
x = input() if x == "ABC": print("ARC") else: print("ABC")
#import numpy as np #import math #from decimal import * #from numba import njit #@njit def main(): S = input() if S == 'ABC': print('ARC') else: print('ABC') main()
1
24,090,597,584,028
null
153
153
s = input() n = len(s) sd = s[::-1] a = s[:int((n-1)/2)] ad = a[::-1] b = s[int((n+3)/2-1):] bd = b[::-1] if s == sd and a == ad and b == bd: print('Yes') else: print('No')
def check(p): global k, wlist loadage = 0 num = 1 for w in wlist: loadage += w if loadage > p: num += 1 if num > k: return False loadage = w return True n, k = map(int, input().split()) wlist = [] for _ in range(n): wlist.append(int(input())) maxw = max(wlist) sumw = sum(wlist) p = 0 while maxw < sumw: p = (maxw + sumw) // 2 if check(p): sumw = p else: maxw = p = p+1 print(p)
0
null
23,034,119,412,878
190
24
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 from collections import defaultdict #nの素因数分解,[[a1,b1],[a2,b2]...] aがb個, def factorization(n): if n==1: return [[1,0]] 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 lcm_dd = defaultdict(int) N=I() A=LI() for i in range(N): a=A[i] arr=factorization(a) for v in arr: p,cnt=v lcm_dd[p]=max(lcm_dd[p],cnt) lcm=1 for k,v in lcm_dd.items(): temp=pow(k,v,mod) lcm=(lcm*temp)%mod ans=0 for i in range(N): temp=(lcm*pow(A[i],mod-2,mod))%mod ans=(ans+temp)%mod print(ans%mod) main()
#!/usr/bin/env python3 from fractions import gcd n = int(input()) a = list(map(int, input().split())) MOD = 10 ** 9 + 7 l = 1 for x in a: l = l * x // gcd(l, x) ans = sum(l // x for x in a) % MOD print(ans)
1
87,556,322,680,992
null
235
235
A = input() B = input() se = set(["1","2","3"]) a = se-set([A,B]) print(a.pop())
from bisect import bisect_left N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() def count(x): ret = 0 for a in A: ret += N - bisect_left(A, x - a) return ret overEq = 0 less = 10**7 while less - overEq > 1: mid = (less + overEq) // 2 if count(mid) >= M: overEq = mid else: less = mid ans = 0 cnt = [0] * N for a in A: i = (N - bisect_left(A, overEq - a)) ans += i * a if i > 0: cnt[-i] += 1 for i in range(1, N): cnt[i] += cnt[i - 1] for a, c in zip(A, cnt): ans += a * c ans -= overEq * (count(overEq) - M) print(ans)
0
null
109,382,657,000,672
254
252
n, m = map(int, input().split()) S = list(map(int, input()))[::-1] L = [] now = 0 while now < n: if n - now <= m: L.append(n - now) break for i in range(m, 0, -1): if not S[now+i]: now += i L.append(i) break else: print(-1) exit() print(*L[::-1])
import math n = int(input()) a = list(map(int, input().split())) nmax = 10**6 check = [0]*(nmax + 5) for i in a: check[i] += 1 pairwise = True for i in range(2, nmax + 5): cnt = 0 for j in range(i, nmax + 5, i): cnt += check[j] if cnt > 1: pairwise = False if pairwise == True: print('pairwise coprime') exit() x = 0 for i in a: x = math.gcd(x,i) if x == 1: print('setwise coprime') else: print('not coprime')
0
null
71,730,672,268,934
274
85
import numpy as np N,K=map(int,input().split()) R,S,P=map(int,input().split()) T1=input() T2=T1.replace('r', str(P)+' ').replace('s',str(R)+' ').replace('p',str(S)+' ')[:-1] T2=np.array(list(map(int, T2.split()))) for i in range(N): if i >=K and T1[i]==T1[i-K] and T2[i-K] != 0: T2[i]=0 print(T2.sum())
s=input() l1=[] l2=[] num1=0 #0は反転なし 1はあり def ap1(str1): l1.append(str1) def ap2(str2): l2.append(str2) nq=int(input()) for i in range(nq): q=list(input().split()) if q[0]=="1": num1=(num1+1)%2 else: f=int(q[1]) if (num1+f)%2==1: #1で先頭 2で末尾 ap1(q[2]) else: ap2(q[2]) if num1==0: ans="" for i in range(len(l1)): ans+=l1[-1-i] ans+=s for i in range(len(l2)): ans+=l2[i] else: ans="" for i in range(len(l2)): ans+=l2[-1-i] for i in range(len(s)): ans+=s[-1-i] for i in range(len(l1)): ans+=l1[i] print(ans)
0
null
81,962,953,132,528
251
204
k=int(input()) line="ACL"*k print(line)
Ss = input().rstrip() print('x' * len(Ss))
0
null
37,682,515,837,430
69
221
s = input() ans = "No" if s[2]==s[3] and s[4]==s[5] : ans = "Yes" print(ans)
def main(): s = input() if s[2]==s[3] and s[4]==s[5]: print("Yes") else: print("No") if __name__ == "__main__": main()
1
41,905,406,566,758
null
184
184
S = int(input()) print("%d:%d:%d" % (S / 3600, S % 3600 / 60, S % 60))
import math while True: s = int(input()) if s == 0: break r = list(map(float, input().split())) x = sum(r) / s sigtwo = sum(list(map(lambda y: (y-x)**2, r))) / s sig = math.sqrt(sigtwo) print("{:.8f}".format(sig))
0
null
266,738,201,140
37
31
n, k = map(int, input().split()) def cul(x): ans = (1 + x)*x/(2*x) return ans p = list(map(cul, list(map(int, input().split())))) cnt = sum(p[0:k]) ans = cnt for i in range(k, n): cnt += p[i] - p[i - k] ans = max(ans, cnt) print(ans)
import collections n = int(input()) a = list(map(int,input().split())) ans = 0 cnt = collections.defaultdict(int) for i in range(n): ans += cnt[i-a[i]] cnt[i+a[i]]+=1 print(ans)
0
null
50,456,458,997,340
223
157
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) from collections import deque class Graph(): def __init__(self, v): from heapq import heappop, heappush self.v = v self.graph = [[] for _ in range(v)] self.INF = 10 ** 9 def addEdge(self, start, end, edge): self.graph[start].append((end, edge)) self.graph[end].append((start, edge)) def do(): n=INT() g=Graph(n) for i in range(n-1): a,b=INTM() a-=1 b-=1 g.addEdge(a,b,i) que=deque() check=[True]*n clrs=[0]*(n-1) que.append([0,0]) check[0]=False while que: clr=1 now,clr_f=que.popleft() if clr_f==1: clr=2 for next,i in g.graph[now]: if check[next]: check[next]=False que.append([next,clr]) clrs[i]=clr clr+=1 if clr==clr_f: clr+=1 print(max(clrs)) for i in range(n-1): print(clrs[i]) if __name__=='__main__': do()
import sys from collections import deque read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *AB = map(int, read().split()) G = [[] for _ in range(N)] for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)): G[a - 1].append((i, b - 1)) G[b - 1].append((i, a - 1)) queue = deque([0]) color = [0] * (N - 1) color_from_parent = [0] * N color_from_parent[0] = -1 while queue: v = queue.popleft() c = 1 for i, nv in G[v]: if color_from_parent[nv] != 0: continue if c == color_from_parent[v]: c += 1 color_from_parent[nv] = c color[i] = c c += 1 queue.append(nv) print(max(color)) print(*color, sep='\n') return if __name__ == '__main__': main()
1
136,169,626,825,460
null
272
272
n,a,b=map(int,input().split()) if a%2==b%2: print((b-a)//2) exit() if a-1<n-b: print(a+(b-a-1)//2) else: print(n-b+1+(b-a-1)//2)
n = int(input()) P = list(map(int,input().split())) k=0 bc=0 c=0 i=0 while k < n : if P[k]!=i+1 : bc+=1 else: i+=1 c+=1 k+=1 if c==0 : bc = -1 print(bc)
0
null
112,228,231,344,222
253
257
import math a, b, deg = map(float, input().split()) rad = math.radians(deg) area = 0.5 * a * b * math.sin(rad) c = math.sqrt(a*a + b*b - 2*a*b*math.cos(rad)) h = area*2 / a; print(area, a+b+c, h)
# Aizu Problem ITP_1_2_A: Small, Large or Equal # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") a, b = [int(_) for _ in input().split()] if a < b: print("a < b") elif a > b: print("a > b") else: print("a == b")
0
null
272,934,245,258
30
38
S = input() ans = 0 for i in range(0,len(S)//2): if S[i] != S[len(S)-1-i]: ans += 1 print(ans)
a, b, c, d = map(int, input().split()) h = a * c i = a * d j = b * c k = b * d print(max(h, i, j, k))
0
null
61,773,536,044,960
261
77
import bisect N=int(input()) arr=list(map(int,input().split())) arr.sort() ans=0 for i in range(N-2): for j in range(i+1,N-1): k=bisect.bisect_left(arr,arr[i]+arr[j]) if k>j: ans+=k-j-1 else: pass print(ans)
while True: (H, W) = [int(i) for i in input().split()] if H == W == 0: break print ("\n".join(["".join(["#" if i == 0 or i == W - 1 or j == 0 or j == H - 1 else "." for i in range(W)]) for j in range(H)])) print()
0
null
86,526,424,977,122
294
50
INF = int(1e9) def main(): n, m = map(int, input().split()) a = [int(i) for i in input().split()] a.sort() s = [0] for i in range(n): s.append(s[i]+a[i]) #Xより大きい要素の数を数える def counter(x): count = 0 for i in range(n): l = -1 r = n while r-l>1: mid = (l+r)//2 if a[i] + a[mid] > x: r = mid else: l = mid count += n-r return count #Xより大きい要素数がm個未満であるXのうち最大のものを探す l = 0 r = INF while r-l>1: mid = (l+r)//2 if counter(mid) < m: r = mid else: l = mid #lより大きい要素の総和を求める def sigma(x): cnt = 0 sgm = 0 for i in range(n): l = -1 r = n while r-l >1: mid = (l+r)//2 if a[i]+a[mid]>x: r = mid else: l = mid cnt += n-r sgm += a[i] * (n-r) + (s[n]-s[r]) return (sgm, cnt) sgm, cnt = sigma(l) ans = sgm+(m-cnt)*r print(ans) main()
import numpy as np from numpy.fft import fft from numpy.fft import ifft class FFT: def exe(s, A, B): N, M = 1, len(A) + len(B) - 1 while N < M: N <<= 1 A, B = s.arrN(N, A), s.arrN(N, B) A = fft(A) * fft(B) A = ifft(A).real[:M] + 0.5 return list(map(int, A)) def arrN(s, N, L): return np.zeros(N) + (L + [0] * (N - len(L))) N, M = list(map(int, input().split())) A = list(map(int, input().split())) MAX = max(A) L = [0] * (MAX + 1) for i in A: L[i] += 1 f = FFT() L = f.exe(L, L) ans = 0 for i in range(len(L) - 1, -1, -1): if L[i] < M: ans += i * L[i] M -= L[i] else: ans += i * M break print(ans)
1
107,986,415,577,128
null
252
252
def resolve(): s = str(input()) if s[2]==s[3] and s[4]==s[5]: print('Yes') else: print('No') a = resolve()
#Macで実行する時 import sys import os if sys.platform=="darwin": base = os.path.dirname(os.path.abspath(__file__)) name = os.path.normpath(os.path.join(base, '../atcoder/input.txt')) sys.stdin = open(name) s = input() if s[2]==s[3] and s[4]==s[5]: print("Yes") else: print("No")
1
42,202,551,257,108
null
184
184
from fractions import gcd from datetime import date, timedelta from heapq import* import math from collections import defaultdict, Counter, deque import sys from bisect import * import itertools import copy sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 def modpow(a, n, mod): res = 1 while n > 0: if n & 1: res = res * a % mod a = a * a % mod n >>= 1 return res def main(): n = int(input()) if n % 2 == 0: print((n - 1) // 2) else: print(n//2) if __name__ == '__main__': main()
N = int(input())-1 print(N//2)
1
152,941,890,661,662
null
283
283
while True: H, W = [int(i) for i in input().split()] if H == W == 0: break for h in range(H): for w in range(W): if (w + h) % 2 == 0 : print('#', end='') else: print('.', end='') print() print()
input_str = input().split() amount_to_make = int(input_str[0]) lot_size = int(input_str[1]) time_to_make_one_lot = int(input_str[2]) proceeded_time = 0 made_amount = 0 while made_amount < amount_to_make: made_amount += lot_size proceeded_time += time_to_make_one_lot print(proceeded_time)
0
null
2,563,252,377,688
51
86
H, W, K = map(int, input().split()) S = [input() for i in range(H)] C = [[0 for i in range(W)] for j in range(H)] L = [] u = 0 M = [] for i in range(H): s = 0 for j in range(W): if S[i][j] == '#': s += 1 u += 1 C[i][j] = u if s == 0: L.append(i) else: M.append(i) d = 0 for i in range(len(M)): for j in range(W): if C[M[i]][j] != 0: for k in range(d, j): C[M[i]][k] = C[M[i]][j] d = j + 1 for k in range(d, W): C[M[i]][k] = C[M[i]][d-1] d = 0 ma, mi = max(M), min(M) M.insert(0, -1) for i in range(W): for j in range(len(M)-1): for k in range(M[j]+1, M[j+1]): C[k][i] = C[M[j+1]][i] for j in range(ma+1, H): C[j][i] = C[ma][i] for i in range(H): for j in range(W): if j != W-1: print(C[i][j], end = ' ') else: print(C[i][j], end = '') print()
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n, k = nm() p = nl() _c = nl() c = [0]*n for i in range(n): p[i] -= 1 c[i] = _c[p[i]] m = 31 MIN = - (1 << 63) vertex = list() score = list() vertex.append(p) score.append(c) for a in range(1, m+1): p_ath = [0] * n c_ath = [0] * n for i in range(n): p_ath[i] = vertex[a-1][vertex[a-1][i]] c_ath[i] = score[a-1][i] + score[a-1][vertex[a-1][i]] vertex.append(p_ath) score.append(c_ath) prv = [[MIN, 0] for _ in range(n)] nxt = [[MIN, MIN] for _ in range(n)] for b in range(m, -1, -1): for i in range(n): if (k >> b) & 1: nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i]) nxt[vertex[b][i]][1] = max(nxt[vertex[b][i]][1], prv[i][1] + score[b][i]) nxt[i][0] = max(nxt[i][0], prv[i][0], prv[i][1]) else: nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i]) nxt[i][0] = max(nxt[i][0], prv[i][0]) nxt[i][1] = max(nxt[i][1], prv[i][1]) prv, nxt = nxt, prv ans = max(max(x) for x in prv) if ans == 0: ans = max(c) print(ans) return solve()
0
null
74,662,476,827,640
277
93
import numpy as np S = input() K = int(input()) seq = [] init = 1 def seq_count(strings, lst): init = 1 for i in range(len(strings)-1): if strings[i] == strings[i+1]: init += 1 else: lst.append(init) init = 1 lst.append(init) seq_count(S, seq) if S[0] != S[-1]: array = np.array(seq) ans = array // 2 print(int(np.sum(ans))*K) else: seq2 = seq[1:-1] array = np.array(seq2) part_ans = array // 2 if len(seq) > 1: print(int(np.sum(part_ans))*K+((seq[0]+seq[-1])//2)*(K-1)+(seq[0]//2)+(seq[-1]//2)) else: print((seq[0]*K)//2)
import collections s = str(input()) k = int(input()) ans = 0 #if s[0] == s[-1]: # ans += k tmp = '' tmp_num = 0 check = '' check_num = 0 if len(collections.Counter(s).keys()) == 1: ans = len(s)*k//2 else: for i, w in enumerate(s): if i == 0: tmp += w tmp_num += 1 continue if tmp[-1] == w: tmp += w tmp_num += 1 elif tmp[-1] != w: if check_num == 0: check = tmp check_num = 1 ans += (tmp_num // 2) * k #print('ans', ans) tmp = w tmp_num = 1 if i == len(s)-1: if len(tmp) == 1: if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1): ans += k-1 else: #print(check, tmp) if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1): ans += k-1 ans += (tmp_num // 2) * k #print('last', ans) print(ans)
1
175,530,461,909,440
null
296
296
import math def main(): K = int(input()) s = 0 for i in range(K): for j in range(K): tmp = math.gcd(i+1, j+1) for k in range(K): s += math.gcd(tmp, k+1) print(s) if __name__=="__main__": main()
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) aa = [0] bb = [0] for i in range(n): aa.append(aa[-1]+a[i]) for i in range(m): bb.append(bb[-1]+b[i]) c = m ans = 0 for i in range(n+1): u = k - aa[i] for j in range(c, -1, -1): if bb[j] <= u: ans = max(ans, i+j) c = j break print(ans)
0
null
23,168,507,292,030
174
117
n, k, s = map(int, input().split()) L = [0] * n for i in range(n): if i < k: L[i] = s else: if s != 10 ** 9: L[i] = s + 1 else: L[i] = s - 1 print(*L)
N = int(input()) X = list(map(int, input().split())) MAX = 10 ** 6 + 1 prime = [True] * MAX counted = set() for v in X: if v in counted: prime[v] = False continue for j in range(2 * v, MAX, v): prime[j] = False counted.add(v) ans = 0 for v in X: ans += int(prime[v]) print(ans)
0
null
52,594,245,364,290
238
129
n = int(input()) string = input() ans = 0 for i in range(0, n-2): if string[i] == "A" and string[i+1] == "B" and string[i+2] == "C": ans += 1 print(ans)
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): N = I() S = _S() print(S.count("ABC")) main()
1
99,063,968,623,100
null
245
245
l = int(input()) l /= 3 print(l**3)
import math I=list(map(int,input().split())) X=(2*I[1]-I[0])//3 Y=(2*I[0]-I[1])//3 n=X+Y r=X if (X<0 or Y<0 or (I[0]+I[1])%3!=0): print(0) exit() def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 10 ** 6 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) print(cmb(n, r, p))
0
null
98,795,835,003,230
191
281
s='' try: while True: sentence=input() s+=sentence.lower() except: for i in[chr(i) for i in range(97,97+26)]: print(i,':',s.count(i))
# coding: utf-8 import string d = {} for ch in list(string.ascii_lowercase): d[ch] = 0 while True: try: s = list(input().lower()) except EOFError: break for ch in s: if ch.isalpha(): d[ch] += 1 else: pass for k, v in sorted(d.items()): print('{} : {}'.format(k, v))
1
1,683,284,285,486
null
63
63
import math N = int(input()) if N % 2 == 1: print(0) else: i = 10 ans = 0 while(True): a = math.floor(N // i) if a < 1: break ans += a i *= 5 print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) K, N = mapint() As = list(mapint()) lis = [] for i in range(1, N): lis.append(As[i]-As[i-1]) lis.append(As[0]+(K-As[-1])) print(K-max(lis))
0
null
79,360,253,928,332
258
186
n, t = map(int,input().split()) ab = [list(map(int,input().split())) for i in range(n)] ab = sorted(ab, key=lambda x:(x[0])) t -= 1 dp = [[0]*(t+1) for i in range(n+1)] for i in range(1, n+1): ca, cb = ab[i-1][0], ab[i-1][1] for j in range(1, t+1): if j - ca >= 0: dp[i][j] = max(dp[i-1][j], dp[i-1][j-ca] + cb) else: dp[i][j] = dp[i-1][j] b_max = [0] tmp = 0 for i in range(n-1, -1, -1): tmp = max(tmp, ab[i][1]) b_max = [tmp] + b_max ans = 0 for i in range(n+1): ans = max(ans, dp[i][t] + b_max[i]) # print(dp[i][t] + b_max[i]) print(ans)
N, T = map(int, input().split()) ls = [] for i in range(N): a, b = map(int, input().split()) ls += [(a,b)] ls.sort(key=lambda x:x[0]) t = [[0]*T for i in range(N+1)] for i in range(1,N+1): a, b = ls[i-1] for j in range(T): if j-a>=0: t[i][j] = max(t[i-1][j-a]+b,t[i-1][j]) last = [0] for i in range(N-1,-1,-1): last += [max(last[-1], ls[i][-1])] ans = 0 for i in range(1,N+1): j = N-i ans = max(ans, last[j]+t[i][-1]) print(ans)
1
151,562,786,158,780
null
282
282
d,t,s = input().split() gool = int(d) / int(s) if gool <= int(t): print('Yes') else: print('No')
s = str(input()) t = str(input()) ans = len(t) for i in range(len(s) - len(t) + 1): tmp_ans = 0 for j in range(len(t)): if s[i+j] != t[j]: tmp_ans += 1 ans = min(ans, tmp_ans) print(ans)
0
null
3,616,587,733,990
81
82
n,k=map(int,input().split()) x,i=0,0 while n>0: x+=(n%k)*10**i n=n//k i+=1 print(len(str(x)))
num = int(input()) num_list = list(map(int,input().split(" "))) print(min(num_list),max(num_list),sum(num_list))
0
null
32,500,282,517,642
212
48
import sys def input(): return sys.stdin.readline().strip() def MAP(): return map(int, input().split()) n, a, b = MAP() print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)
n = int(input()) s = input() ans = s.count('R') * s.count('G') * s.count('B') for i in range(n-2): for j in range(i+1, n-1): k = 2*j-i if k < n: if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]: ans -= 1 else: break print(ans)
0
null
72,369,122,703,790
253
175
# coding: utf-8 # Your code here! n=int(input()) flag=0 for i in range(1,10): if n%i==0: if 10>n/i: flag=1 if flag: print('Yes') else: print('No')
n = int(input()) ans = 0 for i in range(9): if n % (i+1) == 0: if n//(i+1) >= 1 and n//(i+1) <= 9: print('Yes') ans = 1 break if ans == 0: print('No')
1
159,769,788,298,872
null
287
287
n = int(input()) Ai = list(map(int, input().split())) sum_ans = sum(Ai) ans = 0 mod = 1000000007 for i in range(n-1): sum_ans -= Ai[i] ans += sum_ans * Ai[i] ans %= mod print(ans)
N=int(input()) A=list(map(int,input().split())) sumA=0 sumB=[0] for i in range(N): sumB.append(sumB[i]+A[i]) i=i+1 for j in range(N-1): sumA=sumA+(A[j]*(sumB[N]-sumB[j+1]))%(10**9+7) j=j+1 print(sumA%(10**9+7))
1
3,816,495,775,938
null
83
83
while True: cou = 0 n,x = map(int,input().split()) if n==0 and x==0: break for i in range(1,x//2): for j in range(i+1,x//2): k = x - i - j if i<=n and j<=n and k<=n and k>j: cou += 1 print(cou)
t=list(input()) if t[0]=='?': t[0]=t[0].replace('?','D') for i in range(1,len(t)-1): if t[i]=='?' and t[i+1]=='D' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='P': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='D' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='P' and t[i-1]=='D': t[i]=t[i].replace('?','D') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='D': t[i]=t[i].replace('?','P') elif t[i]=='?' and t[i+1]=='?' and t[i-1]=='P': t[i]=t[i].replace('?','D') if t[-1]=='?': t[-1]=t[-1].replace('?','D') for i in t: print(i,end='')
0
null
9,964,261,981,152
58
140
n = int(input()) a = list(map(int,input().split())) ans = 1 for i in a : ans *= i if ans > 10**18 : ans = -1 break if 0 in a : ans = 0 print(ans)
N = int(input()) A = list(map(int, input().split())) f = 0 if 0 in A: print("0") f = 1 else: ans = A[0] for i in range(1, N): ans = ans * A[i] if ans > 10**18: print("-1") f = 1 break if f == 0: print(ans)
1
16,022,811,141,862
null
134
134
while True: n,x = map(int,input().split()) if n == x == 0: break count = 0 for a in range(n+1): for b in range(1,a): for c in range(1,b): if a+b+c==x: count+=1 print(count)
def main(): N = int(input()) S = [0] * N T = [0] * N for i in range(N): S[i], T[i] = input().split() X = input() idx = S.index(X) ans = sum(map(int, T[idx+1:])) print(ans) if __name__ == "__main__": main()
0
null
49,160,323,386,552
58
243
def main(): K = int(input()) from math import gcd ans = 0 for i in range(1, K+1): for j in range(1, K+1): g = gcd(i, j) for k in range(1, K+1): ans += gcd(g, k) print(ans) if __name__ == '__main__': main()
n,m = map(int,input().split()) dic = {} ac = 0 wa = 0 for _ in range(m): p,s = map(str,input().split()) p = int(p) if p not in dic: if s =='AC': ac += 1 dic[p] = s else: dic[p] = 1 elif dic[p]=='AC': continue else: if s =='AC': ac += 1 wa +=dic[p] dic[p] = s else: dic[p] += 1 print(str(ac) + ' ' + str(wa))
0
null
64,666,469,363,870
174
240
class Node: def __init__(self,key): self.key = key self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.nil = Node(None) self.nil.prev = self.nil self.nil.next = self.nil def insert(self,key): new = Node(key) new.next = self.nil.next self.nil.next.prev = new self.nil.next = new new.prev = self.nil def listSearch(self,key): cur = self.nil.next while cur != self.nil and cur.key != key: cur = cur.next return cur def deleteNode(self, t): if t == self.nil: return t.prev.next = t.next t.next.prev = t.prev def deleteFirst(self): self.deleteNode(self.nil.next) def deleteLast(self): self.deleteNode(self.nil.prev) def deleteKey(self, key): self.deleteNode(self.listSearch(key)) if __name__ == '__main__': import sys input = sys.stdin.readline n = int(input()) d = DoublyLinkedList() for _ in range(n): c = input().rstrip() if c[0] == "i": d.insert(c[7:]) elif c[6] == "F": d.deleteFirst() elif c[6] =="L": d.deleteLast() else: d.deleteKey(c[7:]) ans = [] cur = d.nil.next while cur != d.nil: ans.append(cur.key) cur = cur.next print(" ".join(ans))
s = raw_input().swapcase() print s
0
null
767,462,270,462
20
61
N = int(input()) ans = [0]*(N+1) for x in range(1,100): for y in range(1,100): for z in range(1,100): num = x*x + y*y + z*z + x*y + y*z + z*x if num>N: break ans[num] = ans[num] + 1 for m in ans[1:]: print(m)
n,m=map(int,input().split()) def exit(): import sys print(-1) sys.exit() num=['']*n for s,c in (map(int,input().split()) for i in range(m)): if n>1 and [s,c]==[1,0]: exit() if num[s-1]!='': if num[s-1]==c: continue else: exit() else: num[s-1]=c else: if n==1: print(num[0] if num[0]!='' else 0, end='') else: print(num[0] if num[0]!='' else 1, end='') for i in range(1,n): print(num[i] if num[i]!='' else 0, end='')
0
null
34,527,056,972,892
106
208
listA=[] listOP=[] listB=[] count=0 while True: a,op,b=input().split() listA.append(int(a)) listOP.append(op) listB.append(int(b)) if op=="?": del listA[len(listA)-1] del listOP[len(listOP)-1] del listB[len(listB)-1] break #入力パートここまで。計算出力パートここから while count<=len(listA)-1: if listOP[count]=="+": print(listA[count]+listB[count]) elif listOP[count]=="-": print(listA[count]-listB[count]) elif listOP[count]=="*": print(listA[count]*listB[count]) elif listOP[count]=="/": print(listA[count]//listB[count]) else: print("ERROR") count+=1
from sys import stdin operate = { '+': lambda lhs, rhs: lhs + rhs, '-': lambda lhs, rhs: lhs - rhs, '*': lambda lhs, rhs: lhs * rhs, '/': lambda lhs, rhs: lhs // rhs, } while True: arr = (stdin.readline().rstrip().split()) a, op, b = int(arr[0]), arr[1], int(arr[2]) if op == '?': break answer = operate[op](a, b) print(answer)
1
680,179,683,080
null
47
47
import decimal d = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) D_1 = 0 for i in range(d): L_i = abs(x[i] - y[i]) D_1 += L_i D_2 = 0 for i in range(d): L_i = abs(x[i]-y[i])**2 D_2 += L_i D_2 = (D_2) **(1/2) D_3 = 0 for i in range(d): L_i = abs(x[i]-y[i])**3 D_3 += L_i D_3 = (D_3) ** (1/3) L =[] for i in range(d): L.append(abs(x[i]-y[i])) D_ = max(L) print('{:.8f}'.format(D_1)) print('{:.8f}'.format(D_2)) print('{:.8f}'.format(D_3)) print('{:.8f}'.format(D_))
n = input() print pow(n, 3)
0
null
245,226,407,680
32
35
def print_puddle(puddle): n = len(puddle) if n > 0: print(n, end=' ') else: print(n) for i in range(n): if i != n - 1: print(puddle[i][1], end=' ') else: print(puddle[i][1]) def solve(A): left = [] puddle = [] sum_all = 0 for i, a in enumerate(A): if a == '\\': left.append(i) elif a == '/' and len(left) > 0: left_i = left.pop() a = i - left_i sum_paddle = i - left_i sum_all += a while len(puddle) and puddle[-1][0] > left_i: tmp = puddle.pop() sum_paddle += tmp[1] puddle.append((left_i, sum_paddle)) print(sum_all) print_puddle(puddle) def main(): A = list(input()) solve(A) if __name__ == "__main__": main()
import sys readline = sys.stdin.readline li = [] for i, s in enumerate(readline().strip()): if s == "\\": li.append([i, 0]) elif s == "/": if li: if li[-1][1] == 0: li[-1][1] = i - li[-1][0] else: for j in range(len(li) - 1, -1, -1): if li[j][1] == 0: li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]] break ans = [] for a in li: if a[1] != 0: ans.append(a[1]) print(sum(ans)) print(len(ans), *ans)
1
58,416,286,088
null
21
21
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()
x = [x for x in input().split()] print(x[1]+x[0])
0
null
52,912,988,087,650
74
248
b = [] while True: a = input().split() if a[1] == "?": break elif a[1] == "+": b.append(int(a[0])+int(a[2])) elif a[1] == "-": b.append(int(a[0])-int(a[2])) elif a[1] == "*": b.append(int(a[0])*int(a[2])) else: b.append(int(a[0])//int(a[2])) for i in b: print(i)
n, m, k = map(int, input().split(" ")) a = [int(i) for i in input().split(" ")] b = [int(i) for i in input().split(" ")] A = [0] B = [0] for i in a: if A[-1] > k: break A.append(A[-1] + i) for i in b: if B[-1] > k: break B.append(B[-1] + i) ans = 0 j = len(B) - 1 for i in range(len(A)): if A[i] > k: break while A[i] + B[j] > k: j -= 1 ans = max(ans, i + j) print(ans)
0
null
5,664,528,250,488
47
117
def main(): n = input() res = 0 for ni in n: res = (res + int(ni)) % 9 print(('Yes', 'No')[res != 0]) if __name__ == '__main__': main()
n=int(input()) for i in range(9): for u in range(9): if n==(i+1)*(u+1): print('Yes') exit() print('No')
0
null
82,333,037,570,180
87
287
import numpy as np N,A,B = (int(x) for x in input().split()) C = A+B set = N // C ans = A if (N-C*set) >= A else N-C*set ans += set*A print(ans)
n = int(input()) t = [0] * 100 for i in range(11, 100): msb = i // 10 lsb = i % 10 if lsb == 0: continue for j in range(1, n+1): if j % 10 == lsb and int(str(j)[0]) == msb: t[i] += 1 ans = 0 for i in range(11, 100): msb = i // 10 lsb = i % 10 if lsb == 0: continue if msb == lsb: ans += t[i] ** 2 else: ans += t[i] * t[lsb * 10 + msb] print(ans)
0
null
71,293,884,212,768
202
234
n = int(input()) sum = 0 for i in range(n + 1): if i % 3 != 0 and i % 5 != 0 and i % 15 != 0: sum += i print(sum)
from collections import Counter n = int(input()) a = list(map(int, input().split())) q = int(input()) ans = sum(a) count = Counter(a) for _ in range(q): b,c = map(int, input().split()) count[c] += count[b] ans -= b*count[b] ans += c*count[b] count[b] = 0 print(ans)
0
null
23,535,701,393,194
173
122
if __name__ == '__main__': N, A, B = map(int, input().split()) base = pow(10, 100) C = A+B mod = N%C n = N//C if mod>A: print(A*n+A) else: print(A*n+mod)
xy = [map(int,input().split()) for i in range(2)] x,y = [list(j) for j in zip(*xy)] if (y[0] + 1) == y[1] : ans = 0 else: ans = 1 print(ans)
0
null
89,630,847,131,168
202
264
N = int(input()) numbers = [int(input()) for i in range(N)] ans = [] def check_prime(n): for i in range(2, int(n**0.5)+1): if n % i == 0: return 0 else: return 1 for n in numbers: ans.append(check_prime(n)) print(sum(ans))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A=map(int,read().split()) bound = [0]*(N+1) bound[0] = 1 #Nが0のとき if N == 0: if A[0] == 1: print(1) else: print(-1) sys.exit() #Nが0以外のとき #上から for i in range(1,N+1): bound[i] = (bound[i-1]-A[i-1]) *2 if bound[i] < A[i]: print(-1) sys.exit() #下からのと最小値を取る cum_sum = 0 for i in range(N,-1,-1): cum_sum += A[i] bound[i] = min(bound[i],cum_sum) print(sum(bound))
0
null
9,391,779,329,388
12
141
x, k, d = map(int, input().split()) if x < 0: target = abs(x) // d x = x + d * min(target, k) k -= min(target, k) else: target = x // d x = x - d * min(target, k) k -= min(target, k) if k % 2 != 0: if x < 0: x += d else: x -= d print(abs(x))
# coding: UTF-8 CONTEST_NUM = 26 class Optimizer: def __init__(self, days, s, c): self._days = days self._s = s self._c = c def optimize(self): # 貪欲法による手法 t = [] for d in range(self._days): max_d_value = 0 max_contest = 0 for i in range(CONTEST_NUM): d_value = self._s[d][i] + self._c[i] * (d + 1) if d_value > max_d_value: max_d_value = d_value max_contest = i t.append(max_contest + 1) return t def main(): ## 引数読み込み days = int(input()) # D c = tuple(map(int, input().split())) # c[i] s = [] # s[d][i] for i in range(days): s.append(tuple(map(int, input().split()))) ## 試しに指標計算 t = Optimizer(days, s, c).optimize() ## print out for v in t: print(v) if __name__ == "__main__": main()
0
null
7,503,012,182,048
92
113
x,n=map(int,input().split()) p=set(map(int,input().split())) low=x high=x while True: if low not in p: print(low) break elif high not in p: print(high) break low-=1 high+=1
def Qc(): x, n = map(int, input().split()) if 0 < n: p = list(map(int, input().split())) for i in range(101): if x - i not in p: print(x - i) exit() if x + i not in p: res = x + 1 print(x + i) exit() else: # 整数列がなにもない場合は自分自身が含まれていない最近値になる print(x) exit() if __name__ == "__main__": Qc()
1
14,087,333,562,650
null
128
128
n = input() for i in range(n): l = map(int, raw_input().split()) l.sort() if(l[0] * l[0] + l[1] * l[1] == l[2] * l[2]): print("YES") else: print("NO")
import math n, x, t = map(int, input().split()) count = math.ceil(n / x) time = t * count print(time)
0
null
2,133,852,825,988
4
86
S = list(str(input())) T = list(str(input())) i = 0 ans = [] len_s = len(S) len_t = len(T) while i < len_s-len_t+1: cnt = 0 for ss, tt in zip(S[i:i+len_t], T): if ss != tt: cnt += 1 ans.append(cnt) i += 1 print(min(ans))
S=list(input()) T=list(input()) A=[] for i in range(len(S)-len(T)+1): B=0 for j in range(len(T)): if T[j]==S[i+j]: continue else: B =B+1 A.append(B) A.sort() print(A[0])
1
3,698,221,595,872
null
82
82
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) d = abs(A-B) if d-(V-W)*T<=0: print("YES") else: print("NO")
#!/usr/bin/env python3 import sys from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): mod = 1000000007 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) a, v = mi() b, w = mi() t = ii() if v <= w: print('NO') else: dist = abs(a - b) print('YES') if dist <= t * (v - w) else print('NO') if __name__ == "__main__": main()
1
15,152,893,141,738
null
131
131
s = input() a = len(s)//2 count = 0 for i in range(a): if s[i] != s[-i-1]: count += 1 print(count)
import sys import os # import math # input = sys.stdin.readline def int_array(): return list(map(int, input().strip().split())) def str_array(): return input().strip().split() def gcd(a,b): if b == 0: return a return gcd(b, a % b);x def take_input(): if os.environ.get("check"): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') take_input() ######################### TEMPLATE ENDS HERE ################################# for _ in range(int(input())): print("ACL", end="")
0
null
61,407,519,332,812
261
69
a,b,c,k = map(int,input().split()) ans = min(a,k) k -= ans if k == 0: print(ans) exit(0) k -= min(b,k) if k == 0: print(ans) exit(0) ans -= min(c,k) print(ans)
import sys input = sys.stdin.readline A = sorted(list(map(int,input().split()))) if (A[0] != A[1] and A[1] == A[2]) or (A[0] == A[1] and A[1] != A[2]) : print('Yes') else: print('No')
0
null
44,927,515,252,280
148
216
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy time = 1 def dfs(node): global time if visited[node] != -1: return visited[node] = 0 d[node] = time time += 1 for v in edge[node]: dfs(v) f[node] = time time += 1 if __name__ == "__main__": n = int(input()) edge = [] for i in range(n): u,k,*v_li = map(int,input().split()) for j in range(len(v_li)): v_li[j] -= 1 u-=1 edge.append(v_li) d = {} f = {} visited = [-1]*n for i in range(n): dfs(i) for i in range(n): print(i+1,d[i],f[i])
from collections import defaultdict def main(): n, x, y = map(int, input().split()) ans = defaultdict(int) for i in range(1, n + 1): for j in range(i + 1, n + 1): l = min(abs(i - j), abs(i - x) + abs(y - j) + 1, abs(i - y) + abs(x - j) + 1) ans[l] += 1 [print(ans[i]) for i in range(1, n)] if __name__ == '__main__': main()
0
null
22,019,654,230,782
8
187
length = raw_input() a, b = length.split() a = int(a) b = int(b) print a * b, 2 * (a + b)
# your code goes here in1,in2 = map(int, input().split()) print(in1 * in2, in1 * 2 + in2 * 2)
1
303,788,781,670
null
36
36
def insertionSort(A,n,g,count): for i in range(g,N): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g count += 1 A[j+g] = v return count def shellSort(A,n): count = 0 m = 0 G = [] while (3**(m+1)-1)//2 <= n: m += 1 G.append((3**m-1)//2) for i in range(m): count = insertionSort(A,n,G[-1-i],count) return m,G,count import sys input = sys.stdin.readline N = int(input()) A = [int(input()) for _ in range(N)] m,G,count = shellSort(A,N) print(m) print(*G[::-1]) print(count) print('\n'.join(map(str,A)))
exchange_cnt = 0 def insertion_sort(w_list, g): """一般化した Insertion ソート 通常の Insertion ソートは gap が 1 固定だが、ここでは、 gap を引数 g で指定できる。 当然、g < len(w_list) でないといけない。 """ global exchange_cnt N = len(w_list) for i in range(g, N): v = w_list[i] j = i - g while j >= 0 and w_list[j] > v: w_list[j+g] = w_list[j] j -= g exchange_cnt += 1 w_list[j+g] = v def make_gap_sequence(n): """gap sequence を作成 とりあえず、Wiki にのっていたやり方のひとつを採用。 N ^ 1.5 のオーダーになるという。 """ seq = [] k = 1 while True: gap = 2 ** k - 1 if gap > n: break seq.append(gap) k += 1 seq.reverse() # in place なので効率が良い。 return seq def make_gap_sequence_2(n): """もうひとつの gap sequence の作成方法 Wiki にのっていた Shell によるオリジナルの方法。 これだと最悪の場合、N ^ 2 のオーダーになってしまうようだ。 """ seq = [] k = 1 while True: gap = n // (2 ** k) if gap <= 1: break seq.append(gap) k += 1 seq.append(1) return seq def shell_sort(w_list): N = len(w_list) # N から gap sequence を決める。 # どう決めるかで効率が変わってくるのだが、どう決めるかは難問。 # gap_sequence = make_gap_sequence(N) gap_sequence = make_gap_sequence_2(N) for g in gap_sequence: insertion_sort(w_list, g) return gap_sequence n = int(input()) w_list = [] for _ in range(n): w_list.append(int(input())) gap_seq = shell_sort(w_list) print(len(gap_seq)) print(*gap_seq) print(exchange_cnt) for i in w_list: print(i)
1
32,220,167,368
null
17
17
n=int(input()) a=list(enumerate(map(int,input().split()))) a.sort(key=lambda x: -x[1]) dp=[[0]*(n+1) for i in range(n+1)] for idx,ix in enumerate(a): i,x=ix for j in range(idx+1): dp[j+1][idx-j]=max(dp[j+1][idx-j],dp[j][idx-j]+(i-j)*x) dp[j][idx-j+1]=max(dp[j][idx-j+1],dp[j][idx-j]+((n-1-(idx-j))-i)*x) print(max([dp[i][n-i] for i in range(n+1)]))
n = int(input()) a = [(int(x), i) for i, x in enumerate(input().split())] a.sort(reverse=True) aval, ai = zip(*a) dp = [[0] * (n+1) for _ in range(n+1)] for l in range(n): for r in range(n): if l + r >= n: break dp[l+1][r] = max(dp[l+1][r], dp[l][r] + aval[l+r] * abs(ai[l+r]-l)) dp[l][r+1] = max(dp[l][r+1], dp[l][r] + aval[l+r] * abs(ai[l+r]-(n-r-1))) print(max([dp[i][n-i] for i in range(n+1)]))
1
33,816,603,655,572
null
171
171
inf = float("inf") S = input() N = len(S) bestP = [None for i in range(N)] bestD = [None for i in range(N)] if S[0] in ["?", "D"]: bestP[0] = 0 bestD[0] = 1 else: bestP[0] = 0 bestD[0] = 0 for i in range(1, N): bestP[i] = max(bestD[i - 1], bestP[i - 1]) bestD[i] = max(bestD[i - 1] + 1, bestP[i - 1] + 2) if S[i] != "?": if S[i] == "P": bestD[i] = -inf else: assert S[i] == "D" bestP[i] = -inf ans = [None for i in range(N)] if bestP[-1] > bestD[-1]: ans[-1] = 'P' else: ans[-1] = 'D' for i in range(N - 2, -1, -1): if S[i] != '?': ans[i] = S[i] else: prev = ans[i + 1] if prev == 'D': if bestP[i] + 2 > bestD[i] + 1: ans[i] = 'P' else: ans[i] = 'D' else: if bestP[i] > bestD[i]: ans[i] = 'P' else: ans[i] = 'D' print(''.join(ans))
import itertools a = [0, 1, 2, 3, 4, 5] x = int(input()) n = x // 100 m = x % 100 for c in itertools.combinations_with_replacement(a, n): if sum(c) == m: print(1) break else: print(0)
0
null
72,623,964,005,792
140
266
n = int(input()) a = list(map(int, input().split())) iseven=(n%2==0) if n==2: print(max(a)) exit() dp = [[-float("inf") for _ in range(3)] for _ in range(n)] dp[0][0]=a[0] dp[1][1]=a[1] if n>2: dp[2][2]=a[2] for i in range(n): for k in range(3): if i+2<n: dp[i+2][k] = max(dp[i+2][k], dp[i][k] + a[i+2]) if k<=1 and i+3<n: dp[i+3][k+1] = max(dp[i+3][k+1], dp[i][k] + a[i+3]) if not iseven and k==0 and i+4<n: dp[i+4][k+2] = max(dp[i+4][k+2], dp[i][k] + a[i+4]) if iseven: ans=max([dp[-1][0],dp[-1][1]]) else: ans=max([dp[-3][0],dp[-2][1],dp[-1][2]]) print(ans)
N = int(input()) V = [0]*10000 for j in range (1, 100): for k in range (1, 100): for l in range (1, 100): if j**2+k**2+l**2+j*k+k*l+j*l < 10001: V[j**2+k**2+l**2+j*k+k*l+j*l-1]+=1 for i in range (0, N): print(V[i])
0
null
22,614,350,803,616
177
106
m,n=map(long,raw_input().split()) print m/n, print m%n, print '%.5f' % (float(m)/n)
a, b = map(int, input().split(" ")) print("%d %d %.5f" %(a/b, a%b, a/b))
1
612,775,923,320
null
45
45
S = input() if S == "hi" * (len(S)//2): print("Yes") else: print("No")
s = list(input()) if len(s) % 2 != 0: print("No") exit() while s: if s[0]=="h" and s[1] == "i": s.pop(0) s.pop(0) else: print("No") exit() print("Yes")
1
52,935,238,019,290
null
199
199
s=input() rs=s[::-1] ans=0 for i in range (len(s)): if s[i] != rs[i]: ans+=1 print(ans//2)
n = int(raw_input()) A = map(int, raw_input().strip().split(' ')) q = int(raw_input()) M = map(int, raw_input().strip().split(' ')) def ans(i, m): if m == 0: return 1 if i >= n or m > sum(A): return 0 res = ans(i + 1, m) or ans(i + 1, m - A[i]) return res for j in range(0, q): if ans(0, M[j]): print "yes" else: print"no"
0
null
60,406,673,405,472
261
25
a=[] for i in range(2): m=input().split() a.append(m) list_1=[int(l) for l in a[0]] list_2=[int(l) for l in a[1]] total=0 largest=list_2[0] smallest=list_2[0] for x in range(list_1[0]): if largest<list_2[x]: largest=list_2[x] if smallest>list_2[x]: smallest=list_2[x] for x in list_2: total+=x print(smallest,largest,total)
import sys N,K=map(int,input().split()) if N<K: print(1) sys.exit() M=K R=1 while M<=N: M*=K R+=1 print(R)
0
null
32,532,160,813,392
48
212
b = input() a = input().split() for i in range(len(a)): a[i] = int(a[i]) max_a = max(a) min_a = min(a) Sum = sum(a) print(min_a,max_a,Sum)
from collections import deque n = int(input()) M = [[0]*n for _ in range(n)] d = [-1]*n st = [0]*n for _ in range(n): i = [int(i) for i in input().split()] u = i[0] k = i[1] V = i[2:] for v in V: M[u-1][v-1] = 1 def bfs(s): Q = deque() Q.append(s) st[s] = 1 d[s] = 0 while Q: u = Q.popleft() for v in range(n): if M[u][v] and st[v] == 0: st[v] = 1 Q.append(v) d[v] = d[u]+1 st[u] = 2 return bfs(0) for i in range(n): print(i+1,d[i])
0
null
373,518,968,312
48
9
import sys import math #https://atcoder.jp/contests/agc008/submissions/15248942 sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inm = lambda: map(int, sys.stdin.readline().split()) inl = lambda: list(inm()) ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) N = ini() S = input() ans = 0 for i in range(1000): V = str(i).zfill(3) p1 = S.find(V[0]) if p1 != -1: p2 = S.find(V[1], p1+1) if p2 != -1: p3 = S.find(V[2], p2+1) if p3 != -1: ans += 1 print(ans)
N = int(input()) S = input() ''' Editorialのヒントを参照しました。 000 ~ 999の実現可能性を考えます。 ''' L = [] s = '' Comb = 0 key_k = False for i in range(0, 10): for j in range(0, 10): if key_k is not True: s += str(j) else: s += str(i) s += str(j) key_k = False for k in range(0, 10): s += str(k) L.append(s) s = '' s += str(i) s += str(j) s = '' key_k = True L.remove(L[0]) L.append('000') #生成、もう少し短くしたい S_copy = S A = [] for el in L: c0 = el[0] c1 = el[1] c2 = el[2] S = S_copy N0 = S.find(c0) if N0 == -1: continue else: S = S[N0+1::] N1 = S.find(c1) if N1 == -1: continue else: S = S[N1+1::] N2 = S.find(c2) if N2 == -1: continue else: Comb += 1 print(Comb)
1
128,745,897,531,020
null
267
267
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10 ** 9) def main(): N, K, S = map(int, input().split()) A = [S for _ in range(K)] if S != 10 ** 9: B = [S + 1 for _ in range(N - K)] else: B = [S - 1 for _ in range(N - K)] C = A + B print(*C, sep=" ") if __name__ == "__main__": main()
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)
1
91,393,134,089,066
null
238
238
import queue N = int(input()) def common_divisors(n): i = 1 res = [] while i*i <= n: if n % i == 0: res.append(i) res.append(n//i) if i*i == n: res.pop() i += 1 return res ans = 0 ans += len(common_divisors(N-1))-1 for i in common_divisors(N): if i == 1: continue n = N while n % i == 0: n /= i if n % i == 1: ans += 1 print(ans)
n=int(input()) if n%2==0:print(n//2) else:print(n//2+1)
0
null
50,170,140,141,760
183
206
import math import fractions import collections import itertools from collections import deque S=input() N=len(S) cnt=0 l=[] """ cnt=0 p=10**9+7 for i in range(K,N+2): cnt=(cnt+((N-i+1)*i)+1)%p #print(((N-i+1)*i)+1) print(cnt) """ amari=[0]*(N+1) num=0 for i in range(N): num=num+pow(10,i,2019)*int(S[N-1-i]) amari[i+1]=num%2019 #print(amari) c=collections.Counter(amari) values=list(c.values()) #aのCollectionのvalue値のリスト(n_1こ、n_2こ…) key=list(c.keys()) #先のvalue値に相当する要素のリスト(要素1,要素2,…) #for i in range(len(key)): # l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix #xprint(l) for i in range(len(values)): cnt=cnt+(values[i]*(values[i]-1))//2 print(cnt)
import sys # import re import math import collections # import decimal import bisect import itertools import fractions # import functools import copy import heapq import decimal # import statistics import queue # import numpy as np sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 # MOD = 998244353 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): s = input() cnt = [0 for _ in range(2019)] cnt[0] += 1 dec = 1 num = 0 for i in reversed(s): num += int(i) * dec num %= 2019 dec *= 10 dec %= 2019 cnt[num] += 1 ans = 0 for c in cnt: ans += c * (c - 1) // 2 print(ans) if __name__ == '__main__': main()
1
30,583,554,260,228
null
166
166
def main(): k, n = map(int, input().split(" ")) a = list(map(int, input().split(" "))) d =[min(a)+k-max(a)] for i in range(n-1): d.append(a[i+1]-a[i]) print(k-max(d)) if __name__ == "__main__": main()
K, N = map(int, input().split()) A = list(map(int, input().split())) c = abs(K - A[N-1] + A[0]) for i in range(N-1): d = abs(A[i] - A[i+1]) if c < d: c = d else: c = c print(K-c)
1
43,438,110,556,412
null
186
186
N=list(input()) M=list(input()) ans=0 number=len(N) for i in range(number): if N[i]==M[i]: ans+=1 print(number-ans)
import collections N=int(input()) A=list(map(int,input().split())) cc=collections.Counter(A) L=list(cc.values()) total=0 for i in range(len(L)): total+=L[i]*(L[i]-1)//2 ans=0 for a in A: temp=cc[a]*(cc[a]-1)//2 ttemp=(cc[a]-1)*(cc[a]-2)//2 ans=total-temp+ttemp print(ans)
0
null
29,227,011,308,352
116
192
n = int(input()) nums = list(map(int, input().split())) ans = 0 for idx in range(1, n): if nums[idx] - nums[idx-1] < 0: ans += abs(nums[idx] - nums[idx-1]) nums[idx] = nums[idx-1] print(ans)
# A - DDCC Finals def main(): X, Y = map(int, input().split()) prize_table = {1: 300000, 2: 200000, 3: 100000} prize = 0 for rank in (X, Y): if rank in prize_table: prize += prize_table[rank] if X == Y and X == 1: prize += 400000 print(prize) if __name__ == "__main__": main()
0
null
72,269,860,438,272
88
275
from math import floor from fractions import Fraction a,b = input().split() a = int(a) b = Fraction(b) print(floor(a*b))
x = input() a = list(map(int, input().split())) print(f'{min(a)} {max(a)} {sum(a)}')
0
null
8,619,110,866,652
135
48
def solve(): N = int(input()) L = list(map(int, input().split())) count = 0 for i in range(N): for j in range(i+1, N): for k in range(j+1, N): if(L[i] != L[j] and L[j] != L[k] and L[k] != L[i]): if(L[i]+L[j] > L[k] and L[j]+L[k] > L[i] and L[k]+L[i] > L[j]): count += 1 print(count) if __name__ == "__main__": solve()
import sys #from collections import deque #from functools import * #from fractions import Fraction as f from copy import * from bisect import * #from heapq import * from math import gcd,ceil,sqrt from itertools import permutations as prm,product def eprint(*args): print(*args, file=sys.stderr) zz=1 #sys.setrecursionlimit(10**6) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') di=[[-1,0],[1,0],[0,1],[0,-1]] def inc(d,c,x=1): d[c]=d[c]+x if c in d else x def bo(i): return ord(i)-ord('A') def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def comp(a,b): if(a>b): return 2 return 2 if a==b else 0 def gi(): return [xx for xx in input().split()] def fi(): return int(input()) def pro(a): return reduce(lambda a,b:a*b,a) def swap(a,i,j): a[i],a[j]=a[j],a[i] def si(): return list(input().rstrip()) def mi(): return map(int,input().split()) def gh(): sys.stdout.flush() def isvalid(i,j): return 0<=i<n and 0<=j<m and a[i][j]!="." def bo(i): return ord(i)-ord('a') def graph(n,m): for i in range(m): x,y=mi() a[x].append(y) a[y].append(x) t=1 mod=998244353 while t>0: t-=1 n,k,m=mi() vis={} cycle=[] i=ans=0 while k not in vis: cycle.append(k) vis[k]=i i+=1 ans+=k if i==n: print(ans) exit(0) k=(k**2)%m if k in vis: cycle=cycle[vis[k]:] n-=i s=sum(cycle) p=n%len(cycle) z=len(cycle) print(ans+(n//z)*s+sum(cycle[:p]))
0
null
3,942,686,751,276
91
75
import statistics while True: n = input() if n == '0': break print(statistics.pstdev(map(int, input().split())))
import sys def input(): return sys.stdin.readline().rstrip() def main(): S = input() T = input() len_s = len(S) len_t = len(T) ans = 1000 for i in range(len_s-len_t+1): cunt = 0 for j in range(len_t): if S[i+j] != T[j]: cunt += 1 ans = min(ans, cunt) print(ans) if __name__=='__main__': main()
0
null
1,914,899,463,110
31
82
from collections import Counter def main(): n,x,y=map(int,input().split()) x,y=x-1,y-1 ans=[] for i in range(n): dp = [n]*n dp[i] = 0 calcstep(i, dp) dp[y] = min(dp[y], dp[x]+1) dp[x] = min(dp[x], dp[y]+1) calcstep(x, dp) calcstep(y, dp) #print(i, dp) ans += dp ans = Counter(ans) for i in range(1,n): print(ans[i]//2) def calcstep(i, dp): for j in range(i, len(dp)-1): if dp[j+1] > dp[j]+1: dp[j+1] = dp[j]+1 else: break for j in range(1,i+1)[::-1]: if dp[j-1] > dp[j]+1: dp[j-1] = dp[j]+1 else: break if __name__ == "__main__": main()
n,x,y = map(int, input().split()) ans = [0]*n for i in range(1,n): for j in range(i+1,n+1): v1 = j-i v2 = abs(x-i) + 1 + abs(y-j) v3 = abs(y-i) + 1 + abs(x-j) minv = min(v1,v2,v3) ans[minv] += 1 for a in ans[1:]: print(a)
1
44,383,229,433,872
null
187
187
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline()) for i in range(n)) class Combination: """ comb = Combination(1000000) print(comb(5, 3)) # 10 """ def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod def make_factorial_list(self, n): # 階乗のリストと階乗のmod逆元のリストを返す O(n) # self.make_modinv_list()が先に実行されている必要がある fac = [1] facinv = [1] for i in range(1, n+1): fac.append(fac[i-1] * i % self.mod) facinv.append(facinv[i-1] * self.modinv[i] % self.mod) return fac, facinv def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n) modinv = [0] * (n+1) modinv[1] = 1 for i in range(2, n+1): modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod return modinv n,k = inpl() m = min(n-1,k) res = 1 if m == 1: print((n-1)*n%mod) quit() comb = Combination(n+10) for i in range(m): res += comb(n,i+1) * comb(n-1,n-i-2) res %= mod print(res)
class Combination: def __init__(self, size, mod=10**9 + 7): self.size = size + 2 self.mod = mod self.fact = [1, 1] + [0] * size self.factInv = [1, 1] + [0] * size self.inv = [0, 1] + [0] * size for i in range(2, self.size): self.fact[i] = self.fact[i - 1] * i % self.mod self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod def npr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * self.factInv[n - r] % self.mod def ncr(self, n, r): if n < r or n < 0 or r < 0: return 0 return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod def nhr(self, n, r): # 重複組合せ return self.ncr(n + r - 1, n - 1) def factN(self, n): if n < 0: return 0 return self.fact[n] N, K = map(int, input().split()) K = min(K, N) MOD = 10**9 + 7 comb = Combination(N + 100) ans = 0 for k in range(K + 1): ans += comb.ncr(N, k) * comb.nhr(N - k, k) ans %= MOD print(ans)
1
66,884,540,485,828
null
215
215
N=int(input()) k=N%1000 if k==0: t=0 else: t=1000-k print(t)
import math def abc173a_payment(): n = int(input()) print(math.ceil(n/1000)*1000 - n) abc173a_payment()
1
8,434,344,620,128
null
108
108
# 154 A s, t = input().split() a, b = map(int, input().split()) u = input() if u == s: a = a - 1 elif u == t: b = b - 1 print(a, end = " ") print(b)
s1, s2 = input().split() n1, n2 = map(int, input().split()) u = input() if u == s1: n1 -= 1 else: n2 -= 1 print(n1, n2)
1
72,021,215,632,170
null
220
220
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) mid = sum(A) / 2 x = 0 near_length = 0 for a in A: x += a if x >= mid: if x - mid > abs(x - a - mid): near_length = abs(x - a) else: near_length = x break ans = int(abs(mid-near_length) * 2) print(ans) if __name__ == "__main__": main()
N=int(input()) A=list(map(int,input().split())) B=sum(A) b=0 ans=202020202020 for a in A: b+=a ans=min(ans,abs(B-b*2)) print(ans)
1
142,003,686,257,440
null
276
276