akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int ans[N];
void sol(int n)
{
	if(n==1){ans[n]=1;return;}
	bool win=false;
	if(!ans[n-1])sol(n-1);
	if(ans[n-1]==2)win=true;
	if(n>2){
		if(!ans[n-2])sol(n-2);
		if(ans[n-2]==2)win=true;
	}if(win)ans[n]=1;
	else ans[n]=2;
}
vector<int>V[N];
int mx=0;
int dfs(int idx,int par)
{
	int fi=0,se=0;
	for(auto k:V[idx]){
		if(k==par)continue;
		int u=dfs(k,idx);
		if(u>=fi)se=fi,fi=u;
		else if(u>se)se=u;
	}
	mx=max(mx,fi+se+1);
	return fi+1;
}
int main()
{
	int n;scanf("%d",&n);
	sol(n);
	for(int i=0;i<n-1;i++){
		int u,v;scanf("%d%d",&u,&v);
		V[u].push_back(v);
		V[v].push_back(u);
	}dfs(1,-1);
//	for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
//	cout<<endl;
//	cout<<mx<<'\n';
	if(ans[mx]==1)cout<<"First\n";
	else cout<<"Second\n";
}


Measured memory_bytes: 23936
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

int inf = std::numeric_limits<int>().max();

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define ll long long
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

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

	vector<vector<int>> m(n+1, vector<int>(n+1, 0)); 
	for(int i=0; i<n; i++) {
		string s;
		cin >> s;
		for(int j=0; j<n; j++) {
			if (s[j] == '1') m[i+1][j+1] = 1;
		}
	}

	/*for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cout << m[i][j] << " ";
		}
		cout << endl;
	}*/

	bool vf = true;
	int pk = -1;
	for(int j=1; j<=n and vf; j++) {
		vector<int> v(n+1, 0);
		queue<int> fila;
		fila.push(j);
		v[j] = 1;
		while (!fila.empty()) {
			int u = fila.front();
			fila.pop();
			for(int i=1; i<=n; i++) {
				if (i!=u and m[u][i] == 1) {
					if (!v[i]) {
						v[i] = v[u]+1;
						fila.push(i);
					} else if ((v[i] + v[u]) % 2 == 0) vf = false;
				}
			}
		}
		if (vf) {
			for(int i=1; i<=n; i++) {
				pk = max(v[i], pk);
			}
		}
	}

	cout << pk << endl;

}


Measured memory_bytes: 384
<?php
fscanf(STDIN,'%d%d%d',$N,$M,$X);
$A=explode(" ",trim(fgets(STDIN)));
$cost1=0;
$cost2=0;
for ($i=0; $i <=$M-1 ; $i++) {
  // code...
  if($A[$i]<$X){
    $cost1++;
  }else{
    $cost2++;
  }
}
echo min($cost1,$cost2);
 ?>


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

int main() {
  int n;
  cin >> n;
  vector<bool> a(8, false);
  int cnt = 0;
  rep(i, n) {
    int x;
    cin >> x;
    if (x<400) a[0] = true;
    else if (x<800) a[1] = true;
    else if (x<1200) a[2] = true;
    else if (x<1600) a[3] = true;
    else if (x<2000) a[4] = true;
    else if (x<2400) a[5] = true;
    else if (x<2800) a[6] = true;
    else if (x<3200) a[7] = true;
    else cnt++;
  }

  int ans = 0;
  rep(i, 8) {
    if (a[i]) ans++;
  }
  cout << max(1, ans) << " " << ans + cnt << endl;
}


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

