akhauriyash/Code-Regression huggingface dataset:
import sys

Tmp = []
N = int(input())

Tmp = input().rstrip().split(' ')

AllDis = 0
Data = [0 for i in range(N)]
TmpNow = 0


for i in range(N):
    TmpX = int(Tmp[i])
    TmpN = abs(TmpNow - TmpX)
    AllDis += TmpN
    
    if i+1 != N:
        TmpX2 = int(Tmp[i+1])
        TmpN2 = abs(TmpX2 - TmpX)
        Data[i] =  TmpN + TmpN2 - abs(TmpX2 - TmpNow) 
        TmpNow = TmpX
    else:
        TmpN2 = abs(0 - TmpX)
        AllDis += TmpN2
        Data[i] =  TmpN + TmpN2 - abs(0 - TmpNow)
        TmpNow = TmpX
        break

for i in range(N):
    Ans = AllDis - Data[i]
    print(Ans)


Measured memory_bytes: 15800
s = list(input())
n = len(s)
total = 0
for i in range(2 ** (n-1)):
    bag = []
    for j in range(n):
        if ((i >> j) & 1):
            bag.append(s[j])
            bag.append('+')
        else:
            bag.append(s[j])
        #print(bag)
    bag = ''.join(bag)
    #print(bag)
    for m in bag.split('+'):
        total += int(m)
print(total)

Measured memory_bytes: 40048
s = input()

cnt_n = s.count('N')
cnt_s = s.count('S')
cnt_e = s.count('E')
cnt_w = s.count('W')

p1 = ((cnt_n > 0) and (cnt_s > 0)) or ((cnt_n == 0) and (cnt_s == 0))
p2 = ((cnt_e > 0) and (cnt_w > 0)) or ((cnt_e == 0) and (cnt_w == 0))
print('Yes' if p1 and p2 else 'No')

Measured memory_bytes: 3064
def rec(N,k=0,tight=True,prev_0=True,_7=False, _5=False, _3=False):
    if k==len(N):
        if _7==True and _5==True and _3==True:
            return 1
        else:
            return 0  
    x=N[k]
    r=int(x)  
    if r<3 and tight:
        return 0
    #res = dp[k][0]+dp[k][1]
    res=0
    for i in [0,3,5,7]:
        if not prev_0 and i==0:
            continue
        if i==0:
            prev_0 = True
        else:
            prev_0 = False
        next_tight = tight and i==r
        next_3 = _3
        next_5 = _5
        next_7 = _7
        if tight:
            if i>r:
                return res
        if i==3:
            next_3=True
        elif i==5:
            next_5=True
        elif i==7:
            next_7=True
        temp_rec = rec(N,k+1,next_tight,prev_0,next_7,next_5,next_3)
        res+=temp_rec
    return res
N=input()
print(rec(N))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
class Sushi {
public:
  int t, d;
  bool operator<(const Sushi &that) const {
    if (d == that.d) return t < that.t;
    else return d < that.d;
  }
};
bool comp1(Sushi a, Sushi b) {
  if (a.d == b.d) return a.t < b.t;
  else return a.d > b.d;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<Sushi> ss(n);
  vector<bool> b(n, false);
  for (int i = 0; i < n; i++) {
    int t, d;
    cin >> t >> d;
    ss[i] = {t: t, d: d};
  }
  sort(ss.begin(), ss.end(), comp1);
  set<int> s;
  set<Sushi> uni;
  long long del = 0;
  for (int i = 0; i < n; i++) {
    if (s.find(ss[i].t) == s.end()) {
      s.insert(ss[i].t);
      uni.insert(ss[i]);
      b[i] = true;
      del += ss[i].d;
    }
    if (s.size() == k) break;
  }
  int cnt = s.size();
  for (int i = 0; i < n; i++) {
    if (cnt == k) break;
    if (!b[i]) {
      del += ss[i].d;
      uni.erase(ss[i]);
      b[i] = true;
      cnt++;
    }
  }
  vector<Sushi> sss;
  for (auto x: uni) {
    sss.push_back(x);
  }
  sort(sss.begin(), sss.end(), comp1);
  reverse(sss.begin(), sss.end());
  long long kind = s.size();
  long long ans = del + kind * kind;
  int idx = 0;
  for (int i = 0; i < sss.size(); i++) {
    del -= sss[i].d;
    kind--;
    while (idx < n && b[idx]) idx++;
    if (idx == n) break;
    del += ss[idx].d;
    b[idx] = true;
    if (ans > del + kind * kind) break;
    ans = del + kind * kind;
  }
  cout << ans << endl;
  return 0;
}

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

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

