akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

  int get_digit(long num) {
    int digit = 0;
    while (num != 0) {
      num /= 10;
      ++digit;
    }
    return digit;
  }

  int main() {
    long n;
    std::cin >> n;

    long ans =  10000000000;
    for (long a = 1; a * a <= n; ++a) {
      if (n % a == 0) {
        long b = n / a;
        if (std::max(get_digit(a), get_digit(b)) < ans) {
          ans = std::max(get_digit(a), get_digit(b));
        }
      }
    }
    std::cout << ans << std::endl;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define M 1000000000
void printprecise(double l,ll precision)
{
    std::cout << std::fixed;
    std::cout << std::setprecision(precision);
    std::cout << l;
}

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

void initialize(ll ar[],ll n)
{
	for(ll x=0;x<n;x++)
		ar[x] = x;
}

void printarray(ll ar[],ll n)
{
	for(ll x=0;x<n;x++)
		cout<<ar[x]<<" ";
	cout<<endl;
}

void printvector(vector <char> v)
{
	for(ll x=0;x<v.size();x++)
	{
		cout<<v[x]<<" ";
	}
	cout<<endl;
}

ll root(ll i,ll ar[])
{
	while(ar[i]!=i)
	{
		ar[i] = ar[ar[i]];
		i = ar[i];
	}
	return i;
}

void unione(ll a,ll b,ll ar[])
{
	ll p = root(a,ar);
	ll q = root(b,ar);
	ar[p] = ar[q];
}

ll bfs(ll n,ll vis[],vector <ll> v[],ll level[])
{
	list <ll> g;
	g.pb(n);
	vis[n]=1;
	level[n]=1;
	while(!g.empty())
	{
		ll a = g.front();
		g.pop_front();
		for(ll x=0;x<v[a].size();x++)
		{
			if(vis[v[a][x]]==1 && v[a][x] != a) 
			{
				return level[a]-level[v[a][x]]+1;
			}
			else
			{
				g.pb(v[a][x]);
				vis[v[a][x]]=1;
				level[v[a][x]] = level[a]+1;
			}
		}
	}
	return 10000000;
}


int main()
{
	

	ll n,w;
	cin>>n>>w;
	ll ar[n+1][w+1]={0};
	memset(ar,0,sizeof(ar));
	vector <pair<ll,ll>> v(n+1);
	for(ll x=1;x<=n;x++)
	{
		ll a,b;
		cin>>a>>b;
		v[x] = {a,b};
	}

	for(ll x=1;x<=n;x++)
	{
		for(ll y=1;y<=w;y++)
		{
			if(v[x].first > y)
				ar[x][y] = ar[x-1][y];
			else
				ar[x][y] = max(ar[x-1][y],v[x].second + ar[x-1][y-v[x].first]);
		}
	}

	cout<<ar[n][w];
}

	 	

Measured memory_bytes: 79104
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	final long MOD = (long) 1e9 + 7;

	void run() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		char[] cs = sc.next().toCharArray();
		int[] next = new int[N + 1];
		for (int i = 0; i < next.length; ++i)
			next[i] = i;
		for (int i = N; i >= N - M; --i) {
			if (i >= 0 && cs[i] == '0')
				next[N] = Math.min(next[N], i);
		}
		for (int i = N - 1; i >= 0; --i) {
			next[i] = Math.min(next[i], next[i + 1]);
			if (i - M >= 0 && cs[i - M] == '0')
				next[i] = Math.min(next[i], i - M);
		}
		ArrayDeque<Integer> ans = new ArrayDeque<>();
		int cur = N;
		while (cur != 0) {
			ans.addFirst(cur - next[cur]);
			if (cur == next[cur]) {
				System.out.println(-1);
				return;
			}
			cur = next[cur];
		}
		int sz = ans.size();
		PrintWriter pw = new PrintWriter(System.out);
		for (int a : ans) {
			pw.print(a + (sz == 1 ? "\n" : " "));
			--sz;
		}
		pw.close();
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 34248
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0) 
#define inf                  (ll)1<<60
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#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 pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,w;
    cin>>n>>w;
    vector<ll> a(n),v(n);
    vector<vector<ll>> dp(n,vector<ll> (w+1,0));
    f(i,n)
    {
        cin>>a[i]>>v[i];
        dp[i][a[i]]=v[i];
    }

    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if(j-a[i]>=0&&dp[i-1][j-a[i]]>0)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-a[i]]+v[i]);
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=w;i++)
    {
        ans=max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
}


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

