akhauriyash/Code-Regression huggingface dataset:
import sys


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def is_prime_MR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1 << 32 else [
        2, 3, 5, 7, 11, 13, 17
    ] if n < 1 << 48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1


def find_factor_rho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):

        def f(x):
            return (x * x + c) % n

        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if is_prime_MR(g):
                return g
            elif is_prime_MR(n // g):
                return n // g
            return find_factor_rho(g)


def prime_factor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2**20:
            while n > 1:
                if is_prime_MR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = find_factor_rho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k
    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret


input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, input().split()))
g = 0
for a in A:
    g = gcd(g, a)

if g > 1:
    print('not coprime')
    exit()

X = [0] * 1001001
for a in A:
    for p in prime_factor(a):
        if X[p]:
            print('setwise coprime')
            exit()
        X[p] = 1

print('pairwise coprime')


Measured memory_bytes: 168452
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>

using namespace std;

long long int k, n, d[10], count = 0, s;
bool c[10] = {0};
vector<int> f;

void solve(int ans, int high){
	if(ans >= n){
		 f.push_back(ans);
		 return;
	}
	for(int i = 0; i < 10; i++){
		if(!c[i]){
			if(high == s && i == 0)
				continue;
			solve(ans + high*i, high*10);
		}
	}
	return;
}

