akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define Max 500000

typedef struct
{
  int key;
  int p;
  int l[2];
}Node;

Node T[Max];
void insert( int );
void find( int, int );
int successor( int );
void delete( int );
void Preorder( int );
void Inorder( int );


int main(){

  int i, n, k;
  char s[7];

  scanf("%d", &n);

  T[0].key = -1;

  for(i=0; i<n; i++){
      T[i].l[0] = -1;
      T[i].l[1] = -1;
      scanf("%s", s);

      if(strcmp(s, "insert") == 0){
      scanf("%d", &T[i].key);
      insert(i);
    }else if(strcmp(s, "print") == 0){
      Inorder(0);
      printf("\n");
      Preorder(0);
      printf("\n");
    }else if(strcmp(s, "find") == 0){
      scanf("%d", &k);
      find(0, k);
    }else if(strcmp(s, "delete") == 0){
      scanf("%d", &k);
      delete(k);
    }
  }
  return 0;
}


void insert(int z){

  int x, y;
  y = -1;
  x = 0;

  if(z != 0)
    while(x != -1){
    y = x;
    if(T[z].key < T[x].key) x = T[x].l[0];
    else x = T[x].l[1];
    }

  T[z].p = y;

  if(y != -1){
    if(T[z].key < T[y].key) T[y].l[0] = z;
    else T[y].l[1] = z;
  }
}

void find(int x, int k){
  if(x == -1) printf("no\n");
  else if(T[x].key == k) printf("yes\n");
  else if(k < T[x].key) find(T[x].l[0], k);
  else find(T[x].l[1], k);
}

int successor(int x){
  int y;

  if(T[x].l[1] != -1){
    x = T[x].l[1];
    while(T[x].l[0] != -1) x = T[x].l[0];
    return x;
  }else{
    y = T[x].p;
    while(y != -1 && x == T[y].l[1]){
    x = y;
    y = T[y].p;
  }
  return y;
  }
}

void delete(int k){

  int x, y, z = 0;

  while( 1 ){
    if(T[z].key == k) break;
    else if(k < T[z].key) z = T[z].l[0];
    else z = T[z].l[1];
  }

  if(T[z].l[0] == -1 || T[z].l[1] == -1) y = z;
  else y = successor(z);

  if(T[y].l[0] != -1) x = T[y].l[0];
  else x = T[y].l[1];

  if(x != -1) T[x].p = T[y].p;

  if(T[y].p != -1){
    if(y == T[T[y].p].l[0]) T[T[y].p].l[0] = x;
    else T[T[y].p].l[1] = x;
  }
  if(y !=  z) T[z].key = T[y].key;
}


void Preorder(int a){

  printf(" %d", T[a].key);

  if(T[a].l[0] != -1) Preorder(T[a].l[0]);
  if(T[a].l[1] != -1) Preorder(T[a].l[1]);
}


void Inorder(int a){
  if(T[a].l[0] == -1){
    printf(" %d", T[a].key);
    if(T[a].l[1] != -1) Inorder(T[a].l[1]);
  }else{
    Inorder(T[a].l[0]);
    printf(" %d", T[a].key);
    if(T[a].l[1] != -1) Inorder(T[a].l[1]);
  }
}

Measured memory_bytes: 8428
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using ll = long long;

using namespace std;

const int inf = 1e6 + 7;

int main(){	
	int k;
	cin >> k;
	for(int i = 0; i < k; i++){
		cout << "ACL";
	}
	cout << endl;
	return 0;
}
 

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<30)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;
 
int a[220000];
int ans[220000];
vector<int> dp(220000, INF);

int main() {
    int n, m, x;
    Int ans = -1;
    cin >> n >> m >> x;
    vector<int> c(n, 0);
    vector<vector<int>> a(n, vector<int>(m, 0));

    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    /*for (int i = 0; i < n; i++) {
        cout << c[i] << endl;
        for (int j = 0; j < m; j++) {
            cout << a[i][j] << ' ';
        }
        cout << endl;
    }*/


    for (int i = 0; i < 1<<n; i++) {
        vector<int> taka(m, 0);
        int money = 0;
        for (int j = 0; j < n; j++) {
            if (1<<j & i) {
                money += c[j];
                for (int k = 0; k < m; k++) {
                    taka[k] += a[j][k];
                    // cout << taka[k] << ' ';
                }
                // cout << endl;
            }
        }
        int flag = 1;
        for (int j = 0; j < m; j++) {
            if (taka[j] < x) {
                flag = 0;
            }
        }
        if (flag) {
            if (ans == -1) {
                ans = money;
            } else {
                ans = ((ans > money) ? money : ans);
            }
            // cout << ans << ' ' << i << endl;
        }
    }
    cout << ans ;

    return 0;
}

