akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

vector<vector<int>> graph;
int ans = 0;
vector<bool> visited;
int cnt;
int n, m;

void dfs(int v){
    visited[v] = true;
    cnt++;
    if(cnt == n){
        ans++;
        visited[v] = false;
        cnt--;
        return;
    }

    for(int nv : graph[v]){
        if(visited[nv]) continue;
        dfs(nv);
    }
    visited[v] = false;
    cnt--;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    cin >> n >> m;

    graph.resize(n);
    visited.resize(n);
    cnt = 0;
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a1 := readInt()
	b1 := readInt()
	a2 := readInt()
	b2 := readInt()
	a3 := readInt()
	b3 := readInt()

	answer := solve(a1, b1, a2, b2, a3, b3)
	fmt.Printf("%v\n", answer)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(readString())
	if e != nil {
		panic(e)
	}
	return i
}

func solve(a1, b1, a2, b2, a3, b3 int) string {
	nums := []int{a1, b1, a2, b2, a3, b3}
	if sumSlice(nums) != 15 {
		return "NO"
	} else {
		return "YES"
	}
	//path1 := []int{a1, b1}
	//path2 := []int{a2, b2}
	//path3 := []int{a3, b3}
	//paths := [][]int{path1, path2, path3}
	//for i, p1 := range paths {
	//	a := p1[0]
	//	b := p1[1]
	//	otherPaths := append(paths[:i], paths[i+1:]...)
	//	for j, p2 := range otherPaths {
	//		if a == p2[0] || b == p2[0] || a == p2[1] || b == p2[1] {
	//			lastPath := append(otherPaths[:j], otherPaths[j+1:]...)
	//			if lastPath[0][0] == p2[0] || lastPath[0][1] == p2[0] || lastPath[0][0] == p2[1] || lastPath[0][1] == p2[1] {
	//				return "YES"
	//			}
	//		}
	//	}
	//}
	//return "NO"
}

func sumSlice(nums []int) (sum int) {
	for _, n := range nums {
		sum += n
	}
	return
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    
    for(int j = 0; j < 4; j++){
      if(s.charAt(j) == '+')
        count++;
      else
        count--;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 20692
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

string S; int N;

int main() {
	cin >> N >> S; int ret = N;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] == S[i + 1]) ret--;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

using namespace std;

const int sz=5e3+10;
int n,k;
int len,a[sz];
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>k;
    len=0;
    int ans=n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(x>=k)ans--;
        else a[len++]=x;
    }
    sort(a,a+len);
    int tmp=0;
    while(len>=2)
    {
        tmp+=a[len-1];
        if(a[len-2]+tmp<k)
        {
            len--;
            continue;
        }
        if(a[0]+tmp>=k)
        {
            ans=0;
            break;
        }
        int l=0,r=len-2;
        while(l+1<r)
        {
            int mid=(l+r)/2;
            if(tmp+a[mid]>=k)r=mid;
            else l=mid;
        }
        ans=ans-(len-r);
        len=r;
    }
    cout<<ans<<endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a.at(i);
    }
    
    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;
    
    for (int i = 0; i < h; i++) {
        cout << "#" << a.at(i) << "#" << endl;
    }
    
    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 256
mod = 1_000_000_007

n = gets.to_i
a = gets.split.map &:to_i

tmp0 = a.sum
tmp0 = ((tmp0 % mod) ** 2) % mod
tmp1 = a.sum { |e| e ** 2 } % mod
ans = tmp0 < tmp1 ? tmp0 - tmp1 + mod : tmp0 - tmp1

if ans.odd?
  puts (ans + mod) / 2
else
  puts ans / 2
end


Measured memory_bytes: 30676
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, k = map(int, read().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a //= 2
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b //= 2
print(a, b)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int a,b,c,t;
int main(){
	cin>>a>>b>>c;
	if(a>c){
		t=a;
		a=c;
		c=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, k;
    cin >> n >> k;
    ll res = n - k;
    if(k == 1) cout << 0 << endl;
    else cout << res << endl;

    return 0;
}

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

using namespace std;

struct pos {
    int x, y;
};

int h, w;
const vector<pos> moves{{1,  0},
                        {-1, 0},
                        {0,  1},
                        {0,  -1}};

bool inRange(pos p) {
    return 0 <= p.x && p.x < h && 0 <= p.y && p.y < w;
}

int main() {
    cin >> h >> w;
    vector<string> v(h);
    for (int i = 0; i < h; i++)cin >> v[i];

    bool ret = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (v[i][j] == '#') {
                pos here = {i, j};
                bool found = false;
                for (auto move:moves) {
                    pos next = {here.x + move.x, here.y + move.y};
                    if (inRange(next) && v[next.x][next.y] == '#')found = true;
                }
                if (!found) ret = false;
            }
        }
    }

    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

string int_to_basem2(ll n) {
  if (n == 0) {
    return "0";
  }

  string retv = "";
  while (n != 0) {
    ll remain = ((n % 2LL) + 2LL) % 2LL;
    char digit = (char)remain + '0';

    retv.insert(retv.begin(), digit);
    n = (n - remain) / (-2LL);
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  // main procedure
  string ans = int_to_basem2(N);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t;
	scanf("%d%d",&n,&t);
	int a,b;
	int Min=INT_MAX;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a,&b);
		if(b<=t){
			if(a<Min){
				Min=a;
			}
		}
	}
	if(Min==INT_MAX){
		printf("TLE\n");
	}else{		
		printf("%d\n",Min);
	}
	return 0;
} 

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

