akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  if(m2==(m1+1))
  {
   cout<<1<<endl;
    
    
  }
  else
    cout<<0<<endl;

  
}

Measured memory_bytes: 3636
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>

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

using namespace std;
using ll = long long;

ll func(ll n){
    return n*(n+1)/2;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int sum = 0;
    int xor_ = 0;
    ll ans = 0;
    ll l = 0,r = 0;
    ll former_r = 0;
    while(r < n){
        sum += a[r];
        xor_ ^= a[r];
        r++;


        if(sum != xor_){
            ans += func(r-l-1);
            
            if(former_r-l+1 > 0 && former_r > 0){
                ans -= func(former_r-l+1);
            }
            former_r = r-2;
            while(sum != xor_){
                sum -= a[l];
                xor_ ^= a[l];
                l++;
            }
        }
    }

    ans += func(r-l);
    if(former_r-l+1 > 0 && former_r > 0){
        ans -= func(former_r-l+1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int A,B,M;
    cin>>A>>B>>M;
    vector<int> a(A),b(B);
    vector<int> x(M),y(M),c(M);
    vector<int> hiyou(M);
    for(int i=0;i<A;i++) cin>>a[i];
    for(int i=0;i<B;i++) cin>>b[i];
    for(int i=0;i<M;i++){
        cin>>x[i]>>y[i]>>c[i];
        hiyou[i] = a[x[i]-1]+b[y[i]-1]-c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    int ans=a[0]+b[0];
    for(int i=0;i<M;i++){
        ans = min(ans,hiyou[i]);
    }

    cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define Rrep(i,n) for(int i=((int)n-1); i>=0; i--)
#define all(x) (x).begin(),().end()
#define SZ(x) ((int)(x).size())
typedef long long ll;



int main()
{
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(15);

        ll n;
        ll m;
        ll ac=0;
        ll wa=0;
        cin>>n>>m;
        vector<bool> fg(n,false);
        vector<ll> q(m);
        vector<string> judge(m);
        vector<ll> wacnt(n,0);

        rep(i,m){
                cin>>q.at(i);
                cin>>judge.at(i);
        }

        rep(i,m){
                if(judge.at(i)=="AC"&&fg.at(q.at(i)-1)==false) {
                        ac++;
                        wa=wa+wacnt.at(q.at(i)-1);
                        fg.at(q.at(i)-1)=true;
                }
                else if(judge.at(i)=="WA"&&fg.at(q.at(i)-1)==false) {
                        wacnt.at(q.at(i)-1)++;
                }
        }

        cout<<ac<<" "<<wa<<endl;
        return 0;
}


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

using namespace std;

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

inline bool inrange(int x, int y) {
  return (0<=x&&x<8) && (0<=y&&y<8);
}

string F[8];
bool used[8][8];
int turn;

int dx, dy;
int dfs(int x, int y, char me, int cnt) {
  x += dx, y += dy;
  if(!inrange(x, y)) { return 0; }
  if(F[y][x] == '.') { return 0; }
  if(F[y][x] == me) {
    return cnt;
  }
  used[y][x] = 1;
  int r = dfs(x, y, me, cnt+1);
  if(r == 0) { used[y][x] = 0; }
  return r;
}

#define DREP(i, a, b, c, d)                                 \
  for(int i=turn&1?a:c; turn&1?i>=b:i<=d; turn&1?i--:i++)

int main() {
  rep(i, 8) cin >> F[i];
  int ucnt = 0;
  for(turn=0; turn<=64; turn++) {
    int pl;
    bool u[8][8] = {};
    int mx = 0;
    DREP(i, 7, 0, 0, 7) DREP(j, 7, 0, 0, 7) {
      if(F[i][j] == '.') {
        rep(a, 8) rep(b, 8) used[a][b] = 0;
        used[i][j] = 1;
        int r = 0;
        for(dy=-1; dy<2; dy++) for(dx=-1; dx<2; dx++) {
          if(dx == 0 && dy == 0) { continue; }
          r += dfs(j, i, "ox"[turn&1], 0);
        }            
        if(mx < r) {
          memcpy(u, used, sizeof u);
          mx = r; pl = turn&1;
        }
      }
    }
    if(mx > 0) {
      rep(i, 8) rep(j, 8)
        if(u[i][j]) { F[i][j] = "ox"[pl]; }
      ucnt = 0;
    }
    else {
      if(ucnt) { break; }
      ucnt ++;
    }
  }
  rep(i, 8) {
    rep(j, 8) {
      cout << F[i][j];
    }
    puts("");
  }
  
  return 0;
}

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

int main() {

	int a,b,c,d;

	cin >> a >> b >> c >> d;

	if (a*b>c*d) {
		cout << a * b << endl;
	}

	else {
		cout << c * d << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[400000];
bool solve(int t) {
	vector<H>v;
	v.push_back(H{ 1,0 });
	for (int i = 0; i < n; i++) {
		if (v[v.size() - 1].x < a[i]) {
			v.push_back(H{ a[i],1 });
		}
		else {
			while (!v.empty() && v[v.size() - 1].x > a[i]) v.pop_back();
			if (v[v.size() - 1].x == a[i]) v[v.size() - 1].y++;
			else v.push_back(H{ a[i],2 });
		}
		while (v.size() >= 2 && v[v.size() - 1].y == t + 1) {
			int k = v.size();
			if (v[k - 2].x == v[k - 1].x - 1) {
				v[k - 2].y++;
				v.pop_back();
			}
			else {
				k = v[k - 1].x - 1;
				v.pop_back();
				v.push_back(H{ k,1 });
			}
		}
		if (i == 0) v[0].y = 1;
	}
	if (v[0].y > t) return 0;
	return 1;

}
signed main() {
	cin >> n;
	bool b = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0 && a[i - 1] >= a[i]) b = 0;
	}
	if (b) {
		cout << 1 << endl;
		return 0;
	}
	int ng = 1, ok = (1 << 30), t;
	while (abs(ok-ng) > 1) {
		t = (ok+ng) / 2;
		if (solve(t)) ok = t;
		else ng = t;
	}
	cout << ok << endl;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)


#define Vi vector
#define pr pair
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

vector<char> prime (10000000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (ld j=i*i; j<=n; j+=i)
					prime[j] = false;
}


vd v1;

vd g[100004];
//vd g1[100004];
//vd ar;
//vvd final;
//ld mind = 1000000006;
//vd mind;
//ld c;
bool visit[100004];
ld dist[100004];
//for topological sort of a graph
void dfs(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(j=0;j<g[i].size();j++)
	{
		if(!visit[g[i][j]])
		{
			dfs(g[i][j],n);
		}
	}
	v1.pb(i);
}

void dfs1(ld i,ld n)
{
	visit[i] = true;
	ld j,k;
	for(auto x : g[i])
	{
		if(!visit[x])dfs1(x,n);
		dist[i]=max(dist[i],dist[x]+1);
	}
}


int main(){
	ld n,m,i,j;
	cin >> n >> m;
	REP(i,1,m)
	{
		ld a,b;
		cin >> a >> b;
		g[a].pb(b);
		//g1[b].pb(a);
	}
	memset(visit,0,sizeof(visit));
	memset(dist,0,sizeof(dist));
	REP(i,1,n)
	{
		if(!visit[i])dfs1(i,n);
	}
	cout << *max_element(dist,dist+n+1) << endl;
	return 0;
}

/*
//next step
//from transposed graph g1,get strongly connected components
void dfs1(ld i,ld n,ld len)
{
	visit[i] = true;
	ld j,k;
	final[len].pb(i);
	mind[len] = min(mind[len],ar[i]);
	rep(j,0,g1[i].size())
	{
		if(!visit[g1[i][j]])
		{
			dfs1(g1[i][j],n,len);
		}
	}
}
*/

Measured memory_bytes: 18432
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n >> m >> s;
  t = "Yes";
  rep(i,0,n)if(s[i] == '-')t = "No";
  if(s[n] != '-')t = "No";
  rep(i,n+1,n+m)if(s[i] == '-')t = "No";
  print(t);
  return 0;
}


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

int n,k;

int cant[20];


bool ok(int num)
{
    while(num)
    {
        int t = num % 10;
        if(cant[t]) return false;
        num /= 10;
    }
    return true;
}

int solve()
{

    for(int i = n;;++i)
    {
        if(ok(i))
            return i;
    }
}

int main()
{
  //  freopen("./test.txt","r",stdin);
    scanf("%d %d",&n,&k);
    memset(cant,0,sizeof(cant));
    for(int i = 0;i < k;++i)
    {
        int t;
        scanf("%d",&t);
        cant[t] = 1;
    }

    int res = solve();
    printf("%d\n",res);

    return 0;
}


Measured memory_bytes: 764
# -*- coding: utf-8 -*-
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
px = []
for i in range(m):
    px.append([int(i) for i in input().split()])

for i in range(m):
    ans = sum(t)
    ans -= t[px[i][0] - 1] - px[i][1]
    print(ans)


Measured memory_bytes: 3060
from math import sqrt

X = int(input())
p = -1

if X == 1 or X == 2:
    print(X)
    exit()

for i in range(X, 10**10):
    if i % 6 == 1 or i % 6 == 5:
        isPrime = True
        for j in range(2, int(sqrt(i)) + 1):
            if i % j == 0:
                isPrime = False
                break
            else:
                continue
        if isPrime == True:
            p = i
            break
    else:
        continue
print(p)


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

int main()
{
    std::uint64_t K, N;
    std::cin >> K >> N;

    std::vector<std::uint64_t> A(N);
    for(auto& a : A)
    {
        std::cin >> a;
    }

    std::sort(A.begin(), A.end());

    std::vector<std::uint64_t> dist(N);
    dist[0] = K + A[0] - A[N-1];
    for(std::size_t i=1; i<N; ++i)
    {
        dist[i] = A[i] - A[i-1];
    }

    std::cout << K - *std::max_element(dist.begin(), dist.end()) << std::endl;


    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int p,q,r;
  cin>>p>>q>>r;
  cout<<p+q+r-max({p,q,r})<<endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B, X; cin >> A >> B >> X;
    
    string ans = "NO";
    if (A <= X && X <= A + B) ans = "YES";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

long long gcd(long long  a,long long b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	long long  n, m;
	while(scanf("%ld %ld",&n,&m)!=EOF)
	{
		long long  tmp,tnp;
		if(n>m)
		{
			tmp=n;
			tnp=m;
		}
		else
		{
			tmp=m;
			tnp=n;
		}
		printf("%ld %ld\n",gcd(tmp,tnp),n/gcd(tmp,tnp)*m);
	}
	return 0;
}

Measured memory_bytes: 2584
import sys
INF = float("inf")
n = int(input())
A = [0]
for i, a in enumerate(sys.stdin):
    a = list(map(int, a.split()))
    if i == 0:
        A.extend(a)
    else:
        A.append(a[1])
C = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(n + 1):
    C[i][i] = 0
for j in range(1, n):
    for i in range(1, n - j + 1):
        for k in range(i + 1, i + j + 1):
            cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1]
            if cost < C[i][i + j]:
                C[i][i + j] = cost
print(C[1][n])



Measured memory_bytes: 5672
#include<stdio.h>

int main(void){

    int N,i;
    char S[101],T[101];

    scanf("%d",&N);
    scanf("%s %s",S,T);

    for(i = 0;i < N;i++){
        printf("%c%c",S[i],T[i]);
    }

    return 0;
}

Measured memory_bytes: 128
import math
n,k = map(int,input().split())
A = list(map(int,input().split()))

low = 1
high = max(A)

while low != high:
    mid = (low + high)// 2
    cnt = 0
    for i in A:
        cnt += math.ceil(i/mid) - 1
    if cnt > k :
        low = mid + 1
    else:
        high = mid

print(low)

Measured memory_bytes: 31100
n = gets.chomp.to_i
h = Hash.new(0)

max_num = 0

n.times do |i|
  s = gets.chomp

  h[s] += 1


  max_num = [max_num, h[s]].max

end



h =  h.sort_by{ |x| x[0]}

# puts max_num

h.each do |key, value|
  if value == max_num
    puts key
  end
end





Measured memory_bytes: 38340
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#define int long long
const int mx = 1e5+5;
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	vector<pair<int,int> >v;
	for(int i=0;i<m;i++)
	{
		int p,q;
		cin>>p>>q;
		v.push_back(make_pair(q,p));
	}
	sort(arr,arr+n);
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	int j =0;
	int p1 = v[j].second;
	for(int i=0;i<n;i++)
	{
		if(i == p1)
		{
			j++;
			p1 += v[j].second;
		}
		if(arr[i] < v[j].first)
		{
			arr[i] = v[j].first;
		}
		else
		{
			break;
		}
	}
	int sum =0;
	for(int i=0;i<n;i++)
	{
		//cout<<arr[i]<<" ";
		sum += arr[i];
	}
	cout<<sum<<endl;
	
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s,t;
	cin >> s >> t;
	for(int i = 0;i<s.size();i++)
	{
		bool isans = true;
		for(int j = i;j<t.size()+i;j++)
		{
			if(t[j-i]!=s[j%s.size()])isans = false;
		}
		if(isans == true)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>

int main()
{
	std::string s;

	std::cin >> s;


	s.erase(s.length() - 2, 2);

	while (true) {
		std::string str = s.substr(s.length() / 2);
		if (str + str == s) {
			break;
		}
		s.erase(s.length() - 2, 2);
	}


	std::cout << s.length() << std::endl;

	return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans=0
mod = 10**9+7

factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod - 2, mod))
 
def comb(n, r, mod):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod

a=a[::-1]
for i in range(n-k+1):
    ans += (a[i] * comb(n-i-1, k-1, mod))%mod
a=a[::-1]
for i in range(n-k+1):
    ans -= (a[i] * comb(n-i-1, k-1, mod))%mod


print(ans%mod)


Measured memory_bytes: 16532
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() { puts("-1"); exit(0); }


V dx = {1, 0, -1, 0};
V dy = {0, 1, 0, -1};


int main() {
  int n; cin >> n;
  V p(n*n); cin >> p;

  VVbo vac(n, Vbo(n));
  VV d(n, V(n));
  rep(i, n) rep(j, n) d[i][j] = min({i, n-i-1, j, n-j-1});

  ll ans = 0;

  for (auto e : p) {
    --e;
    int si = e/n;
    int sj = e%n;
    queue<P> que;
    que.emplace(si, sj);
    ans += d[si][sj];
    vac[si][sj] = true;

    while (!que.empty()) {
      auto [i, j]  = que.front(); que.pop();
      rep(dir, dx.size()) {
        int ii = i + dx[dir];
        int jj = j + dy[dir];
        if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
        int dd = d[i][j] + 1 - vac[i][j];
        if (chmin(d[ii][jj], dd)) {
          que.emplace(ii, jj);
        }
      }
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5292
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string string[n];
	int cnt[4]={0};
	for(int i=0;i<n;i++){
		cin>>string[i];
//		cout<<string[i]<<endl;
		if(string[i]=="AC")
		cnt[0]++;
		
		else if(string[i]=="WA")
		cnt[1]++;
		
		else if(string[i]=="TLE")
		cnt[2]++;
		
		else if(string[i]=="RE")
		cnt[3]++;
	}
	cout<<"AC x "<<cnt[0]<<endl;
	cout<<"WA x "<<cnt[1]<<endl;
	cout<<"TLE x "<<cnt[2]<<endl;
	cout<<"RE x "<<cnt[3];
	
	
	
	return 0;
}

Measured memory_bytes: 6740
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n,v[101010];
int ans,t1[101010],t2[101010];//t1，t2存奇偶数位的桶
int m1,m2,i1,i2;//t1,t2中的一个数出现最大次数和该数是多少
int q1,q2;//t1,t2中的一个数出现次大次数
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&v[i]);
		if(i&1)
			t1[v[i]]++;
		else
			t2[v[i]]++;
	}
	for(int i=1;i<=100000;i++)
	{
		if(t1[i]>m1)
		{
			m1=t1[i];
			i1=i;
		}
		if(t2[i]>m2)
		{
			m2=t2[i];
			i2=i;
		}
	}
	if(i1!=i2)
		printf("%d",n-m1-m2);
	else
	{
		for(int i=1;i<=n;i++)
		{
			if(t1[i]>q1&&i!=i1)
				q1=t1[i];
			if(t2[i]>q2&&i!=i2)
				q2=t2[i];
		}
		printf("%d\n",min(n-m1-q2,n-m2-q1));
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int z = in.nextInt();
		int w = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
		}
		if(n==1) System.out.println(Math.abs(a[0]-w));
		else System.out.println(Math.max(Math.abs(a[n-1]-w), Math.abs(a[n-1]-a[n-2])));
		

	}

}


Measured memory_bytes: 26096
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    int x;
    cin>>x;
    cout<<x*x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;  // 階乗と階乗の逆元
  combination(int n):fact(n+1),ifact(n+1) {  // 階乗と階乗の逆元を n まで求める
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

  ll n, k;
  cin >> n >> k;

  mint ans;
  combination comb(k);
  for (ll i = 0; i <= k; i++) {
    mint tmp = comb(k, i) * mint(i).pow(n);
    if ((k-i) % 2 == 1) ans -= tmp;
    else ans += tmp;
  }

  for (ll m = k; m > 0; m--) ans /= m;

  cout << ans.x << endl;

  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>

using namespace std; using ll=long long; const int INF=1e2; using P=pair<ll,ll>;

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

  /*
  const int n=8;
  P p[n];
  for(int i=0;i<n;i++) {
    p[i].first = r::nd((int)1e2);
    p[i].second = r::nd((int)1e2);
  }

  cout<<n<<endl;
  for(int i=0;i<n;i++) cout<<p[i].first<<" "<<p[i].second<<endl;
  */

  P p[n];

  for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
  for(int i=0;i<n;i++) if (p[i].first > p[i].second) swap(p[i].first, p[i].second);

  sort(p,p+n);

  ll x[n], y[n];
  for(int i=0;i<n;i++) x[i]=p[i].first, y[i]=p[i].second;

  multiset<ll> s1, s2;
  for(int i=0;i<n;i++) {
    s1.insert(x[i]);
    s2.insert(y[i]);
  }

  ll an=1e18;
  for(int i=0;i<n;i++) {
    ll xx = (*(s1.rbegin()) - *(s1.begin()));
    ll yy = (*(s2.rbegin()) - *(s2.begin()));
    //cout<<i<<" "<<*(s1.rbegin())<<" "<<*(s1.begin())<<" "<<*(s2.rbegin())<<" "<<*(s2.begin())<<endl;
    an = min(an, xx * yy);

    auto it1 = s1.find(x[i]); // 重複削除回避
    auto it2 = s2.find(y[i]);
    s1.erase(it1); s1.insert(y[i]);
    s2.erase(it2); s2.insert(x[i]);
  }
  cout<<an<<endl;
  /*

  an = 1e18;
  for(int i=0;i<(1<<n);i++) {
    ll mx1 = -1e9, mn1 = 1e9, mx2 = -1e9, mn2 = 1e9;
    for(int j=0;j<n;j++) {
      if (i & (1<<j)) {
        mx1 = max(mx1, x[j]); mn1 = min(mn1, x[j]);
        mx2 = max(mx2, y[j]); mn2 = min(mn2, y[j]);
      } else {
        mx1 = max(mx1, y[j]); mn1 = min(mn1, y[j]);
        mx2 = max(mx2, x[j]); mn2 = min(mn2, x[j]);
      }
    }
    if ((mx1 - mn1) * (mx2 - mn2) == 4365) {
      int ii=i; string str;
      while(ii>0) str+=to_string(ii%2), ii/=2;
      reverse(str.begin(), str.end());
      cout<<str<<" "<<mx1<<" "<<mn1<<" "<<mx2<<" "<<mn2<<endl;
    }
    an = min(an, (mx1 - mn1) * (mx2 - mn2));
  }
  cout<<an<<endl;
  */
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A+B) > (C+D)) {
    cout << "Left" << endl;
  }
  else if ((A+B) == (C+D)) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int N;
