akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
int main(){
  ll n;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  rep(i,0,n){
    cout << s1[i];
    cout << s2[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	graph := make([][]int, N)
	for i := range graph {
		graph[i] = make([]int, N)
		var u, k int
		fmt.Scan(&u, &k)
		for j := 0; j < k; j++ {
			var v int
			fmt.Scan(&v)
			v--
			graph[i][v] = 1
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(graph[i][j])
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1260
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int[] copy = (int[])arr.clone();
		Arrays.sort(copy);
		int mid = copy[(n + 1) / 2];
		int changed = copy[(n + 1) / 2 - 1];
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (arr[i] >= mid) {
				sb.append(changed);
			} else {
				sb.append(mid);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 75964
#include<cstdio>//AT2084
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int len,now;

char ch[102];

bool checkf(){
	while(now<len){
		if(ch[now]=='F'){
			return true;
		}
		now++;
	}
	return false;
}

bool checkc(){
	while(now<len){
		if(ch[now]=='C'){
			now++;
			if(checkf()){
				return true;
			}
			else{
				return false;
			}
		}
		now++;
	}
	return false;
}

int main(){
	scanf("%s",&ch);
	len=strlen(ch);
	if(checkc()){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 256
n, a, b = gets.split.map(&:to_i)
while true do
  if a + 1 != b
    a += 1
  elsif a - 1 >= 1
    a -= 1
  else
    puts "Borys"
    break
  end
  if b - 1 != a
    b -= 1
  elsif b + 1 <= n
    b += 1
  else
    puts "Alice"
    break
  end
end


Measured memory_bytes: 14312
package main

import (
	"fmt"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	
	foods := make([]int,m)
	
	for i := 0; i < n; i++ {
		var k,food int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			fmt.Scan(&food)
			food--
			foods[food]++
		}
	}
	ans := 0
	for i,_ := range foods {
		if foods[i] == n {
			ans++
		}
	}
	fmt.Println(ans)
}

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

#define int long long

int n;
int q, k;

vector<vector<pair<int, int>>> G;

struct LCA {
    int V, logV;
    vector<int> depth, len;
    vector<vector<int> > parent;

    LCA(int V) {
        this->V = V;
        logV = 0;
        while (V > (1LL<<logV)) logV++;
        this->depth = vector<int>(V);
        this->len = vector<int>(V);
        this->parent = vector<vector<int> >(logV, vector<int>(V));
    }

    void init(int v, int par, int d, int l) {
        depth[v] = d;
        parent[0][v] = par;
        len[v] = l;
        for (int i = 0; i < (int)G[v].size(); i++) {
            int w = G[v][i].first;
            int lc = G[v][i].second;
            if (w == par) continue;
            init(w, v, d+1, lc + l);
        }
    }

    void build() {
        for (int k = 0; k + 1 < logV; k++) {
            for (int v = 0; v < V; v++) {
                if (parent[k][v] < 0) parent[k+1][v] = -1;
                else parent[k+1][v] = parent[k][parent[k][v]];
            }
        }
    }

    int query(int u, int v) {
        if (depth[u] > depth[v]) swap(u, v);
        for (int k = 0; k < logV; k++) {
            if ((depth[v] - depth[u]) >> k & 1)
                v = parent[k][v];
        }
        if (u == v) return u;

        for (int k = logV-1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }

    int dist(int u, int v) {
      int z = query(u, v);
      return len[u] + len[v] - 2 * len[z];
    }

    int solver(int u, int v, int k) {
      return dist(u, k) + dist(k, v);
    }
};

signed main() {
  cin >> n;
  G.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;

    G[u].push_back(make_pair(v, c));
    G[v].push_back(make_pair(u, c));
  }

  LCA po(n);
  po.init(0, -1, 0, 0);
  po.build();

  cin >> q >> k;
  while (q--) {
    int x, y;
    cin >> x >> y;

    cout << po.solver(x - 1, y - 1, k - 1) << endl;
  }
}


Measured memory_bytes: 28016
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	vector<string> cmpStr(4);
	cmpStr[0] = "dream";
	cmpStr[1] = "dreamer";
	cmpStr[2] = "erase";
	cmpStr[3] = "eraser";
	REP(i, 4) {
		reverse(cmpStr[i].begin(), cmpStr[i].end());
	}

	string S;
	cin >> S;
	reverse(S.begin(), S.end());

	bool ret = true;
	for (int i = 0; i < S.size();) {
		bool find = false;
		for (auto cmpOne : cmpStr) {
			int iPos = S.compare(i, cmpOne.size(), cmpOne);
			if (iPos == 0) {
				find = true;
				i += (int)cmpOne.size();
				break;
			}
		}
		if (!find) {
			ret = false;
			break;
		}
	}

	if (ret) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MAX 2001
using namespace std;
int K[MAX] = {};
int N,X,Y,ans;
int main () {
    ios_base::sync_with_stdio(false);
    cin>>N>>X>>Y;
    for(int i=1;i<=N;i++) {
        for(int j=i+1;j<=N;j++) {
            int k = min(min(abs(j-i), abs(X-i) + 1 + abs(j-Y)), abs(Y-i) + 1 + abs(j-X)); 
            K[k]++;
        }
    }
    for(int i=1;i<N;i++) {
        cout<<K[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, B := ReadInt(), ReadInt()
	if B%A == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#else
#define rall(x,a) for(auto x : a)
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int D = 11, P = 111, TP = 1111, INF = 1e14;
int p[D], c[D];
int dp[D][TP];
int d, g;

signed main() {
    ios_base::sync_with_stdio(false);
    cin >> d >> g;
    int sump = 0;
    rep(i, 1, d) {
        cin >> p[i] >> c[i];
        sump += p[i];
    }
    fill(dp[0], dp[0] + sump, -INF);
    dp[0][0] = 0;
    rep(i, 1, d) {
        rep(ts, 0, sump) {
            rep(cs, 0, min(p[i], ts)) {
                int cur = cs * i * 100 + (cs == p[i] ? c[i] : 0);
                dp[i][ts] = max(dp[i - 1][ts - cs] + cur, dp[i][ts]);
            }
        }
    }
    rep(ts, 0, sump) {
        if(dp[d][ts] >= g) {
            cout << ts << endl;
            return 0;
        }
    }
    exit(1);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n;
  cin>>n;
  vi ans(100);
  ans[0]=2;
  ans[1]=1;
  for(i=2;i<=n;i++)ans[i]=ans[i-1]+ans[i-2];
  cout<<ans[n]<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu
int n,k,res;
//
int main(){
	n=getint();k=getint();
	rep(i,n)res+=(getint()>=k);
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

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

    int x;
    cin >> x;
    int ans = -1;
    if (x <= 599)
        ans = 8;
    else if (x <= 799)
        ans = 7;
    else if (x <= 999)
        ans = 6;
    else if (x <= 1199)
        ans = 5;
    else if (x <= 1399)
        ans = 4;
    else if (x <= 1599)
        ans = 3;
    else if (x <= 1799)
        ans = 2;
    else
        ans = 1;
    cout << ans;

    return 0;
}


Measured memory_bytes: 3600
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
inline int read(){int now=0;register char c=getchar();for(;!isdigit(c);c=getchar());
for(;isdigit(c);now=now*10+c-'0',c=getchar());return now;}
#define For(i, x, y) for(int i=x;i<=y;i++)  
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))  
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);  
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);  
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long  
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second 
typedef vector<int> VI;
const double eps = 1e-9;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7; 
int N,M,K;
int tree[maxn];
int group[maxn];
void init(){
	for(int i = 1; i <= N; i ++){
		tree[i] = i;
		group[i] = 0;
	} 
}
int find(int x){
	if(x == tree[x]) return x;
	int fx = find(tree[x]);
	group[x] = group[tree[x]] + group[x];
	tree[x] = fx;
	return fx;
}
bool Union(int l,int r,int d){
	int fa = find(l),fb = find(r);
	if(fa == fb) return group[l] - group[r] == d;
	if(l + group[l] <= l + d + group[r]){
		tree[fa] = fb;
		group[fa] = -group[l] + d + group[r];
	}else{
		tree[fb] = fa;
		group[fb] = -group[r] - d + group[l];
	}
	return true;
}
int main(){
	Sca2(N,M); init();
	for(int i = 1; i <= M ; i ++){
		int l,r,d;
		scanf("%d%d%d",&l,&r,&d);
		if(!Union(l,r,d)){
			puts("No");
			exit(0);
		}
	}
	for(int i = 1; i <= N ; i ++){
		find(i);
		if(group[i] > 1e9){
			puts("No");
			exit(0);
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	string s;
	cin>>s;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7')cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  int K;
  cin>>K;
  rep(i,K){
    cout<<"ACL";
  }
}


Measured memory_bytes: 3512
N = int(input())
*A, = map(int, input().split())

aA = [abs(a) for a in A]
asum = sum(aA)
c = sum([(a < 0) for a in A])

if c % 2:
	print(asum - min(aA) * 2)
else:
	print(asum)


Measured memory_bytes: 14412
#include <iostream>

#define P 1000000007

using namespace std;

long dp[101][8];

int main(){
    int H, W, K;
    long pat[7] = {0};
    long total = 0;
    cin >> H >> W >> K;
    for(int i = 0; i < (1<<(W-1)); i++){
        bool flag = false;
        for(int j = 1; j < W; j++){
            if(i&(1<<(j-1)) &&i&(1<<j)){
                flag = true;
                break;
            }
        }
        if(flag) continue;
        for(int j = 0; j < W-1; j++){
            if(i&(1<<j)){
                pat[j]++;
            }
        }
        total++;
    }
    /*
    cout << total << endl;
    for(int j = 0; j < W-1; j++){
        cout << pat[j] << ' ';
    }
    cout << endl;
    */
    dp[0][0] = 1;
    for(int i = 1; i <= H; i++){
        for(int j = 0; j < W; j++){
            if(j == 0){
                dp[i][j] = (dp[i][j]+(total-pat[0])*dp[i-1][j])%P;
                dp[i][j+1] = (dp[i][j+1]+pat[0]*dp[i-1][j])%P;
            }
            else if(j == W-1){
                dp[i][j] = (dp[i][j]+(total-pat[W-2])*dp[i-1][j])%P;
                dp[i][j-1] = (dp[i][j-1]+pat[W-2]*dp[i-1][j])%P;
            }else{
                dp[i][j] = (dp[i][j]+(total-pat[j-1]-pat[j])*dp[i-1][j])%P;
                dp[i][j+1] = (dp[i][j+1]+pat[j]*dp[i-1][j])%P;
                dp[i][j-1] = (dp[i][j-1]+pat[j-1]*dp[i-1][j])%P;
            }
        }
    }
    cout << dp[H][K-1] << endl;
}

Measured memory_bytes: 256
from collections import deque

def main():
    n, x, y = map(int, input().split())
    cnt = [0]*n
    x -= 1
    y -= 1
    q = deque()
    
    for i in range(n):
        q.appendleft(i)
        dist = [None]*n
        dist[i] = 0
        while q:
            j = q.pop()
            d = dist[j]
            cnt[d] += 1
            if j > 0 and dist[j-1] is None:
                dist[j-1] = d+1
                q.appendleft(j-1)
            if j < n-1 and dist[j+1] is None:
                dist[j+1] = d+1
                q.appendleft(j+1)
            if j == x and dist[y] is None:
                dist[y] = d+1
                q.appendleft(y)
            elif j == y and dist[x] is None:
                dist[x] = d+1
                q.appendleft(x)
    for i in range(1, n):
        print(cnt[i]//2)
                

if __name__ == "__main__":
    main()

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

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

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

// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  combination C(n+k);
  auto H = [&](int n, int r) {
    return C(n+r-1, r);
  };
  mint ans = 0;
  for(int i = 0; i <= k; ++i) {
    mint add = H(n, i);
    add *= modpow(25, i);
    add *= modpow(26, k-i);
    ans += add;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c,k;
  cin>>a>>b>>c>>k;
  int d =max({a,b,c});
  int sum=d;
  for (int i = 0; i < k; i++) {
 sum *=2;
}
 int e= a+b+c-d;
   sum +=e;
cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define ll long long
#define mod 1000000007
#define N 410
using namespace std;
ll f[N][N],sum[N][N];//sum[x][m]:1^m+...+x^m;
ll res[N];
int a[N],b[N];
int main()
{
	int n,c;
	scanf("%d%d",&n,&c);
	for(int i=1;i<=400;i++) res[i]=1,sum[0][i]=sum[0][i-1]+res[i];
	for(int i=1;i<=400;i++)
	{
		for(int j=1;j<=400;j++) res[j]=res[j]*j%mod;
		for(int j=1;j<=400;j++) sum[i][j]=(sum[i][j-1]+res[j])%mod;
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=c;j++)
			for(int k=0;k<=j;k++)
			f[i][j]=(f[i][j]+f[i-1][j-k]*(sum[k][b[i]]-sum[k][a[i]-1]+mod)%mod)%mod;
	}
	printf("%lld\n",f[n][c]);
	return 0;
}


Measured memory_bytes: 2816
import sys

def insert(k):
    global S, last
    S[last] = k
    idx = last
    while True:
        p = (idx + 1) / 2 - 1
        if S[idx] <= S[p]:
            break
        else:
            S[idx], S[p] = S[p], S[idx]
            idx = p
    last += 1

def maxHeapify(i):
    global S, last
    l = 2 * i + 1
    r = 2 * i + 2

    if l < last and S[l] > S[i]:
        largest = l
    else:
        largest = i

    if r < last and S[r] > S[largest]:
        largest = r

    if largest != i:
        S[i], S[largest] = S[largest], S[i]
        maxHeapify(largest)

def extract():
    global S, last
    print S[0]
    last -= 1
    S[0], S[last] = S[last], 0
    maxHeapify(0)

lines = sys.stdin.readlines()
lines.pop()

S = [0] * 2000001
S[2000000] = 2000000000
last = 0
for line in lines:
    if line[0] == "i":
        insert(int(line[7:]))
    else:
        extract()

Measured memory_bytes: 166648
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
using P = pair<int, int>;
using PP = pair<int, P>;

int N, M;
struct edge {
	P to;
	int cost;
};

template <typename T1, typename T2, typename T3>
int bfs(T1& G, T2& d, T3& used, P s) {
	deque<PP> deq;
	deq.push_back(PP(0, s));

	while (!deq.empty()) {
		PP q = deq.front();
		deq.pop_front();
		int cost = q.first;
		P v = q.second;
		if (used[v]) { continue; }
		used[v] = true;
		if (v == P(N - 1, -1)) { return cost; }

		for (int i = 0; i < G[v].size(); ++i) {
			if (used[G[v][i].to]) { continue; }
			if (G[v][i].cost == 0) {
				deq.push_front(PP(cost, G[v][i].to));
			} else {
				deq.push_back(PP(cost + 1, G[v][i].to));
			}
		}
	}
	return -1;
}

int main() {
	const int INF = 1e9;
	cin >> N >> M;
	map<P, vector<edge>> G;
	for (int i = 0; i < M; ++i) {
		int p, q, c;
		cin >> p >> q >> c;
		--p; --q;

		G[P(p, c)].push_back({P(q, c), 0});
		G[P(p, c)].push_back({P(p, -1), 0});
		G[P(p, -1)].push_back({P(q, c), 1});
		G[P(q, c)].push_back({P(p, c), 0});
		G[P(q, c)].push_back({P(q, -1), 0});
		G[P(q, -1)].push_back({P(p, c), 1});
	}

	map<P, int> d;
	map<P, bool> used;
	for (auto it = G.begin(); it != G.end(); ++it) {
		d[it->first] = INF;
		used[it->first] = false;
	}

	int res = bfs(G, d, used, P(0, -1));
	cout << res << endl;

	return 0;
}


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

#define ll long long  
#define endl "\n"

const ll int MOD=1e9+7;

void solve()
{
	ll n,i,ans=0,z,j;
	cin >> n;
	z = n;
	for(i=2;i<sqrt(n)+1;i++)
	{
		if(z%i == 0)
		{
			int cnt=0;
			while(z%i ==0)
			{
				z = z/i;
				cnt++;
			}
			// if(cnt!=0)
			// 	cout <<"i "<<i << endl;

			for(j=1;cnt>=j;j++)
			{
				cnt = cnt-j;
				ans++;
			}
		}
	}
	if(z!=1 and n!=1)
		ans++;
	cout << ans << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}

Measured memory_bytes: 3688
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

def main():
    N, L = list(map(int, input().split()))
    a = list(map(int, input().split()))
    pair_L = []
    for car, cdr in zip(a[:-1], a[1:]):
        pair_L.append(car + cdr)
    maximum = max(pair_L)
    # print(maximum)
    if maximum < L:
        print("Impossible")
    else:
        print("Possible")
        index = pair_L.index(maximum) + 1
        i = 1
        while i < index:
            print(i)
            i += 1
        i = N - 1
        while i > index:
            print(i)
            i -= 1
        print(index)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14668
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=5000002;

void solve(){
	string s,t;
	cin>>s>>t;
	int x=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			x++;
		}
	}
	cout<<x;
	
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}


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

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

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

use std::cmp::{max, min};
use std::collections::VecDeque;

fn main() {

  let a: i64 = read();
  let s: String = read();
  // let a: Vec<i64> = read_n(n);
  // let mut keta_memo = vec![0; 42];
  if 3200 <= a {
    println!("{}", s);
  } else {
    println!("{}", "red");
  }

}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws IOException {

        int dataNum = 0;
        int totalAmount = 0;
        int totalCount = 0;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String readString = null;
        while ((readString = br.readLine()) != null) {

            dataNum ++;
            String[] strValues = readString.split(",");
            int goodsCnt = Integer.parseInt(strValues[1]);
            totalAmount += Integer.parseInt(strValues[0]) * goodsCnt;
            totalCount += goodsCnt;
        }

        System.out.println(totalAmount);
        System.out.println(Math.round((double)totalCount/(double)dataNum));
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define REP(i, a, n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

ll gcd(ll a_,ll b_){if(b_>a_)swap(b_,a_);return (b_==0?a_:gcd(b_,a_%b_));}

int arr[M];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, x;
	
	map<int, int> mp;
	
	cin >> n;
	REP(i, 0, n){
		cin >> x;
		mp[x]++;
	}
	
	int ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->first > it->second){
			ans += it->second;
		}
		else if(it->first < it->second){
			ans += it->second - it->first;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4736
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

int n, a, b;

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

    cin >> n >> a >> b;
    cout << min(n * a, b) << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,i;
    int a,flag=0;

    cin>>n;
    cin>>a;

    for(i=a;i>=0;i--){
        if((n-i)%500==0){
            flag=1;
            break;
        }

    }
    if(flag==1){cout<<"Yes"<<endl;}
    else {cout<<"No"<<endl;}
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    cin >> A;
    int ans = 0;
    REP(i, N) REP(j, i) ans += A[i][j];
    REP(i, N) {
        REPF(j, i + 1, N) {
            bool found = false;
            REP(k, N) {
                if (k == i || k == j) continue;
                if (A[i][k] + A[k][j] == A[i][j]) {
                    found = true;
                    break;
                }
                if (A[i][k] + A[k][j] < A[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
            if (found) {
                ans -= A[i][j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

int check_all_even(int * a, int n) {
  int i;
  for(i=0;i<n;i++){
    if(a[i] % 2 != 0) {
      return 1;
    }
  }
  return 0;
}

int main() {
  int n;
  int i;
  int a[210];
  int cnt = 0;

  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  while(1) {
    if(check_all_even(a,n) == 0) {
      cnt++;
      for(i=0;i<n;i++){
        a[i]/=2;
      }
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    long double n,m,d;cin>>n>>m>>d;

    if(d==0){   
        cout<<fixed<<setprecision(20)<<(db)(m-1)/n<<endl;
    }else{
        cout<<fixed<<setprecision(20)<<(db)(2*(n-d)*(m-1)/(n*n))<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        Arrays.sort(arr);

        long ans = 0;

        for (int i=0; i<n-2; i++) {
            for (int j=i+1; j<n-1; j++) {
                int a = arr[i];
                int b = arr[j];
                int left = j+1;
                int right = n;
                while (left<right) {
                    int mid = (left+right)/2;
                    if (arr[mid]<a+b) {
                        left = mid+1;
                    } else {
                        right = mid;
                    }
                }                 
                ans += (right-j-1);

            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 26676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    const ll ans = max({a * c, a * d, b * c, b * d});
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s;

int main() {
	cin>>s;
	ll n = s.size();
	ll ans = 0;

	for(ll i = 0; i < (1 <<(n - 1)); i++) {
		ll thisSum = s[0] - '0';
		for(ll j = 0; j < n - 1; j++) {
			if(i&(1<<j)) {
				ans += thisSum;
				thisSum = (s[j + 1] - '0');
			}
			else {
				thisSum = (thisSum * 10LL) + (s[j + 1] - '0');
			}
		}
		ans += thisSum;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,average=0,result_f=0,result_c=0;
  int a[100];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    average+=a[i];
  }
  
  average=average/n;
  
  //average by floor
  for(i=0;i<n;i++){
    result_f+=(average-a[i])*(average-a[i]);
  }
  
  //average by ceil
  for(i=0;i<n;i++){
    result_c+=(average+1-a[i])*(average+1-a[i]);
  }
  
  if(result_f<=result_c){
    printf("%d",result_f);
  } else {
    printf("%d",result_c);
  }
}

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

int main(){
	int l = -2,r = -2;
	string s;
	cin >> s;
	for(int i = 0;i < s.length() - 1;i++){
		if(s[i] == s[i + 1]){
			l = i;
			r = i + 1;
		}
	}
	for(int i = 0;i < s.length() - 2;i++){
		if(s[i] == s[i + 2]){
			l = i;
			r = i + 2;
		}
	}
	cout << l + 1 << " " << r + 1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(e-a<=k){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int l,r,L = -1,R = 1000000001;
  for(int i = 0; i < m; i++){
    cin >> l >> r;
    
    L = max(L,l);
    R = min(R,r);
  }
  if(R-L + 1 < 0)cout << 0;
  else cout << R - L + 1;
}
    


Measured memory_bytes: 3612
//JAI SAI RAM 
//AGC 
//A GENERAL DP QUESTION
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mat[1000][1000];
ll MAX=100000000000000;
ll dp[1000][1000];

int main()
{
    ll i,j,k,l,m,n,o,p,q,r,s,t;
    
    cin>>n>>m;
    string a[n];

    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    {
       
        for(j=0;j<m;j++)
        {
            
            if(a[i][j]=='.')
            mat[i+1][j+1]=0;
            else 
            mat[i+1][j+1]=1;
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        dp[i][j]=MAX;
    }
    dp[n][m]=MAX;
    dp[1][1]=mat[1][1];
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(i>=2)
            {
                ll tmp=dp[i-1][j];
                if(mat[i][j]!=mat[i-1][j])
                tmp++;
                dp[i][j]=min(dp[i][j],tmp);
            }
            if(j>=2)
            {
                ll tmp=dp[i][j-1];
                if(mat[i][j]!=mat[i][j-1])
                tmp++;
                dp[i][j]=min(dp[i][j],tmp);
            }
        }
    }
    dp[n][m]+=mat[n][m];
    cout<<(dp[n][m])/2<<endl;
    return 0;
}
//A: When you decide on one Range Flip Find Route route, consider how many times you need to operate to get through that route. In the route, Z is the value obtained by adding 1 only when s11 is black to the number of times that the cell moves from the white cell to the black cell. Actually, the minimum number of operations to be able to follow this route is Z. Think about how the color of the cells in the route changes when you perform an operation. This means that the color does not change at all, or the color of the section of the route is inverted. In addition, you can see that it is possible to perform an operation that inverts all sections of the route. From the above observations, it can be seen that when the section of the color column of the route can be reversed as desired, it is necessary to consider how many operations need to be performed to make all the cells white. And if you notice that you can always reduce Z by 1 no matter what operation you perform, and that you can do an operation that reduces Z by 1, you know that the minimum number of times is Z. All you have to do is find the path with the smallest Z, and you can get the answer to this problem by doing a DP.

Measured memory_bytes: 4864
module CharMap = Map.Make (Char)

module RegExp : sig
  type t
  val empty_set : t
  val empty_str : t
  val char : Char.t -> t
  val app : t -> t -> t
  val union : t -> t -> t
  val star : t -> t

  val matches : t -> Char.t list -> bool
end = struct
  type t =
    { body : regexp;
      is_nullable : bool;
      mutable derivatives : t CharMap.t }
  and regexp =
    | EmptySet
    | EmptyStr
    | Char of Char.t
    | App of t * t
    | Union of t * t
    | Star of t

  let empty_set =
    { body = EmptySet;
      is_nullable = false;
      derivatives = CharMap.empty }

  let empty_str =
    { body = EmptyStr;
      is_nullable = true;
      derivatives = CharMap.empty }

  let char c =
    { body = Char c;
      is_nullable = false;
      derivatives = CharMap.empty }

  let app re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> empty_set
    | _, { body = EmptySet } -> empty_set
    | { body = EmptyStr }, _ -> re2
    | _, { body = EmptyStr } -> re1
    | _, _ ->
        { body = App (re1, re2);
          is_nullable = re1.is_nullable && re2.is_nullable;
          derivatives = CharMap.empty }

  let union re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> re2
    | _, { body = EmptySet } -> re1
    | _, _ ->
        { body = Union (re1, re2);
          is_nullable = re1.is_nullable || re2.is_nullable;
          derivatives = CharMap.empty }

  let star = function
    | { body = EmptySet } -> empty_str
    | { body = EmptyStr } -> empty_str
    | { body = Star re } -> re
    | re -> { body = Star re; is_nullable = true; derivatives = CharMap.empty }

  let rec derive c re =
    try CharMap.find c re.derivatives
    with Not_found ->
      let d =
        match re with
        | { body = EmptySet } -> empty_set
        | { body = EmptyStr } -> empty_set
        | { body = Char c' } ->
            if Char.compare c c' = 0 then empty_str else empty_set
        | { body = App (re1, re2) } ->
            union (if re1.is_nullable then derive c re2 else empty_set) (app (derive c re1) re2)
        | { body = Union (re1, re2) } ->
            union (derive c re1) (derive c re2)
        | { body = Star re0 } ->
            app (derive c re0) re in
      re.derivatives <- CharMap.add c d re.derivatives; d

  let matches re s =
    (List.fold_left (fun re c -> derive c re) re s).is_nullable
end

let () =
  let s = read_line () in
  print_endline @@
  if
    let open RegExp in
    matches
      (star @@
        union
          (app (char 'd') @@ app (char 'r') @@ app (char 'e') @@ app (char 'a') @@ app (char 'm') @@
            union empty_str @@ app (char 'e') @@ char 'r')
          (app (char 'e') @@ app (char 'r') @@ app (char 'a') @@ app (char 's') @@ app (char 'e') @@
            (union empty_str @@ char 'r'))) @@
      Array.to_list @@ Array.init (String.length s) (String.get s)
  then "YES"
  else "NO"

Measured memory_bytes: 6400
n=int(input())
a=[['7', '5', '3']]*9
for i in range(8):
    for j in range(len(a[i])):
        a[i+1].append(a[i][j]+'7')
        a[i + 1].append(a[i][j] + '5')
        a[i + 1].append(a[i][j] + '3')
ans=[]
for num in a[0]:
    if int(num) <= n and num.count('3')>0 and num.count('5') >0 and num.count('7')>0 :
        ans.append(num)
print(len(set(ans)))


Measured memory_bytes: 63216
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;

int main() {
   long long N;
  long long Y=0;
  cin>>N;
  for (long long X=1;X<=sqrt(N);X++){
    if(N%X==0){
      Y=N/X;
    }
  }
  long long X=N/Y;
  cout<<X+Y-2<<endl;
}

Measured memory_bytes: 3660
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    for i in range(N - 2):
        a = L[i]
        for j in range(i + 1, N - 1):
            b = L[j]
            for k in range(j + 1, N):
                c = L[k]
                if not ((a != b) and (b != c) and (c != a)): continue
                if not ((a + b > c) and (b + c > a) and (c + a > b)): continue
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73220
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, m;
const int maxN = 1e5 + 10;
int a[maxN];
ll delta[maxN];
void addDelta(int l, int r, int d) {
    if (l <= r) {
        delta[l] += d;
        delta[r + 1] -= d;
    }
    else {
        delta[1] += d;
        delta[r + 1] -= d;
        delta[l] += d;
    }
}
ll f[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i + 1 <= n; i++) {
        int from = a[i];
        int to = a[i + 1];
        int nfrom = from % m + 1;
        int dist = (to + m - from) % m;
        int nto = to % m + 1;
        addDelta(nto, from, dist);
        addDelta(nfrom, to, 1);
        if (nfrom <= to) {
            addDelta(nfrom, to, +to);
            f[nfrom] -= 1;
            f[to + 1] += 1;
        }
        else {
            addDelta(nfrom, m, to + m);
            f[nfrom] -= 1;
            addDelta(1, to, +to);
            f[1] -= 1;
            f[to + 1] += 1;
        }
    }
    ll best = 1e18;
    for (int i = 1; i <= m; i++) {
        delta[i] += delta[i - 1];
        f[i] += f[i - 1];
        best = min(best, delta[i] + f[i] * i);
    }
    cout << best;
    return 0;
}

Measured memory_bytes: 2176
N = input()
A = map(int, raw_input().split())
for i in range(len(A)):
    v = A[i]
    j = i - 1
    while (j >= 0) & (A[j] > v):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print ' '.join(map(str, A))

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> num(3);
  cin >> num.at(0) >> num.at(1) >> num.at(2);
  sort(num.begin(), num.end());
  num.at(1) -= num.at(0);
  num.at(2) -= num.at(0);
  int counter = 0;
  if(num.at(1) % 2 != 0) {
    num.at(1) -= 1;
    counter++;
  }
  counter += num[1] + num[2] - 3*(num[1]/2);
  cout << counter << endl;
}

  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
H, W = map(int, input().split())

C = [''] * H
for i in range(H):
    C[i] = input()
    
C2 = [''] * 2 * H
for i in range(1, 2 * H + 1):
    for j in range(W):
        C2[i - 1] += C[(i + 1) // 2 - 1][j]
#        C2[i][j] = C[(i + 1) // 2][j]
        
for i in range(2 * H):
    print(C2[i])

Measured memory_bytes: 3060