akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    readln;
    readln.chomp.uniq.count.writeln;
}


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

int main(){
  int x, y, X, Y;
  cin >> x >> y >> X >> Y;
  int z, w, Z, W;
  z = X + (y - Y);
  w = Y - (x - X);
  Z = x + (y - Y);
  W = y - (x - X);
  cout << z << ' ' << w << ' ' << Z << ' ' << W << endl; 
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n;
	while(scanf("%d",&n)){
		if(n==-1)break;
		if(n<=10)printf("%d\n",4280-1150);
		else{
			int price = 1150;
			if(n<=20){
				for(int i=0;i<n-10;++i){
					price+=125;
				}
				printf("%d\n", 4280-price);
			}else if(n<=30){
				price+=125*10;
				for(int i=0;i<n-20;++i){
					price+=140;
				}
				printf("%d\n",4280-price);
			}else {
				price += (125+140) * 10;
				for(int i=0;i<n-30;++i){
					price+=160;
				}
				printf("%d\n",4280-price);
			}
		}
	}
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
//const ll mod=1e9+7;
const ll mod=998244353;
const ll inf=1LL<<61;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-min
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// min-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=min(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return INF; // min
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return min(lv,rv); // min
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmin(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for(ll i=0;i<n;i++) {
    ll x,d;
    cin >> x >> d;
    x+=1e9;
    a[i]={-x,-d};
  }
  sort(a.begin(),a.end());
  segtree dp(n);
  dp.Set(0,n+1,inf);
  vec ans(n+1);
  ans[0]=1;
  for(ll i=0;i<n;i++) {
    ll x=a[i].first;
    ll d=a[i].second;
    ll v=x+d;
    ll l=-1,r=n;
    while(l+1<r) {
      ll tmp=(l+r)>>1;
      if(a[tmp].first>v) {
        r=tmp;
      }
      else {
        l=tmp;
      }
    }
    dp.Set(i,i+1,r);
    dp.Set(i,i+1,dp.Getmin(r,i+1));
    ans[i+1]=(ans[i]+ans[dp.Getmin(i,i+1)])%mod;
  }
  cout << ans[n] << endl;
}

Measured memory_bytes: 21376
from Queue import Queue

n, m = map(int, raw_input().split())
indeg = [0] * n
graph = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, raw_input().split())
    graph[x - 1].append(y - 1)
    indeg[y - 1] += 1

cola = Queue()
for i in range(n):
    if indeg[i] == 0:
        cola.put(i)
topsort = []
while not cola.empty():
    v = cola.get()
    topsort.append(v)
    for i in graph[v]:
        indeg[i] -= 1
        if indeg[i] == 0:
            cola.put(i)

dp = [0] * n
for i in range(n - 1, -1, -1):
    v = topsort[i]
    for u in graph[v]:
        dp[v] = max(dp[v], 1 + dp[u])
print(max(dp))


Measured memory_bytes: 25880
def actual(n, m, C, B, A):
    cnt = 0

    for A_i in A:
        ab = sum([a * b for a, b in zip(A_i, B)])

        if ab + C > 0:
            cnt += 1

    return cnt

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

