akhauriyash/Code-Regression huggingface dataset:
//2次元いもす法の基本的な問題
#include<iostream>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i=0;i<(n);i++)

ll N;

ll c[1010][1010];

int main() {
    cin >> N;

    rep(i,N) {
        ll x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;//[x1,x2) [y1,y2)

        c[y1][x1]++;
        c[y1][x2]--;
        c[y2][x1]--;
        c[y2][x2]++;
    }

    rep(i,1001) {
        rep(j,1000) {
            c[i][j + 1] += c[i][j];
        }
    }
    rep(j,1001) {
        rep(i,1000) {
            c[i + 1][j] += c[i][j];
        }
    }

    ll ans = 0;

    rep(i,1001)rep(j,1001) ans = max(ans,c[i][j]);

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


Measured memory_bytes: 10992
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    string[] input = Console.ReadLine().Split();
    if(input[0][input[0].Length-1] == input[1][0]
       && input[1][input[1].Length-1] == input[2][0]){
      Console.WriteLine("YES");
    }
    else{
      Console.WriteLine("NO");
    }
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

int main() {
    int n;
    cin >> n;
    int a[200010] = {};
    for(int i = 1; i < n; i++){
        int aa;
        cin >> aa;
        a[aa]++;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
	return 0;
}

Measured memory_bytes: 4428
#define _GLIBCXX_DEBUG //提出時に消す
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 2100000000
#define MOD 1000000007

bool dbgflag = false; //debug

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k, a, b;
  cin >> k >> a >> b;

  
  for (int i = a; i <= b; i++) {
    if (i%k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n, m, x;
    cin >> n >> m >> x;

    vi c(n);
    vvi a(n, vi(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) {
            cin >> a[i][j];
        }
    }

    int ans = 1000000000;
    for(int bit = 0; bit < (1 << n); bit++) {
        vi s(m);
        int t = 0;
        bool can = true;
        for(int i = 0; i < n; i++) {
            if(bit & (1 << i)) {
                t += c[i];
                rep(j, m) s[j] += a[i][j];
            }
        }
        rep(i, m) {
            if(s[i] < x) can = false;
        }
        if(can) ans = min(ans, t);

        //cout << t << endl;
    }

    cout << (ans == 1000000000 ? -1 : ans) << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
	int N = 0;
	int a = 0, b = 0,n = 0,ans = 0,frag = 0;
	int A[100000] = { 0 };
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", &A[i]);

	for (int i = 0; i < N; i++){
		
		if (A[i] == i + 1 && A[i + 1] == i + 2){
			ans++;
			
			A[i] = -1;
			A[i + 1] = -1;
			i++;
		}
		if (A[i] == i + 1){
			ans++;
			A[i] = -1;
		}
		a = i;
	}
	if (A[a + 1] == N)
		ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
LL a[maxn];
int n;
int main()
{
    scanf("%d",&n);
    int tot=0;
    LL sum=0;
    LL mi=INT64_MAX;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(a[i]<0) tot++;
        sum+=abs(a[i]);
        mi=min(mi,abs(a[i]));
    }
    if(tot&1) sum-=2*mi;
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const int INF = 1e9;

int n,wmi,whi,emi,ehi;
string s;
int ans=INF;
int main(){
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='W')wmi++;
    else emi++;
  }
  for(int i=0;i<n;i++){
    if(s[i]=='W')wmi--;
    else emi--;
    ans=min(whi+emi,ans);
    if(s[i]=='W')whi++;
    else ehi++;
  }
  cout<<ans<<endl;
  return 0;
}



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

int main()
{
	bool flag;
	int sum, H;
	while (cin >> H, H) {
		sum = 0;
		vector< vector<int> > a(5, vector<int>(H, 0));
		for (int j = 0; j < H; j++) {
			for (int i = 0; i < 5; i++) {
				cin >> a[i][j];
				sum += a[i][j];
			}
		}

		do {
			flag = false;
			for (int j = H - 1; j >= 0; j--) {
				for (int i = 0; i < 3; i++) {
					if (a[i][j] != 0 && a[i][j] == a[i + 1][j] && a[i][j] == a[i + 2][j]) {
						if (i <= 1 && a[i][j] == a[i + 3][j]) {
							if (i == 0 && a[i][j] == a[i + 4][j]) {
								a[i + 4][j] = 0;
							}
							a[i + 3][j] = 0;
						}
						a[i][j] = a[i + 1][j] = a[i + 2][j] = 0;
						flag = true;
					}
				}
			}
			for (int i = 0; i < 5; i++) {
				for (int j = 0; j < H - 1; j++) {
					if (a[i][j + 1] == 0 && a[i][j] != 0) {
						a[i][j + 1] = a[i][j];
						a[i][j] = 0;
						j = -1;
					}
				}
			}
		} while (flag);

		for (int j = 0; j < H; j++)
			for (int i = 0; i < 5; i++)
				sum -= a[i][j];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
# ABC109D - Make Them Even
def main():
    H, W, *A = map(int, open(0).read().split())
    A = [[i & 1 for i in a] for a in zip(*[iter(A)] * W)]
    ans = []
    for i in range(H):  # move left to right
        for j in range(W - 1):
            if A[i][j]:
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]
    for i in range(H - 1):  # move up to down
        if A[i][W - 1]:
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 21460
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Cards { internal int top, btm; }

    class Program
    {
        static readonly int INF = int.MaxValue / 2;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Cards[] c = new Cards[n];
            int[,] dp = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                c[i].top = int.Parse(input[0]);
                c[i].btm = int.Parse(input[1]);
            }

            for (int l = 1; l < n; l++)
            {
                for (int i = 0; i < n - l; i++)
                {
                    int j = i + l;
                    dp[i, j] = INF;

                    for (int k = i; k < j; k++)
                    {
                        int cost = dp[i, k] + dp[k + 1, j] + c[i].top * c[k].btm * c[k + 1].top * c[j].btm;

                        dp[i, j] = Math.Min(dp[i, j], cost);
                    }
                }
            }
            Console.WriteLine(dp[0, n - 1]);
        }
    }
}

