stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<iomanip>

#include<cmath>

#include<vector>

#include<algorithm>



using namespace std;



#define int long long

#define endl "\n"



const long long INF = (long long)1e18;

const long long MOD = 1'000'000'007; 



string yn(bool f){return f?"Yes":"No";}

string YN(bool f){return f?"YES":"NO";}







signed main(){

	cin.tie(nullptr);

	ios::sync_with_stdio(false);

	cout<<fixed<<setprecision(10);

	

	long double a, b, x;

	long double ans, PI = acos(-1);

	long double Z = 0;

	cin>>a>>b>>x;

	// cout<<PI<<endl;

	long double l = 0, h = 90, m;

	

	// cout<<atan(b/a)*180/PI<<endl;

	

	Z  = atan(b/a)*180/PI;

	

	for(int i = 0; i < 200; i++){

		m = (l+h)/2;

		

		long double area, y;

		

		y = tan(m * PI / 180.0) * a;

		

		// cout<<"tam "<<tan(m * PI / 180.0)<<" "<<m*PI/180<<endl;

		

		if(Z < m) {

			area = tan((90-m) * PI / 180) * b * b/ 2;

			

			// cout<<"Z "<<" "<<endl;

		} else {

		

			area = a * (b - y);

		

			area += a * y / 2 ;

		}

		// cout<<"area = "<<area<<" "<<y<<" m = "<<m<<endl;

		

		if(area*a < x){

			h = m;

		} else {

			l = m;

		}

	}

	

	cout<<m<<endl;

	

	

	

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<string>

#include<iomanip>

#include<cmath>

#include<vector>

#include<algorithm>

#include<utility>



using namespace std;



#define int long long

#define endl "\n"



constexpr long long INF = (long long)1e18;

constexpr long long MOD = 1'000'000'007; 



struct fast_io {

	fast_io(){

		std::cin.tie(nullptr);

		std::ios::sync_with_stdio(false);

	};

} fio;



signed main(){

	cout<<fixed<<setprecision(10);

	

	long double pi = acos(-1);

	long double y, ans = 0;

	long double a, b, x;

	

	cin>>a>>b>>x;

	

	y = (a * a * b) / 2;

	

	if(y > x) {

		long double h = (2 * x) / (a * b);

		cout<<90 - (atan(h/b) / pi)  * 180<<endl;

	} else {

		long double z = 2 * (x / (a * a)) - b;

		cout<<90 - (atan(a/(b-z)) / pi) * 180<<endl;

	}

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef  long long ll;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}

template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//自作関数

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}



#define rep(i,n) for(ll i=0;i<(ll)n;i++)

#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

    const long double PI = (acos(-1));

    const long double eps=1e-9;



long long INF = 1LL<<60;

void xlfp(double x){printf("%.10lf\n",x);}



long double f(long double a,long double b,long double theta){

if(theta>PI/2-eps){

        return 0.0;

    }

    long double ret;

    if(a*tan(theta)<=b){

        return a*a*b-a*a*a*tan(theta)/2;

    }

    else{

        return b*b/tan(theta)*a/2.0;

    }

}

int main(){

    long double a,b,x;

    cin>>a>>b>>x;

    long double ok=PI/2.0,ng=0;

    for(int i=1;i<=10000;i++){

        long double mid = (ok+ng)/2.0;

        if(f(a,b,mid)<x)ok=mid;

        else ng=mid;

    }

    xlfp(ok/PI*180);

    return 0;

}






// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef  long long ll;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}

template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//自作関数

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}



#define rep(i,n) for(ll i=0;i<(ll)n;i++)

#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

    const long double PI = (acos(-1));

    const long double eps=1e-9;



long long INF = 1LL<<60;

void xlfp(double x){printf("%.10lf\n",x);}



long double f(long double a,long double b,long double x){

    if(a*a*b<=2*x){

        return atan(2*(a*a*b-x)/(a*a*a));

    }

    else{

        return PI/2-atan(2*x/(a*b*b));

    }

}

