akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

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

    var(int, N);
    vector<i64> a(3 * N);
    read(a);

    vector<i64> leftAns(3 * N);
    vector<i64> rightAns(3 * N);

    {
        i64 sum = 0;
        MinHeap<i64> h;
        rep(i, 0, N) h.push(a[i]), sum += a[i];

        rep(i, N, 2*N) {
            leftAns[i] = sum;
            sum += a[i]; h.push(a[i]);
            sum -= h.top(); h.pop();
        }
        leftAns[2*N] = sum;
    }
    {
        i64 sum = 0;
        MaxHeap<i64> h;
        repr(i, 3*N-1, 2*N) h.push(a[i]), sum += a[i];

        rightAns[2*N] = sum;
        repr(i, 2*N-1, N) {
            sum += a[i]; h.push(a[i]);
            sum -= h.top(); h.pop();
            rightAns[i] = sum;
        }
    }

    i64 ans = -LINF;
    rep(i, N, 2*N+1) {
        dump(i, leftAns[i], rightAns[i]);
        chmax(ans, leftAns[i] - rightAns[i]);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
struct data{
	int a[3][3];
	data(){memset(a,0,sizeof(a));}
	inline data operator *(const data &p){
		data ret;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					ret.a[i][j]=(ret.a[i][j]+1ll*a[i][k]*p.a[k][j])%mod;
		return ret;
	}
}A,B,C;
int n,m;
inline data ksm(data x,int y){
	data ret;
	for(int i=0;i<3;i++)ret.a[i][i]=1;
	for(;y;y>>=1,x=x*x)if(y&1)ret=ret*x;
	return ret;
}
int main(){
	cin>>n>>m;
	B.a[0][0]=1;B.a[0][1]=2;B.a[0][2]=1;
	B.a[1][1]=B.a[1][2]=1;
	B.a[2][0]=1;B.a[2][2]=B.a[2][1]=2;
	C=B;
	C.a[2][0]=C.a[2][1]=0;C.a[2][2]=1;
	A.a[0][0]=1;
	int x,las=-1; 
	for(int i=1;i<=m;i++,las=x){
		scanf("%d",&x);
		A=A*ksm(B,x-las-1)*C;
	}
	A=A*ksm(B,n-las-1);
	cout<<A.a[0][2];
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 1 << 11;
vector <int> L;
int pas, n;



void caut_bin(int x, int &r, int j)
{
  pas = N;
  while( pas != 0 )
  {
      if( r + pas < n && L[pas + r] < x )
          r += pas;
      pas /= 2;
  }
}


int main(){

  int x, rez = 0, k, maxi = -1;

  cin >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> x;
    L.push_back(x);
  }

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

  // for ( auto x : L ){
  //     cout << x << " ";
  // }

  for ( int i = 0; i < n - 1; i++ )
    for ( int j = i + 1; j < n; j++ ){
      int s =L[i] + L[j];
      k = j;
      caut_bin( s, k, j );
      rez += k - j;
    }

    cout << rez;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
using namespace std;

struct Node
{
	int data;
	Node* next;
	Node* prev;
};

class List
{
private:
	Node* mother;
public:
	List();
	~List();
	void Ins(int);
	void Del(int);
	void DelFirst();
	void DelLast();
	void Show();
};

List::List()
{
	mother = new Node;
	mother->data = -1;
	mother->next = this->mother;
	mother->prev = this->mother;
}

void List::Ins(int x)
{
	Node *tmp;
	tmp = this->mother->next;
	this->mother->next = new Node;
	this->mother->next->data = x;
	this->mother->next->next = tmp;
	this->mother->next->prev = mother;
	tmp->prev = mother->next;
	
	return;
}

void List::Del(int x)
{
	Node *tmp;
	tmp = this->mother->next;
	while (tmp != this->mother)
	{
		if (tmp->data == x)
		{
			tmp->prev->next = tmp->next;
			tmp->next->prev = tmp->prev;
			delete tmp;
			break;
		}
		tmp = tmp->next;
	}
	return;
}

void List::DelFirst()
{
	Node *tmp;
	tmp = this->mother->next;
	tmp->next->prev = mother;
	this->mother->next = tmp->next;
	delete tmp;
}

void List::DelLast()
{
	Node *tmp;
	tmp = this->mother->prev;
	this->mother->prev = tmp->prev;
	tmp->prev->next = mother;
	delete tmp;
}

void List::Show()
{
	Node *tmp;
	tmp = mother->next;
	cout << tmp->data;
	tmp = tmp->next;
	while (tmp != mother)
	{
		cout << " " << tmp->data;
		tmp = tmp->next;
	}
	cout << endl;
	return;
}

List::~List()
{
	Node *tmp;
	tmp = mother->next;
	while (1)
	{
		tmp = tmp->next;
		delete tmp->prev;
		if (tmp == mother)
			break;
	}
}

int main()
{
	int n, x;
	char command[20];
	List list;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> command;
		if (!strcmp(command, "insert"))
		{
			cin >> x;
			list.Ins(x);
		}
		else if (!strcmp(command, "delete"))
		{
			cin >> x;
			list.Del(x);
		}
		else if (!strcmp(command, "deleteFirst"))
			list.DelFirst();
		else
			list.DelLast();
	}
	list.Show();

	return 0;
}


Measured memory_bytes: 34352
//
// Created by habibaraphat on 5/25/20.
//

#include <iostream>
#include <vector>
#include <climits>
#include <map>

using namespace std;

class SegmentTree{
 public:
  vector<int> v;
  map<pair<int,int>,int> item_cnt;
  int end = 10000;
  int size = 4*10000;
  SegmentTree(){
    v = vector<int>(size, INT_MAX);
  }

  int _set_val(int start, int end, int running_idx, int idx, int val){
    if(idx>end || idx<start){
      return v[running_idx];
    }
    if(idx==start && idx==end){
      return v[running_idx] = val;
    }
    int mid = (start+end)/2;
    return v[running_idx] = min(_set_val(start, mid, running_idx*2+1, idx, val), _set_val(mid+1, end, running_idx*2+2, idx, val));
  }

  int _get_val(int start, int end, int running_idx, int idx_start, int idx_end){
    if(end<idx_start || start>idx_end){
      return INT_MAX;
    }
    if(start>=idx_start && end<=idx_end){
      return v[running_idx];
    }
    int mid = (start+end)/2;
    return min(
        _get_val(start, mid, running_idx*2+1, idx_start, idx_end),
        _get_val(mid+1, end, running_idx*2+2, idx_start, idx_end));
  }

  void set_val(int idx, int val){
    item_cnt[make_pair(idx, val)]++;
    _set_val(0, end, 0, idx, val);
  }

  void remove_val(int idx, int val){
    item_cnt[make_pair(idx, val)]--;
    if(item_cnt[make_pair(idx, val)]==0){
      _set_val(0, end, 0, idx, INT_MAX);
    }
  }

};

class SegmentTreeL:public SegmentTree{
 public:

  int get_val(int idx){
    return _get_val(0, end, 0, idx, end);
  }

  int get_b(int prev_best, int val){
    return prev_best+val;
  }

};

class SegmentTreeR: public SegmentTree{
 public:

  int get_val(int idx){
    int start_idx = 0;
    return _get_val(0, end, 0, start_idx, idx);
  }

  int get_b(int prev_best, int val){
    return prev_best+abs(val-end);
  }
};



int calculate(vector<int> &inp, int k){
  int res = 0;
  SegmentTreeL l;
  SegmentTreeR r;
  vector<int> cost(inp.size(), 0);
  l.set_val(inp[0], l.get_b(0, inp[0]));
  r.set_val(inp[0], r.get_b(0, inp[0]));
  for(int i=1; i<inp.size(); i++){
    int l_cost = l.get_val(inp[i])-inp[i];
    int r_cost = r.get_val(inp[i])-(r.end-inp[i]);

    res = min(l_cost, r_cost);
    cost[i] = res;
    l.set_val(inp[i], l.get_b(res, inp[i]));
    r.set_val(inp[i], r.get_b(res, inp[i]));
    if(i-k>=0){
      int idx = i-k;
      l.remove_val(inp[idx], l.get_b(cost[idx], inp[idx]));
      r.remove_val(inp[idx], r.get_b(cost[idx], inp[idx]));
    }

  }
  return res;
}

int main(){
  int n, k;
  vector<int> a;

  cin>>n>>k;
  for(int i=0; i<n; i++){
    int tmp;
    cin>>tmp;
    a.push_back(tmp);
  }

  int res = calculate(a, k);

  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 13816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll a[5005],b[5005];
bool c[5005];
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n >> k;
	for(i=1;i<=n;i++)
		cin >> a[i];
	for(i=1;i<=n;i++)
		cin >> b[i];
	ll ans=-1e15;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			c[j]=false;
		vector<ll>v;
		x=i;
		ll sm=0;
		while(1)
		{
			x=a[x];
			if(c[x])
				break;
			c[x]=true;
			v.pb(b[x]);
			sm+=b[x];
		}
		ll g=v[0],h=0;		
		for(j=1;j<sz(v);j++)
		{
			v[j]+=v[j-1];
			if(j<k)
				g=max(g,v[j]);
		}
		
		if(sm>0)
		{
			h=sm*(k/sz(v));
			if(k%(sz(v)))
			{
				ll mx=v[0];
				for(j=0;j<k%(sz(v));j++)
					mx=max(mx,v[j]);
				h+=mx;
			}
			ans=max(ans,h);
		}
		ans=max(ans,g);


		if(k>sz(v))
		{
			for(j=0;j<sz(v);j++)
			{
				x=v[j];
				y=sm*((k-j-1)/(sz(v)));
				ans=max(ans,x+y);
			}
		}
	}
	cout<<ans<<endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vl v(n);
	REP(i, n)cin >> v[i];
	vl a(n + 1);
	a[0] = 0;
	REP(i, n)a[i + 1] = v[i];
	REP(i, n)a[i + 1] += a[i];
	ll ans = INF * INF; 
	FOR(i, 2, n - 1) {
		ll mind = INF * INF;
		int c = lower_bound(ALL(a), a[i] / 2) - a.begin();
		if (c != i) {
			mind = min(mind, abs(a[i] - 2*a[c]));
		}
		if (c != 1) {
			mind = min(mind, abs(a[i] - 2 * a[c-1]));
		}
		int d = lower_bound(ALL(a), (a.back() + a[i]) / 2) - a.begin();
		ll mind2 = INF * INF;
		if (d != n) {
			mind2 = min(mind2, abs(a[n] -a[i]- 2 * (a[d]-a[i])));
		}
		if (d != i + 1) {
			mind2 = min(mind2, abs(a[n] - a[i] - 2 * (a[d - 1] - a[i])));
		}
		ll minv = min((a[i] - mind) / 2, (a[n] - a[i] - mind2) / 2);
		ll maxv = max((a[i] + mind) / 2, (a[n] - a[i] + mind2) / 2);
		ans = min(ans, maxv - minv);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3456
#include<stdio.h>
int gcd(int,int);
int main(void)
{
  int x,y;
  int ans;
  int tmp;
  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));
  return 0;
}
int gcd(int x,int y)
{
  if(x<y) return gcd(y,x);
  if(x%y==0) return y;
  else return gcd(y,x%y);
}




