akhauriyash/Code-Regression huggingface dataset:
#import <stdio.h>
int main() {
	long a,b;
	scanf("%ld %ld",&a,&b);
	long ans;
	if(a>=0&&b>0){
		ans = (b>=a)?b-a:a-b+2;
	}else if(a<0&&b>0){
		ans = (b>=-a)?1+b+a:-b-a+1;
	}else if(a<0&&b<0){
		ans = (b>=a)?b-a:-b+a+2;
	}else if(a>0&&b<0){
		ans = (-b>=a)?-b-a+1:b+a+1;
	}else if(a<0&&b==0){
		ans = -a;
	}else if(a==0&&b<0){
		ans = -b+1;
	}else if(a>0&&b==0){
		ans = a+1;
	}
	printf("%ld\n",ans);
}


Measured memory_bytes: 7120
n = gets.to_i
t,a = gets.split.map{|x| x.to_i}
h = gets.split.map{|x| x.to_i}

#print "n:#{n} t:#{t} a:#{a}\n"
#print h
#print "\n"

mindif = 99999.9
suf = -1
for i in 0...h.size
  temp = t - 0.006 * h[i]
  dif = (temp - a).abs
  #print "temp:#{temp} dif:#{dif} min:#{mindif}\n"
  if dif < mindif
    mindif =  dif
    suf = i
    #print "set to #{dif}@#{suf}\n"
  end
end
print (suf+1)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int berat[10],batas,kelarutan,occ[10]={};
pii best;
pii max(pii a,pii b){
	return (a.fi*b.se>b.fi*a.se)?a:b;
}
int totalgula(){
	return (occ[3]*berat[3]+occ[4]*berat[4]);
}
int totalberat(){
	int ret=0;
	for(int i=1;i<=4;i++)
		ret+=occ[i]*berat[i];
	return ret;
}
int totalair(){
	return (occ[1]*berat[1]+occ[2]*berat[2]);
}
bool possible(){
	return ((totalberat()<=batas)&&(totalair()*kelarutan>=100*totalgula()));
}
void dfs(int depth){
	if(depth==5)
	{
		best=max(best,mp(totalgula(),totalberat()));
		return;
	}
	while(possible())
	{
		dfs(depth+1);
		occ[depth]++;
	}
	occ[depth]=0;
}
int main()
{
	for(int i=1;i<=4;i++)
		scan(berat[i]);
	berat[1]*=100;
	berat[2]*=100;
	scan(kelarutan,batas);
	best=mp(0,berat[1]);
	dfs(1);
	printf("%d %d\n",best.se,best.fi);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0225
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] inEdge = new int[26];
                int[] outEdge = new int[26];
                UnionFind uf = new UnionFind(26);

                for (int i = 0; i < n; i++)
                {
                    string st = RSt();
                    int s = st[0] - 'a';
                    int e = st[st.Length - 1] - 'a';

                    outEdge[s]++;
                    inEdge[e]++;
                    uf.Unite(s, e);
                }

                bool isConcat = uf.parents.Where((x, i) => inEdge[i] != 0 || outEdge[i] != 0).Select(x => uf.Find(x)).Distinct().Count() == 1;
                bool isEuler = inEdge.Where((x, i) => x == outEdge[i]).Count() == inEdge.Count();
                Console.WriteLine(isConcat && isEuler ? "OK" : "NG");
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

    class UnionFind
    {
        public readonly int[] parents;
        private readonly int[] rank;

        public UnionFind(int n)
        {
            parents = new int[n];
            rank = new int[n];
            for (int i = 0; i < n; i++) parents[i] = i;
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);
            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool IsSameGroup(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }
}



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