int main(){

    long double a,b,x;

    cin>>a>>b>>x;

    xlfp(f(a,b,x)/PI*180);

    return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const long double PI = (acos(-1));

const long double EPS = 0.0000000001;



long double a, b, x;



long double f(long double a, long double b, long double theta){

    if(theta > PI/2.0 - EPS) return 0.0;

    long double ret;

    if(a*tan(theta) <= b)

        ret = a*a*b - a*a*a*tan(theta)/2.0;

    else

        ret = b*b/tan(theta)*a/2.0;

    return ret;

}



void solve(){

    long double ok = PI/2.0;

    long double ng = 0.0;

    for(int _ = 1; _ <= 100000; _++){

        long double mid = (ok+ng)/2.0;

        if(f(a, b, mid) < x) ok = mid;

        else ng = mid;

    }

    cout << fixed << setprecision(10) << ok/PI*180 << endl;

}



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    cin >> a >> b >> x;

    solve();

    return 0;

}

// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long int ll;

typedef pair<int, int> P;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	double a, b, x;

	cin >> a >> b >> x;

	x /= a;

	double rad;

	if(x <= a * b / 2) rad = atan2(b * b, 2 * x);

	else rad = atan2(2 * (a * b - x), a * a);

	double ans = rad / (2 * acos(-1)) * 360;

	cout << fixed << setprecision(12) << ans << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define deg_to_rad(deg) (((deg)/360)*2*M_PI)



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    double lo = 0, hi = 90;

    while(hi - lo > 1e-8){

        const double mid = (hi + lo) / 2.0;

        const double rad = deg_to_rad(mid);

        const double rad2 = M_PI / 2 - rad;

        const double aheight = sin(rad) * a;

        const double bheight = sin(rad2) * b;

        double vol = 0;

        if(aheight >= bheight){

            const double aheight2 = bheight / cos(rad2);

            vol = aheight2 * a * b / 2.0;

        }else{

            const double y = aheight / tan(rad2);

            const double z = aheight / sin(rad2);

            vol = (

                a * a * z / 2.0 + a * (a * cos(rad) + y) * (bheight - aheight)

            );

        }

        if(vol < x){

            hi = mid;

        }else{

            lo = mid;

        }

    }

    printf("%.8f\n", lo);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define rad_to_deg(rad) (((rad)/2/M_PI)*360)



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    x /= a;



    double ans = 0;

    if(x <= a * b / 2.0){

        const double a2 = 2 * x / b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a2, b));

    }else{

        const double b2 = 2 * x / a - b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a, b - b2));

    }

    printf("%.8f\n", ans);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

#include <functional>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define deg_to_rad(deg) (((deg)/360)*2*M_PI)



double continuous_binary_search(

    double lo, // 絶対 OK な値

    double hi, // [lo, hi] の間に最適値があるとする

    function<double(double)> is_ok, // OK かどうかを判定する

    double eps // 閾値

){

    while(hi - lo > eps){

        const double mid = (hi + lo) / 2.0;

        if(is_ok(mid)){

            lo = mid;

        }else{

            hi = mid;

        }

    }

    return lo;

}



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    double ans = continuous_binary_search(

        0, 90,

        [&](double mid){

            const double rad = deg_to_rad(mid);

            const double rad2 = M_PI / 2 - rad;

            const double aheight = sin(rad) * a;

            const double bheight = sin(rad2) * b;

            double vol = 0;

            if(aheight >= bheight){

                const double aheight2 = bheight / cos(rad2);

                vol = aheight2 * a * b / 2.0;

            }else{

                const double y = aheight / tan(rad2);

                const double z = aheight / sin(rad2);

                vol = (

                    a * a * z / 2.0 + a * (a * cos(rad) + y) * (bheight - aheight)

                );

            }

            return (vol >= x);

        }, 1e-8

    );

    printf("%.8f\n", ans);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define rad_to_deg(rad) (((rad)/2/M_PI)*360)



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    x /= a;



    double ans = 0;

    if(x <= a * b / 2.0){

        const double a2 = 2 * x / b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a2, b));

    }else{

        const double b2 = 2 * x / a - b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a, b - b2));

    }

    printf("%.8f\n", ans);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

#include <functional>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define deg_to_rad(deg) (((deg)/360)*2*M_PI)