Measured memory_bytes: 2084
from bisect import *

def binary_search_int(ok, ng, test):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ng

def get_count1(k, A):
    """ K番目の要素が正の場合 """
    l, r = 0, len(A)-1
    res = 0
    while l < r:
        if A[l]*A[r] > k:
            r -= 1
            continue
        res += r-l
        l += 1
    return res

def get_count2(k, B, C):
    """ K番目の要素が負の場合 """
    l, r = 0, len(C)-1
    res = 0
    while True:
        if l > len(B)-1 or r < 0:
            break
        if B[l]*C[r] < -k:
            l += 1
            continue
        res += len(B)-l
        r -= 1
    return res

def test1(k):
    return get_count1(k, B) + get_count1(k, C) + count_negative < K

def test2(k):
    return get_count2(k, B, C) < K



N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

at_zero = bisect_left(A,0)
B = A[:at_zero]
B = list(map(lambda x: -x, B))
B = list(reversed(B))   # 負の要素
C = A[at_zero:]         # 正の要素
count_positive = (len(B)*(len(B)-1)//2 + len(C)*(len(C)-1)//2)
count_negative = N*(N-1)//2 - count_positive
if K > count_negative:
    print(binary_search_int(-1, 10**18+1, test1))
else:
    print(binary_search_int(-10**18, 1, test2))


Measured memory_bytes: 108044
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, m, p = na()
 
def bf(es, n, start):
    d = [999999999999] * n
    d[start] = 0
 
    for r in range(n-1):
        updated = False
        for e in es:
            if d[e[0]] == 999999999999:
                continue
            if d[e[0]] + e[2] < d[e[1]]:
                d[e[1]] = d[e[0]] + e[2]
                updated = True
        if not updated:
            break
 
    for e in es:
        if d[e[0]] < 999999999999 and d[e[0]] + e[2] < d[e[1]]:
            return None
 
    return d
 
es = []
for i in range(m):
    a, b, c = na()
    es.append((a-1, b-1, -(c-p)))
 
import collections
q = collections.deque()
q.append(n-1)
 
valid = [False] * n
valid[n-1] = True
while len(q) > 0:
    cur = q.popleft()
    for e in es:
        if e[1] == cur and not valid[e[0]]:
            valid[e[0]] = True
            q.append(e[0])
 
nes = []
for e in es:
    if valid[e[0]] and valid[e[1]]:
        nes.append(e)
es = nes
 
d = bf(es, n, 0)
if not d:
    print(-1)
else:
    print(max(0, -d[n-1]))

Measured memory_bytes: 42992
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void io(){ ios_base::sync_with_stdio(false);cin.tie(NULL);  cout.tie(NULL);}
int main()
{
    //io();
    ll tt;
    tt=1;
    cout<<fixed;
    while(tt--)
    {
       double r;
       cin>>r;
       cout<<acos(-1)*2*r;
    }
}


Measured memory_bytes: 3788
class City
  attr_accessor :prefec, :year, :spot, :rank
  def initialize prefec,year,spot
    self.prefec = prefec
    self.year = year

    # 自分が何番目に表示されるべきか
    self.spot = spot
  end
  def getID
    return "%06d%06d" % [self.prefec,self.rank]
  end
end

datas = gets.split(" ").map{|nn|nn.to_i}
n = datas[0]
m = datas[1]
cities = []

m.times do|spot|
  datas = gets.split(" ").map{|nn|nn.to_i}
  cities << City.new(datas[0],datas[1],spot)
end

prefecs = {}

cities.each do|cit|
  if prefecs[cit.prefec.to_s] != nil
    prefecs[cit.prefec.to_s] << cit
  else
    prefecs[cit.prefec.to_s] = [cit]
  end
end
prefecs.each do|cits|
  cits[1].sort!{|a, b| a.year <=> b.year}
  index = 1
  cits[1].each do|cit|
    cit.rank = index
    index += 1
  end
end
cities.sort!{|a, b| a.spot <=> b.spot}
cities.each do|cit|
  puts cit.getID
end

Measured memory_bytes: 38128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};
 
