akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

s = input()

def typeStr(ans, str1):
    if str1 == "B":
        # 文字列が空ではない確認
        if ans != "":
            # 残っている時のみ削除を行う(最後の1文字以外を切り取る)
            ans = ans[0:-1]
    else:
        ans += str1
    return ans

ans = ""
for i in range(len(s)):
    ans = typeStr(ans, s[i])

print(ans)

Measured memory_bytes: 2940
import bisect
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=sorted(list(map(int, input().split())))
key=bisect.bisect_right(P,X)
small=101
large=0

for i in range(N):
    if P[key-1]-i not in P:
        small=P[key-1]-i
        break
for i in range(N):
    if P[key-1]+i not in P:
        large=P[key-1]+i
        break
print(small if abs(X-small)<=abs(X-large) else large)

Measured memory_bytes: 9220
H,W = map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)] 
A=[list(map(int,input().split())) for i in range(H)]

minimum_cost = [0 for i in range(10)]
for s in range(10):#s for start
    g =1 # g for goal
    md = [2000 for i in range(10)]#sからの最小距離
    md[s] = 0
    flag = [0 for i in range(10)]#確定フラグ
    while flag[g] != 1:

        mikakutei_min = min([md[j] for j in range(10) if flag[j]==0])
        for v in range(10):
            if (flag[v] == 0 and md[v] == mikakutei_min):
                flag[v] = 1
        for j in [j for j in range(10) if flag[j] == 0]:
            for i in [i for i in range(10) if flag[i] == 1]:
                if md[j] > md[i] + c[i][j]:
                    md[j] = md[i] + c[i][j]
    minimum_cost[s] = md[g]
        
#print(minimum_cost)                
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += minimum_cost[A[i][j]]
print(ans)        



Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;
#define int ll
int n, m;
int depend[10][10];
int p[10];
int32_t main()
{
    cin >> n >> m;
    for (int i = 0; i<m; i++)
    {
        int k; cin >> k;
        for (int j = 0; j<k; j++)
        {
            int x; cin >> x;
            depend[i][x-1] = 1;
        }
    }
    for (int i = 0; i<m; i++) cin >> p[i];
    int ans = 0;
    for (int i = 0; i<(1<<n); i++)
    {
        int ct_on = 0;
        for (int j = 0; j<m; j++)
        {
            int ctr = 0;
            for (int k = 0; k<n; k++)
            {
                if ((1<<k)&i)
                {
                    if (depend[j][k])
                        ctr++;
                }
            }
            if (ctr%2==p[j])
                ct_on++;
        }
        if (ct_on == m)
            ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
n = int(input())
l = [0]*n
s = set()
f_max,s_max = 0,0
c = 0
for i in range(n):
    a = int(input())
    l[i] = a
    if f_max < a:
        s_max = f_max
        f_max = a
        c = 0
    elif s_max < a < f_max:
        s_max = a
    elif f_max == a:
        c+=1

#s.sort()

if len(s)==1:
    for i in range(n):
        print(l[0])

    exit()

if c==0:
    for i in range(n):
        if l[i]==f_max:
            print(s_max)
        else:
            print(f_max)
else:
    for i in range(n):
        print(f_max)

        

Measured memory_bytes: 12508
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }
};

int main()
{
    input in;
    output out;

    int N, D;
    in >> N, D;
    std::vector<std::vector<int>> v(N);
    for (auto& p : v) {
        p.resize(D);
        in.read(p.begin(), D);
    }

    int res = 0;
    for (int i : boost::irange(0, N)) {
        for (int j : boost::irange(i + 1, N)) {
            int d2 = 0;
            for (int k : boost::irange(0, D)) d2 += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            int d = std::sqrt(d2);
            if (d * d == d2) ++res;
        }
    }

    out << res;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
int f[1000000];

void solve() {
    int n,d,c=0;
    cin>>n>>d;
    double x,y;
    fo(i,n)
    {
        cin>>x>>y;
        int p=ceil(sqrt(x*x+y*y));
        if(p<=d) c++;
    }
    cout<<c<<endl;
}




int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
   /* int t;
    cin>>t;
    while(t--)
    {
      solve();
    } */
    solve();
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}


