akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdlib>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int n;
  ll sum=0;
  ll a[100010]={};
  ll b[100010]={};

  cin >> n;
  for(int j=1; j<=n; j++){
    cin >> a[j];
    sum+=llabs(a[j]-a[j-1]);
    b[j]=llabs(a[j]-a[j-1]);
  }
  sum+=llabs(a[n+1]-a[n]);
  b[n+1]=llabs(a[n+1]-a[n]);

  for(int i=1; i<=n; i++){
    ll ans=sum;
    ans-=(b[i]+b[i+1]);
    ans+=llabs(a[i+1]-a[i-1]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
int main()
{
    long long a[10],x;
    int i,j,k,l;
    for(i=0;i<10;i++)
    scanf("%lld",&a[i]);
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            if(a[j]<a[j+1])
            {
                x=a[j];
                a[j]=a[j+1];
                a[j+1]=x;
            }
        }
    }
    printf("%lld\n%lld\n%lld\n",a[0],a[1],a[2]);
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define INF 1e+9

int a[300][300];
int d[300][300];


void warshall_floyd(int V)
{
    rep(i,V){
        d[i][i] = 0;
    }
    rep(i,V){
        rep(j,V){
            rep(k,V){
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
}


int main(){

  int n;
  cin>>n;
  rep(i,n){
    rep(j,n){
      cin>>a[i][j];
      d[i][j]=a[i][j];
    }
  }
  warshall_floyd(n);
  bool flag=true;
  rep(i,n){
    if(!flag)break;
    rep(j,n){
      if(d[i][j]!=a[i][j]){flag=false;break;}
    }
  }
  if(!flag){cout<<-1<<endl;return 0;}
  long long sum = 0;
  rep(i,n){
    rep(j,n){
      flag = true;
      rep(k,n){
        if(i!=k&&j!=k&&a[i][j] == a[i][k]+a[k][j]){
          flag = false;
        }
      }
      if(flag)sum+=a[i][j];
    }
  }
  cout << sum/2 << endl;


  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

struct Node {
  int id, s0, s1;
  bool operator == (const Node &A) const {
    return id == A.id && s0 == A.s0 && s1 == A.s1;
  }
  bool operator < (const Node &A) const {
    if (s0 * A.s1 == s1 * A.s0)
      return id ^ A.id ? id < A.id : (s0 ^ A.s0 ? s0 < A.s0 : s1 < A.s1);
    return s0 * A.s1 < s1 * A.s0;
  }
};
struct DHeap {
  priority_queue <Node> I, O;
  inline void Pop() {
    while (!I.empty() && !O.empty() && I.top() == O.top())
      I.pop(), O.pop();
  }
  inline void insert(Node x) { I.push(x); }
  inline void del(Node x) { O.push(x); }
  inline Node top() { return Pop(), I.top(); }
  inline bool empty() { return Pop(), I.empty(); }
} q;

int const MAXN = 2e5 + 5;
int fa[MAXN], rt[MAXN];
Node Now[MAXN];

int Find(int k) { return rt[k] == k ? k : rt[k] = Find(rt[k]); }

signed main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n; read(n);
  for (RI i = 2; i <= n; ++i) read(fa[i]);
  for (RI i = 1, x; i <= n; ++i)
    read(x), q.insert(Now[i] = (Node){i, x == 0, x == 1}), rt[i] = i;
  LL ans = 0;
  while (!q.empty()) {
    Node t = q.top(); q.del(t);
    if (t.id == 1) continue;
    int f = Find(fa[t.id]);
    rt[t.id] = f;
    if (f != 1) q.del(Now[f]);
    ans += 1ll * Now[f].s1 * t.s0;
    Now[f].s1 += t.s1, Now[f].s0 += t.s0;
    if (f != 1) q.insert(Now[f]);
  }
  printf("%lld\n", ans);

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 25452
H,W,M = map(int,input().split())
X = [0 for i in range(H)]
Y = [0 for j in range(W)]
combi = []
for k in range(M):
    pos = list(map(int,input().split()))
    X[pos[0]-1]+=1
    Y[pos[1]-1]+=1
    combi.append(1000000007*pos[0]+pos[1])
a = max(X)
b = max(Y)
X_max = [0 for d in range(H)]
Y_max = [0 for e in range(W)]
for l in range(H):
    if X[l] == a:
        X_max[l]+=1
for m in range(W):
    if Y[m] == b:
        Y_max[m]+=1
X_count = X_max.count(1)
Y_count = Y_max.count(1)
chance = X_count*Y_count
flg = 1
for s in combi:
    ans1 = s//1000000007
    ans2 = s % 1000000007
    if X_max[ans1-1]==1 and Y_max[ans2-1]==1:
        chance-=1
if chance > 0:
    flg = 0
print(a + b - flg)


Measured memory_bytes: 141124
from copy import deepcopy as dp
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
for i in a:
    if a_sum[-1] + i > 10 ** 9:
        break
    a_sum.append(a_sum[-1] + i)

b_sum = [0]
for i in b:
    if b_sum[-1] + i > 10 ** 9:
        break
    b_sum.append(b_sum[-1] + i)

class binarySearch(object):

    def __init__(self, target):
        self.target = dp(target)
        self.target.append(10**18)

    def set(self, value):
        self.value = value

    def search(self):
        self.lower, self.upper = 0, len(self.target) - 1
        while self.upper != self.lower+1:
            next = (self.upper + self.lower) // 2
            if self.target[next] > self.value:
                self.upper = next
            else:
                self.lower = next
        return self.lower


test = binarySearch(b_sum)

ans = 0
for i, a_time in enumerate(a_sum):
    rest = k - a_time
    if rest >= 0:
        test.set(rest)
        ans = max(i + test.search(), ans)
    else:
        break

print(ans)

Measured memory_bytes: 43528
n = int(input())
A = list(map(int,input().split()))
if n %2 == 0:
    s = [2]*(n//2)
else:
    s = [2]*(n//2+1)
    s[0] = 1
if n%2 == 0:
    for a in A:
        if s[(a-1)//2] >0:
            s[(a-1)//2] -= 1
        else:
            continue
    if sum(s)==0:
        print(2**(n//2)%(10**9+7))
    else:
        print(0)
else:
    for a in A:
        if s[a//2] >0:
            s[a//2] -= 1
        else:
            continue
    if sum(s) == 0:
        print(2**((n-1)//2)%(10**9+7))
    else:
        print(0)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll a,b;cin>>a>>b;
    cout<<a*b<<" "<<2*(a+b)<<endl;
}

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



Measured memory_bytes: 3112
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int arr[N];
int p[N],x[N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<vector<int> > v;
    v.assign(n+1,vi());
    for(int i = 0; i < m; ++i)
    {
        cin>>p[i]>>x[i];
        v[p[i]].push_back(x[i]);
    }
    for(int i = 0; i <= n; ++i)
        sort(v[i].begin(),v[i].end());
    for(int i = 0; i < m; ++i)
    {
        printf("%06d",p[i]);
        int index = lower_bound(v[p[i]].begin(),v[p[i]].end(),x[i]) - v[p[i]].begin();
        index++;
        printf("%06d\n",index);
    }
}


Measured memory_bytes: 7808
#include <iostream>
    using namespace std;
    typedef long long ll;

    int main()
    {
        ll A, B;
        cin >> A >> B;
        ll minAB = min(A, B);
        ll maxAB = max(A, B);
        while(maxAB % minAB != 0){
            ll tmp = minAB;
            minAB = maxAB % minAB;
            maxAB = tmp;
        }
        ll gcd = minAB;
        int count = 1;
        for (ll i = 2; i <= gcd; i++){
            bool watta = false;
            while (gcd % i == 0){
                gcd /= i;
                watta = true;
            }
            if(watta){
                count++;
            } else if (i * i > minAB){
                count++;
                break;
            } 
        }
        cout << count;
        return 0;
    }

Measured memory_bytes: 256
n = int(input())
li = []
 
for i in range(n):
    a = int(input())
    li.append(a)
    
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
while len(li) > 1:
    a = li[0]
    b = li[1]
    li.pop(1)
    li.pop(0)
    ans = a * b // gcd(a, b)
    li.append(ans)
 
print(li[0])

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

int main(){
  int A, B;
  int ans = 0;
  int count = 0;
  cin >> A >> B;
  while(count < 2){
    if(A > B){
      ans = ans + A;
      A = A - 1;
    }else{
      ans = ans + B;
      B = B - 1;
    }
    count++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        if(a == b){
            if(a != c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else{
            if(a == c || b == c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int a[3][3];
bool c[3][3];
int b[100];
bool have[101];
int n;

void Output(bool ok) {
  cout << (ok ? "Yes" : "No") << endl;
  exit(0);
}

int main()
{
  for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    have[b[i]] = true;
  }

  for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) {
    c[i][j] = have[a[i][j]];
  }

  for (int i = 0; i < 3; ++i) {
    if (c[i][0] && c[i][1] && c[i][2]) Output(true);
    if (c[0][i] && c[1][i] && c[2][i]) Output(true);
  }

  if (c[0][0] && c[1][1] && c[2][2]) Output(true);
  if (c[2][0] && c[1][1] && c[0][2]) Output(true);

  Output(false);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  vector<vector<pair<int,int>>> cnt(2,vector<pair<int,int>>(100005,{0,0}));
  for(int i=0;i<n;i++){
      cin>>v[i];
      cnt[i%2][v[i]].first++;
      cnt[i%2][v[i]].second=v[i];
  }
  sort(cnt[0].rbegin(),cnt[0].rend());
  sort(cnt[1].rbegin(),cnt[1].rend());

  if(cnt[0][0].second!=cnt[1][0].second){
      cout<<n-cnt[0][0].first-cnt[1][0].first<<endl;
  }else{
      cout<<n-max(cnt[0][1].first+cnt[1][0].first,cnt[0][0].first+cnt[1][1].first)<<endl;
  }

  return 0;
}


Measured memory_bytes: 2944
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        x: usize,
        s: [usize; n],
    }
    let mut s = s;
    s.sort();
    let mut dp: Vec<u64> = vec![0; x + 1];
    for (i, x) in dp.iter_mut().enumerate() {
        *x = i as u64;
    }
    for (i, s) in s.into_iter().enumerate() {
        let i = i as u64;
        let mut next = vec![0; x + 1];
        for (z, (x, y)) in next.iter_mut().zip(dp.iter().take(s).cycle().zip(dp.iter())) {
            *z = *x + *y * i;
        }
        for (t, f) in dp.iter_mut().zip(next.iter()) {
            *t = *f % 1000000007;
        }
    }
    println!("{}", dp[x]);
}

fn main() {
    run();
}


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


int main()
{
    int n,x;cin>>n>>x;
    int l[n+1];
    int i,j,k;
    for(i=1;i<=n;i++) cin>>l[i];
    k=0; int c=1;
    while(1)
    {
        if(k>x || c>n+1){c--; break;}

        k=k+l[c];
        c++;
    }
    cout<<c;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
char str[maxn];
unordered_map<int, int>mi;
int get(int x)
{
    if(mi.count(x))
    {
        return mi[x];   
    }
    return maxn;
}
void add(int x, int val)
{
    if(!mi.count(x))
    {
        mi[x]=val;
    }
    else mi[x]=min(mi[x], val);
}
int main()
{
    scanf("%s", str);
    int i, j;
    int dp=0, mask=0;
    for(i=0; str[i]; i++)
    {
        add(mask, dp);    
        mask^=1<<(str[i]-'a');
        dp=get(mask)+1;
        for(j=0; j<26; j++)
        {
            dp=min(dp, get(mask^(1<<j))+1);
        }
    }
    printf("%d\n", dp);

}


Measured memory_bytes: 8648
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k, a[10] = {}, sum = 0, ans = 0, count = 1, m;
	vector<int> v;
	cin >> n >> k;
	REP(i, k) {
		cin >> sum;
		a[sum]++;
	}
	m = n;
	while (true) {
		n = m;
		while (n > 0) {
			if (a[n % 10] > 0) {
				break;
			}
			else if (n < 10) {
				cout << m;
				return 0;
			}
			n /= 10;
		}
		m++;
	}
}

Measured memory_bytes: 256
num = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]

n = int(input())
for i in range(n):
  b, f, r, v = map(int, input().split())
  num[b-1][f-1][r-1] += v
  
for b in range(4):
  for f in range(3):
    print(" " + " ".join(map(str, num[b][f])))
  if b < 3:
    print("#" * 20)


Measured memory_bytes: 5608
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

int main() {
  long N;
  cin >> N;
  long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i;
  }
  sort(A, A + N);
  long mid = A[N / 2];
  long res = 0;
  for (int i = 0; i < N; i++) {
    res += abs(A[i] - mid);
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
x=int(input())
buy=[0]*10**6
buy[0]=1
def write(n):
  if buy[n-105] or buy[n-104] or buy[n-103] or buy[n-102] or buy[n-101] or buy[n-100]:
    buy[n]=1
for i in range(10**5+1):
  write(i)
print(buy[x])

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

char acgt[] = {'A', 'C', 'G', 'T'};

int main(){
    string s; cin >> s;
    int ans = 0, f = 0;
    int cnt = 0;
    rep(i, s.size()){
        rep(j, 4){
            if(s[i] == acgt[j]){
                f = 1;
                cnt++;
            }
        }
        if(!f) cnt = 0;
        f = 0;
        ans = max(ans, cnt);
    }
    COUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    vector<ll> check(10);
    rep(i, 4) {
        ll a;
        cin >> a;
        check[a]++;
    }

    bool ans = true;
    rep(i, 10) {
        if (i == 1 || i == 4 || i == 7 || i == 9) {
            if (check[i] != 1) {
                ans = false;
            }
        }
    }

    if (ans)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0);
const int N = 200005;
const int MOD = 1e9 + 7;
const int inf = 1<<28;
typedef long long ll;

double a[105];
int main()
{
   
    
    int n;
   	cin>>n;

   	double x, ans = 0;
   	for(int i = 0; i < n; i++)
	{
   		cin>>x;
   		ans += 1.0 / x;
	}

	ans = 1 / ans;
   	cout<<fixed<<setprecision(8)<<ans;

   	
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int rev(int a){
	stringstream ss;string s;int b;
	ss<<a;ss>>s;
	reverse(s.begin(),s.end());
	ss.clear();
	ss<<s;ss>>b;
	return b;
}
int main(void){
	int n;
	cin>>n;
	int i=0;
	do{
		if(rev(n-i)==n-i){
			cout<<n-i<<endl;
			break;
		}else if(rev(n+i)==n+i){
			cout<<n+i<<endl;
			break;
		}
	}while(++i);
	return 0;
}

Measured memory_bytes: 1224
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*First ever A, last ever Z */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		int N = S.length();
		int L = 0;
		int R = 0;
		for (int i = 0; i < N; i++) {
			if (S.charAt(i)=='A') {
				L=i;
				break;
			}
		}
		for (int i = N-1; i>=0; i--) {
			if (S.charAt(i)=='Z') {
				R=i;
				break;
			}
		}
		O.pln(R-L+1);
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 29564
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,c,d,x,y,z,n,m,l,w,sum=100000,sum2=0,ans=0;
    string s,t;
    bool ok=true;
    cin >> a >> b;
    if(a <= 0 && b >= 0 ){
        cout << "Zero" << endl;
        return 0;
    }

    if(a>0 && b>0){
        cout << "Positive" << endl;
        return 0;
    }
    else{
        x = abs(b)-1;
        if((abs(a)-x)%2==0){
            cout << "Positive" << endl;
        }
        else
            cout << "Negative" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class binaryTreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

n = int(input())
root = None
for index in range(n):
    inputL = input().split()
    if inputL[0] == 'insert':
        if index == 0:
            root = binaryTreeNode(int(inputL[1]))
        else:
            def walkNode(node, val, parent):
                if node != None:
                    if node.val > val:
                        walkNode(node.left, val, node)
                    else:
                        walkNode(node.right, val, node)
                else:
                    if parent.val > val:
                        parent.left = binaryTreeNode(val)
                    else:
                        parent.right = binaryTreeNode(val)
            walkNode(root, int(inputL[1]), None)
    else:
        inL = [] 
        def lookNodeIn(node):
            if node != None:
                lookNodeIn(node.left)
                inL.append(node.val)
                lookNodeIn(node.right)
        lookNodeIn(root)
        preL = []
        def lookNodePre(node):
            if node != None:
                preL.append(node.val)
                lookNodePre(node.left)
                lookNodePre(node.right)
        lookNodePre(root)
        print(' '+' '.join(list(map(str, inL))))
        print(' '+' '.join(list(map(str, preL))))


Measured memory_bytes: 147680
#include <stdio.h>
#include <string.h>
#define MAX 1000

int lcs(char *,char *);
char A[MAX+1],B[MAX+1];

int main(){
  int n,i;

  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",A);
    scanf("%s",B);
    printf("%d\n",lcs(A,B));
  }
  return 0;
}

int lcs(char *A,char *B){
  int m,n,i,j;
  int C[MAX+2][MAX+2];

  int max=0;
  
  m=strlen(A);
  n=strlen(B);
  
  for(i=0;i<=m;i++){
    C[i][0]=0;
  }
  for(j=0;j<=n;j++){
    C[0][j]=0;
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(A[i-1]==B[j-1]){
	C[i][j]=C[i-1][j-1]+1;
      }
      else if(C[i-1][j]>=C[i][j-1]){
	C[i][j]=C[i-1][j];
      }
      else C[i][j]=C[i][j-1];
      if(C[i][j]>max) max= C[i][j];

    }
  }
  return C[m][n];
}

Measured memory_bytes: 4528
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define push push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
int main(){
    int n,m;
    bool ans=false;
    cin >>n>>m;
    pair<int,int>fin=mp(n-m,n-m);
    pair<int,int>now=mp(0,0);
    int at=0;
    vector<string>a(n,"");
    vector<string> b(m, "");
    rep(i,n){
        cin>>a[i];
    }
    rep(i, m){
        cin >> b[i];
    }
    while(now.F <=fin.F){
        at=0;
        while (now.S <= fin.S){
            for(int i=0;i<m;i++){
                if(equal(all(b[i]),(a[now.F+i].begin()+now.S))){
                    at++;
                    if(i==m-1){
                        ans=true;
                         //cout<<i<<"  "<<now.F<<" "<<now.S<<endl;
                    }
                }else{
                //    cout<<i<<"  "<<now.F<<" "<<now.S<<endl;
                    break;
                }
            }
            //if(at==m){
            //    ans=true;
            //}
            now.S++;
        }
        now.S=0;
        now.F++;
    }
    cout<<solve(ans)<<endl;
}

Measured memory_bytes: 764
from collections import defaultdict
from heapq import heappop, heappush

h, w = map(int, input().split())
c = []
for i in range(10):#h:高さ
    c.append([int(m) for m in input().split()])
a = []
for i in range(h):#h:高さ
    a.append([int(m) for m in input().split()])
dist = []
for i in range(10):
    for j in range(10):
        dist.append([i, j, c[i][j]])

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
# (src, dst, weight)
inputs = dist

g = Graph()
for src, dst, weight in inputs:
    g.add_edge(src, dst, weight)
    #g.add_edge(dst, src, weight)
spdi = {}
for i in range(10):
    d = Dijkstra(g, i)
    sp = format(d.shortest_distance(1))
    spdi[i] = int(sp)
#print('最短経路: {}'.format(d.shortest_path(1)))
#print('最短距離: {}'.format(d.shortest_distance(1)))

ncdi = {}
ncdi = defaultdict(int)
for i in range(h):
    for j in range(w):
        ncdi[a[i][j]] += 1
count = 0
for i in range(10):
    count += spdi[i] * ncdi[i]
print(count)

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

void cal_score(vector<int> &c, vector<vector<int>> &s, int &score, vector<int> v, vector<int> &mai) {
	int n = v.size() - 1;
	score += s[n][v.back()];
	REP(i, 26)mai[i]++;
	mai[v.back()] = 0;
	REP(i, 26)score -= c[i] * mai[i];
}

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

	ll d;cin >> d;
	vector<int> c(26);REP(i, 26)cin >> c[i];
	vector<vector<int>> s(d, vector<int>(26));
	REP(i, d)REP(j, 26)cin >> s[i][j];

	vector<pair<int, pair<vector<int>, vector<int>>>> lis;
	REP(i, 26){
		vector<int> v(1, i);
		vector<int> mai(26, 0);
		int score = 0;
		cal_score(c, s, score, v, mai);
		lis.EB(score, MP(v, mai));
	}

	REP(i, d-1){
		sort(ALL(lis), greater<pair<int, pair<vector<int>, vector<int>>>>());
		lis.resize(min((int)lis.size(), 230));
		vector<pair<int, pair<vector<int>, vector<int>>>> now;

		for(auto seica: lis){
			REP(i, 26){
				vector<int> v = seica.SE.FI;v.PB(i);
				vector<int> mai = seica.SE.SE;
				int score = seica.FI;
				cal_score(c, s, score, v, mai);
				now.EB(score, MP(v, mai));
			}
		}

		lis = now;
	}

	sort(ALL(lis), greater<pair<int, pair<vector<int>, vector<int>>>>());
	REP(i, d){
		cout << (lis[0].SE.FI[i]+1) << endl;
	}


	return 0;
}


Measured memory_bytes: 23128
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<bool> VB;
typedef std::vector<VB> VBB;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

int attack(int h) {
  if (h == 1) {
    return 1;
  } else {
    int half = attack(h/2);
    return 2 * half + 1;
  }
}

void solve() {
  int h;
  std::cin >> h;
  int total = attack(h);
  cout(total);
}



Measured memory_bytes: 256
#include "stdio.h"

char O[50] = {};
char E[50] = {};

int main() {
	scanf("%s", O);
	scanf("%s", E);
	for (int i = 0; i <= 50; i++) {
		if (O[i] == NULL)break;
		printf("%c", O[i]);
		if (E[i] == NULL)break;
		printf("%c", E[i]);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9)
        {cout<<"hon"<<endl;
    return 0;}
    else if(n==3){cout<<"bon"<<endl;
    return 0;}
    else {cout<<"pon"<<endl;
    return 0;}
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class CAntiDivision {
public:
    void solve(std::istream &in, std::ostream &out) {
        int64_t A, B, C, D;
        in >> A >> B >> C >> D;

        int64_t R = C / __gcd(C, D) * D;

        int64_t res1 = (B - A + 1) - (B / C - (A - 1) / C);
        int64_t res2 = (B - A + 1) - (B / D - (A - 1) / D);
        int64_t res3 = (B - A + 1) - (B / R - (A - 1) / R);
        out << (res1 + res2 - res3);

    }
};


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld n, m;
    cin >> n;
    cin >> m;
    lld s, e;
    lld i, t;
    if (n == 1){
    	s = 0;
    	e = 9;
    }
    if (n == 2){
    	s = 10;
    	e = 99;
    }
    if (n == 3){
    	s = 100;
    	e = 999;
    }
    lld si[m];
    lld dg[m];
    for(i = 0; i <  m; i++){
    	cin >> si[i];
    	cin >> dg[i];
    }
    lld f = 0;
    lld z = 0;
    for(i = s; i <= e; i++){
    	lld A[n];
    	t = i;
    	lld j = n - 1;
    	while (1){
    		A[j]=t%10;
    		j--;
    		t =  t/10;
    		if (t==0){
    			break;
    		}
    	}
    	lld k;
    	lld g = 1;
    	for(k = 0;k<m;k+=1){
    		if (A[si[k]-1] != dg[k]){
    			g = 0;
    			break;
    		}
    	}
    	if (g == 1){
    		f = 1;
    		z = i;
    		break;
    	}
    }
    if (f==1)
    	cout << z << "\n";
    else
    	cout <<"-1"<<"\n";
    return 0;
}

Measured memory_bytes: 256
//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//
 
int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    LL n, k;
    cin >> n >> k;

    unordered_map<LL, LL> next;
    for(int i = 1; i < n+1; ++i){
        next[i] = READ_LONG();
    }

    VI current_loop;
    VI visited(n+1, 0);

    LL cur = 1;
    LL l = 0;
    while(l < k && visited[cur] == 0){
        visited[cur] = 1;
        l++;
        cur = next[cur];

        // cout << cur << ", " << l << endl;
    }

    if(l == k){
        cout << cur << endl;
        return 0;
    }
    visited.assign(n+1, 0);
    int cycle_len = 0;
    int start = cur;
    while(visited[start] != 1){
        visited[start] = 1;
        cycle_len += 1;
        start = next[start];
    }

    // cout << "cycle len = " << cycle_len << ", source: " << start << endl;

    k -= l;
    k %= cycle_len;
    RANGE(i,k){
        cur = next[cur];
    }
    // printf("New k: %lld, source: %d\n", k, start);
    cout << cur;
    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/

Measured memory_bytes: 12272
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = nextIntList().sorted()
    val S = A.last()
    val T = A.bfind(S / 2.0)
    println("$S $T")
}

tailrec fun List<Int>.bfind(v: Double, l: Int = 0, r: Int = this.size): Int {
    if (r - l == 1) {
        if (r == this.size) return this[l]
        return if (Math.abs(this[l] - v) <= Math.abs(this[r] - v)) this[l] else this[r]
    }
    val m = (l + r) / 2
    val vm = this[m]
    return when {
        vm < v -> bfind(v, m, r)
        vm > v -> bfind(v, l, m)
        else -> vm
    }
}

Measured memory_bytes: 58708
public class Hello{
    public static void Main(){

        int N = int.Parse(System.Console.ReadLine());
        string[] str = System.Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = int.Parse(str[i]);
        }
        
        System.Array.Sort(a);
        
        int Alice = 0;
        int Bob = 0;
        for(int i = N - 1; i >= 0; i -= 2){
            Alice += a[i];
        }
        for(int i = N - 2; i >= 0; i -= 2){
            Bob += a[i];
        }
        System.Console.WriteLine(Alice - Bob);
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
int d,len;ll pw10[20],ad[20],ans;
void init(){
	pw10[0]=1;
	rep (i,1,18) pw10[i]=pw10[i-1]*10;
	rep (i,0,9) rep (j,0,9) ad[i-j+10]++;
}
void dfs(int k,ll now,ll ret){
	if (k>=len/2){
		if (len&1) ret*=10;
		if (now==d) ans+=ret;
		return;
	}
	int i=-9;
	while (i<=9&&now+i*(pw10[len-k-1]-pw10[k])<=d) i++;
//	if (len==2) cerr<<i<<'\n';
	i--;
	dfs(k+1,now+i*(pw10[len-k-1]-pw10[k]),ret*(ad[i+10]-(!k&&i>=0)));
	i++;
	if (i<=9) dfs(k+1,now+i*(pw10[len-k-1]-pw10[k]),ret*(ad[i+10]-(!k&&i>=0)));
}
int main(){
	init();
	cin>>d;
	for (len=1;len<=19;len++) dfs(0,0,1);
	cout<<ans<<'\n';
	return 0;
}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

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

    ll min_v = 1e9 * 2 * n;
    for (ll i = 0, x = 0; i < n - 1; ++i) {
        x += a[i];
        if (abs(sum - 2 * x) < min_v) min_v = abs(sum - 2 * x);
    }

    cout << min_v << endl;

    return 0;
}


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

char F[102][102];
void DFS(int x,int y,char z){
    if(F[x][y]!=z)
        return;

    F[x][y]='.';

    DFS(x-1,y,z);
    DFS(x,y+1,z);
    DFS(x+1,y,z);
    DFS(x,y-1,z);
}

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0||W==0){
            break;
        }
        for(int x=1;x<=H;x++){
            for(int y=1;y<=W;y++){
                cin>>F[x][y];
            }
        }

        int cnt=0;
        for(int x=1;x<=H;x++){
          for(int y=1;y<=W;y++){
             if(F[x][y]=='#'){
                    cnt++;
                    DFS(x,y,'#');
             }
                if(F[x][y]=='@'){
                    cnt++;
                    DFS(x,y,'@');
                }
                if(F[x][y]=='*'){
                    cnt++;
                    DFS(x,y,'*');
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3380
n = int(raw_input())
stable = 1

class Card():
    __slots__ = ('suit', 'value')

#mergeSort
A = [Card() for _ in xrange(n)]
#quickSort
B = [Card() for _ in xrange(n)]

for i in xrange(n):
    a = raw_input().split()
    A[i].suit = a[0]
    B[i].suit = a[0]
    A[i].value = int(a[1])
    B[i].value = int(a[1])

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1) 
    R = [0] * (n2+1)
    L[:n1] = A[left:mid]
    R[:n2] = A[mid:right]
    #for i in xrange(n1):
    #    L[i] = A[left + i]
    #for i in xrange(n2):
    #    R[i] = A[mid + i]
    L[n1] = Card()
    R[n2] = Card()
    L[n1].value = float('inf')
    R[n2].value = float('inf')
    i = 0
    j = 0
    for k in xrange(left,right):
        if L[i].value <= R[j].value:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return 0

def mergeSort(A, left, right):
    if right - left > 1:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    return 0

def partition(A, p, r):
    x = A[r].value
    i = p-1
    for j in xrange(p,r):
        if A[j].value <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i+1]
    A[i+1] = A[r]
    A[r] = tmp
    return i+1

def quickSort(A,p,r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q, r)
    return 0

mergeSort(A, 0, n)
quickSort(B, 0, n-1)

for i in xrange(n):
    if A[i].suit != B[i].suit:
        stable = 0

if stable == 1:
    print 'Stable'
else:
    print 'Not stable'

for i in xrange(n):
    print B[i].suit, B[i].value

Measured memory_bytes: 85452