akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[e] += 1
    answer = 0
    for i in counter:
        ball_count = counter[i]
        if i > ball_count:
            answer += ball_count
        elif i < ball_count:
            answer += ball_count - i
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)


Measured memory_bytes: 18676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
ll n,ans=0,x[6]={0};
string s;

int main(){
	cin>>n;
	FOR(i,0,n){
		cin>>s;
		if(s[0]=='M')x[1]++;
		else if(s[0]=='A')x[2]++;
		else if(s[0]=='R')x[3]++;
		else if(s[0]=='C')x[4]++;
		else if(s[0]=='H')x[5]++;
	}
	FOR(i,1,6){
		FOR(j,i+1,6){
			FOR(k,j+1,6){
				ans+=x[i]*x[j]*x[k];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
 int i,H,W,j;
 scanf("%d%d",&H,&W);
 while(H*H+W*W){
  for(j=0;j<H;j++){
   for(i=0;i<W;i++){
    printf("#");}
   printf("\n");}
  printf("\n");
  scanf("%d%d",&H,&W);}
 return 0;}
 

Measured memory_bytes: 572
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
        int i,v;
        for(;;){
            int h = scan.nextInt();
            int w = scan.nextInt();
            if(h == 0 && w == 0)
                break;
            for(i = 1; i <= h; i++){
              for(v = 1; v <= w; v++){
                  System.out.print("#");
                }
                  System.out.println("");
                }
                System.out.println("");
              }
  }
}

Measured memory_bytes: 33100
from itertools import accumulate
from bisect import bisect_right

R = lambda: map(int, input().split())
*_, k = R()
a = accumulate(R())
b = list(accumulate(R()))
r = bisect_right(b, k)
for i, x in enumerate(a, 1):
  if x > k:
    break
  j = bisect_right(b, k - x)
  r = max(r, i + j) 
print(r)


Measured memory_bytes: 51512
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	string s;
	cin >> s;
	int same = 0, diff = 0;
	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == s[i + 1]){
			same++;
		}else{
			diff++;
		}
	}
	int yes = diff / 2 + diff % 2;
	if (yes <= k){
		printf("%d\n", n - 1);
	}else{
		printf("%d\n", same + k * 2);
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;cin>>a>>b;
    cout<<(a*b%2==0?"No":"Yes")<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
added = [0] * n
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
for i in range(n, 0, -1):
    if (i - 2) % 3 == 0:
        continue
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
        break

ans.sort()

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Measured memory_bytes: 16840
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin>>N;
  string s;
  s = to_string(N);
  
  if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3720
N,A=map(int, input().split())
x=list(map(int, input().split()))
dp = [[[0]*(51*51) for _ in range(N+1)] for _ in range(N+1)]
# dp[j][k][s]
for j in range(N+1):
    for k in range(N+1):
        for s in range(51*51):
            if j==0 and k==0 and s==0:
                dp[j][k][s] = 1
            elif j >=1 and s < x[j-1]:
                dp[j][k][s] = dp[j-1][k][s]
            elif j >=1 and k >= 1 and s >= x[j-1]:
                dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
            else:
                dp[j][k][s] = 0

ans = 0
for i in range(1, N+1):
    ans+= dp[N][i][i*A]
print(ans)

Measured memory_bytes: 94684
#include<stdio.h>

int main()
{
    int n,i,sum=0,a[3000]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&(a[i]));
		sum+=(a[i]-1);
	}
	
    printf("%d",sum);
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
vl dp(1<<21);
int main(){
  dp[0]=1;
  ll n;cin>>n;
  vvl a(n,vl(n));
  rep(i,n){
    rep(j,n)cin>>a[i][j];
  }
  for(ll S=1;S<(1<<n);S++){
    ll i=__builtin_popcount(S);
    rep(j,n){
      if((S&(1<<j))&&a[i-1][j])dp[S]=(dp[S]+dp[S^(1<<j)])%MOD;
    }
  }
  ll ans=dp[(1<<n)-1];
  cout<<ans<<endl;
}
  

Measured memory_bytes: 16640
a = []
b = []
A,B = map(int,input().split())
for i in range(B,A+B):
  p =abs(i)
  a.append(p)
  b.append(i)
