akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int answer = (int)Math.pow((double)N, 3.0);
        os.println(answer);
    }
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long  A, B, N;
	cin >> A >> B >> N;

	long long ans = 0;

	/*for (int x = 1; x <= N; x++) {
		int num = (int)(A * x / B) - A * (int)(x / B);
		int num2 = 
		if (ans < num)ans = num;
	}*/

	long long x = B-1;
	if (x >= N)x = N;
	long long num = (int)(A * x / B) - A * (int)(x / B);
	if (ans < num)ans = num;
	
	cout << ans;
	
}

Measured memory_bytes: 3624
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  minj=i
  for j in range(i+1,n):
    if a[j]<a[minj]:
      minj=j
  a[i],a[minj]=a[minj],a[i]
  if minj!=i:
    ans+=1

print(*a)
print(ans)



Measured memory_bytes: 5608
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

int A, B;
int nCr[4002][4002], nCrT[4002][4002];
int dp[4002][4002];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  nCr[0][0] = 1;
  for (int i=1; i<=4000; i++) {
    nCr[i][0] = 1;
    for (int j=1; j<=i; j++) {
      nCr[i][j] = (nCr[i-1][j-1] + nCr[i-1][j]) % MOD;
    }
  }
  for (int i=0; i<=4000; i++) {
    for (int j=0; j<=i; j++) {
      add(nCrT[i][j], nCr[i][j]);
      if (j > 0) add(nCrT[i][j], nCrT[i][j-1]);
    }
  }
  dp[0][0] = 1;
  for (int n=1; n<=4000; n++) {
    for (int k=1; k<=4000; k++) {
      add(dp[n][k], nCrT[k-1][min(k-1, n-k)]);
    }
  }
  rep(n, 4001) rep(k, 4001) add(dp[n+1][k], dp[n][k]);

  cin >> A >> B;
  int s = 1; // RR...BB
  for (int pos=B; pos<A+B; pos++) {
    for (int b=1; b<=B; b++) {
      add(s, (1LL*nCr[B-1][b-1]*dp[A+B-pos][B-b]) % MOD);
    }
  }
  cout << s << "\n";
  return 0;
}


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

//---------------------------------------------------------------
// ------ disjoint set ------ //
struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);  // par -> child とは限らない
            data[x] += data[y]; data[y] = x; __size--;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
    vector<int> subset_roots() {
        vector<int> roots;
        for (int i = 0; i < data.size(); i++) if (data[i] < 0) roots.push_back(i);
        return roots;
    }
};
//---------------------------------------------------------------

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n * 2);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        uf.unionSet(a, b + n);
        uf.unionSet(a + n, b);
    }
    if (uf.findSet(0, n)) {
        cout << 1LL * n * (n - 1) / 2 - m << endl;
    } else {
        int cnt = 0;
        for (int i = 0; i < n; i++) if (uf.findSet(0, i)) cnt++;
        cout << 1LL * cnt * (n - cnt) - m << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n;
	cin>>n;
	ll lo=pow(10,6),hi=(-pow(10,6)),x0,y0;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		if(lo>x)
			lo=x,y0=i+1;
		if(hi<x)
			hi=x,x0=i+1;
	}
	cout<<2*n-1<<"\n";
	if(hi+lo>=0){
		for(ll i=1;i<=n;i++)
			cout<<x0<<" "<<i<<"\n";
		for(ll i=1;i<n;i++)
			cout<<i<<" "<<i+1<<"\n";
	}
	else{
		for(ll i=1;i<=n;i++)
			cout<<y0<<" "<<i<<"\n";
		for(ll i=n;i>1;i--)
			cout<<i<<" "<<i-1<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3784
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int h, w;
    vector<pair<int, int> > x;
    while (1)
    {
        cin >> h >> w;
        if (h == 0)
        {
            break;
        }
        int diagonal = h * h + w * w;
        int maximam = (w + 1) * (w + 1) * (w + 1) * (w + 1);
        int mi_h = h, mi_w = w;
        int w_i = w;

        for (int i = h; i >= 1; i--)
        { // hを縮めてwを伸ばす
            int bigger_dig = i * i + w_i * w_i;
            if (bigger_dig <= maximam && bigger_dig > diagonal)
            {
                maximam = bigger_dig;
                mi_h = i;
                mi_w = w_i;
                // cout << i << " " << w_i << " " << bigger_dig << endl;
            }
            if (bigger_dig <= diagonal)
            {
                w_i++;
                i++; // iをもう一回やる
            }
        }
        w_i = w;
        for (int i = h+1; i<w; i++){// hをw以下に伸ばしながらwも狭めていく
            int bigger_dig = i * i + w_i * w_i; // hをw以下に伸ばす
            // cout << i << " " << w_i << " " << bigger_dig << endl;
            if(i>=w_i) break;
            if (bigger_dig < maximam && bigger_dig >= diagonal)
            {
                maximam = bigger_dig;
                mi_h = i;
                mi_w = w_i;
                w_i--;
                i--; // iを元に戻す
            } else if (bigger_dig == maximam && i < mi_h){
                maximam = bigger_dig;
                mi_h = i;
                mi_w = w_i;
                w_i--;
                i--; // iを元に戻す
            }else if(bigger_dig>maximam){
                w_i--;
                i--; // iを元に戻してwを小さくする
            }
            if(bigger_dig<diagonal){
                w_i++;
            }
        }

        x.push_back(make_pair(mi_h, mi_w));
    }
    for (int i = 0; i < x.size(); i++)
    {
        cout << x[i].first << " " << x[i].second << endl;
    }
}



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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)