const int N = 1e5 + 10;

int a[N];
long long pre[N], suf[N], sum[N];

int main() {
  int n, k;
  long long ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + max(a[i], 0);
  for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + max(a[i], 0);
  for (int i = 0; i <= n - k; i++)
    ans = max(ans, pre[i] + suf[i + k + 1] + max(sum[i + k] - sum[i], 0LL));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> in(n);
	REP(i, n)cin >> in[i];
	vector<string> v(2 * n);
	REP(i, n)v[i] = in[i] + in[i];
	REP(i, n)v[i + n] = v[i];
	vvi cnt(2 * n, vi(2 * n, 0)), cnt2(2 * n, vi(2 * n, 0));
	REP(i, 2 * n) {
		REP(j, 2 * n) {
			int k = 0;

			while (1) {
				int ai = i + k, aj = j - k, bi = i - k, bj = j + k;
				if (ai == -1 || ai == 2 * n || aj == -1 || aj == 2 * n || bi == -1 || bi == 2 * n || bj == -1 || bj == 2 * n)break;
				if (v[ai][aj] == v[bi][bj]) cnt[i][j]++;
				else 	break;

				k++;
			}
		}
	}
	REP(i, 2 * n) {
		REP(j, 2 * n) {
			int k = 0;
			while (1) {
				int ai = i + k + 1, aj = j - k - 1, bi = i - k, bj = j + k;
				if (ai == -1 || ai == 2 * n || aj == -1 || aj == 2 * n || bi == -1 || bi == 2 * n || bj == -1 || bj == 2 * n)break;
				if (v[ai][aj] == v[bi][bj]) cnt2[i][j]++;
				else 	break;

				k++;
			}
		}
	}
	int ans = 0;
	vi num(n);
	vi num2(n - 1);
	REP(i, n)num[i] = min(i + 1, n - i);
	REP(i, n - 1)num2[i] = min(i + 1, n - 1 - i);
	REP(a, n) {
		REP(b, n) {
			int f = 1;

			REP(i, n) {
				if (cnt[a + i][b + i] < num[i])f = 0;

			}
			REP(i, n-1) {
				if (cnt2[a + i][b + i + 1] < num2[i])f = 0;
			}
			if (f)ans++;
		}
	}
	cout << ans << endl;
}


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

using namespace std;


int main() {
    int i, cnt1 = 0, cnt2 = 0;
    bool isBlack = true;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        char t = isBlack ? '1' : '0';
        if (s[i] != t) cnt1++;
        isBlack = !isBlack;
    }
    isBlack = false;
    for (int i = 0; i < s.size(); i++) {
        char t = isBlack ? '1' : '0';
        if (s[i] != t) cnt2++;
        isBlack = !isBlack;
    }
    cout << min(cnt1, cnt2);
    return 0;
}

Measured memory_bytes: 512
n=int(input())
s=[]
l=[]
for i in range(n):
    p=int(input())
    s.append(p)
    if p%10!=0:
        l.append(p)
ans=sum(s)
if ans%10==0:
    if l==[]:
        print(0)
    else:
        print(ans-min(l))
else:
    print(ans)