Measured memory_bytes: 3416
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  if (c <= a+b) flag = false;
  if (4*a*b >= (c-a-b) * (c-a-b)) flag = false;
  
  if (flag) puts("Yes");
  else puts("No");
  return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, K;
string S;

bool comp(pii a, pii b)
{
    int add = 0;
    add += (a.f>0);
    add += (a.s<(N-1));
    int add2 = 0;
    add2 += (b.f>0);
    add2 += (b.s<(N-1));
    return (b.s - b.f + add2) < (a.s - a.f + add);
}
int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    cin >> S;
    int ans = 0;
    for(int i=0; i<N-1; i++)
    {
        if(S[i] == S[i+1])
        {
            ans++;
        }
    }
    cout << min(N-1, ans+2*K);
    return 0;
}


Measured memory_bytes: 512
def resolve():
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A3 = list(map(int, input().split()))
    N = int(input())
    b = [int(input()) for i in range(N)]

    A = A1 + A2 + A3
    checkA = [0]*9
    for i in range(N):
        if b[i] in A:
            checkA[A.index(b[i])] = 1
    if checkA[0] + A[1] + A[2] == 3:
        print('Yes')
    elif checkA[3] + checkA[4] + checkA[5] == 3:
        print('Yes')
    elif checkA[6] + checkA[7] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[3] + checkA[6] == 3:
        print('Yes')
    elif checkA[1] + checkA[4] + checkA[7] == 3:
        print('Yes')
    elif checkA[2] + checkA[5] + checkA[8] == 3:
        print('Yes')
    elif checkA[0] + checkA[4] + checkA[8] == 3:
        print('Yes')
    elif checkA[2] + checkA[4] + checkA[6] == 3:
        print('Yes')
    else:
        print('No')
resolve()

Measured memory_bytes: 38384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), m = sc.nextInt();
        V[] vs = new V[n];

        for (int i = 0; i < n; i++) {
            vs[i] = new V(sc.nextInt(), sc.nextInt());
        }

        Arrays.sort(vs);

        long ret = 0;
        for (int i = 0;m > 0;i++) {
            if (m >= vs[i].b) {
                ret += 1L * vs[i].a * vs[i].b;
                m -= vs[i].b;
            } else {
                ret += 1L * vs[i].a * m;
                m = 0;
            }
        }

        System.out.println(ret);
    }

    class V implements Comparable<V> {

        int a, b;

        V(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(V o) {
            return a - o.a;
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 89464
from collections import defaultdict


class Solution:
    def main(self):
        N, M = map(int, input().split())
        L = []
        R = []
        cards = set(list(range(1, N+1)))
        left = 1
        right = N
        for _ in range(M):
            l, r = map(int, input().split())
            if right < l or r < left:
                print(0)
                return 0

            left = max(l, left)
            right = min(r, right)
        else:
            print(right-left+1)
            return


if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 13504
//  Created by liszt on 2019/08/04.
#include<bits/stdc++.h>
using namespace std;

int main(){
    long long n,k; cin>>n >>k;
    long long ans=k;
    for(int i=1;i<n;i++)ans*=k-1;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] S = new int[n];
		String[] strArray = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			S[i] = Integer.parseInt(strArray[i]);
		}
		
		int q = Integer.parseInt(br.readLine());
		int[] T = new int[q];
		strArray = br.readLine().split(" ");
		for(int i = 0; i < q; i++){
			T[i] = Integer.parseInt(strArray[i]);
		}		
		
		int count = 0;
		for(int i = 0; i < T.length ; i++){
			if(linearSearch(S, T[i]) != -1){
				count++;
			}
		}
		System.out.println(count);
	}
	
	static int linearSearch (int[] array , int key){
		int result = -1;
		
		for(int i = 0; i < array.length ;i++){
			if(array[i] == key){
				return i;
			}
		}
		
		return result;
	}

}

