akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 1<<20, mod = 924844033;
vi primes;
bool prime(ll a) {
	for(ll i = 2; i * i <= a; i++) if(a%i == 0) return 0;
	return 1;
}
void gen() {
	for(int i = 2; i < 3000; i++) if(prime(i)) primes.pb(i);
}
ll is_square(ll x) {
	ll t = sqrt(x);
	for(int i = max(-10ll, -t); i < 10; i++) if((t+i)*(t+i) == x) return t+i;
	return -1;
}
ll compress(ll x) {
	ll res = 1;
	for(auto i : primes) {
		if(x%i) continue;
		int c = 0;
		while(x%i == 0) x/=i, c++;
		c %= 3;
		while(c--) res *= i;
	}
	ll t = is_square(x);
	if(t >= 0 && t > 100000) return 1ll<<50;
	if(t == -1 && x > 100000) return 1ll<<50;
	return res*x;
}
ll inv(ll x) {
	ll res = 1;
	for(auto i : primes) {
		if(x%i) continue;
		int c = 0;
		while(x%i == 0) x/=i, c++;
		c = (3 - c%3)%3;
		while(c--) res *= i;
	}
	ll t = is_square(x);
	if(t != -1) return res*t;
	return res*x*x;
}
int n;
map<ll, ll> cnt;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	gen();
	cin >> n;
	for(ll t, i = 0; i < n; i++) {
		cin >> t;
		cnt[compress(t)]++;
	}
	ll ans = 0;
	for(auto &i : cnt) {
		if(i.first == 1ll<<50) ans += 2*i.second;
		else if(i.first == 1) ans+=2;
		else {
			if(cnt.count(inv(i.first)))
				ans += max(i.second, cnt[inv(i.first)]);
			else
				ans += 2*i.second;
		}
	}
	cout << ans/2;
}