Measured memory_bytes: 9092
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
#define int long long

#define fr(s,n,i) for(int i=s;i<n;i++)
#define fr_(s,n,i) for(int i=s;i>=n;i--)

int MOD = 1000000007;

void solve();

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

void solve(){
    int n,m;
    map<int,int> mp;
    cin >> n >> m;
    fr(0,n,i){
        int k;
        cin >> k;
        fr(0,k,j){
            int buf;
            cin >> buf;
            mp[buf]++;
        }
    }
    int cnt=0;
    fr(0,m+1,i){
        if(mp[i] == n){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
static const int MAX_N = 10000001;
bool primes[MAX_N];
int qr[900];

int main() {
    fill(primes, primes+MAX_N, 1);
    fill(qr, qr+13, 0);
    primes[0] = primes[1] = false;
    for (int i = 2; i * i < MAX_N; i++) {
        if (!primes[i]) continue;
        for (int j = i * i; j < MAX_N; j+=i) primes[j] &= 0;
    }
    qr[0] = 0;
    int idx = 1;
    for (int i = 2; i < MAX_N-8; i++)
        if (primes[i] && primes[i+2] && primes[i+6] && primes[i+8]) qr[idx++] = i+8;
    int n, res;

    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        res = int(upper_bound(qr, qr+idx, n)-qr-1);
        printf("%d\n", qr[res]);
    }
    return 0;
}



Measured memory_bytes: 12348
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std;

int n;
long long dp1[300010],dp2[300010],a[300010],sum1,sum2;

priority_queue<long long,vector<long long>,greater<long long> > q;
priority_queue<long long> q2;

int main()
{
	//fuck!!!
	scanf("%d",&n);
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0x3f,sizeof(dp2));
	for(int i=1;i<=3*n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		q.push(a[i]);
		sum1+=a[i];
	}
	dp1[n]=sum1;
	for(int i=n+1;i<=3*n;i++)
	{
		if(q.top()<a[i])
		{
			sum1-=q.top();
			sum1+=a[i];
			q.pop();
			q.push(a[i]);
		}
		dp1[i]=sum1;
	}
	for(int i=3*n;i>2*n;i--)
	{
		q2.push(a[i]);
		sum2+=a[i];
	}
	dp2[2*n+1]=sum2;
	for(int i=2*n;i>=1;i--)
	{
		if(q2.top()>a[i])
		{
			sum2-=q2.top();
			sum2+=a[i];
			q2.pop();
			q2.push(a[i]);
		}
		dp2[i]=sum2;
	}
	long long ans=-0x3f3f3f3f3f3f3f3f;
	for(int i=n;i<=2*n;i++)
	{
//		printf("%d %lld %lld\n",i,dp1[i],dp2[i]);
		ans=max(ans,dp1[i]-dp2[i+1]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 9588
#include<stdio.h>
#include<string.h>

int main(void){

  int a=0, b=0, c=0, d=0;
  int sum=0;

scanf("%d %d %d %d", &a, &b, &c, &d);
  if(a>=b){
    sum=b;
  }else{
    sum=a;
}
  if(c>=d){
    sum=sum+d;
  }else{
    sum=sum+c;
  }

  printf("%d\n", sum);

  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
    return 0;
}

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

using namespace std;

/**/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/**/

#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;



int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int n, k;
	string s;
	cin >> n >> k >> s;

	int g = 0, ans = 0;

	for (int i = 0, j = 0; i < n; i = j) {
		while (j < n && s[i] == s[j]) ++j;
		++g; ans += j - i - 1;
	}

	while (g >= 3 && k > 0) {
		g -= 2;
		ans += 2;
		--k;
	}

	if (k > 0 && g == 2) ans += 1;

	cout << ans << '\n';




	return 0;
}



Measured memory_bytes: 512
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    ((n*m)%2!=0)?cout<<"Yes":cout<<"No"
;}


Measured memory_bytes: 3616
#include <stdio.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int ufroot(int x){return unicnt[x]<=0?-(unicnt[x]=-ufroot(-unicnt[x])):x;}
int ufsame(int x,int y){return ufroot(x)==ufroot(y);}
void uni(int x,int y){if((x=ufroot(x))==(y=ufroot(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	ufinit(n);
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t)printf("%d\n",ufsame(x,y));
		else uni(x,y);
	}
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 5010
#define MAXM 210

vector<pi> V;
ll G[MAXN][MAXM];
ll N,M;
ll A[MAXN];
ll updates[MAXN][MAXN];

int main(){
	cin>>N>>M;
	for (ll i=1;i<N;++i)cin>>A[i];
	for (ll i=1;i<=N;++i)for (ll j=1;j<=M;++j)cin>>G[i][j];
		
	for (ll j=1;j<=M;++j){
		V.clear();
		V.pb(1e9,0);
		for (ll i=1;i<=N;++i){ 
			// Updates are all update[something][i];
			ll val = G[i][j];

			while (SZ(V) && V.back().f < val){
				pi p = V.back();V.pop_back();
				ll st=V.back().s+1;
				// Update everything from st to p (inclusive)
				ll c = val - p.f;
				// cout<<"Updated "<<i<<" from "<<st<<" to "<<p.s<< " as "<<c<<'\n';
				updates[st][i] += c;
				updates[p.s+1][i] -= c;
			}
			updates[i][i] += val;
			updates[i+1][i] -= val;
			V.pb(val,i);
		}
		// break;
	}
	for (ll i=1;i<=N;++i)for (ll j=1;j<=N;++j)updates[i][j] += updates[i-1][j];
	// for (ll i=1;i<=M;++i){for (ll j=1;j<=M;++j)cout<<updates[i][j]<<' ';cout<<'\n';}cout<<'\n';

	ll ans = 0;
	ll cur = 0;
	for (ll st = 1;st<=N;++st){
		cur = updates[st][st];
		// cout<<"Happiness from "<<st<<" to "<<st<<" is "<<cur<<'\n';
		ans=max(ans,cur);
		for (ll ct = st+1;ct<=N;++ct){
			cur += updates[st][ct];
			cur -= A[ct-1];
			// cout<<"Happiness from "<<st<<" to "<<ct<<" is "<<cur<<'\n';
			ans=max(ans,cur);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 204544
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

int main() {
	int n;cin >> n;
    string S;cin >> S;
    if(n ==1 || (n%2 ==1)){
        cout << "No"<< endl;
        return 0;
    }
    REP(i,n/2){
        if(S[i]!=S[i+n/2]) {
            cout << "No"<< endl;
            return 0;
        }
    }
    cout << "Yes"<< endl;
    return 0;


}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A = 0;
  int C = 1;
  int G = 2;
  int T = 3;
  long MOD = 1e9 + 7;
  long dp[101][5][5][5] = {};
  dp[0][4][4][4] = 1;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      for (int k = 0; k < 5; k++)
      {
        for (int l = 0; l < 5; l++)
        {
          for (int m = 0; m < 4; m++)
          {
            if (k == A && l == G && m == C)
              continue;
            if (k == A && l == C && m == G)
              continue;
            if (k == G && l == A && m == C)
              continue;
            if (j == A && l == G && m == C)
              continue;
            if (j == A && k == G && m == C)
              continue;
            dp[i + 1][k][l][m] += dp[i][j][k][l];
            dp[i + 1][k][l][m] %= MOD;
          }
        }
      }
    }
  }
  long ans = 0;
  for (int j = 0; j < 4; j++)
  {
    for (int k = 0; k < 4; k++)
    {
      for (int l = 0; l < 4; l++)
      {
        ans += dp[N][j][k][l];
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(void)
{
  int N,A,res=0;

  scanf("%d",&N);

  scanf("%d",&A);

  res=(N*N)-A;

  printf("%d",res);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				int val=a[i];
				int val1=a[j];
				int val2=a[k];
				if(val==val1||val1==val2||val==val2)
					continue;
				int maxi=max({val,val1,val2});
                int sum=0;
                if(val!=maxi)sum+=val;
                if(val1!=maxi)sum+=val1;
                if(val2!=maxi)sum+=val2;
                if(sum>maxi)
                	cnt++;
			}
		}
	}
	cout<<cnt;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	long long N, S = 0;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		if (i % 3 != 0 && i % 5 != 0) S += i;
	}
	cout << S << '\n';
	return 0;
}

Measured memory_bytes: 3624
N, Y = [int(_) for _ in input().split()]
Z = Y // 1000 - N
for x in range(Z // 9, Z // 9 - 4, -1):
    if (Z - 9 * x) % 4 == 0:
        y = (Z - 9 * x) // 4
        z = N - x - y
        break
if x >= 0 and y >= 0 and z >= 0:
    print(x, y, z)
else:
    print(-1, -1, -1)

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, -1)
#define RREP(i, n, k) for(auto i = n; i != k; i--)

#define debug(x) cerr << #x << " " << x << endl
#define print(x) cout << x;
#define println(x) cout << x << endl;
#define spc << " " <<

#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define eb emplace_back
#define np next_permutation

using ll = long long;
using Pii = pair<int, int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

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

   int N, M; cin >> N >> M;
   V<bool> like = V<bool>(M, true);

   rep(n, N) {
      int K; cin >> K;
      V<bool> like_tmp = V<bool>(M, false);
      rep(k, K) {
         int A; cin >> A;
         like_tmp[A-1] = true;
      }
      rep(m, M) {
         like[m] = like[m] && like_tmp[m];
      }
   }

   int ans = 0;
   rep(m, M) {
      if (like[m]) ans++;
   }

   cout << ans << endl;

   return 0;
}


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

x_list=list(map(int,input().split()))
x_list=sorted(x_list,reverse=True)

a,b=0,0

for i in range(N):
    if((i+1)%2!=0):
        a+=x_list[i]
    else:
        b+=x_list[i]

print(a-b)

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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435

const int d4i[4]={-1,0,1,0},d4j[4]={0,1,0,-1};
const int d8i[8]={-1,-1,0,1,1,1,0,-1},d8j[8]={0,1,1,1,0,-1,-1,-1};


void solve(){
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	F(l,r+1,i){
		if(i%d == 0) ans++;
	}
	cout<<ans;
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



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

int main() {
  int D, T, S;
  scanf("%d%d%d", &D, &T, &S);
  if (((float)D / (float)S) <= T) 
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

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

int main(){
    int w, h, n; cin>>w>>h>>n;
    int w1=0, w2=w, h1=0, h2=h;
    for(int i=0; i<n; i++){
        int x, y, a;
        cin>>x>>y>>a;
        if(a==1) chmax(w1, x);
        if(a==2) chmin(w2, x);
        if(a==3) chmax(h1, y);
        if(a==4) chmin(h2, y);
    }
    cout<<max(w2-w1, 0)*max(h2-h1, 0)<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define errp(...) fprintf(stderr, __VA_ARGS__)

int main () { 
	int X, Y,Sum;
	scanf("%d",&X);
	Y = X;

	while (Y > 0) {
		Sum+=Y%10;
		Y=Y/10;
	}
		if(X%Sum==0)
			printf("Yes");
		else
			printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
     
#define pb emplace_back
#define fi first
#define se second
     
using namespace std;
     
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n, m;

int dist[1000010];

vi adj[1000010];
map<int,vpi> G[1000010];
set<pi> used;


priority_queue<pi,vpi,greater<pi> > que;

void dfs( int x , int c , int d ){
  // cout << x <<  " " << c << " " << d << endl;
  used.insert( pi(x,c) );
  if( d < dist[x] ){
    dist[x] = d;
    que.emplace( d , x );
  }
  YYS( e , G[x][c] ){
    if( used.find( pi( e.fi , c ) ) == used.end() ){
      dfs( e.fi , c , d );
    }
  }
}

int main(){

  n = in();
  m = in();
  REP( i , m ){
    int a = in() - 1;
    int b = in() - 1;
    int c = in() - 1;
    adj[a].pb( c );
    adj[b].pb( c );
    G[a][c].pb( b , i );
    G[b][c].pb( a , i );
  }

  REP( i , n ){
    dist[i] = INF;
  }
  dist[0] = 0;
  
  que.emplace( 0 , 0 );
  while( !que.empty() ){
    int d = que.top().fi;
    int x = que.top().se;
    que.pop();
    if( d > dist[x] ){
      continue;
    }
    YYS( c , adj[x] ){
      if( used.find( pi( x , c ) ) == used.end() ){
	dfs( x , c , d + 1 );
      }
    }
  }

  int ans = -1;
  if( dist[n-1] < INF ){
    ans = dist[n-1];
  }
  
  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 137464
#include <cstdio>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
int a[2][13], n, f, c;
int main()
{
    while (scanf("%d", &n), n) {
        rep(i, n) scanf("%d", &a[0][i]);
        c = f = 0;
        while (true) {
            bool ok = true;
            rep(i, n) if (a[0][i] != a[1][i]) ok = false;
            if (ok) break;
            rep(i, n) a[1-f][i] = std::count(a[f], a[f] + n, a[f][i]);
            f = 1 - f;
            c++;
        }
        printf("%d\n", c-1);
        rep(i, n-1) printf("%d ", a[f][i]); printf("%d\n", a[f][n-1]);
    }
    return 0;
}

Measured memory_bytes: 0
N_X = input().split()
N = int(N_X[0])
X = int(N_X[1])

m = []
list_range = range(N)
total_m = 0
for i in list_range:
    m.append(int(input()))
    total_m += m[i]

remaining_m = X - total_m

min_m = min(m)
index_min_m = m.index(min_m)
additional_pieces = remaining_m // min_m
total_pieces = additional_pieces + N
print(total_pieces)






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

typedef long long ll;
const int MAX_WEIGHTS = 10000005;
ll w[105], v[105], dp[MAX_WEIGHTS];
int N, W;
//ll weights[MAX_WEIGHTS];

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

    for(int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        //dp[w[i]] = v[i];
    }
    
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        for(int x = MAX_WEIGHTS - 2; x >= 0; x--) {
            if(dp[x] || x == 0)
                dp[x + w[i]] = max(dp[x + w[i]], dp[x] + v[i]);
        }
    }

    for(int i = 1; i <= W; i++)
        ans = max(ans, dp[i]);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 39168
#include <stdio.h>
#include <stdlib.h>
int f(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}
int main(){
  int N,d[200000];
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%d",d+i);
  qsort(d,N,sizeof(int),f);
  printf("%d\n",d[N/2]-d[N/2-1]);
  return 0;
}

Measured memory_bytes: 2312
h,w = map(int, input().split())
S = [input() for i in range(h)]
U = [[0]*w for i in range(h)]
D = [[0]*w for i in range(h)]
L = [[0]*w for i in range(h)]
R = [[0]*w for i in range(h)]

for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j > 0:
                L[i][j] = L[i][j-1] + 1
            else:
                L[i][j] = 1
    for j in range(w-1,-1,-1):
        if S[i][j] == ".":
            if j < w-1:
                R[i][j] = R[i][j+1] + 1
            else:
                R[i][j] = 1
for i in range(w):
    for j in range(h):
        if S[j][i] == ".":
            if j > 0:
                D[j][i] = D[j-1][i] + 1
            else:
                D[j][i] = 1
    for j in range(h-1,-1,-1):
        if S[j][i] == ".":
            if j < h-1:
                U[j][i] = U[j+1][i] + 1
            else:
                U[j][i] = 1
ans = 0
for i in range(h):
    for j in range(w):
       ans = max(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3,ans)
print(ans)

Measured memory_bytes: 179716
#include <iostream> 

 

using namespace std; 

 

int 

 

main () 

 

{ 

 

  

 

  int a = 1; 

 

  int b; 

 

  while (cin>>b && b) 

 

    { 

 

       

 

      cout << "Case " << a << ": " << b << endl; 

 

      a++; 

 

      

 

    } 
return 0;
   

 

} 


Measured memory_bytes: 3000
n = int(input())
A = input().split()
if n == 1:
    print(' '.join(A))
elif n%2 == 0:
    print(' '.join(A[1::2][::-1]) + ' ' + ' '.join(A[::2]))
else:
    print(' '.join(A[::2][::-1]) + ' ' + ' '.join(A[1::2]))



Measured memory_bytes: 25796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var cnt = Math.Abs(A[0]);
            for (var i = 1; i < N; i++) cnt += Math.Abs(A[i] - A[i - 1]);
            cnt += Math.Abs(A[N - 1]);

            if ((A[0] > 0 && A[1] > 0) || (A[0] < 0 && A[1] < 0))
            {
                if (Math.Abs(A[1]) >= Math.Abs(A[0])) Console.WriteLine(cnt);
                else Console.WriteLine(cnt - 2 * Math.Abs(A[0] - A[1]));
            } else
            {
                Console.WriteLine(cnt - 2 * Math.Abs(A[0]));
            }

            for (var i = 1; i < N - 1; i++)
            {
                var tmp = 0;
                tmp += Math.Abs(A[i] - A[i - 1]) + Math.Abs(A[i + 1] - A[i]);

                if ((A[i + 1] > 0 && A[i - 1] > 0) || (A[i + 1] < 0 && A[i - 1] < 0))
                {
                    Console.WriteLine(cnt - tmp + Math.Abs(Math.Abs(A[i + 1]) - Math.Abs(A[i - 1])));
                }
                else
                {
                    Console.WriteLine(cnt - tmp + Math.Abs(A[i + 1]) + Math.Abs(A[i - 1]));
                }
            }

            if ((A[N - 1] > 0 && A[N - 2] > 0) || (A[N - 1] < 0 && A[N - 2] < 0))
            {
                if (Math.Abs(A[N - 1]) >= Math.Abs(A[N - 2])) Console.WriteLine(cnt - 2 * (Math.Abs(A[N - 1]) - Math.Abs(A[N - 2])));
                else Console.WriteLine(cnt);
            }
            else
            {
                Console.WriteLine(cnt - 2 * Math.Abs(A[N - 1]));
            }
        }
    }
}

Measured memory_bytes: 27228
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[,]A = new int[N,2];
		var uf = new UnionFind(100001);
		var list = new List<int>[100001];
		for(var i=0;i<100001;i++){
			list[i] = new List<int>();
		}
		for(var i=0;i<N;i++){
			string[] str = Console.ReadLine().Split();
			A[i,0] = int.Parse(str[0]);
			A[i,1] = int.Parse(str[1]);
			list[A[i,0]-1].Add(A[i,1]-1);
		}
		var dic = new Dictionary<int,int>();
		for(var i=0;i<100001;i++){
			dic[i] = 1;
		}
		for(var i=0;i<100001;i++){
			if(list[i].Count >= 2){
				for(var j=1;j<list[i].Count;j++){
					if(!uf.IsSameGroup(list[i][0],list[i][j])){
						int a = dic[uf.Root(list[i][0])];
                      　int b = dic[uf.Root(list[i][j])];
						uf.Unite(list[i][0],list[i][j]);
						dic[uf.Root(list[i][0])] = a+b;
					}
				}
			}
		}
		long ans = 0;
		for(var i=0;i<100001;i++){
			if(list[i].Count >= 1){
				ans += dic[uf.Root(list[i][0])] - list[i].Count;
			}
		}
		Console.WriteLine(ans);
	}
	
	public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    public int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

}


Measured memory_bytes: 32780
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=200005;
int n;map<char,char>M1,M2;
char c1[MAXN],c2[MAXN];
int main(){
	scanf("%s%s",c1+1,c2+1);
	n=strlen(c1+1);
	for(int i=1;i<=n;i++){
		if(M1[c1[i]]&&M1[c1[i]]!=c2[i]){
			printf("No\n");return 0;
		}
		if(M2[c2[i]]&&M2[c2[i]]!=c1[i]){
			printf("No\n");return 0;
		}
		if(!M1[c1[i]]&&!M2[c2[i]]){
			M1[c1[i]]=c2[i];
			M2[c2[i]]=c1[i];
		}
	}
	printf("Yes\n");
	return 0;
}
/*
abcdefg
bcdefga
*/

Measured memory_bytes: 640
import sys
f = sys.stdin

def take2(iterable):
    while True:
        yield next(iterable), next(iterable)
#内積
def dot(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag

for line in f:
    a,b,c,d = [x + y * 1j for x, y in take2(map(float, line.split()))]
    
    #内積の絶対値が十分に小さい時、直行と判断する
    print('YES' if abs(dot(a - b, c - d)) < 1.e-10 else 'NO')

Measured memory_bytes: 6752
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};
ostream& operator<<(ostream& os, const mint& m) {
	os << m.x;
	return os;
}


int S;
mint ans = 0;
mint dp[2005];
mint cnt = 0;

void dfs(int n) {
	for (int i = 3; n + i <= S; i++) {
		dp[n] += dp[n + i];
	}
}

signed main() {
	rep(i, 2005)dp[i] = 0;
	cin >> S;
	dp[S] = 1;
	if (S <= 2) {
		cout << 0;
		return 0;
	}
	for (int i = S; i >= 3; i--) {
		cnt = 0;
		dfs(i);
	}
	rep(i, S + 1)ans += dp[i];
	cout << ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    sort(all(a));

    int res = 0;

    set<int> st;

    rep(i, n) {
        while (a[i] == a[i+1]) {
            st.insert(a[i]);
            i++;
        }

        bool f = true;

        for (int j = 1; j * j <= a[i]; j++) {
            if (st.empty()) break;
            if (a[i] % j == 0) {
                if (st.find(j) != st.end()) {
                    f = false;
                    break;
                }
                if (j * j != a[i]) {
                    if (st.find(a[i]/j) != st.end()) {
                        f = false;
                        break;
                    }
                }
            }
        }

        if (f) {
            res++;
        }

        st.insert(a[i]);
    }

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

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


const ll INF = 1001001001;

struct PointUpdateRangeMax {
  using Val = ll;
  int n;
  vector<Val> seg;
  void clear(int N) {
    for (n = 1; n < N; n <<= 1);
    seg.assign(n * 2, 0); // 初期値
  }
  // [l, r)
  Val getMax(int l, int r) {
    if (r - l <= 0) return -INF;
    return getMax(0, n, 1, l, r);
  }
  Val getMax(int nl, int nr, int k, int l, int r) {
    if (r <= nl || nr <= l) return -INF;
    if (l <= nl && nr <= r) return seg[k];
    Val x = getMax(nl, (nl+nr)/2, 2*k  , l, r);
    Val y = getMax((nl+nr)/2, nr, 2*k+1, l, r);
    return max(x, y);
  }
  void update(int pos, ll val) {
    int k = n + pos;
    seg[k] = val;
    while (k/2 >= 1) {
      k /= 2;
      seg[k] = max(seg[2*k], seg[2*k+1]);
    }
  }
};


int main2() {
  int H = nextLong();
  int W = nextLong();
  int M = nextLong();


  vector<pair<int,int>> v;
  REP(i, M) {
    int x = nextLong();
    int y = nextLong();
    v.push_back({x, y});
  }
  sort(ALL(v));

  PointUpdateRangeMax count;
  count.clear(312345);

  REP(i, M) {
    int y = v[i].second;
    int cur = count.getMax(y, y+1);
    count.update(y, cur + 1);
  }
  ll ans = count.getMax(0, 312340);

  vector< vector<int> > xs(H+1);
  REP(i, M) {
    int x = v[i].first;
    int y = v[i].second;
    xs[x].push_back(y);
  }

  REP(x, H+1) if (xs[x].size()) {
    for (auto y : xs[x]) {
      int cur = count.getMax(y, y+1);
      count.update(y, cur - 1);
    }

    ll val = xs[x].size();
    val +=  count.getMax(0, 312340);

    // cout << val << " x=" << x << "   +" << xs[x].size() << endl;

    chmax(ans, val);
    for (auto y : xs[x]) {
      int cur = count.getMax(y, y+1);
      count.update(y, cur + 1);
    }

  }


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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()
#define MP(x, y) make_pair(x, y)

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n; cin >> n;
    vector<P> p(n);
    map<P, ll> m;
    rep(i, n) {
        ll x, y; cin >> x >> y;
        p[i] = MP(x, y);
    }
    frep(i, 0, n-2) {
        frep(j, i+1, n-1) {
            ll x = p[i].first - p[j].first;
            ll y = p[i].second - p[j].second;
            if(x < 0 && y < 0) {
                x *= -1;
                y *= -1;
            }
            if(x > 0 && y < 0) {
                x *= -1;
                y *= -1;
            }
            if(y == 0) x = my_abs(x);
            if(x == 0) y = my_abs(y);
            if(m.count(MP(x, y))) {
                m[MP(x, y)]++;
            }
            else {
                m[MP(x, y)] = 1;
            }
        }
    }
    ll a = 0;
    for(auto p: m) {
        auto value = p.second;
        if(a < value) a = value;
    }

    cout << n-a << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define mx 100005
#define inf 1000000007
using namespace std;

int n, m, w, v, dp[mx], ans;

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

	fill(dp+1, dp+mx, inf);

	for(int i = 0; i < n; i++){
		scanf("%d%d", &w, &v);
		for(int j = mx-v; j >= 0; j--){
			if(dp[j] <= m-w) dp[j+v] = min(dp[j+v], dp[j] + w);
		}
	}
	for(int i = mx-1; i >= 0; i--){
		if(dp[i] <= m){
			ans = i;
			break;
		}
	}
	printf("%lld", ans);
}

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

int main(){
  int n;
  cin>>n;
  ll ans=0;
  ll high=0;
  for(int i=0;i<n;i++){
    ll x;
    cin>>x;
    if(x<=high){
      ans+=high-x;
    }
    else{
      high=x;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
N , M , C = map(int,input().split())
B = list(input().split())

count = 0

for i in range(N):
    multipl = 0
    A = list(input().split())
    for i in range(M):
        multipl = float(A[i]) * float(B[i]) + multipl
    if (multipl + C) > 0:
        count += 1
print(count)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22){
		cout<<"bust";
	}
	else cout<<"win";
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


vector<pll> wlist;


bool compare_b(pll a, pll b) {

	if (a.second < b.second) {
		return true;
	}

	return false;

}

int main() {
	ll N;

	cin >> N;
	wlist.resize(N);
	rep(i, N) {
		cin >> wlist[i].first >> wlist[i].second;

	}

	sort(wlist.begin(), wlist.end(), compare_b);
	
	ll sum_w = 0;
	rep(i, N) {

		sum_w += wlist[i].first;

		if (sum_w > wlist[i].second) {
			cout << "No" << endl;
			return 0;
		}


	}


	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int N, A[100001] = { 0 };
	cin >> N;

	int a, x = 0;
	REP(i, N) {
		cin >> a;
		if (A[a] > 0) {
			x++;
		}
		A[a]++;
	}

	int y = 0;
	REP(i, 100001) {
		if (A[i] != 0) {
			y++;
		}
	}
	if (x % 2 == 0) {
		cout << y << endl;
	}
	else {
		cout << y - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 640