akhauriyash/Code-Regression huggingface dataset:
def main():
  n, m = map(int, input().split(' '))

  if m == 0:
    print(10 ** (n - 1) if n > 1 else 0)
    return

  num_list = [0] * n
  done_list = [-1] * n

  for _ in range(m):
    s, c = map(int, input().split(' '))

    if (n > 1 and s == 1 and c == 0) or (done_list[s - 1] != -1 and done_list[s - 1] != c):
      print(-1)
      exit()

    num_list[s - 1] = c
    done_list[s - 1] = c

  if num_list[0] == 0:
    num_list[0] = 0 if n == 1 else 1

  print("".join(map(str, num_list)))

main()


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

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

int main()

{

    ll n, m;
    scanf("%lld%lld", &n, &m);
    char a[n][m];
    for(ll i=  0; i < n; i++)
    {

        for(ll j = 0; j < m; j++)
        {

            scanf(" %c", &a[i][j]);
        }
    }
    bool vis[n][m];
    mset(vis, 0);
    bool tf = 1;
    for(ll i = 0; i < n; i++)
    {
        if(tf == 0) break;
        for(ll j = 0; j < m; j++)
        {

            if(vis[i][j] || a[i][j]=='.') continue;
            ll cnt = 1;
            queue<pll> q;
            q.push(mp(i, j));
            vis[i][j] = 1;
            while(!q.empty())
            {

                pll u = q.front();
                q.pop();
                for(ll ii = 0; ii < 4; ii++)
                {

                    ll x = u.ff+dx[ii];
                    ll y = u.ss+dy[ii];
                    //cout << "XY " << x << " " << y << endl;
                    if(!vis[x][y] && x >= 0 && x < n && y >= 0 && y < m && a[x][y]=='#')
                    {

                        cnt++;
                        vis[x][y]=1;
                        q.push(mp(x,y));
                    }
                }
            }
           // cout << "CN " << " IJ " << cnt << " " << i << " " << j << endl;
            if(cnt==1)
            {

                tf = 0;
                break;
            }
        }
    }
    if(tf) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

using Graph = vector<vector<int>>;
/* topo_sort(G): グラフG をトポロジカルソート
    返り値: トポロジカルソートされた頂点番号
    計算量: O(|E|+|V|)
 */
void dfs(Graph &G, int v, vector<bool> &used, vector<int> &ans) {
    used[v] = true;
    for (int e : G[v]) {
        if (!used[e]) {
            dfs(G, e, used, ans);
        }
    }
    ans.push_back(v);  // 帰りがけにpush_back
}
vector<int> topo_sort(Graph &G) {  // bfs
    vector<int> ans;
    int n = (int)G.size();
    vector<bool> used(n, false);
    for (int v = 0; v < n; v++) {  // 未探索の頂点ごとにDFS
        if (!used[v]) dfs(G, v, used, ans);
    }
    reverse(ans.begin(), ans.end());  // 逆向きなのでひっくり返す
    return ans;
}

signed main(){
  int n,m;cin>>n>>m;
  Graph g(n);
  Graph rg(n);
  ivec tj(n);
  ivec ans(n);
  rep(i,n+m-1){
    int a,b;cin>>a>>b;a--;b--;
    g[a].pb(b);
    rg[b].pb(a);
  }
  ivec topo=topo_sort(g);
  rep(i,n)tj[topo[i]]=i;
  for(int v:topo){
    if(v==topo[0]){
      ans[v]=0;
      continue;
    }
    int ma=-1;
    int res=-10;
    for(int w:rg[v]){
      //cout<<tj[w]<<endl;
      if(ma<tj[w])ma=tj[w],res=w;
    }
    ans[v]=res+1;
  }
  rep(i,n)cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 21964
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b;cin >> a >> b;
  cout << a*a-b << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

//累積和　

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

  vl sum(N + 1, 0);
  map<ll, ll> num;

  FOR(i, 1, N + 1) {
    ll a;
    cin >> a;
    sum[i] = sum[i - 1] + a;
  }

  FOR(i, 0, N + 1) { num[sum[i]]++; }

  ll res = 0;
  for (auto it : num) {
    long long num = it.second;  // it.first が it.second 個ある
    res += num * (num - 1) / 2;
  }

  cout << res << endl;
}

Measured memory_bytes: 14336
K=int(input())
A,B=input().split()
A=int(A)
B=int(B)
C=A%K
if (1<=A<=B<=1000)and(1<=K<=1000):
    if B-A>=K-1:
        print("OK")
    else:
        if C==0:
            print("OK")
        elif A+K-C<=B:
            print("OK")
        elif A+K-C>B:
            print("NG")

Measured memory_bytes: 9140
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// g++ -std=c++11 prac.cpp
ll Max=-1,Min=1e9+1;

int main(){
    ll c,x=0,y=0,n,m,k,l,r,w,sum1=0,sum2=0,ans=0;
    string s,t;
    bool f=true;
    cin >> n >> m >> s;
    VI a(n+1);
    rep(i,n){
        if(s[i]=='A'&& s[i+1]=='C')
            a[i+1] = a[i] + 1;
        else
            a[i+1] = a[i];
    }

    rep(i,m){
        cin >> l >> r;
        cout << a[r-1] - a[l-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    string s;
    bool flg=false;
    int cnt=0;
    int temp=0;
    cin>>s;
    reps(i,2,s.size()-1){
      if(s[i]=='C'&&s[0]=='A'){
        if(cnt>0){
          flg=false;
          break;
         }
        cnt++;
        flg=true;
        temp=i;
      }
    }
    reps(i,1,s.size()){
      if(i!=temp&&s[i]-'Z'<0) {
        flg=false;
      }
    }
    if(flg) cout<<"AC"<<endl;
    else    cout<<"WA"<<endl;
    return 0;
}


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

int main() {
  int r,D,x;
  scanf("%d %d %d", &r,&D,&x);

  int hold=x;
  
  for(int i=0;i<10;i++){
    hold = hold*r-D;
    cout << hold << endl;
  }

}



Measured memory_bytes: 256
local ior = io.input()
local n, m = ior:read("*n", "*n")
local t = {}
for i = 1, m do t[i] = 0 end
for i = 1, n do
  local k = ior:read("*n")
  for j = 1, k do
    local a = ior:read("*n")
    t[a] = t[a] + 1
  end
end
local cnt = 0
for i = 1, m do
  if(t[i] == n) then cnt = cnt + 1 end
end
print(cnt)


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
	char s1[16], s2[16], s3[16];
	if (scanf("%15s%15s%15s", s1, s2, s3) != 3) return 1;
	printf("%c%c%c\n",
		toupper((unsigned char)s1[0]), toupper((unsigned char)s2[0]), toupper((unsigned char)s3[0]));
	return 0;
}


Measured memory_bytes: 128
/*    Isn't it lovely, all alone?              */
/*    Heart made of glass, my mind of stone    */
/*    Tear me to pieces, skin to bone          */
/*    Hello, welcome home                      */

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;


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

ll t=1;
//cin>>t;
while(t--)
{

ll n;
cin>>n;
ll a[n],i;
for(i=0;i<n;i++)
cin>>a[i];

ll has[100009]={0};

for(i=0;i<n;i++)
has[a[i]]++;

ll sum=0;
for(i=0;i<n;i++)
sum=sum+a[i];



ll q;
cin>>q;


for(i=1;i<=q;i++)
{
  ll b,c;
  cin>>b>>c;

 sum-=has[b]*b;


ll te=has[b];

 has[c]+=has[b];
has[b]=0;
 sum+=te*c;
   cout<<sum<<endl;

}




}
return 0;
}



















Measured memory_bytes: 5212
l = ['L', 'R', 'U', 'D']
s = list(input())
ans = 'Yes'
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == 'L':
      ans = 'No'
      break
  if i % 2 == 1:
    if s[i] == 'R':
      ans = 'No'
      break
print(ans)

Measured memory_bytes: 3060
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;

int dp[26][100005];
 
signed main()
{
    tezz

    string s, t;
    cin>>s>>t;
    int n = s.length();

    for(int i=0;i<=n;i++) for(int j=0;j<26;j++) dp[j][i] = MAX;
    
    for(int i=n-2;i>=0;i--){
        for(int j=0;j<26;j++){
            if(j+'a' == s[i+1]) dp[j][i+1] = i+2;
            else dp[j][i+1] = dp[j][i+2];
        }
    }
    for(int j=0;j<26;j++){
        if(j+'a' == s[0]) dp[j][0] = 1;
        else dp[j][0] = dp[j][1];
    }

    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<26;j++) if(dp[j][i] >= 0) cout<<(char)(j+'a')<<" --> "<<dp[j][i]<<endl;
    //     cout<<endl;
    // }

    int l = t.length();
    int curr = 0, len = 0;

    for(int i=0;i<l;i++){
        char c = t[i];
        if(dp[c-'a'][0] == MAX) {cout<<-1; return 0;}

        int temp = dp[c-'a'][curr];
        
        if(temp == MAX){
            len += (n - curr);
            // cout<<len<<' ';
            curr = 0;
            curr = dp[c-'a'][curr];
            len += curr;
        }
        else{
            len += (temp - curr);
            curr = temp;
        }

        // cout<<len<<endl;
    }
    // cout<<endl;

    cout<<len;
} 

