akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
i = 1
st = a[0]
ans = 0
(n - 1).times do 
    if st > a[i]
        sa = st - a[i]
        ans += sa
    else
        st = a[i]
    end
    i += 1
end
puts ans

Measured memory_bytes: 30088
n=int(input())
alpha=[chr(i) for i in range(97, 97+26)]
def calc(x):
  if x//26>0:
    return calc(x//26-1) + str(x%26).zfill(2)
  return str(x%26).zfill(2)
wk=calc(n-1)
ans=""
for i in range(0,len(wk),2):
  ans+=alpha[int(wk[i:i+2])]
print(ans)

Measured memory_bytes: 9224
s=input()
n=len(s)
l=s[:(n-1)//2]
r=s[(n+3)//2-1:]

flag=True

for i in range((n-1)//2+1):
    if s[i]==s[n-i-1]:
        flag=True
    else:
        flag=False
        break
if flag:
    for j in range((len(l)-1)//2+1):
        if l[j]==l[len(l)-j-1] and r[j]==r[len(l)-j-1]:
            flag=True
        else:
            flag=False
            break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define rep(i,a,b) for(int i =  (a);i<(b);i++)
int main(){
  int N, a, max1=0,max2=0, index1=0,index2=0;
  cin >> N;
  rep(i,0,N){
    cin >> a;
    if(a > max1 && a > max2){
      max2 = max1; max1 = a;
      index2 = index1; index1 = i;
    }else if(a <= max1 && a > max2){
      max2 = a;
      index2 = i;
    }
  }
  rep(i,0,N){
    if(i == index1) cout << max2 << endl;
    else cout << max1 << endl;
  }
}


Measured memory_bytes: 1664
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, input().split()))

X,Y,Z,K = ints_raw()

A = ints_raw()
B= ints_raw()
C= ints_raw()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def main():
    D = [a+b for a in A for b in B]
    D.sort(reverse=True)
    D = D[:K+1]
    E =[d+c for d in D for c in C]
    E.sort(reverse=True)
    for e in range(K):
        print (E[e])

main()


Measured memory_bytes: 161492
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);

        double N = scanner.nextInt();
        double X = scanner.nextInt();
        int T = scanner.nextInt();

        System.out.println((int) Math.ceil(N/X) * T);
    }
}


