akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
string s, t;
int memo[N][N];
int LCS(int i, int j)
{
    if(i == s.size() || j == t.size())
        return 0;
    if(memo[i][j] != -1)
        return memo[i][j];
    if(s[i] == t[j])
        return memo[i][j] = LCS(i + 1, j + 1) + 1;
    else
        return memo[i][j] = max(LCS(i + 1, j), LCS(i, j + 1));
}

void build(int i, int j)
{
    if(i == s.size() || j == t.size())
        exit(0);
    int x = memo[i][j];
    if(s[i] == t[j])
    {
        cout << s[i];
        build(i + 1, j + 1);
    }
    else
    {
        if(x == LCS(i + 1, j))
            build(i + 1, j);
        else
            build(i, j + 1);
    }
}
int main()
{
    memset(memo, -1, sizeof(memo));
    cin >> s >> t;
    LCS(0, 0);
    build(0, 0);
    return 0;
}

Measured memory_bytes: 35968
using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)

const int N = 1e5 + 1 ;
int a[N] ;

int main()
{
#define TASK "NAME"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cout << fixed ;
    cout << setprecision(5);
    int n ;
    cin >> n ;
    for (int i = 1 ; i <= n ; ++i){
        cin >> a[i];
    }
    long double ans = 0.0 ;
    for (int i = 1; i <= n; ++i){
        ans += (long double)(1.0 / a[i]) ;
    }
    cout << 1.0 / ans << endl;


    return 0;
}



Measured memory_bytes: 256
// AtCoder template
// 最近sabaがかまってくれないからキレて暴れてる
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n, m; cin >> n >> m;
    int a,b;
    vector<vector<int>> graph(n); 
    rep(i,m){
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queue<pair<int,int>> que;
    vector<int> ans(n,-1);
    que.emplace(0,0);
    while(!que.empty()){
        int now = que.front().first;
        int from = que.front().second;
        que.pop();

        if(ans[now] != -1) continue;
        ans[now] = from;
        
        rep(i,graph[now].size()){
            int next = graph[now][i];
            if(ans[next] != -1) continue;
            que.emplace(next,now);
        }
    }

    cout << "Yes" << endl;
    rep(i,n-1){
        cout << ans[i+1]+1 << "\n";
    }
}

Measured memory_bytes: 10904
t,s=open(0)
n,k=map(int,t.split())
i=0
for j in range(n):
 k-='1'>s[j]and'0'!=s[j-1]
 if k<0:k+='1'>s[i]and'0'<s[i+1];i+=1
print(n-i)

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		HashMap<String, Integer> strMap = new HashMap<>();
		HashSet<String> strSet = new HashSet<>();
		long valiation = 0;
		for(int i = 0; i < n; i++) {
			String[] strArr = sc.nextLine().split("");
			Arrays.sort(strArr);
			String concatStr = "";
			for(int j = 0; j < 10; j++) {
				concatStr = concatStr.concat(strArr[j]);
			}
			if(strMap.containsKey(concatStr)) {
				valiation += strMap.get(concatStr);
				strMap.put(concatStr, new Integer(strMap.get(concatStr)) + 1);
			}else {
				strMap.put(concatStr, new Integer(1));
				strSet.add(concatStr);
			}
		}
		sc.close();		
		
		System.out.println(valiation);
	}
	
	public static long factorial(int n) {
		long result = 1;
		for(int i = 1 ; i <= n; i++) {
			result *= (long)i;
		}
		return result;
	}

}


