akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ASSERT(C, ...) assert( (C) || (PRINT(__VA_ARGS__), false) )
template <class Head> void PRINT(Head head) {
    std::cout << head << "\n";
}
template <class Head, class... Tail> void PRINT(Head head, Tail... tail) {
    std::cout << head << " ";
    PRINT(tail...);
}

ll solve() {
    ll N;
    cin >> N;
    vector<ll> P(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> P[i];
        P[i]--;
    }
    vector<ll> da(N, 1), db(N, 1);
    for ( int i = 0; i < N; i++ ) {
        int p = P[i];
        if ( p < N-1 ) {
            da[p+1] += N-i;
        }
        if ( p > 0 ) {
            db[p-1] += N-i;
        }
    }
    vector<ll> a(N), b(N);
    ll sa = 0, sb = 0;
    for ( int i = 0; i < N; i++ ) {
        sa += da[i];
        a[i] = sa;
    }
    for ( int i = N-1; i >= 0; i-- ) {
        sb += db[i];
        b[i] = sb;
    }
    // for ( int i = 1; i < N; i++ ) {
    //     ASSERT(a[P[i-1]]+b[P[i-1]] < a[P[i]]+b[P[i]], i);
    // }

    for ( int i = 0; i < N; i++ ) {
        cout << (i != 0 ? " " : "") << a[i];
    }
    cout << "\n";
    for ( int i = 0; i < N; i++ ) {
        cout << (i != 0 ? " " : "") << b[i];
    }
    cout << "\n";
    return 0;
}

int main() {
    solve();
    return 0;
}

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


Measured memory_bytes: 7372
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

I = list(map(lambda x: x[0], Y[0:min(N-1, len(Y))]))
I.sort()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    if last < I[i]:
        Z.append(X[last:I[i]])
        last = I[i]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    if len(array) > 0:
        u = max(array)
        l = min(array)
        s += u - l

print(s)

Measured memory_bytes: 51104
N,P=map(int,input().split())
A=list(map(int,input().split()))
g=k=0
for i in A:
    if i%2:
        k+=1
    else:
        g+=1
a=0
from math import factorial
if P:
    for i in range(1,k+1,2):
        a+=factorial(k)//factorial(i)//factorial(k-i)
else:
    for i in range(0,k+1,2):
        a+=factorial(k)//factorial(i)//factorial(k-i)
print(a*pow(2,g))

Measured memory_bytes: 3064
// 29/07/19 // 7:10 PM //

#include <iostream>
#include <cstring>

using namespace std;

#define MAXN 110
#define MAXW 100010

int n, w;
int weight[MAXN], value[MAXN];

long long memo[MAXN][MAXW];

long long knapsack(int i, int over){
    if(memo[i][over]>=0) return memo[i][over];

    if(i>n) return memo[i][over] = 0LL;

    long long take=0LL, dtake = dtake = knapsack(i+1, over);;

    if(over-weight[i]>=0)
        take = value[i] + knapsack(i+1, over-weight[i]);

    return memo[i][over] = max(dtake, take);
}

