akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

fn read_vec<T: FromStr>(s: String) -> Result<Vec<T>, T::Err> {
    s.split(' ').map(|x| x.parse()).collect()
}

fn main() {
    const M: i64 = 1000_000_000 + 7;
    let mut lines = BufReader::new(io::stdin()).lines().map(|l| l.unwrap());
    let nk: Vec<usize> = read_vec(lines.next().unwrap()).unwrap();
    let k = nk[1];
    let mut v: Vec<i64> = read_vec(lines.next().unwrap()).unwrap();
    let mut P: Vec<_> = v.iter().filter(|&&x| x > 0).collect();
    let mut N: Vec<_> = v.iter().filter(|&&x| x < 0).collect();
    P.sort_unstable();
    N.sort_unstable();
    // 正の数にできるか否か
    let can_positive = if P.len() >= k {
        true // Pが十分あればok
    } else if P.len() == 0 {
        k & 1 == 0 && k <= N.len() // Pがゼロ個なら、kが偶数で、Nはkより多い必要がある
    } else {
        // Pが1つ以上あって、kより少ない時
        (k - P.len() + 1) & !1 <= N.len() // Pが一つ以上あれば、k-Pを2の倍数に切り上げた数より、Nが多い必要がある
    };
    if !can_positive {
        if v.contains(&0) {
            // ゼロにできる時
            println!("0");
        } else {
            // 負の数になる時
            v.sort_unstable_by_key(|x| {
                let y = x >> 31;
                (x ^ y) - y
            });
            let ans = v
                .iter()
                .take(k) // 小さい方から集めて
                .fold(1, |acc, x| acc * (x % M) % M);
            println!("{}", (ans + M) % M);
        }
        return;
    }
    let mut ans = 1;
    let mut k = k;
    if k & 1 == 1 {
        ans *= P.pop().unwrap();
        k -= 1;
    }
    let mut P = P.rchunks_exact(2).map(|x| x[0] * x[1]).peekable();
    let mut N = N.chunks_exact(2).map(|x| x[0] * x[1]).peekable();
    loop {
        if k == 0 {
            break;
        }
        let pn = match P.peek() {
            // pnどっちからとるか
            Some(ab) => match N.peek() {
                Some(cd) => ab > cd,
                _ => true,
            },
            None => false,
        };
        ans *= if pn {
            P.next().unwrap()
        } else {
            N.next().unwrap()
        } % M;
        ans %= M;
        k -= 2;
    }
    println!("{}", (ans + M) % M);
}

Measured memory_bytes: 6112
x=int(input())
c=0
y,z,d=int(input()),int(input()),int(input())
for i in range(x+1):
    for j in range(y+1):
        for k in range(z+1):
            f=500*i+100*j+50*k
            if(f==d):
                c+=1
print(c)


Measured memory_bytes: 67380
# -.- coding:utf-8 -.-

tmp = input()
answer = [0] * len(tmp)
number = len(tmp)

for i in range(2):
  count = 0
  for j in range(number):
    if tmp[j] == "R":
      count += 1
    else:
      answer[j] += count//2
      answer[j-1] += -( -count // 2 )
      count = 0
  
  tmp = tmp[::-1]
  answer = answer[::-1]
  
  tmp_list = list(tmp)
  for k in range(len(tmp_list)):
    if tmp_list[k] == "L":
      tmp_list[k] = "R"
    else:
      tmp_list[k] = "L"
  tmp = "".join(tmp_list)
  
print(*answer)

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

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL);
typedef long long li;
const int N = 1e6 + 10;

int dp[N] , a[N];

int main(){

	/*#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
	#endif*/
  	
  double t , x;
  cin>>t>>x;
  printf("%0.5lf\n",t/x);
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
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 A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int ans[10000010];
signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  rep(i, 1, 101) {
    rep(j, 1, 101) {
      rep(k, 1, 101) {
        int wa = (i * i) + (j * j) + (k * k);
        wa += (i * j) + (j * k) + (i * k);
        ans[wa]++;
      }
    }
  }

  rep(i, 1, n + 1) cout << ans[i] << '\n';

  return 0;
}

Measured memory_bytes: 4032
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) if(s[i] >= 'A' && s[i] <= 'Z'){
        if(s[i] != 'C' && s[i] != 'A') {
            cout << "WA";
        return 0;
        }
    }
    if(s[0] == 'A'){
        int cnt = 0;
        if(s[1] != 'C' && s[s.size()-1] != 'C'){
        for(int i = 2; i < s.size()-1; i++) {
            if(s[i] == 'C') cnt++;
            if(s[i] >= 'A' && s[i] <= 'Z' && s[i] != 'A' && s[i] != 'C'){
                cout << "WA";
                return 0;
            }
        }
        if(cnt == 1) cout << "AC";
        else cout << "WA";
        }
        else cout << "WA";
    }
    else cout << "WA";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cctype>
