akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int hang, lie;
int n, m, a, b;
char s[1020][1020];

void caonima(int a, int b, int niubi) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			s[i][j] = '.';
		}
	}
	if (m % 2 == 1) {
		for (int i = 0; i + 1 < n; i += 2) {
			if (b >= 1) {
				s[i][m - 1] = '^';
				s[i + 1][m - 1] = 'v';
				b -= 1;
			} else {
				s[i][m - 1] = '.';
				s[i + 1][m - 1] = '.';
			}
		}
	}
	if (n % 2 == 1) {
		for (int j = 0; j + 1 < m; j += 2) {
			if (a >= 1) {
				s[n - 1][j] = '<';
				s[n - 1][j + 1] = '>';
				a -= 1;
			} else {
				s[n - 1][j] = '.';
				s[n - 1][j + 1] = '.';
			}
		}
	}
	if (niubi && n >= 3 && m >= 3 && n % 2 == 1 && m % 2 == 1 && a >= 1 && b >= 1) {
		s[n - 3][m - 3] = '<';
		s[n - 3][m - 2] = '>';
		s[n - 3][m - 1] = '^';
		s[n - 2][m - 1] = 'v';
		s[n - 2][m - 3] = '^';
		s[n - 1][m - 3] = 'v';
		s[n - 1][m - 2] = '<';
		s[n - 1][m - 1] = '>';
		a -= 1;
		b -= 1;
	}
	for (int i = 0; i + 1 < n; i += 2) {
		for (int j = 0; j + 1 < m; j += 2) {
			if (s[i][j] != '.') {
				continue;
			}
			if (a >= 2) {
				s[i][j] = '<';
				s[i][j+1] = '>';
				s[i+1][j] = '<';
				s[i+1][j+1] = '>';
				a -= 2;
			} else if (a == 1) {
				s[i][j] = '<';
				s[i][j+1] = '>';
				s[i+1][j] = '.';
				s[i+1][j+1] = '.';
				a -= 1;
			} else if (b >= 2) {
				s[i][j] = '^';
				s[i][j+1] = '^';
				s[i+1][j] = 'v';
				s[i+1][j+1] = 'v';
				b -= 2;
			} else if (b == 1) {
				s[i][j] = '^';
				s[i][j+1] = '.';
				s[i+1][j] = 'v';
				s[i+1][j+1] = '.';
				b -= 1;
			} else {
				s[i][j] = '.';
				s[i][j+1] = '.';
				s[i+1][j] = '.';
				s[i+1][j+1] = '.';
			}
		}
	}
	if (a == 0 && b == 0) {
		printf("YES\n");
		for (int i = 0; i < n; i++) {
			printf("%s\n", s[i]);
		}
		exit(0);
	}
}
int main() {
	cin >> n >> m >> a >> b;
	caonima(a, b, 0);
	caonima(a, b, 1);
	printf("NO\n");
	exit(0);
}

