akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;

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; }


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

void solve() {
    ll N, K; cin >> N >> K;
    ll h[110000]; rep(i, N) cin >> h[i];
    ll dp[110000]; rep(i, N) dp[i] = INF;

    dp[0] = 0;
    for (int i = 0; i < N; ++i){
        for (int j = 1; j <= K; ++j){
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[N-1] << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int l[101] = { 0 };
	int n = 0;
	int g;
	while (cin >> g) {
		l[g]++;
		n = max(n, l[g]);
	}
	for (int i = 0; i < 100; i++){
		if (l[i] == n)
			cout << i << endl;
	}
}

Measured memory_bytes: 2980
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s; //source
	int d; //destination
	Weight w; //weight
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

enum { WHITE, GRAY, BLACK };
vector<int> dijkstra(const Graph &g, int s, vector<Weight> &dist) {
	using State = tuple<Weight, int, int>; //?§?????????????????°?????????? ??? ???
	priority_queue<State, vector<State>, greater<State>> PQ;
	int n = g.size();
	vector<int> color(n, WHITE);
	vector<int> prev(n, -1);
	dist.assign(n, INF);
	dist[s] = 0; PQ.emplace(0, s, -1); color[s] = GRAY; //?§????
	while (PQ.size()) {
		Weight d; int v, u;
		tie(d, v, u) = PQ.top(); PQ.pop(); //dist???????°???¨??????State???????????????
		if (dist[v] < d)continue; //?????§???????????§???????????°??????
		color[v] = BLACK;
		prev[v] = u;
		for (auto &e : g[v]) { //??£??\????????????????????¨????????????		
			if (color[e.d] == BLACK)continue; //??¢?´¢????????????
			if (dist[e.d] > dist[v] + e.w) {
				dist[e.d] = dist[v] + e.w;
				PQ.emplace(dist[e.d], e.d, v);
				color[e.d] = GRAY;
			}
		}
	}
	return prev;
}

//??¨?????´???
Edge diameter(const Graph &g, int s = 0) {
	vector<Weight> dist;
	dijkstra(g, s, dist);
	int n = g.size(), u = -1, v = -1;
	for (int i = 0; i < n; i++) if (dist[i] != INF && (u == -1 || dist[i] > dist[u])) u = i;
	dijkstra(g, u, dist);
	for (int i = 0; i < n; i++) if (dist[i] != INF && (v == -1 || dist[i] > dist[v])) v = i;
	Weight d = dist[v];
	if (u > v) swap(u, v);
	return Edge(u, v, d);
}

//??¨?????????
//?????????: ??????????????????????????????????????§????????¢
vector<Weight> height(const Graph &g) {
	Edge e = diameter(g);
	vector<Weight> dist1, dist2;
	dijkstra(g, e.s, dist1);
	dijkstra(g, e.d, dist2);
	int n = g.size();
	vector<Weight> height(n);
	for (int i = 0; i < n; i++)
		height[i] = max(dist1[i], dist2[i]);
	return height;
}

signed main() {
	int n; cin >> n;
	Graph g(n);
	rep(i, 0, n-1) {
		int s, t, w; cin >> s >> t >> w;
		g[s].emplace_back(s, t, w);
		g[t].emplace_back(t, s, w);
	}
	vector<Weight> ans = height(g);
	for (auto w : ans)cout << w << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 2000000000;
constexpr auto MOD = 1000000007;

ll a, b, x;

ll divx(ll i) {
	if (i == 0)return 1;
	return 1 + i / x;
}

int main() {

	cin >> a >> b >> x;
	if (a == 0)cout << divx(b) << endl;
	else cout << divx(b)-divx(a-1) << endl;
}

Measured memory_bytes: 256
import numpy as np

def main():
    #n = int(input())
    n,a,b = map( int, input().split())
    l = []
    for i in range(1,n+1):
        i_sum = np.sum([int(x) for x in list(str(i))])
        #print(i_sum)
        if a <= i_sum and i_sum <= b:
            #print(i)
            l.append(i)
    print(np.sum(l))

    
    
if __name__ == '__main__':
    main()

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

int main()
{
  int a;
  int b;
  int x;
  
  cin >> a >> b;
  
  x = a * b;
  
  if (x % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
 
  return (0);
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////


int main()
{
    fast
    #ifdef ANUBHAB
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n, A[400000] = {0}, a, B[400000], tot = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
      cin >> B[i], ++A[B[i]];
    for (int i = 0; i <= n; i++)
      tot += (A[i] * (A[i] - 1)) / 2;
    for (int i = 0; i < n; i++)
    {
      a = tot - (A[B[i]] * (A[B[i]] - 1)) / 2;
      a += ((A[B[i]] - 2) * (A[B[i]] - 1)) / 2;
      cout << a << "\n";
    }
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long i64;
using namespace std;

int H, W;

long long int min(long long int x, long long int y) {
	if (x < y) { return x; }
	return y;
}

long long int calc(long long int a, long long int b, long long int c) {
	vector<long long int > V;
	V.push_back(a);
	V.push_back(b);
	V.push_back(c);
		sort(V.begin(), V.end());
	return V[2] - V[0];
}

i64 sep(i64 cur, i64 h, i64 w)
{
	i64 mx, lo;
	if (h % 2 == 0 || w % 2 == 0) {
		mx = lo = h * w / 2;
	}
	else {
		mx = (h * w + min(h, w)) / 2;
		lo = h * w - mx;
	}
	return max({ 0LL, mx - cur, cur - lo, mx - lo });
}


int main(void) {

	cin >> H >> W;
	
	/*for (H = 99990; H <= 100000; H++) {
		for (int W = 4444; W <= 4468; W++) {
*/
			long long int ans = (long long int) H*W;
			//1
			long long int a, b, c;
			long long int value;
			for (a = 1; a <= W - 1; a++) {
				b = (W - a) / 2;
				c = W - a - b;
				value = calc(a*H, b*H, c*H);
				ans = min(ans, value);
			}


			//2
			for (a = 1; a <= H - 1; a++) {
				b = (H - a) / 2;
				c = H - a - b;
				value = calc(a*W, b*W, c*W);
				ans = min(ans, value);
			}


			//3
			a = H / 2;
			b = H - a;
			for (int x = 1; x <= W - 1; x++) {
				value = calc((long long int)x*H, a*(W - x), b*(W - x));
				//if (x == 33333) { cout << "H*x= " << (long long int) H*x << endl; }
				ans = min(ans, value);
			}



			//4
			a = W / 2;
			b = W - a;
			for (int x = 1; x <= H - 1; x++) {
				value = calc((long long int) W*x, a*(H - x), b*(H - x));
				ans = min(ans, value);
			}


/*			i64 ret = H * W;
			for (int i = 0; i <= H; ++i) {
				ret = min(ret, sep(i * W, H - i, W));
			}
			for (int i = 0; i <= W; ++i) {
				ret = min(ret, sep(i * H, W - i, H));
			}

			if (ans != ret) {
				cout << "=====";
				cout << "H= " << H << " W= " << W << "  " << ans << " " << ret << endl;
			}

	}
	}*/

			cout << ans << endl;

	//system("pause");
	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char a = s1[0]-('a'-'A');
    char b = s2[0]-('a'-'A');
    char c = s3[0]-('a'-'A');
    cout << a << b << c << "\n";
    
	return 0;
}

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

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

    string s;
    cin >> s;
    int min_val = 999;
    for (unsigned long i = 0; i < s.length() - 2; ++i) {
        min_val = min(min_val, abs(753 - stoi(s.substr(i, 3))));
    }

    cout << min_val << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
ld dp[3005][3005];

int main()
{
	
	int n;
	cin>>n;
	ld coin[n];
	for(int i=0;i<n;i++) cin>>coin[i];
	
	for(int i=0;i<=n;i++)
	{
		dp[0][i] = 0.0;
	}
	dp[1][0] = 1.0*(1.0-coin[0]);
	dp[0][0]=1.0;
	for(int i=2;i<=n;i++)
	{
		
		dp[i][0] = 1.0*dp[i-1][0]*(1-coin[i-1]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			dp[i][j] = 1.0*(dp[i-1][j]*(1-coin[i-1])+1.0*dp[i-1][j-1]*coin[i-1]);
		}
	}

	ld ans=0.0;
	for(int i=(n+1)/2;i<=n;i++)ans=ans+dp[n][i];
	cout<<std::setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 139392
#include<bits/stdc++.h>
#define ll long long int
//ll a[1000000+9]= {0};
using namespace std;
int main ()
{
    ll a,b,c,x,y,p,mn,sum=0,mx;
    cin>>a>>b>>c>>x>>y;
    p=2*c;
    if (p<(a+b))
    {
        mn=min(x,y);
        mx=max(x,y);
        sum=mn*p;
        if(mn==y)
        {
            sum+=(x-mn)*a;
        }
        else
        {
            sum+=(y-mn)*b;
        }
        if(sum>(p*mx))
        {
            sum=p*mx;
        }
    }
    else
    {
        sum=(x*a)+(y*b);
    }
    cout<<sum<<endl;
    return 0;
}


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

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  mint dp[n + 1][s + 1] = {};
  dp[0][0] = mint(2).pow(n);
  rep(i, n) rep(j, s) {
    dp[i + 1][j] += dp[i][j];
    if(j + a[i] <= s) dp[i + 1][j + a[i]] += dp[i][j] / 2;
  }
  mint ans = 0;
  rep2(i, 1, n + 1) ans += dp[i][s];
  cout << ans << endl;
}

Measured memory_bytes: 73984
N,K,Q = map(int, input().split())
A = []
for i in range(Q):
    A.append(int(input()))
c = {i:0 for i in range(1,N+1)}
for i in A:
    c[i] += 1
P = [K-Q for _ in range(N)]
for i in range(N):
    P[i] += c[i+1]
for i in P:
    if i <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 63572
n = int(input())
rob = []
for i in range(n):
    x,l = map(int,input().split())
    rob.append([x-l,x+l])
rob.sort()
ans  = n
right = rob[0][1]
for i,[l,r] in enumerate(rob):
    if i == 0:
        continue
    if l < right:
        ans -= 1
        right = min(right,r)
    else:
        right = r
print(ans)

Measured memory_bytes: 20100
N = int(input())
Alist = list(map(int, input().split()))

hmax = Alist[0]
ans = 0
for n in range(1, N):
    if Alist[n] < hmax:
        ans += hmax - Alist[n]
    else:
        hmax = Alist[n]

print(ans)

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
    unsigned int FOR;
    asm("rdtsc" : "=A"(FOR));
    srand(FOR);
}

int n, a[11];

int gcd(int a, int b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int phi(int n) {
    int res = 1;
    for(int i = 2; 1ll * i * i <= n; i ++) {
        int mlt = 1;
        while(n % i == 0) {
            n /= i, mlt *= i;
        }
        res *= mlt - mlt / i;
    }
    if(n > 1)
        res *= n - 1;
    return res;
}

int main() {
    cin >> n;
    cout << phi(n) << '\n';
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin() (a).end()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

template<class T = int>
T in() { T x; cin >> x; return x; }

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int ans = 0, sub = 999;
  for (int i = 0; i < 5; i++) {
    int tmp = in(), m = tmp % 10;
    if (m == 0) {
      ans += tmp;
    } else if (m <= (sub % 10)) {
      if (sub < 999) {
        ans += sub + 10 - (sub % 10);
      }
      sub = tmp;
    } else {
      ans += tmp + (10-m);
    }
  }
  if (sub < 999) ans += sub;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
     
    using namespace std;
     
    string s;
     
    int get(char c)
    {
    	vector <int> pos;
     
    	pos.push_back(-1);
    	for (int i = 0; i < s.size(); ++i)
    		if (s[i] == c)
    			pos.push_back(i);
     
    	pos.push_back(s.size());
     
    	int ans = 0;
     
    	if (pos.size() == 2) return INT_MAX;
     
    	for (int i = 1; i < pos.size(); ++i)
    		ans = max(ans, pos[i] - pos[i - 1] - 1);
     
    	return ans;
    }
     
    int solve()
    {
    	int ans = INT_MAX;
    	for (char c = 'a'; c <= 'z'; ++c) ans = min(ans, get(c));
    	return ans;
    }
     
    int main()
    {
    	cin >> s;
    	cout << solve() << '\n';
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void solve()
{
	int s,w;
  	cin>>s>>w;
  	if(w>=s) cout<<"unsafe";
      else cout<<"safe";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
return 0;
}

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

string goal;

int dfs(string s,int c) {
    if(s == goal) return 0;
    if(c == s.length()) return 1<<29;
    if(s[c] == goal[c]) return dfs(s,c+1);
    int res = 1<<29,rot = s[c]-goal[c];
    for(int i=1; i<=(s.length()-c); ++i) {
        s[c+i-1] -= rot;
        if(s[c+i-1] < '0') s[c+i-1] += 10;
        if(s[c+i-1] > '9') s[c+i-1] -= 10;
        res = min(res, dfs(s,c+1) + 1);
    }
    return res;
}

int main() {
    int k;
    string s;
    while(cin>>k,  k) {
        cin>>s>>goal;
        cout<<dfs(s,0)<<endl;
    }
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 1;

int n;
int a[maxN][4];
int dp[maxN][4];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for1(i, n)
    {
        for1(j, 3)
        {
            cin >> a[i][j];
        }
    }
    for1(i, n)
    {
        for1(j, 3)
        {
            dp[i][j] = 0;
            for1(k, 3)
            {
                if (j != k)
                {
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
                }
            }
        }
    }
    cout << *max_element(dp[n] + 1, dp[n] + 4);
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <complex>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
long long mod = 1e9 + 7;
long long inved(long long a){
    long long x = 1, y = 0, u = 0, v = 0, k = a, l = mod;
    long long tmp1, tmp2, tmp3;
    while (l != 0){
        tmp1 = x, tmp2 = y;
        x = u, y = v;
        u = tmp1 - u * (k / l), v = tmp2 - v * (k / l);
        tmp3 = k;
        k = l;
        l = tmp3 % l;
    }
    return (x + mod) % mod;
}
int main(void){
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i=0;i<N;i++){
        cin >> A[i];
    }
    cpp_int L = (cpp_int)A[0];
    cpp_int x, y, tmp;
    for (int i=1;i<N;i++){
        x = L, y = (cpp_int)A[i];
        while (y != 0){
            tmp = x;
            x = y;
            y = tmp % y;
        }
        y = A[i] / x;
        L *= y;
    }
    L %= mod;
    long long S = 0LL;
    for (int i=0;i<N;i++){
        S += inved(A[i]);
        S %= mod;
    }
    cout << (L*S)%mod << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int A[100000], n;

int bS(int k);

int main(){
  int i, j, q, k, sum=0;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
  }
  
  scanf("%d", &q);
  for(j=0;j<q;j++){
    scanf("%d", &k);
    if(bS(k)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}
  
  
int bS(int k){
  int l = 0;
  int r = n;
  int m;
  while(l < r){
    m=(l + r) / 2;
    if(k == A[m])return 1;
    if(k > A[m]) l = m + 1;
    else if(k < A[m]) r = m;
  }
  return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>

void mergeSort(int numbers[], int array_size);
void m_sort(int numbers[], int temp[], int left, int right);
void merge(int numbers[], int temp[] ,int left, int mid, int right);

void mergeSort(int numbers[],int array_size)
{
    int temp[array_size];
    for(int i = 0;i < array_size; i++)
    {
        temp[i] = 0;
    }
    m_sort(numbers, temp, 0, array_size - 1);
}

void m_sort(int numbers[], int temp[], int left, int right)
{
    int mid;

    if(right > left)
    {
        mid = (right + left) / 2;
        m_sort(numbers, temp, left, mid);
        m_sort(numbers, temp, mid + 1, right);

        merge(numbers, temp,left, mid+1, right);
    }
}

void merge(int numbers[], int temp[] ,int left, int mid, int right)
{
    int i, left_end, num_elements, tmp_pos;

    left_end = mid - 1;
    tmp_pos = left;
    num_elements = right - left + 1;

    while((left <= left_end) && (mid <= right))
    {
        if(numbers[left] <= numbers[mid])
        {
            temp[tmp_pos] = numbers[left];
            tmp_pos++;
            left++;
        }
        else
        {
            temp[tmp_pos] = numbers[mid];
            tmp_pos++;
            mid++;
        }
    }

    while(left <= left_end)
    {
        temp[tmp_pos] = numbers[left];
        left++;
        tmp_pos++;
    }

    while(mid <= right)
    {
        temp[tmp_pos] = numbers[mid];
        mid++;
        tmp_pos++;
    }

    for(i=0; i <= num_elements; i++)
    {
        numbers[right] = temp[right];
        right--;
    }
}

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    
    if(m == 1 || n > m)
    {
        puts("0");
        return 0;
    }
    
    int x[m],y[m-1];
    for(int i = 0; i < m; i++)
    {
        scanf("%d",&x[i]);
    }
    
    mergeSort(x,m);
  
    for(int i = 0; i < m - 1; i++)
    {
        y[i] = x[i+1] - x[i];
    }
    
    
    mergeSort(y,m-1);
    
    int ans = x[m-1] - x[0];
    int count = m-2;
    for(int i = 0; i < n - 1; i++)
    {
        ans -= y[count];
        count--;
    }
    
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1280
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
const ll MAX_N = 1e5;
ll N,M;
bool visited_h[MAX_N]; // 各頂点が通過済みか
bool visited_l[MAX_N]; // 各頂点が通過済みか
vector<ll> human[MAX_N]; // graph[人番号][言語番号]
vector<ll> lang[MAX_N]; // graph[言語番号][人番号]
 
// 現在位置(x)
void dfs(ll i, bool mode_h){
	if (mode_h){ // 人番号が入力
		visited_h[i] = true; // 今いるところをtrueに置き換える
		REP(j,human[i].size()){
			ll target_l = human[i][j];
			if (visited_l[target_l]==false) dfs(target_l, false);
		}
	}
	else{
		visited_l[i] = true; // 今いるところをtrueに置き換える
		REP(j,lang[i].size()){
			ll target_h = lang[i][j];
			if (visited_h[target_h]==false) dfs(target_h, true);
		}
	}
}

 
int main() {
	// 入力
	cin >> N>>M;
	REP(i,N){
		ll K;cin>>K;
		REP(j,K){
			ll L;cin>>L;L--;
			human[i].pb(L);
			lang[L].pb(i);
		}
	}
 
	// 解法
	REP(i,N) visited_h[i] = false; // 訪問済み判定初期化
	REP(i,M) visited_l[i] = false; // 訪問済み判定初期化
	dfs(0, true); // DFSで連結判定
	// REP(i,N) printf("%lld %lld\n", i, visited_h[i]);
	bool ans = true;
	REP(i,N) if (visited_h[i]==false) ans = false;
	
	// 出力
	if (ans) printf("YES\n");
	else printf("NO\n");
 
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int X;
  cin >> X;

  int cnt = 0;
  while (true) {
    cnt++;
    if((cnt * X) % 360 == 0) break;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
const int maxn = 101;
const int maxq = 1000000;
const int tomod = 1000000007;
int n, k;
ll dp[maxn][maxq];/*, pf[maxn][maxq];*/
int v[maxq], vn;
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	{
		set<int> val; 
		for(int i = 1;i * i <= n;++i)val.insert(i), val.insert(n/i);
		for(auto &i : val)v[++vn] = i;
	}
	fill(dp[0], dp[0] + maxq, 1);
	for(int i = 1;i <= k;++i){
		for(int j = 1;j <= vn;++j){
			dp[i][j] = ((v[j]-v[j-1]) * (dp[i-1][lower_bound(v+1, v+1+vn, n/v[j]) - v]) % tomod + dp[i][j-1]) % tomod;
		}
	}
	cout << dp[k][vn] << '\n';
}

Measured memory_bytes: 263552
object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val l = List.fill(3)(sc.nextInt)
  val a, b, c, d = sc.nextInt

  val left = a + b
  val right = c + d
  val ans =
    if (left > right) "Left"
    else if (left == right) "Balanced"
    else "Right"

  println(ans)
}

Measured memory_bytes: 25528
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={1,-1,0,0};
    static int dy[]={0,0,1,-1};

    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

//        int n=sc.nextInt();
        int h=sc.nextInt();
        int w=sc.nextInt();
        int k=sc.nextInt();

        int dp[][]=new int[h+1][w+2];
        dp[0][0]++;
        int d[]=new int[w];
        fill(d,1000);
        for (int i = 1; i < dp.length; i++) {
lp:			for (int t = 0; t < 1<<(w-1); t++) {
				for (int z = 0; z < w-1; z++) {
					if((t>>z)%2==1 && (t>>(z+1))%2==1)continue lp;
				}				
				for (int z = 0; z < w-1; z++) {
					if((t>>z)%2==1) {
						dp[i][z]+=dp[i-1][z+1];
						dp[i][z+1]+=dp[i-1][z];
						d[z]=t;
						d[z+1]=t;
						if(dp[i][z]>=mod)dp[i][z]-=mod;
						if(dp[i][z+1]>=mod)dp[i][z+1]-=mod;

					}
				}
				for (int z = 0; z < w; z++) {
					if(d[z]!=t)dp[i][z]+=dp[i-1][z];
					if(dp[i][z]>=mod)dp[i][z]-=mod;
				}
				//db(i,t,dp[i]);
			}
		}
        
        out.println(dp[h][k-1]);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

typedef long long int ll;
int main(){
    init;
    ll N,W,i,j,k,l;
    cin>>N>>W;
    ll w[N+1],v[N+1];
    for(i=1;i<=N;i++)
        cin>>w[i]>>v[i];
    ll dp[N+1][W+1];
    memset(dp,0,sizeof(dp));

    for(i=1;i<=N;i++){
        for(j=1;j<=W;j++){
            if(j >= w[i]){
                dp[i][j] = max(dp[i-1][j - w[i]] + v[i] , dp[i-1][j]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int f[n];
	f[0] = 0;
	for(int i=1; i<n; i++){
		int u = 1e9;
		for(int j=1; j<=k; j++){
			if(i-j<0) break;
			u = min(u,f[i-j]+abs(h[i]-h[i-j]));
		}
		f[i] = u;
	}
	cout<<f[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<char,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  string s;cin>>s;
  int ans=INT_MAX;
  vector<int> wList(n);int wCnt=0;
  vector<int> eList(n);int eCnt=0;
  rep(i,n){
    if(s[i]=='W'){
      wCnt++;
    }
    wList[i]=wCnt;

    if(s[n-1-i]=='E'){
      eCnt++;
    }
    eList[n-1-i]=eCnt;
  }
  rep(i,n){
    ans=min(wList[i]+eList[i]-1,ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');
            string[] b = Console.ReadLine().Split(' ');
            string[] c = Console.ReadLine().Split(' ');

            int satisfy = 0;

            for (int i = 0; i < N; i++)
            {
                if (i == 0)
                {
                    satisfy += int.Parse(b[int.Parse(a[i]) - 1]);
                }
                else if (int.Parse(a[i]) - int.Parse(a[i - 1]) != 1)
                {
                    satisfy += int.Parse(b[int.Parse(a[i]) - 1]);
                }
                else
                {
                    satisfy += int.Parse(b[int.Parse(a[i]) - 1]) + int.Parse(c[int.Parse(a[i]) - 2]);
                }
            }

            Console.WriteLine(satisfy);
        }
    }
}


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

const int MAXN = 100;
int N;
int ioNum[MAXN];

bool isOK() {
  int odd = 0;
  int pos[2] = {0, 0};
  for(int i = 0; i < N; ++i) {
    if(ioNum[i] % 2) {
      if(odd == 2) return false;
      pos[odd++] = i;
    }
  }
  return pos[0] + pos[1] == 1;
}

int main() {
  while(1) {
    fill(ioNum, ioNum+MAXN, 0);
    N = 0;
    while(1) {
      int a, b;
      if(cin >> a >> b) ; else return 0;
      if(a == 0 && b == 0) break;
      N = max(N, max(a, b));
      --a; --b;
      ++ioNum[a];
      ++ioNum[b];
    }
    if(isOK()) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#define MOD 1000000007
#define inf (1<<30)
typedef long long ll;
using namespace std;

int main(){
  priority_queue<ll,vector<ll>,greater<ll>> P;
  priority_queue<ll> Q;
  int n;
  cin>>n;
  ll sum1=0,sum2=0;
  ll a[3*n+1]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum1+=a[i];
    P.push(a[i]);
  }
  for(int i=n+1;i<=2*n;i++){
    cin>>a[i];
  }
  for(int i=2*n+1;i<=3*n;i++){
    cin>>a[i];
    sum2+=a[i];
    Q.push(a[i]);
  }
  ll l[2*n+1]={};
  ll r[2*n+1]={};
  l[n]=sum1;
  r[2*n]=sum2;
  for(int i=n+1;i<=2*n;i++){
    ll u=P.top();
    if(u<a[i]){
      l[i]=l[i-1]+a[i]-u;
      P.pop();
      P.push(a[i]);
    }else{
      l[i]=l[i-1];
    }
  }
  for(int i=2*n-1;i>=n;i--){
    ll v=Q.top();
    if(v>a[i+1]){
      r[i]=r[i+1]+a[i+1]-v;
      Q.pop();
      Q.push(a[i+1]);
    }else{
      r[i]=r[i+1];
    }
  }
  ll ans=l[n]-r[n];
  for(int i=n;i<=2*n;i++){
    ans=max(ans,l[i]-r[i]);
    //cout<<l[i]<<" "<<r[i]<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7412
import numpy as np
lst = []
nums = []
for _ in range(3):
    l = []
    l = list(map(int, input().split()))
    lst.append(l)
    array = np.array(lst)
 
n = int(input())
for _ in range(n):
    nums.append(int(input()))

for h in range(3):
    for w in range(3):
        if array[h][w] in nums:
            array[h][w] = 0

i = 0
for h in range(3):
    if sum(array[:, h]) == 0:
        i = 1
for w in range(3):
    if sum(array[w]) == 0:
        i = 1
if sum(np.diag(np.fliplr(array))) == 0:
    i = 1
if sum(np.diag(array)) == 0:
    i = 1

if i == 1:
    print("Yes")
else:
    print('No')


Measured memory_bytes: 12500
A,B,C,X,Y = map(int,input().split())
if 2*C >= A + B:
    ans = A*X+B*Y
else:
    n_c = 2*min(X,Y)
    #print(n_c)
    if X > Y:
        ans = min(n_c*C+A*(X-n_c/2),C*2*X)
    else:
        ans = min(n_c*C+B*(Y-n_c/2),C*2*Y)
print(int(ans))


Measured memory_bytes: 9184
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int R_rate = scan.nextInt();

		if (R_rate < 1200) {
			System.out.println("ABC");
			return;
		}

		if (R_rate < 2800) {
			System.out.println("ARC");
			return;
		}

		System.out.println("AGC");

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27084
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename 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...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}
const int N=10000;


int main()
{
  IOS
   ll n;
   cin>>n;
   ll a[n][n];
   ll dp[1<<n];
   ll sum[1<<n];
   memset(dp,0,sizeof(dp));
   memset(sum,0,sizeof(sum));
   for(ll i=0;i<n;i++)
   {
    for(ll j=0;j<n;j++)
        cin>>a[i][j];
   }

   for(ll i=0;i<(1<<n);i++)
        {
            for(ll j=0;j<n;j++)
             for(ll k=0;k<n;k++)
                if((i>>j&1LL)&&((i>>k)&1LL))
                    sum[i]+=a[j][k];
            sum[i]>>=1;
        }

        for(ll i=0;i<1LL<<n;i++)
        {   
            for(ll j=i;j;j=(j-1)&i)
                dp[i]=max(dp[i],dp[i^j]+sum[j]);
        }
        cout<<dp[(1LL<<n)-1];
  
 
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;



int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    int x,y;
    x= c-a;
    y=d-b;
    REP(i,x) cout << 'R';
    REP(i,y) cout << 'U';
    REP(i,x) cout << 'L';
    REP(i,y) cout << 'D';
    cout << 'D';
    REP(i,x+1) cout << 'R';
    REP(i,y+1) cout << 'U';
    cout << 'L';
    cout << 'U';
    REP(i,x+1) cout << 'L';
    REP(i,y+1) cout << 'D';
    cout << 'R'<<endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var s = "abc";
        var ct = new[] { 0, 0, 0 };
        for (var i = 0; i < 3; i++)
            ct[i] = str.Count(c => c == s[i]);
        Array.Sort(ct);
        WriteLine((ct[2] - ct[0]) <= 1 ? "YES" : "NO");
    }
}


Measured memory_bytes: 13268
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int m, n, k, t;
    cin >> n >> m;

    map<int,int> mp;

    REP(_,n){
        cin >> k;
        REP(i,k){
            cin >> t;
            mp[t]++;
        }
    }

    int ans = 0;
    REP(i,m){
        if (mp[i+1] == n) ans++;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read(){
	ll dat = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) dat = (dat<<3) + (dat<<1) + (ch ^ 48),ch = getchar();
	return w ? -dat : dat;
}

ll l,n,ans;
ll dat[200005];
ll s[200005];
void solve()
{
	for(ll i=2;i<=n;i++)
	{
		s[i]=s[i-1]+(dat[i]-dat[i-1])*i;
	}
	for(ll i=1;i<=n;i++)
	{
		ll sum=dat[i];
		sum+=(dat[i]+l-dat[n])*(n-i);
		if((n-i)%2==0)
		{
			ll tmp=(n+i)/2;
			if(i+1<=tmp)
			{
				sum+=(2*tmp+1)*(dat[tmp]-dat[i])-2*(s[tmp]-s[i]);
			}
			if(tmp+2<=n)
			{
				sum+=2*(s[n]-s[tmp+1])-2*(tmp+1)*(dat[n]-dat[tmp+1]);
			}
		}
		else
		{
			ll tmp=(n+i)/2;
			if(i+1<=tmp)
			{
				sum+=2*(tmp+1)*(dat[tmp]-dat[i])-2*(s[tmp]-s[i]);
			}
			if(tmp+2<=n)
			{
				sum+=2*(s[n]-s[tmp+1])-(2*(tmp+1)+1)*(dat[n]-dat[tmp+1]);
			}
		}
		ans=max(ans,sum);
	}
}
int main() 
{
	cin>>l>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>dat[i];
	}
	solve();
	for(ll i=1;i<=n;i++)
	{
		dat[i]=l-dat[i];
	}
	reverse(dat+1,dat+n+1);
	solve();
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3456
use std::io::Read;

fn main() {
    let mut buf = String::new();
    let mut stdin = std::io::stdin();
    stdin.read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut curr: usize = 1;
    for i in 0..n {
        let brick = iter.next().unwrap().parse::<usize>().unwrap();
        if brick == curr {
            curr += 1;
        }
    }
    let n_break = n+1 - curr;
    if n_break == n {
        println!("-1");
    } else {
        println!("{}", n+1 - curr);
    }
}


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

int main(){
    int N,M;
    cin >> N;
    vector<string>s(N);
    set<string> word;
    for(int i = 0; i < N; i++){
        cin >> s.at(i);
        word.insert(s.at(i));
    }
    cin >> M;
    vector<string>t(M);
    for(int i = 0; i < M; i++){
        cin >> t.at(i);
    }
    int max = 0;
    for(string w : word){
        int score = 0;
        for(int i = 0; i < N; i++){
            if(w == s.at(i))score++;
        }
        for(int i = 0; i < M; i++){
            if(w == t.at(i))score--;
        }
        if(max < score)max = score;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


int R, C;
vector<string> s;

bool isin(int r, int c) {
  return 0 <= r && r < R && 0 <= c && c < C;
}

int dr[] = {0, 1};
int dc[] = {1, 0};

const int INF = 1001001001;
const int MAX_N = 55;
int dist[MAX_N][MAX_N];

atcoder::mcf_graph<ll, ll> graph;

void bfs(int sr, int sc) {
  REP(i, MAX_N) REP(j, MAX_N) dist[i][j] = INF;
  queue<int> q;
  q.push(sr);
  q.push(sc);
  dist[sr][sc] = 0;
  while (!q.empty()) {
    int r = q.front(); q.pop();
    int c = q.front(); q.pop();

    REP(i, 2) {
      int nr = r + dr[i];
      int nc = c + dc[i];
      if (isin(nr, nc) && s[nr][nc] != '#') {
        if (dist[nr][nc] > dist[r][c] + 1) {
          dist[nr][nc] = dist[r][c] + 1;
          q.push(nr);
          q.push(nc);
        }
      }
    }
  }

  // REP(i, R) {
  //   REP(j, C) {
  //     cout << (dist[i][j] == INF ? -1 : dist[i][j]) << " ";
  //   }
  //   cout << endl;
  // }
  // cout << ".." << endl;
}

int main2() {
  R = nextLong();
  C = nextLong();
  s = vector<string>(R);
  REP(i, R) cin >> s[i];
  const ll L = 1e10;

  graph = atcoder::mcf_graph<ll, ll> (100 + R * C + 2);

  int start = 100 + R * C;
  int end = 100 + R * C + 1;

  int o = 0;
  REP(i, R) REP(j, C) if (s[i][j] == 'o') {
    bfs(i, j);

    REP(ii, R) REP(jj, C) if (dist[ii][jj] < INF) {
      graph.add_edge(o, 100 + ii * C + jj, 1, L - dist[ii][jj]);
    }
    graph.add_edge(start, o, 1, 0);
    o++;
  }

  REP(i, R) REP(j, C) {
    graph.add_edge(100 + i * C + j, end, 1, 0);
  }

  auto res = graph.flow(start, end);

  ll ans =  o * L - res.second;
  cout << ans << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 8932
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];
int v[maxn],ans;

int main()
{
	scanf("%s",s+1); int len=strlen(s+1);
	for(int i=len;i>=1;i--)
	{
		v[i]=v[i]+(s[i]-'0');
		if(v[i]==10) v[i-1]++;
		else if(v[i]>5) v[i-1]++,ans+=(10-v[i]);
		else if(v[i]<5) ans+=v[i];
		else
		{
			if(s[i-1]-'0'>=5) ans+=5,v[i-1]++;
			else ans+=5;
		}
	}
	if(v[0]) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120