akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static long MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] s = br.readLine().split(" ");

        int n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);

        String[] s2 = br.readLine().split(" ");
        Integer[] nums = new Integer[n];
        List<Long> positives = new ArrayList<>();
        List<Long> negatives = new ArrayList<>();

        int zeroCount = 0;

        for (int i = 0; i < n; i++) {
            nums[i] = (Integer.parseInt(s2[i]));
            int temp = Integer.parseInt(s2[i]);
            if (temp<0)negatives.add((long) (temp));
            else if (temp==0){
                ++zeroCount;
            }
            else  positives.add((long) temp);
        }

        boolean isPositive = positives.size() + ((int)(negatives.size()/2))*2 >= k && (k%2 == 0 || positives.size() > 0);


        if (isPositive){
            //positive sing = > select negatives or positives in groups of two (by whichever pair has higher product) and mul 1 more pos at the end if k nos not taken

            positives.sort(Collections.reverseOrder());
            Collections.sort(negatives);

            int negIdx = 0;
            int posIdx = 0;
            int total = k;
            long ans  = 1L;
            if(k%2==1){
                ans = positives.get(posIdx);
                ++posIdx;
                --total;
            }
            while (total>0){

                long negProd = negatives.size()-negIdx>=2 ? (negatives.get(negIdx)*negatives.get(negIdx+1)) : 0;
                long posProd = positives.size()-posIdx>=2 ? (positives.get(posIdx)*positives.get(posIdx+1)) : 0;


                ans = (ans * (Math.max(negProd,posProd)%MOD))%MOD;
                if(negProd>posProd)
                    negIdx += 2;
                else
                    posIdx += 2;
                total -= 2;
            }
            System.out.println(ans);
        }else{
            // sign will be negative, hence choose smallest k numbers(by abs value).
            if(zeroCount>0){
                System.out.println(0);
                return;
            }
            Arrays.sort(nums, Comparator.comparingInt(Math::abs));
            long ans = 1L;
            for(int i = 0 ; i<k; i++){
                ans = (ans*nums[i])%MOD;
            }
            System.out.println((ans+MOD)%MOD);
        }

    }
}

Measured memory_bytes: 78920
num = int(input())
ac_num = 0
wa_num = 0
tle_num = 0
re_num = 0
for i in range(num):
    s = input()
    if(s=='AC'):
        ac_num += 1
    elif(s=='WA'):
        wa_num += 1
    elif(s=='TLE'):
        tle_num += 1
    else:
        re_num += 1

print('AC x '+str(ac_num))
print('WA x '+str(wa_num))
print('TLE x '+str(tle_num))
print('RE x '+str(re_num))


Measured memory_bytes: 9204
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/15/20 20:19:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<int> L(n); for (auto& l:L) cin>>l;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        vector<int> ll = {L[i],L[j],L[k]};
        sort(ll.begin(), ll.end());
        if (ll[0] == ll[1] or ll[1] == ll[2])
          continue;
        if (ll[0] + ll[1] > ll[2])
          ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3660
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String Sr = new StringBuffer(S).reverse().toString();
    int N = S.length();
    if(!S.equals(Sr)){
      System.out.println("No");
      return;
    }
    
    String T = S.substring(0,(N-1)/2);
    String Tr = new StringBuffer(T).reverse().toString();
    if(!T.equals(Tr)){
      System.out.println("No");
      return;
    }
    System.out.println("Yes");
  }
}

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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed

int N, M;
bool isa[110000];
int dp[110000];
int mod = 1e9 + 7;

signed main() {
    cin >> N >> M;
    fill(isa, isa + 110000, true);
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        isa[a] = false;
    }
    dp[1] = 1;
    for (int i = 2; i <= N + 1; i++) {
        dp[i] = (dp[i - 1] * isa[i - 2] + dp[i - 2] * isa[i - 3]) % mod;
    }
    cout << dp[N + 1] << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#define MAX 10000
#define NIL -1

struct Node {
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg=0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  if(T[u].parent==NIL){
    printf("root\n");
  }
  else if(T[u].left==NIL&&T[u].right==NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int v, l, r,root=0;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d", &v, &l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  for(i=0;i<n;i++)
    if(T[i].parent==NIL) root=i;
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++)
    print(i);
  return 0;
}



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