vector<queue<int>> arr(200000,queue<int>());
vector<int> val(200000,0);
void taishoadd(int n){
    while(!arr[n].empty()){
        int x=arr[n].front();
        val[x]+=val[n];
        arr[n].pop();
        taishoadd(x);
    }
    return;
}

int main() {
    int N,Q,x,y;
    cin >>N>>Q;


    rep(i,N-1){
        cin >> x>>y;
        arr[x-1].push(y-1);
    }
    rep(i,Q){
        cin>>x>>y;
        val[x-1]+=y;
    }
    taishoadd(0);

    cout << val[0];
    repd(i,1,N) cout<<" " << val[i];
    cout <<endl;


    return (0);
}

Measured memory_bytes: 146944
<?php
list($A, $B, $Q) = array_map("intval", explode(" ", trim(fgets(STDIN))));

$aArray[] =-10**18;
for($i = 0; $i < $A; $i++)$aArray[] = intval(fgets(STDIN));
$aArray[] = 10**18;

$bArray[] =-10**18;
for($i = 0; $i < $B; $i++)$bArray[] = intval(fgets(STDIN));
$bArray[] = 10**18;
 
for($i = 0; $i < $Q; $i++){
    $q = intval(fgets(STDIN));
    $min = 10**18;
    $a = bsl($aArray, $q);
    $b = bsl($bArray, $q);
    foreach([[[$aArray, $a], [$bArray,$b]], [[$bArray, $b], [$aArray,$a]]] as list(list($aa, $_a), list($bb, $_b))){
        foreach([$aa[$_a], $aa[$_a+1]] as $a1){
            $p3 = $bb[$_b];
            $p4 = $bb[$_b+1];
            $min = min($min, abs($q - $a1) + abs($a1 - $p3));
            $min = min($min, abs($q - $a1) + abs($a1 - $p4));
        }
    }
    printf("%d\n", $min);
}
 
//二分探索　target以下で最大の値の場所を返す
function bsl($nums, $target) {
    $size = count($nums);
    $min = 0; 
    $max = $size - 1;
    while(true){
        $center = intdiv($min + $max, 2);
        $centerValue = $nums[$center];
        if($target == $centerValue){
            return $center;
        }elseif($target > $centerValue){
            $min = $center + 1;
        }else{
            $max = $center;
        }
        if($min == $max){
            $center = intdiv($min + $max, 2);
            $centerValue = $nums[$center];
            if($centerValue == $target){
                return $center;
            }elseif($centerValue < $target){
                return $center;
            }else{
                return $center - 1;
            }
        }
    }
}

Measured memory_bytes: 14836
#!/usr/bin/env python3
import sys


