akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// 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) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

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

  vec dp(n, INF);

  for (int i = 0; i < n; i++) {
    int tmp = (int)(lower_bound(ALL(dp), a[i]) - dp.begin());
    dp[tmp] = min(dp[tmp], a[i]);
  }

  cout << (int)(lower_bound(ALL(dp), INF) - dp.begin()) << endl;

  return 0;
}



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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  vector<int> primes{2};  
  bool isprime[100001];
  fill_n(isprime, 100001, true);
  isprime[0] = isprime[1] = false;  
  for ( int i = 3; i < 100001; i+=2 ) {
    for ( int j = 3; j <= sqrt(i); j++ ) {
      if ( i%j == 0 ) {
	isprime[i] = false;
	break;	
      }
    }
  }

  for ( int i = 3; i < 100001; i+=2 ) {
    if ( isprime[i] ) primes.emplace_back(i);    
  }
  int sz = primes.size();

  int m, a, b;
  while ( cin >> m >> a >> b, m ) {
    int ma = 0;
    int ap, aq;    
    for ( int i = 0; i < sz; i++ ) {
      int p = primes[i];
      int tmp = min(m/p, (int)((double)p*b/a));      
      
      auto it =  upper_bound(primes.begin(), primes.end(), tmp);      
      if ( it == primes.begin() ) continue;
      int q = *(it-1);      
      if ( (double)a/b > (double)p/q || (double)p/q > 1.0 ) continue;
      if ( ma < p*q ) {
	ma = p*q;
	ap = p;
	aq = q;	
      }
    }

    cout << ap << " " << aq << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long int a[n]={0};
	int b[n];
	for(int i=0;i<=n-1;i++){
		cin>>b[i];
		a[b[i]-1]++;
	}
	long long int sum=0;
	for(int j=0;j<=n-1;j++){
		sum += ((a[j])*(a[j]-1))/2;
	}
	for(int k=0;k<=n-1;k++){
		cout<<sum-(((a[b[k]-1])*(a[b[k]-1]-1))/2)+(((a[b[k]-1]-1)*(a[b[k]-1]-2))/2)<<endl;
	}
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a%2==b%2)printf("%lld\n",(b-a)/2);
		else printf("%lld\n",min(a,n-b+1)+(b-a-1)/2);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] + [int(a) for a in input().split()]
B = [0] + [int(a) for a in input().split()]
C = [0] + [int(a) for a in input().split()]

previous = -1
satisfaction = 0

for a in A[1:]:
    satisfaction += B[a]
    if previous == a-1:
        satisfaction += C[a-1]
    previous = a

print(satisfaction)


Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    long x, y;
    scan(x, y);

    writeln(abs(x - y) < 2 ? "Brown" : "Alice");
}


