akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9 + 7)

int element_count(int n){
	n = (0x55555555 & n) + (0x55555555 & (n >> 1));
	n = (0x33333333 & n) + (0x33333333 & (n >> 2));
	n = (0x0f0f0f0f & n) + (0x0f0f0f0f & (n >> 4));
	n = (0x00ff00ff & n) + (0x00ff00ff & (n >> 8));
	n = (0x0000ffff & n) + (0x0000ffff & (n >> 16));
	return n;
}

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, i, j, Fj, sum, ans = -inf;
	scanf("%d", &N);
	int *F = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		F[i] = 0;
		for(j = 0; j < 10; j++){
			scanf("%d", &Fj);
			if(Fj == 1){
				F[i] |= (1 << j);
			}
		}
	}
	int **P = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		P[i] = (int *)malloc(sizeof(int) * 11);
		for(j = 0; j <= 10; j++){
			scanf("%d", &P[i][j]);
		}
	}
	for(i = 1; i < (1 << 10); i++){
		sum = 0;
		for(j = 0; j < N; j++){
//			printf("element_count(%d & F[%d]) = %d\n", i, j, element_count(i & F[j]));
			sum += P[j][element_count(i & F[j])];
		}
		ans = max(ans, sum);
//		printf("i = %d: ans = %d\n", i, ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {
	int H,W,N,sy,sx;
	char[][] field;
	int[] dy = {0,0,-1,1};
	int[] dx = {1,-1,0,0};
	public void solve() {
		H = nextInt();
		W = nextInt();
		N = nextInt();
		field = new char[H][];
		for(int i = 0;i < H;i++){
			field[i] = next().toCharArray();
			for(int j = 0;j < W;j++){
				if(field[i][j] == 'S'){
					sy = i;
					sx = j;
				}
			}
		}
		int ans = 0;
		for(int i = 1;i <= N;i++){
			Queue<int[]> q = new ArrayDeque<int[]>();
			boolean[][] used = new boolean[H][W];
			q.add(new int[]{sy,sx,0});
			while(q.size() > 0){

				int[] point = q.poll();

				int y = point[0];
				int x = point[1];
				int d = point[2];

				if(field[y][x] == ('0' + i)){
					sy = y;
					sx = x;
					ans += d;
					break;
				}
				if(used[y][x])continue;
				used[y][x] = true;
				for(int j = 0;j < 4;j++){
					int ny = dy[j] + y;
					int nx = dx[j] + x;

					if(ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
					if(field[ny][nx] == 'X')continue;
					q.add(new int[]{ny,nx,d + 1});
				}
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 97724
/*#include<cstdio>
#include<iostream>
using namespace std;

bool judge(int x){
    int ans3 = 0,ans5 = 0,ans7 = 0,num=0;
    do{
       if(x % 10 == 3) ans3++;
       if(x % 10 == 5) ans5++;
       if(x % 10 == 7) ans7++;
       num++;
       x = x/10;

    }while(x != 0);
    if(ans3 > 0 && ans5 > 0 && ans7 > 0 && ans3+ans5+ans7 == num){
        return true;
    }else{
        return false;
    }
}

int main(){
    int t;
    cin>>t;
    int ans = 0;
    for(int i = 1;i <= t;){
        if(judge(i)){
            ans++;
            i+=18;
        }else{
            i++;
        }
    }
    cout<<ans;
}
*/
#include<cstdio>
int count = 0;
int t;

void DFS(long long x,bool three,bool five,bool seven){
    if(x <= t){
        if(three && five && seven) count++;
    DFS(x*10+3,true,five,seven);
    DFS(x*10+5,three,true,seven);
    DFS(x*10+7,three,five,true);
    }

}

int main(){
    scanf("%d",&t);
    DFS(0,false,false,false);
    printf("%d",count);
}

























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

int main(){
    int a, b;
    char op;
    int o;
    vector<int> out;

    while (true)
    {
        cin >> a >> op >> b;
        if(op == '?') break;
        else if(op == '+'){
            o = a+b;
            out.push_back(o);
        }
        else if(op == '-'){
           o = a-b;
           out.push_back(o); 
        } 
        else if(op == '*'){
            o = a*b;
            out.push_back(o);
        }
        else if(op == '/'){
            o = a/b;
            out.push_back(o);
        }
    }
    for (int i = 0; i < out.size(); i++)
    {
        cout << out.at(i) << endl;
    }
    
}


Measured memory_bytes: 3156
#include<stdio.h>
int main(){
  int a, b, c;
  scanf("%d%d",&a,&b);
  while(1){
    c = a % b;

    if(c == 0){
      break;
    }
    else {
      a = b;
      b = c;
  }
  }
  printf("%d\n",b);
  return 0;
}

Measured memory_bytes: 592
#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;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<ii> v;
    vector<ii> c;
    c.pb({0,0});
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        v.pb({x,y});
    }
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        c.pb({x,y});
    }
    for(int i=0;i<n;i++){
        ll d=abs(c[1].fi-v[i].fi)+abs(c[1].se-v[i].se),index=1;
        for(int j=2;j<=m;j++){
            ll k=abs(c[j].fi-v[i].fi)+abs(c[j].se-v[i].se);
            if(k<d){
                index=j;
                d=k;
            }
        }
        cout<<index<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
const ll modP = 1000000007;


int main()
{
	int n;
	cin>>n;
	vector<ll> A(n);
	rep(i,n) cin>>A[i];
	vector<ll> x(n+1,0);
	vector<ll> y(n+1,0);
	vector<ll> z(n+1,0);
	for(int i = 0; i < n; i++){
		x[i+1] = x[i];
		y[i+1] = y[i];
		z[i+1] = z[i];
		if( A[i] == x[i]){
			x[i+1]++;
		}else if(A[i] == y[i]){
			y[i+1]++;
		}else{
			z[i+1]++;
		}
	}
	ll ans = 1;
	for(int i = 0; i < n; i++){
		int t = 0;
		if( x[i] == A[i]) t++;
		if( y[i] == A[i]) t++;
		if( z[i] == A[i]) t++;
		ans = (ans * t) % modP;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5912
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    long long a,b,c;
    cin >> a >> b >> c;
    long long tempA=a,tempB=b,tempC=c;
    int count=0;
    if(a==b && a==c & b==c && a%2==0){
        cout << -1 <<endl;
    }else{
        while(true){
        if(tempA%2!=0 || tempB%2!=0 || tempC%2!=0){
            break;
        }else{
            tempA = b/2 + c/2;
            tempB = a/2 + c/2;
            tempC = a/2 + b/2;
            a = tempA;
            b = tempB;
            c = tempC;
            count++;
        }
    }
    cout << count <<endl;
    }  
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(){
	int m,f,r,i;
	char x;
	for(i=1;i<=50;i++){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1 && f==-1 && r==-1)break;
		x=m+f;
		if(x>=80){x='A';
			}else if(x<80 && x>=65){
				x='B';
			}else if(x<65 && x>=50){
				x='C';
			}else if(x<50 && x>=30){
				x='D';
				if(r>=50)
				x='C';
			}else{
				x='F';
			}
		if(m==-1 || f==-1)x='F';
		printf("%c\n",x);
	}
return 0;
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int mod = 1e9+7;
const int inf = 1e8;
int g[22][22];
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        g[x][y] = g[y][x] = 1;
    }
    int ans = 0;
    int a[12];
    for(int i=0;i<n;i++)a[i] = i+1;
    do{
        if(a[0]!=1)break;
        int cnt = 1;
        for(int i=1;i<n;i++){
            if(g[a[i]][a[i-1]]==0)cnt = 0;
        }
        ans+=cnt;
    }while(next_permutation(a,a+n));
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
N,X=map(int,input().split())
D=[]
num=0
for i in range(N):
    m=int(input())
    D.append(m)
    X-=m
    if X<min(D):
        print(N)
        exit()
while X>=min(D):
    X-=min(D)
    num+=1
    if X<min(D):
        print(N+num)
        exit()


Measured memory_bytes: 9028
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  int a,b,c,k=0;
  cin>>a>>b>>c;
  if ((a != b) and (a != c))
    k=a;
  else
    if ((b != a) and (b != c))
      k=b;
      else
        k=c;
  cout<<k;
  system ("pause");
  return 0;
  }

Measured memory_bytes: 504
a, b = list(map(int, input().split()))
s = input()

sl = s.split('-')
if len(sl) != 2:
    print('No')
elif ( sl[0].isdecimal() and len(sl[0]) == a ) and ( sl[1].isdecimal() and len(sl[1]) == b):
   print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

int main(){
    int N,x;
    int A[100000];
    cin>>N>>x;
    int64_t tot=0;
    int64_t res=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        tot+=A[i];
        if(A[i]>x){
            res += A[i]-x;
            A[i]=x;
        }
    }
    if(x==0){
        cout<<tot<<endl;
    }else{
        for(int i=0;i<N-1;i++){
            if(A[i] !=0 && A[i+1] != 0){
                if(A[i]+A[i+1] > x){
                    res += A[i]+A[i+1]-x;
                    A[i+1]=x-A[i];
                }
            }
        }
        cout<<res<<endl;
    }
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 640
N = int(input())
temp = [0, 0, 0, 0]
for i in range(N):
    s = input()
    if s == "AC":
        temp[0] += 1
    elif s == "WA":
        temp[1] += 1
    elif s == "TLE":
        temp[2] += 1
    else:
        temp[3] += 1

print("AC x", temp[0])
print("WA x", temp[1])
print("TLE x", temp[2])
print("RE x", temp[3])

Measured memory_bytes: 9204
n = int(input())
A = list(map(int, input().split()))
m = min(A)
M = max(A)
if M - m > 1:
  print("No")
elif M - m == 0:
  if 1 <= M <= n//2 or m == n-1:
    print("Yes")
  else:
    print("No")
else:
  k = A.count(m)
  if 1 <= M-k <= (n-k)//2:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 13964
#include<stdio.h>

 
int main(){
	int h,w,i,j,k,tate;
	char snake[5],yoko;
	scanf("%d %d",&h,&w);
	getchar();
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			for(k=0;k<5;k++){
			scanf("%c",&snake[k]);
			}
			if(snake[0]=='s' && snake[1]=='n' && snake[2]=='u' && snake[3]=='k' && snake[4]=='e'){
				yoko='A'+('B'-'A')*j;
				tate=i+1;
			}
			getchar();
		}
	}
	printf("%c%d\n",yoko,tate);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n, k;
    cin>>n>>k;
    vi v(n);
    for(int i = 0; i < n; i++)cin>>v[i];
    for(int i = k; i < n; i++){
        if(v[i-k]<v[i])cout<<"Yes\n";
        else cout<<"No\n";
    }   
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 4776
n = int(input())
A = [int(input()) for _ in range(n)]

B = []
import bisect
for i, a in enumerate(A):
    if len(B) == 0:
        B.append(-a)
    else:
        j = bisect.bisect_right(B, -a)
        #print(j)
        if j == len(B):
            B.append(-a)
        elif j == 0:
            B[0] = -a
        else:
            B[j] = -a
    #print(B)
#print(B)
print(len(B))


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

using namespace std;





int main()
{

 int n,a,b;



  scanf("%d%d%d",&n,&a,&b);

  int k = n-2;

  int it = b-a;
  if( it < 0)
  {
      printf("%d",0);
  }
    else  if(it ==0)
    {
       printf("%d",1);

    }
    else
    {
        if(n == 1)
                printf("%d",0);
        else
        {


    printf("%ld",  (long long) k*(b-a)+1 );

        }


    }
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

const int MAX_V = 110;

// 辺を表す構造体（行き先、容量、逆辺の場所）
struct edge{
    int to, cap, rev;
};

vector<vector<edge>> G(MAX_V); 
int level[MAX_V]; // sからの距離
int iter[MAX_V];  // どこまで調べ終わったか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap){
    G[from].eb((edge){to, cap, (int)G[to].size()});
    G[to].eb((edge){from, 0, (int)(G[from].size()-1)});
}

// sからの最短距離を計算する
void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);

    while(que.size()){
        int v = que.front(); que.pop();
        for(int i=0; i<G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

// 増加パスを探す
int dfs(int v, int t, int f){
    if(v == t) return f;
    for(int &i=iter[v]; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }

    return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, 1e9)) > 0){
            flow += f;
        }
    }
}

