akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>

using namespace std;
using ld = long double;

struct Graph {
    Graph(const int n)
    {
        edge.resize(n);
    }
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
    }
    vector<vector<int>> edge;
};


int main()
{
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        Graph g(N);
        vector<ld> p(N, 0);
        for (int i = 0; i < N; i++) {
            cin >> p[i];
            int M;
            cin >> M;
            for (int j = 0; j < M; j++) {
                int from;
                cin >> from;
                from--;
                g.addEdge(i, from);
            }
        }

        vector<vector<bool>> reachable(N, vector<bool>(N, false));
        for (int i = 0; i < N; i++) {
            queue<int> q;
            vector<bool> used(N, false);
            q.push(i);
            used[i] = true;
            reachable[i][i] = true;
            while (not q.empty()) {
                const int s = q.front();
                q.pop();
                for (int to : g.edge[s]) {
                    reachable[i][to] = true;
                    if (used[to]) {
                        continue;
                    }
                    used[to] = true;
                    q.push(to);
                }
            }
        }

        vector<int> number(N);
        for (int i = 0; i < N; i++) {
            number[i] = i;
        }
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (reachable[i][j] and reachable[j][i]) {
                    number[j] = number[i];
                }
            }
        }
        vector<ld> prob(N, -1);
        for (int i = 0; i < N; i++) {
            prob[number[i]] = (prob[number[i]] == -1) ? p[i] : prob[number[i]] * p[i];
        }

        vector<int> indim(N, 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) {
                    continue;
                }
                if (reachable[i][j] and number[i] != number[j]) {
                    indim[number[j]]++;
                }
            }
        }
        ld ans = 1;
        for (int i = 0; i < N; i++) {
            if (indim[i] == 0 and prob[i] != -1) {
                ans *= (1 - prob[i]);
            }
        }
        cout << fixed << setprecision(10) << ans << endl;
    }


    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i=0;i<n;i++) {
    cin >> vec.at(i);
  }
  
  vector<int> log;
  
  for (int i=0;i<n;i++) {
    if(vec.at(i) % 2 == 0) {
      log.push_back(vec.at(i));
    }
  }
  
  int c = 0;
  
  for (int j=0;j<log.size();j++) {
    if(log.at(j) % 3 == 0 || log.at(j) % 5 == 0) {
      c++;
    }
  }
  
    if(c == log.size()) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[1000005];