long dsum(long b, long n) {
    return n < b ? n : dsum(b, n / b) + (n % b);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const int LGN = 63;
const int Z = 1e9+7;

int main() {
    ios::sync_with_stdio(false);

    ll l, r;
    cin >> l >> r;

    int p3[LGN];
    for (int i = 0; i < LGN; i++) {
        p3[i] = i == 0 ? 1 : 3ll * p3[i-1] % Z;
    }

    int dp[LGN+1][5];
    dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = 1;
    for (int i = 1; i <= LGN; i++) {
        bool bl = l >> (i - 1) & 1, br = r >> (i - 1) & 1;
        if (!bl && !br) {
            dp[i][0] = dp[i-1][0];
            dp[i][1] = dp[i-1][1];
        } else if (!bl && br) {
            dp[i][0] = (dp[i-1][2] + dp[i-1][4]) % Z;
            dp[i][1] = (0ll + dp[i-1][3] + dp[i-1][4] + dp[i-1][1]) % Z;
        } else if (bl && !br) {
            dp[i][0] = dp[i][1] = 0;
        } else {
            dp[i][0] = dp[i][1] = dp[i-1][1];
        }

        if (!bl) {
            dp[i][2] = (dp[i-1][2] + p3[i-1]) % Z;
            dp[i][3] = (2ll * dp[i-1][3] + p3[i-1]) % Z;
        } else {
            dp[i][2] = dp[i][3] = dp[i-1][3];
        }

        if (!br) {
            dp[i][4] = dp[i-1][4];
        } else {
            dp[i][4] = (2ll * dp[i-1][4] + p3[i-1]) % Z;
        }
    }

    cout << dp[LGN][0] << endl;

    return 0;
}


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

#define pb push_back
#define mp make_pair

typedef long long ll;

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

  string t[] = {"dream", "dreamer", "erase", "eraser"};

  int pos = s.size();
  for(;pos > 0;){
    bool flag = false;
    for(int j = 0; j < 4; j++){
      if(pos-(int)t[j].size() >= 0){
        if(s.substr(pos-t[j].size(), t[j].size()) == t[j]){
          flag = true;
          pos -= t[j].size();
          break;
        }
      }
    }
    if(!flag){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, 0, n)
    cin >> a[i];
  
  vi mxlis(0), mnlis(0);
  
  rep(i, 1, n){
    if(a[i] >= a[i-1]){
      if(i == n-1)
        mxlis.push_back(i);
    }
    else
      mxlis.push_back(i-1);
      
    if(a[i] <= a[i-1]){}
    else
      mnlis.push_back(i-1);
  }
  
  
  vi operate(n, 0);
  rep(i, 0, mxlis.size()){
    operate[mxlis[i]] = 1;
  }
  rep(i, 0, mnlis.size()){
    operate[mnlis[i]] = -1;
  }
  
  ll money = 1000, stock = 0;
  
  rep(i, 0, n){
    int op = operate[i];
    if(op == 0)
      continue;
    if(op == -1){
      stock += money/a[i];
      money -= (money/a[i]) * a[i];
    }
    if(op == 1){
      money += stock*a[i];
      stock = 0;
    }
  }
    
  cout << money << endl;
  
  return 0;
  
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10**7)

import sys
input = sys.stdin.readline

n = int(input())
al = list(map(int,input().split()))

from collections import defaultdict
G = defaultdict(list)

for _ in range(n-1):
    u,v = map(int,input().split())
    G[u-1].append(v-1)
    G[v-1].append(u-1)

from bisect import bisect
ansl = [0 for i in range(n)]
dp = [float("inf") for _ in range(n+1)]
dp[0] = -1
used = [0 for i in range(n)]
used[0] = 1


stack = []
def dfs(pos):
    idx = bisect(dp, al[pos] - 1)
    stack.append((idx, dp[idx]))
    dp[idx] = min(al[pos], dp[idx])
    ansl[pos] = bisect(dp, 10**18) - 1
    for v in G[pos]:
        if used[v] == 0:
            used[v] = 1
            dfs(v)
            idx, k = stack.pop()
            dp[idx] = k


dfs(0)
flag = False
for i in range(n):
    print(ansl[i])




Measured memory_bytes: 358420
#include <bits/stdc++.h>
//#pragma GCC optimize ("Ofast")

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=0;

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int a,b; cin >> a >> b;
    cout << a*b << '\n';
}

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

words = set()

flag = True
for i in range(N):
    word = input()
    if i == 0:
        words.add(word)
        prev_word = word
    else :
        if prev_word[-1] != word[0]:
            flag = False
        else :          
            words.add(word)
            prev_word = word
            
if flag:
    if len(words) == N :
        print('Yes')
    else :
        print('No')
else :
    print('No')

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	char temp,str[100005];
	while(~scanf("%s",str))
	{
		int r=0,s=0,len=strlen(str);
		temp=str[0];
		for(int i=0;i<len;i++)
		{
			if(temp!=str[i])
			{
				r++;
				temp=str[i];
			}
		}
		temp=str[len-1];
		for(int i=len-2;i>=0;i--)
		{
			if(temp!=str[i])
			{
				s++;
				temp=str[i];
			}
		}
		cout<<min(r,s);
	}
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = 0
b = 0
c = 0
d = 0
 
for i in range(n):
    S = str(input())
    if S == 'AC':
        a += 1
    if S == 'WA':
        b += 1
    if S == 'TLE':
        c += 1
    if S == 'RE':
        d += 1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define for_range(i, a, b) for (int i = (a); i < (b); i++)
