akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h+2], t;

    s[0] = string(w+2, '.');
    s[h+1] = string(w+2, '.');

    for(int i=1; i<h+1; i++) {
        cin >> t;
        s[i] = '.' + t + '.';
    }

    int a[4] = {1, 0, -1, 0};
    int b[4] = {0, 1, 0, -1};

    for(int i=1; i<h+1; i++) {
        for(int j=1; j<w+1; j++) {
            if(s[i][j]=='#') {
                bool flag=false;
                for(int k=0; k<4; k++) {
                    if(s[i+a[k]][j+b[k]]=='#') flag=true;
                }
                if(!flag) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


string s;

int main(){
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '9') cout << '1';
		else cout << '9';
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
   int a, b;
   cin >> a >> b;
   if((a+b)%2!=0) out("IMPOSSIBLE");
   else out((a+b)/2);

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
  ll n,ans=0,neg_cnt=0,pos_cnt=0,pos_tmp=0;
  bool flag=true;
  priority_queue<ll,vector<ll>> que;
  cin >> n;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
    if(a[i]>b[i]){
      que.push(a[i]-b[i]);
    }
  }
  for(int i=0;i<n;i++){
    if(a[i]<b[i]){
      ans++;
      ll tmp=b[i]-a[i];
      while(!que.empty()&&pos_tmp<tmp){
        ll num = que.top(); que.pop();
        pos_tmp+=num;
        ans++;
      }
      if(pos_tmp<tmp){
        flag=false;
        break;
      }else{
        pos_tmp-=tmp;
      }
    }
  }
  if(flag) cout << ans<<endl;
  else cout <<"-1\n";
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,m,c;
  cin>>n>>m>>c;
  int b[22];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=c;
    for(int j=0;j<m;j++){
	 int a;
	 cin>>a;
	 sum+=a*b[j];
    }
    if(sum>0)ans++;
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    long long n,m;
    cin>>n;
    vector<long long> hh(100000,0);
    vector<long long> hhh(100000,0);
    for(int i=0;i<n;i++){
        cin>>hh.at(i);
    }
    hhh.at(1)=abs(hh.at(0)-hh.at(1));
    for(int i=2;i<n;i++){
            hhh.at(i)=min(hhh.at(i-2)+abs(hh.at(i)-hh.at(i-2)),hhh.at(i-1)+abs(hh.at(i)-hh.at(i-1)));
        if(i==n-1){
            
        }
    }
cout<<hhh.at(n-1)<<'\n';
    return(0);
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <typename First> void Exit(First first){cout << first << endl;exit(0); };

int main(){
    iosetup;
    int a, b, c; cin >> a >> b >> c;
    cout << a * b / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()

ans = 0
c = '?'
x = 0
for i in range(len(s)):
    if c == '?':
        c = s[i]
        x = 1
    elif c != s[i]:
        x -= 1
        ans += 2
        if x == 0:
            c = '?'
    else:
        x += 1

print(ans)


Measured memory_bytes: 3188
A,B,AB,X,Y=map(int,input().split())
ans1=A*X+B*Y
ans2=2*AB*max(X,Y)
if X<Y:
    ans3=2*AB*X+B*(Y-X)
else:
    ans3=2*AB*Y+A*(X-Y)
print(min(ans1,ans2,ans3))


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

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

  std::vector<int> a(N - 1), b(N - 1), deg(N);
  std::vector<std::vector<int>> from(N);
  std::vector<std::pair<int, int>> edge;
  rep(i, N - 1) {
    std::cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    ++deg[a[i]];
    ++deg[b[i]];
    from[a[i]].push_back(b[i]);
    from[b[i]].push_back(a[i]);
    edge.emplace_back(a[i], b[i]);
  }

  int K = 0;
  rep(i, N - 1) {
    K = std::max(K, deg[i]);
  }
  std::cout << K << '\n';

  std::map<std::pair<int, int>, int> ans;
  std::vector<int> in_color(N);
  std::vector<bool> hist(N);
  std::queue<int> q;
  q.push(0);
  hist[0] = true;

  while(! q.empty()) {
    int u = q.front(); q.pop();

    int c = 1;
    for(int v : from[u]) {
      if(hist[v]) continue;
      if(c == in_color[u]) {
        ++c;
      }
      in_color[v] = ans[std::make_pair(u, v)] = ans[std::make_pair(v, u)] = c++;
      q.push(v);
      hist[v] = true;
    }
  }

  rep(i, N - 1) {
    std::cout << ans[edge[i]] << '\n';
  }


}


Measured memory_bytes: 20852
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
typedef long long ll;
const int mod=1e9+7;
const int N=86400;
int main()
{
    int r,g;
    while(~scanf("%d%d",&r,&g))
    {
        int ans=2*g-r;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	auto isFour = false;
	for (auto i = 0; i < N; ++i)
	{
		char S;
		cin >> S;
		if (S == 'Y')
		{
			isFour = true;
		}
	}

	if (isFour)
	{
		cout << "Four" << endl;
	}
	else
	{
		cout << "Three" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, a, b, c);

  puts(max({a, b, c}) == min({a, b, c}) ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <ctime>
#include <string>
#include <iostream>
#include <bitset>
#define PII pair <int, int>
#define PPI pair <PII, int>
#define x first
#define y second
#define P 998244353

using namespace std;

typedef long long ll;

int N, X;

int F[2][6010][2][2], G[3010][6010], C[6010][6010];

void add(int &x, int y) {
    x = (x + y) % P;
}
int main() {
    scanf("%d%d", &N, &X);
    G[0][0] = 1;
    int ans = 0;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < X; j++) {
            add(G[i + 1][j], G[i][j]);
            add(G[i + 1][j + 1], G[i][j]);
            add(G[i + 1][j + 2], G[i][j]);
        }
    if(X % 2 == 1) {
        for(int i = 0; i <= N; i++)
            for(int j = 0; j <= i; j++)
                C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % P;
        for(int i = X; i <= N; i++)
            add(ans, C[N][i]);
    }
    for(int i = 0; i < X; i++) add(ans, G[N][i]);
    int a = 0, b = 1;
    memset(F, 0, sizeof F);
    F[a][0][0][1 - 1] = 1;
    for(int i = 0; i < N - 1; i++, swap(a, b)) {
        memset(F[b], 0, sizeof F[b]);
        for(int o = 0; o < X; o++)
            for(int s = 0; s < 2; s++)
                for(int k = 1; k < 3; k++) if(F[a][o][s][k - 1])
                    for(int l = 0; l + k < 3; l++) {
                        add(F[b][o + l][s][k + l - 1], F[a][o][s][k - 1]);
                        if(l) add(F[b][o + l][!s][l - 1], F[a][o][s][k - 1]);
                    }
        for(int o = 1; o < X; o++)
            for(int k = 1; k < 3; k++)
                for(int l = 1; l + k < 3; l++)
                    add(ans, 1LL * F[b][o][1][k - 1] * G[N - i - 2][X - 1 - o - l] % P);
    }
    printf("%d\n", (ans % P + P) % P);
    return 0;
}

Measured memory_bytes: 142720
#include<stdio.h>
int main(void)
{
	int a,c,x,b,e=0;
	double d ;

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

	for(x=a;x<=b;x++)
	{
		d = c%x;
		
		if(d==0)
		{
			e++;
		}
		
	}

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

Measured memory_bytes: 596
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    B = [input() for _ in range(N)]
    M = int(input())
    R = [input() for _ in range(M)]

    ans = -9999999999999

    for b in B:
        cnt = 0

        for bb in B:
            if b == bb:
                cnt += 1

        for r in R:
            if r == b:
                cnt -= 1

        ans = max(cnt, ans)

    print(max(ans, 0))


main()


Measured memory_bytes: 4860
n=int(input())
p=list(map(int,input().split()))
sum=0
for i in range(1,n-1):
    if p[i]>=p[i-1] and p[i]<=p[i+1]:
        sum+=1
    elif p[i]>=p[i+1] and p[i]<=p[i-1]:
        sum+=1

print(sum)

Measured memory_bytes: 3060
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {

    val n = StdIn.readInt()
    val k = StdIn.readInt()
    val x = StdIn.readInt()
    val y = StdIn.readInt()

    val `after k+1` = if (n >= k) {
      (n - k) * y
    } else {
      0
    }

    val stay = if (n >= k) k else n

    println(stay * x + `after k+1`)
  }
}

Measured memory_bytes: 27332
<?php
    fscanf(STDIN, "%d %d %d %d", $a,$b,$c,$d);
	
	if($d>=diffCalc($a,$b)&&$d>=diffCalc($b,$c)){
    	echo 'Yes';
    }
	else if($d>=diffCalc($a,$c)){
    	echo 'Yes';
    } 
    else echo 'No';

	//引き算メソッド
	function diffCalc($A,$B){
      return abs($A-$B);
    }

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
int main()
{
int n,m;
cin>>n>>m;
char a[n+1][m+1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
ll dp[n+1][m+1];
memset(dp,0,sizeof(dp));
if(a[1][1]=='.')
dp[1][1]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]=='.')
dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%mod;
cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N, M; cin >> N >> M;
  priority_queue<ll, vector<ll>, less<ll>> pq;
  REP(i,N){
    ll a; cin >> a;
    pq.push(a);
  }

  ll cur = M;
  while(cur-- && !pq.empty()){
    ll p = pq.top();
    pq.pop();
    p /= 2;
    if(p==0) continue;
    pq.push(p);
  }

  ll ans = 0;
  while(!pq.empty()){
    ll p = pq.top();
    pq.pop();
    ans += p;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    int sum = 0;
    int min_num = 1000;
    rep(i, N) {
        int a;
        cin >> a;
        sum += a;
        if (a % 10 != 0) {
            min_num = min(min_num, a);
        }
    }

    if (sum % 10 == 0) {
        if (min_num == 1000)
            cout << 0 << endl;
        else
            cout << sum - min_num << endl;
    } else
        cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

const int N = 510, M = 1e5+10;
P pos[2][M*10];
int x[M];

int n, u, v, m;

int board[N][N];
bool check(int turn, P *pos, int uv){
	MEMSET(board, 0);

	for (int i = 0; i < turn; ++i){
		board[pos[x[i]].Y][pos[x[i]].X] = 1;
	}
	int cnt[2] = {};
	FOR(i, 1, n+1){
		if (board[i][i]) ++cnt[0];
		if (board[i][n+1-i]) ++cnt[1];
	}
	rep(i, n+1) rep(j, n+1){
		board[i + 1][j] += board[i][j];
		board[i][j + 1] += board[i][j];
		board[i + 1][j + 1] -= board[i][j];
	}

	int res = (cnt[0] == n) + (cnt[1] == n);
	FOR(i, 1, n+1){
		if (board[i][n+1] == n) ++res;
		if (board[n+1][i] == n) ++res;
	}

	if (n == 1) res = !!res;

	return res >= uv;
}

int main(){
	cin >> n >> u >> v >> m;
	rep(i, 2) rep(j, n) rep(k, n){
		int xx;
		cin >> xx;
		pos[i][xx] = MP(k+1, j+1);
	}
	rep(i, m) cin >> x[i];

	bool end = false;
	int lb = 0, ub = m+1;
	while (ub - lb > 1){
		int mid = (ub + lb) / 2;
		bool usa = check(mid, pos[0], u);
		bool neko = check(mid, pos[1], v);
		if (usa != neko){
			if (usa) cout << "USAGI" << endl;
			else cout << "NEKO" << endl;
			end = true;
			break;
		}
		if (usa) ub = mid;
		else lb = mid;
	}
	if (!end) cout << "DRAW" << endl;

	return 0;
}

Measured memory_bytes: 17964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++)
    {
        int pnt = i;
        double k = 1.0;
        while (true)
        {
            if (pnt >= K)
            {
                ans += (k / N);
                break;
            }
            k /= 2.0;
            pnt *= 2;
        }
    }
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

typedef long long ll;

const ll INF = 1e18;
const int BIG = 1e9;
const int maxN = 100 * 1000 + 9;
const string FILENAME = "sample";

int n;
int a[maxN], b[maxN], c[maxN], d[maxN];
bool mrk[maxN];

void read(){
	cin >> n;
	for(int i = 1; i <= n - 1; i++){
		cin >> a[i] >> b[i];
	}

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

void solv(){
	sort(c + 1, c + n + 1);
	reverse(c + 1, c + n + 1);

	mrk[a[1]] = mrk[b[1]] = true; 
	d[a[1]] = c[1], d[b[1]] = c[2];

	for(int i = 3; i <= n; i++){
		for(int j = 1; j <= n - 1; j++){
			if(mrk[a[j]] && !mrk[b[j]]){
				d[b[j]] = c[i];
				mrk[b[j]] = true;
				break;
			} else if(!mrk[a[j]] && mrk[b[j]]){
				d[a[j]] = c[i];
				mrk[a[j]] = true;
				break;
			}
		}
	}
	
	int score = 0;
	for(int i = 1; i <= n - 1; i++){
		score += min(d[a[i]], d[b[i]]);
	}
	
	cout << score << '\n';
	for(int i = 1; i <= n; i++)
		cout << d[i] << ' ';
	cout << '\n';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
#ifdef h4h4
	freopen((FILENAME + ".inp").c_str(), "r", stdin);
	freopen((FILENAME + ".out").c_str(), "w", stdout);
#endif

	read();
	solv();

	return 0;
}

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



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


	
	string a,b;

	cin>>a>>b;

	if(a.size()>b.size())
	{
		cout<<"GREATER";
	}
	else if(a.size()<b.size())
		cout<<"LESS";

	else
	{
		int j =0;
		for(int i=0;i<a.size();i++)
		{

			int x = a[i]-'0';
			int y = b[i]-'0';

		//	cout<<x<<" "<<y;
			if(x>y){
				j = 1;
				break;
			}
			else if(x<y)
			{
				j = 2 ;
				break;
			}
		}

		if(j == 0)cout<<"EQUAL";
		else if(j==1)
			cout<<"GREATER";
		else
			cout<<"LESS";

	}
    return 0;
		
}








Measured memory_bytes: 3600
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n=1;
	int CONST = 998244353;
	cin >> n;
	vector<mp::cpp_int> v(n);

	for (int i = 0; i<n-1; i++) {
		v[i] = 0;
	}

	for (int i = 0; i<n; i++) {
		int x = 0;
		cin >> x;
		if ((i == 0 && x != 0) || (i != 0 && x == 0)) {
			cout << 0;
			return 0;
		}
		v[x]++;
	}

	int max_idx = 0;
	for (int i = n-1; i>=0; i--) {
		if (v[i] != 0) {
			max_idx = i;
			break;
		}
	}

	mp::cpp_int ret = 1;
	for (int i = 1; i < max_idx; i++) {
		mp::cpp_int idx = v[i + 1];
		for (int j = 0; j < idx; j++) {
			ret = ret * v[i] % CONST;
		}
	}

	cout << ret;

	return 0;
}

Measured memory_bytes: 3328
use proconio::*;

fn main() {
    input! {
        x: i64,
        y: i64
    }

    let m = 4 * x - y;
    if m % 2 == 0 && 0 <= m && m <= 2 * x {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX + 1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2 * i;
    r = 2 * i + 1;

    //从左子结点,自身,右子结点中选出最大的结点.
    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest]) largest = r;

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}



int main(){
    cin >> H;

    for(int i=1; i<=H; i++) cin >> A[i];

    for(int i=H/2; i >= 1; i--) maxHeapify(i);

    for(int i=1; i<=H; i++) cout<<" "<<A[i];

    cout<<endl;
    return 0;
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
using namespace std;

void solve(long long H, long long W){
    if(H==2 && W==2){
        cout << 1 << endl;
        return;
    }

    auto ans = LONG_LONG_MAX;

    if(H>2) {
        // russia
        if (H % 3 > 0)ans = min(ans, W);
        else ans = 0;

        // T shape
        vector<long long> ws = {W / 2, (W + 1) / 2};
        for (long long i = 1; i < H - 1; i++) {
            auto maxa = max({ws[0] * i, ws[1] * i, W * (H - i)});
            auto mina = min({ws[0] * i, ws[1] * i, W * (H - i)});
            ans = min(ans, maxa - mina);
        }
    }
    if(W>2) {
        //bellgium
        if (W % 3 > 0)ans = min(ans, H);
        else ans = 0;


        // inversed T shape
        vector<long long> hs = {H / 2, (H + 1) / 2};
        for (long long i = 1; i < W - 1; i++) {
            auto maxa = max({hs[0] * i, hs[1] * i, H * (W - i)});
            auto mina = min({hs[0] * i, hs[1] * i, H * (W - i)});
            ans = min(ans, maxa - mina);
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define inf 0x3f3f3f3f
#define pb push_back
#define vi vector<int>
#define fi first
#define se second 
#define mp make_pair
typedef unsigned long long ull;
//typedef pair<int,int> P;
#define LL long long 
#define pi acos(-1)
#define MOD 998244353
typedef long long ll;
using namespace std;
const int maxn = 10005;
char b[maxn];
const char p[]="ACGT";
int find(char c){
	for(int i=0;i<4;i++) if(p[i]==c) return 1;
	return 0;
}
int main(){
	cin>>b;
	int k=0,q=0,n=strlen(b);
	for(int i=0;i<n;i++){
		if(find(b[i]))k++;
		else k=0;
		q=max(q,k);
	}
	cout<<q<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long

int cmpfunc(const void *a, const void *b){
    return *(int *)b - *(int *)a;
}

int main(int argc, char **argv){
    int n,i;
    scanf("%d",&n);
    ll a[n];
    for(i=0;i<n;i++) scanf("%lld",&a[i]);
    ll sum[n];
    sum[0]=a[0];
    for(i=1;i<n;i++) sum[i]=sum[i-1]+a[i];
    ll total=sum[n-1];
    //ll diff[n];
    //first ppl take sum[0] to sum[n-2]
    ll u=total-2*sum[0];
    if(u<0) u*=-1;
    ll min=u;
    for(i=1;i<=n-2;i++){
        ll ans=total-2*sum[i];
        if(ans<0) ans*=-1;
        if(ans<min) min=ans;
    }
    printf("%lld\n",min);
    return 0;
}


Measured memory_bytes: 3328
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let s =
    Array.fold_left (fun (a, s) a' -> (a', abs (a - a') + s)) (0, 0) as_
    |> (fun (a, s) -> abs a + s) in
  let f i =
    if i = 0 || i = n + 1 then 0
    else as_.(i - 1) in
  for i = 1 to n do
    Printf.printf "%d\n" @@
      s + abs (f (i - 1) - f (i + 1))
      - abs (f (i - 1) - f i)
      - abs (f i - f (i + 1))
  done

Measured memory_bytes: 6272
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>

const int INF=1001001001;
#define rep(i,n) for(int i=0;i<n;i++)
int N;
int A[200004];
long long int B[100002];


int main(){
	//FILE *fp;
	//fp=fopen("F:\\1JOI本選\\2014\\joi2014-ho-data\\joi2014-ho-data\\2014-ho-t3\\in\\03-06.txt","r");
	scanf("%d",&N);
	long long int MAX = 0;
	rep(i,N){
		scanf("%d",&A[i]);
		MAX+=A[i];
		B[i]=MAX;
	}
	memcpy(&A[N],A,sizeof(int)*N);
	
	long long int M=MAX/3;//全てのピースがM以上になる切り方は存在するか?
	long long int m=0;
	do{
		bool cann=false;//全てのピースがn以上になる切り方は存在するか?
		long long int n=(M+m)/2;
		rep(i,N-2){//どこで最初に切るか
			int a=i;//よりあとで切る
			int b=N-2;//以前で切る
			do{//次に切る場所を探す
				int c=(a+b)/2;
				long long int piece1=B[c]-B[i];
				if(piece1>=n){b=c;}//c以前で切れる
				else a=c;//cよりあとで切るべき
			}while(b>a+1);
			long long int p1=B[b]-B[i];
			if(p1<n)continue;//1個目がもうだめ
			int x=b;
			int y=N-1;
			do{//最後に切る場所を探す
				int z=(x+y)/2;
				long long int piece2=B[z]-B[b];
				if(piece2>=n){y=z;}
				else x=z;
			}while(y>x+1);
			long long int p2=B[y]-B[b];
			if(p2<n)continue;//2個目がもうだめ
			if(MAX-p1-p2>=n){cann=true;}
		}
		if(cann){m=n;}//すべて(３つ)のピースがn以上になりえる
		else{M=n;}
	}while(M>m+1);
	printf("%lld\n",m);
	return 0;
}

Measured memory_bytes: 2596
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

bool isKaibun(string s) {
  string t = s;
  reverse(s.begin(), s.end());
  return (s == t);
}

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

  string s;
  cin >> s;

  int n = s.size();
  bool flag = true;
  if (!isKaibun(s)) flag = false;
  if (!isKaibun(s.substr(0, (n-1)/2))) flag = false;
  if (!isKaibun(s.substr((n+3)/2-1, n-(n+3)/2+1))) flag = false;

  YesorNo(flag);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

vector<ll> solve(ll n, ll a, ll b) {
	ll k = (1 << n);
	vector<ll> ans(k);
	if (n == 0) {
		ans[0] = 0;
		return ans;
	}
	if (n == 1) {
		ans[0] = a;
		ans[1] = b;
		return ans;
	}
	b ^= a;
	if ((k / 2) & b) {
		vector<ll> x = solve(n - 1, 0, 1);
		vector<ll> y = solve(n - 1, 1, b - k / 2);
		for (int i = 0; i < k / 2; i++) {
			ans[i] = x[i];
			ans[i + k / 2] = y[i] + k / 2;
		}
	}
	else {
		vector<ll> x = solve(n - 1, 0, b);
		vector<ll> y = solve(n - 1, x[k / 2 - 2], b);
		for (int i = 0; i < k / 2 - 1; i++) {
			ans[i] = x[i];
		}
		for (int i = 0; i < k / 2; i++) {
			ans[i + k / 2 - 1] = y[i] + k / 2;
		}
		ans[k - 1] = x[k / 2 - 1];
	}
	for (int i = 0; i < k; i++) {
		ans[i] = (ans[i] ^ a);
	}
	return ans;
}

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		if (((1 << i)&a) != ((1 << i)&b)) {
			cnt++;
		}
	}
	if (cnt % 2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	vector<ll> ans = solve(n, a, b);
	cout << "YES" << endl;
	for (int i = 0; i < (1 << n); i++) {
		cout << ans[i] << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 3320
N = int(input())
S = input()
t = S.count(".")
if t == N or t == 0:
    print(0)
    exit(0)

W = [0 for k in range(N+1)]
B = [0 for k in range(N+1)]

for k in range(N):
    if S[k] == "#":
        B[k] = B[k-1] + 1
    else:
        B[k] = B[k-1]

W[0] = t
for k in range(N):
    if S[k] == ".":
        W[k+1] = W[k] - 1
    else:
        W[k+1] = W[k]
ans = N
for k in range(N):
    ans = min(ans,W[k+1]+B[k])
print(min(ans,t,S.count("#")))

Measured memory_bytes: 13032
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    ans = 0
    for i, a in enumerate(A, start=1):
        if i % 2 and a % 2:
            ans += 1
    print(ans)


main()


Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

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

int main() {
    int n, H;
    cin >> n;
    vector<int>x(n);
    vector<int>y(n);
    vector<int>h(n);
    map<int, int>cnt;
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    for (int i = 0; i < 101; i++){
        for (int j = 0; j < 101; j++){
            H = -1;
            bool ok = true;
            rep(k, n){
                if (h[k] == 0) continue;
                int A = abs(i - x[k]) + abs(j - y[k]) + h[k];
                if (H == -1) {
                    H = A;
                } else if (H != A) {
                    ok = false;
                }
            }
            if (!ok) continue;
            rep(k, n) {
                int A = max(H - abs(i - x[k]) - abs(j - y[k]), 0);
                if (h[k] != A) ok = false;
            }
            if (ok) {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
*A, = map(int, input().split())

A.sort(reverse=True)
total_point = sum(A)

selectable = False

if total_point * (1 / (4 * M)) <= A[M-1]:
    selectable = True

if selectable:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m;
int main(){
    cin>>n>>m;
    int cnt=0;
    int l=n-(m+1)/2*2+1,r=n;
    int p=(r-l)%2;
    while(l<r&&cnt<m){
        cout<<l<<" "<<r<<endl;
        ++l,--r;++cnt;
    }
    l=1,r=n-(m+1)/2*2;
    if((r-l)%2==p) ++l;
    while(l!=r&&cnt<m){
        cout<<l<<" "<<r<<endl;
        ++l,--r;++cnt;
    }
    return 0;
}

Measured memory_bytes: 3600
import numpy as np
a = np.zeros([3,3])
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))

ans = (np.zeros([3,3]) ==1)

n = int(input())
for i in range(n):
  num = int(input())
  ans += (a == num)
if(any([any(ans.all(axis=1, dtype=bool)),
          any(ans.all(axis=0, dtype=bool)),
          all([ans[0,0],ans[1,1],ans[2,2]]),
          all([ans[0,2],ans[1,1],ans[2,0]])])):
  print("Yes")
else:
  print("No")
  




Measured memory_bytes: 12444
#include<bits/stdc++.h>
#define SZ(x) x.size()
#define pii pair<int,int>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int mod = 1e9 + 7;
ll qpow(ll a, ll b, ll mod) {
    ll ans = 1;
    while(b) {
        if(b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll inv(ll a, ll p) {
    return qpow(a, p - 2, p) ;
}
ll Inv[200005];
ll n[200005], n_1[200005];
int main() {
    ll N, K;
    scanf("%lld%lld", &N, &K);
    for(int i = 0; i < 200005; i++)
        Inv[i] = inv(i, mod);
    n[0] = n_1[0] = 1;
    for(ll i = 1; i < 200005; i++) {
        n[i] = n[i - 1] * (N - i + 1) % mod * Inv[i] % mod;
        n_1[i] = n_1[i - 1] * (N - i) % mod * Inv[i] % mod;
        //printf("C(%lld,%lld) = %lld\n", N, i, n[i]);
        //printf("C(%lld,%lld) = %lld\n", N - 1, i, n_1[i]);
    }
    ll ans = 0;
    for(ll i = 0; i <= min(K, N - 1); i++) {
        ans = (ans + n[i] * n_1[N - i - 1] % mod) % mod;
        //printf("%lld %lld\n", n[i], n_1[N - i - 1]);
    }
    printf("%lld", (ans + mod) % mod);
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <cmath>

#define rep(var, n) for(int var = 0;var < n;var++)
using namespace std;

void print_field(vector< vector<int> > &field) {
  rep(i, field.size()) {
    rep(j, field[i].size()) {
      cout << field[i][j] << ' ';
    }
    cout << endl;
  }
  cout << endl;
}

int main() {
  while(true) {
    int R, C;
    cin >> R >> C;
    if(R == 0 && C == 0) break;

    vector< vector<int> > field(R, vector<int>(C));

    rep(i, R) {
      rep(j, C) {
        cin >> field[i][j];
      }
    }

    int ans = -1;

    int n = pow(2, R);
    rep(i, n) {
      vector< vector<int> > field2 = field;

      int num_of_one = 0;
      rep(j, R) {
        rep(k, C) {
          if((i >> j) & 1) field2[j][k] = 1 - field2[j][k];

          if(field2[j][k] == 1) num_of_one++;
        }
      }

      //print_field(field2);

      int flip_to = num_of_one > (R * C) ? 1 : 0;

      int num = 0;
      rep(i, C) {
        int num_col = 0;
        rep(j, R) {
          if(field2[j][i] == flip_to) {
            num_col++;
          }
        }

        if(num_col <= R / 2) {
          rep(j, R) {
            field2[j][i] = 1 - field2[j][i];
          }
          num_col = R - num_col;
        }

        num += num_col;
      }

      //print_field(field2);

      //cout << "---------------------" << endl;

      ans = max(ans, num);
    }

    //cout << "============" << endl;

    cout << ans << endl;
  }
}

Measured memory_bytes: 2068
#演習１－１４
sys_a = [0]*2 #aの攻撃システム[ランナー,アウト]　
sys_b = [0]*2 #bの攻撃システム[ランナー,アウト]
score_a = 0 #socre of a
score_b = 0 #score of b
outs = 0 #total number of outs (1 ining = 6 outs)
inings = int(input()) #number of inings

while outs <= 3*inings:
    
    if outs == 3*inings: #outsが3回×イニング数　個たまったらおわり
        break
          
    else:
        action = input()
        if action == "OUT":
            if sys_a[-1] != 2:
                sys_a[-1] = sys_a[-1]+1
                outs = outs + 1
            else :
                print(score_a)
                score_a = 0
                sys_a = [0] * 2
                outs = outs +1
                
        elif action == "HOMERUN":
            score_a += sys_a[0] +1
            sys_a[0] = 0
        else :
            if sys_a[0] == 3:
                score_a = score_a+1
                sys_a[0] = 3
            else:
                sys_a[0] = sys_a[0]+ 1


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

int main()
{
    int N, M;
    cin>>N;
    cin>>M;
    
    vector<int> v(M, 0);
    for (int i = 0; i < N; i++)
    {
        int k, A;
        cin>>k;
        for (int j = 0; j < k; j++)
        {
            cin>>A;
            v[A - 1]++;
        }
    }
    
    int result = 0;
    for (int i = 0; i < M; i++)
    {
        if (v[i] == N)
            result++;
    }
    
    cout<<result<<endl;
    
    return 0;
}

Measured memory_bytes: 256
while 1:
   H, W = map(int, raw_input().split())
 
   if H == 0 and W == 0:
      break
   for i in range(H):
      if i%2 == 0:
         if W%2 == 0:
           print "#."*(W/2)
         elif W%2 == 1:
           print "#."*(W/2)+"#"
      elif i%2 == 1:
         if W%2 == 0:
            print ".#"*(W/2)
         elif W%2 == 1:
            print ".#"*(W/2)+"."
   print ""

Measured memory_bytes: 6444
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
string fol,kol;
int dp[3001][3001];
int sol[3001][3001];
int solve(int x,int y)
{
  if(x>=fol.size() || y>= kol.size())return 0;
  if(dp[x][y]!= -1)return dp[x][y];
  int ans = 0;
  int s=0;
  if(fol[x]==kol[y])
  {
    int vol = solve(x+1,y+1);
    if(vol+1 > ans)s=1;
    ans = max(ans,1 + vol);
  }
  int vol1 = solve(x+1,y);
   if(vol1>ans)s=0;
  ans = max(ans,vol1);
  int  kol = solve(x,y+1);
  if(kol>ans)s=2;
  ans = max(ans , kol);
  sol[x][y]=s;
  return dp[x][y]=ans;
}
int indexi;
int ans;
void parcours(int x,int y)
{
  if(indexi == ans){
    exit(0);
  }
  if(sol[x][y]==1){cout<<fol[x];indexi++;
  parcours(x+1,y+1);}
  if(sol[x][y]==0){
    parcours(x+1,y);
  }
  else {parcours(x,y+1);}
}
int main()
{
  memset(dp,-1,sizeof dp);
 cin>>fol>>kol;
 ans = solve(0,0);
 parcours(0,0);
  return 0;
}

Measured memory_bytes: 71040
// luogu-judger-enable-o2
#include<bits/stdc++.h>

using namespace std;
//
//struct node
//{
//    char str[1005];
//}zifu[1005];

int main()
{

    string s;
    cin>>s;
    int ans=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]!=s[i+1])
        {
            ans++;
        }
    }
    cout<<ans-1<<endl;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,s=0,mx=0,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        s+=a;
        mx=max(mx,a);
    }
    cout<<(mx<s-mx?"Yes":"No")<<endl;
}


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

int main(){ 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, k, a[100001];
    cin >> n >> k;
    vector<int> dp(n, INT_MAX);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 1; j <= k; ++j){
            if(i + j < n)
                dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
            else
                break;
        }
    }
    cout << dp[n - 1] << '\n';
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N+1, vector<int>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> color(N+1, 0);
    color[1] = 1;
    int black=1, white=0;
    queue<int> q;
    q.push(1);
    bool check = true;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (color[nxt] != 0 && color[now] == color[nxt]) {
                check = false;
                break;
            }
            if (color[now]+color[nxt] == 3) continue;
            color[nxt] = 3-color[now];
            if (color[nxt] == 1) black++;
            else white++;
            q.push(nxt);
        }
        if (!check) break;
    }
    if (check) cout << (ll)black*white - M << endl;
    else cout << (ll)N*(N-1)/2 - M << endl;
    return 0;
}

Measured memory_bytes: 6144
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
typedef long long ll;
typedef double db;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
//start!
const int MAX_N=1e6+5;
bool is_prime[MAX_N];
int prime[MAX_N],cntp=0;
int f[MAX_N],sum[MAX_N],low[MAX_N];//f:?????? sum:f??? low:i???????p^a
void mf_sieve(int n)
{
	repi(i,2,n) is_prime[i]=true;
	f[1]=sum[1]=1;//?????????
	repi(i,2,n){
		if(is_prime[i]) prime[++cntp]=i,low[i]=i,f[i]=2;//?????????(?????????)
		for(register int j=1;j<=cntp&&i*prime[j]<=n;j++){
			is_prime[i*prime[j]]=false;
			if(i%prime[j]==0){
				low[i*prime[j]]=low[i]*prime[j];
				if(low[i]==i) f[i*prime[j]]=f[i]+1;//??i??????????,f(p^k) low[i]=p^a i%prime[j]=0 => p=prime[j]
				else f[i*prime[j]]=f[i/low[i]]*f[low[i]*prime[j]];
				break;
			}
			low[i*prime[j]]=prime[j];
			f[i*prime[j]]=f[i]*f[prime[j]];
		}
	}
}
int main()
{
	int ans=0;
	int n=qi(); mf_sieve(n);
	repi(i,1,n-1) ans+=f[i];
	printf("%d\n",ans);
	return 0;
}

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

int main(void){
    string str;
    cin >> str;
    for(int i=1; i<str.size(); i++){
        for(int j=0; j<i; j++){
            if(str[i]==str[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
#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 mp make_pair
#define ll long long
#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 100010
#define inf 1e9

int main()
{

    string ss;
    ll n;
    cin >> n >> ss;
    string ans;
    ans.pb(ss[0]);
    for(ll i = 1; i < ss.size(); i++)
    {

        ll sz = ans.size();
        if(ans[sz-1] != ss[i]) ans.pb(ss[i]);
    }
    cout << ans.size();
}


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

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

	vector<long long> buff(4);
	buff.at(0) = a*c;
	buff.at(1) = a*d;
	buff.at(2) = b*c;
	buff.at(3) = b*d;

	sort(buff.begin(),buff.end());
	if(buff.at(3) == -0){
		cout << 0 << endl;
		return 0;
	}
	//printf("%.0lf\n",buff.at(3));
	cout << buff.at(3) << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <limits>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s);i<(e);i++)
#define rep(i,n) REP(i,0,n)

int main(void) {
  int N, K; cin >> N >> K;
  double p = 0.0;
  for (int i = 1; i <= N; i++) {
    double pp = 1.0 / N;
    int n = i;
    while (n < K) {
      pp /= 2.0;
      n *= 2;
    }
    p += pp;
  }
  printf("%.10f\n", p);
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, sum int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)

	l := make([]int, n)
	scanner.Scan()
	for i, v := range strings.Split(scanner.Text(), " ") {
		l[i], _ = strconv.Atoi(v)
	}

	sort.Ints(l)
	for i := 0; i < n-1; i++ {
		sum += l[i]
	}
	if sum > l[n-1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1852
import collections
S = list(input())
s = collections.deque(S)
Q = int(input())
mode = 1
for _ in range(Q):
    tmp = tuple(input().split())
    if len(tmp) == 1:
        mode = 1 ^ mode
    else:
        t, f, c = tmp
        f = int(f)
        f -= 1
        if mode ^ f:
            s.appendleft(c)
        else:
            s.append(c)
if mode:
    print("".join(list(s)))
else:
    print("".join(list(s)[::-1]))


Measured memory_bytes: 72568
from collections import deque
k = int(input())

q = deque([i for i in range(1,10)])

for i in range(1,k+1):
  x = q.popleft()
  
  if i == k:
    print(x)
    exit()
    
  if x%10 != 0:
    q.append(10*x+(x%10)-1)
    
  q.append(10*x+(x%10))
  
  if x%10 != 9:
    q.append(10*x+(x%10)+1)

Measured memory_bytes: 11908
import itertools
from collections import defaultdict

def ok_bit(bit):
    for i in range(N):
        if bit[i] == 0:
            continue
        for x, y in evidence_dict[i]:
            if y != bit[x-1]:
                return False
    return True



def solver():
    for bit in reversed(bit_list):
        if ok_bit(bit):
            return bit
    return [0]

N = int(input())
evidence_dict = defaultdict(list)
A = []
for i in range(N):
    A1 = int(input())
    for j in range(A1):
        evidence_dict[i].append(list(map(int, input().split())))

L = [0, 1]
bit_list = list(itertools.product(L, repeat=N))


if __name__ == "__main__":
    ans_bit = solver()
    res = 0
    for b in ans_bit:
        if b==1:
            res+=1
    print(res)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
      
#define pb push_back
#define fst first
#define snd second
#define ios ios_base::sync_with_stdio(0); cin.tie(0);
#define open freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
    
using namespace std;
 
typedef long long ll;
typedef long double ld;

signed main(){
	ios;
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size() / 2; i++){
		cnt += (s[i] != s[s.size() - i - 1]);
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int a = n;

        for (int i = 0; i < 2; i++) {
            a = a * n;
        }

        System.out.println(a);
    }
}


Measured memory_bytes: 26160