int main() {
  string a;
  cin >> a;

  if (a[0]==a[1]&&a[1]==a[2]) cout << "Yes" << endl;
  else if(a[1]==a[2]&&a[2]==a[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

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

  int A[3][3] ;
  bool B[3][3] ;
  rep(i,3) rep(j,3) cin >> A[i][j] ;
  rep(i,3) rep(j,3) B[i][j] = false ;
  int N ;
  cin >> N ;
  rep(i,N){
    int M ;
    cin >> M ;
    rep(i,3)rep(j,3) if( A[i][j] == M ) B[i][j] = true ;
  }
  int ans = 0 ;
  rep(i,3){
    rep(j,3) if(B[i][j] == true )ans++ ;
    if(ans == 3 ){
	  cout << "Yes" << endl;
      return 0 ;
    }
    ans  = 0 ;  
  }
  rep(j,3){
    rep(i,3) if(B[i][j] == true )ans++ ;
    if(ans == 3 ){
	  cout << "Yes" << endl;
      return 0 ;
    }
    ans  = 0 ; 
  }
  if(B[0][0] == true && B[1][1]  == true &&B[2][2]  == true){
	cout << "Yes" << endl;
      return 0 ;
    }
  if(B[0][2] == true && B[1][1]  == true &&B[0][2]  == true){
	cout << "Yes" << endl;
      return 0 ;
    }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import deque

H, W = map(int, input().split())
maze = [ ['.' for _ in range(W)] for _ in range(H) ]
num_white = 0

for y in range(H):
    X = list(input().rstrip())
    for x in range(W):
        maze[y][x] = X[x]
        if X[x] == '.':
            num_white += 1

#print(maze)
# print(num_white)

# 1) まずゴールへの最短距離を求める
# 2) 全体の白ますの数 - 1) が答え

distance = [ [-1 for _ in range(W)] for _ in range(H) ]
#print(distance)

def bfs(x, y):
    distance[y][x] = 0
    q = deque([(x, y)])

    while q:
        (x, y) = q.popleft()

        if y > 0 and maze[y-1][x] != '#' and distance[y-1][x] == -1:
            distance[y-1][x] = distance[y][x] + 1
            q.append( (x, y-1) )
        if y < H-1 and maze[y+1][x] != '#' and distance[y+1][x] == -1:
            distance[y+1][x] = distance[y][x] + 1
            q.append( (x, y+1) )
        if x > 0 and maze[y][x-1] != '#' and distance[y][x-1] == -1:
            distance[y][x-1] = distance[y][x] + 1
            q.append( (x-1, y) )
        if x < W-1 and maze[y][x+1] != '#' and distance[y][x+1] == -1:
            distance[y][x+1] = distance[y][x] + 1
            q.append( (x+1, y) )

bfs(0, 0)
nearest = distance[H-1][W-1]

# 到達できない
if nearest == -1:
    print(-1)
else:
    # -1 はスタート地点の分
    print (num_white - nearest - 1)


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

int main(){
    int N,C;

    cin >> N >> C;

    int p[C];
    int H=0;

    for(int i=0;i<C;i++){
        cin >> p[i];
        H=H+p[i];
    }

    if(H%(N+1)==0){
        cout << H/(N+1)<< endl;
    }else{
        cout << H/(N+1)+1 << endl;
    }

    return 0;

    }




Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<long long> S(N + 1, 0);
  for (int i = 0; i < N; i++){
    S[i + 1] = S[i] + a[i];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, INF));
  for (int i = 0; i < N; i++){
    dp[i][i + 1] = 0;
  }
  for (int d = 2; d <= N; d++){
    for (int i = 0; i <= N - d; i++){
      int j = i + d;
      for (int k = i + 1; k < j; k++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + S[j] - S[i]);
      }
    }
  }
  cout << dp[0][N] << endl;
}

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

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

    priority_queue<tuple<int, int>> pq;

    for(int i = 0; i < n; i++){
        int a; cin >> a;
        pq.emplace(a, 1);
    }
    
    for(int i = 0; i < m; i++){
        int b, c;
        cin >> b >> c;
        pq.emplace(c, b);
    }

    vector<int> v;
    bool f = true;
    while(f){
        tuple<int, int> t;
        t = pq.top(); pq.pop();
        int num = get<0>(t);
        int loop = get<1>(t);
        while(f && loop){
            v.emplace_back(num);
            loop--;
            if((int)v.size() == n) f = false;
        }
    }
    cout << accumulate(v.begin(), v.end(), 0LL) << endl;
}


Measured memory_bytes: 2672
n=int(input())
s=input()
l=[0]*n
east=0#右を向いてる人の数
for i in range(n):
    if s[i]=='E':
        east+=1
    l[i]=east
#print(l)
ans=3*10**5
for i in range(n-1,-1,-1):
    if i==n-1:
        R=0
    else:
        R=l[-1]-l[i]
    if i==0:
        L=0
    else:
        L=i-l[i-1]
    ans=min(ans,R+L)
print(ans)

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

int main(){
    int n,m;
    int tmp;
    int ans;
    int p[1000];
    std::cin >> n;
    std::cin >> m;

    while(n!=0 && m!=0){
        ans =-1;
        for(int i=0;i<n;i++){
            std::cin >> tmp;
            p[i] = tmp;
        }
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                if(p[i] + p[j] <= m){
                    if(p[i] + p[j] > ans){
                        ans = p[i] + p[j];
                    }
                }
            }
        }
        if(ans==-1){
            std::cout << "NONE\n";
        }else{
            std::cout << ans <<"\n";
        }
        std::cin >> n;
        std::cin >> m;
    }
    return 0;
}


