input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C ) # なぜか2WAが取れない # 嘘解法? N, C = list(map(int, input().split())) x = 2 * (10**5) # x = 30 # test imos = [[0 for _ in range(x)] for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) s, t, c = s * 2 - 1, t * 2 - 1, c - 1 im...
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C ) # なぜか2WAが取れない # これ嘘解法ぽい気がする N, C = list(map(int, input().split())) x = 2 * (10**5) # x = 30 # test imos = [[0 for _ in range(x)] for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) s, t, c = s * 2 - 1, t * 2 - 1, c - 1 ...
p03504
N,C = list(map(int, input().split())) L = [[int(a) for a in input().split()] for _ in range(N)] ans = [[0, 0] for _ in range(C)] L.sort() for i in range(N): j = 0 while j < C: if ans[j][0] == L[i][0] and ans[j][1] == L[i][2]: ans[j][0] = L[i][1] j = C elif ans...
N,C = list(map(int, input().split())) L = [[int(a) for a in input().split()] for _ in range(N)] ans = [0]*C chan = [0]*C L.sort() for i in range(N): for j in range(C): if ans[j] == L[i][0] and chan[j] == L[i][2]: ans[j] = L[i][1] break elif ans[j] < L[i][0]: ...
p03504
# heapqの方針で上手くいかなかった # 解説放送を見てimosにした def main(): from collections import namedtuple from heapq import heappop, heappush import sys input = sys.stdin.readline Prog = namedtuple('Prog', 'L R') Prog.__eq__ = lambda self, other: self.R == other.R Prog.__lt__ = lambda self, other: s...
# heapqの方針で上手くいかなかった # 解説放送を見てimosにした def main(): from collections import namedtuple from heapq import heappop, heappush import sys input = sys.stdin.readline Prog = namedtuple('Prog', 'L R') Prog.__eq__ = lambda self, other: self.R == other.R Prog.__lt__ = lambda self, other: s...
p03504
import copy N,C=list(map(int,input().split())) channel=[tuple(map(int,input().split())) for i in range(N)] channel=sorted(channel,key=lambda cha: cha[0]) n=0 while(channel!=[]): c=copy.copy(channel) n+=1 pro=channel[0] c.remove(pro) for i in channel: if i[0]>pro[1]: ...
N,C=list(map(int,input().split())) channel=[tuple(map(int,input().split())) for i in range(N)] channel=sorted(channel,key=lambda cha: cha[0]) n=0 while(channel!=[]): c=[] n+=1 pro=channel[0] channel.remove(pro) for i in channel: if i[0]>pro[1]: pro=i elif(i[...
p03504
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, ...
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, ...
p03504
# -*- coding: utf-8 -*- N, C = list(map(int, input().split())) T = 10**5+2 c_ls = [[0] * T for _ in range(C)] # いもす for i in range(N): s, t, c = list(map(int, input().split())) c_ls[c-1][s] += 1 c_ls[c-1][t] -= 1 # 各チャンネル毎の累積和 for i in range(C): for j in range(1, T): c_ls[i][j] +...
# -*- coding: utf-8 -*- import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in rang...
p03504
if __name__ == "__main__": n,c = list(map(int, input().split())) timeline = {} for i in range(n): s, t, c = list(map(int, input().split())) for i in range(s-1, t): xs = timeline.get(i, None) if xs is None: xs = set() xs.add(c)...
def getter(starts, ends): while starts: if starts[-1][0] < ends[-1][1]: yield (starts.pop(), True) else: yield (ends.pop(), False) def foo(C, targets): starts = sorted(targets, key=lambda x:x[0], reverse=True) ends = sorted(targets, key=lambda x: x[1], rev...
p03504
N, C, *STC = list(map(int, open(0).read().split())) T = [[0] * 10 ** 5 for _ in range(C + 1)] for s, t, c in zip(*[iter(STC)] * 3): T[c][s - 1:t] = [1] * (t - s + 1) print((max(list(map(sum, list(zip(*T)))))))
def main(): N, C, *STC = list(map(int, open(0).read().split())) T = [[0] * 10 ** 5 for _ in range(C + 1)] for s, t, c in zip(*[iter(STC)] * 3): T[c][s - 1:t] = [1] * (t - s + 1) print((max(list(map(sum, list(zip(*T))))))) main()
p03504
# -*- coding: utf-8 -*- from operator import itemgetter N,C = list(map(int, input().split())) record = [] for _ in range(N): s,t,c = list(map(int, input().split())) record.append((s,t,c)) record.sort(key=itemgetter(1,0,2)) def can_record(k): slots = [(-1,-1)]*k # (end_time, channel) for...
# -*- coding: utf-8 -*- from operator import itemgetter N,C = list(map(int, input().split())) T = 0 record = [] for _ in range(N): s,t,c = list(map(int, input().split())) T = max(T, t) record.append((s,t,c)) record.sort(key=itemgetter(2,0,1)) tl = [0]*(T+1) curr_channel = None for r in recor...
p03504
import collections N,C=list(map(int,input().split())) #print N,C d = collections.defaultdict(list) start=float("inf") end=0 for i in range(N): s,t,c=list(map(int,input().split())) d[c].append((s,t)) start=min(start,s) end=max(end,t) #print start,end #print d [d[i].sort() for i in list(d.keys())] #pr...
import collections N,C=list(map(int,input().split())) a=collections.defaultdict(list) max_t=0 for i in range(N): s,t,c=list(map(int,input().split())) a[c].append((s,t)) max_t=max(max_t,t) [a[i].sort() for i in list(a.keys())] #print a #print max_t b=collections.defaultdict(list) for i,j in list...
p03504
import collections N,C=list(map(int,input().split())) a=collections.defaultdict(list) max_t=0 for i in range(N): s,t,c=list(map(int,input().split())) a[c].append((s,t)) max_t=max(max_t,t) [a[i].sort() for i in list(a.keys())] #print a #print max_t b=collections.defaultdict(list) for i,j in list...
# -*- coding: utf-8 -*- import sys from collections import deque N,C=list(map(int, sys.stdin.readline().split())) stc=[ list(map(int, sys.stdin.readline().split())) for _ in range(N)] stc.sort(key=lambda x:(x[0]) ) max_t=max(stc, key=(lambda x: x[1]))[1] channel=[ deque() for _ in range(C+1) ] for s,t,c ...
p03504
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.rea...
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.re...
p03504
N,C = list(map(int,input().split())) ch = {} for _ in range(N): s,t,c = list(map(int,input().split())) if c not in ch: ch[c] = [0 for _ in range(2*10**5+2)] for i in range(2*s-1,2*t): ch[c][i]=1 cmax = 0 for i in range(2*10**5+2): cnt = 0 for c in ch: if ch[c][i]=...
N,C = list(map(int,input().split())) G = {i:[0 for _ in range(10**5+1)] for i in range(1,C+1)} for i in range(N): s,t,c = list(map(int,input().split())) G[c][s] += 1 G[c][t] -= 1 F = [0 for _ in range(2*(10**5)+1)] for c in range(1,C+1): for i in range(10**5+1): if G[c][i]==1: ...
p03504
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] ...
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] ...
p03504
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] ...
import sys N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,sys.stdin.readline().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i]...
p03504
n,C = list(map(int,input().split())) INF = float("INF") ch = [[0]*(200001) for _ in range(C)] m = 0 for _ in range(n): s,t,c = list(map(int,input().split())) s = s*2-1 t *= 2 c -= 1 ch[c][s] += 1 ch[c][t] -= 1 m = max(m,t) cnt = [0]*(m+1) for c in range(C): for i in range...
n,C = list(map(int,input().split())) ch = [[0]*(200001) for _ in range(C)] m = 0 for _ in range(n): s,t,c = list(map(int,input().split())) s = s*2-1 t *= 2 c -= 1 ch[c][s] += 1 ch[c][t] -= 1 m = max(m,t) cnt = [0]*(m+1) for c in range(C): for i in range(1,m+1): ch...
p03504
def func(): tvs = [] for i in range(num): tvs.append((-1, -1)) for i in range(len(bans)): now = bans[i][0] can = bans[i][2] tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can] for j, tv in enumerate(tvs): if tv[1] == -1 o...
def func(): tvs = [] for i in range(num): tvs.append((-1, -1)) for i in range(len(bans)): now = bans[i][0] can = bans[i][2] # tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can] for j, tv in enumerate(tvs): if tv[1] == -1...
p03504
N, C = list(map(int, input().split())) program = [] program_list = [0 for _ in range((((10 ** 5) * 2) + 10))] for _ in range(C + 1): program.append(program_list.copy()) sm = program_list.copy() s_list = [] t_list = [] c_list = [] for _ in range(N): s, t, c = list(map(int, input().split())) s_li...
N, C = list(map(int, input().split())) program = [] program_list = [False for _ in range((((10 ** 5) * 2) + 10))] for _ in range(C + 1): program.append(program_list.copy()) for _ in range(N): s, t, c = list(map(int, input().split())) s2 = (t * 2) - ((s * 2) - 1) program[c][(s * 2) - 1:t * 2] =...
p03504
N,C = list(map(int,input().split())) T = [[0 for i in range(10**5+1)] for j in range(30)] for i in range(N): s,t,c = list(map(int,input().split())) T[c-1][s] += 1 T[c-1][t] -= 1 for i in range(C): for j in range(10**5): T[i][j+1] += T[i][j] for i in range(C): for j in range(10*...
n,c = list(map(int,input().split())) t = [[0 for i in range(100001)] for j in range(c)] for i in range(n): si,ti,ci = list(map(int,input().split())) for j in range(si,ti+1): t[ci-1][j] = 1 ans = 0 for i in range(100001): ans = max(ans,sum(t[j][i] for j in range(c))) print(ans)
p03504
N,C = list(map(int,input().split())) src = [list(map(int,input().split())) for i in range(N)] MAX = 10**5 bucket = [[] for i in range(MAX+2)] bucket2 = [set() for i in range(MAX+2)] for s,t,c in src: bucket[s].append((t,c)) bucket2[s].add(c) imos = [0]*(MAX+2) for s in range(MAX): for t,c in b...
N,C = list(map(int,input().split())) STC = [tuple(map(int,input().split())) for i in range(N)] cs = [[] for _ in range(30)] for s,t,c in STC: cs[c-1].append((s,t)) imos = [0]*(100005) for c in cs: c.sort(key=lambda x:x[0]) pt = -1 for s,t in c: if s==pt: imos[s] += 1 ...
p03504
N,C = list(map(int,input().split())) P = [[] for i in range(C)] for i in range(N): s,t,c = list(map(int,input().split())) P[c-1].append([s,"S"]) P[c-1].append([t,"T"]) P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)] #print(P) P2 = [] for i in range(C): ...
N,C = list(map(int,input().split())) program_list = [] for i in range(N): s,t,c = list(map(int,input().split())) program_list.append((s-0.5,"s",c-1)) program_list.append((t,"t",c-1)) program_list.sort(key=lambda x:x[0]) c_list=[0 for i in range(C)] count_list=[0 for i in range(C)] max_num...
p03504
def LI(): return list(map(int, input().split())) def LS(): return input().split() def I(): return int(eval(input())) def S(): return eval(input()) n, c = LI() l = [] for i in range(n): l.append(LI()) start = 0 end = 0 ans = 0 l.sort(key=lambda x: x[1]) #print(l) while(len(l) > 0): ans += 1 ...
def LI(): return list(map(int, input().split())) def LS(): return input().split() def I(): return int(eval(input())) def S(): return eval(input()) n, c = LI() l = [] for i in range(n): l.append(LI()) #チャンネル見る必要がある #同じチャンネルで連続しているものはくっつける la = [[[], []] for i in range(c)] for i in l: la[i[2] - 1]...
p03504
n,c = list(map(int,input().split())) arr = [[0 for i in range((10**5+2) * 2)] for i in range(c)] for i in range(n): s,t,ch = list(map(int,input().split())) arr[ch-1][s*2-1] = 1 arr[ch-1][t*2] = -1 for i in range(c): for j in range(1,(10**5+2)*2): arr[i][j] = arr[i][j-1] + arr[i][j] ans = 0 f...
n, c = list(map(int, input().split())) r = [[0 for i in range(c)] for j in range(100000)] for dummy in range(n): s, t, c = list(map(int, input().split())) for j in range(s - 1, t): r[j][c - 1] = 1 ans = 0 for i in range(100000): if sum(r[i]) > ans: ans = sum(r[i]) print(a...
p03504
n,c=[int(i) for i in input().split()] s=[] t=[] for _ in range(n): a=[int(i) for i in input().split()] s.append(a[0]-0.5) t.append(a[1]) s.sort() t.sort() x=0 m=0 while s !=[] or t !=[]: if s==[]: x-=1 del t[0] elif t==[]: x+=1 del s[0] else: if s[0] < t[0]: x...
n,c=[int(i) for i in input().split()] s0=[] t0=[] for _ in range(n): a=[int(i) for i in input().split()] s0.append((a[0],a[2])) t0.append((a[1],a[2])) s1=set(s0) t1=set(t0) s2=list(s1.difference(t0)) t2=list(t1.difference(s0)) s=[i[0]-0.5 for i in s2] t=[i[0] for i in t2] s.sort() t.sort() x=0 m...
p03504
#!/usr/bin/env python3 N, C = list(map(int, input().split())) table = [[0] * C for i in range(2 * 10 ** 5 + 2)] for i in range(N): s, t, c = list(map(int, input().split())) table[2 * s - 1][c - 1] = 1 table[2 * t][c - 1] = -1 ans = [0] * (2 * 10 ** 5 + 2) for i in range(1, 2 * 10 ** 5 + 2): f...
#!/usr/bin/env python3 N, C = list(map(int, input().split())) table = [[0] * C for i in range(10 ** 5 + 1)] for i in range(N): s, t, c = list(map(int, input().split())) table[s - 1][c - 1] += 1 table[t - 1][c - 1] -= 1 imos = [0] * (10 ** 5 + 1) for i in range(10 ** 5 + 1): for j in range(C):...
p03504
n, c = list(map(int, input().split())) MAX_COLS = 10**5 table = [[0 for _ in range(MAX_COLS)] for _ in range(c)] for _ in range(n): s, t, i = list(map(int, input().split())) for j in range(s - 1, t - 1): table[i - 1][j] = 1 for i in range(c): for j in range(MAX_COLS - 1): if tab...
n, c = list(map(int, input().split())) MAX_COLS = 10**5 table = [[0 for _ in range(MAX_COLS)] for _ in range(c)] for _ in range(n): s, t, i = list(map(int, input().split())) for j in range(max(0, s - 2), t - 1): table[i - 1][j] = 1 res = 0 for j in range(MAX_COLS): count = 0 for i ...
p03504
N,C = list(map(int, input().split())) s =[0]*N t =[0]*N c =[0]*N for i in range(N): s[i],t[i],c[i] = list(map(int, input().split())) imos = [[0]*int(1e5+20) for _ in range(31)] for i in range(N): imos[c[i]][s[i]]+=1 imos[c[i]][t[i]+1]-=1 ans = 0 for i in range(1,int(1e5+10)): sm = 0 ...
N,C = list(map(int, input().split())) s =[0]*N t =[0]*N c =[0]*N for i in range(N): s[i],t[i],c[i] = list(map(int, input().split())) imos = [[0]*int(1e5+20) for _ in range(31)] for i in range(N): imos[c[i]][s[i]]+=1 imos[c[i]][t[i]+1]-=1 ans = 0 for i in range(1,int(1e5+10)): sm = 0 ...
p03504
def d_recording(N, C, R): """ N:録画する番組の数 C:テレビが受信できるチャンネルの数 R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc] """ s = [row[0] for row in R] t = [row[1] for row in R] c = [row[2] for row in R] # いつまで録画機を動かすか。0.5を単位時間とするので*2 # 時刻を0からスタートさせるので+2 l = max(t) * 2 + 2 sm = [0 for _...
def d_recording(N, C, R): # N:録画する番組の数 # C:テレビが受信できるチャンネルの数 # R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc] from itertools import accumulate start = [row[0] for row in R] end = [row[1] for row in R] channel_num = [row[2] for row in R] # いつまで録画機を動かすか。0.5を単位時間とするので*2 # 時刻を0からスタートさせるので+2 ...
p03504
n, c = list(map(int, input().split())) T = 10**5+1 l = [[0]*c for _ in range(T)] for _ in range(n): s, t, c_ = list(map(int, input().split())) c_ -= 1 l[s-1][c_] += 1 l[t][c_] -= 1 for i in range(1, T): for c_ in range(c): l[i][c_] += l[i-1][c_] l[i-1][c_] = min(1, l...
n, c = list(map(int, input().split())) T = 10**5+1 l = [[0]*c for _ in range(T)] for _ in range(n): s, t, c_ = list(map(int, input().split())) c_ -= 1 for i in range(s-1, t): l[i][c_] = 1 ans = 0 for i in range(T): ans = max(ans, sum(l[i])) print(ans)
p03504
import sys input=sys.stdin.buffer.readline n,c=list(map(int,input().split())) a=[ [0 for _ in range(10**5+2)] for _ in range(c)] for _ in range(n): s,t,cc=list(map(int,input().split())) cc-=1 # print(s-1,end=' s-1\n') #a[cc][s-1]+=1 #a[cc][t]-=1 for i in range(s-1,t): a[cc][i]=...
import sys input=sys.stdin.buffer.readline n,c=list(map(int,input().split())) a=[ [0 for _ in range(10**5+2)] for _ in range(c)] for _ in range(n): s,t,cc=list(map(int,input().split())) cc-=1 # print(s-1,end=' s-1\n') #a[cc][s-1]+=1 #a[cc][t]-=1 for i in range(s-1,t): a[cc][i]=...
p03504
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R()...
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R()...
p03504
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R()...
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R()...
p03504
_ = eval(input()) a = [int(i) for i in input().split(' ')] res = 9999999999999999999999999 for i in range(1,len(a)): s = sum(a[:i]) t = sum(a[i:]) temp = abs(s-t) res = min(temp,res) print(res)
import sys n = int(eval(input())) a = [] b = input().split(" ") for i in range(n): a.append(int(b[i])) for i in range(1, n): a[i] += a[i-1] mn = abs(a[n-1] - 2*a[0]) for i in range(1, n-1): mn = min(mn, abs(a[n-1] - 2*a[i])) print(mn)
p03661
# ABC067C - Splitting Pile (ARC078C) def main(): n = int(eval(input())) lst = tuple(map(int, input().rstrip().split())) l, r, ans = 0, sum(lst), float("inf") for i in lst[:-1]: l += i r -= i ans = min(ans, abs(l - r)) print(ans) if __name__ == "__main__": m...
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) ans = min(abs(lst[-1] - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
p03661
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) ans = min(abs(lst[-1] - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) total = lst[-1] ans = min(abs(total - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
p03661
n=int(eval(input())) a=list(map(int,input().split())) total=sum(a) x=0 lis=[] for i in range(n-1): x+=a[i] lis.append(abs(2*x-total)) print((min(lis)))
n=int(eval(input())) a=list(map(int,input().split())) total=sum(a) x=0 ans=abs(max(a)-min(a)) for i in range(n-1): x+=a[i] if abs(2*x-total)<ans: ans=abs(2*x-total) print(ans)
p03661
N = int(eval(input())) a = list(map(int, input().split())) S = sum(a) arr = [abs(S - 2*sum(a[:i])) for i in range(1,N)] print((min(arr)))
N = int(eval(input())) a = list(map(int, input().split())) S = sum(a) _min = 10000000000000000000 x = 0 for i in range(0,N-1): x += a[i] tmp = abs(S - 2*x) if tmp < _min: _min = tmp print(_min)
p03661
n,*A=list(map(int,open(0).read().split())) for i in range(n-1):A[i+1]+=A[i] print((min(abs(A[n-1]-A[i]*2)for i in range(n-1))))
n,*A=list(map(int,open(0).read().split())) while n>1:n-=1;A[n-1]+=A[n] print((min(abs(A[0]-e*2)for e in A[1:])))
p03661
def main(): N = int(eval(input())) a = list(map(int, input().split())) #N = 1000 #a = [i for i in range(N)] #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)] summation = [] sumtemp = sum(a) for i in range(len(a)-1): tmp1 = sum(a[:(i+1)]) ...
def main(): N = int(eval(input())) a = list(map(int, input().split())) #N = 1000 #a = [i for i in range(N)] #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)] summation = [] sumtemp = sum(a) tmp1 = 0 for i in range(len(a)-1): tmp1 += a[...
p03661
class SegmentTree: def __init__(self, lst, op, e): self.n = len(lst) self.N = 2**((self.n-1).bit_length()) self.op = op # operation self.e = e # identity element self.v = [None]*(2*self.N-1) # construction for i in range(self.N): ...
N = int(eval(input())) *A, = list(map(int, input().split())) total = sum(A) snuke = 0 ans = 10**18 for i in range(N-1): snuke += A[i] arai = total - snuke ans = min(ans, abs(arai - snuke)) print(ans)
p03661
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/2/ Solved on 2019/2/ @author: shinjisu """ # ARC 078 C Splitting Pile def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0]*n def getIntLines(n): return [int(inp...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/2/ Solved on 2019/2/ @author: shinjisu """ # ARC 078 C Splitting Pile def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0]*n def getIntLines(n): return [int(inp...
p03661
N = int(eval(input())) a = list(map(int,input().split())) cum_sum = [0]*N cum_sum[0] = a[0] for i in range(1,N): cum_sum[i] = cum_sum[i-1] + a[i] res = 10**15 for i in range(N-1): x = cum_sum[i] y = cum_sum[N-1] - cum_sum[i] res = min(res, abs(x-y)) print(res)
N = int(eval(input())) a = list(map(int,input().split())) x = a[0] y = sum(a[1:]) res = abs(x - y) for i in range(1, N - 1): x += a[i] y -= a[i] res = min(res, abs(x - y)) print(res)
p03661
N = eval(input()) a = list(map(int, input().split())) all = sum(a) mini = 10000000000 for i in range(1,N): x = sum(a[:i]) y = all - x ret = abs(x-y) if(ret < mini): mini=ret print(mini)
N = eval(input()) a = list(map(int, input().split())) all = sum(a) mini = 10000000000 x = 0 y = all for i in range(0,N-1): x += a[i] y -= a[i] ret = abs(x-y) if(ret < mini): mini=ret print(mini)
p03661
# -*- coding: utf-8 -*- from itertools import combinations def inpl(): return tuple(map(int, input().split())) N = int(eval(input())) A = inpl() s = sum(A) X = [sum(A[:i]) for i in range(1, N)] print((min([abs(2*x - s) for x in X])))
# -*- coding: utf-8 -*- def inpl(): return tuple(map(int, input().split())) N = int(eval(input())) A = inpl() s = sum(A) x, y = A[0], sum(A[1:]) res = abs(x-y) for a in A[1:-1]: x += a y -= a if abs(x-y) < res: res = abs(x-y) print(res)
p03661
# -*- coding:utf-8 -*- N = int(eval(input())) a = list(map(int, input().split())) b = sum(a) minimum = float('inf') for tmp in range(1,N): c = sum(a[tmp:len(a)]) d = abs(b-2*c) minimum = min(minimum, d) print(minimum)
# -*- coding:utf-8 -*- N = int(eval(input())) a = list(map(int, input().split())) b = sum(a) c = 0 minimum = float('inf') for tmp in range(0,N-1): c += a[tmp] d = abs(c-(b-c)) minimum = min(minimum, d) print(minimum)
p03661
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break print(cnt)
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(...
p02267
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(...
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(...
p02267
n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) C = [] for s in S: for t in T: if s == t and not s in C: C.append(s) print((len(C)))
n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) C = 0 for t in T: for s in S: if s == t: C += 1 break print(C)
p02267
def linearSearch(key, list, N): list[N] = key i = 0 while list[i] != key: i += 1 return int(i != N) N1 = int(eval(input())) arr1 = [int(n) for n in input().split()] + [0] N2 = int(eval(input())) arr2 = [int(n) for n in input().split()] print((sum([linearSearch(key, arr1, N1) for ...
def linearSearch(key, list): for e in list: if key == e: return 1 return 0 N1 = int(eval(input())) arr1 = [int(n) for n in input().split()] N2 = int(eval(input())) arr2 = [int(n) for n in input().split()] print((sum([linearSearch(key, arr1) for key in arr2])))
p02267
def main(): N = int(eval(input())) S = [int(_) for _ in input().split()] Q = int(eval(input())) T = [int(_) for _ in input().split()] ans = 0 for t in T: for s in S: if s == t: ans += 1 break print(ans) main()
import sys # Set max recursion limit sys.setrecursionlimit(1000000) def li_input(): return [int(_) for _ in input().split()] def main(): n = int(eval(input())) S = li_input() q = int(eval(input())) T = li_input() ans = 0 for t in T: if t in S: a...
p02267
n = int(eval(input())) li1 = list(map(int,input().split())) m = int(eval(input())) li2 = list(map(int,input().split())) cnt = 0 for i in li2: if i in li1: cnt +=1 print(cnt)
n = int(eval(input())) S = set(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) sum = 0 for i in T: if i in S: sum +=1 print(sum)
p02267
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: for s in S: if t == s: count += 1 break print(count) def get_i...
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: if t in S: count += 1 print(count) def get_input1(): n = int(eval(input())) if n > 100...
p02267
import sys n = int(sys.stdin.readline()) s = [int(x) for x in sys.stdin.readline().split()] q = int(sys.stdin.readline()) t = [int(x) for x in sys.stdin.readline().split()] cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
import sys n = sys.stdin.readline() s = sys.stdin.readline().split() q = sys.stdin.readline() t = sys.stdin.readline().split() cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
p02267
n = int(eval(input())) s = input().split() q = int(eval(input())) t = input().split() cont = 0 for i in t: for o in s: if i == o: cont +=1 break print(cont)
n = int(eval(input())) s = set(input().split()) q = int(eval(input())) t = set(input().split()) print((len(s & t)))
p02267
def LinearSearch(n, S, t): """ ????????????????????¢????????? """ S.append(t) i = 0 while S[i] != t: i += 1 if i == n: return -1 else: return i n = int(eval(input())) S = [int(s) for s in input().split()] q = int(eval(input())) T = [int(t) for t in ...
def LinearSearch1(S, n, t): for i in range(n): if S[i] == t: return i break else: return -1 """ def LinearSearch2(S, n, t): S.append(t) i = 0 while S[i] != t: i += 1 S.pop() if i == n: return -1 else: ...
p02267
#coding:utf-8 #1_4_A def isFound(array, x): """ linear search """ array.append(x) i = 0 while array[i] != x: i += 1 if i == len(array)-1: return False return True n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, i...
#coding:utf-8 #1_4_A n = int(eval(input())) S = set(map(int, input().split())) q = int(eval(input())) T = set(map(int, input().split())) print((len(S & T)))
p02267
a, b = list(map(int, input().split())) res = a - 2*b if res < 0: res = 0 print(res)
a,b = list(map(int, input().split())) res = a - b - b print((0 if res < 0 else res))
p02885
A,B=input().split() A,B=[int(A),int(B)] if(A >= 2*B): print((A-2*B)) else: print((0))
from sys import stdin def main(): #入力 readline=stdin.readline A,B=list(map(int,readline().split())) C=max(0,A-B*2) print(C) if __name__=="__main__": main()
p02885
a,b=list(map(int, input().split())) print((max(a-2*b,0)))
a,b = list(map(int,input().split())) print((max(0,a-b*2)))
p02885
a,b= list(map(int,input().split())) r = a-b*2 if r <= 0: print((0)) else: print(r)
A,B=list(map(int,input().split())) ans=A-B*2 print((ans if ans>=0 else 0))
p02885
a,b = list(map(int,input().split())) if b * 2 >= a: print((0)) else: print((a-2*b))
a,b = list(map(int,input().split())) print((max(0,a-2*b))) ''' if b * 2 >= a: print(0) else: print(a-2*b) '''
p02885
A, B = list(map(int, input().split())) print((A - 2 * B if A - 2 * B > 0 else 0))
A,B = list(map(int, input().split())) print((max(0, A-2*B)))
p02885
a, b = list(map(int, input().split())) ans = a - b * 2 if ans < 0: ans = 0 print (ans)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) a, b = list(map(int, input().split())) ans = a - b * 2 if (ans >= 0): print(ans) else: print((0))
p02885
""" author : halo2halo date : 19,Oct,2019 """ import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) A, B = list(map(int, readline().split())) print((max(A-2*B, 0)))
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) A, B = list(map(int, readline().split())) S=A-2*B print((S if S>0 else 0))
p02885
a,b = list(map(int,input().split())) c = 2*b d = a-c if d > 0: print(d) elif d <= 0: print((0))
a,b = list(map(int,input().split())) if a-2*b > 0: print((a-2*b)) else: print((0))
p02885
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a, b = list(map(int, input().split())) print((max(0, a - 2 * b))) if __name__ == "__main__": setrecursionlimit(10000) main()
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a, b = list(map(int, input().split())) if a - 2 * b >= 0: print((a - 2 * b)) else: print((0)) if __name__ == "__main__": setrecursionlimit(10000) main()
p02885
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # input=lambda :sys.stdin.readline().rstrip() def resolve(): a,b=list(map(int,input().split())) print((max(0,a-2*b))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): a,b=list(map(int,input().split())) print((max(0,a-2*b))) resolve()
p02885
a,b = list(map(int,input().split())) print((max(0,a-2*b)))
A,B = list(map(int,input().split())) print((max(0,A-2*B)))
p02885
a,b=list(map(int,input().split())) if 0>a-(2*b): print((0)) else: print((a-(2*b)))
a,b=list(map(int,input().split())) if a<2*b: print((0)) else: print((a-(2*b)))
p02885
a,b=list(map(int,input().split())) if a<2*b: print((0)) else: print((a-(2*b)))
a,b=list(map(int,input().split())) print((max(0,a-2*b)))
p02885
import sys input = sys.stdin.readline a, b = [int(x) for x in input().split()] if 2*b >= a: print((0)) else: print((a - 2*b))
import sys input = lambda : sys.stdin.readline().rstrip() a, b = list(map(int, input().split())) print((max(0, a - 2*b)))
p02885
A, B = list(map(int, input().split())) if A <= B * 2: print('0') else: print((A - 2 * B))
A, B = list(map(int, input().split())) print((max(0, A - 2 * B)))
p02885
a, b = list(map(int, input().split())) if a < b * 2: print((0)) else: print((a-(b*2)))
a, b = list(map(int, input().split())) if a < (b*2): print((0)) else: print((a-(b*2)))
p02885
A,B = list(map(int,input().split())) x = A-B-B print((max(0,x)))
A,B = list(map(int,input().split())) print((max(0, A-B-B)))
p02885
a, b = list(map(int, input().split())) if a > b*2: print((a - b*2)) else: print((0))
a, b = list(map(int, input().split())) print((max(0, a-b*2)))
p02885
A, B = list(map(int, input().split())) space = A - B * 2 if space < 0: space = 0 print(space)
a, b = list(map(int, input().split())) ans = max(a - 2 * b, 0) print(ans)
p02885
A, B = list(map(int, input().split())) print((max(0, A - 2*B)))
a,b=list(map(int,input().split())) print((max(0,a-b-b)))
p02885
a,b=list(map(int,input().split())) d=a-2*b print((d if d>0 else 0))
a,b=list(map(int,input().split())) print((max(0,a-b*2)))
p02885
a,b=list(map(int,input().split())) print((max(0,a-b*2)))
a, b = list(map(int, input().split())) print((max(0, a-2*b)))
p02885
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N-H+1)*(N-W+1)))
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N-W+1)*(N-H+1)))
p03155
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N+1-H)*(N+1-W)))
n = int(eval(input())) h = int(eval(input())) w = int(eval(input())) print(((n+1-h)*(n+1-w)))
p03155
n=int(eval(input())) m=int(eval(input())) h=int(eval(input())) print(((n-m+1)*(n-h+1)))
n,h,w = [int(eval(input())) for _ in range(3)] print(((n-h+1)*(n-w+1)))
p03155
row = [True] * 8 col = [True] * 8 dpos = [True] * 15 dneg = [True] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = map(int, line.split()) row[r] = "INIT" col[c] = ...
row = [False] * 8 col = [False] * 8 dpos = [False] * 15 dneg = [False] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = list(map(int, line.split())) row[r] = True c...
p02244
import sys; def putQueen(i, row, col, dpos, dneq): if(i == 8): global finding if(finding == 0): return finding = 0 printBoard(row[0:]) for j in range(8): if i in myset: putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:]) ...
import sys; def putQueen(i, row, col, dpos, dneq): global finding if(finding == 0): return if(i == 8): finding = 0 printBoard(row[0:]) return for j in range(8): if i in myset: putQueen(i+1,row[0:], col[0:], dpos[0:], dneq...
p02244
import itertools N, Q, row, col = eval(input()), [], list(range(8)), list(range(8)) for _ in range(N): r, c = list(map(int, input().split())) Q.append((r, c)) row.remove(r) col.remove(c) for l in itertools.permutations(col): queen = Q + list(zip(row, l)) if not any(any((r1 != r2 or c1 !...
import itertools N, Q, row, col = eval(input()), [], list(range(8)), list(range(8)) for _ in range(N): r, c = list(map(int, input().split())) Q.append((r, c)) row.remove(r) col.remove(c) for l in itertools.permutations(col): queen = Q + list(zip(row, l)) if not any((r1 != r2 or c1 != c2...
p02244
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBo...
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBo...
p02244
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBo...
from sys import stdin from itertools import permutations as per def check(queen): for r1, c1 in queen: if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) for r2, c2 in queen): return False return True k = int(stdin.readline()) R, C = [[i for i in range(...
p02244
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] @lru_cache(maxsize=None) def dia(s,a,b): d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: d.append(s[i][j]) if j - (a ...
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: ...
p02244
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: ...
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + abs(a - i) == ...
p02244
L = list(map(int, input().split())) maxres = 0 for i in range(3): n = [1, 0, -1] if L[i] <= L[3]: maxres += L[i] * n[i] L[3] -= L[i] else: for j in range(L[3]): maxres += n[i] L[3] -= 1 print(maxres)
L = list(map(int, input().split())) n = [1, 0, -1] maxres = 0 for i in range(3): if L[3] == 0: break maxres += L[i] * n[i] L[3] -= L[i] #print(L[3]) if L[3] < 0: maxres -= abs(L[3]) * n[i] break print(maxres)
p02682
A, B, C, K = list(map(int, input().split())) point = 0 judge = False if A == K: point = A judge = True elif A == 0 and B == K: point = 0 judge = True elif A == 0 and B == 0 and C == K: point = -K judge = True if not judge: if A > 0 and K > 0: while A > 0 and K > 0: K -= 1 A...
a,b,c,k=list(map(int,input().split()));count=0 if k<=a: print(k) elif k<=a+b: print(a) else: print((a-(k-a-b)))
p02682
a,b,c,k = list(map(int,input().split())) res = 0 if a > 0: if a <= k: res += a k -= a elif a > k: while k > 0: res += 1 k -= 1 if k > 0 and b > 0: if b <= k: k -= b elif b > k: k = 0 if k > 0 and c > 0: if c <= k...
a,b,c,k = list(map(int,input().split())) res = 0 if a > 0: if a <= k: res += a k -= a elif a > k: res += k k = 0 if k > 0 and b > 0: if b <= k: k -= b elif b > k: k = 0 if k > 0 and c > 0: if c <= k: res -= c k -=...
p02682
from collections import * A, B, C, K = list(map(int, input().split())) if K<=A: print(K) elif K<=A+B: print(A) else: print((A-(K-A-B)))
A, B, C, K = list(map(int, input().split())) if K<A: print(K) elif K<A+B: print(A) else: print((A-(K-A-B)))
p02682
a, b, c, k = list(map(int, input().split())) res = 0 i = 0 a_times = 0 b_times = 0 c_times = 0 if a == k: a_times = k else: for i in range(k): # print('i = ', i) if i < a: a_times += 1 # print('res + 1= ', res) elif i + a < a + b: ...
a, b, c, k = list(map(int, input().split())) a_times = 0 b_times = 0 c_times = 0 if a <= k: a_times = a # print('a_times = ', a_times) if a_times + b <= k: b_times = b # print('if - b_times = ', b_times) else: b_times = k - a_times # print('else - b_times ...
p02682
A, B, C, K = list(map(int, input().split())) sum = 0 if A <= K: K -= A sum += 1 * A elif K > 0: sum += 1 * K K = 0 if B <= K: K -= B elif K > 0: K = 0 if C <= K: K -= C sum -= 1 * C elif K > 0: sum -= 1 * K print(sum)
a, b, c, k = list(map(int, input().split())) if k <= a: print(k) elif k <= a + b: print(a) else: print((a - (k - (a + b))))
p02682
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) else: if a+b>=k: print(a) else: if a+b+c>=k: print((a-(k-(a+b))))
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) elif a+b>=k: print(a) else: print((a-(k-(a+b))))
p02682
def main(): A, B, C, K = list(map(int, input().split())) v = 0 if K <= A: return K elif K <= A+B: return A else: return A - (K-A-B) if __name__ == '__main__': print((main()))
def main(): A, B, C, K = list(map(int, input().split())) if K <= A: return K elif K <= A+B: return A else: return A - (K-A-B) if __name__ == '__main__': print((main()))
p02682
A, B, C, K = list(map(int, input().split())) a = min(A, K) K -= a b = min(B, K) K -= b c = K print((a-c))
a, b, c, k = list(map(int, input().split())) ans = 0 ans += min(a,k) k -= min(a,k) ans += min(b,k)*0 k -= min(b,k) ans += k*(-1) print(ans)
p02682
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) elif a<k: if k-a<=b: print(a) elif k-a >b: print((a-(k-a-b)))
a,b,c,k=list(map(int,input().split())) ans=0 ans=min(k,a) k-=min(k,a) ans+=min(k,b)*0 k-=min(k,b) ans+=min(k,c)*(-1) print(ans)
p02682
a,b,c,k=list(map(int,input().split())) if k<=a+b: print(a) for i in range(1,c): if k==a+b+i: print((a-i))
a,b,c,k=list(map(int,input().split())) def calc(a,b,c,k): if k<a: return k elif k<=a+b: return a else: return a-(k-a-b) print((calc(a,b,c,k)))
p02682