akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input=input.split("\n");
  const N=input[0].split(' ')[0]-0;
  const M=input[0].split(' ')[1]-0;
  var price=input[1].split(' ').map(e=>{
    return e-0;
  });
  var numberOfDigits=new Array(N);
  var memo=new Array(N);
  price.forEach((e,i)=>{
    numberOfDigits[i]=Math.floor(Math.log2(price[i]));
    if(memo[Math.floor(Math.log2(price[i]))]===undefined){
      memo[Math.floor(Math.log2(price[i]))]=1;
    }else{
      memo[Math.floor(Math.log2(price[i]))]++;
    }
  });
  for(var i=0;i<memo.length;i++){
    if(memo[i]===undefined){
      memo[i]=0;
    }
  }
  var numberOfCounted=0;
  var sum=0;
  var threshold=0;
  for(var i=memo.length-1;i>=0;i--){
    numberOfCounted+=memo[i];
    sum+=numberOfCounted;
    //console.log(sum);
    if(sum>M){
      threshold=i;
      break;
    }
  }
  var remain=M;
  for(var i=0;i<price.length;i++){
    if(numberOfDigits[i]>threshold){
      price[i]=Math.floor(price[i]/2**(numberOfDigits[i]-threshold));
      remain-=numberOfDigits[i]-threshold;
    }
  }
  //console.log(threshold,remain,numberOfDigits);
  price.sort((a,b)=>{
    return -a+b;
  });
  //console.log(price);
  var ret=0;
  for(var i=0;i<price.length;i++){
    if(i<remain){
      ret+=Math.floor(price[i]/2);
    }else{
      ret+=price[i];
    }
  }
  console.log(ret);
  
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 45020
N, L = map(int, input().split())

sumA = 0
for i in range(N):
    sumA += (L + i)
    
