akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, input().split()))
    left = [0 for _ in range(n + 1)]
    right = [0 for _ in range(n + 1)]

    # KeyInsight
    # 一つを書き換える→消すと同じ意味
    # 最大公約数の交換則
    # 左右から最大公約数を前計算
    # See:
    # https://www.youtube.com/watch?v=8lm8o8L9Bmw
    # http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
    for i in range(n):
        left[i + 1] = gcd(left[i], a[i])

    for i in range(n - 1, -1, -1):
        right[i] = gcd(right[i + 1], a[i])

    ans = 0

    for i in range(n):
        l = left[i]
        r = right[i + 1]
        ans = max(ans, gcd(l, r))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16580
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define MP make_pair 
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
typedef pair<int, int> PII; 
const double eps = 1e-12;
const double PI = acos(-1);
const LL INFF = (LL)1e18;
const int INF = (int)1e9;
const int mod = 998244353;
const int MAX = (int)1e5+7;
PII st[MAX];
bitset<MAX>ck;
priority_queue<PII, vector<PII>, greater<PII>>pqr;
priority_queue<PII>pql;
int main(void){
	DRI(n);
	rep1(i, 1, n+1){
		scanf("%d %d", &st[i].F, &st[i].S);
		pql.push(MP(st[i].F, i));
		pqr.push(MP(st[i].S, i));
	}
	int cp = 0;
	LL ans1 = 0;
	rep1(i, 1, n+1){
		while(ck[ pql.top().S ]) pql.pop();
		while(ck[ pqr.top().S ]) pqr.pop();
		if(cp < pql.top().F){
			int p = pql.top().S; pql.pop();
			ck[p] = 1;
			ans1 += st[p].F - cp;
			cp = st[p].F;
		}
		else if(cp > pqr.top().F){
			int p = pqr.top().S; pqr.pop();
			ck[p] = 1;
			ans1 += cp - st[p].S;
			cp = st[p].S;
		}
		else break;
	}
	ans1 += abs(cp);
	LL ans = ans1;
	ck.reset();
	while(!pql.empty()) pql.pop();
	while(!pqr.empty()) pqr.pop();
	rep1(i, 1, n+1){
		pql.push(MP(st[i].F, i));
		pqr.push(MP(st[i].S, i));
	}
	cp = 0;
	ans1 = 0;
	rep1(i, 1, n+1){
		while(ck[ pql.top().S ]) pql.pop();
		while(ck[ pqr.top().S ]) pqr.pop();
		if(cp > pqr.top().F){
			int p = pqr.top().S; pqr.pop();
			ck[p] = 1;
			ans1 += cp - st[p].S;
			cp = st[p].S;
		}
		else if(cp < pql.top().F){
			int p = pql.top().S; pql.pop();
			ck[p] = 1;
			ans1 += st[p].F - cp;
			cp = st[p].F;
		}
		else break;
	}
	ans1 += abs(cp);
	ans = max(ans, ans1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2796
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import ceil


def check(s):
    cnt = 0
    for hh in h:
        if s * b < hh:
            cnt += ceil((hh - s * b) / (a - b))
    return cnt <= s


n, a, b, *h = map(int, read().split())
low = 0
high = 10 ** 18
while low + 1 < high:
    mid = (low + high) // 2
    if check(mid):
        high = mid
    else:
        low = mid
print(high)


Measured memory_bytes: 13064
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        #print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        #print(que,"k")    

    print("NO")
#%%submit!
resolve()

Measured memory_bytes: 4308
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;

const int maxn = 110;
int n, p, x, a, b;
int main(){
	scanf("%d%d", &n, &p);
	for(int i = 1;i <= n;++i){
		scanf("%d", &x);
		if(x & 1)a++;
		else b++;
	}
	if(a == 0){
		if(p == 0)printf("%lld\n", 1LL << n);
		else puts("0");
	}
	else printf("%lld\n", 1LL << (n - 1));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long ans=0;
  string s;
  cin >> s;
  for(int i=0; i<(1<<(s.size()-1)); i++) {
    long long cnt=s[0]-'0';
    for(int j=0; j<s.size()-1; j++) {
      if(i&(1<<j)) {
        ans+=cnt;
        cnt=0;
      }
      cnt=cnt*10+s[j+1]-'0';
    }
    ans+=cnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N=int(input())

F=[]
for i in range(N):
    f=list(map(int, input().split()))
    F.append(f)

P=[]
for i in range(N):
    p=list(map(int, input().split()))
    P.append(p)

F=np.array(F)
P=np.array(P)

ans=-np.inf

for b in range(1,2**10):
    now=0
    L=np.zeros(N)
    for i in range(10):
        if b>>i&1==1:
            L+=F[:,i]
    for i in range(N):
        now+=P[i,int(L[i])]
    ans=max(ans, now)

print(ans)

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

using namespace std;

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

	int n, m;
	cin >> n >> m;
	vector<vector<int>> e(n, vector<int>(n, 1e9));
	vector<vector<int>> d(n, vector<int>(n, -1));
	for (int i = 0; i < n; i++) {
		e[i][i] = 0;
	}
	for (int i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		d[u][v] = d[v][u] = e[u][v] = e[v][u] = w;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
			}
		}
	}
	int res = m;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (d[i][j] == e[i][j]) {
				res--;
			}
		}
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String W = sc.nextLine();

		ArrayList<String> T = new ArrayList<String>();
		String[] input;
		while (EndDecision(input = sc.nextLine().split("[\\s]+"))) {
			for (String str : input) {
				T.add(str.toLowerCase());
			}
		}

		int count = 0;
		for (String str : T) {
			if (W.equals(str)) {
				count++;
			}
		}

		System.out.println(count);

	}

	public static boolean EndDecision(String[] array) {
		if (array[0].equals("END_OF_TEXT")) {
			return false;
		} else {
			return true;
		}

	}

}



