akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<numeric>

using namespace std;

int main() {
    int S,h,u;
    cin>>S;
    h=S%100;
    u=(S-S%100)/100;
    if((0<h&&h<13)&&(0<u&&u<13))cout<<"AMBIGUOUS"<<endl;
    if((h>12||h==0)&&(u>12||u==0))cout<<"NA"<<endl;
    if((h>12||h==0)&&(0<u&&u<13))cout<<"MMYY"<<endl;
    if((0<h&&h<13)&&(u>12||u==0))cout<<"YYMM"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#define INF 1000000000
using namespace std;

class Balloon{
public:
  int p, t;
};

main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    Balloon ball[40];
    for(int i=0;i<n;i++){
      cin >> ball[i].p >> ball[i].t;
    }
  
    int dp[3][41];
    for(int i=0;i<3;i++){
      for(int j=0;j<41;j++){
	dp[i][j]=INF;
      }
    }
    if(ball[0].p<=ball[0].t){
      dp[0][0]=ball[0].p;
      for(int j=0;j<n;j++){
	for(int i=0;i<3;i++){
	  if(dp[i][j]==INF) continue;
	  if(j==n-1){
	    dp[0][j+1]=min(dp[0][j+1], ball[j].p+dp[i][j]);
	  }else if(ball[j+1].t-ball[j].t>=ball[j].p*(i+2)+ball[j+1].p){
	    dp[0][j+1]=min(dp[0][j+1], ball[j].p+dp[i][j]+ball[j+1].p);
	  }
	  if(i!=2){
	    if(ball[j+1].t-ball[j].t>=abs(ball[j].p-ball[j+1].p)*(i+2)){
	      dp[i+1][j+1]=min(dp[i+1][j+1], abs(ball[j].p-ball[j+1].p)+dp[i][j]);
	    }
	  }
	}
      }
      if(dp[0][n]!=INF){ 
	cout << "OK " << dp[0][n] << endl;
      }else{
	for(int j=0;j<n;j++){
	  if(dp[0][j]==INF && dp[1][j]==INF && dp[2][j]==INF){
	    cout << "NG " << j+1 << endl;
	    break;
	  }
	}
      }
    }else{
      cout << "NG " << 1 << endl;
    }
    /*for(int i=0;i<3;i++){
      for(int j=0;j<n;j++){
	cout << dp[i][j] << ' ';
      }
      cout << endl;
      }*/
  }
  return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  vi h(n);
  REP(i, n) {
    cin >> h[i];
  }

  vvi g(n);
  REP(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int cnt = 0;
  REP(i, n) {
    int ma = 0;
    REP(j, SZ(g[i])) {
      chmax(ma, h[g[i][j]]);
    }
    cnt += ma < h[i];
  }
  cout << cnt << endl;


}
























Measured memory_bytes: 8736
import java.util.Scanner;

public class Main {

    private static String solve(String s, int k) {
        if (s.length() == k || s.length() < k)
            return s;

        return s.substring(0, k) + "...";
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        String s = sc.next();
        String res = solve(s, k);
        System.out.println(res);
    }
}


Measured memory_bytes: 26984
#include<iostream>
using namespace std;
int main(){
	int n,k,p=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]>=k)
		p++;
	}
	cout<<p<<endl;
}

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

int main()
{
    int a,b = 0,x = 0;
    string s;

    cin >> s;

    a = s.length();

    if( a > 1 ){
        for(int i = 0; i < a; i++){
            if( i == 0){

            }
            else{
                if( s[i] == b ){
                    x++;
                    if(b == '0'){
                        s[i] = '1';
                    }else{
                        s[i] = '0';
                    }
                }
            }
            b = s[i];
        }
    }
    cout << x;
}

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

