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

const int mod=1e9+7,inf=(1<<30);
typedef long long LL;

inline int in()
{
	char ch=getchar();
	int f=1,o=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {o=(o<<1)+(o<<3)+ch-'0';ch=getchar();}
	return f*o;
}

const int N=400010;
int n,m,w[N<<1],col[N<<1];

void build(int l,int r,int rt)
{
	if(l==r) return void(w[rt]=l);
	int mid=l+r>>1;
	build(l,mid,rt<<1);
	build(mid+1,r,rt<<1|1);
	w[rt]=max(w[rt<<1],w[rt<<1|1]);
}

void add(int L,int R,int l,int r,int rt)
{
	if(L<=l&&R>=r) {w[rt]++;col[rt]++;return;}
	int mid=l+r>>1;
	if(L<=mid) add(L,R,l,mid,rt<<1);
	if(R>mid)  add(L,R,mid+1,r,rt<<1|1);
	w[rt]=col[rt]+max(w[rt<<1],w[rt<<1|1]);
}

int query(int L,int R,int l,int r,int rt)
{
	if(L<=l&&R>=r) return w[rt];
	int mid=l+r>>1,ret=0;
	if(L<=mid) ret=max(ret,query(L,R,l,mid,rt<<1));
	if(R>mid)  ret=max(ret,query(L,R,mid+1,r,rt<<1|1));
	return col[rt]+ret;
}

vector<int> a[N];