Measured memory_bytes: 26928
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n,k,q;
	cin>>n>>k>>q;
	vector<int> a(q),b(n,0);
	rep(i,q) cin>>a[i];
	rep(i,q) b[a[i]-1]+=1;
	rep(i,n){
		if(b[i]>q-k) cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,a,b; cin>>n>>a>>b;
	int ans=b;
	chmin(ans,a*n);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

typedef long long ll;

char S[500005];
ll cnt[500005];
int flag[500005];

vector<int>v;

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

int main() {

	scanf("%s", S);

	int N = strlen(S);

	int i;

	int prev = 0;

	for (i = 0; i < N; i++) {
		if (S[i] == '<') { flag[i + 1] = 1; }
		else { flag[i + 1] = -1; }
	}

	int plus = 1;
	int minus = -1;

	for (i = 1; i < N; i++) {
		if (flag[i] != flag[i + 1]) {
			if (flag[i] > 0) {
				v.push_back(plus);
				plus = 0;
			}
			else {
				v.push_back(minus);
				minus = 0;
			}
		}
		if (flag[i] > 0) { plus++; }
		else { minus--; }
	}

	if (flag[N] > 0) { v.push_back(plus); }
	else { v.push_back(minus); }

	/*

	printf("flag\n");

	for (i = 0; i <= N; i++) {
		printf("%d ",flag[i]);
	}

	printf("\n連続\n");

	for (i = 0; i < v.size(); i++) {
		printf("%d ",v[i]);
	}

	printf("\n");
	*/

	int j;

	int pos = 0;

	for (i = 0; i < v.size(); i++) {
		if (v[i] > 0) {
			int x = 0;
			for (j = 0; j < v[i]; j++) {
				cnt[pos] = (ll)x;
				x += 1ll;
				pos++;
				//printf("プラスとして%d番目を%dで埋める,v[i]=%d,i=%d,j=%d\n", pos-1,x-1,v[i],i,j);
			}
		}
		else {
			int x = -v[i];
			for (j = 0; j < -v[i]; j++) {
				cnt[pos] = (ll)x;
				x -= 1ll;
				pos++;
				//printf("マイナスとして%d番目を%dで埋める,-v[i]=%d,i=%d,j=%d\n",pos-1,x+1,-v[i],i,j);
			}
		}
	}

	//printf("%d\n",cnt[8]);

	pos = 0;

	for (i = 0; i < v.size() - 1; i++) {
		//printf("pos=%d,i=%d,v[i]=%d,v[i+1]=%d\n",pos,i,v[i],v[i+1]);
		if (v[i] > 0 && v[i + 1] < 0) { cnt[pos + v[i]] = max(v[i], -v[i + 1]); pos += v[i]; }
		else if (v[i] < 0 && v[i + 1]>0) { pos += -v[i]; }
	}

	if (S[N - 1] == '>') { cnt[N] = 0ll; }
	else { cnt[N] = cnt[N - 1] + 1ll; }

	/*

	printf("cnt\n");

	for (i = 0; i <= N; i++) {
		printf("%d ", cnt[i]);
	}

	printf("\n");

	*/

	ll ans = 0ll;

	for (i = 0; i <= N; i++) {
		ans += cnt[i];
	}

	printf("%lld\n", ans);

	/*

	0<1
	3>2 >1 >0
	0<1 <2
	1>0
	0<1 <2 <3 <4 <5
	3> 2> 1>0
	0<1

		0 < 3> 2 > 1 > 0< 1 < 2 > 0< 1 < 2 < 3 < 4 < 5 > 2 > 1 > 0< 1



	printf("%d\n",ans);
	*/

	return 0;
}


Measured memory_bytes: 7668
import math
a, b, x = list(map(int, input().split()))

ans = 0
if a * a *b / 2.0 <= x:
    ans = math.atan(2 * (a * a * b - x) / (a * a * a))
else:
    ans = math.pi / 2 - math.atan(2 * x / (a * b * b))

print(math.degrees(ans))

Measured memory_bytes: 2940
import java.util.*
tailrec fun loop(): Unit {
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
    if (n == 0) return
    val cards = Array(n){ readLine()!!.toInt()}
    val maxSegmentTree = MaxSegmentTree(n)
    val minSegmentTree = MinSegmentTree(n)
    for ((i, c) in cards.withIndex()) {
        maxSegmentTree.increase(i, c)
        minSegmentTree.reduce(i, c)
    }
    val ck = (0 .. n - k).map { from ->
        (from until from + k).map{i -> cards[i].toLong()}.reduce(Long::times)
    }.max()!!
    val newCk = (0 .. n - k).map{from ->
        (from until from + k).map{i -> cards[i].toLong()}.reduce(Long::times) / minSegmentTree.find(from, from + k - 1) * Math.max(maxSegmentTree.find(0, from - 1), maxSegmentTree.find(from + k, n - 1))
    }.max()!!
    println(
            if (k == 1 && cards.max()!!.let{max -> cards.count{it == max} == 1}) "NO GAME" else if (newCk < ck) 0 else newCk - ck
    )
    loop()
}
class MaxSegmentTree(val size: Int){
    private val mArray = ArrayList<Array<Int>>().let{
        it.add(Array(size){Int.MIN_VALUE})
        while(it.last().size > 1){
            it.add(Array((it.last().size + 1) / 2){Int.MIN_VALUE})
        }
        it.toTypedArray()
    }
    fun increase(at: Int, to: Int): Unit {
        var position = at
        for (array in mArray){
            array[position] = Math.max(array[position], to)
            position /= 2
        }
    }
    fun find(from: Int, to: Int): Int {
        tailrec fun sub(left: Int, right: Int, depth: Int = 0, result: Int = Int.MIN_VALUE): Int {
            return if (left <= right && mArray.size > depth){
                var r = result
                if (left % 2 == 1) r = Math.max(r, mArray[depth][left])
                if (right % 2 == 0) r = Math.max(r, mArray[depth][right])
                if (left == right) r
                else sub((left + 1) / 2, (right - 1) / 2, depth + 1, r)
            }else {
                result
            }
        }
        return sub(from, to)
    }
}
class MinSegmentTree(val size: Int) {
    private val mArray = ArrayList<Array<Int>>().let{
        it.add(Array(size){Int.MAX_VALUE})
        while(it.last().size > 1){
            it.add(Array((it.last().size + 1) / 2){Int.MAX_VALUE})
        }
        it.toTypedArray()
    }
    fun reduce(at: Int, to: Int): Unit {
        var position = at
        for (array in mArray){
            array[position] = Math.min(array[position], to)
            position /= 2
        }
    }
    fun find(from: Int, to: Int): Int {
        tailrec fun sub(left: Int, right: Int, depth: Int = 0, result: Int = Int.MAX_VALUE): Int {
            return if (left <= right && mArray.size > depth){
                var r = result
                if (left % 2 == 1) r = Math.min(r, mArray[depth][left])
                if (right % 2 == 0) r = Math.min(r, mArray[depth][right])
                if (left == right) r
                else sub((left + 1) / 2, (right - 1) / 2, depth + 1, r)
            }else {
                result
            }
        }
        return sub(from, to)
    }

}
fun main(args:Array<String>?): Unit {
    loop()
}


Measured memory_bytes: 42840
#include <atcoder/convolution>
#include <cstdio>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  std::vector<int> a(n), b(m);

  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) scanf("%d", &b[i]);

  a = atcoder::convolution(a, b);

  for (int i = 0; i < n + m - 1; ++i) printf("%d ", a[i]);
  printf("\n");
  return 0;
}


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

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

