akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k; cin>>k;//k++;
    vector<vector<ll>> dp(10,vector<ll>(10,0));
    vector<ll> sum(10,0);//sum[i]:i+1桁のるんるん数の個数
    //dp[i][j]:jから始まるi+1桁のるんるん数の個数(ただし0始まりを含む)
    dp[0]=vector<ll>(10,1);
    rep2(i,1,10){
        rep(j,10){
            if(j==0)dp[i][j]=dp[i-1][0]+dp[i-1][1];
            else if(j==9)dp[i][j]=dp[i-1][8]+dp[i-1][9];
            else dp[i][j]=dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
        }
    }

    for(int i=0; i<10; i++){
        ll s=0;
        for(int j=1; j<10; j++){
            s+=dp[i][j];
        }
        sum[i]=s;
    }

    //for(int i=0; i<10; i++)cout<<sum[i]<<endl;
    int d = 0;
    while(k>sum[d]){
        k-=sum[d];
        d++;
    }//kotaeha d+1桁
    int prev;
    for(int i=d; i>=0; i--){//上の桁から決める
        if(i==d){
            for(int j=1; j<10; j++){
                if(k<=dp[i][j]){
                    prev=j;
                    cout<<j;
                    break;
                }else{
                    k-=dp[i][j];
                }
            }
        }else{
            for(int j=max(0,prev-1);;j++){
                if(k<=dp[i][j]){
                    prev=j;
                    cout<<j;
                    break;
                }else{
                    k-=dp[i][j];
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
 * Author: Utkal Sinha
 * Created on: 2020-08-29, Sat, 18:13
 * Problem:
 * Platfrom: General
 * */
#if USE_BOOST2
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
namespace bst = boost::multiprecision;
typedef bst::int1024_t vll; //int512_t or //int128_t
typedef bst::cpp_bin_float_100 vdouble;
#endif

#include <bits/stdc++.h>
using namespace std;
#define GETTIME std::chrono::system_clock::now()
#define DURATION std::chrono::duration<double>
#ifdef MY_DEV_ENV2
#define LOCALDEV
#endif
typedef long long ll;
typedef std::chrono::system_clock::time_point TPT;
static TPT starttime, endtime, timelimit;
static double problem_tle = 1.5;
static inline void calc_problem_end_time() {timelimit = starttime + std::chrono::milliseconds(int (problem_tle * 1000));}
// template end

ll n, m;
// DSU -- start
ll parent[200005];
ll sz[200005];

void make_set(long long v) {
    parent[v] = v;
    sz[v] = 1;
}

int find_set(long long v) {
    if (v == parent[v]) return v;
    return find_set(parent[v]);
}

void union_sets(long long a, long long b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (sz[a] < sz[b]) swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
    }
}
// DSU -- end

void love() {
    cin >> n >> m;
    for(int i= 0; i<=n; i++) make_set(i);

    ll ai, bi;
    for(int i= 0; i<m; i++) {
        cin >> ai >> bi;
        union_sets(ai, bi);
    }

    ll ans = 0;
    for(int i= 0; i<=n; i++) ans = max(ans, sz[i]);
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    srand(time(0));
#ifdef LOCALDEV
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
#ifdef LOCALDEV
    starttime = GETTIME;
    calc_problem_end_time();
#endif
    while(t--) love();
#ifdef LOCALDEV
    endtime = GETTIME;
    DURATION elapsed_seconds = endtime - starttime;
    DURATION time_limit_seconds = timelimit - starttime;
    clog << "Elapsed time: " << elapsed_seconds.count() << "s\n";
    clog << "Time limit: " << time_limit_seconds.count() << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 6784
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

int main(){
    long int a[10];
    long int b[10];

    for(int i = 0; i < 4; ++i) {
        scanf("%ld", &a[i]);
    }
    b[0] = a[0] * a[2];
    b[1] = a[0] * a[3];
    b[2] = a[1] * a[2];
    b[3] = a[1] * a[3];

    long int max = LONG_MIN;
    //printf("%ld\n", max);
    for(long int i = 0; i < 4; ++i) {
        if (max < b[i]){
            max = b[i];
        }
    }
    printf("%ld\n", max);
}

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

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

const LL mod = 1e9+7;

LL add(LL x, LL y) {
    return (x + y)%mod;
}
LL sub(LL x, LL y) {
    return ((x%mod) - (y%mod) + mod)%mod;
}
LL mul(LL x, LL y) {
    return ((x%mod)*(y%mod))%mod;
}
LL pw(LL x, LL y) {
    LL res = 1;
    while(y != 0) {
        if(y%2) {
            res = mul(x, res);
            y--;
        }else{
            x = mul(x, x);
            y /= 2;
        }
    }
    return res;
}
LL inv(LL x) {
    return pw(x, mod - 2);
}

int main() {
    LL H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<LL> fact(H + W + 1, 1);
    FOR(i, 1, H + W + 1) {
        fact[i] = mul(i, fact[i - 1]);
    }

    LL res = 0;
    REP(i, H - A) {
        LL d1 = mul(mul(fact[i + B - 1], inv(fact[i])), inv(fact[B - 1]));
        LL d2 = mul(mul(fact[H - i - 1 + W - B - 1], inv(fact[H - i - 1])), inv(fact[W - B - 1]));
        res = add(res, mul(d1, d2));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

const long long MOD = 1000000007;

struct WBK {
	int x;
	int y;
	int m;
};

int main(){
	int A,B,M;
	cin >> A >> B >> M;
	vector<int> a(A),b(B);
	WBK m[M];
	
	int a_min=999999;
	for(int i=0;i<A;i++){
		cin >> a[i];
		a_min=min(a_min,a[i]);
	}
	
	int b_min=999999;
	for(int i=0;i<B;i++){
		cin >> b[i];
		b_min=min(b_min,b[i]);
	}
	
	for(int i=0;i<M;i++){
		cin >> m[i].x >> m[i].y >> m[i].m;
	}
	
	//割引を使わない最小額
	int ans_1=a_min+b_min;
	
	//割引を使う最小額
	int ans_2=999999;
	for(int i=0;i<M;i++){
		int now_cost=a[m[i].x-1]+b[m[i].y-1]-m[i].m;
		ans_2=min(ans_2,now_cost);
	}

	//cout << ans_1 << " " << ans_2 << endl;
	cout << min(ans_1,ans_2) << endl;
	return 0;
}


Measured memory_bytes: 2176
[n,m]=map(int,input().split())
A=[[] for i in range(n)]
B=[0 for i in range(m)]
for i in range(n):
    A[i]=list(map(int,input().split()))
C=[0 for i in range(n)]
for i in range(m):
    B[i]=int(input())
for i in range(n):
    for j in range(m):
        C[i]+=A[i][j]*B[j]
for i in range(n):
    print(C[i])



Measured memory_bytes: 6032
N = int(input())
A = [int(s) for s in input().split(" ")]
ABI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True)
prev = [0]
for k, (a,i) in enumerate(ABI):
  curr = [0]*(k+2)
  for l in range(k+1):
    curr[l] = max(curr[l], prev[l]+abs(N-i-k+l)*a)
    curr[l+1] = prev[l]+abs(i-l-1)*a
    
  prev = curr

print(max(prev))

Measured memory_bytes: 9404
S = list(input())

ok = True
for i in range(len(S)):
    banme = i + 1

    if banme % 2 == 1:
        if S[i] == "R" or S[i] == "U" or S[i] == "D":
            pass
        else:
            ok = False
    else:
        if S[i] == "L" or S[i] == "U" or S[i] == "D":
            pass
        else:
            ok = False

if ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());

        var S = new string[N];
        for (int i = 0; i < N; i++)
        {
            S[i] = Console.ReadLine();
        }

        Console.WriteLine(S.Distinct().Count());
    }
}


Measured memory_bytes: 48068
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N;
const ll MAX_N = 200000;
ll A[MAX_N], B[MAX_N];

int main(){
  cin >> N;
  REP(i, N) cin >> A[i] >> B[i];
  vpll vec;
  REP(i, N) {
    vec.pb(pll(B[i], A[i]));
  }
  sort(ALL(vec));

  ll crt = 0;
  REP(i, N) {
    crt += vec[i].S;
    if(crt > vec[i].F) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

#define PI 3.14159265359

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  int min = H * 60 + M;
  double Ax = A * cos((90 - M * 6) / 180.0 * PI);
  double Ay = A * sin((90 - M * 6) / 180.0 * PI);
  double Bx = B * cos((180 - min) / 360.0 * PI);
  double By = B * sin((180 - min) / 360.0 * PI);
  cout << fixed << setprecision(12) << sqrt(pow(Ax - Bx, 2) + pow(Ay - By, 2)) << endl;
}


Measured memory_bytes: 4060
N = int(input())
A, B = map(int,input().split())
P = list(map(int,input().split()))

P.sort()
d = {
    "A":0,
    "B":0,
    "C":0,
}
for p in P:
    if p <= A:
        d["A"] += 1
    elif p <= B:
        d["B"] += 1
    else:
        d["C"] += 1

print(min(d["A"],d["B"],d["C"]))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define F first
#define S second

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    std::vector<string> v;
    std::map<string, int> mp;
    string s;
    for (size_t i = 0; i < n; i++) {
        cin>>s;
        mp[s]++;

    }
    int ans = -1;
    for(auto it : mp){
        ans = max(ans , it.second);
    }
    for(auto it : mp){
        if(it.second == ans){
            v.push_back(it.first);
        }
    }
    sort(ALL(v));
    for (size_t i = 0; i < v.size(); i++) {
        cout<<v[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 25584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;

    return 0;
}

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

int main(void) {

  for(;;) {
    int N, Q;
    std::cin >> N >> Q;
    if( N == 0 and Q == 0 ) break;

    int date[128] = {};
    for(int i = 0; i < N; ++i) {
      int M;
      std::cin >> M;
      for(int j = 0; j < M; ++j) {
        int temp;
        std::cin >> temp;
        date[temp] += 1;
      }
    }

    int num = 0;
    int res = 0;
    for(int i = 0; i < 128; ++i) {
      if( Q <= date[i] ) {
        if( num < date[i] ) {
          num = date[i];
          res = i;
        }
      }
    }

    std::cout << (num != 0 ? res : 0) << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
int A[3];
 
cin >> A[0] >> A[1] >> A[2];
 
sort(A,A+3);
 
cout << A[0]  << " "<< A[1] << " " <<A[2] << endl;
 
}

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

using namespace std;

int main(){
	int n; cin >> n;
	vector<int> w(n);
	int r = 0;
	int l = 0;
	for(int i=0; i<n; i++){
		cin >> w[i];
		l += w[i];
	}

	int ans = l;
	for(int i=0; i<n; i++){
		r += w[i];
		l -= w[i];
		ans = min(ans, abs(r-l));
	}
	
	cout << ans << endl;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int a, b;
    cin >> a >> b;
    char c = [&] {
        if (a + b == 15) return '+';
        if (a * b == 15) return '*';
        return 'x';
    }();
    cout << c << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = 100001;
		boolean[] isPrime = new boolean[N];
		for(int i=2;i<N;++i) isPrime[i] = true;
		for(int i=2;i<=(int)Math.sqrt((double)N);++i){
			if(isPrime[i]){
				for(int j=2*i;j<N;j+=i) isPrime[j] = false;
			}
		}		
		int[] ruiseki = new int[N];
		ruiseki[1] = 0;
		for(int i=3;i<N;i+=2){
			if(isPrime[i]&&isPrime[(i+1)/2]) ruiseki[i]++;
			ruiseki[i] += ruiseki[i-2];
		}
		
		int Q = sc.nextInt();
		for(int i=0;i<Q;++i){
			int l = sc.nextInt()-2;
			if(l<0) l=1;
			int r = sc.nextInt();
			System.out.println(ruiseki[r]-ruiseki[l]);
		}
		return;
	}
}

Measured memory_bytes: 63300
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10**9+7
xacc, yacc = [0], [0]

for i in range(n-1):
    xacc.append((xacc[-1]+x[i+1]-x[i])%MOD)

for i in range(m-1):
    yacc.append((yacc[-1]+y[i+1]-y[i])%MOD)

X, t = 0, 0

for i in range(1, n):
    X += i*xacc[i]-t
    X %= MOD
    t += xacc[i]

Y, t = 0, 0

for i in range(1, m):
    Y += i*yacc[i]-t
    Y %= MOD
    t += yacc[i]

print(X*Y%MOD)

Measured memory_bytes: 102992
#include <iostream>
#include <string>
//#include <cstring>
//#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
//#include <stack>
//#include <queue>
//#include <chrono>
//#include <numeric>
//#include <set>
//#define _USE_MATH_DEFINES
//#include <cmath>
//#include <math.h>
//#include <iomanip>
//#include <list>
//#include <limits>

using namespace std;
const int infty = static_cast <int> (pow(256, sizeof(int)) / 2 - 1);

class cRMQ
{
	int max;
	vector<int> va;
public:
	cRMQ(int n);
	void update(int i, int x);
	int find(int s, int t);
	int find(int s, int t, int k, int l, int r);
};

cRMQ::cRMQ(int n)
{
	int n_ = 1;
	while (n_ < n) n_ *= 2;
	max = n_ - 1;
	va.resize(2 * n_ - 1);
	for(int i = 0; i < 2 * n_ - 1; ++i)
		va[i] = infty;
}

void cRMQ::update(int k, int x)
{
	k += max;
	va[k] = x;
	while(k > 0)
	{
		k = (k - 1) / 2;
		va[k] = min(va[k * 2 + 1], va[k * 2 + 2]);
	}
}
int cRMQ::find(int s, int t)
{
	return find(s, t, 0, 0, max);
}
int cRMQ::find(int s, int t, int k, int l, int r)
{
	if (s <= l && r <= t)return va[k];
	if (r < s || t < l)return infty;
	int m = (l + r) / 2;
	return min(find(s, t, k * 2 + 1, l, (l+r)/2.0 - 0.5), find(s, t, k * 2 + 2, (l+r)/2.0 + 0.5, r));
}

int main()
{
	//ifstream fin("DSL_2_A_in3.txt");
	////ifstream fin("test.txt");
	//if (!fin.is_open())
	//{
	//	cout << "File not found." << endl;
	//	return 0;
	//}

	//fin.tie(0);
	//ios::sync_with_stdio(false);

	//int n,q;
	//fin >> n >> q;
	//fin.ignore();

	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, q;
	cin >> n >> q;
	cin.ignore();

	int com, x, y;
	cRMQ cr(n);

	for (int i = 0; i < q; ++i)
	{
		cin >> com >> x >> y;
		//fin >> com >> x >> y;
		switch (com)
		{
		case 0:
			cr.update(x, y);
			break;
		case 1:
			cout << cr.find(x, y) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3816
N = int(input())

t = [0]*(N+1)
x = [0]*(N+1)
y = [0]*(N+1)

for i in range(1,N+1):
    t[i],x[i],y[i] = map(int, input().split())
    if (t[i] - t[i-1]) < abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]): #最短でも無理な場合
        print("No")
        break
    elif t[i]%2 != (x[i]+y[i])%2: #止まれないか
        print("No")
        break
    if i == N:
        print("Yes")

Measured memory_bytes: 11668
#include<iostream>
#include<algorithm>
#include<cmath>

int digit(long long n){
    int count = 0;

    while(n > 0){
        n /= 10;
        count++;
    }
    return count;
}

int main(void){
    long long n;
    std::cin >> n;

    int ans = 50;

    for(int i = 1; i <= std::sqrt(n); i++){
        long long a = i;
        if(n % a != 0) continue;

        long long b = n / a;

        int digit_a = digit(a);
        int digit_b = digit(b);

        int temp_ans = std::max(digit_a, digit_b);
        ans = std::min(ans, temp_ans);
    }
    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans;
    if (a <= k) {
        ans = a - max(0, k - a - b);
    } else {
        ans = k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
ll N,W;
ll v[40],w[40];
vector<P> x,y;
 
void func(int si,int ti,vector<P> &x){
  int size=ti-si;
  for(int bit=0;bit<(1<<size);bit++){
    P p=P(0,0);
    for(int i=0;i<size;i++){
      if(bit>>i&1){
        p.first+=w[si+i];
        p.second+=v[si+i];
      }
    }
    x.push_back(p);
  }
}
 
int main(){
  cin>>N>>W;
  for(int i=0;i<N;i++)cin>>v[i]>>w[i];
   
  func(0,N/2,x);
  sort(x.begin(),x.end());
  func(N/2,N,y);
  sort(y.begin(),y.end());
   
  ll target=0,maxm=-(1LL<<60),ans=0;
   
  for(int i=(int)x.size()-1;i>=0;i--){
    P p=x[i];
    while(target<(int)y.size() && p.first+y[target].first <=W ){
      maxm=max(maxm,y[target].second);
      target++;
    }
    ans=max(ans,maxm+p.second);
  }
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 43760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

	vector<long long int> A;
	for (int ii = 0; ii < N; ii++) {
		long long int a;
		cin >> a;
		A.push_back(a);
	}

	sort(A.begin(), A.end(), [](const auto& item1, const auto& item2) {
		return item1 < item2;
	});

	long long int n = A.back();
	long long int r = -1;
	double b = (double) n;
	for (auto& a : A) {
		if (b > fabs((double)a - (double)n / 2.0)) {
			r = a;
			b = fabs((double)a - (double)n / 2.0);
		}
	}
	cout << n << " " << r << endl;

	return 0;
}


Measured memory_bytes: 1528
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int n=s[0],k=s[1];
		int[] a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[] dp=new long[k+a[n-1]];
		for(int i=0;i<k;i++){
			if(i<a[0]){dp[i]=1;}
			if(dp[i]==1){
				for(int j=0;j<n;j++){dp[i+a[j]]=2;}
			}
			else if(dp[i]==2){
				for(int j=0;j<n;j++){
					if(dp[i+a[j]]==0){dp[i+a[j]]=1;}
				}
			}
		}
		Console.WriteLine("{0}",dp[k]==2?"First":"Second");
	}
}

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

ll GCD(ll x, ll y) {
    return x ? GCD(y % x, x) : y;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    //互いに素なペアがある時必ず一になる=>ユークリッドの互除法
    //互いに素なものがないとき，配列の最小値になる

    sort(A.begin(), A.end());
    ll x = A[0];

    for (int i = 1; i < N; i++) {
        x = GCD(x, A[i]);
    }

    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9 + 7; 
const int maxn = 3e6;
int d[22][maxn], G[30][30];
int a[22][maxn], c[22], vis[22][maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			cin >> G[i][j];
		}
	}
	for(int i = 0; i < n; ++i){
		if(G[0][i]) {
			d[0][1 << i] = 1;
			a[0][c[0]++] = 1 << i;
		}
	}
	for(int i = 0; i < n - 1; ++i){
		for(int j = 0; j < c[i]; ++j){
			for(int k = 0; k < n; ++k){
				if(((a[i][j] & (1 << k)) == 0) && G[i + 1][k] == 1) {
					if(!vis[i + 1][a[i][j] | (1 << k)]){
						a[i + 1][c[i + 1]++] = a[i][j] | (1 << k);
						vis[i + 1][a[i][j] | (1 << k)] = 1;
					}
					d[i + 1][a[i][j] | (1 << k)] = (d[i + 1][a[i][j] | (1 << k)] + d[i][a[i][j]]) % inf;
				}
			}
		}
	}
	/*for(int i = 0; i < n; ++i){
		cout << c[i] << ' ';
		for(int j = 0; j < (1 << n); ++j){
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}*/
	cout << d[n - 1][(1 << n) - 1] << endl;
	return 0;
}

Measured memory_bytes: 430336
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 3010;

ll N, Q, A[maxn], dp[maxn][maxn];

ll poww(ll a, ll b) {
    ll r = 1;
    while (b) {
        if (b & 1) Mul(r, a);
        Mul(a, a);
        b >>= 1;
    }
    return r;
}

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

    cin >> N >> Q;
    fori (i, N) cin >> A[i];

    ll q2 = poww(2, Q);
    ll inv2 = poww(2, MOD - 2);
    fori (i, N) fori (j, N) {
        if (A[i] > A[j]) dp[i][j] = q2;
    }

    fori (q, Q) {
        ll x, y; cin >> x >> y; --x, --y;
        fori (i, N) {
            if (i == x || i == y) continue;
            ll a = dp[x][i] = 1LL * dp[x][i] * inv2 % MOD;
            ll b = dp[i][x] = 1LL * dp[i][x] * inv2 % MOD;
            ll c = dp[y][i] = 1LL * dp[y][i] * inv2 % MOD;
            ll d = dp[i][y] = 1LL * dp[i][y] * inv2 % MOD;
            Add(dp[x][i], c), Add(dp[i][x], d);
            Add(dp[y][i], a), Add(dp[i][y], b);
        }
        ll a = dp[x][y] = 1LL * dp[x][y] * inv2 % MOD;
        ll b = dp[y][x] = 1LL * dp[y][x] * inv2 % MOD;
        Add(dp[x][y], b), Add(dp[y][x], a);
    }
    ll s = 0;
    fori (i, N) forifrom (j, i + 1, N) Add(s, dp[i][j]);
    cout << s << '\n';

}


Measured memory_bytes: 38940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w,board[2001][2001],l[2001],c=0,max=0;
    string str[2001];
    cin >> h >> w;
    for(int i=0;i<h;i++){
        cin >> str[i];
    } 
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(str[i][j]=='.'){
                c++;
                l[j]++;
            }else{
                for(int k=j-1;k>=0;k--){
                    if(str[i][k]=='#'){
                        c=0; 
                        break;
                    }
                    board[i][k]=c;
                }
                for(int k=i-1;k>=0;k--){
                    if(str[k][j]=='#'){
                        l[j]=0;
                        break;
                    }
                    board[k][j]+=l[j];
                }
                c=0;
                l[j]=0;
                
            }
        }
        for(int j=w-1;j>=0;j--){
            if(str[i][j]=='#'){
                c=0;
                break;
            }
            board[i][j]=c;
        }
        c=0;
    }
    for(int i=0;i<w;i++){
        for(int j=h-1;j>=0;j--){
            if(str[j][i]=='#'){
                break;
            }
            board[j][i]+=l[i];
        }
    }
    //cout << endl;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //cout << setw(3) << board[i][j] << " ";
            if(board[i][j]>max){
                max=board[i][j];
            }
           
        }
        //cout << endl;
    }
    cout << max-1 << endl;
    return 0;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[101010];
