akhauriyash/Code-Regression huggingface dataset:
m,n=map(int,input().split())
l=[]
ans=[]
for i in range(m):
  l.append(input())
  ans.append([-1]*n)
ans[0][0]=0
memo=[[-1,0],[1,0],[0,1],[0,-1]]
from collections import deque
d = deque([[0,0]])
while d:
  no=d.popleft()
  for me in memo:
    now=[0,0]
    for i in range(2):
      now[i]=no[i]+me[i]
    if min(now)<0 or now[0]>m-1 or now[1]>n-1 or l[now[0]][now[1]]=='#' or ans[now[0]][now[1]]>-1:
      pass
    else:
      d.append(now)
      ans[now[0]][now[1]]=ans[no[0]][no[1]]+1
if ans[-1][-1]<0:
  print(-1)
else:
  a=n*m-ans[-1][-1]-1
  for i in range(m):
    for j in range(n):
      if l[i][j]=='#':
        a-=1
  print(a)
  
  

Measured memory_bytes: 3316
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(2**n):
    bit=[(i>>j)&1 for j in range(n)]
    if sum(bit)==k and bit[0]:
        cost=0
        kijun=a[0]
        for j in range(1,n):
            if not bit[j]:
                kijun=max(kijun,a[j])
            elif a[j]>=kijun+1:
                kijun=a[j]
            else:
                cost+=kijun+1-a[j]
                kijun+=1
        ans=min(ans,cost)
print(ans)

Measured memory_bytes: 43356
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int h,w,n;
  while(input(h,w,n)) {
    int k = max(h,w);
    cout << (n+k-1)/k << endl;
  }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (auto& x: p) {
        cin >> x;
    }
    sort(p.begin(), p.end());
    int sum = accumulate(p.begin(), p.begin() + K, 0);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

using namespace std;