a = sorted(a)
if a[0] in b:
  b.remove(a[0])
else:
  b.remove(-a[0])
print(sum(b))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std;
int main (){
	int a, b , d , r ;
	double f ;
	cin >> a >> b;
	d= a / b;
	r= a % b;
	f=  (double )a/b;
	cout << fixed << setprecision(5);
	cout << d <<" "<< r<<" "<< f;
	return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<vector>
#include <math.h>
#include <iomanip>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
#define inf 1000000007

signed main(){
    string s,t;cin>>s>>t;
    int sl=s.size(),tl=t.size();
    if(sl<tl)return 0;
    rep(i,0,s.size()-t.size()+1){
        bool ch=true;
        rep(j,i,i+tl){
            if(s[j]!=t[j-i])ch=false;
        }
        if(ch)cout<<i<<endl;
    }
    return 0;
}



Measured memory_bytes: 3208
S = list(input())
for i in range(len(S)):
	if i % 2 == 0:
		if (S[i] == "R") or(S[i] ==  "U") or(S[i] ==  "D"):
			continue
		else:
			print("No")
			exit()
	else:
		if (S[i] == "L") or(S[i] ==  "U") or(S[i] ==  "D"):
			continue
		else:
			print("No")
			exit()
print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    string x=s;
    reverse(x.begin(),x.end());
    if(s==x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

double exp_value(short int D1, short int D2, short int D3, ll N, vector<vector<vector<double>>>& dp){
  if(D1<0 || D2<0 || D3<0) return (double)0.0;
  if(D1==0 && D2==0 && D3==0) return (double)0.0;
  if(dp[D1][D2][D3]>=-0.5) return dp[D1][D2][D3];
  /*
  exp_value(D1, D2, D3, N, dp)
  = (N-D1-D2-D3)*exp_value(D1, D2, D3, N, dp)/N
  + D1*exp_value(D1-1, D2, D3, N, dp)/N
  + D2*exp_value(D1+1, D2-1, D3, N, dp)/N
  + D3*exp_value(D1, D2+1, D3-1, N, dp)/N
  + 1
  */
  ll sum = D1+D2+D3;
  double tmp1 = (double)D1*exp_value(D1-1, D2, D3, N, dp)/sum;
  double tmp3 = (double)D3*exp_value(D1, D2+1, D3-1, N, dp)/sum;
  double tmp2 = (double)D2*exp_value(D1+1, D2-1, D3, N, dp)/sum;
  return dp[D1][D2][D3] = tmp1+tmp2+tmp3+(double)N/sum;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vector<short int> Dishes(3, 0);
  ll a;
  rep(i, 0, N){
    cin >> a;
    ++Dishes[a-1];
  }
  vector<vector<vector<double>>> dp(Dishes[0]+Dishes[1]+Dishes[2]+1, vector<vector<double>>(Dishes[1]+Dishes[2]+1, vector<double>(Dishes[2]+1, -1.0)));

  printf("%.10lf\n", exp_value(Dishes[0], Dishes[1], Dishes[2], N, dp));

  return 0;
}


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

int main(){
	string s,t;
	cin >> s;
	cin >> t;
	int count=0;
	for(int i=0;i<3;i++){
		if(s.at(i)==t.at(i)){
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e10+1;
using namespace std;
#define NOT_EXIST -1

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

int N, nodeindex;
vector<int> c;
vector<pi> ab;
vector<int> ans;
vector<vector<int> > node;
vector<bool> done;

void bfs(int st) {
		nodeindex = 0;
		done = vector<bool>(N,false);
		done[st] = true;
		queue<int> q;
		q.push(st);
		while(!q.empty()){
				int now = q.front();
				q.pop();
				ans[now] = c[nodeindex++];
				for(int i=0;i<node[now].size();i++){
						int nextnode = node[now][i];
						if(done[nextnode] == false){
								done[nextnode] = true;
								q.push(nextnode);
						}
				}
		}
}

signed
main(){
	cin >> N;
	//初期化
	c = vector<int>(N);
	ab = vector<pi>(N-1);
	ans = vector<int>(N);
	node = vector<vector<int> >(N);

	rep(i,N-1){
			int a,b;
			cin >> a >> b;
			a--,b--;
			ab[i] = {a,b};
			node[a].push_back(b);
			node[b].push_back(a);
	}

	rep(i,N){
			cin >> c[i];
	}
	sort(Rall(c));

	nodeindex = 0;
	bfs(0);

	int sum = 0;
	for(int i=0;i<N-1;i++){
			sum += min(ans[ab[i].first], ans[ab[i].second]);
	}
	cout << sum << endl;

	for(int i=0;i<N;i++){
			if(i!=0) cout << " ";
			cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, s64>;

s64 prim(vector<vector<P>>& g, s64 s)
{
    int n = g.size();
    static const s64 inf = 1e18;
    vs64 cost(n, inf);
    cost[s] = 0;

    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(P{cost[s], s});
    s64 ret = 0;
    vector< bool > used(n, false);
    while (!pq.empty())
    {
        auto p = pq.top(); pq.pop();
        int from = p.second;
        if (used[from]) continue;
        ret += p.first;
        used[from] = true;

        for (auto x : g[from])
        {
            int to = x.first;
            s64 c = x.second;
            if (cost[to] > c)
            {
                cost[to] = c;
                pq.push(P{cost[to], to});
            }
        }
    }

    return ret;
}

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

    int n, m;
    cin >> n >> m;

    vector<vector<P>> g(n);
    rep (i, m)
    {
        s64 u, v, c;
        cin >> u >> v >> c;
        g[u].emplace_back(v, c);
        g[v].emplace_back(u, c);
    }

    cout << prim(g, 0) << "\n";

    return 0;
}



Measured memory_bytes: 9004
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 5e5 + 5;
int a[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n,x;
	while (cin >> n)
	{
		f(i, 1, n)scanf("%d", &a[i]);
		int idx = 1;
		ll now = (ll)1000;
		f(i, 2, n)
		{
			if (a[i] > a[i - 1])
			{
				ll res = now % a[i - 1];
				 now = now / a[i - 1] * a[i]+res;
			}
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}



int main() {
    int n, m; cin >> n >> m;
    if (n % m == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

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

bool kaibun(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

int main () {
  string s;
  cin >> s;
  
  int n = s.size();
  if (kaibun(s) && kaibun(s.substr(0, n/2)) && kaibun(s.substr(n/2+1))) {
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int main() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    int i = 0;
    while (i < s.size()) {
        if (s.substr(i, 7) == "remaerd") i += 7;
        else if (s.substr(i, 6) == "resare") i += 6;
        else if (s.substr(i, 5) == "maerd" || s.substr(i, 5) == "esare") i += 5;
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
ll dp[2000000];
main(){
    int n=in(),k=in();
    vec v;
    rep(i,n)v.pb(in());
    int ans=0;
    rep2(i,0,n){
        rep2(j,i,n){
            vec s;
            int temp=0;
            if(i)
            rep2(ii,0,i-1){
                s.pb(v[ii]);
                temp+=v[ii];
            }
            if(j!=n)
            rep2(ii,j,n-1){
                s.pb(v[ii]);
                temp+=v[ii];
            }
            sort(ALL(s));
            if(s.size()>k)continue;
            int kk=k-s.size();
            int p=0;
            while(kk&&p<s.size()&&s[p]<0){
                temp-=s[p];
                p++;
                kk--;
            }
            ans=max(ans,temp);
        }
    }
    cout<<ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l),I=(r);i<I;++i)
//-------head-------
const int N = 1e5 + 7;
int n, m, a[N], x[N], p[N], t[N];
ll k, ans[N];
int main() {
	scanf("%d", &n);
	rep(i, 1, n + 1) scanf("%d", &x[i]);
	scanf("%d%lld", &m, &k);
	rep(i, 1, n + 1) a[i] = i;
	rep(i, 0, m) {
		int w;
		scanf("%d", &w);
		swap(a[w], a[w + 1]);
	}
	rep(i, 1, n + 1) p[a[i]] = i, a[i] = i;
	rep(z, 0, 60) {
		if (k >> z & 1) {
			rep(i, 1, n + 1) t[p[i]] = a[i];
			rep(i, 1, n + 1) a[i] = t[i];
		}
		rep(i, 1, n + 1) t[i] = p[p[i]];
		rep(i, 1, n + 1) p[i] = t[i];
	}
	ans[1] = x[1];
	rep(i, 2, n + 1) ans[i] = ans[i - 1] + x[a[i]] - x[a[i] - 1];
	rep(i, 1, n + 1) printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;

ll countBlack(const vector<vector<char>>& c, ull skipH, ull skipW)
{
    ll count = 0;
    for(ll i = 0; i < c.size(); i++)
    {
        if((skipH >> i & 0x1) == 1)
        {
            continue;
        }

        for(ll j = 0; j < c[i].size(); j++)
        {
            if((skipW >> j & 0x1) == 1)
            {
                continue;
            }

            if(c[i][j] == '#')
            {
                count++;
            }
        }
    }

    return count;
}

int main()
{
    ll h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h);
    for(ll i = 0; i < h; i++)
    {
        for(ll j = 0; j < w; j++)
        {
            char ch;
            cin >> ch;
            c[i].push_back(ch);
        }
    }

    ull iMax = pow(2, h) - 1;
    ull jMax = pow(2, w) - 1;
    ll count = 0;
    for(ull i = 0; i < iMax; i++)
    {
        for(ull j = 0; j < jMax; j++)
        {
            if(countBlack(c, i, j) == k)
            {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 4104
def main():
    N = int(input())
    S = input()
    
    ans = S.count('R') * S.count('G') * S.count('B')
    colors = set(list('RGB'))

    for i in range(N-2):
        for j in range(i+1, i+1+(N-1-i)//2):
            k = j + (j - i)
            if set([S[i], S[j], S[k]]) == colors:
                ans -= 1
            
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> V, C;
	for(int i = 0; i < N; ++i) {
		int v;
		cin >> v;
		V.push_back(v);
	}
	for(int i = 0; i < N; ++i) {
		int c;
		cin >> c;
		C.push_back(c);
	}
	int ans = 0;
	for(int i = 0; i < N; ++i) {
		if(V[i] > C[i]) {
			ans += V[i] - C[i];
		}
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    map<ll, ll> mp;
    rep(i, N)
    {
        ll x;
        cin >> x;
        mp[x]++;
    }

    ll area = 0;
    ll fst = 0;
    for (auto& p : mp) {
        if (p.second < 2) {
            continue;
        }
        if (p.second >= 4) {
            area = max(area, p.first * p.first);
        }
        area = max(area, p.first * fst);
        fst = p.first;
    }
    cout << area << endl;
    return 0;
}

Measured memory_bytes: 6528
using System;

public class Class1
{
	static void Main(string[] args)
	{
        int a, b;
        string[] str = Console.ReadLine().Split(' ');

        a = int.Parse(str[0]);
        b = int.Parse(str[1]);

        if (a * b % 2 == 0) {
            Console.WriteLine("Even");
        }
        else{
            Console.WriteLine("Odd");
        }
    }
}


Measured memory_bytes: 11092
x=int(input())


targetList=[]
for i in range(-3000,3000):
    targetList.append(i**5)

for i in range(-3000,3000):
    for j in range(i,3000):
        if targetList[3000+j]-targetList[3000+i]==x:
            print(str(j)+" "+str(i))
            exit()

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

int main() {
    int64_t N; cin >> N;
    int64_t ans = 1e18;
    for(int64_t i = 1; i * i <= N; ++i) {
        if(N % i) continue;
        ans = min(ans, i + N / i - 2);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stdlib.h>
#include <time.h> 
#include <assert.h>

#define nmax 500010
#define eps 1e-8
#define MOD 998244353

#define P1 25671
#define P2 191
#define MOD1 666013
#define MOD2 1000000007
#define B_SIZE 315

#define SZ(x) ((int)(x.size()))

#define fst first
#define snd second
#define pb push_back
#define mp make_pair

using namespace std;

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

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n, k;
int h[nmax], dp[nmax];

int main()
{
	scanf("%d %d", &n, &k);

	for (int i = 1; i <= n; i++) scanf("%d", &h[i]);

	for (int i = 1; i <= n; i++) dp[i] = 1e9;

	dp[1] = 0;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= k && i + j <= n; j++)
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));

	printf("%d", dp[n]);

	return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector <string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  sort (S.begin(),S.end());
  int ans = 1;
  for (int i = 0; i < N-1; i++) {
    if (S.at(i) != S.at(i+1)) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	string s = to_string(n);
	int x = 0;
	rep(i, 0, s.size()) {
		x += s[i] - '0';
	}
	if (n%x == 0) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#define ui unsigned int
int main(void){
	ui n,a,b,one,ten,hun,thou,mil,sum,total=0;
	scanf("%u%u%u",&n,&a,&b);
	for(ui i=1;i<=n;i++){
		mil=i/10000;
		thou=(i-mil*10000)/1000;
		hun=(i-mil*10000-thou*1000)/100;
		ten=(i-mil*10000-thou*1000-hun*100)/10;
		one=i-mil*10000-thou*1000-hun*100-ten*10;
		sum=mil+thou+hun+ten+one;
		if(a<=sum && sum<=b){
			total+=i;
		}
	}
	printf("%u",total);

	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

template <typename T>
std::vector<size_t> sort_indexes(const std::vector<T> &v) {
  std::vector<size_t> idx(v.size());
  std::iota(idx.begin(), idx.end(), 0);
  std::sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) {return v[i1] < v[i2];});
  return idx;
}

int main() {
  ll n,m;
  std::cin >> n >> m;
  std::vector<ll> a(n);
  rep(i,n) std::cin >> a[i];
  std::vector<ll> b(m);
  std::vector<ll> c(m);
  rep(i,m) std::cin >> b[i] >> c[i];
  std::sort(a.begin(), a.end());
  std::vector<size_t> idx = sort_indexes<ll>(c);
  ll count = 0;
  ll sum = 0;
  ll ai = n-1;
  ll idxi = m-1;
  while(count<n) {
    if(idxi<0||a[ai]>c[idx[idxi]]) {
      sum+=a[ai];
      count++;
      ai--;
    }
    else {
      if(count+b[idx[idxi]]<=n) {
        sum+=b[idx[idxi]]*c[idx[idxi]];
        count+=b[idx[idxi]];
        idxi--;
      }
      else {
        sum+=c[idx[idxi]]*(n-count);
        count+=b[idx[idxi]];
      }
    }
  }
  std::cout << sum << std::endl;
  
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,m,q;
ll a[200005],mina[200005],b[200005],ans[200005];
multiset<pll> s;

int main(){
	n=readint(); q=readint()+1;
	a[1]=n;
	for(int i=2;i<=q;i++) a[i]=readint();
	mina[q+1]=1ll<<60;
	for(int i=q;i>=1;i--) mina[i]=min(mina[i+1],a[i]);
	for(int i=1;i<=q;i++) if(mina[i]==a[i]) b[++m]=a[i];
//	for(int i=1;i<=m;i++) cout<<b[i]<<' ';
//	cout<<endl;
	ll lst=0;
	s.insert(mp(-b[m],1));
	for(int i=m-1;i>=1;i--){
		lst=0;
		set<pll>::iterator tmp=s.begin();
		for(auto it=s.begin();it!=s.end();it++){
			tmp=it;
			if((-it->fi)<b[i]) break;
			if((-it->fi)%b[i]) s.insert(mp(-((-it->fi)%b[i]),it->se));
			lst+=((-it->fi)/b[i])*it->se;
		}
		if(!s.empty()&&-((--s.end())->fi)>=b[i]) s.clear();
		else s.erase(s.begin(),tmp);
		if(lst) s.insert(mp(-b[i],lst));
//		cout<<"test "<<i<<endl;
//		for(auto x:s) cout<<x.fi<<' '<<x.se<<endl;
	}
	for(auto x:s) ans[-x.fi]+=x.se;
	for(int i=n;i>=1;i--) ans[i]+=ans[i+1];
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 19584
#include <iostream>

using namespace std;

int main() {
	int s;
	cin >> s;
	int h = int(s/3600);
	s -= 3600 * h;
	int m = int(s/60);
	s -= 60 * m;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

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

ll n, m;
ll ans;

int main() {
    scanf("%lld%lld", &n, &m);
    ans += n * m;
    if (n > 1 && m > 1) {
        ans -= (m - 2) * 2;
        ans -= (n - 2) * 2;
        ans -= 4;
    }
    else if (n > 1 || m > 1) {
        ans -= 2;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

vector<bool> visited(8, false);
vector<vector<bool>> edges;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>  p;
    rep(i, N){
        p.push_back(i);
        edges.push_back(vector<bool>(8, false));
    }
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        edges[a][b] = edges[b][a] = true;
    }
    int ans = 0;
    do{
        bool flag = true;
        for(int i = 0; i < p.size() - 1; i++){
            int next = p[i + 1];
            int now = p[i];
            if(! edges[now][next]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans ++;
        }
    }while (next_permutation(p.begin() + 1, p.end()));

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int maxn=1<<21;
int n;
int a[105][105];
int color[105];
int d[105];
int p[105];
int f()
{
    int u;int minx;
    for(int i=0;i<105;i++)
    {
        d[i]=maxn;
        p[i]=-1;
    }
    d[0]=0;
    while(1)
    {
        minx=maxn;
        u=-1;
        for(int i=0;i<n;i++)
        {
            if(minx>d[i]&&color[i]==0)
            {
                u=i;
                minx=d[i];
            }
        }
        if(u==-1) break;
        color[u]=1;
        for(int i=0;i<n;i++)
        {
            if(color[i]==0&&a[u][i]!=maxn)
            {
                if(d[i]>a[u][i])
                {
                    d[i]=a[u][i];
                    p[i]=u;
                    color[i]=0;
                }
            }
        }
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        if(p[i]!=-1) sum+=a[i][p[i]];
    }
    return sum;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            int x;
            scanf("%d",&x);
            a[i][j]=(x==-1)?maxn:x;
        }
    }
    printf("%d\n",f());
    return 0;
}

Measured memory_bytes: 2732
using System;
using System.Collections.Generic;

namespace Volume0_0008
{
	class Program
	{
		static void Main(string[] args)
		{
			List<int> ns = new List<int>();

			for(int i = 0; i < 50; i++) {
				string str = Console.ReadLine();
				if(str == null) {
					break;
				}

				ns.Add(int.Parse(str));
			}

			foreach(int n in ns) {
				int cnt = 0;

				for(int a = 0; a <= 9; a++) {
					for(int b = 0; b <= 9; b++) {
						for(int c = 0; c <= 9; c++) {
							for(int d = 0; d <= 9; d++) {
								if(a + b + c + d == n) {
									cnt++;
								}
							}
						}
					}
				}

				Console.WriteLine(cnt);
			}
		}
	}
}



Measured memory_bytes: 13928
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 100000007
typedef long long ll;
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	string s;
	int x,y;
	lol(i,h)lol(j,w){
		cin>>s;
		if(s=="snuke"){
			x=j,y=i;
		}
	}
	char z=x+'A';
	cout<<z<<y+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

signed main() {
  int N;
  cin >> N;
  
  vector<int> T(N+1);
  vector<int> X(N+1);
  vector<int> Y(N+1);
  for( int i = 1; i <= N; i++ ) cin >> T.at(i) >> X.at(i) >> Y.at(i);
  
  for( int i = 1; i <= N; i++ ){
    int A = T.at(i)-T.at(i-1);
    int B = abs(X.at(i)-X.at(i-1))+abs(Y.at(i)-Y.at(i-1));
    if( A%2 != B%2 || A < B ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}


Measured memory_bytes: 2560
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  uint32_t d = 0;
  std::cin >> d;
  std::vector<uint32_t> A(d + 1);
  for (auto &&a : A) std::cin >> a;

  std::vector<unsigned long long> cap(A.size(), 1ll);
  for (uint32_t i = 0; i < A.size(); i++) {
    if (cap[i] < A[i]) {
      std::cout << -1 << std::endl;
      return 0;
    }
    if (i + 1 < A.size()) cap[i + 1] = (cap[i] - A[i]) * 2;
  }

  std::vector<uint64_t> count(d + 1, 0);
  unsigned long long sum = 0;
  for (int32_t i = A.size() - 1; i >= 0; i--) {
    if (i != static_cast<int32_t>(A.size()) - 1) count[i] += count[i + 1];
    count[i] += A[i];
    count[i] = (cap[i] < count[i]) ? cap[i] : count[i];
    sum += count[i];
  }

  std::cout << sum << std::endl;

  return 0;
}

Measured memory_bytes: 5052
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	int a,b,c,k;
	int t=0;
	cin>>a>>b>>c;
	cin>>k;

	while(a>=b){
		b*=2;
		t++;
	}
	while(b>=c){
		c*=2;
		t++;
	}
	if(t<=k)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
n, k, q = map(int, input().split())
c = [k - q for i in range(n)]
a = [int(input()) for i in range(q)]
for i in range(q):
    c[a[i] - 1] += 1

for i in range(n):
    if c[i] >= 1:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 11796
# -*- coding: utf-8 -*-


def main():
    from itertools import product

    n = int(input())
    numbers = list()
    ans = 0

    for digit in range(1, 10):
        for i in list(product(['3', '5', '7'], repeat=digit)):
            numbers.append(''.join(map(str, list(i))))

    for number in numbers:
        if int(number) <= n:
            if '3' in number and '5' in number and '7' in number:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	string S;
	cin >> S;
	int additional = 0;
	
	if (S[0] == 'o') additional += 100;
	if (S[1] == 'o') additional += 100;
	if (S[2] == 'o') additional += 100;
	
	cout << 700+additional <<endl;
	
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
A=[]
B=[]
for i in range(n):
    A.append(input())
for i in range(m):
    B.append(input())
cnt=0
flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = 'Yes'
        for k in range(m):
            for l in range(m):
                if A[i+k][j+l]!=B[k][l]:
                    ans = 'No'
        else:
            if ans == 'Yes':
                print(ans)
                exit()
print(ans)

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

int di[4] = {0, -1, 0, 1};
int dj[4] = {1, 0, -1, 0};
char G[12][6];
int nseq, cnt;
bool v[12][6];

void reset(){ rep(i, 12) rep(j, 6) v[i][j] = false; }

bool isColor( char c ){
    return c == 'R' || c == 'G' || c == 'B' || c == 'Y' || c == 'P';
}

void dfs(int y, int x, char c){
    cnt++;
    int ni, nj;
    v[y][x] = true;
    rep(r, 4){
	ni = y + di[r];
	nj = x + dj[r];
	if ( ni < 0 || nj < 0 || ni >= 12 || nj >= 6 ) continue;
	if ( !v[ni][nj] && c == G[ni][nj] ) dfs(ni, nj, c);
    }
}

void parse(int y, int x, char c){
    int ni, nj;
    G[y][x] = 'X';
    rep(r, 4){
	ni = y + di[r];
	nj = x + dj[r];
	if ( ni < 0 || nj < 0 || ni >= 12 || nj >= 6 ) continue;
	if ( c == G[ni][nj] ) parse(ni, nj, c);
    }
}

bool simulate(){
  

    bool isR = false;
    rep(i, 12) rep(j, 6){
	cnt = 0;
	if ( isColor(G[i][j])){
	    reset();
	    dfs(i, j, G[i][j]);
	}
	if ( cnt >= 4 ){
	    reset();
	    parse(i, j, G[i][j]);
	    isR = true;
	}
    }

    
    rep(i, 12) rep(j, 6){
	if ( G[i][j] != 'O' ) continue;
	rep(r, 4){
	    int ni = i + di[r];
	    int nj = j + dj[r];
	    if ( ni < 0 || nj < 0 || ni >= 12 || nj >= 6 ) continue;
	    if ( G[ni][nj] == 'X' ) G[i][j] = 'x';
	}
    }
   
    rep(i, 12) rep(j, 6) if ( G[i][j] == 'X' || G[i][j] == 'x' ) G[i][j] = '.';
    
  




    for ( int j = 0; j < 6; j++ ){
	while(1){
	    bool isChange = false;
	    for ( int i = 11; i >= 1; i-- ){
		if ( G[i][j] == '.' && G[i-1][j] != '.' ){
		    G[i][j] = G[i-1][j];
		    G[i-1][j] = '.';
		    isChange = true;
		    break;
		}
	    }
	    if ( !isChange ) break;
	}
    }


    return isR;
}

void compute(){
    rep(i, 12) rep(j, 6) cin >> G[i][j];
    nseq = 0;
    while(simulate()){ nseq++; }
    cout << nseq << endl;
}

main(){
    int tcase; cin >> tcase;
    for ( int i = 0; i < tcase; i++ ) compute();
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int ans = Math.min(A,B)+Math.min(C,D);
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

struct train
{	
	int c,s,f;
};
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	int n;	

	cin>>n;

	string a;

	map<char,ll>occ;

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

	std::vector<char> v = {'M','A','R','C','H'};
	ll ans = 0;
	for(int i=0;i<sz(v);i++){
		for(int j=i+1;j<sz(v);j++){
			for(int k=j+1;k<sz(v);k++){
				ans+=occ[v[i]]*occ[v[j]]*occ[v[k]];
			}
		}
	}

	cout<<ans<<endl;
}



Measured memory_bytes: 384
t = int(input())

if t > 3600:
    h = t // 3600
    ms = t % 3600
    if ms >= 60:
        m = ms // 60
        s = ms % 60
    else:
        m = 0
        s = ms    
elif t < 3600:
    h = 0
    m = t // 60
    s = t % 60
    if t < 60:
        h = 0
        m = 0
        s = t
else:
    h = 1
    m = 0
    s = 0

print(f'{h}:{m}:{s}')


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(min(a,b)<c&&c<max(a,b))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;cin>>c;
    puta((char)(c+1));
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))


//組み合わせ（nとrが少ないとき）
int combination_low(ll n,ll r){
	const ll N = 500;
	ll C[N][N];
	memset(C, 0, sizeof(C));
	C[0][0]=1;
	for(ll n=1; n<N; n++){
		C[n][0]=C[n-1][0];
		for(ll r=1; r<N; r++){
			C[n][r] = C[n-1][r-1] + C[n-1][r];
		}
	}
	return C[n][r];
}

//二分累乗法
int powa(ll a, ll n){
	ll res = 1;
	while(n>0) {
		if(n&1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1; 
	}
	return res;
}

//逆元
int inverse(ll a){
	ll n = mod-2;
	return powa(a, n);
}

/*組み合わせ（いちばんうまくいったやつ）*/
int combination(ll n,ll r){
	ll x=1,y=1;
	for(int i=1;i<=r;i++){
		x = x * (n-i+1) % mod;
		y = y * i % mod;
	}
	return x * inverse(y) % mod;
}

int main(void){
	int d,n;
	scanf("%d %d",&d,&n);
	int ans=0,base=1*powa(100,d);
	for(int i=1;i<=n;i++){
		if(i==100) ans+=2*base;
		else ans+=base;
	}
	printf("%d\n",ans);
	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define maxx 1001
#define mod 1000000007

char a[maxx][maxx];

int f(int h,int w)
{
    int dp[h][w];
    memset(dp,-1,sizeof dp);
    int flag=1;
    for(int i=0;i<h;i++)
    {
        if(a[i][0]=='#')
            flag=0;
        dp[i][0]=flag;
    }
    flag=1;
    for(int i=0;i<w;i++)
    {
        if(a[0][i]=='#')
            flag=0;
        dp[0][i]=flag;
    }
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(a[i][j]=='#')
                dp[i][j]=0;
            else
                dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
    }
    return dp[h-1][w-1];
}
int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>a[i][j];

    cout<<f(h,w);
}


Measured memory_bytes: 8396
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='1') ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int A[100];
int main()
{
    int n=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    sort(A,A+n);
    int sum=0;
    for(int i=0;i<n-1;i++) sum+=A[i];
    if(sum>A[n-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#import<cstdio>
int main(){for(int a,c,r,t;r=c=1,~a;~-r&&printf("%d\n",r))for(char d[]="12354",s[9];a=scanf("%s",s),*s>60;r+=*d&7)*s%6-4?t=*d,*d=d[a+=*s%5+*s*2+c&3],d[a]=~t,d[++a%4+1]=t:c+=*s+3;}

Measured memory_bytes: 0