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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,int,int> P;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

typedef int Weight;
typedef int Flow;
struct Edge {
  int src, dest, rev;
  Flow cap;
  Weight cost;
  bool operator < (const Edge &rhs) const {
    return cost > rhs.cost;
  }
  Edge(int s, int d) : src(s), dest(d) { ; }
  Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
  Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Flow cap){
  g[src].push_back((Edge){src, dest, (int)g[dest].size(), cap, 0});
  g[dest].push_back((Edge){dest, src, (int)g[src].size()-1, 0, 0});
}

Flow dfs(Graph &g, vector<bool> &used, int v, int t, Flow f){
  if(v == t) return f;
  used[v] = true;
  for(Edge& e: g[v]){
    if(!used[e.dest] && e.cap > 0){
      Flow d = dfs(g, used, e.dest, t, min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        g[e.dest][e.rev].cap += d;
      return d;
      }
    }
  }
  return 0;
}

Flow ford_fulkerson(Graph &g, int s, int t){
  Flow flow = 0;
  for(;;){
    vector<bool> used(g.size(),false);
    Flow f = dfs(g,used,s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main() {
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  Graph G(N);
  vector<P> ways;
  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    add_edge(G, x, y, 1);
    add_edge(G, y, x, 1);
    ways.emplace_back(x, i + 1, G[x].size() - 1);
  }
  int S, T;
  cin >> S >> T;
  S--, T--;
  cout << ford_fulkerson(G, S, T) << endl;
  set<int> ans;
  for (P way : ways) {
    int x = get<0>(way), r = get<1>(way),
        idx = get<2>(way);
    if (G[x][idx].cap == 1) {
      ans.insert(r);
    }
  }
  cout << ans.size() << endl;
  for (int a : ans) {
    cout << a << endl;
  }
  return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A > B){
    cout << 2*A - 1 << endl;
  }
  else if(A == B){
    cout << A + B << endl;
  }
  else{
    cout << 2*B - 1 << endl;
  }
}


Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int a;
	cin>>a;
	int b=a/100;
	a%=100;
	bool h1=false,h2=false;
	if(b>=1&&b<=12)h1=true;
	if(a>=1&&a<=12)h2=true;
	if(h1&&h2)cout<<"AMBIGUOUS"<<endl;
	if(h1&&!h2)cout<<"MMYY"<<endl;
	if(!h1&&h2)cout<<"YYMM"<<endl;
	if(!h1&&!h2)cout<<"NA"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	int n=read(),cnt=0;
   	for(int i=1;i<=n;i++)
   	{
   		int uf=read();
   		if(uf!=i)cnt++;
   	}
   	if(cnt<3)puts("YES");
   	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations
import sys
sys.setrecursionlimit(10 ** 7)
import bisect
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

D = defaultdict(int)
N = int(input())
A = list(map(int, input().split()))
for a in A:
    D[a] += 1

Q = int(input())

sm = 0
for k, v in D.items():
    sm += k * v


for i in range(Q):
    b, c = map(int, input().split())
    tmp = D[b]
    sm -= b * tmp
    sm += c * tmp
    print(sm)
    D[b] = 0
    D[c] += tmp


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll n, i, j;
    cin >> n;
    vector< ll >v1(n),v2(n),v(n);
    for(i = 0; i < n; i++)cin>>v1[i];
    for(i = 0; i < n; i++)cin>>v2[i];
    iota(all(v),1);
    
    ll c1 = 0,c2 = 0,cur = 0;
    do{
        cur++;
        if(v == v1)c1 = cur;
        if(v == v2)c2 = cur;        
    }
    while(next_permutation(all(v)));
    cout << abs(c1-c2) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

int black(int a,int b){
    for (int i=b-(a-1); i<=b+(a-1); i++) cout << i << " ";
    return 0;
}

int main(){
    int K,X,ans;
    cin >> K >> X;
    ans = black(K,X);
    return 0;
}

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

int n;
int A[400];
long long int sum[401];

long long int dp[401][401];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", A+i);
  for(int i = 0; i < n; i++) sum[i+1] = sum[i] + A[i];

  for(int i = n-1; i >= 0; i--){
    for(int j = i+2; j <= n; j++){
      dp[i][j] = (1ULL << 63) - 1;
      for(int k = i+1; k < j; k++){
        dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
      }
      dp[i][j] += sum[j] - sum[i];
    }
  }
  
  printf("%lld\n", dp[0][n]);
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxx 1000010
long long l1,r1,l2,r2,num,mid;
long long a[maxx],b[maxx],c[maxx];
int main()
{
    long long t;
    while(~scanf("%lld",&t))
    {
        num=0;
        for(long long i=0; i<t; i++)
            scanf("%lld",&a[i]);
        for(long long i=0; i<t; i++)
            scanf("%lld",&b[i]);
        for(long long i=0; i<t; i++)
            scanf("%lld",&c[i]);
        sort(a,a+t);
        sort(b,b+t);
        sort(c,c+t);
        for(long long i=0; i<t; i++)
        {
            l1=0;
            r1=t-1;
            while(l1<=r1)
            {
                mid=l1+(r1-l1)/2;
                if(a[mid]<b[i])
                    l1=mid+1;
                else
                    r1=mid-1;
            }
            l2=0;
            r2=t-1;
            while(l2<=r2)
            {
                mid=l2+(r2-l2)/2;
                if(c[mid]<=b[i])
                    l2=mid+1;
                else
                    r2=mid-1;
            }
            num=num+(l1*(t-l2));
        }
        printf("%lld\n",num);
    }
    return 0;
}


Measured memory_bytes: 9216
import sys
from collections import Counter


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def get_ans(v, ans):
    while len(v) != 1:
        ans += v.pop()
    return ans


def main():
    n = ni()
    V = nl()
    V_e = V[0::2]
    V_o = V[1::2]
    V_e_c = Counter(V_e)
    V_o_c = Counter(V_o)
    # num_V_e = sorted(list(V_e_c.values()))[::-1]
    # num_V_o = sorted(list(V_o_c.values()))[::-1]

    if V_e_c.most_common()[0][0] != V_o_c.most_common()[0][0]:
        ans = len(V) - \
            V_e_c.most_common()[0][1] - V_o_c.most_common()[0][1]

    else:
        if len(V_e_c.most_common()) == 1 or len(V_o_c.most_common()) == 1:
            if len(V_e_c.most_common()) == 1 and len(V_o_c.most_common()) == 1:
                ans = len(V) // 2
            else:
                if len(V_e_c.most_common()) != 1:
                    ans = len(V) // 2 - V_e_c.most_common()[1][1]
                else:
                    ans = len(V) // 2 - V_o_c.most_common()[1][1]

        else:
            ans = len(V) - max(
                V_e_c.most_common()[0][1] + V_o_c.most_common()[1][1],
                V_e_c.most_common()[1][1] + V_o_c.most_common()[0][1],
            )

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24764
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define endl '\n'
#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define ld long double
#define PI 3.14159265359

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	while (t--) {
		ull n;
		cin >> n;
		ull co = 3 * n;
		vector<ull> a(co);
		for (auto &i : a) {
			cin >> i;
		}
		sort(a.begin(), a.end());
		ull sum = 0;
		for (int i = co - 2; i >= n; i -= 2) {
			sum += a[i];
		}
		cout << sum;
	}
}

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

