akhauriyash/Code-Regression huggingface dataset:
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"

#define fastio  	ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
#define TC      	int t; cin >> t; for(int tc = 1; tc <= t; tc++)
#define read    	freopen("input.txt", "r", stdin);
#define write   	freopen("output.txt", "w", stdout);
#define nl      	'\n'
#define pii			pair<int, int>
#define ll 			long long
#define pb			push_back
#define eb			emplace_back
#define all(v)		v.begin(), v.end()
#define rall(v)		v.rbegin(), v.rend()
#define d(x)		cerr << #x << " = " << x << nl


using namespace std;


int main() {
	/*
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    */
	string s, t;
	cin >> s >> t;
	int ans = t.size();
	for(int start = 0; start <= s.size()-t.size(); start++) {
		int diff = 0;
		for(int i = 0; i < t.size(); i++) {
			if(t[i] != s[start+i]) diff++;
		}
		ans = min(ans, diff);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string divide[4]={"dream","dreamer","erase","eraser"};
int main(){
  string S;
  cin>>S;
  reverse(S.begin(),S.end());
  for(int i=0; i<4;i++) reverse(divide[i].begin(),divide[i].end());
  bool can = true;
  for(int i=0; i<S.size();){
    bool can2 = false;
    for(int j=0; j<4; j++){
      string d = divide[j];
      if(S.substr(i,d.size())==d){
        can2=true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }
  if(can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
  

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 987654321
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;

double r;
int main() {
	scanf("%lf", &r);
	printf("%lf", 3.141592 * 2 * r);
}

Measured memory_bytes: 3788
import math

def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    def _f(length: int) -> bool:
        count = 0
        for a in A:
            count += int((a-1) / length)
        return count <= K

    l = 0
    r = 10**9
    while (r-l) > 1:
        mid = (l+r) // 2
        if _f(mid):
            r = mid
        else:
            l = mid
    print(r)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 31056
#include <stdio.h>
#include <math.h>
int main(void){
    int n,i,j;
    scanf("%d",&n);
    for(i=n;;i++){
        int flag=1;
        for(j=2;j<sqrt(i);j++){
            if(i%j==0) flag=0;
        }
        if(flag){
            printf("%d",i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 5005
#define inf 0x7fffffff
int n,k,q;
int ans=inf;
int s[MN],c[MN],v[MN];
inline int Min(int a,int b){return a<b?a:b;}
inline void work(int x){
	memset(c,sizeof(c),0);memset(v,sizeof(v),0);
	int l=1,r=1,cnt=0;
	while(l<=n){
		while(l<=n&&s[l]<x)  l++;r=l;
		while(r<=n&&s[r]>=x) r++;r--;
		if(r-l+1>=k){
			int tie=0;
			for(int i=l;i<=r;i++) v[++tie]=s[i];
			std::sort(v+1,v+1+tie);
			tie=1;
			for(int i=cnt+1;tie<=r-l-k+2;i++,tie++) c[i]=v[tie];
			cnt=cnt+r-l-k+2;
		}l=++r;
	}
	if(cnt>=q) {
		std::sort(c+1,c+cnt+1);
		if(c[1]==x) ans=Min(ans,c[q]-x);
	}
}
int main(){
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	for(int i=1;i<=n;i++) work(s[i]);
	printf("%d",ans);
} 

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

int a, b;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  
  cin >> a >> b;
  if(a >= b){
    for(int i = 0; i < a; i++){
      cout << b;
    }
  } else{
    for(int i = 0; i < b; i++){
      cout << a;
    }
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

nums = [0 for _ in range(4)]

for _ in range(3):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nums[a] += 1
    nums[b] += 1

nums.sort()

if nums[0] == 1 and nums[3] == 2: 
    print("YES")
else:
    print("NO")

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

int main() {
    int h, w;
    cin >> h >> w;

    char s[h][w];
    bool t[h][w];
    int u[h][w];

    int i, j;
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            t[i][j] = true;
        }
    }

    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }

    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if (s[i][j] == '#') {
                u[i][j] = 1;
            }
            else {
                u[i][j] = 0;
            }
        }
    }

    int tmp = 0;
    int k;
    for(i = 0; i < h; i++, tmp = 0){
        for(j = 0; j < w; j++){
            tmp += u[i][j];
        }
        if (tmp == 0) {
            for(k = 0; k < w; k++){
                t[i][k] = false;
            }
        }
    }

    for(i = 0; i < w; i++, tmp = 0){
        for(j = 0; j < h; j++){
            tmp += u[j][i];
        }
        if (tmp == 0) {
            for(k = 0; k < h; k++){
                t[k][i] = false;
            }
        }
    }

    for(i = 0; i <h; i++, tmp = 0){
        for(j = 0; j < w; j++){
            if (t[i][j] == true) {
                cout << s[i][j];
            }
            for(k = 0; k < w; k++){
                tmp += u[i][k];
            }
            if (tmp != 0 && j == w - 1) {
                cout << endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
const ll LL_MAX = 0x7fffffffffffffff;

int main()
{
    int a[2];
    cin >> a[0] >> a[1];
    int sum = 0;
    for (int i = 0; i < 2; i++)
    {
        int index = a[0] >= a[1] ? 0 : 1;
        sum += a[index];
        a[index]--;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int sum=0;
	int ans=0;
	if(b==1)
	{
		printf("0\n");
		return 0;
	}
	while(sum<b)
	{
		if(sum+a>=b)
		{
			ans++;
			sum+=a;
			break;
		}
		sum+=a-1;
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  sort(vec.begin(),vec.end());
  int ans=0;
  rep(i,k) ans+=vec[i];
  cout << ans << endl;

}

Measured memory_bytes: 3572
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main(){
	llint n, m;
	cin >> n >> m;
	hei(llint) a(n), b(n);
	rep(i, 0, n) {
		cin >> a[i] >> b[i];
	}
	sort(b.begin(), b.end());
	sort(a.begin(), a.end());
	llint x = 0;
	llint ans = 0,y=n-1;
	while (true) {
		if (x >= m)break;
		if (y<0||a[n-1]>=b[y]) {
			ans += ((m - x + a[n - 1]-1) / a[n - 1]);
			x = m;
		}
		else {
			if (a[n - 1] < b[y]) {
				x += b[y];
				ans++;
				y--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<string>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define FOR(i,l,r) for(int i = l ; i <= r ;++i )
#define ALL(T)  T.begin(),T.end()
#define lson(i)     i<<1
#define rson(i)     (i<<1|1)
#define ll long long 
#define pu push
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define is insert
#define se second
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define debug(x) cout << "[" << #x << ": " << (x) << "]" << endl
#define endl "\n"
#define in inline
using namespace std;
typedef pair<int,int> pii;
const int N = 1e3+10;

struct point {
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
    bool operator < (const point &rhs)const{
        return atan2(y,x) < atan2(rhs.y, rhs.x);
    }
}p[N];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n);
    double ans = 0;
    for(int i=0;i<n;++i){
        double x = 0,y = 0;
        int j = i;
        do{
            x += p[j].x, y += p[j].y;
            ans = max(ans,x*x+y*y);
            j = (j+1)%n;
        }while(i!=j);
    }
    printf("%.15lf\n",sqrt(ans));
    return 0;
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

ans = 0
for i in range(N//R+1):
  cntR = N - i * R
  for j in range(cntR//G+1):
    cntG = cntR - j * G
    if cntG % B == 0:
      ans += 1
print(ans)


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

int main() {
	int ax, ay, bx, by;
	cin >> ax >> ay >> bx >> by;
	int x = bx - ax;
	int y = by - ay;
	for(int i = 0;i < y;i++){
		cout << "U";
	}
	for(int i = 0;i < x;i++){
		cout << "R";
	}
	for(int i = 0;i < y;i++){
		cout << "D";
	}
	for(int i = 0;i < x;i++){
		cout << "L";
	}
	cout << "L" << "U";
	for(int i = 0;i < y;i++){
		cout << "U";
	}
	cout << "R";
	for(int i = 0;i < x;i++){
		cout << "R";
	}
	cout << "D" << "R" << "D";
	for(int i = 0;i < y;i++){
		cout << "D";
	}
	cout << "L";
	for(int i = 0;i < x;i++){
		cout << "L";
	}
	cout << "U" << endl;
}


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

using namespace std;

struct Node{
    int key;
    Node *left;
    Node *right;
    Node *parent;
};

Node* root= nullptr;

void insert(int key){
    Node *node=(Node*)calloc(1,sizeof(Node));
    node->key=key;
    if(root== nullptr){
        root=node;
        node->parent=nullptr;
        return;
    }

    Node *p=root;
    Node *parent;

    while(p!=nullptr){
        if(p->key<key){
            parent=p;
            p=p->right;
        }else if(p->key>key){
            parent=p;
            p=p->left;
        }
    }

    node->parent=parent;
    if(parent->key<key){
        parent->right=node;
    }else{
        parent->left=node;
    }

}

bool find(int key){
    bool canFind=false;
    Node *p=root;
    while(p!=nullptr){
        if(p->key<key){
            p=p->right;
        }else if(p->key>key){
            p=p->left;
        }else if(p->key==key){
            canFind=true;
            break;
        }
    }
    return canFind;
}

void key_delete(int key){

}


void middlePrint(Node *node){
    if(node==nullptr){
        return;
    }
    middlePrint(node->left);
    printf(" %d",node->key);
    middlePrint(node->right);
}
void firstPrint(Node *node){
    if(node== nullptr){
        return;
    }
    printf(" %d",node->key);
    firstPrint(node->left);
    firstPrint(node->right);
}
void print(Node *node){
    middlePrint(node);printf("\n");
    firstPrint(node);printf("\n");
}

int main() {


    int m;scanf("%d",&m);
    string str;

    for(int i=0;i<m;i++){
        cin>>str;

        if(str=="insert"){
            int key;cin>>key;
            insert(key);
        }
        else if(str=="find"){
            int key;cin>>key;
            if(find(key)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
        else if(str=="delete"){
            int key;cin>>key;
            key_delete(key);
        }
        else if(str=="print"){
            print(root);
        }

    }
    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll x;

	cin >> x;

	ll exp[1001];

	REP(i, 1001) {
		exp[i] = 0;
	}

	exp[1] = 1;

	FOR(i, 2, x + 1) {
		ll b = i * i;
		while (b <= x) {
			exp[b] = 1;
			b = b * i;
		}
	}

	RFOR(i, 0, 1001) {
		if (exp[i] == 1) {
			cout << i << endl;
			return 0;
		}
	}
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

struct edge { int from, to, cost; };

const int MAX_N = 2500;
const int MAX_M = 5000;
const ll INF = 10000000000LL;
int n,m,p;
edge edges[MAX_M];
vi g[MAX_N];
ll d[MAX_N];
bool vis[MAX_N];
bool rt[MAX_N];
bool rf[MAX_N];

bool dfs1(int u) {
  if (vis[u]) return rf[u];

  vis[u] = true;

  if (u == n-1) return rf[u] = true;

  for (int v : g[u]) {
    rf[u] |= dfs1(v);
  }

  return rf[u];
}

void dfs2(int u) {
  if (rt[u]) return;

  rt[u] = true;

  for (int v : g[u]) dfs2(v);
}

int main()
{
  cin >> n >> m >> p;
  forn(i,m) {
    int a,b,c; cin >> a >> b >> c;
    a--,b--;
    edges[i].from = a; edges[i].to = b; edges[i].cost = p-c;
    g[a].push_back(b);
  }

  fill_n(d,n,INF);
  d[0] = 0;

  forn(i,n-1) {
    forn(j,m) {
      edge e = edges[j];
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
      }
    }
  }

  forn(i,n) dfs1(i);
  dfs2(0);

  bool nl = false;
  forn(i,m) {
    edge e = edges[i];
    if (d[e.to] > d[e.from] + e.cost) {
      d[e.to] = d[e.from] + e.cost;
      nl |= rt[e.to] && rf[e.from];
    }
  }


  if (nl)
    cout << -1 << endl;
  else
    cout << max(0LL,-d[n-1]) << endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define ll long long
int main()
{
    ll n, m;
    while(scanf("%lld%lld", &n, &m)!=EOF)
    {
        ll ans=0;
        if(m/2>n) ans+=n+(m-2*n)/4;
        else ans+=m/2;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;

    int p = S.size() - T.size();
    bool judge = false;
    for(int i = p; i >= 0; i--){
        judge = true;
        for(int j = 0; j < T.size(); j++){
            if(T[j] != S[j+i] && S[j+i] != '?'){
                judge = false;
            }
        }
        if(judge == true){
            p = i;
            break;
        }
    }
    
    if(judge == false){
        cout << "UNRESTORABLE" << endl;
    }else{
        for(int i = p; i < T.size()+p; i++){
            if(S[i] == '?'){
                S[i] = T[i-p];
            }
        }
        for(int i = 0; i < S.size(); i++){
            if(S[i] == '?'){
                S[i] = 'a';
            }
        }
        cout << S << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=0;
	for (int i=1;i<=n;i++){
		for (int j=2;j<10;j++)
			if (((i%j)==0)&&((j*10+i/j)<=m)&&((i/j)!=1)&&((i/j)<10)) ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    ll cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + k * 50 == x) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long K = sc.nextLong();
        long D = sc.nextLong();
        long minx = 0;

        if (X >= 0) {
            if ((X / D) >= K) {
                minx = X - (D * K);
            } else {
                if (((X/D) - K) % 2 == 0) {
                    minx = X % D;
                } else {
                    minx = - (X % D - D);
                }
            }
        } else {
            X = - X;
            if ((X / D) >= K) {
                minx = X - (D * K);
            } else {
                if (((X/D) - K) % 2 == 0) {
                    minx = X % D;
                } else {
                    minx = - (X % D - D);
                }
            }
        }
        System.out.println(minx);
    }
}

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

int main () {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (r <= x && x <= W-r && r <= y && y <= H-r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 2e5+100;
ll n;
ll a[SIZE];
ll ans1[SIZE], ans2[SIZE];
ll mem[SIZE],add[SIZE];
ll ans_leng;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    for(int i = n; i > 0; i--){
        ll sum = 0;
        for(int j = n/i; j > 0; j--){
            int num = j*i;
            sum += add[num];
        }
        if(sum %2 != a[i]){
            if(add[i] == 1){
                cout << i << ' ' << sum << endl;
                cout << "-1\n";
                return 0;
            }
            ++add[i];
            ans1[ans_leng] = i;
            ++ans_leng;
        }
    }

    cout << ans_leng << endl;
    if(ans_leng == 0)   return 0;
    for(int i = 0; i < ans_leng; i++){
        cout << ans1[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

void call(int b1[3],vi b2,vi b3){
    
 }

int main(){
    vector<vi> c(3,vi(3));
    rep(i,3) rep(j,3) cin >> c[i][j];
    bool ok = false;
    rep(i,101){
        vi b1 = {c[0][0]-i,c[0][1]-i,c[0][2]-i};
        rep(j,101){
            vi b2 = {c[1][0]-j,c[1][1]-j,c[1][2]-j};
            if(b1!=b2) continue;
            rep(k,101){
                vi b3 = {c[2][0]-k,c[2][1]-k,c[2][2]-k};
                if(b1==b2 && b2==b3){
                    ok = true;
                    break;
                }
            }
        }
    }
    cout << (ok? "Yes":"No") << endl;
}

Measured memory_bytes: 256
N, L = map(int, input().split(' '))

apple = []
flav = []

for i in range(1, N+1):
    apple.append(i)
    flav.append(L+i-1)

abs_flav = list(map(abs, flav))
num = abs_flav.index(min(abs_flav))

print(sum(flav) - flav[num])

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

string s, t;
vector<int> num[30];

int search(char c, int prev){
    int alp = c - 'a';
    if(num[alp].size() == 0) return -1;
    auto key = upper_bound(ALL(num[alp]), prev);
    if(key == num[alp].end()) return num[alp].front();
    else return *key;
}

signed main(){
    cin >> s >> t;
    REP(i, s.length()) num[s[i] - 'a'].push_back(i);
    ll ans = 0;
    int prev = -1, next = 0;
    REP(i, t.length()){
        if((next = search(t[i], prev)) == -1){
            PRINT("-1");
            return 0;
        }
        //cerr << t[i] << " " << next << endl;
        if(prev < next) ans += next - prev;
        else ans += next + s.length() - prev;
        prev = next;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
int x, y, n, z, xx, yy;
int ans[2001];
int main() {
	scanf("%d%d%d", &n, &x, &y);
	x--; y--;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			xx = x - i;
			if (xx < 0)xx *= -1;
			yy = y - j;
			if (yy < 0)yy *= -1;
			z = xx + yy + 1;
			if (j - i < z)z = j - i;
			ans[z]++;
		}
	}
	for (int i = 1; i < n; i++) {
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 128
loop.with_index do |_, k|
  n = gets.to_i
  break if n == 0
  p = []
  n.times{ p << gets.split.map(&:to_f) }
  p << p[0]
  s = p.each_cons(2).map{ |a, b| a[1]*b[0] - a[0]*b[1] }.inject(:+) / 2
  puts "#{k+1} %.1f" % s
  gets
end

Measured memory_bytes: 8788
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> v(n);
    vector<int> prix(n);
    for (int i=0; i<n; i++)
    {
        cin >> prix[i];
        for (int j=0; j<m; j++)
        {
            int e; cin >> e;
            v[i].push_back(e);
        }
    }
    // for (int i=0; i<n; i++)
    // {
    //     for (int j=0; j<m; j++)
    //     {
    //         cout << v[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = LLONG_MAX;
    for(int mask = 0; mask < (1<<n); mask++)
    {
        vector<bool> active(n, false);
        vector<int> learn(m, 0);
        ll sum = 0;
        for(int i=0; i<n; i++) if(mask & (1<<i))
            active[i] = true;
        for (int i=0; i<n; i++)
        {
            if (active[i] == true)
            {
                sum += prix[i];
                for (int j=0; j<m; j++)
                {
                    learn[j] = learn[j] + v[i][j];
                }
            }
        }
        bool corr = true;
        for (int j=0; j<m; j++)
            if (learn[j] < x)
            {
                corr = false;
                break;
            }
        if (corr == true)
            ans = min(ans, sum);
    }
    if (ans == LLONG_MAX)
        cout << -1;
    else 
        cout << ans;
    return 0;
}

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

using namespace std;

int main(int, char**) {
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	queue<int> que;
	stack<int> stk;
	for (int i=0; i<n; i++) {
		if (s.at(i) == 'o') {
			que.push(i + 1);
			stk.push(i + 1);
		}
	}
	vector<int> l;
	int cnt = 0;
	int lp = -2*n;

	while (cnt<k) {
		int now = que.front();
		que.pop();
		if (now - lp > c) {
			l.push_back(now);
			cnt++;
			lp = now;
		}
	}

	vector<int> r;
	cnt = 0;
	int rp = 3*n;
        while (cnt<k) {
                int now = stk.top();
                stk.pop();
                if (rp - now > c) {
                        r.push_back(now);
                        cnt++;
                        rp = now;
                }
        }
        for (int i=0; i<k; i++) {
                int a = l.at(i);
                int b = r.at(k-i-1);
                if (a==b) cout << a << endl;
        }

        return 0;
}


Measured memory_bytes: 7096
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}



void solve()
{
	int n, m;
	cin >> n >> m;
	bool good = 0;
	map<pii, bool> z;
	rep(i, m){
		int x, y;
		cin >> x >> y;
		if(x > y) swap(x, y);
		if(x == 1 && z.count({y, n})) good = 1;
		if(y == n && z.count({1, x})) good = 1;
		z[{x, y}] = 1;
	}
	if(!good) cout << "IM";
	cout << "POSSIBLE";

}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 16084
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 1123456789012;
LL N, M;
std::vector<LL>K, dis;
std::vector<std::vector<LL>>L;
std::vector<std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(dis.begin(), dis.end(), inf);
	dis[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dis[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dis[e.to] > dis[v] + e.cost)
			{
				dis[e.to] = dis[v] + e.cost;
				que.push(P(dis[e.to], e.to));
			}
		}
	}
}


int main()
{
	in >> N >> M;
	K.resize(N), L.resize(N);
	G.resize(N + M + 2), dis.resize(N + M + 2);
	rep(i, N)
	{
		in >> K[i];
		L[i].resize(K[i]);
		rep(j, K[i]) in >> L[i][j];
	}
	rep(i, N)
	{
		rep(j, K[i])
		{
			G[i + 1].push_back({ L[i][j] + N,1 });
			G[L[i][j] + N].push_back({ i + 1,1 });
		}
	}
	dijkstra(1);
	rep(i, N)
	{
		if (dis[i + 1] == inf)
		{
			out << "NO" << std::endl;
			return 0;
		}
	}
	out << "YES" << std::endl;
	return 0;
}

Measured memory_bytes: 20464
#include<stdio.h>
int main(void){
    int n;
    char s[1000];
    int ans;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        if((i+1)%2!=0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){

             }else{
                 printf("No\n");
                 return 0;
             }
        }
        
        if((i+1)%2==0){
            if(s[i]=='L'||s[i]=='U'||s[i]=='D'){

             }
             else{
                 printf("No\n");
                 return 0;
             }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
from itertools import product
import queue
 
H, W = map(int, input().split())
road_grid = list()
for _ in range(H):
  road_grid.append(input())

# for each start point, find the furthest travellable point
# then return largest path length of all these
# ps y is down, x is right
furthest_so_far = -1
for y_init, x_init in product(range(H), range(W)):
    if road_grid[y_init][x_init] == "#": continue
    boundary = queue.Queue()
    boundary.put((y_init, x_init))
    steps_taken = [[-1]*W for _ in range(H)]
    steps_taken[y_init][x_init] = 0
    while not boundary.empty():
        y, x = boundary.get()
        neighbours = [(y+1, x), (y, x+1), (y-1, x), (y, x-1)]
        for (new_y, new_x) in neighbours:
            if (0 <= new_y < H and 0 <= new_x < W
                and steps_taken[new_y][new_x] == -1 and road_grid[new_y][new_x] == "."):
                steps_taken[new_y][new_x] = steps_taken[y][x] + 1
                boundary.put((new_y, new_x))
    furthest_here = max(max(row) for row in steps_taken)
    furthest_so_far = max(furthest_so_far, furthest_here)
print(furthest_so_far)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    bool flag[n];
    rep(i, n) flag[i] = true;
    int ans = 0;
    rep(i, k) {
        if (t[i] == 'r')
            ans += p;
        else if (t[i] == 's')
            ans += r;
        else if (t[i] == 'p')
            ans += s;
    }
    for (int i = k; i < n; i++) {
        if (t[i] == t[i - k]) {
            flag[i] = !flag[i - k];
            if (flag[i - k])
                continue;
        }
        if (t[i] == 'r')
            ans += p;
        else if (t[i] == 's')
            ans += r;
        else if (t[i] == 'p')
            ans += s;
    }
    cout << ans << endl;
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


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

void solve() {
    int K; cin >> K;
	ll res=0;
	for(ll i=1; i<=K; i++){
		for(ll j=1; j<=K; j++){
			for(ll k=1; k<=K; k++){
				res += gcd(i,gcd(j, k));
			}
		}
	}

	cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

long long int kaijyou(long long int number)
{
	long long int result = 1;
	for (long long int i = number; i > 0; i--)
	{
		result = result * i % (1000000000 + 7);
	}
	return result;
}

int main()
{
	long long int n, m;
	cin >> n >> m;
	long long int count;
	if (n - m > 1 || m - n > 1)
	{
		cout << 0 << endl;
	}
	else {
		if (n >= m)
		{
			if ((n + m) % 2 == 0)
			{
				count = kaijyou(n) * kaijyou(m) * 2;
				count = count % (1000000000 + 7);
			}
			else {
				count = kaijyou(n) * kaijyou(m);
				count = count % (1000000000 + 7);
			}
		}
		else {
			if ((n + m) % 2 == 0)
			{
				count = kaijyou(n) * kaijyou(m) * 2;
				count = count % (1000000000 + 7);
			}
			else {
				count = kaijyou(n) * kaijyou(m);
				count = count % (1000000000 + 7);
			}

		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	int k=1,s=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==k)
		k++;
		else
		{
			s++;
		}
	}
	if(k==1)
	cout<<"-1";
	else
	cout<<s;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n;
int a[maxn];

void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    int ans=1,mn;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    mn=a[1];
    for(int i=2;i<=n;++i){
        mn=min(mn,a[i]);
        if(mn==a[i])++ans;
    }
    cout<<ans<<endl;
}
int main(){
    solve();

    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast", "unroll-loops")

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using uint = unsigned int;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;
// mt19937 rnd(1);

const int P = 998244353;

void add(int &a, int b, int p = P) {
    a += b;
    if (a >= p) {
        a -= p;
    }
}

void sub(int &a, int b, int p = P) {
    a -= b;
    if (a < 0) {
        a += p;
    }
}


void mul(int &a, int b, int p = P) {
    a = ll(a) * b % p;
}

int binPow(int a, int b, int p = P) {
    int res = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) {
            mul(res, a, p);
        }
        mul(a, a, p);
    }
    return res;
}

int reverse(int a, int p = P) {
    return binPow(a, p - 2, p);
}

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

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;      

    int n;
    cin >> n;

    vector<int> r(n + 1);

    for (int i = 1; i <= n; ++i) {
        r[i] = reverse(i);
    }

    int sum = 1;
    int cur = 1;

    for (int i = 1; i < n / 2; ++i) {
        mul(cur, n - i + 1);
        mul(cur, r[i]);
        mul(cur, 2);
        add(sum, cur);
    } 

    mul(sum, 2);

    int res = binPow(3, n);

    sub(res, sum);

    cout << res << endl;

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}

 

Measured memory_bytes: 39296
def main():
    N, T = map(int,input().split())
    A = [0]
    B = [0]

    for _ in range(N):
        a, b = map(int,input().split())
        A.append(a)
        B.append(b)

    dp1 = [[0] * (T + 1) for i in range(N + 1)]
    # dp1[i][t] = 1~i番目から選んでt分以内に食べるときの美味しさの和の最大値
    dp2 = [[0] * (T + 1) for i in range(N + 2)]
    # dp2[i][t] = i~N番目から選んでt分以内に食べるときの美味しさの和の最大値

    for i in range(1, N+1):
        for t in range(T+1):
            if t >= A[i]:
                dp1[i][t] = max(dp1[i-1][t], dp1[i-1][t-A[i]] + B[i])
            else:
                dp1[i][t] = dp1[i-1][t]

    for i in range(N, 0, -1):
        for t in range(T + 1):
            if t >= A[i]:
                dp2[i][t] = max(dp2[i + 1][t], dp2[i + 1][t - A[i]] + B[i])
            else:
                dp2[i][t] = dp2[i + 1][t]

    ans = dp1[N][T]
    for i in range(1, N+1): # 最後にi番目の料理を食べる
        for t in range(T):
            ans = max(ans, dp1[i-1][t] + dp2[i+1][T-1-t] + B[i])
    print(ans)

if __name__ == "__main__":
    main()



Measured memory_bytes: 215948
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <chrono>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s1, s2;
    cin >> s1 >> s2;
    int s1_size = s1.size(), s2_size = s2.size();
    int cost_i = 1, cost_d = 1, cost_s = 1;

    // s1をs2にする編集距離
    vector<vector<int>> dp(s1_size+1, vector<int>(s2_size+1, 0));
    for(int i=0; i<s1_size+1; i++){
        dp[i][0] = i * cost_d;
    }
    for(int i=0; i<s2_size+1; i++){
        dp[0][i] = i * cost_i;
    }

    // 上から下は削除, 左から右は挿入, 斜めは置換
    // 同一の場合は斜めからコストなしで作成可
    for(int i=1; i<s1_size+1; i++){
        for(int j=1; j<s2_size+1; j++){
            if(s1[i-1] == s2[j-1]){
                dp[i][j] = dp[i-1][j-1];
            }else{
                dp[i][j] = min(dp[i-1][j] + cost_d, min(dp[i][j-1] + cost_i, dp[i-1][j-1] + cost_s));
            }
        }
    }
    
    COUT(dp.back().back());
    
    return 0;
}


Measured memory_bytes: 6736
_ = input()
A = list(map(int, input().rstrip().split(" ")))

x = A[-1]

i = 0
j = 0
while i < len(A) - 1:
    if A[i] <= x:
        A[j], A[i] = A[i], A[j]
        j += 1
    i += 1
A[-1], A[j] = A[j], A[-1]
A[j] = "[" + str(A[j]) + "]"

A = list(map(str, A))
print(" ".join(A))in(list(map(str, A)))


Measured memory_bytes: 16384
#include <algorithm>
#include <cstdio>
#include <vector>
int ans, arr[100005], k;
std::vector<int> son[100005];
int dfs(int u)
{
	int dep = 1;
	for (int v : son[u])
		dep = std::max(dep, dfs(v) + 1);
	if (dep == k)
	{
		ans += !!arr[u];
		dep = 0;
	}
	return dep;
}
int main()
{
	// freopen("AGC004-D.in", "r", stdin);
	int n;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i);
		if (!i)
		{
			ans += arr[i] != 1;
			arr[i] = 0;
		}
		else
			son[--arr[i]].push_back(i);
	}
	dfs(0);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
#define _CRT_SECURE_NO_WARNINGS
int w, h;
char c[62][12];
bool checked[62][12] = {};

queue<P> Q;
int dx[3] = { 1,0,-1 };
int dy[3] = { 0,1,0 };

int g[62][12] = {};
int blockNum[62][12] = {};

int blockHash[62][12] = {};
int nowHash=1;
bool gChecked[10];

int top[12];
int l, r;
queue<P> blockQ;
int weight = 0;
int countingBlockNum;

bool ans = true;
void SetLRT(int _y,int _x) {
	for (int i = 0; i < w;i++) {
		top[i] = 100;
	}
	weight = 0;
	l = 100; r = -1;

	P p(_y, _x);
	Q.push(p);
	checked[_y][_x] = true;
	blockHash[_y][_x] = nowHash;
	top[_x] = min(top[_x], _y);
	if (_y + 1 < h) {
		if (c[_y + 1][_x] != '.' && c[_y + 1][_x] != c[_y][_x]) {
			l = min(l, _x); r = max(r, _x);
		}
	}
	else {
		l = min(l, _x); r = max(r, _x);
	}
	weight += _x;
	blockQ.push(p);

	while (!Q.empty()) {
		P now = Q.front();
		Q.pop();
		for (int i = 0; i < 3; i++) {
			int y = now.first + dy[i];
			int x = now.second + dx[i];
			if (c[y][x] == c[_y][_x] && !checked[y][x]) {
				p.first = y; p.second = x;
				Q.push(p);
				checked[y][x] = true;
				blockHash[y][x] = nowHash;
				top[x] = min(top[x], y);
				if (y + 1 < h) {
					if (c[y + 1][x] != '.' && c[y + 1][x] != c[y][x]) {
						l = min(l, x); r = max(r, x);
					}
				}
				else {
					l = min(l, x); r = max(r, x);
				}
				weight += x; 
				blockQ.push(p);
			}
		}
	}
	nowHash++;
}

//FILE* fp;

void CalcG() {
	for (int i = 1; i < nowHash;i++) {
		gChecked[i] = false;
	}
	countingBlockNum = 0;
	for (int i = 0; i < w;i++) {
		if (0 < top[i] && top[i] < 100  && c[top[i] - 1][i]!='.' && !gChecked[blockHash[top[i] - 1][i]]) {
			weight += g[top[i] - 1][i];
			countingBlockNum += blockNum[top[i] - 1][i];
			gChecked[blockHash[top[i] - 1][i]] = true;
		}
	}
	float n = (float)weight / (countingBlockNum + 4);
	if ( n <= l-0.5 || r+0.5 <= n ) {
		ans = false;
		return;
	}
	while (!blockQ.empty()) {
		P now = blockQ.front(); blockQ.pop();
		g[now.first][now.second] = weight;
		blockNum[now.first][now.second] = countingBlockNum+4;
	}
}
int main() {

	//fp = fopen("a.txt", "w");
	while (1) {
		scanf("%d%d", &w, &h);
		if (w==0) {
			break;
		}
		for (int i = 0; i < h; i++) {
			scanf("%s", &c[i]);
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				checked[i][j] = false;
				blockHash[i][j] = 0;
				g[i][j] = 0;
				blockNum[i][j] = 0;
			}
		}
		ans = true;
		nowHash = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (c[i][j] != '.' && !checked[i][j]) {
					SetLRT(i,j);
					CalcG();
					if (ans == false) {
						break;
					}
				}
			}
			if (ans == false) {
				break;
			}
		}

		if (ans == false) {
			printf("UNSTABLE\n");
			//fprintf(fp, "UNSTABLE\n");
		}
		else {
			printf("STABLE\n");
			//fprintf(fp, "STABLE\n");
		}
	}
	//fclose(fp);
	return 0;
}


Measured memory_bytes: 2520
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		var S = sc.get();
		var T = sc.get().toCharArray();
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < S.length() - T.length + 1; i++) {
			var seq = S.substring(i, i + T.length).toCharArray();
			int count = 0;
			for (int j = 0; j < seq.length; j++) {
				if (seq[j] != T[j]) {
					count++;
				}
			}
			min = Math.min(min, count);
		}
		System.out.println(min);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 33556
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
const ll maxn = 100000000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
    ll v,e;
    cin>>v>>e;
    vvll d(v,vll(v,maxn));
    rep(i,e){
        ll s,t,k;
        cin>>s>>t>>k;
        d.at(s).at(t)=k;
       // d.at(t).at(s)=k;
    }
    rep(i,v){
        d.at(i).at(i)=0;
    }
    for(int k=0;k<v;k++){
        for(int i=0;i<v;i++){
            for(int j=0;j<v;j++){
                d.at(i).at(j)=min(d.at(i).at(j),d.at(i).at(k)+d.at(k).at(j));
               
                //cout<<d.at(i).at(j)<<endl;
               
            
            }
        }
    }
    
    rep(i,v){
       
       
          if(d.at(i).at(i)<0){
                cout<<"NEGATIVE CYCLE"<<endl;
                return 0;  
          }
           
        
    }
     rep(i,v){
        rep(j,v-1){
            if(d.at(i).at(j)>=1000000000000)cout<<"INF ";
            else cout<<d.at(i).at(j)<<" ";
        }
        if(d.at(i).at(v-1)>=1000000000000)cout<<"INF"<<endl;
        else cout<<d.at(i).at(v-1)<<endl;
    }
   
}



Measured memory_bytes: 3252