int main() {
    string s;
    cin >> s;
    int ans = 1;

    for(int i = 0; i < s.length(); i++){
        if (i % 2 == 0 && s[i] == 'L') {
            ans = 0;
        }if(i % 2 == 1 && s[i] == 'R') {
            ans = 0;
        }
    }
    if(ans == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],i;
  for(i=0;i<n;i++){
     scanf("%d",&a[i]);
     if(a[i]%2==0){
       if(!(a[i]%3==0||a[i]%5==0)){
         printf("DENIED");
         return 0;
       }
     }
  }
  printf("APPROVED");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define max(a, b) ((int)(a) > (int)(b) ? (a) : (b))
#define min(a, b) ((int)(a) > (int)(b) ? (b) : (a))

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

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

    for(int i = 0; i < min(K, 50); i++)
    {
        for(int j = 0; j < N + 1; j++) { lamp[j] = 0; }
        for(int j = 0; j < N; j++)
        {
            lamp[max(0, j - A[j])] += 1;
            lamp[min(N, j + A[j] + 1)] -= 1;
        }

        for(int j = 1; j < N + 1; j++) { lamp[j] += lamp[j - 1]; }
        for(int j = 0; j < N + 1; j++) { A[j] = lamp[j]; }
    }

    for(int i = 0; i < N; i++)
    {
        printf("%d ", A[i]);
    }
    printf("\n");
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<pair<int, int>> A;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        A.push_back(make_pair(x, i));
        A.push_back(make_pair(y, i));
    }
    sort(A.begin(), A.end());
    int vmax = A.back().first, imax = A.back().second;
    A.erase(A.end() - 1);
    int vmin = A.front().first, imin = A.front().second;
    A.erase(A.begin());

    int64_t ans = 0;
    {
        vector<bool> used(n, false);
        used[imin] = true;
        int left = 0;
        int bmax = vmin;
        int rmin = vmax;
        while (left < SZ(A)) {
            if (!used[A[left].second]) {
                bmax = A[left].first;
            } else {
                rmin = min(rmin, A[left].first);
            }
            used[A[left].second] = true;
            left++;
        }
        ans = (int64_t) (vmax - rmin) * (bmax - vmin);
    }
    if (imax != imin) {
        int len = -1;
        for (int step = 1 << 29; step > 0; step /= 2) {
            vector<int> cnt(n, 0);
            int clen = len + step;
            int have = 0;
            bool ok = false;
            for (int i = 0, j = 0; i < SZ(A) && !ok; ++i) {
                while (j < SZ(A) && A[j].first - A[i].first <= clen) {
                    cnt[A[j].second]++;
                    if (cnt[A[j].second] == 1) {
                        have++;
                    }
                    j++;
                }
                if (have == n) {
                    ok = true;
                }
                cnt[A[i].second]--;
                if (cnt[A[i].second] == 0) {
                    have--;
                }
            }
            if (!ok) {
                len = clen;
            }
        }
        len++;
        ans = min(ans, (int64_t) (vmax - vmin) * len);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6128
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int a = in.nextInt();
        int b = in.nextInt();

        out.println(Math.max(a+b, Math.max(a - b, a * b)));
    }

}


