akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define PI acos(-1)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{
    return Point(x + p.x , y + p.y);
  }

  Point operator - (const Point &p)const{
    return Point(x - p.x , y - p.y);
  }

  Point operator * (const double &k)const{
    return Point(x * k , y * k);
  }

  Point operator / (const double &k)const{
    return Point(x / k , y / k);
  }

  double dot(const Point &p)const{
    return x*p.x + y*p.y;
  }

  double cross(const Point &p)const{
    return x*p.y - p.x*y;
  }

  double dist(const Point &p)const{
    return sqrt(pow(x-p.x,2) + pow(y-p.y,2));
  }

  double norm(){
    return x*x + y*y;
  }

  double Abs(){
    return sqrt(norm());
  }
};

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(a.cross(b) > EPS){ return COUNTER_CLOCKWISE; }
  if(a.cross(b) < -EPS){ return CLOCKWISE; }
  if(a.dot(b) < -EPS){ return ONLINE_BACK; }
  if(a.norm() < b.norm()){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

typedef vector<Point> Polygon;

#define prev(G,i) (G[(i-1+G.size())%G.size()])
#define curr(G,i) (G[(i)%G.size()])
#define next(G,i) (G[(i+1)%G.size()])

bool isConvex(const Polygon &p){
  for(int i = 0 ; i < (int)p.size() ; i++){
    if(ccw(prev(p,i),curr(p,i),next(p,i)) == CLOCKWISE){
      return false;
    }
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  Polygon p(N);
  for(int i = 0 ; i < N ; i++){
    cin >> p[i].x >> p[i].y;
  }
  cout << isConvex(p) << endl;
  return 0;
}

Measured memory_bytes: 1228
S = gets.chomp
if S.size < 26
  puts S + ([*?a..?z] - S.chars)[0]
else
  (S.size-1).downto(0){|i|
    c = S[i]
    next_c = (c.succ..?z).find{|d|
      !S[0..i][d]
    }
    if next_c
      puts S[0...i]+next_c
      exit
    end
  }
  p -1
end


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define DEBUG 0
/*
*/

using namespace std;



int main() {
	long long int N;
	cin >> N;
	vector<long long int>D(N * 3);
	for (size_t i = 0; i < N * 3; i++)
	{
		cin >> D[i];
	}
	sort(D.rbegin(), D.rend());
	long long int ans = 0;
	for (size_t i = 0; i < N; i++)
	{
		ans += D[i * 2 + 1];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define MAX 1e5
#define DIV 1000000007
using namespace std;

int main() {
    int N;
    cin >> N;

    int a;
    vector<int> cnt(MAX + 1);
    for (int i = 0; i < N; i++) {
        cin >> a;
        cnt[a]++;
    }
    
    int ans = 0;
    int total;

    for (int i = 1; i < MAX; i++) {
        ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
    }
    
    cout << ans << endl;
}



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string s;cin>>s;
    int n = s.size();
    vector<vector<int>> dp(n,vector<int>(2,-INF));
    dp[0][1] = 1;
    dp[1][0] = 1;
    if(s[0]!=s[1]) dp[1][1] = 2;
    for(int i=2;i<n;i++)
    {
        dp[i][1] = dp[i-1][0] + 1;
        if(s[i-1]!=s[i]) dp[i][1] = max(dp[i][1], dp[i-1][1] + 1);

        dp[i][0] = dp[i-2][1] + 1;
        if(i-3>=0 && s.substr(i-3, 2)!=s.substr(i-1,2)) dp[i][0] = max(dp[i][0], dp[i-2][0] + 1);
    }
    cout << max(dp[n-1][0], dp[n-1][1]) << endl;
}


Measured memory_bytes: 11412
#include <bits/stdc++.h>
using namespace std;
#define MAX 10000
#define ll long long
int main(){
	 ios_base::sync_with_stdio(false);
	  cin.tie(NULL);cout.tie(NULL);
 string s,t;
 cin>>s;
 cin>>t;
 t.erase((int)t.size()-1,1);
 if(s!=t) cout<<"No"<<"\n";
 else cout<<"Yes\n";
}


Measured memory_bytes: 3596
def main():    
    import heapq
    
    n, m, s = map(int, input().split())
    if s >= 2500:
        s = 2499
    
    edges = [[] for _ in range(n)]
    for _ in range(m):
        from_, to, cost, time = map(int, input().split())
        edges[from_-1].append((to-1, cost, time))
        edges[to-1].append((from_-1, cost, time))
    
    banks = []
    for i in range(n):
        coin, time = map(int, input().split())
        banks.append((coin, time))
    
    INF = float('INF')
    DP = [[INF] * 2500 for _ in range(n)]
    ans = [INF] * n
    
    def push_todo(node, coin, time):
        if coin < 0:
            return
        if time >= DP[node][coin]:
            return
        heapq.heappush(todo, (time, node, coin))
    
    def charge(node, current_coin, current_time):
        coin, time = banks[node]
        new_coin = current_coin + coin
        if new_coin >= 2500:
            new_coin = 2499
        push_todo(node, new_coin, current_time+time)
    
    todo = [(0, 0, s)]
    while todo:
        current_time, node, current_coin = heapq.heappop(todo)
        if current_time >= DP[node][current_coin]:
            continue
    
        if current_time < ans[node]:
            ans[node] = current_time
    
        DP[node][current_coin] = current_time
        charge(node, current_coin, current_time)
    
        for to, cost, time in edges[node]:
            push_todo(to, current_coin-cost, current_time+time)
    
    for a in ans[1:]:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36004
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<_> = st.trim().chars().collect();
    let mut r:i64 = 0;
    let mut c:i64 = 0;
    for i in (0..s.len()).rev() {
        if s[i] == 'B' {
            r += c;
        } else {
            c += 1;
        };
    };
    println!("{}", r)
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int CH[300002] = {0};
int CW[300002] = {0};

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int H, W, M;
	cin >> H >> W >> M;
	map<int, int> HM, WM;
	map<pair<int, int>, int> MM;
	for(int i=0; i<M; i++){
		int h, w;
		cin >> h >> w;
		CH[h]++;
		CW[w]++;
		MM[make_pair(h, w)] = 1;
	}
	
	int hmax = 0;
	for(int i=1; i<=H; i++){
		if(hmax < CH[i]){
			hmax = CH[i];
		}
	}
	map<int, int> M1;
	for(int i=1; i<=H; i++){
		if(CH[i] == hmax){
			M1[i] = hmax;
		}
	}

	int wmax = 0;
	for(int i=1; i<=W; i++){
		if(wmax < CW[i]){
			wmax = CW[i];
		}
	}
	map<int, int> M2;
	for(int i=1; i<=W; i++){
		if(CW[i] == wmax){
			M2[i] = wmax;
		}
	}
	LL prod = (LL)M1.size() * (LL) M2.size() ;
	if(prod > M){
		printf("%d\n", hmax + wmax);
		return 0;
	}

	int exist = 0;
	for(auto itr1 = M1.begin(); itr1 != M1.end(); itr1++){
		for(auto itr2 = M2.begin(); itr2 != M2.end(); itr2++){
			int a = itr1->first;
			int b = itr2->first;
			if(MM.count(make_pair(a, b)) == 0){
				exist = 1;
				break;
			}
		}
		if(exist == 1){
			break;
		}
	}
	if(exist == 1){
		printf("%d\n", hmax + wmax );
	}
	else{
		printf("%d\n", hmax + wmax - 1);
	}
	return 0;
}



Measured memory_bytes: 52808
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
#define tam 1234567
int cant[tam],arrpa[tam];
int findpa(int num)
{
    if (arrpa[num]==num)
        return num;
    else
        return arrpa[num]=findpa(arrpa[num]);
}
vector<int> g[tam];
int restar[tam];
int main()
{
    forr(i,0,tam)
    cant[i]=1,arrpa[i]=i;
    int n,m,k;
    cin>>n>>m>>k;
    int pa1,pa2,iz,der;
    forr(i,0,m)
    {
        cin>>iz>>der;
        pa1=findpa(iz);
        pa2=findpa(der);
        restar[iz]++;
        restar[der]++;
        if (pa1!=pa2)
            cant[pa1]+=cant[pa2],arrpa[pa2]=pa1;
    }
    forr(i,0,k)
    {
        cin>>iz>>der;
        g[iz].pb(der);
        g[der].pb(iz);
    }
    forr(i,1,n+1)
    {
        int tot=cant[findpa(i)]-restar[i]-1;
        for(int hijo:g[i])
        {
            if (findpa(i)==findpa(hijo))
                tot--;
        }
        cout<<tot<<" ";
    }
}
// PLUS ULTRA!

Measured memory_bytes: 43904
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int parN = Integer.parseInt(sc.next());
        sc.close();
        int[] result = new int[10000];
        int cur = 0;

        for (int z = 1; z <= 100; z++) {
            for (int y = 1; y <= z; y++) {
                for (int x = 1; x <= y; x++) {
                    cur = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (x * z);
                    if (cur > 10000) {
                        break;
                    }
                    if (cur != 0) {
                        if (x == z) {
                            result[cur - 1] = result[cur - 1] + 1;
                        } else if (x == y || y == z) {
                            result[cur - 1] = result[cur - 1] + 3;
                        } else {
                            result[cur - 1] = result[cur - 1] + 6;
                        }

                    }
                }
            }
        }

        for (int i = 0; i < parN; i++) {
            System.out.println(result[i]);
        }
    }

}