Measured memory_bytes: 27076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextWord() string {
	sc.Scan()
	str := sc.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func main(){
	sc.Split(bufio.ScanWords)
	a, b, c := nextInt(), nextInt(), nextInt()
	ans := c - a + b
  if ans < 0 {
    ans = 0
  }
  fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
int main(){ //srand((unsigned)time(NULL));
  ll r,c;
  cin >> r >> c;
  vector<vector<ll>> n(r,vector<ll>(c));
  for (int i = 0; i < r; i++) {
    ll ans = 0;
    for (int l = 0; l < c; l++) {
      cin >> n[i][l];
      ans += n[i][l];
      cout << n[i][l] << " ";
    }
    cout << ans << endl;
  }
  ll anss = 0;
  for (int i = 0; i < c; i++) {
    ll ans = 0;
    for (int l = 0; l < r; l++) {
      ans += n[l][i];
    }
    anss += ans;
    cout << ans << " ";
  }cout << anss << endl;
}



Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	
	int x = x2 - x1;
	int y = y2 - y1;
	cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;  
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+100;
int dp[maxn];
int path[maxn];
char s[maxn];
struct node{
	int id;
	int val;
	bool operator < (const node&z)const {
		if(val!=z.val)return val<z.val;
		return id<z.id;
	}
};
set<node>st;
stack<int>ans;
void solve()
{
	int n,m;scdd(n,m);
	scanf("%s",s);
	mst(dp,inf);
	dp[0]=0;
	st.insert(node{0,0});
	rep1(i,n){
		if(i-m-1>=0&&s[i-m-1]=='0'){
			auto it=st.lower_bound(node{i-m-1,dp[i-m-1]});
			st.erase(it);
		}
		if(s[i]=='1')continue;
		auto it=st.begin();
		if(it==st.end()){
			printf("-1\n");
			return ;
		}
		dp[i]=it->val+1;
		path[i]=it->id;
		st.insert(node{i,dp[i]});
	}
	int now=n;
	while(now){
		ans.push(now-path[now]);
		now=path[now];
	}
	int mark=ans.size();
	while(!ans.empty()){
		if(ans.size()!=mark)printf(" ");
		int u=ans.top();
		ans.pop();
		printf("%d",u);
	}printf("\n");
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 4224
def two(x,y):
	return (y-len(bin(x)[2:]))*"0"+bin(x)[2:]
h,w,K=map(int,input().split())
c=[input()for _ in range(h)]
ans=0
for i in range(2**h):
	for j in range(2**w):
		H=two(i,h);W=two(j,w)
		cnt=0
		for k in range(h):
			for l in range(w):
				if c[k][l]=="#" and H[k]=="0" and W[l]=="0":
					cnt+=1
		if cnt==K:
			ans+=1
print(ans)

Measured memory_bytes: 9212
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
string s;
cin>>s;
cout<<s.substr(0,5)<<" "<<s.substr(6,7)<< " " <<s.substr(14,5)<<endl;
    }



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  sort(rng(A));
  reverse(rng(A));
  int ans = 0;
  rep(i,N) {
    if(i%2==0) {
      ans += A[i];
    } else {
      ans -= A[i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const double PI = 3.14159265358979;

struct Node {
	int parent = -1;
	int left = -1, right = -1;
	int depth = 0, height = 0;

};

void setDepth(Node *tree, int id, int deep) {

	tree[id].depth = deep;

	if (tree[id].right != -1)
		setDepth(tree, tree[id].right, deep + 1);
	if (tree[id].left != -1)
		setDepth(tree, tree[id].left, deep + 1);
}

int setHeight(Node *tree, int id) {

	int lh = 0, rh = 0;
	if (tree[id].left != -1)
		lh = setHeight(tree, tree[id].left) + 1;
	if (tree[id].right != -1)
		rh = setHeight(tree, tree[id].right) + 1;
	tree[id].height = max(lh, rh);
	return tree[id].height;
}

int main() {

	int n; cin >> n;

	Node* tree = new Node[n];

	int root = -1;
	for (int i = 0; i < n; i++) {
		int id, left, right; 
		scanf("%d%d%d", &id, &left, &right);
		tree[id].left = left;
		tree[id].right = right;
		tree[left].parent = id;
		tree[right].parent = id;
	}
	for (int i = 0; i < n; i++) {
		if (tree[i].parent == -1) {
			root = i;
			break;
		}
	}

	setDepth(tree, root, 0);
	setHeight(tree, root);

	for (int i = 0; i < n; i++)	{
		char type[20];	// 0 root   1 internal node   2 leaf
		if (tree[i].parent == -1) {
			strcpy(type, "root");
		}
		else if (tree[i].left == -1 && tree[i].right == -1) {
			strcpy(type, "leaf");
		}
		else {
			strcpy(type, "internal node");
		}
		Node node = tree[i];

		int sib = -1;
		if (node.parent != -1) {
			Node par = tree[node.parent];
			if (par.left == i) {
				sib = par.right;
			}
			else {
				sib = par.left;
			}
		}

		int degree = 0;
		if (node.left != -1) degree++;
		if (node.right != -1) degree++;

		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
			i, node.parent, sib, degree, node.depth, node.height, type);
		
	}

	return 0;
}



Measured memory_bytes: 3200
import sys
N = int(input())
a = list(map(int,input().split(" ")))

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

for l in range(N-1,-1,-1):
    for r in range(l,N):
        turn = ((N - r) + l + 1) % 2

        if turn == 0:
            if r > 0 and l < N-1:
                dp[l][r] = max(a[l] + dp[l+1][r],a[r]+dp[l][r-1])
            elif l < N-1:
                dp[l][r] =  a[l] + dp[l+1][r]
            else:
                dp[l][r] =  a[r] + dp[l][r-1]
        else:
            if r > 0 and l < N-1:
                dp[l][r] = min(-a[l] + dp[l+1][r],-a[r]+dp[l][r-1])
            elif l < N-1:
                dp[l][r] = -a[l] + dp[l+1][r]
            else:
                dp[l][r] = -a[r] + dp[l][r-1]
print(dp[0][N-1])

Measured memory_bytes: 112604
#include<stdio.h>
int main(){
	int e,y;
	scanf("%d %d",&e,&y);
	if(e==0){
		if(y<=1911){
			printf("M%d\n",y-1867);
			}else{if(y<=1925){
				printf("T%d\n",y-1911);
				}else{if(y<=1988){
					printf("S%d\n",y-1925);
						}else{if(y<=2016){printf("H%d\n",y-1988);
						}
					}
				}
			}
		}
	if(e==1){printf("%d\n",y+1867);}
	if(e==2){printf("%d\n",y+1911);}
	if(e==3){printf("%d\n",y+1925);}
	if(e==4){printf("%d\n",y+1988);}
}


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

const int MAXB = 1000000000;

int main(void) {
    int H, N;
    cin >> H >> N;
    vector< int > A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    int dp[N + 1][H + 1];
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 0;
    }
    for (int i = 1; i <= H; i++) {
        dp[0][i] = MAXB;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= H; j++) {
            dp[i][j] =
                min(dp[i - 1][j], dp[i][max(0, j - A[i - 1])] + B[i - 1]);
        }
    }
    printf("%d\n", dp[N][H]);
    return 0;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    map<char, Int> mp;
    Int cnt = 0;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (isalpha(s[i])) cnt++;
    }
    for (Int i = 0; i < (Int)cnt; i++) {
        char a;
        Int x;
        cin >> a >> x;
        mp[a] = x;
    }
    stack<char> st;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (s[i] == '-') continue;
        if (s[i] == '[' or isalpha(s[i])) {
            st.push(s[i]);
        }
        if (s[i] == ']') {
            char a = st.top();
            st.pop();
            char b = st.top();
            st.pop();
            st.pop();
            if (mp[a] == 0 and mp[b] == 0) {
                print("No");
                return 0;
            } else if (mp[a] == 0) {
                mp[b]--;
                st.push(b);
            } else if (mp[b] == 0) {
                mp[a]--;
                st.push(a);
            } else {
                print("No");
                return 0;
            }
        }
    }
    if (st.size() == 1 and mp[st.top()] == 0) {
        print("Yes");
    } else {
        print("No");
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const int MAX = 100005;
const int MOD = 1000000007;

ll N, K, ans=0;
vector<ll> A;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    COMinit();
    cin >> N >> K;
    A.resize(N);
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(), A.end());
    for(int i=N-1;i>=0;i--) {
            //if(K<2) continue;
            //else if(K==2) ans += A[i]-A[j];
            ans += A[i]*COM(i, K-1);
            ans %= MOD;
            ans -= A[i]*COM(N-i-1, K-1);
            ans %= MOD;
            //cout << COM(i-j-1, K-2) << endl;
            //cout << A[i]-A[j] << endl;
            //cout << ans << endl;
            //cout << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6268
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
int main(){
  int x;
  cin>>x;
  cout<<(!x)<<'\n';
}

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

int main() {
  int N;  //〇番目
  cin >> N;  //入力
  
  long K = 2;  //〇ー２番目のリュカ数をKとする
  long L = 1;  //〇－１番目のリュカ数をLとする
  long M = 0;  //〇番目のリュカ数をMとする
  
  if (N >= 2){
    for (int i = 0; i < N - 1; i++){
      M = K + L;
      K = L;
      L = M;
    }
  }
  //リュカ数を出力
  if (N == 1){
  	M = 1;
  }
  cout << M << endl;
}


Measured memory_bytes: 256
#include<iostream>
int main()
{
	int v1, v2, v3, v4, v5;
	std::cin >> v1 >> v2 >> v3 >> v4 >> v5;
	if ( v5 <= v3 && v5 <= v4 && v3 + v5 <= v1 && v4 + v5 <= v2 )
	{
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
	return 0;
}


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

int main(){
  long long a, b;
  cin >> a >> b;
  
  string ans;
  if(a * b <= 0) ans = "Zero";
  else if(a > 0) ans = "Positive";
  else if(a%2 == b%2) ans = "Negative";
  else ans = "Positive";
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (b / a >= c) {
            System.out.println(c);
            return;
        }
        System.out.println(b / a);
    }

}


Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;
void max(int a[],int num,int &max1,int &max2){
	max1=0;max2=0;
	for(int i=0;i<num;i++){
		if(max1<a[i] || i==0){
			max2=max1;
			max1=a[i];
		}else if(max2<a[i] || i==1){
			max2=a[i];
		}
	}
}
int main(){
	int num=0,a[200000]={},max1,max2;
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>a[i];
	}
	max(a,num,max1,max2);
	for(int i=0;i<num;i++){
		if(a[i]==max1){
			cout<<max2;
		}else{
			cout<<max1;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

void solve() {
    int n, k;
    cin >> n >> k;
    bool seen[n];
    memset(seen, false, sizeof seen);
    rep(i, k) {
        int a;
        cin >> a;
        rep(j, a) {
            int c;
            cin >> c;
            seen[c - 1] = true;
        }
    }
    int sm = 0;
    rep(i, n) {
        if (!seen[i]) {
            sm++;
        }
    }
    cout << sm << endl;
}

void querySolve() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    solve();
    //querySolve();
}


Measured memory_bytes: 3620
/****************************************************************************
 \file      ITP1_1_D.c
 \author    SENOO, Ken
 \copyright CC0
 \date      created date: 2016-03-05T16:10+09:00
 \date      updated date: 2016-03-05T17:30+09:00
 ****************************************************************************/

#include <stdio.h>

int main(){
  unsigned long int h, m, s;
  const int sph = 3600, spm = 60;

  scanf("%ld", &s);

  h  = s / sph;
  s -= h * sph;
  m  = s / spm;
  s -= m * spm;

  printf("%lu:%lu:%lu\n", h, m, s);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

vector<long long> a, p;

long long f(ll N, ll X){
    if(X == 0){
        return 0;
    }
    else if(N == 0){
        return 1;
    }
    else if(X <= a[N-1] + 1){
        return f(N-1, X-1);
    }
    else{
        return p[N-1] + 1 + f(N-1, X - a[N-1] - 2);
    }
}

int main(){
    a.resize(51); p.resize(51);
    a[0] = 1;
    p[0] = 1;
    for (ll i = 1; i < 51; i++) {
        a[i] = 2 * a[i-1] + 3;
        p[i] = 2 * p[i-1] + 1;
    }
    ll N, X;
    cin >> N >> X;
    printf("%lld\n", f(N, X));

}

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

int main() {
	//input
	int D, T, S;
	cin >> D >> T >> S;

	//calculation
	int t = (D - 1) / S;

	//output
	if (t < T) {
		cout << "Yes" << endl;

	} else {
		cout << "No" << endl;

	}


	return 0;
}


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

int main() {
    
    /* Input */
    int N;
    cin >> N;

    int AC = 0, WA = 0, TLE = 0, RE = 0;
    rep (i, N) {
        string s;
        cin >> s;
        if (s == "AC") AC++;
        if (s == "WA") WA++;
        if (s == "TLE") TLE++;
        if (s == "RE") RE++;
    }

    /* Output */
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
    return 0;
}

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

int main(){
	int N,A,B,ans=0,n;
	cin>>N>>A>>B;
	
	int X[N],Y[N]={};//X[i]=i,Yは各桁の和
	for(int i=0;i<N;i++)
		X[i]=i+1;
	
	for(int i=0;i<N;i++){
		while(X[i]!=0){
			Y[i]+=X[i]%10;
			X[i]/=10;
		}
	}
	
	for(int i=0;i<N;i++)
		X[i]=i+1;
	
	for(int i=0;i<N;i++){
		if(Y[i]>=A&&Y[i]<=B){
			n=i;
			ans+=X[n];
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 384
n, a = map(int, input().split())
x = [int(i) for i in input().split()]
cache = {}
def s(v, k, i):
    if i == n: return int(v > 0 and v == k * a)
    if v > a * n: return 0
    key = (v, k, i)
    if key in cache: return cache[key]
    cache[key] = s(v, k, i + 1) + s(v + x[i], k + 1, i + 1)
    return cache[key]

print(s(0, 0, 0))


Measured memory_bytes: 47652
#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<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main(){
    int N;
    int K;
    int g;
    int A;
    cin >> N >> K;
    cin >> g;
    int MAX = g;
    REP(i,N-1){
        cin >> A;
        if(MAX < A) MAX = A;
        g = gcd(A,g);
    }
    if(K <= MAX && K%g == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a > b)swap(a, b);
	if (b > c)swap(b, c);
	if (c > d)swap(c, d);
	if (a > b)swap(a, b);
	if (b > c)swap(b, c);
	if (a > b)swap(a, b);
	cout << ((a == 1 && b == 4 && c == 7 && d == 9) ? "YES\n" : "NO\n");
}

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

vector<ll> makediv(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.emplace_back(i);
			if (i * i != n) res.emplace_back(n / i);
		}
	}
	return res;
}

int main() {
	ll n; cin >> n;
	int ans = 0;
	for (ll x : makediv(n)) {
		if (x == 1) continue;
		ll tmp = n;
		while (tmp % x == 0) tmp /= x;
		tmp %= x;
		if (tmp == 1) ans++;
	}
	ans += (int)makediv(n - 1).size() - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;




int main() {
    int n;
    cin >> n;
    map<int,int> m1, m2;
    rep(i,n/2) {
        int a, b;
        cin >> a >> b;
        m1[a]++;
        m2[b]++;
    }
    int max1 = 0, max2 = 0;
    vector<int> maxa, maxb;

    for (auto ite = m1.begin(); ite != m1.end(); ite++) {
        max1 = max(max1, ite->second);
    }
    for (auto ite = m2.begin(); ite != m2.end(); ite++) {
        max2 = max(max2, ite->second);
    }
    for (auto ite = m1.begin(); ite != m1.end(); ite++) {
        if (max1 == ite->second) {
            maxa.push_back(ite->first);
        }
    }
    for (auto ite = m2.begin(); ite != m2.end(); ite++) {
        if (max2 == ite->second) {
            maxb.push_back(ite->first);
        }
    }

    if (maxa.size() == 1 && maxb.size() == 1 && maxa[0] == maxb[0]) {
        int max1sub = 0, max2sub = 0;
        for (auto ite = m1.begin(); ite != m1.end(); ite++) {
            if (ite->second != max1) max1sub = max(max1sub, ite->second);
        }
        for (auto ite = m2.begin(); ite != m2.end(); ite++) {
            if (ite->second != max2) max2sub = max(max2sub, ite->second);
        }
        cout << n - max1 - max(max1sub,max2sub) << endl;
    }
    else {
        cout << n - max1 - max2 << endl;
    }
}

Measured memory_bytes: 5504
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node


using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/

const int N = 200005;
int v1[N];
int v2[N];



void solve()
{ 
        int n,m;
        ll t;
        cin >> n >> m >> t;
    
        fo(i,0,n-1) cin >> v1[i];
        fo(i,0,m-1) cin >> v2[i];

        ll sum = 0LL;
        int best = 0;

        int i = -1;
        while((i+1)<n)
        {
          if(((sum+v1[i+1])<=t)) sum += v1[++i];
          else break;
        }

        int j = -1;

          while((j+1)<m)
          {
            if(((sum+v2[j+1])<=t))  sum += v2[++j];
            else break;
          }

           best = max(best,(i+j+2));

     
        while( (j+1) < m and i>=0)
        {
          
              sum -= v1[i--];
  
              while((j+1) < m)
             {
               if(((sum+v2[j+1])<=t)) sum += v2[++j];
               else break;
             }
     
               best = max(best,(i+j+2));
        }

        cout << best << endl;

       
}
int main() {
    
    FIO
  //  INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 5196
N=int(input())
A=[list(map(int,input().split())) for i in range(2)]
maxi=0

for j in range(0,N):
  cost = 0
  cost += sum(A[0][:j+1])
  cost += sum(A[1][j:])
  maxi=max(maxi,cost)
                  
print(maxi)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

#define int long long

using namespace std;

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

	cout << min(n % k, abs(n % k - k)) << endl;

}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 50;
const int MX_L=6;

int n;
int parent[MX_L][MX];
int depth[MX];
vector<vi> e;

void dfs(int c, int p, int d){
	depth[c] = d;
	parent[0][c] = p;
	rep(i, e[c].size()){
		int to = e[c][i];
		if(to == p) continue;
		dfs(to, c, d + 1);
	}
}
inline int lca(int a, int b){
	if(depth[a] > depth[b]) swap(a, b);
	int d = depth[b] - depth[a];
	rep(i, MX_L) if(d & 1 << i) b = parent[i][b];
	if(a == b) return a;
	for(int i = MX_L - 1; i >= 0; i--) if(parent[i][a] != parent[i][b]){
		a = parent[i][a];
		b = parent[i][b];
	}
	return parent[0][a];
}

int w[50];
int calc(int c, int p, int &ans){
	int res = w[c];
	for(int i : e[c]) if(i != p){
		int tmp = calc(i, c, ans);
		if(tmp < 0) ans++;
		res += tmp;
	}
	return res;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	e.resize(n);
	
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	parent[0][n] = n;
	dfs(0, n, 1);
	rep(i, MX_L - 1) rep(j, n) parent[i + 1][j] = parent[i][parent[i][j]];
	
	int m; cin >> m;
	vector<pi> v;
	rep(i, m){
		int a, b; cin >> a >> b; a--; b--;
		v.emplace_back(a, b);
	}
	vector<ll> way(1 << m);
	rep(i, 1 << m){
		memset(w, 0, sizeof(w));
		rep(j, m) if(i >> j & 1){
			int a = v[j].first, b = v[j].second;
			int c = lca(a, b);
			w[c] += 2; w[a]--; w[b]--;
		}
		int ans = 0;
		calc(0, 0, ans);
		way[i] = 1ll << (n - 1 - ans);
	}
	
	ll ans = 0;
	rep(i, 1 << m){
		if(__builtin_parity(i)) ans -= way[i];
		else ans += way[i];
	}
	cout << ans << endl;
	
	return 0;
}


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

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

int main() {
    int A; cin >> A;
    cout << (A == 1 ? 0 : 1) << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int ans = INF;
    rep(i, 201) {
        int tmp = 0;
        rep(j, N) tmp += (a[j] - 100 + i) * (a[j] - 100 + i);
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal bd = sc.nextBigDecimal();
		bd = bd.multiply(sc.nextBigDecimal());
		BigInteger bi = bd.toBigInteger();
		System.out.println(bi.toString());
	}
}


Measured memory_bytes: 37624
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<=n/4;i++){
        if((n-i*4)%7==0){
           printf("Yes\n");
           return 0;;
        }
    }
    printf("No\n");
    return 0;
}

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

int main(int argc, char* argv[]) {
  map<int, int> data;
  int var;
  int max = 0;
  while(cin >> var) {
    data[var]++;
    if(data[var] > max) {
      max = data[var];
    }
  }
  //cout << max << endl;
  for(map<int, int>::iterator it=data.begin(); it!=data.end(); it++) {
    if(it->second == max) cout << it->first << endl;
  }
}



Measured memory_bytes: 2980
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut string: String = read();
    let count: u32 = read();

    for _ in 0..count {
        let command: String = read();
        let a: usize = read();
        let b: usize = read();

        if command == "replace" {
            let p: String = read();
            string = format!("{}{}{}", &string[..a], &p, &string[(b + 1)..]);
        } else if command == "print" {
            println!("{}", &string[a..(b + 1)]);
        } else {
            let mut chars: Vec<_> = string[a..(b + 1)].chars().collect();
            chars.reverse();

            let reversed_chars: String = chars.into_iter().collect();

            string = format!("{}{}{}", &string[..a], reversed_chars, &string[(b + 1)..]);
        }
    }
}



Measured memory_bytes: 5036
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int n;
  double x1,y1,x2,y2,x3,y3,p,p1,p2,q,q1,q2,r;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    p1 = (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) * (y3 - y1) - (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) * (y2 - y1);
    p2 = 2 * (x1 * y2 - x1 * y3 + x2 * y3 - x2 * y1 + x3 * y1 - x3 * y2);
    p = p1 / p2;
    q1 = (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1) * (x3 - x1) - (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) * (x2 - x1);
    q2 =  2 * (y1 * x2 - y1 * x3 + y2 * x3 - y2 * x1 + y3 * x1 - y3 * x2);
    q = q1 / q2;
    r = sqrt((x1-p) * (x1-p) + (y1-q) * (y1-q) );
    p *= 1000;
    p += 0.5;
    p = floor(p);
    p /= 1000;
    q *= 1000;
    q += 0.5;
    q = floor(q);
    q /= 1000;
    r *= 1000;
    r += 0.5;
    r = floor(r);
    r /= 1000;
    printf("%.3f %.3f %.3f\n", p, q, r);
  }
}