void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}


Measured memory_bytes: 10904
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        int[][] nums=new int[n][2];
        if(s.charAt(0)=='#'){
            nums[0][0]=1;
        }else{
            nums[0][1]=1;
        }
        for(int i=1;i<n;i++){
            if(s.charAt(i)=='#'){
                nums[i][0]=1;
            }else{
                nums[i][1]=1;
            }
            nums[i][0]+=nums[i-1][0];
            nums[i][1]+=nums[i-1][1];
        }
        int output=nums[n-1][1];
        for(int i=0;i<n;i++){
            if(nums[i][0]+nums[n-1][1]-nums[i][1]<output){
                output=nums[i][0]+nums[n-1][1]-nums[i][1];
            }
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 33584
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long K, string S) {
    const glen = S.group.count;
    return N - glen + 2 * min(K, glen / 2) - (glen % 2 == 0 && K >= glen / 2 ? 1 : 0);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, K, S);
    else
        solve(N, K, S).writeln;
}


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int s, w;
    cin >> s >> w;
    if(w >= s) out("unsafe");
    else out("safe");
}

Measured memory_bytes: 3592
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

struct edge{
  int u;
  int v;
  int cost;
};

class UnionFind{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    //作る時はParentの値を全て-1にする
    //こうするとずべてバラバラになる
    UnionFind(int N){
      Parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているのか調べる
    int root(int A){
      if(Parent[A]<0) return A;
      return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
      return -Parent[root(A)];//親を取ってきたい
    }

    //AとBをくっつける
    bool connect(int A,int B){
      //AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける)
      A = root(A);
      B = root(B);
      if(A==B){
        //すでにくっついているからくっつけない
        return false;
      }
      //大きい方(A)に小さい方(B)をくっつけたい
      //大小が逆だったらひっくり返しちゃう
      if(size(A)<size(B)) swap(A,B);

      //Aのサイズを更新する
      Parent[A] += Parent[B];
      //Bの親をAに変更する
      Parent[B] = A;

      return true;
    }
  };

bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

edge es[MAX];
int V,E;                  //頂点数と辺数

int kruskal(){
  sort(es, es + 2*E-2, comp); //edge.costが小さい順にソートする
  UnionFind Uni(V);
  int res = 0;
  for (int i = 0; i < 2*E-2; i++){
    edge e = es[i];
    if(Uni.root(e.u) != Uni.root(e.v)) {
      Uni.connect(e.u , e.v);
      res += e.cost;
    }
  }
  return res;
}

int main(){
  int N;cin>>N;
  V = N;
  E = N;
  vector<pair<int ,int> > a(N),b(N);
  rep(i,N){
    cin>>a[i].first>>b[i].first;
  }
  rep(i,N){
    a[i].second = i;
    b[i].second = i;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  rep(i,N-1){
    es[i] = edge({a[i].second, a[i+1].second, a[i+1].first - a[i].first});
    es[N-1+i] = edge({b[i].second, b[i+1].second, b[i+1].first - b[i].first});
  }
  // rep(i,N) cout<<es[i].cost<<endl;

  int ans = kruskal();
  cout<<ans<<endl;

}


Measured memory_bytes: 6272
def resolve():
    n, m, x = map(int, input().split())
    A, C = [], []
    for _ in range(n):
        c_a = list(map(int, input().split()))
        c = c_a.pop(0)
        A.append(c_a)
        C.append(c)

    def dfs(N, B, D):
        if N == n:
            if min(B) < x:
                return -1
            else:
                return D
        r = dfs(N + 1, [x + y for (x, y) in zip(B, A[N])], D + C[N])
        l = dfs(N + 1, B, D)
        if l == r == -1:
            return -1
        else:
            if l == -1:
                return r
            elif r == -1:
                return l
            else:
                return min([l, r])

    print(dfs(0, [0 for i in range(m)], 0))
resolve()



Measured memory_bytes: 9240
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).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 main()
{
    const int MAX_V_SUM = 100000;

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, W;
    cin >> N >> W;

    vll w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    //dp[i][j] := 品物i - 1まで選んで価値をjにするときの重さの最小値
    vvll dp(N + 1, vll(MAX_V_SUM + 1, INF));
    dp[0][0] = 0;

    rep(i, N)
    {
        reple(j, 0, MAX_V_SUM)
        {
            chmin(dp[i + 1][j], dp[i][j]);

            if(j - v[i] >= 0) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }

    int ans = 0;
    reple(i, 0, MAX_V_SUM)
    {
        if (dp[N][i] <= W) chmax(ans, i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 80256
/*
                                                                                                                                               
8b        d8                           888888888888                                             88b           d88                  ad88888ba   
 Y8,    ,8P                                 88                                        ,d        888b         d888                 d8"     "8b  
  Y8,  ,8P                                  88                                        88        88`8b       d8'88                 ""      a8P  
   "8aa8"  ,adPPYba,   88       88          88  8b,dPPYba,  88       88  ,adPPYba,  MM88MMM     88 `8b     d8' 88   ,adPPYba,          ,a8P"   
    `88'  a8"     "8a  88       88          88  88P'   "Y8  88       88  I8[    ""    88        88  `8b   d8'  88  a8P_____88         d8"      
     88   8b       d8  88       88          88  88          88       88   `"Y8ba,     88        88   `8b d8'   88  8PP"""""""         ""       
     88   "8a,   ,a8"  "8a,   ,a88          88  88          "8a,   ,a88  aa    ]8I    88,       88    `888'    88  "8b,   ,aa         aa       
     88    `"YbbdP"'    `"YbbdP'Y8          88  88           `"YbbdP'Y8  `"YbbdP"'    "Y888     88     `8'     88   `"Ybbd8"'         88       
                                                                                                                                               
*/
#include <bits/stdc++.h>
using namespace std;

string s;

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	cin >> s;
	sort(s.begin(), s.end());

	if (s[1] != s[2] && s[0] == s[1] && s[2] == s[3]) cout << "Yes\n";
	else cout << "No\n";

	return 0;
} 

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

int main() {
    long a, b, c, k, ans;
    cin >> a >> b >> c >> k;
    ans = min(a, k);
    k -= a + b;
    ans -= max(0l, k);
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n, q, temp, count = 0;
    vector<int> line1, line2;
    cin >>n;
    for(int i = 0; i < n; i++){
        cin >>temp;
        line1.push_back(temp);
    }
    cin >>q;
    for(int i = 0; i < q; i++){
        cin >>temp;
        line2.push_back(temp);
    }
    for(int i = 0; i < line2.size(); i++){
        auto result = find(line1.begin(), line1.end(), line2.at(i));

        if(result != line1.end()){
            //cout << line1.size() << ":" << line2.size() << ":" << i << endl;
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long n, m, k, t;
    cin >> n >> m >> k >> t;
    long long r=0;
    while (m<=n)
    {
        m*=2;
        r+=1;
    }
    while (k<=m)
    {
        k*=2;
        r+=1;
    }
    if (r>t)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    
    int n = int(s.size());
    
    stack<bool> t;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'S') {
            t.push(1);
        }
        else {
            if(t.empty()) ans++;
            else t.pop();
        }
    }
    
    cout << ans + int(t.size());
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        int b;
        cin >> b;
        b--;
        a.at(i) = b;
    }
    int nwbt = 0;
    int cnt = 0;
    while(true){
        if(nwbt == 1){
            cout << cnt << endl;
            break;
        }
        if(cnt >= N){
            cout << -1 << endl;
            break;
        }
        nwbt = a.at(nwbt);
        cnt++;
    }
}

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=100+5;
bool no[N][N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int n;
	cin>>n;
	if(n%2==1)
	{
		rep(i,1,n/2)no[i][n-i]=1;
	}
	else
	{
		rep(i,1,n/2)no[i][n-i+1]=1;
	}
	int m=0;
	rep(i,1,n)
	rep(j,i+1,n)
	if(!no[i][j])++m;
	printf("%d\n",m);
	rep(i,1,n)
	rep(j,i+1,n)
	if(!no[i][j])printf("%d %d\n",i,j);
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var A = Read();
            var B = Read();
            var digit = Math.Max(A.Length, B.Length);
            A = A.PadLeft(digit, '0');
            B = B.PadLeft(digit, '0');
            if (A.CompareTo(B) < 0)
            {
                Console.WriteLine("LESS");
            }else if (A.CompareTo(B) > 0)
            {
                Console.WriteLine("GREATER");
            }
            else
            {
                Console.WriteLine("EQUAL");
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void b(ll n)
{

    ll c=1;
    string s="";
    while(n){
       if(n%(2*abs(c))){
          s+='1';
          n-=c;
       }
       else s+='0';
       c*=-2;
    }
    reverse(s.begin(),s.end());
    cout <<s<<endl;

}
int main()
{

     int n;
     cin >>n;
     if(n==0)return cout <<0<<endl,0;
     b(n);
//    int n,k;
//    cin >>n>>k;
//    int x=n/k;
//    int i=1,p=1;
//    while(1)
//    {
//        if(p>=n)break;
//        p=k*i;i++;
//    }
//    int y=p/k;
//    cout <<abs(y-x)<<endl;


//    bool ok=0;
//    while(1)
//    {
//        if(!n){ok=1;break;}
//        if(n<4){ok=0;break;}
//        else if(n%4==0){n/=4;ok=1;break;}
//        else if(n%7==0){n/=7;ok=1;break;}
//        else if(n>=7){n-=7;}
//        else if(n>=4){n-=4;}
//    }
//    cout <<((ok)?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

total = sum(A)//2

x0 = total
for i in range(N//2):
  x0 -= A[2*i+1]

ans = [2*x0]
for i in range(0,N-1):
  ans.append((A[i]-ans[i]//2)*2)

print(*ans)

Measured memory_bytes: 14024
import java.util.*;

class Main{
    Scanner sc = new Scanner(System.in);

    Main(){
	int a=sc.nextInt();
	int b=sc.nextInt();
	System.out.print( (a/b)+" "+(a%b)+" " );
	System.out.printf("%.8f\n", (double)a/b );
    }

    public static void main(String[] args){
	new Main();
    }
}

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

int main()
{
	int n;
	vector<int> d(3);
	cin >> n >> d[0] >> d[1] >> d[2];
	vector<pair<int, int>> q;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		int a = 0, b = 1;
		if(s == "AB") a = 0, b = 1;
		if(s == "AC") a = 0, b = 2;
		if(s == "BC") a = 1, b = 2;
		q.emplace_back(a, b);
	}
	string ans;
	auto add = [&](int a, int b){
		d[a]++;
		d[b]--;
		ans += 'A' + a;
	};
	q.emplace_back(0, 1);
	for(int i = 0; i < n; i++){
		int a = q[i].first;
		int b = q[i].second;
		if(!d[a] && !d[b]){
			cout << "No\n";
			return 0;
		}
		if(!d[a]) add(a, b);
		else if(!d[b]) add(b, a);
		else{
			int na = q[i + 1].first;
			int nb = q[i + 1].second;
			if(a == na || a == nb) add(a, b);
			else add(b, a);
		}
	}
	cout << "Yes\n";
	for(auto&& e : ans) cout << e << endl;
	return 0;
}


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

int main() {
    string s, t, ans = "UNRESTORABLE";
    cin >> s >> t;
    int i, j;
    for (i = s.size() - t.size(); i >= 0; i--) {
        bool isNotAnswer = false;
        for (j = 0; j < t.size(); j++) {
            if (s[i+j] != t[j] && s[i+j] != '?') {
                isNotAnswer = true;
                break;
            }
        }
        if (!isNotAnswer) {
            ans = s;
            for (j = 0; j < t.size(); j++) ans[i+j] = t[j];
            for (j = 0; j < s.size(); j++) if (ans[j] == '?') ans[j] = 'a';
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	string s;
	cin>>s;
	vint v(26);
	int n = s.size();
	rep(i,n){
		v[s[i]-'a']++;
	}
	ll ans = 1LL*n*(n+1)/2+1;
	rep(i,n){
		ans -= v[s[i]-'a'];
		// cout<<i<<" "<<v[s[i]-'a']<<endl;
		v[s[i]-'a']--;
		// ans -= v[s[i]-'a'];
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 720
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {
    static boolean check(String s){
        int n = s.length();
        for(int i = 0; i < n ; ++i){
            if(s.charAt(i) != s.charAt(n-1-i)){
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        String a = s.substring(0, (n-1)/2);
        String b = s.substring((n+3)/2-1, n);
        String ans = "No";
        if(check(s) && check(a) && check(b)) ans = "Yes";
        System.out.println(ans);
    }
}

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

int main(void)
{
	int a, b;
	cin >> a >> b;

	if (a <= 0 && b>=0) {
		cout << "Zero" << endl;
	}
	else if (b < 0) {
		if ((a - b) % 2 == 0) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}
	else {
		cout << "Positive" << endl;
	}
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r[n] = { }, l[n] = { };
  FOR(i, 1, n){
    r[i] = r[i-1] + (s[i-1] == 'W'?1:0);
  }
  for(int i = n-2; i >= 0; i--){
    l[i] = l[i+1] + (s[i+1] == 'E'?1:0);
  }
  int sum[n];
  REP(i, n) sum[i] = r[i] + l[i];
  int ans = INF;
  REP(i, n) ans = min(ans, sum[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4228
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i+1]: ans += 1
    if p[i-1] > p[i] > p[i+1]: ans += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	string s0;
	int n, a, b;
	string str[3] = {"replace", "reverse", "print"};
	cin >> s0 >> n;
	rep(i,n) {
		string s1;
		cin >> s1 >> a >> b;	
		if(s1 == str[0]) {
			string q;
			cin >> q;
			s0.replace(a, b - a + 1, q);
		} else if(s1 == str[1]) {
			string s2 = s0.substr(0, a);
			string s3 = s0.substr(a, b - a + 1);
			string s4 = s0.substr(b + 1);
			string s5;
			for(int j = 0; j < b - a + 1; ++j) {
				s5 += s3[b - a - j];
			}
			s0 = s2 + s5 + s4;
		} else if(s1 == str[2]){
			rep2(j, a, b + 1) {
				cout << s0[j];
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3216
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll fact(int n,int m)
{
	ll x=1;
	int i;
	f(i,1,n+1)
	{
		 x*=i;
		 x%=mod;
	}
	f(i,1,m+1)
	{
		x*=i;
		x%=mod;
	}
	return x;
}
int main(){
	std::ios::sync_with_stdio(false);
	int n,m;
	ll x;
	cin>>n>>m;
	if(abs(n-m)>1)
		cout<<0<<endl;
	else
	{
		if(n!=m)
		{
			cout<<fact(n,m)<<endl;
		}
		else{
			x=fact(n,m)*2;
			x%=mod;
			cout<<x<<endl;
		}
	}
} 


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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() {

	ll N,M,ans;
	cin >> N >> M;
	if(2 * N <= M) {
		ans = N;
		ans += (M-2*N) / 4;
	}else {
		ans = M/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

 
   int ans[31] = {};
  ans[1] = 1;
  ans[2] = 2;
  ans[3] = 4;
  for(int i=4;i<=30;i++) ans[i] = ans[i-3] + ans[i-2] + ans[i-1] ;
     
 while(1) {
				
   int n;
   cin >> n;
   if(n == 0) break;
   
    cout << (ans[n]/3650) +1 << endl;

  }

  return 0;

}
    

Measured memory_bytes: 1160
#include <iostream>

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

int main()
{
	unsigned long long A = 0, B = 0, C = 0, D= 0;

	std::cin >> A >> B >> C >> D;

	unsigned long long ans = B - A + 1;

	unsigned long long Sac = A / C;
	unsigned long long Sbc = B / C;
	unsigned long long Sad = A / D;
	unsigned long long Sbd = B / D;

	unsigned long long CD = C * D / gcd(C, D);

	unsigned long long Sacd = A / (CD);
	unsigned long long Sbcd = B / (CD);

	if (A%C != 0){
		Sac++;
	}
	if (A%D != 0){
		Sad++;
	}

	if (A%(CD) != 0){
		Sacd++;
	}

	ans -= ((Sbc - Sac + 1) + (Sbd - Sad + 1) - (Sbcd - Sacd + 1));

	std::cout << ans << std::endl;

	return 0;
}

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

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int k;
	cin >> k;

	int s = 0;
	for (int a = 1; a <= k; ++a) {
		for (int b = 1; b <= k; ++b) {
			for (int c = 1; c <= k; ++c) {
				s += gcd(gcd(a, b), c);
			}
		}
	}

	cout << s;
	
	return 0;
}
	

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int n, m;
vector<vector<pint>> g (105);
set<pint> s;

void dijkstra (int now) {
    int l[n], p[n];
    bool seen[n] = {};
    priority_queue<pint, vector<pint>, greater<pint>> pq;
    rep (i, n) {
        l[i] = inf;
        p[i] = -1;
    }
    l[now] = 0;
    pq.push ({0, now});

    while (!pq.empty()) {
        pint f = pq.top();
        pq.pop();
        int u = f.second;
        rep (i, g[u].size()) {
            int next = g[u][i].second;
            if (!seen[next] && l[next] > l[u] + g[u][i].first) {
                l[next] = l[u] + g[u][i].first;
                p[next] = u;
                pq.push ({l[next], next});
            }
        }
    }

    rep (i, n) {
        if (p[i] == -1) continue;
        int a = max (i, p[i]), b = min (i, p[i]);
        s.insert ({a, b});
        // cout << now << " " << a << " " << b << " " << l[i] << "\n";
    }
}

int main() {
    cin >> n >> m;
    int a[m], b[m], c[m];
    rep (i, m) {
        cin >> a[i] >> b[i] >> c[i];
        g[--a[i]].push_back ({c[i], --b[i]});
        g[b[i]].push_back ({c[i], a[i]});
    }
    rep (i, n) dijkstra (i);
    int ans = m - s.size();
    cout << ans << "\n";
}

Measured memory_bytes: 256
n = input()
minsofar = 100000000

def sumofdigits(a):
    ans = 0
    for i in `a`:
        ans += int(i)
    return ans

for i in range(1, n):
    a = i
    b = n - a
    minsofar = min(minsofar, sumofdigits(a) + sumofdigits(b))

print minsofar

Measured memory_bytes: 5764
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  cout << a * a - b << endl;
  return 0;
}


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

using namespace std;

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;

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

    int n;
    cin >> n;
    vi a(n);
    for (int i=0;i<n;++i) cin >> a[i];
    multiset<int> s(a.begin(),a.end());
    for (int i=0;i<n;++i) {
        s.erase(s.find(a[i]));
        auto x = s.end();
        --x;
        cout << *x << "\n";
        s.insert(a[i]);
    }
    return 0;
}

Measured memory_bytes: 11776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)
	        throws IOException {
		BufferedReader br = new BufferedReader(
		        new InputStreamReader(System.in));
		char[] c = br.readLine().toCharArray();
		for (int i = c.length - 1; i >= 0; i--) {
			System.out.print(c[i]);
		}
		System.out.println();
	}
}

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

int main()
{
	vector<int> card(5);
	vector<int> count(13);
	string handName[7] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
	int hand;
	int max, pair;
	int i;

	while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF) {
		fill(count.begin(), count.end(), 0);
		max = 0;
		pair = 0;
		for (i = 0; i < 5; i++) {
			if ( ++count[card[i]-1] > max )
				max = count[card[i]-1];
			if ( count[card[i]-1] == 2 )
				pair++;
		}

		if (max == 4) hand = 6;
		else if (max==3 && pair==2) hand = 5;
		else if (max == 3) hand = 3;
		else if (pair == 2) hand = 2;
		else if (pair == 1) hand = 1;
		else hand = 0;
		if (hand < 4) {
			for (i = 0; i < 13-3; i++) {
				if (count[i]==1 && count[i+1]==1 && count[i+2]==1 && count[i+3]==1 && count[(i+4)%13]==1)
					hand = 4;
			}
		}

		cout<<handName[hand]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C = sl()
    print(str.upper(A[0] + B[0] + C[0]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if (L[i] != L[j]) and (L[i] != L[k]) and (L[j] != L[k]):
                if ((L[i]+L[j])>L[k]) and ((L[i]+L[k])>L[j]) and ((L[j]+L[k])>L[i]):
                    ans += 1
print(ans)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
int udis[200001];
int vdis[200001];
vector<int> ca[200001];
bool vis[200001];
queue<int> qu;
lol ans=0;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>a;
  int u,v;
  cin >>u>>v;
  for(int n=0;n<a-1;n++){
    cin >>c>>d;
    ca[c].push_back(d);
    ca[d].push_back(c);
  }
  memset(vis,false,sizeof(vis));
  memset(udis,inf,sizeof(udis));
  memset(vdis,inf,sizeof(vdis));
  vdis[v]=0;
  qu.push(v);
  vis[v]=true;
  while(!qu.empty()){
    int x=qu.front();
    qu.pop();
    vis[x]=true;
    for(int n=0;n<ca[x].size();n++){
      if(!vis[ca[x][n]]&&vdis[x]+1<vdis[ca[x][n]]){
	qu.push(ca[x][n]),vdis[ca[x][n]]=vdis[x]+1;
      }
    }
  }
  memset(vis,false,sizeof(vis));
  udis[u]=0;
  qu.push(u);
  vis[u]=true;
  while(!qu.empty()){
    int x=qu.front();
    qu.pop();
    vis[x]=true;
    if(udis[x]<=vdis[x]){
      /*  if(udis[x]+2<vdis[x]){
	lol op=udis[x];
	while(1){
	  if(op+2>vdis[x]) break;
	  op+=2;
	}
	if(op+1==vdis[x]) op++;
	ans=max(ans,op);
      }
      else
      */ 
      ans=max(ans,(lol)udis[x]+(vdis[x]-udis[x]));
      if(udis[x]==vdis[x]) continue;
    }
    for(int n=0;n<ca[x].size();n++){
      if(!vis[ca[x][n]]&&udis[x]+1<udis[ca[x][n]]){
	qu.push(ca[x][n]),udis[ca[x][n]]=udis[x]+1;
      }
    }
  }
  cout <<ans-1<<'\n';
  return (0);
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


struct Unionfind{
    vector<int> parents;
    int n;
    Unionfind(int n):n(n),parents(n,-1){ }

    int find(int x){
        if(parents[x] < 0) return x;
        else return parents[x] = find(parents[x]);
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x==y) return;
        if(parents[x] > parents[y]) swap(x,y);
        parents[x] += parents[y];
        parents[y] = x;
    }  

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

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

   vector<int> members(int x){
       int root = find(x);
       vector<int> member;
       for(int i=0;i<n;i++){
           if(find(i)==root){
               member.push_back(i);
           }
       }
      return member;
  }

  int group_cnt(){
      int c = 0;
      rep(i,n){
          if(parents[i] < 0) ++c;
      }
      return c;
  }
};

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

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0 && m == 0) break;
        vector<edge> eg;
        rep(i,m){
            int a,b,c;
            cin >> a >> b >> c;
            eg.push_back(edge{a,b,c});
        }

        sort(eg.begin(),eg.end(),[](const edge &l,const edge &r){
            return l.cost < r.cost;
        });

        Unionfind uf(n);
        int ans = 0;

        rep(i,eg.size()){
            if(uf.same(eg[i].from,eg[i].to)) continue;
            uf.unite(eg[i].from,eg[i].to);
            ans += eg[i].cost;
        }
        
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    double a;
    double d = 0.0;
    double answer = 0.0;
  
    for(int i = 0; i < N; i++) {cin >> a; d += 1/a;}
    
    answer = 1/d;
  
    // 出力
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>

using namespace std;

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

typedef pair<bool,int> parsed;

parsed formula(const string& t,int i)
{
	if(isupper(t[i]))
		return parsed(t[i]=='T',i+1);
	
	if(t[i]=='-'){
		parsed p=formula(t,i+1);
		p.first^=1;
		return p;
	}
	if(t[i]=='('){
		parsed p1=formula(t,i+1);
		int j=p1.second;
		if(t[j]=='-'){
			parsed p2=formula(t,j+2);
			return parsed(p1.first<=p2.first,p2.second+1);
		}
		parsed p2=formula(t,j+1);
		if(t[j]=='*')
			return parsed(p1.first&&p2.first,p2.second+1);
		if(t[j]=='+')
			return parsed(p1.first||p2.first,p2.second+1);
	}
	assert(false);
}

bool solve(string s)
{
	rep(bit,1<<11){
		string t;
		rep(i,s.size()){
			if(islower(s[i]))
				t+="FT"[bit>>s[i]-'a'&1];
			else
				t+=s[i];
		}
		parsed p1=formula(t.substr(0,t.find('=')),0);
		parsed p2=formula(t.substr(t.find('=')+1),0);
		if(p1.first!=p2.first){
			return false;
		}
	}
	return true;
}

int main()
{
	for(string s;cin>>s,s!="#";)
		cout<<(solve(s)?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 1240
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;}
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

/* }}} */

#define sq(x) ((x) * (x))

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

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

  while (n--){
    double x1, y1, x2, y2, x3, y3;
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);

    double a = 2 * (x1 - x2), b = 2 * (y1 - y2),
           c = 2 * (x1 - x3), d = 2 * (y1 - y3);
    double e = sq(x1) + sq(y1) - sq(x2) - sq(y2),
           f = sq(x1) + sq(y1) - sq(x3) - sq(y3);

    double x = (1 / (a * d - b * c)) * (d * e - b * f),
           y = (1 / (a * d - b * c)) * (-c * e + a * f);

    double r = sqrt(sq(x - x1) + sq(y - y1));
    printf("%.3f %.3f %.3f\n", x, y, r);
  }

  return 0;
}

Measured memory_bytes: 1248
import bisect

if __name__ == '__main__':
    n = int(input())
    a = [int(input()) for _ in range(n)]
    colors = [a[-1]]
    ans = 1
    for x in reversed(a[:-1]):
        i = bisect.bisect_left(colors, x + 1)
        if i == ans:
            ans += 1
            colors.append(x)
        else:
            colors[i] = x
    print(ans)


Measured memory_bytes: 8604