using ll = long long;
using namespace std;

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

    vector<pair<char, bool>> command;

    int q;
    cin >> q;
    rep (q, _) {
      int type;
      cin >> type;
      if ( type == 1 ) {
        command.emplace_back('\0', true);
      }
      else {
        int f;
        char c;
        cin >> f >> c;
        if ( f == 1 )
          command.emplace_back(c, true);
        else
          command.emplace_back(c, false);
      }
    }
    bool reversed = false;
    for (const auto & c : command) {
      if ( c.first == '\0' )
        reversed = !reversed;
      else {
        if ( c.second ^ reversed )
          s.insert(0, 1, c.first);
        else
          s.push_back(c.first);
      }
    }
    if ( reversed )
      reverse(s.begin(), s.end());

    cout << s << endl;
}


Measured memory_bytes: 1404
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		if (s.equals("Sunny"))
			System.out.println("Cloudy");
		else if (s.equals("Cloudy"))
			System.out.println("Rainy");
		else
			System.out.println("Sunny");

	}
}

Measured memory_bytes: 21844
#除くではなくて除かなくていい部分を選ぶ→各文字で考えず行・列単位で考える
h,w = list(map(int,input().split()))
a = [""] * h

for i in range(h):
    a[i] = input()
    
row = [False] * h
col = [False] * w

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j],end="")
        print()

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

using namespace std;

int main(){
    string s; getline(cin,s);
    if(s=="MON")cout<<"6\n";
    if(s=="TUE")cout<<"5\n";
    if(s=="WED")cout<<"4\n";
    if(s=="THU")cout<<"3\n";
    if(s=="FRI")cout<<"2\n";
    if(s=="SAT")cout<<"1\n";
    if(s=="SUN")cout<<"7\n";
}


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

