akhauriyash/Code-Regression huggingface dataset:
class Tree():
    def __init__(self,n,edge):
        self.n = n
        self.tree = [[] for _ in range(n)]
        for e in edge:
            self.tree[e[0]].append((e[1],e[2]))
            self.tree[e[1]].append((e[0],e[2]))
    def setroot(self,root):
        self.root = root
        self.parent = [None for _ in range(self.n)]
        self.parent[root] = -1
        self.depth = [None for _ in range(self.n)]
        self.depth[root] = 0
        self.distance = [None for _ in range(self.n)]
        self.distance[root] = 0
        stack = [root]
        while stack:
            node = stack.pop()
            for adj,cost in self.tree[node]:
                if self.parent[adj] is None:
                    self.parent[adj] = node
                    self.depth[adj] = self.depth[node]+1
                    self.distance[adj] = self.distance[node]+cost
                    stack.append(adj)
    def diam(self):
        u = self.distance.index(max(self.distance))
        dist_u = [None for _ in range(N)]
        dist_u[u] = 0
        stack = [u]
        while stack:
            node = stack.pop()
            for adj,cost in self.tree[node]:
                if dist_u[adj] is None:
                    dist_u[adj] = dist_u[node]+cost
                    stack.append(adj)
        d = max(dist_u)
        v = dist_u.index(d)
        return d,u,v
    def construct_lca(self):
        L = (self.n-1).bit_length()
        self.k_parent = [self.parent]
        prev = self.parent
        for k in range(L):
            array = [0 for _ in range(self.n)]
            for i in range(self.n):
                if prev[i] == -1: continue
                array[i] = prev[prev[i]]
            self.k_parent.append(array)
            prev = array
    def lca(self,u,v):
        d = self.depth[v]-self.depth[u]
        if d < 0: u,v,d = v,u,-d
        for k in self.k_parent:
            if d & 1: v = k[v]
            d >>= 1
        if u == v: return u
        for k in reversed(self.k_parent):
            pu,pv = k[u],k[v]
            if pu != pv: u,v = pu,pv
        return self.k_parent[0][u]
    def dist(self,u,v):
        l = self.lca(u,v)
        return self.distance[u]+self.distance[v]-2*self.distance[l]

import sys
input = sys.stdin.readline

N = int(input())
E = [tuple(map(int,input().split())) for _ in range(N-1)]

t = Tree(N,E)
t.setroot(0)
t.construct_lca()
d,u,v = t.diam()
ans = []

for i in range(N):
    ans.append(max(t.dist(i,u),t.dist(i,v)))

print('\n'.join(map(str,ans)))


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

// すべてのx_iのxorをTとする
// T = x1 ^ ... ^ xn
// a_1 ^ ... ^ an = (T ^ x1) ^ ... ^ (T ^ xn) = (T をn+1回XOR取った数) = T
// nは偶数より。