double continuous_binary_search(

    double lo, // 絶対 OK な値

    double hi, // [lo, hi] の間に最適値があるとする

    function<bool(double)> is_ok, // OK かどうかを判定する

    double eps // 閾値

){

    while(hi - lo > eps){

        const double mid = (hi + lo) / 2.0;

        if(is_ok(mid)){

            lo = mid;

        }else{

            hi = mid;

        }

    }

    return lo;

}



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    double ans = continuous_binary_search(

        0, 90,

        [&](double mid){

            const double rad = deg_to_rad(mid);

            const double rad2 = M_PI / 2 - rad;

            const double aheight = sin(rad) * a;

            const double bheight = sin(rad2) * b;

            double vol = 0;

            if(aheight >= bheight){

                const double aheight2 = bheight / cos(rad2);

                vol = aheight2 * a * b / 2.0;

            }else{

                const double y = aheight / tan(rad2);

                const double z = aheight / sin(rad2);

                vol = (

                    a * a * z / 2.0 + a * (a * cos(rad) + y) * (bheight - aheight)

                );

            }

            return (vol >= x);

        }, 1e-8

    );

    printf("%.8f\n", ans);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define rad_to_deg(rad) (((rad)/2/M_PI)*360)



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    x /= a;



    double ans = 0;

    if(x <= a * b / 2.0){

        const double a2 = 2 * x / b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a2, b));

    }else{

        const double b2 = 2 * x / a - b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a, b - b2));

    }

    printf("%.8f\n", ans);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

#include <functional>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define deg_to_rad(deg) (((deg)/360)*2*M_PI)



/*

二部探索で最適値を求める

(lo, hi) の間に最適値があるとする。

最大化のとき lo は必ず ok となる値とする。

最小化のとき hi は必ず ok となる値とする。

*/

double continuous_binary_search(

    double lo,

    double hi,

    function<bool(double)> is_ok,

    bool is_maximize,

    double eps

){

    while(hi - lo > eps){

        const double mid = (hi + lo) / 2.0;

        if(is_maximize){

            if(is_ok(mid)){

                lo = mid;

            }else{

                hi = mid;

            }

        }else{

            if(is_ok(mid)){

                hi = mid;

            }else{

                lo = mid;

            }

        }

    }

    return lo;

}





int main(){

    double a, b, x;

    cin >> a >> b >> x;



    double ans = continuous_binary_search(

        0, 90,

        [&](double mid) -> bool {

            const double rad = deg_to_rad(mid);

            const double rad2 = M_PI / 2 - rad;

            const double aheight = sin(rad) * a;

            const double bheight = sin(rad2) * b;

            double vol = 0;

            if(aheight >= bheight){

                const double aheight2 = bheight / cos(rad2);

                vol = aheight2 * a * b / 2.0;

            }else{

                const double y = aheight / tan(rad2);

                const double z = aheight / sin(rad2);

                vol = (

                    a * a * z / 2.0 + a * (a * cos(rad) + y) * (bheight - aheight)

                );

            }

            return (vol >= x);

        }, true, 1e-8

    );

    printf("%.8f\n", ans);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cmath>



using namespace std;

typedef long long ll;

#define REP(i,n) for (ll i = 0; i < (n); ++i)



#define rad_to_deg(rad) (((rad)/2/M_PI)*360)



int main(){

    double a, b, x;

    cin >> a >> b >> x;



    x /= a;



    double ans = 0;

    if(x <= a * b / 2.0){

        const double a2 = 2 * x / b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a2, b));

    }else{

        const double b2 = 2 * x / a - b;

        ans = rad_to_deg(M_PI / 2.0 - atan2(a, b - b2));

    }

    printf("%.8f\n", ans);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



#define ll long long

#define X first

#define Y second

#define all(x) x.begin(), x.end()



const int MX = (int)1e5 + 10;

const int mod = (int)1e9 + 7;