Measured memory_bytes: 26104
#include <iostream>
#define llint long long

using namespace std;

llint n, W;
llint w[105], v[105];
llint dp[105][100005];

int main(void)
{
  cin >> n >> W;
  for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= W; j++){
      dp[i][j] = -1e18;
    }
  }
  dp[0][0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= W; j++){
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      if(j+w[i+1] <= W) dp[i+1][j+w[i+1]] = max(dp[i+1][j+w[i+1]], dp[i][j] + v[i+1]);
    }
  }
  llint ans = 0;
  for(int i = 0; i <= W; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80128
#include<iostream>
using namespace std;
int main()
{
     int n;
     cin>>n;int p=0,q=0;
     for(int i=1;i<10;i++)
      {
      	for(int j=1;j<10;j++)
      	{
      		if(n==i*j)
      		{
			  cout<<"Yes";q=q+1;
			  break;
      	    }
		  }
		     if(q==1)
      	    break;
	
	  }
	  if(q!=1)
	  cout<<"No";
	  return 0;
	  
}

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

int main()
{
  double g;
  cin >> g;
  double t = g / 3;
  double ans = t * t * t;
  printf("%.6f\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int ctoi(char);

//既にその頂点を使用しているかを格納するリスト
vector<int> used;

//接続状況を格納するリスト
vector<vector<int>> connect;

int N, M;

int dfs(int now, int depth)
{
    //使用済みであればreturn
    if(used[now])
    {
        return 0;
    }

    //depthがNであれば有効なパスであるから1を返す
    if(depth == N)
    {
        return 1;
    }
    //使用済みフラグを立てる
    used[now] = 1;
    int ans = 0;

    //全部の遷移先をチェックする
    for (int i=0; i<N; i++)
    {
        //nowから繋がっている頂点であれば, 遷移を移す
        if (connect[now][i])
        {
            ans += dfs(i, depth + 1);
        }
    }
    used[now] = 0;
    return ans;

}

int main()
{
    cin >> N >> M;
    vector<int> a(M), b(M);

    rep(i, M)
    {
        cin >> a.at(i) >> b.at(i);
        //1から始まると使いにくいので-1した数を格納するようにする
        a.at(i) -= 1;
        b.at(i) -= 1;
    }
    used = vector<int>(N, 0);
    connect = vector<vector<int>>(N, vector<int>(N, 0));
    rep(i, M)
    {
        connect.at(a.at(i)).at(b.at(i)) = 1;
        connect.at(b.at(i)).at(a.at(i)) = 1;
    }
    //0番から始まるパスの種類を列挙し, 出力する
    cout << dfs(0, 1) <<endl;

}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}


Measured memory_bytes: 256
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($X,$Y) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

$res = getS($X);
$res += getS($Y);
if ($X==1 && $Y==1) $res+=400000;
printf("%d\n",$res);

function getS($x) {
  $yen=0;
switch($x) {
  case 1:
    $yen = 300000;
    break;
  case 2:
    $yen = 200000;
    break;
  case 3:
    $yen = 100000;
    break;
}
return $yen;
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}

  return 0;
}


Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
using   ld =          long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)2e5+5;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    string s;
    ll ans=0;
    cin>>s;
    rep(i,SZ(s))
    {
        ans+=s[i]-'0';
        ans%=9;
    }
    if(ans==0)cout<<"Yes"<<nl;
    else cout<<"No"<<nl;
    return 0;
}


Measured memory_bytes: 3780
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var mae = myconv(input[0],4)[0];
  var ato = myconv(input[1],4)[0];
  if(mae != ato){
     myout("1");
     }else{
     myout("0");
     }
}

Main(myin());


Measured memory_bytes: 22076
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s;
    cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());
    vector<int> S(n + 1);
    S[0] = 0;
    int mul = 1;
    constexpr int m = 2019;
    for(int i = 0; i < n; ++i){
        int x = s[i] - '0';
        x = x * mul % m;
        mul = mul * 10 % m;
        S[i + 1] = (S[i] + x) % m;
    }
    vector<int> c(m, 0);
    ll ans = 0;
    for(int i = 0; i <= n; ++i){
        ans += c[S[i]]++;
    }
    cout << ans << endl;
}

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

int main(){
    int a,b;cin>>a>>b;
    double a1 = a*12.5;
    double a2 = (a+1)*12.5;
    double b1 = b*10.0;
    double b2 = (b+1)*10.0;
    int ans;
    if(a % 2 == 0){
        //aが偶数ならa1が整数になるので.
        ans = max(a1,b1);
    }else{
        //奇数なら小数点切り上げが必要.
        ans = ( (int)(a1+1) < b1 ? b1:a1+1);
    }
    if(ans < min(a2,b2))cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int n,B[100005],a[100005],len;
int main()
{
	  fast;
    cin>>n;
    for (int i=1;i<=n;i++)
       cin>>a[i];
    B[1]=-a[1],len=1;
    for (int i=2;i<=n;i++)
    {
        if (-a[i]>=B[len])
				   B[++len]=-a[i];
        else
        {
            int pos=upper_bound(B+1,B+len,-a[i])-B;
            B[pos]=-a[i];
        }
    }
    cout<<len<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
    int a, b;
    cin >> a >> b;
    if (a >= 10 || b >= 10) {
        cout << -1 << endl;
        return 0;
    }
    cout << a*b << endl;
}


Measured memory_bytes: 256
import java.util.*;

/**
 * A
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
            System.out.print(array[i]);
            if(i<array.length-1) {
                System.out.print(" ");
            }
        }

        System.out.println();

        sc.close();

        for(int i=1; i<array.length; i++) {
            
            int key = array[i];
            /* insert A[i] into the sorted sequence A[0,...,j-1] */
            int j = i-1;
            while(j>=0 && array[j]>key) {
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = key;

            for(int num=0; num<array.length; num++) {
                System.out.print(array[num]);
                if(num != array.length-1) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                }
            }
        }

    }
}


Measured memory_bytes: 34456
#include <cstdio>
#include <limits>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

struct S {
    string F;
    int z;
    int t;
    S(const string& F, int z, int t) : F(F), z(z), t(t) {}
};

map<string, int> ANSWER;
void init() {
    string init = "01234567";
    ANSWER[init] = 0;
    queue<S> Q;
    Q.push(S(init, 0, 0));
    vector<int> d[8];
    for (int i = 0; i < 8; i++) {
        if (i % 4 != 0) d[i].push_back(-1);
        if (i % 4 != 3) d[i].push_back(1);
        if (i / 4 == 0) d[i].push_back(4);
        else d[i].push_back(-4);
    }
    while (!Q.empty()) {
        S s = Q.front(); Q.pop();
        int z = s.z;
        int t = s.t;
        for (int i = 0; i < d[z].size(); i++) {
            int nz = z + d[z][i];
            if (nz < 0 || nz >= 8) continue;
            string nF = s.F;
            swap(nF[z], nF[nz]);
            if (ANSWER.count(nF)) continue;
            ANSWER[nF] = t + 1;
            Q.push(S(nF, nz, t + 1));
        }
    }
}