#define for_range_rev(i, a, b) for (int i = (b)-1; i >= (a); i++)
using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using u32 = uint_fast32_t;
const u64 MOD = 1'000'000'007;
// const u64 MOD = 998'244'353;

int ceil_pow2(int n) {
    int x = 0;
    while ((1u << x) < (u32)(n)) x++;
    return x;
}

i64 floor_sum(i64 n, i64 m, i64 a, i64 b) {
    i64 r = 0;
    if (a >= m) {
        r += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        r += n * (b / m);
        b %= m;
    }
    i64 y = (a * n + b) / m, x = (y * m - b);
    if (y == 0) return r;
    r += (n - (x + a - 1) / a) * y;
    r += floor_sum(y, a, m, (a - x % a) % a);
    return r;
}

void solve() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n, m, a, b) << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}

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

int main() {
    double a, b;
    cin >> a >> b;
    cout << round((a + b) / 2.0) << endl;

    return 0;
}

Measured memory_bytes: 3876
#include <stdio.h>

int main(void){
    int i, j;
    int a[3], b[3];
    int c[3][3];
    for(i = 0;i < 3;i++) for(j = 0;j < 3;j++) scanf("%d", &c[i][j]);
    a[0] = c[0][0];
    a[1] = c[1][0];
    a[2] = c[2][0];
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    if(c[1][1] == a[1] + b[1] && c[1][2] == a[1] + b[2] && c[2][1] == a[2] + b[1] && c[2][2] == a[2] + b[2]) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

int N;
int main(){
    while(true){
        cin >> N;
        if(N==0) return 0;
        string S;
        vector<string> v;
        for(int i=0;i<N;i++){
            cin >> S;
            string T = "";
            for(int j=0;j<S.size();j++){
                if(j==0) T += S[j];
                else if(S[j-1]=='a' || S[j-1]=='i' || 
                S[j-1]=='u' || S[j-1]=='e' || S[j-1]=='o') T += S[j];
            }
            v.push_back(T);
        }
        int ans = -1;
        for(int i=1;i<=50;i++){
            set<string> s;
            for(auto x:v){
                s.insert(x.substr(0,i));
            }
            if(s.size()==N){
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
#define pi acos(-1)
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    deci(10);
    ll r;
    cin >> r;
    cout << 2*pi*r<<"\n";


} 

Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <cstdio>
#include <deque>
#include <algorithm>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <stack>

using namespace std;
int n, k;
int c[100001];
pair<long long, int> a[100001];
vector<pair<long long, int>> v;
priority_queue<pair<long long, int>> q;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].second >> a[i].first;
	}

	long long ans = 0;
	sort(a, a + n);
	long long s = 0;
	for (int i = n - 1; i >= 0; i--) { // a.second == 종류 a.first = 맛
		if (c[a[i].second] == 0) {
			if (s < k) {
				c[a[i].second] = 1;
				ans += a[i].first;
				s += 1;
				v.push_back({ a[i].first,a[i].second }); // 맛 종류
			}
		}
		else {
			q.push({ a[i].first, a[i].second }); // ( 맛 , 종류 )
		}
	}
	ans += s * s;
	int t = s;

	while (t < k) {
		ans += q.top().first;
		c[q.top().second] += 1;
		v.push_back({ q.top().first,q.top().second });
		q.pop();
		t += 1;
	}
	sort(v.begin(), v.end());
	long long cnt = ans;
	for (int i = 0; i < v.size(); i++) {
		if (q.empty() || v[i].first > q.top().first)break;
		c[v[i].second] -= 1;
		if (c[v[i].second] == 0) {
			c[q.top().second] += 1;
			if (c[q.top().second] == 1) { // 처음 1된경우
				cnt = cnt - v[i].first + q.top().first;
			}
			else { // 원래 1보다 컸던 경우
				cnt = cnt - s * s - v[i].first + q.top().first + (s - 1)*(s - 1);
				s -= 1;
			}
		}
		else { // 1이 안됨 빼져도
			c[q.top().second] += 1;
			if (c[q.top().second] == 1) { // 처음 1된경우
				cnt = cnt - s * s - v[i].first + q.top().first + (s + 1)*(s + 1);
				s += 1;
			}
			else { // 원래 1보다 컸던 경우
				cnt = cnt - v[i].first + q.top().first;
			}
		}
		q.pop();
		ans = max(cnt, ans);
	}

	cout << ans << '\n';
}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, C, A[410], B[410]; 
	long long MOD = 1000000007; 
	long long power[410][410] = {}; // i^j mod
	long long POWER[410][410] = {}; // i^j のiについての累積和 mod
	for(int i = 1; i <= 400; i++){
		power[i][0] = 1; POWER[i][0] = i; 
	}
	for(int i = 1; i <= 400; i++){
		for(int j = 1; j <= 400; j++){
			power[i][j] = power[i][j-1] * i % MOD; 
			POWER[i][j] = POWER[i-1][j] + power[i][j];
			if(POWER[i][j] >= MOD) POWER[i][j] -= MOD;  
		}
	}
	cin >> N >> C; 
	for(int i = 1; i <= N; i++) cin >> A[i]; 
	for(int i = 1; i <= N; i++) cin >> B[i]; 
	long long dp[410][410] = {}; // dp[i人目まで見て][ちょうどj個配る]
	dp[0][0] = 1; 
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= C; j++){
			for(int k = 0; k <= j; k++){
				long long tmp = (POWER[B[i]][k] - POWER[A[i]-1][k] + MOD) % MOD; 
				dp[i][j] += tmp * dp[i-1][j-k] % MOD; 
			}
			dp[i][j] %= MOD; 
		}
	}
	cout << dp[N][C] << endl; 
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}


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

	vector<int> a(n);

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

	int ans;
	for (int i = 0; i < n; i++){
		if (i == 0){
			ans = gcd(a[i], a[i + 1]);
			i++;
		}
		else {
			ans = gcd(ans, a[i]);
		}
	}

	cout << ans << endl;
}


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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<bool> a(n,false);
    rep(i,k){
        ll d; cin >> d;
        rep(j,d){
            ll e; cin >> e;
            e--;
            a[e]=true;
        }
    }
    ll ans=0;
    rep(i,n){
        if(a[i]==false) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
s = input()
K = int(input())

N = len(s)
Ans = ["z"*5000]*5
for i in range(N):
    for j in range(i,min(N,i+5)):
        tmp = s[i:j+1]
        for k in range(5):
            if Ans[k] > tmp:
                if not (tmp in Ans):
                    for l in range(4-k):
                        Ans[4-l] = Ans[3-l]
                    Ans[k] = tmp
                    break       
print(Ans[K-1])

Measured memory_bytes: 40432
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = i64(1e9) + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, m;
    cin >> n >> m;
    if(!n){
        return false;
    }
    vector<vector<i64>> dist_l(n, vector<i64>(n, INF));
    vector<vector<i64>> dist_s(n, vector<i64>(n, INF));
    for(int i = 0; i < n; ++i){
        dist_l[i][i] = 0;
        dist_s[i][i] = 0;
    }
    for(int i = 0; i < m; ++i){
        int x, y;
        i64 t;
        string s;
        cin >> x >> y >> t >> s;
        --x, --y;
        auto& dist = (s == "S" ? dist_s : dist_l);
        chmin(dist[x][y], t);
        chmin(dist[y][x], t);
    }

    for(int l = 0; l < 10; ++l)
        for(int k = 0; k < n; ++k)
            for(int i = 0; i < n; ++i)
                for(int j = 0; j < n; ++j){
                    chmin(dist_l[i][j], dist_l[i][k] + dist_l[k][j]);
                    chmin(dist_s[i][j], dist_s[i][k] + dist_s[k][j]);
                }

    int r;
    cin >> r;
    int v;
    cin >> v;
    --v;
    vector<i64> dp(n, INF);
    dp[v] = 0;

    for(int _ = 0; _ < r - 1; ++_){
        vector<i64> nex(n, INF);
        int prev = v;
        cin >> v;
        --v;

        for(int i = 0; i < n; ++i)
            chmin(nex[i], dp[i] + dist_l[prev][v]);
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                chmin(nex[j], dp[i] + dist_l[prev][i] + dist_s[i][j] + dist_l[j][v]);
        dp = move(nex);
    }
    i64 ans = INF;
    for(int j = 0; j < n; ++j)
        chmin(ans, dp[j]);
    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define SZ(a) ((int)a.size())
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl
	
void solve(int x) {
	if (x <= 4) {
		printf("2 %d\n", x);
		forn(i, x) {
			printf("1 2 %d\n", i);
		}
		return;
	}
	int n = 0;
	int t = x;
	int bitcnt = 0;
	while(t) {
		if (t & 1) bitcnt++;
		t >>= 1;
		n++;
	}
	// printf("\n%d %d %d\n", x, n, bitcnt);
	if (bitcnt == 1) {
		printf("%d %d\n", n - 1, n * 2 - 2);
	} else {
		int m = n * 2 - 2 + bitcnt;
		if (x & 2) {
			m += 1;
		}
		printf("%d %d\n", n, m);	
	}
	printf("1 2 1\n");
	printf("1 2 3\n");
	forn(i, n - 2) {
		printf("%d %d %d\n", i + 1, i + 2, 0);
		printf("%d %d %d\n", i + 1, i + 2, (2 << i));
	}
	t = x;
	int p = 1;
	int s = 0;
	while(t && bitcnt != 1) {
		if (t & 1) {
			if (p == 1) {
				printf("1 %d 0\n", n);
				s++;
			}
			else if (p == 2) {
				printf("1 %d %d\n", n, s);
				printf("1 %d %d\n", n, s + 1);
				s += 2;
			}
			else {
				printf("%d %d %d\n", p - 1, n, s);
				s += 1 << (p-1);
			}
		}
		t >>= 1;
		p++;
	}
}

int main(int argc, char *argv[]) {
//	freopen("in.txt", "r", stdin);
	int l;
	while (scanf("%d", &l) != EOF) {
		solve(l);
	}
//	printf("%d\n", (1<<19)+(1<<18)-1);
//	cout << bitset<20>(786431) << endl;
//	cout << bitset<20>(1000000) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;

    int h, w;
    cin >> h >> w;

    string s[h];
    for(int i=0; i < h; i++){
        cin >> s[i];
    }
    
    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){
            int temp = 0;
            if(s[i].at(j) == '.'){
                if(i-1 >= 0 && j-1 >= 0){
                    temp += (s[i-1].at(j-1) == '#');
                }
                if(i-1 >= 0){
                    temp += (s[i-1].at(j) == '#');
                }
                if(i-1 >= 0 && j+1 < w){
                    temp += (s[i-1].at(j+1) == '#');
                }

                if(j-1 >= 0){
                    temp += (s[i].at(j-1) == '#');
                }
                    temp += (s[i].at(j) == '#');
                if(j+1 < w){
                    temp += (s[i].at(j+1) == '#');
                }

                if(i+1 < h && j-1 >= 0){
                    temp += (s[i+1].at(j-1) == '#');
                }
                if(i+1 < h){
                    temp += (s[i+1].at(j) == '#');
                }
                if(i+1 < h && j+1 < w){
                    temp += (s[i+1].at(j+1) == '#');
                }
                s[i].at(j) = std::to_string(temp).at(0);
            }
        }
    }

    for(int i=0; i < h; i++){
        cout << s[i] << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct log{
    int start;
    int end;
    int pc_number;
    int student_number;
    bool check;
};


int main() {
    while (1) {
        int N,M;
        vector<log> log_data;
        
        cin >> N >> M;
        if((N==0)||(M==0)) break;
        int r;
        cin >> r;
        while(r--){
            int t,n,m,s;
            cin >> t >> n >> m >> s;
            if(s==1){
                log temp = {t,0,n,m,false};
                log_data.push_back(temp);
            }
            else{
                vector<log>::iterator it=log_data.begin();
                while(1){
                    if(((it->pc_number==n)&&(it->student_number==m))&&(it->check==false)) {
                        it->end = t;
                        it->check = true;
                        break;
                    }
                    it++;
                }
            }
        }
        
        int q;
        cin >> q;
        while(q--){
            int t_s,t_e,m,total=0;
            cin >> t_s >> t_e >> m;
            
            vector<log>::iterator it;
            int i=t_s;
            while(i < t_e){
                it = log_data.begin();
                while(it != log_data.end()){
                    if(it->student_number == m){
                        if((it->start <= i)&&(i < it->end)){
                            total++;
                            break;
                        }
                    }
                    it++;
                }
            i++;
            }
            cout << total <<endl;
        }
    
    }
    
}

Measured memory_bytes: 1236
//#pragma GCC optimize("O3")
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}