int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int>a(n), b(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[a[i] - 1]++;
	}
	sort(b.begin(), b.end());
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] > 0) {
			count++;
		}
	}
	int ans = 0;
	if (count <= k) {
		cout << ans;
	}
	else {
		for (int i = 0; i < n; i++) {
			while (b[i]>0) {
				ans += b[i];
				b[i] = 0;
				count--;
				if (count <= k) {
					cout << ans;
					return 0;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,sum;
  cin>>n;
  int arr[n-1],arr2[n];
  for(i=0;i<n-1;i++)cin>>arr[i];
  arr2[0]=arr[0];
  if(arr[0]<arr[1])
    arr2[1]=arr[0];
  else
    arr2[1]=arr[1];
  for(i=1;i<n-2;i++)
  {
    if(arr[i]<arr[i+1])
      arr2[i+1]=arr[i];
    else
      arr2[i+1]=arr[i+1];
  }
  arr2[i+1]=max(arr2[i],arr[i]);
  sum=0;
  for(i=0;i<n;i++)sum+=arr2[i];
  cout<<sum<<endl;
}


Measured memory_bytes: 256
using System;


namespace ConsoleApplication37
{
    class Program
    {
        static void Main(string[] args)
        {
            String s = Console.ReadLine();
            String[] ss = s.Split(' ');
            int n = int.Parse(ss[0]);
            for (int i = 1; i <= n;i++ )
            {
                if(i % 3 == 0)
                {
                    Console.Write( " " + i );
                }
                else
                {
                    for (int x = i; x > 0; x /= 10 )
                    {
                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }
                    }
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
int a[105];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int cnt=0;
    for(int i=1;i<n;)
    {
        if(a[i]==a[i-1])
        {
            cnt++;
            i+=2;
        }
        else i++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
#####################################
n=int(input())
A=INPUT()
A.sort(reverse=True)
B=[0]*n
distinct=list(set(A))
distinct.sort(reverse=True)
#print(distinct)
ans=0
D={}
for ele in A:
    if ele in D:
        D[ele]+=1
    else:
        D[ele]=1
#print(D)
count=0
i=0
p=0
while(i<n):
    ele=distinct[p]
    count=D[ele]*2
    while(i<n and count>0):
        B[i]=ele
        count-=1
        i+=1
    p+=1


#print(B)
print(sum(B)-B[0])


Measured memory_bytes: 162696
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		scan.next();
		String s = scan.next();
		scan.next();
		System.out.println("A" + s.charAt(0) + "C");
	}
}


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

int main() {
  int64_t n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  cout << (int64_t)ceil((double)n/min(a,min(b,min(c,min(d,e)))))+4;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char END = '\n';

ll even(ll x) {
	ll count = 0;
	while (x % 2 == 0) {
		x /= 2;
		count++;
	}
	return count;
}


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

	ll N, Ans = 0;
	cin >> N;
	ll n;
	rep(i, N) {
		cin >> n;
		Ans += even(n);
	}
	cout << Ans << END;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, 1});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  int n,a,b=1;
  set<int> s;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
    const auto &res = prime_factorize(v[i]);
    for (auto p : res) {
        for (int i = 0; i < p.second; ++i) {
          if(!s.count(p.F)){
            s.insert(p.F);
          }else{
            b=0;
            break;
          }
        }
    }
    if(i==0){
      a=v[0];
    }else{
      a=gcd(v[i],a);
    }
  }
  if(b==1){co("pairwise coprime");return 0;}
  if(a!=1){co("not coprime");return 0;}
  co("setwise coprime");
  return 0;
}


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

using namespace std;

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

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

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

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

    int n, k;
    cin >> n >> k;
    vi v(n);
    int suma = 0;
    for(auto &z : v)
        cin >> z, suma += z;

    vi del;

    for(int i = 1; i * i <= suma; ++i)
    {
        if(suma % i == 0)
        {
            del.pb(i);
            if(suma / i != i)
                del.pb(suma / i);
        }
    }

    int ans = 1;

    for(auto pok : del)
    {
        vi temp(n);
        int mini = 1e9 + 10;
        int treba = 0;
        for(int i = 0; i < n; ++i)
        {
            temp[i] = v[i] % pok;
            treba += pok - temp[i];
        }

        sort(all(temp));

        int treba2 = 0;

        if(treba == treba2)
        {
            mini = treba;
        }
        
        for(int i = 0; i < n; ++i)
        {
            treba -= (pok - temp[i]);
            treba2 += temp[i];
            if(treba == treba2)
            {
                ckmin(mini, treba);
            }
        }

        if(mini <= k)
        {
            ckmax(ans, pok);
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3656
A, B = list(map(int, input().split()))


def factorization(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


a = set(factorization(A))
b = set(factorization(B))


ans = 1
for aa in a:
    if aa in b:
        ans += 1

print(ans)


Measured memory_bytes: 38512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(reader.readLine());
            }

            System.out.println(func2(N, A));
        }
    }

    public static int func2(int N, int[] A) {
        ArrayList<Integer> list = new ArrayList<Integer>();

        for (int i = N - 1; i >= 0; i--) {
            if (list.isEmpty() || list.get(list.size() - 1) <= A[i]) {
                list.add(A[i]);
                continue;
            }

            int higherIndex = higher(list, A[i], 0, list.size());
            list.remove(higherIndex);
            list.add(higherIndex, A[i]);
        }

        return list.size();
    }

    public static int higher(ArrayList<Integer> list, int value, int start, int end) {
        if (end - start == 1) {
            return start;
        }

        int center = (start + end) / 2;
        if (list.get(center - 1) <= value) {
            return higher(list, value, center, end);
        } else {
            return higher(list, value, start, center);
        }
    }

}


Measured memory_bytes: 35320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
using pii = pair<int,int>;
int main(){
  string s,t;
  cin>>s>>t; 
  int count = 0;

  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i])count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3836
/*
さいころ

mapを使っているところは普通のサイコロとかなら配列で大丈夫
まぁ、せいぜいO(log24)なのでOKか

参考:
http://www.prefield.com/algorithm/misc/dice.html
*/
#include <bits/stdc++.h>
using namespace std;

//up(上),down(下),front(前),back(後ろ),right(右),left(左)
enum FACE{UP,DOWN,FRONT,BACK,RIGHT,LEFT};
template<typename T>
struct Dice{
    T var[6];
    map<pair<T,T>,int> M;
    vector<Dice> V;
    Dice(){}
    T& operator[](FACE f){return var[f];}
    Dice operator[](int idx){return V[idx];};
    Dice find(T up,T front){return V[ M[{up,front}] ];}
    int id(){return M[{var[FRONT],var[UP]}];}

    void rollR(){roll(UP,LEFT,DOWN,RIGHT);}
    void rollL(){roll(UP,RIGHT,DOWN,LEFT);}
    void rollU(){roll(UP,FRONT,DOWN,BACK);}
    void rollD(){roll(UP,BACK,DOWN,FRONT);}
    void rollT(){roll(FRONT,RIGHT,BACK,LEFT);}
    void rollH(){roll(FRONT,LEFT,BACK,RIGHT);}
    void roll(FACE a,FACE b,FACE c,FACE d){
        int tmp=var[a];
        var[a]=var[b];
        var[b]=var[c];
        var[c]=var[d];
        var[d]=tmp;
    }

    void allDice(){
        int cnt=0;
        V.resize(24);
        Dice d=*this;
        for(int k=0;k<6;(k&1?d.rollR():d.rollD()),k++){
            for(int i=0;i<4;d.rollT(),i++,cnt++){
                V[cnt]=d;
                M[{d[UP],d[FRONT]}]=cnt;
            }
        }
    }
    bool operator==(const Dice &d)const noexcept{
        for(int i=0;i<6;i++){
            if(var[i]!=d.var[i]) return false;
        }
        return true;
    }

};

signed main(){
    Dice<int> d,b;
    cin>>d[UP]>>d[FRONT]>>d[RIGHT]>>d[LEFT]>>d[BACK]>>d[DOWN];
    cin>>b[UP]>>b[FRONT]>>b[RIGHT]>>b[LEFT]>>b[BACK]>>b[DOWN];
    b.allDice();
    for(int i=0;i<24;i++){
        if(d==b.V[i]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

int main() {
  long n;
  cin >> n;
  
  long long ans = 0;
  for (long i = 1; i <= n; i++) {
    if (i%3 && i%5) ans += i;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <bitset>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;

ll mod_pow(ll k, ll p)
{
    if (k == 0)
    {
        return 1 % p;
    }
    if (k == 1)
    {
        return 2 % p;
    }

    if (k % 2 == 0)
    {
        ll tmp = mod_pow(k / 2, p);
        return tmp * tmp % p;
    }
    else
    {
        ll tmp = mod_pow((k - 1) / 2, p);
        tmp *= tmp;
        tmp %= p;
        tmp *= 2;
        tmp %= p;
        return tmp;
    }
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2) % MOD;
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, (k - 1) / 2);
        return tmp * tmp * n;
    }
}
map<ll, ll> sosuu(ll n)
{
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            n /= i;
            mp[i] += 1;
        }
    }
    if (n != 1)
    {
        mp[n] += 1;
    }
    return mp;
}

class Tree
{
private:
    vector<vector<ll>> edge;
    vector<ll> counter;

public:
    Tree() : counter(1000000, 0), edge(1000000){};
    ~Tree(){};

    void add(ll n, ll k)
    {
        this->edge[n].push_back(k);
        this->edge[k].push_back(n);
    }

    void query(ll p, ll x)
    {
        this->counter[p] += x;
    }

    void create()
    {
        vector<vector<ll>> children(1000000);
        vector<bool> visited(1000000, false);

        // 木の生成
        {
            queue<ll> Q;
            Q.push(1);
            visited[1] = true;

            while (!Q.empty())
            {
                ll top = Q.front();
                Q.pop();
                vector<ll> dist = this->edge[top];

                for (ll j = 0; j < dist.size(); j++)
                {
                    ll c = dist[j];
                    if (visited[c])
                    {
                        continue;
                    }
                    children[top].push_back(c);
                    Q.push(c);
                    visited[c] = true;
                }
            }
        }
        // 探索開始
        {
            queue<ll> Q;
            Q.push(1);
            while (!Q.empty())
            {
                ll top = Q.front();
                Q.pop();

                vector<ll> child = children[top];
                for (auto &&e : child)
                {
                    this->counter[e] += this->counter[top];
                    Q.push(e);
                }
            }
        }
    }
    ll count(ll n)
    {
        return this->counter[n];
    }
};

int main()
{
    ll X;
    cin >> X;
    ll rate;
    for (ll i = 1; i <= 8; i++)
    {
        if ((2000 - 200 * i) <= X && X < (2000 - 200 * (i - 1)))
        {
            rate = i;
        }
    }
    cout << rate << endl;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){

    int a,b,k, n, max;
    VI arr;

    cin >> a >> b >> k;
    if(a > b){
        n = b;
        max = a;
    } else {
        n = a;
        max = b;
    }

    for(int i=1; i <= n; i++) {
        if(n%i == 0 && max%i == 0){
            arr.push_back(i);
        }
    }

    cout << arr[arr.size() - k];

    return 0;
}


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

using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vp;
#define y1 def1
#define all(q) q.begin(), q.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define X first
#define Y second
#define endl '\n'
const int maxn = 1e6 + 10;
int a[maxn];
char get(string s){
    int n = s.size();
    if(n == 1) return s[0];
    int pos = n/2;
    if(s[pos] == s[pos - 1]) return s[pos];
    if(s[pos] == s[pos + 1]) return s[pos];
    int mn[2];
    memset(mn, 63, sizeof mn);
    for(int i=pos-2; i>=0; i--)
        if(s[i] == s[i + 1]){
            mn[s[i] - '0'] = pos - i;
            break;
        }
    for(int i=pos+2; i<n; i++)
        if(s[i] == s[i - 1]){
            mn[s[i] - '0'] = i - pos;
            break;
        }
    if(mn[0] < mn[1]) return '0';
    if(mn[1] < mn[0]) return '1';
    return s[0];
}
main(){
    IOS;
    int n;
    cin >> n;
    n = n * 2 - 1;
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i]--;
    }
    int lo = -1, hi = n;
    while(hi - lo > 1){
        int mid = (hi + lo) / 2;
        string s;
        for(int i=0; i<n; i++)
            if(a[i] >= mid) s += '1';
            else s += '0';
        if(get(s) == '0')
            hi = mid;
        else
            lo = mid;
    }
    cout << lo + 1 << endl;

}


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

