akhauriyash/Code-Regression huggingface dataset:
import sys
from operator import itemgetter

N = int(input())
V = set()
for s in sys.stdin.readlines():
    x, y = map(int, s.split())
    V.add((x + y, x - y))

y_max = max(V, key=itemgetter(1))[1]
y_min = min(V, key=itemgetter(1))[1]
x_max = max(V, key=itemgetter(0))[0]
x_min = min(V, key=itemgetter(0))[0]

print(max(x_max - x_min, y_max - y_min))


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



Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

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

    int tmp = a;
    int ans = 1;
    while (tmp < b) {
        tmp += a-1;
        ans++;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	cin >> s ;
	deque<char> Q ;
	for(int i = 0 ; i < sz(s) ; i++){
		Q.push_back(s[i]) ;
	}
	int n ;
	cin >> n ;
	bool side = 0 ;
	for(int i = 0 ; i < n ; i++){
		int x ;
		cin >> x ;
		if(x==1){
			side ^= 1 ;
		}
		else{
			int y ;
			char ch ;
			cin >> y >> ch ;
			if(y==1){
				if(side == 1){
					Q.push_back(ch) ;
				}
				else{
					Q.push_front(ch) ;
				}

			}
			else{
				if(side == 0){
					Q.push_back(ch) ;
				}
				else{
					Q.push_front(ch) ;
				}
			}
		}
	}
	string ans = "" ;
	while(!Q.empty()){
		ans.pb(Q.front()) ;
		Q.pop_front() ;
	}
	if(side) reverse(all(ans)) ;
	cout << ans << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 1368
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]

XL.sort(key=lambda x: x[0] + x[1])

right = -float('inf')

ans = 0
for x, l in XL:
    s, t = x-l, x+l
    if s >= right:
        right = t
        ans += 1

print(ans)

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

int H, W;
char a[100][100];

