akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
	int H,W;
	scanf("%d %d",&H,&W);
	char S[H][W];
	for(int i=0;i<H;i++){
		scanf("%s",&S[i]);
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i][j]=='.'){
				S[i][j]='0';
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i][j]=='#'){
				for(int k=-1;k<=1;k++){
					for(int l=-1;l<=1;l++){
						if((i+k>=0)&&(i+k<H)&&(j+l>=0)&&(j+l<W)){
							if(S[i+k][j+l]!='#'){
								S[i+k][j+l]++;
							}
						}
					}
				}
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			printf("%c",S[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
def resolve():
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    far = 0
    for i in range(n - 1):
        far = max(far, a[i + 1] - a[i])
    far = max(far, k + a[0] - a[-1])
    print(k - far)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }

void _main() {
  string S;
  cin >> S;

  int ans = 0;
  char now = S[0];
  rep(i, 0, (int)S.size()) {
    if (S[i] == now) continue;
    ans++;
    now = (now == 'B') ? 'W' : 'B';
  }

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

const ll mx=1LL<<11;
ll dp[mx][mx];
vector<ll> a;
ll m,n;

ll dfs(ll know,ll up){
    if(dp[know][up]!=-1){return dp[know][up];}
    ll count=0;
    for(int i=0;i<n;i++){
        if((a[i]&know)==up){count++;}
    }
    if(count<=1){return dp[know][up]=0;}
    ll mi=E;
    for(ll i=0;i<m;i++){
        if(know>>i&1){continue;}
        ll a=dfs(know|(1LL<<i),up|(1LL<<i));
        a=max(a,dfs(know|(1LL<<i),up));
        mi=min(mi,a+1);
    }
    return dp[know][up]=mi;
}


int main(){
    while(cin>>m>>n && n){
        a.resize(n);
        for(int i=0;i<mx;i++){
            for(int t=0;t<mx;t++){
                dp[i][t]=-1;
            }
        }
        for(int i=0;i<n;i++){
            a[i]=0;
            for(int t=0;t<m;t++){
                char c;
                cin>>c;
                if(c=='1'){
                    a[i]+=1LL<<(m-t-1);
                }
            }
        }
        cout<<dfs(0,0)<<endl;
    }
    
    
    
    return 0;
}




Measured memory_bytes: 35912
from collections import Counter

num = int(input())
input = [input() for i in range(num)]
rv = 0
counters = [sorted(Counter(s).elements()) for s in input]
strings = ["".join(s) for s in counters]
counts = list(Counter(strings).values())
for c in counts:
  rv += sum(x for x in range(1,c))
print(rv)


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

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

const int nax = 1e5 + 5;
int val[nax];
vector<int> w[nax];
typedef long long ll;

void NO() {
	puts("NO");
	exit(0);
}

ll dfs(int a, int par) {
	if((int) w[a].size() == 1)
		return val[a];
	vector<ll> children;
	for(int b : w[a]) if(b != par)
		children.push_back(dfs(b, a));
	ll s = 0;
	ll big = 0;
	for(ll x : children) {
		s += x;
		big = max(big, x);
	}
	// sum + ? = 2 * val
	ll nowy = 2 * val[a] - s;
	debug() << imie(s) << imie(nowy);
	if(nowy < 0) NO();
	s += nowy;
	big = max(big, nowy);
	if(big > s - big) NO();
	return nowy;
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &val[i]);
	if(n == 2) {
		puts(val[1] == val[2] ? "YES" : "NO");
		return 0;
	}
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		w[a].push_back(b);
		w[b].push_back(a);
	}
	for(int root = 1; root <= n; ++root)
		if((int) w[root].size() >= 2) {
			if(dfs(root, -1)) NO();
			puts("YES");
			return 0;
		}
	assert(false);
}



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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

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

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M, K;
  cin >> N >> M >> K;

  bool ok = false;
  rep(i, N + 1) {
    rep(j, M + 1) {
      int b = i * M + j * N - 2 * i * j;
      if (b == K)
        ok = true;
    }
  }

  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int K,X;

int main() {
	cin>>K>>X;
	cout<<(K*500>=X?"Yes":"No")<<endl;

	return 0;
}



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

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

Measured memory_bytes: 256
package main
import . "fmt"
func main() {
  var n int
  var s string
  var m []int64 = make([]int64,5)
  var x int64
  Scan(&n)
  for i:=0;i<n;i++ {
    Scan(&s)
    switch s[0:1] {
      case "M": m[0]++
      case "A": m[1]++
      case "R": m[2]++
      case "C": m[3]++
      case "H": m[4]++
    }
  }
  x = 0
  x += m[0]*m[1]*m[2]+m[0]*m[2]*m[4]
  x += m[1]*m[2]*m[3]+m[1]*m[3]*m[0]
  x += m[2]*m[3]*m[4]+m[2]*m[4]*m[1]
  x += m[3]*m[4]*m[0]+m[3]*m[0]*m[2]
  x += m[4]*m[0]*m[1]+m[4]*m[1]*m[3]
  Println(x)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int N = 51;

int n;
int a[N], b[N];

bool good(int mask) {
	bool ok = true;
	for (int i = 0; i < n; ++i) {
		vector<bool> vis(N, false);
		queue<int> q;
		q.push(a[i]);
		vis[a[i]] = true;
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int bit = 1; bit <= 50; ++bit) {
				if (!(mask & (1LL << bit))) continue;
				if (!vis[u % bit]) {
					vis[u % bit] = true;
					q.push(u % bit);
				}
			}
		}
		ok &= vis[b[i]];
	}
	return ok;
}
				