#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef vector<int> vi;


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

	int N;
	cin >> N;
	vi s;
	int ans = 0;
	rep(i, N) {
		int tmp;
		cin >> tmp;
		s.push_back(tmp);
		ans += tmp;
	}

	if (ans % 10 != 0) {
		cout << ans << endl;
		return 0;
	}

	sort(all(s));

	bool flag = false;
	rep(i, N) {
		if (s[i] % 10 != 0) {
			ans -= s[i];
			flag = true;
			break;
		}
	}
	if (flag) {
		cout << ans << endl;
	}
	else {
		cout << "0" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
N , M = map(int,input().split())
L = []
transit1 = set()
transit2 = set()
for _ in range(M):
    t = tuple(map(int,input().split()))
    L.append(t)
for x in L :
    if x[1] == N:
        transit1.add(x[0])
    if x[0] == 1:
        transit2.add(x[1])
if transit1 & transit2 == set():
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Measured memory_bytes: 88408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<set<ll>> g(h);
  vl nh(h, 0), nw(w, 0);
  rep(i, m) {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    g[u].insert(v);
    nh[u]++;
    nw[v]++;
  }
  set<P, greater<P>> st;
  rep(j, w) st.insert({nw[j], j});
  P mx = *st.begin();
  ll ans = 0;
  rep(i, h) {
    ll now = mx.first;
    if(g[i].count(mx.second)) now--;
    for(auto v : st) {
      if(g[i].count(v.second)) continue;
      now = max(now, v.first);
      break;
    }
    now += nh[i];
    ans = max(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 54728
# -*- coding: utf-8 -*-

def main():

    A, B = map(int, input().split())

    if A >= 13:
        ans = B

    elif 6 <= A <= 12:
        ans = B / 2

    elif A <= 5:
        ans = 0

    print(int(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 8924
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  s <- getLine :: IO String
  let
    l = n `div` 2
    pr = take l s
  putStrLn $ if s == pr ++ pr then "Yes" else "No"

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  ll cnt=0;
  vll a(n);
  ll min=INF;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]<0){
      cnt++;
    }
    chmin(min,abs(a[i]));
    sum+=abs(a[i]);
  }
  if(cnt%2){
    cout<<sum-min*2<<endl;
  }
  else{
    cout<<sum<<endl;
  }
  
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
int a,b;
scanf("%d %d",&a,&b);
if(a > b)
{
printf("a > b\n",a,b);
}
else if(a < b)
{
printf("a < b\n",a,b);
}
else if(a == b)
{
printf("a == b\n",a,b);
}
return 0;
}

Measured memory_bytes: 580
#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+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> s(m,vector<int>(n));
    vector<int> ks(m);
    rep(i,m){
        int k;
        cin >> k;
        ks[i] =k;
        rep(j,k)cin >>s[i][j];
    }
    vector<int> p(m);
    rep(i,m) cin >> p[i];

    int rel = 0;

    rep(i,n+1){
        vector<int> a(n,4);
        rep(k,i)a[k] = 1;
        do{
            bool ans = true;
            rep(j,m){
                int chk=0;
                rep(l,ks[j]){
                    if(a[s[j][l]-1]==1)++chk;
                }
                if(chk%2!=p[j])ans=false;
            }
            if(ans)rel++;
        }while(next_permutation(a.begin(),a.end()));
    }
    cout << rel << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

// #define DEBUG 1
#define DFILE "t1.1"

typedef struct
{
  int k;
  int s[10];
} T1;

typedef struct
{
  int p;
  int on;
} T2;

int main()
{
#ifdef DEBUG
#define cin fin
  fstream fin(DFILE);
#endif
  int n, m;
  cin >> n >> m;
  T1* a;
  T2* b;
  int* s;
  a = new T1[m];
  b = new T2[m];
  s = new int[n + 1];
  for (int i = 0; i < m; i++) {
    cin >> a[i].k;
    for (int j = 0; j < a[i].k; j++) {
      cin >> a[i].s[j];
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i].p;
  }
  // cout << (2 << n) << endl;
  int bit = 0;
  int total = 0;
  for (bit = 0; bit < (1 << n); bit++) {
    // cout << bit << ":";
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        s[i + 1] = 1;
      } else {
        s[i + 1] = 0;
      }
      // cout << s[i + 1] << " ";
    }
    // cout << endl;
    int i;
    for (i = 0; i < m; i++) {
      int sum = 0;
      for (int k = 0; k < a[i].k; k++) {
        if (s[a[i].s[k]]) {
          sum++;
        }
      }
      // cout << sum << endl;
      if (sum % 2 != b[i].p) {
        break;
      }
    }
    if (i == m) {
      total++;
    }
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
#define int ll

int g[105][105], d[105], n;

void bfs() {
  queue<int> q;
  q.push(0);
  fill(d, d + n, -1);
  d[0] = 0; 

  while(!q.empty()) {
    int que = q.front();
    q.pop();
    for (int i = 0; i < n; i++) {
      if (g[que][i] && d[i] == -1) {
        d[i] = d[que] + 1;
        q.push(i);
      }
    }
  }
}

signed main(void) {
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      g[u-1][v-1] = 1;
    }
  }

  bfs();
  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pri 1000000007

