akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int jun[114514],n,ans=0,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&jun[i]);
    }
    for(i=0;i<n;i++){
        if(jun[i]==(i+1) && i!=n-1){
            swap(jun[i],jun[i+1]);
            ans ++;
        }
        if(jun[i]==(i+1) && i==n-1){
            ans ++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
string s;
cin >> s;
int n = s.size();
if (n%2 == 0){
cout << "No";
return 0;
}
bool ok = true;
for (int i = 0; i < n/2; i++) {
if (s[i] != s[n-1-i]) {
ok = false;
break;
}
}
if(!ok){
cout << "No";
return 0;
}
string s1 = s.substr(0, n/2);
string s2 = s.substr((n+1)/2, n/2);
n = n/2;
for (int i = 0; i < n/2; i++) {
if (s1[i] != s1[n-1-i]) {
ok = false;
break;
}
}
for (int i = 0; i < n/2; i++) {
if (s2[i] != s2[n-1-i]) {
ok = false;
break;
}
}
if(!ok){
cout << "No";
return 0;
}
cout << "Yes";

}

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

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> edge(N+1);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back({b, i});
        edge[b].push_back({a, i});
    }
    int M;
    cin >> M;
    vector<ll> route(M);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        queue<pair<pair<int, int>, ll>> q;
        q.push({{u, -1}, 0});
        while (!q.empty()) {
            int now = q.front().first.first;
            int par = q.front().first.second;
            ll r = q.front().second;
            q.pop();
            if (now == v) {
                route[i] = r;
                break;
            }
            for (auto p : edge[now]) {
                if (p.first == par) continue;
                q.push({{p.first, now}, r+(1LL<<p.second)});
            }
        }
    }
    vector<ll> bit(1LL << M, 0);
    for (int i = 1; i < (1LL<<M); i++) {
        int t = __builtin_ffs(i) - 1;
        bit[i] = bit[i-(1LL<<t)] | route[t];
    }
    ll ans = 0;
    for (int i = 0; i < (1LL<<M); i++) {
        int t = 0, u = 0;
        t = __builtin_popcountll(bit[i]);
        u = __builtin_parity(i);
        if (u == 0) ans += (1LL << (N-1-t));
        else ans -= (1LL << (N-1-t));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8448
/*
要做这道题...先简单分析一下
dp稳了，但是难在怎么处理or
就是所谓的i or j <= k...
那么转移的时候就是看哪些新的可以加进来
打个表试试...
没用
这么做吧
int f[maxn], g[maxn];
用两个数组存
分别表示为k的时候，最大的俩
 */
#define R register
#include <bits/stdc++.h>

using namespace std;

const int maxn = (1 << 18) + 5;

int n, a[maxn], f[maxn], g[maxn], tmp[10];
int main()
{
	scanf("%d", &n);
	for (R int i = 0; i < (1 << n); ++i) scanf("%d", &a[i]), f[i] = a[i];
	for (R int j = 0; j < n; ++j)
	{
        for (R int i = 0; i < (1 << n); ++i)
			if((i | (1 << j)) != i) {
				tmp[1] = f[i], 
				tmp[2] = g[i], 
				tmp[3] = f[i | (1 << j)], 
				tmp[4] = g[i | (1 << j)];
				sort(tmp + 1, tmp + 1 + 4);
				f[i | (1 << j)] = tmp[4], g[i | (1 << j)] = tmp[3];
			}
	}
	int ans = 0;
	for (R int i = 1; i < (1 << n); ++i)
		ans = max(ans, f[i] + g[i]), printf("%d\n", ans);
}

Measured memory_bytes: 6144
#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()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

#include <boost/multiprecision/cpp_dec_float.hpp>

namespace mp = boost::multiprecision;
// 仮数部 500 bit の浮動小数点数
using cpp_dec_float = mp::number<mp::cpp_dec_float<500>>;

int main()
{
    cpp_dec_float a;
    cpp_dec_float b;
    cin >> a >> b;

    // 桁数
    cout << (long long)(a * b) << endl;
    return 0;
}

Measured memory_bytes: 3876
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[100005];
int main()
{
    int n;
    scanf("%d",&n);
    ll a[100005],i;

    for(i=0; i<n; i++)
        scanf("%lld",&a[i]),b[i]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
    rep(i, H) rep(j, W) cin >> S[i + 1][j + 1];
    
    vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
    vector<int> dy = {0, 1, 1, 1, 0, -1, -1, -1};
    vector<vector<int>> ans(H + 2, vector<int>(W + 2, -1));
    rep(i, H) rep(j, W) {
        if (S[i + 1][j + 1] == '#') continue;
        int cnt = 0;
        rep(k, 8) {
            if (S[i + 1 + dx[k]][j + 1 + dy[k]] == '#') ++cnt;
        }
        ans[i + 1][j + 1] = cnt;
    }
    
    rep(i, H) {
        rep(j, W) {
            if (ans[i + 1][j + 1] == -1) cout << '#';
            else cout << ans[i + 1][j + 1];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.length();
  char ch=s[n-1];
  char ch2=s[n-2];
  if(ch=='e'){
    s=s+"s";
    cout<<s;
  }
  else if(ch=='s'){
    cout<<s+"es";
  }
  else{
    cout<<s+"s";
  }
      
  return 0;
}

Measured memory_bytes: 3128
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 300005;

#define lsb(x) (x&(-x))

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

ll n;
ll aib[NMAX];
// the aib is 1 indexed

void update(ll x, ll position)
{
	position = position+1;
	for(int i = position; i<= n; i+=lsb(i))
		aib[i]+=x;
}

// adds from left but substract from right
void update_range(ll x, int left, int right)
{
	update(x,left);
	update(-x,right+1);
}

ll query(ll position)
{
	position = position+1;
	ll sum = 0;
	for(int i = position; i> 0; i-=lsb(i))
	{
		sum+=aib[i];
	}
	return sum;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll d,a;
    cin >> n >> d >> a;

    vector<pair<ll,ll> > monsters;

    for(int i =0; i < n; ++i)
    {
		ll x, h;
		cin >> x >> h;
		h = (h + a - 1) / a;
		monsters.emplace_back(x,h);
	}

	sort(monsters.begin(), monsters.end());

	for(int i = 0; i< n; ++i)
	{
		ll toAdd = monsters[i].second;
		if(i)
			toAdd-= monsters[i-1].second;

		// ca la smenul lui mars vectorul b a[i] = b[0] + b[1] + .. b[i]
		update(toAdd,i);
	}
	// segment tree or BIT to hold the health of the monsters
	// want to use smenul lui mars pt aib 

	ll ans = 0;
    for(int i =0 ; i < n; ++i)
	{
		// prefix sum (0,i) din b care da elementul i
		ll currHp = query(i);
		if(currHp <= 0)
			continue;

		ll low = i, high = n - 1;
		ll ok = -1;

		while(low <= high)
		{
			ll mid = (low + high) / 2;
			// find the last monster still hit by a bomb starting from monster[i] location
			if(monsters[mid].first <= monsters[i].first + 2LL * d)
			{
				ok = mid;
				low = mid+1;
			}
			else
			{
				high = mid-1;
			}
		}
		assert(ok != -1);
		update_range(-currHp,i,ok);
		ans+=currHp;
	}
	cout << ans;

    return 0;
}

Measured memory_bytes: 6256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

typedef long long LL;
const int maxn = 1e5 + 20;

int N, E, T;
int x[maxn];
LL f[maxn];

int main()
{
	scanf("%d%d%d", &N, &E, &T);
	for(int i = 1; i <= N; i++)
	{
		scanf("%d", &x[i]);
	}
	
	LL pmin = 1ll << 60;
	
	for(int i = 1, p = 1; i <= N; i++)
	{
		while(p <= N && (x[i] - x[p]) * 2 > T)
		{
			pmin = std::min(pmin, f[p - 1] - 2 * x[p]);
			p++;
		}
		
		f[i] = f[i - 1] + T;
		f[i] = std::min(f[i], f[p - 1] + T);
		f[i] = std::min(f[i], pmin + 2 * x[i]);
	}
	
	printf("%lld\n", f[N] + E);
	
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <functional>
#include <cmath>
#include <cassert>
#define SIZE 42
#define MX 9
#define MOD 1000000007

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

map <vector <int>,int> mp,nxt;
map <vector <int>,int>::iterator it;
int n,X,Y,Z;

bool ok(vector <int> vec)
{
	int nm=0;
	int start=vec.size();start--;
	while(start>=0&&nm<X+Y+Z) nm+=vec[start--];
	if(nm>X+Y+Z) return false;
	int sum=0;
	int turn=0;
	for(int i=start+1;i<vec.size();i++)
	{
		sum+=vec[i];
		int tg=turn==0?X:turn==1?Y:Z;
		if(sum>tg) return false;
		if(sum==tg)
		{
			sum=0;
			turn++;
		}
	}
	return turn==3;
}
int main()
{
	scanf("%d %d %d %d",&n,&X,&Y,&Z);
	vector <int> NL,vec,now,T;
	mp[NL]=1;
	for(int i=0;i<n;i++)
	{
		//printf("%d\n",mp.size());
		nxt.clear();
		int sum=0;
		for(it=mp.begin();it!=mp.end();it++)
		{
			T=it->first;
			int way=it->second;
			if(i>=10)
			{
				//for(int j=0;j<T.size();j++) printf("%d ",T[j]);printf(": %d\n",way);
			}
			for(int j=1;j<=7;j++)
			{
				vec=T;
				vec.push_back(j);
				int nm1=0;
				int start=vec.size();start--;
				while(start>=0&&nm1<X+Y+Z) nm1+=vec[start--];
				start++;
				if(nm1==X+Y+Z)
				{
					int sum1=0;
					int turn=0;
					bool up=true;
					for(int i=start;i<vec.size();i++)
					{
						sum1+=vec[i];
						int tg=turn==0?X:turn==1?Y:Z;
						if(sum1>tg)
						{
							up=false;
							break;
						}
						if(sum1==tg)
						{
							sum1=0;
							turn++;
						}
					}
					if(up) continue;
				}
				now.clear();
				for(int k=start;k<vec.size();k++)
				{
					int nm=0;
					int turn=0;
					bool up=true;
					for(int p=k;p<vec.size();p++)
					{
						nm+=vec[p];
						int tg=turn==0?X:turn==1?Y:Z;
						if(nm>tg)
						{
							up=false;
							break;
						}
						if(nm==tg)
						{
							nm=0;
							turn++;
						}
					}
					if(up)
					{
						//printf("%d %d %d\n",X+Y+Z,nm,turn);
						//for(int p=0;p<vec.size();p++) printf("%d ",vec[p]);printf(": %d %d\n",k,turn);
						for(int p=k;p<vec.size();p++) now.push_back(vec[p]);
						//for(int p=0;p<now.size();p++) printf("%d ",now[p]);puts("");
						break;
					}
				}
				//if(i<=8) {for(int j=0;j<now.size();j++) printf("%d ",now[j]);puts("");}
				nxt[now]+=way;
				if(nxt[now]>=MOD) nxt[now]-=MOD;
			}
			for(int j=8;j<=10;j++)
			{
				sum+=way;
				if(sum>=MOD) sum-=MOD;
			}
		}
		nxt[NL]+=sum;
		if(nxt[NL]>=MOD) nxt[NL]-=MOD;
		mp=nxt;
	}
	int ret=0;
	for(it=mp.begin();it!=mp.end();it++)
	{
		vec=it->first;
		int sum=0;
		for(int i=0;i<vec.size();i++) sum+=vec[i];
		ret+=it->second;
		if(ret>=MOD) ret-=MOD;
	}
	ll all=1;
	for(int i=0;i<n;i++) all=all*10LL%MOD;
	printf("%lld\n",(all+MOD-ret)%MOD);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int lcm(int x, int y){
  return x/__gcd(x, y)*y;
}


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int l = 1;
  vector<int> v(N);
  REP(i, N){
    l = lcm(l, A[i]/2);

    if(l > M){
      cout << 0 << "\n";
      return 0;
    }
    while(A[i]%2 == 0){
      A[i] /= 2;
      v[i]++;
    }
  }

  sort(ALL(v));
  if(v[0] != v[N-1]){
    cout << 0 << "\n";
    return 0;
  }

  cout << M/l-M/(l*2) << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
int a[maxn], f[maxn], g[maxn];
inline bool chk(int a,int b,int c) {
	return a < b && b < c || b < c && c < a || c < a && a < b;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		int x; cin >> x, a[x] = i;
	}
	for(int i = n - 1;i >= 1;--i) {
		if(!g[i + 1]) {
			if(a[i] > a[i + 1]) {
				g[i] = 1;
				f[i] = i + 1;
			}
		} else {
			if(chk(a[f[i + 1]], a[i], a[i + 1])) {
				g[i] = g[i + 1];
				f[i] = f[i + 1];
			} else {
				g[i] = g[i + 1] + 1;
				f[i] = i + 1;
			}
		}
	}
	cout << g[1] << '\n';
}


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

char f(int n,char c){
    for(int i=0;i<n;i++){
        if(c=='Z'){
            c = 'A';
            continue;
        }
        c++;
    }
    return c;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
        s.at(i) = f(n,s.at(i));
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int n;
  cin>>n;
  vector<int> t(n);
  for(int i=0;i<n;i++) cin>>t[i];
  int m=*max_element(t.begin(),t.end());
  vector<int> v;
  for(int i=1;i<=m;i++)
    if(m%i==0) v.push_back(i);
  int ans=0;
  for(int i=0;i<n;i++)
    ans+=*lower_bound(v.begin(),v.end(),t[i])-t[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		StringBuilder sb = new StringBuilder(in.next());
		int num = in.nextInt();

		for(int i = 0; i < num; i++){

			String command = in.next();

			if(command.equals("print")){

				// ???????????????????????????????????§?????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();

				// ????????????????????????????????????
				System.out.println(sb.substring(first_num, second_num + 1));

			}else if(command.equals("reverse")){

				// ???????????????????????????????????§????????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();

				sb = reverse(first_num, second_num, sb);

				/*// ????????????????????????????????????????????????
				String reverse_word = sb.substring(first_num, second_num + 1);
				// ??????????????????????????????????????§?????????????????????
				StringBuilder reverse_sb = new StringBuilder(reverse_word);
				// ???????????????????????????
				reverse_word = reverse_sb.reverse().toString();
				// ???????????????????????????????????????????????´?????????????????????
				sb = sb.replace(first_num, second_num+1, reverse_word);*/

			}else if(command.equals("replace")){

				// ???????????????????????????????????§???????????????????????????
				int first_num = in.nextInt();
				int second_num = in.nextInt();
				// ??????????????????????????????
				String str = in.next();
				// ?????????????????????
				sb.replace(first_num, second_num + 1, str);

			}
		}
	}
	public static StringBuilder reverse(int first_num, int second_num, StringBuilder sb){

		// ????????????????????????????????????????????????
		String reverse_word = sb.substring(first_num, second_num + 1);
		// ??????????????????????????????????????§?????????????????????
		StringBuilder reverse_sb = new StringBuilder(reverse_word);
		// ???????????????????????????
		reverse_word = reverse_sb.reverse().toString();
		// ???????????????????????????????????????????????´?????????????????????
		sb = sb.replace(first_num, second_num+1, reverse_word);

		return sb;

	}
}

Measured memory_bytes: 29096
# coding: utf-8

def get_ans():
    n = int(input().rstrip())
    if n == 0:
        return "0"
    dv = 1
    bit_list = []
    while n != 0:
        tmp = n % (dv*2)
        if tmp == 0:
            bit_list.append("0")
        else:
            bit_list.append("1")
        n -= tmp
        dv *= -2
    return "".join(reversed(bit_list))


print(get_ans())


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
//#include <stdio.h>

using namespace std;

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

    int kekka;

    string S;

    cin >> S;

    string str1 = S.substr(0, 4);
    int num1 = atoi(str1.c_str());

    string str2 = S.substr(5, 2);
    int num2 = atoi(str2.c_str());

    string str3 = S.substr(8, 2);
    int num3 = atoi(str3.c_str());

    if(num1 < 2019){
        kekka = 1;
    }else if(num1 == 2019){
        if(num2 < 4){
            kekka = 1;
        }else if(num2 == 4){
            if(num3 <= 30){
                kekka = 1;
            }else
            {
                kekka = 0;
            }     
        }else
        {
            kekka = 0;
        }
    }else{
        kekka = 0;
    }


    if(kekka == 1){
        cout << "Heisei";
    }else
    {
        cout << "TBD";
    }
    
    
}

Measured memory_bytes: 760
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  bool zero_flag = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2) zero_flag = true;
  }
  ll ans = 0;
  while (!zero_flag) {
    for (int i = 0; i < N; i++) {
      A[i] /= 2;
      if (A[i] % 2) zero_flag = true;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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


#define abs1(a) ((a) >= 0 ? (a) : ((a) * -1))

int main(void)
{
    int n;
    int x[100], y[100];
    double p1, p2, p3, pn;
    int i;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d", &y[i]);
    }
    
    p1 = p2 = p3 = 0;
    for (i = 0; i < n; i++){
        p1 += abs1(x[i] - y[i]);
        p2 += abs1(x[i] - y[i]) * abs1(x[i] - y[i]);
        p3 += abs1(x[i] - y[i]) * abs1(x[i] - y[i]) * abs(x[i] - y[i]);
    }
    
    pn = abs1(x[0] - y[0]);
    for (i = 1; i < n; i++){
        if (pn < abs1(x[i] - y[i])){
            pn = abs1(x[i] - y[i]);
        }
    }

    printf("%lf\n", p1);
    printf("%lf\n", sqrt(p2));
    printf("%lf\n", pow(p3, 1.0 / 3.0));
    printf("%lf\n", pn);
    
    return (0);
}



Measured memory_bytes: 2104
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vll h(N);
    inN(h, N);

    ll ans = h[0];

    reps(i, 1, N)
    {
        ans += h[i] > h[i - 1] ? h[i] - h[i - 1]:0;
    }

    outl(ans);

    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;


typedef struct {
    int num;
    char suit[2];
} Card;

void readCard(Card c[],int i){
    char cc[3],num[2];
    cin >> cc;
    
    num[0] = cc[1];
    num[1] = '\0';
    c[i].num = atoi(num);
    c[i].suit[0] = cc[0];
    c[i].suit[1] = '\0';
}

void bs(Card c[],int N){
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (c[j].num < c[j-1].num){
                swap(c[j],c[j-1]);
            }
        }
    }
}

