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

int solve(int M, int N, int b) {
    vector<bool> flag(b, true);
    for (int i = M; i < b && N; i++) {
        if (flag[i]) {
            for (int j = i; j < b; j += i) {
                flag[j] = false;
            }
            N--;
        }
    }
    for (int i = M; i < b; i++) {
        if (flag[i]) return i;
    }
    return -1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, n;
    int bambooMax = 7500000;
    while (1) {
        cin >> m >> n;
        if (!m & !n) break;
        cout << solve(m, n, bambooMax) << endl;
    }
}


Measured memory_bytes: 3924
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void)
{
	char K[10];
	scanf("%s", K);
	for (int i = 0; i < 3; i++) {
		if (K[i] == K[i + 1]) {
			printf("Bad");
			return 0;
		}
	}
	printf("Good");
	return 0;
}


Measured memory_bytes: 128
n, m = [int(i) for i in input().split()]
s, c = [], []
for _ in range(m):
    a, b = [int(i) for i in input().split()]
    a -= 1
    s.append(a)
    c.append(b)

for ans in range(1000):
    st = str(ans)
    if len(st) != n:
        continue

    ok = True
    for i in range(m):
        if st[s[i]] != str(c[i]):
            ok = False
    if ok:
        print(st)
        exit()

print(-1)


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

using namespace std;

typedef long long ll;

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

    string S;
    cin >> S;

    bool yes = (N % 2 == 0)?true:false;
    if (yes)
    for (int i = 0; i < (N / 2); i++)
    {
        if (S[i] == S[i + (N / 2)])
            continue;
        else
        {
            yes = false;
            break;
        }
    }

    if (yes)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



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


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

}


Measured memory_bytes: 22740
n, k = map(int,input().split())
S = input()

sn = [1]
for i in range(n-1):
  if S[i] == S[i+1]:
    sn[-1] += 1
  else:
    sn.append(1)
    
for i in range(k):
  temp = 0
  if len(sn) > 2:
    for j in range(3):
      temp += sn.pop()
    sn.append(temp)
  elif len(sn) == 2:
    sn[0] += sn.pop()
  else:
    break
    
ans = sum(sn)-len(sn)
print(ans)

Measured memory_bytes: 3956
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
  int N, K, score[200001], i;
  scanf("%d%d", &N, &K);
  for (i = 0; i < N; i++)
  {
    scanf("%d", &score[i]);
  }

  for (i = 0; i < N - K; i++)
  {
    if (score[i] < score[i + K])
    {
      printf("Yes\n");
    }
    else
    {
      printf("No\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
	string str;
	std::cin >> str;
	int count = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str[i] == '1') {
			count++;
		}
	}
	std::cout << count << '\n';
	return 0;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
vector<ll> v(n,0);
rep(i, n-1){
  cin >> a[i];
  v[a[i]-1]++;
}

for(auto ans:v)cout << ans << endl;
return 0;
}

Measured memory_bytes: 6376
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
BIGNUM = 10 ** 9 + 7

if m > 0:
    last_ana = int(input())
    blocks = [last_ana]

    for _ in range(1, m):
        ana = int(input())
        blocks.append(ana - last_ana - 1)
        last_ana = ana
    blocks.append(n - last_ana)
else:
    blocks = [n + 1]

if 0 in blocks:
    ans = 0
else:
    b_max = max(blocks)
    c = [1, 1]
    for i in range(2, b_max):
        ctmp = c[i - 1] + c[i - 2]
        c.append(ctmp % BIGNUM)

    ans = 1
    for num in blocks:
        if num == 1:
            continue
        ans = (ans * c[num - 1]) % BIGNUM
        if ans == 0:
            break

print(ans)

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

int c=0;

int bubble(int *r, int n){
    int flag=1;
    int tmp;
    while(flag){
        flag=0;
        for(int i=n-1;i>0;i--){
            if(r[i]<r[i-1]){
                tmp=r[i];
                r[i]=r[i-1];
                r[i-1]=tmp;
                flag=1;
                c++;
            }
        }
    }

    for(int k=0;k<n;k++){
        if(k!=n-1) cout<<r[k]<<' ';
        else cout<<r[k]<<endl;
    }
    return 0;

}


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

    bubble(r, n);
    cout<<c<<endl;

}


Measured memory_bytes: 3096
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.09 20:55:18
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int p, q, r;
    cin >> p >> q >> r;
    int ma = max(p, max(q, r));
    int ret = p + q + r - ma;
    cout << ret << "\n";

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
using namespace std;

int main() {
	string A;
	cin >> A;
	int N = A.size();



	int ans = 0;
	for (int i = 2; i < N - 1; i++){
		if (A[0] == 'A' && A[i] == 'C') {
			ans++;
		}
	}
  	int cnt=0;
  	for(int i=0;i<N;i++)if(isupper(A[i]))cnt++;
	if (ans != 1||cnt!=2) {
		cout << "WA" << endl;
	}
	else {
		cout << "AC" << endl;
	}
}


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

Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int G[100][100],i,j,n,u[100],k[100],count,l;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u[i],&k[i]);
    for(j=0;j<k[i];j++){
      scanf("%d",&G[i][j]);
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      count=0;
      for(l=0;l<k[i];l++){
	if(G[i][l]==j+1){
	  if(j+1==n){
	    printf("1");
	  }
	  else printf("1 ");
	  count++;
	  break;
	}
      }
      if(count==0){
	if(j+1==n){
	  printf("0");
	}
	else printf("0 ");
      }
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  input.shift();
  var S = input;
  S.splice(N,S.length);
  var a=0;
  var b=0;
  var c=0;
  var d=0;
  for(var i =0;i<N;i++){
    if(S[i]=="AC"){
      a++;
    }else if(S[i]=="WA"){
      b++;
    }else if(S[i]=="TLE"){
      c++;
    }else{
      d++;
    }
  }
  var ans = "AC x " + a + "\nWA x " + b + "\nTLE x " + c + "\nRE x " + d;

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37100
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

ll GCD(ll x,ll y) {
	if (x == 0)return y;
	return GCD(y % x, x);
}

int main() {
	ll A, B;
	cin >> A >> B;
	ll ans = A * B / (GCD(A, B));
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_H = 1e5 + 5;
const int MAX_N = 3e3 + 5;

ll fastExpo(int base, int e) {
    ll ans = 1;
    while(e != 0) {
        if(e % 2 == 1) ans = (ll) ans * base % MOD;
        base = (ll) base * base % MOD;
        e /= 2;
    }
    return ans;
}

namespace modOp {
    int add(int a, int b, int mod = MOD) {return (a + b) % mod; /* int r = a + b; if (r >= mod) r -= mod; return r; */} 
    int sub(int a, int b, int mod = MOD) {return (a - b + mod) % mod; /* int r = a - b; if (r < 0) r += mod; return r; */}
    int mul(int a, int b, int mod = MOD) {return (ll)a * b % mod;}
    int divide(int a, int b, int mod = MOD) {return (ll)a * fastExpo(b, mod - 2) % mod;} //mod has to be a prime number
}
using namespace modOp;

int H, W, N;
pi walls[MAX_N];
int dp[MAX_N];
ll fac[2 * MAX_H], inv[2 * MAX_H];

int f(int a, int b) {
	a += b;
	if (a < 0 || b < 0 || b > a) return 0;
	return mul(fac[a], mul(inv[b], inv[a - b]));
}

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

	fac[0] = inv[0] = 1;
	for (int i = 1; i < 2 * MAX_H; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = divide(1, fac[i]);
	}

	cin >> H >> W >> N;
	for (int i = 0; i < N; ++i) {
		cin >> walls[i].ff >> walls[i].ss;
	}
	walls[N] = {H, W};

	sort(walls, walls + N + 1, [](pi a, pi b) {return a.ff + a.ss < b.ff + b.ss;});

	for (int i = 0; i <= N; ++i) {
		dp[i] = f(walls[i].ff - 1, walls[i].ss - 1);
		for (int j = 0; j < i; ++j) {
			if (walls[i].ff >= walls[j].ff && walls[i].ss >= walls[j].ss) {
				dp[i] = sub(dp[i], mul(dp[j], f(walls[i].ff - walls[j].ff, walls[i].ss - walls[j].ss)));
			}
		}
	}

	cout << dp[N] << '\n';

	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int n;
	cin >> n;
	if(n == 1) cout << "Hello World\n";
	else
	{
		int a;
		cin >> a;
		int b;
		cin >> b;
		cout << a + b << "\n";
	}	
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for i in range(N)]
 
dp=[[0]*(W+1) for i in range(N+1)]
 
for w in range(W+1):
    for n in range(N):
        if wv[n][0] <= w:
            dp[n+1][w] = max(dp[n][w-wv[n][0]] + wv[n][1], dp[n][w])
        else:
            dp[n+1][w] = dp[n][w]
 
 
print(dp[N][W])

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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

void solve() {

	const int n = 3;

	int res = 0;
	for (int i = 0; i < n; i++) {
		int val; cin >> val;
		res = res * 10 + val;
	}

	bool ans = res % 4 == 0;

	if (ans) cout << "YES";
	else cout << "NO";
}

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

	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();
}

Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n=int(input())
l=[0]*(n+1)
for i in range(1,n+1):
    c=prime_factorize(i)
    #print(c)
    for j in range(len(c)):
        l[c[j]]+=1
