akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005; 
int main ( ){
fast_io();
int a , b ;
cin >> a >> b ;
int x = ceil ( (100.0*a)/8.0 ) ;
int x2 = 10 * b ;
// cout << x <<" "<<x2 ,br 
int aa = 0.08 * x ;
int aaa = 0.1 * x ;
// cout << aa <<" "<<aaa ,br 

int bb =  0.08 *x2 ;
int bbb = 0.1 * x2 ;

// cout << bb <<" "<<bbb ,br
 
bool  ok1 = (aa == a and aaa ==b )  ;
bool ok2 =  (bb == a and bbb == b ); 
if (ok1 and ok2)
cout << min (x , x2 ) ; 
else if (ok1)
cout << x ;
else if (ok2 )
cout << x2 ;
else
cout << "-1" ;
br


return 0 ;
 
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main(){
  int i,j,n,x[10000],a=0;
  
  scanf("%d", &n);
  
  if(n >= 1 && n <= 100000){
  
      for(i = 0 ; i < n ; i++){
          scanf("%d",&x[i]);
      }
      
      for(i = 0 ; i < n ; i++){
          for(j = 2; j <=sqrt(x[i] ) ;j++){
              if(x[i] % j == 0){
                  a++;
              break;
              }
          }
      }
      
      printf("%d\n",n-a);
      
  }
}



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

int main(){
	long a[100001] = {};
	long n,k;
	int c,d;

	cin >> n >> k;
	for(int i = 0; i < n;++i){
		cin >> c >> d;
		a[c] += d;
	}

	for(int i = 1; i < 100001;++i){
		k -= a[i];
		if(k <= 0){
			cout << i << endl;
			return 0;
		}
	}

}

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

using namespace std;

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

typedef complex<double> p;

double cross(p a, p b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<p> point(n);
		REP(i, n) {
			double a, b;
			scanf("%lf,%lf", &a, &b);
			point[i] = p(a, b);
		}
		
		vector<bool> done(n, false);
		REP(i, n) FOR(j, i + 1, n) FOR(k, j + 1, n) {
			if (done[i] || done[j] || done[k]) continue;
			p now[4];
			now[0] = point[i]; now[1] = point[j]; now[2] = point[k];
			
			REP(l, n) {
				if (l == i || l == j || l == k || done[i] || done[j] || done[k]) continue;
				now[3] = point[l];
				
				int cnt = 0;
				REP(m, 3) {
					p v[2];
					v[0] = now[(m + 1) % 3] - now[m];
					v[1] = now[3] - now[m];
					if (cross(v[0], v[1]) < -EPS) cnt++;
				}
				if (cnt == 0 || cnt == 3) done[l] = true;
			}
		}
		
		int ans = 0;
		REP(i, n) if (done[i]) ans++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
# ユニオンファインド
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod

def comb(n):
    x=1
    y=1
    for i in range(2):
        x*=(n-i)
        y*=(i+1)
    return x//y


n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
b = [[] for i in range(n)]
uf = UnionFind(n)

ans=[]
x=comb(n)
for i in range(m):
    ans.append(x)
    if uf.same(a[m-i-1][0]-1,a[m-i-1][1]-1):
        uf.union(a[m-i-1][0]-1,a[m-i-1][1]-1)
    else:
        x-=uf.size(a[m-i-1][0]-1)*uf.size(a[m-i-1][1]-1)
        uf.union(a[m-i-1][0]-1,a[m-i-1][1]-1)
for i in range(m):
    print(ans[-1-i])

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

int main()
{
	int a,g,s,b,q;
	scanf("%d",&a);
	q = a / 1000;
	b = ( a - q * 1000 ) / 100;
	s = ( a - q * 1000 - b * 100) / 10;
	g = a % 10;
	if( (q == b && b == s ) || (g == s && s == b))
		printf("Yes\n");
		else printf("No\n");
}



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

    val n = readInputLine().toInt()

    builder.appendln(
        when(n % 10) {
            0 -> "pon"
            1 -> "pon"
            2 -> "hon"
            3 -> "bon"
            4 -> "hon"
            5 -> "hon"
            6 -> "pon"
            7 -> "hon"
            8 -> "pon"
            9 -> "hon"
            else -> ""
        }
    )

    print(builder.toString())
}

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


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  map<string, int> m;
  for (int i = 0; i < N; ++i) {
    ++m[S[i]];
  }
  cout << m.size() << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int min = 0;
  for (int i = 1; i < N; i++) {
    if (S.at(i) == 'E')
      min++;
  }
  
  int m = min;
  
  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) == 'W')
      m++;
    if (S.at(i) == 'E')
      m--;
      
    if (min > m)
      min = m;
  } 
  
  cout << min << endl;
}

