akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <set>
#define LL long long
#define mp make_pair
#define x first
#define y second

using namespace std;

const int maxn=2010;
const int oo=1000000000;
const int modulo=1000000007;

int w, h, ans;
string s[maxn];
int a[maxn][maxn];
stack<pair<int, int>> st;

void input(){
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> s[i];
}

void init(){
    for (int i = 1; i < h; i++)
    for (int j = 1; j < w; j++){
        if ((s[i][j] + s[i-1][j] + s[i][j-1] + s[i-1][j-1]) % 2 == 0)
            a[i][j] = a[i-1][j] + 1;
        else
            a[i][j] = 0;
    }
}

void solve(){
    ans = max(w, h);
    st.push({0, 0});
    for (int i = 1; i < h; i++){
        // cout << "Size " << st.size() << endl;
        for (int j = 1; j <= w; j++){
            int l = j;
            while (a[i][j] < a[i][st.top().x]){
                // cout << i << ' ' << j << ' ' << a[i][j] << ' ' << l << ' ' << st.top().x << ' ' << st.top().y << endl;
                l = min(l, st.top().y);
                ans = max(ans, (j - st.top().y + 1) * (a[i][st.top().x] + 1));
                st.pop();
            }
            if (a[i][j] > a[i][st.top().x]){
                st.push({j, l});
                // cout << "Push " << i << ' ' << j << ' ' << a[i][j] << ' ' << l << endl;
            }
        }
    }
}

void output(){
    cout << ans;
}

int main(){
//	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
	std::ios::sync_with_stdio(false);
	input();
	init();
	solve();
	output();

	return(0);
}


Measured memory_bytes: 20224
my $N = <>;
my $s = <>; chomp $s;
my @dat = split(/ /,$s);
my $total=0;
for(my $i=0;$i<=$#dat;$i++){
  $total = $total ^ $dat[$i];
}

for(my $i=0;$i<=$#dat;$i++){
  my $ans = $total ^ $dat[$i]; 
  print "$ans ";
}

Measured memory_bytes: 27184
#include <iostream>
#include <string>
#include <vector>

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

