akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	std::string s = "", t = "abcdefghij";
	std::vector<std::string> ans;
	auto solve = [&](auto&& solve, int now, int ind) {
		if(ind == n) {
			ans.push_back(s);
			return;
		} else {
			for(int i = 0; i < now; i++) {
				s += t[i];
				solve(solve, now, ind + 1);			
				s.pop_back();
			}
			s += t[now];
			solve(solve, now + 1, ind + 1);
			solve(solve, now, ind + 1);
			s.pop_back();
		}
	};
	solve(solve, 0, 0);

	sort(begin(ans), end(ans));
	ans.erase(unique(begin(ans), end(ans)), end(ans));

	for(auto v: ans) printf("%s\n", v.c_str());
	return 0;
}


Measured memory_bytes: 42472
K, N = map(int, input().split())
A = list(map(int, input().split())) 

maxdis = 0
for i in range(len(A)-1):
  if maxdis < A[i+1] - A[i]:
    maxdis = A[i+1] - A[i]
if maxdis < (K - A[-1]) + A[0]:
  maxdis = (K - A[-1]) + A[0]
print(K-maxdis)


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

using namespace std;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a,b,c;
  cin >>  a >> b >> c;
  swap(a,b);
  swap(a,c);
  cout << a << " " << b  << " " << c;

  return 0;
}

Measured memory_bytes: 256
INF = 1000000
NMAX=40
ABMAX=10
n,ma,mb = map(int,input().split())
a=[]
b=[]
c=[]
for i in range(n):
    ai,bi,ci=map(int,input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)

dp = [[[INF]*(NMAX*ABMAX+1) for i in range(NMAX*ABMAX+1)] for i in range(n+1)]
dp[0][0][0]=0
for i in range(n):
    for j in range(NMAX*ABMAX+1):
        for k in range(NMAX*ABMAX+1):
            if j+a[i]>NMAX+ABMAX or k+b[i]>NMAX+ABMAX:
                continue
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i])

ans = INF
for j in range(1,NMAX*ABMAX+1):
    for k in range(1,NMAX*ABMAX+1):
        if (j*mb==k*ma):
            ans = min(ans,dp[n][j][k])

if ans == INF:
    ans = -1

print(ans)


Measured memory_bytes: 56036
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}