ll fact_pow(ll n,ll m,ll p)
{
  ll res=1;
  for(ll i=n;i>=1;i--)
  {
    res=res*i%m;
  }
  
  ll ans=1;
  while(p>0)
  {
    if(p&1)ans=ans*res%m;
    res=res*res%m;
    p>>=1;
  }

return ans;
}



int main()
{
  ll i ,j,r1,r2,c1,c2,m=1000000007,temp1=1,ans=0,temp2,temp3,temp4,temp5;
  cin>>r1>>c1>>r2>>c2;
  
temp1=fact_pow(r2+c2+2,m,1)*fact_pow(r2+1,m,m-2)%m;
temp1=temp1*fact_pow(c2+1,m,m-2)%m;



temp2=fact_pow(r2+c1+1,m,1)*fact_pow(r2+1,m,m-2)%m;
temp2=temp2*fact_pow(c1,m,m-2)%m;

temp3=fact_pow(r1+c2+1,m,1)*fact_pow(r1,m,m-2)%m;
temp3=temp3*fact_pow(c2+1,m,m-2)%m;

temp4=fact_pow(r1+c1,m,1)*fact_pow(r1,m,m-2)%m;
temp4=temp4*fact_pow(c1,m,m-2)%m;

ans=temp1+temp4-temp2-temp3;


cout<<(ans+4*m)%m<<endl;

return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main(){
 int s,k; 
int count=0;
cin>>k>>s; 
for(int x=0;x<=k;x++) { 
for(int y=0;y<=k;y++) {
 int z=s-(x+y); 
if((z>=0)&&(z<=k)){ 
count ++; 
}
}
}
cout<<count; 
return 0; 
}

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

const int MN = 200010;

int N, M;
int A[MN], X[MN], psum[MN];

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N - 1; i++) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &M);

    for(int i = 0; i < M; i++) {
        scanf("%d", &X[i]);
    }

    for(int i = 0; i < N - 1; i++) {
        psum[i] = A[i];
        if(i) psum[i] += psum[i - 1];
    }

    if(N == 3) {
        for(int i = 0; i < M; i++) {
            printf("%d\n", X[i] + A[0] - A[1]);
        }
        return 0;
    }

    deque<int> dq;
    for(int i = 0; i >= -psum[1]; i--) dq.push_front(i);

    for(int i = 3; i < N - 1; i++) {
        vector<int> add;
        int q = 1;
        for(int j = -psum[i - 2] - 1; j >= -psum[i - 1]; j--) {
            if(dq.size() <= q) add.push_back(q + 1 - (int)dq.size());
            else add.push_back(dq[q]);
            q++;
        }
        for(int j = 0; j < add.size(); j++) dq.push_front(add[j]);
    }

    for(int i = 0; i < M; i++) {
        int t = X[i] - psum[N - 2];
        if(t < -psum[N - 3]) t = -2 * psum[N - 3] - t;
        t += psum[N - 3];

        printf("%d\n", (t < dq.size()? dq[t] : t + 1 - (int)dq.size()) + psum[1] + A[0] - A[1]);
    }
}


Measured memory_bytes: 10608
def insertsort(N_list):
    sort_list = list(N_list)
    ans = [str(i) for i in sort_list]
    print(" ".join(ans))
    for i in range(1,len(N_list)):
        target = sort_list[i]
        j = i-1
        while j >= 0 and sort_list[j] > target:
            sort_list[j], sort_list[j+1] = target, sort_list[j]
            j -= 1
        ans = [str(i) for i in sort_list]
        print(" ".join(ans))
            
    
N = int(input())
N_list = list(map(int,input().split()))
insertsort(N_list)


Measured memory_bytes: 5604
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }
    let num2 = num_of_factor2(a[0]);
    for i in 2..=n {
        if num2 != num_of_factor2(a[i - 1]) {
            println!("0");
            return;
        }
    }
    let mut alcm = 1;
    for &ai in &a {
        alcm = lcm(alcm, ai / 2);
    }
    let mut tmp1 = m / alcm;
    if tmp1 % 2 != 0 {
        tmp1 += 1;
    }
    println!("{}", tmp1 / 2);
}

fn num_of_factor2(a: usize) -> usize {
    let mut num = 0;
    let mut aa = a;
    while aa % 2 == 0 {
        aa /= 2;
        num += 1;
    }
    return num;
}

