akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑



void solve()
{
	int N;
	while (cin >> N, N)
	{
		vector<int> x(N);
		vector<int> y(N);
		vector<int> r(N);
		vector<int> c(N);
		for (int i = 0; i < N; i++)
		{
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		
		vector<int> G[N];
		//vector<int> P(N);
	/*	for (int i = 0; i < N; i++)
		{
			P[i] = -1;
		}*/
		for (int i = 0; i < N; i++)
		{
			for (int j = i + 1; j < N; j++)
			{
				int xx = x[i] - x[j];
				int yy = y[i] - y[j];
				int rr = r[i] + r[j];
				if (xx * xx + yy * yy < rr * rr)
				{
					G[j].emplace_back(i);
				}
			}
		}

		vector<int> dp(1 << N, 0);
		int ans = 0;
		vector<bool> ok(N, false);
		for (int S = 0; S < 1 << N; S++)
		{
			if (S != 0 && dp[S] == 0)continue;
			for (int i = 0; i < N; i++)
			{
				if (S >> i & 1)continue;
				for (int j = i + 1; j < N; j++)
				{
					if (S >> j & 1)continue;
					if (c[i] != c[j])continue;
					bool flag = true;
					for (int v : G[i])
					{
						if ((S >> v & 1) == 0) {
							flag = false;
							break;
						}
					}
					if (!flag)continue;
					for (int v : G[j]) {
						if ((S >> v & 1) == 0)
						{
							flag = false;
							break;
						}
					}
					if (!flag)continue;


					dp[S | (1 << i) | (1 << j)] = dp[S] + 2;
					ans = max(ans, dp[S] + 2);
					//ok[i] = true;
					//ok[j] = true;
				}
			}
			//cout << dp[S] << endl;
		}

		cout << ans << endl;

	}
}

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


Measured memory_bytes: 68580
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 998244353;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e6 + 1;
	
	
	long[] fac, finv, inv;
	void doIt() {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		comInit();
		long sum = 0;
		for(int i = 0; i <= K; i++) {
			long ans = 1;
			ans = ans * (long)M % MOD;
			ans = ans * modCom(N - 1, i) % MOD;
			ans = ans * modPow(M - 1, N - 1 - i) % MOD;
			sum = (sum + ans) % MOD;
		}
		System.out.println(sum);
	}
	
	long modPow(long a, long n) {
		long ans = 1;
		while(n > 0) {
			if((n & 1) == 1)
				ans = ans * a % MOD;
			a = a * a % MOD;
			n >>= 1;
		}
		return ans;
	}
	
	void comInit() {
		fac = new long[len];
		finv = new long[len];
		inv = new long[len];
		fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    inv[1] = 1;
	    for (int i = 2; i < len; i++){
	        fac[i] = fac[i - 1] * i % MOD;
	        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
	        finv[i] = finv[i - 1] * inv[i] % MOD;
	    }
	}
	
	long modCom(int n, int k){
	    if (n < k) return 0;
	    if (n < 0 || k < 0) return 0;
	    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}

}


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

// main
int main(){
    string S, T; cin >> S >> T;
    cout << T + S << endl;
    return 0;
}

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

const int N=1e5+5;
string s[2];
int n[2],pf[2][2][N];

void solve(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	--a,--b,--c,--d;
	int num[2]={0};
	num[0]=pf[0][0][b]+pf[0][1][b]*2;
	if(a>0) num[0]-=pf[0][0][a-1]+pf[0][1][a-1]*2;
	num[1]=pf[1][0][d]+pf[1][1][d]*2;
	if(c>0) num[1]-=pf[1][0][c-1]+pf[1][1][c-1]*2;
//	cerr<<num[0]<<' '<<num[1]<<'\n';
	if(abs(num[0]-num[1])%3==0) cout<<"YES\n";
	else cout<<"NO\n";
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>s[0]>>s[1];
	n[0]=s[0].size();
	n[1]=s[1].size();
	for(int i=0;i<2;++i)
		for(char c='A';c<='B';++c)
			for(int j=0;j<n[i];++j)
				pf[i][c-'A'][j]=(j?pf[i][c-'A'][j-1]:0)+(s[i][j]==c);
	int T;
	cin>>T;
	while(T--) solve();
}




