akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

i32 calc (i32 k,char *s, i32 n, char *t, char *d, i32 q) {
  for (i32 i = 0; i < q && 0 <= k && k < n; ++i) {
    if (s[k] == t[i]) {
      k += (d[i] == 'L' ? -1 : 1);
    }
  }
  return k;
}

void run (void) {
  i32 n, q;
  scanf ("%" SCNi32 "%" SCNi32, &n, &q);
  char *s = (char *) calloc (n + 1, sizeof (char));
  scanf ("%s", s);
  char *t = (char *) calloc (q + 1, sizeof (char));
  char *d = (char *) calloc (q + 1, sizeof (char));
  for (i32 i = 0; i < q; ++i) {
    scanf ("%s%s", t + i, d + i);
  }
  if (calc (n - 1, s, n, t, d, q) < 0 || calc (0, s, n, t, d, q) >= n) {
    puts("0");
    return;
  }
  i32 ans = n;
  i32 l = -1;
  i32 r = n - 1;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    if (calc (m, s, n, t, d, q) < 0) {
      l = m;
    } else {
      r = m;
    }
  }
  ans -= l + 1;
  l = 0;
  r = n;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    if (calc (m, s, n, t, d, q) >= n) {
      r = m;
    } else {
      l = m;
    }
  }
  ans -= n - r;
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 768
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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


int main(void){
    string s;

    cin >> s;

    int r = 0;
    int b = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            r++;
        }
        if(s[i] == '1'){
            b++;
        }
    }

    int ans;
    if(r > b){
        cout << b * 2 << endl;
    } else {
        cout << r * 2 << endl;
    }
}



Measured memory_bytes: 512
#include <iostream>
#include <stdint.h>
#include <vector>
#include <limits.h>
#include <utility>
#include <memory>
#include <set>
#include <map>

using namespace std;

using Group = set<int>;

uint64_t calc_convenience(Group& group)
{
  uint64_t island_count = group.size();
  return island_count * (island_count-1) / 2;
}

int main()
{
  int N,M;
  cin >> N >> M;

  vector<pair<int,int>> bridges;
  
  for (int m=0; m<M; ++m) {
    int a,b;
    cin >> a >> b;
    bridges.push_back(pair<int,int>(a,b));
  }

  map<int,shared_ptr<Group>> island2group;
  set<shared_ptr<Group>> groups;

  for (int n=0; n<N; ++n) {
    set<int> new_group = {n+1};
    auto ptr_new_group = make_shared<Group>(new_group);
    island2group[n+1] = ptr_new_group;
    groups.insert(ptr_new_group);
  }

  vector<uint64_t> conveniences = {0};

  for (int m=M-1; m>=0; m--) {
    auto bridge = bridges[m];
    int a = bridge.first, b = bridge.second;
    auto group_a = island2group[a];
    auto group_b = island2group[b];
    uint64_t convenience_prev = calc_convenience(*group_a) + calc_convenience(*group_b);
    if (group_a != group_b) {
      if (group_b->size() > group_a->size())
	swap(group_a,group_b);

      for (int island_b : *group_b) {
	group_a->insert(island_b);
	island2group[island_b] = group_a;
      }
      groups.erase(group_b);
      uint64_t convenience_now = calc_convenience(*group_a);
      conveniences.push_back(conveniences.back()+convenience_now-convenience_prev);
    } else {
      conveniences.push_back(conveniences.back());
    }
  }
  
  for (auto itr = conveniences.rbegin()+1; itr != conveniences.rend(); ++itr) {
    cout << conveniences.back() - *itr << endl;
  }
  
  return 0;
}

Measured memory_bytes: 28916
N = int(input())
p = [int(i) for i in input().split()]

tmp = N + 1
count = 0
ret = 1
for i in range(N):
    if p[i] == i + 1:
        continue
    else:
        count += 1
        if count == 3:
            ret = 0
            break
        elif count == 2:
            if tmp == i + 1:
                ret = 1
            else:
                ret = 0
                break
        tmp = p[i]

if ret == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
	int n, m;
	cin >> n >> m;
	
    int a;
    vector<int> dp(n+1,1);
	for(int i=0; i<m; ++i){
        cin >> a;
        dp[a]=0;
    }
	for(int i=2; i<=n; ++i) dp[i] = dp[i]*(dp[i-1]+dp[i-2])%mod;

	cout << dp[n] << endl;
}

Measured memory_bytes: 640
n, m = [int(i) for i in input().split()]

def subdata(a, i, j):
  return [row[j:j + m] for row in a[i:i + m]]

def template_matching(a, b):
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      if subdata(a, i, j) == b:
        return "Yes"
  return "No"

print(template_matching([input() for _ in range(n)], [input() for _ in range(m)]))

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n;
int t[100010],x[100010],y[100010];

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

	cin>>n;
	FOR(i,1,n+1) cin>>t[i]>>x[i]>>y[i];

	FOR(i,1,n+1) {
		int xdif=abs(x[i]-x[i-1]),ydif=abs(y[i]-y[i-1]);
		int d=xdif+ydif;
		if(t[i]<d||((t[i]-t[i-1])%2!=d%2)) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;


	return 0;
}