const ll Mod = 1000000007;
bool exists(vector<ll>& vec,ll x)
{
    auto pos = lower_bound(vec.begin(),vec.end(),x);
    if(pos == vec.end())return false;
    return *pos == x;
}
void solve(ll N, ll M, vector<ll> A, vector<ll> B)
{
    ll ans = 1;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    ll empty = 0;
    ll numrow=0,numcol=0;
    for(ll x = M*N;x>=1;--x)
    {
        if(exists(A,x))
        {
            if(exists(B,x))
            {
                empty += numcol + numrow;
                numcol++;
                numrow++;
            }else
            {
                empty += numcol - 1;
                ans *= numcol;
                ans %= Mod;
                numrow++;
            }
        }else
        {
            if(exists(B,x))
            {
                empty += numrow - 1;
                ans *= numrow;
                ans %= Mod;
                numcol++;
            }else
            {
                if(empty <= 0)
                {
                    cout<<0<<endl;
                    return;
                }
                ans *= empty;
                empty--;
                ans %= Mod;
            }
        }
    }
    cout<<ans<<endl;
}


int main()
{
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin >> A[i];
    }
    vector<ll> B(M);
    for(int i = 0 ; i < M ; i++)
    {
        cin >> B[i];
    }
    solve(N, M, move(A), move(B));
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll a[100010];