using namespace std;
void run(){
	ll r,g,b,n;
	cin>>r>>g>>b>>n;
	ll ans=0;
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=n;j++){
			if((n-r*i-g*j)%b==0&&n-r*i-g*j>=0)ans++;
			
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,k;
    cin>>n>>k;

    vi v(n+1);
    for(int i=1;i<=n;++i)
        cin>>v[i];

    queue<int> q;
    vi dist(n+1,inf),node(n+5,0);

    dist[1]=0;
    node[0]=1;
    q.push(1);

    int x,y;
    int pos,len;
    while(!q.empty())
    {
        x=q.front();
        q.pop();

        y=v[x];
        if(dist[y]==inf)
        {
            dist[y]=dist[x]+1;
            node[dist[y]]=y;
            q.push(y);
        }
        else
        {
            pos=dist[y];
            len=dist[x]-dist[y]+1;
            break;
        }
    }

    //cout<<pos<<" "<<len<<"\n";

    if(k<pos)
        cout<<node[k];
    else
    {
        k-=pos;
        k%=len;

        cout<<node[pos+k];
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 7952
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    for (int i = 0; i < N; ++i)
        cin >> B[i];
    vector<ll> d(N);
    for (int i = 0; i < N; ++i)
        d[i] = B[i] - A[i];
    ll op_total = accumulate(d.begin(), d.end(), 0LL);
    ll tmp1 = 0, tmp2 = 0;
    for (int i = 0; i < N; ++i){
        if (d[i] < 0) tmp1 -= d[i];
        else tmp2 += (d[i] + 1) / 2;
    }
    string res = (tmp1 <= op_total && tmp2 <= op_total) ? "Yes" : "No";
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
  
int main(){
	
	int m,n;  
	while(cin>>n>>m)
	{ 
		priority_queue<int>q;
		int t;
		for(int i=0;i<n;i++)
		{
			
			cin>>t;
			q.push(t);    
		}
		long long sum=0;
		
		while(m)
		{
			t=q.top()/2;
			q.pop();
			q.push(t);
			m--;
		}
		while(!q.empty())
		{
			sum+=q.top();
			q.pop();
		}
		cout<<sum<<endl; 
	}  
	return 0;
}


Measured memory_bytes: 892
from bisect import bisect_right

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

SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i + 1] = SA[i] + A[i]
for i in range(M):
    SB[i + 1] = SB[i] + B[i]

ans = 0
for i in range(N + 1):
    cntA = i
    rest = K - SA[i]
    if rest < 0:
        break
    cntB = bisect_right(SB, rest) - 1
    ans = max(ans, cntA + cntB)
print(ans)


Measured memory_bytes: 110920
n = int(input())
N = list(map(int, input().split()))
q = input()
Q = list(map(int, input().split()))

from itertools import combinations, permutations
L = []
for i in range(1,n+1):
    L += list(combinations(N,i))
ans = []
for l in L:
    ans.append(sum(l))
for q in Q:
    if q in ans:
        print('yes')
    else:
        print('no')


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

struct UnionFind{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int size) : par(size), sizes(size,1){
        for(int i=0;i<size;i++) par[i] = i;
    }

    bool unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x == y) return false;
        if(sizes[x] < sizes[y]) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return true;
    }

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

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

    int getSize(int x){
        return sizes[find(x)];
    }
};

struct edge{
    int from,to;
    int weight;

    bool operator <(const edge& e) const {
        return weight < e.weight;
    }
};

vector<edge> kruskal(int VertexNum, vector<edge>& Edges){
    UnionFind forest(VertexNum);
    vector<edge> edges;
    
    sort(Edges.begin(),Edges.end());
    for(edge Edge : Edges){
        if(!forest.isSame(Edge.from,Edge.to)){
            forest.unite(Edge.from,Edge.to);
            edges.push_back(Edge);
        }
    }

    return edges;
}

signed main(){
    int V,E;
    cin >> V >> E;
    
    vector<edge> Edges(E);

    for(int i=0;i<E;i++){
        edge Edge;
        cin >> Edge.from >> Edge.to >> Edge.weight;
        Edges[i] = Edge;
    }

    vector<edge> minimumSpanningTree = kruskal(V, Edges);
    long long minimumWeight = 0;
    for(edge e : minimumSpanningTree){
        minimumWeight += e.weight;
    }

    cout << minimumWeight << endl;
}


Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
#define DB double
const int N=400010;
const int M=800010;
const int maxn=30;
using namespace std;

int n;
char c[2][2];
int p[2],g[2];