def solve(x: int, a: int, b: int):
    print("A" if abs(a - x) < abs(b - x) else "B")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(x, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long;
#define dbg(x) cout<<#x<<"--------------"<<x<<endl;
#define dl cout<<"LINE"<<__LINE__<<endl;
using namespace std;
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;int a[999999];
    cin>>n;
    for(int i=2;i<=n;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<endl;
    }





    return 0;
}


Measured memory_bytes: 4396
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    int ans = 0;
    rep(s,1<<h) rep(t,1<<w){
        auto c2 = c;
        rep(i,h){
            if((s>>i)&1){
                rep(j, w) c2[i][j]='.';
            }
        }

        rep(j,w){
            if((t>>j)&1){
                rep(i, h) c2[i][j] = '.';
            }
        }

        int cnt = 0;
        rep(i, h) rep(j, w) if (c2[i][j] == '#')++ cnt;
        if (cnt == k) ++ans;
    }

    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int X[200100];
int main()
{
	int N;
    cin>>N;
    for(int i=1;i<N;i++)
    {
    	int Y;
        cin>>Y;
        X[Y]++;
    }
    for(int i=1;i<=N;i++){
    	cout<<X[i]<<endl;}
	return 0;
}


Measured memory_bytes: 4344
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const ll Mod = 1e9 + 7;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}

int main()
{
//	GOAT();	
	ll n, k;
	cin >> n >> k;
	if (n % k == 0)cout << 0 << endl;
	else cout << min(n%k,k-(n-(n/k)*k))<< endl;

}

Measured memory_bytes: 256
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 08, 2020 2:24 PM
 *    Problem Name  : B - Common Raccoon vs Monster
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc153/tasks/abc153_b
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);
    
    ll h,n,sum=0;
    cin >> h >> n;

    ll arr[n+1];
    for(ll i=0; i<n; i++){
        cin >> arr[i];
        sum += arr[i];
    }

    if(h <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0 ;
}


Measured memory_bytes: 4424
n, w = int(input()), list(map(int, input().split()))
l, r = 0, sum(w)
ans = 10 ** 8
for i in range(len(w)):
    l += w[i]
    r -= w[i]
    tmp = abs(l - r)
    if tmp < ans:
        ans = tmp
print(ans)

Measured memory_bytes: 3064
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        PriorityQueue<Long> q = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++)
            q.add(sc.nextLong());
        for (int i = 0; i < m; i++)
            q.add(q.poll() / 2);

        long ans = 0;
        for (long x : q)
            ans += x;

        System.out.println(ans);
        sc.close();
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  REP(i,s.size())if(i%2==0)putchar(s[i]);puts("");
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    string s;
    cin >> s;
    if(s.find("RRR") != string::npos)cout << 3 << endl;
    else if(s.find("RR") != string::npos)cout << 2 << endl;
    else if(s.find("R") != string::npos)cout << 1 << endl;
    else cout << 0 << endl;
}




Measured memory_bytes: 3228
#a, b, m = list(map(int, input().split()))
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
import math
H, W = list(map(int, input().split()))
 
ans = math.ceil(W/2) * (math.ceil(H/2))
ans += (W // 2) * (H//2)

if H == 1 or W == 1:
  ans = 1
 
print(ans)



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/22  Problem: ABC 055 D / Link: http://abc055.contest.atcoder.jp/tasks/abc055_d  ----- */


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

	LL N; cin >> N;
	string s; cin >> s;
	VVI state(4, VI(N, -1));
	// -1:unset, 0:sheep, 1:wolf
	FOR(k, 0, 4) {
		FOR(i, 0, 2) {
			state[k][i] = (k > 1) ^ (i&k);
		}
	}
	FOR(k, 0, 4) {
		FOR(i, 1, N - 1) {
			int L = (i - 1 + N) % N;
			int R = (i + 1) % N;
			if (state[k][i] == 0) { // sheep
				state[k][R] = (s[i] == 'o' ? state[k][L] : !state[k][L]);
			}
			else {
				state[k][R] = (s[i] == 'o' ? !state[k][L] : state[k][L]);
			}
		}
	}
	FOR(k, 0, 4) {
		bool ok = 1;
		FOR(i, 0, N) {
			int L = (i - 1 + N) % N;
			int R = (i + 1) % N;
			if (state[k][i] == 0) {
				ok &= (s[i] == 'o' ? state[k][L] == state[k][R] : state[k][L] != state[k][R]);
			}
			else {
				ok &= (s[i] == 'o' ? state[k][L] != state[k][R] : state[k][L] == state[k][R]);
			}
		}
		if (ok) {
			FOR(i, 0, N) {
				cout << "SW"[state[k][i]];
			}cout << endl;
			return 0;
		}

	}

	cout << (-1) << "\n";

	return 0;
}


