akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		for(int m,n,x,a[][];(n=s.nextInt())>0;){
			m=s.nextInt();
			x=s.nextInt();
			a=new int[n][m];
			Deque<int[]>q=new ArrayDeque<int[]>();
			for(int i=0;i<x;++i){
				int u=s.nextInt()-1,v=s.nextInt()-1;
				a[u][v]=1;
				q.add(new int[]{u,v,1});
			}
			int[][]dn={{-1,-1,-1,0,0,1},{-1,0,0,1,1,1}};
			int[][]dm={{-1,0,1,-1,1,0},{0,-1,1,-1,0,1}};
			
			while(!q.isEmpty()){
				int[]t=q.poll();
				for(int i=0;i<6;++i){
					int u=t[0]+dn[t[1]%2][i],v=t[1]+dm[t[1]%2][i];
					if(0<=u&&u<n&&0<=v&&v<m&&a[u][v]<1){
						q.add(new int[]{u,v,a[u][v]=t[2]+1});
					}
				}
			}
			int r=0;
			for(x=s.nextInt();x-->0;){
				int u=s.nextInt()-1,v=s.nextInt()-1;
				if(a[u][v]>1){
					int[][] tmp = new int[n][];
					for(int i=0;i<n;++i)
						tmp[i]=Arrays.copyOf(a[i],m);
					tmp[u][v]=1;
					q.add(new int[]{u,v,1});
					int c=1;
					while(!q.isEmpty()){
						int[]t=q.poll();
						for(int i=0;i<6;++i){
							int u1=t[0]+dn[t[1]%2][i],v1=t[1]+dm[t[1]%2][i];
							if(0<=u1&&u1<n&&0<=v1&&v1<m&&tmp[u1][v1]>t[2]+1){
								++c;
								q.add(new int[]{u1,v1,tmp[u1][v1]=t[2]+1});
							}
						}
					}
					r=r>c?r:c;
				}
			}
			System.out.println(r);
		}
	}
}

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

int main()
{
	int n;

	cin >> n;

	while (n > 0) {
		vector<int> b(n);

		int m = 0, t = 0;
		for (int i = 0; i < n; i++) {
			cin >> b[i];
			m += b[i];
		}
		
		for (int i = 1; i < 1500; i++) {
			if (i * (i + 1) / 2 == m) {
				t = i;
				break;
			}
		}

		if (t == 0)
			cout << -1 << endl;
		else {
			int ct = 0;

			while (ct < 10000) {

				int k = 1;
				bool f = 0;
				vector<int> a = b;
				b.clear();
				for (int i = 0; i < a.size(); i++) {
					if (a[i] != 1)
						b.push_back(a[i] - 1);
					if (a[i] != i + 1)
						f = 1;
				}
				if (!f)
					break;

				ct++;
				b.push_back(a.size());
			}

			if (ct >= 10000)
				cout << -1 << endl;
			else
				cout << ct << endl;
		}

		cin >> n;
	}

	return 0;
}



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

int main() {
	int A, B, K; cin >> A >> B >> K;
	int ans=min(A, B), num=0;
	while(true){
	    if(A%ans<1 && B%ans<1) ++num;
	    if(num==K){
	        cout << ans << endl;
	        return 0;
	    }
	    --ans;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        HashMap<Integer, Integer> h = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            if (h.containsKey(a)) {
                h.put(a, h.get(a) + 1);
            } else {
                h.put(a, 1);
            }
        }
        sc.close();
        long ans = h.values().stream().filter(i -> i % 2 == 1).count();
        System.out.println(ans);
    }
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m, q;
    string s[2000];
    cin >> n >> m >> q;
    for(int i=0;i<n;++i) cin >> s[i];
    static int vsum[2001][2001];
    static int eyoko[2001][2001], etate[2001][2001];
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            vsum[i][j] = vsum[i][j-1] + vsum[i-1][j] - vsum[i-1][j-1] + (s[i-1][j-1] == '1');
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<m;++j){
            eyoko[i][j] = eyoko[i][j-1];
            if(s[i-1][j-1] == '1' && s[i-1][j] == '1') eyoko[i][j] += 1;
        }
        for(int j=1;j<m;++j) eyoko[i][j] += eyoko[i-1][j];
    }
    for(int j=1;j<=m;++j){
        for(int i=1;i<n;++i){
            etate[i][j] = etate[i-1][j];
            if(s[i-1][j-1] == '1' && s[i][j-1] == '1') etate[i][j] += 1;
        }
        for(int i=1;i<n;++i) etate[i][j] += etate[i][j-1];
    }

    for(int i=0;i<q;++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int v = vsum[x2][y2] - vsum[x1-1][y2] - vsum[x2][y1-1] + vsum[x1-1][y1-1];
        int ey = (eyoko[x2][y2-1] - eyoko[x2][y1-1]) - (eyoko[x1-1][y2-1] - eyoko[x1-1][y1-1]);
        int et = (etate[x2-1][y2] - etate[x1-1][y2]) - (etate[x2-1][y1-1] - etate[x1-1][y1-1]);
        cout << v - ey - et << endl;
    }
    return 0;
}

