akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int table[100000];

int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < 100000; i++) table[i] = 0;
        for (int i = 0; i < n; i++) {
            string s, t;
            cin >> s >> t;
            // 最初の時間を求める
            {
                int h = (s[0]-'0') * 10 + (s[1]-'0');
                int m = (s[3]-'0') * 10 + (s[4]-'0');
                int ss = (s[6]-'0') * 10 + (s[7]-'0');
                table[h*3600+m*60+ss]++;
            }
            // 到着の時間を求める
            {
                int h = (t[0]-'0') * 10 + (t[1]-'0');
                int m = (t[3]-'0') * 10 + (t[4]-'0');
                int ss = (t[6]-'0') * 10 + (t[7]-'0');
                table[h*3600+m*60+ss]--;
            }
        }
        int cur = 0, ans = 0;
        for (int i = 0; i < 100000; i++) {
            cur += table[i];
            ans = max(ans, cur);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1596
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)

diff = []
diff_2 = []
for i in range(n+1):
    diff.append(abs(a[i+1]-a[i]))

for i in range(n):
    diff_2.append(abs(a[i+2]-a[i]))

list_sum = sum(diff)

for i in range(n):
    x = diff[i] + diff[i+1] - diff_2[i]
    print(list_sum - x)



Measured memory_bytes: 16400
import java.util.*;

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

        int sunuke[] = new int[n];
        for(int i=0; i<n; i++) {
            sunuke[i] = 0;
        }

        for(int i=0; i<k; i++) {
            int a = sc.nextInt();
            for(int j=0; j<a; j++) {
                int b = sc.nextInt() - 1;
                sunuke[b] = 1;
            }
        }

        int count = 0;
        for(int i=0; i<n; i++) {
            if(sunuke[i] == 0) count++;
        }

        System.out.println(count);
	}
}

Measured memory_bytes: 46264
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
//俺の小文字が大きくなるプログラム
//ウホッ！！
int main()
{
    string str;
    getline(cin, str);
    transform(str.begin(), str.end(), str.begin(), ::toupper);
    cout << str << endl;
    return 0;
}

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

int main() {
    int n;
    cin>>n;
    string a;cin>>a;
    int min=99999999;
    vector<int> datw(n,0),date(n,0);
    int cntw=0,cnte=0;
    for(int i=0;i<n;i++){
        //i番目より左側に何個あるか
        if(a[i]=='W')cntw++;
        else cnte++;
        datw[i]=cntw;
        date[i]=cnte;
    }
    for(int i=0;i<n;i++){
        int cnt;
        if(i==0)cnt=date[n-1]-date[i];
        else cnt=datw[i-1]+date[n-1]-date[i];
        if(min>cnt)min=cnt;
    }
    cout<<min<<endl;
}


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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(M);
    scanInt(Q);
    vector<pair<int, int>> LR(M);
    REP(m, M){
        scanInt(Lm); --Lm;
        scanInt(Rm); --Rm;
        LR[m] = make_pair(Lm, Rm);
    }
    vector<vector<int>> board(N + 1, vector<int>(N + 1, 0));
    REP(m, M){
        auto& l = LR[m].first;
        auto& r = LR[m].second;
        board[0][r]++;
        board[l + 1][r]--;
    }
    REP(y, N){
        int temp = 0;
        REP(x, N){
            temp += board[y][x];
            board[y][x] = temp;
        }
    }
    REP(x, N){
        int temp = 0;
        REP(y, N){
            temp += board[y][x];
            board[y][x] = temp;
        }
    }
    REP(i, Q){
        scanInt(pi); --pi;
        scanInt(qi); --qi;
        cout << board[pi][qi] << endl;
    }
}

Measured memory_bytes: 3456
S = input()
Q = int(input())
front = ''
end = ''
cnt = 0
for _ in range(Q):
    T = input().split()
    if int(T[0]) == 1:
        cnt += 1
    else:
        F = int(T[1])
        C = T[2]
        if F == 1:
            if cnt%2==0:
                front = C+front
            else:
                end = end+C
        else:
            if cnt%2==0:
                end = end+C
            else:
                front=C+front
if cnt % 2 == 0:
    S = front+S+end
    print(S)
else:
    S = list(reversed(S))
    end = list(reversed(end))
    front = list(reversed(front))
    S = end+S+front
    print(''.join(S))

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