fn lcm(a: usize, b: usize) -> usize {
    return a * b / gcd(a, b);
}

fn gcd(a: usize, b: usize) -> usize {
    if a < b {
        return gcd(b, a);
    }
    if b == 0 {
        return a;
    }
    return gcd(b, a - (a / b) * b);
}


Measured memory_bytes: 3768
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int main(){
  vector<string>s;
  vector<int>in[100];
  string tmp;
  int num;
  int co=0;  
  while(cin>>tmp>>num){
    int n=-1;
    rep(i,s.size())if(s[i]==tmp)n=i;
    if(n+1){
      in[n].pb(num);
    }else{
      s.pb(tmp);
      in[co].pb(num);
      co++;
    }
  }
  vector<int>order(s.size());
  rep(i,s.size())order[i]=i;
  rep(i,s.size()){
    rep(j,s.size()-i-1){
      if(s[order[j]]>s[order[j+1]]){
	swap(order[j],order[j+1]);
      }
    }
  }
  rep(i,s.size()){
    cout<<s[order[i]]<<endl;
    sort(in[order[i]].begin(),in[order[i]].end());
    cout<<in[order[i]][0];
    rep(j,in[order[i]].size()-1)cout<<" "<<in[order[i]][j+1];
    cout<<endl;
  }
}

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

int main()
{
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;

	if(r <= x && x <=  w-r && r <= y && y <= h-r)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>){

  val (N, K) = readLine()!!.split(" ").map{ it.toInt() }
  val S = readLine()!!
  val K_index = K - 1

  val result = S.substring(0, K_index) + S.substring(K_index, K_index + 1).toLowerCase() + S.substring(K_index + 1)

  println(result)

}


Measured memory_bytes: 37608
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}",(v[0] + v[1] + 1) / 2);
}


Measured memory_bytes: 4352
MOD = 10**9 + 7
MAX = int(2e5)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combination(r, c):
    return FACT[r] * INV[r-c] * INV[c]


def main():
    N, M, K = map(int, input().split())
    ans1 = 0
    for d in range(1, N):
        ans1 = (ans1 + d * (N-d) * (M**2)) % MOD
    ans2 = 0
    for d in range(1, M):
        ans2 = (ans2 + d * (M-d) * (N**2)) % MOD
    ans = ((ans1 + ans2) * combination(M*N-2, K-2)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42344
#include<stdio.h>
int main()
{
	int n,i,m;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&m);
		if(m%2==0)
		{
			if(m%3!=0&&m%5!=0)
			break;
		}
	}
	if(i==n+1)
	printf("APPROVED\n");
	else
	printf("DENIED\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <map>
#include <iomanip>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	vector<int> next(n, -1);
	queue<int> que;

	next[0] = 0;
	que.push(0);

	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int num = 0; num < g[v].size(); ++num) {
			int nv = g[v][num];
			if (next[nv] != -1)	continue;
			next[nv] = v;
			que.push(nv);
		}
	}

	cout << "Yes" << endl;
	for (int v = 1; v < n; ++v)	cout << next[v] + 1 << endl;
	return 0;
}

Measured memory_bytes: 9612
#include <iostream>
#include <map>
using namespace std;
int main() {
	map<string,int>a;
	int n;
	cin >> n;
	int mx=0;
	for (int i=1; i<=n; i++) {
		string t;
		cin >> t;
		a[t]++;
		mx = max(mx, a[t]);
	}
	for (auto i:a) {
		if (i.second == mx) {
			cout << i.first << endl;
		}
	}
}

Measured memory_bytes: 25216
#include<stdio.h>
#include <stdlib.h>
double abso(double a,double b)
{
    if(a-b<0)
        return b-a;
    else
        return a-b;
}
int main()
{
    int n,i;
    scanf("%d",&n);
    double a[n],sum=0,x,min;
    scanf("%lf",&x);
    for(i=1; i<n; i++)
    {
        scanf("%lf",&a[i]);
        sum+=a[i];
    }
    min=abso(x,sum);
    for(i=1; i<n-1; i++)
    {
        x+=a[i];
        sum-=a[i];
        if(abso(x,sum)<min)
            min=abso(x,sum);
    }
    printf("%.0lf\n",min);
}