static const double pi = 3.141592653589793;

double ans(int a,int b,int h,int m){
  double angle1=(h+m/60.0)/6.0*pi;
  double angle2=m/30.0*pi;
  double tmp=angle1-angle2;
  return pow((pow(a,2.0)+pow(b,2.0)-2.0*a*b*(cos(angle1)*cos(angle2)+sin(angle1)*sin(angle2))),0.50);
}

int main(){
  double a,b,h,m;
  cin >>a>>b>>h>>m;
  cout <<setprecision(15)<<ans(a,b,h,m)<<endl;
}

Measured memory_bytes: 4292
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct EdgeA
{
	int to;
	ll cost;
};

void calcAllShortest(vector<vector<EdgeA>>& G, vector<vector<ll>>& d)
{
	auto numV = (int)G.size();
	for (auto i = 0; i < numV; ++i)
	{
		d.push_back(vector<ll>(numV, LLONG_MAX));

		for (auto v : G[i])
		{
			d[i][v.to] = v.cost;
		}
		d[i][i] = 0;
	}

	for (auto k = 0; k < numV; ++k)
	{
		for (auto i = 0; i < numV; ++i)
		{
			for (auto j = 0; j < numV; ++j)
			{
				if (d[i][k] >= LLONG_MAX || d[k][j] >= LLONG_MAX)
				{
					continue;
				}
				auto kd = d[i][k] + d[k][j];
				if (d[i][j] > kd)
				{
					d[i][j] = kd;
				}
			}
		}
	}
}

