akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long N,K;
  long long output = 0;
  long long base = 1;
  cin>>N;
  cin>>K;
  stringstream ss;
  if (K==2){
    ss << bitset<30>(N);
    string s=ss.str();
    //cout<<s<<endl;
    for (int i=0;i<30;i++){
      if(!(s.at(i)=='0')){
        cout<<30-i<<endl;
        return 0;
      }
    }
  }

  while(N>0){
    output = output + ( N % K ) * base;
    N = N / K;
    base = base * 10;
  }
    cout<<(long long)log10(output)+1<<endl;
 
  return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
  int a,b,count=0;
  cin>>a>>b;
  int c=b;
  if(b%10==2||b%10==3||b%10==7||b%10==8)
  cout<<"No";
  else
  {
  	while(b)
  	{
  		b=b/10;
  		count++;
  		
	  }
	  a=a*(pow(10,count))+c;
	  double d_sqrt = sqrt( a );
int i_sqrt = d_sqrt;
if ( d_sqrt == i_sqrt )
    cout<<"Yes";
	else
	cout<<"No";
  }
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	int SUNUKE = 100 ;
	int FUNUKE = 200 ;
	int DOT = 0 ;
	int STONE = 1 ;
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		String S = sc.next() ;

//		System.out.println("N=" + N);
//		System.out.println("A=" + A);
//		System.out.println("B=" + B);
//		System.out.println("C=" + C);
//		System.out.println("D=" + D);
//		System.out.println("S=" + S);
//

		int cell[] = new int[N + 1] ;
		for(int i = 1 ; i <= N ; i ++) {
			if(i == A) {
				cell[i] = SUNUKE ;
			}else if(i == B) {
				cell[i] = FUNUKE ;
			}else {
				String z = S.substring(i - 1, i ) ;
				if(z.equals(".")) {
					cell[i] = DOT ;
				}else {
					cell[i] = STONE ;
				}
			}

		}

//		String Z = "" ;
//		for(int i = 1 ; i <= N ; i ++) {
//			int x = cell[i];
//			if(x==SUNUKE) {
//				Z += "S" ;
//			}else if(x == FUNUKE) {
//				Z += "F" ;
//			} else {
//				Z += x + "" ;
//			}
//		}
//		System.out.println(Z);

		//BからDまでの間に石が2つ並んでいたらNG
		for(int i = B + 1 ; i <= D; i ++) {
			if((cell[i] == STONE) &&  (cell[i] == cell[i -1])) {
				System.out.println("No");
				return ;
			}
		}
		//ここまでくれば、ふぬけ君はDまで移動できる
		//AからCまでの間に石が2つ並んでいたらNG
		for(int i = A + 1; i <= C; i ++) {
			if((cell[i] == STONE) &&  (cell[i] == cell[i -1])) {
				System.out.println("No");
				return ;
			}
		}
		// C < Dの場合
		if( C < D) {
		} else {// D < Cの場合

			//追い抜けるかどうか？
			//BからCまでの間に、抜けるポイント＝石が連続して3か所以上空いている場所があればOK
			int blank = 0 ;
			boolean check = false ;
			if(cell[B-1] != STONE) {
				blank = 1 ;
			}
			for(int i = B ; i <= D; i ++) {
				if(cell[i] != STONE) {
					blank ++ ;
					if(blank == 3) {
						check = true ;
						break ;
					}
				}else{
					blank = 0 ;
				}
			}
			//追い抜くポイントなしのためNG
			if(!check) {
				if((cell[D-1] != STONE) && (cell[D+1] != STONE)) {
					//Dの手前も後ろも空いていれば、ここで追い抜ける
				}else {
					System.out.println("No");
					return ;
				}
			}
		}

		//ここまでくれば、すぬけ君はCまで移動できる
		System.out.println("Yes");
		return ;
//
//
//
//
//
//
//
//
//		String Z = "" ;
//		for(int i = 1 ; i <= N ; i ++) {
//			int x = cell[i];
//			if(x==SUNUKE) {
//				Z += "S" ;
//			}else if(x == FUNUKE) {
//				Z += "F" ;
//			} else {
//				Z += x + "" ;
//			}
//		}
//		System.out.println(Z);
	}



}