int main(){



    cin.tie(0); cout.tie(0);

    ios_base::sync_with_stdio(0);



    double a, b, x;

    cin >> a >> b >> x;



    const double PI = acos(-1);

    double l = 0, r = 90;

    int it = 10000;

    while(it--){

        double md = (l + r) / 2;



        double angle = PI * md / 180.0;

        double ratio = tan(angle);

        double heightRem = a * ratio;



        if(heightRem >= b){

            double angle = 90 - md;

            double ratio = tan(angle * PI / 180.0);

            double org_base = b * ratio;

            double otherArea = 0.5 * org_base * b;

            if(otherArea * a >= x) l = md;

            else r = md;

            continue;

        }



        double areaExtra = 0.5 * a * heightRem;

        double ExtraVol = areaExtra * a;

        double rem = a * a * b - ExtraVol;



        if(rem >= x) l = md;

        else r = md;

    }

    

    cout << fixed << setprecision(6) << (l + r) / 2 << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



using namespace std;



#define ll long long

#define X first

#define Y second

#define all(x) x.begin(), x.end()



const int MX = (int)1e5 + 10;

const int mod = (int)1e9 + 7;



int main(){



    cin.tie(0); cout.tie(0);

    ios_base::sync_with_stdio(0);



    double a, b, x;

    cin >> a >> b >> x;



    const double PI = acos(-1);

    double l = 0, r = 90;

    int it = 50;

    while(it--){

        double md = (l + r) / 2;



        double angle = PI * md / 180.0;

        double ratio = tan(angle);

        double heightRem = a * ratio;



        if(heightRem >= b){

            double angle = 90 - md;

            double ratio = tan(angle * PI / 180.0);

            double org_base = b * ratio;

            double otherArea = 0.5 * org_base * b;

            if(otherArea * a >= x) l = md;

            else r = md;

            continue;

        }



        double areaExtra = 0.5 * a * heightRem;

        double ExtraVol = areaExtra * a;

        double rem = a * a * b - ExtraVol;



        if(rem >= x) l = md;

        else r = md;

    }

    

    cout << fixed << setprecision(6) << (l + r) / 2 << endl;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> l_l;

typedef pair<int, int> i_i;



const long double PI = (acos(-1));

const long double EPS = 0.0000000001;



long double a, b, x;



void input() {

    cin >> a >> b >> x;

}



long double f(long double a, long double b, long double theta) {

    if(theta > PI / 2.0 - EPS) {

        return 0.0;

    }

    long double ret;

    if(a * tan(theta) <= b) {

        ret = a * a * b - a * a * a * tan(theta) / 2.0;

    } else {

        ret = b * b / tan(theta) * a / 2.0;

    }

    return ret;

}



void solve() {

    input();

    long double ok = PI / 2.0;

    long double ng = 0.0;

    for(int _ = 1; _ <= 100000; _++) {

        long double mid = (ok + ng) / 2.0;

        if(f(a, b, mid) < x) ok = mid;

        else ng = mid;

    }

    cout << fixed << setprecision(10) << ok / PI * 180 << endl;

    return;

}



int main() {

    solve();

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> l_l;

typedef pair<int, int> i_i;



const long double PI = (acos(-1));

const long double EPS = 0.0000000001;



long double a, b, x;



void input() {

    cin >> a >> b >> x;

}



long double f(long double a, long double b, long double x) {

    long double ans;

    if(a * a * b / 2.0 <= x) {

        ans = atan(2 * (a * a * b - x) / (a * a * a));

    } else {

        ans = PI / 2 - atan(2 * x / (a * b * b));

    }

    return ans;

}



void solve() {

    input();

    cout << fixed << setprecision(10) << f(a, b, x) * 180.0 / PI << endl;

    return;

}



int main() {

    solve();

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//Bokan ga bokka--nn!!

//Daily Lunch Special Tanoshii !!

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <string>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <functional>

#include <iostream>

#include <map>

#include <set>

using namespace std;

typedef pair<int,int> P;

typedef pair<int,P> P1;

typedef pair<P,P> P2;

typedef long long ll;

#define pu push

#define pb push_back

#define mp make_pair

#define eps 1e-7

#define INF 2000000000

#define s(x) scanf("%d",&x)

#define rep(i,x) for(int i=0;i<x;i++)

int rui[1005][1005][3]={};

char f[1005][1005];

int n,m,q;

int main()

{

	scanf("%d %d %d",&n,&m,&q);

	for(int i=0;i<n;i++)

	{

		scanf("%s",f[i]);

	}

	for(int i=1;i<=n;i++)

	{

		for(int j=1;j<=m;j++)

		{

			rui[i][j][0]=rui[i-1][j][0]+rui[i][j-1][0]-rui[i-1][j-1][0]+(f[i-1][j-1]=='J');

			rui[i][j][1]=rui[i-1][j][1]+rui[i][j-1][1]-rui[i-1][j-1][1]+(f[i-1][j-1]=='O');

			rui[i][j][2]=rui[i-1][j][2]+rui[i][j-1][2]-rui[i-1][j-1][2]+(f[i-1][j-1]=='I');

			

		}

	}

	for(int aa=0;aa<q;aa++)

	{

		int x,y,z,w;

		scanf("%d %d %d %d",&x,&y,&z,&w);

		int r[3];

		for(int i=0;i<3;i++) r[i]=rui[z][w][i]-rui[z][y-1][i]-rui[x-1][w][i]+rui[x-1][y-1][i];

		printf("%d %d %d\n",r[0],r[1],r[2]);

	}

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int n,m,q,a,b,c,d,rui[1005][1005][3],ret[3];char f[1005][1005],e[3]={'J','O','I'};

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=0;i<n;i++) scanf("%s",&f[i]);

	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=0;k<3;k++)

	rui[i][j][k]=rui[i-1][j][k]+rui[i][j-1][k]-rui[i-1][j-1][k]+(f[i-1][j-1]==e[k]);

	for(int i=0;i<q;i++){

		scanf("%d%d%d%d",&a,&b,&c,&d);

		for(int j=0;j<3;j++) ret[j]=rui[c][d][j]-rui[c][b-1][j]-rui[a-1][d][j]+rui[a-1][b-1][j];

		printf("%d %d %d\n",ret[0],ret[1],ret[2]);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int H,W,K;

char t[1001][1001];

int J[1001][1001];

int O[1001][1001];

int I[1001][1001];



int main(){

  while(cin>>H>>W>>K){

    for(int i=1;i<=H;i++){

      for(int j=1;j<=W;j++){

	cin>>t[i][j];

	J[i][j]=(t[i][j]=='J'?1:0)+J[i-1][j]+J[i][j-1]-J[i-1][j-1];

	O[i][j]=(t[i][j]=='O'?1:0)+O[i-1][j]+O[i][j-1]-O[i-1][j-1];

	I[i][j]=(t[i][j]=='I'?1:0)+I[i-1][j]+I[i][j-1]-I[i-1][j-1];

      }

    }

    for(int i=0;i<K;i++){

      int ay,ax,by,bx;

      cin>>ay>>ax>>by>>bx;

      cout<<J[by][bx]-J[ay-1][bx]-J[by][ax-1]+J[ay-1][ax-1]<<' ';

      cout<<O[by][bx]-O[ay-1][bx]-O[by][ax-1]+O[ay-1][ax-1]<<' ';

      cout<<I[by][bx]-I[ay-1][bx]-I[by][ax-1]+I[ay-1][ax-1]<<endl;

    }

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

int H,W,K;

char t[1001][1001],ch;

int J[1001][1001];

int O[1001][1001];

int I[1001][1001];

int ay,ax,by,bx;

int main(){

  scanf("%d %d %d",&H,&W,&K);

  scanf("%c",&ch);

  for(int i=1;i<=H;i++){

    for(int j=1;j<=W;j++){

      scanf("%c",&t[i][j]);

      J[i][j]=(t[i][j]=='J'?1:0)+J[i-1][j]+J[i][j-1]-J[i-1][j-1];

      O[i][j]=(t[i][j]=='O'?1:0)+O[i-1][j]+O[i][j-1]-O[i-1][j-1];

      I[i][j]=(t[i][j]=='I'?1:0)+I[i-1][j]+I[i][j-1]-I[i-1][j-1];

    }

    scanf("%c",&ch);

  }

  for(int i=0;i<K;i++){

    scanf("%d %d %d %d",&ay,&ax,&by,&bx);

    printf("%d ",J[by][bx]-J[ay-1][bx]-J[by][ax-1]+J[ay-1][ax-1]);

    printf("%d ",O[by][bx]-O[ay-1][bx]-O[by][ax-1]+O[ay-1][ax-1]);

    printf("%d\n",I[by][bx]-I[ay-1][bx]-I[by][ax-1]+I[ay-1][ax-1]);

  }

  

  return 0;

}

// Fastest known solution for this problem: