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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_NOde_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
	#ifdef LOCAL_TEST
	freopen("in.txt","r",stdin);
	//freopen("out.txt", "w", stdout);
	#else
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	#endif

	ll n,K;
	cin>>n>>K;
	ll a[100] = {0};
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}

	ll dp[55][55][105] = {0};
	for(int i=1;i<=n;i++)
	{
		for(int k=1;k<=K;k++)
		{
			if(a[i]>=0)
			{
				dp[i][i][k] = a[i];
			}
		}
	}

	for(int l=1;l<=n;l++)
	{
		for(int i=1;i<=n-l;i++)
		{
			for(int k=1;k<=K;k++)
			{
				int j = i + l;
				dp[i][j][k] = max(dp[i][j][k],dp[i+1][j][k-1]+a[i]);
				if(k > 1)
				{
					dp[i][j][k] = max(dp[i][j][k],dp[i+1][j][k-2]);
					dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k-2]);
				}
				dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k-1]+a[j]);
			}
		}
	}

	ll ans = 0;
	//cout << dp[2][n][2] << "\n";
	for(int i=1;i<=K;i++)
	{
		if(dp[1][n][i] > ans)ans = dp[1][n][i];
	}

	cout << ans << "\n";

	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int main(){
	int n,a;
	cin>>n>>a;
	if(n%500<=a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAXN 100005
int n,m;
int tot[MAXN];
bool b[MAXN];
int main()
{
	b[1]=1,tot[1]=1;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		tot[i]=1;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		tot[x]--,tot[y]++;
		if(b[x]==1) b[y]=1;
		if(tot[x]==0) b[x]=0;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(b[i])
			ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
import java.util.*;

import java.io.*;
import java.math.BigInteger;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static int inf = (int) 1e15;
	static HashSet<Integer>[] ad;
	static int n, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.nextLine();
		int[][] dp = new int[n + 1][n + 1];
		dp[1][1] = 1;
		for (int l = 2; l <= n; l++) {
			for (int i = 1; i <= l; i++) {
				dp[l - 1][i] += dp[l - 1][i - 1];
				if (dp[l - 1][i] >= mod)
					dp[l - 1][i] -= mod;
			}
			for (int num = 1; num <= l; num++)
				if (s.charAt(l - 2) == '>') {
					dp[l][num] += dp[l - 1][l-1] - dp[l - 1][num-1]+mod;
					if (dp[l][num] >= mod)
						dp[l][num] -= mod;
				} else {
					dp[l][num] += dp[l - 1][num-1] ;
					if (dp[l][num] >= mod)
						dp[l][num] -= mod;
				}
		}
		int ans = 0;
		for(int i=1;i<=n;i++) {
			ans+=dp[n][i];
		 if(ans>=mod)
			 ans-=mod;
		}
		System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

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

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

    int max = vec.at(0);
    int cnt = 1;
    for (int i = 1; i < N; i++)
    {
        if (max <= vec.at(i))
        {
            cnt++;
            max = vec.at(i);
        }
    }
    cout << cnt << endl;
}

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

int main() {
  int N,i,time=0,tMax=0;
  cin>>N;
  vector<int> D1(N),D2(N);
  for (i=0;i<N;i++) {
    cin>>D1[i]>>D2[i];
    if (D1[i]==D2[i]) {
      time++;
      tMax = max(tMax, time);
    }
    else time=0;
  }
  cout<<(tMax>=3 ? "Yes" : "No")<<endl;
  return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;

void solve() {
  int H, A;
  cin >> H >> A;
  int ans = 0;
  while (H > 0) {
    H -= A;
    ans++;
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

const int MAXN = 100 + 5,MAXK = 1e5 + 5;
const long long MOD = 1e9 + 7;

using namespace std;

int n,k,v[MAXN];
long long dp[MAXN][MAXK],mars[MAXK];

int main()
{
    ///dp[i + 1][j + ceva] += dp[i][j], ceva = [0,a[i + 1]]
    ///j,j + 1,j + 2... j + cva
    ///mars[j] += dp[i][j], mars[j + a[i + 1] + 1] -= dp[i][j]
    cin>>n>>k;
    for(int i = 1; i <= n; i++)
        cin>>v[i];
    for(int j = 0; j <= v[1]; j++)
        dp[1][j] = 1;
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= k; j++)
            mars[j] = 0;
        for(int j = 0; j <= k; j++){
            mars[j] += dp[i - 1][j];
            mars[j] %= MOD;
            if(j + v[i] + 1 < MAXK){
                mars[j + v[i] + 1] -= dp[i - 1][j];
                mars[j + v[i] + 1] %= MOD;
            }
        }
        for(int j = 0; j <= k; j++){
            mars[j] += mars[j - 1];
            mars[j] %= MOD;
        }
        for(int j = 0; j <= k; j++)
            dp[i][j] = mars[j];
    }
    dp[n][k] %= MOD;
    dp[n][k] = (dp[n][k] + MOD) % MOD;
    cout<<dp[n][k];
    return 0;
}



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

int main() {
	int n,k;
	cin >> n >> k;
	vector<long long> a(n);
	for (int i=0; i<n; i++) cin >> a[i];
	sort(a.begin(),a.end());
	int ans=1e9;
	for (int i=0; i<=n-k; i++){
		if (a[i+k-1]-a[i]<ans) ans=a[i+k-1]-a[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int i;
  long long N;
  rd(N);
  long long res = 0;
  for(i=(1);i<(N);i++){
    res += (N-1) / i;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200916-1

// --- original code ---
// {
//   ll @N, res = 0;
//   rep(i,1,N) res += (N-1) / i;
//   wt(res);
// }


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N%2==0){
            System.out.println("0.5");
        }else{
            double a = (N+1)/2;
            System.out.println(a/N);
        }
    }
}


Measured memory_bytes: 21716
# import bisect
# import heapq
# from copy import deepcopy
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
s = deque(input())
q = int(input())
rev = False
for i in range(q):
    que = input()
    if que[0] == '1':
        rev = not rev
    else:
        que = list(que.split())
        if (int(que[1])==1 and not rev) or (int(que[1])==2 and rev):
            s.appendleft(que[2])
        else:
            s.append(que[2])

if rev: ans = ''.join(reversed(s))
else: ans = ''.join(s)
print(ans)


Measured memory_bytes: 75224
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	int N,i,len;
	char S[10000];

	cin>>N;
	cin>>S;

	len=strlen(S);

	for(i=0;i<len;i++){
		S[i]+=N;
		if(S[i]>'Z') S[i]-=26;
	}

	cout<<S<<endl;
	return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < s.length(); j++) {
			if (i % 2 == 0) {
				if (j % 2 == 0) {
					if (s[j] == '0')a++;
				}
				else {
					if (s[j] == '1')a++;
				}
			}
			else {
				if (j % 2 != 0) {
					if (s[j] == '0')b++;
				}
				else {
					if (s[j] == '1')b++;
				}
			}
		}
	}
	cout << min(a, b) << endl;

	return 0;
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/abc095/tasks/abc095_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  string s;
  int r = 700;

  cin >> s;

  for (size_t i = 0; i < s.length(); i++)
  {
    if (s[i] == 'o')
      r += 100;
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
S = input()

S = S[::-1]

L = ['dream', 'dreamer', 'erase', 'eraser']
L = [[l[::-1], len(l)] for l in L]


can = True
ind = 0
S_max = len(S)

while can:
    
    if ind == S_max:
        break

    for l in L:
        if ind + l[1] > S_max:
            pass
        else:
            if l[0] == S[ind: ind+l[1]]:
                ind += l[1]
                break
    else:
        can = False

if can:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


void solve() {
	ll a, b, k;
	cin >> a >> b >> k;
	ll t = a;
	a -= min(a, k);
	k -= min(t, k);
	b -= min(b, k);
	cout << a << " " << b << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 



Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
    while(1){
        int n,m,p;
        scanf("%d%d%d",&n,&m,&p);
        if(n+m+p==0) break;
        int x[100];
        int sum=0;
        for(int i=0;i<n;i++){
            scanf("%d",&x[i]);
            sum+=x[i];
        }
        sum*=100; sum=sum*(100-p)/100;
        if(x[m-1]==0) printf("0\n");
        else printf("%d\n",sum/x[m-1]);
    }
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    ll k=0;
    go(i,0,s.size()){
        if(s[i]==t[i]) k++;
    }
    show(k);
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main(){
	int n, m, l, i, j, k;
	int a[100][100], b[100][100];
	long int s;


	scanf("%d%d%d", &n, &m, &l);

	/* aの行列 */
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}

	/* bの行列 */
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			scanf("%d", &b[i][j]);
		}
	}


	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			s = 0;
			for (k = 0; k < m; k++) {
				s += a[i][k] * b[k][j];
			}
			printf("%ld", s);
			if (j + 1 == l) {
				printf("\n");
			}
			else {
				printf(" ");
			}
		}
	}

	return 0;
}