#include<set>
#include<map>
#include<list>
#include<string>

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
int main()
{
  int n, m; cin >> n >> m;
	vector<vector<int>> tb(n, vector<int>(m));
 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> tb[i][j];
		}
	}
 
	set<int> s;
	for (int i = 0; i < 10000; i++) {
		s.insert(i*i);
	}
 
	int ans = 0;
 
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int val = 0;
			for (int k = 0; k < m; k++) {
				int diff = abs(tb[i][k] - tb[j][k]);
				val += diff * diff;
			}
			if (s.count(val))ans++;
 
		}
	}
	
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
    int W, H, x, y, r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3056
n = int(input())
k = int(input())
tmp = 1
i = 0
while True:
  a = 0
  b = 0
  if i == n:
    break
  else:
    a = tmp * 2
    b = tmp + k
    tmp = min(a,b)
    #print(tmp)
    i += 1
print(tmp)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define var auto
using ll = long long;
const char newl = '\n';
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if(a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if(a < b) a = b;}

using namespace std;

unsigned long long rng(uint64_t prev){
    return prev * 1145141919810 + 314259265358979;
}


signed main(){
    vector<uint64_t> hoge{};
    hoge.push_back(1986098285729847598ull);
    for (int i = 1; i < 26; i++){
        hoge.push_back(rng(hoge[i - 1]));
    }
    string s, t;
    cin >> s >> t;
    set<uint64_t> se{};
    for (int len = min(s.size(), t.size()); len >= 1; len--){
        se.clear();
        uint64_t cur = 0;
        for (int i = 0; i < len; i++) cur += hoge[s[i] - 'a'];
        se.insert(cur);
        for (int i = len; i < s.size(); i++){
            cur += hoge[s[i] - 'a'];
            cur -= hoge[s[i - len] - 'a'];
            se.insert(cur);
        }

        cur = 0;
        for (int i = 0; i < len; i++) cur += hoge[t[i] - 'a'];
        if (se.count(cur) != 0) goto valid;
        for (int i = len; i < t.size(); i++){
            cur += hoge[t[i] - 'a'];
            cur -= hoge[t[i - len] - 'a'];
            if (se.count(cur) != 0) goto valid;
        }

        continue;
        valid:;
        cout << len << endl;
        return 0;
    }
    cout << 0 << endl;
}



Measured memory_bytes: 3408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, c;
    cin >> n >> c;
    vvi d(c, vi(c));
    rep(i, c) rep(j, c) cin >> d[i][j];
    vvi color(n, vi(n));
    rep(i, n) rep(j, n) {
        cin >> color[i][j];
        color[i][j]--;
    }
    
    vvi now(3, vi(c, 0));
    rep(i, n) rep(j, n) {
        int k = ((i+1) + (j+1)) % 3;
        now[k][color[i][j]]++;
    }

    int ans = INF;

    for (int c0 = 0; c0 < c; ++c0) {
        for (int c1 = 0; c1 < c; ++c1) {
            if (c0 == c1) continue;
            for (int c2 = 0; c2 < c; ++c2) {
                if (c0 == c2 || c1 == c2) continue;
                int cost = 0;
                rep(i, c) cost += d[i][c0] * now[0][i];
                rep(i, c) cost += d[i][c1] * now[1][i];
                rep(i, c) cost += d[i][c2] * now[2][i];
                chmin(ans, cost);
            }
        }
    }

    cout << ans << endl; 
}

Measured memory_bytes: 1280
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit(0)

x.sort()
x_dis = []

for i in range(m-1):
    x_dis.append(x[i+1]-x[i])

x_dis.sort(reverse=True)
num = 0

for i in range(n-1):
    num += x_dis[i]

