akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int l = sc.nextInt();
      int[] arr = new int[n];
      int sum = 0;
      for(int i = 0; i < n; i++) {
        arr[i] = l + i;
        sum += arr[i];
      }
      int min = Integer.MAX_VALUE;
      int res = 0;
      for(int i = 0; i < n; i++) {
        if(Math.abs(arr[i]) < min) {
          min = Math.abs(arr[i]);
          res = sum - arr[i];
        }
      }
      System.out.println(res);
  }
}

Measured memory_bytes: 23764
const MAX: i64 = 1000000000;


fn main() {
    let s: i64 = read();

    let (x3, y3) = if s == 1000000000000000000 {
        (0, MAX)
    } else {
        (MAX - s % MAX, s / MAX + 1)
    };

    println!("0 0 {} 1 {} {}", MAX, x3, y3);
}
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


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

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

  int a[n][m] = {{0}};
  int b[m] = {0};
  int c[n] = {0};

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

  for (int j = 0; j < m; j++) {
    cin >> b[j];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c[i] += (a[i][j] * b[j]);
    }
  }

  for (int i = 0; i < n; i++) {
    cout << c[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	string S, T, U;
	ll A, B;

	cin >> S;
	cin >> T;
	cin >> A;
	cin >> B;
	cin >> U;

	if (S == U)
	{
		A -= 1;
	}
	else
	{
		B -= 1;
	}

	cout << A << " " << B << endl;

	//system("pause");
}


Measured memory_bytes: 256
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)*}
    };
}

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

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut c = [0, 0, 0];
    for i in 0..n {
        c[v[i] - 1] += 1;
    }
    let mut tab: Vec<Vec<Vec<f64>>> = vec![vec![vec![0.; c[0] + c[1] + c[2] + 1]; c[1] + c[2] + 1]; c[2] + 1];
    for i in 0..c[2] + 1 {
        for j in 0..c[1] + c[2] + 1 - i {
            for k in 0..c[0] + c[1] + c[2] + 1 - i - j {
                let l = i + j + k;
                if l == 0 {
                    continue;
                }
                tab[i][j][k] = n as f64 / l as f64;
                if i != 0 {
                    tab[i][j][k] += tab[i - 1][j + 1][k] * i as f64 / l as f64;
                }
                if j != 0 {
                    tab[i][j][k] += tab[i][j - 1][k + 1] * j as f64 / l as f64;
                }
                if k != 0 {
                    tab[i][j][k] += tab[i][j][k - 1] * k as f64 / l as f64;
                }
            }
        }
    }
    println!("{}", tab[c[2]][c[1]][c[0]]);
}


Measured memory_bytes: 237820
//2018.09.14 unfinish
//答えはあってそうだけど、REになる。<-配列のスタックオーバーフロー?

#include <iostream>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    int a[H][W];

    int i,j;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin >> a[i][j];
        }
    }

    int ans[4*H*W];
    int count = 0;

    for(i=0;i<H-1;i++){
        for(j=0;j<W;j++){
            if(a[i][j]%2!=0){
                a[i+1][j]+=1;
                ans[count*4]=i;
                ans[count*4+1]=j;
                ans[count*4+2]=i+1;
                ans[count*4+3]=j;
                count++;
            }
        }
    }

    for(j=0;j<W-1;j++){
        if(a[H-1][j]%2!=0){
            a[H-1][j+1]+=1;
            ans[count*4]=H-1;
            ans[count*4+1]=j;
            ans[count*4+2]=H-1;
            ans[count*4+3]=j+1;
            count++;
        }
    }

    cout << count << endl;
    for(i=0;i<(count*4);i+=4){
        cout << ans[i]+1 << ' ' << ans[i+1]+1 << ' ' << ans[i+2]+1 << ' ' << ans[i+3]+1 << endl;
    }
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using  namespace std;
typedef long long ll;
const ll Mod = 998244353;
const int MAXN = 10000;
bool flag;