void solve(){

    ll n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> v;
    bool is = true;
    rep(i,n){
        if(a[i]==0){
            v.emplace_back(0);
            if(v.size()>=4){
                is = false;
                break;
            }
        }
        else{
            if(v.size()==0){
                is=false;
                break;
            }
            if(v[0]==a[i]-1){
                v[0]++;
                continue;
            }
            else if(v.size()==1){
                is=false;
                break;
            }
            else if(v[1]==a[i]-1){
                v[1]++;
                continue;
            }
            else if(v.size()==2){
                is=false;
                break;
            }
            else if(v[2]==a[i]-1){
                v[2]++;
                continue;
            }
            else{
                is=false;
                break;
            }
        }
    }

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

    ll numof0 = 0;
    vector<ll> v2;
    ll ans = 1;

    rep(i,n){
        if(i==0) {
            v2.emplace_back(a[0]);
            numof0++;
            continue;
        }
        if(a[i]==0){
            v2.emplace_back(a[i]);
            numof0++;
            continue;
        }
        int count = 0;
        rep(j,v2.size()){
            if(v2[j]==a[i]-1) count++;
        }
        ans = (ans * count) % MOD;
        rep(j,v2.size()){
            if(v2[j]==a[i]-1){
                v2[j]++;
                break;
            }
        }
    }

    if(numof0>=2){
        ans = (ans * 3*2) % MOD;
    }
    else{
        ans = (ans * 3) % MOD;
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <math.h>
#include <complex>
using ll = long long;
using namespace std;
int const MOD = 1e9 + 7;
ll const INF = (1LL << 62) - 1;
#define rep(i, n) for (int i = 0; i < (n); i++)

using P = pair<ll, ll>;
bool operator<(const P &a, const P &b)
{
    if (a.first == b.first)
        return a.second < b.second;
    return a.first < b.first;
}

ll arr[200010];
int main(void)
{
    ll N, M;
    cin >> N >> M;
    map<ll, ll> mp;
    mp[0]++;
    ll t = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> arr[i];
        t += arr[i];
        t %= M;
        mp[t]++;
    }
    ll ans = 0;
    for (auto e : mp)
        ans += e.second * (e.second - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numT := scanner.Text()
	num, _ := strconv.ParseInt(numT, 10, 64)

	zoroCounter := 0

	for i := 0; i < int(num); i++ {
		scanner.Scan()
		numsLine := scanner.Text()
		nums := strings.Split(numsLine, " ")

		if nums[0] == nums[1] {
			zoroCounter++
			continue
		}
		if zoroCounter < 3 {
			zoroCounter = 0
		}
	}

	if zoroCounter >= 3 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


Measured memory_bytes: 1776
from collections import Counter
from heapq import heapify, heappop, heappush
from itertools import accumulate


def solve(n, k, ppp, ccc):
    NINF = -(10 ** 18)
    ans = NINF

    checked = [False] * n
    for s in range(n):
        if checked[s] == True:
            continue
        checked[s] = True
        scores = [ccc[ppp[s]]]
        v = ppp[s]
        while v != s:
            scores.append(ccc[ppp[v]])
            checked[v] = True
            v = ppp[v]

        l = len(scores)
        d, m = divmod(k, l)
        loop = sum(scores)

        if d > 0:
            d -= 1
            m += l

        scores += scores * 2
        scores.insert(0, 0)
        acc = list(accumulate(scores))

        base = max(0, loop * d)

        range_max = [-a for a in acc[1:m + 1]]
        available_max = Counter(range_max)
        heapify(range_max)
        for i in range(l):
            while available_max[range_max[0]] == 0:
                heappop(range_max)
            ans = max(ans, base - range_max[0] - acc[i])
            old = -acc[i + 1]
            new = -acc[i + m + 1]
            available_max[old] -= 1
            available_max[new] += 1
            heappush(range_max, new)

    return ans


n, k = map(int, input().split())
ppp = list(map(int, input().split()))
ppp = [p - 1 for p in ppp]
ccc = list(map(int, input().split()))

print(solve(n, k, ppp, ccc))


Measured memory_bytes: 12064
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){
    int n; cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];

    int fb = 0, la = 0, ab = 0;
    int ba = 0;

    rep(i,n){
        bool flb = false,fla = false;
        
        if(s[i][0] == 'B' and s[i][s[i].size()-1] == 'A') ba++;
        else if(s[i][0] == 'B') fb++;
        else if(s[i][s[i].size()-1] == 'A') la++;

        
        rep(j,s[i].size()-1){
            //cout << s[i].substr(j,2) << endl;
            if(s[i].substr(j,2) == "AB") ab++;
        }
    }

    int ans = 0;
    if(ba == 0) ans = min(la,fb);
    else if(la + fb == 0) ans = ba-1;
    else ans = ba + min(la,fb);

    cout << ab + ans << endl;
}

Measured memory_bytes: 768
a, b, c, x, y = gets.strip.split(" ").map(&:to_i)

if a + b > c * 2
  m = [x, y].min
  ans = c * 2 * m

  x -= m
  y -= m

  t = x == 0 ? y : x
  p = x == 0 ? b : a
  if p > c * 2
    ans += c * 2 * t
  else
    ans += p * t
  end

  puts ans
else
  puts a * x + b * y
end


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

int main (){
	int n,i;
	pair<long long,long long> task[200005];
	cin >> n;
	long long a[200005],b[200005],suma=0,sumb=0;
	for(i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		task[i]=make_pair(-b[i],-a[i]);
	}
	sort(task,task+n);
	int flag=0;
	for(i=n-1;i>=0;i--){
		suma-=task[i].second;
		if(suma>-task[i].first){
			flag=1;
			break;
		}
	}
	if(flag==0) cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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 (a > b) { a = b; return 1; } return 0; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

signed main(){
	int n;
	cin>>n;
	int a[110];
	bool ok=true;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0){
			if(!(a[i]%3==0||a[i]%5==0))ok=false;
		}
	}
	if(ok)cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

use std::collections::HashSet;

fn main() {
    input!{
      n: usize,
      m: usize,
      abs: [(usize, usize); m],
    }

    let mut to_2 = HashSet::new();
    let mut to_n = HashSet::new();
    for (a, b) in abs {
        if a == 1 {
            to_2.insert(b);
        }
        if b == n {
            to_n.insert(a);
        }
    }
    for i2 in to_2 {
        if to_n.contains(&i2) {
            println!("{}", "POSSIBLE");
            return;
        }
    }
    println!("{}", "IMPOSSIBLE");
}


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

int main() {
    long long A,B,K;
    cin >> A >> B >> K;
    if(A>=K) cout << A-K << " " << B << endl;
    else if(A+B >=K) cout << 0 << " " << A+B-K << endl;
    else cout << 0 << " " << 0 << endl;  
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(3 * n);
	REP(i, 3 * n)cin >> v[i];
	sort(ALL(v));
	ll ans = 0;
	REP(i, n) {
		ans += v[n + 2 * i];
	}
	cout << ans << endl;
}


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

money = 1000
min_val = 10000

for i in range(N):
    if (A[i] < min_val):
        min_val = A[i]

    if (A[i] > min_val):
        money += (money // min_val) * (A[i] - min_val)
        min_val = A[i]

print(money)


Measured memory_bytes: 61976
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))
n,k = l_in()
A = l_in()


