1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
what does odbyt mean?
who is paris platynov and why is he rhyming about stara and stary?
 
░░░░░░░░░░░░░▄▄▀▀▀▀▀▀▄▄
░░░░░░░░░░▄▄▀▄▄▄█████▄▄▀▄
░░░░░░░░▄█▀▒▀▀▀█████████▄█▄
░░░░░░▄██▒▒▒▒▒▒▒▒▀▒▀▒▀▄▒▀▒▀▄
░░░░▄██▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▄
░░░░██▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▌
░░░▐██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐█
░▄▄███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
▐▒▄▀██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐▌
▌▒▒▌▒▀▒▒▒▒▒▒▄▀▀▄▄▒▒▒▒▒▒▒▒▒▒▒▒█▌
▐▒▀▒▌▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▒▀▀▀▀▄▒▐
░█▒▒▌▒▒▒▒▒▒▒▒▀▀▒▀▒▒▐▒▄▀██▀▒▒▒▌
░░█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒█
░░░▀▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▄▀
░░░▐▒▒▒▒▒▒▒▒▒▄▀▐▒▒▒▒▒▐▒▒▒▒▄▀
░░▄▌▒▒▒▒▒▒▒▄▀▒▒▒▀▄▄▒▒▒▌▒▒▒▐▀▀▀▄▄▄
▄▀░▀▄▒▒▒▒▒▒▒▒▀▀▄▄▄▒▄▄▀▌▒▒▒▌░░░░░░
▐▌░░░▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▀░░░░░░░
░█░░░░░▀▄▄▒▒▒▒▒▒▒▒▒▒▒▒▄▀░█░░░░░▒▒
░░█░░░░░░░▀▄▄▄▒▒▒▒▒▒▄▀░░░░█░░░▒▒▒
░░░█░░░░░░░░░▌▀▀▀▀▀▀▐░░░░░▐▌░▒▒▒▒
░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒
░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒░
░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒░░
░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒░░░
░░░░░░░░░░░░░░░░░░░░░░░▄▄▒▒▒▒▒░░░
░░░░░░░░░░░░░░░▄▄▄████████▒▒░░░░░
░░░░▄▄▄▄▄▄█████▀▀▀▀▀░░░░░░░░░░░░░
░░░▀▀▀▀▀▀▀░░░░░░░░░░░░░░░░░░░░░░░
 
NIE BIERZ TEGO BLUNTA SYNU
1 MARIHUANA = 1 ZNISZCZONE ŻYCIE
Papież chroni papież radzi
Papież nigdy cię nie zdradzi
 
słuchaj Papieża, żyj zdrowo i miej Boga w sercu
*/
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define satori int bepis;cin >> bepis;while(bepis--)
#define st [0]
#define nd [1]
#define mp make_pair
#define int long long
using namespace std;
 
int v[2000][2000][2];
 
void vis(vector<string> &s, queue<pair<int,int>> &q ,int i, int j, int &k, int &l)
{
 
      if(i < 0 or j < 0)return;
      if(i > s.size()-1 or s[0].size()-1 < j)return;
      if(v[i][j]st != INT_MAX  and v[i][j]nd != INT_MAX)return;
      if(s[i][j] == 'X')return;
      if(s[i][j] == '%')
      {
                              if(v[i][j]st == INT_MAX){
              v[i][j]st = min(v[k][l]st  , v[k][l]nd ) + 1;
              v[i][j]nd = v[i][j]st;
              q.push(mp(i,j));
              }
              return;
      }
      if(s[i][j] == '+')
      {
              if(v[k][l]st!=INT_MAX and v[i][j]st == INT_MAX){
              v[i][j]st = v[k][l]st+1;
              q.push(mp(i,j));
              }
              return;
      }
      if(s[i][j] == 'o')
      {
              if(v[k][l]nd!=INT_MAX and v[i][j]nd == INT_MAX){
              v[i][j]nd = v[k][l]nd+1;
              q.push(mp(i,j));
              }
              return;
      }
      if(v[k][l]st!=INT_MAX and v[i][j]st == INT_MAX)
      {
              v[i][j]st = min(v[k][l]st+1 , v[i][j]st);
              q.push(mp(i,j));
      }
      if(v[k][l]nd!=INT_MAX and v[i][j]nd == INT_MAX)
      {
              v[i][j]nd = min(v[k][l]nd+1 , v[i][j]nd);
              q.push(mp(i,j));
      }
      return;
}
int rozw(int &n,int &m ,int &p)
{
      cin >> n >> m >>p;
      vector <string> s(n);
      pair<int,int> b;
      for(int i = 0;i<n;i++)
      {
              cin>>s[i];
             // for(unsigned int j = 0;j < s[i].size();j++)
               //       if(s[i][j] == '@')b = mp(i,j);
      }
      b = mp(0,0);
      s[n-1][m-1] = '>';
        for(int i = 0;i<n;i++)
      {
              for(int j = 0;j < m;j++)
              {
                      v[i][j]st = INT_MAX;
                      v[i][j]nd = INT_MAX;
              }
      }
      //vector<vector<pair<int,int>>> v(n,vector<pair<int,int>>(m,mp(INT_MAX,INT_MAX)));
      queue <pair<int,int>> q;
      v[b.first][b.second]st = 0;
      v[b.first][b.second]nd = INT_MAX;
      q.push(b);
      
      while(q.size())
      {
              b = q.front();
              q.pop();
              if(s[b.first][b.second] == '>')
              {
                      return min(v[b.first][b.second]st,v[b.first][b.second]nd);
              }
              vis(s,q,b.first,b.second-1,b.first,b.second);
              vis(s,q,b.first,b.second+1,b.first,b.second);
              vis(s,q,b.first-1,b.second,b.first,b.second);
              vis(s,q,b.first+1,b.second,b.first,b.second);
      }
      //cout<<"NIE"<<'\n';
}
int32_t main()
{
      std::ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);
     // satori
      int n,m,q;
      int l = rozw(n,m,q);
     // cout << l;
      int k = LONG_LONG_MAX, j = 0;
	  for(int i = 0;i<q;i++)
	  {
	  	int a , b;
	  	cin >> a >> b;
	  	int x = a*(n+m-2) + ((a+b)*(l-n-m+2))/2;
	  	if(x==k)j++;
	  	if(x<k)
	  	{
	  		k=x;
	  		j = 1;
	  	}
	  }
	 cout << k << ' '<< j;
}