Measured memory_bytes: 21844
n = int(input())
a=[]
for i in range(n):
    a.append(int(input()))

b_set=set()

ans=1
now=0
while True:
    nxt=a[now]-1
    if nxt==1:
        print(ans)
        exit()
    else:
        if nxt in b_set:
            print(-1)
            exit()
        b_set.add(nxt)
        ans+=1
        now=nxt


Measured memory_bytes: 55896
# -*- coding: utf-8 -*-
import heapq


n = int(input())
q = []

for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(q, (b, a))

wk_time = 0
finished = True
for _ in range(n):
    b, a = heapq.heappop(q)
    wk_time += a
    if wk_time > b:
        finished = False
        break

print("Yes" if finished else "No")


Measured memory_bytes: 28760
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    rep(i,5){
        int x=in();
        if(i+1!=x){
            cout<<i+1<<endl;
        }
    }
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 2e5 + 7;
const LL INF = 1e18 + 7;

int n;
LL x, T[N];

LL count(int k)
{
    LL ans = x * (n + k);
    int tmp = k, kr = 1;
    for(int i = n; i; i--)
    {
        if(kr == 1)
            ans += 2LL * T[i];
        ans += T[i] * (2 * kr + 1);
        tmp--;
        if(tmp == 0)
        {
            tmp = k;
            kr++;
        }
    }
    return ans;
}

int main()
{
    _upgrade
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
        cin >> T[i];
    LL ans = INF;
    if(n <= 2000)
    {
        for (int i = 1; i <= n; i++)
            ans = min(ans, count(i));
    }
    else
    {
        int l = 1, r = n;
        while(l + 20 < r)
        {
            int l1 = (l + l + r) / 3;
            int r1 = (l + r + r) / 3;
            LL c1 = count(l1), c2 = count(r1);
            ans = min({ans, c1, c2});
            if(c1 < c2)
            {
                r = r1;
            }
            else
            {
                l = l1;
            }
        }
        for(int i = l; i <= r; i++)
            ans = min(ans, count(i));
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin >>a>>b;
    
    if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)cout << "Possible" << endl;
    else cout << "Impossible" <<  endl;
    
    return 0;
}



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

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

int H,W,N;

typedef vector<vector<char>>VVc;

bool Solve(VVc grid){
	REP(i,H){
		REP(j,W){
			//cout<<grid[i][j];
		}
		//cout<<endl;
	}

	bool flag=true;
	while(flag){
		//{{{ Drop
		REP(j,W){
			int cnt=0;
			for(int i=H-1; i>=0;i--){
				if(grid[i][j]=='.')cnt++;
				else if(cnt){
					flag=true;
					grid[i+cnt][j]=grid[i][j];
					grid[i][j]='.';
				}
			}
		}
		//}}}

		
		//{{{ Delete
		flag=false;
		VVc tmp=grid;
		REP(i,H){
			REP(j,W){
				if(grid[i][j]=='.')continue;

				char tgt=grid[i][j];
				if(i<=H-N){
					int cnt=0;
					queue<pair<int,int>>Q;
					for(int k=0; ;k++){
						if(i+k>=H)break;
						else if(grid[i+k][j]==tgt){
							Q.push({i+k,j});	cnt++;
						}else break;
					}
					if(cnt>=N){
						flag=true;
						while(Q.empty()==false){
							pair<int,int> f=Q.front();	Q.pop();
							tmp[f.first][f.second]='.';
						}
					}
				}

				if(j<=W-N){
					int cnt=0;
					queue<pair<int,int>>Q;
					for(int k=0; ;k++){
						if(j+k>=W)break;
						else if(grid[i][j+k]==tgt){
							Q.push({i,j+k});
							cnt++;
						}else break;
					}
					if(cnt>=N){
						flag=true;
						while(Q.empty()==false){
							pair<int,int> f=Q.front();	Q.pop();
							tmp[f.first][f.second]='.';
						}
					}
				}
			}
		}
		grid=tmp;
		//}}}
	}

	int cnt=0;
	REP(i,H){
		REP(j,W){
			if(grid[i][j]!='.')cnt++;
		}
	}

	if(cnt){
		return false;
	}else{
		return true;
	}
}