using namespace std;

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

	int N;
	cin >> N;
	
	long long sol = 0, ant = 0, now;

	for(int i=0;i<N;++i) {
		cin >> now;
                if( !now ){ant=0; continue;}
                now += ant; 
		sol += now/2;
		now %= 2;
		ant = now;
	}

	cout << sol << '\n';

	return 0;
} // br1

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

//Lupin The 4th
public class Main{

	int n, INF = 1<<29;
	int[] dist, num;
	double[][] dp;
	int[][][] pre;
	
	double get(int state, int v, int w){
		if(state==(1<<n)-1){
			pre[state][v] = new int[]{-1, -1};
			return 0;
		}
		if(dp[state][v]!=INF)return dp[state][v];
		double min = INF;
		for(int i=0;i<n;i++){
			if(i==v||((state>>i)&1)>0)continue;
			double t = Math.abs(dist[v]-dist[i])/(2000.0/(70+w)) + get(state+(1<<i), i, w+20*num[i]);
			if(t<min){
				min = t;
				pre[state][v] = new int[]{state+(1<<i), i};
			}
		}
		return dp[state][v] = min;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] ref = new int[n];
		dist = new int[n];
		num = new int[n];
		for(int i=0;i<n;i++){
			ref[i] = sc.nextInt();
			dist[i] = sc.nextInt();
			num[i] = sc.nextInt();
		}
		dp = new double[1<<n][n];
		for(double[]a:dp)Arrays.fill(a, INF);
		pre = new int[1<<n][n][2];
		double min = INF;
		int id = -1;
		for(int i=0;i<n;i++){
			double t = get(1<<i, i, 20*num[i]);
			if(t<min){
				min = t; id = i;
			}
		}
		int[] s = new int[]{1<<id, id};
		System.out.print(ref[id]);
		for(;;){
			s = pre[s[0]][s[1]];
			if(s[0]==-1)break;
			System.out.print(" "+ref[s[1]]);
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int p[MN+5],n,k,q[MN+5],pi[MN+5],qi[MN+5],s[MN+5],a[MN+5],si[MN+5],tmp[MN+5];
void Mul(int*A,int*B)
{
    for(int i=1;i<=n;++i) tmp[i]=A[B[i]];
    for(int i=1;i<=n;++i) A[i]=tmp[i];
}
int main()
{
    n=read();k=read();
    for(int i=1;i<=n;++i) p[i]=read(),pi[p[i]]=i,s[i]=i;
    for(int i=1;i<=n;++i) q[i]=read(),qi[q[i]]=i,a[i]=i;
    if(k>6)
    {
        Mul(s,q);Mul(s,pi);Mul(s,qi);Mul(s,p);
        for(int t=(k-1)/6;t;t>>=1,Mul(s,s)) if(t&1) Mul(a,s);
    }
    int r=(k-1)%6+1;
    if(r>3) Mul(a,q); if(r>4) Mul(a,pi);
    for(int i=1;i<=n;++i) si[a[i]]=i;
    if(r==1) Mul(a,p); if(r==2) Mul(a,q); if(r==3) Mul(a,q),Mul(a,pi);
    if(r==4) Mul(a,pi);if(r==5) Mul(a,qi);if(r==6) Mul(a,qi),Mul(a,p);
    Mul(a,si);
    for(int i=1;i<=n;++i) printf("%d ",a[i]);
    return 0;
}

Measured memory_bytes: 3968
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (!map.containsKey(num)) {
				map.put(num, 1);
				list.add(num);
			} else {
				map.put(num, map.get(num) + 1);
			}
		}
		List<Integer> list2 = new ArrayList<>();
		for(int num: list) {
			list2.add(map.get(num));
		}
		Collections.sort(list2);
		int cnt = list2.size();
	    int ans = 0;
	    for(int i = 0; i < list2.size(); i++) {
	    	if (cnt <= k) break;
	    	ans += list2.get(i);
	    	cnt--;
	    }
	    out.println(ans);