struct nn{
	int x,y;
}a[N];

void READ(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d%d",&a[i].x,&a[i].y);
		g[abs(a[i].x+a[i].y)%2]++;
	}
}

void PRT(int x){
	if(!x){
		printf("0\n");
		return;
	}
	int pos=0,flp[10];
	while(x)flp[++pos]=x%2,x/=2;
	tep(i,pos,1)printf("%d",flp[i]);
	printf("\n");
}

void PRT(int x,int y){
	c[0][0]='R';c[0][1]='L';
	c[1][0]='U';c[1][1]='D';
	if(x<0)x=-x,swap(c[0][0],c[0][1]);
	if(y<0)y=-y,swap(c[1][0],c[1][1]);
	int flg=0;
	p[0]=0,p[1]=0;
	tep(i,maxn,0){
		if(x<y)swap(x,y),flg^=1;
		printf("%c",c[flg][p[flg]]);
		if(!((x>>i)&1))p[flg]^=1,x=(1<<i)-x;
		else x^=(1<<i);
	}
	if(g[0])printf("R");
	printf("\n");
}

int SOLVE(){
	if(g[1]*g[0]!=0)return 0;
	printf("%d\n",maxn+1+(g[0]!=0));
	tep(i,maxn,0)printf("%d ",(1<<i));
	if(g[0]!=0){
		rep(i,1,n)a[i].x--;
		printf("1");
	}
	printf("\n");
	//---
	rep(i,1,n)PRT(a[i].x,a[i].y);
	return 1;
}

int main(){
	READ();
	if(!SOLVE())printf("-1\n");
	return 0;
}

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

int main()
{
  int x, y;
  cin >> x >> y;
  if (y >= 2 * x && y <= 4 * x && y % 2 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC149C - Next Prime

        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        boolean isSosu = false;
        while(!isSosu) {
            isSosu = true;
            for (int i = 2; i < x; i++) {
                if (x % i == 0) {
                    isSosu = false;
                    x++;
                    break;
                }
            }
        }

        System.out.println(x);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cstdlib>
#include<cassert>

#define REP(i, b, n) for(int i =b; i<(int) n; i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, o) for(__typeof((o).begin()) it = (o).begin(); it != (o).end(); ++it)

using namespace std;

enum{
  H = 501, N = 101, KK = 101
};

int h, n, p, m, K;
double dp[H][N][KK];
bool usedHeight[H], canMove[H][N];
int atl[H];
double solve(int cnt){
  rep(i, H)rep(j, N)rep(k, KK)dp[i][j][k] = 0;
  dp[h][p-1][0] = 1;
  for(int i = h; i>0; i--){
    rep(j, n){
      rep(k, K+1){
        //cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k]<< endl;;
        if(canMove[i][j-1]){
          dp[i-1][j-1][k] += dp[i][j][k];
        }
        else if(canMove[i][j]){
          dp[i-1][j+1][k] += dp[i][j][k];
        }
        else if(!usedHeight[i] && k < K){
          int tmp=n-1;
          if(j > 0){//left
            dp[i-1][j-1][k+1] += dp[i][j][k]; 
            tmp--;
          }
          if(j < n-1){//right
            dp[i-1][j+1][k+1] += dp[i][j][k];
            tmp--;
          }
          
          //mid
          //dp[i-1][j][k] += dp[i][j][k] * remain;
          //if (k+i-1 >= K){

          if (k+atl[i] > K){
            dp[i-1][j][k+1]+=dp[i][j][k]*tmp;
            dp[i-1][j][k]  +=dp[i][j][k];// * remain;
          }else {
            dp[i-1][j][k+1]+=dp[i][j][k]*tmp;
          }
        }
        else {
          dp[i-1][j][k] += dp[i][j][k];
        }
      }
    }       
  }
  double ret = 0,sum=0;
  rep(i, n){
    ret = max(ret, dp[0][i][K]);
    sum+=dp[0][i][K];
  }
  //cout << endl;
  //cout <<"proba sum " <<  sum << endl;
  return ret/sum;
}

int main(){
  while(cin >> h >> n >> p >> m >> K){
    rep(i, H+1){
      usedHeight[i] = false;
      rep(j, N){
        canMove[i][j] = false;
      }
    }
    rep(i, m){
      int a, b;
      cin >> a >> b;
      canMove[a][b-1] = true;
      usedHeight[a] = true;
    }
    rep(i,H+1)atl[i]=0;
    REP(i,1,H+1){
      atl[i]+=atl[i-1];
      if (!usedHeight[i])atl[i]++;
    }

    int cnt = (h - m ) * (n-1);
    printf("%.7f\n", solve(cnt));
  }

}

Measured memory_bytes: 39000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
    
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll n; cin>>n;
    ll a[n],count[100001]={0},sum=0;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        sum+=a[i];
        count[a[i]]++;
    }
    ll q; cin>>q;
    for(ll i=1;i<=q;i++){
        ll b,c;
        cin>>b>>c;
        sum+=(c-b)*count[b];
        count[c]+=count[b];
        count[b]=0;
        cout<<sum<<'\n';
    }
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}