#print(l)
ans=1
for i in range(n+1):
    if l[i]!=0:
        ans=ans*(l[i]+1)%(10**9+7)
print(ans%(10**9+7))

Measured memory_bytes: 42716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
int n,k,c;
char s[N];
int sum[N],ps[N],cnt[N];
struct ST{
	static const int N = 201010;
	int a[20][N], lg[N];
	void build(int *v, int n){
		rep(i, 2, n + 1) lg[i] = lg[i >> 1] + 1;
		rep(i, 0, n) a[0][i] = v[i];
		rep(i, 1, lg[n] + 1) rep(j, 0, n - (1 << i) + 1) {
			a[i][j] = max(a[i - 1][j], a[i - 1][j + (1 << i >> 1)]);
		}
	}
	int qry(int l, int r){
		if(l > r) swap(l, r);
		int i = lg[r - l + 1];
		return max(a[i][l] , a[i][r + 1 - (1 << i)]);
	}
}st;
int main()
{
	cin>>n>>k>>c;
	cin>>(s + 1);
	c++;
	for(int i = n ;i >= 1;--i){
		sum[i] = sum[i + 1];
		if(s[i] == 'o')sum[i] = max(sum[i],sum[i + c] + 1);
	//	de(sum[i]);
	}
	if(c == 1){
		rep(i , 1 , n + 1)
			if(s[i] == 'o' && sum[1] <= k)cout<<i<<"\n";
		return 0;
		
	}
	for(int i = 1;i <= n;++i){
		ps[i] = ps[i - 1];
		if(s[i] == 'o'){
			ps[i] = max(ps[i],ps[max(0,i-c)] + 1);
		}
	//	de(ps[i]);
	}
	//if(ps[n] <k)return 0;

	for(int i = 1;i <= n;++i){
		cnt[i] = ps[i] + sum[i + c];
	//	de(cnt[i]);
	}
	st.build(cnt,n + 1);
	rep(i , 1 , n + 1){
		if(s[i] == 'x')continue;
		int l = max(0,i - c + 1);
		int r = i - 1;
	//	dd(l),dd(r),de(st.qry(l,r));
		if(st.qry(l,r) <k && sum[i + 1] < k && ps[i - 1] < k){
			cout<<i<<"\n";
		}
		
	}
	return 0;
}



Measured memory_bytes: 28928
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	long long N;
	cin >> N;
	vector<pair<long long,long long>> pa(N);
	for(long long i=0;i<N;i++){
		cin >> pa[i].second >> pa[i].first;
	}
	sort(pa.begin(),pa.end());
	long long now=0;
	for(long long i=0;i<N;i++){
		now+=pa[i].second;
		//cout << "now=  " << now << endl;
		if(now>pa[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



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

char area[102][102];

int main(){
    int A,B;
    cin >> A >> B;
    for(int i=0;i<50;i++){
        for(int j=0;j<100;j++){
            area[i][j] = '#';
            area[i+50][j] = '.';   
        }
    }
    A--; B--;

    for(int i=1;i<50;i=i+2){
        for(int j=1;j<100;j=j+2){
            if(A>0){
                area[i][j] = '.';
                A--;
            }
            if(B>0){
                area[i+50][j] = '#';
                B--;
            }
        }
    }

    cout << 100 << ' ' << 100 << "\n";

    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            cout << area[i][j];
        }
        cout << "\n";
    }


    return 0;
}

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 1; i < n; ++i) {
        if(s[i] != s[i-1]) ++cnt;
    }
    cnt = n-cnt-1;
    cout << min(n-1, cnt+2*k);
}


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

int main(){
    while(1)
    {
        int n;
        cin>>n;
        int sum=0;
        int count=0;
        if(n==0)return 0;
        count = 0;
        for(int i=1;i<n;i++)
        {
            //count = 0;
            sum = 0;
            for(int j=i;j<n;j++)
            {
                //cout<<i<<","<<j<<","<<sum<<endl;
                sum += j;
                if(sum == n)
                {
                    count++;
                }
                else if(sum>n)
                {
                    j = n;
                }
            }
        }
        cout<<count<<endl;
    }
    
}