int main(){
	cin >> n >> k;
	for(int i = 0; i < k; i++){
		cin >> d[i];
		c[d[i]] = 1;
	}
	
	for(int i = 1; i <= 10000; i*=10){
		if(n / i == 0){
			s = i;
			break;
		}
	}
	solve(0, 1);
	sort(f.begin(), f.end());
	cout << f[0] << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    ll n; ll x[105][3];
    cin >> n;
    for(int a = 0; a < n; a++){
        cin >> x[a][0] >> x[a][1] >> x[a][2];
    }
    for(int b = 0; b <= 100; b++){
        for(int c = 0; c <= 100; c++){
            int i = 0;
            ll h;
            while(true){
                h = x[i][2]+abs(x[i][1]-c)+abs(x[i][0]-b);
                if(x[i][2] != 0)break;          
                i++;
            }
            for(int d = 0; d < n; d++){
                if(x[d][2] != max((ll)0, h-abs(x[d][1]-c)-abs(x[d][0]-b)) )break;
                if(d == n-1){
                    cout << b << ' ' << c << ' ' << h << endl;
                    return 0;
                }
                
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n;
  while(scanf("%d", &n) && n){
    int minp = 999, maxp = 0;
    rep(j, n){
      int sum = 0, s;
      rep(i, 5){ scanf("%d", &s); sum += s;}
      maxp = max(maxp, sum); minp = min(minp, sum);
    }
    printf("%d %d\n", maxp, minp);
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   String a = sc.next();
   int count = 0;
 
   for(int i=0;i<3;i++) 
   {
     if(a.charAt(i)=='o')count++;
   }
   System.out.println(700+count*100);
 }
}

Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt(),h = scan.nextInt();
		int n = scan.nextInt();
		int x,y,a;
		int w1=0,w2=w,h1=0,h2=h;
		for(int i=0; i<n; i++) {
			x=scan.nextInt();
			y=scan.nextInt();
			a=scan.nextInt();
			if(a==1 && w1<x)w1=x;
			if(a==2 && w2>x)w2=x;
			if(a==3 && h1<y)h1=y;
			if(a==4 && h2>y)h2=y;
		}
		System.out.println(w2-w1>0 && h2-h1>0 ? (w2-w1)*(h2-h1) : 0);
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

//単純に反転させるとTLE
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;
    string r = {}, l = {};
    ll q; cin >> q;
    ll cnt_t = 0;
    rep(i, 0, q){
        ll t; cin >> t;
        if(t == 1){
            cnt_t++;
        }else{
            ll f; char c;
            cin >> f >> c;
            if(cnt_t%2 != 0){
                if(f == 1) f = 2;
                else if(f == 2) f = 1;
            }
            if(f == 1){
                l.push_back(c);
            }else{
                r.push_back(c);
            }
        }
    }
    reverse(ALL(l));
    s = l + s + r;
    if(cnt_t%2 != 0) reverse(ALL(s));
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

// A[i] := i人で行きたい友達の人数
int A[100003];

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

    REP(i, N){
        int a, b;
        std::cin >> a >> b;

        A[a]++;
        A[b+1]--;
    }

    FOR(i, 1, (N+1)+1){
        A[i] += A[i-1];
    }

    // REP(i, (N+1)+1){
    //     std::cout << A[i] << std::endl;
    // }

    int res = 0;
    FOR(i, 1, (N+1)+1){
        if(i <= A[i]+1){res = i-1;}
    }

    std::cout << res << std::endl;
}

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

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

  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  ll ans = 1;
  bool overflow_flag = false;
  bool zero_flag = false;
  for (int i = 0; i < N; i++) {
    if (__int128(ans) * A.at(i) > __int128(1e18)) {
      overflow_flag = true;
    }
    if (A.at(i) == 0) {
      zero_flag = true;
    }

    ans = ans * A.at(i);
  }

  if (zero_flag) {
    cout << 0 << endl;
    return 0;
  }
  if (overflow_flag) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

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

long long int findDivisors(long long int n)
{
    vector< long long int > div(n+1,0);

    for (int i = 1; i <= n; i++) {

        for (int j = 1; j * i <= n; j++)
            div[i * j]++;
    }
    long long int result = 0;
    for (int i = 1; i <= n; i++)
        result+=(i*div[i]);
    return result;
}

int main()
{
    long long int n; cin >> n;
    cout << findDivisors(n) << endl;
    return 0;
}


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

using namespace std;

main(){
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for(int i=0;i<n;i++){
    int sum = 0;
    for(int j=0;j<m;j++){
      int in;
      cin >> in;
      sum += in;
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

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

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

	string s; cin>>s;
	stack<char> st;
	for(auto i : s){
		if( st.empty() ){ st.push(i); }
		else{
			int x = st.top();
			if( x != i ){
				st.pop();
			}else{
				st.push(i);
			}
		}
	}
	cout<<(int)(s.size() - st.size())<<endl; 
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> v( N ), w( N );
    REP( i, N )
    {
        cin >> v[ i ] >> w[ i ];
    }
    vector<vector<int>> dp( N + 1, vector<int>( 100001 ) );
    for( int i = 1; i <= N; ++i )
    {
        for( int j = 0; j <= W; ++j )
        {
            if( j >= w[ i - 1 ] )
            {
                dp[ i ][ j ] = max( dp[ i - 1 ][ j ], dp[ i - 1 ][ j - w[ i - 1 ] ] + v[ i - 1 ] );
            }
            else
            {
                dp[ i ][ j ] = dp[ i - 1 ][ j ];
            }
        }
    }
    cout << dp[ N ][ W ] << endl;
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()

typedef long long ll;

const int N = 2e5 + 10;

int par[N];

int find(int u) {
	if (par[u] < 0) return u;
	return par[u] = find(par[u]);
}

void merge(int a, int b) {
	if ((a = find(a)) == (b = find(b))) return;
	if (par[a] < par[b]) swap(a, b);
	par[b] += par[a];
	par[a] = b;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
	fill(par, par + N, -1);
	int f, n;
	cin >> f >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		merge(a, b);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) if (par[i] < 0) ans = max(-par[i], ans);
	cout << ans;
	return 0;
}


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

using namespace std;

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

const int INF = 1000000000;

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

    vector< vector<int> > a(n, vector<int>(m));
    vector<int> c(n);

    rep (i, n) {
        cin >> c[i];
        rep (j, m) {
            cin >> a[i][j];
        }
    }

    int ans = INF;
    rep (i, 1 << n) {
        int cost = 0;
        vector<int> d(m);
        rep (j, n) {
            if ((i >> j) & 1) {
                cost += c[j];
                rep (k, m) {
                    d[k] += a[j][k];
                }
            }
        }

        bool ok = true;
        rep (j, m) {
            if (d[j] < x) {
                ok = false;
            }
        }
        if (ok) {
            ans = min(ans, cost);
        }
    }

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int[] hen=new int[N];
		int max=0;
		for(int i=0; i<N; i++) {
			hen[i]=sc.nextInt();
		}
		Arrays.sort(hen);
		for(int i=0; i<N-1; i++) {
			max+=hen[i];
		}
		if(max>hen[N-1]) {
			pl("Yes");
		}
		else {
			pl("No");
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

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

const int INF = 2147483647;

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 h[N];for(int i = 0; i < N; i++){cin >> h[i];}
    int cost[N];fill(cost,cost+N,INF);
    cost[0] = 0;cost[1] = abs(h[0]-h[1]);

    for(int i = 2; i < N; i++){
        chmin(cost[i], cost[i-1] + abs(h[i]-h[i-1]));
        chmin(cost[i], cost[i-2] + abs(h[i]-h[i-2]));
    }

    cout << cost[N-1] << endl;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()


def solve():
    for i in range(K, N):
        if A[i] > A[i - K]:
            print("Yes")
        else:
            print("No")


solve()


Measured memory_bytes: 31472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    cin >> N;
    REP(h,1,3501){
        REP(n,1,3501){
            ll a = N*h*n;
            ll b = 4*h*n - N*h - N*n;
            //cout << "a"<< endl;
            if(a >= b && b > 0 && a % b == 0){
                cout << h << " " << n << " " << a/b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;
int arr[maxn];
int odd[maxn];
int eve[maxn];
int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i<= n; i++)
	{
		scanf("%d", arr+i);
		if(i%2 == 1) odd[arr[i]]++;
		else eve[arr[i]]++;
	}
	int best = 0, ndbest = 0;
	int best1 = 0, ndbest1 = 0;
	for(int i = 1; i<= 1e5; i++)
	{
		if(best == 0 || eve[i]> eve[best])
		{
			ndbest = best;
			best = i;
		}
		else if(ndbest == 0 || eve[i]> eve[ndbest])
		{
			ndbest = i;
		}
		if(best1 == 0 || odd[i]> odd[best1])
		{
			ndbest1 = best1;
			best1 = i;
		}
		else if(ndbest1 == 0 || odd[i]> odd[ndbest1])
		{
			ndbest1 = i;
		}
	}
	int most = 0;
	most = max(eve[best]+odd[ndbest1], eve[ndbest]+odd[best1]);
	if(best != best1) most = max(most, eve[best]+odd[best1]);
	printf("%d\n", n-most);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N, K;
  cin >> N >> K;
  ll index = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    if (a == 1) {
      index = i;
    }
  }

  ll left_count = index;
  ll right_count = N - index - 1;
  K--;
  ll amari_left = left_count % K;
  ll amari_right = right_count % K;
  ll ans = 0;
  if (amari_left < amari_right) {
    if (left_count % K == 0) {
      ans += left_count / K;
    } else {
      ans += left_count / K + 1;
      right_count -= K - left_count % K;
      right_count = max((ll)0, right_count);
    }

    if (right_count % K == 0) {
      ans += right_count / K;
    } else {
      ans += right_count / K + 1;
    }
  } else {
    if (right_count % K == 0) {
      ans += right_count / K;
    } else {
      ans += right_count / K + 1;
      left_count -= K - right_count % K;
      left_count = max((ll)0, left_count);
    }
    if (left_count % K == 0) {
      ans += left_count / K;
    } else {
      ans += left_count / K + 1;
    }
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,n;
  cin>>a>>n;
	long long int arr[n+1];
  long long	int sum=0;
  for(int i=1;i<=n;i++)
  {
    cin>>arr[i];
    sum+=arr[i];
  }
  if(a<=sum)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;


}

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

void print_vector(vector<int> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        cout << A.at(i);
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;
}

int bubble_sort(vector<int> &A, int N)
{
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = N - 1; j >= i + 1; j--)
        {
            if (A.at(j - 1) > A.at(j))
            {
                count++;
                swap(A.at(j), A.at(j - 1));
            }
        }
    }
    return count;
}

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A.at(i);

    int count = bubble_sort(A, N);

    print_vector(A, N);
    cout << count << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
 
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}




void solve()
{
    int n;
    cin>>n;
    int ans = n;
    int p=1;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        if(k==p)
        {
            ans--;
            p++;
        }
    }
    if(ans==n)cout<<-1;
    else cout<<ans<<endl;
}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
        ll t;
    //cin>>t;
    //while(t--)
        solve();
}



Measured memory_bytes: 256
n = int(input())
lst = []
ans = 1

for i in range(n):
  lst.append(input())
#
lst.sort()
#print(lst)
pre = lst[0]
for s in lst[1:]:
  #print(s)
  if pre != s:
    ans += 1
  pre = s
  
print(ans)





Measured memory_bytes: 24792
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, m;
vector<P> v[1010];
bool used[1010] = {0};
i64 dp[1010];

i64 dfs(i64 now, i64 val){
	if(now == n+1) return val;
	for(int i = 0; i < v[now].size(); i++){
		val = v[now][i].second;
		if(dp[v[now][i].first] >= dp[now] + val) continue;
		if(dp[v[now][i].first] == LINF) continue;
		if(dp[now] == LINF){
			dp[v[now][i].first] = LINF;
			dfs(v[now][i].first, LINF);
			continue;
		}
		if(dp[v[now][i].first] != -LINF && dp[v[now][i].first] < dp[now]+val){
			//dp[now] = LINF;
			dp[v[now][i].first] = LINF;
			dfs(v[now][i].first, LINF);
			continue;
		}
		dp[v[now][i].first] = dp[now] + val;
		dfs(v[now][i].first, v[now][i].second);
	}
	//dp[now] = -LINF;
	return dp[n+1];
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a,b,c;
		cin >> a >> b >> c;
		v[a].push_back(P(b,c));
	}
	v[n].push_back(P(n+1, 0));
	
	for(int i = 0; i < 1010; i++) dp[i] = -LINF;
	dp[0] = 0; dp[1] = 0;
	
	i64 ans = dfs(1, 0);
	if(ans == LINF) cout << "inf" << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int v[N],n,a,b;
bool ch(int x){
	int moves=0;
	rep(i,0,n){
		int top=v[i]-b*x;
		if(top<0) continue;
		int bot=a-b;
	//	trace4(x,i,top,bot);
		int req=(top+bot-1)/bot;
		moves+=max(0LL,req);
	}
//	trace2(x,moves);
	if(moves<=x) return 1;
	else return 0;
}
int32_t main(){
	cin>>n>>a>>b;
	rep(i,0,n) cin>>v[i];
	int low=1,high=1e9;
	int ans=high;
	while(low<=high){
		int mid=(low+high)/2;
		if(ch(mid)){
			ans=min(ans,mid);
			high=mid-1;
		}
		else low=mid+1;
	}
	cout<<ans;
}



Measured memory_bytes: 1024
n = int(input())

ans = [0, 0, 0, 0]

for i in range(n):
  s = input()
  if s == 'AC':
    ans[0] += 1
  elif s == 'WA':
    ans[1] += 1
  elif s == 'TLE':
    ans[2] += 1
  else:
    ans[3] += 1

print('AC x ', end = '')
print(ans[0])
print('WA x ', end = '')
print(ans[1])
print('TLE x ', end = '')
print(ans[2])
print('RE x ', end = '')
print(ans[3])

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
long double l;
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>l;
	l/=3.00000;
	cout<<fixed<<setprecision(50)<<l*l*l<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
  	cin>>n>>m;
  	vector<int> miti(n);
 	for (int i=0;i<m;i++){
      for (int j=0;j<2;j++){
      	int path;
        cin>>path;
        miti.at(path-1)++;
      }
    } 
      for (int i=0;i<n;i++){
      	cout<<miti.at(i)<<endl;
      }
  
}



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