cur_diff = float('inf')
ans = 0
for i in range(N):
    tmp = sumA - (L + i)
    diff = abs(sumA - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp
        
print(ans)

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

static const int MAX_N = 100;
static const int MAX_W = 1e5;

int N, W;
int v[MAX_N];
int w[MAX_N];
long dp[MAX_N + 1][MAX_W + 1];

long dfs(int i, int j) {
  if (i >= N)
    return 0;
  if (dp[i][j] >= 0)
    return dp[i][j];
  long res = dfs(i + 1, j);
  if (j >= w[i]) {
    res = max(res, dfs(i + 1, j - w[i]) + v[i]);
  }
  return dp[i][j] = res;
}

long solve_dfs() {
  fill(dp[0], dp[0] + (MAX_N + 1) * (MAX_W + 1), -1);
  return dfs(0, W);
}

long solve() {
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (j < w[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }
  return dp[N][W];
}

long solve_backward() {
  for (int i = N - 1; i >= 0; --i) {
    for (int j = 0; j <= W; ++j) {
      if (j < w[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }
  return dp[0][W];
}

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  long ret = solve();
  if (ret != solve_dfs())
    return 1;
  fill(dp[0], dp[0] + (MAX_N + 1) * (MAX_W + 1), 0);
  if (ret != solve_backward())
    return 1;

  cout << ret << endl;
  return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T &b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T &b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

map<int,int,greater<int>> mp;
vector<int> vi;

int main()
{
    int N;
    cin >> N;
    _for(i,0,N){
        int num;
        cin >> num;
        vi.PB(num);
        mp[num]++;
    }
    int fs = mp.begin()->first;
    int sc;
    if(mp.begin() -> second >= 2) sc = fs;
    else sc = (++mp.begin())->first;
    _for(i,0,N){
        if(vi[i] != fs) cout << fs <<endl;
        else cout << sc << endl;
    }

    return 0;
}


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

using namespace std;

int main() {
	int N, A, B; cin >> N >> A >> B;
	int res = 0;
	for(int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		if (!(A<=tmp && tmp<B)) res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: usize = read()[0];
    let v: Vec<Vec<Vec<usize>>> = (0..n)
        .map(|_| (0..read()[0]).map(|_| read()).collect())
        .collect();

    let mut ans = 0;
    for b in 0..1 << n {
        if (0..n).all(|j| (b >> j) & 1 == 0 || v[j].iter().all(|q| (b >> (q[0] - 1)) & 1 == q[1])) {
            ans = std::cmp::max(ans, b.count_ones());
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int cal(int a, int b)
{
    int c = a / 2;
    if((ll)a + c > (ll) b * c) return (int)((ll)a + c - (ll)b * c);
    int x = (int)ceil(b * c * 1.0 / (a + c));
    return max((a + c) * x - b * c, (b - x) * (a - 2 * c));
}
int cal2(int a, int b)
{
    int c = (int)ceil(a / 2.0);
    if(a + c > (ll)b * c) return 1e9;
    int x = (ll)b * c / ( c + a );
    return max((int)((ll)b * c - (ll)x * (a + c)), (int)((ll)(b - x) * ( 2 * c - a )));
}
int cal3(int a, int b)
{
    double x = floor(b / 3.0);
    double y = ceil(b / 3.0);
    return (int)(y * a - x * a);
}
int main()
{
    int a, b;
    a = read();
    b = read();
    int ans = min(cal(a, b), min(cal(b, a), min(cal2(a, b), min(cal2(b, a), min(cal3(a, b), cal3(b, a))))));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  int nth = b - a;
  int true_height_b = nth * (nth + 1) / 2;
  printf("%d\n", true_height_b - b);
  return 0;
}


Measured memory_bytes: 760
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,a;
    for(i=0;i<10000;i++){
        cin >> a;
        if (a ==0){
            break;
        }else{
            cout << "Case " << (i+1) << ": " << a << endl;
        }
    }
}


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

class beaker {
private:
  std::int_fast64_t a;
  std::int_fast64_t b;
  std::int_fast64_t c;
  std::int_fast64_t d;
  std::int_fast64_t e;
  std::int_fast64_t f;

  beaker create_new_beaker(const std::int_fast64_t water, const std::int_fast64_t sugar) const {
    return beaker(this->a, this->b, this->c, this->d, this->e, this->f, water, sugar);
  }

  bool is_legal() const {
    return this->water > 0 && 100 * this->sugar <= this->water * this->e && this->total() <= this->f;
  }

public:
  std::int_fast64_t water;
  std::int_fast64_t sugar;

  beaker(
    const std::int_fast64_t a,
    const std::int_fast64_t b,
    const std::int_fast64_t c,
    const std::int_fast64_t d,
    const std::int_fast64_t e,
    const std::int_fast64_t f,
    const std::int_fast64_t water,
    const std::int_fast64_t sugar
  ) :
    a(a),
    b(b),
    c(c),
    d(d),
    e(e),
    f(f),
    water(water),
    sugar(sugar) {
  }

  beaker(const beaker&) = default;
  beaker& operator=(const beaker&) = default;
  beaker(beaker&&) = default;

  std::int_fast64_t total() const {
    return this->water + this->sugar;
  }

  beaker operateA() const {
    return this->create_new_beaker(this->water + 100 * this->a, this->sugar);
  }

  beaker operateB() const {
    return this->create_new_beaker(this->water + 100 * this->b, this->sugar);
  }

  beaker operateC() const {
    return this->create_new_beaker(this->water, this->sugar + this->c);
  }

  beaker operateD() const {
    return this->create_new_beaker(this->water, this->sugar + this->d);
  }

  friend bool operator<(const beaker& lhs, const beaker& rhs) {
    return rhs.is_legal()
      ? lhs.is_legal()
        ? rhs.total() * lhs.sugar < lhs.total() * rhs.sugar
        : true
      : false;
  }
};

int main() {
  std::int_fast64_t a, b, c, d, e, f;
  std::cin >> a >> b >> c >> d >> e >> f;

  std::vector<beaker> dp(f + 1, beaker(a, b, c, d, e, f, 0, 0));
  for (std::int_fast64_t i = 0; i < f; ++i) {
    if (i + 100 * a <= f) dp[i + 100 * a] = std::max(dp[i + 100 * a], dp[i].operateA());
    if (i + 100 * b <= f) dp[i + 100 * b] = std::max(dp[i + 100 * b], dp[i].operateB());
    if (i + c <= f) dp[i + c] = std::max(dp[i + c], dp[i].operateC());
    if (i + d <= f) dp[i + d] = std::max(dp[i + d], dp[i].operateD());
  }

  const beaker optimized_beaker = *std::max_element(dp.begin(), dp.end());
  std::cout << optimized_beaker.total() << ' ' << optimized_beaker.sugar << std::endl;

  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	map<int,int> deg;
	while(m-->0) {
		int a,b; cin>>a>>b;
		if(a==1||a==n) deg[b]++;
		if(b==1||b==n) deg[a]++;
	}
	for (int i=2; i<=n-1; i++)
		if(deg[i]==2) {
			cout<<"POSSIBLE\n";
			return 0;
		}
	cout<<"IMPOSSIBLE\n";
	return 0;
}


Measured memory_bytes: 9600
let () =
    let m = 1000000000 + 7 in
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let sn = float n |> sqrt |> floor |> int_of_float in
        let perfect = n / sn = sn in
        let arr = Array.make (2 * sn - if perfect then 1 else 0) 1 in
        for i = 0 to sn - 1 do
            arr.(i) <- n/(i + 1) - n/(i + 2)
        done;
        let l = Array.length arr in
        let rev = Array.init l (fun i -> arr.(l - 1 - i)) in
        let rec loop i prev =
            if i = 0 then prev.(l - 1) else (
                let next = Array.make l 0 in
                for j = 0 to l - 1 do
                    next.(j) <- ((if j = 0 then 0 else next.(j - 1)) + prev.(l - 1 - j) * rev.(j)) mod m;
                done;
                loop (i - 1) next
            )
        in
        Printf.printf "%d\n" (loop k (Array.make l 1))
    in
    main ()

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, w;
  cin >> n >> h >> w;
  vector<int> height(n);
  vector<int> width(n);
  for (int i = 0; i < n; i++) {
    cin >> height.at(i) >> width.at(i);
  }
  int ans = n;
  for (int i = 0; i < n; i++) {
    if (height.at(i) < h || width.at(i) < w) ans--;
  }
  cout << ans << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
struct edge {
  ll to, cost;
};

// UnionFindを示す構造体
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(M), B(M); 
  REP(i, M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }
  UnionFind uf(N);
  ll res = N * (N - 1) / 2;
  vector<ll> ans;
  for(int i = M - 1; i >= 0; --i) {
    ans.push_back(res);
    ll sizA = uf.size(A[i]); ll sizB = uf.size(B[i]);
    if(!uf.issame(A[i], B[i])) res -= sizA * sizB;
    uf.merge(A[i], B[i]);
  }
  for(int i = ans.size() - 1; i >= 0; --i) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 6280
S = input()

a = 0
b = 0
c = 0
o = 0

for i in S:

    if i == "a":
        a += 1


    elif i == "b":
        b += 1


    elif i == "c":
        c += 1

    else:
        o += 1

if a == 1 and b == 1 and c == 1 and o == 0:
    print("Yes")
else:
    print ("No")

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))

up=2
ans=1
for i in range(1,n):
    if up==2:
        if a[i-1]<a[i]:
            up=1
        elif a[i-1]>a[i]:
            up=0
    elif up==1 and a[i-1]>a[i]:
        up=2
        ans+=1
    elif up==0 and a[i-1]<a[i]:
        up=2
        ans+=1
        
print(ans)

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

int n ; 
double dp[303][303][303];

double func(int a1, int a2 ,int a3)
{ 

	if(!(a1+a2+a3))
	return(0);

    
	if(dp[a1][a2][a3]!=-1)
	return(dp[a1][a2][a3]);
	
    
	double num = a1+a2+a3; 
    double p1 = 0 , p2 =0 , p3 = 0 ; 
    
    
    
	if(a1)
	{
		p1 = a1/num *func(a1-1, a2, a3);
	}
	if(a2)
	{
		p2 = a2/num *func(a1+1, a2-1, a3);
	}
	if(a3)
	{
		p3 = a3/num *func(a1, a2+1, a3-1);
	}
	//cout<<a1<<"*"<<a2<<"*"<<a3<<endl;
    //cout<<p1<<"*"<<p2<<"*"<<p3<<"*"<<n/num<<"**"<<(p1+p2+p3+(n/num))<<endl;
    
	return(dp[a1][a2][a3]=(p1+p2+p3+(n/(num))));
}

int main()
{  ios_base::sync_with_stdio(false);cin.tie(NULL);
cin>>n ; 
int x ; int a1 =  0, a2 = 0 , a3 =0 ; 
for(int i = 0  ; i<n ; i++)
{
	cin>>x ; 
	if(x==1)
	a1++;
	else if(x==2)
	a2++; 
	else
	a3++;
} 
for(int i = 0 ; i<=n; i++)
{
	for(int j = 0 ;j<=n; j++)
	{
		for(int k = 0; k<=n; k++)
		dp[i][j][k]= -1 ; 
	}
}
cout<<fixed;
cout<<setprecision(11);
cout<<func(a1,a2,a3);
return(0);
}


Measured memory_bytes: 217472
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long mod = (long)Math.pow(10,9) + 7;
        long pow = 1;
        long n = sc.nextLong();
        for(int i = 1; i <= n; i++){
            pow *= i;
            pow %= mod;
        }
        System.out.println(pow);
    }
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, K;
  cin >> N >> K;
  map<int, int> mp;

  int tmp;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    mp[tmp]++;
  }

  vector<int> vecA;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    vecA.push_back(itr->second);
  }

  sort(vecA.rbegin(), vecA.rend());

  int Nmans = 0;
  for(int i = 0; i < vecA.size() && i < K; i++){
    Nmans += vecA[i];
  }

  cout << (N - Nmans) << endl;

  return 0;
}


Measured memory_bytes: 10744
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;
using  ull = unsigned long long int;

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

ull md = (ull)pow(10, 9) + 7;

ull func(int n) {
	ull sum = 1;

	rep(i, 1, n + 1) {
		sum *= i;
		sum = sum %md;
	}
	return sum;

}

int main() {


	int dog, monkey;
	cin >> dog >> monkey;
	ull sum = 1;

	if (2 <= abs(dog - monkey)) {
		cout << "0" << endl;
		return 0;
	}
	

	if (dog == monkey) {
		sum *= func(monkey)*func(dog) * 2;
	}
	else {
		sum *= func(monkey)*func(dog);
	}


	cout << sum%md << endl;
	


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, A, B, t, c;

int main () {
        cin >> N >> A >> B;
        fo(i, 0, N) {
                cin >> t;
                c += (t < A || t >= B);
        }
        cout << c << endl;
        return 0;
}


Measured memory_bytes: 256
declare var require: (x: string) => any;

function Main(input: string[]) {
  const [n, m] = input[0].split(' ').map(x => +x);
  // const arr = input.slice(1, m+1).map(s => s.split(' ').map(x => +x)).sort();
  //
  // let ans = 0;
  // arr.reduce((pre: number, cur: number[]) => {
  //   if (pre <= cur[0]) {
  //     ans++;
  //     return cur[1];
  //   } else {
  //     return Math.min(pre, cur[1]);
  //   }
  // }, n+1);
  //
  // console.log('%d', ans + 1);

  const arr = new Int32Array(n + 1).fill(n);
  input.forEach((s, i) => {
    if (i == 0 || i > m) return;
    const [a, b] = s.split(' ').map(x => +x - 1);
    arr[a] = Math.min(arr[a], b);
  });

  let ans = 0;
  let wall = n;
  for (var i = 0; i < n; i++){
    if (i >= wall) {
      ans++;
      wall = arr[i];
    } else {
      wall = Math.min(wall, arr[i]);
    }
  }

  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));


Measured memory_bytes: 29164
n,a,b,c,d=map(int,input().split())
s=list(input())
fa=True
fb=True
ff=False
for i in range(a,c-1):
    if s[i]=="#" and s[i+1]=="#":
        fa=False
for i in range(b,d-1):
    if s[i]=="#" and s[i+1]=="#":
        fb=False
if c>d:
    for i in range(b-2,d-1):
        if s[i]=="." and s[i+1]=="." and s[i+2]==".":
            ff=True
if c<d:
    if fa and fb:
        print("Yes")
    else:
        print("No")
else:
    if fa and fb and ff:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 61680
#include<bits/stdc++.h>
using namespace std;
#define ll              long long int
#define ull             unsigned long long int
#define mod             1000000007 
#define pb              push_back
#define mp              make_pair
#define count_1(n)      __builtin_popcountll(n) //set bits
#define fr              first
#define sc              second

bool isPrime(ll n) {

  if (n == 1) {
    return false;
  }

  for (ll i = 2; i*i <=n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

 
   
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;     
    x = x % p;  
                
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 

int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
  
        if (arr[mid] == x) 
            return mid; 
  
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
  
        return binarySearch(arr, mid + 1, r, x); 
    } 
  
    return -1; 
} 



int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
        ll n;
        cin>>n;
        if(n==1)
            cout<<0;
        else {
            ll ans=(((power(10,n,mod)+(power(8,n,mod)))%mod)-((2*(power(9,n,mod)))%mod) + mod ) %mod;
           
            cout<<ans;
            
        }
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  int nx=-1000,ny=1000;
  cin>>n>>m>>x>>y;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    nx=max(nx,a);
  }
  for(int i=0;i<m;i++){
    int b;
    cin>>b;
    ny=min(ny,b);
  }
  for(int i=x+1;i<=y;i++){
    if(x<i&&i<=y&&nx<i&&ny>=i){
      cout<<"No War"<<endl;
      return(0);
    }
  }
  cout<<"War"<<endl;
  return(0);
}


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