Measured memory_bytes: 3088
//Author: ZindagiMeBasAishHiChahiye
//WA/TLE
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ll          long long
#define N 1000005
// ll po(ll a,ll b,ll m){
// 	a%=m;
// 	if(b==0) return 1;
// 	if(b%2) return (a*(po((a*a)%m,b/2,m)%m)%m)%m;
// 	return po((a*a)%m,b/2,m)%m;
// }

bool check(ll a,ll b,ll x,ll y){
	if(a<0||b<0) return false;
	if(a>=x||b>=y) return false;
	return true;
}
ll x[1004][1004];
bool vis[N];
string s[1000];
set<int> st[N];
vi ad[N];
void dfs(ll i,ll j,ll c,ll h,ll w){
	if(x[i][j]||s[i][j]=='#') return;
	x[i][j]=c;
	if(check(i,j+1,h,w)) dfs(i,j+1,c,h,w);
	if(check(i,j-1,h,w)) dfs(i,j-1,c,h,w);
	if(check(i+1,j,h,w)) dfs(i+1,j,c,h,w);
	if(check(i-1,j,h,w)) dfs(i-1,j,c,h,w);
}

void bfs(ll a,ll b,ll &an){
	queue<pii> q;
	q.push({a,0});
	vis[a]=true;
	while(!q.empty()){
		pii pp=q.front();
		q.pop();
		for(auto x:ad[pp.F]){
			if(!vis[x]){
				vis[x]=true;
				q.push({x,pp.S+1});
				if(x==b){
					an=pp.S+1;
					return;
				}
			}
		}
	}
}
void solve(){
	ll h,w,c1,c2,d1,d2;
	cin>>h>>w>>c1>>c2>>d1>>d2;
	c1--;
	c2--;
	d1--;
	d2--;
	rep(i,0,h)
	cin>>s[i];
	ll c=1;
	rep(i,0,h){
		rep(j,0,w){
			if(s[i][j]!='#'&&(x[i][j]==0)){
				dfs(i,j,c,h,w);
				c++;
			}
		}
	}
	if(x[c1][c2]==x[d1][d2]){
		cout<<0;
		return;
	}
	rep(i,0,h){
		rep(j,0,w){
			if(x[i][j])
			rep(k,-2,3){
				rep(l,-2,3){
					if(check(i+k,j+l,h,w)&&x[i+k][j+l]&&x[i+k][j+l]!=x[i][j]){
						// cout<<i<<j<<k<<l<<endl;
						if(st[x[i][j]].find(x[i+k][j+l])==st[x[i][j]].end()){
							ad[x[i][j]].pb(x[i+k][j+l]);
							st[x[i][j]].insert(x[i+k][j+l]);
							ad[x[i+k][j+l]].pb(x[i][j]);
							st[x[i+k][j+l]].insert(x[i][j]);
						}
					}
				}
			}
		}
	}
	rep(i,0,N)
	vis[i]=false;
	ll an=-1;
	bfs(x[c1][c2],x[d1][d2],an);
	// cout<<ad[1].size();
	cout<<an;



}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1,z=1;
	// cin>>TESTS;
	while(TESTS--){
		// time
		// cout<<"Case #"<<z<<": ";
		// z++;
		solve();
		time

	}
	return 0;
}

Measured memory_bytes: 108136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[100010],post[100010];
int vi[100010];
int gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
 } 
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>vi[i];
	pre[1] = vi[1] , post[n] = vi[n];
	for(int i=1;i<=n;i++)
		pre[i] = gcd(pre[i-1],vi[i]);
	for(int i=n-1;i;i--)
	{
		post[i] = gcd(post[i+1],vi[i]);
	}
	int ans = -10000000;
	for(int i=1;i<=n;i++)
	{
		ans = max(gcd(pre[i-1],post[i+1]),ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1408
n = int(input())
h = [int(e) for e in input().split()]
cost = [float('inf')] * n
cost[0] = 0
for i in range(n - 2):
  cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))
  cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i]))
cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2]))
print(cost[n - 1])


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