double dist(pair<double,double> p1, pair<double,double> p2)
{
	return pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2);
}
signed main()
{
    
	int n;cin>>n;
	vector<pair<double,double>> inp(n);
	double x=0,y=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>inp[i].x>>inp[i].y;
		x+=inp[i].x;
		y+=inp[i].y;
	}
	x=x/n;
	y=y/n;
	double p=0.01;
	double d;
	for(int i=0;i<300000;++i)
	{
		pair<double,double> most_dist=inp[0];
		d=dist(inp[0],{x,y});
		for(int i=1;i<n;++i)
		{
			if(dist(inp[i],{x,y})>d)
			{
				most_dist=inp[i];
				d=dist(inp[i],{x,y});
			}
		}
		x+=((most_dist.x)-x)*p;
		y+=(most_dist.y-y)*p;
		p*=0.9999;
	}
	printf("%.9lf",sqrt(d));
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

btw = []
for i in range(M):
  if i == M - 1:
    break
  else:
    btw.append(X[i+1] - X[i])
btw = sorted(btw, reverse=True)

ans =0
for e in btw[N-1:]:
  ans += e
 
print(ans)

Measured memory_bytes: 13968
def Euclid(m,n):
    while True:
        p = m%n
        m = n
        n = p
        if p == 0:
            return m
            break