Measured memory_bytes: 2176
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define moder 1000000007
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, k, a[55], r[55];
signed main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
		r[i] = a[i];
		if (i)r[i] += r[i - 1];
	}
	vector<int> vec;
	int ans = 0;
	rep(i, min(n, k) + 1) {
		for (int j = 0; j <= i; j++) {
			vec.clear();
			int sum;
			if (j)sum = r[j - 1] + r[n - 1] - r[n - 1 - (i - j)];
			else sum = r[n - 1] - r[n - 1 - (i - j)];
			rep(l, j)vec.push_back(a[l]);
			for (int l = n - 1; l >= n - (i - j); l--)vec.push_back(a[l]);
			sort(vec.begin(), vec.end());
			for (int l = 0; l < vec.size() && l < k - i; l++) {
				if (vec[l] >= 0)break;
				sum -= vec[l];
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
c,s,f=[],[],[]
for i in range(n-1):
    a=list(map(int,input().split()))
    c.append(a[0])
    s.append(a[1])
    f.append(a[2])
for i in range(n-1):
    tot=s[i]
    for j in range(i,n-1):
        tot+=c[j]
        if j!=n-2:
            if tot<s[j+1]: tot+=s[j+1]-tot
            else:
                if (tot-s[j+1])%f[j+1]!=0: tot+=f[j+1]-(tot-s[j+1])%f[j+1]
    print(tot)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
 
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
 
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;
}
///////////////////////////////////////////////
/* (๑╹最強╹) */




int main() {
    int N,t,x,x1,y,y1;
    string ans;
    x = y = 0;
    cin >> N;
    ans = "Yes";
    rep(i,N)
    {
        cin >> t >> x1 >> y1;
        if ((x1-x)+(y1-y) <= t && ((x1-x)+(y1-y)) %2 == t % 2)
        continue;
        else
        {
            ans = "No";
        }
        
    }
cout << ans << endl;

}

Measured memory_bytes: 384
N = int(input())
As = list(map(int, input().split()))

count = 0
state = 0
beforeA = As[0]
for A in As:
    if A > beforeA:
        if state == 0 or state == 1:
            state = 1
        else:
            count += 1
            state = 0
    if A < beforeA:
        if state == 0 or state == 2:
            state = 2
        else:
            count += 1
            state = 0
    beforeA = A

print(count+1)


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,h,w,ans=0;
	cin>>n>>h>>w;
	int a[n],b[n];
	for (int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		if (a[i]>=h && b[i]>=w)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

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

    if (a >= b && a >= c) {
        cout << 10*a + b + c << endl;
    }
    else if (b >= a && b >= c) {
        cout << 10*b + a + c << endl;
    }
    else { // max:c
        cout << 10*c + a + b << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
using namespace atcoder;
using mint = modint998244353;
struct S {
    mint a;
    int size;
};

struct F {
    mint a, b;
};

S op(S l, S r) {
    return S{l.a + r.a, l.size + r.size};
}

S e() { return S{0, 0}; }

S mapping(F l, S r) {
    return S{l.a * r.a + l.b * r.size, r.size };
}

F composition(F l, F r) {
    return F{l.a * r.a, l.a * r.b + l.b };
}

F id() {
    return F{1, 0};
}

void Main()
{
    ll n, Q;
    cin >> n >> Q;

    vector<S> a(n);
    rep(i, n) {
        int ai;
        cin >> ai;
        a[i] = S{ai, 1};
    }
    
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    rep(i, Q) {
        int t;
        cin >> t;
        if (t == 0) {
            int l, r, b, c;
            cin >> l >> r >> b >> c;
            seg.apply(l, r, F{b, c});
        }
        else {
            int l, r;
            cin >> l >> r;
            put(seg.prod(l, r).a.val());
        }
    }
}
signed main(){ Main();return 0;}

Measured memory_bytes: 19340
N,M=map(int,input().split())
LR=set(range(N+1))
l=[]
r=[]
for i in range(M):
    L,R=map(int,input().split())
    l.append(L)
    r.append(R)
ans=min(r)-max(l)+1
if ans<0:
    ans=0
print(ans)

Measured memory_bytes: 25320
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(1)
    {
        c=c-b;
        if(c<=0)
            break;
        a=a-d;
        if(a<=0)
            break;
    }
    if(c<=0)
        printf("Yes\n");
    else
       printf("No\n");
}


Measured memory_bytes: 1664
from bisect import *
a, b, q = map(int,input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
inf = 10 ** 18
s = [-inf] + s + [inf]
t = [-inf] + t + [inf]

for i in range(q):
    x = int(input())
    s_ind = bisect_left(s, x)
    t_ind = bisect_left(t, x)
    
    res = inf
    for cand_s in [s[s_ind - 1], s[s_ind]]:
        for cand_t in [t[t_ind - 1], t[t_ind]]:
            st = abs(cand_s - cand_t)
            dx = min(abs(cand_s - x), abs(cand_t - x))
            
            res = min(res, st + dx)
    
    print(res)

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

int main() {
  int a, b; std::cin >> a >> b;
  int d = std::abs(a-b);
  if (d%2 == 0) std::cout << d/2 + (a > b ? b : a) << std::endl;
  else std::cout << "IMPOSSIBLE" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3624
def roof10(n):
    if n%10==0:
        return n
    else:
        return 10*(n//10+1)

A=[]
N=5
for i in range(N):
    A.append(int(input()))
B=[roof10(A[n]) for n in range(N)]
x=max([B[n]-A[n] for n in range(N)])
print(sum(B)-x)

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

int dp[10000000],dp2[10000000];

int f(int a){
  if(dp2[a])return dp2[a];
  int tmp=a;
  while(tmp>=10)tmp/=10;
  return dp2[a]=tmp;
}
int g(int a){
  if(dp[a])return dp[a];
  for(int i=100;i<100000000;i*=10)if(a<i)return dp[a]=i/10;
  return 0;
}

signed main(){
  int n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int t=f(i);
    for(int j=t;j<=i;j+=10){
      while(j<=n&&f(j)!=i%10)j+=g(j);
      if(f(j)==i%10&&j<=i)ans+=1+(i!=j);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3072
a,b,c,x,y=map(int,input().split())
abget=min(a+b,2*c)
aget=min(a,2*c)
bget=min(b,2*c)
xyget=min(x,y)
ans=xyget*abget
if x>y:
  ans+=(x-xyget)*aget
elif y>x:
  ans+=(y-xyget)*bget
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N, b;
  scanf("%d%d", &N, &b);
  auto a = -10000;
  auto f = 0, g = 0;
  while (--N) {
    int c;
    scanf("%d", &c);
    auto h = min(f + abs(a - c), g + abs(b - c));
    a = b;
    b = c;
    f = g;
    g = h;
  }
  printf("%d\n", g);
  return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

struct UnionFind
{
	vector<ll> par;

	void init(ll n) {par.assign(n, -1);}

	ll root(ll x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool unit(ll x, ll y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	ll size(ll x)
	{
		return -par[root(x)];
	}
};

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<ll> P(N); REP(i, N) cin >> P[i], --P[i];
	UnionFind uf;
	uf.init(N);

	REP(i, M)
	{
		ll x, y; cin >> x >> y;
		--x, --y;
		uf.unit(x, y);
	}

	ll res{0};

	REP(i, N)
	{
		if (uf.root(i) == uf.root(P[i]))
			++res;
	}

	std::cout << res << std::endl;
}


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

using namespace std;

#define MAX 514

string S;
int memo[MAX][MAX];

bool rec(int L,int R){
    int &res = memo[L][R];
    if(res != -1) return res;
    if(L > R) return 1;
    if(S[L] != 'm' || S[R] != 'w') return (res = 0);
    res = 0;
    for(int i = L+1 ; i < R ; i++){
        if(S[i] == 'e'){
            res = max(res,rec(L+1,i-1)&rec(i+1,R-1));
        }
    }
    return res;
}

int main(){
    cin >> S;
    memset(memo,-1,sizeof(memo));
    cout << (rec(0,S.size()-1) ? "Cat" : "Rabbit") << endl;
    return 0;
}

Measured memory_bytes: 2232
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = Counter(a)
a = a.most_common()
p = len(a)
ans = 0
for i in range(-1,-n-1,-1):
    if p <=k:break
    ans += a[i][1]
    p-=1

print(ans)


Measured memory_bytes: 37788
//=template===================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <map>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef struct {
  LL cost;
  bool done;
} node_t;

// conversion
inline int
toInt(string s)
{
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//============================================================================//

//=function prototype=========================================================//

//============================================================================//

//=variables==================================================================//

//============================================================================//
int main(void)
{
  // Scan begin.
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  // Scan done.

  // Code begin.
  if (x1 == 0) { cout << "1" << endl; }
  if (x2 == 0) { cout << "2" << endl; }
  if (x3 == 0) { cout << "3" << endl; }
  if (x4 == 0) { cout << "4" << endl; }
  if (x5 == 0) { cout << "5" << endl; }
  // Code done.

  return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

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

	cin >> a >> b >> c >> x >> y;

	int ans = 0x7F7F7F7F;

	int totalA = 0;
	int totalB = 0;
	int totalC = 0;
	if (a + b > c * 2)
	{
		int cnum = min(x, y);
		totalC = cnum * 2 * c;
		x -= cnum;
		y -= cnum;
	}

	if (a > c * 2)
	{
		totalC += x * 2 * c;
		x -= x;
		y -= x;
	}
	else
	{
		totalA = x * a;
		x -= x;
	}

	if (b > c * 2)
	{
		totalC += y * 2 * c;
		x -= y;
		y -= y;
	}
	else
	{
		totalB = y * b;
		y -= y;
	}
	cout << (totalA + totalB + totalC) << endl;

	return 0;
}


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

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  char dif='A'-'a';
  printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
  return 0;
}


Measured memory_bytes: 256
S1 = list(input())
T = list(input())
S = S1.copy()
find = False
for i in range(len(S1) - 1, len(T) - 2, -1):
    if S1[i] == T[-1] or S1[i] == '?':
        if len(T) > 1:
            for j in range(1, len(T)):
                if S1[i - j] != '?' and S1[i - j] != T[len(T) - j - 1]:
                    possible = False
                    break
                elif j == len(T) - 1:
                    find = True
        else:
            find = True
        if find:
            S[i - len(T) + 1:i + 1] = T
            break
if find:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
def solve():
    N, K = map(int, input().split())
    if K&1:
        return str((N//K)**3)
    else:
        i = K//2
        a, b = N//K, N%K
        c = a+(b>=i)-(i==0)
        return str(c**3+a**3)
    return str(m)

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3060
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = int(input())
    ans = [0]*(10**4+1)
    h = 0

    for i in range(1,99):
        for j in range(1,99):
            for m in range(1,99):
                h = i**2 + j**2 + m**2 + i*j + j*m + m*i
                if h >= (10**4)+1:
                    break
                ans[h] += 1

    for i in range(1,n+1):
        print(ans[i])

if __name__ == '__main__':
	main()


Measured memory_bytes: 9700
object Main{
  def main(args:Array[String]) = {
    val list = scala.io.StdIn.readLine.split(" ").map(_.toLong).toList;
    val ans = list(0) * 100 + list(1) * 10 + list(2)
    if(ans % 4 == 0)
      println("YES")
    else
      println("NO")
  }
}

Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
string str[2];
int n,ima;


int stoi(int &i){
  int res=0;
  while('0'<=str[ima][i]&&str[ima][i]<='9')res=res*10+str[ima][i]-'0',i++;
  return res;
}


int main(){
  while(1){

    cin>>str[1]>>n;
    if(str[1]=="0"&&n==0)break;
    str[0].clear();
    for(int i=0;i<str[1].size();i++) {
      if(str[1][i]=='('&&str[1][i+2]==')') str[0]+=str[1][i+1],i+=2;
      else str[0]+=str[1][i];
    }
    str[1].clear();    

    ima=0;
    int f=1;
    int flg=1;
    while(f){
      f=0;
      str[!ima].clear();
      for(int i=0;i<(int)str[ima].size();i++){
	if(!('0'<=str[ima][i]&&str[ima][i]<='9')) str[!ima]+=str[ima][i];
	else {
	  f=1;
	  int num=stoi(i);
	  string pls;
	  if(str[ima][i]!='(') pls+=str[ima][i];
	  else {
	    int c=1;
	    while(c){
	      i++;
	      if(str[ima][i]=='(')c++;
	      if(str[ima][i]==')')c--;
	      if(c) pls+=str[ima][i];
	    }
	  }
	  while(num--&&(int)str[!ima].size()<=n) str[!ima]+=pls;
	}
      }
      
      ima=!ima;
    }
    //cout <<str[ima]<<endl;
    if((int)str[ima].size()<=n&&flg) cout <<0<<endl;
    else cout << str[ima][n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int N;
   cin>>N;
   int flag=1;
   for(int i=0;i<=N/4;i++){
      for (int j = 0; j <= N/7; j++)
      {
         if(4*i+7*j==N){
            cout<<"Yes";
            flag=0;
         }
         if(flag==0){
            return 0;
         }

      }
      
   }
   if(flag==1){
      cout<<"No";
   }
   return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;

	ll N = 1e6 + 10;
	vl cnt(N), ok(N,1);
	FOR(i,0,n) {
		ll x; cin >> x;
		cnt[x]++;
	}
	
	ll res = 0;
	FOR(i,1,N) if (cnt[i]) {
		if (cnt[i] > 1) ok[i] = 0;
		else res += ok[i];
		for (ll j = 2*i; j < N; j += i) ok[j] = 0;
	}
	cout << res << endl;
}



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

typedef long long ll;
typedef std::pair<ll, ll> P;
typedef std::tuple<ll, ll, ll> t3;
constexpr ll INF = 1e15;
constexpr ll mod = 1e9+7;

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

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


class Divisor {
private:
	vector<ll> F;
public:
	Divisor(ll N) {
		for (ll i = 1; i * i <= N; i++) {
			if (N % i == 0) {
				F.push_back(i);
				if (i * i != N) F.push_back(N / i);
			}
		}
		sort(begin(F), end(F));
	}
	int size() { return F.size(); }
	ll operator[](int k) { return F[k]; }
	const vector<ll>& factors() { return F; }
};

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<bool> ws(n, 0);
	rep(i, n) {
		ws[i] = s[i] == 'W';
	}
	int j = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (ws[i]) {
			ll dist = i - j;
			sum += dist;
			j++;
		}
	}
	cout << sum << endl;
	return 0;
}


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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 1000000000000000000
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  vector<int>a(5);
  int k;
  for(int i=0;i<5;i++)cin>>a[i];
  cin>>k;
  bool ans = true;
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(abs(a[i]-a[j]>k))ans=false;
    }
  }
  if(ans)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
  return 0;
}




Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] x = new long[n];
        for(int i = 0; i < n; i++){
            x[i] = sc.nextLong();
        }
        int[][] d = new int[n][45];
        int[] cnt0 = new int[45], cnt1 = new int[45];
        for(int i = 0; i < n; i++){
            d[i] = func(x[i]);
            for(int j = 0; j < 45; j++){
                if(d[i][j] == 0){
                    cnt0[j]++;
                }
                else if(d[i][j] == 1){
                    cnt1[j]++;
                }
            }
        }
        long ans = 0;
        int j = 44;
        long tmp = 0;
        while(j >= 0){
            if(cnt0[j] > cnt1[j]){
                tmp = ans + (long) Math.pow(2, j);
            }
            if(tmp <= k) ans = tmp;
            j--;
        }
        long aans = 0;
        for(int i = 0; i < n; i++){
            aans += x[i] ^ ans;
        }
        System.out.println(aans);

/*        long max = 0; int maxindex = -1;
        for(int z = 1; z <= k; z++){
            long ttmp = 0;
            for(int i = 0; i < n; i++){
                ttmp += x[i] ^ z;
            }
            if(ttmp > max){
                max = ttmp;
                maxindex = z;
            }
        }
        System.out.println(maxindex + " " + max);*/
    }
    static int[] func(long x){
        int index = 0;
        long n = x;
        int[] res = new int[45];
        while(n > 0){
            res[index] = (int) (n % 2);
            index++;
            n /= 2;
        }
        return res;
    }
}

Measured memory_bytes: 80888
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll a[410];
ll dp[410][410];
ll S[410];

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    std::cin >> a[i];

    S[i+1] = S[i]+a[i];
  }

  rep( i, N+1 ) rep( j, N+1 )
    dp[i][j] = INF;

  rep( i, N )
    dp[i][i] = 0;

  repi( l, 1, N+1 ) rep( i, N-l ) repi( k, i, i+l )
    chmin( dp[i][i+l], dp[i][k]+dp[k+1][i+l]+S[i+l+1]-S[i] );

  std::cout << dp[0][N-1] << std::endl;

  return 0;
}

Measured memory_bytes: 1536
import sys
from scipy.sparse.csgraph import dijkstra

input = sys.stdin.readline
N, M = map(int, input().split())

graph = [[0 if i == j else float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    ai, bi, ci = map(int, input().split())
    graph[ai - 1][bi - 1] = ci
    graph[bi - 1][ai - 1] = ci

dist = dijkstra(graph, directed=False)

cnt = 0
for i in range(N):
    for j in range(N):
        used = False
        if i > j:
            continue
        for k in range(N):
            if graph[i][j] + dist[k][i] == dist[i][j]:
                used = True
                break
        if not used and graph[i][j] != float("inf"):
            cnt += 1
print(cnt)


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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int ans[s.size()];
	for (int i = 0; i < s.size(); ++i)
	{
		ans[i]=1;
	}
	for (int i = 0; i < s.size()-1; ++i)
	{
		if (s.at(i)=='R'&&s.at(i+1)=='R')
		{
			ans[i+2]+=ans[i];
			ans[i]=0;
		}
	}
	for (int i = s.size()-1; i > 0; --i)
	{
		if (s.at(i)=='L'&&s.at(i-1)=='L')
		{
			ans[i-2]+=ans[i];
			ans[i]=0;
		}
	}
	cout<<ans[0];
	for (int i = 1; i < s.size(); ++i)
	{
		cout<<" "<<ans[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1024
n, q = map(int, input().split())
prcs = []
for _ in range(n):
    nm, tm = input().split()
    prcs.append([nm, int(tm)])
elps = 0
while prcs != []:
    tmp = prcs.pop(0)
    if tmp[1] - q > 0:
        tmp[1] = tmp[1] - q
        prcs.append(tmp)
        elps += q
    else:
        elps += tmp[1]
        print(tmp[0], elps)


Measured memory_bytes: 13012
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, M, X; cin >> N >> M >> X;
  vector<int> A(M);
  for(auto& a : A) {
    cin >> a;
  }

  vector<bool> road(N, false);
  for(auto a : A) {
    road[a] = true;
  }

  int left_cost = 0, right_cost = 0;
  for(int i = 0; i < X; i++) {
    if(road[i]) {
      left_cost++;
    }
  }
  for(int i = N - 1; i >= X; i--) {
    if(road[i]) {
      right_cost++;
    }
  }

  cout << min(left_cost, right_cost) << endl;
}


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D)
    cout<<"Left"<<endl;
  if(A+B==C+D)
    cout<<"Balanced"<<endl;
  if(A+B<C+D)
    cout<<"Right"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, K;
  cin >> N >> K;
  vector<ll> V(N);
  REP(i, N) cin >> V[i];
  
  ll ans = 0;
  if (N <= K) {
    for (auto& e : V) {
      ans += max(0LL, e);
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> Vr(V);
  reverse(ALL(Vr));

  REP(i, K + 1) {
    REP(j, K - i + 1) {
      vector<ll> v;
      REP(k, i) v.PB(V[k]);
      REP(k, j) v.PB(Vr[k]);
      if (v.empty()) {
        continue;
      }
      sort(ALL(v));
      ll tmp = 0;
      REP(k, v.size()) tmp += v[k];
      REP(k, K-i-j) {
        if (k >= v.size() || v[k] > 0) break;
        tmp -= v[k];
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque


class LowestCommonAncestor():
    """根付き木に対して、二頂点の共通の祖先で最も近いところにある頂点を求める
    初期化(ダブリング配列parent[k][v]の構築): O(NlogN)
    lcaを求めるクエリ: O(logN)
    """
    
    def __init__(self, tree, root):
        self.n = len(tree)
        self.depth = [0] * self.n
        self.log_size = (self.n).bit_length()
        self.parent = [[-1] * self.n for i in range(self.log_size)]

        # 親を2^0回たどって到達する頂点、つまり現在の頂点に対する親の頂点を求める
        # parent[0][現在の頂点] = 親の頂点
        q = deque([(root, -1, 0)]) # (現在の地点, 親の頂点, 現在の頂点と親の頂点間の距離) 
        while q:
            v, par, dist = q.pop()
            self.parent[0][v] = par
            self.depth[v] = dist
            for child_v in tree[v]:
                if child_v != par:
                    self.depth[child_v] = dist + 1
                    q.append((child_v, v, dist + 1))

        # ダブリングで親を2^k回たどって到達する頂点を求める
        for k in range(1, self.log_size):
            for v in range(self.n):
                self.parent[k][v] = self.parent[k-1][self.parent[k-1][v]]
            
    def lca(self, u, v):
        # u, vのうち深いところにある方から|depth[u] - depth[v]|だけ親をたどる
        if self.depth[u] > self.depth[v]:
            u, v = v, u
        for k in range(self.log_size):
            if (self.depth[v] - self.depth[u] >> k) & 1:
                v = self.parent[k][v]
        if u == v:
            return u
          
        # 二分探索でLCAを求める
        for k in reversed(range(self.log_size)):
            if self.parent[k][u] != self.parent[k][v]:
                u = self.parent[k][u]
                v = self.parent[k][v]
        return self.parent[0][u]


n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
tree = [[] for i in range(n)]
for i in range(n):
    for j in info[i][1:]:
        tree[i].append(j)
        tree[j].append(i)

lca = LowestCommonAncestor(tree, 0)

q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    u, v = query[i]
    print(lca.lca(u, v))


Measured memory_bytes: 69052
#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int H, W;
    vector<int> h;
    vector<int> w;
    int count = 0;

    while(1)
    {
        cin >> H >> W;
        if(H == 0 && W == 0)
            break;
        else
        {
            h.push_back(H);
            w.push_back(W);
            count++;
        }
    }
    for(int i = 0; i < count; i++)
    {
        for(int j = 0; j < h[i]; j++)
        {
            for(int k = 0; k < w[i]; k++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
} 

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;

string s;
string t;
int p[100005],q[100005];
int main(){
    int qq;
    cin >> s >> t >> qq;
    int ss = (int)s.size();
    int tt = (int)t.size();
    rep(i,ss){
        p[i+1]=p[i];
        if(s[i]=='A')p[i+1]++;
    }
    rep(i,tt){
        q[i+1]=q[i];
        if(t[i]=='A')q[i+1]++;
    }
    int a,b,c,d;
    rep(i,qq){
        cin >> a  >> b >> c >> d;
        if((b-a+1+p[b]-p[a-1])%3==(d-c+1+q[d]-q[c-1])%3){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main(){
   //freopen("in.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   ll t,nahi=0;
   string s1,s2;
   cin>>s1>>s2;
   f(i,0,s1.length()){
	   	if(s1[i]!=s2[i]){
	   		nahi=1;
	   	}
   }
   if(nahi==1) cout<<"No"<<endl;
   else cout<<"Yes"<<endl;

  
}



Measured memory_bytes: 3636
[N,K] = list(map(int,input().split()))

nino_ijo=[0]*21
for i in range(21):
    nino_ijo[i] = 2**i
# print('nino:', nino_ijo)

out=0
for i in range(1,N+1):
    # print('i:',i)
    for j in range(21):
        if i*(2**j) >= K:
            out += (1/N) * ((1/2)**j)
            break
    # print('out:',out)
print(out)


Measured memory_bytes: 66848
#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)
 
N,K=gets.split.map(&:to_i)
V=gets.split.map(&:to_i)
R=[N,K].min

G1=[]
temp=[]
G1 << temp.dup
(R+1).times do |i|
  temp << V[i]
  G1 << temp.dup
end

G2=[]
temp=[]
G2 << temp.sort
(R+1).times do |i|
  temp << V[-i-1]
  G2 << temp.dup
end

max=0
(R+1).times do |i|
  (R+1).times do |j|
    next if i+j>R
    vs=([0]+G1[i]+G2[j]).sort
    sum=vs.inject(:+)
    (K-(i+j)).times do
      if vs.size>0 && vs[0]<0
        v=vs.shift
        sum-=v
      end
    end
    #p [i,j,sum]
    max=sum if sum>max
  end
end
p max

Measured memory_bytes: 2300
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}
int main(void) {
    int n;
    std::cin >> n;
    std::vector<int> a(n);  // rate
    std::cin >> a;
    /**
     * [0]~399 : gray
     * [1]~799 : brown
     * [2]~1199: green
     * [3]~1599: water
     * [4]~1999: blue
     * [5]~2399: yellow
     * [6]~2799: orange
     * [7]~3199: red
     * [8]       free
     */
    std::vector<int> r(9);
    std::fill(r.begin(), r.end(), 0);
    for (int ae : a) {
        int ri = std::min(ae / 400, 8);
        r.at(ri)++;
    }

    int ans_min = 0;
    for (int i = 0; i < 8; ++i) {
        if (r.at(i) > 0) ++ans_min;
    }
    int ans_max = ans_min + r.at(8);

    ans_min = std::max(1, ans_min);

    std::cout << ans_min << ' ' << ans_max << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define llong long long
#define pii pair<int,llong>
#define fi first
#define se second
int n;
int ed[110][2];
struct data{
    int to,nxt;
}mp[220];
int head[110],cnt;
void link(int x,int y)
{
    mp[++cnt].to=y;
    mp[cnt].nxt=head[x];
    head[x]=cnt;
}

int md[110];
int dep[110];
queue<int>q;
pii solve(int x,int y)
{
    pii res;res.fi=res.se=0;
    memset(dep,0,sizeof(dep));
    memset(md,0,sizeof(md));
    q.push(x);dep[x]=1;
    if(y)q.push(y),dep[y]=1;
    int u,v,d;
    while(!q.empty())
    {
        u=q.front();q.pop();
        res.fi=max(res.fi,dep[u]);
        d=0;
        for(int i=head[u];i;i=mp[i].nxt)
            if(!dep[mp[i].to])
            {
                v=mp[i].to;
                dep[v]=dep[u]+1;
                q.push(v);
                d++;
            }
        md[dep[u]]=max(md[dep[u]],d);
    }
    res.se=y?2:1;
    for(int i=1;md[i];++i) res.se*=md[i];
    return res;
}
pii ans;
int main()
{
    scanf("%d",&n);
    int xx,yy;
    for(int i=1;i<n;++i)
    {
        scanf("%d%d",&xx,&yy);
        link(xx,yy);link(yy,xx);
        ed[i][0]=xx;ed[i][1]=yy;
    }
    ans.fi=22832737;ans.se=23721837;
    for(int i=1;i<=n;++i)
        ans=min(ans,solve(i,0));
    for(int i=1;i<n;++i)
        ans=min(ans,solve(ed[i][0],ed[i][1]));
    printf("%d %lld\n",ans.fi,ans.se);
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1e9);

struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n,-1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y){return find(x) == find(y);}
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)];}
};

int main(){
  int N, H, W;
  cin >> N >> W >> H;
  vector<int> X(W+1,-1), Y(H+1,-1);
  vector< pair<int,int> > V;
  UnionFind uf(N);
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    V.emplace_back(x,y);
    if(X[x] > -1) uf.unite(i,X[x]);
    else X[x] = i;
    if(Y[y] > -1) uf.unite(i,Y[y]);
    else Y[y] = i;
  }
  if(uf.size(0) == N){
    cout << N-1 << endl;
    return 0;
  }
  bool t = false, b = false, l = false, r = false;
  set<int> P;
  for(int i = 0; i < N; ++i){
    int x = V[i].first, y = V[i].second;
    int p = uf.find(i);
    P.insert(p);
    l |= (x == 1);
    r |= (x == W);
    b |= (y == 1);
    t |= (y == H);
  }
  int ps = P.size();
  int ans = INF;
  ans = min(ans, N + ps - 1 - (l or r or b or t));
  cout << ans << endl;
}



Measured memory_bytes: 5352
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N;cin>>N;
    typedef pair<ll,ll> P;
    vector<P> p(N);
    REP(i,N)cin>>p[i].first>>p[i].second;
    sort(ALLv(p));
    ld ans=0;ll cnt=0;
    do{
        ld s=0;
        FOR(i,1,N){
            s+=hypot(p[i].first-p[i-1].first,p[i].second-p[i-1].second);
        }
        ans+=s;cnt++;
        //cout<<p[0].first<<p[0].second<<"\n";
    }while(next_permutation(ALLv(p)));
    cout<<dcml(10)<<ans/cnt<<"\n";
}

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

int main() { 
  int n;
  cin >> n;
  double sum = 0;
  
  for(int i=1;i<=n;i++){
    double a;
    cin >> a;
    sum += 1.0/a;    
  }
  double ans = 1.0/sum;

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

  return 0;
}


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

using namespace std;

#define f(a, b) ((1 << (a)) * (b))

int n, q, k, h[100005], at[100005], y[200005], s[19][200005], si, ta, tb;
long long x[100005], tc;
vector< int > va[100005];
vector< long long > vb[100005];

int mi(int a, int b) {
	return h[y[a]] < h[y[b]] ? a : b;
}

void dfs(int a, int b, long long c, int d) {
	x[a] = c;
	h[a] = d;
	y[at[a] = si++] = a;
	for (int i = 0; i < va[a].size(); i++)
		if (b != va[a][i]) {
			dfs(va[a][i], a, c + vb[a][i], d + 1);
			y[si++] = a;
		}
}

int f1(int a, int b, int c, int d) {
	if (f(c, d) == a && f(c, d + 1) == b)
		return s[c][d];
	c--, d = d * 2 + 1;
	if (b <= f(c, d))
		return f1(a, b, c, d - 1);
	if (a >= f(c, d))
		return f1(a, b, c, d);
	return mi(f1(a, f(c, d), c, d - 1), f1(f(c, d), b, c, d));
}

int lca(int a, int b) {
	if (at[a] > at[b])
		swap(a, b);
	return y[f1(at[a], at[b] + 1, 18, 0)];
}

long long path(int a, int b) {
	return x[a] + x[b] - x[lca(a, b)] * 2;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%lld", &ta, &tb, &tc);
		va[ta].push_back(tb);
		va[tb].push_back(ta);
		vb[ta].push_back(tc);
		vb[tb].push_back(tc);
	}
	dfs(1, 0, 0, 0);
	for (int i = 0; i < si; i++)
		s[0][i] = i;
	for (int i = 1; i < 19; i++)
		for (int j = 0; f(i, j) < si; j++)
			s[i][j] = mi(s[i - 1][j * 2], s[i - 1][j * 2 + 1]);
	scanf("%d%d", &q, &k);
	while (q--) {
		scanf("%d%d", &ta, &tb);
		printf("%lld\n", path(ta, k) + path(k, tb));
	}
	return 0;
}

Measured memory_bytes: 37760
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  int k, n;
  cin >> k >> n;
  vector<int> as(n);
  for (auto & a : as ) cin >> a;
  vector<int> dists(n, 0);
  rep(i, n-1) {
    dists[i] = as[i+1] - as[i]; 
  }
  dists[n-1] = k + as[0] - as[n-1];
  int mn = *max_element(dists.begin(), dists.end());
  cout << k-mn << endl;

}

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

int e[10][10];
int main() {
	while (true) {
		string s;
		cin >> s;
		if (s == "#") break;
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int x = 0, y = 0;
		for (int i = 0; i < s.size(); ++i) {
			if (s[i] == '/') {
				y++;
				x = 0;
				continue;
			}
			else if (s[i] == 'b') {
				e[y][x] = 1;
				x++;
			}
			else {
				int j = s[i] - '0';
				while (j > 0) {
					e[y][x] = 0;
					x++;
					--j;
				}
			}
		}

		e[a - 1][b - 1] = 0;
		e[c - 1][d - 1] = 1;
		/*cout << x << " " << y << endl;
		for (int i = 0; i <= y; ++i) {
			for (int j = 0; j < x; ++j) {
				cout << e[i][j] << " ";
			}
			cout << endl;
		}*/
		string ans = "";
		for (int i = 0; i <= y; ++i) {
			int con = 0;
			for (int j = 0; j < x; ++j) {
				if (e[i][j] == 1) {
					if(con > 0) ans += con + '0';
					ans += 'b';
					con = 0;
				}
				else {
					con++;
				}
			}
			if(con > 0) ans += con + '0';
			if (i != y) ans += '/';
			//cout << "i;" << i << " " << ans << endl;
		}

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

Measured memory_bytes: 3192
H, W = map(int, input().split())
s = [0]*H

def check(x, y):
    return 0 <= x and x < W and 0 <= y and y < H

def test(x, y):
    if check(x, y):
        return s[y][x]
    else:
        return "."

for i in range(H):
    s[i] = input()
ans = "Yes"
for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            l = list(map(lambda p: test(p[0], p[1]), [(x-1, y),(x+1, y),(x, y-1),(x, y+1)]))
            if "#" not in l:
               ans = "No"
               break
print(ans)



Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int ans = 0;
  int count = 0;
  int flag = 0;
  while(1){
    char c = getchar();
    if(c == EOF){
      break;
    }else if(flag == 0 && c == 'A'){
      count++;
      flag = 1;
    }else if(flag == 1){
      count++;
      if(c == 'Z'){
        ans = count;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main()
{
    int n;cin>>n;
    vector<int> v(n);
    for(int &x : v)
        cin>>x;
    vector<int> d(n + 1 );
    d[1] = abs(v[1] - v[0]);
    for(int i = 2 ; i < n ; i++)
    {
        d[i] = min(d[i - 1] +  abs(v[i]- v[i - 1]) ,d[i - 2] + abs(v[i] - v[i - 2]));
    }

    cout<<d[n - 1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

static const int INF = 1e9 + 7;

int n, k;
bool canuse[10];
vector<int> useInts;    

int dfs(int now, int score){
    if(now < 0) return INF;
    if(score >= n) return score;
    int res = INF;
    for(auto&& i : useInts){
        res = min(res, dfs(now - 1, score * 10 + i));
    }
    return res;
}

int main(){
    cin >> n >> k;
    for(auto&& i : canuse){
        i = true;
    }
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        canuse[d] = false;
    }
    for(int i = 0;  i < 10; i++){
        if(canuse[i]){
            useInts.push_back(i);
        }
    }
    int size = to_string(n).size();
    cout << dfs(size + 1, 0) << "\n";
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BTAKOYAKIFESTIVAL2019 {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> d(n);
      rep(i, n) {
        cin >> d[i];
      }
      ll ans = 0;
      rep(i, n) {
        for(int j=i+1; j<n; j++) {
          ans += d[i]*d[j];
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  BTAKOYAKIFESTIVAL2019 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let M: usize = read();
    println!(
        "{}",
        if N * 2 > M {
            M / 2
        } else {
            N + ((M - (2 * N)) / 4)
        }
    );
}


Measured memory_bytes: 4352