akhauriyash/Code-Regression huggingface dataset:
//A

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

int main(){
    long long A,B; cin >> A >> B;
    if(A > B) {long long  tmp = A; A = B; B = tmp;}
    long long gap = B-A;
    if(gap % 2 == 1){cout << "IMPOSSIBLE" << endl;
    }else{
        cout << A + gap/2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string N;
  cin >> N;
  
  int size = N.length();
  
  int count = 0;

  for (int i = 0; i < size; ++i) {
    count += (int)(N[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
  }
 
  if(count % 9 ==0){
   cout << "Yes" << endl;
  }else{
   cout << "No" << endl; 
  }
 
}

Measured memory_bytes: 3732
#include<stdio.h>

int main(void){
	int w[300], h[300];
	int i_count = 0;
	while (1){
		scanf("%d %d", &h[i_count], &w[i_count]);
		if (h[i_count] == 0 && w[i_count] == 0)
			break;

		i_count++;
	}

	int i, j,n=i_count;
	for (i_count = 0; i_count < n; i_count++){
		for (i = 0; i < h[i_count]; i++){
			for (j = 0; j < w[i_count]; j++){
				printf("%c", '#');
			}
			putchar('\n');
		}
		putchar('\n');
	}


	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0, (a + b) - n) << endl;
}


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

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

using namespace std;

int dp[1001][1001];

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

int main()
{
	int count = 0;
	int W,n,ans;
	int w[1001],v[1001];

	while(cin >> W && W)
	{
		count++;
		memset(dp,0,sizeof(dp));
		cin >> n;
		rep(i,n)
		{
			string s;
			cin >> s;
			vector<string> _s = split(s,',');
			v[i] = atoi(_s[0].c_str());
			w[i] = atoi(_s[1].c_str());
		}

		for(int i=0;i< n ;i++)
		{
			for(int j = 0 ; j <= W; j++)
			{
				if(j < w[i])
				{
					dp[i+1][j] = dp[i][j];
				}
				else
				{
					dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
				}
			}
		}
		for(int j=0;j <= W ; j++)
		{
			if(dp[n][j] == dp[n][W])
			{
				ans = j;
				break;
			}
		}
		cout << "Case " << count <<  ":" << endl;
		cout << dp[n][W] << endl << ans << endl;
	
	}

	return 0;
}

Measured memory_bytes: 5148
# -*- coding: utf-8 -*-

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

s = [list(input()) for i in range(h)]

s2 = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        cnt = 0

        if 1 <= i and 1 <= j:
            if s[i-1][j-1] == '#':
                cnt += 1
        if 1 <= i:
            if s[i-1][j] == '#':
                cnt += 1
        if 1 <= i and j <= w-2:
            if s[i-1][j+1] == '#':
                cnt += 1
        if 1 <= j:
            if s[i][j-1] == '#':
                cnt += 1
        if j <= w-2:
            if s[i][j+1] == '#':
                cnt += 1
        if i <= h-2 and 1 <= j:
            if s[i+1][j-1] == '#':
                cnt += 1
        if i <= h-2:
            if s[i+1][j] == '#':
                cnt += 1
        if i <= h-2 and j <= w-2:
            if s[i+1][j+1] == '#':
                cnt += 1

        if s[i][j] == '#':
            s2[i][j] = '#'
        else:
            s2[i][j] = str(cnt)


for i in range(h):
    print(''.join(s2[i]))


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int max_rectangle(const vector<int>& vec) {
	int rtn = 0;
	stack<pii> stk;
	auto calstk = [&](int ps, int ht){
		int t = ps;
		for( ;!stk.empty() && stk.top().second >= ht; stk.pop()){
			t = stk.top().first;
			rtn = max(rtn, (ps-t) * stk.top().second);
		}
		if(ht >0) stk.push(pii(t, ht));
	};
	rep(i, sz(vec)){
		calstk(i, vec[i]);
	}
	calstk(sz(vec), 0);
	return rtn;
}


int main()
{
	int h,w;
	while(cin >>h >>w){
		if(h==0 && w==0) break;
		vector<vector<int>> fl(h+1, vector<int>(w+1));
		rep(i,h) rep(j,w){
			char ch; cin >>ch;
			if(ch =='1') fl[i][j] = 0;
			else fl[i][j] = i? fl[i-1][j] +1 : 1;
		}
		//for(auto xl: fl){for(auto x :xl) printf("%d ",x); puts("");}
		int ans =0;
		
		rep(i,h){
			ans = max(ans, max_rectangle(fl[i]));
		}
		cout << ans <<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 10444
N = int(input())
dp = [10**20]*(N+10)
dp[0] = 0
for i in range(N+10):
    k = 0
    j = 1
    while i-6**k >= 0:
        dp[i] = min(dp[i-6**k]+1,dp[i])
        k += 1
    while i-9**j >= 0:
        dp[i] = min(dp[i-9**j]+1,dp[i])
        j += 1
print(dp[N])

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

#define pb push_back
#define int ll

using ll=long long;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;
using vi=vector<int>;
using vvi=vector<vi>;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;
    int r = 0;
    for (int i=0; i<n; ++i) {
        if (s[i] == 'R')
            ++r;
    }
    if (r > n-r)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
#line 1 "abc159_e.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
using P = std::pair<int, int>;
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vi> grid(h, vi(w));
  REP(i, h) {
    string s;
    cin >> s;
    REP(j, w) { grid[i][j] = s[j] - '0'; }
  }

  int ans = 5000000;

  REP(bit, (1 << (h - 1))) {
    int tmpans = 0;

    int o = 1;
    REP(i, h - 1) {
      if ((bit >> i) % 2 == 1) {
        o++;
      }
    }

    vector<vi> c(o, vi(w));

    REP(j, w) {
      REP(i, h) {
        int one = 0;
        REP(k, i) {
          if ((bit >> k) % 2 == 1) {
            one++;
          }
        }
        c[one][j] += grid[i][j];
      }
    }

    bool can = true;
    REP(j, w) {
      REP(i, o) {
        if (c[i][j] > k) {
          can = false;
          break;
        }
      }
    }
    if (!can)
      continue;

    vi count(o, 0);
    REP(j, w) {
      vi cur(o, 0);
      bool over = false;
      REP(i, o) {
        cur[i] += c[i][j];
        if (cur[i] + count[i] > k) {
          over = true;
        }
      }
      if (over) {
        tmpans++;
        REP(i, o) { count[i] = cur[i]; }
      } else {
        REP(i, o) { count[i] += cur[i]; }
      }
    }
    ans = min(ans, tmpans + o - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define ll                          long long

#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
double const pi = 3.14159265359;
int  main()
{
	double r;
	cin >> r;
	double ans = 2 * pi * r;
	cout << std::setprecision(9) << ans;
}

Measured memory_bytes: 3812
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main(){

	s := strings.Split(read()," ")
	if s[0] == s[1] && s[0] != s[2] || s[0] == s[2] && s[0] != s[1] || s[0] != s[1] && s[1] == s[2]{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}

}

func read() string{

	var(
        scan = bufio.NewScanner(os.Stdin)
	    s string
	)

	if scan.Scan(){
		s=scan.Text()
	}

	return s
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
	while(true){
		int n, m, p;
		cin >> n >> m >> p;
		if(n == 0 && m == 0 && p == 0){ break; }
		vector<int> x(n);
		for(int i = 0; i < n; ++i){ cin >> x[i]; }
		int sum = accumulate(x.begin(), x.end(), 0);
		int answer = 0;
		if(x[m - 1] > 0){ answer = (sum * (100 - p)) / x[m - 1]; }
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	bc := 0
	for i := 1; i <= k; i <<= 1 {
		bc++
	}

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n)
	bits := make([]int, bc)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		for j := range bits {
			if a[i]&(1<<uint(j)) == 0 {
				bits[j]++
			}
		}
	}

	x := 0
	for i := len(bits) - 1; i >= 0; i-- {
		if v := 1 << uint(i); bits[i] > len(a)/2 && x+v <= k {
			x += v
		}
	}

	ans := 0
	for _, v := range a {
		ans += x ^ v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    
    int A[N];
    int B[N];
    vector<int> C{};
    for (int i=0;i<N;i++) cin >> A[i];
    for (int i=0;i<N;i++) cin >> B[i];
    
    long long number = 0;
    int result = 0;
    for (int i=0;i<N;i++) {
        if (A[i]<B[i]) {
            number += B[i] - A[i];
            result += 1;
        }
        else if (B[i]<A[i]) {
            C.push_back(A[i]-B[i]);
        }
    }
    sort(C.begin(), C.end(),greater<int>());
    int n = C.size();
    
    int i = 0;
    while (number>0 and i<n) {
        number -= C[i];
        i += 1;
    }
    if (number<=0) cout << result+i << endl;
    else cout << -1 << endl;
    
    
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
#define int long long
string s[11234];
int ans;
int Bf,Ae,Mu;
signed main(){
    int N;
    cin>>N;
    rep(i,N){
        cin>>s[i];
        rep(j,(int)s[i].size()-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
        }

        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')Mu++;
        else if(s[i][s[i].size()-1]=='A')Ae++;
        else if(s[i][0]=='B')Bf++;
    }

    dump(Ae);
    dump(Bf);
    dump(Mu);
    dump(ans);

    //cout<<ans+min(Ae+Mu,Bf+Mu)<<endl;

    if(Ae<Bf){
        ans+=Ae;
        if(Mu>0&&Bf>0)ans+=1;
        ans+=max(0LL,Mu-1);
    }else if(Ae==Bf){
        if(Ae==0){
            ans+=Ae;
            ans+=max(0LL,Mu-1);
        }else{
            ans+=Ae;
            ans+=max(0LL,Mu);
            
        }
       
    }else{
        ans+=Bf;
        if(Mu>0&&Ae>0)ans+=1;
        ans+=max(0LL,Mu-1);
    }

    cout<<ans<<endl;




    
    

}

/*
7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBHZ
SZMEHMA

7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBAB
SZMEHMA

*/

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s == "RRR") cout << 3 << endl;
  else if(s == "RRS" || s == "SRR") cout << 2 << endl;
  else if(s == "SSS") cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3628
H,W,K = tuple(map(int,input().split()))
m = 1000000007
def get (bou_no_kazu):
    if bou_no_kazu == 2 or bou_no_kazu ==3:
        return bou_no_kazu
    else:
        return get(bou_no_kazu-1) + get(bou_no_kazu-2)

def n(nodes,from_idx,to_idx):
    ret = nodes[from_idx]
    ## print("r",ret)
    if min(from_idx,to_idx) > 1:
        #print("left")
        ret *= get(min(from_idx,to_idx))
    if max(from_idx,to_idx) < W-2:
        #print("right")
        ret *= get(W-max(from_idx,to_idx)-1)
    return ret
    
prev_node = [1]*1+[0]*(W-1)
next_node = [1]*W

for i in range(H):
    for j in range(W):
        #print(prev_node,next_node)
        next_node[j] = n(prev_node,j,j)
        if j-1 >= 0:
            next_node[j] += n(prev_node,j-1,j)
        if j+1 <= W-1:
            next_node[j] += n(prev_node,j+1,j)
    #print(prev_node)
        
    prev_node = [int(i)%m for i in next_node.copy()]
#print(next_node)
print(int(prev_node[K-1]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

//TEMPLATE
/*
    for(int i=0; i<N; i++){
    }
*/

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    for(int i=0; i<Q; i++){
        cin >> A.at(i);
    }
    vector<int> points(N, K-Q);
    for(int i=0; i<Q; i++){
        points.at(A[i]-1)++;
    }
    for(int i=0; i<N; i++){
        if(points[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M,C;
cin >> N >> M >> C;
int b[21];
for(int i = 0; i < M; i++) cin >> b[i];
int a[21];
int ans = 0;
for(int i = 0; i< N; i++){
  for(int j = 0; j<M; j++){
    cin >> a[j];
  }
  int sum = 0;
  for(int j = 0; j < M; j++){
    sum+= a[j]*b[j];
  }
  if(sum > -1*C){
    ans++;
  }
}
cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define min(p,q)((p)<(q)?(p):(q))
#define rep(i,l,r)for(int i=(l);i<(r);i++)

int ans[3010];
int main(){
	int n,x,y;
	scanf("%d%d%d",&n,&x,&y);
	rep(i,1,n+1)rep(j,i+1,n+1){
		ans[min(j-i,min(abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(x-j)))]++;
	}
	rep(i,1,n)printf("%d\n",ans[i]);
}

Measured memory_bytes: 1732
R, G, B, N = map(int, input().split())
count = 0

for r in range(int(N / R) + 1):
    for g in range(int(N / G) + 1):
        x = N - r * R - g * G
        if x < 0:
            break
        if x >= 0 and x % B == 0:
            count = count + 1

print(count)

Measured memory_bytes: 3060
N = gets.chomp.to_i

S = []
N.times do |i|
  S[i] = gets.chomp.to_s
end

sorted_strings = S.map do |s|
  s.split('').sort.join('')
end

h = sorted_strings.group_by{|s| s}.select{|_, v| v.size > 1}
@output = 0
h.each do |k, v|
  v_size = v.size
  @output += ((v_size * (v_size - 1)) / 2)
end

puts @output



Measured memory_bytes: 41468
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int n;
    cin >> n;
    vector<int> T;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        T.push_back(t);
    }
    int m;
    cin >> m;
    vector<int> vec;
    for(int i=0; i<m; i++){
        int p,x;
        cin >> p >> x;
        int count = 0;
        for(int j=0; j<T.size(); j++){
            if(j!=p-1){
                count+=T[j];
            }
        }
        cout << count + x <<endl;
    }  
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,a[100]={0},ans=0;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    int h;
    cin>>h;
    for(int j=0;j<h;j++){
      int m;
      cin>>m;
      a[m-1]=1;
    }
  }
  for(int i=0;i<n;i++)
    if(!a[i])
      ans+=1;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ret = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
            var Ci = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            for (int i = 0; i < N - 1; i++)
            {
                if (Ai[i + 1] - Ai[i] == 1)
                {
                    ret += Ci[Ai[i] - 1];
                }
            }
            Console.Write(ret);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

Measured memory_bytes: 13268
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


class BIT(object):
    """Bibary Indexed Tree / Fenwick Tree"""
    # 1-indexed
    def __init__(self, size):
        self.size = size
        self.l = [0] * (size + 1)

    def sum(self, i):
        r = 0
        while i > 0:
            r += self.l[i]
            i -= i & -i
        return r

    def add(self, i, x):
        while i <= self.size:
            self.l[i] += x
            i += i & -i


max_a = 1000000


def solve(a):
    bit = BIT(max_a)
    ans = 0
    for i, x in enumerate(a):
        ans += i - bit.sum(x)
        bit.add(x, 1)
    return ans


def main():
    while True:
        N = int(input())
        if N == 0:
            return
        a = []
        for i in range(N):
            a.append(int(input()))
        print(solve(a))


if __name__ == "__main__":
    main()

Measured memory_bytes: 18004
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long d[n];
    rep(i,n){
        cin >> d[i];
    }
    sort(d,d+n);
    if(d[n/2]==d[(n/2)-1]){
        cout << 0 << endl;
        return 0;
    }
    cout << d[n/2]-d[(n/2)-1] << endl;
}

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 ac, wa, tle, re;
		ac = 0;
		wa = 0;
		tle = 0;
		re = 0;
		for(int i=0;i<N;++i){
			String S = sc.next();
			if (S.equals("AC")) ac++;
			if (S.equals("WA")) wa++;
			if (S.equals("TLE")) tle++;
			if (S.equals("RE")) re++;
		}
		sc.close();
		System.out.println("AC x " + ac);
		System.out.println("WA x " + wa);
		System.out.println("TLE x " + tle);
		System.out.println("RE x " + re);
	}
}


Measured memory_bytes: 58488
//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000007
#define OO 0x3f3f3f3f
#define NIL -1
using namespace std;
typedef long long ll;

ll memo[3005][3005];

ll n, arr[3005];

ll solve(int idx_1, int idx_2){
	if(idx_2 < idx_1)
		return 0;
	if(memo[idx_1][idx_2] != NIL)
		return memo[idx_1][idx_2];
	return memo[idx_1][idx_2] = max(arr[idx_1] - solve(idx_1 + 1, idx_2), arr[idx_2] - solve(idx_1, idx_2 - 1));
}

int main() {
	Data_Nerd
	memset(memo, NIL, sizeof(memo));

	scanf("%lld", &n);

	for(int i = 0; i < n; ++i)
		scanf("%lld", &arr[i]);

	printf("%lld", solve(0, n - 1));

	return 0;
}


Measured memory_bytes: 71040
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
a = p[:X] + q[:Y] + r
a.sort(reverse = True)
print(sum(a[:X+Y]))



Measured memory_bytes: 23328
import java.util.*;

public class Main {
	int N;
	String S;
	List<Set<Character>> groups;
	Map<Character, Integer> map;
	long[] results = null;
	long result = 0;

	Main() {
		Scanner in = new Scanner(System.in);
		N = Integer.parseInt(in.nextLine());
		S = in.nextLine();
		in.close();

		this.map = new HashMap<>();
		this.results = new long[N];
		this.results[0] = 1;
		this.map.put(S.charAt(0), 1);
		for (int i = 1; i < S.length(); ++i) {
			Character c = S.charAt(i);
			long addVal = getAddVal(map, c);
			results[i] = (results[i - 1] + addVal) % 1000000007L;
			// System.out.println(results[i] + ", " + addVal);
			if (map.containsKey(c)) {
				map.put(c, map.get(c) + 1);
			} else {
				map.put(c, 1);
			}
		}
	}

	long getKaijo(int val) {
		long result = (long) Math.pow(2.0, (double) val);
		return result;
	}

	long getKaijo(Map<Character, Integer> map, Character c) {
		long result = 1;
		for (Character key : map.keySet()) {
			if (key.equals(c)) {
				continue;
			}
			result *= map.get(key) + 1;
			result %= 1000000007L;
		}
		return result;
	}

	long getAddVal(Map<Character, Integer> map, Character c) {
		long result = getKaijo(map, c);
		/*
		for (Character key : map.keySet()) {
			if (key.equals(c)) {
				continue;
			}
			if (map.get(key) >= 2) {
				result += map.get(key);
			}
		}*/
		return result;
	}

	void show() {
		System.out.println(results[results.length - 1]);
	}

	void calc() {

		result = calcCombi(map.size());
		System.out.println(result);
		for (Character c : map.keySet()) {
			if (map.get(c) > 1) {
				result += map.get(c);
			}
		}
	}

	long calcCombi(int val) {
		long result = 0;
		for (int i = 1; i <= val; ++i) {
			result += calcCombi(val, i);
		}
		return result;
	}

	long calcCombi(int val, int c) {
		if (c > Math.floorDiv(val, 2)) {
			return calcCombi(val, val - c);
		}
		long result = 1;
		for (int i = 1; i <= c; ++i) {
			result *= val - i + 1;
		}
		for (int i = 1; i <= c; ++i) {
			result /= i;
		}
		return result;
	}

	public static void main(String[] args) {
		Main ins = new Main();
		// ins.calc();
		ins.show();
	}

}


Measured memory_bytes: 31088
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint()
{
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//purplesun
const int N=2e5+10;
int n,a[N],b[N];
//
int main()
{
	n=getint();
	rep(i,2*n-1)b[i]=getint();
	int lb=1,rb=2*n;
	while(rb-lb>1)
	{
		int mid=(lb+rb)>>1;
		rep(i,2*n-1)a[i]=(b[i]>=mid);
		int p=n-1,x=a[p],ans=0;
		bool flag=false;
		while(p>0)
		{
			p--;
			if(a[p]==x||a[n*2-p-2]==x)
			{
				ans=x;
				flag=true;
				break;
			}
			x^=1;
		}
		if(!flag)ans=a[0]&1;
		if(ans)lb=mid;
		else rb=mid;
	}
	printf("%d\n",lb);
	return 0;
}


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

using namespace std;


int main() {
    int n,a,b,c,d;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    long long up=1LL*(n-1)*d+a,down=1LL*(n-1)*c+a;
    //printf("%lld %lld\n",up,down);
    for(int i=0;i<=n;i++)
    {
        if(b>=down&&b<=up){
            printf("YES\n");return 0;
        }
        down-=c;up-=d;
        down-=d;up-=c;
    }
    printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;


int month[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
char date[7][10] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};


int main(){
    int M,D,days=0;
    
    while(1){
        days=0;
        scanf("%d%d",&M,&D);
        if(M+D==0) break;
        
        for(int i=0;i<M-1;i++)
            days+=month[i];
    
        printf("%s\n",date[(days+D)%7]);
    }
    
    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N;
  cin>>N;
  map<pair<int,int>,bool> m;
  int x;
  if(N%2==1) x = N;
  else x = N + 1;
  for(int i(1);i<=N/2;i++){
    m[{i,x-i}] = true;
  }
  cout << N*(N-1) / 2 - m.size() << endl;
  for(int i(1);i<=N;i++){
    for(int j(i+1);j<=N;j++){
      if(m[{i,j}]) continue;
      cout << i << " "<< j << endl;
    }
  }
  return 0;
}



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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	bool flag = true;
	while(a > 0 && c > 0){
		if(flag)c -= b;
		else a -= d;
		flag = !flag;
	}

	cout << (a > 0 ? "Yes" : "No" ) << endl;

	return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int x = sc.nextInt();

        long a0 = sc.nextLong();
        long count = 0;
        for (int i = 1; i < n; i++) {
            long a1 = sc.nextLong();
            if (a0 + a1 > x) {
                count += a0 + a1 - x;
                if (a1 >= a0 + a1 - x) {
                    a1 -= a0 + a1 - x;
                } else {
                    a1 = 0;
                }
            }

            a0 = a1;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 48808
def examA():
    A = LI()
    A.sort()
    ans = A[2]*10+A[1]+A[0]
    print(ans)
    return

def examB():
    N, M, x, y = LI()
    X = LI()
    Y = LI()
    X.sort(); Y.sort()
    if max(X[-1],x)<min(Y[0],y):
        print("No War")
    else:
        print("War")
    return

def examC():
    S = SI()
    T = SI()
    N = len(S)
    Ds = defaultdict(str)
    Dt = defaultdict(str)
    for i in range(N):
        s = S[i]; t = T[i]
        if Ds[s]!="" and Ds[s]!=t:
            print("No")
            return
        Ds[s] = t
        if Dt[t] != "" and Dt[t] != s:
            print("No")
            return
        Dt[t] = s
    print("Yes")
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

int main() {
  int D;
  cin >> D;
  
  if (D == 25) {
    cout << "Christmas" << endl;
  } else if (D == 24) {
    cout << "Christmas Eve" << endl;
  } else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))
L.append(0)
L.append(10**9)
L.sort()

#print(L)

ans=0
import bisect

for a in range(1,N):
    for b in range(a+1,N+1):
        c=bisect.bisect_left(L,L[a]+L[b])
        if L[c]>=L[a]+L[b]:
            c-=1
        ans+=(c-b)
        #print(a,b,c)
print(ans)

Measured memory_bytes: 43356
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
int N;
vector<pair<int, pair<int, int>>> edges;
vector<int> parent;

int find(int x) {
    if (parent[x] != x)
        return parent[x] = find(parent[x]);
    return x;
}

void unite(int x, int y) {
    int px = find(x);
    int py = find(y);

    if (rand() & 1) {
        parent[px] = py;
    } else {
        parent[py] = px;
    }
}

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

    cin >> N;

    vector<pair<int, int>> xs, ys;

    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        xs.emplace_back(x, i);
        ys.emplace_back(y, i);
    }

    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    for (int i = 0; i + 1 < N; i++) {
        edges.push_back(make_pair(xs[i + 1].first - xs[i].first, make_pair(xs[i].second, xs[i+1].second)));
    }

    for (int i = 0; i + 1 < N; i++) {
        edges.push_back(make_pair(ys[i + 1].first - ys[i].first, make_pair(ys[i].second + N, ys[i+1].second + N)));
    }

    for (int i = 0; i < N; i++)
        edges.push_back(make_pair(0, make_pair(i, i + N)));

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

    parent.resize(2*N);
    for (int i = 0; i < 2 * N; i++)
        parent[i] = i;

    int result = 0;

    for (auto e : edges) {
        int A = e.second.first;
        int B = e.second.second;
        int cost = e.first;

        if (find(A) != find(B)) {
            unite(A, B);
            result += cost;
        }
    }

    cout << result << "\n";

    return 0;
}


Measured memory_bytes: 10724
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let abc = read_vec::<String>();
    if abc.windows(2).all(|s| s[0].chars().last() == s[1].chars().next()){
        println!("YES");
    }else{
        println!("NO");
    }
    
}

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

int main(){

  int i,j,k;
  int input;
  char str[1024];
  
  scanf("%d",&input);    
  //for(i=1;i<=input;i++){
    scanf("%s",str);
  //}
  
  //printf("%s",str);
  k = 0;
  if( (input%2)==1 ){
    printf("No\n");
  }
  else{
    for(i=0;i<(input/2);i++){
      j = i+(input/2);
      if( str[i] == str[j] ){
        k++;
      }
      else{
        printf("No\n");
        break;
      }
    }
    if( k == (input/2) ){
      printf("Yes\n"); 
    }
  }
  
  
}

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

int main() {

  int a, b;
  scanf("%d%d", &a, &b);

  if (a==1)
   a = 14;
  if (b==1)
   b = 14;

  string ans = a > b ? "Alice" : "Bob";
  if (a==b)
    ans = "Draw";

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int hantei(int);
main(){
  int i,j,n,sum=0;
  int N[10000];
  scanf("%d",&n);
  for(i=0;i<n;i++){ 
      scanf("%d",&N[i]);
      if(hantei(N[i]))sum++; 
} 
  printf("%d\n",sum);
  return 0;
}

int hantei(int n){
  int i=3;
  if(n==2)return 1;
  else if(n<2 || (n%2)==0)return 0;
  else{
  while(i<=sqrt(n)){
    if((n%i)==0)return 0;
    i= i+2;
    }}
   return 1;
}

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

int main() {
  int N, A, B, r, s = 0;
  cin >> N >> A >> B;
  for (int i = 1; i <= N ;i++){
    
    r = i%10 + ((i/10)%10) + ((i/100)%10) + ((i/1000)%10) +
      i/10000;
    if (A <= r&& r <= B ){
      s+=i;
      
    }
    
  }
  cout << s <<endl;
}
  



   
  
  


Measured memory_bytes: 256
#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif

 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void solve()
{
	int n;
	cin>>n;
	
	map<string,int>fre;
	
	for(int i=0;i<n;i++)
	{
		string x;
		cin>>x;
		
		fre[x]++;
	}
	
	cout<<"AC x "<<fre["AC"]<<"\n";
	cout<<"WA x "<<fre["WA"]<<"\n";
	cout<<"TLE x "<<fre["TLE"]<<"\n";
	cout<<"RE x "<<fre["RE"]<<"\n";
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main (){
	int h,w;
	for (int i=1; ; i++)
	{
		scanf ("%d %d",&h,&w);
		if (h==0 && w==0)
		{
			break;
		}
		for (int j=1;j<=h;j++)
		{
			for (int k=1;k<=w;k++)
			{
				if (j>1 && j<h && k>1 && k<w)
				{
					printf (".");
				}else
				{
				printf ("#");
				}
			}
			printf ("\n");
		}
		printf ("\n");
	}
	return 0;
}


Measured memory_bytes: 1904
from sys import stdin
from math import sin, cos, pi

def kock(n, p1, p2):
    if n != 0:
        s = ( (2.0*p1[0]+p2[0])/3.0, (2.0*p1[1]+p2[1])/3.0 )
        t = ( (p1[0]+2.0*p2[0])/3.0, (p1[1]+2.0*p2[1])/3.0 )
        u_x = (t[0]-s[0])*cos(pi/3.0) - (t[1]-s[1])*sin(pi/3.0) + s[0]
        u_y = (t[0]-s[0])*sin(pi/3.0) + (t[1]-s[1])*cos(pi/3.0) + s[1]
        u = (u_x, u_y)

        kock(n-1, p1, s)
        print(*s)
        kock(n-1, s, u)
        print(*u)
        kock(n-1, u, t)
        print(*t)
        kock(n-1, t, p2)

n = int(stdin.readline().rstrip())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
print(*p1)
kock(n, p1, p2)
print(*p2)



Measured memory_bytes: 5780
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define inf 100100100

int main(){
    string s;
    cin >> s;
    long long a = 0;
    long long b = 0;
    rep(i,s.length()){
        if(s[i]=='B'){
            a++;
        }else{
            b+=a;
        }
    }
    cout << b << endl;;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if((a==5&&b==7&&c==5) || (a==5&&b==5&&c==7) || (a==7&&b==5&&c==5))
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}

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

int main(){
    int n, n_odd = 0;
    std::cin >> n;

    std::vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
        if (v[i] % 2 == 1) {
            n_odd++;
        }
    }

    if (n_odd % 2 == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }


    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	double EPS = 1.0e-01;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-- > 0){
			double [] compDis = new double[3];
			for(int i = 0; i < 3; i++){
				compDis[i] = sc.nextDouble();
			}
			int m = sc.nextInt();
			double [][] inputDis = new double[m][3];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < 3; j++){
					inputDis[i][j] = sc.nextDouble();
				}
			}
			
			calc(compDis, inputDis);
			
		}
	}
	
	private void calc(double [] compDis, double [][] inputDis){
		int m = inputDis.length;
		for(int i = 0 ; i < m; i++){
			for(int j = 0; j < m; j++){
				for(int k = 0; k < m; k++){
					if(i == j || i == k || j == k) continue;
					double a = getDis(inputDis[k], inputDis[j]);
					double b = getDis(inputDis[i], inputDis[k]);
					double c = getDis(inputDis[j], inputDis[i]);
					double rate = compDis[0] / a;
					double value1 = rate * b;
					double value2 = rate * c;
					if(isSimilar(compDis[1],value1) && isSimilar(compDis[2], value2)){
						System.out.println((i+1) + " "+ (j+1) + " " + (k+1));
						return;
					}
				}
			}
		}
	}
	
	

	private boolean isSimilar(double comp, double value1) {
		if(value1 - EPS <= comp && comp <= value1 + EPS){
			return true;
		}
		return false;
	}

	private double getDis(double [] a, double [] b) {
		double x = a[0] - b[0];
		double y = a[1] - b[1];
		double z = a[2] - b[2];
		double res = x * x + y * y + z * z;
		return Math.sqrt(res);
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 13000
import sys
def solve():
    readline=sys.stdin.buffer.readline
    int(readline())
    x=list(map(int,readline().split()))
    x.sort()
    mt=10**10
    for i in range(x[0],x[-1]+1):
        t=0
        for v in x:
            t+=(v-i)**2
        mt=min(mt,t)
    print(mt)
if __name__ == '__main__':
    solve()

'''
N=int(input())
X=list(map(int,input().split()))

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=(x-p)**2
    #print(p,sm)
    mn=min(sm,mn)
print(mn)
'''

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmax(T &a, T b) {
    a = max(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<int> a(m, 0);
        REP(i, 0, n) {
            int d, v;
            cin >> d >> v;
            chmax(a[d - 1], v);
        }
        cout << accumulate(a.begin(), a.end(), 0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3184
//Multiplication 1

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    ll n;cin>>n;
    ll s = n;
    map<ll,ll>m{};
    for(ll i=2;s>i*i;i++){
        while(n%i==0){
            m[i]++;
            n/=i;
        }
    }
    if(n!=1)m[n]++;
    ll ans = 0;
    irep(i,m){
        for(int j = 1;i->second>=j;j++){
            i->second-=j;
            ans++;
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define rep(n) for(ll j=1;j<=n;j++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define loopne(i,a,b) for(ll i=a;i<b;i++)
vector < ll > graph[100005];
ll visited[100005] = {0};
ll a[100005]={0};
ll maxi[100005]={0};
ll paths[100005]={0};
void dfs(ll node)
{
   if(visited[node]==0)
   {
       visited[node]++;
    for(auto x:graph[node])
         {
             maxi[x]=max(maxi[x],maxi[node]+1);
             paths[x]++;
             if(paths[x]==a[x])
             dfs(x);
         }
   }
        
}

int main()
{
    ll n,m;

    
    cin>>n>>m;
    rep(m)
    {
        ll x;ll y;
        cin>>x;
        cin>>y;
        graph[x].pb(y);
        a[y]++;
    }
    pair<ll,ll> an[n+1];
    for(ll i=1;i<=n;i++)
    {
        an[i]=mp(a[i],i);
    }
    sort(an+1,an+n+1);
    rep(n)
     {
       if(an[j].first==0)
         dfs(an[j].second);
     }
     ll ans=0;
     rep(n)
     {
         ans=max(ans,maxi[j]);
     }
     cout<<ans<<endl;
     return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<char> a;
  for (int i = 0; i < n; i++) {
    if (a.size() == 0 || s[i] != a.back()) {
      a.push_back(s[i]);
    }
  }
  cout << a.size() << '\n';
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

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)

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int n;
    cin >> n;
    pair<int, int> a[100100];
    rep(i, n) {
        int tmp;
        cin >> tmp;
        a[i] = make_pair(tmp, i+1);
    }
    sort(a, a+n);
    rep(i, n) {
        cout << a[i].second << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 1664
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> list(n, vector<int>(n, INF)), cost(n, vector<int>(n, INF));
  for (int i = 0; i < m; i++) {
    int s, e, c;
    cin >> s >> e >> c; s--, e--;
    list[s][e] = c;
    list[e][s] = c;
    cost[s][e] = c;
    cost[e][s] = c;
  }
  
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (list[i][j] != INF && cost[i][j] != list[i][j]) {
        cnt++;
      }
    }
  }
  
  cout << cnt / 2 << endl;
  return 0;
}


Measured memory_bytes: 384
import sys
n = int(input())
s = input()
if len(s) % 2 == 1:
    print('No')
    sys.exit(0)
flag = True
for i in range(len(s)//2):
    if s[i] != s[i+len(s)//2]:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38372
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import Text.Printf

readInt = ( readLn :: IO Int )
getInts = map ( read :: String -> Int ) . words <$> getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	let
		s = sum $ map digitToInt $ show n
	putStrLn $ which "Yes" "No" $ n `mod` s == 0


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

vi mul(vi p, vi q){
	vi res(sz(p));
	rep(i,0,sz(p)) res[i] = p[q[i]];
	return res;
}

vi inv(vi p){
	vi res(sz(p));
	rep(i,0,sz(p)) res[p[i]] = i;
	return res;
}

vi pow(vi p, int e){
	vi res(sz(p));
	rep(i,0,sz(p)) res[i] = i;
	while(e){
		if(e%2) res = mul(res, p);
		p = mul(p,p);
		e /= 2;
	}
	return res;
}

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

	int n, k;
	cin >> n >> k;
	--k;

	vi ps(n), qs(n);
	trav(x, ps) cin >> x, --x;
	trav(x, qs) cin >> x, --x;

	vi com = mul(qs, inv(ps));
	com = mul(com, inv(qs));
	com = mul(com, ps);
	com = pow(com, k/6);
	k %= 6;
	rep(_,0,k){
		ps = mul(qs, inv(ps));
		swap(ps,qs);
	}
	vi ans = mul(com, mul(ps, inv(com)));
	trav(x, ans) cout << x+1 << ' ';
	cout << endl;
}


Measured memory_bytes: 4408