akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 9000

signed main(){
    string s;
    cin >> s;
    int x,y;
    cin >> x >> y;
    vector<int> X, Y;
    int start_x;
    int cnt_F = 0, cnt_T = 0;
    REP(i,s.size()){
        if(s[i] == 'T'){
            if(cnt_T == 0) start_x = cnt_F;
            else if(cnt_T % 2 == 0) X.emplace_back(cnt_F);
            else Y.emplace_back(cnt_F);
            cnt_F = 0;
            cnt_T++;
        }else{
            cnt_F++;
        }
    }
    if(cnt_T == 0) start_x = cnt_F;
    else if(cnt_T % 2 == 0) X.emplace_back(cnt_F);
    else Y.emplace_back(cnt_F);
    vector<vector<bool>> dp_x(X.size() + 1, vector<bool>(MAX * 2 + 1, false)), dp_y(Y.size() + 1, vector<bool>(MAX * 2 + 1, false));
    dp_x[0][MAX + start_x] = true;
    for(int i = 0; i < X.size(); i++){
        for(int j = 0; j <= MAX * 2; j++){
            if(j - X[i] >= 0) dp_x[i + 1][j] = dp_x[i + 1][j] || dp_x[i][j - X[i]];
            if(j + X[i] <= MAX * 2) dp_x[i + 1][j] = dp_x[i + 1][j] || dp_x[i][j + X[i]];
        }
    }
    dp_y[0][MAX] = true;
    for(int i = 0; i < Y.size(); i++){
        for(int j = 0; j <= MAX * 2; j++){
            if(j - Y[i] >= 0) dp_y[i + 1][j] = dp_y[i + 1][j] || dp_y[i][j - Y[i]];
            if(j + Y[i] <= MAX * 2) dp_y[i + 1][j] = dp_y[i + 1][j] || dp_y[i][j + Y[i]];
        }
    }
    if(dp_x[X.size()][MAX + x] && dp_y[Y.size()][MAX + y]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

#define endl '\n'
#define int long long

const int N = 1e5+7;

int n, m; 
int cache[N];
vector<int> e[N];


int dfs(int k) {
    
    int &ans = cache[k];

    if(ans != -1) 
        return ans;

    ans = 0;
    for(auto it: e[k]) {
        ans = max(ans, 1 + dfs(it));
    }

    return ans;
}

int32_t main()
{
    IOS;   // FIO;

    memset(cache, -1, sizeof(cache));

    cin >> n >> m;

    for(int i = 1; i <= m; i ++) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++) {
        ans = max(ans, dfs(i));
    }

    cout << ans;
    
    return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int distA[100005], distB[100005];
vector<int> adj[100005];

void dfs(int u, int p, int *dist) {
    for (int v : adj[u])
        if (v != p) {
            dist[v] = dist[u] + 1;
            dfs(v, u, dist);
        }
}

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

    int n, a, b;
    cin >> n >> a >> b;
    a--, b--;
    for (int i=0; i<n-1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }

    dfs(a, -1, distA);
    dfs(b, -1, distB);

    int ret = 0;
    for (int i=0; i<n; i++)
        if (distA[i] < distB[i])
            ret = max(ret, distB[i] - 1);
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 15016
from math import sin
from math import sqrt
from math import cos
from math import pi

a, b, angle = map(float, input().split())

angle = angle/180 * pi


s = a * b * (1/2) * sin(angle)

l = a + b + sqrt(a**2 + b**2 - 2*a*b*cos(angle))

h = b * sin(angle)

print(s, l, h, sep='\n')


Measured memory_bytes: 5692
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int mod = 1e9 + 7;

vector<vector<int>> combi;


int calc(int ball, int partition) {
	return combi[ball + partition][ball];
}

void init(int maxi) {
	int n = maxi + 1;
	combi.assign(n, {});
	for (int i = 0; i < n; i++) {
		combi[i] = vector<int>(i+1, 0);
	}

	combi[0][0] = 1;

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

			combi[i+1][j]   %= mod;
			combi[i+1][j+1] %= mod;
		}
	}
}

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

	init(2 * n);
	// exit(0);

	int brue = k;
	int red = n - k;

	vector<int> ans(k + 1, 0);
	for (int i = 1; i <= k; i++) {
		int rest_blue = k - i;
		int rest_red = red - (i - 1);

		if (rest_red < 0) {
			break;
		}

		int patition_blue = i;
		int patition_red = i + 1;

		ans[i] = 1LL * calc(rest_blue, patition_blue - 1) * calc(rest_red, patition_red - 1) % mod;
		// printf("ans [%d] %d\n", i, ans[i]);
	}

	for (int i = 1; i <= k; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,j,H,W;
  string sharp = "";
  cin >> H >> W;
  vector<string> s(H);
  vector<char> c(W);
  
  for(i=0;i<H;i++){
  	cin >> s.at(i);
  }
  
  for(i=0;i<W+2;i++){
   sharp += '#';
  }
  
  for(i=0;i<H;i++){
    if(i == 0) cout << sharp << endl;
    cout << '#' << s.at(i) << '#' << endl;
    if(i == H-1) cout << sharp << endl;
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    int dp[101][4][4][4] = {};

    int mod = 1e9 + 7;
    dp[0][3][3][3] = 1;

    rep(len, n)
    {
        rep(i, 4)
        {
            rep(j, 4)
            {
                rep(k, 4)
                {
                    rep(a, 4)
                    {
                        if (dp[len][i][j][k] == 0)
                            continue;
                        if (a == 2 && i == 1 && j == 0)
                            continue;
                        if (a == 2 && i == 0 && j == 1)
                            continue;
                        if (a == 1 && i == 2 && j == 0)
                            continue;
                        if (a == 2 && i == 1 && k == 0)
                            continue;
                        if (a == 2 && j == 1 && k == 0)
                            continue;

                        dp[len + 1][a][i][j] += dp[len][i][j][k];
                        dp[len + 1][a][i][j] %= mod;
                    }
                }
            }
        }
    }
    int ans = 0;
    rep(i, 4)
    {
        rep(j, 4)
        {
            rep(k, 4)
            {
                ans += dp[n][i][j][k];
                ans %= mod;
            }
        }
    }
    OP(ans);
    return 0;
}


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

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

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

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

int main() {
    int X, Y;
    cin >> X >> Y;
    int s, t;

    if((2 * Y - X) < 0 or (2 * X - Y) < 0 or (2 * Y - X) % 3 != 0 or
       (2 * X - Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    } else {
        s = (2 * Y - X) / 3;
        t = (2 * X - Y) / 3;
    }
    // 前処理
    COMinit();
    // 計算
    cout << COM(s + t, s) % MOD << endl;
    return 0;
}


Measured memory_bytes: 32616
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   string s;
   cin>>s;
   s[3]='8';
   cout<<s<<endl;
   

}

Measured memory_bytes: 256
import queue

N, M = map(int, input().split())
root = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    root[A-1].append(B-1)
    root[B-1].append(A-1)

#sign:道しるべがどこを示しているか
sign = [-1]*N
sign[0] = 0

flag = True

# FIFOキューの作成
q = queue.Queue()
q.put(0)
r = queue.Queue()


while flag:
    flag = False
    num = 1

    while not q.empty():
        hoge = q.get()
        for i in range(len(root[hoge])):
            if sign[root[hoge][i]] == -1:
                sign[root[hoge][i]] = hoge
                r.put(root[hoge][i])
                flag = True

    while not r.empty():
        q.put(r.get())

    num += 1

if sign.count(-1) == 0:
    print("Yes")
    for i in range(1,N):
        print(sign[i]+1)
else:
    print("No")
    print(sign)

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

long long f(long long b, long long n) {
	if (n < b) {
		return n;
	}
	else {
		return f(b, n/b) + n%b;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	
 	long long n, s;
 	cin >> n >> s;
    long long ans = 1e18;
    long long sqn = sqrt(n)+1;

    if(s == n){
        cout << n+1 << '\n';
        return 0;
    }

    if(s > n){
        cout << "-1\n";
        return 0;
    }

    for (int i = 2; i <= sqn; i++) {
    	if (f(i, n) == s) {
    		cout << i << '\n';
    		return 0;
    	}
    }

    for (int p = 1; p <= sqn; p++) {
    	if ((n-s) % p != 0) {
    		continue;
    	}
    	long long b = (n-s) / p + 1;
    	long long q = s-p;
    	if (b > q && q >= 0) {
    		ans = min(ans, b);
    	}
    }

    if(ans == 1e18){
        cout << -1 << '\n';
        return 0;
    }
    cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x

int bubbleSort(int* A, int N){ // N 個の要素を含む 0-オリジンの配列 A
  int flag = 1;
  int count = 0;
  int j;

  while( flag == 1 ){
    flag = 0;
    for( j = N-1; j >= 1; j-- ){
      if (A[j] < A[j-1]){
        swap( A[j], A[j-1] );
        count++;
        flag = 1;
      }
    }
  }
  return count;
}

int main() {

  int N, A[200];
  int count;

  cin >> N;

  REP(i, N){
    cin >> A[i];    
  }

  count = bubbleSort( A, N );

  REP(i, N){
    cout << A[i];
    if( i != N-1 ){
      cout << " ";
    }    
  }
  cout << endl;
  cout << count << endl;

}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

public class Main {
	public static void main(String[] args) {
		double[] input = new double[6];		
		Scanner scan1 = new Scanner(System.in);
		while(scan1.hasNext()){
			for(int i=0; i<6; i++){
				input[i] = scan1.nextInt();
			}
			double tmp = input[3] / input[0];
			for(int i=0; i<3; i++){
				input[i+3] = input[i+3] - (input[i] * tmp);
			}
			double y = input[5] / input[4];
			double x = (input[2] - (input[1] * y)) / input[0];
			double x_ans = new BigDecimal(x).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
			double y_ans = new BigDecimal(y).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
			System.out.printf("%.3f ",x_ans);
			System.out.printf("%.3f",y_ans);
			System.out.println("");
		}
	}
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

  vector<double> t(n + 2), v(n + 2);
  for (auto i : irange(1L, n + 1)) {
    cin >> t[i];
    t[i] += t[i - 1];
  }
  for (auto i : irange(1L, n + 1)) {
    cin >> v[i];
  }

  // 加速終了時刻、減速開始時刻、終了速度
  vector<double> t1(n + 2), t2(n + 2), vv(n + 2);
  for (auto i : irange(1L, n + 2)) {
    if (vv[i - 1] > v[i]) {
      vv[i - 1] = v[i];
      for (auto j : irange(1L, i) | reversed) {
        auto dt = t[j] - t[j - 1];
        if (vv[j] + dt >= vv[j - 1]) {
          t1[j] = min(t1[j], t[j - 1] + (vv[j] + dt - vv[j - 1]) / 2.0);
          t2[j] = t[j] - (vv[j - 1] + (t1[j] - t[j - 1]) - vv[j]);
          break;
        } else {
          t1[j] = t2[j] = t[j - 1];
          vv[j - 1] = vv[j] + dt;
        }
      }
    }

    t1[i] = min(t[i - 1] + v[i] - vv[i - 1], t[i]);
    t2[i] = t[i];
    vv[i] = vv[i - 1] + t1[i] - t[i - 1];
  }

  double ans = 0;
  for (auto i : irange(1L, n + 1)) {
    auto dt1 = t1[i] - t[i - 1];
    auto dt2 = t2[i] - t1[i];
    auto dt3 = t[i] - t2[i];
    ans += vv[i - 1] * dt1 + dt1 * dt1 / 2.0;
    ans += (vv[i - 1] + dt1) * dt2;
    ans += vv[i] * dt3 + dt3 * dt3 / 2.0;
  }

  cout << setprecision(10) << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int N = s.size();
    int K;
    cin >> K;
    set<string> st;

    for (int i = 0; i <= N - 1; ++i) {
        string S = "";
        for (int j = 0; i + j <= N - 1 && j <= K; ++j) {
            S += s[i + j];
            st.insert(S);
        }
    }
    auto itr = st.begin();
    while (--K)
        ++itr;
    cout << *itr << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>
using namespace std;

#if 0
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif

int main(){
  long long l,r;
  cin >> l >> r;

  // 2019 = 3 * 673
  // long long x = l % 2019;
  // long long y = r % 2019;

  long long p = l / 2019;
  long long q = r / 2019;

  if( p < q ){ // 間に2019で割り切れる数がある
    cout << 0 << endl;
  }
  else{
    int minval = 1e4;
    for( long long i = l; i <= r; ++i ){
      for( long long j = i+1; j <= r; ++j ){
        int a = (i * j) % 2019;
        if( minval > a ){
          minval = a;
        }
      }
    }
    cout << minval << endl;
  }


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int n, cnt;
int judge(int x) {
	for(int i= 2; i * i <= x; i++)
		if(x % i == 0) return 0;
	return 1;
}
int main() {
	cin >> n;
	printf("%.12lf\n", (double)(n / 2 + n % 2) / n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
int dx[4] = { 0,0,1,1 }, dy[4] = { 0,1,0,1 };
int main()
{
	int n; cin >> n;
	map<pii, ll> mp;
	REP(i, n)
	{
		int x, y, w; cin >> x >> y >> w;
		mp[pii(x, y)] = w;
	}
	ll ans = 0;
	for (auto i:mp)
	{
		int x = i.first.first, y = i.first.second;
		REP(j, 4) 
		{
			int tx = x - dx[j], ty = y - dy[j];
			ll res = 0;
			REP(k, 4)
			{
				int nx = tx + dx[k], ny = ty + dy[k];
				if (mp.count(pii(nx, ny))) res += mp[pii(nx, ny)];
			}
			chmax(ans, res);
		}
	}
	cout << ans << " / 1" << endl;
	return 0;
}

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

using std::vector;
using std::unordered_map;
using std::pair;
using Node = pair<uint64_t, vector<uint32_t>>;

unordered_map<uint32_t, Node> g_tree{};

void rec(const uint32_t source, const uint32_t target, const uint64_t recv_data)
{
  g_tree[target].first += recv_data;

  auto send_data = g_tree[target].first;
  for(const auto& sendto : g_tree[target].second)
  {
    if(sendto != source)
    {
      rec(target, sendto, send_data);
    }
  }
  return;
}

int main(void)
{
  uint32_t N{}, Q{};
  std::cin >> N >> Q;

  for(uint32_t i = 0; i < N - 1; ++i)
  {
    uint32_t a{}, b{};
    std::cin >> a >> b;
    --a; --b;

    g_tree[a].second.push_back(b);
    g_tree[b].second.push_back(a);
  }

  for(uint32_t i = 0; i < Q; ++i)
  {
    uint32_t p{};
    uint64_t x{};
    std::cin >> p >> x;
    --p;

    g_tree[p].first += x;
  }

  auto data = g_tree[0].first;
  for(const auto& sendto : g_tree[0].second)
  {
    rec(0, sendto, data);
  }

  std::cout << data;
  for(uint32_t index = 1; index < N; ++index)
  {
    std::cout << ' ' << g_tree[index].first;
  }
  std::cout << '\n';

  return 0;
}


Measured memory_bytes: 35656
from sys import stdin

# Union-Find木で解く
class UnionFind:
    def __init__(self, n):
        # 親
        self.par = [i for i in range(n)]
        # 木の深さ
        self.rank = [1] * (n)
        # size[i]: iを根とするグループのサイズ
        self.size = [1] * (n)

    # 木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            # 検索していく過程で親を書き換える（経路圧縮による効率化）
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # xとyの属する集合の併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 木の高さの低い方を高い方に繋げる（ランクによる効率化）
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x] # サイズの更新
        else:
            self.par[y] = x
            self.size[x] += self.size[y] # サイズの更新
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 木のサイズを求める
    def get_size(self, x):
        return self.size[x]

# N個の島とM本の橋
N, M = [int(x) for x in stdin.readline().rstrip().split()]
bridge = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]

# Union-Find木の定義
unionfind = UnionFind(N)

# 逆順にする
bridge.reverse()

# 結果の格納リスト
result = []

# Union-Find木のindexに合わせる
for i in range(M):
    bridge[i] = [bridge[i][0]-1, bridge[i][1]-1]

for land1, land2 in bridge:
    # 島同士の所属しているグループが一緒かどうか
    if unionfind.is_same(land1, land2):
        result.append(0)
    else:
        # 島同士が完全に素の場合、それぞれが属するグループの点の数を掛けたものになる
        num = unionfind.get_size(unionfind.find(land1)) * unionfind.get_size(unionfind.find(land2))
        result.append(num)
        # 島同士を繋げる
        unionfind.union(unionfind.find(land1), unionfind.find(land2))

answer = 0
for i in range(M):
    answer += result[M-1-i]
    print(answer)

Measured memory_bytes: 122844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Starry Sky Tree */
//0-index

struct StarrySkyTree{
  typedef ll Type;
  int segn2;
  vector<Type> data, s_data;
  function<Type(Type, Type)> merge;

  StarrySkyTree(function<Type(Type, Type)> merge, int n): merge(merge)
  {
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
    s_data.assign(segn2*2, 0);
  }

  StarrySkyTree(int n): //Original Ver.
    StarrySkyTree([](Type a, Type b){ return min(a, b); }, n) {}

  //get value of [a,b)
  Type query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(r <= a || b <= l) return LLINF; //大きさに注意
    if(a <= l && r <= b) return data[k] + s_data[k];
    return merge(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2 , r, k*2+2)) + s_data[k];
  }

  //add x to [a,b)
  Type add(int a, int b, Type x, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b)
      s_data[k] += x;
    else if(a < r && l < b)
      data[k] = merge(add(a, b, x, l, (l+r)/2, k*2+1), add(a, b, x, (l+r)/2, r, k*2+2));

    return data[k] + s_data[k];
  }

  Type val(int x){
    Type res = 0;
    x += segn2 - 1;

    while(x){
      res += s_data[x];
      x = (x-1)/2;
    }

    return res;
  }

};

int main(){
  int N, A, B, p;

  scanf("%d%d%d", &N, &A, &B);

  StarrySkyTree seg(N+1);

  for(int i=0;i<N;i++){
    scanf("%d", &p);
    ll minVal = seg.query(0, p);

    seg.add(0, p, A);
    seg.add(p+1, N+1, B);

    ll q = seg.val(p);
    seg.add(p, p+1, minVal - q);
  }

  ll ans = seg.query(0, N+1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Study Scheduling
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int h0, m0, h1, m1, k;
  scanf("%d%d%d%d%d", &h0, &m0, &h1, &m1, &k);

  int t0 = h0 * 60 + m0, t1 = h1 * 60 + m1;
  printf("%d\n", t1 - t0 - k);
  return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int MAXN=2e3+100;
const int N=1e6+1000;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll a[N];
vector<pii>g;
int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    int n;cin>>n;
    rep1(i,n) cin>>a[i];
    for(int i=1;i<=n;++i)
    {
        int pos=i;
        while(pos+1<=n&&a[pos]<=a[pos+1]) pos++;
        g.PB({i,pos});
        i=pos;
    }
    ll ans=1000;
    for(pii v:g)
    {
        int x=v.X,y=v.Y;
        ll d=ans/a[x];
        ans-=d*a[x];
        ans+=d*a[y];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int W,H,N;
  cin >> W >> H >> N;
  vector<int> w(2),h(2);
  w.at(0)=0;
  w.at(1)=W;
  h.at(0)=0;
  h.at(1)=H;
  for(int i=0;i<N;i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1){
      w.at(0)=max(w.at(0),x);
    }else if(a==2){
      w.at(1)=min(w.at(1),x);
    }else if(a==3){
      h.at(0)=max(h.at(0),y);
    }else{
      h.at(1)=min(h.at(1),y);
    }
  }
  if((w.at(0)>w.at(1)||(h.at(0)>h.at(1)))){
    cout << 0 << endl;
  }else{
    cout << (w.at(1)-w.at(0))*(h.at(1)-h.at(0)) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
alpha='abcdefghijklmnopqrstuvwxyz'
t,h=0,0
for i in range(n):
    x,y=map(str,input().split())
    if x==y:
        t+=1
        h+=1
    elif x<y:
        h+=3
    else:
        t+=3
print(t,h)


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

int main(){

	int i;
	int height[10];

	for (i = 0; i < 10; i++){
		do{
			cin >> height[i];
		} while (height[i] < 0 || height[i] > 10000);
	}

	sort(height, height + 10, greater<int>());

	for (i = 0; i < 3; i++){
		cout << height[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>

int main()
{
	int k;
	long long X, tmp = 100;
	scanf("%lld", &X);
	for (k = 0; tmp < X; k++, tmp = (long long)((long double)tmp * 101 / 100));
	printf("%d\n", k);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1712
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray

fib :: Int -> Int
fib n = go n
  where
    memo :: Array Int Int
    memo = listArray (0, n) $ fmap go [0 .. n]
    go 0 = 1
    go 1 = 1
    go k = memo ! (k - 1) + memo ! (k - 2)

main :: IO ()
main = do
    n <- readLn
    print $ fib n



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

int main(){
	string s;
  	cin >>s;
  	bool f=false;
  	for(int i=0;i<s.size();i++){
    	if((i%2)==0){
        	if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
            	f=true;
            }else{
            	f=false;
              break;
            }
            }else{
        if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
            	f=true;
            }else{
        	f=false;
          break;
        }
        }
        }
if(f){
	cout<<"Yes"<<endl;
}else{
	cout<<"No"<<endl;
}
}

Measured memory_bytes: 256
int main(){
	int x,y,z;
	
	while(1){
		scanf("%d %d\n",&x,&y);
		if(x == 0 && y == 0){
			break;
		}
		if(x>y) {
			printf("%d %d\n",y,x);
		}
		else {
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
using namespace std;

int l[8]={0},len[4];
int main(){
  int i,k,m,N,A[3],dp[4],sum,ans=1000000000;
  cin>>N>>A[0]>>A[1]>>A[2];
  for(i=0;i<N;i++){
    cin>>l[i];
  }
  
  for(k=0;k<pow(4,N);k++){
    //dp[]及びlen[]の初期化
    dp[0]=0;dp[1]=0;dp[2]=0;dp[3]=0;
    len[0]=0;len[1]=0;len[2]=0;len[3]=0;
    sum=0;m=k;
    
    //合成魔法の使用
    for(i=0;i<N;i++){
      if(len[m%4]>0)dp[m%4]=dp[m%4]+10;
      len[m%4]+=l[i];
      m/=4;
    }
    //len[]が全て1以上であることの確認。
    if(len[0]*len[1]*len[2]==0)continue;
    
    for(i=0;i<3;i++){sum=sum+dp[i]+abs(len[i]-A[i]);} 
    
    if(ans>sum){ans=sum;}
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
<?php
// Your code here!
$s = trim(fgets(STDIN));
$count = strlen($s);

$ans = '';
for($i=0; $i<$count; $i++){
    if($s[$i] == '0'){
        $ans .= '0';
    }elseif($s[$i] == '1'){
        $ans .= '1';
    }elseif($s[$i] == 'B'){
        $ans = substr($ans, 0, -1);
    }
}
echo $ans;


Measured memory_bytes: 4856
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int l=1;
		long[][] m1=new long[n][m];
		long[][] m2=new long[m][l];
		long[][] ans=new long[n][l];
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				m1[i][j]=sc.nextLong();
			}
		}
		for(int i=0; i<m; i++) {
			for(int j=0; j<l; j++) {
				m2[i][j]=sc.nextLong();
			}
		}
		for(int i=0; i<n; i++) {
			for(int j=0; j<l; j++) {
				long tmp=0;
				for(int k=0; k<m; k++) {
					tmp+=m1[i][k]*m2[k][j];
				}
				ans[i][j]=tmp;
			}
		}
		output(ans,n,l);
	}
	public static void output(long[][] a,int h,int w) {
		for(int i=0; i<h; i++) {
			for(int j=0; j<w-1; j++) {
				System.out.print(a[i][j]+" ");
			}
			if(w>0) {
				System.out.println(a[i][w-1]);;
			}
		}
	}
}


Measured memory_bytes: 40672
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
using namespace std;
int A[100005];
int main()
{
    //std::ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    ll k,i,mini=2,maxi=2,a,b;
    cin>>k;
    for(i=0;i<k;i++)
    	cin>>A[i];
    for(i=k-1;i>=0;i--){
    	a=(mini+A[i]-1)/A[i]*A[i];
    	b=(maxi/A[i])*A[i];
    	if(a>maxi){
    		cout<<"-1";
    		return 0;
    	}
    	mini=a,maxi=b+A[i]-1;
    }
    cout<<mini<<" "<<maxi;
    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    ll goal; cin>>goal;
    ll x=100;
    int ans=0;
    while (x<goal) {
	ans++;
	x=floor(1.01*x);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3760
# DLS_1_A Disjoint Set: Union Find Tree
import sys
n, q = map(int, input().split())


class Dset:
    def __init__(self, value):
        self.value = value
        self.rank = 0
        self.parent = self

    def unite(self, y):
        x = self
        while x.parent != x:
            x = x.parent
        while y.parent != y:
            y = y.parent

        if x.rank >= y.rank:
            big = x
            small = y
        else:
            big = y
            small = x

        small.parent = big.parent
        small.rank += 1
        return

    def same(self, y):
        x = self
        while x.parent != x:
            x = x.parent
        while y.parent != y:
            y = y.parent
        if x.parent == y.parent:
            return 1
        else:
            return 0


l = [] * n
for i in range(n):
    l.append(Dset(i))

for i in range(q):
    com, x, y = map(int, sys.stdin.readline().strip().split())
    if com == 0:
        l[x].unite(l[y])
    else:
        print(l[x].same(l[y]))

# for i in range(n):
#     print('i : {}  parent : {}'.format(i, l[i].parent.value))





Measured memory_bytes: 8264
#include <stdio.h>

int selectionSort(int A[], int N){
  int i, j, t, sw=0, min;
  for(i=0; i<N-1; i++){
    min = i;
    for(j=i; j<N; j++){
      if(A[j]<A[min]) min=j;
    }
    t = A[i];
    A[i] = A[min];
    A[min] = t;
    if(i!=min) sw++;
  }
  return sw;
}

int main(){
  int N, i, A[100], sw;

  scanf("%d", &N);
  
  for(i=0; i<N; i++) scanf("%d", &A[i]);

  sw = selectionSort(A, N);

  for(i=0; i<N; i++){
    printf("%d", A[i]);
    if(i!=N-1) printf(" ");
  }
  
  printf("\n");
  printf("%d\n", sw);
  return 0;
}



Measured memory_bytes: 2048
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a : u32 = read();
    let b : u32 = read();
    let c : u32 = read();
    let x : u32 = read();
    let mut ans = 0;
    for anum in 0..a+1 {
        for bnum in 0..b+1 {
            for cnum in 0..c+1 {
                if anum * 500 + bnum * 100 + cnum * 50 == x {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



 
int main(){fastio
    ll n;cin>>n;
    cout<<n*n<<endl;
  
    /*
    ll n;cin>>n;
    string s;cin>>s;
    if(n%2==1){
        cout<<"No"<<endl;return 0;
    }
    rep(i,0,n/2-1){
        if(s[i]!=s[i+n/2]){
            cout<<"No"<<endl;return 0;
        }
    }
    cout<<"Yes"<<endl;
     */
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

const int MAXN = 105;
const int MAX_K = (int)1e5 + 5;

int a[MAXN];
int dp[MAX_K];

int main(void) {
    int n, k;

    scanf(" %d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf(" %d", &a[i]);
    }
    for (int i = 0; i <= k; i++) {
        dp[i] = 0;
        for (int j = 0; j < n; j++) {
            if (i - a[j] >= 0) {
                dp[i] |= 1 - dp[i - a[j]];
            }
        }
    }
    printf("%s\n", dp[k] == 1 ? "First" : "Second");

    return 0;
}


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

const int nex = 1e5 + 5;
vector<int> graph[nex];
int in_degree[nex] = {};
bool visited[nex] = {};
int dist[nex] = {};
void dfs(int a){
	assert(!visited[a]);
	visited[a] = true;
	for(auto b : graph[a]){
		dist[b] = max(dist[b],dist[a] + 1);
		--in_degree[b];
		if(!in_degree[b]){
			dfs(b);
		}

	}
}

int main(){

	int n,m;
	cin >> n >> m;

	
	for(int i=0;i<m;++i){
		int x,y;
		cin >> x >> y;
		graph[x].push_back(y);
		in_degree[y]++;
	}

	

	for(int i=1;i<=n;++i){
		if(!visited[i] && in_degree[i] == 0){
			dfs(i);
		}
	}

	int ans = 0;

	for(int i=1;i<=n;++i){
		ans = max(ans,dist[i]);
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
int n, k;

int main(){
	IOS
	cin >> n >> k;
	int arr[n+5];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr, arr+n);
	int ans=0;
	for(int i=0;i<k;i++){
		ans+=arr[i];
	}
	cout << ans << '\n';
}


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

using namespace std;
using ll = long long;

#define REP(i,n) FOR(i, 0, n)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define FORR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

int main() {
	int n;
	V<string> v;
	string s;

	cin >> n;

	REP(i,n) {
		cin >> s;
		sort(ALL(s));
		v.push_back(s);
	}
	sort(ALL(v));
	v.push_back("zzzzzzzzzzzzzzzz");

	ll ans = 0;
	string t = v[0];
	ll cnt = 1;
	FOR(i,1,n+1) {
		if(t == v[i]) {
			cnt++;
		} else {
			ans += cnt*(cnt-1)/2;
			cnt = 1;
			t = v[i];
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 5748
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;
vector<int> a;


// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (a[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}


int main(){
  int N,ans=0;
  cin>>N;
  REP(i,N){
    int s;
    cin>>s;
    a.push_back(s);
  }
  SORT(a);
  
  for(int i=0; i<N-2; ++i){
    for(int j=i+1; j<N-1; ++j){
      ans+=binary_search(a.at(i)+a.at(j))-j-1;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	string a, b;
	cin >> a;
	b = a;
	n = (int)a.size() - 1;
	int fi = n;
	for(int i = n; i >= 0 && b[i] == '0'; i--, fi--){}
	for(int i = fi; i >= 0; i--) b[i] = ('9' - b[i]) + '0';
	b[fi] = char(b[fi] + 1);
	vi min_a(a.size(), 0);
	vi min_b(b.size(), 0);
	min_a[n] = min(a[n] - '0', 2 + ('9' - a[n]));
	min_b[n] = min(b[n] - '0', 2 + ('9' - b[n]));
	for(int i = n - 1; i >= 0; i--)
	{
		min_a[i] = min((a[i] - '0') + min_a[i + 1], (a[i] - '0') + 1 + min_b[i + 1]);
		min_b[i] = min((b[i] - '0') + min_b[i + 1], (b[i] - '0') + 1 + min_a[i + 1]);
		min_a[i] = min(min_a[i], 1 + min_b[i]);
		min_b[i] = min(min_b[i], 1 + min_a[i]);
	}
	cout << min_a[0];
}

Measured memory_bytes: 10140
#include <bits/stdc++.h>
#define maxn 510
#define pii pair<int,int>
#define fi first
#define se second

using namespace std;

int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],n,m,p[maxn],fre[maxn],cnt=0,been[maxn][maxn];
pii g[maxn][maxn];

bool visit(int u) {
    if (fre[u]!=cnt) fre[u]=cnt;
    else return false;
    for (int v=0;v<n;v++)
        if (g[u][v].fi==1) {
            if (p[v]==-1||visit(p[v])) {
                p[v]=u;
                return true;
            }
        }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   // freopen("in.txt","r",stdin);
    cin>>n>>m;
    for (int i=0;i<n;i++)
        for (int j=0;j<m;j++) {
            cin>>a[i][j];
            a[i][j]--;
        }
    for (int col=0;col<m;col++) {
        for (int i=0;i<n;i++) {
            for (int j=0;j<n;j++) g[i][j]=pii(-1,-1);
            p[i]=-1;
        }
        for (int i=0;i<n;i++)
            for (int j=0;j<m;j++)
                if (!been[i][j]) g[i][a[i][j]/m]=pii(1,j);
        for (int i=0;i<n;i++) {
            cnt++;
            visit(i);
        }
        for (int i=0;i<n;i++) {
            int row = p[i];
            b[row][col] = a[row][g[row][i].se]+1;
            c[i][col] = a[row][g[row][i].se]+1;
            been[row][g[row][i].se]=1;
        }
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) cout<<b[i][j]<<" ";
        cout<<endl;
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) cout<<c[i][j]<<" ";
        cout<<endl;
    }
    //for (int i=0;i<n;i++) {
     //   for (int j=0;j<m;j++) if ((c[i][j]-1)/m!=i) cout<<"fuck "<<c[i][j]<<" "<<i<<endl;
   // }
    return 0;
}



Measured memory_bytes: 3200
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;

int n, q;
ll a[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    while (q--) {
        ll cnt, ans = 0;
        cin >> cnt;
        int i = 0, j = -1;
        while (j < n) {
            if (cnt >= 0) {
                ++j;
                if (j >= n) break;
                cnt -= a[j];
            }
            else {
                cnt += a[i];
                ++i;
            }
            if (cnt >= 0) ans += j - i + 1;
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3988
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let w = v[0];
	let h = v[1];
	let n = v[2];
	let mut x:Vec<i32> = Vec::new();
	let mut y:Vec<i32> = Vec::new();
	let mut a:Vec<i32> = Vec::new();
	for i in 0..n {
		let v:Vec<i32> = procon_read();
		x.push(v[0]);
		y.push(v[1]);
		a.push(v[2]);
	}
	let mut leftx = 0;
	let mut lefty = 0;
	let mut rightx = w;
	let mut righty = h;
	for i in 0..n {
		if a[i as usize] == 1 {
			if leftx < x[i as usize] {
				leftx = x[i as usize];
			}
		}else if a[i as usize] == 2 {
			if rightx > x[i as usize] {
				rightx = x[i as usize];
			}
		}else if a[i as usize] == 3 {
			if lefty < y[i as usize] {
				lefty = y[i as usize];
			}
		}else{
			if righty > y[i as usize] {
				righty = y[i as usize];
			}
		}
	}
	if (righty - lefty) < 0 || (rightx - leftx) < 0{
		println!("0");
	}else{
		println!("{}", (righty - lefty)*(rightx -leftx));
	}
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void){

  ll N;  cin >> N;
  ll keep_num = 1;
  for(int i = 1; i <= (ll)sqrtl(N) + 1 ; i++)
    if(N % i == 0)  keep_num = i;

  ll ans = (keep_num - 1) + (N / keep_num - 1);
  cout << ans << endl;
  
  return 0;
}


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

//最大公約数の計算(ユークリッドの互除法)
long long int gcd(long long int a, long long int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    lint a, b;
    cin >> a >> b;
    cout << (a * b) / gcd(a, b) << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
	public static void main (String[] args) throws IOException
	{
		String X;
		int x;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		X = br.readLine();
		x = Integer.parseInt(X);
		System.out.println((int)Math.pow(x,3));
	}
}

Measured memory_bytes: 17044
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for h in range(H):
        for w in range(W):
            if (h+w)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7008
import java.util.*;
public class Main {
	static int Sum(List<Integer> a){
		int result=0;
		for(int i=0;i<a.size();i++)result+=a.get(i);
		return result;
	}
	static void print(List<Integer> a){
		Collections.sort(a);
		for(int i=0;i<a.size()-1;i++){
			System.out.print(a.get(i)+" ");
		}
		System.out.println(a.get(a.size()-1));
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int target = in.nextInt();
			List<Integer> result = new ArrayList<Integer>();
			int n=0;
			int sum=Sum(result);
			for(int i=10;i>=0;i--){
				if(sum+(1<<i)<=target){
					result.add(1<<i);
					sum=Sum(result);
				}
			}
			print(result);
		}
	}
}

Measured memory_bytes: 17228