		out.close();
	}
	

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



Measured memory_bytes: 50392
import java.util.*;

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 a[]=new int[n+1];
    	    for(int i=0;i<=n;i++){
                a[i]=sc.nextInt();
            }
            if(n==4){
                if(a[3]-a[2]==a[2]-a[1]&&a[2]-a[1]==a[1]-a[0]){
                    System.out.println(a[4]);
                }else if(a[4]-a[2]==a[2]-a[1]&&a[2]-a[1]==a[1]-a[0]){
                    System.out.println(a[3]);
                }else if(a[4]-a[3]==a[3]-a[1]&&a[3]-a[1]==a[1]-a[0]){
                    System.out.println(a[2]);
                }else if(a[4]-a[3]==a[3]-a[2]&&a[3]-a[2]==a[2]-a[0]){
                    System.out.println(a[1]);
                }else{
                    System.out.println(a[0]);
                }
            }else if(n>4){
                int sub=0;
                int b[]=new int[5];
                for(int i=0;i<5;i++){
                    b[i]=a[i+1]-a[i];
                }
                Arrays.sort(b);
                sub=b[2];
                for(int i=0;i<n;i++){
                    if(a[i+1]-a[i]!=sub){
                        if(i==n-1){
                            System.out.println(a[i+1]);
                            break;
                        }else if(a[i+2]-a[i+1]!=sub){
                            System.out.println(a[i+1]);
                            break;
                        }else{
                            System.out.println(a[i]);
                            break;
                        }
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 43020
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];

        int Answer = 0;

        for(int i=0; i<N; i++){
            A[i] = nextInt();
        }
        for(int i=0; i<N; i++){
            B[i] = nextInt();
        }
        for(int i=0; i<N-1; i++){
            C[i] = nextInt();
        }

        for (int i=1; i<N; i++) {
        	if (A[i] - 1 == A[i - 1]) {
        		int test = A[i - 1] - 1;
        		Answer += C[test];
        	}
        	Answer += B[i];
        }

        Answer += B[0];

        println(Answer);
    }

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

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

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}

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

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

    vector<int64_t> L(87);
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        L[i] = L[i - 1] + L[i - 2];
        // printf("%d ", L[i]);
    }
    cout << L[N] << endl;
    return (0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

int count(int x)
{
   if (x == 0)
      return 0;
   return (x & 1) + count(x >> 1);
}

int main()
{
   int n, a[15] = {}, x[15][15] = {}, y[15][15] = {}, ans = 0;
   cin >> n;
   FOR(i, 0, n)
   {
      cin >> a[i];
      FOR(j, 0, a[i])
      {
         cin >> x[i][j] >> y[i][j];
         x[i][j]--;
      }
   }
   FOR(i, 0, (1 << n))
   {
      bool flag = true;
      FOR(j, 0, n)
      {
         if (!((i >> j) & 1))
            continue;
         FOR(k, 0, a[j])
         {
            if (((i >> x[j][k]) & 1) != y[j][k])
            {
               flag = false;
               break;
            }
         }
      }
      if (flag)
         ans = max(ans, count(i));
   }
   cout << ans << endl;

   return 0;
}


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

int main() {
	while (1) {
		long long q;
		double x;
		cin >> q;
		if (q == -1) break;
		x = (double)q / 2;
		while (fabs(x*x*x - q) >= 1e-5*q) {
			x = x - (x*x*x - q) / (3 * x*x);
		}
		printf("%.6f\n", x);
	}
}


Measured memory_bytes: 3112
#include<stdio.h>

int main(){
  int N,i,cnt=0;
  char S[50];

  scanf("%d",&N);
  scanf("%s",S);

  for(i=0;i<50;i++){
    if(S[i]=='A'){
      if(S[i+1]=='B'){
	if(S[i+2]=='C'){
	  cnt++;
	}
      }
    }
  }
  printf("%d",cnt);
    }

Measured memory_bytes: 128
#include <stdio.h>

void main() {

    int S, W;
    char buf[100 + 1];

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d\n", &S, &W);

    if (S <= W) {
        printf("unsafe");
    }
    else {
        printf("safe");
    }
    return;
}

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

def ht(n):
    str_n = str(n)
    head = int(str_n[0])
    tail = int(str_n[-1])
    return (head, tail)

htmap = [[0] * 10 for i in range(10)]

for i in range(1, N+1):
    h,t = ht(i)
    htmap[h][t] += 1

ans = 0
for i in range(1, N+1):
    h,t = ht(i)
    ans += htmap[t][h]

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=1e5+10;

int main() {
  ll n;
  cin >> n;
  vec a(N);
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ll v;
    cin >> v;
    a[v]++;
    ans+=v;
  }
  ll q;
  cin >> q;
  while(q--) {
    ll b,c;
    cin >> b >> c;
    ans+=(c-b)*a[b];
    a[c]+=a[b];
    a[b]=0;
    cout << ans << endl;
  }
}