string F;
bool input() {
    F = "";
    for (int i = 0; i < 8; i++) {
        int x; cin >> x;
        if (cin.fail()) return false;
        F.push_back(x + '0');
    }
    //cin.ignore(numeric_limits<streamsize>::max(), '\n');
    return true;
}

void solve() {
    cout << ANSWER[F] << endl;
}

int main() {
    init();
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3464
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int a[N], ans = 1000000007;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	for(int i = 1; i <= 3; i++){scanf("%d",a+i);}
	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= 3; j++)
			for(int k = 1; k <= 3; k++)
				if(i != j and k != j and k != i){
					ans = min(ans, abs(a[i] - a[j]) + abs(a[j] - a[k]));
				}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int a, b, c, i, s = 0;
	scanf("%d%d%d", &a, &b, &c);
	for(i = a; i <= b; i++)
	{
		if (c % i == 0) s++;
	}
	printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 2112
#include <algorithm> //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vo;
vector<ll> ve;

int main()
{
  ll n;
  cin >> n;
  int cont = 0;
  int prev = -1,tmp;
  int ret = 0;

  REP(i, n){
    cin >> tmp;
    if(prev == tmp)cont++;
    else{
     ret += cont/2;
     cont = 1;
    }
    prev = tmp;
  }
  ret += cont / 2;
  cont = 1;

  cout << ret << 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=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    cin >> s;
    int n = sz(s);
    rep(i, n) rep(j, n) if (i <= j) {
        string now = s.substr(0, i) + s.substr(j, n-j);
        if (now == "keyence") {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}


Measured memory_bytes: 3608
n = int(input())
hn = [int(x) for x in input().split()]

cnt = 0
prev_h = 0

cnt_n = [0] * n

for h in range(1, 101):
  if hn[0] >= h:
    cnt_n[0] = cnt_n[n-1] + 1
  else:
    cnt_n[0] = cnt_n[n-1]
  for i in range(1, n):
    if hn[i] >= h:
      if hn[i - 1] >= h:
        cnt_n[i] = cnt_n[i-1]
      else:
        cnt_n[i] = cnt_n[i-1]+1
    else:
      cnt_n[i] = cnt_n[i-1]

print(max(cnt_n))


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

int main()
{
    long long int a,b,c;
    cin>>a>>b>>c;
    if(4*a*b<(c-a-b)*(c-a-b)&&c>a+b)
        cout<<"Yes";
    else 
        cout<<"No";
    
}

Measured memory_bytes: 256
n=int(input())
nt,nx,ny=0,0,0

for i in range(n):
    t,x,y=map(int,input().split())
    if (abs(nx-x)+abs(ny-y)) > t-nt:
        print("No")
        exit()
    else:
        t2=t-nt-abs(nx-x)
        if abs(ny-y)%2==0 and t2%2==0:
            nt,nx,ny=t,x,y
        elif abs(ny-y)%2==1 and t2%2==1:
            nt,nx,ny=t,x,y
        else:
            print("No")
            exit()

print("Yes")

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

struct state {
    int y, x, dir;
    state(int y, int x, int dir) : y(y), x(x), dir(dir) {}
};

int main() {
    // south, east, north, west 
    constexpr int dx[4] = {0, 1, 0, -1};
    constexpr int dy[4] = {1, 0, -1, 0};
    constexpr int inf = 1e9;

    int H, W, N;
    while(cin >> H >> W >> N, H) {
        string s;
        cin >> s;
        vector<string> fld(H);
        int sy, sx, gy, gx;
        for(int i = 0; i < H; ++i) {
            cin >> fld[i];
            for(int j = 0; j < W; ++j) {
                if(fld[i][j] == 'S') {
                    sy = i;
                    sx = j;
                }
                if(fld[i][j] == 'G') {
                    gy = i;
                    gx = j;
                }
            }
        }

        vector<vector<int>> next_idx(N + 1, vector<int>(4, inf));
        {
            int cur_dir = 2;
            for(int i = 0; i < N; ++i) {
                (cur_dir += (s[i] == 'L' ? 1 : 3)) %= 4;
            }
            for(int i = N - 1; i >= 0; --i) {
                next_idx[i] = next_idx[i + 1];
                next_idx[i][cur_dir] = i;
                (cur_dir += s[i] == 'L' ? 3 : 1) %= 4;
            }
        }

        vector<vector<vector<int>>> dist(H, vector<vector<int>>(W, vector<int>(4, inf)));
        queue<state> que;
        que.emplace(sy, sx, 2);
        dist[sy][sx][2] = 0;
        while(!que.empty()) {
            auto now = que.front();
            que.pop();

            // turn
            const int now_op_idx = dist[now.y][now.x][now.dir];
            for(int ndir = 0; ndir < 4; ++ndir) {
                const int next_op_idx = next_idx[now_op_idx][ndir] + 1;
                if(dist[now.y][now.x][ndir] > next_op_idx) {
                    dist[now.y][now.x][ndir] = next_op_idx;
                    que.emplace(now.y, now.x, ndir);
                }
            }

            // forward
            const int ny = now.y + dy[now.dir];
            const int nx = now.x + dx[now.dir];
            if(ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
            if(fld[ny][nx] == '#') continue;
            if(dist[ny][nx][now.dir] > dist[now.y][now.x][now.dir]) {
                dist[ny][nx][now.dir] = dist[now.y][now.x][now.dir];
                que.emplace(ny, nx, now.dir);
            }
        }

        if(*min_element(begin(dist[gy][gx]), end(dist[gy][gx])) != inf) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 59260
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned short int uns;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define pb push_back
#define mp make_pair
#define pf push_front
#define fi first
#define se second
#define sqr(a) ((a) * (a))
#define pi 3.1415926535897932
#define eps 0.0000001
#define mod 1000000007
#define vii vector<int>
#define vll vector<ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define vpp vector<pii>

using namespace std;

int n, m, k;

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    if (a + b >= x && a <= x)
        cout << "YES";
    else
        cout << "NO";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	char b;

	cin >> b;

	switch (b) {
	case 'A': cout << 'T' << endl; break;
	case 'T': cout << 'A' << endl; break;
	case 'C': cout << 'G' << endl; break;
	case 'G': cout << 'C' << endl; break;
	}

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#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>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}
int p[100000]={0};
bool b[100000]={false};

void pri()
{
  

  rep(i,2,100000)
  for(int j=i+i;j<100000;j+=i)b[j]=true;

    rep(i,2,100000)if(b[i]==false)p[i]=1;
}



int solve( ){

int n;

string a;
cin>>a;


int x=0;

int ans=0,ans1=0,mn=hell;
rep(i,0,a.size())
{
  if(a[i]-'0'==i%2)ans++;
  if(a[i]-'0'==(i+1)%2)ans1++;
}
cout<<min(ans,ans1);
return 0;
}



signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);
  
 // pri();
  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;
    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
   //cout << "Processor time taken is "
     // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}



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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    long color_change = 0;
    for(int i=0; i < N-1; i++){
        if(S.at(i) != S.at(i+1)){
            color_change ++;
        }
    }
    cout << color_change + 1 << endl;
    return 0;


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b)     for(int i=a;i>=b;--i)
#define init(a, x) memset(a,x,sizeof(a))
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))

ll md(ll x1, ll y1, ll x2, ll y2)
{
	return abs(x1-x2) + abs(y1-y2);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	ll m1, m2, m3, m4;
    	// m1 = m2 = m3 = m4 = -1e10;
    	// m2 = m4 = 1e10;
    	ll x1,x2,x3,x4,y1,y2,y3,y4;
    	cin>>a>>b;
    	x1 = x2 = x3 = x4 = a;
    	y1 = y2 = y3 = y4 = b;
    	m1 = m2 = a+b;
    	m3 = m4 = a-b;
    	for(int i=1;i<n;i++)
    	{
    		cin>>a>>b;
    		if(a+b>m1)
    		{
    			m1 = a+b;
    			x1 = a;
    			y1 = b;
    		}
    		else if(a+b<m2)
    		{
    			m2 = a+b;
    			x2 = a;
    			y2 = b;
    		}
    		else if(a-b>m3)
    		{
    			m3 = a-b;
    			x3 = a;
    			y3 = b;
    		}
    		else if(a-b<m4)
    		{
    			m4 = a-b;
    			x4 = a;
    			y4 = b;
    		}
    	}
    	ll ans = md(x1,y1,x2,y2);
    	ans = max(ans, md(x1,y1,x3,y3));
    	ans = max(ans, md(x1,y1,x4,y4));
    	ans = max(ans, md(x2,y2,x3,y3));
    	ans = max(ans, md(x2,y2,x4,y4));
    	ans = max(ans, md(x4,y4,x3,y3));
    	cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
while True:
    try:
        d = input()
        D = list(d)
        J = 0
        I = 0
        for i in range(len(D)-2):
            if D[i] == 'J' and D[i+1] == 'O' and D[i+2] == 'I':
                J += 1
            if D[i] == 'I' and D[i+1] == 'O' and D[i+2] == 'I':
                I += 1
        print(J)
        print(I)

    except EOFError:
        break


Measured memory_bytes: 5596
import heapq
n,q = map(int,input().split())
Q = [[] for i in range(n)]

for i in range(q):
    query = [k for k in map(int,input().split())]

    if query[0] == 0:
       heapq.heappush(Q[query[1]],-query[2])
    elif query[0] == 1:
        try:
            print(-Q[query[1]][0])
        except:
            pass
    elif query[0] == 2:
        try:
            heapq.heappop(Q[query[1]])
        except:
            pass



Measured memory_bytes: 13312
#include<stdio.h>
int main()
{
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r<=W&&x-r>=0&&y+r<=H&&y-r>=0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------
#define bitrep(i, n)     for(ll i=0; i<(ll) (1<<(n)); i++)
#define bis(i, j)        i & (1<<(j))

int main(void) {
  int h, w, num;
  cin >> h >> w >> num;
  arrst(c, h);

  int ans=0;
  bitrep(i,h){
    bitrep(j,w){
      vecst cp = c;
      rep(k,h){
        if(bis(i,k)){
          rep(_,w){
            cp[k][_]='.';
          }
        }
      }
      rep(k,w){
        if(bis(j,k)){
          rep(_,h){
            cp[_][k]='.';
          }
        }
      }

      int tmp=0;
      rep(a,h){
        rep(b,w){
          if(cp[a][b]=='#') tmp++;
        }
      }
      if(tmp==num) ans++;
    }
  }
  prt(ans);
}


Measured memory_bytes: 3632
(H, W) = map(int, input().split())
a = []
for i in range(H):
    a.append(list(map(int, input().split())))
#print("a: ")
#print(a)

odd_flag = []
for i in range(len(a)):
    odd_flag.append(list())
    for j in range(len(a[i])):
        if a[i][j]%2 != 0:
            odd_flag[i].append(True)
        else:
            odd_flag[i].append(False)
#print("odd_flag: ")
#print(odd_flag)

odd_sum = 0
for i in range(len(odd_flag)):
    odd_sum += odd_flag[i].count(True)
#print(odd_sum)

def move(h, w):
    if h%2 == 0:
        if w == W-1:
            return (h+1, w)
        else:
            return (h, w+1)
    else:
        if w == 0:
            return (h+1, w)
        else:
            return (h, w-1)

s_h = 0
s_w = 0
N = 0
ope_list = []
move_flag = False
while odd_sum >= 2:
    # 移動先到着
    if move_flag is True and odd_flag[s_h][s_w] is True:
        move_flag = False
        (s_h, s_w) = move(s_h, s_w)
        odd_sum -= 2
    # 移動中
    elif move_flag is True and odd_flag[s_h][s_w] is False:
        ope = ""
        ope += str(s_h+1) + " " + str(s_w+1) + " "
        (s_h, s_w) = move(s_h, s_w)
        ope += str(s_h+1) + " " + str(s_w+1) + "\n"
        ope_list.append(ope)
        N += 1
    # 移動すべきものなし
    elif move_flag is False and odd_flag[s_h][s_w] is False:
        (s_h, s_w) = move(s_h, s_w)
    # 移動元到着
    elif move_flag is False and odd_flag[s_h][s_w] is True:
        move_flag = True
        ope = ""
        ope += str(s_h+1) + " " + str(s_w+1) + " "
        (s_h, s_w) = move(s_h, s_w)
        ope += str(s_h+1) + " " + str(s_w+1) + "\n"
        ope_list.append(ope)
        N += 1

print(N)
for i in range(len(ope_list)):
    print(ope_list[i], end="")



Measured memory_bytes: 19188
#include <bits/stdc++.h>
#define pii pair<unsigned long long, unsigned long long>
#define fi first
#define se second
#define watch(x) cout << (#x) << " is " << (x) << endl;
using namespace std;

int main() {
    #define int unsigned long long
    int N, M;
    cin >> N >> M;

    int A[N+1];
    for(int i = 1; i <= N; i++) cin >> A[i];

    vector<pii> ops;
    ops.emplace_back(numeric_limits<int>::max(), 0);
    for(int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;
        ops.emplace_back(b, a);
    }

    sort(ops.rbegin(), ops.rend());
    sort(A+1, A+N+1);

    int pos = 1;
    int curOp = 1;

    while(curOp <= M && pos <= N) {
        int k = 1;
        while(k <= ops[curOp].se && pos <= N) {
            if(A[pos] < ops[curOp].fi) {
                k++;
                A[pos] = ops[curOp].fi;
            }
            pos++;
        }
        curOp++;
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
        ans += A[i];
    }

    cout << ans << endl;
}

/* 
3 2
4 4 3
2 4
1 5 
*/

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define pque(type) priority_queue<type,vector<type>,greater<type> >

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

  if(a<=x && x<= a+b) cout << "YES" << endl;
  else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int N,M;
string S,T;
int dp[2001][2001][2];
int ans=0;
int main(){
	scanf("%d%d",&N,&M);
	cin >> S >> T;
	/*
	for(int i=1;i<=N;i++){
		for(int j=1;j<=M;j++){
			if(i>=1&&S[i-1]=='I'){
				if(i>=1&&!(dp[i-1][j][0]&1))dp[i][j][0]=max(dp[i-1][j][0]+1,dp[i][j][0]);
				if(j>=1&&!(dp[i][j-1][1]&1))dp[i][j][0]=max(dp[i][j-1][0]+1,dp[i][j][0]);
				dp[i][j][0]=max(dp[i][j][0],1);
				ans=max(ans,dp[i][j][0]);
			}
			else {
				if(i>=1&&(dp[i-1][j][0]&1))dp[i][j][0]=max(dp[i-1][j][0]+1,dp[i][j][0]);
				if(j>=1&&(dp[i][j-1][1]&1))dp[i][j][0]=max(dp[i][j-1][0]+1,dp[i][j][0]);
				dp[i][j][0]=max(dp[i][j][0],0);
			}
			if(j>=1&&T[j-1]=='I'){
				if(i>=1&&!(dp[i-1][j][0]&1))dp[i][j][1]=max(dp[i-1][j][0]+1,dp[i][j][1]);
				if(j>=1&&!(dp[i][j-1][1]&1))dp[i][j][1]=max(dp[i][j-1][0]+1,dp[i][j][1]);
				dp[i][j][1]=max(dp[i][j][1],1);
				ans=max(ans,dp[i][j][1]);
			}
			else{
				if(i>=1&&(dp[i-1][j][0]&1))dp[i][j][1]=max(dp[i-1][j][0]+1,dp[i][j][1]);
				if(j>=1&&(dp[i][j-1][1]&1))dp[i][j][1]=max(dp[i][j-1][0]+1,dp[i][j][1]);
				dp[i][j][1]=max(dp[i][j][1],0);
			}
			//printf("%d %d:%d %d\n",i,j,dp[i][j][0],dp[i][j][1]);
		}
	}*/
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			if(i>=1&&S[i-1]=='I'){
				if(i>=1&&!(dp[i-1][j][0]&1))dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]+1);
				if(i>=1&&!(dp[i-1][j][1]&1))dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][1]+1);
				dp[i][j][0]=max(dp[i][j][0],1);
				ans=max(ans,dp[i][j][0]);
			}
			else if(i>=1){
				if(i>=1&&(dp[i-1][j][0]&1))dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][0]+1);
				if(i>=1&&(dp[i-1][j][1]&1))dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][1]+1);
				dp[i][j][0]=max(dp[i][j][0],0);
			}
			if(j>=1&&T[j-1]=='I'){
				if(i>=1&&!(dp[i][j-1][0]&1))dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+1);
				if(j>=1&&!(dp[i][j-1][1]&1))dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][1]+1);
				dp[i][j][1]=max(dp[i][j][1],1);
				ans=max(ans,dp[i][j][1]);
			}
			else if(j>=1){
				if(i>=1&&(dp[i][j-1][0]&1))dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+1);
				if(j>=1&&(dp[i][j-1][1]&1))dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][1]+1);
				dp[i][j][1]=max(dp[i][j][1],0);
			}
		}
		
	}
	/*
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			printf("%d ",dp[i][j][0]);
		}
		printf("\n");
	}
	printf("\n");
	for(int i=0;i<=N;i++){
		for(int j=0;j<=M;j++){
			printf("%d ",dp[i][j][1]);
		}
		printf("\n");
	}
	printf("\n");*/
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 34608
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const ll INF = 1LL << 60;
int former(ll pos,vector<ll>& v){
  return lower_bound(v.begin(),v.end(),pos) - v.begin() - 1;
}
int latter(ll pos,vector<ll>& v){
  return lower_bound(v.begin(),v.end(),pos) - v.begin();
}