Measured memory_bytes: 0
//C
#include <cassert>
//#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	char s;
	cin >> s;
	cout << (char)((int)s + 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    ll N; cin >> N;
    vector<pair<ll, ll>> P(N);
    for(int i = 0; i < N; i++){
        ll x; cin >> x;
        P[i] = {x, i};
    }
    sort(P.begin(), P.end());
    ll l = N/2-1, r = N/2;
    unordered_map<ll, ll> M;
    for(int i = 0; i < N/2; i++) M[P[i].second] = P[r].first;
    for(int i = N/2; i < N; i++) M[P[i].second] = P[l].first;

    for(int i = 0; i < N; i++) cout << M[i] << endl;


} 


Measured memory_bytes: 14536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
/*------------------junk----------------------*/
typedef long long int lli;
typedef unsigned long long int ulli;
const int MOD = 1e9 + 7;
#define ff first
#define ss second
#define gc getchar_unlocked
#define fri(i, j , n) for (auto (i) = (j); (i) < (n); ++(i))
#define frie(i, j , n) for (auto (i) = (j); (i) <= (n); ++(i))
#define frb(i,j, n) for (auto (i) = (j); (i) >= (n); (i)--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define rall(x) (x).rbegin(),(x).rend()
#define f2a(x , n , v)  fill(&(x)[0][0], &(x)[0][0] + (0 + n) *(0 + n) , (v))
#define fa(x , n , v) fill( (x), (x)+(n), (v)) 
#define ra(a) for(int &x : (a)) cin >> (x)
#define pa(a) for(int &x : (a)) cout << (x) << " ";cout << "\n"
#define pb emplace_back
#define mp make_pair
#define vi vector<int>
#define vlli vector<lli>
#define getchar_unlocked getchar
# define TMP template<typename
#ifdef LOCAL 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
    
    ~debug() { cerr << endl; }
    template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return * this; }
    template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return * this << range(begin(i), end(i)); }
    template < class c, class b > debug & operator <<(pair < b, c > d) {
        return * this << "(" << d.first << ", " << d.second << ")";
    }
    template < class c > debug & operator <<(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        return * this << "]";
    }};
