akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n;
    cin>>n;
    vector<int> v;
    rep(i,n){
        int a;
        cin>>a;
        v.push_back(a);
    }
    sort(all(v));
    cout<<v[v.size()-1]-v[0]<<endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int m = n;
  int sum = 0;
  while(m > 0) {
    sum += m % 10;
    m /= 10;
  }

  if(n % sum == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>

#define ll long long

using namespace std;

inline bool search(vector<ll> v, ll target) {
    v[v.size()-1] = target;
    ll i = 0;
    while (v[i] != target) {
        i++;
    }
    
    // reached to the end?
    return i != v.size() - 1;
}

int main(void) {
    ll n, q, s, t;
    cin >> n;
    vector<ll> vs;
    vector<ll> vt;

    for (ll i = 0; i < n; i++) {
        cin >> s;
        vs.push_back(s);
    }
    cin >> q;
    for (ll i = 0; i < q; i++) {
        cin >> t;
        vt.push_back(t);
    }
    
    ll count = 0;
    for (ll i = 0; i < q; i++) {
        if (search(vs, vt[i])) count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;
 
 
int main() {
	string s;
  	cin >> s;
  	s[5] = ' ';
  	s[13] = ' ';
  	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, c;
    cin >> s;
    for (long unsigned i = 0; i < s.length(); ++i)
    {
        if (s[i] == '1') c += '1';
        if (s[i] == '0') c += '0';
        if (s[i] == 'B')
        {
            if (c[0] != '\0')
                c.erase(c.end() - 1);
        }
    }
    cout << c;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>

size_t
dist(std::pair<ssize_t, ssize_t> a, std::pair<ssize_t, ssize_t> b) {
  return std::abs(a.first - b.first) + std::abs(a.second - b.second);
}

int main() {
  size_t H, W, D;
  std::cin >> H >> W >> D;

  std::vector<std::pair<size_t, size_t>> coords(H*W);

  for (size_t y=0; y<H; y++) {
    for (size_t x=0; x<W; x++) {
      int a;
      std::cin >> a;
      coords[a-1] = std::make_pair(y-1, x-1);
    }
  }

  std::vector<size_t> accs(H*W);

  for (size_t i=0; i<H*W; i++) {
    if (i<D) {
      accs[i] = 0;
    } else {
      accs[i] = accs[i-D] + dist(coords[i-D], coords[i]);
    }
  }

  size_t Q;
  std::cin >> Q;

  for (int i=0; i<Q; i++) {
    int L;
    int R;
    std::cin >> L;
    std::cin >> R;
    L--; R--;

    std::cout << (accs[R] - accs[L]) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int a,b;
    cin>>a>>b;
    a-=2*b;
    if(a<0){cout<<0<<endl;}
    else{cout<<a<<endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;

int main(void) {
    ll X;cin>>X;
    for (ll a = -200; a <= 200; a++) {
        for (ll b = -200; b <= 200; b++) {
            if (pow(a, 5) - pow(b, 5) == X) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3540
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC133-D
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

int N;
vector<int> A;
vector<int> R;
ll suma=0;

bool check(int a){
  R[0]=a;
  ll sum=(ll)a;
  REP2(i,1,N){
    R[i] = A[i-1]-R[i-1];
    sum += R[i];
    if(R[i]<0){return false;}
  }
  if(R[0]!=A[N-1]-R[N-1]){return false;}
  if(suma == 2*sum){return true;}
  return false;
}


void solve(void){
    
  cin >> N;
  
  A.assign(N, 0);
  R.assign(N, 0);

  int amax = 0;
  
  REP(i,N){
    cin >> A[i];  // 0-indexed
    chmax(amax, A[i]);
    suma += A[i];
  }
  
  ll tmp =suma/2;
  
  for(int i=1; i<N-1; i+=2){
    tmp -= A[i];
  }
  
  R[0]=(int) tmp;
  
  REP2(i,1,N){
    R[i] = A[i-1]-R[i-1];
  }
  
  REP(j,N-1){
    cout << 2*R[j] << " ";
  }
  cout << 2*R[N-1] << endl;

  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 2176
n,c=map(int,input().split())
D=[list(map(int,input().split())) for _ in range(c)]
C=[list(map(int,input().split())) for _ in range(n)]

X1=[0]*(c+1)
X2=[0]*(c+1)
X0=[0]*(c+1)

for i in range(n):
    for j in range(n):
        if (i+1+j+1)%3==0:
            X0[C[i][j]]+=1
        elif (i+1+j+1)%3==1:
            X1[C[i][j]]+=1
        else:
            X2[C[i][j]]+=1
A=[]
for c1 in range(c):
    for c2 in range(c):
        if c2==c1:
            continue
        for c3 in range(c):
            if c3==c2 or c3==c1:
                continue
            ans=0
            for i in range(1,c+1):
                ans+=X0[i]*D[i-1][c1]+X1[i]*D[i-1][c2]+X2[i]*D[i-1][c3]
            A.append(ans)
print(min(A))
                

Measured memory_bytes: 7668
#include<stdio.h>
#include<math.h>
double dist(double x1, double x2, double y1, double y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
  int n;
  scanf("%d", &n);
  int x[n], y[n];
  for(int i=0; i<n; i++){
    scanf("%d %d", &x[i], &y[i]);
  }
  double d[n][n];
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      d[i][j]=dist((double)x[i],(double)x[j],(double)y[i],(double)y[j]);
    }
  }
  double ans=0.0;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      ans += d[i][j];
    }
  }
  for(int i=0; i<n; i++){
    ans -= d[i][i];
  }
  ans /= 2;
  ans /= (n*(n-1)/2);
  ans *= (n-1);
  printf("%.9f", ans);
  return 0;
}

Measured memory_bytes: 128
h,w = gets.chomp.split(' ').map(&:to_i)
arr = []
arr.push("."*(w + 2))
h.times do
  arr.push("." + gets.chomp + ".")
end
arr.push("."*(w + 2))
for i in 1..h
  for j in 1..w
    if arr[i][j] == "."#"#"のときはそのままにしておく。
      count = 0
      for k in (i-1)..(i+1)
        for l in (j-1)..(j+1)
          if arr[k][l] == "#"
            count += 1
          end
        end
      end
      arr[i][j] = count.to_s
    end
  end
end
arr.delete_at(0)
arr.delete_at(h)
arr.each do |row|
  row = row.chars
  row.delete_at(0)
  row.delete_at(w)
  puts row.join
end

Measured memory_bytes: 14368
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vlong a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(all(a));
  if(a[0]%2==1 && a[1]%2==1 && a[2]%2==1){
    cout<<a[0]*a[1]<<'\n';
  }
  else{
    cout<<0<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
N, X = [int(x) for x in input().split()]
INF = 10**9

layer_num = [1]
p = [1]

for i in range(N):
    layer_num.append(layer_num[-1]*2+3)
    p.append(p[-1]*2+1)


def rec(n, x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    elif x <= layer_num[n-1]+1:
        return rec(n-1, x-1)
    else:
        return p[n-1] + 1 + rec(n-1, x-(layer_num[n-1]+2))


print(rec(N, X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  if (a % 2 == 0 || b % 2 == 0) {
    cout << "Even" << endl;
  }
  
 
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	
	int a,b,c;
	scanf("%d %d %d", &a , &b, &c);
	if((a == c && b == a && b ==c ) ||( a!=c && b!=a && b!=c))
	printf("No");
	else
	printf("Yes");
	
	return 0;
}

Measured memory_bytes: 2116
#include <iostream>
using namespace std;
int main(){
  long long n;cin>>n;
  for(long long i = 1; 3500 >= i; i++){
    for(long long j = 1; 3500 >= j; j++){
      if(!(4*i*j-n*j-n*i))continue;
      if(!((n*i*j)%(4*i*j-n*j-n*i)) && (n*i*j)/(4*i*j-n*j-n*i) > 0){
        cout << i << " " << j << " " << (n*i*j)/(4*i*j-n*j-n*i) << endl;
        return 0;
      }
    }
  }
}

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

int main(){

    char s[222222];

    scanf("%s",s);

    int a=strlen(s),start=0,finish=0;
    for(int i=0;i<a;i++){
      if(s[i]=='A'){
        start=i;
        break;
      }
    }

    for(int i=start;i<a;i++){
      if(s[i]=='Z'){
        finish=i;
      }
    }

    printf("%d\n",finish-start+1);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    int k; cin >> k;
	rep(i,0,k){
		cout << "ACL" ;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>
//by Skeef79

typedef long long ll;
typedef long double ld;

typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SZ(a) int(a.size())
#define what_is(x) cout<<#x<<" is "<<x<<en;


using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];

}

void solve()
{
	string s, t;
	cin >> s >> t;
	ll ans = 0;
	for (int i = 0; i < SZ(s); i++)
		if (s[i] != t[i])
			ans++;
	cout<<ans;
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("luigi.in", "r", stdin);
	//freopen("luigi.out", "w", stdout);

	int tst = 1;
	//cin >> tst;

	while (tst--)
		solve();
}


Measured memory_bytes: 3816
#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}

inline static int sp(char* str, unsigned short i){
    if(i>99){
        char c0 = i%10; i/=10;
        char c1 = i%10; i/=10;
        str[0] = i+48;
        str[1] = c1+48;
        str[2] = c0+48;
        return 3;
    }else if(i>9){
        char c0 = i%10; i/=10;
        str[0] = i+48;
        str[1] = c0+48;
        return 2;
    }else{
        str[0] = i+48;
        return 1;
    }
}

char a[1001*500];
char buffer[8*1024*1024];

int main(void){
    const int h=gl(), w=gl();
    int p = 0;
    int pos=0;
    fread(a, 1, 2*w*h, stdin);
    {
        char haveCoin = 0;
        short old_y, old_x;
        for(int i=1; i<=h; i++){
            //fgets_unlocked(a, 1001, stdin);
            if(i%2==1){
                for(int j=1; j<=w; j++){
                    if(haveCoin){
                        pos++;
                        p += sp(buffer+p, old_y)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, old_x)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, i)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, j)+1; buffer[p-1] = '\n';
                    }
                    haveCoin ^= a[(i*w+j-1-w)*2]&1;
                    old_y = i;
                    old_x = j;
                }
            }else{
                for(int j=w; j>0; j--){
                    if(haveCoin){
                        pos++;
                        p += sp(buffer+p, old_y)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, old_x)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, i)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, j)+1; buffer[p-1] = '\n';
                    }
                    haveCoin ^= a[(i*w+j-1-w)*2]&1;
                    old_y = i;
                    old_x = j;
                }
            }
        }
    }
    pl(pos); putchar_unlocked('\n');
    fwrite(buffer, 1, p, stdout);
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;

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


int main()
{
	fast;
	cin>>n>>m;
	cout<<3*(n-gcd(n,m));

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int s1 = (S[0] - '0') * 10 + S[1] - '0';
	int s2 = (S[2] - '0') * 10 + S[3] - '0';
	if (s1 <= 0 || s1 >= 13) {
		if (s2 <= 0 || s2 >= 13) {
			print("NA"); return 0;
		}
		else {
			print("YYMM")return 0;
		}
	}
	else {
		if(s2 <= 0 || s2 >= 13) {
		print("MMYY");
		}
		else {
			print("AMBIGUOUS");
		}
	}

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX_N 1000010
bool prime[MAX_N], dp[MAX_N];
int main(){
	for(int i=0;i<=MAX_N;i++){
		prime[i] = true;
	}
	prime[0] = prime[1] = false;
	for(int i=2;i*i<MAX_N;i++){
		if(prime[i]){
			for(int j=i*2;j<=MAX_N;j+=i)prime[j] = false;
		}
	}

	int n, x, menu[30];
	while(1){
                cin >> n >> x;
                if(n==0&&x==0)break;
		for(int i=0;i<=x;i++){
			dp[i] = false;
		}

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

		int res = 0;

		dp[0] = true;
		for(int i=1;i<=x;i++){
			for(int j=0;j<n;j++){
				if(i-menu[j] >= 0 && dp[i-menu[j]]){
					dp[i] = true;
					break;
				}
			}
			if(dp[i] && prime[i]){
				res = i;
			}
		}

		if(res != 0){
			cout << res << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 3112
from itertools import *
g=lambda a,x,b:{'+':a+b,'-':a-b,'*':a*b}[x]
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"(({a}{x}{b}){y}{c}){z}{d}"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"({a}{x}{b}){y}({c}{z}{d})"
 return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Measured memory_bytes: 5656
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  cout << max({a, b, c}) - min({a, b, c}) << endl;
}


Measured memory_bytes: 3604
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

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

Measured memory_bytes: 256
fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val aArr = readInputLine().split(" ").map { it.toInt() }

    var xorAll = 0

    for (a in aArr) {
        xorAll = xorAll xor a
    }

    val ans = IntArray(n) { xorAll xor aArr[it] }

    builder.appendln(ans.joinToString(" "))

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 68304
#include <stdio.h>

int main(void)
{
	int a, b;
	int digits;
	
	while (scanf("%d %d", &a, &b) != EOF){
		digits = 0;
		a += b;
		while (a > 0){
			a /= 10;
			digits++;
		}
		printf("%d\n", digits);
	}
	
	return (0);
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int r;
    cin >> r;
    int area = r*r*3.14;
    int area2 = 3.14;
    cout << r*r;
}

Measured memory_bytes: 256
/*
* C++11 code template for contests.
* @author: Andrey Kalendarov
* @e-mail: andreykalendarov@gmail.com
*/

//#define ANDREIKKAA_TOPCODER
//#define ANDREIKKAA_ALLOCATOR
#define ANDREIKKAA_CLASS Solution
#define ANDREIKKAA_METHOD solve
#define ANDREIKKAA_PARAMETERS void
#define ANDREIKKAA_CALL
#define ANDREIKKAA_RETURN_TYPE void

#define first x
#define second y
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
const ld PI = acos(-1);

const int _ML = 200;
const char _inpf[] =
#if defined(ANDREIKKAA)
"input.txt"
#else
""
#endif
;
const char _outf[] =
#if defined(ANDREIKKAA)
""
#else
""
#endif
;

#if defined(ANDREIKKAA_ALLOCATOR)
char _mem[_ML * 1024LL * 1024LL];
size_t _ptr = 0;
inline void* operator new(size_t _x) { _ptr += _x; return _mem + _ptr - _x; }
inline void operator delete(void*) { }
#endif

template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << _m.begin()->first << ": " << _m.begin()->second; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", " << _it->first << ": " << _it->second; return _out; }

/* ________ CODE ________ */

inline ANDREIKKAA_RETURN_TYPE mainFunction(ANDREIKKAA_PARAMETERS)
{
	ll x;
	cin >> x;

	ll ans = (x / 11) * 2;
	x %= 11;
	if (0 < x && x <= 6)
	{
		++ans;
	}
	else if(6 < x)
	{
		ans += 2;
	}
	cout << ans << endl;
}

/* ________ CODE ________ */

#if defined(ANDREIKKAA) || !defined(ANDREIKKAA_TOPCODER)
int main()
{
#if defined(ANDREIKKAA)
	time_t _start = clock();
#endif
#pragma warning(push)
#pragma warning(disable: 4127)
	if (sizeof(_inpf) > 1)
		freopen(_inpf, "r", stdin);
	if (sizeof(_outf) > 1)
		freopen(_outf, "w", stdout);
#pragma warning(pop)
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << setprecision(20);
	//cout << fixed;
	mainFunction(ANDREIKKAA_CALL);
#if defined(ANDREIKKAA)
	cerr << "Time: " << (clock() - _start) / (ld)CLOCKS_PER_SEC << endl;
	while (true);
#endif
}
#else
class ANDREIKKAA_CLASS { public: ANDREIKKAA_RETURN_TYPE ANDREIKKAA_METHOD(ANDREIKKAA_PARAMETERS) { return mainFunction(ANDREIKKAA_CALL); } };
#endif


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


int main()
{

  string s;
  cin>>s;

  int n = s.length();
  if(s[n-1] != 's'){
     s+='s';
  }else{
      s+="es";
  }

  cout<<s<<endl;
  return 0;
}


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

int combination(int x){
  
}

int main(){
  int N;
  cin >> N;
  vector<int>A(N);
  
  rep(i,N)cin >> A[i];
  sort(A.begin(),A.end());
  
  int a = A[N/2];
  int b = A[N/2 -1];
  
  cout << a - b << endl;
  
}

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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}

ll dp[101][10001];

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll W;
  cin >> n >> W;
  vector<int> v(n);
  vector<ll> w(n);
  rep(i, n)cin >> v[i] >> w[i];
  rep(i, n + 1){
    rep(j, 10001)dp[i][j] = linf;
  }
  dp[0][0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= 10000; j++){
      dp[i+1][j] = dp[i][j];
      if(j-v[i]>=0)dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
    }
  }
  int res = 0;
  for(int i = 10000; i >= 0; i--){
    if(dp[n][i] <= W){
      res = i;
      break;
    }
  }
  cout << res << endl;
	return 0;
}



Measured memory_bytes: 11076
io = STDIN
n,m,x=io.gets.split.map(&:to_i)
ar=n.times.map{io.gets.split.map(&:to_i)}
ans=Float::INFINITY
[true,false].repeated_permutation(n) do |bits|
  fee=0
  sum=Array.new(m,0)
  bits.zip(ar) do |b,ca|
    next unless b
    c,a=ca[0],ca[1..-1]
    fee+=c
    m.times {|i|sum[i]+=a[i]}
  end
  if sum.all?{|a|a>=x}
    ans=[fee,ans].min
  end
end
if ans==Float::INFINITY
  puts -1
else
  puts ans
end


Measured memory_bytes: 14344
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int x, a;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a==b&&b==c&&a%2==0)
    cout << -1 << endl;
  else{
    int i=0;
    while(a%2==0&&b%2==0&&c%2==0){
      int x=a/2;
      a=a/2+b/2;
      b=b/2+c/2;
      c=c/2+x;
      i++;
    }
    cout << i << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e6 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
string s;
main() {
    file("censor");
    ios;
    cin >> n >> s;
    if (n & 1) return !(cout << "No");
    string t = s.substr(0, n / 2);
    if (t + t == s) return !(cout << "Yes");
    cout << "No";
    return 0;
}
/**

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll x;
    cin >> x;
    if(x>=30){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long 
int cmp(const void*a,const void*b){return *(int*)a-*(int*)b;}
void ap(void){
    printf("APPROVED\n");
}
void de(void){
    printf("DENIED\n");
}
int main(){
    int n;
    int count=0;
    scanf("%d",&n);
    int a[n+1];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]%2==0){
            count++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0)
                ans++;
        }
    }
    if(ans==count){
        ap();
    }
    else{
        de();
    }
    return 0;
}

Measured memory_bytes: 128
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None
        self.prev = None
 
 
def run():
    n = int(input())
    tail = Node(None)
    node = tail
 
    for _ in range(n):
        command = input()
        if command.startswith('0'):
            nn = Node(int(command[2:]))
            nn.prev, nn.next = node.prev, node
            if node.prev is not None:
                node.prev.next = nn
            node.prev = nn
            node = node.prev
        elif command.startswith('1'):
            i = int(command[2:])
            if i > 0:
                for _ in range(i):
                    node = node.next
            else:
                for _ in range(-i):
                    node = node.prev
        elif command.startswith('2'):
            p, n = node.prev, node.next
            node.prev, node.next = None, None
            node = n
            if p is None:
                n.prev = None
            else:
                n.prev, p.next = p, n
        else:
            raise ValueError('invalid command')
 
    st = []
    node = tail.prev
    while node is not None:
        st.append(node.value)
        node = node.prev
 
    while len(st) > 0:
        print(st.pop())
 
 
if __name__ == '__main__':
    run()


Measured memory_bytes: 92992
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (k <= a) {
        cout << a - k << " " << b << endl;
    } else if (k <= a + b) {
        cout << 0 << " " << b - (k - a) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] b = new int[3];
		for (int i = 0; i < 3; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		int[] ab = new int[3];
		int[] ba = new int[3];
		for (int i = 0; i < 3; i++) {
			ab[i] = b[i] - a[i];
			ba[i] = a[i] - b[i];
		}
		br.close();

		int[] dp1 = new int[n + 1];
		for (int i = 0; i < 3; i++) {
			for (int w = 0; w + a[i] <= n; w++) {
				dp1[w + a[i]] = Math.max(dp1[w + a[i]], dp1[w] + ab[i]);
			}
		}
		int m = dp1[n] + n;
		long[] dp2 = new long[m + 1];
		for (int i = 0; i < 3; i++) {
			for (int w = 0; w + b[i] <= m; w++) {
				dp2[w + b[i]] = Math.max(dp2[w + b[i]], dp2[w] + ba[i]);
			}
		}
		System.out.println(dp2[m] + m);
	}
}


Measured memory_bytes: 218580
using System;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            
            var ans = "No";

            do
            {
                if (n % 7 == 0)
                {
                    ans = "Yes";
                    break;
                    }
                else
                {
                    n = n - 4;
                }
            } while (n >= 0);

            Console.WriteLine(ans);   
        }
    }
}

Measured memory_bytes: 27476
n, k = map(int, input().split())
if n <= k-1:
    print(1)
else:
    n -= (k-1)
    for s in range(1, 1000000000):
        if n > (k**s)*(k-1):
            n -= (k**s)*(k-1)
        else:
            print(s+1)
            break


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

int main(int argc, const char * argv[]) {
    string a, b;
    
    cin >> a >> b;
    
    if (a.length()>b.length()) {
        cout << "GREATER" << endl;
    }else if (a.length()<b.length()){
        cout << "LESS" << endl;
    }else{
        if(a>b){
            cout << "GREATER" << endl;
        }else if (a<b){
            cout << "LESS" << endl;
        }else{
            cout << "EQUAL" << endl;
        }
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
while True:
    n,x=map(int,input().split())
    if n==0 and x==0 :
        break
    snt=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            if j<x-i-j<=n:
                snt+=1
    print(snt)


Measured memory_bytes: 5596
#include <iostream>
using namespace std;
int main(){
  char koma[3] = {'o','x','d'},gomoku[9];
  while(cin >> gomoku[0]){
  for(int i = 1 ; i < 9 ; i++ ){
    cin >> gomoku[i];
}

  int ans = 2;
  for(int i = 0 ; i < 2 ; i++){
    if(gomoku[0] == koma[i]){
      if((gomoku[3] == koma[i] && gomoku[6] == koma[i])||
	 (gomoku[4] == koma[i] && gomoku[8] == koma[i])||
	 (gomoku[1] == koma[i] && gomoku[2] == koma[i]))ans = i;
    }
  if(gomoku[1] == koma[i] && gomoku[4] == koma[i] &&
	      gomoku[7] == koma[i])ans = i;

  if(gomoku[2] == koma[i] ){
    if(gomoku[5] == koma[i] && gomoku[8] == koma[i])ans = i;
    if(gomoku[4] == koma[i] && gomoku[6] == koma[i])ans = i;
      }

  if(gomoku[3] == koma[i] && gomoku[4] == koma[i] && gomoku[5] == koma[i])
    ans = i;

  if(gomoku[6] == koma[i] && gomoku[7] == koma[i] && gomoku[8] == koma[i])
    ans = i;
    }
  cout << koma[ans] << endl;
  }

}

Measured memory_bytes: 1132
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,s;
	scanf("%d %d %d",&a,&b,&c);
	s=a-(b+c);
	if(s<0){
		s*=-1;
	}
	if(a>b+c){
		printf("0\n");
	}
	else{
	printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
N, K = inpl()
X = inpl()
ans = 10**9

r0 = bisect_left(X, 0)

for i in range(N):
    #print(r0+i, r0-K+i+1)
    if (0 <= r0+i < N) and (0 <= r0-K+i+1 < N):
        if X[r0+i] < 0 or X[r0-K+i+1] > 0:
            continue
        #print(2*X[r0+i] - X[r0-K+i+1])
        #print(X[r0+i] - 2*X[r0-K+i+1])
        ans = min(ans, 2*X[r0+i] - X[r0-K+i+1])
        ans = min(ans, X[r0+i] - 2*X[r0-K+i+1])

if r0+K-1 < N:
    ans = min(X[r0+K-1], ans)
if r0-K >= 0:
    ans = min(-X[r0-K], ans)

print(ans)

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



class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	 int a = sc.nextInt();
    	 int b =sc.nextInt();
    	 int c =sc.nextInt();
    	 
    	 
    	 System.out.println(a*b/2);

    	 
    	
    }

}

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF INT_MAX/2
#define int long long

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int n,a,b;
    cin>>n>>a>>b;
    
    if(a>b){cout<<0<<ENT;return 0;}
    if(n==1 && a!=b){cout<<0<<ENT;return 0;}
    
    cout<<(b-a)*(n-2)+1<<ENT;
    return 0;
}

signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        if (n <= 9) {
            ans = n;
        } else if (n <= 999 && n >= 100) {
            ans = n-90;
        } else if (n <= 99999 && n >= 10000) {
            ans = n-9000-90;
        } else if (n >= 10 && n <= 99) {
            ans = 9;
        } else if (n >= 1000 && n <= 9999) {
            ans = 909;
        } else if (n == 100000) {
            ans = n-9000-90-1;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 23124
# coding:utf-8

import sys
from collections import Counter, defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


H, W = LI()
B = [[1 if s == '#' else 0 for s in S()] for _ in range(H)]


dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)

def BFS(i, j):
    ans = 0
    queue = deque([(i, j)])
    visited = set()
    visited_b = set()
    while queue:
        y, x = queue.pop()
        color = B[y][x]
        if color == 0 and (y, x) not in visited:
            # print(y, x)
            ans += 1
        if color == 1:
            visited_b.add((y, x))
        visited.add((y, x))
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if (ny, nx) in visited:
                continue

            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue

            if B[ny][nx] == color:
                continue

            queue.append((ny, nx))

    return ans, visited_b


ans = 0
visited_b = set()
for h in range(H):
    for w in range(W):
        if B[h][w] == 1 and (h, w) not in visited_b:
            tmp, v = BFS(h, w)
            ans += tmp * len(v)
            visited_b |= v
            # print(ans, v)

print(ans)


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

int main(){
    int n, cnt, z;
    vector<int> v;
    scanf("%d", &n);

    for (int i = 0; i < n; i++){
        //scanf("%d", &z);
        cin >> z;
        z--;
        v.push_back(z);
    } 

    int now = 0;
    for (int i = 0; i <= n; i++){
        if (now == 1){
            printf("%d\n" ,i);
            break;
        }

        if (i == n){
            printf("-1\n");
            break;
        }
        now = v.at(now);
    }

    return 0;
}

Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(long.Parse).ToArray();
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            while (a[i] > 0 && a[i] % 2 == 0)
            {
                a[i] /= 2;
                ans++;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 29520
n=int(input())
x=0 #太郎のポイント
y=0 #花子のポイント
for i in range(n):
    a,b=input().split()
    if a<b:
        y+=3
    elif a==b:
        x+=1
        y+=1
    else:
        x+=3
print(x,y)


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

int main(){
  long long LARGE = pow(10,9)+7;
  long long N; cin >> N;
  string s; cin >> s;
  map<char,long long> mp_count;
  for(char i='a';i<'z'+1;i++){
    mp_count[i] = 0;
  }
  REP(i,N){
    mp_count[ s[i] ]++;
  }
  long long r = 1;
  for(char i='a';i<'z'+1;i++){
    r *= (mp_count[i]+1);
    r %= LARGE;
  }
  r--;
  cout << r << "\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;
int n,m;
deque<int>d;
bool cmp(int u,int v){
	return u%2<v%2;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	d.resize(m);
	for(int i=0; i<m ;i++) cin >> d[i];
	sort(d.begin(),d.end(),cmp);
	if(m>=3 && d[m-3]%2){
		cout << "Impossible\n";
		return 0;
	}
	d.push_front(d.back());
	d.pop_back();
	for(auto cur:d) cout << cur << ' ';
	cout << endl;
	d[0]--;
	if(d.size()==1) d.push_back(0);
	d.back()++;
	if(d[0]==0) d.pop_front();
	cout << d.size() << endl;
	for(auto cur:d) cout << cur << ' ';
	cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int main() {
    int n;
    scanf("%d", &n);
    ll ans = 0;
    ll s = 0;
    map<ll, ll> q;
    q[0] = 1;
    forn(i, 0, n) {
        ll x;
        scanf("%llu", &x);
        s += x;
        if (q.count(s)) {
            ans += q[s];
        }
        q[s]++;
    }
    printf("%llu\n", ans);
    return 0;
}



Measured memory_bytes: 12800
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];

        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        Arrays.sort(a);
        Arrays.sort(b);

        int ans = ( H + a[N-1] - 1) / a[N-1];

        int i = 0;
        for(int j = 0; j < N; j++){
            int tmp = 0;
            i++;
            H -= b[N - i];
            if(H <= 0){
                H = 0;
            }

            tmp = i + ( H + a[N-1] - 1) / a[N-1];

            ans = Math.min(ans, tmp);

            if(H < 0){
                break;
            }
        }

        System.out.println(ans);
    }
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x  first
#define y  second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(i,z,n)for(int i=z;i<n;i++)
#define all(v)    v.begin(),v.end()

//int a[200002]={};
//ll b[200002]={};
ll n,m;

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[s.size()-1]=='s')cout<<s+"es";
        else cout<<s+"s";
    }
    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>

using namespace std;

int main() {
	int a,b;
	while(scanf("%d %d",&a,&b),a||b) {
		int t=b-a;
		printf("%d %d %d\n",t%1000%500/100,t%1000/500,t/1000);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

ll H, W;
ll black;
ll white;
vector<string> S;
vector<vector<bool>> used;

void dfs(int x, int y, char n) {
    if (used[y][x] || n == S[y][x]) return;
    if (n == '#' && S[y][x] == '.') white++;
    if (n == '.' && S[y][x] == '#') black++;
    used[y][x] = true;
    if (y + 1 < H) dfs(x, y + 1, S[y][x]);
    if (y - 1 >= 0) dfs(x, y - 1, S[y][x]);
    if (x + 1 < W) dfs(x + 1, y, S[y][x]);
    if (x - 1 >= 0) dfs(x - 1, y, S[y][x]);
}

int main()
{
    cin >> H >> W;
    S = vector<string>(H);
    used = vector<vector<bool>>(H, vector<bool>(W, false));
    rep(i, H) cin >> S[i];

    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            if (used[i][j]) continue;
            dfs(j, i, '-');
            if (S[i][j] == '.') white++;
            else black++;
            ans += black * white;
            white = 0;
            black = 0;
            // cout << i << ":" << j << " " << black << " " << white << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N=0;
  int A[200010]={0};
  int count[200010]={0};
  scanf("%d",&N );
  for(int i=1;i<N;i++){
    scanf("%d",&A[i] );
    count[A[i]-1]++;
  }
  for(int i=0;i<N;i++){
    printf("%d\n",count[i]);
  }

  return 0;
}

Measured memory_bytes: 3292
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N,sum_N=0,R;
        N=sc.nextInt();
        R=N;
        while(R!=0){
            sum_N+=R%10;
            R=R/10;
        }
        if(N%sum_N==0) System.out.println("Yes");
        else System.out.println("No");
        }
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int arr[] = new int[n];
        for(int i = 0;i < n;i++)arr[i] = scan.nextInt();
        for(int i = n-1;i >= 0;i--){
            if(i != n-1)System.out.print(" ");
            System.out.print(arr[i]);
        }
        System.out.println();

        scan.close();
    }  
}


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

int main(){
	int n;
	cin >> n;
	long long a[n], b[n], ans = 0;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = n - 1; i >= 0; i--){
		a[i] += ans;
		ans += (b[i] - a[i] % b[i]) % b[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1920