Measured memory_bytes: 3064
import java.util.Scanner;

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

		boolean startsFromA = (S.charAt(0) == 'A');
		String seekC = S.substring(2, S.length() - 1);
		int indexOfC = seekC.indexOf('C');
		boolean containsSingleC = (indexOfC != -1 && seekC.indexOf('C', indexOfC + 1) == -1);
		boolean lowersOtherThanAC = isLowersOtherThanAC(S, indexOfC + 2);
		System.out.println((startsFromA && containsSingleC && lowersOtherThanAC) ? "AC" : "WA");
	}

	private static boolean isLowersOtherThanAC(String S, int indexOfC) {
		char[] array = S.toCharArray();
		int length = array.length;
		for (int i = 1; i < length; i++) {
			if (i != indexOfC && Character.isUpperCase(array[i])) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    int ret = 0;
    rep(i,n){
        int a;cin >> a;
        ret += a;
    }
    cout << ret - n << endl;
    return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans = p[:x] + q[:y] + r
print(sum(sorted(ans, reverse=True)[:x + y]))


Measured memory_bytes: 23328
def solve():
    N = int(input())
    f = lambda x,y,z:x*x+y*y+z*z+x*y+y*z+z*x
    MAX = 10000

    ans = [0]*(MAX+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                if f(x,y,z)>MAX:
                    break
                ans[f(x,y,z)]+=1
    for i in range(1, N+1):
        print(ans[i])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 69696
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main()
{
 
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n, q; cin >> n;
    int a[n]; 
    int s = 0;
    unordered_map<int, int> mpp;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        s += a[i];
        mpp[a[i]]++;
    }
    cin >> q;
    while (q--) {
        int b, c; cin >> b >> c;
        if (mpp.find(b) != mpp.end()) {
            s -= mpp[b]*b;
            s += c*mpp[b];
            mpp[c] += mpp[b];
            mpp.erase(mpp.find(b));
        }
        cout << s << endl;
    }
    
    return 0;
}

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

int main(){
    int n ,l;
    std::vector<int> vec;
    int tast = 0;
    int sum;

    std::cin >> n >> l;

    for(int b = 0; b < n; b++){
        vec.push_back(l);
        tast += l;
        l++;
    }

    if(vec[0] >= 0){
        sum = tast - vec[0];
    }else if(vec[n - 1] <= 0){
        sum =tast - vec[n - 1];
    }else{
        sum = tast;
    }

    std::cout << sum << std::endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> A(Q);
  rep(i, Q) cin >> A[i];
  rep(i, Q) --A[i];

  vector<int> members(N);
  rep(i, Q) ++members[A[i]];

  rep(i, N) {
    int point = Q * -1 + K + members[i];

    if (point > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    char op;
    for(;;) {
        cin >> a >> op >> b;
        if(op == '?') break;
        if(op == '+') cout << a + b << endl;
        else if(op == '-') cout << a - b << endl;
        else if(op == '*') cout << a * b << endl;
        else if(op == '/') cout << a / b << endl;
    }
}


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

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

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

    int Q;  // aの0未満の要素の個数
    if(0 <= a[1]) {
        Q = 1;
    }
    else if(a[n] < 0) {
        Q = n-1;
    }
    else {
        for(int i = 2; i <= n; i++) {
            if(0 <= a[i]) {
                Q = i-1;
                break;
            }
        }
    }

    vector<pair<ll, ll>> ans(n);

    for(int i = Q+1; i <= n-1; i++) {
        ans[i-Q] = make_pair(a[1], a[i]);
        a[1] -= a[i];
    }
    for(int i = 1; i <= Q; i++) {
        ans[n-1-Q+i] = make_pair(a[n], a[i]);
        a[n] -= a[i];
    }
    
    cout << a[n] << "\n";
    for(int i = 1; i <= n-1; i++) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll a;
	cin >> a;
	if (a % 2 == 0)cout << a / 2 - 1 << endl;
	else cout << a / 2 << endl;
}

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

using namespace std;

int main(void){

  int N; cin >> N;
  vector<int > Col;
  for (int i = 0; i < N; i++)
  {
    int temp; cin >> temp;
    Col.push_back(temp);
  }
  
  sort(Col.begin(), Col.end());
  
  for (vector<int >::iterator itr = Col.begin(); itr != Col.end()-1; ++itr)
  {
    if(*itr == *(itr+1)){
      cout << "NO" << endl;
      return 0;
    }
  }
  


  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 1400
from collections import defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    W, H, K = map(int, readline().split())
    N = int(readline())
    mp = defaultdict(lambda:defaultdict(int))
    for i in range(N):
        x, y = map(int, readline().split())
        if y % 2 == 1:
            continue
        if x % 2 == 1:
            mp[y][x//2] |= 1
            if x < W:
                mp[y][x//2+1] |= 4
        else:
            mp[y][x//2] |= 2
    if K < W//2:
        write("-1\n")
        return
    K -= W//2+1
    r = 0
    for y, mp_xs in mp.items():
        *S, = mp_xs.items()
        S.sort()
        a = 0; b = 10**9
        prv = -1
        for x, bs in S:
            if x - prv > 1:
                a = b = min(a, b)
            v0 = ((bs & 1) > 0); v1 = ((bs & 2) > 0); v2 = ((bs & 4) > 0)
            a, b = min(a + v0, b + min(v0+v2, 2*v1)), min(a, b + v2)
            prv = x
        if prv < W // 2:
            c = min(a, b)
        else:
            c = a
        r += c
    ans = max((W//2+1)*(H//2) + max(r - K, 0) - K, 0)
    write("%d\n" % ans)
solve()


Measured memory_bytes: 12880
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

LL mod = 1000000007;

int main()
{
	string day[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

	map<string, LL> m;

	for (LL i = 0; i < 7; ++i) {
		m[day[i]] = i;
	}


	string s;
	cin >> s;

	cout << 7-m[s] << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7;

lint N;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	if (N % 2 == 0) {
		cout << N * (N - 1) / 2 - N / 2 << endl;
		FOR(i, 1, N){
			FOR(j, i + 1, N + 1) {
				if (j == N - (i - 1)) continue;
				cout << i << " " << j << endl;
			}
		}
	}
	else {
		cout << N * (N - 1) / 2 - N / 2 << endl;
		FOR(i, 1, N) {
			FOR(j, i + 1, N + 1) {
				if (j == N - i) continue;
				cout << i << " " << j << endl;
			}
		}
	}
}


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

int main()
{
    int N,K;
    cin >> N>>K;
    int h[N];
    int count =0;
    for(int i=1;i<=N;i++)
    {
        cin >>h[i];
        if(h[i]>=K){
            count ++;
        }
    }
    cout <<count <<endl;
    return 0;
    
}

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 256
def main():
    S = input()
    N = len(S)+1
    now = 0
    A = [0]
    for s in S:
        if s == "<":
            now += 1
        else:
            now = 0
        A.append(now)
    B = [0]
    now = 0
    for s in S[::-1]:
        if s == ">":
            now += 1
        else:
            now = 0
        B.append(now)
    B = B[::-1]
    ans = sum( [ max(A[i], B[i]) for i in range(N)])
    
    print(ans)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 32700
package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt64() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solve()
	writer.Flush()
}

type pair struct {
	i, j int
}

func solve() {
	H, _ := nextInt(), nextInt()
	C := make([]string, H)
	for i := 0; i < H; i++ {
		C[i] = nextLine()
	}
	for i := 0; i < H; i++ {
		for j := 0; j < 2; j++ {
			out(C[i])
		}
	}
}


Measured memory_bytes: 768
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define ll long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()

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

    vector<pair<int, int>> s1, s2;

    repeat(n) {
        string s;
        cin >> s;

        for(auto it = s.find("()"); it != string::npos; it = s.find("()")) {
            s.erase(it, 2);
        }

        int lc = count(all(s), ')');
        int rc = count(all(s), '(');

        if (rc - lc >= 0) {
            s1.push_back(make_pair(lc, rc));
        } else {
            s2.push_back(make_pair(lc, rc));
        }
    }

    sort(all(s1), [](const auto& lhs, const auto& rhs){ 
        return lhs.first < rhs.first;
    });
    sort(all(s2), [](const auto& lhs, const auto& rhs){ 
        return lhs.second > rhs.second;
    });

    int le = 0, re = 0;
    for (auto& s: s1) {
        le = le + s.first - min(s.first, re);
        re = re - min(s.first, re) + s.second;
    }
    for (auto& s: s2) {
        le = le + s.first - min(s.first, re);
        re = re - min(s.first, re) + s.second;
    }


    if (le == 0 && re == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 11228
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
map<ll,ll> p;
int main(){
    ll a,b,c,d,ans=2,k=2;
    cin>>a>>b;
    c=__gcd(a,b),d=c;
    while (c>=k*k) {
        if(c%k==0){
        c/=k;
        if(c%k!=0)ans++;
      } else {
        k++;
      }
    }
    if(d!=1)cout<<ans;
    else cout<<"1";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;       //     ____   _   _  __   __
#define ll long long       //    / ___| | |_| |   / /
const ll INF = 0x3f3f3f3f; //   | |     |  _  |   V /
const ll N   = 1e5 + 5;    //   | |___  | | | |   | |
const ll MOD = 1e9 + 7;    //    ____| |_| |_|   |_|
ll read() {
  ll   x = 0, f = 1;
  char ch = getchar();

  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1; ch = getchar();
  }

  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0'; ch = getchar();
  }
  return x * f;
}

ll n;
struct node {
  double x, y;
}   a[N];
int idx[N];
double sum, cnt;

double dis(int i, int j) {
  return sqrt((a[i].x - a[j].x) * (a[i].x - a[j].x) + (a[i].y - a[j].y) *
              (a[i].y - a[j].y));
}

int main() {
  n = read();

  for (int i = 1; i <= n; i++) {
    a[i].x = read(), a[i].y = read();
  }
  cnt = 1;

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

  do
  {
    for (int i = 2; i <= n; i++) {
      sum += dis(idx[i - 1], idx[i]);
    }
  }
  while (next_permutation(idx + 1, idx + 1 + n));
  printf("%.10f\n", sum / cnt);
  return 0;
}


Measured memory_bytes: 256
import copy
def BubbleSort(A):
    C = copy.deepcopy(A)
    N = len(A)
    for i in range(N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j -1][1]):
                C[j], C[j - 1] = C[j - 1], C[j]
    return C

def SelectionSort(A):
    C = copy.deepcopy(A)
    N = len(A)
    for i in range(N):
        min_temp = i
        for j in range(i, N, 1):
            if int(C[j][1]) < int(C[min_temp][1]):
                min_temp = j
        C[min_temp], C[i] = C[i], C[min_temp]
    return C

def isStable(A, B):
    N = len(A)
    M = len(B)
    for i in range(N):
        for j in range(i+1, N, 1):
            for x in range(M):
                for y in range(x+1, M, 1):
                    if A[i][1] == A[j][1] and A[i] == B[y] and A[j] == B[x]:
                        return 'Not stable'
    else:
        return 'Stable'

N = int(input())
cards = input().split()
result1 = ' '.join(BubbleSort(cards))
result2 = ' '.join(SelectionSort(cards))
print(result1)
print(isStable(cards, BubbleSort(cards)))
print(result2)
print(isStable(cards, SelectionSort(cards)))


Measured memory_bytes: 6344
#include <iostream>
#include <bits/stdc++.h>
#define scan(n)      scanf("%I64d",&n);
#define scan2(a,b)   scanf("%I64d%I64d",&a,&b);
#define scan3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c);
#define sc(n)        scanf("%c",&n);
#define sf(n)        scanf("%lf",&n);
#define ss(n)        scanf("%s",n);
#define forall(i,a,b)for(long long int i=a;i<b;i++)
#define all(a)       a.begin(), a.end()
#define pb           push_back
#define mp           make_pair
#define FAST_IO      ios_base::sync_with_stdio(false); cin.tie(NULL);
#define minimum(a)   *min_element(a.begin(),a.end())
#define maximum(a)   *max_element(a.begin(), a.end())
#define display(a)   for(auto i : a) cout<<i<<" ";
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<ll> scanVector(ll n, vector<ll> &v)
{
  ll temp;
  for(ll i = 0; i < n ; i++)
  {
     cin>>temp;
     v.pb(temp);
  }
  return v;
}

ll fun(ll n )
{
    return (n*(n-1))/2;
}
int main() {
    FAST_IO
    ll t;
    //cin>>t;
    t = 1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        cout<<fun(n)+fun(m)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    for(int i = n - 1; i >= 2; i--){
        // 尺取り法
        int cnt = 0;
        int k;
        for(k = i - 2; k >= 0; k--){
            if(l[i] >= l[i-1] + l[k]) break;
            cnt++;
        }
        k++;
        ans += cnt;
        for(int j = i - 2; j >= 1; j--){
            cnt--;
            for(k; k < j; k++){
                if(l[i] < l[j] + l[k]){
                    ans += cnt;
                    break;
                }
                cnt--;
                if(cnt <= 0) break;
            }
            if(cnt <= 0) break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int  main () {
  int N,i,flag,tmp,count=0;

  scanf("%d",&N);

  int A[N];

  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
  }
  flag=1;
  while(flag) {
    flag=0;
  for(i=N-1;i>=1;i--) {
    if(A[i] < A[i-1]) {
      tmp = A[i];
      A[i] = A[i-1];
      A[i-1]=tmp;
      flag=1;
      count++;
    }
  }
  }
  
 
  for(i=0;i<N;i++) {
    if(i==0) printf("%d",A[i]);

    else printf(" %d",A[i]);
    if(i==N-1) printf("\n");
  }
  printf("%d\n",count);

  return 0;
  }
      
  
      



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <fstream>

// グラフクラス
class Graph {
public:
	// エッジ
	struct Edge {
		// 接続先のノード番号
		int node;
		// 移動コスト
		int cost;
	};
	// ノード
	struct Node {
		std::vector<Edge> edges;     // 近隣のエッジ
	};
	// コンストラクタ
	Graph(std::istream& in) {
		// ノード数の読み込み
		int n;
		in >> n;
		// ノード用の配列を初期化
		nodes_.resize(n);
		// エッジ数の読み込み
		int e;
		in >> e;
		// 始点の読み込み
		in >> start_;
		for (int i = 0; i < e; ++i) {
			int s, t, u;
			in >> s >> t >> u;
			Edge edge;
			edge.node = t; edge.cost = u;
			nodes_[s].edges.push_back(edge);
		}

	}
	// ノードを取得
	const Node& operator[] (int index) const {
		return nodes_[index];
	}
	// ノード数を取得
	std::size_t node_count() const {
		return nodes_.size();
	}
	// 始点を取得
	int get_start() const {
		return start_;
	}

private:
	// ノード用配列
	std::vector<Node> nodes_;
	// 始点
	int start_;
};

// パス検索クラス
class PathFinder {
	// 距離とノード番号のペア
	using dist_node = std::pair<long, int>;
public:
	// パス検索
	static std::vector<long> find_path(const Graph& graph) {
		// 最大値
		const auto inf = 2147483647L;
		//const auto inf = (float)std::numeric_limits<float>::max();
		// 経路情報
		std::vector<dist_node> dist_nodes(graph.node_count(), { inf, -1 });
		// プライオリティキュー
		std::priority_queue<dist_node, std::vector<dist_node>, std::greater<dist_node>> queue;
		// コストの配列
		std::vector<long> costs;
		// 開始ノードをキューに登録
		int start = graph.get_start();
		dist_nodes[start] = { 0, -1 };
		queue.push({ 0, start });
		// キューにデータがあるか？
		while (!queue.empty()) {
			// 先頭のノードをキューから取り出す
			const auto front = queue.top(); queue.pop();
			const auto front_g = front.first;
			const auto front_node = front.second;
			// キュー内のデータよりも経路情報の合計距離が小さい？
			if (dist_nodes[front_node].first < front_g) continue; //キュー内のデータは最短距離ではないので無視

            // 周辺のノードを取得
			for (const auto& node : graph[front_node].edges) {
				// コストを格納
				const auto g = dist_nodes[front_node].first + node.cost;
				// 合計距離が小さい場合は最短経路としてキューに登録
				if (dist_nodes[node.node].first > g) {
					// 経路情報を保存
					dist_nodes[node.node] = { g, front_node };
					// キューに登録
					queue.push({ g, node.node });
				}
			}
		}
		for (auto node : dist_nodes) {
			if (node.first == inf) {
				costs.push_back(-1);
				continue;
			}
			costs.push_back(node.first);
		}
		return costs;
	}
};

int main() {
	Graph graph(std::cin);
	auto costs = PathFinder::find_path(graph);
	for (auto cost : costs) {
		if (cost == -1) {
			std::cout << "INF" << std::endl;
			continue;
		}
		std::cout << cost << std::endl;
	}
	return 0;
}


Measured memory_bytes: 15948
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int,int> pii;

const int mod=1000000007;

pii a[200010],c[200010],b[200010];
int s[200010];

int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i].second,&a[i].first);
	sort(a+1,a+n+1);
	int top=0;
	for (int i=1;i<=n;i++)
	{
		if (top==0||a[i].second>b[top].first) b[++top]=make_pair(a[i].second,i);
		int l=1,r=top;
		while (l<=r)
		{
			int mid=(l+r)>>1;
			if (b[mid].first>=a[i].second) r=mid-1; else l=mid+1;
		}
		c[i].first=b[l].second;
	}
	top=0;
	for (int i=n;i;i--)
	{
		if (top==0||a[i].second<b[top].first) b[++top]=make_pair(a[i].second,i);
		int l=1,r=top;
		while (l<=r)
		{
			int mid=(l+r)>>1;
			if (b[mid].first<=a[i].second) r=mid-1; else l=mid+1;
		}
		c[i].second=b[l].second;
	}
	sort(c+1,c+n+1);
	s[0]=0;s[1]=1;c[0].second=0;c[n+1].first=n+1;
	int k=0;
	for (int i=1;i<=n+1;i++)
	{
		while (c[k].second+1<c[i].first) k++;
		s[i+1]=((s[i]+s[i])%mod-s[k]+mod)%mod;
	}
	printf("%d\n",(s[n+2]-s[n+1]+mod)%mod);
	return 0;
}


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

long long int n, m, ans;

int main(){
	scanf("%lld %lld", &n, &m);
	long long int t = min(n, m/2);
	ans += t;
	n -= t;
	m -= 2*t;
	m /= 4;
	ans += m;
	printf("%lld\n", ans);
}

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

int main() 
{
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];

    sort(a.rbegin(), a.rend());
    priority_queue<ll> que;
    rep(i,y)rep(j,z) que.push(b[i]+c[j]);

    int w = min(y*z, 3005);
    vector<ll> d;
    rep(i,w) {
        d.push_back(que.top());
        que.pop();
    }

    priority_queue<ll> Q;
    rep(i,x)rep(j,w) Q.push(a[i]+d[j]);

    rep(i,k){
        cout << Q.top() << endl;
        Q.pop();
    }

    return 0;
}


Measured memory_bytes: 43400
from heapq import heappop, heappush
manhattan = (
 (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6),
 (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5),
 (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4),
 (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3),
 (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5),
 (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4),
 (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3),
 (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2),
 (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4),
 (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3),
 (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2),
 (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1),
 (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3),
 (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2),
 (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1),
 (6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0))
movables = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11),
            (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14))
swap_mul = [[(1 << mf) - (1 << mt) for mt in range(0, 64, 4)] for mf in range(0, 64, 4)]
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, input().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
    estimation, board, blank = heappop(queue)
    if board in visited:
        continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited:
            continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45:
            continue
        heappush(queue, (new_estimation, new_board, new_blank))


Measured memory_bytes: 161248
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	long N;
	int K;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Long.parseLong(tokens[0]);
		K = Integer.parseInt(tokens[1]);
	}

	void calc() {
		StringBuilder strBuilder = new StringBuilder();
		long val = N;
		int count = 0;
		while (val > 0) {
			val /= K;
			++count;
		}
		System.out.println(count);
	}

	void showResult() {

	}
}


Measured memory_bytes: 20564
// by jojifrank
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

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

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

vector<int> ans;
void solve()
{
    int n; cin>>n;
    int xxor = 0;
    vector<int> a(n);
    rep(i,0,n)
    {
        cin>>a[i];
        xxor^=a[i];
    }
    rep(i,0,n) ans.pb(xxor^a[i]);
    for(int i:ans) cout<<i<<" ";
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5032
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
  if a[i]+1==a[i+1]:
    ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    vector<int> ord(n);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](int x, int y){
        return a[x] < a[y];
    });
    int cnt;
    vector<pair<int, int>> ans;
    if(a[ord.front()] < 0 && a[ord.back()] > 0){
        int pos;
        if(abs(a[ord.front()]) >= a[ord.back()])pos=ord.front();
        else pos = ord.back();
        rep(i, n){
            a[i] += a[pos];
            cnt++;
            ans.push_back(make_pair(pos+1, i+1));
        }
    }
    if(a[ord.front()] >= 0){
        for(int i = 1; i < n; ++i){
            if(a[i] < a[i-1]){
                a[i]+=a[i-1];
                cnt++;
                ans.push_back(make_pair(i, i+1));
            }
        }
    }
    else{
        for(int i = n-2; i >= 0; --i){
            if(a[i] > a[i+1]){
                a[i]+=a[i+1];
                cnt++;
                ans.push_back(make_pair(i+2, i+1));
            }
        }
    }
    
    cout << cnt << endl;
    rep(i, cnt)cout << ans[i].first << " " << ans[i].second << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

bool dp[100][100][40000];

int main(){
    ll h,w;cin>>h>>w;
    ll a[h][w],b[h][w];
    rep(i,0,h-1){
        rep(j,0,w-1){
            cin>>a[i][j];
        }
    }
    rep(i,0,h-1){
        rep(j,0,w-1){
            cin>>b[i][j];
        }
    }
    ll c[h][w];
    rep(i,0,h-1){
        rep(j,0,w-1){
            c[i][j]=a[i][j]-b[i][j];
        }
    }
    ll x=(h+w-1)*80;
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(i==0){
                if(j==0){
                    dp[i][j][c[i][j]+x]=1;
                    dp[i][j][-c[i][j]+x]=1;
                }else{
                    rep(k,0,(h+w-1)*160){
                        if(dp[i][j-1][k]){
                            dp[i][j][k+c[i][j]]=1;
                            dp[i][j][k-c[i][j]]=1;
                        }
                    }
                }
            }else{
                if(j==0){
                    rep(k,0,(h+w-1)*160){
                        if(dp[i-1][j][k]){
                            dp[i][j][k+c[i][j]]=1;
                            dp[i][j][k-c[i][j]]=1;
                        }
                    }
                }else{
                    rep(k,0,(h+w-1)*160){
                        if(dp[i-1][j][k] || dp[i][j-1][k]){
                            dp[i][j][k+c[i][j]]=1;
                            dp[i][j][k-c[i][j]]=1;
                        }
                    }
                }
            }
        }
    }
    rep(i,0,(h+w-1)*80){
        if(dp[h-1][w-1][x+i] || dp[h-1][w-1][x-i]){
            cout<<i<<endl;
            break;
        }
    }
    
    
    return 0;
}




Measured memory_bytes: 312064
n = int(input())
s = input().rstrip()

nums = 0
jmp = 0

for x,a in enumerate(s):
  if jmp!=0:
    jmp -= 1
    continue

  if x>len(s)-3:
    break
  if a=='A':
    if s[x+1]=='B' and s[x+2]=='C':
      nums += 1
      jmp = 2

print(nums)

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

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

#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            auto z = s - i - j;
            if (0 <= z && z <= k) ans++;
//            for (int l = 0; l <= k; ++l) {
//                if (s == (i + j + l)) ans++;
//            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256