void ss(Card c[],int N){
    for (int i = 0; i < N-1; i++) {
        int mini = i;
        for (int j = i+1; j < N; j++) {
            if (c[mini].num > c[j].num) {
                mini = j;
            }
        }
        if(mini != i) swap(c[i],c[mini]);
    }
}

void printCard(Card c[],int N){
    for (int i = 0; i < N; i++) {
        cout << c[i].suit << c[i].num;
        if (i != N-1) cout << " ";
    }
    cout << endl;
}

int main(){
    int N;
    Card s[36],b[36];
    cin >> N;
    for (int i = 0; i < N; i++) {
        readCard(s,i);
        b[i] = s[i];
    }
    bs(b,N);
    ss(s,N);
    
    printCard(b,N);
    cout << "Stable" << endl;
    printCard(s,N);
    
    bool flag = true;
    
    for (int i = 0; i < N; i++) {
        if(b[i].suit[0] != s[i].suit[0]){
            flag = false;
            break;
        }
    }
    
    if (flag) {
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1176
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
counter = Counter(''.join(sorted(input())) for _ in range(N))
print(sum(i * (i - 1) // 2 for i in counter.values()))



Measured memory_bytes: 58972
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 20;
int n, m, x, y, q, d,z, w = 0, sum, ans = 0;
vector<int>a;
const int MAX = 510000;
const int MOD = 1000000007;
vector<pair<pair<string, int>, int>> p;
int main(void) {
	string s, t; cin >> s >> t;
	vector<int> a(26,0), b(26,0);
	rep(i, s.size()) {
		a[s[i] - 'a']++;
	}rep(i, t.size()) {
		b[t[i] - 'a']++;
	}sort(ALL(a)); sort(ALL(b));
	if (a == b) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 3832
#include <iostream>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define bs(n) (1ull<<(n))

ll digits(ll b,ll n) {
	if (b <= 1) return -1;
	ll c = 0;
	while (n > 0) {
		c += n % b;
		n /= b;
	}
	return c;
}

int main() {
	ll n, s;
	cin >> n >> s;
	if (n == s) {
		cout << n + 1 << endl;
		return 0;
	}
	ll m = (ll)sqrt(n);
	for (ll i = 2; i <= m; i++) {
		if (digits(i, n) == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (ll i = m; i > 0; i--) {
		if ((n - s) % i)continue;
		ll b = (n - s + i) / i;
		if (digits(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

int main(void){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> sum(N+1, 0);
    for(int i=1;i<N;i++){
        if( S[i-1] == 'A' && S[i]=='C' ){
            sum[i+1] = sum[i] + 1;
        } else{
            sum[i+1] = sum[i];
        }
    }

    vector<int> L(Q), R(Q);
    for(int i=0;i<Q;i++){
        cin >> L[i] >> R[i];
    }
    for(int i=0;i<Q;i++){
        cout << sum[R[i]] - sum[L[i]] << endl;
    }

}

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

 int H, W, i, j;
 while(1) {

 scanf("%d%d",&H,&W);

 if(H == 0 && W == 0) break;
  for(i = 1; i <= H; i++) {
   for(j = 1; j <= W; j++) {
    if(i == 1 || i == H || j == 1 || j == W) {
    printf("#");
    } else {
    printf(".");
    }
   }
  printf("\n");
  }
 printf("\n");
 }

 return 0;
}

Measured memory_bytes: 572
n = int(input())
l =[[' ', 0, -1] for i in range(n)]
for i in range(n):
    l[i][0], p = input().split()
    l[i][1] = -int(p)
    l[i][2] = i+1

l_ = sorted(l)
for i in range(n):
    print(l_[i][2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    string s; cin>>s;
    rep(i,s.size()){
        s[i]='x';
    }
    cout<<s<<endl;


    return 0;
}

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

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

#define forn(i, n) for(int i=0; i<n; i++)
#define mp makepair
#define pb push_back

string s,t;
string ans;

int main(){
    cin>>s>>t;
    int dp[3001][3001] = {0};
    for(int i=1; i <= s.length(); i++) {
        for(int j=1; j <= t.length(); j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = 1 + dp[i-1][j-1]; 
            } else {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }
    string ans = "";
    int i = s.length();
    int j = t.length();
    while(i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            i--;
            j--;
            ans = t[j] + ans;
        } else
        if (dp[i-1][j] > dp[i][j-1]) {
            i--;
        } else {
            j--;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
};
int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(m);
    vector<vector<int>> v(n);
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int l;
            cin >> l;
            l--;
            v[i].push_back(l);
        }
        rep(j, k - 1) {
            uf.unite(v[i][j], v[i][j + 1]);
        }
    }
    bool ok = 1;
    rep(i, n) ok &= uf.find(v[i][0], v[0][0]);
    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 6144
def main():
    A, B, C = map(int, input().split())

    rs = [0] * B
    r = A % B

    s = r
    while True:
        if rs[s]: break
        rs[s] = 1
        s = (s + r) % B

    print('YES' if rs[C] else 'NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import itertools 
N,M,Q=list(map(int,input().split()))
 
ABCD=[list(map(int,input().split())) for _ in range(Q)]
ans=[]
for i in itertools.combinations_with_replacement(range(1,M+1),N):
  num=0
  for a,b,c,d in ABCD:
    if i[b-1]-i[a-1]==c:
      num+=d
  ans.append(num)
print(max(ans))

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

int main(){
    int t;
    cin >> t;
    unsigned long long int w = 1;
    unsigned long long int q = 1000000000000000000;
    bool limited = true;
    bool zero = false;
    while (t--){
        unsigned long long int n;
        cin >> n;
        if (n == 0){
            zero = true;
        }
        if (limited && !zero){
            if(n>q/w){
                limited= false;
            }else{
                w= w*n;
            }
        }
    }

    if (zero){
        cout << 0 << endl;
    }else if (limited){
        cout << w << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const ll INF = (1ll << 60);
bool isok(ll m, ll k, vector<ll> &a, vector<ll> &f)
{
    ll cost = 0;
    rep(i, a.size())
    {
        if (a[i] * f[i] <= m)
            continue;
        cost += a[i] - (m / f[i]);
    }
    return cost <= k;
}

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(ALL(a));
    sort(ALL(f), greater<ll>());
    rep(i, n) cerr << a[i] << " ";
    cerr << endl;
    rep(i, n) cerr << f[i] << " ";
    cerr << endl;
    ll l = -1;
    ll r = INF;
    while (l + 1 != r)
    {
        ll mid = (l + r) / 2;
        if (isok(mid, k, a, f))
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3328
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll =long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

unsigned long long int lcm(unsigned long long int number1, unsigned long long int number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	vector<unsigned long long int> a(n);
	int tmp, tmp2 = 0, tmp3 = -1;
	rep(i, n) {
		scanf("%llu", &a[i]);
		tmp = a[i];
		tmp2 = 0;
		while (tmp % 2 == 0) {
			++tmp2;
			tmp >>= 1;
		}
		if (tmp3 == -1)tmp3 = tmp2;
		if (tmp2 != tmp3) {
			printf("0\n");
			return 0;
		}
	}
	unsigned long long int k = 1;
	rep(i, n)k = lcm(k, a[i]);
	unsigned long long int ans = m / k;
	if (k * ans + (k / 2) <= m)++ans;
	printf("%lld\n", ans);

	Please AC;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;


    for (int i=1; i<=50000; i++) {
	double x = 1.08*i;
	int res = floor(x);
	if (res==n) out(i);
    }

    cout<<":(\n";
    
    
    return 0;
}


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

int main(){
  int i,j;ll cnt=0;
  ll n;
  cin>>n;
  ll a[3*n];
  for(i=0;i<3*n;i++)cin>>a[i];
  sort(a,a+3*n,greater<ll>());
  for(i=0;i<n;i++)cnt+=a[2*i+1];
  cout<<cnt<<endl;
}

Measured memory_bytes: 2560
from collections import Counter
q=[]
h,w,n=map(int,input().split())
for i in range(n):
    x,y=map(int,input().split())
    for j in range(3):
        for k in range(3):
            if (x-2+j)<1 or (x-2+j)>h-2 or (y-2+k)<1 or (y-2+k)>w-2:
                0
            else:
                q.append((x-2+j,y-2+k))
c=Counter(q)
ans=[0]*10
while c:
    ans[c.popitem()[1]]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])
for i in ans:
    print(i)

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

using namespace std;

long long int arr[1000000][2],ans[105][100003];
vector<long long int>crr;
long long int W,N;

int dp[3005][3005];

vector<char> lcs(string  s,string t)
{
	int n=s.size();
	int m=t.size();

	for (int i = 0; i <n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if(s[i]==t[j])
			{
				dp[i+1][j+1]=1+dp[i][j];
			}
			else
			{
				dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);

			}
		}
	}

	vector<char>ans;
	int last=m;
	int val=dp[n][m];


	// for (int i = 0; i <=n; ++i)
	// {
	// 	for(int j=0;j<=m;j++)
	// 	{
	// 			cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }

	// for (int i = n; i >= 0; --i)
	// {
	// 	for (int j = last; j >=0; --j)
	// 	{
	// 		if(dp[i][j]==val)
	// 		{
	// 			last=j;
	// 		}
	// 		else
	// 		{
	// 		//	cout<<i<<" "<<j<<endl;
	// 			ans.push_back(t[j]);
	// 			last=j;
	// 			val--;
	// 			break;
	// 		}
	// 	}

	// }


	for (int i = n; i >0 ; --i)
	{
		for (int j = last; j >0; --j)
		{
			if(s[i-1]==t[j-1])
			{
				ans.push_back(s[i-1]);
				last=j-1;
				break;
			}
			else if(dp[i-1][j]>dp[i][j-1])
			{
				last=j;
				break;
			}
		}
	}
	return ans;
}


int  main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long int n,a,b,c,d,w;
	string s,t;
	cin>>s>>t;

	for (int i = 0; i < 3005; ++i)
	{
		for(int j=0;j<3005;j++)
		{
			if(i!=0 && j!=0)
				dp[i][j]=-1;
		}
	}
	vector<char>ans;
	ans=lcs(s,t);
	reverse(ans.begin(),ans.end());
	for (int i = 0; i < ans.size(); ++i)
	{
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

struct pos{
  int x;
  int y;
  int d;
};

int main(){
  int v[5]={0,1,0,-1,0};
  while(1){
    int r;
    cin >> r;
    if(r==0) return 0;
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    x--,y--;
    vector<vector<int>> m(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> m[i][j];
      }
    }
    priority_queue<pos,vector<pos>,function<bool(pos,pos)>>
      q([](const pos &a, const pos &b){return a.d>b.d;});
    q.push({x,y,1});
    m[y][x]=-1;
    vector<int> a(w*h+1);
    a[0]=0;
    int nowidx=1;
    pos now;
    while(!q.empty()){
      now=q.top();
      q.pop();
      a[nowidx]=max(now.d,a[nowidx-1]);
      // cout << a[nowidx] << " ";
      nowidx++;
      for(int i=0;i<4;i++){
        int nx=now.x+v[i+1];
        int ny=now.y+v[i];
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
          if(m[ny][nx]>0){
            q.push({nx,ny,m[ny][nx]});
            m[ny][nx]=-1;
          }
        }
      }
    }
    // cout << endl;
    cin >> w >> h >> x >> y;
    x--,y--;
    m=vector<vector<int>>(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> m[i][j];
      }
    }
    q.push({x,y,1});
    m[y][x]=-1;
    vector<int> b(w*h+1);
    b[0]=0;
    nowidx=1;
    while(!q.empty()){
      now=q.top();
      q.pop();
      // cout << now.d SP b[nowidx-1] << endl;
      b[nowidx]=max(now.d,b[nowidx-1]);
      // cout << b[nowidx] << endl;
      nowidx++;
      for(int i=0;i<4;i++){
        int nx=now.x+v[i+1];
        int ny=now.y+v[i];
        if(0<=nx&&nx<w&&0<=ny&&ny<h){
          if(m[ny][nx]>0){
            q.push({nx,ny,m[ny][nx]});
            m[ny][nx]=-1;
          }
        }
      }
    }
    // cout << endl;
    int ans=IINF;
    for(int i=0;i<=min(r,(int)a.size()-1)&&r-i<=b.size()-1;i++){
      ans=min(ans,a[i]+b[r-i]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 6020
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
// ciling(x/y) = (x+y-1)/y

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    int n;string s;cin >> n >> s;
    map<pair<char, pair<char, char>>, char> m;
    m[{'S', {'o', 'S'}}] = 'S';
    m[{'S', {'o', 'W'}}] = 'W';
    m[{'S', {'x', 'S'}}] = 'W';
    m[{'S', {'x', 'W'}}] = 'S';
    m[{'W', {'o', 'S'}}] = 'W';
    m[{'W', {'o', 'W'}}] = 'S';
    m[{'W', {'x', 'S'}}] = 'S';
    m[{'W', {'x', 'W'}}] = 'W';
    for(auto ss : {"SS", "SW", "WS", "WW"}){
        string ans = ss;
        for(int i=1;i<n-1;i++){
            ans += m[{ans[i], {s[i], ans[i-1]}}];
            // cout << ans << endl;
        }
        bool flag = false;
        for(int i=0;i<n;i++){
            char l = ans[(i-1+n)%n];
            char r = ans[(i+1+n)%n];
            if(m[{ans[i], {s[i], l}}] != r){
                flag = true;
                break;
            }
        }
        if(!flag){
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n,a,b,c;
string ans;
vector<string> s;
map<pair<pair<int,int>,pair<int,int>>,int> mp;
using P = pair<int,int>;
void dfs(int now,int A,int B,int C)
{
	//if(mp[pair<P,P>(P(now,A),P(B,C))]==0)
	//{
		//mp[pair<P,P>(P(now,A),P(B,C))]=1;
	//}
	//else
	//{
		//return;
	//}
	
	if(A==-1||B==-1||C==-1)
	{
		return;
	}
	if(now==n)
	{
		cout<<"Yes"<<endl;
		for(auto c:ans)
		{
			cout<<c<<endl;
		}
		exit(0);
	}

	if(s[now]=="AB")
	{
		ans[now]='B';
		dfs(now+1,A-1,B+1,C);
		ans[now]='A';
		dfs(now+1,A+1,B-1,C);
	}
	if(s[now]=="BC")
	{
		ans[now]='B';
		dfs(now+1,A,B+1,C-1);
		ans[now]='C';
		dfs(now+1,A,B-1,C+1);
	}
	if(s[now]=="AC")
	{
		ans[now]='A';
		dfs(now+1,A+1,B,C-1);
		ans[now]='C';
		dfs(now+1,A-1,B,C+1);
	}
}

int main()
{
	cin >> n >> a >>b >> c;
	for(int i = 0;i<n;i++)
	{
		string t;
		cin >> t;
		s.push_back(t);
	}
	ans = string(n,0);
	dfs(0,a,b,c);
	cout<<"No"<<endl;
}


Measured memory_bytes: 15884
program d
 integer(8) :: a(0:9)=(/0,1,2,4,7,12,20,29,38,52/),f(10)=0
 read(*,*) n
 f(3)=1
 do i=4,n
 f(i)=f(i-1)*(a(i-2)+a(i-3)+1)
 enddo
 do i=1,n
  do j=1,n
   write(*,'(i0,x)',advance='no') merge(0_8,f(max(i,j))*a(min(i,j))+1,i==j)
  enddo
  write(*,*)
 enddo
end program d

Measured memory_bytes: 512
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

fn main() {
    input! {
    n: usize,
    k: usize,
    }
    let mut l = vec![0; n];
    for _ in 0..k {
        input! {
        d: usize,
        a: [usize; d]
        }
        for i in a {
            l[i - 1] += 1
        }
    }
    let ans = l.iter().filter(|&&x| x == 0).count();
    println!("{}", ans);
}


Measured memory_bytes: 2192