akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

string S;
int K;

int main() {
  cin >> S >> K;
  vector<string> vec;
  for (int i = 0; i < S.size(); ++i) {
    for (int j = 1; j <= K; ++j) {
      string tmp = S.substr(i, j);
      vec.push_back(tmp);
    }
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec[K-1] << endl;
}

Measured memory_bytes: 1660
import java.util.Scanner;
import java.util.Arrays;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		try {
		    Scanner sc = new Scanner(System.in);
		    int t,n,i,a,b,k,m;
		    n=sc.nextInt();
		    
		        m=k=0;
		        for(i=0;i<n;i++)
		        {
		            a=sc.nextInt();
		            b=sc.nextInt();
		            if(a==b)
		             k++;
		             else
		             {
		          
		                 if(k>m)
		                 m=k;
		                 k=0;
		             }
		        }
		         if(k>m)
		                 m=k;
		        if(m>=3)
		        System.out.println("Yes");
		        else
		       System.out.println("No");
		    }
		 catch(Exception e) {
		}
	}
}


Measured memory_bytes: 36072
W,H,x,y = map(int, input().split())

"""
A=min(W-x,x)*H
B=min(H-y,y)*W

if(A==B):
    print(A,"1")
else:
    print(max(A,B),"0")

"""
ans=W*H/2
if((W/2==x) & (H/2==y)):
    print(ans,"1")
else:
    print(ans,"0")


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

int main()
{
	int n,h,w,i,j,x,y,m,k;
	int a[101][101];
	cin>>h>>w>>n;
	k=-1;
	for (i=1;i<=n;i++)
	{
		cin>>m;
		do
		{
			k++;
			x=(k/h%2?h-1-k%h:k%h);
			y=k/h;
			a[x][y]=i;
			m--;
		}
		while (m>0);
	}
	for (i=0;i<h;i++)
	{
	  for (j=0;j<w-1;j++)
	  cout<<a[i][j]<<' ';
	  cout<<a[i][w-1]<<endl;
    }
	return 0;
 } 

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int n,x[100]={},y[100]={};
    double max=0.0,a,b=0.0,c=0.0,d=0.0,e,f,g;
    cin >> n;
    for(int i = 0;i<n;i++){
        cin >> x[i];
    }
    for(int i=0;i<n;i++){
        cin >> y[i];
    }
    for(int i=0;i<n;i++){
        a = abs(x[i]-y[i]);
        b+=a;
        c+=a*a;
        d+=a*a*a;
        if(a>max)max=a;
    }
    e = sqrt(c);
    f = cbrt(d);
    g = max;
    printf("%f\n %f\n %f\n %f\n",b,e,f,g);
    return 0;
}


Measured memory_bytes: 3328
n=int(input())
a=list(map(int,input().split()))
asum=sum(a)
y=[0]*n
y[-1]=a[-1]
for i in range(n-1):
    if i%2==0:
        y[-1]-=a[i]
    else:
        y[-1]+=a[i]
for i in range(n-1):
    y[i]=a[i-1]*2-y[i-1]
print(*y)


Measured memory_bytes: 64996
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

