akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut e = vec![];
    for _ in 0..n {
        let x: f64 = sc.read();
        let y: f64 = sc.read();
        e.push((x, y));
    }
    e.sort_by(|&(x1, y1), &(x2, y2)| {
        let t1 = y1.atan2(x1);
        let t2 = y2.atan2(x2);
        t1.partial_cmp(&t2).unwrap()
    });

    let mut ans = 0.0;
    for head in 0..n {
        let (mut sx, mut sy) = (0.0, 0.0);
        for i in 0..n {
            let (x, y) = e[(head + i) % n];
            sx += x;
            sy += y;
            let s = sx * sx + sy * sy;
            if ans < s {
                ans = s;
            }
        }
    }

    println!("{}", ans.sqrt());
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> l(n),r(n);
  for(Int i=0;i<n;i++) cin>>l[i]>>r[i];
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());

  Int ans=0;
  {
    Int res=0,pos=0;
    for(Int i=0;i<n;i++){
      if(r[i]>pos) break;
      res+=abs(pos-r[i]);
      pos=r[i];
      if(pos>l[n-(i+1)]) break;
      res+=abs(l[n-(i+1)]-r[i]);
      pos=l[n-(i+1)];
    }
    chmax(ans,res+abs(pos));
  }
  {
    reverse(l.begin(),l.end());
    reverse(r.begin(),r.end());
    Int res=0,pos=0;
    for(Int i=0;i<n;i++){
      if(l[i]<pos) break;
      res+=abs(pos-l[i]);
      pos=l[i];
      if(pos<r[n-(i+1)]) break;
      res+=abs(r[n-(i+1)]-l[i]);
      pos=r[n-(i+1)];
    }
    chmax(ans,res+abs(pos));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
<?php
  $arr = explode(' ',readline());
$a = $arr[0];
$b = $arr[1];
$c = $arr[2];
$k = $arr[3];
if($k <= $a){
  echo($k);
} else {
  $sum = $a;
  $k -= $a;
  $k -= $b;
  if($k > 0){
  	if($k < $c)$sum -= $k;
    else $sum -= $c;  
  }
  echo($sum);
}
	

Measured memory_bytes: 16436
from heapq import heappush,heappop
n,m,s,t=map(int,input().split())
a,b=[[]for i in range (n+1)],[[]for i in range(n+1)]
for i in range(m):
    p,q,r,g=(int(i) for i in input().split())
    a[p].append((q,r))
    a[q].append((p,r))
    b[p].append((q,g))
    b[q].append((p,g))
def f(x,r):
    p=[float("inf")for i in range(n+1)]
    p[x],q=0,[[0,x]]
    while q:
        y,z=heappop(q)
        for i,j in r[z]:
            if p[i]>y+j:
                p[i]=y+j
                heappush(q,[p[i],i])
    return p
s1,t1,p=f(s,a),f(t,b),[]
for i in range(1,n+1):
    p.append((s1[i]+t1[i],i))
p,e=sorted(p),0
for i in range(n):
    while p[e][1]<=i: e+=1
    print(10**15-p[e][0])

Measured memory_bytes: 90544
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> a(n);
    map<ll, ll> p, q;
    rep(i,n) {
        cin >> a[i];
        p[i-a[i]]++;
        q[a[i]+i]++;
    }
    ll ans = 0;
    for (auto v : p) {
        ans += v.second * q[v.first];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 38296
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;

ll com[52][52];

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    com[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++){
            com[i][j] = com[i - 1][j];
            if(j) com[i][j] += com[i - 1][j - 1];
        }
    }
    ll v[52];
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v + n, greater<ll>());
    ll s = 0;
    for(int i = 0; i < a; i++) s += v[i];
    cout << fixed << setprecision(15) << s * 1.0 / a << endl;
    if(v[0] == v[a - 1]){
        int k;
        for(k = 0; k < n; k++){
            if(v[k] != v[0]) break;
        }
        ll ans = 0;
        for(int i = a; i <= min(k, b); i++) ans += com[k][i];
        cout << ans << endl;
        return 0;
    }
    int p = 0;
    for(int i = a - 1; i >= 0; i--){
        if(v[i] == v[a - 1]) p++;
    }
    int q = 0;
    for(int i = a; i < n; i++){
        if(v[i] == v[a - 1]) q++;
    }
    cout << com[p + q][p] << endl;
}


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