int32_t main() {
	fast_cin();  
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	int mask = (1LL << 51) - 1;
	if (!good(mask)) {
		cout << -1 << endl;
		return 0;
	}
	for (int bit = 50; bit >= 0; --bit) {
		if (good(mask ^ (1LL << bit))) {	
			mask ^= (1LL << bit);
		}
	}
	cout << mask << endl;
	return 0;
}

Measured memory_bytes: 3640
H, W = map(int, input().split())
STAGE = [list(input()) for _ in range(H)]

ds = ((0, 1), (1, 0))
cp = [(0, 0)]
sc = 1

while cp:
	np = []
	for p in cp:
		y, x = p
		for d in ds:
			dy, dx = y + d[0], x + d[1]
			if 0 <= dy < H and 0 <= dx < W:
				if "#" == STAGE[dy][dx]:
					sc += 1
					if not (dy, dx) in np:
						np += [(dy, dx)]
						break
			else:
				continue
	#print(np)
	cp = np

c = 0
for line in STAGE:
	c += line.count("#")

print(["Possible", "Impossible"][not(sc == c)])


Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <vector>

#define MAX_N 100000
#define MAX_X 100000

using namespace std;

typedef pair<int, int> P;

struct UnionFind
{
private:
    vector<int> root;

public:
    UnionFind( int size ) { root.resize( size, -1 ); }

    int find( int x )
    {
        if ( root[x] < 0 ) return x;
        return root[x] = find( root[x] );
    }

    bool same( int x, int y ) { return find( x ) == find( y ); }

    int size( int x ) { return -root[find( x )]; }

    bool unite( int x, int y )
    {
        int rx = find( x );
        int ry = find( y );

        if ( rx == ry ) return false;

        if ( root[ry] < root[rx] ) swap( rx, ry );

        root[rx] += root[ry];
        root[ry] = rx;

        return true;
    }
};

int main( int argc, char **argv )
{
    int N;
    cin >> N;

    vector<int> X( N );
    vector<int> Y( N );
    for ( int i = 0; i < N; i++ ) cin >> X[i] >> Y[i];

    UnionFind ufx = UnionFind( MAX_X + 1 );
    UnionFind ufy = UnionFind( MAX_X + 1 );

    vector<int> pairX( MAX_X + 1 );
    vector<int> pairY( MAX_X + 1 );
    for ( int i = 0; i < N; i++ )
    {
        if ( pairY[X[i]] > 0 ) ufy.unite( pairY[X[i]], Y[i] );
        pairY[X[i]] = Y[i];

        if ( pairX[Y[i]] > 0 ) ufx.unite( pairX[Y[i]], X[i] );
        pairX[Y[i]] = X[i];
    }

    long long ans = 0;
    set<P> checked;

    for ( int i = 0; i < N; i++ )
    {
        int rx = ufx.find( X[i] );
        int ry = ufy.find( Y[i] );

        if ( checked.find( P( rx, ry ) ) == checked.end() )
        {
            checked.insert( P( rx, ry ) );
            ans += (long long)ufx.size( rx ) * ufy.size( ry );
        }
    }

    cout << ( ans - N ) << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  if((a + b) % 2 == 1)
  {
   double A,B;
   A = a;
   B = b;
   cout << (A + B) / 2 + 0.5 << endl;
  }
  else{
  cout << (a + b) / 2 << endl;
    }
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

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

	bool a = true;
	bool b = true;

	if (s.size() % 2 == 1) b = false;

	for (int i; i < s.size() - 1; i += 2) {
		if (s[i] != 'h' || s[i + 1] != 'i') {
			a = false;
			break;
		}
	}

	if (a == true && b == true) dunk("Yes");
	else dunk("No");
}