int main()
{
    string S;
    cin >> S;

    bool YYMM = false, MMYY = false;
    {
        bool year = false, month = false;
        for (ll i = 0; i < 100; i++)
        {
            ostringstream s;
            s << setfill('0') << setw(2) << i;
            if (s.str() == S.substr(0, 2))
            {
                year = true;
            }
        }
        for (ll i = 1; i <= 12; i++)
        {
            ostringstream s;
            s << setfill('0') << setw(2) << i;
            if (s.str() == S.substr(2, 2))
            {
                month = true;
            }
        }
        YYMM = year && month;
    }
    {
        bool year = false, month = false;
        for (ll i = 0; i < 100; i++)
        {
            ostringstream s;
            s << setfill('0') << setw(2) << i;
            if (s.str() == S.substr(2, 2))
            {
                year = true;
            }
        }
        for (ll i = 1; i <= 12; i++)
        {
            ostringstream s;
            s << setfill('0') << setw(2) << i;
            if (s.str() == S.substr(0, 2))
            {
                month = true;
            }
        }
        MMYY = year && month;
    }

    if (YYMM && MMYY)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (YYMM)
    {
        cout << "YYMM" << endl;
    }
    else if (MMYY)
    {
        cout << "MMYY" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<int>> mp(h, vector<int>(w));
	rep(i, h) rep(j, w) cin >> mp[i][j];
	vector<tuple<int, int, int, int>> ans;
	rep(i, h) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; ++j) {
				if (mp[i][j] % 2 == 1) {
					if (j + 1 < w) {
						mp[i][j + 1]++;
						ans.emplace_back(i + 1, j + 1, i + 1, j + 2);
					}
					else if (i + 1 < h) {
						mp[i + 1][j]++;
						ans.emplace_back(i + 1, j + 1, i + 2, j + 1);
					}
				}
			}
		}
		else {
			for (int j = w - 1; j >= 0; --j) {
				if (mp[i][j] % 2 == 1) {
					if (j - 1 >= 0) {
						mp[i][j - 1]++;
						ans.emplace_back(i + 1, j + 1, i + 1, j);
					}
					else if (i + 1 < h) {
						mp[i + 1][j]++;
						ans.emplace_back(i + 1, j + 1, i + 2, j + 1);
					}
				}
			}
		}
	}
	int sz = ans.size();
	cout << sz << endl;
	for (auto c : ans) printf("%d %d %d %d\n", get<0>(c), get<1>(c), get<2>(c), get<3>(c));
	return 0;
}

Measured memory_bytes: 6312
# https://atcoder.jp/contests/agc034/tasks/agc034_a
import sys
n, a, b, c, d = map(int, input().split())
s = list(input())

for i in range(a - 1, c - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

for i in range(b - 1, d - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

if c > d:
    f = False
    for i in range(b - 2, d - 1):
        if s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.':
            f = True
else:
    f = True
if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n;
  cin >> n;
  set <ll> s;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0) {
      s.insert(b);
      cout << s.size() << endl;
    } else if (a == 1) {
      cout << s.count(b) << endl;
    } else {
      s.erase(b);
    }
  }
}


Measured memory_bytes: 12464
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 100005;
ll T,n,m;
ll a[maxn];
ll num[maxn];
ll dp[maxn];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]++;
	}
	ll sum = 1;
	num[0] = 3;
	for(int i=1;i<=n;i++){
		sum*=(num[a[i]-1]);
		num[a[i]]++;
		num[a[i]-1]--;
		sum%=mod;
	}
	cout<<sum<<endl;
	return 0;
	
}



Measured memory_bytes: 1792
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    ll now = 1000, k = 0;
    rep(i, n - 1) {
        if (a[i] < a[i + 1]) {
            k += now / a[i];
            now %= a[i];
        }
        if (a[i] > a[i + 1]) {
            now += k * a[i];
            k = 0;
        }
    }
    
    now += k * a[n - 1];
    cout << now << "\n";
    return;
}


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

typedef unsigned long long int lli;

vector<int> v;

bool linearSeach(int x)
{
    for(int i = 0; i < v.size(); i++)
    {
        if(v[i] == x)
        {
            return true;
        }
    }
    return false;
}

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

    v.resize(n);

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

    int i = x, j = x;
    int counter = 0;

    while(1)
    {
        if(counter%2 == 0)
        {
            if(!linearSeach(i))
            {
                cout << i;
                break;
            }
            i--;
        }
        else
        {
            if(!linearSeach(j))
            {
                cout << j;
                break;
            }
            j++;
        }
        counter++;
    }
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,q,t;
    string s;
    vector<ll>v;
    deque<ll>dq;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if (s=="Cloudy")cout<<"Rainy"<<endl;
    else if (s=="Rainy")cout<<"Sunny"<<endl;
}




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


