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)
}

C++: #include <iostream>
using namespace std;
int main(){

  int n,m,d,s,v,day[360]={};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m>>d>>v>>s;
    int d1=(m-1)*30+d-1;
    for(int j=0;j<v;j++){
      int tmp=(d1+j)%360;
      day[tmp]=max(day[tmp],s);
    }
    for(int j=0;j<s;j++){
      int tmp1=d1-j;
      while(tmp1<0) tmp1+=360;
      day[tmp1]=max(day[tmp1],s-j);
      int tmp2=d1+v+j;
      tmp2%=360;
      day[tmp2]=max(day[tmp2],s-j-1);
    }
  }
  int md=1001;
  for(int i=0;i<360;i++) md=min(md,day[i]);
  cout<<md<<endl;
  // for(int i=0;i<360;i++) if(day[i]==md) cout<<i/30+1<<" "<<i%30+1<<endl;

  return 0;

}

C++: #include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define int long long 
#define rep(i, N) for (int i = 0; i < N; i++)
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define vi vector<int>
#define vvi vector< vi >

signed main()
{
    int n;
    cin >> n;

    vvi day(n, vi(361, -1));

    rep(i, n) {
        //cout << endl;
        //cout << i << endl;
        int2(a, b);
        int2(d, c);
        rep(j, d) {
            day[i][(j + ((a - 1) * 30) + b - 1) % 360] = c;
            //cout << day[i][(j + (a * 30) + b) % 360] << " ";
        }
        int st = (a - 1) * 30 + b - 1;
        int en = (st + d - 1) % 360;
        rep(j, 360) {
            int dist = min( (st - j + 360) % 360,
                    (j - en + 360) % 360);
            day[i][j] = max(day[i][j], max(c - dist, 0LL));
            //cout << day[i][j] << " ";
        }
        //cout << endl;
    }

    int ans = INF;
    rep(j, 360) {
        int tmp = 0;
        rep(i, n) {
            tmp = max(tmp, day[i][j]);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;

int ma[360];

signed main(){
    cin>>N;
    while(N--){
        int m,d,v,s;
        cin>>m>>d>>v>>s;
        m--;d--;

        int l=m*30+d;
        int r=l+v-1;

        for(int i=-360;i<=360;i++){
            int tmp;
            if(i<l)tmp=s-(l-i);
            else if(l<=i&&i<=r)tmp=s;
            else tmp=s-(i-r);
            chmax(tmp,0ll);
            chmax(ma[(i+360)%360],tmp);
        }
    }

    cout<<*min_element(ma,ma+360)<<endl;
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int Start[100];
int s[100];
int End[100];
int v[100];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		int M, D;
		cin >> M >> D >> v[i] >> s[i];
		Start[i] = 30 * (M - 1) + D;
		End[i] = Start[i] + v[i] - 1;
	}

	int ans = 1e9;
	for(int i = 0; i < 360; i++) {
		int x = 0;
		for(int j = 0; j < N; j++) {
			if(Start[j] <= i && i <= End[j]) {
				x = max(x, s[j]);
			}
			else if(Start[j] <= i + 360 && i + 360 <= End[j]) {
				x = max(x, s[j]);
			}
			else {
				int t = 1e9;
				t = min({ t, abs(Start[j] - i), abs(End[j] - i) });
				t = min({ t, abs(Start[j] + 360 - i), abs(End[j] + 360 - i) });
				t = min({ t, abs(Start[j] - 360 - i), abs(End[j] - 360 - i) });
				x = max({ x, s[j] - t });
				/*if(i < Start[j]) {
					int t = s[j] - min(Start[j] - i, i + 360 - End[j]);
					x = max(x, t);
					}
					else {
					int t = s[j] - min(i - End[j], Start[j] + 360 - i);
					x = max(x, t);
					}*/
			}
		}

		ans = min(ans, x);
	}
	cout << ans << endl;
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI crowd(360);
  REP(diesirae, 0, n) {
    int m, d, v, s;
    cin >> m >> d >> v >> s;
    int dat = 30 * (m - 1) + d - 1;
    VI eff(360, 0);
    REP(i, 0, v) {
      eff[(dat + i) % 360] = s;
    }
    REP(i, 0, s) {
      int &r = eff[(dat - i + 360 + 359) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, s) {
      int &r = eff[(dat + v + i + 360) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, 360) {
      crowd[i] = max(crowd[i], eff[i]);
    }
  }
  int mi = 10000;
  REP(i, 0, 360) {
    mi = min(mi, crowd[i]);
  }
  cout << mi << endl;
}