int main() {
  int n;
  cin>>n;
  if(n==0){
    cout << 2 << endl;
    return 0;
  }else if(n==1){
    cout << 1 << endl;
    return 0;
  }
  int cnt=1;
  ll a,b,c;
  b=1; c=2;
  while(cnt!=n){
    a=b+c;
    c=b;
    b=a;
    cnt++;
  }
  
  cout << b << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

int main(){
    ll N,M;
    cin >> N >> M;
    rep(i,M){
      ll a;cin >> a;
      N -= a;
    }
    if(N < 0) cout << -1 << endl;
    else cout << N << endl;
}


Measured memory_bytes: 3624
nlist=[]
command=input().split()

for c in command:
    if c=="+":
        ans=int(nlist[-1])+int(nlist[-2])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    elif c=="-":
        ans=int(nlist[-2])-int(nlist[-1])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    elif c=="*":
        ans=int(nlist[-2])*int(nlist[-1])
        nlist.pop(-1)
        nlist.pop(-1)
        nlist.append(ans)

    else:
        nlist.append(c)

print(nlist[0])


Measured memory_bytes: 5600
using System;

namespace AtCoder.BeginnersSelections
{
    class Test
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int top =0;

            for (int i = 0; i < 3; i++)
                if (str[i] == 'o')
                    top++;

            Console.WriteLine(700 + 100 * top);
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main(void) {
    int p1,p2,p3,d1,d2,pmin,dmin;
    scanf("%d%d%d%d%d",&p1,&p2,&p3,&d1,&d2);
    if (p1<p2&&p1<p3) {
        pmin=p1;
    } else if (p2<p1&&p2<p3) {
        pmin=p2;
    } else {
        pmin=p3;
    }
    if (d1<d2) {
        dmin=d1;
    } else {
        dmin=d2;
    }
    printf("%d\n",pmin+dmin-50);
    return 0;
}

Measured memory_bytes: 592
h,w,k = map(int,input().split())
g = [list(input()) for i in range(h)]
ans = [[1]*w for i in range(h)]
count = 1
path = False
l = []
for i in range(h):
    if "#" in g[i]:
        path = True
        done = 0
        for j in range(w):
            if g[i][j] == "#":
                done += 1
                if done >= 2:
                    count += 1
            ans[i][j] = count
        count += 1
        if l:
            for j in l:
                ans[j] = ans[i]
            l = []
    else:
        if path:
            ans[i] = ans[i-1]
        else:
            l.append(i)
for i in ans:
    print(*i)


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

long	f(long &h0, long &A, long &B, vector<long> &h, long &SA, long &SB) {
	SB=(h0+B-1)/B;
	SA=0;
	for (long i=0; i<h.size(); i++)
		if (h.at(i)>h0)
			SA +=(h.at(i)-h0+A-1)/A;
	return max(SA, SB);
}

int	main() {
	long N, A, B;
	cin >>N >>A >>B;
	A -=B;
	vector<long> h(N, 0);
	for (long i=0; i<N; i++)
		cin >>h.at(i);
	sort(h.begin(), h.end());
	long hl=0;
	long hh=h.back();
	long SA, SB;
	long HL=f(hl, A, B, h, SA, SB);
	long HH=f(hh, A, B, h, SA, SB);
	while(hh-hl>1) {
		long hm=(hl+hh)/2;
		long HM=f(hm, A, B, h, SA, SB);
		if (SA<SB) {
			hh=hm;
			HH=HM;
		} else {
			hl=hm;
			HL=HM;
		}
	}
	cout <<min(HH, HL) <<endl;
	return 0;
}



Measured memory_bytes: 1024
n=int(input())
def divisor(n): #約数
    f=[]
    d=[1]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    for i in range(len(f)):
        t=[]
        for j in range(1,f[i][1]+1):
            t.append(f[i][0]**j)
        for j in range(len(d)):
            for k in range(len(t)):
                d.append(d[j]*t[k])
    return sorted(d)
x=divisor(n)
a=x[len(x)//2]
c=0
while a>=10:
    a=a/10
    c+=1
print(c+1)

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int A=0,B=0,C=0,D=0;
	char bl[3];
	while (scanf("%*d,%2s",bl)!=EOF) {
		if (string(bl)=="A") {
				A++;
		} else if (string(bl)=="B") {
				B++;
		} else if (string(bl)=="AB") {
				C++;
		} else if (string(bl)=="O") {
				D++;
		}
	}
	printf("%d\n%d\n%d\n%d\n",A,B,C,D);
}

Measured memory_bytes: 0
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    ans=0
    for _ in range(n):
        l,r=MI()
        ans+=r-l+1
    print(ans)
main()

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

n, a, b = list(map(int,input().split()))

ans = 0
for i in range(1,n+1):
    tmpsum = 0
    for j in range(len(str(i))):
        tmpsum += int(str(i)[j])
    if(a <= tmpsum and tmpsum <= b):ans += i
print(ans)

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

int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<bool> from1(N, false), toN(N, false);
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    a--;
    b--;
    if (a == 0)
      from1[b] = true;
    if (b == N-1)
      toN[a] = true;
  }
  for (int i=0; i<N; i++)
    if (from1[i] && toN[i]) {
      cout << "POSSIBLE\n";
      return 0;
    }
  cout << "IMPOSSIBLE\n";
  return 0;
}

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


