akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int n, q;
int S[10010];
int T[510];
// vector<int> C;

// int search(int x) {
//   int ret = -1;
//   for (int i = 0; i < q; i++) {
//     if (T[i] == x) {
//       ret = i;
//       break;
//     }
//   }
//   return ret;
// }
//
// int linearSearch(int x) {
//   // 比較
//   // 1. 終わったかどうか
//   // 2. keyと同じかどうか
//   for (int i = 0; i < n; i++) {
//     if (A[i] == x) {
//       return i;
//     }
//   }
//   return -1;
// }

int linearSearch(int x) {
  int i = 0;
  S[n] = x;
  // 1. keyと同じかどうか
  while(S[i] != x) {
    i++;
  }
  // cout << x << ", i:" << i << ", n:" << n << endl;
  if (i >= n) {
    return -1;
  } else {
    return i;
  }
}

//
// int searchC(int x) {
//   int ret = -1;
//   for (auto itr = C.begin(); itr != C.end(); itr++) {
//     if (*itr == x) {
//       ret =
//       return ret;
//     }
//   }
// }

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }
  int count = 0;
  for (int i = 0; i < q; i++) {
    int ret = linearSearch(T[i]);
    if (ret != -1) {
      count++;
    }
  }
  cout << count << endl;
}



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

struct UnionFind {
    vector<int> par;

    UnionFind(int v) : par(v, -1) { }

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            par[x] += par[y]; par[y] = x;
        }
    }

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