Measured memory_bytes: 37472
class UnionFind{
  int[] root;
  this(int n){
    root.length=n;
    foreach(i; 0..n) root[i]=i;
  }
  int find(int x){
    if(x==root[x]) return x;
    else return root[x]=find(root[x]);
  }
  void merge(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;
    root[x]=y;
  }
}

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, k, l; rd(n, k, l);
  auto s1=new UnionFind(n), s2=new UnionFind(n);
  foreach(_; 0..k){
    int a, b; rd(a, b);
    s1.merge(a-1, b-1);
  }
  foreach(_; 0..l){
    int a, b; rd(a, b);
    s2.merge(a-1, b-1);
  }
  struct Pair{int fi, se;}
  int[Pair] freq;
  foreach(i; 0..n){
    auto pair=Pair(s1.find(i), s2.find(i));
    if(pair in freq) freq[pair]++;
    else freq[pair]=1;
  }
  foreach(i; 0..n){
    writeln(freq[Pair(s1.find(i), s2.find(i))]);
  }

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 22396
from itertools import *
N,C=map(int,input().split())
D=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]

lst=[[],[],[]]

for y in range(N):
    for x in range(N):
        lst[(y+x)%3].append(c[y][x])


Revalue=10**18

valuelst=[[0 for i in range(C)] for i in range(3)]
for v in range(3):
    for Color in range(1,C+1):
        value=0
        for i in lst[v]:
            value+=D[i-1][Color-1]
        valuelst[v][Color-1]=value


for Color1,Color2,Color3 in list(permutations(list(range(1,C+1)),3)):
    value=valuelst[0][Color1-1]+valuelst[1][Color2-1]+valuelst[2][Color3-1]

    Revalue=min(Revalue,value)
print(Revalue)