int main(){
  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;
  string u; cin >> u;
  
  if(s == u) --a;
  if(t == u) --b;
  cout << a << ' ' << b << endl;
  return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  string tmp="";
  int kotae=0;
  for(int i=0;i<n;i++){
    int count=1;
    string a=s.substr(i,count);
    if(tmp==a){
      while(tmp==a){
        count++;
        a=s.substr(i,count);
        i+=count-1;
      }
    }
    //cout<<a<<" ";
    if(i+1>n)break;
    kotae++;
    count=1;
    tmp=a;
  }
  cout<<kotae<<endl;
  return 0;
}
      



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

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int i = a;
    int count = 0;
    while(i<=b){
        if(c%i==0)count++;
        i++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int x;
	cin >> x;
	int a = x / 500;
	x -= 500 * a;
	int b = x / 5;
	cout << 1000 * a + 5 * b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	
	int x1,y1,z1,w1;
	int x2,y2,z2,w2;
	int x3,y3,z3,w3;
	int n ;
	while(cin>>n,n){
	
	for(int i = 0 ; i< n ; i ++){
		cin>>x1>>y1>>z1>>w1>>x2>>y2>>z2>>w2;
		x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
		y3 = x2 * y1 + y2 * x1 - z2 * w1 + w2 * z1;
		z3 = x2 * z1 + y2 * w1 + z2 * x1 - w2 * y1;
		w3 = x2 * w1 - y2 * z1 + z2 * y1 + w2 * x1;
		cout<<x3<<" "<<y3<<" "<<z3<<" "<<w3<<endl;
	}
	}
}