int main(void){
  int f[1001],m=1001,V,d;
  f[0]=1;f[1]=2;
  for(int i=2;i<=1000;++i){f[i]=(f[i-1]+f[i-2])%m;}
  while(cin>>V>>d){
    UnionFind uf(V);
    for(int i=1;i<=V;++i){
      for(int j=1;j<=V;++j){
        if(abs(f[i]-f[j])<d)uf.unite(i-1,j-1);
      }
    }
    int cnt=0;
    for(int i=0;i<V;++i)cnt+=(uf.par[i] < 0)?1:0;
    // for(int i = 0; i < V; i++) cerr << f[i+1] << ' ' << uf.root(i) << endl;
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>

int main(){
  int u, k, n, v, G[200][200], i, j;

  scanf("%d", &n);

  for(i = 1 ; i <= n ; i++)
    for(j = 1 ; j <= n ; j++)
      G[i][j] = 0;

  for(i = 1 ; i <= n ; i++){
    scanf("%d%d", &u, &k);
    for(j = 1 ; j <= k ; j++){
      scanf("%d", &v);
      G[i][v] = 1;
    }
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n ; j++){
      if(j == n) printf("%d", G[i][j]);
      else printf("%d ", G[i][j]);
    }
    printf("\n");

  }

  return 0;
}

Measured memory_bytes: 684
#include <iostream>
#include <algorithm>

using namespace std;

struct Fraction {
    int numer, denom;

    Fraction(int n, int d) : numer(n), denom(d) { normalize(); }

    void normalize() {
        int gcd = __gcd(numer, denom);
        numer /= gcd;
        denom /= gcd;
    }

    double value() const {
        return (double)numer / denom;
    }

    Fraction& operator -=(const Fraction &other) {
        int gcd = __gcd(denom, other.denom);
        int lcm = denom*other.denom / gcd;
        
        numer *= (lcm/denom);
        numer -= other.numer*lcm/other.denom;
        denom = lcm;
        normalize();

        return *this;
    }

    bool operator < (const Fraction &other) const {
        return (long long)numer*other.denom < (long long)other.numer*denom;
    }

    bool operator == (const Fraction &other) const {
        return numer == other.numer && denom == other.denom;
    }

    bool operator <= (const Fraction &other) const {
        return *this == other || *this < other;
    }
};

Fraction operator - (const Fraction &f1, const Fraction &f2) {
    Fraction res = f1;
    res -= f2;
    return res;
}

ostream& operator <<(ostream &os, const Fraction &f) {
    os << f.numer << "/" << f.denom;
    return os;
}

int N, A;

int dfs(const Fraction &frac, int a, int n, int m) {
    if(a > A) return 0;
    if(n == N) {
        //cout << frac << ' ' << a << ' ' << n << endl;
        if(frac.numer == 1 && frac.denom >= m && (long long)a*frac.denom <= A) return 1;
        return 0;
    }

    //cout << frac << ' ' << a << ' ' << n <<  ' ' << m << endl;
    int cnt = 0;
    if(frac.numer == 1 && frac.denom >= m && (long long)frac.denom*a <= A) ++cnt;

    for(int i = m; frac <= Fraction(N-n+1, i); ++i) {
        if((long long)a*i > A) break;
        Fraction next = frac - Fraction(1, i);
        if(next.value() < 0) continue;
        if(next.numer == 0) continue;
        //cout << "Select " << Fraction(1,i) << endl;;
        cnt += dfs(next, a*i, n+1, i);
    }
    return cnt;
}

int main() {
    while(true) {
        int p, q;
        cin >> p >> q >> A >> N;
        if(!p && !q && !A && !N) break;

        cout << dfs(Fraction(p, q), 1, 1, 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 864
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(0)
 
money = 1000
previous_tendency = "remain"
current_tendency = "remain"
count = 1

#print(A)
 
for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "remain"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(money,n,"chance",A[n],min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(A[n]-min(A[count:n+1]))
        #print(A[count:n+1],money)
        count = n + 1
        previous_tendency = "remain"
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    
    if current_tendency != "remain":
      previous_tendency = current_tendency
print(money)

Measured memory_bytes: 9172
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm> 
#include <ctime>

#define MaxN 500005
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int N,M,FN=1,FM=1;

int main()
{
	cin>>N>>M;
	if(abs(N-M)>1)
	{
		cout<<0;
		return 0;
	}
	for(int i=2;i<=N;i++)
		FN=(1LL*FN*i)%MOD;
	for(int i=2;i<=M;i++)
		FM=(1LL*FM*i)%MOD;
	if(N==M)
		cout<<(1LL*FN*FM*2)%MOD;
	else cout<<(1LL*FN*FM)%MOD;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1 << 30;
const int C[] = {1, 5, 10, 50, 100, 500};

int main()
{
  vector<int> dp(666000+1, 0);
  for (int i = 0; i < dp.size(); ++i) {
    int pay = i;
    for (int j = 5; j >= 0; --j) {
      int k = pay / C[j];
      pay -= k * C[j];
      dp[i] += k;
    }
  }

  int P;
  while (cin >> P) {
    if (P == 0)
      break;

    int sum = 0;
    vector<int> N(6);
    for (int i = 0; i < 6; ++i) {
      cin >> N[i];
      sum += C[i] * N[i];
    }

    int ans = INF;
    for (int i = P; i <= sum; ++i) {
      int pay = i, num = 0;
      for (int j = 5; j >= 0; --j) {
	int k = min(pay / C[j], N[j]);
	pay -= k * C[j];
	num += k;
      }

      if (pay != 0)
	continue;

      ans = min(ans, num+dp[i-P]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int>time(3);
  for(int i=0;i<3;i++){
    cin>>time.at(i);
  }
  sort(time.begin(),time.end());
  cout<<time.at(0)+time.at(1)<<endl;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k; llong T[MAX];
// 最大積載量 P の k 台のトラックで何個の荷物を積めるか?
int check(llong P) {
    int i=0;
    for(int j=0; j<k; j++){
        llong s=0;
        while(s+T[i] <= P){
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}
int solve() {
    llong left = 0;
    llong right = 100000*10000; //荷物の個数×1個当たりの最大重量
    llong mid;
    while(right-left > 1){
        mid = (left + right) / 2;
        int v = check(mid); // mid == P を決めて何個積めるかチェック
        if(v>=n) right= mid;
        else left = mid;
    }
    return right;
}

int main()
{
    cin >> n >> k;
    for(int i=0; i<n; i++) cin>>T[i];
    llong ans = solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3864
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
int a[3] = {300000, 200000, 100000};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int x, y;
    cin >> x >> y;
    int ans = 0;
    
    if(x <= 3) ans += a[x - 1];
    if(y <= 3) ans += a[y - 1];
    if(x == 1 && y == 1) ans += 400000;
    output(ans);
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[200000];
int cnt[20];
int isok(int x){
  int i;
  for(i=0;i<(20);i++){
    if( (x&1<<i) && cnt[i] ){
      return 0;
    }
  }
  return 1;
}
void add(int x, int v){
  int i;
  for(i=0;i<(20);i++){
    if(x&1<<i){
      cnt[i] += v;
    }
  }
}
int main(){
  int i, j;
  long long res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  j = 0;
  for(i=0;i<(N);i++){
    while(j < N && isok(A[j])){
      add(A[j++], 1);
    }
    res += j - i;
    add(A[i], -1);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N, A[2d5];
// int cnt[20];
// 
// int isok(int x){
//   rep(i,20) if( (x&1<<i) && cnt[i] ) return 0;
//   return 1;
// }
// 
// void add(int x, int v){
//   rep(i,20) if(x&1<<i) cnt[i] += v;
// }
// 
// {
//   int i, j;
//   ll res = 0;
//   rd(N,A(N));
// 
//   j = 0;
//   rep(i,N){
//     while(j < N && isok(A[j])) add(A[j++], 1);
//     res += j - i;
//     add(A[i], -1);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    int max = 0, ret = 0;
    for (int i = 0; i < n; i++) {
        int h;
        std::cin >> h;
        if (h >= max) ret++;
        max = std::max(max, h);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b, k, sum = 0, num = 0, ans = 0; cin >> n >> a >> b >> k;
	long long test[3] = { 0 }, uiop[2] = { 0 };
	test[0] = n; test[1] = a; test[2] = b;
	for (int h = 0; h < 2; h++) {
		sum = test[1] + test[2]; num = test[0] + test[2];
		ans = test[0] + test[1];
		test[0] = sum; test[1] = num; test[2] = ans;
		uiop[h] = test[0] - test[1];
		if (abs(test[0] - test[1]) >= 1000000000000000000) {
			cout << "Unfair" << endl;
			cin >> n; return 0;
		}
	}
	if (k % 2 == 0) {
		cout << uiop[1] << endl;
	}
	else {
		cout << uiop[0] << endl;
	}
	cin >> n;
}

Measured memory_bytes: 384
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>
#include <iomanip>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


void proc() {
	struct Link {
		int next;
		int w;
	};
	LOAD(int, N);
	std::vector<std::vector<Link>>link(N);
	std::vector<int> color(N);
	std::fill_n(color.begin(), N, -1);
	for (int i = 0; i < N - 1; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		link[u - 1].push_back({ v - 1,w });
		link[v - 1].push_back({ u - 1,w });
	}
	unordered_set<int> visited = { 0 };
	unordered_set<int> pos = { 0 };
	color[0] = 0;
	while (!pos.empty()) {
		auto& p = *pos.begin();
		for (auto& li : link[p]) {
			if (visited.find(li.next) != visited.end())continue;
			visited.insert(li.next);
			pos.insert(li.next);
			if (li.w % 2 == 0) {
				color[li.next] = color[p];
			}
			else {
				color[li.next] = 1 - color[p];
			}
		}
		pos.erase(p);
	}

	for (int i = 0; i < N; ++i) {
		if (color[i] == 0) {
			cout << '0';
		}
		else {
			cout << '1';
		}
		if (i != N - 1) {
			cout << endl;
		}
	}

}


#endif


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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A, B;
	string op;
	cin >> A >> op >> B;
	if (op == "+")
		cout << A + B << "\n";
	else
		cout << A - B << "\n";
}


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

int main() {
  ll N, K, S;
  cin >> N >> K >> S;
  ll dif = N - K - 1;
  for (ll i = 0; i < N; ++i) {
    if (i <= dif) {
      if (S != pow(10, 9)) {
        cout << 1000000000 << " ";
      } else {
        cout << 1000000000 - 1 << " ";
      }
    } else if (dif < i) {
      cout << S << " ";
    }
  }
}

Measured memory_bytes: 1280
N = int(input())  
A = [int(i) for i in input().split()]

ans = []

sumA = sum(A)
sum_even = 2*sum(A[1 : N : 2])
ans_i = sumA - sum_even
ans.append(ans_i)

for i in range(N-2):
	ans_i = 2*A[i] - ans_i
	ans.append(ans_i)

ans.append(2*A[-1] - ans[0])

ans=[str(a) for a in ans]
ans=" ".join(ans)
print(ans)

Measured memory_bytes: 18120
#include <cstdio>
#include <map>

int main()
{
  int n;
  scanf("%d", &n);
  std::map<int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    int a;
    scanf("%d", &a);
    mp[a]++;
  }
  int odd = 0;
  int even = 0;
  for (auto &p : mp)
  {
    p.second & 1 ? ++odd : ++even;
  }
  printf("%d\n", even & 1 ? odd + even - 1 : odd + even);
  return 0;
}

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

using namespace std;

const int MAX_N = 100000;

int n, a, b, x[MAX_N + 1];

long long ans = 0;

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

    cin >> n >> a >> b;

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

    for (int i = 2; i <= n; i++) {
        ans += min((long long)(b), (long long)(a) * (long long)(x[i] - x[i - 1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
//==========================================
// ABC141a
//
// 2019/09/15
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  string s;
  cin >> s;

  if(s == "Sunny")
  {
    cout << "Cloudy" << endl;
  }
  else if(s == "Cloudy")
  {
    cout << "Rainy" << endl;
  }
  else
  {
    cout << "Sunny" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int n;
    cin >> n;
    vll arr(n);
    for (auto &x: arr)
        cin >> x;

    ll c = 0;
    FOR (i, 2, n)
        c ^= arr[i];

    ll d = arr[0] + arr[1];
    ll a = 0, b = 0;

    FOR (i, 0, 43) {
        if (c&(1ll<<(ll)i)) {
            b += (1ll<<(ll)i);
        }
    }
    d -= b;
    RFOR (i, 0, 43) {
        if ((c&(1ll<<(ll)i)) == 0 and 2*(1ll<<(ll)i) <= d)
            a += (1ll<<(ll)i), b += (1ll<<(ll)i), d -= 2*(1ll<<(ll)i);
    }

    if (d)
        goto bad;

    assert((a^b) == c);

    RFOR (i, 0, 43) {
        if ((a&(1ll<<(ll)i)) == 0 and (b&(1ll<<(ll)i)) != 0) {
            if (a + (1ll<<(ll)i) <= arr[0]) {
                a += (1ll<<(ll)i);
                b -= (1ll<<(ll)i);
            }
        }
    }

    if (a > arr[0] or a == 0)
        goto bad;

    cout << arr[0] - a << "\n";
    return;

    bad: cout << -1 << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    int t = 1;
    tc(t) {
        solve();
    }

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 3668
import sys
read=sys.stdin.buffer.readline

class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l)

def main():
    def update(x,i):
        if good[x]==-1:
            good[x]=i
            bit.add(i,1)
        else:
            bit.add(good[x],-1)
            good[x]=i
            bit.add(good[x],1)
        return
    
    N,Q=map(int,read().split())
    c=list(map(int,read().split()))
    Query=[]
    for i in range(Q):
        l,r=map(lambda x:int(x)-1,read().split())
        Query.append((l,r,i))
    Query.sort(key=lambda x:x[1])
    ans=[-1]*Q
    good=[-1]*(N+1)
    bit=BIT(N)

    i=0
    for L,R,w in Query:
        while(i<=R):
            update(c[i],i)
            i+=1
        ans[w]=bit.cum(L,R+1)

    print(*ans,sep='\n')
    return
    
if __name__=='__main__':
    main()


Measured memory_bytes: 190272
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int a,b,c;
  cin >> a >> b >> c;
  int ans=a+b+c;
  ans -= max(a,max(b,c));

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

Measured memory_bytes: 256
from bisect import bisect_right
N,D,A=map(int,input().split())
X,H=[None]*N,{}
for i in range(N):
  X[i],H[X[i]]=map(int,input().split())
X.sort()
f=[0]*N
ans=i=0
while i<N:
  if i>0:
    f[i]+=f[i-1]
  if f[i]*A<H[X[i]]:
    k=-((f[i]*A-H[X[i]])//A)
    f[i]+=k
    ans+=k
    j=bisect_right(X,X[i]+(D<<1))
    if j<N:
      f[j]-=k
  i+=1
print(ans)

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

int H;
int W;


char r[802][820];

int dist[802][802];  //minimum walk
int D[802][802];

bool ok[802][802];



struct st{
	int a;
	int b;
};
queue<st> q;

int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };


int main(){
	memset(dist, 0, sizeof(dist));
	cin >> H >> W;
	int kk;
	cin >> kk;
	pair<int, int> star;
	for (int i = 0; i < H; i++){
		scanf("%s", r[i]);
		for (int j = 0; j < W; j++){
			if (r[i][j] == 'S'){
				star = make_pair(i, j);
			}
		}
	}
	memset(dist, -1, sizeof(dist));
	dist[star.first][star.second] = 0;
	q.push({ star.first, star.second });
	while (!q.empty()){
		int a = q.front().a;
		int b = q.front().b;
		q.pop();
		for (int i = 0; i < 4; i++){
			int x = a + dx[i];
			int y = b + dy[i];
			if (x >= 0 && y >= 0 && x < H&&y < W){
				if (r[x][y] == '#')continue;
				if (dist[a][b] != kk&&dist[x][y] == -1){
					dist[x][y] = dist[a][b] + 1;
					q.push({ x, y });
				}
			}
		}
	}
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (dist[i][j] != -1){
				ok[i][j] = true;
				dist[i][j] = 0;
				q.push({ i, j });
				if (i == H - 1 || i == 0 || j == 0 || j == W - 1){
					puts("1");
					return 0;
				}
			}
		}
	}
	while (!q.empty()){
		int a = q.front().a;
		int b = q.front().b;
		q.pop();
		for (int i = 0; i < 4; i++){
			int x = a + dx[i];
			int y = b + dy[i];
			if (x >= 0 && y >= 0 && x < H&&y < W){
				if (dist[x][y] == -1||dist[x][y]>dist[a][b]+1){
					dist[x][y] = dist[a][b] + 1;
					q.push({ x, y });
				}
			}
		}
	}
	int ans = INT_MAX;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (i == 0 || j == 0 || i == H - 1 || j == W - 1){
				ans = min(ans, (dist[i][j] + kk - 1) / kk);
			}
		}
	}
	ans++;
	cout << ans << endl;
	return 0;
}

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

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

typedef long long ll;

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

/*
#define MAX 10000
#define NIL -1
struct Node { int p, l, r; };
struct Node T[MAX];
*/

ll dp[107][100007] = {0}; //dpにはv[i]が入る
ll w[107], v[107], W;

int main() {

    int n;
    cin >> n >> W;

    rep(i, n) cin >> w[i] >> v[i];

    for (int i = 0; i < n; i++){
        for (int sum_w = 0; sum_w <= W; sum_w++){ //最大値のWを超えない範囲で

            if(sum_w - w[i] >= 0){ //重量オーバーにならないなら実行
                chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]); //dp[i+1]にかき集める
            }

            chmax(dp[i + 1][sum_w], dp[i][sum_w]); //スルー
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


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

int main() {
  int N,N1,A=0,B,i,j;
  cin >> N;
  N1=N;
  for(i=8;i>=0;i--){
    B=1;
    for(j=0;j<i;j++){
      B*=10;
    }
    A+=N1/B;
    N1=N1%B;
  }
  if(N%A){cout <<"No" <<endl;}
  else{cout << "Yes" <<endl;}
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include<iomanip>

using namespace std;
 
const long long N = 1e5 + 5;

long long cnt = 0;
long long ans = 0;
long long n, m; 
long long a[N];
vector <long long> graph[N];
vector <long long> other;
vector <long long> component[N];
long long comp[N];
bool mark[N];
 
void dfs(long long v, long long cnt) 
{
	comp[v] = cnt;
	mark[v] = true;
	for (long long i = 0; i < graph[v].size(); i++)
	{
		long long u = graph[v][i];
		if (!mark[u])
		{
			dfs(u, cnt);
		}
	}
}

int main() 
{
	cin >> n >> m;
	for (long long i = 0; i < n; i++) 
	{
		cin >> a[i];
	}
	for (long long i = 0; i < m; i++) 
	{
		long long u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	if (m == n - 1) 
	{
		cout << 0 << endl;
		exit(0);
	}
	for (long long i = 0; i < n; i++) 
	{
		if (!mark[i]) 
		{
			cnt++;
			dfs(i, cnt);
		}
	}
	for (long long i = 0; i < n; i++) 
	{
		component[comp[i]].push_back(a[i]);
	}
	for (long long i = 1; i <= cnt; i++)
	{
		sort(component[i].begin(), component[i].end());
	}
	for (long long i = 1; i <= cnt; i++) 
	{
		ans += component[i][0];
		for (long long j = 1; j < component[i].size(); j++) 
		{
			other.push_back(component[i][j]);
		}
	}
	sort(other.begin(), other.end());
	if (2 * (cnt - 1) > n) 
	{
		cout << "Impossible" << endl;
		exit(0);
	}
	for (long long i = 0; i < cnt - 2; i++) 
	{
		ans += other[i];
	}
	cout << ans << endl;
}
	
            


 


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int ret=0;
	string s; cin>>s;
	int n=s.size();
	for (int i=0; i<n/2; i++)
		if (s[i]!=s[n-1-i])
		ret++;
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;


class Program
{
    static void Main()
    {
        int n, k;
        var t = ReadIntArray();
        n = t[0]; k = t[1];
        
        string s;
        s = ReadLine();
        int len = s.Length;
        s = s + "E" ; // sentinel

        int l = 0, r = 0;

        // skip '1's
        while (s[r] == '1'){ r++; }
        for (int i = 0; i < k; i++){
            // skip '0's
            while (s[r] == '0'){ r++; }
            // skip '1's
            while (s[r] == '1'){ r++; }
        }
 
        int ans = r - l;
  
        while (r < len){
            // NEXT L
            // skip '1's
            while (s[l] == '1'){ l++; }
            // skip '0's
            while (s[l] == '0'){ l++; }
 
            // NEXT R
            // skip '0's
            while (s[r] == '0'){ r++; }
            // skip '1's
            while (s[r] == '1'){ r++; }
 
            ans = Math.Max(ans, r - l);
        }

        WriteLine(ans);
    }

    static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

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

using namespace std;

using int64 = long long;

int main() {
  int64 N, C, X[100000], V[100000];

  cin >> N >> C;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> V[i];
  }

  int64 ret = 0;

  auto solve = [&]() {

    int64 sum = 0;
    int64 pv = 0;
    vector< int64 > get(N);
    for(int i = 0; i < N; i++) {
      sum -= X[i] - pv;
      sum += V[i];
      ret = max(ret, sum);
      get[i] = sum;
      pv = X[i];
    }
    for(int i = 1; i < N; i++) {
      get[i] = max(get[i], get[i - 1]);
    }

    sum = 0;
    pv = C;
    for(int i = N - 1; i >= 0; i--) {

      sum -= pv - X[i];
      sum += V[i];
      ret = max(ret, sum);
      pv = X[i];

      int64 sum2 = sum;
      sum2 -= C - X[i];
      if(i > 0) ret = max(ret, sum2 + get[i - 1]);
    }
  };

  solve();
  for(int i = 0; i < N; i++) {
    X[i] = C - X[i];
  }
  reverse(X, X + N);
  reverse(V, V + N);
  solve();

  cout << ret << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

map<string, vector<PII>> M;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    REP(i, n) {
        string s; int p;
        cin >> s >> p;
        M[s].emplace_back(-p, i+1);
    }

    for(auto a:M) {
        sort(ALL(a.second));
        for(auto i:a.second) cout << i.second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        d = 4*h*n-N*h-N*n
        if d <= 0 or N*h*n%d != 0: continue
        w = N*h*n//d
        print(h,n,w)
        exit()

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

namespace atcoder {
    class Program {
        static void Main (string[] args)
         {
            var num = Input.getIntArray();
            int r = num[0];
            int d = num[1];
            int tmp = num[2];
            int result = 0;

            for (int i = 0; i < 10; i++)
            {
                result = r * tmp - d;
                Console.WriteLine(result);
                tmp = result;
            }
        }
    }

    class Output {
        public static void writeIntArraySprit (int[] array) {
            for (int i = 0; i < array.Length; i++) {
                if (i == array.Length - 1) {
                    Console.Write (i);
                } else {
                    Console.Write (i + " ");
                }

            }
        }
    }

    class Input {
        public static int[] getIntArray () {
            string[] s = Console.ReadLine ().Split (' ');
            int[] num = s.Select (x => int.Parse (x)).ToArray ();
            return num;
        }
        public static long[] getLongArray () {
            string[] s = Console.ReadLine ().Split (' ');
            long[] num = s.Select (x => long.Parse (x)).ToArray ();
            return num;
        }
        public static string[] getStringArray (int n) {
            var s = new string[n];
            for (int i = 0; i < n; i++) {
                s[i] = Console.ReadLine ();
            }
            return s;
        }
    }
}

Measured memory_bytes: 11348
def main():
    s = list(input())
    s.reverse()
    MOD = 2019
    tot = 0
    ans = 0
    d = [0 for _ in range(MOD)]
    for i in range(len(s)):
        d[tot] += 1
        x = pow(10, i, MOD)
        p = int(s[i]) * x
        p %= MOD
        tot = (tot + p) % MOD
        ans += d[tot]
    return ans


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


Measured memory_bytes: 10448
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

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

  ll sum = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll m = i - 1;
      ll anotherm = n / i - 1;
      if ((m != 0) && ((n / m) == (n % m))) {
        sum += m; 
      }
      if ((i != n/i) && (anotherm != 0)) {
        if ((n / anotherm) == (n % anotherm)) {
          sum += anotherm;
        }
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	long long n, a[100001], ans1 = 0, x = 0, sum2, sum1, ans2 = 0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	sum2 = a[0]; sum1 = a[0];
	if (sum2 <= 0) {
		ans1 = abs(sum2) + 1;
		sum2 = 1; sum1 = 1;
	}
	for (int i = 1; i < n;i++) {
		sum2 += a[i];
		if (sum2 >= 0 && sum1 > 0) {
			ans1 += abs(sum2) + 1;
			sum2 = sum2 - abs(sum2) - 1;
		}
		if (sum2 <= 0 && sum1 < 0) {
			ans1 += abs(sum2) + 1;
			sum2 = sum2 + abs(sum2) + 1;
		}
		sum1 = sum2;
	}
	sum2 = a[0]; sum1 = a[0];
	if (sum2 >= 0) {
		ans2 = abs(sum2) + 1;
		sum2 = -1; sum1 = -1;
	}
	for (int i = 1; i < n; i++) {
		sum2 += a[i];
		if (sum2 >= 0 && sum1 > 0) {
			ans2 += abs(sum2) + 1;
			sum2 = sum2 - abs(sum2) - 1;
		}
		if (sum2 <= 0 && sum1 < 0) {
			ans2 += abs(sum2) + 1;
			sum2 = sum2 + abs(sum2) + 1;
		}
		sum1 = sum2;
	}
	cout << min(ans1,ans2) << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
ll N;cin>>N;
ll i;
for(i=0;i*(i+1)/2<N;i++){continue;}
cout << i << endl;
}

Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-11 21:19:22
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
string S[10010];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    for (auto j = 0; j < (int)S[i].size() - 1; j++)
    {
      if (S[i][j] == 'A' && S[i][j + 1] == 'B')
      {
        ans++;
      }
    }
  }
  int A = 0;
  int B = 0;
  int AB = 0;
  for (auto i = 0; i < N; i++)
  {
    if (S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A')
    {
      AB++;
    }
    else if (S[i][0] == 'B')
    {
      B++;
    }
    else if (S[i][S[i].size() - 1] == 'A')
    {
      A++;
    }
  }
#if DEBUG == 1
  cerr << "ans = " << ans << ", A = " << A << ", B = " << B << ", AB = " << AB << endl;
#endif
  if (AB > 0)
  {
    ans += AB - 1;
    if (A > 0)
    {
      ans++;
      A--;
    }
    if (B > 0)
    {
      ans++;
      B--;
    }
  }
#if DEBUG == 1
  cerr << "ans = " << ans << ", A = " << A << ", B = " << B << ", AB = " << AB << endl;
#endif
  ans += min(A, B);
  cout << ans << endl;
}

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

int main(void){

    int n,m;
    cin >> n;
    int x[n];
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    cin >> m;
    int a[m];
    for(int i=0;i<m;i++){
        cin >> a[i];
        bool ck = true;
        if(x[a[i]-1]<2019){
            for(int j=0;j<n;j++){
                if(x[a[i]-1]+1==x[j]){
                    ck = false;
                    break;
                }
            }
            if(ck) x[a[i]-1] = x[a[i]-1]+1;
        }
    }
    
    for(int i=0;i<n;i++){
        cout << x[i] << endl;
    }
}


Measured memory_bytes: 3100
import sys

def solve():
    file_input = sys.stdin
    N, W = map(int, file_input.readline().split())
    C = [0] * (W + 1)
    for line in file_input:
        item_v, item_w = map(int, line.split())
        for i, vals in enumerate(zip(C, C[item_w:]), start=item_w):
            v1, v2 = vals
            C[i] = max(v1 + item_v, v2)
    print(C[W])

solve()

Measured memory_bytes: 8348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

ll cnt = 0;
int n, a[1000009];
vector<int> g;

void insertionSort(int a[], int n, int g) {
  for(int i = g; i < n; i++) {
    int v = a[i];
    int j = i-g;
    while(j >= 0 && a[j] > v) {
      a[j+g] = a[j];
      j = j-g;
      cnt++;
    }
    a[j+g] = v;
  }
}

void shellSort(int a[], int n) {
  for(int i = 1;;) {
    if(i > n) break;
    g.push_back(i);
    i = 3*i + 1;
  }
  for(int i = g.size() - 1; i >= 0; i--) insertionSort(a, n, g[i]);
}

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

  shellSort(a, n);

  cout << g.size() << endl;
  for(int i = g.size() - 1; i >= 0; i--) {
    cout << g[i];
    if(i) cout << " "; 
  }
  cout << endl << cnt << endl;
  for(int i = 0; i < n; i++) cout << a[i] << endl;

  return 0;
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vld vector<long double>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl A(n);
    rep(i,n)cin>>A[i];
    ld x=1;
    rep(i,n)x*=A[i];
    ld y=0;
    rep(i,n)y+=x/A[i];
    ld res=x/y;
    cout<<fixed<<setprecision(10)<<res<<endl;
}

Measured memory_bytes: 3840
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
4 10
---+/
/+---test
8 9
---+/
/+:---test
8 8
---+/

void main(string[] args) {
  long A, B;
  readf(" %d %d ", &A, &B);

  long cnt = 1;

  long ans;
  while (cnt < B) {
    cnt += A - 1;
    ++ans;
  }
  ans.writeln;
}


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

int main()
{
    string x, y;
    int a = 0;
    cin >> x >> y;
    for (size_t i = 0; i < x.size(); i++)
    {
        /* code */

        if (x[i] != y[i])
        {
            a++;
            /* code */
        }
    }

    cout << a;
}

Measured memory_bytes: 3388
def dfs(left,right):
    if right-left==1:
        return h[left]
    elif right-left<=0:
        return 0
    else:
        ret=min(h[left:right])
        k=0
        for i in range(left,right):
            h[i]-=ret
            if h[i]==0:
                k=i
        ret+=dfs(left,k)
        ret+=dfs(k+1,right)
        return ret

N=int(input())
h=list(map(int,input().split()))

print(dfs(0,N))


Measured memory_bytes: 9136
N = int(input())
A = list(map(int, input().split()))

r = 0
xorsum = 0
sum = 0
count = 0
for l in range(N):
    while (r != N and sum + A[r] == xorsum ^ A[r]):
        sum += A[r]
        xorsum ^= A[r]
        r += 1

    count += r - l
    sum -= A[l]
    xorsum ^= A[l]

print(count)

Measured memory_bytes: 24424
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	cin >> L;
	while (M <= N) {
		M <<= 1;
		L--;
	}
	while (K <= M) {
		K <<= 1;
		L--;
	}
	if (L >= 0)cout << "Yes\n";
	else cout << "No\n";
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

int main() {
  ll K;
  cin >> K;
  vector<ll> l(50, 49+(K+49)/50);
  rep(i,50) {
    if (i<K%50) continue;
    else l[i]-=(K%50+1);
  }
  if (K%50==0) rep(i,50) l[i]++;
  cout << 50 << endl;
  rep(i,50) cout << l[i] << ' ';
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>

#define BOGO 10

using namespace std;

int main()
{
	int arr[BOGO];
	bool found;
	int j;
	srand(static_cast<unsigned int>(time(NULL)));
	
	for(int i = 0; i < BOGO; i++){
		cin >> arr[i];
	}
	
	for(;;){
		
		/**
		for(int j = 0; j < BOGO; j++){
			cout << arr[j] << flush;
		}
		cout << endl;
		/**/
		
		found = true;
		for(j = 0; j < BOGO-1; j++){
			if(arr[j] > arr[j+1]){
				found = false;
				break;
			}
		}
		
		if(found){
			break;
		}
		random_shuffle(arr, arr+BOGO);
	}
	cout << arr[9] << "\n" << arr[8] << "\n" << arr[7] << endl;
}

Measured memory_bytes: 836
/*
      author  : nishi5451
      created : 15.08.2020 20:59:54
*/

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


int main(){
    string s;
    cin >> s;
    if(s=="RRR"){
        cout << 3 << endl;
    }
    else if(s=="RRS" || s=="SRR"){
        cout << 2 << endl;
    }
    else if(s=="SSS"){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;
vector<int> G[MAX];

int DFS(int u,int p){
    int cnt=0,ha=0;
    
    for(int to:G[u]){
        if(to==p) continue;
        
        int a=DFS(to,u);
        if(a) cnt+=a;
        else ha++;
    }
    if(p==-1){
        if(G[u].size()==2){
            if(ha) cnt++;
        }else{
            cnt+=max(0,ha-1);
        }
    }else{
        cnt+=max(0,ha-1);
    }
    
    return cnt;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    if(N==2){
        cout<<1<<endl;
        return 0;
    }
    
    for(int i=0;i<N;i++){
        if(G[i].size()>=2){
            cout<<DFS(i,-1)<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 13440
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int main()
{
   fast;
   int n;
   cin >> n;
   string s1;
   cin >> s1;
   for(int i=0; s1[i]!=0; i++){
      int cc = s1[i]-'A';
      int n1 = cc+n; /// 27
      if(n1>=26){
        int c = (n1%26)+'A'; /// 1+A
        cout << (char)c;
      }
      else{
        int c = n1+'A';
        cout << (char)c;
      }
   }
   return 0;
}


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

#define f first
#define s second
#define p_b push_back
#define ull unsigned long long
#define ll  long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(nullptr);cout.tie(nullptr);ios_base::sync_with_stdio(false);
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int) x.size()
#define endl '\n'
#define len(x) x.length()

using namespace std;

signed main()
{
    fast_io;
    ll n;
    cin>>n;
    vector<ll>a(n);
    bool ok=1;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0 && a[i]%3 && a[i]%5){
            ok=0;
        }
    }
    if(ok){
        cout<<"APPROVED";
    }
    else{
        cout<<"DENIED";
    }
    return 0;
}


Measured memory_bytes: 256