int main() {
    cin >> H >> W;
    rep(i, H)rep(j, W) cin >> a[i][j];

    // 縦 
    char ans1[100][100];

    rep(i, W) {
        int all_white = true;
        rep(j, H) {
            // cout << a[j][i];
            if (a[j][i] == '#') {
                all_white = false;
                break;
            }  
        }
        // cout << endl;

        if (all_white) {
            rep(j, H) {
                a[j][i] = 'x';
            }
        }
    }

    // 横
    rep(i, H) {
        int all_white_row = true;
        rep(j, W) {
            if (a[i][j] == '#') {
                all_white_row = false;
                break;
            }
        }

        if (all_white_row) {
            rep(j, W) {
                a[i][j] = 'x';
            }
        }
    }

    // cout << endl;
    rep(i, H) {
        int tmp = 0;
        rep(j, W) {
            if (a[i][j] == 'x') {
                tmp++;
                continue;
            }
            cout << a[i][j];
        }

        if (tmp != W) {
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();;
		if(b-a==c-b)System.out.println("YES");
		else System.out.println("NO");
	}
}

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

using namespace std;



string ABCD;
string anser;


bool abcd7(int i, string ans, int sum){
    
    if (i == 3) {
        ans += ABCD.substr(i, 1);
        //sum += atoi(ABCD.substr(i, 1).c_str());
        
        
        if (sum == 7) {
            //cout << ans << "=7" << endl;
            anser = ans;
            return false;
        }else{
            //cout << ans << endl;
            return false;
        }
        
        
    }
    
    
    if (abcd7(i+1, ans+(ABCD.substr(i, 1)+"+"), sum+atoi(ABCD.substr(i+1, 1).c_str()))) {
        return true;
    }
    if (abcd7(i+1, ans+(ABCD.substr(i, 1)+"-"), sum-atoi(ABCD.substr(i+1, 1).c_str()))) {
        return true;
    }
    
    return false;
}





int main(){

    cin >> ABCD;
    
    int A = atoi(ABCD.substr(0, 1).c_str());
    
    abcd7(0, "", A);
    cout << anser << "=7" << endl;
   
    
    
    return 0;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define BRUTE (9*8*7*6*5*4*3*2)

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int ge[9], ja[9];

int dfs(int n, int gp, int jp, int *used){
  if(n == 9) return gp > jp;
  int res = 0;
  rep(i, 9){
    if(used[i]) continue;
    used[i] = 1;
    res += dfs(n+1, gp + (ge[n]>ja[i]?ge[n]+ja[i]:0), jp + (ja[i]>ge[n]?ja[i]+ge[n]:0), used);
    used[i] = 0;
  }
  return res;
}

int main(){
  int n;
  scanf("%d", &n);
  rep(i, n){
    rep(j, 9) scanf("%d", ge+j);
    rep(j, 9) scanf("%d", ja+j);
    int used[9] = {};
    int win = dfs(0, 0, 0, used);
    printf("%lf %lf\n", (double)win/BRUTE, 1-(double)win/BRUTE);
  }
  return 0;
}

Measured memory_bytes: 1220
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
#define N 1002
void Print(int,int,char *);
void Reverse(int, int, char *);
void Replace(int, int, char *);

int main() {
	char str[N], *p,op[N];
	int a, i,q,b;
	scanf("%s", str);
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		p = str;
		scanf("%s %d %d", op, &a, &b);
		if (strcmp(op, "print")==0) Print(a, b, p);
		if (strcmp(op, "reverse")==0) Reverse(a, b, p);
		if (strcmp(op, "replace")==0) Replace(a, b, p);
	}
	//printf("%s\n", p);
	return 0;
}
void Print(int a, int b, char *p) {
	for (; a <= b; a++)
		printf("%c", *(p + a));
	putchar('\n');
}
void Reverse(int a, int b, char *p) {
	char tmp[N]="",*p2;
	int i,j;
	strcat(tmp, p);
	p2 = tmp;
	for (i = b,j=0; a <= i; i--,j++) *(p+a+j) = *(p2 +  i);
}

void Replace(int a, int b, char *p) {
	char s[N] ,*pp;
	int i;
	scanf("%s", s);
	pp = s;
	for (i = a; i <= b; i++) {
		*(p + i) = *pp;
		*(pp++);
	}
}

Measured memory_bytes: 588
#include <cstdio>
#include <algorithm>
int n;
int a[100005];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	std::sort(a, a + n);
	printf("%d\n", a[n / 2] - a[n / 2 - 1]);
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	float a,b;
	while(scanf("%f %f",&a,&b)!=EOF){
		/*scanf("%f %f",&a,&b);*/
		if(a<35.5 && b<71.0){
			printf("AAA\n");
		}
		else if(a<37.5 && b<77.0){
			printf("AA\n");
		}
		else if(a<40.0 && b<83.0){
			printf("A\n");
		}
		else if(a<43.0 && b<89.0){
			printf("B\n");
		}
		else if(a<50.0 && b<105.0){
			printf("C\n");
		}
		else if(a<55.0 && b<116.0){
			printf("D\n");
		}
		else if(a<70.0 && b<148.0){
			printf("E\n");
		}
		else{
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){

	int MM[100][100]={};
	int m,n;
	cin>>m>>n;
	int x,y;
	int max=n;int k=n;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		k+=x-y;
		if(max<k)max=k;
		if(k<0){k=0;max=k;break;}
	}
	cout<<max<<endl;
	return 0;
}

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

const int maxn = 200010;
int n, K, a[maxn], b[maxn];

int main() {
    scanf("%d %d", &n, &K);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    while (K--) {
        if (*min_element(a + 1, a + n + 1) == n) break;
        memset(b, 0, sizeof(b));
        for (int i = 1; i <= n; i++) {
            int l = max(1, i - a[i]), r = min(n, i + a[i]);
            b[l]++, b[r + 1]--;
        }
        for (int i = 1; i <= n; i++) {
            b[i] += b[i - 1], a[i] = b[i];
        }
    }
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    return 0;
}

Measured memory_bytes: 5324
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,list<int>> g;
#define pb push_back
int toposort(int n){
    int ideg[n+1];
    int dis[n+1];
    for(int i=1;i<=n;i++){ideg[i]=0;dis[i]=0;}
for(int i=1;i<=n;i++){
    for(int v:g[i])ideg[v]++;
}
queue<int> q;
for(int i=1;i<=n;i++){
    if(ideg[i]==0)q.push(i);
}
while(!q.empty()){
int tt=q.front();
//cout<<tt<<endl;
q.pop();
for(int i:g[tt]){
    ideg[i]--;
    dis[i]=max(dis[i],1+dis[tt]);
    if(ideg[i]==0)q.push(i);
}
}
int maxx=0;
for(int i=1;i<=n;i++){
    maxx=max(maxx,dis[i]);
}
return maxx;
}

int main(){
    int  n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    g[x].pb(y);
    }
    cout<<toposort(n)<<endl;
    return 0;
}