K = int(input())
sum = 0

sub1_sum = 0
for i in range(3,K+1):
    for j in range(2,i):
        temp = Euclid(i,j)
        for k in range(1,j):
            sub1_sum += Euclid(temp,k)

sum += sub1_sum*6

sum += round(K*(K+1)/2)

sub2_sum = 0
for i in range(2,K+1):
    for j in range(1,i):
        sub2_sum += Euclid(i,j)

sum += sub2_sum*6
print(sum)


Measured memory_bytes: 9212
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}



int main(){
    int N;
    cin >> N;
    LL a[N];
    REP(i,N) cin >> a[i];
    sort(a,a+N);
    LL ans=0;
    LL pos=0;
    LL tmp=0;
    LL count=0;
    while(pos<N){
        tmp=a[pos];
        count=0;
        for(int i=pos;i<N;++i){
            if(a[i]==tmp){
                ++count;
                ++pos;
            }
            else{
                break;
            }
        }
        if(count>=tmp){
            ans+=count-tmp;
        }
        else{
            ans+=count;
        }
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    string s;
    cin >> s;
    auto t = s.length()+1;
    int ans = INF<int>;
    for (char i = 'a'; i <= 'z'; ++i) {
        string ss = "?" + s;
        if(s.find(i) == string::npos) continue;
        int a = 0;
        while(true) {
            bool flag = true;
            for (int j = 0; j < t; ++j) {
                if (ss[j] != i && ss[j] != '?') flag = false;
            }
            if (flag) {
                break;
            }else {
                for (int j = static_cast<int>(t - 2); j >= 0; --j) {
                    if(ss[j] == '?') ss[j+1] = ss[j];
                    if(ss[j] == i) ss[j+1] = ss[j];
                }
                a++;
            }
        }
        ans = min(a, ans);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <cmath>
#include <map>
using namespace std;

bool isLeap(const int y){
	if(!(y%400)) return true;
	if(!(y%100)) return false;
	if(!(y%4)) return true;
	return false;
}

int main(int,char**){
	int a,b;
	bool ini(0);
	while(std::cin >> a>> b){
		if(!a&&!b) break;
		if(ini) cout <<endl;
		else ini=true;
		
		bool ex(0);
		for(int i(a);i<=b;++i){
			if(isLeap(i)) {
				cout << i <<endl;
				ex = true;
			}
		}
		if(!ex) cout << "NA" <<endl;
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
	int x;
	scanf("%d", &x);
	
	bool X[110001];
	
	for(int i = 0; i < 110001; i++){
		X[i] = true;
	}
	
	for(int i = 2; i < x * 3 && i < 110001; i++)
	{
		if(X[i] == true){
			for(int j = i + 1; j < 110001; j++){
				if(j % i == 0){
					X[j] = false;
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = x; i < 110001; i++){
		if(X[i]){
			ans = i;
			break;
		}
	}
	
	printf("%d\n", ans);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10 , OO = 0x3f3f3f3f ;
const int mod = 1e9 + 7;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n , m , k;

int main()
{
   // startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    /*
        3 4 240
        60 90 120 -- SumA : 60 150 270
        80 150 80 150 -- SumB : 0 80 230 310 460
                                0 1   2   3   4

    */
    scanf("%d %d %d", &n , &m , &k);
    vector < ll > prefA(n + 1) , prefB(m + 1);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%lld" , &prefA[i]);
        prefA[i] += prefA[i - 1];
    }

    for(int i = 1 ; i <= m ; ++i){
        scanf("%lld" , &prefB[i]);
        prefB[i] += prefB[i - 1];
    }

    // we want to count how many i , j (0 <= i <= n , 0 <= j <= m) such that
    // a[j] + b[j] <= k -- b[j] <= k - a[j]

    int ans = 0;
    for(int cntA = 1 ; cntA <= n ; ++cntA){
        if(prefA[cntA] > k)
            break;
        ll bj = k - prefA[cntA];
        int cntB = upper_bound(prefB.begin() , prefB.end() , bj) - prefB.begin() - 1;
        ans = max(ans , cntA + cntB);
    }
    for(int cntB = 1 ; cntB <= m ; ++cntB){
        if(prefB[cntB] > k)
            break;
        ll aj = k - prefB[cntB];
        int cntA = upper_bound(prefA.begin() , prefA.end() , aj) - prefA.begin() - 1;
        ans = max(ans , cntA + cntB);
    }

    printf("%d\n" , ans);

    return 0;
}

Measured memory_bytes: 6312
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[20][20],d[(1<<16)],F[(1<<16)];
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cin>>a[i-1][j-1];
        }
    }
    int t=(1<<n)-1;
    for(int i=1;i<=t;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(((1&(i>>j))==1)&&((1&(i>>k))==1))d[i]+=a[j][k];
            }
        }
        //cout<<d[i]<<'\n';
    }
    for(int i=1;i<=t;i++)
    {
        for(int j=i;j>=0;j=((j-1)&i))
        {
            F[i]=max(F[i],F[j]+d[i^j]);
            if(j==0)break;
        }
    }
    cout<<F[t];
}


Measured memory_bytes: 4672
DATE = input()
a = int(DATE[0:2])
b = int(DATE[2:4])
if 1<=a<=12 and 1<=b<=12:
    print("AMBIGUOUS")
elif 1<=a<=12:
    print("MMYY")
elif 1<=b<=12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, k;
  cin >> n >> k;
  ll ans;
  int a = n / k;
  ans = (ll)a * a * a;
  if(k % 2 == 0) {
    int b = (n * 2) / k - a;
    ans += (ll)b * b * b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:f64, a:[i64;5]};
    let m:i64 = *a.iter().min().unwrap();

    println!("{}", f64::ceil(n as f64 / m as f64) as i64 + 4);

}

Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll A,V,B,W,T; cin>>A>>V>>B>>W>>T;
  if(W>=V&&A!=B) {cout<<"NO"<<endl; return 0;}
  if(abs(A-B)<=(V-W)*T) {cout<<"YES"<<endl; return 0;}
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 3624
n, m, l =map(int, input().split())

A = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(m)]
C = []