int main(){

    memset(memo, -1, sizeof(memo));

    cin >> n >> w;

    for(int i=1; i<=n; i++)
        cin >> weight[i] >> value[i];

    cout << knapsack(1, w) << "\n";

    return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6 + 8;
const int MOD = 1e9 + 7;
const int sz = 1e5 + 5;
void f_io(){
    #ifndef ONLINE_JUDGE
    FRE
    #endif
}


int32_t main(){
    // f_io();
    IOS;
    int tc = 1;
    //cin>>tc;
    while(tc--){
        int n; cin >> n;
        if(n >= 30) cout << "Yes" << endl;
        else cout << "No" << endl;

    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll a,b,c,n;
ll res;
int main()
{
	cin >>a>>b>>c>>n;
	if (n<=a) res+=1*n,n=0;
	else res+=1*a,n-=a;
	if (n<=b) res+=0*n,n=0;
	else res+=0*b,n-=b;
	if (n<=c) res-=1*n,n=0;
	else res-=1*c,n-=c;
	cout <<res;
	return 0;
}

Measured memory_bytes: 3672
from collections import defaultdict

while True:
    n = int(input())
    
    if n==0:
        break
    
    initial = defaultdict(set)
    cnt = defaultdict(int)
    
    for _ in range(n):
        l = list(input().split())
        
        for li in l:
            initial[li[0]].add(li)
            cnt[li] += 1
    
    k = input()
    ans = list(initial[k])
    
    if len(ans)==0:
        print('NA')
        continue
    
    ans.sort()
    ans.sort(key=lambda w: cnt[w], reverse=True)
    
    if len(ans)<5:
        print(*ans)
    else:
        print(*ans[:5])


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

fn read_stdin() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().to_string()
}

fn main() {
    let input: String = read_stdin();

    if input.contains('a') && input.contains('b') && input.contains('c') {
        print!("Yes");
    } else {
        print!("No");
    }
}

Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for ( ;; ) {
      int N = ni();
      int M = ni();
      if ( ( N | M ) == 0 ) {
        break;
      }

      int[][] imos = new int[M + 1][1261];

      int r = ni();
      for ( int i = 0; i < r; ++i ) {
        int t = ni();
        int n = ni();
        int m = ni();
        int s = ni();

        imos[ m ][ t ] += 2 * s - 1;
      }

      int q = ni();
      for ( int i = 0; i < q; ++i ) {
        int ts = ni();
        int te = ni();
        int m = ni();

        int v = 0;
        int cnt = 0;
        for ( int j = 0; j < te; ++j ) {
          v += imos[ m ][ j ];
          if ( v > 0 && ts <= j ) {
            ++cnt;
          }
        }

        System.out.println( cnt );
      }
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

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

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 208392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///find_by_order, order_of_key

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int MAXA = 1e6;
int a[MAXA+1], kolikoIma[MAXA+1], delioci[MAXA+1];

int main()
{
    #ifdef ljuba
    auto pocetakChronoSata123 = high_resolution_clock::now();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);       
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;

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

    for(int i = 1; i <= MAXA; ++i)
    {
        for(int j = i; j <= MAXA; j += i)
        {
            delioci[j] += kolikoIma[i];
        }
    }

    int res = 0;
    for(int i = 0; i < n; ++i)
    {
        if(delioci[a[i]] == 1)
            ++res;
    }

    cout << res << '\n';

    #ifdef ljuba
    auto krajChronoSata123 = high_resolution_clock::now();
    auto trajanje = duration_cast<microseconds>(krajChronoSata123 - pocetakChronoSata123);
    cout << "----------------------------------------------------\n";
    cout << "Vreme u milisekundama: " << (ld)trajanje.count() / 1000.00 << '\n';
    #endif
    return 0;
}

Measured memory_bytes: 12080
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
    int id;
};

int partition(struct Card A[], int n, int p, int r){
    int i,j;
    struct Card t,x;
    x = A[r];
    i = p-1;
    for (j = p;j<r;j++){
        if (A[j].value <= x.value){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if (p<r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i=0;i<n;i++){
        scanf("%s %d", S, &v);
        A[i].suit = S[0];
        A[i].value = v;
        A[i].id = i;
    }

    quickSort(A, n, 0, n-1);

    for (i=0;i<n;i++){
        if (A[i-1].value == A[i].value && A[i-1].id > A[i].id){
            stable = 0;
            break;
        }
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i=0;i<n;i++){
        printf("%c %d\n", A[i].suit, A[i].value);
    }

    return 0;
}


Measured memory_bytes: 2980
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define MOD 1000000007
#define N 401000
#define M 100005
using namespace std;
struct ED{
	int v,w,next;
}ed[201000];
int head[201000],cnt;
long long ww[N];
int add(int u,int v,int w)
{
	ed[cnt].v=v;
	ed[cnt].w=w;
	ed[cnt].next=head[u];
	head[u]=cnt++;
}
int dfs(int u,int fa,long long w)
{
	ww[u]=w;
	for(int i=head[u];i!=-1;i=ed[i].next)
	{
		int v=ed[i].v;
		if(fa==v)
			continue;
		dfs(v,u,w+ed[i].w);
	}
}
int main()
{
	int i,j,n,m,u,v,w,q,k;
	long long tp;
	memset(head,-1,sizeof(head));
	cnt=0;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d%lld",&u,&v,&tp);
		add(u,v,tp);
		add(v,u,tp);
	}
	scanf("%d%d",&q,&k);
	dfs(k,-1,0);
	while(q--)
	{
		scanf("%d%d",&u,&v);
		printf("%lld\n",ww[u]+ww[v]);
	}
}

Measured memory_bytes: 11392
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int a=0,b=0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='A')
      a+=1;
    else
      b+=1;
  }
  if(a==3||b==3)
    cout<<"No";
  else
    cout<<"Yes";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define eni(x) template < class c > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; return * this; }