Measured memory_bytes: 5504
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
    int N;
    cin >> N ;
    int digit = to_string(N).size();
    
    int arr[3] = {3,5,7};
    int ans = 0;
    for(int d=3; d<=digit; d++){
        int patterns = 1;
        for(int i=0; i<d; i++)patterns *=3;

        for(int _trits=0; _trits<patterns; _trits++){
            int trits = _trits;
            bitset<3> use;
            int sum = 0;
            for(int i=0;i<d;i++){
                sum = sum*10 + arr[trits %3];
                use[trits % 3] = true;
                trits /= 3;
            }
            if(use.all() && sum <= N)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

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

void solve() {
    string s;
    cin >> s;
    int ans = 1;

    for (int i = 0; i < s.length(); ++i) {
        if (i % 2 == 0) {
            if (s[i] == 'U' or s[i] == 'R' or s[i] == 'D') {
                continue;
            } else {
                ans = 0;
                break;
            }
        } else {
            if (s[i] == 'L' or s[i] == 'U' or s[i] == 'D') {
                continue;
            } else {
                ans = 0;
                break;
            }
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

int main(void) {
    u_int a, b, n;
    const int NOT_ASSIGNED = -1;

    std::cin >> a >> b;
    for (; a != 0 && b != 0; std::cin >> a >> b) {
        /*
         * 初期化
         */
        std::vector<std::vector<int>> matrix(a);
        for (u_int x = 0; x < a; ++x) {
            if (x == 0) {
                // x = 0 上はそれぞれ1通り
                matrix[x].resize(b, 1);
            } else {
                matrix[x].resize(b, NOT_ASSIGNED);
            }
            matrix[x][0] = 1;  // y = 0 上はそれぞれ1通り
        }
        // 原点
        matrix[0][0] = 0;

        /*
         * 行き止まりを反映する
         */
        std::cin >> n;
        for (u_int i = 0, x, y; i < n; ++i) {
            std::cin >> x >> y;
            matrix[--x][--y] = 0;  // 行き止まり

            // x = 0 上に行き止まりがあるとき、y 以降は通ることができない
            if (x == 0) {
                auto it = matrix[0].begin();
                for (std::advance(it, y + 1); it != matrix[0].end(); ++it) {
                    *it = 0;
                }
            }
            // y = 0 上に行き止まりがあるとき、x 以降は通ることができない
            if (y == 0) {
                for (u_int j = x + 1; j < a; ++j) {
                    matrix[j][0] = 0;
                }
            }
        }

        /*
         * 経路の計算
         */
        for (u_int x = 1; x < a; ++x) {
            for (u_int y = 1; y < b; ++y) {
                if (matrix[x][y] == NOT_ASSIGNED) {
                    matrix[x][y] = matrix[x][y-1] + matrix[x-1][y];
                }
            }
        }

        std::cout << matrix[a-1][b-1] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>

using namespace std;

long long x = 1000000007;


int main() {
	string n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7')cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        long mod = 998244353;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> map = new ArrayList<Integer>();
        int first = sc.nextInt();
        if(first != 0){
            System.out.println(0);
            return;
        }
        for(int i = 1; i < n; i++){
            map.add(sc.nextInt());
        }
        Collections.sort(map);
        if(map.get(0) == 0){
            System.out.println(0);
            return;
        }
        long ans = 1;
        int prev = 0;
        long prevcnt = 0;
        long nowcnt = 0;
        for(int m : map){
            if(m == 1){
                prev = 1;
                prevcnt++;
            }else if(m != prev){
                if(m - prev == 1 && prev != 1){
                    ans *= rep2(prevcnt,nowcnt,mod);
                    ans %= mod;
                    prev = m;
                    prevcnt = nowcnt;
                    nowcnt = 1;
                }else if(m - prev == 1){
                    prev = m;
                    nowcnt++;
                }else{
                    System.out.println(0);
                    return;
                }
            }else{
                nowcnt++;
            }
        }
        System.out.println(ans * rep2(prevcnt,nowcnt,mod) % mod);
    }
    
    private static long rep2(long b, long n, long mod){
        if(n == 0) return 1;
        if(n == 1) return b;
        long bn = rep2(b,n/2,mod)%mod;
        if(n % 2 == 0){
            return (long)(bn%mod*bn%mod)%mod;
        }else{
            return (long)(bn%mod*bn%mod)%mod*b%mod;
        }
    }
}

Measured memory_bytes: 60900
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int parent[100010], sz[100010]; // サイズを忘れずに入れる

int root(int a)
{
    if(parent[a]==a)    return a;
    else    return (parent[a]=root(parent[a]));
}

bool same_set(int a, int b)
{
    return (root(a)==root(b));
}

void unite(int a, int b)
{
    if(root(a)!=root(b))
    {
        if(sz[root(a)]<sz[root(b)]) swap(a, b);
        sz[root(a)]+=sz[root(b)];
        parent[root(b)]=root(a);
    }
}
int main()
{
    // P[]とsz[]のサイズを入れる
    int n, x, y;
    cin >> n;
    pai a[100010], b[100010];
    rep(i, n)
    {
        cin >> x >> y;
        a[i]=make_pair(x, i);
        b[i]=make_pair(y, i);
    }
    sort(a, a+n);
    sort(b, b+n);

    pair<int, pai> c[200010];
    rep(i, n-1)
    {
        c[2*i]=make_pair(a[i+1].first-a[i].first, make_pair(a[i].second, a[i+1].second));
        c[2*i+1]=make_pair(b[i+1].first-b[i].first, make_pair(b[i].second, b[i+1].second));
    }
    sort(c, c+(2*(n-1)));
    reps(i, n)
    {
        parent[i]=i;
        sz[i]=1;
    }
    ll ans=0;
    rep(i, 2*(n-1))
    {
        if(!same_set(c[i].second.first, c[i].second.second))
        {
            ans+=c[i].first;
            unite(c[i].second.first, c[i].second.second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
import itertools

n = int(input())

li = [3,5,7]
ans = 0
for i in range(1,11):
    for elm in itertools.product(li,repeat=i):
        if not(7 in elm) or not(5 in elm) or not(3 in elm):
            continue
        ttl = 0
        for j in range(len(elm)):
            ttl += elm[j]*(10**j)
        if ttl<=n:
            #print(ttl)
            ans += 1  

print(ans)

Measured memory_bytes: 43884
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x;
	scanf("%d",&x);
	int a,b;
	a=x/500;
	x=x%500;
	b=x/5;
	int sum;
	sum=a*1000+b*5;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int pv=0,v=0;
	int result = 0;
	for(int i=0;i<N;i++)
	{
		pv 	=  v;
		cin >> v;
		if(pv==v)
		{
			result++;
			v=0;
		}
/*
		if(a[cp]!=a[cp+1])
		{
			cp++;
			continue;
		}
		result++;
		a[cp+1]=0;
		if(cp==N-2)				break;
		if(a[cp+1]==a[cp+2])	cp++;
		cp++;
*/
	}
	cout << result << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
const int MAX_V=1000;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
int gcd(int a,int b){
	if(a>b) swap(a,b);
	if(a==0) return b;
	return gcd(b%a,a);
}
void add_edge(int u,int v){
	G[u].push_back(v);
	G[v].push_back(u);
}
bool dfs(int v){
	used[v]=true;
	rep(i,G[v].size()){
		int u=G[v][i],w=match[u];
		if(w<0 || (!used[w] && dfs(w))){
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}
int nibu(){
	int res=0;
	memset(match,-1,sizeof(match));
	rep(v,V){
		if(match[v]<0){
			memset(used,0,sizeof(used));
			if(dfs(v)) res++;
		}
	}
	return res;
}
int main(){
	while(true){
		int m,n,b[500],r[500];
		cin>>m>>n;
		if(m==0) break;
		rep(i,m) cin >> b[i];
		rep(i,n) cin >> r[i];
		V=m+n;
		rep(i,V) G[i].clear();
		rep(i,m) rep(j,n) if(gcd(b[i],r[j])>1) add_edge(i,j+m);
		cout << nibu() << endl;
	}
}

Measured memory_bytes: 3372
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, a, b;
vector<ll> v;
unordered_map<ll, ll> mp;

// nCr: v[n][r]
vector<vector<ll>> comb(ll n, ll r) {
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}


void solve() {
    sort(v.begin(), v.end(), greater<>());
    ll d[n + 1];
    d[0] = 0;
    rep(i, n) d[i + 1] = v[i] + d[i];
    double tmp = 0;
    for (ll i = a; i <= b; ++i) if (d[i] / double(i) > tmp) tmp = d[i] / double(i);


    if (v[0] == v[a - 1]) {
        ll ans = 0;
        vector<vector<ll>> table = comb(mp[v[0]], min(mp[v[0]], b));
        for (ll i = a; i <= min(mp[v[0]], b); i++) {
            ans += table[mp[v[0]]][i];
        }
        cout << fixed << tmp << endl;
        cout << ans << endl;
    } else {
        ll prev = 0;
        rep(i, a) if (v[i] != v[a - 1]) prev++;
        vector<vector<ll>> table = comb(mp[v[a - 1]], a - prev);
        cout << fixed << tmp << endl;
        cout << table[mp[v[a - 1]]][a - prev] << endl;
    }
}

int main() {
    cin >> n >> a >> b;
    v.resize(n);
    rep(i, n) {
        cin >> v[i];
        mp[v[i]]++;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  while (1){
    int N, T, L, B;
    cin >> N >> T >> L >> B;
    if (N == 0 && T == 0 && L == 0 && B == 0){
      break;
    }
    vector<char> c(N + 1, '.');
    for (int i = 0; i < L; i++){
      int l;
      cin >> l;
      c[l] = 'L';
    }
    for (int i = 0; i < B; i++){
      int b;
      cin >> b;
      c[b] = 'B';
    }
    vector<vector<double>> dp(T + 2, vector<double>(N + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < T; i++){
      for (int j = 0; j < N; j++){
        for (int k = 1; k <= 6; k++){
          int next = j + k;
          if (next > N){
            next = N - (next - N);
          }
          if (c[next] == 'B'){
            dp[i + 1][0] += dp[i][j] / 6;
          }
          if (c[next] == 'L'){
            dp[i + 2][next] += dp[i][j] / 6;
          }
          if (c[next] == '.'){
            dp[i + 1][next] += dp[i][j] / 6;
          }
        }
      }
    }
    double ans = 0;
    for (int i = 0; i <= T; i++){
      ans += dp[i][N];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int N, M;
    cin >> N >> M;

    int p, y;
    vector<vector<int>> v(M, vector<int>(2));
    vector<vector<int>> v1(M, vector<int>(2));
    vector<P> pp(M);
    REP(i, M){
        cin >> v[i][0] >> v[i][1];
        v1[i][0] = v[i][0];
        v1[i][1] = v[i][1];
    }
    sort(v1.begin(), v1.end(), [](vector<int> a, vector<int> b){return a[1] < b[1];});

    vector<int> r(N+1, 1);
    map<int, int> m; 
    REP(i, M){
        m[v1[i][1]] = r[v1[i][0]]++;
    }
    REP(i, M){
        printf("%06d", v[i][0]);
        printf("%06d\n", m[v[i][1]]);
    } 



    return 0;
}

Measured memory_bytes: 18304
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int w, h, n;
    cin >> w >> h >> n;
    int lx = 0, rx = w, uy = h, dy = 0;
    for (int i = 0; i < n; ++ i) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) lx = max(lx, x);
        else if (a == 2) rx = min(rx, x);
        else if (a == 3) dy = max(dy, y);
        else uy = min(uy, y);
    }
    int area = 0;
    if (rx > lx && uy > dy) area = (rx - lx) * (uy - dy);
    cout << area; 
    
}

Measured memory_bytes: 256
def myAnswer(a:int,b:int) -> str:
   ab=int(str(a)+str(b))
   for i in range(2,ab):
      if(i**2 == ab):
         return "Yes"
      elif(i**2 > ab):
         return "No"
   return "No"


def modelAnswer():
   tmp=1
def main():
   a,b=map(int,input().split())
   print(myAnswer(a,b))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<vector>
using namespace std;

struct Node{
  int parent;
  int root;
  int internal;
  vector<int> child;
};

Node T[100000];

int depth(int m){
  int d = 0;
  while(T[m].parent != -1){
    m = T[m].parent;
    d++;
  }

  return d;
}
  

int main() {
  int i=0,j=0,n,id,k[100000],s,num;

  scanf("%d",&n);

  while(i<n) {
    T[i].parent = -1;
    T[i].root = 1;
    T[i].internal =1;
    i++;
  }
  i=0;  
    while(i<n){
    scanf("%d",&id);
    scanf("%d",&k[id]);
    T[id].child.resize(k[id]);
    j=0;
    while(j<k[id]){
      if(i==0){
	T[id].parent = -1;
	T[id].root = 1;
      }
      else {
	T[id].internal =1;
      }
      
      scanf("%d",&s);
      T[s].parent = id;
      T[s].root = 0;
      T[s].internal = 1;
      T[id].child[j] = s;

      j++;
    }
    i++;
  }
    i=0;
  while(i<n){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    printf("depth = %d, ",depth(i));
    j=0;
    if(T[i].root) {
      printf("root, [");
      while(j<k[i]){
	if(j==0) printf("%d",T[i].child[j]);
	else printf(", %d",T[i].child[j]);

	j++;
      }
      printf("]\n");
    }
    else if(T[i].internal&&k[i]){
      printf("internal node, [");
      while(j<k[i]){
	if(j==0) printf("%d",T[i].child[j]);
	else printf(", %d",T[i].child[j]);

	j++;
      }
      printf("]\n");
    }
    else printf("leaf, []\n");

    i++;
  }

  return 0;
}
      
      
	



Measured memory_bytes: 7452
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M, X = [int(x) for x in input().strip().split()]
    C = [0] * N
    A = [[0 for _ in range(M)] for _ in range(N)]
    for n in range(N):
        ca = [int(x) for x in input().strip().split()]
        C[n] = ca[0]
        A[n] = ca[1:]
    ans = float('inf')
    for i in range(1 << N):
        A_ = [0] * M
        ans_ = 0
        for j in range(N):
            if i >> j & 1 == 1:
                for m in range(M):
                    A_[m] += A[j][m]
                ans_ += C[j]
        f = True
        for m in range(M):
            if A_[m] < X:
                f = False
                break
        if f:
            ans = min(ans, ans_)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9264
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
using namespace std;

typedef pair<int,int> P;

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define pb push_back
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define sor(vec) sort(vec.begin(),vec.end())
#define rev(vec) reverse(vec.begin(),vec.end())
#define pque(x) priority_queue<x>
#define rpque(x) priority_queue<x,vector<x>,greater<x> >
#define fr first
#define sc second

const int INF=1000000000;


int main(){
	int s,r,u,v,w,a,b,q;
	static vector<P> G[100010];
	
	scanf("%d%d",&s,&r);
	rep(i,r){
		scanf("%d%d%d",&u,&v,&w);
		G[u].pb(P(v,w));
		G[v].pb(P(u,w));
	}
	scanf("%d%d%d",&a,&b,&q);
	
	static bool used[100010];
	static int d[100010];
	rpque(P) que;
	static vector<int> prev[100010];
	
	rep(i,100010)used[i]=false;
	rep(i,100010)d[i]=INF;
	d[a]=0;
	que.push(P(0,a));
	
	while(!que.empty()){
		P p=que.top(); que.pop();
		if(!used[p.sc]){
			rep(i,G[p.sc].size()){
				P ed=G[p.sc][i];
				if(d[ed.fr]>d[p.sc]+ed.sc){
					d[ed.fr]=d[p.sc]+ed.sc;
					prev[ed.fr].clear();
					prev[ed.fr].pb(p.sc);
					que.push(P(d[ed.fr],ed.fr));
				}
				else if(d[ed.fr]==d[p.sc]+ed.sc){
					prev[ed.fr].pb(p.sc);
				}
			}
			used[p.sc]=true;
		}
	}
	
	/*rep1(i,s){
		printf("%d:",i);
		rep(j,prev[i].size()){
			printf("%d ",prev[i][j]);
		}
		printf("\n");
	}*/
		
	
	rep(i,100010)used[i]=false;
	queue<int> que0;
	static vector<int> nG[100010];
	que0.push(b); used[b]=true;
	
	while(!que0.empty()){
		int x=que0.front(); que0.pop();
		rep(i,prev[x].size()){
			int p=prev[x][i];
			nG[p].pb(x);
			if(!used[p]){
				que0.push(p);
				used[p]=true;
			}
		}
	}
	
	/*rep1(i,s){
		printf("%d:",i);
		rep(j,nG[i].size()){
			printf("%d ",nG[i][j]);
		}
		printf("\n");
	}*/
	
	static bool used0[100010];
	rep(i,100010)used0[i]=used[i];
	
	rep(ppp,q){
		int c,e;
		scanf("%d%d",&c,&e);
		
		if(!used0[e]){
			printf("No\n");
			continue;
		}
		
		rep(i,100010)used[i]=false;
		stack<int> sta;
		sta.push(c); used[c]=true;
		
		bool ret=false;
		while(!sta.empty()){
			int x=sta.top(); sta.pop();
			if(x==e){ ret=true; break; }
			if(d[x]<d[e]){
				rrep(i,nG[x].size()){
					int nex=nG[x][i];
					if(!used[nex]){
						sta.push(nex);
						used[nex]=true;
					}
				}
			}
		}
		
		if(ret)printf("Yes\n");
		else printf("No\n");
	}
}

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<vector<int>> ans(h, vector<int>(w));
	vector<vector<bool>> vis(h, vector<bool>(w, false));
	int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	int d = 0, x = 0, y = 0;
	for(int i = 1; i <= n; i++) {
		int cnt = a[i];
		while(cnt) {
			ans[x][y] = i;
			vis[x][y] = true;
			int xx = x + dx[d % 4];
			int yy = y + dy[d % 4];
			if(xx >= h || xx < 0 || yy >= w || yy < 0 || vis[xx][yy]) d++;
			x = x + dx[d % 4];
			y = y + dy[d % 4];
			cnt--;
		}
	}
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(j > 0) cout << " ";
			cout << ans[i][j];
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 384
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);
  int[] p; readA(n, p);
  p[] -= 1;

  auto uf = UnionFind!int(n);
  foreach (_; 0..m) {
    int x, y; readV(x, y); --x; --y;
    uf.unite(x, y);
  }

  auto ans = 0;
  foreach (g; uf.groups) {
    auto q = p.indexed(g);
    q.sort();
    ans += g.setIntersection(q).walkLength;
  }

  writeln(ans);
}

struct UnionFind(T)
{
  import std.algorithm, std.range;

  T[] p; // parent
  const T s; // sentinel
  const T n;
  T countForests; // number of forests
  T[] countNodes; // number of nodes in forests

  this(T n)
  {
    this.n = n;
    s = n;
    p = new T[](n);
    p[] = s;
    countForests = n;
    countNodes = new T[](n);
    countNodes[] = 1;
  }

  T opIndex(T i)
  {
    if (p[i] == s) {
      return i;
    } else {
      p[i] = this[p[i]];
      return p[i];
    }
  }

  bool unite(T i, T j)
  {
    auto pi = this[i], pj = this[j];
    if (pi != pj) {
      p[pj] = pi;
      --countForests;
      countNodes[pi] += countNodes[pj];
      return true;
    } else {
      return false;
    }
  }

  auto countNodesOf(T i) { return countNodes[this[i]]; }
  bool isSame(T i, T j) { return this[i] == this[j]; }

  auto groups()
  {
    auto g = new T[][](n);
    foreach (i; 0..n) g[this[i]] ~= i;
    return g.filter!(l => !l.empty);
  }
}


Measured memory_bytes: 6844
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);

if(a==b+c) puts("Yes");
else
if(b==a+c) puts("Yes");
else
if(c==a+b) puts("Yes");
else
puts("No");


return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  if (n % 2 == 1) {
    cout << "0\n";
    return 0;
  }
  string s = to_string(n);
  ll ans = n / 10;
  n /= 10;
  while(n>0){
    ans += n / 5;
    n /= 5;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main() {
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const ll MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}

ll choose(ll a, ll b)
{
    ll res = 1LL;
    for(ll i = a; i>=a-b+1; i--)
    {
        res = times(res, i);
    }

    for(ll i = 1; i<= b; i++)
    {
        res = times(res, fastExp(i, MOD-2));
    }
    return res;
}

const int MAXN = (int)1e6+1;
ll N, arr[MAXN];
map<ll, ll> primes;
int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> arr[i];
        ll n = arr[i];
        ll ctr = 0;
        while (n % 2 == 0)
        {
            ctr++;
            n/=2;
        }
        primes[2] = max(primes[2], ctr);
        for (ll i = 3; i <= sqrt(n); i = i + 2)
        {
            ctr = 0;
            while (n % i == 0)
            {
                ctr++;
                n = n/i;
            }
            primes[i] = max(primes[i], ctr);
        }

        if (n > 2)
            primes[n] = max(primes[n], 1LL);
    }

    ll res = 1;
    for(auto a = primes.begin(); a != primes.end(); a++)
    {
        res = times(res, fastExp(a->first, a->second));
    }
    ll res2 = 0;
    for(int i=0; i<N; i++)
    {
        res2 = add(res2, fastExp(arr[i], MOD-2));
    }
    cout << times(res, res2);
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 1e6 + 10;
int n;
int p[N];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	sort(p, p + n);
	cout << p[n / 2] - p[n / 2 - 1] << "\n";
	return 0;
}


Measured memory_bytes: 1024
function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var len = parseInt(input[0]);
  var list = input[1].split(" ").map((a)=>Number(a));
  var sum = Math.abs(list[0]);
  for(var i = 0; i < len - 1; i++){
    sum += Math.abs(list[i] - list[i + 1]);
  }
  sum += Math.abs(list[len - 1]);
  
  //console.log("sum:" + sum);
  for(var i = 0; i < len; i++){
    var tmp = 0;
    if(i == 0){
       tmp = sum - Math.abs(list[0]) - Math.abs(list[0] - list[1]) + Math.abs(list[1]);
    }else if(i == list.length - 1){
      var last =  list.length - 1;
      tmp = sum - Math.abs(list[last - 1] - list[last]) - Math.abs(list[last]) + Math.abs(list[last - 1]);
    }else{
      tmp = sum - Math.abs(list[i-1] - list[i]) - Math.abs(list[i] - list[i+1]) + Math.abs(list[i-1] - list[i+1]);
    }
    console.log(tmp);
  }
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 31156
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    A, B = map(int, input().split())

    #output
    print(A*B)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint x, y;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> x >> y;
	for(int i = 0; i <= x; i++){
		llint a = 2*i + (x-i)*4;
		if(a == y){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    
    if(x == 1){
        cout << b - a + 1 << endl;
    }
    else{
        ll ans = 0;
        if(a % x != 0){
            a += abs(x - a % x);
        }
        if(b % x != 0){
            b -= b % x;
        }
        
        a /= x;
        b /= x;
        if(b - a < 0)   cout << 0 << endl;
        else{
            ans = b - a + 1;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
x = int(input())
a = {i**5 for i in range(10**3)}
for p in a:
	if abs(p-x) in a:
		if p-x < 0:
			q = x-p
			print(int(p**(1/5)),int(-q**(1/5)))
			break
		else:
			q = p-x
			print(int(p**(1/5)),int(q**(1/5)))
			break

Measured memory_bytes: 9476
h,n=map(int,input().split())
lis=[]
amax=0
for i in range(n):
  a,b=map(int,input().split())
  if a>amax:
    amax=a
  lis.append([a,b])
dp=[0]*(h+amax)
for i in range(1,h+amax):
  dp[i]=min(dp[i-a]+b for a,b in lis)
print(dp[h])

Measured memory_bytes: 3584
#include<iostream>   
#include<string>
#include<vector>
using namespace std; 
 
int main()
{
	int a,b; 
	cin >> a >> b; 
	if (a==b)
	{
		cout << "Draw\n";
	} 
	else if (a==1)
	{
		cout << "Alice\n"; 
	}
	else if (b==1)
	{
		cout << "Bob\n";
	} 
	else if (a>b)
	{
		cout << "Alice\n";
	} 
	else
	{
		cout << "Bob\n";
	}
	
}

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

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

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point& operator+=(const point& a){ x+=a.x; y+=a.y; return *this; }
	point& operator-=(const point& a){ x-=a.x; y-=a.y; return *this; }
	point& operator*=(double c){ x*=c; y*=c; return *this; }
	point& operator/=(double c){ x/=c; y/=c; return *this; }
	point operator+(const point& a)const{ return point(x+a.x,y+a.y); }
	point operator-(const point& a)const{ return point(x-a.x,y-a.y); }
	point operator/(double c)const{ return point(x/c,y/c); }
	point operator-()const{ return point(-x,-y); }
	bool operator< (const point& a)const{ return x+EPS<a.x || (abs(x-a.x)<EPS && y+EPS<a.y); }
	bool operator==(const point& a)const{ return abs(x-a.x)<EPS && abs(y-a.y)<EPS; }
	bool operator!=(const point& a)const{ return abs(x-a.x)>EPS || abs(y-a.y)>EPS; }
};

point operator*(double c,const point& a){ return point(c*a.x,c*a.y); }

double dot(const point& a,const point& b){ return a.x*b.x+a.y*b.y; }

double cross(const point& a,const point& b){ return a.x*b.y-a.y*b.x; }

double abs(const point& a){ return sqrt(a.x*a.x+a.y*a.y); }

double abs2(const point& a){ return a.x*a.x+a.y*a.y; }

point rot(const point& a,double theta){ return point(a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)); }

// x 軸の正方向を基準としたときのベクトル a の角度を [0, 2*PI) の範囲で求める
double arg(const point& a){ double t=atan2(a.y,a.x); return t<0?t+2*PI:t; }

typedef vector<point> polygon;

struct circle{
	point c;
	double r;
	circle():c(point(0,0)),r(0){}
	circle(const point& c,double r):c(c),r(r){}
};

bool cover(const circle &C,const point &p){
	return abs(C.c-p)<C.r+EPS;
}

class smallest_enclosing_ball{
	static const int DIM=2;

	// 与えられた点集合
	int n;
	point *P;

	// 境界にある点集合
	int n_bd;
	point bd[DIM+1];

	// {bd[0], ..., bd[n_bd-1]} の最小包含球を求める
	circle naive(){
		if(n_bd==0) return circle(point(0,0),-1);

		// Gram-Schmidt で使う作業用
		point v[DIM]; // v[i] := ( v[0], ..., v[i-1] と直交するベクトル )
		double z[DIM]; // z[i] := |v[i]|^2

		// (cen, sqrt(R2)) := ( {bd[0], ..., bd[i]} の最小包含球 )
		point cen=bd[0];
		double R2=0;
		rep(i,n_bd-1){
			point delta=bd[i+1]-cen;

			// Gram-Schmidt
			v[i]=delta;
			rep(j,i){
				v[i]-=dot(v[j],delta)/z[j]*v[j];
			}
			z[i]=dot(v[i],v[i]);

			double mag=abs2(delta)-R2;
			cen+=mag/(2*z[i])*v[i];
			R2+=mag*mag/(4*z[i]);
		}

		return circle(cen,sqrt(R2));
	}

	circle dfs(int i){
		if(i==n || n_bd==DIM+1) return naive();

		// P[i] を境界として使わない場合
		circle C=dfs(i+1);
		// P[i] を境界として使う場合
		if(C.r==-1 || !cover(C,P[i])){
			bd[n_bd++]=P[i];
			C=dfs(i+1);
			n_bd--;
		}
		return C;
	}

public:
	circle solve(int n,point *P){
		this->n=n;
		this->P=P;
		random_shuffle(P,P+n);
		n_bd=0;
		return dfs(0);
	}
};

int main(){
	int n; scanf("%d",&n);
	point P[50];
	rep(i,n) scanf("%lf%lf",&P[i].x,&P[i].y);

	smallest_enclosing_ball S;
	printf("%.9f\n",S.solve(n,P).r);

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int m,d; 
int main(){
	int ans = 0;
	m = read(),d = read();
	for(int i = 1; i <= m;++i){
		for(int j = 10;j <= d;++j){
			if(j % 10 < 2) continue;
			if((j / 10) % 10 < 2) continue;
			int x = j % 10;
			int y = (j / 10) % 10;
			if(x * y == i) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define int long long
using namespace std;

void Solve(){
  int a, b;
  cin >> a >> b;
  int cur = 1;
  int cnt = 0;
  while (cur < b){
    cur = cur - 1 + a;
    cnt++;
  }
  cout << cnt;
}

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  Solve();
  
  return 0;
}
/*



*/

Measured memory_bytes: 256
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0
 
while i < len(s)-1:
    # BC=>0
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

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


int main(){
int n,W;
cin>>n>>W;
vector<int> dp(W+1,0);
vector<int> v(n+1),w(n+1),m(n+1);
for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>m[i];

for(int i=0;i<n;i++){
	for(int k=0;m[i]>0;k++){
	int tmp = min(m[i],(int)1<<k);
	for(int j=W-tmp*w[i];j>=0;j--)	dp[j+tmp*w[i]]=max(dp[j+tmp*w[i]],dp[j]+tmp*v[i]);
	m[i]-=tmp;
	}	
}

int ans=0;
	for(int i=0;i<=W;i++)ans = max(ans,dp[i]);
cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
long long dp(long long N, long long A, long long B, long long C, long long D, map<long long, long long> &mp){
  if (mp.count(N)){
    return mp[N];
  } else if (N == 0){
    return 0;
  } else if (N == 1){
    return D;
  } else {
    long long ans = INF;
    if (N <= 9000000000){
      ans = min(ans, N * D);
    }
    ans = min(ans, dp(N / 2, A, B, C, D, mp) + A + (N % 2) * D);
    ans = min(ans, dp((N + 1) / 2, A, B, C, D, mp) + A + (2 - N % 2) % 2 * D);
    ans = min(ans, dp(N / 3, A, B, C, D, mp) + B + (N % 3) * D);
    ans = min(ans, dp((N + 2) / 3, A, B, C, D, mp) + B + (3 - N % 3) % 3 * D);
    ans = min(ans, dp(N / 5, A, B, C, D, mp) + C + (N % 5) * D);
    ans = min(ans, dp((N + 4) / 5, A, B, C, D, mp) + C + (5 - N % 5) % 5 * D);
    mp[N] = ans;
    return ans;
  }
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    long long N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    map<long long, long long> mp;
    cout << dp(N, A, B, C, D, mp) << endl;
  }
}

Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
int M, N;
char a[202][202];
char b[202][202];
int main()
{
    cin >> N >> M;
    for(int i=0; i<N; ++i) cin>>a[i];
    for(int i=0; i<M; ++i) cin>>b[i];
    for(int i=0; i<=N-M; ++i)
        for(int j=0; j<=N-M; ++j)
        {
            bool flag = true;
            for(int k=0; k<M; ++k)
                for(int s=0; s<M; ++s)
                    if(a[k+i][s+j]!=b[k][s])
                        flag=  false;
            if(flag)
            {
                puts("Yes");
                return 0;
            }
        }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define m_p make_pair
#define pb push_back
#define pob pop_back
#define pf pop_front
#define puf push_front
#define st stack
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll> ml;
typedef map<ll,ll>::iterator itll;
typedef queue<P> BFs;
int main()
{
	string s;
	cin>>s;
	char c = s[s.size()-1];
	if(c=='2'||c=='5'||c=='7'||c=='4'||c=='9')cout<<"hon\n";
	else if(c == '0'||c=='1'||c=='6'||c=='8')cout<<"pon\n";
	else
		cout<<"bon\n";
	return 0;
}

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

int main(){
    bool is_prime[1000000];

    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<1000000;i++){
        is_prime[i]=true;
    }

    for(int i=2;i*i<1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }

    while(true){
        int n;
        cin>>n;

        if(cin.eof()) break;
        int a,b;
        for(int i=n-1;i>0;i--){
            if(is_prime[i]){
                a=i;
                break;
            }
        }
        for(int i=n+1;i<51000;i++){
            if(is_prime[i]){
                b=i;
                break;
            }
        }

        cout<<a<<' '<<b<<endl;
    }

}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

template <class T> inline T square(T x) {
  T result;
  result = x * x;
  return result;
};

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  auto start = chrono::steady_clock::now();
#endif

  int k, n;
  cin >> k >> n;

  vector<int> a(n);

  for (auto &i : a) {
    cin >> i;
  }

  int ans = INF;

  ans = min(ans, k - (a[0] - a[n - 1] + k));
  dbg(a[0] - a[n - 1] + k);

  for (auto i = 1; i < n; ++i) {
    int anticlock = a[i] - a[i - 1];
    ans = min(k - anticlock, ans);
  }

  for (auto i = 0; i < n - 1; ++i) {
    int clock = a[i + 1] - a[i];
    ans = min(ans, k - clock);
  }

  ans = min(ans, k - (k + a[0] - a[n - 1]));

  print(ans);
#ifdef LOCAL
  auto end = chrono::steady_clock::now();
  auto diff = end - start;

  cout << "Duration: " << chrono::duration<double, milli>(diff).count() << " ms"
       << '\n';
#endif

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";
ll A,B,C;


void solve(long long N,std::vector<std::string> s){
    vector<string> ans;
    for(int i=0;i<N;i++){
        if(s[i] =="AB"){
            bool addA = true;
            if(A+B==0){
                cout << NO <<endl;
                return;
            }
            if(A==0){  
            }else if(B==0){
                addA =false;
            }else if(i < N-1 &&(s[i+1] =="BC")){
                addA =false;
            }
            if(addA){
                ans.push_back("A");
                ++A;--B;
            }else{
                 ans.push_back("B");
                ++B;--A;
            }
            continue;
        }
        if(s[i] =="BC"){
            bool addB = true;
            if(B+C==0){
                cout << NO <<endl;
                return;
            }
            if(B==0){  
            }else if(C==0){
                addB =false;
            }else if(i < N-1 &&(s[i+1] =="AC")){
                addB =false;
            }
            if(addB){
                ans.push_back("B");
                ++B;--C;
            }else{
                 ans.push_back("C");
                ++C;--B;
            }
            continue;
        }
         if(s[i] =="AC"){
            bool addA = true;
            if(A+C==0){
                cout << NO <<endl;
                return;
            }
            if(A==0){  
            }else if(C==0){
                addA =false;
            }else if(i < N-1 &&(s[i+1] =="BC")){
                addA =false;
            }
            if(addA){
                ans.push_back("A");
                ++A;--C;
            }else{
                 ans.push_back("C");
                ++C;--A;
            }
            continue;
        }
    }

    cout<< YES <<endl;
    for(int i=0;i<N;i++){
        cout <<ans[i] << endl;
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    scanf("%lld",&A);
    scanf("%lld",&B);
    scanf("%lld",&C);
    std::vector<std::string> s(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
    }
    solve(N,  std::move(s));
    return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    string s;
    cin >> s;
    int cnt_0 = 0, cnt_1 = 0;
    rep(i, s.size()) {
        if (s[i] == '0')++cnt_0;
        else ++cnt_1;
    }
    cout << min(cnt_0, cnt_1) * 2 << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

#define TMP (signed int)30
#define YES "Yes"
#define NO "No"

int main()
{
    signed int x = 0;

    scanf("%d", &x);

    if (x >= TMP)
        printf("%s", YES);
    else
        printf("%s", NO);

    return (0);
}

Measured memory_bytes: 1732
import math
import sys

n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s > n:
    print(-1)
    sys.exit(0)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn+1):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

ans = n + 1
for i in range(1, sn+1):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if b >= 2 and f(b, b * i + n%b) == s:
            ans = min((ans, b))
if s == n:
    print(n+1)
elif ans < n + 1:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 3188