Measured memory_bytes: 3100
ans :: [String] -> Int
ans (a:"=":_) = read a :: Int
ans (a:"+":b:xs) =
  let a' = read a :: Int
      b' = read b :: Int
  in
    ans ((show (a'+b')):xs)

ans (a:"-":b:xs) =
  let a' = read a :: Int
      b' = read b :: Int
  in
    ans ((show (a'-b')):xs)

ans (a:"*":b:xs) =
  let a' = read a :: Int
      b' = read b :: Int
  in
    ans ((show (a'*b')):xs)

ans (a:"/":b:xs) =
  let a' = read a :: Int
      b' = read b :: Int
  in
    ans ((show (a' `div` b')):xs)

main = do
  c <- getContents
  let i = lines c
      o = ans i
  print o

Measured memory_bytes: 4148
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	sl := make([]int, n)
	for i, _ := range sl {
		fmt.Scan(&sl[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(sl)))
	var cnt int
	for i, _ := range sl {
		if i == 0 || sl[i] != sl[i-1] {
			cnt++
		}
	}

	fmt.Println(cnt)
}


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

int H, W;
char s[55][55];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
        scanf("%s", &s[i]);
	}
    bool ans = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                bool found = false;
                for (int k = 0; k < 4; k++) {
                    int i2 = i + dx[k];
                    int j2 = j + dy[k];
                    if (i2 >= 0 && i2 < H &&
                        j2 >= 0 && j2 < W && s[i2][j2] == '#') {
                        found = true;
                    }
                }
                if (!found) ans = false;
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n,a,b,h[100000],i,l;
long long x,m,r;
main(){
  for(scanf("%d%d%d",&n,&a,&b),a-=b;i<n;l=1,r=1e9)scanf("%d",h+i++);
  while(l<r){
    m=(l+r)/2;
    for(x=i=0;i<n;++i)h[i]>m*b?x+=(h[i]-m*b+a-1)/a:0;
    x<=m?r=m:l=m+1;
  }
  printf("%d\n",l);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

char s[200000];
ll cnt[5];

signed main(){
string dir="MARCH";
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%s",s);
		rep(j,5){
			if(dir[j]==s[0]){
				cnt[j]++;
			}
		}
	}
	ll ans=0;
	rep(i,5){
		for(int j=i+1;j<5;j++){
			for(int k=j+1;k<5;k++){
				ans+=cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

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

const WIDTH = 502
const HEIGHT = 502

/*
var nrs = bufio.NewReaderSize(os.Stdin, 1000000)

func readLineToInt() []int {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := nrs.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    line := strings.Split(string(buf), " ")
    var intLine []int
    for _, str := range line {
        n, _ := strconv.Atoi(str)
        intLine = append(intLine, n)
    }
    return intLine
}
*/
var sc = bufio.NewScanner(os.Stdin)
func main() {
    var n, m, q int
    var l, r int
    var a, b int
    var mp [HEIGHT][WIDTH]int
    //nmq := readLineToInt()
    //_, m, q := nmq[0], nmq[1], nmq[2]
    sc.Scan()
    fmt.Sscanf(sc.Text(), "%d %d %d", &n, &m, &q)

    for i := 0; i < m; i++ {
        //lr := readLineToInt()
        //l, r := lr[0], lr[1]
        sc.Scan()
        fmt.Sscanf(sc.Text(), "%d %d", &l, &r)
        mp[l][r] += 1
    }

    for x := 0; x < WIDTH - 1; x++ {
        mp[0][x] += mp[0][x + 1]
    }

    for y := 1; y < HEIGHT; y++ {
        for x := 0; x < WIDTH - 1; x++ {
            mp[y][x + 1] += mp[y][x]
            mp[y][x] += mp[y - 1][x]
        }
    }

    for i := 0; i < q; i++ {
        //ab := readLineToInt()
        //a, b := ab[0], ab[1]
        sc.Scan()
        fmt.Sscanf(sc.Text(), "%d %d", &a, &b)
        fmt.Println(mp[b][b] - mp[b][a - 1] - mp[a - 1][b] + mp[a - 1][a - 1])
    }
}

Measured memory_bytes: 8192
N = int(input())
lst = [list(map(int,input().split())) for _ in range(N)]

for x,y,h in lst:
    if h != 0:
        break

for cx in range(101):
    for cy in range(101):
        H = abs(cx-x) + abs(cy-y) + h
        if all(hi == max(H-abs(cx-xi)-abs(cy-yi),0) for xi,yi,hi in lst):
            print(cx,cy,H)
            exit()


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

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    int m = x * 2, M = x * 4;
    if (m <= y && y <= M && !(y & 1))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n,a,b;
  cin>>n>>a>>b;

  cout<<min(n*a,b)<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
ll a[2000000];
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll a=n%100;
    ll b=n/100;
    if((a<=12&&a!=0)&&(b<=12&&b!=0))
    {
        cout<<"AMBIGUOUS";
    }
    else if(a<=12&&a!=0)
    {
        cout<<"YYMM";
    }
    else if(b<=12&&b!=0)
    {
        cout<<"MMYY";
    }
    else
        cout<<"NA";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int n; cin >> n;
    int t[50], u[50];
    rep(i, n) {
        int x; cin >> x;
        t[i]=x;
        u[i]=x;
    }
    sort(t, t+n);
    int diff =0;
    rep(i, n){
        if(t[i] != u[i]) diff++;
    }
    if(diff<=2) cout << "YES"<< endl;
    else cout << "NO" <<endl;
}

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

#define ll long long

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
   vector<ll>dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
  
  for(int i=2;i<n;i++)
  {
      //int val=INT_MAX;
	for(int j=1;j<=k;j++)
    {
      if(i>=j)
			dp[i]=min(dp[i-j] + abs(a[i-j]-a[i]),dp[i]);  
     }
     //dp[i]=val;
   }

        cout<<dp[n-1];
    return 0;
}
                  

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
typedef long long ll;

int main()
{
	ll a,b,i,j;
	sl(a);sl(b);
	ll t = b-a;
	ll sum = 0;
	for(i = 1;i < t;i++)
	sum += i;
	pl(sum-a);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
	int n, k, x, sum = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x;
		sum += x < k - x ? x : k - x;
	}
	cout << sum * 2 << endl;
	return 0;
}



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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N;
    int a, b;
    cin >> N;
    vint P(N), Q(N);
    vint v(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    for (int i = 0; i < N; i++) v[i] = i + 1;

    int cnt = 0;
    do {
        if (P == v) a = cnt;
        if (Q == v) b = cnt;
        cnt++;
    } while (next_permutation(begin(v), end(v)));

    cout << abs(a - b) << endl;

    return (0);
}


Measured memory_bytes: 256
sub i{$t=<STDIN>;$t=~s/[¥r¥n]+//;return split/ /,$t;}@c=i;for($j=0;$j<$c[2];$j++){@d=i;if($d[1]<=$d[0]){${$s[$d[1]]}[@{$s[$d[1]]}]=$d[0];}}$e=$c[0]+1;$f=1;for($j=1;$j<=$c[1];$j++){foreach $g(sort{$a<=>$b}@{$s[$j]}){if($f==$g){$f++;}elsif($f<$g&&$e>$g){$e=$g;}}$f++;}$e--;print "$e";

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

int main() {
  ll n, m, b, c, ans = 0;
  cin >> n >> m;

  map<ll, ll> p;
  vector<ll> a(n + m + 5);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[a[i]]++;
  }

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

  sort(a.rbegin(), a.rend());

  int cnt = 0, i = 0;

  for (int i = 0; i < n; i++) {
    if (cnt + p[a[i]] < n) {
      ans += a[i] * p[a[i]];
      cnt += p[a[i]];
      p[a[i]] = 0;
    } else if (cnt + p[a[i]] >= n) {
      ans += a[i] * (n - cnt);
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 14336
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    s, t = input().split()
    a, b = LI()
    u = input()
    if u == s:
        print("{} {}".format(a - 1, b))
    elif u == t:
        print("{} {}".format(a, b - 1))
    return


# B
def B():
    s = input()
    print('x' * len(s))
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 38384
s = list(input())
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

def p_mark(j):
    if j % 2 == 0:
        return '+'
    else:
        return '-'

for i in range(2 ** 3):
    j = i
    p = a
    x = p_mark(j)
    if x == '+':
        p += b
    else:
        p -= b
    j = j // 2
    y = p_mark(j)
    if y == '+':
        p += c
    else:
        p -= c
    j = j // 2
    z = p_mark(j)
    if z == '+':
        p += d
    else:
        p -= d
    if p == 7:
        print(str(a) + x + str(b) + y + str(c) + z + str(d) + '=7')
        break

Measured memory_bytes: 9188
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <functional>
#include <cmath>
#define SIZE 200005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll inv[SIZE],fac[SIZE],finv[SIZE];
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main()
{
	make();
	int W,H,A,B;
	scanf("%d %d %d %d",&H,&W,&A,&B);W--,H--;
	ll ret=C(W+H,W);
	for(int i=0;i<B;i++)
	{
		ll all=C((H-A)+i,i);
		ll all2=C((W-i)+(A-1),A-1);
		ret-=all*all2%MOD;
		if(ret<0) ret+=MOD;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 4864
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;


int main(){
    ll n,m,x; cin>>n>>m>>x;
    vector<ll>c(n);
    vector<vector<ll>>a(n,vector<ll>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }
   ll cost=0;
   ll ans=mod;
    for(ll tmp=0;tmp<(1<<n);tmp++){
         vector<ll>xx(m,0);
         cost=0;
        bitset<15>b(tmp);
        bool jud=true;
        for(int i=0;i<n;i++){
            if(b.test(i)){
                cost+=c[i];
                rep(j,m){
                    xx[j]+=a[i][j];
                }
            }
        }
        rep(i,m){
            if(xx[i]<x){
                jud=false;
            }
        }
        if(jud){
        ans=min(ans,cost);
        }
    }
    if(ans==mod)cout<<-1<<endl;
    else cout<<ans<<endl;
}








Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1000000007;//1e9 + 7;




int main(){
	string s;
	int f;
	cin>>f>>s;
	int n=0;
	rep(i,s.size()-2){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')n++;
	}
	cout<<n<<endl;
	
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#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 FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
char s[200001], t[200001];
int nums[200001] = { 0 };
int numt[200001] = { 0 };

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	scanf("%s %s", s,t);

	int f[26][27] = { 0 };
	int len = strlen(s);
	int cnts[26] = { 0 }, cntt[26] = { 0 };
	REP(i, len) {
		cnts[s[i] - 'a']++;
		cntt[t[i] - 'a']++;
	}
	REP(i, 26) {
		nums[cnts[i]]++;
		numt[cntt[i]]++;
	}
	REP(i, 200001) {
		if (nums[i] != numt[i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
    int n, i, a;
    int min =  1000000;
    int max = -1000000;
    long long sum = 0;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        scanf("%d", &a);
        sum = sum + a;
        if ( min > a )
        {
            min = a;
        }
        if ( max < a )
        {
            max = a;
        }
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt();
		int[] x=new int[n+1];
		int sum = 0;
		for(int i=0;i<n;i++){
			x[sc.nextInt()]++;
		}
		Arrays.sort(x);
		for(int i=n-k;i>=0;i--){
			sum+=x[i];
		}
		System.out.print(sum);
	}
}


Measured memory_bytes: 84424
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;
  std::vector<i64> H;
  tools::read(H, N);

  std::vector<i64> rivals(N, std::numeric_limits<i64>::min());
  for (i64 i = 0; i < M; ++i) {
    i64 A_i, B_i;
    std::cin >> A_i >> B_i;
    --A_i;
    --B_i;
    rivals[A_i] = std::max(rivals[A_i], H[B_i]);
    rivals[B_i] = std::max(rivals[B_i], H[A_i]);
  }

  i64 answer = 0;
  for (i64 i = 0; i < N; ++i) {
    if (H[i] > rivals[i]) {
      ++answer;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 4724
K =  gets.chomp().to_i
N = 50
n = (K / N).to_i
m = K % N
a = Array.new(N){|i| i+n }
puts(N)
(0...m).each{|i|
    (0...N).each{|j|
        if j == i
            a[j] += N
        else
            a[j] -= 1
        end
    }
}
puts(a.join(' '))

Measured memory_bytes: 1788
/*
20/7/27
無理、どうやってAを全探索するのか
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int best_score=0;
vector<int> a(60),b(60),c(60),d(60);
int N,M,Q;

void dfs(int A_num, int l_limit, vector<int> &A){
    if(A_num>N) return;
    for(int i=l_limit;i<=M;i++){
        A[A_num-1]=i;
        if(A_num==N){
            int score=0;
            for(int i=0;i<Q;i++){
                if((A[b[i]]-A[a[i]])==c[i]) score+=d[i];
            }
            //for(int i:A) cout << i << " ";
            //cout << endl;
            //cout << score << endl;
            best_score=max(best_score,score);
        }
        dfs(A_num+1,i,A);
    }
}

int main(){
    cin >> N >> M >> Q;
    a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
    for(int i=0;i<Q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> A(N,0);
    dfs(1,1,A);
    cout << best_score << endl;
}

Measured memory_bytes: 3600
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
answer = -float('inf')
for s in range(N):
    S = []
    i = P[s]-1
    S.append(C[i])
    while i!= s:
        i = P[i]-1
        S.append(S[-1]+C[i])
        
    if K<=len(S):
        score = max(S[:K])
    elif S[-1]<=0:
        score = max(S)
    else:
        score1 = S[-1]*(K//len(S))
        amari = K%len(S)
        if amari!=0:
            score1 += max(0,max(S[:amari]))
        score2 = S[-1]*(K//len(S)-1)
        score2 += max(S)
        score = max(score1,score2)
    
    answer = max(answer,score)
print(answer)

Measured memory_bytes: 80620
i = list(map(str, input().split()))
poor = False
if i[0] == i[1] and i[0] != i[2]:
    poor = True
if i[0] == i[2] and i[0] != i[1]:
    poor = True
if i[1] == i[2] and i[0] != i[1]:
    poor = True
if poor:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n = int(input())
k = int(input())
x = int(input())
y = int(input())

ans = []
if n>k:
    for i in range(k):
        ans.append(x)

    for i in range(n-k):
        ans.append(y)
else:
    for i in range(n):
        ans.append(x)
print(sum(ans))


Measured memory_bytes: 9180
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 998244353;
//}}}

int main(){
  int n, m, d;
  cin >> n >> m >> d;
  double p;
  if (d == 0) {
    p = 1.0 / n;
  } else if (d + 1 > n - d) {
    p = 1.0 / n;
  } else {
    p = 1.0 * 2 * d + 2.0 * (n - 2 * d);
    p /= n;
    p /= n;
  }

  double ans = p * (m - 1);
  printf("%0.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp
Q = gets.to_i
left = []
right = []
reversed = false
Q.times {
  t,f,c = gets.split
  if t == "1"
    reversed = !reversed
  else
    leftee = f == "1"
    if (leftee && !reversed) || (!leftee && reversed)
      left << c
    else
      right << c
    end
  end
}
if reversed
  s.reverse!
  left,right = [right,left]
end
$stderr.puts [left.size, s.size, right.size]
puts [left.reverse,s,right] * ""


Measured memory_bytes: 18172
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000;
const int MAX = 10000000;

int n;
bool use[4];
int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        char s;
        cin >> s;
        if (s == 'P') use[0] = true;
        else if (s == 'W') use[1] = true;
        else if (s == 'G') use[2] = true;
        else if (s == 'Y') use[3] = true;

    }

    if (use[0] && use[1] && use[2] && use[3]) cout << "Four" << endl;
    else cout << "Three" << endl;

}

Measured memory_bytes: 256
/*input
5
2 4 4 0 2
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

bool cov[100001];

void solve(){
	 int n;cin >> n;
	 // g = (n-i-1)-(i-1) = n-i-i+1 -> .-2*i+n -> 2
	 RE(i,n){
	 	cov[i] = 0;
	 }
	 REP(i,n){
	 	int j;cin >> j;
	 	int ind = (n-j+1)/2;
//	 	cout << ind << " ";
	 	if(!cov[ind])cov[ind] = 1;
	 	else if(!cov[(n-ind)+1] && j)cov[(n-ind)+1] = 1;
	 }
	 
	 RE(i,n){
	 	if(!cov[i]){cout << 0;return;}
	 }
	 cout << fast_ex(2,n/2,MOD);
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define int128 __int128_t
#define Android ios::sync_with_stdio(false), cin.tie(NULL)
#define redirect_input freopen("./input.txt", "r", stdin);
#define redirect_output freopen("./output.txt", "w", stdout);
#define debug(s, r) std::cerr << #s << ": " << (s) << (r==0?' ':'\n')
#define pii pair<int, int>  
#define sqr(x) ((x)*(x))

using namespace std;

const int maxn = 1e6 + 1000;

char val[2][maxn];

bool isSubmask(ll ori, ll test){
    return (ori & test) == test;
}

void solve(){
    int n; cin >> n;
    cin >> val[0];
    for(int i=0; i<n; i++) val[0][i] -= 0;
    if(n == 1) {
        cout << (int)val[0][0] << '\n';
        return;
    }
    n--;
    for(int i=0; i<n; i++) val[1][i] = abs(val[0][i] - val[0][i+1]);
    char * arr = val[1];
    if(n == 1){
        cout << (int)arr[0] << endl;
        return;
    }
    bool one_exist = false;
    int parity_1 = 0, parity_2 = 0;
    for(int i=0; i<n; i++){
        if(arr[i] == 1){
            parity_1 = (parity_1 + isSubmask(n - 1, i)) % 2;
            one_exist = true;
        }
        if(arr[i] == 2){
            parity_2 = (parity_2 + isSubmask(n - 1, i)) % 2;
        }
    }
    int ans = 1;
    if(parity_1 == 0){
        if(!one_exist && parity_2 == 1) ans = 2;
        else ans = 0;
    }
    cout << ans << '\n';
}

signed main(){
    Android;
    solve();
}


Measured memory_bytes: 2176
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
  int N,Y,i,j,k;
  scanf("%d %d",&N,&Y);
  for(i=0;i<=N;i++){
    for(j=0;j+i<=N;j++){
      k = N - i - j;
      if(10000*i+5000*j+1000*k == Y){
        printf("%d %d %d\n",i,j,k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

int main() {
  int A, B, C;
  int K;
  scanf("%d %d %d %d", &A, &B, &C, &K);

  int res = A + B + C - std::max({A, B, C});
  res += std::max({A, B, C}) << K;
  printf("%d\n", res);
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
diff = float('Inf')
point = 0
for i in range(N):
    newdiff = abs(T - H[i]*0.006 - A)
    if diff > newdiff:
        diff = newdiff
        point = i + 1
print(point)

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

class Dice{
private:
  int front,back,right,left,top,bottom;
public:
  Dice(int f, int bk, int r, int l, int t, int bt){
    front = f; back = bk;
    right = r; left = l;
    top = t; bottom = bt;
  }
  void turnR(){
    int tmp = top;
    top = left; left = bottom;
    bottom = right; right = tmp;
  }
  void turnL(){
    int tmp = top;
    top = right; right = bottom;
    bottom = left; left = tmp;
  }
  void turnF(){
    int tmp = top;
    top = back; back = bottom;
    bottom = front; front = tmp;
  }
  void turnBk(){
    int tmp = top;
    top = front; front = bottom;
    bottom = back; back = tmp;
  }
  void spinR(){
    int tmp = front;
    front = right; right = back;
    back = left; left = tmp;
  }
  void spinL(){
    int tmp = front;
    front = left; left = back;
    back = right; right = tmp;
  }
  int getF(){ return front;}
  int getBk(){ return back;}
  int getR(){ return right;}
  int getL(){ return left;}
  int getT(){ return top;}
  int getBt(){ return bottom;}  
  void print(){
    cout << "T:" << top << " F:" << front << " R:" << right <<
      " Bk:" << back << " L:" << left << " Bt:" << bottom << endl;
  }
};
//------------------------------------------------------

int main(void){
  Dice *d;
  int t,f,r,l,bk,bt;
  int n;
  
  cin >> t >> f >> r >> l >> bk >> bt;
  d = new Dice(f,bk,r,l,t,bt);
//  d->print();
  cin >> n;
  for (int i=0; i<n; i++){
    int qf, qt; cin >> qt >> qf;
    if (d->getR() == qt) d->turnL();
    else if (d->getL() == qt) d->turnR();
    while (d->getT() != qt) d->turnBk();
    while (d->getF() != qf) d->spinR();
//    d->print();
    cout << d->getR() << endl;
  }
  return 0;
}




Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<queue>
using namespace std;



int main(){
  int n; cin>>n;
  int a[112];
  for(int i=0;i<n;i++)
  cin>>a[i];

  double sum=0;
  for(int i=0;i<n;i++)
  sum+= 1.0/a[i];

  cout<<setprecision(10)<<1/sum<<endl;
}


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

void solve() {
  int a, b, k; cin >> a >> b >> k;
  for(int i=0; i<k; ++i) {
    if(i & 1) {
      a += b >>= 1;
    } else {
      b += a >>= 1;
    }
  }
  cout << a << ' ' << b << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


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

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){

    unsigned long N, K;
    cin >> N >> K;

    vector<unsigned long> H(N);
    unsigned long i;
    for(i=0; i<N; i++) cin >> H.at(i);

    sort(H.begin(), H.end(), greater<unsigned long>());


    for(i=0; K>0; i++, K--){

        if(i >= H.size()){
            cout << 0 << endl;
            return 0;
        }
        H.at(i) = 0;
    }

    //for(i=0; i<N; i++) cout << H.at(i) << " ";
    //cout << endl;

    unsigned long ans = accumulate(H.begin(), H.end(), 0UL);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 2424
#include <stdio.h>
#define max 1000
int n;
 int m[max][max],p[max];


int main(){
  int c,r;
  int i,k;
 
  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  printf("%d\n", optimalParenthesization());
}

int optimalParenthesization(){
  int l,i,j;
  for(i=1;i<n+1;i++) m[i][i]=0;
  for(l=2;l<n+1;l++){  
    for(i=1;i<n+1;i++){
       j = i + l -1;
       
      m[i][j] = min(i,j);
    }
  }
 
  return m[1][n];
}
int min(int i,int j){
  int min,k;
  for(k=i; k<=j; k++){
    m[i][j] = m[i][k] + m[k+1][j] +p[i-1]*p[k]*p[j];
    
    if(k==i) min = m[i][j];
    if(k>i && m[i][j] < min) min = m[i][j];
  }
  // printf("i = %d,j = %d,%d\n",i,j,min);
  return min;
}



Measured memory_bytes: 2188
def main():
    n, m = list(map(int, input().split()))
    mod = 1000000007
    def factorial(num, mod):
        ans = 1
        if num <= 1: return ans
        for i in range(2, num + 1):
            ans = (ans * i) % mod
        return ans

    if abs(n - m) >= 2:
        print(0)
    elif abs(n - m) == 1:
        print(factorial(n, mod) * factorial(m, mod) % mod)
    else:
        print(2 * factorial(n, mod) * factorial(m, mod) % mod)




if __name__ == '__main__':
    main()


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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> D(N);
    for(int i = 0; i < N; ++i) {
        cin >> D[i];
    }
    sort(D.rbegin(), D.rend());
    double ans = (double)C / A;
    int total = C;
    for(int i = 1; i <= N; ++i) {
        total += D[i - 1];
        ans = max(ans, (double)total / (i * B + A));
    }
    cout << (int)ans << endl;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
const int N = 100005;
int n, a[N], c[2*N], s[N];
int query(int x){
    int ans = 0;
    for(int i = x; i; i -= lowbit(i)) ans += c[i];
    return ans;
}
void add(int x){
    for(int i = x; i < 2*N; i += lowbit(i)) c[i] += 1;
}
bool check(int x){
    for(int i = 1; i < 2*N; ++i) c[i] = 0;
    for(int i = 1; i <= n; ++i){
        s[i] = s[i-1] + (a[i] >= x ? 1 : -1);
    }
    long long sum = 0;
    for(int i = 0; i <= n; ++i){
        sum += query(s[i] + N);
        add(s[i] + N);
    }
    return sum >= 1ll*n*(n+1)/4;
}
int main(){
    int l = 0, r = 0, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", a+i);
        r = max(a[i], r);
    }
    for(int i = 1; i <= 32; ++i){
        int mid = (l + r) >> 1;
        if(check(mid)){
            l = mid + 1;
            ans = mid;
        }else r = mid - 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
int main()
{
  std::string S;
  std::cin>> S ;
  int n = 0;
  n = S.size();
  if(S[n-1] == 's')
  {
    S = S + "es";
    std::cout<<S;
  }
  else
  {
    S = S + "s";
    std::cout<<S;
  }
}

Measured memory_bytes: 3056
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 1.5e6 + 6;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("mountains.in", "r", stdin);
	//freopen("mountains.out", "w", stdout);
	ll n, m, q; cin >> n >> m >> q;
	vector<ll>a(n);
	vector<ll>b(m);
	for (ll i = 0; i < n; i++) cin >> a[i];
	for (ll i = 0; i < m; i++) cin >> b[i];
	ll ans = *min_element(all(a)) + *min_element(all(b));

	while (q--) {
		ll x, y, c; cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans << endl;
	return 0;
}

/*


*/

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;

int main(){
    vector<int> mon(1,6);
    const int MAX = 300000;
    for(int i=1;7*i<MAX;i++){
        mon.emplace_back(7*i + 1);
        mon.emplace_back(7*i + 6);
    }

    vector<int> monPrime;
    for(int m : mon){
        bool isPrime = true;
        for(int p : monPrime){
            if(m % p == 0){
                isPrime = false;
                break;
            }
            if(p*p > m) break;
        }
        if(isPrime) monPrime.emplace_back(m);
    }

    int N;
    while(cin >> N , N != 1){
        cout << N << ":";
        for(int p : monPrime){
            if(N % p == 0) cout << " " << p;
        }
        cout << endl;
    }
  
}



Measured memory_bytes: 3428
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int sz, tz;
    string s, t;
    cin >> s >> t, sz = s.size(), tz = t.size();
    
    int dp[sz+1][tz+1];
    memset(dp, 0x00, sizeof(dp));
    
    for (int i = 0; i < sz; ++i) {
        for (int j = 0; j < tz; ++j) {
            dp[i+1][j+1] = max({dp[i+1][j], dp[i][j+1], dp[i][j] + (s[i] == t[j])});
        }
    }
    
    int nx = sz, ny = tz;
    string ans;
    while (nx and ny) {
        if (dp[nx][ny] == dp[nx - 1][ny - 1] + 1 and s[nx - 1] == t[ny - 1]) --nx, --ny, ans.pb(s[nx]);
        else if (dp[nx][ny] == dp[nx - 1][ny]) --nx;
        else if (dp[nx][ny] == dp[nx][ny - 1]) --ny;
    }
    reverse(ALL(ans));
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 73900