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

using pint=pair<int,int>;
int n;
vector<vector<pint>> v;

bool judge(int bit){
    for(int i=0;i<n;i++){
        if(!(bit&(1<<i))) continue;
        for(pint xy:v[i]){
            int x=xy.first;
            int y=xy.second;
            if(y==1 && !(bit&(1<<x))) return false;
            if(y==0 && (bit&(1<<x))) return false;
        }
    }
    return true;
}

int main(){
    cin >> n;
    v.resize(n);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        v[i].resize(a);
        for(int j=0;j<a;j++){
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }

    int res=0;
    for(int bit=0;bit<(1<<n);++bit){
        if(judge(bit)){
            int count=0;
            for(int i=0;i<n;i++){
                if(bit&(1<<i)) count++;
            }
            res=max(res,count);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	const string ok = "Yes", ng = "No";
	int N; cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];
	vector<int> b = a;
	sort(all(b));
	b.erase(unique(all(b)), b.end());

	bool flg;
	if(b.size() > 2) {
		flg = false;
	}
	else if(b.size() == 1) {
		if((b[0] == N-1) || (b[0]*2 <= N))
			flg = true;
		else
			flg = false;
	}
	else {
		int A, B;
		A = B = 0;
		rep(i,N) {
			if(a[i] == b[0]) A++;
		}
		B = b[0]-A+1;

		if(A > 0 && B > 0 && A+B == b[1] && N-A >= B*2) {
			flg = true;
		}
		else {
			flg = false;
		}
	}

	if(flg)
		cout << ok << endl;
	else
		cout << ng << endl;
	return 0;
}


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

int N,tmp,even=0,odd=0;

int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		cin>>tmp;
		(tmp%2==0 ? even++ : odd++);
	}
	if(odd%2==1){
		if(odd==1&&even==0){
			cout<<"YES"<<'\n';
		}else{
			cout<<"NO"<<'\n';
		}
	}else{
		cout<<"YES"<<'\n';
	}
}

Measured memory_bytes: 3552
n, q = map(int, input().split())
S = input()

Sev = [0] * n
for i in range(n-1):
  if S[i] == "A" and S[i+1] == "C":
    Sev[i] = 1

Simos = [0] * n
Simos[0] = Sev[0]
for i in range(1, n):
  Simos[i] = Simos[i-1] + Sev[i]
    
for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  r = r-1
  if l == 0:
    print(Simos[r])
  else:
    print(Simos[r] - Simos[l-1])

Measured memory_bytes: 52940
#include <algorithm>
#include <iostream>
#include <string>
#include <array>

using namespace std;
const int MAX=32;

array<int, MAX> StrToRL(string s){
    array<int,MAX> num={};
    char l[15]={'q','w','e','r','t','a','s','d','f','g',
                    'z','x','c','v','b'};
    //char r[11]={'y','u','i','o','p','h','j','k','l','n','m'};
    for(int i=0;i<s.size();i++){
        bool lflag=true;
        for(int j=0;j<15;j++){
            if(s[i]==l[j]){
                lflag=false;
                num[i]=1;
            }
            if(lflag){num[i]=-1;}
        }
    }

    return num;
}

int GetChange(array<int, MAX> n){
    int cnt=0;
    for(int i=0;i<MAX-1;i++){
        if(n[i]*n[i+1]==-1){cnt++;}
    }
    return cnt;
}