Measured memory_bytes: 52992
def function(num):
    if num % 2 == 0:
        return int(num/2)
    else:
        return int((3*num) + 1)

num = int(input())

a = []
a.append(num)
while True:
    an = function(a[-1])
    for i in range(len(a)):

        if a[i] == an:
            a.append(an)
            print('{}'.format(len(a)))
            exit()

    a.append(an)

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

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

int main()
{
	queue<int> S[3];
	rep(i, 3)
	{
		string s;
		cin >> s;
		rep(j, s.size())
		{
			if (s[j] == 'a')
			{
				S[i].push(0);
			}
			else if(s[j] == 'b')
			{
				S[i].push(1);
			}
			else if (s[j] == 'c')
			{
				S[i].push(2);
			}
		}
	}

	int winner;
	int turn = 0;
	while (true)
	{
		if (S[turn].empty())
		{
			winner = turn;
			break;
		}

		int turn_t = S[turn].front();
		S[turn].pop();
		turn = turn_t;
	}

	cout << static_cast<char>('A' + winner) << endl;

	return 0;
}

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

typedef long long ll;
const int N = 2e5;

int n,k;
map<int,int> ada;
int li[N+5];
int ps[N+5];

int main(){
	scanf("%d%d",&n,&k);
	ll ans = 0ll;
	ada[0] = 1;
	for(int i=1;i<=n;i++){
		if(i>=k){
			ada[ps[i-k]]--;
//			cout << "BUANG " << ps[i-k-1] << endl;
		}
		scanf("%d",&li[i]);
		li[i]--;
		li[i]%=k;
		ps[i] = (ps[i-1] + li[i])%k;
		ans += (ll) ada[ps[i]];
		ada[ps[i]]++;
//		cout << ">>> " << ps[i] << " " <<  ans << endl;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11136
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N;
LL K;
VI A, B;

void input() {
	cin >> N >> K;
	A.resize(N);
	B.resize(N);
	for (int n = 0; n < N; n++)
	{
		cin >> A[n] >> B[n];
	}
}

void daminput() {
}

void solve() {
	vector<PLL> querys;
	for (int n = 0; n < N; n++)
	{
		querys.push_back(PLL(A[n], B[n]));
	}
	sort(querys.begin(), querys.end(), [](PLL a, PLL b) {
		return a.first < b.first;
	});
	for (int n = 1; n < N; n++)
	{
		querys[n].second += querys[n - 1].second;
	}
	int s = -1, e = N;
	while (e - s > 1) {
		int m = (e + s) / 2;
		if (querys[m].second < K)s = m;
		else e = m;
	}
	cout << querys[e].first << "\n";
}

Measured memory_bytes: 5712
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  string t = "CODEFESTIVAL2016";
  cin >> s;
  int c = 0;
  for (int i = 0; i < 16; i++) {
    if (s[i] != t[i]) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int a,b;
	cin >> a >> b;
	if (abs(a - b) % 2 == 1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int N;cin>>N;
  cout<<N*N*N<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#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 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 100005


int main(){

    ll n,ans = 0;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;

    REP(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll cnt = 0;//辺の数2以上である長さを持つ辺の個の個数
    for(auto itr:mp){
        if(itr.second >= 2){
            cnt++;
        }
    }
    ll maxi = -INF,sec_maxi = -INF;
    ll tmp = maxi*sec_maxi;
    ans = tmp;
    ll maxi_edge_num = 0;
    for(auto itr:mp){
        if(itr.second >= 2){
            maxi = max(maxi,itr.first);
            maxi_edge_num = itr.second;
        }
    }
    if(maxi_edge_num >= 4){
        ans = maxi*maxi;
    }else{
        for(auto itr:mp){
            if(itr.second >= 2 && itr.first < maxi){
                sec_maxi = max(sec_maxi,itr.first);
            }
        }
        ans = maxi * sec_maxi;
    }
    if(ans == tmp){
        ans = 0;
    }
    cout << ans << endl;

   

    return 0;
}


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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  long long int N,O;
  cin >> N;
  O = N*(N+1)*(N+2)/6;
  
  int u,v,U,V;
  for(int i=0;i<N-1;i++){
    cin >> u >> v;
    O = O - min(u,v)*(N-max(u,v)+1);
  }
    
  cout << O <<endl;
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3544
package main

import "fmt"

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

	for x := 0; x <= N; x++ {
		for y := 0; y <= N-x; y++ {
			z := N - x - y
			if x*10000+y*5000+z*1000 == Y {
				fmt.Println(x, y, z)
				return
			}
		}
	}

	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

#define MAX_N 55
ll C[MAX_N][MAX_N];
void make() {
  rep(i, MAX_N) {
    C[i][1] = i;
    C[i][i] = 1;
    C[0][i] = 1;
    C[i][0] = 1;
  }
  REP(i, 1, MAX_N) rep(j, i) {
    if(i-1 < 0 || j-1 < 0) continue;
    C[i][j] = C[i-1][j] + C[i-1][j-1];
  }
}
ll comb(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return C[n][r];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  make();
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> V(n);
  map<ll, int> mp;
  rep(i, n) {
    cin >> V[i];
    mp[V[i]]++;
  }
  ll prev;
  int cnt = 0;
  auto itr = mp.rbegin();
  while(cnt < a) {
    cnt += itr->second;
    prev = itr->first;
    itr++;
  }
  cnt -= mp[prev];
  int mn = a-cnt;
  int mx = min(b-cnt, mp[prev]);
  if(mp.rbegin()->first == prev) {
    cout << prev << "\n";
    ll ans = 0;
    for(int i=mn; i<=mx; i++) {
      ans += comb(mp[prev], i);
    }
     cout << ans << "\n";
  } else {
    itr = mp.rbegin();
    double ans = 0;
    while(itr->first != prev) {
      ans += (double)itr->first/a*itr->second;
      itr++;
    }
    ans += (double)prev/a*mn;
    cout << ans << "\n";
    cout << comb(mp[prev], mn) << "\n";
  }
  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b)	for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int N=2e5+5,inf=0x3f3f3f3f;
ll k,a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>k;
	a[0]=1;
	rep(i,1,k)	cin>>a[i];
	ll mx=2,mn=2;
	rrep(i,k,1)
	{
		ll p=(mn+a[i]-1)/a[i],q=mx/a[i];
		mn=p*a[i],mx=(q+1)*a[i]-1;
		
	}
	if(mn<=mx)
		cout<<mn<<' '<<mx<<endl;
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc121/tasks/abc121_b


N, M, C = gets.split.map(&:to_i)
Bs = gets.split.map(&:to_i)
Ass = Array.new(N) { gets.split.map(&:to_i) }

ans = N.times.count do |i|
  M.times.reduce(C) { |memo, j| memo + Ass[i][j] * Bs[j] } > 0
end

puts ans


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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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

    int n;
    while (cin >> n) {
        ivec a(n);
        cin >> a;

        ivec b(n + 1);
        i64 s = 0;
        forn(i, n) {
            b[a[i]]++;
            s++;
        }

        ivec bb;
        forn(i, n + 1) {
            if (b[i]) {
                bb.push_back(b[i]);
            }
        }

        sort(bb.rbegin(), bb.rend());

        cout << s << endl;
        i64 x = s;
        forr(i, 2, n + 1) {
            logv(bb);
            
            forn(j, bb.size()) {
                if (bb[j] <= x) {
                    break;
                }
                s -= bb[j] - x;
                bb[j] = x;
            }

            while (bb[0] > s / i) {
                i64 si = s / i;            
                forn(j, bb.size()) {
                    if (bb[j] <= si) {
                        break;
                    }
                    s -= bb[j] - si;
                    bb[j] = si;
                }
            }

            logs(s);
            x = s / i;
            cout << x << endl;
        }
    }
}


Measured memory_bytes: 4724
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int a,a3;
	scanf("%d",&a);
	a3=a+a*a+a*a*a;
	printf("%d\n",a3);
	return 0;
}

Measured memory_bytes: 1728
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

template<typename T> istream 
&operator>>(istream &a, vector<T> &v) { 
for (auto& x : v) a >> x; return a; }

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

const bool flag = 0;

void maincode() {
    string s;
    cin >> s;
    int cnt = 0;
    vector<ll> v;
    char pv = s[0];
    for (char c : s) {
        if (c == pv) {
            cnt++;
        } else {
            v.pb(cnt), cnt = 1;
        }
        pv = c;       
    }    
    v.pb(cnt);
    ll ans = 0;
    if (s[0] == '>') {
        ans = v[0]*(v[0]+1)/2;
        v.erase(v.begin());
    }
    for (int i = 0; i < sz(v); ++i) {
        ans += v[i]*(v[i]+1)/2;               
        if (i & 1) {
            ans -= v[i];
            continue;
        }     
        if (i+1 < sz(v) && v[i+1] > v[i]) 
            ans += v[i+1]-v[i];               
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long w, h, n;
  cin >> w >> h >> n;
  int xl=0, xh=w, yl=0, yh=h, x[n], y[n], a[n];
  rep(i,0,n) cin >> x[i] >> y[i] >> a[i];
  rep(i,0,n){
    if(a[i]==1){
      xl=max(xl, x[i]);
    }
    if(a[i]==2){
      xh=min(xh, x[i]);
    }
    if(a[i]==3){
      yl=max(yl, y[i]);
    }
    if(a[i]==4){
      yh=min(yh, y[i]);
    }
  }
  if(xh-xl>0 && yh-yl>0) co((xh-xl)*(yh-yl));
  else co(0);
  
  
  return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
ans = 0
N = getN()
list = getList()
bind = []
for i, x in enumerate(list):
    if x == i+1:
        bind.append(x)
p = 0
l = len(bind)
while p<l:
    ans += 1
    if p == l-1:
        p += 1
    elif bind[p] + 1 == bind[p+1]:
        p += 2
    else:
        p += 1


print(ans)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;
typedef vi poly;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=41;
ll f[N][N][N],ans;
int a[N][N],n;
char s[N][N];

int main(){
	read(n),n*=2;
	rep(i,1,n){
		scanf("%s",s[i]+1);
		rep(j,1,n)a[i][j]=s[i][j]-'0';
		f[i][i][i]=1;
	}
	per(l,n,2)rep(r,l,n)rep(p,l,r){
		rep(L,l+1,p)rep(R,p,r-1)
			if(f[L][p][R]){
				rep(x,l,L-1)rep(y,R+1,r)
					if(a[x][y]){
						//printf("%d %d %d  %d %d  %d %d\n",l,p,r,x,L,R,y);
						f[l][p][r]+=f[L][p][R]*f[l][x][L-1]*f[R+1][y][r];
					}
			}
		//printf("f[%d][%d][%d] = %lld\n",l,p,r,f[l][p][r]);
	}
	rep(i,2,n)
		if(a[1][i])ans+=f[2][i][n];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import math

N,D = map(int, input().split())
x = [[int(i) for i in input().split()] for j in range(N)]

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

ans = 0
for i in range(N):
    for j in range(i+1, N):
        d = 0
        for k in range(D):
            d += (x[i][k] - x[j][k])**2
        n = math.sqrt(d)
        if is_integer_num(n):
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll dp[110][101200];

int main() {
  ll n, w; cin >> n >> w;
  rep(i, 110) rep(j, 101200) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i, n) {
    ll a, b; cin >> a >> b;
    rep(j, 100100) {
      chmin(dp[i+1][j+b], dp[i][j] + a);
      chmin(dp[i+1][j], dp[i][j]);
    }
  }
  ll ans = 0;
  rep(i, 100100) if(dp[n][i] <= w) chmax(ans, i);
  cout << ans << endl;
}

Measured memory_bytes: 87168
/*
[agc039] D - Incenters
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

typedef complex<double> P;

const int MAX_N = 3000;
const P I = 1.0i;

int N, L;
int T[MAX_N];

P solve() {
    P ans;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double theta = M_PI * (T[i] + T[j]) / L;
            ans += exp(I * theta) * (double)(N + 2 * i - 2 * j);
        }
    }

    ans *= 6.0 / N / (N - 1) / (N - 2);

    return ans;
}

int main() {
    cin >> N >> L;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }

    P ans = solve();
    cout << setprecision(15) << real(ans) << " " << imag(ans) << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	static long MOD = (long) 1e9 + 7;

	public static void main(String[] args) {
		int n = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		sc.close();

		long[][] dp = new long[3][n];
		dp[0][0] = a[0];
		dp[1][0] = b[0];
		dp[2][0] = c[0];
		for (int i = 1; i < n; i++) {
			dp[0][i] = Math.max(dp[1][i - 1], dp[2][i - 1]) + a[i];
			dp[1][i] = Math.max(dp[0][i - 1], dp[2][i - 1]) + b[i];
			dp[2][i] = Math.max(dp[0][i - 1], dp[1][i - 1]) + c[i];
		}
		System.out.println(Math.max(dp[0][n - 1], Math.max(dp[1][n - 1], dp[2][n - 1])));
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static Integer[] arrayInteger(Scanner sc, int n) {
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 61100
s=input()
for i in range(len(s)-2):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    elif s[i]==s[i+2]:
        print(i+1,i+3)
        break
else:
    if len(s)==2 and s[0]==s[1]:
        print(1,2)
    else:
        print("-1 -1")

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

int main() {
	string a, b, c;
	int x, y, z;			//各文字列の残り長さ;
	int x1=0, y1=0, z1=0;	//最初から何番目チェッカー;
	char ch = 'a';

	cin >> a >> b >> c;

	x = a.length();
	y = b.length();
	z = c.length();
	
	while (x >= 0 && y >= 0 && z >= 0) {
		if (ch == 'a') {
			ch = a[x1];
			x1++;
			x--;
		}
		else if (ch == 'b') {
			ch = b[y1];
			y1++;
			y--;
		}
		else if(ch == 'c'){
			ch = c[z1];
			z1++;
			z--;
		}
	}
	if (x == -1)cout << "A" << endl;
	else if (y == -1)cout << "B" << endl;
	else if (z == -1)cout << "C" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

int N, M, Q;
vector<vector<int>> sum;

void buildSumTable(vector<int> l, vector<int> r) {
    sum = vector<vector<int>>(N + 1, vector<int>(N + 1));
    REP(i, M) { sum[l[i]][r[i]]++; }
    FOR(i, 1, N + 1) {
        FOR(j, 1, N + 1) {
            sum[i][j] += sum[i - 1][j];
            sum[i][j] += sum[i][j - 1];
            sum[i][j] -= sum[i - 1][j - 1];
        }
    }
}

int getSumRange(int l, int r) {
    int ans = sum[r][r] - sum[r][l - 1] - sum[l - 1][r] + sum[l - 1][l - 1];
    return ans;
}

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

    cin >> N >> M >> Q;
    vector<int> l(M), r(M), p(Q), q(Q);
    REP(i, M) cin >> l[i] >> r[i];
    REP(i, Q) cin >> p[i] >> q[i];

    buildSumTable(l, r);

    REP(i, Q) {
        int ans = getSumRange(p[i], q[i]);
        cout << ans << '\n';
    }

    return 0;
}

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

using namespace std;

using ll = long long;

const int NONE = -1;

struct Trie {
    const static int CHAR_NUM = 2;
    const static char FIRST_CHAR = '0';

    struct Node {
        bool leaf;
        int idxs[CHAR_NUM];
        Node() {
            leaf = false;
            fill(idxs, idxs + CHAR_NUM, NONE);
        };
    };

    vector<Node> tree;

    Trie() {
        tree.emplace_back();
    }

    void insert(const string& s) {
        int cur = 0;
        for (char c : s) {
            if (tree[cur].idxs[c - FIRST_CHAR] == NONE) {
                tree[cur].idxs[c - FIRST_CHAR] = tree.size();
                tree.emplace_back();
            }
            cur = tree[cur].idxs[c - FIRST_CHAR];
        }
        tree[cur].leaf = true;
    }

    bool find(const string& s) {
        int cur = 0;
        for (char c : s) {
            if (tree[cur].idxs[c - FIRST_CHAR] == NONE) {
                return false;
            } 
            cur = tree[cur].idxs[c - FIRST_CHAR];           
        }
        return tree[cur].leaf;
    }
};

ll L;
Trie tr;

void solve(int cur, int idx, vector<ll>& hoge) {
    if ((tr.tree[idx].idxs[0] == NONE) ^ (tr.tree[idx].idxs[1] == NONE)) hoge.push_back(L - cur);
    if (tr.tree[idx].idxs[0] != NONE) solve(cur + 1, tr.tree[idx].idxs[0], hoge);
    if (tr.tree[idx].idxs[1] != NONE) solve(cur + 1, tr.tree[idx].idxs[1], hoge);
}

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

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        tr.insert(s);
    }

    vector<ll> hoge;
    solve(0, 0, hoge);
    ll foo = 0;
    for (ll x : hoge) {
        int cnt = 0;
        while (x > 0) {
            if (x & 1) break;
            cnt++;
            x >>= 1;
        }
        foo ^= (1LL << cnt);
    }
    cout << (foo != 0 ? "Alice" : "Bob") << endl;
    return 0;
}

Measured memory_bytes: 7904
MOD = 10**9+7
# dp[i][j] := Sの後ろからi桁を13で割った余りがjとなるようなものの個数
S = input()
l = len(S)
dp = [[0]*13 for _ in range(l+5)]
dp[0][0] = 1
mul = 1  
for i in range(l):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:
        k = int(x) # これしか選ぶ余地なし
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13
print(dp[l][5]%MOD)

Measured memory_bytes: 62300
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 333*333;
const int maxq = 1e5+5;
int h,w,d,q, x[maxn], y[maxn], vis[maxn], dist[maxn];

void dfs(const int u)
{
    vis[u]++;
    const int v = u+d;
    if (v < h*w+1) {
        dist[v] = dist[u] + abs(x[u]-x[v]) + abs(y[u]-y[v]);
        dfs(v);
    }
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    ios::sync_with_stdio(false);
    while (cin >> h >> w >> d) {
        FOR(i,0,h) FOR(j,0,w) {
            int a; cin >> a;
            x[a] = i;
            y[a] = j;
        }
        memset(vis,0,sizeof(vis));
        FOR(i,1,h*w+1) if (!vis[i]) {
            dist[i] = 0;
            dfs(i);
        }
        cin >> q;
        FOR(i,0,q) {
            int a,b; cin >> a >> b;
            cout << dist[b]-dist[a] << endl;
        }
    }   
    return 0;
}


Measured memory_bytes: 2688
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 4e3 + 10, mod = 998244353;

ll b[N], r[N], dp[N][N];

int main() {
	fast_cin();
	string s; cin >> s;
	int n = s.length();
	s = " " + s;
	b[0] = r[0] = 0;
	for (int i = 1; i <= n; ++i) {
		b[i] = b[i - 1];
		r[i] = r[i - 1];
		if (s[i] == '0') {
			r[i] += 2;
		} else if (s[i] == '1') {
			++r[i];
			++b[i];
		} else {
			b[i] += 2;
		}
	}
	for (int i = n + 1; i <= 2 * n; ++i) {
		b[i] = b[i - 1];
		r[i] = r[i - 1];
	}
	dp[0][0] = 1;
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j <= i; ++j) {
			// cout << i << ' ' << j << ' ' << dp[i][j] << endl;
			if (r[i + 1] > j) {
				dp[i + 1][j + 1] += dp[i][j];
				dp[i + 1][j + 1] %= mod;
			}
			if (b[i + 1] > i - j) {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
			}
		}
	}
	ll ans = 0;
	for (int j = 0; j <= 2 * n; ++j) {
		ans += dp[2 * n][j];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 123904
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
int N;
std::string S,B;
int main() {
	std::cin >> N;
	int lb = 0;
	int ub = N;
	std::cout << 0 << std::endl;
	std::cin >> B;
	if (B == "Vacant")return 0;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		std::cout << mid << std::endl;
		std::cin >> S;
		if (S == "Vacant")return 0;
		if (mid % 2 == 0) {
			if (S == B)lb = mid;
			else ub = mid;
		}
		else {
			if (S == B)ub = mid;
			else lb = mid;
		}
	}
	std::cout << lb << std::endl;
	std::cin >> S;
	if (S == "Vacant")return 0;
	std::cout << ub << std::endl;
	if (S == "Vacant")return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  //vector<int> a{8,3,7,1,9,1,4};
  vector<int> a;

  int n,num;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
  }

  int q,t,b,e;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    cin >> b;
    cin >> e;

    auto itr_s = a.begin();
    auto itr_e = a.begin();

    for (int i=0;i<b;i++){
      itr_s++;
    }
    for (int i=0;i<e;i++){
      itr_e++;
    }

    if (t == 0){
      int min = *min_element(itr_s, itr_e);
      cout << min << endl;
    }else if(t == 1){
      int max = *max_element(itr_s, itr_e);
      cout << max << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
/*
дружочек, ты видимо не понял с кем общаешься.
вот эта манера речи "клоунская" меня не впечатляет.
давай встретимся и я объясню на понятном тебе языке - языке боли.
*/
int main(){
int n;
cin >> n;
vector<int> b(n);
for(int i = 0;i<n;i++) cin >> b[i];
vector<int> ans;
while(b.size()){
        bool lol = false;
    for(int i = b.size()-1;i>=0;i--){
        if(b[i]==i+1){ans.push_back(b[i]); b.erase(b.begin()+i);lol = true;break;}
    }
    if(!lol){cout << -1; return 0;}
}
reverse(ans.begin(),ans.end());
for(auto x : ans) cout << x << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[101];
    scanf("%s",s);
    int i,j,flag1=0,flag2=0;
    int len=strlen(s);
    for(i=0;i<len;i=i+2){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
                flag1=0;
            }
            else{
                flag1++;
                break;
            }
    }
    for(i=1;i<len;i+=2){
        if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
                flag2=0;
            }
            else{
                flag2++;
                break;
            }
    }
    if(flag1==0&&flag2==0)
        printf("Yes\n");
        else if(flag1>0 || flag2>0)
            printf("No\n");
    return 0;
}


Measured memory_bytes: 128
import collections

n = int(input())
v = [int(_) for _ in input().split()]

a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])

A = collections.Counter(a).most_common()
B = collections.Counter(b).most_common()

sa, na = A[0]
sb, nb = B[0]
if sa == sb:
    if na == n // 2 and nb == n // 2:
        print(na)
    else:
        if len(A) == 1:
            _, nb = B[1]
            print(n - na - nb)
        elif len(B) == 1:
            _, na = A[1]
            print(n - na - nb)
        else:
            _, nna = A[1]
            _, nnb = B[1]
            if na + nnb < nb + nna:
                print(n - nb - nna)
            else:
                print(n - na - nnb)
else:
    print(n - na - nb)

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

ll fpb(ll a,ll b){
    while (a%b!=0){
        ll c=b;
        b=a%b;
        a=c;
    }

    return b;
}

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

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;

    ll cc=b/c-a/c,dd=b/d-a/d,ee=b/(c*d/fpb(c,d))-a/(c*d/fpb(c,d));

  //  cerr << cc << " " << dd << el;
    cout << b-a-cc-dd+ee << el;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 0, sz(s) - 1 >> 1) {
        ans += s[i] != s[sz(s) - 1 - i];
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  if(a <= 0 && 0 <= b) cout<<"Zero"<<endl;
  else if(a > 0 || (b-a)%2) cout<<"Positive"<<endl;
  else cout<<"Negative"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int H ,W;
cin >> H >> W;
char c[55][55] ={'.'};
for(int i = 1; i <= H; i++){
  for(int j = 1; j <= W; j++){
    cin >> c[i][j];
  }
}
for(int i = 1; i <=H; i++){
  for(int j = 1; j<= W; j++){
    if(c[i][j] == '#'){
      if(c[i][j-1] != '#' && c[i][j+1] != '#' && c[i+1][j] != '#' &&c[i-1][j] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
}
cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
long long IN(void)
{
  long long x=0;short f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
signed main(void)
{
  char S[1000000];
  int a=0x7f7f7f7f,cusum[1000001]={0},len=0,max=0,min,temp,RT=2,rv[1000001]={0};
  if(scanf("%s",S)!=0)len=strlen(S);
  for(int i=0;i<len;i++)
  {
    cusum[i+1]=rv[i+1]=cusum[i]+((S[i]=='1')?1:-1);
    max=(cusum[i+1]<max)?max:cusum[i+1];
  }
  for(int i=len-1;i>=0;i--){rv[i]=(rv[i]<rv[i+1])?rv[i+1]:rv[i];}
  while(RT--)
  {
    temp=0,min=0;
    for(int i=0;i<len;i++)
    {
      if(S[i]=='?'){if(temp+rv[i+1]-cusum[i]+2<=max){temp++;}else temp--;}
      else if(S[i]=='0'){temp--;}
      else{temp++;}
      min=(min<temp)?min:temp;
    }
    a=(a<max-min)?a:max-min;
    max++;
  }
  return printf("%d\n",a),0;
}

Measured memory_bytes: 10492
#include <iostream>
//#include <string>
#include <algorithm>
using namespace std;


int main() {
  int N, Y;
  cin >> N >> Y;
  bool flag = false;
  
  for (int i=0;i<=N;++i){
    for(int j=0;j<=N-i;++j){
		int k=N-i-j;
      if(10000*i+5000*j+1000*k==Y){
        cout << i << " " << j << " " << k << endl;
        return 0;
        

      }
    }
  }
  cout << "-1 -1 -1" << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

ll D;
ll c[30];
ll s[400][30];
ll t[400];
ll last[30];
ll score;

int main() {
  cin >> D;
  repe(i, 1, 26) { cin >> c[i]; }
  repe(i, 1, D) {
    repe(j, 1, 26) { cin >> s[i][j]; }
  }
  repe(i, 1, D) { cin >> t[i]; }

  repe(i, 1, D) {
    ll ct = t[i];

    score += s[i][ct];
    last[ct] = i;

    repe(j, 1, 26) { score -= c[j] * (i - last[j]); }

    cout << score << "\n";
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string N;
    cin >> N;
    int ans = 0;
    int len = N.size();
    vector<int> vec(len);
    rep(i,len){
        vec[i] = stoi(N.substr(len - 1 - i,1));
    }
    rep(i,len - 1){
        if (vec[i] <= 4){
            ans += vec[i];
        }
        else if (vec[i] == 5){
            if (vec[i + 1] >= 5){
                vec[i + 1]++;
            }
            ans += 5;
        }
        else if (vec[i] <= 10){
            ans += 10 - vec[i];
            vec[i + 1]++;
        }
    }
    if (vec[len - 1] <= 5){
        ans += vec[len - 1];
    }
    else{
        ans += 11 - vec[len - 1];
    }
    cout << ans << endl;
}


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

using namespace std;

#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<pii> vpii;

template<typename T>
T getint() {
    T x=0,p=1;
    char ch;
    do{ch=getchar();}while(ch <= ' ');
    if(ch=='-')p=-1,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*p;
}

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

template<typename T1,typename T2>bool umin(T1 &x,const T2&y){if(x>y)return x=y,true;return false;}
template<typename T1,typename T2>bool umax(T1 &x,const T2&y){if(x<y)return x=y,true;return false;}

const int maxn=(int)(1 << 20)+10;
const int inf=(int)1e9+5;
const int mod=1e9 + 7;
const ll llinf=(ll)1e18+5;
const ld pi=acos(-1.0);

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

    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    vector <int> a(n);
    map <int, int> d[2];
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        d[i % 2][x]++;
    }

    pair <int, int> A, B, C, D;
    A = make_pair(0, -1);
    B = make_pair(0, -2);
    C = make_pair(0, -3);
    D = make_pair(0, -4);
    for(auto x: d[0]) {
        auto z = make_pair(x.se, x.fi);
        if (z > A) {
            B = A;
            A = z;
        } else if (z > B) {
            B = z;
        }
    }
    for(auto x: d[1]) {
        auto z = make_pair(x.se, x.fi);
        if (z > C) {
            D = C;
            C = z;
        } else if (z > D) {
            D = z;
        }
    }

    int mx = 0;
    if (A.se != C.se) mx = max(mx, A.fi + C.fi);
    if (A.se != D.se) mx = max(mx, A.fi + D.fi);
    if (B.se != C.se) mx = max(mx, B.fi + C.fi);
    if (B.se != D.se) mx = max(mx, B.fi + D.fi);
    cout << n - mx << endl;
    return 0;
}


Measured memory_bytes: 5376