void solve(long long N, vector<long long> X){
  // たかだか候補は2つ。median と medianの手前
  long long m;
  vector<long long> sx = X;
  sort(sx.begin(), sx.end());
  long long premed=sx[ceill((N+1)/2)-1], med=sx[ceill((N+1)/2)];

  for(auto i=0;i<N;++i){
    if(X[i]<med) cout << med << "\n";
    else cout << premed << "\n";
  }


}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long N;
  scanf("%lld",&N);
  vector<long long> X(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&X[i]);
  }
  solve(N, move(X));
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int cnt=0;
    string w,t;
    cin>>w;
    cin>>t;
    while(t!="END_OF_TEXT") {
        REP(i,t.size()) {
            if('A'<=t[i]&&'Z'>=t[i]) t[i]+='a'-'A';
        }
        if(w==t) cnt++;
        cin>>t;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
//#include <I AK IOI>
using namespace std;
int n, m, x[15005], y[15005];
bool vis[15005];
vector<int> g[15005];
long long ans;
void dfs(int x) {
    if(vis[x])
        return;
    vis[x] = true;
    for(int i = 0; i < g[x].size(); i++)
        dfs(g[x][i]);
}
int cnt; 
int main() {
    ios::sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
        cin >> x[i] >> y[i];
    for(int i = 1; i <= m; i++) {
        memset(vis, false, sizeof(vis));
        for(int j = 1; j <= n; j++) {
            g[j].clear();
        }
        for(int j = 1; j <= m; j++) {
            if(j != i) {
                g[x[j]].push_back(y[j]);
                g[y[j]].push_back(x[j]);
            }
        }
        for(int j = 1; j <= n; j++) {
            if(!vis[j]) {
                dfs(j);
                cnt++;
            }
        }
        if(cnt > 1) {
            ans++;
        }
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long long a,b,c=1,k,i,n,j,ans,temp,p,m;
	   
	    int arr[4];
	    for(i=0;i<3;i++)
	    cin>>arr[i];
	   // cout<<arr[0]<<arr[1]<<arr[2];
	    sort(arr,arr+3);
	    if((arr[0]+arr[1])==arr[2])
	    cout<<"Yes";
	    else cout<<"No";
	   // cout<<arr[0]<<arr[1]<<arr[2];
	    
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int PRECISION = 6+1;

double water(double angle, double A, double B) {

    double top = A * (A * 1/tan(angle)) / 2;
    double bottom =  B * (B * tan(angle)) /2;

    if (top >= bottom ) { // <= half

        return bottom * A;
    } else {
       return A*A*B - top * A; 
    }


        // b * b tan /2 * a
        //  ab * a - (a * a ctan /2) * a
}

double bsearch(double A, double B, double X) {

    double l = 0, r = acos(-1)/2; // [0-90], pi=acos(-1)

    for (int i = 0; i < 100; i++) {
    
        double mid = (l+r)/2;

        if (water(mid, A, B) > X)
            r = mid;
        else
            l = mid;
    }

    return acos(-1) / 2 - l;
}

int main(){

    double A, B, X;
    cin >> A >> B >> X;

    double result = bsearch(A, B, X);
    cout << setprecision(PRECISION) << fixed << result*360/(acos(-1)*2) << "\n";

    return 0;
}


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

int main() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = (double) w * h / 2;
	int num;
	if (w == x * 2 && h == y * 2)
	num = 1;
	else
	num = 0;

	cout << fixed << setprecision(10) << ans << " " << num << endl;
}


Measured memory_bytes: 256
N,M = list(map(int,input().split()))
KA = []
for i in range(N):
    KA.append(list(map(int,input().split())))

food = [0 for i in range(M)]

for i in range(N):
    x = KA[i][1:]
    for j in x:
        food[j - 1] += 1

print(food.count(N))

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

int main(){
  string s;
  cin >> s;
  s[4] = s[7] = '\0';
  int y = atoi(&s[0]);
  int m = atoi(&s[5]);
  if(y < 2019){
    cout << "Heisei" << endl;
    return 0;
  }
  if(y == 2019 && m <= 4){
    cout << "Heisei" << endl;
    return 0;
  }
  cout << "TBD" << endl;
  return 0;
}


Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimensi0n, default_val) assert(type(default_val) ~= 'table') local n=dimensi0n local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----

local N = read.n()

local function first_last(x)
    local s = tostring(x)
    local first = tonumber(s:sub(1,1))
    return first, x%10
end

local t = array(1, 0)
for i=1,N do
    local f, e = first_last(i)
    t[f*10+e] = t[f*10+e] + 1
end


local cnt = 0
for x=1,9 do
    for y=1,9 do
        local cnt_a = t[x*10+y]
        local cnt_b = t[y*10+x]
        cnt = cnt + cnt_a * cnt_b
    end
end
print(cnt)

Measured memory_bytes: 2908
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n #各要素の親要素の番号を格納するリスト

    def find(self, x): #要素xが属するグループの根を返す
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y): #要素xが属するグループと要素yが属するグループとを併合する
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return

        if self.parents[x]>self.parents[y]:
            x,y=y,x

        self.parents[x]+=self.parents[y]
        self.parents[y]=x

    def size(self,x): #要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self,x,y): #要素x, yが同じグループに属するかどうかを返す
        return self.find(x)==self.find(y)

    def members(self,x): #要素xが属するグループに属する要素をリストで返す
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]

    def roots(self): #すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x<0]

    def group_count(self): #グループの数を返す
        return len(self.roots())

    def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#print(list(uf.all_group_members().values())) #グループ一覧を表示