Measured memory_bytes: 1160
/*
AizuOnline A0516
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
#include <limits.h>
//Global data section
int n,k,a[100000];
int maxval,sumval;
//
main()
{
  int i,w;

  while(EOF != scanf("%d %d",&n,&k) && (n || k))
    {
      sumval=0;maxval=INT_MIN;
      for(i=0;i<n;i++)
	{
	  //printf("::%d\n",i);
	  scanf("%d",&w);
	  a[i]=w;
	  if(i < k)
	    {
	      sumval += w;
	      if(i == k-1)
		{
		  maxval = sumval;
		  //printf("sv=%d\n",sumval);
		}
	    }
	  else
	    {
	      sumval = sumval + w - a[i-k];
	      if(maxval < sumval)
		maxval=sumval;
	      //printf("sv=%d\n",sumval);
	    }
	}
      printf("%d\n",maxval);
    }

return(0);
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int l=1, r=l+m;
  while(l < r){
    printf("%d %d\n", l,r);
    l++;r--;
  }
  l=1+m+1, r=l+m-1;
  while(l < r){
    printf("%d %d\n", l,r);
    l++;r--;
  }
  return 0;
}

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

using namespace std;

int N, X[16], Y[16];

bool isparallel(int a, int b, int c, int d)
{
  auto dx1 = X[a] - X[b];
  auto dy1 = Y[a] - Y[b];
  auto dx2 = X[c] - X[d];
  auto dy2 = Y[c] - Y[d];
  return (dx1 * dy2 == dy1 * dx2);
}

bool matched[16];

int rec(int);

int parallel_rec(int latte, int malta, int idx, int sz)
{
  if(idx == N) {
    return (rec(latte + 1));
  }
  if(matched[idx]) {
    return (parallel_rec(latte, malta, idx + 1, sz));
  }
  int ret = parallel_rec(latte, malta, idx + 1, sz);
  for(int j = idx + 1; j < N; j++) {
    if(matched[j]) continue;
    if(isparallel(latte, malta, idx, j)) {
      matched[idx] = true;
      matched[j] = true;
      ret = max(ret, parallel_rec(latte, malta, idx + 1, sz + 1) + sz);
      matched[j] = false;
      matched[idx] = false;
    }
  }
  return (ret);
}

int rec(int idx)
{
  if(idx == N) {
    return (0);
  }
  if(matched[idx]) {
    return (rec(idx + 1));
  }
  int ret = rec(idx + 1);
  for(int j = idx + 1; j < N; j++) {
    if(matched[j]) continue;
    matched[idx] = true;
    matched[j] = true;
    ret = max(ret, parallel_rec(idx, j, 0, 1));
    matched[j] = false;
    matched[idx] = false;
  }
  return (ret);
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  cout << rec(0) << endl;
}

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

#define MAX 10002
#define sqrtMAX 100

int main()
{
	bool b[MAX+1] = {0};
	int i, j;
	b[0] = 1;
	b[1] = 1;
	for(i=4; i<=MAX; i+=2) b[i] = 1;
	for(i=3; i<=sqrtMAX; i+=2)
		for(j=i+i; j<=MAX; j+=i) b[j] = 1;

	int p[MAX+1] = {0};
	j = 5;
	for(i=5; i<MAX-2; i+=2) {
		p[i] = j;
		p[i+1] = j;
		if ( !(b[i]|b[i+2]) ) j = i+2;
	}

	while (cin>>i, i) cout<<p[i]-2<<" "<<p[i]<<endl;

	return 0;
}

Measured memory_bytes: 916
s = int(input())

s1 = int(s/100)
s2 = int((s-s1*100)/10)
s3 = int((s-s1*100-s2*10))

n = 0

if s1 ==1 :
  n += 1

if s2 ==1 :
  n += 1

if s3 == 1 :
  n += 1
  
print(n)

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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  vector<pii> cnts;
  int a = 0, b = 0;
  cnts.push_back(make_pair(a, b));
  for (int i = 1; i <= S.size(); i++) {
    if (S[i - 1] == '#')
      a++;
    else if (S[i - 1] == '.')
      b++;
    cnts.push_back(make_pair(a, b));
  }
  int res = 1 << 29;
  for (int i = 0; i <= S.size(); i++) {
    res = min(res, cnts[i].first + cnts[N].second - cnts[i].second);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 2700
use proconio::input;

const MOD: i64 = 1000000007;

fn mpow(a: i64, b: i64) -> i64 {
  let tmp = if b % 2 == 1 { a } else { 1 };
  match b {
    0 => 1,
    _ => tmp * mpow(a * a % MOD, b / 2) % MOD
  }
}

fn main() {
  input! {
    n: i64,
    k: i64
  }
  let mut dp = vec![0; k as usize + 1];
  
  for i in (1..=k).rev() {
    dp[i as usize] = mpow(k / i, n);
    for j in (i*2..=k).step_by(i as usize) {
      dp[i as usize] = (dp[i as usize] + MOD - dp[j as usize]) % MOD;
    }
  }
  
  println!("{}", (1..=k).fold(0, |v, t| (v + dp[t as usize] * t % MOD) % MOD))
}



Measured memory_bytes: 2780
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
	int n;
	cin >> n;

	if (n%2 != 0){
		cout << n/2+1 << endl;
	}
	else{
		cout << n/2 << endl;
	}

	return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(f.readLine());
        int[][] counts = new int[n+1][3];
        String str = f.readLine();
        for(int i = 1; i <= n; i++){
            if(str.charAt(i-1) == 'R'){
                counts[i][0] = counts[i-1][0]+1;
                counts[i][1] = counts[i-1][1];
                counts[i][2] = counts[i-1][2];
            }
            if(str.charAt(i-1) == 'G'){
                counts[i][0] = counts[i-1][0];
                counts[i][1] = counts[i-1][1]+1;
                counts[i][2] = counts[i-1][2];
            }
            if(str.charAt(i-1) == 'B'){
                counts[i][0] = counts[i-1][0];
                counts[i][1] = counts[i-1][1];
                counts[i][2] = counts[i-1][2]+1;
            }
        }
        long sum = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                char c1 = str.charAt(i);
                char c2 = str.charAt(j);
                char other = '.';
                int idx = -1;
                if(c1 != c2){
                    if(c1 == 'R' && c2 == 'B' || c1 == 'B' && c2 == 'R'){
                        idx = 1;
                        other = 'G';
                    }else if(c1 == 'R' && c2 == 'G' || c1 == 'G' && c2 == 'R'){
                        idx = 2;
                        other = 'B';
                    }else{
                       idx = 0;
                       other = 'R';
                    }
                    sum+=(counts[n][idx]-counts[j+1][idx]);
                    if(j+(j-i) < n && str.charAt(j+(j-i)) == other) sum--;
                }
            }
        }
        out.println(sum);
        out.close();


    }
}


Measured memory_bytes: 34304
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=a;i<b;i++)
#define rep2(i,a,b) for (int i=a;i>=b;i--)
#define mod 1000000007
#define INF  1e9+5
#define fr first
#define se second
#define int long long
#define ll long long
#define PI 3.1415926535 
#define pll pair <ll,ll>
#define vl vector <ll>
#define mll map<ll,ll>
#define mci map<char,int>
#define msi map<string,int>
#define vb  vector <bool>
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 100005;
int height[N];
bool vis[N];
vl adj[N];
ll r=100,c=100;
ll r1,c1;
ll M[100][100];
ll level[N];
bool visited[100][100];
void dfs(ll M[][100], ll R, ll C, bool visited[][100]) 
{
    visited[R][C]=true;
    ll row[] = {-1,-1,-1,0,0,1,1,1};
    ll col[] = {-1,0,1,-1,1,-1,0,1};
    for(int k=0;k<8;k++)
    {
       if(R+row[k]>=0 && R+row[k]<=r1 && C+col[k]>=0 && C+col[k]<=c1 && M[R+row[k]][C+col[k]] && visited[R+row[k]][C+col[k]]==0)
       dfs(M,R+row[k],C+col[k],visited);
    }
}
void bfs(ll s)
{
   queue<ll>q;
   q.push(s);
   vis[s]=true;
   level[s]=0;
   while(!q.empty())
   {
       ll p= q.front();
       q.pop();
       for(int i=0;i<adj[p].size();i++)
       {
           if(vis[adj[p][i]]==false)
           {
               level[adj[p][i]]=level[p]+1;
               vis[adj[p][i]]=true;
               q.push(adj[p][i]);
           }
       }
   }
}
ll power(ll a,ll b,ll c)
{
    ll result=1;
    while(b)
   {
    if(b&1) result=(result*b)%c;
    a=(a*a)%c;
    b=b/2;
   }
   return result%c;
}
signed main()
{
    Senky_Bansal
    IIIT_ALLAHABAD
     
    ll a,b;
    cin>>a>>b;
    if(a>=2*b-1)
    	cout<<"YES"<<endl;
    else
    	cout<<"NO"<<endl;



}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int n;
	cin >> n;
	int p[n], q[n];
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	vector<int> a(n);
	rep(i, n) a[i] = i + 1;

	int P, Q;
	int cnt = 0;

	do {
		bool f = true;
		rep(i, n) {
			if(a[i] != p[i]) f = false;
		}
		if(f) P = cnt;
		f = 1;
		rep(i, n) {
			if(a[i] != q[i]) f = false;
		}
		if(f) Q = cnt;
		cnt++;
	} while(next_permutation(all(a)));

	cout << abs(P - Q) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,z;
	scanf("%d",&a);
	if(a>=100&&a<=999)
	{
		b=a/100;
		c=(a%100)/10;
		d=a%10;
		z=b+c*10+d*100;
		if(a==z)
		printf("Yes");
		else
		printf("No");
	}
}

Measured memory_bytes: 256
import java.math.BigDecimal;
        import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        
        long[][][] dp = new long[n+1][n+1][3010];
        
        dp[0][0][0] = 1;
 
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k <= 2500; k++) {
                    dp[i + 1][j][k] += dp[i][j][k];
                    if (k>=x[i]) dp[i + 1][j + 1][k] += dp[i][j][k-x[i]];
                }
            }
 
        }
 
        long ans = 0;
        for (int j = 1; j <= n; j++) {
            ans += dp[n][j][j * a];
        }
        System.out.println(ans);
 
    }
 
}

Measured memory_bytes: 128328
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
    DRI(n);
    puts((n%10==9||n/10==9)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;

    bool can = false;

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j + i < N; j++)
        {
            if (4 * i + 7 * j == N)
            {
                can = true;
                break;
            }
        }
        if (can)
        {
            break;
        }
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
i = 0
k = 1
while i < n:
    if l[i] == k:
        k = k+1
        i = i+1
    else:
        i = i+1
if k == 1:
    print(-1)
else:
    print(n-k+1)

Measured memory_bytes: 24744
package main

import (
	"fmt"
	"unicode"
)

func main() {
	s := map[rune]string{}

	for i := 0; i < 3; i++ {
		var input string
		fmt.Scan(&input)
		s['A'+rune(i)] = input
	}

	turn := 'A'

	for s[turn] != "" {
		pre := turn
		turn = unicode.ToUpper(rune(s[turn][0]))

		s[pre] = s[pre][1:]
	}

	fmt.Println(string(turn))
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
   
public class Main {
       
     
    public static void main(String[] args) {
            
          try {
                 
        	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
            String s = null;
            String now = "A";
            
            while((s = br.readLine())!=null){
       		 StringTokenizer st = new StringTokenizer(s,",");
       		 String first = st.nextToken();
       		 String second = st.nextToken();
       		 if(now.equals(first))
       		 {
       			 now = second;
       			 
       		 }
       		 else if(now.equals(second))
       		 {
       			 now = first;	
       		 }
       		
            }
            System.out.println(now);
          }catch (Exception e) {
              e.printStackTrace();
            }
        }
      
}
    

Measured memory_bytes: 24084
//Author: ZindagiMeBasAishHiChahiye
//WA/TLE
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ll          long long
#define N 1000005
// ll po(ll a,ll b,ll m){
// 	a%=m;
// 	if(b==0) return 1;
// 	if(b%2) return (a*(po((a*a)%m,b/2,m)%m)%m)%m;
// 	return po((a*a)%m,b/2,m)%m;
// }

bool check(ll a,ll b,ll x,ll y){
	if(a<0||b<0) return false;
	if(a>=x||b>=y) return false;
	return true;
}
ll x[1004][1004];
bool vis[N];
string s[1000];
set<int> st[N];
vi ad[N];
void dfs(ll i,ll j,ll c,ll h,ll w){
	if(x[i][j]||s[i][j]=='#') return;
	x[i][j]=c;
	if(check(i,j+1,h,w)) dfs(i,j+1,c,h,w);
	if(check(i,j-1,h,w)) dfs(i,j-1,c,h,w);
	if(check(i+1,j,h,w)) dfs(i+1,j,c,h,w);
	if(check(i-1,j,h,w)) dfs(i-1,j,c,h,w);
}

void bfs(ll a,ll b,ll &an){
	queue<pii> q;
	q.push({a,0});
	vis[a]=true;
	while(!q.empty()){
		pii pp=q.front();
		q.pop();
		for(auto x:ad[pp.F]){
			if(!vis[x]){
				vis[x]=true;
				q.push({x,pp.S+1});
				if(x==b){
					an=pp.S+1;
					return;
				}
			}
		}
	}
}
void solve(){
	ll h,w,M;
	cin>>h>>w>>M;
	vi ro(h,0);
	vector<pii> co(w);
	rep(i,0,w){
		co[i].F=0;
		co[i].S=i;
	}
	map<pii,ll> m;
	rep(i,0,M){
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		m[{a,b}]=1;
		ro[a]++;
		co[b].F++;
	}
	sort(all(co),greater<pii>());
	// cout<<co[1].F;
	ll an=0;
	rep(i,0,h){
		rep(j,0,w){
			// cout<<i<<j<<ro[i]<<endl;
			ll c=ro[i]+co[j].F;
			if(m[{i,co[j].S}]) an=max(an,c-1);
			else {
				an=max(an,c);
				break;
			}
		}
	}
	cout<<an;

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1,z=1;
	// cin>>TESTS;
	while(TESTS--){
		// time
		// cout<<"Case #"<<z<<": ";
		// z++;
		solve();
		time

	}
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int vec[n];
  map<int,int> ma;
  map<int,int> mab;
  for(int i=0;i<n;i++){
    cin>>vec[i];
    if(i%2==0){
      ma[vec[i]]++;
    }
    else{
      mab[vec[i]]++;
    }
  }
  int a=0,b=0,c=1e6,d,e=0,f=0,g=1e6,h;
  for(int i=0;i<n;i+=2){
    if(ma[vec[i]]>=a){
      b=a;
      d=c;
      a=ma[vec[i]];
      c=vec[i];
      ma[vec[i]]=0;
    }
    else if(ma[vec[i]]>=b){
      b=ma[vec[i]];
      d=vec[i];
      ma[vec[i]]=0;
    }
  }
  for(int i=1;i<n;i+=2){
    if(mab[vec[i]]>=e){
      f=e;
      h=g;
      e=mab[vec[i]];
      g=vec[i];
      mab[vec[i]]=0;
    }
    else if(mab[vec[i]]>=f){
      f=mab[vec[i]];
      h=vec[i];
      mab[vec[i]]=0;
    }
  }
  if(c!=g){
    cout<<n-a-e<<endl;
    return 0;
  }
  cout<<min(n-a-f,n-b-e)<<endl;
  return 0;
}

Measured memory_bytes: 5376
#!/usr/bin/env python3
#ABC123 B

LI = [int(input()) for _ in range(5)]
LI2 = [LI[i] % 10 for i in range(5)]

x = [(LI[i],LI2[i]) for i in range(5)]
#print(x)

ans = 0
x = sorted(x, key = lambda x:x[1],reverse = True)
for i in range(5):
    if x[i][1] == 0:
        t = x[i]
        x.remove(t)
        x.insert(0,t)
#print(x)

for i in range(4):
    if x[i][1] != 0:
        ans += x[i][0] + (10 - x[i][1])
    else:
        ans += x[i][0]
ans += x[4][0]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
using namespace std;
long long int a[300001]={0};
long long int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long int k;
		cin>>k;
		int j=0;
		while(k!=0)
		{
			a[j]=a[j]+k%2;
			j++;
			k/=2;
		}
	}
	long long int max=0;
	long long int u=1;
	for(int i=0;i<=61;i++)
	{
		if(i!=0)	u*=2;
		u=u%1000000007;
		max+=(n-a[i])*a[i]%1000000007*u;
	}
	cout<<max%1000000007;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b,c,e=2;
  cin >> a >> b >> c;
  int ans=(a+b)*c/e;
  cout << ans << endl;
}


Measured memory_bytes: 256
MOD = 10**9 + 7
N = int(input())
C = []
last_idx = [0 for i in range(200001)]
bef = [0 for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
if N == 1 or N == 2:
	print(1)
	exit()

for i in range(2, N+1):
	if bef[i] < i-1:
		dp[i] = (dp[i-1] + dp[bef[i]]) % MOD
	else:
		dp[i] = dp[i-1]
print(dp[N])

Measured memory_bytes: 28332
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int i=0, j=0, k=0;
	cin>>s;
	for( ; s[i]!='A'; ++i){
		
	}
	for(j=s.length(); s[j]!='Z'; j--){
		
	}
	j++;
	cout<<j-i<<"\n";
	
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(void) {
	int a, b;
	top = 0;
	char s[100];
	while(scanf("%s", s) != EOF){
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);
		}else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a-b);
		}else if(s[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return 0;
}



Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int main(){
  int y,m,d;
  string s;
  while(1){
    cin >> s;
    if(s == "#") break;
    cin >> y >> m >> d;
    if(y>=31){
     if(y==31 && m<5){
     }
     else {
       s = "?";
       y -= 30;
     }
    }
    cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main() {
    scanf("%d",&n);
    for (int i=1,x;i<=n;++i) {
        scanf("%d",&x),a[i]=(i==x);
    }
    int ans=0;
    for (int i=1;i<=n;++i) {
        if (a[i]) a[i]=a[i+1]=0,++ans;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    if(a > b) cout << 'a' << " " << '>' << " " << 'b' << endl;
    if(a < b) cout << 'a' << " " << '<' << " " << 'b' << endl;
    if(a == b) cout << 'a' << " " << "==" << " " << 'b' << endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    reverse(all(a));
    rep(i,n-1) {
        cout << a.at(i) <<  " ";
    }
    cout << a.at(n-1) << endl;

    return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int A = S[0] - '0';
    int B = S[1] - '0';
    int C = S[2] - '0';
    int D = S[3] - '0';
    char op[2] = {'+', '-'};
    rep(i,0,2){
        rep(j,0,2){
            rep(k,0,2){
                int ans = 0;
                ans += A;
                if(i == 0){
                    ans += B;
                }else{
                    ans -= B;
                }
                if(j == 0){
                    ans += C;
                }else{
                    ans -= C;
                }
                if(k == 0){
                    ans += D;
                }else{
                    ans -= D;
                }
                if(ans == 7){
                    cout << A << op[i] << B << op[j] << C << op[k] << D << "=7" << endl;
                    return 0;
                }
            }
        }
    }



}


Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque
inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
suma = sum(a)
sumb = sum(b)
count = sumb-suma
suba = 0
subb = 0
if count < 0:
    print('No')
    sys.exit()
for i in range(n):
    if a[i] > b[i]:
        suba+=abs(a[i]-b[i])
    else:
        subb+=(abs(a[i]-b[i])+1)//2
if max(suba, subb) <= count:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 40560