Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	seq := make([]int, 360)
	N := io.NextInt()
	for i := 0; i < N; i++ {
		M, D, V, S := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		M = (M - 1) * 30
		D--
		for j := M + D; j < M+D+V; j++ {
			seq[j%360] = intMax(S, seq[j%360])
		}
		for j := 0; j < S; j++ {
			seq[(M+D-j+360)%360] = intMax(S-j, seq[(M+D-j+360)%360])
			seq[(M+D+V+j-1)%360] = intMax(S-j, seq[(M+D+V+j-1)%360])
		}
	}
	ans := 360
	for _, val := range seq {
		ans = intMin(val, ans)
	}
	io.Println(ans)
}

func intMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: n = int(input())
eff = [0]*360
days = [list(map(int, input().split())) for i in range(n)]

for m, d, v, s in days:
    # [a, b)
    a = (m-1)*30 + d - 1
    b = a + v
    for i in range(a, b):
        eff[i%360] = max(eff[i%360], s)
    for i in range(b, a+360):
        eff[i%360] = max(eff[i%360], s - min(i - b + 1, 360 + a - i))
print(min(eff))

Python: 
N = input()
N = int(N)+1
X = [0]
C = [0]*360

for i in range(1,N):
    x = input()
    X.append(x.split())
    i_start = (int(X[i][0])-1)*30+int(X[i][1])-1
    i_end = i_start+int(X[i][2])-1

    for j in range(i_start,i_end+1):
        C[j%360] = max(C[j%360],int(X[i][3]))

    for k in range(1,int(X[i][3])+1):
        C[(i_start-k+360)%360] = max(C[(i_start-k+360)%360],int(X[i][3])-k)
        C[(i_end+k)%360] = max(C[(i_end+k)%360],int(X[i][3])-k)

print(min(C))

Python: D = 360
x = [0 for i in range(D)]

n = int(input())
for i in range(n):
    m,d,v,s = map(int,input().split())
    m -= 1
    d -= 1

    start = 30*m+d
    end = (start+v-1)%D
    h = [False for _ in range(D)]
    for j in range(v):
        y = (start+j)%D
        h[y] = True

    for j in range(D):
        if h[j]:
            x[j] = max(x[j],s)
        else:
            A = abs(start-j)
            if A>D//2:
                A = D-A
            B = abs(end-j)
            if B>D//2:
                B = D-B
            x[j] = max(x[j], s-min(A,B))

print(min(x))

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	//vector<pair<pair<ll, ll>, ll>> seg(N);
	ll Seg[360] = { 0 };
	for (int i = 0; i < N;i++) {
		ll M, D, S, V; cin >> M >> D >> V >> S; D--;
		for (int j = 0; j < V;j++) {
			Seg[((M - 1) * 30 + D + j) % 360] = max(Seg[((M - 1) * 30 + D + j) % 360], S);
		}
		for (int j = 1; j <= S; j++) {
			Seg[((M - 1) * 30 + D - j + 360 * 2) % 360] = max(Seg[((M - 1) * 30 + D - j + 360 * 2) % 360], S - j);
			Seg[((M - 1) * 30 + D + V + j - 1) % 360] = max(Seg[((M - 1) * 30 + D + V + j - 1) % 360], S - j);
		}
	}
	ll ans = INF;
	for (int i = 0;i < 360; i++) {
		ans = min(ans, Seg[i]);
	}
	cout << ans << endl;
	return 0;
}

C++: int main(){
    
}

C++: int main(){
    
}

C++: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MAXCH(a, b) a = max(a, b);
#define INF (1LL << 30)
using namespace std;
typedef long long ll;

ll N, M[100], D[100], V[100], S[100];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> M[i] >> D[i] >> V[i] >> S[i];

  vector<ll> crowd(360, 0);
  REP(i, 0, N) {
    ll t = (M[i] - 1) * 30 + (D[i] - 1);
    REP(j, 0, V[i] + 1) MAXCH(crowd[(t + j) % 360], S[i]);
    REP(j, 0, S[i]) MAXCH(crowd[(t + V[i] + 1 + j) % 360], S[i] - j - 1);
    REP(j, 0, S[i]) MAXCH(crowd[(t + 360 - j) % 360], S[i] - j - 1);
  }

  // REP(i, 0, 360) cout << crowd[i] << " ";
  // cout << endl;

  cout << *min_element(crowd.begin(), crowd.end()) << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n;i++)
#define INF 1e9
int main(){
    vector<int>array(600,0);
    int n; cin>>n;
    using pii = pair<int,int>;
    using piii=pair<pii,int>;
    vector<piii>holiday;
    for(int i=0;i<n;i++){
        int m,d,v,s; cin>>m>>d>>v>>s;
        holiday.push_back(piii(pii((m-1)*30+d,v),s));
        int x=(m-1)*30+d;
        int cnt=0;
        for(int i=0;i<v;i++,cnt++){
            array[x+cnt]=max(array[x+cnt],s);
            if(x+i==360){x=0, cnt=1;}
        }
    }
    for(int j=1;j<=360;j++){
        for(int i=0;i<holiday.size();i++){
            int fi=(holiday[i].first.first-j);
            int sec=(j-(holiday[i].first.first+holiday[i].first.second-1));
            if(fi<0)fi=360-j+holiday[i].first.first;
            if(sec<0)sec=j+360-(holiday[i].first.first+holiday[i].first.second-1);
            array[j]=max(array[j],max(0,holiday[i].second-min(fi,sec)));
        }
    }
    int ans=INF;
    for(int i=1; i<=360;i++)ans=min(ans,array[i]);
    cout<<ans<<endl;
}