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

using namespace std;

template< typename Monoid, typename OperatorMonoid = Monoid >
struct LazySegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
  using G = function< Monoid(Monoid, OperatorMonoid, int) >;
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

  int sz;
  vector< Monoid > data;
  vector< OperatorMonoid > lazy;
  const F f;
  const G g;
  const H h;
  const Monoid M1;
  const OperatorMonoid OM0;


  LazySegmentTree(int n, const F f, const G g, const H h,
                  const Monoid &M1, const OperatorMonoid OM0)
      : f(f), g(g), h(h), M1(M1), OM0(OM0) {
    sz = 1;
    while(sz < n) sz <<= 1;
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(int k, const Monoid &x) {
    data[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      data[k] = f(data[2 * k + 0], data[2 * k + 1]);
    }
  }

  void propagate(int k, int len) {
    if(lazy[k] != OM0) {
      if(k < sz) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      }
      data[k] = g(data[k], lazy[k], len);
      lazy[k] = OM0;
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x, int k, int l, int r) {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return data[k];
    } else if(a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      propagate(k, r - l);
      return data[k];
    } else {
      return data[k] = f(update(a, b, x, 2 * k + 0, l, (l + r) >> 1),
                         update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x) {
    return update(a, b, x, 1, 0, sz);
  }


  Monoid query(int a, int b, int k, int l, int r) {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return M1;
    } else if(a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, 2 * k + 0, l, (l + r) >> 1),
               query(a, b, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid query(int a, int b) {
    return query(a, b, 1, 0, sz);
  }

  Monoid operator[](const int &k) {
    return query(k, k + 1);
  }
};

vector< int > order, g[100000];
int in[100000], out[100000];

void dfs(int idx) {
  in[idx] = order.size();
  order.push_back(idx);
  for(auto &to : g[idx]) dfs(to);
  out[idx] = order.size();
}

int main() {
  int N, Q;
  cin >> N >> Q;
  for(int i = 1; i < N; i++) {
    int p;
    cin >> p;
    g[--p].push_back(i);
  }
  dfs(0);
  auto f = [](int x, int y) { return x + y; };
  auto g = [](int x, int y, int len) {
    if(y & 1) return len - x;
    return x;
  };
  LazySegmentTree< int > seg(N, f, g, f, 0, 0);
  for(int i = 0; i < N; i++) {
    char c;
    cin >> c;
    if(c == 'G') seg.set(in[i], 1);
  }
  seg.build();
  for(int i = 0; i < Q; i++) {
    int k;
    cin >> k;
    --k;
    seg.update(in[k], out[k], 1);
    cout << (seg.query(0, N) * 2 > N ? "broccoli" : "cauliflower") << endl;
  }
}


Measured memory_bytes: 16436
#include<bits/stdc++.h>
#define N 300005
using namespace std;
int c[N],n,m;
void add(int pos,int x)
{
    for(int i=pos;i<=n;i+=(i&(-i)))
    {
        //cout<<i<<endl;
        c[i]+=x;
    }
    return ;
}
int qur(int pos)
{
    int ans=0;
    for(int i=pos;i;i-=(i&(-i)))
    {
        ans+=c[i];
    }
    return ans;
}
struct node
{
    int l,r;
    friend bool operator < (const node &aa,const node &bb)
    {
        return aa.r-aa.l<bb.r-bb.l;
    }
}a[N];
int main()
{
    scanf("%d%d",&m,&n);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&a[i].l,&a[i].r);
    }
    sort(a+1,a+m+1);int p=1;
    for(int i=1;i<=n;i++)
    {
        while(p<=m&&a[p].r-a[p].l+1<=i)
        {
            add(a[p].r+1,-1);
            add(a[p].l,1);
            p++;
       //     cout<<p<<endl;
        }
        int ans=m-p+1;
        for(int j=i;j<=n;j+=i)
        {
            ans+=qur(j);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3712
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
beforeN = sum(Alist)
for i in range(N - 1, -1, -1):
    rest_power = Blist[i] - Alist[i + 1]
    if rest_power > 0:
        Alist[i + 1] = 0
        last_power = Alist[i] - rest_power
        if last_power <= 0:
            Alist[i] = 0
        else:
            Alist[i] = Alist[i] - rest_power
    else:
        Alist[i + 1] = Alist[i + 1] - Blist[i]
        continue
ans = beforeN - sum(Alist)
print(ans)

Measured memory_bytes: 18624
def main():
    n,k,s = map(int,input().split())
    if k == n:
        arr = [s]*n
    elif k == 0:
        if s == 10**9:
            s = 1
        else:
            s += 1

        arr = [s]*n
    else:
        arr = []
        if s == 1:
            for i in range(k):
                arr.append(s)
        else:
            arr.append(1)
            arr.append(s-1)
            k -= 1
            if k%2 == 0:
                while k > 0:
                    arr.append(1)
                    arr.append(s-1)
                    k -= 2
            else:
                while k > 1:
                    arr.append(1)
                    arr.append(s-1)
                    k -= 2

                arr.append(1)
                    
        if s == 10**9:
            s = 2
        else:
            s = 10**9
            
        while len(arr) != n:
            arr.append(s)

    for i in arr:
        print(i,end = ' ')


main()


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

typedef long long ll;
const int N = 3054, mod = 1000000007, iv2 = (mod + 1) / 2;

int n, q;
int a[N], f[N][N];

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

inline int half(int x) {return x = (x >> 1) + (-(x & 1) & (iv2 - mod)), x + (x >> 31 & mod);;}

int main() {
	int i, j, u, v; ll I = 0;
	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; ++i) scanf("%d", a + i);
	for (i = 1; i <= n; ++i)
		for (j = 1; j <= n; ++j)
			f[i][j] = a[i] > a[j];
	for (i = 0; i < q; ++i) {
		scanf("%d%d", &u, &v), f[u][v] = f[v][u] = half(f[u][v] + f[v][u]);
		for (j = 1; j <= n; ++j) if (j != u && j != v)
			f[u][j] = f[v][j] = half(f[u][j] + f[v][j]),
			f[j][u] = f[j][v] = half(f[j][u] + f[j][v]);
	}
	for (i = 1; i <= n; ++i) I += std::accumulate(f[i] + i, f[i] + (n + 1), 0ll);
	printf("%d\n", (int)PowerMod(2, q, I % mod));
	return 0;
}

Measured memory_bytes: 36224
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


int dp[100000000];
vector<long long> divisor(long long n) {
  vector< long long > ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

vector<pair<ll, int>> factrized(ll num){
  vector<pair<ll, int>>  res;
 
  for(ll i = 2; i * i <= num; i++){
    if(num % i)continue;
    res.emplace_back(i, 0);
    while(num % i == 0){
      num /= i;
      res.back().second++;
    }
  }
  if(num != 1) res.emplace_back(num, 1);
  return res;
}

long long findDivisors(long long n) 
{ 
  
    // Array to store the count 
    // of divisors 
    long long div[n + 1]; 
    memset(div, 0, sizeof div); 
  
    // For every number from 1 to n 
    for (long long i = 1; i <= n; i++) { 
  
        // Increase divisors count for 
        // every number divisible by i 
        for (long long j = 1; j * i <= n; j++) 
            div[i * j]++; 
    } 
  
    // Print the divisors 
    long long ans = 0;
    for (long long i = 1; i <= n; i++) 
        ans += (i * div[i]);
    // cout << ans << endl;
    return ans;
} 

int main(){
  long long n;
  cin >> n;
  cout << findDivisors(n) << endl;
}


Measured memory_bytes: 81724
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n").map(Number);
var a=arr.splice(0,4);
a.sort(function(a,b){
   return b-a;
});
var b=Math.max(arr[0],arr[1]);
console.log(a[0]+a[1]+a[2]+b);

Measured memory_bytes: 15600
N = int(input())
S1 = input()
S2 = input()

ds = []

i = 0
while i < N:
    if S1[i] == S2[i]:
        ds.append('X')
        i += 1
    else:
        ds.append('Y')
        i += 2

n = 0
if ds[0] == 'X':
    n = 3
else:
    n = 6
for i in range(1, len(ds)):
    if ds[i] == 'X':
        if ds[i - 1] == 'X':
            n *= 2 % 1000000007
        else:
            n *= 1 % 1000000007
    else:
        if ds[i - 1] == 'X':
            n *= 2 % 1000000007
        else:
            n *= 3 % 1000000007
print(n % 1000000007)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int> 
#define pii pair<int,int>
const int N = 2e4 +5;
int dp[N],n;
main(){
	ios::sync_with_stdio(0);  
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 100; i++)
	for (int j = 1; j<= 100; j++)
	for (int k = 1; k <= 100; k++) {
		if (i*i+j*j+k*k + i*j+i*k+j*k <=n)
		dp[i*i+j*j+k*k + i*j+i*k+j*k]++;
	}
	for (int i = 1; i <= n; i++) 
		cout << dp[i]<<'\n';
}

Measured memory_bytes: 3648
// 2020-08-15 21:27:54
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int MX = 3030;
ll dp[MX][MX][4], V[MX][MX];
void answer() {
  int r_sz, c_sz, k;
  cin >> r_sz >> c_sz >> k;
  rep(i, k) {
    ll r, c, v;
    cin >> r >> c >> v;
    r--; c--;
    V[r][c] = v;
  }
  rep(i, r_sz) rep(j, c_sz) rep(x, 4) {
    chmax(dp[i+1][j][0], dp[i][j][x]);
    chmax(dp[i][j+1][x], dp[i][j][x]);
    if(V[i][j] > 0 && x < 3) {
      chmax(dp[i+1][j][0], dp[i][j][x] + V[i][j]);
      chmax(dp[i][j+1][x+1], dp[i][j][x] + V[i][j]);
    }
  }
  ll ans = 0;
  rep(x, 4) {
    chmax(ans, dp[r_sz][c_sz-1][x]);
    chmax(ans, dp[r_sz-1][c_sz][x]);
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

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

  char s[n];
  cin >> s;

  int max=0;
  char tmp[n];
  char ctmp;

  for(int i=0;i<n-1;i++){
    strcpy(tmp,s);
    int mtmp=0;
    for(int j=0;j<i+1;j++){
      ctmp=tmp[j];
      int k;
      for(k=i+1;k<n;k++){
	if(ctmp==tmp[k]){
	  mtmp++;
	  tmp[k]='*';
	  break;
	}
      }
      for(;k<n;k++){
	if(ctmp==tmp[k]) tmp[k]='*';
      }
    }
    if(mtmp>max) max=mtmp;
  }
  
  cout << max << endl;

  return 0;
}


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

#define IDX(i, j) ((i)*m+(j))

typedef vector<int> Vec;
typedef vector<Vec> Mat;

int n;
int m;
int d;
int S[114][514];
int Case;

int main() {
  while (1) {
    scanf("%d%d%d", &m, &n, &d);
    if ((n|m|d) == 0) return 0;

    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
        scanf("%d", &S[i][j]);
      }
    }

    int sz = n*m;
    Mat aug(sz, Vec(sz+1, 0));
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
        int idx = IDX(i, j);
        aug[idx][idx] = 1;
        aug[idx][sz] = S[i][j];
        for (int k=0; k<n; k++) {
          for (int l=0; l<m; l++) {
            if (abs(k-i)+abs(l-j) == d) aug[idx][IDX(k, l)] = 1;
          }
        }
      }
    }

    int lim = 0;
    for (int idx=0; idx<sz+1; idx++) {
      int chosen = -1;
      for (int i=lim; i<sz; i++) {
        if (aug[i][idx]) {
          chosen = i;
          break;
        }
      }

      if (chosen == -1) continue;

      swap(aug[chosen], aug[lim]);
      for (int i=lim+1; i<sz; i++) {
        if (i == lim) continue;
        if (!aug[i][idx]) continue;
        for (int j=idx; j<=sz; j++) {
          aug[i][j] ^= aug[lim][j];
        }
      }

      lim++;
    }

    bool fail = false;
    for (int i=0; i<sz; i++) {
      bool pos = true;
      for (int j=0; j<sz; j++) {
        if (aug[i][j]) {
          pos = false;
          break;
        }
      }

      if (aug[i][sz] == 0) continue;
      if (pos) {
        fail = true;
        break;
      }
    }

    if (fail) puts("0");
    else puts("1");
  }
}