int main(){
    int v, e; cin>>v>>e;
    for(int i=0; i<e; i++){
        int s, t, c; cin>>s>>t>>c;
        add_edge(s, t, c);
    }

    cout << max_flow(0, v - 1) << endl;
}


Measured memory_bytes: 3188
#include<stdio.h>
long long int gcd(long long int a, long long int b)
{
	 return a%b == 0 ? b: gcd(b, a%b);
}
long long int lcm(long long int a, long long int b)   
{
	return a/gcd(a, b)*b;
}
int main()
{
	long long int n, z[101];
	while (scanf("%lld", &n) != EOF)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &z[i]);
		}
		long long int lcmn=1;
		for (int i = 0; i < n; i++)
		{
			lcmn = lcm(z[i], lcmn);
		}
		printf("%lld\n", lcmn);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;


int main() {
	int x;
	cin >> x;
	if (x==7||x==5||x==3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[,] dp = new int[n, n];
                int max = 0;

                string input = Console.ReadLine();

                for (int j = 0; j < n; j++)
                {
                    dp[0, j] = input[j] == '.' ? 1 : 0;
                }

                for (int i = 1; i < n; i++)
                {
                    input = Console.ReadLine();

                    for (int j = 0; j < n; j++)
                    {
                        if (input[j] == '.')
                        {
                            dp[i, j] = 1;

                            if (j == 0) continue;

                            dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]);
                            dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j - 1]) + 1;
                            max = Math.Max(max, dp[i, j]);
                        }
                    }
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 20928
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
int a[100010];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*int n, m;
	for (int i = 0; i < n; i++) cin >> a[i];
	int a, b;
	while (m--)
	{
		cin >> a >> b;

	}*/
	int b[1000] = { 0 };
	int n, k;
	int ans = 0;
	cin >> n >> k;
	int s;
	int w;
	while (k--)
	{
		cin >> s;
		while (s--)
		{
			cin >> w;
			b[w]++;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (b[i] == 0) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3596
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	string res;
	int N, A, B; cin >> N >> A >> B;

	res = ((B - A) % 2 == 0) ? "Alice" : "Borys";

	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String m = sc.next();
        int cnt = 0;
        for(int i = 0;i < m.length();i++){
            if(m.charAt(i) == '1')
            cnt++;
        }
        System.out.println(cnt);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    map<char,bool> mp;
    for(auto e:S){
        mp[e] = true;
    }
    if(mp['a']&&mp['b']&&mp['c']){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int32_t main(){
	string s;
	int k;
	cin>>s>>k;
	int st=0,fn=0,md=0;
	int n = s.length();
	for(int i=0;s[i]==s[0];i++){
		st++;
	}
	for(int i=n-1;s[i]==s[0];i--){
		fn++;
	}
	for(int i=st+1;i<n;i++){
		if(s[i-1]==s[i]){
			md++;
			i++;
		}
	}
	//cout<<st<<" "<<fn<<" "<<md<<"\n";
	if(st==n){
		cout<<(n*k)/2;
		return 0;
	}
	if(k==1){
		cout<<st/2 + md;
		return 0;
	}
	if(s[0]!=s[n-1]){
		cout<<(st/2 + md)*k;
	}
	else {
		cout<<(st/2 + ((st+fn)/2)*(k-1) + (md-fn/2)*k + fn/2 );
	}
}


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

using namespace std;

const int N = 5e5 + 5;

int n, a[N];

int main(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 != 0 && a[i] % 5 != 0) {
                ok = false;
                break;
            }
        }
    }
    
    if (ok) cout << "APPROVED";
    else cout << "DENIED";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int y, m, d, date;
	
	while (scanf("%d%d%d", &y, &m, &d) != EOF){
		date = y * 10000 + m * 100 + d;
		
		if (date >= 19890108){
			printf("heisei %d %d %d\n", y - 1988, m, d);
		}
		else if (date >= 19261225){
			printf("showa %d %d %d\n", y - 1925, m, d);
		}
		else if (date >= 19120730){
			printf("taisho %d %d %d\n", y - 1911, m, d);
		}
		else if ( date >= 18680908){
			printf("meiji %d %d %d\n", y - 1867, m, d);
		}
		else {
			printf("pre-meiji\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 608
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 18;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {


	int N = getint();
	int D[100001] = {};
	rep(i, N) (*(D + getint()))++;
	int S = 0;
	int kotae = 0;
	for (int i = 100000; i > 0; i--) {
		S += *(D + i);
		if (S >= N / 2) {
			if (S == N / 2) {
				i--;
				kotae++;
				while (!D[i]) {
					kotae++;
					i--;
				}
			}
			break;
		}
	}
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 768
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e6+5;


int main()
{ 

  IOS;

ll n;cin>>n;

vl a(4);

for(int i=1;i<=n;i++){
  string s;cin>>s;
  if(s[0]=='A'){
    a[0]++;

  }
  else if(s[0]=='T')a[1]++;
  else if(s[0]=='W')a[2]++;
  else a[3]++;
}


cout<<"AC x "<<a[0]<<endl;


cout<<"WA x "<<a[2]<<endl;



cout<<"TLE x "<<a[1]<<endl;



cout<<"RE x "<<a[3]<<endl;


return 0;
 
}



Measured memory_bytes: 3644
'use strict';

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

var onNumber = (function() {
  var readingInput = false;
  var n;
  var data;

  return function(i) {
    if (!readingInput) {
      n = i;
      data = [];
      readingInput = true;
      return;
    }
    data.push(i);
    n--;
    if (n === 0) {
      onDataSet(data);
      readingInput = false;
    }
  };
})();

rl.on('line', function(line) {
  onNumber(Number(line.trim()));
});

function onDataSet(array) {
  console.log(maxContiguousSubarraySum(array));
}

function maxContiguousSubarraySum(array) {
  var max = -Infinity;
  var sum = 0;

  for (var i = 0; i < array.length; i++) {
    sum += array[i];
    if (sum > max) {
      max = sum;
    }
    if (sum < 0) {
      sum = 0;
    }
  }

  return max;
}

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

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

void solve(long long n, long long m)
{
    cout << (n - 1) * (m - 1) << endl;
}

int main()
{
    long long n;
    scanf("%lld", &n);
    long long m;
    scanf("%lld", &m);
    solve(n, m);
    return 0;
}


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

#define MOD (998244353)
#define N (300)

using namespace std;

int x[N],y[N],p[N];

inline long long myPow(long long a,long long b)
{
    long long c = 1;

    for(;b > 0;b >>=1,a = a * a % MOD)
	if(b & 1)
	    c = c * a % MOD;

    return c;
}

inline bool det(int i,int j,int l)
{
    return (x[l]-x[j])*(y[j] - y[i]) - (x[j] - x[i])*(y[l]-y[j]) == 0;
}

int main(void)
{
    int n;
    long long ans = 0;
    
    cin>>n;

    for(int i = 0;i <= n;i++)
    {
	p[i] = myPow(2,i);
    }

    for(int i = 1;i <= n;i++)
    {
	cin>>x[i]>>y[i];
    }

    for(int i = 1;i <= n;i++) {
	for(int j = i+1;j <= n;j++) {
	    int k = 0;
	    for(int l = j+1;l <= n;l++)
		if(det(i,j,l))
		    k++;
	    ans = (ans + p[k]) % MOD;
	}
    }

    ans = (p[n] - ans - n - 1) % MOD;
    
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 1e5+19;
int a[N];
int main(){
    int n, c, k;
    while(~scanf("%d %d %d",&n,&c,&k)){
        for(int i = 0; i < n; i ++) cin >> a[i];
        sort(a,a+n);
        int ans = 1;
        int st = a[0], res = 1;
        for(int i = 1; i < n; i ++){
            if(res < c && a[i] <= st+k){
                res++;
            }
            else{
                ans++;
                st = a[i];
                res = 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
def EuclideanAlgolism(x, y):
   if x<y:
       x, y = y, x
   while y!=1:
        if x%y == 0:
            break
        else:
            x, y = y, x%y
   print(y)

if __name__ == "__main__":
    x, y =  map(int, input().split())
    EuclideanAlgolism(x,y)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string S, string T, long long A, long long B, string U){
	if (S == U) {
		cout << A-1 << " " << B << endl;
	} else {
		cout << A << " " << B-1 << endl;
	}
}

int main(){	
	string T;
	long long B;
	long long A;
	string U;
	string S;
	cin >> S;
	cin >> T;
	scanf("%lld",&A);
	scanf("%lld",&B);
	cin >> U;
	solve(S, T, A, B, U);
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int e;
	while (scanf("%d", &e), e)
	{
		int res = e;

		int z_max = pow(e, 1.0 / 3) + 1;
		int y_max = (int)sqrt(e + 0.0) + 1;
		for (int z = z_max; z >= 0; --z)
		{
			for (int y = y_max; y >= 0; --y)
			{
				int x = e - (z*z*z + y*y);
				if (x >= 0)
					min_swap(res, x + y + z);
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 892
S = list(input())
S.reverse()
S = ''.join(S)
st = ['maerd','remaerd','esare','resare']
ans = 'YES'
while S != '':
    if S[0:5] in st:
        S = S[5:]
    elif S[0:6] in st:
        S = S[6:]
    elif S[0:7] in st:
        S = S[7:]
    else:
        ans = 'NO'
        break
print(ans)

Measured memory_bytes: 9812
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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 Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int H, W; cin >> H >> W;
    int N; cin >> N;
    vector<int> a(N,0);
    rep(i,N) cin >> a[i];

    vector<vector<int>> ans(H, vector<int>(W, 0));
    int index = 0;
    rep(i,H){
        if (i % 2 == 0){
            for (int j = 0; j < W; j++){
                ans[i][j] = index;
                if (--a[index] == 0) index++;
            }
        }
        else{
            for (int j = W-1; j >= 0; j--){
                ans[i][j] = index;
                if (--a[index] == 0) index++;
            }
        }
    }

    rep(i,H){
        rep(j,W){
            if(j != 0) cout << " ";
            cout << ans[i][j]+1;
        }
        cout << endl;
    }

}

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


int main(){
    int n;
    cin >> n;
    vector<int> v(100001);
    while(n--){
        int a;
        cin >> a;
        v[a]++;
    }
    int ans = 0;
    for(int i = 1; i < 100000; i++){
        ans = max(ans, v[i-1] + v[i] + v[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    cout<<(n-k)*(k!=1)<<endl;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int A, B;
    cin >> A >> B;
    cout << (2 * B < A ? A - 2 * B : 0) << endl;
    return 0;
}


Measured memory_bytes: 3628
w = input()

h = [0]

for i in range(len(w)):
  if w[i] == "/":
    h.append(h[i]+1)
  elif w[i] == "_":
    h.append(h[i])
  else:
    h.append(h[i]-1)

L = []

lstart = []

for i in range(len(w)):
  if w[i] == "\\":
    lstart.append(i)
    L.append(0)
  elif w[i] == "/" and not lstart == []:
    j = lstart.pop()
    s = i-j
    for k in range(1, i-j):
      if L[i-k]>0:
        s += L.pop(i-k)
        L.append(0)
    L.append(s)
  else:
    L.append(0)

L = [i for i in L if i > 0]

print(sum(L))
L.insert(0,len(L))
print(" ".join(map(str, L)))


Measured memory_bytes: 7296
l, a, b = gets.strip.split.map(&:to_i)
ans=0
1.upto(l) do |i|
  se=0
  i.to_s.split('').map(&:to_i).each{|i|se += i}
  if a <= se && b >= se
 ans = ans + i
  end
end
puts ans

Measured memory_bytes: 2044
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1
    else:
        print(-1)


if __name__=='__main__':
    main()

Measured memory_bytes: 62944
#include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-7;
const D INF = 1e9;
const D PI = acos(-1);
const int N = 200100;

ll n,dat[2*N-1];

void init(int n_){
  n=1;
  while(n<n_)n*=2;
  rep(i,2*n-1)dat[i] = 0;
}

void update(ll k,ll a){
  k += n-1;
  dat[k] = a;
  while(k>0){
    k = (k-1)/2;
    dat[k] = max(dat[k*2+1],dat[k*2+2]);
  }
}

//return minimam value in [a,b). ( [l,r) is interval in which k is.)
ll query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return 0;
  if(a<=l && r<=b)return dat[k];
  ll vl = query(a,b,2*k+1,l,(l+r)/2);
  ll vr = query(a,b,2*k+2,(l+r)/2,r);
  return max(vl,vr);
}

int main(){
  ll n_, x[N];

  cin >> n_;
  rep(i,n_)cin >> x[i];
  init(n_);

  ll ans = 0;
  rep(i,n_){
    ll val = query(0,x[i],0,0,n) + x[i];
    ans = max(ans,val);
    update(x[i]-1,val);
  }

  cout << n_*(n_+1)/2 - ans << endl;
}

Measured memory_bytes: 3996
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
int d1[4]={0,1,0,-1};//これで四方向のベクトルを表現
int d2[4]={1,0,-1,0};
int h,w,ans;
int map[20][20];

void dfs(int depth,int y,int x){
	int i,ny,nx;
	if(depth>=ans)return;
	for(i=0;i<4;i++){	
		ny=y+d1[i];nx=x+d2[i];//ポイント
		if(map[ny][nx]==1)continue;//すぐ隣のブロックの破壊を防ぐ
		while(0<=ny&&ny<h&&0<=nx&&nx<w&&map[ny][nx]!=1){//ブロックにぶつかるまで、while文
			if(map[ny][nx]==3){
				ans=depth;return;
			}else {
				ny+=d1[i];nx+=d2[i];
			}
		}	
		if(map[ny][nx]==1&&0<=ny&&ny<h&&0<=nx&&nx<w){//while文に入れると、
					map[ny][nx]=0;//ブロック消滅
					dfs(depth+1,ny-d1[i],nx-d2[i]);
					map[ny][nx]=1;//ここで戻すのがポイント!!
				}
	}
}


int main(){
	while(1){
		int i,j;
		ans=11;
		cin>>w>>h;
		if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cin>>map[i][j];
			}
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(map[i][j]==2){
					dfs(1,i,j);
					goto OUT;
				}				
			}
		}
		OUT:
		if(ans==11){
			cout<<"-1"<<endl;
		}else{
			cout<<ans<<endl;
		}

	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=1;i<=n;i++)
const int inf = 1000000007;
int a[100005];
signed main() {
	int n, k;
	cin >> n >> k;
	if ((n - 1) % (k - 1) == 0)cout << (n - 1) / (k - 1) << endl;
	else cout << (n - 1) / (k - 1) + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s;

}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

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

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


int main () {
  cin.tie(0);
  cout << setprecision(10);

  vi dx = {-1, 0, 1, 0};
  vi dy = {0, -1, 0, 1};

  while(1) {
    int w, h; cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<vector<char>> a(h);
    REP(i, h) {
      a[i].resize(w);
      REP(j, w) {
        cin >> a[i][j];
      }
    }

    int black = 0, white = 0;
    vector<vector<bool>> sel(h);
    REP(i, h) sel[i].resize(w, false);
    REP(i, h) {
      REP(j, w) {
        if(sel[i][j]) continue;
        if(a[i][j] == 'B' || a[i][j] == 'W') {
          continue;
        }
        int area = 1;
        bool bl = false;
        bool wh = false;
        queue<P> q;
        sel[i][j] = true;
        q.push(make_pair(i, j));
        while(!q.empty()) {
          P p = q.front(); q.pop();
          REP(k, 4) {
            P tmp = make_pair(p.first + dy[k], p.second + dx[k]);
            if(0 <= tmp.first && tmp.first <h && 0 <= tmp.second && tmp.second < w) {
              if(sel[tmp.first][tmp.second]) continue;
              if(a[tmp.first][tmp.second] == 'B') {
                bl = true;
                continue;
              }
              if(a[tmp.first][tmp.second] == 'W') {
                wh = true;
                continue;
              }
              sel[tmp.first][tmp.second] = true;
              area++;
              q.push(tmp);
            }
          }
        }

        // cout << i << ":" << j << ":" << area << ":" << bl << ":" << wh << endl;

        if(bl && !wh) {
          black += area;
        } else if(!bl && wh) {
          white += area;
        }
      }
    }
    cout << black << " " << white << endl;
  }
}



Measured memory_bytes: 3176
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    while (X > 0 || Y > 0) {
        if (X > 0) {
            if (Y > 0) {
                if (A + B < C * 2) {
                    ans += A + B;
                    X--;
                    Y--;
                } else {
                    ans += C * 2;
                    X--;
                    Y--;
                }
            } else {
                if (A < C * 2) {
                    ans += A;
                    X--;
                } else {
                    ans += C * 2;
                    X--;
                }
            }
        } else if (Y > 0) {
            if (B < C * 2) {
                ans += B;
                Y--;
            } else {
                ans += C * 2;
                Y--;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  bool judge = true;
  int x;
  int n	= 0;
  while (judge) {
    cin >> x;
    n++;
    if (x != 0) {
      cout << "Case " << n << ": " << x	<< endl;
    } else {
      judge = false;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   int k;
  string a;
  cin >> k>> a;
  string moto = a.substr(0,k/2);//cout<<moto;
  string aho = moto+moto;//cout<<aho;
  if(a == aho) cout<<"Yes";
  else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int A[S.size()]={0};
  for(int i=0;i<S.size()-1;i++){
    if(S[i]==S[i+1]) A[i+1]=A[i];
    else A[i+1]=A[i]+1;
  }
  cout<<A[S.size()-1]<<endl;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
// static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

#include <iostream>
using namespace std;

const int MAX = 10000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];


int main(void){

  int N, i;
  cin >> N >> i;

  cout << (N-1)*(i-1) << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> point(n, k - q);
    for(int i = 0; i < q; i++) {
        cin >> a[i];
        point[a[i] - 1] += 1;
    }

    for(int i = 0; i < n; i++){
        if(point[i] > 0) cout << "Yes";
        else cout << "No";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int n,a,x,c,k[35];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		x^=a;
		a^=a-1;
		for(int j=1;j<31;j++)if(a==(1<<j)-1)k[j]=1;
	}
	for(int i=30;i>0;i--)
	{
		if(x&(1<<(i-1))&&k[i])c++,x^=(1<<i)-1;
	}
	cout<<(x?-1:c)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==0&&b!=100)
        printf("%d\n",b);
    if(a==0&&b==100)
        printf("101\n");
    if(a==1&&b!=100)
        printf("%d\n",b*100);
    if(a==1&&b==100)
        printf("10100\n");
    if(a==2&&b!=100)
        printf("%d\n",b*10000);
    if(a==2&&b==100)
        printf("1010000\n");
    return 0;
}


Measured memory_bytes: 128
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
s = "".join(s)
t = "".join(t)
if s == t:
    print("No")
    exit()
ans = [s,t]
ans2 = sorted(ans)
if ans == ans2:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, long long K, vector<long long> x) {
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ans += min(abs(x[i] - 0), abs(x[i] - K));
    }
    ans *= 2;

    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  cin >> N;
  long long K;
  cin >> K;
  vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  solve(N, K, move(x));
  return 0;
}


Measured memory_bytes: 3628