akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    double D;
    cin >> D;

    int ans = 0;
    double x, y;

    REPinit(i, 0, N) {
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= D) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3860
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    int n = s.length();
    int ans = n;
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'S') ++cnt;
        else{
            if(cnt == 0)    continue;
            --cnt;
            ans -= 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll ans = 100000;
    rep(i, n) {
        ll a;
        cin >> a;
        ll x = 0;
        while(a%2 == 0) {
            a /= 2;
            x++;
        }
        chmin(ans, x);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  int A[N],B[N];
  for(int i=0;i<N;i++) cin >> A[i];
  for(int i=0;i<N;i++) cin >> B[i];
  int ans=0;
  for(int i=0;i<N;i++) for(int j=0;j<N;j++) ans^=A[i]+B[j];
  cout << ans << endl;
} 

Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr auto MOD = 998244353;
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 edge {
    int from, to; ll cost;
    edge(int s, int t, ll w) : from(s), to(t), cost(w) {}
};

class unionfind {
    vector<int> par, rank;
public:
    unionfind(int n) : par(n), rank(n, 1) {
        for (int i = 0; i < n; i++)par[i] = i;
    }
    void init(int n) {
        par.clear();
        rank.clear();
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++)par[i] = i;
        for (int i = 0; i < n; i++)rank[i] = 1;
    }
    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    int size(int x) {
        if (par[x] == x)return rank[x];
        return size(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
            rank[ry] += rank[rx];
        }
        else {
            par[ry] = rx;
            rank[rx] += rank[ry];
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

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

    int n, h, w;
    cin >> n >> h >> w;

    vector<edge> g;
    int r, c; ll a;
    FOR(i, 0, n) {
        cin >> r >> c >> a;
        g.push_back({ r, h + c, a });
    }

    rSORT(g, [](edge x, edge y) {return x.cost > y.cost; });
    unionfind uf(h + w + 1);
    ll ans = 0;
    FOR(i, 0, n) {
        if (!uf.same(g[i].from, g[i].to)) {
            ans += g[i].cost;
            uf.unite(g[i].from, g[i].to);
        }
        else if (!uf.same(g[i].from, 0)) {
            ans += g[i].cost;
            uf.unite(g[i].from, 0);
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3440
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
using namespace std;

typedef long long LL;

LL a[200000+10],f[200000+100],n,k;

bool cmp(LL x,LL y)
{
    return x>y;
}
bool  check(LL amd)
{
    LL sum=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]*f[i]>amd)
           sum=sum+ ceil(1.0 * (a[i] * f[i] - amd) / f[i]);
        if(sum>k)
            return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%lld",&f[i]);
    sort(a+1,a+1+n);
    sort(f+1,f+1+n,cmp);
    LL l=-1,r=1e13,ans=0;
    while(r-l>1)
    {
        LL mid=(l+r)>>1;
        //cout<<" "<<l<<" "<<r<<" "<<mid<<" "<<check(mid)<<endl;
        if(check(mid))
        {
            ans=mid;
            r=mid;
        }
        else l=mid;
    }
     printf("%ld",ans);
    //cout<<ans;
    return 0;
}

Measured memory_bytes: 3328
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;
  invec<ll> A(N);
  
  bst::sort(A);
  ll r = A.back();
  priority_queue<ll> siz;
  siz.push(A[N - 2]);
  siz.push(A[N - 2]);

  for (int i = N - 3; i >= 0; i--) {
    auto add = siz.top(); siz.pop();
    r += add;
    siz.push(A[i]);
    siz.push(A[i]);

  }

  return r;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 6924
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
typedef vector<int> vi;

enum DIR { LEFT, RIGHT, FRONT, BACK, BOTTOM, TOP };
int rotm[4][6]={
	{5,4,2,3,0,1},
	{0,1,5,4,2,3},
	{0,1,4,5,3,2},
	{4,5,2,3,1,0}
};

struct Dice{
	vi d, x;
	Dice(vi d):d(d), x(6){}
	inline int &operator[](int i){
		return d[i];
	}
	inline void rot(int k){
		REP(i, 6) x[rotm[k][i]] = d[i];
		swap(d, x);
	}
	inline int check(){
		if(d[BOTTOM] == -1) return 0;
		const int A = d[BOTTOM] + d[TOP];
		const int B = d[LEFT] + d[RIGHT];
		const int C = d[FRONT] + d[BACK];
		return (A <= B+C && B <= A+C+1 && C <= A+B+1);
	}
	
};
int n, p, q;
string db = "ENSW";
int main(){
	while(1){
		vi t(6);
		REP(i, 6) scanf("%d", &t[i]);
		sort(ALL(t));
		if(t[5] == 0) break;
		int n = accumulate(ALL(t), 0);
		string ans(n, 'Z');
		do{
			Dice dice(t);
			string tmp;
			int f = 0;
			REP(itr, n){
				REP(i, 4){
					dice.rot(i);
					dice[BOTTOM] --;
					if(dice.check()){
						tmp.pb(db[i]);
						break;
					}
					dice[BOTTOM] ++;
					dice.rot(3-i);
				}
				if(tmp.size() != itr+1 || !f && ans[itr] < tmp[itr]) break;
				f |= ans[itr] > tmp[itr];
			}
			if(f) ans = tmp;
		}while(next_permutation(ALL(t)));
		scanf("%d%d", &p, &q); p--;
		if(ans[0] == 'Z') puts("impossible");
		else puts(ans.substr(p, q-p).c_str());
	}
}

Measured memory_bytes: 1344
import java.util.*

fun main(args: Array<String>) {


    var sc = Scanner(System.`in`)


    val n = sc.nextInt()
    val w = sc.nextInt()

    var weights = IntArray(n + 1)
    var values = IntArray(n+1)

    for(i in 1..n){
        values[i] = sc.nextInt()
        weights[i] = sc.nextInt()
    }

    var dp = Array(n+1){LongArray(w + 1)}
    for(_w in 1..w){
        dp[0][_w] = 0
    }

    for(i in 1..n) {
        for (_w in 1..w) {
            if(_w - weights[i] < 0){
                dp[i][_w] = dp[i-1][_w]
            }
            else {
                dp[i][_w] = Math.max(dp[i - 1][_w], dp[i - 1][_w - weights[i]] + values[i])
            }
        }

    }
    println(dp[n][w])
}




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

int main() {
  int h,n;
  cin >> h>>n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) {
    h-=a[i];
    if (h<=0) {
        cout << "Yes" << endl;
        return 0;
    }
  }  
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    int N, x;
    cin >> N >> x;
    vector<int> as(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> as[i];
    }

    sort(as.begin(), as.end());
    int acc = 0;
    int sum = 0;
    for (int i=0; i<N; ++i)
    {
        int a = as[i];
        sum += a;
        if (i==N-1) {
            if (sum == x) {
                ++acc;
            }
        }else if (sum <= x)
        {
            ++acc;
        }
        else
        {
            break;
        }
    }

    cout << acc << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;

int main() {

	int n, k;
	cin >> n >> k;
	vector<int> a(n, 0);
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int temp;
			cin >> temp;
			a[temp-1] = 1;
		}
	}
	int cnt = 0;
	for (auto e : a) {
		if (e == 0) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3636
package main

import (
	// "bufio"
	"fmt"
	// "os"
	// "strconv"
	"math"
)

type height struct {
	human int
	step  int
}

func (h height) Sum() int {
	return h.human + h.step
}

func main() {
	// var N int
	// fmt.Scan(&N)

	// A := make([]height, N)

	// for i := 0; i < N; i++ {
	// 	fmt.Scan(&A[i].human)
	// }

	// // scanner := bufio.NewScanner(os.Stdin)
	// // for i := 0; i < N && scanner.Scan(); i++ {
	// // 	A[i].human, _ = strconv.Atoi(scanner.Text())
	// // }
	// sum, tmp := 0, 0
	// for i := 0; i < N-1; i++ {
	// 	if A[i+1].human >= A[i].Sum() {
	// 		continue
	// 	}
	// 	tmp = A[i].Sum() - A[i+1].human
	// 	A[i+1].step = tmp
	// 	sum += tmp
	// }

	// fmt.Println(sum)

	var N int
	fmt.Scan(&N)
	human := make([]int, N)
	// step := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&human[i])
	}
	sum := 0
	var Max int
	for i := 0; i < N; i++ {
		Max = int(math.Max(float64(human[i]), float64(Max)))
		sum += Max - human[i]
	}
	fmt.Println(sum)

}


Measured memory_bytes: 6484
#include<bits/stdc++.h>
using namespace std;
#define re register
int f[410][1010],g[410][1010],a[410],b[410],fac[410],ifac[410],ei[410][1010],ee[410][1010];
const int mod=998244353;
int ex(re int a,re int b)
{
	re int ans=1;
	for(;b;b>>=1,a=(long long)a*a%mod)if(b&1)ans=(long long)ans*a%mod;
	return ans;
}
int main()
{
	re int n,a1=0,b1=0,x,ans=0;
	scanf("%d",&n);
	for(re int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	f[0][0]=fac[0]=1;
	for(re int i=1;i<=400;i++)fac[i]=(long long)fac[i-1]*i%mod;
	ifac[400]=ex(fac[400],mod-2);
	for(re int i=400;i;i--)ifac[i-1]=(long long)ifac[i]*i%mod;
	for(re int i=1;i<=n;i++)
	{
		for(re int j=a1;j>=0;j--)
			for(re int k=b1;k>=0;k--)if(f[j][k])
				for(re int i1=0,kl=1;i1<b[i];i1++,kl=(long long)kl*a[i]%mod)
					f[j+a[i]][k+i1]=(f[j+a[i]][k+i1]+(long long)(mod-f[j][k])*ifac[i1]%mod*kl)%mod;
		a1+=a[i];b1+=b[i];
	}
	for(re int i=1;i<=400;i++)
	{
		x=ex(i,mod-2);ei[i][0]=ee[i][0]=1;
		for(re int j=1;j<=401;j++)ei[i][j]=(long long)ei[i][j-1]*x%mod;
		for(re int j=1;j<=400;j++)ee[i][j]=(long long)ee[i][j-1]*i%mod;
	}//printf("**%d %d\n",a1,b1);
	for(re int i=1;i<=n;i++)
	{
		memcpy(g,f,sizeof(g));
		for(re int j=0;j<=a1-a[i];j++)
			for(re int k=0;k<=b1-b[i];k++)if(g[j][k])
			{
				for(re int i1=0,kl=1;i1<b[i];i1++,kl=(long long)kl*a[i]%mod)
					g[j+a[i]][k+i1]=(g[j+a[i]][k+i1]+(long long)g[j][k]*ifac[i1]%mod*kl)%mod;
				ans=(ans+(long long)g[j][k]*ifac[b[i]-1]%mod*fac[k+b[i]]%mod*ee[a[i]][b[i]]%mod*ei[j+a[i]][k+b[i]+1]%mod
				*a1)%mod;
			}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 6656
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N; cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	double out = 0;
	REP(i, N) {
		out += 1 / (double)A[i];
	}
	printf("%.10lf\n", 1 / out);





	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll n,m;
int dp[maxn];
int a[10][10];
int main() {
	
	cin>>n;
	int cnt = 0;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i==j&&i<=n) a[i][j]++;
			if((j*10+i)<=n) a[i][j]++;
			for(int l=0;l<=9;l++){
				int num = j*100+l*10+i;
				if(num<=n) a[i][j]++;
				else break;
			}
			for(int l=0;l<=99;l++){
				int num = j*1000+l*10+i;
				if(num<=n) a[i][j]++;
				else break;
			}
			for(int l=0;l<=999;l++){
				int num = j*10000+l*10+i;
				if(num<=n) a[i][j]++;
				else break;
			}
			for(int l=0;l<=9999;l++){
				int num = j*100000+l*10+i;
				if(num<=n) a[i][j]++;
				else break;
			}
		}
	}
	for(int i=1;i<=9;i++){
		dp[i] = dp[i-1]+a[i][i];
	}
		
	for(int i=10;i<=n;i++){
		if(i%10==0){
			dp[i] = dp[i-1];
			continue;
		}
		int x = i%10,y;
		int t = i;
		while(t){
			y = t%10;
			t/=10;
		}
		dp[i] = dp[i-1]+a[y][x];

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

Measured memory_bytes: 1024
/**
 *   @FileName	b.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.14 21:08:00
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int x,y;cin >> x >> y;
    if (y - 2 * x >= 0 && (y - 2 * x) % 2 == 0 && 4 * x - y >= 0 && (4 * x - y) % 2 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

char c[4];

int main() {
  char cc = getchar();
  while (cc != 'R' && cc != 'S') cc = getchar();
  c[1] = cc;
  c[2] = getchar();
  c[3] = getchar();
  int ans = 0;
  int cnt = 0;
  for (int i = 1; i <= 3; ++i) {
    if (c[i] == 'R') ++cnt;
    else cnt = 0;
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3756
N = int(input())
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))

ans = 0
for i in range(N):
    a0 = min(A[i], B[i])
    B[i] -= a0
    A[i] -= a0

    a1 = min(A[i+1], B[i])
    B[i] -= a1
    A[i+1] -= a1

    ans += (a0 + a1)

print(ans)


Measured memory_bytes: 85596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

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

	if(N % 2 == 1){
		for(int i=0; i<M; i++){
			cout << i+1 << " " << N-i << endl;
		}
		return 0;
	}

	//以下Nが偶数の場合 
	//b-a==N/2にならないように途中で1ずらして表示　例(N, M) = (6,2)で影響
	//あるいは 前回のa,bの差と 今回のa,bの差の合計がNにならないように途中で1ずらして表示 例(N, M) = (8, 3)で影響
	int tmp = 0;
	for(int i=0; i<M; i++){
		if(tmp==0 &&  (N-i)-(i+1) == N/2) tmp++;
		if(tmp==0 && (N-i+1)-(i+1-1) +(N-i)-(i+1) == N) tmp++;
		cout << i+1 << " " << N-i-tmp << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
//Created by Aminul on 7/25/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = in.nextInt();
        long amount = 1000, stocks = 0, res = 1000, lastPrice = 500;

        for (int i = 0; i < n; i++) {
            long x = in.nextInt();
            if(x == lastPrice) {
                continue;
            }
            else if(x > lastPrice) {
                amount += (x * stocks);
                res = max(res, amount);
                stocks = amount / x;
                amount %= x;
            } else {
                amount += (lastPrice * stocks);
                stocks = amount / x;
                amount %= x;
            }
            lastPrice = x;
        }

        pw.println(res);
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 27220
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    string s;
    int n;
    cin>>n;
    map<string,ll>mp;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    map<string,ll>::iterator it=mp.begin();
    for(;it!=mp.end();it++)
    {
        ll x =it->second;
        x--;
        ans+=(x*(x+1))/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
N = int(input())
cordinate = [list(map(int, input().split())) for i in range(N)]

for i in range(0, 101):
    for j in range(0, 101):
        H = -1
        check = 0
        zero_height = []
        for k in cordinate:
            if k[2] == 0:
                zero_height.append(k)
                continue
            if H == -1:
                check = 1
                H = k[2] + abs(k[0] - i) + abs(k[1] - j)
            else:
                tmp = k[2] + abs(k[0] - i) + abs(k[1] - j)
                if H == tmp:
                    check = 1
                    continue
                else:
                    check = -1
                    break
        if check == 1:
            for x in zero_height:
                if H > abs(x[0] - i) + abs(x[1] - j):
                    check = -1
                    break
            if check == 1:
                print(i, j , H)
                exit()

Measured memory_bytes: 3064
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;




vi e[220];
int two[220];
int ansl[220][220];


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

  int n;
  cin >> n;
  rep(i,n) {
    string s;
    cin >> s;
    rep(j,n){
      if(s[j] == '1'){
        e[i].push_back(j);
      }
    }
  }

  stack<pii> st;
  st.push(mp(0,1));

  bool flag = true;

  while(!st.empty()&&flag){
    pii tmp = st.top();
    st.pop();
    int nextc = 0;
    if(tmp.S == 1){nextc = 2;}
    else{nextc = 1;}

    if(two[tmp.F] != 0){
      if(two[tmp.F] != tmp.S){
      flag = false;}}
    else{
      two[tmp.F] = tmp.S;
      for(const auto& t : e[tmp.F]){
        if(t == tmp.F)continue;
        st.push(mp(t,nextc));
      }
    }

  }
  
  if(!flag) {
    prints(-1);
    return 0;
  }



  queue<pii> q;


  rep(i,n){

    q.push(mp(i,1));
    while(!q.empty()&&flag){
      pii tmp = q.front();
      q.pop();
      if(ansl[i][tmp.F]!=0) {continue;}
      else{
      ansl[i][tmp.F] = tmp.S;
      for(const auto& t : e[tmp.F]){
        q.push(mp(t,tmp.S+1));
      }
    }}
  }

  int ans = 0;
  rep(i,n)rep(j,n) {ans = max(ans,ansl[i][j]);}
  prints(ans);

  return 0;

}


Measured memory_bytes: 768
n,p=map(int,input().split())

item=[]
for i in range(n):
    b=int(input())
    item.append(b)
    
item.sort()
temp=[]

for i in range(n-p+1):
    a=item[i+p-1]-item[i]
    temp.append(a)
    
temp.sort()
print(min(temp))

Measured memory_bytes: 11416
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,a[100000];
  cin>>N;
  long total=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    total+=a[i];
  }
  double avg=(double)total/N;
  double min=100;
  int ans;
  for(int i=N-1;i>=0;i--){
  	if(abs(a[i]-avg)<=min){
    	ans=i;
      	min=abs(a[i]-avg);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, K;
vector<vector<int>> G;
int ans = 0;
int f(int p) {
	if (G[p].empty()) return 1;
	int r = 1;
	for (int x : G[p]) {
		int y = f(x);
		if (y == K) ++ ans;
		else r = max(r, y + 1);
	}
	return r;
}
int main() {
	cin >> N >> K;
	vector<int> a(N);
	for (int& x : a) { cin >> x; -- x; }
	int r = 0;
	if (a[0] != 0) ++ ans;
	if (K == 1) {
		for (int i = 1; i < N; ++ i) if (a[i] != 0) ++ ans;
	} else {
		G.resize(N);
		for (int i = 1; i < N; ++ i) G[a[i]].push_back(i);
		for (int x : G[0]) f(x);
	}
	cout << ans << endl;
}


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

int main()
{
  int n;
  cin>>n;
  vector<int>dp(n,0);
  vector<int>step(n,0);
  for(int i=0;i<n;i++)
  {
    cin>>step[i];
  }
  dp[1] = abs(step[1]-step[0]);
  for(int i=2;i<n;i++)
  {
    dp[i] = min((dp[i-1]+abs(step[i]-step[i-1])),(dp[i-2]+abs(step[i]-step[i-2])));
  }
  cout<<dp[n-1];
  return 0;
}
    


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
	   	Main g=new Main();
	   	g.main();
	   	out.close();
	}

	
	
	//Main
	void main() {
		
		int n=inp.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++) a[i]=inp.nextLong();
		long gg=0;
		long max=a[0];
		for(int i=1;i<n;i++) {
			if(a[i]<max) {
				gg+=max-a[i];
			}else {
				max=a[i];
			}
		}
		System.out.println(gg);
	}
    
    
		
}


Measured memory_bytes: 63316
using System;

class Program {
    static int Main(string[] args) {
        string v = Console.ReadLine();
        int x = int.Parse(v.Split(' ')[0]);
        int y = int.Parse(v.Split(' ')[1]);
        Console.WriteLine(string.Format("{0} {1}", x * y, 2 * (x + y)));
        return 0;
    }
}

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

constexpr int MAX_N = 1e4;
int dp[MAX_N+10];
int A[9];
int main() {
  int N, M;
  ins(N, M);

  rep(i, M) {
    cin >> A[i];
    --A[i];
  }
  sort(A, A+M);
  reverse(A, A+M);
  // i本ちょうどでdp[i]桁作れる

  int cost[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  rep(i, N+10) dp[i] = -1;
  dp[0] = 0;

  rep(i, N) {
    rep(j, M) {
      dp[i+cost[A[j]]] = max(dp[i+cost[A[j]]], dp[i] + 1);
    }
  }

  int n = N;
  rep(i, dp[N]) {
    rep(j, M) {
      if (n-cost[A[j]] >= 0 && dp[n-cost[A[j]]] + 1 == dp[n]) {
        n -= cost[A[j]];
        cout << A[j]+1;
        break;
      }
    }
    if (n == 0)
      break;
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
str = "abcdefghijklmnopqrstuvwxyz"
def dfs(s,mx):
    if len(s) == N:
        print(s)
    else:
        for c in str[:mx+1]:
            if c == str[mx]: dfs(s+c, mx+1)
            else: dfs(s+c, mx)
dfs("", 0)

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

struct Point {
  double X, Y;
  Point(double x, double y) :X(x), Y(y) {}
};

double cross(Point p0, Point p1, Point p2) {
  Point a = Point(p1.X - p0.X, p1.Y - p0.Y);
  Point b = Point(p2.X - p0.X, p2.Y - p0.Y);
  return a.X * b.Y - a.Y * b.X;
}

bool is_contain(Point a, Point b, Point c, Point p) {
  double c1 = cross(a, b, p);
  double c2 = cross(b, c, p);
  double c3 = cross(c, a, p);
  if (c1 > 0 && c2 > 0 && c3 > 0) return true;
  if (c1 < 0 && c2 < 0 && c3 < 0) return true;
  return false;
}

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) {
    Point a = Point(x1, y1);
    Point b = Point(x2, y2);
    Point c = Point(x3, y3);
    Point p = Point(xp, yp);
    if (is_contain(a, b, c, p)) puts("YES");
    else puts("NO");
  }
}


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

int main()
{
    string a,b;
    cin>>a>>b;
    int n=a.size(),sum=0;
    for(int i =0;i<=n;i++){
        if(a[i] != b[i]){
            sum++;
            }
        }
        cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3908
#include<cstdio>
#include<cmath>
int n,s[3][105],x,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
	  for(int j=1;j<=n;j++)
	  {
	  	scanf("%d",&x);
		s[i][j]=s[i][j-1]+x;
	  }
	for(int i=1;i<=n;i++)
	  ans=fmax(ans,s[1][i]+s[2][n]-s[2][i-1]);
	printf("%d\n",ans);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] dishes = new int[5];
        for (int i = 0; i < dishes.length; i++) {
            dishes[i] = sc.nextInt();
        }

        int min = Integer.MAX_VALUE;
        int[] tmpOrder = new int[dishes.length];

        for (int a = 0; a < dishes.length; a++) {
            tmpOrder[0] = dishes[a];

            for (int b = 0; b < dishes.length; b++) {
                tmpOrder[1] = dishes[b];

                for (int c = 0; c < dishes.length; c++) {

                    tmpOrder[2] = dishes[c];

                    for (int d = 0; d < dishes.length; d++) {

                        tmpOrder[3] = dishes[d];

                        for (int e = 0; e < dishes.length; e++) {
                            tmpOrder[4] = dishes[e];

                            // 同じ料理があったらスキップ
                            boolean exist = search(new int[]{a, b, c, d, e});
                            if (exist) {
                                continue;
                            } else {

                                int tmpTime = time(tmpOrder);
                                if (min > tmpTime) {
                                    min = tmpTime;
                                }
                            }
                        }
                    }
                }
            }
        }

        System.out.println(min);

    }

    private static boolean search(int[] array) {

        boolean exist = false;
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length; j++) {

                if (i == j) continue;

                if (array[i] == array[j]) {
                    exist = true;
                    break;
                }
            }
        }

        return exist;
    }

    private static int time(int[] dishes) {
        int time = 0;
        for (int i = 0; i < dishes.length; i++) {
            time += dishes[i];

            if (time % 10 == 0) continue;

            if (!(i == dishes.length -1)) {
                time += (10 - time % 10);
            }
        }

        return time;
    }
}


Measured memory_bytes: 24916
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EasyLinearProgramming solver = new EasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class EasyLinearProgramming {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int k = in.nextInt();

            int result = 0;
            if (a > 0) {
                int max = Math.min(a, k);
                k -= max;
                result += max;
            }
            if (b > 0) {
                int max = Math.min(b, k);
                k -= max;
            }
            if (c > 0) {
                int max = Math.min(c, k);
                k -= max;
                result -= max;
            }
            out.append(String.valueOf(result));
        }

    }
}



Measured memory_bytes: 35792
#include <iostream>
#include <stdio.h>
#include <vector>
#include <unordered_map>

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

    std::vector<int> A(N);
    for (int i = 0 ; i < N; i++) {
        scanf("%d", &A[i]);
    }

    std::unordered_map<int, int> remainder_counts;
    int cum_remainder = 0;
    for (int i = 0; i < N; i++) {
        cum_remainder = (cum_remainder + A[i]) % M;
        remainder_counts[cum_remainder] += 1;
    }
    remainder_counts[0] += 1;

    long combinations = 0;
    for (auto kv : remainder_counts) {
        long count = kv.second;
        combinations += count * (count - 1) / 2;
    }
    std::cout << combinations << std::endl;
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
#define INF 1000000009
using namespace std;

int n,m,s1,s2,num[710];
bool g[710][710],vis[710],dp[2010],k[2010];

bool dfs(int u,int mask)
{
	if(vis[u]){
		if(num[u]!=mask){
			return false;
		}
		return true;
	}
	vis[u]=true;
	num[u]=mask;
	if(mask) s1++;
	else s2++;
	for(int i=1;i<=n;i++) if(u!=i&&!g[u][i]){
		if(!dfs(i,mask^1)) return false;
	}
	return true;
}

int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		g[x][y]=1;
		g[y][x]=1;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++) if(!vis[i]){
		s1=0;s2=0;
		if(!dfs(i,0)){
			cout<<-1<<endl;
			return 0;
		}
		for(int j=0;j<=n;j++){
			k[j+s1]|=dp[j];
			k[j+s2]|=dp[j];
		}
		for(int j=0;j<=n;j++) dp[j]=k[j],k[j]=0;
	}
	int x=INF;
	for(int i=0;i<=n;i++) if(dp[i]){
		x=min(x,i*(i-1)/2+(n-i)*(n-i-1)/2);
		//cout<<x<<" "<<i<<endl;
	}
	cout<<x<<endl; 
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int a, b, c;
    std::cin>>a>>b>>c;

    std::string ans = "NO";
    for(int i = 1;i <= b;i++){
        if((a * i) % b == c){
            ans = "YES";
            break;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

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

int main(void){
  int ansnum[31];
  map<int, int> team;
  memset(ansnum, 0, sizeof(ansnum));
  int n,p;

  while(cin >> n){
    cin.ignore();
    cin >> p;
    if(n==0 && p==0) break;
    team[n] = p;
    ansnum[p]++;
  }

  while(cin >> n){
    int ret=0;
    p = team[n];
    for(int i=30;i>p;i--){
      if(ansnum[i] != 0) ret++;
    }
    cout << ret+1 << endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int n,m,q;
vector<int> a,b,c,d;
int ans=0;
void dfs(vector<int> A){
  if(A.size()==n+1){
    int score=0;
    rep(i,q){
    if(A[b[i]]-A[a[i]]==c[i])score+=d[i];
    }
    ans=max(score,ans);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=m){
    dfs(A);
    A.back()++;
  }
}
int main(){
  cin>>n>>m>>q;
  a=b=c=d=vector<int>(q);
  rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
  dfs(vector<int> (1,1));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3588
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ankit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int r = in.nextInt();
            int x = in.nextInt();
            int y = in.nextInt();
            if ((x * 10 + y) % 4 == 0) out.println("YES");
            else out.println("NO");
        }

    }
}



Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int ll
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
        while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
        return x * f ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

using namespace std ;

#define N 100010

int m = read(), n = read();
int a[N], f[N];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	for(int i = 1; i <= n; ++i) a[i] = read();
	sort(a + 1, a + n + 1);
	if(m >= n) return puts("0"), 0;
	int cnt = 0;
	for(int i = 2; i <= n; ++i) {
		f[++cnt] = a[i] - a[i - 1];
	}
	sort(f + 1, f + n + 1, cmp);
	ll ans = 0;
	for(int i = m; i <= n; ++i) ans += f[i];
	printf("%lld\n", ans);
} 


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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	int n;
	cin>>n;
	if(n>=30){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

#define max(a,b) (a > b ? a : b)

int main(void){
    int n;
    cin >> n;
    int grade[8] = {0};
    int rank,count=0;
    int strong_human = 0;
    for(int i=0;i<n;i++){
        int box;
        cin >> box;
        rank = box / 400;
        if(rank > 7)strong_human++;
        else grade[rank] = 1;
    }
    for(int i=0;i<8;i++){
        if(grade[i])count++;
    }
    cout << max(count,1) << " " << count + strong_human << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

H,W,M=map(int,input().split())
AB=[tuple(map(int,input().split()))for i in range(M)]
AB=[(a-1,b-1)for a,b in AB]
st=set(AB)

Wc=defaultdict(lambda :0)
Hc=defaultdict(lambda :0)
for a,b in AB:
    Hc[a]+=1
    Wc[b]+=1

Hm=max(Hc.values())
hhh=list(Hc.keys())
www=list(Wc.keys())
for i in hhh:
    if Hc[i]!=Hm:
        Hc.pop(i)
Wm=max(Wc.values())
for j in www:
    if Wc[j]!=Wm:
        Wc.pop(j)

ans=0
count=0
for i in Hc.keys():
    for j in Wc.keys():
        add = -1 if (i,j) in st else 0
        tmp= Hc[i] + Wc[j] + add
        ans=max(ans,tmp)
        if count>300000:
            break
        count+=1

print(ans)


Measured memory_bytes: 210420
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    int n,a,b;
    cin >> n >> a>>b;
    vector<int>p(n);
    rep(i,n) cin >> p[i];
    int x=0,y=0,z=0;
    rep(i,n){
        if(p[i]<=a) x++;
        else if(p[i]>=b+1) z++;
        else y++;
    }
    cout << min(x,min(y,z)) <<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

signed main(){
	IOS
	int n;cin>>n;
	vi DP(3,0),DP_new(3,0);
	forn(i,n){
		int a,b,c;cin>>a>>b>>c;
		DP_new[0]=a+max(DP[1],DP[2]);
		DP_new[1]=b+max(DP[0],DP[2]);
		DP_new[2]=c+max(DP[1],DP[0]);
		swap(DP,DP_new);
	}
	cout<<*max_element(all(DP));
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 26.11.2019 17:52:04       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  int low = 1, high = n;
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
      b[i] = (a[i] >= mid);
    }
    vector<int> seq(1, 1);
    for (int i = 1; i < n; i++) {
      if (b[i] != b[i - 1]) {
        seq.push_back(1);
      } else {
        seq.back() += 1;
      }
    }
    seq[0] += n;
    seq.back() += n;
    int sz = (int) seq.size();
    vector<int> what(sz);
    for (int i = 0; i < sz; i++) {
      what[i] = (b[0] + i) % 2;
    }
    vector<set<pair<int, int>>> inner(2);
    vector<int> delta(2, 0);
    for (int i = 0; i < sz; i++) {
      inner[what[i]].emplace(seq[i], i);
    }
    vector<int> pr(sz);
    vector<int> ne(sz);
    for (int i = 0; i < sz; i++) {
      pr[i] = i - 1;
      ne[i] = i + 1;
    }
    auto Remove = [&](int x) {
      if (ne[x] < sz) {
        pr[ne[x]] = pr[x];
      }
      ne[pr[x]] = ne[x];
    };
    for (char c : s) {
      int u = (c == 'm' ? 0 : 1);
      delta[u] += 1;
      delta[u ^ 1] -= 1;
      while (!inner[u ^ 1].empty() && inner[u ^ 1].begin()->first + delta[u ^ 1] == 0) {
        int me = inner[u ^ 1].begin()->second;
        inner[u ^ 1].erase(inner[u ^ 1].begin());
        inner[u].erase({seq[pr[me]], pr[me]});
        inner[u].erase({seq[ne[me]], ne[me]});
        seq[pr[me]] += seq[ne[me]] + delta[u];
        inner[u].emplace(seq[pr[me]], pr[me]);
        Remove(me);
        Remove(ne[me]);
      }
      if (what[0] == u) {
        inner[u].erase({seq[0], 0});
        seq[0] -= 1;
        inner[u].emplace(seq[0], 0);
      }
    }
    int have = 0;
    int winner = -1;
    for (int i = 0; i < sz; i = ne[i]) {
      have += seq[i] + delta[what[i]];
      if (have >= n + 1) {
        winner = what[i];
        break;
      }
    }
    if (winner == 1) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << '\n';
  return 0;
}


Measured memory_bytes: 4296
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<deque>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
ll dp[4010][11];
int main() {
	int N;
	char s[4001];
	scanf("%d", &N);
	scanf("%s", s);
	dp[0][0] = 1;
	rep(i, 0, N) {
		rep(i2, 0, 11) {
			dp[i + 1][i2] = dp[i][i2];
		}
		if (s[i] == 'R') {
			dp[i + 1][1]++;
			dp[i + 1][5] += dp[i][2];
			dp[i + 1][7] += dp[i][3];
			dp[i + 1][10] += dp[i][8] + dp[i][9];
		}
		if (s[i] == 'G') {
			dp[i + 1][2]++;
			dp[i + 1][4] += dp[i][1];
			dp[i + 1][9] += dp[i][3];
			dp[i + 1][10] += dp[i][6] + dp[i][7];
		}
		if (s[i] == 'B') {
			dp[i + 1][3]++;
			dp[i + 1][6] += dp[i][1];
			dp[i + 1][8] += dp[i][2];
			dp[i + 1][10] += dp[i][4] + dp[i][5];
		}
		//printf("%lld\n", dp[i + 1][10]);
	}
	ll C = 0;
	rep(i, 0, N) {
		rep(k, 1, N) {
			if (i + k * 2 >= N)break;
			if (s[i] != s[i + k] && s[i] != s[i + 2 * k] && s[i + k] != s[i + 2 * k])C++;
		}
	}
	printf("%lld\n", dp[N][10] - C);
	return 0;
}

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

namespace C_ABC156
{
    class MainClass
    {

        static int[] n, x;

        public static void Main(string[] args)
        {
            n = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            x = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            var xlst = x.ToList();
            xlst.Sort();

            var anslst = new List<long>();
            for (int i = xlst[0]; i <= xlst.Last(); i++)
            {
                long tmpans = 0;
                for (int j = 0; j < xlst.Count(); j++)
                {
                    tmpans += (long)Pow(Abs(i-xlst[j]),2);
                }
                anslst.Add(tmpans);
            }
            anslst.Sort();
            WriteLine(anslst.First());


        }
    }
}


Measured memory_bytes: 13524