Measured memory_bytes: 20944
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long h;
  cin>>h;
  if(h==1){
      cout<<1;
      return 0;
  }
  long long ans = 1LL << (64-__builtin_clzll(h));
  cout<<ans-1<<"\n";
  return 0;
}



Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll h[225816];

int main(void){
	int n,k,i;
	ll ans=0ll;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	sort(h,h+n,greater<ll>());
	for(i=k; i<n; ++i){
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  int a,b; cin>>a>>b; Cout((a*3+b)/2);
}












Measured memory_bytes: 256
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
count_right = 0
count_left = 0
for i in a:
    if i > x:
        count_right += 1
    elif i < x:
        count_left += 1

ans = count_right if count_left > count_right else count_left
print(ans)

Measured memory_bytes: 3060
n = int(input())
lists = []
limit = []
cost = [0 for _ in range(n)]
for i in range(n):
    a, b = (map(int,input().split()))
    lists.append([a,b])

lists.sort(key = lambda x:x[1])
sum_ = 0
for i in range(n):
    sum_ = sum_ + lists[i][0]
    if sum_ <= lists[i][1]:
        continue
    else:
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 39696
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long 
#define mod 1000000007

ll fact(ll n)
{
	if(n==1) return 1;
	else
	{
		return (n*(fact(n-1)%mod)%mod);
	} 
}

int main()
{
	ll n,k;
	cin>>n>>k;
	if(abs(n-k)>1)
	{
		cout<<0<<endl;
		return 0;
	}
	else if(abs(n-k)==1)
	{
		cout<<(fact(n)*fact(k))%mod<<endl;
	}
	else
	{
		cout<<(2*(fact(n)*fact(k))%mod)%mod<<endl;
	}
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
struct pos {
  int x;
  int y;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int whiteCount = 0;
int X, Y;
vector<pos> directions = {
    {.x = 0, .y = 1},
    {.x = 1, .y = 0},
    {.x = 0, .y = -1},
    {.x = -1, .y = 0},
};
vector<vector<char>> grid;
vector<vector<int>> points;
int main(void) {
  cin >> Y >> X;

  grid.resize(Y);
  points.resize(Y);
  rep(y, Y) {
    grid[y].resize(X);
    points[y].resize(X);
    string tmp;
    cin >> tmp;
    rep(x, X) {
      grid[y][x] = tmp[x];
      if (tmp[x] == '.') {
        whiteCount++;
      }
      points[y][x] = INF;
    }
  }

  points[0][0] = 1;
  queue<pos> keep;
  pos start = {.x = 0, .y = 0};
  keep.push(start);

  while (keep.size() > 0) {
    pos current = keep.front();
    keep.pop();

    for (pos direction : directions) {
      int newX = current.x + direction.x;
      int newY = current.y + direction.y;

      if (newX < 0 || newX >= X || newY < 0 || newY >= Y) continue;
      char val = grid[newY][newX];
      if (val != '.') continue;

      grid[newY][newX] = '#';
      points[newY][newX] =
          min(points[newY][newX], points[current.y][current.x] + 1);

      if (newX == X - 1 && newY == Y - 1) {
        cout << whiteCount - points[newY][newX] << endl;
        return 0;
      }
      keep.push(pos{.x = newX, .y = newY});
    }
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
best = 9999999999
for i in range(len(s)-2):
    v = int(s[i:i+3])
    best = min(best, abs(v-753))
print(best)


Measured memory_bytes: 2940
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)

ab=[a[i]+b[i] for i in range(n)]

ab.sort(reverse=True)
asum=sum(ab[::2])
print(asum-sum(b))





Measured memory_bytes: 21152
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int

	fmt.Scan(&n, &m)

	var lights = make([][]int, m)
	for i := 0; i < m; i++ {
		var k int
		fmt.Scan(&k)

		var light = make([]int, k)
		for j := 0; j < k; j++ {
			var s int
			fmt.Scan(&s)
			light[j] = s - 1
		}

		lights[i] = light
	}

	var ps = make([]int, m)
	for i := 0; i < m; i++ {
		var p int
		fmt.Scan(&p)
		ps[i] = p
	}

	var result = 0
	for i := 0; i < int(math.Pow(2.0, float64(n))); i++ {
		var temp = i
		var j = 0
		var ss = make([]int, n)

		for temp > 0 {
			ss[j] = temp % 2

			temp /= 2
			j++
		}

		for i, light := range lights {
			var sum = 0
			for _, l := range light {
				sum += ss[l]
			}

			if sum%2 != ps[i] {
				goto NEXT_PATTERN
			}
		}
		result++

	NEXT_PATTERN:
	}

	fmt.Println(result)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string l; cin >> l;
  ll n = l.size();
  vector<ll> li(n);
  rep(i, n) li[i] = l[i] - '0';
  ll cnt = 0;
  ll ans = 0;
  rep(i, n - 1) {
      if(li[i] == 1) { 
        ll plu = myPow(3, n - 1 - i, mod);
        plu *= myPow(2, cnt, mod);
        plu %= mod;
        ans += plu;
        ans %= mod;
        cnt++;
      }
  }
  if(li[n-1] == 0) {
      ll plu = myPow(2, cnt, mod);
      ans += plu;
  }
  if(li[n-1] == 1) {
      ll plu = 3 * myPow(2, cnt, mod);
      ans += plu;
  }
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> vec(n+1,0);
    int d;

    for(int i=0;i<k;i++){
    	cin>>d;
    	int a;
    	for(int j=0;j<d;j++){
    		cin>>a;
    		vec[a] = 1;
    	}
    }
    int cnt = 0;
    for(int i=1;i<=n;i++){
    	if(vec[i]==0){
    		cnt++;
    	}
    }
    cout<<cnt<<endl;
    return 0;

}

Measured memory_bytes: 3664
N, K = gets.strip.split.map(&:to_i)

ans=0.0

(1..N).each do |i|
	if K<=i
	  ans+=(1.0/N)
	  next
	end
	x=1.0
	j=i
	while j<K
		j*=2
		x*=0.5
	end
	ans+=(1.0/N)*x;
end




puts ans


Measured memory_bytes: 3836
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ans = Integer.MAX_VALUE;
		for (int i = 1; i < n; i++) {
			int a = i;
			int b = n - i;
			int sum = 0;
			while (a > 0) {
				sum += a % 10;
				a /= 10;
			}
			while (b > 0) {
				sum += b % 10;
				b /= 10;
			}
			ans = Math.min(ans, sum);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  const X = inp[0].split(' ').map(n => Number(n));
  
  let sum = 0
  for (let i = 0; i < N; i++) {
    sum += X[i]
  }
  let ave = Math.round(sum / N)

  let cost = 0
  for (let i = 0; i < N; i++) {
    cost += Math.pow(X[i] - ave, 2)
  }
  console.log(cost)
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
using T = tuple<ll,ll,ll>;
int X,Y,Z;
int N;
T h[100100];
ll bsum[100100];
ll cb[100100];
ll asum[100100];
ll ca[100100];
priority_queue<ll> q;
int main(){
  cin >> X >> Y >> Z;
  N = X+Y+Z;
  for(int i=0;i<N;i++){
    ll a,b,c;
    cin >> a >> b >> c;
    h[i] = make_tuple(a,b,c);
  }
  sort(h,h+N,[](T a,T b){return get<0>(a)-get<1>(a) < get<0>(b)-get<1>(b);});
  // for(int i=0;i<N;i++){
  //   ll a,b,c;
  //   tie(a,b,c) = h[i];
  //   cout << a << ' ' << b << ' ' << c << endl;
  // }
  ll bs = 0ll;
  for(int i=0;i<Y;i++){
    bs += get<1>(h[i]);
    ll d = get<2>(h[i])-get<1>(h[i]);
    q.push(d);
  }
  bsum[Y-1] = bs;
  cb[Y-1] = 0ll;
  for(int i=0;i<Z;i++){
    bsum[Y+i] = bsum[Y+i-1]+get<1>(h[Y+i]);
    ll d = get<2>(h[Y+i])-get<1>(h[Y+i]);
    q.push(d);
    cb[Y+i] = cb[Y+i-1]+q.top();
    q.pop();
  }
  while(!q.empty()){q.pop();}

  ll as = 0ll;
  for(int i=0;i<X;i++){
    as += get<0>(h[N-1-i]);
    ll d = get<2>(h[N-1-i])-get<0>(h[N-1-i]);
    q.push(d);
  }
  asum[N-X] = as;
  cb[N-X] = 0ll;
  for(int i=0;i<Z;i++){
    asum[N-X-1-i] = asum[N-X-i]+get<0>(h[N-X-1-i]);
    ll d = get<2>(h[N-X-1-i])-get<0>(h[N-X-1-i]);
    q.push(d);
    ca[N-X-1-i] = ca[N-X-i]+q.top();
    q.pop();
  }
  // for(int i=0;i<5;i++){
  //   cout << asum[i] << ' ';
  // }
  // cout << endl;
  // for(int i=0;i<5;i++){
  //   cout << bsum[i] << ' ';
  // }
  // cout << endl;
  // for(int i=0;i<5;i++){
  //   cout << cb[i] << ' ';
  // }
  // cout << endl;
  // for(int i=0;i<5;i++){
  //   cout << ca[i] << ' ';
  // }
  // cout << endl;
  ll ans = 0ll;
  for(int i=Y-1;i<N-X;i++){
    ans = max(ans,bsum[i]+cb[i]+asum[i+1]+ca[i+1]);
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private int A, B;
        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
        }

        private bool F(int n)
        {
            var s = n.ToString();
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != s[s.Length - 1 - i])
                {
                    return false;
                }
            }
            return true;
        }

        public void Solve()
        {
            Scan();
            int c = 0;
            for (int i = A; i <= B; i++)
            {
                if (F(i)) c++;
            }
            Console.WriteLine(c);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
int main()
{
  int a;
  scanf("%d",&a);
  
  int b,c;
  
  b = a/100; c = a%100;
  
  if(1<=b&&b<=12)
	b=1;
  else 
	b=0;

  if(1<=c&&c<=12)
	c=1;
  else 
	c=0;

  if(c&&b)
	printf("AMBIGUOUS");
  if(c&&!b)
	printf("YYMM");
  if(!c&&b)
	printf("MMYY");
  if(!c&&!b)
	printf("NA");
	  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=1001 ;
int main()
{
   fast ;
   ll h ;
   cin>>h ;
   ll ans=0 ;
   ll cnt=1 ;
   while(h>0)
   {
       ans+=cnt ;
       h/=2 ;
       cnt*=2 ;
   }
   cout<<ans ;

}


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

int main(){
    ll N;
    cin >> N;
    ll min = pow(10,12);
    for (int i = 1; i <= pow(10,6); i++) {
        if(N % i == 0 && i + N / i - 2 < min){
            min = i + N / i - 2;
        }
    }
    cout << min << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int s3 = a % 10;
  int s2 = a / 10 % 10;
  int s1 = a / 100;
  cout << s1 + s2 + s3  << endl;
}

Measured memory_bytes: 384
// hmmmm ...coool
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int x, y;
		cin>>x>>y;
		if(y<2*x|| (y-2*x)&1)return cout<<"No",0;
		int k = (y-2*x)/2;
		if(k > x)return cout<<"No",0;
		cout<<"Yes";
	
	
	}
	return 0;
}

Measured memory_bytes: 3632
//38
#include<iostream>

using namespace std;

char *a,*b;

void si(char **s,bool f){
  if(**s!='(')return;
  if(f){
    cout<<**s;
  }
  ++*s;
  if(**s=='('){
    si(s,f);
  }
  if(f){
    cout<<**s;
  }
  ++*s;
  if(**s=='('){
    si(s,f);
  }
  if(f){
    cout<<**s;
  }
  ++*s;
}

void op(int f){
  if(*a!='(')return;
  cout<<*a;
  a++;
  b++;
  if(!(*a==*b&&*a==',')){
    if(*a==*b){
      op(f);
    }else{
      si(&a,f);
      si(&b,f);
    }
  }
  cout<<*a;
  a++;
  b++;
  if(!(*a==*b&&*a==')')){
    if(*a==*b){
      op(f);
    }else{
      si(&a,f);
      si(&b,f);
    }
  }
  cout<<*a;
  a++;
  b++;
}
 
int main(){
  for(char o;cin>>o;){
    char sa[301],sb[301];
    a=sa;
    b=sb;
    cin>>sa>>sb;
    op(o=='u');
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1136
a,b=map(int,input().split())

if a%2==0:
  SA=(a*25)//2
  LA=SA+12

else:
  SA=((a*25)//2)+1
  LA=SA+11


A=[x for x in range(SA,LA+1)]
B=[x for x in range(b*10,b*10+9)]

X=set(A) & set(B)
if len(X)==0:
  print(-1)
else: 
  print(min(X))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
vector<vector<int>> l;

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  l.resize(s.length() + 1);
  for (int i = 0; i < l.size(); ++i) l[i].resize(t.length() + 1, 0);
  for (int i = 0; i < l.size(); ++i) {
    for (int j = 0; j < l[i].size(); ++j) {
      if (i == 0 || j == 0) {
        l[i][j] = 0;
      } else {
        if (s[i - 1] == t[j - 1]) {
          l[i][j] = 1 + l[i - 1][j - 1];
        } else {
          l[i][j] = max(l[i - 1][j], l[i][j - 1]);
        }
      }
    }
  }
  string ans = "";
  int i = s.length();
  int j = t.length();
  while (i > 0 && j > 0) {
    if (s[i - 1] == t[j - 1]) {
      ans += s[i - 1];
      i--;
      j--;
    } else {
      if (l[i - 1][j] > l[i][j - 1])
        i--;
      else
        j--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 35712
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(Int x = 0; x < n; x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (x[x.size()-1])

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  bool operator< (const Point &p1) {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

bool compX (const Point &p1, const Point &p2) {
  return p1.x < p2.x;
}

bool compY (const Point &p1, const Point &p2) {
  return p1.y < p2.y;
}

string S;

void input() {
  cin >> S;
}

void solve() {
  Int count = 0;
  loop(i,0,S.size()/2) {
    if (S[i] != S[S.size()-1-i]) count++;
  }
  cout << count << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
pS = [list(input().split()) for _ in range(M)]
A = [0]*N
P = [0]*N
ans_A = 0
ans_P = 0
for p,S in pS:
    p = int(p)
    if S == 'AC':
        A[p-1] = 1
    else:
        if A[p-1] == 0:
            P[p-1] += 1
idx = 0
for a,p in zip(A,P):
    if a == 1:
        ans_A += 1
        ans_P += P[idx]
    idx += 1
print(ans_A,ans_P)



Measured memory_bytes: 27444
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve() {
	int n, m, x; cin >> n >> m >> x;
	vector<bool> b(n + 1,false);
	rep(i, m) {
		int a; cin >> a;
		b[a] = true;
	}
	int s1 = 0;
	for (int i = x - 1; i >= 0; i--) {
		if (b[i])s1++;
	}
	int s2 = 0;
	for (int i = x + 1; i <= n; i++) {
		if (b[i])s2++;
	}
	cout << min(s1, s2) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

#include <vector>

/*	verified : 2020/07/18
		AOJ, Disjoint Set: Union Find Tree
		http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
*/

struct union_find {
	long long N;					// the number of nodes
	long long M;					// the number of trees
	std::vector<long long> parent;	// parent[i] := the direct parent of i
	std::vector<long long> size;	// size[i] := the number of nodes in the tree rooted to i
	vector<ll> white_cnt;
	vector<ll> black_cnt;

	union_find(long long n) : N(n), M(n) {
		parent.resize(n, -1);
		size.resize(n, 1);
		white_cnt.resize(n, 0);
		black_cnt.resize(n, 0);
	}

	long long root(long long i) {
		if (parent[i] == -1) return i;
		else return parent[i] = root(parent[i]);
	}

	bool is_united(long long i, long long j) {
		return (root(i) == root(j));
	}

	// true : unite succeeded
	bool unite(long long i, long long j) {
		i = root(i); j = root(j);
		if (i == j) return false;
		if (size[i] < size[j]) std::swap(i, j);
		parent[j] = i;
		size[i] += size[j];
		white_cnt[i] += white_cnt[j];
		black_cnt[i] += black_cnt[j];
		M--;
		return true;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (ll i = 0; i < h; i++) cin >> s[i];

	ll m = h * w;
	union_find uf(m);
	auto idx = [&] (ll i, ll j) {return i * w + j;};
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (s[i][j] == '.') uf.white_cnt[idx(i, j)]++;
			else uf.black_cnt[idx(i, j)]++;
		}
	}

	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (i < h - 1 && (s[i][j] ^ s[i + 1][j])) uf.unite(idx(i, j), idx(i + 1, j));
			if (j < w - 1 && (s[i][j] ^ s[i][j + 1])) uf.unite(idx(i, j), idx(i, j + 1));
		}
	}

	ll ans = 0;
	for (ll i = 0; i < m; i++) {
		if (uf.parent[i] == -1) {
			ans += uf.white_cnt[i] * uf.black_cnt[i];
		}
	}
	cout << ans << endl;
}

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

int a, b, c, v[105];
int main()
{
	cin >> a >> b >> c;
	for (int i = 1; i <= 100; i++) {
		if ((a * i) % b == c) {
			cout << "YES";
			return 0;
		}
	}
//	while (1) {
//		if (v[a]) break;
//		v[a] = 1;
//		if (a == c) {
//			cout << "YES";
//			return 0;
//		}
//		a = (a * ) % b;
//	}
	cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <iomanip>
#include <limits>
using namespace std;

int main() {
    int N;
    cin >> N;
    if (N < 10) {
        cout << N << endl;
    } 
    else if (10 <= N && N < 100) {
        cout << 9 << endl;
    }
    else if (100<= N && N < 1000) {
        cout << 10 + 100 * (N / 100 - 1) + (N % 100) << endl;
    }
    else if (1000 <= N && N < 10000) {
        cout << 909 << endl;
    }
    else  if (10000 <= N  && N < 100000){
        cout << 910 + 10000 * (N / 10000 - 1) + N % 10000 << endl;
    }
    else {
        cout << 90909 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int cnt[MAX_N];
vector<int> G[MAX_N];
int flag[MAX_N];

void dfs(int u,int k,int& sm,bool& nibu)
{
    flag[u] = k;
    sm++;
    rep(i,len(G[u])){
        if(flag[G[u][i]] == 0){
            dfs(G[u][i],-k,sm,nibu);
        }else if(flag[G[u][i]] == k){
            nibu = false;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].pb(b),G[b].pb(a);
    }
    ll x=0,y=0,z=0;
    rep(i,n){
        if(flag[i] == 0){
            int kazu = 0;
            bool nibu = true;
            dfs(i,1,kazu,nibu);
            if(kazu == 1){
                z++;
            }else if(nibu){
                y++;
            }else{
                x++;
            }
        }
    }
    cout << x*x+2*x*y+2*y*y+2*z*n-z*z << "\n";
    return 0;
}


Measured memory_bytes: 11776
n = int(input())
a = [int(input()) for _ in range(n)]
b = [0]
target = 0
count = 0
while(True):
    target = a[target] - 1
    count += 1
    if count > n:
        print("-1")
        break
    if target == 1:
        print(count)
        break

Measured memory_bytes: 7084
#include<stdio.h>

int main(){
		int n,ans=0;
		scanf("%d",&n);
		if(n<=10)ans=n;
		else if(n==100||n==1000||n==10000||n==100000)ans=10;
		else {
				while(n>0){
						int tmp=n%10;
						ans+=tmp;
						n=(n-tmp)/10;
				}
		}
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define d_flag 0
#define MAX 100000
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)<(b)?(b):(a))
#define abs(a) max((a),-(a))
typedef long int li;

int main(){
  int n,W;
  scanf("%d%d",&n,&W);
  int i,j,w[n];
  li v[n],ans=0,dp[MAX+1]={};
  
  for(i=0;i<n;i++){
    scanf("%d%ld",&w[i],&v[i]);
  }
  for(j=0;j<n;j++){
    for(i=W;i>=0;i--){
      if(w[j]<=i && dp[i]<v[j]+dp[i-w[j]]) dp[i]=v[j]+dp[i-w[j]];
      if(ans<dp[i]) ans=dp[i];
    }
  }


  if(d_flag){
    for(i=0;i<=W;i++)
      printf(" %d",dp[i]);
    printf("\n");
  }
  printf("%ld",ans);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


vector<vll> dp(3001, vll(3001, vl(4, -INF)));
vll a(3001, vl(3001));

signed main() {
    fio();
    int h, w, k;
    cin >> h >> w >> k;
    rep (i, k) {
        int r, c, v;
        cin >> r >> c >> v;
        r--; c--;
        a[r][c] = v;
    }

    dp[0][0][0] = 0;
    dp[0][0][1] = a[0][0];
    rep (i, h) {
        rep (j, w) {
            rep (k, 4) {
                chmax(dp[i + 1][j][0], dp[i][j][k]);
                chmax(dp[i + 1][j][1], dp[i][j][k] + a[i + 1][j]);
                chmax(dp[i][j + 1][k], dp[i][j][k]);
                if (k != 3) {
                    chmax(dp[i][j + 1][k + 1], dp[i][j][k] + a[i][j + 1]);
                }
            }
        }
    }

    ll ans = -INF;
    rep (i, 4) chmax(ans, dp[h - 1][w - 1][i]);
    cout << ans << endl;
}

Measured memory_bytes: 707464
#include<stdio.h>
int main(void)
{
	int n,i,a[10000];
	long long sum=0,max=-1000000,min=1000000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>=max){
			max=a[i];
		}
		if(a[i]<=min){
			min=a[i];
		}
		sum=sum+a[i];
	}
	printf("%lld %lld %lld\n",min,max,sum);
	
	return 0;
}

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

using namespace std;

int main(){
	int T, N, D;
	cin>>T;
	for(int i=0; i<T; i++){
		cin>>N>>D;
		cout<<127*(N-1)+((N-1)%2 ? (int)(unsigned char)(~D)-128 : D)<<endl;
	}

	return 0;
}

Measured memory_bytes: 256