Measured memory_bytes: 900
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi p(n);
  rep (i, n) {
    scanf("%d", &p[i]);
    p[i] -= 1;
  }
  vector<bool> same(n, false);
  rep (i, n) {
    if (p[i] == i) {
      same[i] = true;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ) {
    if (i == (n-1)) {
      if (same[i]) {
        cnt += 1;
      }
      break;
    }
    if (same[i]) {
      cnt += 1;
      if (same[i+1]) {
        i += 2;
      } else {
        i += 1;
      }
      continue;
    }
    i += 1;
  }
  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;

  for (int i=1; i<=9; i++){
    for (int j=1; j<=9; j++){
      if (i*j == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10=1024,X11=2048,X12=4096,X13=8196,X14=16392,X15=32786,X16=65536,X17=131072,X18=262144,X19=524288,X20=1048576;


int A[26];
void _(){
    int n,a;
    cin >> n >> a;
    cout <<(n%500 <=a ?"Yes":"No");
}






int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
const int N = 2005;
int calcc[N];
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int n, x, y;
	cin >> n >> x >> y;
	for(int i = 1; i <= n; i++)
		for(int j = i+1; j <= n; j++)
			calcc[min(j - i, abs(x - i) + abs(j - y) + 1)]++;
	
	for(int i = 1; i <= n-1; i++)
		cout << calcc[i] << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,A,B;
int main(){
	n=read(),m=read(),A=read(),B=read();
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			putchar(((i>B)^(j>A))+'0');
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<'\n';
	re 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cstdio>
#include <vector>
int fa[2005], deg[2005], dep[2005], arr[2005];
int idx[2005], bel[2005], vis[2005];
std::vector<int> vec[2005], blue[2005], ans;
inline void shift(int u)
{
	ans.push_back(u);
	std::vector<int> path;
	int v = u, orig = arr[0];
	while (v)
	{
		path.push_back(v);
		v = fa[v];
	}
	for (int i = path.size() - 1; i >= 0; i--)
		arr[fa[path[i]]] = arr[path[i]];
	arr[u] = orig;
}
int main()
{
	// freopen("H.in", "r", stdin);
	int n;
	scanf("%d", &n);
	fa[0] = -1;
	for (int i = 1; i < n; i++)
	{
		scanf("%d", fa + i);
		deg[fa[i]]++;
		dep[i] = dep[fa[i]] + 1;
	}
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	int rem = n - 1;
	while (rem)
	{
		for (int i = 0; i < n; i++)
		{
			vec[i].clear();
			blue[i].clear();
		}
		int cnt = 0;
		for (int u = 0; u < n; u++)
		{
			if (deg[u] || vis[u] == 2)
				continue;
			int v = u;
			while (v && deg[v] <= 1)
			{
				idx[v] = vec[cnt].size();
				bel[v] = cnt;
				vec[cnt].push_back(v);
				vis[v] = 1;
				v = fa[v];
			}
			cnt++;
		}
		while (true)
		{
			if (vis[arr[0]])
			{
				int u = arr[0];
				vis[u] = 2;
				rem--;
				deg[fa[u]]--;
				auto &add = blue[bel[u]];
				auto comp = [&] (int x, int y) { return idx[x] < idx[y]; };
				int pos = std::lower_bound(add.begin(), add.end(), u, comp) - add.begin();
				add.insert(add.begin() + pos, u);
				shift(vec[bel[u]][pos]);
			}
			else
			{
				int mx = -1;
				for (int u = 0; u < n; u++)
				{
					if (vis[arr[u]] == 1 && (mx == -1 || dep[u] > dep[mx]))
						mx = u;
				}
				if (-1 == mx)
					break;
				shift(mx);
			}
		}
	}
	printf("%d\n", (int)ans.size());
	for (int u : ans)
		printf("%d\n", u);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define H_MAX 500005

int A[H_MAX];
int H;
void maxHeapify(int *A, int i);
void buildMaxHeap(int *A);

int main(){
  int i;

  scanf("%d", &H);
  for(i=1; i<H+1; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap(A);

  for(i=1; i<H+1; i++){
    printf(" %d", A[i]);
  }
  printf("\n");

  return 0;
}


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

  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }

  if(r <= H && A[r] > A[largest]){
    largest = r;
  }

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

void buildMaxHeap(int *A)
{
  int i;
  for(i=H/2; i>0; i--){
    maxHeapify(A, i);
  }
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define N 100007
using namespace std;
vector <int> adj[N];
int mem[N];
int dp(int i)
{
    if(mem[i] != -1)
        return mem[i];
    int ans = 0;
    for(int j = 0;j < adj[i].size();j++)
    {
        int k = dp(adj[i][j]);
        ans = max(ans, k);
    }
    ans += 1;
    mem[i] = ans;
    return ans;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m;
    cin >> n >> m;
    memset(mem, -1, sizeof(mem));
    for(int i = 0;i < m;i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }
    int mx = 0;
    for(int i = 1;i < N;i++)
    {
        int k = dp(i);
        if(k > mx)
            mx = k;
    }
    cout << mx-1 << endl;
    return 0;
}

Measured memory_bytes: 11432
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
S = input()
k = len(S)
ans = "Yes"

for i in range(k):
  if (i%2) == 1 and S[i] == "R":
    ans = "No"
    break
  elif (i%2) == 0 and S[i] == "L":
    ans = "No"
    break
    
print(ans)

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

int main() {
  long long int N;
  cin >> N;
  long long int ans=0;

  
  for(int i=sqrt(N);i>=1;i--){
    if(N%i==0){
      cout << i + N/i -2 << endl;
      break;
    }
  }

}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

int dp[20][1005][2][2];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.size();

  dp[0][0][0][0] = 1;
  REP(i, n) REP(j, 1000) REP(k, 2) REP(l, 2) {
    int lim = k ? 9 : s[i]-'0';
    REP(nxt, lim+1) {
      int cond = l || (j/100 == 5 && j%100/10 == 1 && nxt == 3);
      dp[i+1][j%100*10 + nxt][k || nxt < lim][cond] += dp[i][j][k][l];
      // if(cond==1) {
      //   cout << i << " " << j << " " << k << " " << l << " " << nxt << endl;
      //   cout << dp[i+1][j%100*10 + nxt][k || nxt < lim][cond] << " " << dp[i][j][k][l] << endl;
      // }
    }
  }

  int ans = 0;
  REP(i, 1000) REP(j, 2) {
    ans += dp[n][i][j][1];
    // if(dp[n][i][j][1]) {
    //   cout << i << " " << j << " " << dp[n][i][j][1] << endl;
    // }
  }
  cout << ans << endl;

  return 0;
}



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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> answer(2000);
  int maxi = 0;
  
  for(int i = 1; i < n; ++i) {
    for(int j = i + 1; j <= n; ++j) {
      int mini = min(j - i, abs(x - i) + 1 + abs(y - j));
      ++answer[mini];
    }
  }
  
  rep(i, n - 1) cout << answer[i+1] << endl;
  return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var c = long.Parse(line[2]);
        Console.WriteLine((a % 2 == 0) || (b % 2 == 0) || (c % 2 == 0) ? 0 : getMin(a, b, c));
    }
    public static long getMin(long a, long b, long c)
    {
        var w = new long[3];
        w[0] = getMin2(a, b, c);
        w[1] = getMin2(b, a, c);
        w[2] = getMin2(c, a, b);
        return w.Min();
    }
    public static long getMin2(long a, long b, long c) => (a - 2 * (a / 2)) * b * c;
}


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


int chk(string s, string str, int n) {
	for(int i = 0; i < n; i++) {
		char prv = str[(i + n - 1) % n], nxt = str[(i + 1) % n];
		if(str[i] == 'S') {
			if((prv != nxt) && s[i] == 'o') {
				return 0;
			}
			if((prv == nxt) && s[i] == 'x') {
				return 0;
			}
		} else {
			if((prv == nxt) && s[i] == 'o') {
				return 0;
			}
			if((prv != nxt) && s[i] == 'x') {
				return 0;
			}
		}
	}
	return 1;
}

string construct(string str, string s, int n) {
	for(int i = 1; i < n - 1; i++) {
		char ch = s[i - 1];
		if(s[i] == 'S') {
			if(str[i] == 'o') {
				s.push_back(ch);
			} else {
				s.push_back(ch ^ 'S' ^ 'W');
			}
		} else {
			if(str[i] == 'x') {
				s.push_back(ch);
			} else {
				s.push_back(ch ^ 'S' ^ 'W');
			}
		}
	}
	return s;
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; string s; cin >> n >> s;
	string ss[] = {"SS", "WW", "SW", "WS"};
	for(int i = 0; i < 4; i++) {
		string k = construct(s, ss[i], n);
		if(chk(s, k, n)) {
			cout << k << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 3784
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

signed main(void)
{
  int l;
  string s, t;
  cin >> l >> s >> t;
  REP(i, l) {
    if(s[i%s.size()] < t[i%t.size()]) break;
    else if(s[i%s.size()] > t[i%t.size()]) {
      swap(s, t);
      break;
    }
  }

  for(int i=0; i*(int)t.size()<=l; ++i) {
    int len = l-(int)t.size()*i;
    if(len%s.size() == 0) {
      REP(j, len/s.size()) {
        cout << s;
      }
      REP(j, i) {
        cout << t;
      }
      cout << endl;
      return 0;
    }
  }
  assert(false);

  return 0;
}


Measured memory_bytes: 1024
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let x = nextInt()
    const large = Math.floor(x / 500)
    x = x - 500 * large
    const small = Math.floor(x / 5)
    console.log(1000 * large + 5 * small)

}
Main()


Measured memory_bytes: 29660
#include "math.h"
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<vector>

using namespace std;

int main(void){
    int menu[4];
	int cut_time = 10;
	int result = 0;

    cin>>menu[0];
    cin>>menu[1];
    cin>>menu[2];
    cin>>menu[3];
    cin>>menu[4];

	for(int i=0; i<5; i++){
		if((menu[i]%10 != 0) && (menu[i]%10 < cut_time)){
			cut_time = menu[i]%10;
		}
	}
	
	for(int i=0; i<5; i++){
		result += ((menu[i]-1)/10+1)*10;
	}
	
	if(cut_time != 0){
		result -= 10-cut_time;
    }
    
    cout<<result<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
bool mfprime[352010];
int main(void)
{
  REP(i,302010) mfprime[i]=false;
  REP(i,50000){
    int j=i*7+6;
    mfprime[j]=true;
    j=i*7+8;
    mfprime[j]=true;
  }
  REP(i,500){
    int j=i*7+6;
    if(mfprime[j])
      for(int k=j*j;k<302010;k+=j)
	if(k/j%7!=1 && k/j%7!=6) continue;
	else mfprime[k]=false;
    j=i*7+8;
    if(mfprime[j])
      for(int k=j*j;k<302010;k+=j)
	if(k/j%7!=1 && k/j%7!=6) continue;
	else mfprime[k]=false;
  }
  vector<int> mfpv;
  REP(i,50000){
    int j=i*7+6;
    if(mfprime[j]) mfpv.push_back(j);
    j=i*7+8;
    if(mfprime[j]) mfpv.push_back(j);
  }
  for(;;){
    int n;
    cin >> n;
    if(n==1) return 0;
    cout << n << ':';
    REP(i,mfpv.size())
      if(n%mfpv[i]==0) cout << ' ' << mfpv[i];
    cout << endl;
  }
}

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

int main() {
    long long int ans = 1;
    int N,K;
    cin >> N >> K;
    for(int i = 0;i < N; i++){
        if(ans >= K){
            ans += K;
        }
        else{
            ans *= 2;
        }
    }
    cout << ans << endl;
}


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

struct Point {
  double x;
  double y;
};

double dot(Point p0, Point p1, Point p2, Point p3) {
  return (p1.x - p0.x) * (p3.x - p2.x) + (p1.y - p0.y) * (p3.y - p2.y);
}

double cross(Point p0, Point p1, Point p2, Point p3) {
  return (p1.x - p0.x) * (p3.y - p2.y) - (p1.y - p0.y) * (p3.x - p2.x);
}

int main(void) {
  int q;
  Point p0, p1, p2, p3;
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    if(dot(p0, p1, p2, p3) == 0.0) { //垂直だった場合
      cout << "1" << endl;
    }
    else if(cross(p0, p1, p2, p3) == 0.0) { //平行だった場合
      cout << "2" << endl;
    }
    else {
      cout << "0" << endl;
    }
  }
}


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

int main()
{
    int n, m;
  	cin >> n >> m;
    int array[n][m];
    int vector[m];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            cin >> array[i][j];
    }
    for(int i = 0; i < m; i++)
        cin >> vector[i];
    for(int i = 0; i < n; i++)
    {
        int sum = 0;
        for(int j = 0; j < m; j++)
            sum += array[i][j] * vector[j];
        cout << sum << endl;
    }
}


Measured memory_bytes: 3120
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;
typedef pair<int,string> P;
string s;
int n,m;
vector<P> p;
map<string,int> q;

int main(){
	scanf("%d",&n);
	p.resize(n);
	for(int i=0;i<n;i++){
		cin>>p[i].second>>m;
		p[i].first=p[i].second.size();
		q[p[i].second]+=m;
	}
	sort(p.begin(),p.end());
	for(int i=0;i<n;i++){
		if(i&&p[i]==p[i-1]) continue;
		printf("%s %d\n",p[i].second.c_str(),q[p[i].second]);
	}
}


Measured memory_bytes: 3852
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
        ab:[(Usize1,Usize1);m],
    }
    let mut v = vec![vec![]; n];
    let mut uf = UnionFind::new(n);
    for (a, b) in ab {
        v[a].push(b);
        v[b].push(a);
        uf.unite(a, b);
    }
    let mut st = BTreeSet::new();
    let mut mx = 0;
    for i in 0..n {
        st.insert(uf.par[i]);
        mx = max(mx, uf.size(i));
    }
    // dbg!(mx);
    println!("{}", mx);
}
pub struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
    size: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            par: vec,
            rank: vec![0; n],
            size: vec![1; n],
        }
    }
    pub fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        } else {
            let par = self.par[x];
            let res = self.find(par);
            self.par[x] = res;
            res
        }
    }
    pub fn same(&mut self, a: usize, b: usize) -> bool {
        self.find(a) == self.find(b)
    }
    pub fn unite(&mut self, a: usize, b: usize) {
        let apar = self.find(a);
        let bpar = self.find(b);
        if apar == bpar {
            return;
        }
        if self.rank[apar] > self.rank[bpar] {
            self.par[bpar] = apar;
            self.size[apar] += self.size[bpar];
        } else {
            self.par[apar] = bpar;
            self.size[bpar] += self.size[apar];
            if self.rank[apar] == self.rank[bpar] {
                self.rank[bpar] += 1;
            }
        }
    }
    pub fn size(&mut self, a: usize) -> usize {
        let p = self.find(a);
        self.size[p]
    }
}