Measured memory_bytes: 5208
#include<stdio.h>
main(){
  int H,N,i,S,A;
  S=0;
  scanf("%d %d",&H,&N);
  for(i=0;i<N;i++){
    scanf("%d",&A);
    S+=A;
    }
  if(H>S)printf("No");
  else printf("Yes");
  return 0;
}

Measured memory_bytes: 128
//g++ -std=c++14 test.cpp -o test.out
//URL
//https://atcoder.jp/contests/abc142/tasks/abc142_e
//BFSは重みなしグラフの、スタート地点Sから各頂点の最短距離を求められる
//重みがあったらダイクストラを使う必要が出てくる
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647;
const LL mod = 1000000007ll;
 
int N,M;
vector<vector<int>> to;//iから行くことのできる点の集合をto[i]とする
int S,T;
 
int ans = 0;
 
void solve(){
	vector<vector<int>> distance(N,vector<int>(3,INF_INT));
	//Sから頂点uへの距離をdとしたとき、uへd%3でいけるような経路が存在するなら
	//distance[u][d%3] = dとする
	//いけないならdistance[u][d%3] = INF
	queue<pair<int,int>> q;//pair<頂点番号,長さのmod>
	q.push(make_pair(S,0));
	distance[S][0] = 0;//Sはスタート地点の頂点　スタート地点からSまでの距離は当然0で、0%3=0なのでこうなる
	//BFS
	while(!q.empty()){
		int v = q.front().first;//頂点番号
		int l = q.front().second;//長さのmod
		q.pop();
		for(int u : to[v]){
			int next_l = (l+1)%3;
			if(distance[u][next_l]!=INF_INT) continue;//Sからuへいく経路で、その長さ%3がiであるような経路をもう見つけたならば
			distance[u][next_l] = distance[v][l]+1;
			q.push(make_pair(u,next_l));
		}
	}
	ans = distance[T][0];
	if(ans==INF_INT) ans=-1;
	else ans/=3;
}
 
int main(){
	cin >> N >> M;
	to = vector<vector<int>>(N);
	for(int i=0;i<M;i++){
		int u,v;
		cin >> u >> v;
		to[u-1].push_back(v-1);
	}
	cin >> S >> T;
	S--;T--;
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;

    int cnt = 0;

    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= d) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3676
n=int(input())
a=[list(map(int,input().split())) for _ in range(2)]
ans=0
#print(a)
for i in range(n):
    tmp=0
    cnt=0
    for j in range(n):
        tmp+=a[cnt][j]
        if i==j:
            cnt+=1
            tmp+=a[cnt][j]
    ans=max(tmp,ans)
print(ans)

Measured memory_bytes: 3064
k, a, b =  map(int, input().split())
if a >= b or k < a:
    print(1 + k)
else:
    s = k - a + 1
    t = s // 2
    if s % 2 == 0:
        if (a + (b - a) * t) > 1 + k:
            print(a + (b - a) * t)
        else:
            print(1 + k)
    else:
        if (a +(b - a) * t + 1) > 1 + k:
            print(a +(b - a) * t + 1)
        else:
            print(1 + k)

Measured memory_bytes: 3060
#include<stdio.h>
int binarySearch(int*,int,int);

int main(){
  int n,S[1000000];
  int q,T[1000000];
  int i,j,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
    if(binarySearch(S,n,T[j])!=0){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}


int binarySearch(int *s,int n,int key){
  int left,middle,right;
  left=0;
  right=n;
 
  while(left<right){
    middle=(right+left)/2;
    if(s[middle]==key){
      return 1;
    }else if(s[middle]>key){
      right=middle;
    }else{
      left=middle+1;
    }
  }
  return 0;
}






Measured memory_bytes: 2452
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tate = in.nextInt();
        int yoko = in.nextInt();
       
        int menseki  = tate * yoko;
        int syu = tate *2 + yoko *2;
        System.out.println(menseki + " " + syu);
    }
}