const ll mo=1000000007;

const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll sum[101010];


ll comb(ll N_, ll C_) {
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	comb(1,1);
	cin>>N;
	FOR(i,N) cin>>X[i];
	
	for(i=1;i<=N;i++) {
		sum[i]=(sum[i-1]+inv[i]*inv[i+1])%mo;
	}
	
	ll ret=0;
	y=N-1;
	FOR(x,y) {
		(ret+=inv[y-x]%mo*(X[y]-X[x]))%=mo;
	}
	
	FOR(x,N-1) {
		if(x) (ret+=X[x]*sum[x])%=mo;
		ret+=mo-X[x]*sum[N-2-x]%mo;
	}
	
	ret=(ret%mo+mo)%mo;
	
	cout<<ret*fact[N-1]%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10880
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int r, g, b;
  cin >> r >> g >> b;
  if((100 * r + 10 * g + b) % 4 == 0)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N =1e7+7;
int f[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    for (int i = 1; i < N; ++i)
        for (int j = i; j < N; j +=i)
            ++f[j];

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans += i*f[i];
    cout << ans << endl;
    //cout << Time << endl;
}

Measured memory_bytes: 81772
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[100005], finv[100005], inv[100005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge>>G;

int main() {
	int n;
	cin >> n;
	if (n % 2) {
		cout << (n - 1)*(n - 2) / 2 - (n - 1) / 2 + n - 1 << endl;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n - 1; j++)
				if (j != n - i) { cout << i << " " << j << endl; }
		}
		for (int i = 1; i <= n - 1; i++) { cout << i << " " << n << endl; }
	}
	else {
		cout << n * (n - 1) / 2 - n / 2 << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++)
				if (j != n + 1 - i) { cout << i << " " << j << endl; }
		}
	}
}