//組み合わせを線形で
//参考:https://drken1215.hatenablog.com/entry/2018/06/08/210000
 
const int MXN=1000001;//変更可
ll fac[MXN],inv[MXN],finv[MXN];
 
ll pow_mod(ll x,ll y){
    if(y==0){
        return 1;
    }
    if(y%2){
        return x*pow_mod(x,y-1)%MOD;
    }
    ll t=pow_mod(x,y/2);
    return t*t%MOD;
}
 
void COMinit(int M) {
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(int i=2;i<MXN;i++){
        fac[i]=fac[i-1]*i%M;
        inv[i]=M-M/i*inv[M%i]%M;
        finv[i]=finv[i-1]*inv[i]%M;
    }
}
 
ll COMBI(int N,int K,int M){
    if(N<K){
        return 0;
    }
    if(N<0||K<0){
        return 0;
    }
    return fac[N]*finv[N-K]%M*finv[K]%M;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    COMinit(MOD);
    vl c(n);
    rep(i,n){
        cin >> c[i];
    }
  	sort(c.begin(),c.end());
  	vl sum_c(n,c[0]),sum_sum_c(n,c[0]);
    FOR(i,1,n){
    	sum_c[i]=sum_c[i-1]+c[i];
        sum_c[i]%=MOD;
    }
  	FOR(i,1,n){
      	sum_sum_c[i]=sum_sum_c[i-1]+sum_c[i];
        sum_sum_c[i]%=MOD;
    }
    ll ans=0;
  	ll res=pow_mod(2,n);
    FOR(i,1,n+1){
      	ans+=((COMBI(n-1,i-1,MOD)-COMBI(n-2,i-2,MOD))%MOD*sum_c[n-1])%MOD+(COMBI(n-2,i-2,MOD)*sum_sum_c[n-1])%MOD;
      	ans%=MOD;
    }
  	ans*=res;
  	ans%=MOD;
  	cout << (ans+MOD)%MOD << endl;
}

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