int main()
{
   ll n,s=0;
   cin>>n;
   for(ll i=1;i<=n;i++)
   {
       if(i%5==0 and i%3==0)
       continue;
       if(i%5==0)
       continue;
       if(i%3==0)
       continue;
       s+=i;
   }
   cout<<s;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

ll ans=0;
ll n,m;

void dfs(Graph &G,ll now,vector<bool> &visit){
	bool stop=true;
	
	for(auto next:G[now]){
		if(visit[next]) continue;
		stop=false;

		visit[next]=true;
		dfs(G,next,visit);
		visit[next]=false;
	}

	if(stop){
		bool allpath=true;
		rep(i,n){
			if(!visit[i]){//行っていない頂点があるなら条件を満たさない
				allpath=false;
				break;
			}
		}
		if(allpath) ans++;
	}

	return;
}

int main(){
	cin>>n>>m;
	Graph G(n);
	rep(i,m){
		ll a,b;cin>>a>>b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<bool> visit(n,false);
	visit[0]=true;
	dfs(G,0,visit);

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

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

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

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D 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 inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    int n, k; cin >> n >> k;
    vi p(n); REP(i, n) cin >> p[i];

    sort(ALL(p));

    int ans = 0;

    REP(i, k) {
        ans += p[i];
    }

    print(ans);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define MOD 1000000007
#define pb push_back
#define int long long int

using namespace std;

int32_t main(void) {
    fast;
    int n; cin>>n;
    double x=0;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end() );
    x = a[0];
    for(int i=1; i<n; i++) x = (x + a[i])/2;
    cout<<x;
}



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

constexpr int64_t mod = 1'000'000'007; //'

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;

    int64_t dp = 1;
    int64_t over = 1;

    if(s[0] == 'W' || s[2*n-1] == 'W'){
        cout << 0 << endl;
        return 0;
    } 

    for(int i=1;i<2*n;i++){
        int stat = (s[i]=='B' ? 0 : 1);
        if((stat + over) % 2 == 1){
            dp = dp * over % mod;
            over--;
        }else{
            over++;
        }
    }

    int64_t fact = 1;
    for(int i=1;i<=n;i++) fact = i*fact % mod;
    if(over == 0){
        cout << dp*fact%mod << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 640
//インクルード(アルファベット順)
#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>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

bool setcontain(set<int> const& X,int const x){
std::set<int>::iterator itr=X.begin();
  for(int i=0;i<X.size();i++){
    if((*itr)==x){
      return 1;
    }
    itr++;
  }
  return 0;
}


signed main() {
ll N,M;
cin >> N >> M;
vector<set<int> > ks(M);
vector<int> p(M);
int tmp=0,in,ans=0;
for(int i=0;i<M;i++){
cin >> tmp;
for(int j=0;j<tmp;j++){
    cin >> in;
    ks.at(i).insert(in);
}
}
REP(i,M){
    cin >> p[i];
}
int count;
bool frag = true;   
for(int bit =0;bit<(1<<N);bit++){
    frag = true;
for(int i=0;i<M;i++){
    count =0;
for(int bits =0;bits<N;bits++){
    if(bit & (1 <<bits)){
     if(setcontain(ks.at(i),bits+1)){
     count ++;
     }
   }
}
if(count%2!=p[i]){
    frag = false;
}
}
if(frag){
    ans++;
}
}



answer(ans);
return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int ans = 0;
    int N; cin >> N;
    REP(i, N + 1)if (i / 10 == 0 || (i / 1000 == 0 && i / 100 != 0) || i / 100000 == 0 && i / 10000 != 0)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3600
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if((s[0]=='A'&&s[1]=='A'&&s[2]=='A')||(s[0]=='B'&&s[1]=='B'&&s[2]=='B')) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main()
{
  int N;
  scanf("%d",&N);
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    scanf("%lld",&A[i]);
  }
  priority_queue<pair<int, int>> pq;
  vector<ll> B(N);
  for(int i=0; i<N; i++){
    scanf("%lld",&B[i]);
    pq.push(make_pair(B[i], i));
  }

  ll cnt = 0;
  while (!pq.empty()) {
    pair<int, int> cur = pq.top(); pq.pop();
    int b = cur.second;
    int a = (b-1+N)%N;
    int c = (b+1)%N;
    ll ac = B[a]+B[c];

    if (B[b] == A[b]) continue;
    if (B[b] - ac < A[b]) {
      cout << -1 << endl;
      return 0;
    }

    ll tmp = (B[b]-A[b])/ac;
    B[b] -= ac*tmp;
    cnt += tmp;
    pq.push(make_pair(B[b], b));
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

typedef std::vector<std::vector<int>> graph;

bool isbipartite(int v, int par, int color, vector<int> &data, const graph &g) {
  if (data[v] != 0)
    if (data[v] != color) {
      return false;
    } else {
      return true;
    }
  data[v] = color;
  for (auto u : g[v]) {
    if (u == par)
      continue;
    if (!isbipartite(u, v, -color, data, g))
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) { cin >> s[i]; }

  graph g(n);
  REP(i, n) {
    REP(j, n) {
      if (s[i][j] == '1') {
        g[i].push_back(j);
      }
    }
  }

  vi c(n);
  if (!isbipartite(0, -1, 1, c, g)) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  REP(i, n) {

    queue<int> q;
    q.push(i);
    vector<bool> used(n);
    vi data(n, 0);
    data[i] = 1;
    while (!q.empty()) {
      auto v = q.front();
      q.pop();
      if (used[v])
        continue;
      used[v] = true;

      for (auto u : g[v]) {
        if (!used[u]) {
          data[u] = data[v] + 1;
          q.push(u);
        }
      }
    }
    REP(j, n) { ans = max(ans, data[j]); }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll INF=1e9+7;

int main(){
    ll a,b,c,x;
    cin >> a >> b >> c >> x;
    ll ans=0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    cout << ans << endl;
} 

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

int main() {
	int N,T;
	cin >> N >> T;
	int c[N],t[N];
	for(int i = 0;i<N;i++)
		cin >> c[i] >> t[i];
	int eff = -1;
	for(int i = 0;i<N;i++){
		if(t[i]<=T){
			if(c[i] < eff || eff == -1)
				eff = c[i];
		}
	}
	if(eff==-1)
		cout << "TLE" << endl;
	else
		cout << eff << endl;
	return 0;
}

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

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = true;
    int i = 0;
    while(flag){
        flag = false;
        for(int j = N - 1; j >= i + 1; --j){
            if(A[j] < A[j - 1]){
                swap(A[j], A[j - 1]);
                flag = true;
                ++sw;
            }
        }
        ++i;
    }
    return sw;
}

int main(void){
    int N;    cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    
    int sw = bubbleSort(A, N);
    
    rep(i, N - 1) cout << A[i] << " ";
    cout << A[N - 1] << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();

    List<Integer> list1 = new ArrayList<Integer>();
    List<Integer> list2 = new ArrayList<Integer>();

    for (int i = 0; i < n; i++) {
      list1.add(scanner.nextInt());
    }

    for (int i = 0; i < n; i++) {
      list2.add(scanner.nextInt());
    }

    int max = 0;
    int candies = 0;

    for (int i = 0; i < list1.size(); i++) {
      // list1は、iまでの要素の合計
      // list2は、i以降の要素の合計
      // list1
      for (int j = 0; j <= i; j++) {
        candies = candies + list1.get(j);
      }
      for (int k = i; k < list2.size(); k++) {
        candies = candies + list2.get(k);
      }

      if (max < candies) {
        max = candies;
      }

      candies = 0;
    }

    System.out.println(max);

  }

}

Measured memory_bytes: 23892
import java.util.*;


class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    Set<Integer> set = new HashSet<>();
    set.add(in.nextInt());
    set.add(in.nextInt());
    set.add(in.nextInt());
    System.out.println(set.size() == 2 ? "Yes" : "No");
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl


int main() {
    ll m,f,r,mfSum;
    while(1){
        cin >> m >> f >> r;
        if (m == -1 &&  f == -1 && r == -1){
            break;
        }
        mfSum = m + f;

        if (m == -1 || f == -1){
            cout << "F" << endl;     
        }
        else if(mfSum >= 80){
            cout << "A" << endl;            
        } else if (mfSum >= 65 && mfSum < 80){
            cout << "B" << endl;            
        } else if(mfSum >= 50 && mfSum < 65){
            cout << "C" << endl;            
        } else if(mfSum >= 30 && mfSum < 50){
            if(r >= 50){
                cout << "C" << endl;            
            } else {
                cout << "D" << endl;            
            }
        } else if(mfSum < 30){
            cout << "F" << endl;            
        }
    }

    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <complex>
#include <algorithm>
#define EPS 1e-10
#define EQ(a,b) ((a - b) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
using namespace std;

typedef complex<double> P;

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


    while (n--) {
        double ax, ay, ar, bx, by, br;
        cin >> ax >> ay >> ar >> bx >> by >> br;
        P a = P(ax, ay);
        P b = P(bx, by);

        double d = abs(a - b);
        if (d > ar + br) {
            cout << "0" << endl;
        } else if (d + ar <  br) {
            cout << "-2" << endl;
        } else if (d + br < ar) {
            cout << "2" << endl;
        } else {
            cout  << "1" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1240
/* Author:bhagatsunny96
         JGEC
	   template__
	lets_code_it_ */
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
#define loopr(n) for(long long int i=n-1;i>=0;i--)
#define lrp(a,b) for(long long int i=a;i<=b;i++)
#define lrn(a,b) for(long long int i=b;i>=a;i--)
#define endl '\n'
#define ivec vector<ll>
#define ivecp vector<pair<ll,ll>>
#define imap map<ll,ll>
#define uimap unordered_map<ll,ll>
#define iset set<ll>;
#define cvec vector<char>
#define civecp vector<pair<char,ll>>
#define cimap map<char,ll>
#define ucimap unordered_map<char,ll>
#define cset set<char>
using namespace std;
ll gcd(ll a, ll b)
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 }
 ll power(ll x, unsigned ll y) 
 { 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++) 
    {
       if(num%i==0) 
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) 
{ 
    return (a.first > b.first); 
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
string sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
   return str;
} 
void countSort(ll arr[], ll n, ll exp) 
{ 
	ll output[n];
	ll i, count[10] = {0}; 
	for (i = 0; i < n; i++) 
		count[ (arr[i]/exp)%10 ]++; 
	for (i = 1; i < 10; i++) 
		count[i] += count[i - 1]; 
	for (i = n - 1; i >= 0; i--) 
	{ 
		output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; 
		count[ (arr[i]/exp)%10 ]--; 
	} 
	for (i = 0; i < n; i++) 
		arr[i] = output[i]; 
} 
void radixsort(ll arr[], ll n) 
{
    ll mx = arr[0]; 
	for (ll i = 1; i < n; i++) 
		if (arr[i] > mx) 
			mx = arr[i];
	ll m =mx;
	for (ll exp = 1; m/exp > 0; exp *= 10) 
		countSort(arr, n, exp); 
} 
void print(ll arr[], ll n) 
{ 
    for (ll i = 0; i < n; i++) 
        cout << arr[i] << " "; 
} 
int main() 
{
    fIO
    string s;
    cin>>s;
    ll n=s.length();
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x,ans=10000;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        int p=0;
        while(x%2==0)
        {
            x/=2;
            p++;
        }
        ans=min(ans,p);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []; /* 空で配列定義 */  
var reader = require('readline').createInterface({ /* readlineライブラリの読み込みとメソッド */
    input: process.stdin, /*読み取り可能*/
    output: process.stdout /*読み取り可能*/
});

reader.on('line', function (line) {
    // ここで入力を処理する
    lines.push(line); /* linesにlineにpushで配列格納してる */
});
reader.on('close', function () {
    // ここで出力する
    for(var i =0; i<lines.length; i++){
      console.log(lines[i] * lines[i] * lines[i]);
    }
});


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){
    return (a%b+b)%b;
}
ll gcd(ll a, ll b){
    return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}
void Yes(){
    cout << "Yes" << endl;
}
void No(){
    cout << "No" << endl;
}
void Judge(bool b){
    b ? Yes() : No();
}
void YES(){
    cout << "YES" << endl;
}
void NO(){
    cout << "NO" << endl;
}
void JUDGE(bool b){
    b ? YES() : NO();
}
ll powmod(ll b, ll e){
    ll r = 1; while(e > 0) {if(e&1) r = (r%MOD)*(b%MOD)%MOD; b = (b%MOD)*(b%MOD)%MOD; e >>= 1;} return r;
}
double distance(ll x1, ll y1, ll x2, ll y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

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;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for(int i = 0; i < len; ++i) {
        s << v[i]; if(i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    }
} fastio;

int main(){

    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(m), d(m);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    rep(i, m){
        cin >> c[i] >> d[i];
    }

    rep(i, n){
        ll mn = LINF, idx = 0;
        rep(j, m){
            ll tmp = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(mn > tmp) {
                mn = tmp;
                idx = j+1;
            }
        }
        ppp(idx);
    }

    return 0;
}


Measured memory_bytes: 256
s=int(input())

A = []

def a(i):
    if i == 1:
        return s
    elif A[i-2]%2:
        return 3*A[i-2]+1
    else:
        return A[i-2]/2

i = 1

while True:
    if a(i) in A:
        print(i)
        break
    else:
        A.append(a(i))
        i += 1
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

const int Max = 1e6;
int like[Max];

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        like[i + 1] = a;
    }
    int ans = 0;
    rep(i, n)
        if(like[like[i + 1]] == i + 1) ans++;
    cout << ans / 2 << endl;
}

Measured memory_bytes: 640
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstring>
#include <iomanip>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 5e5 + 5;
const int M = 26;

string s;
int n, q;
int val[N];
int nxt[N][M];
int em[N][M];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> s;
	n = s.length();

	for (int i = 0; i < n; i++) {
		val[i] = s[i] - 'a';
	}

	for (int i = 0; i <= n + 1; i++) {
		for (int j = 0; j < M; j++) {
			em[i][j] = n + 1;
			nxt[i][j] = n + 1;
		}
	}

	for (int i = n - 1; i >= 0; i--) {
		nxt[i][val[i]] = i + 1;
		//cerr << "At " << i << ' ' << val[i] << ' ' << nxt[i][val[i]] << '\n';
		for (int j = val[i] + 1; j < M; j++) {
			nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
		}
		//cerr << "Next z at " << nxt[i][M - 1] << '\n';
		em[i][0] = nxt[nxt[i][M - 1]][M - 1];
		for (int j = 0; j < val[i]; j++) {
			nxt[i][j] = nxt[em[i][0]][j];
		}
	}

	/*for (int i = 0; i < n; i++) {
		cerr << em[i][0] << " \n"[i == n - 1];
	}*/

	for (int j = 1; j < M; j++) {
		for (int i = 0; i < n; i++) {
			em[i][j] = em[em[i][j - 1]][j - 1];
		}
	}

	cin >> q;

	while (q--) {
		int a, b;
		cin >> a >> b;
		a--;
		for (int j = M - 1; j >= 0; j--) {
			if (em[a][j] <= b) a = em[a][j];
			//cerr << a << ' ';
		}
		//cerr << '\n';
		cout << (a == b ? "Yes" : "No") << '\n';
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 104980
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans, surplus = 0, 0
for i in range(N):
    tmp = min(A[i], surplus)
    ans += tmp
    A[i] -= tmp
    if B[i] > A[i]:
        ans += A[i]
        surplus = B[i] - A[i]
    else:
        ans += B[i]
        surplus = 0
tmp = min(A[N], surplus)
ans += tmp
print(ans)

Measured memory_bytes: 18624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
from collections import defaultdict


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, src, dest, w=1):
        self.E[src].append((dest, w))
        self.E[dest].append((src, w))  # 無向グラフ


class UnionFind(object):
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):

    # ブロック関係
    block = Graph(N)
    for c, d in zip(C, D):
        block.add_edge(c-1, d-1)

    # 友好関係
    friendUF = UnionFind(N)
    degree = [0]*N
    for a, b in zip(A, B):
        friendUF.unite(a-1, b-1)
        degree[a-1] += 1
        degree[b-1] += 1

    # 友好的に連結している数を調べる
    group = defaultdict(int)
    for i in range(N):
        group[friendUF.root(i)] += 1

    ans = []
    for i in range(N):
        # iの連結している個数 - 次数 - 1 （自身を除く）
        # print(" -- {} --".format(i))
        # print(group[friendUF.root(i)], degree[i])
        ans.append(group[friendUF.root(i)] - degree[i] - 1)
        # ブロックを考慮する
        for dest, _ in block.E[i]:
            if friendUF.same(dest, i):
                ans[-1] -= 1
    print(*ans, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    C = [int()] * (K)  # type: "List[int]"
    D = [int()] * (K)  # type: "List[int]"
    for i in range(K):
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, M, K, A, B, C, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 85280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

const ll M = MOD;

vector<ll> fac(300001);
vector<ll> ifac(300001); 

ll mpow(ll x, ll n){ 
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCb
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

void init()
{
	fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M;
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; 
    }
}

int main(int argc, char **argv)
{
	ll N, P; cin >> N >> P;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	ll so{0}, sd{0};
	for (ll i = 0; i < N; ++i)
	{
		if (A[i] & 1)
			++so;
		else
			++sd;
	}

	if (so == 0)
	{
		if (P == 0)
		{
			ll res{1};
			for (ll i = 0; i < N; ++i)
				res *= 2;
			std::cout << res << std::endl;
		}
		else
			std::cout << 0 << std::endl;
	}
	else
	{
		ll res{1};
		for (ll i = 0; i < N-1; ++i)
			res *= 2;
		std::cout << res << std::endl;
	}
}

Measured memory_bytes: 4992
N,M=map(int,input().split())
edges=[]
for m in range(M):
  a,b,c=map(int,input().split())
  edges.append([a-1,b-1,-c])
inf=float("inf")
dist=[inf for i in range(N)]
dist[0]=0
dist_n=[inf for i in range(N)]
negative=[-1 for i in range(N)]
for i in range(N-1):
  for e in edges:
    if dist[e[1]]>dist[e[0]]+e[2]:
      dist[e[1]]=dist[e[0]]+e[2]  
for i in range(N):
  for e in edges:
    if negative[e[0]]>0:
      negative[e[1]]=1
    if dist[e[1]]>dist[e[0]]+e[2]:
      dist[e[1]]=dist[e[0]]+e[2]
      negative[e[1]]=1
if negative[N-1]>0: 
  print(inf)
else:
  print(-dist[N-1])
        
     
      


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

using namespace std;

int main(){
    int n;
    cin>>n;
    string ans="";
    while(n!=0){
        if(n%3==0)ans="0"+ans;
        if(n%3==1)ans="+"+ans;
        if(n%3==2){
            n=n+3;
            ans="-"+ans;
        }
        n=n/3;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    ll x;
    ll price = 100;
    ll count = 0;
    cin >> x;
    ll ans = 0;
    while (true){
        price = price * 1.01;
        price /= 1;
        count++;
        if (price >= x) {
            break;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
    	Scanner sn = new Scanner(System.in);
      	String n = sn.next();
      	int digits = 0;
      	int sum = 0;
      	for(int i = 0; i < n.length() ; i++) {
        	digits = Integer.parseInt(n.substring(i, i+1));
          	sum = sum + digits; 
        }
      	if(sum % 9 == 0) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 49580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> adj[100005];
ll mod = 1e9 + 7, dp[2][100005];
void dfs(int current, int parent)
{
	dp[0][current] = dp[1][current] = 1;
	for (int i = 0; i < adj[current].size(); ++i) {
		int next = adj[current][i];
		if (next == parent)
			continue;
		dfs(next, current);
		dp[0][current] = (dp[0][current] * ((dp[0][next] + dp[1][next]) % mod)) % mod;
		dp[1][current] = (dp[1][current] * dp[0][next]) % mod;
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a, b;
	while (--n) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1, 0);
	cout << (dp[0][1] + dp[1][1]) % mod << '\n';
	return 0;
}

Measured memory_bytes: 14208
#include<vector>
#include<iostream>
#include<algorithm>
#include<chrono>
#include<set>
#include<string>

using namespace std;


int main()
{
    long long n;
    cin >> n;
    string str = "";
    while(n){
        if(n%26){
            str.push_back(n%26+'a'-1);
        }
        else{
            str.push_back('z');
            n -= 26;
        }
        n /= 26;
    }
    reverse(str.begin(), str.end());
    cout << str;
}

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

const int N = 2005;

struct edge { int to, nxt; } e[N << 1];
int n, m, head[N], tot;

void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

typedef std::bitset<N> bitset;

int f[N], next[N][N], lca[N][N];

bitset path[N], sub[N];

void dfs(int x) {
	path[x].set(x), sub[x].set(x);
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f[x]) {
		path[e[i].to] = path[x], f[e[i].to] = x, dfs(e[i].to);
		for (int j = sub[e[i].to]._Find_first(); j < N; j = sub[e[i].to]._Find_next(j)) {
			next[x][j] = e[i].to;
			for (int k = sub[x]._Find_first(); k < N; k = sub[x]._Find_next(k))
				lca[j][k] = lca[k][j] = x;
		}
		sub[x] |= sub[e[i].to];
	}
}

bitset near[N], U;
std::queue<std::pair<int, int>> q;

int edge_num = 0;

void _link(int x, int y) {
	near[x].set(y), near[y].set(x), q.emplace(x, y), ++edge_num;
}

inline bitset get_path(int x, int y) {
	bitset ret = path[x] ^ path[y];	ret.set(lca[x][y]);
	return ret;
}
inline bitset subtree(int x, int y) {
	if (sub[x].test(y)) std::swap(x, y);
	if (sub[y].test(x)) return sub[x] | U ^ sub[next[y][x]];
	else return sub[x] | sub[y];
}
inline bitset get(int x, int y) {
	return subtree(x, y) | get_path(x, y);
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 1; i <= n; ++i) U.set(i), near[i].set(i);
	for (int i = 1, x, y; i < n; ++i)
		std::cin >> x >> y, link(x, y);
	dfs(1);
	for (int i = 0, x, y; i < m; ++i) std::cin >> x >> y, _link(x, y);
	while (q.size()) {
		auto tmp = q.front(); q.pop();
		bitset t = (near[tmp.first] ^ near[tmp.second]) & get(tmp.first, tmp.second);
		for (int x = t._Find_first(); x < N; x = t._Find_next(x)) {
			int v = near[tmp.first].test(x) ? tmp.second : tmp.first;
			_link(x, v);
		}
	}
	std::cout << edge_num << '\n';
	return 0;
}

Measured memory_bytes: 49588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;
    cin>>s;
    bool k=true;
    for(int x=1;x<s.length();x++)
    {
        if(s[x-1]==s[x])
            k=false;
    }
    if(k)
        cout<<"Good";
    else
        cout<<"Bad";
}


Measured memory_bytes: 256
from collections import Counter,defaultdict
import bisect

s = input()
t = input()
ss = s*2

S = Counter(s)
T = Counter(t)

for i in T.keys():
    if i not in S:
        print(-1)
        exit()

alpha = [[] for _ in range(26)]

for i,j in enumerate(ss):
    alpha[ord(j)-ord("a")].append(i)

rep,now = 0,-1

for i in t:
    alp = alpha[ord(i) - ord('a')]
    i = bisect.bisect_left(alp,now+1)
    now = alp[i]
    if now >= len(s):
        now -= len(s)
        rep += 1

print(rep*len(s)+now+1)

Measured memory_bytes: 12276
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<ll> x(N), y(N);
  for(int i=0; i<N; i++) cin >> x[i] >> y[i];
  
  vector<int> xi(N), yi(N);
  iota(xi.begin(), xi.end(), 0);
  iota(yi.begin(), yi.end(), 0);
  sort(xi.begin(), xi.end(), [&](int i, int j){return x[i]<x[j];});
  sort(yi.begin(), yi.end(), [&](int i, int j){return y[i]<y[j];});
  
  multiset<tuple<ll, int, int>> s;
  for(int i=1; i<N; i++){
    s.emplace((x[xi[i]] - x[xi[i-1]]), xi[i], xi[i-1]);
    s.emplace((y[yi[i]] - y[yi[i-1]]), yi[i], yi[i-1]);
  }
  
  UnionFind tree(N);
  int n, i, j;
  ll ans = 0;
  for(auto t: s){
    tie(n, i, j) = t;
    if(tree.same(i, j)) continue;
    tree.unite(i, j);
    ans += n;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    if(s.size() < t.size()){
        cout << "UNRESTORABLE";
        return 0;
    }
    bool pos = false;
    for(int i = 0; i <= s.size() - t.size(); i++){
        bool flag = true;
        for(int j = 0; j < t.size(); j++){
            flag &= (s[i + j] == '?' || s[i + j] == t[j]);
        }
        if(flag){
            for(int j = 0; j < t.size(); j++){
                s[i + j] = t[j];
            }
            pos = true;
            break;
        }
    }
    if(!pos){
        cout << "UNRESTORABLE";
        return 0;
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '?'){
            s[i] = 'a';
        }
    }
    reverse(s.begin(), s.end());
    cout << s;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
 
 
    void solve()
    {
        var S = cin.next;
        int A = S[0] - '0';
        int B = S[1] - '0';
        int C = S[2] - '0';
        int D = S[3] - '0';
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                for (int k = 0; k < 2; k++)
                {
                    int sum = A;
                    sum += (i == 0) ? B : -B;
                    sum += (j == 0) ? C : -C;
                    sum += (k == 0) ? D : -D;
                    if (sum == 7)
                    {
                        Write(S[0]);
                        Write(i == 0 ? "+" : "-");
                        Write(S[1]);
                        Write(j == 0 ? "+" : "-");
                        Write(S[2]);
                        Write(k == 0 ? "+" : "-");
                        Write(S[3]);
                        WriteLine("=7");
                        return;
                    }
                }
            }
        }
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
data = [0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

index = int(input())

print(data[index])



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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    ll x,y; cin >> x >> y;
    ll ans = 0;
    ll now = x;
    while(true) {
        if(now > y) {
            break;
        } else {
            ans++;
            now*=2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256