Measured memory_bytes: 256
import sys
import heapq
from functools import lru_cache
sys.setrecursionlimit(10000)

# \n
def input():
    return sys.stdin.readline().rstrip()


def level(n, k):
    number = 2 ** (n + 1) - 3  # 一個レベル下のやつの数
    cn = 2**(n+2) -3
    if n == 0:
        return 1
    elif k==cn:
        return (2**(n+1) -1)

    else:
        if k == 1:
            return 0
        elif k <= 1 + number:
            return level(n - 1, k - 1)
        elif k == 2 + number:
            return level(n - 1, number) + 1
        else:
            return 1 + level(n - 1, number) + level(n - 1, min(number, k - number - 2))



def main():

    n,k=map(int,input().split())
    print(level(n,k))


if __name__ == "__main__":
    main()


Measured memory_bytes: 67092
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

int main(){
    int n, k; string s; cin >> n >> s >> k;k--;
    char c = s[k];
    rep(i, n)if(s[i]!=c)s[i]='*';
    cout << s << ln;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e2) + 5;
const int MAX_A = int(15e6);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

string s;
int n;
int cnt = 1;

void rec(int k, int l, int r){
    if(k<0)return;
    if(s[k]=='1'){
        int nl, nr;
        nl = ++cnt;
        nr = ++cnt;
        cout << l << " " << nl << endl;
        cout << r << " " << nr << endl;
        rec(k-1, nl, nr);
    }
    else {
        cout << l << " " << ++cnt << endl;
        cout << r << " " << ++cnt << endl;
        rec(k-1, l, r);
    }
}