Measured memory_bytes: 26016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int INF = 1e9+10;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    if(a[0] + 1 < a[n-1])
    {
        cout << "No" << endl;
        return 0;
    }
    if(a[0] == a[n-1])
    {
        if(a[0] == n-1 || a[0] * 2 <= n)
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    int num = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[i] == a[0]) num++;
    }
    if(num > a[0])
    {
        cout << "No" << endl;
        return 0;
    }
    int d = a[0] - num;
    if(2 * (d + 1) <= n - num) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3748
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,k,d[11]={};
	string s;
	cin>>n>>k;
	FOR(i,0,k){
		int t;
		cin>>t;
		d[t]=1;
	}
	FOR(ans,n,10*n+1){
		int t=ans,f=1;
		while(t>0){
			if(d[t%10])f=0;
			t/=10;
		}
		if(f){
			cout<<ans;
			break;
		}
	}
    return 0;
}


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

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


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B = MAP()

    for i in range(1000):
        if int((i+1)*0.08) == A and int((i+1)*0.1) == B:
            print(i+1)
            sys.exit()

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
"use strict"
function main(arg) {
    let base = [1,2,3,4,5]
    let list = arg.trim().split("\n")[0].split(" ").map(Number)
    for (let i = 0; i < list.length; i++) {
        if (base[i] !== list[i]) {
            console.log(i + 1)
            break
        }
    }
    // console.log()
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
    int N, A[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

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

    sort(A, A+N);
    if(negative % 2 == 1) A[0] *= -1;

    int64_t ans = 0;
    for(int i=0; i<N; i++) ans += A[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
  int n, m, total = 0, num;
  scanf("%d%d", &n, &m);
  for(int i = 0; i < m; i++){
    scanf("%d", &num);
    total += num;
  }
  if(total > n){puts("-1");}
  else{
    printf("%d", n - total);
  }
}

Measured memory_bytes: 1728
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n; cin >> n;
  vector<pair<int, int>> b(n);

  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    b[i] = make_pair(a, i);
  }
  sort(b.begin(), b.end());

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    // i: ソート後の順番, b[i].second: もとの数列の順番
    if ( (i & 1) != (b[i].second & 1) ) {
      cnt++;
    }
  }
  cout << cnt/2 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int w;
  cin >> w;
  int n = s.size();
  for (int i = 0; i < n; i += w) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<stdio.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i =1; i<=n;i++){
        if (i % 3 == 0 or i % 10 == 3 ){
            cout << " " << i;
            continue;
        }
        int x = i;
        while (x){
            if (x%10 == 3){
                cout << " " << i;
                break;
            }
            x = x/10;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int MAXN = 1e5 + 5, MAXM = 2e6 + 5, BOUND = 2e5, MOD = 10000, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-6;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define lc(x) c[x][0]
#define rc(x) c[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
char gdffsaw;
#define G gdffsaw=getchar()
#define GO G;while(gdffsaw<'-')G
#define in(z) GO;z=gdffsaw&15;G;while(gdffsaw>'-')z*=10,z+=gdffsaw&15,G
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
ll n, m;
struct node {
	ll x, y;
	bool operator <(const node &n)const {
		return x < n.x;
	}
}a[MAXN];
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> a[i].x >> a[i].y;
	}
	sort(a + 1, a + 1 + n);
	ll ans = 0;
	rep(i, 1, n) {
		ans += min(m, a[i].y) * a[i].x;
		m -= min(m, a[i].y);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll solve(string s) {
    vector<ll> val(2019, 0);
    ll tenfactor = 1;
    ll r = 0;
    val[r]++ ;
    ll n = s.size();
    for (int i = 0; i < n; i++) {
        r = (r + (s[n-i-1] - '0') * tenfactor) % 2019;
        tenfactor = tenfactor * 10 % 2019;
        val[r]++;
    } 
    ll ans = 0;
    for (int i = 0; i < 2019; i++) {
        ans += val[i] * (val[i] - 1) / 2;
    }
    return ans;
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
}

Measured memory_bytes: 3796
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, min = 0, a;
  scanf("%lld%lld", &n, &k);
  for(i = 1; i <= n; ++i) {
    scanf("%lld", &a);
    if(a == 1) {
      min = i;
      break;
    }
  }
  ll ans = 0;
  ans += (min + k - 3) / (k - 1);
  min = ans * (k - 1) + 1;
  min = n - min + 1;
  ans += (min + k - 3) / (k - 1);
  if(n != k) printf("%lld", ans);
  else printf("1");
  return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define l first
#define r second
#define int long long

int n, m;
int a[500000];
long long ss[500000];
long long kek[500000];
vector<pair<int, int> > sigma;

signed main()
{
    cin >> n >> m;
    if (n % 2 == 1)
    {
        for (int i = 1; i <= n; i++) cin >> a[i], a[i] *= 2;
        n++;
    }
    else
    {
        for (int i = 0; i < n; i++) cin >> a[i], a[i] *= 2;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        ss[i] = ss[i + 1];
        ss[i] += a[i];
    }
    for (int i = 0; i < n; i++)
    {
        kek[i] = kek[i - 2] + a[i];
    }
    sigma.push_back({2000000000, 2});
    int p1 = n - 3, p2 = n - 2, id = 4;
    while (p1 > 0)
    {
        sigma.push_back({a[p1] / 2 + a[p2] / 2, id});
        p1 -= 2, p2 -= 1, id += 2;
    }
    reverse(sigma.begin(), sigma.end());
    for (int i = 0; i < sigma.size(); i++)
    {
        ;//cout << sigma[i].first << " " << sigma[i].second << endl;
    }
    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k, k *= 2;
        int l = -1, r = sigma.size() - 1;
        while (l + 1 < r)
        {
            int mid = (l + r) / 2;
            if (k <= sigma[mid].first) r = mid;
            else l = mid;
        }
        cout << kek[n - sigma[r].second - 1] / 2 + ss[n - sigma[r].second / 2] / 2 << "\n";
    }
}


Measured memory_bytes: 11636
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll n,k;
  cin>>n>>k;
  set<ll>fol;
  for (ll i = 0; i < k; ++i)
  {
    ll yo;cin>>yo;
    for (ll j = 0; j < yo; ++j)
    {
      ll ko;cin>>ko;fol.insert(ko);
    }
  }
  cout<<n-fol.size();
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int n;
int main()
{
	cin>>n;
	if (n==22) cout<<"Christmas Eve Eve Eve";
	else if (n==23) cout<<"Christmas Eve Eve";
	else if (n==24) cout<<"Christmas Eve";
	else if (n==25) cout<<"Christmas";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
shougen=[[-1]*(n+1) for _ in range(n+2)]
for i in range(1,n+1):
  a = int(input())
  for j in range(a):
    x,y = map(int, input().split())
    # 人iのxに対する証言はy
    shougen[i][x]=y

ans=0
# bit全探索
for i in range(2**n):
  f=True
  for j in range(n):
    if i>>j & 1:
      for k,s in enumerate(shougen[j+1][1:],start=0):
        if s == 1 and not i>>k & 1:
          f=False
        if s == 0 and i>>k & 1:
          f=False
  else:
    if f:
      ans=max(ans, str(bin(i)).count("1"))

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int i, j, t, n, x, s;
	while (scanf("%d %d", &n, &x) != EOF && n + x)
	{
		s = 0;
		for (i = 1;i < n;i++)
			for (j = i + 1;j <= n;j++)
				for (t = j + 1;t <= n;t++)
					if (i + j + t == x)
						s++;
		printf("%d\n", s);
	}
	return 0;
}


Measured memory_bytes: 2032
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S[3];
  REP(i,3)cin>>S[i];
  REP(i,3)cout<<S[i][i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int solve(const std::vector<int>& weights)
{
  int s1 = 0;
  int s2 = std::accumulate(weights.begin(), weights.end(), 0);
  int result = s2;
  for (const auto& w : weights) {
    s1 += w;
    s2 -= w;
    result = std::min(result, std::abs(s1 - s2));
  }
  return result;
}

int main()
{
  int n;
  std::cin >> n;

  std::vector<int> weights(n);
  for (auto& w : weights) {
    std::cin >> w;
  }

  std::cout << solve(weights) << std::endl;
}


Measured memory_bytes: 256
'''input
3 3
.#.
#..
.#.
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import deque


def mp(arr):
	arr = map(str, arr)
	return ' '.join(arr)


def bfs(source):
	myq = deque()
	myq.append(source)
	visited = dict()
	visited[mp(source)] = True
	dist = -1
	while len(myq) > 0:
		temp = deque()
		dist += 1
		while len(myq) > 0:
			x, y  = myq.popleft()
			if x - 1 >= 0 and maze[x - 1][y] != '#' and mp([x - 1, y]) not in visited:
					visited[mp([x -1, y])] = True
					temp.append([x - 1, y])
			if x + 1 < n and maze[x + 1][y] != '#' and mp([x + 1, y]) not in visited:
					visited[mp([x + 1, y])] = True
					temp.append([x + 1, y])
			if y - 1 >= 0 and maze[x][y - 1] != '#' and mp([x, y - 1]) not in visited:
					visited[mp([x, y - 1])] = True
					temp.append([x, y - 1])
			if y + 1 < m and maze[x][y + 1] != '#' and mp([x, y + 1]) not in visited:
					visited[mp([x, y + 1])] = True
					temp.append([x, y + 1])
		myq = temp
	return dist		


# main starts
n, m = list(map(int, input().split()))
maze = []
for _ in range(n):
	state = list(input().strip())
	maze.append(state)

# from random import randint
# for _ in range(1000):
# maze = []
# n = randint(1, 20)
# m = randint(1, 20)
# for i in range(n):
# 	temp = []
# 	for j in range(m):
# 		k = randint(1, 2)
# 		if k == 1:
# 			temp.append('.')
# 		else:
# 			temp.append('#')
# 	maze.append(temp)

ans = 0
for i in range(n):
	for j in range(m):
		if maze[i][j] != '#':
			first = [i, j]
			ans = max(ans, bfs(first))
print(ans)

Measured memory_bytes: 90712
function main(input) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10),
          cards = args[1].split(' ').map(n => parseInt(n, 10));

    var aSum = 0,
        bSum = 0;

    cards.sort((a, b) => (a < b ? 1 : -1)).forEach((n, i) => {
        (i % 2 === 0)? aSum += n : bSum += n;
    });

    console.log(aSum - bSum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	string s;
    cin>>s;
    int count=1;
    int maximum=0;
     for(int i=0;i<s.size();i++){
        if(s[i]=='R'){
          if(s[i+1]=='R'){
            count++;
          }
          else{
            maximum=max(maximum,count);
            count=1;
       }
     }
}
    cout<<maximum;
	return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define MIN(x) *min_element(all(x))
#define MAX(x) *max_element(all(x))
#define in(x) cin >> x
#define co(x) cout << x
#define el  cout << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main() {
    LL n, x, ans;
    cin >> n >> x;
    if(n * 500 >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 764
import sys
import itertools
from collections import Counter
N = int(input())
name = []
for _ in range(N):
    a = input()
    name.append(a[0])
name = Counter(name)
kouho = []
kouho.append(name["M"])
kouho.append(name["A"])
kouho.append(name["R"])
kouho.append(name["C"])
kouho.append(name["H"])
name = []
for i in kouho:
    if i == 0:
        continue
    name.append(i)
total = sum(name)
seki = 1
for i in name:
    seki = seki*i
hikuseki = 1
for i in name:
    if i > 1:
        hikuseki = hikuseki*i

if len(name) < 3:
    print(0)
    sys.exit()

seki = list(itertools.combinations(name, 3))
ans = 0
for i in seki:
    a, b, c = i
    ans += a*b*c
print(ans)


Measured memory_bytes: 10064
n,k = gets.split.map(&:to_i)
s = readlines.map{|line| line.split.map(&:to_i)}
MOD = 998244353
dp = Array.new(n,0)
wa = Array.new(n+1)
dp[0] = 1
wa[0] = 0
wa[1] = 1
for i in 1..(n-1)
  for j in 0..(k-1)
    if i-s[j][0] >= 0 && i-s[j][1] < 0
      dp[i] += wa[i-s[j][0]+1]%MOD
    elsif i-s[j][0] >= 0 && i-s[j][1] >= 0
      dp[i] += (wa[i-s[j][0]+1]-wa[i-s[j][1]])%MOD
    end
  end
  wa[i+1] = (wa[i]+dp[i])%MOD
end
puts dp[n-1]%MOD

Measured memory_bytes: 17500
#include <iostream>
#include <list>

using namespace std;

int main() {
    long long n;
    cin >> n;

    if (n == 0) {
        cout << "0" << endl;
    } else {
        list<int> res;
        for (long long i = 2; n != 0; i *= -2) {
            if (n % i == 0) {
                res.push_front(0);
            } else {
                res.push_front(1);
                n -= i / 2;
            }
        }

        for (list<int>::iterator i = res.begin(); i != res.end(); i++) {
            cout << *i;
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                ans = ans + 1
          
print(ans)

Measured memory_bytes: 3060