for i in range(n):
    C.append([])

for i in range(n):
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += A[i][k]*B[k][j]
        C[i].append(sum)
for i in range(n):
    print(*C[i])


Measured memory_bytes: 7060
s = input()
first_A = 200000
last_Z = 0

for index, word in enumerate(s):
    if word == "A":
        if first_A >= index:
            first_A = index
    if word == "Z":
        if last_Z <= index:
            last_Z = index

ans = last_Z - first_A + 1
print(ans)

Measured memory_bytes: 3516
use std::cmp::{max, min};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let c: i32 = sc.read();
    let d: i32 = sc.read();
    println!("{}", max(0, min(b,d)-max(a,c)));
}

// Thanks, kenkoooo(https://kenkoooo.hatenablog.com/entry/2019/05/07/101033)
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 4352
N = int(input())
D = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
    if D[i][0] == D[i][1]:
        if cnt == 2:
            print("Yes")
            exit()
        else:
            cnt += 1
    else:
        cnt = 0

print("No")

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    string S;
    cin >> S;
    S += "S";
    int ret = 0;
    int cnt = 0;
    for(int i = 0;i < 4;i++) {
        if(S.at(i) == 'R') {
            cnt++;
        }
        else {
            chmax(ret,cnt);
            cnt = 0;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int gcd(int n, int m){
  if(m==0){
    return n;
  }else if(n==0){
    return m;
  }else if(n>=m){
    return gcd(n%m,m);
  }else{
    return gcd(n,m%n);
  }
}


int main(){
  
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
      cin >> A[i];
  }
//  cout << gcd(5,4) << endl;

  int ans = 1;

  int front[N];

  front[0] = A[0]; 
  for(int i=0;i<N-1;i++){
    front[i+1] = gcd(front[i], A[i+1]);
  }


  int back[N];

  back[N-1] = A[N-1];
  for(int i=N-1;i>0;i--){
    back[i-1] = gcd(back[i],A[i-1]);
  }


  ans = max(ans, back[1]);
  ans = max(ans, front[N-2]);

  for(int i=0;i<N-2;i++){
    int l = gcd(front[i], back[i+2]);
    ans = max(ans, l);
  }

  cout << ans <<endl;

  return 0;
}








Measured memory_bytes: 1408
N = gets.to_i
hs = gets.chomp.split.map(&:to_i)

def segments(hs, h)
  e, s = false, 0
  N.times { |i|
    if hs[i] >= h && !e
      s += 1
      e = true
    end
    e = false if hs[i] < h && e
  }
  s
end

ans = 0
hs.max.times { |i|
  ans += segments(hs, i + 1)
}
p ans

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

int main() {
    int64_t N, x;
    std::cin >> N >> x;

    int64_t a, prev = 0, cnt = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        if (i == 0) {
            const int64_t sub = std::max<int64_t>(0, a - x);
            cnt += sub;
            prev = a - sub;
        } else {
            const int64_t sub = std::max<int64_t>(0, (a + prev) - x);
            cnt += sub;
            prev = a - sub;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	ll n;
	cin >> n;
	ll m = 0, a = 0, r = 0, c = 0, h = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s[0] == 'M')
			m++;
		if (s[0] == 'A')
			a++;
		if (s[0] == 'R')
			r++;
		if (s[0] == 'C')
			c++;
		if (s[0] == 'H')
			h++;
	}
	ll ans = 0;
	ll d[5];
	d[0] = m;
	d[1] = a;
	d[2] = r;
	d[3] = c;
	d[4] = h;
	for (int  i = 0 ; i < 5 ; i++){
		for (int j = i+1 ; j < 5 ; j++){
			for (int k = j+1 ; k < 5 ; k++){
				ans += d[i]*d[j]*d[k];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e9 + 7 ;

int main(){ skorost ;

	ll k = 1 ;

	ll n ;

	cin >> n ;

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

		k *= i ;

		k %= N ;
 
	}

	cout << k << endl ;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int a[maxn];
int main()
{
    int n,m,x,k,couts=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>x,a[i]=a[i-1]+x;
        for(int i=1;i<=n;i++)
        {
            if(a[i]<=k)
                couts++;
        }
        cout<<couts+1<<endl;

    return 0;
}


Measured memory_bytes: 256