A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
print(actual(N, M, C, B, A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;

#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    int N,M;cin >> N >> M;
    if(N >= M){
        cout<<0<<endl;
        return 0;
    }
    vector<int> vec;
    for(int a = 0;a < M;a++){
        int b;cin >> b;
        vec.push_back(b);
    }
    sort(vec.begin(),vec.end());
    vector<int> diff;
    for(int a = 0;a < M-1;a++){
        diff.push_back(vec.at(a+1)-vec.at(a));
    }
    sort(diff.begin(),diff.end());
    reverse(diff.begin(),diff.end());
    LL ans = vec.back()-vec.front();
    for(int a = 0;a < N-1;a++){
        ans -= diff.at(a);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1400
n = int(input())
t = 0
h = 0
for i in range(n):
    s = input().split()
    if s[0] < s[1]:
        h += 3
    elif s[0] > s[1]:
        t += 3
    else:
        t += 1
        h += 1
print(t,h)



Measured memory_bytes: 5592
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
  
  	private final static Scanner sc = new Scanner(System.in);
    public static void main (String [] args) {
      int N = sc.nextInt();
      int M = sc.nextInt();
      TreeMap<Long ,Long > map = new TreeMap<Long,Long>();
      for(int i = 0; i < N; i++) {
    	 long Ai = sc.nextLong();
    	 if(map.containsKey(Ai)) {
    		 map.replace(Ai, map.get(Ai) +1);
    	 } else {
    		 map.put(Ai,1l);
    	 } 
      }
      for(int i = 0; i < M; i++) {
    	  long key = map.lastKey();
    	  long value = map.get(key);
    	  if(value == 1) {
    		  map.remove(key);
    	  } else {
    		  map.replace(key, value-1);
    	  }
    	  key = key/2;
    	  if(map.containsKey(key)) {
    		  map.replace(key, map.get(key)+1);
    	  } else {
    		  map.put(key, 1l);
    	  }
      }
      long sum = 0;
      for(long key : map.keySet()) {
    	  sum += key * map.get(key);
      }
      System.out.println(sum);    
      
   }
}

Measured memory_bytes: 69168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    vector<ll> h(N);
    rep(i,N){
        cin >> h[i];
    }  

    sort(ALL(h));
    reverse(ALL(h));


    if(N <= K){
        cout << 0 << endl;
    }else{
        ll ans = 0;
        for(int i = K;i < N;i++){
            ans += h[i];
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

string f(ll a) {
  int cnt=0;
  int at=a;
  while(at>0) {
    at/=10;
    cnt++;
  }
  stringstream ss;
  rep(t,6-cnt) {
    ss<<"0";
  }
  ss<<a;
  return ss.str();
}

string make_id(ll p, vector<int>& cnt) {
  stringstream ss;
  ss << f(p) << f(cnt[p]+1);
  cnt[p]++;
  return ss.str();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<tuple<ll,ll,int>> ps(m);
  vector<int> cnt(n+1);
  vector<string> ids(m);
  rep(i,m) {
    ll p,y;
    cin>>p>>y;
    ps[i]=make_tuple(y,p,i);
  }
  sort(ps.begin(),ps.end());
  rep(i,m) {
    ll y,p;
    int idx;
    tie(y,p,idx) = ps[i];
    ids[idx] = make_id(p,cnt);
  }
  rep(i,m) {
    cout << ids[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 9728
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	char[] s = readln.chomp.to!(char[]);
	long k = readln.chomp.to!long;
	
	foreach(i, c; s){
		int x = 'z' + 1 - c;
		if(s[i] > 'a' && x <= k){
			s[i] = 'a';
			k -= x;
			}
		}
	
	s[$ - 1] = 'a' + (cast(long)(s[$ - 1] - 'a') + k) % 26;
	
	s.writeln;
	
	}

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

typedef pair<int, int> P;
int ans[200005];
int par[400005];    // Union-Find(2倍用意しておく)

void init(int n){
    for(int i = 0; i < 2 * n; ++i){
        par[i] = i;
    }
}

int find(int n){
    if(par[n] == n){
        return n;
    }
    else{
        return par[n] = find(par[n]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    
    if(x == y)      return;
    
    par[y] = x;
    return;
}

bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k, l;
    cin >> n >> k >> l;
    map<P, int> m;
    init(n);
    for(int i = 0; i < k; ++i){     // road
        int p, q;
        cin >> p >> q;
        --p;
        --q;
        unite(p, q);
    }
    for(int i = 0; i < l; ++i){     // rail
        int r, s;
        cin >> r >> s;
        --r;
        --s;
        unite(r + n, s + n);
    }
    
    for(int i = 0; i < n; ++i){
        ++m[P(find(i), find(i + n))];
    }
    
    for(int i = 0; i < n; ++i){
        ans[i] = m[P(find(i), find(i + n))];
    }
    
    for(int i = 0; i < n; ++i){
        cout << ans[i] << ((i == n - 1) ? "\n" : " ");
    }
}

Measured memory_bytes: 14336
import math

N=int(input())

PI = math.pi

X=[]
Y=[]
for i in range(N):
    x,y=[int(i) for i in input().split()]
    X.append(x)
    Y.append(y)

for i in range(N):
    kakudo = [math.atan2(Y[i]-Y[j],X[i]-X[j]) for j in range(N) if j != i]
    kakudo.sort()
#    print(kakudo)
    kmax = 0
    if N == 2:
        kmax = 2*PI
    else:
        for j in range(N-2):
            kmax = max(kmax,kakudo[j+1] - kakudo[j])
            kmax = max(kmax, kakudo[0] + 2*PI - kakudo[N-2])
    print(max(0,kmax-PI)/(2*PI))

#print(math.atan2(0,0))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
struct part{
	bool horf;
	int len;
};
int main()
{
	int white=0;
	bool ok[100001];
	int n,k;
	int dp[100001];
	part all[100001];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		char tmp;
		cin>>tmp;
		ok[i]=tmp-'0';
	}
	int i;
	int cnt=0;
	for(i=1;i<=n;)
	{
		all[++cnt].horf=ok[i];
		all[cnt].len=0;
		if(all[cnt].horf==0)
		{
			white++;
		}
		for(;i<=n;i++,all[cnt].len++)
		{
			if(ok[i]!=all[cnt].horf)
			{
				break;
			}
		}
	}
//	cout<<"  black:  "<<cnt-white<<"   white:  "<<white<<endl;
	if(white<=k)
	{
		cout<<n<<endl;
		return 0;
	}/*
	for(int i=1;i<=cnt;i++)
	{
		cout<<all[i].len<<" ";
	}
	cout<<endl;*/
	dp[0]=0;
	dp[1]=all[1].len;
	for(int i=2;i<=cnt;i++)
	{
		dp[i]=dp[i-1]+all[i].len;
	}
/*	for(int i=1;i<=cnt;i++)
	{
		cout<<dp[i]<<" "; 
	}
	cout<<endl;*/
	int big=0;
	for(int i=1;i<=cnt;i++)
	{
		int ans=dp[min(i+2*k-!all[i].horf,cnt)]-dp[i-1];
/*		if(all[i].horf!=all[i-1].horf&&all[i].horf!=all[i+1].horf)
		{
			ans+=all[i].len;
		}
		if(all[i+k+1].horf!=all[i+k].horf&&all[i+k+1].horf!=all[i+k+2].horf)
		{
			ans+=all[i].len;
		}*/
		big=max(big,ans);
//		printf("%3d",ans);
	}
//	cout<<endl;
	cout<<big<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
map<int,int> ma;
int main(){
    int n;
    scanf("%d",&n);
    int f1,f2=-10086;
    int x;
    ma.clear();
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        ma[x]++;
        if(i==1) f1=x;
        if(x!=f1) f2=x;
    }
    int re1=f1,re2=f2;
    if(f1==0 && f2==-10086){
        puts("Yes");
        return 0;
    }
    if(n%3!=0||ma.size()>3){
        puts("No");
        return 0;
    }
    
    ma[f1]--,ma[f2]--;
    for(int i=3;i<=n;i++){
        f1=f1^f2;
        if(ma[f1]==0){
            puts("No");
            return 0;
        }
        ma[f1]--;
        swap(f1,f2);
    }
    if((f1^f2)!=re1 || (f2^re1)!=re2){
        puts("No");
        return 0;
    }
    puts("Yes");
}


Measured memory_bytes: 3840
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

      
 public static void main(String[] args) {
    
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
    int K = in.nextInt();
    int[] arr = new int[N];
    int[] dp = new int[N];
    
    for (int m = 1; m <= N; ++m) {
       int n = in.nextInt();
       arr[m-1] = n;
    }
    
    for(int i = 0; i < N; i++) {
        int start = Math.max(i-K, 0);
        dp[i] = Integer.MAX_VALUE;
        for(int j = start; j < i; j++) {
            if(j == 0) {
                dp[i] = Math.abs(arr[i]-arr[j]);
            }
            else {
                dp[i] = Math.min(Math.abs(arr[i]-arr[j])+dp[j], dp[i]); 
            }
        }
    }

    System.out.println(dp[N-1]);
  }
  
}

Measured memory_bytes: 59128
#if 0
#endif

#include <iostream>
#include <string>
using namespace std;

int /* 頂点の数, 最大100,000 */ POINT_NUM,
    /* 辺の数, 最大500,000 */ NODE_NUM,
    /* 始点 */ start,
    S[500010], T[500010], D[500010];
int C[100010]; // 各頂点までの最短距離の上限
const int Inf = 10000 * 100000 + 100;

int main()
{
    cin >> POINT_NUM >> NODE_NUM >> start;
    if (NODE_NUM == 0)
    {
        for (int i = 0; i < POINT_NUM; i++)
        {
            cout << (i == start ? to_string(0) : "INF") << endl;
        }
        return 0;
    }
    for (int i = 0; i < NODE_NUM; i++)
    {
        // 変数の入力
        cin >> S[i] >> T[i] >> D[i];
    }
    for (int i = 0; i < POINT_NUM; i++)
    {
        // Cの初期化
        C[i] = i != start ? Inf : 0;
    }
    for (int t = 0; t < POINT_NUM; ++t)
    {
        bool update = false;
        for (int i = 0; i < NODE_NUM; ++i)
        {
            // t: 頂点
            // i: ノードの値
            int s = S[i], t = T[i], d = D[i];
            if (C[s] < Inf && C[t] > C[s] + d)
            {
                C[t] = C[s] + d;
                update = true;
            }
        }
        if (!update)
            break;
    }
    for (int i = 0; i < POINT_NUM; i++)
    {
        cout << (C[i] == Inf ? "INF" : to_string(C[i])) << endl;
    }
}



Measured memory_bytes: 9376
#include<cstdio>
#define tin int
#define itn int
#define tni int
#define nit int
#define nti int
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define ll long long
#define inl inline
#define br break
#define con continue
#define mst(a,b) memset(a,b,sizeof(a))
#define fa(x,a,b) for(x=a;x<=b;++x)
#define fb(x,a,b) for(x=a;x>=b;--a)
#define infa 0x3f3f3f3f
#define infb 0x7fffffff
#define infc 1061109567
#define infd 0x7f
using namespace std;
#define maxa 10
#define maxb 10004
#include<cstring>
#include<iostream>

itn a,b,x,y;

itn main()
{
	scanf("%d%d",&a,&b);
	if((max(a,b)>0)&&(min(a,b)<0))
	{
		pritnf("Zero\n");
		return 0;
	}
	else if((a>0)&&(b>0))
	{
		pritnf("Positive\n");
		return 0;
	}
	else if(a==b)
	{
		if(a>0)
		{
			pritnf("Positive\n");
			return 0;
		}
		else if(a<0)
		{
			pritnf("Negative\n");
			return 0;
		}
		else
		{
			pritnf("Zero\n");
			return 0;
		}
	}
	else
	{
		if((max(a,b)-min(a,b))%2==0)
		{
			pritnf("Negative\n");
			return 0;
		}
		else
		{
			pritnf("Positive\n");
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int  main()
{
   int r,g,b;
    cin>>r>>g>>b;
    int t=r*100+g*10+b;
    if(t%4==0)
    {
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
}


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

int main() {
    ld a,b;
    ld h,m;
    std::cin >> a>>b>>h>>m;

    std::cout <<setprecision(20)<< hypot(b*cosl((m/60)*M_PI*2)-a*cosl(((h+m/60)/12)*M_PI*2),b*sinl((m/60)*M_PI*2)-a*sinl(((h+m/60)/12)*M_PI*2))   << std::endl;
}


Measured memory_bytes: 4188
#include <stdio.h>
#include <utility>
#include <queue>
#define large 1001
// #define large 50

using namespace std;

int h,w;
char a[large][large];
int visited[large][large]={};//黒からのユークリッド距離を保有
int vecx[]={1,-1,0,0};
int vecy[]={0,0,1,-1};

queue<pair<int,int>> que;//<x,y>

void bfs(pair<int,int> p)
{
    for(int i=0;i<4;i++)
    {
        if(!(p.first+vecx[i]<0||p.first+vecx[i]>=h||p.second+vecy[i]<0||p.second+vecy[i]>=w)&&a[p.first+vecx[i]][p.second+vecy[i]]=='.')
        {
            a[p.first+vecx[i]][p.second+vecy[i]]='#';
            visited[p.first+vecx[i]][p.second+vecy[i]]=visited[p.first][p.second]+1;
            que.push(make_pair(p.first+vecx[i],p.second+vecy[i]));
        }
    }
}

int main()
{
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++) scanf("%s",&a[i]);

    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    if(a[i][j]=='#')
    {
        que.push(make_pair(i,j));
    }

    while(!que.empty())
    {
        bfs(que.front());
        que.pop();
    }
    int max=0;
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    if(max<visited[i][j]) max=visited[i][j];
    printf("%d\n",max);

}

Measured memory_bytes: 11280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(RALL(v));
    int ans1 = v[0], ans2 = 0, num = 0;
    rep(i,n) {
        if(ans1-v[i]<v[i]) {
            if(num<ans1-v[i]) {
                num = ans1-v[i];
                ans2 = v[i];
            }
        }
        else {
            if(num<v[i]) {
                num = v[i];
                ans2 = v[i];
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;

    return 0;
}

Measured memory_bytes: 640
def myAnswer(X:int) -> int:
   while True:
      for i in range(2,X):
         if(X % i==0):
            break
      else:
         return X
      X+=1

def modelAnswer():
   tmp=1
def main():
   X = int(input())
   print(myAnswer(X))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define Max 1000000000

int main(void){
  long i,j;
  long rest1,rest2=1;

  long long s;
  scanf("%lld",&s);

  if(s==1000000000000000000){
    printf("0 0 0 %ld %ld 0\n",Max,Max);
    return 0;
  }

  long root_s1=sqrt(s)+1;
  long root_s2=root_s1;

  if((root_s1-1)*(root_s2-1)>s){
    root_s1--;
    root_s2--;
  }else if(root_s1*(root_s2-1)>s){
    root_s2--;
  }

  rest1=root_s1*root_s2-s;

  if(rest1>Max){
    for(i=2;i<rest1;i++){
      while(0){
        if(rest1%i==0){
          rest1/=i;
          rest2*=i;
        }else{
          break;
        }
      }
      if(rest1<Max){
        break;
      }
    }
  }

  printf("0 0 %ld %ld %ld %ld\n",root_s1,rest1,rest2,root_s2);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<char,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
const ll INF=1000000;
using namespace std;

int main( ) {
  ll A,B;
  cin>>A>>B;
  vec C(A);
  rep(i,0,A) cin>>C[i];
  sort(C);
  ll count=0;
  rep(i,0,B) {
    count+=C[i];
  }
  cout<<count<<endl;
}
     
    

Measured memory_bytes: 3632
MOD = 10**9+7

def powmod(x, n, m)
  if n == 0
    1
  elsif n % 2 == 0
    powmod(x * x % m, n / 2, m)
  else
    powmod(x * x % m, n / 2, m) * x % m
  end
end

def inverse(x)
  powmod(x, MOD - 2, MOD)
end

def fact(n)
  (1..n).inject(1) {|a, b| (a * b) % MOD }
end

def falling_fact(n, k)
  (n-k+1..n).inject(1) {|a, b| (a * b) % MOD }
end

def binom(n, k)
  falling_fact(n, k) * inverse(fact(k))
end

n, a, b = gets.split(" ").map(&:to_i)
puts (powmod(2, n, MOD) - 1 - binom(n, a) - binom(n, b)) % MOD


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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 string YES = "Yes";
const string NO = "No";

void solve(std::string S) {
    for (int i = 0; i < S.size(); i++) {
        if( S[i] == 'D' || S[i] == 'U') continue;
        if (i % 2 == 1) {
            if( S[i] == 'R' ){
                cout << NO << endl;
                return;
            }
        } else {
            if( S[i] == 'L' ){
                cout << NO << endl;
                return;
            }
        }
    }
    cout << YES << endl;
}

int main() {
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var r = cin.nextInt();
            if (n >= 10)
            {
                Console.WriteLine(r);
            }
            else
            {
                var ans = r + (100 * (10 - n));
                Console.WriteLine(ans);
            }
            
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

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

Measured memory_bytes: 1536
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>

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


int main() {
	int n, i = 0,a,e=0;
	cin >> n;
	rep(i, n) {
		cin >> a;
		if ((i + 1) % 2 != 0 && a % 2 != 0) {
			e++;
		}
	}
	cout << e << endl;
	
	
	return 0;
}

Measured memory_bytes: 3620
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0,0)
now = 1
seen = [0]*(n+1)
seen[1] = 1
for i in range(1,n+1):
  now = a[now]
  if seen[now] != 0:
    break
  else:
    seen[now] = i+1
if k <= max(seen):
  print(a[seen.index(k)])
elif (k - max(seen)) % (max(seen)-seen[now]+1) == 0:
  print(a[seen.index(max(seen))])
else:
  print(a[seen.index(max(seen) - (max(seen)-seen[now]+1) + (k - max(seen)) % (max(seen)-seen[now]+1))])

Measured memory_bytes: 32308
#include <iostream>
#include <vector>
#include <string>

using namespace std;
using ll = long long;

int cnt[26] = {0};

int main(){
    string s;
    cin >> s;
    ll ans = 1;
    for (int i = 0; i < s.size(); ++i) {
        ans += i - cnt[s[i] - 'a'];
        //cout << ans << endl;
        cnt[s[i] - 'a']++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 832
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
#define N 200000
//sは始点、nは頂点の数
int d[N+1]={};
struct edge{
    int to,cost;
};
vector<edge>G[N+1];
void dijkstra(int s,int n){
    //最短距離が小さい順に取りだす
    priority_queue<P,vector<P>,greater<P> >que;
    fill(d,d+n,INF);
    d[s]=0;
    //P<int,int>最短距離、頂点の番号
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        //vに隣接している頂点の距離を更新
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
int main(void){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        edge e;
        e.to=b;
        e.cost=1;
        G[a].push_back(e);
    }
    dijkstra(0,n);
    if(d[n-1]<=2)printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 11124
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll n,d;
    cin >> n >> d;
    vector<ll> x(n),y(n);
    ll ct = 0;
    rep(i,0,n){
        cin >> x[i] >> y[i];
        if(pow(x[i],2) + pow(y[i],2) <= d*d){
            ct++;
        }
    }
    cout << ct << endl;

}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int cnt[4][3][10];

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

    int n;
    cin >> n;
    while (n--)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        b--;
        f--;
        r--;
        cnt[b][f][r] += v;
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << cnt[i][j][k];
            }
            cout << endl;
        }
        if(i!=3) cout << "####################" << endl;
    }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  long long X;
  cin >> X;
  long long maxNum;
  maxNum = 1;
  for(int i = 2; i < 100; i++){
    for(int j = 2;;j++){
      long long n = pow(i,j);
      if(n <= X) maxNum = max(n,maxNum);
      else break;
    }
  }
  cout << maxNum << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main() {
	int n, m, k, num;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			num = i * m + j * n - 2 * (i * j);
			if (num == k) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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


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

int main(){
    int x, y, i;
    
    for(i = 0; i <= 3000; i ++){
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }else if(x < y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2988
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
lis = range(1, n+1)

#permulations(l,n)でリストlの要素のうちn個を選んで並べる
a = list(itertools.permutations(lis))

print(abs(a.index(p) - a.index(q)))


Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    mat c(2, vec(n));
    rep(i, 2) rep(j, n) cin >> c[i][j];

    int dp[2][110] = {};
    dp[0][0] = c[0][0];
    dp[1][0] = c[1][0] + c[0][0];

    rep(i, n-1) rep(j, 2) {
        if (j == 0) dp[j+1][i] = max(dp[j+1][i], dp[j][i] + c[j+1][i]);
        dp[j][i+1] = max(dp[j][i+1], dp[j][i] + c[j][i+1]);
    }

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

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Coer
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int W = in.nextInt();
            int[] w = new int[n + 1];
            int[] v = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                w[i] = in.nextInt();
                v[i] = in.nextInt();
            }
            // 只考虑前i个物品的情况下，背包容量是j所能凑出的最大价值之和
            long[][] dp = new long[n + 1][W + 1];
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= W; j++) {
                    if (w[i] > j) {
                        dp[i][j] = dp[i - 1][j];
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
                    }
                }
            }
            out.println(dp[n][W]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

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

signed main() {
  int N;
  cin >> N;
  int ans = 0;
  static int a[101010];
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    tmp--;
    a[i] = tmp;
    if (tmp < i) {
      if (a[tmp] == i) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) {
    ostringstream stm;
    stm << n;
    return stm.str();
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}


int const INF = 1001001001;


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

int a,b;
cin >> a >> b;
int c = (b-a) * (b-a+1) / 2;
cout << c - b << endl;

return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())
    C0 = 0
    C1 = 0
    C2 = 0
    C3 = 0
    for i in range(N):
        S = input()
        if S == 'AC':
            C0 += 1
        elif S == 'WA':
            C1 += 1
        elif S == 'TLE':
            C2 += 1
        elif S == 'RE':
            C3 += 1

    print(f'AC x {C0}')
    print(f'WA x {C1}')
    print(f'TLE x {C2}')
    print(f'RE x {C3}')


Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  set<ll>se;
  while(k--){
    ll a;cin>>a;
    while(a--){
      ll b;cin>>b;
      se.insert(b);
    }
  }
  cout<<n-se.size()<<endl;
  return 0;
}


Measured memory_bytes: 3708
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,M = (int(_) for _ in input().split())
    a = []
    b = []
    c = []
    d = []
    ans = []
    for i in range(N):
        t1, t2 = (int(_) for _ in input().split())  
        a.append(t1)
        b.append(t2)
    for i in range(M):
        t1, t2 = (int(_) for _ in input().split())  
        c.append(t1)
        d.append(t2)

    for i in range(N):
        min_dist = 1e10
        ans.append(0)
        for j in range(M):
            dist = abs(a[i]-c[j])+abs(b[i]-d[j])
            if min_dist > dist:
                ans[i] = str(j+1)
                min_dist = dist
    print('\n'.join(ans))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#include <math.h>
#include <bits/stdc++.h>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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



Measured memory_bytes: 3020
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 1e6 + 11;
const ll INF = 5e16;
const ll P = 1e9 + 7;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n, k, fac[N], inv[N];
	
	inline ll power ( ll a, ll b, ll res = 1 ) {
		for (; b; b >>= 1, a = a * a % P) 
			res = (b & 1)? res * a % P: res; return res;
	}
	
	inline void Init() {
		fac[0] = inv[0] = 1;
		For ( i, 1, 1e6 ) fac[i] = fac[i - 1] * i % P;
		inv[1000000] = power(fac[1000000], P - 2);
		Rep ( i, 1e6 - 1, 1 ) inv[i] = inv[i + 1] * (i + 1) % P;
	}
	
	inline ll C ( ll n, ll m ) {
		if (n < m || !m) return !m? 1: 0;
		return fac[n] * inv[n - m] % P * inv[m] % P;
	}
	
	int main() {
		Init();
		n = read(), k = read();
		For ( i, 1, k ) wln (C(k - 1, i - 1) * C(n - k + 1, i) % P);
		return 0;
	}

}

int main()
{
	return Cesare::main();
}

/*

*/






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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;

vector<ll> ans;
int N, M, Q;
vector<long long> a;
vector<long long> b;
vector<long long> c;
vector<long long> d;


//列Aの点を計算
ll score(vector<int> &A) {
	ll res = 0;
	for (int i = 0; i < Q; i++) {
		if (A[b[i] - 1] - A[a[i] - 1] == c[i]) res += d[i];
	}
	return res;
}

//列Aを全て生成し、各Aのスコアをvector<int> ansに格納
 void dfs(vector<int> &A, int add) {

	if (A.size() == N) {
		ans.push_back(score(A));
		return;
	}
	
	for (ll i = add; i <= M; i++) {
		A.push_back(i);
		dfs(A, i);
		A.pop_back();
	}
}


int main() {
	
	cin >> N >> M >> Q;
	a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
	for (int i = 0; i < Q; i++) {
		ll aa, bb, cc ,dd;
		cin >> aa >> bb >> cc >> dd;
		a[i] = aa;
		b[i] = bb;
		c[i] = cc;
		d[i] = dd;
	}

	vector<int> A;

	dfs(A, 1);
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());

	cout << ans[0] << endl;
}

Measured memory_bytes: 4228
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main() {
    int n; cin >> n;
    vi a(n); rep(i, n) cin >> a[i];
    sort(all(a));

    while(1) {
        bool br = true;
        for(int i = 1; i < a.size(); i++) {
            if (a[i] % a[0] != 0) {
                a[i] = a[i] % a[0];
                br = false;
                break;
            }
        }
        sort(all(a));
        if (br) break;
    }
    cout << a[0] << endl;
}

Measured memory_bytes: 640