#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
TMP Arg1>
void __f(const char *name, Arg1 &&arg1)
{cerr << name << ": " << arg1 << "\n";}
TMP Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{const char *comma = strchr(names + 1, ',');cerr.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);
}
void in(int &x){
    cin  >> x;
}
#else
inline void in(int &x)
    {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar_unlocked());
    if(c=='-') {neg=1;c=getchar_unlocked();}
    for(;c>47 && c<58;c = getchar_unlocked()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
    }
#endif
/*----------check constraints again-------------*/
int a[25];
int c[25];
int b[25];
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  in(n);
  frie(i,1 ,n) in(a[i]);
  frie(i,1 ,n) in(b[i]);
  frie(i,1 ,n-1) in(c[i]);
  int ans = 0;
  frie(i,1,n){
      ans+= b[a[i]];
      if (a[i + 1] == a[i] + 1) ans += c[a[i]];
  };
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N],B[N],C[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(A,A+N);
  sort(B,B+N);
  sort(C,C+N);
  ll num[N];
  for (int i = 0; i < N; i++) num[i] = 0;
  ll R[N];
  for (int i = 0; i < N; i++) {
    ll a = upper_bound(B,B+N,A[i]) - B;
    if (0 <= a && a < N) {
      num[a]++;
    }
  }
  R[0] = num[0];
  for (int i = 1; i < N; i++) {
    R[i] = R[i-1] + num[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll b = upper_bound(C,C+N,B[i]) - C;
    ans += (N - b) * R[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n;
    ll W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    ll w0;
    rep(i, n) {
        cin >> w[i] >> v[i];
        if (i == 0) w0 = w[0];
        w[i] -= w0;
    }
    // cout << w0 << endl;

    auto dp = make_vec<ll>(110, 440, 110);
    //重さj 選んだ個数k 価値max
    rep(i, n) {
        rep(j, 440) {
            rep(k, i + 1) {
                //使う
                if (j - w[i] >= 0)
                    chmax(dp[i + 1][j][k + 1], dp[i][j - w[i]][k] + v[i]);
                //使わない
                chmax(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }
    ll ans = 0;
    rep(j, 440) rep(k, n + 1) {
        if (j + k * w0 <= W) chmax(ans, dp[n][j][k]);
    }
    cout << ans << endl;
}

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

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    N,R = MI()
    ans = R + 100*(10-N)

    if N<10:
        print(ans)
    else:
        print(R)



if __name__ == "__main__":
	main()

Measured memory_bytes: 38384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
 
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
int main(void){
    int n,S[100000],q,T,below,above,middle,ans=0;
    cin >> n;
    FOR(i,0,n) cin >> S[i];
    cin >> q;
    FOR(i,0,q) {
        cin >> T;
        below=0;
        above=n-1;
        middle=(above-below)/2+below;
        FOR(j,0,n/2+2){
            if(S[middle]<T){
                below=middle;
                middle=(above-below)/2+below+1;
            }
            else if(S[middle]>T){
                above=middle;
                middle=(above-below)/2+below;
            }
            else{
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> vec(m, 0);
    for(int i=0; i< n; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int a;
            cin >> a;
            vec[a-1]++;
        }
    }
    int cnt=0;
    for(int i=0; i<m; i++){
        if(vec[i] == n) ++cnt;
    }
    out(cnt);

}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) (a+=b,b=a-b,a-=b)
const int MOD=1e9+7;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void AscRadix32(int *a,const int sz,const int minus)
{
  int x,shift=0,elem[256],temp[sz];
  while(shift<32)
  {
    int bucket[256]={0};
    rep(i,sz){x=(a[i]>>shift)&255;bucket[x]++;temp[i]=a[i];}
    elem[0]=0;rep(i,255)elem[i+1]=elem[i]+bucket[i];
    rep(i,sz){x=(temp[i]>>shift)&255;a[elem[x]]=temp[i];elem[x]++;}
    shift+=8;
  }
  rep(i,minus/2)swap(a[sz-minus+i],a[sz-1-i]);
  rep(i,(sz-minus)/2)swap(a[i],a[sz-minus-1-i]);
  rep(i,sz/2)swap(a[i],a[sz-1-i]);
}
int main()
{
  int N=IN(),K=IN(),l,m=0,r,accum=1,sign=1,A[N];long x,y;
  rep(i,N)A[i]=IN(),m+=A[i]<0?1:0;
  AscRadix32(A,N,m);
  if(K&1)accum=A[N-1],sign=(A[N-1]<0?-1:1),N--,K--;
  l=0,r=N-1;
  while(K)
  {
    x=1l*A[l]*A[l+1],y=1l*A[r]*A[r-1];
    if(x*sign>y*sign)x%=MOD,accum=1l*accum*x%MOD,l+=2;
    else y%=MOD,accum=1l*accum*y%MOD,r-=2;
    K-=2;
  }
  return printf("%ld\n",(1l*accum%MOD+MOD)%MOD),0;
}

Measured memory_bytes: 3140