int main() {
  int n;
  cin >> n;
  int d[n+1];
  rep(i, n) cin >> d[i];
  if (d[0] != 0) flag = true;
  sort(d, d+n);
  d[n] = d[n-1] + 1;
  if (n > 1 && d[1] == 0) flag = true;
  if (flag) {
    cout << 0 << endl;
    return 0;
  }

  int k = 1;
  ll ans = 1;
  ll buf = 1;
  while (lower_bound(d, d+n+1, k+1) != d+n+1) {
    if (lower_bound(d, d+n+1, k+1) == upper_bound(d, d+n+1, k+1)) {
      ans = 0;
      break;
    }
    int tmp = lower_bound(d, d+n+1, k+1) - lower_bound(d, d+n+1, k);
    rep(i, tmp) ans = ans * buf % Mod;
    buf = tmp;
    ++k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    REP(i,N){
        cin>>A[i];
    }
    //inputend;
    sort(ALL(A));
    int flag=0;
    REP(i,N-1){
        if(A[i]==A[i+1]){
            flag=1;
        }
    }
    if(flag){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 1024
import numpy as np

c = [list(map(int,input().split())) for i in range(3)]
c = np.array(c)
flg = True

for i in range(2):
    if not c[0,i]-c[0,i+1] == c[1,i]-c[1,i+1] == c[2,i]-c[2,i+1]:
        flg = False
        break
    if not c[i,0]-c[i+1,0] == c[i,1]-c[i+1,1] == c[i,2]-c[i+1,2]:
        flg = False
        break
print('Yes') if flg else print('No')

Measured memory_bytes: 27124
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <cassert>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	const int m = n + 2;
	vector<int> p(n * n);
	for(int i = 0; i < n * n; ++i){
		int x;
		cin >> x;
		const int r = (x - 1) / n, c = (x - 1) % n;
		p[i] = (r + 1) * m + (c + 1);
	}
	vector<int> cache(m * m);
	vector<char> done(m * m, 1);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			cache[(i + 1) * m + (j + 1)] = min({ i, n - 1 - i, j, n - 1 - j });
			done[(i + 1) * m + (j + 1)] = 0;
		}
	}
	const array<int, 4> delta = { -m, -1, 1, m };
	vector<int> q0, q1;
	int answer = 0;
	for(const auto s : p){
		const int dist = cache[s];
		answer += dist;
		done[s] = 1;
		int cost = dist;
		q0.push_back(s);
		while(!q0.empty()){
			while(!q0.empty()){
				const int c = q0.back();
				q0.pop_back();
				for(const auto d : delta){
					const int cc = c + d;
					if(cost < cache[cc]){
						cache[cc] = cost;
						if(done[cc]){
							q0.push_back(cc);
						}else{
							q1.push_back(cc);
						}
					}
				}
			}
			q0.swap(q1);
			++cost;
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 6108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int x = obj.nextInt();
        for(int i=-200;i<=200;i++)
        {
            for(int j=-200;j<=200;j++)
            {
                if((Math.pow(i,5)-Math.pow(j,5))==x)
                {
                    System.out.print(i+" "+j);
                    return;
                }
            }
        }
    }
}


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

n, m = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(m):
    i, j = map(int, input().split())
    i -= 1
    j -= 1
    tree[i].append(j)
    tree[j].append(i)

# BFS
from collections import deque

# todoに(現在の頂点, [通った頂点の履歴])を追加する
first = [True] * n
first[0] = False
todo = deque([(0, first)])
ans = 0
while len(todo) > 0:
    now, history = todo.popleft()
    if not any(history):
        ans += 1
        continue
    for i in tree[now]:
        if history[i]:
            next_history = history.copy()
            next_history[i] = False
            todo.append((i, next_history))

print(ans)

Measured memory_bytes: 74616
#include <iostream>
using namespace std;
int main() {
    unsigned long long N, b=10, ans=0;
    cin >> N;
    if (N % 2 == 0) {
        while (b <= N) {
            ans += N / b;
            b *= 5;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=200010;
char s[mn];
int cnt[30][mn],len;
ll ans;
int main() {
	scanf("%s",s);
	len=strlen(s);
	for (int i=len-1;i>=0;i--) {
		for (int j=0;j<26;j++)
			cnt[j][i]=cnt[j][i+1];
		cnt[s[i]-'a'][i]++;
	}
	ans=(ll)len*(len-1)/2+1;
	for (int i=0;i<len;i++)
		ans-=(ll)cnt[s[i]-'a'][i+1];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20864
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
pii cc(ll x)
{
	ll a=x%10;
	while(x>9)
	{
		x/=10;
	}
	return {x,a};
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,total,ans,h,b,x,y,n; bool xx;
    	cin>>n;
    	ll c[10][10];
    	repi(i,0,9)
    	{
    		repi(j,0,9)
    		c[i][j]=0;
		}
    	pii p; ans=0;
    	repi(i,1,n)
    	{
    		p=cc(i);
    		c[p.F][p.S]++;
		}
		repi(i,0,9)
		{
			repi(j,0,9)
			{
				ans+=c[i][j]*c[j][i];
			}
		}
		cout<<ans<<'\n';
    } 
    
	return 0;
}

Measured memory_bytes: 256
using System;
class Program
    {
        static void Main(string[] args)
        {
            //まずは数字を読む
            string[] input = Console.ReadLine().Split(' ');
            int p = int.Parse(input[0]);
            int q = int.Parse(input[1]);
            int r = int.Parse(input[2]);

            //とりあえず最小を決める
            int min = p + q;

            //もし小さければ入れ替え
            if (min > q + r)
                min = q + r;

            if (min > r + p)
                min = r + p;

            Console.WriteLine(min);


        }
    }

Measured memory_bytes: 13140
from collections import defaultdict
N,A=map(int,input().split())
X=list(map(int,input().split()))
Y=[_-A for _ in X]
D=defaultdict(int)
D[0]=1
for y in Y:
    for k,v in list(D.items()):D[k+y]+=v
print(D[0]-1)

Measured memory_bytes: 3572
# coding: utf-8
l = [300000, 200000, 100000]
l += [0] * 1000
x, y = map(int, input().split())
if x == y == 1:
    print(l[x-1] + l[y-1] + 400000)
else:
    print(l[x-1] + l[y-1])

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int n, i, check, tmp, t=0;
  scanf("%d",&n);
  int array[n];
  for(i = 0; i < n; i++) scanf("%d",&array[i]);

  check = 1;
  while(check == 1){
    check = 0;
    for(i = n-1; i >= 1; i--){
      if(array[i] < array[i-1]){
	tmp = array[i-1];
	array[i-1] = array[i];
	array[i] = tmp;

	t += 1;
	check = 1;
      }
    }
  }

  for(i = 0; i < n; i++) {
    if(i == n-1) printf("%d\n",array[i]);
    else printf("%d ",array[i]);
  }
  printf("%d\n", t);

  return 0;
}

  



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define N 50000
using namespace std;
typedef long long ll;
bool used[N];

ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}

bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=min((ll)N,n);i++){
    if(n%i)continue;
    if(i<N)res&=!used[i],used[i]=1;
    //    if(i!=n/i&&n/i<N)res&=!used[n/i],used[n/i]=1;
  }
  return res;
}

