akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,n;cin >> x >> n;
    ll p[101];
    memset(p, 0, sizeof(p));
    for (int i = 0; i < n; ++i)
    {
    	ll d;cin >> d;
    	p[d]=1;
    }
    int ans=x;int dans=0;
    for(int i=1;i<=100;i++)
    {
    	if(!p[i])
    	{
    		if(llabs(x-i)<ans)
    		{
    			ans=llabs(x-i);dans=i;
    		}
    	}
    }
    if(101-x<ans)dans=101;
    cout << dans;
    }

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	if(n==m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
  ll n,m;
  cin >> n >> m;
  ll ans = 0;
  if(n * 2 >= m){
    ll temp = m / 2;
    n -= temp;
    m -= temp * 2;
    ans += temp;
  }else{
    ans += n;
    m -= n * 2;
  }
  ans += m / 4;
  cout << ans << endl;
}

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

int main(){
  while (true){
    int H, W;
    cin >> H >> W;
    if (H==0 && W==0) break;
    for (int i=1; i<=H; i++){
      for (int j=1; j<=W; j++){
	if (i%2 == j%2) cout << '#';
	else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 044 A / Link: http://abc044.contest.atcoder.jp/tasks/abc044_a  ----- */


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

	LL N, K, X, Y; cin >> N >> K >> X >> Y;
	LL ans = (N<=K?X*N:K*X+(N-K)*Y);
	
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll cnt[100005];
vector<ll> p, a, b, c;

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

	p.resize(m);
	rep(i, m) {
		cin >> p[i];
		p[i]--;
	}

	a.resize(n-1);
	b.resize(n-1);
	c.resize(n-1);

	rep(i, n-1) {
		cin >> a[i] >> b[i] >> c[i];
	}

	rep(i, m-1) {
		if(p[i] == p[i+1]) continue;

		if(p[i] < p[i+1]) {
			cnt[p[i]]++;
			cnt[p[i+1]]--;
		} else {
			cnt[p[i+1]]++;
			cnt[p[i]]--;
		}
	}

	rep(i, 100005) {
		cnt[i+1] += cnt[i];
	}

	ll ans = 0;
	rep(i, n-1) {
		ans += min(cnt[i] * a[i], cnt[i] * b[i] + c[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5012
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b, c, holes;
    cin >> a >> b >> c, holes = 3 * max({a, b, c}) - (a + b + c);
    if (holes & 1) holes += 3;
    cout << holes / 2 << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
long N,A,B;
scanf("%ld%ld%ld",&N,&A,&B);
long i,a[100000];
for(i=0;i<N;i++){
scanf("%ld",&a[i]);
}
long sum=0;
for(i=0;i<N-1;i++){
if(A*(a[i+1]-a[i])>=B){
sum+=B;
}
else{
sum+=A*(a[i+1]-a[i]);
}
}
printf("%ld",sum);
}


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

int main() {
  int h, w, i, j, dx[8] = {0,1,0,-1,1,1,-1,-1}, dy[8] = {1,0,-1,0,1,-1,1,-1};
  string s[50];
  cin >> h >> w;
  for(i=0; i<h; i++) cin >> s[i];
  for(i=0; i<h; i++){
    for(j=0; j<w; j++){
      int num=0, k;
      if(s[i].at(j) != '#'){
		for(k=0; k<8; k++){
          int x=j+dx[k], y=i+dy[k];
          if(x>=0 && x<=w-1 && y>=0 && y<=h-1 && s[y].at(x) == '#') num++; 
        }
        s[i].at(j) = to_string(num).at(0);
      }
    }
  }
  for(i=0; i<h; i++) cout << s[i] << endl;  
}


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

def abc154a(s, t, a, b, u):
    if(s == u):
        a -= 1
    else:
        b -= 1
    return(a, b)

###
# main
if(__name__ == '__main__'):
    # input
    (s, t) = input().split()
    (a, b) = map(int, input().split())
    u = input()
    
    (new_a, new_b) = abc154a(s, t, a, b, u)
    
    # output
    print(str(new_a) + " " + str(new_b))
# else:
    # do nothing


Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
    
    cout << endl;
}


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())

if a+b > 2*c:
  if x <= y:
    ans = x*c*2 + (y-x)*min(b,2*c)
  elif y < x:
    ans = y*c*2 + (x-y)*min(a,2*c)
    
else:
  ans = x*a + y*b
  
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    if (x+r<=W && y+r<=H && x-r>=0 && y-r>=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}


Measured memory_bytes: 3116
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ll long long
using namespace std;

void solve() {
    ll n, k, prev = 1e15;
    cin >> n >> k;
    unordered_map<ll, bool> vis;
    ll ans = 1e18;
    while(true) {
        if (vis[n])
            break;
        vis[n] = true;
        ans = min(ans, n);
        n = abs(n - k) % k;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("input.txt", "r", stdin);
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

out = []
for i in range(len(S)):
    for j in range(26):
        if S[i] == alf[j]:
            k = (j + N) % 26
            out.append(alf[k])

print("".join(out))

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

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

const long long INF = 1LL << 60;

vector<long long> h(100010);
long long dp[100010];

int rec(int i)  {
    if (i == 0) {
        return 0;
    }
    if (dp[i] < INF) {
        return dp[i];
    }
    
    long long res = INF;
    chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
    if (i > 1) {
        chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));
    }
    return dp[i] = res;
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        scanf("%lld", &h[i]);
    }
    for (int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }

    cout << rec(N - 1) << endl;

    return 0;
}

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

const int MAX = 510000;
const int mod = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
    long long n,a,b,k;
    cin>>n>>a>>b>>k;
    long long ans=0;
    COMinit();
    for(long long red=0;red<=n;red++){
        long long m=k-a*red;
        if(m%b!=0) continue;
        long long blue=m/b;
        ans+=COM(n,red)*COM(n,blue);
        ans%=mod;

    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 12160
#include <stdint.h>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int64_t L, R;
  cin >> L >> R;

  vector<int64_t> a;
  a.reserve(2020);
  for (int64_t i = L; i <= R; ++i) {
    if (a.size() > size_t(2019)) break;
    a.emplace_back(i % 2019);
  }

  int64_t ans = 2018;

  for (size_t i = 0; i < a.size(); ++i) {
    for (size_t j = i + 1; j < a.size(); ++j) {
      ans = min(ans, a[i] * a[j] % 2019);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	sort(h.begin(),h.end());
	rep(i, n - k) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	int n, num[11][11];
	while (1) {
		if (cin >> n, !n) break;
		
		for (int i=0; i<11; i++) for (int j=0; j<11; j++) num[i][j] = 0;
		
		for (int i=0; i<n; i++) for (int j=0; j<n; j++) cin >> num[i][j];
		
		for (int i=0; i<10; i++)
			for (int j=0; j<10; j++) num[10][i] += num[j][i];
		
		for (int i=0; i<11; i++)
			for (int j=0; j<10; j++) num[i][10] += num[i][j];
		
		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {if ((i<n && j<n) || (i==10 && j<n) || (j==10 && i<n) || (j==10 && i==10)) {cout.width(5); cout << num[i][j];}}
			if ((i < n) || (i == 10))  cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const ll MAX_N = 1E+05;
const ll MOD = 1E+09 + 7;

int N, M;

ll X[MAX_N], Y[MAX_N];
ll sumx[MAX_N], sumy[MAX_N];

ll solve();

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

    cin >> N >> M;

    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> Y[i];
    }

    cout << solve() << "\n";

    return 0;
}

ll solve()
{
    ll dsum = M - 3;
    sumy[0] = M - 1;
    sumy[M - 2] = sumy[0];
    for (int i = 1; dsum >= 1; i++) {
        sumy[i] = (sumy[i - 1] + dsum) % MOD;
        sumy[M - i - 2] = sumy[i];
        dsum -= 2;
    }

    ll yline = 0;
    for (int i = 0; i < M - 1; i++) {
        yline = (yline + ((Y[i + 1] - Y[i]) % MOD) * sumy[i]) % MOD;
    }

    dsum = N - 3;
    sumx[0] = N - 1;
    sumx[N - 2] = sumx[0];
    for (int i = 1; dsum >= 1; i++) {
        sumx[i] = (sumx[i - 1] + dsum) % MOD;
        sumx[N - i - 2] = sumx[i];
        dsum -= 2;
    }

    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        ans = (ans + yline * ((((X[i + 1] - X[i]) % MOD) * sumx[i]) % MOD)) % MOD;
    }

    return ans;
}

Measured memory_bytes: 6744
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#include<algorithm>
#include<queue>
typedef long long ll;
#include<vector>
#include<set>
#define cin(n) scanf("%lld",&(n))
#define cout(n) printf("%lld",(n))
#define couc(c) printf("%c",(c))
#define coutn printf("\n")
#define cout_ printf(" ")
set<int> s;
const int MAXN= 1e4 + 5 ;
ll n;
ll ans;
void dfs(ll l,ll a,ll b,ll c)
{
    if(l>n)    return;
    if(a>=1&&b>=1&&c>=1) ans++;
    dfs(l*10+3,a+1,b,c);
    dfs(l*10+5,a,b+1,c);
    dfs(l*10+7,a,b,c+1);
}
int main()
{
    scanf("%lld",&n);
    dfs(0,0,0,0);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
array = list(map(int,input().split(" ")))
arra = []
i = 0
while i < N:
  arra.append(array[i]-(i+1))
  i+=1
arra.sort()
if N%2 == 0:
  m = int((0.5)*(arra[int(N/2)-1]+arra[int(N/2)]))
else:
  m = arra[int((N-1)/2)]
j = 0
sum = 0
while j < N:
  sum+=abs(array[j]-(m+j+1))
  j+=1
print(int(sum))

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

def divisor(n: int) -> list:
    list_of_divisor = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            list_of_divisor.append(i)
            if i != n//i:
                list_of_divisor.append(n//i)
    list_of_divisor.sort()
    return list_of_divisor

li = divisor(n)
num = len(li)
if num % 2 == 0:
    # print(li[num//2-1], li[num//2])
    if li[num//2-1] == 1:
        print(li[num//2]-1)
    else:
        print((li[num//2-1]-1)+(li[num//2]-1))
else:
    print((li[num//2]-1)*2)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

bool is_ok(vector<int> &v, vector<int> &op)
{
    int ans = v[0];
    rep(i, 3)
    {
        if (op[i] == 0)
        {
            ans += v[i + 1];
        }
        else
        {
            ans -= v[i + 1];
        }
    }
    return ans == 7;
}

int main(int argc, char const *argv[])
{
    vector<int> v(4);
    string s;
    cin >> s;
    rep(i, 4)
    {
        v[i] = s[i] - '0';
    }
    vector<int> op(3);
    rep(i, 8)
    {
        op[0] = (i >> 0) & 1;
        op[1] = (i >> 1) & 1;
        op[2] = (i >> 2) & 1;
        if (is_ok(v, op))
        {
            cout << v[0];
            rep(j, 3)
            {
                cout << (op[j] == 0 ? '+' : '-');
                cout << v[j + 1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

int main(void){
	int n,de,res=0,tmp;	
	cin >> n;
	vector<int> l;
	l.resize(n);
	for(int i=0;i<n;++i){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	for(int i=n-1;i>=0;--i){
		for(int j=i-1;j>=0;--j){
			de = l[i] - l[j];
			auto itt = upper_bound(l.begin(),l.begin()+j,de);
			tmp = int(itt - l.begin());
			if(j - tmp > 0)res += j - tmp;
 		}
	}
	cout << res << endl;
}

/*

*/

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

typedef long long ll;
const ll INF = 1LL << 60;

ll dp[110][(int)(2 * 1e5)];

ll N, W;
vector<ll> w, v;

int main() {
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    rep(i, N) cin >> w[i] >> v[i];

    rep(i, N + 1)rep(j, 2 * 1e5) {
       dp[i][j] = INF; 
    }
    ll limit_v = accumulate(v.begin(), v.end(), 0LL);
    // cout << limit_v << endl;

    dp[0][0] = 0;
    rep(i, N)rep(j, 2 * 1e5) {
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        // if (j + v[i] > limit_v) continue;
        dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
        // printf("i + 1 %lld j + v[i] %lld w: %lld\n", i + 1, j + v[i], dp[i][j] + w[i]);
    }

    // rep(j, 150) {
    //     cout << dp[N][j] << endl;
    // }
    ll ans = 0;
    rep(j, 2 * 1e5) {
        if (j > limit_v) continue;
        if (dp[N][j] <= W) ans = j;
    }
    cout << ans << endl;
}

Measured memory_bytes: 160000
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    unordered_map<int64_t, int64_t> count;
    for (auto _ : irange(0L, n)) {
        int64_t a;
        cin >> a;

        ++count[a];
    }

    if (count.size() <= k) {
        cout << 0 << endl;
        return 0;
    }

    vector<int64_t> nums;
    for (const auto& kv : count) {
        nums.push_back(kv.second);
    }

    sort(nums.rbegin(), nums.rend());

    int64_t ans = 0;
    for (int64_t i = k; i < nums.size(); ++i) {
        ans += nums[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 11592
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int x,y;
    cin>>x>>y;
    if(x*2<=y && y<=x*4 && y%2==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

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

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

const int MN = 200010;

int N;
vector<int> adj[MN];
int par[MN], V[MN], fa[MN];
void init() {
    for(int i = 0; i < N; i++) fa[i] = i;
}
int find(int u) {
    if(fa[u] == u) return u;
    else return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
    u = find(u);
    v = find(v);
    fa[v] = u;
}

struct Info {
    int u, c0, c1;
    bool operator <(const Info &i) const {
        if(c1 == 0) return false;
        if(i.c1 == 0) return true;
        return 1LL * c0 * i.c1 < 1LL * c1 * i.c0;
    }
};
priority_queue<Info> pq;
int C0[MN], C1[MN];

int main() {
    scanf("%d", &N);

    for(int i = 1; i < N; i++) {
        scanf("%d", &par[i]);
        par[i]--;
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", &V[i]);
    }
    for(int i = 0; i < N; i++) {
        pq.push({ i, !V[i], V[i] });
        C0[i] = !V[i];
        C1[i] = V[i];
    }

    init();
    ll ans = 0;
    while(!pq.empty()) {
        Info t = pq.top(); pq.pop();

        int u = t.u;
        int p = find(par[u]);
        int c0 = t.c0;
        int c1 = t.c1;
        if(!u || c0 != C0[u] || c1 != C1[u]) continue;

        //cout << u + 1 << ' ' << p + 1 << ' ' << c0 << ' ' << c1 << endl;

        ans += 1LL * C1[p] * C0[u];

        mrg(p, u);
        C0[p] += C0[u];
        C1[p] += C1[u];
        C0[u] = 0;
        C1[u] = 0;
        if(p) pq.push({ p, C0[p], C1[p] });
    }
    printf("%lld", ans);
}


Measured memory_bytes: 13168
from collections import deque
H,W = map(int,input().split())
src = [input() for i in range(H)]
walls = 0
for row in src:
    walls += row.count('#')

visited = [[0 for j in range(W)] for i in range(H)]
q = deque([(0,0,0)])
dxs = [1,0,-1,0]
dys = [0,1,0,-1]
while q:
    d,x,y = q.popleft()
    if (x,y) == (W-1,H-1):
        print(H*W - walls - d - 1)
        exit()
    for dx,dy in zip(dxs,dys):
        nx,ny = x+dx, y+dy
        if not(0 <= nx < W) or not(0 <= ny < H): continue
        if src[ny][nx] == '#' or visited[ny][nx]: continue
        q.append((d+1,nx,ny))
        visited[ny][nx] = 1

print(-1)


Measured memory_bytes: 3316
#include <stdio.h>
int main() {

    int a,b,c;

    scanf ("%d %d %d",&a,&b,&c);

    if(a <= b && b <= c) printf("%d %d %d\n",a,b,c);
    else if(a <= c && c <= b) printf("%d %d %d\n",a,c,b);
    else if(c <= a && a <= b) printf("%d %d %d\n",c,a,b);
    else if(c <= b && b <= a) printf("%d %d %d\n",c,b,a);
    else if(b <= c && c <= a) printf("%d %d %d\n",b,c,a);
    else printf("%d %d %d\n",b,a,c);

    return 0;
}

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

using namespace std;

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

  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) 
    cin >> c[i][0] >> c[i][1] >> c[i][2];

  for (int a1 = 0; a1 < 101; ++a1) 
    for (int a2 = 0; a2 < 101; ++a2) 
      for (int a3 = 0; a3 < 101; ++a3) {
        int A = c[0][0]-a1;
        int B = c[0][1]-a1;
        int C = c[0][2]-a1;
        if ((  (c[1][0]-a2) == A && A == (c[2][0]-a3))
            &&((c[1][1]-a2) == B && B == (c[2][1]-a3))
            &&((c[1][2]-a2) == C && C ==(c[2][2]-a3))) {
          cout << "Yes" << endl;
          return 0;
        }
      }
  cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#import<bits/stdc++.h>
#define LL long long
using namespace std;
typedef struct{int x;int y;}H;
long long a,b,c,d,i,j,k,m=2018,n,s,t,x,y,z,w[11][11];
int pv[300000];
char h,u[105];
H e[200040];
queue<int>B,D;
int A(H a,H b){return a.x<b.x||a.x==b.x&&a.y<b.y;}
void BP(void);
void bfs(int s);
void dfs(int s);
int dgs(int x){int s=0;for(;x;x/=10)s+=x%10;return s;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int max2(int x,int y){return x>y?x:y;}
int max3(int x,int y,int z){return x>y?x>z?x:z:y>z?y:z;}
int min2(int x,int y){return x<y?x:y;}
int min3(int x,int y,int z){return x<y?x<z?x:z:y<z?y:z;}
int prime(int x){if(x<2||x%6^1&&x%6^5)return x==2|x==3;for(int i=5;i*i<=x;i+=6)if(x%i<1||x%(i+2)<1)return 0;return 1;}
int vowel(char x){return x%32==1||x%32==5||x%32==9||x%32==15||x%32==21;}
int Q(int m){int y=(int)(sqrt((double)(m)));if(y*y==m)return 1;else return 0;}
main()
{
	scanf("%lld%lld",&a,&b);c=a+2018<b?a+2018:b;
	for(i=a;i<=c;i++)for(j=i;j++<(i+2019<b?i+2019:b);)m=min2(m,i*j%2019);
	printf("%lld",m);
}
/*void BP(void)
{
	for(int i=0;e[++i].x;)
	{
		if(e[i].x>e[i-1].x)
		{
			for(int j=e[i-1].x;j++<e[i].x;)
			{
				pv[j]=i;
			}
		}
	}
}
void bfs(int s)
{
	
}
void dfs(int s)
{
	
}*/

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

int main(){
	int a,b,x;
	cin>>x>>a>>b;
	int f=abs(x-b);
	int m=abs(x-a);
	if(f<m) cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}


Measured memory_bytes: 256
# encoding: utf-8
sx, sy, tx, ty = map(int, input().split())

pos = (sx, sy)

# s left out -> t top in
print("L", end="")
for i in range(ty - sy + 1): print("U", end="")
for i in range(tx - sx + 1): print("R", end="")
print("D", end="")

# t right out -> s bottom in
print("R", end="")
for i in range(ty - sy + 1): print("D", end="")
for i in range(tx - sx + 1): print("L", end="")
print("U", end="")

# s top out -> t left in
for i in range(ty - sy): print("U", end="")
for i in range(tx - sx): print("R", end="")

# t bottom out -> s right in
for i in range(ty - sy): print("D", end="")
for i in range(tx - sx): print("L", end="")
print("")

Measured memory_bytes: 4468
class Unionfind
    @par
    
    def initialize(n)
        @par=[nil]*n
        n.times{|i| @par[i]=i}
    end
    
    def root(x)
        return x if @par[x]==x
        return @par[x] = root(@par[x])
    end
    
    def unite(x,y)
        rx=root(x)
        ry=root(y)
        return if rx==ry
        @par[rx]=ry
    end
    
    def same?(x,y)
        rx=root(x)
        ry=root(y)
        return rx==ry
    end
end

n,m=gets.split.map(&:to_i)
arr=gets.split.map(&:to_i)
tree = Unionfind.new(n)

m.times do
    a,b=gets.split.map(&:to_i)
    tree.unite(a-1,b-1)
end

count=0
#p tree,arr

n.times do |i|
    if tree.same?(i,arr[i]-1)
        count+=1
    end
end

p count


Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
#define quick ios::sync_with_stdio(false);cin.tie();

int main() 
{
  cout << fixed << setprecision(15);
  int n, k;
  cin >> n >> k;
  vector<bool> v(n, false);
  for (int i = 0; i < n; i++) 
  {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++)
    {
      int y;
      cin >> y;
      v[y - 1] = true;
    }
  }
  int tot = 0;
  for (int i = 0; i < n; i++)
  {
    if (v[i] == false)
    {
      tot++;
    }
  }
  cout << tot << "\n";
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
template <typename T>
#define all(v) v.begin(),v.end()
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
    tc = 1;  
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        int ans = 0;
        ans = (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
        cout << ans << endl;
    }

    return 0;
}


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

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

using namespace std;

int max_multi(int x)
{
	int maximum = 0;
	int y = 1;
	rep(i, 5){
		int a, b;
		y *= 10;
		a = x / y;
		b = x - a * y;
		maximum = max(maximum, a * b);
	}
	return maximum;
}

int main(void)
{
	int Q;
	cin >> Q;
	rep(i, Q){
		int N, cnt = 0;
		cin >> N;
		//Nが一桁になるまで繰り返す
		while(N >= 10){
			N = max_multi(N);
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    int a[100000];
    for(int i=0;i<N;i++)
        cin >> a[i];
    
    int ans = 0, g = 0;
    for(int i=1;i<N;i++){
        if(a[i-1] < a[i]){
            if(g == -1){
                ans++;
                g = 0;
            }else{
                g = 1;
            }
        }
        if(a[i-1] > a[i]){
            if(g == 1){
                ans++;
                g = 0;
            }else{
                g = -1;
            }
        }
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;
  set<char> se;

  rep(i, si(s)) se.ep(s[i]);
  rep(i, 26) {
    char c = 'a' + i;

    if (!se.count(c)) {
      cout << c << endl;
      return (0);
    }
  }

  cout << "None\n";

  return (0);
}


Measured memory_bytes: 3768
use std::io;


fn main() {
    let n = read_one::<String>().chars().collect::<Vec<char>>();
    if n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3] {
        println!("Yes");
    } else {
        println!("No");
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	int a = dup(N, 1000);
	int ans = 1000 * a - N;
	cout << ans;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
A,V = map(int,input().split(' '))
B,W = map(int,input().split(' '))
T = int(input())
if A <= B :
    print('YES' if T*V+A >= T*W+B else 'NO')
else:
    print('YES' if T*V-A >= T*W-B else 'NO')

Measured memory_bytes: 9188
import itertools
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = list(itertools.accumulate(a))
cnt = 0
for i in range(n):
    if i==n-1 and a[-1]!=x:
        pass
    elif a[i]<=x:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
#define cy cout << "Yes" << endl;
#define cn cout << "No" << endl ;
typedef long long ll ;


int main(){
    ll k ;
    ll n , m ;
    cin >> k ;
    cin >> n >> m ;
    for(ll i = n ; i <= m ; i++){
        if(i % k == 0 ){
            cout << "OK" << endl;
            return 0 ;
        }
    }
    cout << "NG" << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

ll pow(ll a, int b) {
	ll c = 1;
	while(b > 0) {
		c*=a;
		b--;
	}
	return c;
}
int main() {

	ll n;
	cin >> n;
	ll ans = 0;
	if (n % 2 == 1) ans = 0;
	else {
		ll a = 2;
		while(a <= n) {
			a *= 5;
			ans += n / a;
		}
	}
	cout << ans << endl;

  return 0;
}


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

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

//#define DEBUG

#ifdef DEBUG

#define printd printf

#else

#define printd(...)

#endif

template <typename T>
void print_vec(std::vector<T> &v)
{
    std::cout << "{ ";
    for (auto &&i : v)
    {
        std::cout << i << ", ";
    }
    std::cout << "} " << std::endl;
}

int main() {
    constexpr int inf = 100000;
    int n, m;
    std::cin >> n >> m;
    std::vector<int> coins(m + 1, 0);
    for (size_t i = 0; i < m; i++) {
        std::cin >> coins[i];
    }

    // dp
    std::vector<int> dp(n + 1, inf);
    dp[0] = 0;
    for (size_t i = 0; i <= n; i++) {
        for (size_t j = 0; j < m; j++) {
            if (i + coins[j] > n) {
                continue;
            }
            dp[i + coins[j]] = std::min(dp[i + coins[j]], dp[i] + 1);
        }
    }

    #ifdef DEBUG
    print_vec(dp);
    #endif
    
    std::cout << dp[n] << std::endl;
    
    return 0;
}



Measured memory_bytes: 3180
from heapq import heapify, heappop, heappush

N, M = [int(i) for i in input().split()]
A =  [-int(i) for i in input().split()]

heapify(A)
#print(A)
for i in range(M): 
    x = heappop(A)
    heappush(A, x/2)
    #print(i, A)
    
print(sum([-int(a) for a in A]))

Measured memory_bytes: 14180
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let vec: Vec<&str> = s.trim().split_whitespace().collect();
    let ret: i32 = vec.join("").parse().unwrap();
    if ret % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
use std::io;
use std::collections::HashMap;


/// 23:20 ~ 23:52
fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let an = read::<usize>();
    let mut rem = HashMap::new();
    let mut cs = vec![0; n];
    cs[0] = an[0] % m;
    *rem.entry(cs[0]).or_insert(0) += 1;

    for i in 1..n {
        cs[i] = (cs[i - 1] + an[i]) % m;
        *rem.entry(cs[i]).or_insert(0) += 1;
    }

    let ans = rem.iter()
        .map(|(_, &num)| if num >= 2 { ncr(num, 2) } else { 0 })
        .sum::<usize>();

    println!("{}", ans + rem.get(&0).unwrap_or(&0));
}

fn ncr(n: usize, r: usize) -> usize {
    match (n, r) {
        (0, _) | (_, 0) => 1,
        _ => ncr(n, r - 1) * (n - r + 1) / r,
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 14588
#include <stdio.h>
#include <math.h>

int main(void){
	long long int n=1,as=1;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		as=as*i;
		as=as%(1000000000+7);

	}
	printf("%lld\n",as);

	return 0;
}


Measured memory_bytes: 128
import sys

stdin = sys.stdin

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

n = ni()
a = na()

dic = {}

for num in a:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

ans = 0
for key,value in dic.items():
    if key > value:
        ans += value
    else:
        ans += (value - key)

print(ans)


Measured memory_bytes: 17700
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    int A1 = scanner.nextInt();
		    int A2 = scanner.nextInt();
		    int A3 = scanner.nextInt();
		    
		    int max = A1;
		    int min = A1;
		    if(A2 > max) 
		    {
		    	max = A2;
		    }
		    if(A2 < min) 
		    {
		    	min = A2;
		    }
		    if(A3 > max) 
		    {
		    	max = A3;
		    }
		    if(A3 < min) 
		    {
		    	min = A3;
		    }
		    System.out.println(max - min);
		    scanner.close();}
		  }

Measured memory_bytes: 22996
N = int(input())
f = [0 for i in range(N+1)]
for x in range(1, 101):
	if x*x >= N:
		break
	for y in range(1, 101):
		if x*x + y*y + x*y >= N:
			break
		for z in range(1, 101):
			a = x*x + y*y + z*z + x*y + y*z + z*x
			if a > N:
				break
			f[a] += 1
for i in range(1, N+1):
	print(f[i])

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

int main()
{
    long long N;
    cin >> N;
    long long c = N*(N+1)/2;
    long long j = N / 3;
    long long k = N / 5;
    long long l = N / 15;
    c = c - 3*j*(j+1)/2 - 5*k*(k+1)/2 + 15*l*(l+1)/2;
    cout << c;
}




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

int main(){
  int s;
  cin >> s;
  int f=s/100, l=s%100;
  if(f==0 || f>12){
    if(l==0 || l>12)cout << "NA";
    else cout << "YYMM";
  }
  else {
    if(l==0 || l>12)cout << "MMYY";
    else cout << "AMBIGUOUS";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector <vector <int> > dp(501,vector <int> (501));
vector <vector <int> > v(501,vector <int> (501,1));
int n;
void update(int i,int j){
    dp[i][j]--;
    if(i-1>0){
        if(v[i-1][j]==1&&dp[i-1][j]-dp[i][j]>1)update(i-1,j);
        else if(v[i-1][j]==0&&dp[i-1][j]-dp[i][j]>0)update(i-1,j);
    }
    if(j-1>0){
        if(v[i][j-1]==1&&dp[i][j-1]-dp[i][j]>1)update(i,j-1);
        else if(v[i][j-1]==0&&dp[i][j-1]-dp[i][j]>0)update(i,j-1);
    }
    if(i+1<=n){
        if(v[i+1][j]==1&&dp[i+1][j]-dp[i][j]>1)update(i+1,j);
        else if(v[i+1][j]==0&&dp[i+1][j]-dp[i][j]>0)update(i+1,j);
    }
    if(j+1<=n){
        if(v[i][j+1]==1&&dp[i][j+1]-dp[i][j]>1)update(i,j+1);
        else if(v[i][j+1]==0&&dp[i][j+1]-dp[i][j]>0)update(i,j+1);
    }
}
int solve(int x){
    int i=ceil((double)x/n);
    int j=x%n;
    if(j==0)j=n;
    int ans=dp[i][j]-1;
    v[i][j]=0;
    update(i,j);
    /*for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;*/
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //int n;
    cin>>n;
    vector <int> p(n*n);
    for(int i=0;i<n*n;i++)cin>>p[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int k=min(i,n-i+1);
            int l=min(j,n-j+1);
            dp[i][j]=min(k,l);
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    
    ll ans=0;
    for(int i=0;i<n*n;i++){
        ans+=solve(p[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 24980
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	cin >> a;
	cin >> b;
	if (a.length() > b.length()) {
		cout << "GREATER" << endl;
		return 0;
	}
	else if (a.length() < b.length()) {
		cout << "LESS" << endl;
		return 0;
	}
	for (int i = 0; i < a.length(); i++) {
		if (a.at(i) == b.at(i)) continue;
		else if (a.at(i) > b.at(i)) {
			cout << "GREATER" << endl;
			return 0;
		}
		else {
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

ll n, x[1010], y[1010];
bool fl;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> y[i];
		if (!i)fl = abs(x[i] + y[i]) % 2 ? 1 : 0;
		else {
			if (abs(x[i] + y[i]) % 2 && !fl) {
				cout << -1 << endl;
				return 0;
			}
			if (!(abs(x[i] + y[i]) % 2) && fl) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	
	vector<ll> d;
	for (int i = 30; i >= 0; i--) d.push_back(1LL << i);
	if (!fl) d.push_back(1);
	cout << d.size() << endl;
	for (int i = 0; i < d.size(); i++) cout << d[i] << " ";
	cout << endl;

	for (int i = 0; i < n; i++) {
		ll xt = x[i], yt = y[i];
		ll x = 0, y = 0;
		for (int j = 0; j < (int)d.size(); j++) {
			if (abs(x - xt) >= abs(y - yt)) {
				if (x >= xt) x -= d[j], cout << "L";
				else x += d[j], cout << "R";
			}
			else {
				if (y >= yt) y -= d[j], cout << "D";
				else y += d[j], cout << "U";
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int P[3], J[2];

int main(void) {
  REP(i, 0, 3) cin >> P[i];
  REP(i, 0, 2) cin >> J[i];

  int ans = INT_MAX;
  REP(i, 0, 3) {
    REP(j, 0, 2) {
      ans = min(ans, P[i] + J[j] - 50);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1160
#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<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define reo(i,n) for(int (i) = 1 ; (i) <= (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define mkp make_pair
#define mem0(x) memset(x,0,sizeof(x))
#define vec vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ 0,0,-1,1 }, dy{ 1,-1,0,0 };
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; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : 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
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 600000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------------------
int dp[20][20];
signed main() {
	int n;
	cin >> n;
	rng(i, 1, n + 1) {
		string s = to_string(i);
		dp[(int)(s[0] - '0')][(int)(s[s.size() - 1] - '0')]++;
	}
	int ans = 0;
	rep(i, 10) {
		rep(j, 10) {
			ans += dp[i][j] * dp[j][i];
		}
	}
	cout << ans << endl;
}

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

vst = [False for i in range(N)]
plc = [0]

for i in range(N):
    mm = plc[-1]
    mm2 = A[mm]-1
    if vst[mm2]:
        break
    vst[mm] = True
    plc.append(A[mm]-1)

li = []
flg = False
for i in range(len(plc)):
    if plc[i]==mm2:
        flg = True

    if not(flg):
        continue

    li.append(plc[i])

# for i in A:
#     print(i-1," ",end="")


ans = (K-len(plc))%len(li)
if (K-len(plc)) >=0:
    print(li[ans]+1)
else:
    print(plc[K]+1)



Measured memory_bytes: 32388
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    ll ans = 1;

    ll r = 1e18;

    vector<ll> a(n);

    for (auto &x : a)
    {
        cin >> x;
        if (x == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (1000000000000000000 / ans < a[i])
        {
            cout << -1 << endl;
            return 0;
        }

        ans *= a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 4048
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 399;

int h;
int w;
int d;
int q;
int ar[N][N];
long long dist[N*N];

struct loc{
    int row , col;
} getP[N * N];

long long calc(int i , int j){
    int x = abs(getP[i].col - getP[j].col);
    int y = abs(getP[i].row - getP[j].row);
    return x + y;
}

int main(){
    scanf("%d%d%d" , &h , &w , &d);
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            scanf("%d" , &ar[i][j]);
            getP[ar[i][j]] = {i , j};
        }
    }
    for(int i = h * w; i >= 1; i--){
        if(i + d <= h*w){
            dist[i] = dist[i + d] + calc(i , i + d);
        }
    }
    scanf("%d" , &q);
    while(q--){
        int l , r;
        scanf("%d%d" , &l , &r);
        printf("%lld\n" , dist[l] - dist[r]);
    }
}

Measured memory_bytes: 2944
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = len(s)+len(t)
t_accumulate = list(itertools.accumulate(t))
for x in t_accumulate[::-1]:
    if x in s:
        ans -= len(x)
        break
if ans>=N:
    print(ans)
else:
    print(max(N,len(s)+len(t)))


Measured memory_bytes: 3188
def main():
    a, b, k = map(int, input().split())
    s1 = set(range(a, min(a + k, b + 1)))
    s2 = set(range(max(b - k + 1, a), b + 1))
    for c in sorted(s1 | s2):
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060