#define pb push_back
#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 4010;

int n, k, m;
int Begin[N], Next[N], to[N], e = 1;

void add(int u, int v) {
	to[++e] = v, Next[e] = Begin[u], Begin[u] = e;
}

bool flag[N], used[N];
vector<int> P[N];

bool DFS(int o, int f, int aim, vector<int>& E) {
	if (o == aim) return true;
	for (int i = Begin[o]; i; i = Next[i]) {
		int u = to[i];
		if (u == f) continue;
		E.pb(i);
		if (DFS(u, o, aim, E)) return true;
		E.pop_back();
	}
	return false;
}

int cnt[N];
vector<int> cov[N];

int fr[N], de[N];

int main() {

	scanf("%d%d", &n, &m);

	k = n - 1;
	For(i, 1, k) {
		int u, v;
		scanf("%d%d", &u, &v);
		add(u, v), add(v, u);
	}
	For(i, 1, m) {
		int u, v;
		scanf("%d%d", &u, &v);
		fr[i] = u, de[i] = v;
		DFS(u, 0, v, P[i]);
		for (int x : P[i]) ++cnt[x / 2], cov[x / 2].pb(i);
	}

	int ans = 0;
	For(i, 1, k) ans += min(2, cnt[i]);

	while (true) {

		int id = 0;
		For(j, 1, k) if (cnt[j] == 1 && flag[j << 1] != flag[j << 1 | 1])
			id = flag[j << 1] ? j << 1 | 1 : j << 1;
		if (!id) {
			For(j, 1, k) if (cnt[j]) { id = j << 1; break; }
			if (!id) break;
		}

		int x = id / 2;
		while (used[cov[x].back()]) cov[x].pop_back();
		int y = cov[x].back();
		used[y] = true;

		bool rev = false;
		for (int s : P[y]) if (s / 2 == x) {
			rev = s != id;
			break;
		}
		if (rev) {
			swap(fr[y], de[y]);
			for (int &s : P[y]) s ^= 1;
		}

		for (int s : P[y]) --cnt[s / 2], flag[s] = true;
	}

	printf("%d\n", ans);
	For(i, 1, m) printf("%d %d\n", fr[i], de[i]);

	return 0;
}

