akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

ll H, W;
vector<string> V(405);
bool vis[405][405];
int d1[4] = {0, 1, 0, -1};
int d2[4] = {1, 0, -1, 0};
vector<vector<ll>> ans(405, vector<ll>(405));

void bfs(ll h, ll w){
    set<pair<ll, ll>> ST; ST.insert({h, w});
    queue<ll> qh, qw;
    queue<char> qb;
    qh.push(h), qw.push(w), qb.push(V[h][w]);
    while(!qh.empty()){
        ll ph = qh.front(), pw = qw.front();
        char pb = qb.front();
        qh.pop(); qw.pop(); qb.pop();
        //cout << ph << " " << pw << endl;
        for(int i = 0; i < 4; i++){
            ll nh = ph+d1[i];
            ll nw = pw+d2[i];
            if(0 <= nh && nh < H && 0 <= nw && nw < W && !vis[nh][nw]){
                //cout << nh << "  " << nw << endl;
                if(V[ph][pw] == '#' && V[nh][nw] == '.'){
                    vis[nh][nw] = true;
                    qh.push(nh); qw.push(nw); qb.push(V[nh][nw]);
                }
                else if(V[ph][pw] == '.' && V[nh][nw] == '#'){
                    //cout << nh << "   " << nw << endl;
                    vis[nh][nw] = true;
                    ST.insert({nh, nw});
                    qh.push(nh); qw.push(nw); qb.push(V[nh][nw]);
                }
            }
        }
    }
    for(auto p : ST){
        ll h = p.first, w = p.second;
        for(int i = 0; i < 4; i++){
            ll nh = h+d1[i];
            ll nw = w+d2[i];
            if(0 <= nh && nh < H && 0 <= nw && nw < W && V[nh][nw] == '.'){
                ans[nh][nw] = ST.size();
            }
        }
    }

}


int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++) cin >> V[i];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(V[i][j] == '#' && !vis[i][j]){
                vis[i][j] = true;
                bfs(i, j);
            }
        }
    }
    ll SUM = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            SUM += ans[i][j];
        }
    }
    cout << SUM << endl;
}