int main() {
  int N, K, a, b, sum = 1;
  cin >> N >> K;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    // Aの場合
    a = sum * 2;
    // Bの場合
    b = sum + K;
    if (a > b) {
      sum += K;
    } else {
      sum *= 2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
s=int(input())
a=[s]
i=0
while True:
    if a[i]%2==0:
        a.append(int(a[i]/2))
        i+=1
    else:
        a.append(int(3*a[i]+1))
        i+=1
    if [j for j in set(a) if a.count(j)>1]:
        a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
        break
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)    






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

long GCD(long n,long m) {
	long r = n % m;
  while(r!=0){
    n = m;
    m = r;
    r = n % m;
  }
	return m;
}


int main() {
	long n,m;
	string s,t;
	cin >> n >> m;
	cin >> s;
	cin >> t;

  long x = n * m;
 
  /* 自然数 n > m を確認・入替 */
  if(n<m){
    long tmp = n;
		string tmpstr = s;
    n = m;
		s = t;
    m = tmp;
		t = tmpstr;
  }

	long gcd = GCD(n,m);
	long lcm = x/gcd;

	for (int i=0; i<=gcd-1; i++) {
		if (s[n/gcd*i]!=t[m/gcd*i]) {
			cout << -1 << endl;
			return 0;
		}
		if (i==gcd-1) cout << lcm << endl;
	}


	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	string a, b;
	cin >> a >> b;
	b.pop_back();
	if (a == b)
		cout << "Yes\n";
	else
		cout << "No\n";
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,pair<int,int>> PP;
typedef pair<int,int> P;
typedef tuple<int,int,int> tp;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,Q;
    cin >> N >> Q;
    vector<tp> V(N);
    rep(i,0,N){
        int s,t,x;
        cin >> s >> t >> x;
        V[i] = tie(x, s, t);
    }
    vector<int> D(Q), ans(Q,-1);
    sort(V.begin(), V.end());
    set<P> st;
    rep(i,0,Q){
        cin >> D[i];
        st.insert(P(D[i], i));
    }
    rep(i,0,N){
        int x,l,r;
        tie(x,l,r) = V[i];
        l -= x;
        r -= x;
        //cout << ":" << i << endl;
        auto itr = st.lower_bound(P(l, -1));
        for(; itr != st.end();){
            if(itr->first >= r)break;
            //cout << itr->second << " ";
            ans[itr->second] = x;
            st.erase(itr++);
            //cout << itr->second << endl;
            //itr++;
        }//cout << endl;
    }//cout << endl;
    rep(i,0,Q){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

ll mpow(ll x, ll n, ll mod){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

// nCa
ll combination(ll n, ll a, ll mod) {
    ll X = 1;
    for (ll i = n - a + 1; i <= n; i++) {
        X = (X * i) % mod;
    }
    ll Y = 1;
    for (ll i = 1; i <= a; i++) {
        Y = (Y * i) % mod;
    }

    ll iY = mpow(Y, mod - 2, mod);
    return X * iY % mod;
}


void Main()
{
    ll X, Y;
    cin >> X >> Y;

    if ((X + Y) % 3 != 0) {
        put(0);
        return;
    }

    ll step = (X + Y) / 3;
    ll nx = X - step;
    ll ny = Y - step;
    // nx+ny C nx 
    if (nx < 0 || ny < 0) {
        put(0);
        return;
    }

    ll mod = 7LL + 1e9;
    ll res = combination(nx + ny, nx, mod);
    put(res);
}
signed main(){ Main();return 0;}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do{ cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// Let's get AC!
int main(){

    string s;
    cin >> s;

    debug(s);
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;

}

Measured memory_bytes: 256
/**
*    created: 03.07.2020 02:38:21
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    string s = to_string(n);
    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long n;
vector<long>a;
long ans;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long x;cin>>x;a.push_back(x);
	}
	while(1)
	{
		sort(a.begin(),a.end(),greater<long>());
		if(a[0]<n)break;
		long k=0;
		while(k+1<n&&a[k+1]+k+1>=n&&a[0]-a[k+1]<n+1)k++;
		if(k==n-1)
		{
			k=0;
			while(k+1<n&&a[k+1]+k+1>=n&&a[0]-a[k+1]<=k+1)k++;
		}
		if(k<n-1)
		{
			long L=(a[0]-a[k+1])/(1+n);
			if(L<=0)L=1;
			ans+=L*(k+1);
			for(int i=0;i<n;i++)
			{
				if(i>k)a[i]+=L*(k+1);
				else a[i]+=L*(k-n);
			}
		}
		else
		{
			long L=a[0]-n+1;
			if(L>a[n-1])L=a[n-1];
			ans+=L*n;
			for(int i=0;i<n;i++)a[i]-=L;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n;
  scanf("%d",&n);

  int a[1000010]={0};
  int t;
  for(int i = 0; i < n; ++i){
    scanf("%d",&t);
    a[t]++;
  }

  int ans = 0;
  for(int i = 0; i < 1000010; ++i){
    if(!a[i]) continue;
    if(a[i] == 1)ans++;
    else a[i] = 0;

    for(int j = i*2; j < 1000010 ; j += i){
      a[j] = 0;
    }
  }

  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 5604
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	int n, k;
	int ans = 1;
	cin >> n >> k;
	while(n >= k){
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vi a(n + 1, -1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    map<int, ll> mp1, mp2;

    for (int i = 1; i <= n; i++) {
        if (mp1.find(i + a[i]) != mp1.end()) {
            mp1[i + a[i]]++;
        } else {
            mp1[i + a[i]] = 1;
        }

        if (i - a[i] >= 0) {
            if (mp2.find(i - a[i]) != mp2.end()) {
                mp2[i - a[i]]++;
            } else {
                mp2[i - a[i]] = 1;
            }
        }
    }

    ll c = 0;
    for (auto itr = mp1.begin(); itr != mp1.end(); itr++) {
        if (mp2.find(itr->first) != mp2.end()) {
            c += itr->second * mp2[itr->first];
        }
    }

    cout << c << endl;
}

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

long long MOD = 1e9 + 7;

long long mul(long long a, long long b) {
    return a * b % MOD;
}

long long fac[100010];

long long pow_mod(long long x, long long n) {
    long long res = 1;
    while (n) {
        if (n & 1) res = mul(res, x);
        x = mul(x, x);
        n /= 2;
    }
    return res;
}

long long inv(long long n) {
    return pow_mod(n, MOD - 2);
}

long long binomial(int k, int n) {
    if(n<0 || k<0 || n-k<0) return 0;
    return mul(mul(fac[n], inv(fac[n - k])), inv(fac[k]));
}

int main(int argc, char *argv[])
{
    fac[0] = 1;
    for (int i = 1; i < 100001; i++) {
        fac[i] = mul(fac[i - 1], i);
    }
    int N, K;
    cin >> N >> K;
    vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(begin(a), end(a));
    long long res = 0;
    for (int i = 0; i <= N - K; i++) {
        res = (res - mul(a[i], binomial(K - 1, N - i - 1)) + MOD) % MOD;
    }
        for (int i = 0; i < N/* = N - K */; i++) {
//for (int i = N - 1; i >= K - 1; i--) {
        res = (res + mul(a[i], binomial(K - 1, i))) % MOD;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1920
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
    int i,m,cnt,ans=0,n,a,b;
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
    {
        m=i;
        cnt=0;
        while(m)
        {
            cnt+=m%10;
            m/=10;
        }
        if((cnt>=a)and(cnt<=b)) ans+=i;
    }
    cout<<ans;
    WAIT;
    rt0;
}



Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

bool watch[20][31];
map <int, string> mp;
int score[20];

int main()
{
//	cut here before submit 
//	freopen ("testcase.PE", "r", stdin );
	int n;
	
	while (cin >> n && n ){
		memset (watch, false, sizeof (watch ) );
		memset (score, 0, sizeof (score ) );
		for (int i = 0; i < n; ++i ){
			cin >> mp[i];
			int m;
			cin >> m;
			for (int j = 0; j < m; j++ ){
				int d;
				cin >> d;
				watch[i][d] = true;
			} // end for
		} // end for
		for (int d = 0; d <= 30; d++ ){
			int sum = n+1;
			for (int i = 0; i < n; i++ ){
				if (watch[i][d] ){
					sum--;
				} // end if
			} // end for
			for (int i = 0; i < n; i++ ){
				if (watch[i][d] ){
					score[i] += sum;
				} // end if
			} // end for
		} // end for
		int minS = 1 << 20;
		set <string> res; 
		for (int i = 0; i < n; i++ )
			if (minS > score[i] )
				minS = score[i];
			
		for (int i = 0; i < n; i++ )
			if (minS == score[i] )
				res.insert (mp[i] );

		cout << minS << ' ' << *res.begin() << endl;

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    int n;
    int x;
    int i, k, m;
    int result = 0;
    for(;;){
        result = 0;
        cin >> n >> x;
        if(n==0 && x==0) break;
        for(i=1; i<n+1; i++){
            for(k=i+1; k<n+1; k++){
                for(m=k+1; m<n+1; m++){
                    if(i+k+m == x){
                        result ++;
                        //cout << i << k << m << endl;

                    }
                }
            }
        }
        cout << result << endl;
    }


}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

using namespace std;

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

int get_two_index(int v){
    int ans = 0;
    while(v % 2 == 0){
        v /= 2;
        ans ++;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    int ans;
    rep(i, N){
        int tmp;
        cin >> tmp;
        ans += get_two_index(tmp);
    }
    cout << ans << endl;
    return 0;
}


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

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

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

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    roop(i, n) cin >> a[i];

    for(int i = n-1; i >= 0;i--){
        if(i == 0) cout << a[i] << endl;
        else cout << a[i] << " ";
    }

    return 0;
}


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

int main(void){
  int n, m;
  int ans;
  scanf("%d %d", &n, &m);
  ans = (1900 * m + 100 * (n-m)) / (1 /pow(2,m));
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll c[200010];

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    if(n==1&&a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    for(ll i=0;i<n-1;i++){
        if(i==0&&a[0]!=0){
            cout<<-1<<endl;
            return 0;
        }
        if(a[i]+1<a[i+1]){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll ans=0;
    for(ll i=1;i<n;i++){
        if(a[i-1]+1==a[i])ans++;
        else ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S, a, b;
    cin >> S;
    int size = S.size();
    rep(i, 0, size)
    {
        if (i % 2 == 0)
        {
            a += '0';
            b += '1';
        }
        else
        {
            a += '1';
            b += '0';
        }
    }
    int count1 = 0;
    int count2 = 0;
    rep(i, 0, size)
    {
        if (S.at(i) != a.at(i))
        {
            count1++;
        }
        else if (S.at(i) != b.at(i))
        {
            count2++;
        }
    }
    if (count1 > count2)
    {
        cout << count2 << endl;
    }
    else
    {
        cout << count1 << endl;
    }
}

Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  cout<<(N-2)*180<<endl;
}



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

int main() {
    long long N; cin >> N;
    vector<long long>A(N), B(N); 
    for (long long i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    B.at(0) = A.at(0);
    for (long long i = 1; i < N; i++) {
        B.at(i) = B.at(i - 1) + A.at(i);
    }
    long long ans = 0;
    for (long long i = 0; i < N; i++) {
        ans += A.at(i) * ((B.at(N - 1) - B.at(i)) % 1000000007);
        ans %= 1000000007;
    }
    cout << ans % 1000000007 << endl;
}

Measured memory_bytes: 6420
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int n,k;
    cin >> n>>k;
    int d;
    vi v[n+1];
    for(int i=0;i<k;i++){
    	cin >> d;
    	for(int j=0;j<d;j++){
    		int x;
    		cin>>x;
    		v[x].pb(i);
    	}
    	
    }
    int c=0;
    for(int i=1;i<=n;i++){
    	if(v[i].size()==0) c++;
    }
    cout<<c<<endl;
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long
#define wtcl return
using namespace std;

inline ll read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
inline void out(ll x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) out(x/10);
	putchar(x%10+'0');
}

int main()
{
	int n,k;
	cin>>n>>k;
	int num[100005];
	for(int i=0;i<n;i++)
		num[i]=read();
	sort(num,num+n);
	int ans  = 999999999;
	for(int i=0;i<=n-k;i++)
	{
		ans = min(ans,num[i+k-1]-num[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007;

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

    long long power = 1;

    for (int i = 1; i <= n; i++)
    {
        power = power * i;
        power %= MOD;
    }
    cout << power << endl;
}

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

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

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            int k = N - i - j;
            if (k >= 0 && k <= N && 10000 * i + 5000 * j + 1000 * k == Y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll s[100100],t[100100];

int main(void){
	int n,m,q,sp,tp,i;
	ll x,ans,sl,sr,tl,tr;
	cin >> n >> m >> q;
	s[0] = -INFLL;
	for(i=1; i<=n; ++i){
		cin >> s[i];
	}
	s[n+1] = INFLL;
	n += 2;
	t[0] = -INFLL;
	for(i=1; i<=m; ++i){
		cin >> t[i];
	}
	t[m+1] = INFLL;
	m += 2;
	for(i=0; i<q; ++i){
		ans = INFLL;
		cin >> x;
		sp = (int)(lower_bound(s,s+n,x)-s);
		tp = (int)(lower_bound(t,t+m,x)-t);
		sl = s[sp-1];
		tl = t[tp-1];
		sr = s[sp];
		tr = t[tp];
		ans = min((abs(x-sl)+abs(sl-tl)),ans);
		ans = min((abs(x-sl)+abs(sl-tr)),ans);
		ans = min((abs(x-sr)+abs(sr-tl)),ans);
		ans = min((abs(x-sr)+abs(sr-tr)),ans);
		ans = min((abs(x-tl)+abs(tl-sl)),ans);
		ans = min((abs(x-tl)+abs(tl-sr)),ans);
		ans = min((abs(x-tr)+abs(tr-sl)),ans);
		ans = min((abs(x-tr)+abs(tr-sr)),ans);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
int main()
{
	int x,y,h[5]={0},make,kati,aiko;
	while(scanf("%d",&h[0])&&h[0]!=0)
	{
		for(x=1; x<5; x++)
			scanf("%d",&h[x]);
		for(x=0; x<5; x++)
		{
			make=0;
			kati=0;
			aiko=0;
			if(h[x]==1)
			{
				for(y=0; y<5; y++)
				{
					if(y!=x)
					{
						if(h[y]==3)
						{
							make=1;
						}
						if(h[y]==2)
						{
							kati=1;
						}
						if(h[y]==1)
						{
							aiko=1;
						}
					}
				}
				if(make==1 && kati==1)
					printf("3\n");
				else if(kati==1)
					printf("1\n");
				else if(make==1)
					printf("2\n");
				else if(aiko==1)
					printf("3\n");
			}
			if(h[x]==2)
			{
				for(y=0; y<5; y++)
				{
					if(y!=x)
					{
						if(h[y]==1)
						{
							make=1;
						}
						if(h[y]==3)
						{
							kati=1;
						}
						if(h[y]==2)
						{
							aiko=1;
						}
					}
				}
				if(make==1 && kati==1)
					printf("3\n");
				else if(kati==1)
					printf("1\n");
				else if(make==1)
					printf("2\n");
				else if(aiko==1)
					printf("3\n");
			}
			if(h[x]==3)
			{
				for(y=0; y<5; y++)
				{
					if(y!=x)
					{
						if(h[y]==2)
						{
							make=1;
						}
						if(h[y]==1)
						{
							kati=1;
						}
						if(h[y]==3)
						{
							aiko=1;
						}
					}
				}
				if(make==1 && kati==1)
					printf("3\n");
				else if(kati==1)
					printf("1\n");
				else if(make==1)
					printf("2\n");
				else if(aiko==1)
					printf("3\n");
			}
		}
	}
	return 0;
}

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

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	if(-a+b<=0)cout << "delicious" << endl;
	else if(-a+b<=x)cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll; 

int N, M;
const int MAX_N = 100000;
int X[MAX_N];

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> X[i];
    
    if (N >= M) cout << 0 << endl;
    else {
        sort(X, X + M);

        int sec[M-1];
        for (int i = 0; i < M - 1; i++) sec[i] = X[i + 1] - X[i];
        sort(sec, sec + M-1);

        int ans = 0;
        for (int i = 0; i < M - N; i++) ans += sec[i];
        cout << ans << endl;
    }
    return 0;    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll h, w;
  cin >> h >> w;
  
  ll cnt=0;
  char c;
  rep(i, h) rep(j, w) {
    cin >> c;
    if(c=='#') cnt++;
  }
  
  cout << (cnt==h+w-1 ? "Possible" : "Impossible") << newl;
  return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
int main(){
  char W[100];
  scanf("%s",&W);
  int c = 0;
  for(int i = 0;i < strlen(W);i++){
    int cnt = 0;
    for(int j = 0;j < strlen(W);j++){
      if(W[i] == W[j]){
        cnt++;
      }
    }
    if(cnt % 2 == 0){
      c++;
    }
  }
  if(c == strlen(W)){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

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

using namespace std;

const double eps = 1e-12;

double f(double x, double d) {
	double y = sqrt(d*d-x*x);
	return x + y;
}

int main() {
	double d; cin >> d;
/*
	double l = 0, r = d;
	for (int t = 0; t < 100; ++t) {
		double m1 = l+(r-l)/3, m2 = l+(r-l)*2/3;
		if ( f(m1, d) < f(m2, d) ) {
			l = m2;
		}
		else {
			r = m1;
		}
	}
	double ans = f(l, d);
*/
	double ans = d * sqrt(2);
	for (int h = 1; h <= 10; ++h) {
		double ww = d*d-h*h;
		if (-eps < ww && ww < 1-eps) {
			double w = sqrt(w);
			if (w < 1-eps) {
				ans = max(ans, (double)h+1);
			}
		}
	}
	cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 1280