Measured memory_bytes: 186212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{int H, W; cin >> H >> W;
 vector<vector<char>> B ( H, vector<char>(W));//H*W配列
 for(int i = 0; i < H; i++){
   for(int j = 0 ; j < W; j++){
     cin >> B.at(i).at(j);}}//
 int dx[] = {1,0,-1,0};
 int dy[] = {0,1,0,-1};
 
 bool flag0 = true;
 
 for(int i = 0; i < H; i++){
   for(int j = 0; j < W; j++){
     if(B.at(i).at(j) == '#'){
      bool flag = false;
     for(int k = 0; k < 4;k++){
       int a = i + dx[k]; int b = j + dy[k];
       if(0 <= a && a <= H-1 && 0 <= b && b <= W-1 && B.at(a).at(b) == '#'){
         flag = true;}}
     if(!flag){flag0 = false;
               break;}}
   else{continue;}}}
 
 if(flag0){cout << "Yes" <<endl;}
 else{cout << "No" <<endl;}
 return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String argv[]) {
    int n, k, sum = 0;
    Scanner sc = new Scanner(System.in);
    n = Integer.parseInt(sc.next());
    k = Integer.parseInt(sc.next());
    for (int i = 0;i < n;i++) {
      if (Integer.parseInt(sc.next()) >= k)
        sum++;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 44944
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll inf = 1 << 30;
const ll mod = 1000000000 + 7;

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

	vector<pair<ll, ll>> p(n);
	for (int i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		
		p.at(i) = make_pair(a, b);
	}

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

	ll res = 0;
	for (int i = 0; m > 0; i++)
	{
		if (m >= p.at(i).second)
		{
			res += p.at(i).first * p.at(i).second;
			m -= p.at(i).second;
		}
		else
		{
			res += p.at(i).first * m;
			m -= p.at(i).second;
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, m, p, a, b;
double t[10], dmin[50][1<<8];
vector<vector<P> > g;

void dijkstra(){
    REP(i,m) fill(dmin[i],dmin[i]+(1<<8),double(LLINF)/10);
    dmin[a][(1<<n)-1] = 0.0;
    priority_queue<P3, vector<P3>, greater<P3> > que;
    que.push({0.0,{a,(1<<n)-1}});
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        int now = p.second.first, S = p.second.second;
        if(dmin[now][S]+EPS < p.first) continue;
        for(auto e : g[now]){
            int to = e.first;
            double z = double(e.second);
            for(int i=0; i<n; i++){
                if(((S>>i)&1)==1 && dmin[to][S^(1<<i)] > dmin[now][S] + z/t[i] + EPS){
                    dmin[to][S^(1<<i)] = dmin[now][S] + z/t[i];
                    que.push({dmin[to][S^(1<<i)],{to, S^(1<<i)}});
                }
            }
        }
    }
}

int main() {
    while(cin >> n >> m >> p >> a >> b, n){
        REP(i,n) cin >> t[i];
        a--; b--;
        g.clear();
        g.resize(m);
        REP(i,p){
            int x, y, z;
            cin >> x >> y >> z;
            x--; y--;
            g[x].push_back({y,z});
            g[y].push_back({x,z});
        }
        dijkstra();
        double ans = double(LLINF)/10;
        REP(i,(1<<n)){
            ans = min(ans, dmin[b][i]);
        }
        if(ans < double(LLINF)/10 - EPS){
            printf("%.5lf\n",ans);
        }
        else{
            cout << "Impossible" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4616
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath> 
#include <tuple>
#include <bitset>
#include<string>
//pair sort firstに揃う

#define int long long
#define double long double
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1 vector<int>
#define VectorS vector<string>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define incin2(n,m) int (n),(m); cin >> (n)>>(m);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
namespace Mathf
{
    const int INF = 1000000000000;
    const double PI = 3.14159274;
    const double Rad2Deg = 57.29578;
    const double log2(double a,double b);
    const double log2(double a,double b){
        return log(b)/log(a);
    }
} // namespace Mathf

using namespace std;

int MD(pair<int,int> a,pair<int,int> b){//ManhattanDisRance
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int MOD(int a,int b){
    return abs(a%b);
}
template <typename T1,typename T2> bool Comp (pair<T1,T2> a,pair<T1,T2> b){
    if(a.first!=b.first){
        return a.first<b.first;//first昇順
    }
    if(a.second!=b.second){
        return a.second > b.second;//second降順
    }else{
        return  true;
    }
}
double Dis(pair<int,int> a,pair<int,int> b){
    return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
int Step(int N){
    if(N==0){
        return 1;
    }else{
        return N*Step(N-1);
    }
}
int Pemu(int n,int r){
    int ans = n;
    for(int i=0;i<r;i++){
        ans*=(ans-i);
    }
    return ans;
}
int Comb(int n,int m){
    int ans=n;
    for(int i=0;i<m;m++){
        ans*=(ans-i);
    }
    return ans/Step(m);
}
int Digit(int x){
    string ss = to_string(x);
    int size = ss.size();
    int sum = 0;
    for(int i=0;i<size;i++){
        sum+=ctoi(ss[i]);
    }
    return sum;
}
signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int cost = 0;

    if (2*c < a+b){
        if(x>y){
            if(2*c<a){
                cout<<2*c*x<<endl;
            }else{
                cout<<2*c*y+a*(x-y)<<endl;
            }
        }else{
            if(2*c<b){
                cout<<2*c*y<<endl;
            }else{
                cout<<2*c*x+b*(y-x)<<endl;
            }
        }
    }else{
        cout<<a*x+b*y<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using LP = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;

int INF = 1e9+7;

vector<int> nums(4);

string ans;
string str;

bool check(string target){
  int result = 0;
  rep(i, 4){
    if(i==0){
      result += target[i] - '0';
    }else{
      if(target[2*i-1] == '+'){
        result += target[2*i]-'0';
      }else{
        result -= target[2*i]-'0';
      }
    }
  }
  if(result == 7){
    ans = target + "=7";
    return true;
  }else{
    return false;
  }
}


bool dfs(string current, int depth){
  if(depth == 4){
    if(check(current)){
      return true;
    }else{
      return false;
    }
  }

  if(depth == 0){
    return dfs(current + str[depth], depth+1);
  }

  return dfs(current + "+" + str[depth], depth+1) || dfs(current + "-" + str[depth], depth+1);
}


int main(){

  cin >> str;

  bool found = dfs("", 0);
  if(found){
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(scanner.nextInt());
        }

        Integer max = a.stream().max(Comparator.naturalOrder()).get();
        a.remove(max);
        Integer m = a.stream().min(Comparator.comparingInt(i -> Math.abs(i - max + i))).get();
        System.out.println(max + " " + m);
    }
}

Measured memory_bytes: 61284
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,ans=0;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i%2==0 && a[i]%2==1){
      ans ++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
#define MAX 3000

int main(){
    ll a,b; cin >> a >> b;
    if(a > 0) cout << "Positive" << endl;
    else if(b >= 0) cout << "Zero" << endl;
    else{
        if((b - a) % 2 == 0) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
}

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

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

int lcm(int a,int b)
{
	return (a*b)/gcd(a,b);
}*/

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

    int n;
    cin>>n;
    if(n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9)
    	{cout << "hon";return 0;}
    else if(n%10==0 or n%10==1 or n%10==6 or n%10==8)
    	{cout << "pon";return 0;}
    else {cout << "bon";return 0;}
}


Measured memory_bytes: 3648
# https://atcoder.jp/contests/abc150/tasks/abc150_c

def init_fact(n)
  @fact = Array.new(n + 1)
  @fact[0] = 1
  n.times { |i| @fact[i + 1] = @fact[i] * (i + 1) }
end

def order(ps)
  order2((1..ps.size).to_a, ps)
end

def order2(as, ps)
  return 0 if as.size == 0
  i = ps[0]
  ret = as.index(i) * @fact[as.size - 1]
  as.delete(i)
  ps.delete(i)
  ret + order2(as, ps)
end

N = gets.to_i
Ps = gets.split.map(&:to_i)
Qs = gets.split.map(&:to_i)

init_fact(N)
a = order(Ps)
b = order(Qs)
puts (a - b).abs


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1 << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll calc(vl ss, vector<bool> pos) {
    ll now = 0;
    ll ret = 0;
    REP(i, 0, s.size()) {
        if (i == 0) {
            now += ss.at(i);
            continue;
        }
        if (pos.at(i - 1) == true) {
            ret += now;
            now = ss.at(i);
        } else {
            now *= 10;
            now += ss.at(i);
        }
    }
    ret += now;
    return ret;
}

void search(vl ss, ll idx, vector<bool> pos) {
    if (idx >= s.size() - 1) {
        ans += calc(ss, pos);
        return;
    }
    pos[idx] = false;
    search(ss, idx + 1, pos);
    pos[idx] = true;
    search(ss, idx + 1, pos);
}

int main() {
    cin >> s;
    vl ss;
    REP(i, 0, s.size()) {
        ss.push_back(s.at(i) - '0');
    }

    vector<bool> pos(s.size() - 1, false);

    search(ss, 0, pos);
    MSG(ans)
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
#define ll long long
#define int long long
using namespace std;
const int inf = 0x3f3f3f3f;
int n;
struct node
{
    int x,y;
    friend bool operator < (const node &aa,const node &bb)
    {
        return aa.x>bb.x;
    }
}a[N];
int mx1[N],mx2[N],mn1[N],mn2[N];
signed main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&a[i].x,&a[i].y);
        if(a[i].x<a[i].y)swap(a[i].x,a[i].y);
    }
    sort(a+1,a+n+1);
    mn1[0]=mn2[0]=inf;
    for(int i=1;i<=n;i++)
    {
        mn1[i]=min(mn1[i-1],a[i].x);
        mn2[i]=min(mn2[i-1],a[i].y);
        mx1[i]=max(mx1[i-1],a[i].x);
        mx2[i]=max(mx2[i-1],a[i].y);
    }
    ll ans=1LL<<62;
    for(int i=1;i<n;i++)
    {
        int Rmax=a[1].x,Lmax=max(a[i+1].x,mx2[i]);
        int Rmin=mn2[n],Lmin=min(mn2[i],a[n].x);
        ans=min(ans,(Rmax-Rmin)*(Lmax-Lmin));
        Lmin=mn2[n],Rmin=min(a[i+1].y,a[n].x);
        ans=min(ans,(Rmax-Rmin)*(Lmax-Lmin));
    }
   // cout<<mx2[n]<<' '<<mn2[n]<<endl;
    ans=min(ans,(mx1[n]-mn1[n])*(mx2[n]-mn2[n]));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>

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

int main(){
  unsigned long k, sum=0;
  std::cin>>k;
  for(int i=1; i<=k; ++i){
    for(int j=1; j<=k; ++j){
      for(int l=1; l<=k; ++l){
        sum += gcd(gcd(i, j),l);
      }
    }
  }
  std::cout<<sum<<std::endl;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N, K;
  cin >> N >> K;

  int H = K;
  int W = K;
  vector<vector<int>> a(H, vector<int>(W,0)); // 黒の管理
  vector<vector<int>> b(H, vector<int>(W,0)); // 白の管理

  vector<int> x(N);
  vector<int> y(N);
  vector<int> c(N);

  for(int i = 0; i < N; i++){
    ll tmp1, tmp2;
    char ch;
    int col;
    cin >> tmp1 >> tmp2 >> ch;
    if(ch == 'B') col = 0;
    if(ch == 'W') col = 1;
    tmp1 %= (2*K);
    tmp2 %= (2*K);

    if(tmp1 >= K){
      col++;
    }
    if(tmp2 >= K){
      col++;
    }

    tmp1 %= K;
    tmp2 %= K;
    if(col%2 == 0){
      a[tmp1][tmp2] += 1;
    } else {
      b[tmp1][tmp2] += 1;
    }
  }

  // 二次元累積和
  vector<vector<int>> s(H+1, vector<int>(W+1, 0));
  vector<vector<int>> t(H+1, vector<int>(W+1, 0));
  for (int i = 0; i < H; ++i){
    for (int j = 0; j < W; ++j){
      s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + a[i][j];
      t[i+1][j+1] = t[i][j+1] + t[i+1][j] - t[i][j] + b[i][j];
    }
  }

  // クエリ [x1, x2) × [y1, y2) の長方形区域の和
  // cout << s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1] << endl;
  auto cnt_black = [&s](int x1, int y1, int x2, int y2){
    return s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1];
  };
  
  auto cnt_white = [&t](int x1, int y1, int x2, int y2){
    return t[x2][y2] - t[x1][y2] - t[x2][y1] + t[x1][y1];
  };

  int max_val = 0;
  for(int i = 0; i < K; i++){
    for(int j = 0; j < K; j++){
      int tmp_val = 0;
      // i,jが黒
      tmp_val += cnt_black(0,0,i+1,j+1);
      tmp_val += cnt_black(i+1,j+1,K,K);
      tmp_val += cnt_white(0,j+1,i+1,K);
      tmp_val += cnt_white(i+1,0,K,j+1);

      max_val = max(tmp_val, max_val);

      // i,jが白
      tmp_val = 0;
      tmp_val += cnt_white(0,0,i+1,j+1);
      tmp_val += cnt_white(i+1,j+1,K,K);
      tmp_val += cnt_black(0,j+1,i+1,K);
      tmp_val += cnt_black(i+1,0,K,j+1);

      max_val = max(tmp_val, max_val);

    }
  }

  cout << max_val << endl;


}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 998244353;

long long fact[202020], frev[202020];

long long modpow(long long a, long long p = MOD - 2) {
    if (p == 0) return 1;
    long long tmp = modpow(a, p / 2);
    tmp = tmp * tmp % MOD;
    if (p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}

long long C(int p, int q){
    if (q < 0 || p < q) return 0;
    return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}

int main(){
    fact[0] = frev[0] = 1;
    for(int i=1;i<=200000;i++){
        fact[i] = (fact[i - 1] * i) % MOD;
        frev[i] = modpow(fact[i]);
    }

    int N, M, K;
    cin >> N >> M >> K;

    ll ans = 0;
    for(int k=0;k<=K;k++){
        ans = (ans + (M * ((modpow(M - 1, N - k - 1) * C(N - 1, k)) % MOD)) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6772
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	ll n;
	cin>>n;
	vector<ll> v(n);
	for(ll i=0;i<n;i++)
		cin>>v[i];
	sort(rall(v));
	ll ans = v[0];
	ll j = 1;
	for(ll i=2;i<n;i+=2)
	{
		ans += v[j];
		if(i+1<n)
			ans += v[j];
		j+=1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4776
import java.util.Scanner;

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;
		boolean ans=false;

		for(int i=1;i<=3;i++){
			c=a*b*i;
			if(c%2==1){
				ans=true;
				break;
			}else{
				ans=false;
			}
		}

		if(ans==true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}


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

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x=root(x), y=root(y);
        if (x!=y) {
            if (data[y]<data[x]) {
                swap(x, y);
            }
            data[x]+=data[y], data[y]=x;
        }
        return x!=y;
    }

    bool find(int x, int y) {
        return root(x)==root(y);
    }

    int root(int x) {
        return data[x]<0 ? x : data[x]=root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};


int main(){
    int n,m,ans=1;
    scanf("%d %d",&n,&m);
    UnionFind uf(n);
    for (int i=0;i<m;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
        uf.unite(a-1,b-1);
    }
    //printf("%d\n",);
    for(int i=0;i<n;i++) {
        ans=max(ans,uf.size(i));
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4060
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

gcd_ = gcd(N, M)
lcm_ = N * M // gcd_
for i in range(gcd_):
    if S[i * N // gcd_] != T[i * M // gcd_]:
        print(-1)
        quit()
print(lcm_)


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

#define INF 2147483647
#define F first
#define S second
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main(){
	int n;
	long long k;
	long double ans;
	pair<int, int> p[10];
	
	ans = 0;
	cin>>n;
	rep(i,n)
		cin>>p[i].F>>p[i].S;
	k = 1;
	for(int i=1;i<=n;i++)
		k *= i;
	sort(p, p+n);

	do{
		for(int i=1;i<n;i++){
			ans += sqrt((p[i].F - p[i-1].F)*(p[i].F - p[i-1].F) + (p[i].S - p[i-1].S)*(p[i].S - p[i-1].S));
		}
	}while(next_permutation(p, p+n));
	cout<<fixed<<setprecision(20);
	cout<<ans / k;
	
}

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int r = 0, w = 0;
  rep(i, n) {
      if(s[i] == 'R') r++;
  }
  int ans = max(r, w);
  rep(i, n) {
      if(s[i] == 'R') r--;
      else w++;
      int now = max(r, w);
      ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>
int main(void){

	int N, d;
	char S[110], dummy;
	int max, point;

	scanf("%d",&N);
	scanf("%c",&dummy);
	
	for(int i=0; i<N; i++)
		scanf("%c", &S[i]);
	max=0;
	point=0;

	for(int i=0; i<N; i++){
		if(S[i]=='I'){
			point++;		
		}
		else{
			point--;
		}
		if(point > max){
			max = point;	
		}
	}


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

	return 0;
}

Measured memory_bytes: 128
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M = MI()
    XYZ = LLIN(N)

    a,b,c = [1<<i for i in range(3)]
    def f(x):
        x,y,z = x
        return abs(x) + abs(y) + abs(z)

    ans = 0
    for mask in range(1<<3):
        x_minus = bool(a&mask)
        y_minus = bool(b&mask)
        z_minus = bool(c&mask)

        XYZ.sort(reverse=True, key=lambda x: ((-1)**x_minus) * x[0] + ((-1)**y_minus) * x[1] + ((-1)**z_minus) * x[2] )
        x_sum, y_sum, z_sum = 0, 0, 0
        for x,y,z in XYZ[:M]:
            x_sum += x
            y_sum += y
            z_sum += z
        ans = max(ans, f((x_sum, y_sum, z_sum)))
    print(ans)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 65260
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)

int main(){
    int n;
    cin >> n;
    vector<double> r(n);
    for(int i=0; i<n; i++){
        cin >> r[i];
    }
    sort(r.begin(), r.end());
    
    double ans = 0;
    for(int cn=3; cn<=n; cn++){
        vector<bool> choose(n, false);
        for(int i=0; i<cn; i++){
            choose[n-i-1] = true;
        }
        do{
            vector<double> cr;
            for(int i=0; i<n; i++){
                if(choose[i]){
                    cr.push_back(r[i]);
                }
            }
            do{
                double maxratio = 1;
                for(int i=0; i<cn; i++){
                    maxratio = max(maxratio, abs((cr[0]*cr[1])/(cr[i]*cr[(i+1)%cn])));
                }
                double lb = acos(1/maxratio);
                double ub = PI -lb;
                lb += EPS; ub -= EPS;
                int repnum = 100;
                for(int rep=0; rep<repnum; rep++){
                    double mid = (lb +ub)/2;
                    double cosm = cos(mid);
                    double theta[8];
                    theta[0] = mid;
                    for(int i=1; i<cn; i++){
                        theta[i] = acos((cr[0]*cr[1]) /(cr[i]*cr[(i+1)%cn]) *cosm);
                    }
                    double sum = 0;
                    for(int i=0; i<cn; i++){
                        sum += theta[i];
                    }
                    
                    if(sum > 2*PI){
                        ub = mid;
                    }else{
                        lb = mid;
                    }
                    if(rep == repnum-1 && EQ(2*PI, sum)){
                        double area = 0;
                        for(int i=0; i<cn; i++){
                            area += cr[i] *cr[(i+1)%cn] *sin(theta[i]);
                        }
                        area /= 2.0;
                        ans = max(ans, area);
                    }
                }
          
            }while(next_permutation(cr.begin()+1, cr.end()));
        }while(next_permutation(choose.begin(), choose.end()));
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> a(H);
  
  for (int i=0; i<H; i++)
    cin >> a.at(i);
  
  for (int i=0; i<W+2; i++)
    cout << '#';
    
  cout << endl;
  
  for (int i=0; i<H; i++)
    cout << '#' << a.at(i) << '#' << endl;
  
  for (int i=0; i<W+2; i++)
    cout << '#';
    
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
ll gcd(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	while (a%b != 0) {
		ll G = a % b;
		a = b;
		b = G;
	}
	return b;
}
int main() {
	int N, X;
	cin >> N >> X;
	int a[100001];
	int A[100001];
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		A[i] = abs(X - a[i]);
	}
	int ans = A[0];
	for (int i = 0; i < N - 1; ++i) {
		ans = gcd(ans,A[i+1]);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

int main()
{
    string s;
    cin >> s;

    vector<int> ss(200, 0);

    rep(i, s.length()) ss[s[i]]++;

    int ans = 0;

    for (int i = 97; i < 97 + 26; i++)
    {
        if (ss[i] == 0)
        {
            ans = i;
            break;
        }
    }

    if (ans == 0)
    {
        cout << "None" << endl;
        return 0;
    }

    cout << (char)ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
queue<pair<int, int>> q;
int n, m, x, kk, k, y, start, stop, res;
int main() {
    DAU
    cin >> n >> m;
    vector<vector<int>> g(n + 1);
    while (m--) {
        cin >> x >> y;
        g[x].emplace_back(y);
    }
    cin >> start >> stop;
    q.emplace(start, 0);
    vector<vector<int>> dp(n + 1, vector<int>(3, -1));
    dp[start][0] = 0;
    while (!q.empty()) {
        tie(x, kk) = q.front();
        q.pop();
        k = (kk + 1) % 3;
        for (const int& y : g[x])
            if (dp[y][k] == -1 || dp[x][kk] + 1 < dp[y][k]) {
                dp[y][k] = dp[x][kk] + 1;
                q.emplace(y, k);
            }
    }
    res = dp[stop][0];
    if (res != -1)
        res /= 3;
    cout << res;
    PLEC
}


Measured memory_bytes: 14508
#include <iostream>
using namespace std;
int main()
{
	int n, num = 0;
	int ar[105];
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> ar[i];
	}
	for (int i = 0;i < n;i += 2)
	{
		if (ar[i] % 2 != 0) { num++; }
	}
	cout << num;
	return 0;
}


Measured memory_bytes: 3524
from itertools import accumulate
from collections import defaultdict
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(accumulate(A))
    d = defaultdict(int)
    for i in range(N):
        B[i] %= M
        d[B[i]] += 1

    cnt = 0
    for i, j in d.items():
        if i == 0:
            cnt += j
        if j >= 2:
            cnt += cmb(j , 2)

    print(cnt)
    
    
            
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 62744
#include <bits/stdc++.h>
using namespace std;
int main(){

  int n;
  bool ans=true;
  cin>>n;
  string S;
  cin >> S;
  if(n%2!=0) ans = false;
  else for(int i=0; i<n/2; i++){
    if(S[i]!=S[i+n/2]) ans = false;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = X
    if P == []:
        print(ans)
        return

    #
    # P = [i for i in range(1, 99)]
    # N = 100
    # X = 50

    mn = INF
    for i in range(X-110, X+110):
        # if i == X: continue
        if i not in P:
            if mn > abs(X - i):
                mn = abs(X - i)
                ans = i
            # print(i, abs(X - i), ans)
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9260
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  cin>>S;
  bool CAN=true;
  REP(i,S.size()-1){
    FOR(j,i+1,S.size()){
      if(S.at(i)==S.at(j)) CAN=false;
    }
  }
  if(CAN) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
N = int(input())
N_List = list(map(int,input().split()))
N_List_Sorted = sorted(N_List)
B = N_List_Sorted[N//2]
A = N_List_Sorted[N//2 - 1]

if A == B:
    for i in range(N):
        print(A)
else:
    for i in range(N):
        if N_List[i] <= A:
            print(B)
        else:
            print(A)





Measured memory_bytes: 30736
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

data = [0]*(n+5)
def dsum(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= n+2:
        data[i] += x
        i += i & -i
ans = 0
for e, i in v:
    ans += dsum(i+1)
    add(i+1, 1)
print ans


Measured memory_bytes: 36096
n,m,l = map(int,input().split())
a = [[0 for i2 in range(m)] for i1 in range(n)]
b = [[0 for i2 in range(l)] for i1 in range(m)]

for i in range(n):
    row = list(map(int,input().split()))
    for j in range(m):
        a[i][j] = row[j]

for i in range(m):
    row = list(map(int,input().split()))
    for j in range(l):
        b[i][j] = row[j]

c = [[0 for i2 in range(l)] for i1 in range(n)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            c[i][j] += a[i][k]*b[k][j]

for i in range(n):
    for j in range(l-1):
        print(c[i][j],end = ' ')
    print(c[i][-1])

Measured memory_bytes: 9200
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1000000007; /// 1e9+7
const int MAX = 100005;     /// 1e5+5
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    double n; cin>>n;
    n = sqrt(n);
    ll x = (ll)n;
    cout<<x*x<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int H;
    int W;
	
	int i;
	int n;
	while(1){
            scanf("%d",&H);
            scanf("%d",&W);
            if(H==0 && W==0) break;
	    for(i=1;i<=H;i++){
	       for(n=1;n<=W;n++){
	            printf("#");
	       } 
	       printf("\n");
	     }	
	printf("\n");
	}
	return 0;
}
	


Measured memory_bytes: 2044
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long

ll n,a,b;
int main(){	
	cin>>n>>a>>b;
	ll ans=0;
	if(a>b){
		ans=0;
	}

	else if(n==1){
		if(a==b)ans=1;
	}
	else if(n==2){
		ans=1;
	}

	else{
		if(a==b)ans=1;
		else ans=(n-2)*(b-a)+1;

	}

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


Measured memory_bytes: 256
//phoenix




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=0; i--)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a) sort(a,a+n);


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 ;




ll solveDp(ll i,ll a[],ll n,vector <ll> &dp) {
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    else if(i==(n-2))
        return dp[i]=abs(a[i]-a[i+1])+solveDp(i+1,a,n,dp);
    else
        return dp[i]=min((abs(a[i]-a[i+1])+solveDp(i+1,a,n,dp)),(abs(a[i]-a[i+2])+solveDp(i+2,a,n,dp)));
}




void cazz() {
    ll t,n,i,j,k,ans=0,f=0,b;
    cin>>n;
    ll a[n];
    fr(i,0,n) cin>>a[i];
    vector <ll> dp(n,-1);
    cout<<solveDp(0,a,n,dp)<<"\n";
}




int main() {
    spdio;
	cazz();
	return 0;
}





Measured memory_bytes: 6528
function Main(input) {
  "use strict";
	const lines = input.split("\n");
  let S = lines[0].split(" ").map(e => parseInt(e));
  
  const K = S.pop()
  const N = S.pop()

  const Ps = [];
  for (let i=0; i < 17; i++) {
    Ps.push(Math.pow(2, i+1))
  }

  const Pr = Ps.map( n => 1/n)
  const L = Ps.length;

  let ans = 0;
  for (let i=1; i<N+1; i++) {
    if (i >= K) {
      ans += 1/N;
      continue
    }
    let idx = 0;
    prb:
    for(let j =0; j < L ; j++) {
      if (i*Ps[j] >= K) {
        idx = j;
        break prb;
      }
    }
    ans += Pr[idx] / N


  }
  console.log(ans)

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

Measured memory_bytes: 23092
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++){
    b[a[i]-1]=i+1;
  }
  for(int i=0;i<n;i++){
    printf("%d ",b[i]);
  }
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

int root = 0;
vector< vector<int> > G;
vector<int> oya;
vector<int> color;
vector<bool> use;
vector<int> V;

int cal(int p, int OYA) {
	use[p] = true;
	oya[p] = OYA;
	int len = G[p].size();
	for (int i = 0; i < len; ++i) {
		int ter = G[p][i];
		if (use[ter] == true)continue;
		int res = cal(ter, p);
		V[p] += res;
	}
	return V[p] + 1;
}

vector<int> test(int p) {
	vector<int> ans;
	ans.push_back(p);
	int now = p;
	while (oya[now] != -1) {
		now = oya[now];
		ans.push_back(now);
	}
	return ans;
}
void solve() {
	int N;
	cin >> N;
	G = vector<vector<int>>(N);
	color = vector<int>(N, -1);
	color[0] = 0;//黒,先手
	color[N - 1] = 1;//白
	use = vector<bool>(N, false);
	V = vector<int>(N, 0);
	oya = vector<int>(N, -1);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	oya[root] = -1;
	cal(root, -1);
	vector<int> res = test(N - 1);
	reverse(res.begin(), res.end());

	int len = res.size();
	int A = V[root]+1;//全部
	int B = V[ res[(len+1)/2] ]+1;
	A -= B;
	if (A > B) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 15356
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n,a[105],flag[10];
    while(~scanf("%d",&n))
    {
        int num=0,num2=0;
        memset(flag,0,sizeof(flag));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            a[i]/=400;
        }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<8; j++)
            {
                if(a[i]==j&&!flag[j])
                {
                    flag[j]=1;
                    num++;
                }
                else if(a[i]>=8)
                {
                    num2++;
                    break;
                }
            }
        }
        if(num==0)
        {
            printf("1 %d\n",num2);
            continue;
        }
        int ans=num2+num;
        printf("%d %d\n",num,ans);
    }
    return 0;
}


Measured memory_bytes: 128
import scala.io.Source.stdin

object Main {
  val v = new Array[Int](101)
  def main(args:Array[String]) =  {
    stdin.getLines.foreach { a => v(a.toInt) += 1 }
    v.zipWithIndex.filter( _._1 == v.max ).foreach { i => println(i._2) }
  }
}

Measured memory_bytes: 43956
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
typedef pair<double, double> P;

const double INF = 1e12;

pair<double, double> outercenter(double x1, double y1, double x2, double y2, double x3, double y3){
    if(x1 == x2 && y1 == y2) return pair<double, double>((x1 + x3) / 2, (y1 + y3) / 2);
    if(x2 == x3 && y2 == y3) return pair<double, double>((x2 + x1) / 2, (y2 + y1) / 2);
    if(x3 == x1 && y3 == y1) return pair<double, double>((x3 + x2) / 2, (y3 + y2) / 2);
    double a = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
    double b = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
    double c = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    double wa = a * a * (b * b + c * c - a * a);
    double wb = b * b * (c * c + a * a - b * b);
    double wc = c * c * (a * a + b * b - c * c);
    double w = wa + wb + wc;
    if(w == 0) return P(INF, INF);
    return pair<double, double>((wa * x1 + wb * x2 + wc * x3) / w, (wa * y1 + wb * y2 + wc * y3) / w);
}

int main()
{
    int n;
    cin >> n;
    double x[52], y[52];
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    double ans = 1e12;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                P p = outercenter(x[i], y[i], x[j], y[j], x[k], y[k]);
                double r = 0;
                for(int l = 0; l < n; l++){
                    r = max(r, sqrt((x[l] - p.first) * (x[l] - p.first) + (y[l] - p.second) * (y[l] - p.second)));
                }
                ans = min(ans, r);
            }
        }
    }
    cout << fixed << setprecision(15) << ans << endl;
}

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

int A[2000005];
int H = 0;

void swap(int i, int j){
    int tmp = A[j];
    A[j] = A[i];
    A[i] = tmp;
}
// maxHeapify是从上往下整理
void maxHeapify(int i){
    int maxi = A[i];
    int maxi_id = i;
    if(2*i<=H){
        int lvalue = A[2*i];
        if(lvalue>maxi){
            maxi = lvalue;
            maxi_id = 2*i;
        }
    }
    if((2*i+1)<=H){
        int rvalue = A[2*i+1];
        if(rvalue>maxi){
            maxi = rvalue;
            maxi_id = 2*i+1;
        }
    }
    if(maxi_id != i){
        swap(i,maxi_id);
        maxHeapify(maxi_id);
    }
}

void extractMax(){
    int value = A[1];
    A[1] = A[H];
    H--;
    maxHeapify(1);
    printf("%d\n",value);
}
// 需要从下往上整理
void insert(int value){
    H++;
    A[H] = value;
    int i = H;
    while(i>1){
        if(A[i/2]<A[i]){
            swap(i/2,i);
        }
        else break;
        i /= 2;
    }
}

int main(){
    string cmd;
    int value;
    while(1){
        cin >> cmd;
        if(cmd[1]=='x'){
            extractMax();
        }
        else if(cmd[0]=='i'){
            scanf("%d",&value);
            insert(value);
        }
        else break;
    }
    return 0;
}



Measured memory_bytes: 7148