Measured memory_bytes: 5368
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> A(N+1); // A[i]:= i 文字目まで見たときのAC の数の合計
    rep(i,N){
        A[i+1] = A[i];
        if(S[i]=='C' && S[i-1]=='A' && i-1>=0){
            A[i+1]++;
        }
    }
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        cout << A[r] - A[l] << endl;
    }
}


Measured memory_bytes: 1488
// inputに入力データ全体が入る
function Main(input) {
  input = input.split(/\s/);
  var x = parseInt(input[0], 10)
  var y = parseInt(input[1], 10)
  var fare = x + (y/2)
  console.log(fare)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

int main() {
  int N;
  cin >> N;
  int A[200000];
  vector<int> a(N);
  for(int i = 0;i < N;i++)cin >> A[i];
  for(int i = 0;i < N;i++) a.at(i) = A[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for(int i = 0;i < N;i++){
    if(A[i] != a.at(0)){
      cout << a.at(0) << endl;
    }
    else if(A[i] == a.at(0)){
      cout << a.at(1) << endl;
    }
  }
}

   


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    int ans=n/m;
    if(n%m) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$stdin = trim(fgets(STDIN));
$ary = explode(" ", $stdin);
$a = $ary[0];
$b = $ary[1];
$c = $ary[2];
$cnt = 0;
for ($i = $a; $i <= $b; $i++) {
  if ($c % $i == 0) {
    $cnt++;
  }
}
echo $cnt . PHP_EOL;

Measured memory_bytes: 15420
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        if(s.length()%2==1) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }
  int r = a % b;
  if (r == 0) return b;
  return gcd(b, r);
}

int main() {
  int K;
  cin >> K;
  int ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      int a = gcd(i, j);
      for (int k = 1; k <= K; k++) {
        int b = gcd(a, k);
        ans += b;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main(){
  ll n,i;
  cin >> n;
  vector<ll> a(n);
  map<ll,ll> mp;
  for(i=0;i<n;++i){
    cin >> a[i];
    mp[a[i]]++;
  }
  vector<ll> d(200020,-1);
  ll ans=0;
  for(auto p :mp){
    ans+=(p.second*(p.second-1))/2;
    d[p.first]=p.second;
  }
  //vector<ll> dp(200010,-1);
  for(ll k=0;k<n;++k){
    d[a[k]]--;
    ll cal=ans-d[a[k]];
    cout << cal << endl;
    d[a[k]]++;
  }
  return 0;

}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll H, W; cin >> H >> W;

	if (H == 1 && W == 1) {
		print(1);
	} else if (H == 1 || W == 1) {
		print(max(H, W) - 2);
	} else {
		print(H * W - 2 * H - 2 * W + 4);
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		List<Integer> num = new ArrayList<>();
		List<Integer> min = new ArrayList<>();
		int n, m = Integer.MAX_VALUE, M = Integer.MIN_VALUE;

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int tmp;

		for (int i = 0; i < n; i++) {
			tmp = sc.nextInt();
			if (tmp < m) {
				m = tmp;
			}
			num.add(tmp);
			min.add(m);
		}
		sc.close();

		for (int i = 1; i < n; i++) {
			tmp = num.get(i) - min.get(i - 1);
			if (tmp > M) {
				M = tmp;
			}
		}
		System.out.println(M);
	}
}



Measured memory_bytes: 109984
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
      
      
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
    
  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
      
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3112
char a[2][204];n,m,i,j,c,p;main(s){for(;i=scanf(m="%d %[^\n] %[^\n]",&n,a,a+1)>2;printf(m<n?"%d\n":"NA\n",m)){for(;~i;m>c?m=c:0)for(j=i--,c=p=0;s=a[j][p+p]-50,c<n&&!s|n+~p;)p+=p<n&&s?~s|a[j][p+p+2]-49?j=!j,++c,2:1:-1;}}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
    long long int i,n,hito[5],x;
    scanf("%lld",&n);
    
    for(i = 0;i<=4;i++){
        scanf("%lld",&hito[i]);
    }
    x= hito[0];
    for(i=1;i<=4;i++){
        x = (x > hito[i])? hito[i] : x;
    }
    printf("%lld",(n-1) / x + 5);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  100000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a[13][13];
    int c[13];
    int n, m, x;
    int ans = INT_MAX;
    
    scanf("%d%d%d", &n, &m, &x);
    rep(i, n){
        scanf("%d", &c[i]);
        rep(j, m){
            scanf("%d", &a[i][j]);
        }
    }

    rep(s, 1<<n) {
        int cost = 0;
        int d[max] = {0};
        rep(i, n) {
            if (s>>i&1) {
                cost += c[i];
                rep(j, m){
                    d[j] += a[i][j];
                }
            }
        }

         bool ok = true;
           rep(j, m) {
             if (d[j] < x) {
               ok = false;
               break;
             }
           }
        
        if(ok) ans = fmin(cost, ans);
    }
    
    if (ans == INT_MAX)printf("%d", -1);
    else printf("%d", ans);

    return 0;
}