int main(){
	cin>>H>>W>>N;
	VVc tile(H,vector<char>(W));
	REP(i,H)REP(j,W)cin>>tile[i][j];


	REP(i,H){
		REP(j,W-1){
			//if(tile[i][j]=='.'||tile[i][j+1]=='.')continue;

			swap(tile[i][j],tile[i][j+1]);
			if( Solve(tile) ){
				cout<<"YES"<<endl;
				return 0;
			}
			swap(tile[i][j],tile[i][j+1]);
		}
	}

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



Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  bool num[10];
  for(int i = 0;i < 10;i++)
    num[i] = true;
  for(int i = 0;i < k;i++){
    int d;
    cin >> d;
    num[d] = false;
  }
  int a,f = 0;
  for(int u = 0;u < 10;u++){
    for(int i = 0;i < 10;i++){
      for(int j = 0;j < 10;j++){
	for(int k = 0;k < 10;k++){
	  for(int l = 0;l < 10;l++){
	    a = u*10000+1000*i+j*100+k*10+l;
	    
	    vector <int> m;
	    int b = a,sn = 0;
	    while(b != 0){
	      sn++;
	      b = b/10;
	    }
	    b = a;
	    for(int o = 0;o < sn;o++){
	      
	      m.push_back(b%10);
	      b = b/10;
	    }
	  bool fl = true;
	  for(int o = 0;o < m.size();o++)
	    fl = fl && num[m[o]];
	  if(fl && a >= n){
	    //cout << sn << endl;
	    //cout << m[0] << "  " << m[2] << endl;
	    f = 1;
	    break;
	  }
	  
	  }
	  if(f == 1)
	    break;
      }
	if(f == 1)
	  break;
      }
    if(f == 1)
      break;
    }
    if(f == 1)
      break;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,i,j,sum=0,max=0;

    scanf("%d",&n);
    int ara[2*n],ara2[n];


    for(i=0; i<2*n; i++)
    {
        scanf("%d",&ara[i]);
    }

  /*  for(i=0; i<2*n; i++)
    {
        printf("%d",ara[i]);
    }
*/

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

      for(j=0; j<2*n;)
      {
          if(j==i)
          {sum+=ara[j];
              j=j+n;}
          else
          {
              sum+=ara[j];
              j++;
          }

      }
      ara2[i]=sum;
  }

  for(i=0; i<n; i++)
  {
      if(ara2[i]>=max)max=ara2[i];
  }

      printf("%d",max);

}

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

