akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int H,W;
    int[,] a; 
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long[,,] dp = new long[H,W,H];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                for(int k=0;k<H;k++){
                    if(i == 0 && j == 0 && k == 0){
                        dp[i,j,k] = a[i,j];
                    }
                    else if(i == H-1 && j == W-1 && k == H-1){
                        long max = dp[i-1,j,k-1];
                        if(max < dp[i-1,j,k]){
                            max = dp[i-1,j,k];
                        }
                        if(max < dp[i,j-1,k-1]){
                            max = dp[i,j-1,k-1];
                        }
                        if(max < dp[i,j-1,k]){
                            max = dp[i,j-1,k];
                        }
                        dp[i,j,k] = max + a[H-1,W-1];
                    }
                    else if(i == k){
                        dp[i,j,k] = 0;
                    }
                    else if(i+j >= k && i+j-k < W){
                        long max = 0;
                        if(i != 0 && k != 0){
                            max = dp[i-1,j,k-1];
                        }
                        if(i != 0 && k != (i+j) && max < dp[i-1,j,k]){
                            max = dp[i-1,j,k];
                        }
                        if(j != 0 && k != 0 && max < dp[i,j-1,k-1]){
                            max = dp[i,j-1,k-1];
                        }
                        if(j != 0 && k != (i+j) && max < dp[i,j-1,k]){
                            max = dp[i,j-1,k];
                        }
                        dp[i,j,k] = max + a[i,j] + a[k,i+j-k];
                    }
                    else{
                        dp[i,j,k] = 0;
                    }
                }
            }
        }
        sb.Append(dp[H-1,W-1,H-1]+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        H = int.Parse(str[0]);
        W = int.Parse(str[1]);
        a = new int[H,W];
        for(int i=0;i<H;i++){
            str = Console.ReadLine().Split(' ');
            for(int j=0;j<W;j++){
                a[i,j] = int.Parse(str[j]);
            }
        }
    }    
}

Measured memory_bytes: 69080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc079/tasks/abc079_c

string op;
string abcd;

bool dfs(int sum, string cop) {
    if (cop.length() == 3) {
        op = cop;
        return sum == 7;
    }

    if (dfs(sum + (abcd[cop.length() + 1] - '0'), cop+"+")) return true;

    if (dfs(sum - (abcd[cop.length() + 1] - '0'), cop+"-")) return true;

    return false;
}

int main() {
    cin >> abcd;

    if (dfs(abcd[0] - '0', "")) {
        printf("%c%c%c%c%c%c%c=7\n", abcd[0], op[0], abcd[1], op[1], abcd[2], op[2], abcd[3]);
    } else {
        cout << "no" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

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

  size_t n;
  cin >> n;

  string s, t;
  cin >> s >> t;

  rep (i, n)
  {
    cout << s [i] << t [i];
  }
  cout << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n : usize,
        l : [usize;n],
    }

    let mut cnt = 0;

    if n < 3 {
        println!("{}", cnt);
        return
    }

    // println!("{:?}",&l);

    for i in 0..(n-2){
        for j in (i+1)..(n-1){
            for k in (j+1)..n{
                if l[i] == l[j] || l[k] == l[j] || l[i] == l[k]{
                    continue;
                }

                if (l[i] < l[j] + l[k]) && (l[j] < l[k] + l[i] ) && (l[k] < l[i] + l[j]) {
                    cnt += 1;
                }
            }
        }
    }
    println!("{}",cnt);
}


Measured memory_bytes: 2132
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

const ll INF = -(1LL << 50);
int n, m;
int a[2000], b[2000];
ll c[2000];
ll d[1001];