set<long long> Primer(long long a){
  set<long long> P;
  long double x = sqrtl(a);
  for(int i = 2; i <= x; ++i){
    if(a % i == 0){
      a /= i;
      P.insert(i);
      while(a % i == 0){
        a /= i;
      }
    }
  }
  P.insert(1);
  P.insert(a);
  return P;
}

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

  long long A, B;
  cin >> A >> B;

  set<long long> PofA = Primer(A);
  set<long long> PofB = Primer(B);

  long long count = 0;

  for(auto x: PofA){
    if(PofB.count(x)){
      ++count;
    }
  }

  cout << count <<endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;

	ll mi = min(a, min(b, min(c, min(d, e))));
	out((ll)ceil((double)n / mi) + 4);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
using namespace std;
template<class T>il read(T &x){
	x=0;int f=1;char k=getchar();
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>9) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	double L=n/3.;
	printf("%.7lf",L*L*L);
	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $X, $N);
if ($N === 0) {
    echo $X, PHP_EOL;
    exit;
}

$p = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($p);

$i_c = array_search($X, $p, true);
if ($i_c === false) {
    echo $X, PHP_EOL;
    exit;
}

for ($j = 1; ; $j++) {
    $i_l = $i_c - $j;
    $i_r = $i_c + $j;
    if (! isset($p[$i_l])) {
        echo $X - $j, PHP_EOL;
        break;
    } elseif ($p[$i_l] !== $X - $j) {
        echo $X - $j, PHP_EOL;
        break;
    }
    if (! isset($p[$i_r])) {
        echo $X + $j, PHP_EOL;
        break;
    } elseif ($p[$i_r] !== $X + $j) {
        echo $X + $j, PHP_EOL;
        break;
    }
}




Measured memory_bytes: 16192
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll a,b; cin>>a>>b;
	if(a<b){
		lp(i,0,b)
		cout<<a;
	}
	else lp(i,0,a) cout<<b;

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

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