class AtCoderCS {
    static void Main(string[] args) {
        long[] ABCK = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        long A = ABCK[0], B = ABCK[1], C = ABCK[2], K = ABCK[3];

        long ans = 0;
        if (K >= A) {
            ans += A;
            K -= A;
        } else {
            ans += K;
            K = 0;
        }

        if (K >= B)
            K -= B;
        else
            K = 0;

        ans -= K;

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28240
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;
  
  vector<int> v;
  int now = 1, cnt = 0;
  rep(i,n){
    if(s[i] == (char)('0'+now)) cnt++;
    else{
      v.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  if (cnt != 0) v.push_back(cnt);
  if(v.size() %2 == 0) v.push_back(0);
  int Add = 2 * k +1;
  int ans = 0;
  int left = 0;
  int right = 0;
  int tmp = 0;
  
  for(int i = 0; i < v.size(); i+=2){
    int Nextleft = i;
    int Nextright = min(i+Add,(int)v.size());
    
    while(Nextleft > left){
      tmp -= v[left];
      left++;
    }
    while(Nextright > right){
      tmp += v[right];
      right++;
    }
    
    ans = max(tmp,ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a[5],b[5],c[5],i,max=0,num=0;
    string str[5]={"A","B","C","D","E"};
    while(cin>>a[0]>>b[0]){
        if(a[0]==0&&b[0]==0)break;
        for(i=1;i<5;i++){
            cin>>a[i]>>b[i];
        }
        for(i=0;i<5;i++){
            c[i]=a[i]+b[i];
        }
        for(i=0;i<5;i++){
            if(max<c[i]){
            max=c[i];
                num=i;
            }
        }
        cout<<str[num]<<" "<<max<<endl;
        max=0;
    }
    return 0;
}

Measured memory_bytes: 3096
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
l = [int(input()) for _ in range(N)]

c = Counter(l)

ans = 0
for i, j in zip(c.keys(), c.values()):
    if j % 2 != 0:
        ans += 1

print(ans)


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

#define int long long

signed main() {
    int N;
    cin >> N;
    int F[100] = {};
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            int bit;
            cin >> bit;
            F[i] += bit * (1 << j);
        }
    }

    int P[100][11];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    int max_score = -pow(10, 20);
    for (int i = 1; i < 1024; i++) {
        int score = 0;
        for (int j = 0; j < N; j++) {
            int cur = 0;
            int a = i & F[j];
            for (int k = 0; k < 10; k++) {
                cur += (a >> k) & 1;
            }
            score += P[j][cur];
        }
        max_score = max(max_score, score);
    }
    cout << max_score << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,count;
	bool f=false;
	while(true){
	    cin>>a>>b;
		count=0;
		if(a==0&&b==0)
			break;
		if(f==true)
		    cout<<endl;
		f=true;
		bool h=false;
		for(int i=a;i<=b;i++){
			bool t=false;
			if(i%4==0)
				t=true;
			if(i%100==0)
				t=false;
			if(i%400==0)
				t=true;
			if(t==true){
				cout<<i<<endl;
				h=true;
			}
		}
		if(h==false)
			cout<<"NA"<<endl;
	}
    return 0;
}
 

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

struct edge{
    ll to,cap,cost,rev;
    edge(){}
    edge(ll to,ll cap,ll rev):to(to),cap(cap),rev(rev){}
    edge(ll to,ll cap,ll cost,ll rev):to(to),cap(cap),cost(cost),rev(rev){}
};

typedef vector<vector<edge> > graph;
struct Dinic{
    ll n;
    graph g;
    vector<ll> level,iter;
    Dinic() {}
    Dinic(ll n): n(n){
	g.resize(n);
	level.resize(n);
	iter.resize(n);
    }
    void add_edge(ll from, ll to, ll cost){
	g[from].push_back(edge(to,cost,g[to].size()   ) );
	g[to].push_back(edge(from,0,g[from].size() -1 ) );
    }
    void bfs(ll s){
	fill(level.begin(),level.end(),-1);
	queue<ll> q;
	q.push(s);
	level[s] = 0;
	while(!q.empty()){
	    ll tmp = q.front();
	    q.pop();
	    for(ll i=0;i<g[tmp].size();i++){
		edge &e = g[tmp][i];
		if(e.cap > 0 && level[e.to] < 0){
		    level[e.to] = level[tmp] + 1;
		    q.push(e.to);
		}
	    }
	}
    }
    ll dfs(ll v,ll t,ll f){
	if( v == t ) return f;
	for(ll &i = iter[v]; i < g[v].size() ; i++){
	    edge &e = g[v][i];
	    if( e.cap > 0 && level[v] < level[e.to] ){
		ll d = dfs(e.to, t, min(f,e.cap) );
		if( d > 0 ){
		    e.cap -= d;
		    g[e.to][e.rev].cap += d;
		    return d;
		}
	    }
	}
	return 0;
    }
    ll max_flow(ll s,ll t){
	ll flow = 0, f;
	while(1){
	    bfs(s);
	    if(level[t] < 0) return flow;
	    fill(iter.begin(),iter.end() , 0);
	    for(f = dfs(s,t,inf); f > 0; f = dfs(s,t,inf) ) flow += f;
	}
    }
};


int main(){
    ll v,e;
    cin>>v>>e;
    Dinic f(v);
    for(ll i=0;i<e;i++){
	ll u,v,c;
	cin>>u>>v>>c;
	f.add_edge(u,v,c);
    }
    cout<<f.max_flow(0,v-1)<<endl;
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

int main()
{
	ll i,j,k,a,b,ans = 0;
	ll N,M;
	ll mp[100010] = {0};
	ll mx = 0;
	ll mod = 998244353;
	vector<ll> v;
	cin >> N;
	for(i=0;i<N;++i)
	{
		cin >> j;
		if(mx < j)
			mx = j;
		v.push_back(j);
	}
	ans = 0;
	if(v[0]==0)
	{
		for(i=1;i<N;++i)
		{
			mp[v[i]] ++;
		}
		if(mp[0] == 0)
		{
			j = 1;
			for(i=1;i<mx;++i)
			{
				if(mp[i] == 0)
					j = 0;
			}
			if(j==1)
			{
				ans = 1;
				j = 1;
				for(i=1;i<=mx;++i)
				{
					for(k=0;k<mp[i];++k)
					{
						ans *= j;
						ans %= mod;
					}
					j = mp[i];
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 2168
/*
    B - Beautiful Strings
    https://atcoder.jp/contests/abc044/tasks/abc044_b
*/

#include <iostream>
#include <vector>

using namespace std;

#define ll long long
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)
#define r_1(v) cin >> v
#define r_2(v1, v2) cin >> v1 >> v2

int main() {
    string w;
    int ch[101] = {0};
    r_1(w);

    forn(i, 0, w.length()) ch[w[i] - 97]++;

    forn(i, 0, w.length()) {
        if (ch[w[i] - 97] % 2 != 0) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define sortA(a) sort(a.begin(),a.end())
#define sortD(a) sort(a.begin(),a.end(),greater<int>())
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    rep(i,n+1)
      a[i]=0;
    rep(i,k)
    {
      int d;
      cin>>d;
      rep(i,d)
      {
          int x;
          cin>>x;
          a[x]++;
      }
    }

    int ans = -1;
    rep(i,n+1)
    {
      if(a[i]==0)
        ans++;
    }
    cout<<ans;

	  return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    string S,T;
    cin >> S >> T;
    int siz=S.size();

    bool flag=true;
    map<char,char> m;
    REP(i,0,siz){
        if(m.find(S[i])==m.end()){
            m[S[i]]=T[i];
        }else if(m[S[i]]!=T[i]){
            flag=false;
            break;
        }
    }

    m.clear();
    REP(i,0,siz){
        if(m.find(T[i])==m.end()){
            m[T[i]]=S[i];
        }else if(m[T[i]]!=S[i]){
            flag=false;
            break;
        }
    }
    cout << ((flag)? "Yes" : "No" )<< endl;
    
}

Measured memory_bytes: 776
#include <iostream>

using namespace std;

int main(){
  int rep;
  cin >> rep;
  for(int i=0;i<rep;i++){
	int in,b = 0,c = 0;
	bool ball = true;
	for(int j=0;j<10;j++){
	  cin >> in;
	  if (in < b && in < c){     
		ball = false;
	  }
	  else if (in < b && in > c){
		c = in;
	  }
	  else if (in > b && in < c){
		b = in;
	  }
	  else if (in > b && in > c){
		((b > c)? b : c ) = in;
	  }
	}
	cout << (ball?"YES":"NO") << endl;
  }
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;





class UnionFind{
public:
    int uf[200005];
    UnionFind(){
        memset(uf,-1,sizeof uf);
    }
    
    int parent(int i){
        if (uf[i] < 0) return i;
        return uf[i] = parent(uf[i]);
    }
    
    void join(int i, int j){
        int pi = parent(i);
        int pj = parent(j);
        if (pi == pj) return;
        if (size(pi) < size(pj)) swap(pi,pj);
        uf[pi] += uf[pj];
        uf[pj] = pi;
        
    }
    
    int size(int i){
        int pi = parent(i);
        return abs(uf[pi]);
    }
    
    void init(){
        memset(uf,-1,sizeof uf);
    }
};





void solve(){

    int n,q;
    cin >> n >> q;
    UnionFind uf;
    rep(i,q){
        int t;
        cin >> t;
        int a,b;
        cin >> a >> b;
        if (t) cout << (uf.parent(a) == uf.parent(b)) << endl;
        else uf.join(a,b);
    }
    

}




int main() {
    int T;
    //cin >> T;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}




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

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

	if (1 == N % 2) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < S.size()/2; i++) {
		if (S[i] != S[i + N / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define radhey krishna
#define endl "\n"
 vector<int>v(4,0);
 string s;
 //string s[4] = {'AC' ,'TLE', 'WA','RE'};
int main(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
       ios_base::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	//int n , cnt1 =0, cnt2 = 0,cnt3 = 0, cnt4 = 0;
	cin>>n;
	for(int i =0 ;i<n;i++){
	   cin>>s; 
		if(s== "AC"){
			v[0]++;
		}
		else if(s == "WA"){
			v[1]++;
		}
		else if(s == "TLE"){
			v[2]++;
		}  
		else{  
			v[3]++;   
		}
	}    
		cout<<"AC"<<" "<<"x"<<" "<<v[0]<<endl;
		cout<<"WA"<<" "<<"x"<<" "<<v[1]<<endl;
        cout<<"TLE"<<" "<<"x"<<" "<<v[2]<<endl;
        cout<<"RE"<<" "<<"x"<<" "<<v[3]<<endl;
	
	return 0; 
}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

vector<int> a(100);
int ans = 0;

void sol() {
  bool skip = false;
  for (int i = 0; i < 100; i++) {
    if (a[i] <= 0) {
      skip = false;
      while (a[i] <= 0) ++i;
      if (i >= 100) break;
    }
    if (!skip) {
      skip = true;
      ++ans;
    }
  }
}

void water() {
  for (int i = 0; i < a.size(); i++) --a[i];
}

bool ok() {
  for (auto v : a) if (v > 0) return false;
  return true;
}

int main() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  while (!ok()) {
    sol();
    water();
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;

ll modi(ll a,ll n,ll MOD){
	if(n==0)
		return 1;
	else{
	    if(n%2==0){	      
         	ll temp=modi(a,n/2,MOD);	              
		    return (temp*temp)%MOD;		
        }
        else{
              return(a*modi(a,n-1,MOD))%MOD;	
        }
    }
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
        
	ll n,m,x;
	cin>>n>>x>>m;
	map<ll,ll>vis;
	map<ll,ll>rvis;
	vis[x]=1;
	rvis[1]=x;
	ll ans=x;
	for(ll i=1;i<n;i++){
		ll tans=modi(rvis[i],2,m);
		if(vis[tans]!=0){
			ll num=(i-vis[tans]+1);
			ll rem=n-i;
			ll ttans=0;
			for(ll j=vis[tans];j<=i;j++){
				ttans+=rvis[j];
			}
			ll ttansm=0;
			for(ll j=vis[tans];j<=vis[tans]+rem%num-1;j++){
				ttansm+=rvis[j];
			}	
			ans+=(ttans*(rem/num))+ttansm;
			break;	
		}
		else{
			vis[tans]=i+1;
			rvis[i+1]=tans;
			ans+=tans;
		}
	}
	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 9840