Measured memory_bytes: 1664
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
#define pi = 3.14159265358979323846;

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////////////////////////////////////////////////
//Fuctions if any:





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
//ios_base& scientific (ios_base& str);

int n;
cin>>n;
int a[n][3];
int dp[n+1][3];
memset(dp,0,sizeof(dp));

fr(i,n)
{
	cin>>a[i][0]>>a[i][1]>>a[i][2];
}
dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];
fr1(i,1,n)
{
	dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
	dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
	dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);

}
// fr(i,n+1)
// {
// 	cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
// }
cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll k;
    cin >> k;

    ll n = (k + 49) / 50;
    ll m = (50 - (k % 50)) % 50;

    cout << 50 << endl;

    ll a[50];

    REP(i, 50)
    a[i] = 49 + n;

    REP(i, m)
    {
        sort(a, a + 50);

        REP(j, 49)
        a[j]++;

        a[49] -= 50;
    }

    REP(i, 50)
    cout << a[i] << endl;

    return 0;
}

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

typedef long long i64;

vector <int> card;
int N, L, T;

int main()
{
	int cnt = 0;
	cin >> N >> L >> T ;

	for(int i = 1; i <= N; i++)
	{
		int X, W;
		cin >> X >> W ;

		switch(W)
		{
		case 1:
			cnt += (T + X) / L;
			card.push_back((T + X) % L);
			break;
		case 2:
			cnt -= (T - X + L - 1) / L;
			card.push_back(((X - T) % L + L) % L);
			break;
		}
		cnt %= N;
	}

	cnt = (cnt + N) % N;

	sort(card.begin(), card.end());
	for(int i = cnt; i < N; i++)
		cout << card[i] << endl;
	for(int i = 0; i < cnt; i++)
		cout << card[i] << endl ;

	return 0;
}



Measured memory_bytes: 1656
n = int(input())
x = list(map(int, input().split()))
x.sort()
a = x[0]
b = x[-1]
l = []
for i in range(a,b+1):
    count = 0
    for j in x:
        count += (j - i)**2
    l.append(count)
print(min(l))

Measured memory_bytes: 3064
//In the name of GOD
//SMani24
#include<bits/stdc++.h>
#define int long long
using namespace std;

int a, b, ans;