int main() {
  int n, i, j, k;
  long long ans = 0;
  vector<long long> c(5);
  string s;
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> s;
    if (s[0] == 'M')
      c[0]++;
    if (s[0] == 'A')
      c[1]++;
    if (s[0] == 'R')
      c[2]++;
    if (s[0] == 'C')
      c[3]++;
    if (s[0] == 'H')
      c[4]++;
  }

  for (i = 0; i < 5; i++) {
    for (j = i + 1; j < 5; j++) {
      for (k = j + 1; k < 5; k++) {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

for d in range(D):
  max_index=-1
  max_sd=-1
  for i in range(26):
    if max_sd<smat[d][i]:
      max_index=i+1
      max_sd=smat[d][i]
      
  print(max_index)

Measured memory_bytes: 74696
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 101, W = 1e5 + 1;

int n, w;
int vi[N], wi[N];
long long dp[W];

int main()
{
  cin >> n >> w;
  for(int i = 0 ; i < n ; i++)
    cin >> wi[i] >> vi[i];
  for(int i = 1 ; i <= n ; i++) {
    for(int j = w ; j >=0 ; j--) {
      if(j - wi[i - 1] >= 0) {
        dp[j] = max(dp[j], vi[i - 1] + dp[j - wi[i - 1]]);
      }
    }
  }
  cout << dp[w] << endl;
  return 0;
}


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

int main(void)
{
	int a, b;
	cin >> a;
	cin >> b;

	if ((a * b) % 2 == 0) {
		cout << "Even" << endl;
	} else {
		cout << "Odd" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int n, l;
string s;
int mx = 0;
int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> s;
        m[s]++;
    }
    cin >> l;
    for (int i = 0; i < l; i++)
    {
        cin >> s;
        m[s]--;
    }
    map<string, int>::iterator p;
    for (p = m.begin(); p != m.end(); p++)
    {
        mx = max(mx, p->second); //firstがキー，secondが値
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#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);
  ve<int> l(N);
  rep(i, N){
    ci(l.at(i));
  }
  sort allr(l);
  int a = 0;
  rep(i, K){
    a += l.at(i);
  }
  co(a);
}

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

int main(){
  int n; cin>>n;
  vector<ll> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  
  ll ans=0,x=1;
  for(int i=0;i<61;i++){
    ll c0=0,c1=0;
    for(int j=0;j<n;j++){
      if(num[j]%2==0){
        c0++;
      }else{
        c1++;
      }
      num[j]/=2;
    }
    c0*=x;
    c0%=MOD;
    c0*=c1;
    c0%=MOD;
    ans+=c0;
    ans%=MOD;
    x*=2;
    x%=MOD;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        mut a: [i64; 5],
        k: i64,
    }

    a.sort();

    let ans = if a[4] - a[0] > k { ":(" } else { "Yay!" };

    println!("{}", ans);
}


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

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

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

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

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

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double n,a,b,c;
  cin >> n >> a >> b >> c;
  double cal = c,pr = a;
  vary(ll,d,n,0);
  rep(i,n){
    cin >> d[i];
  }
  sort(all(d),greater<ll>());
  rep(i,n){
    if((cal+d[i])/(pr+b)>cal/pr){
      cal += d[i];
      pr += b;
    }
  }
  cout << int(cal/pr)<<endl;
  return 0;
}

Measured memory_bytes: 3240
import sys
a, b, c = map(int, input().split())
i = a ** 2 + b ** 2 + c ** 2
j = 2 * (a * b + b * c + c * a)
k = i - j
if c - a - b < 0:
    print("No")
    sys.exit()
if k > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
using System;

namespace ITP1_4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            double a, b;
            string str = Console.ReadLine();
            double r = double.Parse(str);

            a = r * r * Math.PI;
            b = 2 * r * Math.PI;

            Console.WriteLine("{0:F6} {1:F6}", a, b);
        }
    }
}

Measured memory_bytes: 9236
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,o,h,p;
	char s[8];
	scanf("%d",&n);
	o=h=p=0;
	while(n>0){
		scanf("%s",s);
		if(s[1]=='I'){
			h++;
			if(h>3){p++;h--;}
		}else if(s[1]=='U'){
			o++;
			if(o>2){
				printf("%d\n",p);
				o=h=p=0;
				n--;
			}
		}else if(s[1]=='O'){
			p+=h+1;
			h=0;
		}
	}
	return 0;
}