int main(){
  int a,b,q; cin >> a >> b >> q;
  vector<ll> s(a),t(b);
  rep(i,a) cin >> s[i];rep(i,b) cin >> t[i];
  s.push_back(INF);s.push_back(-INF);sort(s.begin(),s.end());
  t.push_back(INF);t.push_back(-INF);sort(t.begin(),t.end());
  

  rep(i,q){
    ll x; cin >> x;
    ll res = INF;
    rep(j,2){//先にsに行く場合
      ll first = (j ? s[former(x,s)]:s[latter(x,s)]);
      rep(k,2){
        ll second = (k ? t[former(first,t)]:t[latter(first,t)]);  
        chmin(res,abs(x-first)+abs(first-second));
      }
    }
    rep(j,2){//先にtに行く場合
      ll first = (j ? t[former(x,t)]:t[latter(x,t)]);
      rep(k,2){
        ll second = (k ? s[former(first,s)]:s[latter(first,s)]);  
        chmin(res,abs(x-first)+abs(first-second));
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 2912
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    ans = a[N/2] - a[N/2 - 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<long double> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

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

    for(int i=0;i<n-1;i++){
        long double k=(v[i]+v[i+1])/2;
        v[i+1]=k;
    }
    cout<<setprecision(11)<<v[n-1];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[300030], finv[300030], inv[300030];
long long mod = 998244353;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 300030; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
	COMinit();
	long long n, a, b, k;
	cin >> n >> a >> b >> k;
	long long ans = 0;
	for (long long i = 0; i <= n; i++) {
		if ((k - i * a) % b == 0) {
			long long co = COM(n, i) * COM(n, (k - i * a) / b);
			co %= 998244353;
			ans += co;
			ans %= 998244353;
		}
	}
	cout << ans << endl;
}


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

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

    int res = 1;
    for (int i = 0; i < n; i++) {
        if (res * 2 <= res + k) {
            res *= 2;
        } else {
            res += k;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int LIS(vi in){//Longest Increasing Subsequence
	int n=in.size();
	int r=1;
	vi out(n+1,inf);
	rep(i,n){
		*lower_bound(all(out),in[i])=in[i];
	}
	return lower_bound(all(out),inf)-out.begin();
}
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	cout<<LIS(in)<<endl;
}

Measured memory_bytes: 2060
#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
use std::cmp::Ordering;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Rev(i64);

impl Ord for Rev {
    fn cmp(&self, other: &Rev) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl PartialOrd for Rev {
    fn partial_cmp(&self, other: &Rev) -> Option<Ordering> {
        Some(other.0.cmp(&self.0))
    }
}


pub struct Scanner<R> {
    reader: R,
}
impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf: String = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        buf.parse::<T>().ok().expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner { reader: stdin.lock() };

    let q: usize = sc.read();

    use std::collections::BinaryHeap;
    let mut lq = BinaryHeap::new();
    let mut rq = BinaryHeap::new();

    let mut lsum = 0i64;
    let mut rsum = 0;
    let mut bsum = 0;

    for _ in 0..q {
        let t:usize = sc.read();
        if t == 1 {
            let a:i64 = sc.read();
            let b:i64 = sc.read();
            bsum += b;

            if lq.len() == 0 {
                lq.push(a);
                lsum += a;
                continue;
            }

            if lq.len() > rq.len() {
                rsum += a;
                rq.push(Rev(a));
            } else {
                lsum += a;
                lq.push(a);
            }

            if let (Some(mut l), Some(Rev(mut r))) = (lq.pop(), rq.pop()) {
                lsum -= l;
                rsum -= r;

                if l > r {
                    std::mem::swap(&mut l, &mut r);
                }

                lq.push(l);
                lsum += l;
                rq.push(Rev(r));
                rsum += r;
            }
        } else {
            let x = *lq.peek().unwrap();
            println!(
                "{} {}",
                x,
                bsum + (rsum - rq.len() as i64 *x) + (lq.len() as i64 *x - lsum)
            );
        }
    }
}


Measured memory_bytes: 6908