int main()
{
	n=in(),m=in();
	for(int i=1;i<=n;i++)
	{
		int x=in(),y=in();
		a[x].push_back(y);
	}
	int ans=n-m;
	build(0,m+1,1);
	for(int i=0;i<=m;i++)
	{
		for(auto x:a[i]) add(0,x,0,m+1,1);
		ans=max(ans,query(i+1,m+1,0,m+1,1)-i-m-1);
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 18432
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
	int N, D, X[10][10], ans = 0;
	
  	cin >> N >> D;
  
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}
	
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			double d = 0;
			
			for (int k = 0; k < D; k++) {
				d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			
			d = sqrt(d);
			
			if (d == floor(d)) {
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
N=int(input())
M=len(input())
O=10**9+7
D=[pow(-~O//2,M,O)]+[0]*N
for _ in'_'*N:D=[D[0]+D[1]]+[(i+2*j)%O for i,j in zip(D[2:]+[0],D[:-1])]
print(D[M])

Measured memory_bytes: 80604
object Main extends App {
  val sc = new FastScanner(System.in)
  val n = sc.nextInt()
  val xy = List.fill(n)((sc.nextInt(), sc.nextInt())).zipWithIndex
  var e = List[(Int, Int, Int)]()
  xy.sortBy(_._1._1).sliding(2).foreach{ case List(((x1, y1), idx1), ((x2, y2), idx2)) =>
    e ::= (idx1, idx2, (x1 - x2).abs.min((y1 - y2).abs))
  }
  xy.sortBy(_._1._2).sliding(2).foreach{ case List(((x1, y1), idx1), ((x2, y2), idx2)) =>
    e ::= (idx1, idx2, (x1 - x2).abs.min((y1 - y2).abs))
  }

  def minimumSpanningTree(n: Int, edges: Seq[(Int, Int, Int)]): Int = {
    class UnionFindTree(n: Int) {
      private val par = Array.tabulate(n)(identity)
      private val rank = Array.fill(n)(1)

      def root(x: Int): Int = {
        var res = x
        var children = List[Int]()
        while (par(res) != res) {
          children ::= res
          res = par(res)
        }

        for (y <- children) {
          par(y) = res
        }
        res
      }

      def unite(x: Int, y: Int): Unit = {
        val xr = root(x)
        val yr = root(y)
        if (xr != yr) {
          if (rank(xr) < rank(yr)) {
            par(xr) = yr
          } else {
            par(yr) = xr
            if (rank(xr) == rank(yr)) {
              rank(xr) += 1
            }
          }
        }
      }
    }

    val uft = new UnionFindTree(n)
    var ans = 0
    for ((x, y, c) <- edges.sortBy(_._3) if uft.root(x) != uft.root(y)) {
      uft.unite(x, y)
      ans += c
    }

    ans
  }

  println(minimumSpanningTree(n, e))
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, vector<ll> A, vector<ll> B) {
  sort(ALL(A));
  sort(rbegin(B),rend(B));
  int ans;
  if(N%2) {
    ans = B[N/2] - A[N/2] + 1;
  } else {
    ans = B[N/2] + B[N/2-1] - A[N/2] - A[N/2-1] + 1;
  }
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cin >> B[i];
  }
  solve(N, move(A), move(B));
  return 0;
}


Measured memory_bytes: 6432
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;

int main() {
	scanf("%d%d", &n, &m);
	int ans = 0;
	REP(i, n) {
		int x;
		scanf("%d", &x);
		if(x >= m) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int n, m, q;
vector<int>a, b, c, d;
ll ans;

void dfs(vector<int> A){
    if (A.size() == n+1){
        ll curr = 0;
        REP(i, q){
            if(A[b[i]] - A[a[i]] == c[i]) curr += d[i];
        }
        ans = max(ans, curr);
        return;
    }

    else{
        A.push_back(A.back());
        FOR(i, A.back(), m+1){
            dfs(A);
            A.back()++;
        }
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q, 0);

    REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> init(1, 1);
    dfs(init);

    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mem(a) memset(a,0,sizeof(a))
#define lb(x) (x&(-x))
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
ll a[maxn];
bool cmp(int a,int b){
	return a>b;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0); 
    std::cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	int cnt=n-2;
	ll ans=a[1];
	for(int i=2;i<=n;i++){
		if(cnt==-1){
			ans-=a[i-1];
			break;
		}
		if(cnt==0){
			break;
		}
		ans+=a[i]*2;
		cnt-=2;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5208
var
    n,i,x,y: Integer;
    a: array[1..100] of Integer;

procedure qsort(l,r:Longint;data:PInteger);
var
    i,j,mid,t: Integer;
begin
    if l>=r then
    begin
        exit;
    end;
    i:=l;
    j:=r;
    mid:=data[(l+r) div 2 - 1];
    repeat
        while data[i-1]<mid do
        begin
            inc(i);
        end;
        while data[j-1]>mid do
        begin
            dec(j);
        end;
        if i<=j then
        begin
            t:=data[i-1];
            data[i-1]:=data[j-1];
            data[j-1]:=t;
            inc(i);
            dec(j);
        end;
    until i>j;
    qsort(l,j,data);
    qsort(i,r,data);
end;
begin
    readln(n);
    for i := 1 to n do
    begin
        read(a[i]);
    end;
    qsort(1,n,@a);
    x:=0;
    y:=0;
    i:=n;
    while i>0 do
    begin
        inc(x,a[i]);
        dec(i,2);
    end;
    i:=n-1;
    while i>0 do
    begin
        inc(y,a[i]);
        dec(i,2);
    end;
    writeln(x-y);
    readln;
    readln;
end.


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map> 
using namespace std;

#define LL long long
#define UI unsigned int
#define MOD (1000000007)


//D
int main() {
	static char s[100010];
	scanf("%s", s);

	int len = (int)strlen(s);

	static LL r2l[100010];
	r2l[0] = -1;
	int dist = -1;
	for (int i = 1; i < len; i++) {
		if (s[i - 1] == 'R' && s[i] == 'L') {
			dist = 0;
		}
		else if (s[i - 1] == 'L' && s[i] == 'L') {
			dist++;
		}
		else {
			dist = -1;
		}

		r2l[i] = dist;
	}

	static LL l2r[100010];
	l2r[len - 1] = -1;
	dist = -1;
	for (int i = len - 2; i >= 0; i--) {
		if (s[i + 1] == 'L' && s[i] == 'R') {
			dist = 0;
		}
		else if (s[i + 1] == 'R' && s[i] == 'R') {
			dist++;
		}
		else {
			dist = -1;
		}

		l2r[i] = dist;
	}

	static LL result[100010];
	memset(result, 0, sizeof(result));
	for (int i = 0; i < len; i++) {
		if (r2l[i] >= 0) {
			if (r2l[i] % 2 == 0) { //RL�̉E�����ŏI
				result[i - r2l[i]]++;
			}
			else { //RL�̍������ŏI
				result[i - r2l[i] - 1]++;
			}
		}

		if (l2r[i] >= 0) {
			if (l2r[i] % 2 == 0) { //RL�̍������ŏI
				result[i + l2r[i]]++;
			}
			else { //LR�̉E�����ŏI
				result[i + l2r[i] + 1]++;
			}
		}
	}

	for (int i = 0; i < len; i++) {
		printf("%lld ", result[i]);
	}
	printf("\n");

	return 0;
}


//int main()
//{
//	long long N;
//
//	cin >> N;
//
//	bool able = true;
//
//	bool danger = false; //!< ���O�ɉ��������������
//	long long prev = 0;
//	for (long iN = 0; iN < N; iN++) {
//		long long val;
//
//		cin >> val;
//
//		if (prev - val >= 2) {
//			able = false;
//			break;
//		}
//		else if (prev - val == 1) {
//			if (danger == true) {
//				able = false;
//				break;
//			}
//			else {
//				danger = true;
//			}
//		}
//		else if (prev < val) {
//			danger = false;
//		}
//
//		prev = val;
//	}
//
//	if (able == true) {
//		cout << "Yes" << endl;
//	}
//	else {
//		cout << "No" << endl;
//	}
//
//	return 0;
//}


//int main()
//{
//	long long A, B, C;
//
//	cin >> A >> B >> C;
//
//	long long lastA = A - B;
//
//	if (C <= lastA) {
//		cout << 0 << endl;
//	}
//	else {
//		cout << C - lastA << endl;
//	}
//
//	return 0;
//}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	string s;
	cin >> n >> s;

	string a = "";
	a += s[0];
	for (int i = 1; i < n; ++i){
		if(s[i] == s[i-1]) continue;
		a += s[i];
	}
	cout << (int)a.size() << '\n';
	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<math.h>

typedef struct
{
	double x;
	double y;
}Point;

void koch(int n,Point a,Point b)
{
	if(n==0)
	{
		return;
	}
	Point s,t,u;
	double th =M_PI * 60.0 / 180.0;

	s.x = (2.0*a.x+1.0*b.x)/3.0;
	s.y = (2.0*a.y+1.0*b.y)/3.0;
	t.x = (1.0*a.x+2.0*b.x)/3.0;
	t.y = (1.0*a.y+2.0*b.y)/3.0;
	u.x = (t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y = (t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

	koch(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(n-1,t,b);
}

int main(void)
{
	Point a;
	Point b;
	int n;

	scanf("%d",&n);

	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;

	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
}



Measured memory_bytes: 2128
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    ll S;
    cin >> S;
    ll x1 = 1000000000;
    cout << 0 << " " << 0 << " " << x1 << " ";

    ll l = 0, r = 1000000000;
    while (l + 1 < r) {
        ll med = (l + r) / 2LL;
        if (x1 * med < S) {
            l = med;
        } else {
            r = med;
        }
    }

    cout << x1 * r - S  << " " << 1 << " " << r << '\n';
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

int K, X;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> K >> X) {
        if (500 * K >= X) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


















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

int main(){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i=0;i<N;i++) cin >> X[i] >> Y[i];
    vector<vector<int>> P(0);
    vector<int> nums(N);
    for (int i=0;i<N;i++) nums[i] = i;

    do {
        P.push_back(nums);
    } while (next_permutation(nums.begin(), nums.end()));

    double ans = 0;
    for (auto& v : P){
        for (int k=0;k<N-1;k++){
            int i = v[k];
            int j = v[k+1];
            ans += sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]));
        }
    }
    for (int i=1;i<N+1;i++) ans /= i;
    cout << fixed << setprecision(10) << ans << endl;


}

Measured memory_bytes: 3256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		ll n, m;
		cin>>n>>m;
		if(n==0 && m==0) return 0;
		vector<ll> h(n);
		vector<ll> w(m);
		REP(i, n) cin>>h[i];
		REP(i, m) cin>>w[i];
		vector<ll> s;
		ll ans = 0;
		REP(i, n) {
			ll shaku = 0;
			REP(j, n) {
				if(j <= i) shaku += h[j];
				else {
					s.pb(shaku);
					shaku -= h[j - (i + 1)];
					shaku += h[j];
				}
			}
			s.pb(shaku);
		}
		sort(ALL(s));
		REP(i, m) {
			ll shaku = 0;
			REP(j, m) {
				if(j <= i) shaku += w[j];
				else {
					ans += upper_bound(ALL(s), shaku) - lower_bound(ALL(s), shaku);
					shaku -= w[j - (i + 1)];
					shaku += w[j];
				}
			}
			ans += upper_bound(ALL(s), shaku) - lower_bound(ALL(s), shaku);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 27980
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n = 100000;
    vector<int> primes;
    vector<bool> is_prime;
    prime_vectors(n+1, primes, is_prime);

    vector<int> similar(n+1, 0); // i 以下の 2017 に似た奇数の数
    int now = 0;
    for(int i=3; i<=n; i++){
        if(is_prime[i] && is_prime[(i+1)/2]){
            now++;
        }
        similar[i] = now;
    }

    int q;
    cin >> q;
    vector<int> ans(q);
    for(int i=0; i<q; i++){
        int l, r;
        cin >> l >> r;
        ans[i] = similar[r] - similar[l-1];
    }
    for(int i=0; i<q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5244
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    H = list(map(int, input().split()))
    ans = 0
    for i in range(0,max(H)+1):
        j = 0
        while (j < N):
            #print(j)
            if H[j] > i:
                ans += 1
                while j < N and H[j] > i:
                    j += 1
                #print(j)
            j += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl "\n"

typedef long long ll;
using namespace std;

//ll const N = 32000;

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

    int N, maxx = 0;
    cin >> N;

    map<string, int> mymap;

    for(int i = 0; i < N; i++)
    {
        string str;
        cin >> str;

        mymap[str]++;
        if(mymap[str] > maxx)maxx = mymap[str];
    }

    map<string, int>::iterator it;

    for(it = mymap.begin(); it != mymap.end(); it++)
    {
        if(it -> second == maxx)cout << it -> first << endl;
    }

    return 0;
}

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

int Keta(long A);

int main()
{
  long N;
  
  cin >> N;
  
  long A = 0; 
  long B = 0;
  
  int Ket = 0;
  int F = 999999;
  
  for (int i = 1; i <= 100000; i++)
  {
    if (N % i == 0) 
    {
      A = i;
      B = N / i;
      
      Ket = max(Keta(A), Keta(B));
      
      //cout << A << " " << B << " " << Ket << endl;
      
	  F = min(Ket, F);
      
    }
  }
  
  cout << F << endl;
    
}

int Keta(long A)
{
  int Ans = 1;
  for (int j = 0; j < 11; j++)
  {
    if (A / 10 != 0) 
    {
      A = A / 10;
      Ans++;
    }
  }
  
  return Ans;
}

Measured memory_bytes: 3636
#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 ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#define mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii map<int,int>
#define mll map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
ll dp[105][N];

int main(){
	boost;
	int n,k;
	cin>>n>>k;
	
	ll arr[n];
	for(int i = 0;i<n;i++){
		cin>>arr[i];
	}
	
	for(int i = 0;i<n;i++){
		for(int j = 0;j<=k;j++){
			if(i==0){
				if(j>=0&&j<=arr[i]){
					dp[i][j] = 1;
				}else{
					dp[i][j] = 0;
				}
			}else if(j==0){
				dp[i][j] = 1;
			}else{
				if(j>arr[i]){
					dp[i][j] = (dp[i-1][j] - dp[i-1][j - arr[i] - 1] + mod)%mod;
				}else{
					dp[i][j] = dp[i-1][j]; 
				}
			}
			
			if(j>0){
				if(!(i==n-1&&j==k))
					dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
			}
		}
	}
	
	//for(int i = 0;i<n;i++){
		//for(int j = 0;j<=k;j++){
			//cout<<dp[i][j]<<" ";
		//}
		//cout<<endl;
	//}
	
	cout<<dp[n-1][k];
	return 0;
}



Measured memory_bytes: 81776
#include<iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a==1){
    cout<<1<<endl;
  }
  else if(a==2||a==3){
    cout<<2<<endl;
  }
  else if(a>3&&a<8){
    cout<<4<<endl;
  }
  else if(a>7&&a<16){
    cout<<8<<endl;
  }
  else if(a>15&&a<32){
    cout<<16<<endl;
  }
  else if(a>31&&a<64){
    cout<<32<<endl;
  }
  else{
    cout<<64<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    
    for i,aa in enumerate(a):
        j = 0

        while aa % 2 == 0:
            aa //= 2
            j+=1
        if i == 0:
            modtmp = j
        else:
            if modtmp != j:
                print(0)
                return

    for i,aa in enumerate(a):
        a[i] = aa//2
    tmp = lcm(*a)
    # print(tmp)
    cnt =0
    # print(a)

    up = m//tmp
    if up % 2 == 0:
        up = up//2
    else:
        up = up//2 + 1

    nowtmp = tmp
    cnt = 0
    ans = 0
    a.sort()
    # print(nowtmp)
    # print(up)
    before = 0
    before_aa = 0
    print(up)
    return
    for i, aa in enumerate(a):
        if before_aa == aa:
            continue
        if aa == 1:
            print(up)
            return
        if aa <= nowtmp and aa>before:
            cnt += 1

        elif aa> nowtmp :
            ans += cnt * up
            up -=1
            cnt = 0
            nowtmp += tmp
            before += tmp
    ans += cnt * up
    print(ans)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
if __name__=='__main__':
    main()


Measured memory_bytes: 89580
N,*f = map(int, open(0).read().split())
xy = [f[i*2:i*2+2] for i in range(N)]
s = [sum(z) for z in xy]
a = max(s) - min(s)
t = [z[0]-z[1] for z in xy]
b = max(t) - min(t)
print(max(a,b))

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

int main() {
	int n;
	cin >> n;
	vector <int> x(n);
	rep (i, n) cin >> x[i];
	vector <int> cp = x;
	sort(cp.begin(), cp.end());

	rep (i, n) {
		cout << (cp[n / 2] <= x[i] ? cp[n / 2 - 1] : cp[n / 2]) << endl;
	}

	return 0;
}

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

#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int


using namespace std;

int w, a, b;

void init()
{
	si(w);
	si(a);
	si(b);
	int sub = abs(a - b);
	if(sub <= w){
		printf("0\n");
	}
	else {
		int t = abs(a - b) - w;
		printf("%d\n", t);
	}
}

int main(){
	
	init();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int b[MAX],c[MAX];

void countingsort(int a[],int b[],int k,int n){
    int i,j;
    for(i=0;i<=k;i++){
        c[i]=0;
    }
    for(j=1;j<=n;j++){
        c[a[j]]++;
    }
    for(i=1;i<=k;i++){
        c[i]=c[i]+c[i-1];
    }
    for(j=n;j>=1;j--){
        b[c[a[j]]]=a[j];
        c[a[j]]--;
    }
    for(i=1;i<=n;i++){
        if(i>1)printf(" ");
        printf("%d",b[i]);
    }
    printf("\n");
}

int main(){
    int a[MAX];
    int n,i,j,k=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i+1]);
        if(k<a[i])k=a[i];
    }
    countingsort(a,b,k,n);
    
    return 0;
}




Measured memory_bytes: 17368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    ll Q,H,S,D,N;
    cin >> Q >> H >> S >> D >> N;
    ll x=min(min(4*Q,2*H),S);
    ll y=min(2*x,D);
    ll ans=N/2*y+N%2*x;
    cout << ans << endl;
}

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

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

    int N, K;
    cin >> N >> K;
    unordered_set<int> seen;
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        while (d--) {
            int x;
            cin >> x;
            seen.insert(x);
        }
    }
    cout << N - (int)seen.size() << endl;

    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict
N, W = list(map(int, input().split()))

v, w = list(), list()
for n in range(N):
    i, j = list(map(int, input().split()))
    v.append(i)
    w.append(j)

dp = dict()
# dp[n][w]: 0からn-1thを考慮した時，　重さがwを超えない価値の最大値
for i in range(N+1):
    dp[i] = dict()
    for j in range(W+1):
        if i == 0:
            dp[i][j] = 0
            continue
        if w[i-1] <= j:
            dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
            
print(dp[N][W])


Measured memory_bytes: 95244
l,r=map(int,input().split())

ans=2018
for i in range(l,r+1):
  for j in range(i+1,r+1):
    amari=(i*j)%2019
    if amari<ans:
      ans=amari
    if ans==0:
      break
  else:
    continue
  break

print(ans)

Measured memory_bytes: 38896
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll d;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> d;
    d = d * d;
    int res = 0;
    FOR(i,1,n) {
        ll u, v;
        cin >> u >> v;
        if (u * u + v * v <= d) res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
	int k,s;
	cin>>k>>s;
	int x,y,z;
	int count=0;
	for(x=0;x<=k;x++){
		for(y=0;y<=k;y++){
				if(x+y<=s&&s-x-y<=k){
					count++;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int k ;
string s ;
int n  ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>k ;
	cin>>s ;
	n = s.size() ;
	for(int i = 0 ; i < min(n , k) ; ++i)
		cout<<s[i] ;
	if(n > k)
		cout<<"..." ;
	cout<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 3652
#include <cstdio>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
const int N = 100001;
int n, k;
vector<int>g[N];
int main()
{
    scanf("%d", &n);
    k = 1;
    while ((long long)k * (k - 1) / 2 < n) k += 1;
    if ((long long) k * (k  - 1) / 2 == n)
    {
        printf("Yes\n");
        printf("%d\n", k);
        for (int i = 1; i <= k ; i ++)
            for (int j = i + 1; j <= k ; j++)
            {
                g[i].push_back(n);
                g[j].push_back(n);
                n -= 1;
            }
        for (int i = 1; i <= k ; i++)
        {
            printf("%d", g[i].size());
            for (int j = 0; j < g[i].size();j ++)
                printf(" %d", g[i][j]);
            printf("\n");
        }
    }
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 4608
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <iostream>
#include <string>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
const ll INF = 1LL<<60;

int n;

struct plp{
	ll sum;
	int c;
	int p;
	bool operator< (const plp &opp) const{
		return sum < opp.sum;
	}
	plp(){}
	plp(ll s, int a, int b):sum(s),c(a),p(b){}
};

main(){
	scanf("%d", &n);
	vi A(n+1);
	vector< set<plp> > vs(n+1);
	REP(i, n) scanf("%lld", &A[i+1]);
	vs[0].insert(plp(-INF, 0, 0));
	REP(i, n+1){
		ll sum = 0;
		for(int j=i+1;j<=n;j++){
			sum += A[j];
			auto it = vs[i].lower_bound(plp(sum, 0, 0));
			if(it == vs[i].begin()) continue;
			-- it;
			int c = it->c + 1;
			auto jt = vs[j].upper_bound(plp(sum, 0, 0));
			if(jt != vs[j].begin()){
				-- jt;
				if(jt->c >= c) continue;
				++ jt;
			}
			while(jt != vs[j].end() && jt->c <= c) jt = vs[j].erase(jt);
			vs[j].insert(plp(sum, c, i));
		}
	}
	auto it = vs[n].end();
	--it;
	int m = it->c;
	printf("%d\n", m);
	vi ans;
	RREP(i, m-1){
		ans.push_back(it->p);
		it = vs[it->p].lower_bound(plp(it->sum, 0, 0));
		-- it;
	}
	RREP(i, ans.size()) printf("%d%s", ans[i], i?" ":"");
	puts("");
	
	
	return 0;
}

Measured memory_bytes: 9192
#[chr(i) for i in range(65, 65+26)]
number=int(input())
moji=input()
moji_list=list(moji) #1文字ずつリストにする

#print(moji_list)
#ord関数を使って数値化する。

moji_number=[]
moji_number=[ord(i) for i in moji_list]
#print(moji_number)
moji_number_plus=[0 for i in moji_list]

for i in range(len(moji_number)):
    if moji_number[i]+number>90:
        moji_number_plus[i]=moji_number[i]+number-26
        #print("if今のiは"+str(i)+"です")
    else:
        #print("else今のiは"+str(i)+"です")
        #print(number)
        moji_number_plus[i]=moji_number[i]+number


#print(moji_number_plus)
result=[]
result=[chr(i) for i in moji_number_plus]
result2=''.join(result)
print(result2)

Measured memory_bytes: 40560
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
	int a[14][14];
	int i; int ii; int kosuu = 0; int mol = 0;
	for (i = 0; i <= 13; i++){
		for (ii = 0; ii <= 13; ii++){
			a[i][ii] = 0;
		}
	}
	int x = 0; int y = 0; int size = 0;
	while (scanf("%d,%d,%d", &x, &y, &size) > 0){
		int xx = x + 2; int yy = y + 2;

		if (size == 1){
			a[xx][yy] = a[xx][yy] + 1;
			a[xx+1][yy] = a[xx+1][yy] + 1;			a[xx-1][yy] = a[xx-1][yy] + 1;			a[xx][yy+1] = a[xx][yy+1] + 1;			a[xx][yy-1] = a[xx][yy-1] + 1;
		}

		if (size == 2){
			for (i = 0; i <= 2; i++){
				for (ii = 0; ii <= 2; ii++){
					a[xx + i - 1][yy + ii - 1] = a[xx + i - 1][yy + ii - 1] + 1;
				}
			}
		}

		if (size == 3){
			for (i = 0; i <= 2; i++){
				for (ii = 0; ii <= 2; ii++){
					a[xx + i - 1][yy + ii - 1] = a[xx + i - 1][yy + ii - 1] + 1;
				}
			}
			a[xx + 2][yy] = a[xx + 2][yy] + 1;			a[xx - 2][yy] = a[xx - 2][yy] + 1;			a[xx][yy + 2] = a[xx][yy + 2] + 1;			a[xx][yy - 2] = a[xx][yy - 2] + 1;
		}
		/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0026&lang=jp */
	}
	for (i = 2; i <= 11; i++){
		for (ii = 2; ii <= 11; ii++){
			if (a[i][ii] == 0){
				kosuu = kosuu + 1;
			}
			if (a[i][ii] > mol){
				mol = a[i][ii];
			}
		}
	}
	cout << kosuu << endl;
	cout << mol << endl;
	return  0;
}

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

int main() {
  int a;
  int b;
  int c;
  cin >> a;
  cin >> b;
  c =  a / (2 * b + 1);
  if((a % (2 * b + 1)) != 0){
    c += 1;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
from collections import Counter
N=int(input())
lis=list(input() for _ in range(N))
ans=[]

counter=Counter(lis)
high=counter.most_common()[0][1]

for k,v in counter.most_common():
  if v==high:
    ans.append(k)
  else:
    break
ans.sort()
for i in ans:
  print(i)

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

int main() {
  int N, A, B, P;
  
  cin >> N;
  vector<int> vec(N);
  
  A=0;
  B=0;
  P=0;
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
    A+=vec.at(i) *10;
  }
  
  P=A/N;
  
  if (P%10<=4) {
    P/=10;
  }
  else {
    P=P/10 + 1;
  }
  for(int j=0; j<N; j++) {
    B+=(vec.at(j) -P)*(vec.at(j) -P);
  }
  cout << B <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> s;
    vector<int> visit(n + 1, -1);
    int loop = 1, bf = 0;
    {
        int v = 1;
        while (visit[v] == -1)
        {
            visit[v] = s.size();
            s.push_back(v);
            v = a[v - 1];
        }
        loop = s.size() - visit[v];
        bf = visit[v];
    }
    if (k < bf)
    {
        cout << s[k] << endl;
    }
    else
    {
        k -= bf;
        k %= loop;
        cout << s[bf + k] << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 5884
// PrintAFrame.cc
// 以下のような、たてH cm よこ W cm の枠を描くプログラムを作成して下さい。
// ##########
// #........#
// #........#
// #........#
// #........#
// ##########
// 上図は、たて 6 cm よこ 10 cm の枠を表しています。
// 【入力】
// 入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：
//   H W
// H, W がともに 0 のとき、入力の終わりとします。
// 【出力】
// 各データセットについて、たて H cm よこ W cm の枠を出力して下さい。
// 各データセットの後に、１つの空行を入れて下さい。
// 【制約】
// 3 ≤ H, W ≤ 300
// 【例】
// 入力：
// 3 4
// 5 6
// 3 3
// 0 0
// 出力：
// ####
// #..#
// ####
// 
// ######
// #....#
// #....#
// #....#
// ######
//
// ###
// #.#
// ###
#include<iostream>
using namespace std;

int main( void) {
  int H, W;

  while ( true) {
    cin >> H >> W;

    if ( H == 0 && W == 0) break;

    for ( int w = 1; w <= W; w++) cout << "#";
    cout << endl;

    for ( int h = 2; h <= H-1; h++) {
      cout << "#";
      for ( int w = 2; w <= W-1; w++) cout << ".";
      cout << "#" << endl;
    }

    for ( int w = 1; w <= W; w++) cout << "#";
    cout << endl << endl;
  }

  return 0;
}    
	



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,sum=1;
cin>>a>>b;
if(a>=b)
{
    if(a%b==0)
        {
        sum=a+b;
    cout<<sum;
    }
    else
        {
    sum=a-b;
    cout<<sum;
    }}
    else
    {
        if(b%a==0)
            {
            sum=a+b;
            cout<<sum;
            }
            else
                {
            sum=b-a;
            cout<<sum;
            }
    }

}



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

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

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

struct Node {
  int key;
  Node *right,*left,*parent;
};

Node *root,*NIL;

Node *treeMinimum(Node *x) {
  while (x->left!=NIL) {
    x=x->left;
  }
  return x;
}
Node *find(Node *u,int k) {
  while (u!=NIL and k!=u->key) {
    if (k<u->key) {
      u=u->left;
    }
    else {
      u=u->right;
    }
  }
  return u;
}
Node *treeSuccessor(Node *x) {
  if (x->right!=NIL) {
    return treeMinimum(x->right);
  }
  Node *y=x->parent;
  while (y!=NIL and x==y->right) {
    x=y;
    y=y->parent;
  }
  return y;
}
void treeDelete(Node *z) {
  Node *y;
  Node *x;
  if (z->left==NIL or z->right==NIL) {
    y=z;
  }
  else {
    y=treeSuccessor(z);
  }
  if (y->left!=NIL) {
    x=y->left;
  }
  else {
    x=y->right;
  }
  if (x!=NIL) {
    x->parent=y->parent;
  }
  if (y->parent==NIL) {
    root=x;
  }
  else {
    if (y==y->parent->left) {
      y->parent->left=x;
    }
    else {
      y->parent->right=x;
    }
  }
  if (y!=z) {
    z->key=y->key;
  }
  free(y);
}
void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while (x!=NIL) {
    y=x;
    if (z->key<x->key) {
      x=x->left;
    }
    else {
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL) {
    root=z;
  }
  else {
    if (z->key<y->key) 
      y->left=z;
    
    else 
      y->right=z;
    
  }
}
void inorder(Node *u) {
  if (u==NIL) {
    return ;
  }
  inorder(u->left);
  cout<<" "<<u->key<<flush;
  inorder(u->right);
}
void preorder(Node *u) {
  if (u==NIL) {
    return ;
  }
  cout<<" "<<u->key<<flush;
  preorder(u->left);
  preorder(u->right);
}
int main() {
  int n;
  cin>>n;
  for (int i=0; i<n; i++) {
    string com;
    cin>>com;
    if (com=="insert") {
      int x;
      cin>>x;
      insert(x);
    }
    else if (com=="print") {
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
    else if (com=="find") {
      int x;
      cin>>x;
      Node *t=find(root,x);
      if (t!=NIL) 
        cout<<"yes"<<endl;
      
      else 
        cout<<"no"<<endl;
      
    }
    else {
      int x;
      cin>>x;
      treeDelete(find(root,x));
    }
  }
  return 0;
}


Measured memory_bytes: 21768
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: Chars,
        k: usize
    };

    let digits = n
        .into_iter()
        .map(|ch| ch.to_digit(10).unwrap())
        .collect::<Vec<_>>();
    let len = digits.len();
    // dp[i][j][k] = 個数
    // i: 何桁目まで見たか
    // j: 0: nと同じ、1: n未満
    // k: 0 でない数字の数
    let mut dp = vec![vec![vec![None; k + 10]; 2]; len + 1];
    dp[0][0][0] = Some(1_u64);
    for i in 0..len {
        for j in 0..2 {
            let cur_d = digits[i];
            let max_d = if j == 0 { cur_d } else { 9 };
            for d in 0..=max_d {
                let to_i = i + 1;
                let to_j = if j == 1 || d < cur_d { 1 } else { 0 };
                for ik in 0..=k {
                    let to_k = ik + if d == 0 { 0 } else { 1 };
                    let v = match (dp[to_i][to_j][to_k], dp[i][j][ik]) {
                        (x, None) => x,
                        (None, x) => x,
                        (Some(x), Some(y)) => Some(x + y),
                    };
                    dp[to_i][to_j][to_k] = v;
                }
            }
        }
    }
    let res = dp[len][0][k].unwrap_or(0) + dp[len][1][k].unwrap_or(0);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2284
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
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);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	LD N, K;
	cin >> N >> K;
	LD ans = 0;
	for (LD i = 1; i <= N; ++i) {
		LD P = 1 / N;
		LL ter = i;
		while (ter < K) {
			P *= 0.5;
			ter *= 2;
		}
		ans += P;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N, L, M = 0,S = 0;
  cin >> N;
  
  for(int i = 0; i < N; ++i){
    cin >> L;
    if(M < L) M = L;
    S += L;
  }
  if(M >= S - M) cout << "No" << endl;
  else cout << "Yes" <<endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string A,B;
    cin >> A >> B;
    string C = A + B;
    //cout << C << endl;
    int test = stoi(C);
    //cout << test;
    for(int i=1;i<=1000;i++){
        if(i*i==test){
            cout << "Yes" << endl;
            break;
        }
        else if(i==1000){
            cout << "No" <<endl;
        }
    }
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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() {
  string s;cin>>s;
  set<int> st;
  char t='z';
  for(auto x:s){
    st.insert(int(x));
  }
  for(int i=97;i<=122;i++){
    if(!st.count(i)){cout<<char(i);return 0;}
  }
  cout<<"None";
}


Measured memory_bytes: 512
//AOJ 0526 Boat Travel
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
const int INF = 100000000;
typedef pair<int, int> P;
queue <int> a[101];
queue <int> save;
int n, k, go, boat[5000][3], st, list;
int solve(){
	int flag[101];
	queue<P> que;
	que.push(P(st, 0));
	for (int i = 0; i <= 100; i++){
		flag[i] = INF;
	}
	while (que.size()){
		P p = que.front(); que.pop();
		int i = 0;
		save = a[p.first];
		while (save.size()){
			i = save.front();
			save.pop();
			if (p.first == boat[i][0] && flag[boat[i][1]]>p.second + boat[i][2]){
				flag[boat[i][1]] = p.second + boat[i][2];
				que.push(P(boat[i][1], p.second + boat[i][2]));
			}
			if (p.first == boat[i][1] && flag[boat[i][0]] > p.second + boat[i][2]){
				flag[boat[i][0]] = p.second + boat[i][2];
				que.push(P(boat[i][0], p.second + boat[i][2]));
			}
		}
	}
	return flag[go];
}
int main() {
	while (cin >> n >> k){
		int ans;
		bool jud;
		for (int i = 0; i<n; i++){
			while (a[i].size())
				a[i].pop();
		}
		for (int i = 0; i < k; i++){
			cin >> jud;
			if (jud == 1){
				cin >> boat[list][0] >> boat[list][1] >> boat[list][2];
				a[boat[list][0]].push(list);
				a[boat[list][1]].push(list);
				list++;

			}
			if (jud == 0){
				cin >> st >> go;
				ans = solve();
				if (ans == INF)
					cout << -1 << endl;
				else
					cout << ans << endl;
			}
		}
		for (int i = 0; i < 5001; i++){
			boat[i][0] = 0;
			boat[i][1] = 0;
			boat[i][2] = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1352