int main() {
    int N, K;
    string s;
    cin >> N >> K >> s;

    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    rep(i, N){
        if(s[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) Nums.push_back(cnt);

    if(Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2 * K + 1;
    
    int ans = 0;

    int left = 0;
    int right = 0;
    int tmp = 0;
    
    for (int i = 0; i < Nums.size(); i += 2) {
        int Nextleft = i;
        int Nextright = min(i + Add, (int)Nums.size());

        while (Nextleft > left) {
            tmp -= Nums[left];
            left++;
        } 
        
        while (Nextright > right) {
            tmp += Nums[right];
            right++;
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

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

/*
括弧を形成できていない数をそれぞれカウントしておく
括弧を形成できていないのは...))...((...のような形式になるはず
つまり{left, right}の組を作れる
あとは、left = 0のものと、right = 0のものが存在し、leftとrightが同数ならできる
-> leftとrightが同数でも場合によってはできない

leftが効果を及ぼすのは自分より右だけ、rightが効果を及ぼすのは自分より左だけ
順番においていって、leftより大きいrightがきたら無理
途中でマイナスになったらダメ
- right + leftの順番でやっていくので、rightがある値以下のもので、left - rightが最大のものを選びたい(最大とは限らないかも)

4
(
)
)))(     
)))(((((
とか

とれるものは現在のall_leftよりrightが小さいものしかない
方針としては2つ
i)rightがもっとも大きいものをとる
	これによってall_leftが小さくなってしまう可能性あり、最善じゃなさそう
ii)left - rightがもっとも大きいものをとる
	次にとれるrightの最大を最大化してくれそう、でもそれをとったことで次のrightで該当するものがなくなるかも
	3 -> {3, 2}, {2, 0}, {1, 0}
	どちらにせよ、いずれとるので、今とったことで取れなくなるならとれない？？？

BITでできそうだけど、値の削除ができないので難しいかも
遅延評価セグ木でやる？
sortして、pairとindexを対応させれば、値の削除もできそう

[解説よんで]
left = 0, right = 0は無視
right = 0のものを連結
left >= rightとなるものをrightが小さい順にたす(もし途中で連結できない場合は、順番を入れ替えてもそのrightをとることはできないことからNo)
right < leftとなるものをleftが大きい順にたす(もし途中で連結できなければ、順番を入れ替えてもrightに対処できない)
left = 0のものを連結
*/

int	main(void)
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	vector<pair<int, int>> positive;
	vector<pair<int, int>> negative;
	int left_cnt = 0;
	int right_cnt = 0;
	for (int i = 0; i < n; i++)
	{
		int left = 0;
		int right = 0;
		for (int j = 0; j < s[i].size(); j++)
		{
			if (s[i][j] == '(') left++;
			else
			{
				if (left > 0) left--;
				else right++;
			}
		}
		if (left == 0 && right == 0) continue;
		if (left == 0) right_cnt += right;
		else if (right == 0) left_cnt += left;
		else if (left >= right) positive.push_back({right, left});
		else negative.push_back({left, right});
	}
	sort(positive.begin(), positive.end());
	sort(negative.begin(), negative.end(), greater<pair<int, int>>());
	for (int i = 0; i < positive.size(); i++)
	{
		left_cnt -= positive[i].first;
		if (left_cnt < 0)
		{
			cout << "No" << endl;
			return (0);
		}
		left_cnt += positive[i].second;
	}
	for (int i = 0; i < negative.size(); i++)
	{
		left_cnt -= negative[i].second;
		if (left_cnt < 0)
		{
			cout << "No" << endl;
			return (0);
		}
		left_cnt += negative[i].first;
	}
	if (left_cnt != right_cnt) cout << "No" << endl;
	else cout << "Yes" << endl;
	return (0);
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;
int sum;

int main()
{
    _FastIO;
    cin >> s;
    int n = s.size();
    for(int i = 0; i < n; i++){
        int k = int(s[i]) - 48;
        if((i % 2) == k)
            sum++;
    }
    int ans = min(sum , (n - sum));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var ND = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = ND[0];
            var D = ND[1];
            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                var XY = Console.ReadLine().Split().Select(double.Parse).ToArray();
                var dis = Math.Sqrt(Math.Pow(XY[0],2) + Math.Pow(XY[1],2));
                if (dis <= D)
                {
                    ret++;
                }
            }

            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 41308
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  ll A, B, M;
  cin >> A >> B >> M;
  ll a[100010], b[100010];
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  ll Min = LINF;
  rep(i, M)
  {
    ll x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    Min = min(Min, a[x] + b[y] - c);
  }
  sort(a, a + A);
  sort(b, b + B);
  Min = min(Min, a[0] + b[0]);
  cout << Min << "\n";
  return 0;
}

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

using namespace std;

int n, m;
vector<int> G[100001], dp(100001), deg_in(100001);

void DFS(int v){
    for(int to : G[v]){
        dp[to] = max(dp[to], dp[v] + 1);
        deg_in[to]--;
        if(deg_in[to] == 0) {
            DFS(to);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int u, v, i=1;i<=m;i++){
        cin >> u >> v;
        G[u].push_back(v);
        deg_in[v]++;
    }
    for(int i=1;i<=n;i++){
        G[0].push_back(i);
        deg_in[i]++;
    }


    DFS(0);

    int ans = 0;
    for(int i=1;i<=n;i++){
        ans = max(ans, dp[i]);
    }
    cout << --ans;
    return 0;
}

Measured memory_bytes: 8056
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct student{
	int idx;
	int a;
};
bool cmp(const student &s1, const student &s2){
	return s1.a < s2.a;
}
int main(){
	int n; cin >> n;
	vector<student> s(n);
	for(int i=0; i<n; i++){
		s[i].idx = i+1;
		cin >> s[i].a;
	}
	sort(s.begin(), s.end(), cmp);
	for(int i=0; i < n; i++) cout << s[i].idx << " ";
	cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	long long n, x, a[100005], ans = 0;

	cin >> n >> x >> a[0];
	for (int i = 1; i < n; ++i) {
		cin >> a[i];
		int d = a[i] + a[i - 1] - x;
		if (d > 0) {
			a[i] = max(a[i] - d, 0ll);
			ans += d;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
N=int(input())
l=list()
W=input()
l.append(W)
w=list(W)
X=w[-1]
for i in range(N-1):
  Y=input()
  l.append(Y)
  y=list(Y)
  if X!=y[0]:
    print('No')
    exit()
  else:
    X=y[-1]
    
if len(l)!=len(set(l)):
  print('No')
  exit()
  
print('Yes')

Measured memory_bytes: 3064
# region header
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
import copy
# @lru_cache(maxsize=None)
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
# endregion
# region input function


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


# endregion

n = inp()
a = inpl()
b = inpl()
a_digest = collections.defaultdict(int)
b_digest = collections.defaultdict(int)
for i in range(n):
    a_digest[a[i]] += 1
    b_digest[b[i]] += 1
for i in range(1, n + 1):
    if a_digest[i] > n - b_digest[i]:
        print("No")
        exit()
print("Yes")
b.sort(reverse=True)
ptr = 0
for i in range(n):
    if a[i] == b[i]:
        while a[i] == b[ptr] or a[ptr] == b[i]:
            ptr += 1
            if ptr == n:
                ptr = 0
        b[ptr], b[i] = b[i], b[ptr]
print(*b)


Measured memory_bytes: 171116
import java.util.*;class Main{public static void main(String[]g){Scanner S=new Scanner(System.in);Stack<Long> s=new Stack<Long>();Long t;for(s.push(S.nextLong());S.hasNext();){t=S.nextLong();if(t>0)s.push(t);else System.out.println(s.pop());}}}


Measured memory_bytes: 26232
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**9)

from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]

memo = [[0] * w for _ in range(h)]

dir = [(0, 1), (0, -1), (1, 0), (-1, 0)]

def dfs(i, j, color):
    if not (0 <= i <= h-1 and 0 <= j <= w-1):
        return 0, 0
    if memo[i][j] == 1:
        return 0, 0
    if s[i][j] == color:
        return 0, 0
    memo[i][j] = 1
    white, black = 0, 0
    if s[i][j] == ".":
        white += 1
    else:
        black += 1
    for dx, dy in dir:
        cur_w, cur_b = dfs(i + dx, j + dy, s[i][j])
        white += cur_w
        black += cur_b
    return white, black

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            white, black = dfs(i, j, "#")
        else:
            white, black = dfs(i, j, ".")

        ans += white * black

print(ans)



Measured memory_bytes: 154788
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#ifdef LOCAL_ENV
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#else
const bool test = false;
#define dump(x) 
#endif
 
#else
const bool test = false;
#define dump(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
void solve();
 
class Solver {
public:
  int N;

  int f(int X) {
    string s = to_string(X);
    int cnt = 0;
    for (auto c : s) {
      cnt += c - '0';
    }
    return cnt;
  }
 
  void solve() {
    cin >> N;
    cout << (N % f(N) == 0 ? "Yes" : "No") << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


Measured memory_bytes: 256
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
	#define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
	#define debug(x...)
	#define light_debug(x) 
#endif


using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;



signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif

	int N;
	cin >> N;
	ll ans = 0;
	rep1(i, N){
		int k = N / i;
		ans += (ll)k * (k + 1) / 2  * i;
	}

	cout << ans << '\n';
	

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}


Measured memory_bytes: 3620
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	ans = -1
	for i in range(1,n+1):
		s = sum(a[:i]+b[i-1:])
		if(s > ans):
			ans = s
	print(ans)

main()

Measured memory_bytes: 68588
using System;

namespace _8_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string now = Console.ReadLine();
                if (now == "0")
                {
                    break;
                }
                int output = 0;
                for (int i = 0; i < now.Length; i++)
                {
                    int x = now[i] - '0';
                    output += x;
                }
                Console.WriteLine(output);
            }
            Console.ReadLine();
        }
    }
}

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

int main() {
	map<ll,ll> m;
	ll n,k;cin>>n>>k;
	ll a[n+1];
	vector<int> d;
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    a[i]--;
	}
	int start=0;
	int l,h;
	d.pb(0);
	m[0]=0;
	for(int i=0;i<=n;i++)
	{
	    d.pb(a[start]);
	    if(m.count(d.back())>0)
	    {
	        l=m[d.back()];
	        h=d.size()-1;
	        break;
	    }
	    else
	        m[d.back()]=d.size()-1;
	    start=a[start];
	}
	if(h>k)
	    cout<<d[k]+1;
	 else
	    {
	        int loop=h-l;
	        k-=l;
	        k%=loop;
	        cout<<d[k+l]+1;
	    }
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

    cout << a[0] << b[0] << c[0] << endl;
    
    return 0;
}

Measured memory_bytes: 256
s=input()
t=input()
ans = 10**9
for i in range(len(s)):
    # print('---',i)
    val = 0
    for j in range(len(t)):
        if i+j >= len(s):
            break
        si = s[i+j]
        ti = t[j]
        # print(si,ti)
        if si != ti:  val += 1
    else:
        ans = min(ans,val)

print(ans)

Measured memory_bytes: 67576
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
sumdigits(n) = sum(digits(n))

function main()
    n=parseInt(readline())
    println(ifelse(n%sumdigits(n)==0,"Yes","No"))
end
main()

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

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e6 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<int, int> mp;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n, m, win = 0, pen = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x; string verd;
        cin >> x >> verd;
        if (mp[x] == -1) {
            continue;
        } else if (verd == "WA") {
            mp[x]++;
        } else {
            pen += mp[x];
            mp[x] = -1;
            win++;
        }
    }
    cout << win << " " << pen << endl;
    return 0;
}


Measured memory_bytes: 4992
/*input
Rainy
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    char c;
    cin >> c;
    if (c =='S') cout << "Cloudy" << endl;
    if (c =='C') cout << "Rainy" << endl;
    if (c =='R') cout << "Sunny" << endl;
}

Measured memory_bytes: 256
s = gets.chomp.chars
t = ("gp" * (s.size/2)).chars
t.push("g") if s.size != t.size

ans = s.each_with_index.inject(0) do |sum, (i, idx)|
  sum + if i == "g" && t[idx] == "g"
    0
  elsif i == "g" && t[idx] == "p"
    1
  elsif  i == "p" && t[idx] == "p"
    0
  else
    -1
  end
end

puts ans

Measured memory_bytes: 16252
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};
// other libs
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}

class dijkstra {
  private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};
template<typename T>
class Union_Find {
  private:
    vector<T> t, s;

  public:
    Union_Find(T max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(T x, T y) {
        if (same(x, y))
            return;
        T tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    T Find(T n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(T x, T y) {
        return Find(x) == Find(y);
    }

    T get_Size(size_t a) {
        return s[a];
    }
};
bool ifPrime(int n){
    if(n==1)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main(signed argc, char* argv[]) {
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    int ans=0;
    rep(i,n){
        ans+=b[a[i]-1];
        if(i&&a[i]-1==a[i-1])ans+=c[a[i-1]-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifndef YK_INCLUDE
#include <bits/stdc++.h>
#endif //! YK_INCLUDE
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

    int H, W, h, w;
    std::cin >> H >> W >> h >> w;
    std::cout << (H-h)*(W-w) << std::endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector v(n);rep(i,n) cin>>v[i];
  for(ll i=0;i+2<n;++i) {
    ll a=v[i];
    for(ll j=i+1;j+1<n;++j) {
      ll b=v[j];
      for(ll k=j+1;k<n;++k) {
        ll c=v[k];
        if(a==b||b==c||c==a) continue;
        if(a+b>c&&b+c>a&&c+a>b) ans++;
      }
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 3680
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        k: usize,
        s: i32,
    }
    let mut ans = 0;
    for i in 0..k+1{
        for j in 0..k+1{
            let xy = (i+j) as i32;
            if xy<=s && s-xy<=k as i32{
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = input()
s_len = len(s)
check = s[0]
if s_len == 2 and s[0] != s[1]:
    print(2)
    exit()
s = s+"1"
ind = 0
ans = 1
for i in range(1,s_len):
    if check == s[ind+1]:
       check = s[ind+1:ind+3]
       ind += 1
    else:
       check = s[ind+1]
    ind += 1
    ans += 1
    if ind >= s_len-1:
        break
if ind == s_len and s[s_len-1] == s[s_len-2]:
    ans -= 1
print(ans)

Measured memory_bytes: 3500
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::{BinaryHeap, VecDeque};

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let k: usize = read();
    let v: Vec<isize> = (0..n).map(|_| read()).collect();
    let mut ans: isize = 0;
    for a in 0..min(n + 1, k + 1){
        for b in 0..min(n - a + 1, k - a + 1){
            let mut sum: isize = 0;
            let mut e = vec![];
            for l in 0..a{
                sum += v[l];
                e.push(v[l]);
            }
            for r in n-b..n{
                sum += v[r];
                e.push(v[r]);
            }
            let c = min(e.len(), k - a - b);
            if c > 0{
                e.sort_by(|x, y| x.cmp(y).reverse());
                for _ in 0..c{
                    let x = e.pop().unwrap();
                    if x > 0{
                        break;
                    }
                    sum -= x;
                }
            }
            ans = max(ans, sum);
        }
    }
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s;
        s = scan.nextLine();
        String t = "";
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) <= 'Z' && s.charAt(i) >= 'A'){
                t += (char)(s.charAt(i) -'A' + 'a');
            }
            else if(s.charAt(i) <= 'z' && s.charAt(i) >= 'a'){
                t += (char)(s.charAt(i) + 'A' - 'a');
            }
            else t += s.charAt(i);
        }
        System.out.println(t);
    }
}



Measured memory_bytes: 31200
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
Scanner scan = new Scanner (System.in);

try{
int a=scan.nextInt();
int b=scan.nextInt();

if(a==b) System.out.println("a == b");
if(a>b) System.out.println("a > b");
if(a<b) System.out.println("a < b");

scan.close();
}catch(NumberFormatException e){
    System.out.println(e);
}




    }
    
}


Measured memory_bytes: 26336
x = gets.to_i
num = gets.chomp.split(" ").map(&:to_i)
a = 1000000000000000000

num.each do |e|
  if e == 0
    puts 0
    exit
  end
end
  
i = 1
cal = num[0].to_i
(x-1).times do
  if cal > a
    puts -1
    exit
  else
    cal *= num[i]
    i += 1
  end
end

if cal > a
  puts -1
  exit
end

puts cal



Measured memory_bytes: 23440
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

ll N,M;
ll dp[SIZE];
bool check[SIZE];

int main(){

	scanf("%lld %lld",&N,&M);
	for(int i = 1; i <= N; i++){

		check[i] = true;
	}

	int tmp;
	for(int i = 0; i < M; i++){

		scanf("%d",&tmp);
		check[tmp] = false;
	}

	dp[0] = 1;
	for(int i = 1; i <= N; i++){

		dp[i] = 0;
	}

	for(int i = 0; i <= N-1; i++){
		if(check[i+1]){

			dp[i+1] += dp[i];
			dp[i+1] %= MOD;
		}
		if(i+2 <= N && check[i+2]){
			dp[i+2] += dp[i];
			dp[i+2] %= MOD;
		}
	}

	printf("%lld\n",dp[N]);

	return 0;
}


Measured memory_bytes: 1152
while True:
    N = int(input())
    if N < 1 or N >100:
        continue
    b = input().split()
    a = [i for i in b]
    if 'P' and 'W' and 'G' and 'Y' in a :
        print('Four')
        break
    else:
        print('Three')
        break

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

namespace CSharp
{
    class Program
    {
        static readonly int mod = 1000000007;

        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = input[0];
            var M = input[1];

            var a = new int[M];
            for (var i = 0; i < M; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }

            var dp = new int[N + 1];
            dp[0] = 1;
            var index = 0;
            for (var i = 1; i <= N; i++)
            {
                if (index < M && a[index] == i)
                {
                    dp[i] = 0;
                    index++;
                }
                else
                {
                    dp[i] = (dp[i - 1] + (i != 1 ? dp[i - 2] : 0)) % mod;
                }
            }
            Console.WriteLine(dp[N]);
        }
    }
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main(){
    int n;
    cin >> n;
    ll x[n], y[n], odd_count;
    bool flag = true;
    rep(n){
        cin >> x[i] >> y[i];
        if(!i){
            odd_count = (abs(x[0])+abs(y[0])) % 2;
            continue;
        }
        if((abs(x[i])+abs(y[i])) % 2 != odd_count){
            flag = false;
        }
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }

    const int M = 32;
    int m = M+1-(odd_count%2);
    ll d[m];
    cout << m << endl;
    ll dd = (1LL << (M-1));
    rep(m-1){
        cout << dd << " ";
        d[i] = dd;
        dd >>= 1;
    }
    cout << 1 << endl;
    d[m-1] = 1;

    rep(n){
        ll dest_u = x[i]-y[i], dest_v = x[i]+y[i], u = 0, v = 0;

        repp(j, m){
            if(dest_u > u){
                u += d[j];
                if(dest_v > v){
                    v += d[j];
                    putchar('R');
                }else{
                    v -= d[j];
                    putchar('D');
                }
            }else{
                u -= d[j];
                if(dest_v > v){
                    v += d[j];
                    putchar('U');
                }else{
                    v -= d[j];
                    putchar('L');
                }
            }
        }
        putchar('\n');
    }
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define w(t) int t;cin>>t;while(t--)



int main(){
	
		fast
		string s,t;
		cin>>s>>t;
		for(int i=0;i<s.length();i++)
		{
			if(s[i]!=t[i])
			{
				cout<<"No";
				return 0;
			}
		}
		cout<<"Yes";


	return 0;
}





Measured memory_bytes: 3648
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

dp = [1000000000000] * N
dp[0] = 0
for i, h in enumerate(A):
    for j in (range(1,3)):
        if i+j < len(A):
            dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i+j]))
        #print(dp)

print(dp[-1])


Measured memory_bytes: 52336
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N;
string S;
int cnt[26][2];

int main() {
	cin >> N >> S;
	
	int ans = 0;
	REP(i, S.size() + 1) {
		
		memset(cnt, 0, sizeof(cnt));
		REP(j, i) cnt[S[j]-'a'][0]++;
		FOR(j, i, S.size()) cnt[S[j]-'a'][1]++;
		
		int cur = 0;
		REP(j, 26) if (cnt[j][0] && cnt[j][1]) cur++;
		chmax(ans, cur);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

vector<LL> ans;

LL calc(LL x,LL y,LL z){
	return x*x + y*y + z*z + x*y + y*z + z*x;
}

void solve(){
	//数iの出現回数をnum[i]とおく
	ans = vector<LL>(10001,0);
	for(int x=1;x<=100;x++){
		for(int y=1;y<=100;y++){
			for(int z=1;z<=100;z++){
				LL result = calc(x,y,z);
				if(result <= 10000) ans[result]++;
			}
		}
	}
}

int main(){
    cin >> N;

    solve();

    for(int i=1;i<=N;i++)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3244
#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.at(i);
    }

    int count = 1;
    sort (S.begin(), S.end());
    for (int i = 1; i < N; i++) {
        if (S.at(i-1) != S.at(i)) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 9600
a,b = map(int,input().split())
c = b - a
if c == 0:
    print(1)
elif b == 1:
    print(0)
else:
    if c%(a-1) == 0:
        d = c // (a-1) + 1
    else:
        d = c // (a-1) + 2
    print(d)


Measured memory_bytes: 2940
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    bc = list(map(int, input().split()))
    BC.append(bc)

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

# print(A)
# print(BC)

bc_i = 0
cnt = 0
r = 0
for ai in A:
    if bc_i > M - 1:
        r += ai
    else:
        bc = BC[bc_i]
        b, c = bc[0], bc[1]

        if ai < c:
            r += c
            cnt += 1
        else:
            r += ai

        if cnt == b:
            bc_i += 1
            cnt = 0

print(r)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n){
		if(i % 2 == 0 && a[i] % 2 == 1){
			ans++;
		}
	}
	cout << ans << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
using namespace std;
 
#define IL inline
#define RE register
#define DB double
#define RT return
#define LL long long
#define INF 1e9+10
#define MAXN 200010
#define FOR(i,a,b) for(RE LL i=(a); i<=(b); i++)
#define FOR2(i,a,b) for(RE LL i=(a); i>=(b); i--)
#define reset(a) memset(a,0,sizeof(a))
#define reset2(a) memset(a,127,sizeof(a)) 
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pq priority_queue
#define P pair<LL,LL>
 
IL LL read()
{
	RE LL 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*10+(c-'0');c=getchar();}
	RT x*f;
} 

LL n,a[MAXN],s[MAXN],tree[MAXN*4],b[MAXN];

IL LL query(RE LL x)
{
	RE LL ans=0;
	while(x)
	{
		ans+=tree[x];
		x-=x&-x;
	}
	RT ans;
}

IL void update(RE LL x)
{
	while(x<=3*n)
	{
		tree[x]++;
		x+=x&-x; 
	}
}

IL LL js(RE LL x)
{
	reset(tree);
	s[0]=0;
	RE LL minn=2*n;
	FOR(i,1,n)
	{
		if(a[i]>=x) s[i]=s[i-1]+1;
		else s[i]=s[i-1]-1;
		minn=min(minn,s[i]); 
	}
	minn=-minn;
	minn++;
	RE LL ans=0;
	FOR(i,1,n)
	{
		ans+=query(s[i]+minn);
		update(s[i]+minn);
		if(s[i]>=0) ans++;
	}
	RT ans;
}

IL bool pd(RE LL x)
{
	RE LL num=js(x);
	if(num>=n*(n+1)/2-num) RT 1;
	RT 0;	
} 

int main()
{
	n=read();
	FOR(i,1,n)
	{
		a[i]=read();
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	RE LL i=1,j=n+1;
	while(i<j)
	{
		RE LL mid=(i+j)>>1ll;
		if(pd(b[mid])) i=mid+1;
		else j=mid; 
	}
	cout<<b[i-1];
	RT 0;
}

Measured memory_bytes: 9728
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

std::string S;

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

  std::string T = S;

  bool fl = true;

  std::reverse(all(T));

  fl &= S == T;

  ll N = S.size();

  std::string s1 = S.substr( 0, (N-1)/2 ), s2( (N+3)/2, (N-1)/2 );
  std::string t1 = s1, t2 = s2;

  std::reverse( all(t1) );
  std::reverse( all(t2) );

  fl &= s1 == t1;
  fl &= s2 == t2;

  puts( fl ? "Yes" : "No" );

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int K; cin >>K;
  ll res = 0;
  for (int i=1; i<=K; i++){
    for (int j=1; j<=K; j++){
      for (int k=1; k<=K; k++){
        res += gcd(gcd(i, j), k);
      }
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 3632
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int h,w;
char ch[60][60];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool outside(int y,int x){
	if(x<0||x>=w)return true;
	if(y<0||y>=h)return true;
	return false;
}

void paint(int y,int x,int color){
	if(ch[y][x]=='.')ch[y][x]=(color)?'w':'b';
	else if((ch[y][x]=='w'&&!color)||(ch[y][x]=='b'&&color))ch[y][x]='?';
	rep(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		if(outside(ny,nx))continue;
		if(ch[ny][nx]=='W'||ch[ny][nx]=='B')continue;
		if(ch[ny][nx]=='w'&&color)continue;
		if(ch[ny][nx]=='b'&&!color)continue;
		if(ch[ny][nx]=='?')continue;
		paint(ny,nx,color);
	}
}

int main(){
	while(cin>>w>>h,w||h){
		rep(i,h)rep(j,w)cin>>ch[i][j];
		rep(i,h)rep(j,w){
			if(ch[i][j]=='W')paint(i,j,1);
			else if(ch[i][j]=='B')paint(i,j,0);
		}
		int nb=0,nw=0;
		rep(i,h){
			rep(j,w){
				if(ch[i][j]=='w')nw++;
				if(ch[i][j]=='b')nb++;
			}
		}
		cout<<nb<<" "<<nw<<endl;
	}
	return 0;
}


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

const long long inf = 1e18 + 13;
const int hell = 1e9 + 7;

signed main () {
	int n;
	cin >> n;
	vector < int > a(n + 1, 0);
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	long long dp[(n >> 1) + (n & 1) + 1][2][2];
	for (int i = 0; i <= (n >> 1) + (n & 1); ++i) {
		for (int j = 0; j <= 1; ++j) {
			for (int w = 0; w <= 1; ++w) 
				dp[i][j][w] = -inf;
		}
	}
	dp[1][0][0] = a[1], dp[1][1][0] = a[2], dp[1][0][1] = 0LL;
	for (int i = 2; i <= (n >> 1); ++i) {
		int x = a[2 * i - 1], y = a[2 * i];
		dp[i][0][0] = dp[i - 1][0][0] + x;
		dp[i][0][1] = max(max(dp[i - 1][0][0], dp[i - 1][1][0]), dp[i - 1][0][1] + x);
		dp[i][1][0] = max(dp[i - 1][0][0], dp[i - 1][1][0]) + y;
		dp[i][1][1] = max(dp[i - 1][1][1], dp[i - 1][0][1]) + y;
	}
	if ((n & 1) && (n > 2)) {
		dp[(n >> 1) + (n & 1)][0][1] = max(max(dp[(n >> 1)][0][0], dp[(n >> 1)][1][0]), dp[(n >> 1)][0][1] + a.back());
		cout << dp[(n >> 1) + (n & 1)][0][1] << '\n';
	}
	else 
		cout << max(dp[(n >> 1)][0][0], dp[(n >> 1)][1][0]) << '\n';
}


Measured memory_bytes: 7220
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

int mcxi2int(const string &s){
	string t = " " + s;
	int x = 0;
	for(int i = 1; i < t.size(); ++i){
		if(t[i] == 'm'){
			x += 1000 * (isdigit(t[i - 1]) ? (t[i - 1] - '0') : 1);
		}else if(t[i] == 'c'){
			x += 100 * (isdigit(t[i - 1]) ? (t[i - 1] - '0') : 1);
		}else if(t[i] == 'x'){
			x += 10 * (isdigit(t[i - 1]) ? (t[i - 1] - '0') : 1);
		}else if(t[i] == 'i'){
			x += 1 * (isdigit(t[i - 1]) ? (t[i - 1] - '0') : 1);
		}
	}
	return x;
}
string int2mcxi(int x){
	const char *TABLE = "ixcm";
	string s;
	for(int i = 0; i < 4; ++i){
		if(x % 10 > 0){
			s += TABLE[i];
			if(x % 10 > 1){ s += ('0' + x % 10); }
		}
		x /= 10;
	}
	reverse(s.begin(), s.end());
	return s;
}

int main(){
	int n;
	cin >> n;
	while(n--){
		string a, b;
		cin >> a >> b;
		cout << int2mcxi(mcxi2int(a) + mcxi2int(b)) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))

using namespace std;

int popcount(int X){
	int ans=0;
	while( X!=0 ){
		int cnt=0;
		int x = X;
		while( x!=0 ){
			if( x&1 ) cnt++;
			x = x>>1;
		}
		X %= cnt;
		ans++;
	}
	return ans;
}

int main(){
	int N;
	cin >> N;
	char x[N];
	cin >> x;
	
	int Pc=0;	// X��popcount
	rep(i,0,N){
		if( x[i]=='1' ) Pc++;
	}
	int pcmod[N],PCmod[N];	// Pc-1,Pc+1 mod
	pcmod[0]=PCmod[0]=1;
	if( Pc==0 || Pc==1 ) pcmod[0]=0;
	rep(i,1,N){
		if( Pc!=1 ) pcmod[i] = (pcmod[i-1]*2)%(Pc-1);
		PCmod[i] = (PCmod[i-1]*2)%(Pc+1);
	}
	int Xpc=0,XPC=0;	// X mod Pc-1,Pc,Pc+1;
	if( Pc!=1 ){
		rep(i,0,N){
			if( x[i]=='1' ){
				Xpc = (Xpc+pcmod[N-1-i])%(Pc-1);
			}
		}
	}
	rep(i,0,N){
		if( x[i]=='1' ){
			XPC = (XPC+PCmod[N-1-i])%(Pc+1);
		}
	}
	
	rep(i,0,N){
		int X_ipc;
		int cnt=0;
		if( x[i]=='0' ){	// popcount��1������
			X_ipc = (XPC+PCmod[N-1-i])%(Pc+1);
			cnt++;
		}else if(Pc!=1){	// popcount��1����
			X_ipc = (Xpc+Pc-1-pcmod[N-1-i])%(Pc-1);
			cnt++;
		}else{	// Pc==1 �����]���������̂�1 �܂�X_i��0
			X_ipc = 0;
		}
		cnt += popcount(X_ipc);	// X_ipc<2*10^5 �Ȃ̂ŏ\���Z�����ԂŎ��s�\?
		cout << cnt << endl;
	}
			
	
	return 0;
}


Measured memory_bytes: 5324
#include<iostream>
#include<cstring>
#define N 1010003
using namespace std;
char data[N][13];
int changenum(char c) {
  if (c == 'A') return 1;
  if (c == 'C') return 2;
  if (c == 'G') return 3;
  return 4;
}
void insert(char *str) {
  int x = 1,sum=0;
  for (int i = 0; str[i] != '\0'; ++i,x*=5) {
    sum += changenum(str[i])*x;
  }
  int hash1 = sum % N, hash2 = sum % (N - 2) + 1,hash;
  for (int i = 0;; ++i) {
    hash = (hash1 + hash2 * i)%N;
    if (strcmp(data[hash], str) == 0||data[hash][0]=='\0') break;
  }
  strcpy(data[hash], str);
}
int find(char *str) {
  int x = 1, sum = 0;
  for (int i = 0; str[i] != '\0'; ++i, x *= 5) {
    sum += changenum(str[i])*x;
  }
  int hash1 = sum % N, hash2 = sum % (N - 2) + 1,hash;
  for(int i=0;;++i){
    hash = (hash1 + hash2 * i)%N;
    if (strcmp(data[hash], str) == 0) return 1;
    if (data[hash][0] == '\0') return 0;
  }
}
int main() {
  char com[7], str[13];
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> com >> str;
    if (com[0] == 'i') insert(str);
    else {
      if (find(str)) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 15908