Measured memory_bytes: 12920
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main()
{
    lli n;
    cin>>n;
    lli a[n],i,j,k,diag=n-1,dp[n][n],sum[n+1];
    for(i=0;i<n;i++)
        cin>>a[i];
    sum[0]=0;
    for(i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i-1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(j>i)
                dp[i][j]=1e18;
            else
                dp[i][j]=0;
        }
    }
    for(i=0;i<diag;i++)
    {
        for(j=n-diag;j<n;j++)
        {
            for(k=i;k<j;k++)
                dp[i][j]=min(dp[i][k]+dp[k+1][j],dp[i][j]);
            dp[i][j] +=sum[j+1]-sum[i];
            i++;
        }
        diag--;
        i=-1;
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

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

"""
・ベルマンフォード
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())

edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    # 0-indexed
    # コストの正負を逆転させれば最短経路問題として処理できる
    edges[i] = (a-1, b-1, -c)

def bellman_ford(N, edges, start):
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    verts = [float('inf')] * N
    verts[start] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            verts[dest] = min(verts[src] + cost, verts[dest])
    # 無限に減らせる場所がないか確認
    for src, dest, cost in edges:
        if verts[src] + cost < verts[dest]:
            verts[dest] = verts[src] + cost
            if dest == N-1:
                # 頂点Nがそれに該当していたら空リストを返却
                return []
    # 問題なければ頂点リストを返却
    return verts

verts = bellman_ford(N, edges, 0)
if not verts:
    print('inf')
else:
    # 正負を戻して出力
    print(-verts[N-1])


Measured memory_bytes: 3308
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long int
int main()
{
    ll a;
    while(~scanf("%lld",&a))
    {
        ll mod=11;
        ll output=a/mod*2;
        a%=mod;
        if(a>=1&&a<=6)output++;
        if(a>=7&&a<=10)output+=2;
        printf("%lld\n",output);
    }
}


Measured memory_bytes: 128
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,ans[1<<15];

void f(int cur,int n,int pre){
	ans[n]++;
	if(cur==4)return;
	rep2(i,pre,INF){
		if(n+i*i >= 1<<15)return;
		f(cur+1,n+i*i,i);
	}
}

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

	f(0,0,1);
	while(cin>>n && n){
		cout<<ans[n]<<endl;
	}
}

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


int main(){
    
    long int n,i;
    cin>>n;unordered_map<long int,int>hash;
    
    vector<long int >a(n);
    for(i=0;i<n;i++){ cin>>a[i];hash[a[i]]++;}
    long int x = a[0];
    
    for(i=1;i<n;i++) x = x^a[i];
    if(x==0) cout<<"Yes";
    else cout<<"No";
    
    
    
    
 return 0;   
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


class UnionFind {
 public:
  vector<int> data;
  int count;
 public:
  UnionFind(int size) : data(size, -1), count(size) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
      --count;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

bool solve(int N, int A,int B,int C,int D, string& s) {
    UnionFind uf(N);
    rep(i,N-1){
        if (s[i] == '.') {
            if (i+1 < N && s[i+1] == '.') uf.unionSet(i, i+1);
            if (i+2 < N && s[i+2] == '.') uf.unionSet(i, i+2);
        }
    }
    if (uf.root(A) != uf.root(C)) return false;
    if (uf.root(B) != uf.root(D)) return false;

    if (C < B) {
        return true;
    } else if (B < C && C < D) {
        return true;
    } else {
        bool pos = false;
        for (int i=B; i<=D; ++i) {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
                pos = true; break;
            }
        }
        return pos;
    }
}

int main() {
    char buf[200003];
    int N,a,b,c,d; scanf("%d %d %d %d %d%*c", &N,&a,&b,&c,&d);
    --a; --b; --c; --d;
    fgets(buf, 200003, stdin);
    string s(&buf[0], &buf[N]);
    cout << (solve(N,a,b,c,d,s) ? "Yes":"No") << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = 998244353;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int D[N]; rep(i,N) cin >> D[i];

  ll X[N]={}; rep(i,N) X[D[i]]++;
  if (D[0]!=0) { cout << 0 << endl; return 0; }
  if (X[0]!=1) { cout << 0 << endl; return 0; }

  int sum = 0;
  ll result = 1;
  rep(i,N) {
    if (X[i]==0) { result = 0; break; }
    if (i!=0) {
      rep(j, X[i]) { result *= X[i-1]; result %= MOD; }
    }
    sum += X[i]; if (sum==N) break;
    // cout << i << ":" << sum << "->" << result << endl;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1408
s = int(input())

def func(n):
    if n%2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1

def check(a, k):    
    for l in range(1, len(a)-k): 
        if a[k] == a[k+l]:
            print(k+l+1)
            return False
    return True

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        if not check(a, k):
            flg = 0
            break
    i += 1

Measured memory_bytes: 3064
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 998244353
#define ciN cin
#define X INT_MAX
#define N INT_MIN
////////////////////////////////////////////////////////////////

void jabru() {
	int n; cin >> n;
	vp v(n);
	For(i, 0, n) {
		int x, y; cin >> x >> y;
		v[i] = mp(x, y);
	}
	For(i, 0, n - 2) {
		int ans = 0;
		For(j, 0, 3) {
			if (v[i + j].F == v[i + j].S)ans++;
		}
		if (ans == 3) {
			cout << "Yes" << endl; return;
		}
	}
	cout << "No" << endl;
}

////////////////////////////////////////////////////////////////


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	t = 1;

	//cin >> t;
	while (t--)
		jabru();


	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???


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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

/************************************************************************************************************************************************/
void search_prime(vector<int>& sum_prime){
    vector<bool> is_prime (100000,true);
    for(int i = 1;i < 100000;i++){
        if(is_prime[i] == true){
//            cout << i+1 << " = prime" << endl;
            for(int j = (i+1)*2-1; j < 100000; j+=(i+1)){
                is_prime[j] = false;
            }
        }
        if((i+1)%2 == 1 && is_prime[i] && is_prime[(i+2)/2-1]){
            sum_prime[i] = sum_prime[i-1]+1;
//            cout << i+1 << " like 2017" << endl;
        }
        else sum_prime[i] = sum_prime[i-1];
    }
//    for(int i = 0;i < 100000;i++){
//        cout << "(" << i+1 << ") " << sum_prime[i] << endl;
//    }
}

void solve(){
    vector<int> sum_prime (100000,0);
    search_prime(sum_prime);
    int Q;
    cin >> Q;
    for(int i = 0;i < Q;i++){
        int l, r;
        cin >> l >> r;
        cout << sum_prime[r-1] - sum_prime[l-2] << endl;
    }
}



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

using namespace std;

#define ll long long

//ifstream cin("a.in");
//ofstream cout("a.out");

const int NMAX = 405;
const ll INF = 4e12;

ll dp[NMAX][NMAX];
ll a[NMAX],sp[NMAX];

//dp[i][j] = the minimal cost to reduce [i..j];

int main()
{
    int N,i,j,k,s;

    cin>>N;

    for(i = 1 ; i <= N ; ++i)
        cin>>a[i],sp[i] = sp[i-1] + a[i];

    for(i = 1 ; i <= N ; ++i)
        for(j = 1 ; j <= N ; ++j)
        {
            if(i != j)
                dp[i][j] = INF;
        }

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

    for(s = 1 ; s < N ; ++s)
    {
        for(i = 1 ; i + s<= N ; ++i)
        {
            j = i + s;
            for(k = i ; k < j ; ++k)
                dp[i][j] = min(dp[i][j] ,sp[j] - sp[i-1] + dp[i][k] + dp[k+1][j]);
        }
    }

    cout<<dp[1][N];
}


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

int n;
int a[200010];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	sort(a, a + n, greater <int> ());
	long long ans = 0;
	for (int i = 1; i < n; ++i)
		ans += a[i >> 1];
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 4612
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()
	{
		int N = GetInt();
		List<int> notMod0 = new List<int>(N);
		int sum = 0;
		for(int i = 0; i < N; i++)
		{
			int s = GetInt();
			sum += s;
			if(s % 10 > 0)
				notMod0.Add(s);
		}
		notMod0.Sort();

		if(sum % 10 == 0)
		{
			if(notMod0.Count == 0)
			{
				Console.WriteLine(0);
			}
			else
			{
				Console.WriteLine(sum - notMod0[0]);
			}
		}
		else
		{
			Console.WriteLine(sum);
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>

typedef enum {false, true} bool;


bool triangle(int a, int b, int c)
{
    if(a+b > c && a+c > b && b+c > a)
        return true;
    else
        return false;
}

int main(void)
{
    int N;
    int *L, temp;
    int i, j, k;
    int sum = 0;
    
    
    scanf("%d", &N);
    
    
    L = (int*)malloc(sizeof(int)*N);
    
    
    scanf("%d", &L[0]);
    
    for(i=1; i<N; i++)
    {
        scanf("%d", &temp);
        
        for(j=i; j>0; j--)
        {
            if(L[j-1] > temp)
                L[j] = L[j-1];
            else
                break;
        }
        L[j] = temp;
    }
    
    
    for(i=0; i<N; i++)
    {
        for(j=i+1; j<N; j++)
        {
            for(k=j+1; k<N; k++)
            {
                if(triangle(L[i], L[j], L[k]))
                    sum++;
                else
                    break;
            }
        }
    }
    
    
    printf("%d\n", sum);
    
    
    free(L);
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 128
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            f = len(c[i]) > len(c[i - 1])
            h, g = (c[i], c[i - 1]) if f else (c[i - 1], c[i])
            for x in g:
                heappush(h, x)
            if f:
                c[i - 1] = c[i]       
print(r)


Measured memory_bytes: 17624
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 305
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m,a[MAXN][MAXN];
int cur[MAXN],cnt[MAXN];
bool del[MAXN];
bool ok()
{
    for(int i=1;i<=n;i++) if(cur[i]>m) return false;
    return true;
}
void calc()
{
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;i++) cnt[a[i][cur[i]]]++;
}
void dele(int x)
{
    del[x]=true;
    for(int i=1;i<=n;i++)
    {
        while(cur[i]<=m&&del[a[i][cur[i]]]) cur[i]++;
    }
}
bool check(int x)
{
    for(int i=1;i<=n;i++) cur[i]=1;
    memset(del,false,sizeof(del));
    while(true)
    {
        if(!ok()) return false;
        calc();
        bool done=true;
        for(int i=1;i<=m;i++)
        {
            if(cnt[i]>x) 
            {
                dele(i);
                done=false;
            }
        }
        if(done) return true;
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    int l=0,r=n;
    while(r-l>1)
    {
        int mid=(l+r)/2;
        if(check(mid)) r=mid; else l=mid;
    }
    printf("%d\n",r);
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int a[M];
    for(int i = 0; i < M; i++){
        cin >> a[i];
    }

    int sum = 0;

    for(int i = 0; i < M; i++){
        sum += a[i];
    
    }

    if(sum > N){
        cout << -1 << endl;
    }

    else{
        cout << N-sum << endl;
    }

}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;string s;cin>>s;
	if(n % 2 == 1){
		cout << "No" << endl;
		return 0;
	}
	rep(i, n/2){
		if(s[i]!=s[i+n/2]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map(String::toLong)
    if (a == 0L || b == 0L) {
        println("Zero")
        return
    }
    if (a <= 0 && b <= 0) {
        if ((b - a) % 2 == 0L) {
            println("Negative")
        } else {
            println("Positive")
        }
    } else if (a <= 0 && 0 <= b) {
        println("Zero")
    } else if (0 <= a && 0 <= b) {
        println("Positive")
    }
}



Measured memory_bytes: 38080
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x-z) / (y + z);

	return 0;
}





Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n[3];
    int temp;
    for(int i = 0; i < 3; i++) cin >> n[i];
    if(n[0] > n[1]){
        temp = n[0];
        n[0] = n[1];
        n[1] = temp;
    }
    if(n[1] > n[2]){
        temp = n[1];
        n[1] = n[2];
        n[2] = temp;
    }
    if(n[0] > n[1]){
        temp = n[0];
        n[0] = n[1];
        n[1] = temp;
    }
    
    cout << n[0] <<' '<<n[1] <<' ' << n[2] << endl;
    return 0;
}


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

int main() {
  int a,b;cin >> a >> b;
  int lm,rm;
  vector<int> l(b),r(b);
  for(int i=0;i<b;i++){
      cin >> l[i] >> r[i];
  }

  lm = l[0];
  rm = r[0];

  if(b == 1){
      cout << rm - lm + 1 << endl;
  }else{
      for(int m=1;m<b;m++){
          lm = max(lm,l[m]);
          rm = min(rm,r[m]);
      }

      if(lm>rm){
          cout << 0 << endl;
      }else{
          cout << rm - lm + 1 << endl;
      }    
  }  
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

    ll len = K + S.length();
    combination comb(len);
    mint ans = 0;

    for (ll N = S.length() - 1; N < len; N++) {
        ll m = len - N - 1;
        mint now = comb(N, S.length() - 1);
        now *= mint(25).pow(K - m);
        now *= mint(26).pow(m);
        ans += now;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35592
import sys
input = sys.stdin.readline
from collections import Counter


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    Q = int(input().strip())
    BC = []
    for i in range(Q):
        b, c = map(int, input().strip().split())
        BC.append((b, c))
    return N, A, Q, BC


def solve(N, A, Q, BC):
    D = Counter(A)
    ans = sum(A)
    for b, c in BC:
        if D[b] > 0:
            v = D[b]
            ans -= b * v
            D[b] = 0
            D[c] += v
            ans += c * v
        print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 31872
import sys
from heapq import heappush,heappop
input = sys.stdin.readline

n,m = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    if a <= m:
        ab.append((a,b))
ab.sort(reverse=1)

stock = []
ans = 0
for i in range(1,m+1):
    while ab and ab[-1][0] <= i:
        a,b = ab.pop()
        heappush(stock,-b)
    if stock:
        ans += -heappop(stock)

print(ans)

Measured memory_bytes: 17236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll N, K;
    cin >> N >> K;
    vl h(N);
    rep(i, N) cin >> h[i];

    vl dp(N);
    for(ll i=1; i<K and i<N; i++) {
        dp[i] = abs(h[0]-h[i]);
    }
    for(ll i=K; i<N; i++) {
        ll x=1e15;
        for(ll j=1; j<=K; j++) chmin(x, dp[i-j] + abs(h[i]-h[i-j]));
        dp[i] = x;
    }

    cout << dp[N-1] << nl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);

  ll ans = 1;
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    } else {
      ll tmp;
      if (__builtin_mul_overflow(ans, a[i], &tmp) ||
          tmp > 1000000000000000000) {
        cout << -1 << endl;
        return 0;
      } else {
        if (tmp == 0) {
          cout << -1 << endl;
          return 0;
        }
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4368
#include <stdio.h>
int main(void)
{
  char x,y;
  scanf("%c",&x);
  scanf("%c",&y);
  while(y==' ' || y=='\n')
  {
    scanf("%c",&y);
  }
  if(x<y)
  {
    printf("<\n");
  }
  else if(x>y)
  {
    printf(">\n");
  }
  else
  {
    printf("=\n");
  }
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;

namespace _0052
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputsList = new List<int>();
            var outputsList = new List<int>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "0")
                {
                    break;
                }
                else 
                {
                    inputsList.Add(int.Parse(input));
                }
            }

            foreach (var input in inputsList)
            {
                var countFiveFactor = 0;
                var targetNumber = input;
                while ((targetNumber /= 5) > 0)
                {
                    countFiveFactor += targetNumber;
                }
                outputsList.Add(countFiveFactor);
            }

            foreach (var output in outputsList)
            {
                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
int main(){
	bool data[10][7]={{0,1,1,1,1,1,1},{0,0,0,0,1,1,0},{1,0,1,1,0,1,1},{1,0,0,1,1,1,1},{1,1,0,0,1,1,0},
		{1,1,0,1,1,0,1},{1,1,1,1,1,0,1},{0,1,0,0,1,1,1},{1,1,1,1,1,1,1},{1,1,0,1,1,1,1}};
	int n;
	while(cin>>n&&n!=-1){
		bool state[7];
		memset(state,false,sizeof(state));
		while(n--){
			int input;
			cin>>input;
			for(int i=0;i<7;i++){
				cout<<(state[i]^data[input][i]);
				state[i]=data[input][i];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int i,j,n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  int dp[n+1]={0};
  dp[1]=0;
  dp[2]=abs(a[1]-a[0]);
  for(i=3;i<=n;i++){
   // if(i==3)
    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i-2]),dp[i-2]+abs(a[i-1]-a[i-3]));
  }
  cout<<dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e+9
#define debug cout << ">>"
using namespace std;
int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i=0; i < n; i++) cin >> h[i];
    int dp[n];
    fill_n(dp, n, INF);
    dp[0] = 0;
    for (int i=0; i < n; i++) {
        for (int j=i+1; j <= i+2; j++)
            dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int bit[112345], bit_n;

int bit_sum(int i)
{
    int s = 0;
    while (i > 0)
    {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void bit_add(int i, int x)
{
    while (i <= bit_n)
    {
        bit[i] += x;
        i += i & -i;
    }
}

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

    string s;
    cin >> s;

    int l = 1;
    int r = s.size() + 1;

    bit_n = s.size();

    while (r - l > 1)
    {
        int mid = (r + l) / 2;

        fill(bit, bit + s.size() + 1, 0);

        int i = 0;
        while (i + mid - 1 < s.size())
        {
            int fnum = bit_sum(i + mid - 1) - bit_sum(i);

            if (((s[i] == '1') + fnum) % 2 == 0)
            {
                i++;
                continue;
            }

            bit_add(i + 1 + mid - 1, 1);

            i++;
        }

        while (i < s.size() && ((s[i] == '1') + bit_sum(s.size()) - bit_sum(i)) % 2 == 0)
            i++;

        bool check = true;
        if (i < s.size())
        {
            if (i - mid < 0)
                check = false;
        }

        if (check)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }

    cout << l << endl;

    return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
ll C, H[200020];
ll dp[200020];


ll f(int i, int j){
    return dp[j] + H[j] * H[j] - 2 * H[i]* H[j];
}

bool check(int j1, int j2, int j3){
    ll a1 = - 2 * H[j1]; ll b1 = dp[j1] + H[j1] * H[j1];
    ll a2 = - 2 * H[j2]; ll b2 = dp[j2] + H[j2] * H[j2];
    ll a3 = - 2 * H[j3]; ll b3 = dp[j3] + H[j3] * H[j3];
    return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2);
}


int main(){

    cin >> N >> C;
    for(int i = 0; i < N; i++) cin >> H[i];
    deque<int> dq; dq.push_back(0);
    for(int i = 1; i < N; i++){
        // if(i == N - 1){
        //     for(int a : dq){
        //         cout << a << endl;
        //     }
        //     cout<<endl;
        // }
        // 末尾から２番目が最小値とならなければ削除
        while(dq.size() > 2){
            int j1 = dq[(int)dq.size() - 3];
            int j2 = dq[(int)dq.size() - 2];
            int j3 = dq[(int)dq.size() - 1];
            if(check(j1, j2, j3)){
                const int tmp = dq.back();
                dq.pop_back();
                dq.pop_back();
                dq.push_back(tmp);
            }
            else{
                break;
            }
        }

        // if(i == N - 1){
        //     for(int a : dq){
        //         cout << a << endl;
        //     }
        // }

        // dequeの先頭要素が最小でない場合は取り除く
        while(dq.size() > 1) {
           int a = dq[0];
            int b = dq[1];
            if(f(i, a) >= f(i, b)){
                dq.pop_front();
            }
            else{
                break;
            }
        }
        // 先頭要素が最小値
        dp[i] = f(i, dq[0]) + C + H[i] * H[i];

        dq.push_back(i);
    }

    // ll dp2[101] = {};
    // for(int i = 1; i < N; i++){
    //     ll ans = 1LL << 60;
    //     for(int j = 0; j < i; j++){
    //         ans = min(ans, dp2[j] + (H[j] - H[i]) * (H[j] - H[i]) + C);
    //     }
    //     dp2[i] = ans;
    // }

    // for(int i = 0; i < N; i++){
    //     cout << dp[i] << ", " << dp2[i] << endl;;
    // }
    // cout << endl;

    
    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll a,b;
  cin >> a >> b;
  a=(a+11)%13;
  b=(b+11)%13;
  if(a<b) cout << "Bob" << endl;
  else if(a>b) cout << "Alice" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2000000000
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
//gcd,lcmセット
ll gcd(ll a, ll b){
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}
ll lcm(ll a, ll b){	
   return a*b/gcd(a, b);
}
bool isPrime(ll x){
    int i;
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
//dfsではvector<vector<int>> g(n);で◎
int main(){
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a int64

	fmt.Scan(&a)

	i := a % 10

	if 3 == i {
		fmt.Println("bon")
	} else if i == 0 || i == 1 || i == 6 || i == 8 {
		fmt.Println("pon")
	} else {
		fmt.Println("hon")
	}

}


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

#define rep(i,n) for (int i =0;i<(n);i++)
#define LL long long 

using namespace std;

int main(){
    int x;
    cin >>x;
    string list[]={"thu","fri","sat","sun","mon","tue","wed"};
    cout <<list[x%7]<<endl;
return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vi adj[200001];
int dst[200001];
int n, r = 1;

void dfs(int x, int p)
{
    for (int y : adj[x])
    {
        if (y == p) continue;
        dst[y] = dst[x] + 1;
        if (dst[y] > dst[r])
            r = y;
        dfs(y, x);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    if (n == 1)
        return cout << "First\n", 0;

    for (int i = 1; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, -1);
    dst[r] = 0;
    dfs(r, -1);
    if ((dst[r] - 1) % 3 == 0)
        cout << "Second";
    else
        cout << "First";
}


Measured memory_bytes: 21376
n = int(input())
S = input()
re = 0
for s in S:
    if s == 'E':
        re += 1
lw = 0
c = 3*10**5
for i in range(n):
    if S[i]  == 'E':
        re -= 1
    c = min(c, re+lw)

    if S[i] == 'W':
        lw += 1
print(c)


Measured memory_bytes: 3700
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()

void max_self(pair<int,pi> &first,pair<int,pi> second)
{
    if(first.first<second.first)
        first={second.first,second.second};
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string a,b;
    cin >> a >> b;
    vector<vector<pair<int,pi>>> dp(sz(a)+1,vector<pair<int,pi>>(sz(b)+1,{0,{0,0}}));
    F0R(i,sz(a))
    {
        F0R(j,sz(b))
        {
            if(a[i]==b[j])
                max_self(dp[i+1][j+1],{dp[i][j].first+1,{i,j}});
            max_self(dp[i+1][j+1],{dp[i+1][j].first,{i+1,j}});
            max_self(dp[i+1][j+1],{dp[i][j+1].first,{i,j+1}});
        }
    }
    int best=0;
    F0R(i,sz(a)+1)
    {
        F0R(j,sz(b)+1)
            best=max(best,dp[i][j].first);
    }
    int x,y;
    F0R(i,sz(a)+1)
    {
        F0R(j,sz(b)+1)
        {
            if(dp[i][j].first==best)
            {
                x=i;
                y=j;
                break;
            }
        }
    }
    vector<char> let;
    while(x!=0 && y!=0)
    {
        if(a[x-1]==b[y-1])
            let.pb(a[x-1]);
        pi next=dp[x][y].second;
        x=next.first;
        y=next.second;
    }
    for(int i=sz(let)-1; i>=0; i--)
        cout << let[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 105984