print(x[m-1]-x[0]-num)

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

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

    sort(A, A + N, 
        [&](int x, int y) { return x > y; }
    );
    int max = A[0];
    int mid1 = max/2;
    int mid2 = (max%2 != 0) ? max/2 + 1 : max/2;
    int midp = A[0], midn = A[N-1];

    for(int i = 0; i < N; ++i) {
        int tmp = A[i];
        if(tmp >= mid2 && (tmp - mid2) < (midp - mid2)) {
            midp = tmp; continue;
        }
        if(mid1 >= tmp && (mid1 - tmp) < (mid1 - midn)) {
            midn = tmp; continue;
        }
    }

    int min = (midp - mid2) < (mid1 - midn) ? midp : midn;
    cout << max << " " << min << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int l,a,b,c,d,n,m,x,y,ans;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	n=a/c;
	x=a%c;
	m=b/d;
	y=b%d;
	if(x>=1){
		n=n+1;
	}
	if(y>=1){
		m=m+1;
	}
	if(n<=m){
		ans=l-m;
	}
	else if(m<=n){
		ans=l-n;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2716
#include<stdio.h>
#define N 100000
#define Q 50000

int main(){
  
  int s[N],t[Q],c=0;
  int i,n,q,a,b,x;
  
  scanf("%d",&n);
  for( i=0 ; i<n ; i++){
   scanf("%d",&s[i]);
 }
 
 scanf("%d",&q);
  for( i=0 ; i<q ; i++){
      scanf("%d",&t[i]);
    }
    
    
    for( i=0 ; i<q ; i++ ){
      a=0;
      b=n+1;
      while( a < b ){
	x=( a + b-1 )/2;
	if(t[i] == s[x]){
	  c++;
	break;
	}
	else if(t[i] > s[x])
	  a = x + 1;
	else if(t[i] < s[x])
	  b = x;
      }
    }
    
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 1184
<?php

fscanf(STDIN, "%s", $count);
$source = fgets(STDIN);
$numbers = explode(" ", $source);
$sum = 0.00000000000000;

for ($i = 0; $i < $count; $i++)
{ 
	$sum += 1/$numbers[$i];
}

print(1/$sum);

Measured memory_bytes: 3700
def knapsack_1(N, W, lst):
    #N : 品物数
    #W : 重みの総和
    #lst (wi,vi) : 商品iの重みwi、価値vi
    
    #dp[i][j] : i番目の品物から重さの総和がj以下になるように選んだ場合の価値の総和の最大値
    dp = [[0 for i in range(W+1)] for _ in range(N+1)]
    
    for i in range(N):
        for j in range(W+1):
            if j < lst[i][0]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j],dp[i][j - lst[i][0]] + lst[i][1])
    return dp[N][W]


n,w = map(int,input().split())
lst = []
for i in range(n):
    w_, v_ =  map(int,input().split())
    lst.append((w_, v_))
print(knapsack_1(n,w,lst))

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