#0-indexed n=5なら頂点の名前は0,1,2,3,4
import sys
input=sys.stdin.readline
v,e=map(int,input().split())
uf=UnionFind(v)
lis=[]
for i in range(e):
    x,y,w=map(int,input().split())
    lis.append([w,x,y])
import heapq
heapq.heapify(lis)

ans=0
for i in range(e):
    w,x,y=heapq.heappop(lis)
    if uf.same(x,y)==False:
        ans+=w
        uf.union(x,y)
    else:
        pass
print(ans)



Measured memory_bytes: 24632
from collections import Counter
h, w = map(int, input().split())
s = ''
for i in range(h):
    s += input()
c = list(Counter(s).values())
for i in range(len(c)):
    c[i] %= 4
a, b, c, d = c.count(0), c.count(1), c.count(2), c.count(3)
if b + d >= 2:
    print('No')
else:
    x = c + d
    if h % 2:
        x -= w // 2
    if w % 2:
        x -= h // 2
    if x <= 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a -b, a * b)) << endl;
    return 0;
}

Measured memory_bytes: 3584
_s = input()
_s = list(map(int, _s[:]))

ans = 0
for i, s in enumerate(_s):
    if i == 0:
        continue
    
    if s == _s[i-1]:
        ans = ans + 1
        if s == 0:
            _s[i] = 1
        else:
            _s[i] = 0

print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int N,D;
  cin >> N >> D;
  
  int sum = 0;
  int apple = N;
  
  for(int i = 0 ; i < N ; i++){
    
    sum++;
    
    apple -= (2*D + 1);
    
    if(apple <= 0){
      
      break;
      
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    Int A, B, C; cin >> A >> B >> C;

    Int D = C - (A+B);
    if(D <= 0) {
        cout << "No" << endl;
    } else if (4*A*B < D*D){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def knapsack(N,W,weight,value):
  #初期化
  inf=float("inf")
  dp=[[inf for i in range(W+1)] for j in range(N+1)]
  dp[0][0]= 0
  #DP
  for i in range(N):
    for w in range(W+1):
      if 0 <= w-weight[i]: #dp[i][w-weight[i]の状態にi番目の荷物が入る可能性がある
        dp[i+1][w]=min(dp[i+1][w-weight[i]]+value[i], dp[i][w])
      else:
        dp[i+1][w]=dp[i][w]
  return dp
 
H,N = map(int,input().split())
 
weight=[]
value=[]
for i in range(N):
    n,a=input().split()
    weight.append(int(n))
    value.append(int(a))
MAX = max(weight)
dp = knapsack(N,H+MAX,weight,value)
 
print(min(dp[N][H:H+MAX]))


Measured memory_bytes: 317576
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<vector>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

#define ld  long double
#define ll  long long int
#define ull unsigned long long int
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define endl "\n"

const ll INF = 1LL << 60;
const ld EPS = 1e-11;

//切り上げ整数除算
int divRoundUp(const int& a, const int& b) { return (a + b - 1) / b; }
//四捨五入
int roundOff(const double& a) { return (int)(a + 0.5); }
// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const ld& r) { return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const ld& a, const ld& b) { return sgn(a - b); }
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; }

using namespace std;

inline void Main() {
	int a[3]; REP(i,3) cin >> a[i];
	sort(a, a + 3);
	cout << a[0] + a[1] << endl;
}

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

	Main();

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_variables, dead_code, clippy::many_single_char_names, non_upper_case_globals, unused_imports, unused_macros)]
use std::{
    collections::{BTreeMap, HashSet, HashMap, VecDeque, LinkedList},
    io::{stdin, stdout, StdinLock, StdoutLock, BufReader, BufWriter, prelude::*},
    mem::swap,
    str::FromStr,
};

struct Reader<'a> {
    stdin: BufReader<StdinLock<'a>>
}

#[cfg(not(debug_assertions))]
macro_rules! yubi {
    () => { unsafe { std::hint::unreachable_unchecked() } }
}

#[cfg(debug_assertions)]
macro_rules! yubi {
    () => { panic!() }
}

