akhauriyash/Code-Regression huggingface dataset:
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
ll mod=1000*1000*1000+7;
set<string> S;
int main() {
    cout.precision(10);
    cout<<fixed;
    int N;
    cin>>N;
    REP(i,N) {
        string t;
        cin>>t;
        S.insert(t);
    }
    cout<<S.size()<<endl;
}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


Measured memory_bytes: 19228
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll dp[2][10000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll P = 2019;
    mod = P;
    string S;
    cin >> S;
    ll ans = 0;
    if (P == 2 || P == 5) {
        REP(i, 0, S.size()) {
            ll num = S[i] - '0';
            if (num % P == 0) {
                ans += i + 1;
            }
        } 
    } else {
        reverse(S.begin(), S.end());
        ll ten = 1;
        map<ll, ll> mp;
        ll now = 0;
        REP(i, 0, S.size()) {
            ll num = S[i] - '0';
            now = modadd(now, multiply(num, ten));
            if (now == 0) {
                ans++;
            }
            ans += mp[now];
            mp[now]++;
            ten = multiply(ten, 10);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
	int n; cin >> n;
	vector<int> a(n);
	for(auto &i : a){
		cin >> i;
	}
	sort(all(a), greater<int>());
	int ans = 0;
	for(int i = 1; i < n; ++i){
		ans += a[i/2];
	}
	cout<<ans<<'\n';
}

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


Measured memory_bytes: 4792
#pragma GCC optimize("O3")

#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;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#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())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,k;

bool sim(vector<int> &arr) {
    vector<int> tmp(sz(arr),0);
    F0R(i,n) {
        int l=max(0,i-arr[i]);
        int r=min(sz(arr),i+arr[i]+1);
        tmp[l]++;
        if(r<sz(arr))
            tmp[r]--;
    }
    FOR(i,1,n)
        tmp[i]+=tmp[i-1];
    bool res=true;
    F0R(i,n) {
        if(tmp[i]<n)
            res=false;
    }
    arr=tmp;
    return res;
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    vector<int> arr(n);
    F0R(i,n)
        cin >> arr[i];
    while(k) {
        bool res=sim(arr);
        k--;
        if(res)
            break;
    }
    F0R(i,n)
        cout << arr[i] << " ";

    return 0;
}


Measured memory_bytes: 4936
/*
 * Author:  heyuhhh
 * Created Time:  2020/6/22 14:05:49
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int n, m, k;
struct node {
    int x, y;
    int cost;
    int r;
    int dir;
    bool operator < (const node& A) const {
        if (cost == A.cost) return r > A.r;
        return cost > A.cost;
    }
};

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

void run() {
    cin >> n >> m >> k;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    --sx, --sy;
    --ex, --ey;
    vector <string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    priority_queue <node> q;
    vector <vector <vector <int>>> dis(n, vector <vector <int>>(m, vector <int>(4, INF)));
    vector <vector <vector <bool>>> vis(n, vector <vector <bool>>(m, vector <bool>(4, false)));
    for (int i = 0; i < 4; i++) {
        dis[sx][sy][i] = 0;
        q.push(node{sx, sy, 0, 0, i});
    }
    while (!q.empty()) {
        node now = q.top(); q.pop();
        int x = now.x, y = now.y;
        int cost = now.cost, r = now.r;
        int dir = now.dir;
        if (vis[x][y][dir]) continue;
        vis[x][y][dir] = true;
        dis[x][y][dir] = cost + (r > 0 ? 1 : 0);
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] != '@') {
                if (d == dir && r < k) {
                    q.push(node{nx, ny, cost, r + 1, d});
                } else {
                    q.push(node{nx, ny, cost + 1, 1, d});
                }
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < 4; i++) {
        ans = min(ans, dis[ex][ey][i]);
    }
    if (ans == INF) ans = -1;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 199556
#include <bits/stdc++.h>
#define maxn 1000006
using namespace std;
long long n, a[maxn], d = 0, luu1[maxn], luu2[maxn],absmx = INT_MIN, absmn = INT_MIN;
void print()
{
    cout << d << '\n';
    for (int i = 1; i <= d; i++)
    {
        cout << luu1[i] << ' ' << luu2[i] << '\n';
    }
}
void trau()
{
    a[0] = INT_MIN;
    int chot, chot2;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > 0)
        {
            if (absmx < abs(a[i]))
            {
                absmx = abs(a[i]);
                chot = i;
            }
        }
        else
        {
            if (absmn < abs(a[i]))
            {
                absmn = abs(a[i]);
                chot2 = i;
            }
        }
    }

    if (absmx > absmn)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[j] < 0)
            {
                a[j] += absmx;
                luu1[++d] = chot; luu2[d] = j;
            }
        }
    }

    else
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[j] > 0)
            {
                a[j] -= absmn;
                luu1[++d] = chot2, luu2[d] = j;
            }
        }
    }

    if (a[1] <= 0)
    {
        for (int i = n; i >= 1; i--)
        {
            if (a[i] > a[i + 1])
            {
                a[i] += a[i + 1];
                luu1[++d] = i + 1; luu2[d] = i;
            }
        }
    }

    else
    {
        for (int i = 1; i <= n; i++)
        {
            if (a[i] < a[i - 1])
            {
                a[i] += a[i - 1];
                luu1[++d] = i - 1; luu2[d] = i;
            }
        }
    }
}
int main()
{
    //freopen ("test.inp", "r", stdin);
    //freopen ("test.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    trau();
    print();
}


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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp

int KnapsackProblem(int N,int W,vector<int> v,vector<int> w) {
  vector<int> dp(W+1,0);
  for(int i=0;i<N;++i) {
    for(int j=0;j<=W-w[i];++j) {
      dp[j+w[i]] = max(dp[j+w[i]],dp[j]+v[i]);
    }
  }
  return dp[W];
}

int main() {
  int N,W;
  cin >> N >> W;
  vector<int> v(N),w(N);
  for(int i=0;i<N;++i) cin >> v[i] >> w[i];
  cout << KnapsackProblem(N,W,v,w) << endl;
  return 0;
}

Measured memory_bytes: 1252
N, *A = map(int, open(0).read().split())
MOD = 1_000_000_007
ans = 0
for i in range(64):
    p, q, = 0, 0
    for a in A:
        if a >> i & 1:
            p += 1
        else:
            q += 1
    ans += pow(2, i, MOD) * p * q
    ans %= MOD
print(ans)

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

int main(){
    int N,K;cin>>N>>K;
    vector<int> P;
    for(int i = 0;i < N;i++){
        int _a;cin>>_a;_a--;
        P.push_back(_a);
    }
    vector<ll> C;
    for(int i = 0;i < N;i++){
        ll _a;cin>>_a;
        C.push_back(_a);
    }

    vector<bool> visited(N, false);
    vector<ll> accum(2*N,0);
    vector<int> accum2(N,0);
    ll result = -10000000000000;
    for(int _vis = 0;_vis < N;_vis++){
        int vis = _vis;
        if(visited[vis])continue;
        // ll cur = 0;
        // int route = 0;
        int pathlen = 0;
        vis = P[vis];
        while(true){
            visited[vis] = true;
            if(pathlen == 0){
                accum[pathlen] = C[vis];
            }else{
                accum[pathlen] = accum[pathlen - 1] + C[vis];
            }
            pathlen++;
            vis = P[vis];
            if(visited[vis])break;
        }
        for(int i = pathlen;i < 2*pathlen;i++){
            // cout<<accum[i-pathlen]<<" ";
            accum[i] = accum[pathlen-1] + accum[i % pathlen];
        }
        // cout<<accum[pathlen]<<endl;
        // cout<<pathlen<<endl;
        // cout<<"-"<<endl;
        for(int start = 0;start <= pathlen;start++){
            for(int end = start+1;end < 2*pathlen;end++){
                if(end - start > K)break;
                ll cost = accum[end] - accum[start];
                // cout<<start<<" "<<end<<" "<<cost<<endl;
                if(accum[pathlen -1] > 0 && K - (end - start) >= pathlen){
                    cost += accum[pathlen -1] * ((K - (end - start)) / pathlen);
                }
                if(result < cost){
                    result = cost;
                }
            }
        }
        // cout<<"------"<<endl;

    }
    cout<<result<<endl;
}

Measured memory_bytes: 3752
import sys
import bisect
input = sys.stdin.readline

N = int(input())

p = N
s = set()
s.add(p)
c = 1

while True:
    if p % 2 == 0:
        p = p // 2
    else:
        p = p * 3 + 1
    c += 1
    if p in s:
        print(c)
        break
    else:
        s.add(p)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        d[i]--;
    }
    vector<vector<int>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }
    vector<lint> sub(n, 1);
    function<void(int, int)> dfs = [&](int c, int p) {
        for (auto &v : edges[c]) {
            if (v == p)
                continue;
            dfs(v, c);
            sub[c] += sub[v];
        }
    };
    dfs(0, -1);
    vector<lint> col(n, 0);
    vector<lint> in(n, 0);
    vector<lint> minus(n, 0);
    function<void(int, int)> dfs2 = [&](int c, int p) {
        col[d[c]] += sub[c];
        in[c] = col[d[c]];
        for (auto &v : edges[c]) {
            if (v == p)
                continue;
            dfs2(v, c);
            lint rem = sub[v] - (col[d[c]] - in[c]);
            minus[d[c]] += rem * (rem + 1) / 2;
            col[d[c]] = in[c];
        }
    };
    dfs2(0, -1);
    for (int i = 0; i < n; ++i) {
        lint rem = n - (col[i]);
        minus[i] += rem * (rem + 1) / 2;
    }
    for (auto &m : minus) {
        cout << n * (n + 1) / 2 - m << "\n";
    }
    return 0;
}

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
mint choose(int n,int a){
  mint x = 1,y=1;
  rep(i,a){
    x*= n-i;
    y*= i+1;
  }
  return x/y;
}
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  mint ans=2;
  ans=ans.pow(n);
  ans-=1;
  ans-=choose(n,a);
  ans-=choose(n,b);
  cout<<ans.x<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H , W;
  cin >> H >> W;
  for(int i = 0 ; i < W + 2 ; i++){
    cout << "#";
  }
  cout << endl;
  for(int i = 0 ; i < H ; i++){
    cout << "#";
    for(int j = 0 ; j < W ; j++){
      char a;
      cin >> a;
      cout << a;
    }
    cout << "#" << endl;
  }
  for(int i = 0 ; i < W + 2 ; i++){
    cout << "#";
  }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int M,T,P,R;
  int m,t,p,j;
  int s[55][4];
  int mp[55][10];
  // s 0=solve 1=time 2=penalty 3=number
  while(1){
    cin>>M>>T>>P>>R;
    if(M==0 && T==0 && P==0 && R==0) break;
    rep(i,55){
      rep(j,4){
	if(j!=3) s[i][j]=0;
	else s[i][j]=i;
      }
    }
    rep(i,55){
      rep(j,10){mp[i][j]=0;}
    }
    rep(i,R){
      cin>>m>>t>>p>>j;
      if(j!=0) mp[t][p]++;
      else{
	s[t][1]+=m+mp[t][p]*20;
	s[t][0]++;
      }
    }
    repi(i,1,T+1){
      int a=i;
      while(1){
	if(a==1) break;
	else if(s[a][0]>s[a-1][0]){swap(s[a],s[a-1]);a--;}
	else if(s[a][0]==s[a-1][0] && s[a][1]<s[a-1][1]){swap(s[a],s[a-1]);a--;}
	else if(s[a][0]==s[a-1][0] && s[a][1]==s[a-1][1] && s[a][3]>s[a-1][3]){swap(s[a],s[a-1]);a--;}
	else break;
      }
    }
    repi(i,1,T+1){
      cout<<s[i][3];
      if(i==T) cout<<endl;
      else{
	if(s[i][0]==s[i+1][0] && s[i][1]==s[i+1][1]) cout<<"=";
	else cout<<",";
      }
    }
  }
  
    
  return 0;
}





Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 20;


int main(){
  string S;
  cin >> S;
  int count1 = 0, count2 = 0;
  rep(i, S.length()){
    if(i % 2 == 0){
      if(S[i] == '1') count1++;
    }else{
      if(S[i] == '0') count1++;
    }
  }

  rep(i, S.length()){
    if(i % 2 == 0){
      if(S[i] == '0') count2++;
    }else{
      if(S[i] == '1') count2++;
    }
  }
  cout << min(count1, count2) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<set>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )

set<string> P;

bool exist(string s){
    for ( set<string>::iterator it = P.begin(); it != P.end(); it++ ){
	if ( s.size() <= (*it).size() && s == (*it).substr(0, s.size())) 
	    return true;
    }
    return false;
}

bool convert(string s, string &t){
    bool f;
    int p, e;

    if ( s.size() >= 2 && s.substr(s.size()-2, 2) == "/." ) s = s.substr(0, s.size()-1);

    for(; (p = s.find("/./")) != string::npos; s.replace(p+1, 2, ""));
    for(; (p = s.find("/..")) != string::npos; ){
	if ( exist(s.substr(0, p+1)) && p){
	    for ( e = p+3, p--; s[p] != '/'; p--);
	    s.replace(p, e-p, "");
	} else return false;
    }
    t = s;
    if ( P.find(t) != P.end()) return true;
    t += (t[t.size()-1]=='/')?"index.html":"/index.html";
    if ( P.find(t) != P.end()) return true;

    return false;
}

main(){
    int N, M;
    string path, t1, t2;
    while( cin >> N >> M && (N || M) ){
	P.clear();
	rep(i, N) { cin >> path; P.insert(path); }
	rep(i, M){
	    cin >> t1 >> t2;
	    string c1, c2;
	    if ( convert(t1, c1) && convert(t2, c2) ){
		cout << ((c1==c2)?"yes":"no") << endl;
	    } else {
		cout << "not found" << endl;
	    }
	}
    }
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(char x : s) if(x == '1') ++ans;
  cout << ans << endl;
  
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    string ans;
    for (int i = 0;i < s.size();i++){
        if (s[i] == '0'){
            ans += '0';
        }
        else if(s[i] == '1'){
            ans += '1';
        }
        else if(s[i] == 'B'){
            if (ans.empty()){
                continue;
            }
            else{
                ans.pop_back();
            }
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int N = 1000007, inf = 0x3f3f3f3f;

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

    int ok = 1;
    for(int i = 0; i < n; ++i) {
        int a; cin >> a;

        if(a%2 == 0) {
            ok = ok and (a%3 == 0 or a%5 == 0);
        }
    }

    cout << (ok? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
import numpy as np
Nmax = 10**5

N = int(input())
h = [int(x) for x in input().split()]

dp = np.zeros(Nmax + 1)

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]))

print(int(dp[N-1]))

Measured memory_bytes: 23092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

vector<vi> g, tree;
vi w;
vector<bool> can_back;
vi mx;

bool get_can_back(int v)
{
	bool res = false;
	if (tree[v].size() + 1 < g[v].size()) res = true;
	for (auto u : tree[v])
	{
		if (get_can_back(u)) res = u;
	}
	return can_back[v] = res;
}

int get_max(int v)
{
	if (mx[v] >= 0) return mx[v];
	int res = 0;
	for (auto u : tree[v])
	{
		chmax(res, get_max(u));
	}
	return mx[v] = res + w[v];
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m;
	cin >> n >> m;
	w.resize(n); cin >> w;
	g.resize(n); tree.resize(n); can_back.resize(n); mx.resize(n, -1);
	REP(i, m)
	{
		int u, v; cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<int> que;
	vector<bool> vis(n);
	vis[0] = true;
	que.push(0);
	while (!que.empty())
	{
		int v = que.front();
		que.pop();
		for (auto u : g[v])
		{
			if (vis[u]) continue;
			vis[u] = true;
			tree[v].push_back(u);
			que.push(u);
		}
	}
	for (auto v : tree[0])
	{
		get_can_back(v);
	}
	int ans = w[0];
	int fin = 0;
	FOR(i, 1, n)
	{
		if (can_back[i]) ans += w[i];
		else
		{
			chmax(fin, get_max(i));
		}
	}
	cout << ans + fin << endl;
	return 0;
}

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

using namespace std;

int main(){
  
  vector<char> A(3);
  for( int i=0; i<3; i++){
    cin >> A[i];
    if( A[i] == '7' ){
      printf("Yes\n");
      return 0;
    }
  }
      printf("No\n");
      return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main() {
	int max=1, min=10000000000;
	int N,A;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> A  ;
		if (A > max) max = A;
		if (A < min)min = A;
	}
	cout << max - min << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
sumb = 0
ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))
ab.sort()
for i in ab:
    a = i[0]
    b = i[1]
    sumb += b
    if sumb >= K:
        print(a)
        break


Measured memory_bytes: 27872
import java.util.Scanner

fun main(args: Array<String>) {
  val cin = Scanner(System.`in`)
  val n = cin.nextInt()
  var s = IntArray(n)
  var res = 0
  var minNum = 101

  for (i in 1..n) {
    val num = cin.nextInt()
    s[i - 1] = num
    res += num
    if (num < minNum && num % 10 != 0) {
      minNum = num
    }
  }

  if (res % 10 != 0) {
    println(res)
  } else if (minNum == 101) {
    println(0)
  } else {
    println(res - minNum)
  }

  cin.close()
}

Measured memory_bytes: 31400
#include<iostream>
using namespace std;
int main(){
  int N,W;
  cin>>N>>W;
  W+=1;
  int value[N];
  int weight[N];
  int data[W];
  for(int i=0;i<N;i++){
    cin>>value[i]>>weight[i];
  }
  for(int i=0;i<W;i++){
    data[i]=0;
  }
  for(int i=0;i<N;i++){
    for(int j=W-1;j>=0;j--){
      if(j-weight[i]>=0){
        if(data[j]<=data[j-weight[i]]+value[i])
          data[j]=data[j-weight[i]]+value[i];
      }
    }
  }
  int max=0;
  for(int i=0;i<W;i++){
    if(max<data[i])
      max=data[i];
  }
  cout<<max<<endl;
  return 0;
}



Measured memory_bytes: 3120
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int x = stdIn.nextInt();
	int a = stdIn.nextInt();
	int b = stdIn.nextInt();
	if(Math.abs(x-a)>Math.abs(x-b)){
	    System.out.println("B");
	}else{
	    System.out.println("A");
	}
    }
}


Measured memory_bytes: 21716
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
int main(){
    string s;cin>>s;
    int k=s.length(),sum=0;
    for(int i=0;i<k;i++){
        if(s[i]=='o') sum++;
    }
    if(sum+15-k>=8)     cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

   
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s[1] == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
import itertools
n = int(input())
s = input()
a = [""] * (n+1)
r = ["S", "W"]

def rev(st):
  if st == "W":
    return "S"
  else:
    return "W"

for i in list(itertools.product(r, r)): 
  a[0] = i[0]
  a[1] = i[1]
  for j in range(1, n): 
    if s[j] == "o":
      if a[j] == "S":
        a[j+1] = a[j-1]
      else:
        a[j+1] = rev(a[j-1])
    else:
      if a[j] == "S":
        a[j+1] = rev(a[j-1])
      else:
        a[j+1] = a[j-1]
  if a[0] == a[-1]:
    if s[0] == "o":
      if a[0] == "S":
        if a[1] == a[-2]:
          print("".join(a[:-1]))
          exit()
      else:
        if a[1] != a[-2]:
          print("".join(a[:-1]))
          exit()
    else:
      if a[0] == "S":
        if a[1] != a[-2]:
          print("".join(a[:-1]))
          exit()
      else:
        if a[1] == a[-2]:
          print("".join(a[:-1]))
          exit()
print(-1)
    

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int bs(int sum){
    int lo = 0;
    int hi = sum;
    int ans = -1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        if(mid*(mid+1) <= 2*sum){
            ans = mid;
            lo = mid+1;
        }
        else{
            hi = mid-1;
        }
    }
    return ans;
}
ll n;
void solve(){
    cin >> n;
    if(n==1){
        cout << 0 << '\n';
        return;
    }
    vector<ll> factors;
    ll s = sqrt(n);
    int ans = 0;
    for(int i = 2; i <= s; i++){
        if(n%i==0) factors.push_back(i);
        if((ll)i * (ll)(n/i) == n && n%(n/i)==0) factors.push_back(n/i);
    }
    factors.push_back(n);
    
    sort(factors.begin(), factors.end());
    
    for(ll i : factors){
        //cout << i << " ";
        int times = 0;
        while(n%i==0){
            n/=i;
            times++;
        }
        ans += bs(times);
    }//cout << '\n';
    
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3664
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
	p,y=map(int,input().split())
	pys[i]=(p,y,i)
pys.sort(key=lambda x:x[1])

num=[0]*n
ans=[0]*m
for p,y,i in pys:
	num[p-1]+=1
	ans[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for a in ans:
	print(a)

Measured memory_bytes: 29768
KEY = "keyence"

def main():
    s = input()

    if s.startswith(KEY) or s.endswith(KEY):
        print("YES")
        return

    for i in range(1, len(KEY)):
        st = KEY[0:i]
        ed = KEY[i:]

        if s.startswith(st) and s.endswith(ed):
            print("YES")
            return

    print("NO")

main()


Measured memory_bytes: 9112
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	vector<char> r(26, '*'), rr(26, '*');
	rep(i, s.size()) {
		if (r.at(s.at(i) - 'a') == '*') {
			r.at(s.at(i) - 'a') = t.at(i);
		}
		else {
			if (r.at(s.at(i) - 'a') != t.at(i)) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (rr.at(t.at(i) - 'a') == '*') {
			rr.at(t.at(i) - 'a') = s.at(i);
		}
		else {
			if (rr.at(t.at(i) - 'a') != s.at(i)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 916
from itertools import combinations
from operator import mul
from functools import reduce

N = int(input())
S = [input() for _ in range(N)]

def make_count_list(names):
    firsts = list(map(lambda x: x[0], names))
    counts = []
    for c in "MARCH":
        counts.append(firsts.count(c))
    return counts

def main():
    counts = make_count_list(S)
    comb_num = 3
    ans = 0
    for comb in combinations(counts, comb_num):
        ans += reduce(mul, comb)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11112
n, a, b = map(int,input().split())
k = 0
ans = []
for i in range(n+1):
    s = str(i)
    array = list(map(int, list(s)))
    result = sum(array)
    k = k+1
    if a <= result and result <= b:
        ans.append(i)
print(sum(ans))


Measured memory_bytes: 3424
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h; cin >> h;
    ll tmp = 1, ans = 0;
    while (h > 0) {
        ans += tmp;
        tmp *= 2;
        h /= 2;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
const int N=1005;
int n,m,a[N][N],l;
void clr(int x,int y,int v){
	for (int i=x,j=y;i<=l;i++,j--) a[i][j]=v;
}
int main(){
	scanf("%d",&n); m=((n+3)/4)*4;
	if (n==1) return printf("1\n1\n"),0;
	l=m/2; int x=1,y=l;
	rep (t,1,l){
		for (int i=x,j=y;i<=l;i++,j--) a[i][j]=2*t-(i&1);
		y++;
	}
	if (n%4!=0){
		if (n%4<=3) clr(1,2*l-1,n);
		if (n%4<=2) clr(1,2*l-2,n-1);
		if (n%4<=1) clr(1,2*l-3,n-2);
	}
	rep (i,1,l) rep (j,1,l) if (!a[i][j]) a[i][j]=a[i][j+l];
	printf("%d\n",l);
	rep (i,1,l){rep (j,1,l) printf("%d ",a[i][j]); puts("");}
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdlib>
using namespace std;
 
int main() {
  string str;
  int size,count = 1,ans = 0,xx[100] = {0};
  char x[100];
  while(cin >> str) {
    char x[100] = {' '};
    int xx[100] = {0};
    size = str.size();
    for(int i=0;i<size;i++) {
      x[i] = *str.substr(i,1).c_str();
      if(x[i] == 'I') {
        xx[i] = 1;
      }
      else if(x[i] == 'V') {
        xx[i] = 5;
      }
      else if(x[i] == 'X') {
        xx[i] = 10;
      }
      else if(x[i] == 'L') {
        xx[i] = 50;
      }
      else if(x[i] == 'C') {
        xx[i] = 100;
      }
      else if(x[i] == 'D') {
        xx[i] = 500;
      }
      else if(x[i] == 'M') {
        xx[i] = 1000;
      }
    }
 
    for(int i=0;i<size-1;i++) {
      if(xx[i] >= xx[i+1]) {
        ans += xx[i];
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
      else if(xx[i] < xx[i+1]) {
        ans -= xx[i];
 
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
    }
    if(size == 1) {
      ans += xx[0];
        }
    cout << ans << endl;
    ans = 0;
  }
}

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

int main() {
  string s, ans = "";
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    switch (s[i]) {
      case '0':
        ans.push_back('0');
        break;
      case '1':
        ans.push_back('1');
        break;
      case 'B':
        if (ans.size() == 0) break;
        ans.pop_back();
        break;
    }
  }
  cout << ans << endl;
}

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

bool is_it_a_num(char a) {
  if (a == '0') return true;
  if (a == '1') return true;
  if (a == '2') return true;
  if (a == '3') return true;
  if (a == '4') return true;
  if (a == '5') return true;
  if (a == '6') return true;
  if (a == '7') return true;
  if (a == '8') return true;
  if (a == '9') return true;
  else return false;
}

int main(){ 
    int A, B;
  string S;
  
  cin >> A >> B >> S;
  
  bool flag = true;
  
  rep(i,A) {
    if (!is_it_a_num(S[i])) flag = false;
  }
  if (S[A] != '-') flag = false;
  rep(i,B) {
    if (!is_it_a_num(S[A+1+i])) flag = false;
  }
  
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;



}


Measured memory_bytes: 256
def main():
  import collections 
  n=int(input())
  v=tuple(map(int,input().split()))
  a,b=collections.Counter(v[::2]).most_common(),collections.Counter(v[1::2]).most_common()
  if len(a)==len(b)==1:
    print(n//2 if a==b else 0)
  else:
    print(n+(-a[0][1]-b[0][1] if a[0][0]!=b[0][0] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1])))
if __name__=='__main__':
  main()

Measured memory_bytes: 20696
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  long long int n,W;
  cin>>n>>W;
  long long int w[n],v[n];
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
  }
  long long int dp[n+1][W+1];
  for(int i=0;i<=n;i++)
    for(int j=0;j<=W;j++)
    {
      if(i==0)
        dp[i][j]=0;
      if(j==0)
        dp[i][j]=0;
    }
    
    
  for(int i=1;i<=n;i++)
    for(int j=1;j<=W;j++)
    {
      if(w[i-1]>j)
        dp[i][j]=dp[i-1][j];
      else
      dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
     }
   cout<<dp[n][W] ;
    
}

Measured memory_bytes: 82436
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

vector <int> E[100010];
int vis[100010];
int color[100010];

int dfs(int x, int c){
	int res = 1;
	vis[x] = 1, color[x] = c;
	for(int e : E[x]){
		if(vis[e] == 0)res &= dfs(e, 3-c);
		else if(color[e] != 3 - c)res = 0;
	}
	return res;
}

int deg[100010];

void solve(){
	int n, m; cin >> n >> m;
	ll ans = 0;
	rep(i, m){
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(y);
		E[y].pb(x);
		deg[x]++, deg[y]++;
	}
	int a = 0, b = 0;
	for(int i=1;i<=n;i++)if(deg[i] > 0 && !vis[i]){
		++a;
		b += dfs(i, 1);
	}
	ans = (ll)n * n;
	int c = 0;
	for(int i=1;i<=n;i++)if(deg[i] > 0)++c;
	ans -= (ll)c * c;
	ans += (ll)a * a + (ll)b * b;
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; // scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 10752
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [x, y] <- map (read::String -> Integer) . words <$> getLine
  print $ countPower x y


countPower::Integer -> Integer -> Integer
countPower x y = if x > y then 0 else 1 + countPower (2 * x) y

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

const int MAX = 2 * 1e5 + 1; // 適宜


ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



void mainsolve(){

	ll n,k;
	cin >> n >> k;

	COMinit();

	ll res = 0;
	for(ll i = 0; i <= min(k,n); i++){
		ll tmp = (COM(n,i) * COM(n-1,n-i-1)) % MOD;

		(res += tmp) %= MOD;
	}

	cout << res << endl;

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static List<string> lunlun;
        static Dictionary<string, List<string>> digits;

        static void Main(string[] args)
        {
            //[summary]D - Lunlun Number
            int K = int.Parse(Console.ReadLine());

            if (K < 10)
            {
                Console.WriteLine(K);
            }
            else
            {
                //1ケタのルンルン数(1～9)をListに追加
                GetFirstDigit();

                //各ケタの数字の右隣に来る可能性のある数字をリストアップ
                //(隣り合うどの2つの桁の値についても、差の絶対値が1以下)
                GetDigits();

                Console.WriteLine(GetLunLunNumber(K));
            }            
        }

        static string GetLunLunNumber(int K)
        {
            var count = lunlun.Count;

            while (true)
            {
                var copy = new List<string>(lunlun);
                lunlun.Clear();

                foreach (var c in copy)
                {
                    var key = c.Substring(c.Length - 1, 1);

                    foreach (var d in digits[key])
                    {
                        lunlun.Add(c + d);

                        count++;

                        if (count == K)
                        {
                            return c + d;
                        }
                    }
                }
            }
        }

        static void GetDigits()
        {
            digits = new Dictionary<string, List<string>>();

            for (int i = 0; i <= 9; i++)
            {
                var values = new List<string>();

                for (int j = -1; j <= 1; j++)
                {
                    if (i + j >= 0 && i + j <= 9)
                    {
                        values.Add((i + j).ToString());
                    }
                }

                digits.Add(i.ToString(), values);
            }
        }

        static void GetFirstDigit()
        {
            lunlun = new List<string>();

            for (int i = 1; i <= 9; i++)
            {
                lunlun.Add(i.ToString());
            }
        }
    }
}


Measured memory_bytes: 23004
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S >> T;
	int N = S.length();

	int ans = 0;
	rep(i, 0, N) if (S[i] != T[i]) ans++;
	cout << ans << endl;
}







Measured memory_bytes: 3740
N = int(input())
Sss = [input() for _ in range(N)]

adjL = [[] for _ in range(N)]
for i, Ss in enumerate(Sss):
    for j, S in enumerate(Ss):
        if S == '1':
            adjL[i].append(j)

def check(vSt):
    vs = set([vSt])
    useds = [False] * (N)
    useds[vSt] = True
    depth = 0
    while vs:
#        print(depth, vs)
        v2s = set()
        for v in vs:
            for v2 in adjL[v]:
                if not useds[v2]:
                    v2s.add(v2)
                    useds[v2] = True
        for u in v2s:
            for v in v2s:
                if Sss[u][v] == '1':
                    return -1
        vs = v2s
        depth += 1
    return depth

ans = -1
for v in range(N):
    ret = check(v)
    if ret != -1:
        ans = max(ans, ret)

print(ans)


Measured memory_bytes: 43884