akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static CompetitiveProgramming.Utilities;

public class Program
{
    public static void Main(string[] args)
    {
        var N = Input.NextInt();
        var S = Input.NextString();
        var K = Input.NextInt() - 1;

        char k = S[K];

        foreach (var c in S)
        {
            Console.Write(c == k ? k : '*');
        }
        Console.WriteLine();
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

namespace CompetitiveProgramming
{
    public static class Utilities
    {
        public static IEnumerable<int> Range(int start, int count) => Enumerable.Range(start, count);
        public static IEnumerable<int> RangeTo(int start, int end) => Enumerable.Range(start, end - start);
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
using namespace std;
class DisjointSet{
private:
  vector<int> rank,p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
  }
  void makeSet(int x){
    p[x] = x;
    rank[x] = 0;
  }
  void Union(int x,int y){
    link(findSet(x),findSet(y));
  }
  int findSet(int x){
    if(x != p[x]) p[x] = findSet(p[x]);
    return p[x];
  }
  bool isSameOut(int x,int y){
    return (findSet(x)==findSet(y));
  }
};
int main(){
  int n,q,com,x,y;
  cin >> n >> q;
  DisjointSet UF(n);
  for(int i=0;i<n;i++) UF.makeSet(i);
  for(int i=0;i<q;i++){
    cin >> com >> x >> y;
    if(com == 0) UF.Union(x,y);
    else cout << (UF.isSameOut(x,y) ? 1 : 0) << endl;
  }
}



Measured memory_bytes: 3180
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x: u32,
    }

    let mut ans = 0;
    let a = x / 500;
    ans += 1000 * a;
    let b = (x - 500 * a) / 5;
    ans += 5 * b;
    println!("{}", ans);
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> as(n);
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      as[i].emplace_back(x, y);
    }
  }
  int ans = 0;
  rep(i, bit32(n)) {
    bool f = true;
    rep(j, n) {
      if (!(i & bit32(j))) continue;
      rep(k, as[j].size()) {
        int x, y;
        tie(x, y) = as[j][k];
        if (y == 0 &&  (i & bit32(x))) f = false;
        if (y == 1 && !(i & bit32(x))) f = false;
      }
    }
    if (f) {
      amax(ans, __builtin_popcount(i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
# import sys
# sys.setrecursionlimit(10 ** 5+1)
import numpy as np
# import IPython

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


from collections import deque
def topological_sort(graph, nodes):
    """

    Prameters
    ---------
    graph: list, [[parent, child], ...]
        graph[i][0]からgraph[i][1]へ
        コード上はv1が親ノード,v2が子ノード

    nodes : list
        全ノードのリスト

    Returns
    -------
    res : list
        トポロジカルソートされたノード
        インデックスが小さい方が親ノード側
    """
    outs = {i: [] for i in nodes}
    ins = {i: 0 for i in nodes}
    for v1, v2 in graph:
        outs[v1].append(v2)
        ins[v2] += 1

    queue = deque(i for i in nodes if ins[i] == 0)
    res = []
    while queue:
        v1 = queue.popleft()
        res.append(v1)
        for v2 in outs[v1]:
            ins[v2] -= 1
            if ins[v2] == 0:
                queue.append(v2)
    return res


N, M = ds_in()

parent = {i+1: [] for i in range(N)}
graph = []
for _ in range(N+M-1):
    a, b = ds_in()
    graph.append([a, b])
    parent[b].append(a)

res = topological_sort(graph, [i+1 for i in range(N)])

sorted_index = np.zeros(N+1, dtype=int)
sorted_index[res] = np.arange(N)

for i in range(1, N+1):
    if i == res[0]:
        print(0)
    else:
        print(parent[i][np.argmax(sorted_index[parent[i]])])


Measured memory_bytes: 82288
using System;
public class Hello{
    public static void Main(){
    
        var weather = Console.ReadLine();
        if(weather == "Sunny")
        {
            Console.WriteLine("Cloudy");
        }
        else if (weather == "Cloudy")
        {
            Console.WriteLine("Rainy");
        }
        else
        {
            Console.WriteLine("Sunny");
        }
    }
}

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

int main(){
  int s[3];
  cin >> s[0] >> s[1] >> s[2];
  sort(s, s+3);
  int x1 = s[2]-s[0];
  int x2 = s[2]-s[1];
  
  if(x1 % 2 == x2 % 2){
    cout << (x1+x2)/2 << endl;
  }else{
    cout << (x1+1)/2 + (x2+1)/2 + 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n,m;cin>>n>>m;
  if(n*2>m){
    cout<<m/2<<endl;
  }
  else{
    ll tmp=m-n*2;
    cout<<n+tmp/4<<endl;
  }
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

_sum = sum(B)
prev_a = N+1

for a in A:
    if prev_a+1 == a:
        _sum += C[prev_a-1]
    prev_a = a

print(_sum)


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

void solve();

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

void solve() {
    while(1) {
        int t,d,l;
        cin >> t >> d >> l;
        if(t == 0 && d == 0 && l == 0) break;
        int x[t];
        for(int i = 0; i < t; i++) {
            cin >> x[i];
        }
        int sum = 0;
        int let = 0;
        for(int i = 0; i < t; i++) {
            if(let != 0) sum++;
            let--;
            if(let == -1) let = 0;
            if(x[i] >= l) let = d;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 3516
s = input()
if s[0] == 'A':
  t = ''
  c_cnt = 0
  for i in range(1, len(s)):
    if s[i] != 'C':
      t += s[i]
    else:
      c_cnt += 1
  if t.islower() and 'C' in s[2:-1] and c_cnt == 1:
    print('AC')
  else:
    print('WA')
else:
  print('WA')


Measured memory_bytes: 9116
program C085
    implicit none
    integer(8) :: N, Y
    integer(8) :: i, j, k, in, jn, kn, ju

    read(5,*) N, Y

    ju = 0
    do i = 0, N
        do j = 0, N-i
            k = N-i-j
            if (10000*i+5000*j+1000*k == Y) then
                ju = ju + 1
                in = i
                jn = j
                kn = k
            end if
        end do
    end do

    if (ju == 0) then
        write(6,*) "-1 -1 -1"
    else
        write(6,*) in, jn, kn
    end if



    
end program C085

Measured memory_bytes: 2832
#include <iostream>
#include <iomanip>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const int inf = 1e9;
const int N = 601;
bool adj[N][N];
int deg[N];
double E[N][2];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m; cin >> n >> m;

	while(m--) {
		int s, t; cin >> s >> t; --s, --t;
		adj[s][t] = 1;
		++deg[s];
	}

	auto solve = [&](bool b) {
		E[n - 1][b] = 0;
		for (int i = n - 2; i >= 0; --i) {
			E[i][b] = 0;
			for (int j = i + 1; j < n - 1; ++j)
				if (adj[i][j])
					E[i][b] += E[j][b];
			E[i][b] /= deg[i];
			E[i][b] += 1;
		}
	};

	solve(0);
	double ans = E[0][0];

	REP(i, 0, n - 1) {
		if (deg[i] == 1) continue;

		int mxpos; double mx = -1;

		REP(j, i + 1, n)
			if (adj[i][j])
				if (mx < E[j][0]) {
					mxpos = j;
					mx = E[j][0];
				}

		--deg[i]; adj[i][mxpos] = 0;
		solve(1);
		++deg[i]; adj[i][mxpos] = 1;

		ans = min(ans, E[0][1]);
	}

	cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  int y = stoi(s.substr(0, 4));
  int m = stoi(s.substr(5, 2));
  int d = stoi(s.substr(8, 2));
  if (y < 2019)
  {
    cout << "Heisei" << endl;
  }
  else if (y == 2019)
  {
    if (m < 4)
    {
      cout << "Heisei" << endl;
    }
    else if (m == 4)
    {
      if (d <= 30)
      {
        cout << "Heisei" << endl;
      }
      else
      {
        cout << "TBD" << endl;
      }
    }
    else
    {
      cout << "TBD" << endl;
    }
  }
  else
  {
    cout << "TBD" << endl;
  }

  return 0;
}


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

using namespace std;

const int MAXN = 2005;
const int MAXK = 10005;

int n, k, br;
string s[MAXN], curr;
int z[MAXK*2];
bool dp[MAXN][MAXK], ok[MAXK];

void precompute () {
    dp[n][0] = 1;
    for (int i = n-1; i >= 0; i--) {
        int len = s[i].size();
        for (int j = 0; j <= k; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j - len >= 0) dp[i][j] |= dp[i + 1][j - len];
        }
    }
}

void z_algo (int ind) {
    string t = s[ind] + '.' + curr;
    int l = 0, r = 0, len = t.size();
    for (int i = 1; i < len; i++) {
        if (r < i) {
            l = r = i;
            while (r < len && t[r - l] == t[r]) r++;
            z[i] = r - l; r--;
        } else {
            int k = i - l;
            if (z[k] < r - i + 1) {
                z[i] = z[k];
            } else {
                l = i;
                while (r < len && t[r - l] == t[r]) r++;
                z[i] = r - l; r--;
            }
        }
    }
    int org = s[ind].size();
    for (int i=0; i<k; i++) {
        z[i] = z[i + org + 1];
    }
}

void calc () {
    for (int i=0; i<k; i++) curr += '{';
    ok[0] = 1;
    for (int i=0; i<n; i++) {
        int len = s[i].size(), ind = -1, d = -1;
        z_algo(i);
        for (int j = 0; j + len <= k; j++) {
            if (!ok[j] || !dp[i+1][k - (j+len)]) continue;
            if (j + z[j] < k && z[j] < len && s[i][z[j]] < curr[j + z[j]]) {
                ind = j;
                break;
            }
        }
        if (ind == -1) continue;
        br = ind + len;
        for (int j=0; j<len; j++) {
            if (d == -1 && curr[ind + j] != s[i][j]) d = ind + j;
            curr[ind + j] = s[i][j];
        }
        for (int j=br; j<k; j++) {
            curr[j] = '{';
        }
        for (int j = d + 1; j <= k; j++) {
            ok[j] = 0;
        }
        ok[br] = 1;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> s[i];
    }
    precompute();
    calc();
    cout << curr;
    return 0;
}
// coba(2)

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

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

    string s,t;
    cin>>s>>t;
    if(s.length()+1==t.length()){
        t.pop_back();
        if (!s.compare(t)){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>

int main()
{
  int n;
  std::cin >>n; 
  char s[n];
  std::cin >>s;
  int count =1;
  char c=s[0];
  for(int i = 1; i< n; i++)
  {
    if(c != s[i])
    {
      c = s[i];
      count ++;
    }
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
using namespace std;
int main()
{	
	int z = 0;
	string x, y;
	cin >> x >> y;

	for (int i = 0; i < x.size(); i++) {
		if (x[i] != y[i])z++;
	}
	cout << z;
	return 0;
}


Measured memory_bytes: 3900
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll n;
    cin>>n;
    vector<ll> v(n);
    ll xorr = 0;
    for(ll i=0; i<n; i++){
        cin>>v[i];
        xorr^=v[i];
    }
    for(ll i=0; i<n; i++){
        cout<<(xorr^v[i])<<" ";
    }
    cout<<endl;
    return 0;
}




Measured memory_bytes: 4716
#include<stdio.h>

int F[45];

int fibonaci(int n){

  int ans;

  if(n == 0 || n == 1) return ans = 1;
  if(F[n] != 0) return F[n];
  ans = fibonaci(n - 2) + fibonaci(n - 1);
  F[n] = ans;
  return ans;

}

int main(){

  int n;

  scanf("%d", &n);

  printf("%d\n", fibonaci(n));

  return 0; 

}

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

int FindSumOfDigits (int n){
  int sum = 0;
  while (n >0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  
  int f = FindSumOfDigits(N);
  if (N % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
    int n;
    cin>>n;
    
    vector<double> v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];
        
    double ans=0;
    
    for(int i=0;i<n;++i)
    ans+=(1.0/v[i]);
    
    ans=1.0/ans;
    cout<<fixed<<setprecision(7)<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    vll a(n);
    ll sum = 0;
    for(ll i=0;i<n;i++) {
    	cin >> a[i];
    	// sum += a[i];
    }
    sort(all(a));
    for(ll i=0;i<n-k;i++) {
    	sum += a[i];
    }
    cout << sum << "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
    //   OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1792
n, a, b, c = [int(it) for it in input().split()]
ls = [int(input()) for it in range(n)]
def dfs(cur, tmpA, tmpB, tmpC):
    if cur == n:
        return abs(a - tmpA) + abs(b - tmpB) + abs(c - tmpC) if tmpA > 0 and tmpB > 0 and tmpC else 10**20
    return min(
        dfs(cur + 1, tmpA + ls[cur], tmpB, tmpC) + (10 if tmpA > 0 else 0),
        dfs(cur + 1, tmpA, tmpB + ls[cur], tmpC) + (10 if tmpB > 0 else 0),
        dfs(cur + 1, tmpA, tmpB, tmpC + ls[cur]) + (10 if tmpC > 0 else 0),
        dfs(cur + 1, tmpA, tmpB, tmpC)
    )

print(dfs(0, 0, 0, 0))

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

#define int long long

using namespace std;

const int maxn = 100005;
bool res[maxn];
int n;
string str;

bool check() {
    bool flag = false;
    for (int i = 0; i < n; i++) {
        int l = ((i-1)+n)%n;
        int r = (i+1)%n;
        //cout << " i = " << i << " l = " << l << " r = " << r << '\n';
        if (res[i]) {
            //cout << " left: " << res[l] << " right: " << res[r] << '\n';
            //cout << str[i] << '\n';
            if (str[i] == 'x' && res[l] == res[r]) flag = true;
            if (str[i] == 'o' && res[l] != res[r]) flag = true;
        }
        if (!res[i]) {
            if (str[i] == 'x' && res[l] != res[r]) flag = true;
            if (str[i] == 'o' && res[l] == res[r]) flag = true;
        }
        //if (flag) cout << " bad at " << i << '\n';
    }
    return !flag;
}

void attempt() {
    for (int i = 1; i < n; i++) {
        int l = ((i-1)+n)%n;
        int r = (i+1)%n;
        if (res[i]) {
            //cout << i << " is sheep\n";
            if (str[i] == 'o') res[r] = res[l];
            if (str[i] == 'x') res[r] = !res[l];
            //cout << "set right to " << res[r] << '\n';
        } else {
            if (str[i] == 'o') res[r] = !res[l];
            if (str[i] == 'x') res[r] = res[l];
        }
    }
}

void print() {
    for (int i = 0; i < n; i++) {
        if (res[i]) cout << "S";
        else cout << "W";
    }
    cout << '\n';
    exit(0);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    cin >> str;

    res[0] = true;
    res[1] = true;
    attempt();
    if (check()) print();

    res[0] = true;
    res[1] = false;
    attempt();
    if (check()) print();

    res[0] = false;
    res[1] = false;
    attempt();
    if (check()) print();

    res[0] = false;
    res[1] = true;
    attempt();
    if (check()) print();

    cout << "-1\n";
}
/*

 */

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

int main(){
    string s,t,u;
    int a,b;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if( u == s ){
        a = a - 1;
    }
    if( u == t ){
        b = b - 1;
    }

    cout << a << " " << b <<endl;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

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

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  // Aで終わるやつにBを優先してつなげる
  int N;
  cin >> N;
  int ret = 0, x = 0, y = 0, z = 0;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for(int j = 0; j + 1 < s.size(); j++) {
      if(s[j] == 'A' && s[j + 1] == 'B') {
        ++ret;
      }
    }
    if(s.back() == 'A') {
      if(s.front() == 'B') ++x;
      else ++y;
    } else if(s.front() == 'B') {
      ++z;
    }
  }
  if(z == 0 && y == 0) cout << ret + max(x - 1, 0) << endl;
  else cout << ret + min(y + x, z + x) << endl;
}









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

int min(int a, int b) {
    return a<b?a:b;
}

int max(int a, int b) {
    return a>b?a:b;
}

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

int main() {
    int n, i, flag = 0;
    if(scanf("%d", &n)) {
        while(n) {
            if(n%10 == 7) {
                printf("Yes");
              	flag = 1;
                break;
            }
            n /= 10;
        }
      	if(!flag)
        	printf("No");
    }
    return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef vector<int> Vi; // ツ静ヲツ督ェツ要ツ素ツづーツ係ツ青板づつオツづ猟伉用

int N, M, P, d[12][7], D[20], p;
string ds[12], v[20], express;
bool is_error_occured;
map<string,int> hash;

Vi formula();
Vi term();
Vi factor();

Vi formula() {
  Vi ret = term();
  while (express[p] == '+' || express[p] == '-') {
    ++p;
    Vi rhs = term();
    for (int i = 1; i <= N; ++i) { // ツ督ッツつカツ篠淞個ウツつゥツチツェツッツク
      if (ret[i] != rhs[i]) {
        is_error_occured = true;
        return ret;
      }
    }
  }
  return ret;
}

Vi term() {
  Vi ret = factor();
  while (express[p] == '*' || express[p] == '/') {
    if (express[p] == '*') {
      ++p;
      Vi rhs = factor();
      for (int i = 1; i <= N; ++i) ret[i] += rhs[i];
    } else {
      ++p;
      Vi rhs = factor();
      for (int i = 1; i <= N; ++i) ret[i] -= rhs[i];
    }
  }
  return ret;
}

Vi factor() {
  Vi ret(N+1,0);
  if (express[p] == '(') {
    ++p; ret = formula(); ++p;
  } else {
    int lb = p, idx = -1;
    while (isalpha(express[p])) ++p;
    if (hash.count(express.substr(lb, p - lb))) {
      idx = hash[express.substr(lb, p - lb)];
    } else {
      cout << "Error Occur:[" << express.substr(lb, p - lb) << "]" << endl;
      exit(0);
    }
    ret[0] = 1;
    for (int i = 0; i < N; ++i) {
      ret[i+1] = d[idx][i];
    }
  }
  return ret;
}


int main() {
  while (cin >> N >> M >> P) {
    if (!(N)) break;
    hash.clear();
    string temp;
    rep(i,M) {
      cin >> ds[i];
      rep(j,N) cin >> d[i][j];
    }
    cin >> express;
    rep(i,P) {
      cin >> v[i] >> temp;
      rep(j,M) if (temp == ds[j]) { D[i] = j; break; }
      hash.insert(make_pair(v[i], D[i]));
    }
    p = 0;
    is_error_occured = false;
    Vi result = formula();
    int idx = -1;
    if (!is_error_occured) {
      for (int i = 0; i < M; ++i) {
        bool ok = true;
        for (int j = 0; j < N; ++j) {
          if (result[j+1] != d[i][j]) ok = false;
        }
        if (ok) idx = i;
      }
      // rep(i,result.size()) printf("%3d", result[i]); puts("");
      if (idx != -1)
        cout << ds[idx] << endl;
      else
        puts("undefined");
    } else {
      puts("error");
    }
  }
  return 0;
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const ld INF = 1e15;
ld dp[20001][102];
ld tv[20001];
int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>t(N);
	vector<int>v(N);
	rep(i, N)cin >> t[i];
	rep(i, N)cin >> v[i];
	int s = 0;
	rep(i, N) {
		rep(j, t[i] + 1) {
			tv[s +1+ j] = v[i];
		}
		s += t[i];
	}
	fill((*dp), (*dp) + 20001 * 101, -1);
	rep(i, 101)dp[0][i] = -INF;
	dp[0][0] = 0;
	reps(i,1,s+1) {
		rep(j, 101) {
			if (j < tv[i]) {
				dp[i][j] = max({ (j == 0 ? -INF : dp[i - 1][j - 1] - 0.5),dp[i - 1][j] + 0.25,dp[i - 1][j + 1] + 0.5 }) + (ld)j;
			}
			else if (j == tv[i]) {
				dp[i][j] = max({ (j == 0 ? -INF : dp[i - 1][j - 1] - 0.5),dp[i - 1][j] }) + (ld)j;
			}
			else dp[i][j] = -INF;
		}
	}
	cout <<fixed<<setprecision(10)<< dp[s][0] << endl;
}

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int max = 0;
        int cnt = 0;

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a >= max) {
                cnt++;
                max = Math.max(a, max);
            }
        }

        System.out.println(cnt);
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21844
import kotlin.math.abs

fun main() {
    val (X, N) = readLine()!!.split(" ").map { it.toInt() }
    if (N == 0) {
        println(X)
        return
    }
    
    val p = readLine()!!.split(" ").map { it.toInt() }.sortedBy { abs(X - it) }
    for (i in 0..100) {
        if (!p.contains(X - i)) {
            println(X - i)
            return
        } else if (!p.contains(X + i)) {
            println(X + i)
            return
        }
    }
}

Measured memory_bytes: 39116
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, L ;
    cin  >> N >> L;
    int sum = 0;
    int  mi = INT_MAX;
    int memo;
    for(int i = 1; i <= N; i++){
        int taste = L + i-1;
        sum += taste;
        if(mi > abs(sum - (sum - taste))){
            mi = abs(sum - (sum - taste));
            memo = taste;
        }
    }
    cout << sum - memo  << endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Process {
   private String name;
   private int time;
  
   public Process(String name, int time) {
       this.name = name;
       this.time = time;
   }
  
   public int getTime() {
       return time;
   }

   public void setTime(int time) {
       this.time = time;
   }

   public String getName() {
       return name;
   }
  
  
}
public class Main {

   public static void main(String[] args) {
      
       // scanner for input.
       Scanner s = new Scanner(System.in);
       // accept number of processes.
       int numberOfProcesses = s.nextInt();
       // accept time quantum.
       int timeQuantum = s.nextInt();
      
       // declare queue for processes.
       Queue<Process> processes = new LinkedList<Process>();
      
       // fill the queue form the input.
       for (int i = 0; i<numberOfProcesses; i++) {
           String namei = s.next();
           int timei = s.nextInt();
          
           Process processi = new Process(namei, timei);
           processes.add(processi);
       }
      
       // intialize current ongoing time.
       int currTime = 0;
       // check if process(Queue) is empty
       while(!processes.isEmpty()) {
           // get the head of queue and remove from queue.
           Process p = processes.poll();
           // if the current process is greater than time quantum
           // subtract its remaining time. and add the current time.
           // add the process back to queue.
           if (p.getTime() > timeQuantum) {
               p.setTime(p.getTime() - timeQuantum);
               currTime += timeQuantum;
               processes.add(p);
           }
           // Else add the current time and display the output.
           else {
               currTime += p.getTime();
               System.out.println(p.getName() + " " + currTime);
           }
       }
   }
}


Measured memory_bytes: 76508
a,b,c,d = map(int, input().split())
if 0 <= a :
  if 0 < d:
    print(b*d)
  else:
    print(a*d)
elif a < 0 and 0 < b:
  if 0 <= c:
    print(b*d)
  elif d < 0:
    print(a*c)
  else:
    print(max(a*c,b*d))
else: #b <= 0
  if c < 0:
    print(a*c)
  else:
    print(b*c)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N), S(N + 1);
    rep(i, N) cin >> A[i], S[i + 1] = S[i] + A[i];
    ll ans = 0;
    rep(i, N) {
        (ans += A[i] * ((S.back() - S[i + 1]) % MOD) % MOD) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<pair<int, int>> A(N);
  REP(i, N) {
    int a; cin >> a;
    A[i] = make_pair(a, i+1);
  }
  sort(ALL(A));
  REP(i, N) cout << A[i].second << " ";
  cout << endl;
}


Measured memory_bytes: 1664
import sys
D,N=map(int,input().split())
if D==0:
    if N==100:
        print(101)
        sys.exit()
    else:
        print(N)
        sys.exit()
elif D==1:
    if N==100:
        print(10100)
        sys.exit()
    else:
        print(N*100)
        sys.exit()
else:
    if N==100:
        print(N*10000+10000)
        sys.exit()
    else:
        print(N*10000)
        sys.exit()

Measured memory_bytes: 3064
#include<iostream>
int main(){
  int a,b,c;
  std::cin>>a>>b;
  if(b<10)c=a*10+b;
  else if(b<100)c=a*100+b;
  else c=a*1000+b;
  for(int i=1;i<1000;i++){
    if(c==i*i){
      std::cout<<"Yes"<<std::endl;
      break;
    }
    if(i==999)std::cout<<"No"<<std::endl;
  }
  return 0;
}


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

#define lp_ui(k,n) for(uint32_t i = (k); i < (n); i++)

typedef uint64_t     ul;
typedef uint32_t     ui;

using namespace std;

int main(void)
{
	ui N{ 0 };
	cin >> N;

	vector<ul> arrayA(N);
	ul sum{ 0 };
	ul halfSum{ 0 };

	lp_ui(0, N)
	{
		cin >> arrayA[i];

		sum += arrayA[i];
		if (i % 2 == 0)
		{
			halfSum += arrayA[i];
		}
	}

	// X_0の導出
	ul ans = halfSum * 2 - sum;
	cout << ans << endl;

	lp_ui(0, N)
	{
		// X_i = A_i * 2 - X_(i-1)
		ans = arrayA[i] * 2 - ans;

		if (i != N - 1)
		{
			cout << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define N 100'000
using namespace std;
int n, m;
struct edge { int u, v, w; };
struct half_edge { int v, w; };
vector<edge> edges;
vector<half_edge> adj[N+1];
int p[N+1];
void init() {
    for(int u = 0; u <= N; u++) {
        p[u] = u;
    }
}
int find(int u) {
    return p[u] == u ? u : p[u] = find(p[u]);
}
void merge(int u, int v) {
    p[find(u)] = find(v);
}
int indeg[N+1];
bool vis[N+1];
void toposort() {
    queue<int> bfs;
    for(int i = 1; i <= n; i++) {
        if(indeg[i] == 0) {
            bfs.push(i);
        }
    }
    while(!bfs.empty()) {
        int u = bfs.front();
        vis[u] = true;
        bfs.pop();
        for(auto e : adj[u]) {
            if(--indeg[e.v] == 0) {
                bfs.push(e.v);
            }
        }
    }
}
int d[N+1];
bool bfs_consistent(int s) {
    queue<int> bfs;
    bfs.push(s);
    d[s] = 0;
    vis[s] = true;
    bool ans = true;
    while(!bfs.empty()) {
        int u = bfs.front(); bfs.pop();
        for(auto e : adj[u]) {
            if(!vis[e.v]) {
                d[e.v] = d[u] + e.w;
                bfs.push(e.v);
                vis[e.v] = true;
            } else {
                ans &= d[e.v] == d[u] + e.w;
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    init();
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        if(w == 0) {
            merge(u, v);
        } else {
            edges.push_back({u, v, w});
        }
    }
    memset(indeg, 0, sizeof indeg);
    for(auto e : edges) {
        int u = find(e.u);
        int v = find(e.v);
        adj[u].push_back({v, e.w});
        indeg[v]++;
    }
    memset(vis, false, sizeof vis);
    toposort();
    bool can = true;
    for(int i = 1; i <= n && can; i++) {
        can &= vis[i];
    }
    for(auto e : edges) {
        int u = find(e.u);
        int v = find(e.v);
        adj[v].push_back({u, -e.w});
    }
    memset(vis, false, sizeof vis);
    for(int i = 1; i <= n && can; i++) {
        if(!vis[i]) {
            can &= bfs_consistent(i);
        }
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 12400
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  string s;
  cin>>s;
  int ans = 0;
  rep(i, 0, s.length())
    if(s[i] == '1')
      ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h = read::<usize>();
    let w = read::<usize>();
    let mut field = vec![vec![]; h];
    for y in 0..h {
        field[y] = read::<String>().chars().collect::<Vec<char>>();
    }
    let mut ans = 0;
    let mut sums = vec![vec![0; w]; h];
    for iter in 0..2 {
        let mut visit = vec![vec![false; w]; h];
        for y in 0..h {
            for x in 0..w {
                if visit[y][x] {
                    continue;
                }
                let dy = [1, 0][iter];
                let dx = [0, 1][iter];
                let mut ny = y;
                let mut nx = x;
                let mut cnt = 0;
                while ny < h && nx < w && field[ny][nx] != '#' {
                    visit[ny][nx] = true;
                    cnt += 1;
                    ny += dy;
                    nx += dx;
                }
                // println!("{} {} {} {} {}", x, y, cnt, nx, ny);
                ny = y;
                nx = x;
                while ny < h && nx < w && field[ny][nx] != '#' {
                    sums[ny][nx] += cnt;
                    ans = std::cmp::max(ans, sums[ny][nx] - 1);
                    ny += dy;
                    nx += dx;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 41212
A = []
for i in range(3):
  temp = list(map(int, input().split()))
  A.append(temp)
N = int(input())
for i in range(N):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if(A[j][k] == b):
        A[j][k] = 0
flag = 0
for i in range(3):
  if(A[i][0]==0 and A[i][1]==0 and A[i][2]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][i]==0 and A[1][i]==0 and A[2][i]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][0]==0 and A[1][1]==0 and A[2][2]==0):
    print("Yes")
    flag=1
    break
  elif(A[0][2]==0 and A[1][1]==0 and A[2][0]==0):
    print("Yes")
    flag=1
    break
if(flag==0):
  print("No")

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  string s;
  cin >> s;

  string right, left;
  right = left = "";
  ll r,l;
  l = 0;
  r = s.size()-1;
  ll ans = 0;
  while(l<=r){
    if(s[l]!=s[r] && s[l]!='x' && s[r]!='x'){
      cout << -1 << endl;
      return 0;
    }
    else if(s[l]!=s[r] && s[l]!='x'){
      ans++;
      r--;
    }
    else if(s[l]!=s[r] && s[r]!='x'){
      ans++;
      l++;
    }
    else if(s[l]==s[r]){
      l++;
      r--;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z=0,cnt=0,h=0,w=0,ans=0,sum=0, Max=-1, Min=3e9+1;
  string s,t;
  cin >> n;
  VL a(10000010);
  for(int i=1; i<=n; i++){
    for(int j=i; j<=n; j+=i){
      a[j]++;
    }
  }
  for(int i=1; i<=n;i++){
    ans += a[i]*i;
  }
  pri(ans);
  return 0;
}

Measured memory_bytes: 81400
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int A, B; cin >> A >> B;
	cout << (A - 1) * (B - 1) << endl;
}

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

char convert(char s, int keyNumber) {
    char c;
    unordered_map<int, char> mItoC;
    unordered_map<char, int> mCtoI;
    for (int i = 'z'; i >= 'a'; i--) {
        mItoC[122 - i] = (char)i;
    }
    for (int i = 'Z'; i >= 'A'; i--) {
        mItoC[116 - i] = (char)i;
    }
    for (int i = 'z'; i >= 'a'; i--) {
        mCtoI[(char)i] = 122 - i;
    }
    for (int i = 'Z'; i >= 'A'; i--) {
        mCtoI[(char)i] = 116 - i;
    }
    c = mItoC[(mCtoI[s] + keyNumber) % 52];
    return c;
}

int main() {
    while (1) {
        int N;
        cin >> N;
        if (!N) break;
        vector<int> K(N);
        for (int i = 0; i < N; i++) {
            cin >> K[i];
        }
        string S;
        cin >> S;
        string ans = "";
        for (int i = 0; i < S.length(); i++) {
            ans += convert(S[i], K[i%N]);
        }
        cout << ans << endl;
    }
}


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

int main()
{
    string s;
    cin >> s;
    int n = (int)s.size()-1;
    ll ans = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        ll t = s[0] - '0';
        ll add = 0;
        for(int j = 0; j < n; j++){
            if(bit & (1 << j)){
                add += t;
                t = 0;
            }
            t = t * 10 + s[j+1] - '0';
        }
        add += t;
        ans += add;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> p(n);
    ffor(i,n) cin >> p[i];
    // dp[i][j] -> probability of getting j heads if we have considered i items
    vector<vector<double>> dp(n + 1,vector<double>(n + 1));
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0;j <= n; ++j)
        {
            // current coin gave tails
            dp[i][j] = (dp[i - 1][j])*(1 - p[i - 1]);
            // current gave heads
            if(j == 0) continue;
            dp[i][j] += dp[i - 1][j - 1]*p[i - 1];
        }
    }
    double ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(i > n - i)
        ans += dp[n][i];
    }
    cout << fixed << setprecision(12) << ans;
}

Measured memory_bytes: 70784