akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
namespace fdata
{
inline char nextchar()
{
    static const int BS = 1 << 21;
    static char buf[BS], *st, *ed;
    if (st == ed)
        ed = buf + fread(st = buf, 1, BS, stdin);
    return st == ed ? -1 : *st++;
}
#ifdef lky233
#define nextchar getchar
#endif
template <typename Y>
inline void poread(Y &ret)
{
    ret = 0;
    char ch;
    while (!isdigit(ch = nextchar()))
        ;
    do
        ret = ret * 10 + ch - '0';
    while (isdigit(ch = nextchar()));
}
#undef nextcar
} // namespace fdata
using fdata::poread;
const int MAXN = 5e5 + 10;
const int MOD = 1e9 + 7;
#define int long long 
int n, m; 
int tree[MAXN];
inline void add(int x, int d)
{
	for(; x <= n; x += (x & -x))
		tree[x] += d;
}
inline int ask(int x)
{
	register int res = 0;
	for(; x; x -= (x & -x))
		res += tree[x];
	return res;
}
int a[MAXN];
int s[MAXN], suf[MAXN];
int fac[MAXN];
signed main()
{
	poread(n);
	fac[0] = 1;
	for(register int i = 1; i <= n; ++i)
		fac[i] = (long long)fac[i - 1] * i % MOD;
	int m = n;
	for(register int i = 1; i <= n; ++i)
	{
		poread(a[i]);
		if(a[i])
			++s[a[i]], --m;
	}
	for(register int i = 1; i <= n; ++i)
		suf[i] = s[i] = 1 - s[i], s[i] += s[i - 1];
	for(register int i = n; i >= 1; --i)
		suf[i] += suf[i + 1];
	register int sum = 0, cnt = 0;
	register int res = 0;
	for(register int i = n; i >= 1; --i)
	{
		if(a[i])
		{
			sum = (long long)ask(a[i] - 1) * fac[m] % MOD;
			if(cnt)
				sum = (sum + (long long)cnt * s[a[i]] % MOD * fac[m - 1] % MOD) % MOD;
			res = (res + (long long)sum * fac[n - i] % MOD) % MOD;
			add(a[i], 1);
//			cerr << sum << endl;
		}
		else
		{
			++cnt;
		}
//		cerr << "*" << res << endl;
	}
	cnt = sum = 0;
	for(register int i = 1; i <= n; ++i)
	{
		if(a[i])
		{
			if(cnt)
				res = (res + (long long)sum * suf[a[i]] % MOD * fac[m - 1] % MOD) % MOD;
		}
		else
		{
			sum = (sum + fac[n - i]) % MOD;
			++cnt;
		}
//		cerr << "*" << res << endl;
	}
	sum =  (long long)(m * (m - 1) >> 1 ) % MOD, cnt = 0;
//	cerr << sum << " " << m <<  endl;
	if(m >= 2)	
		for(register int i = 1; i <= n; ++i)
		{
			if(!a[i])
			{
				++cnt;
				res = (res + (long long)sum * (m - cnt) % MOD * fac[m - 2] % MOD * fac[n - i] % MOD);
//				cerr << sum << " " << m - cnt << " " << fac[m - 2] << " " << fac[n - i] << endl;
			}
//			cerr << "#" << res << endl;
		}
	res = (res + fac[m]) % MOD;
	cout << res << endl;
}