int main() {
    
    cin >> s;
    n = s.size();
    REP(i,n/2){
        if(s[i] != s[n-i-2]){
            cout << -1 << endl;
            return 0;
        }
    }
    if(s[n-1]=='1' || s[0] == '0'){
        cout << -1 << endl;
        return 0;
    }
    if(n%2==1){
        rec(n/2-1, 1, 1);
    }
    else{
        ++cnt;
        cout << 1 << " " << 2 << endl;
        if(s[n/2-1]=='1'){
            rec(n/2-2,1,2);
        }
        else{
            rec(n/2-2,1,1);
        }
    }
    return 0;
}


Measured memory_bytes: 1664
a,b,c,d,e = map(int,input().split())

f = c - a
g = d - b
if g < 0:
  g = 60 + g
  f -=1
total = 60 * f + g
if total - e <= 0:
  print('0')
else:
    total -= e 
    print(total)

Measured memory_bytes: 9136
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([
                ['khabarovsk' ,20],
                ['moscow', 10],
                ['kazan', 50],
                ['kazan', 35],
                ['moscow', 60],
                ['khabarovsk', 40]
            ]),
                [3, 4, 6, 1, 5, 2]
        )

    def test_2(self):
        self.assertEqual(think([
                ['yakutsk', 10],
                ['yakutsk', 20],
                ['yakutsk', 30],
                ['yakutsk', 40],
                ['yakutsk', 50],
                ['yakutsk', 60],
                ['yakutsk', 70],
                ['yakutsk', 80],
                ['yakutsk', 90],
                ['yakutsk', 100]
            ]),
                [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
        )


def solve():
    list_of_s_and_p = read()
    result = think(list_of_s_and_p)
    write(result)


def read():
    n = read_int(1)[0]
    list_of_s_and_p = []
    for _ in range(n):
        buf = read_line().split()
        list_of_s_and_p.append([buf[0], int(buf[1])])
    return list_of_s_and_p


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(list_of_s_and_p):
    data_with_index = []
    for i, e in enumerate(list_of_s_and_p):
        data_with_index.append((i + 1, e[0], e[1]))
    data_with_index.sort(key=lambda x: (x[1], -x[2]))
    return [x[0] for x in data_with_index]


def write(result):
    for r in result:
        print(r)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 5704
#include <stdio.h>

using namespace std;
typedef unsigned long long llong;

#define MAX 100001
const llong mod = 1000000000 + 7;

int main()
{
  llong N;
  llong ans = 0;
  scanf("%llu", &N);
  for (llong i = 1; i <= N; i++)
  {
    if (i % 3 == 0 || i % 5 == 0)
      continue;
    ans += i;
  }
  printf("%llu\n", ans);

  return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(){
  int N;
  while(cin >> N && N){
    const int H = 5010;
    const int W = 5;
    bool block[H][W] = {};
    int height[W] = {};
    int n_h = 0;
    REP(iter, N){
      int d, l, bx;
      cin >> d >> l >> bx;
      bx --;
      if(d == 1){
        // yoko
        int h = 0;
        for(int x = bx; x < bx + l; x++) h = max(h, height[x]);
        for(int x = bx; x < bx + l; x++) block[h][x] = true;
        bool line = true;
        for(int x = 0; x < W; x++) if(!block[h][x]) line = false;
        if(line){
          for(int x = 0; x < W; x++) block[h][x] = false;
        }
      }else if(d == 2){
        // tate
        for(int y = height[bx]; y < height[bx] + l; y++)
          block[y][bx] = true;
        for(int y = height[bx]; y < height[bx] + l; y++){
          bool line = true;
          for(int x = 0; x < W; x++) if(!block[y][x]) line = false;
          if(!line) continue;
          for(int x = 0; x < W; x++) block[y][x] = false;
        }
      }
      //bool new_block[H][W] = {};
      int new_height[W] = {};
      int new_nh = 0;
      int curr = 0;
      /*
      for(int y = n_h + 5; y >= 0; y--){
        debug(block[y], block[y] + 5);
      }
      cout << endl;
      */
      for(int y = 0; y < n_h + 5; y++){
        bool clear = true;
        for(int x = 0; x < W; x++) if(block[y][x]) clear = false;
        if(clear) continue;
        for(int x = 0; x < W; x++)if(block[y][x]){
          block[y][x] = false;
          block[curr][x] = true;
          new_height[x] = curr + 1;
        }
        new_nh = ++curr;
      }
      //memcpy(block, new_block, sizeof(block));
      memcpy(height, new_height, sizeof(height));
      n_h = new_nh;
    }
    int ans = 0;
    REP(y, H)REP(x, W) ans += block[y][x];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
#define P pair<int,int>
int main(){
  int n,m,p,y;
  cin >> n >> m;
  vector<P> v[n];
  string ans[m];
  for(int i = 0;i < m;i++){
    cin >> p >> y;
    v[p-1].push_back(P(y, i));
  }
  for(int i = 0;i < n;i++){
    sort(v[i].begin(), v[i].end());
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < v[i].size(); j++){
      ostringstream spout, stout;
      spout << setfill('0') << setw(6) << i+1;
      stout << setfill('0') << setw(6) << j+1;
      ans[v[i][j].second] = spout.str() + stout.str();
    }
  }
  for(int i = 0;i < m;i++)
    cout << ans[i] << endl;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+3;
int n,siz[N],he[N],e;
long long anss;
struct syzs{
	long long val;
	int num;
} a[N];
struct ans{
	int e1,e2;
	bool operator <(const ans &emm) const{
	    if(emm.e1==e1) return e2>emm.e2;
		return emm.e1<e1;
	}
};
struct edg{
	int ne,to;
} edg[N];
bool cmp(syzs c,syzs b){
	return c.val>b.val;
}
int find(int k){
	long long chec=2*siz[k]-n;
	for(int i=k+1;i<=n;i++) if(a[i].val-a[k].val==chec) return i;
	return -1;
}
long long read(){
	long long s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*f;
}
void add(int u,int v){
	edg[++e].to=v;
	edg[e].ne=he[u];
	he[u]=e;
}
void test(int u,int fa,int dep){
	anss+=dep;
	for(int i=he[u];i;i=edg[i].ne){
		int v =edg[i].to;
		if(v==fa) continue;
		test(v,u,dep+1);
	}
}
int main(){
    priority_queue <ans> q;
	cin>>n;
	for(int i=1;i<=n;i++){
		a[i].val=read();//scanf("%lld",&a[i].val);
		a[i].num=i;
		siz[i]=1;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<n;i++){
		int v=find(i);
		if(v==-1){
			cout<<-1<<endl;
			return 0;
		}
		siz[v]+=siz[i];
		add(a[i].num,a[v].num);
		add(a[v].num,a[i].num);
		q.push((ans) {min(a[v].num,a[i].num),max(a[v].num,a[i].num)});
	}
	test(a[1].num,0,0);
	if(anss!=a[1].val){
		cout<<-1<<endl;
		return 0;
	}
	while(!q.empty()){
		int v1=q.top().e1,v2=q.top().e2;
    	q.pop();
    	printf("%d %d\n",v1,v2);
	}
}

Measured memory_bytes: 13172
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N,M;
  cin >> N >> M;
  
  int ans = 0;
  
  ans += N * (N - 1) / 2;
  ans += M * (M - 1) / 2;
  
  cout << ans <<endl;
}

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


void input(); template<typename First,typename... Rest> void input(First&,Rest&...);
void inputVector(); template<typename First,typename... Rest>  void inputVector(std::vector<First>&,Rest&...);
#define loop(n) for(int i = 0;i < (int)(n);++i)


void calculate(){
    std::string r,g,b;
    input(r,g,b);
    if(stoi(g + b) % 4 == 0) std::cout << "YES\n";
    else std::cout << "NO\n";
}

int main(int,char**){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    calculate();
}



void input(){return;}
template<typename First,typename... Rest>
void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> 
void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#define task ""
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 2;
int n;
const ll mod = 1e9 + 7;
ll ans = 0;
ll r[N], gt[N], rgt[N], POW[N], POW2[N];

void Read()
{
	cin >> n;
}

ll Pow(ll a, ll b)
{
	ll ans = 1;
	for (; b > 0; b >>= 1)
	{
		if (b & 1)
			ans = ans * a % mod;
		a = a * a % mod;
	}
	return ans;
}

void Prepare()
{
	POW[0] = gt[0] = POW2[0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		gt[i] = gt[i - 1] * i % mod;
		POW[i] = POW[i - 1] * 8ll % mod;
		rgt[i] = Pow(gt[i], mod - 2);
		r[i] = Pow(i, mod - 2);
		POW2[i] = POW2[i - 1] * 2 % mod;
	}
}

void Solve()
{
	Prepare();
	ll c = n;
	for (int i = 2; i <= n; ++i)
	{
		ll cur = (POW2[i] - 2) % mod;
		c = c * (n - i + 1) % mod * r[i] % mod;
		ans = (ans + c * POW[n - i] % mod * cur % mod) % mod;
	}
	cout << (ans + mod) % mod;
}

main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	Read();
	Solve();
}


Measured memory_bytes: 42672
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define inf 9999999
using namespace std;

typedef int weight;
typedef vector<weight> array;
typedef vector<array> matrix;

void backward_traverse(int v, int s, int r, matrix &g,
  vector<int> &no, vector< vector<int> > &comp,
  vector<int> &prev, vector<weight> &mcost,
  vector<int> &mark, weight &cost, bool &found) {
  const int n = g.size();
  if (mark[v]) {
    vector<int> temp = no;
    found = true;
    do {
      cost += mcost[v];
      v = prev[v];
      if (v != s) {
        while (comp[v].size() > 0) {
          no[comp[v].back()] = s;
          comp[s].push_back(comp[v].back());
          comp[v].pop_back();
        }
      }
    } while (v != s);
    for (int j = 0; j < n; ++j)
      if (j != r && no[j] == s)
        for (int i = 0; i < n; ++i)
          if (no[i] != s && g[i][j] < inf)
            g[i][j] -= mcost[ temp[j] ];
  }
  mark[v] = true;
  for (int i = 0; i < n; ++i)
    if (no[i] != no[v] && prev[ no[i] ] == v)
      if (!mark[ no[i] ] || i == s)
        backward_traverse(i, s, r, g,
            no, comp, prev, mcost, mark, cost, found);
}

weight minimum_spanning_arborescence(int r, matrix &g) {
  const int n = g.size();

  vector<int> no(n);
  vector< vector<int> > comp(n);
  for (int i = 0; i < n; ++i) {
    no[i] = i;
    comp[i].push_back(i);
  }
  weight cost = 0;
  while (1) {
    vector<int> prev(n, -1);
    vector<weight> mcost(n, inf);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == r) continue;
        if (no[i] != no[j] && g[i][j] < inf) {
          if (g[i][j] < mcost[ no[j] ]) {
            mcost[ no[j] ] = g[i][j];
            prev[ no[j] ] = no[i];
          }
        }
      }
    }
    bool stop = true;
    vector<int> mark(n);
    for (int i = 0; i < n; ++i) {
      if (i == r || mark[i] || comp[i].size() == 0) continue;
      bool found = false;
      backward_traverse(i, i, r, g,
          no, comp, prev, mcost, mark, cost, found);
      if (found) stop = false;
    }
    if (stop) {
      for (int i = 0; i < n; ++i)
        if (prev[i] >= 0)
          cost += mcost[i];
      return cost;
    }
  }
}