int main(void) {
  ull N, T = 0;
  cin >> N;
  vector<ull> a(N);
  rep(i, N) {
    cin >> a[i];
    T ^= a[i];
  }
  rep(i, N) {
    cout << (T ^ a[i]) << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4772
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll N, K, h[100100], ans=0;
    scanf("%lld %lld", &N, &K);
    rep(i, N) scanf("%lld", h+i);
    rep(i, N) if(h[i]>=K) ans++;
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  int c[n]={};
  
  for(int i=0;i<m*2;i++){
    int a;
    cin>>a;
    c[a-1]++;
  }
  
  for(int j=0;j<n;j++) cout<<c[j]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i = 0; i<n; i++)
	{
		cin>>a[i];
	}
	sort(a,a+n,greater<int>());
	int ans = 0,best=0;
	vector<int> v;
	for(int i = 0; i<n; i++)
	{
		if(a[i]%10==0) best += a[i];
		else
		{
			v.push_back(a[i]);
			ans += a[i];
		}
	}
	if(ans %10 ==0 && ans >0)
	{
		ans -= v.back();
		cout<<ans+best<<endl;
	}
	else if(ans%10!=0)
		cout<<ans+best<<endl;
	else
		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
ll n,k;
int main()
{
  IOS
  cin>>n>>k;
  ll i;
  vector<ll> a;
  ll sum=0;
  for(i=1;i<=n;i++)
  {
    ll x;
    cin>>x;
    a.pb(x);
    sum+=x;
  }
  if(sum<k)
    cout<<n-1;
  else if(sum==k)
    cout<<n;
  else
  {
    sort(all(a));
    ll cnt=0;
    for(i=0;i<n;i++)
      if(k>=a[i])
      {
        k-=a[i];
        cnt++;
      }
      else
        break;
      cout<<i;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{     int n,i,x;set<int>s; 
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> x;
        s.insert(x);
    }
    if(s.size()==n)cout<<"YES";else cout<<"NO";
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




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

using namespace std;

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

    if(D ==25)cout << "Christmas" << endl;
    else if(D==24) cout << "Christmas Eve" << endl;
    else if(D==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline().rstrip())

sum = 0
for i in range(n):
  line = sys.stdin.readline().rstrip().split(" ")
  if(line[1] == "BTC"):
    sum += float(line[0]) * 380000.0
  else:
    sum += float(line[0])
print(sum)

Measured memory_bytes: 3060
#!/usr/bin/env python3
s = list(str(input()))

n = len(s)+1


from_left = [0 for _ in range(n)]
from_right = [0 for _ in range(n)]

for i, sym in enumerate(s, 1):
    if sym == ">":
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1

for i, sym in enumerate(s[::-1]):
    i = n-2-i
    if sym == "<":
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1

seq = [max(x, y) for x, y in zip(from_left, from_right)]

print(sum(seq))


Measured memory_bytes: 38356
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

#define MAX_V 1000
struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
  int i;
  if(v==t)return f;
  used[v]=true;
  rep(i,G[v].size()){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(void) {
  int i,j;
  int e,v;
  cin>>v>>e;
  rep(i,e){
    int u,v,c;
    cin>>u>>v>>c;
    add_edge(u,v,c);
  }
  cout<<max_flow(0,v-1)<<endl;
}

Measured memory_bytes: 3212
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  4 5
  1 1 3 4 5
  2 2 2 4 5
  3 3 0 1 1
  2 3 4 4 6
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
r,c=line[0].split(" ").map(&:to_i)

arr = []
(0...r).each do |r|
  tmp = line[r+1].split(" ").map(&:to_i)
  sum = tmp.inject(&:+)
  arr[r] = (tmp << sum)
end

arr = arr.transpose

(0..c).each do |c|
  sum = arr[c].inject(&:+)
  arr[c] << sum
end

arr.transpose.each do |s|
  puts s.join(" ")
end

Measured memory_bytes: 9780
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define debug printf("%s %d\n", __FUNCTION__, __LINE__)
const int N = 50;

long long value[N + 1];
int main(int argc, char **argv) {
    long long k;
    cin >> k;
    long long w = k / N, t = k % N;
    w -= 1;
    if (k > N) {
        for (int i = 1; i <= N; i++) value[i] = w;
        for (int i = 1; i <= t; i++) value[i] += N + 2 - i;
        for (int i = t + 1; i <= N; i++) value[i] += N + 1 - i;
    }
    else if (k <= N) {
        for (int i = 1; i <= k; i++) value[i] = N - i + 1;
        for (int i = k + 1; i <= N; i++) value[i] = 0;
    }

    cout << N << endl;
    for (int i = 1; i <= N; i++) 
        cout << value[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//int const INF=1001001001;
ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll H,W;

int main(){
    cin>>H>>W;

    ll ans=INF;
    repn(a,W-1){
        ll s=a*H;
        ll t=(H/2)*(W-a);
        ll u=((H+1)/2)*(W-a);
        ll res=max(s,max(t,u))-min(s,min(t,u));
        ans=min(ans,res);

        if(a<=W-2){
            t=(W-a)/2*H;
            u=(W-a+1)/2*H;
            res=max(s,max(t,u))-min(s,min(t,u));
            ans=min(ans,res);
        }
    }

    repn(a,H-1){
        ll s=a*W;
        ll t=(W/2)*(H-a);
        ll u=((W+1)/2)*(H-a);
        ll res=max(s,max(t,u))-min(s,min(t,u));
        ans=min(ans,res);

        if(a<=H-2){
            t=(H-a)/2*W;
            u=(H-a+1)/2*W;
            res=max(s,max(t,u))-min(s,min(t,u));
            ans=min(ans,res);
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define SZ(a) int((a).size())
#define mp make_pair
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-6;
inline void read(LL& x){int f=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(f=-1,x=0):(x=c-'0');while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=f;}
inline void read(int& x){LL t;read(t);x=t;}


LL l[1005];

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    l[0]=2;l[1]=1;
    int n;read(n);
    for(int i=2;i<=n;i++) l[i]=l[i-1]+l[i-2];
    printf("%lld\n",l[n]);
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 256
x = list(map(int, input().split()))
M = x[0]
D = x[1]
result = 0

if M <= 3 or D < 22:
    print(result)
else:
    if M > 81:
        M = 81
    for i in range(3, M):
        i += 1
        for j in range(21, D):
            j += 1
            D1 = j % 10
            D10 = j // 10
            if D1 < 2:
                continue
            if i == D1 * D10:
                result += 1
    print(result)

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

int main()
{
    int l,r,d,count=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        {
            //cout<<i<<" ";
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3648
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n, k = io.read("*n", "*n")
local res = 0
for i = 1, n do
  local ti = i
  local rate = 1
  while(ti < k) do
    rate = rate / 2
    ti = ti * 2
  end
  res = res + rate / n
end
print(string.format("%.10f", res))


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n;
	cin >> n;

	vector<ll> x(n), y(n), h(n);
	ll one_i = -1;
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] >= 1) one_i = i;
	}

	ll ansx = -1, ansy = -1, ansh = -1;
	for (ll xx = 0; xx <= 100; xx++) {
		for (ll yy = 0; yy <= 100; yy++) {
			ll hh = h[one_i] + llabs(xx - x[one_i]) + llabs(yy - y[one_i]);

			bool ok = true;
			rep(i, n) {
				if (h[i] >= 1 && (hh - h[i] != llabs(xx - x[i]) + llabs(yy - y[i]))) {
					ok = false;
				}
				if (h[i] == 0 && (hh > llabs(xx - x[i]) + llabs(yy - y[i]))) {
					ok = false;
				}
			}
			if (ok) {
				ansx = xx;
				ansy = yy;
				ansh = hh;
			}
		}
	}

	cout << ansx << " " << ansy << " " << ansh << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        //test cases
        String s = in.next();
        int n = s.length();
       
        int count=0;
        for(int i=0 ; i<n ; i++){
            if(s.charAt(i)=='+') count++;
            else count--;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
#include<tuple>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define fi first
#define se second
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}



ll  d, n, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	if (a < 13)b /= 2;
	if (a <= 5) b = 0;
	cout << b << endl;
	return 0;
}
/*
test case
5
1 3 1
1 5 2
2 3 5
3 4 1
*/

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n;

      m=n/500;

      n%=500;

      m*=1000;

      a=n/5;
      m+=(a*5);

      cout<<m<<endl;













}



Measured memory_bytes: 3596
#include "bits/stdc++.h"

using namespace std;

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

	vector<string> s(n);

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

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

	for (int i = 0; i < s.size(); i++)
	{
		cout << s[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  string name[20];
  int m[20],d[20][31];
  while(cin>>n,n){
    int num[31]={0},point[31]={0};
    for(int i=0;i<n;i++){
      cin>>name[i]>>m[i];
      for(int j=0;j<m[i];j++){
	cin>>d[i][j];
	num[d[i][j]]++;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<m[i];j++){
	point[i] += n+1 - num[d[i][j]];
      }
      if(point[ans]>point[i]){
	ans=i;
      }else if(point[ans]==point[i]){
	if(name[ans]>name[i])ans=i;
      }
    }
    cout<<point[ans]<<" "<<name[ans]<<endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int MAX_V = 100010;
const int MAX_LOG_V = 20;
int root = 0;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

using int64 = long long;
vector<int> G[MAX_V];

void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] != p)
      dfs(G[v][i], v, d + 1);
  }
}

void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < MAX_LOG_V; k++) {
    for (int v = 0; v < V; v++) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}

int lca(int u, int v) {
  if (depth[u] > depth[v])
    swap(u, v);
  for (int k = 0; k < MAX_LOG_V; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v)
    return u;
  for (int k = MAX_LOG_V - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}

int main() {
  int N;
  cin >> N;
  for (int i = 1; i < N; i++) {
    int p;
    cin >> p;
    p--;
    G[p].push_back(i);
  }
  init(N);

  vector<int> ord;
  queue<int> q;
  ord.push_back(0);
  q.push(0);
  while (q.size()) {
    int v = q.front();
    q.pop();
    vector<int> nxt;
    for (int u : G[v]) {
      nxt.push_back(u);
    }
    sort(nxt.begin(), nxt.end());
    for (int u : nxt) {
      ord.push_back(u);
      q.push(u);
    }
  }

  int64 ans = 0;
  for (int i = 0; i < N - 1; i++) {
    int cur = ord[i];
    int nxt = ord[i + 1];
    int l = lca(cur, nxt);
    ans += depth[cur] + depth[nxt] - 2 * depth[l];
  }
  cout << ans << endl;
}

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

const int N = 6e5+5;
int tree[N];

void build(ll node, ll l, ll r)
{
	if(l==r)
	{
		tree[node] = 0;
	}
	else
	{
		ll m = (l+r)/2;
		build(2*node, l, m);
		build(2*node+1, m+1, r);
		tree[node] = max(tree[2*node], tree[2*node+1]);
	}
}

ll query(ll node, ll l, ll r, ll st, ll en)
{
	if(st > en)
		return 0;
	if(r<st||l>en)
		return 0;

	else if(st<=l && r<=en)
		return tree[node];
	
	else
	{
		ll m = (l+r)/2;
		ll p1 = query(2*node, l, m, st, en);
		ll p2 = query(2*node+1, m+1, r, st, en);
		return max(p1, p2);
	}
}

void update(ll node, ll l, ll r, ll ind, ll x)
{
	if(l==r)
		tree[node] = x;
	
	else
	{
		ll m = (l+r)/2;
		if(ind<=m)
			update(2*node, l, m, ind, x);
		else
			update(2*node+1, m+1, r, ind, x);
		tree[node] = max(tree[2*node] , tree[2*node+1]);
	}
}


int32_t main()
{
	int n;
	cin>>n;
	vector<int> h(n), a(n);
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];

	int mx = 0;
	build(1, 1, n);
	for(int i=0;i<n;i++)
	{
		int curr = a[i] + query(1, 1, n, 1, h[i]-1);
		mx = max(mx, curr);
		update(1, 1, n, h[i], curr);
	}
	cout<<mx;
}

Measured memory_bytes: 7424
#include <stdio.h>

int main(void)
{
    int color[9],i,max=0,min=0,n,score;
    for(i=0;i<9;i++) color[i]=0;
    scanf("%d",&n);
    while(n>0)
    {
        scanf("%d",&score);
        if(score<400) color[0]++;
        else if(score<800) color[1]++;
        else if(score<1200) color[2]++;
        else if(score<1600) color[3]++;
        else if(score<2000) color[4]++;
        else if(score<2400) color[5]++;
        else if(score<2800) color[6]++;
        else if(score<3200) color[7]++;
        else color[8]++;
        n--;
    }
    for(i=0;i<8;i++)
        if(color[i]!=0) max=++min;
    if(min==0) printf("%d %d",1,max+color[8]);
    else printf("%d %d",min,max+color[8]);
    return 0;
}


Measured memory_bytes: 128
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        mut s: Bytes,
    }
    s.reverse();
    let mut a = vec![0; s.len() + 1];
    let mut ten = 1;
    for i in 0..s.len() {
        a[i + 1] = (a[i] + (s[i] - b'0') as i64 * ten) % 2019;
        ten *= 10;
        ten %= 2019;
    }
    let mut m = std::collections::BTreeMap::new();
    let mut res = 0u64;
    for i in 0..s.len() + 1 {
        let r = m.entry(a[i]).or_insert(0);
        res += *r;
        *r += 1;
    }
    // println!("{:?}", a);
    println!("{}", res);
}


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

using namespace std;

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

  int H,W; cin>>H>>W;
  vector<string> map(H);
  for (auto& s : map) cin>>s;

  auto bfs = [&](int s) {
    if (map[s/W][s%W] == '#')
      return -1;
    vector<int> d(H*W, numeric_limits<int>::max());
    queue<pair<int, int>> qs;
    qs.emplace(s, 0);
    d[s] = 0;
    while (not qs.empty()) {
      auto q = qs.front(); qs.pop();
      auto s = q.first;
      auto dist = q.second;
      auto go = [&](int t) {
        if (map[t/W][t%W] == '.' and d[t] > dist+1) {
          d[t] = dist+1;
          qs.emplace(t, dist+1);
        }
      };
      // -1
      if (s % W > 0) {
        go(s-1);
      }
      // 1
      if (s%W != W-1) {
        go(s+1);
      }
      // -W
      if (s/W > 0) {
        go(s-W);
      }
      // W
      if (s/W != H-1) {
        go(s+W);
      }
    }
    auto res = 0;
    for (auto v : d) {
      if (v == numeric_limits<int>::max())
        continue;
      res = max(res, v);
    }
    return res;
  };
  auto ans = 0;
  for (int i = 0; i < H*W; i++) {
    ans = max(ans, bfs(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = input[0];
    var b = input[1];
    //出力
	console.log(a - b + 1);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


int main(){
  ll n, q;
  cin >> n >> q;
  deque<pair<string, ll>> queue;
  rep(i,n){
    string name;
    ll time;
    cin >> name >> time;
    queue.emplace_back(name, time);
  }

  ll curtime = 0;
  while(queue.size() > 0) {
    auto p = queue.front();
    queue.pop_front();
    if (p.second > q) {
      p.second -= q;
      queue.push_back(p);
      curtime += q;
    } else {
      curtime += p.second;
      cout << p.first << " " << curtime << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 6340
#define _CRT_SECURE_NO_WARNINGS
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <stack>
#include <random>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;

#define X first
#define Y second

const int MAXN = 100000 + 100;
int n, m, a, b;
vector<int> g[MAXN];
int ans[MAXN * 3];
bool used[MAXN];
int in = MAXN, en = MAXN;

void dfs(int v, bool obr)
{
	used[v] = true;
	if (!obr)
	{
		ans[en] = v;
		en++;
	}
	else
	{
		ans[in - 1] = v;
		in--;
	}
	int use = 0;
	if (v == 0)
	{
		for (int i = 0; i < g[v].size(); i++)
		{
			if (use == 2)
				break;
			if (!used[g[v][i]])
			{
				if (use == 0)
				{
					use++;
					dfs(g[v][i], false);
				}
				else
				{
					use++;
					dfs(g[v][i], true);
				}
			}
		}
	}
	else
	{
		for (int i = 0; i < g[v].size(); i++)
		{
			if (use)
				break;
			if (!used[g[v][i]])
			{
				use++;
				dfs(g[v][i], obr);
			}
		}
	}
}

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("brackets.in", "r", stdin);
	//freopen("brackets.out", "w", stdout);
#endif

	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, false);
	cout << en - in << endl;
	for (int i = in; i < en; i++)
	{
		cout << ans[i] + 1 << " ";
	}
	return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<cstring>
using namespace std;
int w,h;
int s[40][40];
int dp[40][40];
int dx[]={-1,0,1};
int ret(int y,int x){
	if(y>=h-1){
		if(h-1==y&&s[y][x]==1)
		return 0;
		return 1;
	}
	if(dp[y][x]!=-1)
	return dp[y][x];
	if(s[y][x]==1)
		return dp[y][x]=0;
	if(s[y][x]==2){
		return dp[y][x]=ret(y+2,x);
	}
	int ans=0;
	for(int i=0;i<3;i++){
		int nx=dx[i]+x;
		if(nx>=w||nx<0)
			continue;
		
		if(s[y+1][nx]==0){
			ans+=ret(y+1,nx);
		}else if(s[y+1][nx]==2){
			if(i!=1)
				continue;
			ans+=ret(y+1,nx);
		}
	}
	return dp[y][x]=ans;
}
int main(){
	while(cin>>w>>h,w||h){
		memset(dp,-1,sizeof(dp));
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		cin>>s[i][j];
		int ans=0;
		for(int i=0;i<w;i++){
			//if(s[0][i]==0)
				ans+=ret(0,i);
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n,p[234567],c,z[234567];
bool s[234567];
int main(){
    z[0]=3000000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
        if(z[i]==0)z[i]=3000000;
        if(p[i]<z[i])z[i]=p[i];
        z[i+1]=z[i];
    }
    z[0]=p[0];
    for(int i=0;i<n;i++){
        if(p[i]<=z[i])c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 1792
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	n, m, d := nextInt(), nextInt(), nextInt()

	var k int
	switch {
	case d == 0:
		k = n
	default:
		k = 2 * d
	}
	fmt.Println(float64((m-1)*((2*n)-k)) / float64(n*n))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	vector<int> a(3);
	rep(i,n) a.at(s.at(i)-'a')++;
	int num=0;
	rep(i,3) if(a.at(i)) num++;
	if(n==1) cout << "YES" << endl;
	else if(n==2){
		if(num==2) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	else{
		if(num<3) cout << "NO" << endl;
		else{
			if(max(abs(a.at(0)-a.at(1)),max(abs(a.at(1)-a.at(2)),abs(a.at(2)-a.at(0))))<=1) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}


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

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

	vector<vector<int>> A(k);

	rep(i, k){
		int d;
		cin >> d;
		rep(j, d){
			int hito;
			cin >> hito;
			A.at(i).push_back(hito);
		}
	}

	set<int> B;
	for(auto v : A){
		for(auto p : v){
			B.insert(p);
		}
	}
	cout << n - B.size() << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int a, b, c, x, y, n;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  n = a * x + b * y;
  if(x > y){
    swap(x, y);
    swap(a, b);
  }
  n = min(n, 2*c*x+(y-x)*b);
  n = min(n, 2*c*y);
  printf("%d\n", n);
  return 0;
}

Measured memory_bytes: 256
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("%d",2*a-1);
	}
	else if(b>a){
		printf("%d",2*b-1);
	}
	else{
		printf("%d",2*a);
	}
	return 0;
}

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

int main(){
  int n;
  int a[110],b[110];
  string str;

  while(cin >> n , n){
    cin >> str;

    for(int i=0;i<n;i++){
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
    }

    for(int i=n-1;i>=0;i--){
      int s = b[i]-a[i];
      str[a[i]] = (char)('a' + (str[a[i]] + s -'a')%26);
      str[b[i]] = (char)('a' + (str[b[i]] + s -'a')%26);
      swap(str[a[i]],str[b[i]]);
    }
    cout << str << endl;
  }
}

Measured memory_bytes: 0
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    set<int> S;
    for(int i=0; i<N; i++) {
        int v; cin >> v;
        S.insert(v);
    }
    cout << S.size() << endl;
    return 0;
}



Measured memory_bytes: 7684
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >>n;
ll a[n];
for(ll i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
ll max=a[n-1];

ll min=-1;
ll min1=-1;
ll ans=-1;
if(n==2){
cout <<a[1]<<" "<<a[0];
}
else{
cout <<max<<" ";
if(max%2==0){
for(ll i=0;i<n;i++){
if(a[i]<max/2){
min=a[i];
}
else if(a[i]==max/2){
ans=a[i];
}
else{
min1=a[i];
break;
}
}
if(ans>0){
cout <<ans;
}
else if(min<0){
cout <<min1;
}
else if(min1<0){
cout <<min;
}
else{
ll s,t;
s=max/2-min;
t=min1-max/2;
if(s<t)
cout << min;
else
cout <<min1;
}


}
else{
for(ll i=0;i<n;i++){
if(a[i]<max/2+1){
min=a[i];
}
else if(a[i]==max/2+1){
ans=a[i];
}
else{
min1=a[i];
break;
}
}
if(ans>0){
cout <<ans;
}
else if(min<0){
cout <<min1;
}
else if(min1<0){
cout <<min;
}
else{
ll s,t;
s=max/2+1-min;
t=min1-(max/2+1);
if(s<t)
cout << min;
else
cout <<min1;
}


}
}
return 0;

}

Measured memory_bytes: 1024
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
a = wi()
k = 0
for i in range(n):
    k += 1 / a[i]

print(1 / k)

Measured memory_bytes: 6344
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;

int main(){

	string S;

	cin >> S;


	for(int i = 0;i < 26;i++){
		char a = (char)('a' + i);
		if(S.find(a) == string::npos){
		    cout << a;
		    return 0;
		}
	}

	cout << "None";


    return 0;

}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}



void solve(std::istream &in, std::ostream &out) {
  string s;
  in >> s;
  if (s[0]=='7'||s[1]=='7'||s[2]=='7')out<<"Yes\n";
  else out << "No\n";
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

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

	int64_t a = 1;
	int x = n;
	for (int i = 0; i < n; i++) {
		a *= x;
		x--;
		//cout << i << endl;
	}

	cout << a << endl;
}


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

int main(void){
    

    while(1){
        int h = 0;
        int w = 0;
        cin >> h >> w;
    
        if((h == 0) && (w == 0)){
            break;
        }

        for(int i = 0 ; i < h ; i++){
        int toggle = i % 2;
            for(int j = 0 ; j < w ; j++){
                if(toggle == 1){
                    cout << '.';
                    toggle = 0;
                }else{
                    cout << '#';
                    toggle = 1;
                }
            }
            cout << endl;
        }    
        cout << endl;

    }
    return 0;
}

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

using namespace std;
typedef long long ll;

ll a[4][1010];

int main(void) {
  ll n, v;
  cin >> n >> v;

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  vector<ll> b[2];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        b[i].push_back(a[i * 2][j] + a[i * 2 + 1][k]);
      }
    }
    sort(b[i].begin(), b[i].end());
  }

  ll ans = 0;
  for (int i = 0; i < b[0].size(); i++) {
    ans += (upper_bound(b[1].begin(), b[1].end(), v - b[0][i]) - lower_bound(b[1].begin(), b[1].end(), v - b[0][i]));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23100
def main():
    N, K = map(int, input().split())
    mod = 10**9 + 7
    ans = 0
    for i in range(K, N + 2):
        a = N - i + 1
        ans = (ans + i * a + 1) % mod
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N, M;

int main() {
    cin >> N >> M;
    vector<int> a(N);
    int tot = 0;
    rep(i,N) cin >> a[i], tot += a[i];
    sort(RALL(a));
    int th = (tot - 1 + 4*M)/4/M;
    rep(i,M) {
        if (a[i] < th) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main() {
  int N, count;
  cin >> N;
  count = -1;
  
  for (int i = 0; i < N; i++) {
    int A, a, c;
    cin >> A;
    a = 0;
    c = 0;
    while (a == 0) {
      a = A % 2;
      if (a == 0) {
        A /= 2;
        c += 1;
      }
    }
    if (count == -1 || count > c) {
      count = c;
    }
  }
  cout << count << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> d;

	cin >> N;
	d.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> d[i];
	sort(ALL(d));

	llong l = d[N/2-1];
	llong r = d[N/2];

	cout << r-l << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

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

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];

    vector<ll> idx(n);
    iota(ALL(idx), 0);
    sort(ALL(idx), [&](ll l, ll r){
        return b[l] < b[r];
    });

    ll now = 0;
    bool flag = true;
    for(auto i: idx) {
        now += a[i];
        // cout << a[i] << " " << b[i] << " " << now << endl;
        if(now > b[i]) {
            flag = false;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using namespace std;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N;
  cin >> N;
  vector < int > dp(3);
  for (int i = 0; i < N; ++i) {
    vector < int > new_dp(3, 0), cost(3);
    for (int j = 0; j < 3; ++j)
      cin >> cost[j];
    for (int k = 0; k < 3; ++k)
      for (int j = 0; j < 3; ++j)
        if (k != j)
          new_dp[j] = max (new_dp[j], dp[k] + cost[j]);
    dp = new_dp;
  }
  cout << max (dp[0], max (dp[1], dp[2]));
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
const int N=100000+10;

int _r;char _c;

int read()
{
	while(!isdigit(_c=getchar()));
	_r=_c-48;
	while(isdigit(_c=getchar()))
		_r=_r*10-48+_c;
	return _r;
}

int n,m,a[N],fa[N],cnt,ans;
vector<int> v[N];
priority_queue<int,vector<int>,greater<int> > Q;

int find(int x){return (fa[x]==x)?x:(fa[x]=find(fa[x]));}

void hb(int x,int y)
{
	x=find(x);y=find(y);
	if(x!=y)
		fa[x]=y;
}

signed main()
{
	n=read();m=read();
	int i;
	for(i=1;i<=n;++i)
		a[fa[i]=i]=read();
	while(m--)
		hb(read()+1,read()+1);
	for(i=1;i<=n;++i)
		v[find(i)].push_back(a[i]);
	vector<int>::iterator it;
	for(i=1;i<=n;++i)if(fa[i]==i)
	{
		++cnt;
		sort(v[i].begin(),v[i].end());
		ans+=*v[i].begin();
		for(it=v[i].begin()+1;it!=v[i].end();++it)
			Q.push(*it);
	}
	if(cnt==1)
		printf("0");
	else if(cnt-2>Q.size())
		printf("Impossible");
	else
	{
		while(cnt-->2)
		{
			ans+=Q.top();
			Q.pop();
		}
		printf("%lld",ans);
	}        	
	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    int a,b;
    cin>>N>>M;
    map<int,int> m;
    for(int i=0;i<M;i++){
        cin>>a>>b;
        m[a-1]++;m[b-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<m[i]<<endl;
    }
}

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

#include <vector>
#include <algorithm>
#include <limits>
#include <unordered_set>
#include <array>

using namespace std;


int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (2 * c > a + b) {
        cout << a * x + b * y << endl;
    } else {
        int common = min(x, y);
        int yen = common * c * 2;
        int diff = max(x, y) - common;
        if (x > y) {
            yen += min(diff * a, diff * 2 * c);
        } else {
            yen += min(diff * b, diff * 2 * c);
        }
        cout << yen << endl;
    }

}


Measured memory_bytes: 3592