def main():
    H, W = map(int, readline().split())
    grid = []
    for _ in range(H):
        A = list(readline()[:-1])
        if '#' in A:
            grid.append(A)

    for i in range(W-1, -1, -1):
        flag = True
        for j in range(len(grid)):
            if grid[j][i] == '#':
                flag = False
                break
        if flag:
            for k in range(len(grid)):
                del grid[k][i]
    
    for k in range(len(grid)):
        print(''.join(grid[k]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
n = int(input())
c = [int(input()) for _ in range(n)]
mod = 10 ** 9 + 7

# 解説AC
dp = [1] * n
color = [-1] * max(c)
for i, ci in enumerate(c):
    dp[i] = dp[i - 1]
    if 0 <= color[ci - 1] < i - 1:
        dp[i] += dp[color[ci - 1]]
    color[ci - 1] = i
print(dp[-1] % mod)


Measured memory_bytes: 789820
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
struct Graph
{
    Graph(const std::size_t v) : V{v}, edge(v), rev_edge(v) {}
    void addEdge(const std::size_t from, const std::size_t to) { edge[from].push_back(to), rev_edge[to].push_back(from); }
    const std::size_t V;
    std::vector<std::vector<std::size_t>> edge, rev_edge;
};
int main()
{
    std::string S;
    std::cin >> S;
    const int N = S.size();
    S = "0" + S;
    if (S[1] == '0' or S[N] == '1') { return std::cout << "-1" << std::endl, 0; }
    int node = 1;
    using P = std::pair<int, int>;
    std::vector<P> ans;
    for (int i = 2; i < N; i++) {
        if (S[i] != S[N - i]) { return std::cout << -1 << std::endl, 0; }
        if (S[i] == '1') {
            ans.push_back({i, node});
            for (int j = 1; j < i - node; j++) { ans.push_back({i, node + j}); }
            node = i;
        }
    }
    std::cout << N - 1 << " " << N << std::endl;
    for (const auto& p : ans) {
        std::cout << p.first << " " << p.second << std::endl;
    }
    return 0;
}


Measured memory_bytes: 2416
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define Rep(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
#define Repe(i,a,b) for(register int i=(a),i##end=(b);i>=i##end;--i)
#define For(i,a,b) for(i=(a),i<=(b);++i)
#define Forward(i,a,b) for(i=(a),i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
template<typename T>inline void read(T &x)
{
	T f=1;x=0;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c^48);
	x*=f;
}
using namespace std;
const int MAXN=1010;
static int n,m;
inline void init()
{
	read(n);read(m);
}
static long long ans;
inline void solve()
{
	ans=1ll*(n-2)*(m-2);
	if(ans<0)ans*=-1;
	cout<<ans<<endl;
}
int main()
{
	init();
	solve();
	return 0;
}



Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
*p, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())

p.sort(key=lambda x: -x)
q.sort(key=lambda x: -x)
p = p[:X]
q = q[:Y]

pqr = p+q+r
pqr.sort(key=lambda x: -x)
print(sum(pqr[:X+Y]))

Measured memory_bytes: 122980
#include <iostream>

int main() {
  for (size_t i=0; i<3; i++) {
    char c;
    std::cin >> c;
    if (c == '1') std::cout << '9';
    else if (c == '9') std::cout << '1';
    else std::cout << c;
  }

  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "0" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll dp[200020][5];
//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];

    rep(i,N+1) rep(j,5) dp[i][j]=INF2;
    dp[0][0]=0; 
    rep(i,N){
        if(A[i]!=0){
            rep(j,5){
                reps(k,j,5){
                    if(k==0) mini(dp[i+1][k],dp[i][j]+A[i]);
                    if(k==1) mini(dp[i+1][k],dp[i][j]+A[i]%2);
                    if(k==2) mini(dp[i+1][k],dp[i][j]+1-(A[i]%2));
                    if(k==3) mini(dp[i+1][k],dp[i][j]+A[i]%2);
                    if(k==4) mini(dp[i+1][k],dp[i][j]+A[i]);
                }
            }
        }
        else{
            rep(j,5){
                reps(k,j,5){
                    if(k==0) mini(dp[i+1][k],dp[i][j]);
                    if(k==1) mini(dp[i+1][k],dp[i][j]+2);
                    if(k==2) mini(dp[i+1][k],dp[i][j]+1);
                    if(k==3) mini(dp[i+1][k],dp[i][j]+2);
                    if(k==4) mini(dp[i+1][k],dp[i][j]);
                }
            }
        }
    }
    ll ans=INF2;
    rep(i,5) mini(ans,dp[N][i]);
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define sz(x) ((int)x.size())

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
const int N = 1e5+5;
typedef vector<int> vi;

char a[15];
 
int32_t main()
{
   string s;
   cin >> s;
   int ptr = 0;
   memset(a, -1, sizeof(a));
   for(int i = 0; i < sz(s); i++)
   {
      if(s[i] == '0' or s[i] == '1')
         a[ptr++] = s[i];
      else
         if(ptr != 0)
            ptr--;
   }
   for(int i = 0; i < ptr ; i++)
   {
      cout << a[i];
   }
   return 0;
}

Measured memory_bytes: 256
from collections import defaultdict as d
n, m = map(int, input().split())
dico = d(set)
tab = [-1] * n
for _ in range (m):
  s, c = map(int, input().split())
  dico[s].add(c)
  if len(dico[s]) == 2:
    print(-1)
    exit()
  tab[s - 1] = c
if n == 1:
  print(max(0, tab[0]))
else:
  if tab[0] == 0:
    print(-1)
  else:
    if tab[0] == -1:
      tab[0] = 1
    f = ''
    for i in tab:
      if i == -1:
        f += '0'
      else:
        f += str(i)
    print (f)

Measured memory_bytes: 3444
#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>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e30
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, L, R, K, X, A, B, C, Z;
ll ans;
string S;
bool D[10];
ll x[100000000];
ll y[100000000];
ll nowcost = 1;
ll twopow[202020];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll m[100][100];
ll DP[1000001];
int main() {
	cin>>S;
	string ans="";
	rep(i,0,S.size()){
		if(S[i]!='B')ans+=S[i];
		else{
			if(!ans.empty())
			ans.pop_back();
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int gcd(int a, int b)
{
	if(a < b)
		swap(a, b);
		
	if(b == 0)
		return a;
		
	return gcd(b, a % b);
}

int lcm(int a, int b)
{
	int div = gcd(a, b);
	
	return a / div * b;
}

struct mobile {

	int p, q, r, b;
	mobile() {}
	mobile(int p, int q, int r, int b) : p(p), q(q), r(r), b(b) {}
};

int calc(int k, vector<mobile> &m) {

	if(k == -1)
		return 1;

	mobile x = m[k];
	
	int lw, rw;
	
	lw = calc(x.r - 1, m);
	rw = calc(x.b - 1, m);
	
	int div = gcd(x.p, x.q);
	x.p = x.p / div;
	x.q = x.q / div;
	
	//x.p * lw * a = x.q * rw * b
	int sum = lcm(x.p * lw, x.q * rw);
	int ans = sum / x.p + sum / x.q;
	
	//printf("[debug] %d -> %d\n", k, ans);
	
	return ans;
}

int main()
{
	while(true) {
	
		int n;
		
		scanf("%d", &n);
		if(n == 0)
			break;
			
		vector<mobile> m;
		
		m.resize(n);
		
		for(int i = 0; i < n; ++i)
			scanf("%d%d%d%d", &m[i].p, &m[i].q, &m[i].r, &m[i].b);
		
		bool middle[128] = {false};
		int top = -1;
		
		for(int i = 0; i < n; ++i)
			middle[m[i].r] = middle[m[i].b] = true;
		middle[0] = true;
		for(int i = 0; i <= n; ++i) {
			if(!middle[i]) {
				top = i - 1;
				break;
			}	
		}
		
		int ans = calc(top, m);
		
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b,c,d;
  ci(a>>b>>c);
  For(i,0,a){
    ci(d);
    c+=b/d+1;
    if(b%d==0)
      c--;
  }
  co(c);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N;
string s;
long long powminus [200010], powplus [200010], summinus = 0, sumplus = 0;

long long bruteForce(long long x){
    //cout << x << endl;
    int cnt = 0;
    while(x > 0){
        x = x%__builtin_popcountll(x);
        cnt++;
    }
    //cout << "HI " << cnt << endl;
    return cnt;
}

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> s; powplus[0] = powminus[0] = 1;
    int oripop = 0;
    for(int i = 0; i < N; i++) oripop += s[i]-'0';
    for(int i = 1; i < N; i++){
        if(oripop > 1) powminus[i] = (powminus[i-1]*2)%(oripop-1);
        powplus[i] = (powplus[i-1]*2)%(oripop+1);
    }
    for(int i = 0; i < N; i++){
        if(oripop > 1){
            summinus += powminus[N-1-i]*(s[i]-'0');
            summinus %= (oripop-1);
        }
        sumplus += powplus[N-1-i]*(s[i]-'0');
        sumplus %= (oripop+1);
        //cout << sumplus << endl;
    }
    //cout << sumplus << ' ' << summinus << ' ' << oripop << endl;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1'){
            if(oripop == 1){
                cout << "0\n";
                continue;
            }
            cout << 1+bruteForce((summinus-powminus[s.length()-1-i]+oripop-1)%(oripop-1)) << '\n';
        }
        else{
            cout << 1+bruteForce((sumplus+powplus[s.length()-1-i])%(oripop+1)) << '\n';
        }
    }
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 6892
fun main(args: Array<String>){
    val ab = readLine()!!.split(' ').map { it.toInt() }
    val a = ab.max()!!
    val b = ab.min()!!
    if((a - b) % 2 == 1){
        println("IMPOSSIBLE")
        return
    }
    println((a + b) / 2)
}

Measured memory_bytes: 38236
//People only find me interesting because they can't tell whether I'm serious or not
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 105
#define PI 3.14159265359
#define inf LLONG_MAX
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
ll v[N], w[N], dp[100005]; 
void solve(){
    ll n,W,sv=0,mn=inf,mnw=inf,ans=0;
    cin>>n>>W;
    f(i,1,n+1){
        cin>>w[i]>>v[i];
        sv += v[i];
        mn = min(mn,v[i]);
        mnw = min(mnw,w[i]);
    }
    f(i,1,sv+1) dp[i] = W+1;
    f(i,1,n+1){
        bac(j,sv,v[i]){
            dp[j] = min(dp[j], w[i] + dp[j-v[i]]);
        }
    }
    f(i,1,sv+1){
        //cout<<i<<" "<<dp[i]<<endl;
        if(dp[i] <= W) ans = i;
    }
    cout<<ans;
}
signed main() {
    teevra_gati
    
    solve();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int h, w;
    while(1) {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i + j) % 2 == 0) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;

namespace kyoupuro
{
    class MainClass
    {
        public static void Main()
        {
            MainClass mainClass = new MainClass();
            mainClass.Start();
        }

        public void Start(){
            var line = Console.ReadLine().Split(' ');
            int H = int.Parse(line[0]), W = int.Parse(line[1]);
            // var line = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split(' ');
            int h = int.Parse(r[0]), w = int.Parse(r[1]);


            Console.WriteLine((H-h)*(W-w));
            
        }
    }
}




Measured memory_bytes: 11092
#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()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;

    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int n,k;
int a[5010];

bool per[5010][5010],rev[5010][5010];

int main(void){
	cin >> n >> k;
	rep(i,n) cin >> a[i];

	sort(a,a+n);
 
	{
		int limit=0;
		rep(i,n) if(a[i]<=k) limit=i;
		n=limit+1;
	}

	per[0][0]=true;
	rep(i,n)rep(j,k+1){
		if(per[i][j]==false) continue;
		per[i+1][j]=true;
		if(j+a[i]<=k) per[i+1][j+a[i]]=true;
	}

	rev[n][0]=true;
	rrep(i,n)rep(j,k+1){
		if(rev[i+1][j]==false) continue;
		rev[i][j]=true;
		if(j+a[i]<=k) rev[i][j+a[i]]=true;
	}


	int ans=0;
	rep(i,n){
		set<int> s;
		rep(j,k+1) if(rev[i+1][j]) s.insert(j);
		bool ok=false;

		//[k-a[i],k-1] 
		//[small,large]
		//[small-j,large-j] 
		rep(j,k+1){
			if(per[i][j]==false) continue;
			auto it=s.lower_bound(k-a[i]-j);
			if(it!=end(s) and *it<=k-1-j) ok=true;
		}

		if(ok==false) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

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


Measured memory_bytes: 3112
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int SOLVE(){
	int n;
	cin >> n;
	vector<long long> a(n);
	string s;
	for(auto i = 0; i < n; ++ i){
		cin >> a[i];
	}
	cin >> s;
	vector<long long> basis; // increasing
	for(auto i = n - 1; i >= 0; -- i){
		long long x = accumulate(basis.rbegin(), basis.rend(), a[i], [&](long long x, long long y){ return min(x, x ^ y); });
		if(s[i] == '0'){
			if(x){
				basis.insert(lower_bound(basis.begin(), basis.end(), x), x);
			}
		}
		else if(x){
			cout << "1\n";
			return 0;
		}
	}
	cout << "0\n";
	return 0;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int ttt;
	cin >> ttt;
	while(ttt --){
		SOLVE();
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

int main() {
    string ans = "YES";
    int n;
    int max = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
        if(a.at(i) > max){
            max = a.at(i);
        }
    }

    sort(a.begin(),a.end());

    for(int i = 0; i < n-1; i++){
        if(a.at(i) == a.at(i+1)){
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
typedef long long ll;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a.at(i);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (a[i] == j+1 && a[j] == i+1) ans++;
		}
	}
	cout << ans << endl;
}

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

int main(void){
    int N, W; cin >> N >> W;
    vector<ll> w(N), v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(110, vector<ll>(100010));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if(j - w[i] >= 0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);      //i番目を選ぶとき
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);                                    //i番目を選ばないとき
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 87296
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 1;
  char c = s[0];
  REP(i,n){
    if(c == s[i]) continue;
    ans++; c = s[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
int sum[10][10];
int main(){
	cin>>n;
	rep(i,n){
		int h=i+1;
		int hh=h;
		h%=10;
		while(hh>=10)
		hh/=10;
		sum[hh][h]++;
	}
	int ans=0;
	forn(i,1,10){
		forn(j,1,10){
			ans+=sum[i][j]*sum[j][i];
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
int main() {
  ll n, C;
  ll d[50][50], c[600][600], dif[3][50];

  cin >> n >> C;
  REP(i, C) {
    REP(j, C) {
      cin >> d[i][j];
    }
  }
  REP(i, n) {
    REP(j, n) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }

  REP(color, C) {
    ll sum[3] = {};
    REP(i, n) {
      REP(j, n) {
        if (c[i][j] == color)
          continue;
        sum[(i + j) % 3] += d[c[i][j]][color];
      }
    }
    REP(i, 3) {
      dif[(i)][color] += sum[i];
    }
  }
  ll ans = INF;
  REP(i, C) {
    REP(j, C) {
      REP(k, C) {
        if (i == j || i == k || j == k) {
          continue;
        }

        ans = min(ans, dif[0][i] + dif[1][j] + dif[2][k]);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
	int x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int n, a[10005], x, c[10005], k, minn=1e9;
int main() {
	cin>>x>>n;
	for(int i=1;i<=n;i++) a[i]=read(), c[a[i]]=1;
	for(int i=0;i<=200;i++) {
		if(!c[i]&&abs(i-x)<minn)  {
			minn=abs(i-x);
			k=i;
		}
	}
	cout<<k;
}


Measured memory_bytes: 3636
a, b, c = map(int, input().split())
if a == b == c:
    if a % 2 == 0:
        print(-1)
        exit()
    else:
        print(0)
        exit()
for i in range(0, 10**6):
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        print(i)
        exit()
    a, b, c = (b+c) / 2, (c+a)/2, (a+b)/2


Measured memory_bytes: 3060
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int d = int.Parse(s[3]);
            int e = int.Parse(s[4]);

            Console.WriteLine(d + c * 60 - b - a * 60 - e);

        }
    }

    class ProgramB
    {
        public void main()
        {

            string s = Console.ReadLine();

            for(int i = 0;i < s.Length;i++)
            {
                if(s[i] == '?')
                {
                    Console.Write('D');
                }
                else
                {
                    Console.Write(s[i]);
                }
            }
            

        }
    }

    class ProgramC
    {
        public void main()
        {

            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');

            //n=0のときは例外処理
            if(n == 0)
            {
                if (a[0] == "1")
                    Console.WriteLine("1");
                else
                    Console.WriteLine("-1");
                return;
            }
            //0のときは0以外はダメ
            if(a[0] != "0")
            {
                Console.WriteLine("-1");
                return;
            }
            long[] num = new long[n + 1];
            long[] leave = new long[n + 1];
            num[0] = 1;
            leave[n] = long.Parse(a[n]);
            //深さiを含む後ろの根の数を数えておく
            for (int i = n -1; i >= 0 ;i--)
                leave[i] = leave[i + 1] + long.Parse(a[i]);
            //前から根の数を決める（ただし、最大は後ろに考えるべき根の数に限られる）
            for(int i = 1;i <= n;i++)
            {
                num[i] = Math.Min(2 * (num[i - 1] - long.Parse(a[i - 1])), leave[i]);
                //あり得る数が葉になる数より大きければあり得ない
                if(i < n && num[i] <= long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }

                if (i == n && num[i] < long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
            
            //答え出力
            long ans = 0;
            for(int i = 0; i <= n;i++)
                ans += num[i];

            Console.WriteLine(ans);
        }
    }
}






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

int main() {
	int w,h,x,y,r;
	cin >> w >> h >> x >> y >> r;
	if ((x - r) >= 0 && (y - r) >= 0) {
		if ((x + r) <= w && (y + r) <= h) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
	else {
		cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3100