t = 0
while t < k:
    left = [0]*n
    right = [0]*n

    
    for i, a in enumerate(A):
        left[max(i-a,0)] += 1
        right[min(i+a,n-1)] += 1

    flag = True
    A = [0]*n
    current = 0
    for i in range(n):
        current += left[i]
        A[i] = current
        flag = flag and A[i] == n
        current -= right[i]

    t += 1

    if flag:
        break

    

print(*A)
    
    
    


Measured memory_bytes: 170948
S = list(input())
K = int(input())


x = "1"
for i in S:
	if i == "1":
		pass
	else:
		x = i
		break

if x != "1":
	if S.index(x) + 1 <= K:
		print(x)
	else:
		print(1)
else:
	print(1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
     int n;
     cin>>n;
     vector<int>v(n);
 
     f(n)cin>>v[i];
     int k=1;
     int count=0;
     for(int i=0;i<n;i++)
     {
         if(v[i]!=k) count++;
         else k++;
     }
     if (count==n) cout<<"-1"<<endl;
     else 
        cout<<count<<endl;
 
 
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

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

const int MAXN = 2e5 + 10;

ll n, m;
map<ll, ll> cnt;

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

	cin >> n >> m;
	for(int i=0; i<n; i++){
		ll cu; cin >> cu;
		if(cnt.count(cu)) cnt[cu]++;
		else cnt[cu] = 1;
	}
	for(int i=0; i<m; i++){
		ll cb, cc; cin >> cb >> cc;
		if(cnt.count(cc)) cnt[cc] += cb;
		else cnt[cc] = cb;
	}

	auto it = cnt.end();
	ll lef = n;
	ll ans = 0;
	while(lef){
		it--;
		ll take = min(lef, it -> y);
		ans += take * (it -> x);
		lef -= take;
	}

	cout << ans << endl;
}


Measured memory_bytes: 12928
use proconio::{input, fastout};
use proconio::marker::{Chars};

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[fastout]
fn main() {
    input!{
        mut s: Chars,
    }
    let n = s.len();
    s.push('R');
    let mut r: bool = true;
    let mut l: bool = false;
    let mut spot_r = 0;
    let mut spot_l = n-1;
    let mut cnt = 0;
    // let mut sum = 0;
    let mut ans: Vec<usize> = vec![0;n];
    for i in 0..n+1 {
        if r==true && s[i]=='L' {
            r = false;
            l = true;
            spot_r = i-1;
            spot_l = i;
        }
        if l==true && s[i]=='R' {
            let tmp = cnt;
            cnt = i - cnt;
            r = true;
            l = false;
            if cnt%2==0 {
                ans[spot_r] = cnt/2;
                ans[spot_l] = cnt/2;
            } else {
                if (spot_r-tmp)%2==0 {
                    ans[spot_r] = cnt/2 + 1;
                    ans[spot_l] = cnt/2;
                } else {
                    ans[spot_r] = cnt/2;
                    ans[spot_l] = cnt/2 + 1;
                }
            }
            cnt = i;
        }
    }

    for i in 0..n {
        print!("{} ",ans[i]);
    }
    // let mut dp: Vec<usize> = vec![0;n];
    // let mut o = 0;
    // let mut e = 0;
    // let mut spot = 0;
    // for i in 0..n-1 {
    //     if s[i]=='R' {
    //         if i%2!=0 {
    //             o += 1;
    //         } 
    //         if i%
    //         if s[i+1]=='L' {
    //             spot = i;
    //         }
    //     } else {
    //         if s[i+1]=='R' {
    //             dp[spot] = tmp;
    //             tmp = 0;
    //         } else {
    //             tmp += 1;
    //         }
    //     }
    // }

}


Measured memory_bytes: 3296
#include<stdio.h>

int main()
{
	int N,ans=0,n,i;
	scanf("%d",&N);
	for(i=0; N>0; i++){
		ans+=N%10;
		N=N/10;
	}
	if(ans==1)
		ans=10;
	printf("%d\n",ans);
	return 0;
}


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