int main(){
    string a, b;
    cin >> a >> b;
    if (a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#ifdef DEBUG_BUILD
#define DBG(expr) cout << #expr << " = " << expr << endl;
#endif
#define ECHO(expr) cout << expr << endl;
#define REP(var, num) for(ll var = 0; var < num; var++)
#define REP_FROM(var, from, num) for(ll var = from; var < num; var++)
#define MAX_OF(type) numeric_limits<type>::max()
#define MIN_OF(type) numeric_limits<type>::min()
#define SORT(vec) sort(vec.begin(), vec.end())
#define REVERSE(vec) reverse(vec.begin(), vec.end())
#define ALL(vec) vec.begin(), vec.end()
typedef signed long long ll;
typedef unsigned long long ull;

void solve() {
    ll n;
    cin >> n;
    int years[] = {
        111,222,333,444,555,666,777,888,999
    };

    int next = lower_bound(begin(years), end(years), n)[0];
    ECHO(next)
}

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

#ifdef INPUT_FILE
    if (!freopen(INPUT_FILE, "r", stdin)) {
        perror("freopen");
        exit(1);
    }
#endif

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 2e5 + 5;
int n, a, b, c;

int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> n >> a >> b >> c;
	vector <string> s(n + 1);
	for(int i = 0; i < n; i++)	cin >> s[i];
	s[n] = "";
	int ok = 1;
	vector <char> ans(n);
	for(int i = 0; i < n; i++)
	{
		if(s[i] == "AB")
		{
			if(!a && !b)	ok = 0;
			else if(a == 1 && b == 1)
			{
				if(s[i + 1] == "AC")	a++, b--, ans[i] = 'A';
				else			a--, b++, ans[i] = 'B';
			}
			else
			{
				if(a < b)	a++, b--, ans[i] = 'A';
				else		a--, b++, ans[i] = 'B';
			}
		}
		else if(s[i] == "BC")
		{
			if(!b && !c)	ok = 0;
			else if(b == 1 && c == 1)
			{
				if(s[i + 1] == "AB")	b++, c--, ans[i] = 'B';
				else			b--, c++, ans[i] = 'C';
			}
			else
			{
				if(b < c)	b++, c--, ans[i] = 'B';
				else		b--, c++, ans[i] = 'C';
			}
		}
		else
		{
			if(!a && !c)	ok = 0;
			else if(a == 1 && c == 1)
			{
				if(s[i + 1] == "AB")	a++, c--, ans[i] = 'A';
				else			a--, c++, ans[i] = 'C';
			}
			else
			{
				if(a < c)	a++, c--, ans[i] = 'A';
				else		a--, c++, ans[i] = 'C';
			}	
		}
	}
	if(!ok)		cout << "No";
	else
	{
		cout << "Yes\n";
		for(auto &c : ans)
			cout << c << "\n";
	}
    	return 0;
}

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

int main(){
    ll x;
    cin >> x;
    ll ans = (x/11) * 2;
    if(x%11 > 6) ans += 2;
    else if(x%11 > 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int k ,a,b;
	cin >> k >> a >> b;
	for (int i =a; i <=b ; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;

}


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

int main(){
  int S;
  cin>>S;
  int x1,x2,x3,x4;
  x1=S/1000;
  x2=(S-x1*1000)/100;
  x3=(S-x1*1000-x2*100)/10;
  x4=S-x1*1000-x2*100-x3*10;
  if ((10*x1+x2)==0 or (10*x1+x2)>=13){
    if ((10*x3+x4)==0 or (10*x3+x4)>=13){
      cout<<"NA"<<endl;
    } else {
      cout<<"YYMM"<<endl;
    }
  } else {
    if ((10*x3+x4)==0 or (10*x3+x4)>=13){
      cout<<"MMYY"<<endl;
    } else {
      cout<<"AMBIGUOUS"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N, ans;

int nim(int a, int b) {
    if (a % b == 0) return a/b;
    while (1) {
        int k = ceil((double)a/b);
        // a - k*? <= (k-1)*b
        // a-(k-1)*b <= k*? 
        int x = ceil(double(a-(k-1)*b)/k);
        a -= x*k;
        // cout << a << " " << b << "\n";
        if (a % b == 0) return a/b;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N) {
        int a,b; cin >> a >> b;
        ans ^= nim(a,b);
    }
    if (ans) cout << "Takahashi";
    else cout << "Aoki";
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 384
M=10**9+7
n=input()
d=int(input())
dp=[[[0,0] for j in range(d)] for i in range(len(n)+1)]
dp[0][0][0]=1
for i,x in enumerate(map(int,n),1):
  for j in range(10):
    for k in range(d):
      dp[i][(j+k)%d][1]+=dp[i-1][k][1]
      dp[i][(j+k)%d][1]%=M
      if j<x:
        dp[i][(j+k)%d][1]+=dp[i-1][k][0]
        dp[i][(j+k)%d][1]%=M
      if j==x:
        dp[i][(j+k)%d][0]+=dp[i-1][k][0]
        dp[i][(j+k)%d][0]%=M
print((sum(dp[-1][0])-1)%M)


Measured memory_bytes: 129372
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n], b[n];
    int c[n];
    long long allb = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        c[i] = a[i] + b[i];
        allb += -b[i];
    }
    sort(c, c + n);
    for (int i = 0; i < n; i += 2) {
        allb += c[n - 1 - i];
    }
    cout << allb << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
using ll = long long;

int main (){
    int A,ans = 0;
    for (int i = 0; i < 3; i++){
        cin >> A;
        ans += A;
    }
    if (ans >= 22){cout << "bust" << endl; 
    }else cout << "win" << endl;
    return 0;
}
    

    


Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
#define INF 1e9
typedef pair<int,int> P;

int H,W,N;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
vector<vector<int> > maze;
vector<vector<int> > d;

bool mobility(int i, int j){
  return i>=0 && i<W && j >= 0 && j<H && maze[i][j]!=INF && d[i][j] == INF;
}

int bfs(int sx, int sy, int cur){
  int x,y,i;
  queue<P> que;
  que.push(P(sx,sy));
  REP(y,H)REP(x,W){
    if(x!=sx || y!=sy) d[x][y] = INF;
  }
  while(!que.empty()){
    P p = que.front();que.pop();
    x = p.first;y = p.second;
    if(maze[x][y] == cur) break;
    REP(i,4){
      int nx = x + dx[i], ny = y + dy[i];
      if(mobility(nx,ny)){
        que.push(P(nx,ny));
        d[nx][ny] = d[x][y] + 1;
      }
    }
  }
  if(cur == N) return d[x][y];
  return bfs(x,y,cur+1);
}

int main(void){
  int x,y,sx,sy;
  cin >> H >> W >> N;
  maze.resize(W,vector<int> (H));
  d.resize(W,vector<int> (H,INF));
  REP(y,H)REP(x,W){
    char c;
    cin >> c;
    if(isdigit(c)) maze[x][y] =  c - '0';
    else if(c == 'X') maze[x][y] = INF;
    else if(c == '.') maze[x][y] = 0;
    else{
      maze[x][y] = 0;
      sx = x;
      sy = y;
    }
  }
  d[sx][sy] = 0;
  cout << bfs(sx,sy,1) << endl;
  return 0;
}



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

int idx=0;
long N;
vector<long> a(30000);

void dfs(long n){
  if(n<=N){
    a[idx]=n;
    idx++;
    dfs(n*10+3);
    dfs(n*10+5);
    dfs(n*10+7);
  }
}

bool is753(int n){
  bool in7=false;
  bool in5=false;
  bool in3=false;
  int t=n;
  while(t>0){
    int res=t%10;
    if(res==3) in3=true;
    if(res==5) in5=true;
    if(res==7) in7=true;
    t/=10;
  }
  if(in7&&in5&&in3) return true;
  else return false;
}

int main() {

  cin>>N;

  dfs(0);

  sort(a.begin(),a.end());
  int ans=0;

  for(int i=0;i<30000;i++){
    if(a[i]>N) break;
    if(is753(a[i])) ans++;
  }

  cout<<ans<<endl;

  }


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

#define MAXN 2001
int n, a[3*MAXN], mxk[MAXN], mx, tri;

vector<tuple<int,int,int>> ops;
void maxi(int i, int j, int v) {
    ops.emplace_back(i,j,v);
}

void maxip(int i, int j, int v) {
    if (~v) {
        ops.emplace_back(i,j,v+1);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    vector<vector<int>> dp(n+1, vector<int>(n+1, -1)); 
    fill(mxk, mxk+n+1, -1);
    for (int i = 0; i < 3*n; ++i)cin>>a[i];
    dp[a[0]][a[1]] = mxk[a[0]] = mxk[a[1]] = 0;
    for (int i = 0; i < n-1; ++i) {
        int p=a[i*3+2],q=a[i*3+3],r=a[i*3+4];
        if (p==q && q==r) {
            tri++;
        } else {
            if(p == q || q == r || p == r){
                int d, u;
                if(p == q)d = p, u = r;
                if(q == r)d = q, u = p;
                if(p == r)d = p, u = q;
                for (int k = 1; k <= n; ++k) {
                    maxip(k, u, dp[k][d]);
                    maxip(k, u, dp[d][k]);
                }
            }
            maxip(q, r, dp[p][p]);
            maxip(p, r, dp[q][q]);
            maxip(p, q, dp[r][r]);
            maxi(q, r, mx);
            maxi(p, r, mx);
            maxi(p, q, mx);
            for (int k = 1; k <= n; ++k) {
                maxi(k, p, mxk[k]);
                maxi(k, q, mxk[k]);
                maxi(k, r, mxk[k]);
            }
            for (auto &o: ops) {
                int i=get<0>(o), j=get<1>(o), v=get<2>(o);
                dp[i][j] = max(dp[i][j], v);
                mxk[i] = max(mxk[i], v);
                mxk[j] = max(mxk[j], v);
                mx = max(mx, v);
            }   
            ops.clear();
        }
    }
    cout<<max(mx, dp[a[n*3-1]][a[n*3-1]] + 1) + tri;
}

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

using namespace std;
using ll = long long int;

int main()
{
    int n, m;
    cin >> n >> m;

    priority_queue<ll> q;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        q.push(a);
    }

    while (m > 0)
    {
        ll top = q.top();
        q.pop();
        q.push(top >> 1);
        m--;
    }

    ll ans = 0;
    while (!q.empty())
    {
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
#define MAXN 400000
#define LL long long
int n,k,ans,res,tmp;
int p[MAXN+5],flag[MAXN+5],sum[MAXN+5];
inline LL read(){
   	LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
   	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
priority_queue<int> Q1,Q2;
int main()
{
	n=read(),k=read();
	for(int i=1;i<=n;i++)
	p[i]=read();
	p[0]=n;
	for(int i=1;i<=k;i++)
	{tmp+=p[i-1]<p[i];Q1.push(p[i]),Q2.push(-p[i]);flag[p[i]]=1;}
	for(int i=k;i<=n;i++){
		while(!flag[Q1.top()])Q1.pop();
		while(!flag[-Q2.top()])Q2.pop();
		int mx=Q1.top(),mn=-Q2.top();
		if(!(p[i+1]>mx&&mn==p[i-k+1])){
			if(tmp==k-1)ans+=(!res),res++;
			else ans++;
		}
		tmp-=p[i-k+1]<p[i-k+2],tmp+=p[i]<p[i+1];
		flag[p[i-k+1]]=0;flag[p[i+1]]=1;
		Q1.push(p[i+1]),Q2.push(-p[i+1]);
	}
	printf("%d",ans);
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
ll MOD=1000*1000*1000+7, n, m;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n, mini=INT_MAX, ans=0;
	cin>>n;
	vector<int>A(n);
	rep(i,0,n){
		cin>>A[i];
		mini=min(mini, A[i]);
		if(A[i]<=mini)ans++;
	}
	cout<<ans<<"\n";
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a + b == 15) cout << "+" << endl;
    else if(a * b == 15) cout << "*" << endl;
    else cout << "x" << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()

    dfs(n, LinkedList<Int>(), 0)

}

fun dfs(n: Int, res: LinkedList<Int>, max:Int) {
    if (res.size == n) {
        println(res.joinToString("") { ('a' + it).toString() })
        return
    }
    for (c in 0..max) {
        res.add(c)
        dfs(n, res, if (c == max) max + 1 else max)
        res.pollLast()
    }
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 40820
import collections
N =int(input())
As = [int(item) for item in input().split()]

cnt = 0
Bs = collections.deque()
min1 = 1000000000000

for i in As:
	if i < 0:
		cnt +=1
	Bs.append(abs(i))
	min1=min(min1, abs(i))
	
if cnt % 2 ==0:
	print(sum(list(Bs)))
else:
	print(sum(list(Bs))-min1*2)
	

Measured memory_bytes: 20600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        b[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i];
        c[i];
    }
    int mae = -100;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += b[a[i]] + (a[i] == mae + 1 ? c[mae] : 0);
        mae = a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;


int main(int argc, char *args[]) {
	int N, X;
	int g[110];
	
	cin >> N >> X;
	int number = N;
	for (int i = 0; i < N; i++)cin >> g[i];
	int min_g = 2000;
	for (int i = 0; i < N; i++) {
		if (min_g > g[i])min_g = g[i];
	}
	for (int i = 0; i < N; i++) {
		X = X - g[i];
	}
	X = X / min_g;
	number = number + X;
	cout << number << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    int A, B;
    int cnt[5];
    REP(i, 5)cnt[i] = 0;
    REP(i, 3){
        cin >> A >> B;
        cnt[A]++;
        cnt[B]++;
    }
    int cnt1 = 0, cnt2 = 0;
    REP(i, 5){
        if(cnt[i] == 1){cnt1++;}
        else if(cnt[i] == 2){cnt2++;}
    }
    if(cnt1 == 2 && cnt2 == 2){print("YES");}
    else{print("NO");}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int h, n;
  cin >> h >> n;

  bool t[4][10005] = {};

  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    t[x][y] = true;
  }
  int ans = 0;
  rep(i, 0, h - 1) {
    if(!t[0][i] && !t[1][i] && !t[0][i + 1] && !t[1][i + 1]) {
      ans++, t[1][i] = true, t[0][i + 1] = true, t[1][i + 1] = true;
    }
    if(!t[2][i] && !t[3][i] && !t[2][i + 1] && !t[3][i + 1]) {
      ans++, t[2][i] = true, t[2][i + 1] = true, t[3][i + 1] = true;
    }
    if(!t[1][i] && !t[2][i] && !t[1][i + 1] && !t[2][i + 1]) {
      int k = 0;
      while(!t[0][i + 1 + k] && !t[1][i + 1 + k] && !t[2][i + 1 + k] && !t[3][i + 1 + k] && i + 1 + k < h) k++;
      if(k < 2 || k % 2) {
        ans++, t[1][i + 1] = true, t[2][i + 1] = true;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3224
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in [0]*N]
cd = [list(map(int,input().split())) for _ in [0]*M]
for a,b in ab:
    i = -1
    m = 10**9
    for j,tmp in enumerate(cd,1):
        c,d = tmp
        l = abs(a-c)+abs(b-d)
        if l < m:
            m = l
            i = j
    print(i)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
using namespace std;
int div(int n)
{
	int sum=0;
	while(n%2==0){
		sum++;
		n/=2;
	}
	return sum;
}
int main()
{
	int n,max,i,mnum,temp;
	while(cin>>n)
	{
		max=0;mnum=1;
		for(i=1;i<=n;i++){
			if((temp=div(i))>max){max=temp;mnum=i;}
		}
		printf("%d\n",mnum);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<vector<char>> maze(h, vector<char>(w));
    rep(y,h) {
        string s;
        cin >> s;
        rep(x,w) maze[y][x] = s[x];
    }
    vector<int> dx = {0,0,1,-1};
    vector<int> dy = {1,-1,0,0};
    int max_step = 0;
    rep(sx, w) rep(sy, h){
        if(maze[sy][sx] == '#') continue;
        int INF = INT32_MAX;
        queue<pair<int,int>> que;    
        vector<vector<int>> dist(h,vector<int>(w,INF));
        dist[sy][sx] = 0;
        que.push(make_pair(sx,sy));
        while(que.size() != 0) {
            int x = que.front().first;
            int y = que.front().second;
            que.pop();
            rep(i,4) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
                if(maze[ny][nx] == '#') continue;
                if(dist[ny][nx] != INF) continue;
                dist[ny][nx] = dist[y][x]+1;
                chmax(max_step, dist[ny][nx]);
                que.push(make_pair(nx,ny));
            }
        }
    }
    cout << max_step << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

int dep[100010];
int par[100010][19];
vector<int> g[100010];
void dfs(int v,int u,int d){
  dep[v]=d;
  for(int i=0; i<g[v].size(); i++){
    int w=g[v][i];if(w==u) continue;
    par[w][0]=v;dfs(w,v,d+1);
  }
}
int lca(int a,int b){
  if(dep[a]<dep[b]) swap(a,b);
  for(int i=0; i<19; i++){
    if((dep[a]-dep[b])&(1<<i)) a=par[a][i];
  }
  if(a==b) return a;
  for(int i=18;i>=0;i--){
    if(par[a][i]!=par[b][i]) a=par[a][i],b=par[b][i];
  }
  return par[a][0];
}
int n;
void init() {
  memset(par,0,sizeof(par));
  dfs(0,-1,0);
  for(int i=0; i<18; i++)for(int j=0; j<n; j++) par[j][i+1]=par[par[j][i]][i];
}

vector<ll> v[111111];
int c[111111];
vector<P> ans;
void bfs(int x) {
  /*
  rep(i,v[x].size()) {
    int y=v[x][i];
    if(y==p) continue;
    c[x]++;
    if(ss.count(P(y,x))||ss.count(P(x,y))) continue;
    ss.in(P(x,y));
    dfs(y,x);
  }
  */
  queue<int> que;
  que.push(x);
  int u[111111],uu[111111];
  mem(uu);
  u[x]=1;
  while(!que.empty()) {
    x=que.front();que.pop();
    uu[x]=1;
    rep(i,v[x].size()) {
      int y=v[x][i];
      if(!uu[y]) {
        c[x]++;
        ans.pb(P(x,y));
      }
      if(u[y]) continue;
      u[y]=1;
      g[x].pb(y);
      que.push(y);
    }
  }
}


ll d[111111];
set<P> s;

ll dfs(int x) {
  rep(i,g[x].size()) {
    ll y=g[x][i];
    ll z=dfs(y);
    if(z) s.in(P(x,y));
    d[x]^=z;
  }
  return d[x];
}

void Main() {
  ll m;
  cin >> n >> m;
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  bfs(0);
  init();
  vector<int> a;
  rep(i,n) {
    if(c[i]%2) a.pb(i);
  }
  if(a.size()%2) {
    pr(-1);
    return;
  }
  for(int i=0; i<a.size(); i+=2) {
    d[a[i]]++;
    d[a[i+1]]++;
  }
  dfs(0);
  rep(i,ans.size()) {
    if(s.count(ans[i])) swap(ans[i].F,ans[i].S);
    pr(ans[i].F+1,ans[i].S+1);
  }
}

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


Measured memory_bytes: 30576
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

string S;
char in[101010];
bool flg[101010];


int main() {
	cin >> S;

	flg[0] = true;
	FOR(i, 1, S.size() + 1) {
		if (i >= 5 && S.substr(i - 5, 5) == "dream"&&flg[i - 5])flg[i] = true;
		if (i >= 7 && S.substr(i - 7, 7) == "dreamer"&&flg[i - 7])flg[i] = true;
		if (i >= 5 && S.substr(i - 5, 5) == "erase"&&flg[i - 5])flg[i] = true;
		if (i >= 6 && S.substr(i - 6, 6) == "eraser"&&flg[i - 6])flg[i] = true;
	}
	puts(flg[S.size()] ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <string>
#define ll long long 
#define rep(i, s, n) for(int i = s; i < n; i++)
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> s_count(26, 0);
    vector<int> t_count(26, 0);
    rep(i, 0, s.size()) {
        s_count[s[i]-'a']++;
        t_count[t[i]-'a']++;
    }
    sort(s_count.begin(), s_count.end());
    sort(t_count.begin(), t_count.end());
    rep(i, 0, s_count.size()) {
        if(s_count[i] == t_count[i]) {

        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

$output = []

def main
    n = gets().to_i
    return false if n==0

    a_cards = []
    b_cards = []
    n.times do |i|
        str = gets().split(/\s+/)
        a_cards << str[0].to_i
        b_cards << str[1].to_i
    end

    # ゲーム
    a_score = 0
    b_score = 0
    n.times do |i|
        if a_cards[i] > b_cards[i] # aの勝ち
            a_score += (a_cards[i] + b_cards[i])
        elsif a_cards[i] == b_cards[i] # 引き分け
            a_score += a_cards[i]
            b_score += b_cards[i]
        else # bの勝ち
            b_score += (a_cards[i] + b_cards[i])
        end
    end

    $output << "#{a_score} #{b_score}"
    return true
end

while(main)
end

$output.each do |str|
    puts str
end

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

using namespace std;
const int N = 2e5+10;
typedef long long LL;
LL a[N], sum[N];
LL b[N], c[N], d[N];
vector<LL>v;
LL lowbit(LL k)
{
    return k&-k;
}

void add(LL x)
{
    while(x<N)
    {
        c[x]+=1;
        x+=lowbit(x);
    }
    return ;
}

LL ss(LL x)
{
    LL ans=0;
    while(x>0)
    {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}

int main()
{
    int n;
    LL k;
    scanf("%d %lld", &n, &k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld", &a[i]);
        a[i]-=k;
        sum[i]=sum[i-1]+a[i];
    }
    v.clear();
    for(int i=0;i<=n;i++)
    {
        v.push_back(sum[i]);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());

    for(int i=0;i<=n;i++)
    {
        b[i]=(lower_bound(v.begin(),v.end(),sum[i])-v.begin())+1;
    }
    LL ans=0;

    for(int i=0;i<=n;i++)
    {
        ans+=ss(b[i]);
        add(b[i]);
    }

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






Measured memory_bytes: 8176
n = int(input())
lst1 = [int(input()) for i in range(n)]
lst1.sort()
p = sum(lst1)

if p%10 != 0:
    print(p)
else:
    for i in lst1:
        if i %10 != 0:
            print(p-i)
            exit()

    print(0)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int v, e;
  cin >> v >> e;

  using Graph = vector<vector<int>>;

  Graph G(v);
  vector<int> d(v);

  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    d[b]++;
  }
  vector<int> ans;

  queue<int> que;
  for (int i = 0; i < v; i++) {
    if (d[i] == 0) {
      que.push(i);
    }
  }

  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (int i = 0; i < G[v].size(); i++) {
      int u = G[v][i];
      d[u]--;
      if (d[u] == 0) que.push(u);
    }
    ans.push_back(v);
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    if(n / 10 == 9 || n % 10 == 9)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys,fractions
input = sys.stdin.readline

A,B,C,D = map(int,input().split())


lcm =  (C*D)//fractions.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))

Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))

print(int((B-A+1)-(End-Start)))


Measured memory_bytes: 5088
import java.util.Scanner;

public class Main {

    private static boolean calc7(int a, int b, int c, int d, String op1, String op2, String op3) {
        int e = 0;
        e = op1.equals("+") ? (a+b) : (a-b);
        e = op2.equals("+") ? (e+c) : (e-c);
        e = op3.equals("+") ? (e+d) : (e-d);

        if (e == 7) {
            System.out.println(a+op1+b+op2+c+op3+d+"=7");
            System.exit(0);
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] sn = sc.next().split("");
        int a = Integer.parseInt(sn[0]);
        int b = Integer.parseInt(sn[1]);
        int c = Integer.parseInt(sn[2]);
        int d = Integer.parseInt(sn[3]);

        calc7(a, b, c, d, "+", "+", "+");
        calc7(a, b, c, d, "+", "+", "-");
        calc7(a, b, c, d, "+", "-", "+");
        calc7(a, b, c, d, "+", "-", "-");
        calc7(a, b, c, d, "-", "+", "+");
        calc7(a, b, c, d, "-", "+", "-");
        calc7(a, b, c, d, "-", "-", "+");
        calc7(a, b, c, d, "-", "-", "-");
    }

}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <utility>

#define INF 1e9+7

using namespace std;
using llng = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

int N, M, Q;
vvi V, EW, EH;

int vec_sum(int x1, int y1, int x2, int y2) {
    return V[x2][y2] + V[x1-1][y1-1] - V[x2][y1-1] - V[x1-1][y2];
}

int edge_sum(int x1, int y1, int x2, int y2) {
    return (EW[x2][y2] + EW[x1-1][y1] - EW[x2][y1] - EW[x1-1][y2])
            + (EH[x2][y2] + EH[x1][y1-1] - EH[x2][y1-1] - EH[x1][y2]);
}

int main() {
    cin >> N >> M >> Q;
    V = vvi(N+1, vi(M+1, 0));
    EW = vvi(N+1, vi(M+1, 0));
    EH = vvi(N+1, vi(M+1, 0));
    for (int i=1; i<=N; i++) {
        for (int j=1; j<=M; j++) {
            char c; cin >> c;
            V[i][j] = c - '0';
            if (V[i][j]*V[i][j-1] == 1) EW[i][j] = 1;
            if (V[i][j]*V[i-1][j] == 1) EH[i][j] = 1;
        }
    }
    for (int i=1; i<=N; i++) {
        for (int j=1; j<=M; j++) {
            V[i][j] += V[i-1][j] + V[i][j-1] - V[i-1][j-1];
            EW[i][j] += EW[i-1][j] + EW[i][j-1] - EW[i-1][j-1];
            EH[i][j] += EH[i-1][j] + EH[i][j-1] - EH[i-1][j-1];
        }
    }

    for (int q=0; q<Q; q++) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        cout << vec_sum(x1, y1, x2, y2) - edge_sum(x1, y1, x2, y2) << endl;
    }

    return 0;
}

Measured memory_bytes: 48896
#include <stdio.h>
int main(void)
{
    int x,i,j;
    scanf("%d",&x);
    for(i=1;i<10;i++){
        for(j=1;j<10;j++){
            if(x==i*j){
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

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

        long n = sc.nextInt();
        long m = sc.nextInt();
        long n2 = sc.nextInt();
        long m2 = sc.nextInt();
        long t = sc.nextInt();

        if (Math.abs(n - n2) <= (m - m2) * t) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

        sc.close();
    }

}

Measured memory_bytes: 35812
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	string s;	cin>>s;
	if(s[0]=='S'){
		if(s[1]=='A'){
			cout<<"1";
		} else{
			cout<<"7";
		}
	} else if(s[0]=='M'){
		cout<<"6";
	} else if(s[0]=='T'){
		if(s[1]=='U'){
			cout<<"5";
		} else{
			cout<<"3";
		}
	} else if(s[0]=='W'){
		cout<<"4";
	} else if(s[0]=='F'){
		cout<<"2";
	}
}
void q2(){
	int n; cin>>n;
	if(n&1){
		cout<<"No\n";
		return ;
	}
	n/=2;
	string s;
	cin>>s;
	int fg=1;
	for(int i=0;i<n;++i)
	if(s[i]!=s[i+n])
	fg=0;
	fg==1 ? cout<<"Yes\n" : cout<<"No\n";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q1();
	return 0;
}
	


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define clr(x,v) memset(x,v,sizeof(x))
using namespace std;
const int N=1024,V=8192,inf=0x3f3f3f3f;

int gti(void)
{
    char c=getchar();
    int ret=0,st=1;
    for (;!isdigit(c);c=getchar()) if (c=='-') st=-1;
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
    return ret*st;
}

int val[N];
struct edge{edge *nxt;int to;}pool[N],*pt[N],*p;
void add(int a,int b)
{
    *(++p)=(edge){pt[a],b},pt[a]=p;
}

int f[N][2][V];
void upd(int &a,int v)
{
    a=min(a,v);
}
bool dfs(int v)
{
    static int g[V];
    clr(f[v],0);
    for (edge *i=pt[v];i;i=i->nxt)
    {
        if (!dfs(i->to)) return false;
        clr(g,0x3f);
        for (int j=0;j<=val[v];j++)
        {
            if (j+val[i->to]<=val[v])
                upd(g[j+val[i->to]],f[v][0][j]+f[i->to][0][val[i->to]]);
            if (j+f[i->to][1][val[i->to]]<=val[v])
                upd(g[j+f[i->to][1][val[i->to]]],f[v][0][j]+val[i->to]);
        }
        copy(g,g+val[v]+1,f[v][0]);
        clr(g,0x3f);
        for (int j=0;j<=val[v];j++)
        {
            if (j+val[i->to]<=val[v])
                upd(g[j+val[i->to]],f[v][1][j]+f[i->to][1][val[i->to]]);
            if (j+f[i->to][0][val[i->to]]<=val[v])
                upd(g[j+f[i->to][0][val[i->to]]],f[v][1][j]+val[i->to]);
        }
        copy(g,g+val[v]+1,f[v][1]);
    }
    for (int i=0;i<=val[v];i++)
    {
        upd(f[v][0][val[v]],f[v][0][i]);
        upd(f[v][1][val[v]],f[v][1][i]);
    }
    return f[v][0][val[v]]<inf||f[v][1][val[v]]<inf;
}

int main(void)
{
#ifdef debug
    freopen("a.in","r",stdin);
#endif
    for (int T=1;T>=1;T--)
    {
        int n=gti();
        clr(pt,0),p=pool;
        for (int i=2;i<=n;i++)
            add(gti(),i);
        for (int i=1;i<=n;i++)
            val[i]=gti();
        if (dfs(1)) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 65664
n = int(input())
mod = 10**9+7
def pow(x, n):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res *= x
        x *= x
        n >>= 1
    return res
print((pow(10, n)%mod -2*pow(9, n)%mod + pow(8, n)%mod)%mod)

Measured memory_bytes: 11464
//kruskal tree
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;cin>>n,n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z>>r,v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<0)x=0;
			a[m]=i,b[m]=j,node[m].first=x,node[m].second=m;m++;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		cout<<fixed<<setprecision(3)<<x<<endl;
	}
}

Measured memory_bytes: 1508
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;



int main(){
    string s;
    ll ans,num;
    cin>>s;

    ans=0;
//    cout<<s[0]-'0'<<endl;
    for(ll p=0;p<(1<<(s.length()-1));p++){
        num=s[0]-'0';
        for(ll i=0;i<s.length()-1;i++){
            if(p&(1<<i)){
                ans+=num;
                num=0;
            }
            num=num*10+(s[i+1]-'0');
        }
        ans+=num;
    }

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


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

int N,A[4010],B[4010] = {0},W[4010] = {0};
int dp[2010][2010] = {{0}},Bcost[2010][4010] = {{0}},Wcost[2010][4010] = {{0}};
//dp[i][j]:黒をi個，白をj個並べたときの最適値,Bcost[i][j]:位置jまでに黒の番号iより大きいのボールがいくつあるか
char C[4010];

int main(){
	cin >> N;
	for(int i=1;i<=2*N;i++){
		cin >> C[i] >> A[i];
		if(C[i]=='B') B[A[i]] = i;
		else W[A[i]] = i;
	}
	for(int i=0;i<=N+1;i++){
		for(int j=0;j<=2*N;j++){
			Bcost[i][j+1] = Bcost[i][j] + (C[j]=='B'&&A[j]>i);
			Wcost[i][j+1] = Wcost[i][j] + (C[j]=='W'&&A[j]>i);
		}
	}
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			dp[i][j] = 1e9;
		}
	}
	dp[0][0] = 0;
/*	for(int i=0;i<=N;i++){
		for(int j=1;j<=2*N;j++){
			cout << Bcost[i][j] << (j!=2*N? " ":"\n");
		}
	}
	cout << endl;
	for(int i=0;i<=N;i++){
		for(int j=1;j<=2*N;j++){
			cout << Wcost[i][j] << (j!=2*N? " ":"\n");
		}
	}
	for(int i=1;i<=2*N+1;i++){
		for(int b=0;b<=i+1;b++){
			int w = i-b;
			if(b>N || w>N) continue;
*/	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
		if(i>=1) dp[i][j] = min(dp[i-1][j]+Bcost[i][B[i]+1]+Wcost[j][B[i]+1],dp[i][j]);
			if(j>=1) dp[i][j] = min(dp[i][j-1]+Wcost[j][W[j]+1]+Bcost[i][W[j]+1],dp[i][j]);
//			if(b>=1) dp[b][w] = min(dp[b-1][w]+Bcost[b][B[b]+1]+Wcost[w][B[b]+1],dp[b][w]);
	//		if(w>=1) dp[b][w] = min(dp[b][w-1]+Wcost[w][W[w]+1]+Bcost[b][W[w]+1],dp[b][w]);
		}
	}
/*	cout << endl;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			cout << dp[i][j] << (j!=N? " ":"\n");
		}
	}
*/	cout << dp[N][N] << endl;
}

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

N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(1,N):
    if A[i] - A[i-1] != 0:
        B.append(A[i] - A[i-1])
cnt = 0
for i in range(1,len(B)):
    if i >1:
        if B[i-1]*B[i-2] < 0 :
            continue
    if B[i]*B[i-1]<0:
        cnt += 1
        B[i]=0
        
print(cnt+1)

Measured memory_bytes: 20252
/*
            ██        ██              ██        ██████
                    ██████                    ██    ██
        ████████    ██████    ████████      ████████
    ████        ██████████████        ████
  ██        ██████    ██    ██████        ██
██████████  ██████        ████████  ██████████
    ████████    ██████  ██████    ████████
        ████  ██    ██  ██    ██  ████
          ██  ██  ████  ████  ██  ██        ████████
          ██  ██    ██████    ██  ██          ██    ██
        ██      ██████  ██████      ██          ██████
  ██    ██          ██████          ██
        ██      ████████████████    ██
        ██    ██              ██      ██
          ██  ██    ██████    ██      ██      ████
      ██  ██  ██████      ██████        ██    ██  ██
    ████    ██                          ██    ██  ██████████
  ██  ██      ██            ██            ██  ██  ██
  ██  ██        ████      ██              ██  ██  ██
  ████            ████  ██        ██      ██████  ██████████
                ████████        ██        ████    ████
              ██    ████    ████          ████  ██  ██
              ██    ██████████            ████  ██  ██
                ██████████                  ██  ██  ██
        ██████  ██████████████████████████████████  ██
        ██  ████████  ██                    ██  ██  ████
        ██████████      ██████████████████████████    ██
          ██████        ██                  ██        ██████
                          ██                ██
*/
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool used[1000010];
int main(){
    int s; cin>>s;
    used[s]=1;
    int m=2;
    while(1){
        if(s%2){
            s=3*s+1;
        }else{
            s/=2;
        }
        if(used[s]){
            cout<<m<<endl;
            return 0;
        }
        m++;
        used[s]=1;
    }
    return 0;
}


Measured memory_bytes: 256
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ratios = new long[num, 2];
        for (var i = 0; i < num; i++)
        {
            var input = ReadLine().Split(' ');
            ratios[i, 0] = ToInt32(input[0]);
            ratios[i, 1] = ToInt32(input[1]);
        }
        
        long taka = 1;
        long ao = 1;
        for(var i = 0; i < num; i++)
        {
            if (taka > ratios[i, 0] || ao > ratios[i, 1])
            {
                long scope = Max(taka / ratios[i, 0] + (taka % ratios[i, 0] == 0 ? 0 : 1), ao / ratios[i, 1] + (ao % ratios[i, 1] == 0 ? 0 : 1));
                taka = ratios[i, 0] * scope;
                ao = ratios[i, 1] * scope;
            }
            else
            {
                taka = ratios[i, 0];
                ao = ratios[i, 1];
            }

        }
        WriteLine(taka + ao);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  vector<string> s(3);
  rep(i,3) cin >> s[i];
  string ans;
  rep(i,3) ans += s[i][i];
  cout << ans << endl;
}


Measured memory_bytes: 256
class DisjointSet

  def initialize n
    @ps = n.times.map.to_a
  end

  def union x, y
    x = find x
    y = find y
    @ps[y] = x
  end

  def find x
    if x == @ps[x]
      x
    else
      @ps[x] = find @ps[x]
    end
  end

end

n, q = gets.split.map &:to_i
ds = DisjointSet.new n
q.times do
  c, x, y = gets.split.map &:to_i
  if c.zero?
    ds.union x, y
  else
    p ds.find(x) == ds.find(y) ? 1 : 0
  end
end

Measured memory_bytes: 9152
#include <iostream>
#include <vector>

using namespace std;

int main(){
  vector<vector<int> > a(3, vector<int>(3,0));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      std::cin >> a[i][j];
    }
  }
  int n;
  std::cin >> n;
  vector<int> b(n);
  for(int i=0; i<n; i++) std::cin >> b[i];

  for(int i=0; i<n; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if( b[i] == a[j][k]) a[j][k] = INT_MAX;
      }
    }
  }

  for(int i=0; i<3; i++){
    if( a[i][0] == INT_MAX
    &&  a[i][1] == INT_MAX
    &&  a[i][2] == INT_MAX ){
      std::cout << "Yes" << '\n';
      return 0;
    }

    if( a[0][i] == INT_MAX
    &&  a[1][i] == INT_MAX
    &&  a[2][i] == INT_MAX ){
      std::cout << "Yes" << '\n';
      return 0;
    }
  }

  if( a[0][0] == INT_MAX
  &&  a[1][1] == INT_MAX
  &&  a[2][2] == INT_MAX ){
    std::cout << "Yes" << '\n';
    return 0;
  }
  if( a[0][2] == INT_MAX
  &&  a[1][1] == INT_MAX
  &&  a[2][0] == INT_MAX ){
    std::cout << "Yes" << '\n';
    return 0;
  }
  std::cout << "No" << '\n';

  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

typedef struct{int x,y;}P;

int main(void){
	int h,w;
	scanf("%d%d",&h,&w);
	char A[h][w+1];
	for(int i=0;i<h;i++)scanf("%s",A[i]);
	
	P black[1000000];
	int d[h][w];
	int head=0,tail=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(A[i][j]=='#'){
				black[tail].x=i;
				black[tail++].y=j;
				d[i][j]=0;
			}else d[i][j]=-1;
	
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	int ans=0;
	while(head<tail){
		int nx=black[head].x;
		int ny=black[head++].y;
		for(int i=0;i<4;i++){
			int px=nx+dx[i];
			int py=ny+dy[i];
			if(0<=px && px<h && 0<=py && py<w){
				if(d[px][py]<0){
					d[px][py] = d[nx][ny]+1;
					ans=MAX(ans,d[px][py]);
					black[tail].x=px;
					black[tail++].y=py;
				}
			}
		}
	}
	
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b && a>=c)cout<<(b+c)<<endl;
  else if(b>=a && b>=c)cout<<(a+c)<<endl;
  else cout<<(a+b)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int i,m;
	char s[101];

	scanf("%s",s);
	m=strlen(s);
	for(i=0;i<m;i++){
		if((i%2==0)&&(s[i]=='L')){
			printf("No\n");
			return 0;
		}
		else if((i%2!=0)&&(s[i]=='R')){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128