Measured memory_bytes: 1408
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI = 2*acos(0.0);

signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	string word[n];
	for(int i=0;i<n;i++)cin>>word[i];
	bool valid = true;
	set<string> s;
	s.insert(word[0]);
	for(int i=1;i<n;i++)
	{
		if(word[i][0]!=word[i-1][word[i-1].length()-1])
			valid=false;
		if(s.find(word[i])!=s.end())
			valid=false;
		s.insert(word[i]);
	}
	cout<<(valid?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M, Q = list(map(int, input().split()))
abcd = []
for _ in range(Q):
    abcd.append(list(map(int, input().split())))


def get_array(array, index, remain):
    if index == N - 2:
        tmp_array = array.copy()
        tmp_array[index] = remain
        resp = []
        for i in range(remain + 1):
            tmp_array = array.copy()
            tmp_array[index] = i
            resp_array = [1]*N
            for j in range(N-1):
                resp_array[j+1] = resp_array[j] + tmp_array[j]
            resp.append(resp_array)
        return resp
    else:
        resp = []
        for i in range(remain + 1):
            tmp_array = array.copy()
            tmp_array[index] = i
            resp += get_array(tmp_array, index + 1, remain - i)
        return resp


diff_array = [0] * (N - 1)
possible = get_array(diff_array, 0, M - 1)
max_point = 0
for pos in possible:
    point = 0
    for a, b, c, d in abcd:
        if pos[b-1] - pos[a-1] == c:
            point += d
    if point > max_point:
        max_point = point
print(max_point)


Measured memory_bytes: 84240
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll n,h,d;
#define nn 1000008
ll dp[nn];
ll pre[nn];
#define mod 1000000007
ll ask(ll l,ll r){
	if(l<=0) return pre[r];
	return pre[r]-pre[l-1];
}
	ll sf[nn],f[nn];
	ll qpow(ll x){
		ll y=mod-2;ll res=1;
		while(y){
			if(y&1) res=res*x%mod;
			x=x*x%mod;y=y/2;
		}
		return res;
	}
int main(){
	cin>>n>>h>>d;
	sf[0]=f[0]=1;for(int i=1;i<nn;i++) f[i]=f[i-1]*i%mod;sf[0]=0;
	for(int i=1;i<=n;i++) sf[i]=sf[i-1]+f[i],sf[i]%=mod;
	dp[0]=1;pre[0]=f[n];
	
	for(int i=1;i<=h;i++){
		dp[i]+=ask(i-d,i-1);
		dp[i]%=mod;pre[i]=pre[i-1]+dp[i]*sf[n];pre[i]%=mod;
	}
	
	cout<<(dp[h]%mod+mod)%mod;
	
	
	return 0;
}

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

using namespace std;

int N, u, v;
vector<vector<int>> G;

void dfs(int v, int pv, int dist[]) {
  for (auto nv : G[v]) {
    if (nv == pv) continue;
    dist[nv] = dist[v] + 1;
    dfs(nv, v, dist);
  }
}

int main() {
  cin >> N >> u >> v;
  u--, v--;
  G.resize(N);
  int a, b;
  for (int i = 0; i + 1 < N; i++) {
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  int tdist[101010] = {0}, adist[101010] = {0};
  dfs(u, -1, tdist);
  dfs(v, -1, adist);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (G[i].size() != 1) continue;
    if (tdist[i] < adist[i]) {
      ans = max(ans, adist[i] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}

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

const long MOD=1000000007;
const long INF=100000000000000000;
int main(){
    long R;
    cin>>R;
    if(R<1200) cout<<"ABC"<<endl;
    else if(R<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
}

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

using namespace std;

#define MAX 35
#define INF (1<<29)
typedef pair<int, int> pii;

int main()
{
    int W, H, x;
    while (cin >> W >> H, W) {
        bool wall[MAX][MAX][4];
        for (int i = 0; i < 2*H-1; i++) {
            for (int j = 0; j < W - !(i&1); j++) {
                cin >> x;
                if (!(i & 1)) {
                    wall[i/2][j][2] = wall[i/2][j+1][0] = x;
                } else {
                    wall[(i-1)/2][j][3] = wall[i/2+1][j][1] = x;
                }
            }
        }

        queue<pii> que;
        que.push(pii(0, 0));

        vector<vector<int>> d(H, vector<int>(W, INF));
        d[0][0] = 0;

        const int dx[] = {-1, 0, 1, 0};
        const int dy[] = {0, -1, 0, 1};

        bool reachable = 0;
        
        while (!que.empty()) {
            pii p = que.front(); que.pop();
            int x = p.first, y = p.second;

            if (x == W-1 && y == H-1) {
                cout << d[y][x] + 1 << endl;
                reachable = 1;
                break;
            }
            
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (0 <= nx && nx < W && 0 <= ny && ny < H &&
                    !wall[y][x][i] &&
                    d[y][x] + 1 < d[ny][nx]) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push(pii(nx, ny));
                }
            }
        }

        if (!reachable) {
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3032
def main():
    nvertices, nedges = map(int, input().split())
    Adj = [[] * nvertices for i in range(nvertices)]
    for i in range(nedges):
        u, v = map(int, input().split())
        Adj[u].append(v)

    visited = [False] * nvertices
    ordering = []
    for u in range(nvertices):
        if not visited[u]:
            dfs(Adj, u, visited, ordering)

    for u in reversed(ordering):
        print(u)


def dfs(Adj, u, visited, ordering):
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs(Adj, v, visited, ordering)

    ordering.append(u)


main()

Measured memory_bytes: 10996
// Bismillah_hir_rahmanir_rahim

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<math.h>
#include<set>
using namespace std;
#define ll long long int
#define bug cout <<"------------------------"<<endl




int main()
{

	string str;

	cin >> str;

	if (str[0] == '7' or str[1] == '7' or str[2] == '7')cout << "Yes"<< endl;
	else
		cout << "No" << endl;

	
	return 0;
}

Measured memory_bytes: 3068
n=int(input())
s=list(input())
f=0
b=-1
for d in range(1,n):
  c=0
  b=-1
  for i in range(n-d):
    if c>=d:
      break
    if s[i]==s[i+d]:
      if b==-1:b=i
      c+=1
      f=max(f,c)
    else:
      c=0
      b=-1
print(f)


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

int main() {
  int n;
  while(cin >> n && n != -1) {
    if(n == 0) {
      cout << 0 << endl;
      continue;
    }
    vector<int> v;
    while(n) {
      v.push_back(n%4);
      n /= 4;
    }
    for(int i = v.size()-1; i >= 0; --i) cout << v[i];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	
	int ans = 0;
	for(int i = 0; i < s.size(); i++) {
		for(int j = i; j < s.size(); j++) {
			if(s[j] != 'A' and s[j] != 'C' and s[j] != 'G' and s[j] != 'T') break;
			ans = std::max(ans, j - i + 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m=0,d,z;
    string s="ACL";
    cin>>n;
    while(n--){
        cout<<s;
    }

    return EXIT_SUCCESS;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	n%=10;
	if(n==2||n==4||n==5||n==7||n==9)
	{
		cout<<"hon";
		
	}
	if(n==0||n==1||n==6||n==8)
	{
		cout<<"pon";
	}
	if( n==3)
	{
		cout<<"bon";
	}
	return 0;
}

Measured memory_bytes: 3620
N=int(input())
s=[]
sum=0
for i in range(N):
    s.append(int(input()))
    sum+=s[i]
if(sum%10!=0):
    print(sum)
    exit()
else:
    m=0
    for i in range(N):
        t=sum-s[i]
        m=max(t,m) if t%10!=0 else m
    print(m)

Measured memory_bytes: 3060
n, m = map(int, input().split())
a = list(map(int, input().split()))
del a[0]
if n != 1:
  for i in range(n-1):
    b = list(map(int, input().split()))
    del b[0]
    a = a+b
    a = [x for x in set(a) if a.count(x) > 1]
print(len(a))

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

long long** A;
long long** B;
long long** a;

long long N;

void comp(long long K)
{
    if(K == 1)
    {
        for(long long i = 1; i <= N; i++) for(long long j = 1; j <= N; j++) A[i][j] = a[i][j];
        return;
    }
    if(K % 2)
    {
        comp(K-1);
        swap(A, B);
        for(long long i = 1; i <= N; i++) for(long long j = 1; j <= N; j++)
        {
            A[i][j] = 0;
            for(long long k = 1; k <= N; k++) A[i][j] = (A[i][j] + (a[i][k] * B[k][j])) % 1000000007;
        }
    }
    else
    {
        comp(K/2);
        swap(A, B);
        for(long long i = 1; i <= N; i++) for(long long j = 1; j <= N; j++)
        {
            A[i][j] = 0;
            for(long long k = 1; k <= N; k++) A[i][j] = (A[i][j] + (B[i][k] * B[k][j])) % 1000000007;
        }
    }
}

int main()
{
    long long K;
    cin >> N >> K;

    A = new long long*[N+1];
    B = new long long*[N+1];
    a = new long long*[N+1];
    for(long long i = 1; i <= N; i++)
    {
        A[i] = new long long[N+1];
        B[i] = new long long[N+1];
        a[i] = new long long[N+1];
        for(long long j = 1; j <= N; j++) cin >> a[i][j];
    }

    comp(K);

    long long res = 0;
    for(long long i = 1; i <= N; i++) for(long long j = 1; j <= N; j++) res = (res + A[i][j]) % 1000000007;

    cout << res << '\n';
    return 0;
}

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

st = 0
i = 0
sa = 0
while i+K < N:
    sa += p[i+K]-p[i]
    if sa > 0:
        st = i+1
        sa = 0
    i += 1

psum = p[st:st+K]
for i in range(K):
    psum[i] = (psum[i]+1)/2
print(sum(psum))

Measured memory_bytes: 25060
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const ll N = 2e5+10 ;
struct node{
   ll a,b;
}res[N];
bool cmp(node A,node B){
   return A.a < B.a;
}
ll q[N];
int main(){
   ios::sync_with_stdio(false); cin.tie(0);
   ll n,d,x;
   cin >> n >> d >> x;
   d <<= 1;
   for(ll i = 1;i <= n; ++i){
      cin >> res[i].a >> res[i].b;
   }
   sort(res + 1,res + n + 1,cmp);
   ll sum = 0;
   for(ll i = 1;i <= n;++ i){
      q[i] += q[i-1];
      res[i].b -= q[i] * x;
      if(res[i].b <= 0) continue;
      ll p = (res[i].b + x - 1) / x;
      sum += p;
      q[i] += p;
      ll l = i,r = n;
      ll temp = res[i].a + d;
      while(l < r){
         ll mid = l + r + 1>> 1;
         if(res[mid].a <= temp) l = mid;
         else r = mid - 1;
      }
      q[l + 1] -= p;
   }
   cout<<sum;
   
 
 
}

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

int main(){
    long A, B, C, D, N;
    string S;

    cin >> N >> A >> B >> C >> D >> S;
    A--; B--; C--; D--;
    S += '#';

    if(C < D){
        bool funuke = true;
        bool sunuke = true;

        for(long i=B;i<D;i++){
            if(S[i] == '#' && S[i+1] == '#'){
                funuke = false;
            }
        }
        for(long i=A;i<C;i++){
            if(S[i] == '#' && S[i+1] == '#'){
                sunuke = false;
            }
        }
        if(funuke && sunuke){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        bool funuke = true;
        bool sunuke = true;
        bool funukeavoid = false;

        for(long i=B;i<D;i++){
            if(S[i] == '#' && S[i+1] == '#'){
                funuke = false;
            }
        }
        for(long i=A;i<C;i++){
            if(S[i] == '#' && S[i+1] == '#'){
                sunuke = false;
            }
        }
        for(long i=B-1;i<D;i++){
            if((S[i] == '.' && S[i+1] == '.') && S[i+2] == '.'){
                funukeavoid = true;
            }
        }
        if((funuke && sunuke) && funukeavoid){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 640
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
P = []
for i in range(N):
    P.append(n())
P = sorted(P, reverse=True)

print(P[0] // 2 + sum(P[1:]))


Measured memory_bytes: 3060
k,a,b = gets.chomp.split(" ").map(&:to_i)
if a+2 < b
  cnt = 1
  if k > a
    k = k - a + 1
    cnt = a
    cnt += (k / 2) * (b - a)
    if k % 2 == 1
      cnt += 1
    end
  else
    cnt += k
  end
  puts cnt
else
  puts 1 + k
end

Measured memory_bytes: 14336
/*
ID: samarth10
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>

using namespace std;


void setIO(string name) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
}


int main() {
    //setIO();
    int t;
    cin >> t;
    cout << t * (1 + t + t*t);
}



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

int main() {
  int a,b,c;
  cin >> a >> b;
  c = a * b;
  if (c % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		int aa = a;
		int bb = b;
		if (a > b) {
			aa = b;
			bb = a;
		}
		if (aa < c && c < bb) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi

const int nax = 3005;

int D[nax][nax];
pair<int, int>par[nax][nax];


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i] == t[j]) {
				if (D[i][j] + 1 > D[i + 1][j + 1]) {
					par[i + 1][j + 1] = { i, j };
					D[i + 1][j + 1] = D[i][j] + 1;
				}
			}
			if (D[i][j] > D[i + 1][j]) {
				D[i + 1][j] = D[i][j];
				par[i + 1][j] = { i, j };
			}

			if (D[i][j] > D[i][j + 1]) {
				D[i][j + 1] = D[i][j];
				par[i][j + 1] = { i, j };
			}
		}
	}
	int mx = -1;
	pair<int, int>cur;
	
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (D[i][j] > mx) {
				mx = D[i][j];
				cur = { i, j };
			}
		}
	}
	string ans = "";
	while(mx) {
		auto nxt = par[cur.first][cur.second];
		if ((cur.first - nxt.first) + (cur.second - nxt.second) == 2) {
			assert(s[nxt.first] == t[nxt.second]);
			ans += s[nxt.first];
			mx--;
		}
		cur = nxt;
	}
	reverse(all(ans));
	cout << ans;
 	return 0;
}

Measured memory_bytes: 105984
#include <cmath>
#include <iostream>
#include <vector>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int div_count(int n) {
  vector<int> v;
  for (int i = 1; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      int d = n / i;
      v.push_back(i);
      if (i != d) {
        v.push_back(d);
      }
    }
  }
  return v.size();
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    int divs = div_count(i);
    if (divs == 8) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
double x[10],y[10];
double fun(int a,int b)
{
    return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}
int fun2(int d)
{
    int sum=0;
    for(int i=d-1; i>=1; i--)
        sum+=i;
    return sum;
}
int main()
{
    int n;
    cin>>n;
    double ans=0;
    for(int i=1; i<=n; i++)
        scanf("%lf %lf",&x[i],&y[i]);
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
            ans+=fun(i,j);
    printf("%.10f",ans*(n-1)/fun2(n));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt;


int main(){
	ll n;
	cin>>n;
	ll a[3*n];
	for(ll i=0; i<n*3; i++){
		cin>>a[i];
	}
	sort(a,a+3*n);
	reverse(a,a+3*n);
	ll cnt=0;
	for(ll i=0; i<3*n; i++){
		if(cnt==n) break;
		if(i%2!=0){
			sum+=a[i];
			cnt++;
		}
	}
	cout<<sum<<endl;
	
}




Measured memory_bytes: 2560
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 60;
const int tot = 2600;
const ll inf = 1e18;
int n, m;
ll s;
vector<pair<int, pair<int, int>>> G[maxn];
ll dp[maxn][tot];
ll c[120], d[120];
void dijk()
{
    for (int i = 0; i < maxn; i++)
        for (int j = 0; j < tot; j++)
            dp[i][j] = inf;
    priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<pair<ll, pair<int, int>>>> pq;
    pq.push({0, {1, s}});
    pair<ll, pair<int, int>> tp;
    while (!pq.empty())
    {
        tp = pq.top(), pq.pop();
        int nowpos = tp.second.first;
        ll nowcost = tp.first;
        ll nows = (ll)tp.second.second;
        for (auto &to : G[nowpos])
        {
            ll newcost = nowcost + to.second.second;
            ll nwe = min(nows - to.second.first, (ll)tot - 1);
            if (nwe >= 0)
            {
                if (dp[to.first][nwe] > newcost)
                {
                    dp[to.first][nwe] = newcost;
                    pq.push({newcost, {to.first, nwe}});
                }
            }
        }
        ll nwecost = nowcost + d[nowpos];
        ll nwe = min(nows + c[nowpos], (ll)tot - 1);
        if(dp[nowpos][nwe]>nwecost)
        {
            dp[nowpos][nwe] = nwecost;
            pq.push({nwecost, {nowpos, nwe}});
        }
    }
}

void solve()
{
    cin >> n >> m >> s;
    int u, v, a, b;
    for (int i = 1; i <= m; i++)
    {
        cin >> u >> v >> a >> b;
        G[u].push_back({v, {a, b}});
        G[v].push_back({u, {a, b}});
    }
    for (int i = 1; i <= n; i++)
        cin >> c[i] >> d[i];
    dijk();
    ll ans;
    for (int i = 2; i <= n;i++)
    {
        ans = inf;
        for (int j = 0; j < tot;j++)
            ans = min(dp[i][j], ans);
        cout << ans << "\n";
    }
}

int main()
{
    //freopen("in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T-- > 0)
        solve();
}

Measured memory_bytes: 6464
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
di = defaultdict(int)
right = True
for i in range(n):
    if n < a[i]:
        right = False
    if (n%2==0 and a[i]%2==1):
        di[a[i]] += 1
    elif (n%2==1 and a[i]%2==0):
        di[a[i]] += 1
    if 2 < di[a[i]]:
        right = False
    if a[i]==0 and di[a[i]]>1:
        right = False
    if n%2==0 and a[i]%2==0:
        right = False
    elif n%2==1 and a[i]%2 ==1:
        right = False

print((2**(n//2)%(10**9+7)) if right else 0)


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

int main(){
  string s;cin >> s;
  if(s == "A")cout << "T" << endl;
  else if(s == "T")cout << "A" << endl;
  else if(s == "G")cout << "C" << endl;
  else cout << "G" << endl;
  return 0;
}

Measured memory_bytes: 256
##################################################################

if __name__ == "__main__":
    Input = [input() for i in range(2)]
    N = int(Input[0])
    d = list(map(int,Input[1].split()))
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += d[i]*d[j]
    print(ans)


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

const int MAX = 50;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	bool ng = false;
	vector<vector<int>> table(N, vector<int>(MAX + 1));
	for (int i = 0; i < N; i++) {
		cin >> b[i];
		if (b[i] * 2 >= a[i] && b[i] != a[i]) {
			ng = true;
		}
		table[i][a[i]] = 1;
	}
	if (ng) {
		cout << -1 << endl;
		return 0;
	}
	ll res = 0;
	while (true) {
		bool ok = true;
		for (int i = 0; i < N; i++) {
			if (table[i][b[i]] == 0) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << res << endl;
			break;
		}
		ll ma = 0;
		for (int i = 0; i < N; i++) {
			if (table[i][b[i]] == 0) {
				ll ans = 0;
				for (int j = b[i] + 1; j <= MAX; j++) {
					auto dp = table[i];
					for (int k = j; k > b[i]; k--) {
						for (int l = k; l <= MAX; l++) {
							if (dp[l]) {
								dp[l % k] = 1;
							}
						}
					}
					if (dp[b[i]]) {
						ans = j;
						break;
					}
				}
				ma = max(ma, ans);
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = ma; j <= MAX; j++) {
				if (table[i][j] && j % ma >= b[i]) {
					table[i][j % ma] = 1;
				}
			}
		}
		res |= 1LL << ma;
	}
	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

max_num = a
min_num = a
if b < min_num:
    min_num = b
if b > max_num:
    max_num = b

if c < min_num:
    min_num = c
if c > max_num:
    max_num = c

if d < min_num:
    min_num = d
if d > max_num:
    max_num = d

if e < min_num:
    min_num = e
if e > max_num:
    max_num = e

if max_num - min_num <= k:
    print('Yay!')
else:
    print(':(')


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

visited=[0]*N#訪問フラグ
ima_pos=0#現在地
mirai_pos=0#移動先

count_first=0#一巡目のループ
first_DP=[]
while(visited[ima_pos]==0):
  visited[ima_pos]=1#訪れたら更新
  mirai_pos=A[ima_pos]-1
  ima_pos=mirai_pos
  first_DP.append(ima_pos)#何番目のインデックスに移動するか
  count_first+=1#何回移動したか

second_start=ima_pos#2巡目ループのスタート地点
count_second=0#2巡目以降のループ
second_DP=[]

while(True):#スタート地点に戻ってきたら抜ける
  visited[ima_pos]=2#訪れたら更新
  mirai_pos=A[ima_pos]-1
  ima_pos=mirai_pos
  second_DP.append(ima_pos)
  count_second+=1#何回移動したか
  if ima_pos==second_start:
    break

#各DPには何番目(0から)スタートの町に行くか　が書かれている
if K<=count_first:
  print(first_DP[K-1]+1)
elif K>count_first:
  cc=K-count_first#残り何回移動するか
  if cc%count_second==0:
    print(second_DP[-1]+1)
  else:
    print(second_DP[cc%count_second-1]+1)

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

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
	seen[v] = true; // v を訪問済みにする

	// v から行ける各頂点 next_v について
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue ;
		dfs(G, next_v);
	}
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	REP(i, m) cin >> a[i] >> b[i];
	REP(i, m) a[i]--, b[i]--;

	int cnt = 0;
	REP(i, m) {
		// グラフをセットする
		Graph G(n);
		REP(j, m)
			if (i != j) {
				G[a[j]].push_back(b[j]);
				G[b[j]].push_back(a[j]);
			}
		// 頂点 a[i] をスタートした探索を行う
		seen.assign(n, false); // 全頂点を『未訪問』に初期化
		dfs(G, a[i]);
		if (!seen[b[i]]) cnt++;
	}

	cout << cnt << '\n';
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int mina = A[0];
  vector<int> diff;
  for (int i = 1; i < N; i++) {
    if (mina > A[i]) {
      mina = A[i];
    } else {
      diff.emplace_back(A[i] - mina);
    }
  }
  sort(diff.begin(), diff.end(), greater<int>());
  int res = 1;
  for (int i = 0; i < diff.size() - 1; i++) {
    if (diff[i] == diff[i + 1]) {
      res++;
    } else {
      break;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
int main()
{
	int n;
	cin>>n;
	int a[10010];
	int c[1000010]={};
	for(int i=0; i<n; i++){
		cin>>a[i];
		int x=a[i];
		for(int j=2; j*j<=x; j++){
			if(x%j==0){
				int e=0;
				while(x%j==0){
					x/=j;
					e++;
				}
				c[j]=max(c[j], e);
			}
		}
		if(x>1) c[x]=max(c[x], 1);
	}
	ll l=1;
	for(int i=2; i<1000000; i++){
		if(c[i]>0){
			(l*=powmod(i, c[i]))%=MOD;
		}
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		ans+=inv(a[i]);
	}
	ans%=MOD;
	(ans*=l)%=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
#include<string.h>
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];
int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum=0,p=1,i;
  for (i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int h1(int key){return key%M; }
int h2(int key){return 1+(key%(M-1)); }

int find(char str[]){
  long long k,i,hash;
  k=getKey(str);
  for(i=0;;i++){
    hash=(h1(k)+i*h2(k))%M;
    if(strcmp(H[hash],str)==0)return 1;
    else if(strlen(H[hash])==0)return 0;
    }
  return 0;
}

int insert(char str[]){
  long long k,i,h;
  k=getKey(str);
  for(i=0;;i++){
    h =(h1(k)+i*h2(k))%M;
    if(strcmp(H[h],str)==0){return 1;}
    else if(strlen(H[h])==0){
    strcpy(H[h],str);
    return 0;
    }
  }
  return 0;
}

int main(){
    int i,n,h;
    char str[L],com[9];
    for(i=0;i<M;i++) H[i][0]='\0';
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0]=='i' ){
      insert(str);
    }
    else {
      if (find(str)){
      printf("yes\n");
      }
      else {
        printf("no\n");
      }
    }
  }
    return 0;
}

Measured memory_bytes: 14916
while True:
    try:
        a=input().split()
        b=input().split()
    except:
        break
    hit=0
    blow=0
    for i in range(4):
        x=a.count(b[i])
        blow+=x
        if a[i]==b[i]:
            hit+=1
            blow-=1
    print(hit,blow)


Measured memory_bytes: 5564
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

void solve()
{
    int N;
    cin >> N;
    int x;
    cin >> x;
    int a[N];
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }
    long long ans = 0;
    for (int i = 1; i < N; ++i)
    {
        if (a[i] + a[i - 1] > x)
        {
            if (a[i-1]<= x)
            {
                ans += a[i] - x + a[i-1];
                a[i] -= a[i]-x+a[i-1];
            }
            else
            {
                ans += a[i] + a[i - 1] - x;
                a[i - 1] = x;
                a[i] = 0;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 4016
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
ans = 0
if a == b:
    ans = 1
if v == w:
    ans = 0
elif v>w and abs(a-b)/(v-w) <= t :
    ans = 1
if ans == 0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 9192
#include <cstdio>
#include <iostream>
#define abs(x) (x>0?x:-x)
#define int long long
int a[1001],s[1001],b[1000000];
signed main( ) {
	int n,k,ans=0;
	std::cin >> n >> k;
	for (int i=1; i<=n; ++i) {
		std::cin >> a[i];
		s[i] = s[i-1] + a[i];
	}
	for (int i=1; i<=n; ++i) 
		for (int j=1; j<=i; ++j){
			b[++b[0]] = s[i] - s[j-1];
//			std::cout << b[b[0]] << std::endl;
		}
	for (int j=40; ~j; --j) {
		int cur=0;
		for (int i=1; i<=b[0]; ++i) {
			if ((b[i] & ans) == ans && (b[i] & (1ll<<j))) ++cur;
		}
		if (cur >= k) ans |= 1ll<<j;
	}
	std::cout << ans << std::endl;
	return -0;
}



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int W, a, b;
int N;
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    ll ans = 1;
    FOR(i,1,N+1) {
        ans*=i;
        ans%=INF;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
#define pi 3.141592653589793238
int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double minute=2*pi*(m/60.0);
    double hour=2*pi*(h/12.0+(m/60.0)/12.0);
    double result=sqrt((a*a+b*b)-(2*a*b)*cosl(max(minute,hour)-min(minute,hour)));
    cout.precision(20);
    cout << fixed << result << '\n';
    return 0;
}


Measured memory_bytes: 4168
# coding: utf-8
n, m = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]
s = 0
t = 0
flag = "No"
for a in As:
    t += a
for a in As:
    if not (4*m*a < t):
        s += 1
    if s >= m:
        flag = "Yes"
        break
print(flag)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>
#include <climits>
#include <queue>

using namespace std;

using Card = pair<char, int>;

void bubbleSort(std::vector<Card>& xs) {
  for (int i = 0; i < xs.size(); ++i) {
    for (int j = xs.size() - 1; j > i; --j) {
      if (xs[j].second < xs[j-1].second) {
        swap(xs[j], xs[j-1]);
      }
    }
  }
}

void selectionSort(std::vector<Card>& xs) {
  for (int i = 0; i < xs.size(); ++i) {
    int minj = i;
    for (int j = i; j < xs.size(); ++j) {
      if (xs[j].second < xs[minj].second) {
        minj = j;
      }
    }
    swap(xs[i], xs[minj]);
  }
}

bool isStable(const std::vector<Card>& xs, const std::vector<Card>& ys) {
  string xsuits[10], ysuits[10];
  for (auto& x : xs) {
    xsuits[x.second] += x.first;
  }
  for (auto& y : ys) {
    ysuits[y.second] += y.first;
  }
  for (int i = 0; i < 10; ++i) {
    if (xsuits[i] != ysuits[i]) {
      return false;
    }
  }
  return true;
}

void print(const vector<Card>& cards) {
  for (int i = 0; i < cards.size(); ++i) {
    if (i != 0) {
      cout << " ";
    }
    cout << cards[i].first << cards[i].second;
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vector<Card> xs(n);
  for (int i = 0; i < n; ++i) {
    string card;
    cin >> card;
    xs[i] = make_pair(card[0], card[1] - '0');
  }
  vector<Card> bubble = xs;
  bubbleSort(bubble);
  print(bubble);
  if (isStable(xs, bubble)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
  vector<Card> selection = xs;
  selectionSort(selection);
  print(selection);
  if (isStable(xs, selection)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}



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

/*
まず素直に, 最も多く爆弾が置かれている行と列の交点に爆弾を置けば, 最も多く爆破できる.
このとき, 設置点に既に爆弾が置かれていた場合, (行*列)ではその地点を重複して数えてしまうので,
(行*列-1)が爆破できる数になる. 逆に, 最も多く爆弾が置かれている行と列の交点で, かつそこに爆弾
が置かれていない場所に爆弾を置けば, (行*列)個の爆弾を爆破でき, これが最大値となる.
*/

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hs(h), ws(w);  // その行(列)に何個爆弾があるか
  set<P> s;
  rep(i, m) {
    int r, c;
    cin >> r >> c;
    --r; --c;
    hs[r]++; ws[c]++;
    s.emplace(r, c);  // 爆弾が置かれている地点の座標
  }
  
  int mh = 0, mw = 0;
  rep(i, h) mh = max(mh, hs[i]);  // 一行に置かれている爆弾数の最大値
  rep(j, w) mw = max(mw, ws[j]);  // 一列に置かれている爆弾数の最大値
  vector<int> mhs, mws;
  rep(i, h) if (hs[i] == mh) mhs.push_back(i);  // 最も多く爆弾が置かれている行
  rep(j, w) if (ws[j] == mw) mws.push_back(j);  // 最も多く爆弾が置かれている列
  
  int ans = mh + mw;  // 理論上の最大値. 最大行と最大列の交点で, そこに爆弾が置かれていない
  for (auto i : mhs) for (auto j : mws) {
    if (s.count(P(i, j))) continue;  // 交点に爆弾が置かれていたらcontinue
    cout << ans << endl;  // そうでなければ理論上の最大値が答え
    return 0;
  }
  
  // 最大行と最大列の交点で, そこに爆弾が置かれていないような地点がなかった場合
  cout << ans - 1 << endl;  
}

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

int main() {
  int64_t h;
  cin >> h;

  int64_t cnt = 0;
  int64_t divide_cnt = 0;
  while (h > 1) {
    cnt++;
    divide_cnt += pow(2, cnt - 1);
    h /= 2;
  }

  int64_t ans = divide_cnt + pow(2, cnt);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/



int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int Z = S.size();
	vector<char>AL(78);
	AL = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
	,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' 
	,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
	for (int i = 0; i < Z; i++) {
		for (int j = 0; j < 78; j++) {
			if (S[i] == AL[j]) {
				cout << AL[j + N];
				break;
			}
		}
	}
	cout << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int cnt = 15;
	for(auto c : s) {
		if(c == 'x') {
			--cnt;
		}
	}
	if(cnt < 8) {
		cout << "NO" << '\n';
	} else {
		cout << "YES" << '\n';
	}
	return 0;
}


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

using namespace std;

int main(void)
{
    int N, i;
    string S;

    cin >> N >> S;

    if(N % 2 == 1){
        cout << "No" << endl;
    }

    else{
        if(S.substr(0,N/2) == S.substr(N/2,N/2)){
            cout << "Yes" << endl;
        }

        else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#別に誰も10^100なんて数が必要とはいってないのだ
def resolve():
    S=input()
    #シミュレーション真面目にやると|s|^2回必要なのでTLEするよ（乱択でごまかす方法をおもいつきませんでした）
    #状態を圧縮するとシミュレーションできませんか？
    #Sのうち、連続する2文字が”RL”か、文末にだけ1以上がある
    #RLの効果が及ぶところごとに分割しよっかLRの真ん中で分割
    N=len(S)
    sub=[N]#kugiri
    sub2=[]#"RL"のLの位置
    for i in range(N-1):
        cont=()
        if S[i]=="L"and S[i+1]=="R":
            sub.append(i+1)
        if S[i]=="R"and S[i+1]=="L":
            sub2.append(i+1)
    sub.sort(reverse=True)
    #print(sub,sub2)

    ans=[0]*N
    temp=[0,0]
    ind=0
    for i in range(N):
        l=sub2[ind]
        temp[(l-i)%2]+=1
        if i+1 in sub:
            ans[l]+=temp[0]
            ans[l-1]+=temp[1]
            temp=[0,0]
            ind+=1
            sub.pop()
            
            
    
    print(*ans)
    
    
#%%submit!
resolve()


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

int N;
vector<vector<int> > adj;
vector<int> dp;

void dfs(int u, int p) {
    dp[u] = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        dfs(v, u);
        dp[u] ^= dp[v];
    }
    dp[u]++;
}

int main() {
    scanf("%d", &N);

    adj.resize(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dp.resize(N);
    dfs(0, -1);

    int Xor = 0;
    for(int i = 0; i < adj[0].size(); i++) {
        Xor ^= dp[ adj[0][i] ];
    }
    if(Xor) printf("Alice");
    else printf("Bob");
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define mod 100000000000000000
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    for(int i=0; i<a.size(); i++){
        if(a[i]!='0'){swap(a[i],a[0]); break;}
    }
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int main()
{
    Fastio();
    ll n; cin>>n;
    map<pair<ll,ll>,ll>mp,vis;
    for(int i=1; i<=n; i++){
        int x=i;
        while(x>=10)x/=10;
        mp[{x,i%10}]++;
    }
    ll res=0;
    for(int i=0; i<=9; i++){
        for(int y=0; y<=9; y++){
            res+=(mp[{i,y}]*mp[{y,i}]);
        }
    }
    cout<<res<<'\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[m];
        int[] d = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            int ans = 0;
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < m; j++) {
                int tmp1 = Math.abs(a[i] - c[j]);
                int tmp2 = Math.abs(b[i] - d[j]);
                if(min > tmp1 + tmp2) {
                    min = tmp1 + tmp2;
                    ans = j + 1;
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 35876
#include<stdio.h>
int main()
{
 int n,i,co=0,ans=0,ans1,value;
    while(scanf("%d",&n)==1)
    {
        for(i=1;i<=n;i++)
        {
            value=i;
            while(value%2==0)
            {
                co++;
                value=value/2;
            }
            if(co>=ans)ans=co,ans1=i;
            co=0;
        }
        printf("%d\n",ans1);
        ans=0,co=0;
    }
    return 0;
}


Measured memory_bytes: 128