ll n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen("input.in", "r", stdin);
    ///freopen("output.out", "w", stdout);
    cin >> n;
    vector <ll> a (n + 1);
    for (ll i = 1; i <= n; ++i)
        cin >> a[i];
    vector <ll> dp (n + 1);
    dp[1] = 0, dp[2] = abs (a[1] - a[2]);
    for (ll i = 3; i <= n; ++i)
        dp[i] = min (dp[i - 2] + abs (a[i - 2] - a[i]), dp[i - 1] + abs (a[i - 1] - a[i]));
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 1792
n = input()
# 1, 2, 3, 4, 5...をリストに変換する方法
lst = list(map(int, input().split()))

answer = 0
tmp = 0
isFirst = True

for i in lst:
    if isFirst:
        isFirst = False
        tmp = i
    else:
        if tmp > i:
            answer += tmp - i
        else:
            tmp = i
print(answer)


Measured memory_bytes: 32152
#include <iostream>
#include <vector>
#include <array>
using namespace std;

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

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr int max_n = 200'000 + 5;

int n, q;
int cnts[max_n];

int hd[max_n]; // n : 頂点数
int nxt[2*max_n], to[2*max_n]; // 2*(n-1)+1 : 辺の個数+1
int edge_cnt;
inline void add_edge(const int u, const int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(const int cur = 0, const int parent = -1, const int cnt = 0)
{
    cnts[cur] += cnt;
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       const int child = to[e];
       if (child == parent) { continue; }
       dfs(child, cur, cnts[cur]);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        int p,x;
        cin >> p >> x;
        p--;
        cnts[p] += x;
    }

    dfs();

    rep(i, n)
    {
        cout << cnts[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 23880
//codeforces
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<bitset>
#include <climits>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1e9+7;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

class TrieNode{
    public:
    bool isword;
    char c;
    map<char,TrieNode*> m;
    string word;
    public:
    TrieNode(){}
    TrieNode(char ch){
        c=ch;
        isword=false;
    }
};

void insert(TrieNode* root,string word){
    TrieNode* temp=root;
    for(char c:word){
        if(temp->m.find(c)==temp->m.end())
            temp->m[c]=new TrieNode(c);
        temp=temp->m[c];
    }
    temp->isword=true;
    temp->word=word;
}


#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();





int MOD=1e9+7;

int main() {
    int h,w;
    cin>>h>>w;

    vector<vector<char>> mat(h,vector<char> (w));
    vector<vector<long long>> dp(h,vector<long long> (w)); 

    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>mat[i][j];
            

    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int r:{i,i+1}){
                int c=j;
                if(r==i)
                    c++;
                if(r<h && c<w && mat[r][c]=='.'){
                    dp[r][c]+=dp[i][j];
                    dp[r][c]%=MOD;
                }
            }
  
        }

    }

  	

    cout<<dp[h-1][w-1];

    return 0;
}


