akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 500005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

char s[N];
int n, L[N], R[N];

int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	REP(i, 1, n) if(s[i] == s[i - 1]){
		L[i] = L[i - 1];
		R[L[i]] = i;
	}else{
		L[i] = R[i] = i;
	}
	int pts = 1, ans = 0;
	while(pts <= n){
		while(!s[pts]) ++ pts;
		if(pts > n) break;
		++ans;
		while(1){
			int y = R[pts] + 1;
			if(y > n) break;
			if(s[y] > s[pts]) pts = y; else break;
		}
		if(R[pts] == n) break;
		if(R[pts] > pts) R[pts + 1] = R[pts];
		pts ++;
		int x = n;
		while(s[x] == '9') x --;
		if(x < n){
			REP(j, x + 1, n) L[j] = x + 1;
			REP(j, x + 1, n) s[j] = '0';
			R[x + 1] = n;
		}
		if(s[x] == s[x - 1]){
			int getL = max(pts, L[x]);
			if(getL < x) R[getL] --;
			L[x] = R[x] = x;
		}
		s[x] ++;
		if(s[x] == s[x - 1]){
			int getL = max(pts, L[x - 1]);
			R[getL] = x;
			L[x] = getL;
		}
	} 
	printf("%d\n", ans);
	return 0;
}





















Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll num=x/d;
    ll num2=num+1;
    ll val1=x%d;
    ll val2=d-x%d;
    //cout<<num<<" ";
    if(k<num)
    {
        cout<<x-k*d;
        return 0;
    }
    k=k-num;
    if(k%2==0)
    {
        cout<<val1;
    }
    else
    {
        cout<<val2;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define full(c) c.begin(), c.end()
typedef unsigned long long int ull;
using namespace std;

int main(){
	int a[3], s = 0;
	cin >> a[0];
	cin >> a[1];
	cin >> a[2];
	sort(a, a + 3);
	cout << a[2] - a[0] << endl;
	return 0;
}


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

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

    for(int x = 0; x <= n; x++){
        for(int y = 0; y <= n; y++){
            int z;
            z = (yy - x*10000 - y*5000) / 1000;
            if(x + y + z == n && z >= 0){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  import io.StdIn._
  val x = readLine().toInt
  var primesUnderX: List[Int] = List.empty
  for (i <- 2 to Math.sqrt(x).toInt) {
    if (!primesUnderX.exists(p => i % p == 0)) {
      primesUnderX = i :: primesUnderX
    }
  }
  var ans = x
  while (primesUnderX.exists(p => ans % p == 0)) {
    ans += 1
  }

  println(ans)
}


Measured memory_bytes: 25412
from sys import stdin
def input():
    return stdin.readline().strip()

def main():
    n = int(input())
    probabilities = list(map(float, input().split()))

    # dp[i] = P(i heads coins)
    dp = [0.0] * (n//2 + 3)
    dp[0] = 1.0
    for p in probabilities:
        dp[n//2 + 1] += dp[n//2] * p
        for j in range(n//2 + 1)[::-1]:
            dp[j] = dp[j] * (1 - p) + dp[j-1] * p

    print(dp[n//2 + 1])

main()

Measured memory_bytes: 68752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			for(int i=0; i<2; i++){
				int a=sc.nextInt();
				int b=sc.nextInt();
				if(a==0){
					break;
				}
				square(a,b);
				System.out.println();
			}
		}











	}
	public static void square(int a,int b){
		for(int i=1; i<=a; i++){
			for(int j=1; j<=b; j++){
				if(i%2==0 && j%2==0){
					System.out.print("#");
				}else if(i%2==1 && j%2==1){
					System.out.print("#");
				}else{
					System.out.print(".");
				}
			}
			System.out.println();
		}
	}



}


Measured memory_bytes: 35400
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   string s;
   cin >> s;
   int cnt1 = 0;
   int cnt2 = 0;
   for (int i = 0; i < (int)s.size(); i++) {
      if (i % 2 == 0) {
         if (s[i] != '0') cnt1++;
         if (s[i] != '1') cnt2++;
      } else {
         if (s[i] != '1') cnt1++;
         if (s[i] != '0') cnt2++;
      }
   }
   cout << min(cnt1, cnt2) << endl;
   return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	long n;
	scanf("%ld", &n);
	long a[n];
	long b[n];
	long i = 1;
	long j = 1;
	while (j <= n)
		b[j++] = 0;

	while (i < n)
	{
		scanf("%ld", &a[i]);
		b[a[i]] += 1;
		i++;
	}
	long x  = 1;
	long count = 0;
	while (x <= n)
	{
		printf("%ld\n", b[x]);
		x++;
	}
	return 0;
}


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


void solve(long long N){

  long long rst = 0;
  for (long long i=1 ; i<=N; i++){
    // 桁数
    int d = int(log10(i))+1;
    if(d%2) rst++;
  }

  cout << rst << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}

int main(){
  int n;
  cin>> n;
  vector<int>ln(n),rn(n);
  rep(i,n)
    cin >> ln.at(i) >> rn.at(i);
  sort(all(ln));
  sort(all(rn));
  if(n%2==1)
    cout << rn.at(n/2)-ln.at(n/2)+1 << endl;
  else
    cout << rn.at(n/2)+rn.at(n/2-1)-ln.at(n/2)-ln.at(n/2-1)+1<<endl;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100LL
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int dp[upperlimit+1];
int main()
{
	int n,i,j;
	for(i=1;i<=upperlimit;i++){
		dp[i]=1+dp[i-1];
		for(j=6;j<=i;j*=6){
			dp[i]=min(dp[i],1+dp[i-j]);
		}
		for(j=9;j<=i;j*=9){
			dp[i]=min(dp[i],1+dp[i-j]);
		}
	}
	sd(n);
	pdn(dp[n]);
	return 0;
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 1123456789012345
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };
 
LL N, a[112345], b[112345], c[112345], Q, K, x[112345], y[112345];
LL d[112345];
std::vector<edge>G[112345];
 
void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(d, d + N + 1, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (d[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
 
int main()
{
	in >> N;
	rep(i, N - 1)
	{
		in >> a[i] >> b[i] >> c[i];
		G[a[i]].push_back({ b[i],c[i] });
		G[b[i]].push_back({ a[i],c[i] });
	}
	in >> Q >> K;
	rep(i, Q) { in >> x[i] >> y[i]; }
 
	dijkstra(K);
 
	rep(i, Q) { out << d[x[i]] + d[y[i]] << std::endl; }
	return 0;
}

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

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

    for (int i = S.size() - 1; i != 0; i--) {
        if (S[i] == 'R' && i == S.size() - 1) S.insert(S.begin() + i + 1, 'A');
        if (S[i] == 'B' && S[i + 1] != 'A') S.insert(S.begin() + i + 1, 'A');
        if (S[i] == 'H' && S[i + 1] != 'A') S.insert(S.begin() + i + 1, 'A');
    }
    if (S.front() != 'A') S.insert(S.begin(), 'A');
    cout << (S == "AKIHABARA" ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
using graph = vector<vector<int>>;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define all(x) (x).begin(),(x).end()
#define size(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define pb push_back
#define mp make_pair
#define f first
#define s second

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

int main(){
	int s;cin>>s;
	int a=s/100,b=s%100;
	bool flag1=false,flag2=false;
	if(0<a&&a<=12)flag1=true;
	if(0<b&&b<=12)flag2=true;
	if(flag1&&flag2)cout<<"AMBIGUOUS"<<endl;
	else if(flag1&&!flag2)cout<<"MMYY"<<endl;
	else if(!flag1&&flag2)cout<<"YYMM"<<endl;
	else cout<<"NA"<<endl;
}



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

using namespace std;
int main() {
  	string s;
  	cin >> s;
    for (int i = 0; i <=1; i++) {
      if (s[i] == s[i+1] && s[i] == s[i+2]) {
        printf("Yes");
      	return 0;
      }
    }
  	printf("No");
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int m=1e6;


int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int &x: a) cin>>x;
    sort(a.begin(),a.end());
    vector<int> cn(m+1,1);
    int ans=0;
    for(int i=0;i<n;i++){
        if(cn[a[i]]==1){
            for(int j=a[i];j<=m;j+=a[i]){
                cn[j]=0;
            }
            if(i<n-1&&a[i]==a[i+1]) continue;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	int N=in();
	for(int i=0,ei=S.size();i<ei;i++){
		int dist = (26-(S[i]-'a'))%26;
		if(N-dist>=0){
			S[i] = ((S[i]-'a'+dist)%26)+'a';
			N-=dist;
		}
		if(i==ei-1 && N){
			S[i] = ((S[i]-'a'+N)%26)+'a';
		}
	}

	out(S);
	return 0;
}


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

int main() {
  string S;
  string T;
  cin >> S >> T;
  int p = 0;
  
  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) {
      p++;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
void saiki(vector<vector<bool> >& in,int x,int y,int n,int m){
  in[x][y]=0;
  //cout<<x<<" "<<y<<endl;
  loop(i,-1,2){
    loop(j,-1,2){
      if(x+i>=0&&x+i<n&&y+j>=0&&y+j<m&&in[x+i][y+j])saiki(in,x+i,y+j,n,m);
    }
  }
}
int main(){
  int n,m;
  while(cin>>m>>n,n||m){
    int co=0;
    vector<vector<bool> >in(n);
    rep(i,n){
      rep(j,m){
	bool tmp;
	cin>>tmp;
	in[i].push_back(tmp);
      }
    }
    rep(i,n){
      rep(j,m){
	if(!in[i][j])continue;
	saiki(in,i,j,n,m);
	co++;
      }
    }
    cout<<co<<endl;
  }
}

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

int main(){
	string S;
	cin >> S;
	int N = S.size();
	int black[N+1];
	int white[N+1];
	black[0] = 0;
	white[0] = 0;
	for(int i = 1; i <= N; i++){
		if(S[i-1] == '0'){
			black[i] = white[i-1];
			white[i] = black[i-1] + 1;
		}else{
			black[i] = white[i-1] + 1;
			white[i] = black[i-1];
		}
	}
	if(black[N] > white[N]){
		cout << white[N] << endl;
	}else{
		cout << black[N] << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int n,m,l,q,ans=0;
void Main(){
    string S;cin>>S;
    string T=S;
    reverse(T.begin(),T.end());
    For(i,0,S.size()/2){
        if(S[i]!=T[i]) ans++;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}


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

int main(){
  int N;
  cin>> N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++) cin >> B[i];
  int ans = 0;
  ans+=B[0]+B[N-2];
  for(auto itr=B.begin();itr<B.end()-1;++itr){
    ans+= ( *itr<*(itr+1) )? *itr:*(itr+1);   
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<long long> B(N - 1);
    for (int i = 0; i < N - 1; ++i) cin >> B[i];

    long long res = B[0] + B.back();
    for (int i = 0; i + 1 < B.size(); ++i) {
        res += min(B[i], B[i + 1]);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

std::vector<int> par(200005);
std::vector<int> rak(200005);

void init(int n) {
  for(int i=1; i<=n; i++) {
    par.at(i) = i;
    rak.at(i) = 0;
  }
}

int find(int x) {
  if (par.at(x) == x) {
    return x;
  } else {
    return par.at(x) = find(par.at(x));
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  if (rak.at(x) < rak.at(y)) {
    par.at(x) = y;
  } else {
    par.at(y) = x;
    if (rak.at(x) == rak.at(y)) rak.at(x)++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

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

  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    cin >> s[i];
  }

  init(h*w);

  for(int i=0; i<h*w; i++) {
    int x = i/w;
    int y = i%w;
    if (x+1<h && s[x][y] != s[x+1][y]) {
      unite(i+1, i+1+w);
      //debug(i+1); debugln(i+1+w);
    }
    if (y+1<w && s[x][y] != s[x][y+1]) {
      unite(i+1, i+1+1);
      //debug(i+1); debugln(i+1+1);
    }
  }
  
  map<int, P> mp;
  for(int i=0; i<h*w; i++) {
    int x = i/w;
    int y = i%w;
    if (s[x][y] == '.') {
      mp[find(i+1)].first++;
    } else {
      mp[find(i+1)].second++;
    }
  }

  ll ans = 0;
  for(auto e: mp) {
    ans += e.second.first * e.second.second;
  }

  cout << ans << endl;

}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e5;  
using  p = pair<int,int>;

int main(){
   int n;
   cin >>n;
   auto h = vector<ll>(n,0);
   for (int i = 0; i < n; i++)
   {
      cin >> h[i];
   }
   auto c = 0;
   auto ans = 0;
   for (int i = 0; i < n-1; i++)
   {
      if(h[i+1]-h[i]<=0) c++;
      else c = 0;
      ans = max(ans,c);
   }

   cout << ans;
   

}
  
  

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( i = c.begin(); i != c.end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e;++i)
#define forsn(i,s,e) for(int i = s; i < e;++i)
#define rforn(i,s) for(int i = s; i >= 0;--i)
#define rforsn(i,s,e) for(int i = s; i >= e;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
ll INF=1e18;
const int LIM=1e5+5,MOD=1e9+7;
ll min1(ll a,ll b)
{
    if(a<b)
        return a;
    else return b;
}
int main()
{
    fastio;
    ll N=1010;
    vector<ll> segments;
    vector<string> ans;
    ll in[1010][2];

    ll n;
    cin>>n;
    forn(i,n)
    {
        cin>>in[i][0]>>in[i][1];
    }
     
    ll mod2 = abs((in[0][0] + in[0][1])%2);
    bool possible = true;
     
      // check that they all have same parity
    for(int i=1;i<n;i++)
    {
        if(abs((in[i][0] + in[i][1])%2) != mod2)
        {
            possible = false;
            break;
        }
    }
     
    if(possible)
    {
        if(mod2 == 0)
        {
            segments.pb(1);
        }
        forn(i,31)
        {
          segments.pb(1LL << i);
        }
        forn(i,n)
        {
            ll x = in[i][0], y = in[i][1];
     
            int num_segs = segments.size();
            ll sum = (1LL << 31) - mod2;
            string s("");
            for(int j = num_segs-1; j >= 0; j--)
            {
                sum -= segments[j];
                if(abs(x - segments[j]) + abs(y) <= sum) 
                {
                    s += 'R';
                    x -= segments[j];
                }else if(abs(x + segments[j]) + abs(y) <= sum)
                {
                    s += 'L';
                    x += segments[j];
                } else if(abs(x) + abs(y - segments[j]) <= sum)
                {
                    s += 'U';
                    y -= segments[j];
                } else 
                {
                    s += 'D';
                    y += segments[j];
                }
            }
     
              reverse(s.begin(), s.end());
              ans.pb(s);
        }
     
        cout<<segments.size()<<"\n";
        ll j;
        for(j=0;j<segments.size();j++)
        {
          cout<<segments[j]<<" ";
        }
        cout<<"\n";
        puts("");
        for(j=0;j<ans.size();j++)
        {
          cout<<ans[j]<<endl;
        }
     
        } 
        else
        {
            puts("-1");
        }
        return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a;
int main() {
	int n;
	cin >> n;
	bool odd = false;
	rep(i,n) {
		cin >> a;
		if (a % 2) odd = true;
	}
	if (odd) cout << "first" << endl;
	else cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 3644
n = int(input())
t = [list(map(int, input().split())) for i in range(n)]

flag = 'Yes'
for i in range(n):
    if (t[i][1] +t[i][2]) > t[i][0] or (t[i][1] + t[i][2]) % 2 != t[i][0] % 2:
        flag = 'No'
print(flag)


Measured memory_bytes: 27300
#include<iostream>
#include<string>

using namespace std;

string a;

int main(void)
{
	cin>>a;
	
	for(int i = 0 ; i < a.size() ; ++i )
	{
		if(a[i] == 'C')
		{
			for(int j = i + 1 ; j < a.size() ; ++j )
			{
				if(a[j] == 'F')
				{
					cout<<"Yes\n";
					return 0;
				}
			}
		}
	}
	
	cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n + 1, vector<int>(0));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<int> visited(n + 1, 0), v1(1, 1), v2;
    visited[1] = 1;
    for (int i = 0; i < 2; i++) {
        v2.clear();
        for (auto node : v1) {
            for (auto next : v[node]) {
                if (i == 1 && next == n) {
                    cout << "POSSIBLE" << endl;
                    return 0;
                }
                if (visited[next] == 0) {
                    visited[next] = 1;
                    v2.push_back(next);
                }
            }
        }
        v1 = v2;
    }
    cout << "IMPOSSIBLE" << endl;
}


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

int main(){
    string s, ans = "Yes";
    cin >> s;
    if(s == "AAA" || s == "BBB") ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
dx = x2-x1
dy = y2-y1
x3 = x2-dy
y3 = y2 + dx
x4 = x1 - dy
y4 = y1 + dx
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
d1 = {" ":"101","'":"000000",",":"000011","-":"10010001",".":"010001","?":"000001","A":"100101","B":"10011010","C":"0101","D":"0001","E":"110","F":"01001","G":"10011011","H":"010000","I":"0111","J":"10011000","K":"0110","L":"00100","M":"10011001","N":"10011110","O":"00101","P":"111","Q":"10011111","R":"1000","S":"00110","T":"00111","U":"10011100","V":"10011101","W":"000010","X":"10010010","Y":"10010011","Z":"10010000",}
d2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}

while True:
	try:
		c,dc = "",""
		inp = raw_input()
		for a in inp:
			c += d1[a]
		if len(c)%5 != 0:
			c += "0"*(5-len(c)%5)
		for i in range(0,len(c),5):
			dc += d2[c[i:i+5]]
		print dc
	except:
		break

Measured memory_bytes: 4328
//053
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int main(void){
    string s;
    int a, z;
    cin >> s;
    a = s.find('A');
    z = s.rfind('Z'); //rfind()右から
    cout << z-(a-1);
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

string s;
lli w;

int main(){
  cin >> s >> w;
  for(lli i = 0;i < s.size();i += w){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
from math import sqrt

def cross(P0, P1, P2):
    x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
    x1 -= x0; x2 -= x0
    y1 -= y0; y2 -= y0
    return x1*y2 - x2*y1

def dot(P0, P1, P2):
    x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
    x1 -= x0; x2 -= x0
    y1 -= y0; y2 -= y0
    return x1*x2 + y1*y2

def dist2(P0, P1):
    x0, y0 = P0; x1, y1 = P1
    return (x1 - x0)**2 + (y1 - y0)**2

def convex_hull(PS):
    QS = []
    n = len(PS)
    if n==1:
        return PS[:]
    for P in PS:
        while len(QS)>1 and cross(QS[-1], QS[-2], P) > 0:
            QS.pop()
        QS.append(P)
    k = len(QS)
    RS = reversed(PS); next(RS)
    for P in RS:
        while len(QS)>k and cross(QS[-1], QS[-2], P) > 0:
            QS.pop()
        QS.append(P)
    return QS

def cross4(S0, S1, T0, T1):
    x0, y0 = S0; x1, y1 = S1
    X0, Y0 = T0; X1, Y1 = T1
    return (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0)
def calipers(PS):
    QS = convex_hull(PS)
    n = len(QS)
    if n == 2:
        return sqrt(dist2(*QS))
    i = j = 0
    for k in range(n):
        if QS[k] < QS[i]: i = k
        if QS[j] < QS[k]: j = k
    res = 0
    si = i; sj = j
    while i != sj or j != si:
        res = max(res, dist2(QS[i], QS[j]))
        if cross4(QS[i], QS[i-n+1], QS[j], QS[j-n+1]) < 0:
            i = (i + 1) % n
        else:
            j = (j + 1) % n
    return sqrt(res)

n = input()
PS = [map(float, raw_input().split()) for i in range(n)]
PS.sort()
print("%.09f" % calipers(PS))

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=3e5+5,mod=1e9+7;
ll n,a[N],prfx[N],sfx[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    for(ll i=1;i<=3*n;i++)cin>>a[i];
    ll sum=0;
    priority_queue<ll , vector<ll> , greater<ll> > pq;for(ll i=1;i<=n;i++)pq.push(a[i]),sum+=a[i];
    prfx[n]=sum;
    for(ll i=n+1;i<=2*n;i++){
        sum+=a[i];
        pq.push(a[i]);
        auto node = pq.top();
        pq.pop();
        sum-=node;
        prfx[i]=sum;
    }
    priority_queue<ll> pqq;
    sum=0;
    for(ll i=3*n;i>2*n;i--)pqq.push(a[i]),sum+=a[i];
    sfx[2*n+1]=sum;
    for(ll i=2*n;i>n;i--){
        sum+=a[i];
        pqq.push(a[i]);
        auto node = pqq.top();
        pqq.pop();
        sum-=node;
        sfx[i]=sum;
    }
    ll ans = (-1e18);
    for(ll i=n;i<=2*n;i++)ans = max(ans , prfx[i] - sfx[i+1]);
    cout<<ans;
}



Measured memory_bytes: 7796
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  if(C==1)R=1;
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,i,l,a[200010],b;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a[R],&b);
    hin(b);
  }
  l=1e9+10;
  while(n--){
    i=hout();
    if(l>N[i])l=N[i];
    l-=a[i];
  }
  printf("%s\n",l<0?"No":"Yes");
  return 0;
}
    


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
const int inf=1<<30;
long long i,j,k,m,n,tot;
int a[N],ver[N],nxt[N],edge[N],head[N];
char s[N],t[N];
void add(int x,int y,int w)
{
	ver[++tot]=y,edge[tot]=w,nxt[tot]=head[x],head[x]=tot;
}
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=10;i++)
	{
		printf("%lld\n",k*n-m);
		k=k*n-m;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String kaibun = sc.next();
		int mojisuu = kaibun.length();

		if(kaibun.substring(0,(mojisuu-1)/2).equals(kaibun.substring((mojisuu+3)/2-1,mojisuu))) {
			System.out.print("Yes");
		}
		else {
			System.out.print("No");
		}
	}
}


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

int N;
int A[210];

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

    int res = 0;

    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;
        }

        if (exist_odd) break;

        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int len=0,f[100000];
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0') {
			len++;
			f[len]=0;
		}
		else if(s[i]=='1') {
			len++;
			f[len]=1;
		}
		else if(s[i]=='B') {
			if(len!=0) len--;
		}
	}
	for(int i=1;i<=len;i++){
		cout<<f[i];
	}
	return 0;
}

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

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

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

    vector<long long> dp(n);
    dp[0] = 0;
    dp[1] = abs(stoneHeights[0] - stoneHeights[1]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i-1] + abs(stoneHeights[i-1]-stoneHeights[i]),
                dp[i-2] + abs(stoneHeights[i-2] - stoneHeights[i]));
    }

    cout << dp[n-1];

}




Measured memory_bytes: 1408
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int m;
int main()
{
    m=read();
    while(m--)
    {
        int a=read(),b=read(),lt=read(),rt=read();
        int len=(a+b)/(min(a,b)+1);
        int l=1,r=a,mid,res=0;
        while(l<=r)
        {
            mid=l+r>>1;
            int cnt=(mid+len-1)/len;
            int lefta=a-mid,leftb=b-cnt+1-len;
            if(1LL*lefta*len<leftb) r=mid-1;
            else res=mid,l=mid+1;
        }
        int cnt=(res+len-1)/len,prelen=cnt?cnt-1+res:0;
        int lefta=a-res,leftb=b-max(0,cnt-1),first=leftb-(lefta*len);
        for(int j=lt;j<=rt;++j)
        {
            if(j<=(cnt-1)*(len+1)) putchar(j%(len+1)?'A':'B');
            else if(j<=prelen) putchar('A');
            else if(j<=prelen+first) putchar('B');
            else putchar((j-prelen-first)%(len+1)==1?'A':'B');
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 384
/**
 * auther: moririn_cocoa
 */
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main(int argc, char* argv[]) {
  
  int N;
  int A;
  int B;
  
  cin >> N;
  
  if ( N == 1 ) {
    
    cout << "Hello World" << endl;
  }
  
  else if ( N == 2 ) {
    
    cin >> A;
    cin >> B;
    
    cout << A + B << endl;
  }
  
  return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> P(n);
  int sum = 0;
  for (auto &p : P) {
    cin >> p;
    sum += p;
  }
  sort(P.begin(), P.end());
  cout << sum - P[n-1]/2 << endl;

  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    ll m = 26; //26^~
    int dig = 1; //桁

    // 何桁の何番目(0indexed)を同定
    while(true) {
        if(N <= m) {
            break;
        }

        N -= m;
        m *= 26;
        dig++;
    }

    N--;

    //cout << dig << " " << N << endl;

    vector<char> vec;
    for(int i = 0; i < dig; i++) {
        vec.push_back(char('a' + N % 26));
        N /= 26;
    }

    reverse(vec.begin(), vec.end());

    for(auto c : vec) {
        cout << c;
    }
    cout << endl;


    return 0;
}

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

int main(){
  long long H = 0;
  long long cnt = 0;
  long long inc = 1;
  
  cin >> H;
  while(H > 0){
    H /= 2;
    cnt += inc;
    inc *= 2;
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

	int posA, posZ;
	int sizeS = argS.size();
	for (uint i = 0; i < sizeS; ++i) {
		if (argS.at(i) == 'A') {
			posA = i;
			break;
		}
	}

	for (int i = sizeS - 1; i > -1; --i) {
		if (argS.at(i) == 'Z') {
			posZ = i;
			break;
		}
	}

	cout << posZ - posA + 1 << endl;
}


Measured memory_bytes: 832
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
  long long X, K, D;
  cin >> X >> K >> D;
  long long t = abs(X)/D;
  if(t >= K){
    if(X < 0) X += K*D;
    else X -= K*D;
    cout << abs(X) << endl;
    return 0;
  }
  if(X < 0) X += t*D;
  else X -= t*D;
  // cerr << X << endl;
  K -= t;
  K %= 2;
  if(abs(X-D) > abs(X+D)) X += K*D;
  else X -= K*D;
  cout << abs(X) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  double ans = 0;
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  REP(i, n) {
    double tmp_p;
    cin >> tmp_p;
    p.at(i) = (tmp_p + 1.0) / 2.0;
  }
  vector<double> ruiseki(n + 1);
  ruiseki.at(0) = 0;
  for (int i = 1; i <= n; i++) {
    ruiseki.at(i) = ruiseki.at(i - 1) + p.at(i - 1);
  }

  double max_tmp = -1, max_ind;
  REP(i, n + 1 - k) {
    if (ruiseki.at(i + k) - ruiseki.at(i) > max_tmp) {
      max_tmp = ruiseki.at(i + k) - ruiseki.at(i);
      max_ind = i;
    }
  }
  // REP(i, k + 1) { ans += p.at(i); }
  ans = max_tmp;
  cout <<fixed<<setprecision(6)<< ans << endl;
  DEBUGS(ruiseki);
  DEBUG(max_ind);
  DEBUGS(p);
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INF = 1LL << 60;

int main() {
    ll N;
    cin >> N;
    vector<ll> h(N + 2);
    rep(i, N) { cin >> h[i]; }

    vector<ll> ans(N + 2, INF);
    ans[0] = 0;
    rep(i, N) {
        chmin(ans[i + 1], ans[i] + abs(h[i] - h[i + 1]));
        chmin(ans[i + 2], ans[i] + abs(h[i] - h[i + 2]));
    }
    cout << ans[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll cnt[2100];
ll gya(ll n,ll p, ll m){
	ll b=1;
	while(p){
		if(p%2)b=(b*n)%m;
		n=(n*n)%m;
		p/=2;
	}
	return b;
}
int main(){
	string s;
	cin>>s;
	ll now=0;
	for(int i=s.size()-1;i>=0;i--){
		now+=gya(10,s.size()-i-1,2019)*(s[i]-'0');
		now%=2019;
		cnt[now]++;
	}
	cnt[0]++;
	ll ans=0;
	for(int i=0;i<2019;i++){
		ans+=cnt[i]*(cnt[i]-1)/2;
		//cout<<cnt[i]<<' ';
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

class DisjointSet {
public:
    vector<ll> rank, p;
    
    DisjointSet() {};
    DisjointSet(ll size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for(ll i=0; i<size; i++) makeSet(i);
    }
    
    void makeSet(ll x) {
        p[x]=x;
        rank[x]=0;
    }
    
    bool same(ll x, ll y) {
        return findSet(x)==findSet(y);
    }
    
    void unite(ll x, ll y) {
        link(findSet(x), findSet(y));
    }
    
    void link(ll x, ll y) {
        if(rank[x]>rank[y]) {
            p[y]=x;
        }else {
            p[x]=y;
            if(rank[x]==rank[y])
                rank[y]++;
        }
    }
    
    ll findSet(ll x) {
        if(x!=p[x]) {
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

int main(void) {
    ll n, m, i;
    cin >> n >> m;
    ll p[100000];
    ll x[100000], y[100000];
    
    for(i=0; i<n; i++) {
        cin >> p[i];
        p[i]--;
    }
    
    DisjointSet ds=DisjointSet(n);
    
    for(i=0; i<m; i++) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        ds.unite(x[i], y[i]);
    }
    
    ll ans=0;
    for(i=0; i<n; i++) {
        if(ds.same(p[i], i)) ans++;
    }
    
    cout << ans << endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
ll N,m;
vector<vector<ll>> warshall_floyd(vector<vector<ll>> d){
  rep(k,m){
    rep(i,m){
      rep(j,m){
        d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }
  return d;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin>>N>>m&&N&&m){
    int a,b,c,d;
    vector<vector<ll>> time(m+1,vector<ll>(m+1,inf));
    vector<vector<ll>> cost(m+1,vector<ll>(m+1,inf));
    ++m;
    rep(i,N){
      cin >> a >> b >> c >> d;
      time[a][b] = d;
      cost[a][b] = c;
      time[b][a] = d;
      cost[b][a] = c;
    }
    int k,p,q,r ;
    auto T = warshall_floyd(time);
    auto C = warshall_floyd(cost);
    cin >> k;
    rep(i,k){
      cin >> p >> q >> r;
      if(r){
        cout << T[p][q]<<endl;
      }
      else{
        cout << C[p][q]<<endl;
      }
    }
  }
  return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int num_x = abs(tx-sx);
    int num_y = abs(ty-sy);
    REP(i,num_x)cout << 'R';
    REP(i,num_y)cout << 'U';
    REP(i,num_x)cout << 'L';
    REP(i,num_y)cout << 'D';
    cout << 'D';
    REP(i,num_x+1)cout << 'R';
    REP(i,num_y+1)cout << 'U';
    cout << 'L';
    cout << 'U';
    REP(i,num_x+1)cout << 'L';
    REP(i,num_y+1)cout << 'D';
    cout << 'R' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f(vector<vector<int>> &E, vector<int> &dp, int s){
  if (dp[s] != -1){
    return dp[s];
  } else {
    int ans = 0;
    for (int i = 0; i < E[s].size(); i++){
      ans = max(ans, f(E, dp, E[s][i]) + 1);
    }
    dp[s] = ans;
    return ans;
  }
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
  }
  vector<int> dp(N, -1);
  int ans = 0;
  for (int i = 0; i < N; i++){
    ans = max(ans, f(E, dp, i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 8832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b; cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256