Measured memory_bytes: 2544
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i,a) for(ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i,a,b) for(ll i(a), _##i(b); i <= _##i; ++i)
using namespace std;
using ll = long long;

void solve(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for(int &v : p) cin >> v;
    for(int &v : q) cin >> v;
    for(int &v : r) cin >> v;

    sort(RALL(p));
    sort(RALL(q));
    sort(ALL(r));

    while (p.size() > x) p.pop_back();
    while (q.size() > y) q.pop_back();

    ll ans = 0;
    while (r.size() && (p.size() || q.size())){
        bool still = false;
        if (p.size() && q.size()){
            while (r.size() && p.size() && q.size() && p.back() <= q.back() && r.back() > p.back()){
                ans += r.back();
                p.pop_back();
                r.pop_back();
                still = true;
            }
            while (r.size() && p.size() && q.size() && q.back() <= p.back() && r.back() > q.back()){
                ans += r.back();
                q.pop_back();
                r.pop_back();
                still = true;
            }
        } else if (p.size()){
            while (r.size() && p.size() && p.back() < r.back()){
                ans += r.back();
                p.pop_back();
                r.pop_back();
                still = true;
            }
        } else if (q.size()){
            while (r.size() && q.size() && q.back() < r.back()){
                ans += r.back();
                q.pop_back();
                r.pop_back();
                still = true;
            }
        } else break;
        if (!still) break;
    }
    while (p.size()) ans += p.back(), p.pop_back();
    while (q.size()) ans += q.back(), q.pop_back();
    cout << ans << "\n";
}

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

    int T = 1;
    //cin >> T;
    FOR(i,1,T){
        solve();
    }
}


Measured memory_bytes: 1408
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toCharArray();
		int length = S.length;
		int cnt = 0;

		for(int i=0;i<length;i++) {
			if(S[i]!=S[length-i-1]) {
				cnt++;
			}
          	S[i] = S[length-i-1];
		}
		System.out.println(cnt);
	}

}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    
    vector<ll> s(n+2, 0);
    vector<ll> x(n+2, 0);
    ll cnt = 0;
    rep(i, n){
		s[i+1] = s[i] + a[i];
		x[i+1] = x[i] ^ a[i];
	}
	
    ll l=0;
	rep(r, n+1){
		while((s[r]-s[l]) != (x[r]^x[l])) l++;
		cnt += r-l;
	}

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>

using namespace std;

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

    for(int i=0;i<(1<<n);i++)
    {
        cout<<i<<":";
        for(int j=0;j<n;j++)
        {
            if((i>>j)&1) cout<<" "<<j;
        }
        cout<<endl;
    }


    return 0;
}



Measured memory_bytes: 3104
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var ok bool
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if i*j == n {
				ok = true
			}
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1772
H, W = [ int(x) for x in input().split() ]
Cs = [ input() for _ in range(H) ]

ans = ""
for i in range(2 * H):
    for j in range(W):
        ans += Cs[i//2][j]
    if i != 2 * H - 1:
        ans += "\n"

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    for(int i = 0; i < n-1; i += 2){
        
        ans += a.at(i)-a.at(i+1);

    } 

    if(n%2)ans += a.at(n-1);

    cout << ans << endl;

}

Measured memory_bytes: 256
import math
v1, v2, v3 = [int(x) for x in input().split()]
 
flag = (4 * v1 * v2 < (v3 - v1 - v2) ** 2)
if v3 - v1 - v2 < 0:
	print("No")
else:
	print("Yes" if flag else "No")

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

int const N = 100000, md = 998244353;
int dp[N + 1][1 << 4];
map<pair<int, int>, int> mp, sh;