int fun(int x)
{
    int l=1;
    while(x)
    {
        l*=10;
        x/=10;
    }
    return l;
}
int main()
{
    int n,ans=1;
    int p=7;
    cin>>n;
    while(n>p)
    {
        ans++;
        p*=10;
        p+=7;
    }
    while(p)
    {
        if(n<=p)
        p-=n;
        else
        {
        if(!a[p])
        {
            a[p]=1;
            ans++;
            p*=10;
            p+=7;
        }
        else
        {
            cout<<-1;
            return 0;
        }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 7456
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ull = unsigned long long;

int main(){
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy\n";
    }else if(s=="Cloudy"){
        cout<<"Rainy\n";
    }else {
        cout<<"Sunny\n";
    }
    return 0;
}


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

int main(void){
  int n, i = 2;

  scanf("%d", &n);
  printf("%d:", n);
  while(n != 1){
    if(n % i == 0){
      n /= i;
      printf(" %d", i);
    }else if(i > sqrt(n)){
      printf(" %d", n);
      break;
    }else{
      i++;
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(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--)
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = (1 << 30);
const int MOD = 1000000007;
int n, k, ans = 0, h, w, sum = 0,a,b,c,d,takahasi,aoki;
int main() {
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;

    rep(i, 0, (int)s.size()) {
        if (s[i] != '1') {
            if (k < i + 1) {
                cout << '1' << endl;
                return 0;
            } else {
                cout << s[i] << endl;
                return 0;
            }
        }
    }

    cout << '1' << endl;
    return 0;

}


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

ll n;

bool is(string s) {
	// is 753?
	bool a[3]={};
	rep(i, (int)s.size()) {
		if (s[i]=='7') {
			a[0]=1;
		} else if (s[i]=='5') {
			a[1]=1;
		} else if (s[i]=='3') {
			a[2]=1;
		} else {
			return false;
		}
	}
	if (a[0]&&a[1]&&a[2]) {
		return true;
	}
	return false;

}

ll solve(string s) {
	if (stol(s) > n) {
		return 0;
	}

	ll cnt=0; 
	if (is(s)) {
		//cout << s << endl;
		cnt++;
	}

	cnt += solve(s+"7");
	cnt += solve(s+"5");
	cnt += solve(s+"3");

	return cnt;
}

int main() {
	cin >> n;
	ll ans = solve("7") + solve("5") + solve("3");
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
row1 = list(map(int,input().split()))
row2 = list(map(int,input().split()))
row3 = list(map(int,input().split()))
n = int(input())
arr = []
for i in range(n):
    temp = int(input())
    arr.append(temp)
if row1[0] in arr and row1[1] in arr and row1[2] in arr or row2[0] in arr and row2[1] in arr and row2[2] in arr or row3[0] in arr and row3[1] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[0] in arr and row3[0] in arr or row1[1] in arr and row2[1] in arr and row3[1] in arr or row1[2] in arr and row2[2] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[1] in arr and row3[2] in arr or row1[2] in arr and row2[1] in arr and row3[0] in arr:
    print("Yes")
    exit()
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
#include <iomanip>
using namespace std;
const long long mod=1e9+7;
#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,x,n) for(int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k; 
ll INF = 10000000000000000;
const double PI=3.14159265358979323846;



int main(){
    int N,M;
    cin >>N>>M;
    vector<set<int>> path(N);
    rep(i,M){
        int A,B;
        cin >>A>>B;
        A--;
        B--;
        path[A].insert(B);
        path[B].insert(A);
    }
    vi thr(N,0),ans(N,-1);
    thr[0]=1;
    stack<int> l,ll;
    l.push(0);
    while(!l.empty()){
        int s = l.top();
        l.pop();
        for(auto v:path[s]){
            if(thr[v]==1) continue;
            thr[v]=1;
            ans[v]=s;
            ll.push(v);
        }
        if(l.empty()){
            if(ll.empty()) break;
            l=ll;
            while(!ll.empty()) ll.pop();
        }
    }
    rep1(i,N){
        if(ans[i]!=-1) continue;
        cout << "No"<<endl;
        return 0;
    }
    cout <<"Yes"<<endl;
    rep1(i,N){
        cout << ans[i]+1<<endl;
    }
}

Measured memory_bytes: 28128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main() {
    ll N;
    cin >> N;

    ll A[N];
    for(ll i=0; i<N; i++) cin >> A[i];

    multiset<ll> S;
    S.insert(A[N-1]);
    ll cnt = 1;

    for(ll i=N-2; i>=0; i--) {
        auto it = S.upper_bound(A[i]);
        if(it == S.end()) {
            S.insert(A[i]);
            cnt++;
        } else {
            S.erase(it);
            S.insert(A[i]);
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 5760
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

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

//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,d,ans=0;
		cin>>n>>d;
		vector<ll>a(d,0);
		vector<vi>v;
		rep(i,0,n)
		v.pb(a);
		rep(i,0,n)
		{
			rep(j,0,d)
			cin>>v[i][j];
		}
		rep(i,0,n)
		{
			rep(j,i+1,n)
			{
				ll k=0;
				rep(q,0,d)
				{
					k+=(v[i][q]-v[j][q])*(v[i][q]-v[j][q]);
				}
				ll sq=sqrt(k);
				if(sq*sq==k)
					ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    ans = sum(B)-sum(A)
    add1 = 0
    add2 = 0
    for a, b in zip(A, B):
        if a > b:
            add1 += a - b
        elif a < b:
            add2 += (b - a + 1) // 2
        else:
            pass

    if add1 <= ans and add2 <= ans:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    while(cin >> n, n){
        vi fac;
        for(int i = 1; i * i <= n; i++)if(n % i == 0){
            fac.push_back(i);
            if(i*i < n)fac.push_back(n/i);
        }
        vector<pii> ans;
        rep(i,fac.size()){
            int num = fac[i];//項数
            int t = n / fac[i] * 2;//初項+末項
            /*
            末項 + 初項 = t
            末項 - 初項 = num - 1
            を解くと
            2 * 末項 = t + num - 1
            2 * 初項 = t - (num - 1)
            */
            if((t + num - 1)%2 == 0 && t - num + 1 >= 1){
                ans.push_back(pii(num, (t - num + 1)/2));
            }
            num *= 2;
            t /= 2;
            if((t + num - 1)%2 == 0 && t - num + 1 >= 1){
                ans.push_back(pii(num, (t - num + 1)/2));
            }
        }

        sort(all(ans));
        cout << ans.back().second << " " << ans.back().first << endl;
    }
}



Measured memory_bytes: 3152
N = int(input())
A = list(map(int, input().split()))
S = [0] * N
S[0] = A[0]
for i in range(1, N):
    S[i] = S[i - 1] + A[i]

num = float("inf")
a = 0
b = 2
for i in range(1, N - 2):
    while S[a] < S[i] - S[a + 1]:
        a += 1
    b = max(b, i + 1)
    while S[b] - S[i] < S[N - 1] - S[b + 1]:
        b += 1

    P = [S[a], S[i] - S[a], S[b] - S[i], S[N - 1] - S[b]]
    num = min(num, abs(max(P) - min(P)))

print(num)

Measured memory_bytes: 25064
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl;
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl;
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl;
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl;
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl;
#define pb push_back
#define pf push_front
#define oo (ll)1e18
#define inf (int)1e10
#define ll long long 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
typedef tuple<ll,ll,ll> tl3;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
const int MAXN = 305;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}

//#define cerr if(0)cout


ll A[300005];

ll ans;
int main() {
    IAMSPEED
	int n; cin >> n;
	FOR(i,1,n) {
		cin >> A[i];
	}
	FOR(i,0,60) {
		ll c = 0;
		FOR(j,1,n) {
			if ((1ll << i) & A[j]) {
				++c;
			}
		}
		ll t = c*(n-c);
		t%=MOD;
		t *= ((1ll<<i) % MOD);
		t%=MOD;
		ans += t;
		ans %= MOD;
	}
	cout << ans;
			
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;
int c[10001],s;

int main()
{
    int n;
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>c[i];
    for (int i=1; i<=n; i+=2)
        if (c[i]%2==1)
            s++;
    cout<<s;
    return 0;
}

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

int	main() {
	int N, K;
	cin >>N >>K;
	vector<long> x(N);
	for (int i=0; i<N; i++) cin >> x.at(i);
	long S=(abs(x.at(0))+abs(x.at(N-1)))*2;
	int i=K-1;
	while (i<N) {
		long x0=x.at(i-K+1);
		long x1=x.at(i);
		if (x0*x1>=0) {
			S=min(S, max(abs(x0), abs(x1)));
		} else {
			S=min(S, x1-x0+min(x1, -x0));
		}
		i++;
	}
	cout <<S <<endl;
	return 0;
}



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

const int p=200003;

using cd = complex<double>;
const double PI=acos(-1);

void fft(vector<cd> & a, bool invert){
	int n=a.size();
	for(int i=1, j=0; i<n; i++){
		int bit=n>>1;
		for(; j&bit; bit>>=1)
			j ^=bit;
		j^=bit;
		if(i<j)
			swap(a[i], a[j]);
	}
	for(int len=2; len<=n; len <<=1){
		double ang=2*PI/len*(invert ? -1 : 1);
		cd wlen(cos(ang), sin(ang));
		for(int i=0; i<n; i+=len){
			cd w(1);
			for(int j=0; j<len/2; j++){
				cd u=a[i+j], v=a[i+j+len/2]*w;
				a[i+j]=u+v;
				a[i+j+len/2]=u-v;
				w*=wlen;
			}
		}
	}
	if(invert){
		for(cd & x : a)
			x /= n;
	}
}
 
vector<int> multiply(vector<int>const& a, vector<int>const& b){
	vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
	int n=1;
	while(n<a.size()+b.size())
		n <<= 1;
	fa.resize(n);
	fb.resize(n);
	fft(fa, false);
	fft(fb, false);
	for(int i=0; i<n; i++)
		fa[i] *= fb[i];
	fft(fa, true);
	vector<int>result(n);
	for(int i=0; i<n; i++)
		result[i]=round(fa[i].real());
	return result;
}
int powe[500005];
 main() {
	powe[0]=1;
	for(int i=1; i<500005; i++){
		powe[i]=(2*powe[i-1])%p;
	}
	int n;
	cin>>n;
	int a[n];
	int g=2;
	int val=1;
	int pos[200003];
	int po=0;
	
	for(int i=0; i<p-1; i++){
		pos[val]=po;
		val=(val*g)%p;
		po++;
	}
	int sum=0;
	vector<int>cnt;
	cnt.resize(200002);

	for(int i=0; i<200002; i++){
		cnt[i]=0;
	}
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		if(x==0){
			continue;
		}
		sum+=((x*x)%p);
		cnt[pos[x]]++;
	}
	
	vector<int>ans=multiply(cnt, cnt);
	int s=0;
	for(int i=0; i<2*p-3; i++){
		s+=(ans[i]*powe[i]);
	}

	cout<<(s-sum)/2<<endl;

	return 0;
}

Measured memory_bytes: 31112
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

ll move(ll n){
     ll a[n+10];
     a[0] = 1;
     a[1] = 0;
     a[2] = 0;
     a[3] = 1;

     for(int i=4;i<=n;i++){
          a[i] = (a[i-1]+a[i-3])%MOD;
     }
     return a[n];
}

int main (){
     ll n;     cin >> n;
     ans = move(n);
     cout << ans%MOD << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

ll N;
string s[400];
string t[400];



int main(){
	cin>>N;
	Rep(i,N) cin>>s[i];
	int ans=0;
		Rep(B,N){
			bool f=true;
			string t[400]={};
			Rep(i,N){
				Rep(j,N){
					int ni=i%N;
					int nj=(j+B)%N;
					t[i]+=s[ni][nj];
				}
			}
			
			Rep(i,N){
				Rep(j,N){
					if(t[i][j]!=t[j][i]){
						f= false;
					}
				}
			}
			if(f){
				ans++;
			}
		}
	
	cout<<N*ans<<endl;
	
	  return 0;
  }


Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    string s,t="";
    cin>>s;
    string str[]={"eraser","erase","dreamer","dream"};
    rep(j,4){
        if(s.size()==0)continue;
        for(int i=0;i<s.size();i++) {
            if((int)s.size()-str[j].size()-i>=0&&s.substr(i,str[j].size())==str[j])i+=str[j].size()-1;
            else t+=s[i];
        }
        s=t;
        t="";
        // fin(s);
    }
    
    YN(!s.size());
}



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

int main() {
    int n;
    cin >> n;
    double t[n], v[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    double l_min[n + 1], r_min[n + 1];
    l_min[0] = 0;
    r_min[n] = 0;
    for (int i = 0; i < n; i++) {
        l_min[i + 1] = min(l_min[i] + t[i], v[i]);
        r_min[n - i - 1] = min(r_min[n - i] + t[n - i - 1], v[n - i - 1]);
    }
    double vs[n + 1];
    for (int i = 0; i <= n; i++) {
        vs[i] = min(l_min[i], r_min[i]);
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
        double peek_x = (t[i] - vs[i] + vs[i + 1]) / 2, peek_y = (t[i] + vs[i] + vs[i + 1]) / 2;
        ans += (peek_y + vs[i]) * peek_x + (peek_y + vs[i + 1]) * (t[i] - peek_x);
        double v_t = max(0.0, peek_y - v[i]);
        ans -= v_t * v_t * 2;
    }
    ans /= 2;
    cout << fixed << setprecision(4) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
(n,k),p,c  = [list(map(int, s.split())) for s in open(0)]

pset = set(p)
ans = c[0]
for x in range(1,n+1):
    _sum = [0 for _ in range(2*n)]
    num = 0
    while x in pset:
        pset.remove(x)
        _sum[num + 1] = _sum[num] + c[x-1]
        x = p[x-1]
        num += 1
    if num > 0:
        for i in range(1,num):
            _sum[num + i] += _sum[num] + _sum[i]
        # i == 0
        if k//num > 0:
            tmp = _sum[num] * (k//num)
            if tmp > ans:
                ans = tmp
        for i in range(1, min(k+1,num)):
            base = max(0, _sum[num]) * ((k-i)//num)
            for j in range(num):
                tmp = _sum[j+i] - _sum[j] + base
                if tmp > ans:
                    ans = tmp
print(ans)

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

using namespace std;

typedef long long LL;

const int N = 1010;

int a[N];
int x, y;

int main()
{
    for(int i = 1; i <= 999; i++) a[i] = a[i - 1] + i;
    cin >> x >> y;
    int d = y - x;
    for(int i = 2; i <= 999; i++)
        if(a[i] - a[i - 1] == d)
        {
            cout << a[i] - y << endl;
            return 0;
        }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	ll k,a,b;

	cin >> k;
	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		int tmp = i % k;
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	
	return 0;
}


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

using namespace std;

//#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif


int main() {
    ll N; cin >> N;
    ll sum = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                sum += __gcd(__gcd(i,j),k);
            }
        }
    }
    cout << sum << endl;
}


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

int main(){
  int i,n;
  char s[100001];
  scanf("%s",s);
  n=strlen(s);
  for(i=0;i<n-2;i++){
    if(s[i]==s[i+1]){
      printf("%d %d\n",i+1,i+2);
      return 0;
    }
    else if(s[i]==s[i+2]){
      printf("%d %d\n",i+1,i+3);
      return 0;
    }
  }
  if(s[n-2]==s[n-1]){
    printf("%d %d\n",n-1,n);
    return 0;
  }
  printf("-1 -1\n");
}

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

class UnionFind {
private:
    int* par;
    int* rank;

public:
    UnionFind(int N) {
        par = new int[N];
        rank = new int[N];
        for (int i = 0; i < N; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    };
    ~UnionFind() {
        delete[] par;
        delete[] rank;
    };
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    };
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
        }
    };
    bool same(int x, int y) {
        return find(x) == find(y);
    };
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int* p;
    p = new int[N];
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        --p[i];
    }
    UnionFind UF(N);
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        UF.unite(x - 1, y - 1);
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (UF.same(p[i], i)) {
            ++ans;
        }
    }
    cout << ans << endl;
    delete[] p;

    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll h;
	cin >>h;
	
	int ct = 0;
	for(ll w=h; w>0; w/=2) ct++;
	
	cout << (1LL<<ct) -1 <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
    return is >> v.first >> v.second;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (T& i: v) is >> i;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    int n = (int) v.size();
    for (int i = 0; i < n; ++i) os << v[i] << (i == n - 1 ? "" : " ");
    return os;
}

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T1, typename... T2>
void in(const T1 H, const T2... T) {
    std::cin >> (H); in(T...);
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    int a; in(a);
    std::string s; in(s);
    if (a < 3200) out("red"); else out(s);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;

const int N=3005;

int n,mod,tag,ans,w;
int s[N][N],c[N][N];

void init(int n){
	int i,j;
	s[0][0]=1;
	for (i=1;i<=n;i++)
		for (j=1;j<=i;j++) s[i][j]=(s[i-1][j-1]+1ll*s[i-1][j]*j%mod)%mod;
	c[0][0]=1;
	for (i=1;i<=n;i++){
		c[i][0]=1;
		for (j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
}

int quickpow(int x,int y,int p){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%p)
		if (y&1) s=1ll*s*x%p;
	return s;
}

int main(){
	int i,j;
	scanf("%d%d",&n,&mod);
	init(n+1);
	tag=1; ans=0;
	for (i=0;i<=n;i++){
		w=quickpow(2,quickpow(2,n-i,mod-1),mod);
		for (j=0;j<=i;j++)
			(ans+=1ll*tag*w*quickpow(2,(n-i)*j,mod)%mod*c[n][i]%mod*s[i+1][j+1]%mod)%=mod;
		tag*=-1;
	}
	ans=(ans%mod+mod)%mod; 
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 69504
arr=[0,1,1,2]
n=4*(10**5)+100
for i in range(4,n):
    b=bin(i)[2:]
    k=b.count('1')
    arr.append(arr[i%k]+1)
    #print(b,arr[i])
n=int(input())
z=input()
l=z.count('1')
l1=l+1
l2=l-1
ans1=0
ans2=0
for i in range(n):
    if(z[i]=='1'):
        u=pow(2,n-1-i,l1)
        ans1=(ans1+u)%l1
        if l2>0:
            ans2=(ans2+pow(2,n-1-i,l2))%l2
for i in range(n):
    if z[i]=='0':
        p=ans1+pow(2,n-1-i,l1)
        p%=l1
        print(1+arr[p])
    else:
        if l2==0:
            print(0)
        else:
            p=ans2-pow(2,n-1-i,l2)
            p%=l2
            print(1+arr[p])
       

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

using namespace std;


typedef int32_t h_int32;
typedef int64_t h_int64;
typedef uint32_t uh_int32;
typedef uint64_t uh_int64;
typedef h_int64 h_int;

#define REP( i, n ) for(int i = 0; i < ( int )( n ); ++i )
#define REPR( i, n ) for(int i = ( int )( n ); i >= 0; --i)
#define FOR( i, a, n ) for(int i = ( int )( a ); i < ( int )( n ); ++i )
#define FORR( i, a, n ) for(int i = ( int )( n ); i >= ( int )( a ); --i)

#define VINIT( v, type, n )vector<type> v; v.resize( n );
#define VINIT2( v, type, n, a )vector<type> v; v.resize( n, a );
#define VCIN( v, type, n ) VINIT( v, type, n ) REP( i, n ) cin >> v[i];

#define DOUT( x ) cerr << #x << " = " << x << "\n";
#define COUT( x ) cout << ( x ) << "\n";

#define INF 999999999



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

        int h, w, n;
        cin >> h >> w;
        cin >> n;
        vector<int> a;
        a.resize( n );
        REP( i, n ) cin >> a[i];
        vector<vector<int> > res;
        res.resize( h );
        REP( i, h ) res[i].resize( w, 0 );

        int x = 0;
        int y = 0;
        int b = 1;
        REP( i, n )
        {
                REP( j, a[i] )
                {

                        res[y][x] = i + 1;
                        x += b;
                        if( x >= ( int )res[y].size() )
                        {
                                ++y;
                                --x;
                                b = -1;
                        }
                        else if( x < 0)
                        {
                                ++y;
                                ++x;
                                b = 1;
                        }
                }
        }
        REP( i, res.size() )
        {
                REP( j, res[i].size() )
                {
                        cout << res[i][j] << " ";
                }
                cout << "\n";
        }

        return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

int main(void)
{
   int task[3];
   for(int i = 0; i < 3; i++)
    cin >> task[i];

    int first = max({task[0], task[1], task[2]});
    int third = min({task[0], task[1], task[2]});

    int second;
    for(int i = 0; i < 3; i++){
        if(task[0] == task[1] || task[0 == task[2]])
            second = task[0];
        if(task[1] == task[2])
            second = task[1];
    }

    int sum = abs(first - second) + abs(second -third);
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
c=1,6,9,36,81,216,729,1296,6561,7776,46656,59049

DP = [N for i in range(N + 1)]
DP[0] = 0
for cost in c:
    for i in range(cost, N + 1):
        DP[i] = min(DP[i], DP[i - cost] + 1)
print(DP[N])


Measured memory_bytes: 44912
import Data.Int

modulus :: Int64
modulus = 10^9 + 7

fact :: Int64 -> Int64
fact n = f n 1
  where
    f 0 b  = b
    f a b = b `seq` f (a - 1) ((a * b) `rem` modulus)

solve :: Int64 -> Int64 -> Int64
solve n m = calc `rem` modulus
  where
    calc
      | n == m           = 2 * fact n * fact m
      | abs (n - m) == 1 = fact n * fact m
      | otherwise        = 0

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine :: IO [Int64]
    print $ solve n m

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  char x;
  cin >> x;
  if(0<=x-'a'&&x-'a'<=25)
    cout << 'a' << endl;
  else
    cout << 'A' << endl;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
struct A {
	int a , b , c;
};
// .Always initialize dp array
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n; cin >> n;
	vector<A> v;
	for (int i = 0; i < n; i++)
	{
		int a, b, c; cin >> a >> b >> c;
		v.pb({a, b, c});
	}
	int dp[n][3];
	mem(dp, 0);
	dp[0][0] = v[0].a;
	dp[0][1] = v[0].b;
	dp[0][2] = v[0].c;
	for (int i = 1; i < n; i++)
	{
		dp[i][0] = v[i].a + max(dp[i - 1][2], dp[i - 1][1]);
		dp[i][1] = v[i].b + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = v[i].c + max(dp[i - 1][0], dp[i - 1][1]);

	}
	int ans = -1;
	for (int i = 0; i < 3; i++) ans = max(ans , dp[n - 1][i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 7860
r, c = map(int,input().split())
cells = []
for _ in range(r):
    li = list(map(int,input().split()))
    line_sum = sum(li)
    li.append(line_sum)
    cells.append(li)

sums = []
for i in range(c+1):
    s = 0
    for j in range(r):
        s += cells[j][i]
    sums.append(s)
cells.append(sums)

for i in range(r+1):
    for j in range(c+1):
        print(cells[i][j], end='')
        if j == c:
            print('')
        else:
            print(' ', end='')


Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
long long ceilint(long long m, long long n) {
    if (m % n == 0) return m / n;
    else return m / n + 1;
}
int main() {
    long long a, b, x;
    cin >> a >> b >> x;
    cout << b / x - ceilint(a, x) + 1;
}

Measured memory_bytes: 3636
#include<stdio.h>
	int h,w,v[110][110],dx[]={0,0,1,-1},dy[]={1,-1,0,0};
char a[110][110];
void	func(int y,int x,char c){
	int i;
	if(x>=0&&x<w&&y>=0&&y<h)
	if(v[y][x]==-1&&a[y][x]==c){
		v[y][x]=1;
		for(i=0;i<4;i++)
			func(y+dy[i],x+dx[i],c);
	}
	
}
	int main(){
		int d,i,j;
		while(scanf("%d %d",&h,&w),h||w){
			d=0;
			for(i=0;i<h;i++){
				scanf("%s",a[i]);
			
			}
			for(i=0;i<h;i++)
				for(j=0;j<w;j++)
					v[i][j]=-1;
			for(i=0;i<h;i++)
				for(j=0;j<w;j++)
					if(v[i][j]==-1){
						func(i,j,a[i][j]);
						d++;
				
			}
			printf("%d\n",d);
		}
		return 0;
	}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int K = sc.nextInt();

        List<String> list = new ArrayList<>();

        for (int i = 0; i <= s.length(); i++) {
            for (int j = i + 1; j <= s.length() && j <= i + K ; j++) {
                String substring = s.substring(i, j);
                if (!list.contains(substring)){
                    list.add(substring);
                }
            }
            Collections.sort(list);
        }
        System.out.println(list.get(K - 1));
    }
}

Measured memory_bytes: 31084
function Main(input) {
  var tmp = input.trim().split('\n')
  var N = parseInt(tmp[0])
  var Aarr = tmp[1].split(' ')

  var result = 'APPROVED'

  for (var i = 0; i < N; i++) {
    if (Aarr[i] % 2 === 0) {
      if (!(Aarr[i] % 3 === 0 || Aarr[i] % 5 === 0)) {
        result = 'DENIED'
      }
    }
  }

  console.log(result)
  return result
}

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

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S; 
	string T = {}; 
	int N = S.size(); 
	for(int i = 0; i < N; i++){
		if(i < N - 1 && S[i] == 'B' && S[i+1] == 'C'){
			T.push_back('X'); i++;
		}
		else T = T + S[i]; 
	}
	string U[200010] = {}; 
	int xx = 0; 
	for(int i = 0; i < T.size(); i++){
		if(T[i] == 'A' || T[i] == 'X'){
			U[xx].push_back(T[i]);
		}
		else xx ++; 
	}
	long long int ans = 0; 
	for(int i = 0; i <= xx; i++){
		if(U[i].size() == 0) continue; 
		else{
          long long int kosuu = 0; 
			for(int j = 0; j < U[i].size(); j++){
				if(U[i].at(j) == 'X') {
                  ans += (long long) j; kosuu ++; 
                }
			}
          ans -= kosuu * (kosuu - 1) / 2;
		}
	}
	cout << ans << endl; 
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/************************************************************************************************************************************************/
void solve(){
    LL N;
    cin >> N;
    vector<LL> num (100001,0);
    LL sum = 0;
    for(LL i = 0;i < N;i++){
        LL dummy;
        cin >> dummy;
        sum += dummy;
        num[dummy]++;
    }
    LL Q;
    cin >> Q;
    for(LL i = 0;i < Q;i++){
        LL B, C;
        cin >> B >> C;
        sum += (C-B)*num[B];
        num[C] += num[B];
        num[B] = 0;
        cout << sum << endl;
    }
}



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

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

using namespace std;
using lint=long long;

int main(){
	int n,x; scanf("%d%d",&n,&x);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	if(accumulate(a.begin(),a.end(),0LL)==x) return printf("%d\n",n),0;

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

	lint sum=0;
	rep(i,n){
		sum+=a[i];
		if(sum>x) return printf("%d\n",i),0;
	}
	printf("%d\n",n-1);

	return 0;
}


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

void sum_up(int x, int64_t sum, int64_t &result, 
                 string past, string &list) {
  if (x + 1 == list.size()) {
    past.push_back(list.at(x));
    result += sum + stoll(past);
    return;
  }
  
  past.push_back(list.at(x));
  
  int64_t y = sum;
  y += stoll(past);
  sum_up(x + 1, y, result, "", list);
  
  sum_up(x + 1, sum, result, past, list);
}

int main() {
  string list;
  cin >> list;
  
  int64_t result = 0;
  sum_up(0, 0LL, result, "", list);
  
  cout << result << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a.sort()
max_count = 0
count = 0
i = 0
x_before = -1
while i < N:
    x = a[i]
    j = i
    if x_before != x:
        while j < len(a):
            if x == a[j] or x+1 == a[j] or x+2 == a[j]:
                count += 1
                j += 1
            else:
                break
        if max_count < count:
            max_count = count
    x_before = x
    count = 0
    i += 1
print(max_count)


Measured memory_bytes: 13964