Measured memory_bytes: 4048
import java.util.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char s = b.charAt(0);
        
        System.out.println("A" + s + "C");
    }
}

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

int countOrder(vector<int> &arr, int num);
int absSub(int a, int b);
int factorial(int num);

int main() {
	int num = 3;
	int countP = 0;
	int countQ = 0;

	cin >> num;

	vector<int> arrayP(num);
	vector<int> arrayQ(num);

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

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


	countP = countOrder(arrayP, num);
	countQ = countOrder(arrayQ, num);

	cout << absSub(countP, countQ) << endl;

	return 0;
}

int countOrder(vector<int> &arr, int num) {
	int order = factorial(num);

	for(int i = 0; i < (num - 1); i++) {
		int tmp = 0;
		for (int j = 0; j < i; j++) {
			if (arr[i] < arr[i - j - 1]) {
				tmp++;
			}
		}
		order -= (num - arr[i] - tmp) * factorial(num - 1 - i);
	}

	return order;
}

int absSub(int a, int b) {
	if (a < b) {
		return b - a;
	} else {
		return a - b;
	}
}

int factorial(int num) {
	int a = 1;
	for(int i = 1; i <= num; i++) {
		a *= i;
	}
	return a;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();
        if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
        
    }
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

LL digit(LL x, LL d) {
    if(x == 0)
        return 1;
    LL res = 0;
    for(;0 < x;) {
        x /= d;
        res++;
    }
    return res;
}

