akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
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; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}


int main() {
  int n; cin >> n;
  vector<int> v(n);
  rep(i, n) v[i] = i+1;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

  int a, b, cnt = 0;
  do {
    bool flagp = true, flagq = true;
    rep(i, n){
      if(v[i] != p[i]) flagp = false;
      if(v[i] != q[i]) flagq = false;
    }
    if(flagp) a = cnt;
    if(flagq) b = cnt;
    cnt++;
  } while(next_permutation(ALL(v)));

  int ans = abs(a-b);
  cout << ans << endl;
}


Measured memory_bytes: 3572
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
	int h, w;
	while (cin >> h >> w, h) {
		vector<string> map(h);
		for (auto &a : map)cin >> a;
		int dx[] = { 0,0,1,1,1,-1,-1,-1 };
		int dy[] = { 1,-1,0,-1,1,0,1,-1 };
		vector<tuple<string, int, int, int>> buf;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int d = 0; d < 8; d++) {
					buf.push_back(make_tuple((string)"" + map[i][j], j, i, d));
				}
			}
		}
		int l = 0;
		for (;; l++) {
			sort(buf.begin(), buf.end());
			vector<tuple<string, int, int, int>> buf2;
			for (int i = 1; i < buf.size(); i++) {
				if (get<0>(buf[i - 1]).size() < l)continue;
				if (get<0>(buf[i - 1]) == get<0>(buf[i]))buf2.push_back(buf[i - 1]);
				for (; i<buf.size()&&get<0>(buf[i - 1]) == get<0>(buf[i]); i++)buf2.push_back(buf[i]);
			}
			if (buf2.empty())break;
			buf = move(buf2);
			for (auto &a : buf) {
				string str;
				int x, y, d;
				tie(str, x, y, d) = a;
				int x1 = ((x + dx[d]*l) % w + w) % w;
				int y1 = ((y + dy[d]*l) % h + h) % h;
				if (x1 == x && y1 == y)continue;
				str += map[y1][x1];
				a = make_tuple(str, x, y, d);
			}
		}
		if (l < 3)cout << 0 << endl;
		else {
			string str = get<0>(buf[0]);
			cout << str.substr(0, l-1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3420
#include <iostream>
#include <complex>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define X real()
#define Y imag()
#define EPS (1e-9)
typedef complex<double> P;
typedef pair<P,P> L;


double dot(P a, P b){ return a.X*b.X + a.Y*b.Y;}
double cross(P a, P b){ return a.X*b.Y - a.Y*b.X;}

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < 0) return 2;
  if(abs(b) + EPS < abs(c)) return -2;
  return 0;
}

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector<P> B, W;
    double x, y;
    for(int i = 0; i < n; ++i){
      cin >> x >> y;
      B.emplace_back(x,y);
    }
    for(int i = 0; i < m; ++i){
      cin >> x >> y;
      W.emplace_back(x,y);
    }
    bool f = true;
    int c[] = {1,-2,-1,2,1,-2};
    map<int,int> mp;
    mp[1] = 4;
    mp[-2] = 1;
    mp[-1] = 2;
    mp[2] = 3;
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < m; ++j){
        set<int> b_, w_;
        f = true;
        for(int k = 0; k < n; ++k){
          if(k == i) continue;
          int t = ccw(B[i],W[j],B[k]);
          if((!t) || t == -2){
            f = false;
            break;
          }
          b_.insert(t);
        }
        if(!f) break;
        for(int k = 0; k < m; ++k){
          if(k == j) continue;
          int t = ccw(B[i],W[j],W[k]);
          if((!t) || t == 2){
            f = false;
            break;
          }
          w_.insert(t);
        }
        if(!f) continue;
        vector<int> B_, W_;
        for(auto itr = b_.begin(); itr != b_.end(); ++itr) B_.emplace_back(*itr);
        for(auto itr = w_.begin(); itr != w_.end(); ++itr) W_.emplace_back(*itr);
        if(W_.size() > 2){
          f = false;
          continue;
        }
        if(W_.size() == 2 && W_[1] != c[mp[W_[0]]+1] && W_[1] != c[mp[W_[0]]-1]){
          f = false;
          continue;
        }
        if(B_.size() > 2){
          f = false;
          continue;
        }
        if(B_.size() == 2 && B_[1] != c[mp[W_[0]]+1] && B_[1] != c[mp[B_[0]]-1]){
          f = false;
          continue;
        }
        f = true;
        for(int i = 0; i < B_.size(); ++i){
          for(int j = 0; j < W_.size(); ++j){
            if(B_[i] == W_[j]){
              f = false;
              break;
            }
          }
        }
        if(f){
          cout << "YES" << endl;
          break;
        }
      }
      if(f) break;
    }
    if(!f) cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3188