inline void ad(int &x, int y) { if ((x += y) >= md)x -= md; }
inline int pw(int x, ll p){
	int an = 1;
	while (p){
		if (p & 1)an = (ll)an * x % md;
		x = (ll)x * x % md;
		p >>= 1;
	}
	return an;
}
inline int bc(int x){
	int an = 0;
	while (x){
		++an;
		x ^= x & -x;
	}
	return an;
}

int getS1(int msk){
	int x[4] = { msk >> 0 & 1, msk >> 1 & 1, msk >> 3 & 1, msk >> 4 & 1 };
	int an = 0;
	f(i, 0, 4)an |= x[i] << i;
	return an;
}

int getS2(int msk){
	int x[4] = { msk >> 4 & 1, msk >> 5 & 1, msk >> 7 & 1, msk >> 8 & 1 };
	int an = 0;
	f(i, 0, 4)an |= x[i] << i;
	return an;
}

int st[9];
bool cho(int x){
	f(i, 0, 9)if (st[i] != 2 && (x >> i & 1) != st[i])return false;
	if (bc(x) & 1)return false;
	return true;
}

int getMp(int a, int b){
	map<pair<int, int>, int>::iterator it = mp.find(make_pair(a, b));
	if (it == mp.end())return 2;
	return it->second;
}

void fil(int z){
	st[0] = getMp(z, z);
	st[1] = getMp(z, z + 1);
	st[2] = getMp(z, z + 2);
	st[3] = getMp(z + 1, z);
	st[4] = getMp(z + 1, z + 1);
	st[5] = getMp(z + 1, z + 2);
	st[6] = getMp(z + 2, z);
	st[7] = getMp(z + 2, z + 1);
	st[8] = getMp(z + 2, z + 2);
}

void flsm(int z){
	st[0] = getMp(z, z);
	st[1] = getMp(z, z + 1);
	st[2] = 2;
	st[3] = getMp(z + 1, z);
	st[4] = getMp(z + 1, z + 1);
	st[5] = 2;
	st[6] = 2;
	st[7] = 2;
	st[8] = 2;
}

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
		
	ll np = (ll)n * n - n >> 1;
	np -= n - 1 + n - 2;
	
	f(i, 0, m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		mp[make_pair(a, b)] = c;
		if (abs(a - b) <= 2)continue;
		map<pair<int, int>, int>::iterator it = sh.find(make_pair(a, b));
		if (it != sh.end() && it->second != c) { printf("0\n"); return 0; }
		else if (it == sh.end()){
			swap(a, b);
			sh[make_pair(a, b)] = c, --np;
		}
	}
	ll an = pw(2, np);
	
	flsm(1);
	f(a, 0, 4)f(b, 0, 4){
		int msk = a | b << 3, s = a | b << 2;
		if (cho(msk))dp[2][s] = 1;
	}
	
	f(i, 3, n + 1){
		fil(i - 2);
		f(j, 0, 1 << 9)if (cho(j) && !(bc(getS2(j)) & 1))ad(dp[i][getS2(j)], dp[i - 1][getS1(j)]);
	}
	
	int tmp = 0;
	f(i, 0, 1 << 4)ad(tmp, dp[n][i]);
	
	an = (ll)an * tmp % md;
	printf("%lld\n", an);
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 10 15:48:32 JST 2020
 **/