Measured memory_bytes: 1184
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

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

    char ch;
    cin>>ch;ch++;
    cout<<ch;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {

			int n = sc.nextInt();

			if (n == 0) {
				break;
			}

			int[] scores = new int[n];
			for (int i = 0; i < scores.length; i++) {
				scores[i] = sc.nextInt();

			}

			int max = scores[0];
			int min = scores[0];

			for (int i = 1; i < scores.length; i++) {

				if (scores[i] > max) {

					max = scores[i];
				}

				if (scores[i] < min) {

					min = scores[i];
				}

			}

			int average = 0;
			int sum = 0;

			for (int i = 0; i < scores.length; i++) {

				sum += scores[i];

			}

			sum -= max;
			sum -= min;

			average = sum / (n - 2);

			System.out.println(average);

		}

	}

}

Measured memory_bytes: 29208
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 5003, mod = 1e9 + 7;
int n, head[N], to[N << 1], nxt[N << 1], siz[N], f[N][N], tmp[N], g[N];
inline void qmo(int &x){x += (x >> 31) & mod;}
inline void add(int a, int b){
    static int cnt = 0;
    to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt;
}
inline void dfs(int x, int fa = 0){
    f[x][1] = siz[x] = 1;
    for(Rint i = head[x];i;i = nxt[i]) if(to[i] != fa){
        dfs(to[i], x);
        memcpy(tmp + 1, f[x] + 1, siz[x] << 2);
        memset(f[x] + 1, 0, siz[x] << 2);
        for(Rint j = 1;j <= siz[x];++ j)
            for(Rint k = 0;k <= siz[to[i]];++ k)
                qmo(f[x][j + k] += (LL) tmp[j] * f[to[i]][k] % mod - mod);
        siz[x] += siz[to[i]];
    }
    for(Rint i = 2;i <= siz[x];i += 2)
        qmo(f[x][0] -= (LL) f[x][i] * g[i] % mod);
}
int main(){
    scanf("%d", &n);
    for(Rint i = 1, u, v;i < n;++ i){
        scanf("%d%d", &u, &v); add(u, v); add(v, u);
    }
    g[0] = 1;
    for(Rint i = 2;i <= n;i += 2) g[i] = (i - 1ll) * g[i - 2] % mod;
    dfs(1); printf("%d\n", mod - f[1][0]);
}


Measured memory_bytes: 58380
W, H, x, y, r = map(int, input().split())
flag = 0
if x-r < 0:
  flag = -1
if x + r > W:
  flag = -1
if y-r <0:
  flag = -1
if y+r > H:
  flag = -1

if  flag == -1:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 5596
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define MAX_INT 15

ll N, M, A, B, C;
ll arr[MAX_INT];
vector<ll> V;
ll mark[MAX_INT];
ll ans[MAX_INT], arr1[MAX_INT];