impl<'a> Reader<'a> {
    fn new(stdin: BufReader<StdinLock<'a/*'*/>>) -> Self {
        Self {stdin}
    }
    fn read_str(&mut self) -> String {
        let mut s = String::with_capacity(100);
        self.stdin.read_line(&mut s).unwrap();

        if s.ends_with('\n') { s.pop(); if s.ends_with('\r') { s.pop(); } }
        s
    }
    fn read_int<T: FromStr>(&mut self) -> T {
        match self.read_str().parse::<T>() {
            Ok(n) => n,
            _ => yubi!()
        }
    }
    fn read_vec(&mut self) -> Vec<String> {
        let t = self.read_str();
        t.split(' ').map(|x| x.to_owned()).collect()
    }
    fn read_vec_int<T: FromStr>(&mut self) -> Vec<T> {
        let t = self.read_str();
        t.split(' ').map(|x| match x.parse::<T>() {Ok(n) => n, _ => yubi!()}).collect()
    }
}

macro_rules! pipe_read {
    ($r: expr, str, $($x: ident),+) => {
        let t = $r.read_str();
        let mut it = t.split(' ');
        $($x = it.next().unwrap();)+
    };
    ($r: expr, $t: ty, $($x: ident),+) => {
        let t = $r.read_str();
        let mut it = t.split(' ').map(|x| x.parse::<$t>().unwrap());
        $($x = it.next().unwrap();)+
    }
}

macro_rules! pipe {
    ($r: expr, str, $($x: ident),+) => {
        pipe_read!($r, str, $($x),+);
    };
    (declare $r: expr, str, $($x: ident),+) => {
        $(let $x: &str;)+
        pipe_read!($r, str, $($x),+);
    };
    ($r: expr, $t: ty, $($x: ident),+) => {
        pipe_read!($r, $t, $($x),+);
    };
    (declare $r: expr, $t: ty, $($x: ident),+) => {
        $(let $x: $t;)+
        pipe_read!($r, $t, $($x),+);
    };
}

const M: usize = 1_000_000;

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    
    solve(&mut Reader::new(BufReader::with_capacity(M, stdin.lock())), &mut BufWriter::with_capacity(M, stdout.lock()));
}

fn solve(r: &mut Reader, w: &mut BufWriter<StdoutLock>) {
    let a = r.read_int::<usize>();
    let mut total = a-1;
    total += a-2;
    let n = (a+1)>>1;

    if n > 2 {
        for i in 2..n {
            total += (a-1)/i-1;
        }
    }
    writeln!(w, "{}", total).unwrap();
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define MP make_pair
#define PB push_back
#define X first
#define Y second

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, x, t;
    cin >> n >> x >> t;

    cout << ((n / x) + (n % x > 0)) * t << '\n';

    return 0;
}

// g++ sol.cpp -o sol.out -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17