string = input()
for i in range(int(input())):
    lst = list(map(str, input().split()))
    if lst[0] == "replace":
        string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
    if lst[0] == "reverse":
        rev_str = str(string[int(lst[1]):int(lst[2])+1])
        string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
    if lst[0] == "print":
        print(string[int(lst[1]):int(lst[2])+1])



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

int main(){
  long L,R;
  cin >> L >> R;
  long between = R - L + 1;
  L %= 2019;
  R %= 2019;
  if(between >= 2019){
    cout << 0 << endl;
  }else{
    if(L < R){
      //ここが違いそう
      int count = 2019;
      for(int i = L;i <= R - 1;i++){
        for(int j = i + 1;j <= R;j++){
          int k = i * j;
          k %= 2019;
          count = min(count,k);
          //cout << count <<endl;
        }
      }
      cout << count << endl;
    }else{
      cout << 0 << endl;
    }
  }
}


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

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

	vector<pair<string, int>> stv(n);
	for (auto& st: stv) {
		cin >> st.first >> st.second;
	}

	string x;
	cin >> x;

	bool isStart = false;
	int ret = 0;
	for (auto& st : stv) {
		if (isStart) {
			ret += st.second;
		}
		if (st.first == x) {
			isStart = true;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//A
int main() {
	char S[500010];
	scanf("%s", S);
	ll len = strlen(S);

	char prev = ' ';
	ll count = 0;
	ll index = 0;
	if (S[0] == '<') {
		index = 0;
		prev = '<';
	}
	else {
		index = 1;
		prev = '>';
	}

	vector<ll> A(len, 0);

	for (ll i = 0; i < len; i++) {
		if (S[i] == '<')
		{
			if (prev == '<') {
				A[index]++;
			}
			else {
				index++;
				A[index]++;
			}

			prev = '<';
		}
		else { // >
			if (prev == '>') {
				A[index]++;
			}
			else {
				index++;
				A[index]++;
			}

			prev = '>';
		}
	}

	ll result = 0;

	for (ll i = 0; i <= index; i+=2) {
		for (ll j = 0; j < A[i]; j++) {
			result += j;
		}

		for (ll j = 0; j < A[i + 1]; j++) {
			result += j;
		}

		result += max(A[i], A[i + 1]);
	}

	printf("%lld\n", result);
}



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

int main() {
  int N;
  bool fin = false;
  cin >> N;
  if (N == 1) cout << 1 << endl;
  else {
    for(int i = 64; i > 1; i /= 2) {
      for(int j = N; j > i-1; j--) {
        if(j%i == 0) {
          cout << j << endl;
          fin = true;
          break;
        }
      }
      if (fin == true) break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double L;
  cin >> L;
  double ans = (L*L*L) / 27;
  cout << fixed << setprecision(10) << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n,x = list(map(int,input().split()))	
a = list(map(int,input().split()))
a.sort()

#print(a)
c=0
for i in range(n):
    c+=a[i]
#    print(c)
    if c > x:
        break
if c==x:
    i+=1

print(i)
    
    


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
const long long INF = 1e15;
using P = pair<long long, int>;
int n, m, s[2], u, v, a[2], from, to;
long long dist[2][MX], ac, cost, ans[MX];
vector<P> G[2][MX];
priority_queue<P, vector<P>, greater<P>> qu;
void dijkstra(int s, int f){
    fill(dist[f], dist[f]+n, INF);
    qu.push(P(dist[f][s] = 0,s));
    while(!qu.empty()){
        tie(ac,from) = qu.top(); qu.pop();
        if(dist[f][from] == ac) for(P it: G[f][from]){
            tie(cost, to) = it; cost += ac;
            if(dist[f][to] > cost) qu.push(P(dist[f][to] = cost, to));
        }
    }
}
int main(){
    scanf("%d%d%d%d", &n, &m, s, s+1);
    s[0]--; s[1]--;
    rep(i,m){
        scanf("%d%d%d%d", &u, &v, a, a+1);
        u--; v--;
        rep(j,2){
            G[j][u].push_back(P(a[j],v));
            G[j][v].push_back(P(a[j],u));
        }
    }
    rep(i,2) dijkstra(s[i],i);
    for(int i = n-1; i >= 0; i--) ans[i] = max(ans[i+1], INF - dist[0][i] - dist[1][i]);
    rep(i,n) printf("%lld\n", ans[i]);
}


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

int main()
{
	char in[1001];
	char xyz[2][4] = {"XYZ","ABC"};
	bool ed;

	scanf("%s",in);

	for(int i = 0; i < strlen(in); i++){
		ed = true;
		for(int j = 0; j < 3; j++){
			if(in[i] == xyz[1][j]){
				in[i] = xyz[0][j];
				ed = false;
			}
		}
		if(ed){
			in[i] -= 3;
		}
	}

	printf("%s\n",in);

	return 0;
}

Measured memory_bytes: 944
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<30;
const int MOD=1000000007;
const double EPS=1e-8;

int n,a,b;
vi hp;

signed main(){
    io();
    in(n,a,b);
    hp.resize(n);
    rep(i,n) in(hp[i]);

    int ok=INF,ng=0;
    a-=b;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        int need=0;
        for(auto e:hp){
            need+=(max(e-b*mid,0LL)+(a-1))/a;
            if(need > mid) break;
        }
        show(ok,ng,mid,need);
        if(need<=mid) ok=mid;
        else ng=mid;
    }
    out(ok);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

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

int h,w,n;
ll ans;
vvb field;

void bfs(){
	queue<P> que;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		if(p==P(h-1,w-1)){
			ans++;
			continue;
		}
		for(int i=0;i<2;i++){
			int cx=p.first+dx[i],cy=p.second+dy[i];
			if(cx>=0&&cx<h&&cy>=0&&cy<w&&!field[cx][cy]) que.push(P(cx,cy));
		}
	}
}

int main(){
	while(1){
		cin>>h>>w;
		if(!h&&!w) break;
		ans=0;
		field=vvb(h,vb(w));
		cin>>n;
		int x,y;
		for(int i=0;i<n;i++){
			cin>>x>>y;
			field[x-1][y-1]=1;
		}
		bfs();
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9208
#include<iostream>
#include<string>
#include <bitset>
#include <fstream>
#include<string.h>
using namespace std;

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 0;
  return 3;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < ::strlen(str); i++ ){
	  sum *= 4;
    sum += getChar(str[i]);
  }
  return sum;
}
	std::bitset<16*1024*1024> flg;

int main(){
	int n;
	std::istream & c_in = cin;
	string s;
	getline(c_in,s);
	sscanf(s.c_str(),"%d",&n);

	for(int i=0;i<n;++i){
		getline(c_in,s);

		int value;
		if (s[0] == 'i') {				//"insert x"
			sscanf(&(s[6]),"%d",&value);
			flg.set(::getKey(&(s[6])));
		} else //{						//find x
			if (flg.test(::getKey(&(s[4]))))
				printf("yes\n");
			else 
				printf("no\n");
	}
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  bool ok = 0;
  set<string> appear;
  vector<string> vs(n);
  vector<int> vt(n);
  for (int i = 0; i < n; ++i)
    cin >> vs[i] >> vt[i];
  string x;
  cin >> x;
  for (int i = 0; i < n; ++i) {
    if (ok)
      ans += vt[i];
    ok |= vs[i] == x;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N, C;
ll d[35][35];
map<int, ll> mp0;
map<int, ll> mp1;
map<int, ll> mp2;

int main () {
  cin >> N >> C;
  rep(i, C) {
    rep(j, C) {
      cin >> d[i][j];
    }
  }

  rep(i, N) {
    rep(j, N) {
      int tmp;
      cin >> tmp;

      int k = (i + j) % 3;
      if (k == 0) {
        mp0[tmp]++; 
      } else if (k == 1) {
        mp1[tmp]++;
      } else {
        mp2[tmp]++;
      }
    }
  }

  ll ans = INFLL;

  for (int i=1;i<=C;++i) {
    for (int j=1;j<=C;++j) {
      if (i == j) continue;

      for (int k=1;k<=C;++k) {
        if (i == k) continue;
        if (j == k) continue;

        ll tmp = 0;

        rep(c, 30) {
          tmp += d[c][i] * mp0[c];
        }
        rep(c, 30) {
          tmp += d[c][j] * mp1[c];
        }
        rep(c, 30) {
          tmp += d[c][k] * mp2[c];
        }

        ans = min(ans, tmp);
      }
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 764
// Problem : E - Papple Sort
// Contest : AtCoder Regular Contest 088
// URL : https://atcoder.jp/contests/arc088/tasks/arc088_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include "bits/stdc++.h"
#define size(x) (int)x.size()
using ll = long long;
using namespace std;

const int N = 2e5 + 1, mod = 1e9 + 7;

string s;
int t[N];
ll inv = 0;
vector<int> v[26], ans[26];

struct pair_list {
	int l, r;
	bool operator < (const pair_list &o) const {
		return l < o.l;
	}
} p[N];

struct BIT {
	
	int bit[N];
	
	void update(int k, int x) {
		while (k < N) {
			bit[k] += x;
			k += k & -k;
		}
	}
	
	int query(int k) {
		int ans = 0;
		while (k >= 1) {
			ans += bit[k];
			k -= k & -k;
		}
		return ans;
	}
	 
} tree;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> s;
	for (int i = 0; i < size(s); i++) {
		v[int(s[i] - 'a')].push_back(i);
	}
	int odd = 0, opo = 0, n = 0;
	for (int i = 0; i < 26; i++) {
		if (size(v[i]) & 1) {
			odd++;
			opo = i;
		}
		for (int j = 0; j < size(v[i]) / 2; j++) {
			p[++n] = {v[i][j], v[i][size(v[i]) - j - 1]};
		}
	}
	if (odd > 1) {
		return cout << -1, 0;
	}
	sort(p + 1, p + n + 1);
	for (int i = 1; i <= n; i++) {
		t[i] = s[p[i].l] - 'a';
	}
	if (odd == 1) {
		t[++n] = opo;
	}
	for (int i = n + 1; i <= size(s); i++) {
		t[i] = t[size(s) - i + 1];
		n++;
	}
	for (int i = 1; i <= n; i++) {
		ans[t[i]].push_back(i);
	}
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < size(v[i]); j++) {
			t[v[i][j] + 1] = ans[i][j];
		}
	}
	for (int i = n; i >= 1; i--) {
		inv += tree.query(t[i]);
		tree.update(t[i], 1);
	}
	cout << inv;
}

Measured memory_bytes: 5388
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);++i)
#define pb(x) push_back(x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int n,m,k;
bool vs[12]={0};
vector<string> v;
string s;
void dfs(int u,char c){
	if(u==n) {
		v.push_back(s);
		return;
	}
	if(vs[u]) {
		dfs(u+1,c);
		return;
	}
	int cnt=0;
	int y[11];
	fo(i,u+1,n-1) {
		if(!vs[i]) {
			y[cnt++]=i;
		}
	}
	int w=(1<<cnt)-1;
	s[u]=c;
	vs[u]=1;
	fo(i,0,w){
		fo(j,0,cnt-1){
			if((i>>j)&1){
				vs[y[j]]=1;
				s[y[j]]=c;
			}
		}
		dfs(u+1,c+1);
		fo(j,0,cnt-1)
			vs[y[j]]=0;
	}
}
int main() {
	cin>>n;
	fo(i,1,n) s+='a';
	dfs(0,'a');
	sort(ALL(v));
	for(string ss:v)
		cout<<ss<<endl;
	return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int cnt = 0;
ll g, A, B, C;
const int MAX = 15001000;
bool IsPrime[MAX];
int MinFactor[MAX];


ll GCD(ll a, ll b){
    if(b==0) return a;

    return GCD(b, a % b);
}

map<int, int> factorize(ll n)// 素因数分解
{
	map<int, int> ret;
	for(ll i = 2; i*i <= n; ++i)
	{
        if(n % i != 0) continue;

		while(n % i == 0){
			ret[i]++;
			n /= i;
		}
	}
	if(n != 1) ret[n]++;
	
	return ret;
}

void solve(){
    g = GCD(A, B);

    map<int, int> mp = factorize(g);

    for(auto itr = mp.begin(); itr != mp.end(); ++itr)
        cnt++;
    cnt++;

    cout << cnt << endl;
}

int main(){
    cin >> A >> B;

    solve();
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001

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

    ll n, h, w;
    cin >> n >> h >> w;
    ll r = n - h + 1;
    ll c = n - w + 1;
    cout << r * c << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(ceil(1.0*c/b)<=ceil(1.0*a/d))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3648
use std::io::stdin;
use std::io::BufRead;

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let mut buf = String::new();

        stdin.read_line(&mut buf).unwrap();

        let mut buf = buf.trim().split(" ");

        let h = buf.next().unwrap().parse::<i64>().unwrap();
        let w = buf.next().unwrap().parse::<i64>().unwrap();

        if h == 0 && w == 0 { break; }

        for i in 0..h {
            for j in 0..w {
                if (i + j) % 2 == 0 {
                    print!("#");
                } else {
                    print!(".");
                }
            }
            println!();
        }
        println!();
    }
}


Measured memory_bytes: 5028
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

#include <tuple>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

int N;
string S;
VI nxt[26];

const int INF = 1000000;
#define MAXN 200004
int memo[MAXN];
II path[MAXN];
int go(int n) {
   if (n > N) return 0;
   int& res = memo[n];
   if (res < 0) {
      res = INF;
      REP(k, 26) {
         int j = upper_bound(nxt[k].begin(), nxt[k].end(), n) - nxt[k].begin();
         //if (n == 0)
         //   cerr << k << " " <<  j << " " << endl;
         int cur = go( nxt[k][j] ) + 1;
         if (res > cur) {
            res = cur;
            path[n] = II(k, nxt[k][j]);
         }
      }
   }
   return res;
}

string solve() {
   N = SZ(S);
   REP(i, N)
      nxt[ S[i]-'a' ].push_back(i+1);
   REP(k, 26)
      nxt[k].push_back(N+1);

   memset(memo, -1, sizeof(memo));
   int len = go(0);
//   cerr << len << endl;

   string res;
   for (int l = 0, n = 0; l < len; ++l) {
      int k, nn;
      tie(k, nn) = path[n];
      res += 'a' + k;
      n = nn;
   }

   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   cin >> S;

   string res = solve();
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 4116
def getLastMatch(s,t):
    for i in range(len(s)-len(t), -1, -1):
        if s[i] == '?' or s[i] == t[0]:
            match = True
            for j in range(len(t)):
                if s[i+j] == '?': continue
                if s[i+j] != t[j]:
                    match = False
                    break
            if match: return i
    return -1

def getS(s,t,lastMatch):
    s = list(s)
    for i in range(len(t)):
        s[i+lastMatch] = t[i]
    for i in range(len(s)):
        if s[i]=='?': s[i] = 'a'
    res = ''
    for c in s: res+=c
    return res


s,t = input(), input()
lastMatch = getLastMatch(s,t)
if lastMatch == -1:
    print('UNRESTORABLE')
else:
    print(getS(s,t,lastMatch))



Measured memory_bytes: 3064
#include<iostream>
#include<cstring>

using namespace std;

typedef pair<int,int> P;
const int MAX = 16;
bool Mata[MAX][MAX][MAX][MAX];
P g;
int maze[MAX][MAX];

void init(){
  memset(Mata,false,sizeof(Mata));
}

void solve(){
  
  memset(maze,0,sizeof(maze));
  maze[0][0] = 1;


  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++){
      if(i-1 >= 0 && !Mata[i-1][j][i][j]) maze[i][j] += maze[i-1][j];
      if(j-1 >= 0 && !Mata[i][j-1][i][j]) maze[i][j] += maze[i][j-1];
    }
 
}

int main(){
  int N;
  cin >> N;
  while(N--){
    init();
    cin >> g.first >> g.second;
    int num;
    cin >> num;
    while(num--){
      P f,t;
      cin >> f.first >> f.second >> t.first >> t.second;
      Mata[f.first][f.second][t.first][t.second] = true;
      Mata[t.first][t.second][f.first][f.second] = true;
    }
    solve();
    if(maze[g.first][g.second]) cout << maze[g.first][g.second] << endl;
    else cout << "Miserable Hokusai!" << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

inline int dis(char b){
    return (26-(int(b)-int('a')))%26;
}

int main(){
    
    string s;
    ll k;
    cin >> s;
    cin >> k;
    
    rep(i,s.size()){
        char tmp = s[i];
        int d = dis(s[i]);
        if(d<=k)s[i]='a',k-=d;
    }
    if(k>0)s[s.size()-1]=(char)(97+((int)s[s.size()-1]-97+k)%26);
    
    cout << s<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define REP(i,a,b) for(register int i=(a); i<(b); i++)
#define REPE(i,a,b) for(register int i=(a); i<=(b); i++)
using namespace std;
typedef long long ll;
char buf[1<<21], *p1=buf, *p2=buf;
//#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> inline void read(T&x) {
	x=0; char ch; do ch=getchar(); while(ch<=' ');
	while(ch>' ') {x=x*10+ch-'0'; ch=getchar();}
}
#define MAXN 107
char s[MAXN];
int main() {
	scanf("%s", s);
	int l=strlen(s);
	while(0<l--) putchar('x');
	putchar('\n');

}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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()
{
    int q;
    cin >> q;
    bitset<100010> a(0);
    for (int i = 2; i < 100010; i++)
    {
        a.set(i);
    }
    for (int i = 2; i < 100010; i++)
    {
        if (a[i])
        {
            for (int j = i * 2; j < 100010; j += i)
            {
                a.reset(j);
            }
        }
    }
    vector<long long> ruiseki(100011);
    for (int i = 0; i < 100010; i++)
    {
        ruiseki[i + 1] = ruiseki[i];
        if (a[i] && a[(i + 1) / 2])
        {
            ruiseki[i + 1]++;
        }
    }
    int l, r;
    for (int i = 0; i < q; i++)
    {
        cin >> l >> r;
        cout << ruiseki[r + 1] - ruiseki[l] << endl;
    }
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n, k;
mi mp;
void in(){
    cin >> n >> k;
    rep(i,0,n) mp[input()]++;
}

void solve(){

    vi arr;
    for(auto e : mp){
        arr.push_back(e.second);
    }

    sort(all(arr));

    int ans = 0;
    rep(i,0,sz(arr) - k) ans += arr[i];
    print(ans);


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 14964
/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on July 27, 2018, 12:04 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAX 250

/*
 * 
 */

int parent(int i) { return i/2; }
int left(int i) { return 2*i; }
int right(int i) { return 2*i+1; }

int main(int argc, char** argv) {
    int H, T[MAX+1];
    scanf("%d", &H);
    
    for (int i = 1; i <= H; ++i) scanf("%d", &T[i]);
    for (int i = 1; i <= H; ++i) 
    {
        printf("node %d: key = %d, ", i, T[i]);
        if (parent(i) >= 1) printf("parent key = %d, ", T[parent(i)]);
        if (left(i) <= H) printf("left key = %d, ", T[left(i)]);
        if (right(i) <= H) printf("right key = %d, ", T[right(i)]);
        printf("\n");    
    }
    return (EXIT_SUCCESS);
}







Measured memory_bytes: 2112
#include<stdio.h>
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	int t;
	if(a>b)t=a,a=b,b=t;
	if(b>c)t=b,b=c,c=t;
	if(a>b)t=a,a=b,b=t;
	printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000000
using namespace std;
using ll=long long;
using ld=long double;
using vs=vector<string>;


int main() {
    int x;
    cin>>x;
    if(x>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }
    Scoring scoring(D, costs, incentives);
    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        types[day-1] = 1;
    }
    const auto score = scoring.score(types);
    for (long day = 1; day <= D; ++day) {
        std::cout << 1 << std::endl;
    }
    //std::vector<long> types(D);
    //for (long day = 1; day <= D; ++day) {
    //    std::cin >> types[day-1];
    //}

    //long M;
    //std::cin >> M;

    //std::vector<std::array<long,2>> query(M);
    //for (long index = 0; index < M; ++index) {
    //    std::cin >> query[index][0];
    //    std::cin >> query[index][1];
    //}

    //Scoring scoring(D, costs, incentives);
    //for (long index = 0; index < M; ++index) {
    //    types[query[index][0]-1] = query[index][1];
    //    std::cout << scoring.score(types).back() << std::endl;
    //}
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>

using namespace std;

char opposite_animal(char a)
{
	return a == 'S' ? 'W' : 'S';
}

char next_animal(char a0, char a1, char s1)
{
	if (a1 == 'S') {
		if (s1 == 'o') {
			return a0;
		}
		else {
			return opposite_animal(a0);
		}
	}
	else {
		if (s1 == 'o') {
			return opposite_animal(a0);
		}
		else {
			return a0;
		}
	}
}

string solve(int N, const string &s, string t)
{
	for (int i = 1; i + 1 < N; ++i) {
		t += next_animal(t[i - 1], t[i], s[i]);
	}
	if (next_animal(t[N - 2], t[N - 1], s[N - 1]) != t[0]) {
		return "";
	}
	else if (next_animal(t[N - 1], t[0], s[0]) != t[1]) {
		return "";
	}
	else {
		return t;
	}
}

int main()
{
	int N;
	string s;
	cin >> N >> s;
	
	string ans;
	for (const auto &t : { "SS", "SW", "WS", "WW" }) {
		ans = solve(N, s, t);
		if (!ans.empty()) {
			break;
		}
	}
	if (ans.empty()) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
}


Measured memory_bytes: 640
fun main() {
    val x = readLine()!!.toLong()

    for(a in 0..150) {
        var A = 1L
        repeat(5){
            A *= a.toLong()
        }
        for(b in 0..150) {
            var B = 1L
            repeat(5) {
                B *= b.toLong()
            }
            if(A - B == x ) {
                print("$a $b")
                return
            } else if(A + B == x) {
                print("$a -$b")
                return
            }
        }

    }


}

Measured memory_bytes: 34560
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;


#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=200005;
const int k=50;
struct matrix
{
    int m[k][k];
    matrix()
    {
        memset(m,0,sizeof(m));
    }
} M,I;
matrix matmul(matrix a,matrix b)
{
    matrix x;
    for(int i=0;i<k;i++)
    {
        for(int j=0;j<k;j++)
        {
            for(int l=0;l<k;l++)
            {
                x.m[i][j]=(x.m[i][j]%hell+(a.m[i][l]%hell*b.m[l][j]%hell)%hell)%hell;
            }
        }
    }
    return x;
}
matrix matexpo(int n)
{
    if(n==0)
    {
        return I;
    }
    matrix F;
    F=matexpo(n/2);
    F=matmul(F,F);
    if(n%2)
        F=matmul(F,M);
    return F;
}
matrix ADD(matrix M1,matrix M2)
{
    matrix M3;
    for(int r=0;r<2;r++)
        for(int c=0;c<2;c++)
        {
            M3.m[r][c]=(M1.m[r][c]%hell+M2.m[r][c]%hell)%hell;
        }
    return M3;
}


void solve()
{
    int n,K;
    cin>>n>>K;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin>>M.m[i][j];
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(i==j)
                I.m[i][j]=1;
    matrix path=matexpo(K);
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            ans=(ans+path.m[i][j])%hell;
        }
    cout<<ans<<endl;
    
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>


using namespace std;

#include <iostream>
#include <string>
#include <vector>


using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main2() {
    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; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}


int main() {

    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    string eraser = "eraser";
    string erase = "erase";
    string dreamer = "dreamer";
    string dream = "dream";

    reverse(eraser.begin(), eraser.end());
    reverse(erase.begin(), erase.end());
    reverse(dreamer.begin(), dreamer.end());
    reverse(dream.begin(), dream.end());

    do {

        int flg = false;

        if (S.substr(0, eraser.size()) == eraser) {
            flg = true;
            S = S.substr(eraser.size(), S.size() - eraser.size());
        }

        if (S.substr(0, erase.size()) == erase) {
            flg = true;
            S = S.substr(erase.size(), S.size() - erase.size());
        }

        if (S.substr(0, dreamer.size()) == dreamer) {
            flg = true;
            S = S.substr(dreamer.size(), S.size() - dreamer.size());
        }

        if (S.substr(0, dream.size()) == dream) {
            flg = true;
            S = S.substr(dream.size(), S.size() - dream.size());
        }


        // 全部見つからないとbreak
        if (flg == false) {
            break;
        }

    } while (true);


    if (S == "") {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;

    }
}



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

#define NIL -1

struct Node{ int p, l, r; };

Node tree[10000];
int n;

void preParse(int id){
    if(id == NIL) return;
    cout << " " << id;
    preParse(tree[id].l);
    preParse(tree[id].r);
}
void inParse(int id){
    if(id == NIL) return;
    inParse(tree[id].l);
    cout << " " << id;
    inParse(tree[id].r);
}
void postParse(int id){
    if(id == NIL) return;
    postParse(tree[id].l);
    postParse(tree[id].r);
    cout << " " << id;
}

int main(){
    int v, l, r, root = 0;
    cin >> n;

    for(int i=0; i<n; i++) tree[i].p = NIL;

    for(int i=0; i<n; i++){
        cin >> v >> l >> r;
        tree[v].l = l;
        tree[v].r = r;
        if(l != NIL) tree[l].p = v;
        if(r != NIL) tree[r].p = v;
    }

    for(int i=0; i<n; i++){
        if(tree[i].p == NIL) root = i;
    }

    cout << "Preorder" << endl;
    preParse(root);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;

    return 0;
}


Measured memory_bytes: 3092
def comb(n, k, MOD):
    if n < k:
        return 0
    if n - k < k:
        k = n - k
    comb = 1
    for x in range(n - k + 1, n + 1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k + 1):
        d = (d * x) % MOD
    comb *= pow(d, MOD - 2, MOD)
    return comb % MOD

n, k = map(int, input().split())
ans = 0
v = n
w = n - 1

ans = 1 + v * w
mod = 10 ** 9 + 7

for i in range(2, min(n,k) + 1):
    #print(f'v={v} n={n} i={i}')
    v = ((n - i + 1) * v)  * pow(i, mod - 2, mod)
    v %= mod
    w = ((n - i) * w) * pow(i, mod - 2, mod)
    w %= mod
    #print(v, w)
    ans += (v * w) % mod
    ans %= mod



print(ans)

Measured memory_bytes: 40556
N, M = map(int,input().split())
S = list(input())
S.reverse()
p = 0
ans = []
while p != N:
    hoge = 0
    for i in range(min(M,N-p),0,-1):
        if S[p + i] == '0':
            hoge = i
            break
    p += hoge
    if hoge == 0:
        print(-1)
        exit()
    ans.append(hoge)
print(*reversed(ans))

Measured memory_bytes: 52472
#include<stdio.h>

int main()
{
	int a,b,c,d,n,k=0;
	
	while(scanf("%d",&n) !=EOF){
		for(a=0;a<=9;a++){
			for(b=0;b<=9;b++){
				for(c=0;c<=9;c++){
					for(d=0;d<=9;d++){
						if(a+b+c+d==n)k+=1;
					}
				}
			}
		}	
	printf("%d\n",k);
	k=0;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
main () {
	string s, t;
	cin>>s>>t;
	int kerja = 0;
	for (int i=0;i<s.length();i++) {
		if (s[i] != t[i]) {
			kerja++;
		}
	}
	cout<<kerja<<endl;
}

Measured memory_bytes: 3816
/*  ex4_2
    person_A  */
#include<stdio.h>
#include<math.h>

int main(void){
    const double pi=3.14159265359;
    double lengthA,lengthB,angleA_B;
    int hours,minutes;
    //lengthA,lengthB,hours,minutesの値の入力
    scanf("%lf%lf%d%d",&lengthA,&lengthB,&hours,&minutes);
    //以下時針と分針の間の角度を取得
    angleA_B=((double)((11*(hours*60+minutes))%720)/360)*pi;
    //余弦定理を逆算して答えの出力
    printf("%.10f\n",sqrt(lengthA*lengthA+lengthB*lengthB-2*lengthA*lengthB*cos(angleA_B)));
    return 0;
}

Measured memory_bytes: 2552
//65 - A 90 - Z 97 - a 122 - z
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int INF = 1e9 + 7;

LL res;
int t[307][307], n, tt[307][307];
bool odw[307];

void aktu(int x)
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(tt[i][x] + tt[x][j] < tt[i][j])
            {
                tt[i][j] = tt[i][x] + tt[x][j];
                tt[j][i] = tt[i][x] + tt[x][j];
            }
        }
    }
}

bool check()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                if(t[i][k] + t[k][j] < t[i][j]) return false;
            }
        }
    }
    return true;
}


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

    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> t[i][j];
    if(!check())
    {
        puts("-1");
        return 0;
    }
    priority_queue<pair<int, pair<int, int>>> q;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
            if(i != j) q.push({-t[i][j], {i, j}});
    }
    int dif = (n * n) - n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            if(i == j) tt[i][j] = 0;
            else tt[i][j] = INF;
    while(!q.empty())
    {
        auto x = q.top();
        q.pop();
        int a = x.second.first, b = x.second.second, c = -x.first;
        //cout << a << " " << b << endl;
        if(tt[a][b] > c)
        {
            tt[a][b] = c, tt[b][a] = c;
            aktu(a);
            aktu(b);
            dif -= 2;
            res += c;
        }
        /*for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
                cout << tt[i][j] << " ";
            cout << endl;
        }*/
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1656
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[list(map(int,input().split())) for i in range(Q)]
from collections import Counter
x=Counter(A)
s=sum([k*v for k,v in x.items()])
for b,c in BC:
    if b in x:
        s+=(c-b)*x[b]
        if c in x:
            x[c]+=x[b]
        else:
            x[c]=x[b]
        del x[b]
    print(s)

Measured memory_bytes: 37672