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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll x,y;
    cin >> x >> y;
    if(x%y == 0) {
    	cout << x/y << "\n";
    } else {
    	cout << x/y + 1 << "\n";
    }
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    ll n,x,z;
    cin >> n  >> x >> z;
    cout <<(1+(n-1)/x)*z<<endl;
    return ;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
   // cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}




Measured memory_bytes: 3600
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N, H = map(int, input().split())
    A = [0 for _ in range(N)]
    B = [0 for _ in range(N)]
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    max_a = max(A)
    weapon = []
    for b in B:
        if b <= max_a:
            continue
        else:
            weapon.append(b)

    weapon.sort(reverse=True)
    cnt = 0
    for w in weapon:
        cnt += 1
        H -= w
        if H <= 0:
            print(cnt)
            exit(0)

    cnt += math.ceil(H / max_a)
    print(cnt)


Measured memory_bytes: 49964
#include <iostream>
#include <cstdlib>
#include <vector>
#include <stack>

int main()
{
   int64_t A,B;
   std::cin >> A >> B;
   if(A>B) std::swap(A,B);
   int64_t K = B-A;
   if(K%2==0) {
       std::cout<< (K/2 + A) << std::flush;
   } else {
       std::cout << "IMPOSSIBLE" << std::flush;
   }
}


Measured memory_bytes: 256
#
#    ------------------------------------------------
#           ____          _     Generatered using
#          / ___|        | |
#         | |    __ _  __| | ___ _ __  ______ _
#         | |   / _` |/ _` |/ _ \ '_ \|_  / _` |
#         | |__| (_| | (_| |  __/ | | |/ / (_| |
#          \____\____|\____|\___|_| |_/___\____|
#
#      GNU Affero General Public License v3.0
#    ------------------------------------------------
#    Author   : prophet
#    Created  : 2020-07-25 08:11:03.732018
#    UUID     : ZonihA5OmAzqBLgc
#    ------------------------------------------------
#
production = True

import sys, math, collections

def input(f = 0, m = 0):

    if m > 0: return [input(f) for i in range(m)]
    else:
        l = sys.stdin.readline()[:-1]

        if f >= 10:
            u = False
            f = int(str(f)[-1])
        else: u = True

        if f == 0: p = [l]
        elif f == 1: p = list(map(int, l.split()))
        elif f == 2: p = list(map(float, l.split()))
        elif f == 3: p = list(l)
        elif f == 4: p = list(map(int, list(l)))
        elif f == 5: p = l.split()

        return p if u else p[0]

