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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,k;

int main(){
    cin>>n>>k;
    double ans = 0;
    FOR(s,1,n+1){
        double p = 1.0 / n;
        int t = s;
        while(t<k){
            t *= 2;
            p /= 2;
        }
        ans += p;
    }
    printf("%.15f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ld long double
#define MOD 1000000007
#define u128 __int128
#define ff first
#define ss second
#define INTMAX 1000000009

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

void solve()
{
	ll n;
	cin >> n;
	int a[n], f[2] = {};
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		if(a[i] == 0)
			f[0]++;
		else
			f[1]++;
		sum += a[i];
	}
	ll k, x;
	cin >> k >> x;
	if(x == 0)
	{
		cout << sum << "\n";
	}
	else
	{
		sum += f[0];
		int le = f[0] % k;
		if(2 * le > k && f[1] >= k - le)
			sum -= (k - le);
		else
			sum -= le;
		cout << sum << "\n";
	}
}
#define  N 100005
int n, m;
int par[N];

int findset(int a)
{
	if(par[a] == a)
		return a;
	return par[a] = findset(par[a]);
}

void Union(int a, int b)
{
	int k1 = findset(a);
	int k2 = findset(b);
	par[k1] = k2;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i <= n; ++i)
	{
		par[i] = i;
	}
	int x, y, z;
	for (int i = 0; i < m; ++i)
	{
		cin >> x >> y >> z;
		Union(x, y);
	}
	int no = 0;
	for(int i = 1;i <= n; ++i)
	{
		if(i == findset(i))
			no++;
	}
	cout << no;
	return 0;	
}

Measured memory_bytes: 1152
N = int(input())
Bst = 0
Alas = 0
BA = 0
AB = 0
for i in range(N):
    s = input()
    if s[0] == 'B' and s[-1] == 'A':
        BA += 1
    elif s[0] == 'B':
        Bst += 1
    elif s[-1] == 'A':
        Alas += 1
    AB += s.count('AB')
    
if Bst >= 1 and Alas >= 1:
    AB += (BA+1+min(Bst-1, Alas-1))
    
elif Bst == 0 and Alas == 0:
    if BA >= 1:
        AB += (BA-1)
else:
    AB += BA
    
print(AB)
    

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	FOR(i, 1, n-1) {
		cin >> b[i];
	}
	a[1] = b[1];
	a[n] = b[n - 1];
	FOR(i, 2, n - 1) {
		a[i] = min(b[i - 1], b[i]);
	}
	ll sum = accumulate(ALL(a),0LL);
	pv(sum)
	return(0);
}

Measured memory_bytes: 256
///b. replacing integer
#include <stdio.h>
#include <math.h>

long long int diff(long long int a, long long int b)
{
    if(a>=b) return a-b;
    else return b-a;
}
int main()
{
    long long int n,k;
    scanf("%lld %lld",&n,&k);

    if(n<k){
        if(diff(n,k)<n) printf("%lld",diff(n,k));
        else printf("%lld",n);
        return 0;
    }
    if(n%k==0){
        printf("0");
        return 0;
    }
    n=n%k;
    if(n<diff(n,k)) printf("%lld",n);
    else printf("%lld",diff(n,k));

    return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

#define MAX_N 100000
int tmpa[MAX_N],tmpb[MAX_N];

void func(int Len,long long *heada){
    int cent = Len/2;
    int tip  = Len%2;
    if(Len > 2){
        func(cent, heada);
        func(cent+tip, heada+cent);
    }
    int i,j,k;
    i = k = 0;
    j = cent;
    if(Len == 1){
        tmpa[k] = heada[0];
        k++;
    }else{
        while(i < cent && j < Len){
            if(heada[i] > heada[j]){
                tmpa[k] = heada[i];
                k++;
                i++;
            }else{
                tmpa[k] = heada[j];
                k++;
                j++;
            }
        }

        while(i < cent){
            tmpa[k] = heada[i];
            k++;
            i++;
        }

        while(j < Len){
            tmpa[k] = heada[j];
            k++;
            j++;
        }
    }
    int l;
    for(l = 0;l < k;l++){
        heada[l] = tmpa[l];
    }
    return;
}

int main(void){
    int N;
    int A[MAX_N],B[MAX_N];
    long long int AB[MAX_N];
    scanf(" %d",&N);
    int i;
    for(i = 0;i < N;i++){
        scanf(" %d %d",&A[i],&B[i]);
        AB[i] = A[i] + B[i];
    }
    func(N,AB);
    long long int bsum = 0;
    for(i = 0;i < N;i++){
        bsum += B[i];
    }
    long long int ans = 0;
    for(i = 0;i < N;i+=2){
            ans += AB[i];
    }
    ans = ans - bsum;
    printf("%lld\n",ans);
    return 0;
}

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

using namespace std;

using ll = long long; 

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

    ll N, P;
    cin >> N >> P;
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= P; ++p) {
        if (P % p != 0) continue;
        ll num = 0;
        while (P % p == 0) {
            ++num;
            P /= p;
        }
        res.emplace_back(p, num);
    }
    if (P > 1) res.emplace_back(P, 1);

    ll gcm = 1;
    for (auto p: res) {
        if (p.second >= N) gcm *= (ll)pow(p.first, (p.second / N));
    }

    cout << gcm << '\n';

    return 0;
}


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