Measured memory_bytes: 56232
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int gogo[191];
int main() {
	int ans = 0;
	REP(i, 3) {
		int a;
		cin >> a;
		gogo[a]++;
		if (gogo[a] == 1) ans += 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    int L[M];
    int R[M];
    for (int i = 0; i < M; i++) cin >> L[i] >> R[i];
    sort(L,L+M);
    sort(R,R+M);
    int answer = R[0] - L[M-1] + 1;
    if (answer < 0) answer = 0;
    cout << answer;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

struct point {
  long double x, y;
};

long double cross(point p1, point p2) {
  long double c = p1.x * p2.y - p1.y * p2.x;
  if (c < 0) c *= -1;
  return c;
}

long double abs(point p1, point p2) {
  long double lx, ly;
  lx = p2.x - p1.x;
  ly = p2.y - p1.y;
  return (sqrt(lx * lx + ly * ly));
}



int main() {
  int q;
  point p0, p1, p2, p3, v23, v20, v21;
  long double h1, h2, t;
  cin >> q;
  rep(i, q) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    v23.x = p3.x - p2.x;
    v23.y = p3.y - p2.y;
    v20.x = p0.x - p2.x;
    v20.y = p0.y - p2.y;
    v21.x = p1.x - p2.x;
    v21.y = p1.y - p2.y;
    h1 = cross(v23, v20) / abs(p2, p3);
    h2 = cross(v23, v21) / abs(p2, p3);
    t = h1 / (h1 + h2);
    cout << setprecision(15) << p0.x + (p1.x - p0.x) * t << " " << p0.y + (p1.y - p0.y) * t << endl;
  }

  
  return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,K,Q,A[100000],P[100000];
    cin >> N >> K >> Q;
    memset(P, 0, sizeof(P));
    REP(i,Q){
        cin >> A[i];
        P[A[i]-1]++;
    }
    REP(i,N){
        if(K+P[i]-Q > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
open System.Linq

type Restaurant =
    { id : int
      s : string
      p : int }

let N = stdin.ReadLine() |> int
let restaurant = Array.zeroCreate<Restaurant> N

for i in [ 0..N - 1 ] do
    let [| S; P |] = stdin.ReadLine().Split()
    restaurant.[i] <- { id = i
                        s = S
                        p = int P }

let sorted = restaurant.OrderBy(fun x -> x.s).ThenByDescending(fun x -> x.p)

sorted
|> Seq.map (fun x -> x.id + 1)
|> Seq.iter (printfn "%d")


Measured memory_bytes: 14556
#include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    
    while(1){
        c -= b;
        //printf("%d %d\n",b,d);
        if(c<=0){ printf("Yes"); return 0; }
        a -= d;
        if(a<=0){ printf("No"); return 0; }
        
    }
    return 0;
}

Measured memory_bytes: 1732
using System;

namespace abc140_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string res = "";

            if (input == "Sunny")
            {
                res = "Cloudy";
            }else if (input == "Cloudy")
            {
                res = "Rainy";
            }else if (input == "Rainy")
            {
                res = "Sunny";
            }



            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 11092
def main():
    N, K = map(int, input().split())
    S = input()
    A = []
    for j in range(N):
        if j == 0:
            cur = S[j]
            i = 0
        else:
            if S[j] != cur:
                A.append([j-i, cur])
                i = j
                cur = S[j]
    A.append([N-i, cur])
    queue = []
    count = 0
    tot = 0
    ans = 0
    # print(S)
    # print(A)
    for i in range(len(A)):
        c, s = A[i]
        if count < K:
            if s == "0": count += 1
        elif count == K:
            if s == "0":
                c1, s1 = queue.pop(0)
                tot -= c1
                if s1 == "1":
                    c2, s2 = queue.pop(0)
                    tot -= c2
        queue.append([c, s])
        tot += c
        # print(tot)
        ans = max(ans, tot)
    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 18804
a, b, c = sorted(map(int, input().split()))
states = set()
cnt = 0
while True:
    if a % 2 or b % 2 or c % 2:
        break
    state = tuple(sorted([a, b, c]))
    if state in states:
        cnt = -1
        break
    states.add(state)
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    cnt += 1
print(cnt)


Measured memory_bytes: 3188
N = input()
L = len(N)
K = int(input())

dp = [ [ [0]*2 for _ in range(4) ] for _ in range(L+1) ]
dp[0][0][0] = 1
for i in range(L):
  for j in range(K+1):
    for k in range(2):
      nd = int(N[i])
      for d in range(10):
        ni = i+1
        nj = j
        nk = k
        if d != 0: nj += 1
        if nj > K: continue
        if k==0:
          if d > nd: continue
          if d < nd: nk = 1

        dp[ni][nj][nk] += dp[i][j][k]

print(dp[L][K][0] + dp[L][K][1])

Measured memory_bytes: 71556
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

char ans[11][1000000];
int cnt[11][1000000], before[11][1000000];

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

  ans[0][0] = 'a'; cnt[0][0] = 1;

  for (int i = 1; i < N; i++){
    int now = 0;
    for (int j = 0; j < 1e6; j++){
      if (cnt[i - 1][j] == 0) break;
      for (int k = 0; k <= cnt[i - 1][j]; k++){
        char next = 'a' + k;
        ans[i][now] = next;
        cnt[i][now] = cnt[i - 1][j];
        if (k == cnt[i - 1][j]) cnt[i][now]++;
        before[i][now] = j;
        now++;
      }
    }
  }
  
  for (int j = 0; j < 1e6; j++){
    if (cnt[N - 1][j] == 0) break;
    char now[N];
    now[N - 1] = ans[N - 1][j];
    int index = j;
    for (int i = N - 2; i >= 0; i--){
      index = before[i + 1][index];
      now[i] = ans[i][index]; 
    }

    for (int i = 0; i < N; i++){
      cout << now[i];
    }
    
    cout << endl;
  }
  


  return 0;
}


Measured memory_bytes: 52736
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi v(n);
	rep(i, n){
		cin >> v[i];
		v[i] -= i + 1;
	}
	ll ans = 0;
	sort(all(v));
	rep(i, n) ans += abs(v[i] - v[n / 2]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    if(a==b) {
        cout << "Draw" << endl;
    } else if(a==1) {
        cout << "Alice" << endl;
    } else if(b==1) {
        cout << "Bob" << endl;
    } else if(a>b) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    
    int x;

    cin >> x;

    for(int i = x;;i++){
        int f_next = 0;
        for(int j = 2; j < sqrt(x); j++){
            if(i % j == 0){
                f_next = 1;
                break;
            }
        }
        if(!f_next){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int N; cin >> N;
    vi A(N-1); REP(i, N-1) cin >> A[i];
    map<int, int> mp;
    REP(i, N-1) {
        mp[A[i]-1]++;
    }
    REP(i, N) {
        cout << mp[i] << endl;
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 13484
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	if (s == "ABC")
		cout << "ARC";
	else
		cout << "ABC";
	return 0;
}


Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int a, b, c;
	int x, y;
	cin >> a >> b >> c;
	cin >> x >> y;
	int res = a * x + b * y;
	if (c * 2 > a + b)
	{
		cout << res;
		return 0;
	}
	
	for (int i = 0; i < (x + y) * 2; i++)
	{
		int curx = x, cury = y;
		int curres = i * c;
		curx -= i / 2;
		cury -= i / 2;
		if (curx > 0)
			curres += curx * a;
		if (cury > 0)
			curres += cury * b;
		res = min(curres, res);
	}
	cout << res;
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        ll l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

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

vector<int> adj[200005];
int vis[200005];
ll dp[200005][5];

ll mod = 1e9+7;

ll solve(int u, int last, int p = -1){
    if(dp[u][last] != -1) return dp[u][last];
    ll res = 1;
    for(int v : adj[u]){
        if(v == p) continue;
        if(last == 1)
            res = (res * solve(v, !last, u))%mod;
        else
            res = (res * ((solve(v, !last, u) + solve(v, last, u))%mod))%mod ;
    }
    return dp[u][last] = res;
}

int main(){
    memset(dp, -1, sizeof dp);
    int n; cin >> n;
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll res = (solve(1, 0) + solve(1, 1))%mod;
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 24960
import sys

readline = sys.stdin.readline

H, W, N = [int(a) for a in readline().split()]

sr, sc = [int(a) for a in readline().split()]

S = readline().strip()
T = readline().strip()

S_max = {'L':0, 'R':0, 'U':0, 'D':0}
T_max = {'L':0, 'R':0, 'U':0, 'D':0}
maxes = {'L':0, 'R':0, 'U':0, 'D':0}
anti = {'L':'R', 'R':'L', 'U':'D', 'D':'U'}

def check():
    return (-maxes['L'] + sc < 1) or (maxes['R'] + sc > W) or \
    (-maxes['U'] + sr < 1) or (maxes['D'] + sr > H)

for i in range(N):
#    for dir in ['L', 'R', 'U', 'D']:
#        S_max[dir] = S.count(dir)
#        T_max[dir] = T.count(dir)
#        S_max[dir] += 1 if S[i] == 'dir' else 0
#        T_max[dir] += 1 if T[i] == 'dir' else 0        
    
    maxes[S[i]] += 1
    if check():
        print('NO')
        exit()
    maxes[anti[T[i]]] -= 1
    maxes['L'] = max(maxes['L'], sc - W)
    maxes['R'] = max(maxes['R'], -sc + 1)
    maxes['U'] = max(maxes['U'], sr - H)
    maxes['D'] = max(maxes['D'], -sr + 1)
#    if (S_max['R'] - T_max['L'] + sc > W) or \
#        (T_max['R'] - S_max['L'] + sc < 1) or \
#        (S_max['D'] - T_max['U'] + sr > H) or \
#        (T_max['D'] - S_max['U'] + sr < 1):
#        print('NO')
#        exit()

print('YES')

Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
int main()
{long long s=0;string s1;
    cin>>s1;
    for(long long j=0;j<s1.length();j++)
    s+=(s1[j]-'0');
    if(s%9==0)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3720
N = input()
N =int(N)
nums= list(map(int,input().split(" ")))
ans = 1
tend = 0
before = nums[0]
for a in nums[1:]:
    if (before - a) * tend < 0:
        tend = 0
        ans += 1
    else:
        tend = 1 if before - a > 0  else -1 if before - a < 0 else tend

    before = a

print(ans)


Measured memory_bytes: 58664
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;
vector<int>rec[N];


int main()  {
    fastio;
    int n;
    cin>>n;
    vector<int>vec1(n) , vec2(n) , ans, rec;
    for(int i =0 ; i < n ; i++ ) cin>>vec1[i];
    for(int j =0 ;  j< n ; j++ ) cin>>vec2[j];
    ans = vec2;

    reverse(vec2.begin() , vec2.end());
    int l  = n , r = -1;
    for(int i = 0 ; i < n ; i++ ) {
        if(vec1[i] == vec2[i]) {
            l = min(l, i);
            r = max(r ,i);
            rec.push_back(i);
        }
    }

    for(int i =0 ; i < n && rec.size() ; i++ ) {
        if(i >= l && i <= r ) continue;
        

        int id = rec.back();
        int val = vec1[id];

        swap(vec2[id] , vec2[i]);

        if(vec2[id] == vec1[id] || vec2[i] == vec1[i]) {
            swap(vec2[id] , vec2[i]);
        }
        else {
            rec.pop_back();
        }
    }


    if(rec.size()) {
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    for(auto x : vec2) cout<<x<<" ";
    cout<<'\n';


    return 0;

}

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

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

    rep(i,n) {
        string s = to_string(i+1);
        if (s.length() % 2 != 0)  ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	int N, K, P,i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++)
	{
		scanf("%d %d", &K, &P);
		if (K%P != 0) {
			printf("%d\n", K%P);
		}
		else {
			printf("%d\n", P);
		}
	}
	return 0;
}


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

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    s << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    s << ']';
	return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<int> v(n), c(n);
	rep(i, n) cin >> v[i];
	rep(i, n){
	    cin >> c[i];
	}

 	int ans = 0;
	rep(i, n){
	    ans += max(v[i]-c[i], 0);
	}
	ppp(ans);


    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

bool valid(string str) {
	for (int i = 0; i < sz(str) / 2; i++)
		if (str[i] != str[sz(str) - i - 1])
			return 0;
	return 1;
}
int main() {
	//file();
	fast();
	string str; cin >> str;
	int n = sz(str);
	string clear1 = "", clear2 = "";
	for (int i = 0; i < (n - 1) / 2; i++)
		clear1.push_back(str[i]);
	for (int i = (n + 3) / 2 - 1; i < n; i++) {
		clear2.push_back(str[i]);
	}
	if (valid(str) && valid(clear1) && valid(clear2))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int gcd(int a, int b)
{
    while (a != 0) {
        int r = b % a;
        b = a;a = r;
    }

    return b;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, ret = 0;
    cin >> N;
    FOR(i, 0, N) {
        int t;
        cin >> t;
        ret = gcd(ret, t);
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;

struct K {
	int basho, nokori, mincost;
};
bool operator<(K a, K b) {
	return a.mincost > b.mincost;
}
int main() {
	int cost[100][11];//n???????????°????????§m????????????????°????
	int B, c, d, e, f;
	while (scanf("%d%d%d%d%d", &B, &c, &d, &e, &f), B || c || d || e || f) {
		vector<P>a[100]{};
		memset(cost, 0x3f, sizeof(cost));
		e--; f--; cost[e][B] = 0;
		priority_queue<K>Q;
		K g;
		g.basho = e; g.nokori = B; g.mincost = 0;
		Q.push(g);
		for (int h = 0; h < d; h++) {
			int i, j, k;
			scanf("%d%d%d", &i, &j, &k);
			i--; j--;
			a[i].push_back(P(k, j));
			a[j].push_back(P(k, i));
		}
		while (Q.size()) {
			K l = Q.top(); Q.pop();
			int m = l.mincost, n = l.nokori, b = l.basho;
			if (cost[b][n] < m)continue;
			for (P o : a[b]) {
				if (cost[o.second][n] > cost[b][n] + o.first) {
					cost[o.second][n] = cost[b][n] + o.first;
					K xx;
					xx.basho = o.second;
					xx.mincost = cost[o.second][n];
					xx.nokori = n;
					Q.push(xx);
				}
				if (n&&cost[o.second][n-1] > cost[b][n] + o.first / 2) {
					cost[o.second][n - 1] = cost[b][n] + o.first / 2;
					K yy;
					yy.basho = o.second;
					yy.nokori = n - 1;
					yy.mincost = cost[o.second][n - 1];
					Q.push(yy);
				}
			}
		}
		int MINCOST = 1 << 29;
		for (int sss = 0; sss < 11; sss++) {
			MINCOST = min(MINCOST, cost[f][sss]);
		}
		cout << MINCOST << endl;
	}
}

Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t X, Y;
    std::cin >> X >> Y;

    int64_t max = X * 4;
    int64_t min = X * 2;

    if (max < Y || min > Y || Y%2 == 1) {
        std::cout << "No" << std::endl;
        return 0;
    }

    std::cout << "Yes" << std::endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long int
#define ull unsigned long long
#define vii vector <int>
#define pii pair <int, int>
#define fi first
#define se second
#define rep(i,a,n)		for(int i=a;i<n;i++)
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof a)
#define mod 1000000007LL;
#define mkp make_pair
#define pb push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;
double pi=3.1415926535;
double eps=0.000001;

void print(vector <int> &arr){
	for(int i=0;i<arr.size();i++)
		cout<<arr[i]<<" ";
	
	cout<<endl;
}


int32_t main(){
/////////////////////////////////////////////////////////////////////
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//	std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//    std::cout.precision(10);
	int n;
	cin>>n;
	vii arr(n);
	rep(i,0,n) cin>>arr[i];
	vii dp(n+1,0);
	dp[0]=dp[1]=0;
	dp[2]=abs(arr[1]-arr[0]);
	rep(i,3,n+1){
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]), dp[i-2]+abs(arr[i-1]-arr[i-3]));
	}
	cout<<dp[n]<<endl;
	return 0;
	}
	


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	r := "No"
	for i := 1; i < 10; i++ {
		if n%i == 0 {
			if n/i < 10 {
				r = "Yes"
			}
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 4
#define N2 46

int Fin[N][N]={
  {1,2,3,4},
  {5,6,7,8},
  {9,10,11,12},
  {13,14,15,0}};

int P[N*N]={3,0,1,2,
              3,0,1,2,
              3,0,1,2,
              3,0,1,2};
int Q[N*N]={3,0,0,0,
            0,1,1,1,
            1,2,2,2,
            2,3,3,3};

int min=N2;

void sort(int X[N][N], int Xj[N][N], int n)
{
  int i,j,k,l,d=0,f=0,tmp[N][N];

  for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
      if(Fin[i][j]!=X[i][j]) f++;
      if(X[i][j]==0) {
        k=i;
        l=j;
      }
      else
        d+=abs(j-P[X[i][j]])+abs(i-Q[X[i][j]]);

    }
  }
  if(f==0) {
    if(min>n) {
      min=n;
    }
    return;
  }
  if(d+n>min) return;


  if(k>0 && k<N) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[k][l];
    tmp[k][l]=tmp[k-1][l];
    tmp[k-1][l]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      sort(tmp, X, n+1);
  }
    if(l>0 && l<N) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[k][l];
    tmp[k][l]=tmp[k][l-1];
    tmp[k][l-1]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      sort(tmp, X, n+1);
  }
 if(k>=0 && k<N-1) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[k][l];
    tmp[k][l]=tmp[k+1][l];
    tmp[k+1][l]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      sort(tmp, X, n+1);
  }
  if(l>=0 && l<N-1) {
    memcpy(tmp,X,sizeof(int)*N*N);
    f=tmp[k][l];
    tmp[k][l]=tmp[k][l+1];
    tmp[k][l+1]=f;
    if(memcmp(tmp,Xj,sizeof(int)*N*N)!=0)
      sort(tmp, X, n+1);
  }

}

int main()
{
  int i,j,Data[N][N];

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      scanf("%d",&Data[i][j]);
    }
  }
  sort(Data,Data,0);

  printf("%d\n",min);
  return 0;
}




Measured memory_bytes: 2096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int prev = 0, now;
    vector<string> v(3);
    for (int i = 0; i < 3; ++i) {
        cin >> v.at(i);
        reverse(v.at(i).begin(), v.at(i).end());
    }
    while (true) {
        if (v.at(prev).size()) {
            now = v.at(prev).back() - 'a';
            v.at(prev).pop_back();
            prev = now;
        } else {
            cout << char('A' + prev) << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math

S = input()
N = len(S)

ans = [0] * N

r_start = 0
r_end = 0
l_start = N - 1
l_end = N - 1


S += 'R' # ループの最後にLの塊L, ..., Lにいた子供の人数を足すオペレーションを行うため

for i in range(1, N + 1): # i = 1, 2, ..., , N
    if S[i - 1] == 'R' and S[i] == 'L':
            r_end = i - 1
            ans[r_end] += math.ceil((r_end - r_start + 1) / 2)
            ans[r_end + 1] += math.floor((r_end - r_start + 1) / 2)
            l_start = i
    elif S[i - 1] == 'L' and S[i] == 'R':
            l_end = i - 1
            ans[l_start] += math.ceil((l_end - l_start + 1) / 2)
            ans[l_start - 1] += math.floor((l_end - l_start + 1) / 2)
            r_start = i

print(" ".join(str(a) for a in ans))

Measured memory_bytes: 59744
#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define PB push_back
#define INF 2000000000
#define X first
#define Y second
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 600005;
int step[5];
int main()
{
	//freopen("input.txt" , "r" , stdin);
	for(int i = 0; i < 3; i++)
	{
		int u , v;
		cin >> u >> v;
		step[u]++;step[v]++;
	}
	int cnt0 = 0 , cnt1 = 0;
	for(int i = 1; i <= 4; i++)
		cnt0 += step[i] == 2 , cnt1 += step[i] == 1;
	if(cnt0 == 2 && cnt1 == 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long LL;

constexpr long long INFLL = 1e18;

using namespace std;

LL solve(LL temp)
{
    LL ans;
    LL count;
    LL x = 0;

    count = temp / 2 + 1;
    if (temp % 2)
    {
        if (count % 2)
        {
            ans = 1;
        }
        else
        {
            ans = 0;
        }
    }
    else
    {
        count--;
        ans = temp;
        if (count % 2)
        {
            ans++;
        }
        else
        {
            //処理なし
        }
    }
    return ans;
}

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

    if (A > 0)
    {
        A = solve(A - 1);
    }
    bitset<64> bsA(A);
    bitset<64> bsB(solve(B));

    // cout << bsA.to_ullong() << endl;
    // cout << bsB.to_ullong() << endl;

    cout << (bsA ^ bsB).to_ullong() << endl;

    return 0;
}

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

using namespace std;

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

void input(vector< vector<char> > &m);
void delete_(vector< vector< char> > &m, int x, int y);

int main(){
  int h,w;
  while(cin >> h >> w, h&&w){
    int num = 0;
    vector< vector< char > > m(h+2, vector<char>(w+2));
    input(m);
    for(int y = 0; y < m.size(); y++){
      for(int x = 0; x < m[y].size(); x++){
	if(m[y][x] != '-'){
	  delete_(m,x,y);
	  num++;
	}
      }
    }
    cout << num << endl;
  }
}

void input(vector< vector<char> > &m){
  for(int y = 0; y < m.size(); y++){
    for(int x = 0; x < m[y].size(); x++){
      if(y == 0 || x == 0 ||
	 y == m.size()-1 || x == m[y].size()-1){
	m[y][x] = '-';
      }else{
	cin >> m[y][x];
      }
    }
  }
}

void delete_(vector< vector< char> > &m, int x, int y){
  queue< pair< int, int > > q;
  q.push(make_pair(x,y));
  pair<int , int> cur = q.front();
  char c = m[cur.second][cur.first];

  while(!(q.empty())){
    cur = q.front();
    q.pop();
    if(m[cur.second][cur.first] == c){
      m[cur.second][cur.first] = '-';
      for(int i = 0; i < 4 ;i++){
	q.push(make_pair(cur.first+dx[i], cur.second+dy[i]));
      }
    }
  }
}

  

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

int main(){
	int l,m,n,i,t,b,s;
	
	while(cin >> l,l){
		t=0,s=0;
		
		for(i=1;i<=12;i++){
			cin >> m >> n;
			
			t+=(m-n);
			
			if(l<=t && s==0){
				b=i;
				s++;
			}
		}
		if(s==1){
			cout << b << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
    int r,g,b;
    cin >> r >> g >> b;
    int a = r*100+g*10+b;
    if(a%4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


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

using ll = long long;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll ans = a*c;
  ans = max(ans, a*d);
  ans = max(ans, b*c);
  ans = max(ans, b*d);

  cout << ans << endl;
}

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

int f[45];

int fib(int n)
{
    if (n == 1 || n == 0)
        return 1;
    if (f[n] != -1)
        return f[n];

    return (f[n] = fib(n - 1) + fib(n - 2));
}

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

    for (int i = 0; i < 46; i++)
        f[i] = -1;

    cout << fib(n) << endl;
}


Measured memory_bytes: 3116
from collections import deque

N = int(input())
P = list(map(int, input().split()))
swap = []
for i in range(N):
    if P[i] == i + 1:
        swap.append(i + 1)

S = deque(swap)
cnt = 0
while len(S) > 0:
    if len(S) >= 2 and (S[0] + 1 == S[1]):
        cnt += 1
        S.popleft()
        S.popleft()
    else:
        cnt += 1
        S.popleft()

print(cnt)


Measured memory_bytes: 14196
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair
#define MOD 2019

using namespace std;

int main(){

    int N,K;
    cin >> N >> K;

    vector<int> A(N);

    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    int ONE;

    for(int i=0;i<N;i++){
        if(A[i] == 1){
            ONE = i;
        }
    }

    if((N-1)%(K-1)!=0)cout << (N-1)/(K-1) + 1 << endl;
    else cout << (N-1)/(K-1) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

void solve(void){

	int N, M;

	cin >> N >> M;

	if (N == 1)
	{
		cout << M << endl;
		return;
	}

	bool isp = 1;

	for (int i = 2; i * i <= M; i++)
	{
		if (M % i == 0)
		{
			isp = 0;
			break;
		}
	}

	if (isp)
	{
		cout << 1 << endl;
		return;
	}

	int g = 2, ans = 1;

	while(g * g <= M)
	{
		if (M % g == 0)
		{
			if (M / g >= N)
			{
				ans = max(ans, g);
			}
			if (g >= N)
			{
				ans = max(ans, M / g);
			}
		}
		g++;
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
  int N, A[101], mni, tmp, ans = 0;
  int i, j;
  scanf("%d", &N);
  for(i = 0; i < N; i++) scanf("%d", A+i);
  for(i = 0; i < N; i++) {
    mni = i;
    for(j = i; j < N; j++) {
      if(A[j] < A[mni]) mni = j;
    }
    if(mni != i) {
      ans++;
      tmp = A[i];
      A[i] = A[mni];
      A[mni] = tmp;
    }
  }
  for(i = 0; i < N; i++) {
    if(i) printf(" ");
    printf("%d", A[i]);
  }
  puts("");
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x,y) cout<<x<<"-"<<y<<endl;
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int lli;
lli poww(lli x,lli y)
{
	if(y==0 || x==1)return 1;
	lli ans=1;
		if(y%2==0)
		{
			lli t=poww(x,(y/2));
			return t*t;
		}
		else
		{
			return x*poww(x,y-1);
			
		}	
}
int main()
{
	FastIO
	int t=1;
	// cin>>t;
	while(t--)
	{
		string s;
		string t;
		cin>>s;
		cin>>t;
		if(t.size()==(s.size()+1))
		{
			int k=1;
			for(int i=0;i<s.size();i++)
			{
				if(s[i]!=t[i])k=0;
			}
			if(k)cout<<"Yes";
			else
			{
				cout<<"No";
			}
			
		}
		else
		{
			cout<<"No";
		}
		
	
	}
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
	long long n,i,j,ans,k;
	ans=0;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for (i=1;i<n;i++)
	{
		arr[i]+=arr[i-1];
	}
	
	sort(arr,arr+n+1);
	k=1;

	for (i=1;i<=n;i++)
	{
		if (arr[i]==arr[i-1])
		{
			k++;
		}
		else
		{
			ans=ans+k*(k-1)/2;
			k=1;
		}
	}
	ans=ans+k*(k-1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
N=int(input())
P=[int(i) for i in input().split()]
inf = 10**20
table=[[0]*(N+2) for i in range(N+2)]
for i in range(1,N+1):
    if P[i-1]>0:
        table[i][N+1]=P[i-1]
    else:
        table[0][i]=-P[i-1]
    for j in range(2*i,N+1,i):
        table[i][j]=inf
#print(table)
def fk(x,t,f):
    #print(x)
    visit[x]=True
    if x==t:
        return f
    for i in range(N+2):
        if (not visit[i]) and table[x][i]>0:
            df=fk(i,t,min(f,table[x][i]))
            if df>0:
                table[x][i]-=df
                table[i][x]+=df
                return df
    return 0

ans=0
while True:
    visit=[False]*(N+2)
    df=fk(0,N+1,inf)
    if df>0:
        ans+=df
    else:
        break
num=sum([p for p in P if p>0])
print(num-ans)

Measured memory_bytes: 3188