signed main() {
    Int a, b, c, d, n;
    std::cin >> a >> b >> c >> d >> n;
    Int a1 = n / 2 * std::min({a * 8, b * 4, c * 2, d});
    Int a2 = n % 2 * std::min({a * 4, b * 2, c});
    std::cout << a1 + a2 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

const string YES = "YES";
const string NO = "NO";

void solve(long long N, long long A, long long B, long long C, long long D) {
    bool flg = false;
    rep(i, N) {
        if (i * C - (N - 1 - i) * D + A <= B && B <= i * D - (N - 1 - i) * C + A) flg = true;
    }
    if (flg)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(N, A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t n;
  cin >> n;
  cout << 3 * pow(n, 2) << endl;
  return 0;
}



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

int main()
{
  int64_t x, y;
  cin >> x >> y;
  if (x % y == 0)
  {
    cout << -1 << endl;
  }
  else
  {
    int64_t i = 1;
    while ((x * i) % y == 0)
    {
      i++;
    }
    cout << x * i << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,b,c;
    cin >> n >> m;
    vector<ll> a(n),ncard;
    cins(all(a));
    SORT(a);
    vector<P> card(m);
    rep(i,m){
        cin >> b >> c;
        card[i] = P(c,b);
    }
    RSORT(card);
    ll cnt = 0;
    rep(i,m){
        tie(c,b) = card[i];
        rep(_,min(b,n-cnt)){
            ncard.push_back(c);
        }
        if (b >= n-cnt) break;
        cnt += b;
    }
    ll ans = 0;
    rep(i,ncard.size()){
        ans += max(a[i],ncard[i]);
    }
    rep(i,ncard.size(),n){
        ans += a[i];
    }
    PRINT(ans);
}


Measured memory_bytes: 3832
N=int(input())
H=[int(x) for x in input().split()]
ans=True
if N!=1:
  for i in range(len(H)-1,0,-1):
    if H[i]<H[i-1]:
      if H[i-1]-H[i]==1:
        H[i-1]-=1
      else:
        ans=False
        break
if ans:
  print('Yes')
else:
  print('No')

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;
const ll INF = 1e18L + 5;

vector<ll> h;

struct line{
    ll m, c;
    ll val(ll x){
        return m * x + c;
    }
    ll intesectX(line b){
        /// mx + c = b.mx + b.c
        ll x = (b.c - c) / (m - b.m);
        return x;
    }
};

void solve(){
    ll n, c, x;
    cin>>n>>c;
    h.resize(n);
    fr(i, n) {
        cin>>h[i];
    }

    deque<line> dq;

    auto d = [&](ll x){
        return x * x;
    };

    dq.push_back({-2ll * h[0], 0ll + d(h[0])});
    ll best = 0ll;
    rep(i, 1, n-1){
        x = h[i];
        /// query
        while(dq.size() >= 2 && dq.back().val(x) >= dq[dq.size() - 2].val(x))
            dq.pop_back();
        ll val = dq.back().val(x);
        best = c + d(h[i]) + val;
        line l = {-2ll * h[i], best + d(h[i])};

        /// insertion
        while(dq.size() >= 2 && l.intesectX(dq.front()) <= dq.front().intesectX(dq[1]))
            dq.pop_front();

        dq.push_front(l);
    }

    cout<<best;
}

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

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

    return 0;
}



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

int main() {
	long long N;
	long long X, M;
	cin >> N >> X >> M;
	vector<long long> A, C(M, -1);
	A.push_back(X);
	C[X] = 0;
	long long ans = X;
	long long a = X;
	for (long long i = 1; i < N; i++) {
		a = a * a % M;
		ans += a;
		if (C[a] >= 0) {
			long long loop = 0;
			long long length = A.size() - C[a];
			for (long long j = C[a]; j < A.size(); j++) loop += A[j];
			ans -= a;
			ans += loop * ((N - i) / length);
			i += length * ((N - i) / length);
			for (long long j = 0; i + j < N; j++) ans += A[C[a] + j];
			i = N;
		}
		else {
			C[a] = i;
			A.push_back(a);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4692
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9)
    puts("-1");
  else
    cout << a * b << '\n';
}

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

int main(void){
    int k,n;
    cin>>n>>k;
    vector<int> P(n);
    rep(i,n) cin>>P[i];
    sort(P.begin(),P.end());
    int ans=0;
    rep(i,k) ans+=P[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
N,K = list(map(int, input().split()))
win = 0
#全事象に対して
for i in range(N):
    #確率
    j = 1
    k = j + i
    #現在のスコア<目的スコアになるまで
    while k < K:
        #コイントスごとに確率は1/2になる
        j /= 2
        #現在のスコアは2倍になる
        k *= 2
    #while文を通らなかったものは１が足される
    win += j
print(win/N)

Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int Aflg = 0,Cflg = 0,Ccnt = 0,Cidx = 0,Sup = 0;
		if(S.charAt(0) == 'A') Aflg = 1;
		
		for(int i = 2;i < S.length() - 1;i ++) {
			if(S.charAt(i) == 'C') {
				Ccnt ++;
				Cidx = i;
			}
		}
		if(Ccnt == 1) {
			Cflg = 1;
			for(int i = 1;i < S.length();i ++) {
				if(i != Cidx) {
					if(Character.isUpperCase(S.charAt(i)) == true) Sup = 1;
				}
			}
		}
		
		if(Aflg == 1 && Cflg == 1 && Sup ==0) {
			System.out.println("AC");
		}else {
			System.out.println("WA");
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;
const ll INF = 1E+18;

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  rep(i, n-2) {
    vector<int> now;
    rep(j, 3) {
      now.push_back(p[i+j]);
    }
    sort(now.begin(), now.end());
    if (now[1]==p[i+1]) ans++;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      int n = in.nextInt();
      long[] t = new long[n];
      for (int i = 0; i < t.length; i++) {
        t[i] = in.nextLong();
      }

      long ans = 1;
      for (int i = 0; i < t.length; i++) {
        ans = lcm(ans, t[i]);
      }

      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  long gdc(long a, long b) {
    if(b == 0) return a;
    return gdc(b, a % b);
  }
  long lcm(long a, long b) {
    return b / gdc(a, b) * a;
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }

    public String nextLine() throws IOException {
      return br.readLine();
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main()
{	
	int a,b;
	cin>>a>>b;
	if(b>=a)cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
	return 0;
}

Measured memory_bytes: 3604
a,b = map(int,input().split())

c = list(map(int,input().split()))
c.sort()

d = []
for i in range(b-1):
    d.append(c[i+1] - c[i])

d.sort()

#print(c,d)

for k in range(a - 1):
    if d == []:
        print(0)
        exit()
    d.pop()

print(sum(d))

Measured memory_bytes: 13968
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    long long H;
    cin >> N >> H;
    vector<long long> A(N), B(N);
    
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i];
    }
    sort( A.begin(), A.end(), greater<long long>() );
    sort( B.begin(), B.end(), greater<long long>() );
    
    long long ans = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( B[i] >= A[0] ) {
            H -= B[i];
            ans++;
        }
        if ( H <= 0 ) { break; }
    }
    if ( H > 0 ) {
        ans += (H/A[0]) + ( (H%A[0]) ? 1 : 0 );
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
(function(input) {
  var p = input.replace(/\n$/, '').split('\n\n');
  for (var j = 0; j < p.length; j++) {
    var b = p[j].split('\n');
    var m = [];
    for (var i = 0; i < b.length; i++) {
      m.push(b[i].split('').map(Number));
    }
    console.log(exists(m));
    //console.log(m);
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function exists(m) {
  for (var i = 0; i < 8; i++) {
    for (var j = 0; j < 8; j++) {
      if (m[i][j] === 1) {
        return exists_(m, j, i);
      }
    }
  }
}

function exists_(m, x, y) {
  if (check(m, x + 1, y) && check(m, x, y + 1) && check(m, x + 1, y + 1)) {
    return 'A';
  }
  if (check(m, x, y + 1) && check(m, x, y + 2) && check(m, x, y + 3)) {
    return 'B';
  }
  if (check(m, x + 1, y) && check(m, x + 2, y) && check(m, x + 3, y)) {
    return 'C';
  }
  if (check(m, x, y + 1) && check(m, x - 1, y + 1) && check(m, x - 1, y + 2)) {
    return 'D';
  }
  if (check(m, x + 1, y) && check(m, x + 1, y + 1) && check(m, x + 2, y + 1)) {
    return 'E';
  }
  if (check(m, x, y + 1) && check(m, x + 1, y + 1) && check(m, x + 1, y + 2)) {
    return 'F';
  }
  if (check(m, x + 1, y) && check(m, x, y + 1) && check(m, x - 1, y + 1)) {
    return 'G';
  }

}

function check(m, x, y) {
  if (x < 0 || x > 7 || y < 0 || y > 7) {
    return false;
  }
  return m[y][x] === 1;
}

Measured memory_bytes: 8684
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    while(1){
        if(s.size()==0)break;
        else if(s.substr(0,5)=="maerd")s=s.substr(5,s.size()-5);
        else if(s.substr(0,7)=="remaerd")s=s.substr(7,s.size()-7);
        else if(s.substr(0,5)=="esare")s=s.substr(5,s.size()-5);
        else if(s.substr(0,6)=="resare")s=s.substr(6,s.size()-6);
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

template <typename T>
vector<pair<T, ll>> rle(vector<T> v)
{
    vector<pair<T, ll>> ret;
    ret.reserve(v.size() / 2);
    for (const auto x : v)
    {
        if (ret.empty() || ret.back().first != x)
        {
            ret.emplace_back(x, 1);
        }
        else
        {
            ++ret.back().second;
        }
    }
    return ret;
}
vector<pair<char, ll>> rle(string s)
{
    vector<pair<char, ll>> ret;
    ret.reserve(s.size() / 2);
    for (const auto c : s)
    {
        if (ret.empty() || ret.back().first != c)
        {
            ret.emplace_back(c, 1);
        }
        else
        {
            ++ret.back().second;
        }
    }
    return ret;
}

void Main()
{
    string s;
    cin >> s;
    auto v = rle(s);

    vll sum(v.size() + 1, 0);

    rep(i, v.size())
    {
        sum[i + 1] = sum[i] + v[i].second;
    }

    ll ans = LINF;
    rep(i, v.size())
    {
        ans = min(ans, max(sum[i], sum[v.size()] - sum[i]));
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

int main()
{
    std::string word;
    std::string w = "No";
    int64_t a,b,c,d,e,f;
    std::cin>> a;

    c = 0;

    for( int i = 1; i <= a; i++ )
    {
        if( i % 15 == 0 )
        {
            //break;
        }
        else if( i % 3 != 0
                 && i % 5 != 0 )
        {
            c += i;
        }
    }

    std::cout<< c;

}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++){
			if(i==0){
				A[0] = 0;
				continue;
			}
			A[i] = sc.nextInt();
		}
		sc.close();

		int[] ret = getProcess(N, A);

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

	public static int[] getProcess(int N, int[] A){
		int[] ret = new int[N];
		for(int i=0; i<ret.length; i++){
			ret[i] = 0;
		}

		for(int i=0; i<A.length; i++){
			if(A[i]==0){
				continue;
			}
			ret[ A[i]-1 ] ++;
		}

		return ret;
	}


}

Measured memory_bytes: 58400
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int a,b,c,d,e,k;
  cin >> a >>b >>c>>d>>e>>k;
  if(b-a<=k && c-b<=k && d-c<=k && e-d <= k && c-a<=k && d-a<=k && e-a<=k && d-b<=k && e-b<=k && e-c<=k) print("Yay!");
  else print(":(");

 return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_left
import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
A = list(map(int, input().split()))
dp = [float('inf')] * N
tree = defaultdict(list)
for _ in range(N - 1):
	u, v = list(map(int, input().split()))
	tree[u-1].append(v-1)
	tree[v-1].append(u-1)

dp[0] = A[0]
ans = [float('inf')] * N
ans[0] = 1
def backtrack(node, visited, tail_idx):
	flag = any([nx not in visited for nx in tree[node]])
	if not flag:
		return
	for nx in tree[node]:
		if nx in visited:
			continue
		visited.add(nx)
		idx = bisect_left(dp, A[nx])
		prev = dp[idx]
		if tail_idx < idx:
			dp[idx] = A[nx]
			new_tail_idx = idx
			ans[nx] = min(new_tail_idx + 1, ans[nx])
			backtrack(nx, visited, new_tail_idx)
		elif A[nx] < dp[idx]:
			dp[idx] = A[nx]
			ans[nx] = min(tail_idx + 1, ans[nx])
			backtrack(nx, visited, tail_idx)
		else:
			ans[nx] = min(tail_idx + 1, ans[nx])
			backtrack(nx, visited, tail_idx)
		dp[idx] = prev
		visited.remove(nx)

backtrack(node=0, visited={0}, tail_idx=0)
for i in ans:
	print(i)

Measured memory_bytes: 410256
#include <stdio.h>

int main(){
	int a[10] = {0}, i=0, j=0, k=0, l=0, b, c;
	
	for(c=0;c<10;c++){
		scanf("%d", &a[c]);
	}
	
	for(b=0;b<9;b++){
		for(j=9;j>=0;j--){
			if(a[j]<a[j-1]){
				k = a[j];
				a[j] = a[j-1];
				a[j-1] = k;
			}
		}
	}
	j = a[9];
	k = a[8];
	l = a[7];
	
	printf("%d\n%d\n%d\n", j, k, l);
	return 0;
}

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

#define endl '\n'
#define ll long long
#define ull unsigned long long
#pragma GCC optimize("-O3")
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int inf=0x3f3f3f3f;
const int MAXN=101010;
const ull mod=1e9+7;

ll a[MAXN];

int main() {
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++) {
        int nans=0;
        cin>>a[i];
    }
    int nans=0;
    for(int i=1;i<n;i++) {
        if(a[i]<=a[i-1]) {
            nans++;
        }
        else nans=0;
        ans=max(ans,nans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = int long long;
map <int ,int> mpa,mpb;

int main(){
  int N;
  cin >> N;
  ll a[N+1],b[N+1];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  for(int i=0;i<N;i++){
    cin >> b[i];
  }
  ll ans1=0, ans2=0;
  for(int i=0;i<N;i++){
    if(a[i]<b[i]){
      ans1+=(b[i]-a[i])/2;
    }
    else{
      ans2+=a[i]-b[i];
    }
  }
  if(ans1 >= ans2 ){
    cout << "Yes";
    return 0;
  }
  else {
    cout << "No";
    return 0;
  }
}

Measured memory_bytes: 384
import sys
n,x = map(int, sys.stdin.readline().rstrip("\n").split())
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a.sort()
ans = 0
for i in range(n):
    if i == n-1:
        if x - a[i] == 0:
            ans += 1
    else:
        if x-a[i] >= 0:
            x = x-a[i]
            ans += 1
print(ans)

Measured memory_bytes: 62024
#include<iostream>
using namespace std;
int main(){
	int n,temp;
	cin>>n;
	int num[n+1];
	for(int i=0;i<=n;i++){
		num[i]=0;
	}
	for(int i=0;i<n-1;i++){
		cin>>temp;
		num[temp]+=1;
	}
	for(int i=1;i<=n;i++){
		cout<<num[i]<<endl;
	}
}

Measured memory_bytes: 4332
#include <cstdio>
#include <iostream>

using namespace std;
const int N = 200010;
int n,q,cnte,head[N];
int lazy[N],ans[N];
struct edge{
	int to,nxt;
}e[N<<1];
void add(int u,int v){
	e[++cnte]=(edge){v,head[u]};
	head[u]=cnte;
}
void dfs(int u,int fa){
	ans[u]=lazy[u];
	for(int i=head[u]; i; i=e[i].nxt){
		int v=e[i].to;
		if(v==fa){
			continue;
		}
		lazy[v]+=lazy[u];
		dfs(v, u);
	}
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1; i<n; i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u, v);
		add(v, u);
	}
	for(int i=1; i<=q; i++){
		int p,x;
		scanf("%d%d",&p,&x);
		lazy[p]+=x;
	}
	dfs(1, 0);
	for(int i=1; i<=n; i++){
		printf("%d ",ans[i]);
	}
	return 0;
}


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

int cmp(const void *a, const void *b)
{ return *(int *)b - *(int *)a ;}

int main()
{
  int n,i,j,k,count=0;
  int *l;

  scanf("%d", &n);
  l = calloc(n,sizeof(int));

  for(i=0; i<n; i++)
    scanf("%d",&l[i]);

  qsort(l,n,sizeof(int),cmp);

  for(i=0; i<n-2; i++){
    for(k=i+1; k<n-1; k++){
      for(j=k+1; j<n; j++){
        if(l[i]+l[k]>l[j] && l[k]+l[j]>l[i] && l[j]+l[i]>l[k])
        count++;
      }
    }
  }

  printf("%d", count);
  free(l);
  return 0;
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  long long int ans = 0;
  for (int i = 0; i < N-2; i++){
    for (int j = i+1; j < N-1; j++){
      int left = j+1;
      int right = N-1;
      int a = L.at(i);
      int b = L.at(j);
      if (L.at(left) < a + b && L.at(right) >= a + b){
        while(right - left > 1){
         int mid = left + (right - left) / 2;
          if(L.at(mid) < L.at(i) + L.at(j)){
           left = mid;
          } else {
           right = mid;
          }
        }
        ans += left - j;
      } else if (L.at(right) < a + b){
        ans += right - left + 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}

fn main() {

    let line = read_line();
    let n: i64 = to_i(&line);
    let s = read_line();
    let mut count = 0;
    for c in s.chars() {
        if c=='R' {
            count+=1;
        }
    }
    let count2 = n-count;


    let result = count > count2;
    if result {
        print!("Yes");
    } else {
        print!("No");
    }

    

}   

Measured memory_bytes: 4352