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 <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N, x[361] = {};
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int M, D, V, S;
    cin >> M >> D >> V >> S;
    int a = (M - 1) * 30 + D + V - 1;
    int b = (M - 1) * 30 + D;
    for (int k = 0; k < V; k++) {
      // if ((b + k) > 360) { b = (b + k) % 360; }
      // x[(M - 1) * 30 + D + k] = max(S, x[(M - 1) * 30 + D + k]);
      x[(b + k) % 360] = max(S, x[(b + k) % 360]);
    }
    // b = (M - 1) * 30 + D;
    for (int j = 1; j <= 360; j++) {
      // if ((a + j) > 360)
      //   a = a - 360;
      // else if ((b - j) < 1)
      //   b = b + 360;
      x[(a + j) % 360] = max(S - j, x[(a + j) % 360]);
      x[(b - j + 360) % 360] = max(S - j, x[(b - j + 360) % 360]);
    }
  }
  /*for (int i = 1; i <= 360; i++) {
      cout << i<<"="<<x[i] << endl;
  }*/
  sort(x, x + 361);
  cout << x[1] << endl;
  return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  multiset <int> a;
  vector <int> li0[1080],li1[1080];
  int n,b[1080]={},r=1e9,r1[1440]={},r2[360]={};
  a.insert(0);
  cin>>n;
  for(int i=0,m,d,v,s;i<n;i++){
    cin>>m>>d>>v>>s;
    d+=(m-1)*30-1;
    li0[360+d].push_back(s);
    li1[360+d+v-1].push_back(s);
  }
  for(int i=360;i<1080;i++){
    for(int j=0;j<li0[i].size();j++) a.insert(li0[i][j]);
    b[i]=*a.rbegin();
    for(int j=0;j<li1[i].size();j++) a.erase(li1[i][j]);
  }
  for(int i=360;i<1080;i++){
    for(int j=0;j<b[i];j++){
      r1[i+j]=max(b[i]-j,r1[i+j]);
      r1[i-j]=max(b[i]-j,r1[i-j]);
    }
  }
  /* for(int i=0;i<1440;i++) cout<<r1[i]<<" ";                                                                                                                                                 
     cout<<endl; */
  for(int i=0;i<1440;i++) r2[i%360]=max(r2[i%360],r1[i]);
  /*for(int i=0;i<360;i++) cout<<r2[i]<<" ";                                                                                                                                                   
    cout<<endl;*/
  for(int i=0;i<360;i++) r=min(r,r2[i]);
  cout<<r<<endl;
  return 0;
}

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;
        for(int i=0;i<v;i++){
            array[x+i]=max(array[x+i],s);
            if(x+i==360)x=0;
        }
    }
    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;
}

C++: #include <iostream>
#include <algorithm> 
#include <vector>
#include <cstring>
using namespace std;
int main(void){
	int N;
	cin>>N;
	int dat[360];
	memset(dat, -1, sizeof(dat));
	for(int i=0;i<N;i++){
		int M,D,S,V;
		cin>>M>>D>>V>>S;
		for(int j=0;j<V;j++){
			int currentday = ((M-1)*30+D-1+j)%360;
			dat[currentday]=max(S,dat[currentday]);
		}
		for(int j=0;j<360;j++){
			int currentday = ((M-1)*30+D-1+j)%360;
			dat[currentday]=max(dat[currentday],max(0,S-min(360-j,(j+1-V+360)%360)));
		}
	}
	int mi=1000;
	for(int i=0;i<360;i++){
		mi=min(mi,dat[i]);
	}
	cout<<mi<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int m[101],d[101],s[101],v[101];
int out[1000][101];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&m[i],&d[i],&v[i],&s[i]);
		int id=(m[i]-1)*30+d[i]-1;
		for(int j=id;j<id+v[i];j++){
			out[j][i]+=s[i];
		}
		if(id+v[i]>=360){
			for(int j=0;j<id+v[i]-360;j++){
				out[j][i]=max(s[i],out[j][i]);
			}
		}
		int now=(id-1+360)%360;
		int cnt=s[i]-1;
		while(cnt>0){
			out[now][i]=max(out[now][i],cnt);
			cnt--;
			now=(now-1+360)%360;
		}
		now=(id+v[i]+360)%360;
		cnt=s[i]-1;
		while(cnt>0){
			out[now][i]=max(out[now][i],cnt);
			cnt--;
			now=(now+1+360)%360;
		}
	}
	int res=11451419;
	for(int i=0;i<360;i++){
		int now=0;
		for(int j=0;j<n;j++){
			now=max(out[i][j],now);
		}
		res=min(now,res);
	}
	printf("%d\n",res);
	return 0;
}