Measured memory_bytes: 15744
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i = 0;i < n;i++)cin >> d[i];

	sort(d.begin(),d.end());
	for(int i = 0;i < n;i++){
		if(i % 2 == 0){
			if(d[i] != 0 && d[i] != 12)d[i] = 24 - d[i];
		}
	}

	int ans = 1000000000;
	d.push_back(0);
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n+1;j++){
			ans = min(ans,min(abs(d[i]-d[j]),24-abs(d[i]-d[j])));
		}
	}

	cout << ans << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, m;
  cin >> n >> m;
  vi s(m*2);
  re(i, m*2) cin >> s[i];

  fo(i, 1, n+1) {
    int cnt = 0;
    re(j, m*2) {
      if(s[j] == i) cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 105,mo=998244353;
map<ll,int>Map[N];
inline void add(int &x,int y){x=x+y<mo?x+y:x+y-mo;}
int solve(int n, ll S){
	if(!n)return 1;if(Map[n].count(S))return Map[n][S];
	int res=solve(n-1,S>>1)*(1+(S&1))%mo;
	rep(l,1,n){
		ll val=S&((1LL<<l)-1);
		rep(k,2,n/l){
			val&=S>>(l*(k-1));
			add(res,1LL*solve(l,val)*solve(n-l*k,S>>(l*k))%mo);
		}
	}
	return Map[n][S]=res;
}
int main() {
	char S[N];scanf("%s",S+1);int n=strlen(S+1);
	int a[N],f[N]={0};f[n+1]=1;
	rep(i,1,n)a[i]=S[i]-'0';
	per(i,n,1){
		f[i]=f[i+1]*(a[i]+1)%mo;
		rep(k,2,n-i+1)rep(l,1,(n-i+1)/k){
			ll tmp=(1LL<<l)-1;//rep(x,i,i+l-1)tmp|=1LL<<x-i;
			for(int p=i;p+l-1<i+l*k;p+=l){
				ll val=0;rep(x,0,l-1)if(a[p+x])val|=1LL<<x;
				tmp&=val;
			}
			add(f[i],1LL*f[i+l*k]*solve(l,tmp)%mo);
		}
	}
	cout<<f[1];
	return 0;
}


Measured memory_bytes: 3072
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
long long ans=0,n,k,x;
int main()
{
	cin>>n>>k;
	if(k%2)
	{	
		x=n/k;
		cout<<x*x*x;
	}
	else
	{
		x=(n/(k/2)+1)/2;
		ans+=(x*x*x);
		x=n/k;
		ans+=(x*x*x);
		cout<<ans;
	}
	return 0;
}

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

int		main(void)
{
	char b;

	cin >> b;
	char ans;
	if (b == 'A')
		ans = 'T';
	if (b == 'T')
		ans = 'A';
	if (b == 'C')
		ans = 'G';
	if (b == 'G')
		ans = 'C';
	cout << ans << endl;
}


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

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

int main() {
	const int MOD = 1e9 + 7;
	using mint = ModInt<MOD>;
	int n; cin >> n;
	int cnt = 0;
	mint ans = 1;
	for(int i = 0; i < n; ++i) {
		++cnt;
		int x; cin >> x;
		if(x < 2 * cnt - 1) {
			ans *= cnt;
			--cnt;
		}
	}
	for(mint i = 1; i != cnt + 1; i += 1) {
		ans *= i;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

int main(){
  int N;
  scanf("%d", &N);
  int a = N / 2;
  char S[1000];
  scanf("%s", S);
   if(N % 2 != 0){
    printf("No\n");
    return 0;
  }

  for(int i = 0; i < a; i++){
    if(S[i] != S[i + a]){
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
def f(heights,roads):
	count, r =0, [True] * len(heights)
	for u,v in roads:
		if heights[u-1] <= heights[v-1]: r[u-1] = False
		if heights[u-1] >= heights[v-1]:r[v-1] = False
	for b in r:
		count += 1 if b else 0
	return count

n,m = map(int, raw_input().split(' '))
print f(map(int,raw_input().split(' ')), [map(int, raw_input().split(' ')) for _ in range(m)] )


Measured memory_bytes: 94056
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
	let (w, h) = {
    	let line = get_input();
    	let mut split = line.split_whitespace();
    	let w:u64 = split.next().unwrap().parse().unwrap();
    	let h:u64 = split.next().unwrap().parse().unwrap();
        (w, h)
    };
    
    let (x, y) = {
    	let line = get_input();
    	let mut split = line.split_whitespace();
    	let x:u64 = split.next().unwrap().parse().unwrap();
    	let y:u64 = split.next().unwrap().parse().unwrap();
        (x-1, y-1)
    };
    
    let mut ans = 0;
    for xi in 0..w {
    	for yi in 0..h {
        	//println!("({}, {})", xi, yi);
        	if xi > x && yi > y {
            	ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
package main
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)

func next() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func main() {
  sc.Split(bufio.ScanWords)
  n := next()
  tako := make([]int, n, n)
  takoSum := 0  // たこ焼きn種の回復量の和
  ans := 0 // 答え

  for i := 0; i < n; i++ {
    tako[i] = next()
    takoSum += tako[i]
  }
  
  for i := 0; i < n; i++ {
    ans += (takoSum - tako[i]) * tako[i]
  }
  // この時点だとあるたこ焼きの組は2回数えられているので2で割る
  ans /= 2
  fmt.Println(ans)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    if (s[sz(s) - 1] != 's') cout << s + 's' << endl;
    else cout << s + "es" << endl;
	return 0;
}

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

using namespace std;

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

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

    bool is_passed = true;
    for(int i = 0; i < N; i++) {
        if(A[i] % 2 == 0) {
            if(!(A[i] % 3 == 0 || A[i] % 5 == 0)) {
                is_passed = false;
            }
        }
    }

    cout << (is_passed ? "APPROVED" : "DENIED") << endl;
}

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

int ans[305][305];

int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
  /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
   */
  string nish;
  cin>>nish;
  int siz=nish.size();

  int total1=(nish[0]-'0')*10+(nish[1]-'0');
  int total2=(nish[2]-'0')*10+(nish[3]-'0');
  if(total1>0 && total1<=12 && total2>0 && total2<=12 )
  {
    cout<<"AMBIGUOUS"<<endl;
  }
  else if(total1>0 && total1<=12)
  {
    cout<<"MMYY"<<endl;
  }
  else if(total2>0 && total2<=12)
    cout<<"YYMM"<<endl;
  else
    cout<<"NA"<<endl;


   return 0;
    
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int train = Math.min(A,B);
		int bus = Math.min(C,D);
		int min = train + bus;
		System.out.println(min);
	}

}


Measured memory_bytes: 23892
object Main {
  // 標準入力
  import scala.io.StdIn._
  def readints: Array[Long] = readLine split " " map (_.toLong)
  //
  def main(args: Array[String]) = {
    val Array(n, a, b) = readints
    val m = n / (a + b)
    println(s"${m * a + Math.min(a, n % (a + b))}")
  }
}


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


using namespace std;

int main() {
    int n;
    cin >> n;
    int d[n];
    for (auto &di:d) cin >> di;
    sort(d, d+n);
    cout << d[n/2] - d[n/2-1] << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;
#define D
#ifdef D
bool inc3(int n)
{
	while (n)
	{
		if ( n % 10== 3)
			return true;
		n /= 10;
	}
	return false;
}

int main(void)
{
	int n;
	cin >> n;
	n++;
	for (size_t i = 3; i < n; i++)
	{
		if (i % 3 == 0 || inc3(i))
			cout << " " << i;
	}
	cout << endl;
	return 0;
}

#endif // D

Measured memory_bytes: 3116
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;

using namespace std;
LL A[100000];

int main(void){
    int N;
    scanf("%d",&N);REP(i,N)scanf("%lld",A+i);
    int ans=1;
    int isFirst=1;
    LL isDecend=0;
    REP(i,N-1){
        LL a=A[i+1]-A[i];
        if(isFirst){
            if(a!=0){
                isFirst=0;
                isDecend=a;
            }
        }else{
            if(0<a){
                if(isDecend*a<0){
                    isFirst=1;
                    ans++;
                }
            }else if(a<0){
                if(isDecend*a<0){
                    isFirst=1;
                    ans++;
                }
            }else{
                ;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res = 0;

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

    ll N, M;
    cin >> N >> M;
    vector<ll> H(N+50);
    vector<ll> ma(N+50);
    for (int i = 1; i <= N; i++)
    {
        cin >> H[i];
        ma[i] = 0;
    }
    for (int i = 0; i < M; i++)
    {
        ll a, b;
        cin >> a >> b;
        ma[a] = max(ma[a], H[b]);
        ma[b] = max(ma[b], H[a]);
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans += H[i] > ma[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int X = (int)Math.ceil(N/1.08);
		int taxedX = (int)(X * 1.08);
		if (taxedX == N ){
			System.out.print(X);
		}else {
			System.out.print(":(");
		}
	}
}


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

using namespace std;

int main() {
  int num[3];
  cin >> num[0] >> num[1] >> num[2];
  sort(num, num + 3);
  if (num[0] == num[1]) cout << num[2] << endl;
  else cout << num[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
#define endl "\n"
int n;
int a[100005];
int b[100005];
int c[100005];
long long mem[100005][4];
long long solve(int i,int last){
    if(i>=n)return 0;
    if(mem[i][last]!=-1){
        return mem[i][last];
    }
    if(last!=0){
      mem[i][last]=max(mem[i][last],a[i]+solve(i+1,0));
    }
    if(last!=1){
        mem[i][last]=max(mem[i][last],b[i]+solve(i+1,1));
    }
    if(last!=2){
        mem[i][last]=max(mem[i][last],c[i]+solve(i+1,2));
    }
    return mem[i][last];

}
int main() {
Me3za();
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
}
memset(mem,-1,sizeof mem);
cout<<solve(0,3);
}



Measured memory_bytes: 10752
# ARC 063
S = input()
count = 0
stn = S[0]
i = 1
while i<len(S):
    while i<len(S) and stn==S[i] : i+=1 # 色が変わるまで
    if i<len(S): 
        count += 1
        stn = S[i]
print(count)

Measured memory_bytes: 3188
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;


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

	vector<int> a(N);
	vector<bool> used(N, false);

	used[0] = true;

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

	int i = 0, c = 0;
	while (i != 1) {
		++c;
		i = a[i] - 1;
		if (used[i]) {
			cout << -1 << endl;
			return 0;
		}
		used[i] = true;
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 640
N, K, Q = map(int,input().split())
a = []
b = [0] * N
for i in range(Q):
    A = int(input())
    a.append(A)

for i in a:
    b[i - 1] += 1
for i in b:
    if i > Q - K:
        print('Yes')
    else:
        print('No')






Measured memory_bytes: 13736
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,m,x,c[15],g[15][15],ans=INF,l[15],sum[15][15];
bool check()
{
	for(int i=1;i<=m;++i)
	{
		if(l[i]<x)
		{
			return false;
		}
	}
	return true;
}
void dfs(int i,int now)
{
	if(now>=ans)
	{
		return;
	}
	if(check())
	{
		ans=now;
	}
	while(i<n)
	{
		++i;
		for(int j=1;j<=m;++j)
		{
			l[j]+=g[i][j];
		}
		dfs(i,now+c[i]);
		for(int j=1;j<=m;++j)
		{
			l[j]-=g[i][j];
		}
	}
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>m>>x;
	for(int i=1;i<=n;++i)
	{
		cin>>c[i];
		for(int j=1;j<=m;++j)
		{
			cin>>g[i][j];
			sum[i][j]=sum[i-1][j]+g[i][j];
		}
	}
	dfs(0,0);
	if(ans>=INF)
	{
		cout<<"-1"<<endl;
	}
	else
	{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
string S;
int k[1000000]={0};
int main()
{
    while(cin>>S)
    {  //if(S=="0")return 0;
    int len=S.size();
    int i=0,j;
    int count=0;
    for(j=1;j<len;j++)
     if(S[j]!=S[j-1])
        {
            k[++count]=max(j,len-j);
           // cout<<k[]
        }
     int res=len;
    for(int i=1;i<=count;i++)
        res=min(res,k[i]);

    printf("%d\n",res);

    }
}



Measured memory_bytes: 640
a,b,c,x,y = map(int, input().split())

A = a*x + b*y
B = 2*c*max(x,y)

if x > y:
    C = y*2*c+(x-y)*a
else:
    C = x*2*c+(y-x)*b
print(min(A,B,C))


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

int main()
{
    int a,b,c,d,n,m;
    while(~scanf("%d %d %d %d",&a,&b,&c,&d))
    {
        if(a<b)
        {
            n=a;
        }
        else
        {
            n=b;
        }
        if(c<d)
        {
            m=c;
        }
        else
        {
            m=d;
        }
        printf("%d\n",n+m);
    }
    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

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

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  sort(rng(A));
  vector<bool>b(1000001,true);
  bool ng=true;
  ll ans=0;
  for(int i=0;i<N;i++){
    if(!b[A[i]])continue;
    if(A[i]==A[i+1])for(int j=A[i];j<=1000000;j+=A[i])b[j]=false;
    if(b[A[i]]){
      ans++;
      for(int j=A[i];j<=1000000;j+=A[i])b[j]=false;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5116
N = int(input())
p = list(map(float, input().split()))

import numpy as np
dp = np.zeros(N+1)
dp[0] = 1

for i in range(N):
    dp[1:] = dp[1:]*(1-p[i]) + dp[:-1]*p[i]
    dp[0] *= (1-p[i])

print(sum(dp[int(N/2)+1:] ))

Measured memory_bytes: 27256
#include<stdio.h>

int main(){
	while(1){
		int i, n, p;
		scanf("%d %d", &n, &p);
		if(n == 0 && p == 0) break;
		int a[n];
		for(i = 0; i < n; i++){
			a[i] = 0;
		}
		int pn = p;
		int flag = 0;
		while(flag == 0){
			for(i = 0; i < n; i++){
				if(pn != 0){
					a[i]++; pn--;
					if(a[i] == p){
						flag = 1;
						break;
					}
				}else{
					pn += a[i];
					a[i] = 0;
				}
			}
		}
	printf("%d\n", i);
	}
	return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(int argc,char** argv)
{
	char c[2][3];
	for(int i = 0; i < 2; i++){
			scanf("%s", c[i]);
	}

	if(c[0][0] == c[1][2]){
		if(c[0][1] == c[1][1]){
			if(c[0][2] == c[1][0]){
				printf("YES\n");
			}
			else{printf("NO\n");}
		}
		else{printf("NO\n");}
	}
	else{printf("NO\n");}

	return(0);

}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQUE(c)   sort(ALL((c)));(c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

std::vector<int> prime;
void MakePrime(int n) {
	prime.emplace_back(2);
	for (int i = 3; i <= n; i += 2) {
		bool a = false;
		for (int j = 3; j <= std::sqrt(i); j += 2) {
			if (i%j == 0) {
				a = true;
			}
		}
		if (a == false) {
			prime.emplace_back(i);
		}
	}
}

int n, p;

int main(){
	MakePrime(555555);
	while (cin >> n >> p&&(n!=-1)&&(p!=-1)) {
		int num = upper_bound(ALL(prime), n) - prime.begin();
		vector<int> ans;
		for (int i = num; i <= num + p + 1; i++) {
			for (int j = i; j <= num + p + 1; j++) {
				ans.emplace_back(prime[i] + prime[j]);
			}
		}
		sort(ALL(ans));
		cout << ans[p - 1] << endl;
	}
}


Measured memory_bytes: 3156
MOD = 10 ** 9 + 7
L = input()
N = len(L)
total = 0
one_count = 0
p3 = [1] * N
for i in range(1, N):
    p3[i] = p3[i - 1] * 3 % MOD
p2 = 1
for i in range(N):
    if L[i] == "1":
        total = (total + p2 * p3[N - i - 1]) % MOD
        p2 = p2 * 2 % MOD
print((total + p2 * p3[N - i - 1]) % MOD)

Measured memory_bytes: 7156
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

//ABC129x_x
fun func() {
    val S = nextInt()
    val s0 = S / 100
    val s1 = S % 100
    var ans: String
    if (s0 in 1..12)
        if (s1 in 1..12) ans = "AMBIGUOUS"
        else ans = "MMYY"
    else if (s1 in 1..12) ans = "YYMM"
    else ans = "NA"
    println("${ans}")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")


Measured memory_bytes: 31744
n=int(input())
state=[[] for i in range(n)]
a=[]
ans=0
for i in range(n):
    a.append(int(input()))
    state[i]=[list(map(int,input().split())) for j in range(a[i])]
for i in range(2**n):
    flag=False
    for j in range(n):
        if (i>>j)&1:
            for k in range(a[j]):
                if state[j][k][1]==1:
                    if (i>>state[j][k][0]-1)&1: continue
                    else:
                        flag=True
                        break
                else: 
                    if not (i>>state[j][k][0]-1)&1: continue
                    else:
                        flag=True
                        break
        else: continue
        if flag: break
    if flag: continue
    ans=max(ans,str(bin(i)).count("1"))
print(ans)

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

int solve();
int check(int n);
string str;


int main(){
  cin >> str;
  str.pop_back();
  solve();

}

int solve(){
  int nn = str.length();
  for(int i= 0; i<nn; i++){
    if(str.length() % 2 == 0){
      if(check(str.length() /2) == 0){
        break;
      }
    }
    str.pop_back();
  }
  cout << str.length() << endl;
  return 0;
}

int check(int n){
  int fl = 0;
  for(int i= 0; i<n; i++){
    if(str.at(i) != str.at(n+i)){
      fl = 1;
      break;
    }
  }
  return fl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, x;
    int l[100];
    cin >> n >> x;
    int y=0,ans=1;
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
        y+=l[i];
        if(y > x) {
            continue;
        }
        ans+=1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
  return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  ll b=a[0]/2;
  for(int i=1;i<n;i++){
    b=lcm(b,a[i]/2);
    if(b>m){
      puts("0");
      return 0;
    }
  }
  for(int i=0;i<n;i++)if((b/(a[i]/2))%2==0){puts("0");return 0;}
  ll ans=0;
  for(ll i=b;i<=m;i+=2*b)ans++;
  cout << ans << endl;
  return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }



int main()
{
	int n, m, ans = 1, a, b, temp;

	cin >> n >> m;
	vector<bool> flag(n, false);
	vector<set<int>> ab(n);
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		ab[a - 1].insert(b - 1);
		ab[b - 1].insert(a - 1);
	}
	for (int i = 0; i < n; i++)
	{
		if (flag[i] || ab[i].empty())
			continue;
		flag[i] = true;
		temp = 1;
		queue<int> q;
		q.push(i);
		while (!q.empty())
		{
			a = q.front();
			q.pop();
			for (auto v : ab[a])
			{
				if (flag[v])
					continue;
				flag[v] = true;
				q.push(v);
				temp++;
			}
		}
		ans = max(temp, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 31512
def main():
    N, Q = map(int, input().split())
    S = list(input())

    templist = [0]
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            S[i] = 'a'
            templist.append(templist[-1]+1)
        else:
            templist.append(templist[-1])
    templist.append(templist[-1])

    ans = []
    for i in range(Q):
        l, r = map(int, input().split())
        ans.append(templist[r-1] - templist[l-1])
    for a in ans:
        print(a)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 10996
#include<iostream>
//#include<string.h>
using namespace std;
//cout << "Yes" << endl;
//cout << "No" << endl;
int seiyaku_check(long i,int Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		//exit(1);
		return 0;
	}
}

int main(){
	
	int a,b;
	
	cin >> a >> b;
	
	if(seiyaku_check(a,1,9) == 1 && seiyaku_check(b,1,9) == 1){
		cout << a*b << endl;
	}else{
		cout << "-1" << endl;
	}
	
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
	int d;
	while(scanf("%d", &d) != EOF){
		int ans = 0;
		for(int i=1; i < 600/d; i++){
			ans += d * pow(d*i, 2);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1208