int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}
	fill(d, d + 1001, INF);

	for (int i = 0; i < n; ++i) {
		if (a[i] == 1) {
			d[b[i]] = c[i];
		}
	}
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < m; ++j) {
			if (d[a[j]] == INF) continue;
			ll d1 = d[b[j]]; 
			ll d2 = d[a[j]] + c[j];
			if (d1 < d2 ) {
				d[b[j]] = d2;
			}
		}
	}
	ll ans = d[n];
	for (int j = 0; j < m; ++j) {
		if (d[a[j]] == INF) continue;
		ll d1 = d[b[j]]; 
		ll d2 = d[a[j]] + c[j];
		if (d1 < d2 ) {
			d[b[j]] = d2;
		}
	}
	if (ans < d[n]) {
		cout << "inf" << endl;
	}else {
		cout << ans << endl;
	}
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int>S(N);
    vector<int>T(N);
    vector<int>X(N);
    for (int i = 0; i < N; ++i) {
        cin >> S[i] >> T[i] >> X[i];
    }
    vector<int>D(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> D[i];
    }
    /*
    for (int i = 0; i < N; ++i) {
        S[i] = max(0, S[i] - X[i]);
        T[i] = max(0, T[i] - X[i]);
    }
     */

    vector<tuple<int, int, int>> timeline;
    timeline.reserve(N*2+Q);
    for (int i = 0; i < N; ++i) {
        timeline.push_back(make_tuple(S[i] - X[i], 0, X[i])); // 追加クエリ
        timeline.push_back(make_tuple(T[i] - X[i], -1, X[i])); // 削除クエリ
    }
    for (int i = 0; i < Q; ++i) {
        timeline.push_back(make_tuple(D[i], 1, 0)); // 求値クエリ
    }
    sort(timeline.begin(), timeline.end());
    set<int> se;
    vector<int> ans;
    ans.reserve(Q);
    for (int i = 0; i < timeline.size(); ++i) {
        int k = get<1>(timeline[i]);
        int x = get<2>(timeline[i]);
        if(k == 1){
            if(se.size() == 0){
                ans.push_back(-1);
            } else{
                auto iter = se.begin();
                ans.push_back(*iter);
            }
        } else if(k == 0){
            se.insert(x);
        } else{
            se.erase(x);
        }
    }

    for (int i = 0; i < Q; ++i) {
        cout << ans[i] << "\n";
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s;cin>>s;

  int result=0;
  rep(i, 3)if(s[i]=='R')result=1;
  rep1(i, 2)if(s[i-1]=='R' && s[i]=='R')result=2;
  if(s[0]==s[1] && s[1]==s[2] && s[2]=='R')result=3;

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
struct node{
	int to,next;
}e[1000010];
int  n,w[10000010],m,tot,h[1000100],ans,du[1000010],t1[100001],t2[100001],cnt;
bool vis[1000100];
int tong[1000010];
void add(int from,int to)
{
	du[from]++,du[to]++;
	e[++tot].next=h[from];
	e[tot].to=to;
	h[from]=tot;
}
void dfs1(int now)
{
	vis[now]=1;
	t1[++cnt]=now;
	t2[cnt]=w[now];
	for(register int i=h[now];i;i=e[i].next)
	{
		int to=e[i].to;
		if(!vis[to])
		dfs1(to);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;++i) scanf("%d",&w[i]);
	for(register int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	ans=0;
	for(register int i=1;i<=n;++i){
		if(!vis[i])
		{
			cnt=0;
			dfs1(i);
			for(int j=1;j<=cnt;++j) tong[t1[j]]=1;
			for(register int j=1;j<=cnt;++j)
			{
				if(tong[t2[j]]) ans++;
			}
			for(int j=1;j<=cnt;++j) tong[t1[j]]=0;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 13952
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define RFOR(i,a,n) for(int i = (a)-1; i >= (n); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

#define abs(x) ((x) > 0 ? (x) : (-(x)))

int mid(int x, int y, int z) {
  int minv = min(x, min(y, z));
  if (minv == x) return min(y,z);
  else if (minv == y) return min(x,z);
  else return min(x,y);
}


int main() {
  int n; cin >> n;
  vector<int> a(n+2);
  FOR(i,1,n+1) cin >> a[i];
  int route = 0;
  FOR(i,1,n+2) route += abs(a[i] - a[i-1]);
  FOR(i,1,n+1) {
    if (mid(a[i-1], a[i], a[i+1]) == a[i]) {
      cout << route << endl;
    } else if (mid(a[i-1], a[i], a[i+1]) == a[i-1]) {
      cout << route - 2*abs(a[i] - a[i-1]) << endl;
    } else {
      cout << route - 2*abs(a[i+1] - a[i]) << endl;
    }
  }
  return 0;
}


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

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

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

  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  double down = 0;
  rep(i, n) {
    down += 1.0/a[i];
  }

  cout << fixed << setprecision(10);
  cout << 1.0/down << '\n';
  return 0;
}


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	/* inline operator ll () { ll x; return scanf("%lld", &x), x; } */
	/* template<class T> inline void operator () (T &x) { x = *this; } */
	/* template<class T, class ...A> inline void operator () (T &x, A &...a) */
	/* { x = *this; this -> operator () (a...); } */
} read;

const int maxn = 205;
int a[maxn], ap;
int match[maxn];
bool vis[maxn];
bool nop[10000005];

bool find (int p) {
	for (int i = 1; i <= ap; i ++)
		if (!vis[i] and a[i] & 1 and !nop[std::abs(a[i] - a[p])]) {
			vis[i] = 1;
			if (!match[i] or find(match[i])) {
				match[i] = p;
				return 1;
			}
		}
	return 0;
}

int main () {
	int N = 10000000;
	nop[1] = 1;
	for (int i = 2; i <= N; i ++)
		if (!nop[i]) {
			if (i <= N / i)
				for (int j = i * i; j <= N; j += i)
					nop[j] = 1;
		}

	int n = read;
	for (int i = 1, las = -1; i <= n; i ++) {
		int x = read;
		if (x - 1 == las)
			a[ap] = x;
		else {
			a[++ ap] = x - 1;
			a[++ ap] = x;
		}
		las = x;
	}

	int tot = 0;
	for (int i = 1; i <= ap; i ++)
		if (!(a[i] & 1)) {
			std::fill(vis, vis + ap + 1, 0);
			tot += find(i);
		}

	int A = -tot, B = -tot;
	for (int i = 1; i <= ap; i ++)
		a[i] & 1 ? ++ A : ++ B;

	printf("%d\n", ap - tot + (A & 1));
}


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

int main() {
  int N, M, x, y, i;
  cin >> N >> M >> x >> y;
  
  vector<int> X(N + 1);
  vector<int> Y(M + 1);
  X.at(0) = x;
  Y.at(0) = y;
  for(i = 1; i <= N; i++){
    cin >> X.at(i);
  }
  for(i = 1; i <= M; i++){
    cin >> Y.at(i);
  }
  
  int xmax, ymin;
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  xmax = X.at(N);
  ymin = Y.at(0);
  
  if(xmax < ymin){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

var (
	n    int
	t, a []int
)

const MOD int = 1000000007

func main() {
	fmt.Scan(&n)
	t = make([]int, n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	h := make([]int, n)
	b := make([]bool, n)
	h[0] = t[0]
	b[0] = true
	for i := 0; i < n-1; i++ {
		if t[i+1] > t[i] {
			b[i+1] = true
		}
		h[i+1] = t[i+1]
	}

	if b[n-1] {
		if h[n-1] != a[n-1] {
			fmt.Println(0)
			return
		}
	}
	if h[n-1] < a[n-1] {
		fmt.Println(0)
		return
	}
	b[n-1] = true

	for i := n - 1; i > 0; i-- {
		if a[i-1] > a[i] {
			if b[i-1] {
				if h[i-1] != a[i-1] {
					fmt.Println(0)
					return
				}
			} else {
				b[i-1] = true
				if h[i-1] < a[i-1] {
					fmt.Println(0)
					return
				}
				h[i-1] = a[i-1]
			}
		} else {
			if b[i-1] {
				if h[i-1] > a[i-1] {
					fmt.Println(0)
					return
				}
			}
			h[i-1] = min(h[i-1], a[i-1])
		}
	}

	ans := 1
	for i := 0; i < n; i++ {
		if b[i] {
			continue
		}
		ans *= h[i]
		ans %= MOD
	}
	fmt.Println(ans)

}

func printArr(a []int) {
	for i := 0; i < len(a); i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}
func printBl(a []bool) {
	for i := 0; i < len(a); i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}


Measured memory_bytes: 7312
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*((K+1)//2)+(len(S)//2+1)*(K//2)))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll h,n; cin>>h>>n;
	vl v(n);
	rep(i,0,n){
		cin>>v[i];
	}
	sort(all(v));
	ll c=0;
	for(int i=n-1;i>=0;i--){
		c+=v[i];
		if(c>=h){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	
	return 0;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 303;

string s;
int kk;
int d[N][N][N];

int main() {
    ios::sync_with_stdio(false);

    cin >> s >> kk;
    int n = sz(s);
    for (int i = 0; i <= n; ++i)
        for (int j = 0; i + j <= n; ++j)
            for (int k = 0; k <= kk; ++k) {
                if (i == 0 || j == 0) {
                    d[i][j][k] = 0;
                } else {
                    int &cd = d[i][j][k];
                    cd = (k == 0 ? 0 : d[i][j][k-1]);
                    cd = max(cd, d[i-1][j][k]);
                    cd = max(cd, d[i][j-1][k]);
                    if (s[i - 1] == s[n - j])
                        cd = max(cd, d[i-1][j-1][k] + 1);
                    else if (k != 0)
                        cd = max(cd, d[i-1][j-1][k - 1] + 1);
                }
            }

    int ans = 0;
    for (int i = 0; i < n; ++i)
        ans = max(ans, 1 + d[i][n-i-1][kk] * 2);
    for (int i = 1; i < n; ++i)
        ans = max(ans, d[i][n-i][kk] * 2);
    cout << ans << "\n";

    return 0;
}



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

int n, A;
bitset<N*N> S;

int main(){
  
  cin>>n;
  
  int sum=0;
  
  S=1;
  
  for(int i=0;i<n;i++){
    cin>>A;
    S|=S<<A;
    sum+=A;
  }
  
  int num=ceil(sum/2.0);
  
  for(int i=num;i<=sum;i++){
    if(((S>>i)&bitset<N*N>(1))==1){
      cout<<i<<endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
int main(){
    int N,d[100],c=0,i,a,j;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            if(d[i]<d[j]){
                a=d[i];
                d[i]=d[j];
                d[j]=a;
            }
        }
    }
    a=0;
    for(i=0;i<N;i++){
        if(a!=d[i]){
            c++;
            a=d[i];
        }
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int n;
lin x[101], y[101], h[101];
lin mn[101][101];
lin mx[101][101];

int main(void)
{
    cin >> n;

    rep(k,n)
    {
        cin >> x[k] >> y[k] >> h[k];
    }

    bool isFirst = true;

    rep(k,n)
    {
        rep(i, 101)
        {
            rep(j, 101)
            {
                lin dif = abs(i - x[k]) + abs(j - y[k]);
                lin cmx = h[k] + dif;
                lin cmn = h[k] != 0 ? cmx : 0;

                if(isFirst)
                {
                    mx[i][j] = cmx;
                    mn[i][j] = cmn;
                }
                else
                {
                    mx[i][j] = min(mx[i][j], cmx);
                    mn[i][j] = max(mn[i][j], cmn);
                }
            }
        }

        isFirst = false;    
    }

    rep(i, 101)
    {
        rep(j, 101)
        {
            if(mn[i][j] == mx[i][j])
                cout << i << " " << j << " " << mn[i][j] << endl;
        }
    }    
    return 0;
}


Measured memory_bytes: 384
//https://atcoder.jp/contests/abc150/tasks/abc150_c
//C - Count Order
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 <class T>
struct fenwick_tree {
    int n;
    std::vector<T> x;
    fenwick_tree(int n_ = 0) : n(n_), x(n + 1, 0) {}
    int size() const { return n; }
    T sum(int r) const {
        T S = 0;
        for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
        return S;
    }
    T sum(int l, int r) const { return sum(r) - sum(l); }
    void add(int k, const T &a) {
        for (; k < n; k |= k + 1) x[k] += a;
    }
    void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
};

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif    
    ll N; cin>>N;
    vector<ll> pn(N);
    for(auto&& p:pn){ cin>>p; }
    vector<ll> qn(N);
    for(auto&& q:qn){ cin>>q; }

    vector<ll> fact(N+1);
    fact.at(1)=1;
    FOR(i,2,N+1){
        fact.at(i)=fact.at(i-1)*i;
    }

    auto lambda_count = [&](const auto& vec){
        ll result=0;
        fenwick_tree<ll> bit(N+1);
        FOR(i,0,vec.size()){
            ll va = vec.at(i);
#if LOCAL
            ll cnt=0;
            FOR(j,i+1,vec.size()){
                if(va>vec.at(j)) ++cnt;
            }
#endif
            ll cnt2 = va-1-bit.sum(va);
            result += (fact.at(N-i-1)*cnt2);
            dump(N-i,cnt,result,cnt2);

            bit.add(va,1);
        }
        return result+1;
    };
    //dump(lambda_count(vector<ll>{1,2,3}));

    ll a=lambda_count(pn);
    ll b=lambda_count(qn);
    dump(a,b);
    ll ans=abs(a-b);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
long long power(long long x, unsigned long long y, unsigned int m){
    if(y == 0) return 1;
    unsigned long long p = power(x, y/2, m) % m;
    p = (p * p) % m;
    
    if(y & 1)
        return  ((x % m)*p) % m;
    else 
        return p;
}
bool chk(vector<int>& lvl, int m, int x){
	FOR1(i, m){
		if(lvl[i] < x){
			return false;
		}
	}
	return true;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	int T=1;
	//cin >> T;
	FOR1(tp, T)  
	{
		//cout << "Case #" << i << ": ";
		int n, m, x; cin >> n >> m >> x;
		vector<vector<int>> v;
		FOR(i, n){
			vector<int> tmp;
			FOR(i, m+1){
				int x; cin >> x; tmp.pb(x);
			}
			v.emplace_back(tmp);
		}
		int mini = INF;
		vector<vector<int>> curr;
		int pow_set_size = power(2, n, LLONG_MAX);
		for(int c = 0; c < pow_set_size; c++) { 
			int curr = 0;
			vector<int> lvl(m+1, 0);
			for(int j = 0; j < n; j++) { 
				if(c & (1 << j)){
					// consider jth element
					auto row = v[j];
					curr += row[0];
					FOR1(k, m){
						lvl[k] += row[k];
					}

				}
					
			}
			if(chk(lvl, m, x)) mini = min(mini, curr);
		}
		cout << (mini == INF? -1 : mini);
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define int long long

int x, y, n, val[10], a[10][10];

inline int F(int x, int y) {
	if (x == y) return 0;
	if (-x == y) return 1;
	if (x < y) return y - x;
	return 1e18;
}

signed main(void) {
	cin >> x >> y;
	n = 4;
	val[1] = x; val[2] = y; val[3] = -x; val[4] = -y;
	rep (i, 4) rep (j, 4) a[i][j] = i == j ? 0 : F(val[i], val[j]);
	rep (k, 4) rep (i, 4) rep (j, 4) a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	cout << a[1][2] << "\n";
}
				


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};

mint Pow(ll m, ll n){
	if(n==0) return 1;
	mint x = Pow(m,n/2);
	x *= x;
	if(n%2==1) x *= m;
	return x; 
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    mint ans = 0;
    rep(i,60){
    	mint cnt1=0, cnt0=0;
    	rep(j,N){
    		//cout << (1LL<<i) << endl;
    		if(A[j]&(1LL<<i)) cnt1+=1;
    		else cnt0+=1;
    	}
    	ans += cnt1*cnt0 * Pow(2,i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main()
{
	int x,y;
	int a[] = {1,3,1,2,1,2,1,1,2,1,2,1};

	scanf("%d %d",&x,&y);

	if ( a[x-1] == a[y-1] ) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
import collections
s = input()
t = input()
loop = len(s)
s_col = collections.Counter(s)
t_col = collections.Counter(t)
# print("s_col", s_col)
s_l = sorted(s_col.values())
# print(len(s_col))
# print("s_l", s_l)
# print("t_col", t_col)
t_l = sorted(t_col.values())
# print("t_l", t_l)
# print(len(t_col))
if s_l == t_l:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 4016
import sys
read_=sys.stdin.buffer.readline

A=int(read_())
B=int(read_())
C=int(read_())
X=int(read_())

ans=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                ans+=1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<" "<<#x<<"="<<x

#define bit(k) (1LL<<(k))

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/
//dp[i][j]: 下からi桁目まで決めたときに、紙幣の最小値
//（桁iで桁上がりしてるかどうかを持つflag j）
int N;
ll dp[1001001][2];
void debug(){
    cerr<<"---------------------"<<endl;
    rep(i,N){
        rep(j,2){
            cerr<<dp[i][j]<<" ";
        }
        cerr<<endl;
    }
    cerr<<"---------------------"<<endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin>>S;
    reverse(all(S));
    S += '0';
    cerr<<S<<endl;
    N = S.size();
    rep(i,N+1)rep(j,2){
        dp[i][j] = INFLL;
    }
    dp[0][0] = 0;
    rep(i,N)rep(j,2){
        //i桁目に設定する値
        int sita = S[i] - '0';
        if(j)sita++;
        rep(a,10){
            int ni = i+1;
            int nj = 0;
            int b = a - sita;
            if(b < 0){
                nj++;
                b += 10;
            }
            chmin(dp[ni][nj], dp[i][j] + a + b);
        }
    }
    cout<<dp[N][0]<<endl;
}

Measured memory_bytes: 17052
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
int a[6060];
int dp[2020][2020][3];
int mx[2020][2020][3];
int mx1[2020][3], mx2[2020][3];
int mx3[3];
int c[2020];
int s[2020];
int main()
{
    cin>>n;
    for(int i=0; i<3*n; i++){
        cin>>a[i]; a[i]--;
    }
    a[3*n]=a[3*n+1]=n;
    for(int i=1; i<=n; i++){
        if(a[3*i+1]==a[3*i] && a[3*i]==a[3*i-1]) c[i]++;
    }
    for(int i=0; i<=n; i++) s[i+1]=s[i]+c[i];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<3; k++) dp[i][j][k]=-1, mx[i][j][k]=-n-1, mx1[i][k]=-n-1, mx2[i][k]=-n-1, mx3[k]=-n-1;
        }
    }
    dp[0][a[0]][0]=0;
    mx[a[1]][a[0]][0]=0;
    mx1[a[1]][0]=mx2[a[0]][0]=mx3[0]=0;
    int ans=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<3; k++){
                int x1=-1, x2=-1;
                for(int l=0; l<3; l++){
                    if(l==k) continue;
                    if(x1==-1) x1=a[3*i+1-l];
                    else x2=a[3*i+1-l];
                }
                if(x1==x2){
                    for(int l=0; l<3; l++) dp[i][j][k]=max(dp[i][j][k], mx[j][x1][l]+s[i]+1);
                    for(int l=0; l<3; l++) dp[i][j][k]=max(dp[i][j][k], mx[x1][j][l]+s[i]+1);
                }
                for(int l=0; l<3; l++){
                    dp[i][j][k]=max(dp[i][j][k], mx1[j][l]+s[i]);
                    dp[i][j][k]=max(dp[i][j][k], mx2[j][l]+s[i]);
                }
                for(int l=0; l<3; l++){
                    if(k==l) continue;
                    if(a[3*i+1-l]!=j) continue;
                    for(int m=0; m<3; m++){
                        if(k==m || l==m) continue;
                        for(int p=0; p<3; p++) dp[i][j][k]=max(dp[i][j][k], mx[a[3*i+1-m]][a[3*i+1-m]][p]+s[i]+1);
                        for(int p=0; p<3; p++) dp[i][j][k]=max(dp[i][j][k], mx3[p]+s[i]);
                    }
                }
            }
        }
        for(int j=0; j<=n; j++){
            for(int k=0; k<3; k++){
                ans=max(ans, dp[i][j][k]);
                mx[a[3*i+1-k]][j][k]=max(mx[a[3*i+1-k]][j][k], dp[i][j][k]-s[i+1]);
                mx1[a[3*i+1-k]][k]=max(mx1[a[3*i+1-k]][k], dp[i][j][k]-s[i+1]);
                mx2[j][k]=max(mx2[j][k], dp[i][j][k]-s[i+1]);
                mx3[k]=max(mx3[k], dp[i][j][k]-s[i+1]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> v(N);
    double mean = 0;
    for (int i = 0; i < N; i++){
        cin >> v[i];
        mean += v[i];
    } 
    mean /= N;
    int imean = round(mean);

    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += (v[i]-imean) * (v[i]-imean);
    }
    
    cout << ans << endl;
}

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

using namespace std;

int main() {
    char c; cin >> c;
    char a[5] = {'a', 'e', 'i', 'o', 'u'};
    for (int i = 0; i < 5; i++) {
        if (a[i] == c) {
            cout << "vowel" << "\n";
            exit(0);
        }
    }
    cout << "consonant" << "\n";
}

Measured memory_bytes: 3624
p = []
q = []
while True:
    n = int(input())
    m = 0
    number = [0] * 4000
    if n == 0:
        break
    else:
        for i in range(n):
            p.append(i)
            q.append(i)
            e,p[i],q[i] = [int(s) for s in input().split(' ')]
            if number[e] >= 1000000:
                break
            else:
                number[e] = number[e] + p[i] * q[i]
                if number[e] >= 1000000:
                    print(e)
                else:
                    m = m + 1
            if m == n:
                print('NA')



Measured memory_bytes: 5768
#include <iostream>
#include <math.h>
#define Max 200000
#define Mod 998244353
using namespace std;
long long ans = 1;
int N,D[Max], a[Max];
int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++){
		cin >> D[i];a[D[i]]++;
	}
	if (D[1] != 0)ans = 0;
	for (int j = 2; j <= N; j++){
		ans = ((ans)%Mod * (a[D[j] - 1] % Mod)) % Mod;
	}
	cout << ans%Mod;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define N 2000

int solve(int,int);

int A[N],a;

int main(){
  int i,j,b,k;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&b);
  for(j=0;j<b;j++){
    scanf("%d",&k);
    if(solve(0,k)==1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i,int m){
  int res;

  if(m==0) return 1;
  if(i>=a) return 0;
  
  res=solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
#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 MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> VI;
typedef vector<VI> VVI;

int main(){
    char n[4];
    int a,b,c,d;
    cin >> n;
    a = n[0]-'0'; b = n[1]-'0'; c = n[2]-'0'; d = n[3]-'0';

    if (a+b+c+d==7) {
        cout << a <<"+"<< b <<"+"<< c <<"+"<< d << "=7" << endl;;
    }
    else if (a+b+c-d==7) {
        cout << a <<"+"<< b <<"+"<< c <<"-"<< d << "=7" << endl;;
    }
    else if (a+b-c+d==7) {
        cout << a <<"+"<< b <<"-"<< c <<"+"<< d << "=7" << endl;;
    }
    else if (a-b+c+d==7) {
        cout << a <<"-"<< b <<"+"<< c <<"+"<< d << "=7" << endl;;
    }
    else if (a+b-c-d==7) {
        cout << a <<"+"<< b <<"-"<< c <<"-"<< d << "=7" << endl;;
    }
    else if (a-b+c-d==7) {
        cout << a <<"-"<< b <<"+"<< c <<"-"<< d << "=7" << endl;;
    }
    else if (a-b-c+d==7) {
        cout << a <<"-"<< b <<"-"<< c <<"+"<< d << "=7" << endl;;
    }
    else if (a-b-c-d==7) {
        cout << a <<"-"<< b <<"-"<< c <<"-"<< d << "=7" << endl;;
    }

    return 0;
}
   


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

int main(){
  int n,a,count=0,man;
  cin>>n>>a;
  string s;
  cin>>s;
  for(int i=0;i<n-1;i++){
    if(s.at(i)!=s.at(i+1)){
      count++;
    }
  }
  man=n-count-1;
  if(count-(2*a)>0){cout<<man+(2*a)<<endl;}
  else{cout<<n-1<<endl;}
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int m;cin>>m;
  cout<<24+24-m<<endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans=0;
		int n = sc.nextInt();
		int[] in = new int[n];
		for(int i=0;i<n;i++) in[i] = sc.nextInt();
		for(int t=0;t<n;t++){
			int num = in[t];
			if(num==1) continue;
			boolean f = true;
			for(int i=2;i*i<=num;i++){
				if(num%i==0){
					f = false;
					break;
				}
			}
			
			if(f) ans++;
		}
		cout(ans);
	}
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
}

Measured memory_bytes: 41004
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
vi G[MAX_N];
bool used[MAX_N];
int X, Y;

void loop(int v) {
	used[v] = true;
	if(v < 100000) X++;
	else Y++;
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		if(!used[n]) loop(n);
	}
}

void solve() {
	cin >> N;
	rep(i, 0, N) {
		int x, y; cin >> x >> y; x--; y--;
		G[x].pb(y + 100000);
		G[y + 100000].pb(x);
	}
	ll ans = 0;
	rep(i, 0, 200000) {
		if(used[i]) continue;
		X = 0; Y = 0;
		loop(i);
		ans += 1ll * X * Y;
		// if(X * Y) debug(i, X, Y);
	}
	cout << ans - N << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

using namespace std;

typedef long long ll;

const int MAX = 2000000;
const ll INF (1 << 30);

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int H, A[MAX+1];

void max_heapify(int i) {
    int l = left(i), r = right(i), largest = i;
    if (l <= H && A[l] > A[i]) {
        largest = l;
    }
    if (r <= H && A[r] > A[largest]) {
        largest = r;
    }
    if (largest != i) {
        swap(A[i], A[largest]);
        max_heapify(largest);
    }
}

void build_max_heap() {
    for (int i = H / 2; i >= 1; i--) {
        max_heapify(i);
    }
}

int extract() {
    if (H < 1) return -INF;
    int maxv = A[1];
    A[1] = A[H--];
    max_heapify(1);
    return maxv;
}

void increase_key(int i, int key) {
    if (key < A[i])
        return;
    A[i] = key;
    while (i > 1 && A[i / 2] < A[i]) {
        swap(A[i], A[i / 2]);
        i /= 2;
    }
}

void insert(int key) {
    H++;
    A[H] = - INF;
    increase_key(H, key);
}


int main() {

    while (true) {
        string com; cin >> com;
        if (com[0] == 'e' && com[1] == 'n')
            break;
        if (com[0] == 'i') {
            int key; cin >> key;
            insert(key);
        } else {
            cout << extract() << endl;
        }   
    }
}



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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n;
lli px,py,pt;
lli x,y,t;

void error(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  cin >> n;
  for(lli i = 0;i < n;i++){
    cin >> t >> x >> y;
    lli d = abs(px-x) + abs(py-y);
    if(d > (t-pt) || ((t-pt)-d)%2 != 0) error();
    px = x;py = y;pt = t;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int n,a[200005],c[22],now;
long long ans,sum;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int p=0;
	for (int i=1;i<=n;i++){
		while (p<n && (now|a[p+1])==sum+a[p+1]) 
			p++,now|=a[p],sum+=a[p];  
		ans=ans+p-i+1;
		now^=a[i],sum-=a[i];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4560
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const long long INF = 1LL << 60;
const int N_MAX = 300;
const int M_MAX = 300 * (300 - 1) / 2;

void warshallFloyd(int N,long long G[N_MAX][N_MAX]){
    for(int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(G[i][j] > G[i][k] + G[k][j]){
                    G[i][j] =  G[i][k] + G[k][j];
                }
            }
        }
    }
}

int main(){
    int N,M,L,Q;
    long long G1[N_MAX][N_MAX] = {0};
    long long G2[N_MAX][N_MAX] = {0};

    for(int i = 0;i < N_MAX;i++){
        for(int j = 0;j < N_MAX;j++){
            G1[i][j] = INF;
            G2[i][j] = INF;
        }
    }

    cin >> N >> M >> L;
    for(int i = 0;i < M;i++){
        int a,b,c;
        cin >> a >> b >> c;
        G1[a - 1][b - 1] = c;
        G1[b - 1][a - 1] = c;
    }

    warshallFloyd(N,G1);

    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            if(G1[i][j] <= L)G2[i][j] = 1;
        }
    }

    warshallFloyd(N,G2);

    cin >> Q;
    for(int i = 0;i < Q;i++){
        int s,t;
        long long ans = 0;

        cin >> s >> t;

        ans = G2[s - 1][t - 1];

        if(ans == INF)cout << -1 << endl;
        else cout << ans - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
struct SegmentTree
{
  const int INF = 1 << 30;
 
  vector< int > small, add;
  int sz;
 
  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    small.assign(2 * sz - 1, 0);
    add.assign(2 * sz - 1, 0);
  }
  inline void Merge(int k)
  {
    small[k] = min(small[2 * k + 1] + add[2 * k + 1], small[2 * k + 2] + add[2 * k + 2]);
  }
  inline int RangeMinimumQuery(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return(INF);
    if(a <= l && r <= b) return(small[k] + add[k]);
    int L = RangeMinimumQuery(a, b, 2 * k + 1, l, (l + r) >> 1);
    int R = RangeMinimumQuery(a, b, 2 * k + 2, (l + r) >> 1, r);
    return(min(L, R) + add[k]);
  }
  int RangeMinimumQuery(int a, int b)
  {
    return(RangeMinimumQuery(a, b, 0, 0, sz));
  }
  inline void RangeAdd(int a, int b, int x, int k, int l, int r)
  {
    if(a >= r || b <= l) return;
    if(a <= l && r <= b) {
      add[k] += x;
      return;
    }
    RangeAdd(a, b, x, 2 * k + 1, l, (l + r) >> 1);
    RangeAdd(a, b, x, 2 * k + 2, (l + r) >> 1, r);
    Merge(k);
  }
  void RangeAdd(int a, int b, int x)
  {
    return(RangeAdd(a, b, x, 0, 0, sz));
  }
};

int main()
{
  int N, Q;

  scanf("%d %d", &N, &Q);
  char S[300001];
  scanf(" %s", S);
  SegmentTree tree(N);
  set< int > close;
  for(int i = 0; i < N; i++) {
    tree.RangeAdd(i, N, S[i] == '(' ? +1 : -1);
    if(S[i] == ')') close.insert(i);
  }
  while(Q--) {
    int q;
    scanf("%d", &q);
    --q;
    tree.RangeAdd(q, N, S[q] == ')' ? +2 : -2);
    if(S[q] == '(') {
      close.insert(q);
      S[q] = ')';
      printf("%d\n", *close.begin() + 1);
      tree.RangeAdd(*close.begin(), N, +2);
      S[*close.begin()] = '(';
      close.erase(close.begin());
    } else {
      close.erase(q);
      S[q] = '(';
      int low = -1, high = N - 1;
      while(high - low > 1) {
        int mid = (low + high) >> 1;
        if(tree.RangeMinimumQuery(mid, N) >= 2) high = mid;
        else low = mid;
      }
      while(S[q] == ')') ++high;
      printf("%d\n", high + 1);
      tree.RangeAdd(high, N, -2);
      S[high] = ')';
      close.insert(high);
    }
  }
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int A, B;
  cin >> A >> B;
  string ret = (max(A, B) <= 8) ? "Yay!" : ":(";
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256