Measured memory_bytes: 4380
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 187
int f[N][N][N],g[N][N][N],n,m,is[N],f2[N][N][N],g2[N][N][N];
char s[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	for(int j=i;j<=n;j++)
	{
		for(int k=1;k<=m;k++){is[k]=s[i][k]=='.';for(int l=i;l<=j;l++)if(s[l][k]!=s[i][k])is[k]=-1;}
		for(int k=1;k<=m;k++)
		{
			if(is[k]==-1)f[i][j][k]=k-1;
			else if(f[i][j][k-1]>=k)f[i][j][k]=f[i][j][k-1];
			else{f[i][j][k]=k;while(f[i][j][k]<m&&is[f[i][j][k]+1]==is[k])f[i][j][k]++;}
		}
	}
	for(int i=1;i<=m;i++)
	for(int j=i;j<=m;j++)
	{
		for(int k=1;k<=n;k++){is[k]=s[k][i]=='.';for(int l=i;l<=j;l++)if(s[k][l]!=s[k][i])is[k]=-1;}
		for(int k=1;k<=n;k++)
		{
			if(is[k]==-1)g[i][j][k]=k-1;
			else if(g[i][j][k-1]>=k)g[i][j][k]=g[i][j][k-1];
			else{g[i][j][k]=k;while(g[i][j][k]<n&&is[g[i][j][k]+1]==is[k])g[i][j][k]++;}
		}
	}
	if(f[1][n][1]==m){printf("0\n");return 0;}
	for(int i=1;i<=18;i++)
	{
		for(int j=1;j<=n;j++)
		for(int k=j;k<=n;k++)
		for(int l=1;l<=m;l++)
		{
			int t=f[j][k][f[j][k][l]==m?m:f[j][k][l]+1];
			if(f2[j][k][l]<t)f2[j][k][l]=t;
			if(g2[l][t][j]<k)g2[l][t][j]=k;
		}
		for(int j=1;j<=m;j++)
		for(int k=j;k<=m;k++)
		for(int l=1;l<=n;l++)
		{
			int t=g[j][k][g[j][k][l]==n?n:g[j][k][l]+1];
			if(g2[j][k][l]<t)g2[j][k][l]=t;
			if(f2[l][t][j]<k)f2[l][t][j]=k;
		}
		for(int j=1;j<=n;j++)
		for(int k=n;k>=j;k--)
		for(int l=1;l<=m;l++)
		f2[j][k][l]=max(max(f2[j][k][l],f2[j][k+1][l]),max(f2[j-1][k][l],f2[j][k][l-1]));
		for(int j=1;j<=m;j++)
		for(int k=m;k>=j;k--)
		for(int l=1;l<=n;l++)
		g2[j][k][l]=max(max(g2[j][k][l],g2[j][k+1][l]),max(g2[j-1][k][l],g2[j][k][l-1]));
		for(int j=1;j<=n;j++)
		for(int k=j;k<=n;k++)
		for(int l=1;l<=m;l++)
		f[j][k][l]=f2[j][k][l],f2[j][k][l]=0;
		for(int j=1;j<=m;j++)
		for(int k=j;k<=m;k++)
		for(int l=1;l<=n;l++)
		g[j][k][l]=g2[j][k][l],g2[j][k][l]=0;
		if(f[1][n][1]==m){printf("%d\n",i);return 0;}
	}
}