def out(l, f = 0, n = True):

    if f == 0: p = str(l)
    elif f == 1: p = " ".join(map(str, l))
    elif f == 2: p = "\n".join(map(str, l))
    elif f == 3: p = "".join(map(str, l))

    print(p, end = "\n" if n else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
flip = lambda a: (a + 1) & 1

def mapl(i, f = 0):

    if f == 0: return list(map(int, i))
    elif f == 1: return list(map(str, i))
    elif f == 2: return list(map(list, i))

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#


def solve():

    n, k = input(1)
    a = input(1)

    for i in range(n - k):
        out(ter(a[i + k] > a[i], "Yes", "No"))

    return


solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


Measured memory_bytes: 94468
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

long gcd(long a, long b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}

void main() {
    int n = readint();
    long[] xs;
    for (int i = 0; i < n; i++) {
        xs ~= readln.chomp.to!long;
    }

    auto ans = xs.reduce!lcm;
    writeln(ans);
}


Measured memory_bytes: 256
n = gets.to_i
taro = 0
hana = 0
n.times{
	x, y = gets.chomp.split
	if x == y
		taro += 1
		hana += 1
	elsif x < y
		hana += 3
	else
		taro += 3
	end
}
puts [taro, hana].join ' '


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

int main() {
  int t;
  string str1, str2;
  cin >> t;
  
  int taro = 0, hanako = 0;
  for (int i = 0; i < t; i++) {
    cin >> str1 >> str2;
    if (str1 > str2) taro += 3;
    else if (str1 < str2) hanako += 3;
    else {
      taro++;
      hanako++;
    }
  }
  cout << taro << " " << hanako << endl;
  
}



Measured memory_bytes: 3192
object Main extends App{
  val Array(a,b) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  if(b==1) println (0)
  else{
    var count = 1
    while(a+(a-1)*(count-1)<b) count+=1
    println(count)
  }
 }


Measured memory_bytes: 25548
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

class UnionFind{
public:
	vector<int> parent;
	UnionFind(){}
	UnionFind(int n){
		this->parent = vector<int>(n,-1);
	}
	int root(int x){
		if (this->parent[x] < 0) return x;
		this->parent[x] = root(this->parent[x]);
		return this->parent[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return false;
		if (this->parent[rx] > this->parent[ry]) swap(rx, ry);
		this->parent[rx] += this->parent[ry];
		this->parent[ry] = rx;
		return true;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->parent[this->root(x)];
	}
};



int main(){
	int n,m,k; cin >> n >> m >> k;
	vector<set<int>> relation(n+1);
	UnionFind suf(n+1);
	for (int i=0;i<m;i++){
		int a,b; cin >> a >> b;
		relation[a].insert(b);
		relation[b].insert(a);
		suf.unite(a,b);
	}
	for (int i=0;i<k;i++){
		int a,b; cin >> a >> b;
		relation[a].insert(b);
		relation[b].insert(a);
	}
	for (int i=1;i<n+1;i++){
		int ans = suf.size(i) - 1;
		for (auto itr = relation[i].begin(); itr != relation[i].end(); ++itr){
			if (suf.same(*itr,i)) ans--;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n-1);
    REP(i,n) cin>>a[i];
    REP(i,n) cin>>b[i];
    REP(i,n-1) cin>>c[i];
    ll d=0;
    REP(i,n){
        d+=b[a[i]-1];
        if(i<n-1&&a[i+1]-a[i]==1){
            d+=c[a[i]-1];
        }
    }
    cout<<d;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int a, b, s;

scanf("%d %d",&a,&b);
if(a>b){
    s = a + (a - 1);
    printf("%d",s);
}else if(a<b){
    s = b + (b - 1);
    printf("%d",s);
}else{
    s = a + b;
    printf("%d",s);
}
return 0;

}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextWord() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}

	var ans int
	maxH := 0
	for i := 0; i < n; i++ {
		if a[i] >= maxH {
			ans++
			maxH = a[i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
   int n,x,i,d=0,s[101],min;

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

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

   min=s[0];

   for(i=0;i<n;i++){
      if(min>s[i]) min=s[i];
      x-=s[i];
      d++;
   }

   printf("%d\n",d+(x/min));
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,arr[100001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    //for (int i=0;i<n;i++){
        //cin>>arr[i];
    //}
    long long tot=0;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            for (int k=1;k<=n;k++){
                int cur=__gcd(i,j);
                cur=__gcd(cur,k);
                tot+=cur;
            }
        }
    }
    cout<<tot;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d;
    cin >> n;
    ll ans=0;
    if(n%2==0){
        ans=min((n/2)*d,min(n*s,min(2*n*h,4*q*n)));
    } else{
        ll a=(n/2);
        ll b=min(a*d+s,min(a*d+2*h,a*d+4*q));
        ans=min(b,min(n*s,min(2*n*h,4*q*n)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>

/* 
PascalCase  クラス名
camelCase   メソッド名，関数名，変数名
snake_case  ファイル名，名前空間，std のメソッド名，変数名，型名に準じる場合
SNAKE_CASE	マクロ名，static const 定数，列挙体
*/

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

struct Node
{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

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

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    z->parent = y;

    if (y == NIL)
    {
        root = z;
    }
    else
    {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

void inorder(Node *u)
{
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);   
}

void preorder(Node *u)
{
    if(u == NIL) return;
    printf(" %d", u->key);    
    preorder(u->left);
    preorder(u->right);
}

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

    int M;
    cin >> M;

    REP(i, M)
    {
        string order;
        int key;

        cin >> order;

        if(order == "insert")
        {
            cin >> key;
            insert(key);
        }
        else
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");             
        }
    }
    return 0;
}


Measured memory_bytes: 26588
# 079a

def atc_079a(input_value: str) -> str:
    n = 3
    for i in range(0, len(input_value) + 1 - n):
        for j in range(1, n):
            if input_value[i] != input_value[i + j]:
                break
            if j == n - 1:
                return "Yes"
    return "No"

input_value = input()
print(atc_079a(input_value))


Measured memory_bytes: 9044
#include <stdio.h>
int main(void){
    // Your code here!
    int A,B;
    scanf("%d %d",&A,&B);
    if(A >= 13)
        printf("%d\n", B);
    else if(A >= 6)
        printf("%d\n", B/2);
    else
        printf("%d\n", 0);
}


Measured memory_bytes: 128
#include "iostream"
#include <algorithm>

using namespace std;

int partition(int A[],int p,int r){
  int x = A[r];
  int i = p - 1;
  for(int j = p ; j < r ; j++){
    if(A[j] <= x){
      i=i +1;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i + 1;
}

int main(){
  int n,m;
  int A[1000000];
  cin >> n;
  for(int i = 0; i<n;i++) cin >> A[i];
  m = partition(A,0,n-1);
  for(int i = 0 ; i < n; i++){
    if(i) cout << " ";
    if(i == m) cout << "[";
    cout << A[i];
      if(i == m) cout << "]";
  }
  cout << endl;
  return 0;
}



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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double

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

    int a, b;
    cin >> a >> b;
    cout << a * b << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7;
ll H, N, M, L, K, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> N;
	set<string>set;
	string s;
	bool flag = 1;
	cin >> s;
	set.insert(s);
	for (int i = 1; i < N; i++) {
		char tmp = s[s.length() - 1];
		cin >> s;
		if (set.count(s)||tmp!=s[0]) {
			flag = 0; break;
		}
		else set.insert(s);
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

int main() {
  char x;
  scanf("%c",&x);
  x = (int)x;
  //printf("%d",x);
  if(x >= 65 && x <= 90) {
    printf("A");
  } else printf("a");
  return 0;
}


Measured memory_bytes: 1560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int x, y;
  cin >> x >> y;

  int ans = INF;
  for (int a = 0; a <= 1; a++) {
    for (int b = 0; b <= 1; b++) {
      int X = x, Y = y, tmp = 0;

      if (a) X *= -1, tmp++;
      if (b) Y *= -1, tmp++;

      if (X > Y) continue;

      tmp += abs(X - Y);

      chmin(ans, tmp);
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int x,y,z;
int main(){
	scanf("%d%d%d",&x,&y,&z);
	printf("%d\n",(x-z)/(y+z));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int K;
    cin >> K;
    int a[32] = {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};
    cout << a[K - 1] << endl;
}

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

int main(){
    ll n,k; cin>>n>>k;
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    sort(h.rbegin(),h.rend());
    ll ans=0;
    for(int i=k;i<n;i++){
        ans+=h[i];
        /*while(h[i]>0){
            ans++;
            h[i]--;
        }*/
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <memory>
#include <map>
#include <cassert>
#include <array>
#include <iterator>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <array>
#include <numeric>

class Solution {
public:
    long long n;
    std::vector<std::vector<std::array<long long, 2>>> v;
    std::vector<long long> dist;
    std::vector<bool> visited;
    void dfs (long long cur, long long cur_dist)
    {
      dist[cur] = cur_dist;
      visited[cur] = true;
      for (auto &p : v[cur])
        {
          if (visited[p[0]])
            continue;

          dfs (p[0], cur_dist + p[1]);
        }
    }

    void solve(std::istream& in, std::ostream& out) {
      in >> n;
      v.resize (n);
      for (long long i = 0; i < n - 1; ++i)
        {
          long long a, b, c;
          in >> a >> b >> c;
          --a; --b;
          v[a].push_back ({b, c});
          v[b].push_back ({a, c});
        }
      long long q, k;
      in >> q >> k;
      --k;
      dist.resize (n);
      visited.resize (n);
      dfs (k, 0);
      for (long long i = 0; i < q; ++i)
      {
        long long a, b;
        in >> a >> b;
        --a; --b;
        out << dist[a] + dist[b] << '\n';
      }
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <iostream>

int main ()
{
  solve (std::cin, std::cout);
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count=0;
  string S;
  cin>>S;
  for(int i=0;i<S.size();i+=2){
    if(S.at(i)!='R'&&S.at(i)!='U'&&S.at(i)!='D'){
      count++;
     // cout<<count<<endl;
    }
  }
   for(int i=1;i<S.size();i+=2){
    if(S.at(i)!='L'&&S.at(i)!='U'&&S.at(i)!='D'){
      count++;
    }
   }
  if(count==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main()
{
	int n, i, a[100];
	cin>>n;
	for(i=0;i<n;++i)cin>>a[i];
	sort(a, a+n);
	double p=a[0];
	
	for(i=1;i<n;++i){
		p=(p+a[i])/2;
	}

	cout << p << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<set>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = 1000000007;
ll CaseN=1;
const ld PI = 22/7.0;

bool mycmp(string s,string t)
{
if(s.size()<t.size())
{
return true;	
}		
return false;
}

string generate_bstring(ll n)
{
string str;
for(ll i=0;i<n;i++)
{
ll a = rand()%2;
if(a==0)
str += '0';
else
str += '1';
}
	
return str;	
}



ll Test()
{
    ll ans = 0;
  
    return ans;
}


void solve()
{
	ld x;
//	x = rand()%180;
	//if(x==0){x++;}
	cin>>x;
	ld ans=-1;
	
	for(ll i=1;i<=100000;i++)
	{
	ld z = (ld)i;
	ld a = (360*z)/x;
	ll p = (ll)a;
	p = (ld)p;
	if(p==a)
	{
	ans = p;
	break;	
	} 
	}
	
	
	
	cout<<ans<<endl;
	assert(ans!=-1);
   // cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
    
return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 3828
#include <iostream>
using namespace std;
typedef unsigned long long ull;
int main() {
  ull map, shape[] = {0x303, 0x1010101, 0xf, 0x10302, 0x603, 0x20301, 0x306};
  char c, ans;
  int i, j;
  while (cin >> c) {
    map = c - '0';
    for (i = 1; i < 64; i++) {
      cin >> c;
      if (c == '1') map |= (ull) 1 << i;
    }
    for (i = 0; i < 64; i++)
      for (j = 0; j < 7; j++)
        if (((map >> i) & shape[j]) == shape[j]) {
          ans = j + 'A';
          goto p;
        }
    p:
    cout << ans << endl;
  }
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;
  string u; cin >> u;
  if(s == u) {
    cout << a-1 << " " << b << endl;
  } else if(t == u) {
    cout << a << " " << b-1 << endl;
  } else {
    cout << a << " " << b << endl;
  }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

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

int to(string a, string b, string c){
    int x = stoi(a+b);
    int y = stoi(c);
    return x+y;
}

int main() {
    string str[3];
    for (int i = 0; i < 3; i++) {
        cin>>str[i];
    }

    sort(str,str+3);

    int res=-1;

    do{
        res=max(res,to(str[0],str[1],str[2]));
    }while(next_permutation(str, str+3));
    
    cout<<res<<endl;

    return 0;
}

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

typedef long long ll;
typedef pair<ll,int> P;
typedef pair<int,P> P1;

#define pb push_back
#define fr first
#define sc second
#define mp1(a,b,c) P1(a,P(b,c))

ll L;

struct SEG{
	bool flag;
	bool ch;
	SEG *chl,*chr;
	void init(bool flag_ = false){
		flag = flag_;
		ch = false;
	}
	void mkch(){
		chl = new SEG;
		chl->init();
		chr = new SEG;
		chr->init();
		ch = true;
	}
	void add(){
		char c;
		scanf("%c",&c);
		if(c == '\n'){
			flag = false;
			return;
		}
		if(!ch)mkch();
		if(flag){
			flag = false;
			chl->flag = true;
			chr->flag = true;
		}
		if(c == '0')chl->add();
		else chr->add();
	}
	ll sum(ll d){
		if(flag)return (L+1-d)&(-L-1+d);
		if(!ch)return 0;
		return chl->sum(d+1)^chr->sum(d+1);
	}
};

int main(){
	static int N;
	static string s[100010];
	scanf("%d%lld\n",&N,&L);
	
	SEG seg;
	seg.init(true);
	for(int i = 1 ; i <= N ; i ++){
		seg.add();
	}
	if(seg.sum(0) == 0)puts("Bob");
	else puts("Alice");
}



Measured memory_bytes: 10368
#include <iostream>

const int MAX = 100;
int W, H;
char matrix[MAX][MAX];
const char VISITED = 'v';
int dirx[4] = {1, 0, -1, 0};
int diry[4] = {0, 1, 0, -1};

void dfs(int i, int j, char c)
{
  if (i < 0 || i >= H || j < 0 || j >= W || matrix[i][j] != c)
  {
    return;
  }
  matrix[i][j] = VISITED;
  for (int k = 0; k < 4; k++)
  {
    dfs(i + dirx[k], j + diry[k], c);
  }
}

int main()
{
  while (true)
  {
    std::cin >> H;
    std::cin >> W;
    if (H == 0 && W == 0)
    {
      break;
    }
    for (int i = 0; i < H; i++)
    {
      for (int j = 0; j < W; j++)
      {
        std::cin >> matrix[i][j];
      }
    }
    int count = 0;
    for (int i = 0; i < H; i++)
    {
      for (int j = 0; j < W; j++)
      {
        if (matrix[i][j] == VISITED)
        {
          continue;
        }
        count += 1;
        dfs(i, j, matrix[i][j]);
      }
    }
    std::cout << count << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3524
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int H, W;
char s[50][50];
int d[50][50];
int white = 0;
int gx, gy;

int bfs(int y, int x) {
	queue<P> que;
	rep(i, H) {
		rep(j, W) {
			d[i][j] = INF;
		}
	}
	d[0][0] = 0;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		if (p.first == gy && p.second == gx) {
			break;
		}
		rep(i, 4) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (0 <= ny && 0 <= nx && ny < H && nx < W && s[ny][nx] != '#' && d[ny][nx] == INF) {
				que.push(P(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gy][gx];
}

int main() { 
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> H >> W;
	gy = H - 1;
	gx = W - 1;
	rep(i, H) {
		rep(j, W) {
			cin >> s[i][j];
			if (s[i][j] == '.') {
				white++;
			}
		}
	}
	cout << max(-1, white - bfs(0, 0) - 1) << "\n";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const INF = 1001001001

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func calcCost(N, K int, hs []int) int {
	// Definition of DP
	dp := make([]int, N+K)
	// Initialization
	for i := 0; i < N+K; i++ {
		dp[i] = INF
	}
	// Index zero
	dp[0] = 0

	for i := 0; i < N; i++ {
		for j := 1; j <= K; j++ {
			chmin(&dp[i+j], dp[i]+abs(hs[i]-hs[i+j]))
		}
	}

	return dp[N-1]
}

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	hs := make([]int, N+K)
	for i := 0; i < N; i++ {
		fmt.Scan(&hs[i])
	}

	fmt.Println(calcCost(N, K, hs))
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>adj[n+1];
	vector<int>visited(n+1);
	vector<int>dist(n+1,-1);
	for(int i=1; i<=m; i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dist[1]=0;
	queue<int>q;
	q.push(1);
	visited[1]=1;
	while(!q.empty())
	{
		int node=q.front();
	    q.pop();
	    for(auto var : adj[node])
	    {
	    	if(!visited[var])
	    	{
	    		dist[var]=1+dist[node];
	    		visited[var]=1;
	    		q.push(var);
			}
		}
	}
	int num=*min_element(dist.begin()+1,dist.end());
	if(num==-1)
	 cout<<"No";
	else
	{
		cout<<"Yes\n";
		for(int i=2; i<=n; i++)
		{
			int mn=1000000;
			int ans;
			for(auto var : adj[i])
			{
				if(dist[var]<mn)
				{
					ans=var;
					mn=dist[var];
				}
			}
			cout<<ans<<"\n";
		}
	}
	return 0;
	
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int lcs(string x, string y) {
    int lx = x.size(), ly = y.size();
    vector<vector<int>> dp(lx+1, vector<int>(ly+1, 0));
    for (int i=1;i<=lx; i++){
        for (int j=1; j<=ly; j++){
            if (x[i-1] == y[j-1]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j]= max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    return dp[lx][ly];
}

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

    int q;
    cin >> q;
    for (int i=0;i<q;i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}



Measured memory_bytes: 6856
//22
#include<iostream>
#include<complex>
#include<cmath>

using namespace std;

typedef complex<double> P;

int main(){
  for(int n;cin>>n,n;){
    P p[100];
    for(int i=0;i<n;i++){
      double x,y;
      (cin>>x).ignore()>>y;
      p[i]=P(x,y);
    }
    int ans=1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(abs(p[i]-p[j])>2)continue;
	P c;
	if(p[i]==p[j]){
	  c=p[i];
	}else{
	  c=p[i]+polar(1.,arg(p[j]-p[i])+acos(abs(p[j]-p[i])/2));
	}
	int ci=0;
	for(int k=0;k<n;k++){
	  ci+=abs(p[k]-c)<1+1e-9;
	}
	if(ci>ans){
	  ans=ci;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define LD long double
const int MAXN = 303;

bool w[MAXN][MAXN][MAXN];
LD dp[MAXN][MAXN][MAXN];
int t[4], n;

LD result( int a, int b, int c) {
	if(a == 0 and b == 0 and c == 0)	
		return 0;
	if(w[a][b][c])
		return dp[a][b][c];
	w[a][b][c] = true;
	LD r1=0, r2=0, r3=0;
	if(a>0)	r1 = (LD)a/(LD)(a+b+c) * result(a-1, b, c);
	if(b>0)	r2 = (LD)b/(LD)(a+b+c) * result(a+1, b-1, c);
	if(c>0)	r3 = (LD)c/(LD)(a+b+c) * result(a, b+1, c-1);
	dp[a][b][c] = r1 + r2 + r3 + (LD)n/(LD)(a+b+c);
	return dp[a][b][c];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x;	cin >> x;
		++t[x];
	}
	cout << fixed << setprecision(10) << result( t[1], t[2], t[3]);
}


Measured memory_bytes: 459136
def main():
  m, d = map(int, input().split())
  result = 0
  for i in range(m):
    for j in range(d):
      tmp = seki(j+1)
      if tmp:
        if (i+1 == tmp):
          result += 1
  print(result)

def seki(day):
  if day < 10:
    return None
  d1 = day % 10
  d10 = day // 10
  if (d1 < 2 or d10 < 2):
    return None
  return d1 * d10 
      
main()


Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int fib[45];
    fib[0] = 1;
    fib[1] = 1;
    int n;
    cin >> n;
    for(int i=0;i<n-1;i++){
	fib[i+2] = fib[i+1] + fib[i];
    }
    cout << fib[n] << endl;

    return 0;
}

Measured memory_bytes: 1160
def main():
    N, K, S = map(int, input().split())

    if S == 10**9:
        for i in range(N):
            if i < K:
                print(S, end=" ")
            elif i == (N-1):
                print(1)
            else:
                print(1, end=" ")
    else:
        for i in range(N):
            if i < K:
                print(S, end=" ")
            elif i == (N-1):
                print(S+1)
            else:
                print(S+1, end=" ")
    return 0

if __name__ == '__main__':
    main()


Measured memory_bytes: 4220
def get_alphabet_num(s):
    return ord(s) - ord('a')


R = [-1] * 26
R_ = [-1] * 26
for s, t in zip(input(), input()):
    si = get_alphabet_num(s)
    ti = get_alphabet_num(t)
    if R[si] >= 0:
        # R[Si] >= 0 ならば R[Si] が Ti に等しいことを検査する
        if R[si] == ti:
            pass
        else:
            print('No')
            exit()
    if R_[ti] >= 0:
        # R_[Ti] >= 0 ならば R_[Ti] が Si に等しいことを検査する
        if R_[ti] == si:
            pass
        else:
            print('No')
            exit()
    # R[Si] < 0 ならば R[Si] := Ti とする
    R[si] = ti
    # R_[Ti] < 0 ならば R_[Ti] := Si とする
    R_[ti] = si
print('Yes')


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

int main() {
    int N;
    cin >> N; 
    long long int L[N];
    for(int i=0;i<N;i++) {
        cin >> L[i];
    }
    int count = 0;
    for(int i=0;i<N-2;i++) {
        for(int j=i+1;j<N-1;j++) {
            for(int k=j+1;k<N;k++) {
                if(L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i]) {
                    if(L[i]+L[j] > L[k] &&
                        L[j]+L[k] > L[i] &&
                        L[i]+L[k] > L[j]) {
                            count++;
                        }
                }
            }
        }
    }

    cout << count << endl;
}

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

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


template< typename G >
struct LowLink {
  const G &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;

  LowLink(const G &g) : g(g), used(g.size()), ord(g.size()), low(g.size()) {}

  int build(int idx = 0, int k = 0, int par = -1) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0, ordmax = k;
    for(auto &to : g[idx]) {
      if(!used[to]) {
        ++cnt;
        ordmax = build(to, ordmax, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return ordmax;
  }
};


int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  UnWeightedGraph g(V);
  for(int i = 0; i < E; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  LowLink< UnWeightedGraph > lowlink(g);
  lowlink.build();
  sort(lowlink.articulation.begin(), lowlink.articulation.end());
  for(auto &v : lowlink.articulation) printf("%d\n", v);
}



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

template <class T>
struct BIT {
    vector<T> lst;
    int treesize;
    // constructor
    BIT(int newn = 0) {
        treesize = newn;
        lst.resize(treesize + 1);
        for(int i = 0; i <= treesize; ++i) lst[i] = 0;
    }
    // a_place += num
    bool add(int place, T num) {
        while(place <= treesize) {
            lst[place] += num;
            place += place & -place;
        }
        return 1;
    }
    // add wide ver.(add num between l and r)
    bool addw(int left, int right, T num) {
        while(left <= right && left >= 1 && right <= treesize)
            add(left++, num);
        return 1;
    }
    // sum between l and r
    T calcsum(int place) {
        T answer = 0;
        while(place > 0) {
            answer += lst[place];
            place -= place & -place;
        }
        return answer;
    }
    // sum between l and r(calcsum wide ver.)
    T calcsumw(int left, int right) {
        return calcsum(right) - calcsum(left - 1);
    }
};

BIT<long long> memo;
long long n;
vector<long long> a,b,p;

void solve();

int main(){
    cin >> n;
    a.resize(n,1);
    b.resize(n,1);
    p.resize(n);
    memo = BIT<long long>(n);
    for(int i = 0;i < n;++i)cin >> p[i];
    solve();
    for(int i = 0;i < n;++i){
        if(i != 0)cout << " ";
        cout << a[i];
    }
    cout << endl;
    for(int i = 0;i < n;++i){
        if(i != 0)cout << " ";
        cout << b[i];
    }
    cout << endl;
    return 0;
}

void solve(){
    for(int i = 1;i < n;++i){
        a[i] = a[i-1] + 1;
        b[n-1-i] = b[n-i] + 1;
    }
    for(int i = 0;i < n;++i){
        long long now = p[n - 1 - i];
        memo.add(now,i);
    }
    for(int i = 0;i < n;++i){
        a[i] += memo.calcsum(i);
        b[i] += memo.calcsumw(i+2,n);
    }
}

Measured memory_bytes: 1280
program vvv;
var
  a:ansistring;
  c,f:boolean;
  i:longint;
begin
  readln(a);
  c:=false; f:=false;
  for i:=1 to length(a) do
    begin
      if a[i]='C' then c:=true
      else if a[i]='F' then f:=c;
    end;
  if (c and f) then writeln('Yes') else writeln('No');
end.

Measured memory_bytes: 128
/*
Task:F - Must Be Rectangular!
Statement: Given N points (1<=x,y<=10^5)
You can do the following operation find acute triangle
add the point to form it rectangular if that point doesn't exist yet;
Find the maximum number of operation
*/
#include<bits/stdc++.h>
using namespace std;
#define find DSUU
#define merge mergeeee
const int maxn=1e5+10;
int n,pa[maxn],sz[maxn];
bool vis[maxn];
int find(int h){
    return h==pa[h]?h:pa[h]=find(pa[h]);
}
vector<int> b[maxn];
set<int> s[maxn];
void merge(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return;
    if(s[x].size()<s[y].size())swap(x,y);
    pa[y]=x;
    for(auto j:s[y])
        s[x].insert(j);
    sz[x]+=sz[y];
    return;
}


int main(){
    scanf("%d",&n);
    int x,y;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        s[x].insert(y);
        b[y].push_back(x);
    }
    for(int i=1;i<=100000;i++)
        pa[i]=i,sz[i]=1;
       // cout<<"What did you merge\n";
    for(int i=1;i<=100000;i++){
        if(b[i].empty())continue;
        for(int j:b[i])
        merge(j,b[i].back());
    }
    long long ans=0;
    for(int i=1;i<=100000;i++){
            if(b[i].empty())continue;
            int j=find(b[i][0]);
        if(!vis[j]){
            vis[j]=true;
            ans+=(1LL*(int)s[j].size()*sz[j]);
        }
    }
    printf("%lld\n",ans-n);
}
/*
6
1 1
1 2
1 3
2 2
2 3
2 4
*/


Measured memory_bytes: 27392
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long li;

const int maxn = 1e5;

int n, p;
int c0, c1;

int main(void) {
  scanf("%d%d", &n, &p);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x & 1) ++c1; else ++c0;
  }
  if (p == 1 && c1 == 0) {
    puts("0");
    return 0;
  }

  li ans = 1;
  for (int i = 0; i < c0; ++i) {
    ans *= 2;
  }
  for (int i = 0; i < c1 - 1; ++i) {
    ans *= 2;
  }

  printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s = "FESTIVA";
    string t;
    const int sz = 600;
    rep(i,sz){
        t += s;
    }
    vector<ll>a(7);
    vector<ll>dp;
    rep(i,7*sz){
        rep(j,7)if(t[i] == s[j]){
            if(j)a[j] += a[j-1];
            else a[0]++;
        }
        if((i + 1) % 7 == 0){
            dp.push_back(a[6]);
        }
    }
    show(dp);
    ll k;
    cin >> k;
    vector<ll> c(sz);
    for(int i = sz - 1; i >= 0; i--){
        while(k - (c[i]+1)*dp[i]>=0){
            c[i]++;
        }
        k -= c[i] * dp[i];
    }
//    show(c);
    assert(k == 0);
    string ans;
    rep(i,sz){
        ans += s;
        ans += string(c[i],'L');
        cout << s << string(c[i],'L');
    }
    cout << endl;
    s += 'L';
    a.clear();
    a.resize(8);
    show(a);
    rep(i,ans.size()){
        rep(j,8)if(ans[i] == s[j]){
            if(j)a[j] += a[j-1];
            else a[0]++;
        }
//        show(i,a);
    }
    show(a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <list>
#include <cmath>
#include <queue>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

void rev(vector<ll> &x)
{
    reverse(x.begin(), x.end());
}

ll gcd(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll max(ll x, ll y)
{
    if (x > y)
    {
        return x;
    }
    else
    {
        return y;
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

void primeFactors(ll n, vector<ll> &vec)
{

    while (n % 2 == 0)
    {
        vec.push_back(2);
        n = n / 2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            vec.push_back(i);
            n = n / i;
        }
    }

    if (n > 2)
        vec.push_back(n);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

ll g(ll x)
{
    for (ll i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

void solve()
{
    string s;
    cin >> s;
    if (s[s.size() - 1] == 's')
    {
        cout << s << "es";
    }
    else
    {
        cout << s << 's';
    }
}

int main()
{

    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

//0 3 1 0 5 2 6
//0 0 1 2 3 5 6

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            var result = 0;
            foreach (var n in Enumerable.Range(0, S.Length))
            {
                if (S[n] != T[n])
                {
                    result += 1;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28032
import itertools
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
  x=input()
  if x[0]=='M':
    m+=1
  elif x[0]=='A':
    a+=1
  elif x[0]=='R':
    r+=1
  elif x[0]=='C':
    c+=1
  elif x[0]=='H':
    h+=1
    
ans=0

for lst in itertools.combinations([m,a,r,c,h],3):
  cnt=1
  for i in lst:
    cnt*=i
    
  ans+=cnt
  
print(ans)

Measured memory_bytes: 76272
// 0  153 10 10  23
// 0 0 10  10 10 23 = 53
// 0-based indexing
// A[0] = B[1]
// A[N-1] = B[N-1]
// A[i] = min(B[i], B[i+1])

#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n; cin >> n;
  vector<int> b(n);
  for (int i = 1; i < n; i++) cin >> b[i];

  vector<int> a(n);
  a[0] = b[1];
  a[n-1] = b[n-1];
  int sum = a[0] + a[n-1];

  for (int i = 1; i < n-1; i++) {
    a[i] = min(b[i], b[i+1]);
    sum += a[i];
  }

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String sinput = br.readLine();
    	String p = br.readLine();
    	String s = sinput + sinput;
    	int count = 0;
    	int index = 0;
    	
    	for (int i = 0; i < s.length(); i++)
    	{
    		if (p.charAt(0) == s.charAt(i))
    		{
    			if (i + p.length() < s.length())
    			{
    				if (p.equals(s.substring(i, i + p.length() )))
                		count++;
    			}
    			
    		}
    	}
    	if (count >= 1)
    		System.out.println("Yes");
    	else
    		System.out.println("No");
	}

}

Measured memory_bytes: 24396