Measured memory_bytes: 2384
#include<bits/stdc++.h>
#define cmax(a,b) a=max(a,b)
using namespace std;
typedef long long ll;
const ll N=20,V=(1ll<<15)+20,B=(ll)1e15;
ll n,m,sx,S=0,ans;
ll f[N][V],h[V],e[N][N];
int main()
{
	ll i,j,ns,vs,hsx,u,v,w;
	scanf("%lld%lld",&n,&m);
	sx=1<<n;
	for(i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&u,&v,&w);u--;v--;
		e[u][v]=e[v][u]=w;
		for(ns=0;ns<sx;ns++)
		{
			if((ns&(1<<u))&&(ns&(1<<v))) h[ns]+=w;	
		}
		S+=w;
	}
	memset(f,-0x3f,sizeof(f));
	f[0][1]=0;
	for(ns=1;ns<sx;ns++)
	{
		for(i=0;i<n;i++)
		{
			if((ns&(1<<i))==0) continue;
			if(f[i][ns]<-B) continue;
			//printf("#%lld %lld  %lld\n",i,ns,f[i][ns]);
			hsx=(sx-1)^ns;
			if(hsx>0)
			{
				for(vs=hsx;vs;vs=(vs-1)&hsx)
				{
					cmax(f[i][ns|vs],f[i][ns]+h[vs|(1<<i)]);
				}
			}
			for(j=0;j<n;j++)
			{
				if((ns&(1<<j))||e[i][j]==0) continue;
				cmax(f[j][ns|(1<<j)],f[i][ns]+e[i][j]);
			}
		}
	}
	//printf("P%lld\n",f[n-1][sx-1]);
	ans=S-f[n-1][sx-1];
	printf("%lld",ans);
	return 0;
}

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

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

  long i = 0;
  bool flg = true;
  if(b == 1){
    flg = false;
    cout << 0 << endl;
  }
  
  while(flg){
    long c;
    i++;
    if(i == 1){
      c = a;
    }else{
      c = a * i - (i - 1);
    }
    if(c >= b){
      cout << i << endl;
      flg = false;
      break;
    }
  }
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

poss = [0]
for i in A:
    tmp_poss = poss.copy()
    for j in poss:
        tmp_poss.append(i + j)
    poss = tmp_poss
poss.remove(0)

for i in m:
    if poss.count(i) >= 1:
        print("yes")
    else:
        print("no")




Measured memory_bytes: 47144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)

ll n,x,y,p[100010]={},dp[100010][2]={};
vector<ll> v[100010]={};
bool f[100010][2]={},vis[100010];

const ll MOD=1e9+7;
ll ad(ll x,ll y=0){
  return (x+y)%MOD;
}
ll mlt(ll x,ll y=1){
  return (x*y)%MOD;
}

void dfs(ll i,ll pa=0){
  dp[i][0]=dp[i][1]=1;
  for(auto it=v[i].begin();it!=v[i].end();it++){
    if (*it!=pa){
      dfs(*it,i);
      dp[i][0]=mlt(dp[i][0],dp[*it][0]+dp[*it][1]);
      dp[i][1]=mlt(dp[i][1],dp[*it][0]);
    }
  }
}

int main(){
  cin>>n;
  Fr(i,n-1){cin>>x>>y;v[x].pb(y);v[y].pb(x);}
  dfs(1);
  cout<<ad(dp[1][0],dp[1][1])<<endl;
}