Measured memory_bytes: 100480
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

const int maxN = (int)5e5 + 10;

void solve() {
  int n, m;
  cin >> n >> m;
  int s = 0, x;
  for (int i = 0 ; i < m ; i++) {
    cin >> x;
    s += x;
  }
  if (s > n) cout << -1; else cout << n - s;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

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

int main(){
    int n;cin>>n;
    set<int> si;
    int p=0;
    rep(i,n){
        int t;cin>>t;
        t = min(t, 3200);
        t=t/400;
        si.insert(t);
        if(t==8) p++;
    }
    int mn = si.size() - (p>0);
    if(mn==0) mn=1;
    int mx = si.size()-(p>0)+p;
    cout<<mn<<" "<<mx<<endl;

}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    ll n;
    cin >> n;
    ll power = 1;

    repll2(i, n) {
        power *= i;
        power %= MOD;
    }

    cout << power;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    string s;cin>>s;
    if(s.size()==1){
        cout<<0<<endl;
    }else{
        ll a=0;
        rep(i,1,s.size()-1){
            if(s[i]!=s[i-1])a++;
        }
        cout<<a<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var A = Sarray()[0];
            var B = Sarray()[0];
            var ans = new List<int> { 1, 2, 3 };
            ans.Remove(A);
            ans.Remove(B);
            WriteLine(ans[0]);
        }
    }
}


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