Measured memory_bytes: 2148
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    var s = cin.nextLine()
    val p = cin.nextLine()    
    s += s
    
    //if(s.contains(p)) println("Yes") else println("No")

    var res:Int = 0
    for(i in 0..s.length/2-1){
        for(j in 0..p.length-1){
	        if(s[i+j] == p[j]) res++ else res = 0
	        //print(res)
        }
	    if(res == p.length) break
	    res = 0
    	//println()	
    }
    if(res == p.length) println("Yes") else println("No")

}



Measured memory_bytes: 25628
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	int N, A, B;

	cin >> N >> A >> B;

	int P[N];
	int p1=0, p2=0, p3=0;

	for(int i = 0; i < N ; i++){
		cin >> P[i];
		if(A >= P[i]){
			p1++;
		} else if (B < P[i]){
			p3++;
		} else {
			p2++;
		}
	}

	cout << min(min(p1,p2),p3) << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

""" Input
N = int(input())
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

S = input().rstrip()
T = input().rstrip()

print('Yes' if S == T[:-1] else 'No')



Measured memory_bytes: 8968
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 0か1の連続している人数のリスト、累積和
streak = [0, 0]
N, K = lr()
S = sr() + '2'
cur = 1
for i in range(N):
    if S[i] != S[i+1]:
        streak.append(cur)
        cur = 1
    else:
        cur += 1

streak_cum = list(itertools.accumulate(streak))
streak_cum.extend([streak_cum[-1], streak_cum[-1]])
if S[0] == '0':
    start = 0
else:
    start = 1
answer = 0

limit = len(streak_cum) - 1
for i in range(start, len(streak_cum), 2):
    result = streak_cum[min(limit, i+2*K+1)] - streak_cum[i]
    if result > answer:
        answer = result

print(answer)
# 52

Measured memory_bytes: 7924
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
n = int(input())
data = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    data[a].append([b,c])
    data[b].append([a,c])

dist = [-1 for i in range(n)]
q,k = map(int,input().split())
k -= 1
dist[k] = 0

def dfs(now,pre,d):
    dist[now] = d
    for p,q in data[now]:
        if p == pre:
            continue
        dfs(p,now,d+q)

dfs(k,-1,0)

for i in range(q):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    print(dist[x]+dist[y])

Measured memory_bytes: 209328
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
# def slv(N, M, AB):
#     @lru_cache(maxsize=None)
#     def f(done, day):
#         print(day)
#         if day == M:
#             b = 0
#             for i, d in enumerate(done):
#                 if d == '0':
#                     continue
#                 b += AB[i][1]
#             return b
        
#         ans = 0
#         d_ = [d for d in done]
#         for i, d in enumerate(done):
#             if d == 1 or M - day < AB[i][0]:
#                 continue
#             d_[i] = '1'
#             ans = max(ans, f(''.join(d_), day+1))
#             d_[i] = '0'
#         ans = max(ans, f(''.join(d_), day+1))
#         return ans
#     return f('0'*N, 0)


@mt
def slv(N, M, AB):
    ans = 0
    cand = []
    AB.sort(key=lambda x: x[0], reverse=True)
    for i in range(1, M+1):
        while AB and AB[-1][0] <= i:
            a, b = AB.pop()
            heapq.heappush(cand, -b)
        if cand:
            ans -= heapq.heappop(cand)
    return ans 

def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, M, AB))

    # N = 10**5
    # M = 10**5
    # AB = [[random.randint(1, 10**5), random.randint(1, 10**4)] for _ in range(N)]
    # print(slv(N, M, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 31332
#include<bits/stdc++.h>
using namespace std;
 
#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define MAXN 1000000
#define pb push_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
ll maxu = INT_MAX;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    ll a1,a2,a3;
    cin>>a1>>a2>>a3;
    if(a1+a2+a3>=22)
    cout<<"bust";
    else
    {
        cout<<"win";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    cin >> a;
    int ans = INF;
    for (int x : a) {
        vector<int> rem, block;
        for (int y : a) {
            if (y < x) {
                sort(all(block));
                int sz = (int)block.size();
                forn(i, 0, sz - k + 1)
                    rem.eb(block[i]);
                block.clear();
            } else block.eb(y);
        }
        {
            sort(all(block));
            int sz = (int)block.size();
            forn(i, 0, sz - k + 1)
                rem.eb(block[i]);
        }
        sort(all(rem));
        if ((int)rem.size() < q) continue;
        setmin(ans, rem[q - 1] - rem[0]);
    }
    cout << ans << '\n';
}


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

const int INF = 1<<29;
int dp[1005][1005]; //d[i][j]:=s1...siとt1...tjの編集距離

int main(){
    string X, Y;
    cin >> X;
    cin >> Y;

    for(int i=0; i<=X.size(); i++)for(int j=0; j<=Y.size(); j++) dp[i][j] = INF;
    for(int i=0; i<=X.size(); i++) dp[i][0]=i;
    for(int i=0; i<=Y.size(); i++) dp[0][i]=i;

    for(int j=0; j<X.size(); j++){
        for(int k=0; k<Y.size(); k++){
            int cost = (X[j]==Y[k])?0:1;
            dp[j+1][k+1] = min(dp[j][k]+cost, min(dp[j][k+1], dp[j+1][k])+1);
        }
    }
    cout << dp[X.size()][Y.size()] << endl;
}



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

int main(){
    int N;
    string S;
    cin>>N;
    cin >> S;
    for (int a = 0; a < S.size(); a++){
        if('Z'-S.at(a) > N-1){
            S.at(a) += N;
        }else{
            S.at(a) = 'A' - 1 + N - ('Z' - S.at(a));
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n, m, a;
	while (cin >> n >> m&&n != 0 && m != 0) {
		vector<int> map;
		int pos = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			map.emplace_back(a);
		}
		for (int i = 0; i < m; i++) {
			cin >> a;
			pos += a;
			if (pos >= n - 1) {
				cout << i+1 << endl;
				for (int j = 0; j < m - 1 - i; j++) {
					cin >> a;
				}
				break;
			}
			pos += map[pos];
			if (pos >= n - 1) {
				cout << i+1 << endl;
				for (int j = 0; j < m - 1 - i; j++) {
					cin >> a;
				}
				break;
			}
		}
	}
}

Measured memory_bytes: 3016
n=int(input())
l=[*map(int,input().split())]
from math import *
g=l[0]
for x in l:
  g=gcd(g,x)
if g>1: exit(print('not coprime'))
from collections import *
d=Counter()
b=0
for x in l:
  if x%2<1:
    if d[2]:
      b=1
      break
    d[2]=1
  while x%2<1: x//=2
  for i in range(3,int(x**0.5)+1,2):
    if x%i<1:
      if d[i]:
        b=1
        break
      d[i]=1
    while x%i<1: x//=i
    if x<2: break
  if x>1:
    if d[x]:
      b=1
      break
    d[x]=d.get(x,0)+1
print(['pair','set'][b]+'wise coprime')

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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

int find_lower(int *a, int n, int v){
    int l = -1, r = n;

    while (r-l > 1){
        int m = (l+r)/2;
        if (a[m] <= v) l = m;
        else r = m;
    }
    return l;
}

void init(){
}

int bin(int *p, int n, int x){
    int l = 0, r = n-1;
    while (r >= l){
        int m = (l+r)/2;
        if (p[m] == x) return m;
        if (p[m] > x) r = m-1;
        else l = m+1;
    }
    return -1;
}

bool ok(vector<int> a, int k, int x){ //n=6, k=4, x=4, a={1,2,3,4,5,6}
    int n = (int) a.size(); 
    int s = 0;
    int z = 0;
    while (n-z >= k){
        sort(a.rbegin(), a.rend());
        int g = 0;
        for (int i = 0; i < n && g < k; i++){
            if (a[i] > 0){
                g++;
                a[i]--;
                if (a[i] == 0) z++;
            }
        }
        if (g == k) s++;
    }
    return s >= x;
}

void solve(){
    int h, n;
    cin >> h >> n;
    vi a(n);
    int s = 0;
    forn{
        cin >> a[i];
        s += a[i];
    }
    if (s >= h) cout << "Yes\n";
    else cout << "No\n";
}

int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3956
/*input
3 4 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<((a==b&&b==c)?"Yes\n":"No\n");
	return 0;
}


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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v ) {
        os << (a ? "" : " "); 
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.to << ", " << e.cost << ")";
    return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

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

    vector<int> ord(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j) {
            return B[i] < B[j];
            });

    LL t = 0;
    bool ans = true;
    for (int i = 0; i < N; ++i) {
        t += A[ord[i]];
        if (t > B[ord[i]]) {
            ans = false;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

ll dp[11000];

int main() {
    ll h, n; cin >> h >> n;
    rep(i, 11000) dp[i] = INF;
    dp[0] = 0;
    rep(i, n) {
        int a, b; cin >> a >> b;
        rep(j, h) chmin(dp[min(h, j+a)], dp[j] + b);
    }
    cout << dp[h] << endl;
    //rep(i, h+3) cout << dp[i] << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


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


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


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

const int MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/


int main() {

	int a, b;
	cin >> a >> b;
	if (b == 1) {
		cout << "0" << endl;
	}
	else
	{
		cout << a - b << endl;
	}



	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	stock := 0
	ans := len(s)
	for _, r := range s {
		switch r {
		case 'S':
			stock++
		case 'T':
			if stock > 0 {
				stock--
				ans -= 2
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1920
#define _[301][301]
N,M,i,j,t,r,C _,D _;char S _;main(v){for(scanf("%d%d ",&N,&M);gets(S+i++););for(;++t<M;r+=v)for(i=j=1;j>N?j=i++<N:1;++j)v=D[i][j]=fmin(D[i-1][j],D[i][j-1])+(C[i][j]=C[i-1][j-1]+(S[i-1][t-1]==S[j-1][t]));printf("%d\n",r);}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }

int main()
{
    int N, X, T;
    cin >> N >> X >>T;
    int a = N/X;
    int b = N%X;
    int ans = a*T;
    if(b >0) ans += T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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

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



int main(void) {
	int a, b;

	cin >> a >> b;

	if (b%a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}

	return 0;
}

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

int main() {
    stack<int> s1;
    stack<pair<int, int> > s2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') {
            s1.push(i);
        }
        else if (ch == '/' && s1.size() > 0) {
            int j = s1.top(); s1.pop();
            sum += i - j;
            int a = i - j;
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second; s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (s2.size() > 0) {
        ans.push_back(s2.top().second); s2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
}



Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

const int MAX = 500;
ll trains[MAX + 1][MAX + 1];
ll cft[MAX + 1][MAX + 1];

int main() {
    string s;
    cin >> s;
    ll k;
    cin >> k;
    
    ll pos1 = 0;
    while (s[pos1] == '1')
        pos1++;
    if (pos1 < k) {
        cout << s[pos1] << endl;
    } else {
        cout << 1 << endl;
    }
    
}



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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if((e-a) <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define _GLIBCXX_DEBUG
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  ll N, K;cin >> N >> K;
  vector<ll> A(N, 0);
  rep(i, K) {
    ll d;cin >> d;
    rep(j, d) {
      ll a;cin >> a;
      A[a - 1]++;
    }
  }
  int Ans = 0;
  rep(i, N) {
    if (A[i] == 0) Ans++;
  }
  cout << Ans << endl;
}

Measured memory_bytes: 3628
K = int(input())
X,Y = map(int,input().split())
dis = abs(X)+abs(Y)
if K % 2 == 0 and dis % 2 == 1:
    print(-1)
    exit()
time = -(-dis//K)
if time == 1:
    if dis != K:
        time += 1
if (time*K) % 2 != dis % 2:
    time += 1
print(time)
detour = (time*K-dis)//2
Xdir = 1
Ydir = 1
Xdis = abs(X)
Ydis = abs(Y)
Xcur = 0
Ycur = 0
if X < 0:
    Xdir = -1
if Y < 0:
    Ydir = -1
while time:
    if detour > 0:
        if detour <= K:
            if Ydis >= K-detour:
                Xcur += -Xdir*detour
                Xdis += detour
                Ycur += Ydir*(K-detour)
                Ydis -= K-detour
                detour = 0
            else:
                Ycur += -Ydir*detour
                Ydis += detour
                Xcur += Xdir*(K-detour)
                Xdis -= K-detour
                detour = 0
        else:
            Ycur += -Ydir*K
            Ydis += K
            detour -= K
    else:
        if Xdis >= K:
            Xdis -= K
            Xcur += Xdir*K
        else:
            Ycur += Ydir*(K-Xdis)
            Ydis -= K-Xdis
            Xcur += Xdir*Xdis
            Xdis = 0
    print(Xcur,Ycur)
    time -= 1

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}



int main()
{
	int r;cin>>r;
    cout<<r*r<<endl;
}

 
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, K, X[1000000], sum = 0;
    cin >> N >> K;
    REP(i, N) cin >> X[i];

    int ans = 1000000000;
    FOR(i, K, N + 1) {
        ans = min(ans, X[i - 1] - X[i - K] + min(abs(X[i - 1]), abs(X[i - K])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int h,n,sum;
    cin >> h >> n;
    int a[n];
    sum = 0;
    for (int i = 0; i < n; i++ ){
        cin >> a[i];
        sum += a[i];
    }

    if((h - sum) <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(LL i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define FF first
#define SS second
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr> PQ;
const ut INF=1<<30;
const LL p=3+1e6;
const int SIZE=100005;
int main(){
	LL A,B,C;
	cin >> A >> B >> C;
	if(A&B&C&1){
		cout << min(A*B,min(B*C,A*C)) << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  bool ans = false;
  sort(s.begin(), s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ans = true;
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
int MOD = 998244353;

ll add(ll a, ll b)
{
	a+=b; a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	if(a>MOD) a%=MOD;
	if(b>MOD) b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

const bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll n,X; cin>>n>>X>>MOD;
	set<ll> s;
	vi v;
	while(s.find(X)==s.end())
	{
		v.pb(X);
		s.insert(X);
		X=pw(X,2);
	}
	
	ll ans=0;
	reverse(v.begin(), v.end());
	while(v.back()!=X)
	{
		ans+=v.back();
		v.pop_back(); n--;
		if(n==0)
		{
			cout<<ans<<'\n';
			return 0;
		}
	}
	reverse(v.begin(), v.end());
	
	ll sum=0;
	for(ll x: v) sum+=x;
	
	forn(i,0,n%v.size()) ans+=v[i];
	ans+=sum*(n/v.size());
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 5924
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') {
        cout << a + b << endl;
    } else {
        cout << a - b << endl;
    }
}


Measured memory_bytes: 256