int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < M; i++) {
		scanf("%lld %lld", &arr[i], &arr1[i]);
		if(ans[arr[i]] != 0 && ans[arr[i]] != arr1[i]) {
			printf("-1\n");
			exit(0);
		}
		ans[arr[i]] = arr1[i];
		mark[arr[i]] = 1;
	}	
	if(N == 1 && !M) {
		printf("0\n");
		exit(0);
	}
	for(int i = 1; i <= N; i++) {
		if(i == 1 && !mark[i]) {
			ans[i] = 1;
		}
		else {
			if(!mark) {
				ans[i] = 0;
			}
		}
	}
	if(N == 1 && ans[1] == 0) {
		printf("0\n");
		exit(0);
	}
	for(int i = 1; i <= 999; i++) {
		ll X = i;
		int flag = 1;
		ll cnt = 0;
		while(X) {
			ll tmp = X % 10;
			if(tmp != ans[N - cnt]) {
				flag = 0;
				break;
			}
			X /= 10;
			cnt++;
		} 
		// cout << i << " " << cnt << " \n";
		if(cnt != N) {
			continue;
		}
		if(flag) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <iostream> 
using namespace std;
int main()
{
	long long n,a,b,c;
	cin>>n;
	for(long long a=1;a<=3500;a++)
		for(long long b=1;b<=3500;b++){
			long long x=n*a*b;
			long long y=4*a*b-n*b-n*a;
			if(y>0 && x%y==0){
				cout<<a<<" "<<b<<" "<<x/y<<endl;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair< ll, ll > point;
typedef pair< point, point > rect;

rect new_rect(ll x1, ll y1, ll x2, ll y2)
{
  point p1 = point(x1, y1);
  point p2 = point(x2, y2);
  return rect(p1, p2);
}

ll max(ll a, ll b)
{
  return a > b ? a : b;
}

ll min(ll a, ll b)
{
  return a > b ? b : a;
}

vector< rect > points(ll cx, ll cy, ll K)
{
  vector< rect > res;
  ll x1 = max(0, cx - K);
  ll y1 = max(0, cy - K);
  ll x2 = cx;
  ll y2 = cy;
  res.push_back(new_rect(x1, y1, x2, y2));

  x2 = min(2 * K, cx + K), y2 = min(2 * K, cy + K);
  x1 = cx, y1 = cy;
  res.push_back(new_rect(x1, y1, x2, y2));

  if (K < cy)
  {
    x2 = min(2 * K, cx + K), y2 = cy - K;
    x1 = cx, y1 = max(0, y2 - K);
    res.push_back(new_rect(x1, y1, x2, y2));
  }

  if (cx < K)
  {
    x2 = min(2 * K, cx + 2 * K), y2 = cy;
    x1 = cx + K, y1 = max(0, cy - K);
    res.push_back(new_rect(x1, y1, x2, y2));
  }

  if (K < cx)
  {
    x2 = cx - K, y2 = min(2 * K, cy + K);
    x1 = max(0, x2 - K), y1 = cy;
    res.push_back(new_rect(x1, y1, x2, y2));
  }

  if (K < cx && K < cy)
  {
    x2 = cx - K, y2 = cy - K;
    x1 = max(0, x2 - K), y1 = max(0, y2 - K);
    res.push_back(new_rect(x1, y1, x2, y2));
  }

  return res;
}

ll white[2001][2001];
ll checker(ll N, ll K, vector< pair< point, char > > C)
{
  memset(white, 0, sizeof(white));

  for (pair< point, char > pc : C)
  {
    point p = pc.first;
    ll x = p.first, y = p.second;
    char c = pc.second;

    if (c == 'B')
      x += K;

    ll tx = (x % (2 * K)) + 1;
    ll ty = (y % (2 * K)) + 1;
    white[tx][ty] += 1;
  }

  for (ll ky = 0; ky < 2 * K; ky++)
    for (ll kx = 0; kx < 2 * K; kx++)
      white[ky + 1][kx + 1] += white[ky + 1][kx];

  for (ll ky = 0; ky < 2 * K; ky++)
    for (ll kx = 0; kx < 2 * K; kx++)
      white[ky + 1][kx + 1] += white[ky][kx + 1];

  ll max_count = 0;
  for (ll ky = K; ky < 2 * K; ky++)
  {
    for (ll kx = 0; kx < 2 * K; kx++)
    {
      ll count = 0;
      for (rect r : points(kx, ky, K))
      {
        ll x1 = r.first.first;
        ll y1 = r.first.second;
        ll x2 = r.second.first;
        ll y2 = r.second.second;

        count += white[y2][x2] - white[y2][x1] - white[y1][x2] + white[y1][x1];
      }
      max_count = max(max_count, count);
      if (max_count == N)
        break;
    }
  }
  return max_count;
}

int main(int argc, char** argv)
{
  ll N, K;
  cin >> N >> K;
  vector< pair< point, char > > C;
  for (ll n = 0; n < N; n++)
  {
    ll x, y;
    char c;
    cin >> x >> y >> c;
    C.push_back(pair< point, char >(point(x, y), c));
  }
  ll ans = checker(N, K, C);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 36976
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int MY_COM(int n, int k) {
	int x=1, y=1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n / 2 << endl;
	else cout << n / 2 + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)


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

   vec_int A(M);
   vec_int B(M);

   vector<vector<int>> G(N+1);
   rep(i, M){
       cin>>A.at(i)>>B.at(i);
       G.at(A.at(i)).push_back(B.at(i));
       G.at(B.at(i)).push_back(A.at(i));
   }


    //ダイクストラ法で各地点までの最短経路を求める

    vec_int visited(N+1,0);
    vec_int cost_vec(N+1,INT_MAX);
    vec_int prev_vec(N+1,0);

    
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push(make_tuple(0,1,0));

    while(!pq.empty()){
        T temp1 = pq.top();pq.pop();
        int cost,pos,prev_pos;
        tie(cost,pos, prev_pos) = temp1;
        if(visited.at(pos)==1)continue;
        visited.at(pos)=1;
        cost_vec.at(pos) = cost;
        prev_vec.at(pos) = prev_pos;

        for(int next_pos: G.at(pos)){
            int next_cost = cost + 1;
            if(cost_vec.at(next_pos)<=next_cost){
                continue;
            }
            pq.push(make_tuple(next_cost,next_pos,pos));
        }
    }

    rep(i, N){
        if(visited.at(i+1)!=1){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    rep(i, N){
        if(i==0)continue;
        cout<<prev_vec.at(i+1)<<endl;
    }







}

Measured memory_bytes: 14004
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
l=[a,b,c,d,e]
k=[]
for i in l:
    m=10
    for j in range(14):
        if 10*j-i>=0:
            m=10*j-i
            break
    k.append(m)
print(sum(l)+sum(k)-max(k))


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	int x, y;
	cin >> x >> y;

	if (x == 1 && y == 1) {
		cout << 1000000 << endl;
	}
	else {
		cout << max(0, 4 - x) * 100000 + max(0, 4 - y) * 100000 << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T> &st){ os << "["; for(auto a : st) cout << a << ","; os << "]"; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
int main(){
    cin >> N;
    vector<double> a(N);
    rep(i,N) cin>>a[i];
    vector<double> b(a);
    sort(all(b));
    rep(i,N){
        int s = lower_bound(all(b),a[i]) - b.begin();
        int t = upper_bound(all(b),a[i]) - b.begin();
        int v = (t-s) + s * 3;
        cout << v-1 << endl;
    }
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int a,b;
     cin>>a>>b;
     cout<<6-a-b<<endl;
     time();
     return 0;
}

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

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

using namespace std;
using lint=long long;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	lint choose[51][51]={1};
	rep(i,50){
		choose[i+1][0]=1;
		rep(j,i+1) choose[i+1][j+1]=choose[i][j]+choose[i][j+1];
	}

	int n,k,s,t; scanf("%d%d%d%d",&n,&k,&s,&t);

	if((s&t)!=s) return puts("0"),0;

	vector<int> a;
	rep(i,n){
		int x; scanf("%d",&x);
		bool ok=true;
		rep(i,18){
			if((s>>i&1)==0 && (t>>i&1)==0){
				if((x>>i&1)!=0) ok=false;
			}
			if((s>>i&1)==1 && (t>>i&1)==1){
				if((x>>i&1)!=1) ok=false;
			}
		}
		if(ok) a.emplace_back(x);
	}
	n=a.size();

	vector<int> D;
	rep(i,18) if((s>>i&1)!=(t>>i&1)) D.emplace_back(i);
	int m=D.size();
	{
		vector<int> b(n);
		rep(i,n){
			rep(j,m) if(a[i]>>D[j]&1) b[i]|=1<<j;
		}
		a=b;
	}

	lint ans=0;
	rep(i,k) ans+=choose[n][i+1];
	rep(S,1<<m) if(S!=0) {
		lint tmp=0;
		vector<bool> used(n);
		rep(i,n) if(!used[i]) {
			int cnt=0;
			rep(j,n) if((a[i]&S)==(a[j]&S)) used[j]=true, cnt++;
			rep(i,k) tmp+=choose[cnt][i+1];
		}
		if(popcount(S)%2==0) ans+=tmp;
		else                 ans-=tmp;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3792
# pencil and paper !
# n = 3 (x, y, z = 山, a, b, c = ダム)
# x = a - b + c
# y = a + b - c
# z = -a + b + c
# 
# n = 5
# x = a - b + c - d + e
# y = a + b - c + d - e
# 両隣は + , それ以降は -, +, -, +
# z =-a + b + c - d + e
#
# 1e5 * 1e5だけど
# 2つめ以降は前のを利用で 1e5 * 1 
# y + x = 2a
# y = 2a - x
#
# z + y  = 2b
# z = 2b - y
n = int(input())
aaa = list(map(int, input().split(' ')))
ans = []
for i in range(n):  # 1e5
    r = 1
    temp = 0
    if not ans:
        for j in range(n):  # 1e5
            temp += (aaa[(i+j) % n ] * r)
            r *= -1
    else:
        temp = 2 * aaa[(i-1) % n] - ans[-1] 
    ans.append(temp)
print(' '.join(map(str, ans)))

Measured memory_bytes: 88796
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int count=0;
    for(int i=a;i<=b;i++){
        string x=to_string(i);
        if(x[0]==x[4] && x[1]==x[3]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct{
  char suit;
  char num;
  int idx;
}Card;

void print(Card* A, int N){
  int i;
  for(i = 0; i < N; i++){
    if(i) printf(" ");
    printf("%c%c",A[i].suit,A[i].num);
  }
  printf("\n");
}

void is_stable(Card* A, int N){
  int i;
  for(i = 0; i+1 < N; i++)
    if(A[i].num == A[i+1].num && A[i].idx > A[i+1].idx){
      printf("Not stable\n");
      return;
    }
  printf("Stable\n");
}

void swap(Card* a, Card* b){
  Card tmp = *a;
  *a = *b;
  *b = tmp;
}

int bubble_sort(Card* A, int N){
  int i,j, cnt=0;
  for(i = 0; i < N; i++)
    for(j = N-1; j >= i+1; j--)
      if(A[j].num < A[j-1].num){
	swap(&A[j],&A[j-1]);
	cnt++;
      }
  return cnt;
}

int selection_sort(Card* A, int N){
  int i,j,cnt=0;
  for(i = 0; i < N; i++){
    int mini = i;
    for(j = i; j < N; j++) if(A[j].num < A[mini].num) mini = j;
    cnt += (i==mini?0:1);
    swap(&A[i],&A[mini]);
  }
  return cnt;
}

int main(){
  int i,N;
  Card data1[40],data2[40];
  scanf("%d\n",&N);
  for(i = 0; i < N; i++) scanf("%c%c ",&data1[i].suit, &data1[i].num);
  for(i = 0; i < N; i++){
    data2[i] = data1[i];
    data1[i].idx = data2[i].idx = i;
  }
  bubble_sort(data1,N);
  selection_sort(data2,N);
  print(data1,N);
  is_stable(data1,N);
  print(data2,N);
  is_stable(data2,N);
  return 0;
}

Measured memory_bytes: 616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		String input = br.readLine();
		
		//iより左に、西を向いている人が何人いるか
		int[] westCount = new int[n];
		//iより右に、東を向いている人が何人いるか
		int[] eastCount = new int[n];
		
		for(int i = 1; i < n; i++){
			if(input.charAt(i - 1) == 'W'){
				westCount[i] = westCount[i - 1] + 1;
			}
			else {
				westCount[i] = westCount[i - 1];
			}
			
			if(input.charAt(n - i) == 'E'){
				eastCount[n - i - 1] = eastCount[n - i] + 1; 
			}
			else {
				eastCount[n - i - 1] = eastCount[n - i];
			}
		}
		
		int result = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int tmp = westCount[i] + eastCount[i];
			
			result = Math.min(tmp, result);
		}
		
		//debug
//		for(int i = 0; i < n; i++){
//			System.out.print(westCount[i] + " ");
//		}
//		
//		System.out.println();
//
//		for(int i = 0; i < n; i++){
//			System.out.print(eastCount[i] + " ");
//		}
//		
//		System.out.println();

		System.out.println(result);
		
	}

}


Measured memory_bytes: 28536
#include <stdio.h>

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

//answer_max:2192
unsigned short int dp[5][32770];

int main(){
  unsigned short int i,j,k;
  int n;
  for(i=1; i*i<(1<<15); i++){
    dp[1][i*i] = 1;
    for(j=i*i+1; j<(1<<15); j++){
      for(k=1; k<4; k++){
	dp[k+1][j] += dp[k][j-i*i];
      }
    }
  }
  while(scanf("%d",&n),n){
    printf("%d\n",dp[1][n]+dp[2][n]+dp[3][n]+dp[4][n]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

int a[200010];
int n;
long long ans;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    sort(a+1,a+n+1);
    ans=0;
    if(n%2){
        for(int i=1;i<=(n-3)/2;i++)
            ans+=2*(a[n-i+1]-a[i]);
        ans+=a[(n+3)/2]-a[(n-1)/2];
        ans+=max(a[(n+3)/2]-a[(n+1)/2],a[(n+1)/2]-a[(n-1)/2]);
    }else{
        for(int i=1;i<=n/2-1;i++)
            ans+=2*(a[n-i+1]-a[i]);
        ans+=a[n/2+1]-a[n/2];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
s=gets.chomp
a= 0
b=0
0.upto(s.length-1) do |i|
  if s[i] == "A"
    a = i
    break
  end
end
(s.length-1).downto(0) do |i|
  if s[i] == "Z"
    b = i
    break
  end
end
p b - a + 1


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

int main()
{
	int n; cin >> n;
	string s; cin >> s;
	
	const int alphabetNum = 26;
	int ans = 0;
	
	for (int i = 1; i < s.size() - 1; i++) {

		string s_front = s.substr(0, i);
		string s_rear = s.substr(i);
		vector<int> vec_s_front(alphabetNum, 0);
		vector<int> vec_s_rear(alphabetNum, 0);
		
		for (int j = 0; j < s_front.size(); j++) {
			vec_s_front[s_front[j] - 'a']++;
		}

		for (int j = 0; j < s_rear.size(); j++) {
			vec_s_rear[s_rear[j] - 'a']++;
		}
	
		int cnt = 0;
		for (int j = 0; j < alphabetNum; j++) {
			if (1 <= vec_s_front[j] && 1 <= vec_s_rear[j]) cnt++;
		}
		
		ans = max(ans, cnt);
	
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
// atcoder/abc165/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  lli x;
  while (cin >> x) {
    lli y = 100;
    for (int i = 0; ; ++i) {
      if (x <= y) {
        cout << i << endl;
        break;
      }
      y += y / 100;
    }
  }

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<iomanip>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)



int main()
{
	long double x;
	cin >> x;
	long double p;
	p = x / 3;
	cout <<fixed<< setprecision(10)<< pow(p, 3) << "\n";
	return 0;
}

Measured memory_bytes: 3832
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{	
		int N = Int32.Parse(Console.ReadLine());
		string S = Console.ReadLine();
		
		int[] csumEast = new int[N+2];
		int[] csumWest = new int[N+2];
		for(int i = 1; i <= N; i++)
		{
			csumEast[i] = csumEast[i-1];
			csumWest[i] = csumWest[i-1];
			if(S[i-1] == 'E')
				csumEast[i]++;
			else
				csumWest[i]++;
		}
		csumEast[N+1] = csumEast[N];
		csumWest[N+1] = csumWest[N];

		int ans = Int32.MaxValue;
		for(int i = 1; i <= N; i++)
		{
			int tmp = 0;
			tmp += csumWest[i-1];
			tmp += (csumEast[N+1] - csumEast[i]);
			ans = Math.Min(ans, tmp);
		}
			

		Console.WriteLine(ans); 
	}	
}





Measured memory_bytes: 16480
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long int ll;

int main()
{
    ll a, b;
    cin >> a >> b;

    if(a <= 8 && b <= 8)
        cout << "Yay!" << endl;
    else
    {
        cout << ":(" << endl;
    }
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
A,B = np.array([input().split() for _ in range(N)],dtype=np.int64).T

answer = A.sum() # 全部先手がとった場合
improve = A+B # 後手がとると改善する量
improve.sort()
answer -= improve[::-1][1::2].sum()
print(answer)

Measured memory_bytes: 54152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
struct segtree{
	int n;
	function<T(T,T)> op;
	vector<T>arr;
	vector<T>st;
	void build(int lo,int hi,int u){
		if(lo==hi){
			st[u]=arr[lo];
		}
		else{
			int mi=(hi+lo)>>1;
			build(lo,mi,u<<1);
			build(mi+1,hi,u<<1|1);
			st[u]=op(st[u<<1],st[u<<1|1]);
		}
	}
	segtree(vector<T> v,function<T(T,T)> op):n(v.size()),st(v.size()*4),op(op){
		arr=v;
		build(0,n-1,1);
	}
	segtree(T n,function<T(T,T)> op):n(n),st(n*4),op(op){}
	T query(int lo,int hi,int u,int l,int r){
		if(l>r)return T();
		if(l==lo&&r==hi){
			return st[u];
		}
		int mi=(hi+lo)>>1;
		if(mi>r){
			return query(lo,mi,u<<1,l,r);
		}
		else if(mi<l){
			return query(mi+1,hi,u<<1|1,l,r);
		}
		else{
			return op(query(lo,mi,u<<1,l,mi),query(mi+1,hi,u<<1|1,mi+1,r));
		}
	}
	T query(int l,int r){
		return query(0,n-1,1,l,r);
	}
	T addupd(int lo,int hi,int u,int p,int x){
		if(lo==hi&&lo==p){
			return st[u]+=x;
		}
		int mi=(hi+lo)>>1;
		if(mi>=p){
			return st[u]=op(addupd(lo,mi,u<<1,p,x),st[u<<1|1]);
		}
		else if(mi<p){
			return st[u]=op(addupd(mi+1,hi,u<<1|1,p,x),st[u<<1]);
		}
	}
	T setupd(int lo,int hi,int u,int p,int x){
		if(lo==hi&&lo==p){
			return st[u]=x;
		}
		int mi=(hi+lo)>>1;
		if(mi>=p){
			return st[u]=op(addupd(lo,mi,u<<1,p,x),st[u<<1|1]);
		}
		else if(mi<p){
			return st[u]=op(addupd(mi+1,hi,u<<1|1,p,x),st[u<<1]);
		}
	}
	void add(int p,T x){
		addupd(0,n-1,1,p,x);
	}
	void set(int p,T x){
		setupd(0,n-1,1,p,x);
	}
//	void radd(int l,int r,T x){
//		
//	}
//	void rset(int l,int r,T x){
//		
//	}
	void add(int l,int r,T x){
		if(l==r)add(l,x);
//		else radd(l,r,x);
	}
	void set(int l,int r,T x){
		if(l==r)set(l,x);
//		else rset(l,r,x);
	}
};
int main(){
	int n,q;
	cin>>n>>q;
	segtree<int>t(n,[](int a,int b){
		return a+b;
	});
	while(q--){
		int c,x,y;
		cin>>c>>x>>y;
		if(c){
			cout<<t.query(x-1,y-1)<<"\n";
		}
		else{
			t.add(x-1,y);
		}
	}
}



Measured memory_bytes: 4416
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
//#define int unsigned long long
#define ll long long
#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	// 10^18 = 1000000000000000000

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	int n;
	//char n;
	//int a = -111, b = -111;
	int m;
	int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;
	//int x, y;

	string s[111111];
	//string s[100000];
	//char a[1000000];
	//int a[200000];
	//int b[200000];
	//int a[2000000] = { 0 };
	//int b[2000000] = { 0 };
	//int a[20000] = { 0 };
	//int b[20000] = { 0 };
	//vector<int>a(2000000);
	//vector<int>b(2000000);

	//int aaa = 0;
	//int bbb = 0;

	//int box[1000000000000000000];
	int box=0;
	//int box2;
	//int p[1111];

	//long double aaa;

	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;

	int count = 0;
	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//bool flag = true;
	bool flag = false;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	cin >> n;
	//cin >> a >> b;
	//cin >> n >> m >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		if (s[i] == "AC")
		{
			ac++;
		}
		else if(s[i]=="WA")
		{
			wa++;
		}
		else if(s[i]=="TLE")
		{
			tle++;
		}
		else
		{
			re++;
		}
	}

	//n = s.length();

	//sort(p, p + n);
	//n = n - 'Z';

	//for (int i = 0; i < 1000; i++)
	//{
	//	if (n < 1000)
	//	{
	//		all = 1000 - n;
	//		break;
	//	}
	//	n -= 1000;
	//	if (n == 0)
	//	{
	//		all = 0;
	//		break;
	//	}
	//}

	//box = n % 26;

	//for (int i = 0; i < k; i++)
	//{
	//	all += p[i];
	//}

	//all = n + (n * n) + (n * n * n);

	/*if (n > 0)
	{
		cout << "a\n";
	}
	else
	{
		cout << "A\n";
	}*/
	//n = t.length();

	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";

	//cout << all << "\n";
	//cout << box << "\n";
	//cout << a << "\n";

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/

	//cout << fixed << setprecision(111) << all;
}


Measured memory_bytes: 7096
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
a=0
b=0
c=0
for i in range(len(P)):
    if P[i]<=A:
        a+=1
    elif P[i]<=B:
        b+=1
    else:
        c+=1
print(min(a,b,c))

Measured memory_bytes: 3064