LL s(LL x) {
    LL res = 0;
    for(;x != 0;x /= 10) {
        res += x%10;
    }
    return res;
}

int main() {
    LL K;
    cin >> K;

    FOR(i, 1, min<LL>(10, K + 1)) {
        cout << i << endl;
    }
    K -= min<LL>(9, K);

    LL N = 10;
    for(LL i = 0;i < K;) {
        double t = 1e18;
        LL d = digit(N, 10);
        LL res = N;
        REP(j, d) {
            LL x = N;
            LL p = pow(10, j + 1);
            x /= p;
            x += 1;
            x *= p;
            x -= 1;
            if((double)x/s(x) < t) {
                res = x;
                t = (double)x/s(x);
            }
        }
        if(N <= res) {
            cout << res << endl;
            N = res + 1;
            i++;
        }
    }
    return 0;
}



Measured memory_bytes: 256
/*****************
 *   I<3   C++   *
 *  IWANT ANYAC  *
 * ILOVEPROGRAM! *
 *IT'SINTERESTING*
 * ILOVEPROGRAM! *
 *  INCONTESTS   *
 *   GETSCORE    *
 *    ACCODE     *
 *     LETS      *
 *      GO       *
 *****************/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) ((a>>b)&1)
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

int mxzhuan[100007],znmx=0,cnt=0;
int n,m,a[100007];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	mxzhuan[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)mxzhuan[i]=max(mxzhuan[i+1],a[i+1]);
	for(int i=0;i<n;i++)if(mxzhuan[i]-a[i]>znmx)znmx=mxzhuan[i]-a[i];
	for(int i=0;i<n;i++)if(mxzhuan[i]-a[i]==znmx)cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long h[]=new long[n];
		long dif=1000000000L;
		
		
		for(int i=0;i<n;++i) {
			h[i]=sc.nextLong();
		}
		Arrays.sort(h);
		for(int i=0;i+k<=n;++i) {
			if(dif > h[i+k-1]-h[i]) {
				dif=h[i+k-1]-h[i];
			}
		}
		

		System.out.println(dif);
	}
}