int main(){
    string s;
    while (cin >> s && !(s=="#")){
        cout<<GetChange(StrToRL(s))<<endl;
    }
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;string s;cin >> n >> s;int left_count = 0,ans = 0;
	for (int i = 0; i < n; i++) {
		char x = s[i];
		if (x == '(')left_count++;
		else {
			if (left_count >= 1)left_count--;
			else ans++;
		}
	}
	for (int i = 0; i < ans; i++)cout << "(";
	cout << s;
	for (int i = 0; i < left_count; i++)cout << ")";
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll n;

void solve(){
    cin >> n;
    if (n%2==1){
        cout << 0 << endl;
    }
    else {
        ll ans=0;
        n/=2;
        for(ll i=5;i<=1000000000000000000;i*=5){
            ans+=n/i;
        }
        cout << ans << endl;
    }
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,cnt=0;
    string s;
    cin>>n>>s;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
from itertools import accumulate

def is_prime(n):
  if n == 1: return False
  for k in range(2, int(math.sqrt(n))+1):
    if n % k == 0: return False
  return True

MAX = (10**5)+1
q = int(input())
A = [1 if is_prime(i)and is_prime((i + 1)//2) else 0 for i in range(MAX) ]
S = [0] + list(accumulate(A))

Q =[]
Q_append = Q.append
for _ in range(q):
    l, r = map(int, input().split())
    Q_append((l, r))

for qi in Q:  
    print(S[qi[1]+1]-S[qi[0]])

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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int N;

void solve() {
    cin >> N;
    vi dp(N);
    map<int, int> mp;
    int mx = 1;
    rep(i,N) {
        int p;
        cin >> p;
        if (!mp.count(p-1)) {
            mp[p] = 1;
        } else {
            mp[p] = mp[p-1] + 1;
            mx = max(mx, mp[p]);
        }
    }
    cout << N - mx << endl;
}

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

Measured memory_bytes: 10680
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = [None]*N
for i in range(N):
    l[i] = list(map(int,input().split()))

l.sort(key=lambda x: x[2])

#ヒントの中で最大のhとその座標
x,y,h = l[-1]

#Cx,Cyの可能性を全通り試す
for i in range(101):
    for j in range(101):
        H = h + abs(i-x) + abs(j-y)
        for k in range(N-1):
            x_1,y_1,h_1 = l[k]
            H2 = max(H - abs(i-x_1) - abs(j-y_1),0)
            if not H2==h_1:
                break
        else:
            print(i,j,H)
            exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;

struct Node {
    LL a,b;
}node[maxn];

bool cmp(Node x,Node y) {
    return x.b>y.b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL n,h,ta=0;
    cin>>n>>h;
    for(int i=1;i<=n;i++) {cin>>node[i].a>>node[i].b;ta=max(ta,node[i].a);}
    sort(node+1,node+1+n,cmp);
    int ans=0,num2=1;
    while(ta<node[num2].b&&num2<=n) {
        h-=node[num2++].b;
        ans++;
        if(h<=0) {cout<<ans;return 0;}
    }
    ans+=h/ta;
    if(h%ta!=0) ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = [0]*(N+1)
cnt = 1

for i in range(1, N+1):
    D[i] = D[i-1] + L[i-1]
    if D[i] <= X:
        cnt += 1

print(cnt)

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().strip().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def ref_slv(N, S):
    ans = 0

    for i in combinations(range(0, 2*N), N):
        l = []
        r = []
        for j in range(2*N):
            if j in i:
                l.append(S[j])
            else:
                r.append(S[j])

        if ''.join(l) == ''.join(reversed(r)):
            ans += 1

    return ans


@mt
def slv(N, S):
    ans = 0

    l = S[:N]
    r = S[N:][::-1]
    ld = defaultdict(lambda: 0)
    rd = defaultdict(lambda: 0)

    for i in range(N+1):
        for j in combinations(range(N), i):
            lb = []
            lr = []
            rb = []
            rr = []
            for k in range(N):
                if k in j:
                    lb.append(l[k])
                    rr.append(r[k])
                else:
                    lr.append(l[k])
                    rb.append(r[k])
            ld[(''.join(lr), ''.join(lb))] += 1
            rd[(''.join(rr), ''.join(rb))] += 1
    for k, v in ld.items():
        if k in rd:
            ans += v * rd[k]

    return ans


def main():
    # for i in range(1, 19):
    #     print(i, slv(i, ""))
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 181600
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int main(){ _

	pii S,F;
	cin >> S.f >> S.s;
	cin >> F.f >> F.s;

	string go = "", r_go;

	if(S > F) swap(S,F);

	int dx = F.f - S.f;
	int dy = F.s - S.s;

	while(dy--) go += 'U';
	while(dx--) go += 'R';

	r_go = go;

	for(auto &x : r_go){
		if(x == 'U') x = 'D';
		if(x == 'R') x = 'L';
	}

	cout << go << r_go;
	cout << "LU" << go << "RDRD" << r_go << "LU" << endl;

	return 0;
}


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

using namespace std;

int N;
double eps = 3e-8;
double x[100005], y[100005], typ[100005]; //0 U, 1 D, 2 R, 3 L

double calc(double val){
    double minix = 1000000000, maxix = -1000000000, miniy = 1000000000, maxiy = -1000000000;
    for(int i = 1; i<=N; i++){
        if(typ[i] == 0){
            minix = min(minix, x[i]);
            maxix = max(maxix, x[i]);
            miniy = min(miniy, y[i] + val);
            maxiy = max(maxiy, y[i] + val);
        }
        else if(typ[i] == 1){
            minix = min(minix, x[i]);
            maxix = max(maxix, x[i]);
            miniy = min(miniy, y[i] - val);
            maxiy = max(maxiy, y[i] - val);
        }
        else if(typ[i] == 2){
            minix = min(minix, x[i] + val);
            maxix = max(maxix, x[i] + val);
            miniy = min(miniy, y[i]);
            maxiy = max(maxiy, y[i]);
        }
        else{
            minix = min(minix, x[i] - val);
            maxix = max(maxix, x[i] - val);
            miniy = min(miniy, y[i]);
            maxiy = max(maxiy, y[i]);
        }
    }
    return (maxix-minix)*(maxiy-miniy);
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    for(int i= 1; i<=N; i++){
        cin >> x[i] >> y[i];
        char c;
        cin >> c;
        if(c == 'D'){
            typ[i] = 1;
        }
        else if(c == 'R'){
            typ[i] = 2;
        }
        else if(c == 'L'){
            typ[i] = 3;
        }
        else{
            typ[i] = 0;
        }
    }
    double l = 0, r = 200000000;
    while(r - l > eps){
        double mid1 = l + (r-l)/3, mid2 = r - (r-l)/3;
        if(calc(mid1) < calc(mid2)){
            r = mid2;
        }
        else{
            l = mid1;
        }
    }
    double ans = min(calc(l), calc(r));
    ans = min(calc((l+r)/2.0), ans);
    ans = min(calc((2*l+r)/3), ans);
    ans = min(calc((2*r+l)/3), ans);
    printf("%.3f\n", ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

vector<ll> v;

int main() {
    int N;
    cin >> N;
    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    for (ll a : v) {
        if ((double)ans * a > 1e18 - 0.1 || ans * a > (ll)1e18) {
            ans = -1;
            break;
        }
        ans *= a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(Math.min(a+b, Math.min(b+c, c+a)));
	}

}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int gcd(int x, int y){
  if(y == 0)return x;
  return gcd(y, x % y);
}


int main(){
  int n,x; cin >> n >> x;
  int t = 0;
  for(int i = 0; i < n; ++i){
    int y; cin >> y; y = abs(y - x);
    if(i)t = gcd(t,y);
    else t = y;
  }
  cout << t << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

int n,x,y;
int s;

int main(){
  cin>>x>>y;
  cout<<(x-1)*(y-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MAXX,MAXY,n,x,y;
struct node
{
    int x,y,z;
    node()
    {
    }
    node(int X,int Y,int Z)
    {
        x=X;y=Y;z=Z;
    }
} lis[200001];
int st[200001];
bool com(node a,node b)
{
    if(a.x==0 && b.x>0) return 1;
    if(b.x==0 && a.x>0) return 0;
    if(a.x==0 && b.x==0) return (a.y<b.y);
    if(a.y==MAXY && b.y<MAXY) return 1;
    if(b.y==MAXY && a.y<MAXY) return 0;
    if(a.y==MAXY && b.y==MAXY) return (a.x<b.x);
    if(a.x==MAXX && b.x<MAXX) return 1;
    if(b.x==MAXX && a.x<MAXX) return 0;
    if(a.x==MAXX && b.x==MAXX) return (a.y>b.y);
    return a.x>b.x;
    return 0;
}
int main()
{
    scanf("%d%d%d",&MAXX,&MAXY,&n);
    int m=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        bool ok=0;
        if(x==0 || x==MAXX || y==0 || y==MAXY)
            lis[++m]=node(x,y,i),ok=1;
        scanf("%d%d",&x,&y);
        if(x==0 || x==MAXX || y==0 || y==MAXY)
        {
            if(ok)
                lis[++m]=node(x,y,i);
        }
        else
        {
            if(ok)
                --m;
        }
    }
    sort(lis+1,lis+m+1,com);
    int top=0;
    for(int i=1;i<=m;i++)
        if(top>0 && st[top]==lis[i].z) top--;
        else
            st[++top]=lis[i].z;
    puts(top?"NO":"YES");
    return 0;
}


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

int main(){
    int n; cin >> n;
    int ans = 0;
    // {6^p}と{9^p}を入れる
    vector<int> p_list;
    p_list.push_back(1);
    int tmp = 6;
    while(n >= tmp) p_list.push_back(tmp), tmp*=6;
    tmp = 9;
    while(n >= tmp) p_list.push_back(tmp), tmp*=9;
    int pl_size = p_list.size();

    // BFS
    int val,cnt;
    vector<bool> isVisited(n+1, false);
    queue<pair<int, int>> q;
    q.push(make_pair(0,0));
    while(!q.empty()){
        // 先頭の処理
        val = q.front().first;
        cnt = q.front().second;
        q.pop();
        if(val == n){ cout << cnt << endl; return 0;} // 終了
        if(isVisited[val]) continue; // 枝刈り
        isVisited[val] = true;
        rep(i,pl_size) if(val + p_list[i] <= n) q.push(make_pair(val + p_list[i], cnt+1));
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N,a,b;
    cin >>N>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    }
    else{
       long long C=min(b-1,N-a);
       long long A=((N-(a+(N-b+1)))/2)+N-b+1;
       long long B=(((b-(a-1+1))-1)/2)+a-1+1;
       long long D=min(A,B);
       cout << min(C,D)<<endl;
    }
}

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

vector<ll> u, v;
int n, m = 1, a[1000];

main()
{
    cin >> n;
    while (1)
    {
        if (n == 4 || n == 2 || n == 1)
        {
            cout << m + 3 << endl;
            return 0;
        }
        else if (n % 2 == 0)
            n /= 2;
        else
            n = 3 * n + 1;
        m++;
    }
}

Measured memory_bytes: 256
N = int(input())
txy = [list(map(int,input().split())) for i in range(N)]
txy.insert(0,[0,0,0])

for i in range(N):
    d = abs(txy[i+1][1] - txy[i][1]) + abs(txy[i+1][2] - txy[i][2])
    td = txy[i+1][0] - txy[i][0]
    if d > td:
        print("No")
        exit()
    if d % 2 == 0 and td % 2 == 1:
        print("No")
        exit()
    elif d % 2 == 1 and td % 2 == 0:
        print("No")
        exit()
print("Yes")


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

typedef long long ll;
const ll MOD = (ll)1e9 + 7;
ll mult(ll x, ll y)
{
    return (x * y) % MOD;
}

bool isPrime(int x)
{
    for (int y = 2; y * y <= x; y++)
        if (x % y == 0)
            return false;
    return x > 1;
}

int main()
{
    int n;
    scanf("%d", &n);
    ll ans = 1;
    for (int x = 2; x <= n; x++)
    {
        if (!isPrime(x)) continue;
        int y = n;
        int z = 0;
        while(y >= x)
        {
            y /= x;
            z += y;
        }
        ans = mult(ans, z + 1);
    }
    printf("%lld\n", ans);

    return 0;
}

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

using namespace std;

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

    string s;

    cin >> s;

    int a = 0, b = 0;

    for(int i=0; i<3; i++){
        if(s[i] == 'A') a++;
        else b++;
    }

    if(a>=1 and b>=1) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
    #include <array>
    #include <bitset>
    #include <chrono>
    #include <complex>
    #include <fstream>
    #include <functional>
    #include <iostream>
    #include <iterator>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <regex>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <unordered_set>
    #include <vector>
     
    using namespace std;
    typedef long long ll;
     
    #define INT_MAX std::numeric_limits<int>().max()
    #define INT_MIN std::numeric_limits<int>().min()
    #define FOR(i,a,b) for (int i=(a);i<(b);i++)
    #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
    #define REP(i,n) for (int i=0;i<(n);i++)
    #define RREP(i,n) for (int i=(n)-1;i>=0;i--)
     
   // #define _DEBUG_ 1
    void run() {
    	int a, b, c;
    	cin >> a >> b >> c;
    	cout << ((a <= c && c <= b) ? "Yes" : "No") << endl;
    }
     
    int main() {
    #ifdef _DEBUG_
    	using std::chrono::system_clock;
    	using std::chrono::duration_cast;
    	system_clock::time_point  start, end;
    	std::ifstream in("input.txt");
    	cin.rdbuf(in.rdbuf());
    	for (int i = 0; i < _DEBUG_; i++) {
    		cout << "-------------------------- (cnt:" << i << ")" << endl;
    		start = system_clock::now();
    		run();
    		end = system_clock::now();
    		int elapsed = duration_cast<std::chrono::milliseconds>(end - start).count();
    		cout << "-------------------------- (time:" << elapsed << "ms)" << endl << endl;
    	}
    #else
    	run();
    #endif
    	return 0;
    }

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (a > 0 && c > 0)
    {
        c -= b;
        a -= d;
    }

    if(c <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;

  inv[1] = 1;
  for(int i = 2; i< MAX;i++){
    fac[i] = fac[i-1] * i %MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n]*(finv[k]*finv[n-k] % MOD)%MOD;
}


int main(){
    int N,K;

    cin >>N>>K;
    COMinit();

    int r = N-K;
    for(int i = 1;i<=K;i++){
      ll ans = COM(r+1,i)*COM(K-1,i-1)%MOD;
      cout <<ans<<endl;
    }
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

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

using namespace std;

int main()
{
    long i,j,n,W;

    cin>>n>>W;
    long dp[n+1][W+1];
    long w[n],v[n];
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }

    for(i=0;i<=n;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }

            if(j >= w[i-1])
            {
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    cout<<dp[n][W];

    return 0;
}


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

int main() {
  char str[1000];
  map<char, int> count_alphabet;

  cin >> str;
  int str_len = strlen(str);
  // count_alphabet['a'] = 100;
  // cout << count_alphabet['a'] << endl;
  for (int i = 0; i < str_len; i++) {
    count_alphabet[ str[i] ]++;
  }

  int count = 0;
  for (auto itr : count_alphabet) {
    if (itr.second % 2 == 1) {
      count++;
    }
  }
  int count_div_2 = count / 2;

  cout << count_div_2 << endl;
}

Measured memory_bytes: 3096
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string a[255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == '0') return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) cin >> a[i];
		int ret = 0;
		for(int i = 0; i < n * n; i++) {
			for(int j = 0; j < 4; j++) {
				ret = max(ret, check(i / n, i % n, j / 3 - 1, j % 3 - 1));
			}
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 3416
#include <stdio.h>
int main(void){
   int H, W,a,b,i;
   i = 1 ;
     
  
  while(1){
      scanf("%d %d",&a ,&b);
       if( a == 0 && b == 0) break;
    for ( H = 0; H < a; H++ ){
      for ( W = 0; W < b; W++ ){
          printf("#");
    }
      printf("\n");
    }
     printf("\n");
     
    
       i++;
}
   
    return 0;
    
     
}







Measured memory_bytes: 2036
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = LongArray(N)
    val X = LongArray(N); val Y = LongArray(N); val Z = LongArray(N)
    repeat(N) { n ->
        val (x, y, z) = listOfLong()
        X[n] = x; Y[n] = y; Z[n] = z
    }
    var ans = 0L
    for (n in 0 until 8) {
        for (m in 0 until N) {
            A[m]  = (if ((n and 0b001) == 0) X[m] else -X[m])
            A[m] += (if ((n and 0b010) == 0) Y[m] else -Y[m])
            A[m] += (if ((n and 0b100) == 0) Z[m] else -Z[m])
        }
        A.sortDescending()
        var w = A.slice(0 until M).sum()
        if (ans < w) ans = w
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextLong() = java.lang.Long.parseLong(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


Measured memory_bytes: 41756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t A,B,K;
  cin >> A >> B >> K;
  if (A>=K) {
    cout << A-K << " " << B << endl;
  } else if (A+B>=K) {
    cout << 0 << " " << A+B-K << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  };
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
const int maxn=10000;
using namespace std;

int main()
//int found; found=chaine.find(cara); if (found!=std::string::npos) how to verify if a caracter exists in a chaine
// toupper(caractere) ==> return the majuscule of a caractere
//floor(x) Returns the largest integer smaller than x
//ceil(x) returns  Returns the smallest integer greater
/* #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
    #endif */
{
     
	ll n,d;
	cin>>n>>d;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		double dis=sqrt(x*x+y*y);
		if(dis<=d)
		{
			cnt++;
		}
	}
	cout<<cnt;
	
}




Measured memory_bytes: 3648
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

$ans=INF
N,K=get_i
M=5
d={}
get_i.each do|i|
    d[i]=1
end

def dfs(now,s,d)
    return if now>M
    if s.to_i>=N
      $ans=s.to_i if $ans>s.to_i
      return
    end
  0.upto(9) do|i|
      if d[i].nil?
        dfs(now+1,s+i.to_s,d)
      end
  end
end
dfs(0,"",d)
puts $ans

Measured memory_bytes: 14344
#include <iostream>
//#include <array>

int main()
{
    long a, b;
    std::cin >> a >> b;
    if (a % b == 0) {
        std::cout << -1 << '\n';
    } else {
        long i = 1;
        while (true) {
            if ((i * a) % b != 0) {
                std::cout << i * a << '\n';
                break;
            } else {
                i++;
            }
        }
    }

    return 0;
}

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

int main()
{
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if ((x - r) >= 0 && (x + r) <= W)
  {
    if ((y - r) >= 0 && (y + r) <= H)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3120
#include <stdio.h>
int math[]={-1,1};
int main()
{
	int a[4];register int i,j,k;
	for(i=0; i<4; ++i)
	{
		char c=getchar();
		a[i]=c-'0';
	}
	for (i=0; i<2; ++i)
		for (j=0; j<2; ++j)
			for (k=0; k<2; ++k)
				if(a[0]+math[i]*a[1]+math[j]*a[2]+math[k]*a[3]==7)
				{
					printf("%d",a[0]);
					printf("%c",i==0?'-':'+');
					printf("%d",a[1]);
					printf("%c",j==0?'-':'+');
					printf("%d",a[2]);
					printf("%c",k==0?'-':'+');
					printf("%d",a[3]);
					printf("=7\n");
					return 0;
				}
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define al(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define IOS ios::sync_with_stdio(0);

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < sz(s); ++i) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;

	ll ans = lcm(a, b);

	dunk(ans);

	return 0;
}

Measured memory_bytes: 256
A, B, C = (int(x) for x in input().split())

count = 0
S = 0
T = 0
U = 0

if(A == B == C) and (A % 2 == 0 and B % 2 == 0 and C % 2 == 0) :
  print("-1")
  
else:
  while(A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
    count+= 1
    S = 1/2 * A
    T = 1/2 * B
    U = 1/2 * C
    A = T + U 
    B = S + T 
    C = S + U 
  print(count)

Measured memory_bytes: 9272
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


immutable long MOD = 1000000007;


auto solve(long N, long K, long[] A) {
    long ans;
    long a_inverse;
    foreach (i; 0 .. cast(size_t) N) foreach (j; i + 1 .. cast(size_t) N) {
        if (A[i] > A[j]) {
            a_inverse++;
            a_inverse %= MOD;
        }
    }
    ans += (K * a_inverse) % MOD;
    ans %= MOD;

    long nth;
    foreach (i, k; A.sort!"a > b"().group) {
        nth += k;
        ans += (((N - nth) * k) % MOD) * ((K * (K - 1) / 2) % MOD) % MOD;
        ans %= MOD;
    }

    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (N-1-0+1));
    foreach (i; 0 .. cast(size_t) (N-1-0+1)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, K, A);
    else
        solve(N, K, A).writeln;
}


Measured memory_bytes: 2428
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<utility>

#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define PII pair<int,int>
#define LL long long
#define L(x) (x<<1)
#define R(x) ((x<<1)+1)
#define lb(x) (x&(-x))
#define maxn 200000

using namespace std;

inline void GetN(LL &num)
{
    char in=getchar();
    while(in<'0'||in>'9') in=getchar();
    num=in-'0';
    while(in=getchar(),in>='0'&&in<='9') num*=10,num+=in-'0';
}

LL n,i,sum,ans,a[maxn];

int main()
{
	GetN(n);
	for(i=1;i<=n;i++) GetN(a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<n;i++)
	{
		sum+=a[i];
		if(a[i+1]>(sum<<1)) ans=i;
	}
	printf("%d\n",n-ans);
	return 0;
}


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

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

	vector<string>V;

	string str;

	ll temp = N;

	while(temp--)
	{
		cin>>str;
		V.pb(str);
	}

	unordered_map<string,ll>mp;

	for(ll i = 0;i<N;i++)
	{
		mp[V[i]]++;
	}

	ll count = 0;

	for(auto x : mp)
		count++;

	cout<<count<<endl;

	return 0;
}

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





int main(){
  int a[3][2][3]={};
  for(int i=0;i<3;i++){
    cin>>a[i][0][0]>>a[i][0][1]>>a[i][0][2]>>a[i][1][0]>>a[i][1][1]>>a[i][1][2];
    a[i][0][2]=a[i][1][2]-a[i][0][2];
    if(a[i][0][2]<0){a[i][0][2]+=60; a[i][1][1]-=1;}
    
     a[i][0][1]=a[i][1][1]-a[i][0][1];
    if(a[i][0][1]<0){a[i][0][1]+=60; a[i][1][0]-=1;}
    
    a[i][0][0]=a[i][1][0]-a[i][0][0];
  }

  for(int i=0;i<3;i++){
    cout<<a[i][0][0]<<" "<<a[i][0][1]<<" "<<a[i][0][2]<<endl;
      }

  
    
  return 0;
}


Measured memory_bytes: 3100
// problem: "https://atcoder.jp/contests/abc145/tasks/abc145_c"

#include<bits/stdc++.h>
#define ll long long
#define Pair pair<ll,ll>

using namespace std;

int main()
{
    ll n,i;

    cin>>n;

    ll x,y;
    vector<Pair>V;

    for(i=0;i!=n;i++)
    {
        cin>>x>>y;
        V.push_back(Pair(x,y));
    }

    ll j;
    double s = 0.0;
    for(i=0;i!=n-1;i++)
    {
        for(j=i+1;j!=n;j++)
        {
            s += sqrt(pow(V[i].first-V[j].first,2) + pow(V[i].second-V[j].second,2));
        }
    }

    cout<<fixed;
    cout<<setprecision(12)<<s * 2.0 / n;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	Alice := "Alice"
	Borys := "Borys"

	n := readInt32()
	a := readInt32()
	b := readInt32()
	if n <= 2 {
		fmt.Println(Borys)
		os.Exit(0)
	}

	if absInt32(a, b)%2 == 0 {
		fmt.Println(Alice)
	} else {
		fmt.Println(Borys)
	}
}

func readInt32() int32 {
	var a int32
	fmt.Scan(&a)
	return a
}

func absInt32(a, b int32) int32 {
	ret := a - b
	if ret >= 0 {
		return ret
	}
	return ret * -1
}


Measured memory_bytes: 512
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int k;
		cin >> k;
		if (k == 0) return;
		int left = k;
		int right = k;
		while (left != 1) {
			int ok = 0;
			for (int q = 2; q * q <= left; ++q) {
				if (left % q == 0) {
					ok = 1;
				}
			}
			if (ok == 0) break;
			left--;
		}
		while (true) {
			int ok = 0;
			for (int q = 2; q * q <= right; ++q) {
				if (right % q == 0) {
					ok = 1;
				}
			}
			if (ok == 0) break;
			right++;
		}
		cout << max(0LL,right - left) << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3144
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n

dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans=1e9;
    for(char i='a';i<='z';i++){
        string m = s;
        int cnt = 0;
        while(1){
            bool flag = 0;
            for(int k=0;k<m.size();k++){
                if(m[0]!=m[k]) flag = 1;
            }
            if(!flag) break;
            string t;
            for(int j=0;j<m.size()-1;j++){
                if(m[j]==i||m[j+1]==i) t += i;
                else t += m[j];
            }
            m = t;
            cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll ans=0;
	for(int i=0; i<n; i++){
		ll a;
		cin >> a;
		ans+=a;
	}
	cout << ans-n << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        String[] str = bf.readLine().split("");
        int num1 = 0,
            num2 = 0;
        for(int i = 0; i < str.length; i++){
            int color = Integer.parseInt(str[i]);
            if(i%2 == color){
                num1++;
            }
            else{
                num2++;
            }
        }
        System.out.println(Math.min(num1, num2));
    }
}

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

int main()
{
    int N;
    scanf("%d", &N);
    int p[N+1];
    for(int i = 1; i <= N; ++i) scanf("%d", &p[i]);

    int cnt = 0;
    for(int i = 1; i <= N; ++i)
        if(p[i] == i) {
            if(i == N) swap(p[i-1], p[i]);
            else swap(p[i], p[i+1]);
            ++cnt;
        }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

vector<int> fac;

int nCr(int n, int r) {
  return ((fac[n] - fac[r] - fac[n - r]) > 0) ? 0 : 1;
}

int f(vector<int> a) {
  for (int i = 0; i < a.size(); i++) a[i] %= 2;
  int m = a.size() - 1;
  int res = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 1) { res += nCr(m, i); }
  }
  return res % 2;
}

void solve() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vector<int> a;
  for (int i = 0; i < N - 1; i++) {
    a.push_back(abs((int)s[i + 1] - (int)s[i]));
  }
  if (N == 2) {
    cout << a[0] << endl;
    return;
  }
  // judge 1
  int res = f(a);
  if (res == 1) {
    cout << 1 << endl;
    return;
  }
  // judge not 2
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 1) {
      cout << 0 << endl;
      return;
    }
  }
  // judge 0 or 2
  for (int i = 0; i < a.size(); i++) { a[i] /= 2; }
  int ret = f(a);
  if (ret == 1) {
    cout << 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return;
}

signed main() {
  fastio();
  fac.resize(1000001);
  fac[0] = 0;
  fac[1] = 0;
  for (int i = 2; i <= 1000000; i++) { fac[i] = __builtin_ctz(i & -i); }
  for (int i = 2; i <= 1000000; i++) fac[i] += fac[i - 1];
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

int main(){
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.length();i++){
    if(s.at(i)=='x'){
      cnt++;
    }
  }
  if(cnt>=8){
    cout<<"NO"<<endl;
  }
  else {
    cout<<"YES"<<endl;
  }
  return 0;
}




Measured memory_bytes: 3608
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o D.exe D.cpp 
Execute: ./D
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 
	/* Prime factorization */ 
	unsigned long long N;
	cin >> N;
	vector<unsigned long long> primes; 
	vector<unsigned long long> exponents; 
	
	// Base cases: check 2 & 3. 
	unsigned long long num_to_check = 2ULL; 
	// cout << "check: " << N << " " << num_to_check << endl; 
	if(N % num_to_check == 0) {
		primes.push_back(num_to_check); 
		exponents.push_back(0); 
		while(N % num_to_check == 0) {
			exponents.back()++; 
			N /= num_to_check; 
		}
	}
	// cout << "check: " << N << " " << num_to_check << endl; 
	
	for(num_to_check = 3; num_to_check*num_to_check <= N; num_to_check+=2ULL) {
		// cout << "check: " << N << " " << num_to_check << endl; 
		if(N % num_to_check == 0) {
			primes.push_back(num_to_check); 
			exponents.push_back(0); 
			while(N % num_to_check == 0) {
				exponents.back()++; 
				N /= num_to_check; 
			}
		}
		if(N == 1ULL)
			break; 
	}
	
	if(N > 1ULL) {
		primes.push_back(N); 
		exponents.push_back(1);
	}
	
	// Traverse the exponents 
	int result = 0; 
	int j; 
	for(int i = 0; i < exponents.size(); i++) {
		j = (int) floor( (-1.0 + sqrt(1.0 + 8.0*((double) exponents.at(i))))/2.0); 
		result += j; 
		// cout << "Prime check: " << primes.at(i) << " " << exponents.at(i) << " " << result << endl; 
	}
	cout << result << endl; 
	
	
	// Print out factorized results 
	/*
	cout << "Output prime factorization" << endl; 
	for(int i = 0; i < primes.size(); i++) {
		cout << primes.at(i) << " " << exponents.at(i) << endl; 
	}
	*/ 
	
	return 0; 
} 


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    string s;
    cin >> s;

    int ans = 0;
    int sta = 0;

    rep(i,0,s.size()){
        if(s[i] == 'S'){
            sta++;
        }else{
            if(sta == 0){
                ans++;
            }else{
                sta--;
            }
        }
    }

    cout << sta + ans << endl;



    return 0;
}


Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
int inf = (1e9) + 7;


int main(){


	string s;
	string ans = "";
	cin >> s;


	for (int i = 0; i < s.size(); ++i)
	{
		if(!(i%2))
			ans += s[i];
	}
	cout << ans << '\n';
}	

Measured memory_bytes: 512
i,n;char a[100002]="SS",s[999999];f(){for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);}main(){scanf("%d%s",&n,&s);strncat(s,s,n);f();*a=87;f();a[1]=87;f();*a=83;f();puts("-1");}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int counter = 0;
        for(int i = 0; i < N - 1; i++){
            if(S.charAt(i) != S.charAt(i + 1)){
                counter++;
                i++;
            }
        }
        System.out.println(counter);
    }
}



Measured memory_bytes: 29632