Measured memory_bytes: 12128
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int N, key = 0;
	char c[100];

	scanf("%d", &N);
	if (N == 0){
		printf("0\n");
		return 0;
	}
	else{
		while (N != 1){
			if (abs(N) % 2 == 1){
				c[key] = '1';
			}
			else{
				c[key] = '0';
			}
			if (N < 0 && abs(N) % 2 == 1) {
				N = abs(N / 2) + 1;
			}
			else{
				N = -1 * N / 2;
			}
			key++;
		}
		c[key] = '1';
	}

	REPR(i, key){
		printf("%c", c[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

vector<ll> lnln ;
void dfs(ll x, ll y){
    lnln.push_back(x) ;
    string s = to_string(x) ;
    ll f = s.size() ;
    if(f == y){
        return ;
    }
    char en = s[f - 1] ;
    string rr = s + en ;
    ll p = stoll(rr) ;
    for(ll j = -1; j <= 1 ; j++){
        if(en == '0' && j == -1){
            continue ;
        }
        else if (en == '9' && j == 1){
            continue ;
        }
        else {
            ll pf = p + j;
            dfs(pf, y) ;
        }
    } 
    return ;
}

int main() {
    ll k ;
    cin >> k ;
    for(ll i = 1; i <= 9; i++){
            dfs(i, 10) ;
    }
    sort(lnln.begin(), lnln.end()) ;
    cout << lnln[k - 1] << endl ;
}  

Measured memory_bytes: 5412
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
	int n,W;scanf("%d%d",&n,&W);
	vector<lli> dp(W+1,0);
	for(int i=0;i<n;i++)
	{
		int v,w;
		scanf("%d%d",&w,&v);
// as each of the weights can be accomaodated in the knapsack at any poistion 
// so add each weight once in every possible position 
		for(int wa=W-w;wa>=0;wa--)
		{
			dp[wa+w]=max(dp[wa+w],dp[wa]+v);
		}
	}
	
	lli ans;
	for(int i=0;i<=W;i++)
	{
		ans=max(ans,dp[i]);
	}
	
	
	printf("%lld",ans);
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll n,d; cin >> n >> d;
  vector<vector<ll>> x(n, vector<ll>(d));
  REP(i,n) REP(j,d) cin >> x[i][j];
  ll ans = 0;
  REP(i,n) REP(j,n) if(i<j){
    ll t = 0;
    REP(k,d){
      ll dx = (x[i][k]-x[j][k]);
      t += dx*dx;
    }
    //t = a**2?
    FOR(k,0,1000) if(t==k*k){
      ans++;
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int ans = (A - B);

  if (K % 2 == 0) {
    cout << ans << endl;
  } else {
    cout << -ans << endl;
  }

  return 0;
}


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

int main() {
    int n,K,i=1;
    cin >> K;
    n = 7 % K;
    set<int> S;
    while(S.count(n) == 0){
        S.insert(n);
        if(n == 0){
            cout << i << endl;
            return 0;
        }
        n = (n*10+7) % K;
        i++;
    }

    cout << -1 << endl;
    return 0;
}

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

int main() {
    string s;
    
    
    cin >> s;
    
    for (int i=0; i<s.length(); i++) {
        if (s[i]==',') {
            s[i]=' ';
        }
    }
    
    cout << s << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    class BIT():
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
    
    N=int(input())
    P=list(map(int,input().split()))
    P2=[(P[i],i) for i in range(N)]
    P2.sort(reverse=True)
    b=BIT(N)
    
    def nibutan(i,num,ok,ng):
        b_sum_i=b.sum(i)
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(b_sum_i,i,num,mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(b_sum_i,i,num,mid):
        if i>mid:
            if b_sum_i-b.sum(mid-1) >= num:
                return True
        else:
            if b.sum(mid)-b_sum_i >= num:
                return True
        return False
    
    ans=0
    for p in P2:
        x=b.sum(p[1])
        y=b.sum(N-1)
        if x>=1 or y-x>=1:
            s=nibutan(p[1],1,-1,p[1])
            t=nibutan(p[1],2,-1,p[1])
            u=nibutan(p[1],1,N,p[1])
            v=nibutan(p[1],2,N,p[1])
            if x>=1:
                ans+=p[0]*(s-t)*(u-p[1]) if s>-1 else 0
            if y-x>=1:
                ans+=p[0]*(v-u)*(p[1]-s) if u<N else 0
        b.add(p[1],1)
    
    print(ans)
    

if __name__ == '__main__':
    main()


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

int main(){
    string s;
    cin >> s;
    vector<int> vec(1000000);
    int cntr=0;
    int n=s.size();
    vector<int> ans(n+1);
    int tmp=0;
    ans[0]=0;
    for(int i=0; i<n-1; i++){
        if(s[i]=='<'&&s[i+1]=='<'){
            ans[i+1]=ans[i]+1;
        }
        if(s[i]=='<'&&s[i+1]=='>'){
            tmp=i+1;
            ans[i+1]=ans[i]+1;
        }
        if(s[i]=='>'&&s[i+1]=='>'){
            cntr++;
        }
        if(s[i]=='>'&&s[i+1]=='<'){
            ans[i+1]=0;
            for(int j=i+1; j>tmp+1; j--){
                ans[j-1]=ans[j]+1;
            }
            ans[tmp]=max(ans[tmp],cntr+1);
            cntr=0;
        }
    }
    if(s[n-1]=='<')ans[n]=ans[n-1]+1;
    else{
        ans[n]=0;
        for(int j=n; j>tmp+1; j--){
                ans[j-1]=ans[j]+1;
            }
            ans[tmp]=max(ans[tmp],cntr+1);
    }
    ll sum=0;
    for(int i=0; i<n+1; i++){
        sum+=ans[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 6788
#include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt =0;
  string s,t;cin>>s>>t;
  if(s[0]==t[0])cnt++;
  if(s[1]==t[1])cnt++;
  if(s[2]==t[2])cnt++;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    vector<vector<ll>> ar(700,vector<ll>(2500,0LL));
    repp(i,2500,3) ar[1][i] = 1;
    repp(i,700,2){
        repp(j,2500,3*i){
            ar[i][j] = ar[i][j-1] + ar[i-1][j-3];
            ar[i][j] %= mod;
        }
    }
    ll ans = 0LL;
    rep(i,700){
        ans += ar[i][n];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 16984
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-10
 
using namespace std;
typedef long long int ll;
 
double add(double a, double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
	return a+b;
}
 
struct P{
	double x, y;
	P() {}
	P(double x, double y): x(x), y(y){
	}
	P operator+ (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator- (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator* (double d){
		return P(x*d, y*d);
	}
	double dot(P p){
		return add(x*p.x, y*p.y);
	}
	double det(P p){
		return add(x*p.y, -y*p.x);
	}
};
 
bool on_seg(P p1, P p2, P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
 
P intersection(P p1, P p2, P q1, P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1) / (q2-q1).det(p2-p1));
}

double dist(P p1, P p2, P q){
	double d1=sqrt((p1-q).dot(p1-q)), d2=sqrt((p2-q).dot(p2-q));
	if(abs(p1.x-p2.x)<EPS && abs(p1.y-p2.y)<EPS){
		return d1;
	}
	P r=P((p2-p1).y, (p1-p2).x);
	P s=intersection(p1, p2, q, q+r);
	if(on_seg(p1, p2, s)){
		return sqrt((q-s).dot(q-s));
	}else{
		return min(d1, d2);
	}
}

double dist_segs(P p1, P p2, P q1, P q2){
	if((q2-q1).det(p2-p1)!=0){
		P r=intersection(p1, p2, q1, q2);
		if(on_seg(p1, p2, r) && on_seg(q1, q2, r)) return 0;
	}
	double d1=dist(p1, p2, q1), d2=dist(p1, p2, q2), d3=dist(q1, q2, p1), d4=dist(q1, q2, p2);
	double d=min(d1, min(d2, min(d3, d4)));
	return d;
}

int main()
{
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;
		P s, e;
		double sx, sy, ex, ey;
		scanf("%lf %lf %lf %lf", &sx, &sy, &ex, &ey);
		s=P(sx, sy), e=P(ex, ey);
		double d[50], h[50];
		for(int i=0; i<n; i++){
			double minx, miny, maxx, maxy;
			P p1, p2, p3, p4;
			scanf("%lf %lf %lf %lf %lf", &minx, &miny, &maxx, &maxy, &h[i]);
			p1=P(minx, miny), p2=P(maxx, miny), p3=P(maxx, maxy), p4=P(minx, maxy);
			if(minx<=s.x && s.x<=maxx && miny<=s.y && s.y<=maxy){
				d[i]=0;
				continue;
			}
			if(minx<=e.x && e.x<=maxx && miny<=e.y && e.y<=maxy){
				d[i]=0;
				continue;
			}
			d[i]=dist_segs(s, e, p1, p2);
			d[i]=min(d[i], dist_segs(s, e, p2, p3));
			d[i]=min(d[i], dist_segs(s, e, p3, p4));
			d[i]=min(d[i], dist_segs(s, e, p4, p1));
		}
		double r1=0, r2=1000.0;
		for(int t=0; t<100; t++){
			double r=(r1+r2)/2.0;
			bool e=0;
			for(int i=0; i<n; i++){
				if(h[i]>r){
					if(d[i]<r) e=1;
				}else{
					double d0=sqrt(r*r-(r-h[i])*(r-h[i]));
					if(d[i]<d0) e=1;
				}
			}
			if(e==0){
				r1=r;
			}else{
				r2=r;
			}
		}
		printf("%.6lf\n", r1);
	}
	return 0;
}


Measured memory_bytes: 3140
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define int long long int
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD = 1000000007;
const ll mod=1000000006;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
/*
 shuffle(x,x+n,rng) // shuffling elements of x in random order
 */

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n];long double ans,sum=0.0;
    for(int i=0;i<n;i++)
    { cin>>a[i];
        sum=sum+(long double)1/a[i];
    }
    ans=1.0/sum;
    cout<<ans<<endl;
    
    return 0;
}







Measured memory_bytes: 256
n=int(input())
d={}
mx=0
for i in range(n):
  s=input()
  if s not in d:
    d[s]=1
  else:
    d[s]+=1
    if d[s]>mx:
      mx=d[s]
l=[]
if mx==0:
  mx=1
for i in d:
  if d[i]==mx:
    l.append(i)


l.sort()
for i in range(len(l)):
  print(l[i])

Measured memory_bytes: 32096
N, A, B = gets.chop.split.map(&:to_i)
S = gets.chomp
n = S.length
t = 1
b = 0
for i in 0..n - 1 do
  if S[i] == "b"
    b += 1
    if t <= (A + B) && b <= B
      t += 1
      puts "Yes"
    else
      puts "No"
    end
  elsif S[i] == "a"
    if t <= (A + B)
      t += 1
      puts "Yes"
    else
      puts "No"
    end
  else
     puts "No"
  end
end

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int n, Q;
  string s;
  cin >> n >> Q >> s;

  vector<char> t(Q), d(Q);
  rep(i, 0, Q){
    cin >> t[i] >> d[i];
  }

  reverse(all(t));
  reverse(all(d));

  int l = 0, r = n-1;
  rep(i, 0, Q){
    if(l < n and t[i] == s[l] and d[i] == 'L') l++;
    if(r >= 0 and t[i] == s[r] and d[i] == 'R') r--;
    if(l > 0 and t[i] == s[l-1] and d[i] == 'R') l--;
    if(r < n-1 and t[i] == s[r+1] and d[i] == 'L') r++;
  }

  cout << max(0LL, r-l+1) << endl;

  return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,T;
    cin >>N>>T;
    vector<ll>A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll mn=A[0];
    ll ans=0;
    ll md=0;
    rep(i,N){
        if(mn>A[i]){
            mn=A[i];
        }else if(A[i]-mn==md && md!=0){
            ans++;
        }else if(A[i]-mn>md){
            md=A[i]-mn;
            ans=1;
        }
    }
   

    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4048