Measured memory_bytes: 49408
n = int(input())
a = tuple(map(int, input().split()))

st = set()
for tar in a[:2]:
    i = 1
    while i * i <= tar:
        if tar % i == 0:
            st.add(i)
            st.add(tar // i)
        i += 1

for d in sorted(st, reverse=True):
    cnt = 0
    for aa in a:
        if aa % d != 0:
            cnt += 1
        if cnt > 1:
            break
    else:
        print(d)
        exit()


Measured memory_bytes: 14180
N=int(input())
A=input()
B=input()
C=input()

ans=0
for i in range(N):
	if A[i]==B[i] and B[i]==C[i]: continue
	elif A[i]==B[i] or B[i]==C[i] or C[i]==A[i]: ans+=1
	else: ans+=2

print(ans)

Measured memory_bytes: 3316
import numpy as np

def dot_to_zero(letter):
    if letter == ".":
        return "0"
    else:
        return "#"

h, w = map(int, input().split(' '))

a = []
for i in range(h):
    s = np.array(list(map(dot_to_zero, input())))
    a.append(s)
a = np.vstack(a)

def add(array):
    for hei in [0,1,2]:
        for wid in [0,1,2]:
            if array[hei][wid] == "#":
                array[hei][wid] = "#"
            else:
                array[hei][wid] = str(int(array[hei][wid]) + 1)
    return array

a = np.pad(a, (1,1), 'edge')


for index_h in range(1, h+1):
    for index_w in range(1, w+1):
        if a[index_h][index_w] == "#":
            a[index_h-1:index_h+2, index_w-1:index_w+2] = add(a[index_h-1:index_h+2, index_w-1:index_w+2])
            
a = a[1:-1, 1:-1]

for array in a:
    print("".join( array.tolist() )) 

Measured memory_bytes: 12784
from math import sqrt
n = int(input())
xy = []
for i in range(n):
  xy.append(list(map(int, input().split())))
ans = 0
for i in range(n):
  for j in range(i+1, n):
    ans += sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
print(ans*2/n)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    string arr[]={"MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"};
    string a;
    int b;
    cin>>a;
    int x=0,y=0;
    for (int i=0;i<7;i++)
    {
        if (arr[i]==a)
        {
        x=i;
        }
        if (arr[i]=="SUN")
        {
        y=i;
        }
    b=abs(x-y);
    }
    if (b==0)
    cout<<7;
    else
    cout<<b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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; }