bool check(vector<vector<char>> s, int y, int x, int H, int W){
    vector<int> dx = {0, 1, 0, -1};
    vector<int> dy = {1, 0, -1, 0};
    for (int i = 0; i<4; i++){
        if (x+dx.at(i)>=0 && x+dx.at(i)<W && y+dy.at(i)>=0 && y+dy.at(i)<H){
            if (s.at(y + dy.at(i)).at(x + dx.at(i)) == '#'){
                return true;
            }
        }
    }
    return false;
}

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    
    for (int i = 0; i<H; i++){
        for (int j=0; j<W; j++){
            cin >> s.at(i).at(j);
        }
    }
    
    for (int i = 0; i<H; i++){
        for (int j=0; j<W; j++){
            if (s.at(i).at(j)=='#'){
                if (!check(s, i, j, H, W)){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    
    cout << "Yes" << endl;
   
}

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

vector<vector<int>> V;
vector<int> ans;
int inf=1<<30;

void dfs(int to, int cnt) {
  for (auto i: V[to]) {
    if(ans[i]!=inf) continue;
    else {
      ans[i]=cnt;
      dfs(i, cnt);
    }
  }
  return;
}

int main() {
  int N, M; cin >> N >> M;
  V = vector<vector<int>>(N, vector<int>(0));
  for (int i=0; i<M; i++) {
    int x, y, z; cin >> x >> y >> z;
    V[x-1].push_back(y-1);
    V[y-1].push_back(x-1);
  }
  ans = vector<int>(N, inf);
  int tmp=1;
  for (int i=0; i<N; i++) {
    if(ans[i]==inf&&V[i].size()>0) {dfs(i, tmp); tmp++;}
  }
  sort(ans.begin(), ans.end());
  int rem = ans.end() - lower_bound(ans.begin(), ans.end(), inf);
  cout << rem+tmp-1 << "\n";
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<int> > a(2, vector<int>(n));
    for(int i=0; i<2; i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<n-1; i++) a[0][i+1] += a[0][i];
    for(int i=n-1; i>0; i--) a[1][i-1] += a[1][i];

    int ans=0;
    for(int i=0; i<n; i++){
        ans = max(ans, a[0][i]+a[1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
alp = [chr(i) for i in range(97, 97 + 26)]

coe = []
while True:
    q, mod = divmod(N - 1, 26)
    coe.insert(0, mod)
    if q == 0:
        break
    N = q
ans = ""
for i in coe:
    ans += alp[i]
print(ans)


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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



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

    if(s.substr(s.length() - 1) == "s"){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
    
    
    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++) {
    cin >> d[i];
  }
  int sum = 0;
  for(int i = 0; i < N-1; i++) {
    for(int j = i+1; j < N; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
using namespace std;
int main() {
	int N = 0;
	scanf("%d", &N);
	vector<long>v (N+1,0);

	
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				if ((x * x + y * y + z * z + x * y + x * z + z * y) != 0 && ((x * x + y * y + z * z + x * y + x * z + z * y) < v.size())) {
					v[(x * x + y * y + z * z + x * y + x * z + z * y) - 1]++;
				}
				
			}
			
		}
		
	}
	/*
	for (int i = 1; i <= 130; i++) {
		for (int w = 1; w <= 130; w++) {
			for (int y = 1; y <= 130; y++) {
				if (((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w)) <= v.size()) {
					v[((i * i) + (w * w) + (y * y) + (i * w) + (i * y) + (y * w))]++;

				}

			}

		}
	}*/
	
	for (int i = 0; i < N; i++) {
		string str = to_string(v[i]);
		const char* l = str.c_str();
		printf(l);
		if (i != N - 1) {
		printf("\n");
	}
	}
	
	return 0;
}

Measured memory_bytes: 3760
def p(w,r,m,c=1):
    n=d.index(w[r])+d.index(w[r-c])+x.index(m)
    return d[n%2]

a=['SS','SW','WS','WW']
d=['S','W']
x=['o','x']

n=int(input())
s=input()
for j in range(4):
    for i in range(1,n):
        a[j]+=p(a[j],i,s[i])
    a[j]=p(a[j],0,s[0],-1)+a[j]

ans=-1
for w in a:
    if w[0]==w[-2] and w[1]==w[-1]:
        ans=w[1:-1]
print(ans)

Measured memory_bytes: 3856
def factoring(n)
  # 素因数分解O(√n)
  res = Hash.new(0)
  i = 2
  while i*i <= n
    while n % i == 0
      res[i] += 1
      n /= i
    end
    i += 1
  end
  res[n] = 1 if n != 1
  res
end

def comb(n, m)
  res = 1
  cnt = 0
  while cnt < m
    res *= n
    n -= 1
    cnt += 1
  end
  while m > 0
    res /= m
    m -= 1
  end
  res
end

N,M=gets.split.map(&:to_i)
ans = 1
MOD = 10**9+7
factoring(M).each do |k,v|
  ans *= comb(N+v-1, v)
  ans %= MOD
end
p ans

Measured memory_bytes: 3836
s = list(input())
count = 0
a = []
for i in range(len(s)):
    if s[i] =="A" or s[i] =="T" or s[i] =="G" or s[i] =="C":
        count += 1
    else:
        a.append(count)
        count = 0
a.append(count)
print(max(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = 405;
char c[maxN][maxN];
int h, w;
bool used[maxN][maxN];
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
int white = 0;
int black = 0;
void dfs(int i, int j) {
    if (c[i][j] == '#') white++;
    else black++;
    used[i][j] = true;
    for (int k = 0; k < 4; k++) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (c[i][j] == c[ni][nj]) continue;
        if (used[ni][nj]) continue;
        dfs(ni, nj);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    ll ans = 0;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (used[i][j]) continue;
            white = 0;
            black = 0;
            dfs(i, j);
            ans += 1LL * white * black;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 8064
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int i, n, j, s;
	int score[128];
	
	while (scanf("%d", &n), n != 0){
		for (i = 0; i < 128; i++){
			score[i] = 0;
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < 5; j++){
				scanf("%d", &s);
				score[i] += s;
			}
		}
		
		sort(score, score + n);
		
		printf("%d %d\n", score[n - 1], score[0]);
	}
	
	return (0);
}

Measured memory_bytes: 1044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, s;
int ans = 0;

void dfs(int i, int sum, int num){
	if (i == n&&sum == s){
		ans++;
		return;
	}

	for (int j = num; j <= 9; j++){
		dfs(i + 1, sum + j, j + 1);
	}
	return;
}

int main(){
	while (cin >> n >> s){
		if (n + s == 0)break;
		ans = 0;
		dfs(0, 0, 0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3056
N = int(raw_input())
lista = map(int,raw_input().split(' '))
listb = map(int,raw_input().split(' '))

ans=0
for i in range(N):
    sum = 0
    for a in range(i+1):
        sum += lista[a]
    for b in range(N - i):
        sum += listb[b+i]
    if ans < sum:
        ans = sum
        
        
    

print ans

Measured memory_bytes: 2568
# https://atcoder.jp/contests/abc081/tasks/abc081_b

def div_list(list_num):
    _div_list = []
    can_iter = True
    for k in range(len(list_num)):
        if list_num[k] % 2 != 0:
                can_iter = False
        _div_list.append(list_num[k] / 2)
    return can_iter, _div_list


n_input = int(input())
list_number = input().split()
list_number = list(map(int, list_number))

n_iter = 0
can_iter = True

while can_iter == True:
    can_iter, list_number = div_list(list_number)
    if can_iter == True:
        n_iter += 1

print(n_iter)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  int n_max = a[n - 1];
  int idx = lower_bound(a.begin(), a.end(), n_max / 2) - a.begin();
  int n_min = a[idx] < (n_max - a[idx - 1])? a[idx] : a[idx - 1];
  cout << n_max << " " << n_min << endl;
}


Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
using namespace std;

const long long inf = 1e15;
const int mod = 1e9+7;

int main(void){
    long long n,m,k;
    cin >> n >> m >> k;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=m; j++){
            int ans = m*i+n*j-2*i*j;
            if(ans == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;

string s;
vpi lis;
int ans;

struct BIT
{
	int bit[303030];
	int n=300000;

	void add(int k,int x)
	{
		while(k<=n)
		{
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k)
	{
		int ret=0;
		while(k>0)
		{
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
};

BIT b1,b2;

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

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

cin >> s;
int cnt=0,mid;
for(char c='a';c<='z';c++){
       vi v;
       for(int i=0;i<s.size();i++){
              if(s[i]==c){
                     v.pb(i+1);
              }
       }
       if(v.size()%2&&cnt){
              cout << -1 << endl;
              return 0;
       }
       for(int i=0;i<v.size()/2;i++){
              lis.pb({v[i],v[v.size()-i-1]});
       }
       if(v.size()%2){
              cnt++;
              mid = v[v.size()/2];
       }
       v.clear();

}

sort(all(lis));

for(auto t:lis){
       if(cnt)if(mid<t.fs||mid>t.sc)ans++;
       b1.add(t.fs,1);
       b2.add(t.sc,1);
}
//dmp(ans);
for(int i=0;i<lis.size();i++){
       b1.add(lis[i].fs,-1);
       b2.add(lis[i].sc,-1);
       int inside = b2.sum(lis[i].sc);
       int nonoverlap = lis.size()-i-1-b1.sum(lis[i].sc);
       int overlap = lis.size()-i-1-inside-nonoverlap;
       ans+=overlap+nonoverlap*2;
       //cout << inside << " " << nonoverlap << " " << overlap << endl;
}
cout << ans << endl;

return 0;}
///....


Measured memory_bytes: 7176
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        string S = Console.ReadLine();
        int k = S.Length;
        int rest = 15 - k;
        int win = 0;
        for(int i = 0; i < k; i++)
        {
            if(S[i] == 'o')
            {
                win++;
            }
        }
        if(win + rest >= 8)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var prog = new Prog();
        prog.run();
    }
}

//Array.ConvertAll(int.Parse)

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<double, string> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        vector<P> ans(n);
        for(int i=0; i<n; i++){
            string l;
            double p, a, b, c, d, e, f, s, m;
            cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
            double num = ((f * s * m) - p) / (a + b + c + (d + e) * m);
            ans[i] = P(num, l);
        }

        sort(ans.begin(), ans.end(), greater<P>());

        for(int i=0; i<n; i++){
            vector<string> v;
            v.eb(ans[i].sc);

            while(i + 1 < n && ans[i].fs == ans[i+1].fs){
                i++;
                v.eb(ans[i].sc);
            }

            sort(v.begin(), v.end());
            for(auto j:v){
                cout << j << endl;
            }
        }
        cout << "#" << endl;
    }
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 55
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int ans=1e9,vis[N],head[N],g[2][N][N],fa[2][N],n,tot,d[N],can[N],TAG;
struct Edge{int v,next;}edge[N*N];
inline void add(int x,int y){edge[++tot]=Edge{y,head[x]};head[x]=tot;}
void dfs1(int id,int x,int la=0)
{	fa[id][x]=la; if(id) can[x]=can[la]&(fa[0][x]==fa[1][x]);
	for(rint i=1;i<=n;i++) if(g[id][x][i]&&i!=la) dfs1(id,i,x);
}
int dfs2(int x)
{	vis[x]=1;
	for(rint i=head[x];i;i=edge[i].next)
	if(vis[to]==1||!dfs2(to)) return 0;
	vis[x]=2; return 1;
}
void solve(int x)
{	can[0]=1; dfs1(0,x); dfs1(1,x); int tag=1,s=0;
	memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); tot=0;
	for(rint i=1;i<=n;i++)
	if(!can[i])
	{	if(!can[fa[0][i]]) add(fa[0][i],i);
		if(!can[fa[1][i]]) add(i,fa[1][i]); s++;
	}
	for(rint i=1;i<=n;i++) if(!vis[i]) tag&=dfs2(i);
	if(tag) ans=min(ans,s+1);
}
int main()
{//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int t; cin>>t;
	while(t--)
	{	int x,y,tag=1; scanf("%d",&n);
		memset(g,0,sizeof(g)); memset(d,0,sizeof(d)); ans=1e9;
		for(rint i=1;i<n;i++)
		scanf("%d%d",&x,&y),g[0][x][y]=g[0][y][x]=1,d[x]++,d[y]++;
		for(rint i=1;i<n;i++) scanf("%d%d",&x,&y),g[1][x][y]=g[1][y][x]=1;
		dfs1(0,1); dfs1(1,1);
		for(rint i=1;i<=n;i++) tag&=(fa[0][i]==fa[1][i]);
		if(tag){printf("0\n");continue;}
		for(rint i=1;i<=n;i++)
		if(d[i]==1)
		{	int la=0; for(rint j=1;j<=n;j++) if(g[0][i][j]) la=j;
			g[0][i][la]=g[0][la][i]=0;
			for(rint j=1;j<=n;j++)
			if(i!=j&&j!=la)
			{
		//		debug(i);debug(j);
		//	if(i==4&&j==2) TAG=1;
			g[0][i][j]=g[0][j][i]=1,solve(i),g[0][i][j]=g[0][j][i]=0;
		//	if(i==1&&j==3) debug(ans),exit(0);
			}
			g[0][i][la]=g[0][la][i]=1;
		}
		printf("%d\n",ans==1e9?-1:ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;
int32_t main()
{
     int n,m;
     cin>>n>>m;
     if(m!=n)cout<<"No"<<endl;
     else cout<<"Yes"<<endl;
     return 0;     
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

H,W,K = LI()

if W == 1:
    print(1)
    exit(0)

dp = [[0] * W for _ in range(H+1)]
dp[0][0] = 1

good = []
for ami in range(2**(W-1)-1):
    b = 1
    m = -2
    for i in range(W-1):
        if b & ami:
            if i <= m + 1:
                break
            m = i
        b <<= 1
    else:
        s = []
        b = 1
        for i in range(W):
            s.append(ami & b > 0)
            b <<= 1
        good.append([0] + s + [0])

for i in range(H):
    for ami in good:
        for j in range(W):
            if ami[j] == 0 and ami[j+1] == 0:
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            elif ami[j] == 1:
                dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
            else:
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD

print(dp[-1][K-1])

Measured memory_bytes: 41452
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,p[20001];
	scan(N);
	int a[20001],b[20001];
	rep(i,N){
		a[i]=30000*i+1;
		b[i]=30000*(N-i-1)+1;
	}
	rep(i,N){
		scan(p[i]);
		p[i]--;
		a[p[i]]+=i;
	}
	rep(i,N){
		printf("%d ",a[i]);
	}
	kaigyo;
	rep(i,N){
		printf("%d ",b[i]);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 896
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

struct UnionFind {
    n: usize,
    par: Vec<usize>,
    rank: Vec<usize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            n,
            par: (0..n).collect(),
            rank: vec![1; n],
        }
    }
    fn unite(&mut self, x: usize, y: usize) {
        if self.same(x, y) {
            return;
        }
        let rx = self.par[x];
        let ry = self.par[y];
        if self.rank[rx] > self.rank[ry] {
            self.par[ry] = rx;
            self.rank[rx] += self.rank[ry];
        } else {
            self.par[rx] = ry;
            self.rank[ry] += self.rank[rx];
        }
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            self.par[x] = self.root(self.par[x]);
            self.par[x]
        }
    }
    #[allow(dead_code)]
    fn size(&mut self, x: usize) -> usize {
        let r = self.root(x);
        self.rank[r]
    }
    #[allow(dead_code)]
    fn sizes(&mut self) -> Vec<usize> {
        let mut s = vec![];
        for x in 0..self.n {
            if x == self.root(x) {
                s.push(self.rank[x]);
            }
        }
        s
    }
    #[allow(dead_code)]
    fn groups(&mut self) -> Vec<Vec<usize>> {
        let mut g = vec![vec![]; self.n];
        for i in 0..self.n {
            g[self.root(i)].push(i);
        }
        g.iter()
            .filter(|v| !v.is_empty())
            .map(|v| v.clone())
            .collect()
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m]
    }
    let mut uf = UnionFind::new(n);
    for (a, b) in ab {
        uf.unite(a, b);
    }
    println!("{}", uf.sizes().len() - 1);
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3);
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3);
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
bool comp(pi a,pi b)
{
    if(a.se==b.se)
        return a.se<b.se;
    return a.se<b.se;
}
int main()
{
    int i,n,a,b;
    sf(n);
    vector<pi>vec;
    rep0(i,n)
    {
        sff(a,b);
        vec.pb({a,b});
    }
    sort(all(vec),comp);
    ll now=0;
    rep0(i,n)
    {
        if(now+vec[i].fi<=vec[i].se)
            now+=vec[i].fi;
        else
        {
            pf("No");
            return 0;
        }
    }
    pf("Yes");
}


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

int main(){
  int b1l,b1,b2;
  int b1a;
  cin >> b1l >> b1 >> b2;
  b1a = b1l-b1;
  int ans = b2-b1a;
  if ( ans<= 0) ans = 0;
  cout << ans << endl;
  
  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);
        loop: while(true){
            int w = sc.nextInt(),h = sc.nextInt();
            if(w == 0 && h == 0) break loop;
            for(int i = 0;i < w;i++){
                for(int j = 0;j < h;j++) System.out.print("#");
                System.out.println();
            }
            System.out.println();
        }
    }

}

Measured memory_bytes: 34780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int numN;
		char ch;

		Scanner sc = null;

		try {
			sc = new Scanner(System.in);

			while (sc.hasNext()) {

				String line = sc.next();
				//?????????????¢????
				if (!line.equals("-")) {
					char[] card = line.toCharArray();

					int numH = sc.nextInt();


					//?????£????????????????????°
					for (int i = 0; i < numH; i++) {

						//?????£?????????????????°
						numN = sc.nextInt();
						for (int j = 0; j < numN; j++) {
							ch = card[0];
							for (int k = 0; k < card.length - 1; k++) {

								card[k] = card[k + 1];
							}
							card[card.length - 1] = ch;
						}
					}

					System.out.println(card);
				}
			}
		}catch (NumberFormatException e) {
			System.out.println(e);
		} finally {
			sc.close();
		}
	}

}

Measured memory_bytes: 26536
# -*- coding: utf-8 -*-
import sys
import math

def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())


n = get_num()
costs = get_nums(5)

max_time = 0
for cost in costs:
    max_time = max(max_time, int(math.ceil(n / cost)))

print(max_time + 4)

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define buff ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define xy pair<int, int>
#define x first
#define y second 

#define inf std::numeric_limits<int>().max()

int main() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<int> r(h+1), c(w+1);
	set<pair<int,int>> s;
	for(int i=1; i<=m; i++) {
		int a, b;
		cin >> a >> b;
		r[a]++;
		c[b]++;
		s.insert({a, b});
	}
	vector<int> cx, cy;
	int maxX = 0;
	int maxY = 0;
	for(int i=1; i<=h; i++) maxX = max(maxX, r[i]);
	for(int i=1; i<=w; i++) maxY = max(maxY, c[i]);

	for(int i=1; i<=h; i++) 
		if (r[i] == maxX) cx.push_back(i);
	for(int i=1; i<=w; i++) 
		if (c[i] == maxY) cy.push_back(i);

	ll ans = maxX + maxY - 1;
	bool vf = false;
	for(int i=0; i<cx.size() and !vf; i++) {
		for(int j=0; j<cy.size() and !vf; j++) {
			if (r[cx[i]] == maxX and c[cy[j]] == maxY and !s.count({cx[i],cy[j]})) {
				ans++;
				vf = true;
			}
		}
	}

	cout << ans << endl;

}



Measured memory_bytes: 23360
from functools import lru_cache

@lru_cache(maxsize=10**6)
def N(x,y,n): # no of x...y < n
    r=0
    for i in range(1,n+1):
        if str(i)[0]==str(x) and str(i)[-1]==str(y):
            r+=1
    return r

ans=0
n=int(input())
for x in range(1,10):
    ans+=N(x,x,n)*N(x,x,n)
    for y in range(x+1,10):
        ans+=N(x,y,n)*N(y,x,n)*2
        
print(ans)


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

int main(){
  string S;
  cin>>S;
  while(true){
    if(S.size()<=3){
      if(S=="mew"){
        cout<<"Cat"<<endl;
        return 0;
      }else{
        cout<<"Rabbit"<<endl;
        return 0;
      }
    }else{
      bool flag = false;
      for(int i=1;i<S.size()-3;i++){
        if(S[i]=='m'&&S[i+1]=='e'&&S[i+2]=='w'){
          string sub1=S.substr(0,i),sub2=S.substr(i+3);
          S= sub1+sub2;
          flag=true;
          break;
        }
      }
      if(flag==false){
        cout<<"Rabbit"<<endl;
        return 0;
      }
    }
  }
}



Measured memory_bytes: 3224
A=sorted(list(map(int,input().split())))

if A[2]==A[0] and A[0]%2==0:
    print(-1)
else:
    ans=0
    a=A[0]
    b=A[1]
    c=A[2]
    while a%2==0 and b%2==0 and c%2==0:
        ans+=1
        a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
    print(ans)












Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int A[200005], B[200005];

signed main() {
	int N, K;
	cin >> N >> K;


	REP(i, N) {
		cin >> A[i] >> B[i];

		if (A[i] > K) B[i] = 0;
	}


	int cnt = 0;
	for (int i = 0;i < 31;i++) {
		if ((K >> i) == 0) {
			cnt = i - 1;
			break;
		}
	}

	int ans = 0;
	int sum;

	REP(j, N) {
		if ((A[j] | K) == K) ans += B[j];
	}

	for (int i = (1 << cnt); i > 0;i = (i >> 1)) {
		if ((K & i) == 0) continue;
		//cout << ans << endl;
		sum = 0;
		REP(j, N) {
			int mask = ((i - 1) | (K & ~i));
			if ((A[j] | mask) == mask) {
				sum += B[j];
			}
		}
		
		ans = max(ans, sum);
	}


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
k,s=gets.split.map &:to_i
h={}
(k+1).times do |i|
  h[i]=1
end
hh=Array.new(k**2+1,0)
(k+1).times do |i|
  h.each do |e|
    hh[e[0]+i]+=e[1]
  end
end
if 3*k>=s
  g=s-k
  g=0 if g<0
  p hh[g..[k*2,s].min].inject(0){|s,i|s+i}
else
  p 0
end

Measured memory_bytes: 50812
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	int N, M; cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	int total = accumulate(A.begin(), A.end(), 0);
	double border = total / (4.0 * M);
	int cnt = 0;
	for (int i = 0; i < N; ++i)
		if (A[i] >= border)
			++cnt;
	cout << (cnt >= M ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


bool f(string s){
  vector<char> q;

  rep(i,s.size()){
    if(s[i]=='('||s[i]=='[') q.push_back(s[i]);
    if(s[i]==')'){
      if(q.size()==0) return false;
      if(q[q.size()-1]=='[') return false;
      q.pop_back();
    }
    if(s[i]==']'){
      if(q.size()==0) return false;
      if(q[q.size()-1]=='(') return false;
      q.pop_back();
    }
  }

  if(q.size()) return false;

  return true;
}



int main(){

  while(1){
    string s;
    char c;
    c = getchar();
    while(c!='\n'){
      s+=c;
      c = getchar();
    }
    if(s.size()==1&&s[0]=='.') break;
    if(f(s))
      cout<<"yes"<<endl;
    else
      cout<<"no"<<endl;
  }


  return 0;
}




Measured memory_bytes: 3168
n = int(input())

def f(y, m, d):
    ret = 0
    for i in range(1, y):
        if i % 3 == 0:
            ret += 20 * 10
        else:
            ret += 20 * 5 + 19 * 5
    for j in range(m - 1):
        if j % 2 == 0:
            ret += 20
        else:
            if y % 3 == 0:
                ret += 20
            else:
                ret += 19
    ret += d
    return ret

al = f(1000, 1, 1)
for i in range(n):
    y,m,d = map(int,input().split())
    print(al - f(y, m, d))


Measured memory_bytes: 5600
from math import *

n = int(input())

a = [int(x) for x in input().split()]

a_sort = sorted(a)

median_right = a_sort[floor(len(a_sort) / 2)]
median_left = a_sort[floor(len(a_sort) / 2) - 1]

for i in range(len(a)):
	if a[i] > median_left:
		print(median_left)
	else:
		print(median_right)


Measured memory_bytes: 26212