akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,p,q; cin >> N >> p >> q;
    p--; q--;
    vector<vector<int>> G(N);
    rep(i,N-1) {
        int u,v; cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    
    vector<bool> a(N,false);
    a[q] = true;
    queue<int> que;
    que.emplace(p);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        a[v] = true;
        for (auto nv : G[v]) {
            if (a[nv]) continue;
            que.emplace(nv);
        }
    }

    vector<int> dA(N,-1);
    dA[q] = 0;
    que.emplace(q);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (!a[nv]) continue;
            if (dA[nv] != -1) continue;
            dA[nv] = dA[v] + 1;
            que.emplace(nv);
        }
    }

    vector<int> dT(N,-1);
    dT[p] = 0;
    que.emplace(p);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (!a[nv]) continue;
            if (dT[nv] != -1) continue;
            dT[nv] = dT[v] + 1;
            que.emplace(nv);
        }
    }

    rep(i,N) if (dA[i] < dT[i]) a[i] = false;
    int maxd = 0;
    int k = q;
    rep(i,N) {
        if (!a[i]) continue;
        if (chmax(maxd,dA[i])) k = i;
    }
    maxd--;

    cout << maxd << endl;

}

Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=1000;
static const int VMAX=10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve(){
    int ans = 0;
    bool V[MAX];
    
    for(int i=0;i<n; i++){
        B[i]=A[i];
        V[i]=false;
    }
    sort(B,B+n);
    for(int i=0;i<n;i++) T[B[i]] = i;
    for(int i=0; i<n; i++){
        if(V[i]) continue;
        int cur = i;
        int S=0;
        int m=VMAX;
        int an = 0;
        while (1){
            V[cur] = true;
            an++;
            int v=A[cur];
            m=min(m,v);
            S +=v;
            cur=T[v];
            if(V[cur]) break;
        }
        ans += min(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}

int main(){
    cin>>n;
    s=VMAX;
    for(int i=0;i<n;i++){
        cin>>A[i];
        s=min(s,A[i]);
    }
    int ans=solve();
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3180
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  ns <- getIntList
  let [a, b, c] = sort ns
  let c' = c `div` 2
  print $ a * b * (c - c' * 2)


Measured memory_bytes: 3780
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int ans = Math.max(a+b,a-b);
    System.out.println(Math.max(ans,a*b));
  }
}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;

int main(){
  int n,m;
  cin>>n>>m;
  ll sum=0;
  rep(i,m){
    int a;
    cin>>a;
    sum+=a;
  }
  if(sum<=n)cout<<n-sum<<endl;
  else cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
   int n;
    cin>>n;
    int c=0;
    for(int i=0;i<3;i++)
    {
        if(n%10==1)
            c++;
        n=n/10;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;


int main()
{
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < 3; i++)
  {
    if(s.at(i) == 'o'){
      ++count;
    }
  }
  int price;
  if (count > 0)
  {
     price = 700 + (count * 100);
  }else if(count == 0){
    price = 700;
  }

  cout << price << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

X = [0]*N

for i in range(N):
    X[A[i]-1] += 1

ans = 0
for i in range(N):
    ans += int(X[i]*(X[i]-1)/2)

for i in range(N):
    print(int(ans-X[A[i]-1]+1))

Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string Odd,Even;
    cin>>Odd>>Even;
    int d=1;
    for(int i=0,j=0;d<=(Odd.size()+Even.size());d++)
    {
        if(d%2)
        {
            cout<<Odd[j];
            j++;
        }
        else
        {
           cout<<Even[i];
            i++;
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    ll a,b=0,d,x;
    
    cin>>x;
    
    Rep(i, 0, x){
        a = i;
        d = pow(a, 5) - x;
        Rep(j,-1000, 1000){
            if(pow(j, 5) == d){
                b = j;
                break;
            }
        }
        if(b != 0) break;
        
        if(pow(a, 5) - pow(b, 5) == x) break;
    }
    
    
    cout<<a<<" "<<b<<endl;
    
    return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;

int R, G, B, N;

int main() {
  cin >> R >> G >> B >> N;
  int res = 0;

  for(int x = 0; R*x <= N; x++) {
    for(int y = 0; R*x + G*y <= N; y++) {
      int z = (N - (R*x + G*y)) / B;
      if( (N - (R*x + G*y)) % B == 0 && z >= 0) {
        res++;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<queue>

using namespace std;

#define MOD 998244353

int main(){
  int n;
  cin >> n;
  vector<vector<int>> d(n);
  long long ans = 1;
  for(int i = 0; i < n; i++){
    int a;cin >>a;
    d[a].push_back(i);
    if(i == 0) ans = (a == 0);
  }
  int cnt = 0;
  if(d[0].size() != 1) ans = 0;
  for(int i = 0; i < n-1; i++){
    for(int j = 0 ; j < d[i+1].size(); j++){
      ans *= d[i].size() % MOD;
      ans %= MOD;
    }
    cnt += d[i].size();
    if(cnt == n) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  string s;
  cin >> s;
  n = s.size();
  vector<int> answer(n);
  
  int count_odd=0,count_even=0;
  int pos_rl=0,pos_lr=0;
  
  for(int i=0; i<n; i++){
    if(i%2 == 1){
      count_odd++;
    }else{
      count_even++;
    }
    
    if(i == n-1){
      if(pos_rl % 2 == 1){
        answer.at(pos_rl) = count_odd;
        answer.at(pos_rl+1) = count_even;
      }else{
        answer.at(pos_rl+1) = count_odd;
        answer.at(pos_rl) = count_even;
      }
      break;
    }
    
    if(s.at(i) == 'R' && s.at(i+1) == 'L'){
      pos_rl = i;
    }
    
    if(s.at(i) == 'L' && s.at(i+1) == 'R'){
      if(pos_rl % 2 == 1){
        answer.at(pos_rl) = count_odd;
        answer.at(pos_rl+1) = count_even;
      }else{
        answer.at(pos_rl+1) = count_odd;
        answer.at(pos_rl) = count_even;
      }
      count_odd=0;
      count_even=0;
    }
  }
  
  for(int i=0; i<n; i++){
    cout << answer.at(i) << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> t(n), a(n);
  REP(i,n) cin >> t[i] >> a[i];
  ll tp = 1;
  ll ap = 1;
  REP(i,n){
    ll n = max((tp+t[i]-1)/t[i], (ap+a[i]-1)/a[i]);
    tp = n*t[i];
    ap = n*a[i];
  }
  cout << tp+ap << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+5;
int dp[N]={};
int main()
{
	int n,k;
	cin>>n>>k;
	dp[0]=0;
	vector<int> v(n);
	for(int &a:v)
	{
		cin>>a;
	}
	for(int i=1; i<=k; ++i)
	{
		for(int a : v)
		{
			if(i-a >= 0)
			{
				if(dp[i-a] == 0)
				{
					//cout<<"i"<<i<<" a"<<a<<endl;
					dp[i]=1;
					break;
				}
			}
		}
	}
	
	if(dp[k] == 0)
	{
		cout<<"Second\n";
	}
	else{
		cout<<"First\n";
	}
}

Measured memory_bytes: 4024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int start = h1 * 60 + m1;
    int end = h2 * 60 + m2;
    cout << end - start - k<< endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>

int main(void) {
    while(true){
        int x, y;
        std::cin >> x >> y;
        if(!x && !y) break;
        if(x < y) {
            std::cout << x << ' ' << y << std::endl;
        }else{
            std::cout << y << ' ' << x << std::endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3076
#include <stdio.h>

int main()
{
    int n,x,sum=0,min;
    scanf("%d %d",&n,&x);
    int a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(i==0)
            min=a[0];
        sum+=a[i];
        if(min>a[i])
            min=a[i];
        
    }
    printf("%d",(n+((x-sum)/min)));

    return 0;
}


Measured memory_bytes: 1704
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	int sum=0;
	rep(i,10){
		int x; cin>>x;
		sum+=x;
	}
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    
    int A[n];
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    sort(A, A+n);
    reverse(A, A+n);

    int res = 0;
    for(int i = 0; i < n; i++){
        if(i%2) res -= A[i];
        else    res += A[i];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(){
  int n;
  bool finished = false;
  cin >> n;
  vector<vector<int>> a(9, vector<int>(9));
  rep(i, 9){
    if(finished) break;
    rep(j, 9){
      a.at(i).at(j) = (i + 1) * (j + 1);
      if(a.at(i).at(j) == n){
        cout << "Yes" << endl;
        finished = true;
        break;
      }
    }   
  }
  if(!(finished)) 
    cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>

using namespace std;

bool judge ( int x )
{
  string s = to_string(x);

  for ( int l = 0, r = s.size()-1; l < r; ++l, --r)
  {
    if ( s[l] != s[r] ) return false;
  }

  return true;
}

int main()
{
  int A,B;
  int cnt = 0;

  cin >> A >> B;

  for ( int i = A; i <= B; ++i ) {
    if ( judge(i) ) ++cnt;
  }

  cout << cnt << "\n";

}


Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
#include <complex>
using namespace std;
int main()
{
    long long n,y,i,j,k;
    cin>>n>>y;
    for(i=0;i<=n;i++) 
    {
 //       if((i*10000)>y) break;
        for(j=0;j<=n-i;j++) 
        {
                k=n-i-j;

                if(((i*10000)+(j*5000)+(k*1000))==y)
                {
                    cout<<i<<" "<<j<<" "<<k;
                    system ("pause");
                    return 0;
                }

   //             if(((i*10000)+(j*5000)+(k*1000))>y) break;
            
        }
    }
    cout<<"-1 -1 -1";
    system ("pause"); 
    return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;

bool isprime(int n){
	int m = sqrt(n);
	for(int i = 2; i <= m; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}

int main()
{
	int n;
	cin >> n;
	int k = 11;
	while(n){
		if(isprime(k) && k % 10 == 1){
			cout << k << ' ';
			n--;
		}
		k += 10;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int dp[21][1 << 21];

int A[21][21];
int n;

void adds(int& i, int j) {
    if((i += j) > mod) i -= mod;
    return ;
}

int f(int k, int b) {
    if(k == n) return 1;
    if(dp[k][b] != -1) return dp[k][b];
    int mx = 0;
    for(int i = 0; i < n; ++i)
        if((b & (1 << i)) && A[k][i])
            adds(mx, f(k + 1, b ^ (1 << i)));

    return dp[k][b] = mx;
}

int main() {
    cin >> n;
    memset(dp, -1, sizeof dp);
    
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> A[i][j];
    
    cout << f(0, (1 << 21) - 1);
    
    return 0;
}

Measured memory_bytes: 172288
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#define ll long long
#define INF 1000000000
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rev(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define pq priority_queue
#define PI acos(-1)

namespace IO
{
#define p(x) ('0'<=x&&x<='9')
	char cc; int C;
	template <class T>
	void read( T &x )
	{
		x=0; cc=getchar(); C=1;
		while(!p(cc)) { if(cc=='-') C=-1; cc=getchar(); }
		while(p(cc)) { x=x*10+cc-48; cc=getchar(); }
		x*=C;
	}
#undef p
}

using namespace IO;
using namespace std;

int n,k,a[20];

int check(int x)
{
	for(int cur;x;x/=10)
	{
		cur=x%10;
		For(i,1,k) if(cur==a[i]) return 1;
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	srand(time(0));
#ifdef LOCAL
	freopen("./tmp/input.txt", "r", stdin);
#endif

	cin >> n >> k;
	For(i,1,k) cin >> a[i];

	for(int i=n,k;;i+=k)
	{
		k=check(i);
		if(!k)
		{
			cout << i << endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<pii> ans;
int n;

void doit(int n) {
	if (n%2 == 0) {
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (j != i && j != n+1-i && i < j)
					ans.push_back(pii(i, j));
	} else {
		for (int i = 1; i <= n-1; ++i)
			for (int j = 1; j <= n; ++j)
				if (j != i && j != n-i && i < j)
					ans.push_back(pii(i, j));
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	doit(n);
	cout << ans.size() << endl;
	for (pii x : ans)
		cout << x.first << ' ' << x.second << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
bool color[404][404];
bool visited[404][404];

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

    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];
    memset(color, false, sizeof(color));
    rep(i, h) rep(j, w) color[i][j] = (field[i][j] == '#');

    ll ans = 0;
    memset(visited, false, sizeof(visited));
    rep(i, h) rep(j, w) {
        if(visited[i][j]) continue;
        visited[i][j] = true;
        ll cntB = 0, cntW = 0;
        queue<P> que;
        que.push(P(i, j));
        while(que.size()) {
            P p = que.front();
            que.pop();
            int y = p.first, x = p.second;
            if(color[y][x]) cntB++;
            else cntW++;
            rep(k, 4) {
                int nx = x+dx[k];
                int ny = y+dy[k];
                if(nx < 0 || ny < 0 || w <= nx || h <= ny) continue;
                if(visited[ny][nx]) continue;
                if(color[ny][nx] == color[y][x]) continue;
                visited[ny][nx] = true;
                que.push(P(ny, nx));
            }
        }
        ans += cntB*cntW;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
using namespace std;
#define int long long
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
constexpr int MOD = 1000000007;
int pow_mod(int x, int y) {
  int res = 1;
  for(; y > 0; y >>= 1, (x *= x) %= MOD) {
    if(y & 1) (res *= x) %= MOD;
  }
  return res;
}

signed main() {
  string L; cin >> L;
  int n = L.length();
  int ans = 0;
  int one = 0;
  REP(i,n) {
    if (L[i] == '1') {
      int m = n - i - 1;
      int t = pow_mod(3, m) * pow_mod(2, one);
      ans += t;
      ans %= MOD;
      one += 1;
    }
  }
  int t2 = pow_mod(2, one);
  ans += t2;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 512
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define pb	push_back
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	200005
#define P	1000000007

int		N, L[n], R[n];

int		A[n], B[n], S[n], V[n], Q[n], G[n], Deg[n], Now[n], Siz[n];

int		Pow(int a,int b){
		int ret=1;
		for (;b;b>>=1,a=1ll*a*a%P)
			if  (b&1)	ret=1ll*ret*a%P;
		return	ret;
}

int		C(int a, int b)	{
		return	1ll*L[a]*R[b]%P*R[a-b]%P;
}

int		main(int argc, char* argv[]){
		N= IN();
		
		L[0]= 1;
		For(i, 1, N)	L[i]= 1ll*L[i-1]*i%P;
		
		R[N]= Pow(L[N], P-2);
		Rep(i, N, 1)	R[i-1]= 1ll*R[i]*i%P;
		
		For(i, 1, N)	A[i]= IN(), Deg[A[i]]++, Siz[i]= 1;
		For(i, 1, N)	{
			Now[i]= Deg[i];
			if	(! Now[i])	Q[++ *Q]= i;
		}
		
		for (int i= 1; i <= *Q; i++)	{
			int u= Q[i], f= A[u];
			
			Siz[f]+= Siz[u];
			Now[f]--;
			
			if	(! Now[f])	Q[++ *Q]= f;
		}
		
		For(i, 1, *Q)	V[Q[i]]= 1;
		For(i, 1, N)	{
			if	(V[i] && Deg[i] > 1)	return	puts("0"), 0;
			if	(! V[i] && Deg[i] > 2)	return	puts("0"), 0;
		}
		
		int	Ans= 1;
		For(i, 1, N)	if	(! V[i])	{
			int j= i, len= 0;
			for (; ;)	{
				V[j]= 1;
				B[++ len]= Siz[j] - 1;
				
				j= A[j];
				if	(j == i)	break;
			}
			
			For(i, 1, len)	B[len + i]= B[i];
			For(i, 1, 2*len)	S[i]= S[i-1] + B[i];
			
			if	(! S[len])	{
				G[len]++;	continue;
			}
			if	(S[len] > len)	return	puts("0"), 0;
			
			int ret= 1;
			For(i, 1, len)	{
				int x= B[i], t= 0;
				if	(! x)	continue;
				
				if	(S[len+i-1] - S[len+i-x] == 0)	t++;
				if	(S[len+i-1] - S[len+i-x-1] == 0)	t++;
				
				ret= 1ll*ret*t%P;
			}
			
			Ans= 1ll*Ans*ret%P;
		}
		
	//	printf("%d\n", Ans);
		
		For(i, 1, N)	if	(G[i])	{
			int x= G[i], t= 1, v= (i > 1 && (i&1)) ? 2 : 1, ret= Pow(v, x);
			
			For(j, 1, x / 2)	{
				t= 1ll*t*C(x - (j-1)*2, 2)%P;
				ret= (ret + 1ll*t*R[j]%P*Pow(i, j)%P*Pow(v, x - 2*j))%P;
			}
			
			Ans= 1ll*Ans*ret%P;
		}
		
		printf("%d\n", Ans);
		
		return	0;
}

Measured memory_bytes: 7552
#include <iostream>

using namespace std;

int main()
{
	int num[4], tmp[4], hit, blow;
	
	while (1) {
		hit = 0; blow = 0;
		
		cin >> num[0] >> num[1] >> num[2] >> num[3];
		cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3];
		if (cin.eof()) break;
		
		for (int i=0; i<4; i++)
			for (int j=0; j<4; j++)
				if (num[i] == tmp[j]) {
					if (i == j) hit++;
					else		blow++;
				}
		cout << hit << " " << blow << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
def main():
	N, Y = map(int, input().split())
	ans_10000 = -1
	ans_5000 = -1
	ans_1000 = -1

	for i in range(N + 1):
		for j in range(N - i + 1):
			k = N - i - j
			total = 10000 * i + 5000 * j + 1000 * k
			if total == Y :
				ans_10000 = i
				ans_5000 = j
				ans_1000 = k
				break				
	print(ans_10000, ans_5000, ans_1000)

  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9196
# -*- coding: utf-8 -*-

li = [int(input()) for i in range(5)]

li2 = list()

for i in li:
    if i % 10 != 0:
        i = (i // 10 + 1) * 10
    li2.append(i)

# li3 = [i for i in li if i % 10 != 0]

li4 = [int(str(i)[-1]) for i in li if i % 10 != 0]

# print(li3, li4)

if not li4:
    print(sum(li))
else:
    print(sum(li2) - 10 + min(li4))


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
a = [["#"] * 100 for _ in range(100)]
for i in range(100):
  a[i][0] = "."
for i in range(0, 100, 2):
  for j in range(1, 99):
    a[i][j] = "."
for i in range(0, 100, 2):
  for j in range(1, 99, 2):
    if A <= 1: break
    A -= 1
    a[i][j] = "#"
for i in range(99, -1, -2):
  for j in range(98, 0, -2):
    if B <= 1: break
    B -= 1
    a[i][j] = "."
print(100, 100)
for r in a: print("".join(r))

Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    char c1 = s.at(i);
    int count = 0;
    for (int j = 0; j < s.size(); j++)
    {
      char c2 = s.at(j);
      if (c1 == c2)
      {
        count++;
      }
    }
    if (count != 2)
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nk[0];
            var k = nk[1];

            int[] visited = new int[n];

            for(int i = 0; i < k; i++)
            {
                int d = int.Parse(Console.ReadLine());
                var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

                for(int j = 0; j < d; j++)
                {
                     visited[a[j] - 1] = 1;
                }
            }

            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                if(visited[i] == 0)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28388
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int a[111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>a[i];
	int cnt=0;
	rep(i,n){
		if(a[i]%2==1)cnt++;
	}
	if(cnt%2==1)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define M 1000000
using namespace std;

std::vector<int> adj[10];


void answer(){
    ll n,m,ans=0, x,y;
    cin>>n;
    ll a[200005]={};
    for(int i=0;i<n-1;i++){
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++) cout<<a[i]<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 5220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) cin >> S[i];
    vector<vector<int>> tate(W), yoko(H);
    for(int i = 0; i < H; i++){
        yoko[i].push_back(-1);
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#') yoko[i].push_back(j);
        }
        yoko[i].push_back(W);
    }
    for(int i = 0; i < W; i++){
        tate[i].push_back(-1);
        for(int j = 0; j < H; j++){
            if(S[j][i] == '#') tate[i].push_back(j);
        }
        tate[i].push_back(H);
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '.'){
                int res = 0;
                auto ite1 = lower_bound(yoko[i].begin(), yoko[i].end(), j);
                auto ite2 = lower_bound(tate[j].begin(), tate[j].end(), i);
                int r = *ite1--, l = *ite1, d = *ite2--, u = *ite2;
                res += (r - j - 1) + (j - l - 1) + (i - u - 1) + (d - i - 1) + 1;
                ans = max(ans, res);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 43004
#include <bits/stdc++.h>
/*
                 ,,ggddY888Ybbgg,,
          ,agd8""'   .d8888888888bga,
       ,gdP""'     .d88888888888888888g,
     ,dP"        ,d888888888888888888888b,
   ,dP"         ,8888888888888888888888888b,
  ,8"          ,8888888P"""88888888888888888,
 ,8'           I888888I    )88888888888888888,
,8'            `8888888booo8888888888888888888,
d'              `88888888888888888888888888888b
8                `"8888888888888888888888888888
8                  `"88888888888888888888888888
8                      `"8888888888888888888888
Y,                        `8888888888888888888P
`8,                         `88888888888888888'
 `8,              .oo.       `888888888888888'
  `8a             8888        88888888888888'
   `Yba           `""'       ,888888888888P'
     "Yba                   ,88888888888'
       `"Yba,             ,8888888888P"'
          `"Y8baa,      ,d88888888P"'
               ``""YYba8888P888"'
*/
using namespace std;
#define int long long
#define KOD ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define sz size()
#define S second
#define X(a,b) a = ((b) > (a)) ? (b) : (a);
#define N(a,b) a = ((b) > (a)) ? (a) : (b);
#define F first
#define SORT(x) sort(x.begin(),x.end())
#define Rev(a) reverse(a.begin() , a.end());
#define pb push_back
#define pre(x) cout.precision(0);
#define bit(x) __builtin_popcount(x)
#define is(a) insert(a);
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unordered_map<int,int> wi;
typedef unordered_set<int> si;
const int M = 1e5+2;
const int inf = 1e18;
main(){
	string a;
	cin >> a;
	if(a == "ABC") cout << "ARC";
	else  cout << "ABC";	
} 


Measured memory_bytes: 3628
n,m = map(int,input().split())
ball = [1]*(n+1)
red = [0]*(n+1)
red[1] = 1
for _ in range(m):
  x,y = map(int,input().split())
  ball[x] -= 1
  ball[y] += 1
  if red[x]:
    red[y] = 1
  if ball[x] == 0:
    red[x] = 0
print(sum(red))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
 string s;
  cin>>N>>s;
  for(int i=0;i<(int)s.size();i++){
    char c=s.at(i);
    if(c+N<=90){
    cout<<(char)(c+N);
  }else{
      cout<<(char)(c+N-26);
    }
}
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

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

using namespace std;
int main(void){
  int N,Q;
  while(cin>>N>>Q&&N!=0&&Q!=0){
    int M,num=0,cou=1,a_max=0,cou_max=0;
    vector<int> a;
    // a[5000] = {0}
    for(int i=0;i<N;i++){
      cin>>M;
      for(int j=0;j<M;j++){
	//cin>>a[j+num];
	int tmp;
	cin >> tmp;
	a.push_back(tmp);
      }
      num+=M;
    }
    //sort(a,a+num);
    sort(a.begin(),a.end());

     
    for(int k=0;k<num;k++){
      int pos1 = lower_bound(a.begin(),a.end(),a[k]) - a.begin();
      int pos2 = upper_bound(a.begin(),a.end(),a[k]) - a.begin();
      cou = pos2 - pos1;

      if(cou_max<cou){
	cou_max=cou;
	a_max=a[k];
      }
    }
    if(cou_max<Q) cout<<0<<endl; 
    else cout<<a_max<<endl;
  }

}

Measured memory_bytes: 3056
#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int N,M;
int l[3001],r[3001];
int dp[3001][3001];
string s;
int ct;

int ncr[3001][3001];

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

	for (int i=0;i<=3000;i++) for (int j=0;j<=3000;j++) {
		if (i==0) ncr[i][j]=i==j;
		else if (i==j) ncr[i][j]=1;
		else if (j>i) ncr[i][j]=0;
		else if (j==0) ncr[i][j]=1;
		else ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%mod;
	}

	int Mend=0;
	cin >> N >> M >> s;
	for (int i=0;i<M;i++) {
		cin >> l[ct] >> r[ct];l[ct]--;
		if (ct==0 || r[ct]>r[ct-1]) ct++;
	}

	l[ct]=r[ct]=N;
	dp[0][0]=1;

	for (int i=0;i<ct;i++) {
		int ext=0;
		for (int j=max(l[i],Mend);j<r[i];j++) if (s[j]=='1') ext++;

		int toc=min(r[i],l[i+1])-l[i];
		for (int j=0;j<=N;j++) {
			if (dp[i][j]==0) continue;
			for (int k=max(0,ext+j-(r[i]-l[i]-toc));k<=min(toc,ext+j);k++) {
				dp[i+1][ext+j-k]=(dp[i+1][ext+j-k]+(ll)ncr[toc][k]*dp[i][j])%mod;
			}
		}

		smax(Mend,r[i]);
	}

	cout << dp[ct][0] << endl;
}

Measured memory_bytes: 41088
#include <iostream>
using namespace std;
int main(){
	char str[10];
	cin >> str;
	int sign;
	sign = 0;
    if ((str[0]==str[1]) || (str[1]==str[2]) || (str[2]==str[3]))
    {
    	cout << "Bad\n";    	
	}
	else
	{
    	cout << "Good\n";   	 
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

#ifdef LOCAL
#include "../ACL.hpp"
#else 
#include <atcoder/all>
#endif

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve() {
    int n;
    cin >> n;
    vector<pair<PII,int>> ps(n);
    map<PII,int> m;
    REP(i,0,n) {
        cin >> ps[i].first.first >> ps[i].first.second;
        ps[i].second = i;
        m[ps[i].first] = ps[i].second;
    }
    sort(all(ps), [](auto &l, auto &r) {
        return l.first < r.first;
    });
    atcoder::dsu d(n);
    set<PII> s;
    REP(i,0,n) s.emplace(ps[i].first.second, ps[i].first.first);
    int mv = n + 1;
    REP(i,0,n) {
        int x = ps[i].first.first;
        int y = ps[i].first.second;
        int idx = ps[i].second;
        auto it = s.lower_bound(MP(y,x));
        while (it != s.end()) {
            int tx = it->second;
            int ty = it->first;
            // if (i == 2) cerr << tx << ", " << ty << endl;
            int tidx = m[MP(tx,ty)];
            if (d.size(tidx) > 1) break;
            d.merge(idx, tidx);
            ++it;
        }
        {
            auto it = s.rbegin();
            int tx = it->second;
            int ty = it->first;
            // if (i == 2) cerr << tx << ", " << ty << endl;
            int tidx = m[MP(tx,ty)];
            d.merge(idx, tidx);
        }
        s.erase(MP(y,x));

        // REP(i,0,n) cout << d.size(i) << endl;
        // cout << "---" << endl;
    }
    REP(i,0,n) cout << d.size(i) << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 28384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 初期処理
		Scanner sc = null;
		ArrayList<Integer> array = new ArrayList<Integer>();
		int number = 0;

		// テキスト入力クラス
		sc = new Scanner(System.in);

		// do~while処理
		while (sc.hasNext()) {

			// 現在の入力値
			number = sc.nextInt();
			
			//0だったら抜ける
			if (number == 0)
				break;
			// 配列に追加
			array.add(number);

			// 入力結果が0になるまで入力
		}

		// 最後の配列を出力しないので、ループは配列の数より１回少ない
		for (int i = 0; i < array.size(); i++) {
			// 配列に格納されている結果を出力
			System.out.println("Case " + (i+1) + ": " + array.get(i));
		}
	}
}

Measured memory_bytes: 42276
#include <bits/stdc++.h>

using namespace std;

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

int main(){
  int n, u, v;
  cin >> n >> u >> v;
  --u, --v;
  vector<vector<int> > a(n);
  REP(i, n - 1){
    int s, t;
    cin >> s >> t;
    --s, --t;
    a[s].push_back(t);
    a[t].push_back(s);
  }
  vector<int> d(n, -1);
  vector<int> p(n, -1);
  queue<int> q;
  q.push(v);
  d[v] = 0;
  while(!q.empty()){
    int s = q.front();
    q.pop();
    for(auto t: a[s]) if(d[t] == -1){
      d[t] = d[s] + 1;
      p[t] = s;
      q.push(t);
    }
  }
  int r = (d[u] - 1) / 2;
  int f = d[u] - 2 * r;
  REP(i, r) u = p[u];
  q.push(u);
  vector<int> d2(n, -1);
  d2[p[u]] = -2;
  d2[u] = 0;
  int md = 0;
  while(!q.empty()){
    int s = q.front();
    q.pop();
    for(auto t: a[s]) if(d2[t] == -1){
      d2[t] = d2[s] + 1;
      md = max(md, d2[t]);
      q.push(t);
    }
  }
  cout << r + f / 2 + md << endl;
  return 0;
}


Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;

static const int INF = 0x3f3f3f3f;

int dp[1 << 26];

int main() {
        string s;
        cin >> s;
        for (int i = 0; i < (1 << 26); i ++) dp[i] = INF;
        dp[0] = 0;
        int a = 0;
        for (int i = 0; i < s.size(); i ++) {
                a ^= (1 << (s[i] - 'a'));
                for (int j = 0; j < 26; j ++) dp[a] = min(dp[a], dp[a ^ (1 << j)] + 1);
        }
        printf("%d\n", dp[a] ? dp[a] : 1);
        return 0;
}


Measured memory_bytes: 262788
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-07-29 14:54:21 +0900
# LastModified: 2020-07-29 15:02:31 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    a_cnt = Counter(a)
    keys = a_cnt.keys()
    values = a_cnt.values()
    cnt = 0
    for k, v in zip(keys, values):
        if v % 2 == 1:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20904
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;

  map<char,int> m;
  rep(i,S.size()){
    m[S[i]]++;
  }

  bool flg = true;
  FOR(it,m){
    if(it->second != 2) flg = false;
  }
  
  if(m.size() == 2 && flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int digit(int n)
{
	int count=0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}

int f(int n, int m)
{
	int a = digit(n), b = digit(m);
	if (a > b)return a;
	else return b;
}

int main() 
{
	long long n;
	int a,b;
	cin >> n;

	a = sqrt(n);

	while (a > 0)
	{
		if (n%a == 0)
		{
			b = n / a;
			break;
		}
		else a--;
	}

	cout << f(a, b) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int M = scan.nextInt();
        int[] h = new int[M];
        int[] w = new int[M];
        HashMap<Integer, List<Integer>> map_h = new HashMap<>();
        HashMap<Integer, List<Integer>> map_w = new HashMap<>();
        HashSet<Long> cache = new HashSet<>();
        for (int i = 0; i < M; i++) {
            h[i] = scan.nextInt();
            w[i] = scan.nextInt();
            cache.add((long) h[i]*1000000 + (long) w[i]);
            if (!map_h.containsKey(h[i])) {
                map_h.put(h[i], new ArrayList<>());
            }
            if (!map_w.containsKey(w[i])) {
                map_w.put(w[i], new ArrayList<>());
            }
            map_h.get(h[i]).add(i);
            map_w.get(w[i]).add(i);
        }
        List<Integer> vl = new ArrayList<>();
        List<Integer> hl = new ArrayList<>();
        HashMap<Integer, HashSet<Integer>> list_vertical = new HashMap<>();
        for (int y : map_h.keySet()) {
            int count = map_h.get(y).size();
            if (!list_vertical.containsKey(count)) {
                list_vertical.put(count, new HashSet<>());
                vl.add(count);
            }
            list_vertical.get(count).add(y);
        }
        HashMap<Integer, HashSet<Integer>> list_horizontal = new HashMap<>();
        for (int x : map_w.keySet()) {
            int count = map_w.get(x).size();
            if (!list_horizontal.containsKey(count)) {
                list_horizontal.put(count, new HashSet<>());
                hl.add(count);
            }
            list_horizontal.get(count).add(x);
        }
        vl.sort(Comparator.reverseOrder());
        hl.sort(Comparator.reverseOrder());
        long ans = vl.get(0) + hl.get(0)-1;
        for (int y : list_vertical.get(vl.get(0))) {
            for (int x : list_horizontal.get(hl.get(0))) {
                long index = (long) y * 1000000 + (long) x;
                if (!cache.contains(index)) {
                    System.out.println(ans + 1);
                    return;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 244048
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;
  int x = 1;
  
  while (n > 0) {
    if (x*2 <= x+k) x *= 2;
    else x += k;
    n--;
  }
   cout << x << endl;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
ll power(ll a, ll b)
{
    ll res=1LL;
    while(b>0)
    {
        if(b&1LL) res=(res*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    ll ans=power(10,n)-power(9,n)-power(9,n)+power(8,n);
    ans%=mod; ans+=mod; ans%=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

LL q, h, s, d, n, ans;
int a[10], f[10];
int main()
{
	scanf("%lld %lld %lld %lld", &q, &h, &s, &d);
	scanf("%lld", &n);
	f[1] = q * 8;
	f[2] = h * 4;
	f[3] = s * 2;
	f[4] = d;
	a[1] = f[1];
	for(int i = 1; i <= 4; i++)
	{
		a[1] = min(a[1], f[i]);
	}
	f[1] = q * 4;
	f[2] = h * 2;
	f[3] = s;
	a[2] = f[1];
	for(int i = 1; i <= 3; i++)
	{
		a[2] = min(a[2], f[i]);
	}
	if(2 * a[2] > a[1] && n > 1) {
		ans = (LL)(n / 2) * (LL)a[1];
		if(n % 2 == 1) ans += a[2];
	}
	else ans = (LL)n * (LL)a[2];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;

int main(){
  cin >> n;
  for(lli i = 0;i <= n;i += 4){
    if((n-i)%7 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin>>N;
	long long int a=0,b=0,ans=1000000000000000000LL;
	vector<int>A(N);
	REP(i,N){
		cin>>A[i];
		a+=A[i];
	}
	REP(i,N-1){
		b+=A[i];
		//cout<<a<<" "<<b<<endl;
		ans=min(ans,abs(a-2*b));
	}
	cout<<ans<<endl;
	return 0;
}
	

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n;
    
    while(cin >> n)
    {
        int t = 1, c = 0;
        
        for(int i = 0; i < 20; i++)
        {
            if(n & t)
            {
                if(c++) { cout << ' '; }
                
                cout << t;
            }
            
            t *= 2;
        }
        
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3096
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#include <functional>

#define SIZE 300005
#define INF 1000000000
#define FD(d) fixed << setprecision(d)
#define MOD 1000000007
#define ll long long

using namespace std;

typedef pair<ll, ll> P;

int main()
{
	int a, b, c;
	

	cin >> a >> b >> c;


	if ((a == 5 || 7 == a) && (b == 5 || 7 == b) && (c == 5 || 7 == c)) {
		if (a + b + c == 17) {
			cout << "YES" << endl;
			return(0);
		}
	}
	cout << "NO" << endl;
	return (0);
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500 * i + 100 * j + 50 * k == X:
                count += 1
print (count)

Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    int N = S.length();
    int A[] = new int[N];
    int Len = 0;
    int RL = 0;
    
    for (int i = 0; i < N; i++){
      if(S.substring(i,i+1).equals("R")){
        Len++;
        RL++;
      } else {
        if(i == N-1 || S.substring(i+1,i+2).equals("R")){
          Len++;
          if(Len%2 == 0){
            A[i-Len+RL]   = Len/2;
            A[i-Len+RL+1] = Len/2;
          } else {
            if(RL%2 == 0){
              A[i-Len+RL]   = Len/2;
              A[i-Len+RL+1]   = Len/2+1;
            } else {
              A[i-Len+RL]   = Len/2+1;
              A[i-Len+RL+1]   = Len/2;
            }
          }
          Len = 0;
          RL = 0;
        } else {
          Len++;
        }
      }
    }
    for (int i = 0; i < N; i++){
      System.out.print(A[i] + " ");
    }
  }
}

Measured memory_bytes: 43780
#include<stdio.h>
#define FREE 0
#define NOT_FREE 1
#define N 8
void putQueen(int);
void show();
int col[N];
int row[N];
int dpos[N*2];
int dneg[N*2];
int A[N][N];
int B[N][N];

int main(){
  int n,i,j,k,x,y;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);//row,col
    A[x][y]=1;

    }


  putQueen(0);
  return 0;
}
void putQueen(int i){
  int j,f,l,m;

  if(i==N){
    f=0;
    for(l=0;l<N;l++){
      for(m=0;m<N;m++){
	if(A[l][m]!=0&&A[l][m]!=B[l][m])
	  f=1;
      }
    }
    if(f==0)
    show();

    return;
  }
  for(j=0;j<N;j++){
 
    if(col[j]== NOT_FREE){continue;}
    if(dpos[i+j]==NOT_FREE) continue;
    if(dneg[i-j+N-1]==NOT_FREE){
      continue; 
    } 
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    B[i][j]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    B[i][j]=FREE;

  }
}
void show(){
  int i,j;
for(i=0;i<N;i++){
    for(j=0;j<N;j++){

      if(row[i]==j)
	printf("Q");
      else
	printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2108
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    
    int K;
    cin >> K;
    cout << (K/2)*((K+1)/2) << endl;
    
    
    return 0;
}


Measured memory_bytes: 256