eni(==) return * this << range(begin(i), end(i)); }
template < class c, class b > debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template < class c > debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000050
mt19937 myrand(time(0));

int s;
ll dp[2002];

ll call(ll rem){
    if(rem<3) return rem==0;
    ll &ret=dp[rem];
    if(ret!=-1) return ret;
    ret=0;
    for(int i=3;i<=rem;i++) ret=(ret+call(rem-i))%mod;
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    cin>>s;
    memset(dp,-1,sizeof dp);
    ll ans=call(s);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660
program main
   implicit none
   integer n
   integer,allocatable,dimension(:):: h
   integer:: i,j,counter=0
   read(*,*)n
   allocate(h(n))
   read(*,*)h
   do i=1,n
10       continue
      do j=n,i,-1

         if(all(h(i:j)>0))then
            h(i:j)=h(i:j)-1
            counter=counter+1
            goto 10
         endif
      enddo
   enddo
   write(*,*)counter
end program main


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

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

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

struct UnionFind{
  vi par;
  vi rank;

  UnionFind(int n=1){
    init(n);
  }

  // n要素で初期化
  void init(int n=1){
    par.resize(n);
    rank.resize(n);
    REP(i, n){
      par[i]=i;
      rank[i]=0;
    }
  }

  // xの根を求める
  int find(int x){
    if(par[x]==x){
      return x;
    }
    else{
      return par[x]=find(par[x]);
    }
  }

  // xとyが属する集合を併合
  bool unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y){
      return false;
    }
    if(rank[x]<rank[y]){
      par[x]=y;
    }
    else{
      par[y]=x;
      if(rank[x]==rank[y]){
        ++rank[x];
      }
    }
    return true;
  }

  // xとyが同じ集合に属するか判定
  bool issame(int x, int y){
    return find(x)==find(y);
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, a[125252], b[125252];
  pii c[125252], d[125252];
  cin>>n;
  REP(i, n){
    cin>>a[i];
    c[i]=pii(a[i], i);
  }
  REP(i, n){
    cin>>b[i];
    d[i]=pii(b[i], i);
  }
  sort(c, c+n);
  sort(d, d+n);
  REP(i, n){
    if(c[i].first>d[i].first){
      cout<<"No"<<'\n';
      return 0;
    }
  }
  FOR(i, 1, n){
    if(c[i].first<=d[i-1].first){
      cout<<"Yes"<<'\n';
      return 0;
    }
  }
  UnionFind uf(n);
  REP(i, n){
    uf.unite(c[i].second, d[i].second);
  }
  bool ok=false;
  int root=uf.find(0);
  REP(i, n){
    // DEBUG(uf.find(i));
    if(root!=uf.find(i)){
      ok=true;
      break;
    }
  }
  cout<<(ok ? "Yes" : "No")<<'\n';
  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>
#include <functional>
#include <queue>

int main()
{
	long long int N = 0, A = 0, B = 0, ans = 0;
	std::cin >> N >> A >> B;

	long long int s1 = 0, s2 = 0;
	s1 = N / (A + B);
	s2 = N % (A + B);

	ans = s1 * A + std::min(A, s2);
	//std::cout << s1 << "," << s2 << std::endl;
	std::cout << ans << std::endl;

	return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), p.begin() + k, 0) << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int P[220000];

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

    rep(i, n) cin >> P[i];

    int min = P[0];
    int cnt = 1;

    for (int i = 1; i < n; i++) {
        if (P[i] <= min) {
            min = P[i];
            ++cnt;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 4859345
#define int long long
using namespace std;
signed main()
{
	int x,k,d;
	cin>>x>>k>>d;
	int steps=abs(x)/d;
	int now=abs(x);
	now-=(steps*d);
	if(steps==k)
	cout<<now;
	else
	if(steps>k)
	{
		cout<<abs(x)-k*d;
	}
	else
	if((k-steps)%2==1)
	{
		cout<<abs(now-d);
	}
	else
	cout<<now;
	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N, K; cin >> N >> K;
    vector<int>v(N);

    rep(i,N){
        cin >> v[i];
    }

    int ans=-INFint;
    for(int rtake=0; rtake<=min(N,K); rtake++){
        priority_queue<int, vector<int>, greater<int>> pq;
        for(int ltake=0; ltake<=min(N,K); ltake++){

            if(rtake+ltake>K) continue;

            if(rtake+ltake>N){
                for(int i=0; i<N; i++) {
                    pq.push(v[i]);
                }
            }else{
                for(int i=0; i<rtake; i++){
                    pq.push(v[N-1-i]);
                }

                for(int i=0; i<ltake; i++){
                    pq.push(v[i]);
                }
            }

            for(int i=0; i<K-min((rtake+ltake),N); i++){
                if(!pq.empty() && pq.top()<0){
                    pq.pop();
                }
            }

            int sum=0;
            while(!pq.empty()){
                sum+=pq.top();
                pq.pop();
            }

            ans=max(sum, ans);
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, d;
    cin>>n>>d;
    vector<vector<int> > v(n, vector<int>(d));
    rep(i, n){
        rep(j, d) cin>>v[i][j];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            vector<int> s(d);
            rep(k, d) s[k] = pow(v[j][k]-v[i][k], 2);
            int dist2 = accumulate(s.begin(), s.end(), 0);
            bool ok=false;
            rep(k, 160) if(k*k == dist2) ok=true;
            if(ok) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    
    ll n;
    cin>>n;
    unordered_map<ll,ll> umap;
    // freq[]=;
    
    for(int i=0;i<n;i++)
    {   
        ll x;
        cin>>x;
        umap[x]++;    
    }
    int count=0;
    for(auto &x:umap){
        int tmp=x.second-x.first;
        count+=tmp>=0?tmp:x.second;
    }
    cout<<abs(count);
}


Measured memory_bytes: 4260
n=int(input())
ans=100
for i in range(1,n//2+1):
    a=i
    b=n-i
    t=0
    while a>0 or b>0:
        t+=a%10+b%10
        a//=10
        b//=10
    ans=min(t,ans)
print(ans)

Measured memory_bytes: 3060
N=int(input())

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L

S.sort()

goukei=0
banpei=S[0]
ncr=1
for i in range(1,N):
    if banpei==S[i]:
        ncr+=1
    else:
        if ncr>=2:
            goukei+=(ncr*(ncr-1))//2
        ncr=1
        banpei=S[i]

if ncr>=2:
    goukei+=(ncr*(ncr-1))//2 
    

print(goukei)


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, n) { cout << s[i] << t[i]; }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split(' ')))
    def solve(num):
        counter = 0
        while num%2 == 0:
            counter += 1
            num /= 2
        return counter
    a = [solve(i) for i in a]
    print(min(a))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] S = new int[n];
		for(int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		sc.close();
		int count = 0;
		for(int i = 1; i <= n - 2; i++) {
			if((S[i + 1] > S[i])){
				if(S[i] > S[i - 1]) {
					count++;
				}
			}else if((S[i + 1] < S[i])){
				if(S[i] < S[i - 1]) {
					count++;
				}
			}else {
				continue;
			}
		}
		System.out.println(count);
	}
}

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

using namespace std;

int n,m,q;
long long a[100005],b[100005];

long long get(long long x,int i,int j)
{
	if(i<0||j<0||i>=n||j>=m) return (1LL<<60);
	long long aa=a[i],bb=b[j];
	return min(llabs(x-aa)+llabs(aa-bb),llabs(x-bb)+llabs(aa-bb));
}

int main()
{
	cin >> n >> m >> q;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<m;i++) cin >> b[i];
	sort(a,a+n); sort(b,b+m);
	while(q--)
	{
		long long x;
		cin >> x;
		int it1=lower_bound(a,a+n,x)-a;
		int it2=lower_bound(b,b+m,x)-b;
		long long ans=(1LL<<60);
		for(int i=-1;i<=1;i++)
			for(int j=-1;j<=1;j++)
				ans=min(ans,get(x,it1+i,it2+j));
		cout << ans << endl;
	}
}