#define type int

type solve(int a, int b, int h){
  type ans = (a + b) * h / 2;

  return ans;
}

int main(){

  int a, b, h;
  std::cin >> a >> b >> h;

  type result = solve(a, b, h);

  std::cout << result << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
from math import floor
a,b=map(int,input().split())
A=[]
B=[]
for i in range(1,10001):
    x=int(floor(i*0.08))
    y=int(floor(i*0.1))
    if x==a:
        A.append(i)
    if y==b:
        B.append(i)
A=set(A)
B=set(B)
ans=list(A&B)
if ans:
    print(min(ans))
else:
    print(-1)

Measured memory_bytes: 3064
# coding=utf-8

n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for _ in range(n):
    line = input()
    if line[0]=="M":
        m += 1
    elif line[0]=="A":
        a += 1
    elif line[0]=="R":
        r += 1
    elif line[0]=="C":
        c += 1
    elif line[0]=="H":
        h += 1

ret = m*a*r +m*a*c +m*a*h +m*r*c +m*r*h +m*c*h +a*r*c +a*r*h +a*c*h +r*c*h

print(ret)


Measured memory_bytes: 3064
a=int(input())
b=list(map(int,input().split()))

c=[0,abs(b[0]-b[1])]
for i in range(2,a):
  d=min(c[i-2]+abs(b[i-2]-b[i]),c[i-1]+abs(b[i-1]-b[i]))
  c.append(d)
print(c[a-1])

Measured memory_bytes: 13908
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	ll out=0;
	ll mi=inf;
	rep(i,n-1)in[i+1].second+=in[i].second;
	rep(i,n){
		ll t=in[i].second-in[i].first;
		ll tt=(i?in[i-1].second:0)-in[i].first;
		mi=min(mi,tt);
		out=max(out,t-mi);
	}
	cout<<out<<endl;
}










Measured memory_bytes: 3456
#include <iostream>
#include <map>

using namespace std;

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

    map<char, int> mp;
    for(int i=0; i<str.size(); i++) {
        mp[str[i]]++;
    }
    bool flag=true;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(itr->second%2) {
            flag=false;
            break;
        }
    }
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    

    return 0;
    
}

Measured memory_bytes: 256
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

void hora(int tc) {
	string s;
	cin>>s;
	int tot[3] = {0,0,0};
	int n = s.size();
	int mx = 0;
	for(int i = 0;i < n;i++) {
		tot[s[i] - 'a']++;
		mx = max(mx, tot[s[i] - 'a']);
	}
	int totw = n / 3 + (n % 3 != 0);
	if(mx > totw) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
  }
  else if (0 < a) {
    cout << "Positive" << endl;
  }
  else if (b < 0) {
    if ((b - a + 1) % 2 == 0) {
      cout << "Positive" << endl;
    }
    else {
      cout << "Negative" << endl;
    }
  }
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= print . ( $ 0 ) . foldl (.) id . map f

f '+' = succ
f '-' = pred

Measured memory_bytes: 380
# D - Water Bottle

from math import atan, degrees

a, b, x = map(int, input().split())
volume = a * a * b

if x * 2 >= volume:
  h = 2 * b - 2 * x / (a * a)
  print(degrees(atan(h / a)))
