akhauriyash/Code-Regression huggingface dataset:
//https://discuss.codechef.com/t/robagain-editorial/20734
#pragma GCC optimize("O3")
#include<queue>
#include <cmath>
#include <complex>
#include<map>
#include <string>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>


/*
#define x real()
#define y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
*/

//#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
#define NOT(x) (1^x)

const double PI  = acos(-1.0);
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
typedef complex<double> point;

//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//const int N=500009,M=1000000;
const double EPS= 1e-9,eps=-1e9;
const int N =500005;

int n,m,l;
pii ans[303][303];
vector<pair<int,int>>a[303];

void get(int s)
{
    priority_queue<pair<pii,int>,vector<pair<pii,int>>,greater<pair<pii,int>>>q;
    q.push({{0,0},s});
    ans[s][s]={0,0};
    while(q.size())
    {
        int u=q.top().S;
        pii k=q.top().F;
        q.pop();
        if(k>ans[s][u])continue;
        for(auto v:a[u])
        {
            if(v.S+k.S<=l)
            {
                pii t={ans[s][u].F,v.S+k.S};
                if(t<ans[s][v.F]){
                ans[s][v.F]=t;
                q.push({ans[s][v.F],v.F});
                }
            }
            else
            {
                pii t={ans[s][u].F+1,v.S};
                if(t<ans[s][v.F]){
                ans[s][v.F]=t;
                q.push({ans[s][v.F],v.F});
                }
            }
        }

    }
}
 int main()
{
//freopen("travel.in","r",stdin);
//freopen("travel.out","w",stdout);
//__builtin_popcount()
input;


      cin>>n>>m>>l;
      int u,v,c;
      forr(i,1,m)
      {
          cin>>u>>v>>c;
          if(c>l)continue ;
          a[u].push_back({v,c});
          a[v].push_back({u,c});
      }
      forr(i,1,n)forr(j,1,n)ans[i][j]={1e18,1e18};
      forr(i,1,n)get(i);
      int q,s,e;
      cin>>q;
      while(q--)
      {
          cin>>s>>e;
          if(ans[s][e].F==1e18)cout<<"-1"<<endl;
          else cout<<ans[s][e].F<<endl;
      }



return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s;
    ll k;
    cin >> s >> k;

    char res = '1';
    int oneidx = 0;
    rep(i, s.length()){
        if(s[i] != '1') {
            res = s[i];
            oneidx = i;
            break;
        }
    }

    if(k<=oneidx) cout << 1 << endl;
    else cout << res << endl;;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int n,m;



int main()
{
    cin >> n >> m;
    vii a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    rep(i, n - 1)
    {
        if (a[i] == a[i + 1])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, m - 1)
    {
        if (b[i] == b[i + 1])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    repr(now,n*m,0){
        int aidx = lower_bound(all(a), now) - a.begin();
        int bidx = lower_bound(all(b), now) - b.begin();
        ll atar = n - aidx, btar = m - bidx;
        ll kimeta = n * m  - now;
        if (a[aidx]==now && b[bidx]==now){
            continue;
        }
        else if(a[aidx]==now){
            ans = (ans * btar) % mod;
        }
        else if(b[bidx]==now){
            ans = (ans * atar) % mod;
        }
        else {
            ans = (ans * ((atar * btar) % mod + mod - kimeta) % mod) % mod;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m, k;

set<int> s[30];
set<int>::iterator it1, it2;
char ch[maxn];
int main()
{
    scanf("%d", &n);
    scanf("%s", ch + 1);
    for(int i=1;i<=n;i++)s[int(ch[i] - 'a')].insert(i);
    int q;scanf("%d", &q);
    while(q--){
        int type, x, y;
        scanf("%d%d", &type, &x);
        if(type == 1){
            char c[2];
            scanf("%s", c);
            s[int(ch[x] - 'a')].erase(x);
            s[int(c[0] - 'a')].insert(x);
            ch[x] = c[0];
        }
        else{
            scanf("%d", &y);
            //cout << q << " " << x << ' ' << y << '\n';
            int ans = 0;
            for(int i=0;i<26;i++){
                //cout<<"i = " << i << ' ' << ans << '\n';
                //for (auto val : s[i])cout << val << ' '; cout << "\n";
                if(s[i].count(x) > 0 || s[i].count(y) > 0)ans++;
                else{
                    it1 = s[i].upper_bound(x);
                    it2 = s[i].upper_bound(y);
                    if(it1 != s[i].end() && *it1 <= y)ans++;
                }
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}


Measured memory_bytes: 26240
import sys
#import copy
#import math
#import bisect
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

numbers = "0123456789"
characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def base_cvt(value:int, n=26):
    quot = value//n
    rest = value%n
    base = characters[rest]
    tmp = quot
    while quot >= 1:
        quot = (tmp-1)//n
        rest = (tmp-1)%n
        base = characters[rest] + base
        tmp = quot
    return base

def main():
    N = int(input())
    ans = base_cvt(N-1)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll f(ll *x,ll n,ll p){
	ll sum=0;
	rep(i,n){
		sum+=pow((x[i]-p),2);
	}
	return sum;
}

int main(){
	ll n;
	cin >> n;
	ll x[n];
	cinf(x,n);
	sort(x,x+n);
	ll left=x[0];
	ll right=x[n-1];
	ll min=f(x,n,left);
	arep(left+1,i,right+1){
		ll tmp=f(x,n,i);
		if(tmp<min)min=tmp;
	}
	cout << min << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  if i%2==0:
    b[0]+=a[i]
  else:
    b[0]-=a[i]
    
for i in range(1,n):
  b[i]=2*a[i-1]-b[i-1]
  
print(' '.join(map(str,b)))




Measured memory_bytes: 19224
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]

s_lst=[]

for i in range(n):
    tmp_dist=11451419191919
    tmp_ans=0
    for j in range(m):
        if tmp_dist>abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]):
            tmp_dist=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
            tmp_ans=j
    print(tmp_ans+1)


Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
	int N=0,M=0,sum=0;
	//1<=N<=100
	scanf("%d",&N);
	
	for(int M=1;M<=N;M++)
	
	
	sum+=M;
	
	printf("%d",sum);
	  
	
	
	return 0;
	
	
	
	
	
	
	
	
	
	
	
 } 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, L; std::cin >> N >> L;
  std::vector<std::string> S(N);
  rep(i,N) std::cin >> S[i];
  std::sort( all(S) );
  for(int i=0; i<sz(S); i++) std::cout << S[i];
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    A,B,N = [int(item) for item in input().split()]

    def func(x):
        first = int(A * x / B)
        second = A * int(x/B)
        return first - second

    if N >= B:
        print(func(B-1))
    else:
        print(func(N))
        

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9084
import java.util.*;

public class Main {
	int n, sum;
	String[] f;
	int[] w, s, memo, ans;
	double min;
	
	public void loop(int m, int gsum, int wsum){
		if(m==n){
			if(min>(double)gsum/wsum){
				min = (double)gsum/wsum;
				for(int i=0;i<n;i++) ans[i] = memo[i];
			}
			return;
		}
		
		for(int i=0;i<n;i++){
			boolean flag = true;
			for(int j=0;j<m;j++){
				if(memo[j]==i) flag = false;
			}
			if(flag==true){
				memo[m] = i;
				if(sum-wsum-w[i]<=s[i]){
					loop(m+1, gsum+(m+1)*w[i], wsum+w[i]);
				}
			}
		}
	}
	
	public void run(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			if(n==0) break;
			
			f = new String[n];
			w = new int[n];
			s = new int[n];
			memo = new int[n];
			Arrays.fill(memo, -1);
			ans = new int[n];
			sum = 0;
			min = Integer.MAX_VALUE;
			for(int i=0;i<n;i++){
				f[i] = sc.next();
				w[i] = sc.nextInt();
				s[i] = sc.nextInt();
				sum += w[i];
			}
			loop(0,0,0);
			for(int i=0;i<n;i++) System.out.println(f[ans[i]]);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 22376
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define db double
#define ld long double
#define IOS  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#pragma GCC optimize(2)
#define ull unsigned long long
#define maxn 110
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
void dfs(){}
int dp[maxn][maxn];
signed main()
{
    IOS
    int num;
    cin>>num;
    memset(dp,0, sizeof(dp));
    for (int k = 0; k <=9 ; ++k) {
        dp[1][k]=1;
    }
    for (int i = 2; i <=10 ; ++i) {
        for (int j = 0; j <=9 ; ++j) {
            dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
        }
    }
    queue<int> ans;
    int l=0, r = 0,fl=0;
    for (int j = 1; j <=10 ; ++j) {
        for (int i = 1; i <=9 ; ++i) {
            if(num<=dp[j][i]){
                l=j;
                r=i;
                fl=1;
                break;
            }
            num-=dp[j][i];
        }
        if(fl==1)break;
    }
    l--;
    ans.push(r);
    while(l!=0){
        if(num<=dp[l][r-1]){
            r--;
            ans.push(r);
        }else{
            num-=dp[l][r-1];
            if(num<=dp[l][r]){
                ans.push(r);
            }else{
                num-=dp[l][r];
                r++;
                ans.push(r);
            }
        }
        l--;
    }
    while(!ans.empty()){
        int now=ans.front();
        cout<<now;
        ans.pop();
    }
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second

typedef long long ll;

int N,M,W,H,K,A,B,S;
const int mn = 1002,mhw = 2000000;

using namespace std;

int main() {
    cin >> H >> W;
    vector<vector<char>> bw(mn,vector<char>(mn,'x'));
    reps(i,1,H+1){
        reps(j,1,W+1){
            cin >> bw.at(i).at(j);
        }
    }

    vector<vector<int>> vdr(mn,vector<int>(mn,mhw));
    vector<vector<int>> vdl(mn,vector<int>(mn,mhw));
    vector<vector<int>> vur(mn,vector<int>(mn,mhw));
    vector<vector<int>> vul(mn,vector<int>(mn,mhw));

    reps(i,1,H+1){
        reps(j,1,W+1){
            if(bw.at(i).at(j) == '#'){
                vdr.at(i).at(j) = 0;
                vdl.at(i).at(j) = 0;
                vur.at(i).at(j) = 0;
                vul.at(i).at(j) = 0;
            }
        }
    }


    reps(i,1,H+1){
        reps(j,1,W+1){
            vdr.at(i).at(j) = min(vdr.at(i-1).at(j)+1,vdr.at(i).at(j));
            vdr.at(i).at(j) = min(vdr.at(i).at(j-1)+1,vdr.at(i).at(j));
        }
    }
    reps(i,1,H+1){
        for(int j = W; j > 0; j--){
            vdl.at(i).at(j) = min(vdl.at(i-1).at(j)+1,vdl.at(i).at(j));
            vdl.at(i).at(j) = min(vdl.at(i).at(j+1)+1,vdl.at(i).at(j));
        }
    }
    for(int i = H; i > 0; i--){
        for(int j = W; j > 0; j--){
            vul.at(i).at(j) = min(vul.at(i+1).at(j)+1,vul.at(i).at(j));
            vul.at(i).at(j) = min(vul.at(i).at(j+1)+1,vul.at(i).at(j));
        }
    }
    for(int i = H; i > 0; i--){
        reps(j,1,W+1){
            vur.at(i).at(j) = min(vur.at(i+1).at(j)+1,vur.at(i).at(j));
            vur.at(i).at(j) = min(vur.at(i).at(j-1)+1,vur.at(i).at(j));
        }
    }
    
    int ans = 0;
    int temp;
    reps(i,1,H+1){
        reps(j,1,W+1){
            temp = min(vdr.at(i).at(j),vdl.at(i).at(j));
            temp = min(temp,vur.at(i).at(j));
            temp = min(temp,vul.at(i).at(j));
            ans = max(ans,temp);
            //cout << bw.at(i).at(j) << endl;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 17152
/*
g++ -std=c++11 -o2 -Wall ABC110C.cpp -o .\out\ABC110C.out
.\out\ABC110C.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int ss[30];
int ts[30];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    ss[s[i] - 'a'] += 1;
  }
  cin >> t;
  for (int i = 0; i < n; ++i) {
    ts[t[i] - 'a'] += 1;
  }
  sort(begin(ss), end(ss));
  sort(begin(ts), end(ts));
  for (int i = 0; i < 30; ++i) {
    if (ss[i] != ts[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> basic(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++)
      cin >> basic.at(i).at(j);
  }
    
  for (int i = 0; i < H; i++) {
    bool flagH = false;
    for (int j = 0; j < W; j++) {
      if (basic.at(i).at(j) == '#')
        flagH = true;
    }
    if (flagH == true) {
      for (int j = 0; j < W; j++) {
        bool flagW = false;
        for (int k = 0; k < H; k++) {
          if (basic.at(k).at(j) == '#')
            flagW = true;
        }
        if (flagW  == true)
          cout << basic.at(i).at(j);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1
    j = 0
    l = len(S)
    A[0] = l
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A


n = int(input())
s = input()


ans = 0
for i in range(n - 1):
    r = z_algo(s[i:])
    for j in range(1, len(r)):
        if r[j] <= j:
            ans = max(ans, r[j])
print(ans)


Measured memory_bytes: 49116
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */



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

  int N,K;
  cin >> N >> K;
  cout << N-K+1 << endl;

  return 0;
}

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

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string t; cin >> t;
    for (auto &c: t) {
        if (c == '?') c = 'D';
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3780
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);;
		double r = scan.nextDouble();

		System.out.println(String.format("%.8f", r * r * Math.PI) + " " + String.format("%.8f", 2 * r * Math.PI));
		scan.close();
	}
}


Measured memory_bytes: 28264
n, t = gets.chomp.split.map(&:to_i)
costs = []
result = 0
n.times do
  costs.push(gets.chomp.split.map(&:to_i))
end
costs.each do |cost|
  if cost[1] <= t
    if result == 0
      result = cost[0]
    else
      result = cost[0] if cost[0] <= result
    end
  end
end
puts result == 0 ? 'TLE' : result


Measured memory_bytes: 1788
def NtoY(N):
    D = (N-1)//10 + 1
    Y = (D-1)//365 + 1
    return(Y)

while True:
    n = int(input().strip())
    if n == 0:
        break
    elif n == 1:
        print(NtoY(1))
    elif n == 2:
        print(NtoY(2))
    else:
        lst = [0 for i in range(0,n+1)]
        lst[0] = 1
        lst[1] = 1
        lst[2] = 2
        for i in range(0,n-2):
            lst[i+3] = lst[i+2] + lst[i+1] + lst[i]
        print(NtoY(lst[n]))



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

using namespace std;

const double PI = 3.14159265358979;

int G[101][101];
int visited[101];
int n;

int houxuan[101];
int father[101];

int prim() {

	for (int i = 0; i < n; i++)	{
		houxuan[i] = INT_MAX;
		father[i] = -1;
	}
	houxuan[0] = 0;

	int sum = 0;
	while (true) {

		int minx = INT_MAX;
		int u = -1;
		for (int i = 0; i < n; i++) {

			if (!visited[i] && houxuan[i] < minx) {
				minx = houxuan[i];
				u = i;
			}
		}
		if (u == -1) break;

		visited[u] = 1;
		sum += minx;

		for (int i = 0; i < n; i++) {
			if (!visited[i] && G[u][i] != -1) {
				if (houxuan[i] > G[u][i]) {
					houxuan[i] = G[u][i];
					father[i] = u;
				}
			}
		}
	}	

	return sum;
}

int main() {
	
	
	cin >> n;

	for (int i = 0; i < n; i++)	{
		for (int j = 0; j < n; j++)	{
			cin >> G[i][j];
		}
	}
	
	cout << prim() << endl;

	return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int dpdot[200005],dpsq[200005];
int main()
{
    int n;
    string s;
    cin >> n >> s;
    for(int i=1;i<=n;i++)
    {
        if(s[i-1]=='#') dpsq[i]++;
        else dpdot[i]++;
        dpdot[i]+=dpdot[i-1];
        dpsq[i]+=dpsq[i-1];
    }
    int ans=1e9;
    for(int i=0;i<=n;i++) ans=min(ans,dpsq[i]+dpdot[n]-dpdot[i]);
    cout << ans;
}


Measured memory_bytes: 2180
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


print(1-I())


Measured memory_bytes: 61692
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = map(int, raw_input().split())
if K > (N - 1) * N / 2 - (N - 1):
    print -1
    exit()
M = (N - 1) * N / 2 - K
print M
for i in range(2, N + 1):
    print 1, i
cnt = 0
for i in range(2, N + 1):
    for j in range(i + 1, N + 1):
        if cnt < K:
            cnt += 1
        else:
            print i, j

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

using namespace std;
using Long = long long;

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


	int x, y, a, b , c;
	cin >> x >> y >> a >> b >> c;

	vector<Long> red(a), green(b), uncolored(c);

	for (Long& v : red)
		cin >> v;

	for (Long& v : green)
		cin >> v;

	for (Long& v : uncolored)
		cin >> v;

	sort(begin(red), end(red), greater<Long>());
	sort(begin(green), end(green), greater<Long>());

	for (int i  = 0; i < x; ++i)
		uncolored.emplace_back(red[i]);

	for (int i = 0; i < y; ++i)
		uncolored.emplace_back(green[i]);

	sort(begin(uncolored), end(uncolored), greater<Long>());

	
	uncolored.resize(x + y);

	cout << accumulate(begin(uncolored), end(uncolored), 0ll);

	return 0;
}

Measured memory_bytes: 6256
from scipy.sparse.csgraph import floyd_warshall

N,M,L = list(map(int, input().split()))

edges = [[0] * N for _ in range(N)]

for _ in range(M):
    A,B,C = list(map(int, input().split()))
    edges[A-1][B-1] = C
    edges[B-1][A-1] = C

Q = int(input())
queries = []

for _ in range(Q):
    queries.append(list(map(int,input().split())))

# use flord warshall to find min path between all towns
edges = floyd_warshall(edges)

# if the two towns can be travelled to on one tank, add to our fuel graph with distance 1
for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

# use flord warshall to find min number of fuel tanks to travel between two towns
edges = floyd_warshall(edges)

for query in queries:
    s = query[0] - 1
    t = query[1] - 1
    num_tanks = edges[s][t] - 1
    if num_tanks != float('inf'):
        print(int(num_tanks))
    else:
        print("-1")


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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll a,b;
    cin>>a>>b;
    ll ans = 0;
    while(a<=b){
        a*=2;
        ans++;
    }
    cout<<ans<<'\n';

}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> data;
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        data.push(d);
    }
    for (int i = 0; i < M; i++) {
        int a = data.top();
        data.pop();
        data.push(floor(a / 2));
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int a = data.top();
        data.pop();
        ans += ll(a);
    }
    cout << ans << endl;

}


Measured memory_bytes: 3908
N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
BC = []
for m in range(M):
    BC.append([int(i) for i in input().split()])
    if BC[m][0] > N:
        BC[m][0] = N
BC = sorted(BC,reverse=True,key=lambda x: x[1])
change_list = []
for m in range(M):
    change_list.extend([BC[m][1] for _ in range(BC[m][0])])
    if len(change_list) >= N:
        change_list = change_list[0:N]
        break
A.extend(change_list)
A = sorted(A,reverse=True)
print(sum(A[0:N]))

Measured memory_bytes: 30908
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int l=s.size();
    vector<int> t(l+1,0);
    for(int i=0;i<l;i++){
        if(s[i]=='<'){
            t[i+1]=t[i]+1;
        }
    }
    for(int i=l;i;i--){
        if(s[i-1]=='>'){
            t[i-1]=max(t[i-1],t[i]+1);
        }
    }
    long long sum = 0;
    for(int i=0;i<=l;i++){
        sum+=t[i];
        //printf("%d ",t[i]);
    }//puts("");
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> p(a);
	rep(snip_i, a) cin >> p.at(snip_i);
	p.push_back(-1);
	vector<int> q(b);
	rep(snip_i, b) cin >> q.at(snip_i);
	q.push_back(-1);
	vector<int> r(c);
	rep(snip_i, c) cin >> r.at(snip_i);
	r.push_back(-1);
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());
	ll ans = 0;
	int pp, pq, pr;
	pp = pq = pr = 0;
	rep(i, x+y){
		int pa = p.at(pp), qa = q.at(pq), ra = r.at(pr);
		if(pp < x && pq < y){
			if(pa > qa){
				if(pa > ra){
					ans += pa;
					pp++;
				}else{
					ans += ra;
					pr++;
				}
			}else{
				if(qa > ra){
					ans += qa;
					pq++;
				}else{
					ans += ra;
					pr++;
				}
			}
		}else if(pp >= x){
			if(qa > ra){
				ans += qa;
				pq++;
			}else{
				ans += ra;
				pr++;
			}
		}else{
			if(pa > ra){
				ans += pa;
				pp++;
			}else{
				ans += ra;
				pr++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    int n,a,b;
    std::cin >> n>>a>>b;
    std::cout << min(a*n,b) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N, M;
    cin >> N >> M;
    vector<int> cnt(101010), cnt_mod(M);
    REP(i,N){
        int X;
        cin >> X;
        cnt[X]++;
        cnt_mod[X%M]++;
    }
    int ans = 0;
    REP(i,M){
        if(i == 0 || 2 * i == M){
            ans += cnt_mod[i] / 2;
            cnt_mod[i] %= 2;
        }
        else{
            int p = min(cnt_mod[i], cnt_mod[M-i]);
            ans += p;
            cnt_mod[i] -= p, cnt_mod[M-i] -= p;
            for(int j=i;j<101010;j+=M){
                ans += min(cnt_mod[i], cnt[j]) / 2;
                cnt_mod[i] -= min(cnt_mod[i], cnt[j]) / 2 * 2;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int manhatan(tuple<int,int, int> T, tuple<int,int, int> U){
    return abs((get<2>(T) - get<2>(U))) + abs((get<1>(T) - get<1>(U)));
}
int main(){
    int N,i,j,a,b,ans = 0;
    cin >> N;
    vector<tuple<int,int>> XY(0),YX(0),A(0);
    cin >> a >> b;
    tuple<int, int, int> OO = make_tuple(a + b,a,b), OX = make_tuple(a + (b * -1),a,b), XO = make_tuple((a * -1) + b,a,b), XX = make_tuple((a * -1) + (b * -1),a,b); // 合計、X、Y
    for(i = 1;i < N;i++){
        cin >> a >> b;
        if(a + b > get<0>(OO)){
            OO = make_tuple(a + b,a,b);
        }
        if (a + (b * -1) > get<0>(OX)){
            OX = make_tuple(a + (b * -1), a, b);
        }
        if (b + (a * -1) > get<0>(XO)){
            XO = make_tuple(b + (a * -1), a, b);
        }
        if ((a * -1) + (b * -1) > get<0>(XX)){
            XX = make_tuple((a * -1) + (b * -1), a, b);
        }
    }
    ans = max(ans,manhatan(OO,OX));
    ans = max(ans, manhatan(OO, XO));
    ans = max(ans, manhatan(OO, XX));
    ans = max(ans, manhatan(OX,XO));
    ans = max(ans, manhatan(OX,XX));
    ans = max(ans, manhatan(XO,XX));
    cout << ans << endl;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct node{
	struct node *left;
	struct node *right;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){//kに一致するノードを探す
	if (u == NIL){return NIL;}//なかた
	if (u->key == k){ return u; }//あた
	else if (u->key > k){
		return treeSearch(u->left, k);
	}
	else{
		return treeSearch(u->right, k);
	}
}

void treeDelete(Node z){
	Node tmp;

	if (z->left == NIL && z->right == NIL){//子なし
		if (z->parent->left == z){//zが親の左側に属していたら
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		free(z);
	}
	else if (z->left != NIL && z->right != NIL){//子2人
		tmp = z->right;//右側から最少を探す
		while (tmp->left != NIL){
			tmp = tmp->left;
		}
		z->key = tmp->key;
		treeDelete(tmp);		
	}
	else{//子1人
		if (z->left!=NIL){//左に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->left;
				z->left->parent = z->parent;
			}
			else{//zが親の右側にいたら
				z->parent->right = z->left;
				z->left->parent = z->parent;
			}
		}
		else{//右に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->right;
				z->right->parent = z->parent;
				free(z);
			}
			else{//zが親の右側にいたら
				z->parent->right = z->right;
				z->right->parent = z->parent;
			}
		}
	}
}

Node sss(int k, Node x){
	if (x == NIL){ return x; }//root
	if (k < x->key){
		if (x->left != NIL){
			return sss(k, x->left);
		}
		else{
			return x;
		}
	}
	else{
		if (x->right != NIL){
			return sss(k, x->right);
		}
		else{
			return x;
		}
	}
}

void insert(int k){
	Node y = sss(k,root);//入れるべき場所の親探し
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	z->parent = y;

	if (y == NIL){ root=z; }
	else if (y->key < k){//kが親キーより大きい
		y->right = z;
	}
	else{
		y->left = z;
	}
}

void inorder(Node u){
	if (u->left != NIL)
		inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL)
		inorder(u->right);	
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL)
		preorder(u->left);
	if (u->right != NIL)
		preorder(u->right);
}

int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}

Measured memory_bytes: 19360
#include<bits/stdc++.h>
using namespace std;
int main(){
  int l, r;
  long long ans = 2019;
  cin >> l >> r;
  if(r - l >= 2019) cout << 0 << endl;
  else {
    for(long long i = l; i < r; ++i){
      for(long long j = i + 1; j <= r; ++j){
        if((i * j) % 2019 == 0){
          cout << 0 << endl;
          return 0;
        }
        ans = min(ans, (i * j) % 2019); 
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
S = list(input())
# print(S)
FS = S[:int((len(S) - 1)/ 2)]
BS = S[int((len(S) + 3) / 2) -1:]

r_S = list(reversed(S))
r_FS = list(reversed(FS))
r_BS = list(reversed(BS))
flag = 0

for i in range(len(S)):
    # print(r_FS, BS)
    if r_S[i] == S[i] and r_FS == FS and r_BS == BS:
        flag = 1

        continue
    else:
        print('No')
        flag = 0
        break
    
if flag == 1:
    print('Yes')

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

long long gcd(long long m, long long n){

	if(m<n){
		long long swap;
		swap = m;
		m = n;
		n = swap;
	}

	do {
		if(n==0){
			return m;
		}
		
		int swap = m % n;
		m = n;
		n = swap;
	} while(1);
}


int main(){
//	m*n = LCM * GCD
	long long m, n;
	while(cin >> m >> n){
		long long  LCM, GCD;
		
		GCD = gcd(m, n);
		LCM = (m*n)/GCD;
		cout << GCD << " " << LCM << endl;
	}

	return 0;
}

Measured memory_bytes: 0
public class Main{
  static double e = 0.0000000001;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double x1, x2, x3, x4, y1, y2, y3, y4;
    int i;

    n = sc.nextInt();
    for(i = 0;i < n;i++){
      x1 = sc.nextDouble(); y1 = sc.nextDouble();
      x2 = sc.nextDouble(); y2 = sc.nextDouble();
      x3 = sc.nextDouble(); y3 = sc.nextDouble();
      x4 = sc.nextDouble(); y4 = sc.nextDouble();
      if((x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) < e &&
          (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) > -e)
        out.println("YES");
      else out.println("NO");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 31428
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m, ans, a[maxn];
char c[maxn];
signed main() {
	n = ans = read(), m = read();
	rep(i, 1, m) {
		int x = read();
		rep(j, 1, x) {
			int y = read();
			if(!a[y]) a[y] = 1, -- ans;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using  namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
 
int main() {
	string s;
	cin>>s;
	char ans[1000];
	int n=0;
	REP(i,s.size()){
		if(s[i]!='B'){
			ans[n]=s[i];
			n++;
		}else{
			if(n!=0)n--;
		}
	}
	REP(i,n)cout<<ans[i];
	cout<<endl;
}

Measured memory_bytes: 256
// Aizu Vol0 0075: BMI
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int no;
	double w, h, bmi;

	while (scanf("%d,%lf,%lf", &no, &w, &h) == 3) {
		bmi = w / (h*h);
		if (bmi >= 25.0) printf("%d\n", no);
	}
	return 0;
}

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

int main()
{
  i64 N, K;
  cin >> N >> K;
  i64 ans = 0;
  while (0 < N)
  {
    N /= K;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;


int main() {

	int n, x,a[101];
	cin >> n >> x;

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

	sort(a, a + n);

	int count = 0;

	int remain = x;

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

		remain -= a[i];

		if (remain < 0) {
			break;
		}
		count++;

		if (i == n - 1 && remain > 0) {
			count--;
		}
	}

	cout << count << endl;

	return 0;
}




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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;
typedef long double ld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n, k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<pair<pii, int>> block;
	for(int i=0; i<sz(s); i++) {
		if(s[i]=='0') {
			int j=i;
			while(j<sz(s) and s[j]==s[i]) {
				j++;
			}
			block.push_back(make_pair(make_pair(i, j-1), 0));
			i=j-1;
		}
		if(s[i]=='1') {
			int j=i;
			while(j<sz(s) and s[j]==s[i]) {
				j++;
			}
			block.push_back(make_pair(make_pair(i, j-1), 1));
			i=j-1;
		}
	}
	//~ for(int i=0; i<sz(block); i++) {
		//~ auto p = block[i];
		//~ cerr<<p.first.first<<" "<<p.first.second<<" "<<p.second<<"\n";
	//~ }
	n=sz(block);
	int cnt0=0;
	vector<int> pref(n);
	pref[0]=block[0].first.second-block[0].first.first+1;
	if(block[0].second==0) cnt0++;
	for(int i=1; i<n; i++) {
		int cur = block[i].first.second-block[i].first.first+1;
		pref[i]=pref[i-1]+cur;
		if(block[i].second==0) cnt0++;
	}
	//~ watch(cnt0);
	if(cnt0<=k) {
		cout<<sz(s)<<"\n";
		return 0;
	}
	int ans=0;
	for(int i=0; i<n; i++) {
		int type = block[i].second;
		if(type==1) {
			int j=min(n-1, i+k*2);
			int tmpans = pref[j];
			if(i) tmpans -= pref[i-1];
			ans = max(ans, tmpans);
		}
		else {
			int l = i-1;
			int r = min(n-1, l + k*2);
			l=max(0, i-1);
			int tmpans = pref[r];
			if(l) tmpans -= pref[l-1];
			ans = max(ans, tmpans);
		}
	}
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 2088
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    cin >> n;
    vector<int> cnt(n);
    int diam = 0;
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
        chmax(diam, a);
    }

    bool ok = true;
    rep(i, diam + 1) {
        int x = max(i, diam - i);
        if (!cnt[x]) ok = false;
        cnt[x]--;
    }
    int low = (diam + 1) / 2 + 1;
    rep(i, low) if (cnt[i]) ok = false;

    cout << (ok? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <queue>


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

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll n, m;
    cin >> n >> m;
    cout << n - m + 1 << endl;
    return 0;
}

Measured memory_bytes: 256