akhauriyash/Code-Regression huggingface dataset:
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define RET(p,x) return p<<x<<endl,0
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define sqr(x) ((x)*(x))
const int inf=1e9;
const ll lnf=1e18;
const int mod=1e9+7;
int h,w;
char s[13][13];
string ss[13];
int a[13];
int b[13];
void dfs1(int x,bool f)
{
	if (x==w)
	{
		puts("YES");
		exit(0);
	}
	else if (b[x]!=-1) dfs1(x+1,f);
	else
	{
		for (int i=x+1;i<w;++i)
		{
			if (b[i]!=-1) continue;
			int j;
			for (j=0;j<h;++j) if (s[j][x]!=s[a[j]][i]) break;
			if (j==h)
			{
				b[x]=i;
				b[i]=x;
				dfs1(x+1,f);
				b[x]=b[i]=-1;
			}
		}
		if (!f)
		{
			int j;
			for (j=0;j<h;++j) if (s[j][x]!=s[a[j]][x]) break;
			if (j==h)
			{
				b[x]=x;
				dfs1(x+1,true);
				b[x]=-1;
			}
		}
	}
}
void dfs2(int x,bool f)
{
	if (x==h) dfs1(0,!(w&1));
	else if (a[x]!=-1) dfs2(x+1,f);
	else
	{
		for (int i=x+1;i<h;++i)
		{
			if (a[i]!=-1) continue;
			if (ss[x]!=ss[i]) continue;
			a[x]=i;
			a[i]=x;
			dfs2(x+1,f);
			a[x]=a[i]=-1;
		}
		if (!f)
		{
			a[x]=x;
			dfs2(x+1,true);
			a[x]=-1;
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>h>>w;
	for (int i=0;i<h;++i) cin>>s[i],ss[i]=s[i],sort(ss[i].begin(),ss[i].end());
	for (int i=0;i<1000000000;++i);
	for (int i=0;i<h;++i) a[i]=-1;
	for (int i=0;i<w;++i) b[i]=-1;
	dfs2(0,!(h&1));
	cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

template <typename T>
struct BIT
{
    int n;
    vector<T> bit;
    
    BIT(){}
    
    BIT(int n) : n(n){
        bit.resize(n + 1);
    }
    
    T sum(int i){   // sum of [0, i)
        T res = 0;
        while(i){
            res += bit[i];
            i -= (i & -i);
        }
        return res;
    }
    
    void add(int i, T x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += (i & -i);
        }
    }
};

int main()
{
    int n, q;
    cin >> n >> q;
    BIT<ll> bit(n);
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        bit.add(i, a);
    }
    while(q--){
        int t;
        cin >> t;
        if(t){
            int l, r;
            cin >> l >> r;
            cout << bit.sum(r) - bit.sum(l) << endl;;
        }
        else{
            int p;
            ll x;
            cin >> p >> x;
            bit.add(p, x);
        }
    }
}


Measured memory_bytes: 8212
mod=10**9+7
k=input()
d=int(input())
l=[int(i) for i in "0"+k]
dp=[[[0]*(d+2),[0]*(d+2)] for _ in "ww"]
dp[0][0][0]=1
#dp[1][1][0]=1
for i,j in enumerate(l):
    if i==0: continue
    for p in range(d+1):
        if dp[i%2-1][0][p]:
            dp[i%2][0][[(p+j)%d,d][(p+j)%d==0]]=1
            for q in range(j):
                dp[i%2][1][[[(p+q)%d,d][(p+q)%d==0],0][p==q==0]]+=1
        if dp[i%2-1][1][p]:
            for q in range(10):
                dp[i%2][1][[[(p+q)%d,d][(p+q)%d==0],0][p==q==0]]+=dp[i%2-1][1][p]
    for p in range(d+2):
        dp[i%2-1][0][p]=0
        dp[i%2-1][1][p]=0
        dp[i%2][0][p]%=mod
        dp[i%2][1][p]%=mod

print((dp[0][0][d]+dp[0][1][d]+dp[1][0][d]+dp[1][1][d])%mod)

Measured memory_bytes: 49116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;

int main() {
	speed;
	int a, b, n;
	cin >> a >> b >> n;
	cout << n / a * b << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  long long int x,y;
  cin>>x>>y;
  long long int a=x;
  int i=0;
  for(;;i++){
    if(a > y)break;
    a=a<<1;    
  }
  cout<<i<<endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)

int main() {
  int N;
  int p,q;
  int count = 0;
  cin >> N;
  rep (i, N) {
    cin >> p >> q;
    count += q - p + 1;
  }
  
  cout << count << endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
  int x,h;
  double s,r;
  for(;;){
    scanf("%d\n%d",&x,&h);
    if(x==0 && h==0) break;
    r = (double)x / 2;
    r = sqrt(r*r + h*h);
    s = x*x + 2*x*r;
    printf("%.6lf\n",s);
  }
  return 0;
}

Measured memory_bytes: 0
#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 n, a[100001];
  cin >> n;
  rep(i, 0, n) cin >> a[i];


  int sum = 0;
  int ans1 = 0;
  int f = 0;
  rep(i, 0, n) {
    sum += a[i];
    if(f) {
      if(sum <= 0) {
        ans1 += abs(sum) + 1;
        sum = 1;
      }
    }else {
      if(sum >= 0) {
        ans1 += sum + 1;
        sum = -1;
      }
    }
    f = !f;
  }

  sum = 0;
  f = 1;
  int ans2 = 0;
  rep(i, 0, n) {
    sum += a[i];
    if(f) {
      if(sum <= 0) {
        ans2 += abs(sum) + 1;
        sum = 1;
      }
    }else {
      if(sum >= 0) {
        ans2 += sum + 1;
        sum = -1;
      }
    }
    f = !f;
  }

  cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	string a, b;
	long long int counter = 0;
	cin >> a >> b;
	for(int i = 0; i < a.size(); i++){
		if(a[i] != b[i]){
			counter++;
		}
	}
	cout << counter;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll n,k,i,ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    for(i = k + 1;i <= n;i += 1){
        ans = ans + (n / i) * max(0LL,i - k);
        if(n%i >= k)
            ans = ans + n%i - k + 1;
        if(k == 0)
            ans -= 1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N;
	cin >> N;
	if (N < 1000){
		cout << "ABC" <<endl;
	}
	else{
		cout << "ABD" <<endl;
	}
	return 0;
}

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

int main(){
    string A;
    cin >> A;
    int N = (int)A.size();
    vector<ll> dp(N, 0);
    dp[0] = 1;
    vector<int> cnt(26, 0);
    cnt[A[0]-'a']++;
    for (int i = 1; i < N; i++){
        int x = A[i]-'a';
        dp[i] = dp[i-1] + (i-cnt[x]);
        cnt[x]++;
    }
    cout << dp[N-1] << endl;
    return 0;
}


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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int aCount = c / b;
    if (c % b > 0)
        aCount++;
    int bCount = a / d;
    if (a % d > 0)
        bCount++;
    if (aCount <= bCount)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A, B;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    A.emplace_back(x - y);
    B.emplace_back(x + y);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  int res = max(A.back() - A.front(), B.back() - B.front());
  cout << res << '\n';
  return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define rep(i, n) for(LL i = 0;i < n;i++)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/

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

struct Edge{
    int to;
    long long cap;
    int rev;
};

class Dinic{
    private:
        int V; // 頂点数
        vector<long long> minCost; 
        vector<int> iter;
        vector<vector<Edge>> graph;
        const long long INFl = 1e15;
        bool Bfs(int s, int t);
        long long Dfs(int idx, const int t, long long flow);
    public:
        Dinic(int n);
        void AddEdge(int from, int to, long long cap);
        long long Run(int s, int t);
};

Dinic::Dinic(int n):
    V(n)
    {graph.assign(V, vector<Edge>());}

void Dinic::AddEdge(int from, int to, long long cap){
    graph[from].push_back((Edge){to, cap, (int)graph[to].size()});
    graph[to].push_back((Edge){from, 0, (int)graph[from].size() - 1});
}

bool Dinic::Bfs(int s, int t){
    minCost.assign(graph.size(), -1);
    queue<int> que;
    minCost[s] = 0;
    que.push(s);
    while(!que.empty()){
        int p = que.front();
        que.pop();
        for(auto &e : graph[p]){
            if(e.cap > 0 && minCost[e.to] < 0){
                minCost[e.to] = minCost[p] + 1;
                que.push(e.to);
            }
        }
    }
    return (minCost[t] != -1);
}

long long Dinic::Dfs(int idx, const int t, long long flow){
    if(idx == t) return flow;
    for(int &i = iter[idx]; i < (int)graph[idx].size(); ++i){
        Edge &e = graph[idx][i];
        if(e.cap > 0 && minCost[idx] < minCost[e.to]){
            long long d = Dfs(e.to, t, min(flow, e.cap));
            if(d > 0){
                e.cap -= d;
                graph[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

long long Dinic::Run(int s, int t){
    long long flow = 0;
    while(Bfs(s, t)){
        iter.assign(graph.size(), 0);
        long long f = 0;
        while((f = Dfs(s, t, INFl)) > 0){
            flow += f;
        }
    }
    return flow;
}

signed main(){
    int n;
    vector<P> blue, red;

    cin >> n;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        red.pb(P(a, b));
    }
    rep(i, n){
        int c, d;
        cin >> c >> d;
        blue.pb(P(c, d));
    }

    Dinic f(n*2 + 2);
    rep(i, n){
        f.AddEdge(0, i+1, 1);
        f.AddEdge(n+1+i, n*2+1, 1);
    }
    rep(i, n){
        rep(j, n){
            if(red[i].first < blue[j].first && red[i].second < blue[j].second){
                f.AddEdge(i+1, j+n+1, 1);
            }
        }
    }

    cout << f.Run(0, n*2+1) << endl;
}


Measured memory_bytes: 512
n=int(input())
a=[int(input()) for _ in range(n)]
sumA=sum(a)
if sumA%10>0:
  print(sumA)
else:
  a=sorted(a)
  for b in a:
    if b%10>0:
      print(sumA-b)
      break
  else:
    print(0)
  

Measured memory_bytes: 9144
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

class UnionFind {
    struct UFNode {
        int par;
        int rank;
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    int x,y,z;
    REP(i,0,m) {
        cin >> x >> y >> z;
        --x; --y;
        uf.unite(x,y);
    }
    int ans = 0;
    REP(i,0,n) if (uf.root(i) == i) ++ans;
    //REP(i,0,n) dump(uf.root(i));
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 110
#define INF 0x3f3f3f3f
int m[N][N];
int used[N];
int d[N];
int n;
int sum = 0;
void prim(){
    used[1] = 1;
    d[1] = 0;
    for(int k = 1; k < n; k++){
        int min = INF, u;
        for(int i = 1; i <= n; i++){
            if(!used[i] && d[i] < min){
                min = d[i];
                u = i;
            }
        }

        used[u] = 1;
        sum += d[u];
        for(int v = 1; v <= n; v++){
            if(!used[v] && m[u][v] < d[v]){
                d[v] = m[u][v];
            }
        }
    }
    printf("%d\n", sum);
}
int main(){

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) m[i][j] = INF;
    for(int i = 1; i <= n; i++){
        d[i] = INF;
        used[i] = 0;
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int p;
            scanf("%d", &p);
            if(p != -1) m[i][j] = p;
        }
    }
    for(int i = 1; i <= n; i++) d[i] = m[1][i];
    prim();
    return 0;
}


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

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

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

long long solve(long long n, long long a, long long b) {
    long long ans = n;
    ans -= n / a;
    ans -= n / b;
    ans += n / lcm(a, b);
    return ans;
}

long long solve(long long a, long long b, long long c, long long d) {
    long long ans = solve(b, c, d);
    if (a > 1) {
        ans -= solve(a - 1, c, d);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << solve(a, b, c, d) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int num = sc.nextInt();
			int n = num / 2;
			BigDecimal ans = new BigDecimal(num - n).divide(new BigDecimal(num),10,BigDecimal.ROUND_DOWN);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
main(){
  int n,q;
  int c[300001]={0};
  int max;
  int a;
  int cheak;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    cin >> a;
    c[a]=1;
  }
  for(int i=0;i<q;i++){
    cin >> a;
    cheak=0;
    for(int j=1;j<=a && cheak==0;j++){
      for(int k=a-j;k<=300000 && cheak==0;k=k+a){
	if(c[k]==1){
	  cout << a-j << endl;
	  cheak=1;
	}
      }
    }
    
  }
}

Measured memory_bytes: 2340
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	string s; cin >> s;
	int a = 0, bc = 0, ans = 0;
	rep(i, s.size()) {
		if (s[i] == 'A') {
			bc = 0; a++;
		}
		else if (i < s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C') {
			bc++; 
			if (i >= s.size() - 3 || (i < s.size() - 3 && s[i + 2] != 'B' || s[i + 3] != 'C')) {
				ans += bc * a;
				bc = 0;
			}
			i++;
		}
		else {
			a = 0, bc = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
def main():
    w, h, x, y = map(int, input().split())
    print('%.6f %d' % solve(w, h, x, y))

def solve(w, h, x, y):
    r = w * h / 2
    if x == w / 2 and y == h / 2:
        return (r, 1)
    else:
        return (r, 0)

main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> L(N);
	for(int i=0; i<N; i++) cin >> L[i];
	sort(L.begin(), L.end());

	ll ans = 0;
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			auto lb = lower_bound(L.begin()+j+1, L.end(), L[j]-L[i]+1);
			auto ub = upper_bound(L.begin()+j+1, L.end(), L[i]+L[j]-1);
			ans += (ub-lb);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import itertools
import math

def rt(x1, x2, y1, y2):
    cal = (x2-x1)**2 + (y2-y1)**2
    return math.sqrt(cal)

n = int(input())
patern = list(itertools.permutations(range(1,n+1), n))

input_list = [[0, 0]]
for _ in range(1, n+1):
    x, y = map(int, input().split())
    input_list.append([x, y])

cal = 0
for i in range(len(patern)):
    for j in range(n-1):
        index = patern[i][j]
        index_ad = patern[i][j+1]
        x1 = input_list[index][0]
        x2 = input_list[index_ad][0]
        y1 = input_list[index][1]
        y2 = input_list[index_ad][1]

        cal += rt(x1, x2, y1, y2)

print(cal/len(patern))


Measured memory_bytes: 7972
#include<cstdio>
#include<algorithm>
const static int MAX_N = 50;
const static int MAX_M = 50;
bool A[MAX_N][MAX_N];
bool B[MAX_M][MAX_M];

int main(){
	int N, M;
	scanf("%d %d", &N, &M);
	char a;
	for (int i = 0; i < N; ++i){
		scanf("\n");
		for (int j = 0; j < N; ++j){
			scanf("%c", &a);
			A[i][j] = a == '.';
		}
	}
	for (int i = 0; i < M; ++i){
		scanf("\n");
		for (int j = 0; j < M; ++j){
			scanf("%c", &a);
			B[i][j] = a == '.';
		}
	}
	for (int A_begin_x = 0; A_begin_x < N - M + 1; ++A_begin_x){
		for (int A_begin_y = 0; A_begin_y < N - M + 1; ++A_begin_y){
			bool flag = true;
			for (int B_x = 0; B_x < M; ++B_x){
				for (int B_y = 0; B_y < M; ++B_y){
					if(A[A_begin_x + B_x][A_begin_y + B_y] ^ B[B_x][B_y]){
						flag = false;
						break;
					}
				}
				if(!flag) break;
			}
			if(flag){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

const int kMaxN = 101;
const int kInf = 1 << 29;

int dp[kMaxN][kMaxN][kMaxN];

void Update(int& a, int b) {
  a = min(a, b);
}

int main() {
  cin.sync_with_stdio(false);

  int a, b, c;
  cin >> a >> b >> c;

  for (int i = 0; i < kMaxN; i++) {
    for (int j = 0; j < kMaxN; j++) {
      for (int k = 0; k < kMaxN; k++) {
        dp[i][j][k] = kInf;
      }
    }
  }

  dp[a][b][c] = 0;
  for (int i = a; i < kMaxN; i++) {
    for (int j = b; j < kMaxN; j++) {
      for (int k = c; k < kMaxN; k++) {
        if (dp[i][j][k] != kInf) {
          if (i + 1 < kMaxN && j + 1 < kMaxN) {
            Update(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
          }
          if (i + 1 < kMaxN && k + 1 < kMaxN) {
            Update(dp[i + 1][j][k + 1], dp[i][j][k] + 1);
          }
          if (j + 1 < kMaxN && k + 1 < kMaxN) {
            Update(dp[i][j + 1][k + 1], dp[i][j][k] + 1);
          }

          if (i + 2 < kMaxN) {
            Update(dp[i + 2][j][k], dp[i][j][k] + 1);
          }
          if (j + 2 < kMaxN) {
            Update(dp[i][j + 2][k], dp[i][j][k] + 1);
          }
          if (k + 2 < kMaxN) {
            Update(dp[i][j][k + 2], dp[i][j][k] + 1);
          }
        }
      }
    }
  }

  int ans = kInf;
  for (int i = 0; i < kMaxN; i++) {
    ans = min(ans, dp[i][i][i]);
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>

int main(){
   int N;
   scanf("%d",&N);
   if(N %10 == 7 || (N/10)%10 == 7 || (N/100)%10 == 7){
      printf("Yes\n");
   } else {
      printf("No\n");
   }
   return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
ll ji,ou;
ll n;
ll x;
int main()
{
	n=read();
	for(rg int i=1;i<=n;++i)
	{
		x=read();
		if(x%2==0)
		{
			ou++;
		}	
		else if(x%2!=0)
		{
			ji++;
		}	
	}
	while(1)
	{
		if(ji<=1&&ou<=1)
		{
			break;
		}
		if(ji>=2)
		{
			ji-=2;
			ou+=1;
		}
		if(ou>=2)
		{
			ou--;
		}
	}
	if(ji+ou==1)
	{
		cout<<"YES";
		return 0;
	}
	else
	{
		cout<<"NO";
		return 0;
	}
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N - 1);

	for (int i = 0; i < N; i++)
		cin >> A.at(i);
	for (int i = 0; i < N; i++)
		cin >> B.at(i);
	for (int i = 0; i < N - 1; i++)
		cin >> C.at(i);

	int sum = 0;

	for (int i = 0; i < N; i++)
		sum += B.at(i);
	for (int i = 0; i < N - 1; i++) {
		if (A.at(i) + 1 == A.at(i + 1))
			sum += C.at(A.at(i) - 1);
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
    
    int a, b, c, ans;
    ans = 0;
    
    cin >> a >> b >> c; 

    for (int x = a; x <= b; x++){
        if((c % x) == 0) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;		 
}



Measured memory_bytes: 3100
n=gets.to_i
x=gets.chomp.chars.zip(gets.chomp.chars).map{|a,b|a==b}.chunk{|e|e}.map.with_index{|(k,v),i|
	if k
		2**(v.size-1)
	else
		2*3**(v.size/2-1)
	end
}
p x.reduce(:*)*3%(10**9+7)

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

int s[100000];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &s[i]);
	int q; scanf("%d", &q);
	int cnt = 0;
	rep(i, q) {
		int t; scanf("%d", &t);
		if (binary_search(s, s + n, t))cnt++;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 3472
def roll(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

d1 = gets.split(" ").map{|i| i.to_i}
d2 = gets.split(" ").map{|i| i.to_i}

yn = false    
for i in 1..6
  d = Marshal.load(Marshal.dump(d2))
  case i
  when 2 then d = roll(d,"S")
  when 3 then d = roll(roll(d,"W"),"S")
  when 4 then d = roll(d,"N")
  when 5 then d = roll(roll(d,"E"),"S")
  when 6 then d = roll(roll(d,"S"),"S")
  end
  for j in 1..4
    d = roll(d,"W")
    yn = (yn || d == d1)
  end
end

puts(yn ? "Yes" : "No")

Measured memory_bytes: 8668
#include<bits/stdc++.h>
using namespace std;
char func(char c, int n){
    int ch[26];
    n=n%26;
        if(int(c)+n>90){
            return char(64+(n-(90-int(c))));
        }
        else{
            return char(int(c)+n);
        }
}
int main(){
    int n; cin>>n;
    string s; cin>>s;
    for(int i=0;i<s.length();i++)
    {
        s.at(i)=func(s.at(i),n);
    }
    cout<<s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=1000000007;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n,q;cin >> n >> q;
    auto uf = dsu(n);
    while(q--){
        int t,u,v;cin >> t >> u >> v;
        if(t == 0){
            uf.merge(u, v);
        }
        else{
            cout << uf.same(u, v) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#ifdef LOCAL
    #include "trace.h"
#else
    #define trace(args...)
#endif
 
ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
	string s;
	cin>>s;
	if(s.back()=='s')
		s += "es";
	else
		s += "s";	
	cout<<s<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef LOCAL
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=1e5+7;

int h[N],dp[N];

int main(){
	int n=input(),k=input();
	for(int i=1;i<=n;i++){
		h[i]=input();
	}
	dp[1]=0;
	for(int i=2;i<=n;i++){
		dp[i]=0x3f3f3f3f;
		for(int j=1;j<=k;j++){
			if(i-j<1) break; 
			dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]),dp[i]);
		}
	}
	cout<<dp[n]<<endl;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
 #define watch(x) cout<<(#x)<<" is " <<x<<"\n"

#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9 + 7;
const ll MAX = 1e5+7;
const ll inf = 1e18+1;
ld dist[10][10];
int main(){
 fastio;
 ll n;
 cin>>n;
 vii v;
 vi p;
 f(i,0,n){
    ll a,b;
    cin>>a>>b;
    v.pb({a,b});
 }
 f(i,0,n) {
        f(j,0,n) {
            dist[i][j] = powl((v[i].fs-v[j].fs)*(v[i].fs-v[j].fs)+(v[i].sc-v[j].sc)*(v[i].sc-v[j].sc), (ld) 0.5);
        }
    }
f(i,0,n) p.pb(i);
 ld prom = 0,cont=0;
 do { 
    ld dis=0;
    f(i,0,n-1){
        dis += dist[p[i]][p[i+1]];
    }   
    prom+=dis;
    cont++;
    } while (next_permutation(all(p))); 
 cout<<setprecision(20)<<prom/cont<<"\n";
 return 0; 
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

class UnionFind
{
private:
    vector<ll> p;
    vector<ll> rank;
public:
    UnionFind(ll n){
        p.resize(n,-1);
        rank.resize(n,1);
    }
    ll find(ll x){
        if(p[x]<0)return x;
        return p[x]=find(p[x]);
    }
    void unite(ll x,ll y){
        x = find(x);
        y = find(y);
		if(x == y)return;
        if(rank[x] > rank[y])swap(x,y);
        if(rank[x] == rank[y])rank[y]++;
        p[y] += p[x];
        p[x] = y;
    }
    ll size(ll x){
        return -p[find(x)];
    }
};

signed main(){
	//cout << fixed << setprecision(10);
    ll n,m; cin >> n >> m;
	UnionFind uf(n);
	rep(i,0,m){
		ll a,b; cin >> a >> b;
		--a; --b;
		uf.unite(a,b);
	}
	map<ll,ll> mp;
	rep(i,0,n){
		mp[uf.find(i)]++;
	}
	cout << mp.size() - 1 << endl;

	return 0;
}

Measured memory_bytes: 9860
// 19/09/2020  @ 17:56:40
// *****************************************************************
// *****************************************************************
#include <bits/stdc++.h>
// *****************************************************************
// *****************************************************************
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define fr(i,n) for(llu i=0;i<n;i++)
#define fl(j,a,b) for(llu j=a;j<=b;j++)
#define Pi 3.1415926535897932384626
#define mod 1e9+7
#define MID(a,b) ((a + b) >> 1)
#define MAX(a,b) ((a) > (b) ? (a): (b))
#define MIN(a,b) ((a) < (b) ? (a) :(b))
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define printer(a, n) fr(i,n) cout << a[i] << " ";
// *****************************************************************
// *****************************************************************
typedef long long unsigned int llu;
typedef long long int ll;
// *****************************************************************
// *****************************************************************
using namespace std;
// *****************************************************************
// *****************************************************************

                   // Dream it. Wish it. Do it.

                         // tannatsri //

              // Without tact you can learn nothing.

// *****************************************************************
// *****************************************************************
bool rev(ll a, ll b) {
    return a > b;
}
// *****************************************************************
void solution() {
    ll n, ans = 0;
    cin >> n;
    if(n == 2) {
        cout << 1;
        return;
    }
    if(n == 3) {
        cout << 3;
        return;
    }
    n -= 1;
    fl(i, 1, n) {
        ans += (n/i);
    }
    cout << ans;

}
// *****************************************************************
int main() {
    IOS;

    // *****************************************************************
    // *****************************************************************
    int t = 1;
    
    while(t--) {

       solution();
       cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 301;
int n;
double dp[N][N][N];

double dfs(int a, int b, int c) {
	if (dp[a][b][c] >= 0.5) return dp[a][b][c];
	int m = a + b + c;
	double ks = (double)n / m;
	double ret = 0;
	if (a) ret += (dfs(a-1, b, c) + ks) * a / m;
	if (b) ret += (dfs(a+1, b-1, c) + ks) * b / m;
	if (c) ret += (dfs(a, b+1, c-1) + ks) * c / m;
	return dp[a][b][c] = ret;
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	scanf("%d", &n);
	vi cnt(4);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}

	for (int a = 0; a <= n; a++)
		for (int b = 0; b <= n; b++)
			for (int c = 0; c <= n; c++) dp[a][b][c] = -1;
	dp[0][0][0] = 0;
	printf("%.10f\n", dfs(cnt[1], cnt[2], cnt[3]));
}


Measured memory_bytes: 213376
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if (s.charAt(0) != s.charAt(1) && s.charAt(1) != s.charAt(2) && s.charAt(2) != s.charAt(0)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");      
    }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<int> a(n + 10), b(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> tot(n + 10, 0);
    vector<vector<int>> all(n + 10);
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            all[j].push_back(i);
        }
    }
    for (int i = n; i >= 1; i--) {
        if (tot[i] % 2 != a[i]) {
            b[i] = 1;
            for (int &x : all[i]) {
                tot[x]++;
            }
        }
    }
    int m = count(b.begin(), b.end(), 1);
    cout << m << "\n";
    for (int i = 1; i <= n; i++) {
        if (b[i] == 1) {
            cout << i << " ";
        }
    }
    cout << "\n";
}


Measured memory_bytes: 24576
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    //vector<int> val;
public:
    UF(int n) : num(n) {
        par.resize(n);
        siz.resize(n);
        //val.resize(n);
        int i;
        for (i = 0; i < n; i++) {
            par[i] = i; siz[i] = 1;
            //val[i]=0;
        }
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (siz[x] < siz[y]) {
            par[x] = y;
            siz[y] = siz[x] + siz[y];
            //val[y]=val[x]+val[y];
        }
        else {
            par[y] = x;
            siz[x] = siz[x] + siz[y];
            //val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
        //int ngroup( int& ans ) {
        int count = 0;
        int i;
        for (i = 0; i < num; i++) {
            if (par[i] == i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};

void solve()
{
    int n, Q;
    scanf("%d%d", &n, &Q);

    UF uf(n);
    int i;
    for (i = 0; i < Q; i++) {
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
        if (t == 0) {
            uf.unite(u, v);
        }
        else {
            if (uf.same(u, v)) {
                printf("1\n");
            }
            else {
                printf("0\n");
            }
        }
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 4288
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

const int maxn=1e5+100; 

int bk[maxn];

int main()
{
//	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n,q;
	
	scanf("%d",&n);
	
	ll int sum=0;
	
	for(int i=0,x;i<n;i++)
	{
		scanf("%d",&x);
		
		bk[x]++;
		
		sum+=x;
	} 
	
	scanf("%d",&q);
	
	for(int i=0,x,y;i<q;i++)
	{
		scanf("%d%d",&x,&y);
		
		bk[y]+=bk[x];
		
		sum+=(y-x)*bk[x];
		
		bk[x]=0;
		
		printf("%lld\n",sum);
			
	}
	
	return 0;
}

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

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

  int x, y;
  cin >> x >> y;

  if (x < 10 && y < 10) cout << x * y << endl;
  else cout << -1 << endl;

  return (0);
}


Measured memory_bytes: 3612
package main

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

type point struct {
	x, y, a int
}

func main() {
	w := getInt()
	h := getInt()
	n := getInt()

	ps := make([]point, n)
	for i := range ps {
		ps[i].x = getInt()
		ps[i].y = getInt()
		ps[i].a = getInt() - 1
	}

	a0, a1, a2, a3 := 0, w, 0, h
	for _, p := range ps {
		switch p.a {
		case 0:
			a0 = max(a0, p.x)
		case 1:
			a1 = min(a1, p.x)
		case 2:
			a2 = max(a2, p.y)
		case 3:
			a3 = min(a3, p.y)
		}
	}

	ans := max(a1-a0, 0) * max(a3-a2, 0)
	fmt.Println(ans)
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int A[5];
	cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
	int ans = INF/4;
	for (int i = 0; i < 5; i++)for (int j = 0; j < 5; j++) 
		for (int k = 0; k < 5; k++)for (int s = 0; s < 5; s++)
			for (int t = 0; t < 5; t++) {
				if (i == j || i == k || i == s || i == t ||
					j == k || j == s || j == t || k == s ||
					k == t || s == t)continue;
				int tmp = 0;
				tmp += (A[i] / 10 + (A[i] % 10 != 0)) + (A[j] / 10 + (A[j] % 10 != 0)) + (A[k] / 10 + (A[k] % 10 != 0)) + (A[s] / 10 + (A[s] % 10 != 0));
				tmp = tmp * 10 + A[t];
				ans = min(ans, tmp);
			}
	cout << ans << endl;
}


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

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

int main(){
    ll x;
    cin>>x;
    ll a,b;
    for(a=0;a<1000;a++){
        ll tmp;
        for(b=a;(tmp=a*a*a*a*a-b*b*b*b*b)<x;b--){
        }
        if(tmp==x){break;}
    }
    cout<<a<<" "<<b<<endl;

    return 0;
}

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

using u64 = uint64_t;

constexpr const u64 INVALID = UINT64_MAX;
constexpr const u64 MODNUM = 1000000007;

u64 count_way(vector<u64> &memo, array<string, 2> const &grid, unsigned a) {
    if (a >= grid[0].size()) return 1;
    if (memo[a] != INVALID) return memo[a];

    if (a == 0) {
        // 最初
        if (grid[0][a] == grid[1][a]) {
            // 縦。3通り。
            memo[0] = 3 * count_way(memo, grid, a+1);
        } else {
            // 横。6通り。
            memo[0] = 6 * count_way(memo, grid, a+2);
        }
    } else if (grid[0][a-1] == grid[1][a-1]) {
        // 前は縦
        if (grid[0][a] == grid[1][a]) {
            // 今回も縦。
            memo[a] = 2 * count_way(memo, grid, a+1);
        } else {
            // 今回は横。
            memo[a] = 2 * count_way(memo, grid, a+2);
        }
    } else {
        // 前は横
        if (grid[0][a] == grid[1][a]) {
            // 今回は縦。
            memo[a] = 1 * count_way(memo, grid, a+1);
        } else {
            // 今回も横。
            memo[a] = 3 * count_way(memo, grid, a+2);
        }
    }
    memo[a] %= MODNUM;
    return memo[a];
}

int main() {
    int N;
    array<string, 2> grid;
    cin >> N;
    cin >> grid[0] >> grid[1];
    vector<u64> memo(N, INVALID);
    cout << count_way(memo, grid, 0) << endl;
    return 0;
}


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

int main(){
 int A, B;
 cin >> A >> B;
 int k = 0;
 int ans = 0;
 bool ansF = false;

  for(int k = 0; k < 1000000000; k++){
    if(abs(A-k) == abs(B-k)){
      ans = k;
      ansF = true;
    }
  }


  if(ansF){
    cout << ans << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	double x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	

	double sum = hypot(x2-x1,y2-y1);

	printf("%lf\n",sum);

	return 0;
}

Measured memory_bytes: 3220
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

a, b, c = map(int, read().split())
if ((c - a - b) > 0) & (4 * a * b < pow(c - a - b, 2)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940