akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define min(a,b) a>b?b:a
#define Inf 0x3f3f3f3f

int n,m;
char str[105][105];
int dp[105][105];
		
int main(){
    scanf("%d%d%*c",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",str[i]+1);
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++)
            dp[i][j]=Inf;
    dp[0][1]=dp[1][0]=0;
    for(int i=1;i<=n;i++) 
		for(int j=1;j<=m;j++){
            if(str[i][j]=='#')
                dp[i][j]=min(dp[i-1][j]+(str[i][j]!=str[i-1][j]), dp[i][j-1]+(str[i][j]!=str[i][j-1]));
            else
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
        }
    printf("%d\n",dp[n][m]);
	
    return 0;
}

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

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

int main()
{
	int n,i,a,cnt;
	n=read();
	cnt=0;
	for (i=1;i<=n;i++)
	{
		a=read();
		while ((a&1)==0) cnt++,a>>=1;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long f(long long N, long long X) {
    // zal: N > X
    if(N % X == 0) return 2 * N - X;
    return (N / X) * 2 * X + f(X, N % X);
}
 
int main() {
	long long N, X;
	cin >> N >> X;
	cout << f(N - X, X) + N << endl;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int disp[10];
char out[10];
char sta[10];
char stb[10];
int a = -1, b = -1;
int inde = 0;
void npermute(int level, int tol){
	if(level == tol){
		inde++;
		out[tol] = 0;
		if(a == -1){
			if(strcmp(out, sta) == 0) a = inde;
		}
		if(b == -1){
			if(strcmp(out, stb) == 0) b = inde;
		}
	}
	for(int i = 1; i <= tol; ++i){
		if(disp[i]){
			out[level] = i + '0';
			disp[i]--;
			npermute(level +1, tol);
			disp[i]++;
		}
	}
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf(" %c", &sta[i]);
	}
	sta[n] = 0;
	for(int i = 0; i < n; ++i){
		scanf(" %c", &stb[i]);
	}
	stb[n] = 0;
	disp[0] = 0;
	for (int i = 1; i <= n; ++i)
		disp[i] = 1;
	npermute(0, n);
	printf("%d\n", abs(a-b));
}

Measured memory_bytes: 256
#if 1

#include <bits/stdc++.h>
using namespace std;
int n;
int c[25];
int v[25];

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> v[i];
    }
    for(int i = 1;i <= n;i++)
    {
        cin >> c[i];
    }
    int ans = 0,cnt1,cnt2;
    for(int i = 0;i < (1 << n);i++)
    {
        cnt2 = 0;
        cnt1 = 0;
        for(int j = 1;j <= n;j++)
        {
            if(i & (1 << (j-1)))
            {
                cnt1 += v[j];
                cnt2 += c[j];
            }
        }
        ans = max(ans,cnt1-cnt2);
    }
    cout << ans;
}

#endif // 1++

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

a, v = map(int, readline().split())
b, w = map(int, readline().split())
t = int(readline())

d = abs(b - a)

d = d - (v - w)*t
if d <= 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9176
#include<bits/stdc++.h>  
using namespace std;  
  
#define fast ios::sync_with_stdio(false);cin.tie(NULL)  
#define fi first  
#define se second  
#define all(v) (v).begin(),(v).end()  
#define pb push_back  
#define eb emplace_back
#define em emplace
#define mp make_pair
  
typedef long long ll;  
typedef pair<int,int> pii;  
typedef pair<ll,ll> pll;  
const long long INF = 1e18;  
const int inf = 1e9;

int n, k;
int ans;

int tree[1200010];

void update(int node, int s, int e, int i, int x) {
	if(s == e) {
		tree[node] = max(tree[node], x);
		return;
	}

	int m = s + e >> 1;
	if(i <= m) update(node*2, s, m, i, x);
	else update(node*2+1, m+1, e, i, x);

	tree[node] = max(tree[node*2], tree[node*2+1]);
}

int cal(int node, int s, int e, int l, int r) {
	if(r < s || e < l) return 0;
	if(l <= s && e <= r) return tree[node];

	return max(cal(node*2, s, (s+e)/2, l, r), cal(node*2+1, (s+e)/2+1, e, l, r));
}