int main() {
    int n;
    cin>>n;
    int ar[n+1];
    ar[0] = 0;
    int k = 0;
    for(int i = 1; i <=n; i++) {
        cin>>ar[i];
        if(ar[i] != i) k++;
    }
    if(k==0 || k == 2) cout<<"YES"<<"\n";
    else cout<<"NO"<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
int power_mod(int a, int b) {
	int res = 1;
	for(; b; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) res = (ll) res * a % mod;
	return res;
}
const int N = 2e5 + 10;
vector<int> E[N];
int fac[N], ifac[N];
int C(int n, int m) {
	return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int dp[N], sz[N], n;
void dfs1(int u, int pre) {
	dp[u] = sz[u] = 1;
	for(auto &v : E[u]) {
		if(v == pre) continue;
		dfs1(v, u);
		sz[u] += sz[v];
		dp[u] = (ll) dp[u] * dp[v] % mod * ifac[sz[v]] % mod;
	}
	dp[u] = (ll) dp[u] * fac[sz[u] - 1] % mod;
}
int up[N];
void dfs2(int u, int pre) {
	for(auto &v : E[u]) {
		if(v == pre) continue;
		up[v] = (ll) dp[u] * power_mod(dp[v], mod - 2) % mod;
		up[v] = (ll) up[v] * power_mod(C(n - 1, sz[v]), mod - 2) % mod;
		dp[v] = (ll) dp[v] * C(n - 1, sz[v] - 1) % mod;
		dp[v] = (ll) dp[v] * up[v] % mod;
		dfs2(v, u);
	}
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = 1;
	for(int i = 1; i < N; i++) fac[i] = (ll) fac[i - 1] * i % mod;
	ifac[N - 1] = power_mod(fac[N - 1], mod - 2);
	for(int i = N - 2; i; i--) ifac[i] = (ll) ifac[i + 1] * (i + 1) % mod;
	cin >> n;
	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs1(1, 0);
	dfs2(1, 0);
	for(int i = 1; i <= n; i++) {
		cout << dp[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 17908
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

int main()
{
	ll N;
    cin>>N;
    vector<ll> a(N+1);
    FOR(i,1,N){
    	cin>>a[i];
    }

    ll ans=0;
    FOR(i,1,N){
    	if(a[a[i]]==i) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class Field {
public:
	int H;
	int W;
	int n;
	vector<int> di = { 1,0 };
	vector<int> dj = { 0,1 };
	vector<vector<char>> v;
	Field(int H, int W, int n) :H(H), W(W), n(n), v(H, vector<char>(W, 0)) {};
	bool isinrange(int i, int j) { return 0 <= i&&i < H && 0 <= j&&j < W; }
	bool deleteBlocks() {
		bool ret = false;
		do {
			dump("deleteBlocks before");
			show();
			vector<vector<char>> f(H, vector<char>(W, false));
			rep(i, 0, H)rep(j, 0, W) {
				if (v[i][j] == '.')continue;
				rep(k, 0, di.size()) {
					int ii = i, jj = j;
					int cnt = 0;
					while (isinrange(ii, jj) && v[i][j] == v[ii][jj]) {
						ii += di[k], jj += dj[k];
						cnt++;
					}
					if (cnt < n) continue;
					ii = i, jj = j;
					while (isinrange(ii, jj) && v[i][j] == v[ii][jj]) {
						f[ii][jj] = true;
						ii += di[k], jj += dj[k];
					}
				}
			}
			rep(i, 0, H)rep(j, 0, W) {
				if (f[i][j]) {
					v[i][j] = '.';
					ret = true;
				}
			}
			dump("deleteBlocks after");
			show();
		} while (fill());
		return ret;
	}

	bool fill() {
		bool ret = true;
		dump("fill before");
		show();
		vector<vector<char>> v2(H, vector<char>(W, '.'));
		rep(j, 0, W) {
			int ii = H - 1;
			rrep(i, 0, H) {
				if (v[i][j] == '.')continue;
				v2[ii][j] = v[i][j];
				ii--;
			}
		}
		if (v == v2)ret = false;
		v = v2;
		dump("fill after");
		show();
		return ret;
	}

	bool blockExists() {
		rep(i, 0, H)rep(j, 0, W) {
			if (v[i][j] == '.') continue;
			return true;
		}
		return false;
	}

	void show() {
		if (DBG == 0)return;
		rep(i, 0, v.size()) {
			cout << v[i][0];
			rep(j, 1, v[i].size()) { cout << " " << v[i][j]; }
			cout << endl;
		}
		cout << endl;
	}
};

int h, w, n;

signed main() {
	cin >> h >> w >> n;
	Field F(h, w, n);
	rep(i, 0, h) rep(j, 0, w) cin >> F.v[i][j];
	rep(i, 0, h)rep(j, 1, w) {
		Field F2 = F;
		char &a = F2.v[i][j];
		char &b = F2.v[i][j - 1];
		if (a != '.'||b != '.') {
			dump(j - 1);
			dump(j);
			swap(a, b);
			F2.fill();
			while (F2.deleteBlocks());
			if (F2.blockExists() == false) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int n,m,fa[N],out[N];
vector<int>g[N];
inline int Find(int x)
{
	return x==fa[x]?x:fa[x]=Find(fa[x]);
}
inline void dfs(int x,int fa)
{
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i];
		if(v==fa)
			continue;
		dfs(v,x);
		if(out[v]&1)
			printf("%d %d\n",v,x);
		else
		{
			out[x]++;
			printf("%d %d\n",x,v);
		}	
	}
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(m&1)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		if(Find(u)!=Find(v))
		{
			g[u].push_back(v);
			g[v].push_back(u);
			fa[Find(u)]=Find(v);
		}
		else
		{
			out[v]++;
			printf("%d %d\n",v,u);
		}
	}
	dfs(1,0);
	return 0;
}

Measured memory_bytes: 11008
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

    int cnt = 0;
    int before = -1;
    for (int i = 0; i < 4; i++) {
        int num = n % 10;

        if (before == num)
            cnt++;
        else {
            before = num;
            cnt = 1;
        }
        if (cnt == 3)
            break;
        n /= 10;
    }
    cout << (cnt == 3 ? "Yes" : "No") << endl;
    return 0;
}

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

static double eps = 1e-9;

int main(){
    int N;
    cin>>N;
    double x[50+10],y[50+10];
    for(int i=0; i<N; i++) cin>>x[i]>>y[i];

    bool check = true;
    if(N % 2 != 0) check = false;

    double px,py;
    px = (x[0] + x[N/2]) / 2;
    py = (y[0] + y[N/2]) / 2;

    for(int i=0; i<N; i++){
        double nx,ny,difx,dify;
        nx = px - x[i];
        ny = py - y[i];
        difx = px + nx - x[(i+N/2)%N];
        dify = py + ny - y[(i+N/2)%N];
        if(fabs(difx) > eps || fabs(difx) > eps) check = false;
    }

    if(check){
        cout<<setprecision(8)<<fixed;
        cout<<px<<" "<<py<<endl;
    }

    else cout<<"NA"<<endl;

    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <vector>
#include <unordered_map>

#define NMAX (int)1e5 + 1
#define INF 2000000000

#define MIN(a, b) ((a) < (b) ? (a) : (b))

using namespace std;

typedef unsigned long long ull;

ull health;
unordered_map<ull, ull> memo;

ull solve(ull health)
{
	if (health == 1)
		return 1;
	
	if (memo.count(health))
		return memo[health];

	ull next = health / 2;
	ull value = solve(next);

	memo[next] = value;
	return 2 * memo[next] + 1;
}

int main()
{
	cin >> health;
	cout << solve(health) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<long long> N(4);
    for(int i=0;i<4;i++) cin >> N.at(i);
    vector<long long> pro(4);
    long long ma=-1001001001001000100;
    pro.at(0) = N.at(0)*N.at(2);
    pro.at(1) = N.at(0)*N.at(3);
    pro.at(2) = N.at(1)*N.at(2);
    pro.at(3) = N.at(1)*N.at(3);
    for(int i=0;i<4;i++){
        ma = max(ma,pro.at(i));
    }
    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>

using namespace std;

int N;
int A[100007];
int B[100007];

int main(void){
  scanf("%d",&N);
  for(int i=0;i<=N;i++) scanf("%d",&A[i]);
  for(int i=0;i<N;i++) scanf("%d",&B[i]);
  B[N]=0;
  long long ans=0;
  for(int i=N;i>=0;i--){
  	//printf("%d\n",i);
    if(A[i]<=B[i]){
      ans+=A[i];
      B[i]-=A[i];
      A[i]=0;
    }else{
      ans+=B[i];
      A[i]-=B[i];
      B[i]=0;
      if(i!=0){
        if(A[i]<=B[i-1]){
          ans+=A[i];
          B[i-1]-=A[i];
          A[i]=0;
        }else{
          ans+=B[i-1];
          A[i]-=B[i-1];
          B[i-1]=0;
        }
      }
    }
  }
  printf("%lld",ans);
  return 0;
}
  


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

ll dp[110][110][500];

signed main() {
    // dp[i][j][k]: i(1~N)番目までのアイテムを使い、重さが w_0 *j + k のときの最大の価値
    rep(i,0,110) rep(j,0,110) rep(k,0,500) dp[i][j][k]=-1;

    ll N, W;
    cin>>N>>W;
    vector<ll> w(N+1),v(N+1);
    rep(i,1,N+1)
        cin>>w[i]>>v[i];
    
    dp[0][0][0]=0;
    
    rep(i,1,N+1) rep(j,0,110) rep(k,0,500) {
        if (dp[i-1][j][k]!=-1){
            dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k]);
            // printf("i=%d w=%d -> dp=%d\n", i, w[1]*j+k, dp[i][j][k]);

            dp[i][j+1][k + w[i] - w[1] ] = max(dp[i][j+1][k + w[i] - w[1] ],  dp[i-1][j][k] + v[i]);
            // printf("i=%d w=%d -> dp=%d\n", i, w[1]*(j+1) + k+w[i]-w[1],dp[i][j+1][k + w[i] - w[1] ]);
        }
    }
    
    ll ans = 0;
    rep(j,0,110) rep(k,0,500) {
        if (w[1]*j + k <= W){
            ans = max(ans, dp[N][j][k]);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 50856
#include <bits/stdc++.h>
#define MAX_N 100010
#define N MAX_N
#define rank Asdfiasofsad
#define int long long
using namespace std;

class UF{
public:
  vector<int> par,rank;
  UF(){
    par.resize(MAX_N),rank.resize(MAX_N);
    for(int i=0;i<MAX_N;i++)par[i]=i,rank[i]=0;
  }

  UF(int n){
    par.resize(n),rank.resize(n);
    for(int i=0;i<n;i++)par[i]=i,rank[i]=0;
  }

  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

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

vector<int> G[N];
map<int,int>M[N];
vector<int> grp[N];

typedef pair<int,int> P;
signed main(){
  int n,m;
  cin>>n;
  P C[N];

  for(int i=0,a;i<n;i++)cin>>a,C[i]=P(a,i);

  cin>>m; 
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  UF A; 
  for(int i=0;i<n;i++) M[i][C[i].first] = i;

  for(int i=0;i<n;i++)
    for(int p:G[i])
      if(M[p].count(C[i].first)) A.unite(i,M[p][C[i].first]);
      else M[p][C[i].first] = i;

  for(int i=0;i<n;i++)grp[A.find(i)].push_back(i);

  sort(C,C+n);
  int money[N]={};
  int ans = 0;
  for(int i=0;i<n;i++){
    int c = C[i].first;
    int p = C[i].second;
    if(A.find(p) != p) continue;

    int mx = 0;
    for(int pos:grp[p]){
      mx = max(mx,money[pos]);
      for(int nx:G[pos]) mx = max(mx,money[nx]);
    }
    mx++;
    ans += mx*grp[p].size();
    for(int pos:grp[p]){
      money[pos] = mx;
      for(int nx:G[pos]) money[nx] = mx;
    }
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 54584
import java.lang.StringBuilder

fun main(args: Array<String>) {
    val s = readLine() ?: return
    val builder = StringBuilder()
    var add = true
    for (a in s.toCharArray()) {
        if (add) {
            builder.append(a)
        }
        add = add.not()
    }
    println(builder.toString())
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

void subsetsUtil(vector<LL>& A, vector<vector<LL> >& res,
                 vector<LL>& subset, LL index)
{
    res.push_back(subset);
    for (LL i = index; i < A.size(); i++) {

        subset.push_back(A[i]);

        subsetsUtil(A, res, subset, i + 1);

        subset.pop_back();
    }

    return;
}

vector<vector<LL> > subsets(vector<LL>& A)
{
    vector<LL> subset;
    vector<vector<LL> > res;

    LL index = 0;
    subsetsUtil(A, res, subset, index);

    return res;
}

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

    string s, t;
    cin >> s;

    LL ans = 0;

    LL L = s.size();

    for(LL i = 0; i < L; i++){
        t.Pb(s[i]);
        t.Pb('.');
    }

    L = t.size();
    t.erase(L - 1, 1);

    s = t;

    L--;
    Vl v;
    for(LL i = 1; i < L; i += 2)
        v.Pb(i);

    VVl res = subsets(v);

    LL x = res.size();

    for(LL i = 0; i < x; i++){

        t = s;
        LL y = res[i].size();
        for(LL j = 0; j < y; j++){

            t[res[i][j]] = ' ';
        }
        string ch;

        LL lt = t.size();
        for(LL j = 0; j < lt; j++){
            if(t[j] != '.')
                ch.Pb(t[j]);
        }

        stringstream ss(ch);
        LL num;

        LL S = 0;
        while(ss >> num){
            S += num;
        }

        ans += S;
    }

    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
#階乗#
lim = 50  #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod


	
N, P = MAP()
A = LIST()

if any([x%2 for x in A]):
	print(pow(2, N-1))
else:
	print(pow(2, N) if P == 0 else 0)

Measured memory_bytes: 10356
#include <stdio.h>

int prime(int x){
  int i;
  for(i = 2;i * i <= x;i++)
    if(x % i == 0) return 0;
  
  return 1;
}

int a[1000000], b[1000000];
  
int main(){
  int i;
  for(i = 2; i < 1000000; i++) a[i] = prime(i);
  for(i = 2;i < 1000000;i++){
      b[i] = b[i-1];
    if(a[i] == 1) b[i]++;
  }
  while(scanf("%d", &i)!=EOF){
  printf("%d\n", b[i]);
  }
  return 0;
}


Measured memory_bytes: 9532
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 998244353
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,K = LI()

    d = [0] * N
    d[0] = M

    for i in range(1,N):
        d[i] = (d[i-1] * (M-1)) % MOD

    c = 1
    ans = 0
    for i in range(K+1):
        ans = (ans + d[N-1-i] * c) % MOD
        c = (c * (N-1-i) * pow(i+1,MOD-2,MOD)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71720
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
  int n, c = 0, ans = 300002, si[300002];
  char s[300002];

  if(scanf("%d", &n) == 1);
  if(scanf("%s", s) == 1);

  for(int i = 0; i < n; i++) {
    if(s[i] == 'W') {
      c++;
    }
    si[i] = c;
  }

  for(int i = 0; i < n; i++) {
    if(i == 0) {
      if(ans > n - si[n - 1]) {
        ans = n - si[n - 1];
        if(si[0] == 'W') {
          ans++;
        }
      }
    } else if(i == n - 1) {
      if(ans > si[i - 1]) {
        ans = si[i - 1];
      }
    } else {
      if (ans > si[i - 1] + ((n - si[n - 1]) - (i + 1 - si[i]))) {
        ans = si[i - 1] + ((n - si[n - 1]) - (i + 1 - si[i]));
      }
    }
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
struct Point{
    long long x,y;
    Point():x(0),y(0){}
    Point(long long _x,long long _y):x(_x),y(_y){}
    bool operator<(Point other)const{
        if(x==other.x)return y<other.y;
        return x<other.x;
    }
};
struct Vector{
    long long x,y;
    Vector(long long _x,long long _y):x(_x),y(_y){}
};
Vector to_vector(Point a,Point b){
    return Vector(b.x-a.x,b.y-a.y);
}
long long cross(Vector a,Vector b){
    return (a.x*b.y)-(a.y*b.x);
}
bool ccw(Point a,Point b,Point c){
    return cross(to_vector(a,b),to_vector(a,c))>0;
}
bool collinear(Point a,Point b,Point c){
    return cross(to_vector(a,b),to_vector(a,c))==0;
}
vector<Point> convex_hull(vector<Point> point){
    vector<Point> hull;
    sort(point.begin(),point.end());
    for(int i=0;i<2;i++){
        int start=hull.size();
        for(auto p:point){
            while(hull.size()>=start+2
                &&!ccw(hull[hull.size()-2],hull[hull.size()-1],p)
                &&!collinear(hull[hull.size()-2],hull[hull.size()-1],p))hull.pop_back();
            hull.push_back(p);
        }
        hull.pop_back();
        reverse(point.begin(),point.end());
    }
    return hull;
}
int n;
int main(){
    scanf("%d",&n);
    assert(n>=3);
    vector<Point> point;
    for(int i=0;i<n;i++){
        long long x,y;
        scanf("%lld %lld",&x,&y);
        point.push_back(Point(x,y));
    }
    vector<Point> hull=convex_hull(point);
    int start=0;
    for(int i=1;i<hull.size();i++){
        if(hull[i].y<hull[start].y||(hull[i].y==hull[start].y&&hull[i].x<hull[start].x))start=i;
    }
    printf("%d\n",hull.size());
    for(int i=start;i<hull.size();i++){
        printf("%lld %lld\n",hull[i].x,hull[i].y);
    }
    for(int i=0;i<start;i++){
        printf("%lld %lld\n",hull[i].x,hull[i].y);
    }
    return 0;
}

Measured memory_bytes: 8320
import sys
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  n,m,l,*t=map(int,sys.stdin.buffer.read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  print('\n'.join(map(str,map(int,map(d.__getitem__,zip(*[iter(t[m*3+1:])]*2))))))
main()

Measured memory_bytes: 36284
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

ll ans = 0;

void dfs(vector<vector<int>> &graph, int v, set<int> seen){
	seen.insert(v);
	for (auto nxt: graph[v]){
		if (seen.count(nxt))
			continue;
		dfs(graph, nxt, seen);
	}
	if (graph.size() == seen.size())
		ans++;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(graph, 0, set<int>());
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long sum=0,max=-1000000,min=10000000;
    for(int i=0;i<n;++i){
        long long a;
        cin >> a;
        sum+=a;
        min = (min>a) ? a : min;
        max = (max<a) ? a : max;
    }
    cout << min <<' '<< max <<' '<< sum << endl;
}


Measured memory_bytes: 3104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int a = int.Parse (str[0]);

            Console.Write (a + a * a + a * a * a);
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 27516
import java.util.Scanner;
class Main{

public static void main(String args[]){
  Scanner scanner =new Scanner(System.in);
  int A1= scanner.nextInt();
  int A2= scanner.nextInt();
  int A3= scanner.nextInt();
  int num=A1+A2+A3;

  if(num>=22){
System.out.println("bust");
  }else{
System.out.println("win");

  }
}
}

Measured memory_bytes: 23892
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC117B
int main(void) {
  int max=0, n, k, i, L, cou=0, tmp;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf(" %d", &L);
    cou+=L;
    max=max<L ? L : max;
  }
  if(cou-max>max) printf("Yes");
  else printf("No");
}

Measured memory_bytes: 128
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
dp = [[0] * 3 for _ in range(n+1)]
dp[0] = na()
for i in range(1, n):
    a, b, c = na()
    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
    dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
    dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c)
print(max(dp[n - 1]))



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

int main() {
	int N,D,count = 0;
	cin >> N >> D;
	vector<vector<int>> data(N,vector<int>(D));
	rep(i,N){
        rep(j,D){
            cin >> data.at(i).at(j);
        }
    }
    rep(i,N){
        for(int k = i+1; k < N; k++){
            int norm = 0;//ここで初期化すること
            rep(j,D){
                int diff = abs((data.at(i).at(j)-data.at(k).at(j)));
                norm += diff * diff;
            }
            bool flag = false;//整数か判定部、被判定数xについてx = k*kなる整数kが0<=k<=xにあればxは整数
            for(int l=0;l <= norm; l++){
                if(l*l == norm){
                    flag = true;
                }
            }
            if(flag){
                count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N,M;
  cin >> N >> M;
  pint key[M]={};
  rep(i,M){
    int a,b;
    cin >> a >> b;
    key[i].second=a;
    rep(j,b){
      int c;
      cin >> c;
      c--;
      key[i].first+=1<<c;
    }
  }
  int dp[1<<N];
  rep(i,1<<N) dp[i]=INF;
  dp[0]=0;
  rep(i,1<<N){
    rep(j,M){
      int open=i|key[j].first;
      int cost=dp[i]+key[j].second;
      dp[open]=min(dp[open],cost);
    }
  }
  if(dp[(1<<N)-1]==INF) cout << -1 << endl;
  else cout << dp[(1<<N)-1] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int input = sc.nextInt();
    int output;
    if(input < 10){
      output = input;
    }else if(input < 100){
      output = 9;
    }else if(input < 1000){
      output = 9 + input - 99;
    }else if(input < 10000){
      output = 9 + 900;
    }else if(input < 100000){
      output = 9 + 900 + input - 9999;
    }else{
      output = 90909;
    }
    System.out.println(output);
  }
}

Measured memory_bytes: 21972
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
num_either = 0
num_A = 0
num_B = 0

count = 0
for _ in range(N):
	s = input()
	if s[-1] == "A" and s[0] == "B":
		num_either += 1
	elif s[-1] == "A":
		num_A += 1
	elif s[0] == "B":
		num_B += 1

	for i, char in enumerate(s):
		if i == len(s)-1:
			break
		if s[i] == "A" and s[i+1] == "B":
			count += 1

if num_either >= 2:
	count += num_either-1
	num_either = 1
if num_A == 0 and num_B == 0:
	print(count)
else:
	if num_either == 1:
		count += min(num_A, num_B)+1
		print(count)
	else:
		count += min(num_A, num_B)
		print(count)



Measured memory_bytes: 3896
#include<cstdio>
#include<iostream>

using namespace std;

int a, b;
int gcd, lcm;

void GCD(){

	int big, small;

	big = a;
	small = b;

	while (big) {
		if (small > big) swap(big, small);
		big = big % small;
	}
	gcd = small;

}

void LCM() {
	lcm = a / gcd * b;
}




int main(){
	while (cin >> a >> b) {

		GCD();
		LCM();
		cout << gcd << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N = int(input().strip())
sirito_list = []
is_siritori = True
for _ in range(N):
  if not sirito_list:
    sirito_list.append(input().strip())
  else:
    tmp_word = input().strip()
    if tmp_word[0] != sirito_list[-1][-1] or tmp_word in sirito_list:
      print('No')
      is_siritori = False
      break
    else:
      sirito_list.append(tmp_word)
if is_siritori:
  print('Yes')
 

Measured memory_bytes: 2940
function check(H,W,x,y,s)
  
  if x < H && s[x+1][y] == '#'
    return true
  end
  
  if x > 1 && s[x-1][y] == '#'
    return true
  end
  
  if y < W && s[x][y+1] == '#'
    return true
  end
  
  if y > 1 && s[x][y-1] == '#'
    return true
  end
  
  return false
  
end

function main()
  
  (H,W) = map(x -> parse(Int,x), split(readline()))
  s = chomp.(readlines())
  
  ans_check = false
  
  for i in 1:H
    for j in 1:W
      
      if s[i][j] == '#' && !check(H,W,i,j,s)
        ans_check = true
        break
      end
      
    end
  end
  
  if ans_check
    println("No")
  else
    println("Yes")
  end
  
end

main()

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

int main(){
  double n;
  cin >>n;
  for(double i=1;i<=3500;i++){
    for(double j=1;j<=3500;j++){
      double ans1=4/n-1/i-1/j;
      if(ans1<0){
        continue;
      }
      double ans2=1/ans1;
      if(ans2>3500){
        continue;
      }
      int a= ans2;
      for(int k=-1;k<=1;k++){
        long long c=a;
        c+=k;
        long long d=4*c*i*j;
        long long e=n*(c*i+i*j+j*c);
        if(d==e){
          cout << i << " "<<j<<" "<< c;
        return 0;
        }
      }
    }
  }
      
  
}


Measured memory_bytes: 256
// Coordinate compression

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
//#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)



int solve()
{

int n,a,b;
cin>>n>>a>>b;
int pos[2010];
int ans[2010]={0};

rep(i,1,n+1)
{
   rep(j,i,n+1)pos[j]=j-i+1;
   rep(j,1,i)pos[j]=i-j+1;
   pos[b]=min(pos[b],pos[a]+1);

   rep(j,b+1,n+1)
   {
    pos[j]=min(pos[j],pos[j-1]+1);
   }
   for(int j=b-1;j>=1;j--)pos[j]=min(pos[j],pos[j+1]+1);
 

  rep(j,i+1,n+1)ans[pos[j]-pos[i]]++;
}


rep(i,1,n)
{
  cout<<ans[i]<<endl;
}


  return 0;
}


 
signed main()
{  int t=1;

 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
     
                               
 
  clock_t time_req;
                                                                                                                   
//cin>>t;
 
    int k=1;
     
   while(t--)
     {
      solve();
     }
        exit(0);
 
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
    return 0;
 
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;
const ld INF = 1e18;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int a[n],fl = 0;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++)fl |= (!a[i]);
        if(fl)return cout<<0,0;
        fl = 1;
        for(int i=0;i<n;i++)fl &= (a[i]<=INF);
        if(!fl)return cout<<-1,0;
        sort(a,a+n);
        ld ans = 1;
        for(int i=0;i<n;i++)
        {
            ans *= (ld)a[i];
            if(ans > INF){ans = -1;break;}
        }
        int fans = ans;
        cout<<fans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4396
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 14:41:02 2020

@author: shinba
"""

n,m = map(int,input().split())

data = []
relay = []

for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        relay.append(b)
    else:
        if b == n:
            data.append(a)

ans = set(relay) & set(data)

if len(ans) >= 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


        

Measured memory_bytes: 21828
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;++i) cin >> a[i];
    double sum=0;
    for(int i=0;i<n;++i) {
        sum+=1.0/a[i];
    }
    double ans=1.0/sum;
    cout << fixed << setprecision(10) << ans << endl;
}



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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int cnt;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < 3; ++i)
		cnt += s[i] == t[i];
	cout << cnt;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R: std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read {
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0;
        self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {
                break;
            }
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_a<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let n: i32 = r.read_a();
    let m: i32 = r.read_a();
    let x: i32 = r.read_a();
    let mut c: Vec<i32> = Vec::new();
    let mut a: Vec<Vec<i32>> = Vec::new();
    for i in 0..n as usize {
        c.push(r.read_a());
        a.push(Vec::new());
        for j in 0..m {
            a[i].push(r.read_a());
        }
    }

    let max = 2_i32.pow(n as u32);
    let mut ans = std::i32::MAX;
    for mut i in 1..max {
        let mut tmp = 0;
        let mut sum = vec![0; m as usize];
        for j in 0..n as usize {
            if i & 1 == 1 {
                tmp += c[j as usize];
                for k in 0..m as usize {
                    sum[k] += a[j as usize][k];
                }
            }
            i >>= 1;
            if i <= 0 {
                break;
            }
        }
        let mut flg = true;
        for j in 0..m as usize {
            if sum[j] < x {
                flg = false;
            }
        }

        ans = if ans > tmp && flg { tmp } else { ans };
    }

    println!("{}", if ans != std::i32::MAX { ans } else { -1 });
}


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

int main() {
  int N,M,C,ans=0,c=0;
  cin>>N>>M>>C;
  int b[M];
  for(int i=0;i<M;i++){
    cin>>b[i];
  }
  for(int i=0;i<N;i++){
    c=0;
    for(int j=0;j<M;j++){
      int a=0;
      cin>>a;
      //cout<<a;
      c+=a*b[j];
    }
    if(c+C>0){
      ans++;
    }
  }
  cout<<ans;
  
    
}

Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    if n % 2 == 0 {
        println!("0.5");
    } else {
        let n_odd = n / 2 + 1;
        println!("{}", (n_odd as f64)/(n as f64));
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
#define all(x) (x).begin(),(x).end()
using namespace std;
vector<int> v[200010];
int x[200010];
bool used[200010];
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a*b/gcd(a,b);
}
void mutu(int a,int z){
	x[a]+=z;
	used[a]=true;
	f(i,v[a].size()){
		if(!used[v[a][i]])mutu(v[a][i],x[a]);
	}
}
signed main(){
	int n,m;
	cin>>n>>m;
	f(i,n-1){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	f(i,m){
		int a,b;
		cin>>a>>b;
		x[a]+=b;
	}
	mutu(1,0);
	f(i,n){
		if(i)cout<<" ";
		cout<<x[i+1];
	}
}


Measured memory_bytes: 24448
import math
n = int(input())
x_datas = list(map(int, input().split()))
y_datas = list(map(int, input().split()))
length = len(x_datas)

# p=1の時
# ミンコフスキー距離を求める
D1 = 0
for i in range(length):
    D1 += math.fabs(x_datas[i] - y_datas[i])
print(D1)

# p=2の時
# マンハッタン距離を求める
D2_sum = 0
for i in range(length):
    D2_sum += math.fabs(x_datas[i] - y_datas[i]) ** 2
    D2 = math.sqrt(D2_sum)
print(D2)

# p=3の時
D3_sum = 0
for i in range(length):
    D3_sum += math.fabs(x_datas[i] - y_datas[i]) ** 3
    D3 = pow(D3_sum, 1/3)
print(D3)

# p =∞の時
# ユークリッド距離を求める
D4 = []
for i in range(length):
    D4.append(math.fabs(x_datas[i] - y_datas[i]))
print(max(D4))



Measured memory_bytes: 5716
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

    vector<int> as(n);
    for(int i = 0; i < n; i++) {
        cin >> as[i];
    }

    sort(as.begin(), as.end());

    long long h = 0, w = 0;
    for(int i = n-1; i > 0; i--) {
        if (as[i] == as[i-1]) {
            if (h == 0) h = as[i];
            else if (w == 0) w = as[i];
            else break;
            i--;
        }
    }

    cout << h * w << endl;

}


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

int main(){
int X;
  cin>>X;
  
  int ans=0;
  for(int i=1; i<35; i++){
   for(int j=2; j<11; j++){
    int n=pow(i,j);
    if(n>X){break;} 
    if(n>ans){ans=n;} // breakしない場合のみansは更新される
   }
  }
  
  cout<<ans;
}

Measured memory_bytes: 256