const int INF = INT_MAX;
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vs S(N);
    rep(i, N) cin >> S[i];
    map<string, int> dict;
    int n_max = 0;
    rep(i, N) {
        if (dict.count(S[i])) dict[S[i]]++;
        else dict[S[i]] = 1;
    }

    for (auto p : dict) {
        chmax(n_max, p.second);
    }
    for (auto p : dict) {
        if (p.second == n_max) cout << p.first << endl;
    }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int answerArr[] = new int[M];
		int answer = 0;
		Arrays.fill(answerArr, 0);


		for (int i = 0; i < N; i++) {
			int K = sc.nextInt();
			for (int j = 0; j < K; j++) {
				int Ki = sc.nextInt();
				answerArr[Ki - 1]++;
			}
		}

		for (int i = 0; i < M; i++) {
			if (answerArr[i] == N) {
				answer++;
			}
		}

		System.out.println(answer);
	}
}


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

public class Main {

	private static List<List<Integer>> ptnList = new ArrayList<List<Integer>>();

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		List<Point> pointList = new ArrayList<Point>();

		for(int i = 0; i < n; i++) {
			Point p = new Point();
			p.x = sc.nextInt();
			p.y = sc.nextInt();
			pointList.add(p);
		}

		List<Integer> elm = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			elm.add(i);
		}
		List<Integer> empty = new ArrayList<Integer>();
		permutation(elm, empty);

		double totalLength = 0;
		for(int i = 0; i < ptnList.size(); i++) {
			List<Integer> ptn = ptnList.get(i);
			for(int j = 0; j < ptn.size() - 1; j++) {
				Point p1 = pointList.get(ptn.get(j));
				Point p2 = pointList.get(ptn.get(j+1));
				totalLength += Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y,  2));
			}
		}

		System.out.println(totalLength / ptnList.size());

		sc.close();
	}

	private static void permutation(List<Integer> elm, List<Integer> prePtn) {

		if(elm.size() < 1) {
			ptnList.add(prePtn);
			return;
		}

		for(int i = 0; i < elm.size(); i++) {
			List<Integer> ptn = new ArrayList<Integer>(prePtn);
			ptn.add(elm.get(i));

			List<Integer> nextElm = new ArrayList<Integer>(elm);
			nextElm.remove(i);
			permutation(nextElm, ptn);
		}

	}

	private static class Point{
		public double x;
		public double y;
	}

}


Measured memory_bytes: 45852