else:
  h = 2 * x / (a * b)
  print(degrees(atan(b / h)))

Measured memory_bytes: 9380
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

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

#define MOD ((ll)1000000007)

int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int H, W;
	cin >> H >> W;

	vector<vector<char>> s(H, vector<char>(W));

	for (size_t i = 0; i < H; i++)
	{
		for (size_t j = 0; j < W; j++)
		{
			cin >> s[i][j];
		}
	}

	bool ans = true;
	for (size_t i = 0; i < H; i++)
	{
		for (size_t j = 0; j < W; j++)
		{
			if (s[i][j] == '#')
			{
				bool ok = false;
				if (i > 0)
				{
					if (s[i - 1][j] == '#')
					{
						ok = true;
					}
				}
				if (j > 0)
				{
					if (s[i][j - 1] == '#')
					{
						ok = true;
					}
				}
				if (i < H - 1)
				{
					if (s[i + 1][j] == '#')
					{
						ok = true;
					}
				}
				if (j < W - 1)
				{
					if (s[i][j + 1] == '#')
					{
						ok = true;
					}
				}

				if(!ok) {
					ans = false;
				}
			}
		}
	}

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


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 
const int MAX_N = 200005;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c; cin >> a >> b >> c;
  if(a>b) swap(a,b);
  if(a>c) swap(a,c);
  b -= a; c -= a;
  if(b>c) swap(b,c);
  dump(a,b,c);
  int ans = 0;
  ans += b/2;
  b -= ans * 2;
  c -= ans * 2;
  ans += b;
  dump(ans);
  ans += c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop with position = 0
        for idx from offset below (length dest-vector)
        do (setf (values (aref dest-vector idx) position)
                 (parse-integer string :start position :junk-allowed t))
           (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (ls (make-array n :element-type 'uint32)))
    (split-ints-into-vector (read-line) ls)
    (setf ls (sort ls #'>))
    (if (< (aref ls 0)
           (loop for i from 1 below n
                 sum (aref ls i)))
        (println "Yes")
        (println "No"))))

#-swank(main)


Measured memory_bytes: 21732
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=1;i<=n;i++)
#define py printf("YES\n")
#define pn printf("NO\n")
#define pb push_back
#define ll long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define D(x) cout << #x " = " << (x) << endl
#define endl "\n"
using namespace std;
int main()
{
    string s;
    cin>>s;
   int  len=s.size();
    if(s[len-1]=='s')
        {s+='e';s+='s';}
    else
        s+='s';
    cout<<s<<endl;
}


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

int main(){
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;
    for(int i=0; i<N; i++)cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    for (int i=0; i<N; i++){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dt<dist)can = false;
        if(dist%2 != dt%2)can = false;
    }

    if(can)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
# https://atcoder.jp/contests/abc099/tasks/abc099_c
L = [59049,46656,7776,6561,1296,729,216,81,36,9,6]
maxi = 100000
N = int(input())
memo = [0,1,2,3,4,5] + [-1 for _ in range(maxi)]
def f(n):
    if memo[n]!=-1:
        return memo[n]
    res = N
    for l in L:
        if n>=l:
            res = min(res,f(n-l)+1)
    memo[n] = res
    return res
print(f(N))

Measured memory_bytes: 4632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;


int main(){
  int D,T,S;
  cin >> D >> T >> S;
  string A = "Yes";
  if(T*S<D){
    A = "No";
  }
  cout << A << endl;
}

Measured memory_bytes: 3644
N, M, X, Y = map(int,input().split())
x = sorted(list(map(int,input().split())))
y = sorted(list(map(int,input().split())))

for i in range(X+1, Y+1):
  if(x[-1] < i <= y[0]):
    print("No War")
    break
else:
  print("War")

Measured memory_bytes: 3060
import heapq

def prim():
    used = [1] * n
    used[0] = 0
    lis = []
    res = 0
    
    for a,b in edge[0]:
        heapq.heappush(lis,a*(10**6)+b)
        
    while lis:
        minedge = heapq.heappop(lis)
        
        if used[minedge%(10**6)] == 0:
            continue

        v = minedge%(10**6)
        used[v] = 0

        for q in edge[v]:
            if used[q[1]] == 1:
                heapq.heappush(lis , q[0]*(10**6) + q[1] )
        res += (minedge // (10**6))
    return res

n = int(input())
edge = [[] for _ in range(n)]
xsort = [[0]*2 for _ in range(n)]
ysort = [[0]*2 for _ in range(n)]

for i in range(n):
    x ,y = map(int,input().split())
    xsort[i][0] = x
    ysort[i][0] = y
    xsort[i][1] = i
    ysort[i][1] = i
xsort.sort()
ysort.sort()

for i in range(n-1):
    edge[xsort[i][1]].append([xsort[i+1][0] - xsort[i][0] , xsort[i+1][1]])
    edge[xsort[i+1][1]].append([xsort[i+1][0] - xsort[i][0] , xsort[i][1]])
    edge[ysort[i][1]].append([ysort[i+1][0] - ysort[i][0] , ysort[i+1][1]])
    edge[ysort[i+1][1]].append([ysort[i+1][0] - ysort[i][0] , ysort[i][1]])
    
print(prim())

Measured memory_bytes: 124212
#include <bits/stdc++.h>
using namespace std;
string s,t;
map<char,char>mcca,mccb;

int main(){
	//freopen("3_max3","r",stdin);
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(mcca.count(s[i])==0&&mccb.count(t[i])==0||mcca[s[i]]==t[i]){
			mcca[s[i]]=t[i];
			mccb[t[i]]=s[i];
		}
		else {
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <iomanip>
#include <functional>
#include <stack>
#include <numeric>
#define PI 3.1415926535
#define FOR(i,n) for (int i=0; i<(n) ;i++)
#define INF 114514810

using namespace std;

int n, t, sum;
vector<int> s;

int main(){
	while (cin >> n){
		if (n == 0) break;
		FOR(i, n) {
			cin >> t;
			s.push_back(t);
		}
			sort(s.begin(), s.end());
		sum = accumulate(s.begin() + 1, s.end() - 1, 0);
		cout << sum / (n - 2) << endl;
		s.clear();
	}
}

Measured memory_bytes: 1220
#include <cmath>
#include <cstdio>

using namespace std;

inline double sq(double x) {
  return x * x;
}

inline double det(double a, double b, double c, double d) {
  return a * d - b * c;
}

int main() {
  int N;
  scanf("%d", &N);
  for (int I = 0; I < N; I++) {
    double x[3], y[3];
    for (int i = 0; i < 3; i++)
      scanf("%lf%lf", x+i, y+i);
    double a = 2*(x[1]-x[0]),
           b = 2*(y[1]-y[0]),
           c = 2*(x[2]-x[0]),
           d = 2*(y[2]-y[0]),
           e = sq(x[1])-sq(x[0])+sq(y[1])-sq(y[0]),
           f = sq(x[2])-sq(x[0])+sq(y[2])-sq(y[0]),
           p = det(e, b, f, d) / det(a, b, c, d),
           q = det(a, e, c, f) / det(a, b, c, d),
           r = sqrt(sq(p-x[0])+sq(q-y[0]));
    p = round(p * 1000.0) / 1000.0;
    q = round(q * 1000.0) / 1000.0;
    r = round(r * 1000.0) / 1000.0;
    printf("%.3f %.3f %.3f\n", p, q, r);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int Count[4],X;
int Coin[]={50,100,500};
int solve(int idx,int rem)
{
    if(!rem)return 1;
    if(idx>=3||rem<0)return 0;
    int res=0;
    for(int i=0;i<=Count[idx];i++){
        res+=solve(idx+1,rem-i*Coin[idx]);
    }
    return res;
}
int main ()
{
    cin >> Count[2] >> Count[1] >> Count[0];
    cin >> X;
    cout<<solve(0,X)<<endl;
    return 0;
}
/*

*/

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;

class Main {
    public static void main(String args[])
    {
     String s,s11="",s2="";int a;
     Scanner sc=new Scanner(System.in);
     a=sc.nextInt();
     s=sc.next();
    String s1[]=s.split("");
    if(a%2==0)
    {
        for(int i=0;i<s1.length/2;i++)
        {
            s11=s11+s1[i];
        }
        for(int i=(s1.length)/2;i<s1.length;i++)
        {
            s2=s2+s1[i];
        }
        if(s11.equals(s2))
        {
            System.out.print("Yes");
        }
        else
        {
            System.out.print("No");
        }
    }
    else
    {
        System.out.print("No");
    }
    }
}



Measured memory_bytes: 21972
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll N, W;
ll w[110], v[110];
ll dp[110][50000];

int main(){
  cin >> N >> W;
  rep(i, N) cin >> w[i] >> v[i];
  vector<ll> xs;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= 3 * N; j++){
      xs.push_back(j + i * w[0]);
    }
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());

  for(int i = 1; i <= N; i++){
    for(int j = 0; j < xs.size(); j++){//重さ
      dp[i][j] = dp[i-1][j];
      if(xs[j] < w[i-1]) continue;
      ll s = lower_bound(xs.begin(), xs.end(), xs[j]-w[i-1]) - xs.begin();
      if(xs[s] != xs[j]-w[i-1]) continue;
      dp[i][j] = max(dp[i][j], dp[i-1][s] + v[i-1]);
    }
  }
  ll ans = 0;
  rep(i, xs.size()){
    if(xs[i] > W) continue;
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 40572
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

std::vector<pii> adj[16];

void solve(){
	int n; cin>>n;
	for(int i=1; i<=n; i++){
		int a; cin>>a;
		for(int j=0; j<a; j++){
			int x,y;
			cin>>x>>y;
			adj[i].pb({x,y});
		}
	}
	int t = INT_MIN;
	for(int bits=0; bits<(1<<n); bits++){
		int ans = 0;
		int flag = 1;
		for(int i=0; i<n; i++){
			if((bits & (1<<i))){
				//cout<<bits<<" "<<i<<"\n";
				ans++;
				for(auto pp: adj[i+1]){
					//cout<<pp.f<<" "<<pp.s<<"\n";
					if((bits & 1<<(pp.f-1))){
						if(!pp.s) flag = 0;
					}
					else{
						if(pp.s) flag = 0;
					}
				}
			}
		}
		if(flag) t = max(t,ans);
	}
	cout<<t;
}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
 
int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
 
	vector<int> Nums;
	int now = 1; //今見ている数
	int cnt = 0; //nowがいくつ並んでいるか
	for (int i = 0; i < N; i++)
	{
		if (S[i] == (char)('0' + now)) cnt++;
		else {
			Nums.push_back(cnt);
			now = 1 - now; //0と1を切り替える時の計算 now ^= 1;
			cnt = 1; //新しいのをカウントし始める
		}
	}
	if (cnt != 0) Nums.push_back(cnt);
 
	//1-0-1-0-1-0-1って感じの配列が欲しい
	//1-0-1-0みたいに0で終わってたら、適当に１つ足す
	if (Nums.size() % 2 == 0) Nums.push_back(0);
 
	int Add = 2 * K + 1;
 
	int ans = 0;
 
	int left = 0;  
	int right = 0; 
	int tmp = 0;// [left, right) のsum
 
	//1-0-1...の1から始めるので、偶数番目だけ見る
	for (int i = 0; i < Nums.size(); i += 2)
	{
		int Nextleft = i;
		int Nextright = min(i + Add, (int)Nums.size());
 
		//左端を移動する
		while (Nextleft > left) {
			tmp -= Nums[left];
			left++;
		}
		//右端を移動する
		while (Nextright > right) {
			tmp += Nums[right];
			right++;
		}
 
		ans = max(tmp, ans);
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 1020
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem1285 : Gray Area **/
int main()
{
	int N, W;
	while (cin>>N>>W, N) {
		vector<double> dat(N);
		vector<int> hist(100/W+1);
		int range=0;
		
		rep(i, N) {
			cin>>dat[i];
			hist[dat[i]/W]++;
			range = max(range, (int)(dat[i]/W));
		}
		
		int height = *max_element(hist.begin(), hist.end());
		double ans = 0.01;
				
		for (int i=0; i<=range; i++) {
			ans += (double)hist[i]/height*(range-i)/range;
		}
		
		cout << fixed << setprecision(8);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1292
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();
        int[] p = new int[n];

        for (int i = 0; i < n; i++)
        {
            p[i] = cin.nextInt();
        }

        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            if (p[i - 1] != i)
            {
                cnt++;
            }
        }

        if (cnt == 0 || cnt == 2) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

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

  long long ans = 0; 
  for (int i = 0; i < N - 1; i++) {
    if (A[i + 1] < A[i]) {
      ans += A[i] - A[i + 1];
      A[i + 1] = A[i];
    }
  }

  cout << ans << endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> C(H, vector<char>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> C.at(i).at(j);
        }
    }

    rep(i, 2 * H) {
        rep(j, W) {
            int index = (i + 2) / 2 - 1;
            cout << C.at(index).at(j);
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
A_1 = "" #Sの前につく文字
A_2 = "" #Sの後ろにつく文字
k = 1 #反転しているか否か
for q in range(Q):
  x_q = input()
  if x_q == "1":
    k *= -1
  else:
    [a,b,c] = x_q.rstrip().split(" ")
    if b == "1": #F_i = 1
      if k == 1:
        A_1 = c + A_1
      else:
        A_2 = A_2 + c
    else: #F_i = 2
      if k == 1:
        A_2 = A_2 + c
      else:
        A_1 = c + A_1
if k == 1:
  print(A_1 + S + A_2)
else:  
  print((A_1 + S + A_2)[::-1])

Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  	
  ll N,A,B;
  cin>>N>>A>>B;
  ll count=0;
  ll total=0;
  count+=(N/(A+B));
  N-=count*(A+B);
  total=count*A+min(A,N);
  cout<<total<<endl;
	return 0;
}

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

int main(){
  int N;
  ll A[100001],B[100001],C[100001];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  for (int i(0);i<N;i++) cin>>B[i];
  for (int i(0);i<N;i++) cin>>C[i];
  sort(A,A+N);
  sort(B,B+N);
  sort(C,C+N);
  ll cnt_b[100001];
  for (int i(0);i<N;i++){
    cnt_b[i] = (N - (upper_bound(C,C+N,B[i])-C));
  }
  ll sum_b[100001]={0};
  sum_b[N-1] = cnt_b[N-1];
  //for (int i(0);i<N;i++) cout << cnt_b[i] << " ";
  for (int i(N-2);i>=0;i--){
    sum_b[i] = sum_b[i+1]+cnt_b[i];
  }
  //for (int i(0);i<N;i++) cout << sum_b[i] << " ";
  ll sum(0);
  for (int i(0);i<N;i++){
    int tmp = upper_bound(B,B+N,A[i])-B;
    //cout << tmp << endl;
    sum+=sum_b[tmp];
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 4096
import sys
input = sys.stdin.readline


def bubble_sort(A):
    flag = 1  # non-sorted element exist on side
    counter = 0
    while flag:
        flag = 0
        for i in range(1, len(A))[::-1]:
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                flag = 1
                counter += 1
    print(" ".join([str(a) for a in A]))
    print(counter)


def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    bubble_sort(A)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5612
def main():
    n = int(input())
    p = list(map(int, input().split()))

    idx, t = 0, 0
    while idx < n:
        if p[idx] == idx + 1:
            cnt = 1
            idx += 1
            while idx < n and p[idx] == idx + 1:
                idx += 1
                cnt += 1
            t += (cnt+1) // 2
        else:
            idx += 1

    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        String s = in.next();
        if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)) {
            out.println("Yes");
        } else out.println("No");
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 21204
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> A >> B;
  ll min_ab = min(A, B);
  ll max_ab = max(A, B);
  if ((max_ab-min_ab)%2==0){
    max_ab-=min_ab;
    ans =min_ab+max_ab/2;
    cout << ans << endl;
  }
  else cout <<"IMPOSSIBLE" << endl; 
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int m,d,a,b;
  cin >>m >>d;
  int count = 0;

 for(int i =0; i <m;i++){
   for(int p =0; p <d; p++){
     a = (p+1)/10;
     b = (p+1)%10;
     if((a*b == i +1)&& (a >=2) &&(b >=2)){
       count++;
     }
   }
 }
  cout <<count <<endl;
}
       

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

using namespace std;

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

Node *root, *NIL;

Node * treeminimum(Node *x){
	while(x->left!=NIL) x=x->left;
	return x;
}

Node *find(Node *u, int k){
	while(u!=NIL&&k!=u->key){
		if(k<u->key) u=u->left;
		else u=u->right;
	}
	return u;
}

Node * treesuccessor(Node *x){
	/*if(x->right!=NIL)*/ return treeminimum(x->right);
	/*
	Node *y=x->parent;
	while(y!=NIL && x==y->right){
		x=y;
		y=y->parent;
	}
	return y;
	*/
}

void treedelete(Node *z){
	Node *y; //delete node
	Node *x; // child of y
	
	//determination of delete node
	if(z->left==NIL || z->right==NIL) y=z;
	else y=treesuccessor(z);
	
	//decide child x of y
	if(y->left!=NIL) x=y->left;
	else x=y->right;
	
	if(x!=NIL) x->parent = y->parent;
	
	if(y->parent==NIL) root=x;
	else{
		if(y==y->parent->left) y->parent->left = x;
		else y->parent->right = x;
	}
	
	if(y!=z) z->key = y->key;
	free(y);
}

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(){
	int n, k;
	string com;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>com;
		if(com[0]=='f'){//find
			scanf("%d",&k);
			Node *t = find(root,k);
			if(t!=NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(com[0]=='i'){//insert
			scanf("%d",&k);
			insert(k);
		}
		else if(com[0]=='p'){//print
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(com[0]=='d'){//delete
			scanf("%d",&k);
			treedelete(find(root,k));
		}
	}
}

Measured memory_bytes: 21912
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('/n');
  var cols = inputs[0].split(' ');
  var a = parseInt(cols[0], 10);
  var b = parseInt(cols[1], 10);

  function f(a, b) {
    return a === b ? 'a == b' : (a > b ? 'a > b' : 'a < b');
  }

  console.log(f(a, b));
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> c(h,vector<char>(w));
    vector<vector<char>> d(h,vector<char>(w));
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cin>>c[i][j];
            d[i][j]=c[i][j];
        }
    }
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cout<<c[i][j];
        }
        cout<<endl;
        for(int j=0; j<w; j++) {
            cout<<d[i][j];
        }
      	cout<<endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

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

	if(s == "AAA" || s == "BBB") cout << "No" << endl;
	else cout << "Yes" << endl;


	return 0;
}


Measured memory_bytes: 888
from math import gcd

def get_loop(a, m):
  count = 1
  acc = a
  while acc != 1:
    count += 1
    acc *= a
    acc %= m
  return count

def main():
  while True:
    a1, m1, a2, m2, a3, m3 = map(int, input().split())
    if not a1:
      break
    loop_a = get_loop(a1, m1)
    loop_b = get_loop(a2, m2)
    loop_c = get_loop(a3, m3)
    loop_ab = loop_a * loop_b // gcd(loop_a, loop_b)
    loop_abc = loop_ab * loop_c // gcd(loop_ab, loop_c)
    print(loop_abc)

main()


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    vector<set<char>> A(26), B(26);
    REP(i,0,SZ(S)) {
        A[S[i]-'a'].insert(T[i]);
        B[T[i]-'a'].insert(S[i]);
    }
    bool f = true;
    REP(i,0,26) {
        if(SZ(A[i]) > 1 || SZ(B[i]) > 1) f = false;
    }
    if(f) PR("Yes");
    else PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 3848
h,w = map(int,input().split())
lis = []
ans = []
nu = 0
nn = int(input())
li = list(map(int,input().split()))
for i in range(nn):
    for j in range(li[i]):
        if nu % 2 == 0:
            lis.append(str(i+1))
        else:
            lis.insert(0,str(i+1))
        if len(lis) == w:
            ans.append(str(" ".join(lis)))
            lis = []
            nu += 1
for i in range(h):print(ans[i])


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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x1, x2, x3, x4, x5 = input_to_int_map()

    for i, val in enumerate([x1, x2, x3, x4, x5]):
        if val == 0:
            return i + 1


if __name__ == "__main__":
    print(main())


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

int main(){
  int n;

  while(cin >> n, n){
    char t[128];
    fill(t, t + 128, -1);

    for(int i = 0; i < n; i++){
      char a, b;
      cin >> a >> b;
      t[a] = b;
    }

    int m;
    cin >> m;

    for(int i = 0; i < m; i++){
      char ch;
      cin >> ch;
      cout << (t[ch] != -1 ? t[ch] : ch);
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152