Measured memory_bytes: 6912
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  if len(d1)>1 and len(d2)>1:
    print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))
  elif len(d1)==1 and len(d2)==1:
    print(n//2)
  elif len(d1)==1:
    print(n//2-d2[0][1])
  else:
    print(n//2-d1[0][1])

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

typedef pair<int,int> pii;
const int maxv = (int)2e5+5;
vector<int> g[maxv];
int match[maxv];
bool used[maxv];
int V;
int n;
pii a[105],b[105];

void addedge(int u,int v){
    g[u].push_back(v);
    g[v].push_back(u);
}

bool dfs(int v){
    used[v] = true;
    for(int i=0;i<g[v].size();i++){
        int to = g[v][i]; int w = match[to];
        if(w < 0||!used[w]&&dfs(w)){
            match[v] = to;
            match[to] = v;
            return true;
        }
    }
    return false;
}
int bi_match(){
    int res = 0;
    memset(match,-1,sizeof(match));
    for(int v=1;v<=V;v++){
        if(match[v]<0){
            memset(used,0,sizeof(used));
            if(dfs(v)) res++;
        }
    }
    return res;
}

int solve(){
    //int res = 0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++){
        if(a[i].first < b[j].first && a[i].second < b[j].second) addedge(i,j+n);
    }
    return bi_match();
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    V = n;
    for(int i=1;i<=n;++i) cin>>a[i].first>>a[i].second;
    for(int i=1;i<=n;i++) cin>>b[i].first>>b[i].second;
    cout<<solve();
}


Measured memory_bytes: 6016
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N,x = map(int,input().split())
    if N == 2:
        if x == 2:
            print('Yes')
            print('\n'.join(map(str,(1,2,3))))
        else:
            print('No')
        return
    if x == 1 or x == 2*N - 1:
        print('No')
        return

    ans = [-1] * (2*N - 1)
    used = [False] * (2*N)
    if x == 2:
        ans[N - 3] = x + 2
        ans[N - 2] = x - 1
        ans[N - 1] = x
        ans[N] = x + 1
        used[x - 1] = True
        used[x] = True
        used[x + 1] = True
        used[x + 2] = True
        now = 1
        for i in range(2*N - 1):
            if ans[i] >= 0:
                continue
            while used[now]:
                now += 1
            ans[i] = now
            used[now] = True
    else:
        ans[N - 3] = x - 2
        ans[N - 2] = x + 1
        ans[N - 1] = x
        ans[N] = x - 1
        used[x - 1] = True
        used[x] = True
        used[x + 1] = True
        used[x - 2] = True
        now = 1
        for i in range(2*N - 1):
            if ans[i] >= 0:
                continue
            while used[now]:
                now += 1
            ans[i] = now
            used[now] = True
    print('Yes')
    print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 26556
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

h,n = nm()
v = [nl() for _ in range(n)]
dp = [1<<30]*(h+10020)
dp[0] = 0
for a,b in v:
    for i in range(h+1):
        if dp[i+a] > dp[i] + b:
            dp[i+a] = dp[i] + b
print(min(dp[h:]))


Measured memory_bytes: 41708
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author marX
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class B {
public:
	void solve(std::istream& in, std::ostream& out) {
        long long n, M, V, P;
        in >> n >> M >> V >> P;

        vector<long long> a(n);

        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }

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

        long long answer = 0;

        long long lo = -1, hi = n - 1;

        while (lo + 1 < hi) {
            auto m = (lo + hi) / 2;

            if (m >= V - 1) {
                if (a[m] + M >= a[n - P])
                    hi = m;
                else
                    lo = m;
            } else {
                if (a[m] + M < a[n - P]) {
                    lo = m;
                    continue;
                }

                auto vv = V - m - (P - 1) - 1;

                if (vv <= 0) {
                    hi = m;
                    continue;
                }

                long long sum = 0;

                for (int i = m + 1; i <= n - P; ++i) {
                    sum += min(a[m] + M - a[i], M);
                }

                if (sum >= vv * M) {
                    hi = m;
                } else {
                    lo =m;
                }

            }
        }

        out << n - hi << endl;
	}
};


int main() {
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
	int n = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int k, p;
		cin >> k >> p;
		if(k % p == 0){
			cout << p;
		}else{
			cout << k % p;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const double PI = 3.14159265358979323846;
const int mod = 1e9 + 7;

int main(int argc, char *args[]) {
	int n, m;
	cin >> n >> m;
	vector<int> broken(n + 1);
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		broken[a] = 1;
	}
	vector<int> dp(n+2);
	dp[n] = 1;
	for (int i = n - 1; i >= 0; i--) {
		if (broken[i]) {
			dp[i] = 0;
			continue;
		}
		dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
	}
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>	

//素因数分解　
//pair<ll,ll>型
//auto pf=prime_factorize(ll N);で呼ぶ
//for(auto p:pf){}で探す


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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>c(K);
	rep(i, n) {
		cin >> a[i];
		c[a[i]]++;
	}
	
	bool ok = true;
	for (int i = 2; i < K; ++i) {
		int cnt = 0;
		for (int j = i; j < K; j += i) {
			cnt += c[j];
		}
		if (cnt >= 2)ok = false;
	}
	
	if (ok) {
		cout << "pairwise coprime";
		return 0;
	}
	int k = a[0];
	rep(i, n) {
		 k = gcd(a[i], k);
	}
	if (k == 1) cout << "setwise coprime";
	else cout << "not coprime";
	return 0;
}

Measured memory_bytes: 11160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	const double PI = 2*acos(0.0);
	double a,b,c,d;
	while(cin>>a>>b>>c>>d&&!(a==-1&&b==-1&&c==-1&&d==-1)){
		pair<double,double> angle[2];
		vector<pair<double,double> > v;
		v.push_back(make_pair(a,b));
		v.push_back(make_pair(c,d));
		// pxðWAÉvZ
		for(int i = 0; i < 2; i++){
			angle[i].first=(v[i].first/180)*PI;
			angle[i].second=(v[i].second/180)*PI;
		}
		// ¼a
		const double r=6378.1;
		vector<double> points[2];
		// ÊÀWð»ê¼êßé
		for(int i = 0; i < 2; i++){
			points[i].push_back(r*cos(angle[i].first)*cos(angle[i].second));
			points[i].push_back(r*cos(angle[i].first)*sin(angle[i].second));
			points[i].push_back(r*sin(angle[i].first));
		}
		// 2_Ì¼ü£ðvZ
		double dist = sqrt((points[0][0]-points[1][0])*(points[0][0]-points[1][0])
			+(points[0][1]-points[1][1])*(points[0][1]-points[1][1])
			+(points[0][2]-points[1][2])*(points[0][2]-points[1][2]));
		// ]·èÉæè3ÂÌüªªÈ·cosÌlðßé
		double diffAngle=(r*r+r*r-dist*dist)/(2*r*r);
		// acosÉæècosÌlðÏ·
		double anp = acos(diffAngle);
		// 2*PIÆRÂÌüªªÈ·pxÌäðg¢A£ðßé
		double comp=PI*r*(anp/PI);
		cout<<(int)(comp+0.5)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int now = a[0];
  for(int i = 1; i < n; ++i) {
    if(now == a[i]) {
      cout << "NO" << endl;
      return 0;
    }
    now = a[i];
  }

  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 1024
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __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 debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 2e5 + 10;

ll n, a[N], k;
vector < ll > dp(N, -1);
ll solve(ll i);

int main() {
    fast_io();
    cin >> n >> k;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << solve(0) << "\n";
    return 0;
}

ll solve(ll i) {
    auto &ans = dp[i];
    if (ans != -1) {
        return ans;
    }
    ans = INF;
    if (i >= n) {
        return ans;
    } else if (i == n - 1) {
        ans = 0;
        return ans;
    }
    for (ll j = 1; j <= k; j++) {
        ans = min(solve(i + j) + abs(a[i] - a[i + j]), ans);
    }
    return ans;
}


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

using namespace std;

int main(void) {
	int x,y,s;
	while (cin >> x >> y >> s, x) {
		int res = 0;
		for (int p1 = 1; p1 <= s/2; ++p1) {
			for (int p2 = 1; p2 < s; ++p2) {
				int p3 = ((p1*(100+x))/100) + ((p2*(100+x))/100);
				if (p3 == s) {
					int r = ((p1*(100+y))/100) + ((p2*(100+y))/100);
					res = max(res,r);
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

int K,N;
vector<int> A;

long int space[200007]; // n=1 1件目と2件目の距離

int main(){
    cin >> K >> N;
    int n = 0;
    A.push_back(-1);
    for(int i = 1;i < N+1;i++) {
        n = 0;
        cin >> n;
        A.push_back(n);
    }
 
    // 距離を求める
    for(int i = 1;i < N;i++){
        space[i] = A[i+1] - A[i];
    }
    space[N] = K - A[N] + A[1];

    // 最大の距離を求める
    int max = -1;
    for(int i = 1;i < N+1;i++){
        if(space[i] > max){
            max = space[i];
        }
    }

    cout << (K - max) << endl;


}

Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int mod(int a,int b){
  if(a>b){return a-b;}
  else{return b-a;}
}
int main(){
  int a,b,c; 
  cin>>a>>b>>c; int x=a; a=mod(a,b);b=mod(b,c); c=mod(c,x);
  cout<<a+b+c-max(a,max(b,c));
}

Measured memory_bytes: 256
import heapq

N,M = map(int,input().split())
jobs = [[] for _ in range(10 ** 5 + 1)]
for i in range(N):
    A,B = map(int,input().split())
    jobs[A].append(B)

heap = []
ans = 0
#jobs[A]で追加しているためm+1でまわす
for i in range(M+1):
    #空出ないなら
    if jobs[i]:
        for x in jobs[i]:
            heapq.heappush(heap,-x)
    #空出ないなら
    if heap:
        ans += -heapq.heappop(heap)

print(ans)

Measured memory_bytes: 18376
s = list(input())

if s[0] == "A" and s[2:-1].count("C") == 1:
    s.remove("A")
    s.remove("C")
    
    if "".join(s).lower() == "".join(s):
        print("AC")
    else:
        print("WA")

else:
    print("WA")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long solve(vector<long long> neg, vector<long long> pos, int k)
{
	long long ans = 1;
	if(k&1)
	{
		if(pos.size()>0)
			ans *= pos.back(),pos.pop_back(),--k;
		else return -1;
	}
	vector<long long> v;
	for(int i=pos.size()-1;i>=1;i-=2)	
		v.push_back(pos[i]*pos[i-1]);
	for(int i=0;i+1<neg.size();i+=2)	
		v.push_back(neg[i]*neg[i+1]);
	if(v.size()<k/2)
		return -1;
	sort(v.rbegin(),v.rend());
	for(int i=0;i<k/2;++i)
		ans *= v[i]%MOD, ans %= MOD;
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	long long x;
	vector<long long> neg,pos,zero;
	while(n--)
	{
		cin>>x;
		if(x<0)
			neg.push_back(abs(x));
		else if(x>0)
			pos.push_back(x);
		else
			zero.push_back(x);
	}
	sort(pos.begin(),pos.end());
	sort(neg.rbegin(),neg.rend());
	long long ans = solve(neg,pos,k);
	if(ans<0)
	{
		if(zero.size()>0)
			cout<<"0"<<endl;
		else
		{
			for(long long y:neg)
				pos.push_back(y);	
			sort(pos.begin(),pos.end());
			ans = 1;
			while(k--)			
				ans *= pos[k], ans %= MOD;
			cout<<MOD-ans<<endl;
		}
	}
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8132
n = input()

res = 0


if n[0] != "9":
    if len(n[1:]) == n.count("9"):
        res = int(n[0]) + 9*n.count("9")
    else:
        res = int(n[0])-1 + 9*(len(n)-1)
else:
    if len(n) == n.count("9"):
        res = 9*len(n)
    else:
        res = 9*(len(n)-1) + 8

print(res)


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

int main(){
    int n,k,x,s=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>x;
        s+=2*min(x,k-x);
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split(" ")))
c=[]
for k in range(n):
  b=[j for j,i in enumerate(a) if i==j+1]
  if b==[]:
    print(-1)
    k=n
    break
  else:
    c.insert(0,a.pop(b[-1]))
if k==n-1:
  for i in c:
    print(i)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int data[2][110];
int ansOut=-1;

int n;

int main(){
	scanf("%d",&n);
	
	int ans = 0;
	int ans2 = 0;
	
	for(int i=0;i<n;i++){
		scanf("%d",&data[0][i]);
		ans += data[0][i];
	}

	for(int i=0;i<n;i++)
		scanf("%d",&data[1][i]);		
	
	for(int i=n-1;i>=0;i--){
		ans2 += data[1][i];
		ansOut = max(ansOut,ans+ans2);
		ans -= data[0][i];
		
	}
	
	printf("%d",ansOut);
	return 0;
}


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

using namespace std;

int fa[200005];
int fa1[200005];
int vis[200005];

int find1(int a)
{
    if(fa[a]!=a)
        fa[a]=find1(fa[a]);
    return fa[a];
}
void union1(int a,int b)
{
    fa[find1(a)]=find1(b);
}

int find2(int a)
{
    if(fa1[a]!=a)
        fa1[a]=find2(fa1[a]);
    return fa1[a];
}
void union2(int a,int b)
{
    fa1[find2(a)]=find2(b);
}
map<long long,int> mp;
int main()
{
    int n,k,l;
    cin>>n>>k>>l;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<=n;i++)
    {
        fa[i]=i;
        fa1[i]=i;
    }
    for(int i=0;i<k;i++)
    {
        int l1,r;
        scanf("%d %d",&l1,&r);
        union1(l1,r);
    }
    for(int i=0;i<l;i++)
    {
        int l1,r;
        scanf("%d %d",&l1,&r);
        //if(find1(l1)==find1(r))
        union2(l1,r);
        //cout<<find1(l1)<<' '<<find1(r);
    }
    for(int i=1;i<=n;i++)
    {
        if(mp.find((long long)((long long)find1(i)*200005+(long long)find2(i)))==mp.end())
            mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]=0;
        mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]++;
    }
    for(int i=1;i<n;i++)
        printf("%d ",mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]);
    printf("%d\n",mp[(long long)((long long)find1(n)*200005+(long long)find2(n))]);
    return 0;
}


Measured memory_bytes: 14336
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

#define ll long long
#define MP make_pair

int h,w,d[100][100]={};
vector<string> s(100);
queue<pair<int,int>> q;


void bfs(int hi,int wi){

    
    for (int i = -1; i < 2; i+=2) {
        if(hi+i>=0&&hi+i<=h-1){
            if(s[hi+i][wi]=='.'){
                s[hi+i][wi]='#';
                q.push(MP(hi+i,wi));
                d[hi+i][wi]=d[hi][wi]+1;
            }
        }
        if(wi+i>=0&&wi+i<=w-1){
            if(s[hi][wi+i]=='.'){
                s[hi][wi+i]='#';
                q.push(MP(hi,wi+i));
                d[hi][wi+i]=d[hi][wi]+1;
            }
        }
    }
    


    return;
}

int main(void) {
    int white=0;
    cin>>h>>w;
    for (int i = 0; i < h; i++) {
        cin>>s[i];
        for (int j = 0; j < w; j++) {
            if(s[i][j]=='.')white++;
        }
    }

    q.push(MP(0,0));
    d[0][0]=1;    
    s[0][0]='#';

    while(!q.empty()){
        bfs(q.front().first,q.front().second);
        q.pop();
    }

    if(d[h-1][w-1]==0)cout<<"-1\n";
    else cout<<white-d[h-1][w-1]<<"\n";   

    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define Max 100005
#define mem(a,b) memset(a,b,sizeof(a));
#define pb push_back
#define mp make_pair
const LL mod=1e9+7;
const ULL base=131;
const LL LL_MAX=9223372036854775807;
using namespace std;
int b[200005];
vector<int>a,d;
int main()
{
    int n;
    scanf("%d",&n);
    int x;
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        a.push_back(x);
        d.push_back(x);
        b[x]++;
    }
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    for(int i=0;i<n;i++){
        if(d[i]!=a[a.size()-1])
            printf("%d\n",a[a.size()-1]);
        else{
            if(b[a[n-1]]>1)
                printf("%d\n",a[a.size()-1]);
            else{
               // printf("%d\n",a[n-1]-1);
                 printf("%d\n",a[a.size()-2]);
            }

        }
    }
    return 0;
}


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

struct segtree {
    int size;
    vector<int> node;
    
    segtree(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), 0);
    }
    
    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = max(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return -1000000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }

    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<P> XD;
    rep(i, N) {
        int Xi, Di; cin >> Xi >> Di;
        XD.pb(P(Xi, Di));
    }
    sort(XD.begin(), XD.end());
    vector<int> X, D;
    rep(i, N) {
        X.pb(XD[i].first);
        D.pb(XD[i].second);
    }
    X.pb(2000000000000000000);
    
    int dp[N+1];
    dp[N] = 1;
    int M[N];
    segtree st(N);
    for (int i=N-1; i>=0; i--) {
        int lim = lower_bound(X.begin(), X.end(), X[i]+D[i])-X.begin();
        M[i] = max(lim-1, st.get(i+1, lim));
        st.update(i, M[i]);
        dp[i] = dp[i+1]+dp[M[i]+1];
        dp[i] %= MOD;
    }
    
    cout << dp[0] << endl;
}

Measured memory_bytes: 16620
#include <iostream>

using namespace std;
char s[4];
int i,nr;
int main()
{
    cin.getline(s,4);
    for(i=0;i<3;i++)
    {
        if(s[i]=='1')
        {
            nr++;
        }
    }
    cout<<nr<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

string s[] {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main() {
  string x;
  cin >> x;
  int idx = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == x) {
      idx = i;
      break;
    }
  }
  int ans = 0;
  idx++;
  idx %= 7;
  ans++;
  while (s[idx] != "SUN") {
    idx++;
    idx %= 7;
    ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log, floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()

print(a*b)

Measured memory_bytes: 68172
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;
#define MOD 1000000007

using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS

    ll n;
    cin>>n;
    n = (ll)ceil((double)n/1000) * 1000 -n;
    cout<<n<<endl;

    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
signed main(){
    int x;
    cin>>x;
    int now=0;
    rep(i,x+1){
        now+=i;
        if(now>=x){
            cout<<i<<endl;
            return 0;
        }
    }
 
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code
int n;
vector<bool> used(n,false);
const int inf = 99999999;
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
vector<int> lis_fast(const vector<int>& a) {
  const int n = a.size();
  vector<int> A(n, inf);
  vector<int> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = index_of(A, a[i]);
    A[ id[i] ] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  vector<int> b(m+1);
  for (int i = n-1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];
  return b;
}

int main(int argc, char const* argv[])
{
	cin >> n;
	VL a(n);
	cin >> a;
	multiset<int> c; // 最終要素の数
	c.insert(a[0]);
	for (int i = 1; i < n; i++) {
		if (*c.begin() >= a[i]) {
			c.insert(a[i]);
		}
		else {
			auto e = --c.lower_bound(a[i]);
			c.erase(e);
			c.insert(a[i]);
		}
	}
	cout << c.size() << endl;
	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdio.h>
using namespace std;

int a, b, c, d;
int ans;

int main() {
	cin >> a >> b >> c;
	d = a * c;
	if (b > d) {
		cout << c << endl;
	}
	else {
		cout << b / a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll spf[1000005];

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

void sieve(){
    for (int i = 0; i < 1000005; ++i)
    {
        spf[i]=i;
    }
    for (int i = 4; i < 1000005; i+=2)
    {
        spf[i]=2;
    }
    for (int i = 3; i*i < 1000005; i+=2)
    {
        if(spf[i]==i){
            for (int j = i*i; j < 1000005; j+=i)
            {
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

set<ll> get_factors(ll num){
    set<ll> s1;
    while(num>1){
        s1.insert(spf[num]);
        num=num/spf[num];
    }
    return s1;
}

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    sieve();
    ll n;
    cin>>n;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }

    set<ll> tot;
    ll fg=0;
    for (int i = 0; i < n; ++i)
    {
        if(fg==1){
            break;
        }
        set<ll> s1 = get_factors(a[i]);
        for (auto j = s1.begin(); j != s1.end(); ++j)
        {
            if(tot.find(*j)==tot.end()){
                tot.insert(*j);
            }
            else{
                fg=1;
                break;
            }
        }
    }

    if(fg==0){
        cout<<"pairwise coprime";
        return 0;
    }
    // they are setwise coprime
    ll gc=a[0];
    for (int i = 1; i < n; ++i)
    {
        gc = gcd(gc, a[i]);
    }
    if(gc==1){
        cout<<"setwise coprime";
        return 0;
    }

    cout<<"not coprime";

    return 0;
}

Measured memory_bytes: 19188
x1, y1, x2, y2 = map(int,input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

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

using namespace std; 

using ll = long long;

const int N = 1000005, INF = 1000000005;

int arr[N];

vector < int > vec;

int div(int v){
    if(arr[v])  return 0;
    for(int i = 1; i * i <= v; i++){
        if(v % i != 0)  continue;
        if(arr[i] || arr[v / i]){
            return 0;
        }
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, ans = 0;     cin >> n;
    for(int i = 0; i < n; i++){
        int v;  cin >> v;
        arr[v]++;
        vec.push_back(v);
    }
    for(int &v: vec){
        arr[v]--;
        ans += div(v);
        arr[v]++;
    }   
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7748
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 111;
 
int n;
int a[2*maxn];
bool buf;
 
int main() {
  buf = scanf("%d", &n);
  n <<= 1;
  for (int i = 1; i <= n; i++) {
    buf = scanf("%d", a+i);
  }
  sort(a+1, a+n+1);
  int res = 0;
  for (int i = 1; i <= n; i += 2)
    res += a[i];
  printf("%d\n", res);
  return 0;
}

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

int main()
{
	string s; cin >> s;
	
	int cnt = 0;

	if (s.at(0) == 'o') cnt++;
	if (s.at(1) == 'o') cnt++;
	if (s.at(2) == 'o') cnt++;
	
	cout << 700 + 100 * cnt << endl;
			
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int N, K;
vector<ll> F, FInv;

ll mod_pow(ll a, ll n, ll m){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

ll comb(ll n, ll r){
    return (F[n] * (FInv[r] * FInv[n-r] % mod)) % mod;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));

    F.resize(N+1);
    FInv.resize(N+1);
    F[0] = 1;
    REP(i,1,N+1) F[i] = F[i-1] * i % mod;
    FInv[N] = mod_pow(F[N], mod-2, mod);
    RREP(i,1,N+1) FInv[i-1] = FInv[i] * i % mod;

    ll ma = 0, mi = 0;
    rep(i,N){
        if(K <= i + 1) ma += A[i] * comb(i, K - 1);
        ma %= mod;
    }
    sort(rall(A));
    rep(i,N){
        if(K <= i + 1) mi += A[i] * comb(i, K - 1);
        mi %= mod;
    }
    cout << (ma - mi) % mod << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int n;
  scanf("%d", &n);
  vi a(n), ts(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ts[i] = a[i];
  }
  sort(ts.begin(), ts.end());
  ts.resize(unique(ts.begin(), ts.end()) - ts.begin());
  int res = 0;
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(ts.begin(), ts.end(), a[i]) - ts.begin();
    if (a[i] % 2 && i % 2 == 0) ++res;
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {
	long long int a, v, b, w, t;

	cin >> a >> v >> b >> w >> t;

	if (b > a)
	{
		if((a + v*t) >= (b + w*t))
		{
			cout << "YES";
		}
		else
		{
			cout << "NO";
		}
	}	
	else if (b < a)
	{
		if((a - v*t) <= (b - w*t))
		{
			cout << "YES";
		}
		else
		{
			cout << "NO";
		}
	}

	return 0;
}



Measured memory_bytes: 3624
package main

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

// input に使うやつ
var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// string から int へ
func atoi(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

// 一つの文字を int として読み込み
func readInt() int {
	return atoi(readLine())
}

// 複数の文字を int のスライスとして読み込み
func readInts() []int {
	in := readLine()
	ins := strings.Split(in, " ")
	out := make([]int, len(ins))
	for i, v := range ins {
		out[i] = atoi(v)
	}
	return out
}

// sortしたスライスを返す
func sorted(a []int) []int {
	b := make([]int, len(a))
	copy(b, a)
	sort.Ints(b)
	return b
}

// 逆順のsort
func reverse(a []int) []int {
	b := make([]int, len(a))
	copy(b, a)
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	return b
}

func main() {
	n := readInt()
	// w := make([]string, n)
	s := make(map[string]int)
	var c int

	for i := 0; i < n; i++ {
		a := strings.Split(readLine(), "")
		sort.Strings(a)
		str := strings.Join(a, "")
		// w[i] = str
		if _, ok := s[str]; ok {
			s[str]++
		} else {
			s[str] = 1
		}
	}

	for _, v := range s {
		for i := v - 1; i > 0; i-- {
			c += i
		}
	}

	// for i := 0; i < n-1; i++ {
	// 	j := i + 1
	// 	if s[i] == s[j] {
	// 		for {
	// 			c++
	// 			j++
	// 			if j == n {
	// 				break
	// 			}
	// 		}
	// 	} else {

	// 	}
	// }

	fmt.Println(c)
}


Measured memory_bytes: 11648
#include <bits/stdc++.h> 
using namespace std;
int main(){string s;cin>>s;if(s=="A"){cout<<"T"<<endl;return 0;}else if(s=="T"){cout<<"A"<<endl;return 0;}else if(s=="G"){cout<<"C"<<endl;return 0;}else cout<<"G"<<endl;return 0;}

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

using namespace std;
int a[200000] = { 0 };
long long cnt = 0;

void merge(int left, int mid, int right)
{
	int i, j;
	int n1 = mid - left;
	int n2 = right - mid;
	int *L = new int[n1 + 1];
	int *R = new int[n2 + 1];

	for (i = 0; i != n1; ++i)
	{
		L[i] = a[left + i];
	}
	for (i = 0; i != n2; ++i)
	{
		R[i] = a[mid + i];
	}
	L[n1] = R[n2] = 1000000001;
	i = j = 0;

	for (int k = left; k != right; ++k)
	{
		
		if (L[i] > R[j])
		{
			a[k] = R[j];
			++j;
			cnt += n1 - i;
		}
		else
		{	
			a[k] = L[i];
			++i;
		}
	}
	delete[]L;
	delete[]R;
}


void mergeSort(int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}


int main()
{
	int n;

	ios::sync_with_stdio(false);

	cin >> n;

	for (int i = 0; i != n; ++i)
	{
		cin >> a[i];
	}

	mergeSort(0, n);

	cout << cnt << endl;

	return 0;

}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;
  cin >> n >> m;
 // cout << (n*2LL+m)/4LL << endl;
    if(n>=m/2LL) cout << m/2LL << endl;
  else{
   ll s=n;
   ll c=n*2LL;
    m-=c;
    s+=m/4LL;
    cout << s << endl;
    }
  
  
  return 0;
    

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n, m;
  std::cin >> n;
  std::map<int64_t, int64_t> md;
  std::map<int64_t, int64_t> mt;
  std::vector<uint64_t> d(n);
  rep(i, n) {
    std::cin >> d[i];
    md[d[i]]++;
  }
  std::cin >> m;
  std::vector<uint64_t> t(m);
  rep(i, m) {
    std::cin >> t[i];
    mt[t[i]]++;
  }

  for (auto i : mt) {
    if (md[i.first] - i.second < 0) {
      std::cout << "NO" << std::endl;
      return 0;
    }
  }

  std::cout << "YES" << std::endl;
  return 0;
}


Measured memory_bytes: 31504
import java.util.Scanner;

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

		char[] c = sc.next().toCharArray();
		char[] d = sc.next().toCharArray();

		int j = d.length - 1;
		boolean f = true;
		for(int i = 0; i < c.length; i++) {
			if(c[i] != d[j]) {
				f = false;
			}
			j--;
		}

		if(f) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7;
int n, a[N];
bool aa[N];
bool get(int m) {
    for (int i = 0; i < 2 * n - 1; ++i) aa[i] = a[i] >= m;
    ii ans = {2 * N, -1};
    for (int i = n - 1; i; --i) {
        if (aa[i - 1] == aa[i]) ans = min(ans, mp(n - 1 - i, (int)aa[i]));
    }   
    for (int i = n - 1; i + 1 < 2 * n - 1; ++i) {
        if (aa[i + 1] == aa[i]) ans = min(ans, mp(i - n + 1, (int)aa[i]));
    }   
    if (ans.s != -1) return ans.s;
    return aa[n - 1] ^ ((n - 1) & 1);
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < 2 * n - 1; ++i) cin >> a[i];
    int l = 0, r = 2 * N;    
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (get(m)) l = m;
        else r = m;
    }   
    cout << l << '\n';
}

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

namespace Atcoder
{

    class Program
    {
        static void Main(string[] args)
        {
            {
                var split = Console.ReadLine().ToArray();
                int a = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (split[i] == '2' )a++;
                }
                Console.WriteLine(a);

            }
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n=0,d[200009],a[200009],m=0,k=0,ans=0,fl=0;
	string s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	d[0]=0;
	if(n>1)
		d[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		d[i]=min(d[i-1]+abs(a[i]-a[i-1]),d[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<d[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 5184
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>

using namespace std;
int main(void)
{

  int af;
  cin >> af;

  if (af == 1)
    cout << 1.0000000000 << endl;
  else
    cout << fixed << setprecision(10) << (af - af / 2) / (double)af << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define double long double
typedef long long LL;
using namespace std;

int main(int argc, char **argv) {
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
const int mod=1000000007;
int N,M,f[1<<15],g[15][2];
bool G[15][15];
int dfs(int s,int i){
	while(i>=0&&!(s>>i&1))--i;
	if(i<0)return f[s];
	for(int j=0;j<i;j++)if(G[j][i])++g[j][0];
	long long res=dfs(s,i-1);
	res=(res<<g[i][1])-res;
	for(int j=0;j<i;j++)if(G[j][i])--g[j][0],++g[j][1];
	res+=1ll*dfs(s^1<<i,i-1)<<g[i][0];
	for(int j=0;j<i;j++)if(G[j][i])--g[j][1];
	return res%mod;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0,a,b;i<M;i++)scanf("%d%d",&a,&b),G[--a][--b]=1;
	f[0]=1;
	for(int i=0;i<N;i++){
		for(int s=0;s<1<<i;s++)if(((s|1<<i)&1)==((s|1<<i)>>1&1)){
			for(int j=0;j<i;j++)g[j][0]=0,g[j][1]=G[j][i];
			f[s|1<<i]=dfs(s,i);
		}
	}
	int s=1;
	while(M--)s=s*2%mod;
	s=(s+mod-f[(1<<N)-1])%mod;
	printf("%d\n",s);
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

using ll = long long;
using P = pair<int,int>;

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

  vector<int> cnt(n+1, 0);
  for(int i = 1; i <= n; i++) {
    for(int j = i; j <= n; j += i) {
      cnt[j] += 1;
    }
  }

  ll res = 0;
  for(int i = 1; i <= n; i++) {
    res += ll(cnt[i]) * i;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 42328
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
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)

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int d[100];
    FOR(i,0,N) cin >> d[i];

    set<int> s;
    FOR(i,0,N) s.insert(d[i]);

    cout << s.size() << endl;


}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define min(a, b) a < b ? a : b
#define max(a, b) a > b ? a : b

#define MAXN 100000

int main(void)
{
	int i;
	int N;
	int on = 0, en = 0;
	long long A[MAXN];

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		if (A[i] % 2 == 0) en++;
		else on++;
	}
	//printf("%d %d\n", on, en);
	en += on / 2;
	on = on % 2;
	while (on + en > 2) {
		en = en / 2 + en % 2;
		//printf("%d %d\n", on, en);
	}
	if (!on || !en) printf("YES\n");
	else printf("NO\n");
	/*if (on == 0) {
		printf("%d %d\n", on, en);
		while (en > 2) {
			en = en / 2 + en % 2;
			printf("%d %d\n", on, en);
		}
		printf("%d %d\n", on, en);
		if (en == 1) printf("NO\n");
		else printf("YES\n");
	} else {
		printf("NO\n");
	}*/

	//printf("%d %d\n", on, en);

	return (0);
}

Measured memory_bytes: 896