Measured memory_bytes: 3616
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int n,cnt,a[N],b[N];
long long sum;
int read() {
	int tmp=0, fh=1; char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') fh=-1; c=getchar();}
	while (c>='0'&&c<='9') tmp=tmp*10+c-48, c=getchar();
	return tmp*fh;
}
int main() {
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(), sum+=a[i];
	for (int i=1;i<=n;i++) b[i]=read(), sum-=b[i];
	if (sum<0) {puts("-1"); return 0;}
	for (int i=1;i<=n;i++) a[i]-=b[i];
	sort(a+1,a+n+1);
	for (int i=1;i<=n&&a[i]<=sum;i++) {
		if (a[i]<0) continue;
		sum-=a[i]; cnt++;
	}
	printf("%d\n",n-cnt);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.


int _find(string &str){
    
    int num=0;
    int ans=INT_MAX;
    for(int i=0;i<str.l();i++){
        num=num*10 + str[i]-'0';    
        if(i>=2){
            ans=min(ans,abs(num-753));
            num%=100;
        }
    }
    return ans;
}
void solve(){
    string str;
    cin>>str;
    
    cout<<_find(str)<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>

int main(){
    int a, b;

    std::cin >> a >> b;
    if(a < b){ 
        std::cout << "a < b\n";
    }   
    else if(a > b){ 
        std::cout << "a > b\n";
    }   
    else {
        std::cout << "a == b\n";
    }   
    
    return 0;
}

Measured memory_bytes: 1124
def solve():
    min_number, max_number = list(map(int, input().split()))

    current_number = min_number
    answer = 1

    while True:
        next_number = current_number * 2
        if next_number <= max_number:
            current_number = next_number
            answer += 1
        else:
            break

    print(answer)


solve()

Measured memory_bytes: 38256
// 2016-11-25
#include <iostream>
#include <string>
#define L false
#define R true

bool b[26] = {L, L, L, L, L, L, L, R, R, R, R, R, R, R, R, R, L, L, L, L, R, L, L, L, R, L};

int main() {
	std::string s;
	int n;
	bool c;
	for (std::cin >> s; s[0] != '#'; std::cin >> s) {
		n = 0;
		c = b[s[0] - 'a'];
		for (int i = 1; i < s.length(); i++) {
			if (b[s[i] - 'a'] != c) {
				n++;
				c = b[s[i] - 'a'];
			}
		}
		std::cout << n << std::endl;
	}
	return 0;
}

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

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

    int N;
    cin >> N;
    vector<int> A(N + 1);
    A.at(0) = 0;
    ll sum = 0;
    for (int i = 1; i <= N; ++i) {
        cin >> A.at(i);
        sum += abs(A.at(i) - A.at(i - 1));
    }
    sum += abs(A.at(N) - A.at(0));

    vector<int> dx1(N + 1), dx2(N + 1);
    for (int i = 1; i <= N; ++i) {
        dx1.at(i) = abs(A.at(i) - A.at(i - 1)) + abs(A.at((i + 1) % (N + 1)) - A.at(i));
        dx2.at(i) = abs(A.at((i + 1) % (N + 1)) - A.at(i - 1));
    }

    for (int i = 1; i <= N; ++i) {
        cout << sum - dx1.at(i) + dx2.at(i) << endl;
    }

    return 0;
}

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

const int INF = numeric_limits<int>::max();

int main()
{
    int N;
    cin >> N;
    vector<int> H(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> H[i];
    }

    vector<int> dp(N + 1, INF);
    dp[1] = 0;
    for (int n = 2; n <= N; ++n) {
        dp[n] = min(dp[n], dp[n - 1] + abs(H[n] - H[n - 1]));
        if (n - 2 < 1) {
            continue;
        }
        dp[n] = min(dp[n], dp[n - 2] + abs(H[n] - H[n - 2]));
    }
    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

long long int H;
int N;
long long int A[100005];

int main(void) {
	cin >> H >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	long long int sum = 0;

	for (int i = 1; i <= N; i++) { sum += A[i]; }


	if (sum >= H) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int k;
bool h[N];
int main(){
	scanf ("%d", &k);
	
	int ans = 1;
	int r = 7 % k;
	if (!r) {
		puts("1");
		return 0;
	}
	while (1) {
		ans++;
		r = (r * 10 + 7) % k;
		if (!r) break; 
		
		if (h[r]) {
			ans = -1;
			break;
		}
		h[r] = 1;
	}
	printf ("%d\n", ans);
  return 0;
}

Measured memory_bytes: 4796
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
template <typename T>
ll SIZEOF(T a){return (ll)a.size();}
ll xlcm(ll a, ll b){return (a/__gcd(a, b))*b;}

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


const int N = 100005;


void SOLVE(){
    ll cnt = 0;
    ll l, r, d;
    cin >> l >> r >> d;
    for(ll i=l; i<=r; i++){
        if(i%d==0){
            cnt++;
        }
    }
    cout << cnt << '\n';
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif

    ll TC = 1;
    // cin >> TC;
    for(ll tc1=1; tc1<=TC; tc1++){
        // cout << "Case #" << tc1 << ": ";
        SOLVE();
    }
    printclock;
}

Measured memory_bytes: 3776
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long N, A, B;
        N = scanner.nextLong();
        A = scanner.nextLong();
        B = scanner.nextLong();
        /*if (N == 1) {
            if (A == B) {
                System.out.println("1");
            } else {
                System.out.println("0");
            }
        } else {
            if (A > B) {
                System.out.println("0");
            } else {
                System.out.println((long)(B - A) * (N - 2) + 1);
            }
        }*/
        if (A > B) {
            System.out.println("0");
            return;
        }
        if (N == 1) {
            if (A == B) {
                System.out.println("1");
            } else {
                System.out.println("0");
            }
            return;
        }
        /*long min = 0, max = 0;
        for (int i = 0; i < N - 1; i++) {
            min += A;
            max += B;
        }
        min += B;
        max += A;*/
        System.out.println((B - A) * (N - 2) + 1);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<vector>
#define MaxN 200000+100
using namespace std;
int sum[MaxN];
vector<int>arr[MaxN];
int flag[MaxN];
int dfs2(int now,int limit_d,int limit_u)
{
    if(now>limit_u || now<limit_d)
    {
        return 0;
    }
  //  printf(" ----%d",now);
    flag[now]=2;
    int sum=1;
    for(int i=0;i<arr[now].size();i++)
        if(flag[arr[now][i]]==0)
            sum+=dfs2(arr[now][i],limit_d,limit_u);
    flag[now]=0;
    return sum;
}
void dfs(int fa,int now,int max,int second,bool f)
{
  //  printf("%d %d %d ",now,second,max);
    flag[now]=1;
    if(now<max)
    {
    //    printf("1.");
        sum[now]=sum[fa];
        int a,b;
        a=b=0;
        if(f==true)
        {
            a=dfs2(now,-1,max);
            b=dfs2(now,-1,second);
            flag[now]=1;
            sum[now]+=a-b;
            f=false;
        }
    }
    else
    {
   //     printf("2.");
        for(int i=0;i<arr[now].size();i++)
        {
            if(flag[arr[now][i]]==0)
            {
                sum[now]+=dfs2(arr[now][i],-1,max);
            }
        }
        sum[now]+=sum[fa]+1;
        second=max;
        max=now;
        f=true;
    }
 //   printf("         %d\n",sum[now]);
    for(int i=0;i<arr[now].size();i++)
        if(flag[arr[now][i]]!=1)
            dfs(now,arr[now][i],max,second,f);
}
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N-1;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        arr[a].push_back(b);
        arr[b].push_back(a);
    }
    flag[1]=1;
    sum[1]=1;
    for(int i=0;i<=arr[1].size();i++)
        dfs(1,arr[1][i],1,0,true);
    for(int i=2;i<=N;i++)
    {
        if(i!=2)
            printf(" ");
        printf("%d",sum[i]-1);
    }
    return 0;
}




Measured memory_bytes: 29696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int a[500];
int main()
{
    ll n, x;
    cin >> n >> x;
    x = __gcd(n, x);
    x = n - x;
    cout<<3*x<<endl;
    return 0;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  cin >> n;

  vector<pair<int, int>> input(n - 1);
  vector<vector<int>> tree(n);
  rep (i, 0, n - 1) {
    cin >> input[i].first >> input[i].second;
    input[i].first--;
    input[i].second--;

    tree[input[i].first].push_back(input[i].second);
    tree[input[i].second].push_back(input[i].first);
  }

  int memo[n];
  memset(memo, 0, sizeof(memo));
  queue<pair<int, int>> que;
  que.push(make_pair(0, -1));
  map<pair<int, int>, int> mp;
  int k = 0;

  while (!que.empty()) {
    pair<int, int> id = que.front();
    que.pop();

    memo[id.first] = 1;
    k = max(k, (int)tree[id.first].size());

    int cur_c = 1;
    for (int tmp : tree[id.first]) {
       if (memo[tmp] != 0)
        continue;

      if (cur_c == id.second)
        cur_c++;
      mp[make_pair(id.first, tmp)] = cur_c;
      mp[make_pair(tmp, id.first)] = cur_c;
      que.push(make_pair(tmp, cur_c));
      cur_c++;
    }
  }

  cout << k << endl;
  rep (i, 0, n - 1) {
    cout << mp[input[i]] << endl;
  }
	return 0;
}


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

int main(){
	#ifdef LOCAL_DEFINE
		freopen("../a.in","r",stdin);
		freopen("../a.out", "w",stdout);
	#endif

	string s;
	cin >> s;
	string sAns="";
	for(int i=0;i<s.length();i++){
		if(s[i]=='A'){
			sAns += 'T';
		} else if(s[i]=='T'){
			sAns += 'A';
		} else if(s[i]=='G'){
			sAns += 'C';
		} else {
			sAns += 'G';
		}
	}
	cout << sAns << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	if(s[0]==s[s.size()-1])
    	if(s.size()&1)
   	        printf("Second");
  	    else
            printf("First");
    else
        if(s.size()&1)
            printf("First");
        else
            printf("Second");
	return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 5;

vector < int > x (N), y (N), p (N), sz (N);
vector < vector < int > > adj (N);

int find (int u) {
  if (u == p[u]) return u;
  return p[u] = find (p[u]);
}

void merge (int u, int v) {
  u = find (u);
  v = find (v);
  if (u != v) {
    if (sz[u] > sz[v]) swap (u, v);
    p[u] = v;
    sz[v] += sz[u];
  }
}

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

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];

  vector < pair < int, int > > v;
  for (int i = 1; i <= n; i++) {
    v.push_back ({x[i], i});
  }
  sort (v.begin(), v.end());

  for (int i = 1; i < n; i++) {
    if (v[i].first == v[i - 1].first) {
      merge (v[i].second, v[i - 1].second);
    }
  }

  for (int i = 0; i < n; i++) v[i] = {y[i + 1], i + 1};
  sort (v.begin(), v.end());

  for (int i = 1; i < n; i++) {
    if (v[i].first == v[i - 1].first) {
      merge (v[i].second, v[i - 1].second);
    }
  }

  for (int i = 1; i <= n; i++) adj[find (i)].push_back (i);

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    set < int > sx, sy;
    for (auto to : adj[i]) {
      sx.insert (x[to]);
      sy.insert (y[to]);
    }
    ans += (ll)sx.size() * (int)sy.size();
  }

  cout << ans - n << '\n';
}


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