int main() {
	fast;

	cin >> n >> k;

	for(int i=1; i<=n; i++) {
		int a;
		cin >> a;

		int x = cal(1, 0, 300000, max(a - k, 0), min(a + k, 300000)) + 1;
		update(1, 0, 300000, a, x);

		ans = max(ans, x);
	}

	cout << ans;
}

Measured memory_bytes: 7756
import java.util.Scanner;

class Main{
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();	
		sc.close();
		
		System.out.println(subAbs(A, B, C, D));
	}
	
	public static int subAbs(int A, int B, int C, int D){
		int sub = Math.min(B, D) - Math.max(A, C);
		if( sub > 0) {
			return sub;
		}else {
			return 0;
		}
	}
}

Measured memory_bytes: 21972
#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 (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using T = tuple<int, int>;
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		static int dp[110][110];
		memset(dp, 0x3f, sizeof(dp));
		static int D[110][110], E[110][110];
		memset(D, 0x3f, sizeof(D));
		memset(E, 0x3f, sizeof(E));
		rep(i, 0, M) {
			int a, b, d, e; cin >> a >> b >> d >> e;
			a--, b--;
			D[a][b] = D[b][a] = d;
			E[a][b] = E[b][a] = e;
		}
		queue<T> q;
		q.emplace(0, L);
		dp[0][L] = 0;
		while (q.size()) {
			int u, l; tie(u, l) = q.front(); q.pop();
			rep(v, 0, N) {
				if (D[u][v] == INF)continue;
				if (D[u][v] <= l) {
					if (chmin(dp[v][l - D[u][v]], dp[u][l])) {
						q.emplace(v, l - D[u][v]);
					}
				}
				if (chmin(dp[v][l], dp[u][l] + E[u][v])) {
					q.emplace(v, l);
				}
			}
		}
		int ans = INF;
		rep(i, 0, L + 1) {
			chmin(ans, dp[N - 1][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3404
#include <iostream>

int main() {
	int n = 0; 
	long long ans = 0;
	long long l[86];
	l[0] = 2, l[1] = 1;
	std::cin >> n;

	for (int i = 2; i <= n; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
		
	ans = l[n];
	std::cout << ans << std::endl;

}

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

int main() {
	
	int x,y,a,b,c;
	cin >> x>>y>>a>>b>>c;
	vector<int>p(a), q(b), r(c);
	vector<pair<int, char>> v;
	for(auto &i:p) {
		cin >> i;
		v.push_back({i,'r'});
	}
	for(auto &i:q) {
		cin >> i;
		v.push_back({i,'g'});
	}
	for(auto &i:r) {
		cin >> i;
		v.push_back({i,'t'});
	}
	sort(v.rbegin(),v.rend());
	
	int rn{},gn{},tn{};
	int64_t cnt{};
	for(int i=0; i<v.size(); i++){
		auto vl = v.at(i).first;
		auto co = v.at(i).second;
		if(rn<x&&rn+gn+tn<x+y&&co=='r'){
			cnt += vl;
			rn++;
		}
		if(gn<y&&rn+gn+tn<x+y&&co=='g'){
			cnt += vl;
			gn++;
		}
		if(rn+gn+tn<x+y&&co=='t'){
			cnt += vl;
			tn++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 7664
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[3000000];
string st;
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
//     ans=0;
     //cin>>TESTS;
   //  memset(dpt,0,sizeof(dpt));memset(dput,0,sizeof(dput));
    // memset(dsu1,0,sizeof(dsu1));
     while(TESTS--)
     {
         bool cont=false;
         cin>>n;
         cin>>st;
         rep(i,0,n-1) if (st[i]=='2')cont=true;
         rep(i,0,n-1){
             if (cont){
                (st[i]=='1'||st[i]=='3')?arr[i]=1:arr[i]=0;
             }
             else (st[i]=='1')?arr[i]=1:arr[i]=0;
            // cout<<arr[i]<<" ";
         }
         lld change=0;
         rep(i,0,n-1) if (arr[i]&&((n-1)&i)==i)change^=1;
         (change)?((cont)?cout<<1:cout<<2):cout<<0;
     }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool b = true;
  for (int i = 0; i < N / 2 + 1; i++) {
    if (S.at(i) != S.at(N - 1 - i)) {
      b = false;
    }
  }
  for (int i = 0; i < N / 4; i++) {
    if (S.at(i) != S.at((N - 3) / 2 - i)) {
      b = false;
    }
  }
  if (S.substr(0, (N - 1) / 2) != S.substr((N + 1) / 2)) {
    b = false;
  }
  if (b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int pt = 0, px = 0, py = 0;
  for (int i = 0; i < n; i ++) {
    int t, x, y;
    cin >> t >> x >> y;
    int dx = abs(x - px);
    int dy = abs(y - py);
    int dt = abs(t - pt);
    if ((dx + dy) % 2 != dt % 2 || dx + dy > dt) {
      return !puts("No");
    }
    px = x, py = y, pt = t;
  }
  return !puts("Yes");
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)        (abs((a)-(b)) < EPS)
#define CILING(a, b)    (((a)+(b)-1LL)/(b))

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

int main() {
    int h, w;cin >> h >> w;
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans[100][100];
    int now = 0;
    for(int k=0;k<h*w;k++){
        int i = k/w;
        int j = (k/w%2 == 0 ? k%w : w - k%w - 1);
        ans[i][j] = now;
        a[now]--;
        if(a[now] == 0) now++;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << ans[i][j]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
from collections import deque

N = int(input())
L = [deque([int(i)-1 for i in input().split()]) for i in range(N)]

q = deque(range(N))
d = [0 for i in range(N)]
pairs = [-1 for i in range(N)]
while q:
    a = q.popleft()  # qの左端の選手のindexをpopleft
    if len(L[a]) == 0:
        continue
    b = L[a].popleft()

    if pairs[b] == a:  # bのリクエストがaなら
        d[a] = d[b] = max(d[a], d[b]) + 1
        q.append(a)
        q.append(b)
    else:
        pairs[a] = b
print(max(d) if not any(L) else -1)


Measured memory_bytes: 35956
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}

	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		if (p.at(i) > p.at(i - 1) && p.at(i) < p.at(i + 1)) {
			ans++;
		}
		if (p.at(i) < p.at(i - 1) && p.at(i) > p.at(i + 1)) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
from scipy.special import comb
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]

c=C(l)
ans=0

for v in c.values():
  ans+=comb(v, 2, exact=True)
print(ans)

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

typedef struct Card{
    char suit;
    char value;
} card;

void selection(card a[],int n){
    for(int i = 0;i<n;i++){
        int minj=i;
        for(int j=i+1;j<n;j++){
            if(a[minj].value>a[j].value)minj=j;
        }
        swap(a[minj],a[i]);
    }
}

void bubble(card a[],int n){
    for(int i=0;i<n-1;i++){
        for(int j=n-1;j>0;j--){
            if(a[j].value<a[j-1].value){
                swap(a[j],a[j-1]);
            }
        }
    }
}

void print(card a[],int n){
    for(int i=0;i<n;i++){
        cout<<a[i].suit<<a[i].value;
        if(i!=n-1)cout<<' ';
    }
    cout<<endl;
}

bool isStable(card a1[],card a2[],int n){
    for(int i =0;i<n;i++){
        if(a1[i].suit != a2[i].suit)return false;
    }
    return true;
}

int main(void){

    int n;
    cin >> n;

    card c1[n],c2[n];
    for(int i=0;i<n;i++)cin>>c1[i].suit>>c1[i].value;
    for(int i=0;i<n;i++)c2[i]=c1[i];

    bubble(c1,n);
    selection(c2,n);

    print(c1,n);
    cout<<"Stable"<<endl;
    print(c2,n);
    if(isStable(c1,c2,n))cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

    template <class T, class... Args>
    void impl(T&& v, Args&&... args)
    {
        cout << std::forward<T>(v) << ' ';
        impl(std::forward<Args>(args)...);
    }
    template <class T>
    void impl(T&& v)
    {
        cout << std::forward<T>(v);
    }

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class... Args>
    void operator()(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
        cout << '\n';
    }
    template <class... Args>
    void noreturn(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
        cout << '\n';
    }
};

void prog()
{
    input in;
    output out;

    auto h = in.read<std::uint64_t>();
    std::uint64_t n = 1, res = 0;
    while (h != 0) {
        h /= 2;
        res += n;
        n *= 2;
    }
    out(res);
}

int main()
{
    prog();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int main() {
	ll n;
	slld(n);
	if(n&1) pd(0);
	else{
		ll ans=0;
		n/=2;
		while(n>0){
			n/=5;
			ans+=n;
		}
		plld(ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int res = 0;
	int v[n], c[n];
	for(int i = 0; i < n; i++) cin >> v[i];
	for(int i = 0; i < n; i++) cin >> c[i];
	for (int i = 0; i < n; i++)
	{
		res += max(v[i] - c[i], 0);
	}
	cout << res << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4) << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())
S = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    s = input()
    S[s] = S[s] + 1

for a in S:
    print(a + " x " + str(S[a]))


Measured memory_bytes: 9172
#include<iostream>
#include<vector>
#include<algorithm>
#define all(c) (c).begin(),(c).end()

using namespace std;

int main(void){

  int m,nmin,nmax;

  while(cin >> m >> nmin >> nmax, m){
    vector<int>v(m);
    for(int i=0;i<m;i++)cin >> v[i];
    sort(all(v),greater<int>());
    int gap = 0, ans = 0;
    for(int i=nmax;i>=nmin;i--){
      if(v[i-1]-v[i] > gap)gap = v[i-1]-v[i], ans = i;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    int sum = 0;
    if (x == 1) sum += 300000;
    else if (x == 2) sum += 200000;
    else if (x == 3) sum += 100000;

    if (y == 1) sum += 300000;
    else if (y == 2) sum += 200000;
    else if (y == 3) sum += 100000;

    if (x == 1 && y == 1) sum += 400000;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#!/bin/usr/python

A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

x,y = [int(i) for i in input().split()]

if x in A and y in A or x in B and y in B or x in C and y in C:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a, b;
  int A1, B1;
  cin >> a >> b;
  if(a == 'A') A1 = 10;
  else if(a == 'B') A1 = 11;
  else if(a == 'C') A1 = 12;
  else if(a == 'D') A1 = 13;
  else if(a == 'E') A1 = 14;
  else if(a == 'F') A1 = 15;
  if(b == 'A') B1 = 10;
  else if(b == 'B') B1 = 11;
  else if(b == 'C') B1 = 12;
  else if(b == 'D') B1 = 13;
  else if(b == 'E') B1 = 14;
  else if(b == 'F') B1 = 15;
  if(A1 > B1) cout << ">" << endl;
  else if(A1 < B1) cout << "<" << endl;
  else cout << "=" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) xmax = x; return true;
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) xmin = x; return true;
    return false;
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll n, k; cin >> n >> k;
    vector<ll> x(n);
    FOR(i, 0, n) cin >> x.at(i);

    ll sum = 0;
    FOR(i, 0, n) {
        sum += 2 * min(x[i], k - x[i]);
    }
    cout << sum << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> dp(n, 1 << 30);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; i + j < n && j <= k; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;	
}

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

using namespace std;

typedef long long LL;
typedef pair<LL,LL>PII;

const int N=2050;

int n;
LL dp[N][N];
PII p[N];

LL solve(int idx,int mi,int mx)
{
	if(idx>n) return 0;
	if(dp[idx][mi]!=-1) return dp[idx][mi];
	LL op1=solve(idx+1,mi+1,mx)+(LL)p[idx].first*abs(p[idx].second-mi);
	LL op2=solve(idx+1,mi,mx-1)+(LL)p[idx].first*abs(p[idx].second-mx);
	return dp[idx][mi]=max(op1,op2);
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>p[i].first;
		p[i].second=i;
	}
	
	sort(p+1,p+1+n);
	for(int i=1;i<=n/2;i++) {
		swap(p[i],p[n-i+1]);
	}
	memset(dp,-1,sizeof dp);
	cout<<solve(1,1,n);
 	return 0;
} 

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


int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  ll tmp = 1;
  while (N > 0) {
    ans += 1;
    N /= K;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll K;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> K;
}

ll S(ll x){
    ll ret=0;
    string s = to_string(x);
    for (int i = 0; i < s.length(); i++) ret += (s[i]-'0');
    return ret;    
}

long double sunuke(ll n){
    return (long double)n/S(n);
}

int solve(){
    // string s;
    // s = "1";
    // for (int i = 1; i <= K; i++)
    // {
    //     cout << s << "\n";
    //     if(s[0]<'9') s[0] = s[0]+1;
    //     else s = "1"+s;
    // }

    vector<ll> res;
    ll y,next;
    ll x=1;
    y = 0;
    next = x+1;
    for (int i = 0; i < K; i++)
    {
        if(x%10==0) x+=9;
        y = ceil(log10(sunuke(x)));
        x /= pow(10,y);
        x *= pow(10,y);
        if(y>=1) x += stoll(string(y,'9'));
        next = x+pow(10,y);
        if(sunuke(x)<=sunuke(next)) {res.push_back(x); x = next;}
        else {x++;}
    }
    for(auto a:res) cout << a << "\n";
    
    
    return 0;
}   

void test(){
    DBG(S(1234))
    for (int i = 1; i < 1000; i++)
    {
        DBG(make_pair(i,sunuke(i)))
    }
}

int main()
{
    input();
    solve();
    // test();
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int Fi(int);
int f[45];

int main(){
  int n,i;

  scanf("%d",&n);

  for(i = 0; i < 45; i++)
    f[i] = -1;

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

int Fi(int n){
  if(n==0 || n==1)
    return f[n] = 1;
  if(f[n] != -1)
    return f[n];
  return f[n] = Fi(n-1)+Fi(n-2);
}



Measured memory_bytes: 2112
/*
	       ^  ^
			--

	Hello there!   __________    ___  __
	                |       |     |   /
	                |       |     |  /
	                |       |     | /
	                |_______|     |/
	                | \           |\
	                |  \          | \
	                |   \         |  \
	              __|    \________|   \__
*/

#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define f(x, n)             for(int x = 0; x < n; ++ x)
#define fr(x,n)             for(int x=1;x<=n;x++)
#define mp                  make_pair
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define pb                  push_back
#define eb                  emplace_back
#define pii 				pair<int,int>
#define pll 				pair<ll,ll>
#define F 					first
#define S 					second
#define inf 				1e18
#define MOD 				1000000007
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)



int32_t main()
{
	double ans;
	int n;cin>>n;
	if(n==1)
	cout<<prec(1);
	else if(n%2==0){
		cout<<prec(0.5);
	}
	else{
		ans=(double) ((n+1)/2)/n;
		cout<<prec(ans);
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

int main() {
	char s[110], p[110];
	scanf("%s", s);
	scanf("%s", p);
	int n = 0;
	while(s[n] != '\0') ++n;
	int m = 0;
	while(p[m] != '\0') ++m;
	rep(i,n) {
		bool f = 1;
		rep(j,m) {
			if(s[(i + j) % n] != p[j]) {
				f = 0;
				break;
			}
		}
		if(f) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int m;
  cin >> m;
  
  int sumofassignments = 0;
  for(int i=0;i<m;++i)
  {
    int a;
    cin >> a;
    
    sumofassignments += a;
  }
  
  int remainingdays = n-sumofassignments;
  if(remainingdays < 0)
  {
   cout << -1 << endl; 
  }
  else
  {
    cout << remainingdays << endl;
  }
 
  return 0;
}


Measured memory_bytes: 3568
def main():
    eikaku = 0
    donkaku = 0
    chokkaku = 0

    while True:
        a, b, c = sorted([int(a) for a in input().split()])
        if a + b <= c:
            break
        d = a * a + b * b
        if d == c*c:
            chokkaku += 1
        elif d < c*c:
            donkaku += 1
        else:
            eikaku += 1

    print(" ".join([str(a) for a in [eikaku + donkaku + chokkaku, chokkaku, eikaku, donkaku]]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

i64 N;  cin >> N;
vector<tuple<i64, i64, i64>> waAB(N); 
rep(i, 0, N) {
    cin >> get<1>(waAB[i]) >> get<2>(waAB[i]);
    get<0>(waAB[i]) = get<1>(waAB[i]) + get<2>(waAB[i]);
}
sort(ALL(waAB), greater<tuple<i64, i64, i64>>());

i64 ans = 0;
rep(i, 0, N)
    if (i%2)
        ans -= get<2>(waAB[i]);
    else 
        ans += get<1>(waAB[i]);


cout << ans  << endl;

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

const int N = 16;

ll a[N][N];
ll group[1<<N];
ll dp[1<<N];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> a[i][j];
        }
    }
    for (int mask=0; mask<(1<<n); mask++) {
        for (int i=0; i<n; i++) if (mask&(1<<i)) {
            for (int j=i+1; j<n; j++) if (mask&(1<<j)) {
                group[mask] += a[i][j];
            }
        }
    }
    for (int mask=0; mask<(1<<n); mask++) {
        for (int i=0; i<n; i++) if (!(mask&(1<<i))) {
            int mask2 = mask | (1 << i);
            dp[mask2] = max(dp[mask], group[mask2]);
            for (int sub=mask; sub>0; sub=(sub-1)&mask) {
                dp[mask2] = max(dp[mask2], dp[sub] + group[mask2^sub]);
            }
        }
    }
    cout << dp[(1<<n)-1] << '\n';
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9;

int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  int s = 0;
  for(int i = 0; i < N; ++i) cin >> T[i], s += T[i];
  vector<vector<int>> dp(s+1,vector<int>(s+1,INF));
  dp[0][0] = 0;
  for(int i = 0; i < N; ++i){
    vector<vector<int>> dp_(s+1,vector<int>(s+1,INF));
    int t = T[i];
    for(int j = 0; j <= s; ++j){
      for(int k = 0; k <= s; ++k){
        if(dp[j][k] >= INF) continue;
        if(j + t <= s) dp_[j+t][k] = dp[j][k];
        if(k + t <= s) dp_[j][k+t] = dp[j][k];
        dp_[j][k] = dp[j][k] + t;
      }
    }
    dp = dp_;
  }
  int ans = 1e9;
  for(int i = 0; i <= s; ++i)
    for(int j = 0; j <= s; ++j)
      ans = min(ans,max({i,j,dp[i][j]}));
  cout << ans << endl;
}



Measured memory_bytes: 45588
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

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

    map<ll,ll> mp;
    for (ll i = 0; i < n; i++){
        mp[a[i]]++;
    }

    bool ans = false;

    if (mp.size() == 1){
        if (a[0] == 0){
            ans = true;
        }
    }
    else if (mp.size() == 2){
        if (mp[0] == n/3 && mp[a[n-1]] == 2*n/3 && n%3 == 0){
            ans = true;
        }
    }
    else if (mp.size() == 3){
        ll x = 0;
        for (auto p : mp){
            auto k = p.first;
            x = x^k;
        }
        
        if (x == 0 && n%3 == 0){
            bool b = true;
            for (auto p : mp){
                auto v = p.second;
                if (v != n/3){
                    b = false;
                    break;
                }
            }
            if (b){
                ans = true;
            }
        }
    }

    YesNo(ans);


}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << " = " << (x) << "\n";
using ll = long long;
using ld = long double;

struct activites
{
    int a, b, c;
    activites()
    {
        a = b = c = 0;
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll n;
    cin >> n;
    activites cur, prev;
    int a, b, c;
    for (int i = 1; i <= n; i++)
    {
        cin >> a >> b >> c;
        cur.a = max(prev.b, prev.c) + a;
        cur.b = max(prev.a, prev.c) + b;
        cur.c = max(prev.a, prev.b) + c;
        prev = cur;
    }
    cout << max(cur.c, max(cur.a, cur.b));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long ll;

int n, k;
ll T[MAX];

int check(ll P) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        ll s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve() {
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> T[i];
    ll ans = solve();
    cout << ans << endl;
}



Measured memory_bytes: 3876
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] -= i;
	}
	sort(A.begin(), A.end());
	int median = A[N / 2];
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		if (i < N / 2) ans += median - A[i];
		else ans += A[i] - median;
	}
	cout << ans << endl;
	return 0;
}

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

const int MAXN = 1e5+5;

int n, a[MAXN];

int main() {
	cin >> n;
	for (int i = 0; i < 2*n; ++i)
		cin >> a[i];
	sort(a, a+2*n);
	int tot = 0;
	for (int i = 0; i < 2*n; i += 2)
		tot += a[i];
	cout << tot << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define ll long long
#define lld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define mod1 998244353
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("B-small-attempt0.in", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    ll n,m,i;
    cin>>n>>m;
    map<ll, ll> vis;
    for(i=0;i<m;i++)
    {
        ll x;
        cin>>x;
        vis[x]=1;
    }
    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    dp[1]=1;
    for(i=2;i<=n;i++)
    {
        ll x=0;
        if(vis[i-2]==0)
            x=(x+dp[i-2])%mod;
        if(vis[i-1]==0)
            x=(x+dp[i-1])%mod;
        dp[i]=(dp[i]+x)%mod;
    }
    cout<<dp[n]%mod;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) {
    cin >> H[i];
  }
  vector<int> A(M), B(M);
  vector<bool> is_good(N, true);
  rep(i, M) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;

    if (H[A[i]] < H[B[i]])
      is_good[A[i]] = false;
    else if (H[A[i]] > H[B[i]])
      is_good[B[i]] = false;
    else {
      is_good[A[i]] = false;
      is_good[B[i]] = false;
    }
  }

  int ans = 0;
  rep(i, N) {
    ans += is_good[i];
  }
  cout << ans << endl;
}

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

int main()
{
    int N; cin >> N;
    int P[200005];
    for (int i = 1; i <= N; i++)
    {
        cin >> P[i];
    }

    int mn_num = 200001, ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (mn_num > P[i])
        {
            mn_num = P[i];
            ans++;
        }
    }

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

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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

    vector<ll> b(n), c(n);
    for (int i = 0; i < n; i++) {
        b[i] = - a[i] + i;
        c[i] = a[i] + i;
    }

    sort(c.begin(), c.end());

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += upper_bound(c.begin(), c.end(), b[i]) - lower_bound(c.begin(), c.end(), b[i]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll result = max(max(a*c,a*d), max(b*c,b*d));
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   int n,k;cin>>n>>k;
   int p[n];
  for(int i = 0;i<n;i++) cin>>p[i];
  sort(p,p+n);
  int g = 0;
  for(int i = 0;i<k;i++) g+= p[i];
  cout<<g;
    return 0;
}

Measured memory_bytes: 3172
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
void error(const char* str) {
	puts(str);
	exit(0);
}
int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> c(h);
	int cnt = 0, ans = 0, x;
	vector<int> sum_w(w), sum_h(h);
	rep(i, 0, h) {
		cin >> c[i];
		rep(i2, 0, w) {
			if (c[i][i2] == '#')cnt++;
			sum_w[i2]++;
			sum_h[i]++;
		}
	}
	rep(i, 0, 1 << h) {
		rep(i2, 0, 1 << w) {
			x = 0;
			rep(i3, 0, h) {
				{
					rep(i4, 0, w) {
						if ((i2 >> i4 & 1) || (i >> i3 & 1)) {
							if (c[i3][i4] == '#')x++;
						}
					}
				}
			}
			if (x == cnt - k) {
				ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;


int main()
{
    FAST
    ll n;cin>>n;
    ll ans= 0;
    f(i,1,n+1) ans+=(n-i+1)*(n-i+2)/2;
    f(i,0,n-1)
    {
        ll u,v;cin>>u>>v;
        if(v<u) swap(u,v);
        ans-=u*(n-v+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(){
    int x,y;
    while(1){
        scanf("%d%d",&y,&x);
        if(x==0&&y==0){
            break;
        }
        for(int i=0;i<y;i++){
            for(int j=0;j<x;j++){
                if((i+j)%2==1){
                    printf(".");
                }else{
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main() {
	int n, r;
	cin >> n >> r;
	if (n <= 10) {
		cout << r + 100 * (10 - n) << endl;
	}
	else {
		cout << r << endl;
	}

	return 0;
}


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

int main() {
  int N;
  while(cin >> N && N) {
    cin.ignore();
    stringstream ss;
    for(int i=0; i<N; i++) {
      string s;
      getline(cin, s); s += ' ';
      ss<<s;
    }
    string s;
    vector<string> vec;
    while(ss>>s) {
      vec.push_back(s);
    }
    sort(vec.begin(), vec.end());
    map<string, int> mp;
    int cnt = 1;
    for(int i=0; i<vec.size(); i++) {
      //cout << vec[i] << endl;
      if(i<vec.size()-1 && vec[i]==vec[i+1]) {
        cnt ++;
      }
      else {
        mp[vec[i]] = cnt;
        cnt = 1;
      }
    }
    //cout << endl;
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    string q; cin >> q;
    vector<pair<int, string> > vec2;
    for(int i=0; i<vec.size(); i++) {
      if(vec[i][0] == q[0]) {
        vec2.push_back(make_pair(-mp[vec[i]], vec[i]));
        //cout <<vec[i] << " " << mp[vec[i]] << endl;
      }
    }
    sort(vec2.begin(), vec2.end());
    int ok = 0;
    for(int i=0; i<vec2.size(); i++) { 
      if(vec2[i].second[0] == q[0]) {
        ok ++;
        if(ok == 6) break;
        if(i) cout << " ";
        cout << vec2[i].second;
      }
    }
    if(!ok) cout << "NA";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
LI = lambda: list(map(int, input().split()))

N, C = LI()
D = [LI() for _ in range(C)]
c = [LI() for _ in range(N)]

INF = 10 ** 15


def main():
    w = [[0] * C for i in range(3)]
    for i in range(N):
        for j in range(N):
            x = (i + j) % 3
            for k in range(C):
                w[x][k] += D[c[i][j] - 1][k]
    
    ans = INF
    for i in range(C):
        for j in range(C):
            if i == j:
                continue
            for k in range(C):
                if i == k or j == k:
                    continue
                ans = min(ans, w[0][i] + w[1][j] + w[2][k])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11652
n = int(input())
a = list(map(int,input().split()))
X_a = max(a)
N_a = min(a)
L_a = X_a - N_a + 1
b=[0]*L_a

while True:
  if N_a >= X_a:
    break
  for k in range(1,L_a+1):
    for i in a:      
      b[k-1] += (i-N_a)*(i-N_a)
    N_a +=1
print(min(b))


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll a;
  scanf("%lld",&a);
  ll b;
  scanf("%lld",&b);
  if (a*b%2) cout << "Odd" << endl;
  else cout << "Even" << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = 10**18
for z in range(0, max(X, Y) * 2 + 1, 2):
    x, y = max(0, X - z // 2), max(0, Y - z // 2)
    tmp = A * x + B * y + C * z
    ans = min(ans, tmp)
print(ans)


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

int main()
{
    int n;
    char *arr;
    char v;
    cin>>n;
    if(n%2!=0)
        cout<<"No";
    else
    {
        n=n/2;
        arr=new char[n];
        for(int i=0;i<n;i++)
            cin>>arr[i];

        for(int i=0;i<n;i++)
        {
            cin>>v;
            if(v!=arr[i])
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())

def div_count(n,i):
    ans = i
    count = 0
    while n>ans:
        ans *= 2
        count += 1
    return count
ans = 0
for i in range(1,N+1):
    count = div_count(K,i)
    ans += (1/N) * pow(0.5,count)
print(ans)







Measured memory_bytes: 9280
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

for i in 0 .. n - 2 do
  a[i + 1] += a[i]
end

for i in 0 .. m - 2 do
  b[i + 1] += b[i]
end

j = -1
for i in (0 .. m - 1).to_a.reverse do
  if b[i] <= k
    j = i
    break
  end
end
ans = j + 1

for i in 0 .. n - 1 do
  break if a[i] > k
  while j >= 0 and a[i] + b[j] > k
    j -= 1
  end
  ans = [ans, (i + 1) + (j + 1)].max()
end

p ans


Measured memory_bytes: 45132