Measured memory_bytes: 21760
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
	// Your code goes here.
	vector<int>a(5);
	for (int i=0; i<5; i++)
    {
        cin>>a[i];

    }
    for (int i=0; i<5; i++)
    {
        if (a[i]==0)
        {
            cout<<i+1<<endl;
            return;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

    while (T--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3632
import heapq


def dijkstra(s):
    color=["white" for _ in range(n)]
    D=[inf for _ in range(n)]

    M=[[] for _ in range(n)]
    for i in range(n-1):
        M[i].append((1,i+1))
        M[i+1].append((1,i))
    M[x-1].append((1,y-1))
    M[y-1].append((1,x-1))

    D[s]=0

    H=[(0,s)]
    heapq.heapify(H)

    while len(H)>=1:
        u=heapq.heappop(H)[1]
        if color[u]=="black":continue
        color[u]="black"

        V=[(i,j) for i,j in M[u] if color[j]!="black"]
        while len(V)!=0:
            for i,j in V:
                if D[u]+i<D[j]:
                    D[j]=D[u]+i
                    color[j]="gray"
                    heapq.heappush(H,(D[j],j))
            break
    return D


inf=10**7
n,x,y=map(int,input().split())

A=[0]*n
for i in range(n):
    for j in dijkstra(i)[:i]:
        A[j] +=1

for i in A[1:]:
    print(i)

Measured memory_bytes: 131972
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    string s; 
    cin>>n>>s; 
    
    char _start = 'A';
    
    for (int i = 0; i < s.size(); ++ i) {
        cout<<  (char) (((s[i] - 'A') + n) % 26 + 'A');
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    long long kq=700;
    cin>>s;
    for(long long i=0;i<s.size();i++)
    {
        if(s[i]=='o')
            kq+=100;
    }
    cout<<kq;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin>>n>>k;
	vector<int> v;
	for(int i = 0; i < k; ++i){
		int a;
		cin>>a;
		v.push_back(a);
	}
	for(int i = n;;++i){
		int s = i;
		bool ok = true;
		while(s != 0){
			int r = s % 10;
			s /= 10;
			for(int j = 0; j < v.size(); ++j){
				if(v[j] == r)ok = false;
			}
		}
		if(ok){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

//----------------------------------------------------------------

int main()
{
    int n;
    cin >> n;
    string s;
    vector<long long> a(150), b(150);
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        b[s.at(i)] += 1;
    }
    for (int i = 0; i < n - 1; i++)
    {
        cin >> s;
        for (int j = 0; j < s.size(); j++)
        {
            a[s.at(j)] += 1;
        }
        for (int j = 0; j < 150; j++)
        {
            b[j] = min(b[j], a[j]);
        }
        for (int j = 0; j < 150; j++)
        {
            a[j] = 0;
        }
    }
    for (int i = 0; i < 150; i++)
    {
        if (b[i])
        {
            for (int j = 0; j < b[i]; j++)
            {
                cout << (char)i;
            }
        }
    }
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(n, vector<int>(3));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(int i = 1; i < n; i++)
  {
    for(int j = 0; j < 3; j++)
    {
      if(j == 0)
      {
        dp[i][j] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
      }else if(j == 1){
        dp[i][j] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
      }else{
        dp[i][j] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
      }
    }
  } 
  int max_hap = dp[n - 1][0];
  max_hap = max(max_hap, dp[n - 1][1]);
  max_hap = max(max_hap, dp[n - 1][2]);
  cout << max_hap << endl;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int mp[55][55];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    for( int i = 1; i <= h; ++i ) {
        string s;
        cin >> s;
        for( int j = 1; j <= w; ++j ) {
            if( s[j - 1] == '#' ) mp[i][j] = 1;

        }

    }

    for( int i = 1; i <= h; ++i ) {
        for( int j = 1; j <= w; ++j ) {
            if( !mp[i][j] )
            cout << mp[i - 1][j - 1] + mp[i - 1][j] + mp[i - 1][j + 1] + mp[i][j - 1] + mp[i][j + 1] + mp[i + 1][j - 1] + mp[i + 1][j] + mp[i + 1][j + 1];
            else cout << '#';
        }
        cout << endl;
    }

    return 0;
}



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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n,d;
  cin >> n >> d;
  int32 ans = 0;
  REP(i,n){
    int64 x,y;
    cin >> x >> y;
    if(x * x + y * y <= d * d)++ans;
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3652
import math
from collections import defaultdict
n = int(input())
ipt = [list(map(int,input().split())) for i in range(n)]
xy = sorted(ipt)
convh1 = [xy[0],xy[1]]
def slope(xy1,xy2,const = 1):
  x1,y1 = xy1
  x2,y2 = xy2
  dx,dy = x2-x1,y2-y1
  if dx == 0:
    return 10**18*(y2-y1)*const//abs(y2-y1)
  else:
    return dy/dx
def convex(xy1,xy2,xy3,const = 1):
  x1,y1 = xy1
  x2,y2 = xy2
  x3,y3 = xy3
  if slope([x1,y1],[x2,y2],const) < slope([x2,y2],[x3,y3],const):
    return True
  return False
for i in range(2,n):
  x,y = xy[i]
  while len(convh1) >= 2 and not convex(convh1[-2],convh1[-1],[x,y]):
    convh1.pop()
  convh1.append(xy[i])
convh2 = [xy[-1],xy[-2]]
for i in range(n-2)[::-1]:
  x,y = xy[i]
  while len(convh2) >= 2 and not convex(convh2[-2],convh2[-1],[x,y],-1):
    convh2.pop()
  convh2.append(xy[i])
convh = convh1+convh2[1:-1]
prob = [0 for i in convh]
dc = defaultdict(int)
for i,xy in enumerate(convh):
  x,y = xy
  px,py = convh[i-1]
  nx,ny = convh[(i+1)%len(convh)]
  px -= x
  py -= y
  nx -= x
  ny -= y
  rad = math.atan2(ny,nx)-math.atan2(py,px)
  dc[(x,y)] = (math.pi-min(abs(rad),2*math.pi-abs(rad)))/(2*math.pi)
for x,y in ipt:
  print(dc[(x,y)])

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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

void solve(){
    
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll flg=0;
    while(1){
        if(a <= 0 || c<=0)  
            break;
        
        if(flg){
            a -= d;
        }
        else{
            c -= b;
        }
        flg = !flg;
    }

    if(flg){
        cout << "Yes";
    }
    else cout << "No";

}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3580
N = int(input())
a_arr = list(map(int, input().split()))
b_arr = list(map(int, input().split()))
c_arr = list(map(int, input().split()))

ans = b_arr[a_arr[0]-1]
for i in range(1,N):
    if a_arr[i] == a_arr[i-1]+1:
        ans += c_arr[a_arr[i]-2]+b_arr[a_arr[i]-1]
    else:
        ans += b_arr[a_arr[i]-1]

print(ans)

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

int DP[8][1001];
int m,n,a,b,g;


int main(){
	for(int j=0; j<1001; j++)
		DP[0][j] = 0;
	DP[0][0] = 1;
	
	while(true){
		cin >> m;
		if(m == 0)
			return 0;
		
		for(int i=1; i<=m; i++){
			cin >> a >> b;
			
			for(int j=0; j<1001; j++)
				DP[i][j] = DP[i-1][j];
			
			for(int j=0; j<1001; j++){
				if(DP[i-1][j] == 0)
					continue;
				for(int k=1; k<=b; k++){
					if(k*a+j > 1000)
						break;
					DP[i][k*a+j] += DP[i-1][j];
				}
			}
			
		}
		
		cin >> g;
		for(int i=0; i<g; i++){
			cin >> n;
			cout << DP[m][n] << endl;
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
long long MIN(long long a,long long b){return labs(a)<labs(b)?labs(a):labs(b);}
int main(){
  int n,m,i;
  long long s=1e18,d[100010];
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  for(i=m-1;i<n;i++)s=MIN(s,d[i]-d[i-m+1]+MIN(d[i],d[i-m+1]));
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 896
a,b,c = map(int,input().split())
if a == b:
    if b != c:
        print('Yes')
    else:
        print('No')
elif b == c:
    if a != b:
        print('Yes')
    else:
        print('No')
elif c == a:
    if a != b:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
    int countA = 0,countW = 0, countT = 0, countR = 0;
    int n;
    cin>>n;
    string s [n];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        if (s[i] == "AC")
            countA++;
        else if (s[i] == "WA")
            countW++;
        else if (s[i] == "TLE")
            countT++;
        else if (s[i] == "RE")
            countR++;
    }
    cout<<"AC x "<<countA<<"\n";
    cout<<"WA x "<<countW<<"\n";
    cout<<"TLE x "<<countT<<"\n";
    cout<<"RE x "<<countR<<"\n";
    return 0;
}

Measured memory_bytes: 5532
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
int main(){
    int k,n;cin>>k>>n;
    vector<int>A(n),D(n);
    rep(i,0,n)cin>>A[i];
    rep(i,0,n-1)D[i]=A[i+1]-A[i];
    D[n-1]=abs(k+A[0]-A[n-1]);
    int diff=0;
    for(int d:D){
        diff=max(diff,d);
    }
    cout<<k-diff<<endl;
}

Measured memory_bytes: 4800
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D, Ans, inter; vll path;
int main() {
	long double ans = 0;
	cin >> N;
	vector<long double> T(N+1), V(N+2);
	long double sum = 0;
	T[0] = 0;
	for (i = 1; i <= N; i++) {
		long double t;
		cin >> t;
		T[i] = T[i - 1] + t;
		sum += t;
	}
	V[0] = 0; V[N + 1] = 0;
	for (i = 1; i <= N; i++) {
		cin >> V[i];
	}
	for (long double i = 0; i < sum; i+=0) {
		long double y1 = INF;
		for (long double j = 1; j <= N; j++) {
			if (i < T[j-1]) {
				y1 = min(y1, V[j] + (T[j-1] - i));
			}
			else if (T[j] < i) {
				y1 = min(y1, V[j] + (i - T[j])); 
			}
			else {
				y1 = min(y1, V[j]);
			}
			y1 = min(y1, min(i,sum-i));
		}
		i += 0.5;
		long double y2 = INF;
		for (long double j = 1; j <= N; j++) {
			if (i < T[j - 1]) {
				y2 = min(y2, V[j] + (T[j - 1] - i));
			}
			else if (T[j] < i) {
				y2 = min(y2, V[j] + (i - T[j]));
			}
			else {
				y2 = min(y2, V[j]);
			}
		}
		y2 = min(y2, min(i, sum - i));
		//debug(i - 0.5, y1, y2);
		ans += (y1 + y2) / 4;
	}
	cout << fixed << setprecision(12) << ans;
}

Measured memory_bytes: 256
from math import floor, ceil

H,W = map(int, input().split())

def solve(H: int, W: int) -> int:
    # H,Wのどちらかが3の倍数なら0
    if H % 3 == 0 or W % 3 == 0:
        return 0
    
    else:
        INF = float("inf")
        
        # [0]:タテ3分割, [1]：ヨコ3分割, [2]:T字, [3]:ト字
        ans_cand = [INF for _ in range(4)]
        
        # [0]タテ3分割
        if H < 3:
            pass
        else:
            ans_cand[0] = H
            
        # [1]ヨコ3分割
        if W < 3:
            pass
        else:
            ans_cand[1] = W
            
        # [2]T字 (floor,ceil)×(H,W)の4パターン考える
        tmp = 0
        best = INF
        
        # floor×floor
        h = floor(H/3)
        w = floor(W/2)
        
        pieces = [h*W, (H-h)*w, (H-h)*(W-w)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # floor×ceil
        h = floor(H/3)
        w = ceil(W/2)
        
        pieces = [h*W, (H-h)*w, (H-h)*(W-w)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # ceil×floor
        h = ceil(H/3)
        w = floor(W/2)
        
        pieces = [h*W, (H-h)*w, (H-h)*(W-w)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # ceil×ceil
        h = floor(H/3)
        w = floor(W/2)
        
        pieces = [h*W, (H-h)*w, (H-h)*(W-w)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        ans_cand[2] = best
          
        
        # [3]ト字 (floor,ceil)×(H,W)の4パターン考える
        tmp = 0
        best = INF
        
        # floor×floor
        w = floor(W/3)
        h = floor(H/2)
        
        pieces = [w*H, (W-w)*h, (W-w)*(H-h)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # floor×ceil
        w = floor(W/3)
        h = ceil(H/2)
        
        pieces = [w*H, (W-w)*h, (W-w)*(H-h)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # ceil×floor
        w = ceil(W/3)
        h = floor(H/2)
        
        pieces = [w*H, (W-w)*h, (W-w)*(H-h)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        # ceil×ceil
        w = ceil(W/3)
        h = ceil(H/2)
        
        pieces = [w*H, (W-w)*h, (W-w)*(H-h)]
        tmp = max(pieces) - min(pieces)
        best = min(tmp,best)
        
        ans_cand[3] = best
        
    return min(ans_cand)

ans = solve(H,W)
print(ans)

Measured memory_bytes: 3192
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut x: Vec<usize> = Vec::new();
    for _ in 0..n {
        let a: usize = scan(tokens);
        if x.is_empty() || x[x.len() - 1] >= a {
            x.push(a);
        } else if x[0] < a {
            x[0] = a;
        } else {
            let mut i = 0;
            let mut j = x.len() - 1;
            while i + 1 < j {
                let c = (i + j) / 2;
                if x[c] >= a {
                    i = c;
                } else {
                    j = c;
                }
            }
            x[j] = a;
        }
    }
    println!("{}", x.len());
}


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

typedef pair<int, int> P;

struct UnionFind {
  vector<int> par, sizes;

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

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

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

    if (x == y) return;

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

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

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

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

struct Edge {
  int a, b, cost;

  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

struct Graph {
  int n;
  vector<Edge> es;

  // クラスカル法
  int kruskal() {
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;
    for (int i = 0; i < es.size(); i++) {
      Edge& e = es[i];
      if (!uf.same(e.a, e.b)) {
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

int main() {
  int N;
  cin >> N;
  P x[N], y[N];
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &x[i].first, &y[i].first);
    x[i].second = y[i].second = i;
  }

  // 最小全域木を求めるのに辺が多すぎるので、必要な辺だけを残す
  sort(x, x + N), sort(y, y + N);

  Graph g;
  g.n = N;
  Edge e;
  for (int i = 0; i < N - 1; i++) {
    e.a = x[i].second, e.b = x[i+1].second, e.cost = x[i+1].first - x[i].first;
    g.es.push_back(e);
    e.a = y[i].second, e.b = y[i+1].second, e.cost = y[i+1].first - y[i].first;
    g.es.push_back(e);
  }

  cout << g.kruskal() << endl;
  return 0;
}


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

double ans = 1e9;
int main() {
  int N, T, A;
  cin >> N >> T >> A;
  double tmp[N];
  for(int i = 0; i < N; i++){
    double h; cin >> h;
    tmp[i] = T - h * 0.006;
  }
  
  for(int i = 0; i < N; i++){
    ans = min(ans, abs(tmp[i]-A));
  }
  for(int i = 0; i < N; i++){
    if(ans==abs(A-tmp[i])){
      cout << i+1 << endl;
      return 0;
    }
  }
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

ll gcd(ll a,ll b) {
    while (b) {
        a %= b;
        swap(a,b);
    }
    return a;
}

int const MAX_N = 1000010;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

int main() {
    ll a,b;
    cin >> a >> b;
    ll g = gcd(a,b);
    Eratosthenes();
    int ans = 1;
    for (ll p : prime) {
        if (p*p > g) break;
        if (g%p == 0) {
            ans++;
            while (g%p == 0) g /= p;
        }
    }
    if (g > 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>
#define MAX 100

int adj[MAX][MAX];
int d[MAX];
int f[MAX];
int flg[MAX];
int time=0;

void dfs(int u,int n){
	
	flg[u]=1;
	d[u]=++time;
	
	for(int i=0;i<n;i++){
		if(adj[u][i] && !flg[i]){
			dfs(i,n);
		}
	}
	f[u]=++time;
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		flg[i]=0;
		for(j=0;j<n;j++)
			adj[i][j]=0;
	}
	
	for(i=0;i<n;i++){
    	scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			adj[x-1][z-1]=1;
		}
	}
	
	for(i=0;i<n;i++){
		if(!flg[i])
			dfs(i,n);
	}
	
	for(i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
	
	return 0;
	
}



Measured memory_bytes: 2112
#include <iostream>

int main(void){
    int a,b;
    std::cin >> a >> b;
    if(a<b){
        std::cout << "a < b" <<std::endl;
    }
    if(a>b){
        std::cout << "a > b" <<std::endl;
    }
    if(a==b){
         std::cout << "a == b" <<std::endl;
    }
    return 0;
} 



Measured memory_bytes: 3084
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=1e3+5;
char s[maxn][maxn];
int ans[maxn][maxn],vis[maxn][maxn],n,m,fx,fy,tx,ty;
int dir[4][2]={1,0,-1,0,0,1,0,-1};

struct node
{
    int x,y,step=0;
};
deque<node> Q;

int main()
{
    n=read(),m=read();
    fx=read(),fy=read();
    tx=read(),ty=read();
    REP(i,1,n) scanf("%s",s[i]+1);
    REP(i,1,n) REP(j,1,m) ans[i][j]=-1;
    Q.push_back((node){fx,fy,0});
    while(!Q.empty())
    {
        node nd=Q.front(); Q.pop_front();
        int x=nd.x,y=nd.y,step=nd.step;
        if(vis[x][y]) continue;
        //cout<<x<<' '<<y<<endl;
        vis[x][y]=1;
        ans[x][y]=step;
        for(int i=0;i<4;i++)
        {
            int xx=x+dir[i][0],yy=y+dir[i][1];
            if(xx>0 && xx<=n && yy>0 && yy<=m && !vis[xx][yy] && s[xx][yy]=='.')
                Q.push_front((node){xx,yy,step});
        }
        for(int xx=x-2;xx<=x+2;xx++)
            for(int yy=y-2;yy<=y+2;yy++)
            {
                if(xx>0 && xx<=n && yy>0 && yy<=m && !vis[xx][yy] && s[xx][yy]=='.')
                    Q.push_back((node){xx,yy,step+1});
            }
    }
    if(ans[tx][ty]<0) puts("-1");
    else printf("%d\n",ans[tx][ty]);

    return 0;
}

Measured memory_bytes: 13008
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <set>
#include <map>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
using namespace std;
typedef long long LL;
int v[205][205][2];
vector<vector<int>> a(205, vint(205));
int dp(int i, int j, int n, int m, int c)
{
    int k;
    a[i][j] == c ? k = 0 : k = 1;
    if (v[i][j][c] != -1)
    {
        return v[i][j][c];
    }
    else if (i < n && j < m)
    {
        return v[i][j][c] = min(dp(i, j + 1, n, m, a[i][j]), dp(i + 1, j, n, m, a[i][j])) + k;
    }
    else if (j < m)
    {
        return v[i][j][c] = dp(i, j + 1, n, m, a[i][j]) + k;
    }
    else if (i < n)
    {
        return v[i][j][c] = dp(i + 1, j, n, m, a[i][j]) + k;
    }
    else
    {
        return v[i][j][c] = k;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            char e;
            cin >> e;
            if (e == '.')
                a[i][j] = 0;
            else
                a[i][j] = 1;
        }
    }
    for (int i = 1; i <= 101; i++)
    {
        for (int j = 1; j <= 101; j++)
        {
            for (int k = 0; k <= 1; k++)
            {
                v[i][j][k] = -1;
            }
        }
    }
    cout << ceil((double)dp(1, 1, n, m, 0) / 2) << "\n";
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static final int MOD = 1000000007;
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] S = new int[N], T = new int[M];
		for (int i = 0; i < N; i++) {
			S[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			T[i] = sc.nextInt();
		}
		int[][][] table = new int[2][N+1][M+1]; // 0 no restriction, 1 must use first of S
		Arrays.fill(table[0][N], 1);
		for (int i = 0; i < N; i++) {
			table[0][i][M] = 1;
		}
		for (int i = N - 1; i >= 0; i--) {
			for (int j = M - 1; j >= 0; j--) {
				table[1][i][j] = table[1][i][j+1];
				if (S[i] == T[j]) {
					table[1][i][j] += table[0][i+1][j+1];
					table[1][i][j] %= MOD;
				}
				table[0][i][j] = (table[1][i][j] + table[0][i+1][j]) % MOD;
			}
		}
		out.println(table[0][0][0]);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 82772
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

lli bin_pow(lli a, lli b)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1)
            ret *= a;
        b >>= 1;
        a *= a;
    }
    return ret;
}

int main()
{
    lli n, p, d, curr, ans, pow, arr[200005];
    string s;
    cin >> n >> p;
    cin >> s;
    curr = 0, ans = 0;
    memset(arr, 0, sizeof(arr));
    arr[curr]++;
    // pow=1;

    if (p == 2)
    {
        for (lli i = 0; i < n; i++)
        {
            if ((s[i] - '0') % 2 == 0)
                ans += (i + 1);
        }
    }
    else if (p == 5)
    {
        for (lli i = 0; i < n; i++)
        {
            if ((s[i] - '0') % 5 == 0)
                ans += (i + 1);
        }
    }
    else
    {
        lli po = 1;
        for (lli i = n - 1; i >= 0; i--)
        {
            curr = curr + ((s[i] - '0') * po);
            curr = curr % p;
            // if (curr < 0)
            //     curr += p;
            po = (po * 10) % p;
            ans += arr[curr];
            arr[curr]++;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.sync_with_stdio(0); cout.tie(0);
#define Bye return 0
#define int long long
const int MAX = 1e6+1;

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

	int a[n];
	for (int i=0; i<n; i++)
        cin>>a[i];

    sort(a, a+n);

    int sum = 0;
    for (int i=0; i<k; i++)
        sum += a[i];

    cout<<sum<<endl;
}

int32_t main()
{
    //IOS;
    solve();
    Bye;
}


Measured memory_bytes: 3620
#include <iostream>
#include<map>

using namespace std;
#define fin(ans) cout << (ans) << '\n'
int main()
{
    map<string,string> m;
    m["Sunny"] = "Cloudy";
    m["Cloudy"] = "Rainy";
    m["Rainy"] = "Sunny";
    string S;
    cin >> S;
    fin(m[S]);
    return 0;   
}

Measured memory_bytes: 3124
n, m = map(int, input().split())
T1 = [list(map(int, input().split())) for i in range(n)]
T2 = [list(map(int, input().split())) for i in range(m)]


for i in range(n):
    ans = 0
    man = 10 ** 9

    for j in range(m):
        tmp = abs(T1[i][0] - T2[j][0]) + abs(T1[i][1] - T2[j][1])
        if man > tmp:
            man = tmp
            ans = j + 1

    print(ans)

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

using namespace std;
#define mod 1000000007;
long long int fact(long long int n)
{
    if(n==1)
        return 1;
    return n*fact(n-1)%mod;
}

int main() {
    long long int n,m;
    cin>>n>>m;
    if(abs(n-m)==1)
    {
        cout<<fact(n)*fact(m)%mod;
    }
    else if(n-m==0)
    {
        cout<<2*fact(n)*fact(n)%mod;
    }
    else
    {
        cout<<0;
    }
//cin>>n;
    
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import itertools


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    p_cnt = 0
    q_cnt = 0
    i = 0
    for temp in itertools.permutations([i + 1 for i in range(n)]):
        i += 1
        if temp == p:
            p_cnt = i
        if temp == q:
            q_cnt = i

        if p_cnt != 0 and q_cnt != 0:
            break

    return abs(q_cnt - p_cnt)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3188
import java.util.Scanner;

/**
 * <p>Description: </p>
 * <p>Company: http://www.dmall.com</p>
 *
 * @author yong.zhang@dmall.com
 * @version 1.0.0
 * @date 2019/11/14 9:17
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        System.out.println(N * N);
    }
}

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

int main(){
    int A, B;
    cin >> A >> B;
    int a = A + B,b = A - B, c = A * B, d = max(a,b), e=max(b,c);
    cout << max(d,e) << endl;
}

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

int main(int argc, char *argv[]) {
    string s,t;
    cin >> s >> t;
    t.pop_back();
    if(s==t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);


        String s = in.readLine();
        if (s.charAt(s.length() - 1) == 's') pw.println(s + "es");
        else pw.println(s + "s");
        
        pw.close();
    }
   
}


Measured memory_bytes: 36620
#include <iostream>
#include <vector>
#include <algorithm>
#define sup 1000000
using namespace std;
std::vector<int> prm;
/*
inline bool isinthevector(std::vector<int> v,int n)
{
	std::vector<int>::iterator i=find(v.begin(), v.end(),n);
	return i!=v.end();
}
*/

inline bool isprmfunc(int n)
{
	for (int i = 0; prm[i]*prm[i]<=n; ++i)
	{
		if(n%prm[i]==0) return false;
	}
	return true;
}

int main(int argc, char const *argv[])
{
	prm.push_back(2);
	prm.push_back(3);
	bool isprm=true;
	for(int n=5;n<=sup;n+=2,isprm=true)
	{
		for (int i=0;prm[i]*prm[i]<=n;++i)
		{
			if(n%prm[i]==0)
			{
				isprm=false;
				break;
			}
		}
		if (isprm==true)
		{
			prm.push_back(n);
		}
	}

	int n;
	while(cin>>n,n)
	{
		int cnt=0;
		for (int i=0;2*prm[i]<=n;++i)
		{
			if (isprmfunc(n-prm[i]))
			{
				++cnt;
			}
		}
		cout<<cnt<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define  mxn  200000
int arr[mxn];
int cum[mxn];
int main()
{
   ll n;
   cin >> n;
   n--;
   cout << (n*(n+1) )/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def gcd(a, b):
    while(b > 0):
        c = a % b
        a = b; b = c
    return a

n = ni()
g = 0
for i in range(n):
    v = ni()
    if g == 0:
        g = v
    else:
        g = g//gcd(g,v)*v
print(g)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS)
using namespace std;
const int maxn = 1e5 + 50;
int N, K;
int a[maxn], b[maxn], c[maxn];
bool sol()
{
	if (N < (K << 1) - 1) return 0;
	if (N & 1)
	{
		int L = (N + 1) >> 1;
		int cnt = 0;
		for (int i = K; i <= K + 2 * L - 2; i += 2) 
			a[++cnt] = i;
		for (int i = K + 1; i <= K + 2 * L - 3; i += 2)
			a[++cnt] = i;
		cnt = 0;
		for (int i = K + 3 * L - 2; i >= K + 2 * L - 1; --i)
			b[++cnt] = i;
		for (int i = K + 4 * L - 3; i >= K + 3 * L - 1; --i)
			b[++cnt] = i;
		cnt = 0;
		for (int i = K + 4 * L - 2; i <= K + 6 * L - 4; ++i)
			c[++cnt] = i;
	}
	else
	{
		int L = N >> 1;
		int cnt = 0;
		for (int i = K; i <= K + 2 * L - 2; i += 2)
			a[++cnt] = i;
		for (int i = K + 1; i <= K + 2 * L - 1; i += 2)
			a[++cnt] = i;
		cnt = 0;
		for (int i = K + 3 * L - 1; i >= K + 2 * L; --i)
			b[++cnt] = i;
		for (int i = K + 4 * L - 1; i >= K + 3 * L; --i)
			b[++cnt] = i;
		cnt = 0;
		for (int i = K + 4 * L; i <= K + 6 * L; ++i)
			c[++cnt] = i;
	}
	for (int i = 1; i <= N; ++i)
		printf("%d %d %d\n", a[i], b[i], c[i]);
	return 1;
}
int main()
{
	scanf("%d%d", &N, &K);
	if (!sol())
		puts("-1");
	return 0;
} 


Measured memory_bytes: 3456
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n;cin>>n;
    string s;cin>>s;
    int k;cin>>k;
    rep(i,0,n){
        if(s[i]!=s[k-1])s[i]='*';
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n>>k;
    vc fa(n+1,0);
    Ff(i,0,k)
    {
      cin>>x;
      while(x--)
      {
        cin>>y;
        fa[y]++;
      }
    }
    ll ans=0;
    Ff(i,1,n+1)
    {
      if(fa[i]==0)
      ans++;
    }
    cout<<ans;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10636
#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 n,m,res[3]={-1,-1,-1};
  cin >> n >> m;
  m=m/1000;
  rep(i,n+1){
  	rep(j,n-i+1){
  		if(m==9*i+4*j+n)	{
 	      res[0]=i;
          res[1]=j;
          res[2]=n-i-j;
        }
      
  	}
  }
  
  cout << res[0] << " " << res[1] << " " << res[2] <<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
// const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
          dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int h, w; cin >> h >> w;
  vector<string> s(h); REP(i, h) cin >> s[i];
  vector<vector<char> > ans(h, vector<char>(w, '#'));
  REP(i, h) REP(j, w) if (s[i][j] == '.') {
    int cnt = 0;
    REP(k, 8) {
      int y = i + dy[k], x = j + dx[k];
      if (0 <= y && y < h && 0 <= x && x < w && s[y][x] == '#') ++cnt;
    }
    ans[i][j] = '0' + cnt;
  }
  REP(i, h) {
    REP(j, w) cout << ans[i][j];
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

s = input()
s_rev = s[::-1]
count = 0
for i in range(len(s) // 2):
    if s[i] != s_rev[i]:
        count += 1
print(count)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(T1, T2, A1, A2, B1, B2):
    la1 = T1*A1
    la2 = T2*A2
    lb1 = T1*B1
    lb2 = T2*B2

    la = la1 + la2
    lb = lb1 + lb2
    if la == lb:
        return 'infinity'

    if la1 > lb1 and la2 > lb2:
        return 0
    if la1 < lb1 and la2 < lb2:
        return 0

    if la > lb and la1 > lb1:
        return 0

    if la < lb and la1 < lb1:
        return 0


    p = la1 - lb1
    q = la2 - lb2
    if p > q:
        p *= -1
        q *= -1
    ans = -p//(q+p)*2
    if -p % (q+p) != 0:
        ans += 1
    return ans

def main():
    T1, T2 = read_int_n()
    A1, A2 = read_int_n()
    B1, B2 = read_int_n()
    print(slv(T1, T2, A1, A2, B1, B2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6724
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	    cin>>h[i];
	vector<int> dp(n);
	dp[0] = 0;
	int j;
	for(int i=1;i<n;i++){
		if(i-k<1)
		    j = 0;
		else
		    j = i-k;
		dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
		while(j<i-1){
			dp[i] = min(dp[j]+abs(h[i]-h[j]),dp[i]);
			j++;
		}
	}
	cout<<dp[n-1];
	return 0;
}



Measured memory_bytes: 4056
n = int(input())
x_l = list(map(int, input().split()))
y_l = list(map(int, input().split()))
p1 = sum(abs(x_l[i]-y_l[i]) for i in range(n))
p2 = (sum(abs(x_l[i]-y_l[i])**2 for i in range(n)))**0.5
p3 = (sum(abs(x_l[i]-y_l[i])**3 for i in range(n)))**(1/3)
p_max = max(abs(x_l[i]-y_l[i]) for i in range(n))
print(p1, p2, p3, p_max)


Measured memory_bytes: 5656
D=int(input())
c=list(map(int,(input().split())))
s=[]
t=[]
last=[0]*26
sat=0
  
for i in range(D):
  s.append(list(map(int,(input().split()))))
  sat+=max(s[i])
  ans=s[i].index(max(s[i]))+1
  t.append(ans)
  print(ans)

Measured memory_bytes: 9420
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 n: usize = read();

    println!("{}", n * n * n);
}


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

int main() {
  int n;
  cin >> n;
  vector<float> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  float ans = v[0];
  for(int i = 1; i < n; ++i) {
    ans = (ans + v[i]) / 2;
  }
  printf("%.10f", ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long total = 0;
		long[] a = new long[3*n];
		for(int i=0; i<3*n; i++){
			a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		for(int i=3*n-1; n<=i; i--){
			if(n%2==0){
				if(i%2==0){
					total = total + a[i];
				}
			}
			else{
				if(i%2==1){
					total = total + a[i];
				}
			}
		}
				System.out.println(total);
	}
}

Measured memory_bytes: 97896
#include<stdio.h>
int main(){
    int s,m,h,sec;
    scanf("%d",&sec);
    h=(int) sec/3600;
    m=(int) (sec-h*3600)/60;
    s=sec-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    string N;
    cin >> N;
    int n=N.size();
    char m=N.at(n-1);
    if(m=='0'||m=='1'||m=='6'||m=='8'){
        cout << "pon" << endl;
    }else if(m=='3'){
        cout << "bon" << endl;
    }else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3628