Measured memory_bytes: 38952
#include <bits/stdc++.h>
 
using namespace std;
 
bool field[5][5][5];
 
inline bool inField(int x,int y,int z){
    if(0 > x || x >= 5) return false;
    if(0 > y || y >= 5) return false;
    if(0 > z || z >= 5) return false;
    return true;
}
 
int getNum(int x,int y,int z,bool f){
    int res = 0;
    for(int zz = z-1 ; zz <= z+1 ; zz++){
	for(int yy = y-1 ; yy <= y+1 ; yy++){
	    for(int xx = x-1 ; xx <= x+1 ; xx++){
		if(xx == x && yy == y && zz == z) continue;
		if(!inField(xx,yy,zz)) continue;
		if(field[yy][xx][zz] == f){
		    res++;
		}
	    }
	}
    }
    return res;
}
 
int main(){
    int N,Tc = 0;
    bool space = false;
    while(cin >> N, N > 0){
	if(space) cout << endl;
	else space = true;
	for(int z = 0 ; z < 5 ; z++){
	    string str;
	    for(int y = 0 ; y < 5 ; y++){
		cin >> str;
		for(int x = 0 ; x < 5 ; x++){
		    field[y][x][z] = str[x]-'0';
		}
	    }
	}
	int M[2],a[27],b[27];
	cin >> M[0];
	for(int i = 0 ; i < M[0] ; i++){
	    cin >> a[i];
	}
	cin >> M[1];
	for(int i = 0 ; i < M[1] ; i++){
	    cin >> b[i];
	}
	while(N--){
	    bool next[5][5][5];
	    for(int z = 0 ; z < 5 ; z++){
		for(int y = 0 ; y < 5 ; y++){
		    for(int x = 0 ; x < 5 ; x++){
			int num;
			bool f = field[y][x][z];
			if(f){
			    num = getNum(x,y,z,true);
			    bool ok = false;
			    for(int i = 0 ; i < M[1] ; i++){
				if(num == b[i]){
				    ok = true;
				    break;
				}
			    }
			    if(!ok){
				f = !f;
			    }
			}else{
			    num = getNum(x,y,z,true);
			    bool ok = false;
			    for(int i = 0 ; i < M[0] ; i++){
				if(num == a[i]){
				    ok = true;
				    break;
				}
			    }
			    if(ok){
				f = !f;
			    }
			}
			next[y][x][z] = f;
		    }
		}
	    }
	    for(int z = 0 ; z < 5 ; z++){
		for(int y = 0 ; y < 5 ; y++){
		    for(int x = 0 ; x < 5 ; x++){
			field[y][x][z] = next[y][x][z];
		    }
		}
	    }
	}
	cout << "Case " << ++Tc << ":" << endl;
	for(int z = 0 ; z < 5 ; z++){
	    for(int y = 0 ; y < 5 ; y++){
		for(int x = 0 ; x < 5 ; x++){
		    cout << field[y][x][z];
		}
		cout << endl;
	    }
	    if(z != 4){
		cout << endl;
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    
    int n;
    cin>>n;
    int mx = 0;
    int ans =0;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        if(t>=mx)
        {
            ans++;
            mx=  max(t,mx);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    if (S == T.substr(0, S.size())) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
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();
    if(a<b){
        System.out.println("a < b");
    }else if(b<a){
        System.out.println("a > b");
    }else if(a==b){
        System.out.println("a == b");
    }
   }
}


Measured memory_bytes: 26200
#include<stdio.h>
#include<string.h>
 
#define MAX 1000
 
int LCS(char *,char *,int,int);
 
int main(void){
    int n;
    char X[MAX],Y[MAX];
    int i;
 
    scanf("%d",&n);
 
    for(i=0;i<n;i++){
        scanf("%s",X);
        scanf("%s",Y);
 
        printf("%d\n",LCS(X,Y,strlen(X),strlen(Y)));
    }
 
    return 0;
}
 
int LCS(char *X,char *Y,int X_len,int Y_len){
    int table[Y_len+1][X_len+1];
    int i,j;
 
    for(i=1;i<=Y_len;i++) table[i][0]=0;
    for(i=0;i<=X_len;i++) table[0][i]=0;
 
    for(j=1;j<=Y_len;j++){
        for(i=1;i<=X_len;i++){
            if(Y[j-1]==X[i-1]) table[j][i]=table[j-1][i-1]+1;
            else if(table[j-1][i]>=table[j][i-1]) table[j][i]=table[j-1][i];
            else table[j][i]=table[j][i-1];
        }
    }
 
    return table[Y_len][X_len];
     
}

Measured memory_bytes: 4516
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n;
	cin >> n;
	cout << (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
input = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}

N = input[0][0]
M = input[0][1]

X = input[1].sort


def main() 
    diffs = []

    if N >= M 
        return 0
    end

    for i in 0..(M - 2)
        d = X[i + 1] - X[i] 
        diffs.push([i, d])
    end

    ds = diffs.sort_by{|x| x[1]}.reverse.slice(0, N - 1).sort_by{|x| x[0]}
    moves = 0

    if ds.length > 0
        for i in 0..(N - 1)
            if i == 0
                st = 0
                ed = ds[i][0]
            elsif i == (N - 1)
                st = ds[i - 1][0] + 1
                ed = M - 1
            else
                st = ds[i - 1][0] + 1
                ed = ds[i][0]
            end
            moves = moves + (X[ed] - X[st]).abs
        end
    else
        moves = (X.first - X.last).abs
    end
    return moves
end

puts main()

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

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, int> p[n];
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = {a, b};
    }
    sort(p, p + n);

    ll ans = 0;
    rep(i, n) {
        if (m <= p[i].second)
            ans += m * p[i].first, m = 0;
        else
            ans += p[i].first * p[i].second, m -= p[i].second;

        if (m == 0) break;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5148
#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
typedef long long ll;

ll N,M;
struct edge {
  ll to,c;
  edge(){}
  edge(ll to,ll c):to(to),c(c){}
};

vector<edge> G[100001];
bool F[100001][2];
ll S[100001][2];

bool dfs(ll v, ll f){
  F[v][f] = true;
  for(edge e : G[v]) {
    if( F[e.to][1-f] ) {
      if (S[e.to][1-f] != e.c - S[v][f]) return false;
    } else {
      S[e.to][1-f] = e.c - S[v][f];
      if( !dfs(e.to, 1-f) ) return false;
    }
  }
  return true;
}


int main() {
  cin >> N >> M;
  for(ll i=0;i<M;i++){
    ll a,b,c;
     cin >> a >> b >> c; --a; --b;
    G[a].emplace_back( b,c);
    G[b].emplace_back( a,c);
  }

  if( !dfs(0,0) ) {
    cout << 0 << endl;
    return 0;
  }

  ll mini1 = LLONG_MAX, mini2 = LLONG_MAX;
  ll cnt = 0;
  for(ll i=0;i<N;i++) {
    if( F[i][0] ) {
      mini1 = min( mini1, S[i][0] );
      cnt++;
    }
    if( F[i][1] ) {
      mini2 = min( mini2, S[i][1] );
      cnt++;
    }
  }


  if( cnt == 2 * N ) {
    bool f = [mini1,mini2]() {
      for (int i = 0; i < N; i++) {
        for (edge e : G[i]) {
          if (S[i][0] + S[e.to][0] != e.c) {
            int sa = e.c - (S[i][0] + S[e.to][0]);
            if (mini1 + sa / 2 < 1 || mini2 - sa / 2 < 1) return false;
          }
        }
      }
      return true;
    }();
    if( !f ) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  } else {
    if( mini1 > mini2 )
      swap(mini1,mini2);
    mini1--;
    mini2 += mini1;
    cout << max(0LL,mini2) << endl;
  }
}

Measured memory_bytes: 16640
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define pi 3.14159265358979323846264338
#define flash_all ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

const int mxN=2e5;
const int Max=1000000000000000000;

int main()
{
	ll n,m;
	long double x,sum=1;
	cin>>n>>x;
	x=x*100;
	m=x+0.01;
	sum=n*m/100;
	cout<<(ll)sum<<nl;
	return 0;
}
//Happy Coading.....


Measured memory_bytes: 3688
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

int main(void) {
    string s;
    cin >> s;
    ll i, ans=-1;
    
    for(i=0; i<s.size(); i++) {
        while(s[i]==s[i+1] && i<s.size()) {
            i++;
        }
        ans++;
        
    }
    
    prin(ans);
}


Measured memory_bytes: 512
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=505;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,tot,Ans,Mod,l[N],r[N],f[N][N];
int mod(int x){return x>=Mod?x-Mod:x;}
struct Node{
	int x,y,id;
	friend bool operator<(Node A,Node B){
		return A.x!=B.x?A.x<B.x:(A.y!=B.y?A.y<B.y:A.id>B.id);
	}
}P[N];
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();Mod=read();
	for(int i=0;i<2*n;i++){
		r[i]=min((int)(floor(sqrt(4*n*n-i*i))),2*n-1);
		if(i<n){
			l[i]=(int)(ceil(sqrt(n*n-i*i)));
			P[++tot]=(Node){l[i]-1,r[i],i};
		}
		else P[++tot]=(Node){r[i],l[i]-1,i};
	}
	sort(P+1,P+tot+1);
	for(int k=0;k<=n;k++){
		int t=0;
		memset(f,0,sizeof(f));
		f[0][0]=1;
		for(int i=1;i<=tot;i++){
			int x=P[i].id;
			for(int j=0;j<=k;j++){
				if(x>=n){
					int c=r[x]+1-(i-1-(t-j));
					if(c>0)f[i][j]=1ll*f[i-1][j]*c%Mod;
				}
				else{
					int c=r[x]+1-(2*n-1-(x-(k-j)));
					if(c>0)f[i][j]=1ll*f[i-1][j]*c%Mod;
					if(j){
						c=l[x]-(i-1-(t-j+1));
						if(c>0)f[i][j]=mod(f[i][j]+1ll*f[i-1][j-1]*c%Mod);
					}
				}
			}
			t+=(x<n);
		}
		Ans=mod(Ans+1ll*(k&1?Mod-1:1)*f[tot][k]%Mod);
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 4668
#include<bits/stdc++.h>
#define int long long 
#define endl "\n"

using namespace std ; 
int mod = 1e9 + 7 ; 
const int N = 1e5 + 5 ; 
int dp[105][N] ; 
	
int n ,x ; 	
int a[N] ; 

              
signed main()
{
	ios_base::sync_with_stdio(false) ;	
	cin.tie(NULL);	
	
	cin >> n >> x; 

	for(int i = 0 ; i < n ; ++i)
		cin >> a[i] ; 
	dp[0][0] = 1 ; 
	dp[0][1] = -1  ; 

	for(int i = 0 ; i < n ; ++i)
	{
		int s = 0 ; 
		for(int j = 0; j <= x; ++j)
		{
			s = (s+ dp[i][j] + mod)%mod ;
				
			if(s > 0  )
			{
				dp[i+1][j] += s ;
				dp[i+1][j] %= mod  ; 
				if(j +a[i] +1< N)
				{	
					dp[i+1][j + a[i] +1]  -= s ;
					dp[i+1][j + a[i] +1] =(dp[i+1][j+a[i]+1] + mod)% mod ; 

				} 
			}
			
			
		}
	}
//	for(int i =0 ; i <=n ; ++i)
//	{
//		for(int j = 0 ; j<=x ;++j)
//			cout << dp[i][j] << " "  ; 
//		cout << endl ;
//	}
		
	int ans =0 ; 
	for(int i = 0 ; i <=x ; ++i)
	{
		ans += dp[n][i] ;
                if(ans<= 0 )
		{
			cout << 0 << endl ; 
			return 0 ;
		}
		if(ans >= mod )
			ans %= mod ; 
	}
	cout << ans%mod << endl ;

	
}                 	



















Measured memory_bytes: 80980
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>
#include<random>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;


ll fc(ll xa,ll xb){  // xaより大きい最小のxbの倍数
    if(xa%xb==0)return xa;
    return xa/xb*xb+xb;
}

ll fi(ll xa,ll xb){  // xaより小さい最大のxbの倍数
    if(xa%xb==0)return xa;
    return xa/xb*xb;
}

int main(){
    
    cin>>m;
    for(int i=m-1;i>=0;i--){
        cin>>aa[i];
        //n=n/aa[i]*aa[i];
    }

    c=aa[0]; // 達成できる最小数
    z=aa[0]; // 最大数
    r=true;

    for(int i=0;i<m-1;i++){
        a=c;
        z=fi(z+aa[i]-1,aa[i+1]);
        c=fc(c,aa[i+1]);
    }
    ll cm=c;

    for(int i=m-1;i>=0;i--){
        cm=cm-cm%aa[i];
    }

    if(cm!=2)r=false;

    if(r) C c<<" "<<z+aa[m-1]-1 E;
    else C -1 E;
    
}



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

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

    int ans = 0;
    int count = 0;
    for(int i = 0; i < n - 1; i++) {
        if(h[i] >= h[i + 1]) count++;
        else {
            if(ans < count) ans = count;
            count = 0;
        }
    }
    if(ans < count) ans = count;

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
int n,cnt,num;
pii arr[202020];
map<string,int> mp;
map<int,string> ans;
string ret[202020];
main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		arr[i]={0,i};
		string st;
		cin>>st;
		if(mp.find(st)==mp.end())
		mp[st]=cnt, ans[cnt]=st, arr[cnt].first++,cnt++;
		else arr[mp[st]].first++;
	} sort(arr,arr+cnt); int imsi=arr[cnt-1].first;
	for(int i=cnt-1;i>=0;i--) 
	{
		if(arr[i].first==imsi) ret[num++]=ans[arr[i].second];
		else break;
	} sort(ret,ret+num); for(int i=0;i<num;i++)
	{
		cout<<ret[i]<<endl;
	}
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define sz(c) (ll) c.size()	
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define dm(m) trav(x,m) cout << x.f << "->" << x.s << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll n, k; cin >> n >> k;
    
    ll ans;

    if(n%k == 0) {cout << 0; return 0;}

    ans = n%k;

    if(k - ans < ans) ans = k - ans;

    cout  << ans;
}

Measured memory_bytes: 3628
N = int(input())
d = 0

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

for i in range(1,N+1):
  for j in range(i,N+1):
    for k in range(j,N+1):
      t = sorted((i,j,k))
      if i==j==k:
        n =1
      elif i==j or i==k or j ==k:
        n =3
      else:
        n =6
      d+= n*gcd(gcd(i,j),k)
print(d)

Measured memory_bytes: 69072
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

n, m, d = rdi()

if n <= 2*d or d == 0:
        r = (m-1) / float(n)
else:
        r = (m-1) * (2 * n - 2 * d) / float(n * n)

print "%.32f" % r


Measured memory_bytes: 4332
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n,m=0,i;
  cin>>s;
  n=s.length();
  for(i=0;i<n;i++) if(s.at(i)=='0') m++;
  cout<<2*min(m,n-m)<<endl;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
vector<int> A(N), B(N);
map<int, int> mm;

vector<int> solve() {	
	vector<int> ans(N, - 1);
	
	set<int> ss;
	REP(i, N) ss.insert(i);
	
	REP(i, N) {
		int r = i;
		while (r < N && A[r] == A[i]) ++r;
		// [i, r) まで同じ
		int c = r - i;
		int bc = mm[A[i]] - c;
		REP(j, bc) {
			auto it = ss.lower_bound(r);
			if (it != ss.end()) {
				ans[*it] = A[i];
				ss.erase(it);
				continue;
			}
			it = ss.lower_bound(i);
			if (it != ss.begin()) {
				--it;
				ans[*it] = A[i];
				ss.erase(it);
				continue;
			}
			return {};
		}
		i = r - 1;
	}
	
	for (auto c : mm) {
		int cnt = upper_bound(ALL(A), c.first) - lower_bound(ALL(A), c.first);
		if (cnt > 0) continue;
		REP(i, c.se) {
			ans[*ss.begin()] = c.first;
			ss.erase(ss.begin());
		}
	}
	
	bool ok = true;
	REP(i, N) if (ans[i] == A[i]) ok = false;
	if (!ok) {
		return {};
	}
	
	return ans;
}

vector<int> solve2() {
	int p = (N + 1) / 2;
	vector<int> ans(N, - 1);
	
	REP(i, N) {
		int r = i;
		while (r < N && A[r] == A[i]) ++r;
		// [i, r) まで同じ
		int c = r - i;
		int bc = mm[A[i]] - c;
		
		REP(j, bc) {
			ans[p] = A[i];
			p = (p + 1) % N;
		}
		i = r - 1;
	}
	
	for (auto c : mm) {
		int cnt = upper_bound(ALL(A), c.first) - lower_bound(ALL(A), c.first);
		if (cnt > 0) continue;
		REP(i, c.se) {
			ans[p] = c.first;
			p = (p + 1) % N;
		}
	}
	
	bool ok = true;
	REP(i, N) if (ans[i] == A[i]) ok = false;
	if (!ok) {
		return {};
	}
	
	return ans;
}

int main() {
	cin >> N;
	A.resize(N);
	B.resize(N);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, N) scanf("%d", &B[i]);
	
	REP(i, N) mm[A[i]]++;
	REP(i, N) mm[B[i]]++;
	for (auto p : mm) {
		if (p.se > N) {
			puts("No");
			return 0;
		}
	}
	
	auto ans = solve();
	if (ans.empty()) {
		ans = solve2();
	}
	
	if (ans.empty()) puts("No");
	else {
		puts("Yes");
		REP(i, N) printf("%d%c", ans[i], i + 1 == N ? '\n': ' ');
	}
	return 0;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import qualified Data.Set as Set
import Data.IORef
import Control.Monad

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  itemsRef <- newIORef Set.empty :: IO (IORef (Set.Set String))
  forM_ [1..n] $ \i -> do
    str <- getLine
    modifyIORef' itemsRef (Set.insert str)
  items <- readIORef itemsRef
  print $ Set.size items


Measured memory_bytes: 148084
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,d,ans;
	cin>>a>>b>>c>>d;
	ans=max(b*d,a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int h = sc.NextInt();
        int w = sc.NextInt();

        bool[,] black = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            string str = sc.Next();
            for (int j = 0; j < w; j++)
            {
                black[i, j] = str[j] == '#';
            }
        }

        int[] x = new int[] { 0, 0, -1, 1 };
        int[] y = new int[] { 1, -1, 0, 0 };

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (!black[i, j])
                {
                    continue;
                }
                int count = 0;
                for (int k = 0; k < 4; k++)
                {
                    if (i + x[k] < 0 || i + x[k] >= h || j + y[k] < 0 || j + y[k] >= w)
                    {
                        continue;
                    }
                    if (black[i + x[k], j + y[k]])
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }

        Console.WriteLine("Yes");
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 i,o,t,j,l,s,z;
  cin >> i >> o >> t >> j >> l >> s >> z;
  int32 ans = i / 2 * 2 + o + j / 2 * 2 + l / 2 * 2;
  int32 ans2 = 0;
  if(i > 0 && j > 0 && l > 0){
    ans2 = 3;
    i--;j--;l--;
    ans2 += i / 2 * 2 + o + j / 2 * 2 + l / 2 * 2;
  }
  ANS(max(ans,ans2));
  return 0;
}

Measured memory_bytes: 3636
S=input()
months=['01','02','03','04','05','06','07','08','09','10','11','12']

if S[0:2] in months and S[2:4] in months:
    print('AMBIGUOUS')
elif S[0:2] in months:
    print('MMYY')
elif S[2:4] in months:
    print('YYMM')
else:
    print('NA')

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

int main() {
  int N;
  cin >> N;

  vector<vector<int>> xs(N), ys(N);
  rep(i, N) {
    int A;
    cin >> A;
    xs[i].resize(A), ys[i].resize(A);
    rep(j, A) cin >> xs[i][j] >> ys[i][j];
  }

  int cnt = 0;
  rep(i, 1 << (N + 1)) {
    vector<bool> a(N, true), b(N, true);
    rep(j, N) if (i & 1 << j) a[j] = b[j] = false;

    bool flag = true;
    rep(j, N) {
      auto& x = xs[j];
      auto& y = ys[j];
      rep(k, x.size()) {
        if (b[j]) {
          int p = x[k] - 1;
          bool q = (y[k] == 1) ? true : false;
          a[p] = a[p] && q;
          if (b[p] != q) {
            flag = false;
            break;
          }
        }
      }
    }
    if (!flag)
      continue;
    int tmp = 0;
    rep(i, N) if (a[i]) tmp++;
    bool f = true;
    rep(i, N) if (a[i] != b[i]) f = false;
    if (f)
      cnt = max(cnt, tmp);
  }

  cout << cnt << endl;
}

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

#define ll long long int
#define MOD 1000000007

int main(){

  string S;
  cin >> S;
  string T;
  cin >> T;

  ll ans = 0;

  for(int i=0;i<S.length();i++){
    if (S[i] != T[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	cin.ignore();
	while(n--) 
	{
		string in;
		int pos;
		getline(cin,in);
		pos=in.find("Hoshino");
		while(pos!=-1) 
		{
			in[pos]='H'; in[pos+1]='o'; in[pos+2]='s';
			in[pos+3]='h'; in[pos+4]='i'; in[pos+5]='n'; in[pos+6]='a';
			pos=in.find("Hoshino");
		}
		cout<<in<<endl;
	}
  return 0;
}

Measured memory_bytes: 1212
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B
s = S()
for i in range(len(s)):
    if not i%2:
        print(s[i],end = "")
print()
#C
"""
n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
    d[i+1] += 1
    d[i-1] += 1
d = list(d.values())
print(max(d))
"""

#D
"""
n = I()
a = LI()
k = 0
for i in range(n-1):
    if a[i] == i+1:
        x = a[i]
        a[i] = a[i+1]
        a[i+1] = x
        k += 1
if a[n-1] == n:k += 1
print(k)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 51440
import sys


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = self.__dot(node[i], c)
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


N, Q = map(int, input().split())
query = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]

flagH = [N - 1] * N
flagW = [N - 1] * N

stH = SegmentTree([N - 1] * N, min, N - 1)
stW = SegmentTree([N - 1] * N, min, N - 1)

cnt = 0
for t, x in query:
    if t == 1:
        flagX, flagY = flagW, flagH
        stX, stY = stW, stH
    else:
        flagX, flagY = flagH, flagW
        stX, stY = stH, stW

    cnt += max(0, min(stX.get(x - 1, N), flagX[x - 1]) - 1)
    flagX[x - 1] = 0
    stY.update(stX.get(x - 1, N), x - 1)

print(pow(N - 2, 2) - cnt)


Measured memory_bytes: 119680
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 main() {
    ll n,p;
    cin >> n >> p;
    const int mod = p;
    string s;
    cin >> s;
    ll ans = 0;
    if(p==2 || p==5) {
        rep(i,n) if((s[n-1-i]-'0')%p == 0) ans += n-i; 
        cout << ans << endl;
        return 0;   
    }
    ll cur = 0;
    ll fac = 1;
    vector<int>d(n+1);  
    for(int i = n-1;i>=0;i--) {
        cur = (s[i]-'0')*fac;
        cur %= mod;
        d[i] = (d[i+1] + cur)%mod;
        fac = fac*10%mod;
    }
    vector<int>cnt(p);
    for(int i = n;i>=0;i--) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
}
    




Measured memory_bytes: 4440
#include<bits/stdc++.h>
#define mx 100005
using namespace std;

string s;
long long a, b;

int main(){
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    a = a*2 + b;
   b = b*10 + (s[i] - '0' << i);
  }
  printf("%lld\n", a + b);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		int xa = a - x;
		int xb = b - x;
		if (xa < 0) {
			xa = -xa;
		}
		if (xb < 0) {
			xb = -xb;
		}
		if (xa < xb) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}
}

Measured memory_bytes: 23508
N = int(input())
D,X = map(int,input().split())
A = [int(input()) for _ in range(N)]
choco = X
for a in A:
    for i in range(D+1):
        if i*a+1 >D:
            if i==0:
                choco += 1
            else:
                choco += i
            break
print(choco)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
const  int maxx=1e5+100;
const int INF=99999999;
const int MOD=1e9+7;
typedef long long ll;
int n;
struct node
{
    int l,r,nextt;
    ll dis;
}s[maxx*2];
ll d[maxx];
int h[maxx];
int cnt;
void add(int a,int b,ll c)
{
    s[cnt].l=a;
    s[cnt].r=b;
    s[cnt].dis=c;
    s[cnt].nextt=h[a];
    h[a]=cnt++;
}
void dfs(int k,int dd)
{
    for(int i=h[k]; i!=-1; i=s[i].nextt){
        int v=s[i].r;
        if(v==dd)  continue;
        d[v]=d[k]+s[i].dis;
        dfs(v,k);
    }
}
int main()
{
    scanf("%d",&n);
    int a,b;
    ll c;
    cnt=0;
    memset(h,-1,sizeof(h));
    memset(d,0,sizeof(d));
    for(int i=0; i<n-1; i++){
        scanf("%d%d%lld",&a,&b,&c);
        add(a,b,c);
        add(b,a,c);
    }
    int m,k;
    scanf("%d%d",&m,&k);
    dfs(k,-1);
    while(m--){
        scanf("%d%d",&a,&b);
        printf("%lld\n",d[a]+d[b]);
    }
    return 0;
}
//int cnt,head[maxx];
//ll d[maxx];
//struct Edge
//{
//    int l,r,nxt;
//    ll dis;
//}e[maxx*2];
//
//void addedge(int u,int v,ll w)
//{
//    e[cnt].l=u;
//    e[cnt].r=v;
//    e[cnt].dis=w;
//    e[cnt].nxt=head[u];
//    head[u]=cnt++;
//}
//
//void dfs(int u,int fa)
//{
//    for(int i=head[u];i!=-1;i=e[i].nxt)
//    {
//        int to=e[i].r;
//        if(to==fa) continue;
//        d[to]=d[u]+e[i].dis;
//        dfs(to,u);
//    }
//}
//
//int main()
//{
//    int n;
//    scanf("%d",&n);
//        cnt=0;
//        memset(head,-1,sizeof(head));
//        memset(d,0,sizeof(d));
//        int a,b;
//        ll c;
//        for(int i=1;i<=n-1;i++)
//        {
//            scanf("%d%d%lld",&a,&b,&c);
//            addedge(a,b,c);
//            addedge(b,a,c);
//        }
//        int m,k;
//        scanf("%d%d",&m,&k);
//        dfs(k,-1);
//        int x,y;
//        while(m--)
//        {
//            scanf("%d%d",&x,&y);
//            cout<<d[x]+d[y]<<endl;
//            //printf("%lld\n",d[x]+d[y]);
//        }
//    return 0;
//}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

int main()
{
    ll n;
    cin >> n;

    cout << (double)((n + 2 - 1) / 2) / n << endl;

    return 0;
}

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

int main(){
  int a,b; cin>>a>>b;
  int ans=max(2*a-1,2*b-1);
  ans=max(ans,a+b);
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define SZ(v)      ((int)(v).size())
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){//Refering other editorials.
	int h,w;
	int m;
	cin>>h>>w>>m;
	
	set<pii> st;//爆破予定場所の集合.
	vi cnt(h,0),cntt(w,0);//それぞれのx,y軸上にある爆破予定場所の数.
	REP(i,m){
		int y,x;
		cin>>y>>x;
		y--, x--;
		
		st.insert(pii(y,x));
		cnt[y]++;
		cntt[x]++;
	}
	
	vi py,px;//爆破座標候補.
	int mxy=0,mxx=0;//それぞれの最大値.
	REP(i,h){
		if(cnt[i]==mxy) py.push_back(i);
		else if(cnt[i]>mxy){
			py=vi({i});
			mxy=cnt[i];
		}
	}
	REP(i,w){
		if(cntt[i]==mxx) px.push_back(i);
		else if(cntt[i]>mxx){
			px=vi({i});
			mxx=cntt[i];
		}
	}
	
	bool jud=false;//最大候補の行と列が重なるとこに候補地がないかどうか.
	for(auto i:py)for(auto j:px){
		if(st.find(pii(i,j))==st.end()){
			jud=true;
			goto Exit;
		}
	}
	
Exit:
	cout<<mxy+mxx-(jud?0:1)<<endl;
	return 0;
}

Measured memory_bytes: 23824
#include <iostream>
#include <queue>
using namespace std;
int unko[100005];
int main(){
	int N;
	cin >> N;
    queue<int>Q;
    Q.push(0);
    while(unko[N]==0){
        int n = Q.front();
        Q.pop();
        if(n+1<=N){
            if(unko[n+1]==0){
                unko[n+1] = unko[n] + 1;
                Q.push(n+1);
            }
        }
        for(int i = 6; n+i<=N;i*=6){
            if(unko[n+i]==0){
                unko[n+i] = unko[n] + 1;
                Q.push(n+i);
            }
        }
        for(int i = 9; n+i<=N;i*=9){
            if(unko[n+i]==0){
                unko[n+i] = unko[n] + 1;
                Q.push(n+i);
            }
        }
    }
    cout<<unko[N]<<endl;
    return 0;
    /*
    int chinpo = 1;
    
    int min = 0;
    int minChinpo = 0;
    
    int depth = 0;
    
    for(;;){
        
        unko[0] = 1;
        
        while(pow(6,j) < N){
            unko[chinpo] = pow(6,j);
            chinpo ++;
            j++;
        } 
        
        
       // std::cout <<unko[chinpo - 1] << std::endl;
        
        while(pow(9,k) < N){
            unko[chinpo] = pow(9,k);
            chinpo ++;
            k++;
        } 
        
        //chinpo--;
        
       // std::cout <<unko[chinpo - 1] << std::endl;
        
        min = N - unko[0];
        minChinpo = 0;
         
        for(int q = 0; q < chinpo; q++){
            if(min > N - unko[q]){
                min = N - unko[q];
                minChinpo = q;
            }
        }
        
        N = N - unko[minChinpo];
        //std::cout << N << std::endl;
        
        depth++;
        
        if(N == 0){
            std::cout << depth << std::endl;
            return 0;
        }
        
        for(int  q = 0; q < chinpo; q++ ){
            unko[q] = -1;
        }
        
        chinpo = 1;
        
        j = 1;
        k = 1;
      
    } 
    */
    return 0;

}

Measured memory_bytes: 768