akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        val: String,
    };

    let n = val.chars().filter(|&c| c == '1').count();
    println!("{}", n);
}


Measured memory_bytes: 2120
n=int(raw_input())
r=n+1
l=1
while r-l>1:
    m=(r+l)/2
    if m*(m+1)/2>n:
        r=m
    else:
        l=m
if l*(l+1)/2==n:
    for i in xrange(1,l+1):
        print(i)
else:
    for i in xrange(1,l+2):
        if (l+1)*(l+2)/2-i==n:
            idx=i
            break
    for i in xrange(1,l+2):
        if i==idx:continue
        print(i)


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

using namespace std;

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if (a == 0)
        cout << 1 << endl;
    else if (b == 0)
        cout << 2 << endl;
    else if (c == 0)
        cout << 3 << endl;
    else if (d == 0)
        cout << 4 << endl;
    else
        cout << 5 << endl;

    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int p[n];
	int max = -INF;
	int ans = 0;
	REP(i, n){
		cin >> p[i];
		ans += p[i];
		if (max < p[i]) max = p[i];
	}

	cout << ans - max / 2 << endl;



}


Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>

int row[8], col[8], dpos[8 * 2 - 1], dneg[8 * 2 - 1];

void recursive(int);
void printboard(void);
int main(void)
{
  int i, k, r, c;
    scanf("%d", &k);
  for (i = 0; i < k; i++) {
    scanf("%d %d", &r, &c);
    row[r] = c + 1;
    col[c] = dpos[r+c] = dneg[r-c+7]=1;
  }
  recursive(0);
}
void recursive(int k)
{
  int i, j;
  if (k == 8) {
    for (i = 0; i < 8; i++) {
      for (j = 0; j < 8; j++) {
        printf("%c", (row[i] == j + 1) ? 'Q' : '.');
      }
      putchar('\n');
    }
    return;
  }
  if (row[k]) {
    recursive(k + 1);
    return;
  } else {
    for (i = 0; i < 8; i++) {
      if ( col[i] || dpos[k+i] || dneg[k-i+7]) continue;
      row[k] = i + 1;
      col[i] = dpos[k+i] = dneg[k-i+7] = 1;
      recursive(k + 1);
      row[k] = col[i] = dpos[k+i] = dneg[k-i+7] = 0;
    }
  }
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


map<ll,int> prime_factor(ll n) {
    map<ll,int> res;
    repr(i,2,sqrt(n)+1) {
        while (n%i==0) {
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) ++res[n];
    return res;
}

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

    ll n,p;
    cin >> n >> p;
    map<ll,int> pf=prime_factor(p);
    ll ans=1;
    repitr(itr,pf) {
        ans*=pow(itr->first, itr->second/n);
    }
    cout << ans << endl;

        
    
    return 0;   
}

Measured memory_bytes: 3996
n = int(input())
x0 = [0] * 60
x1 = [0] * 60
for i in map(int,input().split()):
  i = bin(i)[2:]
  i = '0'*(60-len(i)) + i
  for j in range(60):
    if i[-j-1] == '0':
      x0[j] += 1
    else:
      x1[j] += 1
ans = 0
for i in range(60):
  ans += (x0[i]*x1[i]*pow(2,i,10**9+7)) % (10**9+7)
print(ans%(10**9+7))

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

int main() {
	// your code goes here
	long long int n,i,j;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(i=0;i<n;i++)
	{
	    cout<<s[i]<<t[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  int b = 0;
  cin >> a;
  if (a[0] == '1') b++;
  if (a[1] == '1') b++;
  if (a[2] == '1') b++;
  cout << b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

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


int main(void)
{
	int n;



	cin >> n;
	ll ans = 0;

	unordered_map<string,ll> moji;
	
	rep(i, n)
	{
		string s;
		cin >> s;
		sort(s.begin(), s.end());

		
		ans += moji[s];
		moji[s] ++;
	}

	cout << ans << endl;
}

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

const int INF = 0x3f3f3f3f;
const int MAXN = 3E5 + 10;
int dp_left_w[MAXN];
int dp_right_e[MAXN];
int main() {
  int n;
  string s;
  while (cin >> n >> s) {
    // cout << s << endl;
    int ans = INF;
    memset(dp_left_w, 0, sizeof dp_left_w);
    memset(dp_right_e, 0, sizeof dp_right_e);
    for (int i = 1; i < n; ++i)
      dp_left_w[i] = dp_left_w[i-1] + (s[i-1] == 'W');
    for (int i = n-2; i >= 0; --i)
      dp_right_e[i] = dp_right_e[i+1] + (s[i+1] == 'E');

    for (int i = 0; i < n; ++i) {
      ans = min(ans, dp_left_w[i] + dp_right_e[i]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3076
# ABC064D - Insertion
# https://www.hamayanhamayan.com/entry/2017/06/10/224823
def main():
    N = int(input())
    S = input().rstrip()
    cnt, pre = 0, 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
            if cnt < 0:
                pre = max(pre, abs(cnt))
    S = "(" * pre + S
    cnt = 0
    for i in S:
        if i == "(":
            cnt += 1
        else:
            cnt -= 1
    S += ")" * cnt
    print(S)
    


if __name__ == "__main__":
    main()

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

int main() {
	int N;
	cin >> N;
	int A[N], B[N], C[N];
	for (int i=0; i<N; i++){
	    cin >> A[i];
	}
	for (int i=0; i<N; i++){
	    cin >> B[i];
	}
	for (int i=0; i<N-1; i++){
	    cin >> C[i];
	}
	int sum=0;
    for (int i=0; i<N; i++){
        sum+=B[A[i]-1];
        if (i<N-1 && A[i]+1==A[i+1]){
            sum+=C[A[i]-1];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

void clear(queue<int> &q ){
   queue<int> empty;
   swap( q, empty );
}

int main() {
  int n;cin >> n;
  queue<int> q;

  int mx=0;
  int sec=0;
  reps(i,n){
    int a;cin >> a;
    if(a>mx) {sec=mx;mx=a;clear(q);q.push(i);}
    else if(a==mx) { q.push(i);}
    else sec=max(sec,a);
  }

  if(q.size()>1){
    reps(i,n)cout << mx << endl;
    return 0;
  }

 reps(i,n){
    int p=q.front();
    if(i==p){q.pop();cout << sec<< endl;}
    else {cout << mx<< endl;}
  }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;


LL sum ;
int n,a[N],d[N];
int main() {
        scanf("%d",&n);
        for(int i = 1; i <= n; ++i) scanf("%d",&a[i]),sum+=a[i];
        if(sum % (1LL*n*(n+1)/2)) {puts("NO");return 0;}
        for(int i = 1; i <= n; ++i) d[i] = a[i] - a[i-1];
        LL k = sum / (1LL*n*(n+1)/2);
        for(int i = 1; i <= n; ++i) {
            if(((d[i] - k)%n+n)%n && d[i] - k < 0) {
                puts("NO");return 0;
            }
        }
        puts("YES");
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll MOD = 1'000'000'007;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  ll n, k;
  cin >> n >> k;
  ll sum1 = 0, sum2 = 0;
  ll ans = 0;
  for (int i = 0; i < n + 1; i++) {
    sum1 += i, sum2 += n - i;
    if (i >= k - 1)
      ans = (ans + (sum2 - sum1 + 1)) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
from sys import stdin

n, l = (int(x) for x in stdin.readline().rstrip().split())
t = [l+i-1 for i in range(1, n+1)]
if 0 in t:
    print(sum(t))
else:
    if sum(t) < 0:
        t.pop(-1)
        print(sum(t))
    else:
        t.pop(0)
        print(sum(t))


Measured memory_bytes: 2940
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
	        Console.WriteLine(ACGT(S));
        }

        static int ACGT(string S)
        {
            var include = new[]{'A', 'C', 'G', 'T'};
            var len = 0;
            var count = 0;
            for (var i = 0; i < S.Length ; ++i) {
                if (include.Contains(S[i])) {
                    count++;
                } else {
                    len = Math.Max(count, len);
                    count = 0;
                }
            }
            len = Math.Max(count, len);
            return len;
        }
    }
}


Measured memory_bytes: 26108
#include<iostream>
using namespace std;
int main(void){
    int a[5];
    a[4]=0;
    for(int i=0;i<4;i++){
        cin >> a[i];
    }
    for(int i=0;i<a[0];i++){
        if(i>=a[1]){
            a[4]=a[4]+a[3];
        }else{
            a[4]=a[4]+a[2];
        }
    }
        cout<<a[4]<<endl;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
A = []
for i in range(n):
    A.append(list(map(int, input().split())))
ans = 10 ** 7
t = 2 ** n
for i in range(t):
    s = [0 for _ in range(m)]
    c = 0
    bin_i = format(i, '012b')
    if len(bin_i) > n:
        bin_i = bin_i[12-n:]
    for j in range(n):
        if bin_i[j] == "1":
            for k in range(m):
                s[k] += A[j][k+1]
            c += A[j][0]
    if  c < ans and min(s) >= x:
        ans = c
if ans == 10 ** 7:
    print(-1)
else:
    print(ans)
    

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


int get_answer(int num){
  int cnt = 0;


  while(!(num&1)){
    num = num/2;
    cnt++;
  }

  return cnt;
}


int main(){


int n;
cin>>n;
int a[n];

long long sum = 0;
for(int i=0;i<n;i++){
  cin>>a[i];

  sum += get_answer(a[i]);
}

cout<<sum<<"\n";

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	long long n,m,result,k;
  	cin >> n;
    result = 0;
  	for(k=1;k<=sqrt(n);k++){
    	if(n%k == 0){
        	m = n/k - 1;
          	if (k < m) result += m;
        }
    }
  	cout << result;
  	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2) printf("%d\n", (a + b) / 2 + 1);
    else printf("%d\n", (a + b) / 2);
    return 0;
}


Measured memory_bytes: 256
n1 = [int(str) for str in input().split()]
n = n1[0]
m = n1[1]
s1 = 0
s2 = 0
s3 = 0
if n == 1:
  o1 = 0
  o2 = 0
  o3 = 0
if n >= 2:
  o1 = 1
  o2 = 0
  o3 = 0
result = 0
  
for x in range(m):
  t = [int(s) for s in input().split()]
  s = t[0]
  c = t[1]
  
  if s == 1:
    if s1 == 0 and c >= o1:
      o1 = c
      s1 += 1
    else:
      if c != o1:
        result = -1
  if s == 2:
    if s2 == 0 and c >= o2:
      o2 = c
      s2 += 1
    else:
      if c != o2:
        result = -1
  if s == 3:
    if s3 == 0 and c >= o3:
      o3 = c
      s3 += 1
    else:
      if c != o3:
        result = -1
  if result == -1:
    break
    
if result != -1:
  if n == 1:
    print(o1)
  if n == 2:
    print(int(o1*10 + o2))
  if n == 3:  
    print(int(o1*100 + o2*10+o3))
else:
  print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  string ans = "";
  rep(i,0,N) {
    ans.push_back(s[i]);
    ans.push_back(t[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    char x, y;
    cin >> x >> y;
    if(x<y) out('<');
    else if(x>y) out('>');
    else out("=");
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int n,x;
   int m[1111],ans=0,minx=10000;
   cin>>n>>x;
   for(int i=0;i<n;i++){
       cin>>m[i];
       x-=m[i];
   }
   ans+=n;
   for(int i=0;i<n;i++){
       minx=min(minx,m[i]);
   }
   ans+=x/minx;
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

int main() {
  kyun;
  int n;
  cin >> n;
  vi data1(n);
  vi data2(n);
  vi data3(n-1);
  rep(i,n) cin >> data1[i];
  rep(i,n) cin >> data2[i];
  rep(i,n-1) cin >> data3[i];
  int ans = 0;
  rep(i,n) {
    ans += data2[data1[i]-1];
    if(i != n-1) if(data1[i+1] - data1[i] == 1) ans += data3[data1[i]-1];
  }
  cout << ans;
  hinata;
}

Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( "\n" );
  var word = data[0];
  var q = data[1];
  var output = [];
  for( var i=0; i<q; i++ ) {
    var cmd = data[2+i].split( ' ' );
    var s = parseInt( cmd[1] );
    var e = parseInt( cmd[2] )+1;    
    if( "print" == cmd[0] ) {
      output.push( word.substring( s, e ) );
    } else if( "reverse" == cmd[0] ) {
      var br = word.substring( s, e );
      word = word.substring( 0, s )+br.split( '' ).reverse().join( '' )+word.substring( e );
    } else if( "replace" == cmd[0] ) {
      word = word.substring( 0, s )+cmd[3]+word.substring( e );
    }
  }
  console.log( output.join( '\n' ) );
});

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int count=0;
  R(i,n){
    int sum=0,d=i;
    while(d){
      sum+=d%10;
      d/=10;
    }
    if(sum>=a&&sum<=b)count+=i;
  }
  cout << count << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

ll cnt[60];

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    rep(i, N) {
        rep(j, 60) {
            if (a[i] >> j & 1) cnt[j]++;
        }
    }

    ll sum = 0;
    rep(i, 60) {
        ll p = 1;
        rep(j, i) {
            p *= 2;
            p %= MOD;
        }
        sum += (((cnt[i] % MOD) * ((N - cnt[i]) % MOD)) % MOD) * p;
        sum %= MOD;
    }
    cout << sum << endl;
}


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

#include <cstdio>

typedef long long ll;
using namespace std;

int main(void){
    
    char c;
    int cnt[26]={};

    while(scanf("%c",&c)!=EOF){
        if(c<='z'&&c>='a'){
            cnt[c-'a']++;
        }
        else if(c<='Z'&&c>='A'){
            cnt[c-'A']++;
        }
    }
    
    for(int i=0;i<26;i++){
        printf("%c : %d\n",'a'+i,cnt[i]);
    }

	return 0;
}


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


#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
typedef pair<ll, ll> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    // ll q,h,s,d;cin >> q >> h >> s >> d;
    vector<ll> b(4);
    priority_queue<P, vector<P>, greater<P>> pq;
    ll num = 8;
    rep(i,4)
    {
        ll temp;cin >> temp;
        b[i] = temp;
        pq.push(P(num*temp,(ll)i));
        num/=2;
    }
    ll n;cin >> n;
    n = 4*n;
    ll sum = 0;
    while(true)
    {
        ll index = pq.top().second;
        pq.pop();
        //cout << index << endl;
        ll div = 1;
        for (ll i = 0; i < index; i++)
        {
            div *= 2;
        }
        
        ll kosu = n/div;
        n %=div;
        //cout << n << endl;
        sum += b[index]*kosu;
        if(n==0)
        {
            break;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

int A[100010];
bool ok[100010];

int ans(int j, int count){
	if(ok[j]) return -1;
	ok[j] = true;
	if(j == 1) return count;
	ans(A[j], count+1);
}

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

	int N;
	cin >> N;
	rep(i,N){
		cin >> A[i];
		--A[i];
	}
	cout << ans(0, 0) << endl;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 4e18 + 1;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

struct pt {
    ll x,y;
};
bool cmpx(const pt &a, const pt &b) {
    return a.x < b.x;
}
bool cmpy(const pt &a, const pt &b) {
   return a.y < b.y;
}

int main (void) {
    int N,K;
    cin>>N>>K;
    vector<pt> p(N);
    REP(i,N) cin>>p[i].x>>p[i].y;
    ll ans = INF;

    REP(i,N) {
        REP(j,N) {
            REP(k,N) {
                REP(l,N) {
                    int xs,xt,ys,yt;
                    if (p[i].x>p[j].x) {
                        xs = j;
                        xt = i;
                    }
                    else {
                        xs = i;
                        xt = j;
                    }
                    if (p[k].y>p[l].y) {
                        ys = l;
                        yt = k;
                    }
                    else {
                        ys = k;
                        yt = l;
                    }
                    int num = 0;
                    REP(m,N) {
                        if (p[m].x>=p[xs].x && p[m].x<=p[xt].x && p[m].y>=p[ys].y && p[m].y<=p[yt].y) 
                            num++;
                    }
                    if (num < K) continue;
                    ll area = (p[xt].x - p[xs].x)*(p[yt].y - p[ys].y);
                    ans = min(ans,area);
                }
            }
        }
    }

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



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int d; cin>>d;
  if(d==22){cout<<"Christmas Eve Eve Eve"<<endl;}
  if(d==23){cout<<"Christmas Eve Eve"<<endl;}
  if(d==24){cout<<"Christmas Eve"<<endl;}
  if(d==25){cout<<"Christmas"<<endl;}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    REP(i, N){
        cin >> C[i];
        REP(j, M){
            cin >> A[i][j];
        }
    }
    int ans = 1<<30;
    for(int i=0; i<(1<<N); i++){
        vector<int> B(M);
        int sm = 0;
        for(int j=0; j<N; j++){
            if(i&(1<<j)){
                for(int k=0; k<M; k++)
                    B[k] += A[j][k];
                sm += C[j];
            }
        }
        bool ok = true;
        for(int j=0; j<M; j++)
            if(B[j] < X){
                ok = false;
                break;
            }
        if(ok) ans = min(ans, sm);
    }
    if(ans==(1<<30)) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
string str[1001];
int dp[1001][1001];
int main()
{
	int h,w;
	cin >> h >> w;
	for(int i=0;i<h;i++)
		cin >> str[i];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<h;i++)
	{
		if(str[0][i]=='.')
			dp[0][i] = 1;
		else
			break;
	}
	for(int i=0;i<w;i++)
	{
		if(str[i][0] == '.')
			dp[i][0] = 1;
		else
			break;
	}
	for(int i=1;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(str[i][j]=='.')
				dp[i][j] = (dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
			else
				dp[i][j] = 0;
		}
	}
	cout << dp[h-1][w-1] << "\n";
}



Measured memory_bytes: 9408
using System;
class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int T = int.Parse(input[1]);
        int[] A = new int[100000];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) A[i] = int.Parse(input[i]);
        int minnum = A[0];
        int mingap = 0;
        int mintime = 0;
        for (int i = 1; i < N; i++)
        {
            if (A[i] < minnum) minnum = A[i];
            else if (A[i] - minnum > mingap)
            {
                mintime = 1;
                mingap = A[i] - minnum;
            }
            else if (A[i] - minnum == mingap) mintime++;
        }
        Console.WriteLine(mintime);
    }
}

Measured memory_bytes: 12248
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

long long dp[101][100001];

int main(){

    int N, W;
    cin >> N >> W;

    vector<int> w(N);
    vector<int> v(N);

    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }

    dp[0][0] = 0;
    for(int i = 1; i < 100001; i++){
        dp[0][i] = 1e9 + 1;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < 100001; j++){
            if(j < v[i - 1]){
                dp[i][j] = dp[i - 1][j];
            }
            else{
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 100001; i++){
        if(dp[N][i] <= W){
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 79104
# -*- coding: utf-8 -*-

###
# main
if(__name__ == '__main__'):
    # input
    x = int(input())

    money = 100
    y = 0
    while money < x:
        money *= 1.01
        money = int(money)
        y += 1

    print(y)
# else:
    # do nothing

Measured memory_bytes: 9168
#include <iostream>

typedef long long ll;

ll count_nth_bit(ll n, ll nth)
{
  if (n < 0) {
    return 0;
  }
  ll divisor = 1LL << nth;
  ll quotient = (n+1) / divisor;
  ll remainder = (n+1) % divisor;
  if (quotient % 2 == 0) {
    return quotient / 2 * divisor;
  } else {
    return quotient / 2 * divisor + remainder;
  }
}

ll solve(ll a, ll b)
{
  ll result = 0;
  for (ll i = 0; i <= 60; i++) {
    ll a_cnt = count_nth_bit(a-1, i);
    ll b_cnt = count_nth_bit(b, i);
    if ((b_cnt - a_cnt) % 2 == 1) {
      result = result | (1LL << i);
    }
  }
  return result;
}

int main()
{
  ll a, b;
  std::cin >> a >> b;
  std::cout << solve(a, b) << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,y;
	cin>>n>>y;
	int s=-1;
	int t=-1;
	int u=-1;
	
	for(int i=0;i<=n;i++){
		for(int j=0;j+i<=n;j++){
			int z=n-i-j;
			if(i*10000+j*5000+z*1000==y){
				s=i;
				t=j;
				u=z;
			}
		}
	}
	cout<<s<<' '<<t<<' '<<u<<endl;

}

Measured memory_bytes: 256
def swit(count, ON_list):
    global ans
    if count == N:
        for l in range(M):
            d = 0
            for m in range(1,len(a[l])):
#                print(ON_list)
                if ON_list[a[l][m]-1] == 1:
                    d = d + 1
            if d % 2 != p[l]:
                return 0
        ans = ans + 1
    else:
        for l in range(2):
            ON_list[count] = l
            swit(count+1, ON_list)

N, M = map(int, input().split())
a = []
for i in range(M):
    b = list(map(int, input().split()))
    a.append(b)
p = list(map(int, input().split()))
ans = 0
swit(0, [0]*N)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	char c=s[0];
	int x=0;
	int y=0;
	int b[4];
	int z[4];
	for(int i=0;i<4;i++)
{
		if(s[i]!=c){
		b[x]=s[i];
		x++;
	}
	else
	{
		z[y]=s[i];
		y++;
	}
}
	if(x==2&&(b[0]==b[1])&&(z[0]==z[1]))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

int main() {
  int N,K;
  cin >> N >>K;
  int x=0;
  for(int i = N;i<=K; i++){
    
     if(i%10==i/10000 &&i/1000%10==i/10%10)
        {x++;}
        }
  cout <<x;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> a(30);
	for(int i = 0; i < s.length(); i++)
	{
		a.at(s.at(i) - 'A')++;
	}

	bool ok = true;
	for (int i = 0; i < a.size(); i++)
	{
		if (!(a.at(i) == 0 || a.at(i) == 2))
		{
			ok = false;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String ans = a.substring(0,5)+" "+a.substring(6,13) + " " +a.substring(14);

        System.out.println(ans);
    }
}


Measured memory_bytes: 39772
from collections import deque
#from math import factorial
import sys
sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
# import collections
n = int(input())
#n, m = list(map(int, input().split()))
d = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = [int(j) for j in input().split()]
    d[u-1].append([v-1, w])  # 対応する頂点と距離
    d[v-1].append([u-1, w])

ans = [-1]*n
stack = [0]
ans[0] = 0

# print(d)
while stack:
    u = stack.pop()  # 見てるとこ
    for v, w in d[u]:  # 対のやつを調べる
        if ans[v] == -1:  # 未訪問の時
            if w % 2 == 0:
                ans[v] = ans[u]  # 対と同じ色
            else:
                ans[v] = (ans[u]+1) % 2
            stack.append(v)
    

for i in ans:
    print(i)


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

int main() {
    string s, t;
    cin >> s >> t;
    // s < tとできるか
    for(int i = 0; i < s.size(); i++) {
        for (int j = 0; j < s.size()-1; j++) {
            if(s[j]>s[j+1]) swap(s[j], s[j+1]);
        }
    }
    for(int i = 0; i < t.size(); i++) {
        for (int j = 0; j < t.size()-1; j++) {
            if(t[j]<t[j+1]) swap(t[j], t[j+1]);
        }
    }
    int len = min(s.size(), t.size());
    string ans = "Yes";
    for (int i = 0; i < len; i++) {
        if(s[i] < t[i]) break;
        if(s[i]>t[i]) ans = "No";
    }
    bool same = true;
    for (int i = 0; i < len; i++) {
        if(s[i]!=t[i]) same = false;
    }
    if(same && s.size()>=t.size()) ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
li = []
while True:
    try:
        li.append(list(map(int,input().split())))
    except:
        break

f_inf = float('inf')
dpa=[li[0][0]]+[0]*(n-1)
dpb=[li[0][1]]+[0]*(n-1)
dpc=[li[0][2]]+[0]*(n-1)

for i in range(1,n):
    dpa[i]=max(dpb[i-1],dpc[i-1])+li[i][0]
    dpb[i]=max(dpa[i-1],dpc[i-1])+li[i][1]
    dpc[i]=max(dpa[i-1],dpb[i-1])+li[i][2]

print(max(dpa[n-1],dpb[n-1],dpc[n-1]))


Measured memory_bytes: 66520
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

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

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

int main() {
	ll ans = 0;
	ll sum = 0;
	ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
	vector<ll> p(A), q(B), r(C);
	for (int i = 0; i < A; i++) {
		cin >> p[i];
		ans += p[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> q[i];
		ans += q[i];
	}
	for (int i = 0; i < C; i++) {
		cin >> r[i];
		ans += r[i];
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());

	vector<ll> h;

	for (int i = 0; i < A - X; i++) {
		sum += p[i];
	}
	for (int i = A - X; i < A; i++) {
		h.push_back(p[i]);
	}
	for (int i = 0; i < B - Y; i++) {
		sum += q[i];
	}
	for (int i = B - Y; i < B; i++) {
		h.push_back(q[i]);
	}
	for (int i = 0; i < C; i++) {
		h.push_back(r[i]);
	}

	sort(h.begin(), h.end());
	for (int i = 0; i < C; i++) {
		sum += h[i];
	}

	cout << ans - sum << endl;

	return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int a[3];
bool solve(int idx, int k) {
	if (a[0] < a[1] && a[1] < a[2])
		return true;
	if (idx == k)
		return false;
	bool ans = false;
	for (int i = 0; i < 3; i++) {
		a[i] = 2 * a[i];
		ans |= solve(idx + 1, k);
		a[i] = a[i] / 2;
	}
	return ans;
}
int32_t main()
{
	GO;
	cin >> a[0] >> a[1] >> a[2];
	int k;
	cin >> k;
	bool ans = solve(0, k);
	cout << ((ans) ? ("Yes") : ("No")) << endl;
	return 0;
}

//!

Measured memory_bytes: 3644
from collections import defaultdict
def calc(x):
    c2, c5 = 0, 0
    if '.' in x:
        x = x.rstrip('0')
        cnt = len(x) - x.index('.') - 1
        c2, c5 = -cnt, -cnt
    x = int(x.replace('.', ''))
    while x % 2 == 0:
        c2 += 1
        x = x // 2
    while x % 5 == 0:
        c5 += 1
        x = x // 5
    return c2, c5
    
    
d = defaultdict(int)
n = int(input())
A = []
for _ in range(n):
    a = input()
    c2, c5 = calc(a)
    d[(c2, c5)] += 1
ans = 0
key = list(d.keys())
for i in range(len(key)):
    c2, c5 = key[i]
    v = d[(c2, c5)]
    if (c2 >= 0) & (c5 >= 0):
        ans += v * (v - 1) // 2
    for j in range(i + 1, len(key)):
        n2, n5 = key[j]
        if ((n2 + c2) >= 0) & ((n5 + c5) >= 0):
            ans += v * d[(n2, n5)]
print(ans)            

Measured memory_bytes: 9484
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let st: String = read();
    let arr = st.split_whitespace().map(|e| e.parse().ok().unwrap()).collect::<Vec<String>>();
    let s = arr[0].to_string();
    let t = arr[1].to_string();

    let ans: String = t+&s;

    println!("{}", ans);
}


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

int n;
bool isSame[105];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int d1, d2; scanf("%d%d", &d1, &d2);
		isSame[i] = d1 == d2;
	}
	for (int i = 2; i < n; i++) {
		if (isSame[i - 2] && isSame[i - 1] && isSame[i]) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 3684
/**
 * Motto:   To Become Better Than Me
 * Author: cherry0697
 **/

 #include<bits/stdc++.h>
 using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define repc(i,a,n) for(i=a;i<n;i++)
#define repa(i,a,n) for(i=a;i<=n;i++)
#define repb(i,a,n) for(i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef vector <long long int> vi;

void solve()
{
  ll n;
  cin>>n;

  ll i,j,k,sum=0;

  for(i=1;i<=n;i++)
  {
    for(j=1;j<=n;j++)
    {
      for(k=1;k<=n;k++)
      {
        sum+=__gcd(i,__gcd(j,k));
      }
    }
  }

  cout<<sum<<"\n";
}

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

  ll t;
  t=1;

  while(t--)
    solve();

return 0;
}


Measured memory_bytes: 3692
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count,temp,answer,i,maxx;
	maxx=0;
	answer=1;
	for(i=1;i<=n;i++)
	{
		temp=i;
		count=0;
		while(temp>=2)
		{
			count++;
			temp=temp/2;
		}
		if(count>maxx)
		{
			maxx=count;
			answer=i;
		}
	}
	cout<<answer;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  bool check = false;

  for(int i = 0;i <= N;i += 4){
      for(int j = 0;i + j <= N;j += 7){
          int total;
          total = i + j;
          if(total == N)check = true;
      }
  }

  if(check){
      cout << "Yes" << endl;
      }
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <numeric>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

vector<int> arr;
int table[101][11];

int solve(int idx, int digit)
{
    if (table[idx][digit] != -1)
        return table[idx][digit];

    int& res = table[idx][digit];

    if (idx == arr.size() - 1)
    {
        if (arr[idx] % 10 == digit)
            return arr[idx];
        else
            return -2;
    }

    res = 0;

    int select = solve(idx + 1, (digit + 10 - arr[idx] % 10) % 10);
    int notSelect = solve(idx + 1, digit);

    if (select == -2 && notSelect == -2)
        return res = -2;

    if (select == -2)
        return res = notSelect;

    if (notSelect == -2)
        return res = select + arr[idx];

    return res = max(select + arr[idx], notSelect);
}

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

    arr.resize(n);

    memset(table, -1, sizeof(table));

    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    int ans = 0;

    for (int i = 1; i < 10; i++)
        ans = max(ans, solve(0, i));

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

    return 0;
}

Measured memory_bytes: 256
#! /usr/local/bin/python3
# coding: utf-8

def count(s, t):
    c = 0
    for x in t:
        for y in s:
            if x == y:
                c += 1
                break
    return c

n = int(input())
s = [int(x) for x in input().split()]

q = int(input())
t = [int(x) for x in input().split()]

print(count(s, t))



Measured memory_bytes: 6560
#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

int main() {
    int A[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << A[k];
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

class UF{
  vector<ll> par,rank,size_x,size_y,size_edge;
public:
  UF(ll size){
    for (ll i = 0; i < size; i++) {
      par.push_back(i);
      rank.push_back(0);
      if(i<100000){size_x.push_back(1);size_y.push_back(0);}
      else {size_y.push_back(1);size_x.push_back(0);}
      size_edge.push_back(0);
    }
  }
  ll find(ll x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  void unite(ll x,ll y){
    x=find(x);
    y=find(y);
    if(x==y){++size_edge[x];return;}
    if(rank[x]<rank[y]){
      par[x]=y;
      size_x[y]+=size_x[x];
      size_y[y]+=size_y[x];
      size_edge[y]+=size_edge[x]+1;
    }
    else{
      par[y]=x;
      size_x[x]+=size_x[y];
      size_y[x]+=size_y[y];
      size_edge[x]+=size_edge[y]+1;
      if(rank[x]==rank[y])rank[x]++;
    }
  }
  bool same(ll x,ll y){
    return find(x)==find(y);
  }
  ll operator [](ll x){
    return this->find(x);
  }
  ll sizeX(ll x){
    x=find(x);
    return size_x[x];
  }
  ll sizeY(ll y){
    y=find(y);
    return size_y[y];
  }
  ll sizeE(ll x){
    x=find(x);
    return size_edge[x];
  }
};

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
  UF uf(200000);
  REP(N){
    uf.unite(x[i],y[i]+100000);
  }
  set<ll> used;
  ll ans=0;
  REP(200000){
    ll tmp=uf.find(i);
    if(used.find(tmp)==used.end()){
      used.insert(tmp);
      ans+=uf.sizeX(tmp)*uf.sizeY(tmp)-uf.sizeE(tmp);
    }
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(ll i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        --x[i];
        --y[i];
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	string s="No";
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++){
			if(i*j == n){
				s = "Yes";
			}
		}
	}
	cout << s << endl;
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    double r,men,syu;
    cin>>r;
    men=r*r*3.141592653589;
    syu=2*r*3.141592653589;
    printf("%f %f\n",men,syu);
    return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//string s;
	int n,m,c=0,t=1,i,j,k,sum=0,ans,f=0,x,y;
	cin>>n>>m;
	vector<int> h(n+1),mx(n+1,0);
	for(int i=1;i<=n;i++) cin>>h[i];
	while(m--){
		cin>>x>>y;
		mx[x]=max(mx[x],h[y]);
		mx[y]=max(mx[y],h[x]);
	}
	for(int i=1;i<=n;i++) if(h[i]>mx[i]) c++;
	cout<<c;
	return 0;
}




Measured memory_bytes: 4728
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>
#include <cstdint>
#include <set>
#include <deque>
#include <iomanip>
#include <queue>

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

#define EPS (1e-7)
#define ALL(x) begin(x), end(x)

constexpr bool isACGT(char c) {
	return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}

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

	int ans = 0;
	for (size_t i = 0; i < S.size(); i++) {
		for (size_t j = 1; j <= S.size() - i; j++) {
			const string str = S.substr(i, j);
			if (all_of(ALL(str), isACGT)) {
				ans = max(ans, (int)j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

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

    string s; cin >> s;
    int n=s.size();
    int x, y; cin >> x >> y;
    vector<int> tate, yoko;

    int pos=0, fcnt=0, tcnt=0;
    while(pos<n){
        if(s[pos]=='T') { ++fcnt; ++pos; }
        else{
            tcnt=1;
            while(pos<n && s[pos+1]=='F') { ++pos; ++tcnt; }
            if(fcnt%2==0) yoko.push_back(tcnt);
            else tate.push_back(tcnt);
            ++pos;
        }
    }

    bool first_right= (s[0]=='F'? true:false);
    // rep(i, yoko.size()) cout << yoko[i] << ' ';
    // cout << endl;
    // rep(i, tate.size()) cout << tate[i] << ' ';
    // cout << endl;

    int base=8010;
    int lim=base*2;
    vector<vector<bool>> dpyoko(2, vector<bool>(lim, false)), dptate(2, vector<bool>(lim, false));
    
    dpyoko[0][base]=true;
    rep(i, yoko.size()) rep(j, lim){
        dpyoko[(i+1)%2][j]=false;
        if( (j-yoko[i]>=0) && (dpyoko[i%2][j-yoko[i]]) )  dpyoko[(i+1)%2][j]=true;

        if( !(i==0&&first_right) && (j+yoko[i]<lim) && (dpyoko[i%2][j+yoko[i]]) ) dpyoko[(i+1)%2][j]=true;
    }

    dptate[0][base]=true;
    rep(i, tate.size()) rep(j, lim){
        dptate[(i+1)%2][j]=false;
        if(j-tate[i]>=0 && dptate[i%2][j-tate[i]]) dptate[(i+1)%2][j]=true;

        if(j+tate[i]<lim && dptate[i%2][j+tate[i]]) dptate[(i+1)%2][j]=true;
    }

    if(dpyoko[yoko.size()%2][x+base] && dptate[tate.size()%2][y+base]) cout << "Yes\n"s;
    else cout << "No\n"s;

    return 0;
}


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

int main(void)
{
	int n,i,j;
	int *a;
	int tmp;

	cin >> n;

	a = new int[n];

	for (i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (i = 0; i < n; i++) {
		j = (n-1-i);
		if (i < j) {
			tmp		= a[i];
			a[i]	= a[j];
			a[j]	= tmp;
		}
		cout << a[i];
		if (i < (n-1)) {
			cout << " ";
		}
	}
	cout << endl;

	delete[] a;
	return 0;
}



Measured memory_bytes: 3044
#include <stdio.h>
#include <math.h>

int main(void){
    int i,j,n,t;
    scanf("%d\n",&n);
    int x[n];
    for (i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    
    for (i=0; i<n; i++) {
      for (j=i+1; j<n; j++) {
        if (x[i] > x[j]) {
          t =  x[i];
          x[i] = x[j];
          x[j] = t;
        }
      }
    }
    
    int k=0;
    int min=1<<29;
    for (i=x[0];i<=x[n-1];i++){
        int p=0;
        for(j=0;j<n;j++){
            p+=pow(x[j]-i,2.0);
        }
        if (min>p) min=p;
        k++;
    }
    
    printf("%d\n",min);
    
    
    
    return 0;
}


Measured memory_bytes: 128