Measured memory_bytes: 256
S = input()
ans = 0
for i in range(2 ** 3):
    tmp = int(S[0])
    tmp2 = ''
    for k in range(3):
        if 1 & i>>k:
            tmp += int(S[k+1])
            tmp2 += '+' + S[k+1]
        else:
            tmp -= int(S[k+1])
            tmp2 += '-' + S[k+1]
    tmp2 = S[0] + tmp2 + '=7'
    if tmp == 7:
        print(tmp2)
        exit()

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

main() {
  int N; cin >> N;
  vi a(N); rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[N - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    // first:数、second:7,5,3が使われてるかどうかをビットで管理
    queue<pair<lint, int>> bfs;
    bfs.push({7, 1});
    bfs.push({5, 2});
    bfs.push({3, 4});
    int ans = 0;
    while (bfs.size() > 0) {
        auto now = bfs.front();
        bfs.pop();
        lint x = now.first, b = now.second;
        if (x > n) continue;
        if (b == 7) ans++;
        bfs.push({x * 10 + 7, b | 1});
        bfs.push({x * 10 + 5, b | 2});
        bfs.push({x * 10 + 3, b | 4});
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  for (int i = 0; i < n; ++i) for (int j = i; j <= n; ++j) {
    string t = s.substr(0, i) + s.substr(j, n);
    if (t == "keyence") {
      return cout << "YES" << '\n', 0;
    }
  }
  cout << "NO" << '\n';
}

Measured memory_bytes: 256
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
ll OO=1e6;  
const int N=1e6 + 2;
int arr[N];
int ans[N];


ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;

vector<int> vec;

map<int,int> mp;

ll Sum(ll x){
	return x*(x+1)/2;
}


int main(){
	
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>arr[i];
		++mp[arr[i]];
	}
	
	for(auto i:mp)
		cnt+=Sum(i.second-1);
	
	for(int i=0;i<n;++i)
		cout<<cnt-(mp[arr[i]]-1)<<endl;
	
		
	
	
	
	
	
	
}
 
 
 
 
 
 
 
 


Measured memory_bytes: 11648
#include <iostream>
#include <math.h>

using namespace std;

int main(void){
  int n, i;
  double a;
  double sum = 0;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> a;
    sum = sum + 1 / a;
  }
  sum = pow(sum, -1);
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())

if n == 2:
    print(1)
    exit()