int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
  
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
	ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
	if(!mark(lcm))continue;
	sum-=SumD(lcm,lcm,n/lcm);
	cnt-=(n/lcm);
      }
    }

    printf("%.8f\n",(p[0]!=1)*(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3328
from math import gcd
from itertools import combinations_with_replacement as cwr

K = int(input())
n = range(1, K+1)
total = 0

for a,b,c in cwr(n,3):
    d = gcd(gcd(a,b),c)
    if a == b == c:
        total += d
    elif a != b != c:
        total += d*6
    else:
        total += d*3

print(total)

Measured memory_bytes: 9196
//By Tushar Gautam
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5;
ll a,b,c,k;
int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    
    cin>>a>>b>>c>>k;
    if(k & 1LL){
        cout<<b-a;
    }else cout<<a-b;
    return 0;
}

Measured memory_bytes: 764
import java.text.DecimalFormat;
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double r = scanner.nextDouble();

        double a, b;
        a = 3.141592653589 * r * r;
        b = 3.141592653589 * 2 * r;
        DecimalFormat df = new DecimalFormat("0.000000000");

        System.out.println(df.format(a) + " " + df.format(b));
    }
}

Measured memory_bytes: 28020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m;
vector<ll> a;

ll func(ll x){
	ll ok = n;
	ll ng = -1;
	while(ok-ng > 1){
		ll mid = (ok+ng)/2;
		if(a[mid] >= x){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	return n-ok;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	
	set<ll> s;
	rep(i, 0, n){
		ll buf;
		cin >> buf;
		a.push_back(buf);
	}
	sort(a.begin(), a.end());
	
	ll ok = 0;
	ll ng = a[n-1]*2+1;
	while(ng-ok > 1){
		ll mid = (ng+ok)/2;
		ll badget = m;
		rep(i, 0, n){
			badget -= func(mid-a[i]);
		}
		if(badget <= 0){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	
	ll suma[n+1];
	suma[0] = 0;
	rep(i, 1, n+1){suma[i] = suma[i-1]+a[i-1];}
	ll ans = 0;
	rep(i, 0, n){
		ll buf = func(ok-a[i]);
		ans += suma[n] - suma[n-buf];
		ans += a[i]*buf;
	}
	
	ll bufm = 0;
	rep(i, 0, n){
		bufm += func(ok-a[i]);
	}
	ans -= (bufm-m)*ok;
	print(ans)
	return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	int m;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&m);
		a[i]=fabs(m-x);
	}
	sort(a,a+n);
	int cnt=0;
	for(int i=0;i<n;i++)
		if(a[i]%a[0]!=0)
		{
			cnt=1;
			break;
		}	
	if(cnt)
	for(int i=a[0]/2;i>0;i--)
		{
			int j;
			for( j=0;j<n;j++)
				if(a[j]%i!=0)
				{
					break;
				}
			if(j==n)
			{
				cout<<i<<endl;
				return 0;
			}
		}
	for(int i=0;i<n;i++)
	{
		for(int j=n-1;j>=0;j--)
			if(a[j]%a[i]!=0)
				{
					cout<<a[i-1]<<endl;
					return 0;
				}
	}
	cout<<a[n-1]<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin>>n;
    vector<int> v(n);
    int cnt =1;
    for(int i=0;i<n;++i){
        cin>>v[i];
        for(int j=0;j<i;++j){
            if(v[i]<v[j])break;
            if(j==i-1)cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    vector<LLONG> values(N + 1);
    values[0] = 2;
    values[1] = 1;
    for (int i = 2; i <= N; ++i)
    {
        values[i] = values[i - 1] + values[i - 2];
    }
    cout << values[N] << endl;
    return 0;
}

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

int main()
{
	int A, B, V, W, T;
	scanf("%d %d", &A, &V);
	scanf("%d %d", &B, &W);
	scanf("%d", &T);
	if (V <= W) printf("NO\n");
	else if (((long long)abs(A - B) + V - W - 1) / (V - W) <= T) printf("YES\n");
	else printf("NO\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>

void change(int *a,int *b){
		int temp;
		temp=*a;
		*a=*b;
		*b=temp;
}

int main(void){
	
	int x,y,n;
	int num[1000][3];
	
	scanf("%d", &n);
	for(x=0;x<n;x++){
		scanf("%d %d %d", &num[x][0],&num[x][1],&num[x][2]);
		if(num[x][0]<num[x][1]) change(&num[x][0],&num[x][1]);
		if(num[x][1]<num[x][2]) change(&num[x][1],&num[x][2]);
		if(num[x][0]<num[x][1]) change(&num[x][0],&num[x][1]);
		if(num[x][0]*num[x][0]==(num[x][1]*num[x][1])+(num[x][2]*num[x][2])) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  int n;
  cin>>n;
  vector<ll>x(n);
  rep(i,n)cin>>x[i];
  vector<ll>y(n);
  y=x;
  sort(all(y));
  int m=n/2;
  int mida=y[m-1],midb=y[m];
  rep(i,n){
    if(x[i]<=mida)cout<<midb<<endl;
    else cout<<mida<<endl;
  }
  
  
    
    
  return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define IOS	ios::sync_with_stdio(false)
using namespace std;
map<string,int> mp;
int main()
{
	int n;
	scanf("%d",&n);
	int maxs=0;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		mp[s]++;
		maxs=max(mp[s],maxs);
	}
	for(map<string,int> :: iterator it=mp.begin();it!=mp.end();it++)
	{
		if(it->second==maxs)
		{
			cout<<it->first<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25216
// youngjinp20
// 2020 03

#include <bits/stdc++.h>
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define byr(x) [](const auto& a, const auto& b) { return a.x > b.x; }
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
using namespace std;

typedef long long ll;

const int MAX = 3000;
int N;
ll a[MAX];
ll dp[MAX][MAX];

ll solve(int l, int r) {
	if (dp[l][r] != -1) return dp[l][r];
	if (l == r) return a[l];
	return dp[l][r] = max(a[l] - solve(l+1, r), a[r] - solve(l, r-1));
}

int main() {
	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> a[i];
	}
	for (int i=0; i<MAX; i++) {
		for (int j=0; j<MAX; j++) {
			dp[i][j] = -1;
		}
	}
	cout << solve(0, N-1) << endl;

	return 0;
}


Measured memory_bytes: 70784
#[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)*}
    };
}

#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;

fn main() {
    input! {
        a:i32,
        b:i32,
    }

    let mut  ans = a - 2 * b;

    if ans < 0 {
        ans = 0
    }

    println! ("{}", ans);

}


Measured memory_bytes: 4352
'use strict';

var main = input => {
    // const [x, y] = input.split(" ").map(e => parseInt(e));
    const array = input.split(" ").map(e => parseInt(e));
    const x = array[0], y = array[1];
    const group1 = [1, 3, 5, 7, 8, 10, 12],
        group2 = [4, 6, 9, 11];
    let same = false;
    same |= group1.indexOf(x) !== -1 && group1.indexOf(y) !== -1;
    same |= group2.indexOf(x) !== -1 && group2.indexOf(y) !== -1;
    console.log(same ? "Yes" : "No");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N = int(input())
l = [0] * (10**5+1)
nums = [0]
for i in range(N):
  tmp = []
  flag = False
  for k in nums:
    if l[k+1] == 0:
      l[k+1] = l[k]+1
      tmp.append(k+1)
    for j in range(1, N):
      if k+6**j <= N:
        if l[k+6**j] == 0:
          l[k+6**j] = l[k]+1
          tmp.append(k+6**j)
      else:
        break
    for j in range(1, N):
      if k+9**j <= N:
        if l[k+9**j] == 0:
          l[k+9**j] = l[k]+1
          tmp.append(k+9**j)
      else:
        break
    if l[N] > 0:
      flag = True
      break
  if flag:
    break
  else:
    nums = tmp
print(l[N])

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vi a(n),b;
    rep(i,n){
        cin>>a[i];
        if(a[i]-1==i)b.PB(a[i]);
    }
    int cnt=0;
    rep(i,b.size()-1){
        if(b[i]+1==b[i+1]){
            cnt++;
            b[i+1]=-1;
        }
    }
    cout<<b.size()-cnt<<endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,A,B,C=1;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    A = C * 2;
    B = C + K;
    
    if(A < B){
      C = A;
    }
    
    else{
      C = B;
    }
    
  }
  cout << C << endl;
}

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

int main() {
	string s;
	cin >> s;
	int l = s.length();

	string ans = "Yes";
	for (int i = 0; i < l/2; i++) {
		if(s.at(i) != s.at(l - i - 1)) {
			ans = "No";
			break;
		}
	}
	for (int i = 0; i < (l-1)/2/2; i++) {
		if (s.at(i) != s.at((l-1)/2 - i -1)) {
			ans = "No";
			break;
		}
	}
	for (int i = 0; i < l - (l+3)/2; i++) {
		if (s.at((l+3)/2 + i - 1) != s.at(l - i - 1)) {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def powmod(a, n, p):
    if(n==0):
        return 2
    elif(n==1):
        return a%p
    elif(n%2==1):
        return ((a%p)*(powmod(a,n//2,p)**2%p))%p
    elif(n%2==0):
        return powmod(a,n//2,p)**2%p
N=int(input())
p=10**9+7
if(N==1):
    print(0)
else:
    print((powmod(10,N,p)-2*powmod(9,N,p)+powmod(8,N,p))%p)


Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

int n,m;
vs s,t(2);
bool f(int x,int y){
    if(x < 0 || y < 0)return false;
    if(x >= n-1 || y >= m-1)return false;
    rep(i,2)rep(j,2){
        if(s[x+i][y+j] != t[i][j])return false;
    }
    return true;
}

signed main(void) {
    cin >> n >> m;
    s = vs(n);
    rep(i,n)cin >> s[i];
    rep(i,2)cin >> t[i];
    int sum = 0;
    rep(i,n-1)rep(j,m-1){
        if(f(i,j))sum++;
    }
    int ans = 0;
    string q = "JOI";
    rep(i,n)rep(j,m)rep(k,3){
        int tmp = sum;
        int p = -1;
        char c = s[i][j];
        rep(_,2){
            if(f(i-1,j))tmp += p;
            if(f(i-1,j-1))tmp += p;
            if(f(i,j-1))tmp += p;
            if(f(i,j))tmp += p;
            p *= -1;
            s[i][j] = q[k];
        }
        s[i][j] = c;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz 100005
#define all(x) x.begin(),x.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define MOD 1000000007
void fastio(void);

bool mk[1000004];

int main(){
    fastio();
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;  cin>>n;
    int rem=7%n, flag=true, cnt=1;

    while(!mk[rem]){
        if(rem==0){
            cout<<cnt<<endl;
            flag=false;
            break;
        }
        mk[rem]=true;
        rem=(rem*10)%n;
        rem=(rem+7)%n;
        cnt++;
    }

    if(flag)
        cout<<-1<<endl;

    return 0;
}

void fastio(void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

Measured memory_bytes: 4580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define abs(x) ((x) >= 0 ? (x) : -(x))

int main() {

    int n;
    cin >> n;

    vector<int> a;
    a.reserve(n);

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

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

    int q = a[n-1];
    int max = 0;
    for (int i = n - 2; i >= 0; i--) {
        int r = a[i];
        if (abs(q / 2 - r) < abs(q / 2 - max)) {
            max = r;
        }
    }

    cout << q << " " << max << endl;

    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string cc = Console.ReadLine();
            char c = cc[0];
            if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }
            // Console.Read();
        }
    }

}


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

int main() {

    int L, R, d;
    cin >> L >> R >> d;
    int cnt = 0;

    for (int i = L; i <= R; ++i) {
        if (i % d == 0) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3632
import std.algorithm;
import std.array;
import std.stdio;
import std.conv;
import std.string;
import std.range;

void main(){
    size_t w, h, sx, sy;
    char[][] data = new char[][](20, 20);
    while(true){
        auto input = readln.split;
        w = input[0].to!int;
        h = input[1].to!int;
        if(!(w | h)){
            break;
        }
        foreach(i; 0..h){
            foreach(j, c; readln.chomp){
                data[i][j] = c;
                if(c == '@'){
                    sx = j;
                    sy = i;
                    data[i][j] = '#';
                }
            }
        }
        data.dfs(sx, sy, w, h).writeln;
    }
}

auto move = [[1, 0], [0, 1], [-1, 0], [0, -1]];

size_t dfs(char[][] data, size_t sx, size_t sy, size_t w, size_t h){
    size_t count = 1;
    foreach(i; 0..4){
        size_t x = sx + move[i][0];
        size_t y = sy + move[i][1];
        if(0 <= x && x < w && 0 <= y && y < h && data[y][x] != '#'){
            data[y][x] = '#';
            count += dfs(data, x, y, w, h);
        }
    }
    return count;
}

Measured memory_bytes: 1048
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)*}
    };
}

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

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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        n: usize,
        b_vec: [usize; n - 1],
    }
    let mut ans = 0;
    for i in 0..n {
        if i == 0 {
            ans += b_vec[i];
            continue;
        }
        if i == n - 1 {
            ans += b_vec[i - 1];
            continue;
        }
        ans +=  std::cmp::min(b_vec[i], b_vec[i - 1]);
    }
    println!("{}", ans);
}


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

int main(void)
{
  int N,M,pass=0,lm=0,r,l,rm=100000;;
  cin >> N >> M;
  for(int i=0;i<M;i++)
  {
    cin >> l >> r;
   if(lm<l) lm=l;
    if(rm>r)  rm=r;
  }
  for(int i=0;i<N;i++)
  {
    if(i+1<=rm && i+1 >=lm)pass++;
  }
  cout << pass <<endl;
  return 0;
}

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

cnt = 0
i = 0
for i in range(0, 5, 2):
  m = 10 ** i
  if len(str(m)) > len(str(N)):
    break
  M = int("9" * (i + 1))
  
  if M > N:
    M = N
  
  cnt += M - m + 1

print(cnt)

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

int Array[205];

int main(){
	int N,L;
	scanf("%d",&N);
	for (int i = 0; i < 2*N; ++i)
	{
		cin >> L;
		Array[i]=L;
	}
	sort(Array,Array+2*N);
	int Suma=0;
	for (int i = 0; i < N; ++i)
	{
		Suma+=Array[2*i];
	}
	cout << Suma;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a, b, k;
        int[] da = new int[12], db = new int[12], br = new int[12];
        a = in.nextInt();
        b = in.nextInt();
        k = in.nextInt();
        for(int i = 0; i < 10; i++){
            da[i] = a%10;
            db[i] = b%10;
            br[i] = 0;
            a /= 10; b /= 10;
        }
        int maxValue = 0;
        for(int i = 0; i < (1 << 9); i++){
            int nBit = 0;
            for(int j = i; j > 0; j /= 2) nBit += j % 2;
            if(nBit > k) continue;
            int mul = 1, value = 0;
            for(int j = 0; j < 9; j++, mul *= 10){
                br[j+1] = 0;
                value += (da[j] - db[j] - br[j]+ 10) % 10 * mul;
                if(da[j] - db[j] - br[j] < 0){
                    br[j+1] = 1;
                    if((i >> j) % 2 == 1){
                        br[j+1] = 0;
                    }
                }
            }
            if(value > maxValue){
                maxValue = value;
            }
        }
        System.out.println(maxValue);
    }
}

Measured memory_bytes: 17352
#include <stdio.h>

int  partition(int *,int,int);

int main(){
  int A[100000];
  int i,n,q;

  scanf("%d",&n);

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

  
  q = partition(A,0,n-1);

  for(i=0;i<n;i++){

    if(i)printf(" ");

    if(i==q)printf("[");

    printf("%d",A[i]);

    if(i==q)printf("]");

  }

  printf("\n");

  return 0;
}

int partition(int A[],int p,int r){
  int x=0;
  int i=0;
  int j;
  int temp=0;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;

      
    }
  }
   temp = A[i+1];
   A[i+1] = A[r];
   A[r] = temp;



  return i+1;
}
 
      




Measured memory_bytes: 2172
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    s = []
    for _ in range(N):
        s.append(int(input()))


    ans = sum(s)
    if ans % 10 != 0:
        print(ans)
    else:
        s.sort()
        for v in s:
            if v % 10 != 0:
                print(ans - v)
                return
        else:
            print(0)

    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    l = 0
    r = len(s)-1
    ans = 0
    while l < r:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            print(-1)
            exit()
    print(ans)
    return

if __name__ == '__main__':
    main()


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

int extgcd(int a, int b, int &x, int &y){
  int d = a;
  if(b){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1;
    y = 0;
  }
  return d;
}

void change_ans(int a, int b, int &X, int &Y, int x, int y){
  if(abs(x) + abs(y) < X + Y){
    X = abs(x);
    Y = abs(y);
  }else if(abs(x) + abs(y) == X + Y && a*abs(x) + b*abs(y) < a*abs(X) + b*abs(Y)){
    X = abs(x);
    Y = abs(y);
  }
}

int main(){
  int a, b, d;
  while(cin >> a >> b >> d, a){
    int x, y, g = extgcd(a,b,x,y), r = d/g;
    x *= r; y *= r;
    a /= g;
    b /= g;
    int X = abs(x), Y = abs(y);
    if(x <= 0){
      int x_ = (b - (-x)%b)%b;
      int t = (x_ - x) / b;
      y -= t*a;
      x = x_;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
    }
    if(y <= 0){
      int y_ = (a - (-y)%a)%a;
      int t = (y_ - y) / a;
      x -= t*b;
      y = y_;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
    }
    if(x >= 0){
      int x_ = x%b;
      int t = x / b;
      y += t*a;
      x = x_;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
    }
    if(y >= 0){
      int y_ = y%a;
      int t = y / a;
      x += t*b;
      y = y_;
      change_ans(a,b,X,Y,x,y);
      x += b;
      y -= a;
      change_ans(a,b,X,Y,x,y);
      x -= b;
      y += a;
    }
    cout << X << " " << Y << endl;
  }
  return 0;
}

Measured memory_bytes: 2980
import java.util.*;
// cin=sc.nextInt();
// List<Integer> a = new ArrayList<Integer>(n);
 
public class Main {
    public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);	
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int e = Math.max(a, b);
			e = Math.max(e, c);
			System.out.println(a+b+c+e*9);
	}
}

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

using namespace std;

bool is_prime(int n) {
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    } // n > 2 が保証された

    if(n%2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(unsigned i=3;i*i<=n;i+=2){
        if(n%i == 0) return false;
    }

    return true;
}

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

    if (x != 2 && x % 2 == 0) x+=1;
    for (int i = x; ; i+=2) {
        if (is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int cross(int ax, int ay, int bx, int by) {
	return ax*by - ay*bx;
}
int main() {
	int n, xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
	cin >> n;
	rep(i,n) {
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		int a=1, b=1;
		if(cross(xp2-xp1,yp2-yp1,xk-xp1,yk-yp1)>0 && cross(xp3-xp2,yp3-yp2,xk-xp2,yk-yp2)>0 && cross(xp1-xp3,yp1-yp3,xk-xp3,yk-yp3)>0 ||
		   cross(xp2-xp1,yp2-yp1,xk-xp1,yk-yp1)<0 && cross(xp3-xp2,yp3-yp2,xk-xp2,yk-yp2)<0 && cross(xp1-xp3,yp1-yp3,xk-xp3,yk-yp3)<0) a = -1;
		if(cross(xp2-xp1,yp2-yp1,xs-xp1,ys-yp1)>0 && cross(xp3-xp2,yp3-yp2,xs-xp2,ys-yp2)>0 && cross(xp1-xp3,yp1-yp3,xs-xp3,ys-yp3)>0 ||
		   cross(xp2-xp1,yp2-yp1,xs-xp1,ys-yp1)<0 && cross(xp3-xp2,yp3-yp2,xs-xp2,ys-yp2)<0 && cross(xp1-xp3,yp1-yp3,xs-xp3,ys-yp3)<0) b = -1;
		if(a*b<0) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
c = [list(map(int, input().split())) for _ in range(3)]
m = 0
for col in c:
  for v in col:
    m = max(m, v)
for a1 in range(m + 1):
  b1 = c[0][0] - a1
  b2 = c[0][1] - a1
  b3 = c[0][2] - a1
  a2 = c[1][0] - b1
  a3 = c[2][0] - b1
  if a2 + b2 != c[1][1]:
    continue
  elif a2 + b3 != c[1][2]:
    continue
  elif a3 + b2 != c[2][1]:
    continue
  elif a3 + b3 != c[2][2]:
    continue
  else:
    print('Yes')
    break
else:
  print('No')

Measured memory_bytes: 3064
n, k = map(int,input().split())

if k % 2 == 0:
    a1 = ((n-k) // k) + 1
    a2 = ((n-(k//2)) // k) + 1
    ans = a1**3 + a2**3
else:
    a1 = ((n-k) // k) + 1
    ans = a1**3

print(ans)

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


#define MAX 100000
#define FR 2000000000
int N;

typedef struct{
  char sign;
  int number;
}QUICK;

QUICK L[MAX/2+2];
QUICK R[MAX/2+2];

QUICK *A;
QUICK *B;


int partition(QUICK *,int,int,int);
void merge(QUICK *,int ,int ,int,int );
void mergeSort(QUICK *,int ,int ,int);
void quickSort(QUICK *,int ,int ,int);

#define MAX 100000
#define RF 2000000000
int N;

int main(){
  int i,j,x;
  scanf("%d",&N);
  A=malloc(sizeof(QUICK) * N);
  B=malloc(sizeof(QUICK) * N);
  char ARRAY[10];
  int stable = 1;

  for(i=0;i<N;i++){
    scanf("%s %d",ARRAY,&x);
    A[i].sign = ARRAY[0];
    B[i].sign = ARRAY[0];
    A[i].number = x;
    B[i].number = x;
  }

  mergeSort(A,N,0,N);
  quickSort(B,N,0,N-1);

  for (i=0;i<N;i++){
    if(A[i].sign != B[i].sign){
      stable = 0;
    }
  }

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

  free(A);
  free(B);
  return 0;
}

void merge(QUICK *A,int n,int left,int mid,int right){
  int i,j,k;
  int a,b;

  a=mid - left;
  b=right - mid;

  for(i=0;i<a;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<b;i++){
    R[i]=A[mid+i];
  }

  L[a].number = R[b].number = FR;

  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].number <= R[j].number){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(QUICK *A,int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(QUICK *A,int n,int p,int r){
  int i,j;
  QUICK t,x,a,b;
  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++){
    if(A[j].number <= x.number){
      i++;
      // A[i] ??¨ A[j] ?????????
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  //A[i+1] ??¨ A[r] ?????????
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;

  return i+1;
}

void quickSort(QUICK *A,int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:
                    ok = False
        if ok: ans = 'Yes'
print(ans)

Measured memory_bytes: 40560