/* In the name of Anton */

/*
* Motto :)
*
*
*
*
*
*/

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(x,a) for(auto &x: a)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define vt vector
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

template<class A> void read(vt<A>& v);
template<class T> void read(T& x){
  cin>>x;
}

void read(double &d){
  string t;
  read(t);
  d=stod(t);
}
void read(long double &d){
  string t;
  read(t);
  d=stold(t);
}

template<class H, class... T> void read(H &h, T&...t){
  read(h);
  read(t...);
}

template <class A> void read(vt<A> &x){
  trav(a,x)
    read(a);
}

string to_string(char c){
  return string(1,c);
}

string to_string(bool b){
  return b?"true":"false";
}

string to_string(const char* s){
  return string(s);
}

string to_string(string s){
  return string(s);
}

string to_string(vt<bool> v){
  string res;
  rep(i,sz(v)){
    res+=char('0'+v[i]);
  }
  return res;
}

template<class T> string to_string(T v){
  bool f=1;
  string res;
  trav(x,v){
    if(!f)
      res+=' ';
    f=0;
    res+=to_string(x);
  }
  return res;
}

template<class A> void write(A x){
  cout<<to_string(x);
}

template<class H, class...T> void write(const H& h, const T&...t){
  write(h);
  write(t...);
}

void print(){
  write("\n");
}

template<class H, class...T> void print(const H& h, const T&...t){
  write(h);
  if(sizeof...(t))
    write(' ');
  print(t...);
}

/* -----------------------------------------------------------------------------------------------*/

void pre(){

}

ll bring(string pat, string txt){
  string s=pat+'#'+txt;
  ll m=(ll)pat.size();
  ll n=(ll)s.size();
  vector <ll> pi(n);

  ll co=0;

  pi[0]=0;

  for(ll i=1;i<n;i++){
    ll j=pi[i-1];

    while(j>0 && s[i]!=s[j])
      j=pi[j-1];

    if(s[i]==s[j]) j++;

    pi[i]=j;

    if(pi[i]==m) co++;
  }

  return co;
}

vector <ll> lao(string pat, string txt){
  string s=pat+'#'+txt;
  ll n=(ll)s.size();
  vector <ll> pi(n);

  pi[0]=0;

  for(ll i=1;i<n;i++){
    ll j=pi[i-1];

    while(j>0 && s[i]!=s[j])
      j=pi[j-1];

    if(s[i]==s[j]) j++;

    pi[i]=j;
  }

  return pi;
}

void solve(){
  ll n; read(n);
  string pat; read(pat);

  string mine="110";

  string txt="";
  ll j=0;;

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }

  for(ll i=0;i<n;i++){
    txt+=mine[j];
    j++;

    if(j==3) j=0;
  }



  ll val=bring(pat,txt);


  ll new_n=(ll)txt.size();

  txt+=txt;

  vector <ll> v1=lao(pat,txt);

  ll con=0;

  for(ll i=n+1+new_n;i<v1.size();i++){
    if(v1[i]==n) con++;
  }

  con-=val;


  ll num=30000000000;
  ll tot=num/new_n;
  ll lef=num%new_n;

  // print(lef);

  ll ans=(tot*val);
  ans+=(con*(tot-1));

  // print(val);

  j=0;
  ll lo=0;

  if(lef!=0){

  for(ll i=n+1+new_n;i<v1.size();i++){
    if(v1[i]==n) ans++;
    j++;

    if(j==lef) break;
  }

  }

  print(ans);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t=1;
  // read(t);
  rep(i,t) solve();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) { cerr << head; dump(); }
template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

int N;
vector<int> X(210);
vector<int> Y(210);
vector<ll> R(210);

vector<int> a(210);
vector<int> b(210);
vector<int> c(210);
vector<int> d(210);

double calc(int x, int y, ll r, int a, int b, int c, int d)
{
    if (x < a || c <= x) return 0;
    if (y < b || d <= y) return 0;
    ll s = abs(a - c) * abs(b - d);
    return 1 - pow(1 - (double)min(r, s)/(double)max(r, s), 2);
}

ll calc_all(const vector<int>& a, const vector<int>& b, const vector<int>& c, const vector<int>& d)
{
  double res = 0;
  rep(i, N) {
    double ret = calc(X[i], Y[i], R[i], a[i], b[i], c[i], d[i]);
    res += ret;
  }
  return roundl(1000000000 * res / N);
}

void output()
{
  rep(i, N) {
    printf("%d %d %d %d\n", a[i], b[i], c[i], d[i]);
  }
}

int main()
{
  cin >> N;
  rep(i, N) {
    cin>>X[i]>>Y[i]>>R[i];
  }

  rep(i, N) {
    a[i] = X[i];
    b[i] = Y[i];
    c[i] = X[i]+1;
    d[i] = Y[i]+1;
  }

  ll res = calc_all(a, b, c, d);

  output();

  return 0;
}