public class Main {
    public static long nibutan(long a[],long b,int n){
        int left=0;
        int right=n;
        while(left<right){
            int mid=(left+right)/2;
            if(a[mid]==b){
                right=mid;
            }else if(a[mid]<b){
                left=mid+1;
            }else if(a[mid]>b){
                right=mid;
            }
        }
        return right;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        long A[]=new long[N];
        long B[]=new long[N];
        long C[]=new long[N];
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        }
        for(int i=0;i<N;i++){
            B[i]=sc.nextInt();
        }
        for(int i=0;i<N;i++){
            C[i]=sc.nextInt();
        }
        long ch1=0;
        long ch2=0;
        long ans=0;
        
        Arrays.sort(A);
        Arrays.sort(C);
        for(int i=0;i<N;i++){
            ch1=nibutan(A,B[i],N);
            ch2=N-nibutan(C,B[i]+1,N);
            ans+=ch1*ch2;
        }
        
        System.out.println(ans);
    }
}

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

int main() {
  long long k;
  cin>>k;
  long long n = 50;
  long long x = k / n;
  long long y = k % n;
  cout<<n<<endl;
  for (int i=0; i<n; i++) {
    if (i < y) {
      cout<<n + x;
    } else {
      cout<<n - y - 1 + x;
    }
    if (i != n - 1) {
      cout<<" ";
    }
  }
  cout<<endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int R, C, K;
    cin >> R >> C >> K;
    vector<vector<int>> items(R, vector<int>(C));
    for (int i=0; i<K; ++i) {
        int r, c, v;
        cin >> r >> c >> v;
        items[r-1][c-1] = v;
    }

    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4)));
    if (items[0][0] > 0) {
        dp[0][0][1] = items[0][0];
    }
    for (int i=0; i<R; ++i) {
        for (int j=0; j<C; ++j) {
            if (i == 0 && j == 0) continue;
            if (i > 0) {
                for (int k=0; k<4; ++k) {
                    chmax(dp[i][j][0], dp[i-1][j][k]);
                    if (items[i][j] > 0) chmax(dp[i][j][1], dp[i-1][j][k] + items[i][j]);
                }
            }
            if (j > 0) {
                for (int k=0; k<4; ++k) {
                    chmax(dp[i][j][k], dp[i][j-1][k]);
                    if (items[i][j] > 0 && k > 0) chmax(dp[i][j][k], dp[i][j-1][k-1] + items[i][j]);
                }
            }
        }
    }

    ll res = 0;
    for (int i=0; i<4; ++i) chmax(res, dp[R-1][C-1][i]);
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 671388
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb(a)
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 55;
using namespace std;
ll n,m,dp[N],ans;
vector<vector<ll>>v;
bool vis[N];
void dfs(ll node)
{
    vis[node] = true;
    for(auto i:v[node])
    {
        if(!vis[i])
            dfs(i);
        dp[node] = max(dp[node],1+dp[i]);
    }
}
int main()
{
    abdelrahman001
    cin >> n >> m;
    v.resize(n+5);
    for(int i = 0,a,b;i<m;i++)
        cin >> a >> b,v[a].pb(b);
    for(int i = 1;i<=n;i++)
        if(!vis[i])
            dfs(i);
    for(int i = 1;i<=n;i++)
        ans = max(ans,dp[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 7808
#include"bits/stdc++.h"

using namespace std;

#define REP(i, N) for(int i = 0; i < (N); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define int long long

string s;

bool itALLOK(int start, int end, char c){
	if(start < 0) return 0;
	if(end > s.size()) return 0;
	
	FOR(i, start, end){
		if(s[i] != c) return 0;
	}
	return 1;
}

signed main(){
	int ans = 0;
	
	cin >> s;
	
	int o_count = 0;
	
	REP(i, s.size()){
		if(s[i] == 'O'){
			o_count++;
		}
		else{
			if(o_count > 0){
				bool ok_j = itALLOK(i - o_count * 2, i - o_count, 'J');
				bool ok_i = itALLOK(i, i + o_count, 'I');
				if(ok_j && ok_i){
					ans = max(ans, o_count);
				}
				o_count = 0;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int mod = 1e5;
const int MAX = 1e6;

int main() {
    while (true) {
        int n; cin >> n;
        if (n == 0) break;
        vint c(24*60*60+2,0);
        rep(i,n) {
            string s, g; cin >> s >> g;
            int s_h = (s[0]-'0')*10+(s[1]-'0');
            int s_m = (s[3]-'0')*10+(s[4]-'0');
            int s_s = (s[6]-'0')*10+(s[7]-'0');
            int s_t = s_h*3600+s_m*60+s_s;
            int g_h = (g[0]-'0')*10+(g[1]-'0');
            int g_m = (g[3]-'0')*10+(g[4]-'0');
            int g_s = (g[6]-'0')*10+(g[7]-'0');
            int g_t = g_h*3600+g_m*60+g_s;
            c[s_t]++; c[g_t]--;
        }
        vint cover(24*60*60+1,0);
        rep(i,24*60*60+1) {
            if (i == 0) cover[i] = c[i];
            cover[i] = cover[i-1]+c[i];
        }
        int ans = 0;
        rep(i,24*60*60) ans = max(ans,cover[i]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3588
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
print(min(s.count('0'), s.count('1')) * 2)

Measured memory_bytes: 64620
package main

import (
        "fmt"
        "math"
)

func solution(n, d int, x [][]int) int {
        out := 0
        for i := 0; i < n; i++ {
                for j := 0; j < n; j++ {
                        if i >= j {
                                continue
                        }
                        y := x[i]
                        z := x[j]
                        sum := 0
                        for k := 0; k < d; k++ {
                                t := y[k] - z[k]
                                sum += t * t
                        }
                        dist := int(math.Sqrt(float64(sum)))
                        if sum == dist*dist {
                                out++
                        }
                }
        }
        return out
}

func distance(nums []int) int {
        out := 0
        for _, n := range nums {
                out += n * n
        }
        return out
}

func main() {
        var n, d int
        fmt.Scan(&n, &d)
        x := make([][]int, n)
        for i := range x {
                x[i] = make([]int, d)
                for j := range x[i] {
                        fmt.Scan(&x[i][j])
                }
        }
        fmt.Println(solution(n, d, x))
}

Measured memory_bytes: 512
import java.util.Scanner;

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

        while(true) {
            int H = scan.nextInt(), W = scan.nextInt();
            if(H == 0 && W == 0) break;
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();

        }
    }
}

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

 int main(){
int N;cin>>N;
 vector<int>v(N);
for(int i=0;i<N;++i){

  cin>>v[i];
 }
 sort(v.begin(),v.end());

 int answer=v[v.size()/2]-v[v.size()/2-1];

cout<<answer<<endl;

//18 
  return 0;
 //19
}

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

int main(){
  int n,k;
  cin >> n >>k;
  vector<long long int> an(n);
  for(int i=0;i<n;i++){
    cin >> an.at(i);
  }
  for(int i=k;i<n;i++){
    if(an.at(i-k)/an.at(i)<1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
	fast;
	string s,t;cin>>s>>t;
	int ans=1e18;
	for(int i=0;i<s.size();i++)
	{
		if(i+t.size()-1>=s.size())
			break;

		int cnt=0;
		for(int j=0;j<t.size();j++)
		{
			if(s[j+i]!=t[j])
				cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int GetDigit(unsigned long long int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit - 1;
}

int main(){
    int n;
    cin >> n;
    int digit = 0;
    long double mul = 1;
    long double c = (unsigned long long int)std::pow(10, 18);
    unsigned long long int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0){
            printf("0\n");
            return 0;
        }
    }
    
    for(int i = 0; i < n; i++){
        digit = digit+GetDigit(a[i]);
        if(digit > 18){
            printf("-1\n");
            return 0;
        }else{
            mul = mul*a[i];
            if( mul > c){
                printf("-1\n");
                return 0;
            }else{
                digit = GetDigit(mul);
            }
        }
    }
    printf("%.0Lf\n", mul);
    return 0;
}

/*
2
1000000000 1000000000

3
101 9901 999999000001

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0
*/

Measured memory_bytes: 4036
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=1e3+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll x[M];
ll a[M*M];
ll jay[M];
ll n;
ll s=0;
int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    memset(a,-1,sizeof a);
    For(i,0,n)
    {
        cin >> x[i];
        x[i]--;
        if (a[x[i]]!=-1) RET("No");
        a[x[i]]=i;
    }
    iota(jay,jay+n,0);
    sort(jay,jay+n,
        [](ll i,ll j){ return x[i]<x[j]; });
    For(ii,0,n)
    {
        ll i=jay[ii];
        //ER(i);
        For(j,0,i)
        {
            //ER(j);
            while (a[s]!=-1) s++;
            if (s>x[i]) RET("No");
            a[s]=i;
        }   
    }
    reverse(jay,jay+n);
    s=n*n-1;
    For(ii,0,n)
    {
        ll i=jay[ii];
        //ER(i);
        For(j,0,n-1-i)
        {
            while (s>=0 && a[s]!=-1) s--;
            if (s<x[i]) RET("No");
            a[s]=i;
        }
    }   
    cout << "Yes\n";
    For(i,0,n*n)
        cout << a[i]+1 << ' ';
}    

Measured memory_bytes: 9088
module Main where

import qualified Data.Vector as Vector
import Data.List

main :: IO ()
main =
    putStrLn =<< (\a -> if a then "Yes" else "No") <$> solve <$> getInt


getInt :: IO [Integer]
getInt = map read <$> words <$> getLine

solve :: [Integer] -> Bool
solve [a, b, c] = 4 * a * b < (c - a - b) * (c - a - b) && a + b < c



Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#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 Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    map<string, int> m;
    m["SAT"] = 1;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    string s;
    cin >> s;
    pr(m[s]);
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

m = 10**20
c = 0
for a in A:
    if a < 0:
        c += 1
    m = min(m, abs(a))

if c % 2 == 0:
    ans = sum([abs(a) for a in A])
else:
    ans = sum([abs(a) for a in A]) - m*2

print(ans)


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

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

    vector<int> A(N);

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

    vector<int> left(N);
    long long ans = 0;

    for (int i = 0; i < N; ++i) {
        int right_pos = i - A[i];
        if (right_pos >= 0 && right_pos < N) {
            ans += left[right_pos];
        }
        int left_pos = i + A[i];
        if (left_pos >= 0 && left_pos < N) {
            ++left[left_pos];
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main(void) {
        vector<int> a;
        int tmp;
        int j = 0;

        while(1) {
                cin >> tmp;
                a.push_back(tmp);
                if(a[j] == 0) {
                        break;
                }
                j++; 
        }
        for(int i = 0; i < a.size() - 1; i++) {
                cout << "Case " << i + 1 << ": "<< a[i] << endl;
}
        return 0;
        
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;
ll k;

ll count(string t) {
  ll cnt = 0LL;

  t.push_back('_');

  ll cur = 1LL;
  for (int i = 1; i < t.size(); ++i) {
    if (t[i] == t[i - 1]) {
      cur += 1LL;
    } else {
      cnt += cur / 2LL;
      cur = 1LL;
    }
  }

  return cnt;
}

int main(void) {
  // Here your code !
  cin >> s;
  scanf("%lld", &k);

  ll ans = count(s) * k;

  string tmp(s.size(), s[0]);

  if (tmp == s) {
    printf("%lld\n", (ll)(s.size()) * k / 2LL);

    return 0;
  }

  if (s[0] == s[s.size() - 1]) {
    char target = s[0];

    ll a = 0LL;
    for (int i = s.size() - 1; i >= 0; --i) {
      if (s[i] != target) break;
      a += 1LL;
    }

    ll b = 0LL;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] != target) break;
      b += 1LL;
    }

    // printf("a: %lld, b: %lld\n", a, b);

    ll connect_part = (a + b) / 2LL - (a / 2LL + b / 2LL);

    ans += connect_part * (k - 1LL);
  }

  // cout << ans << endl;

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Data.List (intersect, nub)

main :: IO ()
main = solve <$> readLn <*> getLine >>= print

solve :: Int -> String -> Int
solve n ss = maximum . map f $ [1..n-1]
  where f i = length $ nub $ intersect as bs
          where (as, bs) = splitAt i ss


Measured memory_bytes: 1020
O,E = input(),input()
ans = ''

if (len(O)+len(E))%2==0:
    for i in range(len(E)):
        ans += O[i] + E[i]
else:
    for i in range(len(E)):
        ans += O[i] + E[i]
    ans+=O[-1]
    
print(ans)

Measured memory_bytes: 9112
n, u, v = map(int, input().split())
u -= 1
v -= 1
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


def dfs(s):
    d = [-1] * n
    d[s] = 0
    stack = [s]
    while stack:
        frm = stack.pop()
        for to in adj[frm]:
            if d[to] == -1:
                d[to] = d[frm] + 1
                stack.append(to)

    return d


du = dfs(u)
dv = dfs(v)

ans = 0
for eu, ev in zip(du, dv):
    if eu < ev:
        ans = max(ans, ev - 1)

print(ans)


Measured memory_bytes: 48804
#include <cassert>

#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
//#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

signed main (){
    int n;cin>>n;
    vector<int> v(n),b(n);
    rep(i,0,n){
        cin>>v[i];
        b[i]=(v[i]-(i+1));
    }

    sort(all(b));
    int ans=0;
    rep(i,0,n){
        ans+=abs(v[i]-(b[n/2]+i+1));
    }
    cout<<ans<<endl;

    


    
}
/*
1-21-2
*/


Measured memory_bytes: 3328
import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;
  
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);

        int N = Integer.valueOf(s.next());
        int ac = 0;
        int wa = 0;
        int tle =0;
        int re =0;
        for(int i=0;i<N;i++){
            String hoge = s.next();
            if(hoge.equals("AC")){
                ac++;
            }else if(hoge.equals("WA") ){
                wa++;
            }else if(hoge.equals("TLE")){
                tle++;
            }else{
                re ++;
            }
        }

        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+ re);

        
        //部下持ち数
        /* int hoge=N-K+2;
		for(int i = K; i <= N+1; i++) {
            for(int i2 =0; i2<= i-1;i2++){
                hoge += N-(2*i2);50
            }
        } */

        

    }
}
    


    

Measured memory_bytes: 58200
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
queue<int>q;
vector<int>E[100005];
int d[100005],v[100005],n;
int id;
void bfs(int s,int id)
{
    d[s]=id;
    v[s]=true;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(auto i:E[u])
        {
            if(!v[i])
            {
                v[i]=true;
                d[i]=id;
                q.push(i);
            }
        }
    }
}
int main()
{
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int s,t;
        cin>>s>>t;
        E[s].push_back(t);
        E[t].push_back(s);
    }
    int q;cin>>q;
    id=1;
    for(int i=1;i<=n;i++)d[i]=-1;
    for(int i=1;i<=n;i++)
        if(d[i]==-1)
        bfs(i,id++);
    for(int i=0;i<q;i++)
    {
        int s,t;
        cin>>s>>t;
        if(d[s]==d[t])cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



Measured memory_bytes: 9408