Measured memory_bytes: 12800
//write for s26

#include<bits/stdc++.h>
using namespace std;
int main() {
	bool pr=0;
	long long n,ans=0;
	cin>>n;
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	for(int i=2;i<=sqrt(n);i++) {
		if(n%i==0) {
			pr=1;
			break;
		}
	}
	if(pr==0) {
		cout<<1<<endl;
		return 0;
	}
	for(int i=2;i<=min(n,(long long)1000000);i++) {
		int j=i;
		while(n%j==0) {
			ans++;
			n/=j;
			j*=i;
		}
		while(n%i==0) {
			n/=i;
		}
	}
	if(n>=1000000) {
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int ans=1,m=1;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ans*=3;
    if(a[i]%2==0){
      m*=2;
    }
  }
  cout << ans-m << endl;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var N = input[0][0];
    var K = parseInt(input[1][0], 10);
    var l = N.length;
    var ans = 0;
    for (var i = 1; i < l; i++){
        if (i < K) continue;
        if (i === K){
            ans += Math.pow(9, K);
        }
        if (i > K){
            if (K === 1) ans += Math.pow(9, K);
            if (K === 2) ans += Math.pow(9, K) * (i - 1);
            if (K === 3) ans += Math.pow(9, K) * (i - 1) * (i - 2) / 2;
        }
    }

    var v = N.split("").map(e => parseInt(e, 10));
    var whereToStart = l;
    for (var i = 1; i < l; i++){
        if (v[i] !== 0) {
            whereToStart = i;
            break;
        }
    }
    if (K === 1) var addAns = (v[0]);

    if (K === 2){
        var addAns = (v[0] - 1) * 9 * (l - 1);
        for (var i = whereToStart; i < l; i++){
            if (i === whereToStart) {
                addAns += v[i];
                // console.log("here");
            }
            else addAns += 9;
        }
    }
    if (K === 3){
        var addAns = (v[0] - 1) * 81 * (l - 1) * (l - 2) / 2;
        for (var i = whereToStart; i < l; i++){
            var flag1 = false;
            for (var j = i + 1; j < l; j++){
                // console.log("ij", i, j);
                if (i === whereToStart){
                    if (j === whereToStart + 1) {
                        addAns += (v[i] - 1) * 9 + v[j];
                        // console.log("?");
                    }
                    else if (!flag1) {
                        addAns += (v[i] - 1) * 9 + v[j];
                    } else {
                        addAns += (v[i]) * 9;
                    }
                    if (!flag1 && v[j] !== 0) flag1 = true;
                } else { 
                    addAns += 81;
                }
                // console.log(addAns);
            }
        }
    }
    ans += addAns;

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 29572
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef pair<int, pair<int, pair<int, int>>> PP;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;

const long long INF = 1LL << 60;
const int inf = 1e9;
const long long MOD = 1e9+7;

int dp[100005] = {};

int main() {
	ll n, x, m;
	ll MEMORY=-1;
	cin >> n >> x >> m;
	dp[x] = 1;
	vector<ll> v;
	v.push_back(x);
	ll memo = x;
	bool flg = true;
	rep(i,n-1) {
		memo = (memo * memo) % m;
		if (dp[memo]) { 
			rep(j, v.size()) {
				if (v[j] == memo) {
					MEMORY = j;
					break;
				}
			}
			break; 
		}
		dp[memo] = 1;
		v.push_back(memo);
	}
	if (MEMORY != -1) {
		ll total = 0;
		ll cnt = v.size() - MEMORY;
		rep(i, cnt) {
			total += v[i + MEMORY];
		}
		ll T = 0;
		rep(i, MEMORY) {
			T += v[i];
		}
		n -= MEMORY;
		ll t = n / cnt;
		ll s = n - t * cnt;
		ll TOTAL = 0;
		rep(i, s) {
			TOTAL += v[i + MEMORY];
		}
		ll ans = T + total * t + TOTAL;
		cout << ans << endl;
	}
	else {
		ll ans = 0;
		rep(i,v.size())ans += v[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4304
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc.chars().into_iter().filter(|&c| c == 'x').count() < 8;
    println!("{}", if s { "YES" } else { "NO" });
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int K, X;
    cin >> K >> X;
    cerr << K << " " << X << " " << X - K + 1 << X + K  << "\n";
    for (int i = X - K + 1; i < X + K; i++) {
        if(i == X + K - 1) cout << i << "\n";
        else cout << i << " ";

    }

}

Measured memory_bytes: 3608
#coding:utf-8
import itertools

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

l = []

for n in range(N):
    l.append(int(input()))

result = 10000000

'''
upper_A = min([abs(A - length) for length in l])
upper_B = min([abs(B - length) for length in l])
upper_C = min([abs(C - length) for length in l])
'''


def get_min(A,target):
    if len(A)==1:
        MP = min([abs(target-l[a]) for a in A])
    else:
        MP = 1000000
        for n in range(1,len(A)+1):
            for c in itertools.combinations(A, n):
                MP = min(MP, abs(target - sum([l[i] for i in c])) + 10 * (n-1))
    return MP


for i in range(3**N):
    shugo = {}
    for n in range(N):
        shugo[n] = int(i / 3**(n)) % 3

    index_A = [k for k,s in shugo.items() if s==0]
    if len(index_A)==0:
        continue
    index_B = [k for k,s in shugo.items() if s==1]
    if len(index_B)==0:
        continue
    index_C = [k for k,s in shugo.items() if s==2]
    if len(index_C)==0:
        continue

    result = min(result,get_min(index_A,A)+get_min(index_B,B)+get_min(index_C,C))

print(result)    

    

Measured memory_bytes: 3064
#include <iostream>
    #include <vector>
    #include <deque>
    #include <algorithm>
    #include <string>
    #include <string.h>
     
    using namespace std;
    
	char S[100001];

    int main()
    {
        cin >> S;
		size_t L = strlen(S);
     
        char* p = S;
		char* E = S + L;
        while (p < E) {
            if (strncmp(p, "dreamera", 8) == 0) { // dream
                p += 5;
            } else if (strncmp(p, "dreamer", 7) == 0) {
                p += 7;
            } else if (strncmp(p, "eraser", 6) == 0) {
                p += 6;
            } else if (strncmp(p, "dream", 5) == 0 || strncmp(p, "erase", 5) == 0) {
                p += 5;
            } else {
                break;
            }
        }
     
        cout << (p == E ? "YES" : "NO") << endl;
     
        return 0;
    }

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

int main(){
    int x,a,b;

    cin >> x >> a >> b;

    if(abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}





void test_case() {

    
    

   string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    rep(qi, q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            swap(s, t);
        } else {
            int f; char c;
            cin >> f >> c;
            if (f == 1) {
                t += c;
            } else {
                s += c;
            }
        }
    }
 
    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;




}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 4024
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;

void Main(int argc, char** argv) {
    int m,d;
    cin>>m>>d;
    int ans = 0;
    rep(j, m+1) {
        if (j == 0) continue;
        rep(i,d+1) {
            if(i <= 10) continue;
            int d10 = i / 10;
            int d1 = i % 10;
            if (d10 <= 1 || d1 <= 1) continue;
            if (j == d1 * d10) {
                ans++;
                // debug(m);
                // debug(d1);
                // debug(d10);
            }
        }
    }
    cout << ans << endl;
}

signed main(int argc, char** argv) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main(argc, argv);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
        {
            cnt=1;
        }
        if(a[i]=='F'&&cnt==1)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
def main():
  import itertools
  s=list(input())
  n=len(s)
  t=[ s[i//2] if i%2==0 else None for i in range(2*n-1)]

  for i in itertools.product("+-", repeat=3):
    k=t
    for j in [0,1,2]:
      k[2*j+1]=i[j]
    l="".join(k)
    if eval(l)==7:
      print(l+"=7")
      exit()
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
template <int N> struct DSU {
    int fa[N], sz[N];
    void init() {
        iota(fa, fa + N, 0);
        fill(sz, sz + N, 1);
    }
    int seek(int x) { return fa[x] == x ? x : fa[x] = seek(fa[x]); }
    void merge(int a, int b) {
        int f1 = seek(a), f2 = seek(b);
        if (f1 != f2) {
            fa[f1] = f2;
            sz[f2] += sz[f1];
        }
    }
    DSU() { init(); }
};
DSU<maxn> dsu;
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        dsu.merge(a, b);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, dsu.sz[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>

using namespace std;

//long long MOD = 1000000007;

int main()
{

    int n;
    cin >> n;
    std::vector<int> a, b, c;

    for (size_t i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        t--;
        a.push_back(t);
    }
    for (size_t i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        b.push_back(t);
    }
    for (size_t i = 0; i < n - 1; i++)
    {
        int t;
        cin >> t;
        c.push_back(t);
    }

    int s = 0;
    int prev = -10;
    for (auto eated : a) {
        s += b[eated];
        if (prev + 1 == eated) {
            s += c[eated - 1];
        }
        prev = eated;
    }
    std::cout << s << std::endl;
    return 0;
}




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

vector<long long> a;

int main(){
  long long K;
  cin >> K;
  
  for(int i = 1;i < 10;i++)  a.push_back(i);
  int index = 0;
  long long tmp;
  int last;
  while(a.size() < K){
    tmp = a[index];
    last = tmp % 10;
    if(last == 0){
      a.push_back(tmp * 10 + last);
      a.push_back(tmp * 10 + last + 1);
    }
    else if(tmp % 10 == 9){
      a.push_back(tmp * 10 + last - 1);
      a.push_back(tmp * 10 + last);
    }
    else{
      a.push_back(tmp * 10 + last - 1);
      a.push_back(tmp * 10 + last);
      a.push_back(tmp * 10 + last + 1);
    }
    ++index;
  }
  
  //for(int i = 0;i < a.size();i++)  cout << a[i] <<  " ";
  cout << a[K - 1] << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
class UnionFind{
    private:
        vector<ll> par;
        vector<ll> siz;
    public:
        UnionFind(ll sz){
            par.resize(sz);
            siz.assign(sz,1LL);
            rep(i,sz) par[i] = i;
        }

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

        void unite(ll x,ll y){
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (siz[x] < siz[y]) swap(x,y);
            siz[x] += siz[y];
            par[y] = x;
        }

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

        ll size(ll x){
            return siz[find(x)];
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x,y;
    cin >> n >> m;
    vector<P> b;
    rep(i,m){
        cin >> x >> y;
        --x;
        --y;
        b.push_back(P(x,y));
    }
    vector<ll> can(m+1,0);
    UnionFind g(n);
    rep(i,m){
        tie(x,y) = b[m-i-1];
        if (g.same(x,y)) can[i+1] = can[i];
        else can[i+1] = can[i]+g.size(x)*g.size(y);
        g.unite(x,y);
    }
    ll cnt = 0;
    reverse(all(can));
    rep(i,m){
        PRINT(n*(n-1)/2-can[i+1]);
    }
}



Measured memory_bytes: 5232
#include <iostream>
#include <cmath>

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

    int n;
    std::cin >> n;
    
    for (; n--;) {
        int h, m;
        char tmp;
        std::cin >> h >> tmp >> m;

        double angle_h, angle_m, diff;

        angle_h = 30. * h + 0.5 * m;
        angle_m = 6. * m;
        diff = std::abs(angle_h - angle_m);

        if (diff > 180.) {
            diff = 360. - diff;
        }

        if (diff < 30.) {
            std::cout << "alert" << std::endl;
        }
        else if (diff < 90.) {
            std::cout << "warning" << std::endl;
        }
        else {
            std::cout << "safe" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

import static java.lang.Long.max;
import static java.lang.Math.min;

/**
 * Created by shoya on 2017/04/14.
 */
public class Main {
    final int INF = 100_000_000;

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

        PriRSQ rsq = new PriRSQ(n);
        for (int i = 0; i < q; i++){
            int com = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (com == 0)
                rsq.add(x, y);
            else
                System.out.println(rsq.getSum(x, y + 1));

            //System.out.printf("%d %d %d\n", com, x, y);
            //rsq.print();
            //System.out.println("\n");
        }
    }


    public static class PriRSQ {
        long nodes[];
        int size;

        PriRSQ(int n){
            int c = 1;
            while (n >= c) c *= 2;
            nodes = new long[2 * c - 1];
            size = c;
            for (int i = 0; i < 2 * c - 1; i++)
                nodes[i] = 0;
        }

        public void add(int node, int val){
            int child = node + size - 1;
            nodes[child] += val;
            while (child != 0){
                child = (child - 1) / 2;
                nodes[child] = nodes[child * 2 + 1] + nodes[child * 2 + 2];
            }
        }

        public long getSum(int queryl, int queryr){
            return getSum(queryl, queryr, 0, 0, size);
        }


        private long getSum(int queryl, int queryr, int root, int left, int right){
            //System.out.printf("%d <--> %d - %d <--> %d - Val %d\n", queryl, queryr, left, right, root);
            if (right <= queryl || queryr <= left)
                return 0;
            if (queryl <= left && right <= queryr)
                return nodes[root];

            long vl = getSum(queryl, queryr, root * 2 + 1, left, (left + right) / 2);
            long vr = getSum(queryl, queryr, root * 2 + 2, (left + right) / 2, right);
            return vl + vr;
        }

        void print(){
            int tmp = 1;
            for (int i = 0; i < 2 * size - 1; i++){
                if (i == tmp) {
                    System.out.println();
                    tmp += ((tmp + 1) / 2) * 2;
                }
                System.out.printf("%d ", nodes[i]);
            }
        }

    }
}

Measured memory_bytes: 106404
n, k= map(int, input().split())
cnt=[0]*k
for i in range(1,n+1):
    cnt[i%k]+=1
ans=0
for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k==0:
        ans+=cnt[a]*cnt[b]*cnt[c]
print(ans)

Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <complex>
#include <cstdio>

using namespace std;

typedef complex<double> P;

P ps[100];

int main(){

  int n;
  while(cin>>n&&n){
    P cp;
    for(int i=0;i<n;i++){
      cin>>ps[i].real()>>ps[i].imag();
      //cout<<ps[i].real()<<" "<<ps[i].imag()<<endl;
      cp+=ps[i];
    }
    cp/=n;
    printf("%.10f %.10f\n",cp.real(),cp.imag());
  }
  

  return 0;
}

Measured memory_bytes: 0
from itertools import product

N = int(input())
ans, L = 0, len(str(N))
for i in range(L + 1):
    for p in product(("7", "5", "3"), repeat=i):
        if "7" in p and "5" in p and "3" in p:
            if (i == L and int(''.join(p)) <= N) or i < L:
                ans += 1
print(ans)


Measured memory_bytes: 3316
H = [[[0 for x in xrange(10)] for j in xrange(3)] for i in xrange(4)]
n = input()

for x in range(n):
        b,f,r,v = map(int, raw_input().split())
        H[b-1][f-1][r-1] += v

for b in range(4):
        for f in range(3):
                print(' '+' '.join(map(str,H[b][f])))
        if b != 3:
                print ('#'*20)

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

const int MXN = 2e5 + 20;

int n, h[MXN], b[MXN];
long long dp[MXN], ans;

void npt() {
	cin >> n;
	for (int i = 0; i < n; i++)	cin >> h[i];
	for (int i = 0; i < n; i++)	cin >> b[i];
}

void slv() {
	int base = 1;
	while (base <= n)
		base *= 2;
	vector <long long> tree(2 * base);
	for (int i = 0; i < n; i++) {
		int x = h[i] + base;
		long long  best = 0;
		while(x > 1) {
			if (x %  2)
				best = max(best, tree[x - 1]);
			x /= 2;
		}
		dp[h[i]] = best + b[i];
		for (int j = base + h[i]; j >= 1; j /= 2)
			tree[j] = max(tree[j], dp[h[i]]);
	}
	for (int i = 0; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
}

void tpt() {
	cout << ans << endl;
}

int main() {
	npt();
	slv();
	tpt();
	return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	ld a;
	cin>>a;
	cout<<fixed<<setprecision(20)<<(ld)(6.28318530717958623200*a)<<endl; 
	return 0;
}



Measured memory_bytes: 3844