int32_t main() {
    cin >> a >> b;
    for(int i = 59; ~i; i--) {
        if((a & (1ll << i)) == (b & (1ll << i))) {
            if(a & (1ll << i)) {
				a -= (1ll << i), b -= (1ll << i);
            }
        }
        else {
            int tmp = (1ll << i);
            int r = tmp * 2 - 1, l = tmp + a, L = tmp, R = tmp;
            for(int j = i - 1; ~j; j--) {
            	if(b & (1ll << j)) {
            		R += (1ll << (j + 1)) - 1;
            		break;
            	}
            }
            if(l <= R) {
				ans += (r - L + 1);
            }
            else {
				ans += (r - l + 1) + (R - L + 1);
            }
			ans += L - a;
            cout << ans << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		int count=0;
		for(int a=0; a<=9; a++){
			for(int b=0; b<=9; b++){
				for(int c=0; c<=9; c++){
					for(int d=0; d<=9; d++){
						if(a+b+c+d == n)
							count++;
					}
				}
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 0
var
i,j,c,d,e,b,zz:longint;
s:string;
begin
read(s);
for i:=1 to length(s) do
begin
zz:=0;
for j:=i to i+2 do
if s[i]<>s[j] then begin zz:=1;break;end;
if zz=0 then begin writeln('Yes');exit;end;
end;
writeln('No');
end.

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int[] V)
        {
            var e = new Dictionary<int, int>();
            var o = new Dictionary<int, int>();
            e[0] = 0;
            o[0] = 0;
            for (int i = 0; i < N; ++i)
            {
                if (i % 2 == 0)
                {
                    if (!e.ContainsKey(V[i])) { e[V[i]] = 0; }
                    ++e[V[i]];
                }
                else
                {
                    if (!o.ContainsKey(V[i])) { o[V[i]] = 0; }
                    ++o[V[i]];
                }
            }
            var x = e.ToArray();
            var y = o.ToArray();
            Array.Sort(x, (a, b) => b.Value.CompareTo(a.Value));
            Array.Sort(y, (a, b) => b.Value.CompareTo(a.Value));
            int e0 = x[0].Value;
            int o0 = y[0].Value;
            int e1 = x[1].Value;
            int o1 = y[1].Value;
            return (x[0].Key != y[0].Key) ? N - e0 - o0 : Math.Min(N - o0 - e1, N - o1 - e0);
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            var V = ReadInts();
            Console.WriteLine(Solve(N, V));
        }
    }
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    vector<string> a(3);
    rep(i, 3)
    {
        cin >> a[i];
    }
    vector<int> ad(3);
    char player = 'a';
    while (true)
    {
        if (player == 'a')
        {
            player = a[0][ad[0]];
            ad[0]++;
            if (a[0].size() == ad[0] - 1)
            {
                cout << "A" << endl;
                return 0;
            }
        }
        if (player == 'b')
        {
            player = a[1][ad[1]];
            ad[1]++;
            if (a[1].size() == ad[1] - 1)
            {
                cout << "B" << endl;
                return 0;
            }
        }

        if (player == 'c')
        {
            player = a[2][ad[2]];
            ad[2]++;
            if (a[2].size() == ad[2] - 1)
            {
                cout << "C" << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int h[n] = {};
    for(int i=0;i<n;++i)
    {
        cin >> h[i];
    }
    int dp[n] = {};
    for(int i=0;i<n;++i)
    {
        dp[i] = 1 << 30;
    }

    dp[0] = 0;
    for(int i=0;i<n;++i)
    {
        if(i+1 < n)
        {
            dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        }

        if(i+2 < n)
        {
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,k) for (int i = 0; i < (int)(k); i++)
#define all(cnt) begin(cnt), end(cnt)

int main() {
    int w, h, t;
    int p;
    while (cin >> w >> h >> t >> p) {
        int c[50][50] = {};
        for (int i = 0; i < p; i++) {
            int x, y, t;
            cin >> x >> y >> t;
            ++c[y][x];
        }
        ll ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int x;
                cin >> x;
                ans += x * c[i][j];
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3100
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

vector<int> a, b, res;

int n;

map<int, int> cnt_a, cnt_b;

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

bool validate() {
  bool valid = true;
  for (int i = 0; i < n; ++i) {
    valid &= (a[i] != res[i]);
  }
  return valid;
}

bool solve() {
  res = b;
  for (int t = 0; t < 150; ++t) {
    rotate(begin(res), begin(res) + rng() % n, end(res));
    if (validate()) return true;
  }
  res = b;
  reverse(all(res));
  for (int t = 0; t < 150; ++t) {
    if (validate()) return true;
    shuffle(all(res), rng);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
  cin >> n;
  a.resize(n), b.resize(n), res.resize(n);
  cin >> a >> b;
  for (int x : b) ++cnt_b[x];
  for (int x : a) {
    ++cnt_a[x];
    if (cnt_b.count(x) && cnt_b[x] + cnt_a[x] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (solve()) {
    cout << "Yes" << endl;
    cout << res << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 24236
object Main {
  def main(args: Array[String]): Unit = {
    import collection._
    val Seq(a, b): Seq[Int] = io.StdIn.readLine().split(' ').map(_.toInt)
    val ans = a + b
    if (ans < 10){
      println(ans)
    }else{
      println("error")
    }
  }
}

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

int main() {
	int a[4];
	for (int i = 0; i < 4; i++) {
		cin >> a[i];
	}
	int n = 4 / 2;
	int c[n];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		c[i] = a[i * 2] * a[i * 2 + 1];
		if (ans < c[i]) {
			ans = c[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	ll N,D;
	cin >> N >> D;
	int ans = 0;
	rep(i,N)
	{
		ll x,y;
		cin >> x >> y;
		if (x*x + y*y <= D*D) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	string s; cin >> s;
	if(s=="ABC")
		cout<<"ARC";
	else
		cout<<"ABC";
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
int main()
{
int n,a,b,c;
  scanf("%d",&n);
  a=n%10;
  n=n/10;
  b=n%10;
  n=n/10;
  c=n%10;
  n=n/10;
  if(a==b && a==c)
    printf("Yes");
  else if(b==c && b==n)
    printf("Yes");
  else
    printf("No");
return 0;
}


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

int main(){
  ll a,n,i;
  string s,t,u;
  cin >> n >> s;
  a=1;
  t=s.substr(0,1);
  for(i=1;i<=n;i++){
    u=s.substr(0,1);
    if(u!=t){
      t=u;
      a+=1;
    }
    s.erase(0,1);
  }
  cout << a << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
int N,K;
int a[100001];
ll s[100001],s2[100001];
ll Max=-1e14;
int main(){
  cin >> N >> K;
  for(int i=1;i<=N;i++) cin >> a[i];
  for(int i=1;i<=N;i++){
    s[i]=s[i-1]+a[i];
    s2[i]=s2[i-1];
    if(a[i]>=0)s2[i]+=a[i];
  }
  for(int i=K ;i<=N;i++){
     ll x,y;
    x=s[i]-s[i-K];
    y=s2[i]-s2[i-K];
    if(x<0)x=0;
    x+=(s2[N]-y);
    Max=max(Max,x);
  }
  cout << Max << endl;
  return 0;
}


Measured memory_bytes: 2176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        long N = nl();
        long[] d26 = new long[15];
        d26[0] = 1;
        for (int i = 1; i < 15; i++) {
            d26[i] = d26[i-1]*26;
        }
        char []alphabet = new char[26];
        char c = 'a';
        for (int i = 0; i < 26; i++){
            alphabet[i] = c++;
        }
        N = N-1;
        ArrayList<Character> ans = new ArrayList<>();
        for (int i = 1; i < d26.length; i++) {
            if(N-d26[i] >= 0){
                N -= d26[i];
            }else{
                for (int j = i; j >=1; j--) {
                    // System.out.println(N);
                    // System.out.println((N/d26[j-1]));
                    ans.add(alphabet[(int)(N/d26[j-1])]);
                    N = N % d26[j-1];
                    // N -= d26[j-1] * ((N-1)/d26[j] + 1);
                }
                break;
            }
        }
        for (int i = 0; i < ans.size(); i++) {
            out.print(ans.get(i));
        }
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32832
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define loop(i,n) for(i=0;i<n;i++)
ll power(ll x,ll y,ll md)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = ((res%md)*(x%md))%md;

        // y must be even now
        y = y>>1; // y = y/2
        x = ((x%md)*(x%md))%md;  // Change x to x^2
    }
    return res%md;
}
ll factor(ll n)
{
    ll c=0;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
            c+=2;
        if(i*i==n)
            c--;
    }
    return c;
}





/* ll arr[2000003];
 ll maxn=2000001;
 ll sieve()
 {
     arr[1]=arr[0]=0;
     for(ll i=2;i<=maxn;i++)
        arr[i]=1;
     for(ll i=2;i*i<=maxn;i++)
     {
         if(arr[i]==1)
         {
             for(ll j=i*i;j<=maxn;j+=i)
                arr[j]=0;
         }
     }

 }*/
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}

int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     //ll t; cin>>t;
      // while(t--)
     {
        ll n,k,h[200007]={0},i,sum=0,x,y;
        cin>>n;
        loop(i,n)
        cin>>x,h[x]++,sum+=x;

        cin>>k;

        while(k--)
        {
            cin>>x>>y;
            ll diff=(y-x);
            sum+=diff*h[x];
            h[y]+=h[x];
            h[x]=0;
            cout<<sum<<endl;
        }

        //cout<<endl;

     }


    return 0;

}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n,m;
    cin >> n >> m;

    cout << n*(n-1)/2+m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
using System;
class Program{
  static void Main(string[] args){
    long n = long.Parse(Console.ReadLine());
    long a = long.Parse(Console.ReadLine());
    long b = long.Parse(Console.ReadLine());
    long c = long.Parse(Console.ReadLine());
    long d = long.Parse(Console.ReadLine());
    long e = long.Parse(Console.ReadLine());
    long[] t = {a, b, c, d, e};
    if(t[0]<t[1]){t[1]=t[0];}
    if(t[1]<t[2]){t[2]=t[1];}
    if(t[2]<t[3]){t[3]=t[2];}
    if(t[3]<t[4]){t[4]=t[3];}
    Console.WriteLine(upper(n,t[4])+4);
  }
  
  static long upper(long a, long b){
    return a%b>0?(long)a/b+1:(long)a/b;
  }
}

Measured memory_bytes: 11092
from collections import defaultdict, deque

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n + 1)]
for a, b in ab:
    adj[a].append(b)
    adj[b].append(a)

col_max = max([len(row) for row in adj])

cols = defaultdict(int)
s = 1
dq = deque([s])
p = [-1] * (n + 1)
p[s] = -2
while dq:
    u = dq.popleft()
    c_banned = cols[(u, p[u])]
    c = 1
    for v in adj[u]:
        if p[v] != -1:
            continue
        p[v] = u
        if c == c_banned:
            c += 1

        cols[(u, v)] = cols[(v, u)] = c
        c += 1

        dq.append(v)

print(col_max)
for a, b in ab:
    print(cols[(a, b)])


Measured memory_bytes: 65732
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, S, E, cnt, ans;
arr fir, sum, fa, deep, dep, to;
struct
{
	int to, last;
} e[Maxn << 1];
void con(int u, int v)
{
	e[++cnt].to = v;
	e[cnt].last = fir[u];
	fir[u] = cnt;
}
int DFS(int x)
{
	if (x == S)
		to[x] = x;
	for (int next = fir[x], nx; next; next = e[next].last)
	{
		nx = e[next].to;
		if (nx == fa[x])
			continue;
		dep[nx] = dep[x] + 1;
		fa[nx] = x;
		if (DFS(nx))
			to[x] = nx;
		deep[x] = max(deep[x], deep[nx] + 1);
	}
	return to[x];
}
int main()
{
	rg int a, b;
	cin >> n >> S >> E;
	for (int i = 1; i < n; i++)
	{
		a = read();
		b = read();
		con(a, b);
		con(b, a);
	}
	DFS(E);
	while (dep[S] - dep[E] > 2)
	{
		S = fa[S];
		E = to[E];
		ans++;
	}
	ans += dep[S] - dep[E] - 1;
	cout << ans + deep[S] << '\n';
	return 0;
}


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

using namespace std;

char maze[23][23];
bool visited[23][23];
int level[23][23];

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

int h, w;
int hx, hy;

int bfs(int fx, int fy)
{
    memset(visited, 0, sizeof(visited));
    memset(level, 0, sizeof(level));

    int mx = 0;
    queue<pair<int, int>> q;

    q.push({fx, fy});
    visited[fx][fy] = 1;
    level[fx][fy] = 0;

    while (!q.empty())
    {
        int px = q.front().first;
        int py = q.front().second;
        q.pop();

        for (int i = 0; i < 4; i++)
        {
            int x = px + dx[i];
            int y = py + dy[i];
            if (!visited[x][y] && maze[x][y] == '.' && x >= 0 && y >= 0 && x < h && y < w)
            {
                level[x][y] = level[px][py] + 1;
                visited[x][y] = 1;
                q.push({x, y});
                if (mx < level[x][y])
                {
                    mx = level[x][y];
                    hx = x;
                    hy = y;
                }
            }
        }
    }
    return mx;
}

int main()
{
    cin >> h >> w;

    int x, y;
    bool f = 1;
    int ans = 0;
    queue<pair<int, int>> nodes;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> maze[i][j];
            if (f && maze[i][j] == '.')
            {
                nodes.push({i, j});
            }
        }
    }

    for (int i = 0; !nodes.empty(); i++)
    {
        x = nodes.front().first;
        y = nodes.front().second;
        nodes.pop();
        ans = max(ans, bfs(x, y));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, K = MI()
    d = [0]*K
    A = [0]*K
    for i in range(K):
        d[i] = II()
        A[i] = LI()
    Alist = []
    for i in range(K):
        for j in range(d[i]):
            Alist.append(A[i][j])
    print(N-len(set(Alist)))


if __name__ == "__main__":
	main()

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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

str s;

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl; 
    /* end code */
	return 0;
}

Measured memory_bytes: 256
def calc(n):
    if n <= 1:
        return 1
    elif n == 2:
        return 2
    else:
        a, b = 1, 2
        for _ in range(n - 2):
            b, a = a + b, b
        return b


K = 10 ** 9 + 7

n, m = map(int, input().split())
broken = []
no_reachable = False
for _ in range(m):
    a = int(input())
    if len(broken) and a == broken[-1] + 1:
        no_reachable = True
        break
    broken.append(a)

if not no_reachable:
    a = 0
    cb = 1
    for b in broken:
        stairs = b - a - 1
        cb *= calc(stairs)
        a = b + 1
    cb *= calc(n - a)
    print(cb % K)
else:
    print(0)


Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;


	return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<int > > a(n,vector<int>(m));
  vector<int>b(m);
  
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a.at(i).at(j);}}
  
  for(int i=0;i<m;i++){
      cin>>b.at(i);}
  
  for(int i=0;i<n;i++){
    int c=0;
   for(int j=0;j<m;j++){
    c +=a.at(i).at(j)*b.at(j);}
    cout<<c<<endl;}
  return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,pos,p,sum;cin>>n;
  lvector A(n,0),B(n,0),checked(n,0);rep(i,n) cin>>A[i];
  bool isok=true;
  rep(i,n) {
    pos=n-1-i,p=pos+1,sum=0;
    while(pos<n) {
      sum+=B[pos];
      pos+=p;
    }
    pos=n-1-i;
    if(sum%2==0&&A[pos]==1||sum%2==1&&A[pos]==0) B[pos]=1;
    else if(sum%2==0&&A[pos]==0||sum%2==1&&A[pos]==1) continue;
    else {isok=false;break;}
  }
  if(isok) {
    ll m=accumulate(B.begin(),B.end(),0);
    print(m);
    if(m>0) {
      rep(i,n) if(B[i]!=0) cout<<i+1<<' ';
      cout<<endl;
    }
  }
  else print(-1);
  return 0;
}


Measured memory_bytes: 5632
<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
$T = trim(fgets(STDIN));
//list($N,$M,$X,$Y) = explode(" ",trim(fgets(STDIN)));
//$y = explode(" ",trim(fgets(STDIN)));
$sc = array_count_values(str_split($S));
$tc = array_count_values(str_split($T));
sort($sc);
sort($tc);
$scstr = implode("",$sc);
$tcstr = implode("",$tc);
//printf("[%s]\n[%s]\n",$scstr,$tcstr);
if ($scstr == $tcstr) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


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

int main() {
    int X, Y;
    cin >> X >> Y;
    for(int i = 0; i <= X; i++ ) {
        int leg = 2*i + 4 * (X - i);
        if(leg == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <math.h>
#define PI 3.14159265359
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;


// 最大公約数
long long gcd(long long a, long long b)
{
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

int main() {

	// 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	//clock_t start = clock();

	int K;
	cin >> K;
	long long res = 0;
	int tmp;

	for (int a = 1; a <= K; a++)
	{
		for (int b = 1; b <= K; b++)
		{
			for (int c = 1; c <= K; c++)
			{
				tmp = gcd(a, b);
				res += gcd(tmp, c);
			}
		}
	}

	cout << res << endl;

	//clock_t end = clock();

	//cout << end << endl;

	return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string sp,t;
	cin>>sp>>t;
	int len=t.size()/*匹配[beg..beg+len-1]*/,lens=sp.size();
	string spc=sp,spci="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
	//main  part
	if(sp==t){cout<<sp;return 0;
	}
	for(int i=0;i<=lens-len;i++) 
	{
		bool flag=1;
		for(int j=0;j<len;j++)
		{
			if(sp[i+j]!=t[j]&&sp[i+j]!='?'){
				flag=0;
				break;
			}
			else spc[i+j]=t[j];
		}
		if(flag&&spci>=spc)spci=spc;
		//cout<<spci<<' '<<spc<<' '<<i<<'\n';
		spc=sp;
	}
	if(spci=="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")cout<<"UNRESTORABLE";
	else {
		for(int i=0;i<lens;i++)spci[i]=(spci[i]=='?'?'a':spci[i]);
	cout<<spci;}
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5;

int q[N + 10] ;
typedef long long ll;

bool cmp(int a,int b){
	return a > b;
}

int main(){
	
	int n , k;
	
	cin >> n >> k;
	ll sum = 0;
	for(int i = 1; i <= n; i ++){
		
		scanf("%d" , &q[i]);
		sum += q[i];
	}
	
	if(k >= n){
		puts("0") ;
		return 0;	
	} 
	
	sort(q+1,q + 1 + n , cmp);
	
	for(int i = 1; i <= k; i ++){
		sum -= q[i];
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1024