int factorial(int n) {
    if (n <= 1) return 1;
    else return n * factorial(n-1);
}

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

    int n;
    cin >> n;
    int x[n], y[n];
    rep (i, n) cin >> x[i] >> y[i];
    int fact = factorial(n);
    double res = 0;
    rep (i, n-1) {
        Rep (j, i+1, n) {
            res += sqrt(pow(x[j]-x[i],2)+pow(y[j]-y[i],2))*2*factorial(n-1);
        }
    }
    printf("%.10f", res/fact);
}

Measured memory_bytes: 3720
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN3(n,m,s);
  if(s[m-1]=='A') s[m-1]='a';
  else if(s[m-1]=='B') s[m-1]='b';
  else s[m-1]='c';
  OUT(s);
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i

@s = []

10.times do |i|
  x = []
  (0..i).each do |j|
    x.push ('a'.ord + j).chr
  end
  @s.push x
end

@a = []
def dfs(s, x, n)
  return s if x == n

  @s[x].each do |c|
    break if !s.empty? && s.map(&:ord).max + 1 < c.ord

    ss = s.dup
    ss.push c
    y = dfs(ss, x + 1, n)
    @a.push y if y
  end
  return nil
end

dfs([], 0, n)
puts @a.map(&:join)


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

template <class T> struct CumulativeSum2D {
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}

    void add(int x, int y, T z) {
        ++x, ++y;
        if (x >= data.size() || y >= data[0].size())
            return;
        data[x][y] += z;
    }

    void build() {
        FOR(i, 1, data.size()) FOR(j, 1, data.size()) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }

    void print() {
        for (auto &x : data) {
            for (auto &y : x) {
                cout << y << " ";
            }
            cout << endl;
        }
    }
};

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    int n, k, x, y;
    cin >> n >> k;
    CumulativeSum2D<int> s(k * 2, k * 2);
    REP(i, n) {
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        y %= 2 * k;
        if (y >= k) {
            y -= k;
            x += k;
        }
        x %= 2 * k;
        s.add(x, y, 1);
        s.add((x + k) % (2 * k), y + k, 1);
    }
    // 二次元累積和
    s.build();
    // s.print();
    int maxv = 0;
    REP(x, k) {
        REP(y, k) {
            int t = s.query(x, y, x + k, y + k);
            maxv = max({maxv, t, n - t});
        }
    }
    cout << maxv << endl;
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

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

    bool flag = true;
    rep(i, n){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 and a % 5 != 0){
                flag = false;
                break;
            }
        }
    }
    string ans;
    ans = flag ? "APPROVED" : "DENIED";
    OP(ans);
}


Measured memory_bytes: 256
//103 B - String Rotation 2018/07/21

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    string s,t;
    cin >> s >> t;
    int len=s.size();
    rep(i ,len){
        string x1=s.substr(len-1,1);
        string x2=s.substr(0,len-1);
        s=x1+x2;
        if( s == t ) { puts("Yes\n"); return 0;}
    }
    puts("No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
const int MAX_W = 100, MAX_H = 100;

typedef std::pair<int,int> P;
int map[MAX_H + 1][MAX_W + 1], w, h;

int bfs(P sp, P gp, int c){
	//½±Æª é©ði[
	int f[MAX_H + 1][MAX_W + 1] = {{0}};
	std::queue<P> q;
	q.push(P(sp.first, sp.second));
	
	while(q.size()){
		P p = q.front(); q.pop();
		//S[Å«½ç¬÷
		if(p.first == gp.first && p.second == gp.second && map[p.second][p.first] == c)return 1;
		
		int vy[4] = {-1,1,0,0}, vx[4] = {0,0,-1,1};
		for(int i=0;i<4;i++){
			int nx = p.first + vx[i],
				ny = p.second + vy[i];
			if(nx >= 0 && nx <= w && ny >= 0 && ny <= h && 
				 map[ny][nx] == c && !f[ny][nx]){
				q.push(P(nx,ny));
				f[ny][nx] = 1;
			}
		}
	}

	//ÅãÜÅS[Å«È¢Èç¸s
	return 0;
}

int main(){
	P sp, gp;
	while(std::cin >> w >> h, w && h){
		memset(map,0,sizeof(map));
		std::cin >> sp.first >> sp.second;
		std::cin >> gp.first >> gp.second;

		int n;
		std::cin >> n;
		//ubNÌÝu
		while(n--){
			int c, d, x, y;
			std::cin >> c >> d >> x >> y;
			
			int mx, my;
			if(d)//w < h
				my = 4, mx = 2;
			else//w > h
				mx = 4, my = 2;
			for(int i=y;i<y+my;i++)
				for(int j=x;j<x+mx;j++)
					map[i][j] = c;
		}

		int sc = map[sp.second][sp.first];

		//bfsÅS[Å«é©mF
		if(bfs(sp, gp, sc))std::cout << "OK" << std::endl;
		else{std::cout << "NG" << std::endl;}
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <string.h>
char a[5][5];
int main()
{
    for(int i=0; i<2; i++)
    {
        scanf("%s",&a[i]);
    }
    if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0])
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vc vector<int>
#define F first
#define S second
#define eb emplace_back

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1; 
        x = (x * x) % p;
    }
    return res;
}

