akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int hor[9][2]={
{1,8},{0,2},{1,3},
{2,4},{3,5},{4,6},
{5,7},{6,8},{0,7}
};

int _pow10[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

struct A{
	int cost;
	int emp;
	long long s;
	bool operator<(const A &a)const{
		return cost>a.cost;
	}
};

int main(){
	int ch,cv;
	while(cin>>ch>>cv,ch|cv){
		map<long long,int> mincost;
		map<long long,int>::iterator it;
		long long start=0,goal=0;
		int emp;
		rep(i,9){
			int a;
			cin>>a;
			start+=a*_pow10[i];
			if(a==0)emp=i;
		}
		rep(i,9){
			int a;
			cin>>a;
			goal+=a*_pow10[i];
		}
		A a;
		a.cost=0;
		a.emp=emp;
		a.s=start;
		priority_queue<A> pq;
		pq.push(a);
		mincost[start]=0;
		int ans=1000000000;
		while(!pq.empty()){
			a=pq.top();pq.pop();
			if(mincost[a.s]<a.cost || ans<=a.cost)continue;
			if(a.s==goal){
				ans=a.cost;
				break;
			}
			int e=a.emp;		
			rep(i,2){
				a.cost+=ch;
				a.emp=hor[e][i];
				int x=a.s/_pow10[hor[e][i]]%10;
				a.s+=x*_pow10[e]-x*_pow10[hor[e][i]];
				it=mincost.find(a.s);
				if(a.cost<ans && (it==mincost.end() || a.cost < it->second)){
					mincost[a.s] = a.cost;
					pq.push(a);
					if(a.s==goal)ans=a.cost;
				}
				a.cost-=ch;
				a.emp=e;
				a.s-=x*_pow10[e]-x*_pow10[hor[e][i]];
			}
			rep(i,2){
				int ver=(e+3+i*3)%9;
				a.cost+=cv;
				a.emp=ver;
				int x=a.s/_pow10[ver]%10;
				a.s+=x*_pow10[e]-x*_pow10[ver];
				it=mincost.find(a.s);
				if(a.cost<ans && (it==mincost.end() || a.cost < it->second)){
					mincost[a.s] = a.cost;
					pq.push(a);
					if(a.s==goal)ans=a.cost;
				}
				a.cost-=cv;
				a.emp=e;
				a.s-=x*_pow10[e]-x*_pow10[ver];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
  int lake; // 池の長さを宣言
  int housenum; // 家の数を宣言
  cin >> lake >> housenum; // 池の長さと家の数を入力
  vector<int> housep(housenum); // 家の数だけ位置の変数を宣言
  vector<int> housesd(housenum); // 家の間の距離を家の数だけ宣言
  int mhousesd;

// 家の位置情報を入力
  for (int i = 0; i < housenum; i++){
    cin >> housep.at(i);
  }

// 隣の家同士の距離を算出
  for (int j = 0; j < housenum - 1; j++){
    housesd.at(j) = housep.at(j + 1) - housep.at(j);
  }

// 距離に池の北が含まれる時の例外計算
  housesd.at(housenum - 1) = lake - housep.at(housenum - 1) + housep.at(0);

// 家同士の距離で一番長いものを求める
  mhousesd = 0;
  for (int l = 0; l < housenum; l++) {
    if (mhousesd <= housesd.at(l)){
      mhousesd = housesd.at(l);
    }
  }

// 答えの出力
  cout << lake - mhousesd << endl;

}

Measured memory_bytes: 1792
#include <stdio.h>

//関数プロトタイプ宣言
void moving_north(int *top, int *bottom, int *front, int *back);
void moving_east(int *top, int *bottom, int *right_side, int *left_side);
void rotate_right(int *front, int *back, int *right_side, int *left_side);

//ダイスの構造体
typedef struct{
	int top;
	int bottom;
	int right_side;
	int left_side;
	int front;
	int back;
}Dice;

int main(void)
{
	Dice dice1;
	Dice dice2;

	//iとjはループ変数、flagは2つのダイスが等しいか表す
	int i, j, flag;

	flag = 0;
	//ダイスの目を入力
	scanf("%d %d %d %d %d %d", 
		  &dice1.top, &dice1.front, &dice1.right_side, &dice1.left_side, &dice1.back, &dice1.bottom);
	scanf("%d %d %d %d %d %d", 
		  &dice2.top, &dice2.front, &dice2.right_side, &dice2.left_side, &dice2.back, &dice2.bottom);

	//dice1を基準とし、dice2を転がして各面を比較する
	for(i = 0; i < (4 * 4); i++){
		for(j = 0; j < 4; j++){
			//2つのダイスの目が全て等しければflagに1を代入
			if((dice1.top == dice2.top) && (dice1.bottom == dice2.bottom) && (dice1.front == dice2.front) &&
				(dice1.back == dice2.back) && (dice1.right_side == dice2.right_side) && (dice1.left_side == dice2.left_side)){
					flag = 1;
			}
			//ダイスの向きを変える
			rotate_right(&dice2.front, &dice2.back, &dice2.right_side, &dice2.left_side);
		}

		//ダイスを北側に転がし、ダイスが1周する度に東側に転がす
		moving_north(&dice2.top, &dice2.bottom, &dice2.front, &dice2.back);
		if((i > 0) && (i % 4 == 0)){
			moving_east(&dice2.top, &dice2.bottom, &dice2.right_side, &dice2.left_side);
		}

		/* 無駄な繰り返しを省略
		if(flag){
			break;
		}
		*/
	}

	//結果を出力
	if(flag){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

//北側に転がす関数
void moving_north(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *front;
	*front = *bottom;
	*bottom = *back;
	*back = temp;
}

//東側に転がす関数
void moving_east(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *left_side;
	*left_side = *bottom;
	*bottom = *right_side;
	*right_side = temp;
}

//上面と下面を軸とし右側へ回転する関数
void rotate_right(int *front, int *back, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *front;
	*front = *left_side;
	*left_side = *back;
	*back = *right_side;
	*right_side = temp;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
     
        using namespace std;
        #define sd(x) scanf("%d",&x);
        #define sdl(x) scanf("%lld",&x);
        #define pr(x) printf("%d\n",x);
        #define prl(x) printf("%lld\n",x);


    
    unordered_map<int,unordered_map<int,int>>dp;
    unordered_map<int,unordered_map<int,int>>done;
    string s;

     long long fast_exp(long long a,long long n,long long mod1)
            {
        
            if (n==0)return 1;
            else if (n==1)return a;
            if (n%2==0)return fast_exp((a*a)%mod1,n/2,mod1);
            else return (a*fast_exp((a*a)%mod1,n/2,mod1))%mod1;
            }
            bool is_square(long long  a)
            {
            long long int b=sqrt(a);
            if (b*b==a)return true;
            else return false;
            }
   
    void solve()
    {
        cin >> s;
        long long dp[200001];
        unordered_map<int,int>arr;
        long long till_now=0;
        long long res=0;
        arr[0]=1;
        for (int c=0;c<s.size();c++)
            {
                till_now=(till_now*10+s[c]-'0')%2019;
                dp[c]=arr[(till_now*fast_exp(202,c,2019))%2019];

                arr[(till_now*fast_exp(202,c,2019))%2019]++;
                res+=dp[c];
              //  cout << till_now << " " << (till_now*fast_exp(202,c,2019))%2019 << endl;
            }
            cout << res << endl;

        
    }
        

    int main ()
    {
      
     int t;
     //cin >> t;
     t=1;

     for (int tt=1;tt<=t;tt++)
     {
         solve();
     }

    return 0;
     
     
     
     
        }


Measured memory_bytes: 3764
input_num = gets.to_i

#下限値より1小さい値を設定
max_diff = -1000000001

#最小値を初回の入力値に設定
min_value = gets.to_i  

#1回値を取得しているのでinput_numから1を引く
(input_num - 1).times do
    #入力値を取得
    check_value = gets.to_i    
    
    #最大の差分値 = 入力値 - 最小値 または これまでの最大差分値
    max_diff = max_diff > (check_value - min_value) ? max_diff : (check_value - min_value)
    
    min_value = min_value < check_value ? min_value : check_value
end

puts max_diff




Measured memory_bytes: 6876
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

int main(void)
{
  int a,b,h,m; cin>>a>>b>>h>>m;
  double r,theta1,theta2,all_theta;
  
  theta1=m*6; theta2=30*h+m*0.5;
  if(theta1<=theta2){all_theta=theta2-theta1;}
  else{all_theta=theta1-theta2;}
  
  r=(a*a)+(b*b)-2*a*b*cos((all_theta/180)*M_PI);
  
  printf("%.20f",sqrt(r));
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 4164
#include <iostream>
#include <utility>

int main()
{
	unsigned long long N, D;
	std::cin >> N >> D;
	unsigned long long cnt = 0;
	for (int i = 0; i < N; ++i) {
		unsigned long long X, Y;
		std::cin >> X >> Y;
		if (D*D >= X * X + Y * Y)
			cnt++;
	}

	std::cout << cnt << std::endl;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private int N = (int) (1e5 + 1);
    //private int[] stones = new int[N];
    private static List<Integer> stones = new ArrayList<>();
    private static int n;
    private static int k;
    private static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        n = input.nextInt();
        k = input.nextInt();
        for (int i = 0; i < n; i++) {
            stones.add(input.nextInt());
        }
        int[] alreadyComputed = new int[n];
        for (int i = 0; i < n; i++) {
            alreadyComputed[i] = -1;
        }
        System.out.println(solution(stones, n - 1, k, alreadyComputed));
    }

    public static int solution(List<Integer> stones, int n, int k, int[] alreadyComputed) {
        if (n == 0) {
            return 0;
        }
        if (alreadyComputed[n] != -1) {
            return alreadyComputed[n];
        }
        int minimum = (int)(1e9);
        if (n < k) {
            k = n;
        }
        for (int i = 1; i <= k; i++) {

            int poss1 = solution(stones, n - i, k, alreadyComputed) + Math.abs(stones.get(n) - stones.get(n - i));
            if (poss1 < minimum) {
                minimum = poss1;
            }
        }
        alreadyComputed[n] = minimum;
        return alreadyComputed[n];
    }
}



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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;


int main() {

    int a, b;
    cin >> a >> b;
    printf("%d %d %.10f\n", a / b, a % b, (double) a / b);
}


Measured memory_bytes: 3152
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define set0(x) memset(x,0,sizeof(x))
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
using namespace std;
typedef pair<int,int> pint;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,m,a[200010];
int main() {
	read(n);read(m);
	n*=2;
	for(int i=0;i<n;i++)read(a[i]);
	sort(a,a+n);
	int l = -1,r = n/2;
	while(l+1!=r){
		int mid = (l+r)/2,cp = mid*2,tol = 0;
		for(int i=cp,j=n-1;i<j;i++,j--) if(a[i]+a[j]<m) tol = 1;
		//cout<<mid<<' '<<tol<<endl;
		if(tol){
			l = mid;
		}else{
			r = mid;
		}
	}
	//cout<<r<<endl;
	int ans = 0;
	for(int i=0;i<r;i++) ans = max(ans,a[i]+a[r*2-1-i]);
	for(int i=r*2,j=n-1;i<j;i++,j--) ans = max(ans,a[i]+a[j]-m);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
n = list(map(int, input().split()))
#print(n)
qn = int(input())
question = []
for i in range(qn):
    q = list(map(int, input().split()))
    question.append(q)

right = []
for i in range(qn):
    x = n
    if question[i][0] == x[1]:  #N(北)に回転
        temp = x[0]
        x[0] = x[1]
        x[1] = x[5]
        x[5] = x[4]
        x[4] = temp
    elif question[i][0] == x[2]:  #W(西)に回転
        temp = x[0]
        x[0] = x[2]
        x[2] = x[5]
        x[5] = x[3]
        x[3] = temp
    elif question[i][0] == x[3]:  #E(東)に回転
        temp = x[0]
        x[0] = x[3]
        x[3] = x[5]
        x[5] = x[2]
        x[2] = temp
    elif question[i][0] == x[4]:  #S(南)に回転
        temp = x[0]
        x[0] = x[4]
        x[4] = x[5]
        x[5] = x[1]
        x[1] = temp
    elif question[i][0] == x[5]:  #S(南)に２回転
        for k in range(2):
            temp = x[0]
            x[0] = x[4]
            x[4] = x[5]
            x[5] = x[1]
            x[1] = temp

    if question[i][1] != x[1]:
        if question[i][1] == x[2]:  #地面から垂直に左回転
            temp = x[2]
            x[2] = x[4]
            x[4] = x[3]
            x[3] = x[1]
            x[1] = temp
        elif question[i][1] == x[3]:  #地面から垂直の右回転
            temp = x[3]
            x[3] = x[4]
            x[4] = x[2]
            x[2] = x[1]
            x[1] = temp
        elif question[i][1] == x[4]:  #地面から垂直に２回右回転
            for k in range(2):
                temp = x[3]
                x[3] = x[4]
                x[4] = x[2]
                x[2] = x[1]
                x[1] = temp
    right.append(x[2])

for i in right:
    print(i)



Measured memory_bytes: 5628
using System;

class Test
{
    static void Main()
    {
        int[] alpha = new int[26];
        string ss;
        while ((ss = Console.ReadLine()) != null)
        {

            for (int i = 0; i < ss.Length; i++)
            {
                if (char.IsUpper(ss[i])) alpha[ss[i] - 65]++;
                else if (char.IsLower(ss[i])) alpha[ss[i] - 97]++;
            }
        }

        for (int i = 0; i < 26; i++)
        {
            Console.WriteLine("{0} : {1}", Convert.ToChar(i + 97), alpha[i]);
        }
    }
}


Measured memory_bytes: 17912
/*
  B - A to Z String
  <http://abc053.contest.atcoder.jp/tasks/abc053_b>
*/

#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {

  char s[200001];
  int len, end, start;
  int i;

  scanf("%s", s);
  len = strlen(s);

  i = 0;
  while( i < len ){
    if ( s[i] == 'A' ) {
      start = i;
      break;
    }
    i++;
  }

  i = len - 1;
  while( i >= 0 ){
    if( s[i] == 'Z' ){
      end = i;
      break;
    }
    i--;
  }

  printf("%d\n", end - (start-1) );

  return 0;
}


Measured memory_bytes: 384
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int MAX_N = 1000;
int n;
int s, g;
double edges[MAX_N + 1][MAX_N + 1];
int visited[MAX_N + 1];
vector<int> route;

bool shotestPath() {
	memset(visited, -1, sizeof(visited));
	typedef pair<double, pair<int, int> > P;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(make_pair(0., make_pair(s, 0)));
	while (!que.empty()) {
		P current = que.top();
		que.pop();
		const double cost = current.first;
		const int pos = current.second.first;
		const int pre = current.second.second;
		if (visited[pos] != -1) continue;
		visited[pos] = pre;
		if (pos == g) {
			return true;
		}
		for (int i = 1; i <= n; i++) {
			if (edges[pos][i] >= 0.) {
				que.push(make_pair(cost + edges[pos][i], make_pair(i, pos)));
			}
		}
	}
	return false;
}

void buildRoute(int p) {
	if (p == 0) return;
	route.push_back(p);
	buildRoute(visited[p]);
}

void solve() {
	if (shotestPath()) {
		route.clear();
		buildRoute(g);
		vector<int>::reverse_iterator it = route.rbegin();
		cout << (*it);
		for (++it; it != route.rend(); ++it) {
			cout << ' ' << (*it);
		}
		cout << endl;
	}
	else {
		cout << "NA" << endl;
	}
}

int main () {
	while (cin >> n, n) {
		double x[n], y[n];
		for (int i = 0; i < n; i++) {
			int b;
			cin >> b;
			cin >> x[b] >> y[b];
		}
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				double w = x[i] - x[j];
				double h = y[i] - y[j];
				double d = w * w + h * h;
				if (d <= 50. * 50.) {
					edges[i][j] = edges[j][i] = sqrt(d);
				}
				else {
					edges[i][j] = edges[j][i] = -1.;
				}
			}
		}
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> s >> g;
			solve();
		}
	}
	return 0;
}

Measured memory_bytes: 1748
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string a, b;
    cin >> a >> b;
    a = a + b;
    lli num = (lli) stoi(a);
    for (lli i = 1; i <= 1000;i++){
        if(i*i==num){
            out("Yes");
            return 0;
        }
    }
    out("No");
}

Measured memory_bytes: 3568
#include <stdio.h>

void gcd(int, int);
int main(){
  int x, y;
  scanf("%d%d",&x,&y);
  gcd(x, y);
  return 0;
}

void gcd(int x, int y){
  int r, n;
  if(x < y){
    n = x;
    x = y;
    y = n;
  }

  r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  printf("%d\n",y);
}




Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  int S,W;cin>>S>>W;
  
  if(W>=S){
    cout<<"unsafe"<<endl;
  }
  else{
    cout<<"safe"<<endl;
  }
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {

		new Main().run();

	}

	public void run(){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String inputData;
        List<TestResult> testDataList = new ArrayList<TestResult>();

        try {
        	//??\???
	        while(true){
				inputData = reader.readLine();
				if("-1 -1 -1".equals(inputData)){
					break;
				}
				String[] strData = inputData.split(" ");
				testDataList.add(new TestResult(Integer.parseInt(strData[0]) , Integer.parseInt(strData[1]) , Integer.parseInt(strData[2])));
	        }

	        //????????????
	        for(TestResult result :testDataList){
	        	System.out.println(result.getEvaluation());
	        }

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * TestResult?????????
	 * ??????????¨?????????°?????????????¨?????????°??????????¨?????????°
	 */
	class TestResult{

		//??????????¨?????????°
		public int m;
		//??????????¨?????????°
		public int f;
		//???????¨?????????°
		public int r;

		public String evalution;

		TestResult(int _m ,int _f,int _r){
			m = _m;
			f = _f;
			r = _r;

			setEvalution();

		}

		/**
		 * ??????????±????
		 */
		private void setEvalution(){

			int total = m + f;
			if(m == -1 || f == -1){
				evalution = "F";
			}else if(total >= 80){
				evalution = "A";
			}else if(total < 80 && total >=65){
				evalution = "B";
			}else if(total < 65 && total >=50){
				evalution = "C";
			}else if(total < 50 && total >=30){
				if(r >= 50){
					evalution = "C";
				}else{
					evalution = "D";
				}
			}else if(total < 30){
				evalution = "F";
			}
		}

		/**
		 * ???????????????
		 * @return
		 */
		public String getEvaluation(){

			return evalution;

		}

	}

}

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

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        a[i] *= n;
    }
    constexpr long long LLINF = 1e18 + 1;
    ll now = LLINF, m;
    for (int i = 0; i < n; i++) {
        if (now > abs(sum - a[i])) {
            now = abs(sum - a[i]);
            m = i;
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int tate, yoko;
    const int max_int32 = 2147483647;

    scanf("%d%d", &tate, &yoko);

    if (yoko <= max_int32 / tate) {
        printf("%d %d\n", tate * yoko, 2 * (tate + yoko));
    } else {
        printf("overflow\n");
    }

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
char str[100060];
int main()
{
    scanf("%s", str);
    int score = 0;
    int paper, rock;
    paper = rock = 0;
    for(int i = 0; str[i]; ++i)
    {
        if(str[i] == 'g')
        {
            if(paper < rock)
            {
                ++paper;
                ++score;
            }
            else
                ++rock;
        }
        else
        {
            if(paper < rock)
                ++paper;
            else
            {
                --score;
                ++rock;
            }
        }
    }
    printf("%d\n", score);
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
ll a,b,c;
//ld ;
//string s,t,u;
// char c;

int main() {
  cin >> a >> b >> c;
  bool ab = a==b;
  bool bc = b==c;
  bool ca = c==a;
  yorn(!((ab && bc && ca) || (!ab && !bc && !ca)));
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MOD = 1000000007;
const int MAX_N = 100050;
int N, M;
int a[MAX_N];

long long dp[MAX_N];
std::unordered_set<int> st;

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i];
    }

    for (int i = 1; i <= M; i++) {
        st.insert(a[i]);
    }

    dp[0] = 1;
    for (int i = 0; i <= N; i++) {
        if (st.find(i+1) == st.end()) {
            dp[i+1] += dp[i];
            dp[i+1] %= MOD;
        }
        if (st.find(i+2) == st.end()) {
            dp[i+2] += dp[i];
            dp[i+2] %= MOD;
        }
    }

    std::cout << dp[N] << std::endl;

    return 0;
}

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


int main() {

    int h, w;
    cin >> h >> w;
    char board[60][60];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char s; cin >> s;
            board[i][j] = s;
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (board[i][j]=='#'&&board[i][j-1]!='#'&&board[i+1][j]!='#'&&board[i][j+1]!='#'&&board[i-1][j]!='#') {
                cout << "No" << endl;
                return 0; 
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
  ***
  0.0
  *-*
 * * *
*  *  *
*  *  *
   *
   *
  * *
 *   *
 *   *
 	   	  		*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define F first
#define S second
// set <int> :: iterator it = x.begin(); it != x.end(); it ++
using namespace std;
ll n,sum,num,maxi=-10e9,maxn=-10e9,mini=10e9,minn=10e9,sam;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();	cout.tie();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for(int i = 1;i <= n/2;i++){
		sum=i;
		num=n-i;
		while(sum>0){
			sam+=sum%10;
			sum/=10;
		}
		while(num>0){
			sam+=num%10;
			num/=10;
		}
		sum=0;
		num=0;
		mini=min(mini,sam);
		sam=0;
	}
	cout<<mini;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	while(k--)
	{
		int d;
		cin>>d;
		for(int i=0;i<d;i++)
		{
			int x;
			cin>>x;
			arr[x-1]=100;
		}
	}
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(arr[i]!=100){
			count++;
		}
	}
	cout<<count<<"\n";
}

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

int main()
{

  int n, q, i, count = 0, k; 
  int *S, *T;

  scanf("%d", &n);
  S = (int *)malloc(n * sizeof(int));
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);

  scanf("%d", &q);
  T = (int *)malloc(n * sizeof(int));
  for(i = 0; i < q; i++)
    scanf("%d", &T[i]);


  /*確認のprintf*/
  /*
    printf("n = %d\n", n);
    for(i = 0; i < n; i++)
    printf("%d ", S[i]);
   
    printf("\n");
    printf("q = %d\n", q);
    for(i = 0; i < q; i++)
    printf("%d ", T[i]);
   
    printf("\n");
  */

  for(k = 0; k < q; k++){
    for(i = 0; i < n; i++){
      if(T[k] == S[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<string.h>
#include <stdbool.h>

int main()
{
  int n;
  
  scanf("%d",&n);
  
  int a[n];
  int b[n];
  int i;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  
 b[n/2]=a[0];
  
  int e=2;
  int o=3;
  for(i=n/2;i>0;i--)
  {
    if(n%2==0)
    {
     b[i-1]=a[e-1];
     e+=2;
    }
    else
    {
     b[i-1]=a[o-1];
     o+=2;
    }
  }
  
  e=2;
  o=3;
  for(i=n/2;i<n;i++)
  {
    if(n%2==0)
    {
     b[i+1]=a[o-1];
     o+=2;
    }
    else
    {
     b[i+1]=a[e-1];
     e+=2;
    }
  }
  
  for(i=0;i<n;i++)
  {
    printf("%d ",b[i]);
  }
   return 0;
 }
  

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

using namespace std;

const int64_t INF = INT64_C(1) << 60;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c -= P;
    G[a].emplace_back(make_pair(b, c));
  }
  vector<int64_t> T(N, -INF);
  T[0] = 0;
  for (int k = 0; k < N; k++) {
    for (int u = 0; u < N; u++) {
      for (auto g : G[u]) {
        int v = g.first, d = g.second;
        if (T[u] != -INF) chmax(T[v], T[u] + d);
      }
    }
  }
  for (int k = 0; k < N; k++) {
    for (int u = 0; u < N; u++) {
      for (auto g : G[u]) {
        int v = g.first, d = g.second;
        if (T[v] != -INF && chmax(T[v], T[u] + d)) {
          T[v] = INF;
        }
      }
    }
  }
  cout << (T[N - 1] == INF ? -1 : max(INT64_C(0), T[N - 1])) << '\n';
  return 0;
}


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

int main() {
    long long a;
    cin >> a;
    string s;
    cin >> s;
    long long b = s[0] - '0';
    b *= 10;
    b += s[2] - '0';
    b *= 10;
    b += s[3] - '0';
    
    a *= b;
    a /= 100;
    cout << a << endl;
    
    
    return 0;
}


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

int N;

int color[100005];
int used[100005];

vector<int> Adj[100005];
vector<int> W[100005];

int u[100005], v[100005], w[100005];

void DFS(int K, int C) {

	color[K] = C;
	used[K] = 1;

	for (int i = 0; i < (int)Adj[K].size(); i++) {
		int y = Adj[K][i];
		int v = W[K][i];
		if (used[y] != 0) { continue; }
		else {
			if (v % 2 == 0) { DFS(y, C); }
			else { DFS(y, (C + 1) % 2); }
		}
	}
}

int main(void) {

	cin >> N;

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

	for (int i = 1; i <= N - 1; i++) {
		Adj[u[i]].push_back(v[i]); W[u[i]].push_back(w[i]);
		Adj[v[i]].push_back(u[i]); W[v[i]].push_back(w[i]);
	}

	DFS(1,0);

	for (int i = 1; i <= N; i++) {
		cout << color[i] << endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,a;
    cin >> h >> a;
    cout << (h+a-1)/a << "\n";

    return 0;
}

Measured memory_bytes: 3596
H, W = map(int, input().split())
MAP = [input() for _ in range(H)]

dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
M = 10**9 + 7
for i in range(H):
  for j in range(W):
    if MAP[i][j] == '#':
      continue
    if i > 0:
      dp[i][j] += dp[i-1][j]
    if j > 0:
      dp[i][j] += dp[i][j-1]
    dp[i][j] %= M
print(dp[-1][-1])

Measured memory_bytes: 51952
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
int q[110000];
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
long long ans[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		scanf("%d%d",p+i,q+i);p[i]--;q[i]--;
	}
	for(int i=0;i<a;i++)UF[i]=-1;
	long long cur=(long long)a*(a-1)/2;
	for(int i=b-1;i>=0;i--){
		ans[i]=cur;
		if(FIND(p[i])!=FIND(q[i])){
			cur-=(long long)(-UF[FIND(p[i])])*(-UF[FIND(q[i])]);
			UNION(p[i],q[i]);
		}
	}
	for(int i=0;i<b;i++)printf("%lld\n",ans[i]);
}


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

int qpow(int b,int e){
    if(!e)return 1;
    if(e&1) return qpow(b,e-1)*b;
    return qpow(b*b,e>>1);
}
int a[101][101];
int32_t main(){
    int w,h,n;
    cin>>w>>h>>n;
    int res=0;
    while(n--){
        int x,y,c;
        cin>>x>>y>>c;
        if(c==1)
            for(int i=0;i<x;i++)
                for(int j=0;j<h;j++)
                    a[i][j]=1;
        if(c==2)
            for(int i=x;i<w;i++)
                for(int j=0;j<h;j++)
                    a[i][j]=1;
        if(c==3)
            for(int i=0;i<w;i++)
                for(int j=0;j<y;j++)
                    a[i][j]=1;
        if(c==4)
            for(int i=0;i<w;i++)
                for(int j=y;j<h;j++)
                    a[i][j]=1;

    }

    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(!a[i][j])res++;
        }
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main(void)
{
    int x,n,dif=0;
    bool p[102]={0,};
    
    cin >> x >> n;
    for(int i=1 ; i<=n ; i++)
    {
        int a;
        cin >> a;
        p[a] = true;
    }
    while(1)
    {
        if(!p[x-dif])
        {
            cout << x-dif;
            break;
        }
        if(!p[x+dif]) 
        {
            cout << x+dif;
            break;
        }
        dif++;
    }
    
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;

struct FenwickTree{
  int n;
  vl bit;
  FenwickTree(int x = 0):n(x){bit = vl(x+1,0);}

  inline void add(int i, ll x){
    i++;
    while(i <= n){
      bit[i] += x;
      i += i & -i;
    }
  }

  inline int sum(int i){
    i++;
    int res = 0;
    while(i > 0){
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
};

const ll INF = 1e18;

void dijk(int s, const vector< vector<pll> > &g, vl &d){
  d[s] = 0;
  priority_queue< pll, vector<pll>, greater<pll> > q;
  q.push(pll(0,s));

  while(q.size()){
    ll cd = q.top().first;
    int v = q.top().second; q.pop();
    if(d[v]<cd)continue;

    for(pll e : g[v]){
      ll nd = cd + e.first;
      int u = e.second;
      if(d[u] > nd){
	d[u] = nd;
	q.push(pll(nd,u));
      }
    }
  }
}

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

  vector< vector<pll> > g(n);
  rep(i,m){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    g[a].push_back(pll(c,b));
    g[b].push_back(pll(c,a));
  }

  vl ds(n,INF), dg(n,INF);
  dijk(0,g,ds); dijk(n-1,g,dg);
  
  vl vs;
  vector< vl > query;

  int q;
  scanf("%d",&q);
  rep(i,q){
    vl tmp(3); tmp[1] = i;
    scanf("%lld%lld",&tmp[2],&tmp[0]);
    query.push_back(tmp);
    vs.push_back(tmp[2]);
  }

  rep(i,n){
    vl tmp(3);
    tmp[0] = dg[i]; tmp[1] = q; tmp[2] = ds[i];
    query.push_back(tmp);
    vs.push_back(tmp[2]);
  }


  sort(all(query));
  reverse(all(query));
  sort(all(vs));
  vs.erase(unique(all(vs)),vs.end());
  //rep(i,vs.size())cout << vs[i] << " "; cout << endl;

  vl ans(q);
  FenwickTree bit(vs.size());
  rep(i,query.size()){
    //cout << query[i][0] << " " << query[i][1] << " " << query[i][2] << endl;
    if(query[i][1] == q){
      int pos = lower_bound(all(vs),query[i][2]) - vs.begin();
      bit.add(pos,1);
      //cout << pos << endl;
    }else{
      int pos = lower_bound(all(vs),query[i][2]) - vs.begin();
      ans[query[i][1]] = bit.sum(pos);
      //cout << pos << " " << bit.sum(pos) << endl;
    }
  }

  rep(i,q)printf("%lld\n",ans[i]);
}

Measured memory_bytes: 24648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int N;
while(cin >> N) {
    if(N % 2 == 1) cout << 2 * N << endl;
    else cout << N << endl;
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
            #include<vector>
            #include <algorithm>
            #include <map>
            using namespace std;
            #define debug(x) //printf((char*)x);printf("\n");
            int main(){
              int n;
             
              cin >> n;
              long long *v = new long long[n+1];
              v[0]=0;
              for(int i=1;i<n+1;i++){
                cin >> v[i];
                v[i] += v[i-1];
                debug("read val");
              }
             
              long long cnt = 0;
              map<long long,long long> comb;
              for(int i=0;i<n+1;i++){
                comb[v[i]] += 1;
              }
 
              for(auto x : comb) {
                  if(x.second > 1){
cnt += (x.second *(x.second -1))/2;
                  }
              }
              
         
              cout << cnt; 
              delete(v);
              return 0;
            }

Measured memory_bytes: 14336
def resolve():
    s=input()
    if s[0]=="R":
        if s[1]=="R":
            if s[2]=="R":
                print(3)
            else:
                print(2)
        else:
            print(1)
    else:
        if s[1]=="R":
            if s[2]=="R":
                print(2)
            else:
                print(1)
        else:
            if s[2]=="R":
                print(1)
            else:
                print(0)
resolve()

Measured memory_bytes: 61700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,b,c,d;
  cin >> N;
  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = N - N / 10 * 10;
  
  if ((a == b&&b == c)||(b == c&&c == d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3604
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int n,a,b,c;
  string s;
  cin >> n >> a >> b >> s;
  c=a+b;
  REP(i,n){
    if(s[i]=='a'){
      if (a>0) {
        a--;
        cout << "Yes" << endl;
      } else {
      if (b>0) {
        b--;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      }
    } else if (s[i]=='b'){
      if (b>0) {
        b--;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i]=='c'){
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 896
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
   // FI(); /// skip this line for compile
    int n,m,c,arr[101],x,cnt=0,sum;
    cin >> n >> m >> c;
    for(int i=0;i<m;i++){
        cin >> arr[i];
    }
    while(n--){
        sum = 0;
        for(int i=0;i<m;i++){
            cin >> x;
            sum+=arr[i]*x;
        }
        sum+=c;
        if(sum>0) cnt++;
    }
    cout << cnt << endl;
    return 0;
    //code end
}
//okbye


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

//cmdで g++ test.cpp とするとコンパイルできる

#define MOD 1000000007
typedef pair<int,int> pii;

int main() {
    string S;
    cin>>S;
    int ans=0;
    int L=S.size();
    for(int i=0;i<L/2;i++){
        if(S.at(i)!=S.at(L-1-i))ans++;
    }
    cout<<ans<<endl;
}


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

string s;
int a, l;

bool check(string t, char c)
{
    for (int i = 0; i < t.size(); i++)
        if (t[i] != c)
            return false;
    return true;
}

bool search(int ind, int l)
{
    if (ind - l * 2 < 0 || ind + l - 1 >= s.size())
        return false;
    return (check(s.substr(ind - l * 2, l), 'J') && check(s.substr(ind, l), 'I'));
}

int main()
{
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'O')
            l++;
        else
            a = max(a, search(i, l) * l), l = 0;
    }
    cout << a << endl;
}


Measured memory_bytes: 4340
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int i = 0;

        while (n != 0) {
                    i = i+1;
            System.out.println("Case " + i + ": " + n);
            n = scn.nextInt();
        }

    }
}



Measured memory_bytes: 42120
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

typedef long long ll;

using namespace std;

const int v=100005;
vector<int> to[v*2];
bool visited[v*2];
vector<int> cnt;

void dfs(int i)
{
  if (visited[i]) return;
  visited[i] = true;
  cnt[i/v]++;
  for (int u : to[i])
  {
    dfs(u);
  }
}
int main()
{
  int N;
  cin >> N;
  for (int i=0;i<N;i++)
  {
    int x,y;
    cin >> x >> y;
    y+=v;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  ll ans = 0;
  for (int i=0;i<v*2;i++)
  {
    if (visited[i]) continue;
    cnt = vector<int>(2, 0);
    dfs(i);
    ans += (ll)cnt[0]*cnt[1];
  }
  ans -= N;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N; 
    cin>>N;
    int max_med, min_med;
    vi A(N), B(N), Asort(N), Bsort(N);
    REP(i, 0, N){
        cin >> A[i] >> B[i];
        Asort[i] = A[i];
        Bsort[i] = B[i];
    }
    sort(Asort.begin(), Asort.end());
    sort(Bsort.begin(), Bsort.end());
    int ans = 0;
    if(N%2){
        min_med = Asort[(N-1)/2];
        max_med = Bsort[(N-1)/2];
        ans = max_med - min_med + 1;
        //cout << min_med << " " << max_med << endl;
    }
    else{
        min_med = (Asort[N/2] + Asort[N/2-1]);
        max_med = (Bsort[N/2] + Bsort[N/2-1]);
        ans = max_med - min_med + 1;
        //cout << min_med << " " << max_med << endl;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/
/******** User-defined Function *******/




/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b; cin >> a >> b;
    if(a>=1 && a<=9 && b>=1 && b<=9){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
vector<ll>g[N];
ll n,u,v,color[N],c[N],son[N],res[N]={0};
ll f(ll n) {return n*(n+1)/2;}
void dfs(ll u,ll fa){
    auto tmp=c[color[u]];
    for(auto v:g[u]){
        if(v==fa) continue;
        c[color[u]]=0;
        dfs(v,u);
        son[u]+=son[v];
        res[color[u]]+=f(son[v]-c[color[u]]);
    }
    c[color[u]]=tmp+son[u];
}

int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        son[i]=1;
        cin>>color[i];
    }
    for(ll i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        cout<<f(n)-f(n-c[i])-res[i]<<endl;
    }
    return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  string s;
  cin >> s;
  int rsl = 0;
  rep(i, 0, s.size()) {
    int idx = i;
    while(idx < s.size()) {
      if(s[idx] != 'A' and s[idx] != 'C' and s[idx] != 'G' and s[idx] != 'T') break;
      ++idx;
    }
    rsl = max(rsl, idx - i);
  }
  cout << rsl << endl;

}


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

 
int main() {
	int a[3];
 
	cin >> a[0] >> a[1] >> a[2];
	
	sort(a,a+3);
	
	int d1 = a[1] - a[0];
	int d2 = a[2] - a[1];
	
	if(d1 < 0) d1 = d1*-1;
	if(d2 < 0) d2 = d2*-1;
	
	cout << d1 + d2 << endl;
 
 
 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<cassert>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

ll pibot;

ll nibutan(ll l, ll u, ll search_num){
//	cout<<"nsn"<<search_num<<endl;
	ll low = l;
	ll up = u;

	pibot = (low + up) / 2;
//	cout<<"a"<<endl;
	while(low < up){
		pibot = (low + up) / 2;
		//cout<<pibot<<endl;
//		if(abs(pibot) > 8000){//8192
//			return 0;
//		}
		ll number = pibot * pibot * pibot * pibot * pibot;
//		cout<<"num : "<<number<<endl;
		if( number == search_num){
			return 1;
		}else if(number < search_num){
			low = pibot+1;
		}
		else{
			up = pibot-1;
		}
//		cout<<low<<" "<<up<<endl;
	}
	return 0;
}

int main(){
	ll X;
	ll A,B;
	cin>>X;
	ll ans;
	ll i = 0;
	while(i < INT_MAX){
		//assert(i < 2);
		ll sn = X + i*i*i*i*i;
		A = nibutan(-200,200,sn);
		if(A != 0){
			A = pibot;
			B = i;
			break;
		}
		sn = X - i*i*i*i*i;
		//cout<<"sn"<<sn<<endl;
		A = nibutan(-200,200,sn);
		if(A != 0){
			A = pibot;
			B = -i;
			break;
		}
		i++;
	}

	cout<<A<<" "<<B<<endl;
	return 0;
}


Measured memory_bytes: 3636