int main(){
    i64 a,b,x,y;
    cin>>a>>b>>x>>y;
    cout<<max(max(max(a*x,a*y),b*x),b*y)<<endl;
    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int n;
  cin >> n;
  vector<int>v(n), o, e;
  map<int, int> odd, even;
  REP(i, n){
    cin >> v[i];
    if(i % 2){
      even[v[i]]++;
    }
    else{
      odd[v[i]]++;
    }
  }
  int maxo = 0, idx1 = 1;
  for(auto it = odd.begin(); it != odd.end(); it++){
    if(maxo < it->second){
      maxo = it->second;
      idx1 = it->first;
    }
    o.push_back(it->second);
  }
  int maxa = 0, idx2 = -1;
  for(auto it = even.begin(); it != even.end(); it++){
    if(maxa < it->second){
      maxa = it->second;
      idx2 = it->first;
    }
    e.push_back(it->second);
  }
  sort(e.begin(), e.end());
  sort(o.begin(), o.end());
  int ans=INF;
  if(idx1 == idx2){
    if(e.size()==1 && o.size()==1){
      ans = n/2;
    }
    if(e.size()>1){
      ans = n-maxo-e[e.size()-2];
    }
    if(o.size()>1){
      ans = min(ans,n-maxa-o[o.size()-2]);
    }
  }
  else{
    ans = n-maxa - maxo;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5888
using System;
class Program {
  static void Main(string[] args) {
    int minX, maxX, minY, maxY;
    string[] vals;
    vals = Console.ReadLine().Split();
    minX = minY = 0;
    maxX = int.Parse(vals[0]);
    maxY = int.Parse(vals[1]);
    int N = int.Parse(vals[2]);

    for (int i = 0; i < N; ++i) {
      vals = Console.ReadLine().Split();
      int x = int.Parse(vals[0]);
      int y = int.Parse(vals[1]);
      int a = int.Parse(vals[2]);

      switch (a) {
        case 1:
          minX = Math.Min(maxX, Math.Max(x, minX));
          break;
        case 2:
          maxX = Math.Max(minX, Math.Min(x, maxX));
          break;
        case 3:
          minY = Math.Min(maxY, Math.Max(y, minY));
          break;
        case 4:
          maxY = Math.Max(minY, Math.Min(y, maxY));
          break;
      }
    }

    int ans = (maxX - minX) * (maxY - minY);

    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

#define pi acos(-1)
// ostream & operator<<(ostream & os, const vector<string> & v)
// {
// 	for (auto e : v)
// 		os << e << " ";
// 	return os;
// }
double angle(int a, int b, int x)
{
	double middle = a * b * a / 2.0;
	double s = x * 1.0 / a;
	if (x * 1.0 < middle){
		return 180 * atan(b * b / s / 2) / pi;
	}

	return 180 * atan(2 * (a * b - s) / a / a) / pi;
}

int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	int toatal = a * a * b;
	
	if (x == toatal / 2) cout << fixed << setprecision(10) << 45.0 << endl; 
	else cout << fixed << setprecision(10) << angle(a, b, x) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll n; cin>>n;
        vector<ll> a(n);
        FOR(I,0,n) cin>>a[I];
        vector<ll> ans(n,0);
        ll xo = 0;
        FOR(i,0,n) xo^=a[i];
        FOR(i,0,n){
            ans[i] = xo^a[i];
        }
        for(auto x:ans) cout<<x<<" ";
    }   
 }

Measured memory_bytes: 6312
use proconio::{input, marker::Usize1};

fn dfs(g: &[Vec<usize>], root: usize, visited: &mut [bool]) {
    for &i in g[root].iter() {
        if visited[i] {
            continue;
        }
        visited[i] = true;
        dfs(g, i, visited);
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m],
    }
    let mut nei = vec![vec![]; n];
    for (a, b) in ab {
        nei[a].push(b);
        nei[b].push(a);
    }

    let mut visited = vec![false; n];
    let mut c = 0;
    for i in 0..n {
        if !visited[i] {
            c += 1;
            dfs(&nei, i, &mut visited);
        }
    }
    println!("{}", c - 1);
}


Measured memory_bytes: 10704
<?php
// $tmp = [];
while($line = fgets(STDIN)){
   $tmp[] = explode(" ",trim($line));
}
// var_dump($tmp);
foreach($tmp as $v){
    if($v[0] == "0" && $v[1] == "0"){
        break;
    }
    for($i=0; $i<$v[0]; $i++){
        echo str_repeat("#", $v[1]),PHP_EOL;
    }
    echo PHP_EOL;
}


Measured memory_bytes: 9280
int main(){
  int n;
  scanf("%d",&n);
  int b[n-1],a = 0;
  for(int i = 0;i<n-1;i++){
    scanf("%d",&b[i]);
    if(i == 0){
      a += b[0];
    }else if(b[i]>b[i-1]){
      a += b[i-1];
    }else{
      a += b[i];
    }
  }
  a += b[n-2];
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    pair = 0
    A = [int(a) for a in input().split()]
    for i, a in enumerate(A):
        if A[a-1] == i + 1: pair += 1
    print(pair // 2)

    return 0

if __name__ =="__main__":
    solve()

Measured memory_bytes: 13876