Measured memory_bytes: 2816
n, X = gets.chomp.split().map(&:to_i)
x = gets.chomp.split().map(&:to_i)

x.push X
x.sort!

diff = []
(x.size-1).times do |i|
  diff.push x[i+1] - x[i]
end

ans = diff[0]

1.upto(diff.size-1).each do |i|
  ans = ans.gcd(diff[i])
end

puts ans

Measured memory_bytes: 11376
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

int main() {
	int N;
	lli K;
	scanf("%d %lld", &N, &K);
	lli ba[100100];
	SET_ZERO(ba);
	for (int i = 0 ; i < N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		ba[a] += b;
	}
	int i;
	for (i = 1; K > 0; i++) {
		K -= ba[i];
	}

	printf("%d\n", i-1);
	return 0;
}



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

using namespace std;

struct Team {
    int id;
    int cnt;
    int penalty;
    int problem[10];

    bool operator<(const Team &r) const {
        if(cnt > r.cnt) {
            return true;
        } else if(cnt == r.cnt) {
            if(penalty < r.penalty) {
                return true;
            } else if(penalty == r.penalty) {
                if(id < r.id) return true;
                else return false;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
};

int main() {

    int t, p, r;
    int tid, pid, time;
    string message;

    while(cin >> t >> p >> r, t | p | r) {

        vector<Team> team(t);

        // Init
        for(int i = 0; i < t; ++i) {
            team[i].id = i + 1;
            team[i].cnt = 0;
            team[i].penalty = 0;
            memset(team[i].problem, 0, sizeof(team[i].problem));
        }

        // SCAN
        for(int i = 0; i < r; ++i) {
            cin >> tid >> pid >> time >> message;
            if(message == "CORRECT") {
                team[tid - 1].cnt++;
                team[tid - 1].penalty += team[tid - 1].problem[pid - 1] * 1200 + time;
            } else if(message == "WRONG") {
                ++team[tid - 1].problem[pid - 1];
            }
        }

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

        for(int i = 0; i < t; ++i) {
            cout << team[i].id << " " << team[i].cnt << " " << team[i].penalty << endl;
        }

    }

}

Measured memory_bytes: 1244
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
#include <queue>

using namespace std;

#define int long long

class Solver {
};

signed main() {
	while (true) {
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		s--;
		d--;
		if (c == 0)break;

		vector<vector<vector<tuple<int, int, int>>>> graph(c + 1,
			vector<vector<tuple<int, int, int>>>(n));

		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			a--;
			b--;
			for (int i = 0; i <= c; i++) {
				graph[i][a].emplace_back(make_tuple(i, b, f));
				graph[i][b].emplace_back(make_tuple(i, a, f));
				if (i < c) {
					graph[i][a].emplace_back(make_tuple(i + 1, b, f/2));
					graph[i][b].emplace_back(make_tuple(i + 1, a, f/2));
				}
			}
		}

		priority_queue<tuple<int, int, int>> que;
		vector<vector<int>> dist(c + 1, vector<int>(n, 1e9));
		que.emplace(make_tuple(0, s, 0));
		while (que.size() > 0) {
			int cnt = get<0>(que.top());
			int pos = get<1>(que.top());
			int distance = get<2>(que.top());
			que.pop();
			if (dist[cnt][pos] <= distance)continue;

			dist[cnt][pos] = distance;
			for (int i = 0; i < graph[cnt][pos].size(); i++) {
				int cnt_t = get<0>(graph[cnt][pos][i]);
				int pos_t = get<1>(graph[cnt][pos][i]);
				int distance_t = get<2>(graph[cnt][pos][i]);
				distance_t += distance;

				if (dist[cnt_t][pos_t] <= distance_t)continue;

				que.emplace(make_tuple(cnt_t, pos_t, distance_t));
			}
		}

		int res = 1e9;
		for (int i = 0; i <= c; i++)res = min(res, dist[i][d]);
		cout << res << endl;
	}
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

ll a[72];

ll ans = 0;

int main(){

  REP( i , 7 ){
    a[i] = in();
  }

  ans = a[1] * 2;

  if( a[0] > 0 and a[3] > 0 and a[4] > 0 and a[0] % 2 + a[3] % 2 + a[4] % 2 >= 2 ){
    ans += 6;
    a[0]--;
    a[3]--;
    a[4]--;
  }

  ans += a[0] / 2 * 4;
  ans += a[3] / 2 * 4;
  ans += a[4] / 2 * 4;

  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    Amax = max(A)
    A2 = A.copy()
    A2.remove(Amax)
    Asecond = max(A2)
    for a in A:
        if a == Amax:
            print(Asecond)
        else:
            print(Amax)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14100
#include <iostream>
#include <iomanip>
constexpr double pi = 3.14159265358979323846;

int main(void) {
    double r;
    std::cin >> r;
    std::cout << std::fixed << std::setprecision(6) << (r * r * pi) << ' ' << (2.0 * r * pi) << std::endl;
    return 0;
}



Measured memory_bytes: 3272
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    deque<int> dq;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(i & 1){
            dq.push_front(a);
        }else{
            dq.push_back(a);
        }
    }
    vector<int> ans(dq.begin(), dq.end());
    if(n & 1){
        reverse(ans.begin(), ans.end());
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 3840
S = gets.chomp

def month?(str)
  (1..12).cover?(str.to_i)
end

def mmyy?(str)
  cond1 = month?(str[0..1])

  cond1
end

def yymm?(str)
  cond1 = month?(str[2..3])

  cond1
end

if mmyy?(S) && yymm?(S)
  puts 'AMBIGUOUS'
elsif mmyy?(S)
  puts 'MMYY'
elsif yymm?(S)
  puts 'YYMM'
else
  puts 'NA'
end


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N];
ll maxs=-9999;
ll sum;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=maxs)
        {
            maxs=a[i];
        }
        else
        {
            sum+=maxs-a[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

void solve(){
  int n; cin>>n;
  vector<int> a(n),p(n),s(n);
  for(int i=0 ; i<n ; i++){
    cin>>a[i];
    p[i]=a[i];
    s[i]=a[i];
  }
  for(int i=1 ; i<n ; i++) p[i]^=p[i-1];
  for(int i=n-2 ; i>=0 ; i--) s[i]^=s[i+1];
  for(int i=0 ; i<n ; i++) cout<<(p[i]^s[i])<<' ';LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  solve();
  return 0;
}

Measured memory_bytes: 7888
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll A,B,C; cin>>A>>B>>C;
    if(A%2==0||B%2==0||C%2==0){
        cout<<0<<endl;
    }
    else {
        vector<ll>a={A,B,C};
        sort(a.begin(),a.end());
        cout<<a[0]*a[1]<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve(){
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>

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

ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}

int main()
{
	int n;
	cin>>n;
	ll X;
	cin>>X;
	ll x[100000];
	for(int i=0; i<n; i++){
		cin>>x[i];
	}
	ll d=abs(X-x[0]);
	for(int i=0; i<n-1; i++){
		d=gcd(d, abs(x[i]-x[i+1]));
	}
	cout<<d<<endl;
	return 0;
}

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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3108
N = int(input())
queue = [x for x in input()]

n_wests = 0
n_easts = queue.count('E') - (1 if queue[0] == 'E' else 0)
min_i = 0
min_n_changes = n_easts
for i in range(1, N):
    prev_dir = queue[i - 1]
    cur_dir = queue[i]
    if prev_dir == 'W':
        n_wests += 1
    if cur_dir == 'E':
        n_easts -= 1
    n_changes = n_wests + n_easts
    if n_changes < min_n_changes:
        min_n_changes = n_changes
        min_i = i

print(min_n_changes)


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L = A + B,R = C + D;
  
  if (L > R)
    cout << "Left" << endl;
  
  else if (L == R)
    cout << "Balanced" << endl;
  
  else if (L < R)
    cout << "Right" << endl;
}


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

using namespace std;

int main() {
	int n = 0, i;
	string s, t;

	cin >> s ;
	t = "CODEFESTIVAL2016";


	for (i = 0; i < 16; i++) {
		if (s[i] != t[i]) {
			n++;
		}
	
	}


	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return False,0,0

    if self.parents[x] > self.parents[y]:
      x, y = y, x
    nx=self.size(x)
    ny=self.size(y)
    self.parents[x] += self.parents[y]
    self.parents[y] = x
    
    return True,nx,ny

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
    
  def all_group_numbers(self):
    return [-x for x in self.parents if x < -1]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
uf=UnionFind(N)
ans=[0]*(M+1)
ans[M]=N*(N-1)//2
i=M-1
for a,b in AB[::-1]:
  flg,na,nb=uf.union(a-1,b-1)
  if flg:
    ans[i]=ans[i+1]-na*nb
  else:
    ans[i]=ans[i+1]
  i-=1
for a in ans[1:]:
  print(a)



Measured memory_bytes: 35436
#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
int main(){
      int x,id=0;
      
      while(scanf("%d",&x)!=EOF){
        arr[id++]=x;
      }
      int ans=0;
      sort(arr,arr+id);
      for(int a=id-2;a>=0;a--){
        ans+=arr[a+1]-arr[a];
      }
      printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,K,Q;
 cin >>N>>K>>Q;
 vector<int>vec(N,-Q);
 for(int i=0;i<Q;i++){
   int A;
   cin >>A;
   vec.at(A-1)+=1;
 }
 for(int i=0;i<N;i++){
     
     if(K+vec.at(i)>0){
         cout <<"Yes"<<endl;
     }
     else{
         cout <<"No"<<endl;
      }
    }
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ans = INT_MAX;
string str;
set<char> st;

int f(string s, char c) {
	int len = s.length();
	if(len == 1)
		return 0;
	string re;
	re.resize(len - 1);
	for(int i = 0; i < len - 1; i++) {
		if(s[i] == c || s[i + 1] == c)
			re[i] = c;
		else
			re[i] = s[i];
	}
	bool fl = false;
	for(int i = 0; i < len - 1; i++)
		if(re[i] != c)
			fl = true;

	if(fl)
		return f(re, c) + 1;
	else
		return 0;
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);

	cin >> str;
	n = str.length();
	for(int i = 0; i < n; i++) {
		st.insert(str[i]);
	}
	for(auto it = st.begin(); it != st.end(); it++)
		ans = min(ans, f(str, *it));
	if(ans == 0)
		cout << 0;
	else
		cout << ans + 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

//int mod = 1000000007;
int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N; cin >> N;
    vec a(N); readv(a);
    int S = 0; REP(i, N) S += a[i];

    int M = 90000;
    mat dp(N + 1, vec(M + 1, 0));
    dp[0][0] = 1;
    REP(i, N){
        REP(j, M + 1){
            if(j + a[i] <= M) Add(dp[i + 1][j + a[i]], dp[i][j]);
            Add(dp[i + 1][j], 2 * dp[i][j]);
        }
    }
    int x = 0;
    FOR(j, (S + 1) / 2, M + 1) Add(x, dp[N][j]); 

    mat dp2(N + 1, vec(M + 1, 0));
    dp2[0][0] = 1;
    REP(i, N){
        REP(j, M + 1){
            if(j + a[i] <= M) Add(dp2[i + 1][j + a[i]], dp2[i][j]);
            Add(dp2[i + 1][j], dp2[i][j]);
        }
    }
    int y = 0;
    FOR(j, (S + 1) / 2, M + 1) Add(y, dp2[N][j]);
    Add(x, 2 * (mod - y) + 1);

    int p = modpow(3, N, mod) - 3 * modpow(2, N, mod) + 3;
    int ans = p - 3 * x;
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 424512
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	int x, n, a[110],b[110],c;
	cin >> x >> n;
	memset(b, -1, sizeof b);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 1; i <= 100; i++) {
		c = 0;
		for (int j = 0; j < n; j++) {
			if (a[j] == i)c = 1;
		}
		if (c != 1)b[i] = 1;
	}
	c = 9999;
	b[0] = 1; b[101] = 1;
	for (int i = 0; i <= 101; i++) {
		if (b[i] == 1 && abs(c-x) > abs(i - x))c = i;
	}
	cout << c;


	return 0;
}

Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();

		if(s.compareTo(t) < 0) {
			System.out.println("Yes");
			return;
		}

		char[] sa = s.toCharArray();
		Arrays.sort(sa);
		s = new String(sa);
		char[] ta = t.toCharArray();
		Arrays.sort(ta);
		t = (new StringBuilder((new String(ta)))).reverse().toString();

		if(s.compareTo(t) < 0) {
			System.out.println("Yes");
			return;
		}

		System.out.println("No");

		return;
	}

}


Measured memory_bytes: 22612
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
p = list(map(float, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
	for j in range(N+1):
		if j-1 >= 0:
			dp[i+1][j] = dp[i][j-1]*p[i] + dp[i][j]*(1-p[i])
		else:
			dp[i+1][j] = dp[i][j]*(1-p[i])
ans = sum(dp[N][-(-N//2):])
print(ans)


Measured memory_bytes: 259676
n = int(input())
MOD = 10 ** 9 + 7
a = [int(i) for i in input().split()]


total = sum(a) % MOD
kotae = 0
for i in range(n-1):
    total -= a[i]
    if(total < 0):
        total += MOD
    kotae += a[i] * total
    kotae = kotae % MOD


print(kotae)

Measured memory_bytes: 105212
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N, K;
  ci(N, K);
  int c = 1;
  rep(i, N){
    if(c < K){
      c *= 2;
    }
    else{
      c += K;
    }
  }
  co(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;
	//at most max(n,n-k) flip find min of this
    int N = S.length();
    int ans = N;
    for (int i = 0; i < N - 1; ++i) {
        if (S[i] != S[i + 1])
            ans = min(ans, max(i + 1, N - i - 1));
    }

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


Measured memory_bytes: 512