vec<string> S;
vec<int> P;

signed main() {
	cin >> N;
	S.resize(N);
	P.resize(N);
	rep (i, N) {
		cin >> S[i] >> P[i];
	}

	vec<int> ord(N);
	iota(all(ord), 0);
	sort(all(ord), [&](int x, int y) {
		if (S[x] == S[y]) {
			return P[x] >= P[y];
		} else {
			return S[x] <= S[y];
		}
	});

	rep (i, N) {
		cout << ord[i] + 1 << 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 ll;
typedef pair<int, int> P;
const int INF = 1001001001;

signed main()
{
    int n, m, l; cin >> n >> m >> l;
    vector<vector<int>> dist(n, vector<int>(n, INF));
    rep (i,n) dist[i][i] = 0;
    rep(i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
    }

    rep(k,n)rep(i,n)rep(j,n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    vector<vector<int>> dist2(n, vector<int>(n, INF));
    rep(i,n)rep(j,n) {
        if (dist[i][j] <= l) dist2[i][j] = 1;
    }
    rep(k,n)rep(i,n)rep(j,n) dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
    int q;
    cin >> q;
    rep(qi, q) {
        int s,t; cin >> s >> t;
        --s; --t;
        int ans = dist2[s][t]-1;
        if (dist2[s][t] == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
//ALDS1_11B
#include <iostream>
#include <vector>
#include <cstdio>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int n;
int color[N],d[N],f[N],tt;
vector< vector<int> > M(N,vector<int>(N));

void dfs_visit(int u){
 int v;
 color[u]=GRAY;
 d[u]=++tt;
 for(v=0;v<n;v++){
  if(M[u][v]==0) continue;
  if(color[v]==WHITE){
   dfs_visit(v);
  }
 }
 color[u]=BLACK;
 f[u]=++tt;
}

void dfs(){
 int u;
 for(u=0;u<n;u++) color[u]=WHITE;
 tt=0;
 for(u=0;u<n;u++){
  if(color[u]==WHITE) dfs_visit(u);
 }
 for(u=0;u<n;u++){
  printf("%d %d %d\n",u+1,d[u],f[u]);
 }
}

int main(){
 int u,v,k,i,j;
 scanf("%d",&n);
 for(i=0;i<n;i++){
  scanf("%d %d",&u,&k);
  u--;
  for(j=0;j<k;j++){
   scanf("%d",&v);
   v--;
   M[u][v]=1;
  }
 }
 dfs();
 return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)

int main() {
	vector<char>a(26);
	a[0] = 'a';  a[1] = 'b'; a[2] = 'c'; a[3] = 'd'; a[4] = 'e'; a[5] = 'f'; a[6] = 'g'; a[7] = 'h'; a[8] = 'i'; a[9] = 'j'; a[10] = 'k'; a[11] = 'l'; a[12] = 'm'; a[13] = 'n'; a[14] = 'o'; a[15] = 'p'; a[16] = 'q'; a[17] = 'r'; a[18] = 's'; a[19] = 't'; a[20] = 'u'; a[21] = 'v'; a[22] = 'w'; a[23] = 'x'; a[24] = 'y'; a[25] = 'z';
	ll n; cin >> n;
	string ans ="";
	
	
	while (1) {
		if (n <= 26) {
			ans.push_back(a[n - 1]);
			break;
		}
		else {
			if (n % 26 == 0) {
				ans.push_back('z');
				n = n / 26 - 1;
			}
			else {
				ans.push_back(a[n % 26 - 1]);
				n = n / 26;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	

	return 0;
}

Measured memory_bytes: 3512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto hwk = readln.split.to!(int[]);
    auto H = hwk[0];
    auto W = hwk[1];
    auto K = hwk[2];

    long[] A, B;
    A.length = W;
    B.length = W;
    A[0] = 1;
    foreach (_; 0..H) {
        B[] = 0;
        foreach (w; 0..1<<(W-1)) {
            bool nxt;
            foreach (i; 0..W-2) if (!!(w & (1<<i)) && !!(w & (1<<(i+1)))) {
                nxt = true;
                break;
            }
            if (nxt) continue;
            foreach (i; 0..W) {
                if (i > 0 && (w & (1<<(i-1)))) {
                    B[i-1] = (B[i-1] + A[i]) % P;
                } else if (i < W-1 && (w & (1<<i))) {
                    B[i+1] = (B[i+1] + A[i]) % P;
                } else {
                    B[i] = (B[i] + A[i]) % P;
                }
            }
        }
        A[] = B[];
    }
    writeln(B[K-1]);
}

Measured memory_bytes: 256
n = int(input())

res = [0] * (n+1)
x = 1
while x*x <= n:
  y = 1
  while y*y <= n:
    z = 1
    while z*z <= n:
      w = x*x+y*y+z*z+x*y+y*z+z*x
      if w <= n:
        res[w] += 1
      z += 1
    y += 1
  x+= 1
  
for i in range(1,n+1):
  print(res[i])

Measured memory_bytes: 9196
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;                                                                                              

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}

int N,p[MaxN];

int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d", &N))
    {
        for(int i=1;i<=N;i++) read(p[i]);
        int ans = 0;
        for(int i=1;i<=N;i++)
        {
            if(p[i]==i) 
            {
                swap(p[i], p[i+1]);
                ans++;
            }
        }
        printf("%d\n", ans); 
    }
    // system("pause");
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b&&a>c&&b>c)
        printf("%d %d %d\n",c,b,a);
    else if(a>b&&c>a&&c>=b)
        printf("%d %d %d\n",b,a,c);
    else if(b>c&&b>a&&c>=a)
        printf("%d %d %d\n",a,c,b);
    else if(b>c&&b>a&&a>=c)
        printf("%d %d %d",c,a,b);
    else if(a>b&&a>c&&c>=b)
        printf("%d %d %d\n",b,c,a);
    else
        printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2100
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    odd_count = 0

    for ai in a:
        if ai % 2 == 1:
            odd_count += 1

    even_count = n - odd_count

    if odd_count % 2 == 1:
        if even_count > 0:
            print('NO')
            exit()
        elif even_count == 0 and odd_count == 1:
            print('NO')
            exit()
        else:
            print('YES')
            exit()
    else:
        print('YES')
        exit()


Measured memory_bytes: 14104
package main
import "fmt"
import "strings"
import "bufio"
import "os"

var sc = bufio.NewScanner(os.Stdin)

func main() {
var s string

if sc.Scan() {
  s = sc.Text()
}
  if strings.HasSuffix(s, "s"){
    s = s + "es"
  } else{
    s = s + "s"
  }
  fmt.Println(s)
}

Measured memory_bytes: 1780
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed compare(const void *a, const void *b){
	int sub = *(int *)a - *(int *)b;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

signed main(){
	int N, i, sumA = 0, sumB = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
		sumA += A[i];
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &B[i]);
		sumB += B[i];
	}
	if(sumA < sumB){
		printf("-1\n");
		return 0;
	}
	int *d = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		d[i] = A[i] - B[i];
	}
	qsort(d, N, sizeof(int), compare);
/*	for(i = 0; i < N; i++){
		printf("d[%d] = %d\n", i, d[i]);
	}
*/	int s = 0, j;
	for(i = 0; i < N && d[i] < 0; i++){
		s += d[i];
	}
	for(j = N - 1; j >= 0 && s < 0; j--){
		s += d[j];
	}
//	printf("(i, j) = (%d, %d)\n", i, j);
	printf("%lld\n", i - 1 + N - j);
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll N, M;

int main(){
	cin >> N >> M;
	
	vector<int> A(N);
	
	for ( int i = 0; i < N; i++ ){
		cin >> A[i];
	}
	sort(A.begin(),A.end()); // Aが小さい方から処理する
	
	vector<pii> BC(M);
	for ( int i = 0; i < M; i++ ){
		cin >> BC[i].first >> BC[i].second;
	}
	sort(BC.begin(),BC.end(),[](const pii &l, const pii &r){return l.second > r.second;}); // Cが大きいものから処理する
	
	int l = 0;
	for ( int i = 0; i < M; i++ ){
		while ( l < N && A[l] < BC[i].second && BC[i].first != 0 ){
			A[l] = BC[i].second;
			BC[i].first--;
			l++;
		}
	}
	
	ll sum = 0;
	for ( int i = 0; i < N; i++ )
		sum += A[i];
	cout << sum << endl;
	
	return 0;
}



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

int main()
{
  int h;
  int w;
  char c = '#';
  char point = '.';
  do 
  {
  cin >> h >> w;
  
  for(int i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
    {
      if(i == 0 || i == h - 1)
      {
        cout << c;
      }else if(j == 0 || j == w -1)
      {
        cout << c;
      }
      else
      {
        cout << point;
      }
    }
    cout << endl;
  }
    if (h != 0 && w != 0)
      cout << endl;
  }while(h != 0 && w != 0);
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535

int main() 
{
    FAST;
    ll k;
    cin>>k;
    set<ll> q;
    for(int i=1;i<10;i++)
        q.insert(i);
    ll in=1,x=1;
    while(in<=k)
    {
        x=*(q.begin());
        if(x%10!=0)
            q.insert((10*x)+(x%10)-1);
        q.insert((10*x)+(x%10));
        if(x%10!=9)
            q.insert((10*x)+(x%10)+1);
        q.erase(q.begin());
        in++;
    }
    cout<<x;
    return 0;
}

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

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

fn main() {
    let n = read::<usize>();
    let q = read::<usize>();
    let mut s = read::<String>().chars().collect::<Vec<char>>();
    let mut queries = vec![(0, 0); q];
    for i in 0..q {
        let l = read::<usize>();
        let r = read::<usize>();
        queries[i] = (l, r);
    }
    s.push('0');
    let mut cnts = vec![0; n + 1];
    for i in 0..n {
        cnts[i + 1] = cnts[i];
        if s[i] == 'A' && s[i + 1] == 'C' {
            cnts[i + 1] += 1;
        }
    }
    for i in 0..q {
        let ans = cnts[queries[i].1 - 1] - cnts[queries[i].0 - 1];
        println!("{}", ans);
    }
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int main()
{
   int n, k, l;
   cin >> n >> k >> l;
   UnionFind a(n), b(n);
   rep(i,k)
   {
      int p, q;
      cin >> p >> q;
      --p;--q;
      a.unite(p,q);
   }
   rep(i,l)
   {
      int r, s;
      cin >> r >> s;
      --r; --s;
      b.unite(r,s);
   }

   map<pair<int, int>, int> m;
   for (int i = 0; i < n; i++) {
      m[{a.root(i), b.root(i)}]++;
   }
   for (int i = 0; i < n; i++) {
      if (i) cout << ' ';
      cout << m[{a.root(i), b.root(i)}];
   }
   cout << endl;
}

Measured memory_bytes: 13568
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}
vector<pii>res;
void solve(){
	int n;
	cin>>n;
	if((n&-n)==n){cout<<"No";return;}
	cout<<"Yes\n";
	res.pb(pii(1,2));
	res.pb(pii(2,3));
	res.pb(pii(3,1+n));
	res.pb(pii(1+n,2+n));
	res.pb(pii(2+n,3+n));
	//int pre1=1,pre2=1;
	for(int i=4;i<n;i+=2){
		res.pb(pii(i,1));
		res.pb(pii(i+1,i));
		res.pb(pii(n+i+1,1));
		res.pb(pii(n+i,n+1+i));
		//pre1=i+1;
		//pre2=n+i;
	}
	if(n%2==0){
		res.pb(pii(n,n+n-1));
		int x=n^(n-1)^1;
		if(x&1)x+=n;
		res.pb(pii(n+n,x));
	}
	for(pii p:res)cout<<p.fi<<" "<<p.se<<"\n";
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

typedef long long ll;
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(ll i = ll(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const long long INF = 1LL << 60;

// 降順ソート
// std::sort(data.begin(),data.end(),std::greater<ll>());
// 昇順ソート
// std::sort(data.begin(),data.end());

// vector型の「data」に xが存在するかを、True or Falseで返す
// vector_finder(data, x)
bool vector_finder(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
  }
  else { // 発見できなかったとき
    return false;
  }
}

// ここから開始だよ！
ll N;
std::vector<ll> v;
ll counts = 0;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
	ll max = 0;
	cin >> N;
	rep(i, N) {
		ll tmp;
		cin >> tmp;
		v.push_back(tmp);
		if (max < tmp) {
			max = tmp;
		}
	}
	
	bool renFlg = false;
	rerep(i, max+1) {
		//cout << v << " " << counts <<  endl;
		rep(j, v.size()) {
			if (v[j] == i) {
				renFlg = true;
				v[j] -= 1;
				continue;
			}
			if(renFlg == true) {
				counts += 1;
				renFlg = false;
			}
		}
		if(renFlg == true) {
			counts += 1;
			renFlg = false;
		}
	}
	
	cout << counts -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
int A,B,H,M;
double E;


int main()
{
    cin >>  A >> B >> H >> M;
    double L,S;
    S=M*6*M_PI/180;
    L=(H*30*M_PI/180)+(S/12);
    if(fabs(S-L)<=M_PI){
        E=pow(A*A+B*B-2*A*B*cos(fabs(S-L)),0.5);
    }else{
        E=pow(A*A+B*B-2*A*B*cos(2*M_PI-fabs(S-L)),0.5);
    }
    
    cout<< fixed << setprecision(20) << E <<endl;
} 

Measured memory_bytes: 4356