num = n - 1
cnt = 1
lst = [n]
for i in range(2, int(n ** 0.5) + 1):
    if num % i == 0:
        cnt += 2
        if num == i ** 2:
            cnt -= 1
    if n % i == 0:
        lst.append(i)
        if n != i ** 2:
            lst.append(n // i)
for num in lst:
    n2 = n
    while n2 % num == 0:
        n2 //= num
    if n2 % num == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
long long  a,b,c,d;
int main()
{
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
    /*if(a>=0&&c>=0)
    {
        cout<<b*d<<endl;
    }
    else if(b<=0&&d<=0)
    {
        cout<<a*c<<endl;
    }
    else if(a*b<=0&&c*d<=0)
    {
        //cout<<1<<endl;
        cout<<max(a*c,b*d)<<endl;
    }else
    {
        //cout<<2<<endl;
        cout<<max(a*d,b*c)<<endl;
    }*/
    return 0;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 mod = 1000000007;
int main() {
    int n;
    cin >> n;
    vector<int>cnt(1005);
    for(int i = 2;i<=n;i++) {
        int a = i;
        for(int j = 2;j*j<=n;j++) {
            if(a%j != 0) continue;
            int tmp = 0;
            while(a%j == 0) {
                a /= j;
                tmp++;
            }
            cnt[j] += tmp;
        }
        if(a != 1) cnt[a]++;
    }
    ll ans = 1;
    rep(i,1001) {
        if(cnt[i] > 0){
            ans *= cnt[i]+1;
            ans %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = IntArray(N) { sc.next().toInt() }
        val a = mutableMapOf<Int, Int>()
        A.forEach {
            a[it] = (a[it] ?: 0) + 1
        }
        //dprint(a)
        var ans = 0L
        a.forEach {
            ans += if (it.key <= it.value) it.value - it.key else it.value
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 47048
#include<stdio.h>
int main(void){
int k[4][13];
int i,n,r,l;
for(i=0;i<4;i++){
for(n=0;n<13;n++){
k[i][n]=0;
}
}
char c;
scanf("%d",&l);
for(i=0;i<l;i++){
scanf("%c",&c);
scanf("%c %d",&c,&r);
if(c=='S'){k[0][r-1]=1;}
else if(c=='H'){k[1][r-1]=1;}
else if(c=='C'){k[2][r-1]=1;}
else if(c=='D'){k[3][r-1]=1;}
}
for(i=0;i<4;i++){
for(n=0;n<13;n++){
if(k[i][n]!=1){
if(i==0){printf("S %d\n",n+1);}
else if(i==1){printf("H %d\n",n+1);}
else if(i==2){printf("C %d\n",n+1);}
else if(i==3){printf("D %d\n",n+1);}
}
}
}
return 0;
}

Measured memory_bytes: 596
import sys
import math

###input
N,D = map(int, input().split())
X = []
for i in range(N):
  X.append(list(map(int, input().split())))

###solve
count = 0
for i in range(N):
  for j in range(i+1, N):
    sum = 0.0
    for (a, b) in zip(X[i], X[j]):
      sum += pow(abs(a-b),2)
    if math.sqrt(sum).is_integer() : count+=1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int x;
	cin >> x;
	int n = 0;
	int y = x;
	while (y > 0) {
		n += y % 10;
		y /= 10;
	}
	if (x%n == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

//CODE
void solve(void)
{
  int H,W;
  cin>>H>>W;
  vector<vector<char> > data(H,vector<char>(W));
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin>>data[i][j];
    }
    
  }
  bool check = 1;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      
      char X = data[i][j];
      if(X == '#')
      {
      bool check_i = 0;
      if(i != 0) if(data[i-1][j] == X) check_i = 1;
      if(i != H-1) if(data[i+1][j] == X) check_i = 1;
      if(j != 0) if(data[i][j-1] == X) check_i = 1;
      if(j != W-1) if(data[i][j+1] == X) check_i = 1;
      if(check_i == false)check = false;
      }
    }
    
  }
  cout<<(check?"Yes":"No")<<endl;
  
  
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void func(int* p, int* b, int x){
    int y = x;
    *(p+x) += 1;
    *(b+x) = (*(p+x)) % 2;
    if(y != 1){
        *(p+1) += 1;
        *(b+1) = (*(p+1)) % 2;
    }
    if(x % 2 == 0 && y != 2){
        *(p+2) += 1;
        *(b+2) = (*(p+2)) % 2;
        while(x % 2 == 0){
            x = x/2;
        }
    }
    for(int i=3; i*i<=x; i+=2){
        if(x % i == 0){
            *(p+i) += 1;
            *(b+i) = (*(p+i)) % 2;
            while(x % i == 0){
                x = x/i;
            }
        }
    }
    if(x != 1 && x != y){
        *(p+x) += 1;
        *(b+x) = (*(p+x)) % 2;
    }
}

int main(){
    int n, m = 0;
    scanf("%d", &n);
    int a[n+1], b[n+1];
    int sum[n+1];
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        sum[i] = 0;
        b[i] = 0;
    }
    for(int i=n; i>=1; i--){
        int cnt = 0;
        for(int j=i*2; j<=n; j += i){
            if(b[j]){
                cnt++;
            }
        }
        if(cnt%2 != a[i]){
            m++;
            b[i] = 1;
        }
        sum[i] = cnt + b[i];
    }
    int f = 1;
    for(int i=1; i<=n; i++){
        if(sum[i] % 2 != a[i]){
            f = 0;
        }
    }
    if(f){
        printf("%d\n", m);
        for(int i=1; i<=n; i++){
            if(b[i]){
                printf("%d ", i);
            }
        }
    }else{
        printf("-1");
    }

    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int S,W;
    cin>>S>>W;
    if(W>=S){
        cout<<"unsafe\n";
    }
    else{
        cout<<"safe";
    }
    
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

ll visited[100001];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vector<ii> v[n+1];
    for(int i=1;i<n;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        v[a].pb(mp(c,b));
        v[b].pb(mp(c,a));
    }
    int q,k;
    cin>>q>>k;

    for(int i=1;i<=n;i++){
        visited[i]=inf;
    }

    priority_queue<ii,vector<ii>,greater<ii>> pq;

    pq.push({0,k});
    visited[k]=0;

    while(!pq.empty()){
        ll u=pq.top().se;
        ll d=pq.top().fi;
        pq.pop();
        for(int i=0;i<v[u].size();i++){
            if(v[u][i].fi+d<visited[v[u][i].se]){
                pq.push({v[u][i].fi+d,v[u][i].se});
                visited[v[u][i].se]=v[u][i].fi+d;
            }
        }
    }

    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        cout<<visited[x]+visited[y]<<endl;

    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; cin >> x; return x;}

int bin[26];
int t[110][110];

int main2() {
  int H = nextInt();
  int W = nextInt();
  memset(bin, 0, sizeof(bin));
  memset(t, -1, sizeof(t));

  REP(i, H) {
    string s; cin >> s;
    REP(j, W) bin[s[j]-'a']++;
  }

  int Q = 0;
  REP(i, H) REP(j, W) {
    if (t[i][j] == -1) {
      t[i][j] = Q;
      t[H-1-i][j] = Q;
      t[i][W-1-j] = Q;
      t[H-1-i][W-1-j] = Q;
      Q++;
    }
  }

  vector<int> need(5);
  {
    map<int,int> counter;
    REP(i, H) REP(j, W) {
      counter[ t[i][j] ] += 1;
    }
    for (auto it = counter.begin(); it != counter.end(); ++it) {
      need[it->second]++;
    }
  }
  bool ans = true;

  vector<int> have;
  for (int i = 0; i < 26; i++){
    int x = bin[i];
    while (need[4] > 0 && x >= 4) {
      x -= 4;
      need[4]--;
    }
    if (x > 0) have.push_back(x);
  }
  if (need[4] > 0) ans = false;

  // pv(ALL(need));
  // pv(ALL(have));
  for (int i = 0; i < (int)have.size(); i++) {
    while (need[3] > 0 && have[i] >= 3) {
      need[3]--;
      have[i] -= 3;
    }
  }
  for (int i = 0; i < (int)have.size(); i++) {
    while (need[2] > 0 && have[i] >= 2) {
      need[2]--;
      have[i] -= 2;
    }
  }
  for (int i = 0; i < (int)have.size(); i++) {
    while (need[1] > 0 && have[i] >= 1) {
      need[1]--;
      have[i] -= 1;
    }
  }

  if (need[1] + need[2] + need[3] + need[4] > 0) ans = false;

  
  
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 384
import numpy as np
n = int(input())
ans =0
for i in range(1,n+1):  
    if(i%2==0):
        continue
    count=0
    for j in range(1,i+1):
        if(i%j == 0):
            count += 1
    if(count == 8):
            ans+=1
print(ans)



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // buiding
    int building[4][3][10] = {};

    //入力
    int n;
    cin >> n;
    vector<int> b(n, 0), f(n, 0), r(n, 0), v(n, 0);
    rep(i, n) { cin >> b[i] >> f[i] >> r[i] >> v[i]; }

    //処理
    rep(i, n) { building[b[i] - 1][f[i] - 1][r[i] - 1] += v[i]; }

    //出力
    rep(u, 4) {
        rep(i, 3) {
            rep(j, 10) { cout << " " << building[u][i][j]; }
            cout << "\n";
        }
        (u == 3) ? cout << "" : cout << "####################" << endl;
    }

    return 0;
}



Measured memory_bytes: 3056
h, w = list(map(int, input().split()))

s = [list(input()) for _ in range(h)]

flag = True

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sub_flag = False
            if i > 0 and s[i-1][j] == "#":
                sub_flag = True
            if j > 0 and s[i][j-1] == "#":
                sub_flag = True
            if i < h-1 and s[i+1][j] == "#":
                sub_flag = True
            if j < w-1 and s[i][j+1] == "#":
                sub_flag = True

            if sub_flag:
                pass
            else:
                flag = False
                break

if flag:
    print("Yes")
else:
    print("No")

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

int main() {
    int n;
    cin >> n;
    long long result = 0, sum = 0;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        if (a == 0) {
            result += sum / 2;
            sum = 0;
        } else {
            sum += a;
        }
    }
    result += sum / 2;
    cout << result;
    return 0;
}

Measured memory_bytes: 256
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n;
	vector<int> v1(n),v2(n);
	for(int i = 0;i < n;i++){
		cin >> v1[i] >> v2[i];
	}
	sort(all(v1));
	sort(all(v2));
	if(n&1){
		cout << (v2[n/2] - v1[n/2] + 1);
	}else{
		int x1 = v1[(n - 1)/2];
		int y1 = v2[(n - 1)/2];
		int x2 = v1[n/2];
		int y2 = v2[n/2];
		long double ans = ((long double)(y1 + y2) - (x1 + x2) + 1);
		cout << ((int)ans);
	}
}
//.........

Measured memory_bytes: 6340
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let pi = 4. *. atan 1.

let degree_to_radian d = (pi *. d /. 180.)

let area a b c = a *. b *. sin c /. 2.

let side_length a b c = sqrt (a *. a +. b *. b -. 2. *. a *. b *. cos c)

let () =
  let l = read_line () in
  match List.map float_of_string (split l ' ') with
  | [] | [_] | _::_::[] -> exit 1
  | a :: b :: c :: _ ->
      let c = degree_to_radian c in
      let s = area a b c in
      let l = a +. b +. side_length a b c in
      let h = b *. sin c in
      Printf.printf "%f\n%f\n%f\n" s l h

Measured memory_bytes: 2576
from itertools import combinations_with_replacement
from collections import Counter

N = int(input())
ans = [0] * (N+1)
for x in combinations_with_replacement(range(1,99),3):
    temp = x[0] ** 2 + x[1] ** 2 + x[2] ** 2 + x[0] * x[1] + x[1] * x[2] + x[2] * x[0]
    if temp <= N:
        tc = Counter(x)
        if len(tc) == 1:
            ans[temp] += 1
        elif len(tc) == 2:
            ans[temp] += 3
        else:
            ans[temp] += 6
for x in ans[1:]:
    print(x)

Measured memory_bytes: 70828
fun main(args: Array<String>) {
    val a = readLine()!!.split(" ").map(String::toInt)
    println(op143a(a))
}

fun op143a(a: List<Int>): Int {
    val result = a[0] - a[1] * 2
    return if (result > 0 ) result else 0
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int H, W, N;
int globalIdx = 0;
int a[10010];
int B[109][109];

void init() {
   rep (i, H) {
      rep (j, W) {
         B[i][j] = -1;
      }
   }
}

void dfs(int y, int x) {
   rep (i, 4) {
      int py = y + dy[i], px = x + dx[i];
      if (py < 0 || py >= H || px < 0 || px >= W || B[py][px] != -1) continue;
      int ny = y, nx = x;
      while (1) {
         ny += dy[i], nx += dx[i];
         if (ny<0 || ny>=H || nx<0 || nx>=W || B[ny][nx]!=-1) break;
         B[ny][nx] = a[globalIdx];
         globalIdx++;
      }
      dfs(ny-dy[i], nx-dx[i]);
   }
}

int main() {
   cin >> H >> W >> N;
   // init();
   int idx = 0;
   rep (i, N) {
      int x;
      cin >> x;
      rep (j, x) {
         a[idx] = i+1;
         idx++;
      }
   }

   idx = 0;
   for (int i = 0; i < H; i++) {
      if (i%2==0) {
         for (int j = 0; j < W; j++) {
            debug3(i, j, a[idx])
            B[i][j] = a[idx];
            idx++;
         }
      } else {
         for (int j = W-1; j >= 0; j--) {
            debug3(i, j, a[idx])
            B[i][j] = a[idx];
            idx++;
         }
      }
   }
   
   // B[0][0] = a[0];
   // globalIdx++;
   // dfs(0, 0);
   rep (i, H) {
      rep (j, W-1) {
         cout << B[i][j] << " ";
      }
      cout << B[i][W-1] << endl;
   }

   return 0;
}

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

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

const int INF = 100100100;

int main() {
  int h, n;
  cin >> h >> n;
  int m = 1e8 + 10;
  vector<int> hs(m, INF);
  vector<P> ab(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab[i] = P(a, b);
  }
  hs[0] = 0;
  for (int i = 0; i <= h; i++) {
    rep(j, n) {
      int a = ab[j].first;
      int b = ab[j].second;
      hs[i + a] = min(hs[i + a], hs[i] + b);
    }
  }

  int ans = INF;
  for (int i = h; i < m; i++) {
    ans = min(hs[i], ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 393988
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[100],b[100];
  cin >> a >> b;
  for(int i=0;i<strlen(a);i++){
    cout << a[i];
    if(b[i]!='\0'){
      cout << b[i];
    }
  }
}


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

int main() {

  int a,b,c,d,e,p,q,x,n,i,y,z;
	cin >>  x>> n;
	d=0;
	e=-1;
	p=0;
	q=0;

vector<int> vec(n);
  for (i = 0; i < n; i++) {
    cin >> vec.at(i);
	}
     while(e < 100) {
	p=0;
	e=e+1;
	i=0;
	y=x-e;
	z=x+e;
	 for (i = 0; i < n; i++) {
 		if(vec.at(i)==y){
		p=1;
		}
		else{
		q=1;
		}
	}

	if(p==0){
		cout << y<< endl;
		 e=e+1000;
	}
	else{
	p=0;
	i=0;
 	for (i = 0; i < n; i++) {
 		if(vec.at(i)==z){
		p=1;
		}
		else{
		q=1;
		}
	}
	if(p==0){
		cout << z<< endl;
	e=e+1000;
		}
	}
		}

}

Measured memory_bytes: 3640
#include <stdio.h>

int r[200000];

int calc_Max_difference(int r[], int n) {
  int rmin = r[0];
  int max = r[1] - r[0], i;

  for (i = 1; i < n; i++) {
    max = (max > r[i] - rmin ? max : r[i] - rmin);
    rmin = (rmin < r[i] ? rmin : r[i]);
  }
  return max;
}

int main(void) {
  int n, i, j, ans;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &r[i]);

  ans = calc_Max_difference(r, n);

  printf("%d\n", ans);

  return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;

const ll MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> v(n);
    for (int& e : v) cin >> e;

    ll res = 1;
    map<int, int> cnt;
    cnt[-1] = 3;
    for (const int e : v) {
        (res *= cnt[e - 1] - cnt[e]) %= MOD;
        cnt[e]++;
    }

    cout << res << '\n';
}

Measured memory_bytes: 5376
A,B,K=map(int,input().split())
i=0
while i<K:
    if i%2:
        B=B//2*2
        A,B=A+B//2,B//2
    else:
        A=A//2*2
        A,B=A//2,B+A//2
    i+=1
print(A,B)

Measured memory_bytes: 9096
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

signed main(void)
{
	string s[10];
	s[1] = ".,!? ";
	s[2] = "abc";
	s[3] = "def";
	s[4] = "ghi";
	s[5] = "jkl";
	s[6] = "mno";
	s[7] = "pqrs";
	s[8] = "tuv";
	s[9] = "wxyz";
	int t;
	cin >> t;
	rep(i, t) {
		string res;
		string message;
		cin >> message;
		char now;
		rep(i, message.size()) {
			now = message[i];
			if (now == '0') continue;
			int cnt = 0;
			REP(j, i + 1, message.size()) {
				if (message[j] != now) {
					cnt = j - i;
					break;
				}
			}
			i += cnt;
			res += s[now - '0'][(cnt - 1) % s[now - '0'].size()];
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
n = gets.to_i
a = gets.split.map(&:to_i)
k = a.max
b = []
c = Array.new(k + 1, 0)

for j in 0..n-1
    c[a[j]] += 1
end

for i in 1..k
    c[i] = c[i] + c[i - 1]
end

for j in -n+1..0
    b[c[a[-j]] - 1] = a[-j]
    c[a[-j]] -= 1
end

puts b.join(" ")


Measured memory_bytes: 152060
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin>>n;
    map<int,int> mp;
    int mx=0;
    forn(i,n){
        int x;
        cin>>x;
        mp[x]++,mp[x-1]++,mp[x+1]++;
        mx=max(mx,max(mp[x+1],max(mp[x],mp[x-1])));
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 7928
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> sc(n,-1);
    rep(i,m){
        ll s,c; cin >> s >> c;
        if(sc.at(s-1) == -1){
            sc.at(s-1) = c;
        }else{
            if(sc.at(s-1)!=c){
                cout << -1 << endl;
                return 0;
            }
        }
    }

    for(int i=0;i<1000;i++){
        string a = to_string(i);
        if((ll)a.size()!=n) continue;
        rep(j,n){
            if(sc.at(j)==-1) continue;
            if(sc.at(j) != (ll)(a.at(j) - '0')){
              goto aaa;
            }
        }
        cout << i << endl;
        return 0;
        aaa:;
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  int q;
  cin>>q;
  vector<int>t(q,0);
  vector<int>f(q,0);
  vector<char>c(q,0);
  int count=0;
  bool rev=false;
  for(int i=0;i<q;i++){
    cin>>t.at(i);
    if(t.at(i)==2){
      cin>>f.at(i)>>c.at(i);
    }
  }
  for(int i=0;i<q;i++){
    if(rev==false){
      if(t.at(i)==1){
        rev=true;
      }else{
        if(f.at(i)==1){
          s.insert(s.begin(),c.at(i));
        }else{
          s.push_back(c.at(i));
        }
      }
    }else{
      if(t.at(i)==1){
        rev=false;
      }else{
        if(f.at(i)==2){
          s.insert(s.begin(),c.at(i));
        }else{
          s.push_back(c.at(i));
        }
      }
    }
  }
  if(rev==true){
    reverse(s.begin(),s.end());
  }

  for(int i=0;i<s.size();i++)
    cout<<s.at(i);
}

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

const int N=1010;
struct Edge{int to,next;} e[N<<1];
int h[N],sum=0,n;
int g[2][5010],k=0;
int w[N],X[N];

void add_edge(int u,int v)
{
	e[++sum].to=v;
	e[sum].next=h[u];
	h[u]=sum;
}

void mem(int k){memset(g[k],0x3f,sizeof(g[k]));}
inline void upmin(int &x,const int &y){if(y<x) x=y;}

bool dfs(int u)
{
	for(int tmp=h[u];tmp;tmp=e[tmp].next)
		if(!dfs(e[tmp].to)) return 0;
	k=1;mem(k);g[k][0]=0;
	for(int tmp=h[u];tmp;tmp=e[tmp].next)
	{
		k^=1;mem(k);int v=e[tmp].to;
		for(int i=0;i<=X[u];i++)
		{
			if(i>=X[v]) upmin(g[k][i],g[k^1][i-X[v]]+w[v]);
			if(i>=w[v]) upmin(g[k][i],g[k^1][i-w[v]]+X[v]);
		}
	}
	int res=0x3f3f3f3f;
	for(int i=0;i<=X[u];i++)
		upmin(res,g[k][i]);
	if(res==0x3f3f3f3f) return 0;
	w[u]=res;return 1; 
}

int main()
{
	int fa;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&fa);
		add_edge(fa,i);
	}
	for(int i=1;i<=n;i++) scanf("%d",X+i);
	puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define H(x) cout << #x << " " << x << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

int N, M;
vvi adj, rev;

bitset<200000> vis;
vi ord, pos;

void topsort(int u){
    vis[u] = 1;
    for(int v : adj[u]) if(!vis[v]) topsort(v);
    ord.pb(u);
}


signed main(){
    vis.reset();
    cin >> N >> M;
    M += N-1;
    adj.resize(N+2);
    rev.resize(N+2);
    FOR(i, 0, M){
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
        rev[v].pb(u);
    }
    int root = 0;
    while(rev[root].size() != 0) root++;
    pos.resize(N);
    topsort(root);

    FOR(i, 0, N) pos[ord[i]] = i;
    vi par(N);
    par[root] = -1;
    FOR(u, 0, N) {
        ii best = {INF, -1};
        for(int p : rev[u])  {
            best = min (best, {pos[p], p});
        }
        par[u] = best.snd;
    }
    for(int u : par) cout << u + 1 << endl;
}

Measured memory_bytes: 18936
while 1:
	n=input()
	if n==0:break
	p=map(int,raw_input().split())+["end"]
	sp=p[0]
	ans=[]
	for i in range(n):
		if p[i]+1!=p[i+1]:
			if sp!=p[i]:
				ans.append(str(sp)+"-"+str(p[i]))
			else:
				ans.append(str(sp))
			sp=p[i+1]
	print " ".join(ans)

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#include<cmath>
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 long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"YES":"NO")<<endl;}
int main(){
	int n;
	cin >>n;
	vector<int>a;
	int bef;
	int aa=0;
	long long ans=0;
	for(int i=0;i<n;i++){
		cin>>bef;
		a.push_back(bef);
	}
	sort(a.begin(),a.end(),greater<int>());
	
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			
			if(aa==0){
				aa=a[i];
				i++;
			}else{
				ans=aa*(long long)a[i];
				break;
			}
		}
	}
	cout <<ans<<endl;

	
}

Measured memory_bytes: 1020
odd_step=["R","U","D"]
even_step=["L","U","D"]

s=input()

ans="Yes"
for i in range(len(s)):
  if i%2 != 0:
    if not s[i] in even_step:
      ans="No"
  else:
    if not s[i] in odd_step:
      ans="No"
print(ans)

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

int main(){
    const long long mod=1e9+7;
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++) cin >> a[i] ;
    long long ans=0;
    vector<long long> count0(61);
    vector<long long> count1(61);
    for(int i=0;i<n;i++){
        for(int j=0;j<61;j++){
            if(a[i]&1ll<<j) count1[j]++;
            else count0[j]++;
        }
    }
    long long kani=1;
    for(int i=0;i<61;i++){
        long long temp=((count0[i]*count1[i])%mod*kani)%mod;
        ans=(ans+temp)%mod;
        kani=(kani*2)%mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5544
#include <iostream>
#include <algorithm>
#include <map>
#include <string>

int main()
{
    std::map<std::string, int> result;

    int num;
    std::cin >> num;
    for(int i = 0; i < num; i++)
    {
        std::string c;
        std::cin >> c;
        std::sort(c.begin(), c.end());
        auto it = result.find(c);
        if(it != result.end())
        {
            it->second++;
        }
        else
        {
            result.insert(std::make_pair(c, 0));
        }
    }

    long sum = 0;
    for(auto& each : result)
    {
        for(int i = 1; i <= each.second; i++)
        {
            sum += i;
        }
    }
    std::cout << sum << std::endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,x,y;
    cin >> n >> x >> y;
    x--;y--;
    vector<vector<int>> d(n, vector<int>(n));
    rep(i,n) rep(j,n) d[i][j] = abs(i-j);
    d[x][y] = d[y][x] = 1;
    rep(i,n) rep(j,n) {
        chmin(d[i][j], d[i][x] +d[x][y] + d[y][j]);
        chmin(d[i][j], d[i][y] +d[y][x] + d[x][j]);
    }
    vector<int> d_k(n-1,0);
    rep(i,n) for(int j = i+1; j < n; j++) d_k[d[i][j]-1]++;
    rep(i,n-1) cout << d_k[i] << endl;
}

Measured memory_bytes: 16000