int modInverse(int n, int p)
{
    return power(n, p - 2, p);
}

int nCrModPFermat(int n, int r, int p)
{

    if (r == 0)
        return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;

    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) %
           p;
}
/*
// dsu started 
int a[1000000],b[1000000];
    int find(int x){
        if(b[x]==x) return x;
        b[x]= find(b[x]);
      return b[x];
    }
    void uniona(int x,int y){
        x=find(x);
        y=find(y);
        if (x!=y) {
            a[y]<a[x] ? b[x]=b[y]:b[y]=b[x];
        }
    }
//cut from here
int n,k;
    cin>>n>>k;
     
   
     for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=i;
    }
     for(int i=1;i<=k;i++){
    int t1,t2;
    cin>>t1>>t2;// basic code for dsu
    uniona(t1,t2);
//dsu ends
*/

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
     int a[n];
     int h=0,m=0;
     for (int i = 0; i < n; i++)
     {
         cin>>a[i];
        if(a[i]<h){
            m+=h-a[i];

        }
        else {
            h=a[i];
        }
     }
    cout<<m;
     
}

Measured memory_bytes: 5172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	private void solve() throws IOException {
		int n = ni();
		int[] dp = new int[n + 1];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			dp[i + 1] = Math.min(dp[i + 1], dp[i] + 1);
			int d = 6;
			while (i + d <= n) {
				dp[i + d] = Math.min(dp[i + d], dp[i] + 1);
				d *= 6;
			}
			d = 9;
			while (i + d <= n) {
				dp[i + d] = Math.min(dp[i + d], dp[i] + 1);
				d *= 9;
			}
		}
		out.println(dp[n]);
		out.close();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	private int[][] na(int n) throws IOException {
		int[][] a = new int[n][2];
		for (int i = 0; i < n; i++) {
			a[i][0] = ni();
			a[i][1] = i;
		}
		return a;
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pb push_back
#define all(c) begin(c),end(c)
using namespace std;
main(){
  map<int,int> m;
  set<int> s;
  rep(i,4){
    char c;cin>>c;
    m[c]++;s.insert(c);
  }
  if(s.size()==2 && m[*(s.begin())]==2)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	int temp[201];
	for(int i=0;i<=200;i++){
	    temp[i]=-100+i;
	}
	
	int ans=INT_MAX;
	for(int i=0;i<=200;i++){
	    int sum=0;
	    for(int j=0;j<n;j++){
	        sum+=(arr[j]-temp[i])*(arr[j]-temp[i]);
	    }
	    ans=min(ans,sum);
	}
	
	cout<<ans;
	return 0;
}


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

int main() {

int A , B , C = 0 ;
int days = 0 ; 
int week_day_count = 0 ; // 週の何日目かのカウント。月曜日:1 , 火曜日:2 , …　土曜日:6 , 日曜日:7

cin >> A >> B >> C ;

	while( C > 0 ){
	
	days = days + 1 ;			// 「経過日数」を1追加
	week_day_count = week_day_count + 1 ;	// 週の何日目かのカウントを1追加

	C = C - A ;				// 毎日のログインボーナスの処理

		if( 7 == week_day_count ) 	//「日曜日になったとき」の処理。if( week_day_count == 7 )としなかったのはミス防止
		{ C = C - B ; 
		  week_day_count = 0 ;		// 週の何日目かのカウントを1（月曜日）にする。
		}else{				// C++ではelse{}は省略可
		}

		if( C <= 0 ) 	// Cが0未満になったときループを抜ける
		{
		break;
		}else{				// C++ではelse{}は省略可
		}


	}

cout << days << endl;

}




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

using namespace std;
 int main(){
    string s;
   cin>>s;
   int l=0;
  for(int i=0;i<3;i++){
		if(s[i]=='R')l++;}
   if(l==3)cout<<3<<endl;
   else if(l==1)cout<<1<<endl;
   else if(l==2){
     if(s[0]=='R'&&s[2]=='R')cout<<1<<endl;
     else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R')) cout<<2<<endl; }
 else{	cout<<0<<endl;}
			
        

   
     
     return 0;
 }


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

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template <typename T> using orderMSet =
//tree <T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long llu;
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
#define inf 1000000000000000018
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

int main()
{
	ll n, m;
	scanf("%lld %lld", &n, &m);

	ll ans = (n*(n-1))/2 + (m*(m-1))/2;

	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<list>
#include<map>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans=0;
	if(d>=b&&c>=a)
		ans=b-c;
	else if(d>=b&&a>=c)
		ans=b-a;
	else if(b>=d&&c>=a)
		ans=d-c;
	else if(b>=d&&a>=c)
		ans=d-a;
	else ans=0;
	if(ans<=0)ans=0;
	cout<<ans<<endl;
	return 0;
}


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

allcount = 0
if n == 1:
  print(1)
  exit()
for i in range(1,n+1):
  count = 0
  vans = i
  while True:
    if i%2 == 1:
      break
    elif i%2 == 0:
      count += 1
      i //= 2

  if count > allcount:
    allcount = count
    ans = vans

print(ans)

Measured memory_bytes: 9084
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstring>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 10000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}

int main(){

    int n;
    erats();
    while(cin>>n&&n!=0){
        int head=0;
        int tail=0;
        int sum=prime[head];
        int cnt=0;
        while(tail<n&&head<=tail){
            if(sum==n)
                cnt++;
            if(sum>=n){
                sum-=prime[head];
                head++;
            }
            else if(sum<n){
                tail++;
                sum+=prime[tail];
            }
        }
        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define dracarys ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
 
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << " Here => " << x 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ptime;
void inline fileIO(){ 
    ptime=false;
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        ptime=true;
    #endif
        srand((unsigned)time(0));
}

void inline solve(int tc){
    int n,m,tar;
    cin >> n >> m >> tar;
    vector<int> row[n+1];
    vector<int> col(m+1);

    for (int x,y,i=0;i<tar;i++){
        cin >> x >> y;
        row[x].pb(y);
        col[y]++;
    }

    set<pair<int,int>,greater<pair<int,int>>> Ust;
    for (int i=1;i<=m;i++){
        if (!col[i]) continue;
        Ust.insert({col[i],i});
    }

    ll cnt = 0;
    for (int now,i=1;i<=n;i++){
        if (!row[i].size()) continue;
        set<pair<int,int>,greater<pair<int,int>>> temp;
        for (int& it:row[i]){
            temp.insert({col[it],it});
            Ust.erase(Ust.find({col[it],it}));
        }
        now = row[i].size();
        now += max(temp.begin()->fi - 1 ,(Ust.size() ? col[Ust.begin()->se]:0));
        cnt = (now > cnt ? now : cnt);
        for (int& it:row[i]){
            Ust.insert({col[it],it});
        }
    }
    cout << cnt << "\n";
}

int main(){
    fileIO();

    dracarys

    int tt=0,t=1;
    //cin >> t;

    while(t--){solve(++tt);}

    if (ptime)
        cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s    ";


    return 0;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const ll MX = 2 * 1e5;

ll N;
map<ll, ll> cnts;
ll ans;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N;
	vl a(N); 
	F0R(i, N) {
		cin >> a[i];
		cnts[a[i]]++;
	}
	
	trav(i, cnts) {
		ans += (i.s * (i.s - 1)) / 2;
	}
	
	F0R(i, N) {
		ll tempAns = ans;
		tempAns -= (cnts[a[i]] * (cnts[a[i]] - 1)) / 2;
		tempAns += ((cnts[a[i]] - 1) * (cnts[a[i]] - 2)) / 2;
		cout << tempAns << "\n";
	}
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  vector<vector<bool>> dp(4, vector<bool>(1000,false));

  dp[0][0] = true;

  for (int i = 0; i < n; i++) {
    vector<vector<bool>> dp2(4, vector<bool>(1000,false));
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 1000; k++) {
        if (!dp[j][k]) continue;
        dp2[j][k] = dp[j][k];
        if (j < 3) {
          dp2[j + 1][10 * k + (s[i] - '0')] = dp[j][k];
        } 
      }
    }
    dp = dp2;
  }
  
  int res = 0;

  for (int i = 0; i < 1000; i++) res += dp[3][i];

  cout << res << endl;

  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>

int gcd(int x, int y)
{
	int r;
	while((r = x % y) != 0){
		x = y;
		y = r;
	}
	return y;
}


int main()
{
	int n, a[100001], t;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		std::cin >> a[i];
	}
	t = a[0];
	for(int i = 1; i < n; i++){
		t = gcd(t, a[i]);
	}
	std::cout << t << std::endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll s[9];
ll h,w,n;
map<P,ll>mp;
int main(void){
    cin>>h>>w>>n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a-j>0&&b-k>0&&a-j<=h-2&&b-k<=w-2){
                    mp[P(a-j,b-k)]++;
                }
            }
        }
    }
    ll tot=0;
    for(auto x:mp){
        s[x.second-1]++;
        tot++;
    }
    cout<<(h-2)*(w-2)-tot<<endl;
    for(int i=0;i<9;i++){
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 56448
import sys
s = input()
s = [c for c in s]
flg = False
if s[0] == 'A':
    if s[2:-1].count('C') == 1:
        if s.count('C') == 1:
            s.remove('A')
            s.remove('C')
            for c in s:
                if not c.islower():
                    flg = False
                    break
                flg = True
print('AC' if flg else 'WA')

Measured memory_bytes: 3060
import java.util.*;
  
class Main{
   public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    int w = input.nextInt();//長方形横
	int h = input.nextInt();//長方形たて
	int x = input.nextInt();//円の中心座標横軸
	int y = input.nextInt();//円の中心座標縦軸
	int r = input.nextInt();//円の半径
   	int inputhightforcircle = (y + r);//円の範囲縦方向
   	int inputwideforcircle = (x + r);//円の範囲横方向
   	
   	if(inputhightforcircle <= h &&
   		inputwideforcircle <= w &&
   		inputhightforcircle > 0 &&
   		inputwideforcircle > 0 && 
   		h > 0 && h <= 100 &&
   		w > 0 && w <= 100 &&
   		r > 0 && r <= 100){
   			
     	System.out.println("Yes");
   	}else{
   		System.out.println("No");
   	}
   	
  }
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   pii;
typedef vector<int>     vi;
typedef long double     ld;
#define MOD         1000000007
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        '\n'
#define PI          3.14159265359d
#define sz(x)       (int)x.size()
vector<pii> adj[100005];
ll dist[100005];
void dfs(int i,int p,int w)
{
    dist[i]=dist[p]+w;
    for(int j=0;j<sz(adj[i]);j++)
        if(adj[i][j].F!=p)
            dfs(adj[i][j].F,i,adj[i][j].S);
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a,b,c,i,q,k;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b>>c;
        adj[a].pb({b,c});
        adj[b].pb({a,c});
    }
    cin>>q>>k;
    dfs(k,0,0);
    while(q--)
    {
        cin>>a>>b;
        cout<<dist[a]+dist[b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14336