int main(){
	int V,E,r,s,t,w;
	scanf("%d%d%d",&V,&E,&r);
	matrix g(V);
	for(s=0;s<V;s++){
		g[s].resize(V);
		for(t=0;t<s;t++)g[s][t]=inf;
		g[s][t++]=0;
		for(;t<V;t++)g[s][t]=inf;
	}
	for(;E--;)scanf("%d%d%d",&s,&t,&w),g[s][t]=w;
	printf("%d\n",minimum_spanning_arborescence(r,g));
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

using namespace std;

int main() {

	SINT32 N = 0;

	cin >> N;

	DOUBLE ANS = 0;

	DOUBLE BUF64 = 0;
	SINT8 BUFST[100];

	
	for (SINT32 i = 0; i < N; i++) {
		cin >> BUF64;
		cin >> BUFST;
		if (BUFST[0] == 'J') {
			ANS = BUF64 + ANS;
		} else {
			ANS = 380000.0 * BUF64 + ANS;
		}
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

Measured memory_bytes: 256
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    al = list(map(int, input().split()))
    su = sum([1/a for a in al])
    print(1/su)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
A = list(input())
B = list(input())
C = list(input())
S = [A,B,C]
turn = 0
while True:
    if S[turn] != []:
        k = S[turn].pop(0)
        if k == 'a':
            turn = 0
        elif k == 'b':
            turn = 1
        elif k == 'c':
            turn = 2
    else:
        break
if turn == 0:
    print("A")
elif turn == 1:
    print("B")
elif turn == 2:
    print("C")

Measured memory_bytes: 3064