Measured memory_bytes: 25516
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int a, b;
    cin >> a >> b;

    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i != n; ++i)
        cin >> x[i] >> y[i];
    double s = .0;
    for (int i = 0; i != n - 1; ++i)
        for (int j = i + 1; j != n; ++j)
            s += hypot(x[i] - x[j], y[i] - y[j]) * 2.0 / n;
    cout << fixed;
    cout.precision(8);
    cout << s;
    return 0;
}

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

using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");

#define hello cout << "hello" << endl
#define dbg(var) cout << #var << " --> " << var << endl
#define mset(a, b)  memset(a, b, sizeof(a))
#define vi vector<int>
#define vii vector<pair<int, int> >
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define boost ios_base::sync_with_stdio(false)

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 1e5 + 10;

int a[55][55];
vector<string> v;
int main(){
	boost;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		string s;
		cin >> s;
		v.push_back(s);
	}
	for(int i = 0; i < v.size(); ++i){
		int m = v[i].length();
		string s = v[i];
		for(int j = 0; j < m; ++j){
			++a[i][s[j] - 'a'];
		}
	}
	string ans;
	for(int j = 0; j < 26; ++j){
		int mi = inf;
		for(int i = 0; i < n; ++i){
			mi = min(mi, a[i][j]);
		}
		while(mi--){
			ans.pb(j + 'a');
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static final void main(String[] args) {
    Rectangle rectangle;
    Circle circle;

    try (Scanner scanner = new Scanner(System.in)) {
      int width = scanner.nextInt();
      int height = scanner.nextInt();
      rectangle = new RectangleImpl(width, height);
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      int center = scanner.nextInt();
      circle = new CircleImpl(x, y, center);
    } catch (Exception e) {
      return;
    }
    if (rectangle.isInCircle(circle)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

interface Rectangle {
  boolean isInCircle(Circle circle);
}

final class RectangleImpl implements Rectangle {

  private final int width;
  private final int height;

  RectangleImpl(int width, int height) {
    this.width = width;
    this.height = height;
  }

  @Override
  public boolean isInCircle(Circle circle) {
    if (circle.getX() - circle.getCenter() < 0) {
      return false;
    }

    if (circle.getX() + circle.getCenter() > width) {
      return false;
    }

    if (circle.getY() - circle.getCenter() < 0) {
      return false;
    }

    if (circle.getY() + circle.getCenter() > height) {
      return false;
    }
    return true;
  }
}

interface Circle {
  int getX();

  int getY();

  int getCenter();
}

final class CircleImpl implements Circle {
  private final int x;
  private final int y;
  private final int center;


  CircleImpl(int x, int y, int center) {
    this.x = x;
    this.y = y;
    this.center = center;
  }

  @Override
  public int getX() {
    return x;
  }

  @Override
  public int getY() {
    return y;
  }

  @Override
  public int getCenter() {
    return center;
  }
}

Measured memory_bytes: 26412
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define F first
#define S second
using namespace std;
int main(){
string s;
int r=0,c=1,i;
vector<pair<char,int> > v;
cin>>s;
char t=s[0];
for(i=1;i<s.size();++i){
if(s[i] == t){
c++;
}else{
v.push_back(make_pair(t,c));
c=1;
t=s[i];
}
}
v.push_back(make_pair(t,c));
for(int i=0;v.size()>=3&&i<v.size()-2;++i){
if(v[i].F=='J' &&
v[i+1].F=='O' &&
v[i+2].F=='I'){
if(v[i].S>=v[i+1].S &&
v[i+2].S>=v[i+1].S){
r=max(r,min(v[i].S,min(v[i+1].S,v[i+2].S)));
}
}
}
cout<<r<< endl;
}

Measured memory_bytes: 9924
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <limits>
#include <utility>
#include <string>
#include <numeric>

template<class T>
using Edge = std::pair<T, T>;
template<class T>
using Graph = std::vector<std::vector<Edge<T> > >;

//The id of a vertex in the graph must be in [0,V).
template<class T>
std::pair<std::vector<T>, std::vector<T> > Dijkstra(Graph<T> &graph, const T &start){
    const T V = graph.size();
    const T distanceSup = std::numeric_limits<T>::max();
    const T zero = static_cast<T>(0);

    std::vector<T> distance(V, distanceSup);
    std::vector<T> predecessor(V);
    std::vector<bool> isVisited(V, false);
    distance[start] = zero;
    std::iota(predecessor.begin(),predecessor.end(),zero);

    auto compare = [](const std::pair<T,T> &a, const std::pair<T,T> &b){
        return a.second > b.second;
    };
    std::priority_queue<std::pair<T,T>, std::vector<std::pair<T,T> >, decltype(compare)> queue(compare);
    queue.emplace(start,distance[start]);
    T pred, suc;
    T distTmp;
    while(!queue.empty()){
        pred = queue.top().first;
        if(isVisited[pred]){
            queue.pop();
            continue;
        }
        isVisited[pred] = true;
        queue.pop();

        if(distance[pred] == distanceSup){
            break;
        }

        for(auto &edge: graph[pred]){
            suc = edge.first;
            if(isVisited[suc]){
                continue;
            }
            distTmp = distance[pred] + edge.second;
            if(distance[suc] > distTmp){
                distance[suc] = distTmp;
                predecessor[suc] = pred;
                queue.emplace(suc,distance[suc]);
            }
        }        
    }

    return std::pair<std::vector<T>, std::vector<T> >(distance,predecessor);
}

int main(int argc, char *argv[]){
    long int N,M;
    std::cin >> N >> M;
    if(M<1){
        std::cout << -1 << std::endl;
        return 0;
    }
    long int u,v;
    Graph<long int> graph(3*N);
    Edge<long int> edge;
    for(long int i=0; i<M; ++i){
        std::cin >> u >> v;
        --u; --v;
        graph[u].emplace_back(v+N,1);
        graph[u+N].emplace_back(v+2*N,1);
        graph[u+2*N].emplace_back(v,1);
    }
    long int S,T;
    std::cin >> S >> T;
    --S; --T;

    auto dijkstra = Dijkstra(graph, S).first[T];
    if(dijkstra < std::numeric_limits<long int>::max()){
        std::cout << dijkstra/3 << std::endl;
    }else{
        std::cout << -1 << std::endl;
    }
    return 0;
}


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

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  
  int sum = 0;
  int m = min(X,Y);
  
  if (A + B > C * 2) {
    sum += min(X,Y) * (C * 2);
    X -= m;
    Y -= m;

    if (X > 0 || Y > 0) {
      if (X > 0) {
        if (A > C * 2)
          sum += (C * 2) * X;
        else
          sum += A * X;
      }
      else {
        if (B > C * 2)
          sum += (C * 2) * Y;
        else
          sum += B * Y;
      }
    }
  }
  else {
    sum += A * X + B * Y;
    X -= m;
    Y -= m;
  }
   
  cout << sum << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '2') {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,n;
    cin>>w>>h>>n;
    int x[2],y[2];
    cin>>x[0]>>y[0];
    int ans=0;
    for(int i=1;i<n;i++){
        cin>>x[1]>>y[1];
        if(x[0]<x[1]&&y[0]<y[1]||x[0]>x[1]&&y[0]>y[1]){
            int kawa=min(abs(x[1]-x[0]),abs(y[1]-y[0]));
            ans+=kawa+max(abs(x[1]-x[0])-kawa,abs(y[1]-y[0])-kawa);
        }
        else ans+=abs(x[0]-x[1])+abs(y[0]-y[1]);
        x[0]=x[1];
        y[0]=y[1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 300005;

LL ec = 0,hed[N] = {0},nxt[N << 1],to[N << 1];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL fa[N],dis[N] = {0},deg[N],vis[N] = {0};
LL a[N],ac = 0,b[N],n;

void dfs(LL u,LL f){
	fa[u] = f; dis[u] = dis[f] + 1;
	deg[u] = 0;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		deg[u] ++;
		dfs(v,u);
	}
}

LL solve(){
	LL id = 0,ed = 0;
	dfs(1,0); for(LL i = 1;i <= n;i ++) if(dis[i] > dis[id]) id = i;
	dfs(id,0); for(LL i = 1;i <= n;i ++) if(dis[i] > dis[ed]) ed = i;
	deg[ed] = 1;
	while(ed){
		a[++ ac] = ed;
		vis[ed] = 1; ed = fa[ed];
	}
	for(LL i = 1;i <= ac;i ++) b[i] = a[ac + 1 - i];
	for(LL i = 1;i <= n;i ++) if(!vis[i] && deg[i]) return 1;
	for(LL i = 1;i <= ac;i ++) a[i] = deg[a[i]],b[i] = deg[b[i]];
	return 0;
}

LL comp(){
	for(LL i = 1;i <= n;i ++){
		if(a[i] > b[i]) return 1;
		if(a[i] < b[i]) return -1;
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	if(solve()){ cout << -1 << '\n'; return 0; }
	if(comp() == 1) swap(a,b);
//	for(LL i = 1;i <= ac;i ++) cout << a[i] << (i == ac ? '\n' : ' ');
	LL now = 1;
	for(LL i = 1;i <= ac;i ++){
		for(LL j = 1;j < a[i];j ++) cout << now + j << ' ';
		cout << now << ' '; now += a[i];
	} cout << '\n';
	return 0;
}

Measured memory_bytes: 23168
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

class BIT {
    // Binary Indexed Tree : 数列要素1つへの加算、数列のある地点までの累積和を高速に計算
    public:
    std::vector<int> data;
    BIT() {}
    BIT(const int size) {
        // 想定されるサイズの2倍の値を入れた方がいいかもしれない。数列は1から数えることを想定している。
        data.resize(size, 0);
    }
    int sum(int i) const {
        int s = 0;
        while (i > 0) {
            s += data[i];
            i = i & (i-1); // iの最後のビットを引く。
        }
        return s;
    }

    void add(int i, int x) {
        while (i < data.size()) {
            data[i] += x;
            i += i - (i & (i-1)); // iの最後のビットを加算する。
        }
    }
};

const int MAX_N = 200050;
const int NUM = 26;
std::string S;

int N, A[MAX_N];

std::vector<int> loc[NUM];
int front[NUM], back[NUM];

BIT processed = BIT(MAX_N * 2);

int main(int argc, char **argv) {
    std::cin >> S;
    N = S.size();

    for (int i = 1; i <= N; i++) {
        A[i] = S[i-1] - 'a';
        loc[A[i]].push_back(i);
        //std::cout << A[i] << std::endl;
    }

    int odd_num = 0;
    for (int i = 0; i < NUM; i++) {
        if (loc[i].size() == 0) {
            front[i] = -1;
            back[i] = -1;
        } else if (loc[i].size() % 2 == 0) {
            front[i] = 0;
            back[i] = loc[i].size() - 1;
        } else {
            front[i] = 0;
            back[i] = loc[i].size() - 1;
            odd_num++;
        }
    }

    if (1 < odd_num) {
        std::cout << "-1" << std::endl;
        return 0;
    }

    int tmp = 1;
    int cnt = 0;
    int center = -1;
    long long ret = 0;
    //for (int i = 1; i <= N/2; i++) {
    while(cnt < N/2) {
        int is_processed = (tmp == 1) ? processed.sum(1) : processed.sum(tmp) - processed.sum(tmp - 1);
        int cur = A[tmp];
        //std::cout << tmp << " " << is_processed << " " << cur << std::endl;
        if (is_processed) {
            // nothing
        } else if (loc[cur].size() % 2 == 1 && front[cur] == back[cur]) {
            center = cnt;
        } else {
            ret += N - loc[cur][back[cur]] - (processed.sum(N) - processed.sum(loc[cur][back[cur]]));
            processed.add(loc[cur][front[cur]], 1);
            processed.add(loc[cur][back[cur]], 1);

            front[cur]++;
            back[cur]--;
            cnt++;
        }
        tmp++;
    }

    //std::cout << "check:" << ret << " " << center << std::endl;

    if (center != -1) {
        ret += (N/2 - center);
    }
    std::cout << ret << std::endl;

    return 0;

}

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

int main() {
  int N; cin >> N;
  string A, B, C; cin >> A >> B >> C;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    set<char> s;
    s.insert(A.at(i));
    s.insert(B.at(i));
    s.insert(C.at(i));
    if (s.size() == 1) continue;
    else if (s.size() == 2) ans++;
    else ans += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad.ST
import Data.Array.ST
import Control.Monad
import Data.Array
import Data.List

main = do
  (n:k:xx) <- map read . words <$> getLine 
  xs <- map read . words <$> getLine
  putStrLn . show $ solve n k xs

solve :: Int -> Int -> [Int] -> Int
solve n k xs = sum . take (n-k) . sort . elems $ runSTArray $ calcInST n xs


calcInST :: Int -> [Int] -> ST s (STArray s Int Int)
calcInST n xs = do
  arr <- newArray (1,n) 0
  forM_ xs $ \x -> do
    v <- readArray arr x 
    writeArray arr x (v+1)
  return arr


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


int main() {

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

	int a, b;

	cin >> a >> b;

	if( a + b == 15 ) {
		cout << "+" << endl;
	}
	else if( a * b == 15 ) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}


}

Measured memory_bytes: 256
# coding: utf-8
import sys
sysread = sys.stdin.readline
from collections import defaultdict
sys.setrecursionlimit(10**7)
def run():

    N,M,K = map(int,sysread().split())
    to = [[] for _ in range(N+1)]
    n_to = [0 for _ in range(N + 1)]
    for i in range(1,M+1):
        a,b = map(int, sysread().split())
        #a,b = AB[i]
        to[a].append(b)
        n_to[a] += 1
        to[b].append(a)
        n_to[b] += 1

    stack = defaultdict(lambda:0)
    visited = [False] * (N+1)
    belong = [None] * (N+1)


    def dfs(n):
        _stack = [n]
        visited[n] = True
        while _stack:
            node = _stack.pop()
            stack[n] += 1
            belong[node] = n
            for next in to[node]:
                if not visited[next]:
                    _stack.append(next)
                    visited[next] = True
        return None


    for i in range(1,N+1):
        if not visited[i]:
            dfs(i)

    block = [0 for _ in range(N+1)]
    for i in range(1, K+1):
        c,d = map(int, sysread().split())
        #c, d = CD[i]
        if belong[c] == belong[d]:
            block[c] += 1
            block[d] += 1

    candidates = [0] * (N+1)

    for k in range(1,N+1):
        tr = belong[k]
        candidates[k] = stack[tr] - 1 - n_to[k] - block[k]

    print(' '.join(map(str, candidates[1:])))

if __name__ == "__main__":
    run()

Measured memory_bytes: 39372
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>
#include <set>

#define int long long
typedef long long ll;
//#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 1000000007

using namespace std;

typedef vector<int> V;
typedef vector<V> VV;

map<ll, ll> cnt;
map<ll, ll> w2idx;
int idx2w[4];
vector<ll> vs[4];
vector<ll> sum[4];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N, W;
    ll w[110], v[110];

    cin >> N >> W;
    int idx = 0;
    REP(i,N) {
        cin >> w[i] >> v[i];
        if (cnt[w[i]] == 0) {
            w2idx[w[i]] = idx;
            idx2w[idx] = w[i];
            idx++;
        }
        cnt[w[i]]++;
        vs[w2idx[w[i]]].push_back(v[i]);
    }

    REP(i,4) {
        sort(vs[i].begin(), vs[i].end(), greater<ll>());
        sum[i].push_back(0);
        sum[i].resize(vs[i].size() + 1);
        REP(j,vs[i].size()) {
            sum[i][j+1] = sum[i][j] + vs[i][j];
        }
    }

    /*
    REP(i,4) {
        REP(j,sum[i].size()) {
            cout << sum[i][j] << " ";
        }
        cout << endl;
    }
    */

    ll ans = 0;
    FOR(i,0,vs[0].size()+1) {
        FOR(j,0,vs[1].size()+1) {
            FOR(k,0,vs[2].size()+1) {
                FOR(l,0,vs[3].size()+1) {
                    if (idx2w[0] * i + idx2w[1] * j + idx2w[2] * k + idx2w[3] * l <= W) {
                        ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int a,b;

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

  return 0;
}


Measured memory_bytes: 3640
N = int(input())
A = list(map(int, input().split()))

def rec(i, n):
    if i == N:
        return 1 if n % 2 == 0 else 0
    res = 0
    a = A[i]
    res += rec(i+1, n*(a-1))
    res += rec(i+1, n*(a+1))
    res += rec(i+1, n*a)

    return res

print(rec(0, 1))


Measured memory_bytes: 3060
s = input()

a = int(s[0:2])
b = int(s[2:])

if a >= 1 and a <= 12:
  if b >= 1 and b <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if b >= 1 and b <= 12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    string T;
    cin >> T;
    ll len = S.size();
    vector<vector<ll> > vec(26, vector<ll>(0));
    rep(i,len){
        int x = S[i] - 'a';
        ll y = i + 1;
        vec[x].push_back(y);
    }
    rep(i,len){
        int x = S[i] - 'a';
        ll y = i + len + 1;
        vec[x].push_back(y);
    }
    ll now = 0;
    ll ans = 0;
    rep(i,T.size()){
        int x = T[i] - 'a';
        if (vec[x].size() == 0){
            ans += -500000000000;
        }
        else{
            vector<ll>::iterator itr = upper_bound(all(vec[x]), now);
            ans += (*itr - now);
            if (*itr > len) now = *itr - len;
            else now = *itr;
        }
    }
    if (ans < 0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 5760