int main()
{
	int H, W;
	cin >> H >> W;

	vector<vector<EdgeA>> G(10);
	for (auto i = 0; i < 10; ++i)
	{
		for (auto j = 0; j < 10; ++j)
		{
			ll c;
			cin >> c;
			G[i].push_back({ j, c });
		}
	}

	vector<vector<ll>> d;
	calcAllShortest(G, d);

	auto ans = 0ll;
	for (auto i = 0; i < H; ++i)
	{
		for (auto j = 0; j < W; ++j)
		{
			int A;
			cin >> A;
			if (A >= 0)
			{
				ans += d[A][1];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define INF 0x3f3f3f3f
#define NINF -0x3f3f3f3f

using namespace std;

typedef pair<int,int> pii;

long long a[55];

int main (int argc, char const* argv[])
{
	int n;
	scanf("%d",&n);
	
	for (int i = 0; i < n; i += 1)
	{
		scanf("%lld",&a[i]);
	}
	
	long long ans = 0;
	while (true)
	{
		long long mx[2] = { -1, -1 };
		int pos[2] = { -1, -1 };
		for (int i = 0; i < n; i += 1)
		{
			if (a[i] > mx[0])
			{
				mx[1] = mx[0];
				pos[1] = pos[0];
				
				mx[0] = a[i];
				pos[0] = i;
			} 
			else if (a[i] > mx[1])
			{
				mx[1] = a[i];
				pos[1] = i;
			}
		}
		
		if (mx[0] < n)
			break;
		
		long long diff = mx[0]-n+1LL;
		long long x = (diff+n-1LL)/n;
	
		ans += x;
		
		for (int i = 0; i < n; i += 1)
		{
			if (i != pos[0])
			{
				a[i] += x;	
			}
			else
			{
				a[i] -= x*n;
			}
		}
	}
	
	printf("%lld\n",ans);	
	return 0;
}

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

int main() {
  vector<int> length(3);
  for (int i = 0; i < 3; i++) {
    cin >> length.at(i);
  }
  sort(length.begin(), length.end());
  cout << length.at(0) * length.at(1) / 2 << endl;
}

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

int k;
int num[100010],out = 100010; 
bool v[100010],l,l2;

void dfs()
{
	queue < int > q;
	q.push(0);
	v[0] = 0;
	while(!q.empty())
	{
		int now = q.front();
		if(now == 0)
		{
			if(l2 == 0) l2 = 1;
			else
			{
				out = min(out,num[now]);
				l = 1;
			}
		}
		if((num[(now + 1) % k] > num[now] + 1 || num[(now + 1) % k] == -1) && l == 0)
		{
			num[(now + 1) % k] = num[now] + 1;
			if(v[(now + 1) % k] == 0)
			q.push((now + 1) % k);
			v[(now + 1) % k] = 1;
		}
		if((num[now * 10 % k] > num[now] || num[now * 10 % k] == -1) && now * 10 % k != now && l == 0)
		{
			num[now * 10 % k] = num[now];
			if(v[now * 10 % k] == 0)
			q.push(now * 10 % k);
			v[now * 10 % k] = 1;
		}
		v[now] = 0;
		q.pop();
		l = 0;
		if(now == 0)
		num[now] = -1;
	}
}

int main()
{
	cin>>k;
	for(int i = 1;i <= k;i++)
	num[i] = -1;
	
	dfs();
	
	cout<<out;
	
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main()
{
	int a,b,c;
	int max,min,total;
	
	scanf("%d %d %d",&a,&b,&c);
	total=a+b+c;
	if(a > b&&a > c )
	{
		max = a;
	}
	else if(b > a&&b > c)
	{
		max = b;
	}
	else
	{
		max = c;
	}
	if(a < b&&a < c)
	{
		min = a;	
	}
	else if(b < a&&b < c)
	{
		min = b;
	}
	else
	{
		min = c;
	}
	  printf("%d %d %d\n",min,total-max-min,max);
	
	return 0;
}


Measured memory_bytes: 2052
ls=list(input())
r_count=0
l_count=0
ans_ls=[]

for i,s in enumerate(ls[:-1]):
    ans_ls.append(0)
    if s=="R":
        r_count+=1
        if ls[i+1]=="L":
            r_idx=i
            l_idx=i+1
        if i+2==len(ls):
            l_count+=1
            ans_ls.append(0)
            ans_ls[r_idx]=(r_count+1)//2+l_count//2
            ans_ls[l_idx]=r_count//2+(l_count+1)//2
            r_count,l_count=0,0
    elif s=="L":
        l_count+=1
        if ls[i+1]=="R":
            ans_ls[r_idx]=(r_count+1)//2+l_count//2
            ans_ls[l_idx]=r_count//2+(l_count+1)//2
            r_count,l_count=0,0
        if i+2==len(ls):
            l_count+=1
            ans_ls.append(0)
            ans_ls[r_idx]=(r_count+1)//2+l_count//2
            ans_ls[l_idx]=r_count//2+(l_count+1)//2
            r_count,l_count=0,0
print(" ".join(list(map(str,ans_ls))))

Measured memory_bytes: 54668
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 1; i <= (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N, X, Y; cin >> N >> X >> Y;
    vector<vi> maze(N+1);
    rep(i, N){
        if (i == X) maze[i].push_back(Y);
        if (i == Y) maze[i].push_back(X);
        maze[i].push_back(i+1);
        maze[i].push_back(i-1);
    }
    vector<vi> dist(N+1, vi(N+1., -1));

    rep(i, N){

        queue<int> q; q.push(i); 
        dist[i][i] = 0;

        while (!q.empty()){

            int n = q.front(); q.pop();

            for (int j : maze[n]){

                if (dist[i][j] != -1) continue;
                if (j == 0 || j == N+1) continue;

                dist[i][j] = dist[i][n] + 1;
                q.push(j);
            }
        }
    }

    vi sum(N);

    rep(i, N){
        for (int j = i+1; j <= N; ++j){
            int tmp = dist[i][j];
            sum[tmp]++;
        }
    }

    rep(i, N-1){
        cout << sum[i] << endl;
    }
    return 0;

}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

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

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  vi a(n); rep(i, n) std::cin >> a[i];
  int ans = 0;
  srep(i, 1, n) {
    if (a[i-1] == a[i]) ans++, i++;
  }
  std::cout << ans << "\n";
}


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

using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;

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

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

  vector<bool> vt(n + 2, false), va(n + 2,false);
  for (int i = 1; i <= n; i++) {
    vt[i] = (t[i] != t[i - 1]);
  }
  for (int i = n; i >= 1; i--) {
    va[i] = (a[i] != a[i + 1]);
  }
  
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    if (!vt[i]) continue;
    if (t[i] > a[i]) ans = 0;
  }
  for (int i = n; i >= 1; i--) {
    if (!va[i]) continue;
    if (a[i] > t[i]) ans = 0;
  }

  for (int i = 1; i <= n; i++) {
    if (vt[i] | va[i]) continue;
    ans *= (ll)min(a[i], t[i]);
    ans %= mod;
  }

  if (t[n] != a[1]) {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a.begin(), a.end(), greater<int>());

  int l = p, r = n;
  while (l < r) {
    int c = (l + r) / 2;

    if (a[c] + m < a[p-1]) {
      r = c;
      continue;
    }

    long long sum = 0;
    for (int i = p-1; i < c; i++) {
      sum += a[c] + m - a[i];
    }

    if (sum < 1LL * m * (v - (p-1) - (n-c))) {
      r = c;
    }
    else {
      l = c + 1;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, '%d', $n);
$foods = fgets(STDIN);
$exploded_foods = explode(' ', trim($foods));
$scores = fgets(STDIN);
$exploded_scores = explode(' ', trim($scores));
$combos = fgets(STDIN);
$exploded_combos = explode(' ', trim($combos));

$sum = 0;
$prev_food = 0;
foreach ($exploded_foods as $food) {
  $sum += $exploded_scores[$food - 1];
  if ($prev_food + 1 == $food) {
    $sum += $exploded_combos[$food - 2];
  }
  $prev_food = $food;
}

echo $sum;

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

const int MAXLOG=20;

struct node{
  int val,rank;
  vector<node*> p;
  node(){}
  node(int a){ val = a; rank=0; }
  void push( node *a ){
    p.push_back( a );
    rank++;
  }
};
struct binomialHeap{

  vector<node*> root;
  binomialHeap(){
    root.resize(MAXLOG,NULL);
  }

  node* mergeTree(node* p,node*q){
    if( p == NULL || q == NULL ) return p?p:q;
    if( p->val < q->val ){
      q->push(p);
      return q;
    } else {
      p->push(q);
      return p;
    }
  }

  void merge( const binomialHeap &ot ){
    node *nxp = NULL;
    for(int i=0;i<(int)root.size();i++){
      node *tree = mergeTree(root[i],nxp); nxp=NULL;      
      if( tree && tree->rank == i ) root[i] = tree;
      else { root[i] = NULL; nxp = tree; }
      tree = mergeTree(root[i],ot.root[i]);
      if( tree && tree->rank == i ) root[i] = tree;
      else { root[i] = NULL; if(!nxp) nxp = tree; }
    }
  }

  void push( int val ){
    node *np = new node(val);
    binomialHeap h; h.root[0] = np;
    merge(h);
  }
  void view(){
    for(int i=0;i<(int)root.size();i++) cout << i << ": " << (root[i]?root[i]->val:-INT_MAX) << endl;
  }
  int top(){
    int ret = -INT_MAX;
    for(int i=0;i<(int)root.size();i++)
      ret = max( ret, (root[i]?root[i]->val:-INT_MAX) );
    return ret;
  }
  void pop(){
    int id=0;
    for(int i=1;i<(int)root.size();i++)
      if( (root[id]?root[id]->val:-INT_MAX) < (root[i]?root[i]->val:-INT_MAX) ) id=i;
    binomialHeap h;
    for(int i=0;i<(int)root[id]->p.size();i++)
      h.root[root[id]->p[i]->rank] = root[id]->p[i];
    delete root[id];
    root[id]=NULL;
    merge(h);
  }
  
};





int main(){
  binomialHeap h;
  char buf[10];
  while( ~scanf("%s",buf) ){
    if( buf[2] == 'd' ) break;
    if( buf[0] == 'i' ){
      int a; scanf("%d",&a);
      h.push( a );
    } else {
      printf("%d\n",h.top());
      h.pop();
    }
  }  
  /*
  int n; cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    cout << a<< endl;
    h.push( a );
  }
  for(int i=0;i<n;i++){
    cout << h.top() << " ";
    h.pop();
  }
  cout << endl;
  */
}

Measured memory_bytes: 67224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> board(H);
  rep(i, H)
  {
    cin >> board[i];
  }

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

  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (board[i][j] == '#')
        continue;
      int num = 0;
      for (int d = 0; d < 8; ++d)
      {
        int ni = i + dy[d];
        int nj = j + dx[d];
        if (ni < 0 || H <= ni)
          continue;
        if (nj < 0 || W <= nj)
          continue;
        if (board[ni][nj] == '#')
          num++;
      }
      board[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < H; ++i)
    cout << board[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int main(){
	int N, L;
	cin >> N >> L;
	int sum = 0;
	for (int i = 0; i <= N - 1; i++) {
		sum += L + i;
	}
	if (L + N - 1 < 0) cout << sum - (L + N - 1); 
	else if (L <= 0 && L + N - 1 >= 0)cout << sum;
	else cout << sum - L;

	return 0;
}



Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,a,b = map(int, input().split())
h=[int(input()) for i in range(n)]

def solve(num):
    all_b = num*b
    cnt=0
    for i in range(len(h)):
        rest = h[i] - all_b
        if rest>0:
            cnt+=(rest - 1) // (a-b) + 1
    if cnt <= num:
        return True
    else:
        return False

l=0
r=10**20
while r-l>1:
    mid=(l+r)//2

    if solve(mid):
        r=mid
    else:
        l=mid
print(r)

Measured memory_bytes: 44124
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int a[MAXN];
int n,m,k;
int fa[MAXN][2];
pair<int,int> l1[MAXN],l2[MAXN];
map<pair<int,int> ,int> mp;
int get_fa(int x,int id){
	if(fa[x][id]==0)
		return x;
	fa[x][id]=get_fa(fa[x][id],id);
	return fa[x][id];
}
int merge(int x,int y,int id){
	int fx=get_fa(x,id);
	int fy=get_fa(y,id);
	if(fx!=fy)
		fa[fx][id]=fy;
}
int main(){
	SF("%d%d%d",&n,&m,&k);
	int u,v;
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);
		merge(u,v,0);
	}
	for(int i=1;i<=k;i++){
		SF("%d%d",&u,&v);
		merge(u,v,1);
	}
	for(int i=1;i<=n;i++)
		mp[make_pair(get_fa(i,0),get_fa(i,1))]++;
	for(int i=1;i<=n;i++)
		PF("%d ",mp[make_pair(get_fa(i,0),get_fa(i,1))]);
	
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    REP(i, n) cin >> t[i];
    sort(ALL(t));

    int saisyo = t[0], jokyaku = 1, ans = 0;
    REPN(i, 1, n) {
        if(t[i] - saisyo > k) {
            ans++;
            saisyo = t[i];
            jokyaku = 1;
        } else {
            if(jokyaku < c) {
                jokyaku++;
            } else {
                ans++;
                jokyaku = 1;
                saisyo = t[i];
            }
        }
    }

    ans++;

    cout << ans << endl;

    return 0;
}

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

// C++ program to demonstrate 
// Basic Euclidean Algorithm 
// Function to return  
// gcd of a and b 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Dr

int main() {
ll a,b,i,j,count=0;
	a=360;
	cin>>b;
count=gcd(a,b);
j=(a*b)/count;
cout<<j/b;

return 0;
}

Measured memory_bytes: 3616
//BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME

//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█


#include<bits/stdc++.h>

#define ull    unsigned long long
#define ll   long long
#define ses   "\n"

using namespace std;
   long double sum=0;
//main function is here.... ....
int main(){
ll n;
cin>>n;
while(n--){
    long double x;
    cin>>x;
    string u;
    cin>>u;
    if(u=="JPY"){
        sum+=x;
    }
    else{
        sum+=(380000.0*x);
    }
}
cout<<fixed<<setprecision(10);
cout<<sum;
}

//Alhamdulillah


Measured memory_bytes: 256
from collections import deque

n = int(input())
commands = [input() for _ in range(n)] # splitとかしてると間に合わない

l = deque()
for com in commands:
    if com[0]=='i':
        l.appendleft(com[7:])
    elif com[6]=='F':
        l.popleft()
    elif com[6]=='L':
        l.pop()
    else:
        try:
            l.remove(com[7:])
        except:
            pass

s = ' '.join(l)
print(s)


Measured memory_bytes: 212324
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def cmb(n,r):  #nCr = n!/(n-r)!r!
    retVal = 1
    for i in range(n-r+1,n+1):
        retVal *= i
    for i in range(2,r+1):
        retVal //= i
    return retVal
def main():
    from collections import defaultdict
    N = int(input())
    d = defaultdict(lambda:0)
    base = ord('a')
    ans = 0
    for _ in range(N):
        s = input().strip() 
        s = ''.join(sorted(s))
        ans += d[s]
        d[s] += 1

    
    print(ans)

        

    





    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 58076
/*
                IftekharMd.Shishir
                Dept. of Information and Communication Engineering
                University of Rajshahi
*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define ll  long long
#define ull  unsigned long long
#define ld  long double
#define f(i,n)  for(i=0;i<n;i++)
#define F(i,n)  for(i=n-1;i>=0;i--)
#define fa(i,a,b)  for(i=a;i<=b;i++)
#define Fa(i,a,b)  for(i=a;i>=b;i--)
#define printArray(i,a,n)  f(i,n)cout<<a[i]<<" "; cout<<endl;
#define printSet(a)  for(auto setData:a) cout<<setData<<" ";cout<<endl;
#define printMap(a)  for(auto mapData:a) cout<<mapData.first<<" "<<mapData.second<<endl;
#define printVector(a)  for(auto vectorData:a)cout<<vectorData<<" ";cout<<endl;
#define printLinkedList()  temp=head;while(temp){cout<<temp->data<<" ";temp=temp->post;} cout<<endl;

#define pb(x)  push_back(x)
#define all(a)  a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()

#define bs  binary_search
#define lb  lower_bound
#define ub  upper_bound
#define mp  make_pair
#define TxtIO  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define TxtTest freopen("C:/Users/Iftekhar/Documents/what/input.txt", "r", stdin);
#define FastIO  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
#define TestCase  ll t;cin>>t;while(t--)
#define points(x)  fixed<<setprecision(x)
#define scd(a,x,y)  a/__gcd(x,y);
#define nl  cout<<endl;
#define done  return 0

const ld PI= 3.14159265358979323846264338327950288;  //2*acos(0.0);
const long long MOD= 1000000007;
const long long MAX = 32000;

// stringstream demo(str);  demo >> x;
// stringstream demo;  demo << x;  name=demo.str();

using namespace __gnu_pbds;
using namespace std;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
        FastIO;
        //TxtTest;
        ll n,k,i,x,sum=0;
        cin>>n>>k;
        while(n--){
                cin>>x;
                sum+=2*(min(x,abs(x-k)));
        }
        cout<< sum <<endl;
        done;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 3e3+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

int n;
double mem[N][N];
double arr[N];

double solve(int i, int v){
    if(i == n){
        if(v == 0) return 1.00;
        else return 0.00;
    }
    if(mem[i][v] != -1.00) return mem[i][v];
    double op1 = solve(i+1, v)*(1.00-arr[i]);
    double op2 = 0.00;
    if(v) op2 = solve(i+1, v-1)*arr[i];
    return mem[i][v] = op1+op2;
}

int main()
{
    _69e27
    cin >> n;
    for(int i = 0; i<n; i++)
        cin >> arr[i];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++)
            mem[i][j] = -1.00;
    }
    double res =0;
    for(int i=(n+1)/2; i<=n; i++)
        res +=solve(0, i);

    cout << fixed << setprecision(10) << res;
    return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define NILL 2000000010
using namespace std;
struct node{
  node *p, *l,*r;
  int key;
};
node *root;
 
node * mk_node(int key,node *l,node *r,node *p){
  node *n=(node *)malloc(sizeof(node));
  n->key=key;
  n->r=r;
  n->l=l;
  n->p=p;
  return n;
}
 
void insert(node *z){
  node *y=mk_node(NILL,NULL,NULL,NULL);
  node *x=root;
  while(x!=NULL){
    y=x;
    if((z->key)<(x->key)) x=x->l;
    else x=x->r;
  }
  z->p = y;
  if(y->key==NILL)root = z;
  else if(z->key < y->key) y->l=z;
  else y->r=z;
}

void print(node *pos, int flg){
  if(flg)cout <<" "<<pos->key;
  if(pos->l!=NULL)print(pos->l,flg);
  if(!flg)cout <<" "<<pos->key;
  if(pos->r!=NULL)print(pos->r,flg);
}

bool find(node *pos,int key){

  if(pos==NULL)return 0;

  if(pos->key>key) return find(pos->l,key);
  if(pos->key<key) return find(pos->r,key);
  return 1;
} 
 
char str[1000];
int main(){
  root=mk_node(NILL,NULL,NULL,NULL);
  int n;
  cin>>n;

  while(n--){
    node *x=mk_node(NILL,NULL,NULL,NULL);
    int a;
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&x->key);
      insert(x);
    }
    else if(str[0]=='p'){
      print(root,0);cout <<endl;
      print(root,1);cout <<endl;
    }
    else if(str[0]=='f'){
      cin>>a;
      cout <<(find(root,a)? "yes":"no")<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 43436
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#define NIL -1

struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};

struct node *root,*NIL;

void insert(int k)
{
  struct node *y,*x,*z;

  y=NIL;    // x の親                                                           
  x=root;

  z=(struct node *)malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;    // 親を設定                                                         
    if(z->key<x->key){
      x=x->left;  // 左の子へ移動                                               
    }else{
      x=x->right;  // 右の子へ移動                                              
    }
  }
  z->parent=y;

  if(y==NIL){  // T が空の場合                                                  
    root=z;
  }else {
    if(z->key<y->key){
    y->left=z;  // z を y の左の子にする                                        
    }else{
    y->right=z;  // z を y の右の子にする                                       
    }
  }
}

struct node *find(struct node *x,int k)
{
  while(x!=NIL && k!=x->key){
    if(k<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  return x;
}

void in_print(struct node *u) //中間から
{
  if(u==NIL) return;
  in_print(u->left);
  printf(" %d",u->key);
  in_print(u->right);
}

void pre_print(struct node *u)  //前から
{
  if(u==NIL) return;
  printf(" %d",u->key);
  pre_print(u->left);
  pre_print(u->right);
}

int main(){
  int i,m,k;
  char str[21];
  struct node *num;

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",str);
    if(strcmp("insert",str)==0){
      scanf("%d",&k);
      insert(k);  
    }else if(strcmp("find",str)==0){
      scanf("%d",&k);
      num=find(root,k);
      if(num!=NIL) printf("yes\n");
      else printf("no\n");
    }else{
      in_print(root);
      printf("\n");
      pre_print(root);
      printf("\n");
    }
  }

  return 0;
}





Measured memory_bytes: 20484
#include <cstring>
#include <cstdio>

using namespace std;

typedef struct word_t {
        char str[33];
        int len;
        int count;
        word_t();
} word_t;

word_t::word_t()
        :count(0)
        {
        }

int main()
{
        word_t word[1000];
        char str[33];
        int top = 0, i;

        while (scanf("%s", str) != EOF) {
                for (i = 0; i < top; i++) {
                        if (!strcmp(str, word[i].str)) {
                                word[i].count++;
                                break;
                        }
                }
                if (i == top) {
                        strcpy(word[i].str, str);
                        word[i].len = strlen(word[i].str);
                        word[i].count++;
                        top++;
                }
        }

        int mostCnt = 0, mostLen = 0;
        for (i = 0; i < top; i++) {
                mostCnt = (word[i].count > word[mostCnt].count) ? i : mostCnt;
                mostLen = (word[i].len > word[mostLen].len) ? i : mostLen;
        }
        printf("%s %s\n", word[mostCnt].str, word[mostLen].str);

        return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	int A, B;
	cin >> A >> B;

	int u = A + B;
	int v = A + (A - 1);
	int w = B + (B - 1);

	printf("%d\n", max(u, max(v, w)));
	return 0;
}



Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
map<string, bool> mp;
int main() {
	int n;
	cin >> n;
	string s;
	bool vis = false;
	cin >> s;
	char ch = s[s.size() - 1];
	mp[s] = 1;
	for (int i = 2; i <= n; i++) {
		cin >> s;
		if (mp[s]||ch!=s[0]) {
			vis = true;
			break;
		}
		mp[s] = 1;
		ch = s[s.size() - 1];
	}
	if (vis)
		cout << "No";
	else
		cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
//////// Bomber 
// https://atcoder.jp/contests/abc176/tasks/abc176_e
// date: 2020-08-22T21:00:10.587993
// memo: 
    
//<editor-fold desc="my macro">

#include<bits/stdc++.h>
#ifdef LOCAL
    #include<my/dump.h>
#else
    #define dump(...) 42 
    #define dumpi(x) 42 
#endif

typedef long long ll;
using namespace std;

#define foe(x, a) for(auto& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define pb(a) push_back(a)
#define mp make_pair
#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

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

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (a) : (b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

#define INF 1e19
#define MOD 1e9+7

ll toKey(int x, int y) {
    return x * 300000 + y;
}

int solve() {
    ll H,W,M;
    ci(H,W,M);
    vec<int> xs(H);
    vec<int> ys(W);
    uset<ll> posi;
    rep(i,M) {
        int _x;
        int _y;
        ci(_x,_y);
        xs[--_x] ++;
        ys[--_y] ++;
        posi.insert(toKey(_x, _y));
    }
    auto maxx = max_element(all(xs));
    auto maxy = max_element(all(ys));

    dump(xs);
    dump(ys);
    dump(*maxx,*maxy);
    dump(posi);

    vec<int> id_x;
    vec<int> id_y;
    rep(i,H) {
        if ( *maxx == xs[i]) id_x.push_back(i);
    }
    rep(i,W) {
        if ( *maxy == ys[i]) id_y.push_back(i);
    }

    bool found=false;
    foe(ix, id_x) foe(iy, id_y) {
        if (posi.count(toKey(ix,iy)) <= 0) {
            found=true;
            break;
        }
    }

    sankou(found, *maxx + *maxy, *maxx + *maxy -1);

    return 0;
}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    
    solve();
    return 0;
}


Measured memory_bytes: 23260
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=1e9+7;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';
int32_t main(){
    int n,a,m;
    cin>>n>>a>>m;
    
    
    vector<int>ans;
    
    map<int,int>mark;
    
    int i=1;
    int res=0;
    int val = 0;
    for(i = 1; i <= n ; i++ ){
        
        int curr = a%m;
        // cout<<curr<<endl;
        if(mark[curr] < 2 ){
            ans.pb(curr);
            res+=curr;
            mark[curr]++;
        }else{
            val = curr;
            break;
        }
        a=(a*a)%m;
    }
    // cout<<val<<endl;
    
    int curr=val;
    if(i == n){
        // cout<<"case1\n";
        cout<<res<<endl;
    }else{
        int cp = 0;
        int len=0;
        val=0;
        for(int i = 0 ; i < ans.size() ; i++ ){
            if(ans[i] == curr){
                cp++;
            }
            if(cp==1){ 
                len++ ; 
                val+=ans[i]; 
                
            }
        }
        
        if(i+len > n){
            
            for(int j = i ; j<= n ; j++ ){
                int curr=a%m;
                res+=curr;
                a=(a*a)%m;
            }
            
        // cout<<"case2\n";
            cout<<res<<endl;
            
        }else{
            
            
            int kita = (n-i+1)/len;
            
            res = res + kita*val;
            
            // cout<<kita<<" "<<val<<endl;
            i = i + len*kita;
            a=(curr)%m;
            for(int j = i; j<=n; j++ ){
                a=a%m;
                res+=a;
                a=(a*a)%m;
            }
            cout<<res<<endl;
            
        // cout<<"case3\n";
            
        }
        
    }
    
    
    
    
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans;
int a[222222];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	int now=1;
	rep(i,n){
		if(a[i]==now){
			now++;
		}
	}
	if(now!=1)cout<<n-now+1<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 1792
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ld a,b,h,m;
    cin >> a >> b >> h >> m;
    ld hd=1.0*m*0.5 + 1.0*30*h;
    ld md=m*6;
    ld alpha=abs(md-hd);
    ld res=sqrt(1.0*a*a + 1.0*b*b - 2.0*a*b*cos(1.0*acos(-1)*alpha/180));
    cout << fixed << setprecision(20) << res;
    return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl a(n-1);
    rep(i,n-1) cin >> a[i];
    vl ans(n);
    rep(i,n-1){
        ans[--a[i]]++;
    }
    rep(i,n){
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 6364